Skip to content

Commit

Permalink
ClusterLocal update set publicBaseUrl and rootBasePath
Browse files Browse the repository at this point in the history
  • Loading branch information
skeeks-semenov committed Mar 26, 2018
1 parent aec1747 commit 6c550f8
Show file tree
Hide file tree
Showing 13 changed files with 410 additions and 39 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -3,6 +3,7 @@ CHANGELOG

5.1.0.pre
----------------
* ClusterLocal update set publicBaseUrl and rootBasePath
* Removed skeeks\cms\Exception
* Widget and component settings to use skeeks/yii2-form
* Change config form interface
Expand Down
2 changes: 1 addition & 1 deletion src/components/ImagingUrlRule.php
Expand Up @@ -67,7 +67,7 @@ public function parseRequest($manager, $request)
if (!in_array(StringHelper::strtolower($extension), (array)\Yii::$app->imaging->extensions)) {
return false;
}

return ['cms/imaging/process', $params];
}
}
7 changes: 7 additions & 0 deletions src/components/storage/ClusterLocal.php
Expand Up @@ -27,12 +27,19 @@ public function init()
if (!$this->name) {
$this->name = \Yii::t('skeeks/cms', "Local storage");
}

if (!$this->publicBaseUrl) {
$this->publicBaseUrl = \Yii::getAlias("@web/uploads/all");
} else {
$this->publicBaseUrl = \Yii::getAlias($this->publicBaseUrl);
}

if (!$this->rootBasePath) {
$this->rootBasePath = \Yii::getAlias("@frontend/web/uploads/all");
} else {
$this->rootBasePath = \Yii::getAlias($this->rootBasePath);
}

parent::init();
}

Expand Down
39 changes: 16 additions & 23 deletions src/controllers/ImagingController.php
Expand Up @@ -14,17 +14,9 @@
use skeeks\cms\components\Imaging;
use skeeks\cms\components\imaging\Filter;
use skeeks\cms\Exception;
use skeeks\sx\Dir;
use skeeks\sx\File;
use Yii;
use skeeks\cms\models\StorageFile;
use skeeks\cms\models\searchs\StorageFile as StorageFileSearch;
use yii\helpers\Json;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use yii\web\UploadedFile;
use skeeks\imagine\Image;


/**
Expand All @@ -51,7 +43,7 @@ public function actionProcess()
$extension = Imaging::getExtension($newFileSrc);

if (!$extension) {
throw new \yii\base\Exception("Extension not found: " . $newFileSrc);
throw new \yii\base\Exception("Extension not found: ".$newFileSrc);
}


Expand All @@ -61,30 +53,31 @@ public function actionProcess()


$newFile = File::object($newFileSrc);
$strposFilter = strpos($newFileSrc, "/" . Imaging::THUMBNAIL_PREFIX);
$strposFilter = strpos($newFileSrc, "/".Imaging::THUMBNAIL_PREFIX);
if (!$strposFilter) {
throw new NotFoundHttpException("This is not a filter thumbnail: " . $newFileSrc);
throw new NotFoundHttpException("This is not a filter thumbnail: ".$newFileSrc);
}

$originalFileSrc = substr($newFileSrc, 0, $strposFilter) . "." . $newFile->getExtension();
$originalFileSrc = substr($newFileSrc, 0, $strposFilter).".".$newFile->getExtension();

//TODO: hardcode delete it in the future
$webRoot = \Yii::getAlias('@webroot');

$originalFileRoot = $webRoot . DIRECTORY_SEPARATOR . $originalFileSrc;
$newFileRoot = $webRoot . DIRECTORY_SEPARATOR . $newFileSrc;
$newFileRootDefault = $webRoot . DIRECTORY_SEPARATOR . str_replace($newFile->getBaseName(),
Imaging::DEFAULT_THUMBNAIL_FILENAME . "." . $extension, $newFileSrc);
$originalFileRoot = $webRoot.DIRECTORY_SEPARATOR.$originalFileSrc;
$newFileRoot = $webRoot.DIRECTORY_SEPARATOR.$newFileSrc;
$newFileRootDefault = $webRoot.DIRECTORY_SEPARATOR.str_replace($newFile->getBaseName(),
Imaging::DEFAULT_THUMBNAIL_FILENAME.".".$extension, $newFileSrc);

$originalFile = new File($originalFileRoot);

if (!$originalFile->isExist()) {
throw new NotFoundHttpException("The original file is not found: " . $newFileSrc);
throw new NotFoundHttpException("The original file is not found: ".$newFileSrc);
}

//Проверено наличие оригинального файла, есть пути к оригиналу, и результирующему файлу.
//Отслось собрать фильтр, и проверить наличие параметров. А так же проверить разрешены ли эти параметры, для этого в строке есть захэшированный ключь

$filterSting = substr($newFileSrc, ($strposFilter + strlen(DIRECTORY_SEPARATOR . Imaging::THUMBNAIL_PREFIX)),
$filterSting = substr($newFileSrc, ($strposFilter + strlen(DIRECTORY_SEPARATOR.Imaging::THUMBNAIL_PREFIX)),
strlen($newFileSrc));
$filterCode = explode("/", $filterSting);
$filterCode = $filterCode[0]; //Код фильтра
Expand All @@ -93,28 +86,28 @@ public function actionProcess()
if ($params = \Yii::$app->request->get()) {
$pramsCheckArray = explode(DIRECTORY_SEPARATOR, $filterSting);
if (count($pramsCheckArray) < 3) {
throw new \yii\base\Exception("the control line not found: " . $newFileSrc);
throw new \yii\base\Exception("the control line not found: ".$newFileSrc);
}

$string = $imaging->getParamsCheckString($params);
if ($pramsCheckArray[1] != $string) {
throw new \yii\base\Exception("Parameters invalid: " . $newFileSrc);
throw new \yii\base\Exception("Parameters invalid: ".$newFileSrc);
}
}

$filterClass = str_replace("-", "\\", $filterCode);


if (!class_exists($filterClass)) {
throw new \ErrorException("Filter class is not created: " . $newFileSrc);
throw new \ErrorException("Filter class is not created: ".$newFileSrc);
}

/**
* @var Filter $filter
*/
$filter = new $filterClass((array)$params);
if (!is_subclass_of($filter, Filter::className())) {
throw new NotFoundHttpException("No child filter class: " . $newFileSrc);
throw new NotFoundHttpException("No child filter class: ".$newFileSrc);
}

