[2055] | 1 | <?php |
---|
[3731] | 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 | */ |
---|
[2055] | 11 | |
---|
| 12 | /* Pager class |
---|
| 13 | -------------------------------------------------------- */ |
---|
[2232] | 14 | class adminPagesList extends adminGenericList |
---|
[2055] | 15 | { |
---|
[3707] | 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); |
---|
[3874] | 22 | $entries = []; |
---|
[3707] | 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>'; |
---|
[3089] | 31 | |
---|
[3874] | 32 | $cols = [ |
---|
[3707] | 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>' |
---|
[3874] | 41 | ]; |
---|
[3089] | 42 | |
---|
[3707] | 43 | $cols = new ArrayObject($cols); |
---|
| 44 | $this->core->callBehavior('adminPagesListHeader', $this->core, $this->rs, $cols); |
---|
[3089] | 45 | |
---|
[3707] | 46 | // Cope with optional columns |
---|
| 47 | $this->userColumns('pages', $cols); |
---|
[3265] | 48 | |
---|
[3707] | 49 | $html_block .= '<tr>' . implode(iterator_to_array($cols)) . |
---|
| 50 | '</tr></thead><tbody id="pageslist">%s</tbody></table></div>'; |
---|
[2566] | 51 | |
---|
[3707] | 52 | if ($enclose_block) { |
---|
| 53 | $html_block = sprintf($enclose_block, $html_block); |
---|
| 54 | } |
---|
[2566] | 55 | |
---|
[3707] | 56 | echo $pager->getLinks(); |
---|
[2566] | 57 | |
---|
[3707] | 58 | $blocks = explode('%s', $html_block); |
---|
[2566] | 59 | |
---|
[3707] | 60 | echo $blocks[0]; |
---|
[2566] | 61 | |
---|
[3707] | 62 | $count = 0; |
---|
| 63 | while ($this->rs->fetch()) { |
---|
| 64 | echo $this->postLine($count, isset($entries[$this->rs->post_id])); |
---|
| 65 | $count++; |
---|
| 66 | } |
---|
[2566] | 67 | |
---|
[3707] | 68 | echo $blocks[1]; |
---|
[2566] | 69 | |
---|
[3707] | 70 | echo $pager->getLinks(); |
---|
| 71 | } |
---|
| 72 | } |
---|
[2566] | 73 | |
---|
[3707] | 74 | private function postLine($count, $checked) |
---|
| 75 | { |
---|
[3774] | 76 | $img = '<img alt="%1$s" title="%1$s" src="images/%2$s" class="mark mark-%3$s" />'; |
---|
[3707] | 77 | $sts_class = ''; |
---|
| 78 | switch ($this->rs->post_status) { |
---|
| 79 | case 1: |
---|
[3774] | 80 | $img_status = sprintf($img, __('Published'), 'check-on.png', 'published'); |
---|
[3707] | 81 | $sts_class = 'sts-online'; |
---|
| 82 | break; |
---|
| 83 | case 0: |
---|
[3774] | 84 | $img_status = sprintf($img, __('Unpublished'), 'check-off.png', 'unpublished'); |
---|
[3707] | 85 | $sts_class = 'sts-offline'; |
---|
| 86 | break; |
---|
| 87 | case -1: |
---|
[3774] | 88 | $img_status = sprintf($img, __('Scheduled'), 'scheduled.png', 'scheduled'); |
---|
[3707] | 89 | $sts_class = 'sts-scheduled'; |
---|
| 90 | break; |
---|
| 91 | case -2: |
---|
[3774] | 92 | $img_status = sprintf($img, __('Pending'), 'check-wrn.png', 'pending'); |
---|
[3707] | 93 | $sts_class = 'sts-pending'; |
---|
| 94 | break; |
---|
| 95 | } |
---|
[2566] | 96 | |
---|
[3707] | 97 | $protected = ''; |
---|
| 98 | if ($this->rs->post_password) { |
---|
[3774] | 99 | $protected = sprintf($img, __('Protected'), 'locker.png', 'locked'); |
---|
[3707] | 100 | } |
---|
[2566] | 101 | |
---|
[3707] | 102 | $selected = ''; |
---|
| 103 | if ($this->rs->post_selected) { |
---|
[3774] | 104 | $selected = sprintf($img, __('Hidden'), 'hidden.png', 'hidden'); |
---|
[3707] | 105 | } |
---|
[2566] | 106 | |
---|
[3707] | 107 | $attach = ''; |
---|
| 108 | $nb_media = $this->rs->countMedia(); |
---|
| 109 | if ($nb_media > 0) { |
---|
| 110 | $attach_str = $nb_media == 1 ? __('%d attachment') : __('%d attachments'); |
---|
[3774] | 111 | $attach = sprintf($img, sprintf($attach_str, $nb_media), 'attach.png', 'attach'); |
---|
[3707] | 112 | } |
---|
[2566] | 113 | |
---|
[3707] | 114 | $res = '<tr class="line ' . ($this->rs->post_status != 1 ? 'offline ' : '') . $sts_class . '"' . |
---|
| 115 | ' id="p' . $this->rs->post_id . '">'; |
---|
[2566] | 116 | |
---|
[3874] | 117 | $cols = [ |
---|
[3707] | 118 | 'position' => '<td class="nowrap handle minimal">' . |
---|
[3874] | 119 | form::number(['order[' . $this->rs->post_id . ']'], [ |
---|
[3725] | 120 | 'min' => 1, |
---|
| 121 | 'default' => $count + 1, |
---|
| 122 | 'class' => 'position', |
---|
| 123 | 'extra_html' => 'title="' . sprintf(__('position of %s'), html::escapeHTML($this->rs->post_title)) . '"' |
---|
[3874] | 124 | ]) . |
---|
[3725] | 125 | '</td>', |
---|
[3707] | 126 | 'check' => '<td class="nowrap">' . |
---|
[3874] | 127 | form::checkbox(['entries[]'], $this->rs->post_id, |
---|
| 128 | [ |
---|
[3707] | 129 | 'checked' => $checked, |
---|
| 130 | 'disabled' => !$this->rs->isEditable(), |
---|
| 131 | 'extra_html' => 'title="' . __('Select this page') . '"' |
---|
[3874] | 132 | ] |
---|
[3707] | 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>' |
---|
[3874] | 142 | ]; |
---|
[3089] | 143 | |
---|
[3707] | 144 | $cols = new ArrayObject($cols); |
---|
| 145 | $this->core->callBehavior('adminPagesListValue', $this->core, $this->rs, $cols); |
---|
[3089] | 146 | |
---|
[3707] | 147 | // Cope with optional columns |
---|
| 148 | $this->userColumns('pages', $cols); |
---|
[3265] | 149 | |
---|
[3707] | 150 | $res .= implode(iterator_to_array($cols)); |
---|
| 151 | $res .= '</tr>'; |
---|
[2566] | 152 | |
---|
[3707] | 153 | return $res; |
---|
| 154 | } |
---|
[2055] | 155 | } |
---|