réorganisation du code, nouvel icone

This commit is contained in:
blr21560 2013-11-01 11:55:10 +01:00
parent b42ad08e34
commit de4039bb04
8 changed files with 264 additions and 145 deletions

20
ConstCategoriesPage.php Normal file
View file

@ -0,0 +1,20 @@
<?php
/* -- BEGIN LICENSE BLOCK ----------------------------------
#
# This file is part of Categories Page, a plugin for Dotclear 2.
#
# Copyright (c) 2013 Adjaya and contributors
# 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.1';
const NS = 'CategoriesPage';
const PARAM = 'CategoriesPage';
const PLUGIN_IS_ACTIVE = 'categoriespage_active';
}

View file

@ -1,37 +1,33 @@
<?php
# -- BEGIN LICENSE BLOCK ----------------------------------
/* -- BEGIN LICENSE BLOCK ----------------------------------
#
# This file is part of Categories Page, a plugin for Dotclear 2.
#
# Copyright (c) 2007-2011 Adjaya and contributors
# 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; }
# -- END LICENSE BLOCK ------------------------------------*/
if (!defined('DC_CONTEXT_ADMIN')) {
return;
}
require_once dirname(__FILE__).'/_widgets.php';
$core->addBehavior('adminBlogPreferencesForm',array('categoriespageAdminBehaviors','adminBlogPreferencesForm'));
$core->addBehavior('adminBeforeBlogSettingsUpdate',array('categoriespageAdminBehaviors','adminBeforeBlogSettingsUpdate'));
categoriespageAdminBehaviors::main();
class categoriespageAdminBehaviors
{
public static function adminBlogPreferencesForm($core,$settings)
{
echo
'<div class="fieldset"><h4>'.__('Categories Page').'</h4>'.
'<p><label class="classic">'.
form::checkbox('categoriespage_active','1',$settings->categoriespage->categoriespage_active).
__('Enable Categories Page').'</label></p>'.
'</div>';
}
public static function adminBeforeBlogSettingsUpdate($settings)
{
$settings->addNameSpace('categoriespage');
$settings->categoriespage->put('categoriespage_active',!empty($_POST['categoriespage_active']),'boolean');
$settings->addNameSpace('system');
}
public static function main() {
require_once '/_widgets.php';
$menu = $GLOBALS['_menu'];
$core = $GLOBALS['core'];
$menu['Plugins']->addItem(
ConstCategoriesPage::NS,
'plugin.php?p='.ConstCategoriesPage::PARAM,
'index.php?pf='.ConstCategoriesPage::PARAM.'/icon.png',
preg_match('/plugin.php\?p='.ConstCategoriesPage::PARAM.'(&.*)?$/',$_SERVER['REQUEST_URI']),
$core->auth->isSuperAdmin());
}
}

View file

