1<?php 2/** 3 * DokuWiki Plugin starred (Syntax Component) 4 * 5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 6 * @author Andreas Gohr <andi@splitbrain.org> 7 */ 8class syntax_plugin_starred extends DokuWiki_Syntax_Plugin 9{ 10 11 /** @inheritdoc */ 12 public function getType() 13 { 14 return 'substition'; 15 } 16 17 /** @inheritdoc */ 18 public function getPType() 19 { 20 return 'block'; 21 } 22 23 /** @inheritdoc */ 24 public function getSort() 25 { 26 return 155; 27 } 28 29 /** @inheritdoc */ 30 public function connectTo($mode) 31 { 32 $this->Lexer->addSpecialPattern('{{starred(?:>min)?(?:\|\d+)?}}', $mode, 'plugin_starred'); 33 } 34 35 /** @inheritdoc */ 36 public function handle($match, $state, $pos, Doku_Handler $handler) 37 { 38 preg_match('{{starred((?:>min)?)\|?(\d*)}}', $match, $matches); 39 return array('min' => $matches[1] !== '', 40 'limit' => $matches[2]); 41 } 42 43 /** @inheritdoc */ 44 public function render($mode, Doku_Renderer $R, $data) 45 { 46 if ($mode != 'xhtml') return false; 47 global $INPUT; 48 49 /** @var Doku_Renderer_xhtml $R */ 50 $R->info['cache'] = false; 51 52 if (!$INPUT->server->has('REMOTE_USER')) { 53 $R->cdata($this->getLang('login')); 54 return true; 55 } 56 57 /** @var helper_plugin_starred $hlp */ 58 $hlp = plugin_load('helper', 'starred'); 59 $starred = $hlp->loadStars(null, $data['limit']); 60 61 $R->doc .= '<div class="plugin_starred">'; 62 if (!count($starred)) { 63 if (!$data['min']) { 64 $R->doc .= '<p>'; 65 $R->cdata($this->getLang('none')); 66 $R->p_close(); 67 } 68 $R->doc .= '</div>'; 69 return true; 70 } 71 72 $R->doc .= '<ul>'; 73 foreach ($starred as $pid => $time) { 74 $R->listitem_open(1); 75 $R->listcontent_open(); 76 $R->internallink(':' . $pid, null, null, false, 'navigation'); 77 if (!$data['min']) { 78 $R->cdata(' ' . dformat($time, '%f')); 79 } 80 global $ID; 81 $R->doc .= $hlp->starHtml($ID, $pid, false); 82 $R->listcontent_close(); 83 $R->listitem_close(); 84 } 85 $R->listu_close(); 86 $R->doc .= '</div>'; 87 return true; 88 } 89} 90