Dotclear

source: plugins/pages/class.listpage.php @ 3707:3a350757c847

Revision 3707:3a350757c847, 6.0 KB checked in by franck <carnet.franck.paul@…>, 8 years ago (diff)

Use array form of optionnal parameters for form::checkbox() where is relevant, code formatting (PSR-2)

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

Sites map