| 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 | if (!defined('DC_RC_PATH')) { return; } |
|---|
| 13 | |
|---|
| 14 | class dcPager extends pager |
|---|
| 15 | { |
|---|
| 16 | protected $form_action; |
|---|
| 17 | protected $form_hidden; |
|---|
| 18 | |
|---|
| 19 | protected function getLink($li_class,$href,$img_src,$img_src_nolink,$img_alt,$enable_link) { |
|---|
| 20 | if ($enable_link) { |
|---|
| 21 | $formatter = '<li class="%s btn"><a href="%s"><img src="%s" alt="%s"/></a><span class="hidden">%s</span></li>'; |
|---|
| 22 | return sprintf ($formatter, |
|---|
| 23 | $li_class,$href,$img_src,$img_alt,$img_alt); |
|---|
| 24 | } else { |
|---|
| 25 | $formatter = '<li class="%s no-link btn"><img src="%s" alt="%s"/></li>'; |
|---|
| 26 | return sprintf ($formatter, |
|---|
| 27 | $li_class,$img_src_nolink,$img_alt,$img_alt); |
|---|
| 28 | } |
|---|
| 29 | } |
|---|
| 30 | public function setURL() { |
|---|
| 31 | parent::setURL(); |
|---|
| 32 | $url = parse_url($_SERVER['REQUEST_URI']); |
|---|
| 33 | if (isset($url['query'])) { |
|---|
| 34 | parse_str($url['query'],$args); |
|---|
| 35 | } else { |
|---|
| 36 | $args=array(); |
|---|
| 37 | } |
|---|
| 38 | # Removing session information |
|---|
| 39 | if (session_id()) |
|---|
| 40 | { |
|---|
| 41 | if (isset($args[session_name()])) |
|---|
| 42 | unset($args[session_name()]); |
|---|
| 43 | } |
|---|
| 44 | if (isset($args[$this->var_page])) { |
|---|
| 45 | unset($args[$this->var_page]); |
|---|
| 46 | } |
|---|
| 47 | if (isset($args['ok'])) { |
|---|
| 48 | unset($args['ok']); |
|---|
| 49 | } |
|---|
| 50 | $this->form_hidden = ''; |
|---|
| 51 | foreach ($args as $k=>$v) { |
|---|
| 52 | if (is_array($v)) { |
|---|
| 53 | foreach ($v as $k2=>$v2) { |
|---|
| 54 | $this->form_hidden .= form::hidden(array($k.'[]'),html::escapeHTML($v2)); |
|---|
| 55 | } |
|---|
| 56 | } else { |
|---|
| 57 | $this->form_hidden .= form::hidden(array($k),html::escapeHTML($v)); |
|---|
| 58 | } |
|---|
| 59 | } |
|---|
| 60 | $this->form_action = $url['path']; |
|---|
| 61 | } |
|---|
| 62 | |
|---|
| 63 | /** |
|---|
| 64 | * Pager Links |
|---|
| 65 | * |
|---|
| 66 | * Returns pager links |
|---|
| 67 | * |
|---|
| 68 | * @return string |
|---|
| 69 | */ |
|---|
| 70 | public function getLinks() |
|---|
| 71 | { |
|---|
| 72 | $this->setURL(); |
|---|
| 73 | $htmlFirst = $this->getLink( |
|---|
| 74 | "first", |
|---|
| 75 | sprintf($this->page_url,1), |
|---|
| 76 | "images/pagination/first.png", |
|---|
| 77 | "images/pagination/no-first.png", |
|---|
| 78 | __('First page'), |
|---|
| 79 | ($this->env > 1) |
|---|
| 80 | ); |
|---|
| 81 | $htmlPrev = $this->getLink( |
|---|
| 82 | "prev", |
|---|
| 83 | sprintf($this->page_url,$this->env-1), |
|---|
| 84 | "images/pagination/previous.png", |
|---|
| 85 | "images/pagination/no-previous.png", |
|---|
| 86 | __('Previous page'), |
|---|
| 87 | ($this->env > 1) |
|---|
| 88 | ); |
|---|
| 89 | $htmlNext = $this->getLink( |
|---|
| 90 | "next", |
|---|
| 91 | sprintf($this->page_url,$this->env+1), |
|---|
| 92 | "images/pagination/next.png", |
|---|
| 93 | "images/pagination/no-next.png", |
|---|
| 94 | __('Next page'), |
|---|
| 95 | ($this->env < $this->nb_pages) |
|---|
| 96 | ); |
|---|
| 97 | $htmlLast = $this->getLink( |
|---|
| 98 | "last", |
|---|
| 99 | sprintf($this->page_url,$this->nb_pages), |
|---|
| 100 | "images/pagination/last.png", |
|---|
| 101 | "images/pagination/no-last.png", |
|---|
| 102 | __('Last page'), |
|---|
| 103 | ($this->env < $this->nb_pages) |
|---|
| 104 | ); |
|---|
| 105 | $htmlCurrent = |
|---|
| 106 | '<li class="active"><strong>'. |
|---|
| 107 | sprintf(__('Page %s / %s'),$this->env,$this->nb_pages). |
|---|
| 108 | '</strong></li>'; |
|---|
| 109 | |
|---|
| 110 | $htmlDirect = |
|---|
| 111 | ($this->nb_pages > 1 ? |
|---|
| 112 | sprintf('<li class="direct-access">'.__('Direct access page %s'), |
|---|
| 113 | form::field(array($this->var_page),3,10)). |
|---|
| 114 | '<input type="submit" value="'.__('ok').'" class="reset" '. |
|---|
| 115 | 'name="ok" />'.$this->form_hidden.'</li>' : ''); |
|---|
| 116 | |
|---|
| 117 | $res = |
|---|
| 118 | '<form action="'.$this->form_action.'" method="get">'. |
|---|
| 119 | '<div class="pager"><ul>'. |
|---|
| 120 | $htmlFirst. |
|---|
| 121 | $htmlPrev. |
|---|
| 122 | $htmlCurrent. |
|---|
| 123 | $htmlNext. |
|---|
| 124 | $htmlLast. |
|---|
| 125 | $htmlDirect. |
|---|
| 126 | '</ul>'. |
|---|
| 127 | '</div>'. |
|---|
| 128 | '</form>' |
|---|
| 129 | ; |
|---|
| 130 | |
|---|
| 131 | return $this->nb_elements > 0 ? $res : ''; |
|---|
| 132 | } |
|---|
| 133 | } |
|---|
| 134 | |
|---|
| 135 | class adminGenericList |
|---|
| 136 | { |
|---|
| 137 | protected $core; |
|---|
| 138 | protected $rs; |
|---|
| 139 | protected $rs_count; |
|---|
| 140 | |
|---|
| 141 | public function __construct($core,$rs,$rs_count) |
|---|
| 142 | { |
|---|
| 143 | $this->core =& $core; |
|---|
| 144 | $this->rs =& $rs; |
|---|
| 145 | $this->rs_count = $rs_count; |
|---|
| 146 | $this->html_prev = __('« prev.'); |
|---|
| 147 | $this->html_next = __('next »'); |
|---|
| 148 | } |
|---|
| 149 | } |
|---|
| 150 | |
|---|
| 151 | class adminPostList extends adminGenericList |
|---|
| 152 | { |
|---|
| 153 | public function display($page,$nb_per_page,$enclose_block='',$filter=false) |
|---|
| 154 | { |
|---|
| 155 | if ($this->rs->isEmpty()) |
|---|
| 156 | { |
|---|
| 157 | if( $filter ) { |
|---|
| 158 | echo '<p><strong>'.__('No entry matches the filter').'</strong></p>'; |
|---|
| 159 | } else { |
|---|
| 160 | echo '<p><strong>'.__('No entry').'</strong></p>'; |
|---|
| 161 | } |
|---|
| 162 | } |
|---|
| 163 | else |
|---|
| 164 | { |
|---|
| 165 | $pager = new dcPager($page,$this->rs_count,$nb_per_page,10); |
|---|
| 166 | $entries = array(); |
|---|
| 167 | if (isset($_REQUEST['entries'])) { |
|---|
| 168 | foreach ($_REQUEST['entries'] as $v) { |
|---|
| 169 | $entries[(integer)$v]=true; |
|---|
| 170 | } |
|---|
| 171 | } |
|---|
| 172 | $html_block = |
|---|
| 173 | '<div class="table-outer">'. |
|---|
| 174 | '<table>'; |
|---|
| 175 | |
|---|
| 176 | if( $filter ) { |
|---|
| 177 | $html_block .= '<caption>'.sprintf(__('List of %s entries match the filter.'), $this->rs_count).'</caption>'; |
|---|
| 178 | } else { |
|---|
| 179 | $html_block .= '<caption class="hidden">'.__('Entries list').'</caption>'; |
|---|
| 180 | } |
|---|
| 181 | |
|---|
| 182 | $cols = array( |
|---|
| 183 | 'title' => '<th colspan="2" class="first">'.__('Title').'</th>', |
|---|
| 184 | 'date' => '<th scope="col">'.__('Date').'</th>', |
|---|
| 185 | 'category' => '<th scope="col">'.__('Category').'</th>', |
|---|
| 186 | 'author' => '<th scope="col">'.__('Author').'</th>', |
|---|
| 187 | 'comments' => '<th scope="col"><img src="images/comments.png" alt="" title="'.__('Comments'). |
|---|
| 188 | '" /><span class="hidden">'.__('Comments').'</span></th>', |
|---|
| 189 | 'trackbacks' => '<th scope="col"><img src="images/trackbacks.png" alt="" title="'.__('Trackbacks'). |
|---|
| 190 | '" /><span class="hidden">'.__('Trackbacks').'</span></th>', |
|---|
| 191 | 'status' => '<th scope="col">'.__('Status').'</th>' |
|---|
| 192 | ); |
|---|
| 193 | $cols = new ArrayObject($cols); |
|---|
| 194 | $this->core->callBehavior('adminPostListHeader',$this->core,$this->rs,$cols); |
|---|
| 195 | |
|---|
| 196 | $html_block .= '<tr>'.implode(iterator_to_array($cols)).'</tr>%s</table></div>'; |
|---|
| 197 | if ($enclose_block) { |
|---|
| 198 | $html_block = sprintf($enclose_block,$html_block); |
|---|
| 199 | } |
|---|
| 200 | |
|---|
| 201 | echo $pager->getLinks(); |
|---|
| 202 | |
|---|
| 203 | $blocks = explode('%s',$html_block); |
|---|
| 204 | |
|---|
| 205 | echo $blocks[0]; |
|---|
| 206 | |
|---|
| 207 | while ($this->rs->fetch()) |
|---|
| 208 | { |
|---|
| 209 | echo $this->postLine(isset($entries[$this->rs->post_id])); |
|---|
| 210 | } |
|---|
| 211 | |
|---|
| 212 | echo $blocks[1]; |
|---|
| 213 | |
|---|
| 214 | echo $pager->getLinks(); |
|---|
| 215 | } |
|---|
| 216 | } |
|---|
| 217 | |
|---|
| 218 | private function postLine($checked) |
|---|
| 219 | { |
|---|
| 220 | if ($this->core->auth->check('categories',$this->core->blog->id)) { |
|---|
| 221 | $cat_link = '<a href="'.$this->core->adminurl->get('admin.category',array('id' => '%s'),'&',true).'">%s</a>'; |
|---|
| 222 | } else { |
|---|
| 223 | $cat_link = '%2$s'; |
|---|
| 224 | } |
|---|
| 225 | |
|---|
| 226 | if ($this->rs->cat_title) { |
|---|
| 227 | $cat_title = sprintf($cat_link,$this->rs->cat_id, |
|---|
| 228 | html::escapeHTML($this->rs->cat_title)); |
|---|
| 229 | } else { |
|---|
| 230 | $cat_title = __('(No cat)'); |
|---|
| 231 | } |
|---|
| 232 | |
|---|
| 233 | $img = '<img alt="%1$s" title="%1$s" src="images/%2$s" />'; |
|---|
| 234 | $sts_class = ''; |
|---|
| 235 | switch ($this->rs->post_status) { |
|---|
| 236 | case 1: |
|---|
| 237 | $img_status = sprintf($img,__('Published'),'check-on.png'); |
|---|
| 238 | $sts_class = 'sts-online'; |
|---|
| 239 | break; |
|---|
| 240 | case 0: |
|---|
| 241 | $img_status = sprintf($img,__('Unpublished'),'check-off.png'); |
|---|
| 242 | $sts_class = 'sts-offline'; |
|---|
| 243 | break; |
|---|
| 244 | case -1: |
|---|
| 245 | $img_status = sprintf($img,__('Scheduled'),'scheduled.png'); |
|---|
| 246 | $sts_class = 'sts-scheduled'; |
|---|
| 247 | break; |
|---|
| 248 | case -2: |
|---|
| 249 | $img_status = sprintf($img,__('Pending'),'check-wrn.png'); |
|---|
| 250 | $sts_class = 'sts-pending'; |
|---|
| 251 | break; |
|---|
| 252 | } |
|---|
| 253 | |
|---|
| 254 | $protected = ''; |
|---|
| 255 | if ($this->rs->post_password) { |
|---|
| 256 | $protected = sprintf($img,__('Protected'),'locker.png'); |
|---|
| 257 | } |
|---|
| 258 | |
|---|
| 259 | $selected = ''; |
|---|
| 260 | if ($this->rs->post_selected) { |
|---|
| 261 | $selected = sprintf($img,__('Selected'),'selected.png'); |
|---|
| 262 | } |
|---|
| 263 | |
|---|
| 264 | $attach = ''; |
|---|
| 265 | $nb_media = $this->rs->countMedia(); |
|---|
| 266 | if ($nb_media > 0) { |
|---|
| 267 | $attach_str = $nb_media == 1 ? __('%d attachment') : __('%d attachments'); |
|---|
| 268 | $attach = sprintf($img,sprintf($attach_str,$nb_media),'attach.png'); |
|---|
| 269 | } |
|---|
| 270 | |
|---|
| 271 | $res = '<tr class="line '.($this->rs->post_status != 1 ? 'offline ' : '').$sts_class.'"'. |
|---|
| 272 | ' id="p'.$this->rs->post_id.'">'; |
|---|
| 273 | |
|---|
| 274 | $cols = array( |
|---|
| 275 | 'check' => '<td class="nowrap">'. |
|---|
| 276 | form::checkbox(array('entries[]'),$this->rs->post_id,$checked,'','',!$this->rs->isEditable()). |
|---|
| 277 | '</td>', |
|---|
| 278 | 'title' => '<td class="maximal" scope="row"><a href="'. |
|---|
| 279 | $this->core->getPostAdminURL($this->rs->post_type,$this->rs->post_id).'">'. |
|---|
| 280 | html::escapeHTML($this->rs->post_title).'</a></td>', |
|---|
| 281 | 'date' => '<td class="nowrap count">'.dt::dt2str(__('%Y-%m-%d %H:%M'),$this->rs->post_dt).'</td>', |
|---|
| 282 | 'category' => '<td class="nowrap">'.$cat_title.'</td>', |
|---|
| 283 | 'author' => '<td class="nowrap">'.html::escapeHTML($this->rs->user_id).'</td>', |
|---|
| 284 | 'comments' => '<td class="nowrap count">'.$this->rs->nb_comment.'</td>', |
|---|
| 285 | 'trackbacks' => '<td class="nowrap count">'.$this->rs->nb_trackback.'</td>', |
|---|
| 286 | 'status' => '<td class="nowrap status">'.$img_status.' '.$selected.' '.$protected.' '.$attach.'</td>' |
|---|
| 287 | ); |
|---|
| 288 | $cols = new ArrayObject($cols); |
|---|
| 289 | $this->core->callBehavior('adminPostListValue',$this->core,$this->rs,$cols); |
|---|
| 290 | |
|---|
| 291 | $res .= implode(iterator_to_array($cols)); |
|---|
| 292 | $res .= '</tr>'; |
|---|
| 293 | |
|---|
| 294 | return $res; |
|---|
| 295 | } |
|---|
| 296 | } |
|---|
| 297 | |
|---|
| 298 | class adminPostMiniList extends adminGenericList |
|---|
| 299 | { |
|---|
| 300 | public function display($page,$nb_per_page,$enclose_block='') |
|---|
| 301 | { |
|---|
| 302 | if ($this->rs->isEmpty()) |
|---|
| 303 | { |
|---|
| 304 | echo '<p><strong>'.__('No entry').'</strong></p>'; |
|---|
| 305 | } |
|---|
| 306 | else |
|---|
| 307 | { |
|---|
| 308 | $pager = new dcPager($page,$this->rs_count,$nb_per_page,10); |
|---|
| 309 | |
|---|
| 310 | $html_block = |
|---|
| 311 | '<div class="table-outer clear">'. |
|---|
| 312 | '<table><caption class="hidden">'.__('Entries list').'</caption><tr>'; |
|---|
| 313 | |
|---|
| 314 | $cols = array( |
|---|
| 315 | 'title' => '<th scope="col">'.__('Title').'</th>', |
|---|
| 316 | 'date' => '<th scope="col">'.__('Date').'</th>', |
|---|
| 317 | 'author' => '<th scope="col">'.__('Author').'</th>', |
|---|
| 318 | 'status' => '<th scope="col">'.__('Status').'</th>' |
|---|
| 319 | ); |
|---|
| 320 | |
|---|
| 321 | $cols = new ArrayObject($cols); |
|---|
| 322 | $this->core->callBehavior('adminPostMiniListHeader',$this->core,$this->rs,$cols); |
|---|
| 323 | |
|---|
| 324 | $html_block .= '<tr>'.implode(iterator_to_array($cols)).'</tr>%s</table></div>'; |
|---|
| 325 | if ($enclose_block) { |
|---|
| 326 | $html_block = sprintf($enclose_block,$html_block); |
|---|
| 327 | } |
|---|
| 328 | |
|---|
| 329 | echo $pager->getLinks(); |
|---|
| 330 | |
|---|
| 331 | $blocks = explode('%s',$html_block); |
|---|
| 332 | |
|---|
| 333 | echo $blocks[0]; |
|---|
| 334 | |
|---|
| 335 | while ($this->rs->fetch()) |
|---|
| 336 | { |
|---|
| 337 | echo $this->postLine(); |
|---|
| 338 | } |
|---|
| 339 | |
|---|
| 340 | echo $blocks[1]; |
|---|
| 341 | |
|---|
| 342 | echo $pager->getLinks(); |
|---|
| 343 | } |
|---|
| 344 | } |
|---|
| 345 | |
|---|
| 346 | private function postLine() |
|---|
| 347 | { |
|---|
| 348 | $img = '<img alt="%1$s" title="%1$s" src="images/%2$s" />'; |
|---|
| 349 | $sts_class = ''; |
|---|
| 350 | switch ($this->rs->post_status) { |
|---|
| 351 | case 1: |
|---|
| 352 | $img_status = sprintf($img,__('Published'),'check-on.png'); |
|---|
| 353 | $sts_class = 'sts-online'; |
|---|
| 354 | break; |
|---|
| 355 | case 0: |
|---|
| 356 | $img_status = sprintf($img,__('Unpublished'),'check-off.png'); |
|---|
| 357 | $sts_class = 'sts-offline'; |
|---|
| 358 | break; |
|---|
| 359 | case -1: |
|---|
| 360 | $img_status = sprintf($img,__('Scheduled'),'scheduled.png'); |
|---|
| 361 | $sts_class = 'sts-scheduled'; |
|---|
| 362 | break; |
|---|
| 363 | case -2: |
|---|
| 364 | $img_status = sprintf($img,__('Pending'),'check-wrn.png'); |
|---|
| 365 | $sts_class = 'sts-pending'; |
|---|
| 366 | break; |
|---|
| 367 | } |
|---|
| 368 | |
|---|
| 369 | $protected = ''; |
|---|
| 370 | if ($this->rs->post_password) { |
|---|
| 371 | $protected = sprintf($img,__('Protected'),'locker.png'); |
|---|
| 372 | } |
|---|
| 373 | |
|---|
| 374 | $selected = ''; |
|---|
| 375 | if ($this->rs->post_selected) { |
|---|
| 376 | $selected = sprintf($img,__('Selected'),'selected.png'); |
|---|
| 377 | } |
|---|
| 378 | |
|---|
| 379 | $attach = ''; |
|---|
| 380 | $nb_media = $this->rs->countMedia(); |
|---|
| 381 | if ($nb_media > 0) { |
|---|
| 382 | $attach_str = $nb_media == 1 ? __('%d attachment') : __('%d attachments'); |
|---|
| 383 | $attach = sprintf($img,sprintf($attach_str,$nb_media),'attach.png'); |
|---|
| 384 | } |
|---|
| 385 | |
|---|
| 386 | $res = '<tr class="line '.($this->rs->post_status != 1 ? 'offline ' : '').$sts_class.'"'. |
|---|
| 387 | ' id="p'.$this->rs->post_id.'">'; |
|---|
| 388 | |
|---|
| 389 | $cols = array( |
|---|
| 390 | 'title' => '<td scope="row" class="maximal"><a href="'. |
|---|
| 391 | $this->core->getPostAdminURL($this->rs->post_type,$this->rs->post_id).'" '. |
|---|
| 392 | 'title="'.html::escapeHTML($this->rs->getURL()).'">'. |
|---|
| 393 | html::escapeHTML($this->rs->post_title).'</a></td>', |
|---|
| 394 | 'date' => '<td class="nowrap count">'.dt::dt2str(__('%Y-%m-%d %H:%M'),$this->rs->post_dt).'</td>', |
|---|
| 395 | 'author' => '<td class="nowrap">'.html::escapeHTML($this->rs->user_id).'</td>', |
|---|
| 396 | 'status' => '<td class="nowrap status">'.$img_status.' '.$selected.' '.$protected.' '.$attach.'</td>' |
|---|
| 397 | ); |
|---|
| 398 | |
|---|
| 399 | $cols = new ArrayObject($cols); |
|---|
| 400 | $this->core->callBehavior('adminPostMiniListValue',$this->core,$this->rs,$cols); |
|---|
| 401 | |
|---|
| 402 | $res .= implode(iterator_to_array($cols)); |
|---|
| 403 | $res .= '</tr>'; |
|---|
| 404 | |
|---|
| 405 | return $res; |
|---|
| 406 | } |
|---|
| 407 | } |
|---|
| 408 | |
|---|
| 409 | class adminCommentList extends adminGenericList |
|---|
| 410 | { |
|---|
| 411 | public function display($page,$nb_per_page,$enclose_block='',$filter=false,$spam=false) |
|---|
| 412 | { |
|---|
| 413 | if ($this->rs->isEmpty()) |
|---|
| 414 | { |
|---|
| 415 | if( $filter ) { |
|---|
| 416 | echo '<p><strong>'.__('No comments or trackbacks matches the filter').'</strong></p>'; |
|---|
| 417 | } else { |
|---|
| 418 | echo '<p><strong>'.__('No comments').'</strong></p>'; |
|---|
| 419 | } |
|---|
| 420 | } |
|---|
| 421 | else |
|---|
| 422 | { |
|---|
| 423 | // Get antispam filters' name |
|---|
| 424 | $filters = array(); |
|---|
| 425 | if ($spam) { |
|---|
| 426 | if (class_exists('dcAntispam')) { |
|---|
| 427 | dcAntispam::initFilters(); |
|---|
| 428 | $fs = dcAntispam::$filters->getFilters(); |
|---|
| 429 | foreach ($fs as $fid => $f) |
|---|
| 430 | { |
|---|
| 431 | $filters[$fid] = $f->name; |
|---|
| 432 | } |
|---|
| 433 | } |
|---|
| 434 | } |
|---|
| 435 | |
|---|
| 436 | $pager = new dcPager($page,$this->rs_count,$nb_per_page,10); |
|---|
| 437 | |
|---|
| 438 | $comments = array(); |
|---|
| 439 | if (isset($_REQUEST['comments'])) { |
|---|
| 440 | foreach ($_REQUEST['comments'] as $v) { |
|---|
| 441 | $comments[(integer)$v]=true; |
|---|
| 442 | } |
|---|
| 443 | } |
|---|
| 444 | $html_block = |
|---|
| 445 | '<div class="table-outer">'. |
|---|
| 446 | '<table>'; |
|---|
| 447 | |
|---|
| 448 | if( $filter ) { |
|---|
| 449 | $html_block .= '<caption>'. |
|---|
| 450 | sprintf(__( |
|---|
| 451 | 'Comment or trackback matching the filter.', |
|---|
| 452 | 'List of %s comments or trackbacks matching the filter.', |
|---|
| 453 | $this->rs_count), $this->rs_count). |
|---|
| 454 | '</caption>'; |
|---|
| 455 | } else { |
|---|
| 456 | $html_block .= '<caption class="hidden">'.__('Comments and trackbacks list').'</caption>'; |
|---|
| 457 | } |
|---|
| 458 | |
|---|
| 459 | $cols = array( |
|---|
| 460 | 'type' => '<th colspan="2" scope="col" abbr="comm" class="first">'.__('Type').'</th>', |
|---|
| 461 | 'author' => '<th scope="col">'.__('Author').'</th>', |
|---|
| 462 | 'date' => '<th scope="col">'.__('Date').'</th>', |
|---|
| 463 | 'status' => '<th scope="col" class="txt-center">'.__('Status').'</th>' |
|---|
| 464 | ); |
|---|
| 465 | if ($spam) { |
|---|
| 466 | $cols['ip'] = '<th scope="col">'.__('IP').'</th>'; |
|---|
| 467 | $cols['spam_filter'] = '<th scope="col">'.__('Spam filter').'</th>'; |
|---|
| 468 | } |
|---|
| 469 | $cols['entry'] = '<th scope="col" abbr="entry">'.__('Entry').'</th>'; |
|---|
| 470 | |
|---|
| 471 | $cols = new ArrayObject($cols); |
|---|
| 472 | $this->core->callBehavior('adminCommentListHeader',$this->core,$this->rs,$cols); |
|---|
| 473 | |
|---|
| 474 | $html_block .= '<tr>'.implode(iterator_to_array($cols)).'</tr>%s</table></div>'; |
|---|
| 475 | |
|---|
| 476 | if ($enclose_block) { |
|---|
| 477 | $html_block = sprintf($enclose_block,$html_block); |
|---|
| 478 | } |
|---|
| 479 | |
|---|
| 480 | echo $pager->getLinks(); |
|---|
| 481 | |
|---|
| 482 | $blocks = explode('%s',$html_block); |
|---|
| 483 | |
|---|
| 484 | echo $blocks[0]; |
|---|
| 485 | |
|---|
| 486 | while ($this->rs->fetch()) |
|---|
| 487 | { |
|---|
| 488 | echo $this->commentLine(isset($comments[$this->rs->comment_id]),$spam,$filters); |
|---|
| 489 | } |
|---|
| 490 | |
|---|
| 491 | echo $blocks[1]; |
|---|
| 492 | |
|---|
| 493 | echo $pager->getLinks(); |
|---|
| 494 | } |
|---|
| 495 | } |
|---|
| 496 | |
|---|
| 497 | private function commentLine($checked=false,$spam=false,$filters=array()) |
|---|
| 498 | { |
|---|
| 499 | global $core, $author, $status, $sortby, $order, $nb_per_page; |
|---|
| 500 | |
|---|
| 501 | $author_url = |
|---|
| 502 | $this->core->adminurl->get('admin.comments',array( |
|---|
| 503 | 'n' => $nb_per_page, |
|---|
| 504 | 'status' => $status, |
|---|
| 505 | 'sortby' => $sortby, |
|---|
| 506 | 'order' => $order, |
|---|
| 507 | 'author' => $this->rs->comment_author |
|---|
| 508 | )); |
|---|
| 509 | |
|---|
| 510 | $post_url = $this->core->getPostAdminURL($this->rs->post_type,$this->rs->post_id); |
|---|
| 511 | |
|---|
| 512 | $comment_url = $this->core->adminurl->get('admin.comment',array('id' => $this->rs->comment_id)); |
|---|
| 513 | |
|---|
| 514 | $comment_dt = |
|---|
| 515 | dt::dt2str($this->core->blog->settings->system->date_format.' - '. |
|---|
| 516 | $this->core->blog->settings->system->time_format,$this->rs->comment_dt); |
|---|
| 517 | |
|---|
| 518 | $img = '<img alt="%1$s" title="%1$s" src="images/%2$s" />'; |
|---|
| 519 | $sts_class = ''; |
|---|
| 520 | switch ($this->rs->comment_status) { |
|---|
| 521 | case 1: |
|---|
| 522 | $img_status = sprintf($img,__('Published'),'check-on.png'); |
|---|
| 523 | $sts_class = 'sts-online'; |
|---|
| 524 | break; |
|---|
| 525 | case 0: |
|---|
| 526 | $img_status = sprintf($img,__('Unpublished'),'check-off.png'); |
|---|
| 527 | $sts_class = 'sts-offline'; |
|---|
| 528 | break; |
|---|
| 529 | case -1: |
|---|
| 530 | $img_status = sprintf($img,__('Pending'),'check-wrn.png'); |
|---|
| 531 | $sts_class = 'sts-pending'; |
|---|
| 532 | break; |
|---|
| 533 | case -2: |
|---|
| 534 | $img_status = sprintf($img,__('Junk'),'junk.png'); |
|---|
| 535 | $sts_class = 'sts-junk'; |
|---|
| 536 | break; |
|---|
| 537 | } |
|---|
| 538 | |
|---|
| 539 | $post_title = html::escapeHTML($this->rs->post_title); |
|---|
| 540 | if (mb_strlen($post_title) > 70) { |
|---|
| 541 | $post_title = mb_strcut($post_title,0,67).'...'; |
|---|
| 542 | } |
|---|
| 543 | $comment_title = sprintf(__('Edit the %1$s from %2$s'), |
|---|
| 544 | $this->rs->comment_trackback ? __('trackback') : __('comment'), |
|---|
| 545 | html::escapeHTML($this->rs->comment_author)); |
|---|
| 546 | |
|---|
| 547 | $res = '<tr class="line '.($this->rs->comment_status != 1 ? 'offline ' : '').$sts_class.'"'. |
|---|
| 548 | ' id="c'.$this->rs->comment_id.'">'; |
|---|
| 549 | |
|---|
| 550 | $cols = array( |
|---|
| 551 | 'check' => '<td class="nowrap">'. |
|---|
| 552 | form::checkbox(array('comments[]'),$this->rs->comment_id,$checked,'','',0).'</td>', |
|---|
| 553 | 'type' => '<td class="nowrap" abbr="'.__('Type and author').'" scope="row">'. |
|---|
| 554 | '<a href="'.$comment_url.'" title="'.$comment_title.'">'. |
|---|
| 555 | '<img src="images/edit-mini.png" alt="'.__('Edit').'"/> '. |
|---|
| 556 | ($this->rs->comment_trackback ? __('trackback') : __('comment')).' '.'</a></td>', |
|---|
| 557 | 'author' => '<td class="nowrap maximal"><a href="'.$author_url.'">'. |
|---|
| 558 | html::escapeHTML($this->rs->comment_author).'</a></td>', |
|---|
| 559 | 'date' => '<td class="nowrap count">'.dt::dt2str(__('%Y-%m-%d %H:%M'),$this->rs->comment_dt).'</td>', |
|---|
| 560 | 'status' => '<td class="nowrap status txt-center">'.$img_status.'</td>' |
|---|
| 561 | ); |
|---|
| 562 | |
|---|
| 563 | if ($spam) { |
|---|
| 564 | $filter_name = ''; |
|---|
| 565 | if ($this->rs->comment_spam_filter) { |
|---|
| 566 | if (isset($filters[$this->rs->comment_spam_filter])) { |
|---|
| 567 | $filter_name = $filters[$this->rs->comment_spam_filter]; |
|---|
| 568 | } else { |
|---|
| 569 | $filter_name = $this->rs->comment_spam_filter; |
|---|
| 570 | } |
|---|
| 571 | } |
|---|
| 572 | $cols['ip'] = '<td class="nowrap"><a href="'. |
|---|
| 573 | $core->adminurl->get("admin.comments",array('ip' => $this->rs->comment_ip)).'">'. |
|---|
| 574 | $this->rs->comment_ip.'</a></td>'; |
|---|
| 575 | $cols['spam_filter'] = '<td class="nowrap">'.$filter_name.'</td>'; |
|---|
| 576 | } |
|---|
| 577 | $cols['entry'] = '<td class="nowrap discrete"><a href="'.$post_url.'">'.$post_title.'</a>'. |
|---|
| 578 | ($this->rs->post_type != 'post' ? ' ('.html::escapeHTML($this->rs->post_type).')' : '').'</td>'; |
|---|
| 579 | |
|---|
| 580 | $cols = new ArrayObject($cols); |
|---|
| 581 | $this->core->callBehavior('adminCommentListValue',$this->core,$this->rs,$cols); |
|---|
| 582 | |
|---|
| 583 | $res .= implode(iterator_to_array($cols)); |
|---|
| 584 | $res .= '</tr>'; |
|---|
| 585 | |
|---|
| 586 | return $res; |
|---|
| 587 | } |
|---|
| 588 | } |
|---|
| 589 | |
|---|
| 590 | class adminUserList extends adminGenericList |
|---|
| 591 | { |
|---|
| 592 | public function display($page,$nb_per_page,$enclose_block='',$filter=false) |
|---|
| 593 | { |
|---|
| 594 | if ($this->rs->isEmpty()) |
|---|
| 595 | { |
|---|
| 596 | if( $filter ) { |
|---|
| 597 | echo '<p><strong>'.__('No user matches the filter').'</strong></p>'; |
|---|
| 598 | } else { |
|---|
| 599 | echo '<p><strong>'.__('No user').'</strong></p>'; |
|---|
| 600 | } |
|---|
| 601 | } |
|---|
| 602 | else |
|---|
| 603 | { |
|---|
| 604 | $pager = new dcPager($page,$this->rs_count,$nb_per_page,10); |
|---|
| 605 | |
|---|
| 606 | $html_block = |
|---|
| 607 | '<div class="table-outer clear">'. |
|---|
| 608 | '<table>'; |
|---|
| 609 | |
|---|
| 610 | if( $filter ) { |
|---|
| 611 | $html_block .= '<caption>'.sprintf(__('List of %s users match the filter.'), $this->rs_count).'</caption>'; |
|---|
| 612 | } else { |
|---|
| 613 | $html_block .= '<caption class="hidden">'.__('Users list').'</caption>'; |
|---|
| 614 | } |
|---|
| 615 | |
|---|
| 616 | $cols = array( |
|---|
| 617 | 'username' => '<th colspan="2" scope="col" class="first">'.__('Username').'</th>', |
|---|
| 618 | 'first_name' => '<th scope="col">'.__('First Name').'</th>', |
|---|
| 619 | 'last_name' => '<th scope="col">'.__('Last Name').'</th>', |
|---|
| 620 | 'display_name' => '<th scope="col">'.__('Display name').'</th>', |
|---|
| 621 | 'entries' => '<th scope="col" class="nowrap">'.__('Entries (all types)').'</th>' |
|---|
| 622 | ); |
|---|
| 623 | |
|---|
| 624 | $cols = new ArrayObject($cols); |
|---|
| 625 | $this->core->callBehavior('adminUserListHeader',$this->core,$this->rs,$cols); |
|---|
| 626 | |
|---|
| 627 | $html_block .= '<tr>'.implode(iterator_to_array($cols)).'</tr>%s</table></div>'; |
|---|
| 628 | if ($enclose_block) { |
|---|
| 629 | $html_block = sprintf($enclose_block,$html_block); |
|---|
| 630 | } |
|---|
| 631 | |
|---|
| 632 | echo $pager->getLinks(); |
|---|
| 633 | |
|---|
| 634 | $blocks = explode('%s',$html_block); |
|---|
| 635 | |
|---|
| 636 | echo $blocks[0]; |
|---|
| 637 | |
|---|
| 638 | while ($this->rs->fetch()) |
|---|
| 639 | { |
|---|
| 640 | echo $this->userLine(); |
|---|
| 641 | } |
|---|
| 642 | |
|---|
| 643 | echo $blocks[1]; |
|---|
| 644 | |
|---|
| 645 | echo $pager->getLinks(); |
|---|
| 646 | } |
|---|
| 647 | } |
|---|
| 648 | |
|---|
| 649 | private function userLine() |
|---|
| 650 | { |
|---|
| 651 | $img = '<img alt="%1$s" title="%1$s" src="images/%2$s" />'; |
|---|
| 652 | $img_status = ''; |
|---|
| 653 | |
|---|
| 654 | $p = $this->core->getUserPermissions($this->rs->user_id); |
|---|
| 655 | |
|---|
| 656 | if (isset($p[$this->core->blog->id]['p']['admin'])) { |
|---|
| 657 | $img_status = sprintf($img,__('admin'),'admin.png'); |
|---|
| 658 | } |
|---|
| 659 | if ($this->rs->user_super) { |
|---|
| 660 | $img_status = sprintf($img,__('superadmin'),'superadmin.png'); |
|---|
| 661 | } |
|---|
| 662 | |
|---|
| 663 | $res = '<tr class="line">'; |
|---|
| 664 | |
|---|
| 665 | $cols = array( |
|---|
| 666 | 'check' => '<td class="nowrap">'.form::hidden(array('nb_post[]'),(integer) $this->rs->nb_post). |
|---|
| 667 | form::checkbox(array('users[]'),$this->rs->user_id).'</td>', |
|---|
| 668 | 'username' => '<td class="maximal" scope="row"><a href="'. |
|---|
| 669 | $this->core->adminurl->get('admin.user',array('id' => $this->rs->user_id)).'">'. |
|---|
| 670 | $this->rs->user_id.'</a> '.$img_status.'</td>', |
|---|
| 671 | 'first_name' => '<td class="nowrap">'.html::escapeHTML($this->rs->user_firstname).'</td>', |
|---|
| 672 | 'last_name' => '<td class="nowrap">'.html::escapeHTML($this->rs->user_name).'</td>', |
|---|
| 673 | 'display_name' => '<td class="nowrap">'.html::escapeHTML($this->rs->user_displayname).'</td>', |
|---|
| 674 | 'entries' => '<td class="nowrap count"><a href="'. |
|---|
| 675 | $this->core->adminurl->get('admin.posts',array('user_id' => $this->rs->user_id)).'">'. |
|---|
| 676 | $this->rs->nb_post.'</a></td>' |
|---|
| 677 | ); |
|---|
| 678 | |
|---|
| 679 | $cols = new ArrayObject($cols); |
|---|
| 680 | $this->core->callBehavior('adminUserListValue',$this->core,$this->rs,$cols); |
|---|
| 681 | |
|---|
| 682 | $res .= implode(iterator_to_array($cols)); |
|---|
| 683 | $res .= '</tr>'; |
|---|
| 684 | |
|---|
| 685 | return $res; |
|---|
| 686 | } |
|---|
| 687 | } |
|---|