/** * 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; }
/** * Saves the new image wherever you want * @todo In case the PHP script has no write access to the location set by $this->newImageFile, * the image shall be sent to the output buffer and then be put into the new file * location using the FileSystemFile object. * @access public * @param string $file The path for the image file to be written. * @param booelan $forceOverwrite Force overwriting existing files if true. * @return boolean True on success, false otherwise. */ public function saveNewImage($file, $forceOverwrite = false) { // TODO: Add some sort of diagnostics (Message) here and elsewhere in this class if (!$this->imageCheck) { return false; } if (empty($this->newImage)) { return false; } if (file_exists($file)) { if (!$forceOverwrite) { return false; } \Cx\Lib\FileSystem\FileSystem::makeWritable($file); } else { try { $objFile = new \Cx\Lib\FileSystem\File($file); $objFile->touch(); } catch (\Cx\Lib\FileSystem\FileSystemException $e) { \DBG::msg($e->getMessage()); } } // TODO: Unfortunately, the functions imagegif(), imagejpeg() and imagepng() can't use the Cloudrexx FileSystem wrapper, // therefore we need to set the global write access image files. // This issue might be solved by using the output-buffer and write the image manually afterwards. // // IMPORTANT: In case something went wrong (see bug #1441) and the path $strPathNew.$strFileNew refers to a directory // we must abort the operation here, otherwise we would remove the execution flag on a directory, which would // cause to remove any browsing access to the directory. if (is_dir($file)) { return false; } \Cx\Lib\FileSystem\FileSystem::chmod($file, 0666); //\Cx\Lib\FileSystem\FileSystem::CHMOD_FILE); $this->newImageFile = $file; if ($this->newImageType == self::IMG_TYPE_PNG) { $this->setTransparency(); } switch ($this->newImageType) { case self::IMG_TYPE_GIF: $function = 'imagegif'; if (!function_exists($function)) { $function = 'imagejpeg'; } break; case self::IMG_TYPE_JPEG: $function = 'imagejpeg'; break; case self::IMG_TYPE_PNG: // make a jpeg thumbnail, too $function = 'imagepng'; break; default: return false; } // Only adjust quality, if it is set. if ($this->newImageQuality != '') { $function($this->newImage, $this->newImageFile, $this->getQuality()); } else { $function($this->newImage, $this->newImageFile); } return true; }