Dotclear

source: inc/admin/lib.pager.php @ 3725:b47f38c701ee

Revision 3725:b47f38c701ee, 34.2 KB checked in by franck <carnet.franck.paul@…>, 7 years ago (diff)

Use specialized input fields (color, email, url, number, …) where is relevant

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

Sites map