[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); |
---|
| 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') => '', |
---|
[2189] | 90 | __('List of blogs') => '' |
---|
[1358] | 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()) { |
---|
[2720] | 101 | echo '<p class="top-add"><a class="button add" href="'.$core->adminurl->get("admin.blog").'">'.__('Create a new blog').'</a></p>'; |
---|
[0] | 102 | } |
---|
[2566] | 103 | |
---|
[0] | 104 | echo |
---|
[2720] | 105 | '<form action="'.$core->adminurl->get("admin.blogs").'" method="get" id="filters-form">'. |
---|
[1514] | 106 | '<h3 class="hidden">'.__('Filter blogs list').'</h3>'. |
---|
[2566] | 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>'. |
---|
[2566] | 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>'. |
---|
[2566] | 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>'; |
---|
[2566] | 129 | |
---|
[0] | 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); |
---|
[2566] | 142 | |
---|
[1926] | 143 | echo $pager->getLinks(); |
---|
[2566] | 144 | |
---|
[0] | 145 | echo |
---|
[2002] | 146 | '<div class="table-outer">'. |
---|
[2135] | 147 | '<table class="clear">'; |
---|
[2566] | 148 | |
---|
[2135] | 149 | if( $show_filters ) { |
---|
[2819] | 150 | echo '<caption>'.sprintf(__('%d blog matches the filter.','%d blogs match the filter.',$nb_blog),$nb_blog).'</caption>'; |
---|
[2135] | 151 | } else { |
---|
| 152 | echo '<caption class="hidden">'.__('Blogs list').'</caption>'; |
---|
| 153 | } |
---|
[2566] | 154 | |
---|
| 155 | echo |
---|
[2135] | 156 | '<tr>'. |
---|
[1668] | 157 | '<th scope="col" class="nowrap">'.__('Blog id').'</th>'. |
---|
| 158 | '<th scope="col">'.__('Blog name').'</th>'. |
---|
[3046] | 159 | '<th scope="col" class="nowrap">'.__('URL').'</th>'. |
---|
[1668] | 160 | '<th scope="col" class="nowrap">'.__('Entries (all types)').'</th>'. |
---|
| 161 | '<th scope="col" class="nowrap">'.__('Last update').'</th>'. |
---|
| 162 | '<th scope="col" class="nowrap">'.__('Status').'</th>'. |
---|
[0] | 163 | '</tr>'; |
---|
[2566] | 164 | |
---|
[0] | 165 | while ($rs->fetch()) { |
---|
| 166 | echo blogLine($rs); |
---|
| 167 | } |
---|
[2566] | 168 | |
---|
[2002] | 169 | echo '</table></div>'; |
---|
[2566] | 170 | |
---|
[1926] | 171 | echo $pager->getLinks(); |
---|
[0] | 172 | } |
---|
| 173 | } |
---|
[2314] | 174 | dcPage::helpBlock('core_blogs'); |
---|
[0] | 175 | dcPage::close(); |
---|
| 176 | |
---|
| 177 | function blogLine($rs) |
---|
| 178 | { |
---|
| 179 | global $core; |
---|
[2566] | 180 | |
---|
[0] | 181 | $blog_id = html::escapeHTML($rs->blog_id); |
---|
| 182 | $edit_link = ''; |
---|
[2566] | 183 | |
---|
[0] | 184 | if ($GLOBALS['core']->auth->isSuperAdmin()) { |
---|
[2566] | 185 | $edit_link = |
---|
[2720] | 186 | '<a href="'.$core->adminurl->get("admin.blog",array('id' => $blog_id)).'" title="'.sprintf(__('Edit blog settings for %s'),$blog_id).'">'. |
---|
[1668] | 187 | '<img src="images/edit-mini.png" alt="'.__('Edit blog settings').'" /> '.$blog_id.'</a> '; |
---|
[2107] | 188 | } else { |
---|
| 189 | $edit_link = $blog_id; |
---|
[0] | 190 | } |
---|
[2566] | 191 | |
---|
[3045] | 192 | $img_status = $rs->blog_status == 1 ? 'check-on' : ($rs->blog_status == 0 ? 'check-off' : 'check-wrn'); |
---|
[0] | 193 | $txt_status = $GLOBALS['core']->getBlogStatus($rs->blog_status); |
---|
| 194 | $img_status = sprintf('<img src="images/%1$s.png" alt="%2$s" title="%2$s" />',$img_status,$txt_status); |
---|
| 195 | $offset = dt::getTimeOffset($core->auth->getInfo('user_tz')); |
---|
| 196 | $blog_upddt = dt::str(__('%Y-%m-%d %H:%M'),strtotime($rs->blog_upddt) + $offset); |
---|
[2566] | 197 | |
---|
[0] | 198 | return |
---|
| 199 | '<tr class="line">'. |
---|
[1668] | 200 | '<td class="nowrap">'.$edit_link.'</td>'. |
---|
[2720] | 201 | '<td class="maximal"><a href="'.$core->adminurl->get("admin.home",array('switchblog' => $rs->blog_id)).'" '. |
---|
[0] | 202 | 'title="'.sprintf(__('Switch to blog %s'),$rs->blog_id).'">'. |
---|
| 203 | html::escapeHTML($rs->blog_name).'</a></td>'. |
---|
[3046] | 204 | '<td class="nowrap"><a class="outgoing" href="'.html::escapeHTML($rs->blog_url).'">'.html::escapeHTML($rs->blog_url). |
---|
| 205 | ' <img src="images/outgoing-blue.png" alt="" /></a></td>'. |
---|
[1668] | 206 | '<td class="nowrap count">'.$core->countBlogPosts($rs->blog_id).'</td>'. |
---|
| 207 | '<td class="nowrap count">'.$blog_upddt.'</td>'. |
---|
[0] | 208 | '<td class="status">'.$img_status.'</td>'. |
---|
| 209 | '</tr>'; |
---|
| 210 | } |
---|