function saveLocaleFile($args) { $this->validate(); $plugin =& PluginRegistry::getPlugin('generic', 'CustomLocalePlugin'); $this->setupTemplate($plugin, true); $locale = array_shift($args); if (!Locale::isLocaleValid($locale)) { $path = array($plugin->getCategory(), $plugin->getName(), 'index'); Request::redirect(null, null, null, $path); } $filename = urldecode(urldecode(array_shift($args))); if (!CustomLocaleAction::isLocaleFile($locale, $filename)) { $path = array($plugin->getCategory(), $plugin->getName(), 'edit', $locale); Request::redirect(null, null, null, $path); } $journal =& Request::getJournal(); $journalId = $journal->getId(); $changes = Request::getUserVar('changes'); $customFilesDir = Config::getVar('files', 'public_files_dir') . DIRECTORY_SEPARATOR . 'journals' . DIRECTORY_SEPARATOR . $journalId . DIRECTORY_SEPARATOR . CUSTOM_LOCALE_DIR . DIRECTORY_SEPARATOR . $locale; $customFilePath = $customFilesDir . DIRECTORY_SEPARATOR . $filename; // Create empty custom locale file if it doesn't exist import('file.FileManager'); import('file.EditableLocaleFile'); if (!FileManager::fileExists($customFilePath)) { $numParentDirs = substr_count($customFilePath, DIRECTORY_SEPARATOR); $parentDirs = ''; for ($i = 0; $i < $numParentDirs; $i++) { $parentDirs .= '..' . DIRECTORY_SEPARATOR; } $newFileContents = '<?xml version="1.0" encoding="UTF-8"?>' . "\n"; $newFileContents .= '<!DOCTYPE locale SYSTEM "' . $parentDirs . 'lib' . DIRECTORY_SEPARATOR . 'pkp' . DIRECTORY_SEPARATOR . 'dtd' . DIRECTORY_SEPARATOR . 'locale.dtd' . '">' . "\n"; $newFileContents .= '<locale name="' . $locale . '">' . "\n"; $newFileContents .= '</locale>'; FileManager::writeFile($customFilePath, $newFileContents); } $file = new EditableLocaleFile($locale, $customFilePath); while (!empty($changes)) { $key = array_shift($changes); $value = $this->correctCr(array_shift($changes)); if (!empty($value)) { if (!$file->update($key, $value)) { $file->insert($key, $value); } } else { $file->delete($key); } } $file->write(); Request::redirectUrl(Request::getUserVar('redirectUrl')); }
function saveLocaleFile($args, &$request) { $this->validate(); $plugin =& $this->plugin; $this->setupTemplate($request, $plugin, true); $locale = array_shift($args); if (!AppLocale::isLocaleValid($locale)) { $path = array($plugin->getCategory(), $plugin->getName(), 'index'); $request->redirect(null, null, null, null, $path); } $filename = urldecode(urldecode(array_shift($args))); if (!CustomLocaleAction::isLocaleFile($locale, $filename)) { $path = array($plugin->getCategory(), $plugin->getName(), 'edit', $locale); $request->redirect(null, null, null, null, $path); } $conference =& $request->getConference(); $conferenceId = $conference->getId(); $changes = $request->getUserVar('changes'); $customFilesDir = Config::getVar('files', 'public_files_dir') . DIRECTORY_SEPARATOR . 'conferences' . DIRECTORY_SEPARATOR . $conferenceId . DIRECTORY_SEPARATOR . CUSTOM_LOCALE_DIR . DIRECTORY_SEPARATOR . $locale; $customFilePath = $customFilesDir . DIRECTORY_SEPARATOR . $filename; // Create empty custom locale file if it doesn't exist import('lib.pkp.classes.file.FileManager'); $fileManager = new FileManager(); import('classes.i18n.EditableLocaleFile'); if (!$fileManager->fileExists($customFilePath)) { $numParentDirs = substr_count($customFilePath, DIRECTORY_SEPARATOR); $parentDirs = ''; for ($i = 0; $i < $numParentDirs; $i++) { $parentDirs .= '..' . DIRECTORY_SEPARATOR; } $newFileContents = '<?xml version="1.0" encoding="UTF-8"?>' . "\n"; $newFileContents .= '<!DOCTYPE locale SYSTEM "' . $parentDirs . 'locale' . DIRECTORY_SEPARATOR . 'locale.dtd' . '">' . "\n"; $newFileContents .= '<locale name="' . $locale . '">' . "\n"; $newFileContents .= '</locale>'; $fileManager->writeFile($customFilePath, $newFileContents); } $file = new EditableLocaleFile($locale, $customFilePath); while (!empty($changes)) { $key = array_shift($changes); $value = $this->correctCr(array_shift($changes)); if (!empty($value)) { if (!$file->update($key, $value)) { $file->insert($key, $value); } } else { $file->delete($key); } } $file->write(); $request->redirectUrl($request->getUserVar('redirectUrl')); }
function deleteLocaleKey($args, $request) { $this->validate(); $plugin =& $this->plugin; $this->setupTemplate($request); $locale = array_shift($args); if (!AppLocale::isLocaleValid($locale)) { $request->redirect(null, null, 'index'); } $filename = urldecode(urldecode(array_shift($args))); if (!TranslatorAction::isLocaleFile($locale, $filename)) { $request->redirect(null, null, 'edit', $locale); } $changes = $request->getUserVar('changes'); $file = new EditableLocaleFile($locale, $filename); if ($file->delete(array_shift($args))) { $file->write(); } $request->redirect(null, null, 'editLocaleFile', array($locale, urlencode(urlencode($filename)))); }
function deleteLocaleKey($args) { $this->validate(); $plugin =& $this->plugin; $this->setupTemplate(); $locale = array_shift($args); if (!Locale::isLocaleValid($locale)) { Request::redirect(null, null, null, 'index'); } $filename = urldecode(urldecode(array_shift($args))); if (!TranslatorAction::isLocaleFile($locale, $filename)) { Request::redirect(null, null, null, 'edit', $locale); } $changes = Request::getUserVar('changes'); import('lib.pkp.classes.file.EditableLocaleFile'); $file = new EditableLocaleFile($locale, $filename); if ($file->delete(array_shift($args))) { $file->write(); } Request::redirect(null, null, null, 'editLocaleFile', array($locale, urlencode(urlencode($filename)))); }