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 | require dirname(__FILE__).'/../inc/admin/prepend.php'; |
---|
14 | |
---|
15 | dcPage::check('usage,contentadmin'); |
---|
16 | |
---|
17 | # Filters |
---|
18 | $sortby_combo = array( |
---|
19 | __('Last update') => 'blog_upddt', |
---|
20 | __('Blog name') => 'UPPER(blog_name)', |
---|
21 | __('Blog ID') => 'B.blog_id' |
---|
22 | ); |
---|
23 | |
---|
24 | $order_combo = array( |
---|
25 | __('Descending') => 'desc', |
---|
26 | __('Ascending') => 'asc' |
---|
27 | ); |
---|
28 | |
---|
29 | $q = !empty($_GET['q']) ? $_GET['q'] : ''; |
---|
30 | $sortby = !empty($_GET['sortby']) ? $_GET['sortby'] : 'blog_upddt'; |
---|
31 | $order = !empty($_GET['order']) ? $_GET['order'] : 'desc'; |
---|
32 | |
---|
33 | $page = !empty($_GET['page']) ? $_GET['page'] : 1; |
---|
34 | $nb_per_page = 30; |
---|
35 | |
---|
36 | if (!empty($_GET['nb']) && (integer) $_GET['nb'] > 0) { |
---|
37 | $nb_per_page = (integer) $_GET['nb']; |
---|
38 | } |
---|
39 | |
---|
40 | $show_filters = false; |
---|
41 | |
---|
42 | # - Search filter |
---|
43 | if ($q) { |
---|
44 | $params['q'] = $q; |
---|
45 | $show_filters = true; |
---|
46 | } |
---|
47 | |
---|
48 | # - Sortby and order filter |
---|
49 | if ($sortby !== '' && in_array($sortby,$sortby_combo)) { |
---|
50 | if ($order !== '' && in_array($order,$order_combo)) { |
---|
51 | $params['order'] = $sortby.' '.$order; |
---|
52 | } |
---|
53 | |
---|
54 | if ($sortby != 'blog_upddt' || $order != 'desc') { |
---|
55 | $show_filters = true; |
---|
56 | } |
---|
57 | } |
---|
58 | |
---|
59 | $params['limit'] = array((($page-1)*$nb_per_page),$nb_per_page); |
---|
60 | |
---|
61 | try { |
---|
62 | $counter = $core->getBlogs($params,1); |
---|
63 | $rs = $core->getBlogs($params); |
---|
64 | $nb_blog = $counter->f(0); |
---|
65 | } catch (Exception $e) { |
---|
66 | $core->error->add($e->getMessage()); |
---|
67 | } |
---|
68 | |
---|
69 | /* DISPLAY |
---|
70 | -------------------------------------------------------- */ |
---|
71 | $starting_script = ''; |
---|
72 | if (!$show_filters) { |
---|
73 | $starting_script .= dcPage::jsLoad('js/filter-controls.js'); |
---|
74 | } |
---|
75 | dcPage::open(__('List of blogs'),$starting_script); |
---|
76 | |
---|
77 | if (!empty($_GET['del'])) { |
---|
78 | dcPage::message(__('Blog has been successfully deleted.')); |
---|
79 | } |
---|
80 | |
---|
81 | dcPage::breadcrumb( |
---|
82 | array( |
---|
83 | __('System') => '', |
---|
84 | '<span class="page-title">'.__('List of blogs').'</span>' => '' |
---|
85 | )); |
---|
86 | |
---|
87 | if (!$core->error->flag()) |
---|
88 | { |
---|
89 | if ($core->auth->isSuperAdmin()) { |
---|
90 | echo '<p class="top-add"><a class="button add" href="blog.php">'.__('Create a new blog').'</a></p>'; |
---|
91 | } |
---|
92 | |
---|
93 | if (!$show_filters) { |
---|
94 | echo '<p><a id="filter-control" class="form-control" href="#">'.__('Filters').'</a></p>'; |
---|
95 | } |
---|
96 | |
---|
97 | echo |
---|
98 | '<form action="blogs.php" method="get" id="filters-form">'. |
---|
99 | '<fieldset class="two-cols"><legend>'.__('Filters').'</legend>'. |
---|
100 | |
---|
101 | '<div class="col">'. |
---|
102 | '<p><label for="sortby">'.__('Order by:').' '. |
---|
103 | form::combo('sortby',$sortby_combo,html::escapeHTML($sortby)). |
---|
104 | '</label> '. |
---|
105 | '<label for="order">'.__('Sort:').' '. |
---|
106 | form::combo('order',$order_combo,html::escapeHTML($order)). |
---|
107 | '</label></p>'. |
---|
108 | '</div>'. |
---|
109 | |
---|
110 | '<div class="col">'. |
---|
111 | '<p><label for="q">'.__('Search:').' '. |
---|
112 | form::field('q',20,255,html::escapeHTML($q)). |
---|
113 | '</label></p>'. |
---|
114 | '<p><label for="nb" class="classic">'. form::field('nb',3,3,$nb_per_page).' '. |
---|
115 | __('Blogs per page').'</label> '. |
---|
116 | '<input type="submit" value="'.__('Apply filters').'" /></p>'. |
---|
117 | '</div>'. |
---|
118 | |
---|
119 | '<br class="clear" />'. //Opera sucks |
---|
120 | '</fieldset>'. |
---|
121 | '</form>'; |
---|
122 | |
---|
123 | # Show blogs |
---|
124 | if ($nb_blog == 0) |
---|
125 | { |
---|
126 | echo '<p><strong>'.__('No blog').'</strong></p>'; |
---|
127 | } |
---|
128 | else |
---|
129 | { |
---|
130 | $pager = new pager($page,$nb_blog,$nb_per_page,10); |
---|
131 | $pager->var_page = 'page'; |
---|
132 | |
---|
133 | echo '<p>'.__('Page(s)').' : '.$pager->getLinks().'</p>'; |
---|
134 | |
---|
135 | echo |
---|
136 | '<table class="clear"><tr>'. |
---|
137 | '<th>'.__('Blog name').'</th>'. |
---|
138 | '<th class="nowrap">'.__('Last update').'</th>'. |
---|
139 | '<th class="nowrap">'.__('Entries (all types)').'</th>'. |
---|
140 | '<th class="nowrap">'.__('Blog ID').'</th>'. |
---|
141 | '<th> </th>'. |
---|
142 | '<th class="nowrap">'.__('Status').'</th>'. |
---|
143 | '</tr>'; |
---|
144 | |
---|
145 | while ($rs->fetch()) { |
---|
146 | echo blogLine($rs); |
---|
147 | } |
---|
148 | |
---|
149 | echo '</table>'; |
---|
150 | |
---|
151 | echo '<p>'.__('Page(s)').' : '.$pager->getLinks().'</p>'; |
---|
152 | } |
---|
153 | } |
---|
154 | |
---|
155 | dcPage::close(); |
---|
156 | |
---|
157 | function blogLine($rs) |
---|
158 | { |
---|
159 | global $core; |
---|
160 | |
---|
161 | $blog_id = html::escapeHTML($rs->blog_id); |
---|
162 | $edit_link = ''; |
---|
163 | |
---|
164 | if ($GLOBALS['core']->auth->isSuperAdmin()) { |
---|
165 | $edit_link = |
---|
166 | '<a href="blog.php?id='.$blog_id.'" '. |
---|
167 | 'title="'.sprintf(__('Edit blog %s'),$blog_id).'">'. |
---|
168 | __('edit').'</a>'; |
---|
169 | } |
---|
170 | |
---|
171 | $img_status = $rs->blog_status == 1 ? 'check-on' : 'check-off'; |
---|
172 | $txt_status = $GLOBALS['core']->getBlogStatus($rs->blog_status); |
---|
173 | $img_status = sprintf('<img src="images/%1$s.png" alt="%2$s" title="%2$s" />',$img_status,$txt_status); |
---|
174 | $offset = dt::getTimeOffset($core->auth->getInfo('user_tz')); |
---|
175 | $blog_upddt = dt::str(__('%Y-%m-%d %H:%M'),strtotime($rs->blog_upddt) + $offset); |
---|
176 | |
---|
177 | return |
---|
178 | '<tr class="line">'. |
---|
179 | '<td class="maximal"><a href="index.php?switchblog='.$rs->blog_id.'" '. |
---|
180 | 'title="'.sprintf(__('Switch to blog %s'),$rs->blog_id).'">'. |
---|
181 | html::escapeHTML($rs->blog_name).'</a></td>'. |
---|
182 | '<td class="nowrap">'.$blog_upddt.'</td>'. |
---|
183 | '<td class="nowrap">'.$core->countBlogPosts($rs->blog_id).'</td>'. |
---|
184 | '<td class="nowrap">'.$blog_id.'</td>'. |
---|
185 | '<td>'.$edit_link.'</td>'. |
---|
186 | '<td class="status">'.$img_status.'</td>'. |
---|
187 | '</tr>'; |
---|
188 | } |
---|
189 | ?> |
---|