use DateTimeZone
This commit is contained in:
parent
596569cbb2
commit
44dd4995df
2 changed files with 32 additions and 19 deletions
|
@ -15,13 +15,13 @@ declare(strict_types=1);
|
||||||
namespace Dotclear\Plugin\postExpired;
|
namespace Dotclear\Plugin\postExpired;
|
||||||
|
|
||||||
use ArrayObject;
|
use ArrayObject;
|
||||||
|
use DateTimeZone;
|
||||||
use cursor;
|
use cursor;
|
||||||
use dcCore;
|
use dcCore;
|
||||||
use dcPostsActions;
|
use dcPostsActions;
|
||||||
use dcPage;
|
use dcPage;
|
||||||
use dcRecord;
|
use dcRecord;
|
||||||
use Exception;
|
use Exception;
|
||||||
use dt;
|
|
||||||
use html;
|
use html;
|
||||||
use form;
|
use form;
|
||||||
use formSelectOption;
|
use formSelectOption;
|
||||||
|
@ -209,7 +209,7 @@ class BackendBehaviors
|
||||||
*
|
*
|
||||||
* @param integer $post_id Post id
|
* @param integer $post_id Post id
|
||||||
*/
|
*/
|
||||||
protected static function delPostExpired(int $post_id): void
|
private static function delPostExpired(int $post_id): void
|
||||||
{
|
{
|
||||||
dcCore::app()->meta->delPostMeta($post_id, My::META_TYPE);
|
dcCore::app()->meta->delPostMeta($post_id, My::META_TYPE);
|
||||||
}
|
}
|
||||||
|
@ -220,7 +220,7 @@ class BackendBehaviors
|
||||||
* @param integer $post_id Post id
|
* @param integer $post_id Post id
|
||||||
* @param ArrayObject $post _POST fields
|
* @param ArrayObject $post _POST fields
|
||||||
*/
|
*/
|
||||||
protected static function setPostExpired(int $post_id, ArrayObject $post): void
|
private static function setPostExpired(int $post_id, ArrayObject $post): void
|
||||||
{
|
{
|
||||||
$post_expired = [
|
$post_expired = [
|
||||||
'status' => '',
|
'status' => '',
|
||||||
|
@ -228,10 +228,7 @@ class BackendBehaviors
|
||||||
'selected' => '',
|
'selected' => '',
|
||||||
'comment' => '',
|
'comment' => '',
|
||||||
'trackback' => '',
|
'trackback' => '',
|
||||||
'date' => date(
|
'date' => self::dateFromUser($post['post_expired_date']),
|
||||||
'Y-m-d H:i:00',
|
|
||||||
strtotime((string) $post['post_expired_date'])
|
|
||||||
),
|
|
||||||
];
|
];
|
||||||
|
|
||||||
if (!empty($post['post_expired_status'])) {
|
if (!empty($post['post_expired_status'])) {
|
||||||
|
@ -263,7 +260,7 @@ class BackendBehaviors
|
||||||
* @param string $post_type Posts type
|
* @param string $post_type Posts type
|
||||||
* @return array Array of HTML form fields
|
* @return array Array of HTML form fields
|
||||||
*/
|
*/
|
||||||
protected static function fieldsPostExpired(string $post_type, ?int $post_id = null): array
|
private static function fieldsPostExpired(string $post_type, ?int $post_id = null): array
|
||||||
{
|
{
|
||||||
$fields = $post_expired = [];
|
$fields = $post_expired = [];
|
||||||
|
|
||||||
|
@ -282,7 +279,7 @@ class BackendBehaviors
|
||||||
$fields['post_expired_date'] = '<p><label for="post_expired_date">' .
|
$fields['post_expired_date'] = '<p><label for="post_expired_date">' .
|
||||||
__('Date:') . '</label>' .
|
__('Date:') . '</label>' .
|
||||||
form::datetime('post_expired_date', [
|
form::datetime('post_expired_date', [
|
||||||
'default' => html::escapeHTML(dt::str('%Y-%m-%dT%H:%M', (int) strtotime((string) ($post_expired['date'] ?? 'now')))),
|
'default' => html::escapeHTML(self::dateToUser($post_expired['date'] ?? 'now')),
|
||||||
'class' => (empty($post_expired['date']) ? 'invalid' : ''),
|
'class' => (empty($post_expired['date']) ? 'invalid' : ''),
|
||||||
])
|
])
|
||||||
. '</p>';
|
. '</p>';
|
||||||
|
@ -348,7 +345,7 @@ class BackendBehaviors
|
||||||
* @param dcRecord $categories Categories recordset
|
* @param dcRecord $categories Categories recordset
|
||||||
* @return array Categorires combo
|
* @return array Categorires combo
|
||||||
*/
|
*/
|
||||||
protected static function categoriesCombo(dcRecord $categories): array
|
private static function categoriesCombo(dcRecord $categories): array
|
||||||
{
|
{
|
||||||
# Getting categories
|
# Getting categories
|
||||||
$categories_combo = [
|
$categories_combo = [
|
||||||
|
@ -378,7 +375,7 @@ class BackendBehaviors
|
||||||
*
|
*
|
||||||
* @return array Status combo
|
* @return array Status combo
|
||||||
*/
|
*/
|
||||||
protected static function statusCombo(): array
|
private static function statusCombo(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
__('Not changed') => '',
|
__('Not changed') => '',
|
||||||
|
@ -393,7 +390,7 @@ class BackendBehaviors
|
||||||
*
|
*
|
||||||
* @return array Selection combo
|
* @return array Selection combo
|
||||||
*/
|
*/
|
||||||
protected static function selectedCombo(): array
|
private static function selectedCombo(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
__('Not changed') => '',
|
__('Not changed') => '',
|
||||||
|
@ -407,7 +404,7 @@ class BackendBehaviors
|
||||||
*
|
*
|
||||||
* @return array Comment status combo
|
* @return array Comment status combo
|
||||||
*/
|
*/
|
||||||
protected static function commentCombo(): array
|
private static function commentCombo(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
__('Not changed') => '',
|
__('Not changed') => '',
|
||||||
|
@ -421,7 +418,7 @@ class BackendBehaviors
|
||||||
*
|
*
|
||||||
* @return array Trackback status combo
|
* @return array Trackback status combo
|
||||||
*/
|
*/
|
||||||
protected static function trackbackCombo(): array
|
private static function trackbackCombo(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
__('Not changed') => '',
|
__('Not changed') => '',
|
||||||
|
@ -429,4 +426,18 @@ class BackendBehaviors
|
||||||
__('Closed') => '!0',
|
__('Closed') => '!0',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static function dateFromUser(string $date): string
|
||||||
|
{
|
||||||
|
$d = date_create($date, new DateTimeZone(dcCore::app()->auth->getInfo('user_tz')));
|
||||||
|
|
||||||
|
return $d ? date_format($d->setTimezone(new DateTimeZone('UTC')), 'Y-m-d H:i:00') : '';
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function dateToUser(string $date): string
|
||||||
|
{
|
||||||
|
$d = date_create($date, new DateTimeZone('UTC'));
|
||||||
|
|
||||||
|
return $d ? date_format($d->setTimezone(new DateTimeZone(dcCore::app()->auth->getInfo('user_tz'))), 'Y-m-d\TH:i') : '';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,11 +14,11 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace Dotclear\Plugin\postExpired;
|
namespace Dotclear\Plugin\postExpired;
|
||||||
|
|
||||||
|
use DateTimeZone;
|
||||||
use dcBlog;
|
use dcBlog;
|
||||||
use dcCore;
|
use dcCore;
|
||||||
use dcMeta;
|
use dcMeta;
|
||||||
use dcRecord;
|
use dcRecord;
|
||||||
use dt;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ingroup DC_PLUGIN_POSTEXPIRED
|
* @ingroup DC_PLUGIN_POSTEXPIRED
|
||||||
|
@ -49,8 +49,9 @@ class FrontendBehaviors
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Get curent timestamp
|
# Prepared date
|
||||||
$now = dt::toUTC(time());
|
$utc = new DateTimeZone('UTC');
|
||||||
|
$now_tz = (int) date_format(date_create('now', $utc), 'U');
|
||||||
|
|
||||||
# Prepared post cursor
|
# Prepared post cursor
|
||||||
$post_cur = dcCore::app()->con->openCursor(dcCore::app()->prefix . dcBlog::POST_TABLE_NAME);
|
$post_cur = dcCore::app()->con->openCursor(dcCore::app()->prefix . dcBlog::POST_TABLE_NAME);
|
||||||
|
@ -62,8 +63,9 @@ class FrontendBehaviors
|
||||||
$post_expired = My::decode($posts->f('meta_id'));
|
$post_expired = My::decode($posts->f('meta_id'));
|
||||||
|
|
||||||
# Check if post is outdated
|
# Check if post is outdated
|
||||||
$now_tz = $now + dt::getTimeOffset($posts->f('post_tz'), $now);
|
$meta_dt = date_create((string) $post_expired['date'], $utc);
|
||||||
$meta_tz = strtotime($post_expired['date']);
|
$meta_tz = $meta_dt ? date_format($meta_dt, 'U') : 0;
|
||||||
|
|
||||||
if ($now_tz > $meta_tz) {
|
if ($now_tz > $meta_tz) {
|
||||||
# Delete meta for expired date
|
# Delete meta for expired date
|
||||||
dcCore::app()->auth->sudo(
|
dcCore::app()->auth->sudo(
|
||||||
|
|
Loading…
Reference in a new issue