translater/_admin.php

122 lines
3.7 KiB
PHP
Raw Normal View History

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-12-26 20:19:57 +00:00
dcCore::app()->addBehaviors([
'adminModulesListGetActions' => ['translaterAdminBehaviors', 'adminModulesGetActions'],
'adminModulesListDoActions' => ['translaterAdminBehaviors', 'adminModulesDoActions'],
'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-12-26 20:48:51 +00:00
dcCore::app()->adminurl->get(basename(__DIR__)),
dcPage::getPF(basename(__DIR__) . '/icon.svg'),
preg_match(
2022-12-26 20:48:51 +00:00
'/' . preg_quote(dcCore::app()->adminurl->get(basename(__DIR__))) . '(&.*)?$/',
$_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
{
/** @var dcTranslater dcTranslater instance */
private static $translater = null;
/**
* Create instance of dcTranslater once
2021-11-01 21:32:32 +00:00
*
* @return dcTranslater dcTranslater instance
*/
2022-11-13 17:40:31 +00:00
private static function translater(): dcTranslater
{
if (!is_a(self::$translater, 'dcTranslater')) {
2022-11-13 17:40:31 +00:00
self::$translater = new dcTranslater(false);
}
2021-11-01 21:32:32 +00:00
return self::$translater;
}
/**
* Add button to go to module translation
2021-11-01 21:32:32 +00:00
*
* @param adminModulesList $list adminModulesList instance
* @param string $id Module id
* @param array $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-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()
) {
return null;
2021-08-18 22:48:47 +00:00
}
2022-11-13 17:40:31 +00:00
if (self::translater()->hide_default
&& in_array($id, dcTranslater::$default_distrib_modules[$prop['type']])
) {
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
/**
* Redirect to module translation
2021-11-01 21:32:32 +00:00
*
* @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): void
2021-08-18 22:48:47 +00:00
{
if (empty($_POST['translater']) || !is_array($_POST['translater'])) {
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(
2022-12-26 20:48:51 +00:00
basename(__DIR__),
['part' => 'module', 'type' => $type, 'module' => key($_POST['translater'])],
'#module-lang'
);
}
2021-09-02 21:44:01 +00:00
/**
* Add dashboard favorites icon
2021-11-01 21:32:32 +00:00
*
* @param dcFavorites $favs dcFavorites instance
*/
2022-11-26 14:12:54 +00:00
public static function adminDashboardFavoritesV2(dcFavorites $favs): void
{
$favs->register('translater', [
2022-12-26 20:19:57 +00:00
'title' => __('Translater'),
2022-12-26 20:48:51 +00:00
'url' => dcCore::app()->adminurl->get(basename(__DIR__)),
'small-icon' => urldecode(dcPage::getPF(basename(__DIR__) . '/icon.svg')),
'large-icon' => urldecode(dcPage::getPF(basename(__DIR__) . '/icon.svg')),
2022-12-03 16:10:38 +00:00
//'permissions' => null,
]);
2021-08-18 22:48:47 +00:00
}
2021-11-01 21:32:32 +00:00
}