| 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 | $page = !empty($_GET['page']) ? $_GET['page'] : 1; | 
|---|
| 34 | $nb_per_page =  30; | 
|---|
| 35 |  | 
|---|
| 36 | if (!empty($_GET['nb']) && (integer) $_GET['nb'] > 0) { | 
|---|
| 37 | $nb_per_page = (integer) $_GET['nb']; | 
|---|
| 38 | } | 
|---|
| 39 |  | 
|---|
| 40 | $show_filters = false; | 
|---|
| 41 |  | 
|---|
| 42 | # - Search filter | 
|---|
| 43 | if ($q) { | 
|---|
| 44 | $params['q'] = $q; | 
|---|
| 45 | $show_filters = true; | 
|---|
| 46 | } | 
|---|
| 47 |  | 
|---|
| 48 | # - Sortby and order filter | 
|---|
| 49 | if ($sortby !== '' && in_array($sortby,$sortby_combo)) { | 
|---|
| 50 | if ($order !== '' && in_array($order,$order_combo)) { | 
|---|
| 51 | $params['order'] = $sortby.' '.$order; | 
|---|
| 52 | } | 
|---|
| 53 |  | 
|---|
| 54 | if ($sortby != 'blog_upddt' || $order != 'desc') { | 
|---|
| 55 | $show_filters = true; | 
|---|
| 56 | } | 
|---|
| 57 | } | 
|---|
| 58 |  | 
|---|
| 59 | $params['limit'] = array((($page-1)*$nb_per_page),$nb_per_page); | 
|---|
| 60 |  | 
|---|
| 61 | try { | 
|---|
| 62 | $counter = $core->getBlogs($params,1); | 
|---|
| 63 | $rs = $core->getBlogs($params); | 
|---|
| 64 | $nb_blog = $counter->f(0); | 
|---|
| 65 | } catch (Exception $e) { | 
|---|
| 66 | $core->error->add($e->getMessage()); | 
|---|
| 67 | } | 
|---|
| 68 |  | 
|---|
| 69 | /* DISPLAY | 
|---|
| 70 | -------------------------------------------------------- */ | 
|---|
| 71 | $starting_script = ''; | 
|---|
| 72 | if (!$show_filters) { | 
|---|
| 73 | $starting_script .= dcPage::jsLoad('js/filter-controls.js'); | 
|---|
| 74 | } | 
|---|
| 75 | dcPage::open(__('List of blogs'),$starting_script); | 
|---|
| 76 |  | 
|---|
| 77 | if (!empty($_GET['del'])) { | 
|---|
| 78 | dcPage::message(__('Blog has been successfully deleted.')); | 
|---|
| 79 | } | 
|---|
| 80 |  | 
|---|
| 81 | echo '<h2 class="page-title">'.__('List of blogs').'</h2>'; | 
|---|
| 82 |  | 
|---|
| 83 | if (!$core->error->flag()) | 
|---|
| 84 | { | 
|---|
| 85 | if ($core->auth->isSuperAdmin()) { | 
|---|
| 86 | echo '<p class="top-add"><a class="button add" href="blog.php">'.__('Create a new blog').'</a></p>'; | 
|---|
| 87 | } | 
|---|
| 88 |  | 
|---|
| 89 | if (!$show_filters) { | 
|---|
| 90 | echo '<p><a id="filter-control" class="form-control" href="#">'.__('Filters').'</a></p>'; | 
|---|
| 91 | } | 
|---|
| 92 |  | 
|---|
| 93 | echo | 
|---|
| 94 | '<form action="blogs.php" method="get" id="filters-form">'. | 
|---|
| 95 | '<fieldset class="two-cols"><legend>'.__('Filters').'</legend>'. | 
|---|
| 96 |  | 
|---|
| 97 | '<div class="col">'. | 
|---|
| 98 | '<p><label for="sortby">'.__('Order by:').' '. | 
|---|
| 99 | form::combo('sortby',$sortby_combo,html::escapeHTML($sortby)). | 
|---|
| 100 | '</label> '. | 
|---|
| 101 | '<label for="order">'.__('Sort:').' '. | 
|---|
| 102 | form::combo('order',$order_combo,html::escapeHTML($order)). | 
|---|
| 103 | '</label></p>'. | 
|---|
| 104 | '</div>'. | 
|---|
| 105 |  | 
|---|
| 106 | '<div class="col">'. | 
|---|
| 107 | '<p><label for="q">'.__('Search:').' '. | 
|---|
| 108 | form::field('q',20,255,html::escapeHTML($q)). | 
|---|
| 109 | '</label></p>'. | 
|---|
| 110 | '<p><label for="nb" class="classic">'.  form::field('nb',3,3,$nb_per_page).' '. | 
|---|
| 111 | __('Blogs per page').'</label> '. | 
|---|
| 112 | '<input type="submit" value="'.__('Apply filters').'" /></p>'. | 
|---|
| 113 | '</div>'. | 
|---|
| 114 |  | 
|---|
| 115 | '<br class="clear" />'. //Opera sucks | 
|---|
| 116 | '</fieldset>'. | 
|---|
| 117 | '</form>'; | 
|---|
| 118 |  | 
|---|
| 119 | # Show blogs | 
|---|
| 120 | if ($nb_blog == 0) | 
|---|
| 121 | { | 
|---|
| 122 | echo '<p><strong>'.__('No blog').'</strong></p>'; | 
|---|
| 123 | } | 
|---|
| 124 | else | 
|---|
| 125 | { | 
|---|
| 126 | $pager = new pager($page,$nb_blog,$nb_per_page,10); | 
|---|
| 127 | $pager->var_page = 'page'; | 
|---|
| 128 |  | 
|---|
| 129 | echo '<p>'.__('Page(s)').' : '.$pager->getLinks().'</p>'; | 
|---|
| 130 |  | 
|---|
| 131 | echo | 
|---|
| 132 | '<table class="clear"><tr>'. | 
|---|
| 133 | '<th>'.__('Blog name').'</th>'. | 
|---|
| 134 | '<th class="nowrap">'.__('Last update').'</th>'. | 
|---|
| 135 | '<th class="nowrap">'.__('Entries (all types)').'</th>'. | 
|---|
| 136 | '<th class="nowrap">'.__('Blog ID').'</th>'. | 
|---|
| 137 | '<th> </th>'. | 
|---|
| 138 | '<th class="nowrap">'.__('Status').'</th>'. | 
|---|
| 139 | '</tr>'; | 
|---|
| 140 |  | 
|---|
| 141 | while ($rs->fetch()) { | 
|---|
| 142 | echo blogLine($rs); | 
|---|
| 143 | } | 
|---|
| 144 |  | 
|---|
| 145 | echo '</table>'; | 
|---|
| 146 |  | 
|---|
| 147 | echo '<p>'.__('Page(s)').' : '.$pager->getLinks().'</p>'; | 
|---|
| 148 | } | 
|---|
| 149 | } | 
|---|
| 150 |  | 
|---|
| 151 | dcPage::close(); | 
|---|
| 152 |  | 
|---|
| 153 | function blogLine($rs) | 
|---|
| 154 | { | 
|---|
| 155 | global $core; | 
|---|
| 156 |  | 
|---|
| 157 | $blog_id = html::escapeHTML($rs->blog_id); | 
|---|
| 158 | $edit_link = ''; | 
|---|
| 159 |  | 
|---|
| 160 | if ($GLOBALS['core']->auth->isSuperAdmin()) { | 
|---|
| 161 | $edit_link = | 
|---|
| 162 | '<a href="blog.php?id='.$blog_id.'" '. | 
|---|
| 163 | 'title="'.sprintf(__('Edit blog %s'),$blog_id).'">'. | 
|---|
| 164 | __('edit').'</a>'; | 
|---|
| 165 | } | 
|---|
| 166 |  | 
|---|
| 167 | $img_status = $rs->blog_status == 1 ? 'check-on' : 'check-off'; | 
|---|
| 168 | $txt_status = $GLOBALS['core']->getBlogStatus($rs->blog_status); | 
|---|
| 169 | $img_status = sprintf('<img src="images/%1$s.png" alt="%2$s" title="%2$s" />',$img_status,$txt_status); | 
|---|
| 170 | $offset = dt::getTimeOffset($core->auth->getInfo('user_tz')); | 
|---|
| 171 | $blog_upddt = dt::str(__('%Y-%m-%d %H:%M'),strtotime($rs->blog_upddt) + $offset); | 
|---|
| 172 |  | 
|---|
| 173 | return | 
|---|
| 174 | '<tr class="line">'. | 
|---|
| 175 | '<td class="maximal"><a href="index.php?switchblog='.$rs->blog_id.'" '. | 
|---|
| 176 | 'title="'.sprintf(__('Switch to blog %s'),$rs->blog_id).'">'. | 
|---|
| 177 | html::escapeHTML($rs->blog_name).'</a></td>'. | 
|---|
| 178 | '<td class="nowrap">'.$blog_upddt.'</td>'. | 
|---|
| 179 | '<td class="nowrap">'.$core->countBlogPosts($rs->blog_id).'</td>'. | 
|---|
| 180 | '<td class="nowrap">'.$blog_id.'</td>'. | 
|---|
| 181 | '<td>'.$edit_link.'</td>'. | 
|---|
| 182 | '<td class="status">'.$img_status.'</td>'. | 
|---|
| 183 | '</tr>'; | 
|---|
| 184 | } | 
|---|
| 185 | ?> | 
|---|