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