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