setURL(); # Page text $htmlText = ''.sprintf(__('Page %s over %s'),$this->env,$this->nb_pages).''; # Previous page if($this->env != 1) { $htmlPrev = ''; } # Next page if($this->env != $this->nb_pages) { $htmlNext = ''; } # Start if($this->env != 1) { $htmlStart = ''. $htmlStart .= $this->html_start.''; } # End if($this->env != $this->nb_pages) { $htmlEnd = ''. $htmlEnd .= $this->html_end.''; } # Direct acces $htmlDirectAccess = ''.__('Direct access to page').' '. form::field(array('page'),3,3,$this->env).' '. ''. ''; # Hidden fields foreach ($_GET as $k => $v) { if ($k != $this->var_page) { $htmlHidden .= form::hidden(array($k),$v); } } $res = '

'. $htmlStart. $htmlPrev. $htmlText. $htmlNext. $htmlEnd. $htmlDirectAccess. $htmlHidden. '

'; return $this->nb_elements > 0 ? $res : ''; } } /** @ingroup DC_CORE @nosubgrouping @brief Dotclear Generic column class. Dotclear Generic column handles each column object use in adminGenericList class. */ class adminGenericColumn { protected $core; /// object dcCore object protected $id; /// string ID of defined column protected $title; /// string Title of defined column protected $callback; /// array Callback calls to display defined column protected $html; /// string Extra HTML for defined column protected $visibility; /// boolean Visibility of defined column /** Inits Generic column object @param id string Column id @param title string Column title (for table headers) @param callback array Column callback (used for display) @param html string Extra html (used for table headers) @param can_hide boolean Defines if the column can be hidden or not */ public function __construct($id,$title,$callback,$html = null,$can_hide = true) { if (!is_string($id) || $id === '') { throw new Exception(__('Invalid column ID')); } if (!is_string($title)) { throw new Exception(__('Invalid column title')); } if (is_null($html) || !is_string($html)) { $html = ''; } if (!empty($html)) { $html = ' '.$html; } if (!is_bool($can_hide)) { $can_hide = true; } try { if (!is_array($callback) || count($callback) < 2) { throw new Exception(__('Callback parameter should be an array')); } $r = new ReflectionClass($callback[0]); $f = $r->getMethod($callback[1]); $p = $r->getParentClass(); if (!$p || $p->name != 'adminGenericList') { throw new Exception(__('Callback class should be inherited of adminGenericList class')); } } catch (Exception $e) { throw new Exception(sprintf(__('Invalid column callback: %s'),$e->getMessage())); } $this->id = $id; $this->title = $title; $this->callback = $callback; $this->html = $html; $this->can_hide = $can_hide; $this->visibility = true; } /** Gets information of defined column @param info string Column info to retrive @return mixed The information requested, null otherwise */ public function getInfo($info) { return property_exists(get_class($this),$info) ? $this->{$info} : null; } /** Sets visibility of defined column @param visibility boolean Column visibility */ public function setVisibility($visibility) { if (is_bool($visibility)) { $this->visibility = $visibility; } } /** Returns visibility status of defined column @return boolean true if column is visible, false otherwise */ public function isVisible() { return $this->visibility; } /** Returns if the defined column can be hidden @return boolean true if column can be hidden, false otherwise */ public function canHide() { return $this->can_hide; } } /** @ingroup DC_CORE @nosubgrouping @brief abstract Generic list class. Dotclear Generic list handles administration lists */ abstract class adminGenericList { protected $core; protected $rs; protected $rs_count; protected $columns; /* Sets columns of defined list */ abstract function setColumns(); /** Inits List object @param core dcCore dcCore object @param rs recordSet Items recordSet to display @param rs_count int Total items number */ public function __construct($core,$rs,$rs_count) { $this->core =& $core; $this->rs =& $rs; $this->rs_count = $rs_count; $this->context = get_class($this); $this->columns = array(); $this->form_prefix = 'col_%s'; $this->form_trigger = 'add_filter'; $this->html_prev = __('prev'); $this->html_next = __('next'); $this->html_start = __('start'); $this->html_end = __('end'); $this->setColumns(); $core->callBehavior('adminListConstruct',$this); $this->setColumnsVisibility(); } /** Returns HTML code form used to choose which column to display @return string HTML code form */ public function getColumnsForm() { $block = '

