diff --git a/ConstCategoriesPage.php b/ConstCategoriesPage.php new file mode 100644 index 0000000..c10e2f4 --- /dev/null +++ b/ConstCategoriesPage.php @@ -0,0 +1,20 @@ +addBehavior('adminBlogPreferencesForm',array('categoriespageAdminBehaviors','adminBlogPreferencesForm')); -$core->addBehavior('adminBeforeBlogSettingsUpdate',array('categoriespageAdminBehaviors','adminBeforeBlogSettingsUpdate')); +categoriespageAdminBehaviors::main(); class categoriespageAdminBehaviors { - public static function adminBlogPreferencesForm($core,$settings) - { - echo - '

'.__('Categories Page').'

'. - '

'. - '
'; - } - - 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()); + } } diff --git a/_define.php b/_define.php index 8f9806b..d29d128 100644 --- a/_define.php +++ b/_define.php @@ -1,21 +1,24 @@ 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', diff --git a/_public.php b/_public.php index 1ab4562..3977ab0 100644 --- a/_public.php +++ b/_public.php @@ -1,91 +1,89 @@ 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 - 'categories->nb_post').'; ?>'; + 'categories->nb_post') . '; ?>'; } /* - Use : - + Use tag : {{tpl:CategoriesURL}} */ - - public static function EntryIfCategoriesPage($attr,$content) - { - return - "blog->settings->categoriespage->categoriespage_active) : ?>". - $content. - ""; - } - - /* - Use tag : {{tpl:CategoriesURL}} - */ - public static function CategoriesURL($attr) - { + public static function CategoriesURL($attr) { $f = $GLOBALS['core']->tpl->getFilters($attr); return - 'blog->url.$core->url->getBase("categories")').'; ?>'; + '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 diff --git a/_widgets.php b/_widgets.php index c3d6709..9926c1c 100644 --- a/_widgets.php +++ b/_widgets.php @@ -1,59 +1,80 @@ 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 ? '' : '
'). - ($w->title ? '

'.html::escapeHTML($w->title).'

' : ''). - ''. - ($w->content_only ? '' : '
'); - - 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 = '
'; + $divE = '
'; + } + if ( $widget->title ) { + $title = '

' . html::escapeHTML($widget->title) . '

'; + } + + return $divB . + '' . + $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:'), ''); } + } diff --git a/default-templates/categories.html b/default-templates/categories.html index 99c95a5..64f162a 100644 --- a/default-templates/categories.html +++ b/default-templates/categories.html @@ -5,12 +5,12 @@ - {{tpl:lang Categories Page}} - {{tpl:BlogName encode_html="1"}} + {{tpl:lang Categories page}} - {{tpl:BlogName encode_html="1"}} - + @@ -40,10 +40,8 @@
-

{{tpl:lang Categories}}

-
- -
+

{{tpl:lang Categories}} :

+

{{tpl:CategoryTitle encode_html="1"}} ({{tpl:CategoryCount}})

{{tpl:CategoryDescription}}
@@ -77,4 +75,4 @@ {{tpl:include src="_footer.html"}}
- \ No newline at end of file + diff --git a/icon.png b/icon.png new file mode 100644 index 0000000..e81b061 Binary files /dev/null and b/icon.png differ diff --git a/index.php b/index.php new file mode 100644 index 0000000..ec601e6 --- /dev/null +++ b/index.php @@ -0,0 +1,83 @@ +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 ' + + + '. $page_title.' + +' . + dcPage::breadcrumb( + array( + html::escapeHTML($core->blog->name) => '', + ''.$page_title.'' => '' + )).$msg. +'
+
+
+

'. __('Plugin activation').'

+

+ +

+
+

+ '. + $core->formNonce(). + ' +

+
+
+ +'; +} +}