From e1d3500fc9881b15dae1b3a00fb1fe198ec6d0d1 Mon Sep 17 00:00:00 2001 From: Jean-Christian Denis Date: Tue, 26 Oct 2021 22:27:27 +0200 Subject: [PATCH] move settings to config file for admin (dc2.20) --- _config.php | 184 ++++++++++++++++++++++++++++++++++ index.php | 280 ++++------------------------------------------------ 2 files changed, 204 insertions(+), 260 deletions(-) create mode 100644 _config.php diff --git a/_config.php b/_config.php new file mode 100644 index 0000000..e9f81cc --- /dev/null +++ b/_config.php @@ -0,0 +1,184 @@ +blog->settings->kUtRL; + +# Default values +$img_green = 'ok'; +$img_red = 'fail'; + +$services_combo = []; +foreach(kutrl::getServices($core) as $service_id => $service) { + $o = new $service($core); + $services_combo[__($o->name)] = $o->id; +} +$ext_services_combo = array_merge([__('Disabled') => ''], $services_combo); +$lst_services_combo = array_merge(['-' => ''], $services_combo); + +$s_active = (boolean) $s->kutrl_active; +$s_plugin_service = (string) $s->kutrl_plugin_service; +$s_admin_service = (string) $s->kutrl_admin_service; +$s_tpl_service = (string) $s->kutrl_tpl_service; +$s_wiki_service = (string) $s->kutrl_wiki_service; +$s_allow_external_url = (boolean) $s->kutrl_allow_external_url; +$s_tpl_passive = (boolean) $s->kutrl_tpl_passive; +$s_tpl_active = (boolean) $s->kutrl_tpl_active; +$s_admin_entry_default = (string) $s->kutrl_admin_entry_default; + +if (!empty($_POST['save'])) { + try { + # settings + $s_active = !empty($_POST['s_active']); + $s_admin_service = (string) $_POST['s_admin_service']; + $s_plugin_service = (string) $_POST['s_plugin_service']; + $s_tpl_service = (string) $_POST['s_tpl_service']; + $s_wiki_service = (string) $_POST['s_wiki_service']; + $s_allow_external_url = !empty($_POST['s_allow_external_url']); + $s_tpl_passive = !empty($_POST['s_tpl_passive']); + $s_tpl_active = !empty($_POST['s_tpl_active']); + $s_admin_entry_default = !empty($_POST['s_admin_entry_default']); + + $s->put('kutrl_active', $s_active); + $s->put('kutrl_plugin_service', $s_plugin_service); + $s->put('kutrl_admin_service', $s_admin_service); + $s->put('kutrl_tpl_service', $s_tpl_service); + $s->put('kutrl_wiki_service', $s_wiki_service); + $s->put('kutrl_allow_external_url', $s_allow_external_url); + $s->put('kutrl_tpl_passive', $s_tpl_passive); + $s->put('kutrl_tpl_active', $s_tpl_active); + $s->put('kutrl_admin_entry_default', $s_admin_entry_default); + + # services + foreach(kutrl::getServices($core) as $service_id => $service) { + $o = new $service($core); + $o->saveSettings(); + } + + $core->blog->triggerBlog(); + + dcPage::addSuccessNotice( + __('Configuration successfully saved') + ); + + $core->adminurl->redirect( + 'admin.plugins', + ['module' => 'kUtRL', 'conf' => 1, 'chk' => 1, 'redir' => $list->getRedir()] + ); + } catch (Exception $e) { + $core->error->add($e->getMessage()); + } +} + +echo ' +

' . __('Settings') . '

+
+
' . __('Plugin activation') . '
+

+
+ +
+
' . __('Behaviors') . '
+

+

' . __('Not only link started with this blog URL could be shortened.') . '

+

+

' . __('If this extension is disabled and the passive mode is enabled, "kutrl" tags (like EntryKurl) will display long urls instead of nothing on templates.') . '

+

+

' . __('If the active mode is enabled, all know default template tags (like EntryURL) will display short urls instead of long ones on templates.') . '
' . +__('You can disable URL shortening for a specific template tag by adding attribute disable_kutrl="1" to it . ') . '

+

' . __('We strongly discourage using active mode as it crashes public post form and complex url if theme is not customize for kUtRL.') . '

+

+

' . __('This can be changed on page of creation/edition of an entry.') . '

+
+ +
+
' . __('Default services') . '
+

+

' . __('Service to use in this admin page and on edit page of an entry.') . '

+

+

' . __('Service to use on third part plugins.') . '

+

+

' . __('Shorten links automatically when using template value like "EntryKutrl".') . '

+

+

' . __('Shorten links automatically found in contents using wiki synthax.') . '

+
+
+ +
+

' .__('Services') . '

+

' . __('List of services you can use to shorten links with pkugin kUtRL.') . '

+'; + +foreach(kutrl::getServices($core) as $service_id => $service) { + $o = new $service($core); + + echo '
' . $o->name . '
'; + + if (!empty($_REQUEST['chk'])) { + $img_chk = $img_red . ' ' . sprintf(__('Failed to test %s API.'), $o->name); + try { + if ($o->testService()) { + $img_chk = $img_green . ' ' . sprintf(__('%s API is well configured and runing.'), $o->name); + } + } catch (Exception $e) { + $core->error->add(sprintf(__('Failed to test service %s: %s'), $o->name, $e->getMessage())); + } + echo sprintf('

%s

', $img_chk) . $o->error->toHTML(); + } + if ($o->home != '') { + echo '

' . sprintf(__('Learn more about %s.'), $o->name) . '

'; + } + $o->settingsForm(); + + echo '
'; +} + +echo'
'; \ No newline at end of file diff --git a/index.php b/index.php index 5b7129d..d62b001 100644 --- a/index.php +++ b/index.php @@ -18,97 +18,10 @@ if (!defined('DC_CONTEXT_ADMIN')) { # Check user perms dcPage::check('admin'); -# Settings -$s = $core->blog->settings->kUtRL; - -# Default values -$p_url = $core->adminurl->get('admin.plugin.kUtRL'); +$header = ''; $part = isset($_REQUEST['part']) ? $_REQUEST['part'] : 'links'; $action = isset($_POST['action']) ? $_POST['action'] : ''; -# used in setting & links -if (in_array($part, ['setting', 'links'])) { - $services_combo = []; - foreach(kutrl::getServices($core) as $service_id => $service) { - $o = new $service($core); - $services_combo[__($o->name)] = $o->id; - } - $ext_services_combo = array_merge([__('Disabled')=>''], $services_combo); - $lst_services_combo = array_merge(['-'=>''], $services_combo); -} - -# used in setting & service -if (in_array($part, ['setting', 'service'])) { - $img_green = 'ok'; - $img_red = 'fail'; -} - -# setting -if ($part == 'setting') { - $s_active = (boolean) $s->kutrl_active; - $s_plugin_service = (string) $s->kutrl_plugin_service; - $s_admin_service = (string) $s->kutrl_admin_service; - $s_tpl_service = (string) $s->kutrl_tpl_service; - $s_wiki_service = (string) $s->kutrl_wiki_service; - $s_allow_external_url = (boolean) $s->kutrl_allow_external_url; - $s_tpl_passive = (boolean) $s->kutrl_tpl_passive; - $s_tpl_active = (boolean) $s->kutrl_tpl_active; - $s_admin_entry_default = (string) $s->kutrl_admin_entry_default; - - if (!empty($_POST['save'])) { - try { - $s_active = !empty($_POST['s_active']); - $s_admin_service = (string) $_POST['s_admin_service']; - $s_plugin_service = (string) $_POST['s_plugin_service']; - $s_tpl_service = (string) $_POST['s_tpl_service']; - $s_wiki_service = (string) $_POST['s_wiki_service']; - $s_allow_external_url = !empty($_POST['s_allow_external_url']); - $s_tpl_passive = !empty($_POST['s_tpl_passive']); - $s_tpl_active = !empty($_POST['s_tpl_active']); - $s_admin_entry_default = !empty($_POST['s_admin_entry_default']); - - $s->put('kutrl_active', $s_active); - $s->put('kutrl_plugin_service', $s_plugin_service); - $s->put('kutrl_admin_service', $s_admin_service); - $s->put('kutrl_tpl_service', $s_tpl_service); - $s->put('kutrl_wiki_service', $s_wiki_service); - $s->put('kutrl_allow_external_url', $s_allow_external_url); - $s->put('kutrl_tpl_passive', $s_tpl_passive); - $s->put('kutrl_tpl_active', $s_tpl_active); - $s->put('kutrl_admin_entry_default', $s_admin_entry_default); - - $core->blog->triggerBlog(); - - dcPage::addSuccessNotice( - __('Configuration successfully saved') - ); - - http::redirect($p_url . '&part=setting'); - } catch (Exception $e) { - $core->error->add($e->getMessage()); - } - } -} - -# services -if ($part == 'service' && !empty($_POST['save'])) { - try { - foreach(kutrl::getServices($core) as $service_id => $service) { - $o = new $service($core); - $o->saveSettings(); - } - $core->blog->triggerBlog(); - - dcPage::addSuccessNotice( - __('Configuration successfully saved') - ); - - http::redirect($p_url . '&part=service'); - } catch (Exception $e) { - $core->error->add($e->getMessage()); - } -} - # link creation if ($part == 'link') { $kut = kutrl::quickPlace('admin'); @@ -183,10 +96,17 @@ if ($part == 'link') { $core->error->add($e->getMessage()); } } -} # links -if ($part == 'links') { +} else { + $services_combo = []; + foreach(kutrl::getServices($core) as $service_id => $service) { + $o = new $service($core); + $services_combo[__($o->name)] = $o->id; + } + $ext_services_combo = array_merge([__('Disabled')=>''], $services_combo); + $lst_services_combo = array_merge(['-'=>''], $services_combo); + $log = new kutrlLog($core); $kUtRL_filter = new adminGenericFilter($core, 'kUtRL'); @@ -206,6 +126,10 @@ if ($part == 'links') { $core->error->add($e->getMessage()); } + $header = + $kUtRL_filter->js($core->adminurl->get('admin.plugin.kUtRL', ['part' => 'links'])) . + dcPage::jsLoad(dcPage::getPF('kUtRL/js/admin.js')); + if (!empty($_POST['deletelinks'])) { try { foreach($_POST['entries'] as $id) { @@ -233,164 +157,10 @@ if ($part == 'links') { # display header echo -'kUtRL, ' . __('Links shortener') . ''; - -if ($part == 'links') { - echo - $kUtRL_filter->js($core->adminurl->get('admin.plugin.kUtRL', ['part' => 'links'])) . - dcPage::jsLoad(dcPage::getPF('kUtRL/js/admin.js')); -} - -echo +'kUtRL, ' . __('Links shortener') . '' . +$header . ''; -# display setting -if ($part == 'setting') { - echo - dcPage::breadcrumb( - [ - __('Links shortener') => '', - '' . __('Plugin configuration') . '' => '', - __('Services configuration') => $p_url .'&part=service' - ], - ['hl' => false] - ) . - dcPage::notices() . - - '

