1<?php 2/** 3 * DokuWiki plugin PageTitle YouAreHere; Syntax component 4 * Hierarchical breadcrumbs 5 * 6 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 7 * @author Satoshi Sahara <sahara.satoshi@gmail.com> 8 */ 9 10if (!defined('DOKU_INC')) die(); 11 12class syntax_plugin_pagetitle_youarehere extends DokuWiki_Syntax_Plugin 13{ 14 public function getType() 15 { // Syntax Type 16 return 'substition'; 17 } 18 19 public function getPType() 20 { // Paragraph Type 21 return 'block'; 22 } 23 24 /** 25 * Connect pattern to lexer, implement Doku_Parser_Mode_Interface 26 */ 27 protected $mode, $pattern; 28 29 public function getSort() 30 { 31 // sort number used to determine priority of this mode 32 return 990; 33 } 34 35 public function preConnect() 36 { 37 // syntax mode, drop 'syntax_' from class name 38 $this->mode = substr(get_class($this), 7); 39 40 //syntax patterns 41 $this->pattern[5] = '<!-- ?YOU_ARE_HERE ?-->'; 42 } 43 44 public function connectTo($mode) 45 { 46 $this->Lexer->addSpecialPattern($this->pattern[5], $mode, $this->mode); 47 } 48 49 /** 50 * Handle the match 51 */ 52 public function handle($match, $state, $pos, Doku_Handler $handler) 53 { 54 global $ID; 55 return $data = [$state, $match, $ID]; 56 } 57 58 /** 59 * Create output 60 */ 61 public function render($format, Doku_Renderer $renderer, $data) 62 { 63 global $ID; 64 static $helper; 65 66 list($state, $match, $id) = $data; 67 68 // skip calls that belong to different pages (eg. title of included page) 69 if (strcmp($id, $ID) !== 0) return false; 70 71 if ($format == 'metadata') { 72 $renderer->meta['plugin']['pagetitle']['youarehere'] =+ 1; 73 74 } elseif ($format == 'xhtml') { 75 // load helper object 76 isset($helper) || $helper = $this->loadHelper($this->getPluginName()); 77 78 $renderer->doc .= DOKU_LF.$match.DOKU_LF; // html comment 79 $renderer->doc .= '<div class="youarehere">'; 80 $renderer->doc .= $helper->html_youarehere(1); // start_depth = 1 81 $renderer->doc .= '</div>'.DOKU_LF; 82 } 83 return true; 84 } 85 86} 87