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
|
|
|
|
*/
|
2023-03-14 23:26:31 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace Dotclear\Plugin\translater;
|
|
|
|
|
|
|
|
use dcCore;
|
|
|
|
use dcNsProcess;
|
|
|
|
use dcPage;
|
2023-04-07 21:32:00 +00:00
|
|
|
use Dotclear\Helper\File\Files;
|
|
|
|
use Dotclear\Helper\Html\Form\{
|
|
|
|
Checkbox,
|
|
|
|
File,
|
|
|
|
Form,
|
|
|
|
Hidden,
|
|
|
|
Input,
|
|
|
|
Label,
|
|
|
|
Note,
|
|
|
|
Para,
|
|
|
|
Select,
|
|
|
|
Submit,
|
|
|
|
Text
|
|
|
|
};
|
|
|
|
use Dotclear\Helper\Html\Html;
|
|
|
|
use Exception;
|
2023-03-14 23:26:31 +00:00
|
|
|
use dt;
|
|
|
|
|
|
|
|
class Manage extends dcNsProcess
|
|
|
|
{
|
|
|
|
public static function init(): bool
|
|
|
|
{
|
2023-03-19 23:20:41 +00:00
|
|
|
static::$init = defined('DC_CONTEXT_ADMIN')
|
|
|
|
&& dcCore::app()->auth?->isSuperAdmin()
|
|
|
|
&& My::phpCompliant();
|
2021-08-18 19:42:30 +00:00
|
|
|
|
2023-03-19 23:20:41 +00:00
|
|
|
return static::$init;
|
2021-09-24 23:58:59 +00:00
|
|
|
}
|
2021-08-18 19:42:30 +00:00
|
|
|
|
2023-03-14 23:26:31 +00:00
|
|
|
public static function process(): bool
|
|
|
|
{
|
2023-03-19 23:20:41 +00:00
|
|
|
if (!static::$init) {
|
2023-03-14 23:26:31 +00:00
|
|
|
return false;
|
|
|
|
}
|
2021-08-18 22:48:47 +00:00
|
|
|
|
2023-03-17 23:18:41 +00:00
|
|
|
$current = ManageVars::init();
|
2021-08-18 22:48:47 +00:00
|
|
|
|
2023-03-14 23:26:31 +00:00
|
|
|
// execute action
|
|
|
|
try {
|
2023-03-16 21:59:33 +00:00
|
|
|
if ($current->action == 'module_create_backups') {
|
|
|
|
if (empty($current->module) || empty($_POST['codes'])) {
|
2023-03-14 23:26:31 +00:00
|
|
|
throw new Exception(__('Nothing to backup'));
|
|
|
|
}
|
2023-03-16 21:59:33 +00:00
|
|
|
foreach ($current->module->getUsedlangs() as $code_id) {
|
2023-03-14 23:26:31 +00:00
|
|
|
if (in_array($code_id, $_POST['codes'])) {
|
2023-03-16 21:59:33 +00:00
|
|
|
$current->module->createBackup($code_id);
|
2023-03-14 23:26:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
self::redirect(__('Backup successfully created'));
|
2021-08-18 22:48:47 +00:00
|
|
|
}
|
|
|
|
|
2023-03-16 21:59:33 +00:00
|
|
|
if ($current->action == 'module_restore_backup') {
|
|
|
|
if (empty($current->module) || empty($_POST['files'])) {
|
2023-03-14 23:26:31 +00:00
|
|
|
throw new Exception(__('Nothing to restore'));
|
|
|
|
}
|
2023-03-16 21:59:33 +00:00
|
|
|
foreach ($current->module->getBackups(true) as $backup_file) {
|
2023-03-14 23:26:31 +00:00
|
|
|
if (in_array($backup_file, $_POST['files'])) {
|
2023-03-16 21:59:33 +00:00
|
|
|
$current->module->restoreBackup($backup_file);
|
2023-03-14 23:26:31 +00:00
|
|
|
}
|
|
|
|
}
|
2021-08-18 22:48:47 +00:00
|
|
|
|
2023-03-14 23:26:31 +00:00
|
|
|
self::redirect(__('Backup successfully restored'));
|
|
|
|
}
|
2021-08-18 22:48:47 +00:00
|
|
|
|
2023-03-16 21:59:33 +00:00
|
|
|
if ($current->action == 'module_delete_backup') {
|
|
|
|
if (empty($current->module) || empty($_POST['files'])) {
|
2023-03-14 23:26:31 +00:00
|
|
|
throw new Exception(__('Nothing to delete'));
|
|
|
|
}
|
2023-03-16 21:59:33 +00:00
|
|
|
foreach ($current->module->getBackups(true) as $backup_file) {
|
2023-03-14 23:26:31 +00:00
|
|
|
if (in_array($backup_file, $_POST['files'])) {
|
2023-03-16 21:59:33 +00:00
|
|
|
$current->module->deleteBackup($backup_file);
|
2023-03-14 23:26:31 +00:00
|
|
|
}
|
|
|
|
}
|
2021-08-18 22:48:47 +00:00
|
|
|
|
2023-03-14 23:26:31 +00:00
|
|
|
self::redirect(__('Backup successfully deleted'));
|
|
|
|
}
|
2021-08-18 22:48:47 +00:00
|
|
|
|
2023-03-16 21:59:33 +00:00
|
|
|
if ($current->action == 'module_export_pack') {
|
|
|
|
if (empty($current->module) || empty($_POST['codes'])) {
|
2023-03-14 23:26:31 +00:00
|
|
|
throw new Exception(__('Nothing to export'));
|
|
|
|
}
|
2023-03-16 21:59:33 +00:00
|
|
|
$current->module->exportPack($_POST['codes']);
|
2021-08-18 22:48:47 +00:00
|
|
|
|
2023-03-14 23:26:31 +00:00
|
|
|
self::redirect(__('Language successfully exported'));
|
|
|
|
}
|
2021-08-18 22:48:47 +00:00
|
|
|
|
2023-03-16 21:59:33 +00:00
|
|
|
if ($current->action == 'module_import_pack') {
|
2023-03-19 23:21:13 +00:00
|
|
|
if (empty($current->module) || empty($_FILES['packfile']['name'])) {
|
2023-03-14 23:26:31 +00:00
|
|
|
throw new Exception(__('Nothing to import'));
|
|
|
|
}
|
2023-03-16 21:59:33 +00:00
|
|
|
$current->module->importPack($_FILES['packfile']);
|
2023-03-14 23:26:31 +00:00
|
|
|
|
|
|
|
self::redirect(__('Language successfully imported'));
|
2021-09-25 09:45:08 +00:00
|
|
|
}
|
2021-08-18 22:48:47 +00:00
|
|
|
|
2023-03-16 21:59:33 +00:00
|
|
|
if ($current->action == 'module_add_code') {
|
|
|
|
if (empty($current->module) || empty($_POST['code'])) {
|
2023-03-14 23:26:31 +00:00
|
|
|
throw new Exception(__('Nothing to create'));
|
|
|
|
}
|
2023-03-16 21:59:33 +00:00
|
|
|
$current->module->addLang($_POST['code'], $_POST['from'] ?? '');
|
2023-03-14 23:26:31 +00:00
|
|
|
|
|
|
|
self::redirect(__('Language successfully added'), $_POST['code']);
|
|
|
|
}
|
|
|
|
|
2023-03-16 21:59:33 +00:00
|
|
|
if ($current->action == 'module_delete_codes') {
|
|
|
|
if (empty($current->module) || empty($_POST['codes'])) {
|
2023-03-14 23:26:31 +00:00
|
|
|
throw new Exception(__('Nothing to delete'));
|
|
|
|
}
|
2023-03-16 21:59:33 +00:00
|
|
|
foreach ($current->module->getUsedlangs() as $code_id) {
|
2023-03-14 23:26:31 +00:00
|
|
|
if (in_array($code_id, $_POST['codes'])) {
|
2023-03-16 21:59:33 +00:00
|
|
|
$current->module->delLang($code_id);
|
2023-03-14 23:26:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
self::redirect(__('Language successfully deleted'), $_POST['code']);
|
|
|
|
}
|
|
|
|
|
2023-03-16 21:59:33 +00:00
|
|
|
if ($current->action == 'module_update_code') {
|
|
|
|
if (empty($current->module) || empty($_POST['code']) || empty($_POST['entries'])) {
|
2023-03-14 23:26:31 +00:00
|
|
|
throw new Exception(__('Nothing to update'));
|
2021-08-18 22:48:47 +00:00
|
|
|
}
|
2023-03-14 23:26:31 +00:00
|
|
|
if (!empty($_POST['update_group'])) {
|
|
|
|
foreach ($_POST['entries'] as $i => $entry) {
|
|
|
|
if (isset($entry['check']) && isset($_POST['multigroup'])) {
|
|
|
|
$_POST['entries'][$i]['group'] = $_POST['multigroup'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-03-16 21:59:33 +00:00
|
|
|
$current->module->updLang($_POST['code'], $_POST['entries']);
|
2023-03-14 23:26:31 +00:00
|
|
|
|
|
|
|
self::redirect(__('Language successfully updated'), $_POST['code']);
|
2021-08-18 22:48:47 +00:00
|
|
|
}
|
2023-03-14 23:26:31 +00:00
|
|
|
} catch (Exception $e) {
|
|
|
|
dcCore::app()->error->add($e->getMessage());
|
2021-08-18 22:48:47 +00:00
|
|
|
}
|
|
|
|
|
2023-03-14 23:26:31 +00:00
|
|
|
return true;
|
2021-09-24 23:58:59 +00:00
|
|
|
}
|
2021-08-18 19:42:30 +00:00
|
|
|
|
2023-03-14 23:26:31 +00:00
|
|
|
public static function render(): void
|
|
|
|
{
|
2023-03-19 23:21:13 +00:00
|
|
|
if (!static::$init) {
|
2023-03-14 23:26:31 +00:00
|
|
|
return;
|
2021-08-18 22:48:47 +00:00
|
|
|
}
|
2023-03-14 23:26:31 +00:00
|
|
|
|
2023-03-17 23:18:41 +00:00
|
|
|
$current = ManageVars::init();
|
2023-03-16 21:59:33 +00:00
|
|
|
|
2023-03-19 23:21:13 +00:00
|
|
|
$breadcrumb = [My::name() => dcCore::app()->adminurl?->get(My::id(), ['type' => '-'])];
|
2023-03-16 21:59:33 +00:00
|
|
|
if (empty($current->type)) {
|
2023-03-14 23:26:31 +00:00
|
|
|
$breadcrumb = [My::name() => ''];
|
2023-03-16 21:59:33 +00:00
|
|
|
} elseif (empty($current->module)) {
|
|
|
|
$breadcrumb[$current->type == 'plugin' ? __('Plugins') : __('Themes')] = '';
|
|
|
|
} elseif (empty($current->lang)) {
|
2023-03-19 23:21:13 +00:00
|
|
|
$breadcrumb[$current->type == 'plugin' ? __('Plugins') : __('Themes')] = dcCore::app()->adminurl?->get(My::id(), ['type' => $current->type]);
|
2023-04-07 21:32:00 +00:00
|
|
|
$breadcrumb[Html::escapeHTML($current->module->name)] = '';
|
2023-03-16 21:59:33 +00:00
|
|
|
} elseif (!empty($current->lang)) {
|
2023-03-19 23:21:13 +00:00
|
|
|
$breadcrumb[$current->type == 'plugin' ? __('Plugins') : __('Themes')] = dcCore::app()->adminurl?->get(My::id(), ['type' => $current->type]);
|
2023-04-07 21:32:00 +00:00
|
|
|
$breadcrumb[Html::escapeHTML($current->module->name)] = dcCore::app()->adminurl?->get(My::id(), ['type' => $current->type, 'module' => $current->module->id]);
|
|
|
|
$breadcrumb[Html::escapeHTML(sprintf(__('%s language edition'), $current->lang->name))] = '';
|
2021-08-18 22:48:47 +00:00
|
|
|
}
|
2023-03-14 23:26:31 +00:00
|
|
|
|
|
|
|
dcPage::openModule(
|
|
|
|
My::name(),
|
|
|
|
dcPage::jsPageTabs() .
|
|
|
|
dcPage::cssModuleLoad(My::id() . '/css/backend.css') .
|
|
|
|
dcPage::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'),
|
|
|
|
]) .
|
|
|
|
dcPage::jsModuleLoad(My::id() . '/js/backend.js') .
|
|
|
|
|
|
|
|
# --BEHAVIOR-- translaterAdminHeaders
|
|
|
|
dcCore::app()->callBehavior('translaterAdminHeaders')
|
2021-09-24 23:58:59 +00:00
|
|
|
);
|
2023-03-14 23:26:31 +00:00
|
|
|
|
2021-11-01 21:32:32 +00:00
|
|
|
echo
|
2023-03-14 23:26:31 +00:00
|
|
|
dcPage::breadcrumb($breadcrumb) .
|
|
|
|
dcPage::notices();
|
|
|
|
|
2023-03-16 21:59:33 +00:00
|
|
|
if (empty($current->module) && $current->type != '') {
|
2023-03-14 23:26:31 +00:00
|
|
|
// modules list
|
2023-03-19 23:21:13 +00:00
|
|
|
echo '<form id="theme-form" method="post" action="' . dcCore::app()->adminurl?->get(My::id(), ['type' => 'plugin']) . '">';
|
2023-03-14 23:26:31 +00:00
|
|
|
|
|
|
|
$res = '';
|
2023-03-16 21:59:33 +00:00
|
|
|
$modules = $current->translater->getModules($current->type);
|
2023-03-14 23:26:31 +00:00
|
|
|
ksort($modules);
|
|
|
|
foreach ($modules as $module) {
|
2023-03-16 21:59:33 +00:00
|
|
|
if ($current->translater->hide_default && in_array($module->id, My::defaultDistribModules($current->type))) {
|
2023-03-14 23:26:31 +00:00
|
|
|
continue;
|
2021-08-18 22:48:47 +00:00
|
|
|
}
|
2023-03-14 23:26:31 +00:00
|
|
|
if ($module->root_writable) {
|
|
|
|
$res .= sprintf(
|
|
|
|
'<tr class="line"><td class="nowrap minimal"><a href="%s" title="%s">%s</a></td>',
|
2023-03-19 23:21:13 +00:00
|
|
|
dcCore::app()->adminurl?->get(My::id(), ['type' => $module->type, 'module' => $module->id]),
|
2023-04-07 21:32:00 +00:00
|
|
|
Html::escapeHTML(sprintf(__('Translate module %s'), __($module->name))),
|
|
|
|
Html::escapeHTML($module->id)
|
2023-03-14 23:26:31 +00:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
$res .= sprintf(
|
|
|
|
'<tr class="line offline"><td class="nowrap">%s</td>',
|
2023-04-07 21:32:00 +00:00
|
|
|
Html::escapeHTML($module->id)
|
2023-03-14 23:26:31 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
$codes = $module->getLangs();
|
|
|
|
foreach ($codes as $code_id => $code_name) {
|
|
|
|
if ($module->root_writable) {
|
|
|
|
$codes[$code_id] = sprintf(
|
|
|
|
'<a class="wait maximal nowrap" title="%s" href="%s">%s (%s)</a>',
|
2023-04-07 21:32:00 +00:00
|
|
|
Html::escapeHTML(sprintf(__('Edit language %s of module %s'), Html::escapeHTML($code_name), __($module->name))),
|
2023-03-19 23:21:13 +00:00
|
|
|
dcCore::app()->adminurl?->get(My::id(), ['type' => $module->type, 'module' => $module->id, 'lang' => $code_id]),
|
2023-04-07 21:32:00 +00:00
|
|
|
Html::escapeHTML($code_name),
|
2023-03-14 23:26:31 +00:00
|
|
|
$code_id
|
|
|
|
);
|
|
|
|
} else {
|
2023-04-07 21:32:00 +00:00
|
|
|
$codes[$code_id] = Html::escapeHTML($code_name) . '(' . $code_id . ')';
|
2023-03-14 23:26:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
$res .= sprintf(
|
|
|
|
'<td class="nowrap maximal">%s</td><td class="nowrap minimal">%s</td><td class="nowrap minimal count">%s</td></tr>',
|
|
|
|
implode(', ', $codes),
|
2023-04-07 21:32:00 +00:00
|
|
|
Html::escapeHTML(__($module->name)),
|
2023-03-14 23:26:31 +00:00
|
|
|
$module->version
|
|
|
|
);
|
|
|
|
}
|
|
|
|
if ($res) {
|
|
|
|
echo '
|
|
|
|
<div class="table-outer">
|
|
|
|
<table class="clear">
|
2023-03-16 21:59:33 +00:00
|
|
|
<caption>' . sprintf(__('Modules list of type "%s"'), $current->type) . '</caption>
|
2023-03-14 23:26:31 +00:00
|
|
|
<tr>
|
|
|
|
<th class="nowrap">' . __('Id') . '</th>
|
|
|
|
<th class="nowrap">' . __('Languages') . '</th>
|
|
|
|
<th class="nowrap">' . __('Name') . '</th>
|
|
|
|
<th class="nowrap">' . __('Version') . '</th>
|
|
|
|
</tr>' .
|
|
|
|
$res .
|
|
|
|
'</table></div>';
|
2021-08-18 22:48:47 +00:00
|
|
|
} else {
|
2023-03-14 23:26:31 +00:00
|
|
|
echo '<tr><td colspan="6">' . __('There is no editable modules') . '</td></tr>';
|
2021-08-18 22:48:47 +00:00
|
|
|
}
|
2023-03-14 23:26:31 +00:00
|
|
|
echo '</form>';
|
|
|
|
|
|
|
|
dcPage::helpBlock('translater.type');
|
2023-03-16 21:59:33 +00:00
|
|
|
} elseif (!empty($current->module) && empty($current->lang)) {
|
|
|
|
$codes = $current->module->getUsedLangs();
|
|
|
|
$backups = $current->module->getBackups();
|
|
|
|
$unused_codes = $current->module->getUnusedLangs();
|
2023-03-14 23:26:31 +00:00
|
|
|
|
|
|
|
// module summary
|
2023-03-16 21:59:33 +00:00
|
|
|
echo '<h3>' . sprintf(__('Module %s %s by %s'), $current->module->name, $current->module->version, $current->module->author) . '</h3>
|
2023-03-14 23:26:31 +00:00
|
|
|
<ul class="nice col">
|
2023-03-16 21:59:33 +00:00
|
|
|
<li><strong>' . __('Root') . '</strong> ' . $current->module->root . '</li>
|
|
|
|
<li><strong>' . __('Locales') . '</strong> ' . $current->module->locales . '</li>
|
|
|
|
<li><strong>' . __('Backups') . '</strong> ' . $current->module->getBackupRoot() . '</li>
|
2023-03-14 23:26:31 +00:00
|
|
|
</ul>
|
|
|
|
<p> </p>';
|
|
|
|
|
|
|
|
// existing languages
|
|
|
|
if (count($codes)) {
|
|
|
|
echo
|
|
|
|
'<div class="clear fieldset"><h3>' . __('Translations') . '</h3>' .
|
2023-03-19 23:21:13 +00:00
|
|
|
'<form id="module-translations-form" method="post" action="' . dcCore::app()->adminurl?->get(My::id()) . '">' .
|
2023-03-14 23:26:31 +00:00
|
|
|
'<table class="clear maximal">' .
|
|
|
|
'<caption>' . __('Existing languages translations') . '</caption>' .
|
|
|
|
'<tr>' .
|
|
|
|
'<th class="nowrap" colspan="2">' . __('Language') . '</th>' .
|
|
|
|
'<th class="nowrap">' . __('Code') . '</th>' .
|
|
|
|
'<th class="nowrap">' . __('Backups') . '</th>' .
|
|
|
|
'<th class="nowrap">' . __('Last backup') . '</th>' .
|
|
|
|
'</tr>';
|
2021-08-18 22:48:47 +00:00
|
|
|
|
2023-03-14 23:26:31 +00:00
|
|
|
foreach ($codes as $code_name => $code_id) {
|
|
|
|
echo
|
|
|
|
'<tr class="line">' .
|
2023-04-07 21:32:00 +00:00
|
|
|
'<td class="minimal">' . (new Checkbox(['codes[]', 'existing_code_' . $code_id]))->value($code_id)->render() . '</td>' .
|
2023-03-14 23:26:31 +00:00
|
|
|
'<td class="nowrap">' .
|
|
|
|
'<a href="' .
|
2023-03-19 23:21:13 +00:00
|
|
|
dcCore::app()->adminurl?->get(My::id(), ['type' => $current->module->type, 'module' => $current->module->id, 'lang' => $code_id])
|
2023-04-07 21:32:00 +00:00
|
|
|
. '" title="' . sprintf(__('Edit %s language'), Html::escapeHTML($code_name)) . '">' . $code_name . '</a>' .
|
2023-03-14 23:26:31 +00:00
|
|
|
'</td>' .
|
|
|
|
'<td class="nowrap maximal"> ' . $code_id . '</td>';
|
|
|
|
|
|
|
|
if (isset($backups[$code_id])) {
|
|
|
|
$time[$code_id] = 0;
|
|
|
|
foreach ($backups[$code_id] as $file => $info) {
|
|
|
|
$time[$code_id] = isset($time[$code_id]) && $time[$code_id] > $info['time'] ?
|
|
|
|
$time[$code_id] : $info['time'];
|
|
|
|
}
|
|
|
|
echo
|
|
|
|
'<td class="nowrap">' . count($backups[$code_id]) . '</td>' .
|
|
|
|
'<td class="nowrap"> ' .
|
2023-03-19 23:21:13 +00:00
|
|
|
dt::str('%Y-%m-%d %H:%M', (int) $time[$code_id], (string) dcCore::app()->blog?->settings->get('system')->get('blog_timezone')) .
|
2023-03-14 23:26:31 +00:00
|
|
|
'</td>';
|
|
|
|
} else {
|
|
|
|
echo '<td class="nowrap">' . __('no backups') . '</td><td class="maximal nowrap">-</td>';
|
|
|
|
}
|
|
|
|
echo '</tr>';
|
|
|
|
}
|
|
|
|
echo '</table>
|
|
|
|
<div class="two-cols">
|
2023-04-07 21:32:00 +00:00
|
|
|
<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),
|
|
|
|
], dcCore::app()->adminurl?->hiddenFormFields(
|
|
|
|
My::id(),
|
|
|
|
['type' => $current->module->type, 'module' => $current->module->id]
|
|
|
|
)
|
|
|
|
))->render() .
|
|
|
|
'</div></form><p> </p></div>';
|
2023-03-14 23:26:31 +00:00
|
|
|
}
|
2021-09-25 09:45:08 +00:00
|
|
|
|
2023-03-14 23:26:31 +00:00
|
|
|
// backups
|
|
|
|
if (!empty($codes) || !empty($backups)) {
|
|
|
|
// delete / retore backups
|
|
|
|
if (!empty($backups)) {
|
|
|
|
echo '<div class="fieldset"><h3>' . __('Backups') . '</h3>' .
|
2023-03-19 23:21:13 +00:00
|
|
|
'<form id="module-backups-form" method="post" action="' . dcCore::app()->adminurl?->get(My::id()) . '">' .
|
2023-03-14 23:26:31 +00:00
|
|
|
'<table class="clear">' .
|
|
|
|
'<caption>' . __('Existing languages backups') . '</caption>' .
|
|
|
|
'<tr>' .
|
|
|
|
'<th class="nowrap" colspan="2">' . __('Language') . '</th>' .
|
|
|
|
'<th class="nowrap">' . __('Code') . '</th>' .
|
|
|
|
'<th class="nowrap">' . __('Date') . '</th>' .
|
|
|
|
'<th class="nowrap">' . __('File') . '</th>' .
|
|
|
|
'<th class="nowrap">' . __('Size') . '</th>' .
|
|
|
|
'</tr>';
|
|
|
|
|
|
|
|
$table_line = '<tr class="line">' .
|
|
|
|
'<td class="minimal">%s</td>' .
|
|
|
|
'<td class="nowrap"><label for="%s">%s</label></td>' .
|
|
|
|
'<td class="nowrap maximal">%s</td>' .
|
|
|
|
'<td class="nowrap count">%s</td>' .
|
|
|
|
'<td class="nowrap">%s</td>' .
|
|
|
|
'<td class="nowrap count">%s</td>' .
|
|
|
|
'</tr>';
|
|
|
|
|
|
|
|
$i = 0;
|
|
|
|
foreach ($backups as $backup_codes) {
|
|
|
|
foreach ($backup_codes as $backup_file => $backup_code) {
|
|
|
|
$i++;
|
|
|
|
$form_id = 'form_file_' . $backup_code['code'] . $backup_code['time'];
|
|
|
|
echo sprintf(
|
|
|
|
$table_line,
|
2023-04-07 21:32:00 +00:00
|
|
|
(new Checkbox(['files[]', $form_id]))->value($backup_file)->render(),
|
2023-03-14 23:26:31 +00:00
|
|
|
$form_id,
|
|
|
|
$backup_code['name'],
|
|
|
|
$backup_code['code'],
|
|
|
|
dt::str(
|
2023-03-19 23:21:13 +00:00
|
|
|
dcCore::app()->blog?->settings->get('system')->get('date_format') . ' ' . dcCore::app()->blog?->settings->get('system')->get('time_format'),
|
2023-03-14 23:26:31 +00:00
|
|
|
(int) $backup_code['time'],
|
2023-03-19 23:21:13 +00:00
|
|
|
dcCore::app()->blog?->settings->get('system')->get('blog_timezone')
|
2023-03-14 23:26:31 +00:00
|
|
|
),
|
|
|
|
$backup_code['path']['basename'],
|
2023-04-07 21:32:00 +00:00
|
|
|
Files::size($backup_code['size'])
|
2023-03-14 23:26:31 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
echo '
|
|
|
|
</table>
|
|
|
|
<div class="two-cols">
|
2023-04-07 21:32:00 +00:00
|
|
|
<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),
|
|
|
|
], dcCore::app()->adminurl?->hiddenFormFields(
|
|
|
|
My::id(),
|
|
|
|
['type' => $current->module->type, 'module' => $current->module->id]
|
|
|
|
)
|
|
|
|
))->render() .
|
|
|
|
'</div></form><p> </p></div>';
|
2023-03-14 23:26:31 +00:00
|
|
|
}
|
|
|
|
}
|
2021-09-25 09:45:08 +00:00
|
|
|
|
2023-03-14 23:26:31 +00:00
|
|
|
echo '<div class="two-cols">';
|
|
|
|
|
|
|
|
// add language
|
|
|
|
if (!empty($unused_codes)) {
|
|
|
|
echo '<div class="col fieldset"><h3>' . __('Add language') . '</h3>
|
2023-04-07 21:32:00 +00:00
|
|
|
<form id="muodule-code-create-form" method="post" action="' . dcCore::app()->adminurl?->get(My::id()) . '">' .
|
|
|
|
(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)),
|
|
|
|
])->render();
|
|
|
|
|
2023-03-14 23:26:31 +00:00
|
|
|
if (empty($codes)) {
|
2023-04-07 21:32:00 +00:00
|
|
|
echo (new Para())->items([(new Hidden(['from'], ''))])->render();
|
2023-03-14 23:26:31 +00:00
|
|
|
} else {
|
|
|
|
echo
|
2023-04-07 21:32:00 +00:00
|
|
|
(new Para())->class('field')->items([
|
|
|
|
(new Label(__('Copy from language:')))->for('from'),
|
|
|
|
(new Select(['from']))->items(array_merge(['-' => ''], $codes)),
|
|
|
|
(new Note())->class('form-note')->text(__('optionnal')),
|
|
|
|
])->render();
|
2021-09-24 23:58:59 +00:00
|
|
|
}
|
2023-04-07 21:32:00 +00:00
|
|
|
echo
|
|
|
|
(new Para())->items(array_merge([
|
|
|
|
(new Submit(['save']))->value(__('Create')),
|
|
|
|
dcCore::app()->formNonce(false),
|
|
|
|
], dcCore::app()->adminurl?->hiddenFormFields(
|
|
|
|
My::id(),
|
|
|
|
['type' => $current->module->type, 'module' => $current->module->id, 'action' => 'module_add_code']
|
|
|
|
)
|
|
|
|
))->render() .
|
|
|
|
'</form><p> </p></div>';
|
2021-08-18 22:48:47 +00:00
|
|
|
}
|
2023-03-14 23:26:31 +00:00
|
|
|
|
|
|
|
// Import
|
2023-04-07 21:32:00 +00:00
|
|
|
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 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),
|
|
|
|
], dcCore::app()->adminurl?->hiddenFormFields(
|
|
|
|
My::id(),
|
|
|
|
['type' => $current->module->type, 'module' => $current->module->id, 'action' => 'module_import_pack']
|
|
|
|
)
|
|
|
|
)),
|
|
|
|
])->render() .
|
|
|
|
'<p> </p></div>';
|
2021-08-18 22:48:47 +00:00
|
|
|
|
2023-03-14 23:26:31 +00:00
|
|
|
echo '</div>';
|
2021-09-25 09:45:08 +00:00
|
|
|
|
2023-03-14 23:26:31 +00:00
|
|
|
dcPage::helpBlock('translater.module');
|
2023-03-16 21:59:33 +00:00
|
|
|
} elseif (!empty($current->lang)) {
|
|
|
|
$lines = $current->lang->getMessages();
|
2023-03-14 23:26:31 +00:00
|
|
|
$allowed_l10n_groups = [];
|
2021-09-24 23:58:59 +00:00
|
|
|
|
2023-03-14 23:26:31 +00:00
|
|
|
echo
|
|
|
|
'<div id="lang-form">' .
|
2023-03-19 23:21:13 +00:00
|
|
|
'<form id="lang-edit-form" method="post" action="' . dcCore::app()->adminurl?->get(My::id()) . '">' .
|
2023-03-14 23:26:31 +00:00
|
|
|
'<table class="table-outer">' .
|
|
|
|
'<caption>' . sprintf(__('List of %s localized strings'), count($lines)) . '</caption>' .
|
|
|
|
'<tr>' .
|
|
|
|
'<th colspan="2">' . __('Group') . '</th>' .
|
|
|
|
'<th>' . __('String') . '</th>' .
|
|
|
|
'<th>' . __('Translation') . '</th>' .
|
|
|
|
'<th>' . __('Existing') . '</th>' .
|
|
|
|
'<th>' . __('File') . '</th>' .
|
|
|
|
'</tr>';
|
2021-08-18 22:48:47 +00:00
|
|
|
|
2023-03-14 23:26:31 +00:00
|
|
|
$table_line = '<tr class="line%s">' .
|
|
|
|
'<td class="nowrap minimal">%s</td>' .
|
|
|
|
'<td class="nowrap minimal">%s</td>' .
|
|
|
|
'<td>%s</td>' .
|
|
|
|
'<td class="nowrap translatertarget">%s</td>' .
|
|
|
|
'<td class="translatermsgstr">%s</td>' .
|
|
|
|
'<td class="nowrap translatermsgfile">%s</td>' .
|
|
|
|
'</tr>';
|
|
|
|
$table_ul = '<div class="subtranslater"><strong>%s</strong><div class="strlist">%s</div></div><br />';
|
|
|
|
$table_li = '<i>%s</i><br />';
|
2021-08-18 22:48:47 +00:00
|
|
|
|
2023-03-14 23:26:31 +00:00
|
|
|
$i = 1;
|
|
|
|
foreach ($lines as $msgid => $rs) {
|
2023-03-16 21:59:33 +00:00
|
|
|
$in_dc = $rs['in_dc'] && $current->translater->parse_nodc ? true : false;
|
2023-03-14 23:26:31 +00:00
|
|
|
$t_msgstr = $t_files = $strin = [];
|
2021-08-18 22:48:47 +00:00
|
|
|
|
2021-11-01 21:32:32 +00:00
|
|
|
foreach ($rs['o_msgstrs'] as $o_msgstr) {
|
2023-03-14 23:26:31 +00:00
|
|
|
if (!isset($strin[$o_msgstr['msgstr'][0]])) {
|
|
|
|
$strin[$o_msgstr['msgstr'][0]] = [];
|
2021-09-24 23:58:59 +00:00
|
|
|
}
|
2023-03-14 23:26:31 +00:00
|
|
|
$strin[$o_msgstr['msgstr'][0]][] = ['module' => $o_msgstr['module'], 'file' => $o_msgstr['file']];
|
2021-09-24 23:58:59 +00:00
|
|
|
}
|
2021-11-01 21:32:32 +00:00
|
|
|
foreach ($strin as $k => $v) {
|
2021-09-24 23:58:59 +00:00
|
|
|
$res = [];
|
2021-11-01 21:32:32 +00:00
|
|
|
foreach ($v as $str) {
|
2023-04-07 21:32:00 +00:00
|
|
|
$res[] = sprintf($table_li, Html::escapeHTML($str['module'] . ':' . $str['file']));
|
2021-09-24 23:58:59 +00:00
|
|
|
}
|
2023-04-07 21:32:00 +00:00
|
|
|
$t_msgstr[] = sprintf($table_ul, Html::escapeHTML((string) $k), implode('', $res));
|
2021-09-24 23:58:59 +00:00
|
|
|
}
|
2021-08-18 22:48:47 +00:00
|
|
|
|
2023-03-14 23:26:31 +00:00
|
|
|
if (!empty($rs['files'][0])) {
|
|
|
|
if (count($rs['files']) == 1) {
|
|
|
|
$t_files[] = $rs['files'][0][0] . ':' . $rs['files'][0][1];
|
|
|
|
} else {
|
|
|
|
$res = [];
|
|
|
|
foreach ($rs['files'] as $location) {
|
|
|
|
$res[] = sprintf($table_li, implode(' : ', $location));
|
|
|
|
}
|
|
|
|
$t_files[] = sprintf($table_ul, sprintf(__('%s occurrences'), count($rs['files'])), implode('', $res));
|
|
|
|
;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-01 21:32:32 +00:00
|
|
|
echo sprintf(
|
|
|
|
$table_line,
|
|
|
|
$in_dc ? ' offline' : ' translaterline',
|
2023-04-07 21:32:00 +00:00
|
|
|
(new Checkbox(['entries[' . $i . '][check]']))->value(1)->render(),
|
|
|
|
(new Select(['entries[' . $i . '][group]']))->default($rs['group'])->items(My::l10nGroupsCombo())->disabled($in_dc)->render(),
|
|
|
|
Html::escapeHTML($msgid),
|
|
|
|
(new Hidden(['entries[' . $i . '][msgid]'], Html::escapeHTML($msgid)))->render() .
|
|
|
|
(new Input(['entries[' . $i . '][msgstr][0]']))->size(48)->maxlenght(255)->value(Html::escapeHTML($rs['msgstr'][0]))->disabled($in_dc)->render(),
|
2021-09-24 23:58:59 +00:00
|
|
|
implode('', $t_msgstr),
|
2023-03-14 23:26:31 +00:00
|
|
|
implode('', $t_files)
|
2021-09-24 23:58:59 +00:00
|
|
|
);
|
2023-03-14 23:26:31 +00:00
|
|
|
|
|
|
|
if (!empty($rs['plural'])) {
|
|
|
|
$t_msgstr = $strin = [];
|
2023-03-16 21:59:33 +00:00
|
|
|
foreach ($current->lang->plural as $j => $plural) {
|
2023-03-14 23:26:31 +00:00
|
|
|
foreach ($rs['o_msgstrs'] as $o_msgstr) {
|
|
|
|
if (isset($o_msgstr['msgstr'][$j + 1])) {
|
|
|
|
if (!isset($strin[$o_msgstr['msgstr'][$j + 1]])) {
|
|
|
|
$strin[$o_msgstr['msgstr'][$j + 1]] = [];
|
|
|
|
}
|
|
|
|
$strin[$o_msgstr['msgstr'][$j + 1]][] = ['module' => $o_msgstr['module'], 'file' => $o_msgstr['file']];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
foreach ($strin as $k => $v) {
|
|
|
|
$res = [];
|
|
|
|
foreach ($v as $str) {
|
2023-04-07 21:32:00 +00:00
|
|
|
$res[] = sprintf($table_li, Html::escapeHTML($str['module'] . ':' . $str['file']));
|
2023-03-14 23:26:31 +00:00
|
|
|
}
|
2023-04-07 21:32:00 +00:00
|
|
|
$t_msgstr[] = sprintf($table_ul, Html::escapeHTML((string) $k), implode('', $res));
|
2023-03-14 23:26:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
echo sprintf(
|
|
|
|
$table_line,
|
|
|
|
$in_dc ? ' offline' : ' translaterline',
|
|
|
|
'+',
|
|
|
|
sprintf(__('Plural "%s"'), $plural),
|
|
|
|
sprintf(__('Plural form of "%s"'), $rs['plural']),
|
2023-04-07 21:32:00 +00:00
|
|
|
(new Hidden(['entries[' . $i . '][msgid_plural]'], Html::escapeHTML($rs['plural'])))->render() .
|
|
|
|
(new Input(['entries[' . $i . '][msgstr][' . ($j + 1) . ']']))->size(48)->maxlenght(255)->value(Html::escapeHTML($rs['msgstr'][$j + 1] ?? ''))->disbaled($in_dc)->render(),
|
2023-03-14 23:26:31 +00:00
|
|
|
implode('', $t_msgstr),
|
|
|
|
''
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$i++;
|
2021-08-18 22:48:47 +00:00
|
|
|
}
|
2023-03-14 23:26:31 +00:00
|
|
|
echo sprintf(
|
|
|
|
$table_line,
|
|
|
|
' offline',
|
2023-04-07 21:32:00 +00:00
|
|
|
(new Checkbox(['entries[' . $i . '][check]']))->value(1)->render(),
|
|
|
|
(new Select(['entries[' . $i . '][group]']))->items(My::l10nGroupsCombo())->default('main')->render(),
|
|
|
|
(new Input(['entries[' . $i . '][msgid]']))->size(48)->maxlenght(255)->render(),
|
|
|
|
(new Input(['entries[' . $i . '][msgstr][0]']))->size(48)->maxlenght(255)->render(),
|
2023-03-14 23:26:31 +00:00
|
|
|
'',
|
|
|
|
''
|
|
|
|
);
|
|
|
|
echo
|
|
|
|
'</table>' .
|
|
|
|
|
|
|
|
'<div class="two-cols">' .
|
|
|
|
'<div class="col left">' .
|
|
|
|
'<p class="checkboxes-helpers"></p>' .
|
2023-04-07 21:32:00 +00:00
|
|
|
|
|
|
|
(new Para())->items([
|
|
|
|
(new Checkbox('update_group'))->value(1),
|
|
|
|
(new Label(__('Change the group of the selected translations to:'), Label::OUTSIDE_LABEL_AFTER))->for('update_group')->class('classic'),
|
|
|
|
(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)),
|
|
|
|
], dcCore::app()->adminurl?->hiddenFormFields(
|
|
|
|
My::id(),
|
|
|
|
['type' => $current->module?->type, 'module' => $current->module?->id, 'lang' => $current->lang->code, 'action' => 'module_update_code']
|
|
|
|
)
|
|
|
|
))->render() .
|
2023-03-14 23:26:31 +00:00
|
|
|
'</div>' .
|
|
|
|
'</form>' .
|
|
|
|
'<p> </p>' .
|
|
|
|
'</div>';
|
|
|
|
|
|
|
|
dcPage::helpBlock('translater.lang');
|
|
|
|
} else {
|
|
|
|
$line = '<li><a href="%s"%s>%s</a></li>';
|
|
|
|
echo '<h4><i>' . __('Translate your Dotclear plugins and themes') . '</i></h4>' .
|
|
|
|
sprintf(
|
|
|
|
'<h3><ul class="nice">%s</ul></h3>',
|
|
|
|
sprintf(
|
|
|
|
$line,
|
2023-03-19 23:21:13 +00:00
|
|
|
dcCore::app()->adminurl?->get(My::id(), ['type' => 'plugin']),
|
2023-03-16 21:59:33 +00:00
|
|
|
$current->type == 'plugin' ? ' class="active"' : '',
|
2023-03-14 23:26:31 +00:00
|
|
|
__('Translate plugins')
|
|
|
|
) .
|
|
|
|
sprintf(
|
|
|
|
$line,
|
2023-03-19 23:21:13 +00:00
|
|
|
dcCore::app()->adminurl?->get(My::id(), ['type' => 'theme']),
|
2023-03-16 21:59:33 +00:00
|
|
|
$current->type == 'theme' ? ' class="active"' : '',
|
2023-03-14 23:26:31 +00:00
|
|
|
__('Translate themes')
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
dcPage::helpBlock('translater.index');
|
2021-08-18 22:48:47 +00:00
|
|
|
}
|
2023-03-14 23:26:31 +00:00
|
|
|
|
|
|
|
dcPage::closeModule();
|
2021-09-24 23:58:59 +00:00
|
|
|
}
|
2021-08-18 19:42:30 +00:00
|
|
|
|
2023-03-14 23:26:31 +00:00
|
|
|
private static function redirect(string $msg, ?string $lang = null): void
|
|
|
|
{
|
2023-03-17 23:38:06 +00:00
|
|
|
$current = ManageVars::init();
|
2023-03-16 21:59:33 +00:00
|
|
|
|
2023-03-14 23:26:31 +00:00
|
|
|
$redir = [
|
2023-03-16 21:59:33 +00:00
|
|
|
'type' => $current->type,
|
2023-03-19 23:21:13 +00:00
|
|
|
'module' => $current->module?->id,
|
2023-03-14 23:26:31 +00:00
|
|
|
];
|
|
|
|
if ($lang) {
|
|
|
|
$redir['lang'] = $lang;
|
|
|
|
}
|
2021-08-18 19:42:30 +00:00
|
|
|
|
2023-03-14 23:26:31 +00:00
|
|
|
dcPage::addSuccessNotice($msg);
|
2023-03-19 23:21:13 +00:00
|
|
|
dcCore::app()->adminurl?->redirect(My::id(), $redir);
|
2023-03-14 23:26:31 +00:00
|
|
|
}
|
|
|
|
}
|