/** * Export the locale files to the browser as a tarball. * Requires tar for operation (configured in config.inc.php). * @param $locale string Locale code for exported locale */ function export($locale) { // Construct the tar command $tarBinary = Config::getVar('cli', 'tar'); if (empty($tarBinary) || !file_exists($tarBinary)) { // We can use fatalError() here as we already have a user // friendly way of dealing with the missing tar on the // index page. fatalError('The tar binary must be configured in config.inc.php\'s cli section to use the export function of this plugin!'); } $command = $tarBinary . ' cz'; $localeFilesList = TranslatorAction::getLocaleFiles($locale); $localeFilesList = array_merge($localeFilesList, TranslatorAction::getMiscLocaleFiles($locale)); $emailTemplateDao = DAORegistry::getDAO('EmailTemplateDAO'); $localeFilesList[] = $emailTemplateDao->getMainEmailTemplateDataFilename($locale); foreach (array_values(TranslatorAction::getEmailFileMap($locale)) as $emailFile) { } // Include locale files (main file and plugin files) foreach ($localeFilesList as $file) { if (file_exists($file)) { $command .= ' ' . escapeshellarg($file); } } header('Content-Type: application/x-gtar'); header("Content-Disposition: attachment; filename=\"{$locale}.tar.gz\""); header('Cache-Control: private'); // Workarounds for IE weirdness passthru($command); }
function getEmailTemplates($locale) { $files = TranslatorAction::getEmailFileMap($locale); $returner = array(); foreach ($files as $templateFile => $templateDataFile) { $xmlParser = new XMLParser(); $data = null; if (file_exists($templateDataFile)) { $data =& $xmlParser->parse($templateDataFile); } if ($data) { foreach ($data->getChildren() as $emailNode) { $returner[$emailNode->getAttribute('key')] = array('subject' => $emailNode->getChildValue('subject'), 'body' => $emailNode->getChildValue('body'), 'description' => $emailNode->getChildValue('description'), 'templateFile' => $templateFile, 'templateDataFile' => $templateDataFile); } } unset($xmlParser, $data); } return $returner; }
/** * Export the locale files to the browser as a tarball. * Requires tar (configured in config.inc.php) for operation. * @param $args array Parameters. * @param $request PKPRequest Request object. */ function export($args, $request) { $locale = $request->getUserVar('locale'); if (!AppLocale::isLocaleValid($locale)) { fatalError('Invalid locale.'); } // Construct the tar command $tarBinary = Config::getVar('cli', 'tar'); if (empty($tarBinary) || !file_exists($tarBinary)) { fatalError('cli.tar binary not properly configured.'); } $command = $tarBinary . ' cz'; $emailTemplateDao = DAORegistry::getDAO('EmailTemplateDAO'); $localeFilesList = array_merge(TranslatorAction::getLocaleFiles($locale), TranslatorAction::getMiscLocaleFiles($locale), array($emailTemplateDao->getMainEmailTemplateDataFilename($locale)), array_values(TranslatorAction::getEmailFileMap($locale))); // Include locale files (main file and plugin files) foreach ($localeFilesList as $file) { if (file_exists($file)) { $command .= ' ' . escapeshellarg($file); } } header('Content-Type: application/x-gtar'); header("Content-Disposition: attachment; filename=\"{$locale}.tar.gz\""); header('Cache-Control: private'); // Workarounds for IE weirdness passthru($command); }
/** * Get a list of email templates for the supplied locale. Returns data in the * following data structure: * array( * 'emailKey' => array( * 'subject' => 'Localized Subject', * 'body' => 'Localized Body', * 'description' => 'Localized Description', * 'templateFile' => '/path/to/template-file.xml', * 'templateDataFile' => '/path/to/localized/data-file.xml' * ), ... * ) * @param $locale string Locale code * @return array Email template data */ static function _getEmailTemplates($locale) { $files = TranslatorAction::getEmailFileMap($locale); $returner = array(); foreach ($files as $templateFile => $templateDataFile) { if (!file_exists($templateFile)) { continue; } $xmlParser = new XMLParser(); $data = $xmlParser->parse($templateFile); foreach ($data->getChildren() as $emailNode) { $returner[$emailNode->getAttribute('key')] = array('subject' => null, 'body' => null, 'description' => null, 'templateFile' => $templateFile, 'statusCode' => 'doesNotExist'); } if (!file_exists($templateDataFile)) { continue; } $localeData = $xmlParser->parse($templateDataFile); if ($localeData) { foreach ($localeData->getChildren() as $emailNode) { $key = $emailNode->getAttribute('key'); if (isset($returner[$key])) { $returner[$key] = array_merge($returner[$key], array('subject' => $emailNode->getChildValue('subject'), 'body' => $emailNode->getChildValue('body'), 'description' => $emailNode->getChildValue('description'), 'templateDataFile' => $templateDataFile, 'statusCode' => 'exists')); } } } } // Fill in status if ($locale != MASTER_LOCALE) { $masterLocale = self::_getEmailTemplates(MASTER_LOCALE); } foreach ($returner as $key => &$emailData) { switch ($emailData['statusCode']) { case 'doesNotExist': $emailData['status'] = __('plugins.generic.translator.email.doesNotExist'); break; case 'exists': $emailData['status'] = __('plugins.generic.translator.email.complete'); if ($locale != MASTER_LOCALE) { $referenceSubject = $masterLocale[$key]['subject']; $referenceBody = $masterLocale[$key]['body']; if (0 != count(array_diff(AppLocale::getParameterNames($emailData['subject']), AppLocale::getParameterNames($referenceSubject)))) { $emailData['status'] = __('plugins.generic.translator.errors.EMAIL_ERROR_DIFFERING_PARAMS.title'); } if (0 != count(array_diff(AppLocale::getParameterNames($emailData['body']), AppLocale::getParameterNames($referenceBody)))) { $emailData['status'] = __('plugins.generic.translator.errors.LOCALE_ERROR_DIFFERING_PARAMS.title'); } } break; } } return $returner; }