function isLocaleFile($locale, $filename)
 {
     if (in_array($filename, CustomLocaleAction::getLocaleFiles($locale))) {
         return true;
     }
     return false;
 }
 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'));
 }
Example #3
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'));
 }