From 83ea869ba249bedc302db49ed6789938876f022c Mon Sep 17 00:00:00 2001 From: Jean-Christian Denis Date: Mon, 2 Jan 2023 01:00:05 +0100 Subject: [PATCH] update to dotclear 2.24 --- _admin.php | 64 +++---- _define.php | 54 +++--- _install.php | 36 ++++ _prepend.php | 63 +++++-- _public.php | 253 ++++++++++++++++++++++++--- _widgets.php | 92 ++++++---- inc/class.dc.comListe.php | 351 -------------------------------------- index.php | 220 +++++++++--------------- locales/en/resources.php | 26 ++- locales/fr/resources.php | 26 ++- 10 files changed, 543 insertions(+), 642 deletions(-) create mode 100644 _install.php delete mode 100644 inc/class.dc.comListe.php diff --git a/_admin.php b/_admin.php index 215700e..e6283c0 100644 --- a/_admin.php +++ b/_admin.php @@ -1,33 +1,39 @@ menu[dcAdmin::MENU_PLUGINS]->addItem( + __('Comments list'), + dcCore::app()->adminurl->get('admin.plugin.' . basename(__DIR__)), + urldecode(dcPage::getPF(basename(__DIR__) . '/icon.png')), + preg_match('/' . preg_quote(dcCore::app()->adminurl->get('admin.plugin.' . basename(__DIR__))) . '(&.*)?$/', $_SERVER['REQUEST_URI']), + dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([dcAuth::PERMISSION_ADMIN]), dcCore::app()->blog->id) +); -$_menu['Blog']->addItem(__('List of comments'),'plugin.php?p=comListe','index.php?pf=comListe/icon.png', - preg_match('/plugin.php\?p=comListe(&.*)?$/',$_SERVER['REQUEST_URI']), - $core->auth->check('admin',$core->blog->id)); - -$core->addBehavior('adminDashboardFavorites','comListeDashboardFavorites'); - -function comListeDashboardFavorites($core,$favs) -{ - $favs->register('comListe', array( - 'title' => __('List of comments'), - 'url' => 'plugin.php?p=comListe', - 'small-icon' => 'index.php?pf=comListe/icon.png', - 'large-icon' => 'index.php?pf=comListe/icon-big.png', - 'permissions' => 'usage,contentadmin' - )); -} \ No newline at end of file +dcCore::app()->addBehaviors([ + // Dashboard favorites + 'adminDashboardFavoritesV2' => function (dcFavorites $favs) { + $favs->register(basename(__DIR__), [ + 'title' => __('Comments list'), + 'url' => dcCore::app()->adminurl->get('admin.plugin.' . basename(__DIR__)), + 'small-icon' => urldecode(dcPage::getPF(basename(__DIR__) . '/icon.png')), + 'large-icon' => urldecode(dcPage::getPF(basename(__DIR__) . '/icon-big.png')), + 'permissions' => dcCore::app()->auth->makePermissions([dcAuth::PERMISSION_ADMIN]), + ]); + }, +]); diff --git a/_define.php b/_define.php index ef79b62..ad3c971 100644 --- a/_define.php +++ b/_define.php @@ -1,28 +1,32 @@ registerModule( - /* Name */ "ComListe", - /* Description*/ "Display a list of all comments and trackbacks of a blog in a public page", - /* Author */ "Benoit de Marne, Pierre Van Glabeke", - /* Version */ '0.4.2', - /* Properties */ - array( - 'permissions' => 'admin', - 'type' => 'plugin', - 'dc_min' => '2.8', - 'support' => 'http://forum.dotclear.org/viewtopic.php?pid=333985#p333985', - 'details' => 'http://plugins.dotaddict.org/dc2/details/comListe' - ) -); \ No newline at end of file + 'Comments list', + 'Display a list of all comments and trackbacks of a blog in a public page', + 'Benoit de Marne, Pierre Van Glabeke and contributors', + '0.5-dev', + [ + 'requires' => [['core', '2.24']], + 'permissions' => dcCore::app()->auth->makePermissions([ + dcAuth::PERMISSION_ADMIN, + ]), + 'type' => 'plugin', + 'support' => 'http://forum.dotclear.org/viewtopic.php?pid=333985', + 'details' => 'https://plugins.dotaddict.org/dc2/details/' . basename(__DIR__), + 'repository' => 'https://raw.githubusercontent.com/JcDenis/' . basename(__DIR__) . '/master/dcstore.xml', + ] +); diff --git a/_install.php b/_install.php new file mode 100644 index 0000000..741f9c5 --- /dev/null +++ b/_install.php @@ -0,0 +1,36 @@ +newVersion( + basename(__DIR__), + dcCore::app()->plugins->moduleInfo(basename(__DIR__), 'version') + )) { + return null; + } + + $s = dcCore::app()->blog->settings->get(basename(__DIR__)); + $s->put('enable', false, 'boolean', 'Enable comListe', false, true); + $s->put('page_title', 'Comments list', 'string', 'Public page title', false, true); + $s->put('nb_comments_per_page', 10, 'integer', 'Number of comments per page', false, true); + $s->put('comments_order', 'desc', 'string', 'Comments order', false, true); + + return true; +} catch (Exception $e) { + dcCore::app()->error->add($e->getMessage()); +} + +return false; diff --git a/_prepend.php b/_prepend.php index f8c7fd7..42288b3 100644 --- a/_prepend.php +++ b/_prepend.php @@ -1,15 +1,54 @@ url->register( + 'comListe', + 'comListe', + '^comListe(?:/(.+))?$', + ['urlcomListe','comListe'] +); -require dirname(__FILE__).'/_widgets.php'; \ No newline at end of file +class urlcomListe extends dcUrlHandlers +{ + public static function comListe($args) + { + $args = (string) $args; + + if (!dcCore::app()->blog->settings->get(basename(__DIR__))->get('enable')) { + self::p404(); + + return null; + } + + $n = self::getPageNumber($args); + if (!$n) { + $n = 1; + } + + dcCore::app()->public->setPageNumber($n); + dcCore::app()->ctx->__set('nb_comment_per_page', (int) dcCore::app()->blog->settings->get(basename(__DIR__))->get('nb_comments_per_page')); + + $tplset = dcCore::app()->themes->moduleInfo(dcCore::app()->blog->settings->get('system')->get('theme'), 'tplset'); + if (!empty($tplset) && is_dir(implode(DIRECTORY_SEPARATOR, [__DIR__, 'default-templates', $tplset]))) { + dcCore::app()->tpl->setPath(dcCore::app()->tpl->getPath(), implode(DIRECTORY_SEPARATOR, [__DIR__, 'default-templates', $tplset])); + } else { + dcCore::app()->tpl->setPath(dcCore::app()->tpl->getPath(), implode(DIRECTORY_SEPARATOR, [__DIR__, 'default-templates', DC_DEFAULT_TPLSET])); + } + + self::serveDocument('comListe.html'); + exit; + } +} diff --git a/_public.php b/_public.php index 8f4caea..ecad548 100644 --- a/_public.php +++ b/_public.php @@ -1,28 +1,235 @@ blog->settings->get(basename(__DIR__))->get('enable')) { + return null; +} -l10n::set(dirname(__FILE__).'/locales/'.$_lang.'/public'); +require __DIR__ . '/_widgets.php'; -require_once dirname(__FILE__).'/inc/class.dc.comListe.php'; - -$core->url->register('comListe','comListe','^comListe(?:/(.+))?$',array('urlcomListe','comListe')); +dcCore::app()->tpl->addValue('ComListeURL', ['tplComListe','comListeURL']); +dcCore::app()->tpl->addValue('ComListePageTitle', ['tplComListe','comListePageTitle']); +dcCore::app()->tpl->addValue('ComListeNbComments', ['tplComListe','comListeNbComments']); +dcCore::app()->tpl->addValue('ComListeNbCommentsPerPage', ['tplComListe','comListeNbCommentsPerPage']); +dcCore::app()->tpl->addBlock('ComListeCommentsEntries', ['tplComListe','comListeCommentsEntries']); +dcCore::app()->tpl->addValue('ComListePaginationLinks', ['tplComListe','comListePaginationLinks']); +dcCore::app()->tpl->addValue('ComListeOpenPostTitle', ['tplComListe','comListeOpenPostTitle']); -$core->tpl->addValue('ComListeURL',array('tplComListe','comListeURL')); -$core->tpl->addValue('ComListePageTitle',array('tplComListe','comListePageTitle')); -$core->tpl->addValue('ComListeNbComments',array('tplComListe','comListeNbComments')); -$core->tpl->addValue('ComListeNbCommentsPerPage',array('tplComListe','comListeNbCommentsPerPage')); -$core->tpl->addBlock('ComListeCommentsEntries',array('tplComListe','comListeCommentsEntries')); -$core->tpl->addValue('ComListePaginationLinks',array('tplComListe','comListePaginationLinks')); -$core->tpl->addValue('ComListeOpenPostTitle',array('tplComListe','comListeOpenPostTitle')); -$core->addBehavior('publicBreadcrumb',array('extComListe','publicBreadcrumb')); \ No newline at end of file +dcCore::app()->addBehaviors([ + 'publicBreadcrumb' => function ($context, $separator) { + if ($context == 'comListe') { + return __('Comments list'); + } + }, +]); + +class tplComListe +{ + public $html_prev = '«prev.'; + public $html_next = 'next»'; + + /* ComListeURL --------------------------------------- */ + public static function comListeURL($attr) + { + $f = dcCore::app()->tpl->getFilters($attr); + + return 'blog->url.dcCore::app()->url->getBase("comListe")') . '; ?>'; + } + + /* ComListePageTitle --------------------------------------- */ + public static function comListePageTitle($attr) + { + $f = dcCore::app()->tpl->getFilters($attr); + + return 'blog->settings->get("' . basename(__DIR__) . '")->get("page_title")') . '; ?>'; + } + + /* ComListeNbCommentsPerPage --------------------------------------- */ + public static function comListeNbCommentsPerPage($attr) + { + dcCore::app()->ctx->__set('nb_comment_per_page', (int) dcCore::app()->blog->settings->get(basename(__DIR__))->get('nb_comments_per_page')); + + return html::escapeHTML((string) dcCore::app()->ctx->__get('nb_comment_per_page')); + } + + /* comListeNbComments --------------------------------------- */ + public static function comListeNbComments($attr) + { + if (!dcCore::app()->ctx->exists('pagination')) { + dcCore::app()->ctx->__set('pagination', dcCore::app()->blog->getComments([], true)); + } + $nb_comments = dcCore::app()->ctx->__get('pagination')->f(0); + + return html::escapeHTML((string) $nb_comments); + } + + /* ComListeCommentsEntries --------------------------------------- */ + public static function comListeCommentsEntries($attr, $content) + { + $p = 'if (dcCore::app()->ctx->posts !== null) { ' . + "\$params['post_id'] = dcCore::app()->ctx->posts->post_id; " . + "dcCore::app()->blog->withoutPassword(false);\n" . + "}\n"; + + if (empty($attr['with_pings'])) { + $p .= "\$params['comment_trackback'] = false;\n"; + } + + $lastn = 0; + if (isset($attr['lastn'])) { + $lastn = abs((int) $attr['lastn']) + 0; + } + + if ($lastn > 0) { + $p .= "\$params['limit'] = " . $lastn . ";\n"; + } else { + $p .= "if (dcCore::app()->ctx->nb_comment_per_page !== null) { \$params['limit'] = dcCore::app()->ctx->nb_comment_per_page; }\n"; + } + + $p .= "\$params['limit'] = array(((dcCore::app()->public->getPageNumber()-1)*\$params['limit']),\$params['limit']);\n"; + + if (empty($attr['no_context'])) { + $p .= 'if (dcCore::app()->ctx->exists("categories")) { ' . + "\$params['cat_id'] = dcCore::app()->ctx->categories->cat_id; " . + "}\n"; + + $p .= 'if (dcCore::app()->ctx->exists("langs")) { ' . + "\$params['sql'] = \"AND P.post_lang = '\".dcCore::app()->blog->con->escape(dcCore::app()->langs->post_lang).\"' \"; " . + "}\n"; + } + + // Sens de tri issu des paramètres du plugin + $order = dcCore::app()->blog->settings->get(basename(__DIR__))->get('comments_order'); + if (isset($attr['order']) && preg_match('/^(desc|asc)$/i', $attr['order'])) { + $order = $attr['order']; + } + + $p .= "\$params['order'] = 'comment_dt " . $order . "';\n"; + + if (isset($attr['no_content']) && $attr['no_content']) { + $p .= "\$params['no_content'] = true;\n"; + } + + $res = "ctx->comments = dcCore::app()->blog->getComments($params); unset($params);' . "\n"; + $res .= "if (dcCore::app()->ctx->posts !== null) { dcCore::app()->blog->withoutPassword(true);}\n"; + + if (!empty($attr['with_pings'])) { + $res .= 'dcCore::app()->ctx->pings = dcCore::app()->ctx->comments;' . "\n"; + } + + $res .= "?>\n"; + + $res .= 'ctx->comments->fetch()) : ?>' . $content . 'ctx->pop("comments"); ?>'; + + return $res; + } + + /* ComListePaginationLinks --------------------------------------- */ + /* Reprise et adaptation de la fonction PaginationLinks du plugin advancedPagination-1.9 */ + public static function comListePaginationLinks($attr) + { + $p = 'public->getPageNumber()) { + $args = $_SERVER["URL_REQUEST_PART"]; + $args = preg_replace("#(^|/)page/([0-9]+)$#","",$args); + $url = dcCore::app()->blog->url.$args; + + if ($pageNumber > 1) { + $url = preg_replace("#/$#","",$url); + $url .= "/page/".$pageNumber; + } + + if (!empty($_GET["q"])) { + $s = strpos($url,"?") !== false ? "&" : "?"; + $url .= $s."q=".rawurlencode($_GET["q"]); + } + + return "".$linkText." "; + } else { + return $linkText." "; + } + } + + $current = dcCore::app()->public->getPageNumber(); + + if(empty($params)) { + dcCore::app()->ctx->pagination = dcCore::app()->blog->getComments(null,true); + } else { + dcCore::app()->ctx->pagination = dcCore::app()->blog->getComments($params,true); + unset($params); + } + + if (dcCore::app()->ctx->exists("pagination")) { + $nb_comments = dcCore::app()->ctx->pagination->f(0); + } + + $nb_per_page = abs((integer) dcCore::app()->blog->settings->get("' . basename(__DIR__) . '")->get("nb_comments_per_page")); + $nb_pages = ceil($nb_comments/$nb_per_page); + $nb_max_pages = 10; + $nb_sequence = 2*3+1; + $quick_distance = 10; + + if($nb_pages <= $nb_max_pages) { + /* less or equal than 10 pages, simple links */ + for ($i = 1; $i <= $nb_pages; $i++) { + echo comListeMakePageLink($i,$i); + } + } else { + /* more than 10 pages, smart links */ + echo comListeMakePageLink(1,1); + $min_page = max($current - ($nb_sequence - 1) / 2, 2); + $max_page = min($current + ($nb_sequence - 1) / 2, $nb_pages - 1); + if ($min_page > 2) { + echo "..."; + echo " "; + } + + for ($i = $min_page; $i <= $max_page ; $i++) { + echo comListeMakePageLink($i,$i); + } + + if ($max_page < $nb_pages - 1) { + echo "..."; + echo " "; + } + echo comListeMakePageLink($nb_pages,$nb_pages); + + /* quick navigation links */ + if($current >= 1 + $quick_distance) { + echo " "; + echo comListeMakePageLink($current - $quick_distance, "<<"); + } + + if($current <= $nb_pages - $quick_distance) { + echo " "; + echo comListeMakePageLink($current + $quick_distance, ">> "); + } + } + ?>'; + + return $p; + } + + /* ComListeOpenPostTitle --------------------------------------- */ + public static function comListeOpenPostTitle($attr) + { + return __('open post'); + } +} diff --git a/_widgets.php b/_widgets.php index 09ba35a..13d4827 100644 --- a/_widgets.php +++ b/_widgets.php @@ -1,37 +1,63 @@ addBehavior('initWidgets', ['comListeWidget','initWidget']); -$core->addBehavior('initWidgets',array('comListeWidgets','initWidgets')); - -class comListeWidgets +class comListeWidget { - public static function initWidgets($w) - { - $w->create('comListe',__('ComListe'),array('tplComListe','comListeWidget'), - null, - __('List of comments')); - $w->comListe->setting('title',__('Title:'),__('ComListe')); - $w->comListe->setting('link_title',__('Link title:'),__('List of comments')); - $w->comListe->setting('homeonly',__('Display on:'),0,'combo', - array( - __('All pages') => 0, - __('Home page only') => 1, - __('Except on home page') => 2 - ) - ); - $w->comListe->setting('content_only',__('Content only'),0,'check'); - $w->comListe->setting('class',__('CSS class:'),''); - $w->comListe->setting('offline',__('Offline'),0,'check'); - } -} \ No newline at end of file + public static function initWidget($w) + { + $w->create( + 'comListe', + __('Comments list'), + ['comListeWidget','publicWidget'], + null, + __('Comments list') + ) + ->addTitle(__('Comments list')) + ->setting( + 'link_title', + __('Link title:'), + __('Comments list') + ) + ->addHomeOnly() + ->addContentOnly() + ->addClass() + ->addOffline(); + } + + public static function publicWidget($w) + { + if ($w->offline + || !$w->checkHomeOnly(dcCore::app()->url->type) + || !dcCore::app()->blog->settings->get(basename(__DIR__))->get('enable') + ) { + return null; + } + + return $w->renderDiv( + $w->content_only, + 'comliste ' . $w->class, + '', + ($w->title ? $w->renderTitle(html::escapeHTML($w->title)) : '') . + sprintf( + '

%s

', + dcCore::app()->blog->url . dcCore::app()->url->getBase('comListe'), + $w->link_title ? html::escapeHTML($w->link_title) : __('Comments list') + ) + ); + } +} diff --git a/inc/class.dc.comListe.php b/inc/class.dc.comListe.php deleted file mode 100644 index 744f99c..0000000 --- a/inc/class.dc.comListe.php +++ /dev/null @@ -1,351 +0,0 @@ -=')) { - $blog_settings =& $core->blog->settings->comListe; - } else { - $blog_settings =& $core->blog->settings; - } - - // definition de la page courante - if ($args == '') { - $GLOBALS['_page_number'] = (integer) 1; - } else { - $current = self::getPageNumber($args); - if ($current) { - $GLOBALS['_page_number'] = (integer) $current; - } - } - // definition du nombre de commentaires par page - $_ctx->nb_comment_per_page=$blog_settings->comliste_nb_comments_per_page; - - // ouverture de la page html - $tplset = $core->themes->moduleInfo($core->blog->settings->system->theme,'tplset'); - if (!empty($tplset) && is_dir(dirname(__FILE__).'/../default-templates/'.$tplset)) { - $core->tpl->setPath($core->tpl->getPath(), dirname(__FILE__).'/../default-templates/'.$tplset); - } else { - $core->tpl->setPath($core->tpl->getPath(), dirname(__FILE__).'/../default-templates/'.DC_DEFAULT_TPLSET); - } - self::serveDocument('comListe.html'); - exit; - } -} - -class tplComListe -{ - public $html_prev = '«prev.'; - public $html_next = 'next»'; - - /* ComListeURL --------------------------------------- */ - public static function comListeURL($attr) - { - $f = $GLOBALS['core']->tpl->getFilters($attr); - return 'blog->url.$core->url->getBase("comListe")').'; ?>'; - } - - /* ComListePageTitle --------------------------------------- */ - public static function comListePageTitle($attr) - { - global $core; - $f = $GLOBALS['core']->tpl->getFilters($attr); - - # Settings compatibility test - if (version_compare(DC_VERSION,'2.2-alpha','>=')) { - return 'blog->settings->comListe->comliste_page_title').'; ?>'; - } else { - return 'blog->settings->comliste_page_title').'; ?>'; - } - } - - /* ComListeNbCommentsPerPage --------------------------------------- */ - public static function comListeNbCommentsPerPage($attr) - { - global $_ctx, $core; - - # Settings compatibility test - if (version_compare(DC_VERSION,'2.2-alpha','>=')) { - $nb_comments_per_page = $_ctx->nb_comment_per_page=$core->blog->settings->comListe->comliste_nb_comments_per_page; - } else { - $nb_comments_per_page = $_ctx->nb_comment_per_page=$core->blog->settings->comliste_nb_comments_per_page; - } - return ''.html::escapeHTML($nb_comments_per_page).''; - } - - /* comListeNbComments --------------------------------------- */ - public static function comListeNbComments($attr) - { - // __('Number of comments') - global $_ctx, $core; - - if(empty($params)) { - $_ctx->pagination = $core->blog->getComments(null,true); - } else { - $_ctx->pagination = $core->blog->getComments($params,true); - unset($params); - } - - if ($_ctx->exists("pagination")) { - $nb_comments = $_ctx->pagination->f(0); - } - return ''.html::escapeHTML($nb_comments).''; - } - - /* ComListeCommentsEntries --------------------------------------- */ - public static function comListeCommentsEntries($attr,$content) - { - global $_ctx, $core; - - # Settings compatibility test - if (version_compare(DC_VERSION,'2.2-alpha','>=')) { - $blog_settings =& $core->blog->settings->comListe; - } else { - $blog_settings =& $core->blog->settings; - } - - $p = - "if (\$_ctx->posts !== null) { ". - "\$params['post_id'] = \$_ctx->posts->post_id; ". - "\$core->blog->withoutPassword(false);\n". - "}\n"; - - if (empty($attr['with_pings'])) { - $p .= "\$params['comment_trackback'] = false;\n"; - } - - $lastn = 0; - if (isset($attr['lastn'])) { - $lastn = abs((integer) $attr['lastn'])+0; - } - - if ($lastn > 0) { - $p .= "\$params['limit'] = ".$lastn.";\n"; - } else { - $p .= "if (\$_ctx->nb_comment_per_page !== null) { \$params['limit'] = \$_ctx->nb_comment_per_page; }\n"; - } - - if (isset($GLOBALS["_page_number"])) { - $_page_number = $GLOBALS["_page_number"]; - $p .= "\$params['limit'] = array(((\$_page_number-1)*\$params['limit']),\$params['limit']);\n"; - } else { - $_page_number = 1; - $p .= "\$params['limit'] = array(0, \$params['limit']);\n"; - } - - if (empty($attr['no_context'])) - { - $p .= - 'if ($_ctx->exists("categories")) { '. - "\$params['cat_id'] = \$_ctx->categories->cat_id; ". - "}\n"; - - $p .= - 'if ($_ctx->exists("langs")) { '. - "\$params['sql'] = \"AND P.post_lang = '\".\$core->blog->con->escape(\$_ctx->langs->post_lang).\"' \"; ". - "}\n"; - } - - // Sens de tri issu des paramètres du plugin - $order = $blog_settings->comliste_comments_order; - if (isset($attr['order']) && preg_match('/^(desc|asc)$/i',$attr['order'])) { - $order = $attr['order']; - } - - $p .= "\$params['order'] = 'comment_dt ".$order."';\n"; - - if (isset($attr['no_content']) && $attr['no_content']) { - $p .= "\$params['no_content'] = true;\n"; - } - - $res = "comments = $core->blog->getComments($params); unset($params);'."\n"; - $res .= "if (\$_ctx->posts !== null) { \$core->blog->withoutPassword(true);}\n"; - - if (!empty($attr['with_pings'])) { - $res .= '$_ctx->pings = $_ctx->comments;'."\n"; - } - - $res .= "?>\n"; - - $res .= - 'comments->fetch()) : ?>'.$content.'comments = null; ?>'; - - return $res; - } - - /* ComListePaginationLinks --------------------------------------- */ - /* Reprise et adaptation de la fonction PaginationLinks du plugin advancedPagination-1.9 */ - public static function comListePaginationLinks($attr) - { - global $_ctx, $core; - - $p = 'blog->url.$args; - - if ($pageNumber > 1) { - $url = preg_replace("#/$#","",$url); - $url .= "/page/".$pageNumber; - } - - if (!empty($_GET["q"])) { - $s = strpos($url,"?") !== false ? "&" : "?"; - $url .= $s."q=".rawurlencode($_GET["q"]); - } - - return "".$linkText." "; - } else { - return $linkText." "; - } - } - - if (isset($GLOBALS["_page_number"])) { - $current = $GLOBALS["_page_number"]; - } else { - $current = 1; - } - - if(empty($params)) { - $_ctx->pagination = $core->blog->getComments(null,true); - } else { - $_ctx->pagination = $core->blog->getComments($params,true); - unset($params); - } - - if ($_ctx->exists("pagination")) { - $nb_comments = $_ctx->pagination->f(0); - } - - # Settings compatibility test - if (version_compare(DC_VERSION,\'2.2-alpha\',\'>=\')) { - $blog_settings =& $core->blog->settings->comListe; - } else { - $blog_settings =& $core->blog->settings; - } - - $nb_per_page = abs((integer) $blog_settings->comliste_nb_comments_per_page); - $nb_pages = ceil($nb_comments/$nb_per_page); - $nb_max_pages = 10; - $nb_sequence = 2*3+1; - $quick_distance = 10; - - if($nb_pages <= $nb_max_pages) { - /* less or equal than 10 pages, simple links */ - for ($i = 1; $i <= $nb_pages; $i++) { - echo comListeMakePageLink($i,$i); - } - } else { - /* more than 10 pages, smart links */ - echo comListeMakePageLink(1,1); - $min_page = max($current - ($nb_sequence - 1) / 2, 2); - $max_page = min($current + ($nb_sequence - 1) / 2, $nb_pages - 1); - if ($min_page > 2) { - echo "..."; - echo " "; - } - - for ($i = $min_page; $i <= $max_page ; $i++) { - echo comListeMakePageLink($i,$i); - } - - if ($max_page < $nb_pages - 1) { - echo "..."; - echo " "; - } - echo comListeMakePageLink($nb_pages,$nb_pages); - - /* quick navigation links */ - if($current >= 1 + $quick_distance) { - echo " "; - echo comListeMakePageLink($current - $quick_distance, "<<"); - } - - if($current <= $nb_pages - $quick_distance) { - echo " "; - echo comListeMakePageLink($current + $quick_distance, ">> "); - } - } - ?>'; - - return $p; - } - - /* ComListeOpenPostTitle --------------------------------------- */ - public static function comListeOpenPostTitle($attr) - { - return __('open post'); - } - - # Widget function - public static function comListeWidget($w) - { - global $core; - - # Settings compatibility test - if (version_compare(DC_VERSION,'2.2-alpha','>=')) { - $blog_settings =& $core->blog->settings->comListe; - } else { - $blog_settings =& $core->blog->settings; - } - - if ($w->offline) - return; - - if (($w->homeonly == 1 && $core->url->type != 'default') || - ($w->homeonly == 2 && $core->url->type == 'default')) { - return; - } - if (!$blog_settings->comliste_enable) { - return; - } - - $res = - ($w->title ? $w->renderTitle(html::escapeHTML($w->title)) : ''). - '

