public function __construct(ObjectFile $objectFile) { if ($objectFile->isLocalFile()) { $this->file = $objectFile; $this->setHeader('Cache-Control', 'no-cache, must-revalidate'); $this->setHeader('Expires', 'Mon, 26 Jul 1997 05:00:00 GMT'); $this->setHeader('Content-type', $objectFile->getMimeType()); $this->setHeader('Content-Disposition', 'attachment; filename="' . $objectFile->getBaseName() . '"'); $this->setHeader('Content-Length', (string) $objectFile->getSize()); $this->setHeader('Content-Encoding', 'none'); } else { $this->setHeader('Location', $objectFile->filePath->get()); } }
public function export() { // preload current locale $this->locale; $tempDir = ClassLoader::getRealPath('cache.tmp.' . rand(1, 10000000)); $locale = Locale::getInstance($this->request->get('id')); $fileDir = ClassLoader::getRealPath('application.configuration.language.en'); $files = $locale->translationManager()->getDefinitionFiles($fileDir); // prepare language files $translated = array(); foreach ($files as $file) { $relPath = substr($file, strlen($fileDir) + 1); // get language default definitions $default = $locale->translationManager()->getFileDefs($relPath, true); if (!is_array($default)) { $default = array(); } // get translated definitions $transl = $locale->translationManager()->getCacheDefs($relPath, true); $transl = array_merge($default, $transl); $values = array(); foreach ($transl as $key => $value) { $values[] = $key . '=' . $value; } $path = $tempDir . '/' . $locale->getLocaleCode() . '/' . $relPath; if ($values) { if (!is_dir(dirname($path))) { mkdir(dirname($path), 0777, true); } file_put_contents($path, implode("\n", $values)); } } // put the files in zip archive require_once ClassLoader::getRealPath('library.pclzip') . '/pclzip.lib.php'; if (!is_dir($tempDir)) { return new ActionRedirectResponse('backend.language', 'edit', array('id' => $locale->getLocaleCode())); } chdir($tempDir); $zip = dirname($tempDir) . '/temp_' . rand(1, 10000) . '.zip'; $archive = new PclZip($zip); $archive->add($locale->getLocaleCode()); // remove the temp directory $this->application->rmdir_recurse($tempDir); $response = new ObjectFileResponse(ObjectFile::getNewInstance('ObjectFile', $zip, 'LiveCart-' . $locale->getLocaleCode() . '.zip')); $response->deleteFileOnComplete(); return $response; }
/** * Loads a set of ProductFile instances * * @param ARSelectFilter $filter * @param bool $loadReferencedRecords * * @return ARSet */ public static function getRecordSet(ARSelectFilter $filter, $loadReferencedRecords = false) { return parent::getRecordSet(__CLASS__, $filter, $loadReferencedRecords); }
public function export() { require_once ClassLoader::getRealPath('library.pclzip') . '/pclzip.lib.php'; $id = $this->getRequest()->get('id'); $files = $this->getThemeFiles($id); if ($files === null) { return new ActionRedirectResponse('backend.theme', 'index'); } do { $path = ClassLoader::getRealPath('cache.tmp.theme_export_' . rand(1, 10000000)); } while (file_exists($path)); $zipFilePath = $path . '_archive.zip'; $confFilePath = $path . DIRECTORY_SEPARATOR . 'theme.conf'; foreach (array($zipFilePath, $confFilePath) as $fp) { if (!is_dir(dirname($fp))) { mkdir(dirname($fp), 0777, true); } } file_put_contents($confFilePath, sprintf('[Theme]' . "\n" . 'name = %s', $id)); $archive = new PclZip($zipFilePath); chdir(ClassLoader::getBaseDir()); $files[] = $confFilePath; $archive->add($files, PCLZIP_OPT_REMOVE_PATH, $path); $this->application->rmdir_recurse($path); $response = new ObjectFileResponse(ObjectFile::getNewInstance('ObjectFile', $zipFilePath, $id . '.zip')); $response->deleteFileOnComplete(); return $response; }
public function getFile() { return ObjectFile::getNewInstance('ObjectFile', self::getFilePath($this->optionText->get()), self::getFileName($this->optionText->get())); }