From 2d5d611e5658cc0201f96f8a3eb38e66106c8075 Mon Sep 17 00:00:00 2001 From: Jean-Christian Denis Date: Sat, 28 Aug 2021 20:39:58 +0200 Subject: [PATCH] fix widgets style --- CHANGELOG.md | 140 ++++++++--------- _define.php | 2 +- _widgets.php | 420 +++++++++++++++++++++++++++------------------------ index.php | 4 +- 4 files changed, 299 insertions(+), 267 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 59eba3e..9536f80 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,96 +1,96 @@ todo - Added public page of the list of know urls and in/visible status - Added passworded links -- fix widgets rendering -- move setting to config file -- fix dashboard rendering - fix deprecated external service -2021.08.27 +2021.08.28 - 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 +- merge index file sub parts +- remove custom js +- fix widgets rendering 2011.04.01 - * Changed version numbering - * Added service su.pr (stumbleUpon) - * Fixed wiki settings (thanks @ploum ) +- Changed version numbering +- Added service su.pr (stumbleUpon) +- Fixed wiki settings (thanks @ploum ) -1.0 20110213 - * Added generic class to easlily access services - * Changed generic service class (and class extend it) - * Fixed config of default service - * Fixed display of admin fake section - * Added checkbox helpers on admin +1.0 - 2011.02.13 +- Added generic class to easlily access services +- Changed generic service class (and class extend it) +- Fixed config of default service +- Fixed display of admin fake section +- Added checkbox helpers on admin -0.6.1 20110130 - * Cleaned up script +0.6.1 - 2011.01.30 +- Cleaned up script -0.6 20110118 'prepare the soCial révolution' - * Added default defined service (for all blogs of a multiblog) - * Added configurable external service - * Added goog.gl client service (first step) - * Added default settings for third part plugins - * Added behaviors after short link creation - * Added attribute to disable URL shortining on template tag with 'active mode' (fixed bug on URL of POST form) - * Remove all messenger functions: this is to another plugin to do that - * Remove priority in plugin definition +0.6 - 2011.01.18 +- Added default defined service (for all blogs of a multiblog) +- Added configurable external service +- Added goog.gl client service (first step) +- Added default settings for third part plugins +- Added behaviors after short link creation +- Added attribute to disable URL shortining on template tag with 'active mode' (fixed bug on URL of POST form) +- Remove all messenger functions: this is to another plugin to do that +- Remove priority in plugin definition -0.5 20100909 - * Removed old Twitter functions - * Added StatusNet small functions (Identica) - * Required plugin Tac for Twitter ability - * Added YOURLS client service +0.5 - 2010.09.09 +- Removed old Twitter functions +- Added StatusNet small functions (Identica) +- Required plugin Tac for Twitter ability +- Added YOURLS client service -0.4.2 20100809 - * Fixed bug on dcTwitter shorten service - * Fixed bug on custom local link - * Added category URL to active mode - * Added priority to plugin definition +0.4.2 - 2010.08.09 +- Fixed bug on dcTwitter shorten service +- Fixed bug on custom local link +- Added category URL to active mode +- Added priority to plugin definition -0.4.1 20100701 - * Fixed multiple bugs +0.4.1 - 2010.07.01 +- Fixed multiple bugs -0.4 20100628 - * Switched to DC 2.2 - * Fixed no short urls on preview mode - * Fixed lock hash of deleted urls - * Fixed hide new short url widget on kutrl pages - * Fixed typo - * Added active mode that shorten urls on default template values - * Added special tweeter message for post (can include post title) - * Added kutrl special 404 page +0.4 - 2010.06.28 +- Switched to DC 2.2 +- Fixed no short urls on preview mode +- Fixed lock hash of deleted urls +- Fixed hide new short url widget on kutrl pages +- Fixed typo +- Added active mode that shorten urls on default template values +- Added special tweeter message for post (can include post title) +- Added kutrl special 404 page -0.3.3 20100528 - * Fixed settings in tweeter class - * Renamed tweeter class +0.3.3 - 2010.05.28 +- Fixed settings in tweeter class +- Renamed tweeter class -0.3.2 20100525 - * FIxed minor bugs - * Fixed DC 2.1.7 +0.3.2 - 2010.05.25 +- FIxed minor bugs +- Fixed DC 2.1.7 -0.3 20100414 - * Added DC 2.2 compatibility (new settings) - * Added semi-custom hash on kUtRL service - * Added status update for Twitter/Identi.ca on new short link - * Added services error management (first step) - * Added options to widgets - * Upgraded bitly service to v3 - * Changed admin design +0.3 2010.04.14 +- Added DC 2.2 compatibility (new settings) +- Added semi-custom hash on kUtRL service +- Added status update for Twitter/Identi.ca on new short link +- Added services error management (first step) +- Added options to widgets +- Upgraded bitly service to v3 +- Changed admin design -0.2 20091223 - * Fixed public redirection with suffix - * Added short.to service +0.2 - 2009.12.23 +- Fixed public redirection with suffix +- Added short.to service -0.1.2 20091212 - * Added option to short url of new entry by default - * Fixed typo +0.1.2 - 2009.12.12 +- Added option to short url of new entry by default +- Fixed typo -0.1.1 20091212 - * Added option to display long url when unactive - * Fixed support of kutrl in feeds +0.1.1 - 2009.12.12 +- Added option to display long url when unactive +- Fixed support of kutrl in feeds -0.1 20091209 - * First lab release \ No newline at end of file +0.1 - 2009.12.09 +- First lab release \ No newline at end of file diff --git a/_define.php b/_define.php index 7b482a4..7639716 100644 --- a/_define.php +++ b/_define.php @@ -19,7 +19,7 @@ $this->registerModule( 'kUtRL', 'Use, create and serve short url on your blog', 'Jean-Christian Denis and contributors', - '2021.08.27', + '2021.08.28', [ 'permissions' => 'admin', 'type' => 'plugin', diff --git a/_widgets.php b/_widgets.php index b829d86..bf1c43d 100644 --- a/_widgets.php +++ b/_widgets.php @@ -11,202 +11,234 @@ # # -- END LICENSE BLOCK ------------------------------------ -if (!defined('DC_RC_PATH')){return;} +if (!defined('DC_RC_PATH')) { + return null; +} -$core->addBehavior('initWidgets',array('widgetKutrl','adminShorten')); -$core->addBehavior('initWidgets',array('widgetKutrl','adminRank')); +$core->addBehavior('initWidgets', ['widgetKutrl', 'adminShorten']); +$core->addBehavior('initWidgets', ['widgetKutrl', 'adminRank']); class widgetKutrl { - public static function adminShorten($w) - { - $w->create('shortenkutrl',__('Links shortener'), - array('widgetKutrl','publicShorten') - ); - $w->shortenkutrl->setting('title', - __('Title:'),__('Shorten link'),'text' - ); - $w->shortenkutrl->setting('homeonly', - __('Home page only'),1,'check' - ); - } - - public static function adminRank($w) - { - $w->create('rankkutrl',__('Top of short links'), - array('widgetKutrl','publicRank') - ); - $w->rankkutrl->setting('title', - __('Title:'),__('Top of short links'),'text' - ); - $w->rankkutrl->setting('text', - __('Text: (Use wildcard %rank%, %hash%, %url%, %count%, %counttext%)'),'%rank% - %url% - %counttext%','text' - ); - $w->rankkutrl->setting('urllen', - __('URL length (if truncate)'),20,'text' - ); - $w->rankkutrl->setting('type', - __('Type:'),'all','combo',array( - __('All') => '-', - __('Mini URL') => 'localnormal', - __('Custom URL') => 'localcustom', - __('Semi-custom') => 'localmix' - ) - ); - $w->rankkutrl->setting('mixprefix', - __('Semi-custom prefix: (only if you want limit to a particular prefix)'), - '','text' - ); - $w->rankkutrl->setting('sortby', - __('Sort by:'),'kut_counter','combo',array( - __('Date') => 'kut_dt', - __('Rank') => 'kut_counter', - __('Hash') => 'kut_hash' - ) - ); - $w->rankkutrl->setting('sort', - __('Sort:'),'desc','combo',array( - __('Ascending') => 'asc', - __('Descending') => 'desc' - ) - ); - $w->rankkutrl->setting('limit', - __('Limit:'),'10','text' - ); - $w->rankkutrl->setting('hideempty', - __('Hide no followed links'),0,'check' - ); - $w->rankkutrl->setting('homeonly', - __('Home page only'),1,'check' - ); - } - - public static function publicShorten($w) - { - global $core; - $s = $core->blog->settings->kUtRL; - - if (!$s->kutrl_active - || !$s->kutrl_srv_local_public - || $w->homeonly && $core->url->type != 'default' - || $core->url->type == 'kutrl') return; - - $hmf = hmfKutrl::create(); - $hmfp = hmfKutrl::protect($hmf); - - return - '
'. - ($w->title ? '

'.html::escapeHTML($w->title).'

' : ''). - '
'. - '

'. - '

'. - '

'. - form::hidden('hmfp',$hmfp). - $core->formNonce(). - '

'. - '
'. - '
'; - } - - public static function publicRank($w) - { - global $core; - $s = $core->blog->settings->kUtRL; - - if (!$s->kutrl_active - || $w->homeonly && $core->url->type != 'default') return; - - $type = in_array($w->type,array('localnormal','localmix','localcustom')) ? - "AND kut_type ='".$w->type."' " : - "AND kut_type ".$core->con->in(array('localnormal','localmix','localcustom'))." "; - - $hide = (boolean) $w->hideempty ? 'AND kut_counter > 0 ' : ''; - - $more = ''; - if ($w->type == 'localmix' && '' != $w->mixprefix) - { - $more = "AND kut_hash LIKE '".$core->con->escape($w->mixprefix)."%' "; - } - - $order = ($w->sortby && in_array($w->sortby,array('kut_dt','kut_counter','kut_hash'))) ? - $w->sortby.' ' : 'kut_dt '; - - $order .= $w->sort == 'desc' ? 'DESC' : 'ASC'; - - $limit = $core->con->limit(abs((integer) $w->limit)); - - $rs = $core->con->select( - 'SELECT kut_counter, kut_hash '. - "FROM ".$core->prefix."kutrl ". - "WHERE blog_id='".$core->con->escape($core->blog->id)."' ". - "AND kut_service = 'local' ". - $type.$hide.$more.'ORDER BY '.$order.$limit - ); - - if ($rs->isEmpty()) return; - - $content = ''; - $i = 0; - - while($rs->fetch()) - { - $i++; - $rank = ''.$i.''; - - $hash = $rs->kut_hash; - $url = $core->blog->url.$core->url->getBase('kutrl').'/'.$hash; - $cut_len = - abs((integer) $w->urllen); - - if (strlen($url) > $cut_len) - { - $url = '...'.substr($url,$cut_len); - } -/* - if (strlen($hash) > $cut_len) - { - $url = '...'.substr($hash,$cut_len); - } -//*/ - if ($rs->kut_counter == 0) - { - $counttext = __('never followed'); - } - elseif ($rs->kut_counter == 1) - { - $counttext = __('followed one time'); - } - else - { - $counttext = sprintf(__('followed %s times'),$rs->kut_counter); - } - - $content .= - '
  • '. - str_replace( - array('%rank%','%hash%','%url%','%count%','%counttext%'), - array($rank,$hash,$url,$rs->kut_counter,$counttext), - $w->text - ). - '
  • '; + public static function adminShorten($w) + { + $w + ->create( + 'shortenkutrl', + __('Links shortener'), + ['widgetKutrl', 'publicShorten'] + ) + ->addTitle(__('Shorten link')) + ->addHomeOnly() + ->addContentOnly() + ->addClass() + ->addOffline(); + } - } - - if (!$content) return; - - return - '
    '. - ($w->title ? '

    '.html::escapeHTML($w->title).'

    ' : ''). - ''. - '
    '; - } -} -?> \ No newline at end of file + public static function adminRank($w) + { + $w + ->create( + 'rankkutrl', + __('Top of short links'), + ['widgetKutrl', 'publicRank'] + ) + ->addTitle(__('Top of short links')) + ->setting( + 'text', + __('Text: (Use wildcard %rank%, %hash%, %url%, %count%, %counttext%)'), + '%rank% - %url% - %counttext%', + 'text' + ) + ->setting( + 'urllen', + __('URL length (if truncate)'), + 20, + 'text' + ) + ->setting( + 'type', + __('Type:'), + 'all', + 'combo',[ + __('All') => '-', + __('Mini URL') => 'localnormal', + __('Custom URL') => 'localcustom', + __('Semi-custom') => 'localmix' + ] + ) + ->setting( + 'mixprefix', + __('Semi-custom prefix: (only if you want limit to a particular prefix)'), + '', + 'text' + ) + ->setting( + 'sortby', + __('Sort by:'), + 'kut_counter', + 'combo', + [ + __('Date') => 'kut_dt', + __('Rank') => 'kut_counter', + __('Hash') => 'kut_hash' + ] + ) + ->setting( + 'sort', + __('Sort:'), + 'desc', + 'combo', + [ + __('Ascending') => 'asc', + __('Descending') => 'desc' + ] + ) + ->setting( + 'limit', + __('Limit:'), + '10', + 'text' + ) + ->setting( + 'hideempty', + __('Hide no followed links'), + 0, + 'check' + ) + ->addHomeOnly() + ->addContentOnly() + ->addClass() + ->addOffline(); + } + + public static function publicShorten($w) + { + global $core; + $s = $core->blog->settings->kUtRL; + + if (!$s->kutrl_active + || !$s->kutrl_srv_local_public + || ($w->homeonly == 1 && !$core->url->isHome($core->url->type)) || ($w->homeonly == 2 && $core->url->isHome($core->url->type)) + || $core->url->type == 'kutrl') { + return null; + } + + $hmf = hmfKutrl::create(); + $hmfp = hmfKutrl::protect($hmf); + + return $w->renderDiv( + $w->content_only, + 'shortenkutrlwidget ' . $w->class, + '', + ($w->title ? $w->renderTitle(html::escapeHTML($w->title)) : '') . + '
    ' . + '

    ' . + '

    ' . + '

    ' . + form::hidden('hmfp',$hmfp) . + $core->formNonce() . + '

    ' . + '
    ' + ); + } + + public static function publicRank($w) + { + global $core; + $s = $core->blog->settings->kUtRL; + + if (!$s->kutrl_active + || ($w->homeonly == 1 && !$core->url->isHome($core->url->type)) || ($w->homeonly == 2 && $core->url->isHome($core->url->type))) { + return null; + } + + $type = in_array($w->type, ['localnormal', 'localmix', 'localcustom']) ? + "AND kut_type ='" . $w->type . "' " : + "AND kut_type " . $core->con->in(['localnormal', 'localmix', 'localcustom']) . " "; + + $hide = (boolean) $w->hideempty ? 'AND kut_counter > 0 ' : ''; + + $more = ''; + if ($w->type == 'localmix' && '' != $w->mixprefix) { + $more = "AND kut_hash LIKE '" . $core->con->escape($w->mixprefix) . "%' "; + } + + $order = ($w->sortby && in_array($w->sortby, ['kut_dt', 'kut_counter', 'kut_hash'])) ? + $w->sortby : 'kut_dt'; + + $order .= $w->sort == 'desc' ? ' DESC' : ' ASC'; + + $limit = $core->con->limit(abs((integer) $w->limit)); + + $rs = $core->con->select( + 'SELECT kut_counter, kut_hash ' . + "FROM " . $core->prefix . "kutrl " . + "WHERE blog_id='" . $core->con->escape($core->blog->id) . "' " . + "AND kut_service = 'local' " . + $type . $hide . $more . 'ORDER BY ' . $order . $limit + ); + + if ($rs->isEmpty()) { + return null; + } + + $content = ''; + $i = 0; + while($rs->fetch()) { + $i++; + $rank = '' . $i . ''; + + $hash = $rs->kut_hash; + $url = $core->blog->url . $core->url->getBase('kutrl') . '/' . $hash; + $cut_len = - abs((integer) $w->urllen); + + if (strlen($url) > $cut_len) { + $url = '...' . substr($url, $cut_len); + } +/* + if (strlen($hash) > $cut_len) { + $url = '...'.substr($hash, $cut_len); + } +//*/ + if ($rs->kut_counter == 0) { + $counttext = __('never followed'); + } elseif ($rs->kut_counter == 1) { + $counttext = __('followed one time'); + } else { + $counttext = sprintf(__('followed %s times'), $rs->kut_counter); + } + + $content .= + '
  • ' . + str_replace( + ['%rank%', '%hash%', '%url%', '%count%', '%counttext%'], + [$rank, $hash, $url, $rs->kut_counter, $counttext], + $w->text + ) . + '
  • '; + } + + if (empty($content)) { + return null; + } + + return $w->renderDiv( + $w->content_only, + 'lastblogupdate ' . $w->class, + '', + ($w->title ? $w->renderTitle(html::escapeHTML($w->title)) : '') . + sprintf('', $content) + ); + + } +} \ No newline at end of file diff --git a/index.php b/index.php index 4626cab..7c7c683 100644 --- a/index.php +++ b/index.php @@ -411,7 +411,7 @@ if ($part == 'service') { dcPage::notices() . '

    ' . __('Services configuration') . '

    ' . - '

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

    '; + '

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

    ' . '
    '; foreach(kutrl::getServices($core) as $service_id => $service) { @@ -429,7 +429,7 @@ if ($part == 'service') { echo $o->error->toHTML(); //} } - if (!empty($o->home)) { + if ($o->home != '') { echo '

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

    '; } $o->settingsForm();