1981e70caSAndreas Gohr<?php 2981e70caSAndreas Gohr 3981e70caSAndreas Gohrnamespace dokuwiki\plugin\extension; 4981e70caSAndreas Gohr 5*652715ccSAndreas Gohruse dokuwiki\Form\Form; 6*652715ccSAndreas Gohr 7981e70caSAndreas Gohrclass GuiAdmin extends Gui 8981e70caSAndreas Gohr{ 9981e70caSAndreas Gohr public function render() 10981e70caSAndreas Gohr { 11981e70caSAndreas Gohr $html = '<div id="extension__manager">'; 12981e70caSAndreas Gohr 13981e70caSAndreas Gohr $html .= $this->tabNavigation(); 14981e70caSAndreas Gohr 15981e70caSAndreas Gohr switch ($this->currentTab()) { 16981e70caSAndreas Gohr case 'search': 17981e70caSAndreas Gohr $html .= $this->tabSearch(); 18981e70caSAndreas Gohr break; 19981e70caSAndreas Gohr case 'templates': 20981e70caSAndreas Gohr $html .= $this->tabTemplates(); 21981e70caSAndreas Gohr break; 22981e70caSAndreas Gohr case 'install': 23981e70caSAndreas Gohr $html .= $this->tabInstall(); 24981e70caSAndreas Gohr break; 25981e70caSAndreas Gohr case 'plugins': 26981e70caSAndreas Gohr default: 27981e70caSAndreas Gohr $html .= $this->tabPlugins(); 28981e70caSAndreas Gohr } 29981e70caSAndreas Gohr 30981e70caSAndreas Gohr $html .= '</div>'; 31981e70caSAndreas Gohr return $html; 32981e70caSAndreas Gohr } 33981e70caSAndreas Gohr 34981e70caSAndreas Gohr /** 35981e70caSAndreas Gohr * Print the tab navigation 36981e70caSAndreas Gohr * 37981e70caSAndreas Gohr */ 38981e70caSAndreas Gohr public function tabNavigation() 39981e70caSAndreas Gohr { 40981e70caSAndreas Gohr $html = '<ul class="tabs">'; 41981e70caSAndreas Gohr foreach ($this->tabs as $tab) { 42981e70caSAndreas Gohr $url = $this->tabURL($tab); 43981e70caSAndreas Gohr if ($this->currentTab() == $tab) { 44981e70caSAndreas Gohr $class = ' active'; 45981e70caSAndreas Gohr } else { 46981e70caSAndreas Gohr $class = ''; 47981e70caSAndreas Gohr } 48981e70caSAndreas Gohr $html .= '<li class="' . $tab . $class . '"><a href="' . $url . '">' . 49981e70caSAndreas Gohr $this->getLang('tab_' . $tab) . '</a></li>'; 50981e70caSAndreas Gohr } 51981e70caSAndreas Gohr $html .= '</ul>'; 52981e70caSAndreas Gohr return $html; 53981e70caSAndreas Gohr } 54981e70caSAndreas Gohr 55176901c2SAndreas Gohr /** 56176901c2SAndreas Gohr * Return the HTML for the list of installed plugins 57176901c2SAndreas Gohr * 58176901c2SAndreas Gohr * @return string 59176901c2SAndreas Gohr */ 60981e70caSAndreas Gohr public function tabPlugins() 61981e70caSAndreas Gohr { 62981e70caSAndreas Gohr $html = '<div class="panelHeader">'; 63981e70caSAndreas Gohr $html .= $this->helper->locale_xhtml('intro_plugins'); 64981e70caSAndreas Gohr $html .= '</div>'; 65981e70caSAndreas Gohr 6679ff0cd0SAndreas Gohr $plugins = (new Local())->getPlugins(); 67981e70caSAndreas Gohr 68981e70caSAndreas Gohr $html .= '<div id="extension__list">'; 6980bc92fbSAndreas Gohr $html .= '<form action="' . $this->tabURL('plugins') . '" method="post">'; 7080bc92fbSAndreas Gohr $html .= '<input type="hidden" name="overwrite" value="1">'; 7180bc92fbSAndreas Gohr $html .= formSecurityToken(false); 72176901c2SAndreas Gohr foreach ($plugins as $ext) { 73981e70caSAndreas Gohr $gui = new GuiExtension($ext); 74981e70caSAndreas Gohr $html .= $gui->render(); 75981e70caSAndreas Gohr } 7680bc92fbSAndreas Gohr $html .= '</form>'; 77981e70caSAndreas Gohr $html .= '</div>'; 78981e70caSAndreas Gohr 79981e70caSAndreas Gohr return $html; 80981e70caSAndreas Gohr } 81176901c2SAndreas Gohr 82176901c2SAndreas Gohr /** 83176901c2SAndreas Gohr * Return the HTML for the list of installed templates 84176901c2SAndreas Gohr * 85176901c2SAndreas Gohr * @return string 86176901c2SAndreas Gohr */ 87*652715ccSAndreas Gohr public function tabTemplates() 88*652715ccSAndreas Gohr { 89176901c2SAndreas Gohr $html = '<div class="panelHeader">'; 90176901c2SAndreas Gohr $html .= $this->helper->locale_xhtml('intro_templates'); 91176901c2SAndreas Gohr $html .= '</div>'; 92176901c2SAndreas Gohr 93176901c2SAndreas Gohr $templates = (new Local())->getTemplates(); 94176901c2SAndreas Gohr 95176901c2SAndreas Gohr $html .= '<div id="extension__list">'; 96176901c2SAndreas Gohr $html .= '<form action="' . $this->tabURL('templates') . '" method="post">'; 97176901c2SAndreas Gohr $html .= '<input type="hidden" name="overwrite" value="1">'; 98176901c2SAndreas Gohr $html .= formSecurityToken(false); 99176901c2SAndreas Gohr foreach ($templates as $ext) { 100176901c2SAndreas Gohr $gui = new GuiExtension($ext); 101176901c2SAndreas Gohr $html .= $gui->render(); 102176901c2SAndreas Gohr } 103176901c2SAndreas Gohr $html .= '</form>'; 104176901c2SAndreas Gohr $html .= '</div>'; 105176901c2SAndreas Gohr 106176901c2SAndreas Gohr return $html; 107176901c2SAndreas Gohr } 108176901c2SAndreas Gohr 109*652715ccSAndreas Gohr /** 110*652715ccSAndreas Gohr * Return the HTML for the search tab 111*652715ccSAndreas Gohr * 112*652715ccSAndreas Gohr * @return string 113*652715ccSAndreas Gohr */ 114*652715ccSAndreas Gohr public function tabSearch() 115*652715ccSAndreas Gohr { 116*652715ccSAndreas Gohr global $INPUT; 117*652715ccSAndreas Gohr 118*652715ccSAndreas Gohr $html = '<div class="panelHeader">'; 119*652715ccSAndreas Gohr $html .= $this->helper->locale_xhtml('intro_search'); 120*652715ccSAndreas Gohr $html .= '</div>'; 121*652715ccSAndreas Gohr 122*652715ccSAndreas Gohr $form = new Form([ 123*652715ccSAndreas Gohr 'action' => $this->tabURL('search'), 124*652715ccSAndreas Gohr 'class' => 'search', 125*652715ccSAndreas Gohr ]); 126*652715ccSAndreas Gohr $form->addTagOpen('div')->addClass('no'); 127*652715ccSAndreas Gohr $form->addTextInput('q', $this->getLang('search_for')) 128*652715ccSAndreas Gohr ->addClass('edit') 129*652715ccSAndreas Gohr ->val($INPUT->str('q')); 130*652715ccSAndreas Gohr $form->addButton('submit', $this->getLang('search')) 131*652715ccSAndreas Gohr ->attrs(['type' => 'submit', 'title' => $this->getLang('search')]); 132*652715ccSAndreas Gohr $form->addTagClose('div'); 133*652715ccSAndreas Gohr $html .= $form->toHTML(); 134*652715ccSAndreas Gohr 135*652715ccSAndreas Gohr if ($INPUT->str('q')) $html .= $this->SearchResults($INPUT->str('q')); 136*652715ccSAndreas Gohr 137*652715ccSAndreas Gohr return $html; 138*652715ccSAndreas Gohr } 139*652715ccSAndreas Gohr 140*652715ccSAndreas Gohr /** 141*652715ccSAndreas Gohr * Return the HTML for the install tab 142*652715ccSAndreas Gohr * 143*652715ccSAndreas Gohr * @return string 144*652715ccSAndreas Gohr */ 145*652715ccSAndreas Gohr public function tabInstall() 146*652715ccSAndreas Gohr { 147*652715ccSAndreas Gohr global $lang; 148*652715ccSAndreas Gohr 149*652715ccSAndreas Gohr $html = '<div class="panelHeader">'; 150*652715ccSAndreas Gohr $html .= $this->helper->locale_xhtml('intro_install'); 151*652715ccSAndreas Gohr $html .= '</div>'; 152*652715ccSAndreas Gohr 153*652715ccSAndreas Gohr $form = new Form([ 154*652715ccSAndreas Gohr 'action' => $this->tabURL('install'), 155*652715ccSAndreas Gohr 'enctype' => 'multipart/form-data', 156*652715ccSAndreas Gohr 'class' => 'install', 157*652715ccSAndreas Gohr ]); 158*652715ccSAndreas Gohr $form->addTagOpen('div')->addClass('no'); 159*652715ccSAndreas Gohr $form->addTextInput('installurl', $this->getLang('install_url')) 160*652715ccSAndreas Gohr ->addClass('block') 161*652715ccSAndreas Gohr ->attrs(['type' => 'url']); 162*652715ccSAndreas Gohr $form->addTag('br'); 163*652715ccSAndreas Gohr $form->addTextInput('installfile', $this->getLang('install_upload')) 164*652715ccSAndreas Gohr ->addClass('block') 165*652715ccSAndreas Gohr ->attrs(['type' => 'file']); 166*652715ccSAndreas Gohr $form->addTag('br'); 167*652715ccSAndreas Gohr $form->addCheckbox('overwrite', $lang['js']['media_overwrt']) 168*652715ccSAndreas Gohr ->addClass('block'); 169*652715ccSAndreas Gohr $form->addTag('br'); 170*652715ccSAndreas Gohr $form->addButton('', $this->getLang('btn_install')) 171*652715ccSAndreas Gohr ->attrs(['type' => 'submit', 'title' => $this->getLang('btn_install')]); 172*652715ccSAndreas Gohr $form->addTagClose('div'); 173*652715ccSAndreas Gohr $html .= $form->toHTML(); 174*652715ccSAndreas Gohr 175*652715ccSAndreas Gohr return $html; 176*652715ccSAndreas Gohr } 177*652715ccSAndreas Gohr 178*652715ccSAndreas Gohr /** 179*652715ccSAndreas Gohr * Execute the given search query and return the results 180*652715ccSAndreas Gohr * 181*652715ccSAndreas Gohr * @param string $q the query 182*652715ccSAndreas Gohr * @return string 183*652715ccSAndreas Gohr */ 184*652715ccSAndreas Gohr protected function SearchResults($q) 185*652715ccSAndreas Gohr { 186*652715ccSAndreas Gohr $repo = Repository::getInstance(); 187*652715ccSAndreas Gohr 188*652715ccSAndreas Gohr $html = '<div id="extension__list">'; 189*652715ccSAndreas Gohr $html .= '<form action="' . $this->tabURL('search') . '" method="post">'; 190*652715ccSAndreas Gohr 191*652715ccSAndreas Gohr try { 192*652715ccSAndreas Gohr $extensions = $repo->searchExtensions($q); 193*652715ccSAndreas Gohr $html .= '<div id="extension__results">'; 194*652715ccSAndreas Gohr foreach ($extensions as $ext) { 195*652715ccSAndreas Gohr $gui = new GuiExtension($ext); 196*652715ccSAndreas Gohr $html .= $gui->render(); 197*652715ccSAndreas Gohr } 198*652715ccSAndreas Gohr $html .= '</div>'; 199*652715ccSAndreas Gohr } catch (Exception $e) { 200*652715ccSAndreas Gohr msg($e->getMessage(), -1); 201*652715ccSAndreas Gohr } 202*652715ccSAndreas Gohr 203*652715ccSAndreas Gohr $html .= '</form>'; 204*652715ccSAndreas Gohr $html .= '</div>'; 205*652715ccSAndreas Gohr 206*652715ccSAndreas Gohr return $html; 207*652715ccSAndreas Gohr } 208981e70caSAndreas Gohr} 209