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