Changeset 238:93307439c17f for inc
- Timestamp:
- 05/11/11 09:52:57 (14 years ago)
- Branch:
- formfilters
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
inc/admin/lib.pager.php
r0 r238 12 12 if (!defined('DC_RC_PATH')) { return; } 13 13 14 class adminGenericColumn 15 { 16 protected $core; 17 protected $rs; 18 protected $id; 19 protected $title; 20 protected $callback; 21 protected $html; 22 protected $order; 23 protected $visibility; 24 25 public function __construct($id,$title,$callback,$html = null,$order = null) 26 { 27 if (!is_string($id) || $id === '') { 28 throw new Exception(__('Invalid column ID')); 29 } 30 31 if (!is_string($title)) { 32 throw new Exception(__('Invalid column title')); 33 } 34 if (is_null($html) || !is_string($html)) { 35 $html = ''; 36 } 37 if (!is_int($order)) { 38 $order = null; 39 } 40 41 try { 42 $r = new ReflectionClass($callback[0]); 43 $f = $r->getMethod($callback[1]); 44 $p = $r->getParentClass(); 45 if (!$p || $p->name != 'adminGenericList') { 46 throw new Exception(__('Invalid callback')); 47 } 48 } 49 catch (Exception $e) { 50 throw new Exception(__('Invalid callback')); 51 } 52 53 $this->id = $id; 54 $this->title = $title; 55 $this->callback = $callback; 56 $this->html = $html; 57 $this->order = $order; 58 $this->visibility = true; 59 } 60 61 public function getInfo($k) 62 { 63 return property_exists(get_class($this),$k) ? $this->{$k} : null; 64 } 65 66 public function setVisibility($visibility) 67 { 68 if (is_bool($visibility)) { 69 $this->visibility = $visibility; 70 } 71 } 72 73 public function isVisible() 74 { 75 return $this->visibility; 76 } 77 } 78 14 79 class adminGenericList 15 80 { … … 17 82 protected $rs; 18 83 protected $rs_count; 84 protected $columns; 85 19 86 20 87 public function __construct($core,$rs,$rs_count) … … 23 90 $this->rs =& $rs; 24 91 $this->rs_count = $rs_count; 92 $this->context = get_class($this); 93 $this->columns = array(); 94 $this->column_pattern = 'c_%s'; 95 25 96 $this->html_prev = __('«prev.'); 26 97 $this->html_next = __('next»'); 27 } 28 } 29 30 class adminPostList extends adminGenericList 31 { 98 99 # Post columns 100 $this->addColumn('adminPostList','title',__('Title'),array('adminPostList','getTitle')); 101 $this->addColumn('adminPostList','date',__('Date'),array('adminPostList','getDate')); 102 $this->addColumn('adminPostList','category',__('Category'),array('adminPostList','getCategory')); 103 $this->addColumn('adminPostList','author',__('Author'),array('adminPostList','getAuthor')); 104 $this->addColumn('adminPostList','comment',__('Comments'),array('adminPostList','getComments')); 105 $this->addColumn('adminPostList','trackback',__('Trackbacks'),array('adminPostList','getTrackbacks')); 106 $this->addColumn('adminPostList','status',__('Status'),array('adminPostList','getStatus')); 107 108 # Post (mini list) columns 109 $this->addColumn('adminPostMiniList','title',__('Title'),array('adminPostList','getTitle')); 110 $this->addColumn('adminPostMiniList','date',__('Date'),array('adminPostList','getDate')); 111 $this->addColumn('adminPostMiniList','author',__('Author'),array('adminPostList','getAuthor')); 112 $this->addColumn('adminPostMiniList','status',__('Status'),array('adminPostList','getStatus')); 113 114 # Comment columns 115 $this->addColumn('adminCommentList','title',__('Title'),array('adminCommentList','getTitle')); 116 $this->addColumn('adminCommentList','date',__('Date'),array('adminCommentList','getDate')); 117 $this->addColumn('adminCommentList','author',__('Author'),array('adminCommentList','getAuthor')); 118 $this->addColumn('adminCommentList','type',__('Type'),array('adminCommentList','getType')); 119 $this->addColumn('adminCommentList','status',__('Status'),array('adminCommentList','getStatus')); 120 $this->addColumn('adminCommentList','edit','',array('adminCommentList','getEdit')); 121 122 # Comment columns 123 $this->addColumn('adminUserList','username',__('Username'),array('adminUserList','getUserName')); 124 $this->addColumn('adminUserList','firstname',__('First name'),array('adminUserList','getFirstName')); 125 $this->addColumn('adminUserList','lastname',__('Last name'),array('adminUserList','getLastName')); 126 $this->addColumn('adminUserList','displayname',__('Display name'),array('adminUserList','getDisplayName')); 127 $this->addColumn('adminUserList','entries',__('Entries'),array('adminUserList','getEntries')); 128 129 $this->setColumnsVisibility(); 130 131 $core->callBehavior('adminGenericListConstruct',$this); 132 } 133 134 public function addColumn($context,$id,$title,$callback,$html = null,$order = null) 135 { 136 try { 137 if (!array_key_exists($context,$this->columns)) { 138 $this->columns[$context] = array(); 139 } 140 141 $c = new adminGenericColumn($id,$title,$callback,$html,$order); 142 $this->columns[$context][$c->getInfo('id')] = $c; 143 } 144 catch (Exception $e) { 145 if (DC_DEBUG) { 146 $this->core->error->add($e->getMessage()); 147 } 148 } 149 } 150 151 public function setColumnsVisibility() 152 { 153 foreach ($this->columns[$this->context] as $k => $v) { 154 $key = sprintf($this->column_pattern,$k); 155 if (array_key_exists($key,$_REQUEST)) { 156 $v->setVisibility((bool) $key); 157 } 158 } 159 } 160 32 161 public function display($page,$nb_per_page,$enclose_block='') 33 162 { … … 43 172 $pager->var_page = 'page'; 44 173 45 $html_block = 46 '<table class="clear"><tr>'. 47 '<th colspan="2">'.__('Title').'</th>'. 48 '<th>'.__('Date').'</th>'. 49 '<th>'.__('Category').'</th>'. 50 '<th>'.__('Author').'</th>'. 51 '<th>'.__('Comments').'</th>'. 52 '<th>'.__('Trackbacks').'</th>'. 53 '<th>'.__('Status').'</th>'. 54 '</tr>%s</table>'; 174 $html_block = '<table class="clear"><tr>'; 175 176 foreach ($this->columns[$this->context] as $k => $v) { 177 if ($v->isVisible()) { 178 $html_block .= sprintf('<th%s>%s</th>',$v->getInfo('html'),$v->getInfo('title')); 179 } 180 } 181 182 $html_block .= '</tr>%s</table>'; 55 183 56 184 if ($enclose_block) { … … 66 194 while ($this->rs->fetch()) 67 195 { 68 echo $this-> postLine();196 echo $this->displayLine(); 69 197 } 70 198 … … 75 203 } 76 204 77 private function postLine() 205 private function displayLine() 206 { 207 $res = ''; 208 209 foreach ($this->columns[$this->context] as $k => $v) { 210 if ($v->isVisible()) { 211 $c = $v->getInfo('callback'); 212 $func = $c[1]; 213 $res .= $this->{$c[1]}(); 214 } 215 } 216 217 return sprintf($this->getDefaultLine(),$res); 218 } 219 220 protected function getDefaultLine() 221 { 222 return '<tr class="line">%s</tr>'; 223 } 224 } 225 226 class adminPostList extends adminGenericList 227 { 228 protected function getDefaultLine() 229 { 230 return 231 '<tr class="line'.($this->rs->post_status != 1 ? ' offline' : '').'"'. 232 ' id="p'.$this->rs->post_id.'">%s</tr>'; 233 } 234 235 protected function getTitle() 236 { 237 return 238 '<td class="maximal">'. 239 form::checkbox(array('entries[]'),$this->rs->post_id,'','','',!$this->rs->isEditable()).' '. 240 '<a href="'.$this->core->getPostAdminURL($this->rs->post_type,$this->rs->post_id).'">'. 241 html::escapeHTML($this->rs->post_title).'</a></td>'; 242 } 243 244 protected function getDate() 245 { 246 return '<td class="nowrap">'.dt::dt2str(__('%Y-%m-%d %H:%M'),$this->rs->post_dt).'</td>'; 247 } 248 249 protected function getCategory() 78 250 { 79 251 if ($this->core->auth->check('categories',$this->core->blog->id)) { … … 90 262 } 91 263 264 return '<td class="nowrap">'.$cat_title.'</td>'; 265 } 266 267 protected function getAuthor() 268 { 269 return '<td class="nowrap">'.$this->rs->user_id.'</td>'; 270 } 271 272 protected function getComments() 273 { 274 return '<td class="nowrap">'.$this->rs->nb_comment.'</td>'; 275 } 276 277 protected function getTrackbacks() 278 { 279 return '<td class="nowrap">'.$this->rs->nb_trackback.'</td>'; 280 } 281 282 protected function getStatus() 283 { 92 284 $img = '<img alt="%1$s" title="%1$s" src="images/%2$s" />'; 93 285 switch ($this->rs->post_status) { … … 123 315 } 124 316 125 $res = '<tr class="line'.($this->rs->post_status != 1 ? ' offline' : '').'"'. 126 ' id="p'.$this->rs->post_id.'">'; 127 128 $res .= 129 '<td class="nowrap">'. 130 form::checkbox(array('entries[]'),$this->rs->post_id,'','','',!$this->rs->isEditable()).'</td>'. 131 '<td class="maximal"><a href="'.$this->core->getPostAdminURL($this->rs->post_type,$this->rs->post_id).'">'. 132 html::escapeHTML($this->rs->post_title).'</a></td>'. 133 '<td class="nowrap">'.dt::dt2str(__('%Y-%m-%d %H:%M'),$this->rs->post_dt).'</td>'. 134 '<td class="nowrap">'.$cat_title.'</td>'. 135 '<td class="nowrap">'.$this->rs->user_id.'</td>'. 136 '<td class="nowrap">'.$this->rs->nb_comment.'</td>'. 137 '<td class="nowrap">'.$this->rs->nb_trackback.'</td>'. 138 '<td class="nowrap status">'.$img_status.' '.$selected.' '.$protected.' '.$attach.'</td>'. 139 '</tr>'; 140 141 return $res; 317 return '<td class="nowrap status">'.$img_status.' '.$selected.' '.$protected.' '.$attach.'</td>'; 142 318 } 143 319 } 144 320 145 class adminPostMiniList extends adminGenericList 146 { 147 public function display($page,$nb_per_page,$enclose_block='') 148 { 149 if ($this->rs->isEmpty()) 150 { 151 echo '<p><strong>'.__('No entry').'</strong></p>'; 152 } 153 else 154 { 155 $pager = new pager($page,$this->rs_count,$nb_per_page,10); 156 $pager->html_prev = $this->html_prev; 157 $pager->html_next = $this->html_next; 158 $pager->var_page = 'page'; 159 160 $html_block = 161 '<table class="clear"><tr>'. 162 '<th>'.__('Title').'</th>'. 163 '<th>'.__('Date').'</th>'. 164 '<th>'.__('Author').'</th>'. 165 '<th>'.__('Status').'</th>'. 166 '</tr>%s</table>'; 167 168 if ($enclose_block) { 169 $html_block = sprintf($enclose_block,$html_block); 170 } 171 172 echo '<p>'.__('Page(s)').' : '.$pager->getLinks().'</p>'; 173 174 $blocks = explode('%s',$html_block); 175 176 echo $blocks[0]; 177 178 while ($this->rs->fetch()) 179 { 180 echo $this->postLine(); 181 } 182 183 echo $blocks[1]; 184 185 echo '<p>'.__('Page(s)').' : '.$pager->getLinks().'</p>'; 186 } 187 } 188 189 private function postLine() 190 { 191 $img = '<img alt="%1$s" title="%1$s" src="images/%2$s" />'; 192 switch ($this->rs->post_status) { 193 case 1: 194 $img_status = sprintf($img,__('published'),'check-on.png'); 195 break; 196 case 0: 197 $img_status = sprintf($img,__('unpublished'),'check-off.png'); 198 break; 199 case -1: 200 $img_status = sprintf($img,__('scheduled'),'scheduled.png'); 201 break; 202 case -2: 203 $img_status = sprintf($img,__('pending'),'check-wrn.png'); 204 break; 205 } 206 207 $protected = ''; 208 if ($this->rs->post_password) { 209 $protected = sprintf($img,__('protected'),'locker.png'); 210 } 211 212 $selected = ''; 213 if ($this->rs->post_selected) { 214 $selected = sprintf($img,__('selected'),'selected.png'); 215 } 216 217 $attach = ''; 218 $nb_media = $this->rs->countMedia(); 219 if ($nb_media > 0) { 220 $attach_str = $nb_media == 1 ? __('%d attachment') : __('%d attachments'); 221 $attach = sprintf($img,sprintf($attach_str,$nb_media),'attach.png'); 222 } 223 224 $res = '<tr class="line'.($this->rs->post_status != 1 ? ' offline' : '').'"'. 225 ' id="p'.$this->rs->post_id.'">'; 226 227 $res .= 228 '<td class="maximal"><a href="'.$this->core->getPostAdminURL($this->rs->post_type,$this->rs->post_id).'" '. 229 'title="'.html::escapeHTML($this->rs->getURL()).'">'. 230 html::escapeHTML($this->rs->post_title).'</a></td>'. 231 '<td class="nowrap">'.dt::dt2str(__('%Y-%m-%d %H:%M'),$this->rs->post_dt).'</td>'. 232 '<td class="nowrap">'.$this->rs->user_id.'</td>'. 233 '<td class="nowrap status">'.$img_status.' '.$selected.' '.$protected.' '.$attach.'</td>'. 234 '</tr>'; 235 236 return $res; 237 } 238 } 321 class adminPostMiniList extends adminPostList{} 239 322 240 323 class adminCommentList extends adminGenericList 241 324 { 242 public function display($page,$nb_per_page,$enclose_block='') 243 { 244 if ($this->rs->isEmpty()) 245 { 246 echo '<p><strong>'.__('No comment').'</strong></p>'; 247 } 248 else 249 { 250 $pager = new pager($page,$this->rs_count,$nb_per_page,10); 251 $pager->html_prev = $this->html_prev; 252 $pager->html_next = $this->html_next; 253 $pager->var_page = 'page'; 254 255 $html_block = 256 '<table><tr>'. 257 '<th colspan="2">'.__('Title').'</th>'. 258 '<th>'.__('Date').'</th>'. 259 '<th>'.__('Author').'</th>'. 260 '<th>'.__('Type').'</th>'. 261 '<th>'.__('Status').'</th>'. 262 '<th> </th>'. 263 '</tr>%s</table>'; 264 265 if ($enclose_block) { 266 $html_block = sprintf($enclose_block,$html_block); 267 } 268 269 echo '<p>'.__('Page(s)').' : '.$pager->getLinks().'</p>'; 270 271 $blocks = explode('%s',$html_block); 272 273 echo $blocks[0]; 274 275 while ($this->rs->fetch()) 276 { 277 echo $this->commentLine(); 278 } 279 280 echo $blocks[1]; 281 282 echo '<p>'.__('Page(s)').' : '.$pager->getLinks().'</p>'; 283 } 284 } 285 286 private function commentLine() 325 protected function getDefaultLine() 326 { 327 return 328 '<tr class="line'.($this->rs->comment_status != 1 ? ' offline' : '').'"'. 329 ' id="c'.$this->rs->comment_id.'">%s</tr>'; 330 } 331 332 protected function getContent() 333 { 334 return 335 '<tr class="line'.($this->rs->comment_status != 1 ? ' offline' : '').'"'. 336 ' id="c'.$this->rs->comment_id.'">%s</tr>'; 337 } 338 339 protected function getTitle() 340 { 341 $post_url = $this->core->getPostAdminURL($this->rs->post_type,$this->rs->post_id); 342 343 return 344 '<td class="maximal"><a href="'.$post_url.'">'. 345 html::escapeHTML($this->rs->post_title).'</a>'. 346 ($this->rs->post_type != 'post' ? ' ('.html::escapeHTML($this->rs->post_type).')' : '').'</td>'; 347 } 348 349 protected function getDate() 350 { 351 return '<td class="nowrap">'.dt::dt2str(__('%Y-%m-%d %H:%M'),$this->rs->comment_dt).'</td>'; 352 } 353 354 protected function getAuthor() 287 355 { 288 356 global $author, $status, $sortby, $order, $nb_per_page; … … 295 363 '&author='.rawurlencode($this->rs->comment_author); 296 364 297 $post_url = $this->core->getPostAdminURL($this->rs->post_type,$this->rs->post_id); 298 299 $comment_url = 'comment.php?id='.$this->rs->comment_id; 300 301 $comment_dt = 302 dt::dt2str($this->core->blog->settings->system->date_format.' - '. 303 $this->core->blog->settings->system->time_format,$this->rs->comment_dt); 304 365 $comment_author = html::escapeHTML($this->rs->comment_author); 366 if (mb_strlen($comment_author) > 20) { 367 $comment_author = mb_strcut($comment_author,0,17).'...'; 368 } 369 370 return '<td class="nowrap"><a href="'.$author_url.'">'.$comment_author.'</a></td>'; 371 } 372 373 protected function getType() 374 { 375 return '<td class="nowrap">'.($this->rs->comment_trackback ? __('trackback') : __('comment')).'</td>'; 376 } 377 378 protected function getStatus() 379 { 305 380 $img = '<img alt="%1$s" title="%1$s" src="images/%2$s" />'; 306 381 switch ($this->rs->comment_status) { … … 319 394 } 320 395 321 $comment_author = html::escapeHTML($this->rs->comment_author); 322 if (mb_strlen($comment_author) > 20) { 323 $comment_author = mb_strcut($comment_author,0,17).'...'; 324 } 325 326 $res = '<tr class="line'.($this->rs->comment_status != 1 ? ' offline' : '').'"'. 327 ' id="c'.$this->rs->comment_id.'">'; 328 329 $res .= 330 '<td class="nowrap">'. 331 form::checkbox(array('comments[]'),$this->rs->comment_id,'','','',0).'</td>'. 332 '<td class="maximal"><a href="'.$post_url.'">'. 333 html::escapeHTML($this->rs->post_title).'</a>'. 334 ($this->rs->post_type != 'post' ? ' ('.html::escapeHTML($this->rs->post_type).')' : '').'</td>'. 335 '<td class="nowrap">'.dt::dt2str(__('%Y-%m-%d %H:%M'),$this->rs->comment_dt).'</td>'. 336 '<td class="nowrap"><a href="'.$author_url.'">'.$comment_author.'</a></td>'. 337 '<td class="nowrap">'.($this->rs->comment_trackback ? __('trackback') : __('comment')).'</td>'. 338 '<td class="nowrap status">'.$img_status.'</td>'. 396 return '<td class="nowrap status">'.$img_status.'</td>'; 397 } 398 399 protected function getEdit() 400 { 401 $comment_url = 'comment.php?id='.$this->rs->comment_id; 402 403 return 339 404 '<td class="nowrap status"><a href="'.$comment_url.'">'. 340 405 '<img src="images/edit-mini.png" alt="" title="'.__('Edit this comment').'" /></a></td>'; 341 342 $res .= '</tr>';343 344 return $res;345 406 } 346 407 } … … 348 409 class adminUserList extends adminGenericList 349 410 { 350 public function display($page,$nb_per_page,$enclose_block='') 351 { 352 if ($this->rs->isEmpty()) 353 { 354 echo '<p><strong>'.__('No user').'</strong></p>'; 355 } 356 else 357 { 358 $pager = new pager($page,$this->rs_count,$nb_per_page,10); 359 $pager->html_prev = $this->html_prev; 360 $pager->html_next = $this->html_next; 361 $pager->var_page = 'page'; 362 363 $html_block = 364 '<table class="clear"><tr>'. 365 '<th colspan="2">'.__('Username').'</th>'. 366 '<th>'.__('First Name').'</th>'. 367 '<th>'.__('Last Name').'</th>'. 368 '<th>'.__('Display name').'</th>'. 369 '<th class="nowrap">'.__('Entries').'</th>'. 370 '</tr>%s</table>'; 371 372 if ($enclose_block) { 373 $html_block = sprintf($enclose_block,$html_block); 374 } 375 376 echo '<p>'.__('Page(s)').' : '.$pager->getLinks().'</p>'; 377 378 $blocks = explode('%s',$html_block); 379 380 echo $blocks[0]; 381 382 while ($this->rs->fetch()) 383 { 384 echo $this->userLine(); 385 } 386 387 echo $blocks[1]; 388 389 echo '<p>'.__('Page(s)').' : '.$pager->getLinks().'</p>'; 390 } 391 } 392 393 private function userLine() 411 protected function getUserName() 394 412 { 395 413 $img = '<img alt="%1$s" title="%1$s" src="images/%2$s" />'; … … 404 422 $img_status = sprintf($img,__('superadmin'),'superadmin.png'); 405 423 } 406 return 407 '<tr class="line">'. 408 '<td class="nowrap">'.form::hidden(array('nb_post[]'),(integer) $this->rs->nb_post). 409 form::checkbox(array('user_id[]'),$this->rs->user_id).'</td>'. 410 '<td class="maximal"><a href="user.php?id='.$this->rs->user_id.'">'. 411 $this->rs->user_id.'</a> '.$img_status.'</td>'. 412 '<td class="nowrap">'.$this->rs->user_firstname.'</td>'. 413 '<td class="nowrap">'.$this->rs->user_name.'</td>'. 414 '<td class="nowrap">'.$this->rs->user_displayname.'</td>'. 424 425 return 426 '<td class="maximal">'.form::hidden(array('nb_post[]'),(integer) $this->rs->nb_post). 427 form::checkbox(array('user_id[]'),$this->rs->user_id). 428 '<a href="user.php?id='.$this->rs->user_id.'">'. 429 $this->rs->user_id.'</a> '.$img_status.'</td>'; 430 } 431 432 protected function getFirstName() 433 { 434 return '<td class="nowrap">'.$this->rs->user_firstname.'</td>'; 435 } 436 437 protected function getLastName() 438 { 439 return '<td class="nowrap">'.$this->rs->user_name.'</td>'; 440 } 441 442 protected function getDisplayName() 443 { 444 return '<td class="nowrap">'.$this->rs->user_displayname.'</td>'; 445 } 446 447 protected function getEntries() 448 { 449 return 415 450 '<td class="nowrap"><a href="posts.php?user_id='.$this->rs->user_id.'">'. 416 $this->rs->nb_post.'</a></td>'. 417 '</tr>'; 451 $this->rs->nb_post.'</a></td>'; 418 452 } 419 453 } 454 420 455 ?>
Note: See TracChangeset
for help on using the changeset viewer.