1<?php
2/**
3 * Allows definition of autolink which is then shown using wikilink tag throughout the pages:
4 * Example:
5 * On the page wanted to be autolinked. {{autolink>anchors|separated by|}}
6 * On the pages where autolink is wanted to insert the whole page around <autolink> and </autolink>
7 *
8 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
9 */
10
11if (!defined('DOKU_INC')) {
12  define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
13}
14if (!defined('DOKU_PLUGIN')) {
15  define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
16}
17require_once(DOKU_PLUGIN.'syntax.php');
18
19
20/**
21 * All DokuWiki plugins to extend the parser/rendering mechanism
22 * need to inherit from this class
23 */
24class syntax_plugin_autolink2_show extends DokuWiki_Syntax_Plugin {
25
26    /**
27     * return some info
28     */
29    function getInfo() {
30        return confToHash(dirname(__FILE__).'/../plugin.info.txt');
31    }
32
33    /**
34     * What kind of syntax are we?
35     */
36    function getType(){return 'substition';}
37    function getPType() {return 'normal';}
38    function getSort() {return 999;}
39
40	function connectTo($mode) {
41      $this->Lexer->addEntryPattern('<autolink>(?=.*?\x3C/autolink\x3E)',$mode,'plugin_autolink2_show');
42    }
43    function postConnect() {
44      $this->Lexer->addExitPattern('</autolink>','plugin_autolink2_show');
45    }
46
47
48    function handle($match, $state, $pos, &$handler){
49       return array($match, $state);
50    }
51
52    /**
53     * Create output
54     */
55    function render($mode, &$renderer, $data) {
56        if($mode == 'xhtml'){
57          $renderer->doc .= $this->_renderautolink($renderer, $data[0],$data[1]);
58          return true;
59        }
60        return false;
61    }
62
63    function _renderautolink(&$renderer, $match, $state) {
64//        if (!$this->getConf('autoautolink')) return false;
65
66        switch ($state) {
67        case DOKU_LEXER_ENTER :
68          return "";
69          break;
70        case DOKU_LEXER_UNMATCHED :
71          if ($my =& plugin_load('helper', 'autolink2')) $anchors = $my->getAnchors();
72          $x=$match;
73          if (is_array($anchors)){
74          $pattern=$anchors[0];
75          $replace=$anchors[1];
76              $replaced = preg_replace($pattern,$replace,$match);
77              $x=p_render('xhtml',p_get_instructions($replaced),$info);
78            return $x;
79          }
80          break;
81        case DOKU_LEXER_EXIT :
82          return "";
83          break;
84        }
85    }
86}
87?>