1<?php
2/**
3 * Tools Plugin
4 *
5 * Enables/disables tools toolbar.
6 *
7 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
8 * @author  Luigi Micco <l.micco@tiscali.it>
9 */
10
11// must be run within Dokuwiki
12if(!defined('DOKU_INC')) die();
13
14if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
15require_once(DOKU_PLUGIN.'syntax.php');
16
17/**
18 * All DokuWiki plugins to extend the parser/rendering mechanism
19 * need to inherit from this class
20 */
21class syntax_plugin_tools_tools extends DokuWiki_Syntax_Plugin {
22
23  /**
24   * return some info
25   */
26  function getInfo(){
27    return array (
28      'author' => 'Luigi Micco',
29      'email' => 'l.micco@tiscali.it',
30      'date' => '2010-03-30',
31      'name' => 'Tools plugin (syntax component)',
32      'desc' => 'Insert toolbar with tools on pages<br />Allows to override config options for a certain pages<br />Syntax: ~~TOOLS:(off|top|bottom|both)~~.',
33      'url' => 'http://www.dokuwiki.org/plugin:tools',
34    );
35  }
36
37  function getType(){ return 'substition'; }
38  function getPType(){ return 'block'; }
39  function getSort(){ return 110; }
40
41  /**
42   * Connect pattern to lexer
43   */
44  function connectTo($mode){
45    if ($mode == 'base'){
46      $this->Lexer->addSpecialPattern('~~TOOLS:(?:o(?:ff|n)|top|bot(?:tom|h))~~', $mode, 'plugin_tools_tools');
47    }
48  }
49  /**
50   * Handle the match
51   */
52  function handle($match, $state, $pos, &$handler){
53    return preg_replace("/[^:]+:(\\w+).+/","\\1",$match);
54  }
55
56  /**
57   *  Render output
58   */
59  function render($mode, &$renderer, $data) {
60      switch ($mode) {
61          case 'metadata' :
62              /*
63              *  mark metadata with found value
64              */
65              $renderer->meta['tools'] = $data;
66              return true;
67              break;
68    }
69    return false;
70  }
71
72
73}
74