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 <?php
# -- BEGIN LICENSE BLOCK ---------------------------------- /* -- BEGIN LICENSE BLOCK ----------------------------------
# #
# This file is part of Categories Page, a plugin for Dotclear 2. # 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. # Licensed under the GPL version 2.0 license.
# See LICENSE file or # See LICENSE file or
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
# #
# -- END LICENSE BLOCK ------------------------------------ # -- END LICENSE BLOCK ------------------------------------*/
if (!defined('DC_CONTEXT_ADMIN')) { return; } if (!defined('DC_CONTEXT_ADMIN')) {
return;
}
require_once dirname(__FILE__).'/_widgets.php'; categoriespageAdminBehaviors::main();
$core->addBehavior('adminBlogPreferencesForm',array('categoriespageAdminBehaviors','adminBlogPreferencesForm'));
$core->addBehavior('adminBeforeBlogSettingsUpdate',array('categoriespageAdminBehaviors','adminBeforeBlogSettingsUpdate'));
class categoriespageAdminBehaviors class categoriespageAdminBehaviors
{ {
public static function adminBlogPreferencesForm($core,$settings) public static function main() {
{
echo require_once '/_widgets.php';
'<div class="fieldset"><h4>'.__('Categories Page').'</h4>'.
'<p><label class="classic">'. $menu = $GLOBALS['_menu'];
form::checkbox('categoriespage_active','1',$settings->categoriespage->categoriespage_active). $core = $GLOBALS['core'];
__('Enable Categories Page').'</label></p>'. $menu['Plugins']->addItem(
'</div>'; ConstCategoriesPage::NS,
} 'plugin.php?p='.ConstCategoriesPage::PARAM,
'index.php?pf='.ConstCategoriesPage::PARAM.'/icon.png',
public static function adminBeforeBlogSettingsUpdate($settings) preg_match('/plugin.php\?p='.ConstCategoriesPage::PARAM.'(&.*)?$/',$_SERVER['REQUEST_URI']),
{ $core->auth->isSuperAdmin());
$settings->addNameSpace('categoriespage'); }
$settings->categoriespage->put('categoriespage_active',!empty($_POST['categoriespage_active']),'boolean');
$settings->addNameSpace('system');
}
} }

View file

@ -1,21 +1,24 @@
<?php <?php
# -- BEGIN LICENSE BLOCK ---------------------------------- /* -- BEGIN LICENSE BLOCK ----------------------------------
# #
# This file is part of Categories Page, a plugin for Dotclear 2. # 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. # Licensed under the GPL version 2.0 license.
# See LICENSE file or # See LICENSE file or
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
# #
# -- END LICENSE BLOCK ------------------------------------ # -- END LICENSE BLOCK ------------------------------------*/
if (!defined('DC_RC_PATH')) { return; } if (!defined('DC_RC_PATH')) {
return;
}
require_once 'ConstCategoriesPage.php';
$this->registerModule( $this->registerModule(
/* Name */ "Categories Page", /* Name */ 'Categories Page',
/* Description*/ "Add a category list page", /* Description*/ 'Add a category list page / Ajoute une page listant les catégories',
/* Author */ "Adjaya, Pierre Van Glabeke", /* Author */ 'Pierre Van Glabeke, Bernard Le Roux',
/* Version */ '0.1', /* Version */ ConstCategoriesPage::VERSION,
/* Properties */ /* Properties */
array( array(
'permissions' => 'admin', 'permissions' => 'admin',

View file

@ -1,91 +1,89 @@
<?php <?php
# -- BEGIN LICENSE BLOCK ---------------------------------- /* -- BEGIN LICENSE BLOCK ----------------------------------
# #
# This file is part of Categories Page, a plugin for Dotclear 2. # 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. # Licensed under the GPL version 2.0 license.
# See LICENSE file or # See LICENSE file or
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
# #
# -- END LICENSE BLOCK ------------------------------------ # -- END LICENSE BLOCK ------------------------------------ */
if (!defined('DC_RC_PATH')) { return; } if (!defined('DC_RC_PATH')) {
return;
}
# If categoriesPage is not active we stop here : publicCategoriesPage::main();
if (!$core->blog->settings->categoriespage->categoriespage_active) { return; }
require_once dirname(__FILE__).'/_widgets.php'; class publicCategoriesPage {
# Adds news Categories' templates tags : public static function main() {
$GLOBALS['core']->tpl->addValue('CategoryCount',array('tplCategories','CategoryCount'));
$GLOBALS['core']->tpl->addBlock('EntryIfCategoriesPage',array('tplCategories','EntryIfCategoriesPage'));
$GLOBALS['core']->tpl->addValue('CategoriesURL',array('tplCategories','CategoriesURL'));
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}} Use tag : {{tpl:CategoryCount}}
*/ */
public static function CategoryCount($attr) public static function CategoryCount($attr) {
{
$f = $GLOBALS['core']->tpl->getFilters($attr); $f = $GLOBALS['core']->tpl->getFilters($attr);
return return
'<?php echo '.sprintf($f,'$_ctx->categories->nb_post').'; ?>'; '<?php echo ' . sprintf($f, '$_ctx->categories->nb_post') . '; ?>';
} }
/* /*
Use : <tpl:EntryIfCategoriesPage> Use tag : {{tpl:CategoriesURL}}
</tpl:EntryIfCategoriesPage>
*/ */
public static function CategoriesURL($attr) {
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)
{
$f = $GLOBALS['core']->tpl->getFilters($attr); $f = $GLOBALS['core']->tpl->getFilters($attr);
return 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 : class behaviorCategoriesPage {
$GLOBALS['core']->addBehavior('publicBeforeDocument',array('behaviorCategoriesPage','addTplPath'));
class behaviorCategoriesPage public static function addTplPath($core) {
{ $tpl = $core->tpl;
public static function addTplPath($core) $tpl->setPath($tpl->getPath(), dirname(__FILE__) . '/default-templates');
{
$core->tpl->setPath($core->tpl->getPath(), dirname(__FILE__).'/default-templates');
} }
} }
# 'categories' urlHandler : class urlCategories extends dcUrlHandlers {
$GLOBALS['core']->url->register('categories','categories','^categories$',array('urlCategories','categories'));
class urlCategories extends dcUrlHandlers public static function categories($args) {
{
public static function categories($args)
{
# The entry # The entry
self::serveDocument('categories.html'); self::serveDocument('categories.html');
exit; exit;
} }
} }
/* compatibilité avec Breadcrumb */ class extCategoriesPage {
$core->addBehavior('publicBreadcrumb',array('extCategoriesPage','publicBreadcrumb'));
class extCategoriesPage public static function publicBreadcrumb($context, $separator) {
{
public static function publicBreadcrumb($context,$separator)
{
// check URL type // check URL type
if ($context == 'categories') { if ($context == 'categories') {
// It's a CategoriesPage page, return my own part // It's a CategoriesPage page, return my own part

View file

@ -1,59 +1,80 @@
<?php <?php
# -- BEGIN LICENSE BLOCK ---------------------------------- /* -- BEGIN LICENSE BLOCK ----------------------------------
# #
# This file is part of Categories Page, a plugin for Dotclear 2. # 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. # Licensed under the GPL version 2.0 license.
# See LICENSE file or # See LICENSE file or
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
# #
# -- END LICENSE BLOCK ------------------------------------ # -- END LICENSE BLOCK ------------------------------------ */
if (!defined('DC_RC_PATH')) { return; } 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') || class widgetsCategoriesPage {
($w->homeonly == 2 && $core->url->type == 'default')) { /*
* 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; return;
} }
$res = ($w->content_only ? '' : '<div class="categories'.($w->class ? ' '.html::escapeHTML($w->class) : '').'">'). $core->addBehavior('initWidgets', array('widgetsCategoriesPage', 'initWidgets'));
($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;
} }
public static function initWidgets($w) // Widget function
{ public static function categoriesPageWidgets($widget) {
$w->create('CategoriesPage',__('Categories page'),array('widgetsCategoriesPage','categoriesPageWidgets')); $core = $GLOBALS['core'];
$w->CategoriesPage->setting('title',__('Title:'),__('Categories page'),'text'); $url = $core->url;
$w->CategoriesPage->setting('homeonly',__('Display on:'),0,'combo',
array( if (($widget->homeonly == 1 && $url->type !== 'default') ||
__('All pages') => 0, ($widget->homeonly == 2 && $url->type === 'default')) {
__('Home page only') => 1, return;
__('Except on home page') => 2 }
$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'); $categoriesPage->setting('content_only', __('Content only'), 0, 'check');
$w->CategoriesPage->setting('class',__('CSS class:'),''); $categoriesPage->setting('class', __('CSS class:'), '');
} }
} }

View file

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