| 1 | <?php | 
|---|
| 2 | # -- BEGIN LICENSE BLOCK --------------------------------------- | 
|---|
| 3 | # | 
|---|
| 4 | # This file is part of Dotclear 2. | 
|---|
| 5 | # | 
|---|
| 6 | # Copyright (c) 2003-2011 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 | # Creating filter combo boxes | 
|---|
| 18 | # Filter form we'll put in html_block | 
|---|
| 19 | $status_combo = array( | 
|---|
| 20 | '-' => '' | 
|---|
| 21 | ); | 
|---|
| 22 | foreach ($core->blog->getAllCommentStatus() as $k => $v) { | 
|---|
| 23 | $status_combo[$v] = (string) $k; | 
|---|
| 24 | } | 
|---|
| 25 |  | 
|---|
| 26 | $type_combo = array( | 
|---|
| 27 | '-' => '', | 
|---|
| 28 | __('comment') => 'co', | 
|---|
| 29 | __('trackback') => 'tb' | 
|---|
| 30 | ); | 
|---|
| 31 |  | 
|---|
| 32 | $sortby_combo = array( | 
|---|
| 33 | __('Date') => 'comment_dt', | 
|---|
| 34 | __('Entry title') => 'post_title', | 
|---|
| 35 | __('Author') => 'comment_author', | 
|---|
| 36 | __('Status') => 'comment_status' | 
|---|
| 37 | ); | 
|---|
| 38 |  | 
|---|
| 39 | $order_combo = array( | 
|---|
| 40 | __('Descending') => 'desc', | 
|---|
| 41 | __('Ascending') => 'asc' | 
|---|
| 42 | ); | 
|---|
| 43 |  | 
|---|
| 44 |  | 
|---|
| 45 | /* Get comments | 
|---|
| 46 | -------------------------------------------------------- */ | 
|---|
| 47 | $author = isset($_GET['author']) ? $_GET['author'] : ''; | 
|---|
| 48 | $status = isset($_GET['status']) ?      $_GET['status'] : ''; | 
|---|
| 49 | $type = !empty($_GET['type']) ?         $_GET['type'] : ''; | 
|---|
| 50 | $sortby = !empty($_GET['sortby']) ?     $_GET['sortby'] : 'comment_dt'; | 
|---|
| 51 | $order = !empty($_GET['order']) ?       $_GET['order'] : 'desc'; | 
|---|
| 52 | $ip = !empty($_GET['ip']) ?             $_GET['ip'] : ''; | 
|---|
| 53 |  | 
|---|
| 54 | $with_spam = $author || $status || $type || $sortby != 'comment_dt' || $order != 'desc' || $ip; | 
|---|
| 55 |  | 
|---|
| 56 | $show_filters = false; | 
|---|
| 57 |  | 
|---|
| 58 | $page = !empty($_GET['page']) ? (integer) $_GET['page'] : 1; | 
|---|
| 59 | $nb_per_page =  30; | 
|---|
| 60 |  | 
|---|
| 61 | if (!empty($_GET['nb']) && (integer) $_GET['nb'] > 0) { | 
|---|
| 62 | if ($nb_per_page != $_GET['nb']) { | 
|---|
| 63 | $show_filters = true; | 
|---|
| 64 | } | 
|---|
| 65 | $nb_per_page = (integer) $_GET['nb']; | 
|---|
| 66 | } | 
|---|
| 67 |  | 
|---|
| 68 | $params['limit'] = array((($page-1)*$nb_per_page),$nb_per_page); | 
|---|
| 69 | $params['no_content'] = true; | 
|---|
| 70 |  | 
|---|
| 71 | # Author filter | 
|---|
| 72 | if ($author !== '') { | 
|---|
| 73 | $params['q_author'] = $author; | 
|---|
| 74 | $show_filters = true; | 
|---|
| 75 | } | 
|---|
| 76 |  | 
|---|
| 77 | # - Type filter | 
|---|
| 78 | if ($type == 'tb' || $type == 'co') { | 
|---|
| 79 | $params['comment_trackback'] = ($type == 'tb'); | 
|---|
| 80 | $show_filters = true; | 
|---|
| 81 | } | 
|---|
| 82 |  | 
|---|
| 83 | # - Status filter | 
|---|
| 84 | if ($status !== '' && in_array($status,$status_combo)) { | 
|---|
| 85 | $params['comment_status'] = $status; | 
|---|
| 86 | $show_filters = true; | 
|---|
| 87 | } elseif (!$with_spam) { | 
|---|
| 88 | $params['comment_status_not'] = -2; | 
|---|
| 89 | } | 
|---|
| 90 |  | 
|---|
| 91 | # - IP filter | 
|---|
| 92 | if ($ip) { | 
|---|
| 93 | $params['comment_ip'] = $ip; | 
|---|
| 94 | $show_filters = true; | 
|---|
| 95 | } | 
|---|
| 96 |  | 
|---|
| 97 | # Sortby and order filter | 
|---|
| 98 | if ($sortby !== '' && in_array($sortby,$sortby_combo)) { | 
|---|
| 99 | if ($order !== '' && in_array($order,$order_combo)) { | 
|---|
| 100 | $params['order'] = $sortby.' '.$order; | 
|---|
| 101 | } | 
|---|
| 102 |  | 
|---|
| 103 | if ($sortby != 'comment_dt' || $order != 'desc') { | 
|---|
| 104 | $show_filters = true; | 
|---|
| 105 | } | 
|---|
| 106 | } | 
|---|
| 107 |  | 
|---|
| 108 | # Actions combo box | 
|---|
| 109 | $combo_action = array(); | 
|---|
| 110 | $default = ''; | 
|---|
| 111 | if ($core->auth->check('publish,contentadmin',$core->blog->id)) | 
|---|
| 112 | { | 
|---|
| 113 | $combo_action[__('publish')] = 'publish'; | 
|---|
| 114 | $combo_action[__('unpublish')] = 'unpublish'; | 
|---|
| 115 | $combo_action[__('mark as pending')] = 'pending'; | 
|---|
| 116 | $combo_action[__('mark as junk')] = 'junk'; | 
|---|
| 117 | } | 
|---|
| 118 | if ($core->auth->check('delete,contentadmin',$core->blog->id)) | 
|---|
| 119 | { | 
|---|
| 120 | $combo_action[__('delete')] = 'delete'; | 
|---|
| 121 | if ($status == -2) { | 
|---|
| 122 | $default = 'delete'; | 
|---|
| 123 | } | 
|---|
| 124 | } | 
|---|
| 125 |  | 
|---|
| 126 | # --BEHAVIOR-- adminCommentsActionsCombo | 
|---|
| 127 | $core->callBehavior('adminCommentsActionsCombo',array(&$combo_action)); | 
|---|
| 128 |  | 
|---|
| 129 | /* Get comments | 
|---|
| 130 | -------------------------------------------------------- */ | 
|---|
| 131 | try { | 
|---|
| 132 | $comments = $core->blog->getComments($params); | 
|---|
| 133 | $counter = $core->blog->getComments($params,true); | 
|---|
| 134 | $comment_list = new adminCommentList($core,$comments,$counter->f(0)); | 
|---|
| 135 | } catch (Exception $e) { | 
|---|
| 136 | $core->error->add($e->getMessage()); | 
|---|
| 137 | } | 
|---|
| 138 |  | 
|---|
| 139 | /* DISPLAY | 
|---|
| 140 | -------------------------------------------------------- */ | 
|---|
| 141 | $starting_script = dcPage::jsLoad('js/_comments.js'); | 
|---|
| 142 | if (!$show_filters) { | 
|---|
| 143 | $starting_script .= dcPage::jsLoad('js/filter-controls.js'); | 
|---|
| 144 | } | 
|---|
| 145 | # --BEHAVIOR-- adminCommentsHeaders | 
|---|
| 146 | $starting_script .= $core->callBehavior('adminCommentsHeaders'); | 
|---|
| 147 |  | 
|---|
| 148 | dcPage::open(__('Comments and trackbacks'),$starting_script); | 
|---|
| 149 |  | 
|---|
| 150 | echo '<h2>'.html::escapeHTML($core->blog->name).' › <span class="page-title">'.__('Comments and trackbacks').'</span></h2>'; | 
|---|
| 151 |  | 
|---|
| 152 | if (!$core->error->flag()) | 
|---|
| 153 | { | 
|---|
| 154 | # Filters | 
|---|
| 155 | if (!$show_filters) { | 
|---|
| 156 | echo '<p><a id="filter-control" class="form-control" href="#">'. | 
|---|
| 157 | __('Filters').'</a></p>'; | 
|---|
| 158 | } | 
|---|
| 159 |  | 
|---|
| 160 | echo | 
|---|
| 161 | '<form action="comments.php" method="get" id="filters-form">'. | 
|---|
| 162 | '<fieldset><legend>'.__('Filters').'</legend>'. | 
|---|
| 163 | '<div class="three-cols">'. | 
|---|
| 164 | '<div class="col">'. | 
|---|
| 165 | '<label for="type">'.__('Type:').' '. | 
|---|
| 166 | form::combo('type',$type_combo,$type). | 
|---|
| 167 | '</label> '. | 
|---|
| 168 | '<label for="status">'.__('Status:').' '. | 
|---|
| 169 | form::combo('status',$status_combo,$status). | 
|---|
| 170 | '</label>'. | 
|---|
| 171 | '</div>'. | 
|---|
| 172 |  | 
|---|
| 173 | '<div class="col">'. | 
|---|
| 174 | '<p><label for="sortby">'.__('Order by:').' '. | 
|---|
| 175 | form::combo('sortby',$sortby_combo,$sortby). | 
|---|
| 176 | '</label> '. | 
|---|
| 177 | '<label for="order">'.__('Sort:').' '. | 
|---|
| 178 | form::combo('order',$order_combo,$order). | 
|---|
| 179 | '</label></p>'. | 
|---|
| 180 | '<p><label for="nb" class="classic">'.  form::field('nb',3,3,$nb_per_page).' '. | 
|---|
| 181 | __('Comments per page').'</label></p>'. | 
|---|
| 182 | '</div>'. | 
|---|
| 183 |  | 
|---|
| 184 | '<div class="col">'. | 
|---|
| 185 | '<p><label for="author">'.__('Comment author:').' '. | 
|---|
| 186 | form::field('author',20,255,html::escapeHTML($author)). | 
|---|
| 187 | '</label>'. | 
|---|
| 188 | '<label for="ip">'.__('IP address:').' '. | 
|---|
| 189 | form::field('ip',20,39,html::escapeHTML($ip)). | 
|---|
| 190 | '</label></p>'. | 
|---|
| 191 | '<p><input type="submit" value="'.__('Apply filters').'" /></p>'. | 
|---|
| 192 | '</div>'. | 
|---|
| 193 |  | 
|---|
| 194 | '</div>'. | 
|---|
| 195 | '<br class="clear" />'. //Opera sucks | 
|---|
| 196 | '</fieldset>'. | 
|---|
| 197 | '</form>'; | 
|---|
| 198 |  | 
|---|
| 199 | if (!$with_spam) { | 
|---|
| 200 | $spam_count = $core->blog->getComments(array('comment_status'=>-2),true)->f(0); | 
|---|
| 201 | if ($spam_count == 1) { | 
|---|
| 202 | echo '<p>'.sprintf(__('You have one spam comments.'),'<strong>'.$spam_count.'</strong>').' '. | 
|---|
| 203 | '<a href="comments.php?status=-2">'.__('Show it.').'</a></p>'; | 
|---|
| 204 | } elseif ($spam_count > 1) { | 
|---|
| 205 | echo '<p>'.sprintf(__('You have %s spam comments.'),'<strong>'.$spam_count.'</strong>').' '. | 
|---|
| 206 | '<a href="comments.php?status=-2">'.__('Show them.').'</a></p>'; | 
|---|
| 207 | } | 
|---|
| 208 | } | 
|---|
| 209 |  | 
|---|
| 210 | # Show comments | 
|---|
| 211 | $comment_list->display($page,$nb_per_page, | 
|---|
| 212 | '<form action="comments_actions.php" method="post" id="form-comments">'. | 
|---|
| 213 |  | 
|---|
| 214 | '%s'. | 
|---|
| 215 |  | 
|---|
| 216 | '<div class="two-cols">'. | 
|---|
| 217 | '<p class="col checkboxes-helpers"></p>'. | 
|---|
| 218 |  | 
|---|
| 219 | '<p class="col right"><label for="action" class="classic">'.__('Selected comments action:').'</label> '. | 
|---|
| 220 | form::combo('action',$combo_action,$default,'','','','title="'.__('action: ').'"'). | 
|---|
| 221 | $core->formNonce(). | 
|---|
| 222 | '<input type="submit" value="'.__('ok').'" /></p>'. | 
|---|
| 223 | form::hidden(array('type'),$type). | 
|---|
| 224 | form::hidden(array('sortby'),$sortby). | 
|---|
| 225 | form::hidden(array('order'),$order). | 
|---|
| 226 | form::hidden(array('author'),preg_replace('/%/','%%',$author)). | 
|---|
| 227 | form::hidden(array('status'),$status). | 
|---|
| 228 | form::hidden(array('ip'),preg_replace('/%/','%%',$ip)). | 
|---|
| 229 | form::hidden(array('page'),$page). | 
|---|
| 230 | form::hidden(array('nb'),$nb_per_page). | 
|---|
| 231 | '</div>'. | 
|---|
| 232 |  | 
|---|
| 233 | '</form>' | 
|---|
| 234 | ); | 
|---|
| 235 | } | 
|---|
| 236 |  | 
|---|
| 237 | dcPage::helpBlock('core_comments'); | 
|---|
| 238 | dcPage::close(); | 
|---|
| 239 | ?> | 
|---|