1<?php 2/** 3 * Provides a syntax for referring/replying to comments in own comments. 4 * 5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 6 * @author Gina Haeussge <gina@foosel.net> 7 */ 8 9/** 10 * Class syntax_plugin_blogtng_commentreply 11 */ 12class syntax_plugin_blogtng_commentreply extends DokuWiki_Syntax_Plugin { 13 14 /** 15 * Syntax Type 16 * 17 * @return string 18 */ 19 function getType() { return 'substition'; } 20 21 /** 22 * Sort for applying this mode 23 * 24 * @return int 25 */ 26 function getSort() { return 300; } 27 28 /** 29 * Register the comment reply syntax 30 * 31 * @param string $mode 32 */ 33 function connectTo($mode) { 34 $this->Lexer->addSpecialPattern('@#\d+:', $mode, 'plugin_blogtng_commentreply'); 35 } 36 37 /** 38 * Handler to prepare matched data for the rendering process 39 * 40 * @param string $match The text matched by the patterns 41 * @param int $state The lexer state for the match 42 * @param int $pos The character position of the matched text 43 * @param Doku_Handler $handler The Doku_Handler object 44 * @return bool|array Return an array with all data you want to use in render, false don't add an instruction 45 */ 46 function handle($match, $state, $pos, Doku_Handler $handler) { 47 $cid = substr($match, 2, -1); 48 return array($cid); 49 } 50 51 /** 52 * Renders a simple anchor in XHTML code for the readmore jump point. 53 * 54 * @param string $format output format being rendered 55 * @param Doku_Renderer $renderer the current renderer object 56 * @param array $data data created by handler() 57 * @return boolean rendered correctly? (however, returned value is not used at the moment) 58 */ 59 function render($format, Doku_Renderer $renderer, $data) { 60 if ($format == 'blogtng_comment') { 61 list($cid) = $data; 62 /** @var helper_plugin_blogtng_comments $commenthelper */ 63 $commenthelper = plugin_load('helper', 'blogtng_comments'); 64 $comment = $commenthelper->comment_by_cid($cid); 65 if (!is_object($comment)) return false; // comment does not exist, cid is invalid 66 67 ob_start(); 68 echo '@<a href="#comment_'.$cid.'" class="wikilink1 blogtng_reply">'; 69 $comment->tpl_name(); 70 echo '</a>:'; 71 $output = ob_get_clean(); 72 73 $renderer->doc .= $output; 74 return true; 75 } 76 77 // unsupported mode 78 return false; 79 } 80} 81