From 151374add107f2eeab862bd9a786dc2ba99e303f Mon Sep 17 00:00:00 2001 From: Mark Hamstra Date: Mon, 28 Jan 2019 11:57:54 +0100 Subject: [PATCH 01/20] Fix nonaggregated column in SELECT list when showing gallery items (only_full_group_by) Full error: Expression #13 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'premium.AlbumItems.rank' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by --- core/components/gallery/processors/mgr/item/getlist.class.php | 1 - 1 file changed, 1 deletion(-) diff --git a/core/components/gallery/processors/mgr/item/getlist.class.php b/core/components/gallery/processors/mgr/item/getlist.class.php index b1f3735..9dc4c7e 100644 --- a/core/components/gallery/processors/mgr/item/getlist.class.php +++ b/core/components/gallery/processors/mgr/item/getlist.class.php @@ -62,7 +62,6 @@ public function prepareQueryAfterCount(xPDOQuery $c) { WHERE Tags.item = galItem.id ) AS tags' )); - $c->groupBy('id'); return $c; } From 1812e5cff4a5da1e9533adddb39b97971b2f2345 Mon Sep 17 00:00:00 2001 From: Dmitriy Antipov Date: Thu, 1 Oct 2020 21:51:50 +0300 Subject: [PATCH 02/20] Update ajaxupload.php ERROR .../core/components/gallery/processors/mgr/item/ajaxupload.php 75 [Gallery] Album Type: # (number) - fix --- core/components/gallery/processors/mgr/item/ajaxupload.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/components/gallery/processors/mgr/item/ajaxupload.php b/core/components/gallery/processors/mgr/item/ajaxupload.php index 90eb498..01addb6 100644 --- a/core/components/gallery/processors/mgr/item/ajaxupload.php +++ b/core/components/gallery/processors/mgr/item/ajaxupload.php @@ -72,7 +72,7 @@ $file = array("name" => $relativePath, "tmp_name" => $randomFilename, "error" => "0"); // emulate a $_FILES object - $modx->log(xPDO::LOG_LEVEL_ERROR,'[Gallery] Album Type: '.$scriptProperties['album']); + $modx->log(xPDO::MODX_LOG_LEVEL_INFO,'[Gallery] Album Type: '.$scriptProperties['album']); if ($bytes == 0 || !$item->upload($file,$scriptProperties['album'])) { From b91eda0c8e24fd116ec8d44f2c26894a8fbaa299 Mon Sep 17 00:00:00 2001 From: Dmitriy Antipov Date: Thu, 21 Jan 2021 00:39:40 +0300 Subject: [PATCH 03/20] Update ajaxupload.php --- core/components/gallery/processors/mgr/item/ajaxupload.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/components/gallery/processors/mgr/item/ajaxupload.php b/core/components/gallery/processors/mgr/item/ajaxupload.php index 01addb6..54fe3fc 100644 --- a/core/components/gallery/processors/mgr/item/ajaxupload.php +++ b/core/components/gallery/processors/mgr/item/ajaxupload.php @@ -72,7 +72,7 @@ $file = array("name" => $relativePath, "tmp_name" => $randomFilename, "error" => "0"); // emulate a $_FILES object - $modx->log(xPDO::MODX_LOG_LEVEL_INFO,'[Gallery] Album Type: '.$scriptProperties['album']); + $modx->log(xPDO::LOG_LEVEL_INFO,'[Gallery] Album Type: '.$scriptProperties['album']); if ($bytes == 0 || !$item->upload($file,$scriptProperties['album'])) { From 417aa530b383fd47f2b73602acbcf6cf10788ac0 Mon Sep 17 00:00:00 2001 From: halftrainedharry Date: Wed, 20 Apr 2022 10:04:32 +0200 Subject: [PATCH 04/20] change flat-file processors --- .../gallery/import/galzipimport.class.php | 15 +- .../processors/mgr/item/ajaxupload.php | 234 ++++++------ .../processors/mgr/item/batchupload.php | 235 ++++++------ .../gallery/processors/mgr/item/sort.php | 79 ++-- .../gallery/processors/mgr/item/zipupload.php | 69 ++-- .../gallery/processors/web/phpthumb.php | 347 +++++++++--------- 6 files changed, 510 insertions(+), 469 deletions(-) diff --git a/core/components/gallery/model/gallery/import/galzipimport.class.php b/core/components/gallery/model/gallery/import/galzipimport.class.php index 3e6c75f..e87a8f4 100644 --- a/core/components/gallery/model/gallery/import/galzipimport.class.php +++ b/core/components/gallery/model/gallery/import/galzipimport.class.php @@ -150,11 +150,18 @@ public function importFile($file,array $options = array()) { * @return bool|string */ public function unpack() { - if (!$this->modx->loadClass('compression.xPDOZip',$this->modx->getOption('core_path').'xpdo/',true,true)) { - return $this->modx->lexicon('gallery.xpdozip_err_nf'); + $archive = null; + if ($this->modx->getVersionData()['version'] >= 3){ + //V3 + $archive = new xPDO\Compression\xPDOZip($this->modx,$this->source['tmp_name']); + } else { + //V2 + if (!$this->modx->loadClass('compression.xPDOZip',$this->modx->getOption('core_path').'xpdo/',true,true)) { + return $this->modx->lexicon('gallery.xpdozip_err_nf'); + } + $archive = new xPDOZip($this->modx,$this->source['tmp_name']); } - /* unpack zip file */ - $archive = new xPDOZip($this->modx,$this->source['tmp_name']); + /* unpack zip file */ if (!$archive) { return $this->modx->lexicon('gallery.zip_err_unpack'); } diff --git a/core/components/gallery/processors/mgr/item/ajaxupload.php b/core/components/gallery/processors/mgr/item/ajaxupload.php index 90eb498..e2a02ff 100644 --- a/core/components/gallery/processors/mgr/item/ajaxupload.php +++ b/core/components/gallery/processors/mgr/item/ajaxupload.php @@ -2,119 +2,125 @@ /* @var modX $modx * @var array $scriptProperties */ - -/* validate form */ -$album = $modx->getOption('album',$scriptProperties,false); -$filenm = $modx->getOption('qqfile',$scriptProperties,false); -/* If $filenm is an array, it means we've used IE and we need to use a different name. */ -if (is_array($filenm)) $filenm = $filenm['name']; - -if (empty($album)) return $modx->error->failure($modx->lexicon('gallery.album_err_ns')); -if (empty($filenm)) return $modx->error->failure($modx->lexicon('gallery.item_err_ns')); - -/* create item */ -$scriptProperties['active'] = !empty($scriptProperties['active']) ? 1 : 0; -/** @var galItem $item */ -$item = $modx->newObject('galItem'); -$item->fromArray($scriptProperties); -$item->set('createdby',$modx->user->get('id')); -$item->set('name',$filenm); - -if (!$item->save()) { - return $modx->error->failure($modx->lexicon('gallery.item_err_save')); -} - -/* Upload */ -$albumDir = $album.'/'; -$targetDir = $modx->call('galAlbum','getFilesPath',array(&$modx)).$albumDir; - -// $cacheManager = $modx->getCacheManager(); -// /* if directory doesnt exist, create it */ -// if (!file_exists($targetDir) || !is_dir($targetDir)) { -// if (!$cacheManager->writeTree($targetDir)) { -// $modx->log(xPDO::LOG_LEVEL_ERROR,'[Gallery] Could not create directory: '.$targetDir); -// return $modx->toJSON(array('error' => 'Could not create directory: ' . $targetDir)); -// } -// } -// /* make sure directory is readable/writable */ -// if (!is_readable($targetDir) || !is_writable($targetDir)) { -// $modx->log(xPDO::LOG_LEVEL_ERROR,'[Gallery] Could not write to directory: '.$targetDir); -// return $modx->toJSON(array('error' => 'Could not write to directory: ' . $targetDir)); -// } - -/* upload the file */ -$extension = @end(explode('.', $filenm)); -$filename = $item->get('id').'.'.$extension; -$relativePath = $albumDir.$filename; -$absolutePath = $targetDir.$filename; - - -if (!empty($_FILES['qqfile'])) { - if (!$item->upload($_FILES['qqfile'],$scriptProperties['album'])) { - $item->remove(); - return $modx->error->failure($modx->lexicon('gallery.item_err_upload')); - } -} else { - - $length = 10; - $tmpDir = MODX_CORE_PATH."cache/gallery-tmp/"; - - if(!file_exists($tmpDir)) mkdir($tmpDir); - - $randomFilename = $tmpDir.substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, $length).".$extension"; - - /* Using AJAX upload - to tmp file then use the correct media source to upload */ - $input = fopen("php://input", "r"); - $target = fopen($randomFilename, "w"); - $bytes = stream_copy_to_stream($input, $target); - fclose($input); - fclose($target); - - $file = array("name" => $relativePath, "tmp_name" => $randomFilename, "error" => "0"); // emulate a $_FILES object - - $modx->log(xPDO::LOG_LEVEL_ERROR,'[Gallery] Album Type: '.$scriptProperties['album']); - - - if ($bytes == 0 || !$item->upload($file,$scriptProperties['album'])) { - $modx->log(xPDO::LOG_LEVEL_ERROR,'[Gallery] An error occurred while trying to upload the file to '.$absolutePath); - $item->remove(); - return $modx->toJSON(array('error' => 'gallery.item_err_upload')); - } else { - $item->set('filename',str_replace(' ','',$relativePath)); +class GalleryItemAjaxUploadProcessor extends modProcessor { + + public function process(){ + $modx = $this->modx; + $scriptProperties = $this->properties; + + /* validate form */ + $album = $modx->getOption('album',$scriptProperties,false); + $filenm = $modx->getOption('qqfile',$scriptProperties,false); + /* If $filenm is an array, it means we've used IE and we need to use a different name. */ + if (is_array($filenm)) $filenm = $filenm['name']; + + if (empty($album)) return $modx->error->failure($modx->lexicon('gallery.album_err_ns')); + if (empty($filenm)) return $modx->error->failure($modx->lexicon('gallery.item_err_ns')); + + /* create item */ + $scriptProperties['active'] = !empty($scriptProperties['active']) ? 1 : 0; + /** @var galItem $item */ + $item = $modx->newObject('galItem'); + $item->fromArray($scriptProperties); + $item->set('createdby',$modx->user->get('id')); + $item->set('name',$filenm); + + if (!$item->save()) { + return $modx->error->failure($modx->lexicon('gallery.item_err_save')); + } + + /* Upload */ + $albumDir = $album.'/'; + $targetDir = $modx->call('galAlbum','getFilesPath',array(&$modx)).$albumDir; + + // $cacheManager = $modx->getCacheManager(); + // /* if directory doesnt exist, create it */ + // if (!file_exists($targetDir) || !is_dir($targetDir)) { + // if (!$cacheManager->writeTree($targetDir)) { + // $modx->log(xPDO::LOG_LEVEL_ERROR,'[Gallery] Could not create directory: '.$targetDir); + // return $modx->toJSON(array('error' => 'Could not create directory: ' . $targetDir)); + // } + // } + // /* make sure directory is readable/writable */ + // if (!is_readable($targetDir) || !is_writable($targetDir)) { + // $modx->log(xPDO::LOG_LEVEL_ERROR,'[Gallery] Could not write to directory: '.$targetDir); + // return $modx->toJSON(array('error' => 'Could not write to directory: ' . $targetDir)); + // } + + /* upload the file */ + $extension = @end(explode('.', $filenm)); + $filename = $item->get('id').'.'.$extension; + $relativePath = $albumDir.$filename; + $absolutePath = $targetDir.$filename; + + + if (!empty($_FILES['qqfile'])) { + if (!$item->upload($_FILES['qqfile'],$scriptProperties['album'])) { + $item->remove(); + return $modx->error->failure($modx->lexicon('gallery.item_err_upload')); + } + } else { + + $length = 10; + $tmpDir = MODX_CORE_PATH."cache/gallery-tmp/"; + + if(!file_exists($tmpDir)) mkdir($tmpDir); + + $randomFilename = $tmpDir.substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, $length).".$extension"; + + /* Using AJAX upload - to tmp file then use the correct media source to upload */ + $input = fopen("php://input", "r"); + $target = fopen($randomFilename, "w"); + $bytes = stream_copy_to_stream($input, $target); + fclose($input); + fclose($target); + + $file = array("name" => $relativePath, "tmp_name" => $randomFilename, "error" => "0"); // emulate a $_FILES object + + $modx->log(xPDO::LOG_LEVEL_ERROR,'[Gallery] Album Type: '.$scriptProperties['album']); + + + if ($bytes == 0 || !$item->upload($file,$scriptProperties['album'])) { + $modx->log(xPDO::LOG_LEVEL_ERROR,'[Gallery] An error occurred while trying to upload the file to '.$absolutePath); + $item->remove(); + return $modx->toJSON(array('error' => 'gallery.item_err_upload')); + } else { + $item->set('filename',str_replace(' ','',$relativePath)); + } + + @unlink($randomFilename); + } + + $item->save(); + + /* get count of items in album */ + $total = $modx->getCount('galAlbumItem',array('album' => $scriptProperties['album'])); + + /* associate with album */ + /** @var galAlbumItem $albumItem */ + $albumItem = $modx->newObject('galAlbumItem'); + $albumItem->set('album',$scriptProperties['album']); + $albumItem->set('item',$item->get('id')); + $albumItem->set('rank',$total); + $albumItem->save(); + + /* save tags */ + if (isset($scriptProperties['tags'])) { + $tagNames = explode(',',$scriptProperties['tags']); + foreach ($tagNames as $tagName) { + $tagName = trim($tagName); + if (empty($tagName)) continue; + + /** @var galTag $tag */ + $tag = $modx->newObject('galTag'); + $tag->set('item',$item->get('id')); + $tag->set('tag',$tagName); + $tag->save(); + } + } + + /* output to browser */ + return $modx->toJSON(array('success' => true)); } - - @unlink($randomFilename); } - -$item->save(); - -/* get count of items in album */ -$total = $modx->getCount('galAlbumItem',array('album' => $scriptProperties['album'])); - -/* associate with album */ -/** @var galAlbumItem $albumItem */ -$albumItem = $modx->newObject('galAlbumItem'); -$albumItem->set('album',$scriptProperties['album']); -$albumItem->set('item',$item->get('id')); -$albumItem->set('rank',$total); -$albumItem->save(); - -/* save tags */ -if (isset($scriptProperties['tags'])) { - $tagNames = explode(',',$scriptProperties['tags']); - foreach ($tagNames as $tagName) { - $tagName = trim($tagName); - if (empty($tagName)) continue; - - /** @var galTag $tag */ - $tag = $modx->newObject('galTag'); - $tag->set('item',$item->get('id')); - $tag->set('tag',$tagName); - $tag->save(); - } -} - -/* output to browser */ -return $modx->toJSON(array('success' => true)); - -?> +return 'GalleryItemAjaxUploadProcessor'; diff --git a/core/components/gallery/processors/mgr/item/batchupload.php b/core/components/gallery/processors/mgr/item/batchupload.php index 32b7249..7ec6aa1 100644 --- a/core/components/gallery/processors/mgr/item/batchupload.php +++ b/core/components/gallery/processors/mgr/item/batchupload.php @@ -18,128 +18,139 @@ * Place, Suite 330, Boston, MA 02111-1307 USA * * @package gallery - */ -/** + * * Batch upload items into an Album via a directory - * - * @package gallery */ +class GalleryItemBatchUploadProcessor extends modProcessor { -/* validate form */ -$album = $modx->getOption('album',$scriptProperties,false); -if (empty($album)) return $modx->error->failure($modx->lexicon('gallery.album_err_ns')); - -$scriptProperties['active'] = !empty($scriptProperties['active']) ? 1 : 0; - -if (empty($scriptProperties['directory'])) $modx->error->addField('directory',$modx->lexicon('gallery.directory_err_ns')); -$directory = str_replace(array( - '{base_path}', - '{assets_path}', - '{core_path}', -),array( - $modx->getOption('base_path',null,MODX_BASE_PATH), - $modx->getOption('assets_path',null,MODX_ASSETS_PATH), - $modx->getOption('core_path',null,MODX_CORE_PATH), -),$scriptProperties['directory']); - -if (empty($directory) || !is_dir($directory)) $modx->error->addField('directory',$modx->lexicon('gallery.directory_err_nf')); - -if ($modx->error->hasError()) { - return $modx->error->failure(); -} - - -/* get sanitized base path and current path */ -$modx->getService('fileHandler','modFileHandler'); -$fullpath = $modx->fileHandler->sanitizePath($directory); + public function process(){ + $modx = $this->modx; + $scriptProperties = $this->properties; + /* validate form */ + $album = $modx->getOption('album',$scriptProperties,false); + if (empty($album)) return $modx->error->failure($modx->lexicon('gallery.album_err_ns')); -$targetDir = $modx->call('galAlbum','getFilesPath',array(&$modx)).$scriptProperties['album'].'/'; + $scriptProperties['active'] = !empty($scriptProperties['active']) ? 1 : 0; -$imagesExts = array('jpg','jpeg','png','gif','bmp'); -$use_multibyte = $modx->getOption('use_multibyte',null,false); -$encoding = $modx->getOption('modx_charset',null,'UTF-8'); -/* iterate */ -$images = array(); -$errors = array(); -$files = array(); -foreach (new DirectoryIterator($fullpath) as $file) { - if (in_array($file,array('.','..','.svn','_notes'))) continue; - if (!$file->isReadable() || $file->isDir()) continue; + if (empty($scriptProperties['directory'])) $modx->error->addField('directory',$modx->lexicon('gallery.directory_err_ns')); + $directory = str_replace(array( + '{base_path}', + '{assets_path}', + '{core_path}', + ),array( + $modx->getOption('base_path',null,MODX_BASE_PATH), + $modx->getOption('assets_path',null,MODX_ASSETS_PATH), + $modx->getOption('core_path',null,MODX_CORE_PATH), + ),$scriptProperties['directory']); - $files[$file->getFilename()] = array( - 'pathname' => $file->getPathname() - ); -} -ksort($files); -foreach ($files as $f_name => $file) { - $fileName = $f_name; - $filePathName = $file['pathname']; - - $fileExtension = pathinfo($filePathName,PATHINFO_EXTENSION); - $fileExtension = $use_multibyte ? mb_strtolower($fileExtension,$encoding) : strtolower($fileExtension); - if (!in_array($fileExtension,$imagesExts)) continue; - - /* create item */ - $item = $modx->newObject('galItem'); - $item->set('name',$fileName); - $item->set('createdby',$modx->user->get('id')); - $item->set('mediatype','image'); - $item->set('active',$scriptProperties['active']); - if (!$item->save()) { - $errors[] = $modx->lexicon('gallery.item_err_save'); - continue; - } + if (empty($directory) || !is_dir($directory)) $modx->error->addField('directory',$modx->lexicon('gallery.directory_err_nf')); - $newFileName = $item->get('id').'.'.$fileExtension; - $newRelativePath = $scriptProperties['album'].'/'.$newFileName; - $newAbsolutePath = $targetDir.'/'.$newFileName; - - $file = array("name" => $newRelativePath, "tmp_name" => $filePathName, "error" => "0"); // emulate a $_FILES object - - $success = $item->upload($file,$scriptProperties['album']); - if(!$success) { - $errors[] = $modx->lexicon('gallery.file_err_move',array( - 'file' => $newFileName, - 'target' => $newAbsolutePath, - )); - $item->remove(); - continue; - } else { - $item->set('filename',$newRelativePath); - $item->save(); - } + if ($modx->error->hasError()) { + return $modx->error->failure(); + } - /* get count of items in album */ - $total = $modx->getCount('galAlbumItem',array('album' => $_POST['album'])); - - /* associate with album */ - $albumItem = $modx->newObject('galAlbumItem'); - $albumItem->set('album',$scriptProperties['album']); - $albumItem->set('item',$item->get('id')); - $albumItem->set('rank',$total); - $albumItem->save(); - - /* save tags */ - if (isset($scriptProperties['tags'])) { - $tagNames = explode(',',$scriptProperties['tags']); - foreach ($tagNames as $tagName) { - $tagName = trim($tagName); - if (empty($tagName)) continue; - - $tag = $modx->newObject('galTag'); - $tag->set('item',$item->get('id')); - $tag->set('tag',$tagName); - $tag->save(); + /* get sanitized base path and current path */ + $filehandler = null; + if ($this->modx->getVersionData()['version'] >= 3){ + //V3 + $filehandler = new MODX\Revolution\File\modFileHandler($modx); + } else { + //V2 + $modx->getService('fileHandler','modFileHandler'); + $filehandler = $modx->fileHandler; + } + $fullpath = $filehandler->sanitizePath($directory); + + $targetDir = $modx->call('galAlbum','getFilesPath',array(&$modx)).$scriptProperties['album'].'/'; + + $imagesExts = array('jpg','jpeg','png','gif','bmp'); + $use_multibyte = $modx->getOption('use_multibyte',null,false); + $encoding = $modx->getOption('modx_charset',null,'UTF-8'); + /* iterate */ + $images = array(); + $errors = array(); + $files = array(); + foreach (new DirectoryIterator($fullpath) as $file) { + if (in_array($file,array('.','..','.svn','_notes'))) continue; + if (!$file->isReadable() || $file->isDir()) continue; + + $files[$file->getFilename()] = array( + 'pathname' => $file->getPathname() + ); + } + ksort($files); + foreach ($files as $f_name => $file) { + $fileName = $f_name; + $filePathName = $file['pathname']; + + $fileExtension = pathinfo($filePathName,PATHINFO_EXTENSION); + $fileExtension = $use_multibyte ? mb_strtolower($fileExtension,$encoding) : strtolower($fileExtension); + if (!in_array($fileExtension,$imagesExts)) continue; + + /* create item */ + $item = $modx->newObject('galItem'); + $item->set('name',$fileName); + $item->set('createdby',$modx->user->get('id')); + $item->set('mediatype','image'); + $item->set('active',$scriptProperties['active']); + if (!$item->save()) { + $errors[] = $modx->lexicon('gallery.item_err_save'); + continue; + } + + $newFileName = $item->get('id').'.'.$fileExtension; + $newRelativePath = $scriptProperties['album'].'/'.$newFileName; + $newAbsolutePath = $targetDir.'/'.$newFileName; + + $file = array("name" => $newRelativePath, "tmp_name" => $filePathName, "error" => "0"); // emulate a $_FILES object + + $success = $item->upload($file,$scriptProperties['album']); + if(!$success) { + $errors[] = $modx->lexicon('gallery.file_err_move',array( + 'file' => $newFileName, + 'target' => $newAbsolutePath, + )); + $item->remove(); + continue; + } else { + $item->set('filename',$newRelativePath); + $item->save(); + } + + /* get count of items in album */ + $total = $modx->getCount('galAlbumItem',array('album' => $_POST['album'])); + + /* associate with album */ + $albumItem = $modx->newObject('galAlbumItem'); + $albumItem->set('album',$scriptProperties['album']); + $albumItem->set('item',$item->get('id')); + $albumItem->set('rank',$total); + $albumItem->save(); + + /* save tags */ + if (isset($scriptProperties['tags'])) { + $tagNames = explode(',',$scriptProperties['tags']); + foreach ($tagNames as $tagName) { + $tagName = trim($tagName); + if (empty($tagName)) continue; + + $tag = $modx->newObject('galTag'); + $tag->set('item',$item->get('id')); + $tag->set('tag',$tagName); + $tag->save(); + } + } + + $images[] = $fileName; } - } - $images[] = $fileName; -} + if (!empty($errors)) { + return $modx->error->failure(implode(',',$errors)); + } -if (!empty($errors)) { - return $modx->error->failure(implode(',',$errors)); + /* output to browser */ + return $modx->error->success('',$images); + } } - -/* output to browser */ -return $modx->error->success('',$images); +return 'GalleryItemBatchUploadProcessor'; diff --git a/core/components/gallery/processors/mgr/item/sort.php b/core/components/gallery/processors/mgr/item/sort.php index 3ce8880..26dd88b 100644 --- a/core/components/gallery/processors/mgr/item/sort.php +++ b/core/components/gallery/processors/mgr/item/sort.php @@ -25,41 +25,50 @@ * @package gallery * @subpackage processors */ -$source = $modx->getObject('galAlbumItem',array( - 'album' => $scriptProperties['album'], - 'item' => $scriptProperties['source'], -)); -if (empty($source)) return $modx->error->failure(); +class GalleryItemSortProcessor extends modProcessor { -$target = $modx->getObject('galAlbumItem',array( - 'album' => $scriptProperties['album'], - 'item' => $scriptProperties['target'], -)); -if (empty($target)) return $modx->error->failure(); + public function process(){ + $modx = $this->modx; + $scriptProperties = $this->properties; -if ($source->get('rank') < $target->get('rank')) { - $modx->exec(" - UPDATE {$modx->getTableName('galAlbumItem')} - SET rank = rank - 1 - WHERE - album = ".$scriptProperties['album']." - AND rank < {$target->get('rank')} - AND rank > {$source->get('rank')} - AND rank > 0 - "); - $newRank = $target->get('rank')-1; -} else { - $modx->exec(" - UPDATE {$modx->getTableName('galAlbumItem')} - SET rank = rank + 1 - WHERE - album = ".$scriptProperties['album']." - AND rank >= {$target->get('rank')} - AND rank < {$source->get('rank')} - "); - $newRank = $target->get('rank'); -} -$source->set('rank',$newRank); -$source->save(); + $source = $modx->getObject('galAlbumItem',array( + 'album' => $scriptProperties['album'], + 'item' => $scriptProperties['source'], + )); + if (empty($source)) return $modx->error->failure(); + + $target = $modx->getObject('galAlbumItem',array( + 'album' => $scriptProperties['album'], + 'item' => $scriptProperties['target'], + )); + if (empty($target)) return $modx->error->failure(); -return $modx->error->success(); + if ($source->get('rank') < $target->get('rank')) { + $modx->exec(" + UPDATE {$modx->getTableName('galAlbumItem')} + SET rank = rank - 1 + WHERE + album = ".$scriptProperties['album']." + AND rank < {$target->get('rank')} + AND rank > {$source->get('rank')} + AND rank > 0 + "); + $newRank = $target->get('rank')-1; + } else { + $modx->exec(" + UPDATE {$modx->getTableName('galAlbumItem')} + SET rank = rank + 1 + WHERE + album = ".$scriptProperties['album']." + AND rank >= {$target->get('rank')} + AND rank < {$source->get('rank')} + "); + $newRank = $target->get('rank'); + } + $source->set('rank',$newRank); + $source->save(); + + return $modx->error->success(); + } +} +return 'GalleryItemSortProcessor'; diff --git a/core/components/gallery/processors/mgr/item/zipupload.php b/core/components/gallery/processors/mgr/item/zipupload.php index 0497e47..a4c6a92 100644 --- a/core/components/gallery/processors/mgr/item/zipupload.php +++ b/core/components/gallery/processors/mgr/item/zipupload.php @@ -18,44 +18,49 @@ * Place, Suite 330, Boston, MA 02111-1307 USA * * @package gallery - */ -/** - * Batch upload items into an Album via a Zip file * - * @package gallery + * Batch upload items into an Album via a Zip file */ +class GalleryItemZipUploadProcessor extends modProcessor { -/* validate form */ -$album = $modx->getOption('album',$scriptProperties,false); -if (empty($album)) return $modx->error->failure($modx->lexicon('gallery.album_err_ns')); + public function process(){ + $modx = $this->modx; + $scriptProperties = $this->properties; -$scriptProperties['active'] = !empty($scriptProperties['active']) ? 1 : 0; -if (empty($_FILES['zip']) || $_FILES['zip']['error'] !== UPLOAD_ERR_OK) { - $modx->error->addField('zip',$modx->lexicon('gallery.zip_err_ns')); -} + /* validate form */ + $album = $modx->getOption('album',$scriptProperties,false); + if (empty($album)) return $modx->error->failure($modx->lexicon('gallery.album_err_ns')); -/* load import class */ -$loaded = $modx->gallery->loadImporter('galZipImport'); -if ($loaded !== true) return $modx->error->failure($loaded); + $scriptProperties['active'] = !empty($scriptProperties['active']) ? 1 : 0; + if (empty($_FILES['zip']) || $_FILES['zip']['error'] !== UPLOAD_ERR_OK) { + $modx->error->addField('zip',$modx->lexicon('gallery.zip_err_ns')); + } -/* attempt to set source zip */ -if (!$modx->gallery->galZipImport->setSource($_FILES['zip'])) { - $modx->error->addField('zip',$modx->lexicon('gallery.zip_err_ns')); -} + /* load import class */ + $loaded = $modx->gallery->loadImporter('galZipImport'); + if ($loaded !== true) return $modx->error->failure($loaded); -$targetSet = $modx->gallery->galZipImport->setTarget($scriptProperties['album']); -if (!$targetSet) { - $modx->error->addField('zip',$targetSet); -} -if ($modx->error->hasError()) { - return $modx->error->failure(); -} + /* attempt to set source zip */ + if (!$modx->gallery->galZipImport->setSource($_FILES['zip'])) { + $modx->error->addField('zip',$modx->lexicon('gallery.zip_err_ns')); + } -/* run import */ -$success = $modx->gallery->galZipImport->run($scriptProperties); -if ($success !== true) { - return $modx->error->failure($success); -} + $targetSet = $modx->gallery->galZipImport->setTarget($scriptProperties['album']); + if (!$targetSet) { + $modx->error->addField('zip',$targetSet); + } + if ($modx->error->hasError()) { + return $modx->error->failure(); + } + + /* run import */ + $success = $modx->gallery->galZipImport->run($scriptProperties); + if ($success !== true) { + return $modx->error->failure($success); + } -/* output to browser */ -return $modx->error->success('',$modx->gallery->galZipImport->results); \ No newline at end of file + /* output to browser */ + return $modx->error->success('',$modx->gallery->galZipImport->results); + } +} +return 'GalleryItemZipUploadProcessor'; \ No newline at end of file diff --git a/core/components/gallery/processors/web/phpthumb.php b/core/components/gallery/processors/web/phpthumb.php index 0ced2c6..a1b3b57 100644 --- a/core/components/gallery/processors/web/phpthumb.php +++ b/core/components/gallery/processors/web/phpthumb.php @@ -1,199 +1,202 @@ modx; + $scriptProperties = $this->properties; -if (!class_exists('phpthumb', false)) { - if (!$modx->loadClass('phpthumb', MODX_CORE_PATH . 'model/phpthumb/', true, true)) { - $modx->log(modX::LOG_LEVEL_ERROR, '[phpThumbOf] Could not load modPhpThumb class.'); - return ''; - } -} + if (!class_exists('phpthumb', false)) { + if (!$modx->loadClass('phpthumb', MODX_CORE_PATH . 'model/phpthumb/', true, true)) { + $modx->log(modX::LOG_LEVEL_ERROR, '[phpThumbOf] Could not load modPhpThumb class.'); + return ''; + } + } -$debug = $modx->getOption('debug', $scriptProperties, false); + $debug = $modx->getOption('debug', $scriptProperties, false); -$src = $modx->getOption('src', $scriptProperties, ''); -$src = str_replace('+', '%27', urldecode($src)); + $src = $modx->getOption('src', $scriptProperties, ''); + $src = str_replace('+', '%27', urldecode($src)); -/* explode tag options */ -$ptOptions = array(); + /* explode tag options */ + $ptOptions = array(); -// Only public parameters of phpThumb should be allowed to pass from user input. -// List properties between START PARAMETERS and START PARAMETERS in src/core/model/phpthumb/phpthumb.class.php -$allowed = array( - 'src', 'new', 'w', 'h', 'wp', 'hp', 'wl', 'hl', 'ws', 'hs', - 'f', 'q', 'sx', 'sy', 'sw', 'sh', 'zc', 'bc', 'bg', 'fltr', - 'goto', 'err', 'xto', 'ra', 'ar', 'aoe', 'far', 'iar', 'maxb', 'down', - 'md5s', 'sfn', 'dpi', 'sia', 'phpThumbDebug' -); + // Only public parameters of phpThumb should be allowed to pass from user input. + // List properties between START PARAMETERS and START PARAMETERS in src/core/model/phpthumb/phpthumb.class.php + $allowed = array( + 'src', 'new', 'w', 'h', 'wp', 'hp', 'wl', 'hl', 'ws', 'hs', + 'f', 'q', 'sx', 'sy', 'sw', 'sh', 'zc', 'bc', 'bg', 'fltr', + 'goto', 'err', 'xto', 'ra', 'ar', 'aoe', 'far', 'iar', 'maxb', 'down', + 'md5s', 'sfn', 'dpi', 'sia', 'phpThumbDebug' + ); -/* iterate through properties */ -foreach ($scriptProperties as $property => $value) { - if (!in_array($property, $allowed, true)) { - $this->modx->log(modX::LOG_LEVEL_WARN, "Detected attempt of using private parameter `$property` (for internal usage) of phpThumb that not allowed and insecure"); - continue; - } - $ptOptions[$property] = $value; -} + /* iterate through properties */ + foreach ($scriptProperties as $property => $value) { + if (!in_array($property, $allowed, true)) { + $this->modx->log(modX::LOG_LEVEL_WARN, "Detected attempt of using private parameter `$property` (for internal usage) of phpThumb that not allowed and insecure"); + continue; + } + $ptOptions[$property] = $value; + } -if (empty($ptOptions['f'])) { - $ext = pathinfo($src, PATHINFO_EXTENSION); - $ext = strtolower($ext); - switch ($ext) { - case 'jpg': - case 'jpeg': - case 'png': - case 'gif': - case 'bmp': - $ptOptions['f'] = $ext; - break; - default: - $ptOptions['f'] = 'jpeg'; - break; - } -} + if (empty($ptOptions['f'])) { + $ext = pathinfo($src, PATHINFO_EXTENSION); + $ext = strtolower($ext); + switch ($ext) { + case 'jpg': + case 'jpeg': + case 'png': + case 'gif': + case 'bmp': + $ptOptions['f'] = $ext; + break; + default: + $ptOptions['f'] = 'jpeg'; + break; + } + } -/* load phpthumb */ -$assetsPath = $modx->getOption('gallery.assets_path', $scriptProperties, $modx->getOption('assets_path') . 'components/gallery/'); -$cacheDir = $assetsPath . 'cache/'; + /* load phpthumb */ + $assetsPath = $modx->getOption('gallery.assets_path', $scriptProperties, $modx->getOption('assets_path') . 'components/gallery/'); + $cacheDir = $assetsPath . 'cache/'; -/* check to make sure cache dir is writable */ -if (!is_writable($cacheDir)) { - if (!$modx->cacheManager->writeTree($cacheDir)) { - $modx->log(modX::LOG_LEVEL_ERROR, '[phpThumbOf] Cache dir not writable: ' . $assetsPath . 'cache/'); - return ''; - } -} + /* check to make sure cache dir is writable */ + if (!is_writable($cacheDir)) { + if (!$modx->cacheManager->writeTree($cacheDir)) { + $modx->log(modX::LOG_LEVEL_ERROR, '[phpThumbOf] Cache dir not writable: ' . $assetsPath . 'cache/'); + return ''; + } + } -/* get absolute url of image */ -if (strpos($src, '/') != 0 && strpos($src, 'http') != 0) { - $src = $modx->getOption('base_url') . $src; -} else { - $src = urldecode($src); -} -/* auto-prepend base path if not a URL */ -if (strpos($src, 'http') === false) { - $basePath = $modx->getOption('base_path', null, MODX_BASE_PATH); - if ($basePath != '/') { - $src = str_replace(basename($basePath), '', $src); - $src = ltrim($src, '/'); - $src = $basePath . $src; - } -} + /* get absolute url of image */ + if (strpos($src, '/') != 0 && strpos($src, 'http') != 0) { + $src = $modx->getOption('base_url') . $src; + } else { + $src = urldecode($src); + } + /* auto-prepend base path if not a URL */ + if (strpos($src, 'http') === false) { + $basePath = $modx->getOption('base_path', null, MODX_BASE_PATH); + if ($basePath != '/') { + $src = str_replace(basename($basePath), '', $src); + $src = ltrim($src, '/'); + $src = $basePath . $src; + } + } -if (!isset($config['modphpthumb'])) { // make sure we get a few relevant system settings - $config['modphpthumb'] = array(); - $config['modphpthumb']['config_allow_src_above_docroot'] = (boolean)$modx->getOption('phpthumb_allow_src_above_docroot', null, false); - $config['modphpthumb']['zc'] = $modx->getOption('phpthumb_zoomcrop', null, 0); - $config['modphpthumb']['far'] = $modx->getOption('phpthumb_far', null, 'C'); - $config['modphpthumb']['config_ttf_directory'] = MODX_CORE_PATH . 'model/phpthumb/fonts/'; - $config['modphpthumb']['config_document_root'] = $modx->getOption('phpthumb_document_root', null, ''); -} -$phpThumb = new phpthumb(); // unfortunately we have to create a new object for each image! -foreach ($config['modphpthumb'] as $param => $value) { // add MODX system settings - $phpThumb->$param = $value; -} -foreach ($ptOptions as $param => $value) { // add options passed to the snippet - $phpThumb->setParameter($param, $value); -} -// try to avert problems when $_SERVER['DOCUMENT_ROOT'] is different than MODX_BASE_PATH -if (!$phpThumb->config_document_root) { - $phpThumb->config_document_root = MODX_BASE_PATH; // default if nothing set from system settings -} -$phpThumb->config_cache_directory = $assetsPath . 'cache/'; // doesn't matter, but saves phpThumb some frustration -$phpThumb->setSourceFilename($src); - -/* setup cache filename that is unique to this tag */ -$inputSanitized = str_replace(array(':', '/'), '_', $src); -$cacheFilename = $inputSanitized; -$cacheFilename .= '.' . md5(serialize($scriptProperties)); -$cacheFilename .= '.' . (!empty($ptOptions['f']) ? $ptOptions['f'] : 'png'); -$cacheKey = $assetsPath . 'cache/' . $cacheFilename; - -/* get cache Url */ -$assetsUrl = $modx->getOption('gallery.assets_url', $scriptProperties, $modx->getOption('assets_url') . 'components/gallery/'); -$cacheUrl = $assetsUrl . 'cache/' . str_replace($cacheDir, '', $cacheKey); -$cacheUrl = str_replace('//', '/', $cacheUrl); - -/* ensure we have an accurate and clean cache directory */ -$phpThumb->CleanUpCacheDirectory(); - -/* debugging code */ -if ($debug) { - $mtime = microtime(); - $mtime = explode(" ", $mtime); - $mtime = $mtime[1] + $mtime[0]; - $tstart = $mtime; - set_time_limit(0); - - $oldLogTarget = $modx->getLogTarget(); - $oldLogLevel = $modx->getLogLevel(); - $modx->setLogLevel(modX::LOG_LEVEL_DEBUG); - $logTarget = $modx->getOption('debugTarget', $scriptProperties, ''); - if (!empty($logTarget)) { - $modx->setLogTarget(); - } -} + if (!isset($config['modphpthumb'])) { // make sure we get a few relevant system settings + $config['modphpthumb'] = array(); + $config['modphpthumb']['config_allow_src_above_docroot'] = (boolean)$modx->getOption('phpthumb_allow_src_above_docroot', null, false); + $config['modphpthumb']['zc'] = $modx->getOption('phpthumb_zoomcrop', null, 0); + $config['modphpthumb']['far'] = $modx->getOption('phpthumb_far', null, 'C'); + $config['modphpthumb']['config_ttf_directory'] = MODX_CORE_PATH . 'model/phpthumb/fonts/'; + $config['modphpthumb']['config_document_root'] = $modx->getOption('phpthumb_document_root', null, ''); + } + $phpThumb = new phpthumb(); // unfortunately we have to create a new object for each image! + foreach ($config['modphpthumb'] as $param => $value) { // add MODX system settings + $phpThumb->$param = $value; + } + foreach ($ptOptions as $param => $value) { // add options passed to the snippet + $phpThumb->setParameter($param, $value); + } + // try to avert problems when $_SERVER['DOCUMENT_ROOT'] is different than MODX_BASE_PATH + if (!$phpThumb->config_document_root) { + $phpThumb->config_document_root = MODX_BASE_PATH; // default if nothing set from system settings + } + $phpThumb->config_cache_directory = $assetsPath . 'cache/'; // doesn't matter, but saves phpThumb some frustration + $phpThumb->setSourceFilename($src); + + /* setup cache filename that is unique to this tag */ + $inputSanitized = str_replace(array(':', '/'), '_', $src); + $cacheFilename = $inputSanitized; + $cacheFilename .= '.' . md5(serialize($scriptProperties)); + $cacheFilename .= '.' . (!empty($ptOptions['f']) ? $ptOptions['f'] : 'png'); + $cacheKey = $assetsPath . 'cache/' . $cacheFilename; + + /* get cache Url */ + $assetsUrl = $modx->getOption('gallery.assets_url', $scriptProperties, $modx->getOption('assets_url') . 'components/gallery/'); + $cacheUrl = $assetsUrl . 'cache/' . str_replace($cacheDir, '', $cacheKey); + $cacheUrl = str_replace('//', '/', $cacheUrl); + + /* ensure we have an accurate and clean cache directory */ + $phpThumb->CleanUpCacheDirectory(); + + /* debugging code */ + if ($debug) { + $mtime = microtime(); + $mtime = explode(" ", $mtime); + $mtime = $mtime[1] + $mtime[0]; + $tstart = $mtime; + set_time_limit(0); + + $oldLogTarget = $modx->getLogTarget(); + $oldLogLevel = $modx->getLogLevel(); + $modx->setLogLevel(modX::LOG_LEVEL_DEBUG); + $logTarget = $modx->getOption('debugTarget', $scriptProperties, ''); + if (!empty($logTarget)) { + $modx->setLogTarget(); + } + } -/* ensure file has proper permissions */ -if (!empty($cacheKey)) { - $filePerm = (int)$modx->getOption('new_file_permissions', $scriptProperties, '0664'); - @chmod($cacheKey, octdec($filePerm)); -} -if ($debug) { - $mtime = microtime(); - $mtime = explode(" ", $mtime); - $mtime = $mtime[1] + $mtime[0]; - $tend = $mtime; - $totalTime = ($tend - $tstart); - $totalTime = sprintf("%2.4f s", $totalTime); - - $modx->log(modX::LOG_LEVEL_DEBUG, "\n
Execution time: {$totalTime}\n
"); - $modx->setLogLevel($oldLogLevel); - $modx->setLogTarget($oldLogTarget); -} -$output = $assetsUrl; - - -/* check to see if there's a cached file of this already */ -if (file_exists($cacheKey)) { - $modx->log(modX::LOG_LEVEL_DEBUG, '[phpThumbOf] Using cached file found for thumb: ' . $cacheKey); - $output = str_replace(' ', '%20', $cacheUrl); -} else { - /* actually make the thumbnail */ - //return $cacheKey; - if ($phpThumb->GenerateThumbnail()) { // this line is VERY important, do not remove it! - if ($phpThumb->RenderToFile($cacheKey)) { + /* ensure file has proper permissions */ + if (!empty($cacheKey)) { + $filePerm = (int)$modx->getOption('new_file_permissions', $scriptProperties, '0664'); + @chmod($cacheKey, octdec($filePerm)); + } + if ($debug) { + $mtime = microtime(); + $mtime = explode(" ", $mtime); + $mtime = $mtime[1] + $mtime[0]; + $tend = $mtime; + $totalTime = ($tend - $tstart); + $totalTime = sprintf("%2.4f s", $totalTime); + + $modx->log(modX::LOG_LEVEL_DEBUG, "\n
Execution time: {$totalTime}\n
"); + $modx->setLogLevel($oldLogLevel); + $modx->setLogTarget($oldLogTarget); + } + $output = $assetsUrl; + + + /* check to see if there's a cached file of this already */ + if (file_exists($cacheKey)) { + $modx->log(modX::LOG_LEVEL_DEBUG, '[phpThumbOf] Using cached file found for thumb: ' . $cacheKey); $output = str_replace(' ', '%20', $cacheUrl); } else { - $modx->log(modX::LOG_LEVEL_ERROR, '[phpThumbOf] Could not cache thumb "' . $src . '" to file at: ' . $cacheKey . ' - Debug: ' . print_r($phpThumb->debugmessages, true)); + /* actually make the thumbnail */ + //return $cacheKey; + if ($phpThumb->GenerateThumbnail()) { // this line is VERY important, do not remove it! + if ($phpThumb->RenderToFile($cacheKey)) { + $output = str_replace(' ', '%20', $cacheUrl); + } else { + $modx->log(modX::LOG_LEVEL_ERROR, '[phpThumbOf] Could not cache thumb "' . $src . '" to file at: ' . $cacheKey . ' - Debug: ' . print_r($phpThumb->debugmessages, true)); + } + } else { + $modx->log(modX::LOG_LEVEL_ERROR, '[phpThumbOf] Could not generate thumbnail: ' . $src . ' - Debug: ' . print_r($phpThumb->debugmessages, true)); + } } - } else { - $modx->log(modX::LOG_LEVEL_ERROR, '[phpThumbOf] Could not generate thumbnail: ' . $src . ' - Debug: ' . print_r($phpThumb->debugmessages, true)); - } -} -if (!headers_sent()) { - $headers = $modx->request->getHeaders(); - $mtime = filemtime($cacheKey); - if (isset($headers['If-Modified-Since']) && strtotime($headers['If-Modified-Since']) == $mtime) { - // cache is good, send 304 - header('Last-Modified: '.gmdate('D, d M Y H:i:s', $mtime).' GMT', true, 304); - exit(); + if (!headers_sent()) { + $headers = $modx->request->getHeaders(); + $mtime = filemtime($cacheKey); + if (isset($headers['If-Modified-Since']) && strtotime($headers['If-Modified-Since']) == $mtime) { + // cache is good, send 304 + header('Last-Modified: '.gmdate('D, d M Y H:i:s', $mtime).' GMT', true, 304); + exit(); + } + header('Last-Modified: '.gmdate('D, d M Y H:i:s', $mtime).' GMT', true, 200); + $phpThumb->setOutputFormat(); + header('Content-Type: '.phpthumb_functions::ImageTypeToMIMEtype($phpThumb->thumbnailFormat)); + header('Content-Disposition: inline; filename="'.basename($src).'"'); + } + + return file_get_contents($cacheKey); } - header('Last-Modified: '.gmdate('D, d M Y H:i:s', $mtime).' GMT', true, 200); - $phpThumb->setOutputFormat(); - header('Content-Type: '.phpthumb_functions::ImageTypeToMIMEtype($phpThumb->thumbnailFormat)); - header('Content-Disposition: inline; filename="'.basename($src).'"'); } - -return file_get_contents($cacheKey); +return 'GalleryPhpthumbProcessor'; From 0b6a380dd1661980d12381269e29148997efb58a Mon Sep 17 00:00:00 2001 From: halftrainedharry Date: Wed, 20 Apr 2022 10:14:14 +0200 Subject: [PATCH 05/20] rename flat-file processor files --- .../processors/mgr/item/{ajaxupload.php => ajaxupload.class.php} | 0 .../mgr/item/{batchupload.php => batchupload.class.php} | 0 .../gallery/processors/mgr/item/{sort.php => sort.class.php} | 0 .../processors/mgr/item/{zipupload.php => zipupload.class.php} | 0 .../gallery/processors/web/{phpthumb.php => phpthumb.class.php} | 0 5 files changed, 0 insertions(+), 0 deletions(-) rename core/components/gallery/processors/mgr/item/{ajaxupload.php => ajaxupload.class.php} (100%) rename core/components/gallery/processors/mgr/item/{batchupload.php => batchupload.class.php} (100%) rename core/components/gallery/processors/mgr/item/{sort.php => sort.class.php} (100%) rename core/components/gallery/processors/mgr/item/{zipupload.php => zipupload.class.php} (100%) rename core/components/gallery/processors/web/{phpthumb.php => phpthumb.class.php} (100%) diff --git a/core/components/gallery/processors/mgr/item/ajaxupload.php b/core/components/gallery/processors/mgr/item/ajaxupload.class.php similarity index 100% rename from core/components/gallery/processors/mgr/item/ajaxupload.php rename to core/components/gallery/processors/mgr/item/ajaxupload.class.php diff --git a/core/components/gallery/processors/mgr/item/batchupload.php b/core/components/gallery/processors/mgr/item/batchupload.class.php similarity index 100% rename from core/components/gallery/processors/mgr/item/batchupload.php rename to core/components/gallery/processors/mgr/item/batchupload.class.php diff --git a/core/components/gallery/processors/mgr/item/sort.php b/core/components/gallery/processors/mgr/item/sort.class.php similarity index 100% rename from core/components/gallery/processors/mgr/item/sort.php rename to core/components/gallery/processors/mgr/item/sort.class.php diff --git a/core/components/gallery/processors/mgr/item/zipupload.php b/core/components/gallery/processors/mgr/item/zipupload.class.php similarity index 100% rename from core/components/gallery/processors/mgr/item/zipupload.php rename to core/components/gallery/processors/mgr/item/zipupload.class.php diff --git a/core/components/gallery/processors/web/phpthumb.php b/core/components/gallery/processors/web/phpthumb.class.php similarity index 100% rename from core/components/gallery/processors/web/phpthumb.php rename to core/components/gallery/processors/web/phpthumb.class.php From 9c62e95874367e1a898f5ad4fc3d69b93f7a2660 Mon Sep 17 00:00:00 2001 From: halftrainedharry Date: Wed, 20 Apr 2022 10:42:47 +0200 Subject: [PATCH 06/20] fix navigation | remove modAction --- _build/data/transport.menu.php | 20 ++++--------------- .../gallery/js/mgr/sections/album/update.js | 2 +- assets/components/gallery/js/mgr/tree.js | 2 +- .../js/mgr/widgets/album/album.tree.js | 2 +- .../js/mgr/widgets/album/albums.grid.js | 2 +- .../controllers/album/update.class.php | 8 +++++++- .../gallery/controllers/home.class.php | 2 ++ .../plugins/gallerycustomtv.plugin.php | 13 ++++++++---- .../processors/mgr/album/getnodes.class.php | 14 +++++++++---- 9 files changed, 36 insertions(+), 29 deletions(-) diff --git a/_build/data/transport.menu.php b/_build/data/transport.menu.php index 25f3c66..0f480aa 100644 --- a/_build/data/transport.menu.php +++ b/_build/data/transport.menu.php @@ -20,34 +20,22 @@ * @package gallery */ /** - * Adds modActions and modMenus into package + * Adds modMenus into package * * @package gallery * @subpackage build */ -$action= $modx->newObject('modAction'); -$action->fromArray(array( - 'id' => 1, - 'namespace' => 'gallery', - 'parent' => 0, - 'controller' => 'index', - 'haslayout' => 1, - 'lang_topics' => 'gallery:default', - 'assets' => '', -),'',true,true); - -/* load action into menu */ $menu= $modx->newObject('modMenu'); $menu->fromArray(array( 'text' => 'gallery', 'parent' => 'components', 'description' => 'gallery.menu_desc', - 'icon' => 'images/icons/plugin.gif', + 'icon' => '', 'menuindex' => 0, + 'action' => 'home', + 'namespace' => 'gallery', 'params' => '', 'handler' => '', ),'',true,true); -$menu->addOne($action); -unset($action); return $menu; \ No newline at end of file diff --git a/assets/components/gallery/js/mgr/sections/album/update.js b/assets/components/gallery/js/mgr/sections/album/update.js index 69de8fd..5b3282f 100644 --- a/assets/components/gallery/js/mgr/sections/album/update.js +++ b/assets/components/gallery/js/mgr/sections/album/update.js @@ -17,7 +17,7 @@ GAL.page.UpdateAlbum = function(config) { text: _('gallery.back') ,id: 'gal-btn-back' ,handler: function() { - location.href = '?a='+MODx.request.a+'&view=index'; + MODx.loadPage('home', 'namespace=gallery'); } ,scope: this }] diff --git a/assets/components/gallery/js/mgr/tree.js b/assets/components/gallery/js/mgr/tree.js index 0a910e0..029062c 100644 --- a/assets/components/gallery/js/mgr/tree.js +++ b/assets/components/gallery/js/mgr/tree.js @@ -112,7 +112,7 @@ Ext.extend(galTreeHandlerClass,Ext.Component,{ } ,updateAlbum: function(btn,e) { var id = this.data.id ? this.data.id : 0; - location.href = '?a='+MODx.action['gallery:index']+'&album='+id+'&action=album/update'; + MODx.loadPage('album/update', 'namespace=gallery&album='+id); } ,removeAlbum: function(btn,e) { MODx.msg.confirm({ diff --git a/assets/components/gallery/js/mgr/widgets/album/album.tree.js b/assets/components/gallery/js/mgr/widgets/album/album.tree.js index ca29059..c1d01c6 100644 --- a/assets/components/gallery/js/mgr/widgets/album/album.tree.js +++ b/assets/components/gallery/js/mgr/widgets/album/album.tree.js @@ -52,7 +52,7 @@ Ext.extend(GAL.tree.Album,MODx.tree.Tree,{ ,updateAlbum: function(btn,e) { var id = this.cm.activeNode ? this.cm.activeNode.attributes.pk : 0; - location.href = '?a='+GAL.action+'&album='+id+'&action=album/update'; + MODx.loadPage('album/update', 'namespace=gallery&album='+id); } ,removeAlbum: function(btn,e) { diff --git a/assets/components/gallery/js/mgr/widgets/album/albums.grid.js b/assets/components/gallery/js/mgr/widgets/album/albums.grid.js index ecb98a8..0f8bd38 100644 --- a/assets/components/gallery/js/mgr/widgets/album/albums.grid.js +++ b/assets/components/gallery/js/mgr/widgets/album/albums.grid.js @@ -55,7 +55,7 @@ Ext.extend(GAL.grid.Albums,MODx.grid.Grid,{ ,updateAlbum: function(btn,e) { if (!this.menu.record || !this.menu.record.id) return false; - location.href = '?a='+MODx.request.a+'&action=album/update'+'&album='+this.menu.record.id; + MODx.loadPage('album/update', 'namespace=gallery&album='+this.menu.record.id); } ,removeAlbum: function(btn,e) { diff --git a/core/components/gallery/controllers/album/update.class.php b/core/components/gallery/controllers/album/update.class.php index 24d8458..d6cc29f 100644 --- a/core/components/gallery/controllers/album/update.class.php +++ b/core/components/gallery/controllers/album/update.class.php @@ -27,6 +27,8 @@ * @var modX $this->modx * @var Gallery $gallery */ +require_once dirname(__FILE__,3) . '/index.class.php'; + class GalleryAlbumUpdateManagerController extends GalleryManagerController { public function getPageTitle() { return $this->modx->lexicon('gallery.album_update'); } public function loadCustomCssJs() { @@ -62,7 +64,11 @@ public function checkForTinyMCE() { $css = $this->modx->getOption('gallery.tiny.theme_advanced_css_selectors',null,''); /** @var modAction $browserAction */ - $browserAction = $this->modx->getObject('modAction',array('controller' => 'browser')); + $browserAction = null; + if ($this->modx->getVersionData()['version'] < 3){ + //V2 + $browserAction = $this->modx->getObject('modAction',array('controller' => 'browser')); + } /* If the settings are empty, override them with the generic tinymce settings. */ $tinyProperties = array( diff --git a/core/components/gallery/controllers/home.class.php b/core/components/gallery/controllers/home.class.php index c8a6df4..102b109 100644 --- a/core/components/gallery/controllers/home.class.php +++ b/core/components/gallery/controllers/home.class.php @@ -25,6 +25,8 @@ * @package gallery * @subpackage controllers */ +require_once dirname(__FILE__,2) . '/index.class.php'; + class GalleryHomeManagerController extends GalleryManagerController { public function getPageTitle() { return $this->modx->lexicon('gallery'); } public function loadCustomCssJs() { diff --git a/core/components/gallery/elements/plugins/gallerycustomtv.plugin.php b/core/components/gallery/elements/plugins/gallerycustomtv.plugin.php index ba7f63e..1376815 100644 --- a/core/components/gallery/elements/plugins/gallerycustomtv.plugin.php +++ b/core/components/gallery/elements/plugins/gallerycustomtv.plugin.php @@ -51,10 +51,15 @@ $modx->controller->addLexiconTopic('gallery:tv'); /* @var modAction $action */ - $action = $modx->getObject('modAction',array( - 'namespace' => 'gallery', - 'controller' => 'index', - )); + $action = null; + if ($this->modx->getVersionData()['version'] < 3){ + //V2 + $action = $modx->getObject('modAction',array( + 'namespace' => 'gallery', + 'controller' => 'index', + )); + } + $modx->controller->addHtml('