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';
|
||||||
|
|
49
_define.php
49
_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([
|
||||||
|
dcAuth::PERMISSION_ADMIN,
|
||||||
|
]),
|
||||||
'type' => 'plugin',
|
'type' => 'plugin',
|
||||||
'dc_min' => '2.9',
|
'support' => 'https://github.com/JcDenis/CategoriesPage',
|
||||||
'support' => 'http://forum.dotclear.org/viewtopic.php?pid=326224#p326224',
|
'details' => 'https://plugins.dotaddict.org/dc2/details/CategoriesPage',
|
||||||
'details' => 'http://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;
|
||||||
|
}
|
||||||
|
}
|
99
_public.php
99
_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);
|
||||||
|
|
||||||
// Adds news Categories' templates tags :
|
|
||||||
$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 {
|
} else {
|
||||||
$core->tpl->setPath($core->tpl->getPath(), dirname(__FILE__).'/default-templates/'.DC_DEFAULT_TPLSET);
|
dcCore::app()->tpl->setPath(dcCore::app()->tpl->getPath(), __DIR__ . '/default-templates/' . DC_DEFAULT_TPLSET);
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
}
|
|
||||||
|
|
||||||
class urlCategories extends dcUrlHandlers {
|
// breacrumb addon
|
||||||
public static function categories($args) {
|
dcCore::app()->addBehavior('publicBreadcrumb', function ($context, $separator) {
|
||||||
# The entry
|
|
||||||
self::serveDocument('categories.html');
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class extCategoriesPage
|
|
||||||
{
|
|
||||||
public static function publicBreadcrumb($context,$separator)
|
|
||||||
{
|
|
||||||
if ($context == 'categories') {
|
if ($context == 'categories') {
|
||||||
return __('Categories Page');
|
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")') . '; ?>';
|
||||||
|
});
|
||||||
|
|
125
_widgets.php
125
_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')) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
widgetsCategoriesPage::main();
|
|
||||||
|
|
||||||
|
|
||||||
class widgetsCategoriesPage {
|
|
||||||
/*
|
|
||||||
* initialisation du context widget
|
|
||||||
*/
|
*/
|
||||||
public static function main() {
|
if (!defined('DC_RC_PATH')) {
|
||||||
require_once __DIR__.'/ConstCategoriesPage.php';
|
return null;
|
||||||
|
}
|
||||||
$core = $GLOBALS['core'];
|
|
||||||
|
dcCore::app()->addBehavior('initWidgets', ['widgetsCategoriesPage', 'initWidgets']);
|
||||||
$core->addBehavior('initWidgets', array('widgetsCategoriesPage', 'initWidgets'));
|
|
||||||
}
|
class widgetsCategoriesPage
|
||||||
|
{
|
||||||
// Widget function
|
public static function initWidgets($w)
|
||||||
public static function categoriesPageWidgets($widget) {
|
{
|
||||||
$core = $GLOBALS['core'];
|
$w
|
||||||
|
->create(
|
||||||
$url = $core->url;
|
'CategoriesPage',
|
||||||
|
__('Categories Page'),
|
||||||
if ($widget->offline)
|
['widgetsCategoriesPage', 'categoriesPageWidgets'],
|
||||||
return;
|
null,
|
||||||
|
__('Link to categories')
|
||||||
if (($widget->homeonly == 1 && $url->type !== 'default') ||
|
)
|
||||||
($widget->homeonly == 2 && $url->type === 'default')) {
|
->addTitle(__('Categories Page'))
|
||||||
return;
|
->addHomeOnly()
|
||||||
}
|
->addContentOnly()
|
||||||
|
->addClass()
|
||||||
$res =
|
->addOffline();
|
||||||
($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')).
|
public static function categoriesPageWidgets($w)
|
||||||
'</a></p>';
|
{
|
||||||
|
if ($w->offline) {
|
||||||
return $widget->renderDiv($widget->content_only,'categories '.$widget->class,'',$res);
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function initWidgets($widget) {
|
if (($w->homeonly == 1 && !dcCore::app()->url->isHome(dcCore::app()->url->type))
|
||||||
$text = __('Categories Page');
|
|| ($w->homeonly == 2 && dcCore::app()->url->isHome(dcCore::app()->url->type))) {
|
||||||
$widget->create('CategoriesPage', __('CategoriesPage'), array('widgetsCategoriesPage', 'categoriesPageWidgets'),
|
return null;
|
||||||
null,
|
}
|
||||||
__('Link to categories'));
|
|
||||||
$categoriesPage = $widget->CategoriesPage;
|
return $w->renderDiv(
|
||||||
$categoriesPage->setting('title', __('Title:'), $text, 'text');
|
$w->content_only,
|
||||||
$categoriesPage->setting('homeonly', __('Display on:'), 0, 'combo', array(
|
'categories ' . $w->class,
|
||||||
__('All pages') => 0,
|
'',
|
||||||
__('Home page only') => 1,
|
($w->title ? $w->renderTitle(html::escapeHTML($w->title)) : '') .
|
||||||
__('Except on home page') => 2
|
'<p><a href="' . dcCore::app()->blog->url . dcCore::app()->url->getBase('categories') . '">' .
|
||||||
)
|
($w->link_title ? html::escapeHTML($w->link_title) : __('All categories')) .
|
||||||
);
|
'</a></p>'
|
||||||
$categoriesPage->setting('content_only', __('Content only'), 0, 'check');
|
);
|
||||||
$categoriesPage->setting('class', __('CSS class:'), '');
|
}
|
||||||
$categoriesPage->setting('offline',__('Offline'),0,'check');
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue