add periods list columns to user pref
This commit is contained in:
parent
7888922dce
commit
779b46aca8
18
_admin.php
18
_admin.php
@ -29,6 +29,10 @@ $core->addBehavior(
|
||||
'adminFiltersLists',
|
||||
['adminPeriodical', 'adminFiltersLists']
|
||||
);
|
||||
$core->addBehavior(
|
||||
'adminColumnsLists',
|
||||
['adminPeriodical', 'adminColumnsLists']
|
||||
);
|
||||
|
||||
if ($core->blog->settings->periodical->periodical_active) {
|
||||
|
||||
@ -139,6 +143,20 @@ class adminPeriodical
|
||||
$blog_settings->periodical->put('periodical_updurl', !empty($_POST['periodical_updurl']));
|
||||
}
|
||||
|
||||
public static function adminColumnsLists(dcCore $core, $cols)
|
||||
{
|
||||
$cols['periodical'] = [
|
||||
__('Periodical'),
|
||||
[
|
||||
'curdt' => [true, __('Next update')],
|
||||
'pub_int' => [true, __('Frequency')],
|
||||
'pub_nb' => [true, __('Pub per update')],
|
||||
'nbposts' => [true, __('Entries')],
|
||||
'enddt' => [true, __('End date')]
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public static function adminFiltersLists(dcCore $core, $sorts)
|
||||
{
|
||||
$sorts['periodical'] = [
|
||||
|
@ -22,91 +22,111 @@ if (!defined('DC_CONTEXT_ADMIN')) {
|
||||
*/
|
||||
class adminPeriodicalList extends adminGenericList
|
||||
{
|
||||
public function periodDisplay($page, $nb_per_page, $enclose_block='')
|
||||
public function periodDisplay($filter, $enclose_block='')
|
||||
{
|
||||
$echo = '';
|
||||
if ($this->rs->isEmpty()) {
|
||||
$echo .= '<p><strong>' .__('No period') .'</strong></p>';
|
||||
if ($filter->show()) {
|
||||
echo '<p><strong>' . __('No period matches the filter') . '</strong></p>';
|
||||
} else {
|
||||
$pager = new dcPager($page, $this->rs_count, $nb_per_page, 10);
|
||||
$pager->html_prev = $this->html_prev;
|
||||
$pager->html_next = $this->html_next;
|
||||
echo '<p><strong>' . __('No period') . '</strong></p>';
|
||||
}
|
||||
} else {
|
||||
$pager = new dcPager($filter->page, $this->rs_count, $filter->nb, 10);
|
||||
$pager->var_page = 'page';
|
||||
|
||||
$html_block =
|
||||
'<div class="table-outer">' .
|
||||
'<table class="clear">' .
|
||||
'<tr>' .
|
||||
'<th colspan="2" class="nowrap">' . __('Name') . '</th>' .
|
||||
'<th class="nowrap">' . __('Next update') . '</th>' .
|
||||
'<th class="nowrap">' . __('Frequency') . '</th>' .
|
||||
'<th class="nowrap">' . __('Publications') . '</th>' .
|
||||
'<th class="nowrap">' . __('Entries') . '</th>' .
|
||||
'<th class="nowrap">' . __('End date') . '</th>' .
|
||||
'</tr>%s</table>' .
|
||||
'</div>';
|
||||
$periods = [];
|
||||
if (isset($_REQUEST['periods'])) {
|
||||
foreach ($_REQUEST['periods'] as $v) {
|
||||
$periods[(integer) $v] = true;
|
||||
}
|
||||
}
|
||||
|
||||
$html_block = '<div class="table-outer"><table><caption>' . ($filter->show() ?
|
||||
sprintf(__('List of %s periods matching the filter.'), $this->rs_count) :
|
||||
sprintf(__('List of %s periods.'), $this->rs_count)
|
||||
). '</caption>';
|
||||
|
||||
$cols = new ArrayObject([
|
||||
'name' => '<th colspan="2" class="first">' . __('Name') . '</th>',
|
||||
'curdt' => '<th scope="col" class="nowrap">' . __('Next update') . '</th>',
|
||||
'pub_int' => '<th scope="col" class="nowrap">' . __('Frequency') . '</th>',
|
||||
'pub_nb' => '<th scope="col" class="nowrap">' . __('Pub per update') . '</th>',
|
||||
'nbposts' => '<th scope="col" class="nowrap">' . __('Entries') . '</th>',
|
||||
'enddt' => '<th scope="col" class="nowrap">' . __('End date') . '</th>'
|
||||
]);
|
||||
|
||||
$this->userColumns('periodical', $cols);
|
||||
|
||||
$html_block .= '<tr>' . implode(iterator_to_array($cols)) . '</tr>%s</table>%s</div>';
|
||||
if ($enclose_block) {
|
||||
$html_block = sprintf($enclose_block, $html_block);
|
||||
}
|
||||
|
||||
$echo .= $pager->getLinks();
|
||||
|
||||
$blocks = explode('%s', $html_block);
|
||||
|
||||
$echo .= $blocks[0];
|
||||
echo $pager->getLinks() . $blocks[0];
|
||||
|
||||
while ($this->rs->fetch()) {
|
||||
$echo .= $this->periodLine();
|
||||
echo $this->periodLine(isset($periods[$this->rs->periodical_id]));
|
||||
}
|
||||
|
||||
$echo .= $blocks[1];
|
||||
|
||||
$echo .= $pager->getLinks();
|
||||
echo $blocks[1] . $blocks[2] . $pager->getLinks();
|
||||
}
|
||||
}
|
||||
|
||||
return $echo;
|
||||
}
|
||||
|
||||
private function periodLine()
|
||||
private function periodLine($checked)
|
||||
{
|
||||
$nb_posts = $this->rs->periodical->getPosts(['periodical_id' => $this->rs->periodical_id], true);
|
||||
$nb_posts = $nb_posts->f(0);
|
||||
$style = !$nb_posts ? ' offline' : '';
|
||||
$posts_links = !$nb_posts ?
|
||||
'0' :
|
||||
'<a href="plugin.php?p=periodical&part=period&period_id=' . $this->rs->periodical_id . '#posts" title="' . __('view related entries') . '">' . $nb_posts . '</a>';
|
||||
$nb_posts = $this->rs->periodical->getPosts(['periodical_id' => $this->rs->periodical_id], true)->f(0);
|
||||
$url = $this->core->adminurl->get('admin.plugin.periodical', ['part' => 'period', 'period_id' => $this->rs->periodical_id]);
|
||||
|
||||
$pub_int = in_array($this->rs->periodical_pub_int, $this->rs->periodical->getTimesCombo()) ?
|
||||
$name = '<a href="' . $url . '#period" title="' . __('edit period') . '">' . html::escapeHTML($this->rs->periodical_title) . '</a>';
|
||||
|
||||
$posts = $nb_posts ?
|
||||
'<a href="' . $url . '#posts" title="' . __('view related entries') . '">' . $nb_posts . '</a>' :
|
||||
'0';
|
||||
|
||||
$interval = in_array($this->rs->periodical_pub_int, $this->rs->periodical->getTimesCombo()) ?
|
||||
__(array_search($this->rs->periodical_pub_int, $this->rs->periodical->getTimesCombo())) : __('Unknow frequence');
|
||||
|
||||
$res =
|
||||
'<tr class="line' . $style . '">' .
|
||||
'<td class="nowrap">' . form::checkbox(['periods[]'], $this->rs->periodical_id) . '</td>' .
|
||||
'<td class="maximal"><a href="plugin.php?p=periodical&part=period&period_id=' . $this->rs->periodical_id . '#period" title="' .
|
||||
__('edit period') . '">' . html::escapeHTML($this->rs->periodical_title) . '</a></td>' .
|
||||
'<td class="nowrap">' . dt::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->periodical_curdt) . '</td>' .
|
||||
'<td class="nowrap">' . $pub_int . '</td>' .
|
||||
'<td class="nowrap">' . $this->rs->periodical_pub_nb .'</td>' .
|
||||
'<td class="nowrap">' . $posts_links . '</td>' .
|
||||
'<td class="nowrap">' . dt::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->periodical_enddt) . '</td>' .
|
||||
'</tr>';
|
||||
$cols = new ArrayObject([
|
||||
'check' => '<td class="nowrap">' . form::checkbox(['periods[]'], $this->rs->periodical_id, ['checked' => $checked]) . '</td>',
|
||||
'name' => '<td class="maximal">' . $name . '</td>',
|
||||
'curdt' => '<td class="nowrap count">' . dt::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->periodical_curdt) . '</td>',
|
||||
'pub_int' => '<td class="nowrap">' . $interval . '</td>',
|
||||
'pub_nb' => '<td class="nowrap count">' . $this->rs->periodical_pub_nb . '</td>',
|
||||
'nbposts' => '<td class="nowrap count">' . $posts. '</td>',
|
||||
'enddt' => '<td class="nowrap count">' . dt::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->periodical_enddt) . '</td>'
|
||||
]);
|
||||
|
||||
return $res;
|
||||
$this->userColumns('periodical', $cols);
|
||||
|
||||
return
|
||||
'<tr class="line ' . ($nb_posts ? '' : ' offline') . '" id="p' . $this->rs->periodical_id . '">' .
|
||||
implode(iterator_to_array($cols)) .
|
||||
'</tr>';
|
||||
}
|
||||
|
||||
public function postDisplay($page, $nb_per_page, $base_url, $enclose_block='')
|
||||
public function postDisplay($filter, $base_url, $enclose_block='')
|
||||
{
|
||||
$echo = '';
|
||||
if ($this->rs->isEmpty()) {
|
||||
$echo .= '<p><strong>' . __('No entry') . '</strong></p>';
|
||||
if ($filter->show()) {
|
||||
echo '<p><strong>' . __('No entry matches the filter') . '</strong></p>';
|
||||
} else {
|
||||
$pager = new dcPager($page, $this->rs_count, $nb_per_page, 10);
|
||||
$pager->html_prev = $this->html_prev;
|
||||
$pager->html_next = $this->html_next;
|
||||
echo '<p><strong>' . __('No entry') . '</strong></p>';
|
||||
}
|
||||
} else {
|
||||
$pager = new dcPager($filter->page, $this->rs_count, $filter->nb, 10);
|
||||
$pager->base_url = $base_url;
|
||||
$pager->var_page = 'page';
|
||||
|
||||
$periodical_entries = [];
|
||||
if (isset($_REQUEST['periodical_entries'])) {
|
||||
foreach ($_REQUEST['periodical_entries'] as $v) {
|
||||
$periodical_entries[(integer) $v] = true;
|
||||
}
|
||||
}
|
||||
|
||||
$html_block =
|
||||
'<table class="clear"><tr>' .
|
||||
'<th colspan="2">' . __('Title') . '</th>' .
|
||||
@ -128,7 +148,7 @@ class adminPeriodicalList extends adminGenericList
|
||||
$echo .= $blocks[0];
|
||||
|
||||
while ($this->rs->fetch()) {
|
||||
$echo .= $this->postLine();
|
||||
$echo .= $this->postLine(isset($periodical_entries[$this->rs->post_id]));
|
||||
}
|
||||
|
||||
$echo .= $blocks[1];
|
||||
@ -139,7 +159,7 @@ class adminPeriodicalList extends adminGenericList
|
||||
return $echo;
|
||||
}
|
||||
|
||||
private function postLine()
|
||||
private function postLine($checked)
|
||||
{
|
||||
if ($this->core->auth->check('categories', $this->core->blog->id)) {
|
||||
$cat_link = '<a href="category.php?id=%s">%s</a>';
|
||||
|
105
index.php
105
index.php
@ -18,12 +18,10 @@ if (!defined('DC_CONTEXT_ADMIN')) {
|
||||
dcPage::check('usage,contentadmin');
|
||||
|
||||
# Objects
|
||||
$s = $core->blog->settings->periodical;
|
||||
$per = new periodical($core);
|
||||
|
||||
# Default values
|
||||
$action = isset($_POST['action']) ? $_POST['action'] : '';
|
||||
$part = isset($_REQUEST['part']) && $_REQUEST['part'] == 'period' ? 'period' : 'periods';
|
||||
|
||||
############################################################
|
||||
#
|
||||
@ -31,7 +29,7 @@ $part = isset($_REQUEST['part']) && $_REQUEST['part'] == 'period' ? 'period' : '
|
||||
#
|
||||
############################################################
|
||||
|
||||
if ($part == 'period') {
|
||||
if ($_REQUEST['part'] == 'period') {
|
||||
|
||||
$starting_script = '';
|
||||
|
||||
@ -58,14 +56,11 @@ if ($part == 'period') {
|
||||
$period_pub_int = $rs->periodical_pub_int;
|
||||
$period_curdt = date('Y-m-d H:i', strtotime($rs->periodical_curdt));
|
||||
$period_enddt = date('Y-m-d H:i', strtotime($rs->periodical_enddt));
|
||||
|
||||
//todo load related posts
|
||||
}
|
||||
}
|
||||
|
||||
# Set period
|
||||
if ($action == 'setperiod') {
|
||||
|
||||
# Get POST values
|
||||
if (!empty($_POST['period_title'])) {
|
||||
$period_title = $_POST['period_title'];
|
||||
@ -74,7 +69,8 @@ if ($part == 'period') {
|
||||
$period_pub_nb = abs((integer) $_POST['period_pub_nb']);
|
||||
}
|
||||
if (!empty($_POST['period_pub_int'])
|
||||
&& in_array($_POST['period_pub_int'], $per->getTimesCombo())) {
|
||||
&& in_array($_POST['period_pub_int'], $per->getTimesCombo())
|
||||
) {
|
||||
$period_pub_int = $_POST['period_pub_int'];
|
||||
}
|
||||
if (!empty($_POST['period_curdt'])) {
|
||||
@ -104,7 +100,6 @@ if ($part == 'period') {
|
||||
|
||||
# If no error, set period
|
||||
if (!$core->error->flag()) {
|
||||
|
||||
$cur = $per->openCursor();
|
||||
$cur->periodical_title = $period_title;
|
||||
$cur->periodical_curdt = $period_curdt;
|
||||
@ -114,7 +109,6 @@ if ($part == 'period') {
|
||||
|
||||
# Update period
|
||||
if ($period_id) {
|
||||
|
||||
$per->updPeriod($period_id, $cur);
|
||||
|
||||
dcPage::addSuccessNotice(
|
||||
@ -122,7 +116,6 @@ if ($part == 'period') {
|
||||
);
|
||||
# Create period
|
||||
} else {
|
||||
|
||||
$period_id = $per->addPeriod($cur);
|
||||
|
||||
dcPage::addSuccessNotice(
|
||||
@ -130,16 +123,16 @@ if ($part == 'period') {
|
||||
);
|
||||
}
|
||||
|
||||
http::redirect(empty($_POST['redir']) ?
|
||||
$p_url . '&part=period&period_id=' . $period_id . '#period' :
|
||||
$_POST['redir']
|
||||
);
|
||||
if (!empty($_POST['redir'])) {
|
||||
http::redirect($_POST['redir']);
|
||||
} else {
|
||||
$core->adminurl->redirect('admin.plugin.periodical', ['part' => 'period', 'period_id' => $period_id], '#period');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Actions on related posts
|
||||
if (!$core->error->flag() && $period_id && $action && !empty($_POST['periodical_entries'])) {
|
||||
|
||||
# Publish posts
|
||||
if ($action == 'publish') {
|
||||
try {
|
||||
@ -153,10 +146,11 @@ if ($part == 'period') {
|
||||
__('Entries successfully published.')
|
||||
);
|
||||
|
||||
http::redirect(empty($_POST['redir']) ?
|
||||
$p_url . '&part=period&period_id=' . $period_id . '#posts' :
|
||||
$_POST['redir']
|
||||
);
|
||||
if (!empty($_POST['redir'])) {
|
||||
http::redirect($_POST['redir']);
|
||||
} else {
|
||||
$core->adminurl->redirect('admin.plugin.periodical', ['part' => 'period', 'period_id' => $period_id], '#posts');
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
$core->error->add($e->getMessage());
|
||||
}
|
||||
@ -175,10 +169,11 @@ if ($part == 'period') {
|
||||
__('Entries successfully unpublished.')
|
||||
);
|
||||
|
||||
http::redirect(empty($_POST['redir']) ?
|
||||
$p_url . '&part=period&period_id=' . $period_id . '#posts' :
|
||||
$_POST['redir']
|
||||
);
|
||||
if (!empty($_POST['redir'])) {
|
||||
http::redirect($_POST['redir']);
|
||||
} else {
|
||||
$core->adminurl->redirect('admin.plugin.periodical', ['part' => 'period', 'period_id' => $period_id], '#posts');
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
$core->error->add($e->getMessage());
|
||||
}
|
||||
@ -196,10 +191,11 @@ if ($part == 'period') {
|
||||
__('Entries successfully removed.')
|
||||
);
|
||||
|
||||
http::redirect(empty($_POST['redir']) ?
|
||||
$p_url . '&part=period&period_id=' . $period_id . '#posts' :
|
||||
$_POST['redir']
|
||||
);
|
||||
if (!empty($_POST['redir'])) {
|
||||
http::redirect($_POST['redir']);
|
||||
} else {
|
||||
$core->adminurl->redirect('admin.plugin.periodical', ['part' => 'period', 'period_id' => $period_id], '#posts');
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
$core->error->add($e->getMessage());
|
||||
}
|
||||
@ -213,6 +209,7 @@ if ($part == 'period') {
|
||||
$post_filter->add('part', 'period');
|
||||
|
||||
$params = $post_filter->params();
|
||||
$params['periodical_id'] = $period_id;
|
||||
$params['no_content'] = true;
|
||||
|
||||
# Get posts
|
||||
@ -249,9 +246,7 @@ if ($part == 'period') {
|
||||
|
||||
# Period form
|
||||
echo '
|
||||
<div class="multi-part" title="' .
|
||||
(null === $period_id ? __('New period') : __('Edit period')) .
|
||||
'" id="period">
|
||||
<div id="period"><h3>' . (null === $period_id ? __('New period') : __('Edit period')) . '</h3>
|
||||
<form method="post" action="' . $p_url . '">
|
||||
|
||||
<p><label for="period_title">' . __('Title:') . '</label>' .
|
||||
@ -311,22 +306,18 @@ if ($part == 'period') {
|
||||
'#posts';
|
||||
|
||||
echo '
|
||||
<div class="multi-part" title="' .
|
||||
__('Entries linked to this period') .
|
||||
'" id="posts">';
|
||||
<div id="posts"><h3>' . __('Entries linked to this period') . '</h3>';
|
||||
|
||||
# Filters
|
||||
$post_filter->display(['admin.plugin.periodical', '#posts'],
|
||||
$core->adminurl->getHiddenFormFields('admin.plugin.zoneclearFeedServer', [
|
||||
'p' => 'periodical',
|
||||
'part' => 'period',
|
||||
'period_id' => $period_id
|
||||
$core->adminurl->getHiddenFormFields('admin.plugin.periodical', [
|
||||
'period_id' => $period_id,
|
||||
'part' => 'period'
|
||||
])
|
||||
);
|
||||
|
||||
# Posts list
|
||||
echo
|
||||
$post_list->postDisplay($post_filter->page, $post_filter->nb, $base_url,
|
||||
echo $post_list->postDisplay($post_filter, $base_url,
|
||||
'<form action="' . $p_url . '" method="post" id="form-entries">' .
|
||||
|
||||
'%s' .
|
||||
@ -337,10 +328,10 @@ if ($part == 'period') {
|
||||
'<p class="col right">' . __('Selected entries action:') . ' ' .
|
||||
form::combo('action', $combo_action) .
|
||||
'<input type="submit" value="' . __('ok') . '" /></p>' .
|
||||
$core->adminurl->getHiddenFormFields('admin.plugin.periodical', $post_filter->values()) .
|
||||
form::hidden(['period_id'], $period_id) .
|
||||
form::hidden(['p'], 'periodical') .
|
||||
form::hidden(['redir'], sprintf($base_url, $post_filter->page)) .
|
||||
$core->adminurl->getHiddenFormFields('admin.plugin.periodical', array_merge($post_filter->values(), [
|
||||
'period_id' => $period_id,
|
||||
'redir' => sprintf($base_url, $post_filter->page)
|
||||
])) .
|
||||
$core->formNonce() .
|
||||
'</div>' .
|
||||
'</form>'
|
||||
@ -371,10 +362,11 @@ if ($part == 'period') {
|
||||
__('Periods removed.')
|
||||
);
|
||||
|
||||
http::redirect(empty($_POST['redir']) ?
|
||||
$p_url.'&part=periods' :
|
||||
$_POST['redir']
|
||||
);
|
||||
if (!empty($_POST['redir'])) {
|
||||
http::redirect($_POST['redir']);
|
||||
} else {
|
||||
$core->adminurl->redirect('admin.plugin.periodical', ['part' => 'periods']);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
$core->error->add($e->getMessage());
|
||||
}
|
||||
@ -391,10 +383,11 @@ if ($part == 'period') {
|
||||
__('Periods emptied.')
|
||||
);
|
||||
|
||||
http::redirect(empty($_POST['redir']) ?
|
||||
$p_url.'&part=periods' :
|
||||
$_POST['redir']
|
||||
);
|
||||
if (!empty($_POST['redir'])) {
|
||||
http::redirect($_POST['redir']);
|
||||
} else {
|
||||
$core->adminurl->redirect('admin.plugin.periodical', ['part' => 'periods']);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
$core->error->add($e->getMessage());
|
||||
}
|
||||
@ -428,12 +421,10 @@ if ($part == 'period') {
|
||||
'</head>' .
|
||||
'<body>' .
|
||||
|
||||
dcPage::breadcrumb(
|
||||
[
|
||||
dcPage::breadcrumb([
|
||||
html::escapeHTML($core->blog->name) => '',
|
||||
__('Periodical') => ''
|
||||
]
|
||||
) .
|
||||
]) .
|
||||
dcPage::notices() .
|
||||
|
||||
'<p class="top-add">
|
||||
@ -443,8 +434,8 @@ if ($part == 'period') {
|
||||
# Filters
|
||||
$p_filter->display('admin.plugin.periodical', form::hidden('p', 'periodical') . form::hidden('part', 'periods'));
|
||||
|
||||
# Posts list
|
||||
echo $period_list->periodDisplay($p_filter->page, $p_filter->nb,
|
||||
# Periods list
|
||||
$period_list->periodDisplay($p_filter,
|
||||
'<form action="' . $p_url . '" method="post" id="form-periods">' .
|
||||
|
||||
'%s' .
|
||||
|
Loading…
Reference in New Issue
Block a user