prepare to DC 2.24

This commit is contained in:
Jean-Christian Paul Denis 2022-11-14 20:55:22 +01:00
parent 09bcd72b54
commit 152aa8d3c4
Signed by: JcDenis
GPG Key ID: 1B5B8C5B90B6C951
13 changed files with 200 additions and 205 deletions

View File

@ -1,3 +1,6 @@
2022.11.12
- require Dotclear 2.24
2022.05.16 2022.05.16
- require Dotclear 2.22 - require Dotclear 2.22
- fix period dates - fix period dates

View File

@ -15,74 +15,73 @@ if (!defined('DC_CONTEXT_ADMIN')) {
return null; return null;
} }
$core->blog->settings->addNamespace('periodical'); dcCore::app()->blog->settings->addNamespace('periodical');
$core->addBehavior( dcCore::app()->addBehavior(
'adminBlogPreferencesForm', 'adminBlogPreferencesFormV2',
['adminPeriodical', 'adminBlogPreferencesForm'] ['adminPeriodical', 'adminBlogPreferencesForm']
); );
$core->addBehavior( dcCore::app()->addBehavior(
'adminBeforeBlogSettingsUpdate', 'adminBeforeBlogSettingsUpdate',
['adminPeriodical', 'adminBeforeBlogSettingsUpdate'] ['adminPeriodical', 'adminBeforeBlogSettingsUpdate']
); );
$core->addBehavior( dcCore::app()->addBehavior(
'adminFiltersLists', 'adminFiltersListsV2',
['adminPeriodical', 'adminFiltersLists'] ['adminPeriodical', 'adminFiltersLists']
); );
$core->addBehavior( dcCore::app()->addBehavior(
'adminColumnsLists', 'adminColumnsListsV2',
['adminPeriodical', 'adminColumnsLists'] ['adminPeriodical', 'adminColumnsLists']
); );
$core->addBehavior( dcCore::app()->addBehavior(
'adminColumnsLists', 'adminPostListHeaderV2',
['adminPeriodical', 'adminColumnsLists']
);
$core->addBehavior(
'adminPostListHeader',
['adminPeriodical', 'adminPostListHeader'] ['adminPeriodical', 'adminPostListHeader']
); );
$core->addBehavior( dcCore::app()->addBehavior(
'adminPostListValue', 'adminPostListValueV2',
['adminPeriodical', 'adminPostListValue'] ['adminPeriodical', 'adminPostListValue']
); );
if ($core->blog->settings->periodical->periodical_active) { if (dcCore::app()->blog->settings->periodical->periodical_active) {
$_menu['Plugins']->addItem( dcCore::app()->menu[dcAdmin::MENU_PLUGINS]->addItem(
__('Periodical'), __('Periodical'),
$core->adminurl->get('admin.plugin.periodical'), dcCore::app()->adminurl->get('admin.plugin.periodical'),
dcPage::getPF('periodical/icon.png'), dcPage::getPF('periodical/icon.png'),
preg_match('/' . preg_quote($core->adminurl->get('admin.plugin.periodical')) . '(&.*)?$/', $_SERVER['REQUEST_URI']), preg_match('/' . preg_quote(dcCore::app()->adminurl->get('admin.plugin.periodical')) . '(&.*)?$/', $_SERVER['REQUEST_URI']),
$core->auth->check('usage,contentadmin', $core->blog->id) dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([
dcAuth::PERMISSION_USAGE,
dcAuth::PERMISSION_CONTENT_ADMIN,
]), dcCore::app()->blog->id)
); );
$core->addBehavior( dcCore::app()->addBehavior(
'adminDashboardFavorites', 'adminDashboardFavoritesV2',
['adminPeriodical', 'adminDashboardFavorites'] ['adminPeriodical', 'adminDashboardFavorites']
); );
$core->addBehavior( dcCore::app()->addBehavior(
'adminPostHeaders', 'adminPostHeaders',
['adminPeriodical', 'adminPostHeaders'] ['adminPeriodical', 'adminPostHeaders']
); );
$core->addBehavior( dcCore::app()->addBehavior(
'adminPostsActionsPage', 'adminPostsActions',
['adminPeriodical', 'adminPostsActionsPage'] ['adminPeriodical', 'adminPostsActions']
); );
$core->addBehavior( dcCore::app()->addBehavior(
'adminPostFormItems', 'adminPostFormItems',
['adminPeriodical', 'adminPostFormItems'] ['adminPeriodical', 'adminPostFormItems']
); );
$core->addBehavior( dcCore::app()->addBehavior(
'adminAfterPostUpdate', 'adminAfterPostUpdate',
['adminPeriodical', 'adminAfterPostSave'] ['adminPeriodical', 'adminAfterPostSave']
); );
$core->addBehavior( dcCore::app()->addBehavior(
'adminAfterPostCreate', 'adminAfterPostCreate',
['adminPeriodical', 'adminAfterPostSave'] ['adminPeriodical', 'adminAfterPostSave']
); );
} }
$core->addBehavior( dcCore::app()->addBehavior(
'adminBeforePostDelete', 'adminBeforePostDelete',
['adminPeriodical', 'adminBeforePostDelete'] ['adminPeriodical', 'adminBeforePostDelete']
); );
@ -106,10 +105,10 @@ class adminPeriodical
]; ];
} }
protected static function period($core) protected static function period()
{ {
if (self::$per === null) { if (self::$per === null) {
self::$per = new periodical($core); self::$per = new periodical();
} }
return self::$per; return self::$per;
} }
@ -117,10 +116,9 @@ class adminPeriodical
/** /**
* Add settings to blog preference * Add settings to blog preference
* *
* @param dcCore $core dcCore instance
* @param dcSettings $blog_settings dcSettings instance * @param dcSettings $blog_settings dcSettings instance
*/ */
public static function adminBlogPreferencesForm(dcCore $core, dcSettings $blog_settings) public static function adminBlogPreferencesForm(dcSettings $blog_settings)
{ {
$s_active = (boolean) $blog_settings->periodical->periodical_active; $s_active = (boolean) $blog_settings->periodical->periodical_active;
$s_upddate = (boolean) $blog_settings->periodical->periodical_upddate; $s_upddate = (boolean) $blog_settings->periodical->periodical_upddate;
@ -162,10 +160,9 @@ class adminPeriodical
/** /**
* User pref for periods columns lists. * User pref for periods columns lists.
* *
* @param dcCore $core dcCore instance
* @param arrayObject $cols Columns * @param arrayObject $cols Columns
*/ */
public static function adminColumnsLists(dcCore $core, $cols) public static function adminColumnsLists($cols)
{ {
$cols['periodical'] = [ $cols['periodical'] = [
__('Periodical'), __('Periodical'),
@ -184,10 +181,9 @@ class adminPeriodical
/** /**
* User pref periods filters options. * User pref periods filters options.
* *
* @param dcCore $core dcCore instance
* @param arrayObject $sorts Sort options * @param arrayObject $sorts Sort options
*/ */
public static function adminFiltersLists(dcCore $core, $sorts) public static function adminFiltersLists($sorts)
{ {
$sorts['periodical'] = [ $sorts['periodical'] = [
__('Periodical'), __('Periodical'),
@ -201,13 +197,12 @@ class adminPeriodical
/** /**
* Add columns period to posts list header. * Add columns period to posts list header.
* *
* @param dcCore $core dcCore instance
* @param record $rs record instance * @param record $rs record instance
* @param arrayObject $cols Columns * @param arrayObject $cols Columns
*/ */
public static function adminPostListHeader(dcCore $core, $rs, $cols) public static function adminPostListHeader($rs, $cols)
{ {
if ($core->blog->settings->periodical->periodical_active) { if (dcCore::app()->blog->settings->periodical->periodical_active) {
$cols['period'] = '<th scope="col">' . __('Period') . '</th>'; $cols['period'] = '<th scope="col">' . __('Period') . '</th>';
} }
} }
@ -215,21 +210,20 @@ class adminPeriodical
/** /**
* Add columns period to posts list values. * Add columns period to posts list values.
* *
* @param dcCore $core dcCore instance
* @param record $rs record instance * @param record $rs record instance
* @param arrayObject $cols Columns * @param arrayObject $cols Columns
*/ */
public static function adminPostListValue(dcCore $core, $rs, $cols) public static function adminPostListValue($rs, $cols)
{ {
if (!$core->blog->settings->periodical->periodical_active) { if (!dcCore::app()->blog->settings->periodical->periodical_active) {
return null; return null;
} }
$r = self::period($core)->getPosts(['post_id' => $rs->post_id]); $r = self::period()->getPosts(['post_id' => $rs->post_id]);
if ($r->isEmpty()) { if ($r->isEmpty()) {
$name = '-'; $name = '-';
} else { } else {
$url = $core->adminurl->get('admin.plugin.periodical', ['part' => 'period', 'period_id' => $r->periodical_id]); $url = dcCore::app()->adminurl->get('admin.plugin.periodical', ['part' => 'period', 'period_id' => $r->periodical_id]);
$name = '<a href="' . $url . '#period" title="' . __('edit period') . '">' . html::escapeHTML($r->periodical_title) . '</a>'; $name = '<a href="' . $url . '#period" title="' . __('edit period') . '">' . html::escapeHTML($r->periodical_title) . '</a>';
} }
$cols['period'] = '<td class="nowrap">' . $name . '</td>'; $cols['period'] = '<td class="nowrap">' . $name . '</td>';
@ -238,19 +232,20 @@ class adminPeriodical
/** /**
* Favorites. * Favorites.
* *
* @param dcCore $core dcCore instance
* @param arrayObject $favs Array of favorites * @param arrayObject $favs Array of favorites
*/ */
public static function adminDashboardFavorites(dcCore $core, $favs) public static function adminDashboardFavorites(dcFavorites $favs)
{ {
$favs->register('periodical', [ $favs->register('periodical', [
'title' => __('Periodical'), 'title' => __('Periodical'),
'url' => 'plugin.php?p=periodical', 'url' => 'plugin.php?p=periodical',
'small-icon' => 'index.php?pf=periodical/icon.png', 'small-icon' => 'index.php?pf=periodical/icon.png',
'large-icon' => 'index.php?pf=periodical/icon-big.png', 'large-icon' => 'index.php?pf=periodical/icon-big.png',
'permissions' => $core->auth->check( 'permissions' => dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([
'usage,contentadmin', dcAuth::PERMISSION_USAGE,
$core->blog->id dcAuth::PERMISSION_CONTENT_ADMIN,
]),
dcCore::app()->blog->id
), ),
'active_cb' => [ 'active_cb' => [
'adminPeriodical', 'adminPeriodical',
@ -289,23 +284,25 @@ class adminPeriodical
*/ */
public static function adminBeforePostDelete($post_id) public static function adminBeforePostDelete($post_id)
{ {
self::delPeriod($GLOBALS['core'], $post_id); self::delPeriod($post_id);
} }
/** /**
* Add actions to posts page combo * Add actions to posts page combo
* *
* @param dcCore $core dcCore instance * @param dcPostsActions $ap dcPostsActions instance
* @param dcPostsActionsPage $ap dcPostsActionsPage instance
*/ */
public static function adminPostsActionsPage(dcCore $core, dcPostsActionsPage $pa) public static function adminPostsActions(dcPostsActions $pa)
{ {
$pa->addAction( $pa->addAction(
[__('Periodical') => [__('Add to periodical') => 'periodical_add']], [__('Periodical') => [__('Add to periodical') => 'periodical_add']],
['adminPeriodical', 'callbackAdd'] ['adminPeriodical', 'callbackAdd']
); );
if (!$core->auth->check('delete,contentadmin', $core->blog->id)) { if (!dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([
dcAuth::PERMISSION_DELETE,
dcAuth::PERMISSION_CONTENT_ADMIN,
]), dcCore::app()->blog->id)) {
return null; return null;
} }
$pa->addAction( $pa->addAction(
@ -317,11 +314,10 @@ class adminPeriodical
/** /**
* Posts actions callback to remove period * Posts actions callback to remove period
* *
* @param dcCore $core dcCore instance * @param dcPostsActions $pa dcPostsActions instance
* @param dcPostsActionsPage $pa dcPostsActionsPage instance
* @param ArrayObject $post _POST actions * @param ArrayObject $post _POST actions
*/ */
public static function callbackRemove(dcCore $core, dcPostsActionsPage $pa, ArrayObject $post) public static function callbackRemove(dcPostsActions $pa, ArrayObject $post)
{ {
# No entry # No entry
$posts_ids = $pa->getIDs(); $posts_ids = $pa->getIDs();
@ -330,13 +326,16 @@ class adminPeriodical
} }
# No right # No right
if (!$core->auth->check('delete,contentadmin', $core->blog->id)) { if (!dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([
dcAuth::PERMISSION_DELETE,
dcAuth::PERMISSION_CONTENT_ADMIN,
]), dcCore::app()->blog->id)) {
throw new Exception(__('No enough right')); throw new Exception(__('No enough right'));
} }
# Remove linked period # Remove linked period
foreach($posts_ids as $post_id) { foreach($posts_ids as $post_id) {
self::delPeriod($core, $post_id); self::delPeriod($post_id);
} }
dcPage::addSuccessNotice(__('Posts have been removed from periodical.')); dcPage::addSuccessNotice(__('Posts have been removed from periodical.'));
@ -346,11 +345,10 @@ class adminPeriodical
/** /**
* Posts actions callback to add period * Posts actions callback to add period
* *
* @param dcCore $core dcCore instance * @param dcPostsActions $pa dcPostsActions instance
* @param dcPostsActionsPage $pa dcPostsActionsPage instance
* @param ArrayObject $post _POST actions * @param ArrayObject $post _POST actions
*/ */
public static function callbackAdd(dcCore $core, dcPostsActionsPage $pa, ArrayObject $post) public static function callbackAdd(dcPostsActions $pa, ArrayObject $post)
{ {
# No entry # No entry
$posts_ids = $pa->getIDs(); $posts_ids = $pa->getIDs();
@ -363,8 +361,8 @@ class adminPeriodical
# Save action # Save action
if (!empty($post['periodical'])) { if (!empty($post['periodical'])) {
foreach($posts_ids as $post_id) { foreach($posts_ids as $post_id) {
self::delPeriod($core, $post_id); self::delPeriod($post_id);
self::addPeriod($core, $post_id, $post['periodical']); self::addPeriod($post_id, $post['periodical']);
} }
dcPage::addSuccessNotice(__('Posts have been added to periodical.')); dcPage::addSuccessNotice(__('Posts have been added to periodical.'));
@ -375,7 +373,7 @@ class adminPeriodical
else { else {
$pa->beginPage( $pa->beginPage(
dcPage::breadcrumb(array( dcPage::breadcrumb(array(
html::escapeHTML($core->blog->name) => '', html::escapeHTML(dcCore::app()->blog->name) => '',
$pa->getCallerTitle() => $pa->getRedirection(true), $pa->getCallerTitle() => $pa->getRedirection(true),
__('Add a period to this selection') => '' __('Add a period to this selection') => ''
)) ))
@ -385,10 +383,10 @@ class adminPeriodical
'<form action="' . $pa->getURI() . '" method="post">' . '<form action="' . $pa->getURI() . '" method="post">' .
$pa->getCheckboxes() . $pa->getCheckboxes() .
self::formPeriod($core) . self::formPeriod() .
'<p>'. '<p>'.
$core->formNonce() . dcCore::app()->formNonce() .
$pa->getHiddenFields() . $pa->getHiddenFields() .
form::hidden(['action'], 'periodical_add') . form::hidden(['action'], 'periodical_add') .
'<input type="submit" value="' . __('Save') . '" /></p>' . '<input type="submit" value="' . __('Save') . '" /></p>' .
@ -407,18 +405,16 @@ class adminPeriodical
*/ */
public static function adminPostFormItems(ArrayObject $main_items, ArrayObject $sidebar_items, $post) public static function adminPostFormItems(ArrayObject $main_items, ArrayObject $sidebar_items, $post)
{ {
global $core;
# Get existing linked period # Get existing linked period
$period = ''; $period = '';
if ($post) { if ($post) {
$rs = self::period($core)->getPosts(['post_id' => $post->post_id]); $rs = self::period()->getPosts(['post_id' => $post->post_id]);
$period = $rs->isEmpty() ? '' : $rs->periodical_id; $period = $rs->isEmpty() ? '' : $rs->periodical_id;
} }
# Set linked period form items # Set linked period form items
$sidebar_items['options-box']['items']['period'] = $sidebar_items['options-box']['items']['period'] =
self::formPeriod($core, $period); self::formPeriod($period);
} }
/** /**
@ -429,29 +425,26 @@ class adminPeriodical
*/ */
public static function adminAfterPostSave(cursor $cur, $post_id) public static function adminAfterPostSave(cursor $cur, $post_id)
{ {
global $core;
if (!isset($_POST['periodical'])) { if (!isset($_POST['periodical'])) {
return null; return null;
} }
# Delete old linked period # Delete old linked period
self::delPeriod($core, $post_id); self::delPeriod($post_id);
# Add new linked period # Add new linked period
self::addPeriod($core, $post_id, $_POST['periodical']); self::addPeriod($post_id, $_POST['periodical']);
} }
/** /**
* Posts period form field * Posts period form field
* *
* @param dcCore $core dcCore instance
* @param string $period Period * @param string $period Period
* @return string Period form content * @return string Period form content
*/ */
protected static function formPeriod(dcCore $core, $period='') protected static function formPeriod($period='')
{ {
$combo = self::comboPeriod($core); $combo = self::comboPeriod();
if (empty($combo)) { if (empty($combo)) {
return null; return null;
@ -467,13 +460,12 @@ class adminPeriodical
/** /**
* Combo of available periods * Combo of available periods
* *
* @param dcCore $core dcCore instance
* @return array List of period * @return array List of period
*/ */
protected static function comboPeriod(dcCore $core) protected static function comboPeriod()
{ {
if (adminPeriodical::$combo_period === null) { if (adminPeriodical::$combo_period === null) {
$periods = self::period($core)->getPeriods(); $periods = self::period()->getPeriods();
if ($periods->isEmpty()) { if ($periods->isEmpty()) {
adminPeriodical::$combo_period = []; adminPeriodical::$combo_period = [];
@ -492,27 +484,25 @@ class adminPeriodical
/** /**
* Remove period from posts. * Remove period from posts.
* *
* @param dcCore $core dcCore instance
* @param integer $post_id Post id * @param integer $post_id Post id
*/ */
protected static function delPeriod(dcCore $core, $post_id) protected static function delPeriod($post_id)
{ {
if ($post_id === null) { if ($post_id === null) {
return null; return null;
} }
$post_id = (integer) $post_id; $post_id = (integer) $post_id;
self::period($core)->delPost($post_id); self::period()->delPost($post_id);
} }
/** /**
* Add period to posts * Add period to posts
* *
* @param dcCore $core dcCore instance
* @param integer $post_id Post id * @param integer $post_id Post id
* @param array $period Period * @param array $period Period
*/ */
protected static function addPeriod($core, $post_id, $period) protected static function addPeriod($post_id, $period)
{ {
# Not saved # Not saved
if ($post_id === null || empty($period)) { if ($post_id === null || empty($period)) {
@ -520,7 +510,7 @@ class adminPeriodical
} }
# Get periods # Get periods
$period = self::period($core)->getPeriods(['periodical_id' => $period]); $period = self::period()->getPeriods(['periodical_id' => $period]);
# No period # No period
if ($period->isEmpty()) { if ($period->isEmpty()) {
@ -530,6 +520,6 @@ class adminPeriodical
$post_id = (integer) $post_id; $post_id = (integer) $post_id;
# Add relation # Add relation
self::period($core)->addPost($period->periodical_id, $post_id); self::period()->addPost($period->periodical_id, $post_id);
} }
} }

View File

@ -19,10 +19,14 @@ $this->registerModule(
'Periodical', 'Periodical',
'Published periodically entries', 'Published periodically entries',
'Jean-Christian Denis and contributors', 'Jean-Christian Denis and contributors',
'2022.05.16', '2022.11.12',
[ [
'requires' => [['core', '2.22']], 'requires' => [['core', '2.24']],
'permissions' => 'usage,contentadmin', 'permissions' => dcCore::app()->auth->makePermissions([
dcAuth::PERMISSION_USAGE,
dcAuth::PERMISSION_CONTENT_ADMIN,
]),
'usage,contentadmin',
'type' => 'plugin', 'type' => 'plugin',
'support' => 'https://github.com/JcDenis/periodical', 'support' => 'https://github.com/JcDenis/periodical',
'details' => 'https://plugins.dotaddict.org/dc2/details/periodical', 'details' => 'https://plugins.dotaddict.org/dc2/details/periodical',

View File

@ -15,9 +15,9 @@ if (!defined('DC_CONTEXT_ADMIN')) {
return null; return null;
} }
$dc_min = '2.22'; $dc_min = '2.24';
$new_version = $core->plugins->moduleInfo('periodical', 'version'); $new_version = dcCore::app()->plugins->moduleInfo('periodical', 'version');
$old_version = $core->getVersion('periodical'); $old_version = dcCore::app()->getVersion('periodical');
if (version_compare($old_version, $new_version, '>=')) { if (version_compare($old_version, $new_version, '>=')) {
return null; return null;
@ -34,7 +34,7 @@ try {
} }
# Tables # Tables
$t = new dbStruct($core->con,$core->prefix); $t = new dbStruct(dcCore::app()->con,dcCore::app()->prefix);
# Table principale des sondages # Table principale des sondages
$t->periodical $t->periodical
@ -51,23 +51,23 @@ try {
->primary('pk_periodical', 'periodical_id') ->primary('pk_periodical', 'periodical_id')
->index('idx_periodical_type', 'btree', 'periodical_type'); ->index('idx_periodical_type', 'btree', 'periodical_type');
$ti = new dbStruct($core->con, $core->prefix); $ti = new dbStruct(dcCore::app()->con, dcCore::app()->prefix);
$changes = $ti->synchronize($t); $changes = $ti->synchronize($t);
# Settings # Settings
$core->blog->settings->addNamespace('periodical'); dcCore::app()->blog->settings->addNamespace('periodical');
$s = $core->blog->settings->periodical; $s = dcCore::app()->blog->settings->periodical;
$s->put('periodical_active', false, 'boolean', 'Enable extension', false, true); $s->put('periodical_active', false, 'boolean', 'Enable extension', false, true);
$s->put('periodical_upddate', true, 'boolean', 'Update post date', false, true); $s->put('periodical_upddate', true, 'boolean', 'Update post date', false, true);
$s->put('periodical_updurl', false, 'boolean', 'Update post url', false, true); $s->put('periodical_updurl', false, 'boolean', 'Update post url', false, true);
$s->put('periodical_pub_order', 'post_dt asc', 'string', 'Order of publication', false, true); $s->put('periodical_pub_order', 'post_dt asc', 'string', 'Order of publication', false, true);
# Version # Version
$core->setVersion('periodical', $new_version); dcCore::app()->setVersion('periodical', $new_version);
return true; return true;
} catch (Exception $e) { } catch (Exception $e) {
$core->error->add($e->getMessage()); dcCore::app()->error->add($e->getMessage());
} }
return false; return false;

View File

@ -15,9 +15,7 @@ if (!defined('DC_RC_PATH')) {
return null; return null;
} }
$d = dirname(__FILE__) . '/inc/';
# DB class # DB class
$__autoload['periodical'] = $d . 'class.periodical.php'; Clearbricks::lib()->autoload(['periodical' => __DIR__ . '/inc/class.periodical.php']);
# Admin list and pagers # Admin list and pagers
$__autoload['adminPeriodicalList'] = $d . 'lib.index.pager.php'; Clearbricks::lib()->autoload(['adminPeriodicalList' => __DIR__ . '/inc/lib.index.pager.php']);

View File

@ -15,14 +15,14 @@ if (!defined('DC_RC_PATH')) {
return null; return null;
} }
if (!in_array($core->url->type, ['default', 'feed'])) { if (!in_array(dcCore::app()->url->type, ['default', 'feed'])) {
return null; return null;
} }
$core->blog->settings->addNamespace('periodical'); dcCore::app()->blog->settings->addNamespace('periodical');
$core->addBehavior( dcCore::app()->addBehavior(
'publicBeforeDocument', 'publicBeforeDocumentV2',
['publicPeriodical', 'publicBeforeDocument'] ['publicPeriodical', 'publicBeforeDocument']
); );
@ -36,18 +36,17 @@ class publicPeriodical
/** /**
* Publish periodical * Publish periodical
* *
* @param dcCore $core dcCore instance
*/ */
public static function publicBeforeDocument(dcCore $core) public static function publicBeforeDocument()
{ {
try { try {
$per = new periodical($core); $per = new periodical();
$s = $core->blog->settings->periodical; $s = dcCore::app()->blog->settings->periodical;
$per->lockUpdate(); $per->lockUpdate();
# Get periods # Get periods
$periods = $core->auth->sudo([$per, 'getPeriods']); $periods = dcCore::app()->auth->sudo([$per, 'getPeriods']);
# No period # No period
if ($periods->isEmpty()) { if ($periods->isEmpty()) {
@ -61,7 +60,7 @@ class publicPeriodical
if (!preg_match('/^(post_dt|post_creadt|post_id) (asc|desc)$/', $posts_order)) { if (!preg_match('/^(post_dt|post_creadt|post_id) (asc|desc)$/', $posts_order)) {
$posts_order = 'post_dt asc'; $posts_order = 'post_dt asc';
} }
$cur_period = $core->con->openCursor($core->prefix . 'periodical'); $cur_period = dcCore::app()->con->openCursor(dcCore::app()->prefix . 'periodical');
while($periods->fetch()) { while($periods->fetch()) {
# Check if period is ongoing # Check if period is ongoing
@ -99,10 +98,10 @@ class publicPeriodical
$posts_params['order'] = $posts_order; $posts_params['order'] = $posts_order;
$posts_params['limit'] = $limit * $max_nb; $posts_params['limit'] = $limit * $max_nb;
$posts_params['no_content'] = true; $posts_params['no_content'] = true;
$posts = $core->auth->sudo([$per, 'getPosts'], $posts_params); $posts = dcCore::app()->auth->sudo([$per, 'getPosts'], $posts_params);
if (!$posts->isEmpty()) { if (!$posts->isEmpty()) {
$cur_post = $core->con->openCursor($core->prefix . 'post'); $cur_post = dcCore::app()->con->openCursor(dcCore::app()->prefix . 'post');
while($posts->fetch()) { while($posts->fetch()) {
# Publish post with right date # Publish post with right date
@ -119,12 +118,12 @@ class publicPeriodical
# Also update post url with right date # Also update post url with right date
if ($s->periodical_updurl) { if ($s->periodical_updurl) {
$cur_post->post_url = $core->blog->getPostURL('', $cur_post->post_dt, $posts->post_title, $posts->post_id); $cur_post->post_url = dcCore::app()->blog->getPostURL('', $cur_post->post_dt, $posts->post_title, $posts->post_id);
} }
$cur_post->update( $cur_post->update(
'WHERE post_id = ' . $posts->post_id . ' ' . 'WHERE post_id = ' . $posts->post_id . ' ' .
"AND blog_id = '" . $core->con->escape($core->blog->id) . "' " "AND blog_id = '" . dcCore::app()->con->escape(dcCore::app()->blog->id) . "' "
); );
# Delete post relation to this period # Delete post relation to this period
@ -139,10 +138,10 @@ class publicPeriodical
} }
# --BEHAVIOR-- periodicalAfterPublishedPeriodicalEntry # --BEHAVIOR-- periodicalAfterPublishedPeriodicalEntry
$core->callBehavior('periodicalAfterPublishedPeriodicalEntry', $core, $posts, $periods); dcCore::app()->callBehavior('periodicalAfterPublishedPeriodicalEntry', $posts, $periods);
} }
$core->blog->triggerBlog(); dcCore::app()->blog->triggerBlog();
} }
} }
@ -151,7 +150,7 @@ class publicPeriodical
$cur_period->periodical_curdt = date('Y-m-d H:i:s', $loop_tz); $cur_period->periodical_curdt = date('Y-m-d H:i:s', $loop_tz);
$cur_period->update( $cur_period->update(
'WHERE periodical_id = ' . $periods->periodical_id . ' ' . 'WHERE periodical_id = ' . $periods->periodical_id . ' ' .
"AND blog_id = '" . $core->con->escape($core->blog->id) . "' " "AND blog_id = '" . dcCore::app()->con->escape(dcCore::app()->blog->id) . "' "
); );
} }
} }

View File

@ -17,20 +17,18 @@ if (!defined('DC_RC_PATH')){
class periodical class periodical
{ {
public $core;
public $con; public $con;
protected $table; protected $table;
protected $blog; protected $blog;
private $lock = null; private $lock = null;
public function __construct($core) public function __construct()
{ {
$this->core = $core; $this->con = dcCore::app()->con;
$this->con = $core->con;
$this->table = $core->con->escape($core->prefix . 'periodical'); $this->table = dcCore::app()->con->escape(dcCore::app()->prefix . 'periodical');
$this->blog = $core->con->escape($core->blog->id); $this->blog = dcCore::app()->con->escape(dcCore::app()->blog->id);
} }
public function openCursor() public function openCursor()
@ -96,8 +94,8 @@ class periodical
$q .= $this->con->limit($params['limit']); $q .= $this->con->limit($params['limit']);
} }
$rs = $this->con->select($q); $rs = $this->con->select($q);
$rs->core = $this->core; //$rs->core = dcCore::app();
$rs->periodical = $this; //$rs->periodical = $this;
return $rs; return $rs;
} }
@ -114,7 +112,7 @@ class periodical
$cur->periodical_id = $id; $cur->periodical_id = $id;
$cur->blog_id = $this->blog; $cur->blog_id = $this->blog;
$cur->periodical_type = 'post'; $cur->periodical_type = 'post';
$cur->periodical_tz = $this->core->auth->getInfo('user_tz'); $cur->periodical_tz = dcCore::app()->auth->getInfo('user_tz');
$cur->insert(); $cur->insert();
$this->con->unlock(); $this->con->unlock();
} catch (Exception $e) { } catch (Exception $e) {
@ -130,7 +128,7 @@ class periodical
if ($cur->periodical_tz == '' if ($cur->periodical_tz == ''
&& ($cur->periodical_curdt != '' || $cur->periodical_enddt != '')) { && ($cur->periodical_curdt != '' || $cur->periodical_enddt != '')) {
$cur->periodical_tz = $this->core->auth->getInfo('user_tz'); $cur->periodical_tz = dcCore::app()->auth->getInfo('user_tz');
} }
$cur->update( $cur->update(
"WHERE blog_id = '" . $this->blog . "' " . "WHERE blog_id = '" . $this->blog . "' " .
@ -183,7 +181,7 @@ class periodical
} }
$this->con->execute( $this->con->execute(
'DELETE FROM ' . $this->core->prefix . 'meta ' . 'DELETE FROM ' . dcCore::app()->prefix . 'meta ' .
"WHERE meta_type = 'periodical' " . "WHERE meta_type = 'periodical' " .
"AND post_id " . $this->con->in($ids) "AND post_id " . $this->con->in($ids)
); );
@ -214,7 +212,7 @@ class periodical
$params['columns'][] = 'T.periodical_pub_int'; $params['columns'][] = 'T.periodical_pub_int';
$params['columns'][] = 'T.periodical_pub_nb'; $params['columns'][] = 'T.periodical_pub_nb';
$params['join'] .= 'LEFT JOIN ' . $this->core->prefix . 'meta R ON P.post_id = R.post_id '; $params['join'] .= 'LEFT JOIN ' . dcCore::app()->prefix . 'meta R ON P.post_id = R.post_id ';
$params['join'] .= 'LEFT JOIN ' . $this->table . ' T ON CAST(T.periodical_id as char) = CAST(R.meta_id as char) '; $params['join'] .= 'LEFT JOIN ' . $this->table . ' T ON CAST(T.periodical_id as char) = CAST(R.meta_id as char) ';
$params['sql'] .= "AND R.meta_type = 'periodical' "; $params['sql'] .= "AND R.meta_type = 'periodical' ";
@ -229,7 +227,7 @@ class periodical
$params['sql'] .= 'AND T.periodical_id ' . $this->con->in($params['periodical_id']); $params['sql'] .= 'AND T.periodical_id ' . $this->con->in($params['periodical_id']);
unset($params['periodical_id']); unset($params['periodical_id']);
} }
if ($this->core->auth->check('admin', $this->core->blog->id)) { if (dcCore::app()->auth->check('admin', dcCore::app()->blog->id)) {
if (isset($params['post_status'])) { if (isset($params['post_status'])) {
if ($params['post_status'] != '') { if ($params['post_status'] != '') {
$params['sql'] .= 'AND P.post_status = ' . (integer) $params['post_status'] . ' '; $params['sql'] .= 'AND P.post_status = ' . (integer) $params['post_status'] . ' ';
@ -240,7 +238,7 @@ class periodical
$params['sql'] .= 'AND P.post_status = -2 '; $params['sql'] .= 'AND P.post_status = -2 ';
} }
$rs = $this->core->blog->getPosts($params, $count_only); $rs = dcCore::app()->blog->getPosts($params, $count_only);
$rs->periodical = $this; $rs->periodical = $this;
return $rs; return $rs;
@ -258,8 +256,8 @@ class periodical
return; return;
} }
$cur = $this->con->openCursor($this->core->prefix .'meta'); $cur = $this->con->openCursor(dcCore::app()->prefix .'meta');
$this->con->writeLock($this->core->prefix . 'meta'); $this->con->writeLock(dcCore::app()->prefix . 'meta');
try { try {
$cur->post_id = $post_id; $cur->post_id = $post_id;
@ -279,7 +277,7 @@ class periodical
$post_id = (integer) $post_id; $post_id = (integer) $post_id;
$this->con->execute( $this->con->execute(
'DELETE FROM ' . $this->core->prefix . 'meta ' . 'DELETE FROM ' . dcCore::app()->prefix . 'meta ' .
"WHERE meta_type = 'periodical' " . "WHERE meta_type = 'periodical' " .
"AND post_id = '" . $post_id . "' " "AND post_id = '" . $post_id . "' "
); );
@ -311,7 +309,7 @@ class periodical
} }
$this->con->execute( $this->con->execute(
'DELETE FROM ' . $this->core->prefix . 'meta ' . 'DELETE FROM ' . dcCore::app()->prefix . 'meta ' .
"WHERE meta_type = 'periodical' " . "WHERE meta_type = 'periodical' " .
"AND post_id " . $this->con->in($ids) "AND post_id " . $this->con->in($ids)
); );

View File

@ -15,10 +15,10 @@ if (!defined('DC_CONTEXT_ADMIN')) {
return null; return null;
} }
dcPage::check('usage,contentadmin'); dcPage::check(dcCore::app()->auth->makePermissions([dcAuth::PERMISSION_USAGE, dcAuth::PERMISSION_CONTENT_ADMIN]));
# Objects # Objects
$per = new periodical($core); $per = new periodical();
# Default values # Default values
$action = isset($_POST['action']) ? $_POST['action'] : ''; $action = isset($_POST['action']) ? $_POST['action'] : '';
@ -41,7 +41,7 @@ if (!empty($_REQUEST['period_id'])) {
'periodical_id' => $_REQUEST['period_id'] 'periodical_id' => $_REQUEST['period_id']
]); ]);
if ($rs->isEmpty()) { if ($rs->isEmpty()) {
$core->error->add(__('This period does not exist.')); dcCore::app()->error->add(__('This period does not exist.'));
$period_id = null; $period_id = null;
} else { } else {
$period_id = $rs->periodical_id; $period_id = $rs->periodical_id;
@ -77,7 +77,7 @@ if ($action == 'setperiod') {
} }
$period_curdt = date('Y-m-d H:i', $period_curdt); $period_curdt = date('Y-m-d H:i', $period_curdt);
} catch (Exception $e) { } catch (Exception $e) {
$core->error->add($e->getMessage()); dcCore::app()->error->add($e->getMessage());
} }
} }
if (!empty($_POST['period_enddt'])) { if (!empty($_POST['period_enddt'])) {
@ -90,7 +90,7 @@ if ($action == 'setperiod') {
} }
$period_enddt = date('Y-m-d H:i', $period_enddt); $period_enddt = date('Y-m-d H:i', $period_enddt);
} catch (Exception $e) { } catch (Exception $e) {
$core->error->add($e->getMessage()); dcCore::app()->error->add($e->getMessage());
} }
} }
@ -101,19 +101,19 @@ if ($action == 'setperiod') {
if (!$old_titles->isEmpty()) { if (!$old_titles->isEmpty()) {
while($old_titles->fetch()) { while($old_titles->fetch()) {
if (!$period_id || $old_titles->periodical_id != $period_id) { if (!$period_id || $old_titles->periodical_id != $period_id) {
$core->error->add(__('Period title is already taken')); dcCore::app()->error->add(__('Period title is already taken'));
} }
} }
} }
if (empty($period_title)) { if (empty($period_title)) {
$core->error->add(__('Period title is required')); dcCore::app()->error->add(__('Period title is required'));
} }
if (strtotime($period_curdt) > strtotime($period_enddt)) { if (strtotime($period_curdt) > strtotime($period_enddt)) {
$core->error->add(__('Start date must be older than end date')); dcCore::app()->error->add(__('Start date must be older than end date'));
} }
# If no error, set period # If no error, set period
if (!$core->error->flag()) { if (!dcCore::app()->error->flag()) {
$cur = $per->openCursor(); $cur = $per->openCursor();
$cur->periodical_title = $period_title; $cur->periodical_title = $period_title;
$cur->periodical_curdt = $period_curdt; $cur->periodical_curdt = $period_curdt;
@ -125,14 +125,14 @@ if ($action == 'setperiod') {
if ($period_id) { if ($period_id) {
$per->updPeriod($period_id, $cur); $per->updPeriod($period_id, $cur);
dcPage::addSuccessNotice( dcAdminNotices::addSuccessNotice(
__('Period successfully updated.') __('Period successfully updated.')
); );
# Create period # Create period
} else { } else {
$period_id = $per->addPeriod($cur); $period_id = $per->addPeriod($cur);
dcPage::addSuccessNotice( dcAdminNotices::addSuccessNotice(
__('Period successfully created.') __('Period successfully created.')
); );
} }
@ -140,33 +140,33 @@ if ($action == 'setperiod') {
if (!empty($_POST['redir'])) { if (!empty($_POST['redir'])) {
http::redirect($_POST['redir']); http::redirect($_POST['redir']);
} else { } else {
$core->adminurl->redirect('admin.plugin.periodical', ['part' => 'period', 'period_id' => $period_id], '#period'); dcCore::app()->adminurl->redirect('admin.plugin.periodical', ['part' => 'period', 'period_id' => $period_id], '#period');
} }
} }
} }
# Actions on related posts # Actions on related posts
if (!$core->error->flag() && $period_id && $action && !empty($_POST['periodical_entries'])) { if (!dcCore::app()->error->flag() && $period_id && $action && !empty($_POST['periodical_entries'])) {
# Publish posts # Publish posts
if ($action == 'publish') { if ($action == 'publish') {
try { try {
foreach($_POST['periodical_entries'] as $id) { foreach($_POST['periodical_entries'] as $id) {
$id = (integer) $id; $id = (integer) $id;
$core->blog->updPostStatus($id, 1); dcCore::app()->blog->updPostStatus($id, 1);
$per->delPost($id); $per->delPost($id);
} }
dcPage::addSuccessNotice( dcAdminNotices::addSuccessNotice(
__('Entries successfully published.') __('Entries successfully published.')
); );
if (!empty($_POST['redir'])) { if (!empty($_POST['redir'])) {
http::redirect($_POST['redir']); http::redirect($_POST['redir']);
} else { } else {
$core->adminurl->redirect('admin.plugin.periodical', ['part' => 'period', 'period_id' => $period_id], '#posts'); dcCore::app()->adminurl->redirect('admin.plugin.periodical', ['part' => 'period', 'period_id' => $period_id], '#posts');
} }
} catch (Exception $e) { } catch (Exception $e) {
$core->error->add($e->getMessage()); dcCore::app()->error->add($e->getMessage());
} }
} }
@ -175,21 +175,21 @@ if (!$core->error->flag() && $period_id && $action && !empty($_POST['periodical_
try { try {
foreach($_POST['periodical_entries'] as $id) { foreach($_POST['periodical_entries'] as $id) {
$id = (integer) $id; $id = (integer) $id;
$core->blog->updPostStatus($id,0); dcCore::app()->blog->updPostStatus($id,0);
$per->delPost($id); $per->delPost($id);
} }
dcPage::addSuccessNotice( dcAdminNotices::addSuccessNotice(
__('Entries successfully unpublished.') __('Entries successfully unpublished.')
); );
if (!empty($_POST['redir'])) { if (!empty($_POST['redir'])) {
http::redirect($_POST['redir']); http::redirect($_POST['redir']);
} else { } else {
$core->adminurl->redirect('admin.plugin.periodical', ['part' => 'period', 'period_id' => $period_id], '#posts'); dcCore::app()->adminurl->redirect('admin.plugin.periodical', ['part' => 'period', 'period_id' => $period_id], '#posts');
} }
} catch (Exception $e) { } catch (Exception $e) {
$core->error->add($e->getMessage()); dcCore::app()->error->add($e->getMessage());
} }
} }
@ -201,17 +201,17 @@ if (!$core->error->flag() && $period_id && $action && !empty($_POST['periodical_
$per->delPost($id); $per->delPost($id);
} }
dcPage::addSuccessNotice( dcAdminNotices::addSuccessNotice(
__('Entries successfully removed.') __('Entries successfully removed.')
); );
if (!empty($_POST['redir'])) { if (!empty($_POST['redir'])) {
http::redirect($_POST['redir']); http::redirect($_POST['redir']);
} else { } else {
$core->adminurl->redirect('admin.plugin.periodical', ['part' => 'period', 'period_id' => $period_id], '#posts'); dcCore::app()->adminurl->redirect('admin.plugin.periodical', ['part' => 'period', 'period_id' => $period_id], '#posts');
} }
} catch (Exception $e) { } catch (Exception $e) {
$core->error->add($e->getMessage()); dcCore::app()->error->add($e->getMessage());
} }
} }
} }
@ -219,7 +219,7 @@ if (!$core->error->flag() && $period_id && $action && !empty($_POST['periodical_
# Prepare combos for posts list # Prepare combos for posts list
if ($period_id) { if ($period_id) {
# Filters # Filters
$post_filter = new adminPostFilter($core); $post_filter = new adminPostFilter();
$post_filter->add('part', 'period'); $post_filter->add('part', 'period');
$params = $post_filter->params(); $params = $post_filter->params();
@ -230,14 +230,14 @@ if ($period_id) {
try { try {
$posts = $per->getPosts($params); $posts = $per->getPosts($params);
$counter = $per->getPosts($params, true); $counter = $per->getPosts($params, true);
$post_list = new adminPeriodicalList($core, $posts, $counter->f(0)); $post_list = new adminPeriodicalList(dcCore::app(), $posts, $counter->f(0));
} catch (Exception $e) { } catch (Exception $e) {
$core->error->add($e->getMessage()); dcCore::app()->error->add($e->getMessage());
} }
$starting_script = $starting_script =
dcPage::jsLoad(dcPage::getPF('periodical/js/checkbox.js')) . dcPage::jsLoad(dcPage::getPF('periodical/js/checkbox.js')) .
$post_filter->js($core->adminurl->get('admin.plugin.periodical', ['part' => 'period', 'period_id' => $period_id], '&').'#posts'); $post_filter->js(dcCore::app()->adminurl->get('admin.plugin.periodical', ['part' => 'period', 'period_id' => $period_id], '&').'#posts');
} }
# Display # Display
@ -253,7 +253,7 @@ dcPage::jsPageTabs() .
echo echo
dcPage::breadcrumb([ dcPage::breadcrumb([
__('Plugins') => '', __('Plugins') => '',
__('Periodical') => $p_url . '&amp;part=periods', __('Periodical') => dcCore::app()->admin->getPageURL() . '&amp;part=periods',
(null === $period_id ? __('New period') : __('Edit period')) => '' (null === $period_id ? __('New period') : __('Edit period')) => ''
]) . ]) .
dcPage::notices(); dcPage::notices();
@ -261,7 +261,7 @@ dcPage::notices();
# Period form # Period form
echo ' echo '
<div id="period"><h3>' . (null === $period_id ? __('New period') : __('Edit period')) . '</h3> <div id="period"><h3>' . (null === $period_id ? __('New period') : __('Edit period')) . '</h3>
<form method="post" action="' . $p_url . '"> <form method="post" action="' . dcCore::app()->admin->getPageURL() . '">
<p><label for="period_title">' . __('Title:') . '</label>' . <p><label for="period_title">' . __('Title:') . '</label>' .
form::field('period_title', 60, 255, html::escapeHTML($period_title), 'maximal') . '</p> form::field('period_title', 60, 255, html::escapeHTML($period_title), 'maximal') . '</p>
@ -292,7 +292,7 @@ form::number('period_pub_nb', ['min' => 1, 'max' => 20, 'default' => $period_pub
<div class="clear"> <div class="clear">
<p><input type="submit" name="save" value="' . __('Save') . '" />' . <p><input type="submit" name="save" value="' . __('Save') . '" />' .
$core->formNonce() . dcCore::app()->formNonce() .
form::hidden(['action'], 'setperiod') . form::hidden(['action'], 'setperiod') .
form::hidden(['period_id'], $period_id) . form::hidden(['period_id'], $period_id) .
form::hidden(['part'], 'period') .' form::hidden(['part'], 'period') .'
@ -301,7 +301,7 @@ form::hidden(['part'], 'period') .'
</form> </form>
</div>'; </div>';
if ($period_id && !$core->error->flag()) { if ($period_id && !dcCore::app()->error->flag()) {
# Actions combo box # Actions combo box
$combo_action = []; $combo_action = [];
@ -309,7 +309,7 @@ if ($period_id && !$core->error->flag()) {
$combo_action[__('Entries')][__('Unpublish')] = 'unpublish'; $combo_action[__('Entries')][__('Unpublish')] = 'unpublish';
$combo_action[__('Periodical')][__('Remove from periodical')] = 'remove_post_periodical'; $combo_action[__('Periodical')][__('Remove from periodical')] = 'remove_post_periodical';
$base_url = $p_url . $base_url = dcCore::app()->admin->getPageURL() .
'&amp;period_id=' .$period_id . '&amp;period_id=' .$period_id .
'&amp;part=period' . '&amp;part=period' .
'&amp;user_id=' . $post_filter->user_id . '&amp;user_id=' . $post_filter->user_id .
@ -330,7 +330,7 @@ if ($period_id && !$core->error->flag()) {
# Filters # Filters
$post_filter->display(['admin.plugin.periodical', '#posts'], $post_filter->display(['admin.plugin.periodical', '#posts'],
$core->adminurl->getHiddenFormFields('admin.plugin.periodical', [ dcCore::app()->adminurl->getHiddenFormFields('admin.plugin.periodical', [
'period_id' => $period_id, 'period_id' => $period_id,
'part' => 'period' 'part' => 'period'
]) ])
@ -338,7 +338,7 @@ if ($period_id && !$core->error->flag()) {
# Posts list # Posts list
$post_list->postDisplay($post_filter, $base_url, $post_list->postDisplay($post_filter, $base_url,
'<form action="' . $p_url . '" method="post" id="form-entries">' . '<form action="' . dcCore::app()->admin->getPageURL() . '" method="post" id="form-entries">' .
'%s' . '%s' .
@ -348,11 +348,11 @@ if ($period_id && !$core->error->flag()) {
'<p class="col right">' . __('Selected entries action:') . ' ' . '<p class="col right">' . __('Selected entries action:') . ' ' .
form::combo('action', $combo_action) . form::combo('action', $combo_action) .
'<input type="submit" value="' . __('ok') . '" /></p>' . '<input type="submit" value="' . __('ok') . '" /></p>' .
$core->adminurl->getHiddenFormFields('admin.plugin.periodical', array_merge($post_filter->values(), [ dcCore::app()->adminurl->getHiddenFormFields('admin.plugin.periodical', array_merge($post_filter->values(), [
'period_id' => $period_id, 'period_id' => $period_id,
'redir' => sprintf($base_url, $post_filter->page) 'redir' => sprintf($base_url, $post_filter->page)
])) . ])) .
$core->formNonce() . dcCore::app()->formNonce() .
'</div>' . '</div>' .
'</form>' '</form>'
); );

View File

@ -15,10 +15,10 @@ if (!defined('DC_CONTEXT_ADMIN')) {
return null; return null;
} }
dcPage::check('usage,contentadmin'); dcPage::check(dcCore::app()->auth->makePermissions([dcAuth::PERMISSION_USAGE, dcAuth::PERMISSION_CONTENT_ADMIN]));
# Objects # Objects
$per = new periodical($core); $per = new periodical();
# Default values # Default values
$action = isset($_POST['action']) ? $_POST['action'] : ''; $action = isset($_POST['action']) ? $_POST['action'] : '';
@ -32,17 +32,17 @@ if ($action == 'deleteperiods' && !empty($_POST['periods'])) {
$per->delPeriod($id); $per->delPeriod($id);
} }
dcPage::addSuccessNotice( dcAdminNotices::addSuccessNotice(
__('Periods removed.') __('Periods removed.')
); );
if (!empty($_POST['redir'])) { if (!empty($_POST['redir'])) {
http::redirect($_POST['redir']); http::redirect($_POST['redir']);
} else { } else {
$core->adminurl->redirect('admin.plugin.periodical', ['part' => 'periods']); dcCore::app()->adminurl->redirect('admin.plugin.periodical', ['part' => 'periods']);
} }
} catch (Exception $e) { } catch (Exception $e) {
$core->error->add($e->getMessage()); dcCore::app()->error->add($e->getMessage());
} }
} }
# Delete periods related posts links (without delete periods) # Delete periods related posts links (without delete periods)
@ -53,17 +53,17 @@ if ($action == 'emptyperiods' && !empty($_POST['periods'])) {
$per->delPeriodPosts($id); $per->delPeriodPosts($id);
} }
dcPage::addSuccessNotice( dcAdminNotices::addSuccessNotice(
__('Periods emptied.') __('Periods emptied.')
); );
if (!empty($_POST['redir'])) { if (!empty($_POST['redir'])) {
http::redirect($_POST['redir']); http::redirect($_POST['redir']);
} else { } else {
$core->adminurl->redirect('admin.plugin.periodical', ['part' => 'periods']); dcCore::app()->adminurl->redirect('admin.plugin.periodical', ['part' => 'periods']);
} }
} catch (Exception $e) { } catch (Exception $e) {
$core->error->add($e->getMessage()); dcCore::app()->error->add($e->getMessage());
} }
} }
@ -73,7 +73,7 @@ $combo_action = [
]; ];
# Filters # Filters
$p_filter = new adminGenericFilter($core, 'periodical'); $p_filter = new adminGenericFilter(dcCore::app(), 'periodical');
$p_filter->add('part', 'periods'); $p_filter->add('part', 'periods');
$params = $p_filter->params(); $params = $p_filter->params();
@ -82,16 +82,16 @@ $params = $p_filter->params();
try { try {
$periods = $per->getPeriods($params); $periods = $per->getPeriods($params);
$counter = $per->getPeriods($params, true); $counter = $per->getPeriods($params, true);
$period_list = new adminPeriodicalList($core, $periods, $counter->f(0)); $period_list = new adminPeriodicalList(dcCore::app(), $periods, $counter->f(0));
} catch (Exception $e) { } catch (Exception $e) {
$core->error->add($e->getMessage()); dcCore::app()->error->add($e->getMessage());
} }
# Display # Display
echo echo
'<html><head><title>' . __('Periodical') . '</title>' . '<html><head><title>' . __('Periodical') . '</title>' .
dcPage::jsLoad(dcPage::getPF('periodical/js/checkbox.js')) . dcPage::jsLoad(dcPage::getPF('periodical/js/checkbox.js')) .
$p_filter->js($core->adminurl->get('admin.plugin.periodical', ['part' => 'periods'])) . $p_filter->js(dcCore::app()->adminurl->get('admin.plugin.periodical', ['part' => 'periods'])) .
'</head>' . '</head>' .
'<body>' . '<body>' .
@ -102,7 +102,7 @@ dcPage::breadcrumb([
dcPage::notices() . dcPage::notices() .
'<p class="top-add"> '<p class="top-add">
<a class="button add" href="' . $p_url . '&amp;part=period">' . __('New period') . '</a> <a class="button add" href="' . dcCore::app()->admin->getPageURL() . '&amp;part=period">' . __('New period') . '</a>
</p>'; </p>';
# Filters # Filters
@ -110,7 +110,7 @@ $p_filter->display('admin.plugin.periodical', form::hidden('p', 'periodical') .
# Periods list # Periods list
$period_list->periodDisplay($p_filter, $period_list->periodDisplay($p_filter,
'<form action="' . $p_url . '" method="post" id="form-periods">' . '<form action="' . dcCore::app()->admin->getPageURL() . '" method="post" id="form-periods">' .
'%s' . '%s' .
@ -120,8 +120,8 @@ $period_list->periodDisplay($p_filter,
'<p class="col right">' . __('Selected periods action:') . ' ' . '<p class="col right">' . __('Selected periods action:') . ' ' .
form::combo('action', $combo_action) . form::combo('action', $combo_action) .
'<input type="submit" value="' . __('ok') . '" /></p>' . '<input type="submit" value="' . __('ok') . '" /></p>' .
$core->adminurl->getHiddenFormFields('admin.plugin.periodical', array_merge(['p' => 'periodical'], $p_filter->values(true))) . dcCore::app()->adminurl->getHiddenFormFields('admin.plugin.periodical', array_merge(['p' => 'periodical'], $p_filter->values(true))) .
$core->formNonce() . dcCore::app()->formNonce() .
'</div>' . '</div>' .
'</form>' '</form>'
); );

View File

@ -22,6 +22,8 @@ if (!defined('DC_CONTEXT_ADMIN')) {
*/ */
class adminPeriodicalList extends adminGenericList class adminPeriodicalList extends adminGenericList
{ {
private $periodical = null;
public function periodDisplay($filter, $enclose_block='') public function periodDisplay($filter, $enclose_block='')
{ {
if ($this->rs->isEmpty()) { if ($this->rs->isEmpty()) {
@ -31,7 +33,8 @@ class adminPeriodicalList extends adminGenericList
echo '<p><strong>' . __('No period') . '</strong></p>'; echo '<p><strong>' . __('No period') . '</strong></p>';
} }
} else { } else {
$pager = new dcPager($filter->page, $this->rs_count, $filter->nb, 10); $this->periodical = new periodical();
$pager = new dcPager((int) $filter->page, $this->rs_count, $filter->nb, 10);
$pager->var_page = 'page'; $pager->var_page = 'page';
$periods = []; $periods = [];
@ -75,8 +78,8 @@ class adminPeriodicalList extends adminGenericList
private function periodLine($checked) private function periodLine($checked)
{ {
$nb_posts = $this->rs->periodical->getPosts(['periodical_id' => $this->rs->periodical_id], true)->f(0); $nb_posts = $this->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]); $url = dcCore::app()->adminurl->get('admin.plugin.periodical', ['part' => 'period', 'period_id' => $this->rs->periodical_id]);
$name = '<a href="' . $url . '#period" title="' . __('edit period') . '">' . html::escapeHTML($this->rs->periodical_title) . '</a>'; $name = '<a href="' . $url . '#period" title="' . __('edit period') . '">' . html::escapeHTML($this->rs->periodical_title) . '</a>';
@ -84,8 +87,8 @@ class adminPeriodicalList extends adminGenericList
'<a href="' . $url . '#posts" title="' . __('view related entries') . '">' . $nb_posts . '</a>' : '<a href="' . $url . '#posts" title="' . __('view related entries') . '">' . $nb_posts . '</a>' :
'0'; '0';
$interval = in_array($this->rs->periodical_pub_int, $this->rs->periodical->getTimesCombo()) ? $interval = in_array($this->rs->periodical_pub_int, $this->periodical->getTimesCombo()) ?
__(array_search($this->rs->periodical_pub_int, $this->rs->periodical->getTimesCombo())) : __('Unknow frequence'); __(array_search($this->rs->periodical_pub_int, $this->periodical->getTimesCombo())) : __('Unknow frequence');
$cols = new ArrayObject([ $cols = new ArrayObject([
'check' => '<td class="nowrap">' . form::checkbox(['periods[]'], $this->rs->periodical_id, ['checked' => $checked]) . '</td>', 'check' => '<td class="nowrap">' . form::checkbox(['periods[]'], $this->rs->periodical_id, ['checked' => $checked]) . '</td>',
@ -169,7 +172,7 @@ class adminPeriodicalList extends adminGenericList
private function postLine($checked) private function postLine($checked)
{ {
if ($this->core->auth->check('categories', $this->core->blog->id)) { if (dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([dcAuth::PERMISSION_CATEGORIES]), dcCore::app()->blog->id)) {
$cat_link = '<a href="category.php?id=%s">%s</a>'; $cat_link = '<a href="category.php?id=%s">%s</a>';
} else { } else {
$cat_link = '%2$s'; $cat_link = '%2$s';

View File

@ -18,7 +18,7 @@ if (!defined('DC_CONTEXT_ADMIN')) {
$part = !empty($_REQUEST['part']) ? $_REQUEST['part'] : 'periods'; $part = !empty($_REQUEST['part']) ? $_REQUEST['part'] : 'periods';
if ($part == 'period') { if ($part == 'period') {
include dirname(__FILE__) . '/inc/index.period.php'; include __DIR__ . '/inc/index.period.php';
} else { } else {
include dirname(__FILE__) . '/inc/index.periods.php'; include __DIR__ . '/inc/index.periods.php';
} }

View File

@ -15,4 +15,4 @@ if (!defined('DC_RC_PATH')) {
return null; return null;
} }
$__resources['help']['periodical'] = dirname(__FILE__) . '/help/help.html'; dcCore::app()->resources['help']['periodical'] = __DIR__ . '/help/help.html';

View File

@ -15,4 +15,4 @@ if (!defined('DC_RC_PATH')) {
return null; return null;
} }
$__resources['help']['periodical'] = dirname(__FILE__) . '/help/help.html'; dcCore::app()->resources['help']['periodical'] = __DIR__ . '/help/help.html';