update license and fix PSR2 codding style

This commit is contained in:
Jean-Christian Paul Denis 2021-08-20 21:36:46 +02:00
parent 16ffcf67d3
commit e7a3cb0fa1
7 changed files with 681 additions and 709 deletions

View File

@ -1,53 +1,45 @@
postExpired xxxx.xx.xx
===========================================================
* Not fix: Wrong timezone on admin vs public expired date
postExpired 2021.08.19
* update license and fix PSR2 coding style
postExpired 2013.11.13
===========================================================
* Fixed wrong field name for category
postExpired 2013.11.03
===========================================================
* Switch to Dotclear 2.6
* Use new posts actions
* Save all options in one meta
* Limit plugin to contentadmin
postExpired 2013.06.30
===========================================================
* Fixed post_type and posts_actions
postExpired 0.5 - 2010-08-17
===========================================================
* Added compatibility with plugins 'pages' and 'muppet'
postExpired 0.4 - 2010-08-03
===========================================================
* Added actions (comments, trackbacks) (closes #525)
* Speed up public part (less sql resquests)
* Fixed typo
postExpired 0.3.1 - 2010-06-21
===========================================================
* Fixed user rights
* Fixed (again) PHP 5.3 compatibility
* Fixed typo
postExpired 0.3 - 2010-06-08
===========================================================
* Switched to DC 2.2 (settings,meta)
postExpired 0.2.1 - 2010-05-28
===========================================================
* Fixed DC 2.1.7 settings bugs
postExpired 0.2 - 2010-04-14
===========================================================
* Added actions choice (status,category,selected)
* Added template block and value
* Added behaviors to open choices
* Enhanced db resquest on public side
postExpired 0.1 - 2010-04-10
===========================================================
* First lab release

View File

@ -30,3 +30,9 @@ Notes:
* Only one expired date per post is supported
* Expired dates are checked from public home page and feed page
## MORE
* License : GNU GPL v2
* Source & contribution : [GitHub Page](https://github.com/JcDenis/postExpired)
* Packages & details: [Dotaddict Page](https://plugins.dotaddict.org/dc2/details/postExpired)

View File

@ -3,8 +3,7 @@
#
# This file is part of postExpired, a plugin for Dotclear 2.
#
# Copyright (c) 2009-2013 Jean-Christian Denis and contributors
# contact@jcdenis.fr http://jcd.lv
# Copyright (c) 2009-2021 Jean-Christian Denis and contributors
#
# Licensed under the GPL version 2.0 license.
# A copy of this license is available in LICENSE file or at
@ -13,70 +12,67 @@
# -- END LICENSE BLOCK ------------------------------------
if (!defined('DC_CONTEXT_ADMIN')) {
return null;
}
# Check plugin version
if ($core->getVersion('postExpired') != $core->plugins->moduleInfo('postExpired', 'version')) {
return null;
}
# Check user right
if (!$core->auth->check('contentadmin', $core->blog->id)) {
return null;
}
# Admin behaviors
$core->addBehavior(
'adminPostsActionsPage',
array('adminBehaviorPostExpired', 'adminPostsActionsPage')
['adminBehaviorPostExpired', 'adminPostsActionsPage']
);
$core->addBehavior(
'adminPagesActionsPage',
array('adminBehaviorPostExpired', 'adminPostsActionsPage')
['adminBehaviorPostExpired', 'adminPostsActionsPage']
);
$core->addBehavior(
'adminPostHeaders',
array('adminBehaviorPostExpired', 'adminPostHeaders')
['adminBehaviorPostExpired', 'adminPostHeaders']
);
$core->addBehavior(
'adminPageHeaders',
array('adminBehaviorPostExpired', 'adminPostHeaders')
['adminBehaviorPostExpired', 'adminPostHeaders']
);
$core->addBehavior(
'adminPostFormItems',
array('adminBehaviorPostExpired', 'adminPostFormItems')
['adminBehaviorPostExpired', 'adminPostFormItems']
);
$core->addBehavior(
'adminPageFormItems',
array('adminBehaviorPostExpired', 'adminPostFormItems')
['adminBehaviorPostExpired', 'adminPostFormItems']
);
$core->addBehavior(
'adminBeforePostDelete',
array('adminBehaviorPostExpired', 'adminBeforePostDelete')
['adminBehaviorPostExpired', 'adminBeforePostDelete']
);
$core->addBehavior(
'adminBeforePageDelete',
array('adminBehaviorPostExpired', 'adminBeforePostDelete')
['adminBehaviorPostExpired', 'adminBeforePostDelete']
);
$core->addBehavior(
'adminAfterPostUpdate',
array('adminBehaviorPostExpired', 'adminAfterPostSave')
['adminBehaviorPostExpired', 'adminAfterPostSave']
);
$core->addBehavior(
'adminAfterPageUpdate',
array('adminBehaviorPostExpired', 'adminAfterPostSave')
['adminBehaviorPostExpired', 'adminAfterPostSave']
);
$core->addBehavior(
'adminAfterPostCreate',
array('adminBehaviorPostExpired', 'adminAfterPostSave')
['adminBehaviorPostExpired', 'adminAfterPostSave']
);
$core->addBehavior(
'adminAfterPageCreate',
array('adminBehaviorPostExpired', 'adminAfterPostSave')
['adminBehaviorPostExpired', 'adminAfterPostSave']
);
/**
@ -133,7 +129,6 @@ class adminBehaviorPostExpired
public static function adminPostFormItems(ArrayObject $main_items, ArrayObject $sidebar_items, $post)
{
if ($post === null) {
return null;
}
@ -174,8 +169,7 @@ class adminBehaviorPostExpired
|| !empty($_POST['post_expired_category'])
|| !empty($_POST['post_expired_selected'])
|| !empty($_POST['post_expired_comment'])
|| !empty($_POST['post_expired_trackback']))
) {
|| !empty($_POST['post_expired_trackback']))) {
self::setPostExpired($core, $post_id, $_POST);
}
}
@ -201,8 +195,7 @@ class adminBehaviorPostExpired
|| !empty($post['post_expired_category'])
|| !empty($post['post_expired_selected'])
|| !empty($post['post_expired_comment'])
|| !empty($post['post_expired_trackback']))
) {
|| !empty($post['post_expired_trackback']))) {
foreach($posts_ids as $post_id) {
self::delPostExpired($core, $post_id);
self::setPostExpired($core, $post_id, $post);
@ -210,10 +203,9 @@ class adminBehaviorPostExpired
dcPage::addSuccessNotice(__('Expired date added.'));
$pa->redirect(true);
}
# Display form
else {
} else {
# Get records to know post type
$posts = $pa->getRS();
@ -223,20 +215,20 @@ class adminBehaviorPostExpired
$pa->getCallerTitle() => $pa->getRedirection(true),
__('Add expired date to this selection') => ''
)),
dcPage::jsDatePicker().
dcPage::jsDatePicker() .
self::adminPostHeaders()
);
echo
'<form action="'.$pa->getURI().'" method="post">'.
$pa->getCheckboxes().
'<form action="' . $pa->getURI() . '" method="post">' .
$pa->getCheckboxes() .
implode('', self::fieldsPostExpired($core, $posts->post_type)).
implode('', self::fieldsPostExpired($core, $posts->post_type)) .
$core->formNonce().
$pa->getHiddenFields().
form::hidden(array('action'), 'post_expired_add').
'<input type="submit" value="'.__('Save').'" /></p>'.
$core->formNonce() .
$pa->getHiddenFields() .
form::hidden(array('action'), 'post_expired_add') .
'<input type="submit" value="' . __('Save') . '" /></p>' .
'</form>';
$pa->endPage();
@ -288,12 +280,12 @@ class adminBehaviorPostExpired
protected static function setPostExpired(dcCore $core, $post_id, $post)
{
$post_expired = array(
'status' => '',
'category' => '',
'selected' => '',
'comment' => '',
'status'=> '',
'category'=> '',
'selected'=> '',
'comment'=> '',
'trackback' => '',
'date' => date(
'date'=> date(
'Y-m-d H:i:00',
strtotime($post['post_expired_date'])
)
@ -334,7 +326,7 @@ class adminBehaviorPostExpired
* @param string $post_type Posts type
* @return array Array of HTML form fields
*/
protected static function fieldsPostExpired(dcCore $core, $post_type, $post_id=null)
protected static function fieldsPostExpired(dcCore $core, $post_type, $post_id = null)
{
$fields = $post_expired = array();
@ -353,32 +345,32 @@ class adminBehaviorPostExpired
}
$fields['post_expired_date'] =
'<p><label for="post_expired_date">'.
__('Date:').'</label>'.
'<p><label for="post_expired_date">' .
__('Date:') . '</label>' .
form::field(
'post_expired_date',
16,
16,
empty($post_expired['date']) ?
'' : $post_expired['date']
).'</p>';
) . '</p>';
$fields['post_expired_status'] =
'<h5>'.__('On this date, change:').'</h5>'.
'<p><label for="post_expired_status">'.
__('Status:').'</label>'.
'<h5>' . __('On this date, change:') . '</h5>' .
'<p><label for="post_expired_status">' .
__('Status:') . '</label>' .
form::combo(
'post_expired_status',
self::statusCombo(),
empty($post_expired['status']) ?
'' : $post_expired['status']
).'</p>';
) . '</p>';
if ($post_type == 'post') {
$fields['post_expired_category'] =
'<p><label for="post_expired_category">'.
__('Category:').'</label>'.
'<p><label for="post_expired_category">' .
__('Category:') . '</label>' .
form::combo(
'post_expired_category',
self::categoriesCombo(
@ -388,38 +380,38 @@ class adminBehaviorPostExpired
),
empty($post_expired['category']) ?
'' : $post_expired['category']
).'</p>';
) . '</p>';
$fields['post_expired_selected'] =
'<p><label for="post_expired_selected">'.
__('Selection:').'</label>'.
'<p><label for="post_expired_selected">' .
__('Selection:') . '</label>' .
form::combo(
'post_expired_selected',
self::selectedCombo(),
empty($post_expired['selected']) ?
'' : $post_expired['selected']
).'</p>';
) . '</p>';
}
$fields['post_expired_comment'] =
'<p><label for="post_expired_comment">'.
__('Comments status:').'</label>'.
'<p><label for="post_expired_comment">' .
__('Comments status:') . '</label>' .
form::combo(
'post_expired_comment',
self::commentCombo(),
empty($post_expired['comment']) ?
'' : $post_expired['comment']
).'</p>';
) . '</p>';
$fields['post_expired_trackback'] =
'<p><label for="post_expired_trackback">'.
__('Trackbacks status:').'</label>'.
'<p><label for="post_expired_trackback">' .
__('Trackbacks status:') . '</label>' .
form::combo(
'post_expired_trackback',
self::trackbackCombo(),
empty($post_expired['trackback']) ?
'' : $post_expired['trackback']
).'</p>';
) . '</p>';
return $fields;
}
@ -443,13 +435,11 @@ class adminBehaviorPostExpired
);
while ($categories->fetch()) {
$categories_combo[] = new formSelectOption(
str_repeat('&nbsp;&nbsp;', $categories->level-1).'&bull; '.html::escapeHTML($categories->cat_title),
str_repeat('&nbsp;&nbsp;', $categories->level - 1) . '&bull; '. html::escapeHTML($categories->cat_title),
'!'.$categories->cat_id
);
}
}
catch (Exception $e) {
} catch (Exception $e) {
return array();
}

