Dotclear

source: plugins/pages/list.php @ 1107:3943962d69b8

Revision 1107:3943962d69b8, 5.7 KB checked in by JcDenis, 12 years ago (diff)

merge with default branch in 2.5-RC

Line 
1<?php
2# -- BEGIN LICENSE BLOCK ---------------------------------------
3#
4# This file is part of Dotclear 2.
5#
6# Copyright (c) 2003-2011 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_CONTEXT_ADMIN')) { return; }
13dcPage::check('pages,contentadmin');
14
15/* Pager class
16-------------------------------------------------------- */
17class adminPageList extends adminGenericList
18{
19     public function display($page,$nb_per_page,$enclose_block='')
20     {
21          if ($this->rs->isEmpty())
22          {
23               echo '<p><strong>'.__('No page').'</strong></p>';
24          }
25          else
26          {
27               $pager = new pager($page,$this->rs_count,$nb_per_page,10);
28               $pager->html_prev = $this->html_prev;
29               $pager->html_next = $this->html_next;
30               $pager->var_page = 'page';
31               
32               $html_block =
33               '<table class="clear"><tr>'.
34               '<th colspan="2">'.__('Title').'</th>'.
35               '<th>'.__('Date').'</th>'.
36               '<th>'.__('Author').'</th>'.
37               '<th>'.__('Comments').'</th>'.
38               '<th>'.__('Trackbacks').'</th>'.
39               '<th>'.__('Status').'</th>'.
40               '</tr>%s</table>';
41               
42               if ($enclose_block) {
43                    $html_block = sprintf($enclose_block,$html_block);
44               }
45               
46               echo '<p>'.__('Page(s)').' : '.$pager->getLinks().'</p>';
47               
48               $blocks = explode('%s',$html_block);
49               
50               echo $blocks[0];
51               
52               while ($this->rs->fetch())
53               {
54                    echo $this->postLine();
55               }
56               
57               echo $blocks[1];
58               
59               echo '<p>'.__('Page(s)').' : '.$pager->getLinks().'</p>';
60          }
61     }
62     
63     private function postLine()
64     {
65          $img = '<img alt="%1$s" title="%1$s" src="images/%2$s" />';
66          switch ($this->rs->post_status) {
67               case 1:
68                    $img_status = sprintf($img,__('published'),'check-on.png');
69                    break;
70               case 0:
71                    $img_status = sprintf($img,__('unpublished'),'check-off.png');
72                    break;
73               case -1:
74                    $img_status = sprintf($img,__('scheduled'),'scheduled.png');
75                    break;
76               case -2:
77                    $img_status = sprintf($img,__('pending'),'check-wrn.png');
78                    break;
79          }
80         
81          $selected = '';
82          if ($this->rs->post_selected) {
83               $selected = sprintf($img,__('hidden'),'hidden.png');
84          }
85         
86          $attach = '';
87          $nb_media = $this->rs->countMedia();
88          if ($nb_media > 0) {
89               $attach_str = $nb_media == 1 ? __('%d attachment') : __('%d attachments');
90               $attach = sprintf($img,sprintf($attach_str,$nb_media),'attach.png');
91          }
92         
93          $res = '<tr class="line'.($this->rs->post_status != 1 ? ' offline' : '').'"'.
94          ' id="p'.$this->rs->post_id.'">';
95         
96          $res .=
97          '<td class="nowrap">'.
98          form::checkbox(array('entries[]'),$this->rs->post_id,'','','',!$this->rs->isEditable(),'title="'.__('select this page').'"').'</td>'.
99          '<td class="maximal"><a href="'.$this->core->getPostAdminURL($this->rs->post_type,$this->rs->post_id).'">'.
100          html::escapeHTML($this->rs->post_title).'</a></td>'.
101          '<td class="nowrap">'.dt::dt2str(__('%Y-%m-%d %H:%M'),$this->rs->post_dt).'</td>'.
102         
103          '<td class="nowrap">'.$this->rs->user_id.'</td>'.
104          '<td class="nowrap">'.$this->rs->nb_comment.'</td>'.
105          '<td class="nowrap">'.$this->rs->nb_trackback.'</td>'.
106          '<td class="nowrap status">'.$img_status.' '.$selected.' '.$attach.'</td>'.
107          '</tr>';
108         
109          return $res;
110     }
111}
112
113/* Getting pages
114-------------------------------------------------------- */
115$params = array(
116     'post_type' => 'page'
117);
118
119$page = !empty($_GET['page']) ? (integer) $_GET['page'] : 1;
120$nb_per_page =  30;
121
122if (!empty($_GET['nb']) && (integer) $_GET['nb'] > 0) {
123     $nb_per_page = (integer) $_GET['nb'];
124}
125
126$params['limit'] = array((($page-1)*$nb_per_page),$nb_per_page);
127$params['no_content'] = true;
128$params['order'] = 'post_position ASC, post_title ASC';
129
130try {
131     $pages = $core->blog->getPosts($params);
132     $counter = $core->blog->getPosts($params,true);
133     $post_list = new adminPageList($core,$pages,$counter->f(0));
134} catch (Exception $e) {
135     $core->error->add($e->getMessage());
136}
137
138# Actions combo box
139$combo_action = array();
140if ($core->auth->check('publish,contentadmin',$core->blog->id))
141{
142     $combo_action[__('publish')] = 'publish';
143     $combo_action[__('unpublish')] = 'unpublish';
144     $combo_action[__('schedule')] = 'schedule';
145     $combo_action[__('mark as pending')] = 'pending';
146}
147if ($core->auth->check('admin',$core->blog->id)) {
148     $combo_action[__('change author')] = 'author';
149}
150if ($core->auth->check('delete,contentadmin',$core->blog->id))
151{
152     $combo_action[__('delete')] = 'delete';
153}
154
155# --BEHAVIOR-- adminPagesActionsCombo
156$core->callBehavior('adminPagesActionsCombo',array(&$combo_action));
157
158/* Display
159-------------------------------------------------------- */
160?>
161<html>
162<head>
163  <title><?php echo __('Pages'); ?></title>
164  <script type="text/javascript" src="js/_posts_list.js"></script>
165  <script type="text/javascript">
166  //<![CDATA[
167  <?php echo dcPage::jsVar('dotclear.msg.confirm_delete_posts',__("Are you sure you want to delete selected pages?")); ?>
168  //]]>
169  </script>
170</head>
171
172<body>
173<?php
174echo '<h2>'.html::escapeHTML($core->blog->name).' &rsaquo; <span class="page-title">'.__('Pages').'</span></h2>'.
175'<p class="top-add"><a class="button add" href="'.$p_url.'&amp;act=page">'.__('New page').'</a></p>';
176
177if (!$core->error->flag())
178{
179     # Show pages
180     $post_list->display($page,$nb_per_page,
181     '<form action="posts_actions.php" method="post" id="form-entries">'.
182     
183     '%s'.
184     
185     '<div class="two-cols">'.
186     '<p class="col checkboxes-helpers"></p>'.
187     
188     '<p class="col right"><label for="action" class="classic">'.__('Selected pages action:').'</label> '.
189     form::combo('action',$combo_action).
190     '<input type="submit" value="'.__('ok').'" /></p>'.
191     form::hidden(array('post_type'),'page').
192     form::hidden(array('redir'),html::escapeHTML($_SERVER['REQUEST_URI'])).
193     $core->formNonce().
194     '</div>'.
195     '</form>');
196}
197dcPage::helpBlock('pages');
198?>
199</body>
200</html>
Note: See TracBrowser for help on using the repository browser.

Sites map