1<?php 2/** 3 * Autolink Action Plugin: 4 * 5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 6 * @author Vincent Fleury <fleury.vincent@gmail.com> 7 * @author Arthur Lobert <arthur.lobert@gmail.com> 8 */ 9 10if(!defined('DOKU_INC')) die(); 11if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 12if (!defined('DOKU_REG')) define ('DOKU_REG', DOKU_PLUGIN.'autolink3/register/'); 13if (!defined('DOKU_PAGES')) define ('DOKU_PAGES', realpath('./data/pages')); 14require_once (DOKU_PLUGIN.'action.php'); 15require_once ('sys.php'); 16 17class action_plugin_autolink3 extends DokuWiki_Action_Plugin 18{ 19 /** 20 * return some info 21 */ 22 function getInfo() 23 { 24 return array( 25 'author' => 'Arthur Lobert', 26 'email' => 'arthur.lobert@gmail.com', 27 'date' => @file_get_contents(DOKU_PLUGIN.'autolink3/VERSION'), 28 'name' => 'autolink3', 29 'desc' => 'Automatic link Manager', 30 'url' => 'http://www.dokuwiki.org/plugin:autolink3', 31 ); 32 } 33 34 /** 35 * Register its handlers with the DokuWiki's event controller 36 */ 37 38 function register(&$controller) 39 { 40 $controller->register_hook('IO_WIKIPAGE_WRITE', 'BEFORE', $this, 41 '_autolink', array()); 42 } 43 44/** 45 * check if the current page is concerned by the by the link processing. 46 * @param $page : name of the current page 47 * @param $text : content of $page 48 * @return $text 49 */ 50 private function _is_link_application($page, $text) 51 { 52 $link = sort_tab(read_file(), compare_len); 53 $link = sort_tab_space($link); 54 foreach ($link as $elem):{ 55 $locate = trim($elem[2]); 56 $locate = str_replace('\\', '/', DOKU_PAGES.str_replace(':', '/', $locate)); 57 $page = realpath($page); 58 $locate = realpath($locate); 59 if (!strncmp($page, $locate, strlen($locate))) 60 { 61 $text = link_replace($text, $elem[0], $elem[1], str_replace(':', '/', $page)); 62 } 63 } 64 endforeach; 65 return ($text); 66 } 67 68 /** 69 * Apply autolink to page. 70 * 71 * @author Vincent Fleury <fleury.vincent@gmail.com> 72 */ 73 74 //TODO : private or not 75 76 function _autolink(&$event, $param) 77 { 78 $event->data[0][1] = $this->_is_link_application($event->data[0][0], $event->data[0][1]); 79 } 80} 81?>