View File

@ -3,8 +3,7 @@
#
# This file is part of postExpired, a plugin for Dotclear 2.
#
# Copyright (c) 2009-2013 Jean-Christian Denis and contributors
# contact@jcdenis.fr http://jcd.lv
# Copyright (c) 2009-2021 Jean-Christian Denis and contributors
#
# Licensed under the GPL version 2.0 license.
# A copy of this license is available in LICENSE file or at
@ -12,23 +11,20 @@
#
# -- END LICENSE BLOCK ------------------------------------
if (!defined('DC_RC_PATH')){return;}
if (!defined('DC_RC_PATH')) {
return null;
}
$this->registerModule(
/* Name */
"Expired entries",
/* Description*/
"Change entries options at a given date",
/* Author */
"Jean-Christian Denis",
/* Version */
'2013.11.13',
/* Properies */
array(
'Expired entries',
'Change entries options at a given date',
'Jean-Christian Denis and Contributors',
'2021.08.19',
[
'permissions' => 'usage,contentadmin',
'type' => 'plugin',
'dc_min' => '2.6',
'support' => 'http://jcd.lv/q=postExpired',
'details' => 'http://plugins.dotaddict.org/dc2/details/postExpired'
)
'dc_min' => '2.18',
'support' => 'https://github.com/JcDenis/postExpired',
'details' => 'https://plugins.dotaddict.org/dc2/details/postExpired'
]
);

