release 2023.07.29
This commit is contained in:
parent
444bff5a07
commit
5dd0eab5c0
14 changed files with 155 additions and 249 deletions
|
@ -4,6 +4,11 @@ dev
|
|||
- [ ] fix third-party API (temp removed)
|
||||
- [ ] fix multiline translations
|
||||
|
||||
2023.07.29
|
||||
- require Dotclear 2.27
|
||||
- require PHP 8.1+
|
||||
- update to Dotclear 2.27-dev
|
||||
|
||||
2023.06.18
|
||||
- require dotclear 2.26
|
||||
- require php 8.1+
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
[![Release](https://img.shields.io/github/v/release/JcDenis/translater)](https://github.com/JcDenis/translater/releases)
|
||||
[![Date](https://img.shields.io/github/release-date/JcDenis/translater)](https://github.com/JcDenis/translater/releases)
|
||||
[![Issues](https://img.shields.io/github/issues/JcDenis/translater)](https://github.com/JcDenis/translater/issues)
|
||||
[![Dotclear](https://img.shields.io/badge/dotclear-v2.26-blue.svg)](https://fr.dotclear.org/download)
|
||||
[![Dotclear](https://img.shields.io/badge/dotclear-v2.27-blue.svg)](https://fr.dotclear.org/download)
|
||||
[![Dotaddict](https://img.shields.io/badge/dotaddict-official-green.svg)](https://plugins.dotaddict.org/dc2/details/translater)
|
||||
[![License](https://img.shields.io/github/license/JcDenis/translater)](https://github.com/JcDenis/translater/blob/master/LICENSE)
|
||||
|
||||
|
@ -19,7 +19,7 @@ It helps dev to translate plugin and theme.
|
|||
_translater_ requires:
|
||||
|
||||
* super admin permissions
|
||||
* Dotclear 2.26
|
||||
* Dotclear 2.27
|
||||
* PHP 8.1+
|
||||
|
||||
## USAGE
|
||||
|
|
|
@ -18,11 +18,11 @@ $this->registerModule(
|
|||
'Translater',
|
||||
'Translate your Dotclear plugins and themes',
|
||||
'Jean-Christian Denis & contributors',
|
||||
'2023.06.18',
|
||||
'2023.07.29',
|
||||
[
|
||||
'requires' => [
|
||||
['php', '8.1'],
|
||||
['core', '2.26'],
|
||||
['core', '2.27'],
|
||||
],
|
||||
'permissions' => null,
|
||||
'type' => 'plugin',
|
||||
|
|
|
@ -2,11 +2,11 @@
|
|||
<modules xmlns:da="http://dotaddict.org/da/">
|
||||
<module id="translater">
|
||||
<name>Translater</name>
|
||||
<version>2023.06.18</version>
|
||||
<version>2023.07.29</version>
|
||||
<author>Jean-Christian Denis & contributors</author>
|
||||
<desc>Translate your Dotclear plugins and themes</desc>
|
||||
<file>https://github.com/JcDenis/translater/releases/download/v2023.06.18/plugin-translater.zip</file>
|
||||
<da:dcmin>2.26</da:dcmin>
|
||||
<file>https://github.com/JcDenis/translater/releases/download/v2023.07.29/plugin-translater.zip</file>
|
||||
<da:dcmin>2.27</da:dcmin>
|
||||
<da:details>https://plugins.dotaddict.org/dc2/details/translater</da:details>
|
||||
<da:support>http://forum.dotclear.org/viewtopic.php?id=39220</da:support>
|
||||
</module>
|
||||
|
|
|
@ -14,53 +14,39 @@ declare(strict_types=1);
|
|||
|
||||
namespace Dotclear\Plugin\translater;
|
||||
|
||||
use dcAdmin;
|
||||
use dcCore;
|
||||
use dcFavorites;
|
||||
use dcNsProcess;
|
||||
use dcPage;
|
||||
use Dotclear\Core\Process;
|
||||
use Dotclear\Core\Backend\Favorites;
|
||||
|
||||
class Backend extends dcNsProcess
|
||||
class Backend extends Process
|
||||
{
|
||||
public static function init(): bool
|
||||
{
|
||||
static::$init = defined('DC_CONTEXT_ADMIN')
|
||||
&& dcCore::app()->auth?->isSuperAdmin();
|
||||
|
||||
return static::$init;
|
||||
return self::status(My::checkContext(My::BACKEND));
|
||||
}
|
||||
|
||||
public static function process(): bool
|
||||
{
|
||||
if (!static::$init) {
|
||||
if (!self::status()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
My::addBackendMenuItem();
|
||||
|
||||
dcCore::app()->addBehaviors([
|
||||
'adminModulesListGetActions' => [BackendBehaviors::class, 'adminModulesGetActions'],
|
||||
'adminModulesListDoActions' => [BackendBehaviors::class, 'adminModulesDoActions'],
|
||||
'adminDashboardFavoritesV2' => function (dcFavorites $favs): void {
|
||||
'adminDashboardFavoritesV2' => function (Favorites $favs): void {
|
||||
$favs->register(My::id(), [
|
||||
'title' => My::name(),
|
||||
'url' => dcCore::app()->adminurl?->get(My::id()),
|
||||
'small-icon' => dcPage::getPF(My::id() . '/icon.svg'),
|
||||
'large-icon' => dcPage::getPF(My::id() . '/icon.svg'),
|
||||
'url' => My::manageUrl(),
|
||||
'small-icon' => My::icons(),
|
||||
'large-icon' => My::icons(),
|
||||
//'permissions' => null,
|
||||
]);
|
||||
},
|
||||
]);
|
||||
|
||||
dcCore::app()->menu[dcAdmin::MENU_PLUGINS]->addItem(
|
||||
My::name(),
|
||||
dcCore::app()->adminurl?->get(My::id()),
|
||||
dcPage::getPF(My::id() . '/icon.svg'),
|
||||
preg_match(
|
||||
'/' . preg_quote((string) dcCore::app()->adminurl?->get(My::id())) . '(&.*)?$/',
|
||||
$_SERVER['REQUEST_URI']
|
||||
),
|
||||
dcCore::app()->auth?->isSuperAdmin()
|
||||
);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,8 +14,8 @@ declare(strict_types=1);
|
|||
|
||||
namespace Dotclear\Plugin\translater;
|
||||
|
||||
use adminModulesList;
|
||||
use dcCore;
|
||||
use Dotclear\Core\Backend\ModulesList;
|
||||
use Dotclear\Helper\Html\Form\Submit;
|
||||
use Dotclear\Helper\Html\Html;
|
||||
|
||||
|
@ -27,7 +27,7 @@ class BackendBehaviors
|
|||
/**
|
||||
* Create instance of Translater once
|
||||
*
|
||||
* @return Translater Translater instance
|
||||
* @return Translater Translater instance
|
||||
*/
|
||||
private static function translater(): Translater
|
||||
{
|
||||
|
@ -41,13 +41,13 @@ class BackendBehaviors
|
|||
/**
|
||||
* Add button to go to module translation
|
||||
*
|
||||
* @param adminModulesList $list adminModulesList instance
|
||||
* @param string $id Module id
|
||||
* @param array $prop Module properties
|
||||
* @param ModulesList $list ModulesList instance
|
||||
* @param string $id Module id
|
||||
* @param array $prop Module properties
|
||||
*
|
||||
* @return string HTML submit button
|
||||
* @return string HTML submit button
|
||||
*/
|
||||
public static function adminModulesGetActions(adminModulesList $list, string $id, array $prop): ?string
|
||||
public static function adminModulesGetActions(ModulesList $list, string $id, array $prop): ?string
|
||||
{
|
||||
if ($list->getList() != $prop['type'] . '-activate'
|
||||
|| !self::translater()->getSetting($prop['type'] . '_menu')
|
||||
|
@ -67,20 +67,16 @@ class BackendBehaviors
|
|||
/**
|
||||
* Redirect to module translation
|
||||
*
|
||||
* @param adminModulesList $list adminModulesList instance
|
||||
* @param array $modules Selected modules ids
|
||||
* @param string $type List type (plugin|theme)
|
||||
* @param ModulesList $list ModulesList 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
|
||||
public static function adminModulesDoActions(ModulesList $list, array $modules, string $type): void
|
||||
{
|
||||
if (empty($_POST['translater']) || !is_array($_POST['translater'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
dcCore::app()->adminurl?->redirect(
|
||||
My::id(),
|
||||
['part' => 'module', 'type' => $type, 'module' => key($_POST['translater'])],
|
||||
'#module-lang'
|
||||
);
|
||||
My::redirect(['part' => 'module', 'type' => $type, 'module' => key($_POST['translater'])], '#module-lang');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,8 +15,11 @@ declare(strict_types=1);
|
|||
namespace Dotclear\Plugin\translater;
|
||||
|
||||
use dcCore;
|
||||
use dcNsProcess;
|
||||
use dcPage;
|
||||
use Dotclear\Core\Process;
|
||||
use Dotclear\Core\Backend\{
|
||||
Notices,
|
||||
Page
|
||||
};
|
||||
use Dotclear\Helper\Html\Form\{
|
||||
Checkbox,
|
||||
Div,
|
||||
|
@ -31,19 +34,16 @@ use Dotclear\Helper\Html\Form\{
|
|||
};
|
||||
use Exception;
|
||||
|
||||
class Config extends dcNsProcess
|
||||
class Config extends Process
|
||||
{
|
||||
public static function init(): bool
|
||||
{
|
||||
static::$init = defined('DC_CONTEXT_ADMIN')
|
||||
&& dcCore::app()->auth?->isSuperAdmin();
|
||||
|
||||
return static::$init;
|
||||
return self::status(My::checkContext(My::CONFIG));
|
||||
}
|
||||
|
||||
public static function process(): bool
|
||||
{
|
||||
if (!static::$init) {
|
||||
if (!self::status()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -63,10 +63,10 @@ class Config extends dcNsProcess
|
|||
}
|
||||
}
|
||||
|
||||
dcPage::addSuccessNotice(
|
||||
Notices::addSuccessNotice(
|
||||
__('Configuration successfully updated.')
|
||||
);
|
||||
dcCore::app()->adminurl?->redirect(
|
||||
dcCore::app()->admin->url->redirect(
|
||||
'admin.plugins',
|
||||
['module' => My::id(), 'conf' => 1, 'redir' => dcCore::app()->admin->__get('list')->getRedir()]
|
||||
);
|
||||
|
@ -79,7 +79,7 @@ class Config extends dcNsProcess
|
|||
|
||||
public static function render(): void
|
||||
{
|
||||
if (!static::$init) {
|
||||
if (!self::status()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -177,6 +177,6 @@ class Config extends dcNsProcess
|
|||
]),
|
||||
])->render();
|
||||
|
||||
dcPage::helpBlock('translater.config');
|
||||
Page::helpBlock('translater.config');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,22 +16,19 @@ namespace Dotclear\Plugin\translater;
|
|||
|
||||
use dcCore;
|
||||
use dcNamespace;
|
||||
use dcNsProcess;
|
||||
use Dotclear\Core\Process;
|
||||
use Exception;
|
||||
|
||||
class Install extends dcNsProcess
|
||||
class Install extends Process
|
||||
{
|
||||
public static function init(): bool
|
||||
{
|
||||
static::$init = defined('DC_CONTEXT_ADMIN')
|
||||
&& dcCore::app()->newVersion(My::id(), dcCore::app()->plugins->moduleInfo(My::id(), 'version'));
|
||||
|
||||
return static::$init;
|
||||
return self::status(My::checkContext(My::INSTALL));
|
||||
}
|
||||
|
||||
public static function process(): bool
|
||||
{
|
||||
if (!static::$init) {
|
||||
if (!self::status()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
195
src/Manage.php
195
src/Manage.php
|
@ -15,8 +15,11 @@ declare(strict_types=1);
|
|||
namespace Dotclear\Plugin\translater;
|
||||
|
||||
use dcCore;
|
||||
use dcNsProcess;
|
||||
use dcPage;
|
||||
use Dotclear\Core\Process;
|
||||
use Dotclear\Core\Backend\{
|
||||
Notices,
|
||||
Page
|
||||
};
|
||||
use Dotclear\Helper\File\Files;
|
||||
use Dotclear\Helper\Html\Form\{
|
||||
Checkbox,
|
||||
|
@ -35,19 +38,16 @@ use Dotclear\Helper\Date;
|
|||
use Dotclear\Helper\Html\Html;
|
||||
use Exception;
|
||||
|
||||
class Manage extends dcNsProcess
|
||||
class Manage extends Process
|
||||
{
|
||||
public static function init(): bool
|
||||
{
|
||||
static::$init = defined('DC_CONTEXT_ADMIN')
|
||||
&& dcCore::app()->auth?->isSuperAdmin();
|
||||
|
||||
return static::$init;
|
||||
return self::status(My::checkContext(My::MANAGE));
|
||||
}
|
||||
|
||||
public static function process(): bool
|
||||
{
|
||||
if (!static::$init) {
|
||||
if (!self::status()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -131,7 +131,7 @@ class Manage extends dcNsProcess
|
|||
}
|
||||
}
|
||||
|
||||
self::redirect(__('Language successfully deleted'), $_POST['code']);
|
||||
self::redirect(__('Language successfully deleted'));
|
||||
}
|
||||
|
||||
if ($current->action == 'module_update_code') {
|
||||
|
@ -158,48 +158,48 @@ class Manage extends dcNsProcess
|
|||
|
||||
public static function render(): void
|
||||
{
|
||||
if (!static::$init) {
|
||||
if (!self::status()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$current = ManageVars::init();
|
||||
|
||||
$breadcrumb = [My::name() => dcCore::app()->adminurl?->get(My::id(), ['type' => '-'])];
|
||||
$breadcrumb = [My::name() => My::manageUrl(['type' => '-'])];
|
||||
if (empty($current->type)) {
|
||||
$breadcrumb = [My::name() => ''];
|
||||
} elseif (empty($current->module)) {
|
||||
$breadcrumb[$current->type == 'plugin' ? __('Plugins') : __('Themes')] = '';
|
||||
} elseif (empty($current->lang)) {
|
||||
$breadcrumb[$current->type == 'plugin' ? __('Plugins') : __('Themes')] = dcCore::app()->adminurl?->get(My::id(), ['type' => $current->type]);
|
||||
$breadcrumb[$current->type == 'plugin' ? __('Plugins') : __('Themes')] = My::manageUrl(['type' => $current->type]);
|
||||
$breadcrumb[Html::escapeHTML($current->module->name)] = '';
|
||||
} elseif (!empty($current->lang)) {
|
||||
$breadcrumb[$current->type == 'plugin' ? __('Plugins') : __('Themes')] = dcCore::app()->adminurl?->get(My::id(), ['type' => $current->type]);
|
||||
$breadcrumb[Html::escapeHTML($current->module->name)] = dcCore::app()->adminurl?->get(My::id(), ['type' => $current->type, 'module' => $current->module->id]);
|
||||
$breadcrumb[$current->type == 'plugin' ? __('Plugins') : __('Themes')] = My::manageUrl(['type' => $current->type]);
|
||||
$breadcrumb[Html::escapeHTML($current->module->name)] = My::manageUrl(['type' => $current->type, 'module' => $current->module->id]);
|
||||
$breadcrumb[Html::escapeHTML(sprintf(__('%s language edition'), $current->lang->name))] = '';
|
||||
}
|
||||
|
||||
dcPage::openModule(
|
||||
Page::openModule(
|
||||
My::name(),
|
||||
dcPage::jsPageTabs() .
|
||||
dcPage::cssModuleLoad(My::id() . '/css/backend.css') .
|
||||
dcPage::jsJson('translater', [
|
||||
Page::jsPageTabs() .
|
||||
My::cssLoad('backend') .
|
||||
Page::jsJson('translater', [
|
||||
'title_add_detail' => __('Use this text'),
|
||||
'image_field' => dcPage::getPF(My::id() . '/img/field.png'),
|
||||
'image_toggle' => dcPage::getPF(My::id() . '/img/toggle.png'),
|
||||
'image_field' => My::fileURL('/img/field.png'),
|
||||
'image_toggle' => My::fileURL('/img/toggle.png'),
|
||||
]) .
|
||||
dcPage::jsModuleLoad(My::id() . '/js/backend.js') .
|
||||
My::jsLoad('backend') .
|
||||
|
||||
# --BEHAVIOR-- translaterAdminHeaders
|
||||
dcCore::app()->callBehavior('translaterAdminHeaders')
|
||||
);
|
||||
|
||||
echo
|
||||
dcPage::breadcrumb($breadcrumb) .
|
||||
dcPage::notices();
|
||||
Page::breadcrumb($breadcrumb) .
|
||||
Notices::getNotices();
|
||||
|
||||
if (empty($current->module) && $current->type != '') {
|
||||
// modules list
|
||||
echo '<form id="theme-form" method="post" action="' . dcCore::app()->adminurl?->get(My::id(), ['type' => 'plugin']) . '">';
|
||||
echo '<form id="theme-form" method="post" action="' . My::manageUrl(['type' => 'plugin']) . '">';
|
||||
|
||||
$res = '';
|
||||
$modules = $current->translater->getModules($current->type);
|
||||
|
@ -211,7 +211,7 @@ class Manage extends dcNsProcess
|
|||
if ($module->root_writable) {
|
||||
$res .= sprintf(
|
||||
'<tr class="line"><td class="nowrap minimal"><a href="%s" title="%s">%s</a></td>',
|
||||
dcCore::app()->adminurl?->get(My::id(), ['type' => $module->type, 'module' => $module->id]),
|
||||
My::manageUrl(['type' => $module->type, 'module' => $module->id]),
|
||||
Html::escapeHTML(sprintf(__('Translate module %s'), __($module->name))),
|
||||
Html::escapeHTML($module->id)
|
||||
);
|
||||
|
@ -227,7 +227,7 @@ class Manage extends dcNsProcess
|
|||
$codes[$code_id] = sprintf(
|
||||
'<a class="wait maximal nowrap" title="%s" href="%s">%s (%s)</a>',
|
||||
Html::escapeHTML(sprintf(__('Edit language %s of module %s'), Html::escapeHTML($code_name), __($module->name))),
|
||||
dcCore::app()->adminurl?->get(My::id(), ['type' => $module->type, 'module' => $module->id, 'lang' => $code_id]),
|
||||
My::manageUrl(['type' => $module->type, 'module' => $module->id, 'lang' => $code_id]),
|
||||
Html::escapeHTML($code_name),
|
||||
$code_id
|
||||
);
|
||||
|
@ -260,7 +260,7 @@ class Manage extends dcNsProcess
|
|||
}
|
||||
echo '</form>';
|
||||
|
||||
dcPage::helpBlock('translater.type');
|
||||
Page::helpBlock('translater.type');
|
||||
} elseif (!empty($current->module) && empty($current->lang)) {
|
||||
$codes = $current->module->getUsedLangs();
|
||||
$backups = $current->module->getBackups();
|
||||
|
@ -279,7 +279,7 @@ class Manage extends dcNsProcess
|
|||
if (count($codes)) {
|
||||
echo
|
||||
'<div class="clear fieldset"><h3>' . __('Translations') . '</h3>' .
|
||||
'<form id="module-translations-form" method="post" action="' . dcCore::app()->adminurl?->get(My::id()) . '">' .
|
||||
'<form id="module-translations-form" method="post" action="' . My::manageUrl() . '">' .
|
||||
'<table class="clear maximal">' .
|
||||
'<caption>' . __('Existing languages translations') . '</caption>' .
|
||||
'<tr>' .
|
||||
|
@ -295,7 +295,7 @@ class Manage extends dcNsProcess
|
|||
'<td class="minimal">' . (new Checkbox(['codes[]', 'existing_code_' . $code_id]))->value($code_id)->render() . '</td>' .
|
||||
'<td class="nowrap">' .
|
||||
'<a href="' .
|
||||
dcCore::app()->adminurl?->get(My::id(), ['type' => $current->module->type, 'module' => $current->module->id, 'lang' => $code_id])
|
||||
My::manageUrl(['type' => $current->module->type, 'module' => $current->module->id, 'lang' => $code_id])
|
||||
. '" title="' . sprintf(__('Edit %s language'), Html::escapeHTML($code_name)) . '">' . $code_name . '</a>' .
|
||||
'</td>' .
|
||||
'<td class="nowrap maximal"> ' . $code_id . '</td>';
|
||||
|
@ -320,22 +320,19 @@ class Manage extends dcNsProcess
|
|||
<div class="two-cols">
|
||||
<p class="col checkboxes-helpers"></p>' .
|
||||
|
||||
(new Para())->class('col right')->items(array_merge(
|
||||
[
|
||||
(new Text('', __('Selected languages action:'))),
|
||||
(new Select('action'))->items([
|
||||
__('Backup languages') => 'module_create_backups',
|
||||
__('Delete languages') => 'module_delete_codes',
|
||||
__('Export languages') => 'module_export_pack',
|
||||
]),
|
||||
(new Submit('do-action'))->value(__('ok')),
|
||||
dcCore::app()->formNonce(false),
|
||||
],
|
||||
is_null(dcCore::app()->adminurl) ? [] : dcCore::app()->adminurl->hiddenFormFields(
|
||||
My::id(),
|
||||
['type' => $current->module->type, 'module' => $current->module->id]
|
||||
)
|
||||
))->render() .
|
||||
(new Para())->class('col right')->items([
|
||||
(new Text('', __('Selected languages action:'))),
|
||||
(new Select('action'))->items([
|
||||
__('Backup languages') => 'module_create_backups',
|
||||
__('Delete languages') => 'module_delete_codes',
|
||||
__('Export languages') => 'module_export_pack',
|
||||
]),
|
||||
(new Submit('do-action'))->value(__('ok')),
|
||||
... My::hiddenFields([
|
||||
'type' => $current->module->type,
|
||||
'module' => $current->module->id,
|
||||
]),
|
||||
])->render() .
|
||||
'</div></form><p> </p></div>';
|
||||
}
|
||||
|
||||
|
@ -344,7 +341,7 @@ class Manage extends dcNsProcess
|
|||
// delete / retore backups
|
||||
if (!empty($backups)) {
|
||||
echo '<div class="fieldset"><h3>' . __('Backups') . '</h3>' .
|
||||
'<form id="module-backups-form" method="post" action="' . dcCore::app()->adminurl?->get(My::id()) . '">' .
|
||||
'<form id="module-backups-form" method="post" action="' . My::manageUrl() . '">' .
|
||||
'<table class="clear">' .
|
||||
'<caption>' . __('Existing languages backups') . '</caption>' .
|
||||
'<tr>' .
|
||||
|
@ -390,21 +387,18 @@ class Manage extends dcNsProcess
|
|||
<div class="two-cols">
|
||||
<p class="col checkboxes-helpers"></p>' .
|
||||
|
||||
(new Para())->class('col right')->items(array_merge(
|
||||
[
|
||||
(new Text('', __('Selected backups action:'))),
|
||||
(new Select('action'))->items([
|
||||
__('Restore backups') => 'module_restore_backup',
|
||||
__('Delete backups') => 'module_delete_backup',
|
||||
]),
|
||||
(new Submit('do-action'))->value(__('ok')),
|
||||
dcCore::app()->formNonce(false),
|
||||
],
|
||||
is_null(dcCore::app()->adminurl) ? [] : dcCore::app()->adminurl->hiddenFormFields(
|
||||
My::id(),
|
||||
['type' => $current->module->type, 'module' => $current->module->id]
|
||||
)
|
||||
))->render() .
|
||||
(new Para())->class('col right')->items([
|
||||
(new Text('', __('Selected backups action:'))),
|
||||
(new Select('action'))->items([
|
||||
__('Restore backups') => 'module_restore_backup',
|
||||
__('Delete backups') => 'module_delete_backup',
|
||||
]),
|
||||
(new Submit('do-action'))->value(__('ok')),
|
||||
... My::hiddenFields([
|
||||
'type' => $current->module->type,
|
||||
'module' => $current->module->id,
|
||||
]),
|
||||
])->render() .
|
||||
'</div></form><p> </p></div>';
|
||||
}
|
||||
}
|
||||
|
@ -414,7 +408,7 @@ class Manage extends dcNsProcess
|
|||
// add language
|
||||
if (!empty($unused_codes)) {
|
||||
echo '<div class="col fieldset"><h3>' . __('Add language') . '</h3>
|
||||
<form id="muodule-code-create-form" method="post" action="' . dcCore::app()->adminurl?->get(My::id()) . '">' .
|
||||
<form id="module-code-create-form" method="post" action="' . My::manageUrl() . '">' .
|
||||
(new Para())->class('field')->items([
|
||||
(new Label(__('Select language:')))->for('code'),
|
||||
(new Select(['code']))->default((string) dcCore::app()->auth?->getInfo('user_lang'))->items(array_merge(['-' => '-'], $unused_codes)),
|
||||
|
@ -431,50 +425,46 @@ class Manage extends dcNsProcess
|
|||
])->render();
|
||||
}
|
||||
echo
|
||||
(new Para())->items(array_merge(
|
||||
[
|
||||
(new Submit(['save']))->value(__('Create')),
|
||||
dcCore::app()->formNonce(false),
|
||||
],
|
||||
is_null(dcCore::app()->adminurl) ? [] : dcCore::app()->adminurl->hiddenFormFields(
|
||||
My::id(),
|
||||
['type' => $current->module->type, 'module' => $current->module->id, 'action' => 'module_add_code']
|
||||
)
|
||||
))->render() .
|
||||
(new Para())->items([
|
||||
(new Submit(['save']))->value(__('Create')),
|
||||
... My::hiddenFields([
|
||||
'type' => $current->module->type,
|
||||
'module' => $current->module->id,
|
||||
'action' => 'module_add_code',
|
||||
]),
|
||||
])->render() .
|
||||
'</form><p> </p></div>';
|
||||
}
|
||||
|
||||
// Import
|
||||
echo '<div class="col fieldset"><h3>' . __('Import') . '</h3>' .
|
||||
(new Form('module-pack-import-form'))->method('post')->action(dcCore::app()->adminurl?->get(My::id()))->extra('enctype="multipart/form-data"')->fields([
|
||||
(new Form('module-pack-import-form'))->method('post')->action(My::manageUrl())->extra('enctype="multipart/form-data"')->fields([
|
||||
(new Para())->items([
|
||||
(new Label(__('Select languages package to import:')))->for('packfile'),
|
||||
(new File('packfile')),
|
||||
|
||||
]),
|
||||
(new Para())->items(array_merge(
|
||||
[
|
||||
(new Submit(['save']))->value(__('Import')),
|
||||
dcCore::app()->formNonce(false),
|
||||
],
|
||||
is_null(dcCore::app()->adminurl) ? [] : dcCore::app()->adminurl->hiddenFormFields(
|
||||
My::id(),
|
||||
['type' => $current->module->type, 'module' => $current->module->id, 'action' => 'module_import_pack']
|
||||
)
|
||||
)),
|
||||
(new Para())->items([
|
||||
(new Submit(['save']))->value(__('Import')),
|
||||
... My::hiddenFields([
|
||||
'type' => $current->module->type,
|
||||
'module' => $current->module->id,
|
||||
'action' => 'module_import_pack',
|
||||
]),
|
||||
]),
|
||||
])->render() .
|
||||
'<p> </p></div>';
|
||||
|
||||
echo '</div>';
|
||||
|
||||
dcPage::helpBlock('translater.module');
|
||||
Page::helpBlock('translater.module');
|
||||
} elseif (!empty($current->lang)) {
|
||||
$lines = $current->lang->getMessages();
|
||||
$allowed_l10n_groups = [];
|
||||
|
||||
echo
|
||||
'<div id="lang-form">' .
|
||||
'<form id="lang-edit-form" method="post" action="' . dcCore::app()->adminurl?->get(My::id()) . '">' .
|
||||
'<form id="lang-edit-form" method="post" action="' . My::manageUrl() . '">' .
|
||||
'<table class="table-outer">' .
|
||||
'<caption>' . sprintf(__('List of %s localized strings'), count($lines)) . '</caption>' .
|
||||
'<tr>' .
|
||||
|
@ -597,23 +587,22 @@ class Manage extends dcNsProcess
|
|||
(new Select('multigroup'))->items(My::l10nGroupsCombo()),
|
||||
])->render() .
|
||||
'</div>' .
|
||||
(new Para())->class('col right')->items(array_merge(
|
||||
[
|
||||
(new Submit('do-action'))->value(__('Save') . ' (s)')->accesskey('s'),
|
||||
dcCore::app()->formNonce(false),
|
||||
(new Hidden(['code'], $current->lang->code)),
|
||||
],
|
||||
is_null(dcCore::app()->adminurl) ? [] : dcCore::app()->adminurl->hiddenFormFields(
|
||||
My::id(),
|
||||
['type' => $current->module?->type, 'module' => $current->module?->id, 'lang' => $current->lang->code, 'action' => 'module_update_code']
|
||||
)
|
||||
))->render() .
|
||||
(new Para())->class('col right')->items([
|
||||
(new Submit('do-action'))->value(__('Save') . ' (s)')->accesskey('s'),
|
||||
... My::hiddenFields([
|
||||
'type' => $current->module->type,
|
||||
'module' => $current->module->id,
|
||||
'action' => 'module_update_code',
|
||||
'lang' => $current->lang->code,
|
||||
'code' => $current->lang->code, //?
|
||||
]),
|
||||
])->render() .
|
||||
'</div>' .
|
||||
'</form>' .
|
||||
'<p> </p>' .
|
||||
'</div>';
|
||||
|
||||
dcPage::helpBlock('translater.lang');
|
||||
Page::helpBlock('translater.lang');
|
||||
} else {
|
||||
$line = '<li><a href="%s"%s>%s</a></li>';
|
||||
echo '<h4><i>' . __('Translate your Dotclear plugins and themes') . '</i></h4>' .
|
||||
|
@ -621,22 +610,22 @@ class Manage extends dcNsProcess
|
|||
'<h3><ul class="nice">%s</ul></h3>',
|
||||
sprintf(
|
||||
$line,
|
||||
dcCore::app()->adminurl?->get(My::id(), ['type' => 'plugin']),
|
||||
My::manageUrl(['type' => 'plugin']),
|
||||
$current->type == 'plugin' ? ' class="active"' : '',
|
||||
__('Translate plugins')
|
||||
) .
|
||||
sprintf(
|
||||
$line,
|
||||
dcCore::app()->adminurl?->get(My::id(), ['type' => 'theme']),
|
||||
My::manageUrl(['type' => 'theme']),
|
||||
$current->type == 'theme' ? ' class="active"' : '',
|
||||
__('Translate themes')
|
||||
)
|
||||
);
|
||||
|
||||
dcPage::helpBlock('translater.index');
|
||||
Page::helpBlock('translater.index');
|
||||
}
|
||||
|
||||
dcPage::closeModule();
|
||||
Page::closeModule();
|
||||
}
|
||||
|
||||
private static function redirect(string $msg, ?string $lang = null): void
|
||||
|
@ -651,7 +640,7 @@ class Manage extends dcNsProcess
|
|||
$redir['lang'] = $lang;
|
||||
}
|
||||
|
||||
dcPage::addSuccessNotice($msg);
|
||||
dcCore::app()->adminurl?->redirect(My::id(), $redir);
|
||||
Notices::addSuccessNotice($msg);
|
||||
My::manageUrl($redir);
|
||||
}
|
||||
}
|
||||
|
|
29
src/My.php
29
src/My.php
|
@ -15,41 +15,20 @@ declare(strict_types=1);
|
|||
namespace Dotclear\Plugin\translater;
|
||||
|
||||
use dcCore;
|
||||
use Dotclear\Module\MyPlugin;
|
||||
|
||||
/**
|
||||
* Plugin definitions
|
||||
*/
|
||||
class My
|
||||
class My extends MyPlugin
|
||||
{
|
||||
/** @var string Locales folder name */
|
||||
public const LOCALES_FOLDER = 'locales';
|
||||
|
||||
/**
|
||||
* This module id.
|
||||
*/
|
||||
public static function id(): string
|
||||
public static function checkCustomContext(int $context): ?bool
|
||||
{
|
||||
return basename(dirname(__DIR__));
|
||||
return dcCore::app()->auth->isSuperAdmin();
|
||||
}
|
||||
|
||||
/**
|
||||
* This module name.
|
||||
*/
|
||||
public static function name(): string
|
||||
{
|
||||
$name = dcCore::app()->plugins->moduleInfo(self::id(), 'name');
|
||||
|
||||
return __(is_string($name) ? $name : self::id());
|
||||
}
|
||||
|
||||
/**
|
||||
* This module path.
|
||||
*/
|
||||
public static function path(): string
|
||||
{
|
||||
return dirname(__DIR__);
|
||||
}
|
||||
|
||||
/**
|
||||
* List of allowed backup folder
|
||||
*/
|
||||
|
|
|
@ -1,42 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dotclear\Plugin\translater;
|
||||
|
||||
use dcCore;
|
||||
use dcNsProcess;
|
||||
|
||||
class Prepend extends dcNsProcess
|
||||
{
|
||||
public static function init(): bool
|
||||
{
|
||||
static::$init = defined('DC_CONTEXT_ADMIN')
|
||||
&& dcCore::app()->auth?->isSuperAdmin();
|
||||
|
||||
return static::$init;
|
||||
}
|
||||
|
||||
public static function process(): bool
|
||||
{
|
||||
if (!static::$init) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isset(dcCore::app()->adminurl)) {
|
||||
dcCore::app()->adminurl->register(My::id(), 'plugin.php', ['p' => My::id()]);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -14,8 +14,6 @@ declare(strict_types=1);
|
|||
|
||||
namespace Dotclear\Plugin\translater;
|
||||
|
||||
use dcCore;
|
||||
|
||||
class Settings
|
||||
{
|
||||
// Show tranlsater button on plugins list
|
||||
|
@ -68,7 +66,7 @@ class Settings
|
|||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$s = dcCore::app()->blog?->settings->get(My::id());
|
||||
$s = My::settings();
|
||||
|
||||
$this->plugin_menu = (bool) ($s?->get('plugin_menu') ?? false);
|
||||
$this->theme_menu = (bool) ($s?->get('theme_menu') ?? false);
|
||||
|
@ -103,8 +101,8 @@ class Settings
|
|||
public function writeSetting(string $key, mixed $value): bool
|
||||
{
|
||||
if (property_exists($this, $key) && settype($value, gettype($this->{$key})) === true) {
|
||||
dcCore::app()->blog?->settings->get(My::id())->drop($key);
|
||||
dcCore::app()->blog?->settings->get(My::id())->put($key, $value, gettype($this->{$key}), '', true, true);
|
||||
My::settings()->drop($key);
|
||||
My::settings()->put($key, $value, gettype($this->{$key}), '', true, true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -119,7 +119,7 @@ class TranslaterModule
|
|||
break;
|
||||
|
||||
case 'translater':
|
||||
$tmp = Path::real(dcCore::app()->plugins->moduleRoot(My::id()));
|
||||
$tmp = Path::real(My::path());
|
||||
if ($tmp !== false && is_writable($tmp)) {
|
||||
@mkDir($tmp . DIRECTORY_SEPARATOR . My::LOCALES_FOLDER);
|
||||
$dir = $tmp . DIRECTORY_SEPARATOR . My::LOCALES_FOLDER;
|
||||
|
|
|
@ -15,21 +15,19 @@ declare(strict_types=1);
|
|||
namespace Dotclear\Plugin\translater;
|
||||
|
||||
use dcCore;
|
||||
use dcNsProcess;
|
||||
use Dotclear\Core\Process;
|
||||
use Dotclear\Plugin\Uninstaller\Uninstaller;
|
||||
|
||||
class Uninstall extends dcNsProcess
|
||||
class Uninstall extends Process
|
||||
{
|
||||
public static function init(): bool
|
||||
{
|
||||
static::$init = defined('DC_CONTEXT_ADMIN');
|
||||
|
||||
return static::$init;
|
||||
return self::status(My::checkContext(My::UNINSTALL));
|
||||
}
|
||||
|
||||
public static function process(): bool
|
||||
{
|
||||
if (!static::$init || !dcCore::app()->plugins->moduleExists('Uninstaller')) {
|
||||
if (!self::status() || !dcCore::app()->plugins->moduleExists('Uninstaller')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue