diff --git a/CHANGELOG.md b/CHANGELOG.md
index 2065afc..59eba3e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,17 +1,17 @@
todo
- Added public page of the list of know urls and in/visible status
- Added passworded links
-- clean PSR-2 codding style and short array
-- fix php 7.3+ and php 8.0.x compatibility
-- fix compatibility with Dotclear 2.19
- fix widgets rendering
- move setting to config file
- fix dashboard rendering
- fix deprecated external service
-- create readme file
2021.08.27
- add dashboard icon
+- clean PSR-2 codding style and short array
+- fix php 7.3+ and php 8.0.x compatibility
+- fix compatibility with Dotclear 2.19
+- create readme file
2011.04.01
* Changed version numbering
diff --git a/_prepend.php b/_prepend.php
index 70d3be7..70abb77 100644
--- a/_prepend.php
+++ b/_prepend.php
@@ -42,6 +42,7 @@ $d = dirname(__FILE__) . '/inc/';
$__autoload['kutrl'] = $d . 'class.kutrl.php';
$__autoload['kutrlService'] = $d . 'lib.kutrl.srv.php';
$__autoload['kutrlLog'] = $d . 'lib.kutrl.log.php';
+$__autoload['kutrlLinksList'] = $d . 'lib.kutrl.lst.php';
# Services
$__autoload['bilbolinksKutrlService'] = $d . 'services/class.bilbolinks.service.php';
diff --git a/dcstore.xml b/dcstore.xml
new file mode 100644
index 0000000..ab3a5d3
--- /dev/null
+++ b/dcstore.xml
@@ -0,0 +1,13 @@
+
' . __('You must set an admin service.') . '
'; -} else { - echo ' - '; -} -dcPage::helpBlock('kUtRL'); -echo $footer . ''; \ No newline at end of file diff --git a/inc/index.links.php b/inc/index.links.php deleted file mode 100644 index a2535b1..0000000 --- a/inc/index.links.php +++ /dev/null @@ -1,264 +0,0 @@ -rs->isEmpty()) { - echo '' . __('No short link') . '
'; - } else { - $pager = new pager($page, $this->rs_count, $nb_per_page, 10); - - $pager->base_url = $url; - - $html_block = - '' . __('Hash') . ' | ' . - '' . __('Link') . ' | ' . - '' . __('Date') . ' | ' . - '' . __('Service') . ' | ' . - '
---|
' . __('Page(s)') . ' : ' . $pager->getLinks() . '
'; - $blocks = explode('%s', $html_block); - echo $blocks[0]; - - $this->rs->index(((integer)$page - 1) * $nb_per_page); - $iter = 0; - while ($iter < $nb_per_page) { - - echo $this->line($url,$iter); - - if ($this->rs->isEnd()) { - break; - } else { - $this->rs->moveNext(); - } - $iter++; - } - echo $blocks[1]; - echo '' . __('Page(s)') . ' : ' . $pager->getLinks() . '
'; - } - } - - private function line($url, $loop) - { - $type = $this->rs->kut_type; - $hash = $this->rs->kut_hash; - - if (null !== ($o = kutrl::quickService($this->rs->kut_type))) { - $type = '' . $o->name . ''; - $hash = '' . $hash . ''; - } - - return - '' . __('No short link') . '
'; + } else { + $pager = new pager($page, $this->rs_count, $nb_per_page, 10); + + $pager->base_url = $url; + + $html_block = + '' . __('Hash') . ' | ' . + '' . __('Link') . ' | ' . + '' . __('Date') . ' | ' . + '' . __('Service') . ' | ' . + '
---|
' . __('Page(s)') . ' : ' . $pager->getLinks() . '
'; + $blocks = explode('%s', $html_block); + echo $blocks[0]; + + $this->rs->index(((integer)$page - 1) * $nb_per_page); + $iter = 0; + while ($iter < $nb_per_page) { + + echo $this->line($url,$iter); + + if ($this->rs->isEnd()) { + break; + } else { + $this->rs->moveNext(); + } + $iter++; + } + echo $blocks[1]; + echo '' . __('Page(s)') . ' : ' . $pager->getLinks() . '
'; + } + } + + private function line($url, $loop) + { + $type = $this->rs->kut_type; + $hash = $this->rs->kut_hash; + + if (null !== ($o = kutrl::quickService($this->rs->kut_type))) { + $type = '' . $o->name . ''; + $hash = '' . $hash . ''; + } + + return + '' . __('There are two templates delivered with kUtRL, if you do not use default theme, you may adapt them to yours.') . '
' .
__('Files are in plugin directory /default-templates, just copy them into your theme and edit them.') . '
-' . __('Settings') . ' - -' . __('Services') . ' - -kUtRL - ' . $core->plugins->moduleInfo('kUtRL','version') . ' - -
'; - -# Messages -$msg = isset($_REQUEST['msg']) ? $_REQUEST['msg'] : ''; -$msg_list = [ - 'savesetting' => __('Configuration successfully saved'), - 'saveservice' => __('Services successfully updated'), - 'createlink' => __('Link successfully shorten'), - 'deletelinks' => __('Links successfully deleted') -]; -if (isset($msg_list[$msg])) { - $msg = sprintf(' ', $msg_list[$msg]); +# 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); } -# Pages -$start_part = $s->kutrl_active ? 'links' : 'setting'; -$default_part = isset($_REQUEST['part']) ? $_REQUEST['part'] : $start_part; - -if (!file_exists(dirname(__FILE__) . '/inc/index.' . $default_part . '.php')) { - $default_part = 'setting'; +# used in setting & service +if (in_array($part, ['setting', 'service'])) { + $img_green = ''; + $img_red = ''; } -include dirname(__FILE__) . '/inc/index.' . $default_part . '.php'; \ No newline at end of file + +# 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'); + + if (!empty($_POST['save'])) { + try { + if (null === $kut) { + throw new Exception('Unknow service'); + } + $url = trim($core->con->escape($_POST['str'])); + $hash = empty($_POST['custom']) ? null : $_POST['custom']; + + if (empty($url)) { + throw new Exception(__('There is nothing to shorten.')); + } + if (!$kut->testService()) { + throw new Exception(__('Service is not well configured.')); + } + if (null !== $hash && !$kut->allow_custom_hash) { + throw new Exception(__('This service does not allowed custom hash.')); + } + if (!$kut->isValidUrl($url)) { + throw new Exception(__('This link is not a valid URL.')); + } + if (!$kut->isLongerUrl($url)) { + throw new Exception(__('This link is too short.')); + } + if (!$kut->isProtocolUrl($url)) { + throw new Exception(__('This type of link is not allowed.')); + } + if (!$kut->allow_external_url && !$kut->isBlogUrl($url)) { + throw new Exception(__('Short links are limited to this blog URL.')); + } + if ($kut->isServiceUrl($url)) { + throw new Exception(__('This link is already a short link.')); + } + if (null !== $hash && false !== ($rs = $kut->isKnowHash($hash))) { + throw new Exception(__('This custom short url is already taken.')); + } + if (false !== ($rs = $kut->isKnowUrl($url))) { + $url = $rs->url; + $new_url = $kut->url_base .$rs->hash; + + dcPage::addSuccessNotice(sprintf( + __('Short link for %s is %s'), + '' . html::escapeHTML($url) . '', + '' . $new_url . '' + )); + } else { + if (false === ($rs = $kut->hash($url, $hash))) { + if ($kut->error->flag()) { + throw new Exception($kut->error->toHTML()); + } + throw new Exception(__('Failed to create short link. This could be caused by a service failure.')); + } else { + $url = $rs->url; + $new_url = $kut->url_base . $rs->hash; + + dcPage::addSuccessNotice(sprintf( + __('Short link for %s is %s'), + '' . html::escapeHTML($url) . '', + '' . $new_url . '' + )); + + # ex: Send new url to messengers + if (!empty($rs)) { + $core->callBehavior('adminAfterKutrlCreate', $core, $rs,__('New short URL')); + } + } + } + } catch (Exception $e) { + $core->error->add($e->getMessage()); + } + } +} + +# links +if ($part == 'links') { + $log = new kutrlLog($core); + + $sortby_combo = [ + __('Date') => 'kut_dt', + __('Long link') => 'kut_url', + __('Short link') => 'kut_hash' + ]; + $order_combo = [ + __('Descending') => 'desc', + __('Ascending') => 'asc' + ]; + + $core->auth->user_prefs->addWorkspace('interface'); + $default_sortby = 'kut_dt'; + $default_order = $core->auth->user_prefs->interface->posts_order ?: 'desc'; + $nb_per_page = $core->auth->user_prefs->interface->nb_posts_per_page ?: 30; + $sortby = !empty($_GET['sortby']) ? $_GET['sortby'] : $default_sortby; + $order = !empty($_GET['order']) ? $_GET['order'] : $default_order; + $urlsrv = !empty($_GET['urlsrv']) ? $_GET['urlsrv'] : ''; + $page = !empty($_GET['page']) ? max(1, (integer) $_GET['page']) : 1; + $show_filters = false; + + if (!empty($_GET['nb']) && (integer) $_GET['nb'] > 0) { + if ($nb_per_page != (integer) $_GET['nb']) { + $show_filters = true; + } + $nb_per_page = (integer) $_GET['nb']; + } + + $params = []; + $params['limit'] = [(($page-1)*$nb_per_page), $nb_per_page]; + + if (!in_array($sortby, $sortby_combo)) { + $sortby = $default_sortby; + } + + if (!in_array($order, $order_combo)) { + $order = $default_order; + } + $params['order'] = $sortby . ' ' . $order; + + if ($urlsrv != '' && in_array($urlsrv, $lst_services_combo)) { + $params['kut_type'] = $urlsrv; + } + + if ($sortby != $default_sortby || $order != $default_order || $urlsrv != '') { + $show_filters = true; + } + + $pager_base_url = + $p_url . + '&urlsrv=' . $urlsrv . + '&sortby=' . $sortby . + '&order=' . $order . + '&nb=' . $nb_per_page . + '&page=%s'; + + try { + $list_all = $log->getLogs($params); + $list_counter = $log->getLogs($params, true)->f(0); + $list_current = new kutrlLinksList($core, $list_all, $list_counter); + } catch (Exception $e) { + $core->error->add($e->getMessage()); + } + + if (!empty($_POST['deletelinks'])) { + try { + foreach($_POST['entries'] as $id) { + $rs = $log->getLogs(['kut_id' => $id]); + if ($rs->isEmpty()) { + continue; + } + if (null === ($o = kutrl::quickService($rs->kut_type))) { + continue; + } + $o->remove($rs->kut_url); + } + + $core->blog->triggerBlog(); + + dcPage::addSuccessNotice( + __('Links successfully deleted') + ); + + http::redirect($p_url . '&part=links&urlsrv=' . $urlsrv . '&sortby=' . $sortby . '&order=' . $order . '&nb=' . $nb_per_page . '&page=' . $page); + } catch (Exception $e) { + $core->error->add($e->getMessage()); + } + } +} + +# display header +echo +'' . __('Back to links list') . '
+ + '; +} + +# display service +if ($part == 'service') { + echo + dcPage::breadcrumb( + [ + __('Links shortener') => '', + __('Plugin configuration') => $p_url . '&part=setting', + '' . __('Services configuration') . '' => '' + ], + ['hl' => false] + ) . + dcPage::notices() . + + '' . __('Back to links list') . '
'; + ''; +} + +# display link creation +if ($part == 'link') { + echo + dcPage::breadcrumb( + [ + __('Links shortener') => '', + __('Links') => $core->adminurl->get('admin.plugin.kUtRL'), + '' . __('New link') . '' => '' + ], + ['hl' => false] + ) . + dcPage::notices(); + + if (null === $kut) { + echo '' . __('You must set an admin service.') . '
'; + } else { + echo ' ++' . __('Plugin configuration') . ' - +' . __('Services configuration') . ' - +kUtRL - ' . $core->plugins->moduleInfo('kUtRL', 'version') . ' + + +
+'; \ No newline at end of file diff --git a/js/admin.js b/js/admin.js deleted file mode 100644 index e8101b4..0000000 --- a/js/admin.js +++ /dev/null @@ -1,15 +0,0 @@ -/* -- BEGIN LICENSE BLOCK ---------------------------------- - * This file is part of kUtRL, a plugin for Dotclear 2. - * - * Copyright (c) 2009-2011 JC Denis and contributors - * jcdenis@gdwd.com - * - * Licensed under the GPL version 2.0 license. - * A copy of this license is available in LICENSE file or at - * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html - * -- END LICENSE BLOCK ------------------------------------*/ - -$(function(){ - /* toogle admin form sidebar */ - $('#kutrl-form-title').toggleWithLegend($('#kutrl-form-content'),{cookie:'dcx_kutrl_admin_form_sidebar'}); -}); \ No newline at end of file diff --git a/js/main.js b/js/main.js deleted file mode 100644 index 8d0d5c9..0000000 --- a/js/main.js +++ /dev/null @@ -1,80 +0,0 @@ -/* -- BEGIN LICENSE BLOCK ---------------------------------- - * This file is part of kUtRL, a plugin for Dotclear 2. - * - * Copyright (c) 2009-2011 JC Denis and contributors - * jcdenis@gdwd.com - * - * Licensed under the GPL version 2.0 license. - * A copy of this license is available in LICENSE file or at - * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html - * -- END LICENSE BLOCK ------------------------------------*/ - -$(function(){ - /* tools */ - dotclear.jcTools = new jcToolsBox(); - /* wait message */ - $('#content').submit(function(){dotclear.jcTools.waitMessage();return true;}); -}); - -function jcToolsBox(){} - -jcToolsBox.prototype={ - text_wait:'Please wait', - section:'', - - formFieldsetToMenu:function(form){ - var This=this; - var section=$(form).children('fieldset[id='+This.section+']').attr('id'); - var hidden_section=$(form).children('input[name=section]').attr('value'); - var formMenu=$(form).children('p.formMenu').get(0); - if (formMenu==undefined) { - $(form).prepend($('').addClass('formMenu')); - } - $(form).children('fieldset').each(function(){ - var Fieldset=this; - $(Fieldset).hide(); - var title=$(Fieldset).children('legend').text(); - var menu=$('').text(title).addClass('button').attr('tabindex','2').click( - function(){ - var fieldset_visible=$(form).children('fieldset:visible'); - if (fieldset_visible==undefined){ - $(Fieldset).slideDown('slow');$(form).children('input[type=submit]').show(); - }else{ - $(fieldset_visible).fadeOut('fast',function(){$(Fieldset).fadeIn('fast');$(form).children('input[type=submit]').show();}) - } - if (hidden_section==undefined){ - $(form).children('input[name=section]').remove(); - $(form).append($('').attr('name','section').attr('value',$(Fieldset).attr('id'))); - } - $('.message').fadeOut('slow',function(){$(this).slideUp('slow',function(){$(this).remove();})}); - } - ); - $(form).children('.formMenu').append(menu).append(' '); - }); - if (section!=undefined){ - $(form).children('fieldset[id='+section+']').show(); - }else{ - $(form).children('fieldset:first').show(); - } - }, - - waitMessage:function(){ - var This=this; - var content=$('div[id=content]'); - if (content!=undefined){ - $(content).hide(); - }else{ - $('input').hide();$('select').hide(); - content=$('body'); - } - var text=$('').addClass('message').text(This.text_wait); - This.blinkItem(text); - var box=$('').attr('style','margin: 60px auto auto;width:200px;').append(text); - $(content).before($(box)); - }, - - blinkItem:function(item){ - var This=this; - $(item).fadeOut('slow',function(){$(this).fadeIn('slow',function(){This.blinkItem(this);})}); - } -} \ No newline at end of file diff --git a/js/service.js b/js/service.js deleted file mode 100644 index ec78b52..0000000 --- a/js/service.js +++ /dev/null @@ -1,17 +0,0 @@ -/* -- BEGIN LICENSE BLOCK ---------------------------------- - * This file is part of kUtRL, a plugin for Dotclear 2. - * - * Copyright (c) 2009-2011 JC Denis and contributors - * jcdenis@gdwd.com - * - * Licensed under the GPL version 2.0 license. - * A copy of this license is available in LICENSE file or at - * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html - * -- END LICENSE BLOCK ------------------------------------*/ - -$(function() { - var kutrlForm=$('#service-form'); - if (kutrlForm!=undefined){ - dotclear.jcTools.formFieldsetToMenu(kutrlForm); - } -}); \ No newline at end of file diff --git a/js/setting.js b/js/setting.js deleted file mode 100644 index b450278..0000000 --- a/js/setting.js +++ /dev/null @@ -1,17 +0,0 @@ -/* -- BEGIN LICENSE BLOCK ---------------------------------- - * This file is part of kUtRL, a plugin for Dotclear 2. - * - * Copyright (c) 2009-2011 JC Denis and contributors - * jcdenis@gdwd.com - * - * Licensed under the GPL version 2.0 license. - * A copy of this license is available in LICENSE file or at - * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html - * -- END LICENSE BLOCK ------------------------------------*/ - -$(function() { - var kutrlForm=$('#setting-form'); - if (kutrlForm!=undefined){ - dotclear.jcTools.formFieldsetToMenu(kutrlForm); - } -}); \ No newline at end of file