From f2adddec5e9a0fbe548a425d776827ca46fd647f Mon Sep 17 00:00:00 2001 From: Jean-Christian Denis Date: Sun, 13 Nov 2022 18:40:31 +0100 Subject: [PATCH] prepare to DC 2.24 --- _admin.php | 35 ++++----- _config.php | 12 +-- _define.php | 6 +- _install.php | 8 +- _prepend.php | 16 ++-- inc/class.dc.translater.lang.php | 12 ++- inc/class.dc.translater.module.php | 53 +++++++------- inc/class.dc.translater.php | 35 ++++----- inc/class.translater.proposals.php | 10 +-- inc/class.translater.rest.php | 6 +- inc/lib.translater.google.php | 6 +- inc/lib.translater.microsoft.php | 10 +-- inc/lib.translater.proposal.php | 17 ++--- index.php | 114 +++++++++++++++-------------- locales/fr/resources.php | 2 +- 15 files changed, 162 insertions(+), 180 deletions(-) diff --git a/_admin.php b/_admin.php index 31e59df..a7b8201 100644 --- a/_admin.php +++ b/_admin.php @@ -14,19 +14,19 @@ if (!defined('DC_CONTEXT_ADMIN')) { return; } -$core->addBehavior('adminModulesListGetActions', ['translaterAdminBehaviors', 'adminModulesGetActions']); -$core->addBehavior('adminModulesListDoActions', ['translaterAdminBehaviors', 'adminModulesDoActions']); -$core->addBehavior('adminDashboardFavorites', ['translaterAdminBehaviors', 'adminDashboardFavorites']); +dcCore::app()->addBehavior('adminModulesListGetActions', ['translaterAdminBehaviors', 'adminModulesGetActions']); +dcCore::app()->addBehavior('adminModulesListDoActions', ['translaterAdminBehaviors', 'adminModulesDoActions']); +dcCore::app()->addBehavior('adminDashboardFavoritesV2', ['translaterAdminBehaviors', 'adminDashboardFavorites']); -$_menu['Plugins']->addItem( +dcCore::app()->menu[dcAdmin::MENU_PLUGINS]->addItem( __('Translater'), - $core->adminurl->get('translater'), + dcCore::app()->adminurl->get('translater'), dcPage::getPF('translater/icon.png'), preg_match( - '/' . preg_quote($core->adminurl->get('translater')) . '(&.*)?$/', + '/' . preg_quote(dcCore::app()->adminurl->get('translater')) . '(&.*)?$/', $_SERVER['REQUEST_URI'] ), - $core->auth->isSuperAdmin() + dcCore::app()->auth->isSuperAdmin() ); class translaterAdminBehaviors @@ -37,14 +37,12 @@ class translaterAdminBehaviors /** * Create instance of dcTranslater once * - * @param dcCore $core dcCore instance - * * @return dcTranslater dcTranslater instance */ - private static function translater(dcCore $core): dcTranslater + private static function translater(): dcTranslater { if (!is_a(self::$translater, 'dcTranslater')) { - self::$translater = new dcTranslater($core, false); + self::$translater = new dcTranslater(false); } return self::$translater; @@ -62,12 +60,12 @@ class translaterAdminBehaviors public static function adminModulesGetActions(adminModulesList $list, string $id, array $prop): ?string { if ($list->getList() != $prop['type'] . '-activate' - || !self::translater($list->core)->{$prop['type'] . '_menu'} - || !$list->core->auth->isSuperAdmin() + || !self::translater()->{$prop['type'] . '_menu'} + || !dcCore::app()->auth->isSuperAdmin() ) { return null; } - if (self::translater($list->core)->hide_default + if (self::translater()->hide_default && in_array($id, dcTranslater::$default_distrib_modules[$prop['type']]) ) { return null; @@ -92,7 +90,7 @@ class translaterAdminBehaviors return; } - $list->core->adminurl->redirect( + dcCore::app()->adminurl->redirect( 'translater', ['part' => 'module', 'type' => $type, 'module' => key($_POST['translater'])], '#module-lang' @@ -102,17 +100,16 @@ class translaterAdminBehaviors /** * Add dashboard favorites icon * - * @param dcCore $core dcCore instance * @param dcFavorites $favs dcFavorites instance */ - public static function adminDashboardFavorites(dcCore $core, dcFavorites$favs): void + public static function adminDashboardFavorites(dcFavorites$favs): void { $favs->register('translater', [ 'title' => __('Translater'), - 'url' => $core->adminurl->get('translater'), + 'url' => dcCore::app()->adminurl->get('translater'), 'small-icon' => urldecode(dcPage::getPF('translater/icon.png')), 'large-icon' => urldecode(dcPage::getPF('translater/icon-big.png')), - 'permissions' => $core->auth->isSuperAdmin() + 'permissions' => dcCore::app()->auth->isSuperAdmin(), ]); } } diff --git a/_config.php b/_config.php index b074eeb..e48edae 100644 --- a/_config.php +++ b/_config.php @@ -14,7 +14,7 @@ if (!defined('DC_CONTEXT_MODULE')) { return null; } -$translater = new dcTranslater($core); +$translater = new dcTranslater(); if (!empty($_POST['save'])) { try { @@ -22,15 +22,15 @@ if (!empty($_POST['save'])) { $translater->$key = $_POST[$key] ?? ''; } $translater->writeSettings(); - dcPage::addSuccessNotice( + dcAdminNotices::addSuccessNotice( __('Configuration successfully updated.') ); - $core->adminurl->redirect( + dcCore::app()->adminurl->redirect( 'admin.plugins', - ['module' => 'translater', 'conf' => 1, 'redir' => $list->getRedir()] + ['module' => 'translater', 'conf' => 1, 'redir' => dcCore::app()->admin->list->getRedir()] ); } catch (Exception $e) { - $core->error->add($e->getMessage()); + dcCore::app()->error->add($e->getMessage()); } } @@ -88,7 +88,7 @@ form::combo('backup_folder', $translater::$allowed_backup_folders, $translater-> form::combo('start_page', [ __('Plugins') => 'plugin', __('Themes') => 'theme', - __('Home') => '-' + __('Home') => '-', ], $translater->start_page) . '

'; + echo ''; $res = ''; $modules = $translater->getModules($type); @@ -199,7 +199,7 @@ if (empty($module) && $type != '') { if ($module->root_writable) { $res .= sprintf( '%s', - $core->adminurl->get('translater', ['type' => $module->type, 'module' => $module->id]), + dcCore::app()->adminurl->get('translater', ['type' => $module->type, 'module' => $module->id]), html::escapeHTML(sprintf(__('Translate module %s'), __($module->name))), html::escapeHTML($module->id) ); @@ -215,7 +215,7 @@ if (empty($module) && $type != '') { $codes[$code_id] = sprintf( '%s (%s)', html::escapeHTML(sprintf(__('Edit language %s of module %s'), html::escapeHTML($code_name), __($module->name))), - $core->adminurl->get('translater', ['type' => $module->type, 'module' => $module->id, 'lang' => $code_id]), + dcCore::app()->adminurl->get('translater', ['type' => $module->type, 'module' => $module->id, 'lang' => $code_id]), html::escapeHTML($code_name), $code_id ); @@ -267,7 +267,7 @@ if (empty($module) && $type != '') { if (count($codes)) { echo '

' . __('Translations') . '

' . - '' . + '' . '' . '' . '' . @@ -283,12 +283,13 @@ if (empty($module) && $type != '') { '' . '' . ''; if (isset($backups[$code_id])) { + $time[$code_id] = 'UTC'; foreach ($backups[$code_id] as $file => $info) { $time[$code_id] = isset($time[$code_id]) && $time[$code_id] > $info['time'] ? $time[$code_id] : $info['time']; @@ -296,7 +297,7 @@ if (empty($module) && $type != '') { echo '' . ''; } else { echo ''; @@ -311,11 +312,11 @@ if (empty($module) && $type != '') { form::combo('action', [ __('Backup languages') => 'module_create_backups', __('Delete languages') => 'module_delete_codes', - __('Export languages') => 'module_export_pack' + __('Export languages') => 'module_export_pack', ]) . '

' . - $core->formNonce() . - $core->adminurl->getHiddenFormFields( + dcCore::app()->formNonce() . + dcCore::app()->adminurl->getHiddenFormFields( 'translater', ['type' => $module->type, 'module' => $module->id] ) . ' @@ -327,7 +328,7 @@ if (empty($module) && $type != '') { // delete / retore backups if (!empty($backups)) { echo '

' . __('Backups') . '

' . - '' . + '' . '
' . __('Existing languages translations') . '
' . form::checkbox(['codes[]', 'existing_code_' . $code_id], $code_id, '', '', '', false) . '' . '' . $code_name . '' . ' ' . $code_id . '' . count($backups[$code_id]) . ' ' . - dt::str('%Y-%m-%d %H:%M', $time[$code_id], $core->blog->settings->system->blog_timezone) . + dt::str('%Y-%m-%d %H:%M', $time[$code_id], dcCore::app()->blog->settings->system->blog_timezone) . '' . __('no backups') . '-
' . '' . '' . @@ -359,9 +360,9 @@ if (empty($module) && $type != '') { $backup_code['name'], $backup_code['code'], dt::str( - $core->blog->settings->system->date_format . ' ' . $core->blog->settings->system->time_format, + dcCore::app()->blog->settings->system->date_format . ' ' . dcCore::app()->blog->settings->system->time_format, $backup_code['time'], - $core->blog->settings->system->blog_timezone + dcCore::app()->blog->settings->system->blog_timezone ), $backup_code['path']['basename'], files::size($backup_code['size']) @@ -376,11 +377,11 @@ if (empty($module) && $type != '') {

' . __('Selected backups action:') . ' ' . form::combo('action', [ __('Restore backups') => 'module_restore_backup', - __('Delete backups') => 'module_delete_backup' + __('Delete backups') => 'module_delete_backup', ]) . '

' . - $core->formNonce() . - $core->adminurl->getHiddenFormFields( + dcCore::app()->formNonce() . + dcCore::app()->adminurl->getHiddenFormFields( 'translater', ['type' => $module->type, 'module' => $module->id] ) . ' @@ -393,9 +394,9 @@ if (empty($module) && $type != '') { // add language if (!empty($unused_codes)) { echo '

' . __('Add language') . '

- +

' . - form::combo(['code'], array_merge(['-' => '-'], $unused_codes), $core->auth->getInfo('user_lang')) . '

'; + form::combo(['code'], array_merge(['-' => '-'], $unused_codes), dcCore::app()->auth->getInfo('user_lang')) . '

'; if (empty($codes)) { echo '

' . form::hidden(['from'], '') . '

'; } else { @@ -405,8 +406,8 @@ if (empty($module) && $type != '') { } echo '

' . - $core->formNonce() . - $core->adminurl->getHiddenFormFields( + dcCore::app()->formNonce() . + dcCore::app()->adminurl->getHiddenFormFields( 'translater', ['type' => $module->type, 'module' => $module->id, 'action' => 'module_add_code'] ) . ' @@ -415,13 +416,13 @@ if (empty($module) && $type != '') { // Import echo '

' . __('Import') . '

- +

' . - $core->formNonce() . - $core->adminurl->getHiddenFormFields( + dcCore::app()->formNonce() . + dcCore::app()->adminurl->getHiddenFormFields( 'translater', ['type' => $module->type, 'module' => $module->id, 'action' => 'module_import_pack'] ) . ' @@ -432,10 +433,11 @@ if (empty($module) && $type != '') { dcPage::helpBlock('translater.module'); } elseif (!empty($lang)) { $lines = $lang->getMessages(); + $allowed_l10n_groups = []; echo '

' . - '' . + '' . '
' . __('Existing languages backups') . '
' . '' . '' . @@ -461,7 +463,7 @@ if (empty($module) && $type != '') { foreach ($lines as $msgid => $rs) { $in_dc = ($rs['in_dc'] && $translater->parse_nodc); $allowed_l10n_groups = array_combine($translater::$allowed_l10n_groups, $translater::$allowed_l10n_groups); - $t_msgstr = $t_files = $strin = []; + $t_msgstr = $t_files = $strin = []; foreach ($rs['o_msgstrs'] as $o_msgstr) { if (!isset($strin[$o_msgstr['msgstr'][0]])) { @@ -528,7 +530,7 @@ if (empty($module) && $type != '') { sprintf(__('Plural "%s"'), $plural), sprintf(__('Plural form of "%s"'), $rs['plural']), form::hidden(['entries[' . $i . '][msgid_plural]'], html::escapeHTML($rs['plural'])) . - form::field(['entries[' . $i . '][msgstr][' . $j + 1 . ']'], 48, 255, html::escapeHTML($rs['msgstr'][$j + 1] ?? ''), '', '', $in_dc), + form::field(['entries[' . $i . '][msgstr][' . ($j + 1) . ']'], 48, 255, html::escapeHTML($rs['msgstr'][$j + 1] ?? ''), '', '', $in_dc), implode('', $t_msgstr), '' ); @@ -559,9 +561,9 @@ if (empty($module) && $type != '') { '' . '

' . '

' . - $core->formNonce() . + dcCore::app()->formNonce() . form::hidden(['code'], $lang->code) . - $core->adminurl->getHiddenFormFields( + dcCore::app()->adminurl->getHiddenFormFields( 'translater', ['type' => $module->type, 'module' => $module->id, 'lang' => $lang->code, 'action' => 'module_update_code'] ) . @@ -578,13 +580,13 @@ if (empty($module) && $type != '') { '

    %s

', sprintf( $line, - $core->adminurl->get('translater', ['type' => 'plugin']), + dcCore::app()->adminurl->get('translater', ['type' => 'plugin']), $type == 'plugin' ? ' class="active"' : '', __('Translate plugins') ) . sprintf( $line, - $core->adminurl->get('translater', ['type' => 'theme']), + dcCore::app()->adminurl->get('translater', ['type' => 'theme']), $type == 'theme' ? ' class="active"' : '', __('Translate themes') ) diff --git a/locales/fr/resources.php b/locales/fr/resources.php index 10de4ba..0fb63e0 100644 --- a/locales/fr/resources.php +++ b/locales/fr/resources.php @@ -15,5 +15,5 @@ if (!defined('DC_RC_PATH')) { } foreach (['index', 'type', 'module', 'lang', 'config'] as $v) { - $__resources['help']['translater.' . $v] = dirname(__FILE__) . '/help/translater.' . $v . '.html'; + dcCore::app()->resources['help']['translater.' . $v] = __DIR__ . '/help/translater.' . $v . '.html'; }
' . sprintf(__('List of %s localized strings'), count($lines)) . '