View File

@ -3,8 +3,7 @@
#
# This file is part of postExpired, a plugin for Dotclear 2.
#
# Copyright (c) 2009-2013 Jean-Christian Denis and contributors
# contact@jcdenis.fr http://jcd.lv
# Copyright (c) 2009-2021 Jean-Christian Denis and contributors
#
# Licensed under the GPL version 2.0 license.
# A copy of this license is available in LICENSE file or at
@ -13,26 +12,21 @@
# -- END LICENSE BLOCK ------------------------------------
if (!defined('DC_CONTEXT_ADMIN')) {
return null;
}
# -- Module specs --
$dc_min = '2.6';
$dc_min = '2.18';
$mod_id = 'postExpired';
# -- Nothing to change below --
try {
# Check module version
if (version_compare(
$core->getVersion($mod_id),
$core->plugins->moduleInfo($mod_id, 'version'),
'>='
)) {
return null;
}
@ -51,11 +45,8 @@ try {
);
return true;
}
catch (Exception $e) {
} catch (Exception $e) {
$core->error->add($e->getMessage());
return false;
}
?>

View File

@ -3,8 +3,7 @@
#
# This file is part of postExpired, a plugin for Dotclear 2.
#
# Copyright (c) 2009-2013 Jean-Christian Denis and contributors
# contact@jcdenis.fr http://jcd.lv
# Copyright (c) 2009-2021 Jean-Christian Denis and contributors
#
# Licensed under the GPL version 2.0 license.
# A copy of this license is available in LICENSE file or at
@ -13,7 +12,6 @@
# -- END LICENSE BLOCK ------------------------------------
if (!defined('DC_RC_PATH')) {
return null;
}
@ -30,7 +28,7 @@ function encodePostExpired($in)
{
$out = array();
foreach($in as $k => $v) {
$out[] = $k.'|'.$v;
$out[] = $k . '|' . $v;
}
return implode(';', $out);

View File

@ -3,8 +3,7 @@
#
# This file is part of postExpired, a plugin for Dotclear 2.
#
# Copyright (c) 2009-2013 Jean-Christian Denis and contributors
# contact@jcdenis.fr http://jcd.lv
# Copyright (c) 2009-2021 Jean-Christian Denis and contributors
#
# Licensed under the GPL version 2.0 license.
# A copy of this license is available in LICENSE file or at
@ -13,12 +12,10 @@
# -- END LICENSE BLOCK ------------------------------------
if (!defined('DC_RC_PATH')) {
return null;
}
if ($core->getVersion('postExpired') != $core->plugins->moduleInfo('postExpired', 'version')) {
return null;
}
@ -29,24 +26,24 @@ __('This entry has no expiration date');
if (in_array($core->url->type, array('default', 'feed'))) {
$core->addBehavior(
'publicBeforeDocument',
array('publicBehaviorPostExpired', 'publicBeforeDocument')
['publicBehaviorPostExpired', 'publicBeforeDocument']
);
}
$core->addBehavior(
'coreBlogGetPosts',
array('publicBehaviorPostExpired', 'coreBlogGetPosts')
['publicBehaviorPostExpired', 'coreBlogGetPosts']
);
$core->tpl->addBlock(
'EntryExpiredIf',
array('tplPostExpired', 'EntryExpiredIf')
['tplPostExpired', 'EntryExpiredIf']
);
$core->tpl->addValue(
'EntryExpiredDate',
array('tplPostExpired', 'EntryExpiredDate')
['tplPostExpired', 'EntryExpiredDate']
);
$core->tpl->addValue(
'EntryExpiredTime',
array('tplPostExpired', 'EntryExpiredTime')
['tplPostExpired', 'EntryExpiredTime']
);
/**
@ -65,19 +62,18 @@ class publicBehaviorPostExpired
{
# Get expired dates and post_id
$posts = $core->con->select(
'SELECT P.post_id, P.post_tz, META.meta_id '.
'FROM '.$core->prefix.'post P '.
'INNER JOIN '.$core->prefix.'meta META '.
'ON META.post_id = P.post_id '.
"WHERE blog_id = '".$core->con->escape($core->blog->id)."' ".
'SELECT P.post_id, P.post_tz, META.meta_id ' .
'FROM ' . $core->prefix . 'post P ' .
'INNER JOIN ' . $core->prefix . 'meta META ' .
'ON META.post_id = P.post_id ' .
"WHERE blog_id = '" . $core->con->escape($core->blog->id) . "' " .
// Removed for quick compatibility with some plugins
//"AND P.post_type = 'post' ".
//"AND P.post_type = 'post' " .
"AND META.meta_type = 'post_expired' "
);
# No expired date
if ($posts->isEmpty()) {
return null;
}
@ -85,7 +81,7 @@ class publicBehaviorPostExpired
$now = dt::toUTC(time());
# Prepared post cursor
$post_cur = $core->con->openCursor($core->prefix.'post');
$post_cur = $core->con->openCursor($core->prefix . 'post');
# Loop through marked posts
$updated = false;
@ -97,8 +93,7 @@ class publicBehaviorPostExpired
# Check if post is outdated
$now_tz = $now + dt::getTimeOffset($posts->post_tz, $now);
$meta_tz = strtotime($post_expired['date']);
if ($now_tz > $meta_tz)
{
if ($now_tz > $meta_tz) {
# Delete meta for expired date
$core->auth->sudo(
array($core->meta, 'delPostMeta'),
@ -111,8 +106,7 @@ class publicBehaviorPostExpired
$post_cur->post_upddt = date('Y-m-d H:i:s', $now_tz);
# Loop through actions
foreach($post_expired as $k => $v)
{
foreach($post_expired as $k => $v) {
if (empty($v)) {
continue;
}
@ -147,8 +141,8 @@ class publicBehaviorPostExpired
# Update post
$post_cur->update(
'WHERE post_id = '.$posts->post_id.' '.
"AND blog_id = '".$core->con->escape($core->blog->id)."' "
'WHERE post_id = ' . $posts->post_id . ' ' .
"AND blog_id = '" . $core->con->escape($core->blog->id) . "' "
);
$updated = true;
@ -190,12 +184,11 @@ class rsExtPostExpiredPublic extends rsExtPost
if (!$rs->postexpired[$rs->post_id]) { //memory
$rs_date = $rs->core->meta->getMetadata(array(
'meta_type' => 'post_expired',
'post_id' => $rs->post_id,
'limit' => 1
'post_id'=> $rs->post_id,
'limit'=> 1
));
if ($rs_date->isEmpty()) {
return null;
}
@ -228,15 +221,14 @@ class tplPostExpired
if (isset($attr['has_date'])) {
$sign = (boolean) $attr['has_date'] ? '!' : '=';
$if[] = '(null '.$sign.'== $_ctx->posts->postExpiredDate())';
}
else {
$if[] = '(null ' . $sign . '== $_ctx->posts->postExpiredDate())';
} else {
$if[] = '(null !== $_ctx->posts->postExpiredDate())';
}
return
"<?php if(".implode(' '.$operator.' ', $if).") : ?>\n".
$content.
"<?php if(" . implode(' ' . $operator . ' ', $if) . ") : ?>\n" .
$content .
"<?php endif; ?>\n";
}
@ -251,16 +243,17 @@ class tplPostExpired
addslashes($attr['format']) : '';
$f = $GLOBALS['core']->tpl->getFilters($attr);
if (!empty($attr['rfc822']))
$res = sprintf($f,"dt::rfc822(strtotime(\$_ctx->posts->postExpiredDate()),\$_ctx->posts->post_tz)");
elseif (!empty($attr['iso8601']))
$res = sprintf($f,"dt::iso8601(strtotime(\$_ctx->posts->postExpiredDate(),\$_ctx->posts->post_tz)");
elseif ($format)
$res = sprintf($f,"dt::dt2str('".$format."',\$_ctx->posts->postExpiredDate())");
else
$res = sprintf($f,"dt::dt2str(\$core->blog->settings->system->date_format,\$_ctx->posts->postExpiredDate())");
if (!empty($attr['rfc822'])) {
$res = sprintf($f, "dt::rfc822(strtotime(\$_ctx->posts->postExpiredDate()),\$_ctx->posts->post_tz)");
} elseif (!empty($attr['iso8601'])) {
$res = sprintf($f, "dt::iso8601(strtotime(\$_ctx->posts->postExpiredDate(),\$_ctx->posts->post_tz)");
} elseif ($format) {
$res = sprintf($f, "dt::dt2str('" . $format . "',\$_ctx->posts->postExpiredDate())");
} else {
$res = sprintf($f, "dt::dt2str(\$core->blog->settings->system->date_format,\$_ctx->posts->postExpiredDate())");
}
return '<?php if (null !== $_ctx->posts->postExpiredDate()) { echo '.$res.'; } ?>';
return '<?php if (null !== $_ctx->posts->postExpiredDate()) { echo ' . $res . '; } ?>';
}
/**
@ -270,7 +263,13 @@ class tplPostExpired
*/
public static function EntryExpiredTime($attr)
{
return '<?php if (null !== $_ctx->posts->postExpiredDate()) { echo '.sprintf($GLOBALS['core']->tpl->getFilters($attr),"dt::dt2str(".(!empty($attr['format']) ? "'".addslashes($attr['format'])."'" : "\$core->blog->settings->system->time_format").",\$_ctx->posts->postExpiredDate())").'; } ?>';
return
'<?php if (null !== $_ctx->posts->postExpiredDate()) { echo ' . sprintf(
$GLOBALS['core']->tpl->getFilters($attr), "dt::dt2str(" .
(!empty($attr['format']) ?
"'" . addslashes($attr['format']) . "'" : "\$core->blog->settings->system->time_format"
) . ",\$_ctx->posts->postExpiredDate())"
) . '; } ?>';
}
/**