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