1<?php 2 3namespace dokuwiki\plugin\extension; 4 5use dokuwiki\Form\Form; 6 7class GuiAdmin extends Gui 8{ 9 public function render() 10 { 11 $html = '<div id="extension__manager">'; 12 13 $html .= $this->tabNavigation(); 14 15 match ($this->currentTab()) { 16 'search' => $html .= $this->tabSearch(), 17 'templates' => $html .= $this->tabTemplates(), 18 'install' => $html .= $this->tabInstall(), 19 default => $html .= $this->tabPlugins(), 20 }; 21 22 $html .= '</div>'; 23 return $html; 24 } 25 26 /** 27 * Print the tab navigation 28 * 29 */ 30 public function tabNavigation() 31 { 32 $html = '<ul class="tabs">'; 33 foreach ($this->tabs as $tab) { 34 $url = $this->tabURL($tab); 35 if ($this->currentTab() == $tab) { 36 $class = ' active'; 37 } else { 38 $class = ''; 39 } 40 $html .= '<li class="' . $tab . $class . '"><a href="' . $url . '">' . 41 $this->getLang('tab_' . $tab) . '</a></li>'; 42 } 43 $html .= '</ul>'; 44 return $html; 45 } 46 47 /** 48 * Return the HTML for the list of installed plugins 49 * 50 * @return string 51 */ 52 public function tabPlugins() 53 { 54 $html = '<div class="panelHeader">'; 55 $html .= $this->helper->locale_xhtml('intro_plugins'); 56 $html .= '</div>'; 57 58 $plugins = (new Local())->getPlugins(); 59 try { 60 // initialize remote data in one go 61 Repository::getInstance()->initExtensions(array_keys($plugins)); 62 } catch (Exception $e) { 63 msg($e->getMessage(), -1); // this should not happen 64 } 65 66 $html .= '<div id="extension__list">'; 67 $html .= '<form action="' . $this->tabURL('plugins') . '" method="post">'; 68 $html .= '<input type="hidden" name="overwrite" value="1">'; 69 $html .= formSecurityToken(false); 70 foreach ($plugins as $ext) { 71 $gui = new GuiExtension($ext); 72 $html .= $gui->render(); 73 } 74 $html .= '</form>'; 75 $html .= '</div>'; 76 77 return $html; 78 } 79 80 /** 81 * Return the HTML for the list of installed templates 82 * 83 * @return string 84 */ 85 public function tabTemplates() 86 { 87 $html = '<div class="panelHeader">'; 88 $html .= $this->helper->locale_xhtml('intro_templates'); 89 $html .= '</div>'; 90 91 $templates = (new Local())->getTemplates(); 92 try { 93 // initialize remote data in one go 94 Repository::getInstance()->initExtensions(array_keys($templates)); 95 } catch (Exception $e) { 96 msg($e->getMessage(), -1); // this should not happen 97 } 98 99 $html .= '<div id="extension__list">'; 100 $html .= '<form action="' . $this->tabURL('templates') . '" method="post">'; 101 $html .= '<input type="hidden" name="overwrite" value="1">'; 102 $html .= formSecurityToken(false); 103 foreach ($templates as $ext) { 104 $gui = new GuiExtension($ext); 105 $html .= $gui->render(); 106 } 107 $html .= '</form>'; 108 $html .= '</div>'; 109 110 return $html; 111 } 112 113 /** 114 * Return the HTML for the search tab 115 * 116 * @return string 117 */ 118 public function tabSearch() 119 { 120 global $INPUT; 121 122 $html = '<div class="panelHeader">'; 123 $html .= $this->helper->locale_xhtml('intro_search'); 124 $html .= '</div>'; 125 126 $form = new Form([ 127 'action' => $this->tabURL('search'), 128 'class' => 'search', 129 ]); 130 $form->addTagOpen('div')->addClass('no'); 131 $form->addTextInput('q', $this->getLang('search_for')) 132 ->addClass('edit') 133 ->val($INPUT->str('q')); 134 $form->addButton('submit', $this->getLang('search')) 135 ->attrs(['type' => 'submit', 'title' => $this->getLang('search')]); 136 $form->addTagClose('div'); 137 $html .= $form->toHTML(); 138 139 if ($INPUT->str('q')) $html .= $this->searchResults($INPUT->str('q')); 140 141 return $html; 142 } 143 144 /** 145 * Return the HTML for the install tab 146 * 147 * @return string 148 */ 149 public function tabInstall() 150 { 151 global $lang; 152 153 $html = '<div class="panelHeader">'; 154 $html .= $this->helper->locale_xhtml('intro_install'); 155 $html .= '</div>'; 156 157 $form = new Form([ 158 'action' => $this->tabURL('install'), 159 'enctype' => 'multipart/form-data', 160 'class' => 'install', 161 ]); 162 $form->addTagOpen('div')->addClass('no'); 163 $form->addTextInput('installurl', $this->getLang('install_url')) 164 ->addClass('block') 165 ->attrs(['type' => 'url']); 166 $form->addTag('br'); 167 $form->addTextInput('installfile', $this->getLang('install_upload')) 168 ->addClass('block') 169 ->attrs(['type' => 'file']); 170 $form->addTag('br'); 171 $form->addCheckbox('overwrite', $lang['js']['media_overwrt']) 172 ->addClass('block'); 173 $form->addTag('br'); 174 $form->addButton('', $this->getLang('btn_install')) 175 ->attrs(['type' => 'submit', 'title' => $this->getLang('btn_install')]); 176 $form->addTagClose('div'); 177 $html .= $form->toHTML(); 178 179 return $html; 180 } 181 182 /** 183 * Execute the given search query and return the results 184 * 185 * @param string $q the query 186 * @return string 187 */ 188 protected function searchResults($q) 189 { 190 $repo = Repository::getInstance(); 191 192 $html = '<div id="extension__list">'; 193 $html .= '<form action="' . $this->tabURL('search') . '" method="post">'; 194 $html .= formSecurityToken(false); 195 196 try { 197 $extensions = $repo->searchExtensions($q); 198 $html .= '<div id="extension__results">'; 199 foreach ($extensions as $ext) { 200 $gui = new GuiExtension($ext); 201 $html .= $gui->render(); 202 } 203 $html .= '</div>'; 204 } catch (Exception $e) { 205 msg($e->getMessage(), -1); 206 } 207 208 $html .= '</form>'; 209 $html .= '</div>'; 210 211 return $html; 212 } 213} 214