1 | <?php |
---|
2 | # -- BEGIN LICENSE BLOCK --------------------------------------- |
---|
3 | # |
---|
4 | # This file is part of Dotclear 2. |
---|
5 | # |
---|
6 | # Copyright (c) 2003-2013 Olivier Meunier & Association Dotclear |
---|
7 | # Licensed under the GPL version 2.0 license. |
---|
8 | # See LICENSE file or |
---|
9 | # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
---|
10 | # |
---|
11 | # -- END LICENSE BLOCK ----------------------------------------- |
---|
12 | if (!defined('DC_RC_PATH')) { return; } |
---|
13 | |
---|
14 | class adminGenericList |
---|
15 | { |
---|
16 | protected $core; |
---|
17 | protected $rs; |
---|
18 | protected $rs_count; |
---|
19 | |
---|
20 | public function __construct($core,$rs,$rs_count) |
---|
21 | { |
---|
22 | $this->core =& $core; |
---|
23 | $this->rs =& $rs; |
---|
24 | $this->rs_count = $rs_count; |
---|
25 | $this->html_prev = __('« prev.'); |
---|
26 | $this->html_next = __('next »'); |
---|
27 | } |
---|
28 | } |
---|
29 | |
---|
30 | class adminPostList extends adminGenericList |
---|
31 | { |
---|
32 | public function display($page,$nb_per_page,$enclose_block='') |
---|
33 | { |
---|
34 | if ($this->rs->isEmpty()) |
---|
35 | { |
---|
36 | echo '<p><strong>'.__('No entry').'</strong></p>'; |
---|
37 | } |
---|
38 | else |
---|
39 | { |
---|
40 | $pager = new pager($page,$this->rs_count,$nb_per_page,10); |
---|
41 | $pager->html_prev = $this->html_prev; |
---|
42 | $pager->html_next = $this->html_next; |
---|
43 | $pager->var_page = 'page'; |
---|
44 | $entries = array(); |
---|
45 | if (isset($_REQUEST['entries'])) { |
---|
46 | foreach ($_REQUEST['entries'] as $v) { |
---|
47 | $entries[(integer)$v]=true; |
---|
48 | } |
---|
49 | } |
---|
50 | $html_block = |
---|
51 | '<table class="clear"><caption class="hidden">'.__('Entries list').'</caption><tr>'. |
---|
52 | '<th colspan="2" class="first">'.__('Title').'</th>'. |
---|
53 | '<th scope="col">'.__('Date').'</th>'. |
---|
54 | '<th scope="col">'.__('Category').'</th>'. |
---|
55 | '<th scope="col">'.__('Author').'</th>'. |
---|
56 | '<th scope="col">'.__('Comments').'</th>'. |
---|
57 | '<th scope="col">'.__('Trackbacks').'</th>'. |
---|
58 | '<th scope="col">'.__('Status').'</th>'. |
---|
59 | '</tr>%s</table>'; |
---|
60 | |
---|
61 | if ($enclose_block) { |
---|
62 | $html_block = sprintf($enclose_block,$html_block); |
---|
63 | } |
---|
64 | |
---|
65 | echo '<p class="pagination">'.__('Page(s)').' : '.$pager->getLinks().'</p>'; |
---|
66 | |
---|
67 | $blocks = explode('%s',$html_block); |
---|
68 | |
---|
69 | echo $blocks[0]; |
---|
70 | |
---|
71 | while ($this->rs->fetch()) |
---|
72 | { |
---|
73 | echo $this->postLine(isset($entries[$this->rs->post_id])); |
---|
74 | } |
---|
75 | |
---|
76 | echo $blocks[1]; |
---|
77 | |
---|
78 | echo '<p class="pagination">'.__('Page(s)').' : '.$pager->getLinks().'</p>'; |
---|
79 | } |
---|
80 | } |
---|
81 | |
---|
82 | private function postLine($checked) |
---|
83 | { |
---|
84 | if ($this->core->auth->check('categories',$this->core->blog->id)) { |
---|
85 | $cat_link = '<a href="category.php?id=%s">%s</a>'; |
---|
86 | } else { |
---|
87 | $cat_link = '%2$s'; |
---|
88 | } |
---|
89 | |
---|
90 | if ($this->rs->cat_title) { |
---|
91 | $cat_title = sprintf($cat_link,$this->rs->cat_id, |
---|
92 | html::escapeHTML($this->rs->cat_title)); |
---|
93 | } else { |
---|
94 | $cat_title = __('(No cat)'); |
---|
95 | } |
---|
96 | |
---|
97 | $img = '<img alt="%1$s" title="%1$s" src="images/%2$s" />'; |
---|
98 | switch ($this->rs->post_status) { |
---|
99 | case 1: |
---|
100 | $img_status = sprintf($img,__('Published'),'check-on.png'); |
---|
101 | break; |
---|
102 | case 0: |
---|
103 | $img_status = sprintf($img,__('Unpublished'),'check-off.png'); |
---|
104 | break; |
---|
105 | case -1: |
---|
106 | $img_status = sprintf($img,__('Scheduled'),'scheduled.png'); |
---|
107 | break; |
---|
108 | case -2: |
---|
109 | $img_status = sprintf($img,__('Pending'),'check-wrn.png'); |
---|
110 | break; |
---|
111 | } |
---|
112 | |
---|
113 | $protected = ''; |
---|
114 | if ($this->rs->post_password) { |
---|
115 | $protected = sprintf($img,__('Protected'),'locker.png'); |
---|
116 | } |
---|
117 | |
---|
118 | $selected = ''; |
---|
119 | if ($this->rs->post_selected) { |
---|
120 | $selected = sprintf($img,__('Selected'),'selected.png'); |
---|
121 | } |
---|
122 | |
---|
123 | $attach = ''; |
---|
124 | $nb_media = $this->rs->countMedia(); |
---|
125 | if ($nb_media > 0) { |
---|
126 | $attach_str = $nb_media == 1 ? __('%d attachment') : __('%d attachments'); |
---|
127 | $attach = sprintf($img,sprintf($attach_str,$nb_media),'attach.png'); |
---|
128 | } |
---|
129 | |
---|
130 | $res = '<tr class="line'.($this->rs->post_status != 1 ? ' offline' : '').'"'. |
---|
131 | ' id="p'.$this->rs->post_id.'">'; |
---|
132 | |
---|
133 | $res .= |
---|
134 | '<td class="nowrap">'. |
---|
135 | form::checkbox(array('entries[]'),$this->rs->post_id,$checked,'','',!$this->rs->isEditable()).'</td>'. |
---|
136 | '<td class="maximal" scope="row"><a href="'.$this->core->getPostAdminURL($this->rs->post_type,$this->rs->post_id).'">'. |
---|
137 | html::escapeHTML($this->rs->post_title).'</a></td>'. |
---|
138 | '<td class="nowrap count">'.dt::dt2str(__('%Y-%m-%d %H:%M'),$this->rs->post_dt).'</td>'. |
---|
139 | '<td class="nowrap">'.$cat_title.'</td>'. |
---|
140 | '<td class="nowrap">'.html::escapeHTML($this->rs->user_id).'</td>'. |
---|
141 | '<td class="nowrap count">'.$this->rs->nb_comment.'</td>'. |
---|
142 | '<td class="nowrap count">'.$this->rs->nb_trackback.'</td>'. |
---|
143 | '<td class="nowrap status">'.$img_status.' '.$selected.' '.$protected.' '.$attach.'</td>'. |
---|
144 | '</tr>'; |
---|
145 | |
---|
146 | return $res; |
---|
147 | } |
---|
148 | } |
---|
149 | |
---|
150 | class adminPostMiniList extends adminGenericList |
---|
151 | { |
---|
152 | public function display($page,$nb_per_page,$enclose_block='') |
---|
153 | { |
---|
154 | if ($this->rs->isEmpty()) |
---|
155 | { |
---|
156 | echo '<p><strong>'.__('No entry').'</strong></p>'; |
---|
157 | } |
---|
158 | else |
---|
159 | { |
---|
160 | $pager = new pager($page,$this->rs_count,$nb_per_page,10); |
---|
161 | $pager->html_prev = $this->html_prev; |
---|
162 | $pager->html_next = $this->html_next; |
---|
163 | $pager->var_page = 'page'; |
---|
164 | |
---|
165 | $html_block = |
---|
166 | '<table class="clear"><caption class="hidden">'.__('Entries list').'</caption><tr>'. |
---|
167 | '<th scope="col">'.__('Title').'</th>'. |
---|
168 | '<th scope="col">'.__('Date').'</th>'. |
---|
169 | '<th scope="col">'.__('Author').'</th>'. |
---|
170 | '<th scope="col">'.__('Status').'</th>'. |
---|
171 | '</tr>%s</table>'; |
---|
172 | |
---|
173 | if ($enclose_block) { |
---|
174 | $html_block = sprintf($enclose_block,$html_block); |
---|
175 | } |
---|
176 | |
---|
177 | echo '<p class="pagination">'.__('Page(s)').' : '.$pager->getLinks().'</p>'; |
---|
178 | |
---|
179 | $blocks = explode('%s',$html_block); |
---|
180 | |
---|
181 | echo $blocks[0]; |
---|
182 | |
---|
183 | while ($this->rs->fetch()) |
---|
184 | { |
---|
185 | echo $this->postLine(); |
---|
186 | } |
---|
187 | |
---|
188 | echo $blocks[1]; |
---|
189 | |
---|
190 | echo '<p class="pagination">'.__('Page(s)').' : '.$pager->getLinks().'</p>'; |
---|
191 | } |
---|
192 | } |
---|
193 | |
---|
194 | private function postLine() |
---|
195 | { |
---|
196 | $img = '<img alt="%1$s" title="%1$s" src="images/%2$s" />'; |
---|
197 | switch ($this->rs->post_status) { |
---|
198 | case 1: |
---|
199 | $img_status = sprintf($img,__('Published'),'check-on.png'); |
---|
200 | break; |
---|
201 | case 0: |
---|
202 | $img_status = sprintf($img,__('Unpublished'),'check-off.png'); |
---|
203 | break; |
---|
204 | case -1: |
---|
205 | $img_status = sprintf($img,__('Scheduled'),'scheduled.png'); |
---|
206 | break; |
---|
207 | case -2: |
---|
208 | $img_status = sprintf($img,__('Pending'),'check-wrn.png'); |
---|
209 | break; |
---|
210 | } |
---|
211 | |
---|
212 | $protected = ''; |
---|
213 | if ($this->rs->post_password) { |
---|
214 | $protected = sprintf($img,__('Protected'),'locker.png'); |
---|
215 | } |
---|
216 | |
---|
217 | $selected = ''; |
---|
218 | if ($this->rs->post_selected) { |
---|
219 | $selected = sprintf($img,__('Selected'),'selected.png'); |
---|
220 | } |
---|
221 | |
---|
222 | $attach = ''; |
---|
223 | $nb_media = $this->rs->countMedia(); |
---|
224 | if ($nb_media > 0) { |
---|
225 | $attach_str = $nb_media == 1 ? __('%d attachment') : __('%d attachments'); |
---|
226 | $attach = sprintf($img,sprintf($attach_str,$nb_media),'attach.png'); |
---|
227 | } |
---|
228 | |
---|
229 | $res = '<tr class="line'.($this->rs->post_status != 1 ? ' offline' : '').'"'. |
---|
230 | ' id="p'.$this->rs->post_id.'">'; |
---|
231 | |
---|
232 | $res .= |
---|
233 | '<td scope="row" class="maximal"><a href="'.$this->core->getPostAdminURL($this->rs->post_type,$this->rs->post_id).'" '. |
---|
234 | 'title="'.html::escapeHTML($this->rs->getURL()).'">'. |
---|
235 | html::escapeHTML($this->rs->post_title).'</a></td>'. |
---|
236 | '<td class="nowrap count">'.dt::dt2str(__('%Y-%m-%d %H:%M'),$this->rs->post_dt).'</td>'. |
---|
237 | '<td class="nowrap">'.html::escapeHTML($this->rs->user_id).'</td>'. |
---|
238 | '<td class="nowrap status">'.$img_status.' '.$selected.' '.$protected.' '.$attach.'</td>'. |
---|
239 | '</tr>'; |
---|
240 | |
---|
241 | return $res; |
---|
242 | } |
---|
243 | } |
---|
244 | |
---|
245 | class adminCommentList extends adminGenericList |
---|
246 | { |
---|
247 | public function display($page,$nb_per_page,$enclose_block='') |
---|
248 | { |
---|
249 | if ($this->rs->isEmpty()) |
---|
250 | { |
---|
251 | echo '<p><strong>'.__('No comment').'</strong></p>'; |
---|
252 | } |
---|
253 | else |
---|
254 | { |
---|
255 | $pager = new pager($page,$this->rs_count,$nb_per_page,10); |
---|
256 | $pager->html_prev = $this->html_prev; |
---|
257 | $pager->html_next = $this->html_next; |
---|
258 | $pager->var_page = 'page'; |
---|
259 | |
---|
260 | $html_block = |
---|
261 | '<table><caption class="hidden">'.__('Comments and trackbacks list').'</caption><tr>'. |
---|
262 | '<th colspan="2" scope="col" abbr="comm" class="first">'.__('Type').'</th>'. |
---|
263 | '<th scope="col">'.__('Author').'</th>'. |
---|
264 | '<th scope="col">'.__('Date').'</th>'. |
---|
265 | '<th scope="col" class="txt-center">'.__('Status').'</th>'. |
---|
266 | '<th scope="col" abbr="entry">'.__('Entry title').'</th>'. |
---|
267 | '</tr>%s</table>'; |
---|
268 | |
---|
269 | if ($enclose_block) { |
---|
270 | $html_block = sprintf($enclose_block,$html_block); |
---|
271 | } |
---|
272 | |
---|
273 | echo '<p class="pagination">'.__('Page(s)').' : '.$pager->getLinks().'</p>'; |
---|
274 | |
---|
275 | $blocks = explode('%s',$html_block); |
---|
276 | |
---|
277 | echo $blocks[0]; |
---|
278 | |
---|
279 | while ($this->rs->fetch()) |
---|
280 | { |
---|
281 | echo $this->commentLine(); |
---|
282 | } |
---|
283 | |
---|
284 | echo $blocks[1]; |
---|
285 | |
---|
286 | echo '<p class="pagination">'.__('Page(s)').' : '.$pager->getLinks().'</p>'; |
---|
287 | } |
---|
288 | } |
---|
289 | |
---|
290 | private function commentLine() |
---|
291 | { |
---|
292 | global $author, $status, $sortby, $order, $nb_per_page; |
---|
293 | |
---|
294 | $author_url = |
---|
295 | 'comments.php?n='.$nb_per_page. |
---|
296 | '&status='.$status. |
---|
297 | '&sortby='.$sortby. |
---|
298 | '&order='.$order. |
---|
299 | '&author='.rawurlencode($this->rs->comment_author); |
---|
300 | |
---|
301 | $post_url = $this->core->getPostAdminURL($this->rs->post_type,$this->rs->post_id); |
---|
302 | |
---|
303 | $comment_url = 'comment.php?id='.$this->rs->comment_id; |
---|
304 | |
---|
305 | $comment_dt = |
---|
306 | dt::dt2str($this->core->blog->settings->system->date_format.' - '. |
---|
307 | $this->core->blog->settings->system->time_format,$this->rs->comment_dt); |
---|
308 | |
---|
309 | $img = '<img alt="%1$s" title="%1$s" src="images/%2$s" />'; |
---|
310 | switch ($this->rs->comment_status) { |
---|
311 | case 1: |
---|
312 | $img_status = sprintf($img,__('Published'),'check-on.png'); |
---|
313 | break; |
---|
314 | case 0: |
---|
315 | $img_status = sprintf($img,__('Unpublished'),'check-off.png'); |
---|
316 | break; |
---|
317 | case -1: |
---|
318 | $img_status = sprintf($img,__('Pending'),'check-wrn.png'); |
---|
319 | break; |
---|
320 | case -2: |
---|
321 | $img_status = sprintf($img,__('Junk'),'junk.png'); |
---|
322 | break; |
---|
323 | } |
---|
324 | |
---|
325 | $post_title = html::escapeHTML($this->rs->post_title); |
---|
326 | if (mb_strlen($post_title) > 60) { |
---|
327 | $post_title = mb_strcut($post_title,0,57).'...'; |
---|
328 | } |
---|
329 | $comment_title = sprintf(__('Edit the %1$s from %2$s'), |
---|
330 | $this->rs->comment_trackback ? __('trackback') : __('comment'), |
---|
331 | html::escapeHTML($this->rs->comment_author)); |
---|
332 | |
---|
333 | $res = '<tr class="line'.($this->rs->comment_status != 1 ? ' offline' : '').'"'. |
---|
334 | ' id="c'.$this->rs->comment_id.'">'; |
---|
335 | |
---|
336 | $res .= |
---|
337 | '<td class="nowrap">'. |
---|
338 | form::checkbox(array('comments[]'),$this->rs->comment_id,'','','',0).'</td>'. |
---|
339 | '<td class="nowrap" abbr="'.__('Type and author').'" scope="raw">'. |
---|
340 | '<a href="'.$comment_url.'" title="'.$comment_title.'">'. |
---|
341 | '<img src="images/edit-mini.png" alt="'.__('Edit').'"/> '. |
---|
342 | ($this->rs->comment_trackback ? __('trackback') : __('comment')).' '.'</a></td>'. |
---|
343 | '<td class="nowrap maximal"><a href="'.$author_url.'">'.html::escapeHTML($this->rs->comment_author).'</a></td>'. |
---|
344 | '<td class="nowrap count">'.dt::dt2str(__('%Y-%m-%d %H:%M'),$this->rs->comment_dt).'</td>'. |
---|
345 | '<td class="nowrap status txt-center">'.$img_status.'</td>'. |
---|
346 | '<td class="nowrap"><a href="'.$post_url.'">'. |
---|
347 | html::escapeHTML($post_title).'</a>'. |
---|
348 | ($this->rs->post_type != 'post' ? ' ('.html::escapeHTML($this->rs->post_type).')' : '').'</td>'; |
---|
349 | |
---|
350 | $res .= '</tr>'; |
---|
351 | |
---|
352 | return $res; |
---|
353 | } |
---|
354 | } |
---|
355 | |
---|
356 | class adminUserList extends adminGenericList |
---|
357 | { |
---|
358 | public function display($page,$nb_per_page,$enclose_block='') |
---|
359 | { |
---|
360 | if ($this->rs->isEmpty()) |
---|
361 | { |
---|
362 | echo '<p><strong>'.__('No user').'</strong></p>'; |
---|
363 | } |
---|
364 | else |
---|
365 | { |
---|
366 | $pager = new pager($page,$this->rs_count,$nb_per_page,10); |
---|
367 | $pager->html_prev = $this->html_prev; |
---|
368 | $pager->html_next = $this->html_next; |
---|
369 | $pager->var_page = 'page'; |
---|
370 | |
---|
371 | $html_block = |
---|
372 | '<table class="clear"><caption class="hidden">'.__('Users list').'</caption><tr>'. |
---|
373 | '<th colspan="2" scope="col" class="first">'.__('Username').'</th>'. |
---|
374 | '<th scope="col">'.__('First Name').'</th>'. |
---|
375 | '<th scope="col">'.__('Last Name').'</th>'. |
---|
376 | '<th scope="col">'.__('Display name').'</th>'. |
---|
377 | '<th scope="col" class="nowrap">'.__('Entries').'</th>'. |
---|
378 | '</tr>%s</table>'; |
---|
379 | |
---|
380 | if ($enclose_block) { |
---|
381 | $html_block = sprintf($enclose_block,$html_block); |
---|
382 | } |
---|
383 | |
---|
384 | echo '<p class="pagination">'.__('Page(s)').' : '.$pager->getLinks().'</p>'; |
---|
385 | |
---|
386 | $blocks = explode('%s',$html_block); |
---|
387 | |
---|
388 | echo $blocks[0]; |
---|
389 | |
---|
390 | while ($this->rs->fetch()) |
---|
391 | { |
---|
392 | echo $this->userLine(); |
---|
393 | } |
---|
394 | |
---|
395 | echo $blocks[1]; |
---|
396 | |
---|
397 | echo '<p class="pagination">'.__('Page(s)').' : '.$pager->getLinks().'</p>'; |
---|
398 | } |
---|
399 | } |
---|
400 | |
---|
401 | private function userLine() |
---|
402 | { |
---|
403 | $img = '<img alt="%1$s" title="%1$s" src="images/%2$s" />'; |
---|
404 | $img_status = ''; |
---|
405 | |
---|
406 | $p = $this->core->getUserPermissions($this->rs->user_id); |
---|
407 | |
---|
408 | if (isset($p[$this->core->blog->id]['p']['admin'])) { |
---|
409 | $img_status = sprintf($img,__('admin'),'admin.png'); |
---|
410 | } |
---|
411 | if ($this->rs->user_super) { |
---|
412 | $img_status = sprintf($img,__('superadmin'),'superadmin.png'); |
---|
413 | } |
---|
414 | return |
---|
415 | '<tr class="line">'. |
---|
416 | '<td class="nowrap">'.form::hidden(array('nb_post[]'),(integer) $this->rs->nb_post). |
---|
417 | form::checkbox(array('users[]'),$this->rs->user_id).'</td>'. |
---|
418 | '<td class="maximal" scope="row"><a href="user.php?id='.$this->rs->user_id.'">'. |
---|
419 | $this->rs->user_id.'</a> '.$img_status.'</td>'. |
---|
420 | '<td class="nowrap">'.html::escapeHTML($this->rs->user_firstname).'</td>'. |
---|
421 | '<td class="nowrap">'.html::escapeHTML($this->rs->user_name).'</td>'. |
---|
422 | '<td class="nowrap">'.html::escapeHTML($this->rs->user_displayname).'</td>'. |
---|
423 | '<td class="nowrap count"><a href="posts.php?user_id='.$this->rs->user_id.'">'. |
---|
424 | $this->rs->nb_post.'</a></td>'. |
---|
425 | '</tr>'; |
---|
426 | } |
---|
427 | } |
---|
428 | ?> |
---|