cleanup admin file and add dashboard icon

master
Jean-Christian Paul Denis 2021-08-27 22:52:24 +02:00
parent ab0217fb89
commit be3d060e51
3 changed files with 309 additions and 295 deletions

View File

@ -2,6 +2,7 @@ todo
- Added public page of the list of know urls and in/visible status - Added public page of the list of know urls and in/visible status
- Added passworded links - Added passworded links
- clean PSR-2 codding style and short array - 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 compatibility with Dotclear 2.19
- fix widgets rendering - fix widgets rendering
- move setting to config file - move setting to config file
@ -9,6 +10,9 @@ todo
- fix deprecated external service - fix deprecated external service
- create readme file - create readme file
2021.08.27
- add dashboard icon
2011.04.01 2011.04.01
* Changed version numbering * Changed version numbering
* Added service su.pr (stumbleUpon) * Added service su.pr (stumbleUpon)

View File

@ -10,40 +10,56 @@
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
# -- END LICENSE BLOCK ------------------------------------ # -- 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 # Plugin menu
$_menu['Plugins']->addItem( $_menu['Plugins']->addItem(
__('Links shortener'), __('Links shortener'),
'plugin.php?p=kUtRL','index.php?pf=kUtRL/icon.png', $core->adminurl->get('admin.plugin.kUtRL'),
preg_match('/plugin.php\?p=kUtRL(&.*)?$/',$_SERVER['REQUEST_URI']), dcPage::getPF('kUtRL/icon.png'),
$core->auth->check('admin',$core->blog->id) preg_match('/' . preg_quote($core->adminurl->get('admin.plugin.kUtRL')) . '(&.*)?$/', $_SERVER['REQUEST_URI']),
); $core->auth->check('admin', $core->blog->id));
# Admin behaviors # Admin behaviors
if ($core->blog->settings->kUtRL->kutrl_active) if ($core->blog->settings->kUtRL->kutrl_active) {
{ $core->addBehavior('adminDashboardFavorites', ['adminKutrl', 'antispamDashboardFavorites']);
$core->addBehavior('adminPostHeaders',array('adminKutrl','adminPostHeaders')); $core->addBehavior('adminPostHeaders', ['adminKutrl', 'adminPostHeaders']);
$core->addBehavior('adminPostFormSidebar',array('adminKutrl','adminPostFormSidebar')); $core->addBehavior('adminPostFormSidebar', ['adminKutrl', 'adminPostFormSidebar']);
$core->addBehavior('adminAfterPostUpdate',array('adminKutrl','adminAfterPostUpdate')); // update existing short url $core->addBehavior('adminAfterPostUpdate', ['adminKutrl', 'adminAfterPostUpdate']); // update existing short url
$core->addBehavior('adminAfterPostUpdate',array('adminKutrl','adminAfterPostCreate')); // create new short url $core->addBehavior('adminAfterPostUpdate', ['adminKutrl', 'adminAfterPostCreate']); // create new short url
$core->addBehavior('adminAfterPostCreate',array('adminKutrl','adminAfterPostCreate')); $core->addBehavior('adminAfterPostCreate', ['adminKutrl', 'adminAfterPostCreate']);
$core->addBehavior('adminBeforePostDelete',array('adminKutrl','adminBeforePostDelete')); $core->addBehavior('adminBeforePostDelete', ['adminKutrl', 'adminBeforePostDelete']);
$core->addBehavior('adminPostsActionsCombo',array('adminKutrl','adminPostsActionsCombo')); $core->addBehavior('adminPostsActionsCombo', ['adminKutrl', 'adminPostsActionsCombo']);
$core->addBehavior('adminPostsActions',array('adminKutrl','adminPostsActions')); $core->addBehavior('adminPostsActions', ['adminKutrl', 'adminPostsActions']);
} }
$core->addBehavior('exportFull',array('backupKutrl','exportFull')); $core->addBehavior('exportFull', ['backupKutrl', 'exportFull']);
$core->addBehavior('exportSingle',array('backupKutrl','exportSingle')); $core->addBehavior('exportSingle', ['backupKutrl', 'exportSingle']);
$core->addBehavior('importInit',array('backupKutrl','importInit')); $core->addBehavior('importInit', ['backupKutrl', 'importInit']);
$core->addBehavior('importSingle',array('backupKutrl','importSingle')); $core->addBehavior('importSingle', ['backupKutrl', 'importSingle']);
$core->addBehavior('importFull',array('backupKutrl','importFull')); $core->addBehavior('importFull', ['backupKutrl', 'importFull']);
# Admin behaviors class # Admin behaviors class
class adminKutrl class adminKutrl
{ {
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 adminPostHeaders() public static function adminPostHeaders()
{ {
return dcPage::jsLoad('index.php?pf=kUtRL/js/admin.js'); return dcPage::jsLoad('index.php?pf=kUtRL/js/admin.js');
@ -54,17 +70,17 @@ class adminKutrl
global $core; global $core;
$s = $core->blog->settings->kUtRL; $s = $core->blog->settings->kUtRL;
if (!$s->kutrl_active || !$s->kutrl_admin_service) return; if (!$s->kutrl_active || !$s->kutrl_admin_service) {
return null;
}
if (null === ($kut = kutrl::quickPlace('admin'))) {
return null;
}
if (null === ($kut = kutrl::quickPlace('admin'))) return; if ($post) {
if ($post)
{
$post_url = $post->getURL(); $post_url = $post->getURL();
$rs = $kut->isKnowUrl($post_url); $rs = $kut->isKnowUrl($post_url);
} } else {
else
{
$post_url = ''; $post_url = '';
$rs = false; $rs = false;
} }
@ -72,16 +88,12 @@ class adminKutrl
echo echo
'<h3 id="kutrl-form-title" class="clear">' . __('Short link') . '</h3>' . '<h3 id="kutrl-form-title" class="clear">' . __('Short link') . '</h3>' .
'<div id="kutrl-form-content">' . '<div id="kutrl-form-content">' .
form::hidden(array('kutrl_old_post_url'),$post_url); form::hidden(['kutrl_old_post_url'], $post_url);
if (!$rs) if (!$rs) {
{ if (empty($_POST['kutrl_old_post_url']) && $s->kutrl_admin_entry_default) {
if (empty($_POST['kutrl_old_post_url']) && $s->kutrl_admin_entry_default)
{
$chk = true; $chk = true;
} } else {
else
{
$chk = !empty($_POST['kutrl_create']); $chk = !empty($_POST['kutrl_create']);
} }
echo echo
@ -89,28 +101,20 @@ class adminKutrl
form::checkbox('kutrl_create', 1, $chk, '', 3) . ' ' . form::checkbox('kutrl_create', 1, $chk, '', 3) . ' ' .
__('Create short link') . '</label></p>'; __('Create short link') . '</label></p>';
if ($kut->allow_custom_hash) if ($kut->allow_custom_hash) {
{
echo echo
'<p class="classic">' . '<p class="classic">' .
'<label for="custom">' . __('Custom short link:') . ' ' . '<label for="custom">' . __('Custom short link:') . ' ' .
form::field('kutrl_create_custom', 32, 32, '', 3) . form::field('kutrl_create_custom', 32, 32, '', 3) .
'</label></p>'; '</label></p>';
} }
} } else {
else
{
$count = $rs->counter; $count = $rs->counter;
if ($count == 0) if ($count == 0) {
{
$title = __('never followed'); $title = __('never followed');
} } elseif ($count == 1) {
elseif ($count == 1)
{
$title = __('followed one time'); $title = __('followed one time');
} } else {
else
{
$title = sprintf(__('followed %s times'),$count); $title = sprintf(__('followed %s times'),$count);
} }
$href = $kut->url_base . $rs->hash; $href = $kut->url_base . $rs->hash;
@ -130,32 +134,37 @@ class adminKutrl
$s = $core->blog->settings->kUtRL; $s = $core->blog->settings->kUtRL;
# Create: see adminAfterPostCreate # Create: see adminAfterPostCreate
if (!empty($_POST['kutrl_create']) || !$s->kutrl_active) return; if (!empty($_POST['kutrl_create']) || !$s->kutrl_active) {
return null;
if (null === ($kut = kutrl::quickPlace('admin'))) return; }
if (null === ($kut = kutrl::quickPlace('admin'))) {
if (empty($_POST['kutrl_old_post_url'])) return; return null;
}
if (empty($_POST['kutrl_old_post_url'])) {
return null;
}
$old_post_url = $_POST['kutrl_old_post_url']; $old_post_url = $_POST['kutrl_old_post_url'];
if (!($rs = $kut->isKnowUrl($old_post_url))) return; if (!($rs = $kut->isKnowUrl($old_post_url))) {
return null;
}
$rs = $core->blog->getPosts(array('post_id'=>$post_id)); $rs = $core->blog->getPosts(['post_id' => $post_id]);
if ($rs->isEmpty()) {
return null;
}
$title = html::escapeHTML($rs->post_title); $title = html::escapeHTML($rs->post_title);
if ($rs->isEmpty()) return;
$new_post_url = $rs->getURL(); $new_post_url = $rs->getURL();
# Delete # Delete
if (!empty($_POST['kutrl_delete'])) if (!empty($_POST['kutrl_delete'])) {
{
$kut->remove($old_post_url); $kut->remove($old_post_url);
}
# Update # Update
else } else {
{ if ($old_post_url == $new_post_url) {
if ($old_post_url == $new_post_url) return; return null;
}
$kut->remove($old_post_url); $kut->remove($old_post_url);
@ -163,8 +172,7 @@ class adminKutrl
$url = $kut->url_base . $rs->hash; $url = $kut->url_base . $rs->hash;
# ex: Send new url to messengers # ex: Send new url to messengers
if (!empty($rs)) if (!empty($rs)) {
{
$core->callBehavior('adminAfterKutrlCreate' ,$core, $rs, $title); $core->callBehavior('adminAfterKutrlCreate' ,$core, $rs, $title);
} }
} }
@ -175,15 +183,19 @@ class adminKutrl
global $core; global $core;
$s = $core->blog->settings->kUtRL; $s = $core->blog->settings->kUtRL;
if (empty($_POST['kutrl_create']) || !$s->kutrl_active) return; if (empty($_POST['kutrl_create']) || !$s->kutrl_active) {
return null;
}
if (null === ($kut = kutrl::quickPlace('admin'))) {
return null;
}
if (null === ($kut = kutrl::quickPlace('admin'))) return; $rs = $core->blog->getPosts(['post_id' => $post_id]);
if ($rs->isEmpty()) {
$rs = $core->blog->getPosts(array('post_id'=>$post_id)); return null;
}
$title = html::escapeHTML($rs->post_title); $title = html::escapeHTML($rs->post_title);
if ($rs->isEmpty()) return;
$custom = !empty($_POST['kutrl_create_custom']) && $kut->allow_custom_hash ? $custom = !empty($_POST['kutrl_create_custom']) && $kut->allow_custom_hash ?
$_POST['kutrl_create_custom'] : null; $_POST['kutrl_create_custom'] : null;
@ -191,8 +203,7 @@ class adminKutrl
$url = $kut->url_base . $rs->hash; $url = $kut->url_base . $rs->hash;
# ex: Send new url to messengers # ex: Send new url to messengers
if (!empty($rs)) if (!empty($rs)) {
{
$core->callBehavior('adminAfterKutrlCreate', $core, $rs, $title); $core->callBehavior('adminAfterKutrlCreate', $core, $rs, $title);
} }
} }
@ -202,13 +213,17 @@ class adminKutrl
global $core; global $core;
$s = $core->blog->settings->kUtRL; $s = $core->blog->settings->kUtRL;
if (!$s->kutrl_active) return; if (!$s->kutrl_active) {
return null;
}
if (null === ($kut = kutrl::quickPlace('admin'))) {
return null;
}
if (null === ($kut = kutrl::quickPlace('admin'))) return; $rs = $core->blog->getPosts(['post_id' => $post_id]);
if ($rs->isEmpty()) {
$rs = $core->blog->getPosts(array('post_id'=>$post_id)); return null;
}
if ($rs->isEmpty()) return;
$kut->remove($rs->getURL()); $kut->remove($rs->getURL());
} }
@ -219,34 +234,35 @@ class adminKutrl
$s = $core->blog->settings->kUtRL; $s = $core->blog->settings->kUtRL;
if (!$s->kutrl_active if (!$s->kutrl_active
|| !$core->auth->check('admin',$core->blog->id)) return; || !$core->auth->check('admin',$core->blog->id)) {
return null;
}
$args[0][__('kUtRL')][__('create short link')] = 'kutrl_create'; $args[0][__('kUtRL')][__('create short link')] = 'kutrl_create';
$args[0][__('kUtRL')][__('delete short link')] = 'kutrl_delete'; $args[0][__('kUtRL')][__('delete short link')] = 'kutrl_delete';
} }
public static function adminPostsActions($core,$posts,$action,$redir) public static function adminPostsActions(dcCore $core, $posts, $action, $redir)
{ {
if ($action != 'kutrl_create' if ($action != 'kutrl_create'
&& $action != 'kutrl_delete') return; && $action != 'kutrl_delete') {
return null;
}
$s = $core->blog->settings->kUtRL; $s = $core->blog->settings->kUtRL;
if (!$s->kutrl_active) {
if (!$s->kutrl_active) return; return null;
}
if (null === ($kut = kutrl::quickPlace('admin'))) return; 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') while ($posts->fetch()) {
{ $url = $posts->getURL();
if ($action == 'kutrl_create') {
$kut->hash($url);
}
if ($action == 'kutrl_delete') {
$kut->remove($url); $kut->remove($url);
} }
} }
@ -281,11 +297,9 @@ class backupKutrl
public static function importSingle($line,$bk,$core) public static function importSingle($line,$bk,$core)
{ {
if ($line->__name == 'kutrl') if ($line->__name == 'kutrl') {
{
# Do nothing if str/type exists ! # Do nothing if str/type exists !
if (false === $bk->kutrl->select($line->kut_url,$line->kut_hash,$line->kut_type,$line->kut_service)) 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); $bk->kutrl->insert($line->kut_url, $line->kut_hash, $line->kut_type, $line->kut_service);
} }
} }
@ -293,10 +307,8 @@ class backupKutrl
public static function importFull($line, $bk, $core) public static function importFull($line, $bk, $core)
{ {
if ($line->__name == 'kutrl') if ($line->__name == 'kutrl') {
{
$bk->cur_kutrl->clean(); $bk->cur_kutrl->clean();
$bk->cur_kutrl->kut_id = (integer) $line->kut_id; $bk->cur_kutrl->kut_id = (integer) $line->kut_id;
$bk->cur_kutrl->blog_id = (string) $line->blog_id; $bk->cur_kutrl->blog_id = (string) $line->blog_id;
$bk->cur_kutrl->kut_service = (string) $line->kut_service; $bk->cur_kutrl->kut_service = (string) $line->kut_service;
@ -306,9 +318,7 @@ class backupKutrl
$bk->cur_kutrl->kut_dt = (string) $line->miniurl_dt; $bk->cur_kutrl->kut_dt = (string) $line->miniurl_dt;
$bk->cur_kutrl->kut_counter = (integer) $line->kut_counter; $bk->cur_kutrl->kut_counter = (integer) $line->kut_counter;
$bk->cur_kutrl->kut_password = (string) $line->kut_password; $bk->cur_kutrl->kut_password = (string) $line->kut_password;
$bk->cur_kutrl->insert(); $bk->cur_kutrl->insert();
} }
} }
} }
?>

View File

@ -18,13 +18,13 @@ $this->registerModule(
'kUtRL', 'kUtRL',
'Use, create and serve short url on your blog', 'Use, create and serve short url on your blog',
'Jean-Christian Denis and contributors', 'Jean-Christian Denis and contributors',
'2011.03.24', '2021.08.27',
[ [
'permissions' => 'admin', 'permissions' => 'admin',
'type' => 'plugin', 'type' => 'plugin',
'dc_min' => '2.19', 'dc_min' => '2.19',
'support' => 'https://github.com/JcDenis/kUtRL', 'support' => 'https://github.com/JcDenis/kUtRL',
'details' => 'http://plugins.dotaddict.org/dc2/details/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'
] ]
); );