diff --git a/language/en-GB/en-GB.plg_fields_radicalmultifield.ini b/language/en-GB/en-GB.plg_fields_radicalmultifield.ini index 98221b1..b916742 100644 --- a/language/en-GB/en-GB.plg_fields_radicalmultifield.ini +++ b/language/en-GB/en-GB.plg_fields_radicalmultifield.ini @@ -28,6 +28,9 @@ PLG_RADICAL_MULTI_FIELD_FIELD_PARAMS_FILESIMPORTRESIZE_LABEL="Enable image resiz PLG_RADICAL_MULTI_FIELD_FIELD_PARAMS_FILESIMPORTRESIZE_DESC="When the resize is enabled, the images will resize under the specified maximum width and height" PLG_RADICAL_MULTI_FIELD_FIELD_PARAMS_FILESIMPORTRESIZEMAXWIDTH_LABEL="Maximum width
in pixels" PLG_RADICAL_MULTI_FIELD_FIELD_PARAMS_FILESIMPORTRESIZEMAXHEIGHT_LABEL="Maximum height
in pixels" +PLG_RADICAL_MULTI_FIELD_FIELD_PARAMS_FILESIMPORTPREVIEW_LABEL="Generate preview images" +PLG_RADICAL_MULTI_FIELD_FIELD_PARAMS_FILESIMPORTPREVIEWMAXWIDTH_LABEL="Max width preview
in pixels" +PLG_RADICAL_MULTI_FIELD_FIELD_PARAMS_FILESIMPORTPREVIEWMAXHEIGHT_LABEL="Max height preview
in pixels" PLG_RADICAL_MULTI_FIELD_FIELD_PARAMS_FILESIMPORTRESIZEOVERLAY_LABEL="Apply a watermark" PLG_RADICAL_MULTI_FIELD_FIELD_PARAMS_FILESIMPORTRESIZEOVERLAYFILE_LABEL="Watermark File" PLG_RADICAL_MULTI_FIELD_FIELD_PARAMS_FILESIMPORTRESIZEOVERLAYPOS_LABEL="Select a position for the sign" diff --git a/language/ru-RU/ru-RU.plg_fields_radicalmultifield.ini b/language/ru-RU/ru-RU.plg_fields_radicalmultifield.ini index ed70544..1c077aa 100644 --- a/language/ru-RU/ru-RU.plg_fields_radicalmultifield.ini +++ b/language/ru-RU/ru-RU.plg_fields_radicalmultifield.ini @@ -28,6 +28,9 @@ PLG_RADICAL_MULTI_FIELD_FIELD_PARAMS_FILESIMPORTRESIZE_LABEL="Подгонять PLG_RADICAL_MULTI_FIELD_FIELD_PARAMS_FILESIMPORTRESIZE_DESC="При включеном параметре, изображения будут изменять размер под указанные максимальную ширину и высоту в пикселях" PLG_RADICAL_MULTI_FIELD_FIELD_PARAMS_FILESIMPORTRESIZEMAXWIDTH_LABEL="Максимальная ширина
в пикселях" PLG_RADICAL_MULTI_FIELD_FIELD_PARAMS_FILESIMPORTRESIZEMAXHEIGHT_LABEL="Максимальная высота
в пикселях" +PLG_RADICAL_MULTI_FIELD_FIELD_PARAMS_FILESIMPORTPREVIEW_LABEL="Генерация превью картинок" +PLG_RADICAL_MULTI_FIELD_FIELD_PARAMS_FILESIMPORTPREVIEWMAXWIDTH_LABEL="Максимальная ширина превью
в пикселях" +PLG_RADICAL_MULTI_FIELD_FIELD_PARAMS_FILESIMPORTPREVIEWMAXHEIGHT_LABEL="Максимальная высота превью
в пикселях" PLG_RADICAL_MULTI_FIELD_FIELD_PARAMS_FILESIMPORTRESIZEOVERLAY_LABEL="Накладывать водяной знак" PLG_RADICAL_MULTI_FIELD_FIELD_PARAMS_FILESIMPORTRESIZEOVERLAYFILE_LABEL="Файл водяного знака" PLG_RADICAL_MULTI_FIELD_FIELD_PARAMS_FILESIMPORTRESIZEOVERLAYPOS_LABEL="Выберите позицию для знака" diff --git a/params/radicalmultifield.xml b/params/radicalmultifield.xml index c7e03e4..4fd2aa0 100644 --- a/params/radicalmultifield.xml +++ b/params/radicalmultifield.xml @@ -125,6 +125,36 @@ showon="filesimportresize:1[AND]filesimport:1" /> + + + + + + + + + _type . '/' . $this->_name . '/params/' . $type . '.xml'; + $path = JPATH_PLUGINS . DIRECTORY_SEPARATOR . $this->_type . DIRECTORY_SEPARATOR . $this->_name . DIRECTORY_SEPARATOR . 'params' . DIRECTORY_SEPARATOR . $type . '.xml'; // Check if params file exists if (!file_exists($path)) @@ -265,14 +265,14 @@ public function onContentPrepareForm(JForm $form, $data) return; } - JLoader::import('radicalmultifieldhelper', JPATH_ROOT . '/plugins/fields/radicalmultifield'); + JLoader::register('RadicalmultifieldHelper', JPATH_ROOT . DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, ['plugins', 'fields', 'radicalmultifield', 'radicalmultifieldhelper']) . '.php'); $paramsfield = file_get_contents($path); if(!empty($pluginType)) { - if(file_exists($pathType . '/newparams.xml')) { - $newParams = file_get_contents($pathType . '/newparams.xml'); + if(file_exists($pathType . DIRECTORY_SEPARATOR . 'newparams.xml')) { + $newParams = file_get_contents($pathType . DIRECTORY_SEPARATOR . 'newparams.xml'); $paramsfield = str_replace('', $newParams . '', $paramsfield); } @@ -325,7 +325,7 @@ public function onContentPrepareForm(JForm $form, $data) if(file_exists($pathType)) { - $paramsfieldValues = file_get_contents($pathType . '/default.xml'); + $paramsfieldValues = file_get_contents($pathType . DIRECTORY_SEPARATOR . 'default.xml'); $paramsfieldValuesXML = new SimpleXMLElement($paramsfieldValues); for ($i = 0; $i < count($paramsfieldValuesXML->fields->fieldset->field); $i++) @@ -392,7 +392,7 @@ public function onAjaxRadicalmultifield() $admin = $app->isAdmin(); $allow = true; - JLoader::register('RadicalmultifieldHelper', JPATH_SITE . '/plugins/fields/radicalmultifield/radicalmultifieldhelper.php'); + JLoader::register('RadicalmultifieldHelper', JPATH_ROOT . DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, ['plugins', 'fields', 'radicalmultifield', 'radicalmultifieldhelper']) . '.php'); $params = RadicalmultifieldHelper::getParams($data['importfield']); @@ -432,10 +432,10 @@ public function onAjaxRadicalmultifield() if($data['type'] === 'get_files') { $exs = explode(',', $params['filesimportexc']); - $directory = ($data['importfieldpath'] ? $data['importfieldpath'] . '/' : '') . preg_replace('/^root/isu', '', $data['directory']); - $directory = str_replace("//", '/', $directory); + $directory = ($data['importfieldpath'] ? $data['importfieldpath'] . DIRECTORY_SEPARATOR : '') . preg_replace('/^root/isu', '', $data['directory']); + $directory = str_replace(DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR, $directory); $filesOutput = []; - $files = Folder::files(JPATH_ROOT . '/' .(string) $directory); + $files = Folder::files(JPATH_ROOT . DIRECTORY_SEPARATOR .(string) $directory); foreach ($files as $file) { $tmpExs = explode('.', $file); @@ -503,15 +503,15 @@ public function onAjaxRadicalmultifield() $data['name'] = isset($data['name']) ? $data['name'] : ''; - $path = JPATH_ROOT . '/' . ($data['importfieldpath'] ? $data['importfieldpath'] . '/' : '') . preg_replace('/^root/isu', '', $data['path']) . '/' . $data['name']; - $path = str_replace("//", '/', $path); + $path = JPATH_ROOT . DIRECTORY_SEPARATOR . ($data['importfieldpath'] ? $data['importfieldpath'] . DIRECTORY_SEPARATOR : '') . preg_replace('/^root/isu', '', $data['path']) . DIRECTORY_SEPARATOR . $data['name']; + $path = str_replace(DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR, $path); if (!file_exists($path)) { Folder::create($path); } - if (File::upload($file['tmp_name'], $path . "/" . $uploadedFileName)) + if (File::upload($file['tmp_name'], $path . DIRECTORY_SEPARATOR . $uploadedFileName)) { if(in_array($type, ['jpg', 'gif', 'png', 'jpeg', 'jpg', 'webp'])) @@ -519,9 +519,9 @@ public function onAjaxRadicalmultifield() if((int)$params['filesimportresize']) { - JLoader::registerNamespace('Gumlet', JPATH_SITE . '/' . implode(DIRECTORY_SEPARATOR , ['plugins', 'fields', 'radicalmultifield', 'libs', 'gumlet', 'lib'])); + JLoader::registerNamespace('Gumlet', JPATH_SITE . DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR , ['plugins', 'fields', 'radicalmultifield', 'libs', 'gumlet', 'lib'])); - $image = new ImageResize($path . "/" . $uploadedFileName); + $image = new ImageResize($path . DIRECTORY_SEPARATOR . $uploadedFileName); $maxWidth = (int)$params['filesimportrezizemaxwidth']; $maxHeight = (int)$params['filesimportrezizemaxheight']; @@ -533,7 +533,7 @@ public function onAjaxRadicalmultifield() if((int)$params['filesimportrezizeoverlay']) { - $file = JPATH_SITE . '/' . $params['filesimportrezizeoverlayfile']; + $file = JPATH_SITE . DIRECTORY_SEPARATOR . $params['filesimportrezizeoverlayfile']; $position = $params['filesimportrezizeoverlaypos']; $padding = $params['filesimportrezizeoverlaypadding']; @@ -618,7 +618,12 @@ public function onAjaxRadicalmultifield() } - $image->save($path . "/" . $uploadedFileName); + $image->save($path . DIRECTORY_SEPARATOR . $uploadedFileName); + + if((int)$params['filesimportpreview']) + { + RadicalmultifieldHelper::generateThumb($params, $path . DIRECTORY_SEPARATOR . $uploadedFileName); + } } } @@ -640,11 +645,11 @@ public function onAjaxRadicalmultifield() { $lang = Factory::getLanguage(); $data['name'] = JFILE::makeSafe($lang->transliterate($data['name'])); - $path = JPATH_ROOT . '/' . ($data['importfieldpath'] ? $data['importfieldpath'] . '/' : '') . preg_replace('/^root/isu', '', $data['path']) . '/' . $data['name']; - $path = str_replace("//", '/', $path); + $path = JPATH_ROOT . DIRECTORY_SEPARATOR . ($data['importfieldpath'] ? $data['importfieldpath'] . DIRECTORY_SEPARATOR : '') . preg_replace('/^root/isu', '', $data['path']) . DIRECTORY_SEPARATOR . $data['name']; + $path = str_replace(DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR, $path); Folder::create($path); - JLoader::register('FormFieldRadicalmultifieldtreecatalog', JPATH_ROOT . '/plugins/fields/radicalmultifield/elements/radicalmultifieldtreecatalog.php'); + JLoader::register('FormFieldRadicalmultifieldtreecatalog', JPATH_ROOT . DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, ['plugins', 'fields', 'radicalmultifield', 'elements', 'radicalmultifieldtreecatalog']) . '.php'); $treeCatalog = new FormFieldRadicalmultifieldtreecatalog; $paramsForField = [ 'name' => 'select-directory', @@ -656,8 +661,7 @@ public function onAjaxRadicalmultifield() 'showroot' => 'true', ]; - $dataAttributes = array_map(function($value, $key) - { + $dataAttributes = array_map(function($value, $key) { return $key . '="' . $value . '"'; }, array_values($paramsForField), array_keys($paramsForField)); diff --git a/radicalmultifield.xml b/radicalmultifield.xml index 5a8515b..125a774 100644 --- a/radicalmultifield.xml +++ b/radicalmultifield.xml @@ -7,7 +7,7 @@ https://delo-design.ru Copyright (C) 2018 "Delo Design". All rights reserved. GNU General Public License version 2 or later; see LICENSE.txt - 2.0 + 2.1 PLG_RADICAL_MULTI_FIELD_XML_DESCRIPTION script.php diff --git a/radicalmultifieldhelper.php b/radicalmultifieldhelper.php index c060388..9baf631 100644 --- a/radicalmultifieldhelper.php +++ b/radicalmultifieldhelper.php @@ -2,6 +2,7 @@ use Joomla\CMS\Factory; use Joomla\Filesystem\Folder; +use Gumlet\ImageResize; defined('_JEXEC') or die; @@ -277,7 +278,8 @@ public static function check($field_id, $item_id, $data = [], $column_find_all = foreach ($item as $keyRow => $row) { - if($column_find_all) { + if($column_find_all) + { if(!isset($data[$keyRow]) || ((string)$row !== (string)$data[$keyRow])) { @@ -285,7 +287,9 @@ public static function check($field_id, $item_id, $data = [], $column_find_all = break; } - } else { + } + else + { if(isset($data[$keyRow]) && ((string)$row == (string)$data[$keyRow])) { @@ -380,4 +384,88 @@ public static function loadClassExtendField($path) return $fileListsName; } + + /** + * @param $fieldOrParams + * @param $source + * + * @return mixed|string + */ + public static function generateThumb(&$fieldOrParams, $source) + { + $source = str_replace(JPATH_ROOT . DIRECTORY_SEPARATOR, '', $source); + $paths = explode(DIRECTORY_SEPARATOR, $source); + $file = array_pop($paths); + $fileSplit = explode('.', $file); + $fileExt = array_pop($fileSplit); + $extAccept = ['jpg', 'jpeg', 'png', 'gif']; + + if(!in_array($fileExt, $extAccept)) + { + return $file; + } + + $pathThumb = implode(DIRECTORY_SEPARATOR, array_merge($paths, ['_thumb'])); + $pathFileThumb = implode(DIRECTORY_SEPARATOR, array_merge($paths, ['_thumb'])) . DIRECTORY_SEPARATOR . $file; + $fullPathThumb = JPATH_ROOT . DIRECTORY_SEPARATOR . $pathThumb . DIRECTORY_SEPARATOR . $file; + + //если есть проевью, то отдаем ссылку на файл + if(file_exists($fullPathThumb)) + { + return $pathFileThumb; + } + + //если нет, генерируем превью + + //проверяем создан ли каталог для превью + if(!file_exists(JPATH_ROOT . DIRECTORY_SEPARATOR . $pathThumb)) + { + //создаем каталог + Folder::create(JPATH_ROOT . DIRECTORY_SEPARATOR . $pathThumb); + } + + //подгружаем библиотеку для фото + JLoader::registerNamespace('Gumlet', JPATH_SITE . DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR , ['plugins', 'fields', 'radicalmultifield', 'libs', 'gumlet', 'lib'])); + + $params = []; + + if(is_object($fieldOrParams)) + { + if(!isset($fieldOrParams->name)) + { + return $source; + } + + //подгружаем параметры поля + $params = self::getParams($fieldOrParams->name); + + } + + if(is_array($fieldOrParams)) + { + $params = $fieldOrParams; + } + + + if(!isset($params['filesimportpreviewmaxwidth']) || !isset($params['filesimportpreviewmaxheight'])) + { + return $source; + } + + copy(JPATH_ROOT . DIRECTORY_SEPARATOR . $source, $fullPathThumb); + $image = new ImageResize($fullPathThumb); + + $maxWidth = (int)$params['filesimportpreviewmaxwidth']; + $maxHeight = (int)$params['filesimportpreviewmaxheight']; + + $image->resizeToBestFit($maxWidth, $maxHeight); + $image->save($fullPathThumb); + unset($image); + + return $pathFileThumb; + + } + + + } \ No newline at end of file diff --git a/tmpl/galleryforuikit2.php b/tmpl/galleryforuikit2.php index e3df5e0..bb42d6e 100644 --- a/tmpl/galleryforuikit2.php +++ b/tmpl/galleryforuikit2.php @@ -18,6 +18,8 @@ $values = json_decode($field->value, JSON_OBJECT_AS_ARRAY); $listtype = $this->getListTypeFromField($field); +jimport('radicalmultifieldhelper', JPATH_ROOT . DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, ['plugins', 'fields', 'radicalmultifield'])); //подключаем хелпер + ?> @@ -26,7 +28,7 @@
- <?= $row['alt'] ?> + <?= $row['alt'] ?>
diff --git a/tmpl/galleryforuikit3.php b/tmpl/galleryforuikit3.php index 2c0240e..aa328c3 100644 --- a/tmpl/galleryforuikit3.php +++ b/tmpl/galleryforuikit3.php @@ -18,6 +18,8 @@ $values = json_decode($field->value, JSON_OBJECT_AS_ARRAY); $listtype = $this->getListTypeFromField($field); +jimport('radicalmultifieldhelper', JPATH_ROOT . DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, ['plugins', 'fields', 'radicalmultifield'])); //подключаем хелпер + ?>
@@ -25,7 +27,7 @@
- <?= $row['alt'] ?> + <?= $row['alt'] ?>