public static function zip($themeName, $addFiles = false, $exclude = null) { $websiteHelper = Zend_Controller_Action_HelperBroker::getStaticHelper('website'); $configHelper = Zend_Controller_Action_HelperBroker::getStaticHelper('config'); $themesConfig = Zend_Registry::get('theme'); $zip = new ZipArchive(); $destinationFile = $websiteHelper->getPath() . $websiteHelper->getTmp() . $themeName . '.zip'; $themePath = $websiteHelper->getPath() . $themesConfig['path'] . $themeName; if (true === $zip->open($destinationFile, ZIPARCHIVE::CREATE)) { $themeFiles = Tools_Filesystem_Tools::scanDirectory($themePath, true, true); foreach ($themeFiles as $file) { if (is_array($exclude) && in_array(Tools_Filesystem_Tools::basename($file), $exclude)) { continue; } $localName = str_replace($themePath, '', $file); $localName = trim($localName, DIRECTORY_SEPARATOR); $zip->addFile($file, $localName); unset($localName); } if (!empty($addFiles)) { foreach ($addFiles as $file) { $file = urldecode($file); $realPath = $websiteHelper->getPath() . $file; if (!file_exists($realPath)) { continue; } elseif (is_array($exclude) && in_array(Tools_Filesystem_Tools::basename($file), $exclude)) { continue; } $pathParts = explode(DIRECTORY_SEPARATOR, $file); if ($pathParts[0] === 'media' && sizeof($pathParts) === 4) { // removing original folder level from zip unset($pathParts[2]); $zip->addFile($websiteHelper->getPath() . $file, implode(DIRECTORY_SEPARATOR, $pathParts)); } else { // assume that this is a preview file $zip->addFile($realPath, $file); } unset($realPath, $pathParts); } } $zip->close(); return $destinationFile; } else { throw new Exceptions_SeotoasterException('Unable to write ' . $destinationFile); } }
public static function minifyJs($jsList) { $websiteHelper = Zend_Controller_Action_HelperBroker::getExistingHelper('website'); $cacheHelper = Zend_Controller_Action_HelperBroker::getExistingHelper('cache'); if (null === ($hashStack = $cacheHelper->load(strtolower(__CLASS__), ''))) { $hashStack = array(); } $container = $jsList->getContainer(); foreach ($container->getArrayCopy() as $js) { if (isset($js->attributes['src'])) { if (strpos($js->attributes['src'], $websiteHelper->getUrl()) === false) { continue; //ignore file if file from remote } if (isset($js->attributes['nominify']) || preg_match('/min\\.js$/', $js->attributes['src']) != false) { continue; //ignore file if special attribute given or src ends with 'min.js' } $path = str_replace($websiteHelper->getUrl(), '', $js->attributes['src']); if (!file_exists($websiteHelper->getPath() . $path)) { continue; } $hash = sha1_file($websiteHelper->getPath() . $path); if (!isset($hashStack[$path]) || $hashStack[$path]['hash'] !== $hash) { $hashStack[$path] = array('hash' => $hash, 'content' => JSMin::minify(Tools_Filesystem_Tools::getFile($websiteHelper->getPath() . $path))); Tools_Filesystem_Tools::saveFile($websiteHelper->getPath() . $websiteHelper->getTmp() . $hash . '.min.js', $hashStack[$path]['content']); } $js->attributes['src'] = $websiteHelper->getUrl() . $websiteHelper->getTmp() . $hash . '.min.js?' . Tools_Filesystem_Tools::basename($path); } elseif (!empty($js->source)) { if (!isset($js->attributes['nominify'])) { $js->source = JSMin::minify($js->source); } } } $cacheHelper->save(strtolower(__CLASS__), $hashStack, '', array(), Helpers_Action_Cache::CACHE_LONG); return $jsList; }
public static function optimizeOriginalImage($imageFile, $savePath, $quality) { $fileInfo = getimagesize($imageFile); $mimeType = $fileInfo['mime']; $destination = $savePath . DIRECTORY_SEPARATOR . 'original' . DIRECTORY_SEPARATOR; $optimizedImageName = preg_replace('~\\.[a-zA-Z]{3,4}~iu', '.jpg', Tools_Filesystem_Tools::basename($imageFile)); switch ($mimeType) { case 'image/gif': $image = imagecreatefromgif($imageFile); imagejpeg($image, $destination . $optimizedImageName, $quality); imagedestroy($image); Tools_Filesystem_Tools::deleteFile($imageFile); break; case 'image/jpg': case 'image/jpeg': $image = imagecreatefromjpeg($imageFile); Tools_Filesystem_Tools::deleteFile($imageFile); imagejpeg($image, $destination . $optimizedImageName, $quality); imagedestroy($image); break; case 'image/png': $image = imagecreatefrompng($imageFile); $bg = imagecreatetruecolor(imagesx($image), imagesy($image)); imagefill($bg, 0, 0, imagecolorallocate($bg, 255, 255, 255)); imagealphablending($bg, true); imagecopy($bg, $image, 0, 0, 0, 0, imagesx($image), imagesy($image)); imagedestroy($image); imagejpeg($bg, $destination . $optimizedImageName, 90); imageDestroy($bg); Tools_Filesystem_Tools::deleteFile($imageFile); break; default: return 'Unknow MIME type'; break; } }
public function exportAction() { if ($this->getRequest()->isPost()) { if (Tools_Security_Acl::isAllowed(Tools_Security_Acl::RESOURCE_USERS)) { $users = Application_Model_Mappers_UserMapper::getInstance()->fetchAll(); $dataToExport = array(); foreach ($users as $user) { $usrData = $user->toArray(); unset($usrData['password']); unset($usrData['id']); unset($usrData['attributes']); $dataToExport[] = $usrData; } $exportResult = Tools_System_Tools::arrayToCsv($dataToExport, array($this->_helper->language->translate('E-mail'), $this->_helper->language->translate('Role'), $this->_helper->language->translate('Full name'), $this->_helper->language->translate('Last login date'), $this->_helper->language->translate('Registration date'), $this->_helper->language->translate('IP address'))); if ($exportResult) { $usersArchive = Tools_System_Tools::zip($exportResult); $this->getResponse()->setHeader('Content-Disposition', 'attachment; filename=' . Tools_Filesystem_Tools::basename($usersArchive))->setHeader('Content-type', 'application/force-download'); readfile($usersArchive); $this->getResponse()->sendResponse(); } exit; } } }