| 1 | <?php |
|---|
| 2 | # ***** BEGIN LICENSE BLOCK ***** |
|---|
| 3 | # This file is part of daInstaller, a plugin for DotClear2. |
|---|
| 4 | # Copyright (c) 2008-2011 Tomtom, Pep and contributors, for DotAddict.org. |
|---|
| 5 | # All rights reserved. |
|---|
| 6 | # |
|---|
| 7 | # ***** END LICENSE BLOCK ***** |
|---|
| 8 | |
|---|
| 9 | /** |
|---|
| 10 | * Class daModulesList |
|---|
| 11 | */ |
|---|
| 12 | class daModulesList extends adminGenericList |
|---|
| 13 | { |
|---|
| 14 | /** |
|---|
| 15 | * Display data table for plugins and themes lists |
|---|
| 16 | * |
|---|
| 17 | * @param int page |
|---|
| 18 | * @param int nb_per_page |
|---|
| 19 | * @param string type |
|---|
| 20 | * @param string url |
|---|
| 21 | */ |
|---|
| 22 | public function display($page,$nb_per_page,$type,$url) |
|---|
| 23 | { |
|---|
| 24 | $search = false; |
|---|
| 25 | if (strpos($type,'search-') === 0) { |
|---|
| 26 | $search = true; |
|---|
| 27 | $type = str_replace('search-','',$type); |
|---|
| 28 | } |
|---|
| 29 | $type = ($type == 'themes') ? 'themes' : 'plugins'; |
|---|
| 30 | if ($type == 'themes') { |
|---|
| 31 | $msg_no_entry = __('No theme'); |
|---|
| 32 | $msg_th_label = __('Themes'); |
|---|
| 33 | $lineMethod = 'themeLine'; |
|---|
| 34 | } |
|---|
| 35 | else { |
|---|
| 36 | $msg_no_entry = __('No plugins'); |
|---|
| 37 | $msg_th_label = __('Plugins'); |
|---|
| 38 | $lineMethod = 'pluginLine'; |
|---|
| 39 | } |
|---|
| 40 | |
|---|
| 41 | if ($this->rs->isEmpty()) { |
|---|
| 42 | echo '<p><strong>'.$msg_no_entry.'</strong></p>'; |
|---|
| 43 | } |
|---|
| 44 | else { |
|---|
| 45 | $pager = new pager($page,$this->rs_count,$nb_per_page,10); |
|---|
| 46 | if (!$search) { |
|---|
| 47 | $pager->base_url = $url.'&tab='.$type.'&page=%s'; |
|---|
| 48 | } |
|---|
| 49 | else { |
|---|
| 50 | $pager->var_pager = 'page'; |
|---|
| 51 | } |
|---|
| 52 | |
|---|
| 53 | $html_block = |
|---|
| 54 | '<div class="table-outer">'. |
|---|
| 55 | '<table caption="modules" class="maximal">'. |
|---|
| 56 | '<thead>'. |
|---|
| 57 | '<tr>'. |
|---|
| 58 | '<th>'.$msg_th_label.'</th>'. |
|---|
| 59 | '<th class="nowrap">'.__('Lastest Version').'</th>'. |
|---|
| 60 | '<th>'.__('Quick description').'</th>'. |
|---|
| 61 | '<th>'.__('Actions').'</th>'. |
|---|
| 62 | '</tr>'. |
|---|
| 63 | '</thead>'. |
|---|
| 64 | '<tbody>%s</tbody>'. |
|---|
| 65 | '</table></div>'; |
|---|
| 66 | |
|---|
| 67 | echo '<p class="pagination">'.__('Page(s)').' : '.$pager->getLinks().'</p>'; |
|---|
| 68 | $blocks = explode('%s',$html_block); |
|---|
| 69 | echo $blocks[0]; |
|---|
| 70 | |
|---|
| 71 | $this->rs->index(((integer)$page - 1) * $nb_per_page); |
|---|
| 72 | $iter = 0; |
|---|
| 73 | while ($iter < $nb_per_page) { |
|---|
| 74 | echo $this->{$lineMethod}($url); |
|---|
| 75 | if ($this->rs->isEnd()) { |
|---|
| 76 | break; |
|---|
| 77 | } |
|---|
| 78 | else { |
|---|
| 79 | $this->rs->moveNext(); |
|---|
| 80 | $iter++; |
|---|
| 81 | } |
|---|
| 82 | } |
|---|
| 83 | echo $blocks[1]; |
|---|
| 84 | echo '<p class="pagination">'.__('Page(s)').' : '.$pager->getLinks().'</p>'; |
|---|
| 85 | } |
|---|
| 86 | } |
|---|
| 87 | |
|---|
| 88 | /** |
|---|
| 89 | * Return a generic plugin row |
|---|
| 90 | * |
|---|
| 91 | * @param string url |
|---|
| 92 | * |
|---|
| 93 | * @return string |
|---|
| 94 | */ |
|---|
| 95 | private function pluginLine($url) |
|---|
| 96 | { |
|---|
| 97 | return |
|---|
| 98 | '<tr class="line wide" id="ext_'.$this->rs->id.'">'."\n". |
|---|
| 99 | # Extension |
|---|
| 100 | '<td class="minimal nowrap">'. |
|---|
| 101 | '<strong>'.html::escapeHTML($this->rs->id).'</strong>'. |
|---|
| 102 | "</td>\n". |
|---|
| 103 | # Version |
|---|
| 104 | '<td class="minimal nowrap">'. |
|---|
| 105 | html::escapeHTML($this->rs->version). |
|---|
| 106 | "</td>\n". |
|---|
| 107 | # Quick description |
|---|
| 108 | '<td>'. |
|---|
| 109 | '<p><strong>'.html::escapeHTML($this->rs->label).'</strong><br />'. |
|---|
| 110 | '<em>'.html::escapeHTML($this->rs->desc).'</em></p>'. |
|---|
| 111 | __('by').' '.html::escapeHTML($this->rs->author).'<br />'. |
|---|
| 112 | '( <a href="'.$this->rs->details.'" class="learnmore modal">'.__('More details').'</a> )'. |
|---|
| 113 | "</td>\n". |
|---|
| 114 | # Action |
|---|
| 115 | '<td class="minimal">'. |
|---|
| 116 | '<form action="'.$url.'" method="post">'. |
|---|
| 117 | '<p><input name="package_url" value="'.$this->rs->file.'" type="hidden" />'. |
|---|
| 118 | $this->core->formNonce(). |
|---|
| 119 | '<input class="install" name="add_plugin" value="'. |
|---|
| 120 | __('Install').'" type="submit" /></p>'. |
|---|
| 121 | '</form>'. |
|---|
| 122 | "</td>\n". |
|---|
| 123 | '</tr>'."\n"; |
|---|
| 124 | } |
|---|
| 125 | |
|---|
| 126 | /** |
|---|
| 127 | * Return a generic theme row |
|---|
| 128 | * |
|---|
| 129 | * @param string url |
|---|
| 130 | * |
|---|
| 131 | * @return string |
|---|
| 132 | */ |
|---|
| 133 | private function themeLine($url) |
|---|
| 134 | { |
|---|
| 135 | return |
|---|
| 136 | '<tr class="line wide" id="ext_'.$this->rs->id.'">'."\n". |
|---|
| 137 | # Extension |
|---|
| 138 | '<td class="minimal nowrap">'. |
|---|
| 139 | '<strong>'.html::escapeHTML($this->rs->id).'</strong>'. |
|---|
| 140 | '<p class="sshot"><img src="'.html::escapeHTML($this->rs->sshot).'" alt="" /></p>'. |
|---|
| 141 | "</td>\n". |
|---|
| 142 | # Version |
|---|
| 143 | '<td class="minimal nowrap">'. |
|---|
| 144 | html::escapeHTML($this->rs->version). |
|---|
| 145 | "</td>\n". |
|---|
| 146 | # Quick description |
|---|
| 147 | '<td>'. |
|---|
| 148 | '<p><strong>'.html::escapeHTML($this->rs->label).'</strong><br />'. |
|---|
| 149 | '<em>'.html::escapeHTML($this->rs->desc).'</em></p>'. |
|---|
| 150 | __('by').' '.html::escapeHTML($this->rs->author).'<br />'. |
|---|
| 151 | '( <a href="'.$this->rs->details.'" class="learnmore modal">'.__('More details').'</a> )'. |
|---|
| 152 | "</td>\n". |
|---|
| 153 | # Action |
|---|
| 154 | '<td class="minimal">'. |
|---|
| 155 | '<form action="'.$url.'" method="post">'. |
|---|
| 156 | '<p><input name="package_url" value="'.$this->rs->file.'" type="hidden" />'. |
|---|
| 157 | $this->core->formNonce(). |
|---|
| 158 | '<input class="install" name="add_theme" value="'. |
|---|
| 159 | __('Install').'" type="submit" /></p>'. |
|---|
| 160 | '</form>'. |
|---|
| 161 | "</td>\n". |
|---|
| 162 | '</tr>'."\n"; |
|---|
| 163 | } |
|---|
| 164 | } |
|---|
| 165 | |
|---|
| 166 | /** |
|---|
| 167 | * Class daModulesUpdateList |
|---|
| 168 | */ |
|---|
| 169 | class daModulesUpdateList |
|---|
| 170 | { |
|---|
| 171 | protected $rs; |
|---|
| 172 | protected $nb; |
|---|
| 173 | |
|---|
| 174 | /** |
|---|
| 175 | * Class constructor |
|---|
| 176 | */ |
|---|
| 177 | public function __construct($core,$rs,$nb) |
|---|
| 178 | { |
|---|
| 179 | $this->core = $core; |
|---|
| 180 | $this->rs = $rs; |
|---|
| 181 | $this->nb = $nb; |
|---|
| 182 | $this->p_link = '<a href="%s" class="%s">%s</a>'; |
|---|
| 183 | } |
|---|
| 184 | |
|---|
| 185 | /** |
|---|
| 186 | * Display data table for plugins and themes update lists |
|---|
| 187 | * |
|---|
| 188 | * @param string type |
|---|
| 189 | * @param string url |
|---|
| 190 | * |
|---|
| 191 | * @return string |
|---|
| 192 | */ |
|---|
| 193 | public function display($type,$url) |
|---|
| 194 | { |
|---|
| 195 | $type = ($type == 'themes') ? 'themes' : 'plugins'; |
|---|
| 196 | if ($type == 'themes') { |
|---|
| 197 | $msg_th_label = __('Theme'); |
|---|
| 198 | $lineMethod = 'themeLine'; |
|---|
| 199 | } |
|---|
| 200 | else { |
|---|
| 201 | $msg_th_label = __('Plugins'); |
|---|
| 202 | $lineMethod = 'pluginLine'; |
|---|
| 203 | } |
|---|
| 204 | |
|---|
| 205 | $iter = 0; |
|---|
| 206 | $items = ''; |
|---|
| 207 | $html_block = |
|---|
| 208 | '<form action="'.$url.'" method="post">'. |
|---|
| 209 | '<div class="table-outer">'. |
|---|
| 210 | '<table caption="upd-%1$s" class="maximal">'. |
|---|
| 211 | '<thead>'. |
|---|
| 212 | '<tr>'. |
|---|
| 213 | '<th>'.$msg_th_label.'</th>'. |
|---|
| 214 | '<th class="nowrap">'.__('Lastest Version').'</th>'. |
|---|
| 215 | '<th>'.__('Quick description').'</th>'. |
|---|
| 216 | '</tr>'. |
|---|
| 217 | '</thead>'. |
|---|
| 218 | '<tbody>%2$s</tbody>'. |
|---|
| 219 | '</table></div>'. |
|---|
| 220 | '<div class="two-cols">'. |
|---|
| 221 | '<p class="col checkboxes-helpers"></p>'. |
|---|
| 222 | '<p class="col right">'. |
|---|
| 223 | $this->core->formNonce(). |
|---|
| 224 | '<input type="submit" value="'.__('Update selected modules').'" name="upd_'.$type.'" /></p>'. |
|---|
| 225 | '</div>'. |
|---|
| 226 | '</form>'; |
|---|
| 227 | |
|---|
| 228 | while ($iter < $this->rs->count()) { |
|---|
| 229 | $items .= $this->{$lineMethod}($url); |
|---|
| 230 | $this->rs->moveNext(); |
|---|
| 231 | $iter++; |
|---|
| 232 | } |
|---|
| 233 | |
|---|
| 234 | echo $this->nb > 0 ? sprintf($html_block,$type,$items) : ''; |
|---|
| 235 | |
|---|
| 236 | } |
|---|
| 237 | |
|---|
| 238 | /** |
|---|
| 239 | * Return a update plugin row |
|---|
| 240 | * |
|---|
| 241 | * @param string url |
|---|
| 242 | * |
|---|
| 243 | * @return string |
|---|
| 244 | */ |
|---|
| 245 | private function pluginLine($url) |
|---|
| 246 | { |
|---|
| 247 | $support = |
|---|
| 248 | strlen($this->rs->support) > 0 ? |
|---|
| 249 | sprintf($this->p_link,$this->rs->support,'support modal',__('Support')) : |
|---|
| 250 | '<span class="support">'.__('No support available').'</span>'; |
|---|
| 251 | |
|---|
| 252 | return |
|---|
| 253 | '<tr class="line wide" id="ext_'.$this->rs->id.'">'."\n". |
|---|
| 254 | # Extension |
|---|
| 255 | '<td class="minimal nowrap">'. |
|---|
| 256 | form::checkbox(array('plugins_id[]'),$this->rs->id). |
|---|
| 257 | '<strong>'.html::escapeHTML($this->rs->id).'</strong>'. |
|---|
| 258 | "</td>\n". |
|---|
| 259 | # Version |
|---|
| 260 | '<td class="minimal nowrap">'. |
|---|
| 261 | html::escapeHTML($this->rs->version). |
|---|
| 262 | "</td>\n". |
|---|
| 263 | # Quick description |
|---|
| 264 | '<td>'. |
|---|
| 265 | '<p><strong>'.html::escapeHTML($this->rs->label).'</strong><br />'. |
|---|
| 266 | '<em>'.html::escapeHTML($this->rs->desc).'</em></p>'. |
|---|
| 267 | __('by').' '.html::escapeHTML($this->rs->author).'<br />'. |
|---|
| 268 | '( <a href="'.$this->rs->details.'" class="learnmore modal">'. |
|---|
| 269 | __('More details').'</a> - '.$support.'</a> )'. |
|---|
| 270 | "</td>\n". |
|---|
| 271 | '</tr>'."\n"; |
|---|
| 272 | } |
|---|
| 273 | |
|---|
| 274 | /** |
|---|
| 275 | * Return a update theme row |
|---|
| 276 | * |
|---|
| 277 | * @param string url |
|---|
| 278 | * |
|---|
| 279 | * @return string |
|---|
| 280 | */ |
|---|
| 281 | private function themeLine($url) |
|---|
| 282 | { |
|---|
| 283 | $support = |
|---|
| 284 | strlen($this->rs->support) > 0 ? |
|---|
| 285 | sprintf($this->p_link,$this->rs->support,'support modal',__('Support')) : |
|---|
| 286 | '<span class="support">'.__('No support available').'</span>'; |
|---|
| 287 | |
|---|
| 288 | return |
|---|
| 289 | '<tr class="line wide" id="ext_'.$this->rs->id.'">'."\n". |
|---|
| 290 | # Themes |
|---|
| 291 | '<td class="minimal nowrap">'. |
|---|
| 292 | form::checkbox(array('themes_id[]'),$this->rs->id). |
|---|
| 293 | '<strong>'.html::escapeHTML($this->rs->id).'</strong>'. |
|---|
| 294 | '<p class="sshot"><img src="'.html::escapeHTML($this->rs->sshot).'" alt="" /></p>'. |
|---|
| 295 | "</td>\n". |
|---|
| 296 | # Version |
|---|
| 297 | '<td class="minimal nowrap">'. |
|---|
| 298 | html::escapeHTML($this->rs->version). |
|---|
| 299 | "</td>\n". |
|---|
| 300 | # Quick description |
|---|
| 301 | '<td>'. |
|---|
| 302 | '<p><strong>'.html::escapeHTML($this->rs->label).'</strong><br />'. |
|---|
| 303 | '<em>'.html::escapeHTML($this->rs->desc).'</em></p>'. |
|---|
| 304 | __('by').' '.html::escapeHTML($this->rs->author).'<br />'. |
|---|
| 305 | '( <a href="'.$this->rs->details.'" class="learnmore modal">'. |
|---|
| 306 | __('More details').'</a> - '.$support.'</a> )'. |
|---|
| 307 | "</td>\n". |
|---|
| 308 | '</tr>'."\n"; |
|---|
| 309 | } |
|---|
| 310 | } |
|---|
| 311 | |
|---|
| 312 | ?> |
|---|