[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 | } |
---|
[2566] | 44 | |
---|
[0] | 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 | } |
---|
[2566] | 56 | |
---|
[0] | 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); |
---|
[3106] | 68 | $rsStatic = $rs->toStatic(); |
---|
| 69 | if ($sortby != 'blog_upddt') { |
---|
| 70 | // Sort blog list using lexical order if necessary |
---|
| 71 | $rsStatic->extend('rsExtUser'); |
---|
| 72 | $rsStatic = $rsStatic->toExtStatic(); |
---|
| 73 | $rsStatic->lexicalSort(($sortby == 'UPPER(blog_name)' ? 'blog_name' : 'blog_id'),$order); |
---|
| 74 | } |
---|
[0] | 75 | } catch (Exception $e) { |
---|
| 76 | $core->error->add($e->getMessage()); |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | /* DISPLAY |
---|
| 80 | -------------------------------------------------------- */ |
---|
[2136] | 81 | |
---|
[2145] | 82 | $form_filter_title = __('Show filters and display options'); |
---|
[2135] | 83 | $starting_script = dcPage::jsLoad('js/filter-controls.js'); |
---|
| 84 | $starting_script .= |
---|
| 85 | '<script type="text/javascript">'."\n". |
---|
| 86 | "//<![CDATA["."\n". |
---|
| 87 | dcPage::jsVar('dotclear.msg.show_filters', $show_filters ? 'true':'false')."\n". |
---|
| 88 | dcPage::jsVar('dotclear.msg.filter_posts_list',$form_filter_title)."\n". |
---|
[2145] | 89 | dcPage::jsVar('dotclear.msg.cancel_the_filter',__('Cancel filters and display options'))."\n". |
---|
[2135] | 90 | "//]]>". |
---|
| 91 | "</script>"; |
---|
| 92 | |
---|
[1358] | 93 | dcPage::open(__('List of blogs'),$starting_script, |
---|
| 94 | dcPage::breadcrumb( |
---|
| 95 | array( |
---|
| 96 | __('System') => '', |
---|
[2189] | 97 | __('List of blogs') => '' |
---|
[1358] | 98 | )) |
---|
| 99 | ); |
---|
[0] | 100 | |
---|
| 101 | if (!empty($_GET['del'])) { |
---|
[1553] | 102 | dcPage::success(__('Blog has been successfully deleted.')); |
---|
[0] | 103 | } |
---|
| 104 | |
---|
| 105 | if (!$core->error->flag()) |
---|
| 106 | { |
---|
| 107 | if ($core->auth->isSuperAdmin()) { |
---|
[2720] | 108 | echo '<p class="top-add"><a class="button add" href="'.$core->adminurl->get("admin.blog").'">'.__('Create a new blog').'</a></p>'; |
---|
[0] | 109 | } |
---|
[2566] | 110 | |
---|
[0] | 111 | echo |
---|
[2720] | 112 | '<form action="'.$core->adminurl->get("admin.blogs").'" method="get" id="filters-form">'. |
---|
[1514] | 113 | '<h3 class="hidden">'.__('Filter blogs list').'</h3>'. |
---|
[2566] | 114 | |
---|
[1420] | 115 | '<div class="table">'. |
---|
| 116 | '<div class="cell">'. |
---|
[1514] | 117 | '<h4>'.__('Filters').'</h4>'. |
---|
[1420] | 118 | '<p><label for="q" class="ib">'.__('Search:').'</label> '. |
---|
| 119 | form::field('q',20,255,html::escapeHTML($q)).'</p>'. |
---|
[0] | 120 | '</div>'. |
---|
[2566] | 121 | |
---|
[1420] | 122 | '<div class="cell filters-options">'. |
---|
[1514] | 123 | '<h4>'.__('Display options').'</h4>'. |
---|
[1420] | 124 | '<p><label for="sortby" class="ib">'.__('Order by:').'</label> '. |
---|
| 125 | form::combo('sortby',$sortby_combo,html::escapeHTML($sortby)).'</p>'. |
---|
| 126 | '<p><label for="order" class="ib">'.__('Sort:').'</label> '. |
---|
| 127 | form::combo('order',$order_combo,html::escapeHTML($order)).'</p>'. |
---|
[2566] | 128 | '<p><span class="label ib">'.__('Show').'</span> <label for="nb" class="classic">'. |
---|
[1420] | 129 | form::field('nb',3,3,$nb_per_page).' '.__('blogs per page').'</label></p>'. |
---|
[0] | 130 | '</div>'. |
---|
[1420] | 131 | '</div>'. |
---|
| 132 | |
---|
[1514] | 133 | '<p><input type="submit" value="'.__('Apply filters and display options').'" />'. |
---|
[1424] | 134 | '<br class="clear" /></p>'. //Opera sucks |
---|
[0] | 135 | '</form>'; |
---|
[2566] | 136 | |
---|
[0] | 137 | # Show blogs |
---|
| 138 | if ($nb_blog == 0) |
---|
| 139 | { |
---|
[2135] | 140 | if( $show_filters ) { |
---|
| 141 | echo '<p><strong>'.__('No blog matches the filter').'</strong></p>'; |
---|
| 142 | } else { |
---|
| 143 | echo '<p><strong>'.__('No blog').'</strong></p>'; |
---|
| 144 | } |
---|
[0] | 145 | } |
---|
| 146 | else |
---|
| 147 | { |
---|
[1926] | 148 | $pager = new dcPager($page,$nb_blog,$nb_per_page,10); |
---|
[2566] | 149 | |
---|
[1926] | 150 | echo $pager->getLinks(); |
---|
[2566] | 151 | |
---|
[0] | 152 | echo |
---|
[2002] | 153 | '<div class="table-outer">'. |
---|
[2135] | 154 | '<table class="clear">'; |
---|
[2566] | 155 | |
---|
[2135] | 156 | if( $show_filters ) { |
---|
[2819] | 157 | echo '<caption>'.sprintf(__('%d blog matches the filter.','%d blogs match the filter.',$nb_blog),$nb_blog).'</caption>'; |
---|
[2135] | 158 | } else { |
---|
| 159 | echo '<caption class="hidden">'.__('Blogs list').'</caption>'; |
---|
| 160 | } |
---|
[2566] | 161 | |
---|
| 162 | echo |
---|
[2135] | 163 | '<tr>'. |
---|
[1668] | 164 | '<th scope="col" class="nowrap">'.__('Blog id').'</th>'. |
---|
| 165 | '<th scope="col">'.__('Blog name').'</th>'. |
---|
[3046] | 166 | '<th scope="col" class="nowrap">'.__('URL').'</th>'. |
---|
[1668] | 167 | '<th scope="col" class="nowrap">'.__('Entries (all types)').'</th>'. |
---|
| 168 | '<th scope="col" class="nowrap">'.__('Last update').'</th>'. |
---|
| 169 | '<th scope="col" class="nowrap">'.__('Status').'</th>'. |
---|
[0] | 170 | '</tr>'; |
---|
[2566] | 171 | |
---|
[3106] | 172 | while ($rsStatic->fetch()) { |
---|
| 173 | echo blogLine($rsStatic); |
---|
[0] | 174 | } |
---|
[2566] | 175 | |
---|
[2002] | 176 | echo '</table></div>'; |
---|
[2566] | 177 | |
---|
[1926] | 178 | echo $pager->getLinks(); |
---|
[0] | 179 | } |
---|
| 180 | } |
---|
[2314] | 181 | dcPage::helpBlock('core_blogs'); |
---|
[0] | 182 | dcPage::close(); |
---|
| 183 | |
---|
| 184 | function blogLine($rs) |
---|
| 185 | { |
---|
| 186 | global $core; |
---|
[2566] | 187 | |
---|
[0] | 188 | $blog_id = html::escapeHTML($rs->blog_id); |
---|
| 189 | $edit_link = ''; |
---|
[2566] | 190 | |
---|
[0] | 191 | if ($GLOBALS['core']->auth->isSuperAdmin()) { |
---|
[2566] | 192 | $edit_link = |
---|
[2720] | 193 | '<a href="'.$core->adminurl->get("admin.blog",array('id' => $blog_id)).'" title="'.sprintf(__('Edit blog settings for %s'),$blog_id).'">'. |
---|
[1668] | 194 | '<img src="images/edit-mini.png" alt="'.__('Edit blog settings').'" /> '.$blog_id.'</a> '; |
---|
[2107] | 195 | } else { |
---|
| 196 | $edit_link = $blog_id; |
---|
[0] | 197 | } |
---|
[2566] | 198 | |
---|
[3045] | 199 | $img_status = $rs->blog_status == 1 ? 'check-on' : ($rs->blog_status == 0 ? 'check-off' : 'check-wrn'); |
---|
[0] | 200 | $txt_status = $GLOBALS['core']->getBlogStatus($rs->blog_status); |
---|
| 201 | $img_status = sprintf('<img src="images/%1$s.png" alt="%2$s" title="%2$s" />',$img_status,$txt_status); |
---|
| 202 | $offset = dt::getTimeOffset($core->auth->getInfo('user_tz')); |
---|
| 203 | $blog_upddt = dt::str(__('%Y-%m-%d %H:%M'),strtotime($rs->blog_upddt) + $offset); |
---|
[2566] | 204 | |
---|
[0] | 205 | return |
---|
| 206 | '<tr class="line">'. |
---|
[1668] | 207 | '<td class="nowrap">'.$edit_link.'</td>'. |
---|
[2720] | 208 | '<td class="maximal"><a href="'.$core->adminurl->get("admin.home",array('switchblog' => $rs->blog_id)).'" '. |
---|
[0] | 209 | 'title="'.sprintf(__('Switch to blog %s'),$rs->blog_id).'">'. |
---|
| 210 | html::escapeHTML($rs->blog_name).'</a></td>'. |
---|
[3046] | 211 | '<td class="nowrap"><a class="outgoing" href="'.html::escapeHTML($rs->blog_url).'">'.html::escapeHTML($rs->blog_url). |
---|
| 212 | ' <img src="images/outgoing-blue.png" alt="" /></a></td>'. |
---|
[1668] | 213 | '<td class="nowrap count">'.$core->countBlogPosts($rs->blog_id).'</td>'. |
---|
| 214 | '<td class="nowrap count">'.$blog_upddt.'</td>'. |
---|
[0] | 215 | '<td class="status">'.$img_status.'</td>'. |
---|
| 216 | '</tr>'; |
---|
| 217 | } |
---|