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';
|
||||
}
|
27
_admin.php
27
_admin.php
|
@ -1,16 +1,17 @@
|
|||
<?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_CONTEXT_ADMIN')) {
|
||||
return;
|
||||
/**
|
||||
* @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_CONTEXT_ADMIN')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
require_once __DIR__.'/_widgets.php';
|
||||
require __DIR__ . '/_widgets.php';
|
||||
|
|
55
_define.php
55
_define.php
|
@ -1,28 +1,33 @@
|
|||
<?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;
|
||||
/**
|
||||
* @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;
|
||||
}
|
||||
|
||||
$this->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'
|
||||
)
|
||||
);
|
||||
'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',
|
||||
|
||||
]
|
||||
);
|
||||
|
|
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
|
||||
/* -- 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 ------------------------------------ */
|
||||
/**
|
||||
* @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;
|
||||
return null;
|
||||
}
|
||||
|
||||
publicCategoriesPage::main();
|
||||
require __DIR__ . '/_widgets.php';
|
||||
|
||||
class publicCategoriesPage {
|
||||
|
||||
public static function main() {
|
||||
$core = $GLOBALS['core'];
|
||||
require_once __DIR__.'/_widgets.php';
|
||||
|
||||
// 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 {
|
||||
$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);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// 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
|
||||
/* -- 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 ------------------------------------ */
|
||||
/**
|
||||
* @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;
|
||||
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 {
|
||||
/*
|
||||
* 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)) : '').
|
||||
'<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');
|
||||
}
|
||||
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)) : '') .
|
||||
'<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