Dotclear

source: plugins/multiToc/trunk/_widgets.php @ 3381

Revision 3381, 2.3 KB checked in by brol, 9 years ago (diff)

1.9, cf changelog

Line 
1<?php
2# -- BEGIN LICENSE BLOCK ----------------------------------
3# This file is part of multiToc, a plugin for Dotclear.
4#
5# Copyright (c) 2009-2015 Tomtom and contributors
6#
7# Licensed under the GPL version 2.0 license.
8# A copy of this license is available in LICENSE file or at
9# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
10# -- END LICENSE BLOCK ------------------------------------
11
12if (!defined('DC_RC_PATH')) { return; }
13
14$core->addBehavior('initWidgets',array('multiTocWidgets','initWidgets'));
15
16class multiTocWidgets
17{
18     public static function initWidgets($w)
19     {
20          $w->create('multiToc',__('MultiToc: table of content'),array('multiTocWidgets','widget'),
21               null,
22               __('Contents by category, keyword and alphabetical order'));
23          $w->multiToc->setting('title',__('Title:'),__('Table of content'));
24          $w->multiToc->setting('homeonly',__('Display on:'),0,'combo',
25               array(
26                    __('All pages') => 0,
27                    __('Home page only') => 1,
28                    __('Except on home page') => 2
29                    )
30          );
31          $w->multiToc->setting('content_only',__('Content only'),0,'check');
32          $w->multiToc->setting('class',__('CSS class:'),'');
33          $w->multiToc->setting('offline',__('Offline'),0,'check');
34     }
35     
36     public static function widget($w)
37     {
38          global $core;
39         
40          if ($w->offline)
41          return;
42
43          if (($w->homeonly == 1 && $core->url->type != 'default') ||
44               ($w->homeonly == 2 && $core->url->type == 'default')) {
45               return;
46          }
47         
48          $amask = '<a href="%1$s">%2$s</a>';
49          $limask = '<li class="%1$s">%2$s</li>';
50         
51          $res = '';
52         
53          $settings = unserialize($core->blog->settings->multiToc->multitoc_settings);
54         
55          if ($settings['cat']['enable']) {
56               $link = sprintf($amask,$core->blog->url.$core->url->getBase('multitoc').'/cat',__('By category'));
57               $res .= sprintf($limask,'toc-cat',$link);
58          }
59          if ($settings['tag']['enable']) {
60               $link = sprintf($amask,$core->blog->url.$core->url->getBase('multitoc').'/tag',__('By tag'));
61               $res .= sprintf($limask,'toc-tag',$link);
62          }
63          if ($settings['alpha']['enable']) {
64               $link = sprintf($amask,$core->blog->url.$core->url->getBase('multitoc').'/alpha',__('By alpha order'));
65               $res .= sprintf($limask,'toc-alpha',$link);
66          }
67         
68          if (!empty($res)) {
69    $res =
70          ($w->title ? $w->renderTitle(html::escapeHTML($w->title)) : '').
71          '<ul>'.$res.'</ul>';
72
73          return $w->renderDiv($w->content_only,'info-blog '.$w->class,'',$res);
74
75          }
76         
77     }
78}
Note: See TracBrowser for help on using the repository browser.

Sites map