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 | $__autoload['multiTocPost'] = dirname(__FILE__).'/inc/class.multi.toc.php'; |
---|
14 | $__autoload['multiTocUi'] = dirname(__FILE__).'/inc/class.multi.toc.php'; |
---|
15 | |
---|
16 | $core->addBehavior('publicBeforeDocument',array('multiTocBehaviors','addTplPath')); |
---|
17 | $core->addBehavior('coreBlogGetPosts',array('multiTocBehaviors','coreBlogGetPosts')); |
---|
18 | $core->addBehavior('initStacker',array('multiTocBehaviors','initStacker')); |
---|
19 | |
---|
20 | $core->url->register('multitoc','multitoc','^multitoc/(.*)$',array('multiTocUrl','multiToc')); |
---|
21 | |
---|
22 | require dirname(__FILE__).'/_widgets.php'; |
---|
23 | |
---|
24 | class multiTocBehaviors |
---|
25 | { |
---|
26 | public static function addTplPath() |
---|
27 | { |
---|
28 | $GLOBALS['core']->tpl->setPath($GLOBALS['core']->tpl->getPath(), dirname(__FILE__).'/default-templates'); |
---|
29 | } |
---|
30 | |
---|
31 | public static function coreBlogGetPosts($rs) |
---|
32 | { |
---|
33 | $rs->extend('rsMultiTocPost'); |
---|
34 | } |
---|
35 | |
---|
36 | public static function postHeaders() |
---|
37 | { |
---|
38 | $s = unserialize($GLOBALS['core']->blog->settings->multiToc->multitoc_settings); |
---|
39 | |
---|
40 | return |
---|
41 | (isset($s['post']['enable']) && $s['post']['enable']) ? |
---|
42 | '<script type="text/javascript" src="index.php?pf=multiToc/js/post.js"></script>'. |
---|
43 | '<script type="text/javascript">'."\n". |
---|
44 | "//<![CDATA[\n". |
---|
45 | dcPage::jsVar('jsToolBar.prototype.elements.multiToc.title',__('Table of content')). |
---|
46 | "\n//]]>\n". |
---|
47 | "</script>\n" : ''; |
---|
48 | } |
---|
49 | |
---|
50 | public static function initStacker($core) |
---|
51 | { |
---|
52 | $core->stacker->addFilter( |
---|
53 | 'multiTocFilter', |
---|
54 | 'multiTocBehaviors', |
---|
55 | 'multiTocFilter', |
---|
56 | 'any', |
---|
57 | 100, |
---|
58 | 'multiToc', |
---|
59 | __('Add post TOC') |
---|
60 | ); |
---|
61 | } |
---|
62 | |
---|
63 | public static function multiTocFilter($rs,$text,$absolute_urls = false) |
---|
64 | { |
---|
65 | if ($rs->hasToc()) { |
---|
66 | $toc = new multiTocPost($rs); |
---|
67 | $text = $toc->process($text); |
---|
68 | unset($toc); |
---|
69 | } |
---|
70 | |
---|
71 | return $text; |
---|
72 | } |
---|
73 | } |
---|
74 | |
---|
75 | class rsMultiTocPost |
---|
76 | { |
---|
77 | public static function hasToc($rs) |
---|
78 | { |
---|
79 | if (preg_match('/<p>::TOC::<\/p>/',$rs->post_excerpt_xhtml.$rs->post_content_xhtml)) { |
---|
80 | return true; |
---|
81 | } |
---|
82 | else { |
---|
83 | return false; |
---|
84 | } |
---|
85 | } |
---|
86 | } |
---|
87 | |
---|
88 | ?> |
---|