%s ';
return sprintf($formatter,
$li_class, $href, $img_src, $img_alt, $img_alt);
} else {
$formatter = ' ';
return sprintf($formatter,
$li_class, $img_src_nolink, $img_alt, $img_alt);
}
}
public function setURL()
{
parent::setURL();
$url = parse_url($_SERVER['REQUEST_URI']);
if (isset($url['query'])) {
parse_str($url['query'], $args);
} else {
$args = array();
}
# Removing session information
if (session_id()) {
if (isset($args[session_name()])) {
unset($args[session_name()]);
}
}
if (isset($args[$this->var_page])) {
unset($args[$this->var_page]);
}
if (isset($args['ok'])) {
unset($args['ok']);
}
$this->form_hidden = '';
foreach ($args as $k => $v) {
if (is_array($v)) {
foreach ($v as $k2 => $v2) {
$this->form_hidden .= form::hidden(array($k . '[]'), html::escapeHTML($v2));
}
} else {
$this->form_hidden .= form::hidden(array($k), html::escapeHTML($v));
}
}
$this->form_action = $url['path'];
}
/**
* Pager Links
*
* Returns pager links
*
* @return string
*/
public function getLinks()
{
$this->setURL();
$htmlFirst = $this->getLink(
"first",
sprintf($this->page_url, 1),
"images/pagination/first.png",
"images/pagination/no-first.png",
__('First page'),
($this->env > 1)
);
$htmlPrev = $this->getLink(
"prev",
sprintf($this->page_url, $this->env - 1),
"images/pagination/previous.png",
"images/pagination/no-previous.png",
__('Previous page'),
($this->env > 1)
);
$htmlNext = $this->getLink(
"next",
sprintf($this->page_url, $this->env + 1),
"images/pagination/next.png",
"images/pagination/no-next.png",
__('Next page'),
($this->env < $this->nb_pages)
);
$htmlLast = $this->getLink(
"last",
sprintf($this->page_url, $this->nb_pages),
"images/pagination/last.png",
"images/pagination/no-last.png",
__('Last page'),
($this->env < $this->nb_pages)
);
$htmlCurrent =
'' .
sprintf(__('Page %s / %s'), $this->env, $this->nb_pages) .
' ';
$htmlDirect =
($this->nb_pages > 1 ?
sprintf('' . __('Direct access page %s'),
form::number(array($this->var_page), 1, $this->nb_pages)) .
' ' . $this->form_hidden . ' ' : '');
$res =
''
;
return $this->nb_elements > 0 ? $res : '';
}
}
class adminGenericList
{
protected $core;
protected $rs;
protected $rs_count;
public function __construct($core, $rs, $rs_count)
{
$this->core = &$core;
$this->rs = &$rs;
$this->rs_count = $rs_count;
$this->html_prev = __('« prev.');
$this->html_next = __('next »');
}
public function userColumns($type, $cols)
{
$cols_user = @$this->core->auth->user_prefs->interface->cols;
if (is_array($cols_user)) {
if (isset($cols_user[$type])) {
foreach ($cols_user[$type] as $cn => $cd) {
if (!$cd && isset($cols[$cn])) {
unset($cols[$cn]);
}
}
}
}
}
}
class adminPostList extends adminGenericList
{
public function display($page, $nb_per_page, $enclose_block = '', $filter = false)
{
if ($this->rs->isEmpty()) {
if ($filter) {
echo '' . __('No entry matches the filter') . '
';
} else {
echo '' . __('No entry') . '
';
}
} else {
$pager = new dcPager($page, $this->rs_count, $nb_per_page, 10);
$entries = array();
if (isset($_REQUEST['entries'])) {
foreach ($_REQUEST['entries'] as $v) {
$entries[(integer) $v] = true;
}
}
$html_block =
'' .
'
';
if ($filter) {
$html_block .= '' . sprintf(__('List of %s entries matching the filter.'), $this->rs_count) . ' ';
} else {
$nb_published = $this->core->blog->getPosts(array('post_status' => 1), true)->f(0);
$nb_pending = $this->core->blog->getPosts(array('post_status' => -2), true)->f(0);
$nb_programmed = $this->core->blog->getPosts(array('post_status' => -1), true)->f(0);
$nb_unpublished = $this->core->blog->getPosts(array('post_status' => 0), true)->f(0);
$html_block .= '' .
sprintf(__('List of entries (%s)'), $this->rs_count) .
($nb_published ?
sprintf(
__(', published (1)', ', published (%s)', $nb_published),
$this->core->adminurl->get('admin.posts', array('status' => 1)),
$nb_published) : '') .
($nb_pending ?
sprintf(
__(', pending (1)', ', pending (%s)', $nb_pending),
$this->core->adminurl->get('admin.posts', array('status' => -2)),
$nb_pending) : '') .
($nb_programmed ?
sprintf(__(', programmed (1)', ', programmed (%s)', $nb_programmed),
$this->core->adminurl->get('admin.posts', array('status' => -1)),
$nb_programmed) : '') .
($nb_unpublished ?
sprintf(__(', unpublished (1)', ', unpublished (%s)', $nb_unpublished),
$this->core->adminurl->get('admin.posts', array('status' => 0)),
$nb_unpublished) : '') .
' ';
}
$cols = array(
'title' => '' . __('Title') . ' ',
'date' => '' . __('Date') . ' ',
'category' => '' . __('Category') . ' ',
'author' => '' . __('Author') . ' ',
'comments' => '' . __('Comments') . ' ',
'trackbacks' => '' . __('Trackbacks') . ' ',
'status' => '' . __('Status') . ' '
);
$cols = new ArrayObject($cols);
$this->core->callBehavior('adminPostListHeader', $this->core, $this->rs, $cols);
// Cope with optional columns
$this->userColumns('posts', $cols);
$html_block .= '' . implode(iterator_to_array($cols)) . ' %s
';
if ($enclose_block) {
$html_block = sprintf($enclose_block, $html_block);
}
echo $pager->getLinks();
$blocks = explode('%s', $html_block);
echo $blocks[0];
while ($this->rs->fetch()) {
echo $this->postLine(isset($entries[$this->rs->post_id]));
}
echo $blocks[1];
echo $pager->getLinks();
}
}
private function postLine($checked)
{
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 = __('(No cat)');
}
$img = ' ';
$sts_class = '';
switch ($this->rs->post_status) {
case 1:
$img_status = sprintf($img, __('Published'), 'check-on.png');
$sts_class = 'sts-online';
break;
case 0:
$img_status = sprintf($img, __('Unpublished'), 'check-off.png');
$sts_class = 'sts-offline';
break;
case -1:
$img_status = sprintf($img, __('Scheduled'), 'scheduled.png');
$sts_class = 'sts-scheduled';
break;
case -2:
$img_status = sprintf($img, __('Pending'), 'check-wrn.png');
$sts_class = 'sts-pending';
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');
}
$res = '';
$cols = array(
'check' => '' .
form::checkbox(array('entries[]'), $this->rs->post_id,
array(
'checked' => $checked,
'disabled' => !$this->rs->isEditable()
)) .
' ',
'title' => '' .
html::escapeHTML($this->rs->post_title) . ' ',
'date' => '' . dt::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->post_dt) . ' ',
'category' => '' . $cat_title . ' ',
'author' => '' . html::escapeHTML($this->rs->user_id) . ' ',
'comments' => '' . $this->rs->nb_comment . ' ',
'trackbacks' => '' . $this->rs->nb_trackback . ' ',
'status' => '' . $img_status . ' ' . $selected . ' ' . $protected . ' ' . $attach . ' '
);
$cols = new ArrayObject($cols);
$this->core->callBehavior('adminPostListValue', $this->core, $this->rs, $cols);
// Cope with optional columns
$this->userColumns('posts', $cols);
$res .= implode(iterator_to_array($cols));
$res .= ' ';
return $res;
}
}
class adminPostMiniList extends adminGenericList
{
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);
$html_block =
'' .
'
' . __('Entries list') . ' ';
$cols = array(
'title' => '' . __('Title') . ' ',
'date' => '' . __('Date') . ' ',
'author' => '' . __('Author') . ' ',
'status' => '' . __('Status') . ' '
);
$cols = new ArrayObject($cols);
$this->core->callBehavior('adminPostMiniListHeader', $this->core, $this->rs, $cols);
// Cope with optional columns
$this->userColumns('posts', $cols);
$html_block .= ' ' . implode(iterator_to_array($cols)) . ' %s
';
if ($enclose_block) {
$html_block = sprintf($enclose_block, $html_block);
}
echo $pager->getLinks();
$blocks = explode('%s', $html_block);
echo $blocks[0];
while ($this->rs->fetch()) {
echo $this->postLine();
}
echo $blocks[1];
echo $pager->getLinks();
}
}
private function postLine()
{
$img = ' ';
$sts_class = '';
switch ($this->rs->post_status) {
case 1:
$img_status = sprintf($img, __('Published'), 'check-on.png');
$sts_class = 'sts-online';
break;
case 0:
$img_status = sprintf($img, __('Unpublished'), 'check-off.png');
$sts_class = 'sts-offline';
break;
case -1:
$img_status = sprintf($img, __('Scheduled'), 'scheduled.png');
$sts_class = 'sts-scheduled';
break;
case -2:
$img_status = sprintf($img, __('Pending'), 'check-wrn.png');
$sts_class = 'sts-pending';
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');
}
$res = '';
$cols = array(
'title' => 'rs->getURL()) . '">' .
html::escapeHTML($this->rs->post_title) . ' ',
'date' => '' . dt::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->post_dt) . ' ',
'author' => '' . html::escapeHTML($this->rs->user_id) . ' ',
'status' => '' . $img_status . ' ' . $selected . ' ' . $protected . ' ' . $attach . ' '
);
$cols = new ArrayObject($cols);
$this->core->callBehavior('adminPostMiniListValue', $this->core, $this->rs, $cols);
// Cope with optional columns
$this->userColumns('posts', $cols);
$res .= implode(iterator_to_array($cols));
$res .= ' ';
return $res;
}
}
class adminCommentList extends adminGenericList
{
public function display($page, $nb_per_page, $enclose_block = '', $filter = false, $spam = false)
{
if ($this->rs->isEmpty()) {
if ($filter) {
echo '' . __('No comments or trackbacks matches the filter') . '
';
} else {
echo '' . __('No comments') . '
';
}
} else {
// Get antispam filters' name
$filters = array();
if ($spam) {
if (class_exists('dcAntispam')) {
dcAntispam::initFilters();
$fs = dcAntispam::$filters->getFilters();
foreach ($fs as $fid => $f) {
$filters[$fid] = $f->name;
}
}
}
$pager = new dcPager($page, $this->rs_count, $nb_per_page, 10);
$comments = array();
if (isset($_REQUEST['comments'])) {
foreach ($_REQUEST['comments'] as $v) {
$comments[(integer) $v] = true;
}
}
$html_block =
'' .
'
';
if ($filter) {
$html_block .= '' .
sprintf(__(
'Comment or trackback matching the filter.',
'List of %s comments or trackbacks matching the filter.',
$this->rs_count), $this->rs_count) .
' ';
} else {
$nb_published = $this->core->blog->getComments(array('comment_status' => 1), true)->f(0);
$nb_spam = $this->core->blog->getComments(array('comment_status' => -2), true)->f(0);
$nb_pending = $this->core->blog->getComments(array('comment_status' => -1), true)->f(0);
$nb_unpublished = $this->core->blog->getComments(array('comment_status' => 0), true)->f(0);
$html_block .= '' .
sprintf(__('List of comments and trackbacks (%s)'), $this->rs_count) .
($nb_published ?
sprintf(
__(', published (1)', ', published (%s)', $nb_published),
$this->core->adminurl->get('admin.comments', array('status' => 1)),
$nb_published) : '') .
($nb_spam ?
sprintf(
__(', spam (1)', ', spam (%s)', $nb_spam),
$this->core->adminurl->get('admin.comments', array('status' => -2)),
$nb_spam) : '') .
($nb_pending ?
sprintf(__(', pending (1)', ', pending (%s)', $nb_pending),
$this->core->adminurl->get('admin.comments', array('status' => -1)),
$nb_pending) : '') .
($nb_unpublished ?
sprintf(__(', unpublished (1)', ', unpublished (%s)', $nb_unpublished),
$this->core->adminurl->get('admin.comments', array('status' => 0)),
$nb_unpublished) : '') .
' ';
}
$cols = array(
'type' => '' . __('Type') . ' ',
'author' => '' . __('Author') . ' ',
'date' => '' . __('Date') . ' ',
'status' => '' . __('Status') . ' '
);
if ($spam) {
$cols['ip'] = '' . __('IP') . ' ';
$cols['spam_filter'] = '' . __('Spam filter') . ' ';
}
$cols['entry'] = '' . __('Entry') . ' ';
$cols = new ArrayObject($cols);
$this->core->callBehavior('adminCommentListHeader', $this->core, $this->rs, $cols);
$html_block .= '' . implode(iterator_to_array($cols)) . ' %s
';
if ($enclose_block) {
$html_block = sprintf($enclose_block, $html_block);
}
echo $pager->getLinks();
$blocks = explode('%s', $html_block);
echo $blocks[0];
while ($this->rs->fetch()) {
echo $this->commentLine(isset($comments[$this->rs->comment_id]), $spam, $filters);
}
echo $blocks[1];
echo $pager->getLinks();
}
}
private function commentLine($checked = false, $spam = false, $filters = array())
{
global $core, $author, $status, $sortby, $order, $nb_per_page;
$author_url =
$this->core->adminurl->get('admin.comments', array(
'n' => $nb_per_page,
'status' => $status,
'sortby' => $sortby,
'order' => $order,
'author' => $this->rs->comment_author
));
$post_url = $this->core->getPostAdminURL($this->rs->post_type, $this->rs->post_id);
$comment_url = $this->core->adminurl->get('admin.comment', array('id' => $this->rs->comment_id));
$comment_dt =
dt::dt2str($this->core->blog->settings->system->date_format . ' - ' .
$this->core->blog->settings->system->time_format, $this->rs->comment_dt);
$img = ' ';
$sts_class = '';
switch ($this->rs->comment_status) {
case 1:
$img_status = sprintf($img, __('Published'), 'check-on.png');
$sts_class = 'sts-online';
break;
case 0:
$img_status = sprintf($img, __('Unpublished'), 'check-off.png');
$sts_class = 'sts-offline';
break;
case -1:
$img_status = sprintf($img, __('Pending'), 'check-wrn.png');
$sts_class = 'sts-pending';
break;
case -2:
$img_status = sprintf($img, __('Junk'), 'junk.png');
$sts_class = 'sts-junk';
break;
}
$post_title = html::escapeHTML($this->rs->post_title);
if (mb_strlen($post_title) > 70) {
$post_title = mb_strcut($post_title, 0, 67) . '...';
}
$comment_title = sprintf(__('Edit the %1$s from %2$s'),
$this->rs->comment_trackback ? __('trackback') : __('comment'),
html::escapeHTML($this->rs->comment_author));
$res = '';
return $res;
}
}
class adminBlogList extends adminGenericList
{
public function display($page, $nb_per_page, $enclose_block = '', $filter = false)
{
if ($this->rs->isEmpty()) {
if ($filter) {
echo '' . __('No blog matches the filter') . '
';
} else {
echo '' . __('No blog') . '
';
}
} else {
$blogs = array();
if (isset($_REQUEST['blogs'])) {
foreach ($_REQUEST['blogs'] as $v) {
$blogs[$v] = true;
}
}
$pager = new dcPager($page, $this->rs_count, $nb_per_page, 10);
$cols = array(
'blog' => 'core->auth->isSuperAdmin() ? ' colspan="2"' : '') .
' scope="col" abbr="comm" class="first nowrap">' . __('Blog id') . ' ',
'name' => '' . __('Blog name') . ' ',
'url' => '' . __('URL') . ' ',
'posts' => '' . __('Entries (all types)') . ' ',
'upddt' => '' . __('Last update') . ' ',
'status' => '' . __('Status') . ' '
);
$cols = new ArrayObject($cols);
$this->core->callBehavior('adminBlogListHeader', $this->core, $this->rs, $cols);
$html_block =
'' .
($filter ?
'' .
sprintf(__('%d blog matches the filter.', '%d blogs match the filter.', $this->rs_count), $this->rs_count) .
' '
:
'' . __('Blogs list') . ' '
) .
'' . implode(iterator_to_array($cols)) . ' %s
';
if ($enclose_block) {
$html_block = sprintf($enclose_block, $html_block);
}
$blocks = explode('%s', $html_block);
echo $pager->getLinks();
echo $blocks[0];
while ($this->rs->fetch()) {
echo $this->blogLine(isset($blogs[$this->rs->blog_id]));
}
echo $blocks[1];
echo $pager->getLinks();
}
}
private function blogLine($checked = false)
{
$blog_id = html::escapeHTML($this->rs->blog_id);
$cols = array(
'check' =>
($this->core->auth->isSuperAdmin() ?
'' .
form::checkbox(array('blogs[]'), $this->rs->blog_id, $checked) .
' ' : ''),
'blog' =>
'' .
($this->core->auth->isSuperAdmin() ?
' $blog_id)) . '" ' .
'title="' . sprintf(__('Edit blog settings for %s'), $blog_id) . '">' .
' ' . $blog_id . ' ' :
$blog_id . ' ') .
' ',
'name' =>
'' .
' $this->rs->blog_id)) . '" ' .
'title="' . sprintf(__('Switch to blog %s'), $this->rs->blog_id) . '">' .
html::escapeHTML($this->rs->blog_name) . ' ' .
' ',
'url' =>
'' .
'' . html::escapeHTML($this->rs->blog_url) .
' ',
'posts' =>
'' .
$this->core->countBlogPosts($this->rs->blog_id) .
' ',
'upddt' =>
'' .
dt::str(__('%Y-%m-%d %H:%M'), strtotime($this->rs->blog_upddt) + dt::getTimeOffset($this->core->auth->getInfo('user_tz'))) .
' ',
'status' =>
'' .
sprintf(
' ',
($this->rs->blog_status == 1 ? 'check-on' : ($this->rs->blog_status == 0 ? 'check-off' : 'check-wrn')),
$this->core->getBlogStatus($this->rs->blog_status)
) .
' '
);
$cols = new ArrayObject($cols);
$this->core->callBehavior('adminBlogListValue', $this->core, $this->rs, $cols);
return
'' .
implode(iterator_to_array($cols)) .
' ';
}
}
class adminUserList extends adminGenericList
{
public function display($page, $nb_per_page, $enclose_block = '', $filter = false)
{
if ($this->rs->isEmpty()) {
if ($filter) {
echo '' . __('No user matches the filter') . '
';
} else {
echo '' . __('No user') . '
';
}
} else {
$pager = new dcPager($page, $this->rs_count, $nb_per_page, 10);
$html_block =
'' .
'
';
if ($filter) {
$html_block .= '' . sprintf(__('List of %s users match the filter.'), $this->rs_count) . ' ';
} else {
$html_block .= '' . __('Users list') . ' ';
}
$cols = array(
'username' => '' . __('Username') . ' ',
'first_name' => '' . __('First Name') . ' ',
'last_name' => '' . __('Last Name') . ' ',
'display_name' => '' . __('Display name') . ' ',
'entries' => '' . __('Entries (all types)') . ' '
);
$cols = new ArrayObject($cols);
$this->core->callBehavior('adminUserListHeader', $this->core, $this->rs, $cols);
$html_block .= '' . implode(iterator_to_array($cols)) . ' %s
';
if ($enclose_block) {
$html_block = sprintf($enclose_block, $html_block);
}
echo $pager->getLinks();
$blocks = explode('%s', $html_block);
echo $blocks[0];
while ($this->rs->fetch()) {
echo $this->userLine();
}
echo $blocks[1];
echo $pager->getLinks();
}
}
private function userLine()
{
$img = ' ';
$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');
}
$res = '';
$cols = array(
'check' => '' . form::hidden(array('nb_post[]'), (integer) $this->rs->nb_post) .
form::checkbox(array('users[]'), $this->rs->user_id) . ' ',
'username' => '' .
$this->rs->user_id . ' ' . $img_status . ' ',
'first_name' => '' . html::escapeHTML($this->rs->user_firstname) . ' ',
'last_name' => '' . html::escapeHTML($this->rs->user_name) . ' ',
'display_name' => '' . html::escapeHTML($this->rs->user_displayname) . ' ',
'entries' => '' .
$this->rs->nb_post . ' '
);
$cols = new ArrayObject($cols);
$this->core->callBehavior('adminUserListValue', $this->core, $this->rs, $cols);
$res .= implode(iterator_to_array($cols));
$res .= ' ';
return $res;
}
}