/** * Regenerate the thumbnails * * @param array $post $_POST values */ protected function generateThumbnail($post) { // release the locks, session not needed $session = \cmsSession::getInstance(); $session->releaseLocks(); session_write_close(); $cx = Cx::instanciate(); $key = $_GET['key']; if (!preg_match("/[A-Z0-9]{5}/i", $key)) { die; } $processFile = $session->getTempPath() . '/progress' . $key . '.txt'; if (\Cx\Lib\FileSystem\FileSystem::exists($processFile)) { die; } try { $objProcessFile = new \Cx\Lib\FileSystem\File($processFile); $objProcessFile->touch(); } catch (\Cx\Lib\FileSystem\FileSystemException $ex) { die; } $recursiveIteratorIterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($cx->getWebsiteImagesPath() . '/'), \RecursiveIteratorIterator::SELF_FIRST); $jsonFileArray = array(); $thumbnailList = UploaderConfiguration::getInstance()->getThumbnails(); $imageManager = new \ImageManager(); $fileCounter = 0; $generalSuccess = true; $imageFiles = array(); foreach ($recursiveIteratorIterator as $file) { /** * @var $file \SplFileInfo */ $extension = 'Dir'; if (!$file->isDir()) { $extension = ucfirst(pathinfo($file->getFilename(), PATHINFO_EXTENSION)); } $filePathinfo = pathinfo($file->getRealPath()); $fileNamePlain = $filePathinfo['filename']; // set preview if image $preview = 'none'; $fileInfos = array('filepath' => mb_strcut($file->getPath() . '/' . $file->getFilename(), mb_strlen($cx->getCodeBasePath())), 'name' => $file->getFilename(), 'cleansize' => $file->getSize(), 'extension' => ucfirst(mb_strtolower($extension)), 'type' => $file->getType()); // filters if ($fileInfos['name'] == '.' || preg_match('/\\.thumb/', $fileInfos['name']) || $fileInfos['name'] == 'index.php' || 0 === strpos($fileInfos['name'], '.')) { continue; } if (!preg_match("/(jpg|jpeg|gif|png)/i", ucfirst($extension))) { continue; } $imageFiles[] = $file; } $imageFilesCount = count($imageFiles); if ($imageFilesCount == 0) { $objProcessFile->write(100); die; } foreach ($imageFiles as $file) { /** * @var $file \SplFileInfo */ $extension = 'Dir'; if (!$file->isDir()) { $extension = ucfirst(pathinfo($file->getFilename(), PATHINFO_EXTENSION)); } $filePathinfo = pathinfo($file->getRealPath()); $fileNamePlain = $filePathinfo['filename']; $fileInfos = array('filepath' => mb_strcut($file->getPath() . '/' . $file->getFilename(), mb_strlen(ASCMS_PATH)), 'name' => $file->getFilename(), 'cleansize' => $file->getSize(), 'extension' => ucfirst(mb_strtolower($extension)), 'type' => $file->getType()); $filePathinfo = pathinfo($file->getRealPath()); $fileExtension = isset($filePathinfo['extension']) ? $filePathinfo['extension'] : ''; $preview = $cx->getCodeBaseOffsetPath() . str_replace($cx->getCodeBaseDocumentRootPath(), '', $file->getRealPath()); $previewList = array(); foreach ($thumbnailList as $thumbnail) { $previewList[] = str_replace('.' . lcfirst($extension), $thumbnail['value'] . '.' . lcfirst($extension), $preview); } $allThumbnailsExists = true; foreach ($previewList as $previewImage) { if (!FileSystem::exists($previewImage)) { $allThumbnailsExists = false; } } if (!$allThumbnailsExists) { if ($imageManager->_isImage($file->getRealPath())) { ThumbnailGenerator::createThumbnail($file->getPath(), $fileNamePlain, $fileExtension, $imageManager, true); } } $fileCounter++; $objProcessFile->write($fileCounter / $imageFilesCount * 100); } $objProcessFile->write(100); die; }
/** * Create Thumbnails for file * * @param $params array * * @return bool */ public function createThumbnails($params) { if (isset($params['get']['file'])) { ThumbnailGenerator::createThumbnailFromPath($params['get']['file']); return true; } return false; }