update to dotclear 2.24 and code review
This commit is contained in:
parent
4920b7a4fd
commit
c46c0eb8ed
6 changed files with 156 additions and 193 deletions
|
@ -1,19 +0,0 @@
|
||||||
<?php
|
|
||||||
/* -- BEGIN LICENSE BLOCK ----------------------------------
|
|
||||||
#
|
|
||||||
# This file is part of Categories Page, a plugin for Dotclear 2.
|
|
||||||
#
|
|
||||||
# Copyright (c) 2013 Pierre Van Glabeke, Bernard Le Roux
|
|
||||||
# Licensed under the GPL version 2.0 license.
|
|
||||||
# See LICENSE file or
|
|
||||||
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
||||||
#
|
|
||||||
# -- END LICENSE BLOCK ------------------------------------ */
|
|
||||||
if (!defined('DC_RC_PATH')) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
class ConstCategoriesPage {
|
|
||||||
const VERSION = '0.6';
|
|
||||||
const NS = 'CategoriesPage';
|
|
||||||
const PARAM = 'CategoriesPage';
|
|
||||||
}
|
|
25
_admin.php
25
_admin.php
|
@ -1,16 +1,17 @@
|
||||||
<?php
|
<?php
|
||||||
/* -- BEGIN LICENSE BLOCK ----------------------------------
|
/**
|
||||||
#
|
* @brief CategoriesPage, a plugin for Dotclear 2
|
||||||
# This file is part of Categories Page, a plugin for Dotclear 2.
|
*
|
||||||
#
|
* @package Dotclear
|
||||||
# Copyright (c) 2013 Pierre Van Glabeke, Bernard Le Roux
|
* @subpackage Plugin
|
||||||
# Licensed under the GPL version 2.0 license.
|
*
|
||||||
# See LICENSE file or
|
* @author Pierre Van Glabeke, Bernard Le Roux and Contributors
|
||||||
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
*
|
||||||
#
|
* @copyright Jean-Christian Denis
|
||||||
# -- END LICENSE BLOCK ------------------------------------*/
|
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||||
|
*/
|
||||||
if (!defined('DC_CONTEXT_ADMIN')) {
|
if (!defined('DC_CONTEXT_ADMIN')) {
|
||||||
return;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
require_once __DIR__.'/_widgets.php';
|
require __DIR__ . '/_widgets.php';
|
||||||
|
|
51
_define.php
51
_define.php
|
@ -1,28 +1,33 @@
|
||||||
<?php
|
<?php
|
||||||
/* -- BEGIN LICENSE BLOCK ----------------------------------
|
/**
|
||||||
#
|
* @brief CategoriesPage, a plugin for Dotclear 2
|
||||||
# This file is part of Categories Page, a plugin for Dotclear 2.
|
*
|
||||||
#
|
* @package Dotclear
|
||||||
# Copyright (c) 2013 Pierre Van Glabeke, Bernard Le Roux
|
* @subpackage Plugin
|
||||||
# Licensed under the GPL version 2.0 license.
|
*
|
||||||
# See LICENSE file or
|
* @author Pierre Van Glabeke, Bernard Le Roux and Contributors
|
||||||
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
*
|
||||||
#
|
* @copyright Jean-Christian Denis
|
||||||
# -- END LICENSE BLOCK ------------------------------------*/
|
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||||
|
*/
|
||||||
if (!defined('DC_RC_PATH')) {
|
if (!defined('DC_RC_PATH')) {
|
||||||
return;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->registerModule(
|
$this->registerModule(
|
||||||
/* Name */ 'CategoriesPage',
|
'Categories Page',
|
||||||
/* Description*/ 'Add a category list page',
|
'Add a public page for categories list',
|
||||||
/* Author */ 'Pierre Van Glabeke, Bernard Le Roux',
|
'Pierre Van Glabeke, Bernard Le Roux and Contributors',
|
||||||
/* Version */ '0.6',
|
'0.7',
|
||||||
/* Properties */
|
[
|
||||||
array(
|
'requires' => [['core', '2.24']],
|
||||||
'permissions' => 'admin',
|
'permissions' => dcCore::app()->auth->makePermissions([
|
||||||
'type' => 'plugin',
|
dcAuth::PERMISSION_ADMIN,
|
||||||
'dc_min' => '2.9',
|
]),
|
||||||
'support' => 'http://forum.dotclear.org/viewtopic.php?pid=326224#p326224',
|
'type' => 'plugin',
|
||||||
'details' => 'http://plugins.dotaddict.org/dc2/details/categoriesPage'
|
'support' => 'https://github.com/JcDenis/CategoriesPage',
|
||||||
)
|
'details' => 'https://plugins.dotaddict.org/dc2/details/CategoriesPage',
|
||||||
|
'repository' => 'https://raw.githubusercontent.com/JcDenis/CategoriesPage/master/dcstore.xml',
|
||||||
|
|
||||||
|
]
|
||||||
);
|
);
|
26
_prepend.php
Normal file
26
_prepend.php
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @brief CategoriesPage, a plugin for Dotclear 2
|
||||||
|
*
|
||||||
|
* @package Dotclear
|
||||||
|
* @subpackage Plugin
|
||||||
|
*
|
||||||
|
* @author Pierre Van Glabeke, Bernard Le Roux and Contributors
|
||||||
|
*
|
||||||
|
* @copyright Jean-Christian Denis
|
||||||
|
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||||
|
*/
|
||||||
|
if (!defined('DC_RC_PATH')) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
dcCore::app()->url->register('categories', 'categories', '^categories$', ['urlCategoriesPage', 'categories']);
|
||||||
|
|
||||||
|
class urlCategoriesPage extends dcUrlHandlers
|
||||||
|
{
|
||||||
|
public static function categories($args)
|
||||||
|
{
|
||||||
|
self::serveDocument('categories.html');
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
}
|
109
_public.php
109
_public.php
|
@ -1,79 +1,42 @@
|
||||||
<?php
|
<?php
|
||||||
/* -- BEGIN LICENSE BLOCK ----------------------------------
|
/**
|
||||||
#
|
* @brief CategoriesPage, a plugin for Dotclear 2
|
||||||
# This file is part of Categories Page, a plugin for Dotclear 2.
|
*
|
||||||
#
|
* @package Dotclear
|
||||||
# Copyright (c) 2013 Pierre Van Glabeke, Bernard Le Roux
|
* @subpackage Plugin
|
||||||
# Licensed under the GPL version 2.0 license.
|
*
|
||||||
# See LICENSE file or
|
* @author Pierre Van Glabeke, Bernard Le Roux and Contributors
|
||||||
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
*
|
||||||
#
|
* @copyright Jean-Christian Denis
|
||||||
# -- END LICENSE BLOCK ------------------------------------ */
|
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||||
|
*/
|
||||||
if (!defined('DC_RC_PATH')) {
|
if (!defined('DC_RC_PATH')) {
|
||||||
return;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
publicCategoriesPage::main();
|
require __DIR__ . '/_widgets.php';
|
||||||
|
|
||||||
class publicCategoriesPage {
|
// public behavior
|
||||||
|
dcCore::app()->addBehavior('publicBeforeDocumentV2', function () {
|
||||||
public static function main() {
|
$tplset = dcCore::app()->themes->moduleInfo(dcCore::app()->blog->settings->system->theme, 'tplset');
|
||||||
$core = $GLOBALS['core'];
|
if (!empty($tplset) && is_dir(__DIR__ . '/default-templates/' . $tplset)) {
|
||||||
require_once __DIR__.'/_widgets.php';
|
dcCore::app()->tpl->setPath(dcCore::app()->tpl->getPath(), __DIR__ . '/default-templates/' . $tplset);
|
||||||
|
} else {
|
||||||
// Adds news Categories' templates tags :
|
dcCore::app()->tpl->setPath(dcCore::app()->tpl->getPath(), __DIR__ . '/default-templates/' . DC_DEFAULT_TPLSET);
|
||||||
$tpl = $core->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
|
|
||||||
'<?php echo ' . sprintf($f, '$_ctx->categories->nb_post') . '; ?>';
|
|
||||||
}
|
|
||||||
// Use tag : {{tpl:CategoriesURL}}
|
|
||||||
public static function CategoriesURL($attr) {
|
|
||||||
$f = $GLOBALS['core']->tpl->getFilters($attr);
|
|
||||||
return
|
|
||||||
'<?php echo ' . sprintf($f, '$core->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');
|
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
}
|
|
||||||
|
// 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 '<?php echo ' . sprintf(dcCore::app()->tpl->getFilters($attr), 'dcCore::app()->ctx->categories->nb_post') . '; ?>';
|
||||||
|
});
|
||||||
|
dcCore::app()->tpl->addValue('CategoriesURL', function ($attr) {
|
||||||
|
return '<?php echo ' . sprintf(dcCore::app()->tpl->getFilters($attr), 'dcCore::app()->blog->url.dcCore::app()->url->getBase("categories")') . '; ?>';
|
||||||
|
});
|
||||||
|
|
113
_widgets.php
113
_widgets.php
|
@ -1,72 +1,59 @@
|
||||||
<?php
|
<?php
|
||||||
/* -- BEGIN LICENSE BLOCK ----------------------------------
|
/**
|
||||||
#
|
* @brief CategoriesPage, a plugin for Dotclear 2
|
||||||
# This file is part of Categories Page, a plugin for Dotclear 2.
|
*
|
||||||
#
|
* @package Dotclear
|
||||||
# Copyright (c) 2013 Pierre Van Glabeke, Bernard Le Roux
|
* @subpackage Plugin
|
||||||
# Licensed under the GPL version 2.0 license.
|
*
|
||||||
# See LICENSE file or
|
* @author Pierre Van Glabeke, Bernard Le Roux and Contributors
|
||||||
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
*
|
||||||
#
|
* @copyright Jean-Christian Denis
|
||||||
# -- END LICENSE BLOCK ------------------------------------ */
|
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||||
|
*/
|
||||||
if (!defined('DC_RC_PATH')) {
|
if (!defined('DC_RC_PATH')) {
|
||||||
return;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
widgetsCategoriesPage::main();
|
dcCore::app()->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 {
|
public static function categoriesPageWidgets($w)
|
||||||
/*
|
{
|
||||||
* initialisation du context widget
|
if ($w->offline) {
|
||||||
*/
|
return;
|
||||||
public static function main() {
|
}
|
||||||
require_once __DIR__.'/ConstCategoriesPage.php';
|
|
||||||
|
|
||||||
$core = $GLOBALS['core'];
|
if (($w->homeonly == 1 && !dcCore::app()->url->isHome(dcCore::app()->url->type))
|
||||||
|
|| ($w->homeonly == 2 && dcCore::app()->url->isHome(dcCore::app()->url->type))) {
|
||||||
$core->addBehavior('initWidgets', array('widgetsCategoriesPage', 'initWidgets'));
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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)) : '').
|
|
||||||
'<p><a href="'.$core->blog->url.$core->url->getBase('categories').'">'.
|
|
||||||
($widget->link_title ? html::escapeHTML($widget->link_title) : __('All categories')).
|
|
||||||
'</a></p>';
|
|
||||||
|
|
||||||
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');
|
|
||||||
}
|
|
||||||
|
|
||||||
|
return $w->renderDiv(
|
||||||
|
$w->content_only,
|
||||||
|
'categories ' . $w->class,
|
||||||
|
'',
|
||||||
|
($w->title ? $w->renderTitle(html::escapeHTML($w->title)) : '') .
|
||||||
|
'<p><a href="' . dcCore::app()->blog->url . dcCore::app()->url->getBase('categories') . '">' .
|
||||||
|
($w->link_title ? html::escapeHTML($w->link_title) : __('All categories')) .
|
||||||
|
'</a></p>'
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue