00001 <?php
00002
00014
00015
00016
00017 define('CUSTOM_LOCALE_DIR', 'customLocale');
00018 import('classes.plugins.GenericPlugin');
00019
00020 class CustomLocalePlugin extends GenericPlugin {
00021
00022 function register($category, $path) {
00023 if (parent::register($category, $path)) {
00024 $this->addLocaleData();
00025
00026 if ($this->getEnabled()) {
00027 import('file.FileManager');
00028 $journal = Request::getJournal();
00029 $journalId = $journal->getJournalId();
00030 $locale = Locale::getLocale();
00031 $localeFiles = Locale::getLocaleFiles($locale);
00032 $publicFilesDir = Config::getVar('files', 'public_files_dir');
00033 $customLocaleDir = $publicFilesDir . DIRECTORY_SEPARATOR . 'journals' . DIRECTORY_SEPARATOR . $journalId . DIRECTORY_SEPARATOR . CUSTOM_LOCALE_DIR;
00034
00035 foreach ($localeFiles as $localeFile) {
00036 $localeFilename = $localeFile->getFilename();
00037 $customLocalePath = $customLocaleDir . DIRECTORY_SEPARATOR . $locale . DIRECTORY_SEPARATOR . $localeFilename;
00038 if (FileManager::fileExists($customLocalePath)) {
00039 Locale::registerLocaleFile($locale, $customLocalePath, true);
00040 }
00041 }
00042 }
00043
00044 return true;
00045 }
00046 return false;
00047 }
00048
00049 function getName() {
00050 return 'CustomLocalePlugin';
00051 }
00052
00053 function getDisplayName() {
00054 return Locale::translate('plugins.generic.customLocale.name');
00055 }
00056
00057 function getDescription() {
00058 return Locale::translate('plugins.generic.customLocale.description');
00059 }
00060
00061 function getEnabled() {
00062 $journal = &Request::getJournal();
00063 if (!$journal) return false;
00064 return $this->getSetting($journal->getJournalId(), 'enabled');
00065 }
00066
00067 function setEnabled($enabled) {
00068 $journal = &Request::getJournal();
00069 if ($journal) {
00070 $this->updateSetting($journal->getJournalId(), 'enabled', $enabled ? true : false);
00071 return true;
00072 }
00073 return false;
00074 }
00075
00076 function smartyPluginUrl($params, &$smarty) {
00077 $path = array($this->getCategory(), $this->getName());
00078 if (is_array($params['path'])) {
00079 $params['path'] = array_merge($path, $params['path']);
00080 } elseif (!empty($params['path'])) {
00081 $params['path'] = array_merge($path, array($params['path']));
00082 } else {
00083 $params['path'] = $path;
00084 }
00085
00086 if (!empty($params['key'])) {
00087 $params['path'] = array_merge($params['path'], array($params['key']));
00088 unset($params['key']);
00089 }
00090
00091 if (!empty($params['file'])) {
00092 $params['path'] = array_merge($params['path'], array($params['file']));
00093 unset($params['file']);
00094 }
00095
00096 return $smarty->smartyUrl($params, $smarty);
00097 }
00098
00099 function getManagementVerbs() {
00100 $isEnabled = $this->getEnabled();
00101
00102 $verbs[] = array(
00103 ($isEnabled?'disable':'enable'),
00104 Locale::translate($isEnabled?'manager.plugins.disable':'manager.plugins.enable')
00105 );
00106
00107 if ($isEnabled) $verbs[] = array(
00108 'index',
00109 Locale::translate('plugins.generic.customLocale.customize')
00110 );
00111
00112 return $verbs;
00113 }
00114
00115 function manage($verb, $args) {
00116 $this->import('CustomLocaleHandler');
00117 $returner = true;
00118
00119 switch ($verb) {
00120 case 'enable':
00121 $this->setEnabled(true);
00122 $returner = false;
00123 break;
00124 case 'disable':
00125 $this->setEnabled(false);
00126 $returner = false;
00127 break;
00128 case 'index':
00129 if ($this->getEnabled()) CustomLocaleHandler::index();
00130 break;
00131 case 'edit':
00132 if ($this->getEnabled()) CustomLocaleHandler::edit($args);
00133 break;
00134 case 'saveLocaleChanges':
00135 if ($this->getEnabled()) CustomLocaleHandler::saveLocaleChanges($args);
00136 break;
00137 case 'editLocaleFile':
00138 if ($this->getEnabled()) CustomLocaleHandler::editLocaleFile($args);
00139 break;
00140 case 'saveLocaleFile':
00141 if ($this->getEnabled()) CustomLocaleHandler::saveLocaleFile($args);
00142 break;
00143 default:
00144 if ($this->getEnabled()) CustomLocaleHandler::index();
00145
00146 }
00147 return $returner;
00148 }
00149 }
00150
00151 ?>