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 if ($this->localised) return; 62 63 global $conf; // definitely don't invoke "global $lang" 64 $path = DOKU_PLUGIN.$this->getPluginName().'/lang/'; 65 66 // don't include once, in case several plugin components require the same language file 67 @include($path.'en/lang.php'); 68 if ($conf['lang'] != 'en') @include($path.$conf['lang'].'/lang.php'); 69 70 $this->lang = $lang; 71 $this->localised = true; 72 } 73 74 // plugin equivalent of localFN() 75 function plugin_localFN($id) { 76 global $conf; 77 $plugin = $this->getPluginName(); 78 $file = DOKU_PLUGIN.$plugin.'/lang/'.$conf['lang'].'/'.$id.'.txt'; 79 if(!@file_exists($file)){ 80 //fall back to english 81 $file = DOKU_PLUGIN.$plugin.'/lang/en/'.$id.'.txt'; 82 } 83 return $file; 84 } 85 86 // use this function to access plugin language strings 87 // to try to minimise unnecessary loading of the strings when the plugin doesn't require them 88 // e.g. when info plugin is querying plugins for information about themselves. 89 function getLang($id) { 90 if (!$this->localised) $this->setupLocale(); 91 92 return (isset($this->lang[$id]) ? $this->lang[$id] : ''); 93 } 94 95 // plugin equivalent of p_locale_xhtml() 96 function plugin_locale_xhtml($id) { 97 return p_cached_xhtml($this->plugin_localFN($id)); 98 } 99 100 // standard functions for outputing email addresses and links 101 // use these to avoid having to duplicate code to produce links in line with the installation configuration 102 function plugin_email($email, $name='', $class='', $more='') { 103 if (!$email) return $name; 104 $email = obfuscate($email); 105 if (!$name) $name = $email; 106 $class = "class='".($class ? $class : 'mail')."'"; 107 return "<a href='mailto:$email' $class title='$email' $more>$name</a>"; 108 } 109 110 function plugin_link($link, $title='', $class='', $target='', $more='') { 111 global $conf; 112 113 $link = htmlentities($link); 114 if (!$title) $title = $link; 115 if (!$target) $target = $conf['target']['extern']; 116 if ($conf['relnofollow']) $more .= ' rel="nofollow"'; 117 118 if ($class) $class = " class='$class'"; 119 if ($target) $target = " target='$target'"; 120 if ($more) $more = " ".trim($more); 121 122 return "<a href='$link'$class$target$more>$title</a>"; 123 } 124 125 // output text string through the parser, allows dokuwiki markup to be used 126 // very ineffecient for small pieces of data - try not to use 127 function plugin_render($text, $format='xhtml') { 128 return p_render($format, p_get_instructions($text),$info); 129 } 130 131} 132//Setup VIM: ex: et ts=4 enc=utf-8 : 133