[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 |
---|
[3400] | 18 | $status_combo = array_merge( |
---|
| 19 | array('-' => ''), |
---|
| 20 | dcAdminCombos::getBlogStatusesCombo() |
---|
| 21 | ); |
---|
| 22 | |
---|
[0] | 23 | $sortby_combo = array( |
---|
| 24 | __('Last update') => 'blog_upddt', |
---|
| 25 | __('Blog name') => 'UPPER(blog_name)', |
---|
[3400] | 26 | __('Blog ID') => 'B.blog_id', |
---|
| 27 | __('Status') => 'blog_status' |
---|
[0] | 28 | ); |
---|
| 29 | |
---|
| 30 | $order_combo = array( |
---|
| 31 | __('Descending') => 'desc', |
---|
| 32 | __('Ascending') => 'asc' |
---|
| 33 | ); |
---|
| 34 | |
---|
| 35 | $q = !empty($_GET['q']) ? $_GET['q'] : ''; |
---|
[3400] | 36 | $status = isset($_GET['status']) ? $_GET['status'] : ''; |
---|
[0] | 37 | $sortby = !empty($_GET['sortby']) ? $_GET['sortby'] : 'blog_upddt'; |
---|
| 38 | $order = !empty($_GET['order']) ? $_GET['order'] : 'desc'; |
---|
[2145] | 39 | |
---|
[2137] | 40 | $show_filters = false; |
---|
[0] | 41 | |
---|
[1912] | 42 | $page = !empty($_GET['page']) ? max(1,(integer) $_GET['page']) : 1; |
---|
[0] | 43 | $nb_per_page = 30; |
---|
| 44 | |
---|
| 45 | if (!empty($_GET['nb']) && (integer) $_GET['nb'] > 0) { |
---|
[2137] | 46 | if ($nb_per_page != $_GET['nb']) { |
---|
| 47 | $show_filters = true; |
---|
| 48 | } |
---|
[792] | 49 | $nb_per_page = (integer) $_GET['nb']; |
---|
[0] | 50 | } |
---|
[2566] | 51 | |
---|
[0] | 52 | # - Search filter |
---|
| 53 | if ($q) { |
---|
| 54 | $params['q'] = $q; |
---|
| 55 | $show_filters = true; |
---|
| 56 | } |
---|
| 57 | |
---|
[3400] | 58 | # - Status filter |
---|
| 59 | if ($status !== '' && in_array($status,$status_combo)) { |
---|
| 60 | $params['blog_status'] = $status; |
---|
| 61 | $show_filters = true; |
---|
| 62 | } else { |
---|
| 63 | $status=''; |
---|
| 64 | } |
---|
| 65 | |
---|
[0] | 66 | # - Sortby and order filter |
---|
| 67 | if ($sortby !== '' && in_array($sortby,$sortby_combo)) { |
---|
| 68 | if ($order !== '' && in_array($order,$order_combo)) { |
---|
| 69 | $params['order'] = $sortby.' '.$order; |
---|
| 70 | } |
---|
[2566] | 71 | |
---|
[0] | 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 | |
---|
| 79 | try { |
---|
| 80 | $counter = $core->getBlogs($params,1); |
---|
| 81 | $rs = $core->getBlogs($params); |
---|
| 82 | $nb_blog = $counter->f(0); |
---|
[3106] | 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 | } |
---|
[0] | 90 | } catch (Exception $e) { |
---|
| 91 | $core->error->add($e->getMessage()); |
---|
| 92 | } |
---|
| 93 | |
---|
| 94 | /* DISPLAY |
---|
| 95 | -------------------------------------------------------- */ |
---|
[2136] | 96 | |
---|
[3397] | 97 | dcPage::open(__('List of blogs'), |
---|
| 98 | dcPage::jsFilterControl($show_filters), |
---|
[1358] | 99 | dcPage::breadcrumb( |
---|
| 100 | array( |
---|
| 101 | __('System') => '', |
---|
[2189] | 102 | __('List of blogs') => '' |
---|
[1358] | 103 | )) |
---|
| 104 | ); |
---|
[0] | 105 | |
---|
| 106 | if (!empty($_GET['del'])) { |
---|
[1553] | 107 | dcPage::success(__('Blog has been successfully deleted.')); |
---|
[0] | 108 | } |
---|
| 109 | |
---|
| 110 | if (!$core->error->flag()) |
---|
| 111 | { |
---|
| 112 | if ($core->auth->isSuperAdmin()) { |
---|
[2720] | 113 | echo '<p class="top-add"><a class="button add" href="'.$core->adminurl->get("admin.blog").'">'.__('Create a new blog').'</a></p>'; |
---|
[0] | 114 | } |
---|
[2566] | 115 | |
---|
[0] | 116 | echo |
---|
[2720] | 117 | '<form action="'.$core->adminurl->get("admin.blogs").'" method="get" id="filters-form">'. |
---|
[3397] | 118 | '<h3 class="out-of-screen-if-js">'.__('Show filters and display options').'</h3>'. |
---|
[2566] | 119 | |
---|
[1420] | 120 | '<div class="table">'. |
---|
| 121 | '<div class="cell">'. |
---|
[1514] | 122 | '<h4>'.__('Filters').'</h4>'. |
---|
[1420] | 123 | '<p><label for="q" class="ib">'.__('Search:').'</label> '. |
---|
| 124 | form::field('q',20,255,html::escapeHTML($q)).'</p>'. |
---|
[3400] | 125 | '<p><label for="status" class="ib">'.__('Status:').'</label> '. |
---|
| 126 | form::combo('status',$status_combo,$status).'</p>'. |
---|
[0] | 127 | '</div>'. |
---|
[2566] | 128 | |
---|
[1420] | 129 | '<div class="cell filters-options">'. |
---|
[1514] | 130 | '<h4>'.__('Display options').'</h4>'. |
---|
[1420] | 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>'. |
---|
[2566] | 135 | '<p><span class="label ib">'.__('Show').'</span> <label for="nb" class="classic">'. |
---|
[1420] | 136 | form::field('nb',3,3,$nb_per_page).' '.__('blogs per page').'</label></p>'. |
---|
[0] | 137 | '</div>'. |
---|
[1420] | 138 | '</div>'. |
---|
| 139 | |
---|
[1514] | 140 | '<p><input type="submit" value="'.__('Apply filters and display options').'" />'. |
---|
[1424] | 141 | '<br class="clear" /></p>'. //Opera sucks |
---|
[0] | 142 | '</form>'; |
---|
[2566] | 143 | |
---|
[0] | 144 | # Show blogs |
---|
| 145 | if ($nb_blog == 0) |
---|
| 146 | { |
---|
[2135] | 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 | } |
---|
[0] | 152 | } |
---|
| 153 | else |
---|
| 154 | { |
---|
[1926] | 155 | $pager = new dcPager($page,$nb_blog,$nb_per_page,10); |
---|
[2566] | 156 | |
---|
[1926] | 157 | echo $pager->getLinks(); |
---|
[2566] | 158 | |
---|
[0] | 159 | echo |
---|
[2002] | 160 | '<div class="table-outer">'. |
---|
[2135] | 161 | '<table class="clear">'; |
---|
[2566] | 162 | |
---|
[2135] | 163 | if( $show_filters ) { |
---|
[2819] | 164 | echo '<caption>'.sprintf(__('%d blog matches the filter.','%d blogs match the filter.',$nb_blog),$nb_blog).'</caption>'; |
---|
[2135] | 165 | } else { |
---|
| 166 | echo '<caption class="hidden">'.__('Blogs list').'</caption>'; |
---|
| 167 | } |
---|
[2566] | 168 | |
---|
| 169 | echo |
---|
[2135] | 170 | '<tr>'. |
---|
[1668] | 171 | '<th scope="col" class="nowrap">'.__('Blog id').'</th>'. |
---|
| 172 | '<th scope="col">'.__('Blog name').'</th>'. |
---|
[3046] | 173 | '<th scope="col" class="nowrap">'.__('URL').'</th>'. |
---|
[1668] | 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>'. |
---|
[0] | 177 | '</tr>'; |
---|
[2566] | 178 | |
---|
[3106] | 179 | while ($rsStatic->fetch()) { |
---|
| 180 | echo blogLine($rsStatic); |
---|
[0] | 181 | } |
---|
[2566] | 182 | |
---|
[2002] | 183 | echo '</table></div>'; |
---|
[2566] | 184 | |
---|
[1926] | 185 | echo $pager->getLinks(); |
---|
[0] | 186 | } |
---|
| 187 | } |
---|
[2314] | 188 | dcPage::helpBlock('core_blogs'); |
---|
[0] | 189 | dcPage::close(); |
---|
| 190 | |
---|
| 191 | function blogLine($rs) |
---|
| 192 | { |
---|
| 193 | global $core; |
---|
[2566] | 194 | |
---|
[0] | 195 | $blog_id = html::escapeHTML($rs->blog_id); |
---|
| 196 | $edit_link = ''; |
---|
[2566] | 197 | |
---|
[0] | 198 | if ($GLOBALS['core']->auth->isSuperAdmin()) { |
---|
[2566] | 199 | $edit_link = |
---|
[2720] | 200 | '<a href="'.$core->adminurl->get("admin.blog",array('id' => $blog_id)).'" title="'.sprintf(__('Edit blog settings for %s'),$blog_id).'">'. |
---|
[1668] | 201 | '<img src="images/edit-mini.png" alt="'.__('Edit blog settings').'" /> '.$blog_id.'</a> '; |
---|
[2107] | 202 | } else { |
---|
| 203 | $edit_link = $blog_id; |
---|
[0] | 204 | } |
---|
[2566] | 205 | |
---|
[3045] | 206 | $img_status = $rs->blog_status == 1 ? 'check-on' : ($rs->blog_status == 0 ? 'check-off' : 'check-wrn'); |
---|
[0] | 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); |
---|
[2566] | 211 | |
---|
[0] | 212 | return |
---|
| 213 | '<tr class="line">'. |
---|
[1668] | 214 | '<td class="nowrap">'.$edit_link.'</td>'. |
---|
[2720] | 215 | '<td class="maximal"><a href="'.$core->adminurl->get("admin.home",array('switchblog' => $rs->blog_id)).'" '. |
---|
[0] | 216 | 'title="'.sprintf(__('Switch to blog %s'),$rs->blog_id).'">'. |
---|
| 217 | html::escapeHTML($rs->blog_name).'</a></td>'. |
---|
[3046] | 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>'. |
---|
[1668] | 220 | '<td class="nowrap count">'.$core->countBlogPosts($rs->blog_id).'</td>'. |
---|
| 221 | '<td class="nowrap count">'.$blog_upddt.'</td>'. |
---|
[0] | 222 | '<td class="status">'.$img_status.'</td>'. |
---|
| 223 | '</tr>'; |
---|
| 224 | } |
---|