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