1981e70caSAndreas Gohr<?php 2981e70caSAndreas Gohr 3981e70caSAndreas Gohrnamespace dokuwiki\plugin\extension; 4981e70caSAndreas Gohr 5652715ccSAndreas Gohruse dokuwiki\Form\Form; 6652715ccSAndreas 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 */ 87652715ccSAndreas Gohr public function tabTemplates() 88652715ccSAndreas 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 109652715ccSAndreas Gohr /** 110652715ccSAndreas Gohr * Return the HTML for the search tab 111652715ccSAndreas Gohr * 112652715ccSAndreas Gohr * @return string 113652715ccSAndreas Gohr */ 114652715ccSAndreas Gohr public function tabSearch() 115652715ccSAndreas Gohr { 116652715ccSAndreas Gohr global $INPUT; 117652715ccSAndreas Gohr 118652715ccSAndreas Gohr $html = '<div class="panelHeader">'; 119652715ccSAndreas Gohr $html .= $this->helper->locale_xhtml('intro_search'); 120652715ccSAndreas Gohr $html .= '</div>'; 121652715ccSAndreas Gohr 122652715ccSAndreas Gohr $form = new Form([ 123652715ccSAndreas Gohr 'action' => $this->tabURL('search'), 124652715ccSAndreas Gohr 'class' => 'search', 125652715ccSAndreas Gohr ]); 126652715ccSAndreas Gohr $form->addTagOpen('div')->addClass('no'); 127652715ccSAndreas Gohr $form->addTextInput('q', $this->getLang('search_for')) 128652715ccSAndreas Gohr ->addClass('edit') 129652715ccSAndreas Gohr ->val($INPUT->str('q')); 130652715ccSAndreas Gohr $form->addButton('submit', $this->getLang('search')) 131652715ccSAndreas Gohr ->attrs(['type' => 'submit', 'title' => $this->getLang('search')]); 132652715ccSAndreas Gohr $form->addTagClose('div'); 133652715ccSAndreas Gohr $html .= $form->toHTML(); 134652715ccSAndreas Gohr 135*7c184cfcSAndreas Gohr if ($INPUT->str('q')) $html .= $this->searchResults($INPUT->str('q')); 136652715ccSAndreas Gohr 137652715ccSAndreas Gohr return $html; 138652715ccSAndreas Gohr } 139652715ccSAndreas Gohr 140652715ccSAndreas Gohr /** 141652715ccSAndreas Gohr * Return the HTML for the install tab 142652715ccSAndreas Gohr * 143652715ccSAndreas Gohr * @return string 144652715ccSAndreas Gohr */ 145652715ccSAndreas Gohr public function tabInstall() 146652715ccSAndreas Gohr { 147652715ccSAndreas Gohr global $lang; 148652715ccSAndreas Gohr 149652715ccSAndreas Gohr $html = '<div class="panelHeader">'; 150652715ccSAndreas Gohr $html .= $this->helper->locale_xhtml('intro_install'); 151652715ccSAndreas Gohr $html .= '</div>'; 152652715ccSAndreas Gohr 153652715ccSAndreas Gohr $form = new Form([ 154652715ccSAndreas Gohr 'action' => $this->tabURL('install'), 155652715ccSAndreas Gohr 'enctype' => 'multipart/form-data', 156652715ccSAndreas Gohr 'class' => 'install', 157652715ccSAndreas Gohr ]); 158652715ccSAndreas Gohr $form->addTagOpen('div')->addClass('no'); 159652715ccSAndreas Gohr $form->addTextInput('installurl', $this->getLang('install_url')) 160652715ccSAndreas Gohr ->addClass('block') 161652715ccSAndreas Gohr ->attrs(['type' => 'url']); 162652715ccSAndreas Gohr $form->addTag('br'); 163652715ccSAndreas Gohr $form->addTextInput('installfile', $this->getLang('install_upload')) 164652715ccSAndreas Gohr ->addClass('block') 165652715ccSAndreas Gohr ->attrs(['type' => 'file']); 166652715ccSAndreas Gohr $form->addTag('br'); 167652715ccSAndreas Gohr $form->addCheckbox('overwrite', $lang['js']['media_overwrt']) 168652715ccSAndreas Gohr ->addClass('block'); 169652715ccSAndreas Gohr $form->addTag('br'); 170652715ccSAndreas Gohr $form->addButton('', $this->getLang('btn_install')) 171652715ccSAndreas Gohr ->attrs(['type' => 'submit', 'title' => $this->getLang('btn_install')]); 172652715ccSAndreas Gohr $form->addTagClose('div'); 173652715ccSAndreas Gohr $html .= $form->toHTML(); 174652715ccSAndreas Gohr 175652715ccSAndreas Gohr return $html; 176652715ccSAndreas Gohr } 177652715ccSAndreas Gohr 178652715ccSAndreas Gohr /** 179652715ccSAndreas Gohr * Execute the given search query and return the results 180652715ccSAndreas Gohr * 181652715ccSAndreas Gohr * @param string $q the query 182652715ccSAndreas Gohr * @return string 183652715ccSAndreas Gohr */ 184*7c184cfcSAndreas Gohr protected function searchResults($q) 185652715ccSAndreas Gohr { 186652715ccSAndreas Gohr $repo = Repository::getInstance(); 187652715ccSAndreas Gohr 188652715ccSAndreas Gohr $html = '<div id="extension__list">'; 189652715ccSAndreas Gohr $html .= '<form action="' . $this->tabURL('search') . '" method="post">'; 190652715ccSAndreas Gohr 191652715ccSAndreas Gohr try { 192652715ccSAndreas Gohr $extensions = $repo->searchExtensions($q); 193652715ccSAndreas Gohr $html .= '<div id="extension__results">'; 194652715ccSAndreas Gohr foreach ($extensions as $ext) { 195652715ccSAndreas Gohr $gui = new GuiExtension($ext); 196652715ccSAndreas Gohr $html .= $gui->render(); 197652715ccSAndreas Gohr } 198652715ccSAndreas Gohr $html .= '</div>'; 199652715ccSAndreas Gohr } catch (Exception $e) { 200652715ccSAndreas Gohr msg($e->getMessage(), -1); 201652715ccSAndreas Gohr } 202652715ccSAndreas Gohr 203652715ccSAndreas Gohr $html .= '</form>'; 204652715ccSAndreas Gohr $html .= '</div>'; 205652715ccSAndreas Gohr 206652715ccSAndreas Gohr return $html; 207652715ccSAndreas Gohr } 208981e70caSAndreas Gohr} 209