[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 |
---|
[453] | 36 | $htmlText = '<span>'.sprintf(__('Page %s over %s'),$this->env,$this->nb_pages).'</span>'; |
---|
[449] | 37 | |
---|
| 38 | # Previous page |
---|
| 39 | if($this->env != 1) { |
---|
| 40 | $htmlPrev = '<a href="'.sprintf($this->page_url,$this->env-1).'" class="prev">'. |
---|
[453] | 41 | $htmlPrev .= $this->html_prev.'</a>'; |
---|
[449] | 42 | } |
---|
| 43 | |
---|
| 44 | # Next page |
---|
| 45 | if($this->env != $this->nb_pages) { |
---|
[453] | 46 | $htmlNext = '<a href="'.sprintf($this->page_url,$this->env+1).'" class="next">'; |
---|
[449] | 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">'. |
---|
[453] | 53 | $htmlStart .= $this->html_start.'</a>'; |
---|
[449] | 54 | } |
---|
| 55 | |
---|
| 56 | # End |
---|
| 57 | if($this->env != $this->nb_pages) { |
---|
[453] | 58 | $htmlEnd = '<a href="'.sprintf($this->page_url,$this->nb_elements).'" class="end">'. |
---|
| 59 | $htmlEnd .= $this->html_end.'</a>'; |
---|
[449] | 60 | } |
---|
| 61 | |
---|
| 62 | # Direct acces |
---|
| 63 | $htmlDirectAccess = |
---|
| 64 | '<span>'.__('Direct access to page').' '. |
---|
[453] | 65 | form::field(array('page'),3,3,$this->env).' '. |
---|
[449] | 66 | '<input type="submit" value="'.__('ok').'" />'. |
---|
[453] | 67 | '</span>'; |
---|
[449] | 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 = |
---|
[453] | 77 | '<form method="get" action="'.$this->base_url.'"><p>'. |
---|
[449] | 78 | $htmlStart. |
---|
| 79 | $htmlPrev. |
---|
| 80 | $htmlText. |
---|
| 81 | $htmlNext. |
---|
| 82 | $htmlEnd. |
---|
| 83 | $htmlDirectAccess. |
---|
| 84 | $htmlHidden. |
---|
[453] | 85 | '</p></form>'; |
---|
[449] | 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 | |
---|
[453] | 276 | return |
---|
| 277 | sprintf($block,implode('',$list)). |
---|
| 278 | '<p><label for="nb">'.__('Items per page:'). |
---|
| 279 | '</label> '.form::field('nb',3,3,$nb_per_page). |
---|
| 280 | '</p>'; |
---|
[242] | 281 | } |
---|
| 282 | |
---|
[452] | 283 | /** |
---|
| 284 | Returns HTML code list to display |
---|
| 285 | |
---|
| 286 | @param page <b>string|int</b> Current page |
---|
| 287 | @param nb_per_page <b>string|int</b> Number of items to display in each page |
---|
| 288 | @param enclose_block <b>string</b> HTML wrapper of defined list |
---|
| 289 | |
---|
| 290 | @return <b>string</b> HTML code list |
---|
| 291 | */ |
---|
| 292 | public function display($page,$nb_per_page,$enclose_block = '') |
---|
[0] | 293 | { |
---|
| 294 | if ($this->rs->isEmpty()) |
---|
| 295 | { |
---|
| 296 | echo '<p><strong>'.__('No entry').'</strong></p>'; |
---|
| 297 | } |
---|
| 298 | else |
---|
| 299 | { |
---|
[449] | 300 | $pager = new dcPager($page,$this->rs_count,$nb_per_page,10); |
---|
[0] | 301 | $pager->html_prev = $this->html_prev; |
---|
| 302 | $pager->html_next = $this->html_next; |
---|
[449] | 303 | $pager->html_start = $this->html_start; |
---|
| 304 | $pager->html_end = $this->html_end; |
---|
[0] | 305 | $pager->var_page = 'page'; |
---|
| 306 | |
---|
[431] | 307 | $html_block = |
---|
| 308 | '<table class="maximal clear">'. |
---|
[432] | 309 | $this->getCaption($page). |
---|
[431] | 310 | '<thead><tr>'; |
---|
[238] | 311 | |
---|
[452] | 312 | foreach ($this->columns as $k => $v) { |
---|
[238] | 313 | if ($v->isVisible()) { |
---|
[431] | 314 | $html_extra = $v->getInfo('html') != '' ? ' '.$v->getInfo('html') : ''; |
---|
| 315 | $html_block .= sprintf('<th scope="col"%s>%s</th>',$html_extra,$v->getInfo('title')); |
---|
[238] | 316 | } |
---|
| 317 | } |
---|
| 318 | |
---|
[431] | 319 | $html_block .= |
---|
| 320 | '</tr></thead>'. |
---|
| 321 | '<tbody>%s</tbody>'. |
---|
| 322 | '</table>'; |
---|
[0] | 323 | |
---|
| 324 | if ($enclose_block) { |
---|
| 325 | $html_block = sprintf($enclose_block,$html_block); |
---|
| 326 | } |
---|
| 327 | |
---|
[449] | 328 | echo '<div class="pagination">'.$pager->getLinks().'</div>'; |
---|
[0] | 329 | |
---|
| 330 | $blocks = explode('%s',$html_block); |
---|
| 331 | |
---|
| 332 | echo $blocks[0]; |
---|
| 333 | |
---|
| 334 | while ($this->rs->fetch()) |
---|
| 335 | { |
---|
[238] | 336 | echo $this->displayLine(); |
---|
[0] | 337 | } |
---|
| 338 | |
---|
| 339 | echo $blocks[1]; |
---|
| 340 | |
---|
[449] | 341 | echo '<div class="pagination">'.$pager->getLinks().'</div>'; |
---|
[0] | 342 | } |
---|
| 343 | } |
---|
| 344 | |
---|
[452] | 345 | /** |
---|
| 346 | Adds column to defined list |
---|
| 347 | |
---|
| 348 | @param id <b>string</b> Column id |
---|
| 349 | @param title <b>string</b> Column title (for table headers) |
---|
| 350 | @param callback <b>array</b> Column callback (used for display) |
---|
| 351 | @param html <b>string</b> Extra html (used for table headers) |
---|
| 352 | @param can_hide <b>boolean</b> Defines if the column can be hidden or not |
---|
| 353 | */ |
---|
| 354 | protected function addColumn($id,$title,$callback,$html = null,$can_hide = true) |
---|
| 355 | { |
---|
| 356 | try { |
---|
| 357 | $c = new adminGenericColumn($id,$title,$callback,$html,$can_hide); |
---|
| 358 | $this->columns[$id] = $c; |
---|
| 359 | } |
---|
| 360 | catch (Exception $e) { |
---|
| 361 | if (DC_DEBUG) { |
---|
| 362 | $this->core->error->add($e->getMessage()); |
---|
| 363 | } |
---|
| 364 | } |
---|
| 365 | } |
---|
| 366 | |
---|
| 367 | /** |
---|
| 368 | Returns default caption text |
---|
| 369 | |
---|
| 370 | @return <b>string</b> Default caption |
---|
| 371 | */ |
---|
| 372 | protected function getDefaultCaption() |
---|
| 373 | { |
---|
| 374 | return; |
---|
| 375 | } |
---|
| 376 | |
---|
| 377 | /** |
---|
| 378 | Returns default HTMl code line |
---|
| 379 | |
---|
| 380 | @return <b>string</b> Default HTMl code line |
---|
| 381 | */ |
---|
| 382 | protected function getDefaultLine() |
---|
| 383 | { |
---|
| 384 | return '<tr class="line">%s</tr>'; |
---|
| 385 | } |
---|
| 386 | |
---|
| 387 | /** |
---|
| 388 | Sets columns visibility of defined list |
---|
| 389 | */ |
---|
| 390 | private function setColumnsVisibility() |
---|
| 391 | { |
---|
| 392 | $ws = $this->core->auth->user_prefs->addWorkspace('lists'); |
---|
| 393 | |
---|
| 394 | $user_pref = !is_null($ws->{$this->context}) ? unserialize($ws->{$this->context}) : array(); |
---|
| 395 | |
---|
| 396 | foreach ($this->columns as $k => $v) { |
---|
| 397 | $visibility = array_key_exists($k,$user_pref) ? $user_pref[$k] : true; |
---|
| 398 | if (array_key_exists($this->form_trigger,$_REQUEST)) { |
---|
| 399 | $key = sprintf($this->form_prefix,$k); |
---|
| 400 | $visibility = !array_key_exists($key,$_REQUEST) ? false : true; |
---|
| 401 | } |
---|
| 402 | if (!$v->canHide()) { |
---|
| 403 | $visibility = true; |
---|
| 404 | } |
---|
| 405 | $v->setVisibility($visibility); |
---|
| 406 | $user_pref[$k] = $visibility; |
---|
| 407 | } |
---|
| 408 | |
---|
| 409 | if (array_key_exists($this->form_trigger,$_REQUEST)) { |
---|
| 410 | $this->core->auth->user_prefs->lists->put($this->context,serialize($user_pref),'string'); |
---|
| 411 | } |
---|
| 412 | } |
---|
| 413 | |
---|
| 414 | /** |
---|
| 415 | Returns HTML code for each line of defined list |
---|
| 416 | |
---|
| 417 | @return <b>string</b> HTML code line |
---|
| 418 | */ |
---|
[238] | 419 | private function displayLine() |
---|
| 420 | { |
---|
| 421 | $res = ''; |
---|
| 422 | |
---|
[452] | 423 | foreach ($this->columns as $k => $v) { |
---|
[238] | 424 | if ($v->isVisible()) { |
---|
| 425 | $c = $v->getInfo('callback'); |
---|
| 426 | $func = $c[1]; |
---|
| 427 | $res .= $this->{$c[1]}(); |
---|
| 428 | } |
---|
| 429 | } |
---|
| 430 | |
---|
| 431 | return sprintf($this->getDefaultLine(),$res); |
---|
| 432 | } |
---|
| 433 | |
---|
[452] | 434 | /** |
---|
| 435 | Returns caption of defined list |
---|
| 436 | |
---|
| 437 | @param page <b>string|int</b> Current page |
---|
| 438 | |
---|
| 439 | @return <b>string</b> HTML caption tag |
---|
| 440 | */ |
---|
[432] | 441 | private function getCaption($page) |
---|
| 442 | { |
---|
| 443 | $caption = $this->getDefaultCaption(); |
---|
| 444 | |
---|
| 445 | if (!empty($caption)) { |
---|
| 446 | $caption = sprintf( |
---|
| 447 | '<caption>%s - %s</caption>', |
---|
| 448 | $caption,sprintf(__('Page %s'),$page) |
---|
| 449 | ); |
---|
| 450 | } |
---|
| 451 | |
---|
| 452 | return $caption; |
---|
| 453 | } |
---|
[452] | 454 | } |
---|
| 455 | |
---|
| 456 | /** |
---|
| 457 | @ingroup DC_CORE |
---|
| 458 | @nosubgrouping |
---|
| 459 | @brief abstract posts list class. |
---|
| 460 | |
---|
| 461 | Handle posts list on admin side |
---|
| 462 | */ |
---|
| 463 | class adminPostList extends adminGenericList |
---|
| 464 | { |
---|
| 465 | public function setColumns() |
---|
[432] | 466 | { |
---|
[452] | 467 | $this->addColumn('title',__('Title'),array('adminPostList','getTitle'),' class="maximal"',false); |
---|
| 468 | $this->addColumn('date',__('Date'),array('adminPostList','getDate')); |
---|
| 469 | $this->addColumn('datetime',__('Date and time'),array('adminPostList','getDateTime')); |
---|
| 470 | $this->addColumn('category',__('Category'),array('adminPostList','getCategory')); |
---|
| 471 | $this->addColumn('author',__('Author'),array('adminPostList','getAuthor')); |
---|
| 472 | $this->addColumn('comment',__('Comments'),array('adminPostList','getComments')); |
---|
| 473 | $this->addColumn('trackback',__('Trackbacks'),array('adminPostList','getTrackbacks')); |
---|
| 474 | $this->addColumn('status',__('Status'),array('adminPostList','getStatus')); |
---|
[432] | 475 | } |
---|
| 476 | |
---|
| 477 | protected function getDefaultCaption() |
---|
| 478 | { |
---|
| 479 | return __('Entries list'); |
---|
| 480 | } |
---|
| 481 | |
---|
[238] | 482 | protected function getDefaultLine() |
---|
| 483 | { |
---|
| 484 | return |
---|
| 485 | '<tr class="line'.($this->rs->post_status != 1 ? ' offline' : '').'"'. |
---|
| 486 | ' id="p'.$this->rs->post_id.'">%s</tr>'; |
---|
| 487 | } |
---|
| 488 | |
---|
| 489 | protected function getTitle() |
---|
| 490 | { |
---|
| 491 | return |
---|
[431] | 492 | '<th scope="row" class="maximal">'. |
---|
| 493 | form::checkbox(array('entries[]'),$this->rs->post_id,'','','',!$this->rs->isEditable()).' '. |
---|
[238] | 494 | '<a href="'.$this->core->getPostAdminURL($this->rs->post_type,$this->rs->post_id).'">'. |
---|
[431] | 495 | html::escapeHTML($this->rs->post_title).'</a></th>'; |
---|
[238] | 496 | } |
---|
| 497 | |
---|
| 498 | protected function getDate() |
---|
| 499 | { |
---|
[433] | 500 | return '<td class="nowrap">'.dt::dt2str(__('%Y-%m-%d'),$this->rs->post_dt).'</td>'; |
---|
| 501 | } |
---|
| 502 | |
---|
| 503 | protected function getDateTime() |
---|
| 504 | { |
---|
[238] | 505 | return '<td class="nowrap">'.dt::dt2str(__('%Y-%m-%d %H:%M'),$this->rs->post_dt).'</td>'; |
---|
| 506 | } |
---|
| 507 | |
---|
| 508 | protected function getCategory() |
---|
[0] | 509 | { |
---|
| 510 | if ($this->core->auth->check('categories',$this->core->blog->id)) { |
---|
| 511 | $cat_link = '<a href="category.php?id=%s">%s</a>'; |
---|
| 512 | } else { |
---|
| 513 | $cat_link = '%2$s'; |
---|
| 514 | } |
---|
| 515 | |
---|
| 516 | if ($this->rs->cat_title) { |
---|
| 517 | $cat_title = sprintf($cat_link,$this->rs->cat_id, |
---|
| 518 | html::escapeHTML($this->rs->cat_title)); |
---|
| 519 | } else { |
---|
| 520 | $cat_title = __('None'); |
---|
| 521 | } |
---|
| 522 | |
---|
[238] | 523 | return '<td class="nowrap">'.$cat_title.'</td>'; |
---|
[0] | 524 | } |
---|
| 525 | |
---|
[238] | 526 | protected function getAuthor() |
---|
| 527 | { |
---|
| 528 | return '<td class="nowrap">'.$this->rs->user_id.'</td>'; |
---|
| 529 | } |
---|
| 530 | |
---|
| 531 | protected function getComments() |
---|
| 532 | { |
---|
| 533 | return '<td class="nowrap">'.$this->rs->nb_comment.'</td>'; |
---|
| 534 | } |
---|
| 535 | |
---|
| 536 | protected function getTrackbacks() |
---|
| 537 | { |
---|
| 538 | return '<td class="nowrap">'.$this->rs->nb_trackback.'</td>'; |
---|
| 539 | } |
---|
| 540 | |
---|
| 541 | protected function getStatus() |
---|
[0] | 542 | { |
---|
| 543 | $img = '<img alt="%1$s" title="%1$s" src="images/%2$s" />'; |
---|
| 544 | switch ($this->rs->post_status) { |
---|
| 545 | case 1: |
---|
| 546 | $img_status = sprintf($img,__('published'),'check-on.png'); |
---|
| 547 | break; |
---|
| 548 | case 0: |
---|
| 549 | $img_status = sprintf($img,__('unpublished'),'check-off.png'); |
---|
| 550 | break; |
---|
| 551 | case -1: |
---|
| 552 | $img_status = sprintf($img,__('scheduled'),'scheduled.png'); |
---|
| 553 | break; |
---|
| 554 | case -2: |
---|
| 555 | $img_status = sprintf($img,__('pending'),'check-wrn.png'); |
---|
| 556 | break; |
---|
| 557 | } |
---|
| 558 | |
---|
| 559 | $protected = ''; |
---|
| 560 | if ($this->rs->post_password) { |
---|
| 561 | $protected = sprintf($img,__('protected'),'locker.png'); |
---|
| 562 | } |
---|
| 563 | |
---|
| 564 | $selected = ''; |
---|
| 565 | if ($this->rs->post_selected) { |
---|
| 566 | $selected = sprintf($img,__('selected'),'selected.png'); |
---|
| 567 | } |
---|
| 568 | |
---|
| 569 | $attach = ''; |
---|
| 570 | $nb_media = $this->rs->countMedia(); |
---|
| 571 | if ($nb_media > 0) { |
---|
| 572 | $attach_str = $nb_media == 1 ? __('%d attachment') : __('%d attachments'); |
---|
| 573 | $attach = sprintf($img,sprintf($attach_str,$nb_media),'attach.png'); |
---|
| 574 | } |
---|
| 575 | |
---|
[238] | 576 | return '<td class="nowrap status">'.$img_status.' '.$selected.' '.$protected.' '.$attach.'</td>'; |
---|
[0] | 577 | } |
---|
| 578 | } |
---|
| 579 | |
---|
[452] | 580 | /** |
---|
| 581 | @ingroup DC_CORE |
---|
| 582 | @nosubgrouping |
---|
| 583 | @brief abstract mini posts list class. |
---|
| 584 | |
---|
| 585 | Handle mini posts list on admin side (used for link popup) |
---|
| 586 | */ |
---|
[418] | 587 | class adminPostMiniList extends adminPostList |
---|
| 588 | { |
---|
[452] | 589 | public function setColumns() |
---|
| 590 | { |
---|
| 591 | $this->addColumn('title',__('Title'),array('adminPostList','getTitle'),' class="maximal"',false); |
---|
| 592 | $this->addColumn('date',__('Date'),array('adminPostList','getDate')); |
---|
| 593 | $this->addColumn('author',__('Author'),array('adminPostList','getAuthor')); |
---|
| 594 | $this->addColumn('status',__('Status'),array('adminPostList','getStatus')); |
---|
| 595 | } |
---|
| 596 | |
---|
[418] | 597 | protected function getTitle() |
---|
| 598 | { |
---|
| 599 | return |
---|
[431] | 600 | '<th scope="row" class="maximal">'. |
---|
| 601 | form::checkbox(array('entries[]'),$this->rs->post_id,'','','',!$this->rs->isEditable()).' '. |
---|
[418] | 602 | '<a href="'.$this->core->getPostAdminURL($this->rs->post_type,$this->rs->post_id).'" '. |
---|
| 603 | 'title="'.html::escapeHTML($this->rs->getURL()).'">'. |
---|
| 604 | html::escapeHTML($this->rs->post_title).'</a></td>'; |
---|
| 605 | } |
---|
| 606 | } |
---|
[238] | 607 | |
---|
[452] | 608 | /** |
---|
| 609 | @ingroup DC_CORE |
---|
| 610 | @nosubgrouping |
---|
| 611 | @brief abstract comments list class. |
---|
| 612 | |
---|
| 613 | Handle comments list on admin side |
---|
| 614 | */ |
---|
[0] | 615 | class adminCommentList extends adminGenericList |
---|
| 616 | { |
---|
[452] | 617 | public function setColumns() |
---|
| 618 | { |
---|
| 619 | $this->addColumn('title',__('Title'),array('adminCommentList','getTitle'),' class="maximal"',false); |
---|
| 620 | $this->addColumn('date',__('Date'),array('adminCommentList','getDate')); |
---|
| 621 | $this->addColumn('author',__('Author'),array('adminCommentList','getAuthor')); |
---|
| 622 | $this->addColumn('type',__('Type'),array('adminCommentList','getType')); |
---|
| 623 | $this->addColumn('status',__('Status'),array('adminCommentList','getStatus')); |
---|
| 624 | $this->addColumn('edit','',array('adminCommentList','getEdit')); |
---|
| 625 | } |
---|
| 626 | |
---|
[432] | 627 | protected function getDefaultCaption() |
---|
| 628 | { |
---|
| 629 | return __('Comments list'); |
---|
| 630 | } |
---|
| 631 | |
---|
[238] | 632 | protected function getDefaultLine() |
---|
[0] | 633 | { |
---|
[238] | 634 | return |
---|
| 635 | '<tr class="line'.($this->rs->comment_status != 1 ? ' offline' : '').'"'. |
---|
| 636 | ' id="c'.$this->rs->comment_id.'">%s</tr>'; |
---|
[0] | 637 | } |
---|
| 638 | |
---|
[238] | 639 | protected function getTitle() |
---|
| 640 | { |
---|
| 641 | $post_url = $this->core->getPostAdminURL($this->rs->post_type,$this->rs->post_id); |
---|
| 642 | |
---|
| 643 | return |
---|
[431] | 644 | '<th scope="row" class="maximal">'. |
---|
| 645 | form::checkbox(array('comments[]'),$this->rs->comment_id,'','','',0).' '. |
---|
[242] | 646 | '<a href="'.$post_url.'">'. |
---|
[238] | 647 | html::escapeHTML($this->rs->post_title).'</a>'. |
---|
[431] | 648 | ($this->rs->post_type != 'post' ? ' ('.html::escapeHTML($this->rs->post_type).')' : '').'</th>'; |
---|
[238] | 649 | } |
---|
| 650 | |
---|
| 651 | protected function getDate() |
---|
| 652 | { |
---|
| 653 | return '<td class="nowrap">'.dt::dt2str(__('%Y-%m-%d %H:%M'),$this->rs->comment_dt).'</td>'; |
---|
| 654 | } |
---|
| 655 | |
---|
| 656 | protected function getAuthor() |
---|
[0] | 657 | { |
---|
| 658 | global $author, $status, $sortby, $order, $nb_per_page; |
---|
| 659 | |
---|
| 660 | $author_url = |
---|
| 661 | 'comments.php?n='.$nb_per_page. |
---|
| 662 | '&status='.$status. |
---|
| 663 | '&sortby='.$sortby. |
---|
| 664 | '&order='.$order. |
---|
| 665 | '&author='.rawurlencode($this->rs->comment_author); |
---|
| 666 | |
---|
[238] | 667 | $comment_author = html::escapeHTML($this->rs->comment_author); |
---|
| 668 | if (mb_strlen($comment_author) > 20) { |
---|
| 669 | $comment_author = mb_strcut($comment_author,0,17).'...'; |
---|
| 670 | } |
---|
[0] | 671 | |
---|
[238] | 672 | return '<td class="nowrap"><a href="'.$author_url.'">'.$comment_author.'</a></td>'; |
---|
| 673 | } |
---|
| 674 | |
---|
| 675 | protected function getType() |
---|
| 676 | { |
---|
| 677 | return '<td class="nowrap">'.($this->rs->comment_trackback ? __('trackback') : __('comment')).'</td>'; |
---|
| 678 | } |
---|
| 679 | |
---|
| 680 | protected function getStatus() |
---|
| 681 | { |
---|
[0] | 682 | $img = '<img alt="%1$s" title="%1$s" src="images/%2$s" />'; |
---|
| 683 | switch ($this->rs->comment_status) { |
---|
| 684 | case 1: |
---|
| 685 | $img_status = sprintf($img,__('published'),'check-on.png'); |
---|
| 686 | break; |
---|
| 687 | case 0: |
---|
| 688 | $img_status = sprintf($img,__('unpublished'),'check-off.png'); |
---|
| 689 | break; |
---|
| 690 | case -1: |
---|
| 691 | $img_status = sprintf($img,__('pending'),'check-wrn.png'); |
---|
| 692 | break; |
---|
| 693 | case -2: |
---|
| 694 | $img_status = sprintf($img,__('junk'),'junk.png'); |
---|
| 695 | break; |
---|
| 696 | } |
---|
| 697 | |
---|
[238] | 698 | return '<td class="nowrap status">'.$img_status.'</td>'; |
---|
| 699 | } |
---|
| 700 | |
---|
| 701 | protected function getEdit() |
---|
| 702 | { |
---|
| 703 | $comment_url = 'comment.php?id='.$this->rs->comment_id; |
---|
[0] | 704 | |
---|
[238] | 705 | return |
---|
[0] | 706 | '<td class="nowrap status"><a href="'.$comment_url.'">'. |
---|
| 707 | '<img src="images/edit-mini.png" alt="" title="'.__('Edit this comment').'" /></a></td>'; |
---|
| 708 | } |
---|
| 709 | } |
---|
| 710 | |
---|
[452] | 711 | /** |
---|
| 712 | @ingroup DC_CORE |
---|
| 713 | @nosubgrouping |
---|
| 714 | @brief abstract users list class. |
---|
| 715 | |
---|
| 716 | Handle users list on admin side |
---|
| 717 | */ |
---|
[0] | 718 | class adminUserList extends adminGenericList |
---|
| 719 | { |
---|
[452] | 720 | public function setColumns() |
---|
| 721 | { |
---|
| 722 | $this->addColumn('username',__('Username'),array('adminUserList','getUserName'),'class="maximal"',false); |
---|
| 723 | $this->addColumn('firstname',__('First name'),array('adminUserList','getFirstName'),'class="nowrap"'); |
---|
| 724 | $this->addColumn('lastname',__('Last name'),array('adminUserList','getLastName'),'class="nowrap"'); |
---|
| 725 | $this->addColumn('displayname',__('Display name'),array('adminUserList','getDisplayName'),'class="nowrap"'); |
---|
| 726 | $this->addColumn('entries',__('Entries'),array('adminUserList','getEntries'),'class="nowrap"'); |
---|
| 727 | } |
---|
| 728 | |
---|
[432] | 729 | protected function getDefaultCaption() |
---|
| 730 | { |
---|
| 731 | return __('Users list'); |
---|
| 732 | } |
---|
| 733 | |
---|
[238] | 734 | protected function getUserName() |
---|
[0] | 735 | { |
---|
| 736 | $img = '<img alt="%1$s" title="%1$s" src="images/%2$s" />'; |
---|
| 737 | $img_status = ''; |
---|
| 738 | |
---|
| 739 | $p = $this->core->getUserPermissions($this->rs->user_id); |
---|
| 740 | |
---|
| 741 | if (isset($p[$this->core->blog->id]['p']['admin'])) { |
---|
| 742 | $img_status = sprintf($img,__('admin'),'admin.png'); |
---|
| 743 | } |
---|
| 744 | if ($this->rs->user_super) { |
---|
| 745 | $img_status = sprintf($img,__('superadmin'),'superadmin.png'); |
---|
| 746 | } |
---|
[238] | 747 | |
---|
[0] | 748 | return |
---|
[431] | 749 | '<th scope="row" class="maximal">'.form::hidden(array('nb_post[]'),(integer) $this->rs->nb_post). |
---|
[242] | 750 | form::checkbox(array('user_id[]'),$this->rs->user_id).' '. |
---|
[238] | 751 | '<a href="user.php?id='.$this->rs->user_id.'">'. |
---|
[431] | 752 | $this->rs->user_id.'</a> '.$img_status.'</th>'; |
---|
[238] | 753 | } |
---|
| 754 | |
---|
| 755 | protected function getFirstName() |
---|
| 756 | { |
---|
| 757 | return '<td class="nowrap">'.$this->rs->user_firstname.'</td>'; |
---|
| 758 | } |
---|
| 759 | |
---|
| 760 | protected function getLastName() |
---|
| 761 | { |
---|
| 762 | return '<td class="nowrap">'.$this->rs->user_name.'</td>'; |
---|
| 763 | } |
---|
| 764 | |
---|
| 765 | protected function getDisplayName() |
---|
| 766 | { |
---|
| 767 | return '<td class="nowrap">'.$this->rs->user_displayname.'</td>'; |
---|
| 768 | } |
---|
| 769 | |
---|
| 770 | protected function getEntries() |
---|
| 771 | { |
---|
| 772 | return |
---|
[0] | 773 | '<td class="nowrap"><a href="posts.php?user_id='.$this->rs->user_id.'">'. |
---|
[238] | 774 | $this->rs->nb_post.'</a></td>'; |
---|
[0] | 775 | } |
---|
| 776 | } |
---|
[238] | 777 | |
---|
[0] | 778 | ?> |
---|