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 function getType() { return 'substition'; } 25 function getPType() { return 'block'; } 26 function getSort() { return 230; } 27 28 /** 29 * Connect pattern to lexer 30 */ 31 function connectTo($mode) { 32 if ($mode == 'base') { 33 $this->Lexer->addSpecialPattern('~~DISCUSSION[^\r\n]*?~~', $mode, 'plugin_discussion_comments'); 34 } 35 } 36 37 /** 38 * Handle the match 39 */ 40 function handle($match, $state, $pos, &$handler) { 41 global $ID, $ACT, $REV; 42 43 // strip markup 44 $match = substr($match, 12, -2); 45 46 // split title (if there is one) 47 list($match, $title) = explode('|', $match, 2); 48 49 // assign discussion state 50 if ($match == ':off') $status = 0; 51 else if ($match == ':closed') $status = 2; 52 else $status = 1; 53 54 return array($status, $title); 55 } 56 57 function render($mode, &$renderer, $data) { 58 list($status, $title) = $data; 59 if ($mode == 'metadata') { 60 /** @var $renderer Doku_Renderer_metadata */ 61 $renderer->meta['plugin_discussion'] = array('status' => $status, 'title' => $title); 62 } 63 return true; 64 } 65} 66// vim:ts=4:sw=4:et:enc=utf-8: 67