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 dcPager extends pager |
---|
15 | { |
---|
16 | protected $form_action; |
---|
17 | protected $form_hidden; |
---|
18 | |
---|
19 | protected function getLink($li_class,$href,$img_src,$img_src_nolink,$img_alt,$enable_link) { |
---|
20 | if ($enable_link) { |
---|
21 | $formatter = '<li class="%s btn"><a href="%s"><img src="%s" alt="%s"/></a><span class="hidden">%s</span></li>'; |
---|
22 | return sprintf ($formatter, |
---|
23 | $li_class,$href,$img_src,$img_alt,$img_alt); |
---|
24 | } else { |
---|
25 | $formatter = '<li class="%s no-link btn"><img src="%s" alt="%s"/></li>'; |
---|
26 | return sprintf ($formatter, |
---|
27 | $li_class,$img_src_nolink,$img_alt,$img_alt); |
---|
28 | } |
---|
29 | } |
---|
30 | public function setURL() { |
---|
31 | parent::setURL(); |
---|
32 | $url = parse_url($_SERVER['REQUEST_URI']); |
---|
33 | if (isset($url['query'])) { |
---|
34 | parse_str($url['query'],$args); |
---|
35 | } else { |
---|
36 | $args=array(); |
---|
37 | } |
---|
38 | # Removing session information |
---|
39 | if (session_id()) |
---|
40 | { |
---|
41 | if (isset($args[session_name()])) |
---|
42 | unset($args[session_name()]); |
---|
43 | } |
---|
44 | if (isset($args[$this->var_page])) { |
---|
45 | unset($args[$this->var_page]); |
---|
46 | } |
---|
47 | if (isset($args['ok'])) { |
---|
48 | unset($args['ok']); |
---|
49 | } |
---|
50 | $this->form_hidden = ''; |
---|
51 | foreach ($args as $k=>$v) { |
---|
52 | if (is_array($v)) { |
---|
53 | foreach ($v as $k2=>$v2) { |
---|
54 | $this->form_hidden .= form::hidden(array($k.'[]'),html::escapeHTML($v2)); |
---|
55 | } |
---|
56 | } else { |
---|
57 | $this->form_hidden .= form::hidden(array($k),html::escapeHTML($v)); |
---|
58 | } |
---|
59 | } |
---|
60 | $this->form_action = $url['path']; |
---|
61 | } |
---|
62 | |
---|
63 | /** |
---|
64 | * Pager Links |
---|
65 | * |
---|
66 | * Returns pager links |
---|
67 | * |
---|
68 | * @return string |
---|
69 | */ |
---|
70 | public function getLinks() |
---|
71 | { |
---|
72 | $this->setURL(); |
---|
73 | $htmlFirst = $this->getLink( |
---|
74 | "first", |
---|
75 | sprintf($this->page_url,1), |
---|
76 | "images/pagination/first.png", |
---|
77 | "images/pagination/no-first.png", |
---|
78 | __('First page'), |
---|
79 | ($this->env > 1) |
---|
80 | ); |
---|
81 | $htmlPrev = $this->getLink( |
---|
82 | "prev", |
---|
83 | sprintf($this->page_url,$this->env-1), |
---|
84 | "images/pagination/previous.png", |
---|
85 | "images/pagination/no-previous.png", |
---|
86 | __('Previous page'), |
---|
87 | ($this->env > 1) |
---|
88 | ); |
---|
89 | $htmlNext = $this->getLink( |
---|
90 | "next", |
---|
91 | sprintf($this->page_url,$this->env+1), |
---|
92 | "images/pagination/next.png", |
---|
93 | "images/pagination/no-next.png", |
---|
94 | __('Next page'), |
---|
95 | ($this->env < $this->nb_pages) |
---|
96 | ); |
---|
97 | $htmlLast = $this->getLink( |
---|
98 | "last", |
---|
99 | sprintf($this->page_url,$this->nb_pages), |
---|
100 | "images/pagination/last.png", |
---|
101 | "images/pagination/no-last.png", |
---|
102 | __('Last page'), |
---|
103 | ($this->env < $this->nb_pages) |
---|
104 | ); |
---|
105 | $htmlCurrent = |
---|
106 | '<li class="active"><strong>'. |
---|
107 | sprintf(__('Page %s / %s'),$this->env,$this->nb_pages). |
---|
108 | '</strong></li>'; |
---|
109 | |
---|
110 | $htmlDirect = |
---|
111 | ($this->nb_pages > 1 ? |
---|
112 | sprintf('<li class="direct-access">'.__('Direct access page %s'), |
---|
113 | form::field(array($this->var_page),3,10)). |
---|
114 | '<input type="submit" value="'.__('ok').'" class="reset" '. |
---|
115 | 'name="ok" />'.$this->form_hidden.'</li>' : ''); |
---|
116 | |
---|
117 | $res = |
---|
118 | '<form action="'.$this->form_action.'" method="get">'. |
---|
119 | '<div class="pager"><ul>'. |
---|
120 | $htmlFirst. |
---|
121 | $htmlPrev. |
---|
122 | $htmlCurrent. |
---|
123 | $htmlNext. |
---|
124 | $htmlLast. |
---|
125 | $htmlDirect. |
---|
126 | '</ul>'. |
---|
127 | '</div>'. |
---|
128 | '</form>' |
---|
129 | ; |
---|
130 | |
---|
131 | return $this->nb_elements > 0 ? $res : ''; |
---|
132 | } |
---|
133 | } |
---|
134 | |
---|
135 | class adminGenericList |
---|
136 | { |
---|
137 | protected $core; |
---|
138 | protected $rs; |
---|
139 | protected $rs_count; |
---|
140 | |
---|
141 | public function __construct($core,$rs,$rs_count) |
---|
142 | { |
---|
143 | $this->core =& $core; |
---|
144 | $this->rs =& $rs; |
---|
145 | $this->rs_count = $rs_count; |
---|
146 | $this->html_prev = __('« prev.'); |
---|
147 | $this->html_next = __('next »'); |
---|
148 | } |
---|
149 | |
---|
150 | public function userColumns($type,$cols) |
---|
151 | { |
---|
152 | $cols_user = @$this->core->auth->user_prefs->interface->cols; |
---|
153 | if (is_array($cols_user)) { |
---|
154 | if (isset($cols_user[$type])) { |
---|
155 | foreach ($cols_user[$type] as $cn => $cd) { |
---|
156 | if (!$cd && isset($cols[$cn])) { |
---|
157 | unset($cols[$cn]); |
---|
158 | } |
---|
159 | } |
---|
160 | } |
---|
161 | } |
---|
162 | } |
---|
163 | } |
---|
164 | |
---|
165 | class adminPostList extends adminGenericList |
---|
166 | { |
---|
167 | public function display($page,$nb_per_page,$enclose_block='',$filter=false) |
---|
168 | { |
---|
169 | if ($this->rs->isEmpty()) |
---|
170 | { |
---|
171 | if( $filter ) { |
---|
172 | echo '<p><strong>'.__('No entry matches the filter').'</strong></p>'; |
---|
173 | } else { |
---|
174 | echo '<p><strong>'.__('No entry').'</strong></p>'; |
---|
175 | } |
---|
176 | } |
---|
177 | else |
---|
178 | { |
---|
179 | $pager = new dcPager($page,$this->rs_count,$nb_per_page,10); |
---|
180 | $entries = array(); |
---|
181 | if (isset($_REQUEST['entries'])) { |
---|
182 | foreach ($_REQUEST['entries'] as $v) { |
---|
183 | $entries[(integer)$v]=true; |
---|
184 | } |
---|
185 | } |
---|
186 | $html_block = |
---|
187 | '<div class="table-outer">'. |
---|
188 | '<table>'; |
---|
189 | |
---|
190 | if( $filter ) { |
---|
191 | $html_block .= '<caption>'.sprintf(__('List of %s entries matching the filter.'), $this->rs_count).'</caption>'; |
---|
192 | } else { |
---|
193 | $nb_published = $this->core->blog->getPosts(array('post_status' => 1),true)->f(0); |
---|
194 | $nb_pending = $this->core->blog->getPosts(array('post_status' => -2),true)->f(0); |
---|
195 | $nb_programmed = $this->core->blog->getPosts(array('post_status' => -1),true)->f(0); |
---|
196 | $nb_unpublished = $this->core->blog->getPosts(array('post_status' => 0),true)->f(0); |
---|
197 | $html_block .= '<caption>'. |
---|
198 | sprintf(__('List of entries (%s)'),$this->rs_count). |
---|
199 | ($nb_published ? |
---|
200 | sprintf( |
---|
201 | __(', <a href="%s">published</a> (1)',', <a href="%s">published</a> (%s)',$nb_published), |
---|
202 | $this->core->adminurl->get('admin.posts',array('status' => 1)), |
---|
203 | $nb_published) : ''). |
---|
204 | ($nb_pending ? |
---|
205 | sprintf( |
---|
206 | __(', <a href="%s">pending</a> (1)',', <a href="%s">pending</a> (%s)',$nb_pending), |
---|
207 | $this->core->adminurl->get('admin.posts',array('status' => -2)), |
---|
208 | $nb_pending) : ''). |
---|
209 | ($nb_programmed ? |
---|
210 | sprintf(__(', <a href="%s">programmed</a> (1)',', <a href="%s">programmed</a> (%s)',$nb_programmed), |
---|
211 | $this->core->adminurl->get('admin.posts',array('status' => -1)), |
---|
212 | $nb_programmed) : ''). |
---|
213 | ($nb_unpublished ? |
---|
214 | sprintf(__(', <a href="%s">unpublished</a> (1)',', <a href="%s">unpublished</a> (%s)',$nb_unpublished), |
---|
215 | $this->core->adminurl->get('admin.posts',array('status' => 0)), |
---|
216 | $nb_unpublished) : ''). |
---|
217 | '</caption>'; |
---|
218 | } |
---|
219 | |
---|
220 | $cols = array( |
---|
221 | 'title' => '<th colspan="2" class="first">'.__('Title').'</th>', |
---|
222 | 'date' => '<th scope="col">'.__('Date').'</th>', |
---|
223 | 'category' => '<th scope="col">'.__('Category').'</th>', |
---|
224 | 'author' => '<th scope="col">'.__('Author').'</th>', |
---|
225 | 'comments' => '<th scope="col"><img src="images/comments.png" alt="" title="'.__('Comments'). |
---|
226 | '" /><span class="hidden">'.__('Comments').'</span></th>', |
---|
227 | 'trackbacks' => '<th scope="col"><img src="images/trackbacks.png" alt="" title="'.__('Trackbacks'). |
---|
228 | '" /><span class="hidden">'.__('Trackbacks').'</span></th>', |
---|
229 | 'status' => '<th scope="col">'.__('Status').'</th>' |
---|
230 | ); |
---|
231 | $cols = new ArrayObject($cols); |
---|
232 | $this->core->callBehavior('adminPostListHeader',$this->core,$this->rs,$cols); |
---|
233 | |
---|
234 | // Cope with optional columns |
---|
235 | $this->userColumns('posts',$cols); |
---|
236 | |
---|
237 | $html_block .= '<tr>'.implode(iterator_to_array($cols)).'</tr>%s</table></div>'; |
---|
238 | if ($enclose_block) { |
---|
239 | $html_block = sprintf($enclose_block,$html_block); |
---|
240 | } |
---|
241 | |
---|
242 | echo $pager->getLinks(); |
---|
243 | |
---|
244 | $blocks = explode('%s',$html_block); |
---|
245 | |
---|
246 | echo $blocks[0]; |
---|
247 | |
---|
248 | while ($this->rs->fetch()) |
---|
249 | { |
---|
250 | echo $this->postLine(isset($entries[$this->rs->post_id])); |
---|
251 | } |
---|
252 | |
---|
253 | echo $blocks[1]; |
---|
254 | |
---|
255 | echo $pager->getLinks(); |
---|
256 | } |
---|
257 | } |
---|
258 | |
---|
259 | private function postLine($checked) |
---|
260 | { |
---|
261 | if ($this->core->auth->check('categories',$this->core->blog->id)) { |
---|
262 | $cat_link = '<a href="'.$this->core->adminurl->get('admin.category',array('id' => '%s'),'&',true).'">%s</a>'; |
---|
263 | } else { |
---|
264 | $cat_link = '%2$s'; |
---|
265 | } |
---|
266 | |
---|
267 | if ($this->rs->cat_title) { |
---|
268 | $cat_title = sprintf($cat_link,$this->rs->cat_id, |
---|
269 | html::escapeHTML($this->rs->cat_title)); |
---|
270 | } else { |
---|
271 | $cat_title = __('(No cat)'); |
---|
272 | } |
---|
273 | |
---|
274 | $img = '<img alt="%1$s" title="%1$s" src="images/%2$s" />'; |
---|
275 | $sts_class = ''; |
---|
276 | switch ($this->rs->post_status) { |
---|
277 | case 1: |
---|
278 | $img_status = sprintf($img,__('Published'),'check-on.png'); |
---|
279 | $sts_class = 'sts-online'; |
---|
280 | break; |
---|
281 | case 0: |
---|
282 | $img_status = sprintf($img,__('Unpublished'),'check-off.png'); |
---|
283 | $sts_class = 'sts-offline'; |
---|
284 | break; |
---|
285 | case -1: |
---|
286 | $img_status = sprintf($img,__('Scheduled'),'scheduled.png'); |
---|
287 | $sts_class = 'sts-scheduled'; |
---|
288 | break; |
---|
289 | case -2: |
---|
290 | $img_status = sprintf($img,__('Pending'),'check-wrn.png'); |
---|
291 | $sts_class = 'sts-pending'; |
---|
292 | break; |
---|
293 | } |
---|
294 | |
---|
295 | $protected = ''; |
---|
296 | if ($this->rs->post_password) { |
---|
297 | $protected = sprintf($img,__('Protected'),'locker.png'); |
---|
298 | } |
---|
299 | |
---|
300 | $selected = ''; |
---|
301 | if ($this->rs->post_selected) { |
---|
302 | $selected = sprintf($img,__('Selected'),'selected.png'); |
---|
303 | } |
---|
304 | |
---|
305 | $attach = ''; |
---|
306 | $nb_media = $this->rs->countMedia(); |
---|
307 | if ($nb_media > 0) { |
---|
308 | $attach_str = $nb_media == 1 ? __('%d attachment') : __('%d attachments'); |
---|
309 | $attach = sprintf($img,sprintf($attach_str,$nb_media),'attach.png'); |
---|
310 | } |
---|
311 | |
---|
312 | $res = '<tr class="line '.($this->rs->post_status != 1 ? 'offline ' : '').$sts_class.'"'. |
---|
313 | ' id="p'.$this->rs->post_id.'">'; |
---|
314 | |
---|
315 | $cols = array( |
---|
316 | 'check' => '<td class="nowrap">'. |
---|
317 | form::checkbox(array('entries[]'),$this->rs->post_id,$checked,'','',!$this->rs->isEditable()). |
---|
318 | '</td>', |
---|
319 | 'title' => '<td class="maximal" scope="row"><a href="'. |
---|
320 | $this->core->getPostAdminURL($this->rs->post_type,$this->rs->post_id).'">'. |
---|
321 | html::escapeHTML($this->rs->post_title).'</a></td>', |
---|
322 | 'date' => '<td class="nowrap count">'.dt::dt2str(__('%Y-%m-%d %H:%M'),$this->rs->post_dt).'</td>', |
---|
323 | 'category' => '<td class="nowrap">'.$cat_title.'</td>', |
---|
324 | 'author' => '<td class="nowrap">'.html::escapeHTML($this->rs->user_id).'</td>', |
---|
325 | 'comments' => '<td class="nowrap count">'.$this->rs->nb_comment.'</td>', |
---|
326 | 'trackbacks' => '<td class="nowrap count">'.$this->rs->nb_trackback.'</td>', |
---|
327 | 'status' => '<td class="nowrap status">'.$img_status.' '.$selected.' '.$protected.' '.$attach.'</td>' |
---|
328 | ); |
---|
329 | $cols = new ArrayObject($cols); |
---|
330 | $this->core->callBehavior('adminPostListValue',$this->core,$this->rs,$cols); |
---|
331 | |
---|
332 | // Cope with optional columns |
---|
333 | $this->userColumns('posts',$cols); |
---|
334 | |
---|
335 | $res .= implode(iterator_to_array($cols)); |
---|
336 | $res .= '</tr>'; |
---|
337 | |
---|
338 | return $res; |
---|
339 | } |
---|
340 | } |
---|
341 | |
---|
342 | class adminPostMiniList extends adminGenericList |
---|
343 | { |
---|
344 | public function display($page,$nb_per_page,$enclose_block='') |
---|
345 | { |
---|
346 | if ($this->rs->isEmpty()) |
---|
347 | { |
---|
348 | echo '<p><strong>'.__('No entry').'</strong></p>'; |
---|
349 | } |
---|
350 | else |
---|
351 | { |
---|
352 | $pager = new dcPager($page,$this->rs_count,$nb_per_page,10); |
---|
353 | |
---|
354 | $html_block = |
---|
355 | '<div class="table-outer clear">'. |
---|
356 | '<table><caption class="hidden">'.__('Entries list').'</caption><tr>'; |
---|
357 | |
---|
358 | $cols = array( |
---|
359 | 'title' => '<th scope="col">'.__('Title').'</th>', |
---|
360 | 'date' => '<th scope="col">'.__('Date').'</th>', |
---|
361 | 'author' => '<th scope="col">'.__('Author').'</th>', |
---|
362 | 'status' => '<th scope="col">'.__('Status').'</th>' |
---|
363 | ); |
---|
364 | |
---|
365 | $cols = new ArrayObject($cols); |
---|
366 | $this->core->callBehavior('adminPostMiniListHeader',$this->core,$this->rs,$cols); |
---|
367 | |
---|
368 | // Cope with optional columns |
---|
369 | $this->userColumns('posts',$cols); |
---|
370 | |
---|
371 | $html_block .= '<tr>'.implode(iterator_to_array($cols)).'</tr>%s</table></div>'; |
---|
372 | if ($enclose_block) { |
---|
373 | $html_block = sprintf($enclose_block,$html_block); |
---|
374 | } |
---|
375 | |
---|
376 | echo $pager->getLinks(); |
---|
377 | |
---|
378 | $blocks = explode('%s',$html_block); |
---|
379 | |
---|
380 | echo $blocks[0]; |
---|
381 | |
---|
382 | while ($this->rs->fetch()) |
---|
383 | { |
---|
384 | echo $this->postLine(); |
---|
385 | } |
---|
386 | |
---|
387 | echo $blocks[1]; |
---|
388 | |
---|
389 | echo $pager->getLinks(); |
---|
390 | } |
---|
391 | } |
---|
392 | |
---|
393 | private function postLine() |
---|
394 | { |
---|
395 | $img = '<img alt="%1$s" title="%1$s" src="images/%2$s" />'; |
---|
396 | $sts_class = ''; |
---|
397 | switch ($this->rs->post_status) { |
---|
398 | case 1: |
---|
399 | $img_status = sprintf($img,__('Published'),'check-on.png'); |
---|
400 | $sts_class = 'sts-online'; |
---|
401 | break; |
---|
402 | case 0: |
---|
403 | $img_status = sprintf($img,__('Unpublished'),'check-off.png'); |
---|
404 | $sts_class = 'sts-offline'; |
---|
405 | break; |
---|
406 | case -1: |
---|
407 | $img_status = sprintf($img,__('Scheduled'),'scheduled.png'); |
---|
408 | $sts_class = 'sts-scheduled'; |
---|
409 | break; |
---|
410 | case -2: |
---|
411 | $img_status = sprintf($img,__('Pending'),'check-wrn.png'); |
---|
412 | $sts_class = 'sts-pending'; |
---|
413 | break; |
---|
414 | } |
---|
415 | |
---|
416 | $protected = ''; |
---|
417 | if ($this->rs->post_password) { |
---|
418 | $protected = sprintf($img,__('Protected'),'locker.png'); |
---|
419 | } |
---|
420 | |
---|
421 | $selected = ''; |
---|
422 | if ($this->rs->post_selected) { |
---|
423 | $selected = sprintf($img,__('Selected'),'selected.png'); |
---|
424 | } |
---|
425 | |
---|
426 | $attach = ''; |
---|
427 | $nb_media = $this->rs->countMedia(); |
---|
428 | if ($nb_media > 0) { |
---|
429 | $attach_str = $nb_media == 1 ? __('%d attachment') : __('%d attachments'); |
---|
430 | $attach = sprintf($img,sprintf($attach_str,$nb_media),'attach.png'); |
---|
431 | } |
---|
432 | |
---|
433 | $res = '<tr class="line '.($this->rs->post_status != 1 ? 'offline ' : '').$sts_class.'"'. |
---|
434 | ' id="p'.$this->rs->post_id.'">'; |
---|
435 | |
---|
436 | $cols = array( |
---|
437 | 'title' => '<td scope="row" class="maximal"><a href="'. |
---|
438 | $this->core->getPostAdminURL($this->rs->post_type,$this->rs->post_id).'" '. |
---|
439 | 'title="'.html::escapeHTML($this->rs->getURL()).'">'. |
---|
440 | html::escapeHTML($this->rs->post_title).'</a></td>', |
---|
441 | 'date' => '<td class="nowrap count">'.dt::dt2str(__('%Y-%m-%d %H:%M'),$this->rs->post_dt).'</td>', |
---|
442 | 'author' => '<td class="nowrap">'.html::escapeHTML($this->rs->user_id).'</td>', |
---|
443 | 'status' => '<td class="nowrap status">'.$img_status.' '.$selected.' '.$protected.' '.$attach.'</td>' |
---|
444 | ); |
---|
445 | |
---|
446 | $cols = new ArrayObject($cols); |
---|
447 | $this->core->callBehavior('adminPostMiniListValue',$this->core,$this->rs,$cols); |
---|
448 | |
---|
449 | // Cope with optional columns |
---|
450 | $this->userColumns('posts',$cols); |
---|
451 | |
---|
452 | $res .= implode(iterator_to_array($cols)); |
---|
453 | $res .= '</tr>'; |
---|
454 | |
---|
455 | return $res; |
---|
456 | } |
---|
457 | } |
---|
458 | |
---|
459 | class adminCommentList extends adminGenericList |
---|
460 | { |
---|
461 | public function display($page,$nb_per_page,$enclose_block='',$filter=false,$spam=false) |
---|
462 | { |
---|
463 | if ($this->rs->isEmpty()) |
---|
464 | { |
---|
465 | if( $filter ) { |
---|
466 | echo '<p><strong>'.__('No comments or trackbacks matches the filter').'</strong></p>'; |
---|
467 | } else { |
---|
468 | echo '<p><strong>'.__('No comments').'</strong></p>'; |
---|
469 | } |
---|
470 | } |
---|
471 | else |
---|
472 | { |
---|
473 | // Get antispam filters' name |
---|
474 | $filters = array(); |
---|
475 | if ($spam) { |
---|
476 | if (class_exists('dcAntispam')) { |
---|
477 | dcAntispam::initFilters(); |
---|
478 | $fs = dcAntispam::$filters->getFilters(); |
---|
479 | foreach ($fs as $fid => $f) |
---|
480 | { |
---|
481 | $filters[$fid] = $f->name; |
---|
482 | } |
---|
483 | } |
---|
484 | } |
---|
485 | |
---|
486 | $pager = new dcPager($page,$this->rs_count,$nb_per_page,10); |
---|
487 | |
---|
488 | $comments = array(); |
---|
489 | if (isset($_REQUEST['comments'])) { |
---|
490 | foreach ($_REQUEST['comments'] as $v) { |
---|
491 | $comments[(integer)$v]=true; |
---|
492 | } |
---|
493 | } |
---|
494 | $html_block = |
---|
495 | '<div class="table-outer">'. |
---|
496 | '<table>'; |
---|
497 | |
---|
498 | if( $filter ) { |
---|
499 | $html_block .= '<caption>'. |
---|
500 | sprintf(__( |
---|
501 | 'Comment or trackback matching the filter.', |
---|
502 | 'List of %s comments or trackbacks matching the filter.', |
---|
503 | $this->rs_count), $this->rs_count). |
---|
504 | '</caption>'; |
---|
505 | } else { |
---|
506 | $nb_published = $this->core->blog->getComments(array('comment_status' => 1),true)->f(0); |
---|
507 | $nb_spam = $this->core->blog->getComments(array('comment_status' => -2),true)->f(0); |
---|
508 | $nb_pending = $this->core->blog->getComments(array('comment_status' => -1),true)->f(0); |
---|
509 | $nb_unpublished = $this->core->blog->getComments(array('comment_status' => 0),true)->f(0); |
---|
510 | $html_block .= '<caption>'. |
---|
511 | sprintf(__('List of comments and trackbacks (%s)'),$this->rs_count). |
---|
512 | ($nb_published ? |
---|
513 | sprintf( |
---|
514 | __(', <a href="%s">published</a> (1)',', <a href="%s">published</a> (%s)',$nb_published), |
---|
515 | $this->core->adminurl->get('admin.comments',array('status' => 1)), |
---|
516 | $nb_published) : ''). |
---|
517 | ($nb_spam ? |
---|
518 | sprintf( |
---|
519 | __(', <a href="%s">spam</a> (1)',', <a href="%s">spam</a> (%s)',$nb_spam), |
---|
520 | $this->core->adminurl->get('admin.comments',array('status' => -2)), |
---|
521 | $nb_spam) : ''). |
---|
522 | ($nb_pending ? |
---|
523 | sprintf(__(', <a href="%s">pending</a> (1)',', <a href="%s">pending</a> (%s)',$nb_pending), |
---|
524 | $this->core->adminurl->get('admin.comments',array('status' => -1)), |
---|
525 | $nb_pending) : ''). |
---|
526 | ($nb_unpublished ? |
---|
527 | sprintf(__(', <a href="%s">unpublished</a> (1)',', <a href="%s">unpublished</a> (%s)',$nb_unpublished), |
---|
528 | $this->core->adminurl->get('admin.comments',array('status' => 0)), |
---|
529 | $nb_unpublished) : ''). |
---|
530 | '</caption>'; |
---|
531 | } |
---|
532 | |
---|
533 | $cols = array( |
---|
534 | 'type' => '<th colspan="2" scope="col" abbr="comm" class="first">'.__('Type').'</th>', |
---|
535 | 'author' => '<th scope="col">'.__('Author').'</th>', |
---|
536 | 'date' => '<th scope="col">'.__('Date').'</th>', |
---|
537 | 'status' => '<th scope="col" class="txt-center">'.__('Status').'</th>' |
---|
538 | ); |
---|
539 | if ($spam) { |
---|
540 | $cols['ip'] = '<th scope="col">'.__('IP').'</th>'; |
---|
541 | $cols['spam_filter'] = '<th scope="col">'.__('Spam filter').'</th>'; |
---|
542 | } |
---|
543 | $cols['entry'] = '<th scope="col" abbr="entry">'.__('Entry').'</th>'; |
---|
544 | |
---|
545 | $cols = new ArrayObject($cols); |
---|
546 | $this->core->callBehavior('adminCommentListHeader',$this->core,$this->rs,$cols); |
---|
547 | |
---|
548 | $html_block .= '<tr>'.implode(iterator_to_array($cols)).'</tr>%s</table></div>'; |
---|
549 | |
---|
550 | if ($enclose_block) { |
---|
551 | $html_block = sprintf($enclose_block,$html_block); |
---|
552 | } |
---|
553 | |
---|
554 | echo $pager->getLinks(); |
---|
555 | |
---|
556 | $blocks = explode('%s',$html_block); |
---|
557 | |
---|
558 | echo $blocks[0]; |
---|
559 | |
---|
560 | while ($this->rs->fetch()) |
---|
561 | { |
---|
562 | echo $this->commentLine(isset($comments[$this->rs->comment_id]),$spam,$filters); |
---|
563 | } |
---|
564 | |
---|
565 | echo $blocks[1]; |
---|
566 | |
---|
567 | echo $pager->getLinks(); |
---|
568 | } |
---|
569 | } |
---|
570 | |
---|
571 | private function commentLine($checked=false,$spam=false,$filters=array()) |
---|
572 | { |
---|
573 | global $core, $author, $status, $sortby, $order, $nb_per_page; |
---|
574 | |
---|
575 | $author_url = |
---|
576 | $this->core->adminurl->get('admin.comments',array( |
---|
577 | 'n' => $nb_per_page, |
---|
578 | 'status' => $status, |
---|
579 | 'sortby' => $sortby, |
---|
580 | 'order' => $order, |
---|
581 | 'author' => $this->rs->comment_author |
---|
582 | )); |
---|
583 | |
---|
584 | $post_url = $this->core->getPostAdminURL($this->rs->post_type,$this->rs->post_id); |
---|
585 | |
---|
586 | $comment_url = $this->core->adminurl->get('admin.comment',array('id' => $this->rs->comment_id)); |
---|
587 | |
---|
588 | $comment_dt = |
---|
589 | dt::dt2str($this->core->blog->settings->system->date_format.' - '. |
---|
590 | $this->core->blog->settings->system->time_format,$this->rs->comment_dt); |
---|
591 | |
---|
592 | $img = '<img alt="%1$s" title="%1$s" src="images/%2$s" />'; |
---|
593 | $sts_class = ''; |
---|
594 | switch ($this->rs->comment_status) { |
---|
595 | case 1: |
---|
596 | $img_status = sprintf($img,__('Published'),'check-on.png'); |
---|
597 | $sts_class = 'sts-online'; |
---|
598 | break; |
---|
599 | case 0: |
---|
600 | $img_status = sprintf($img,__('Unpublished'),'check-off.png'); |
---|
601 | $sts_class = 'sts-offline'; |
---|
602 | break; |
---|
603 | case -1: |
---|
604 | $img_status = sprintf($img,__('Pending'),'check-wrn.png'); |
---|
605 | $sts_class = 'sts-pending'; |
---|
606 | break; |
---|
607 | case -2: |
---|
608 | $img_status = sprintf($img,__('Junk'),'junk.png'); |
---|
609 | $sts_class = 'sts-junk'; |
---|
610 | break; |
---|
611 | } |
---|
612 | |
---|
613 | $post_title = html::escapeHTML($this->rs->post_title); |
---|
614 | if (mb_strlen($post_title) > 70) { |
---|
615 | $post_title = mb_strcut($post_title,0,67).'...'; |
---|
616 | } |
---|
617 | $comment_title = sprintf(__('Edit the %1$s from %2$s'), |
---|
618 | $this->rs->comment_trackback ? __('trackback') : __('comment'), |
---|
619 | html::escapeHTML($this->rs->comment_author)); |
---|
620 | |
---|
621 | $res = '<tr class="line '.($this->rs->comment_status != 1 ? 'offline ' : '').$sts_class.'"'. |
---|
622 | ' id="c'.$this->rs->comment_id.'">'; |
---|
623 | |
---|
624 | $cols = array( |
---|
625 | 'check' => '<td class="nowrap">'. |
---|
626 | form::checkbox(array('comments[]'),$this->rs->comment_id,$checked,'','',0).'</td>', |
---|
627 | 'type' => '<td class="nowrap" abbr="'.__('Type and author').'" scope="row">'. |
---|
628 | '<a href="'.$comment_url.'" title="'.$comment_title.'">'. |
---|
629 | '<img src="images/edit-mini.png" alt="'.__('Edit').'"/> '. |
---|
630 | ($this->rs->comment_trackback ? __('trackback') : __('comment')).' '.'</a></td>', |
---|
631 | 'author' => '<td class="nowrap maximal"><a href="'.$author_url.'">'. |
---|
632 | html::escapeHTML($this->rs->comment_author).'</a></td>', |
---|
633 | 'date' => '<td class="nowrap count">'.dt::dt2str(__('%Y-%m-%d %H:%M'),$this->rs->comment_dt).'</td>', |
---|
634 | 'status' => '<td class="nowrap status txt-center">'.$img_status.'</td>' |
---|
635 | ); |
---|
636 | |
---|
637 | if ($spam) { |
---|
638 | $filter_name = ''; |
---|
639 | if ($this->rs->comment_spam_filter) { |
---|
640 | if (isset($filters[$this->rs->comment_spam_filter])) { |
---|
641 | $filter_name = $filters[$this->rs->comment_spam_filter]; |
---|
642 | } else { |
---|
643 | $filter_name = $this->rs->comment_spam_filter; |
---|
644 | } |
---|
645 | } |
---|
646 | $cols['ip'] = '<td class="nowrap"><a href="'. |
---|
647 | $core->adminurl->get("admin.comments",array('ip' => $this->rs->comment_ip)).'">'. |
---|
648 | $this->rs->comment_ip.'</a></td>'; |
---|
649 | $cols['spam_filter'] = '<td class="nowrap">'.$filter_name.'</td>'; |
---|
650 | } |
---|
651 | $cols['entry'] = '<td class="nowrap discrete"><a href="'.$post_url.'">'.$post_title.'</a>'. |
---|
652 | ($this->rs->post_type != 'post' ? ' ('.html::escapeHTML($this->rs->post_type).')' : '').'</td>'; |
---|
653 | |
---|
654 | $cols = new ArrayObject($cols); |
---|
655 | $this->core->callBehavior('adminCommentListValue',$this->core,$this->rs,$cols); |
---|
656 | |
---|
657 | $res .= implode(iterator_to_array($cols)); |
---|
658 | $res .= '</tr>'; |
---|
659 | |
---|
660 | return $res; |
---|
661 | } |
---|
662 | } |
---|
663 | |
---|
664 | class adminUserList extends adminGenericList |
---|
665 | { |
---|
666 | public function display($page,$nb_per_page,$enclose_block='',$filter=false) |
---|
667 | { |
---|
668 | if ($this->rs->isEmpty()) |
---|
669 | { |
---|
670 | if( $filter ) { |
---|
671 | echo '<p><strong>'.__('No user matches the filter').'</strong></p>'; |
---|
672 | } else { |
---|
673 | echo '<p><strong>'.__('No user').'</strong></p>'; |
---|
674 | } |
---|
675 | } |
---|
676 | else |
---|
677 | { |
---|
678 | $pager = new dcPager($page,$this->rs_count,$nb_per_page,10); |
---|
679 | |
---|
680 | $html_block = |
---|
681 | '<div class="table-outer clear">'. |
---|
682 | '<table>'; |
---|
683 | |
---|
684 | if( $filter ) { |
---|
685 | $html_block .= '<caption>'.sprintf(__('List of %s users match the filter.'), $this->rs_count).'</caption>'; |
---|
686 | } else { |
---|
687 | $html_block .= '<caption class="hidden">'.__('Users list').'</caption>'; |
---|
688 | } |
---|
689 | |
---|
690 | $cols = array( |
---|
691 | 'username' => '<th colspan="2" scope="col" class="first">'.__('Username').'</th>', |
---|
692 | 'first_name' => '<th scope="col">'.__('First Name').'</th>', |
---|
693 | 'last_name' => '<th scope="col">'.__('Last Name').'</th>', |
---|
694 | 'display_name' => '<th scope="col">'.__('Display name').'</th>', |
---|
695 | 'entries' => '<th scope="col" class="nowrap">'.__('Entries (all types)').'</th>' |
---|
696 | ); |
---|
697 | |
---|
698 | $cols = new ArrayObject($cols); |
---|
699 | $this->core->callBehavior('adminUserListHeader',$this->core,$this->rs,$cols); |
---|
700 | |
---|
701 | $html_block .= '<tr>'.implode(iterator_to_array($cols)).'</tr>%s</table></div>'; |
---|
702 | if ($enclose_block) { |
---|
703 | $html_block = sprintf($enclose_block,$html_block); |
---|
704 | } |
---|
705 | |
---|
706 | echo $pager->getLinks(); |
---|
707 | |
---|
708 | $blocks = explode('%s',$html_block); |
---|
709 | |
---|
710 | echo $blocks[0]; |
---|
711 | |
---|
712 | while ($this->rs->fetch()) |
---|
713 | { |
---|
714 | echo $this->userLine(); |
---|
715 | } |
---|
716 | |
---|
717 | echo $blocks[1]; |
---|
718 | |
---|
719 | echo $pager->getLinks(); |
---|
720 | } |
---|
721 | } |
---|
722 | |
---|
723 | private function userLine() |
---|
724 | { |
---|
725 | $img = '<img alt="%1$s" title="%1$s" src="images/%2$s" />'; |
---|
726 | $img_status = ''; |
---|
727 | |
---|
728 | $p = $this->core->getUserPermissions($this->rs->user_id); |
---|
729 | |
---|
730 | if (isset($p[$this->core->blog->id]['p']['admin'])) { |
---|
731 | $img_status = sprintf($img,__('admin'),'admin.png'); |
---|
732 | } |
---|
733 | if ($this->rs->user_super) { |
---|
734 | $img_status = sprintf($img,__('superadmin'),'superadmin.png'); |
---|
735 | } |
---|
736 | |
---|
737 | $res = '<tr class="line">'; |
---|
738 | |
---|
739 | $cols = array( |
---|
740 | 'check' => '<td class="nowrap">'.form::hidden(array('nb_post[]'),(integer) $this->rs->nb_post). |
---|
741 | form::checkbox(array('users[]'),$this->rs->user_id).'</td>', |
---|
742 | 'username' => '<td class="maximal" scope="row"><a href="'. |
---|
743 | $this->core->adminurl->get('admin.user',array('id' => $this->rs->user_id)).'">'. |
---|
744 | $this->rs->user_id.'</a> '.$img_status.'</td>', |
---|
745 | 'first_name' => '<td class="nowrap">'.html::escapeHTML($this->rs->user_firstname).'</td>', |
---|
746 | 'last_name' => '<td class="nowrap">'.html::escapeHTML($this->rs->user_name).'</td>', |
---|
747 | 'display_name' => '<td class="nowrap">'.html::escapeHTML($this->rs->user_displayname).'</td>', |
---|
748 | 'entries' => '<td class="nowrap count"><a href="'. |
---|
749 | $this->core->adminurl->get('admin.posts',array('user_id' => $this->rs->user_id)).'">'. |
---|
750 | $this->rs->nb_post.'</a></td>' |
---|
751 | ); |
---|
752 | |
---|
753 | $cols = new ArrayObject($cols); |
---|
754 | $this->core->callBehavior('adminUserListValue',$this->core,$this->rs,$cols); |
---|
755 | |
---|
756 | $res .= implode(iterator_to_array($cols)); |
---|
757 | $res .= '</tr>'; |
---|
758 | |
---|
759 | return $res; |
---|
760 | } |
---|
761 | } |
---|