diff --git a/ConstCategoriesPage.php b/ConstCategoriesPage.php deleted file mode 100644 index 4fd78d0..0000000 --- a/ConstCategoriesPage.php +++ /dev/null @@ -1,19 +0,0 @@ -registerModule( - /* Name */ 'CategoriesPage', - /* Description*/ 'Add a category list page', - /* Author */ 'Pierre Van Glabeke, Bernard Le Roux', - /* Version */ '0.6', - /* Properties */ - array( - 'permissions' => 'admin', - 'type' => 'plugin', - 'dc_min' => '2.9', - 'support' => 'http://forum.dotclear.org/viewtopic.php?pid=326224#p326224', - 'details' => 'http://plugins.dotaddict.org/dc2/details/categoriesPage' - ) -); \ No newline at end of file + 'Categories Page', + 'Add a public page for categories list', + 'Pierre Van Glabeke, Bernard Le Roux and Contributors', + '0.7', + [ + 'requires' => [['core', '2.24']], + 'permissions' => dcCore::app()->auth->makePermissions([ + dcAuth::PERMISSION_ADMIN, + ]), + 'type' => 'plugin', + 'support' => 'https://github.com/JcDenis/CategoriesPage', + 'details' => 'https://plugins.dotaddict.org/dc2/details/CategoriesPage', + 'repository' => 'https://raw.githubusercontent.com/JcDenis/CategoriesPage/master/dcstore.xml', + + ] +); diff --git a/_prepend.php b/_prepend.php new file mode 100644 index 0000000..568d43d --- /dev/null +++ b/_prepend.php @@ -0,0 +1,26 @@ +url->register('categories', 'categories', '^categories$', ['urlCategoriesPage', 'categories']); + +class urlCategoriesPage extends dcUrlHandlers +{ + public static function categories($args) + { + self::serveDocument('categories.html'); + exit; + } +} diff --git a/_public.php b/_public.php index 99cc77f..bacdbe3 100644 --- a/_public.php +++ b/_public.php @@ -1,79 +1,42 @@ tpl; - $tpl->addValue('CategoryCount', array('tplCategories', 'CategoryCount')); - $tpl->addValue('CategoriesURL', array('tplCategories', 'CategoriesURL')); - // Adds a new template behavior : - $core->addBehavior('publicBeforeDocument', array('behaviorCategoriesPage', 'addTplPath')); - // 'categories' urlHandler : - $core->url->register('categories', 'categories', '^categories$', array('urlCategories', 'categories')); - // compatibilité avec Breadcrumb - $core->addBehavior('publicBreadcrumb', array('extCategoriesPage', 'publicBreadcrumb')); - } -} - -class tplCategories { - // Use tag : {{tpl:CategoryCount}} - public static function CategoryCount($attr) { - $f = $GLOBALS['core']->tpl->getFilters($attr); - return - 'categories->nb_post') . '; ?>'; - } - // Use tag : {{tpl:CategoriesURL}} - public static function CategoriesURL($attr) { - $f = $GLOBALS['core']->tpl->getFilters($attr); - return - 'blog->url.$core->url->getBase("categories")') . '; ?>'; - } -} - -class behaviorCategoriesPage { - public static function addTplPath($core) { - $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); - } - } -} - -class urlCategories extends dcUrlHandlers { - public static function categories($args) { - # The entry - self::serveDocument('categories.html'); - exit; - } -} - -class extCategoriesPage -{ - public static function publicBreadcrumb($context,$separator) - { - if ($context == 'categories') { - return __('Categories Page'); +// public behavior +dcCore::app()->addBehavior('publicBeforeDocumentV2', function () { + $tplset = dcCore::app()->themes->moduleInfo(dcCore::app()->blog->settings->system->theme, 'tplset'); + if (!empty($tplset) && is_dir(__DIR__ . '/default-templates/' . $tplset)) { + dcCore::app()->tpl->setPath(dcCore::app()->tpl->getPath(), __DIR__ . '/default-templates/' . $tplset); + } else { + dcCore::app()->tpl->setPath(dcCore::app()->tpl->getPath(), __DIR__ . '/default-templates/' . DC_DEFAULT_TPLSET); } - } -} \ No newline at end of file +}); + +// breacrumb addon +dcCore::app()->addBehavior('publicBreadcrumb', function ($context, $separator) { + if ($context == 'categories') { + return __('Categories Page'); + } +}); + +// tpl values +dcCore::app()->tpl->addValue('CategoryCount', function ($attr) { + return 'tpl->getFilters($attr), 'dcCore::app()->ctx->categories->nb_post') . '; ?>'; +}); +dcCore::app()->tpl->addValue('CategoriesURL', function ($attr) { + return 'tpl->getFilters($attr), 'dcCore::app()->blog->url.dcCore::app()->url->getBase("categories")') . '; ?>'; +}); diff --git a/_widgets.php b/_widgets.php index ab8519c..ad32554 100644 --- a/_widgets.php +++ b/_widgets.php @@ -1,72 +1,59 @@ addBehavior('initWidgets', ['widgetsCategoriesPage', 'initWidgets']); +class widgetsCategoriesPage +{ + public static function initWidgets($w) + { + $w + ->create( + 'CategoriesPage', + __('Categories Page'), + ['widgetsCategoriesPage', 'categoriesPageWidgets'], + null, + __('Link to categories') + ) + ->addTitle(__('Categories Page')) + ->addHomeOnly() + ->addContentOnly() + ->addClass() + ->addOffline(); + } -class widgetsCategoriesPage { - /* - * initialisation du context widget - */ - public static function main() { - require_once __DIR__.'/ConstCategoriesPage.php'; - - $core = $GLOBALS['core']; + public static function categoriesPageWidgets($w) + { + if ($w->offline) { + return; + } - $core->addBehavior('initWidgets', array('widgetsCategoriesPage', 'initWidgets')); - } - - // Widget function - public static function categoriesPageWidgets($widget) { - $core = $GLOBALS['core']; - - $url = $core->url; - - if ($widget->offline) - return; - - if (($widget->homeonly == 1 && $url->type !== 'default') || - ($widget->homeonly == 2 && $url->type === 'default')) { - return; - } - - $res = - ($widget->title ? $widget->renderTitle(html::escapeHTML($widget->title)) : ''). - '
'. - ($widget->link_title ? html::escapeHTML($widget->link_title) : __('All categories')). - '
'; - - return $widget->renderDiv($widget->content_only,'categories '.$widget->class,'',$res); - } - - public static function initWidgets($widget) { - $text = __('Categories Page'); - $widget->create('CategoriesPage', __('CategoriesPage'), array('widgetsCategoriesPage', 'categoriesPageWidgets'), - null, - __('Link to categories')); - $categoriesPage = $widget->CategoriesPage; - $categoriesPage->setting('title', __('Title:'), $text, 'text'); - $categoriesPage->setting('homeonly', __('Display on:'), 0, 'combo', array( - __('All pages') => 0, - __('Home page only') => 1, - __('Except on home page') => 2 - ) - ); - $categoriesPage->setting('content_only', __('Content only'), 0, 'check'); - $categoriesPage->setting('class', __('CSS class:'), ''); - $categoriesPage->setting('offline',__('Offline'),0,'check'); - } + if (($w->homeonly == 1 && !dcCore::app()->url->isHome(dcCore::app()->url->type)) + || ($w->homeonly == 2 && dcCore::app()->url->isHome(dcCore::app()->url->type))) { + return null; + } + return $w->renderDiv( + $w->content_only, + 'categories ' . $w->class, + '', + ($w->title ? $w->renderTitle(html::escapeHTML($w->title)) : '') . + '' . + ($w->link_title ? html::escapeHTML($w->link_title) : __('All categories')) . + '
' + ); + } }