2021-08-18 19:42:30 +00:00
|
|
|
<?php
|
2021-09-02 21:44:01 +00:00
|
|
|
/**
|
|
|
|
* @brief translater, a plugin for Dotclear 2
|
|
|
|
*
|
|
|
|
* @package Dotclear
|
|
|
|
* @subpackage Plugin
|
|
|
|
*
|
|
|
|
* @author Jean-Christian Denis & contributors
|
|
|
|
*
|
|
|
|
* @copyright Jean-Christian Denis
|
|
|
|
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
|
|
|
*/
|
2021-08-18 19:42:30 +00:00
|
|
|
|
2021-08-18 22:48:47 +00:00
|
|
|
if (!defined('DC_CONTEXT_ADMIN')) {
|
|
|
|
return;
|
|
|
|
}
|
2021-08-18 19:42:30 +00:00
|
|
|
|
2021-09-17 23:29:28 +00:00
|
|
|
$core->addBehavior('adminModulesListGetActions', ['translaterAdminBehaviors', 'adminModulesGetActions']);
|
|
|
|
$core->addBehavior('adminModulesListDoActions', ['translaterAdminBehaviors', 'adminModulesDoActions']);
|
|
|
|
$core->addBehavior('adminDashboardFavorites', ['translaterAdminBehaviors', 'adminDashboardFavorites']);
|
2021-08-18 19:42:30 +00:00
|
|
|
|
|
|
|
$_menu['Plugins']->addItem(
|
2021-08-18 22:48:47 +00:00
|
|
|
__('Translater'),
|
2021-09-24 23:58:59 +00:00
|
|
|
$core->adminurl->get('translater'),
|
2021-09-17 23:29:28 +00:00
|
|
|
dcPage::getPF('translater/icon.png'),
|
|
|
|
preg_match(
|
2021-09-24 23:58:59 +00:00
|
|
|
'/' . preg_quote($core->adminurl->get('translater')) . '(&.*)?$/',
|
2021-09-17 23:29:28 +00:00
|
|
|
$_SERVER['REQUEST_URI']
|
|
|
|
),
|
2021-08-18 22:48:47 +00:00
|
|
|
$core->auth->isSuperAdmin()
|
2021-08-18 19:42:30 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
class translaterAdminBehaviors
|
|
|
|
{
|
2021-09-24 23:58:59 +00:00
|
|
|
/** @var dcTranlsater dcTranslater instance */
|
|
|
|
private static $translater = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create instance of dcTranslater once
|
|
|
|
*
|
|
|
|
* @param dCore $core dcCore instance
|
|
|
|
* @return dctranslater dcTranslater instance
|
|
|
|
*/
|
|
|
|
private static function translater($core)
|
|
|
|
{
|
|
|
|
if (!(self::$translater instanceof dcTranslater)) {
|
|
|
|
self::$translater = new dcTranslater($core);
|
|
|
|
}
|
|
|
|
return self::$translater;
|
|
|
|
}
|
|
|
|
|
2021-09-17 23:29:28 +00:00
|
|
|
/**
|
|
|
|
* Add button to go to module translation
|
|
|
|
*
|
|
|
|
* @param object $list adminModulesList instance
|
|
|
|
* @param string $id Module id
|
|
|
|
* @param arrray $prop Module properties
|
|
|
|
* @return string HTML submit button
|
|
|
|
*/
|
|
|
|
public static function adminModulesGetActions(adminModulesList $list, string $id, array $prop): ?string
|
2021-08-18 22:48:47 +00:00
|
|
|
{
|
2021-09-17 23:29:28 +00:00
|
|
|
if ($list->getList() != $prop['type'] . '-activate'
|
2021-09-24 23:58:59 +00:00
|
|
|
|| !self::translater($list->core)->getSetting($prop['type'] . '_menu')
|
2021-09-17 23:29:28 +00:00
|
|
|
|| !$list->core->auth->isSuperAdmin()
|
|
|
|
) {
|
|
|
|
return null;
|
2021-08-18 22:48:47 +00:00
|
|
|
}
|
2021-09-02 21:44:01 +00:00
|
|
|
|
2021-09-17 23:29:28 +00:00
|
|
|
return
|
|
|
|
' <input type="submit" name="translater[' .
|
|
|
|
html::escapeHTML($id) .
|
|
|
|
']" value="' . _('Translate') . '" /> ';
|
2021-08-18 22:48:47 +00:00
|
|
|
}
|
2021-09-02 21:44:01 +00:00
|
|
|
|
2021-09-17 23:29:28 +00:00
|
|
|
/**
|
|
|
|
* Redirect to module translation
|
|
|
|
*
|
|
|
|
* @param adminModulesList $list adminModulesList instance
|
|
|
|
* @param array $modules Selected modules ids
|
|
|
|
* @param string $type List type (plugin|theme)
|
|
|
|
*/
|
|
|
|
public static function adminModulesDoActions(adminModulesList $list, array $modules, string $type)
|
2021-08-18 22:48:47 +00:00
|
|
|
{
|
2021-09-17 23:29:28 +00:00
|
|
|
if (empty($_POST['translater']) || !is_array($_POST['translater'])) {
|
|
|
|
return null;
|
2021-08-18 22:48:47 +00:00
|
|
|
}
|
2021-09-02 21:44:01 +00:00
|
|
|
|
2021-09-17 23:29:28 +00:00
|
|
|
$list->core->adminurl->redirect(
|
2021-09-24 23:58:59 +00:00
|
|
|
'translater',
|
2021-09-17 23:29:28 +00:00
|
|
|
['part' => 'module', 'type' => $type, 'module' => key($_POST['translater'])],
|
|
|
|
'#module-lang'
|
|
|
|
);
|
|
|
|
}
|
2021-09-02 21:44:01 +00:00
|
|
|
|
2021-09-17 23:29:28 +00:00
|
|
|
/**
|
|
|
|
* Add dashboard favorites icon
|
|
|
|
*
|
|
|
|
* @param dcCore $core dcCore instance
|
|
|
|
* @param dcFavorites $favs dcFavorites instance
|
|
|
|
*/
|
|
|
|
public static function adminDashboardFavorites(dcCore $core, dcFavorites$favs)
|
|
|
|
{
|
|
|
|
$favs->register('translater', [
|
|
|
|
'title' => __('Translater'),
|
2021-09-24 23:58:59 +00:00
|
|
|
'url' => $core->adminurl->get('translater'),
|
2021-09-17 23:29:28 +00:00
|
|
|
'small-icon' => urldecode(dcPage::getPF('translater/icon.png')),
|
|
|
|
'large-icon' => urldecode(dcPage::getPF('translater/icon-big.png')),
|
|
|
|
'permissions' => $core->auth->isSuperAdmin()
|
|
|
|
]);
|
2021-08-18 22:48:47 +00:00
|
|
|
}
|
|
|
|
}
|