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/** 13 * All DokuWiki plugins to extend the parser/rendering mechanism 14 * need to inherit from this class 15 */ 16class syntax_plugin_discussion_comments extends DokuWiki_Syntax_Plugin { 17 18 /** 19 * Syntax Type 20 * 21 * @return string 22 */ 23 function getType() { return 'substition'; } 24 25 /** 26 * Paragraph Type 27 * 28 * @return string 29 */ 30 function getPType() { return 'block'; } 31 32 /** 33 * Sort for applying this mode 34 * 35 * @return int 36 */ 37 function getSort() { return 230; } 38 39 /** 40 * Connect pattern to lexer 41 */ 42 function connectTo($mode) { 43 if ($mode == 'base') { 44 $this->Lexer->addSpecialPattern('~~DISCUSSION[^\r\n]*?~~', $mode, 'plugin_discussion_comments'); 45 } 46 } 47 48 /** 49 * Handler to prepare matched data for the rendering process 50 * 51 * @param string $match The text matched by the patterns 52 * @param int $state The lexer state for the match 53 * @param int $pos The character position of the matched text 54 * @param Doku_Handler $handler The Doku_Handler object 55 * @return array Return an array with all data you want to use in render 56 */ 57 function handle($match, $state, $pos, Doku_Handler $handler) { 58 59 // strip markup 60 $match = substr($match, 12, -2); 61 62 // split title (if there is one) 63 list($match, $title) = explode('|', $match, 2); 64 65 // assign discussion state 66 if ($match == ':off') $status = 0; 67 else if ($match == ':closed') $status = 2; 68 else $status = 1; 69 70 return array($status, $title); 71 } 72 73 /** 74 * Handles the actual output creation. 75 * 76 * @param $mode string output format being rendered 77 * @param $renderer Doku_Renderer the current renderer object 78 * @param $data array data created by handler() 79 * @return boolean rendered correctly? 80 */ 81 function render($mode, Doku_Renderer $renderer, $data) { 82 list($status, $title) = $data; 83 if ($mode == 'metadata') { 84 /** @var $renderer Doku_Renderer_metadata */ 85 $renderer->meta['plugin_discussion'] = array('status' => $status, 'title' => $title); 86 } 87 return true; 88 } 89} 90// vim:ts=4:sw=4:et:enc=utf-8: 91