1<?php 2/** 3 * TOC Plugin: Inserts TOC where you need. 4 * 5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 6 * @author Andriy Lesyuk <andriy.lesyuk@softjourn.com> 7 */ 8 9if(!defined('DOKU_INC')) die(); 10if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 11 12require_once(DOKU_PLUGIN.'syntax.php'); 13 14class syntax_plugin_toc extends DokuWiki_Syntax_Plugin { 15 16 /** 17 * Return some info 18 */ 19 function getInfo() { 20 return array( 21 'author' => 'Andriy Lesyuk', 22 'email' => 'andriy.lesyuk@softjourn.com', 23 'date' => '2009-04-13', 24 'name' => 'TOC Syntax Plugin', 25 'desc' => 'Insert TOC where you need (disables original TOC)' 26 ); 27 } 28 29 /** 30 * Tell the type of the plugin 31 */ 32 function getType() { 33 return 'substition'; 34 } 35 36 /** 37 * Return sort value (took the same as for ~~NOTOC~~) 38 */ 39 function getSort() { 40 return 30; 41 } 42 43 /** 44 * Add our syntax 45 */ 46 function connectTo($mode) { 47 $this->Lexer->addSpecialPattern('~~TOC~~', $mode, 'plugin_toc'); 48 } 49 50 /** 51 * Process syntax code 52 */ 53 function handle($match, $state, $pos, &$handler) { 54 return substr($match, 2, -2); 55 } 56 57 /** 58 * Add <!-- TOC --> to cached page (will be replaced by action component) 59 */ 60 function render($mode, &$renderer, $data) { 61 if ($mode == 'xhtml'){ 62 $renderer->doc .= '<!-- TOC -->'; 63 return true; 64 } elseif ($mode == 'metadata') { 65 $renderer->meta['movetoc'] = true; 66 return true; 67 } else { 68 return false; 69 } 70 } 71 72} 73