' . __('Plugin configuration') . '

-

' . __('Back to links list') . '

- -
- -
-

' . __('Plugin activation') . '

-

-
- -
-

' . __('Behaviors') . '

-

-

' . __('Not only link started with this blog URL could be shortened.') . '

-

-

' . __('If this extension is disabled and the passive mode is enabled, "kutrl" tags (like EntryKurl) will display long urls instead of nothing on templates.') . '

-

-

' . __('If the active mode is enabled, all know default template tags (like EntryURL) will display short urls instead of long ones on templates.') . '
' . - __('You can disable URL shortening for a specific template tag by adding attribute disable_kutrl="1" to it . ') . '

-

' . __('We strongly discourage using active mode as it crashes public post form and complex url if theme is not customize for kUtRL.') . '

-

-

' . __('This can be changed on page of creation/edition of an entry.') . '

-
- -
-

' . __('Default services') . '

-

-

' . __('Service to use in this admin page and on edit page of an entry.') . '

-

-

' . __('Service to use on third part plugins.') . '

-

-

' . __('Shorten links automatically when using template value like "EntryKutrl".') . '

-

-

' . __('Shorten links automatically found in contents using wiki synthax.') . '

-
- -

' . - $core->formNonce() . - form::hidden(['part'], 'setting') . ' -

-
'; -} - -# display service -if ($part == 'service') { - echo - dcPage::breadcrumb( - [ - __('Links shortener') => '', - __('Plugin configuration') => $p_url . '&part=setting', - '' . __('Services configuration') . '' => '' - ], - ['hl' => false] - ) . - dcPage::notices() . - - '

' . __('Services configuration') . '

' . - '

' . __('Back to links list') . '

' . - '
'; - - foreach(kutrl::getServices($core) as $service_id => $service) { - $o = new $service($core); - - echo '

' . $o->name . '

'; - - if (!empty($_POST['save'])) { - echo '

' . ( - $o->testService() ? - $img_green . ' ' . sprintf(__('%s API is well configured and runing.'), $o->name) : - $img_red . ' ' . sprintf(__('Failed to test %s API.'), $o->name) - ) . '

'; - //if ($o->error->flag()) { - echo $o->error->toHTML(); - //} - } - if ($o->home != '') { - echo '

' . sprintf(__('Learn more about %s.'), $o->name) . '

'; - } - $o->settingsForm(); - - echo '
'; - } - - echo ' -
-

' . - $core->formNonce() . - form::hidden(['part'], 'service') . ' -

-
'; -} - # display link creation if ($part == 'link') { echo @@ -410,7 +180,7 @@ if ($part == 'link') { echo '

' . sprintf(__('Shorten link using service "%s"'), $kut->name) . '

-
'; } -} - -if ($part == 'links') { +} else { echo dcPage::breadcrumb( [ @@ -454,7 +222,7 @@ if ($part == 'links') { $list_current->display( $kUtRL_filter->value('page'), $kUtRL_filter->nb, - '
+ ' %s @@ -476,12 +244,4 @@ if ($part == 'links') { # display footer dcPage::helpBlock('kUtRL'); -echo -'

-' . __('Plugin configuration') . ' - -' . __('Services configuration') . ' - -kUtRL - ' . $core->plugins->moduleInfo('kUtRL', 'version') . '  - -' . __('kUtRL') . ' -

-'; \ No newline at end of file +echo ''; \ No newline at end of file