From a11c7781817e865d5397cae56f06a9b7e53624e0 Mon Sep 17 00:00:00 2001 From: Jean-Christian Denis Date: Mon, 26 Dec 2022 21:48:51 +0100 Subject: [PATCH] use abstract plugin id and settings ns --- _admin.php | 14 +++---- _config.php | 2 +- _define.php | 4 +- _prepend.php | 2 +- _uninstall.php | 18 ++++----- inc/class.dc.translater.module.php | 6 +-- inc/class.dc.translater.php | 9 +++-- inc/lib.translater.google.php | 4 +- inc/lib.translater.microsoft.php | 8 ++-- index.php | 64 +++++++++++++++--------------- 10 files changed, 66 insertions(+), 65 deletions(-) diff --git a/_admin.php b/_admin.php index 7c39811..c1847f9 100644 --- a/_admin.php +++ b/_admin.php @@ -26,10 +26,10 @@ dcCore::app()->addBehaviors([ dcCore::app()->menu[dcAdmin::MENU_PLUGINS]->addItem( __('Translater'), - dcCore::app()->adminurl->get('translater'), - dcPage::getPF('translater/icon.svg'), + dcCore::app()->adminurl->get(basename(__DIR__)), + dcPage::getPF(basename(__DIR__) . '/icon.svg'), preg_match( - '/' . preg_quote(dcCore::app()->adminurl->get('translater')) . '(&.*)?$/', + '/' . preg_quote(dcCore::app()->adminurl->get(basename(__DIR__))) . '(&.*)?$/', $_SERVER['REQUEST_URI'] ), dcCore::app()->auth->isSuperAdmin() @@ -97,7 +97,7 @@ class translaterAdminBehaviors } dcCore::app()->adminurl->redirect( - 'translater', + basename(__DIR__), ['part' => 'module', 'type' => $type, 'module' => key($_POST['translater'])], '#module-lang' ); @@ -112,9 +112,9 @@ class translaterAdminBehaviors { $favs->register('translater', [ 'title' => __('Translater'), - 'url' => dcCore::app()->adminurl->get('translater'), - 'small-icon' => urldecode(dcPage::getPF('translater/icon.svg')), - 'large-icon' => urldecode(dcPage::getPF('translater/icon.svg')), + 'url' => dcCore::app()->adminurl->get(basename(__DIR__)), + 'small-icon' => urldecode(dcPage::getPF(basename(__DIR__) . '/icon.svg')), + 'large-icon' => urldecode(dcPage::getPF(basename(__DIR__) . '/icon.svg')), //'permissions' => null, ]); } diff --git a/_config.php b/_config.php index c7aad71..3f94537 100644 --- a/_config.php +++ b/_config.php @@ -27,7 +27,7 @@ if (!empty($_POST['save'])) { ); dcCore::app()->adminurl->redirect( 'admin.plugins', - ['module' => 'translater', 'conf' => 1, 'redir' => dcCore::app()->admin->__get('list')->getRedir()] + ['module' => basename(__DIR__), 'conf' => 1, 'redir' => dcCore::app()->admin->__get('list')->getRedir()] ); } catch (Exception $e) { dcCore::app()->error->add($e->getMessage()); diff --git a/_define.php b/_define.php index a420dff..d7998d5 100644 --- a/_define.php +++ b/_define.php @@ -24,7 +24,7 @@ $this->registerModule( 'permissions' => null, 'type' => 'plugin', 'support' => 'http://forum.dotclear.org/viewtopic.php?id=39220', - 'details' => 'https://plugins.dotaddict.org/dc2/details/translater', - 'repository' => 'https://raw.githubusercontent.com/JcDenis/translater/master/dcstore.xml', + 'details' => 'https://plugins.dotaddict.org/dc2/details/' . basename(__DIR__), + 'repository' => 'https://raw.githubusercontent.com/JcDenis/' . basename(__DIR__) . '/master/dcstore.xml', ] ); diff --git a/_prepend.php b/_prepend.php index d9f310d..c4c5beb 100644 --- a/_prepend.php +++ b/_prepend.php @@ -23,5 +23,5 @@ Clearbricks::lib()->autoload([ ]); if (isset(dcCore::app()->adminurl)) { - dcCore::app()->adminurl->register('translater', 'plugin.php', ['p' => 'translater']); + dcCore::app()->adminurl->register(basename(__DIR__), 'plugin.php', ['p' => basename(__DIR__)]); } diff --git a/_uninstall.php b/_uninstall.php index 38095a6..3076edc 100644 --- a/_uninstall.php +++ b/_uninstall.php @@ -20,7 +20,7 @@ $this->addUserAction( /* action */ 'delete_all', /* ns */ - 'translater', + basename(__DIR__), /* description */ __('delete all settings') ); @@ -31,7 +31,7 @@ $this->addUserAction( /* action */ 'delete', /* ns */ - 'translater', + basename(__DIR__), /* description */ __('delete plugin files') ); @@ -42,7 +42,7 @@ $this->addUserAction( /* action */ 'delete', /* ns */ - 'translater', + basename(__DIR__), /* description */ __('delete the version number') ); @@ -53,9 +53,9 @@ $this->addDirectAction( /* action */ 'delete_all', /* ns */ - 'translater', + basename(__DIR__), /* description */ - sprintf(__('delete all %s settings'), 'translater') + sprintf(__('delete all %s settings'), basename(__DIR__)) ); $this->addDirectAction( @@ -64,9 +64,9 @@ $this->addDirectAction( /* action */ 'delete', /* ns */ - 'translater', + basename(__DIR__), /* description */ - sprintf(__('delete %s plugin files'), 'translater') + sprintf(__('delete %s plugin files'), basename(__DIR__)) ); $this->addDirectAction( @@ -75,7 +75,7 @@ $this->addDirectAction( /* action */ 'delete', /* ns */ - 'translater', + basename(__DIR__), /* description */ - sprintf(__('delete %s version number'), 'translater') + sprintf(__('delete %s version number'), basename(__DIR__)) ); diff --git a/inc/class.dc.translater.module.php b/inc/class.dc.translater.module.php index 2e869bd..8b32561 100644 --- a/inc/class.dc.translater.module.php +++ b/inc/class.dc.translater.module.php @@ -106,7 +106,7 @@ class dcTranslaterModule break; case 'translater': - $tmp = path::real(dcCore::app()->plugins->moduleRoot('translater')); + $tmp = path::real(dcCore::app()->plugins->moduleRoot(basename(dirname(__DIR__)))); if ($tmp && is_writable($tmp)) { @mkDir($tmp . '/locales'); $dir = $tmp . '/locales'; @@ -676,7 +676,7 @@ class dcTranslaterModule $content .= '# Author: ' . html::escapeHTML($info) . "\n"; } } - $content .= '# Translated with translater ' . dcCore::app()->plugins->moduleInfo('translater', 'version') . "\n\n"; + $content .= '# Translated with translater ' . dcCore::app()->plugins->moduleInfo(basename(dirname(__DIR__)), 'version') . "\n\n"; } $content .= "msgid \"\"\n" . "msgstr \"\"\n" . @@ -767,7 +767,7 @@ class dcTranslaterModule $content .= '// Author: ' . html::escapeHTML($info) . "\n"; } } - $content .= '// Translated with dcTranslater - ' . dcCore::app()->plugins->moduleInfo('translater', 'version') . "\n\n"; + $content .= '// Translated with dcTranslater - ' . dcCore::app()->plugins->moduleInfo(basename(dirname(__DIR__)), 'version') . "\n\n"; } l10n::generatePhpFileFromPo($this->locales . '/' . $lang->code . '/' . $group, $content); diff --git a/inc/class.dc.translater.php b/inc/class.dc.translater.php index b307f26..f3a62cf 100644 --- a/inc/class.dc.translater.php +++ b/inc/class.dc.translater.php @@ -104,7 +104,7 @@ class dcTranslater extends dcTranslaterDefaultSettings __('plugins folder root') => 'plugin', __('public folder root') => 'public', __('cache folder of Dotclear') => 'cache', - __('locales folder of translater') => 'translater', + __('locales folder of translater') => basename(dirname(__DIR__)), ]; self::$default_distrib_modules = [ 'plugin' => explode(',', DC_DISTRIB_PLUGINS), @@ -120,7 +120,7 @@ class dcTranslater extends dcTranslaterDefaultSettings public function loadSettings(): void { foreach ($this->getDefaultSettings() as $key => $value) { - $this->$key = dcCore::app()->blog->settings->get('translater')->get($key); + $this->$key = dcCore::app()->blog->settings->get(basename(dirname(__DIR__)))->get($key); try { settype($this->$key, gettype($value)); @@ -137,8 +137,8 @@ class dcTranslater extends dcTranslaterDefaultSettings public function writeSettings($overwrite = true): void { foreach ($this->getDefaultSettings() as $key => $value) { - dcCore::app()->blog->settings->get('translater')->drop($key); - dcCore::app()->blog->settings->get('translater')->put($key, $this->$key, gettype($value), '', true, true); + dcCore::app()->blog->settings->get(basename(dirname(__DIR__)))->drop($key); + dcCore::app()->blog->settings->get(basename(dirname(__DIR__)))->put($key, $this->$key, gettype($value), '', true, true); } } @@ -161,6 +161,7 @@ class dcTranslater extends dcTranslaterDefaultSettings if (preg_match('/^translater_(.*?)$/', $record->setting_id, $match)) { $cur = dcCore::app()->con->openCursor(dcCore::app()->prefix . dcNamespace::NS_TABLE_NAME); $cur->setting_id = $this->{$match[1]} = $match[1]; + $cur->setting_ns = basename(dirname(__DIR__)); $cur->update( "WHERE setting_id = '" . $record->setting_id . "' and setting_ns = 'translater' " . 'AND blog_id ' . (null === $record->blog_id ? 'IS NULL ' : ("= '" . dcCore::app()->con->escape($record->blog_id) . "' ")) diff --git a/inc/lib.translater.google.php b/inc/lib.translater.google.php index a522207..d682b9d 100644 --- a/inc/lib.translater.google.php +++ b/inc/lib.translater.google.php @@ -27,7 +27,7 @@ class googleProposalTool extends translaterProposalTool protected function setup() { - $this->key = dcCore::app()->blog->settings->translater->translater_google_proposal_key; + $this->key = dcCore::app()->blog->settings->get(basename(dirname(__DIR__)))->get('google_proposal_key'); $this->setName(__('Google')); $this->setDesc(__('Google Translation Tool API')); @@ -53,7 +53,7 @@ class googleProposalTool extends translaterProposalTool $key = empty($_POST['translater_google_proposal_key']) ? '' : $_POST['translater_google_proposal_key']; - dcCore::app()->blog->settings->translater->put('translater_google_proposal_key', $key, 'string', '', true, true); + dcCore::app()->blog->settings->get(basename(dirname(__DIR__)))->put('google_proposal_key', $key, 'string', '', true, true); } public function translate($str, $from, $to) diff --git a/inc/lib.translater.microsoft.php b/inc/lib.translater.microsoft.php index 8e66e44..eba73c6 100644 --- a/inc/lib.translater.microsoft.php +++ b/inc/lib.translater.microsoft.php @@ -27,8 +27,8 @@ class microsoftProposalTool extends translaterProposalTool protected function setup() { $this->setActive(false); - $this->client = dcCore::app()->blog->settings->translater->translater_microsoft_proposal_client; - $this->secret = dcCore::app()->blog->settings->translater->translater_microsoft_proposal_secret; + $this->client = dcCore::app()->blog->settings->get(basename(dirname(__DIR__)))->get('microsoft_proposal_client'); + $this->secret = dcCore::app()->blog->settings->get(basename(dirname(__DIR__)))->get('microsoft_proposal_secret'); $this->setName(__('Bing')); $this->setDesc(__('Microsoft Bing translation tool')); @@ -61,8 +61,8 @@ class microsoftProposalTool extends translaterProposalTool $secret = empty($_POST['translater_microsoft_proposal_secret']) ? '' : $_POST['translater_microsoft_proposal_secret']; - dcCore::app()->blog->settings->translater->put('translater_microsoft_proposal_client', $client, 'string', '', true, true); - dcCore::app()->blog->settings->translater->put('translater_microsoft_proposal_secret', $secret, 'string', '', true, true); + dcCore::app()->blog->settings->get(basename(dirname(__DIR__)))->put('microsoft_proposal_client', $client, 'string', '', true, true); + dcCore::app()->blog->settings->get(basename(dirname(__DIR__)))->put('microsoft_proposal_secret', $secret, 'string', '', true, true); } public function translate($str, $from, $to) diff --git a/index.php b/index.php index f7f0479..6207bcb 100644 --- a/index.php +++ b/index.php @@ -45,17 +45,17 @@ if (!empty($module) && !empty($lang)) { } } -$breadcrumb = [__('Translater') => dcCore::app()->adminurl->get('translater', ['type' => '-'])]; +$breadcrumb = [__('Translater') => dcCore::app()->adminurl->get(basename(__DIR__), ['type' => '-'])]; if (empty($type)) { $breadcrumb = [__('Translater') => '']; } elseif (empty($module)) { $breadcrumb[$type == 'plugin' ? __('Plugins') : __('Themes')] = ''; } elseif (empty($lang)) { - $breadcrumb[$type == 'plugin' ? __('Plugins') : __('Themes')] = dcCore::app()->adminurl->get('translater', ['type' => $type]); + $breadcrumb[$type == 'plugin' ? __('Plugins') : __('Themes')] = dcCore::app()->adminurl->get(basename(__DIR__), ['type' => $type]); $breadcrumb[html::escapeHTML($module->name)] = ''; } elseif (!empty($lang)) { - $breadcrumb[$type == 'plugin' ? __('Plugins') : __('Themes')] = dcCore::app()->adminurl->get('translater', ['type' => $type]); - $breadcrumb[html::escapeHTML($module->name)] = dcCore::app()->adminurl->get('translater', ['type' => $type, 'module' => $module->id]); + $breadcrumb[$type == 'plugin' ? __('Plugins') : __('Themes')] = dcCore::app()->adminurl->get(basename(__DIR__), ['type' => $type]); + $breadcrumb[html::escapeHTML($module->name)] = dcCore::app()->adminurl->get(basename(__DIR__), ['type' => $type, 'module' => $module->id]); $breadcrumb[html::escapeHTML(sprintf(__('%s language edition'), $lang->name))] = ''; } @@ -71,7 +71,7 @@ try { } } dcAdminNotices::addSuccessNotice(__('Backup successfully created')); - dcCore::app()->adminurl->redirect('translater', ['type' => $type, 'module' => $module->id]); + dcCore::app()->adminurl->redirect(basename(__DIR__), ['type' => $type, 'module' => $module->id]); } if ($action == 'module_restore_backup') { @@ -85,7 +85,7 @@ try { } } dcAdminNotices::addSuccessNotice(__('Backup successfully restored')); - dcCore::app()->adminurl->redirect('translater', ['type' => $type, 'module' => $module->id]); + dcCore::app()->adminurl->redirect(basename(__DIR__), ['type' => $type, 'module' => $module->id]); } if ($action == 'module_delete_backup') { @@ -99,7 +99,7 @@ try { } } dcAdminNotices::addSuccessNotice(__('Backup successfully deleted')); - dcCore::app()->adminurl->redirect('translater', ['type' => $type, 'module' => $module->id]); + dcCore::app()->adminurl->redirect(basename(__DIR__), ['type' => $type, 'module' => $module->id]); } if ($action == 'module_export_pack') { @@ -109,7 +109,7 @@ try { $module->exportPack($_POST['codes']); dcAdminNotices::addSuccessNotice(__('Language successfully exported')); - dcCore::app()->adminurl->redirect('translater', ['type' => $type, 'module' => $module->id]); + dcCore::app()->adminurl->redirect(basename(__DIR__), ['type' => $type, 'module' => $module->id]); } if ($action == 'module_import_pack') { @@ -119,7 +119,7 @@ try { $module->importPack($_FILES['packfile']); dcAdminNotices::addSuccessNotice(__('Language successfully imported')); - dcCore::app()->adminurl->redirect('translater', ['type' => $type, 'module' => $module->id]); + dcCore::app()->adminurl->redirect(basename(__DIR__), ['type' => $type, 'module' => $module->id]); } if ($action == 'module_add_code') { @@ -129,7 +129,7 @@ try { $module->addLang($_POST['code'], $_POST['from'] ?? ''); dcAdminNotices::addSuccessNotice(__('Language successfully added')); - dcCore::app()->adminurl->redirect('translater', ['type' => $type, 'module' => $module->id, 'lang' => $_POST['code']]); + dcCore::app()->adminurl->redirect(basename(__DIR__), ['type' => $type, 'module' => $module->id, 'lang' => $_POST['code']]); } if ($action == 'module_delete_codes') { @@ -143,7 +143,7 @@ try { } } dcAdminNotices::addSuccessNotice(__('Language successfully deleted')); - dcCore::app()->adminurl->redirect('translater', ['type' => $type, 'module' => $module->id, 'lang' => $_POST['code']]); + dcCore::app()->adminurl->redirect(basename(__DIR__), ['type' => $type, 'module' => $module->id, 'lang' => $_POST['code']]); } if ($action == 'module_update_code') { @@ -160,7 +160,7 @@ try { $module->updLang($_POST['code'], $_POST['entries']); dcAdminNotices::addSuccessNotice(__('Language successfully updated')); - dcCore::app()->adminurl->redirect('translater', ['type' => $type, 'module' => $module->id, 'lang' => $_POST['code']]); + dcCore::app()->adminurl->redirect(basename(__DIR__), ['type' => $type, 'module' => $module->id, 'lang' => $_POST['code']]); } } catch (Exception $e) { dcCore::app()->error->add($e->getMessage()); @@ -169,13 +169,13 @@ try { echo '' . __('Translater') . '' . dcPage::jsPageTabs() . -dcPage::cssModuleLoad('translater/css/translater.css')) . +dcPage::cssModuleLoad(basename(__DIR__) . '/css/translater.css') . dcPage::jsJson('translater', [ 'title_add_detail' => __('Use this text'), - 'image_field' => dcPage::getPF('translater/img/field.png'), - 'image_toggle' => dcPage::getPF('translater/img/toggle.png'), + 'image_field' => dcPage::getPF(basename(__DIR__) . '/img/field.png'), + 'image_toggle' => dcPage::getPF(basename(__DIR__) . '/img/toggle.png'), ]) . -dcPage::jsModuleLoad('translater/js/translater.js') . +dcPage::jsModuleLoad(basename(__DIR__) . '/js/translater.js') . # --BEHAVIOR-- translaterAdminHeaders dcCore::app()->callBehavior('translaterAdminHeaders') . @@ -187,7 +187,7 @@ dcPage::notices(); if (empty($module) && $type != '') { // modules list - echo '
'; + echo ''; $res = ''; $modules = $translater->getModules($type); @@ -199,7 +199,7 @@ if (empty($module) && $type != '') { if ($module->root_writable) { $res .= sprintf( '%s', - dcCore::app()->adminurl->get('translater', ['type' => $module->type, 'module' => $module->id]), + dcCore::app()->adminurl->get(basename(__DIR__), ['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))), - dcCore::app()->adminurl->get('translater', ['type' => $module->type, 'module' => $module->id, 'lang' => $code_id]), + dcCore::app()->adminurl->get(basename(__DIR__), ['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,7 +283,7 @@ if (empty($module) && $type != '') { '' . '' . ''; @@ -317,7 +317,7 @@ if (empty($module) && $type != '') {

' . dcCore::app()->formNonce() . dcCore::app()->adminurl->getHiddenFormFields( - 'translater', + basename(__DIR__), ['type' => $module->type, 'module' => $module->id] ) . '

 

'; @@ -328,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 . '
' . '' . '' . @@ -382,7 +382,7 @@ if (empty($module) && $type != '') {

' . dcCore::app()->formNonce() . dcCore::app()->adminurl->getHiddenFormFields( - 'translater', + basename(__DIR__), ['type' => $module->type, 'module' => $module->id] ) . '

 

'; @@ -394,7 +394,7 @@ if (empty($module) && $type != '') { // add language if (!empty($unused_codes)) { echo '

' . __('Add language') . '

-
+

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

'; if (empty($codes)) { @@ -408,7 +408,7 @@ if (empty($module) && $type != '') {

' . dcCore::app()->formNonce() . dcCore::app()->adminurl->getHiddenFormFields( - 'translater', + basename(__DIR__), ['type' => $module->type, 'module' => $module->id, 'action' => 'module_add_code'] ) . '

 

'; @@ -416,14 +416,14 @@ if (empty($module) && $type != '') { // Import echo '

' . __('Import') . '

-
+

' . dcCore::app()->formNonce() . dcCore::app()->adminurl->getHiddenFormFields( - 'translater', + basename(__DIR__), ['type' => $module->type, 'module' => $module->id, 'action' => 'module_import_pack'] ) . '

 

'; @@ -437,7 +437,7 @@ if (empty($module) && $type != '') { echo '
' . - '
' . + '' . '
' . __('Existing languages backups') . '
' . '' . '' . @@ -564,7 +564,7 @@ if (empty($module) && $type != '') { dcCore::app()->formNonce() . form::hidden(['code'], $lang->code) . dcCore::app()->adminurl->getHiddenFormFields( - 'translater', + basename(__DIR__), ['type' => $module->type, 'module' => $module->id, 'lang' => $lang->code, 'action' => 'module_update_code'] ) . '

' . @@ -580,13 +580,13 @@ if (empty($module) && $type != '') { '

    %s

', sprintf( $line, - dcCore::app()->adminurl->get('translater', ['type' => 'plugin']), + dcCore::app()->adminurl->get(basename(__DIR__), ['type' => 'plugin']), $type == 'plugin' ? ' class="active"' : '', __('Translate plugins') ) . sprintf( $line, - dcCore::app()->adminurl->get('translater', ['type' => 'theme']), + dcCore::app()->adminurl->get(basename(__DIR__), ['type' => 'theme']), $type == 'theme' ? ' class="active"' : '', __('Translate themes') )
' . sprintf(__('List of %s localized strings'), count($lines)) . '