Dotclear

source: admin/blogs.php @ 3400:765789715255

Revision 3400:765789715255, 6.5 KB checked in by Jean-Christian Denis, 9 years ago (diff)

Add blog status to Blogs filters, addresses #1566

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
13require dirname(__FILE__).'/../inc/admin/prepend.php';
14
15dcPage::check('usage,contentadmin');
16
17# Filters
18$status_combo = array_merge(
19     array('-' => ''),
20     dcAdminCombos::getBlogStatusesCombo()
21);
22
23$sortby_combo = array(
24__('Last update') => 'blog_upddt',
25__('Blog name') => 'UPPER(blog_name)',
26__('Blog ID') => 'B.blog_id',
27__('Status') => 'blog_status'
28);
29
30$order_combo = array(
31__('Descending') => 'desc',
32__('Ascending') => 'asc'
33);
34
35$q = !empty($_GET['q']) ? $_GET['q'] : '';
36$status = isset($_GET['status']) ? $_GET['status'] : '';
37$sortby = !empty($_GET['sortby']) ? $_GET['sortby'] : 'blog_upddt';
38$order = !empty($_GET['order']) ? $_GET['order'] : 'desc';
39
40$show_filters = false;
41
42$page = !empty($_GET['page']) ? max(1,(integer) $_GET['page']) : 1;
43$nb_per_page =  30;
44
45if (!empty($_GET['nb']) && (integer) $_GET['nb'] > 0) {
46     if ($nb_per_page != $_GET['nb']) {
47          $show_filters = true;
48     }
49     $nb_per_page = (integer) $_GET['nb'];
50}
51
52# - Search filter
53if ($q) {
54     $params['q'] = $q;
55     $show_filters = true;
56}
57
58# - Status filter
59if ($status !== '' && in_array($status,$status_combo)) {
60     $params['blog_status'] = $status;
61     $show_filters = true;
62} else {
63     $status='';
64}
65
66# - Sortby and order filter
67if ($sortby !== '' && in_array($sortby,$sortby_combo)) {
68     if ($order !== '' && in_array($order,$order_combo)) {
69          $params['order'] = $sortby.' '.$order;
70     }
71
72     if ($sortby != 'blog_upddt' || $order != 'desc') {
73          $show_filters = true;
74     }
75}
76
77$params['limit'] = array((($page-1)*$nb_per_page),$nb_per_page);
78
79try {
80     $counter = $core->getBlogs($params,1);
81     $rs = $core->getBlogs($params);
82     $nb_blog = $counter->f(0);
83     $rsStatic = $rs->toStatic();
84     if ($sortby != 'blog_upddt') {
85          // Sort blog list using lexical order if necessary
86          $rsStatic->extend('rsExtUser');
87          $rsStatic = $rsStatic->toExtStatic();
88          $rsStatic->lexicalSort(($sortby == 'UPPER(blog_name)' ? 'blog_name' : 'blog_id'),$order);
89     }
90} catch (Exception $e) {
91     $core->error->add($e->getMessage());
92}
93
94/* DISPLAY
95-------------------------------------------------------- */
96
97dcPage::open(__('List of blogs'),
98     dcPage::jsFilterControl($show_filters),
99     dcPage::breadcrumb(
100          array(
101               __('System') => '',
102               __('List of blogs') => ''
103          ))
104);
105
106if (!empty($_GET['del'])) {
107     dcPage::success(__('Blog has been successfully deleted.'));
108}
109
110if (!$core->error->flag())
111{
112     if ($core->auth->isSuperAdmin()) {
113          echo '<p class="top-add"><a class="button add" href="'.$core->adminurl->get("admin.blog").'">'.__('Create a new blog').'</a></p>';
114     }
115
116     echo
117     '<form action="'.$core->adminurl->get("admin.blogs").'" method="get" id="filters-form">'.
118     '<h3 class="out-of-screen-if-js">'.__('Show filters and display options').'</h3>'.
119
120     '<div class="table">'.
121     '<div class="cell">'.
122     '<h4>'.__('Filters').'</h4>'.
123     '<p><label for="q" class="ib">'.__('Search:').'</label> '.
124     form::field('q',20,255,html::escapeHTML($q)).'</p>'.
125     '<p><label for="status" class="ib">'.__('Status:').'</label> '.
126     form::combo('status',$status_combo,$status).'</p>'.
127     '</div>'.
128
129     '<div class="cell filters-options">'.
130     '<h4>'.__('Display options').'</h4>'.
131     '<p><label for="sortby" class="ib">'.__('Order by:').'</label> '.
132     form::combo('sortby',$sortby_combo,html::escapeHTML($sortby)).'</p>'.
133     '<p><label for="order" class="ib">'.__('Sort:').'</label> '.
134     form::combo('order',$order_combo,html::escapeHTML($order)).'</p>'.
135     '<p><span class="label ib">'.__('Show').'</span> <label for="nb" class="classic">'.
136     form::field('nb',3,3,$nb_per_page).' '.__('blogs per page').'</label></p>'.
137     '</div>'.
138     '</div>'.
139
140     '<p><input type="submit" value="'.__('Apply filters and display options').'" />'.
141     '<br class="clear" /></p>'. //Opera sucks
142     '</form>';
143
144     # Show blogs
145     if ($nb_blog == 0)
146     {
147          if( $show_filters ) {
148               echo '<p><strong>'.__('No blog matches the filter').'</strong></p>';
149          } else {
150               echo '<p><strong>'.__('No blog').'</strong></p>';
151          }
152     }
153     else
154     {
155          $pager = new dcPager($page,$nb_blog,$nb_per_page,10);
156
157          echo $pager->getLinks();
158
159          echo
160          '<div class="table-outer">'.
161          '<table class="clear">';
162
163          if( $show_filters ) {
164               echo '<caption>'.sprintf(__('%d blog matches the filter.','%d blogs match the filter.',$nb_blog),$nb_blog).'</caption>';
165          } else {
166               echo '<caption class="hidden">'.__('Blogs list').'</caption>';
167          }
168
169          echo
170          '<tr>'.
171          '<th scope="col" class="nowrap">'.__('Blog id').'</th>'.
172          '<th scope="col">'.__('Blog name').'</th>'.
173          '<th scope="col" class="nowrap">'.__('URL').'</th>'.
174          '<th scope="col" class="nowrap">'.__('Entries (all types)').'</th>'.
175          '<th scope="col" class="nowrap">'.__('Last update').'</th>'.
176          '<th scope="col" class="nowrap">'.__('Status').'</th>'.
177          '</tr>';
178
179          while ($rsStatic->fetch()) {
180               echo blogLine($rsStatic);
181          }
182
183          echo '</table></div>';
184
185          echo $pager->getLinks();
186     }
187}
188dcPage::helpBlock('core_blogs');
189dcPage::close();
190
191function blogLine($rs)
192{
193     global $core;
194
195     $blog_id = html::escapeHTML($rs->blog_id);
196     $edit_link = '';
197
198     if ($GLOBALS['core']->auth->isSuperAdmin()) {
199          $edit_link =
200          '<a href="'.$core->adminurl->get("admin.blog",array('id' => $blog_id)).'"  title="'.sprintf(__('Edit blog settings for %s'),$blog_id).'">'.
201          '<img src="images/edit-mini.png" alt="'.__('Edit blog settings').'" /> '.$blog_id.'</a> ';
202     } else {
203          $edit_link = $blog_id;
204     }
205
206     $img_status = $rs->blog_status == 1 ? 'check-on' : ($rs->blog_status == 0 ? 'check-off' : 'check-wrn');
207     $txt_status = $GLOBALS['core']->getBlogStatus($rs->blog_status);
208     $img_status = sprintf('<img src="images/%1$s.png" alt="%2$s" title="%2$s" />',$img_status,$txt_status);
209     $offset = dt::getTimeOffset($core->auth->getInfo('user_tz'));
210     $blog_upddt = dt::str(__('%Y-%m-%d %H:%M'),strtotime($rs->blog_upddt) + $offset);
211
212     return
213     '<tr class="line">'.
214     '<td class="nowrap">'.$edit_link.'</td>'.
215     '<td class="maximal"><a href="'.$core->adminurl->get("admin.home",array('switchblog' => $rs->blog_id)).'" '.
216     'title="'.sprintf(__('Switch to blog %s'),$rs->blog_id).'">'.
217     html::escapeHTML($rs->blog_name).'</a></td>'.
218     '<td class="nowrap"><a class="outgoing" href="'.html::escapeHTML($rs->blog_url).'">'.html::escapeHTML($rs->blog_url).
219     ' <img src="images/outgoing-blue.png" alt="" /></a></td>'.
220     '<td class="nowrap count">'.$core->countBlogPosts($rs->blog_id).'</td>'.
221     '<td class="nowrap count">'.$blog_upddt.'</td>'.
222     '<td class="status">'.$img_status.'</td>'.
223     '</tr>';
224}
Note: See TracBrowser for help on using the repository browser.

Sites map