| 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 | $show_filters = false; |
|---|
| 34 | |
|---|
| 35 | $page = !empty($_GET['page']) ? max(1,(integer) $_GET['page']) : 1; |
|---|
| 36 | $nb_per_page = 30; |
|---|
| 37 | |
|---|
| 38 | if (!empty($_GET['nb']) && (integer) $_GET['nb'] > 0) { |
|---|
| 39 | if ($nb_per_page != $_GET['nb']) { |
|---|
| 40 | $show_filters = true; |
|---|
| 41 | } |
|---|
| 42 | $nb_per_page = (integer) $_GET['nb']; |
|---|
| 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 | -------------------------------------------------------- */ |
|---|
| 74 | |
|---|
| 75 | $form_filter_title = __('Show filters and display options'); |
|---|
| 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". |
|---|
| 82 | dcPage::jsVar('dotclear.msg.cancel_the_filter',__('Cancel filters and display options'))."\n". |
|---|
| 83 | "//]]>". |
|---|
| 84 | "</script>"; |
|---|
| 85 | |
|---|
| 86 | dcPage::open(__('List of blogs'),$starting_script, |
|---|
| 87 | dcPage::breadcrumb( |
|---|
| 88 | array( |
|---|
| 89 | __('System') => '', |
|---|
| 90 | __('List of blogs') => '' |
|---|
| 91 | )) |
|---|
| 92 | ); |
|---|
| 93 | |
|---|
| 94 | if (!empty($_GET['del'])) { |
|---|
| 95 | dcPage::success(__('Blog has been successfully deleted.')); |
|---|
| 96 | } |
|---|
| 97 | |
|---|
| 98 | if (!$core->error->flag()) |
|---|
| 99 | { |
|---|
| 100 | if ($core->auth->isSuperAdmin()) { |
|---|
| 101 | echo '<p class="top-add"><a class="button add" href="'.$core->adminurl->get("admin.blog").'">'.__('Create a new blog').'</a></p>'; |
|---|
| 102 | } |
|---|
| 103 | |
|---|
| 104 | echo |
|---|
| 105 | '<form action="'.$core->adminurl->get("admin.blogs").'" method="get" id="filters-form">'. |
|---|
| 106 | '<h3 class="hidden">'.__('Filter blogs list').'</h3>'. |
|---|
| 107 | |
|---|
| 108 | '<div class="table">'. |
|---|
| 109 | '<div class="cell">'. |
|---|
| 110 | '<h4>'.__('Filters').'</h4>'. |
|---|
| 111 | '<p><label for="q" class="ib">'.__('Search:').'</label> '. |
|---|
| 112 | form::field('q',20,255,html::escapeHTML($q)).'</p>'. |
|---|
| 113 | '</div>'. |
|---|
| 114 | |
|---|
| 115 | '<div class="cell filters-options">'. |
|---|
| 116 | '<h4>'.__('Display options').'</h4>'. |
|---|
| 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>'. |
|---|
| 121 | '<p><span class="label ib">'.__('Show').'</span> <label for="nb" class="classic">'. |
|---|
| 122 | form::field('nb',3,3,$nb_per_page).' '.__('blogs per page').'</label></p>'. |
|---|
| 123 | '</div>'. |
|---|
| 124 | '</div>'. |
|---|
| 125 | |
|---|
| 126 | '<p><input type="submit" value="'.__('Apply filters and display options').'" />'. |
|---|
| 127 | '<br class="clear" /></p>'. //Opera sucks |
|---|
| 128 | '</form>'; |
|---|
| 129 | |
|---|
| 130 | # Show blogs |
|---|
| 131 | if ($nb_blog == 0) |
|---|
| 132 | { |
|---|
| 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 | } |
|---|
| 138 | } |
|---|
| 139 | else |
|---|
| 140 | { |
|---|
| 141 | $pager = new dcPager($page,$nb_blog,$nb_per_page,10); |
|---|
| 142 | |
|---|
| 143 | echo $pager->getLinks(); |
|---|
| 144 | |
|---|
| 145 | echo |
|---|
| 146 | '<div class="table-outer">'. |
|---|
| 147 | '<table class="clear">'; |
|---|
| 148 | |
|---|
| 149 | if( $show_filters ) { |
|---|
| 150 | echo '<caption>'.sprintf(__('%d blog matches the filter.','%d blogs match the filter.',$nb_blog),$nb_blog).'</caption>'; |
|---|
| 151 | } else { |
|---|
| 152 | echo '<caption class="hidden">'.__('Blogs list').'</caption>'; |
|---|
| 153 | } |
|---|
| 154 | |
|---|
| 155 | echo |
|---|
| 156 | '<tr>'. |
|---|
| 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>'. |
|---|
| 162 | '</tr>'; |
|---|
| 163 | |
|---|
| 164 | while ($rs->fetch()) { |
|---|
| 165 | echo blogLine($rs); |
|---|
| 166 | } |
|---|
| 167 | |
|---|
| 168 | echo '</table></div>'; |
|---|
| 169 | |
|---|
| 170 | echo $pager->getLinks(); |
|---|
| 171 | } |
|---|
| 172 | } |
|---|
| 173 | dcPage::helpBlock('core_blogs'); |
|---|
| 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 = |
|---|
| 185 | '<a href="'.$core->adminurl->get("admin.blog",array('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> '; |
|---|
| 187 | } else { |
|---|
| 188 | $edit_link = $blog_id; |
|---|
| 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">'. |
|---|
| 199 | '<td class="nowrap">'.$edit_link.'</td>'. |
|---|
| 200 | '<td class="maximal"><a href="'.$core->adminurl->get("admin.home",array('switchblog' => $rs->blog_id)).'" '. |
|---|
| 201 | 'title="'.sprintf(__('Switch to blog %s'),$rs->blog_id).'">'. |
|---|
| 202 | html::escapeHTML($rs->blog_name).'</a></td>'. |
|---|
| 203 | '<td class="nowrap count">'.$core->countBlogPosts($rs->blog_id).'</td>'. |
|---|
| 204 | '<td class="nowrap count">'.$blog_upddt.'</td>'. |
|---|
| 205 | '<td class="status">'.$img_status.'</td>'. |
|---|
| 206 | '</tr>'; |
|---|
| 207 | } |
|---|