10470c28fSAndreas Gohr<?php 20470c28fSAndreas Gohrnamespace dokuwiki\Ui; 30470c28fSAndreas Gohr 4*79a2d784SGerrit Uitslaguse dokuwiki\Extension\AdminPlugin; 52d85e841SAndreas Gohruse dokuwiki\Utf8\Sort; 62d85e841SAndreas Gohr 70470c28fSAndreas Gohr/** 80470c28fSAndreas Gohr * Class Admin 90470c28fSAndreas Gohr * 100470c28fSAndreas Gohr * Displays the Admin screen 110470c28fSAndreas Gohr * 120470c28fSAndreas Gohr * @package dokuwiki\Ui 130470c28fSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 140470c28fSAndreas Gohr * @author Håkan Sandell <hakan.sandell@home.se> 150470c28fSAndreas Gohr */ 160470c28fSAndreas Gohrclass Admin extends Ui { 170470c28fSAndreas Gohr 1870cc2cbfSAndreas Gohr protected $forAdmins = array('usermanager', 'acl', 'extension', 'config', 'logviewer', 'styling'); 1964cdf779SAndreas Gohr protected $forManagers = array('revert', 'popularity'); 2064cdf779SAndreas Gohr /** @var array[] */ 210470c28fSAndreas Gohr protected $menu; 220470c28fSAndreas Gohr 230470c28fSAndreas Gohr /** 240470c28fSAndreas Gohr * Display the UI element 250470c28fSAndreas Gohr * 260470c28fSAndreas Gohr * @return void 270470c28fSAndreas Gohr */ 280470c28fSAndreas Gohr public function show() { 290470c28fSAndreas Gohr $this->menu = $this->getPluginList(); 305d2e38cbSAndreas Gohr echo '<div class="ui-admin">'; 310470c28fSAndreas Gohr echo p_locale_xhtml('admin'); 32052e1c84SAndreas Gohr 3364cdf779SAndreas Gohr $this->showMenu('admin'); 3464cdf779SAndreas Gohr $this->showMenu('manager'); 35052e1c84SAndreas Gohr $this->showSecurityCheck(); 360470c28fSAndreas Gohr $this->showVersion(); 3764cdf779SAndreas Gohr $this->showMenu('other'); 38713faa94SAndreas Gohr echo '</div>'; 390470c28fSAndreas Gohr } 400470c28fSAndreas Gohr 410470c28fSAndreas Gohr /** 4264cdf779SAndreas Gohr * Show the given menu of available plugins 4364cdf779SAndreas Gohr * 4464cdf779SAndreas Gohr * @param string $type admin|manager|other 450470c28fSAndreas Gohr */ 4664cdf779SAndreas Gohr protected function showMenu($type) { 4764cdf779SAndreas Gohr if (!$this->menu[$type]) return; 480470c28fSAndreas Gohr 4964cdf779SAndreas Gohr if ($type === 'other') { 500470c28fSAndreas Gohr echo p_locale_xhtml('adminplugins'); 5164cdf779SAndreas Gohr $class = 'admin_plugins'; 5264cdf779SAndreas Gohr } else { 5364cdf779SAndreas Gohr $class = 'admin_tasks'; 5464cdf779SAndreas Gohr } 5564cdf779SAndreas Gohr 5664cdf779SAndreas Gohr echo "<ul class=\"$class\">"; 5764cdf779SAndreas Gohr foreach ($this->menu[$type] as $item) { 580470c28fSAndreas Gohr $this->showMenuItem($item); 590470c28fSAndreas Gohr } 600470c28fSAndreas Gohr echo '</ul>'; 610470c28fSAndreas Gohr } 620470c28fSAndreas Gohr 630470c28fSAndreas Gohr /** 640470c28fSAndreas Gohr * Display the DokuWiki version 650470c28fSAndreas Gohr */ 660470c28fSAndreas Gohr protected function showVersion() { 670470c28fSAndreas Gohr echo '<div id="admin__version">'; 680470c28fSAndreas Gohr echo getVersion(); 690470c28fSAndreas Gohr echo '</div>'; 700470c28fSAndreas Gohr } 710470c28fSAndreas Gohr 720470c28fSAndreas Gohr /** 730470c28fSAndreas Gohr * data security check 740470c28fSAndreas Gohr * 750470c28fSAndreas Gohr * simple check if the 'savedir' is relative and accessible when appended to DOKU_URL 760470c28fSAndreas Gohr * 770470c28fSAndreas Gohr * it verifies either: 780470c28fSAndreas Gohr * 'savedir' has been moved elsewhere, or 790470c28fSAndreas Gohr * has protection to prevent the webserver serving files from it 80052e1c84SAndreas Gohr * 81052e1c84SAndreas Gohr * The actual check is carried out via JavaScript. See behaviour.js 820470c28fSAndreas Gohr */ 830470c28fSAndreas Gohr protected function showSecurityCheck() { 840470c28fSAndreas Gohr global $conf; 850470c28fSAndreas Gohr if(substr($conf['savedir'], 0, 2) !== './') return; 8664159a61SAndreas Gohr $img = DOKU_URL . $conf['savedir'] . 8764159a61SAndreas Gohr '/dont-panic-if-you-see-this-in-your-logs-it-means-your-directory-permissions-are-correct.png'; 88d3f829c2SAndreas Gohr echo '<div id="security__check" data-src="' . $img . '"></div>'; 890470c28fSAndreas Gohr } 900470c28fSAndreas Gohr 910470c28fSAndreas Gohr /** 920470c28fSAndreas Gohr * Display a single Admin menu item 930470c28fSAndreas Gohr * 940470c28fSAndreas Gohr * @param array $item 950470c28fSAndreas Gohr */ 960470c28fSAndreas Gohr protected function showMenuItem($item) { 970470c28fSAndreas Gohr global $ID; 980470c28fSAndreas Gohr if(blank($item['prompt'])) return; 990470c28fSAndreas Gohr echo '<li><div class="li">'; 100220b8a20SAndreas Gohr echo '<a href="' . wl($ID, 'do=admin&page=' . $item['plugin']) . '">'; 101220b8a20SAndreas Gohr echo '<span class="icon">'; 1024cd2074fSAndreas Gohr echo inlineSVG($item['icon']); 1030470c28fSAndreas Gohr echo '</span>'; 104220b8a20SAndreas Gohr echo '<span class="prompt">'; 1050470c28fSAndreas Gohr echo $item['prompt']; 106220b8a20SAndreas Gohr echo '</span>'; 1070470c28fSAndreas Gohr echo '</a>'; 1080470c28fSAndreas Gohr echo '</div></li>'; 1090470c28fSAndreas Gohr } 1100470c28fSAndreas Gohr 1110470c28fSAndreas Gohr /** 1120470c28fSAndreas Gohr * Build list of admin functions from the plugins that handle them 1130470c28fSAndreas Gohr * 1140470c28fSAndreas Gohr * Checks the current permissions to decide on manager or admin plugins 1150470c28fSAndreas Gohr * 1160470c28fSAndreas Gohr * @return array list of plugins with their properties 1170470c28fSAndreas Gohr */ 1180470c28fSAndreas Gohr protected function getPluginList() { 1190470c28fSAndreas Gohr global $conf; 1200470c28fSAndreas Gohr 1210470c28fSAndreas Gohr $pluginlist = plugin_list('admin'); 12264cdf779SAndreas Gohr $menu = ['admin' => [], 'manager' => [], 'other' => []]; 12364cdf779SAndreas Gohr 1240470c28fSAndreas Gohr foreach($pluginlist as $p) { 125*79a2d784SGerrit Uitslag /** @var AdminPlugin $obj */ 1260470c28fSAndreas Gohr if(($obj = plugin_load('admin', $p)) === null) continue; 1270470c28fSAndreas Gohr 1280470c28fSAndreas Gohr // check permissions 12964cdf779SAndreas Gohr if (!$obj->isAccessibleByCurrentUser()) continue; 1300470c28fSAndreas Gohr 13164cdf779SAndreas Gohr if (in_array($p, $this->forAdmins, true)) { 13264cdf779SAndreas Gohr $type = 'admin'; 13364cdf779SAndreas Gohr } elseif (in_array($p, $this->forManagers, true)){ 13464cdf779SAndreas Gohr $type = 'manager'; 13564cdf779SAndreas Gohr } else { 13664cdf779SAndreas Gohr $type = 'other'; 13764cdf779SAndreas Gohr } 13864cdf779SAndreas Gohr 13964cdf779SAndreas Gohr $menu[$type][$p] = array( 1400470c28fSAndreas Gohr 'plugin' => $p, 1410470c28fSAndreas Gohr 'prompt' => $obj->getMenuText($conf['lang']), 1420470c28fSAndreas Gohr 'icon' => $obj->getMenuIcon(), 1430470c28fSAndreas Gohr 'sort' => $obj->getMenuSort(), 1440470c28fSAndreas Gohr ); 1450470c28fSAndreas Gohr } 1460470c28fSAndreas Gohr 1470470c28fSAndreas Gohr // sort by name, then sort 14864cdf779SAndreas Gohr uasort($menu['admin'], [$this, 'menuSort']); 14964cdf779SAndreas Gohr uasort($menu['manager'], [$this, 'menuSort']); 15064cdf779SAndreas Gohr uasort($menu['other'], [$this, 'menuSort']); 1510470c28fSAndreas Gohr 1520470c28fSAndreas Gohr return $menu; 1530470c28fSAndreas Gohr } 1540470c28fSAndreas Gohr 15564cdf779SAndreas Gohr /** 15664cdf779SAndreas Gohr * Custom sorting for admin menu 15764cdf779SAndreas Gohr * 15864cdf779SAndreas Gohr * We sort alphabetically first, then by sort value 15964cdf779SAndreas Gohr * 16064cdf779SAndreas Gohr * @param array $a 16164cdf779SAndreas Gohr * @param array $b 16264cdf779SAndreas Gohr * @return int 16364cdf779SAndreas Gohr */ 16464cdf779SAndreas Gohr protected function menuSort($a, $b) { 1652d85e841SAndreas Gohr $strcmp = Sort::strcmp($a['prompt'], $b['prompt']); 16664cdf779SAndreas Gohr if($strcmp != 0) return $strcmp; 16764cdf779SAndreas Gohr if($a['sort'] === $b['sort']) return 0; 16864cdf779SAndreas Gohr return ($a['sort'] < $b['sort']) ? -1 : 1; 16964cdf779SAndreas Gohr } 1700470c28fSAndreas Gohr} 171