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