1<?php 2if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/'); 3if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 4require_once(DOKU_PLUGIN.'admin.php'); 5 6/** 7 * All DokuWiki plugins to extend the admin function 8 * need to inherit from this class 9 */ 10class admin_plugin_autolink2 extends DokuWiki_Admin_Plugin { 11 12 var $_auth = null; // auth object 13 function admin_plugin_autolink2(){ 14 global $auth; 15 16 $this->setupLocale(); 17 18 if (!isset($auth)) { 19 $this->disabled = $this->lang['noauth']; 20 } else if (!$auth->canDo('getUsers')) { 21 $this->disabled = $this->lang['nosupport']; 22 } else { 23 24 // we're good to go 25 $this->_auth = & $auth; 26 27 } 28 } 29 30 /** 31 * return some info 32 */ 33 function getInfo() { 34 return confToHash(dirname(__FILE__).'/plugin.info.txt'); 35 } 36 37 /** 38 * return sort order for position in admin menu 39 */ 40 function getMenuSort() { 41 return 999; 42 } 43 44 /** 45 * handle user request 46 */ 47 function handle() { 48 if (isset($_REQUEST['delete'])) { 49 $old=DOKU_PLUGIN.'autolink/data/links.php'; 50 @unlink($old); 51 global $ID; 52 header("Location: ".wl($ID,array('do'=>'admin','page'=>'autolink2'),true,'&')); 53 exit(); 54 } 55 } 56 57 /** 58 * output appropriate html 59 */ 60 function html() { 61 global $conf; 62 global $ID; 63 64 if(is_null($this->_auth)) { 65 print $this->lang['badauth']; 66 return false; 67 } 68 69 require_once (DOKU_INC.'inc/search.php'); 70 71 $sopts=array(); 72 $sopts['query']="autolink"; 73 search($replace, $conf['datadir'], array($this, 'search'), $sopts); 74 75 if (!isset($replace)) { 76 if (@file_exists(DOKU_PLUGIN.'autolink/data/links.php')) { 77 $oldplugin=DOKU_PLUGIN.'autolink/syntax/add.php'; 78 if (@file_exists($oldplugin)) { 79 ptln($this->lang["removeold"]); 80 } else { 81 ptln($this->lang["noneed"]); 82 } 83 } else { 84 ptln($this->lang["noautolinks"]); 85 ptln('<form action="'.wl($ID).'" method="post">'); 86 ptln('<input type="hidden" name="do" value="admin" />'); 87 ptln('<input type="hidden" name="page" value="autolink2" />'); 88 ptln("<p><input type=\"checkbox\" name=\"delete\"> ".$this->lang['deleteold']."<br />"); 89 ptln("<input type=\"submit\" name=\"deleteold\" class=\"button\" value=\"".$this->lang['delete']."\" /></p>"); 90 ptln("</form>"); 91 } 92 } else { 93 ptln("<table class=\"inline\">"); 94 ptln(" <thead>"); 95 ptln(" <tr>"); 96 ptln(" <th>".$this->lang["autolink2_oldpages"]."</th></thead>"); 97 foreach ($replace as $value){ 98 $page=substr($value,3,-2); 99 $lnk="[[:" . $value['id'] . "|" . $value['id'] . "]]"; 100 ptln("<tr><td>"); 101 $x=p_render('xhtml',p_get_instructions($lnk),$info); 102 $x=substr($x,4,-5); 103 ptln($x); 104 ptln("</td></tr>"); 105 } 106 ptln("</table>"); 107 } 108 } 109 110 function search(&$data,$base,$file,$type,$lvl,$opts){ 111 if(!preg_match('#\.txt$#',$file)) return true;; 112 require_once (DOKU_INC.'inc/search.php'); 113 $words[]=$opts['query']; 114 $reg="autolink "; 115 return search_regex(&$data,$base,$file,$reg,$words); 116 } 117}