1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
|
<?php
/**
* @file CustomLocalePlugin.inc.php
*
* Copyright (c) 2003-2009 John Willinsky
* Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
*
* @class CustomLocalePlugin
*
* @brief This plugin enables customization of locale strings.
*/
// $Id$
define('CUSTOM_LOCALE_DIR', 'customLocale');
import('classes.plugins.GenericPlugin');
class CustomLocalePlugin extends GenericPlugin {
function register($category, $path) {
if (parent::register($category, $path)) {
$this->addLocaleData();
if ($this->getEnabled()) {
// Add custom locale data for already registered locale files.
// This includes the main locale file and the locale files for all
// plugins registered prior to and including this one.
$locale = Locale::getLocale();
$localeFiles = Locale::getLocaleFiles($locale);
$journal = Request::getJournal();
$journalId = $journal->getJournalId();
$publicFilesDir = Config::getVar('files', 'public_files_dir');
$customLocalePathBase = $publicFilesDir . DIRECTORY_SEPARATOR . 'journals' . DIRECTORY_SEPARATOR . $journalId . DIRECTORY_SEPARATOR . CUSTOM_LOCALE_DIR . DIRECTORY_SEPARATOR . $locale . DIRECTORY_SEPARATOR;
import('file.FileManager');
foreach ($localeFiles as $localeFile) {
$customLocalePath = $customLocalePathBase . $localeFile->getFilename();
if (FileManager::fileExists($customLocalePath)) {
Locale::registerLocaleFile($locale, $customLocalePath, true);
}
}
// Add custom locale data for all plugins registered after this one
HookRegistry::register('Plugin::addLocaleData', array(&$this, 'addCustomLocalePlugin'));
}
return true;
}
return false;
}
function addCustomLocalePlugin($hookName, $args) {
$locale =& $args[0];
$localeFilename =& $args[1];
$journal = Request::getJournal();
$journalId = $journal->getJournalId();
$publicFilesDir = Config::getVar('files', 'public_files_dir');
$customLocalePath = $publicFilesDir . DIRECTORY_SEPARATOR . 'journals' . DIRECTORY_SEPARATOR . $journalId . DIRECTORY_SEPARATOR . CUSTOM_LOCALE_DIR . DIRECTORY_SEPARATOR . $locale . DIRECTORY_SEPARATOR . $localeFilename;
import('file.FileManager');
if (FileManager::fileExists($customLocalePath)) {
Locale::registerLocaleFile($locale, $customLocalePath, true);
}
return true;
}
function getName() {
return 'CustomLocalePlugin';
}
function getDisplayName() {
return Locale::translate('plugins.generic.customLocale.name');
}
function getDescription() {
return Locale::translate('plugins.generic.customLocale.description');
}
function getEnabled() {
$journal = &Request::getJournal();
if (!$journal) return false;
return $this->getSetting($journal->getJournalId(), 'enabled');
}
function setEnabled($enabled) {
$journal = &Request::getJournal();
if ($journal) {
$this->updateSetting($journal->getJournalId(), 'enabled', $enabled ? true : false);
return true;
}
return false;
}
function smartyPluginUrl($params, &$smarty) {
$path = array($this->getCategory(), $this->getName());
if (is_array($params['path'])) {
$params['path'] = array_merge($path, $params['path']);
} elseif (!empty($params['path'])) {
$params['path'] = array_merge($path, array($params['path']));
} else {
$params['path'] = $path;
}
if (!empty($params['key'])) {
$params['path'] = array_merge($params['path'], array($params['key']));
unset($params['key']);
}
if (!empty($params['file'])) {
$params['path'] = array_merge($params['path'], array($params['file']));
unset($params['file']);
}
return $smarty->smartyUrl($params, $smarty);
}
function getManagementVerbs() {
$isEnabled = $this->getEnabled();
$verbs[] = array(
($isEnabled?'disable':'enable'),
Locale::translate($isEnabled?'manager.plugins.disable':'manager.plugins.enable')
);
if ($isEnabled) $verbs[] = array(
'index',
Locale::translate('plugins.generic.customLocale.customize')
);
return $verbs;
}
function manage($verb, $args) {
$this->import('CustomLocaleHandler');
$returner = true;
switch ($verb) {
case 'enable':
$this->setEnabled(true);
$returner = false;
break;
case 'disable':
$this->setEnabled(false);
$returner = false;
break;
case 'index':
if ($this->getEnabled()) CustomLocaleHandler::index();
break;
case 'edit':
if ($this->getEnabled()) CustomLocaleHandler::edit($args);
break;
case 'saveLocaleChanges':
if ($this->getEnabled()) CustomLocaleHandler::saveLocaleChanges($args);
break;
case 'editLocaleFile':
if ($this->getEnabled()) CustomLocaleHandler::editLocaleFile($args);
break;
case 'saveLocaleFile':
if ($this->getEnabled()) CustomLocaleHandler::saveLocaleFile($args);
break;
default:
if ($this->getEnabled()) CustomLocaleHandler::index();
}
return $returner;
}
}
?>
|