| 1 | <?php | 
|---|
| 2 | /** | 
|---|
| 3 | * @package Dotclear | 
|---|
| 4 | * @subpackage Backend | 
|---|
| 5 | * | 
|---|
| 6 | * @copyright Olivier Meunier & Association Dotclear | 
|---|
| 7 | * @copyright GPL-2.0-only | 
|---|
| 8 | */ | 
|---|
| 9 |  | 
|---|
| 10 | require dirname(__FILE__) . '/../inc/admin/prepend.php'; | 
|---|
| 11 |  | 
|---|
| 12 | dcPage::check('usage,contentadmin'); | 
|---|
| 13 |  | 
|---|
| 14 | # Filters | 
|---|
| 15 | $status_combo = array_merge( | 
|---|
| 16 | ['-' => ''], | 
|---|
| 17 | dcAdminCombos::getBlogStatusesCombo() | 
|---|
| 18 | ); | 
|---|
| 19 |  | 
|---|
| 20 | $sortby_combo = [ | 
|---|
| 21 | __('Last update') => 'blog_upddt', | 
|---|
| 22 | __('Blog name')   => 'UPPER(blog_name)', | 
|---|
| 23 | __('Blog ID')     => 'B.blog_id', | 
|---|
| 24 | __('Status')      => 'blog_status' | 
|---|
| 25 | ]; | 
|---|
| 26 |  | 
|---|
| 27 | $order_combo = [ | 
|---|
| 28 | __('Descending') => 'desc', | 
|---|
| 29 | __('Ascending')  => 'asc' | 
|---|
| 30 | ]; | 
|---|
| 31 |  | 
|---|
| 32 | # Actions | 
|---|
| 33 |  | 
|---|
| 34 | if ($core->auth->isSuperAdmin()) { | 
|---|
| 35 | $blogs_actions_page = new dcBlogsActionsPage($core, $core->adminurl->get("admin.blogs")); | 
|---|
| 36 | if ($blogs_actions_page->process()) { | 
|---|
| 37 | return; | 
|---|
| 38 | } | 
|---|
| 39 | } | 
|---|
| 40 |  | 
|---|
| 41 | # Requests | 
|---|
| 42 | $q      = !empty($_GET['q']) ? $_GET['q'] : ''; | 
|---|
| 43 | $status = isset($_GET['status']) ? $_GET['status'] : ''; | 
|---|
| 44 | $sortby = !empty($_GET['sortby']) ? $_GET['sortby'] : 'blog_upddt'; | 
|---|
| 45 | $order  = !empty($_GET['order']) ? $_GET['order'] : 'desc'; | 
|---|
| 46 |  | 
|---|
| 47 | $show_filters = false; | 
|---|
| 48 |  | 
|---|
| 49 | $page        = !empty($_GET['page']) ? max(1, (integer) $_GET['page']) : 1; | 
|---|
| 50 | $nb_per_page = 30; | 
|---|
| 51 |  | 
|---|
| 52 | if (!empty($_GET['nb']) && (integer) $_GET['nb'] > 0) { | 
|---|
| 53 | if ($nb_per_page != (integer) $_GET['nb']) { | 
|---|
| 54 | $show_filters = true; | 
|---|
| 55 | } | 
|---|
| 56 | $nb_per_page = (integer) $_GET['nb']; | 
|---|
| 57 | } | 
|---|
| 58 |  | 
|---|
| 59 | # - Search filter | 
|---|
| 60 | if ($q) { | 
|---|
| 61 | $params['q']  = $q; | 
|---|
| 62 | $show_filters = true; | 
|---|
| 63 | } | 
|---|
| 64 |  | 
|---|
| 65 | # - Status filter | 
|---|
| 66 | if ($status !== '' && in_array($status, $status_combo, true)) { | 
|---|
| 67 | $params['blog_status'] = $status; | 
|---|
| 68 | $show_filters          = true; | 
|---|
| 69 | } else { | 
|---|
| 70 | $status = ''; | 
|---|
| 71 | } | 
|---|
| 72 |  | 
|---|
| 73 | # - Sortby and order filter | 
|---|
| 74 | if ($sortby !== '' && in_array($sortby, $sortby_combo, true)) { | 
|---|
| 75 | if ($order !== '' && in_array($order, $order_combo, true)) { | 
|---|
| 76 | $params['order'] = $sortby . ' ' . $order; | 
|---|
| 77 | } else { | 
|---|
| 78 | $order = 'desc'; | 
|---|
| 79 | } | 
|---|
| 80 | } else { | 
|---|
| 81 | $sortby = 'blog_upddt'; | 
|---|
| 82 | $order  = 'desc'; | 
|---|
| 83 | } | 
|---|
| 84 | if ($sortby != 'blog_upddt' || $order != 'desc') { | 
|---|
| 85 | $show_filters = true; | 
|---|
| 86 | } | 
|---|
| 87 |  | 
|---|
| 88 | $params['limit'] = [(($page - 1) * $nb_per_page), $nb_per_page]; | 
|---|
| 89 |  | 
|---|
| 90 | try { | 
|---|
| 91 | $counter  = $core->getBlogs($params, 1); | 
|---|
| 92 | $rs       = $core->getBlogs($params); | 
|---|
| 93 | $nb_blog  = $counter->f(0); | 
|---|
| 94 | $rsStatic = $rs->toStatic(); | 
|---|
| 95 | if (($sortby != 'blog_upddt') && ($sortby != 'blog_status')) { | 
|---|
| 96 | // Sort blog list using lexical order if necessary | 
|---|
| 97 | $rsStatic->extend('rsExtUser'); | 
|---|
| 98 | $rsStatic = $rsStatic->toExtStatic(); | 
|---|
| 99 | $rsStatic->lexicalSort(($sortby == 'UPPER(blog_name)' ? 'blog_name' : 'blog_id'), $order); | 
|---|
| 100 | } | 
|---|
| 101 | $blog_list = new adminBlogList($core, $rs, $counter->f(0)); | 
|---|
| 102 | } catch (Exception $e) { | 
|---|
| 103 | $core->error->add($e->getMessage()); | 
|---|
| 104 | } | 
|---|
| 105 |  | 
|---|
| 106 | /* DISPLAY | 
|---|
| 107 | -------------------------------------------------------- */ | 
|---|
| 108 |  | 
|---|
| 109 | dcPage::open(__('List of blogs'), | 
|---|
| 110 | dcPage::jsLoad('js/_blogs.js') . dcPage::jsFilterControl($show_filters), | 
|---|
| 111 | dcPage::breadcrumb( | 
|---|
| 112 | [ | 
|---|
| 113 | __('System')        => '', | 
|---|
| 114 | __('List of blogs') => '' | 
|---|
| 115 | ]) | 
|---|
| 116 | ); | 
|---|
| 117 |  | 
|---|
| 118 | if (!$core->error->flag()) { | 
|---|
| 119 | if ($core->auth->isSuperAdmin()) { | 
|---|
| 120 | echo '<p class="top-add"><a class="button add" href="' . $core->adminurl->get("admin.blog") . '">' . __('Create a new blog') . '</a></p>'; | 
|---|
| 121 | } | 
|---|
| 122 |  | 
|---|
| 123 | echo | 
|---|
| 124 | '<form action="' . $core->adminurl->get("admin.blogs") . '" method="get" id="filters-form">' . | 
|---|
| 125 | '<h3 class="out-of-screen-if-js">' . __('Show filters and display options') . '</h3>' . | 
|---|
| 126 |  | 
|---|
| 127 | '<div class="table">' . | 
|---|
| 128 | '<div class="cell">' . | 
|---|
| 129 | '<h4>' . __('Filters') . '</h4>' . | 
|---|
| 130 | '<p><label for="q" class="ib">' . __('Search:') . '</label> ' . | 
|---|
| 131 | form::field('q', 20, 255, html::escapeHTML($q)) . '</p>' . | 
|---|
| 132 | ($core->auth->isSuperAdmin() ? | 
|---|
| 133 | '<p><label for="status" class="ib">' . __('Status:') . '</label> ' . | 
|---|
| 134 | form::combo('status', $status_combo, $status) . '</p>' : '') . | 
|---|
| 135 | '</div>' . | 
|---|
| 136 |  | 
|---|
| 137 | '<div class="cell filters-options">' . | 
|---|
| 138 | '<h4>' . __('Display options') . '</h4>' . | 
|---|
| 139 | '<p><label for="sortby" class="ib">' . __('Order by:') . '</label> ' . | 
|---|
| 140 | form::combo('sortby', $sortby_combo, html::escapeHTML($sortby)) . '</p>' . | 
|---|
| 141 | '<p><label for="order" class="ib">' . __('Sort:') . '</label> ' . | 
|---|
| 142 | form::combo('order', $order_combo, html::escapeHTML($order)) . '</p>' . | 
|---|
| 143 | '<p><span class="label ib">' . __('Show') . '</span> <label for="nb" class="classic">' . | 
|---|
| 144 | form::number('nb', 0, 999, $nb_per_page) . ' ' . __('blogs per page') . '</label></p>' . | 
|---|
| 145 | '</div>' . | 
|---|
| 146 | '</div>' . | 
|---|
| 147 |  | 
|---|
| 148 | '<p><input type="submit" value="' . __('Apply filters and display options') . '" />' . | 
|---|
| 149 | '<br class="clear" /></p>' . //Opera sucks | 
|---|
| 150 | '</form>'; | 
|---|
| 151 |  | 
|---|
| 152 | # Show blogs | 
|---|
| 153 | $blog_list->display($page, $nb_per_page, | 
|---|
| 154 | ($core->auth->isSuperAdmin() ? | 
|---|
| 155 | '<form action="' . $core->adminurl->get("admin.blogs") . '" method="post" id="form-blogs">' : '') . | 
|---|
| 156 |  | 
|---|
| 157 | '%s' . | 
|---|
| 158 |  | 
|---|
| 159 | ($core->auth->isSuperAdmin() ? | 
|---|
| 160 | '<div class="two-cols clearfix">' . | 
|---|
| 161 | '<p class="col checkboxes-helpers"></p>' . | 
|---|
| 162 |  | 
|---|
| 163 | '<p class="col right"><label for="action" class="classic">' . __('Selected blogs action:') . '</label> ' . | 
|---|
| 164 | form::combo('action', $blogs_actions_page->getCombo(), | 
|---|
| 165 | ['class' => 'online', 'extra_html' => 'title="' . __('Actions') . '"']) . | 
|---|
| 166 | $core->formNonce() . | 
|---|
| 167 | '<input id="do-action" type="submit" value="' . __('ok') . '" /></p>' . | 
|---|
| 168 | '</div>' . | 
|---|
| 169 |  | 
|---|
| 170 | '<p><label for="pwd" class="classic">' . __('Please give your password to confirm blog(s) deletion:') . '</label> ' . | 
|---|
| 171 | form::password('pwd', 20, 255, ['autocomplete' => 'current-password']) . '</p>' . | 
|---|
| 172 |  | 
|---|
| 173 | form::hidden(['sortby'], $sortby) . | 
|---|
| 174 | form::hidden(['order'], $order) . | 
|---|
| 175 | form::hidden(['status'], $status) . | 
|---|
| 176 | form::hidden(['page'], $page) . | 
|---|
| 177 | form::hidden(['nb'], $nb_per_page) . | 
|---|
| 178 |  | 
|---|
| 179 | '</form>' : ''), | 
|---|
| 180 | $show_filters | 
|---|
| 181 | ); | 
|---|
| 182 | } | 
|---|
| 183 |  | 
|---|
| 184 | dcPage::helpBlock('core_blogs'); | 
|---|
| 185 | dcPage::close(); | 
|---|