xref: /plugin/discussion/syntax/comments.php (revision 479dd10f6efbd08bf070b07eda42aae9b40f3233)
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' => 'Esther Brunner',
30      'email'  => 'wikidesign@gmail.com',
31      'date'   => '2006-12-02',
32      'name'   => 'Discussion Plugin (comments component)',
33      'desc'   => 'Enables discussion features',
34      'url'    => 'http://www.wikidesign.ch/en/plugin/discussion/start',
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(?:|:off|:closed)~~', $mode, 'plugin_discussion_comments');
48    }
49  }
50
51  /**
52   * Handle the match
53   */
54  function handle($match, $state, $pos, &$handler){
55    global $ID;
56    global $ACT;
57
58    // don't show discussion section on blog mainpages
59    if (defined('IS_BLOG_MAINPAGE')) return false;
60
61    // assign discussion state
62    if ($match == '~~DISCUSSION:off~~') $status = 0;
63    else if ($match == '~~DISCUSSION:closed~~') $status = 2;
64    else $status = 1;
65
66    // get discussion meta file name
67    $file = metaFN($ID, '.comments');
68
69    $data = array();
70    if (@file_exists($file)) $data = unserialize(io_readFile($file, false));
71    if ($data['status'] != $status){
72      $data['status'] = $status;
73      io_saveFile($file, serialize($data));
74    }
75
76    return $status;
77  }
78
79  function render($mode, &$renderer, $status){
80    return true; // do nothing -> everything is handled in action component
81  }
82
83}
84
85//Setup VIM: ex: et ts=4 enc=utf-8 :