'.__('Displayed information').'

'. ''; $list = array(); foreach ($this->columns as $k => $v) { $col_id = sprintf($this->form_prefix,$k); $col_label = sprintf('',$col_id,$v->getInfo('title')); $col_html = sprintf('
  • %s
  • ',$col_label.form::checkbox($col_id,1,$v->isVisible(),null,null,!$v->canHide())); array_push($list,$col_html); } $nb_per_page = isset($_GET['nb']) ? $_GET['nb'] : 10; return sprintf($block,implode('',$list)). '

     '.form::field('nb',3,3,$nb_per_page). '

    '; } /** Returns HTML code list to display @param page string|int Current page @param nb_per_page string|int Number of items to display in each page @param enclose_block string HTML wrapper of defined list @return string HTML code list */ public function display($page,$nb_per_page,$enclose_block = '') { if ($this->rs->isEmpty()) { echo '

    '.__('No entry').'

    '; } else { $pager = new dcPager($page,$this->rs_count,$nb_per_page,10); $pager->html_prev = $this->html_prev; $pager->html_next = $this->html_next; $pager->html_start = $this->html_start; $pager->html_end = $this->html_end; $pager->var_page = 'page'; $html_block = ''. $this->getCaption($page). ''; foreach ($this->columns as $k => $v) { if ($v->isVisible()) { $html_extra = $v->getInfo('html') != '' ? ' '.$v->getInfo('html') : ''; $html_block .= sprintf('',$html_extra,$v->getInfo('title')); } } $html_block .= ''. '%s'. '
    %s
    '; if ($enclose_block) { $html_block = sprintf($enclose_block,$html_block); } echo ''; $blocks = explode('%s',$html_block); echo $blocks[0]; while ($this->rs->fetch()) { echo $this->displayLine(); } echo $blocks[1]; echo ''; } } /** Adds column to defined list @param id string Column id @param title string Column title (for table headers) @param callback array Column callback (used for display) @param html string Extra html (used for table headers) @param can_hide boolean Defines if the column can be hidden or not */ protected function addColumn($id,$title,$callback,$html = null,$can_hide = true) { try { $c = new adminGenericColumn($id,$title,$callback,$html,$can_hide); $this->columns[$id] = $c; } catch (Exception $e) { if (DC_DEBUG) { $this->core->error->add($e->getMessage()); } } } /** Returns default caption text @return string Default caption */ protected function getDefaultCaption() { return; } /** Returns default HTMl code line @return string Default HTMl code line */ protected function getDefaultLine() { return '%s'; } /** Sets columns visibility of defined list */ private function setColumnsVisibility() { $ws = $this->core->auth->user_prefs->addWorkspace('lists'); $user_pref = !is_null($ws->{$this->context}) ? unserialize($ws->{$this->context}) : array(); foreach ($this->columns as $k => $v) { $visibility = array_key_exists($k,$user_pref) ? $user_pref[$k] : true; if (array_key_exists($this->form_trigger,$_REQUEST)) { $key = sprintf($this->form_prefix,$k); $visibility = !array_key_exists($key,$_REQUEST) ? false : true; } if (!$v->canHide()) { $visibility = true; } $v->setVisibility($visibility); $user_pref[$k] = $visibility; } if (array_key_exists($this->form_trigger,$_REQUEST)) { $this->core->auth->user_prefs->lists->put($this->context,serialize($user_pref),'string'); } } /** Returns HTML code for each line of defined list @return string HTML code line */ private function displayLine() { $res = ''; foreach ($this->columns as $k => $v) { if ($v->isVisible()) { $c = $v->getInfo('callback'); $func = $c[1]; $res .= $this->{$c[1]}(); } } return sprintf($this->getDefaultLine(),$res); } /** Returns caption of defined list @param page string|int Current page @return string HTML caption tag */ private function getCaption($page) { $caption = $this->getDefaultCaption(); if (!empty($caption)) { $caption = sprintf( '%s - %s', $caption,sprintf(__('Page %s'),$page) ); } return $caption; } } /** @ingroup DC_CORE @nosubgrouping @brief abstract posts list class. Handle posts list on admin side */ class adminPostList extends adminGenericList { public function setColumns() { $this->addColumn('title',__('Title'),array('adminPostList','getTitle'),' class="maximal"',false); $this->addColumn('date',__('Date'),array('adminPostList','getDate')); $this->addColumn('datetime',__('Date and time'),array('adminPostList','getDateTime')); $this->addColumn('category',__('Category'),array('adminPostList','getCategory')); $this->addColumn('author',__('Author'),array('adminPostList','getAuthor')); $this->addColumn('comment',__('Comments'),array('adminPostList','getComments')); $this->addColumn('trackback',__('Trackbacks'),array('adminPostList','getTrackbacks')); $this->addColumn('status',__('Status'),array('adminPostList','getStatus')); } protected function getDefaultCaption() { return __('Entries list'); } protected function getDefaultLine() { return '%s'; } protected function getTitle() { return ''. form::checkbox(array('entries[]'),$this->rs->post_id,'','','',!$this->rs->isEditable()).' '. ''. html::escapeHTML($this->rs->post_title).''; } protected function getDate() { return ''.dt::dt2str(__('%Y-%m-%d'),$this->rs->post_dt).''; } protected function getDateTime() { return ''.dt::dt2str(__('%Y-%m-%d %H:%M'),$this->rs->post_dt).''; } protected function getCategory() { if ($this->core->auth->check('categories',$this->core->blog->id)) { $cat_link = '%s'; } else { $cat_link = '%2$s'; } if ($this->rs->cat_title) { $cat_title = sprintf($cat_link,$this->rs->cat_id, html::escapeHTML($this->rs->cat_title)); } else { $cat_title = __('None'); } return ''.$cat_title.''; } protected function getAuthor() { return ''.$this->rs->user_id.''; } protected function getComments() { return ''.$this->rs->nb_comment.''; } protected function getTrackbacks() { return ''.$this->rs->nb_trackback.''; } protected function getStatus() { $img = '%1$s'; switch ($this->rs->post_status) { case 1: $img_status = sprintf($img,__('published'),'check-on.png'); break; case 0: $img_status = sprintf($img,__('unpublished'),'check-off.png'); break; case -1: $img_status = sprintf($img,__('scheduled'),'scheduled.png'); break; case -2: $img_status = sprintf($img,__('pending'),'check-wrn.png'); break; } $protected = ''; if ($this->rs->post_password) { $protected = sprintf($img,__('protected'),'locker.png'); } $selected = ''; if ($this->rs->post_selected) { $selected = sprintf($img,__('selected'),'selected.png'); } $attach = ''; $nb_media = $this->rs->countMedia(); if ($nb_media > 0) { $attach_str = $nb_media == 1 ? __('%d attachment') : __('%d attachments'); $attach = sprintf($img,sprintf($attach_str,$nb_media),'attach.png'); } return ''.$img_status.' '.$selected.' '.$protected.' '.$attach.''; } } /** @ingroup DC_CORE @nosubgrouping @brief abstract mini posts list class. Handle mini posts list on admin side (used for link popup) */ class adminPostMiniList extends adminPostList { public function setColumns() { $this->addColumn('title',__('Title'),array('adminPostList','getTitle'),' class="maximal"',false); $this->addColumn('date',__('Date'),array('adminPostList','getDate')); $this->addColumn('author',__('Author'),array('adminPostList','getAuthor')); $this->addColumn('status',__('Status'),array('adminPostList','getStatus')); } protected function getTitle() { return ''. form::checkbox(array('entries[]'),$this->rs->post_id,'','','',!$this->rs->isEditable()).' '. ''. html::escapeHTML($this->rs->post_title).''; } } /** @ingroup DC_CORE @nosubgrouping @brief abstract comments list class. Handle comments list on admin side */ class adminCommentList extends adminGenericList { public function setColumns() { $this->addColumn('title',__('Title'),array('adminCommentList','getTitle'),' class="maximal"',false); $this->addColumn('date',__('Date'),array('adminCommentList','getDate')); $this->addColumn('author',__('Author'),array('adminCommentList','getAuthor')); $this->addColumn('type',__('Type'),array('adminCommentList','getType')); $this->addColumn('status',__('Status'),array('adminCommentList','getStatus')); $this->addColumn('edit','',array('adminCommentList','getEdit')); } protected function getDefaultCaption() { return __('Comments list'); } protected function getDefaultLine() { return '%s'; } protected function getTitle() { $post_url = $this->core->getPostAdminURL($this->rs->post_type,$this->rs->post_id); return ''. form::checkbox(array('comments[]'),$this->rs->comment_id,'','','',0).' '. ''. html::escapeHTML($this->rs->post_title).''. ($this->rs->post_type != 'post' ? ' ('.html::escapeHTML($this->rs->post_type).')' : '').''; } protected function getDate() { return ''.dt::dt2str(__('%Y-%m-%d %H:%M'),$this->rs->comment_dt).''; } protected function getAuthor() { global $author, $status, $sortby, $order, $nb_per_page; $author_url = 'comments.php?n='.$nb_per_page. '&status='.$status. '&sortby='.$sortby. '&order='.$order. '&author='.rawurlencode($this->rs->comment_author); $comment_author = html::escapeHTML($this->rs->comment_author); if (mb_strlen($comment_author) > 20) { $comment_author = mb_strcut($comment_author,0,17).'...'; } return ''.$comment_author.''; } protected function getType() { return ''.($this->rs->comment_trackback ? __('trackback') : __('comment')).''; } protected function getStatus() { $img = '%1$s'; switch ($this->rs->comment_status) { case 1: $img_status = sprintf($img,__('published'),'check-on.png'); break; case 0: $img_status = sprintf($img,__('unpublished'),'check-off.png'); break; case -1: $img_status = sprintf($img,__('pending'),'check-wrn.png'); break; case -2: $img_status = sprintf($img,__('junk'),'junk.png'); break; } return ''.$img_status.''; } protected function getEdit() { $comment_url = 'comment.php?id='.$this->rs->comment_id; return ''. ''; } } /** @ingroup DC_CORE @nosubgrouping @brief abstract users list class. Handle users list on admin side */ class adminUserList extends adminGenericList { public function setColumns() { $this->addColumn('username',__('Username'),array('adminUserList','getUserName'),'class="maximal"',false); $this->addColumn('firstname',__('First name'),array('adminUserList','getFirstName'),'class="nowrap"'); $this->addColumn('lastname',__('Last name'),array('adminUserList','getLastName'),'class="nowrap"'); $this->addColumn('displayname',__('Display name'),array('adminUserList','getDisplayName'),'class="nowrap"'); $this->addColumn('entries',__('Entries'),array('adminUserList','getEntries'),'class="nowrap"'); } protected function getDefaultCaption() { return __('Users list'); } protected function getUserName() { $img = '%1$s'; $img_status = ''; $p = $this->core->getUserPermissions($this->rs->user_id); if (isset($p[$this->core->blog->id]['p']['admin'])) { $img_status = sprintf($img,__('admin'),'admin.png'); } if ($this->rs->user_super) { $img_status = sprintf($img,__('superadmin'),'superadmin.png'); } return ''.form::hidden(array('nb_post[]'),(integer) $this->rs->nb_post). form::checkbox(array('user_id[]'),$this->rs->user_id).' '. ''. $this->rs->user_id.' '.$img_status.''; } protected function getFirstName() { return ''.$this->rs->user_firstname.''; } protected function getLastName() { return ''.$this->rs->user_name.''; } protected function getDisplayName() { return ''.$this->rs->user_displayname.''; } protected function getEntries() { return ''. $this->rs->nb_post.''; } } ?>