1<?php
2/**
3 * Autolink2  Plugin
4 *
5 * @author Otto Vainio <otto@valjakko.net>
6 */
7
8if(!defined('DOKU_INC')) die();
9if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
10require_once(DOKU_PLUGIN.'action.php');
11
12class action_plugin_autolink2 extends DokuWiki_Action_Plugin {
13
14  /**
15   * return some info
16   */
17    function getInfo() {
18        return confToHash(dirname(__FILE__).'/plugin.info.txt');
19    }
20
21  /**
22   * Register its handlers with the DokuWiki's event controller
23   */
24  function register(&$controller) {
25    $controller->register_hook('PARSER_WIKITEXT_PREPROCESS', 'BEFORE',  $this, '_hookautolink');
26    $controller->register_hook('IO_WIKIPAGE_WRITE', 'BEFORE',  $this, '_hookautolinkwrite');
27  }
28
29  /**
30   */
31  function _hookautolink(&$event, $param) {
32    if (!$this->getConf('autoautolink')) return;
33    if ($my =& plugin_load('helper', 'autolink2')) $anchors = $my->getAnchors();
34    $x=$event->data;
35    if (substr($x,0,14)=='~~noautolink~~') {
36      $event->data = substr($x,14);
37    } else {
38      if (is_array($anchors)){
39        $pattern=$anchors[0];
40        $replace=$anchors[1];
41        if ($pattern<>'' and $replace<>'') {
42          $replaced = preg_replace($pattern,$replace,$x);
43          $x=$replaced;
44          $event->data = $x;
45        }
46      }
47    }
48  }
49  function _hookautolinkwrite(&$event, $param) {
50    if ($event->data[3]) return;
51    $x=$event->data[0][1];
52    $id="";
53    if ($event->data[1]) {
54      $id=$event->data[1].":";
55    }
56    $id=$id.$event->data[2];
57    if (empty($x)) {
58      if ($my =& plugin_load('helper', 'autolink2')) {
59        $my->_removeAutolinkIndex($id, '');
60      }
61    }
62  }
63}
64
65