Dotclear

source: plugins/pages/class.listpage.php @ 3874:ab8368569446

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

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

Line 
1<?php
2/**
3 * @brief pages, a plugin for Dotclear 2
4 *
5 * @package Dotclear
6 * @subpackage Plugins
7 *
8 * @copyright Olivier Meunier & Association Dotclear
9 * @copyright GPL-2.0-only
10 */
11
12/* Pager class
13-------------------------------------------------------- */
14class adminPagesList extends adminGenericList
15{
16    public function display($page, $nb_per_page, $enclose_block = '')
17    {
18        if ($this->rs->isEmpty()) {
19            echo '<p><strong>' . __('No page') . '</strong></p>';
20        } else {
21            $pager   = new dcPager($page, $this->rs_count, $nb_per_page, 10);
22            $entries = [];
23            if (isset($_REQUEST['entries'])) {
24                foreach ($_REQUEST['entries'] as $v) {
25                    $entries[(integer) $v] = true;
26                }
27            }
28            $html_block =
29                '<div class="table-outer">' .
30                '<table class="maximal dragable"><thead><tr>';
31
32            $cols = [
33                'title'      => '<th colspan="3" scope="col" class="first">' . __('Title') . '</th>',
34                'date'       => '<th scope="col">' . __('Date') . '</th>',
35                'author'     => '<th scope="col">' . __('Author') . '</th>',
36                'comments'   => '<th scope="col"><img src="images/comments.png" alt="" title="' . __('Comments') .
37                '" /><span class="hidden">' . __('Comments') . '</span></th>',
38                'trackbacks' => '<th scope="col"><img src="images/trackbacks.png" alt="" title="' . __('Trackbacks') .
39                '" /><span class="hidden">' . __('Trackbacks') . '</span></th>',
40                'status'     => '<th scope="col">' . __('Status') . '</th>'
41            ];
42
43            $cols = new ArrayObject($cols);
44            $this->core->callBehavior('adminPagesListHeader', $this->core, $this->rs, $cols);
45
46            // Cope with optional columns
47            $this->userColumns('pages', $cols);
48
49            $html_block .= '<tr>' . implode(iterator_to_array($cols)) .
50                '</tr></thead><tbody id="pageslist">%s</tbody></table></div>';
51
52            if ($enclose_block) {
53                $html_block = sprintf($enclose_block, $html_block);
54            }
55
56            echo $pager->getLinks();
57
58            $blocks = explode('%s', $html_block);
59
60            echo $blocks[0];
61
62            $count = 0;
63            while ($this->rs->fetch()) {
64                echo $this->postLine($count, isset($entries[$this->rs->post_id]));
65                $count++;
66            }
67
68            echo $blocks[1];
69
70            echo $pager->getLinks();
71        }
72    }
73
74    private function postLine($count, $checked)
75    {
76        $img       = '<img alt="%1$s" title="%1$s" src="images/%2$s" class="mark mark-%3$s" />';
77        $sts_class = '';
78        switch ($this->rs->post_status) {
79            case 1:
80                $img_status = sprintf($img, __('Published'), 'check-on.png', 'published');
81                $sts_class  = 'sts-online';
82                break;
83            case 0:
84                $img_status = sprintf($img, __('Unpublished'), 'check-off.png', 'unpublished');
85                $sts_class  = 'sts-offline';
86                break;
87            case -1:
88                $img_status = sprintf($img, __('Scheduled'), 'scheduled.png', 'scheduled');
89                $sts_class  = 'sts-scheduled';
90                break;
91            case -2:
92                $img_status = sprintf($img, __('Pending'), 'check-wrn.png', 'pending');
93                $sts_class  = 'sts-pending';
94                break;
95        }
96
97        $protected = '';
98        if ($this->rs->post_password) {
99            $protected = sprintf($img, __('Protected'), 'locker.png', 'locked');
100        }
101
102        $selected = '';
103        if ($this->rs->post_selected) {
104            $selected = sprintf($img, __('Hidden'), 'hidden.png', 'hidden');
105        }
106
107        $attach   = '';
108        $nb_media = $this->rs->countMedia();
109        if ($nb_media > 0) {
110            $attach_str = $nb_media == 1 ? __('%d attachment') : __('%d attachments');
111            $attach     = sprintf($img, sprintf($attach_str, $nb_media), 'attach.png', 'attach');
112        }
113
114        $res = '<tr class="line ' . ($this->rs->post_status != 1 ? 'offline ' : '') . $sts_class . '"' .
115        ' id="p' . $this->rs->post_id . '">';
116
117        $cols = [
118            'position'   => '<td class="nowrap handle minimal">' .
119            form::number(['order[' . $this->rs->post_id . ']'], [
120                'min'        => 1,
121                'default'    => $count + 1,
122                'class'      => 'position',
123                'extra_html' => 'title="' . sprintf(__('position of %s'), html::escapeHTML($this->rs->post_title)) . '"'
124            ]) .
125            '</td>',
126            'check'      => '<td class="nowrap">' .
127            form::checkbox(['entries[]'], $this->rs->post_id,
128                [
129                    'checked'    => $checked,
130                    'disabled'   => !$this->rs->isEditable(),
131                    'extra_html' => 'title="' . __('Select this page') . '"'
132                ]
133            ) . '</td>',
134            'title'      => '<td class="maximal" scope="row"><a href="' .
135            $this->core->getPostAdminURL($this->rs->post_type, $this->rs->post_id) . '">' .
136            html::escapeHTML($this->rs->post_title) . '</a></td>',
137            'date'       => '<td class="nowrap">' . dt::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->post_dt) . '</td>',
138            'author'     => '<td class="nowrap">' . $this->rs->user_id . '</td>',
139            'comments'   => '<td class="nowrap count">' . $this->rs->nb_comment . '</td>',
140            'trackbacks' => '<td class="nowrap count">' . $this->rs->nb_trackback . '</td>',
141            'status'     => '<td class="nowrap status">' . $img_status . ' ' . $selected . ' ' . $protected . ' ' . $attach . '</td>'
142        ];
143
144        $cols = new ArrayObject($cols);
145        $this->core->callBehavior('adminPagesListValue', $this->core, $this->rs, $cols);
146
147        // Cope with optional columns
148        $this->userColumns('pages', $cols);
149
150        $res .= implode(iterator_to_array($cols));
151        $res .= '</tr>';
152
153        return $res;
154    }
155}
Note: See TracBrowser for help on using the repository browser.

Sites map