@ -1,21 +1,24 @@
<?php
# -- BEGIN LICENSE BLOCK ----------------------------------
/* -- BEGIN LICENSE BLOCK ----------------------------------
#
# This file is part of Categories Page, a plugin for Dotclear 2.
#
# Copyright (c) 2007-2011 Adjaya and contributors
# 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; }
# -- END LICENSE BLOCK ------------------------------------*/
if (!defined('DC_RC_PATH')) {
return;
}
require_once 'ConstCategoriesPage.php';
$this->registerModule(
/* Name */ "Categories Page",
/* Description*/ "Add a category list page",
/* Author */ "Adjaya, Pierre Van Glabeke",
/* Version */ '0.1',
/* Name */ 'Categories Page',
/* Description*/ 'Add a category list page / Ajoute une page listant les catégories',
/* Author */ 'Pierre Van Glabeke, Bernard Le Roux',
/* Version */ ConstCategoriesPage::VERSION,
/* Properties */
array(
'permissions' => 'admin',

View file

@ -1,91 +1,89 @@
<?php
# -- BEGIN LICENSE BLOCK ----------------------------------
#
# This file is part of Categories Page, a plugin for Dotclear 2.
#
# Copyright (c) 2007-2011 Adjaya and contributors
# 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; }
/* -- 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;
}
# If categoriesPage is not active we stop here :
if (!$core->blog->settings->categoriespage->categoriespage_active) { return; }
publicCategoriesPage::main();
require_once dirname(__FILE__).'/_widgets.php';
class publicCategoriesPage {
# Adds news Categories' templates tags :
$GLOBALS['core']->tpl->addValue('CategoryCount',array('tplCategories','CategoryCount'));
$GLOBALS['core']->tpl->addBlock('EntryIfCategoriesPage',array('tplCategories','EntryIfCategoriesPage'));
$GLOBALS['core']->tpl->addValue('CategoriesURL',array('tplCategories','CategoriesURL'));
public static function main() {
class tplCategories
{
require_once 'ConstCategoriesPage.php';
$core = $GLOBALS['core'];
$ns = $core->blog->settings->addNamespace(ConstCategoriesPage::NS);
// If categoriesPage is not active we stop here :
if (!$ns->get(ConstCategoriesPage::PLUGIN_IS_ACTIVE)) {
return;
}
require_once '/_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)
{
Use tag : {{tpl:CategoryCount}}
*/
public static function CategoryCount($attr) {
$f = $GLOBALS['core']->tpl->getFilters($attr);
return
'<?php echo '.sprintf($f,'$_ctx->categories->nb_post').'; ?>';
'<?php echo ' . sprintf($f, '$_ctx->categories->nb_post') . '; ?>';
}
/*
Use : <tpl:EntryIfCategoriesPage>
</tpl:EntryIfCategoriesPage>
Use tag : {{tpl:CategoriesURL}}
*/
public static function EntryIfCategoriesPage($attr,$content)
{
return
"<?php if (\$core->blog->settings->categoriespage->categoriespage_active) : ?>".
$content.
"<?php endif; ?>";
}
/*
Use tag : {{tpl:CategoriesURL}}
*/
public static function CategoriesURL($attr)
{
public static function CategoriesURL($attr) {
$f = $GLOBALS['core']->tpl->getFilters($attr);
return
'<?php echo '.sprintf($f,'$core->blog->url.$core->url->getBase("categories")').'; ?>';
'<?php echo ' . sprintf($f, '$core->blog->url.$core->url->getBase("categories")') . '; ?>';
}
}
# Adds a new template behavior :
$GLOBALS['core']->addBehavior('publicBeforeDocument',array('behaviorCategoriesPage','addTplPath'));
class behaviorCategoriesPage {
class behaviorCategoriesPage
{
public static function addTplPath($core)
{
$core->tpl->setPath($core->tpl->getPath(), dirname(__FILE__).'/default-templates');
public static function addTplPath($core) {
$tpl = $core->tpl;
$tpl->setPath($tpl->getPath(), dirname(__FILE__) . '/default-templates');
}
}
# 'categories' urlHandler :
$GLOBALS['core']->url->register('categories','categories','^categories$',array('urlCategories','categories'));
class urlCategories extends dcUrlHandlers {
class urlCategories extends dcUrlHandlers
{
public static function categories($args)
{
public static function categories($args) {
# The entry
self::serveDocument('categories.html');
exit;
}
}
/* compatibilité avec Breadcrumb */
$core->addBehavior('publicBreadcrumb',array('extCategoriesPage','publicBreadcrumb'));
class extCategoriesPage
{
public static function publicBreadcrumb($context,$separator)
{
class extCategoriesPage {
public static function publicBreadcrumb($context, $separator) {
// check URL type
if ($context == 'categories') {
// It's a CategoriesPage page, return my own part

View file

@ -1,59 +1,80 @@
<?php
# -- BEGIN LICENSE BLOCK ----------------------------------
#
# This file is part of Categories Page, a plugin for Dotclear 2.
#
# Copyright (c) 2007-2011 Adjaya and contributors
# 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; }
/* -- 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;
}
if (!$core->blog->settings->categoriespage->categoriespage_active) return;
widgetsCategoriesPage::main();
$core->addBehavior('initWidgets',array('widgetsCategoriesPage','initWidgets'));
class widgetsCategoriesPage
{
# Widget function
public static function categoriesPageWidgets($w)
{
global $core;
if (($w->homeonly == 1 && $core->url->type != 'default') ||
($w->homeonly == 2 && $core->url->type == 'default')) {
class widgetsCategoriesPage {
/*
* initialisation du context widget
*/
public static function main() {
require_once 'ConstCategoriesPage.php';
$core = $GLOBALS['core'];
$ns = $core->blog->settings->addNamespace(ConstCategoriesPage::NS);
if (!$ns->get(ConstCategoriesPage::PLUGIN_IS_ACTIVE)) {
return;
}
$res = ($w->content_only ? '' : '<div class="categories'.($w->class ? ' '.html::escapeHTML($w->class) : '').'">').
($w->title ? '<h2>'.html::escapeHTML($w->title).'</h2>' : '').
'<ul>';
$res .=
'<li><strong><a href="'.$core->blog->url.$core->url->getBase("categories").'">'.
__('All categories').'</a></strong></li>';
$res .= '</ul>'.
($w->content_only ? '' : '</div>');
return $res;
$core->addBehavior('initWidgets', array('widgetsCategoriesPage', 'initWidgets'));
}
public static function initWidgets($w)
{
$w->create('CategoriesPage',__('Categories page'),array('widgetsCategoriesPage','categoriesPageWidgets'));
// Widget function
public static function categoriesPageWidgets($widget) {
$core = $GLOBALS['core'];
$w->CategoriesPage->setting('title',__('Title:'),__('Categories page'),'text');
$w->CategoriesPage->setting('homeonly',__('Display on:'),0,'combo',
array(
__('All pages') => 0,
__('Home page only') => 1,
__('Except on home page') => 2
$url = $core->url;
if (($widget->homeonly == 1 && $url->type !== 'default') ||
($widget->homeonly == 2 && $url->type === 'default')) {
return;
}
$class = $divB = $divE = $title = '';
if ($widget->class) {
$class = html::escapeHTML($widget->class);
}
if ( $widget->content_only) {
$divB = '<div class="categories '. $class . '">';
$divE = '</div>';
}
if ( $widget->title ) {
$title = '<h2>' . html::escapeHTML($widget->title) . '</h2>';
}
return $divB .
'<ul><li><strong><a href="' .
$core->blog->url . $core->url->getBase("categories") . '">' .
__('All categories') .
'</a></strong></li></ul>' .
$divE;
}
public static function initWidgets($widget) {
$text = __('Categories page');
$widget->create('CategoriesPage', $text, array('widgetsCategoriesPage', 'categoriesPageWidgets'));
$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
)
);
$w->CategoriesPage->setting('content_only',__('Content only'),0,'check');
$w->CategoriesPage->setting('class',__('CSS class:'),'');
$categoriesPage->setting('content_only', __('Content only'), 0, 'check');
$categoriesPage->setting('class', __('CSS class:'), '');
}
}

View file

@ -5,12 +5,12 @@
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="ROBOTS" content="{{tpl:BlogMetaRobots robots="NOINDEX"}}" />
<title>{{tpl:lang Categories Page}} - {{tpl:BlogName encode_html="1"}}</title>
<title>{{tpl:lang Categories page}} - {{tpl:BlogName encode_html="1"}}</title>
<meta name="copyright" content="{{tpl:BlogCopyrightNotice encode_html="1"}}" />
<meta name="author" content="{{tpl:BlogEditor encode_html="1"}}" />
<meta name="date" scheme="W3CDTF" content="{{tpl:BlogUpdateDate iso8601="1"}}" />
<link rel="schema.dc" href="http://purl.org/dc/elements/1.1/" />
<meta name="dc.title" lang="{{tpl:BlogLanguage}}" content="{{tpl:lang Categories Page}} - {{tpl:BlogName encode_html="1"}}" />
<meta name="dc.title" lang="{{tpl:BlogLanguage}}" content="{{tpl:lang Categories page}} - {{tpl:BlogName encode_html="1"}}" />
<meta name="dc.language" content="{{tpl:BlogLanguage}}" />
<meta name="dc.publisher" content="{{tpl:BlogEditor encode_html="1"}}" />
<meta name="dc.rights" content="{{tpl:BlogCopyrightNotice encode_html="1"}}" />
@ -40,10 +40,8 @@
<div id="content">
<div id="content-info">
<h2>{{tpl:lang Categories}}</h2>
</div>
<div class="content-inner">
<h2>{{tpl:lang Categories}} :</h2>
<tpl:Categories>
<h3><a href="{{tpl:CategoryURL}}">{{tpl:CategoryTitle encode_html="1"}}</a> ({{tpl:CategoryCount}})</h3>
<div>{{tpl:CategoryDescription}}</div>
@ -77,4 +75,4 @@
{{tpl:include src="_footer.html"}}
</div> <!-- End #page -->
</body>
</html>
</html>

BIN
icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

83
index.php Normal file
View file

@ -0,0 +1,83 @@
<?php
# -- BEGIN LICENSE BLOCK ----------------------------------
#
# This file is part of categoriesMode, a plugin for Dotclear 2.
#
# Copyright (c) 2007-2011 Adjaya and contributors
# 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')) {
exit;
}
indexCategoriesPage::main();
class indexCategoriesPage {
public static function main() {
require_once 'ConstCategoriesPage.php';
$core = $GLOBALS['core'];
$ns = $core->blog->settings->addNameSpace( ConstCategoriesPage::NS);
if ( $ns->get(ConstCategoriesPage::PLUGIN_IS_ACTIVE) === null) {
try {
$ns->put( ConstCategoriesPage::PLUGIN_IS_ACTIVE, false, 'boolean');
# Url de base
$p_url = 'plugin.php?p='.ConstCategoriesPage::PARAM;
http::redirect($p_url);
}
catch (Exception $e) {
$core->error->add($e->getMessage());
}
}
$active = $ns->get( ConstCategoriesPage::PLUGIN_IS_ACTIVE);
$msg = '';
if (!empty($_POST['saveconfig'])) {
try {
$active = (empty($_POST['active'])) ? false : true;
$ns->put( ConstCategoriesPage::PLUGIN_IS_ACTIVE, $active,'boolean');
$core->blog->triggerBlog();
$msg = dcPage::success( __('Configuration successfully updated.'), true, false, false);
}
catch (Exception $e) {
$core->error->add($e->getMessage());
}
}
$page_title = __('Categories Page');
echo '
<html>
<head>
<title>'. $page_title.'</title>
</head>
<body>' .
dcPage::breadcrumb(
array(
html::escapeHTML($core->blog->name) => '',
'<span class="page-title">'.$page_title.'</span>' => ''
)).$msg.
'<div id="categoriesmode_options">
<form method="post" action="plugin.php">
<div class="fieldset">
<h4>'. __('Plugin activation').'</h4>
<p class="field">
<label class=" classic">'. form::checkbox('active', 1, $active).'&nbsp;'.
__('Enable categoriesMode').
'</label>
</p>
</div>
<p>
<input type="hidden" name="p" value="'.ConstCategoriesPage::PARAM.'" />'.
$core->formNonce().
'<input type="submit" name="saveconfig" value="'. __('Save configuration').'" />
</p>
</form>
</div>
</body>
</html>';
}
}