xref: /plugin/discussion/syntax/comments.php (revision 530693fbe53c89e21418636c442e20dc0d1516a2)
1<?php
2/**
3 * Discussion Plugin
4 *
5 * Enables/disables discussion features based on config settings.
6 *
7 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
8 * @author  Esther Brunner <wikidesign@gmail.com>
9 * @author  Dave Lawson <dlawson@masterytech.com>
10 */
11
12// must be run within Dokuwiki
13if(!defined('DOKU_INC')) die();
14
15if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
16require_once(DOKU_PLUGIN.'syntax.php');
17
18/**
19 * All DokuWiki plugins to extend the parser/rendering mechanism
20 * need to inherit from this class
21 */
22class syntax_plugin_discussion_comments extends DokuWiki_Syntax_Plugin {
23
24    /**
25     * return some info
26     */
27    function getInfo() {
28        return array(
29                'author' => 'Gina Häußge, Michael Klier, Esther Brunner',
30                'email'  => 'dokuwiki@chimeric.de',
31                'date'   => '2008-04-20',
32                'name'   => 'Discussion Plugin (comments component)',
33                'desc'   => 'Enables discussion features',
34                'url'    => 'http://wiki.splitbrain.org/plugin:discussion',
35                );
36    }
37
38    function getType() { return 'substition'; }
39    function getPType() { return 'block'; }
40    function getSort() { return 230; }
41
42    /**
43     * Connect pattern to lexer
44     */
45    function connectTo($mode) {
46        if ($mode == 'base') {
47            $this->Lexer->addSpecialPattern('~~DISCUSSION[^\r\n]*?~~', $mode, 'plugin_discussion_comments');
48        }
49    }
50
51    /**
52     * Handle the match
53     */
54    function handle($match, $state, $pos, &$handler) {
55        global $ID, $ACT;
56
57        // strip markup
58        $match = substr($match, 12, -2);
59
60        // split title (if there is one)
61        list($match, $title) = explode('|', $match, 2);
62
63        // assign discussion state
64        if ($match == ':off') $status = 0;
65        else if ($match == ':closed') $status = 2;
66        else $status = 1;
67
68        if ($ACT !== 'save') return $status;
69
70        // get discussion meta file name
71        $file = metaFN($ID, '.comments');
72
73        $data = array();
74        if (@file_exists($file)) $data = unserialize(io_readFile($file, false));
75        if (($data['status'] != $status) || ($data['title'] != $title)) {
76            $data['title']  = $title;
77            $data['status'] = $status;
78            io_saveFile($file, serialize($data));
79        }
80
81        return $status;
82    }
83
84    function render($mode, &$renderer, $status) {
85        return true; // do nothing -> everything is handled in action component
86    }
87}
88//vim:ts=4:sw=4:et:enc=utf-8:
89