release 2023.07.29

This commit is contained in:
Jean-Christian Denis 2023-07-29 14:54:35 +02:00
parent 444bff5a07
commit 5dd0eab5c0
Signed by: JcDenis
GPG key ID: 1B5B8C5B90B6C951
14 changed files with 155 additions and 249 deletions

View file

@ -4,6 +4,11 @@ dev
- [ ] fix third-party API (temp removed) - [ ] fix third-party API (temp removed)
- [ ] fix multiline translations - [ ] fix multiline translations
2023.07.29
- require Dotclear 2.27
- require PHP 8.1+
- update to Dotclear 2.27-dev
2023.06.18 2023.06.18
- require dotclear 2.26 - require dotclear 2.26
- require php 8.1+ - require php 8.1+

View file

@ -3,7 +3,7 @@
[![Release](https://img.shields.io/github/v/release/JcDenis/translater)](https://github.com/JcDenis/translater/releases) [![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) [![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) [![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) [![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) [![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: _translater_ requires:
* super admin permissions * super admin permissions
* Dotclear 2.26 * Dotclear 2.27
* PHP 8.1+ * PHP 8.1+
## USAGE ## USAGE

View file

@ -18,11 +18,11 @@ $this->registerModule(
'Translater', 'Translater',
'Translate your Dotclear plugins and themes', 'Translate your Dotclear plugins and themes',
'Jean-Christian Denis & contributors', 'Jean-Christian Denis & contributors',
'2023.06.18', '2023.07.29',
[ [
'requires' => [ 'requires' => [
['php', '8.1'], ['php', '8.1'],
['core', '2.26'], ['core', '2.27'],
], ],
'permissions' => null, 'permissions' => null,
'type' => 'plugin', 'type' => 'plugin',

View file

@ -2,11 +2,11 @@
<modules xmlns:da="http://dotaddict.org/da/"> <modules xmlns:da="http://dotaddict.org/da/">
<module id="translater"> <module id="translater">
<name>Translater</name> <name>Translater</name>
<version>2023.06.18</version> <version>2023.07.29</version>
<author>Jean-Christian Denis &amp; contributors</author> <author>Jean-Christian Denis &amp; contributors</author>
<desc>Translate your Dotclear plugins and themes</desc> <desc>Translate your Dotclear plugins and themes</desc>
<file>https://github.com/JcDenis/translater/releases/download/v2023.06.18/plugin-translater.zip</file> <file>https://github.com/JcDenis/translater/releases/download/v2023.07.29/plugin-translater.zip</file>
<da:dcmin>2.26</da:dcmin> <da:dcmin>2.27</da:dcmin>
<da:details>https://plugins.dotaddict.org/dc2/details/translater</da:details> <da:details>https://plugins.dotaddict.org/dc2/details/translater</da:details>
<da:support>http://forum.dotclear.org/viewtopic.php?id=39220</da:support> <da:support>http://forum.dotclear.org/viewtopic.php?id=39220</da:support>
</module> </module>

View file

@ -14,53 +14,39 @@ declare(strict_types=1);
namespace Dotclear\Plugin\translater; namespace Dotclear\Plugin\translater;
use dcAdmin;
use dcCore; use dcCore;
use dcFavorites; use Dotclear\Core\Process;
use dcNsProcess; use Dotclear\Core\Backend\Favorites;
use dcPage;
class Backend extends dcNsProcess class Backend extends Process
{ {
public static function init(): bool public static function init(): bool
{ {
static::$init = defined('DC_CONTEXT_ADMIN') return self::status(My::checkContext(My::BACKEND));
&& dcCore::app()->auth?->isSuperAdmin();
return static::$init;
} }
public static function process(): bool public static function process(): bool
{ {
if (!static::$init) { if (!self::status()) {
return false; return false;
} }
My::addBackendMenuItem();
dcCore::app()->addBehaviors([ dcCore::app()->addBehaviors([
'adminModulesListGetActions' => [BackendBehaviors::class, 'adminModulesGetActions'], 'adminModulesListGetActions' => [BackendBehaviors::class, 'adminModulesGetActions'],
'adminModulesListDoActions' => [BackendBehaviors::class, 'adminModulesDoActions'], 'adminModulesListDoActions' => [BackendBehaviors::class, 'adminModulesDoActions'],
'adminDashboardFavoritesV2' => function (dcFavorites $favs): void { 'adminDashboardFavoritesV2' => function (Favorites $favs): void {
$favs->register(My::id(), [ $favs->register(My::id(), [
'title' => My::name(), 'title' => My::name(),
'url' => dcCore::app()->adminurl?->get(My::id()), 'url' => My::manageUrl(),
'small-icon' => dcPage::getPF(My::id() . '/icon.svg'), 'small-icon' => My::icons(),
'large-icon' => dcPage::getPF(My::id() . '/icon.svg'), 'large-icon' => My::icons(),
//'permissions' => null, //'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; return true;
} }
} }

View file

@ -14,8 +14,8 @@ declare(strict_types=1);
namespace Dotclear\Plugin\translater; namespace Dotclear\Plugin\translater;
use adminModulesList;
use dcCore; use dcCore;
use Dotclear\Core\Backend\ModulesList;
use Dotclear\Helper\Html\Form\Submit; use Dotclear\Helper\Html\Form\Submit;
use Dotclear\Helper\Html\Html; use Dotclear\Helper\Html\Html;
@ -27,7 +27,7 @@ class BackendBehaviors
/** /**
* Create instance of Translater once * Create instance of Translater once
* *
* @return Translater Translater instance * @return Translater Translater instance
*/ */
private static function translater(): Translater private static function translater(): Translater
{ {
@ -41,13 +41,13 @@ class BackendBehaviors
/** /**
* Add button to go to module translation * Add button to go to module translation
* *
* @param adminModulesList $list adminModulesList instance * @param ModulesList $list ModulesList instance
* @param string $id Module id * @param string $id Module id
* @param array $prop Module properties * @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' if ($list->getList() != $prop['type'] . '-activate'
|| !self::translater()->getSetting($prop['type'] . '_menu') || !self::translater()->getSetting($prop['type'] . '_menu')
@ -67,20 +67,16 @@ class BackendBehaviors
/** /**
* Redirect to module translation * Redirect to module translation
* *
* @param adminModulesList $list adminModulesList instance * @param ModulesList $list ModulesList instance
* @param array $modules Selected modules ids * @param array $modules Selected modules ids
* @param string $type List type (plugin|theme) * @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'])) { if (empty($_POST['translater']) || !is_array($_POST['translater'])) {
return; return;
} }
dcCore::app()->adminurl?->redirect( My::redirect(['part' => 'module', 'type' => $type, 'module' => key($_POST['translater'])], '#module-lang');
My::id(),
['part' => 'module', 'type' => $type, 'module' => key($_POST['translater'])],
'#module-lang'
);
} }
} }

View file

@ -15,8 +15,11 @@ declare(strict_types=1);
namespace Dotclear\Plugin\translater; namespace Dotclear\Plugin\translater;
use dcCore; use dcCore;
use dcNsProcess; use Dotclear\Core\Process;
use dcPage; use Dotclear\Core\Backend\{
Notices,
Page
};
use Dotclear\Helper\Html\Form\{ use Dotclear\Helper\Html\Form\{
Checkbox, Checkbox,
Div, Div,
@ -31,19 +34,16 @@ use Dotclear\Helper\Html\Form\{
}; };
use Exception; use Exception;
class Config extends dcNsProcess class Config extends Process
{ {
public static function init(): bool public static function init(): bool
{ {
static::$init = defined('DC_CONTEXT_ADMIN') return self::status(My::checkContext(My::CONFIG));
&& dcCore::app()->auth?->isSuperAdmin();
return static::$init;
} }
public static function process(): bool public static function process(): bool
{ {
if (!static::$init) { if (!self::status()) {
return false; return false;
} }
@ -63,10 +63,10 @@ class Config extends dcNsProcess
} }
} }
dcPage::addSuccessNotice( Notices::addSuccessNotice(
__('Configuration successfully updated.') __('Configuration successfully updated.')
); );
dcCore::app()->adminurl?->redirect( dcCore::app()->admin->url->redirect(
'admin.plugins', 'admin.plugins',
['module' => My::id(), 'conf' => 1, 'redir' => dcCore::app()->admin->__get('list')->getRedir()] ['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 public static function render(): void
{ {
if (!static::$init) { if (!self::status()) {
return; return;
} }
@ -177,6 +177,6 @@ class Config extends dcNsProcess
]), ]),
])->render(); ])->render();
dcPage::helpBlock('translater.config'); Page::helpBlock('translater.config');
} }
} }

View file

@ -16,22 +16,19 @@ namespace Dotclear\Plugin\translater;
use dcCore; use dcCore;
use dcNamespace; use dcNamespace;
use dcNsProcess; use Dotclear\Core\Process;
use Exception; use Exception;
class Install extends dcNsProcess class Install extends Process
{ {
public static function init(): bool public static function init(): bool
{ {
static::$init = defined('DC_CONTEXT_ADMIN') return self::status(My::checkContext(My::INSTALL));
&& dcCore::app()->newVersion(My::id(), dcCore::app()->plugins->moduleInfo(My::id(), 'version'));
return static::$init;
} }
public static function process(): bool public static function process(): bool
{ {
if (!static::$init) { if (!self::status()) {
return false; return false;
} }

View file

@ -15,8 +15,11 @@ declare(strict_types=1);
namespace Dotclear\Plugin\translater; namespace Dotclear\Plugin\translater;
use dcCore; use dcCore;
use dcNsProcess; use Dotclear\Core\Process;
use dcPage; use Dotclear\Core\Backend\{
Notices,
Page
};
use Dotclear\Helper\File\Files; use Dotclear\Helper\File\Files;
use Dotclear\Helper\Html\Form\{ use Dotclear\Helper\Html\Form\{
Checkbox, Checkbox,
@ -35,19 +38,16 @@ use Dotclear\Helper\Date;
use Dotclear\Helper\Html\Html; use Dotclear\Helper\Html\Html;
use Exception; use Exception;
class Manage extends dcNsProcess class Manage extends Process
{ {
public static function init(): bool public static function init(): bool
{ {
static::$init = defined('DC_CONTEXT_ADMIN') return self::status(My::checkContext(My::MANAGE));
&& dcCore::app()->auth?->isSuperAdmin();
return static::$init;
} }
public static function process(): bool public static function process(): bool
{ {
if (!static::$init) { if (!self::status()) {
return false; 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') { if ($current->action == 'module_update_code') {
@ -158,48 +158,48 @@ class Manage extends dcNsProcess
public static function render(): void public static function render(): void
{ {
if (!static::$init) { if (!self::status()) {
return; return;
} }
$current = ManageVars::init(); $current = ManageVars::init();
$breadcrumb = [My::name() => dcCore::app()->adminurl?->get(My::id(), ['type' => '-'])]; $breadcrumb = [My::name() => My::manageUrl(['type' => '-'])];
if (empty($current->type)) { if (empty($current->type)) {
$breadcrumb = [My::name() => '']; $breadcrumb = [My::name() => ''];
} elseif (empty($current->module)) { } elseif (empty($current->module)) {
$breadcrumb[$current->type == 'plugin' ? __('Plugins') : __('Themes')] = ''; $breadcrumb[$current->type == 'plugin' ? __('Plugins') : __('Themes')] = '';
} elseif (empty($current->lang)) { } 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)] = ''; $breadcrumb[Html::escapeHTML($current->module->name)] = '';
} elseif (!empty($current->lang)) { } 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)] = dcCore::app()->adminurl?->get(My::id(), ['type' => $current->type, 'module' => $current->module->id]); $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))] = ''; $breadcrumb[Html::escapeHTML(sprintf(__('%s language edition'), $current->lang->name))] = '';
} }
dcPage::openModule( Page::openModule(
My::name(), My::name(),
dcPage::jsPageTabs() . Page::jsPageTabs() .
dcPage::cssModuleLoad(My::id() . '/css/backend.css') . My::cssLoad('backend') .
dcPage::jsJson('translater', [ Page::jsJson('translater', [
'title_add_detail' => __('Use this text'), 'title_add_detail' => __('Use this text'),
'image_field' => dcPage::getPF(My::id() . '/img/field.png'), 'image_field' => My::fileURL('/img/field.png'),
'image_toggle' => dcPage::getPF(My::id() . '/img/toggle.png'), 'image_toggle' => My::fileURL('/img/toggle.png'),
]) . ]) .
dcPage::jsModuleLoad(My::id() . '/js/backend.js') . My::jsLoad('backend') .
# --BEHAVIOR-- translaterAdminHeaders # --BEHAVIOR-- translaterAdminHeaders
dcCore::app()->callBehavior('translaterAdminHeaders') dcCore::app()->callBehavior('translaterAdminHeaders')
); );
echo echo
dcPage::breadcrumb($breadcrumb) . Page::breadcrumb($breadcrumb) .
dcPage::notices(); Notices::getNotices();
if (empty($current->module) && $current->type != '') { if (empty($current->module) && $current->type != '') {
// modules list // 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 = ''; $res = '';
$modules = $current->translater->getModules($current->type); $modules = $current->translater->getModules($current->type);
@ -211,7 +211,7 @@ class Manage extends dcNsProcess
if ($module->root_writable) { if ($module->root_writable) {
$res .= sprintf( $res .= sprintf(
'<tr class="line"><td class="nowrap minimal"><a href="%s" title="%s">%s</a></td>', '<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(sprintf(__('Translate module %s'), __($module->name))),
Html::escapeHTML($module->id) Html::escapeHTML($module->id)
); );
@ -227,7 +227,7 @@ class Manage extends dcNsProcess
$codes[$code_id] = sprintf( $codes[$code_id] = sprintf(
'<a class="wait maximal nowrap" title="%s" href="%s">%s (%s)</a>', '<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))), 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), Html::escapeHTML($code_name),
$code_id $code_id
); );
@ -260,7 +260,7 @@ class Manage extends dcNsProcess
} }
echo '</form>'; echo '</form>';
dcPage::helpBlock('translater.type'); Page::helpBlock('translater.type');
} elseif (!empty($current->module) && empty($current->lang)) { } elseif (!empty($current->module) && empty($current->lang)) {
$codes = $current->module->getUsedLangs(); $codes = $current->module->getUsedLangs();
$backups = $current->module->getBackups(); $backups = $current->module->getBackups();
@ -279,7 +279,7 @@ class Manage extends dcNsProcess
if (count($codes)) { if (count($codes)) {
echo echo
'<div class="clear fieldset"><h3>' . __('Translations') . '</h3>' . '<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">' . '<table class="clear maximal">' .
'<caption>' . __('Existing languages translations') . '</caption>' . '<caption>' . __('Existing languages translations') . '</caption>' .
'<tr>' . '<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="minimal">' . (new Checkbox(['codes[]', 'existing_code_' . $code_id]))->value($code_id)->render() . '</td>' .
'<td class="nowrap">' . '<td class="nowrap">' .
'<a href="' . '<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>' . . '" title="' . sprintf(__('Edit %s language'), Html::escapeHTML($code_name)) . '">' . $code_name . '</a>' .
'</td>' . '</td>' .
'<td class="nowrap maximal"> ' . $code_id . '</td>'; '<td class="nowrap maximal"> ' . $code_id . '</td>';
@ -320,22 +320,19 @@ class Manage extends dcNsProcess
<div class="two-cols"> <div class="two-cols">
<p class="col checkboxes-helpers"></p>' . <p class="col checkboxes-helpers"></p>' .
(new Para())->class('col right')->items(array_merge( (new Para())->class('col right')->items([
[ (new Text('', __('Selected languages action:'))),
(new Text('', __('Selected languages action:'))), (new Select('action'))->items([
(new Select('action'))->items([ __('Backup languages') => 'module_create_backups',
__('Backup languages') => 'module_create_backups', __('Delete languages') => 'module_delete_codes',
__('Delete languages') => 'module_delete_codes', __('Export languages') => 'module_export_pack',
__('Export languages') => 'module_export_pack', ]),
]), (new Submit('do-action'))->value(__('ok')),
(new Submit('do-action'))->value(__('ok')), ... My::hiddenFields([
dcCore::app()->formNonce(false), 'type' => $current->module->type,
], 'module' => $current->module->id,
is_null(dcCore::app()->adminurl) ? [] : dcCore::app()->adminurl->hiddenFormFields( ]),
My::id(), ])->render() .
['type' => $current->module->type, 'module' => $current->module->id]
)
))->render() .
'</div></form><p>&nbsp;</p></div>'; '</div></form><p>&nbsp;</p></div>';
} }
@ -344,7 +341,7 @@ class Manage extends dcNsProcess
// delete / retore backups // delete / retore backups
if (!empty($backups)) { if (!empty($backups)) {
echo '<div class="fieldset"><h3>' . __('Backups') . '</h3>' . 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">' . '<table class="clear">' .
'<caption>' . __('Existing languages backups') . '</caption>' . '<caption>' . __('Existing languages backups') . '</caption>' .
'<tr>' . '<tr>' .
@ -390,21 +387,18 @@ class Manage extends dcNsProcess
<div class="two-cols"> <div class="two-cols">
<p class="col checkboxes-helpers"></p>' . <p class="col checkboxes-helpers"></p>' .
(new Para())->class('col right')->items(array_merge( (new Para())->class('col right')->items([
[ (new Text('', __('Selected backups action:'))),
(new Text('', __('Selected backups action:'))), (new Select('action'))->items([
(new Select('action'))->items([ __('Restore backups') => 'module_restore_backup',
__('Restore backups') => 'module_restore_backup', __('Delete backups') => 'module_delete_backup',
__('Delete backups') => 'module_delete_backup', ]),
]), (new Submit('do-action'))->value(__('ok')),
(new Submit('do-action'))->value(__('ok')), ... My::hiddenFields([
dcCore::app()->formNonce(false), 'type' => $current->module->type,
], 'module' => $current->module->id,
is_null(dcCore::app()->adminurl) ? [] : dcCore::app()->adminurl->hiddenFormFields( ]),
My::id(), ])->render() .
['type' => $current->module->type, 'module' => $current->module->id]
)
))->render() .
'</div></form><p>&nbsp;</p></div>'; '</div></form><p>&nbsp;</p></div>';
} }
} }
@ -414,7 +408,7 @@ class Manage extends dcNsProcess
// add language // add language
if (!empty($unused_codes)) { if (!empty($unused_codes)) {
echo '<div class="col fieldset"><h3>' . __('Add language') . '</h3> 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 Para())->class('field')->items([
(new Label(__('Select language:')))->for('code'), (new Label(__('Select language:')))->for('code'),
(new Select(['code']))->default((string) dcCore::app()->auth?->getInfo('user_lang'))->items(array_merge(['-' => '-'], $unused_codes)), (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(); ])->render();
} }
echo echo
(new Para())->items(array_merge( (new Para())->items([
[ (new Submit(['save']))->value(__('Create')),
(new Submit(['save']))->value(__('Create')), ... My::hiddenFields([
dcCore::app()->formNonce(false), 'type' => $current->module->type,
], 'module' => $current->module->id,
is_null(dcCore::app()->adminurl) ? [] : dcCore::app()->adminurl->hiddenFormFields( 'action' => 'module_add_code',
My::id(), ]),
['type' => $current->module->type, 'module' => $current->module->id, 'action' => 'module_add_code'] ])->render() .
)
))->render() .
'</form><p>&nbsp;</p></div>'; '</form><p>&nbsp;</p></div>';
} }
// Import // Import
echo '<div class="col fieldset"><h3>' . __('Import') . '</h3>' . 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 Para())->items([
(new Label(__('Select languages package to import:')))->for('packfile'), (new Label(__('Select languages package to import:')))->for('packfile'),
(new File('packfile')), (new File('packfile')),
]), ]),
(new Para())->items(array_merge( (new Para())->items([
[ (new Submit(['save']))->value(__('Import')),
(new Submit(['save']))->value(__('Import')), ... My::hiddenFields([
dcCore::app()->formNonce(false), 'type' => $current->module->type,
], 'module' => $current->module->id,
is_null(dcCore::app()->adminurl) ? [] : dcCore::app()->adminurl->hiddenFormFields( 'action' => 'module_import_pack',
My::id(), ]),
['type' => $current->module->type, 'module' => $current->module->id, 'action' => 'module_import_pack'] ]),
)
)),
])->render() . ])->render() .
'<p>&nbsp;</p></div>'; '<p>&nbsp;</p></div>';
echo '</div>'; echo '</div>';
dcPage::helpBlock('translater.module'); Page::helpBlock('translater.module');
} elseif (!empty($current->lang)) { } elseif (!empty($current->lang)) {
$lines = $current->lang->getMessages(); $lines = $current->lang->getMessages();
$allowed_l10n_groups = []; $allowed_l10n_groups = [];
echo echo
'<div id="lang-form">' . '<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">' . '<table class="table-outer">' .
'<caption>' . sprintf(__('List of %s localized strings'), count($lines)) . '</caption>' . '<caption>' . sprintf(__('List of %s localized strings'), count($lines)) . '</caption>' .
'<tr>' . '<tr>' .
@ -597,23 +587,22 @@ class Manage extends dcNsProcess
(new Select('multigroup'))->items(My::l10nGroupsCombo()), (new Select('multigroup'))->items(My::l10nGroupsCombo()),
])->render() . ])->render() .
'</div>' . '</div>' .
(new Para())->class('col right')->items(array_merge( (new Para())->class('col right')->items([
[ (new Submit('do-action'))->value(__('Save') . ' (s)')->accesskey('s'),
(new Submit('do-action'))->value(__('Save') . ' (s)')->accesskey('s'), ... My::hiddenFields([
dcCore::app()->formNonce(false), 'type' => $current->module->type,
(new Hidden(['code'], $current->lang->code)), 'module' => $current->module->id,
], 'action' => 'module_update_code',
is_null(dcCore::app()->adminurl) ? [] : dcCore::app()->adminurl->hiddenFormFields( 'lang' => $current->lang->code,
My::id(), 'code' => $current->lang->code, //?
['type' => $current->module?->type, 'module' => $current->module?->id, 'lang' => $current->lang->code, 'action' => 'module_update_code'] ]),
) ])->render() .
))->render() .
'</div>' . '</div>' .
'</form>' . '</form>' .
'<p>&nbsp;</p>' . '<p>&nbsp;</p>' .
'</div>'; '</div>';
dcPage::helpBlock('translater.lang'); Page::helpBlock('translater.lang');
} else { } else {
$line = '<li><a href="%s"%s>%s</a></li>'; $line = '<li><a href="%s"%s>%s</a></li>';
echo '<h4><i>' . __('Translate your Dotclear plugins and themes') . '</i></h4>' . 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>', '<h3><ul class="nice">%s</ul></h3>',
sprintf( sprintf(
$line, $line,
dcCore::app()->adminurl?->get(My::id(), ['type' => 'plugin']), My::manageUrl(['type' => 'plugin']),
$current->type == 'plugin' ? ' class="active"' : '', $current->type == 'plugin' ? ' class="active"' : '',
__('Translate plugins') __('Translate plugins')
) . ) .
sprintf( sprintf(
$line, $line,
dcCore::app()->adminurl?->get(My::id(), ['type' => 'theme']), My::manageUrl(['type' => 'theme']),
$current->type == 'theme' ? ' class="active"' : '', $current->type == 'theme' ? ' class="active"' : '',
__('Translate themes') __('Translate themes')
) )
); );
dcPage::helpBlock('translater.index'); Page::helpBlock('translater.index');
} }
dcPage::closeModule(); Page::closeModule();
} }
private static function redirect(string $msg, ?string $lang = null): void private static function redirect(string $msg, ?string $lang = null): void
@ -651,7 +640,7 @@ class Manage extends dcNsProcess
$redir['lang'] = $lang; $redir['lang'] = $lang;
} }
dcPage::addSuccessNotice($msg); Notices::addSuccessNotice($msg);
dcCore::app()->adminurl?->redirect(My::id(), $redir); My::manageUrl($redir);
} }
} }

View file

@ -15,41 +15,20 @@ declare(strict_types=1);
namespace Dotclear\Plugin\translater; namespace Dotclear\Plugin\translater;
use dcCore; use dcCore;
use Dotclear\Module\MyPlugin;
/** /**
* Plugin definitions * Plugin definitions
*/ */
class My class My extends MyPlugin
{ {
/** @var string Locales folder name */ /** @var string Locales folder name */
public const LOCALES_FOLDER = 'locales'; public const LOCALES_FOLDER = 'locales';
/** public static function checkCustomContext(int $context): ?bool
* This module id.
*/
public static function id(): string
{ {
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 * List of allowed backup folder
*/ */

View file

@ -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;
}
}

View file

@ -14,8 +14,6 @@ declare(strict_types=1);
namespace Dotclear\Plugin\translater; namespace Dotclear\Plugin\translater;
use dcCore;
class Settings class Settings
{ {
// Show tranlsater button on plugins list // Show tranlsater button on plugins list
@ -68,7 +66,7 @@ class Settings
*/ */
public function __construct() public function __construct()
{ {
$s = dcCore::app()->blog?->settings->get(My::id()); $s = My::settings();
$this->plugin_menu = (bool) ($s?->get('plugin_menu') ?? false); $this->plugin_menu = (bool) ($s?->get('plugin_menu') ?? false);
$this->theme_menu = (bool) ($s?->get('theme_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 public function writeSetting(string $key, mixed $value): bool
{ {
if (property_exists($this, $key) && settype($value, gettype($this->{$key})) === true) { if (property_exists($this, $key) && settype($value, gettype($this->{$key})) === true) {
dcCore::app()->blog?->settings->get(My::id())->drop($key); My::settings()->drop($key);
dcCore::app()->blog?->settings->get(My::id())->put($key, $value, gettype($this->{$key}), '', true, true); My::settings()->put($key, $value, gettype($this->{$key}), '', true, true);
return true; return true;
} }

View file

@ -119,7 +119,7 @@ class TranslaterModule
break; break;
case 'translater': case 'translater':
$tmp = Path::real(dcCore::app()->plugins->moduleRoot(My::id())); $tmp = Path::real(My::path());
if ($tmp !== false && is_writable($tmp)) { if ($tmp !== false && is_writable($tmp)) {
@mkDir($tmp . DIRECTORY_SEPARATOR . My::LOCALES_FOLDER); @mkDir($tmp . DIRECTORY_SEPARATOR . My::LOCALES_FOLDER);
$dir = $tmp . DIRECTORY_SEPARATOR . My::LOCALES_FOLDER; $dir = $tmp . DIRECTORY_SEPARATOR . My::LOCALES_FOLDER;

View file

@ -15,21 +15,19 @@ declare(strict_types=1);
namespace Dotclear\Plugin\translater; namespace Dotclear\Plugin\translater;
use dcCore; use dcCore;
use dcNsProcess; use Dotclear\Core\Process;
use Dotclear\Plugin\Uninstaller\Uninstaller; use Dotclear\Plugin\Uninstaller\Uninstaller;
class Uninstall extends dcNsProcess class Uninstall extends Process
{ {
public static function init(): bool public static function init(): bool
{ {
static::$init = defined('DC_CONTEXT_ADMIN'); return self::status(My::checkContext(My::UNINSTALL));
return static::$init;
} }
public static function process(): bool public static function process(): bool
{ {
if (!static::$init || !dcCore::app()->plugins->moduleExists('Uninstaller')) { if (!self::status() || !dcCore::app()->plugins->moduleExists('Uninstaller')) {
return false; return false;
} }