[0] | 1 | <?php |
---|
| 2 | # -- BEGIN LICENSE BLOCK --------------------------------------- |
---|
| 3 | # |
---|
| 4 | # This file is part of Dotclear 2. |
---|
| 5 | # |
---|
| 6 | # Copyright (c) 2003-2010 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 | |
---|
[452] | 14 | /** |
---|
| 15 | @ingroup DC_CORE |
---|
| 16 | @nosubgrouping |
---|
| 17 | @brief Dotclear Pager class. |
---|
| 18 | |
---|
| 19 | Dotclear Pager handles pagination for every admin list. |
---|
| 20 | */ |
---|
[449] | 21 | class dcPager extends pager |
---|
| 22 | { |
---|
| 23 | public function getLinks() |
---|
| 24 | { |
---|
| 25 | $htmlText = ''; |
---|
| 26 | $htmlStart = ''; |
---|
| 27 | $htmlEnd = ''; |
---|
| 28 | $htmlPrev = ''; |
---|
| 29 | $htmlNext = ''; |
---|
| 30 | $htmlDirectAccess = ''; |
---|
| 31 | $htmlHidden = ''; |
---|
| 32 | |
---|
| 33 | $this->setURL(); |
---|
| 34 | |
---|
| 35 | # Page text |
---|
[452] | 36 | $htmlText = sprintf(__('Page %s over %s'),$this->env,$this->nb_pages).' '; |
---|
[449] | 37 | |
---|
| 38 | # Previous page |
---|
| 39 | if($this->env != 1) { |
---|
| 40 | $htmlPrev = '<a href="'.sprintf($this->page_url,$this->env-1).'" class="prev">'. |
---|
| 41 | $htmlPrev .= $this->html_prev.'</a> '; |
---|
| 42 | } |
---|
| 43 | |
---|
| 44 | # Next page |
---|
| 45 | if($this->env != $this->nb_pages) { |
---|
| 46 | $htmlNext = ' <a href="'.sprintf($this->page_url,$this->env+1).'" class="next">'; |
---|
| 47 | $htmlNext .= $this->html_next.'</a>'; |
---|
| 48 | } |
---|
| 49 | |
---|
| 50 | # Start |
---|
| 51 | if($this->env != 1) { |
---|
| 52 | $htmlStart = '<a href="'.sprintf($this->page_url,1).'" class="start">'. |
---|
| 53 | $htmlStart .= $this->html_start.'</a> '; |
---|
| 54 | } |
---|
| 55 | |
---|
| 56 | # End |
---|
| 57 | if($this->env != $this->nb_pages) { |
---|
| 58 | $htmlEnd = ' <a href="'.sprintf($this->page_url,$this->nb_elements).'" class="end">'. |
---|
| 59 | $htmlEnd .= $this->html_end.'</a> '; |
---|
| 60 | } |
---|
| 61 | |
---|
| 62 | # Direct acces |
---|
| 63 | $htmlDirectAccess = |
---|
| 64 | '<span>'.__('Direct access to page').' '. |
---|
| 65 | form::field('page',3,3,$this->env).' '. |
---|
| 66 | '<input type="submit" value="'.__('ok').'" />'. |
---|
| 67 | '<span>'; |
---|
| 68 | |
---|
| 69 | # Hidden fields |
---|
| 70 | foreach ($_GET as $k => $v) { |
---|
| 71 | if ($k != $this->var_page) { |
---|
| 72 | $htmlHidden .= form::hidden(array($k),$v); |
---|
| 73 | } |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | $res = |
---|
| 77 | '<form method="get" action="'.$this->base_url.'">'. |
---|
| 78 | $htmlStart. |
---|
| 79 | $htmlPrev. |
---|
| 80 | $htmlText. |
---|
| 81 | $htmlNext. |
---|
| 82 | $htmlEnd. |
---|
| 83 | $htmlDirectAccess. |
---|
| 84 | $htmlHidden. |
---|
| 85 | '</form>'; |
---|
| 86 | |
---|
| 87 | return $this->nb_elements > 0 ? $res : ''; |
---|
| 88 | } |
---|
| 89 | } |
---|
| 90 | |
---|
[452] | 91 | /** |
---|
| 92 | @ingroup DC_CORE |
---|
| 93 | @nosubgrouping |
---|
| 94 | @brief Dotclear Generic column class. |
---|
| 95 | |
---|
| 96 | Dotclear Generic column handles each column object use in adminGenericList class. |
---|
| 97 | */ |
---|
[238] | 98 | class adminGenericColumn |
---|
| 99 | { |
---|
[452] | 100 | protected $core; /// <b>object</b> dcCore object |
---|
| 101 | protected $id; /// <b>string</b> ID of defined column |
---|
| 102 | protected $title; /// <b>string</b> Title of defined column |
---|
| 103 | protected $callback; /// <b>array</b> Callback calls to display defined column |
---|
| 104 | protected $html; /// <b>string</b> Extra HTML for defined column |
---|
| 105 | protected $visibility; /// <b>boolean</b> Visibility of defined column |
---|
[238] | 106 | |
---|
[452] | 107 | /** |
---|
| 108 | Inits Generic column object |
---|
| 109 | |
---|
| 110 | @param id <b>string</b> Column id |
---|
| 111 | @param title <b>string</b> Column title (for table headers) |
---|
| 112 | @param callback <b>array</b> Column callback (used for display) |
---|
| 113 | @param html <b>string</b> Extra html (used for table headers) |
---|
| 114 | @param can_hide <b>boolean</b> Defines if the column can be hidden or not |
---|
| 115 | */ |
---|
[418] | 116 | public function __construct($id,$title,$callback,$html = null,$can_hide = true) |
---|
[238] | 117 | { |
---|
| 118 | if (!is_string($id) || $id === '') { |
---|
| 119 | throw new Exception(__('Invalid column ID')); |
---|
| 120 | } |
---|
| 121 | |
---|
| 122 | if (!is_string($title)) { |
---|
| 123 | throw new Exception(__('Invalid column title')); |
---|
| 124 | } |
---|
[242] | 125 | |
---|
[238] | 126 | if (is_null($html) || !is_string($html)) { |
---|
| 127 | $html = ''; |
---|
| 128 | } |
---|
[242] | 129 | if (!empty($html)) { |
---|
| 130 | $html = ' '.$html; |
---|
| 131 | } |
---|
| 132 | |
---|
[418] | 133 | if (!is_bool($can_hide)) { |
---|
| 134 | $can_hide = true; |
---|
| 135 | } |
---|
| 136 | |
---|
[238] | 137 | try { |
---|
[242] | 138 | if (!is_array($callback) || count($callback) < 2) { |
---|
| 139 | throw new Exception(__('Callback parameter should be an array')); |
---|
| 140 | } |
---|
[238] | 141 | $r = new ReflectionClass($callback[0]); |
---|
| 142 | $f = $r->getMethod($callback[1]); |
---|
| 143 | $p = $r->getParentClass(); |
---|
| 144 | if (!$p || $p->name != 'adminGenericList') { |
---|
[242] | 145 | throw new Exception(__('Callback class should be inherited of adminGenericList class')); |
---|
[238] | 146 | } |
---|
| 147 | } |
---|
| 148 | catch (Exception $e) { |
---|
[242] | 149 | throw new Exception(sprintf(__('Invalid column callback: %s'),$e->getMessage())); |
---|
[238] | 150 | } |
---|
| 151 | |
---|
| 152 | $this->id = $id; |
---|
| 153 | $this->title = $title; |
---|
| 154 | $this->callback = $callback; |
---|
| 155 | $this->html = $html; |
---|
[418] | 156 | $this->can_hide = $can_hide; |
---|
[238] | 157 | $this->visibility = true; |
---|
| 158 | } |
---|
| 159 | |
---|
[452] | 160 | /** |
---|
| 161 | Gets information of defined column |
---|
| 162 | |
---|
| 163 | @param info <b>string</b> Column info to retrive |
---|
| 164 | |
---|
| 165 | @return <b>mixed</b> The information requested, null otherwise |
---|
| 166 | */ |
---|
| 167 | public function getInfo($info) |
---|
[238] | 168 | { |
---|
[452] | 169 | return property_exists(get_class($this),$info) ? $this->{$info} : null; |
---|
[238] | 170 | } |
---|
| 171 | |
---|
[452] | 172 | /** |
---|
| 173 | Sets visibility of defined column |
---|
| 174 | |
---|
| 175 | @param visibility <b>boolean</b> Column visibility |
---|
| 176 | */ |
---|
[238] | 177 | public function setVisibility($visibility) |
---|
| 178 | { |
---|
| 179 | if (is_bool($visibility)) { |
---|
| 180 | $this->visibility = $visibility; |
---|
| 181 | } |
---|
| 182 | } |
---|
| 183 | |
---|
[452] | 184 | /** |
---|
| 185 | Returns visibility status of defined column |
---|
| 186 | |
---|
| 187 | @return <b>boolean</b> true if column is visible, false otherwise |
---|
| 188 | */ |
---|
[238] | 189 | public function isVisible() |
---|
| 190 | { |
---|
| 191 | return $this->visibility; |
---|
| 192 | } |
---|
[418] | 193 | |
---|
[452] | 194 | /** |
---|
| 195 | Returns if the defined column can be hidden |
---|
| 196 | |
---|
| 197 | @return <b>boolean</b> true if column can be hidden, false otherwise |
---|
| 198 | */ |
---|
[418] | 199 | public function canHide() |
---|
| 200 | { |
---|
| 201 | return $this->can_hide; |
---|
| 202 | } |
---|
[238] | 203 | } |
---|
| 204 | |
---|
[452] | 205 | /** |
---|
| 206 | @ingroup DC_CORE |
---|
| 207 | @nosubgrouping |
---|
| 208 | @brief abstract Generic list class. |
---|
| 209 | |
---|
| 210 | Dotclear Generic list handles administration lists |
---|
| 211 | */ |
---|
| 212 | abstract class adminGenericList |
---|
[0] | 213 | { |
---|
| 214 | protected $core; |
---|
| 215 | protected $rs; |
---|
| 216 | protected $rs_count; |
---|
[238] | 217 | protected $columns; |
---|
| 218 | |
---|
[452] | 219 | /* |
---|
| 220 | Sets columns of defined list |
---|
| 221 | */ |
---|
| 222 | abstract function setColumns(); |
---|
| 223 | |
---|
| 224 | /** |
---|
| 225 | Inits List object |
---|
| 226 | |
---|
| 227 | @param core <b>dcCore</b> dcCore object |
---|
| 228 | @param rs <b>recordSet</b> Items recordSet to display |
---|
| 229 | @param rs_count <b>int</b> Total items number |
---|
| 230 | */ |
---|
[0] | 231 | public function __construct($core,$rs,$rs_count) |
---|
| 232 | { |
---|
| 233 | $this->core =& $core; |
---|
| 234 | $this->rs =& $rs; |
---|
| 235 | $this->rs_count = $rs_count; |
---|
[238] | 236 | $this->context = get_class($this); |
---|
| 237 | $this->columns = array(); |
---|
[242] | 238 | $this->form_prefix = 'col_%s'; |
---|
| 239 | $this->form_trigger = 'add_filter'; |
---|
[238] | 240 | |
---|
[449] | 241 | $this->html_prev = __('prev'); |
---|
| 242 | $this->html_next = __('next'); |
---|
| 243 | $this->html_start = __('start'); |
---|
| 244 | $this->html_end = __('end'); |
---|
[238] | 245 | |
---|
[452] | 246 | $this->setColumns(); |
---|
[238] | 247 | |
---|
[452] | 248 | $core->callBehavior('adminListConstruct',$this); |
---|
[276] | 249 | |
---|
[238] | 250 | $this->setColumnsVisibility(); |
---|
[0] | 251 | } |
---|
[238] | 252 | |
---|
[452] | 253 | /** |
---|
| 254 | Returns HTML code form used to choose which column to display |
---|
[238] | 255 | |
---|
[452] | 256 | @return <b>string</b> HTML code form |
---|
| 257 | */ |
---|
[242] | 258 | public function getColumnsForm() |
---|
| 259 | { |
---|
| 260 | $block = |
---|
| 261 | '<h3>'.__('Displayed information').'</h3>'. |
---|
| 262 | '<ul>%s</ul>'; |
---|
| 263 | |
---|
| 264 | $list = array(); |
---|
| 265 | |
---|
[452] | 266 | foreach ($this->columns as $k => $v) { |
---|
[242] | 267 | $col_id = sprintf($this->form_prefix,$k); |
---|
| 268 | $col_label = sprintf('<label for="%s">%s</label>',$col_id,$v->getInfo('title')); |
---|
[418] | 269 | $col_html = sprintf('<li class="line">%s</li>',$col_label.form::checkbox($col_id,1,$v->isVisible(),null,null,!$v->canHide())); |
---|
[242] | 270 | |
---|
| 271 | array_push($list,$col_html); |
---|
| 272 | } |
---|
| 273 | |
---|
[437] | 274 | $nb_per_page = isset($_GET['nb']) ? $_GET['nb'] : 10; |
---|
| 275 | |
---|
| 276 | array_push($list,'<label for="nb" class="classic">'.__('Items per page:').'</label> '.form::field('nb',3,3,$nb_per_page)); |
---|
| 277 | |
---|
| 278 | return sprintf($block,implode('',$list)); |
---|
[242] | 279 | } |
---|
| 280 | |
---|
[452] | 281 | /** |
---|
| 282 | Returns HTML code list to display |
---|
| 283 | |
---|
| 284 | @param page <b>string|int</b> Current page |
---|
| 285 | @param nb_per_page <b>string|int</b> Number of items to display in each page |
---|
| 286 | @param enclose_block <b>string</b> HTML wrapper of defined list |
---|
| 287 | |
---|
| 288 | @return <b>string</b> HTML code list |
---|
| 289 | */ |
---|
| 290 | public function display($page,$nb_per_page,$enclose_block = '') |
---|
[0] | 291 | { |
---|
| 292 | if ($this->rs->isEmpty()) |
---|
| 293 | { |
---|
| 294 | echo '<p><strong>'.__('No entry').'</strong></p>'; |
---|
| 295 | } |
---|
| 296 | else |
---|
| 297 | { |
---|
[449] | 298 | $pager = new dcPager($page,$this->rs_count,$nb_per_page,10); |
---|
[0] | 299 | $pager->html_prev = $this->html_prev; |
---|
| 300 | $pager->html_next = $this->html_next; |
---|
[449] | 301 | $pager->html_start = $this->html_start; |
---|
| 302 | $pager->html_end = $this->html_end; |
---|
[0] | 303 | $pager->var_page = 'page'; |
---|
| 304 | |
---|
[431] | 305 | $html_block = |
---|
| 306 | '<table class="maximal clear">'. |
---|
[432] | 307 | $this->getCaption($page). |
---|
[431] | 308 | '<thead><tr>'; |
---|
[238] | 309 | |
---|
[452] | 310 | foreach ($this->columns as $k => $v) { |
---|
[238] | 311 | if ($v->isVisible()) { |
---|
[431] | 312 | $html_extra = $v->getInfo('html') != '' ? ' '.$v->getInfo('html') : ''; |
---|
| 313 | $html_block .= sprintf('<th scope="col"%s>%s</th>',$html_extra,$v->getInfo('title')); |
---|
[238] | 314 | } |
---|
| 315 | } |
---|
| 316 | |
---|
[431] | 317 | $html_block .= |
---|
| 318 | '</tr></thead>'. |
---|
| 319 | '<tbody>%s</tbody>'. |
---|
| 320 | '</table>'; |
---|
[0] | 321 | |
---|
| 322 | if ($enclose_block) { |
---|
| 323 | $html_block = sprintf($enclose_block,$html_block); |
---|
| 324 | } |
---|
| 325 | |
---|
[449] | 326 | echo '<div class="pagination">'.$pager->getLinks().'</div>'; |
---|
[0] | 327 | |
---|
| 328 | $blocks = explode('%s',$html_block); |
---|
| 329 | |
---|
| 330 | echo $blocks[0]; |
---|
| 331 | |
---|
| 332 | while ($this->rs->fetch()) |
---|
| 333 | { |
---|
[238] | 334 | echo $this->displayLine(); |
---|
[0] | 335 | } |
---|
| 336 | |
---|
| 337 | echo $blocks[1]; |
---|
| 338 | |
---|
[449] | 339 | echo '<div class="pagination">'.$pager->getLinks().'</div>'; |
---|
[0] | 340 | } |
---|
| 341 | } |
---|
| 342 | |
---|
[452] | 343 | /** |
---|
| 344 | Adds column to defined list |
---|
| 345 | |
---|
| 346 | @param id <b>string</b> Column id |
---|
| 347 | @param title <b>string</b> Column title (for table headers) |
---|
| 348 | @param callback <b>array</b> Column callback (used for display) |
---|
| 349 | @param html <b>string</b> Extra html (used for table headers) |
---|
| 350 | @param can_hide <b>boolean</b> Defines if the column can be hidden or not |
---|
| 351 | */ |
---|
| 352 | protected function addColumn($id,$title,$callback,$html = null,$can_hide = true) |
---|
| 353 | { |
---|
| 354 | try { |
---|
| 355 | $c = new adminGenericColumn($id,$title,$callback,$html,$can_hide); |
---|
| 356 | $this->columns[$id] = $c; |
---|
| 357 | } |
---|
| 358 | catch (Exception $e) { |
---|
| 359 | if (DC_DEBUG) { |
---|
| 360 | $this->core->error->add($e->getMessage()); |
---|
| 361 | } |
---|
| 362 | } |
---|
| 363 | } |
---|
| 364 | |
---|
| 365 | /** |
---|
| 366 | Returns default caption text |
---|
| 367 | |
---|
| 368 | @return <b>string</b> Default caption |
---|
| 369 | */ |
---|
| 370 | protected function getDefaultCaption() |
---|
| 371 | { |
---|
| 372 | return; |
---|
| 373 | } |
---|
| 374 | |
---|
| 375 | /** |
---|
| 376 | Returns default HTMl code line |
---|
| 377 | |
---|
| 378 | @return <b>string</b> Default HTMl code line |
---|
| 379 | */ |
---|
| 380 | protected function getDefaultLine() |
---|
| 381 | { |
---|
| 382 | return '<tr class="line">%s</tr>'; |
---|
| 383 | } |
---|
| 384 | |
---|
| 385 | /** |
---|
| 386 | Sets columns visibility of defined list |
---|
| 387 | */ |
---|
| 388 | private function setColumnsVisibility() |
---|
| 389 | { |
---|
| 390 | $ws = $this->core->auth->user_prefs->addWorkspace('lists'); |
---|
| 391 | |
---|
| 392 | $user_pref = !is_null($ws->{$this->context}) ? unserialize($ws->{$this->context}) : array(); |
---|
| 393 | |
---|
| 394 | foreach ($this->columns as $k => $v) { |
---|
| 395 | $visibility = array_key_exists($k,$user_pref) ? $user_pref[$k] : true; |
---|
| 396 | if (array_key_exists($this->form_trigger,$_REQUEST)) { |
---|
| 397 | $key = sprintf($this->form_prefix,$k); |
---|
| 398 | $visibility = !array_key_exists($key,$_REQUEST) ? false : true; |
---|
| 399 | } |
---|
| 400 | if (!$v->canHide()) { |
---|
| 401 | $visibility = true; |
---|
| 402 | } |
---|
| 403 | $v->setVisibility($visibility); |
---|
| 404 | $user_pref[$k] = $visibility; |
---|
| 405 | } |
---|
| 406 | |
---|
| 407 | if (array_key_exists($this->form_trigger,$_REQUEST)) { |
---|
| 408 | $this->core->auth->user_prefs->lists->put($this->context,serialize($user_pref),'string'); |
---|
| 409 | } |
---|
| 410 | } |
---|
| 411 | |
---|
| 412 | /** |
---|
| 413 | Returns HTML code for each line of defined list |
---|
| 414 | |
---|
| 415 | @return <b>string</b> HTML code line |
---|
| 416 | */ |
---|
[238] | 417 | private function displayLine() |
---|
| 418 | { |
---|
| 419 | $res = ''; |
---|
| 420 | |
---|
[452] | 421 | foreach ($this->columns as $k => $v) { |
---|
[238] | 422 | if ($v->isVisible()) { |
---|
| 423 | $c = $v->getInfo('callback'); |
---|
| 424 | $func = $c[1]; |
---|
| 425 | $res .= $this->{$c[1]}(); |
---|
| 426 | } |
---|
| 427 | } |
---|
| 428 | |
---|
| 429 | return sprintf($this->getDefaultLine(),$res); |
---|
| 430 | } |
---|
| 431 | |
---|
[452] | 432 | /** |
---|
| 433 | Returns caption of defined list |
---|
| 434 | |
---|
| 435 | @param page <b>string|int</b> Current page |
---|
| 436 | |
---|
| 437 | @return <b>string</b> HTML caption tag |
---|
| 438 | */ |
---|
[432] | 439 | private function getCaption($page) |
---|
| 440 | { |
---|
| 441 | $caption = $this->getDefaultCaption(); |
---|
| 442 | |
---|
| 443 | if (!empty($caption)) { |
---|
| 444 | $caption = sprintf( |
---|
| 445 | '<caption>%s - %s</caption>', |
---|
| 446 | $caption,sprintf(__('Page %s'),$page) |
---|
| 447 | ); |
---|
| 448 | } |
---|
| 449 | |
---|
| 450 | return $caption; |
---|
| 451 | } |
---|
[452] | 452 | } |
---|
| 453 | |
---|
| 454 | /** |
---|
| 455 | @ingroup DC_CORE |
---|
| 456 | @nosubgrouping |
---|
| 457 | @brief abstract posts list class. |
---|
| 458 | |
---|
| 459 | Handle posts list on admin side |
---|
| 460 | */ |
---|
| 461 | class adminPostList extends adminGenericList |
---|
| 462 | { |
---|
| 463 | public function setColumns() |
---|
[432] | 464 | { |
---|
[452] | 465 | $this->addColumn('title',__('Title'),array('adminPostList','getTitle'),' class="maximal"',false); |
---|
| 466 | $this->addColumn('date',__('Date'),array('adminPostList','getDate')); |
---|
| 467 | $this->addColumn('datetime',__('Date and time'),array('adminPostList','getDateTime')); |
---|
| 468 | $this->addColumn('category',__('Category'),array('adminPostList','getCategory')); |
---|
| 469 | $this->addColumn('author',__('Author'),array('adminPostList','getAuthor')); |
---|
| 470 | $this->addColumn('comment',__('Comments'),array('adminPostList','getComments')); |
---|
| 471 | $this->addColumn('trackback',__('Trackbacks'),array('adminPostList','getTrackbacks')); |
---|
| 472 | $this->addColumn('status',__('Status'),array('adminPostList','getStatus')); |
---|
[432] | 473 | } |
---|
| 474 | |
---|
| 475 | protected function getDefaultCaption() |
---|
| 476 | { |
---|
| 477 | return __('Entries list'); |
---|
| 478 | } |
---|
| 479 | |
---|
[238] | 480 | protected function getDefaultLine() |
---|
| 481 | { |
---|
| 482 | return |
---|
| 483 | '<tr class="line'.($this->rs->post_status != 1 ? ' offline' : '').'"'. |
---|
| 484 | ' id="p'.$this->rs->post_id.'">%s</tr>'; |
---|
| 485 | } |
---|
| 486 | |
---|
| 487 | protected function getTitle() |
---|
| 488 | { |
---|
| 489 | return |
---|
[431] | 490 | '<th scope="row" class="maximal">'. |
---|
| 491 | form::checkbox(array('entries[]'),$this->rs->post_id,'','','',!$this->rs->isEditable()).' '. |
---|
[238] | 492 | '<a href="'.$this->core->getPostAdminURL($this->rs->post_type,$this->rs->post_id).'">'. |
---|
[431] | 493 | html::escapeHTML($this->rs->post_title).'</a></th>'; |
---|
[238] | 494 | } |
---|
| 495 | |
---|
| 496 | protected function getDate() |
---|
| 497 | { |
---|
[433] | 498 | return '<td class="nowrap">'.dt::dt2str(__('%Y-%m-%d'),$this->rs->post_dt).'</td>'; |
---|
| 499 | } |
---|
| 500 | |
---|
| 501 | protected function getDateTime() |
---|
| 502 | { |
---|
[238] | 503 | return '<td class="nowrap">'.dt::dt2str(__('%Y-%m-%d %H:%M'),$this->rs->post_dt).'</td>'; |
---|
| 504 | } |
---|
| 505 | |
---|
| 506 | protected function getCategory() |
---|
[0] | 507 | { |
---|
| 508 | if ($this->core->auth->check('categories',$this->core->blog->id)) { |
---|
| 509 | $cat_link = '<a href="category.php?id=%s">%s</a>'; |
---|
| 510 | } else { |
---|
| 511 | $cat_link = '%2$s'; |
---|
| 512 | } |
---|
| 513 | |
---|
| 514 | if ($this->rs->cat_title) { |
---|
| 515 | $cat_title = sprintf($cat_link,$this->rs->cat_id, |
---|
| 516 | html::escapeHTML($this->rs->cat_title)); |
---|
| 517 | } else { |
---|
| 518 | $cat_title = __('None'); |
---|
| 519 | } |
---|
| 520 | |
---|
[238] | 521 | return '<td class="nowrap">'.$cat_title.'</td>'; |
---|
[0] | 522 | } |
---|
| 523 | |
---|
[238] | 524 | protected function getAuthor() |
---|
| 525 | { |
---|
| 526 | return '<td class="nowrap">'.$this->rs->user_id.'</td>'; |
---|
| 527 | } |
---|
| 528 | |
---|
| 529 | protected function getComments() |
---|
| 530 | { |
---|
| 531 | return '<td class="nowrap">'.$this->rs->nb_comment.'</td>'; |
---|
| 532 | } |
---|
| 533 | |
---|
| 534 | protected function getTrackbacks() |
---|
| 535 | { |
---|
| 536 | return '<td class="nowrap">'.$this->rs->nb_trackback.'</td>'; |
---|
| 537 | } |
---|
| 538 | |
---|
| 539 | protected function getStatus() |
---|
[0] | 540 | { |
---|
| 541 | $img = '<img alt="%1$s" title="%1$s" src="images/%2$s" />'; |
---|
| 542 | switch ($this->rs->post_status) { |
---|
| 543 | case 1: |
---|
| 544 | $img_status = sprintf($img,__('published'),'check-on.png'); |
---|
| 545 | break; |
---|
| 546 | case 0: |
---|
| 547 | $img_status = sprintf($img,__('unpublished'),'check-off.png'); |
---|
| 548 | break; |
---|
| 549 | case -1: |
---|
| 550 | $img_status = sprintf($img,__('scheduled'),'scheduled.png'); |
---|
| 551 | break; |
---|
| 552 | case -2: |
---|
| 553 | $img_status = sprintf($img,__('pending'),'check-wrn.png'); |
---|
| 554 | break; |
---|
| 555 | } |
---|
| 556 | |
---|
| 557 | $protected = ''; |
---|
| 558 | if ($this->rs->post_password) { |
---|
| 559 | $protected = sprintf($img,__('protected'),'locker.png'); |
---|
| 560 | } |
---|
| 561 | |
---|
| 562 | $selected = ''; |
---|
| 563 | if ($this->rs->post_selected) { |
---|
| 564 | $selected = sprintf($img,__('selected'),'selected.png'); |
---|
| 565 | } |
---|
| 566 | |
---|
| 567 | $attach = ''; |
---|
| 568 | $nb_media = $this->rs->countMedia(); |
---|
| 569 | if ($nb_media > 0) { |
---|
| 570 | $attach_str = $nb_media == 1 ? __('%d attachment') : __('%d attachments'); |
---|
| 571 | $attach = sprintf($img,sprintf($attach_str,$nb_media),'attach.png'); |
---|
| 572 | } |
---|
| 573 | |
---|
[238] | 574 | return '<td class="nowrap status">'.$img_status.' '.$selected.' '.$protected.' '.$attach.'</td>'; |
---|
[0] | 575 | } |
---|
| 576 | } |
---|
| 577 | |
---|
[452] | 578 | /** |
---|
| 579 | @ingroup DC_CORE |
---|
| 580 | @nosubgrouping |
---|
| 581 | @brief abstract mini posts list class. |
---|
| 582 | |
---|
| 583 | Handle mini posts list on admin side (used for link popup) |
---|
| 584 | */ |
---|
[418] | 585 | class adminPostMiniList extends adminPostList |
---|
| 586 | { |
---|
[452] | 587 | public function setColumns() |
---|
| 588 | { |
---|
| 589 | $this->addColumn('title',__('Title'),array('adminPostList','getTitle'),' class="maximal"',false); |
---|
| 590 | $this->addColumn('date',__('Date'),array('adminPostList','getDate')); |
---|
| 591 | $this->addColumn('author',__('Author'),array('adminPostList','getAuthor')); |
---|
| 592 | $this->addColumn('status',__('Status'),array('adminPostList','getStatus')); |
---|
| 593 | } |
---|
| 594 | |
---|
[418] | 595 | protected function getTitle() |
---|
| 596 | { |
---|
| 597 | return |
---|
[431] | 598 | '<th scope="row" class="maximal">'. |
---|
| 599 | form::checkbox(array('entries[]'),$this->rs->post_id,'','','',!$this->rs->isEditable()).' '. |
---|
[418] | 600 | '<a href="'.$this->core->getPostAdminURL($this->rs->post_type,$this->rs->post_id).'" '. |
---|
| 601 | 'title="'.html::escapeHTML($this->rs->getURL()).'">'. |
---|
| 602 | html::escapeHTML($this->rs->post_title).'</a></td>'; |
---|
| 603 | } |
---|
| 604 | } |
---|
[238] | 605 | |
---|
[452] | 606 | /** |
---|
| 607 | @ingroup DC_CORE |
---|
| 608 | @nosubgrouping |
---|
| 609 | @brief abstract comments list class. |
---|
| 610 | |
---|
| 611 | Handle comments list on admin side |
---|
| 612 | */ |
---|
[0] | 613 | class adminCommentList extends adminGenericList |
---|
| 614 | { |
---|
[452] | 615 | public function setColumns() |
---|
| 616 | { |
---|
| 617 | $this->addColumn('title',__('Title'),array('adminCommentList','getTitle'),' class="maximal"',false); |
---|
| 618 | $this->addColumn('date',__('Date'),array('adminCommentList','getDate')); |
---|
| 619 | $this->addColumn('author',__('Author'),array('adminCommentList','getAuthor')); |
---|
| 620 | $this->addColumn('type',__('Type'),array('adminCommentList','getType')); |
---|
| 621 | $this->addColumn('status',__('Status'),array('adminCommentList','getStatus')); |
---|
| 622 | $this->addColumn('edit','',array('adminCommentList','getEdit')); |
---|
| 623 | } |
---|
| 624 | |
---|
[432] | 625 | protected function getDefaultCaption() |
---|
| 626 | { |
---|
| 627 | return __('Comments list'); |
---|
| 628 | } |
---|
| 629 | |
---|
[238] | 630 | protected function getDefaultLine() |
---|
[0] | 631 | { |
---|
[238] | 632 | return |
---|
| 633 | '<tr class="line'.($this->rs->comment_status != 1 ? ' offline' : '').'"'. |
---|
| 634 | ' id="c'.$this->rs->comment_id.'">%s</tr>'; |
---|
[0] | 635 | } |
---|
| 636 | |
---|
[238] | 637 | protected function getTitle() |
---|
| 638 | { |
---|
| 639 | $post_url = $this->core->getPostAdminURL($this->rs->post_type,$this->rs->post_id); |
---|
| 640 | |
---|
| 641 | return |
---|
[431] | 642 | '<th scope="row" class="maximal">'. |
---|
| 643 | form::checkbox(array('comments[]'),$this->rs->comment_id,'','','',0).' '. |
---|
[242] | 644 | '<a href="'.$post_url.'">'. |
---|
[238] | 645 | html::escapeHTML($this->rs->post_title).'</a>'. |
---|
[431] | 646 | ($this->rs->post_type != 'post' ? ' ('.html::escapeHTML($this->rs->post_type).')' : '').'</th>'; |
---|
[238] | 647 | } |
---|
| 648 | |
---|
| 649 | protected function getDate() |
---|
| 650 | { |
---|
| 651 | return '<td class="nowrap">'.dt::dt2str(__('%Y-%m-%d %H:%M'),$this->rs->comment_dt).'</td>'; |
---|
| 652 | } |
---|
| 653 | |
---|
| 654 | protected function getAuthor() |
---|
[0] | 655 | { |
---|
| 656 | global $author, $status, $sortby, $order, $nb_per_page; |
---|
| 657 | |
---|
| 658 | $author_url = |
---|
| 659 | 'comments.php?n='.$nb_per_page. |
---|
| 660 | '&status='.$status. |
---|
| 661 | '&sortby='.$sortby. |
---|
| 662 | '&order='.$order. |
---|
| 663 | '&author='.rawurlencode($this->rs->comment_author); |
---|
| 664 | |
---|
[238] | 665 | $comment_author = html::escapeHTML($this->rs->comment_author); |
---|
| 666 | if (mb_strlen($comment_author) > 20) { |
---|
| 667 | $comment_author = mb_strcut($comment_author,0,17).'...'; |
---|
| 668 | } |
---|
[0] | 669 | |
---|
[238] | 670 | return '<td class="nowrap"><a href="'.$author_url.'">'.$comment_author.'</a></td>'; |
---|
| 671 | } |
---|
| 672 | |
---|
| 673 | protected function getType() |
---|
| 674 | { |
---|
| 675 | return '<td class="nowrap">'.($this->rs->comment_trackback ? __('trackback') : __('comment')).'</td>'; |
---|
| 676 | } |
---|
| 677 | |
---|
| 678 | protected function getStatus() |
---|
| 679 | { |
---|
[0] | 680 | $img = '<img alt="%1$s" title="%1$s" src="images/%2$s" />'; |
---|
| 681 | switch ($this->rs->comment_status) { |
---|
| 682 | case 1: |
---|
| 683 | $img_status = sprintf($img,__('published'),'check-on.png'); |
---|
| 684 | break; |
---|
| 685 | case 0: |
---|
| 686 | $img_status = sprintf($img,__('unpublished'),'check-off.png'); |
---|
| 687 | break; |
---|
| 688 | case -1: |
---|
| 689 | $img_status = sprintf($img,__('pending'),'check-wrn.png'); |
---|
| 690 | break; |
---|
| 691 | case -2: |
---|
| 692 | $img_status = sprintf($img,__('junk'),'junk.png'); |
---|
| 693 | break; |
---|
| 694 | } |
---|
| 695 | |
---|
[238] | 696 | return '<td class="nowrap status">'.$img_status.'</td>'; |
---|
| 697 | } |
---|
| 698 | |
---|
| 699 | protected function getEdit() |
---|
| 700 | { |
---|
| 701 | $comment_url = 'comment.php?id='.$this->rs->comment_id; |
---|
[0] | 702 | |
---|
[238] | 703 | return |
---|
[0] | 704 | '<td class="nowrap status"><a href="'.$comment_url.'">'. |
---|
| 705 | '<img src="images/edit-mini.png" alt="" title="'.__('Edit this comment').'" /></a></td>'; |
---|
| 706 | } |
---|
| 707 | } |
---|
| 708 | |
---|
[452] | 709 | /** |
---|
| 710 | @ingroup DC_CORE |
---|
| 711 | @nosubgrouping |
---|
| 712 | @brief abstract users list class. |
---|
| 713 | |
---|
| 714 | Handle users list on admin side |
---|
| 715 | */ |
---|
[0] | 716 | class adminUserList extends adminGenericList |
---|
| 717 | { |
---|
[452] | 718 | public function setColumns() |
---|
| 719 | { |
---|
| 720 | $this->addColumn('username',__('Username'),array('adminUserList','getUserName'),'class="maximal"',false); |
---|
| 721 | $this->addColumn('firstname',__('First name'),array('adminUserList','getFirstName'),'class="nowrap"'); |
---|
| 722 | $this->addColumn('lastname',__('Last name'),array('adminUserList','getLastName'),'class="nowrap"'); |
---|
| 723 | $this->addColumn('displayname',__('Display name'),array('adminUserList','getDisplayName'),'class="nowrap"'); |
---|
| 724 | $this->addColumn('entries',__('Entries'),array('adminUserList','getEntries'),'class="nowrap"'); |
---|
| 725 | } |
---|
| 726 | |
---|
[432] | 727 | protected function getDefaultCaption() |
---|
| 728 | { |
---|
| 729 | return __('Users list'); |
---|
| 730 | } |
---|
| 731 | |
---|
[238] | 732 | protected function getUserName() |
---|
[0] | 733 | { |
---|
| 734 | $img = '<img alt="%1$s" title="%1$s" src="images/%2$s" />'; |
---|
| 735 | $img_status = ''; |
---|
| 736 | |
---|
| 737 | $p = $this->core->getUserPermissions($this->rs->user_id); |
---|
| 738 | |
---|
| 739 | if (isset($p[$this->core->blog->id]['p']['admin'])) { |
---|
| 740 | $img_status = sprintf($img,__('admin'),'admin.png'); |
---|
| 741 | } |
---|
| 742 | if ($this->rs->user_super) { |
---|
| 743 | $img_status = sprintf($img,__('superadmin'),'superadmin.png'); |
---|
| 744 | } |
---|
[238] | 745 | |
---|
[0] | 746 | return |
---|
[431] | 747 | '<th scope="row" class="maximal">'.form::hidden(array('nb_post[]'),(integer) $this->rs->nb_post). |
---|
[242] | 748 | form::checkbox(array('user_id[]'),$this->rs->user_id).' '. |
---|
[238] | 749 | '<a href="user.php?id='.$this->rs->user_id.'">'. |
---|
[431] | 750 | $this->rs->user_id.'</a> '.$img_status.'</th>'; |
---|
[238] | 751 | } |
---|
| 752 | |
---|
| 753 | protected function getFirstName() |
---|
| 754 | { |
---|
| 755 | return '<td class="nowrap">'.$this->rs->user_firstname.'</td>'; |
---|
| 756 | } |
---|
| 757 | |
---|
| 758 | protected function getLastName() |
---|
| 759 | { |
---|
| 760 | return '<td class="nowrap">'.$this->rs->user_name.'</td>'; |
---|
| 761 | } |
---|
| 762 | |
---|
| 763 | protected function getDisplayName() |
---|
| 764 | { |
---|
| 765 | return '<td class="nowrap">'.$this->rs->user_displayname.'</td>'; |
---|
| 766 | } |
---|
| 767 | |
---|
| 768 | protected function getEntries() |
---|
| 769 | { |
---|
| 770 | return |
---|
[0] | 771 | '<td class="nowrap"><a href="posts.php?user_id='.$this->rs->user_id.'">'. |
---|
[238] | 772 | $this->rs->nb_post.'</a></td>'; |
---|
[0] | 773 | } |
---|
| 774 | } |
---|
[238] | 775 | |
---|
[0] | 776 | ?> |
---|