diff --git a/CHANGELOG.md b/CHANGELOG.md index 62c15ba..2065afc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,13 +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 compatibility with Dotclear 2.19 - - fix widgets rendering - - move setting to config file - - fix dashboard rendering - - fix deprecated external service - - create readme file +- 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 2011.04.01 * Changed version numbering diff --git a/_admin.php b/_admin.php index c6f5db3..0c2f6ff 100644 --- a/_admin.php +++ b/_admin.php @@ -10,305 +10,315 @@ # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html # -- END LICENSE BLOCK ------------------------------------ -if (!defined('DC_CONTEXT_ADMIN')){return;} +if (!defined('DC_CONTEXT_ADMIN')) { + return null; +} -require_once dirname(__FILE__).'/_widgets.php'; +require_once dirname(__FILE__) . '/_widgets.php'; # Plugin menu $_menu['Plugins']->addItem( - __('Links shortener'), - 'plugin.php?p=kUtRL','index.php?pf=kUtRL/icon.png', - preg_match('/plugin.php\?p=kUtRL(&.*)?$/',$_SERVER['REQUEST_URI']), - $core->auth->check('admin',$core->blog->id) -); + __('Links shortener'), + $core->adminurl->get('admin.plugin.kUtRL'), + dcPage::getPF('kUtRL/icon.png'), + preg_match('/' . preg_quote($core->adminurl->get('admin.plugin.kUtRL')) . '(&.*)?$/', $_SERVER['REQUEST_URI']), + $core->auth->check('admin', $core->blog->id)); # Admin behaviors -if ($core->blog->settings->kUtRL->kutrl_active) -{ - $core->addBehavior('adminPostHeaders',array('adminKutrl','adminPostHeaders')); - $core->addBehavior('adminPostFormSidebar',array('adminKutrl','adminPostFormSidebar')); - $core->addBehavior('adminAfterPostUpdate',array('adminKutrl','adminAfterPostUpdate')); // update existing short url - $core->addBehavior('adminAfterPostUpdate',array('adminKutrl','adminAfterPostCreate')); // create new short url - $core->addBehavior('adminAfterPostCreate',array('adminKutrl','adminAfterPostCreate')); - $core->addBehavior('adminBeforePostDelete',array('adminKutrl','adminBeforePostDelete')); - $core->addBehavior('adminPostsActionsCombo',array('adminKutrl','adminPostsActionsCombo')); - $core->addBehavior('adminPostsActions',array('adminKutrl','adminPostsActions')); +if ($core->blog->settings->kUtRL->kutrl_active) { + $core->addBehavior('adminDashboardFavorites', ['adminKutrl', 'antispamDashboardFavorites']); + $core->addBehavior('adminPostHeaders', ['adminKutrl', 'adminPostHeaders']); + $core->addBehavior('adminPostFormSidebar', ['adminKutrl', 'adminPostFormSidebar']); + $core->addBehavior('adminAfterPostUpdate', ['adminKutrl', 'adminAfterPostUpdate']); // update existing short url + $core->addBehavior('adminAfterPostUpdate', ['adminKutrl', 'adminAfterPostCreate']); // create new short url + $core->addBehavior('adminAfterPostCreate', ['adminKutrl', 'adminAfterPostCreate']); + $core->addBehavior('adminBeforePostDelete', ['adminKutrl', 'adminBeforePostDelete']); + $core->addBehavior('adminPostsActionsCombo', ['adminKutrl', 'adminPostsActionsCombo']); + $core->addBehavior('adminPostsActions', ['adminKutrl', 'adminPostsActions']); } -$core->addBehavior('exportFull',array('backupKutrl','exportFull')); -$core->addBehavior('exportSingle',array('backupKutrl','exportSingle')); -$core->addBehavior('importInit',array('backupKutrl','importInit')); -$core->addBehavior('importSingle',array('backupKutrl','importSingle')); -$core->addBehavior('importFull',array('backupKutrl','importFull')); +$core->addBehavior('exportFull', ['backupKutrl', 'exportFull']); +$core->addBehavior('exportSingle', ['backupKutrl', 'exportSingle']); +$core->addBehavior('importInit', ['backupKutrl', 'importInit']); +$core->addBehavior('importSingle', ['backupKutrl', 'importSingle']); +$core->addBehavior('importFull', ['backupKutrl', 'importFull']); # Admin behaviors class class adminKutrl { - public static function adminPostHeaders() - { - return dcPage::jsLoad('index.php?pf=kUtRL/js/admin.js'); - } - - public static function adminPostFormSidebar($post) - { - global $core; - $s = $core->blog->settings->kUtRL; - - if (!$s->kutrl_active || !$s->kutrl_admin_service) return; - - if (null === ($kut = kutrl::quickPlace('admin'))) return; - - if ($post) - { - $post_url = $post->getURL(); - $rs = $kut->isKnowUrl($post_url); - } - else - { - $post_url = ''; - $rs = false; - } - - echo - '

