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; }
/** * Create new instance of product file * * @param Product $product Product to which the file belongs * @param string $filePath Path to that file (possibly a temporary file) * @param string $fileName File name with extension. (image.jpg) * @return ActiveRecord */ public static function getNewInstance(Product $product, $filePath, $fileName, $pathOrUrl = null) { $productFileInstance = parent::getNewInstance(__CLASS__, $filePath, $fileName, $pathOrUrl); $productFileInstance->product->set($product); return $productFileInstance; }
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())); }