'. - ($w->link_title ? html::escapeHTML($w->link_title) : __('List of comments')). - '

'; - - return $w->renderDiv($w->content_only,'comliste '.$w->class,'',$res); - } - -} - -class extComListe -{ - public static function publicBreadcrumb($context,$separator) - { - if ($context == 'comListe') { - return __('List of comments'); - } - } -} \ No newline at end of file diff --git a/index.php b/index.php index 3c22fe3..762d3bb 100644 --- a/index.php +++ b/index.php @@ -1,158 +1,96 @@ =')) { - $core->blog->settings->addNamespace('comListe'); - $blog_settings =& $core->blog->settings->comListe; - $system_settings = $core->blog->settings->system; -} else { - $core->blog->settings->setNamespace('comListe'); - $blog_settings =& $core->blog->settings; - $system_settings =& $core->blog->settings; +/** + * @brief comListe, a plugin for Dotclear 2 + * + * @package Dotclear + * @subpackage Plugin + * + * @author Benoit de Marne, Pierre Van Glabeke and contributors + * + * @copyright Jean-Christian Denis + * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html + */ +if (!defined('DC_CONTEXT_ADMIN')) { + return null; } -// initilisation des variables -$action = !empty($_REQUEST['action']) ? $_REQUEST['action'] : null; +dcPage::check(dcCore::app()->auth->makePermissions([ + dcAuth::PERMISSION_ADMIN, +])); -// Setting default parameters if missing configuration -if (is_null($blog_settings->comliste_enable)) { - try { - $blog_settings->put('comliste_enable',false,'boolean','Enable comListe'); - $core->blog->triggerBlog(); - http::redirect(http::getSelfURI()); - } - catch (Exception $e) { - $core->error->add($e->getMessage()); - } +$s = dcCore::app()->blog->settings->get(basename(__dir__)); +$action = $_REQUEST['action'] ?? null; +$order_combo = [ + __('Ascending') => 'asc', + __('Descending') => 'desc', +]; + +if ($action == 'saveconfig') { + try { + if (empty($_POST['comliste_page_title'])) { + throw new Exception(__('No page title.')); + } + + $s->put('enable', !empty($_POST['comliste_enable'])); + $s->put('comliste_page_title', $_POST['comliste_page_title']); + $s->put('comliste_nb_comments_per_page', $_POST['comliste_nb_comments_per_page'] ?? 10); + $s->put('comliste_comments_order', $_POST['comliste_comments_order'] == 'asc' ? 'asc' : 'desc'); + + dcCore::app()->blog->triggerBlog(); + + dcAdminNotices::addSuccessNotice( + __('Configuration successfully updated.') + ); + + dcCore::app()->adminurl->redirect( + 'admin.plugin.' . basename(__DIR__) + ); + } catch (Exception $e) { + dcCore::app()->error->add($e->getMessage()); + } } -// Getting current parameters -$comliste_enable = (boolean)$blog_settings->comliste_enable; -$comliste_page_title = $blog_settings->comliste_page_title; -$comliste_nb_comments_per_page = $blog_settings->comliste_nb_comments_per_page; -$comliste_comments_order = $blog_settings->comliste_comments_order; +echo ' +' . __('Comments list') . '' . +dcPage::breadcrumb([ + html::escapeHTML(dcCore::app()->blog->name) => '', + __('Comments list') => '', +]) . +dcPage::notices() . -if ($comliste_page_title === null) { - $comliste_page_title = __('List of comments'); -} -if ($comliste_nb_comments_per_page === null) { - $comliste_nb_comments_per_page = 10; -} -if ($comliste_comments_order === null) { - $comliste_comments_order = 'desc'; -} +'
' . +'

' . __('Plugin activation') . '

' . -// Saving new configuration -if ($action == 'saveconfig') -{ - try { - - // Enable plugin - $comliste_enable = (empty($_POST['comliste_enable']))?false:true; - - // Title page - $comliste_page_title = $_POST['comliste_page_title']; - if (empty($_POST['comliste_page_title'])) { - throw new Exception(__('No page title.')); - } +'

' . - // Number of comments per page - $comliste_nb_comments_per_page = !empty($_POST['comliste_nb_comments_per_page'])?$_POST['comliste_nb_comments_per_page']:$comliste_nb_comments_per_page; - - // Order - $comliste_comments_order = !empty($_POST['comliste_comments_order'])?$_POST['comliste_comments_order']:$comliste_comments_order; - - // Insert settings values - $blog_settings->put('comliste_enable',$comliste_enable,'boolean','Enable comListe'); - $blog_settings->put('comliste_page_title',$comliste_page_title,'string','Title page'); - $blog_settings->put('comliste_nb_comments_per_page',$comliste_nb_comments_per_page,'integer','Number of comments per page'); - $blog_settings->put('comliste_comments_order',$comliste_comments_order,'string','Comments order'); - - $core->blog->triggerBlog(); +'
' . +'

' . __('General options') . '

' . - http::redirect($p_url.'&saveconfig=1'); - - } catch (Exception $e) { - $core->error->add($e->getMessage()); - } -} +'

' . +form::field('comliste_page_title', 30, 255, (string) $s->get('page_title')) . +'

' . -?> +'

' . +form::number('comliste_nb_comments_per_page', ['min' => 0, 'max' => 99, 'default' => (int) $s->get('nb_comments_per_page')]) . +'

' . - - +'

' . +form::combo('comliste_comments_order', $order_combo, $s->get('comments_order') == 'asc' ? 'asc' : 'desc') . +'

' . - - - <?php echo $page_title; ?> - +'
- - +

' . +form::hidden(['action'], 'saveconfig') . +dcCore::app()->formNonce() . ' + +

-blog->name) => '', - ''.$page_title.'' => '' - )); +
'; -if (!empty($_GET['saveconfig'])) { - dcPage::success(__('Settings have been successfully updated.')); -} -?> +dcPage::helpBlock('comListe'); - 'asc', -__('Descending') => 'desc' ); - - // comListe plugin configuration - if ($core->auth->check('admin',$core->blog->id)) - { - echo - '
'. - '

'. __('Plugin activation').'

'. - '

'. - '

'. - '
'. - '

'. __('General options').'

'. - '

'. - '

'. - '

'. - '
'. - '

'. - $core->formNonce(). - form::hidden(array('action'),'saveconfig'). - form::hidden(array('p'),'comListe').'

'. - '
'; - } - -?> - - - - - \ No newline at end of file +echo ''; diff --git a/locales/en/resources.php b/locales/en/resources.php index 96aa196..b0f4a5c 100644 --- a/locales/en/resources.php +++ b/locales/en/resources.php @@ -1,15 +1,13 @@ resources['help']['comListe'] = __DIR__ . '/help/comListe.html'; diff --git a/locales/fr/resources.php b/locales/fr/resources.php index 96aa196..b0f4a5c 100644 --- a/locales/fr/resources.php +++ b/locales/fr/resources.php @@ -1,15 +1,13 @@ resources['help']['comListe'] = __DIR__ . '/help/comListe.html';