[0] | 1 | <?php |
---|
| 2 | # -- BEGIN LICENSE BLOCK --------------------------------------- |
---|
| 3 | # |
---|
| 4 | # This file is part of Dotclear 2. |
---|
| 5 | # |
---|
[1179] | 6 | # Copyright (c) 2003-2013 Olivier Meunier & Association Dotclear |
---|
[0] | 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'; |
---|
[2145] | 32 | |
---|
[2137] | 33 | $show_filters = false; |
---|
[0] | 34 | |
---|
[1912] | 35 | $page = !empty($_GET['page']) ? max(1,(integer) $_GET['page']) : 1; |
---|
[0] | 36 | $nb_per_page = 30; |
---|
| 37 | |
---|
| 38 | if (!empty($_GET['nb']) && (integer) $_GET['nb'] > 0) { |
---|
[2137] | 39 | if ($nb_per_page != $_GET['nb']) { |
---|
| 40 | $show_filters = true; |
---|
| 41 | } |
---|
[792] | 42 | $nb_per_page = (integer) $_GET['nb']; |
---|
[0] | 43 | } |
---|
| 44 | |
---|
| 45 | # - Search filter |
---|
| 46 | if ($q) { |
---|
| 47 | $params['q'] = $q; |
---|
| 48 | $show_filters = true; |
---|
| 49 | } |
---|
| 50 | |
---|
| 51 | # - Sortby and order filter |
---|
| 52 | if ($sortby !== '' && in_array($sortby,$sortby_combo)) { |
---|
| 53 | if ($order !== '' && in_array($order,$order_combo)) { |
---|
| 54 | $params['order'] = $sortby.' '.$order; |
---|
| 55 | } |
---|
| 56 | |
---|
| 57 | if ($sortby != 'blog_upddt' || $order != 'desc') { |
---|
| 58 | $show_filters = true; |
---|
| 59 | } |
---|
| 60 | } |
---|
| 61 | |
---|
| 62 | $params['limit'] = array((($page-1)*$nb_per_page),$nb_per_page); |
---|
| 63 | |
---|
| 64 | try { |
---|
| 65 | $counter = $core->getBlogs($params,1); |
---|
| 66 | $rs = $core->getBlogs($params); |
---|
| 67 | $nb_blog = $counter->f(0); |
---|
| 68 | } catch (Exception $e) { |
---|
| 69 | $core->error->add($e->getMessage()); |
---|
| 70 | } |
---|
| 71 | |
---|
| 72 | /* DISPLAY |
---|
| 73 | -------------------------------------------------------- */ |
---|
[2136] | 74 | |
---|
[2145] | 75 | $form_filter_title = __('Show filters and display options'); |
---|
[2135] | 76 | $starting_script = dcPage::jsLoad('js/filter-controls.js'); |
---|
| 77 | $starting_script .= |
---|
| 78 | '<script type="text/javascript">'."\n". |
---|
| 79 | "//<![CDATA["."\n". |
---|
| 80 | dcPage::jsVar('dotclear.msg.show_filters', $show_filters ? 'true':'false')."\n". |
---|
| 81 | dcPage::jsVar('dotclear.msg.filter_posts_list',$form_filter_title)."\n". |
---|
[2145] | 82 | dcPage::jsVar('dotclear.msg.cancel_the_filter',__('Cancel filters and display options'))."\n". |
---|
[2135] | 83 | "//]]>". |
---|
| 84 | "</script>"; |
---|
| 85 | |
---|
[1358] | 86 | dcPage::open(__('List of blogs'),$starting_script, |
---|
| 87 | dcPage::breadcrumb( |
---|
| 88 | array( |
---|
| 89 | __('System') => '', |
---|
| 90 | '<span class="page-title">'.__('List of blogs').'</span>' => '' |
---|
| 91 | )) |
---|
| 92 | ); |
---|
[0] | 93 | |
---|
| 94 | if (!empty($_GET['del'])) { |
---|
[1553] | 95 | dcPage::success(__('Blog has been successfully deleted.')); |
---|
[0] | 96 | } |
---|
| 97 | |
---|
| 98 | if (!$core->error->flag()) |
---|
| 99 | { |
---|
| 100 | if ($core->auth->isSuperAdmin()) { |
---|
[158] | 101 | echo '<p class="top-add"><a class="button add" href="blog.php">'.__('Create a new blog').'</a></p>'; |
---|
[0] | 102 | } |
---|
| 103 | |
---|
| 104 | echo |
---|
| 105 | '<form action="blogs.php" method="get" id="filters-form">'. |
---|
[1514] | 106 | '<h3 class="hidden">'.__('Filter blogs list').'</h3>'. |
---|
[0] | 107 | |
---|
[1420] | 108 | '<div class="table">'. |
---|
| 109 | '<div class="cell">'. |
---|
[1514] | 110 | '<h4>'.__('Filters').'</h4>'. |
---|
[1420] | 111 | '<p><label for="q" class="ib">'.__('Search:').'</label> '. |
---|
| 112 | form::field('q',20,255,html::escapeHTML($q)).'</p>'. |
---|
[0] | 113 | '</div>'. |
---|
| 114 | |
---|
[1420] | 115 | '<div class="cell filters-options">'. |
---|
[1514] | 116 | '<h4>'.__('Display options').'</h4>'. |
---|
[1420] | 117 | '<p><label for="sortby" class="ib">'.__('Order by:').'</label> '. |
---|
| 118 | form::combo('sortby',$sortby_combo,html::escapeHTML($sortby)).'</p>'. |
---|
| 119 | '<p><label for="order" class="ib">'.__('Sort:').'</label> '. |
---|
| 120 | form::combo('order',$order_combo,html::escapeHTML($order)).'</p>'. |
---|
[1426] | 121 | '<p><span class="label ib">'.__('Show').'</span> <label for="nb" class="classic">'. |
---|
[1420] | 122 | form::field('nb',3,3,$nb_per_page).' '.__('blogs per page').'</label></p>'. |
---|
[0] | 123 | '</div>'. |
---|
[1420] | 124 | '</div>'. |
---|
| 125 | |
---|
[1514] | 126 | '<p><input type="submit" value="'.__('Apply filters and display options').'" />'. |
---|
[1424] | 127 | '<br class="clear" /></p>'. //Opera sucks |
---|
[0] | 128 | '</form>'; |
---|
| 129 | |
---|
| 130 | # Show blogs |
---|
| 131 | if ($nb_blog == 0) |
---|
| 132 | { |
---|
[2135] | 133 | if( $show_filters ) { |
---|
| 134 | echo '<p><strong>'.__('No blog matches the filter').'</strong></p>'; |
---|
| 135 | } else { |
---|
| 136 | echo '<p><strong>'.__('No blog').'</strong></p>'; |
---|
| 137 | } |
---|
[0] | 138 | } |
---|
| 139 | else |
---|
| 140 | { |
---|
[1926] | 141 | $pager = new dcPager($page,$nb_blog,$nb_per_page,10); |
---|
[0] | 142 | |
---|
[1926] | 143 | echo $pager->getLinks(); |
---|
[0] | 144 | |
---|
| 145 | echo |
---|
[2002] | 146 | '<div class="table-outer">'. |
---|
[2135] | 147 | '<table class="clear">'; |
---|
| 148 | |
---|
| 149 | if( $show_filters ) { |
---|
| 150 | echo '<caption>'.sprintf(__('List of %s blogs match the filter.'), $nb_blog).'</caption>'; |
---|
| 151 | } else { |
---|
| 152 | echo '<caption class="hidden">'.__('Blogs list').'</caption>'; |
---|
| 153 | } |
---|
| 154 | |
---|
| 155 | echo |
---|
| 156 | '<tr>'. |
---|
[1668] | 157 | '<th scope="col" class="nowrap">'.__('Blog id').'</th>'. |
---|
| 158 | '<th scope="col">'.__('Blog name').'</th>'. |
---|
| 159 | '<th scope="col" class="nowrap">'.__('Entries (all types)').'</th>'. |
---|
| 160 | '<th scope="col" class="nowrap">'.__('Last update').'</th>'. |
---|
| 161 | '<th scope="col" class="nowrap">'.__('Status').'</th>'. |
---|
[0] | 162 | '</tr>'; |
---|
| 163 | |
---|
| 164 | while ($rs->fetch()) { |
---|
| 165 | echo blogLine($rs); |
---|
| 166 | } |
---|
| 167 | |
---|
[2002] | 168 | echo '</table></div>'; |
---|
[0] | 169 | |
---|
[1926] | 170 | echo $pager->getLinks(); |
---|
[0] | 171 | } |
---|
| 172 | } |
---|
| 173 | |
---|
| 174 | dcPage::close(); |
---|
| 175 | |
---|
| 176 | function blogLine($rs) |
---|
| 177 | { |
---|
| 178 | global $core; |
---|
| 179 | |
---|
| 180 | $blog_id = html::escapeHTML($rs->blog_id); |
---|
| 181 | $edit_link = ''; |
---|
| 182 | |
---|
| 183 | if ($GLOBALS['core']->auth->isSuperAdmin()) { |
---|
| 184 | $edit_link = |
---|
[1668] | 185 | '<a href="blog.php?id='.$blog_id.'" title="'.sprintf(__('Edit blog settings for %s'),$blog_id).'">'. |
---|
| 186 | '<img src="images/edit-mini.png" alt="'.__('Edit blog settings').'" /> '.$blog_id.'</a> '; |
---|
[2107] | 187 | } else { |
---|
| 188 | $edit_link = $blog_id; |
---|
[0] | 189 | } |
---|
| 190 | |
---|
| 191 | $img_status = $rs->blog_status == 1 ? 'check-on' : 'check-off'; |
---|
| 192 | $txt_status = $GLOBALS['core']->getBlogStatus($rs->blog_status); |
---|
| 193 | $img_status = sprintf('<img src="images/%1$s.png" alt="%2$s" title="%2$s" />',$img_status,$txt_status); |
---|
| 194 | $offset = dt::getTimeOffset($core->auth->getInfo('user_tz')); |
---|
| 195 | $blog_upddt = dt::str(__('%Y-%m-%d %H:%M'),strtotime($rs->blog_upddt) + $offset); |
---|
| 196 | |
---|
| 197 | return |
---|
| 198 | '<tr class="line">'. |
---|
[1668] | 199 | '<td class="nowrap">'.$edit_link.'</td>'. |
---|
[0] | 200 | '<td class="maximal"><a href="index.php?switchblog='.$rs->blog_id.'" '. |
---|
| 201 | 'title="'.sprintf(__('Switch to blog %s'),$rs->blog_id).'">'. |
---|
| 202 | html::escapeHTML($rs->blog_name).'</a></td>'. |
---|
[1668] | 203 | '<td class="nowrap count">'.$core->countBlogPosts($rs->blog_id).'</td>'. |
---|
| 204 | '<td class="nowrap count">'.$blog_upddt.'</td>'. |
---|
[0] | 205 | '<td class="status">'.$img_status.'</td>'. |
---|
| 206 | '</tr>'; |
---|
| 207 | } |
---|
| 208 | ?> |
---|