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 * or by setting option 'autoautolink' to 1 links are set in avery page. You can prevent page from
8 * autoimatically  setting links by setting ~~noautolink~~ in the start of the page
9 *
10 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
11 */
12
13if (!defined('DOKU_INC')) {
14  define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
15}
16if (!defined('DOKU_PLUGIN')) {
17  define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
18}
19require_once(DOKU_PLUGIN.'syntax.php');
20
21
22/**
23 * All DokuWiki plugins to extend the parser/rendering mechanism
24 * need to inherit from this class
25 */
26class syntax_plugin_autolink2_add extends DokuWiki_Syntax_Plugin {
27
28    /**
29     * return some info
30     */
31    function getInfo() {
32        return confToHash(dirname(__FILE__).'/../plugin.info.txt');
33    }
34
35    function getType(){ return 'substition'; }
36    function getSort(){ return 304; }
37    function getPType(){ return 'block';}
38
39    /**
40     * Connect pattern to lexer
41     */
42    function connectTo($mode) {
43    // {{autolink>Anchor text}}
44    // '\{\{tag>.*?\}\}'
45      $this->Lexer->addSpecialPattern('\{\{autolink>.*?\}\}',$mode,'plugin_autolink2_add');
46    }
47
48    /**
49     * Handle the match
50     */
51
52  function handle($match, $state, $pos, &$handler){
53    global $ID;
54    global $conf;
55    global $ACT;
56    if ($ACT<>"show") return "";
57    $anchors = explode('|', substr($match, 11, -2)); // strip markup and split tags
58    if (!$my = plugin_load('helper', 'autolink2')) return false;
59    $my->_updateAutolinkIndex($ID, $anchors);
60    return $anchors;
61  }
62
63
64    /**
65     * Create output
66     */
67  function render($mode, &$renderer, $data) {
68    if ($data === false) return false;
69    if (!$my = plugin_load('helper', 'autolink2')) return false;
70    // XHTML output
71    if ($mode == 'xhtml'){
72      return true;
73    // for metadata renderer
74    } elseif ($mode == 'metadata'){
75//      if ($renderer->capture) $renderer->doc .= DOKU_LF.strip_tags($tags).DOKU_LF;
76//      foreach ($my->references as $ref => $exists){
77//        $renderer->meta['relation']['references'][$ref] = $exists;
78//      }
79      $renderer->meta['anchors'] = $data;
80      return true;
81    }
82    return false;
83  }
84}
85
86//Setup VIM: ex: et ts=4 enc=utf-8 :
87?>
88