Ejemplo n.º 1
0
 function editLocaleFile($args)
 {
     list($plugin) = CustomLocaleHandler::validate();
     CustomLocaleHandler::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);
     }
     $templateMgr =& TemplateManager::getManager();
     import('file.FileManager');
     import('file.EditableLocaleFile');
     $journal = Request::getJournal();
     $journalId = $journal->getJournalId();
     $publicFilesDir = Config::getVar('files', 'public_files_dir');
     $customLocaleDir = $publicFilesDir . DIRECTORY_SEPARATOR . 'journals' . DIRECTORY_SEPARATOR . $journalId . DIRECTORY_SEPARATOR . CUSTOM_LOCALE_DIR;
     $customLocalePath = $customLocaleDir . DIRECTORY_SEPARATOR . $locale . DIRECTORY_SEPARATOR . $filename;
     if (FileManager::fileExists($customLocalePath)) {
         $localeContents = EditableLocaleFile::load($customLocalePath);
     } else {
         $localeContents = null;
     }
     $referenceLocaleContents = EditableLocaleFile::load($filename);
     $referenceLocaleContentsRangeInfo = Handler::getRangeInfo('referenceLocaleContents');
     // Handle a search, if one was executed.
     $searchKey = Request::getUserVar('searchKey');
     $found = false;
     $index = 0;
     $pageIndex = 0;
     if (!empty($searchKey)) {
         foreach ($referenceLocaleContents as $key => $value) {
             if ($index % $referenceLocaleContentsRangeInfo->getCount() == 0) {
                 $pageIndex++;
             }
             if ($key == $searchKey) {
                 $found = true;
                 break;
             }
             $index++;
         }
     }
     if ($found) {
         $referenceLocaleContentsRangeInfo->setPage($pageIndex);
         $templateMgr->assign('searchKey', $searchKey);
     }
     $templateMgr->assign('filename', $filename);
     $templateMgr->assign('locale', $locale);
     import('core.ArrayItemIterator');
     $templateMgr->assign_by_ref('referenceLocaleContents', new ArrayItemIterator($referenceLocaleContents, $referenceLocaleContentsRangeInfo->getPage(), $referenceLocaleContentsRangeInfo->getCount()));
     $templateMgr->assign('localeContents', $localeContents);
     $templateMgr->display($plugin->getTemplatePath() . 'localeFile.tpl');
 }
 /**
  * @copydoc GridHandler::loadData()
  */
 function loadData($request)
 {
     import('lib.pkp.classes.file.EditableLocaleFile');
     $referenceLocaleContents = EditableLocaleFile::load(str_replace($this->locale, MASTER_LOCALE, $this->filename));
     $localeContents = file_exists($this->filename) ? EditableLocaleFile::load($this->filename) : array();
     $returner = array();
     foreach ($referenceLocaleContents as $key => $value) {
         $returner[$key][MASTER_LOCALE] = $value;
     }
     foreach ($localeContents as $key => $value) {
         $returner[$key][$this->locale] = $value;
     }
     return $returner;
 }
Ejemplo n.º 3
0
 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'));
 }
Ejemplo n.º 4
0
 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))));
 }
Ejemplo n.º 5
0
 function editLocaleFile($args)
 {
     list($plugin) = TranslatorHandler::validate();
     TranslatorHandler::setupTemplate();
     $locale = array_shift($args);
     if (!Locale::isLocaleValid($locale)) {
         Request::redirect(null, null, 'index');
     }
     $filename = urldecode(urldecode(array_shift($args)));
     if (!TranslatorAction::isLocaleFile($locale, $filename)) {
         Request::redirect(null, null, 'edit', $locale);
     }
     $templateMgr =& TemplateManager::getManager();
     import('i18n.EditableLocaleFile');
     $localeContentsRangeInfo = Handler::getRangeInfo('localeContents');
     $localeContents = EditableLocaleFile::load($filename);
     // Handle a search, if one was executed.
     $searchKey = Request::getUserVar('searchKey');
     $found = false;
     $index = 0;
     $pageIndex = 0;
     if (!empty($searchKey)) {
         foreach ($localeContents as $key => $value) {
             if ($index % $localeContentsRangeInfo->getCount() == 0) {
                 $pageIndex++;
             }
             if ($key == $searchKey) {
                 $found = true;
                 break;
             }
             $index++;
         }
     }
     if ($found) {
         $localeContentsRangeInfo->setPage($pageIndex);
         $templateMgr->assign('searchKey', $searchKey);
     }
     $templateMgr->assign('filename', $filename);
     $templateMgr->assign('locale', $locale);
     $templateMgr->assign_by_ref('localeContents', new ArrayItemIterator($localeContents, $localeContentsRangeInfo->getPage(), $localeContentsRangeInfo->getCount()));
     $templateMgr->assign('referenceLocaleContents', EditableLocaleFile::load(TranslatorAction::determineReferenceFilename($locale, $filename)));
     $templateMgr->display($plugin->getTemplatePath() . 'localeFile.tpl');
 }
Ejemplo n.º 6
0
 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'));
 }
Ejemplo n.º 7
0
 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))));
 }
 function createFile($args)
 {
     $this->validate();
     $plugin =& $this->plugin;
     $this->setupTemplate();
     $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);
     }
     import('lib.pkp.classes.file.FileManager');
     $fileManager = new FileManager();
     $fileManager->copyFile(TranslatorAction::determineReferenceFilename($locale, $filename), $filename);
     $localeKeys = LocaleFile::load($filename);
     import('lib.pkp.classes.file.EditableLocaleFile');
     $file = new EditableLocaleFile($locale, $filename);
     // remove default translations from keys
     foreach (array_keys($localeKeys) as $key) {
         $file->update($key, '');
     }
     $file->write();
     Request::redirectUrl(Request::getUserVar('redirectUrl'));
 }