1*e1d9dcc8SAndreas Gohr<?php 2*e1d9dcc8SAndreas Gohr 3*e1d9dcc8SAndreas Gohrnamespace dokuwiki\Extension; 4*e1d9dcc8SAndreas Gohr 5*e1d9dcc8SAndreas Gohr/** 6*e1d9dcc8SAndreas Gohr * Admin Plugin Prototype 7*e1d9dcc8SAndreas Gohr * 8*e1d9dcc8SAndreas Gohr * Implements an admin interface in a plugin 9*e1d9dcc8SAndreas Gohr * 10*e1d9dcc8SAndreas Gohr * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 11*e1d9dcc8SAndreas Gohr * @author Christopher Smith <chris@jalakai.co.uk> 12*e1d9dcc8SAndreas Gohr */ 13*e1d9dcc8SAndreas Gohrabstract class AdminPlugin extends Plugin 14*e1d9dcc8SAndreas Gohr{ 15*e1d9dcc8SAndreas Gohr 16*e1d9dcc8SAndreas Gohr /** 17*e1d9dcc8SAndreas Gohr * Return the text that is displayed at the main admin menu 18*e1d9dcc8SAndreas Gohr * (Default localized language string 'menu' is returned, override this function for setting another name) 19*e1d9dcc8SAndreas Gohr * 20*e1d9dcc8SAndreas Gohr * @param string $language language code 21*e1d9dcc8SAndreas Gohr * @return string menu string 22*e1d9dcc8SAndreas Gohr */ 23*e1d9dcc8SAndreas Gohr public function getMenuText($language) 24*e1d9dcc8SAndreas Gohr { 25*e1d9dcc8SAndreas Gohr $menutext = $this->getLang('menu'); 26*e1d9dcc8SAndreas Gohr if (!$menutext) { 27*e1d9dcc8SAndreas Gohr $info = $this->getInfo(); 28*e1d9dcc8SAndreas Gohr $menutext = $info['name'] . ' ...'; 29*e1d9dcc8SAndreas Gohr } 30*e1d9dcc8SAndreas Gohr return $menutext; 31*e1d9dcc8SAndreas Gohr } 32*e1d9dcc8SAndreas Gohr 33*e1d9dcc8SAndreas Gohr /** 34*e1d9dcc8SAndreas Gohr * Return the path to the icon being displayed in the main admin menu. 35*e1d9dcc8SAndreas Gohr * By default it tries to find an 'admin.svg' file in the plugin directory. 36*e1d9dcc8SAndreas Gohr * (Override this function for setting another image) 37*e1d9dcc8SAndreas Gohr * 38*e1d9dcc8SAndreas Gohr * Important: you have to return a single path, monochrome SVG icon! It has to be 39*e1d9dcc8SAndreas Gohr * under 2 Kilobytes! 40*e1d9dcc8SAndreas Gohr * 41*e1d9dcc8SAndreas Gohr * We recommend icons from https://materialdesignicons.com/ or to use a matching 42*e1d9dcc8SAndreas Gohr * style. 43*e1d9dcc8SAndreas Gohr * 44*e1d9dcc8SAndreas Gohr * @return string full path to the icon file 45*e1d9dcc8SAndreas Gohr */ 46*e1d9dcc8SAndreas Gohr public function getMenuIcon() 47*e1d9dcc8SAndreas Gohr { 48*e1d9dcc8SAndreas Gohr $plugin = $this->getPluginName(); 49*e1d9dcc8SAndreas Gohr return DOKU_PLUGIN . $plugin . '/admin.svg'; 50*e1d9dcc8SAndreas Gohr } 51*e1d9dcc8SAndreas Gohr 52*e1d9dcc8SAndreas Gohr /** 53*e1d9dcc8SAndreas Gohr * Determine position in list in admin window 54*e1d9dcc8SAndreas Gohr * Lower values are sorted up 55*e1d9dcc8SAndreas Gohr * 56*e1d9dcc8SAndreas Gohr * @return int 57*e1d9dcc8SAndreas Gohr */ 58*e1d9dcc8SAndreas Gohr public function getMenuSort() 59*e1d9dcc8SAndreas Gohr { 60*e1d9dcc8SAndreas Gohr return 1000; 61*e1d9dcc8SAndreas Gohr } 62*e1d9dcc8SAndreas Gohr 63*e1d9dcc8SAndreas Gohr /** 64*e1d9dcc8SAndreas Gohr * Carry out required processing 65*e1d9dcc8SAndreas Gohr */ 66*e1d9dcc8SAndreas Gohr public function handle() 67*e1d9dcc8SAndreas Gohr { 68*e1d9dcc8SAndreas Gohr // some plugins might not need this 69*e1d9dcc8SAndreas Gohr } 70*e1d9dcc8SAndreas Gohr 71*e1d9dcc8SAndreas Gohr /** 72*e1d9dcc8SAndreas Gohr * Output html of the admin page 73*e1d9dcc8SAndreas Gohr */ 74*e1d9dcc8SAndreas Gohr abstract public function html(); 75*e1d9dcc8SAndreas Gohr 76*e1d9dcc8SAndreas Gohr /** 77*e1d9dcc8SAndreas Gohr * Checks if access should be granted to this admin plugin 78*e1d9dcc8SAndreas Gohr * 79*e1d9dcc8SAndreas Gohr * @return bool true if the current user may access this admin plugin 80*e1d9dcc8SAndreas Gohr */ 81*e1d9dcc8SAndreas Gohr public function isAccessibleByCurrentUser() { 82*e1d9dcc8SAndreas Gohr $data = []; 83*e1d9dcc8SAndreas Gohr $data['instance'] = $this; 84*e1d9dcc8SAndreas Gohr $data['hasAccess'] = false; 85*e1d9dcc8SAndreas Gohr 86*e1d9dcc8SAndreas Gohr $event = new Event('ADMINPLUGIN_ACCESS_CHECK', $data); 87*e1d9dcc8SAndreas Gohr if($event->advise_before()) { 88*e1d9dcc8SAndreas Gohr if ($this->forAdminOnly()) { 89*e1d9dcc8SAndreas Gohr $data['hasAccess'] = auth_isadmin(); 90*e1d9dcc8SAndreas Gohr } else { 91*e1d9dcc8SAndreas Gohr $data['hasAccess'] = auth_ismanager(); 92*e1d9dcc8SAndreas Gohr } 93*e1d9dcc8SAndreas Gohr } 94*e1d9dcc8SAndreas Gohr $event->advise_after(); 95*e1d9dcc8SAndreas Gohr 96*e1d9dcc8SAndreas Gohr return $data['hasAccess']; 97*e1d9dcc8SAndreas Gohr } 98*e1d9dcc8SAndreas Gohr 99*e1d9dcc8SAndreas Gohr /** 100*e1d9dcc8SAndreas Gohr * Return true for access only by admins (config:superuser) or false if managers are allowed as well 101*e1d9dcc8SAndreas Gohr * 102*e1d9dcc8SAndreas Gohr * @return bool 103*e1d9dcc8SAndreas Gohr */ 104*e1d9dcc8SAndreas Gohr public function forAdminOnly() 105*e1d9dcc8SAndreas Gohr { 106*e1d9dcc8SAndreas Gohr return true; 107*e1d9dcc8SAndreas Gohr } 108*e1d9dcc8SAndreas Gohr 109*e1d9dcc8SAndreas Gohr /** 110*e1d9dcc8SAndreas Gohr * Return array with ToC items. Items can be created with the html_mktocitem() 111*e1d9dcc8SAndreas Gohr * 112*e1d9dcc8SAndreas Gohr * @see html_mktocitem() 113*e1d9dcc8SAndreas Gohr * @see tpl_toc() 114*e1d9dcc8SAndreas Gohr * 115*e1d9dcc8SAndreas Gohr * @return array 116*e1d9dcc8SAndreas Gohr */ 117*e1d9dcc8SAndreas Gohr public function getTOC() 118*e1d9dcc8SAndreas Gohr { 119*e1d9dcc8SAndreas Gohr return array(); 120*e1d9dcc8SAndreas Gohr } 121*e1d9dcc8SAndreas Gohr 122*e1d9dcc8SAndreas Gohr} 123*e1d9dcc8SAndreas Gohr 124