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