Dotclear

source: inc/admin/lib.pager.php @ 3874:ab8368569446

Revision 3874:ab8368569446, 34.1 KB checked in by franck <carnet.franck.paul@…>, 7 years ago (diff)

short notation for array (array() → [])

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

Sites map