00001 <?php
00002
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
00028 $locale = AppLocale::getLocale();
00029 $localeFiles = AppLocale::getLocaleFiles($locale);
00030 $conference = Request::getConference();
00031 $conferenceId = $conference->getId();
00032 $publicFilesDir = Config::getVar('files', 'public_files_dir');
00033 $customLocalePathBase = $publicFilesDir . DIRECTORY_SEPARATOR . 'conferences' . DIRECTORY_SEPARATOR . $conferenceId . DIRECTORY_SEPARATOR . CUSTOM_LOCALE_DIR . DIRECTORY_SEPARATOR . $locale . DIRECTORY_SEPARATOR;
00034
00035 import('file.FileManager');
00036 foreach ($localeFiles as $localeFile) {
00037 $customLocalePath = $customLocalePathBase . $localeFile->getFilename();
00038 if (FileManager::fileExists($customLocalePath)) {
00039 AppLocale::registerLocaleFile($locale, $customLocalePath, true);
00040 }
00041 }
00042
00043
00044 HookRegistry::register('PKPLocale::registerLocaleFile', array(&$this, 'addCustomLocale'));
00045 }
00046
00047 return true;
00048 }
00049 return false;
00050 }
00051
00052 function addCustomLocale($hookName, $args) {
00053 $locale =& $args[0];
00054 $localeFilename =& $args[1];
00055
00056 $conference = Request::getConference();
00057 $conferenceId = $conference->getId();
00058 $publicFilesDir = Config::getVar('files', 'public_files_dir');
00059 $customLocalePath = $publicFilesDir . DIRECTORY_SEPARATOR . 'conferences' . DIRECTORY_SEPARATOR . $conferenceId . DIRECTORY_SEPARATOR . CUSTOM_LOCALE_DIR . DIRECTORY_SEPARATOR . $locale . DIRECTORY_SEPARATOR . $localeFilename;
00060
00061 import('file.FileManager');
00062 if (FileManager::fileExists($customLocalePath)) {
00063 AppLocale::registerLocaleFile($locale, $customLocalePath, true);
00064 }
00065
00066 return true;
00067
00068 }
00069
00070 function getName() {
00071 return 'CustomLocalePlugin';
00072 }
00073
00074 function getDisplayName() {
00075 return __('plugins.generic.customLocale.name');
00076 }
00077
00078 function getDescription() {
00079 return __('plugins.generic.customLocale.description');
00080 }
00081
00082 function getEnabled() {
00083 $conference =& Request::getConference();
00084 if (!$conference) return false;
00085 return $this->getSetting($conference->getId(), 0, 'enabled');
00086 }
00087
00088 function setEnabled($enabled) {
00089 $conference =& Request::getConference();
00090 if ($conference) {
00091 $this->updateSetting($conference->getId(), 0, 'enabled', $enabled ? true : false);
00092 return true;
00093 }
00094 return false;
00095 }
00096
00097 function smartyPluginUrl($params, &$smarty) {
00098 $path = array($this->getCategory(), $this->getName());
00099 if (is_array($params['path'])) {
00100 $params['path'] = array_merge($path, $params['path']);
00101 } elseif (!empty($params['path'])) {
00102 $params['path'] = array_merge($path, array($params['path']));
00103 } else {
00104 $params['path'] = $path;
00105 }
00106
00107 if (!empty($params['key'])) {
00108 $params['path'] = array_merge($params['path'], array($params['key']));
00109 unset($params['key']);
00110 }
00111
00112 if (!empty($params['file'])) {
00113 $params['path'] = array_merge($params['path'], array($params['file']));
00114 unset($params['file']);
00115 }
00116
00117 return $smarty->smartyUrl($params, $smarty);
00118 }
00119
00120 function getManagementVerbs() {
00121 $isEnabled = $this->getEnabled();
00122
00123 $verbs[] = array(
00124 ($isEnabled?'disable':'enable'),
00125 __($isEnabled?'manager.plugins.disable':'manager.plugins.enable')
00126 );
00127
00128 if ($isEnabled) $verbs[] = array(
00129 'index',
00130 __('plugins.generic.customLocale.customize')
00131 );
00132
00133 return $verbs;
00134 }
00135
00136
00137
00138
00139
00140
00141
00142
00143 function manage($verb, $args, &$message) {
00144 $this->import('CustomLocaleHandler');
00145 $returner = true;
00146
00147 switch ($verb) {
00148 case 'enable':
00149 $this->setEnabled(true);
00150 $returner = false;
00151 $message = __('plugins.generic.customLocale.enabled');
00152 break;
00153 case 'disable':
00154 $this->setEnabled(false);
00155 $returner = false;
00156 $message = __('plugins.generic.customLocale.disabled');
00157 break;
00158 case 'index':
00159 if ($this->getEnabled()) {
00160 $customLocaleHandler = new CustomLocaleHandler();
00161 $customLocaleHandler->index();
00162 }
00163 break;
00164 case 'edit':
00165 if ($this->getEnabled()) {
00166 $customLocaleHandler = new CustomLocaleHandler();
00167 $customLocaleHandler->edit($args);
00168 }
00169 break;
00170 case 'saveLocaleChanges':
00171 if ($this->getEnabled()) {
00172 $customLocaleHandler = new CustomLocaleHandler();
00173 $customLocaleHandler->saveLocaleChanges($args);
00174 }
00175 break;
00176 case 'editLocaleFile':
00177 if ($this->getEnabled()) {
00178 $customLocaleHandler = new CustomLocaleHandler();
00179 $customLocaleHandler->editLocaleFile($args);
00180 }
00181 break;
00182 case 'saveLocaleFile':
00183 if ($this->getEnabled()) {
00184 $customLocaleHandler = new CustomLocaleHandler();
00185 $customLocaleHandler->saveLocaleFile($args);
00186 }
00187 break;
00188 default:
00189 if ($this->getEnabled()) {
00190 $customLocaleHandler = new CustomLocaleHandler();
00191 $customLocaleHandler->index();
00192 }
00193
00194 }
00195 return $returner;
00196 }
00197 }
00198
00199 ?>