2021-08-18 19:42:30 +00:00
|
|
|
<?php
|
2021-09-02 21:44:01 +00:00
|
|
|
/**
|
|
|
|
* @brief translater, a plugin for Dotclear 2
|
2021-11-01 21:32:32 +00:00
|
|
|
*
|
2021-09-02 21:44:01 +00:00
|
|
|
* @package Dotclear
|
|
|
|
* @subpackage Plugin
|
2021-11-01 21:32:32 +00:00
|
|
|
*
|
2021-09-02 21:44:01 +00:00
|
|
|
* @author Jean-Christian Denis & contributors
|
2021-11-01 21:32:32 +00:00
|
|
|
*
|
2021-09-02 21:44:01 +00:00
|
|
|
* @copyright Jean-Christian Denis
|
|
|
|
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
|
|
|
*/
|
2021-08-18 22:48:47 +00:00
|
|
|
if (!defined('DC_CONTEXT_ADMIN')) {
|
|
|
|
return;
|
|
|
|
}
|
2021-08-18 19:42:30 +00:00
|
|
|
|
2022-12-03 16:10:38 +00:00
|
|
|
if (!dcCore::app()->auth->isSuperAdmin()) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2022-11-13 17:40:31 +00:00
|
|
|
dcCore::app()->addBehavior('adminModulesListGetActions', ['translaterAdminBehaviors', 'adminModulesGetActions']);
|
|
|
|
dcCore::app()->addBehavior('adminModulesListDoActions', ['translaterAdminBehaviors', 'adminModulesDoActions']);
|
2022-11-26 14:12:54 +00:00
|
|
|
dcCore::app()->addBehavior('adminDashboardFavoritesV2', ['translaterAdminBehaviors', 'adminDashboardFavoritesV2']);
|
2021-08-18 19:42:30 +00:00
|
|
|
|
2022-11-13 17:40:31 +00:00
|
|
|
dcCore::app()->menu[dcAdmin::MENU_PLUGINS]->addItem(
|
2021-08-18 22:48:47 +00:00
|
|
|
__('Translater'),
|
2022-11-13 17:40:31 +00:00
|
|
|
dcCore::app()->adminurl->get('translater'),
|
2022-11-26 14:12:54 +00:00
|
|
|
dcPage::getPF('translater/icon.svg'),
|
2021-09-17 23:29:28 +00:00
|
|
|
preg_match(
|
2022-11-13 17:40:31 +00:00
|
|
|
'/' . preg_quote(dcCore::app()->adminurl->get('translater')) . '(&.*)?$/',
|
2021-09-17 23:29:28 +00:00
|
|
|
$_SERVER['REQUEST_URI']
|
|
|
|
),
|
2022-11-13 17:40:31 +00:00
|
|
|
dcCore::app()->auth->isSuperAdmin()
|
2021-08-18 19:42:30 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
class translaterAdminBehaviors
|
|
|
|
{
|
2021-11-09 22:58:45 +00:00
|
|
|
/** @var dcTranslater dcTranslater instance */
|
2021-09-24 23:58:59 +00:00
|
|
|
private static $translater = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create instance of dcTranslater once
|
2021-11-01 21:32:32 +00:00
|
|
|
*
|
2021-11-09 22:58:45 +00:00
|
|
|
* @return dcTranslater dcTranslater instance
|
2021-09-24 23:58:59 +00:00
|
|
|
*/
|
2022-11-13 17:40:31 +00:00
|
|
|
private static function translater(): dcTranslater
|
2021-09-24 23:58:59 +00:00
|
|
|
{
|
2021-11-09 22:58:45 +00:00
|
|
|
if (!is_a(self::$translater, 'dcTranslater')) {
|
2022-11-13 17:40:31 +00:00
|
|
|
self::$translater = new dcTranslater(false);
|
2021-09-24 23:58:59 +00:00
|
|
|
}
|
2021-11-01 21:32:32 +00:00
|
|
|
|
2021-09-24 23:58:59 +00:00
|
|
|
return self::$translater;
|
|
|
|
}
|
|
|
|
|
2021-09-17 23:29:28 +00:00
|
|
|
/**
|
|
|
|
* Add button to go to module translation
|
2021-11-01 21:32:32 +00:00
|
|
|
*
|
2021-11-09 22:58:45 +00:00
|
|
|
* @param adminModulesList $list adminModulesList instance
|
|
|
|
* @param string $id Module id
|
|
|
|
* @param array $prop Module properties
|
|
|
|
*
|
|
|
|
* @return string HTML submit button
|
2021-09-17 23:29:28 +00:00
|
|
|
*/
|
|
|
|
public static function adminModulesGetActions(adminModulesList $list, string $id, array $prop): ?string
|
2021-08-18 22:48:47 +00:00
|
|
|
{
|
2021-11-01 21:32:32 +00:00
|
|
|
if ($list->getList() != $prop['type'] . '-activate'
|
2022-11-13 17:40:31 +00:00
|
|
|
|| !self::translater()->{$prop['type'] . '_menu'}
|
|
|
|
|| !dcCore::app()->auth->isSuperAdmin()
|
2021-09-17 23:29:28 +00:00
|
|
|
) {
|
|
|
|
return null;
|
2021-08-18 22:48:47 +00:00
|
|
|
}
|
2022-11-13 17:40:31 +00:00
|
|
|
if (self::translater()->hide_default
|
2021-11-09 22:58:45 +00:00
|
|
|
&& in_array($id, dcTranslater::$default_distrib_modules[$prop['type']])
|
2021-09-25 15:49:48 +00:00
|
|
|
) {
|
|
|
|
return null;
|
|
|
|
}
|
2021-09-02 21:44:01 +00:00
|
|
|
|
2021-11-01 21:32:32 +00:00
|
|
|
return
|
|
|
|
' <input type="submit" name="translater[' .
|
|
|
|
html::escapeHTML($id) .
|
2021-09-25 15:24:38 +00:00
|
|
|
']" 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
|
2021-11-01 21:32:32 +00:00
|
|
|
*
|
2021-09-17 23:29:28 +00:00
|
|
|
* @param adminModulesList $list adminModulesList instance
|
|
|
|
* @param array $modules Selected modules ids
|
|
|
|
* @param string $type List type (plugin|theme)
|
|
|
|
*/
|
2021-11-09 22:58:45 +00:00
|
|
|
public static function adminModulesDoActions(adminModulesList $list, array $modules, string $type): void
|
2021-08-18 22:48:47 +00:00
|
|
|
{
|
2021-09-17 23:29:28 +00:00
|
|
|
if (empty($_POST['translater']) || !is_array($_POST['translater'])) {
|
2021-11-09 22:58:45 +00:00
|
|
|
return;
|
2021-08-18 22:48:47 +00:00
|
|
|
}
|
2021-09-02 21:44:01 +00:00
|
|
|
|
2022-11-13 17:40:31 +00:00
|
|
|
dcCore::app()->adminurl->redirect(
|
2021-11-01 21:32:32 +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
|
2021-11-01 21:32:32 +00:00
|
|
|
*
|
2021-09-17 23:29:28 +00:00
|
|
|
* @param dcFavorites $favs dcFavorites instance
|
|
|
|
*/
|
2022-11-26 14:12:54 +00:00
|
|
|
public static function adminDashboardFavoritesV2(dcFavorites $favs): void
|
2021-09-17 23:29:28 +00:00
|
|
|
{
|
|
|
|
$favs->register('translater', [
|
|
|
|
'title' => __('Translater'),
|
2022-11-13 17:40:31 +00:00
|
|
|
'url' => dcCore::app()->adminurl->get('translater'),
|
2022-11-26 14:12:54 +00:00
|
|
|
'small-icon' => urldecode(dcPage::getPF('translater/icon.svg')),
|
|
|
|
'large-icon' => urldecode(dcPage::getPF('translater/icon.svg')),
|
2022-12-03 16:10:38 +00:00
|
|
|
//'permissions' => null,
|
2021-09-17 23:29:28 +00:00
|
|
|
]);
|
2021-08-18 22:48:47 +00:00
|
|
|
}
|
2021-11-01 21:32:32 +00:00
|
|
|
}
|