Skip to content

Commit

Permalink
dev
Browse files Browse the repository at this point in the history
  • Loading branch information
skeeks-semenov committed Mar 14, 2024
1 parent 8128ca1 commit 6a71442
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 14 deletions.
52 changes: 38 additions & 14 deletions src/components/imaging/filters/Thumbnail.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@

namespace skeeks\cms\components\imaging\filters;

use yii\base\Component;
use skeeks\imagine\Image;
use Imagine\Image\ManipulatorInterface;
use skeeks\imagine\Image;
use yii\base\Exception;

/**
Expand All @@ -28,6 +27,12 @@ class Thumbnail extends \skeeks\cms\components\imaging\Filter
* @var int Качество сохраняемого фото
*/
public $q;

/**
* @var int Если не задана ширина или высота, то проверять оригинальный размер файла и новый файл не будет крупнее
*/
public $s = 1;

public $m = ManipulatorInterface::THUMBNAIL_INSET;

public function init()
Expand All @@ -38,12 +43,12 @@ public function init()
throw new Exception("Необходимо указать ширину или высоту");
}

$q = (int) $this->q;
$q = (int)$this->q;
if (!$q) {
$this->q = (int) \Yii::$app->seo->img_preview_quality;
$this->q = (int)\Yii::$app->seo->img_preview_quality;
}

$q = (int) $this->q;
$q = (int)$this->q;

if ($q < 10) {
$this->q = 10;
Expand All @@ -61,30 +66,49 @@ protected function _save()
$this->m = ManipulatorInterface::THUMBNAIL_INSET;
}*/
if (!$this->w) {
//Если ширина не указана нужно ее расчитать
$size = Image::getImagine()->open($this->_originalRootFilePath)->getSize();

//Если размер оригинальной кратинки больше, то уменьшаем его
if ($this->s == 1) {
if ($this->h > $size->getHeight()) {
$this->h = $size->getHeight();
}
}


$width = ($size->getWidth() * $this->h) / $size->getHeight();

Image::thumbnailV2($this->_originalRootFilePath, (int)round($width), $this->h,
$this->m)->save($this->_newRootFilePath, [
'jpeg_quality' => $this->q,
'webp_quality' => $this->q,
]);
'jpeg_quality' => $this->q,
'webp_quality' => $this->q,
]);

} else {
if (!$this->h) {
$size = Image::getImagine()->open($this->_originalRootFilePath)->getSize();

//Если размер оригинальной кратинки больше, то уменьшаем его
if ($this->s == 1) {
if ($this->w > $size->getWidth()) {
$this->w = $size->getWidth();
}
}


$height = ($size->getHeight() * $this->w) / $size->getWidth();
Image::thumbnailV2($this->_originalRootFilePath, $this->w, (int)round($height),
$this->m)->save($this->_newRootFilePath, [
'jpeg_quality' => $this->q,
'webp_quality' => $this->q,
]);
'jpeg_quality' => $this->q,
'webp_quality' => $this->q,
]);
} else {
$image = Image::thumbnailV2($this->_originalRootFilePath, $this->w, $this->h,
$this->m)->save($this->_newRootFilePath, [
'jpeg_quality' => $this->q,
'webp_quality' => $this->q,
]);
'jpeg_quality' => $this->q,
'webp_quality' => $this->q,
]);
}
}
}
Expand Down
9 changes: 9 additions & 0 deletions src/models/CmsContentProperty.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace skeeks\cms\models;

use skeeks\cms\query\CmsContentPropertyActiveQuery;
use skeeks\cms\relatedProperties\models\RelatedPropertyModel;
use Yii;
use yii\helpers\ArrayHelper;
Expand Down Expand Up @@ -228,4 +229,12 @@ public function asText()
return parent::asText();
return $result." ($this->code)";
}

/**
* @return CmsContentPropertyActiveQuery
*/
public static function find()
{
return (new CmsContentPropertyActiveQuery(get_called_class()));
}
}
17 changes: 17 additions & 0 deletions src/models/behaviors/HasStorageFileMulti.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,24 @@ public function saveStorgaFile($e)
} catch (\Exception $e) {
}
} else {

//Если файл не существует, то будет удален
if (!$storageFile = CmsStorageFile::findOne($fileId)) {
continue;
}

//Если файл еще не был привязан, то нужно привязать
if (!in_array($fileId, $oldIds)) {
if ($this->owner->isNewRecord) {
$this->_linkFiles[$relation][] = $storageFile;
} else {
$this->owner->link($relation, $storageFile);
}
}

//Файл попадает в перечень файлов
$files[] = $fileId;
//Удаляется ID из претендентов на удаление
ArrayHelper::remove($oldIds, $fileId);
}
}
Expand Down
8 changes: 8 additions & 0 deletions src/query/CmsContentElementActiveQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@
class CmsContentElementActiveQuery extends CmsActiveQuery
{

/**
* @param mixed $id
* @return CmsTreeActiveQuery
*/
public function sxId(mixed $id)
{
return $this->andWhere(['sx_id' => $id]);
}

/**
* Фильтрация по дате публикации
Expand Down
24 changes: 24 additions & 0 deletions src/query/CmsContentPropertyActiveQuery.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
/**
* @link https://cms.skeeks.com/
* @copyright Copyright (c) 2010 SkeekS
* @license https://cms.skeeks.com/license/
* @author Semenov Alexander <semenov@skeeks.com>
*/

namespace skeeks\cms\query;

/**
* @author Semenov Alexander <semenov@skeeks.com>
*/
class CmsContentPropertyActiveQuery extends CmsActiveQuery
{
/**
* @param mixed $id
* @return CmsContentPropertyActiveQuery
*/
public function sxId(mixed $id)
{
return $this->andWhere(['sx_id' => $id]);
}
}
1 change: 1 addition & 0 deletions src/query/CmsTreeActiveQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
class CmsTreeActiveQuery extends CmsActiveQuery
{
public $is_active = false;
/**
* @param mixed $id
* @return CmsTreeActiveQuery
Expand Down

0 comments on commit 6a71442

Please sign in to comment.