1<?php 2/** 3 * TOC Plugin 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.'action.php'); 13 14class action_plugin_toc extends DokuWiki_Action_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 Action Plugin', 25 'desc' => 'Inserts TOC in the place you specified in your Wiki page' 26 ); 27 } 28 29 /** 30 * Register event handlers 31 */ 32 function register(&$controller) { 33 $controller->register_hook('TPL_ACT_RENDER', 'BEFORE', $this, 'handle_act_render', array()); 34 $controller->register_hook('TPL_CONTENT_DISPLAY', 'BEFORE', $this, 'handle_content_display', array()); 35 } 36 37 function handle_act_render(&$event, $param) { 38 global $ID; 39 global $INFO; 40 if (p_get_metadata($ID, 'movetoc')) { 41 $INFO['prependTOC'] = false; 42 } 43 } 44 45 /** 46 * Replace <!-- TOC --> with the toc 47 */ 48 function handle_content_display(&$event, $param) { 49 $toc = tpl_toc(true); 50 if ($toc) { 51 $event->data = str_replace('<!-- TOC -->', '<div class="inlinetoc">'.$toc."</div>", $event->data); 52 } 53 } 54 55} 56