| [ Index ] |
PHP Cross Reference of DokuWiki |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * DokuWiki Plugin base class 4 * 5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 6 * @author Christopher Smith <chris@jalakai.co.uk> 7 */ 8 9 /** 10 * Do not inherit directly from this class, instead inherit from the specialized 11 * ones in lib/plugin 12 */ 13 class DokuWiki_Plugin { 14 15 var $localised = false; // set to true by setupLocale() after loading language dependent strings 16 var $lang = array(); // array to hold language dependent strings, best accessed via ->getLang() 17 var $configloaded = false; // set to true by loadConfig() after loading plugin configuration variables 18 var $conf = array(); // array to hold plugin settings, best accessed via ->getConf() 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 // plugin introspection methods 37 // extract from class name, format = <plugin type>_plugin_<name>[_<component name>] 38 function getPluginType() { list($t) = explode('_', get_class($this), 2); return $t; } 39 function getPluginName() { list($t, $p, $n) = explode('_', get_class($this), 4); return $n; } 40 function getPluginComponent() { list($t, $p, $n, $c) = explode('_', get_class($this), 4); return (isset($c)?$c:''); } 41 42 // localisation methods 43 /** 44 * getLang($id) 45 * use this function to access plugin language strings 46 * to try to minimise unnecessary loading of the strings when the plugin doesn't require them 47 * e.g. when info plugin is querying plugins for information about themselves. 48 * 49 * @param $id id of the string to be retrieved 50 * @return string string in appropriate language or english if not available 51 */ 52 function getLang($id) { 53 if (!$this->localised) $this->setupLocale(); 54 55 return (isset($this->lang[$id]) ? $this->lang[$id] : ''); 56 } 57 58 /** 59 * locale_xhtml($id) 60 * 61 * retrieve a language dependent file and pass to xhtml renderer for display 62 * plugin equivalent of p_locale_xhtml() 63 * 64 * @param $id id of language dependent wiki page 65 * @return string parsed contents of the wiki page in xhtml format 66 */ 67 function locale_xhtml($id) { 68 return p_cached_output($this->localFN($id)); 69 } 70 71 /** 72 * localFN($id) 73 * prepends appropriate path for a language dependent filename 74 * plugin equivalent of localFN() 75 */ 76 function localFN($id) { 77 global $conf; 78 $plugin = $this->getPluginName(); 79 $file = DOKU_PLUGIN.$plugin.'/lang/'.$conf['lang'].'/'.$id.'.txt'; 80 if(!@file_exists($file)){ 81 //fall back to english 82 $file = DOKU_PLUGIN.$plugin.'/lang/en/'.$id.'.txt'; 83 } 84 return $file; 85 } 86 87 /** 88 * setupLocale() 89 * reads all the plugins language dependent strings into $this->lang 90 * this function is automatically called by getLang() 91 */ 92 function setupLocale() { 93 if ($this->localised) return; 94 95 global $conf; // definitely don't invoke "global $lang" 96 $path = DOKU_PLUGIN.$this->getPluginName().'/lang/'; 97 98 $lang = array(); 99 100 // don't include once, in case several plugin components require the same language file 101 @include($path.'en/lang.php'); 102 if ($conf['lang'] != 'en') @include($path.$conf['lang'].'/lang.php'); 103 104 $this->lang = $lang; 105 $this->localised = true; 106 } 107 108 // configuration methods 109 /** 110 * getConf($setting) 111 * 112 * use this function to access plugin configuration variables 113 */ 114 function getConf($setting){ 115 116 if (!$this->configloaded){ $this->loadConfig(); } 117 118 return $this->conf[$setting]; 119 } 120 121 /** 122 * loadConfig() 123 * merges the plugin's default settings with any local settings 124 * this function is automatically called through getConf() 125 */ 126 function loadConfig(){ 127 global $conf; 128 129 $defaults = $this->readDefaultSettings(); 130 $plugin = $this->getPluginName(); 131 132 foreach ($defaults as $key => $value) { 133 if (isset($conf['plugin'][$plugin][$key])) continue; 134 $conf['plugin'][$plugin][$key] = $value; 135 } 136 137 $this->configloaded = true; 138 $this->conf =& $conf['plugin'][$plugin]; 139 } 140 141 /** 142 * read the plugin's default configuration settings from conf/default.php 143 * this function is automatically called through getConf() 144 * 145 * @return array setting => value 146 */ 147 function readDefaultSettings() { 148 149 $path = DOKU_PLUGIN.$this->getPluginName().'/conf/'; 150 $conf = array(); 151 152 if (@file_exists($path.'default.php')) { 153 include($path.'default.php'); 154 } 155 156 return $conf; 157 } 158 159 /** 160 * Loads a given helper plugin (if enabled) 161 * 162 * @author Esther Brunner <wikidesign@gmail.com> 163 * 164 * @param $name name of plugin to load 165 * @param $msg message to display in case the plugin is not available 166 * 167 * @return object helper plugin object 168 */ 169 function loadHelper($name, $msg){ 170 if (!plugin_isdisabled($name)) $obj =& plugin_load('helper',$name); 171 else $obj = NULL; 172 if (is_null($obj) && $msg) msg("Helper plugin $name is not available or invalid.",-1); 173 return $obj; 174 } 175 176 // standard functions for outputing email addresses and links 177 // use these to avoid having to duplicate code to produce links in line with the installation configuration 178 179 /** 180 * email 181 * standardised function to generate an email link according to obfuscation settings 182 */ 183 function email($email, $name='', $class='', $more='') { 184 if (!$email) return $name; 185 $email = obfuscate($email); 186 if (!$name) $name = $email; 187 $class = "class='".($class ? $class : 'mail')."'"; 188 return "<a href='mailto:$email' $class title='$email' $more>$name</a>"; 189 } 190 191 /** 192 * external_link 193 * standardised function to generate an external link according to conf settings 194 */ 195 function external_link($link, $title='', $class='', $target='', $more='') { 196 global $conf; 197 198 $link = htmlentities($link); 199 if (!$title) $title = $link; 200 if (!$target) $target = $conf['target']['extern']; 201 if ($conf['relnofollow']) $more .= ' rel="nofollow"'; 202 203 if ($class) $class = " class='$class'"; 204 if ($target) $target = " target='$target'"; 205 if ($more) $more = " ".trim($more); 206 207 return "<a href='$link'$class$target$more>$title</a>"; 208 } 209 210 /** 211 * output text string through the parser, allows dokuwiki markup to be used 212 * very ineffecient for small pieces of data - try not to use 213 */ 214 function render($text, $format='xhtml') { 215 return p_render($format, p_get_instructions($text),$info); 216 } 217 218 // deprecated functions 219 function plugin_localFN($id) { return $this->localFN($id); } 220 function plugin_locale_xhtml($id) { return $this->locale_xhtml($id); } 221 function plugin_email($e, $n='', $c='', $m='') { return $this->email($e, $n, $c, $m); } 222 function plugin_link($l, $t='', $c='', $to='', $m='') { return $this->external_link($l, $t, $c, $to, $m); } 223 function plugin_render($t, $f='xhtml') { return $this->render($t, $f); } 224 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Tue Dec 2 01:30:01 2008 | Cross-referenced by PHPXref 0.7 |