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 public function getType() { return 'substition'; } 24 25 /** 26 * Paragraph Type 27 * 28 * @return string 29 */ 30 public function getPType() { return 'block'; } 31 32 /** 33 * Sort for applying this mode 34 * 35 * @return int 36 */ 37 public function getSort() { return 230; } 38 39 /** 40 * Connect pattern to lexer 41 */ 42 public 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 public function handle($match, $state, $pos, Doku_Handler $handler) { 58 // strip markup 59 $match = substr($match, 12, -2); 60 61 // split title (if there is one) 62 list($match, $title) = array_pad(explode('|', $match, 2), 2, ''); 63 64 // assign discussion state 65 if ($match == ':off') { 66 $status = 0; 67 } elseif ($match == ':closed') { 68 $status = 2; 69 } else { 70 // comments enabled 71 $status = 1; 72 } 73 74 return [$status, $title]; 75 } 76 77 /** 78 * Handles the actual output creation. 79 * 80 * @param string $format output format being rendered 81 * @param Doku_Renderer $renderer the current renderer object 82 * @param array $data data created by handler() 83 * @return boolean rendered correctly? 84 */ 85 public function render($format, Doku_Renderer $renderer, $data) { 86 list($status, $title) = $data; 87 if ($format == 'metadata') { 88 /** @var Doku_Renderer_metadata $renderer */ 89 $renderer->meta['plugin_discussion'] = ['status' => $status, 'title' => $title]; 90 } 91 return true; 92 } 93} 94