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 | -------------------------------------------------------- */ |
---|
15 | class 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::number(array('order[' . $this->rs->post_id . ']'), array( |
---|
121 | 'min' => 1, |
---|
122 | 'default' => $count + 1, |
---|
123 | 'class' => 'position', |
---|
124 | 'extra_html' => 'title="' . sprintf(__('position of %s'), html::escapeHTML($this->rs->post_title)) . '"' |
---|
125 | )) . |
---|
126 | '</td>', |
---|
127 | 'check' => '<td class="nowrap">' . |
---|
128 | form::checkbox(array('entries[]'), $this->rs->post_id, |
---|
129 | array( |
---|
130 | 'checked' => $checked, |
---|
131 | 'disabled' => !$this->rs->isEditable(), |
---|
132 | 'extra_html' => 'title="' . __('Select this page') . '"' |
---|
133 | ) |
---|
134 | ) . '</td>', |
---|
135 | 'title' => '<td class="maximal" scope="row"><a href="' . |
---|
136 | $this->core->getPostAdminURL($this->rs->post_type, $this->rs->post_id) . '">' . |
---|
137 | html::escapeHTML($this->rs->post_title) . '</a></td>', |
---|
138 | 'date' => '<td class="nowrap">' . dt::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->post_dt) . '</td>', |
---|
139 | 'author' => '<td class="nowrap">' . $this->rs->user_id . '</td>', |
---|
140 | 'comments' => '<td class="nowrap count">' . $this->rs->nb_comment . '</td>', |
---|
141 | 'trackbacks' => '<td class="nowrap count">' . $this->rs->nb_trackback . '</td>', |
---|
142 | 'status' => '<td class="nowrap status">' . $img_status . ' ' . $selected . ' ' . $protected . ' ' . $attach . '</td>' |
---|
143 | ); |
---|
144 | |
---|
145 | $cols = new ArrayObject($cols); |
---|
146 | $this->core->callBehavior('adminPagesListValue', $this->core, $this->rs, $cols); |
---|
147 | |
---|
148 | // Cope with optional columns |
---|
149 | $this->userColumns('pages', $cols); |
---|
150 | |
---|
151 | $res .= implode(iterator_to_array($cols)); |
---|
152 | $res .= '</tr>'; |
---|
153 | |
---|
154 | return $res; |
---|
155 | } |
---|
156 | } |
---|