1<?php 2/** 3 * Admin Plugin Prototype 4 * 5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 6 * @author Christopher Smith <chris@jalakai.co.uk> 7 */ 8if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/'); 9if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 10 11/** 12 * All DokuWiki plugins to extend the admin function 13 * need to inherit from this class 14 */ 15class DokuWiki_Admin_Plugin { 16 17 var $localised = false; 18 var $lang = array(); 19 20 /** 21 * General Info 22 * 23 * Needs to return a associative array with the following values: 24 * 25 * author - Author of the plugin 26 * email - Email address to contact the author 27 * date - Last modified date of the plugin in YYYY-MM-DD format 28 * name - Name of the plugin 29 * desc - Short description of the plugin (Text only) 30 * url - Website with more information on the plugin (eg. syntax description) 31 */ 32 function getInfo(){ 33 trigger_error('getInfo() not implemented in '.get_class($this), E_USER_WARNING); 34 } 35 36 function getMenuText($language) { 37 return $this->getLang('menu'); 38 } 39 40 function getMenuSort() { 41 return 1000; 42 } 43 44 function handle() { 45 trigger_error('handle() not implemented in '.get_class($this), E_USER_WARNING); 46 } 47 48 function html() { 49 trigger_error('html() not implemented in '.get_class($this), E_USER_WARNING); 50 } 51 52 // private methods (maybe a dokuwiki plugin base class is required for these) 53 54 // plugin introspection methods 55 // extract from class name, format = <plugin type>_plugin_<name>[_<component name>] 56 function getPluginType() { list($t) = explode('_', get_class($this), 2); return $t; } 57 function getPluginName() { list($t, $p, $n) = explode('_', get_class($this), 4); return $n; } 58 function getPluginComponent() { list($t, $p, $n, $c) = explode('_', get_class($this), 4); return (isset($c)?$c:''); } 59 60 function setupLocale() { 61 global $conf; // definitely don't invoke "global $lang" 62 $path = DOKU_PLUGIN.$this->getPluginName().'/lang/'; 63 64 // don't include once, in case several plugin components require the same language file 65 @include($path.'en/lang.php'); 66 if ($conf['lang'] != 'en') @include($path.$conf['lang'].'/lang.php'); 67 68 $this->lang = $lang; 69 $this->localised = true; 70 } 71 72 // plugin equivalent of localFN() 73 function plugin_localFN($id) { 74 global $conf; 75 $plugin = $this->getPluginName(); 76 $file = DOKU_PLUGIN.$plugin.'/lang/'.$conf['lang'].'/'.$id.'.txt'; 77 if(!@file_exists($file)){ 78 //fall back to english 79 $file = DOKU_PLUGIN.$plugin.'inc/lang/en/'.$id.'.txt'; 80 } 81 return $file; 82 } 83 84 // use this function to access plugin language strings 85 // to try to minimise unnecessary loading of the strings when the plugin doesn't require them 86 // e.g. when info plugin is querying plugins for information about themselves. 87 function getLang($id) { 88 if (!$this->localised) $this->setupLocale(); 89 90 return (isset($this->lang[$id]) ? $this->lang[$id] : ''); 91 } 92 93 // plugin equivalent of p_locale_xhtml() 94 function plugin_locale_xhtml($id) { 95 return p_cached_xhtml($this->plugin_localFN($id)); 96 } 97 98 // standard functions for outputing email addresses and links 99 // use these to avoid having to duplicate code to produce links in line with the installation configuration 100 function plugin_email($email, $name='', $class='', $more='') { 101 if (!$email) return $name; 102 $email = $this->obfuscate($email); 103 if (!$name) $name = $email; 104 $class = "class='".($class ? $class : 'mail')."'"; 105 return "<a href='mailto:$email' $class title='$email' $more>$name</a>"; 106 } 107 108 function plugin_link($link, $title='', $class='', $target='', $more='') { 109 global $conf; 110 111 $link = htmlentities($link); 112 if (!$title) $title = $link; 113 if (!$target) $target = $conf['target']['extern']; 114 if ($conf['relnofollow']) $more .= ' rel="nofollow"'; 115 116 if ($class) $class = " class='$class'"; 117 if ($target) $target = " target='$target'"; 118 if ($more) $more = " ".trim($more); 119 120 return "<a href='$link'$class$target$more>$title</a>"; 121 } 122 123 // output text string through the parser, allows dokuwiki markup to be used 124 // very ineffecient for small pieces of data - try not to use 125 function plugin_render($text, $format='xhtml') { 126 return p_render($format, p_get_instructions($text),$info); 127 } 128 129 // return an obfuscated email address in line with $conf['mailguard'] setting 130 // FIXME?? this should really be a common function, used by the renderer as well - no point maintaining two! 131 function obfuscate($email) { 132 global $conf; 133 134 switch ($conf['mailguard']) { 135 case 'visible' : 136 $obfuscate = array('@' => '[at]', '.' => '[dot]', '-' => '[dash]'); 137 return strtr($email, $obfuscate); 138 139 case 'hex' : 140 $encode = ''; 141 for ($x=0; $x < strlen($email); $x++) $encode .= '&#x' . bin2hex($email{$x}).';'; 142 return $encode; 143 144 case 'none' : 145 default : 146 return $email; 147 } 148 } 149 150} 151//Setup VIM: ex: et ts=4 enc=utf-8 : 152