[0] | 1 | <?php |
---|
| 2 | # -- BEGIN LICENSE BLOCK --------------------------------------- |
---|
| 3 | # |
---|
| 4 | # This file is part of Dotclear 2. |
---|
| 5 | # |
---|
[270] | 6 | # Copyright (c) 2003-2011 Olivier Meunier & Association Dotclear |
---|
[0] | 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 |
---|
[519] | 17 | @brief Dotclear items pager class. |
---|
[452] | 18 | |
---|
[519] | 19 | Dotclear items pager handles pagination for every admin list. |
---|
[452] | 20 | */ |
---|
[519] | 21 | class adminItemsPager extends pager |
---|
[449] | 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) { |
---|
[519] | 58 | $htmlEnd = '<a href="'.sprintf($this->page_url,$this->nb_pages).'" class="end">'. |
---|
[453] | 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 |
---|
[519] | 94 | @brief Dotclear items column class. |
---|
[452] | 95 | |
---|
[519] | 96 | Dotclear items column handles each column object use in adminItemsList class. |
---|
[452] | 97 | */ |
---|
[519] | 98 | class adminItemsColumn |
---|
[238] | 99 | { |
---|
[452] | 100 | protected $core; /// <b>object</b> dcCore object |
---|
| 101 | protected $id; /// <b>string</b> ID of defined column |
---|
[508] | 102 | protected $alias; /// <b>string</b> ID of defined column |
---|
[452] | 103 | protected $title; /// <b>string</b> Title of defined column |
---|
| 104 | protected $callback; /// <b>array</b> Callback calls to display defined column |
---|
[508] | 105 | protected $html; /// <b>array</b> Extra HTML for defined column |
---|
[238] | 106 | |
---|
[452] | 107 | /** |
---|
| 108 | Inits Generic column object |
---|
| 109 | |
---|
| 110 | @param id <b>string</b> Column id |
---|
[508] | 111 | @param alias <b>string</b> Column alias for SQL |
---|
[452] | 112 | @param title <b>string</b> Column title (for table headers) |
---|
| 113 | @param callback <b>array</b> Column callback (used for display) |
---|
[508] | 114 | @param html <b>array</b> Extra html (used for table headers) |
---|
| 115 | @param sortable <b>boolean</b> Defines if the column can be sorted or not |
---|
| 116 | @param listable <b>boolean</b> Defines if the column can be listed or not |
---|
[452] | 117 | @param can_hide <b>boolean</b> Defines if the column can be hidden or not |
---|
| 118 | */ |
---|
[508] | 119 | public function __construct($id,$alias,$title,$callback,$html = null,$sortable = true,$listable = true,$can_hide = true) |
---|
[238] | 120 | { |
---|
| 121 | if (!is_string($id) || $id === '') { |
---|
| 122 | throw new Exception(__('Invalid column ID')); |
---|
| 123 | } |
---|
| 124 | |
---|
| 125 | if (!is_string($title)) { |
---|
| 126 | throw new Exception(__('Invalid column title')); |
---|
| 127 | } |
---|
[242] | 128 | |
---|
[508] | 129 | if (is_null($html) || !is_array($html)) { |
---|
| 130 | $html = array(); |
---|
[238] | 131 | } |
---|
[508] | 132 | |
---|
| 133 | if (!is_bool($sortable)) { |
---|
| 134 | $sortable = true; |
---|
| 135 | } |
---|
| 136 | |
---|
| 137 | if (!is_bool($listable)) { |
---|
| 138 | $listable = true; |
---|
[242] | 139 | } |
---|
| 140 | |
---|
[418] | 141 | if (!is_bool($can_hide)) { |
---|
| 142 | $can_hide = true; |
---|
| 143 | } |
---|
| 144 | |
---|
[508] | 145 | if (!is_string($alias) && $sortable) { |
---|
| 146 | throw new Exception(__('Invalid column alias')); |
---|
| 147 | } |
---|
| 148 | |
---|
[238] | 149 | try { |
---|
[242] | 150 | if (!is_array($callback) || count($callback) < 2) { |
---|
| 151 | throw new Exception(__('Callback parameter should be an array')); |
---|
| 152 | } |
---|
[238] | 153 | $r = new ReflectionClass($callback[0]); |
---|
| 154 | $f = $r->getMethod($callback[1]); |
---|
| 155 | $p = $r->getParentClass(); |
---|
[456] | 156 | $find_parent = false; |
---|
| 157 | |
---|
| 158 | while (!$p) { |
---|
[519] | 159 | if ($p->name == 'adminItemsList') { |
---|
[456] | 160 | $find_parent = true; |
---|
| 161 | } |
---|
| 162 | else { |
---|
| 163 | $p->getParentClass(); |
---|
| 164 | } |
---|
| 165 | } |
---|
| 166 | |
---|
| 167 | if (!$p || !$f) { |
---|
[519] | 168 | throw new Exception(__('Callback class should be inherited of adminItemsList class')); |
---|
[238] | 169 | } |
---|
| 170 | } |
---|
| 171 | catch (Exception $e) { |
---|
[242] | 172 | throw new Exception(sprintf(__('Invalid column callback: %s'),$e->getMessage())); |
---|
[238] | 173 | } |
---|
| 174 | |
---|
| 175 | $this->id = $id; |
---|
[508] | 176 | $this->alias = $alias; |
---|
[238] | 177 | $this->title = $title; |
---|
| 178 | $this->callback = $callback; |
---|
| 179 | $this->html = $html; |
---|
[508] | 180 | $this->sortable = $sortable; |
---|
| 181 | $this->listable = $listable; |
---|
[418] | 182 | $this->can_hide = $can_hide; |
---|
[238] | 183 | $this->visibility = true; |
---|
| 184 | } |
---|
| 185 | |
---|
[452] | 186 | /** |
---|
| 187 | Gets information of defined column |
---|
| 188 | |
---|
| 189 | @param info <b>string</b> Column info to retrive |
---|
| 190 | |
---|
| 191 | @return <b>mixed</b> The information requested, null otherwise |
---|
| 192 | */ |
---|
| 193 | public function getInfo($info) |
---|
[238] | 194 | { |
---|
[452] | 195 | return property_exists(get_class($this),$info) ? $this->{$info} : null; |
---|
[238] | 196 | } |
---|
| 197 | |
---|
[452] | 198 | /** |
---|
| 199 | Sets visibility of defined column |
---|
| 200 | |
---|
| 201 | @param visibility <b>boolean</b> Column visibility |
---|
| 202 | */ |
---|
[238] | 203 | public function setVisibility($visibility) |
---|
| 204 | { |
---|
[508] | 205 | if (is_bool($visibility) && $this->can_hide) { |
---|
[238] | 206 | $this->visibility = $visibility; |
---|
| 207 | } |
---|
[508] | 208 | else { |
---|
| 209 | $this->visibility = true; |
---|
| 210 | } |
---|
[238] | 211 | } |
---|
| 212 | |
---|
[452] | 213 | /** |
---|
| 214 | Returns visibility status of defined column |
---|
| 215 | |
---|
| 216 | @return <b>boolean</b> true if column is visible, false otherwise |
---|
| 217 | */ |
---|
[238] | 218 | public function isVisible() |
---|
| 219 | { |
---|
| 220 | return $this->visibility; |
---|
| 221 | } |
---|
[418] | 222 | |
---|
[452] | 223 | /** |
---|
[508] | 224 | Returns if the defined column can be sorted |
---|
| 225 | |
---|
| 226 | @return <b>boolean</b> true if column is sortable, false otherwise |
---|
| 227 | */ |
---|
| 228 | public function isSortable() |
---|
| 229 | { |
---|
| 230 | return $this->sortable; |
---|
| 231 | } |
---|
| 232 | |
---|
| 233 | /** |
---|
| 234 | Returns if the defined column can be listed |
---|
| 235 | |
---|
| 236 | @return <b>boolean</b> true if column is listable, false otherwise |
---|
| 237 | */ |
---|
| 238 | public function isListable() |
---|
| 239 | { |
---|
| 240 | return $this->listable; |
---|
| 241 | } |
---|
| 242 | |
---|
| 243 | /** |
---|
[452] | 244 | Returns if the defined column can be hidden |
---|
| 245 | |
---|
| 246 | @return <b>boolean</b> true if column can be hidden, false otherwise |
---|
| 247 | */ |
---|
[418] | 248 | public function canHide() |
---|
| 249 | { |
---|
| 250 | return $this->can_hide; |
---|
| 251 | } |
---|
[238] | 252 | } |
---|
| 253 | |
---|
[452] | 254 | /** |
---|
| 255 | @ingroup DC_CORE |
---|
| 256 | @nosubgrouping |
---|
[519] | 257 | @brief abstract items list class. |
---|
[452] | 258 | |
---|
[519] | 259 | Dotclear items list handles administration lists |
---|
[452] | 260 | */ |
---|
[764] | 261 | abstract class adminItemsList implements dcFilterExtraInterface |
---|
[0] | 262 | { |
---|
| 263 | protected $core; |
---|
| 264 | protected $rs; |
---|
| 265 | protected $rs_count; |
---|
[238] | 266 | protected $columns; |
---|
[519] | 267 | protected $sortby; |
---|
| 268 | protected $order; |
---|
| 269 | protected $nb_per_page; |
---|
| 270 | protected $page; |
---|
[805] | 271 | protected $default_sortby; |
---|
| 272 | protected $default_order; |
---|
[238] | 273 | |
---|
[452] | 274 | /* |
---|
| 275 | Sets columns of defined list |
---|
| 276 | */ |
---|
[519] | 277 | abstract function setColumns(); |
---|
[452] | 278 | |
---|
| 279 | /** |
---|
| 280 | Inits List object |
---|
| 281 | |
---|
| 282 | @param core <b>dcCore</b> dcCore object |
---|
| 283 | */ |
---|
[519] | 284 | public function __construct($core) |
---|
[0] | 285 | { |
---|
[519] | 286 | |
---|
| 287 | $this->core = $core; |
---|
[238] | 288 | $this->context = get_class($this); |
---|
[764] | 289 | $this->columns = new ArrayObject(); |
---|
[780] | 290 | $this->form_prefix = 'col_'; |
---|
[238] | 291 | |
---|
[449] | 292 | $this->html_prev = __('prev'); |
---|
| 293 | $this->html_next = __('next'); |
---|
| 294 | $this->html_start = __('start'); |
---|
| 295 | $this->html_end = __('end'); |
---|
[238] | 296 | |
---|
[764] | 297 | $this->nb_per_page = 10; |
---|
[519] | 298 | |
---|
[452] | 299 | $this->setColumns(); |
---|
[238] | 300 | |
---|
[519] | 301 | # --BEHAVIOR-- adminItemsListConstruct |
---|
| 302 | $core->callBehavior('adminItemsListConstruct',$this); |
---|
[276] | 303 | |
---|
[0] | 304 | } |
---|
[238] | 305 | |
---|
[764] | 306 | public function __clone() { |
---|
| 307 | $arr = new ArrayObject(); |
---|
| 308 | foreach ($this->columns as $k=>$v) { |
---|
| 309 | $arr[$k]= clone $v; |
---|
| 310 | } |
---|
| 311 | $this->columns = $arr; |
---|
| 312 | } |
---|
[452] | 313 | /** |
---|
[519] | 314 | Apply limit, sortby and order filters to items parameters |
---|
| 315 | |
---|
| 316 | @param params <b>array</b> Items parameters |
---|
| 317 | |
---|
| 318 | @return <b>array</b> Items parameters |
---|
| 319 | */ |
---|
| 320 | public function applyFilters($params) |
---|
| 321 | { |
---|
| 322 | if (!is_null($this->sortby) && !is_null($this->order)) { |
---|
[804] | 323 | if ( |
---|
| 324 | isset($this->columns[$this->sortby]) && |
---|
| 325 | in_array($this->order,array('asc','desc')) |
---|
| 326 | ) { |
---|
| 327 | $params['order'] = $this->columns[$this->sortby]->getInfo('alias').' '.$this->order; |
---|
[519] | 328 | } |
---|
| 329 | } |
---|
| 330 | |
---|
| 331 | $params['limit'] = array((($this->page-1)*$this->nb_per_page),$this->nb_per_page); |
---|
| 332 | |
---|
| 333 | return $params; |
---|
| 334 | } |
---|
| 335 | |
---|
| 336 | /** |
---|
| 337 | Sets items and items counter |
---|
| 338 | |
---|
| 339 | @param rs <b>recordSet</b> Items recordSet to display |
---|
| 340 | @param rs_count <b>int</b> Total items number |
---|
| 341 | */ |
---|
| 342 | public function setItems($rs,$rs_count) |
---|
| 343 | { |
---|
| 344 | $this->rs = $rs; |
---|
| 345 | $this->rs_count = $rs_count; |
---|
| 346 | } |
---|
| 347 | |
---|
| 348 | /** |
---|
[452] | 349 | Returns HTML code form used to choose which column to display |
---|
[238] | 350 | |
---|
[452] | 351 | @return <b>string</b> HTML code form |
---|
| 352 | */ |
---|
[764] | 353 | public function getFormContent() |
---|
[242] | 354 | { |
---|
| 355 | $block = |
---|
| 356 | '<h3>'.__('Displayed information').'</h3>'. |
---|
| 357 | '<ul>%s</ul>'; |
---|
| 358 | |
---|
| 359 | $list = array(); |
---|
[804] | 360 | $sortby_combo = array(); |
---|
[452] | 361 | foreach ($this->columns as $k => $v) { |
---|
[780] | 362 | $col_id = $this->form_prefix.$k; |
---|
[242] | 363 | $col_label = sprintf('<label for="%s">%s</label>',$col_id,$v->getInfo('title')); |
---|
[418] | 364 | $col_html = sprintf('<li class="line">%s</li>',$col_label.form::checkbox($col_id,1,$v->isVisible(),null,null,!$v->canHide())); |
---|
[242] | 365 | |
---|
[508] | 366 | if ($v->isListable()) { |
---|
| 367 | array_push($list,$col_html); |
---|
| 368 | } |
---|
[804] | 369 | $sortby_combo[$v->getInfo('title')] = $k; |
---|
[242] | 370 | } |
---|
[804] | 371 | $order_combo = array( |
---|
| 372 | __('Descending') => 'desc', |
---|
| 373 | __('Ascending') => 'asc' |
---|
| 374 | ); |
---|
[242] | 375 | |
---|
[519] | 376 | $nb_per_page = !is_null($this->nb_per_page) ? $this->nb_per_page : 10; |
---|
[437] | 377 | |
---|
[453] | 378 | return |
---|
| 379 | sprintf($block,implode('',$list)). |
---|
[519] | 380 | '<p><label for="nb_per_page">'.__('Items per page:'). |
---|
| 381 | '</label> '.form::field('nb_per_page',3,3,$nb_per_page). |
---|
[804] | 382 | '</p>'. |
---|
| 383 | '<p><label for="sortby">'.__('Sort by:'). |
---|
| 384 | '</label> '.form::combo('sortby',$sortby_combo,$this->sortby). |
---|
| 385 | '</p>'. |
---|
| 386 | '<p><label for="order">'.__('Order:'). |
---|
| 387 | '</label> '.form::combo('order',$order_combo,$this->order). |
---|
[453] | 388 | '</p>'; |
---|
[242] | 389 | } |
---|
| 390 | |
---|
[764] | 391 | public function updateRequestParams($params) { |
---|
[804] | 392 | if (!is_null($this->sortby) && isset($this->columns[$this->sortby])) { |
---|
| 393 | $params['sortby'] = $this->columns[$this->sortby]->getInfo('alias'); |
---|
[764] | 394 | } |
---|
| 395 | if (!is_null($this->order)) { |
---|
| 396 | $params['order'] = $this->order; |
---|
| 397 | } |
---|
| 398 | if (!is_null($this->nb_per_page)) { |
---|
| 399 | $params['nb_per_page'] = $this->nb_per_page; |
---|
| 400 | } |
---|
| 401 | if (!is_null($this->page)) { |
---|
| 402 | $params['page'] = $this->page; |
---|
| 403 | } |
---|
| 404 | foreach ($this->columns as $k => $v) { |
---|
| 405 | if($v->isVisible()) |
---|
[780] | 406 | $params[$this->form_prefix.$k] = 1; |
---|
[764] | 407 | } |
---|
| 408 | |
---|
| 409 | } |
---|
| 410 | |
---|
[452] | 411 | /** |
---|
[519] | 412 | Returns HTML hidden fields for list options |
---|
| 413 | |
---|
| 414 | @return <b>string</b> HTML hidden fields |
---|
| 415 | */ |
---|
| 416 | public function getFormFieldsAsHidden() |
---|
| 417 | { |
---|
| 418 | $res = ''; |
---|
| 419 | |
---|
| 420 | if (!is_null($this->sortby)) { |
---|
| 421 | $res .= form::hidden(array('sortby'),$this->sortby); |
---|
| 422 | } |
---|
| 423 | if (!is_null($this->order)) { |
---|
| 424 | $res .= form::hidden(array('order'),$this->order); |
---|
| 425 | } |
---|
| 426 | if (!is_null($this->nb_per_page)) { |
---|
| 427 | $res .= form::hidden(array('nb_per_page'),$this->nb_per_page); |
---|
| 428 | } |
---|
| 429 | if (!is_null($this->page)) { |
---|
| 430 | $res .= form::hidden(array('page'),$this->page); |
---|
| 431 | } |
---|
| 432 | |
---|
| 433 | return $res; |
---|
| 434 | } |
---|
| 435 | |
---|
| 436 | /** |
---|
[452] | 437 | Returns HTML code list to display |
---|
| 438 | |
---|
| 439 | @param enclose_block <b>string</b> HTML wrapper of defined list |
---|
| 440 | |
---|
| 441 | @return <b>string</b> HTML code list |
---|
| 442 | */ |
---|
[519] | 443 | public function display($enclose_block = '') |
---|
[0] | 444 | { |
---|
| 445 | if ($this->rs->isEmpty()) |
---|
| 446 | { |
---|
[463] | 447 | echo '<p><strong>'.__('No item').'</strong></p>'; |
---|
[0] | 448 | } |
---|
| 449 | else |
---|
| 450 | { |
---|
[519] | 451 | $pager = new adminItemsPager($this->page,$this->rs_count,$this->nb_per_page,10); |
---|
[0] | 452 | $pager->html_prev = $this->html_prev; |
---|
| 453 | $pager->html_next = $this->html_next; |
---|
[449] | 454 | $pager->html_start = $this->html_start; |
---|
| 455 | $pager->html_end = $this->html_end; |
---|
[0] | 456 | $pager->var_page = 'page'; |
---|
| 457 | |
---|
[431] | 458 | $html_block = |
---|
| 459 | '<table class="maximal clear">'. |
---|
[519] | 460 | $this->getCaption($this->page). |
---|
[431] | 461 | '<thead><tr>'; |
---|
[238] | 462 | |
---|
[452] | 463 | foreach ($this->columns as $k => $v) { |
---|
[238] | 464 | if ($v->isVisible()) { |
---|
[508] | 465 | $title = $v->getInfo('title'); |
---|
| 466 | if ($v->isSortable()) { |
---|
| 467 | $title = sprintf('<a href="%2$s">%1$s</a>',$title,$this->getSortLink($v)); |
---|
| 468 | } |
---|
| 469 | $html_extra = ''; |
---|
| 470 | foreach ($v->getInfo('html') as $i => $j) { |
---|
| 471 | $html_extra = $i.'="'.implode(' ',$j).'"'; |
---|
| 472 | } |
---|
| 473 | $html_extra = !empty($html_extra) ? ' '.$html_extra : ''; |
---|
| 474 | $html_block .= sprintf('<th scope="col"%2$s>%1$s</th>',$title,$html_extra); |
---|
[238] | 475 | } |
---|
| 476 | } |
---|
| 477 | |
---|
[431] | 478 | $html_block .= |
---|
| 479 | '</tr></thead>'. |
---|
| 480 | '<tbody>%s</tbody>'. |
---|
| 481 | '</table>'; |
---|
[0] | 482 | |
---|
| 483 | if ($enclose_block) { |
---|
| 484 | $html_block = sprintf($enclose_block,$html_block); |
---|
| 485 | } |
---|
| 486 | |
---|
[449] | 487 | echo '<div class="pagination">'.$pager->getLinks().'</div>'; |
---|
[0] | 488 | |
---|
| 489 | $blocks = explode('%s',$html_block); |
---|
| 490 | |
---|
| 491 | echo $blocks[0]; |
---|
| 492 | |
---|
| 493 | while ($this->rs->fetch()) |
---|
| 494 | { |
---|
[238] | 495 | echo $this->displayLine(); |
---|
[0] | 496 | } |
---|
| 497 | |
---|
| 498 | echo $blocks[1]; |
---|
| 499 | |
---|
[449] | 500 | echo '<div class="pagination">'.$pager->getLinks().'</div>'; |
---|
[0] | 501 | } |
---|
| 502 | } |
---|
| 503 | |
---|
[452] | 504 | /** |
---|
| 505 | Adds column to defined list |
---|
| 506 | |
---|
| 507 | @param id <b>string</b> Column id |
---|
[508] | 508 | @param alias <b>string</b> Column alias for SQL |
---|
[452] | 509 | @param title <b>string</b> Column title (for table headers) |
---|
| 510 | @param callback <b>array</b> Column callback (used for display) |
---|
| 511 | @param html <b>string</b> Extra html (used for table headers) |
---|
[508] | 512 | @param sortable <b>boolean</b> Defines if the column can be sorted or not |
---|
| 513 | @param listable <b>boolean</b> Defines if the column can be listed or not |
---|
[452] | 514 | @param can_hide <b>boolean</b> Defines if the column can be hidden or not |
---|
| 515 | */ |
---|
[508] | 516 | protected function addColumn($id,$alias,$title,$callback,$html = null,$sortable = true,$listable = true,$can_hide = true) |
---|
[452] | 517 | { |
---|
| 518 | try { |
---|
[508] | 519 | if (is_null($html) || !is_array($html)) { |
---|
| 520 | $html = array(); |
---|
| 521 | } |
---|
[519] | 522 | if ($this->sortby === $alias && !is_null($this->order)) { |
---|
[508] | 523 | if (array_key_exists('class',$html)) { |
---|
[519] | 524 | array_push($html['class'],$this->order); |
---|
[508] | 525 | } |
---|
| 526 | else { |
---|
[519] | 527 | $html['class'] = array($this->order); |
---|
[508] | 528 | } |
---|
| 529 | } |
---|
[519] | 530 | $c = new adminItemsColumn($id,$alias,$title,$callback,$html,$sortable,$listable,$can_hide); |
---|
[452] | 531 | $this->columns[$id] = $c; |
---|
| 532 | } |
---|
| 533 | catch (Exception $e) { |
---|
| 534 | if (DC_DEBUG) { |
---|
[519] | 535 | $this->core->error->add(sprintf('[%s] %s',$id,$e->getMessage())); |
---|
[452] | 536 | } |
---|
| 537 | } |
---|
| 538 | } |
---|
| 539 | |
---|
| 540 | /** |
---|
| 541 | Returns default caption text |
---|
| 542 | |
---|
| 543 | @return <b>string</b> Default caption |
---|
| 544 | */ |
---|
| 545 | protected function getDefaultCaption() |
---|
| 546 | { |
---|
| 547 | return; |
---|
| 548 | } |
---|
| 549 | |
---|
| 550 | /** |
---|
[764] | 551 | Returns default HTML code line |
---|
[452] | 552 | |
---|
| 553 | @return <b>string</b> Default HTMl code line |
---|
| 554 | */ |
---|
| 555 | protected function getDefaultLine() |
---|
| 556 | { |
---|
| 557 | return '<tr class="line">%s</tr>'; |
---|
| 558 | } |
---|
| 559 | |
---|
| 560 | /** |
---|
[764] | 561 | Loads list from user settings |
---|
[519] | 562 | */ |
---|
[764] | 563 | public function load() { |
---|
[519] | 564 | $ws = $this->core->auth->user_prefs->addWorkspace('lists'); |
---|
| 565 | $user_pref = !is_null($ws->{$this->context.'_opts'}) ? unserialize($ws->{$this->context.'_opts'}) : array(); |
---|
[805] | 566 | $this->sortby = array_key_exists('sortby',$user_pref) ? $user_pref['sortby'] : $this->default_sortby; |
---|
| 567 | $this->order = array_key_exists('order',$user_pref) ? $user_pref['order'] : $this->default_order; |
---|
[519] | 568 | $this->nb_per_page = array_key_exists('nb_per_page',$user_pref) ? $user_pref['nb_per_page'] : 10; |
---|
[764] | 569 | $user_pref = !is_null($ws->{$this->context.'_col'}) ? unserialize($ws->{$this->context.'_col'}) : array(); |
---|
| 570 | foreach ($this->columns as $k => $v) { |
---|
| 571 | $visibility = array_key_exists($k,$user_pref) ? $user_pref[$k] : true; |
---|
| 572 | $v->setVisibility($visibility); |
---|
[519] | 573 | } |
---|
[805] | 574 | if ($this->sortby != null && !isset($this->columns[$this->sortby])) { |
---|
[804] | 575 | // No alias found |
---|
[805] | 576 | $this->sortby=$this->default_sortby; |
---|
| 577 | $this->order=$this->default_order; |
---|
[804] | 578 | } |
---|
| 579 | |
---|
[519] | 580 | } |
---|
| 581 | |
---|
| 582 | /** |
---|
[764] | 583 | Saves list to user settings |
---|
[452] | 584 | */ |
---|
[764] | 585 | public function save() { |
---|
| 586 | $ws = $this->core->auth->user_prefs->addWorkspace('lists'); |
---|
| 587 | $user_pref = !is_null($ws->{$this->context.'_opts'}) ? unserialize($ws->{$this->context.'_opts'}) : array(); |
---|
| 588 | $user_pref['order'] = $this->order; |
---|
| 589 | $user_pref['nb_per_page'] = $this->nb_per_page; |
---|
| 590 | $user_pref['sortby'] = $this->sortby; |
---|
[519] | 591 | |
---|
[764] | 592 | $this->core->auth->user_prefs->lists->put($this->context.'_opts',serialize($user_pref),'string'); |
---|
[452] | 593 | |
---|
[519] | 594 | $user_pref = !is_null($ws->{$this->context.'_col'}) ? unserialize($ws->{$this->context.'_col'}) : array(); |
---|
[452] | 595 | |
---|
| 596 | foreach ($this->columns as $k => $v) { |
---|
[764] | 597 | $user_pref[$k] = $v->isVisible(); |
---|
| 598 | } |
---|
| 599 | $this->core->auth->user_prefs->lists->put($this->context.'_col',serialize($user_pref),'string'); |
---|
| 600 | } |
---|
| 601 | |
---|
| 602 | /** |
---|
| 603 | Set dedicated data from form submission |
---|
| 604 | (either $_GET or $_POST depending on the context |
---|
| 605 | |
---|
| 606 | @param data <b>array</b> Data to retrieve information from |
---|
| 607 | */ |
---|
| 608 | public function initializeFromData ($data) |
---|
| 609 | { |
---|
[770] | 610 | $load_from_settings = true; |
---|
| 611 | foreach ($data as $k=>$v) { |
---|
[780] | 612 | if (strpos($k,$this->form_prefix) === 0) { |
---|
[770] | 613 | $load_from_settings = false; |
---|
| 614 | } |
---|
| 615 | } |
---|
| 616 | if ($load_from_settings) { |
---|
| 617 | $this->load(); |
---|
| 618 | } |
---|
[764] | 619 | # Sortby |
---|
| 620 | $this->sortby = array_key_exists('sortby',$data) ? $data['sortby'] : $this->sortby; |
---|
| 621 | $this->order = array_key_exists('order',$data) ? $data['order'] : $this->order; |
---|
[804] | 622 | $this->nb_per_page = array_key_exists('nb_per_page',$data) ? (integer) $data['nb_per_page'] : $this->nb_per_page; |
---|
[764] | 623 | # Page |
---|
[804] | 624 | $this->page = array_key_exists('page',$data) ? (integer) $data['page'] : 1; |
---|
[770] | 625 | if ($load_from_settings) |
---|
| 626 | return; |
---|
[764] | 627 | foreach ($this->columns as $k => $v) { |
---|
[780] | 628 | $key = $this->form_prefix.$k; |
---|
[764] | 629 | $visibility = !array_key_exists($key,$data) ? false : true; |
---|
[452] | 630 | $v->setVisibility($visibility); |
---|
| 631 | } |
---|
| 632 | } |
---|
| 633 | |
---|
| 634 | /** |
---|
| 635 | Returns HTML code for each line of defined list |
---|
| 636 | |
---|
| 637 | @return <b>string</b> HTML code line |
---|
| 638 | */ |
---|
[238] | 639 | private function displayLine() |
---|
| 640 | { |
---|
| 641 | $res = ''; |
---|
| 642 | |
---|
[452] | 643 | foreach ($this->columns as $k => $v) { |
---|
[238] | 644 | if ($v->isVisible()) { |
---|
| 645 | $c = $v->getInfo('callback'); |
---|
| 646 | $res .= $this->{$c[1]}(); |
---|
| 647 | } |
---|
| 648 | } |
---|
| 649 | |
---|
| 650 | return sprintf($this->getDefaultLine(),$res); |
---|
| 651 | } |
---|
| 652 | |
---|
[452] | 653 | /** |
---|
| 654 | Returns caption of defined list |
---|
| 655 | |
---|
| 656 | @param page <b>string|int</b> Current page |
---|
| 657 | |
---|
| 658 | @return <b>string</b> HTML caption tag |
---|
| 659 | */ |
---|
[432] | 660 | private function getCaption($page) |
---|
| 661 | { |
---|
| 662 | $caption = $this->getDefaultCaption(); |
---|
| 663 | |
---|
| 664 | if (!empty($caption)) { |
---|
| 665 | $caption = sprintf( |
---|
| 666 | '<caption>%s - %s</caption>', |
---|
| 667 | $caption,sprintf(__('Page %s'),$page) |
---|
| 668 | ); |
---|
| 669 | } |
---|
| 670 | |
---|
| 671 | return $caption; |
---|
| 672 | } |
---|
[508] | 673 | |
---|
| 674 | /** |
---|
| 675 | Returns link to sort the defined column |
---|
| 676 | |
---|
| 677 | @param c <b>adminGenericColumn</b> Current column |
---|
| 678 | |
---|
| 679 | @return <b>string</b> HTML link |
---|
| 680 | */ |
---|
| 681 | private function getSortLink($c) |
---|
| 682 | { |
---|
| 683 | $order = 'desc'; |
---|
[804] | 684 | if (!is_null($this->sortby) && $this->sortby === $c->getInfo('id')) { |
---|
[519] | 685 | if (!is_null($this->order) && $this->order === $order) { |
---|
[508] | 686 | $order = 'asc'; |
---|
| 687 | } |
---|
| 688 | } |
---|
| 689 | |
---|
| 690 | $args = $_GET; |
---|
[804] | 691 | $args['sortby'] = $c->getInfo('id'); |
---|
[508] | 692 | $args['order'] = $order; |
---|
| 693 | |
---|
| 694 | array_walk($args,create_function('&$v,$k','$v=$k."=".$v;')); |
---|
| 695 | |
---|
| 696 | $url = $_SERVER['PHP_SELF']; |
---|
| 697 | $url .= '?'.implode('&',$args); |
---|
| 698 | |
---|
| 699 | return $url; |
---|
| 700 | } |
---|
[452] | 701 | } |
---|
| 702 | |
---|
| 703 | /** |
---|
| 704 | @ingroup DC_CORE |
---|
| 705 | @nosubgrouping |
---|
| 706 | @brief abstract posts list class. |
---|
| 707 | |
---|
| 708 | Handle posts list on admin side |
---|
| 709 | */ |
---|
[519] | 710 | class adminPostList extends adminItemsList |
---|
[452] | 711 | { |
---|
| 712 | public function setColumns() |
---|
[432] | 713 | { |
---|
[508] | 714 | $this->addColumn('title','post_title',__('Title'),array('adminPostList','getTitle'),array('class' => array('maximal')),true,true,false); |
---|
| 715 | $this->addColumn('date','post_dt',__('Date'),array('adminPostList','getDate')); |
---|
| 716 | $this->addColumn('datetime','post_dt',__('Date and time'),array('adminPostList','getDateTime')); |
---|
| 717 | $this->addColumn('category','cat_title',__('Category'),array('adminPostList','getCategory')); |
---|
| 718 | $this->addColumn('author','user_id',__('Author'),array('adminPostList','getAuthor')); |
---|
| 719 | $this->addColumn('comments','nb_comment',__('Comments'),array('adminPostList','getComments')); |
---|
| 720 | $this->addColumn('trackbacks','nb_trackback',__('Trackbacks'),array('adminPostList','getTrackbacks')); |
---|
| 721 | $this->addColumn('status','post_status',__('Status'),array('adminPostList','getStatus')); |
---|
[805] | 722 | $this->default_sortby = 'datetime'; |
---|
| 723 | $this->default_order = 'desc'; |
---|
| 724 | |
---|
[432] | 725 | } |
---|
| 726 | |
---|
| 727 | protected function getDefaultCaption() |
---|
| 728 | { |
---|
| 729 | return __('Entries list'); |
---|
| 730 | } |
---|
| 731 | |
---|
[238] | 732 | protected function getDefaultLine() |
---|
| 733 | { |
---|
| 734 | return |
---|
| 735 | '<tr class="line'.($this->rs->post_status != 1 ? ' offline' : '').'"'. |
---|
| 736 | ' id="p'.$this->rs->post_id.'">%s</tr>'; |
---|
| 737 | } |
---|
| 738 | |
---|
| 739 | protected function getTitle() |
---|
| 740 | { |
---|
| 741 | return |
---|
[431] | 742 | '<th scope="row" class="maximal">'. |
---|
| 743 | form::checkbox(array('entries[]'),$this->rs->post_id,'','','',!$this->rs->isEditable()).' '. |
---|
[238] | 744 | '<a href="'.$this->core->getPostAdminURL($this->rs->post_type,$this->rs->post_id).'">'. |
---|
[431] | 745 | html::escapeHTML($this->rs->post_title).'</a></th>'; |
---|
[238] | 746 | } |
---|
| 747 | |
---|
| 748 | protected function getDate() |
---|
| 749 | { |
---|
[433] | 750 | return '<td class="nowrap">'.dt::dt2str(__('%Y-%m-%d'),$this->rs->post_dt).'</td>'; |
---|
| 751 | } |
---|
| 752 | |
---|
| 753 | protected function getDateTime() |
---|
| 754 | { |
---|
[238] | 755 | return '<td class="nowrap">'.dt::dt2str(__('%Y-%m-%d %H:%M'),$this->rs->post_dt).'</td>'; |
---|
| 756 | } |
---|
| 757 | |
---|
| 758 | protected function getCategory() |
---|
[0] | 759 | { |
---|
| 760 | if ($this->core->auth->check('categories',$this->core->blog->id)) { |
---|
| 761 | $cat_link = '<a href="category.php?id=%s">%s</a>'; |
---|
| 762 | } else { |
---|
| 763 | $cat_link = '%2$s'; |
---|
| 764 | } |
---|
| 765 | |
---|
| 766 | if ($this->rs->cat_title) { |
---|
| 767 | $cat_title = sprintf($cat_link,$this->rs->cat_id, |
---|
| 768 | html::escapeHTML($this->rs->cat_title)); |
---|
| 769 | } else { |
---|
| 770 | $cat_title = __('None'); |
---|
| 771 | } |
---|
| 772 | |
---|
[238] | 773 | return '<td class="nowrap">'.$cat_title.'</td>'; |
---|
[0] | 774 | } |
---|
| 775 | |
---|
[238] | 776 | protected function getAuthor() |
---|
| 777 | { |
---|
| 778 | return '<td class="nowrap">'.$this->rs->user_id.'</td>'; |
---|
| 779 | } |
---|
| 780 | |
---|
| 781 | protected function getComments() |
---|
| 782 | { |
---|
| 783 | return '<td class="nowrap">'.$this->rs->nb_comment.'</td>'; |
---|
| 784 | } |
---|
| 785 | |
---|
| 786 | protected function getTrackbacks() |
---|
| 787 | { |
---|
| 788 | return '<td class="nowrap">'.$this->rs->nb_trackback.'</td>'; |
---|
| 789 | } |
---|
| 790 | |
---|
| 791 | protected function getStatus() |
---|
[0] | 792 | { |
---|
| 793 | $img = '<img alt="%1$s" title="%1$s" src="images/%2$s" />'; |
---|
| 794 | switch ($this->rs->post_status) { |
---|
| 795 | case 1: |
---|
| 796 | $img_status = sprintf($img,__('published'),'check-on.png'); |
---|
| 797 | break; |
---|
| 798 | case 0: |
---|
| 799 | $img_status = sprintf($img,__('unpublished'),'check-off.png'); |
---|
| 800 | break; |
---|
| 801 | case -1: |
---|
| 802 | $img_status = sprintf($img,__('scheduled'),'scheduled.png'); |
---|
| 803 | break; |
---|
| 804 | case -2: |
---|
| 805 | $img_status = sprintf($img,__('pending'),'check-wrn.png'); |
---|
| 806 | break; |
---|
| 807 | } |
---|
| 808 | |
---|
| 809 | $protected = ''; |
---|
| 810 | if ($this->rs->post_password) { |
---|
| 811 | $protected = sprintf($img,__('protected'),'locker.png'); |
---|
| 812 | } |
---|
| 813 | |
---|
| 814 | $selected = ''; |
---|
| 815 | if ($this->rs->post_selected) { |
---|
| 816 | $selected = sprintf($img,__('selected'),'selected.png'); |
---|
| 817 | } |
---|
| 818 | |
---|
| 819 | $attach = ''; |
---|
| 820 | $nb_media = $this->rs->countMedia(); |
---|
| 821 | if ($nb_media > 0) { |
---|
| 822 | $attach_str = $nb_media == 1 ? __('%d attachment') : __('%d attachments'); |
---|
| 823 | $attach = sprintf($img,sprintf($attach_str,$nb_media),'attach.png'); |
---|
| 824 | } |
---|
| 825 | |
---|
[238] | 826 | return '<td class="nowrap status">'.$img_status.' '.$selected.' '.$protected.' '.$attach.'</td>'; |
---|
[0] | 827 | } |
---|
| 828 | } |
---|
| 829 | |
---|
[452] | 830 | /** |
---|
| 831 | @ingroup DC_CORE |
---|
| 832 | @nosubgrouping |
---|
| 833 | @brief abstract mini posts list class. |
---|
| 834 | |
---|
| 835 | Handle mini posts list on admin side (used for link popup) |
---|
| 836 | */ |
---|
[418] | 837 | class adminPostMiniList extends adminPostList |
---|
| 838 | { |
---|
[452] | 839 | public function setColumns() |
---|
| 840 | { |
---|
[508] | 841 | $this->addColumn('title','post_title',__('Title'),array('adminPostMiniList','getTitle'),array('class' => array('maximal')),true,true,false); |
---|
| 842 | $this->addColumn('date','post_dt',__('Date'),array('adminPostList','getDate')); |
---|
| 843 | $this->addColumn('author','user_id',__('Author'),array('adminPostList','getAuthor')); |
---|
| 844 | $this->addColumn('status','post_status',__('Status'),array('adminPostList','getStatus')); |
---|
[452] | 845 | } |
---|
| 846 | |
---|
[418] | 847 | protected function getTitle() |
---|
| 848 | { |
---|
| 849 | return |
---|
[431] | 850 | '<th scope="row" class="maximal">'. |
---|
| 851 | form::checkbox(array('entries[]'),$this->rs->post_id,'','','',!$this->rs->isEditable()).' '. |
---|
[418] | 852 | '<a href="'.$this->core->getPostAdminURL($this->rs->post_type,$this->rs->post_id).'" '. |
---|
| 853 | 'title="'.html::escapeHTML($this->rs->getURL()).'">'. |
---|
| 854 | html::escapeHTML($this->rs->post_title).'</a></td>'; |
---|
| 855 | } |
---|
| 856 | } |
---|
[238] | 857 | |
---|
[452] | 858 | /** |
---|
| 859 | @ingroup DC_CORE |
---|
| 860 | @nosubgrouping |
---|
| 861 | @brief abstract comments list class. |
---|
| 862 | |
---|
| 863 | Handle comments list on admin side |
---|
| 864 | */ |
---|
[519] | 865 | class adminCommentList extends adminItemsList |
---|
[0] | 866 | { |
---|
[452] | 867 | public function setColumns() |
---|
| 868 | { |
---|
[508] | 869 | $this->addColumn('title','post_title',__('Title'),array('adminCommentList','getTitle'),array('class' => array('maximal')),true,true,false); |
---|
| 870 | $this->addColumn('date','comment_dt',__('Date'),array('adminCommentList','getDate')); |
---|
| 871 | $this->addColumn('author','comment_author',__('Author'),array('adminCommentList','getAuthor')); |
---|
| 872 | $this->addColumn('type','comment_trackback',__('Type'),array('adminCommentList','getType')); |
---|
| 873 | $this->addColumn('status','comment_status',__('Status'),array('adminCommentList','getStatus')); |
---|
| 874 | $this->addColumn('edit',null,'',array('adminCommentList','getEdit'),null,false,false,false); |
---|
[805] | 875 | $this->default_sortby = 'date'; |
---|
| 876 | $this->default_order = 'desc'; |
---|
[452] | 877 | } |
---|
| 878 | |
---|
[432] | 879 | protected function getDefaultCaption() |
---|
| 880 | { |
---|
| 881 | return __('Comments list'); |
---|
| 882 | } |
---|
| 883 | |
---|
[238] | 884 | protected function getDefaultLine() |
---|
[0] | 885 | { |
---|
[238] | 886 | return |
---|
| 887 | '<tr class="line'.($this->rs->comment_status != 1 ? ' offline' : '').'"'. |
---|
| 888 | ' id="c'.$this->rs->comment_id.'">%s</tr>'; |
---|
[0] | 889 | } |
---|
| 890 | |
---|
[238] | 891 | protected function getTitle() |
---|
| 892 | { |
---|
| 893 | $post_url = $this->core->getPostAdminURL($this->rs->post_type,$this->rs->post_id); |
---|
| 894 | |
---|
| 895 | return |
---|
[431] | 896 | '<th scope="row" class="maximal">'. |
---|
| 897 | form::checkbox(array('comments[]'),$this->rs->comment_id,'','','',0).' '. |
---|
[242] | 898 | '<a href="'.$post_url.'">'. |
---|
[238] | 899 | html::escapeHTML($this->rs->post_title).'</a>'. |
---|
[431] | 900 | ($this->rs->post_type != 'post' ? ' ('.html::escapeHTML($this->rs->post_type).')' : '').'</th>'; |
---|
[238] | 901 | } |
---|
| 902 | |
---|
| 903 | protected function getDate() |
---|
| 904 | { |
---|
| 905 | return '<td class="nowrap">'.dt::dt2str(__('%Y-%m-%d %H:%M'),$this->rs->comment_dt).'</td>'; |
---|
| 906 | } |
---|
| 907 | |
---|
| 908 | protected function getAuthor() |
---|
[0] | 909 | { |
---|
| 910 | global $author, $status, $sortby, $order, $nb_per_page; |
---|
| 911 | |
---|
| 912 | $author_url = |
---|
| 913 | 'comments.php?n='.$nb_per_page. |
---|
| 914 | '&status='.$status. |
---|
| 915 | '&sortby='.$sortby. |
---|
| 916 | '&order='.$order. |
---|
| 917 | '&author='.rawurlencode($this->rs->comment_author); |
---|
| 918 | |
---|
[238] | 919 | $comment_author = html::escapeHTML($this->rs->comment_author); |
---|
| 920 | if (mb_strlen($comment_author) > 20) { |
---|
| 921 | $comment_author = mb_strcut($comment_author,0,17).'...'; |
---|
| 922 | } |
---|
[0] | 923 | |
---|
[238] | 924 | return '<td class="nowrap"><a href="'.$author_url.'">'.$comment_author.'</a></td>'; |
---|
| 925 | } |
---|
| 926 | |
---|
| 927 | protected function getType() |
---|
| 928 | { |
---|
| 929 | return '<td class="nowrap">'.($this->rs->comment_trackback ? __('trackback') : __('comment')).'</td>'; |
---|
| 930 | } |
---|
| 931 | |
---|
| 932 | protected function getStatus() |
---|
| 933 | { |
---|
[0] | 934 | $img = '<img alt="%1$s" title="%1$s" src="images/%2$s" />'; |
---|
| 935 | switch ($this->rs->comment_status) { |
---|
| 936 | case 1: |
---|
| 937 | $img_status = sprintf($img,__('published'),'check-on.png'); |
---|
| 938 | break; |
---|
| 939 | case 0: |
---|
| 940 | $img_status = sprintf($img,__('unpublished'),'check-off.png'); |
---|
| 941 | break; |
---|
| 942 | case -1: |
---|
| 943 | $img_status = sprintf($img,__('pending'),'check-wrn.png'); |
---|
| 944 | break; |
---|
| 945 | case -2: |
---|
| 946 | $img_status = sprintf($img,__('junk'),'junk.png'); |
---|
| 947 | break; |
---|
| 948 | } |
---|
| 949 | |
---|
[238] | 950 | return '<td class="nowrap status">'.$img_status.'</td>'; |
---|
| 951 | } |
---|
| 952 | |
---|
| 953 | protected function getEdit() |
---|
| 954 | { |
---|
| 955 | $comment_url = 'comment.php?id='.$this->rs->comment_id; |
---|
[0] | 956 | |
---|
[238] | 957 | return |
---|
[0] | 958 | '<td class="nowrap status"><a href="'.$comment_url.'">'. |
---|
| 959 | '<img src="images/edit-mini.png" alt="" title="'.__('Edit this comment').'" /></a></td>'; |
---|
| 960 | } |
---|
| 961 | } |
---|
| 962 | |
---|
[452] | 963 | /** |
---|
| 964 | @ingroup DC_CORE |
---|
| 965 | @nosubgrouping |
---|
| 966 | @brief abstract users list class. |
---|
| 967 | |
---|
| 968 | Handle users list on admin side |
---|
| 969 | */ |
---|
[519] | 970 | class adminUserList extends adminItemsList |
---|
[0] | 971 | { |
---|
[452] | 972 | public function setColumns() |
---|
| 973 | { |
---|
[508] | 974 | $this->addColumn('username','U.user_id',__('Username'),array('adminUserList','getUserName'),array('class' => array('maximal')),true,true,false); |
---|
| 975 | $this->addColumn('firstname','user_firstname',__('First name'),array('adminUserList','getFirstName'),array('class' => array('nowrap'))); |
---|
| 976 | $this->addColumn('lastname','user_name',__('Last name'),array('adminUserList','getLastName'),array('class' => array('nowrap'))); |
---|
| 977 | $this->addColumn('displayname','user_displayname',__('Display name'),array('adminUserList','getDisplayName'),array('class' => array('nowrap'))); |
---|
| 978 | $this->addColumn('entries','nb_post',__('Entries'),array('adminUserList','getEntries'),array('class' => array('nowrap'))); |
---|
[805] | 979 | $this->default_sortby='lastname'; |
---|
| 980 | $this->default_order='asc'; |
---|
[452] | 981 | } |
---|
| 982 | |
---|
[432] | 983 | protected function getDefaultCaption() |
---|
| 984 | { |
---|
| 985 | return __('Users list'); |
---|
| 986 | } |
---|
| 987 | |
---|
[238] | 988 | protected function getUserName() |
---|
[0] | 989 | { |
---|
| 990 | $img = '<img alt="%1$s" title="%1$s" src="images/%2$s" />'; |
---|
| 991 | $img_status = ''; |
---|
| 992 | |
---|
| 993 | $p = $this->core->getUserPermissions($this->rs->user_id); |
---|
| 994 | |
---|
| 995 | if (isset($p[$this->core->blog->id]['p']['admin'])) { |
---|
| 996 | $img_status = sprintf($img,__('admin'),'admin.png'); |
---|
| 997 | } |
---|
| 998 | if ($this->rs->user_super) { |
---|
| 999 | $img_status = sprintf($img,__('superadmin'),'superadmin.png'); |
---|
| 1000 | } |
---|
[238] | 1001 | |
---|
[0] | 1002 | return |
---|
[431] | 1003 | '<th scope="row" class="maximal">'.form::hidden(array('nb_post[]'),(integer) $this->rs->nb_post). |
---|
[242] | 1004 | form::checkbox(array('user_id[]'),$this->rs->user_id).' '. |
---|
[238] | 1005 | '<a href="user.php?id='.$this->rs->user_id.'">'. |
---|
[431] | 1006 | $this->rs->user_id.'</a> '.$img_status.'</th>'; |
---|
[238] | 1007 | } |
---|
| 1008 | |
---|
| 1009 | protected function getFirstName() |
---|
| 1010 | { |
---|
| 1011 | return '<td class="nowrap">'.$this->rs->user_firstname.'</td>'; |
---|
| 1012 | } |
---|
| 1013 | |
---|
| 1014 | protected function getLastName() |
---|
| 1015 | { |
---|
| 1016 | return '<td class="nowrap">'.$this->rs->user_name.'</td>'; |
---|
| 1017 | } |
---|
| 1018 | |
---|
| 1019 | protected function getDisplayName() |
---|
| 1020 | { |
---|
| 1021 | return '<td class="nowrap">'.$this->rs->user_displayname.'</td>'; |
---|
| 1022 | } |
---|
| 1023 | |
---|
| 1024 | protected function getEntries() |
---|
| 1025 | { |
---|
| 1026 | return |
---|
[0] | 1027 | '<td class="nowrap"><a href="posts.php?user_id='.$this->rs->user_id.'">'. |
---|
[238] | 1028 | $this->rs->nb_post.'</a></td>'; |
---|
[0] | 1029 | } |
---|
| 1030 | } |
---|
[238] | 1031 | |
---|
[456] | 1032 | /** |
---|
| 1033 | @ingroup DC_CORE |
---|
| 1034 | @nosubgrouping |
---|
| 1035 | @brief abstract blogs list class. |
---|
| 1036 | |
---|
| 1037 | Handle blogs list on admin side |
---|
| 1038 | */ |
---|
[519] | 1039 | class adminBlogList extends adminItemsList |
---|
[456] | 1040 | { |
---|
| 1041 | public function setColumns() |
---|
| 1042 | { |
---|
[508] | 1043 | $this->addColumn('blogname','UPPER(blog_name)',__('Blog name'),array('adminBlogList','getBlogName'),array('class' => array('maximal')),true,true,false); |
---|
| 1044 | $this->addColumn('lastupdate','blog_upddt',__('Last update'),array('adminBlogList','getLastUpdate'),array('class' => array('nowrap'))); |
---|
| 1045 | $this->addColumn('entries',null,__('Entries'),array('adminBlogList','getEntries'),array('class' => array('nowrap')),false); |
---|
| 1046 | $this->addColumn('blogid','B.blog_id',__('Blog ID'),array('adminBlogList','getBlogId'),array('class' => array('nowrap'))); |
---|
[519] | 1047 | $this->addColumn('action',null,'',array('adminBlogList','getAction'),array('class' => array('nowrap')),false); |
---|
[508] | 1048 | $this->addColumn('status','blog_status',__('status'),array('adminBlogList','getStatus'),array('class' => array('nowrap'))); |
---|
[805] | 1049 | $this->default_sortby='lastupdate'; |
---|
| 1050 | $this->default_order='desc'; |
---|
[456] | 1051 | } |
---|
| 1052 | |
---|
| 1053 | protected function getDefaultCaption() |
---|
| 1054 | { |
---|
| 1055 | return __('Blogs list'); |
---|
| 1056 | } |
---|
| 1057 | |
---|
| 1058 | protected function getBlogName() |
---|
| 1059 | { |
---|
| 1060 | return |
---|
| 1061 | '<th scope="row" class="maximal"><a href="index.php?switchblog='.$this->rs->blog_id.'" '. |
---|
| 1062 | 'title="'.sprintf(__('Switch to blog %s'),$this->rs->blog_id).'">'. |
---|
| 1063 | html::escapeHTML($this->rs->blog_name).'</a></th>'; |
---|
| 1064 | } |
---|
| 1065 | |
---|
| 1066 | protected function getLastUpdate() |
---|
| 1067 | { |
---|
| 1068 | $offset = dt::getTimeOffset($this->core->auth->getInfo('user_tz')); |
---|
| 1069 | $blog_upddt = dt::str(__('%Y-%m-%d %H:%M'),strtotime($this->rs->blog_upddt) + $offset); |
---|
| 1070 | |
---|
| 1071 | return '<td class="nowrap">'.$blog_upddt.'</td>'; |
---|
| 1072 | } |
---|
| 1073 | |
---|
| 1074 | protected function getEntries() |
---|
| 1075 | { |
---|
| 1076 | return '<td class="nowrap">'.$this->core->countBlogPosts($this->rs->blog_id).'</td>'; |
---|
| 1077 | } |
---|
| 1078 | |
---|
| 1079 | protected function getBlogId() |
---|
| 1080 | { |
---|
| 1081 | return '<td class="nowrap">'.html::escapeHTML($this->rs->blog_id).'</td>'; |
---|
| 1082 | } |
---|
| 1083 | |
---|
| 1084 | protected function getAction() |
---|
| 1085 | { |
---|
| 1086 | $edit_link = ''; |
---|
| 1087 | $blog_id = html::escapeHTML($this->rs->blog_id); |
---|
| 1088 | |
---|
| 1089 | if ($GLOBALS['core']->auth->isSuperAdmin()) { |
---|
| 1090 | $edit_link = |
---|
| 1091 | '<a href="blog.php?id='.$blog_id.'" '. |
---|
| 1092 | 'title="'.sprintf(__('Edit blog %s'),$blog_id).'">'. |
---|
| 1093 | __('edit').'</a>'; |
---|
| 1094 | } |
---|
| 1095 | |
---|
| 1096 | return '<td class="nowrap">'.$edit_link.'</td>'; |
---|
| 1097 | } |
---|
| 1098 | |
---|
| 1099 | protected function getStatus() |
---|
| 1100 | { |
---|
| 1101 | $img_status = $this->rs->blog_status == 1 ? 'check-on' : 'check-off'; |
---|
| 1102 | $txt_status = $GLOBALS['core']->getBlogStatus($this->rs->blog_status); |
---|
| 1103 | $img_status = sprintf('<img src="images/%1$s.png" alt="%2$s" title="%2$s" />',$img_status,$txt_status); |
---|
| 1104 | |
---|
| 1105 | return '<td class="status">'.$img_status.'</td>'; |
---|
| 1106 | } |
---|
| 1107 | } |
---|
| 1108 | |
---|
| 1109 | /** |
---|
| 1110 | @ingroup DC_CORE |
---|
| 1111 | @nosubgrouping |
---|
| 1112 | @brief abstract blogs permissions list class. |
---|
| 1113 | |
---|
| 1114 | Handle blogs permissions list on admin side |
---|
| 1115 | */ |
---|
| 1116 | class adminBlogPermissionsList extends adminBlogList |
---|
| 1117 | { |
---|
| 1118 | public function setColumns() |
---|
| 1119 | { |
---|
[508] | 1120 | $this->addColumn('blogid','B.blog_id',__('Blog ID'),array('adminBlogPermissionsList','getBlogId'),array('class' => array('nowrap')),false,true,false); |
---|
| 1121 | $this->addColumn('blogname','UPPER(blog_name)',__('Blog name'),array('adminBlogPermissionsList','getBlogName'),array('class' => array('maximal')),false); |
---|
| 1122 | $this->addColumn('entries',null,__('Entries'),array('adminBlogList','getEntries'),array('class' => array('nowrap')),false); |
---|
| 1123 | $this->addColumn('status','blog_status',__('status'),array('adminBlogList','getStatus'),array('class' => array('nowrap')),false); |
---|
[456] | 1124 | } |
---|
| 1125 | |
---|
| 1126 | protected function getBlogId() |
---|
| 1127 | { |
---|
| 1128 | return |
---|
| 1129 | '<th scope="row" class="nowrap">'. |
---|
| 1130 | form::checkbox(array('blog_id[]'),$this->rs->blog_id,'','','',false,'title="'.__('select').' '.$this->rs->blog_id.'"'). |
---|
| 1131 | $this->rs->blog_id.'</th>'; |
---|
| 1132 | } |
---|
| 1133 | |
---|
| 1134 | protected function getBlogName() |
---|
| 1135 | { |
---|
| 1136 | return '<td class="maximal">'.html::escapeHTML($this->rs->blog_name).'</td>'; |
---|
| 1137 | } |
---|
| 1138 | } |
---|
| 1139 | |
---|
[804] | 1140 | ?> |
---|