'.__('Short link').'

'. - '
'. - form::hidden(array('kutrl_old_post_url'),$post_url); - - if (!$rs) - { - if (empty($_POST['kutrl_old_post_url']) && $s->kutrl_admin_entry_default) - { - $chk = true; - } - else - { - $chk = !empty($_POST['kutrl_create']); - } - echo - '

'; - - if ($kut->allow_custom_hash) - { - echo - '

'. - '

'; - } - } - else - { - $count = $rs->counter; - if ($count == 0) - { - $title = __('never followed'); - } - elseif ($count == 1) - { - $title = __('followed one time'); - } - else - { - $title = sprintf(__('followed %s times'),$count); - } - $href = $kut->url_base.$rs->hash; - - echo - '

'. - '

'.$href.'

'; - } - echo '
'; - } - - public static function adminAfterPostUpdate($cur,$post_id) - { - global $core; - $s = $core->blog->settings->kUtRL; - - # Create: see adminAfterPostCreate - if (!empty($_POST['kutrl_create']) || !$s->kutrl_active) return; - - if (null === ($kut = kutrl::quickPlace('admin'))) return; - - if (empty($_POST['kutrl_old_post_url'])) return; - - $old_post_url = $_POST['kutrl_old_post_url']; - - if (!($rs = $kut->isKnowUrl($old_post_url))) return; - - $rs = $core->blog->getPosts(array('post_id'=>$post_id)); - $title = html::escapeHTML($rs->post_title); - - if ($rs->isEmpty()) return; - - $new_post_url = $rs->getURL(); - - # Delete - if (!empty($_POST['kutrl_delete'])) - { - $kut->remove($old_post_url); - } - # Update - else - { - if ($old_post_url == $new_post_url) return; - - $kut->remove($old_post_url); - - $rs = $kut->hash($new_post_url,$custom); // better to update (not yet implemented) - $url = $kut->url_base.$rs->hash; - - # ex: Send new url to messengers - if (!empty($rs)) - { - $core->callBehavior('adminAfterKutrlCreate',$core,$rs,$title); - } - } - } - - public static function adminAfterPostCreate($cur,$post_id) - { - global $core; - $s = $core->blog->settings->kUtRL; - - if (empty($_POST['kutrl_create']) || !$s->kutrl_active) return; - - if (null === ($kut = kutrl::quickPlace('admin'))) return; - - $rs = $core->blog->getPosts(array('post_id'=>$post_id)); - $title = html::escapeHTML($rs->post_title); - - if ($rs->isEmpty()) return; - - $custom = !empty($_POST['kutrl_create_custom']) && $kut->allow_custom_hash ? - $_POST['kutrl_create_custom'] : null; - - $rs = $kut->hash($rs->getURL(),$custom); - $url = $kut->url_base.$rs->hash; - - # ex: Send new url to messengers - if (!empty($rs)) - { - $core->callBehavior('adminAfterKutrlCreate',$core,$rs,$title); - } - } - - public static function adminBeforePostDelete($post_id) - { - global $core; - $s = $core->blog->settings->kUtRL; - - if (!$s->kutrl_active) return; - - if (null === ($kut = kutrl::quickPlace('admin'))) return; - - $rs = $core->blog->getPosts(array('post_id'=>$post_id)); - - if ($rs->isEmpty()) return; - - $kut->remove($rs->getURL()); - } - - public static function adminPostsActionsCombo($args) - { - global $core; - $s = $core->blog->settings->kUtRL; - - if (!$s->kutrl_active - || !$core->auth->check('admin',$core->blog->id)) return; - - $args[0][__('kUtRL')][__('create short link')] = 'kutrl_create'; - $args[0][__('kUtRL')][__('delete short link')] = 'kutrl_delete'; - } + public static function antispamDashboardFavorites(dcCore $core, $favs) + { + $favs->register( + 'kUtRL', + [ + 'title' => __('Links shortener'), + 'url' => $core->adminurl->get('admin.plugin.kUtRL'), + 'small-icon' => dcPage::getPF('kUtRL/icon.png'), + 'large-icon' => dcPage::getPF('kUtRL/icon-b.png'), + 'permissions' => 'admin' + ] + ); + } - public static function adminPostsActions($core,$posts,$action,$redir) - { - if ($action != 'kutrl_create' - && $action != 'kutrl_delete') return; - - $s = $core->blog->settings->kUtRL; - - if (!$s->kutrl_active) return; - - if (null === ($kut = kutrl::quickPlace('admin'))) return; - - while ($posts->fetch()) - { - $url = $posts->getURL(); - - if ($action == 'kutrl_create') - { - $kut->hash($url); - } - - if ($action == 'kutrl_delete') - { - $kut->remove($url); - } - } - $core->blog->triggerBlog(); - http::redirect($redir.'&done=1'); - } + public static function adminPostHeaders() + { + return dcPage::jsLoad('index.php?pf=kUtRL/js/admin.js'); + } + + public static function adminPostFormSidebar($post) + { + global $core; + $s = $core->blog->settings->kUtRL; + + if (!$s->kutrl_active || !$s->kutrl_admin_service) { + return null; + } + if (null === ($kut = kutrl::quickPlace('admin'))) { + return null; + } + + if ($post) { + $post_url = $post->getURL(); + $rs = $kut->isKnowUrl($post_url); + } else { + $post_url = ''; + $rs = false; + } + + echo + '

