From 09bcd72b5489df8c6fc50c58aca5d2d14b426071 Mon Sep 17 00:00:00 2001 From: Jean-Christian Denis Date: Mon, 16 May 2022 23:05:40 +0200 Subject: [PATCH] fix period dates --- CHANGELOG.md | 4 ++++ README.md | 2 +- _define.php | 4 ++-- _install.php | 2 +- dcstore.xml | 6 +++--- inc/index.period.php | 38 ++++++++++++++++++++++++++++++-------- 6 files changed, 41 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 880fe83..e93a1eb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +2022.05.16 +- require Dotclear 2.22 +- fix period dates + 2022.04.27 - require Dotclear 2.21.3 - fix browser date picker diff --git a/README.md b/README.md index 6163216..c94acf2 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ and they will be publish ones after the others every week. * admin permissions to configure plugin * usage,contentadmin permissions to link feeds - * Dotclear 2.21.3 + * Dotclear 2.22 ## NOTICE diff --git a/_define.php b/_define.php index c2f5636..8b9034d 100644 --- a/_define.php +++ b/_define.php @@ -19,9 +19,9 @@ $this->registerModule( 'Periodical', 'Published periodically entries', 'Jean-Christian Denis and contributors', - '2022.04.27', + '2022.05.16', [ - 'requires' => [['core', '2.21']], + 'requires' => [['core', '2.22']], 'permissions' => 'usage,contentadmin', 'type' => 'plugin', 'support' => 'https://github.com/JcDenis/periodical', diff --git a/_install.php b/_install.php index f45f0c0..9a03831 100644 --- a/_install.php +++ b/_install.php @@ -15,7 +15,7 @@ if (!defined('DC_CONTEXT_ADMIN')) { return null; } -$dc_min = '2.21'; +$dc_min = '2.22'; $new_version = $core->plugins->moduleInfo('periodical', 'version'); $old_version = $core->getVersion('periodical'); diff --git a/dcstore.xml b/dcstore.xml index 62c3222..0201286 100644 --- a/dcstore.xml +++ b/dcstore.xml @@ -1,11 +1,11 @@ Periodical -2022.04.27 +2022.05.16 Jean-Christian Denis and contributors Published periodically entries -https://github.com/JcDenis/periodical/releases/download/v2022.04.27/plugin-periodical.zip -2.21 +https://github.com/JcDenis/periodical/releases/download/v2022.05.16/plugin-periodical.zip +2.22 https://plugins.dotaddict.org/dc2/details/periodical https://github.com/JcDenis/periodical diff --git a/inc/index.period.php b/inc/index.period.php index dbc72ae..c367877 100644 --- a/inc/index.period.php +++ b/inc/index.period.php @@ -30,8 +30,10 @@ $period_id = null; $period_title = __('One post per day'); $period_pub_nb = 1; $period_pub_int = 'day'; -$period_curdt = time(); -$period_enddt = time() + 31536000; //one year +$period_curdt = date('Y-m-d H:i', time()); +$period_enddt = date('Y-m-d H:i', time() + 31536000); //one year +$bad_period_curdt = false; +$bad_period_enddt = false; # Get period if (!empty($_REQUEST['period_id'])) { @@ -46,8 +48,8 @@ if (!empty($_REQUEST['period_id'])) { $period_title = $rs->periodical_title; $period_pub_nb = $rs->periodical_pub_nb; $period_pub_int = $rs->periodical_pub_int; - $period_curdt = strtotime($rs->periodical_curdt); - $period_enddt = strtotime($rs->periodical_enddt); + $period_curdt = date('Y-m-d H:i', strtotime($rs->periodical_curdt)); + $period_enddt = date('Y-m-d H:i', strtotime($rs->periodical_enddt)); } } @@ -66,10 +68,30 @@ if ($action == 'setperiod') { $period_pub_int = $_POST['period_pub_int']; } if (!empty($_POST['period_curdt'])) { - $period_curdt = strtotime($_POST['period_curdt']); + try { + $period_curdt = strtotime($_POST['period_curdt']); + if ($period_curdt == false || $period_curdt == -1) { + $bad_period_curdt = true; + + throw new Exception(__('Invalid date')); + } + $period_curdt = date('Y-m-d H:i', $period_curdt); + } catch (Exception $e) { + $core->error->add($e->getMessage()); + } } if (!empty($_POST['period_enddt'])) { - $period_enddt = strtotime($_POST['period_enddt']); + try { + $period_enddt = strtotime($_POST['period_enddt']); + if ($period_enddt == false || $period_enddt == -1) { + $bad_period_enddt = true; + + throw new Exception(__('Invalid date')); + } + $period_enddt = date('Y-m-d H:i', $period_enddt); + } catch (Exception $e) { + $core->error->add($e->getMessage()); + } } # Check period title and dates @@ -249,13 +271,13 @@ form::field('period_title', 60, 255, html::escapeHTML($period_title), 'maximal')

' . form::datetime('period_curdt', [ 'default' => html::escapeHTML(dt::str('%Y-%m-%dT%H:%M', strtotime($period_curdt))), - 'class' => (!$period_curdt ? 'invalid' : ''), + 'class' => ($bad_period_curdt ? 'invalid' : ''), ]) . '

' . form::datetime('period_enddt', [ 'default' => html::escapeHTML(dt::str('%Y-%m-%dT%H:%M', strtotime($period_enddt))), - 'class' => (!$period_enddt ? 'invalid' : ''), + 'class' => ($bad_period_enddt ? 'invalid' : ''), ]) .'