| Server IP : 195.134.90.114 / Your IP : 216.73.217.33 Web Server : Apache/2.4.58 System : Linux nepub 6.8.0-88-generic #89-Ubuntu SMP PREEMPT_DYNAMIC Sat Oct 11 01:02:46 UTC 2025 x86_64 User : www-data ( 33) PHP Version : 8.2.30 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/html/public_html/plugins/generic/customLocale/ |
Upload File : |
<?php
/**
* @file CustomLocalePlugin.inc.php
*
* Copyright (c) 2016-2023 Language Science Press
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class CustomLocalePlugin
*
*/
import('lib.pkp.classes.plugins.GenericPlugin');
class CustomLocalePlugin extends GenericPlugin {
/**
* @copydoc Plugin::register
*/
function register($category, $path, $mainContextId = null) {
if (!parent::register($category, $path, $mainContextId)) return false;
if ($this->getEnabled()) {
// Add custom locale data for already registered locale files.
$locale = AppLocale::getLocale();
$localeFiles = AppLocale::getLocaleFiles($locale);
$request = Application::get()->getRequest();
$context = $request->getContext();
import('lib.pkp.classes.file.ContextFileManager');
$contextFileManager = new ContextFileManager($context ? $context->getId() : CONTEXT_SITE);
$customLocalePathBase = $contextFileManager->getBasePath() . "customLocale/$locale/";
import('lib.pkp.classes.file.FileManager');
$fileManager = new FileManager();
foreach ($localeFiles as $localeFile) {
$customLocalePath = $customLocalePathBase . $localeFile->getFilename();
if ($contextFileManager->fileExists($customLocalePath)) {
AppLocale::registerLocaleFile($locale, $customLocalePath, false);
}
}
// Add custom locale data for all locale files registered after this plugin
HookRegistry::register('PKPLocale::registerLocaleFile', array($this, 'addCustomLocale'));
HookRegistry::register('LoadComponentHandler', array($this, 'setupGridHandler'));
HookRegistry::register('Template::Settings::website', array($this, 'callbackShowWebsiteSettingsTabs'));
HookRegistry::register('LoadHandler', array($this, 'handleLoadRequest'));
$templateMgr = TemplateManager::getManager($request);
$templateMgr->addJavaScript(
'customLocale',
$request->getBaseUrl() . '/' . $this->getPluginPath() . '/js/customLocale.js',
['contexts' => 'backend']
);
}
return true;
}
/**
* Permit requests to the custom locale grid handler
* @param $hookName string The name of the hook being invoked
* @param $args array The parameters to the invoked hook
*/
function setupGridHandler($hookName, $args) {
$component = $args[0];
if ($component == 'plugins.generic.customLocale.controllers.grid.CustomLocaleGridHandler') {
// Allow the custom locale grid handler to get the plugin object
import($component);
CustomLocaleGridHandler::setPlugin($this);
return true;
}
return false;
}
/**
* Hook callback: Handle a request for a page load
* @param $hookName string Hook name
* @param $args array Hook arguments
*/
function handleLoadRequest($hookName, $args) {
$request = $this->getRequest();
$templateMgr = TemplateManager::getManager($request);
// get url path components
$page =& $args[0];
$op =& $args[1];
$tail = implode('/', $request->getRequestedArgs());
if ($page=='management' && $op=='settings' && $tail=='printCustomLocaleChanges') {
$op = 'printCustomLocaleChanges';
define('HANDLER_CLASS', 'CustomLocaleHandler');
define('CUSTOMLOCALE_PLUGIN_NAME', $this->getName());
$this->import('CustomLocaleHandler');
}
return false;
}
/**
* @copydoc Plugin::getActions()
*/
function getActions($request, $actionArgs) {
$dispatcher = $request->getDispatcher();
import('lib.pkp.classes.linkAction.request.RedirectAction');
return array_merge(
$this->getEnabled()?array(
new LinkAction(
'customize',
new RedirectAction($dispatcher->url(
$request, ROUTE_PAGE,
null, 'management', 'settings', 'website',
array('uid' => uniqid()), // Force reload
'customLocale' // Anchor for tab
)),
__('plugins.generic.customLocale.customize'),
null
),
new LinkAction(
'printChanges',
new RedirectAction($dispatcher->url(
$request, ROUTE_PAGE,
null, 'management', 'settings', 'printCustomLocaleChanges',
array('uid' => uniqid()), // Force reload
null // Anchor for tab
)),
__('plugins.generic.customLocale.printChanges'),
null
),
):array(),
parent::getActions($request, $actionArgs)
);
}
/**
* Add custom locale data.
* @param $hookName string
* @param $args array
* @return boolean Hook processing status
*/
function addCustomLocale($hookName, $args) {
$locale =& $args[0];
$localeFilename =& $args[1];
$request =& Registry::get('request');
$context = $request->getContext();
$contextFileManager = new ContextFileManager($context ? $context->getId() : CONTEXT_SITE);
$customLocalePath = $contextFileManager->getBasePath() . "customLocale/$locale/$localeFilename";
if ($contextFileManager->fileExists($customLocalePath)) {
AppLocale::registerLocaleFile($locale, $customLocalePath, false);
}
return true;
}
/**
* Get the plugin display name.
* @return string
*/
function getDisplayName() {
return __('plugins.generic.customLocale.name');
}
/**
* Get the plugin display status.
* @return string
*/
function getDescription() {
return __('plugins.generic.customLocale.description');
}
/**
* Extend the website settings tabs to include custom locale
* @param $hookName string The name of the invoked hook
* @param $args array Hook parameters
* @return boolean Hook handling status
*/
function callbackShowWebsiteSettingsTabs($hookName, $args) {
$templateMgr = $args[1];
$output =& $args[2];
$output .= $templateMgr->fetch($this->getTemplateResource('customLocaleTab.tpl'));
// Permit other plugins to continue interacting with this hook
return false;
}
/**
* @copydoc PKPPlugin::getSeq()
*/
function getSeq() {
return -1;
}
}