try {
Expand All @@ -135,7 +128,7 @@ public function actionProcess()
}
}

$url = \Yii::$app->request->getUrl() . ($params ?
$url = \Yii::$app->request->getUrl().($params ?
""//"?" . http_build_query($params) . '&sx-refresh'
: '?sx-refresh');

Expand Down
3 changes: 3 additions & 0 deletions src/messages/ru/main.php
Expand Up @@ -95,6 +95,9 @@
"City" => "Город",
"Verification Code" => "Проверочный код",

"Display columns" => "Отображаемые колонки",
"Hidden columns" => "Скрытые колонки",

"Type" => "Тип",
"File Type" => "Тип файла",
"File Size" => "Размер файла",
Expand Down
136 changes: 136 additions & 0 deletions src/widgets/DualSelect.php
@@ -0,0 +1,136 @@
<?php
/**
* @author Semenov Alexander <semenov@skeeks.com>
* @link https://skeeks.com/
* @copyright (c) 2010 SkeekS
* @date 24.03.2018
*/

namespace skeeks\cms\widgets;

use skeeks\cms\widgets\assets\DualSelectAsset;
use yii\base\InvalidConfigException;
use yii\helpers\ArrayHelper;
use yii\helpers\Html;
use yii\widgets\InputWidget;
/**
* Class SortableDualList
* @package skeeks\cms\widgets
*/
class DualSelect extends InputWidget
{
/**
* @var array
*/
public $wrapperOptions = [];

/**
* @var array
*/
public $items = [];

/**
* @var array
*/
public $jsOptions = [];


/**
* @var array|string
*/
public $visibleLabel = [
'tag' => 'h3',
'body' => 'Visibles'
];

/**
* @var array|string
*/
public $hiddenLabel = [
'tag' => 'h3',
'body' => 'Hiddens'
];

public $itemOptions = [
'tag' => 'li'
];


/**
* @inheritdoc
*/
public function run()
{
if (!$this->hasModel()) {
throw new InvalidConfigException('!!!');
}

Html::addCssClass($this->options, 'sx-select-element');

if (!ArrayHelper::getValue($this->options, 'id')) {
$this->options['id'] = Html::getInputId($model, $attribute);
$this->jsOptions['element_id'] = $this->options['id'];
}

$this->wrapperOptions['id'] = $this->id;
$this->jsOptions['id'] = $this->id;

$this->options['multiple'] = true;

$items = (array) $this->model->{$this->attribute};
$selectedItems = [];
if ($items) {
foreach ($items as $value)
{
$selectedItems[$value] = $value;
}
}

$element = Html::activeListBox($this->model, $this->attribute, (array) $selectedItems, $this->options);

echo $this->render('dual-select', [
'element' => $element,
]);
}

/**
* @param $value
* @param $item
*/
public function renderItem($value, $item)
{
$itemOptions = $this->itemOptions;
$tag = ArrayHelper::getValue($itemOptions, 'tag', 'li');
ArrayHelper::remove($itemOptions, 'tag');

$itemOptions['data']['value'] = $value;

echo Html::beginTag($tag, $itemOptions);
echo $item;
echo Html::endTag($tag);
}

/**
* @param $options
* @param string $defaultTab
* @return mixed
*/
public function renderHtml($options, $defaultTab = 'h3')
{
if (is_string($options)) {
return $this->renderHtml([
'body' => $options
]);
}

$tag = ArrayHelper::getValue($options, 'tag', $defaultTab);
ArrayHelper::remove($options, 'tag');

$body = ArrayHelper::getValue($options, 'body');
ArrayHelper::remove($options, 'body');

echo Html::beginTag($tag, $options);
echo $body;
echo Html::endTag($tag);
}
}
5 changes: 2 additions & 3 deletions src/widgets/FiltersWidget.php
Expand Up @@ -50,7 +50,7 @@ class FiltersWidget extends Widget
/**
* @var array
*/
public $config = [];
public $configBehaviorData = [];

/**
* @var bool генерировать фильтры автоматически
Expand Down Expand Up @@ -102,8 +102,7 @@ public function behaviors()
['visibleFilters', 'safe'],
],
],
],
(array)$this->config),
], (array)$this->configBehaviorData),
]);
}

Expand Down

0 comments on commit 6c550f8

Please sign in to comment.