00001 <?php
00002
00016
00017
00018
00019 require_once('CustomLocalePlugin.inc.php');
00020 require_once('CustomLocaleAction.inc.php');
00021 import('handler.Handler');
00022
00023 class CustomLocaleHandler extends Handler {
00025 var $plugin;
00026
00030 function CustomLocaleHandler() {
00031 parent::Handler();
00032
00033 $this->addCheck(new HandlerValidatorConference($this));
00034 $this->addCheck(new HandlerValidatorRoles($this, true, null, null, array(ROLE_ID_SITE_ADMIN, ROLE_ID_CONFERENCE_MANAGER)));
00035
00036 $plugin =& PluginRegistry::getPlugin('generic', 'CustomLocalePlugin');
00037 $this->plugin =& $plugin;
00038 }
00039
00040 function index() {
00041 $this->validate();
00042 $plugin =& $this->plugin;
00043 $this->setupTemplate($plugin, false);
00044
00045 $conference = Request::getConference();
00046 $rangeInfo = Handler::getRangeInfo('locales');
00047
00048 $templateMgr =& TemplateManager::getManager();
00049 import('core.ArrayItemIterator');
00050 $templateMgr->assign('locales', new ArrayItemIterator($conference->getSupportedLocaleNames(), $rangeInfo->getPage(), $rangeInfo->getCount()));
00051 $templateMgr->assign('masterLocale', MASTER_LOCALE);
00052
00053 $templateMgr->display($plugin->getTemplatePath() . 'index.tpl');
00054 }
00055
00056 function edit($args) {
00057 $this->validate();
00058 $plugin =& $this->plugin;
00059 $this->setupTemplate($plugin, true);
00060
00061 $locale = array_shift($args);
00062 $file = array_shift($args);
00063
00064 if (!AppLocale::isLocaleValid($locale)) {
00065 $path = array($plugin->getCategory(), $plugin->getName(), 'index');
00066 Request::redirect(null, null, null, null, $path);
00067 }
00068 $localeFiles = CustomLocaleAction::getLocaleFiles($locale);
00069
00070 $templateMgr =& TemplateManager::getManager();
00071
00072 $localeFilesRangeInfo = Handler::getRangeInfo('localeFiles');
00073
00074 import('core.ArrayItemIterator');
00075 $templateMgr->assign('localeFiles', new ArrayItemIterator($localeFiles, $localeFilesRangeInfo->getPage(), $localeFilesRangeInfo->getCount()));
00076
00077 $templateMgr->assign('locale', $locale);
00078 $templateMgr->assign('masterLocale', MASTER_LOCALE);
00079
00080 $templateMgr->display($plugin->getTemplatePath() . 'locale.tpl');
00081 }
00082
00083 function editLocaleFile($args) {
00084 $this->validate();
00085 $plugin =& $this->plugin;
00086 $this->setupTemplate($plugin, true);
00087
00088 $locale = array_shift($args);
00089 if (!AppLocale::isLocaleValid($locale)) {
00090 $path = array($plugin->getCategory(), $plugin->getName(), 'index');
00091 Request::redirect(null, null, null, null, $path);
00092 }
00093
00094 $filename = urldecode(urldecode(array_shift($args)));
00095 if (!CustomLocaleAction::isLocaleFile($locale, $filename)) {
00096 $path = array($plugin->getCategory(), $plugin->getName(), 'edit', $locale);
00097 Request::redirect(null, null, null, null, $path);
00098 }
00099
00100 $templateMgr =& TemplateManager::getManager();
00101
00102 import('file.FileManager');
00103 import('i18n.EditableLocaleFile');
00104 $conference = Request::getConference();
00105 $conferenceId = $conference->getId();
00106 $publicFilesDir = Config::getVar('files', 'public_files_dir');
00107 $customLocaleDir = $publicFilesDir . DIRECTORY_SEPARATOR . 'conferences' . DIRECTORY_SEPARATOR . $conferenceId . DIRECTORY_SEPARATOR . CUSTOM_LOCALE_DIR;
00108 $customLocalePath = $customLocaleDir . DIRECTORY_SEPARATOR . $locale . DIRECTORY_SEPARATOR . $filename;
00109 if (FileManager::fileExists($customLocalePath)) {
00110 $localeContents = EditableLocaleFile::load($customLocalePath);
00111 } else {
00112 $localeContents = null;
00113 }
00114
00115 $referenceLocaleContents = EditableLocaleFile::load($filename);
00116 $referenceLocaleContentsRangeInfo = Handler::getRangeInfo('referenceLocaleContents');
00117
00118
00119 $searchKey = Request::getUserVar('searchKey');
00120 $found = false;
00121 $index = 0;
00122 $pageIndex = 0;
00123 if (!empty($searchKey)) foreach ($referenceLocaleContents as $key => $value) {
00124 if ($index % $referenceLocaleContentsRangeInfo->getCount() == 0) $pageIndex++;
00125 if ($key == $searchKey) {
00126 $found = true;
00127 break;
00128 }
00129 $index++;
00130 }
00131
00132 if ($found) {
00133 $referenceLocaleContentsRangeInfo->setPage($pageIndex);
00134 $templateMgr->assign('searchKey', $searchKey);
00135 }
00136
00137 $templateMgr->assign('filename', $filename);
00138 $templateMgr->assign('locale', $locale);
00139 import('core.ArrayItemIterator');
00140 $templateMgr->assign_by_ref('referenceLocaleContents', new ArrayItemIterator($referenceLocaleContents, $referenceLocaleContentsRangeInfo->getPage(), $referenceLocaleContentsRangeInfo->getCount()));
00141 $templateMgr->assign('localeContents', $localeContents);
00142
00143 $templateMgr->display($plugin->getTemplatePath() . 'localeFile.tpl');
00144 }
00145
00146 function saveLocaleFile($args) {
00147 $this->validate();
00148 $plugin =& $this->plugin;
00149 $this->setupTemplate($plugin, true);
00150
00151 $locale = array_shift($args);
00152 if (!AppLocale::isLocaleValid($locale)) {
00153 $path = array($plugin->getCategory(), $plugin->getName(), 'index');
00154 Request::redirect(null, null, null, null, $path);
00155 }
00156
00157 $filename = urldecode(urldecode(array_shift($args)));
00158 if (!CustomLocaleAction::isLocaleFile($locale, $filename)) {
00159 $path = array($plugin->getCategory(), $plugin->getName(), 'edit', $locale);
00160 Request::redirect(null, null, null, null, $path);
00161 }
00162
00163 $conference =& Request::getConference();
00164 $conferenceId = $conference->getId();
00165 $changes = Request::getUserVar('changes');
00166 $customFilesDir = Config::getVar('files', 'public_files_dir') . DIRECTORY_SEPARATOR . 'conferences' . DIRECTORY_SEPARATOR . $conferenceId . DIRECTORY_SEPARATOR . CUSTOM_LOCALE_DIR . DIRECTORY_SEPARATOR . $locale;
00167 $customFilePath = $customFilesDir . DIRECTORY_SEPARATOR . $filename;
00168
00169
00170 import('file.FileManager');
00171 import('i18n.EditableLocaleFile');
00172 if (!FileManager::fileExists($customFilePath)) {
00173 $numParentDirs = substr_count($customFilePath, DIRECTORY_SEPARATOR);
00174 $parentDirs = '';
00175 for ($i=0; $i<$numParentDirs; $i++) {
00176 $parentDirs .= '..' . DIRECTORY_SEPARATOR;
00177 }
00178
00179 $newFileContents = '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
00180 $newFileContents .= '<!DOCTYPE locale SYSTEM "' . $parentDirs . 'locale' . DIRECTORY_SEPARATOR . 'locale.dtd' . '">' . "\n";
00181 $newFileContents .= '<locale name="' . $locale . '">' . "\n";
00182 $newFileContents .= '</locale>';
00183 FileManager::writeFile($customFilePath, $newFileContents);
00184 }
00185
00186 $file = new EditableLocaleFile($locale, $customFilePath);
00187
00188 while (!empty($changes)) {
00189 $key = array_shift($changes);
00190 $value = $this->correctCr(array_shift($changes));
00191 if (!empty($value)) {
00192 if (!$file->update($key, $value)) {
00193 $file->insert($key, $value);
00194 }
00195 } else {
00196 $file->delete($key);
00197 }
00198 }
00199 $file->write();
00200
00201 Request::redirectUrl(Request::getUserVar('redirectUrl'));
00202 }
00203
00204 function correctCr($value) {
00205 return str_replace("\r\n", "\n", $value);
00206 }
00207
00208 function setupTemplate(&$plugin, $subclass = true) {
00209 parent::setupTemplate();
00210
00211 $templateMgr =& TemplateManager::getManager();
00212 $templateMgr->register_function('plugin_url', array(&$plugin, 'smartyPluginUrl'));
00213 $pageHierarchy = array(array(Request::url(null, null, 'user'), 'navigation.user'), array(Request::url(null, null, 'manager'), 'user.role.manager'));
00214 if ($subclass) {
00215 $path = array($plugin->getCategory(), $plugin->getName(), 'index');
00216 $pageHierarchy[] = array(Request::url(null, null, null, null, $path), 'plugins.generic.customLocale.name');
00217 }
00218 $templateMgr->assign('pageHierarchy', $pageHierarchy);
00219 $templateMgr->assign('helpTopicId', 'plugins.generic.CustomLocalePlugin');
00220 }
00221 }
00222 ?>