/** * @param $folder * @param $url * @param $options * @return bool */ public function makeThumb($folder, $url, $options) { if (empty($url)) { return false; } $thumb = new \Helpers\PHPThumb(); $inputFile = MODX_BASE_PATH . $this->fs->relativePath($url); $outputFile = MODX_BASE_PATH . $this->fs->relativePath($folder) . '/' . $this->fs->relativePath($url); $dir = $this->fs->takeFileDir($outputFile); $this->fs->makeDir($dir, $this->modx->config['new_folder_permissions']); if ($thumb->create($inputFile, $outputFile, $options)) { return true; } else { $this->modx->logEvent(0, 3, $thumb->debugMessages, __NAMESPACE__); return false; } }
function getThumbConfig($tconfig, $rid, $template) { $out = array(); include_once MODX_BASE_PATH . 'assets/snippets/DocLister/lib/jsonHelper.class.php'; $thumbs = \jsonHelper::jsonDecode(urldecode($tconfig), array('assoc' => true), true); foreach ($thumbs as $thumb) { if ($thumb['rid'] == $rid || $thumb['template'] == $template) { $out = $thumb; break; } } return $out; } } if ($e->name == "OnFileBrowserUpload" && isset($template) || $e->name == "OnSimpleGalleryRefresh") { $thumb = new \Helpers\PHPThumb(); $thumb->optimize($filepath . '/' . $filename); $fs = \Helpers\FS::getInstance(); $thumbConfig = getThumbConfig($tconfig, $sg_rid, $template); if (!empty($thumbConfig)) { extract($thumbConfig); $fs->makeDir($filepath . '/' . $folder); $thumb->create($filepath . '/' . $filename, $filepath . '/' . $folder . '/' . $filename, $options); $thumb->optimize($filepath . '/' . $folder . '/' . $filename); } } if ($e->name == "OnSimpleGalleryDelete") { $fs = \Helpers\FS::getInstance(); $thumbConfig = getThumbConfig($tconfig, $sg_rid, $template); if (!empty($thumbConfig)) { extract($thumbConfig);