update license and fix PSR2 codding style
This commit is contained in:
parent
16ffcf67d3
commit
e7a3cb0fa1
@ -1,53 +1,45 @@
|
|||||||
postExpired xxxx.xx.xx
|
postExpired xxxx.xx.xx
|
||||||
===========================================================
|
|
||||||
* Not fix: Wrong timezone on admin vs public expired date
|
* 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
|
postExpired 2013.11.13
|
||||||
===========================================================
|
|
||||||
* Fixed wrong field name for category
|
* Fixed wrong field name for category
|
||||||
|
|
||||||
postExpired 2013.11.03
|
postExpired 2013.11.03
|
||||||
===========================================================
|
|
||||||
* Switch to Dotclear 2.6
|
* Switch to Dotclear 2.6
|
||||||
* Use new posts actions
|
* Use new posts actions
|
||||||
* Save all options in one meta
|
* Save all options in one meta
|
||||||
* Limit plugin to contentadmin
|
* Limit plugin to contentadmin
|
||||||
|
|
||||||
postExpired 2013.06.30
|
postExpired 2013.06.30
|
||||||
===========================================================
|
|
||||||
* Fixed post_type and posts_actions
|
* Fixed post_type and posts_actions
|
||||||
|
|
||||||
postExpired 0.5 - 2010-08-17
|
postExpired 0.5 - 2010-08-17
|
||||||
===========================================================
|
|
||||||
* Added compatibility with plugins 'pages' and 'muppet'
|
* Added compatibility with plugins 'pages' and 'muppet'
|
||||||
|
|
||||||
postExpired 0.4 - 2010-08-03
|
postExpired 0.4 - 2010-08-03
|
||||||
===========================================================
|
|
||||||
* Added actions (comments, trackbacks) (closes #525)
|
* Added actions (comments, trackbacks) (closes #525)
|
||||||
* Speed up public part (less sql resquests)
|
* Speed up public part (less sql resquests)
|
||||||
* Fixed typo
|
* Fixed typo
|
||||||
|
|
||||||
postExpired 0.3.1 - 2010-06-21
|
postExpired 0.3.1 - 2010-06-21
|
||||||
===========================================================
|
|
||||||
* Fixed user rights
|
* Fixed user rights
|
||||||
* Fixed (again) PHP 5.3 compatibility
|
* Fixed (again) PHP 5.3 compatibility
|
||||||
* Fixed typo
|
* Fixed typo
|
||||||
|
|
||||||
postExpired 0.3 - 2010-06-08
|
postExpired 0.3 - 2010-06-08
|
||||||
===========================================================
|
|
||||||
* Switched to DC 2.2 (settings,meta)
|
* Switched to DC 2.2 (settings,meta)
|
||||||
|
|
||||||
postExpired 0.2.1 - 2010-05-28
|
postExpired 0.2.1 - 2010-05-28
|
||||||
===========================================================
|
|
||||||
* Fixed DC 2.1.7 settings bugs
|
* Fixed DC 2.1.7 settings bugs
|
||||||
|
|
||||||
postExpired 0.2 - 2010-04-14
|
postExpired 0.2 - 2010-04-14
|
||||||
===========================================================
|
|
||||||
* Added actions choice (status,category,selected)
|
* Added actions choice (status,category,selected)
|
||||||
* Added template block and value
|
* Added template block and value
|
||||||
* Added behaviors to open choices
|
* Added behaviors to open choices
|
||||||
* Enhanced db resquest on public side
|
* Enhanced db resquest on public side
|
||||||
|
|
||||||
postExpired 0.1 - 2010-04-10
|
postExpired 0.1 - 2010-04-10
|
||||||
===========================================================
|
|
||||||
* First lab release
|
* First lab release
|
@ -30,3 +30,9 @@ Notes:
|
|||||||
|
|
||||||
* Only one expired date per post is supported
|
* Only one expired date per post is supported
|
||||||
* Expired dates are checked from public home page and feed page
|
* 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)
|
822
_admin.php
822
_admin.php
@ -3,8 +3,7 @@
|
|||||||
#
|
#
|
||||||
# This file is part of postExpired, a plugin for Dotclear 2.
|
# This file is part of postExpired, a plugin for Dotclear 2.
|
||||||
#
|
#
|
||||||
# Copyright (c) 2009-2013 Jean-Christian Denis and contributors
|
# Copyright (c) 2009-2021 Jean-Christian Denis and contributors
|
||||||
# contact@jcdenis.fr http://jcd.lv
|
|
||||||
#
|
#
|
||||||
# Licensed under the GPL version 2.0 license.
|
# Licensed under the GPL version 2.0 license.
|
||||||
# A copy of this license is available in LICENSE file or at
|
# A copy of this license is available in LICENSE file or at
|
||||||
@ -13,70 +12,67 @@
|
|||||||
# -- END LICENSE BLOCK ------------------------------------
|
# -- END LICENSE BLOCK ------------------------------------
|
||||||
|
|
||||||
if (!defined('DC_CONTEXT_ADMIN')) {
|
if (!defined('DC_CONTEXT_ADMIN')) {
|
||||||
|
return null;
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Check plugin version
|
# Check plugin version
|
||||||
if ($core->getVersion('postExpired') != $core->plugins->moduleInfo('postExpired', 'version')) {
|
if ($core->getVersion('postExpired') != $core->plugins->moduleInfo('postExpired', 'version')) {
|
||||||
|
return null;
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Check user right
|
# Check user right
|
||||||
if (!$core->auth->check('contentadmin', $core->blog->id)) {
|
if (!$core->auth->check('contentadmin', $core->blog->id)) {
|
||||||
|
return null;
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Admin behaviors
|
# Admin behaviors
|
||||||
$core->addBehavior(
|
$core->addBehavior(
|
||||||
'adminPostsActionsPage',
|
'adminPostsActionsPage',
|
||||||
array('adminBehaviorPostExpired', 'adminPostsActionsPage')
|
['adminBehaviorPostExpired', 'adminPostsActionsPage']
|
||||||
);
|
);
|
||||||
$core->addBehavior(
|
$core->addBehavior(
|
||||||
'adminPagesActionsPage',
|
'adminPagesActionsPage',
|
||||||
array('adminBehaviorPostExpired', 'adminPostsActionsPage')
|
['adminBehaviorPostExpired', 'adminPostsActionsPage']
|
||||||
);
|
);
|
||||||
$core->addBehavior(
|
$core->addBehavior(
|
||||||
'adminPostHeaders',
|
'adminPostHeaders',
|
||||||
array('adminBehaviorPostExpired', 'adminPostHeaders')
|
['adminBehaviorPostExpired', 'adminPostHeaders']
|
||||||
);
|
);
|
||||||
$core->addBehavior(
|
$core->addBehavior(
|
||||||
'adminPageHeaders',
|
'adminPageHeaders',
|
||||||
array('adminBehaviorPostExpired', 'adminPostHeaders')
|
['adminBehaviorPostExpired', 'adminPostHeaders']
|
||||||
);
|
);
|
||||||
$core->addBehavior(
|
$core->addBehavior(
|
||||||
'adminPostFormItems',
|
'adminPostFormItems',
|
||||||
array('adminBehaviorPostExpired', 'adminPostFormItems')
|
['adminBehaviorPostExpired', 'adminPostFormItems']
|
||||||
);
|
);
|
||||||
$core->addBehavior(
|
$core->addBehavior(
|
||||||
'adminPageFormItems',
|
'adminPageFormItems',
|
||||||
array('adminBehaviorPostExpired', 'adminPostFormItems')
|
['adminBehaviorPostExpired', 'adminPostFormItems']
|
||||||
);
|
);
|
||||||
$core->addBehavior(
|
$core->addBehavior(
|
||||||
'adminBeforePostDelete',
|
'adminBeforePostDelete',
|
||||||
array('adminBehaviorPostExpired', 'adminBeforePostDelete')
|
['adminBehaviorPostExpired', 'adminBeforePostDelete']
|
||||||
);
|
);
|
||||||
$core->addBehavior(
|
$core->addBehavior(
|
||||||
'adminBeforePageDelete',
|
'adminBeforePageDelete',
|
||||||
array('adminBehaviorPostExpired', 'adminBeforePostDelete')
|
['adminBehaviorPostExpired', 'adminBeforePostDelete']
|
||||||
);
|
);
|
||||||
$core->addBehavior(
|
$core->addBehavior(
|
||||||
'adminAfterPostUpdate',
|
'adminAfterPostUpdate',
|
||||||
array('adminBehaviorPostExpired', 'adminAfterPostSave')
|
['adminBehaviorPostExpired', 'adminAfterPostSave']
|
||||||
);
|
);
|
||||||
$core->addBehavior(
|
$core->addBehavior(
|
||||||
'adminAfterPageUpdate',
|
'adminAfterPageUpdate',
|
||||||
array('adminBehaviorPostExpired', 'adminAfterPostSave')
|
['adminBehaviorPostExpired', 'adminAfterPostSave']
|
||||||
);
|
);
|
||||||
$core->addBehavior(
|
$core->addBehavior(
|
||||||
'adminAfterPostCreate',
|
'adminAfterPostCreate',
|
||||||
array('adminBehaviorPostExpired', 'adminAfterPostSave')
|
['adminBehaviorPostExpired', 'adminAfterPostSave']
|
||||||
);
|
);
|
||||||
$core->addBehavior(
|
$core->addBehavior(
|
||||||
'adminAfterPageCreate',
|
'adminAfterPageCreate',
|
||||||
array('adminBehaviorPostExpired', 'adminAfterPostSave')
|
['adminBehaviorPostExpired', 'adminAfterPostSave']
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -86,430 +82,424 @@ $core->addBehavior(
|
|||||||
*/
|
*/
|
||||||
class adminBehaviorPostExpired
|
class adminBehaviorPostExpired
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Add actions to posts page combo
|
* Add actions to posts page combo
|
||||||
*
|
*
|
||||||
* @param dcCore $core dcCore instance
|
* @param dcCore $core dcCore instance
|
||||||
* @param dcPostsActionsPage $ap dcPostsActionsPage instance
|
* @param dcPostsActionsPage $ap dcPostsActionsPage instance
|
||||||
*/
|
*/
|
||||||
public static function adminPostsActionsPage(dcCore $core, dcPostsActionsPage $pa)
|
public static function adminPostsActionsPage(dcCore $core, dcPostsActionsPage $pa)
|
||||||
{
|
{
|
||||||
$pa->addAction(
|
$pa->addAction(
|
||||||
array(
|
array(
|
||||||
__('Expired entries') => array(
|
__('Expired entries') => array(
|
||||||
__('Add expired date') => 'post_expired_add'
|
__('Add expired date') => 'post_expired_add'
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
array('adminBehaviorPostExpired', 'callbackAdd')
|
array('adminBehaviorPostExpired', 'callbackAdd')
|
||||||
);
|
);
|
||||||
|
|
||||||
$pa->addAction(
|
$pa->addAction(
|
||||||
array(
|
array(
|
||||||
__('Expired entries') => array(
|
__('Expired entries') => array(
|
||||||
__('Remove expired date') => 'post_expired_remove'
|
__('Remove expired date') => 'post_expired_remove'
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
array('adminBehaviorPostExpired', 'callbackRemove')
|
array('adminBehaviorPostExpired', 'callbackRemove')
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add javascript for date field and toggle
|
* Add javascript for date field and toggle
|
||||||
*
|
*
|
||||||
* @return string HTML head
|
* @return string HTML head
|
||||||
*/
|
*/
|
||||||
public static function adminPostHeaders()
|
public static function adminPostHeaders()
|
||||||
{
|
{
|
||||||
return dcPage::jsLoad('index.php?pf=postExpired/js/postexpired.js');
|
return dcPage::jsLoad('index.php?pf=postExpired/js/postexpired.js');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add form to post sidebar
|
* Add form to post sidebar
|
||||||
*
|
*
|
||||||
* @param ArrayObject $main_items Main items
|
* @param ArrayObject $main_items Main items
|
||||||
* @param ArrayObject $sidebar_items Sidebar items
|
* @param ArrayObject $sidebar_items Sidebar items
|
||||||
* @param record $post Post record or null
|
* @param record $post Post record or null
|
||||||
*/
|
*/
|
||||||
public static function adminPostFormItems(ArrayObject $main_items, ArrayObject $sidebar_items, $post)
|
public static function adminPostFormItems(ArrayObject $main_items, ArrayObject $sidebar_items, $post)
|
||||||
{
|
{
|
||||||
if ($post === null) {
|
if ($post === null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
$sidebar_items['post_expired'] = array(
|
||||||
}
|
'title' => __('Expired date'),
|
||||||
|
'items' => self::fieldsPostExpired(
|
||||||
|
$GLOBALS['core'],
|
||||||
|
$post->post_type,
|
||||||
|
$post->post_id
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
$sidebar_items['post_expired'] = array(
|
/**
|
||||||
'title' => __('Expired date'),
|
* Delete expired date on post edition
|
||||||
'items' => self::fieldsPostExpired(
|
*
|
||||||
$GLOBALS['core'],
|
* @param integer $post_id Post id
|
||||||
$post->post_type,
|
*/
|
||||||
$post->post_id
|
public static function adminBeforePostDelete($post_id)
|
||||||
)
|
{
|
||||||
);
|
self::delPostExpired($GLOBALS['core'], $post_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete expired date on post edition
|
* Add expired date on post edition
|
||||||
*
|
*
|
||||||
* @param integer $post_id Post id
|
* @param cursor $cur Current post cursor
|
||||||
*/
|
* @param integer $post_id Post id
|
||||||
public static function adminBeforePostDelete($post_id)
|
*/
|
||||||
{
|
public static function adminAfterPostSave(cursor $cur, $post_id)
|
||||||
self::delPostExpired($GLOBALS['core'], $post_id);
|
{
|
||||||
}
|
global $core;
|
||||||
|
|
||||||
/**
|
self::delPostExpired($core, $post_id);
|
||||||
* Add expired date on post edition
|
|
||||||
*
|
|
||||||
* @param cursor $cur Current post cursor
|
|
||||||
* @param integer $post_id Post id
|
|
||||||
*/
|
|
||||||
public static function adminAfterPostSave(cursor $cur, $post_id)
|
|
||||||
{
|
|
||||||
global $core;
|
|
||||||
|
|
||||||
self::delPostExpired($core, $post_id);
|
if (!empty($_POST['post_expired_date'])
|
||||||
|
&& (!empty($_POST['post_expired_status'])
|
||||||
|
|| !empty($_POST['post_expired_category'])
|
||||||
|
|| !empty($_POST['post_expired_selected'])
|
||||||
|
|| !empty($_POST['post_expired_comment'])
|
||||||
|
|| !empty($_POST['post_expired_trackback']))) {
|
||||||
|
self::setPostExpired($core, $post_id, $_POST);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!empty($_POST['post_expired_date'])
|
/**
|
||||||
&& (!empty($_POST['post_expired_status'])
|
* Posts actions callback to add expired date
|
||||||
|| !empty($_POST['post_expired_category'])
|
*
|
||||||
|| !empty($_POST['post_expired_selected'])
|
* @param dcCore $core dcCore instance
|
||||||
|| !empty($_POST['post_expired_comment'])
|
* @param dcPostsActionsPage $pa dcPostsActionsPage instance
|
||||||
|| !empty($_POST['post_expired_trackback']))
|
* @param ArrayObject $post _POST actions
|
||||||
) {
|
*/
|
||||||
self::setPostExpired($core, $post_id, $_POST);
|
public static function callbackAdd(dcCore $core, dcPostsActionsPage $pa, ArrayObject $post)
|
||||||
}
|
{
|
||||||
}
|
# No entry
|
||||||
|
$posts_ids = $pa->getIDs();
|
||||||
|
if (empty($posts_ids)) {
|
||||||
|
throw new Exception(__('No entry selected'));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
# Add epired date
|
||||||
* Posts actions callback to add expired date
|
if (!empty($post['post_expired_date'])
|
||||||
*
|
&& (!empty($post['post_expired_status'])
|
||||||
* @param dcCore $core dcCore instance
|
|| !empty($post['post_expired_category'])
|
||||||
* @param dcPostsActionsPage $pa dcPostsActionsPage instance
|
|| !empty($post['post_expired_selected'])
|
||||||
* @param ArrayObject $post _POST actions
|
|| !empty($post['post_expired_comment'])
|
||||||
*/
|
|| !empty($post['post_expired_trackback']))) {
|
||||||
public static function callbackAdd(dcCore $core, dcPostsActionsPage $pa, ArrayObject $post)
|
foreach($posts_ids as $post_id) {
|
||||||
{
|
self::delPostExpired($core, $post_id);
|
||||||
# No entry
|
self::setPostExpired($core, $post_id, $post);
|
||||||
$posts_ids = $pa->getIDs();
|
}
|
||||||
if (empty($posts_ids)) {
|
|
||||||
throw new Exception(__('No entry selected'));
|
|
||||||
}
|
|
||||||
|
|
||||||
# Add epired date
|
dcPage::addSuccessNotice(__('Expired date added.'));
|
||||||
if (!empty($post['post_expired_date'])
|
$pa->redirect(true);
|
||||||
&& (!empty($post['post_expired_status'])
|
|
||||||
|| !empty($post['post_expired_category'])
|
|
||||||
|| !empty($post['post_expired_selected'])
|
|
||||||
|| !empty($post['post_expired_comment'])
|
|
||||||
|| !empty($post['post_expired_trackback']))
|
|
||||||
) {
|
|
||||||
foreach($posts_ids as $post_id) {
|
|
||||||
self::delPostExpired($core, $post_id);
|
|
||||||
self::setPostExpired($core, $post_id, $post);
|
|
||||||
}
|
|
||||||
|
|
||||||
dcPage::addSuccessNotice(__('Expired date added.'));
|
# Display form
|
||||||
$pa->redirect(true);
|
} else {
|
||||||
}
|
# Get records to know post type
|
||||||
|
$posts = $pa->getRS();
|
||||||
|
|
||||||
# Display form
|
$pa->beginPage(
|
||||||
else {
|
dcPage::breadcrumb(array(
|
||||||
# Get records to know post type
|
html::escapeHTML($core->blog->name) => '',
|
||||||
$posts = $pa->getRS();
|
$pa->getCallerTitle() => $pa->getRedirection(true),
|
||||||
|
__('Add expired date to this selection') => ''
|
||||||
|
)),
|
||||||
|
dcPage::jsDatePicker() .
|
||||||
|
self::adminPostHeaders()
|
||||||
|
);
|
||||||
|
|
||||||
$pa->beginPage(
|
echo
|
||||||
dcPage::breadcrumb(array(
|
'<form action="' . $pa->getURI() . '" method="post">' .
|
||||||
html::escapeHTML($core->blog->name) => '',
|
$pa->getCheckboxes() .
|
||||||
$pa->getCallerTitle() => $pa->getRedirection(true),
|
|
||||||
__('Add expired date to this selection') => ''
|
|
||||||
)),
|
|
||||||
dcPage::jsDatePicker().
|
|
||||||
self::adminPostHeaders()
|
|
||||||
);
|
|
||||||
|
|
||||||
echo
|
implode('', self::fieldsPostExpired($core, $posts->post_type)) .
|
||||||
'<form action="'.$pa->getURI().'" method="post">'.
|
|
||||||
$pa->getCheckboxes().
|
|
||||||
|
|
||||||
implode('', self::fieldsPostExpired($core, $posts->post_type)).
|
$core->formNonce() .
|
||||||
|
$pa->getHiddenFields() .
|
||||||
|
form::hidden(array('action'), 'post_expired_add') .
|
||||||
|
'<input type="submit" value="' . __('Save') . '" /></p>' .
|
||||||
|
'</form>';
|
||||||
|
|
||||||
$core->formNonce().
|
$pa->endPage();
|
||||||
$pa->getHiddenFields().
|
}
|
||||||
form::hidden(array('action'), 'post_expired_add').
|
}
|
||||||
'<input type="submit" value="'.__('Save').'" /></p>'.
|
|
||||||
'</form>';
|
|
||||||
|
|
||||||
$pa->endPage();
|
/**
|
||||||
}
|
* Posts actions callback to add expired date
|
||||||
}
|
*
|
||||||
|
* @param dcCore $core dcCore instance
|
||||||
|
* @param dcPostsActionsPage $pa dcPostsActionsPage instance
|
||||||
|
* @param ArrayObject $post _POST actions
|
||||||
|
*/
|
||||||
|
public static function callbackRemove(dcCore $core, dcPostsActionsPage $pa, ArrayObject $post)
|
||||||
|
{
|
||||||
|
# No entry
|
||||||
|
$posts_ids = $pa->getIDs();
|
||||||
|
if (empty($posts_ids)) {
|
||||||
|
throw new Exception(__('No entry selected'));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
# Delete expired date
|
||||||
* Posts actions callback to add expired date
|
foreach($posts_ids as $post_id) {
|
||||||
*
|
self::delPostExpired($core, $post_id);
|
||||||
* @param dcCore $core dcCore instance
|
}
|
||||||
* @param dcPostsActionsPage $pa dcPostsActionsPage instance
|
|
||||||
* @param ArrayObject $post _POST actions
|
|
||||||
*/
|
|
||||||
public static function callbackRemove(dcCore $core, dcPostsActionsPage $pa, ArrayObject $post)
|
|
||||||
{
|
|
||||||
# No entry
|
|
||||||
$posts_ids = $pa->getIDs();
|
|
||||||
if (empty($posts_ids)) {
|
|
||||||
throw new Exception(__('No entry selected'));
|
|
||||||
}
|
|
||||||
|
|
||||||
# Delete expired date
|
dcPage::addSuccessNotice(__('Expired date deleted.'));
|
||||||
foreach($posts_ids as $post_id) {
|
$pa->redirect(true);
|
||||||
self::delPostExpired($core, $post_id);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
dcPage::addSuccessNotice(__('Expired date deleted.'));
|
/**
|
||||||
$pa->redirect(true);
|
* Delete expired date
|
||||||
}
|
*
|
||||||
|
* @param dcCore $core dcCore instance
|
||||||
|
* @param integer $post_id Post id
|
||||||
|
*/
|
||||||
|
protected static function delPostExpired(dcCore $core, $post_id)
|
||||||
|
{
|
||||||
|
$core->meta->delPostMeta($post_id, 'post_expired');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete expired date
|
* Save expired date
|
||||||
*
|
*
|
||||||
* @param dcCore $core dcCore instance
|
* @param dcCore $core dcCore instance
|
||||||
* @param integer $post_id Post id
|
* @param integer $post_id Post id
|
||||||
*/
|
* @param array $post _POST fields
|
||||||
protected static function delPostExpired(dcCore $core, $post_id)
|
*/
|
||||||
{
|
protected static function setPostExpired(dcCore $core, $post_id, $post)
|
||||||
$core->meta->delPostMeta($post_id, 'post_expired');
|
{
|
||||||
}
|
$post_expired = array(
|
||||||
|
'status'=> '',
|
||||||
|
'category'=> '',
|
||||||
|
'selected'=> '',
|
||||||
|
'comment'=> '',
|
||||||
|
'trackback' => '',
|
||||||
|
'date'=> date(
|
||||||
|
'Y-m-d H:i:00',
|
||||||
|
strtotime($post['post_expired_date'])
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
/**
|
if (!empty($post['post_expired_status'])) {
|
||||||
* Save expired date
|
$post_expired['status'] =
|
||||||
*
|
(string) $post['post_expired_status'];
|
||||||
* @param dcCore $core dcCore instance
|
}
|
||||||
* @param integer $post_id Post id
|
if (!empty($post['post_expired_category'])) {
|
||||||
* @param array $post _POST fields
|
$post_expired['category'] =
|
||||||
*/
|
(string) $post['post_expired_category'];
|
||||||
protected static function setPostExpired(dcCore $core, $post_id, $post)
|
}
|
||||||
{
|
if (!empty($post['post_expired_selected'])) {
|
||||||
$post_expired = array(
|
$post_expired['selected'] =
|
||||||
'status' => '',
|
(string) $post['post_expired_selected'];
|
||||||
'category' => '',
|
}
|
||||||
'selected' => '',
|
if (!empty($post['post_expired_comment'])) {
|
||||||
'comment' => '',
|
$post_expired['comment'] =
|
||||||
'trackback' => '',
|
(string) $post['post_expired_comment'];
|
||||||
'date' => date(
|
}
|
||||||
'Y-m-d H:i:00',
|
if (!empty($post['post_expired_trackback'])) {
|
||||||
strtotime($post['post_expired_date'])
|
$post_expired['trackback'] =
|
||||||
)
|
(string) $post['post_expired_trackback'];
|
||||||
);
|
}
|
||||||
|
|
||||||
if (!empty($post['post_expired_status'])) {
|
$core->meta->setPostMeta(
|
||||||
$post_expired['status'] =
|
$post_id,
|
||||||
(string) $post['post_expired_status'];
|
'post_expired',
|
||||||
}
|
encodePostExpired($post_expired)
|
||||||
if (!empty($post['post_expired_category'])) {
|
);
|
||||||
$post_expired['category'] =
|
}
|
||||||
(string) $post['post_expired_category'];
|
|
||||||
}
|
|
||||||
if (!empty($post['post_expired_selected'])) {
|
|
||||||
$post_expired['selected'] =
|
|
||||||
(string) $post['post_expired_selected'];
|
|
||||||
}
|
|
||||||
if (!empty($post['post_expired_comment'])) {
|
|
||||||
$post_expired['comment'] =
|
|
||||||
(string) $post['post_expired_comment'];
|
|
||||||
}
|
|
||||||
if (!empty($post['post_expired_trackback'])) {
|
|
||||||
$post_expired['trackback'] =
|
|
||||||
(string) $post['post_expired_trackback'];
|
|
||||||
}
|
|
||||||
|
|
||||||
$core->meta->setPostMeta(
|
/**
|
||||||
$post_id,
|
* Expired date form fields
|
||||||
'post_expired',
|
*
|
||||||
encodePostExpired($post_expired)
|
* @param dcCore $core dcCore instance
|
||||||
);
|
* @param string $post_type Posts type
|
||||||
}
|
* @return array Array of HTML form fields
|
||||||
|
*/
|
||||||
|
protected static function fieldsPostExpired(dcCore $core, $post_type, $post_id = null)
|
||||||
|
{
|
||||||
|
$fields = $post_expired = array();
|
||||||
|
|
||||||
/**
|
if ($post_id) {
|
||||||
* Expired date form fields
|
|
||||||
*
|
|
||||||
* @param dcCore $core dcCore instance
|
|
||||||
* @param string $post_type Posts type
|
|
||||||
* @return array Array of HTML form fields
|
|
||||||
*/
|
|
||||||
protected static function fieldsPostExpired(dcCore $core, $post_type, $post_id=null)
|
|
||||||
{
|
|
||||||
$fields = $post_expired = array();
|
|
||||||
|
|
||||||
if ($post_id) {
|
$rs = $core->meta->getMeta(
|
||||||
|
'post_expired',
|
||||||
|
1,
|
||||||
|
null,
|
||||||
|
$post_id
|
||||||
|
);
|
||||||
|
|
||||||
$rs = $core->meta->getMeta(
|
if (!$rs->isEmpty()) {
|
||||||
'post_expired',
|
$post_expired = decodePostExpired($rs->meta_id);
|
||||||
1,
|
}
|
||||||
null,
|
}
|
||||||
$post_id
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!$rs->isEmpty()) {
|
$fields['post_expired_date'] =
|
||||||
$post_expired = decodePostExpired($rs->meta_id);
|
'<p><label for="post_expired_date">' .
|
||||||
}
|
__('Date:') . '</label>' .
|
||||||
}
|
form::field(
|
||||||
|
'post_expired_date',
|
||||||
|
16,
|
||||||
|
16,
|
||||||
|
empty($post_expired['date']) ?
|
||||||
|
'' : $post_expired['date']
|
||||||
|
) . '</p>';
|
||||||
|
|
||||||
$fields['post_expired_date'] =
|
$fields['post_expired_status'] =
|
||||||
'<p><label for="post_expired_date">'.
|
'<h5>' . __('On this date, change:') . '</h5>' .
|
||||||
__('Date:').'</label>'.
|
'<p><label for="post_expired_status">' .
|
||||||
form::field(
|
__('Status:') . '</label>' .
|
||||||
'post_expired_date',
|
form::combo(
|
||||||
16,
|
'post_expired_status',
|
||||||
16,
|
self::statusCombo(),
|
||||||
empty($post_expired['date']) ?
|
empty($post_expired['status']) ?
|
||||||
'' : $post_expired['date']
|
'' : $post_expired['status']
|
||||||
).'</p>';
|
) . '</p>';
|
||||||
|
|
||||||
$fields['post_expired_status'] =
|
if ($post_type == 'post') {
|
||||||
'<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>';
|
|
||||||
|
|
||||||
if ($post_type == 'post') {
|
$fields['post_expired_category'] =
|
||||||
|
'<p><label for="post_expired_category">' .
|
||||||
|
__('Category:') . '</label>' .
|
||||||
|
form::combo(
|
||||||
|
'post_expired_category',
|
||||||
|
self::categoriesCombo(
|
||||||
|
$core->blog->getCategories(
|
||||||
|
array('post_type' => 'post')
|
||||||
|
)
|
||||||
|
),
|
||||||
|
empty($post_expired['category']) ?
|
||||||
|
'' : $post_expired['category']
|
||||||
|
) . '</p>';
|
||||||
|
|
||||||
$fields['post_expired_category'] =
|
$fields['post_expired_selected'] =
|
||||||
'<p><label for="post_expired_category">'.
|
'<p><label for="post_expired_selected">' .
|
||||||
__('Category:').'</label>'.
|
__('Selection:') . '</label>' .
|
||||||
form::combo(
|
form::combo(
|
||||||
'post_expired_category',
|
'post_expired_selected',
|
||||||
self::categoriesCombo(
|
self::selectedCombo(),
|
||||||
$core->blog->getCategories(
|
empty($post_expired['selected']) ?
|
||||||
array('post_type' => 'post')
|
'' : $post_expired['selected']
|
||||||
)
|
) . '</p>';
|
||||||
),
|
}
|
||||||
empty($post_expired['category']) ?
|
|
||||||
'' : $post_expired['category']
|
|
||||||
).'</p>';
|
|
||||||
|
|
||||||
$fields['post_expired_selected'] =
|
$fields['post_expired_comment'] =
|
||||||
'<p><label for="post_expired_selected">'.
|
'<p><label for="post_expired_comment">' .
|
||||||
__('Selection:').'</label>'.
|
__('Comments status:') . '</label>' .
|
||||||
form::combo(
|
form::combo(
|
||||||
'post_expired_selected',
|
'post_expired_comment',
|
||||||
self::selectedCombo(),
|
self::commentCombo(),
|
||||||
empty($post_expired['selected']) ?
|
empty($post_expired['comment']) ?
|
||||||
'' : $post_expired['selected']
|
'' : $post_expired['comment']
|
||||||
).'</p>';
|
) . '</p>';
|
||||||
}
|
|
||||||
|
|
||||||
$fields['post_expired_comment'] =
|
$fields['post_expired_trackback'] =
|
||||||
'<p><label for="post_expired_comment">'.
|
'<p><label for="post_expired_trackback">' .
|
||||||
__('Comments status:').'</label>'.
|
__('Trackbacks status:') . '</label>' .
|
||||||
form::combo(
|
form::combo(
|
||||||
'post_expired_comment',
|
'post_expired_trackback',
|
||||||
self::commentCombo(),
|
self::trackbackCombo(),
|
||||||
empty($post_expired['comment']) ?
|
empty($post_expired['trackback']) ?
|
||||||
'' : $post_expired['comment']
|
'' : $post_expired['trackback']
|
||||||
).'</p>';
|
) . '</p>';
|
||||||
|
|
||||||
$fields['post_expired_trackback'] =
|
return $fields;
|
||||||
'<p><label for="post_expired_trackback">'.
|
}
|
||||||
__('Trackbacks status:').'</label>'.
|
|
||||||
form::combo(
|
|
||||||
'post_expired_trackback',
|
|
||||||
self::trackbackCombo(),
|
|
||||||
empty($post_expired['trackback']) ?
|
|
||||||
'' : $post_expired['trackback']
|
|
||||||
).'</p>';
|
|
||||||
|
|
||||||
return $fields;
|
/**
|
||||||
}
|
* Custom categories combo
|
||||||
|
*
|
||||||
|
* @param record $categories Categories recordset
|
||||||
|
* @return array Categorires combo
|
||||||
|
*/
|
||||||
|
protected static function categoriesCombo(record $categories)
|
||||||
|
{
|
||||||
|
# Getting categories
|
||||||
|
$categories_combo = array(
|
||||||
|
__('Not changed') => '',
|
||||||
|
__('Uncategorized') => '!'
|
||||||
|
);
|
||||||
|
try {
|
||||||
|
$categories = $GLOBALS['core']->blog->getCategories(
|
||||||
|
array('post_type' => 'post')
|
||||||
|
);
|
||||||
|
while ($categories->fetch()) {
|
||||||
|
$categories_combo[] = new formSelectOption(
|
||||||
|
str_repeat(' ', $categories->level - 1) . '• '. html::escapeHTML($categories->cat_title),
|
||||||
|
'!'.$categories->cat_id
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} catch (Exception $e) {
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
return $categories_combo;
|
||||||
* Custom categories combo
|
}
|
||||||
*
|
|
||||||
* @param record $categories Categories recordset
|
|
||||||
* @return array Categorires combo
|
|
||||||
*/
|
|
||||||
protected static function categoriesCombo(record $categories)
|
|
||||||
{
|
|
||||||
# Getting categories
|
|
||||||
$categories_combo = array(
|
|
||||||
__('Not changed') => '',
|
|
||||||
__('Uncategorized') => '!'
|
|
||||||
);
|
|
||||||
try {
|
|
||||||
$categories = $GLOBALS['core']->blog->getCategories(
|
|
||||||
array('post_type' => 'post')
|
|
||||||
);
|
|
||||||
while ($categories->fetch()) {
|
|
||||||
$categories_combo[] = new formSelectOption(
|
|
||||||
str_repeat(' ', $categories->level-1).'• '.html::escapeHTML($categories->cat_title),
|
|
||||||
'!'.$categories->cat_id
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception $e) {
|
|
||||||
|
|
||||||
return array();
|
/**
|
||||||
}
|
* Custom status combo
|
||||||
|
*
|
||||||
|
* @return array Status combo
|
||||||
|
*/
|
||||||
|
protected static function statusCombo()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
__('Not changed') => '',
|
||||||
|
__('Published') => '!1',
|
||||||
|
__('Pending') => '!-2',
|
||||||
|
__('Unpublished') => '!0'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return $categories_combo;
|
/**
|
||||||
}
|
* Custom selection combo
|
||||||
|
*
|
||||||
|
* @return array Selection combo
|
||||||
|
*/
|
||||||
|
protected static function selectedCombo()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
__('Not changed') => '',
|
||||||
|
__('Selected') => '!1',
|
||||||
|
__('Not selected') => '!0'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Custom status combo
|
* Custom comment status combo
|
||||||
*
|
*
|
||||||
* @return array Status combo
|
* @return array Comment status combo
|
||||||
*/
|
*/
|
||||||
protected static function statusCombo()
|
protected static function commentCombo()
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
__('Not changed') => '',
|
__('Not changed') => '',
|
||||||
__('Published') => '!1',
|
__('Opened') => '!1',
|
||||||
__('Pending') => '!-2',
|
__('Closed') => '!0'
|
||||||
__('Unpublished') => '!0'
|
);
|
||||||
);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Custom selection combo
|
* Custom trackback status combo
|
||||||
*
|
*
|
||||||
* @return array Selection combo
|
* @return array Trackback status combo
|
||||||
*/
|
*/
|
||||||
protected static function selectedCombo()
|
protected static function trackbackCombo()
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
__('Not changed') => '',
|
__('Not changed') => '',
|
||||||
__('Selected') => '!1',
|
__('Opened') => '!1',
|
||||||
__('Not selected') => '!0'
|
__('Closed') => '!0'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Custom comment status combo
|
|
||||||
*
|
|
||||||
* @return array Comment status combo
|
|
||||||
*/
|
|
||||||
protected static function commentCombo()
|
|
||||||
{
|
|
||||||
return array(
|
|
||||||
__('Not changed') => '',
|
|
||||||
__('Opened') => '!1',
|
|
||||||
__('Closed') => '!0'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Custom trackback status combo
|
|
||||||
*
|
|
||||||
* @return array Trackback status combo
|
|
||||||
*/
|
|
||||||
protected static function trackbackCombo()
|
|
||||||
{
|
|
||||||
return array(
|
|
||||||
__('Not changed') => '',
|
|
||||||
__('Opened') => '!1',
|
|
||||||
__('Closed') => '!0'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
34
_define.php
34
_define.php
@ -3,8 +3,7 @@
|
|||||||
#
|
#
|
||||||
# This file is part of postExpired, a plugin for Dotclear 2.
|
# This file is part of postExpired, a plugin for Dotclear 2.
|
||||||
#
|
#
|
||||||
# Copyright (c) 2009-2013 Jean-Christian Denis and contributors
|
# Copyright (c) 2009-2021 Jean-Christian Denis and contributors
|
||||||
# contact@jcdenis.fr http://jcd.lv
|
|
||||||
#
|
#
|
||||||
# Licensed under the GPL version 2.0 license.
|
# Licensed under the GPL version 2.0 license.
|
||||||
# A copy of this license is available in LICENSE file or at
|
# A copy of this license is available in LICENSE file or at
|
||||||
@ -12,23 +11,20 @@
|
|||||||
#
|
#
|
||||||
# -- END LICENSE BLOCK ------------------------------------
|
# -- END LICENSE BLOCK ------------------------------------
|
||||||
|
|
||||||
if (!defined('DC_RC_PATH')){return;}
|
if (!defined('DC_RC_PATH')) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
$this->registerModule(
|
$this->registerModule(
|
||||||
/* Name */
|
'Expired entries',
|
||||||
"Expired entries",
|
'Change entries options at a given date',
|
||||||
/* Description*/
|
'Jean-Christian Denis and Contributors',
|
||||||
"Change entries options at a given date",
|
'2021.08.19',
|
||||||
/* Author */
|
[
|
||||||
"Jean-Christian Denis",
|
'permissions' => 'usage,contentadmin',
|
||||||
/* Version */
|
'type' => 'plugin',
|
||||||
'2013.11.13',
|
'dc_min' => '2.18',
|
||||||
/* Properies */
|
'support' => 'https://github.com/JcDenis/postExpired',
|
||||||
array(
|
'details' => 'https://plugins.dotaddict.org/dc2/details/postExpired'
|
||||||
'permissions' => 'usage,contentadmin',
|
]
|
||||||
'type' => 'plugin',
|
|
||||||
'dc_min' => '2.6',
|
|
||||||
'support' => 'http://jcd.lv/q=postExpired',
|
|
||||||
'details' => 'http://plugins.dotaddict.org/dc2/details/postExpired'
|
|
||||||
)
|
|
||||||
);
|
);
|
63
_install.php
63
_install.php
@ -3,8 +3,7 @@
|
|||||||
#
|
#
|
||||||
# This file is part of postExpired, a plugin for Dotclear 2.
|
# This file is part of postExpired, a plugin for Dotclear 2.
|
||||||
#
|
#
|
||||||
# Copyright (c) 2009-2013 Jean-Christian Denis and contributors
|
# Copyright (c) 2009-2021 Jean-Christian Denis and contributors
|
||||||
# contact@jcdenis.fr http://jcd.lv
|
|
||||||
#
|
#
|
||||||
# Licensed under the GPL version 2.0 license.
|
# Licensed under the GPL version 2.0 license.
|
||||||
# A copy of this license is available in LICENSE file or at
|
# A copy of this license is available in LICENSE file or at
|
||||||
@ -13,49 +12,41 @@
|
|||||||
# -- END LICENSE BLOCK ------------------------------------
|
# -- END LICENSE BLOCK ------------------------------------
|
||||||
|
|
||||||
if (!defined('DC_CONTEXT_ADMIN')) {
|
if (!defined('DC_CONTEXT_ADMIN')) {
|
||||||
|
return null;
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# -- Module specs --
|
# -- Module specs --
|
||||||
|
$dc_min = '2.18';
|
||||||
$dc_min = '2.6';
|
|
||||||
$mod_id = 'postExpired';
|
$mod_id = 'postExpired';
|
||||||
|
|
||||||
# -- Nothing to change below --
|
# -- Nothing to change below --
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
# Check module version
|
||||||
|
if (version_compare(
|
||||||
|
$core->getVersion($mod_id),
|
||||||
|
$core->plugins->moduleInfo($mod_id, 'version'),
|
||||||
|
'>='
|
||||||
|
)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
# Check module version
|
# Check Dotclear version
|
||||||
if (version_compare(
|
if (!method_exists('dcUtils', 'versionsCompare')
|
||||||
$core->getVersion($mod_id),
|
|| dcUtils::versionsCompare(DC_VERSION, $dc_min, '<', false)) {
|
||||||
$core->plugins->moduleInfo($mod_id, 'version'),
|
throw new Exception(sprintf(
|
||||||
'>='
|
'%s requires Dotclear %s', $mod_id, $dc_min
|
||||||
)) {
|
));
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
# Set module version
|
||||||
}
|
$core->setVersion(
|
||||||
|
$mod_id,
|
||||||
|
$core->plugins->moduleInfo($mod_id, 'version')
|
||||||
|
);
|
||||||
|
|
||||||
# Check Dotclear version
|
return true;
|
||||||
if (!method_exists('dcUtils', 'versionsCompare')
|
} catch (Exception $e) {
|
||||||
|| dcUtils::versionsCompare(DC_VERSION, $dc_min, '<', false)) {
|
$core->error->add($e->getMessage());
|
||||||
throw new Exception(sprintf(
|
|
||||||
'%s requires Dotclear %s', $mod_id, $dc_min
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
# Set module version
|
return false;
|
||||||
$core->setVersion(
|
|
||||||
$mod_id,
|
|
||||||
$core->plugins->moduleInfo($mod_id, 'version')
|
|
||||||
);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
catch (Exception $e) {
|
|
||||||
$core->error->add($e->getMessage());
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
?>
|
|
28
_prepend.php
28
_prepend.php
@ -3,8 +3,7 @@
|
|||||||
#
|
#
|
||||||
# This file is part of postExpired, a plugin for Dotclear 2.
|
# This file is part of postExpired, a plugin for Dotclear 2.
|
||||||
#
|
#
|
||||||
# Copyright (c) 2009-2013 Jean-Christian Denis and contributors
|
# Copyright (c) 2009-2021 Jean-Christian Denis and contributors
|
||||||
# contact@jcdenis.fr http://jcd.lv
|
|
||||||
#
|
#
|
||||||
# Licensed under the GPL version 2.0 license.
|
# Licensed under the GPL version 2.0 license.
|
||||||
# A copy of this license is available in LICENSE file or at
|
# A copy of this license is available in LICENSE file or at
|
||||||
@ -13,8 +12,7 @@
|
|||||||
# -- END LICENSE BLOCK ------------------------------------
|
# -- END LICENSE BLOCK ------------------------------------
|
||||||
|
|
||||||
if (!defined('DC_RC_PATH')) {
|
if (!defined('DC_RC_PATH')) {
|
||||||
|
return null;
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -28,12 +26,12 @@ if (!defined('DC_RC_PATH')) {
|
|||||||
*/
|
*/
|
||||||
function encodePostExpired($in)
|
function encodePostExpired($in)
|
||||||
{
|
{
|
||||||
$out = array();
|
$out = array();
|
||||||
foreach($in as $k => $v) {
|
foreach($in as $k => $v) {
|
||||||
$out[] = $k.'|'.$v;
|
$out[] = $k . '|' . $v;
|
||||||
}
|
}
|
||||||
|
|
||||||
return implode(';', $out);
|
return implode(';', $out);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -44,11 +42,11 @@ function encodePostExpired($in)
|
|||||||
*/
|
*/
|
||||||
function decodePostExpired($in)
|
function decodePostExpired($in)
|
||||||
{
|
{
|
||||||
$out = array();
|
$out = array();
|
||||||
foreach(explode(';', $in) as $v) {
|
foreach(explode(';', $in) as $v) {
|
||||||
$v = explode('|', $v);
|
$v = explode('|', $v);
|
||||||
$out[$v[0]] = $v[1];
|
$out[$v[0]] = $v[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
return $out;
|
return $out;
|
||||||
}
|
}
|
413
_public.php
413
_public.php
@ -3,8 +3,7 @@
|
|||||||
#
|
#
|
||||||
# This file is part of postExpired, a plugin for Dotclear 2.
|
# This file is part of postExpired, a plugin for Dotclear 2.
|
||||||
#
|
#
|
||||||
# Copyright (c) 2009-2013 Jean-Christian Denis and contributors
|
# Copyright (c) 2009-2021 Jean-Christian Denis and contributors
|
||||||
# contact@jcdenis.fr http://jcd.lv
|
|
||||||
#
|
#
|
||||||
# Licensed under the GPL version 2.0 license.
|
# Licensed under the GPL version 2.0 license.
|
||||||
# A copy of this license is available in LICENSE file or at
|
# A copy of this license is available in LICENSE file or at
|
||||||
@ -13,13 +12,11 @@
|
|||||||
# -- END LICENSE BLOCK ------------------------------------
|
# -- END LICENSE BLOCK ------------------------------------
|
||||||
|
|
||||||
if (!defined('DC_RC_PATH')) {
|
if (!defined('DC_RC_PATH')) {
|
||||||
|
return null;
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($core->getVersion('postExpired') != $core->plugins->moduleInfo('postExpired', 'version')) {
|
if ($core->getVersion('postExpired') != $core->plugins->moduleInfo('postExpired', 'version')) {
|
||||||
|
return null;
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
__('Expired on');
|
__('Expired on');
|
||||||
@ -27,26 +24,26 @@ __('This entry has no expiration date');
|
|||||||
|
|
||||||
# launch update only on public home page and feed
|
# launch update only on public home page and feed
|
||||||
if (in_array($core->url->type, array('default', 'feed'))) {
|
if (in_array($core->url->type, array('default', 'feed'))) {
|
||||||
$core->addBehavior(
|
$core->addBehavior(
|
||||||
'publicBeforeDocument',
|
'publicBeforeDocument',
|
||||||
array('publicBehaviorPostExpired', 'publicBeforeDocument')
|
['publicBehaviorPostExpired', 'publicBeforeDocument']
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
$core->addBehavior(
|
$core->addBehavior(
|
||||||
'coreBlogGetPosts',
|
'coreBlogGetPosts',
|
||||||
array('publicBehaviorPostExpired', 'coreBlogGetPosts')
|
['publicBehaviorPostExpired', 'coreBlogGetPosts']
|
||||||
);
|
);
|
||||||
$core->tpl->addBlock(
|
$core->tpl->addBlock(
|
||||||
'EntryExpiredIf',
|
'EntryExpiredIf',
|
||||||
array('tplPostExpired', 'EntryExpiredIf')
|
['tplPostExpired', 'EntryExpiredIf']
|
||||||
);
|
);
|
||||||
$core->tpl->addValue(
|
$core->tpl->addValue(
|
||||||
'EntryExpiredDate',
|
'EntryExpiredDate',
|
||||||
array('tplPostExpired', 'EntryExpiredDate')
|
['tplPostExpired', 'EntryExpiredDate']
|
||||||
);
|
);
|
||||||
$core->tpl->addValue(
|
$core->tpl->addValue(
|
||||||
'EntryExpiredTime',
|
'EntryExpiredTime',
|
||||||
array('tplPostExpired', 'EntryExpiredTime')
|
['tplPostExpired', 'EntryExpiredTime']
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -56,120 +53,117 @@ $core->tpl->addValue(
|
|||||||
*/
|
*/
|
||||||
class publicBehaviorPostExpired
|
class publicBehaviorPostExpired
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Check if there are expired dates
|
* Check if there are expired dates
|
||||||
*
|
*
|
||||||
* @param dcCore $core dcCore instance
|
* @param dcCore $core dcCore instance
|
||||||
*/
|
*/
|
||||||
public static function publicBeforeDocument(dcCore $core)
|
public static function publicBeforeDocument(dcCore $core)
|
||||||
{
|
{
|
||||||
# Get expired dates and post_id
|
# Get expired dates and post_id
|
||||||
$posts = $core->con->select(
|
$posts = $core->con->select(
|
||||||
'SELECT P.post_id, P.post_tz, META.meta_id '.
|
'SELECT P.post_id, P.post_tz, META.meta_id ' .
|
||||||
'FROM '.$core->prefix.'post P '.
|
'FROM ' . $core->prefix . 'post P ' .
|
||||||
'INNER JOIN '.$core->prefix.'meta META '.
|
'INNER JOIN ' . $core->prefix . 'meta META ' .
|
||||||
'ON META.post_id = P.post_id '.
|
'ON META.post_id = P.post_id ' .
|
||||||
"WHERE blog_id = '".$core->con->escape($core->blog->id)."' ".
|
"WHERE blog_id = '" . $core->con->escape($core->blog->id) . "' " .
|
||||||
// Removed for quick compatibility with some plugins
|
// Removed for quick compatibility with some plugins
|
||||||
//"AND P.post_type = 'post' ".
|
//"AND P.post_type = 'post' " .
|
||||||
"AND META.meta_type = 'post_expired' "
|
"AND META.meta_type = 'post_expired' "
|
||||||
);
|
);
|
||||||
|
|
||||||
# No expired date
|
# No expired date
|
||||||
if ($posts->isEmpty()) {
|
if ($posts->isEmpty()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
# Get curent timestamp
|
||||||
}
|
$now = dt::toUTC(time());
|
||||||
|
|
||||||
# Get curent timestamp
|
# Prepared post cursor
|
||||||
$now = dt::toUTC(time());
|
$post_cur = $core->con->openCursor($core->prefix . 'post');
|
||||||
|
|
||||||
# Prepared post cursor
|
# Loop through marked posts
|
||||||
$post_cur = $core->con->openCursor($core->prefix.'post');
|
$updated = false;
|
||||||
|
while($posts->fetch()) {
|
||||||
|
|
||||||
# Loop through marked posts
|
# Decode meta record
|
||||||
$updated = false;
|
$post_expired = decodePostExpired($posts->meta_id);
|
||||||
while($posts->fetch()) {
|
|
||||||
|
|
||||||
# Decode meta record
|
# Check if post is outdated
|
||||||
$post_expired = decodePostExpired($posts->meta_id);
|
$now_tz = $now + dt::getTimeOffset($posts->post_tz, $now);
|
||||||
|
$meta_tz = strtotime($post_expired['date']);
|
||||||
|
if ($now_tz > $meta_tz) {
|
||||||
|
# Delete meta for expired date
|
||||||
|
$core->auth->sudo(
|
||||||
|
array($core->meta, 'delPostMeta'),
|
||||||
|
$posts->post_id,
|
||||||
|
'post_expired'
|
||||||
|
);
|
||||||
|
|
||||||
# Check if post is outdated
|
# Prepare post cursor
|
||||||
$now_tz = $now + dt::getTimeOffset($posts->post_tz, $now);
|
$post_cur->clean();
|
||||||
$meta_tz = strtotime($post_expired['date']);
|
$post_cur->post_upddt = date('Y-m-d H:i:s', $now_tz);
|
||||||
if ($now_tz > $meta_tz)
|
|
||||||
{
|
|
||||||
# Delete meta for expired date
|
|
||||||
$core->auth->sudo(
|
|
||||||
array($core->meta, 'delPostMeta'),
|
|
||||||
$posts->post_id,
|
|
||||||
'post_expired'
|
|
||||||
);
|
|
||||||
|
|
||||||
# Prepare post cursor
|
# Loop through actions
|
||||||
$post_cur->clean();
|
foreach($post_expired as $k => $v) {
|
||||||
$post_cur->post_upddt = date('Y-m-d H:i:s', $now_tz);
|
if (empty($v)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
# Loop through actions
|
# values are prefixed by "!"
|
||||||
foreach($post_expired as $k => $v)
|
$v = (integer) substr($v, 1);
|
||||||
{
|
|
||||||
if (empty($v)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
# values are prefixed by "!"
|
# Put value in post cursor
|
||||||
$v = (integer) substr($v, 1);
|
switch($k)
|
||||||
|
{
|
||||||
|
case 'status':
|
||||||
|
$post_cur->post_status = $v;
|
||||||
|
break;
|
||||||
|
|
||||||
# Put value in post cursor
|
case 'category':
|
||||||
switch($k)
|
$post_cur->cat_id = $v ? $v : null;
|
||||||
{
|
break;
|
||||||
case 'status':
|
|
||||||
$post_cur->post_status = $v;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'category':
|
case 'selected':
|
||||||
$post_cur->cat_id = $v ? $v : null;
|
$post_cur->post_selected = $v;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'selected':
|
case 'comment':
|
||||||
$post_cur->post_selected = $v;
|
$post_cur->post_open_comment = $v;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'comment':
|
case 'trackback':
|
||||||
$post_cur->post_open_comment = $v;
|
$post_cur->post_open_tb = $v;
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
case 'trackback':
|
# Update post
|
||||||
$post_cur->post_open_tb = $v;
|
$post_cur->update(
|
||||||
break;
|
'WHERE post_id = ' . $posts->post_id . ' ' .
|
||||||
}
|
"AND blog_id = '" . $core->con->escape($core->blog->id) . "' "
|
||||||
}
|
);
|
||||||
|
|
||||||
# Update post
|
$updated = true;
|
||||||
$post_cur->update(
|
}
|
||||||
'WHERE post_id = '.$posts->post_id.' '.
|
}
|
||||||
"AND blog_id = '".$core->con->escape($core->blog->id)."' "
|
|
||||||
);
|
|
||||||
|
|
||||||
$updated = true;
|
# Say blog is updated
|
||||||
}
|
if ($updated) {
|
||||||
}
|
$core->blog->triggerBlog();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
# Say blog is updated
|
/**
|
||||||
if ($updated) {
|
* Extends posts record with expired date
|
||||||
$core->blog->triggerBlog();
|
*
|
||||||
}
|
* @param record $rs Post recordset
|
||||||
}
|
*/
|
||||||
|
public static function coreBlogGetPosts(record $rs)
|
||||||
/**
|
{
|
||||||
* Extends posts record with expired date
|
$rs->extend('rsExtPostExpiredPublic');
|
||||||
*
|
}
|
||||||
* @param record $rs Post recordset
|
|
||||||
*/
|
|
||||||
public static function coreBlogGetPosts(record $rs)
|
|
||||||
{
|
|
||||||
$rs->extend('rsExtPostExpiredPublic');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -179,32 +173,31 @@ class publicBehaviorPostExpired
|
|||||||
*/
|
*/
|
||||||
class rsExtPostExpiredPublic extends rsExtPost
|
class rsExtPostExpiredPublic extends rsExtPost
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Retrieve expired date of a post
|
* Retrieve expired date of a post
|
||||||
*
|
*
|
||||||
* @param record $rs Post recordset
|
* @param record $rs Post recordset
|
||||||
* @return string Expired date or null
|
* @return string Expired date or null
|
||||||
*/
|
*/
|
||||||
public static function postExpiredDate(record $rs)
|
public static function postExpiredDate(record $rs)
|
||||||
{
|
{
|
||||||
if (!$rs->postexpired[$rs->post_id]) { //memory
|
if (!$rs->postexpired[$rs->post_id]) { //memory
|
||||||
$rs_date = $rs->core->meta->getMetadata(array(
|
$rs_date = $rs->core->meta->getMetadata(array(
|
||||||
'meta_type' => 'post_expired',
|
'meta_type' => 'post_expired',
|
||||||
'post_id' => $rs->post_id,
|
'post_id'=> $rs->post_id,
|
||||||
'limit' => 1
|
'limit'=> 1
|
||||||
));
|
));
|
||||||
|
|
||||||
if ($rs_date->isEmpty()) {
|
if ($rs_date->isEmpty()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
$v = unserialize(base64_decode($rs_date->meta_id));
|
||||||
}
|
$rs->postexpired[$rs->post_id] = $v['date'];
|
||||||
|
}
|
||||||
|
|
||||||
$v = unserialize(base64_decode($rs_date->meta_id));
|
return $rs->postexpired[$rs->post_id];
|
||||||
$rs->postexpired[$rs->post_id] = $v['date'];
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return $rs->postexpired[$rs->post_id];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -214,81 +207,87 @@ class rsExtPostExpiredPublic extends rsExtPost
|
|||||||
*/
|
*/
|
||||||
class tplPostExpired
|
class tplPostExpired
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Template condition to check if there is an expired date
|
* Template condition to check if there is an expired date
|
||||||
*
|
*
|
||||||
* @param array $attr Block attributes
|
* @param array $attr Block attributes
|
||||||
* @param string $content Block content
|
* @param string $content Block content
|
||||||
*/
|
*/
|
||||||
public static function EntryExpiredIf($attr, $content)
|
public static function EntryExpiredIf($attr, $content)
|
||||||
{
|
{
|
||||||
$if = array();
|
$if = array();
|
||||||
$operator = isset($attr['operator']) ?
|
$operator = isset($attr['operator']) ?
|
||||||
self::getOperator($attr['operator']) : '&&';
|
self::getOperator($attr['operator']) : '&&';
|
||||||
|
|
||||||
if (isset($attr['has_date'])) {
|
if (isset($attr['has_date'])) {
|
||||||
$sign = (boolean) $attr['has_date'] ? '!' : '=';
|
$sign = (boolean) $attr['has_date'] ? '!' : '=';
|
||||||
$if[] = '(null '.$sign.'== $_ctx->posts->postExpiredDate())';
|
$if[] = '(null ' . $sign . '== $_ctx->posts->postExpiredDate())';
|
||||||
}
|
} else {
|
||||||
else {
|
$if[] = '(null !== $_ctx->posts->postExpiredDate())';
|
||||||
$if[] = '(null !== $_ctx->posts->postExpiredDate())';
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return
|
return
|
||||||
"<?php if(".implode(' '.$operator.' ', $if).") : ?>\n".
|
"<?php if(" . implode(' ' . $operator . ' ', $if) . ") : ?>\n" .
|
||||||
$content.
|
$content .
|
||||||
"<?php endif; ?>\n";
|
"<?php endif; ?>\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Template for expired date
|
* Template for expired date
|
||||||
*
|
*
|
||||||
* @param array $attr Value attributes
|
* @param array $attr Value attributes
|
||||||
*/
|
*/
|
||||||
public static function EntryExpiredDate($attr)
|
public static function EntryExpiredDate($attr)
|
||||||
{
|
{
|
||||||
$format = !empty($attr['format']) ?
|
$format = !empty($attr['format']) ?
|
||||||
addslashes($attr['format']) : '';
|
addslashes($attr['format']) : '';
|
||||||
$f = $GLOBALS['core']->tpl->getFilters($attr);
|
$f = $GLOBALS['core']->tpl->getFilters($attr);
|
||||||
|
|
||||||
if (!empty($attr['rfc822']))
|
if (!empty($attr['rfc822'])) {
|
||||||
$res = sprintf($f,"dt::rfc822(strtotime(\$_ctx->posts->postExpiredDate()),\$_ctx->posts->post_tz)");
|
$res = sprintf($f, "dt::rfc822(strtotime(\$_ctx->posts->postExpiredDate()),\$_ctx->posts->post_tz)");
|
||||||
elseif (!empty($attr['iso8601']))
|
} elseif (!empty($attr['iso8601'])) {
|
||||||
$res = sprintf($f,"dt::iso8601(strtotime(\$_ctx->posts->postExpiredDate(),\$_ctx->posts->post_tz)");
|
$res = sprintf($f, "dt::iso8601(strtotime(\$_ctx->posts->postExpiredDate(),\$_ctx->posts->post_tz)");
|
||||||
elseif ($format)
|
} elseif ($format) {
|
||||||
$res = sprintf($f,"dt::dt2str('".$format."',\$_ctx->posts->postExpiredDate())");
|
$res = sprintf($f, "dt::dt2str('" . $format . "',\$_ctx->posts->postExpiredDate())");
|
||||||
else
|
} else {
|
||||||
$res = sprintf($f,"dt::dt2str(\$core->blog->settings->system->date_format,\$_ctx->posts->postExpiredDate())");
|
$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 . '; } ?>';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Template for expired time
|
* Template for expired time
|
||||||
*
|
*
|
||||||
* @param array $attr Value attributes
|
* @param array $attr Value attributes
|
||||||
*/
|
*/
|
||||||
public static function EntryExpiredTime($attr)
|
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())"
|
||||||
|
) . '; } ?>';
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse tempalte attributes oprerator
|
* Parse tempalte attributes oprerator
|
||||||
*
|
*
|
||||||
* @param string $op Operator
|
* @param string $op Operator
|
||||||
*/
|
*/
|
||||||
protected static function getOperator($op)
|
protected static function getOperator($op)
|
||||||
{
|
{
|
||||||
switch (strtolower($op))
|
switch (strtolower($op))
|
||||||
{
|
{
|
||||||
case 'or':
|
case 'or':
|
||||||
case '||':
|
case '||':
|
||||||
return '||';
|
return '||';
|
||||||
case 'and':
|
case 'and':
|
||||||
case '&&':
|
case '&&':
|
||||||
default:
|
default:
|
||||||
return '&&';
|
return '&&';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user