' . __('Short link') . '

' . + '
' . + form::hidden(['kutrl_old_post_url'], $post_url); + + if (!$rs) { + if (empty($_POST['kutrl_old_post_url']) && $s->kutrl_admin_entry_default) { + $chk = true; + } else { + $chk = !empty($_POST['kutrl_create']); + } + echo + '

'; + + if ($kut->allow_custom_hash) { + echo + '

' . + '

'; + } + } else { + $count = $rs->counter; + if ($count == 0) { + $title = __('never followed'); + } elseif ($count == 1) { + $title = __('followed one time'); + } else { + $title = sprintf(__('followed %s times'),$count); + } + $href = $kut->url_base . $rs->hash; + + echo + '

' . + '

' . $href . '

'; + } + echo '
'; + } + + public static function adminAfterPostUpdate($cur, $post_id) + { + global $core; + $s = $core->blog->settings->kUtRL; + + # Create: see adminAfterPostCreate + if (!empty($_POST['kutrl_create']) || !$s->kutrl_active) { + return null; + } + if (null === ($kut = kutrl::quickPlace('admin'))) { + return null; + } + if (empty($_POST['kutrl_old_post_url'])) { + return null; + } + + $old_post_url = $_POST['kutrl_old_post_url']; + + if (!($rs = $kut->isKnowUrl($old_post_url))) { + return null; + } + + $rs = $core->blog->getPosts(['post_id' => $post_id]); + if ($rs->isEmpty()) { + return null; + } + $title = html::escapeHTML($rs->post_title); + $new_post_url = $rs->getURL(); + + # Delete + if (!empty($_POST['kutrl_delete'])) { + $kut->remove($old_post_url); + # Update + } else { + if ($old_post_url == $new_post_url) { + return null; + } + + $kut->remove($old_post_url); + + $rs = $kut->hash($new_post_url, $custom); // better to update (not yet implemented) + $url = $kut->url_base . $rs->hash; + + # ex: Send new url to messengers + if (!empty($rs)) { + $core->callBehavior('adminAfterKutrlCreate' ,$core, $rs, $title); + } + } + } + + public static function adminAfterPostCreate($cur, $post_id) + { + global $core; + $s = $core->blog->settings->kUtRL; + + if (empty($_POST['kutrl_create']) || !$s->kutrl_active) { + return null; + } + if (null === ($kut = kutrl::quickPlace('admin'))) { + return null; + } + + $rs = $core->blog->getPosts(['post_id' => $post_id]); + if ($rs->isEmpty()) { + return null; + } + $title = html::escapeHTML($rs->post_title); + + $custom = !empty($_POST['kutrl_create_custom']) && $kut->allow_custom_hash ? + $_POST['kutrl_create_custom'] : null; + + $rs = $kut->hash($rs->getURL(), $custom); + $url = $kut->url_base . $rs->hash; + + # ex: Send new url to messengers + if (!empty($rs)) { + $core->callBehavior('adminAfterKutrlCreate', $core, $rs, $title); + } + } + + public static function adminBeforePostDelete($post_id) + { + global $core; + $s = $core->blog->settings->kUtRL; + + if (!$s->kutrl_active) { + return null; + } + if (null === ($kut = kutrl::quickPlace('admin'))) { + return null; + } + + $rs = $core->blog->getPosts(['post_id' => $post_id]); + if ($rs->isEmpty()) { + return null; + } + + $kut->remove($rs->getURL()); + } + + public static function adminPostsActionsCombo($args) + { + global $core; + $s = $core->blog->settings->kUtRL; + + if (!$s->kutrl_active + || !$core->auth->check('admin',$core->blog->id)) { + return null; + } + + $args[0][__('kUtRL')][__('create short link')] = 'kutrl_create'; + $args[0][__('kUtRL')][__('delete short link')] = 'kutrl_delete'; + } + + public static function adminPostsActions(dcCore $core, $posts, $action, $redir) + { + if ($action != 'kutrl_create' + && $action != 'kutrl_delete') { + return null; + } + $s = $core->blog->settings->kUtRL; + if (!$s->kutrl_active) { + return null; + } + if (null === ($kut = kutrl::quickPlace('admin'))) { + return null; + } + + while ($posts->fetch()) { + $url = $posts->getURL(); + + if ($action == 'kutrl_create') { + $kut->hash($url); + } + if ($action == 'kutrl_delete') { + $kut->remove($url); + } + } + $core->blog->triggerBlog(); + http::redirect($redir . '&done=1'); + } } # Import/export behaviors for Import/export plugin class backupKutrl { - public static function exportSingle($core,$exp,$blog_id) - { - $exp->export('kutrl', - 'SELECT kut_id, blog_id, kut_service, kut_type, '. - 'kut_hash, kut_url, kut_dt, kut_password, kut_counter '. - 'FROM '.$core->prefix.'kutrl '. - "WHERE blog_id = '".$blog_id."' " - ); - } - - public static function exportFull($core,$exp) - { - $exp->exportTable('kutrl'); - } - - public static function importInit($bk,$core) - { - $bk->cur_kutrl = $core->con->openCursor($core->prefix.'kutrl'); - $bk->kutrl = new kutrlLog($core); - } - - public static function importSingle($line,$bk,$core) - { - if ($line->__name == 'kutrl') - { - # Do nothing if str/type exists ! - if (false === $bk->kutrl->select($line->kut_url,$line->kut_hash,$line->kut_type,$line->kut_service)) - { - $bk->kutrl->insert($line->kut_url,$line->kut_hash,$line->kut_type,$line->kut_service); - } - } - } - - public static function importFull($line,$bk,$core) - { - if ($line->__name == 'kutrl') - { - $bk->cur_kutrl->clean(); - - $bk->cur_kutrl->kut_id = (integer) $line->kut_id; - $bk->cur_kutrl->blog_id = (string) $line->blog_id; - $bk->cur_kutrl->kut_service = (string) $line->kut_service; - $bk->cur_kutrl->kut_type = (string) $line->kut_type; - $bk->cur_kutrl->kut_hash = (string) $line->kut_hash; - $bk->cur_kutrl->kut_url = (string) $line->kut_url; - $bk->cur_kutrl->kut_dt = (string) $line->miniurl_dt; - $bk->cur_kutrl->kut_counter = (integer) $line->kut_counter; - $bk->cur_kutrl->kut_password = (string) $line->kut_password; - - $bk->cur_kutrl->insert(); - } - } -} -?> \ No newline at end of file + public static function exportSingle($core, $exp, $blog_id) + { + $exp->export('kutrl', + 'SELECT kut_id, blog_id, kut_service, kut_type, ' . + 'kut_hash, kut_url, kut_dt, kut_password, kut_counter ' . + 'FROM ' . $core->prefix . 'kutrl ' . + "WHERE blog_id = '" . $blog_id . "' " + ); + } + + public static function exportFull($core, $exp) + { + $exp->exportTable('kutrl'); + } + + public static function importInit($bk, $core) + { + $bk->cur_kutrl = $core->con->openCursor($core->prefix . 'kutrl'); + $bk->kutrl = new kutrlLog($core); + } + + public static function importSingle($line,$bk,$core) + { + if ($line->__name == 'kutrl') { + # Do nothing if str/type exists ! + if (false === $bk->kutrl->select($line->kut_url, $line->kut_hash, $line->kut_type, $line->kut_service)) { + $bk->kutrl->insert($line->kut_url, $line->kut_hash, $line->kut_type, $line->kut_service); + } + } + } + + public static function importFull($line, $bk, $core) + { + if ($line->__name == 'kutrl') { + $bk->cur_kutrl->clean(); + $bk->cur_kutrl->kut_id = (integer) $line->kut_id; + $bk->cur_kutrl->blog_id = (string) $line->blog_id; + $bk->cur_kutrl->kut_service = (string) $line->kut_service; + $bk->cur_kutrl->kut_type = (string) $line->kut_type; + $bk->cur_kutrl->kut_hash = (string) $line->kut_hash; + $bk->cur_kutrl->kut_url = (string) $line->kut_url; + $bk->cur_kutrl->kut_dt = (string) $line->miniurl_dt; + $bk->cur_kutrl->kut_counter = (integer) $line->kut_counter; + $bk->cur_kutrl->kut_password = (string) $line->kut_password; + $bk->cur_kutrl->insert(); + } + } +} \ No newline at end of file diff --git a/_define.php b/_define.php index 21cd67d..f75b010 100644 --- a/_define.php +++ b/_define.php @@ -18,13 +18,13 @@ $this->registerModule( 'kUtRL', 'Use, create and serve short url on your blog', 'Jean-Christian Denis and contributors', - '2011.03.24', + '2021.08.27', [ 'permissions' => 'admin', 'type' => 'plugin', 'dc_min' => '2.19', 'support' => 'https://github.com/JcDenis/kUtRL', 'details' => 'http://plugins.dotaddict.org/dc2/details/kUtRL', - 'repository' => 'https://raw.githubusercontent.com/JcDenis/kUtRL/master/repository.xml' + 'repository' => 'https://raw.githubusercontent.com/JcDenis/kUtRL/master/dcstore.xml' ] ); \ No newline at end of file