diff --git a/src/Backend.php b/src/Backend.php
index 2f750cd..0646c44 100644
--- a/src/Backend.php
+++ b/src/Backend.php
@@ -15,7 +15,6 @@ declare(strict_types=1);
namespace Dotclear\Plugin\periodical;
use dcAdmin;
-use dcAuth;
use dcCore;
use dcNsProcess;
use dcPage;
@@ -26,9 +25,10 @@ class Backend extends dcNsProcess
{
static::$init == defined('DC_CONTEXT_ADMIN')
&& My::phpCompliant()
+ && !is_null(dcCore::app()->blog) && !is_null(dcCore::app()->auth)
&& dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([
- dcAuth::PERMISSION_USAGE,
- dcAuth::PERMISSION_CONTENT_ADMIN,
+ dcCore::app()->auth::PERMISSION_USAGE,
+ dcCore::app()->auth::PERMISSION_CONTENT_ADMIN,
]), dcCore::app()->blog->id);
return static::$init;
@@ -40,6 +40,7 @@ class Backend extends dcNsProcess
return false;
}
+ // register backend behaviors
dcCore::app()->addBehaviors([
'adminBlogPreferencesFormV2' => [BackendBehaviors::class, 'adminBlogPreferencesForm'],
'adminBeforeBlogSettingsUpdate' => [BackendBehaviors::class, 'adminBeforeBlogSettingsUpdate'],
@@ -50,18 +51,20 @@ class Backend extends dcNsProcess
'adminBeforePostDelete' => [BackendBehaviors::class, 'adminBeforePostDelete'],
]);
- if (dcCore::app()->blog->settings->get(My::id())->get('periodical_active')) {
+ if (dcCore::app()->blog?->settings->get(My::id())->get('periodical_active')) {
+ // add backend sidebar icon
dcCore::app()->menu[dcAdmin::MENU_PLUGINS]->addItem(
My::name(),
- dcCore::app()->adminurl->get('admin.plugin.' . My::id()),
+ dcCore::app()->adminurl?->get('admin.plugin.' . My::id()),
dcPage::getPF(My::id() . '/icon.svg'),
- preg_match('/' . preg_quote(dcCore::app()->adminurl->get('admin.plugin.' . My::id())) . '(&.*)?$/', $_SERVER['REQUEST_URI']),
- dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([
- dcAuth::PERMISSION_USAGE,
- dcAuth::PERMISSION_CONTENT_ADMIN,
+ preg_match('/' . preg_quote((string) dcCore::app()->adminurl?->get('admin.plugin.' . My::id())) . '(&.*)?$/', $_SERVER['REQUEST_URI']),
+ dcCore::app()->auth?->check(dcCore::app()->auth->makePermissions([
+ dcCore::app()->auth::PERMISSION_USAGE,
+ dcCore::app()->auth::PERMISSION_CONTENT_ADMIN,
]), dcCore::app()->blog->id)
);
+ // register bakend behaviors required user permissions
dcCore::app()->addBehaviors([
'adminDashboardFavoritesV2' => [BackendBehaviors::class, 'adminDashboardFavoritesV2'],
'adminPostHeaders' => [BackendBehaviors::class, 'adminPostHeaders'],
diff --git a/src/BackendBehaviors.php b/src/BackendBehaviors.php
index 625f6d1..989b688 100644
--- a/src/BackendBehaviors.php
+++ b/src/BackendBehaviors.php
@@ -15,14 +15,15 @@ declare(strict_types=1);
namespace Dotclear\Plugin\periodical;
use ArrayObject;
-use cursor;
-use dcAuth;
use dcCore;
use dcFavorites;
use dcPage;
use dcPostsActions;
-use dcRecord;
use dcSettings;
+use Dotclear\Database\{
+ Cursor,
+ MetaRecord
+};
use Dotclear\Helper\Html\Form\{
Checkbox,
Div,
@@ -47,9 +48,9 @@ class BackendBehaviors
private static array $combo_period = [];
/**
- * Add settings to blog preference
+ * Add settings to blog preference.
*
- * @param dcSettings $blog_settings dcSettings instance
+ * @param dcSettings $blog_settings dcSettings instance
*/
public static function adminBlogPreferencesForm(dcSettings $blog_settings): void
{
@@ -81,9 +82,9 @@ class BackendBehaviors
}
/**
- * Save blog settings
+ * Save blog settings.
*
- * @param dcSettings $blog_settings dcSettings instance
+ * @param dcSettings $blog_settings dcSettings instance
*/
public static function adminBeforeBlogSettingsUpdate(dcSettings $blog_settings): void
{
@@ -95,7 +96,7 @@ class BackendBehaviors
/**
* User pref for periods columns lists.
*
- * @param arrayObject $cols Columns
+ * @param ArrayObject $cols Columns
*/
public static function adminColumnsLists(ArrayObject $cols): void
{
@@ -116,7 +117,7 @@ class BackendBehaviors
/**
* User pref periods filters options.
*
- * @param arrayObject $sorts Sort options
+ * @param ArrayObject $sorts Sort options
*/
public static function adminFiltersLists(ArrayObject $sorts): void
{
@@ -132,12 +133,12 @@ class BackendBehaviors
/**
* Add columns period to posts list header.
*
- * @param dcRecord $rs record instance
- * @param ArrayObject $cols Columns
+ * @param MetaRecord $rs record instance
+ * @param ArrayObject $cols Columns
*/
- public static function adminPostListHeader(dcRecord $rs, ArrayObject $cols): void
+ public static function adminPostListHeader(MetaRecord $rs, ArrayObject $cols): void
{
- if (dcCore::app()->blog->settings->get('periodical')->get('periodical_active')) {
+ if (dcCore::app()->blog?->settings->get('periodical')->get('periodical_active')) {
$cols['period'] = '
' . __('Period') . ' | ';
}
}
@@ -145,12 +146,12 @@ class BackendBehaviors
/**
* Add columns period to posts list values.
*
- * @param dcRecord $rs record instance
- * @param ArrayObject $cols Columns
+ * @param MetaRecord $rs record instance
+ * @param ArrayObject $cols Columns
*/
- public static function adminPostListValue(dcRecord $rs, ArrayObject $cols): void
+ public static function adminPostListValue(MetaRecord $rs, ArrayObject $cols): void
{
- if (!dcCore::app()->blog->settings->get('periodical')->get('periodical_active')) {
+ if (!dcCore::app()->blog?->settings->get('periodical')->get('periodical_active')) {
return;
}
@@ -158,7 +159,7 @@ class BackendBehaviors
if ($r->isEmpty()) {
$name = '-';
} else {
- $url = dcCore::app()->adminurl->get('admin.plugin.periodical', ['part' => 'period', 'period_id' => $r->f('periodical_id')]);
+ $url = dcCore::app()->adminurl?->get('admin.plugin.periodical', ['part' => 'period', 'period_id' => $r->f('periodical_id')]);
$name = '' . Html::escapeHTML($r->f('periodical_title')) . '';
}
$cols['period'] = '' . $name . ' | ';
@@ -167,26 +168,29 @@ class BackendBehaviors
/**
* Dashboard Favorites.
*
- * @param dcFavorites $favs Array of favorites
+ * @param dcFavorites $favs Array of favorites
*/
public static function adminDashboardFavoritesV2(dcFavorites $favs): void
{
+ if (is_null(dcCore::app()->auth) || is_null(dcCore::app()->blog) || is_null(dcCore::app()->adminurl)) {
+ return;
+ }
$favs->register(My::id(), [
'title' => My::name(),
'url' => dcCore::app()->adminurl->get('admin.plugin.' . My::id()),
'small-icon' => dcPage::getPF(My::id() . '/icon.svg'),
'large-icon' => dcPage::getPF(My::id() . '/icon.svg'),
'permissions' => dcCore::app()->auth->makePermissions([
- dcAuth::PERMISSION_USAGE,
- dcAuth::PERMISSION_CONTENT_ADMIN,
+ dcCore::app()->auth::PERMISSION_USAGE,
+ dcCore::app()->auth::PERMISSION_CONTENT_ADMIN,
]),
]);
}
/**
- * Add javascript for toggle
+ * Add javascript for toggle.
*
- * @return string HTML head
+ * @return string HTML head
*/
public static function adminPostHeaders(): string
{
@@ -194,9 +198,9 @@ class BackendBehaviors
}
/**
- * Delete relation between post and period
+ * Delete relation between post and period.
*
- * @param integer $post_id Post id
+ * @param int $post_id Post id
*/
public static function adminBeforePostDelete(int $post_id): void
{
@@ -204,9 +208,9 @@ class BackendBehaviors
}
/**
- * Add actions to posts page combo
+ * Add actions to posts page combo.
*
- * @param dcPostsActions $pa dcPostsActions instance
+ * @param dcPostsActions $pa dcPostsActions instance
*/
public static function adminPostsActions(dcPostsActions $pa): void
{
@@ -215,10 +219,10 @@ class BackendBehaviors
[self::class, 'callbackAdd']
);
- if (dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([
- dcAuth::PERMISSION_DELETE,
- dcAuth::PERMISSION_CONTENT_ADMIN,
- ]), dcCore::app()->blog->id)) {
+ if (dcCore::app()->auth?->check(dcCore::app()->auth->makePermissions([
+ dcCore::app()->auth::PERMISSION_DELETE,
+ dcCore::app()->auth::PERMISSION_CONTENT_ADMIN,
+ ]), dcCore::app()->blog?->id)) {
$pa->addAction(
[My::name() => [__('Remove from periodical') => 'periodical_remove']],
[self::class, 'callbackRemove']
@@ -227,28 +231,28 @@ class BackendBehaviors
}
/**
- * Posts actions callback to remove period
+ * Posts actions callback to remove period.
*
- * @param dcPostsActions $pa dcPostsActions instance
- * @param ArrayObject $post _POST actions
+ * @param dcPostsActions $pa dcPostsActions instance
+ * @param ArrayObject $post _POST actions
*/
public static function callbackRemove(dcPostsActions $pa, ArrayObject $post): void
{
- # No entry
+ // No entry
$posts_ids = $pa->getIDs();
if (empty($posts_ids)) {
throw new Exception(__('No entry selected'));
}
- # No right
- if (!dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([
- dcAuth::PERMISSION_DELETE,
- dcAuth::PERMISSION_CONTENT_ADMIN,
- ]), dcCore::app()->blog->id)) {
+ // No right
+ if (!dcCore::app()->auth?->check(dcCore::app()->auth->makePermissions([
+ dcCore::app()->auth::PERMISSION_DELETE,
+ dcCore::app()->auth::PERMISSION_CONTENT_ADMIN,
+ ]), dcCore::app()->blog?->id)) {
throw new Exception(__('No enough right'));
}
- # Remove linked period
+ // Remove linked period
foreach ($posts_ids as $post_id) {
self::delPeriod($post_id);
}
@@ -258,14 +262,14 @@ class BackendBehaviors
}
/**
- * Posts actions callback to add period
+ * Posts actions callback to add period.
*
- * @param dcPostsActions $pa dcPostsActions instance
- * @param ArrayObject $post _POST actions
+ * @param dcPostsActions $pa dcPostsActions instance
+ * @param ArrayObject $post _POST actions
*/
public static function callbackAdd(dcPostsActions $pa, ArrayObject $post): void
{
- # No entry
+ // No entry
$posts_ids = $pa->getIDs();
if (empty($posts_ids)) {
throw new Exception(__('No entry selected'));
@@ -273,7 +277,7 @@ class BackendBehaviors
//todo: check if selected posts is unpublished
- # Save action
+ // Save action
if (!empty($post['periodical'])) {
foreach ($posts_ids as $post_id) {
self::delPeriod($post_id);
@@ -284,13 +288,13 @@ class BackendBehaviors
$pa->redirect(true);
}
- # Display form
+ // Display form
else {
$pa->beginPage(
dcPage::breadcrumb([
- Html::escapeHTML(dcCore::app()->blog->name) => '',
- $pa->getCallerTitle() => $pa->getRedirection(true),
- __('Add a period to this selection') => '',
+ Html::escapeHTML((string) dcCore::app()->blog?->name) => '',
+ $pa->getCallerTitle() => $pa->getRedirection(true),
+ __('Add a period to this selection') => '',
])
);
@@ -313,49 +317,50 @@ class BackendBehaviors
}
/**
- * Add form to post sidebar
+ * Add form to post sidebar.
*
- * @param ArrayObject $main_items Main items
- * @param ArrayObject $sidebar_items Sidebar items
- * @param dcRecord $post Post record or null
+ * @param ArrayObject $main_items Main items
+ * @param ArrayObject $sidebar_items Sidebar items
+ * @param null|MetaRecord $post Post record or null
*/
- public static function adminPostFormItems(ArrayObject $main_items, ArrayObject $sidebar_items, ?dcRecord $post): void
+ public static function adminPostFormItems(ArrayObject $main_items, ArrayObject $sidebar_items, ?MetaRecord $post): void
{
- # Get existing linked period
+ // Get existing linked period
$period = '';
if ($post !== null) {
$rs = Utils::getPosts(['post_id' => $post->f('post_id')]);
$period = $rs->isEmpty() ? '' : $rs->f('periodical_id');
}
- # Set linked period form items
+ // Set linked period form items
$sidebar_items['options-box']['items']['period'] = (string) self::formPeriod((int) $period)?->render();
}
/**
- * Save linked period
+ * Save linked period.
*
- * @param cursor $cur Current post cursor
- * @param null|int $post_id Post id
+ * @param Cursor $cur Current post Cursor
+ * @param null|int $post_id Post id
*/
- public static function adminAfterPostSave(cursor $cur, ?int $post_id): void
+ public static function adminAfterPostSave(Cursor $cur, ?int $post_id): void
{
if (!isset($_POST['periodical']) || $post_id === null) {
return;
}
- # Delete old linked period
+ // Delete old linked period
self::delPeriod($post_id);
- # Add new linked period
+ // Add new linked period
self::addPeriod($post_id, (int) $_POST['periodical']);
}
/**
- * Posts period form field
+ * Posts period form field.
*
- * @param int $period Period
- * @return null|Para Period form object
+ * @param int $period Period
+ *
+ * @return null|Para Period form object
*/
private static function formPeriod(int $period = 0): ?Para
{
@@ -368,9 +373,9 @@ class BackendBehaviors
}
/**
- * Combo of available periods
+ * Combo of available periods.
*
- * @return array List of period
+ * @return array List of period
*/
private static function comboPeriod(): array
{
@@ -392,7 +397,7 @@ class BackendBehaviors
/**
* Remove period from posts.
*
- * @param int $post_id Post id
+ * @param int $post_id Post id
*/
private static function delPeriod(int $post_id): void
{
@@ -400,22 +405,22 @@ class BackendBehaviors
}
/**
- * Add period to posts
+ * Add period to posts.
*
- * @param int $post_id Post id
- * @param int $period_id Period
+ * @param int $post_id Post id
+ * @param int $period_id Period
*/
private static function addPeriod(int $post_id, int $period_id): void
{
- # Get periods
+ // Get periods
$period = Utils::getPeriods(['periodical_id' => $period_id]);
- # No period
+ // No period
if ($period->isEmpty()) {
return;
}
- # Add relation
+ // Add relation
Utils::addPost($period_id, $post_id);
}
}
diff --git a/src/Dater.php b/src/Dater.php
index 0b1cdf2..b1792a1 100644
--- a/src/Dater.php
+++ b/src/Dater.php
@@ -24,27 +24,45 @@ use Exception;
class Dater
{
/**
- * Format a date from UTC to user TZ
+ * Format a date from UTC to user TZ.
+ *
+ * @param string $date The date
+ * @param string $format The output format
+ *
+ * @return string The formated date on user timezone
*/
public static function fromUser(string $date, string $format = 'Y-m-d H:i:00'): string
{
- $d = date_create($date, new DateTimeZone(dcCore::app()->auth->getInfo('user_tz')));
+ $tz = dcCore::app()->auth?->getInfo('user_tz');
+ $d = date_create($date, new DateTimeZone($tz ?? 'UTC'));
return $d ? date_format($d->setTimezone(new DateTimeZone('UTC')), $format) : '';
}
/**
- * Format a date from user TZ to UTC
+ * Format a date from user TZ to UTC.
+ *
+ * @param string $date The date
+ * @param string $format The output format
+ *
+ * @return string The formated date on UTC
*/
public static function toUser(string $date, string $format = 'Y-m-d\TH:i'): string
{
- $d = date_create($date, new DateTimeZone('UTC'));
+ $tz = dcCore::app()->auth?->getInfo('user_tz');
+ $d = date_create($date, new DateTimeZone('UTC'));
- return $d ? date_format($d->setTimezone(new DateTimeZone(dcCore::app()->auth->getInfo('user_tz'))), $format) : '';
+ return $d ? date_format($d->setTimezone(new DateTimeZone($tz ?? 'UTC')), $format) : '';
}
/**
- * Format a date to specific TZ (UTC by default) from another format
+ * Format a date to specific TZ (UTC by default) from another format.
+ *
+ * @param string $date The date
+ * @param string $format The output format
+ * @param string $to_tz The output timezone
+ *
+ * @return string The formated date
*/
public static function toDate(int|string $date = 'now', string $format = 'Y-m-d H:i:00', string $to_tz = 'UTC'): string
{
@@ -56,7 +74,12 @@ class Dater
}
/**
- * Get next timestamp from a period
+ * Get next timestamp from a period.
+ *
+ * @param int $ts The timestamp
+ * @param string $period The period (periodical string format)
+ *
+ * @return int The timestamp of next update
*/
public static function getNextTime(int $ts, string $period): int
{
diff --git a/src/Frontend.php b/src/Frontend.php
index 0b239f2..3437b09 100644
--- a/src/Frontend.php
+++ b/src/Frontend.php
@@ -39,15 +39,19 @@ class Frontend extends dcNsProcess
}
dcCore::app()->addBehavior('publicBeforeDocumentV2', function (): void {
+ if (is_null(dcCore::app()->auth) || is_null(dcCore::app()->blog)) {
+ return;
+ }
+
try {
$s = dcCore::app()->blog->settings->get(My::id());
Utils::lockUpdate();
- # Get periods
+ // Get periods
$periods = dcCore::app()->auth->sudo([Utils::class, 'getPeriods']);
- # No period
+ // No period
if ($periods->isEmpty()) {
Utils::unlockUpdate();
@@ -62,7 +66,7 @@ class Frontend extends dcNsProcess
$cur_period = dcCore::app()->con->openCursor(dcCore::app()->prefix . My::TABLE_NAME);
while ($periods->fetch()) {
- # Check if period is ongoing
+ // Check if period is ongoing
$cur_ts = (int) Dater::toDate($periods->f('periodical_curdt'), 'U');
$end_ts = (int) Dater::toDate($periods->f('periodical_enddt'), 'U');
@@ -83,9 +87,9 @@ class Frontend extends dcNsProcess
} catch (Exception $e) {
}
- # If period need update
+ // If period need update
if ($limit > 0) {
- # Get posts to publish related to this period
+ // Get posts to publish related to this period
$posts_params = [];
$posts_params['periodical_id'] = $periods->f('periodical_id');
$posts_params['post_status'] = dcBlog::POST_PENDING;
@@ -98,18 +102,18 @@ class Frontend extends dcNsProcess
$cur_post = dcCore::app()->con->openCursor(dcCore::app()->prefix . dcBlog::POST_TABLE_NAME);
while ($posts->fetch()) {
- # Publish post with right date
+ // Publish post with right date
$cur_post->clean();
$cur_post->setField('post_status', dcBlog::POST_PUBLISHED);
- # Update post date with right date
+ // Update post date with right date
if ($s->get('periodical_upddate')) {
$cur_post->setField('post_dt', Dater::toDate($last_ts, 'Y-m-d H:i:00', $posts->post_tz));
} else {
$cur_post->setField('post_dt', $posts->f('post_dt'));
}
- # Also update post url with right date
+ // Also update post url with right date
if ($s->get('periodical_updurl')) {
$cur_post->setField('post_url', dcCore::app()->blog->getPostURL(
'',
@@ -124,25 +128,25 @@ class Frontend extends dcNsProcess
"AND blog_id = '" . dcCore::app()->con->escapeStr(dcCore::app()->blog->id) . "' "
);
- # Delete post relation to this period
+ // Delete post relation to this period
Utils::delPost((int) $posts->f('post_id'));
$last_nb++;
- # Increment upddt if nb of publishing is to the max
+ // Increment upddt if nb of publishing is to the max
if ($last_nb == $max_nb) {
$last_ts = Dater::getNextTime($last_ts, $periods->f('periodical_pub_int'));
$last_nb = 0;
}
- # --BEHAVIOR-- periodicalAfterPublishedPeriodicalEntry
+ // --BEHAVIOR-- periodicalAfterPublishedPeriodicalEntry
dcCore::app()->callBehavior('periodicalAfterPublishedPeriodicalEntry', $posts, $periods);
}
dcCore::app()->blog->triggerBlog();
}
}
- # Update last published date of this period even if there's no post to publish
+ // Update last published date of this period even if there's no post to publish
$cur_period->clean();
$cur_period->setField('periodical_curdt', Dater::toDate($loop_ts, 'Y-m-d H:i:00'));
$cur_period->update(
diff --git a/src/Install.php b/src/Install.php
index 735acce..abf6771 100644
--- a/src/Install.php
+++ b/src/Install.php
@@ -14,9 +14,9 @@ declare(strict_types=1);
namespace Dotclear\Plugin\periodical;
-use dbStruct;
use dcCore;
use dcNsProcess;
+use Dotclear\Database\Structure;
use Exception;
class Install extends dcNsProcess
@@ -32,31 +32,30 @@ class Install extends dcNsProcess
public static function process(): bool
{
- if (!static::$init) {
+ if (!static::$init || is_null(dcCore::app()->blog)) {
return false;
}
try {
- # Tables
- $t = new dbStruct(dcCore::app()->con, dcCore::app()->prefix);
+ $t = new Structure(dcCore::app()->con, dcCore::app()->prefix);
- # Table principale des sondages
- $t->{My::TABLE_NAME} // @phpstan-ignore-line
- ->periodical_id('bigint', 0, false)
- ->blog_id('varchar', 32, false)
- ->periodical_type('varchar', 32, false, "'post'")
- ->periodical_title('varchar', 255, false, "''")
- ->periodical_curdt('timestamp', 0, false, ' now()')
- ->periodical_enddt('timestamp', 0, false, 'now()')
- ->periodical_pub_int('varchar', 32, false, "'day'")
- ->periodical_pub_nb('smallint', 0, false, 1)
+ // create database table
+ $t->__get(My::TABLE_NAME)
+ ->field('periodical_id', 'bigint', 0, false)
+ ->field('blog_id', 'varchar', 32, false)
+ ->field('periodical_type', 'varchar', 32, false, "'post'")
+ ->field('periodical_title', 'varchar', 255, false, "''")
+ ->field('periodical_curdt', 'timestamp', 0, false, ' now()')
+ ->field('periodical_enddt', 'timestamp', 0, false, 'now()')
+ ->field('periodical_pub_int', 'varchar', 32, false, "'day'")
+ ->field('periodical_pub_nb', 'smallint', 0, false, 1)
->primary('pk_periodical', 'periodical_id')
->index('idx_periodical_type', 'btree', 'periodical_type');
- (new dbStruct(dcCore::app()->con, dcCore::app()->prefix))->synchronize($t);
+ (new Structure(dcCore::app()->con, dcCore::app()->prefix))->synchronize($t);
- # Settings
+ // set default settings
$s = dcCore::app()->blog->settings->get(My::id());
$s->put('periodical_active', false, 'boolean', 'Enable extension', false, true);
$s->put('periodical_upddate', true, 'boolean', 'Update post date', false, true);
diff --git a/src/Manage.php b/src/Manage.php
index 536f2d1..22db30b 100644
--- a/src/Manage.php
+++ b/src/Manage.php
@@ -15,7 +15,6 @@ declare(strict_types=1);
namespace Dotclear\Plugin\periodical;
use adminGenericFilter;
-use dcAuth;
use dcCore;
use dcNsProcess;
use dcPage;
@@ -35,9 +34,10 @@ class Manage extends dcNsProcess
{
static::$init == defined('DC_CONTEXT_ADMIN')
&& My::phpCompliant()
+ && !is_null(dcCore::app()->auth) && !is_null(dcCore::app()->blog)
&& dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([
- dcAuth::PERMISSION_USAGE,
- dcAuth::PERMISSION_CONTENT_ADMIN,
+ dcCore::app()->auth::PERMISSION_USAGE,
+ dcCore::app()->auth::PERMISSION_CONTENT_ADMIN,
]), dcCore::app()->blog->id);
// call period manage page
@@ -54,14 +54,20 @@ class Manage extends dcNsProcess
return false;
}
+ // nullsafe
+ if (is_null(dcCore::app()->adminurl)) {
+ return false;
+ }
+
+ // call period manage page
if (($_REQUEST['part'] ?? 'periods') === 'period') {
return ManagePeriod::process();
}
- # Default values
+ // load default values
$vars = ManageVars::init();
- # Delete periods and related posts links
+ // Delete periods and related posts links
if ($vars->action == 'deleteperiods' && !empty($vars->periods)) {
try {
foreach ($vars->periods as $id) {
@@ -83,7 +89,7 @@ class Manage extends dcNsProcess
}
}
- # Delete periods related posts links (without delete periods)
+ // Delete periods related posts links (without delete periods)
if ($vars->action == 'emptyperiods' && !empty($vars->periods)) {
try {
foreach ($vars->periods as $id) {
@@ -116,19 +122,25 @@ class Manage extends dcNsProcess
return;
}
+ // nullsafe
+ if (is_null(dcCore::app()->adminurl)) {
+ return;
+ }
+
+ // call period manage page
if (($_REQUEST['part'] ?? 'periods') === 'period') {
ManagePeriod::render();
return;
}
- # Filters
+ // Filters
$p_filter = new adminGenericFilter(dcCore::app(), My::id());
$p_filter->add('part', 'periods');
$params = $p_filter->params();
- # Get periods
+ // Get periods
try {
$periods = Utils::getPeriods($params);
$counter = Utils::getPeriods($params, true);
@@ -137,7 +149,7 @@ class Manage extends dcNsProcess
dcCore::app()->error->add($e->getMessage());
}
- # Display
+ // Display
dcPage::openModule(
My::name(),
dcPage::jsModuleLoad(My::id() . '/js/checkbox.js') .
@@ -155,10 +167,10 @@ class Manage extends dcNsProcess
';
if (isset($period_list)) {
- # Filters
+ // Filters
$p_filter->display('admin.plugin.' . My::id(), (new Hidden('p', My::id()))->render() . (new Hidden('part', 'periods'))->render());
- # Periods list
+ // Periods list
$period_list->periodDisplay(
$p_filter,
'