prepare to DC 2.24

This commit is contained in:
Jean-Christian Paul Denis 2022-11-14 21:47:24 +01:00
parent 81f2a3f967
commit 947b0cf339
Signed by: JcDenis
GPG Key ID: 1B5B8C5B90B6C951
4 changed files with 92 additions and 96 deletions

View File

@ -16,61 +16,64 @@ if (!defined('DC_CONTEXT_ADMIN')) {
}
# Check plugin version
if ($core->getVersion('postExpired') != $core->plugins->moduleInfo('postExpired', 'version')) {
if (dcCore::app()->getVersion('postExpired') != dcCore::app()->plugins->moduleInfo('postExpired', 'version')) {
return null;
}
# Check user right
if (!$core->auth->check('contentadmin', $core->blog->id)) {
if (!dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([
dcAuth::PERMISSION_CONTENT_ADMIN,
]), dcCore::app()->blog->id)
) {
return null;
}
# Admin behaviors
$core->addBehavior(
'adminPostsActionsPage',
['adminBehaviorPostExpired', 'adminPostsActionsPage']
dcCore::app()->addBehavior(
'adminPostsActions',
['adminBehaviorPostExpired', 'adminPostsActions']
);
$core->addBehavior(
'adminPagesActionsPage',
['adminBehaviorPostExpired', 'adminPostsActionsPage']
dcCore::app()->addBehavior(
'adminPagesActions',
['adminBehaviorPostExpired', 'adminPostsActions']
);
$core->addBehavior(
dcCore::app()->addBehavior(
'adminPostHeaders',
['adminBehaviorPostExpired', 'adminPostHeaders']
);
$core->addBehavior(
dcCore::app()->addBehavior(
'adminPageHeaders',
['adminBehaviorPostExpired', 'adminPostHeaders']
);
$core->addBehavior(
dcCore::app()->addBehavior(
'adminPostFormItems',
['adminBehaviorPostExpired', 'adminPostFormItems']
);
$core->addBehavior(
dcCore::app()->addBehavior(
'adminPageFormItems',
['adminBehaviorPostExpired', 'adminPostFormItems']
);
$core->addBehavior(
dcCore::app()->addBehavior(
'adminBeforePostDelete',
['adminBehaviorPostExpired', 'adminBeforePostDelete']
);
$core->addBehavior(
dcCore::app()->addBehavior(
'adminBeforePageDelete',
['adminBehaviorPostExpired', 'adminBeforePostDelete']
);
$core->addBehavior(
dcCore::app()->addBehavior(
'adminAfterPostUpdate',
['adminBehaviorPostExpired', 'adminAfterPostSave']
);
$core->addBehavior(
dcCore::app()->addBehavior(
'adminAfterPageUpdate',
['adminBehaviorPostExpired', 'adminAfterPostSave']
);
$core->addBehavior(
dcCore::app()->addBehavior(
'adminAfterPostCreate',
['adminBehaviorPostExpired', 'adminAfterPostSave']
);
$core->addBehavior(
dcCore::app()->addBehavior(
'adminAfterPageCreate',
['adminBehaviorPostExpired', 'adminAfterPostSave']
);
@ -85,10 +88,9 @@ class adminBehaviorPostExpired
/**
* Add actions to posts page combo
*
* @param dcCore $core dcCore instance
* @param dcPostsActionsPage $ap dcPostsActionsPage instance
*/
public static function adminPostsActionsPage(dcCore $core, dcPostsActionsPage $pa)
public static function adminPostsActions(dcPostsActions $pa)
{
$pa->addAction(
array(
@ -135,7 +137,6 @@ class adminBehaviorPostExpired
$sidebar_items['post_expired'] = array(
'title' => __('Expired date'),
'items' => self::fieldsPostExpired(
$GLOBALS['core'],
$post->post_type,
$post->post_id
)
@ -149,7 +150,7 @@ class adminBehaviorPostExpired
*/
public static function adminBeforePostDelete($post_id)
{
self::delPostExpired($GLOBALS['core'], $post_id);
self::delPostExpired($post_id);
}
/**
@ -160,9 +161,7 @@ class adminBehaviorPostExpired
*/
public static function adminAfterPostSave(cursor $cur, $post_id)
{
global $core;
self::delPostExpired($core, $post_id);
self::delPostExpired($post_id);
if (!empty($_POST['post_expired_date'])
&& (!empty($_POST['post_expired_status'])
@ -170,18 +169,17 @@ class adminBehaviorPostExpired
|| !empty($_POST['post_expired_selected'])
|| !empty($_POST['post_expired_comment'])
|| !empty($_POST['post_expired_trackback']))) {
self::setPostExpired($core, $post_id, $_POST);
self::setPostExpired($post_id, $_POST);
}
}
/**
* Posts actions callback to add expired date
*
* @param dcCore $core dcCore instance
* @param dcPostsActionsPage $pa dcPostsActionsPage instance
* @param dcPostsActions $pa dcPostsActions instance
* @param ArrayObject $post _POST actions
*/
public static function callbackAdd(dcCore $core, dcPostsActionsPage $pa, ArrayObject $post)
public static function callbackAdd(dcPostsActions $pa, ArrayObject $post)
{
# No entry
$posts_ids = $pa->getIDs();
@ -197,11 +195,11 @@ class adminBehaviorPostExpired
|| !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);
self::delPostExpired($post_id);
self::setPostExpired($post_id, $post);
}
dcPage::addSuccessNotice(__('Expired date added.'));
dcAdminNotices::addSuccessNotice(__('Expired date added.'));
$pa->redirect(true);
# Display form
@ -211,7 +209,7 @@ class adminBehaviorPostExpired
$pa->beginPage(
dcPage::breadcrumb(array(
html::escapeHTML($core->blog->name) => '',
html::escapeHTML(dcCore::app()->blog->name) => '',
$pa->getCallerTitle() => $pa->getRedirection(true),
__('Add expired date to this selection') => ''
)),
@ -223,9 +221,9 @@ class adminBehaviorPostExpired
'<form action="' . $pa->getURI() . '" method="post">' .
$pa->getCheckboxes() .
implode('', self::fieldsPostExpired($core, $posts->post_type)) .
implode('', self::fieldsPostExpired($posts->post_type)) .
$core->formNonce() .
dcCore::app()->formNonce() .
$pa->getHiddenFields() .
form::hidden(array('action'), 'post_expired_add') .
'<input type="submit" value="' . __('Save') . '" /></p>' .
@ -238,11 +236,10 @@ class adminBehaviorPostExpired
/**
* Posts actions callback to add expired date
*
* @param dcCore $core dcCore instance
* @param dcPostsActionsPage $pa dcPostsActionsPage instance
* @param dcPostsActions $pa dcPostsActions instance
* @param ArrayObject $post _POST actions
*/
public static function callbackRemove(dcCore $core, dcPostsActionsPage $pa, ArrayObject $post)
public static function callbackRemove(dcPostsActions $pa, ArrayObject $post)
{
# No entry
$posts_ids = $pa->getIDs();
@ -252,32 +249,30 @@ class adminBehaviorPostExpired
# Delete expired date
foreach($posts_ids as $post_id) {
self::delPostExpired($core, $post_id);
self::delPostExpired($post_id);
}
dcPage::addSuccessNotice(__('Expired date deleted.'));
dcAdminNotices::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)
protected static function delPostExpired($post_id)
{
$core->meta->delPostMeta($post_id, 'post_expired');
dcCore::app()->meta->delPostMeta($post_id, 'post_expired');
}
/**
* Save expired date
*
* @param dcCore $core dcCore instance
* @param integer $post_id Post id
* @param array $post _POST fields
*/
protected static function setPostExpired(dcCore $core, $post_id, $post)
protected static function setPostExpired($post_id, $post)
{
$post_expired = array(
'status'=> '',
@ -312,7 +307,7 @@ class adminBehaviorPostExpired
(string) $post['post_expired_trackback'];
}
$core->meta->setPostMeta(
dcCore::app()->meta->setPostMeta(
$post_id,
'post_expired',
encodePostExpired($post_expired)
@ -322,17 +317,16 @@ class adminBehaviorPostExpired
/**
* 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)
protected static function fieldsPostExpired($post_type, $post_id = null)
{
$fields = $post_expired = array();
if ($post_id) {
$rs = $core->meta->getMetadata([
$rs = dcCore::app()->meta->getMetadata([
'meta_type' => 'post_expired',
'post_id' => $post_id,
'limit' => 1
@ -371,7 +365,7 @@ class adminBehaviorPostExpired
form::combo(
'post_expired_category',
self::categoriesCombo(
$core->blog->getCategories(
dcCore::app()->blog->getCategories(
array('post_type' => 'post')
)
),
@ -416,10 +410,10 @@ class adminBehaviorPostExpired
/**
* Custom categories combo
*
* @param record $categories Categories recordset
* @param dcRecord $categories Categories recordset
* @return array Categorires combo
*/
protected static function categoriesCombo(record $categories)
protected static function categoriesCombo(dcRecord $categories)
{
# Getting categories
$categories_combo = array(
@ -427,7 +421,7 @@ class adminBehaviorPostExpired
__('Uncategorized') => '!'
);
try {
$categories = $GLOBALS['core']->blog->getCategories(
$categories = dcCore::app()->blog->getCategories(
array('post_type' => 'post')
);
while ($categories->fetch()) {

View File

@ -19,10 +19,13 @@ $this->registerModule(
'Expired entries',
'Change entries options at a given date',
'Jean-Christian Denis and Contributors',
'2022.04.27',
'2022.11.12',
[
'requires' => [['core', '2.21']],
'permissions' => 'usage,contentadmin',
'requires' => [['core', '2.24']],
'permissions' => dcCore::app()->auth->makePermissions([
dcAuth::PERMISSION_USAGE,
dcAuth::PERMISSION_CONTENT_ADMIN,
]),
'type' => 'plugin',
'support' => 'https://github.com/JcDenis/postExpired',
'details' => 'https://plugins.dotaddict.org/dc2/details/postExpired',

View File

@ -16,15 +16,15 @@ if (!defined('DC_CONTEXT_ADMIN')) {
}
# -- Module specs --
$dc_min = '2.21';
$dc_min = '2.24';
$mod_id = 'postExpired';
# -- Nothing to change below --
try {
# Check module version
if (version_compare(
$core->getVersion($mod_id),
$core->plugins->moduleInfo($mod_id, 'version'),
dcCore::app()->getVersion($mod_id),
dcCore::app()->plugins->moduleInfo($mod_id, 'version'),
'>='
)) {
return null;
@ -39,14 +39,14 @@ try {
}
# Set module version
$core->setVersion(
dcCore::app()->setVersion(
$mod_id,
$core->plugins->moduleInfo($mod_id, 'version')
dcCore::app()->plugins->moduleInfo($mod_id, 'version')
);
return true;
} catch (Exception $e) {
$core->error->add($e->getMessage());
dcCore::app()->error->add($e->getMessage());
return false;
}

View File

@ -15,7 +15,7 @@ if (!defined('DC_RC_PATH')) {
return null;
}
if ($core->getVersion('postExpired') != $core->plugins->moduleInfo('postExpired', 'version')) {
if (dcCore::app()->getVersion('postExpired') != dcCore::app()->plugins->moduleInfo('postExpired', 'version')) {
return null;
}
@ -23,25 +23,25 @@ __('Expired on');
__('This entry has no expiration date');
# launch update only on public home page and feed
if (in_array($core->url->type, array('default', 'feed'))) {
$core->addBehavior(
'publicBeforeDocument',
if (in_array(dcCore::app()->url->type, array('default', 'feed'))) {
dcCore::app()->addBehavior(
'publicBeforeDocumentV2',
['publicBehaviorPostExpired', 'publicBeforeDocument']
);
}
$core->addBehavior(
dcCore::app()->addBehavior(
'coreBlogGetPosts',
['publicBehaviorPostExpired', 'coreBlogGetPosts']
);
$core->tpl->addBlock(
dcCore::app()->tpl->addBlock(
'EntryExpiredIf',
['tplPostExpired', 'EntryExpiredIf']
);
$core->tpl->addValue(
dcCore::app()->tpl->addValue(
'EntryExpiredDate',
['tplPostExpired', 'EntryExpiredDate']
);
$core->tpl->addValue(
dcCore::app()->tpl->addValue(
'EntryExpiredTime',
['tplPostExpired', 'EntryExpiredTime']
);
@ -56,17 +56,16 @@ class publicBehaviorPostExpired
/**
* Check if there are expired dates
*
* @param dcCore $core dcCore instance
*/
public static function publicBeforeDocument(dcCore $core)
public static function publicBeforeDocument()
{
# Get expired dates and post_id
$posts = $core->con->select(
$posts = dcCore::app()->con->select(
'SELECT P.post_id, P.post_tz, META.meta_id ' .
'FROM ' . $core->prefix . 'post P ' .
'INNER JOIN ' . $core->prefix . 'meta META ' .
'FROM ' . dcCore::app()->prefix . 'post P ' .
'INNER JOIN ' . dcCore::app()->prefix . 'meta META ' .
'ON META.post_id = P.post_id ' .
"WHERE blog_id = '" . $core->con->escape($core->blog->id) . "' " .
"WHERE blog_id = '" . dcCore::app()->con->escape(dcCore::app()->blog->id) . "' " .
// Removed for quick compatibility with some plugins
//"AND P.post_type = 'post' " .
"AND META.meta_type = 'post_expired' "
@ -81,7 +80,7 @@ class publicBehaviorPostExpired
$now = dt::toUTC(time());
# Prepared post cursor
$post_cur = $core->con->openCursor($core->prefix . 'post');
$post_cur = dcCore::app()->con->openCursor(dcCore::app()->prefix . 'post');
# Loop through marked posts
$updated = false;
@ -95,8 +94,8 @@ class publicBehaviorPostExpired
$meta_tz = strtotime($post_expired['date']);
if ($now_tz > $meta_tz) {
# Delete meta for expired date
$core->auth->sudo(
array($core->meta, 'delPostMeta'),
dcCore::app()->auth->sudo(
array(dcCore::app()->meta, 'delPostMeta'),
$posts->post_id,
'post_expired'
);
@ -142,7 +141,7 @@ class publicBehaviorPostExpired
# Update post
$post_cur->update(
'WHERE post_id = ' . $posts->post_id . ' ' .
"AND blog_id = '" . $core->con->escape($core->blog->id) . "' "
"AND blog_id = '" . dcCore::app()->con->escape(dcCore::app()->blog->id) . "' "
);
$updated = true;
@ -151,16 +150,16 @@ class publicBehaviorPostExpired
# Say blog is updated
if ($updated) {
$core->blog->triggerBlog();
dcCore::app()->blog->triggerBlog();
}
}
/**
* Extends posts record with expired date
*
* @param record $rs Post recordset
* @param dcRecord $rs Post recordset
*/
public static function coreBlogGetPosts(record $rs)
public static function coreBlogGetPosts(dcRecord $rs)
{
$rs->extend('rsExtPostExpiredPublic');
}
@ -179,7 +178,7 @@ class rsExtPostExpiredPublic extends rsExtPost
* @param record $rs Post recordset
* @return string Expired date or null
*/
public static function postExpiredDate(record $rs)
public static function postExpiredDate(dcRecord $rs)
{
if (!$rs->postexpired[$rs->post_id]) { //memory
$rs_date = $rs->core->meta->getMetadata([
@ -221,9 +220,9 @@ class tplPostExpired
if (isset($attr['has_date'])) {
$sign = (boolean) $attr['has_date'] ? '!' : '=';
$if[] = '(null ' . $sign . '== $_ctx->posts->postExpiredDate())';
$if[] = '(null ' . $sign . '== dcCore::app()->ctx->posts->postExpiredDate())';
} else {
$if[] = '(null !== $_ctx->posts->postExpiredDate())';
$if[] = '(null !== dcCore::app()->ctx->posts->postExpiredDate())';
}
return
@ -241,19 +240,19 @@ class tplPostExpired
{
$format = !empty($attr['format']) ?
addslashes($attr['format']) : '';
$f = $GLOBALS['core']->tpl->getFilters($attr);
$f = dcCore::app()->tpl->getFilters($attr);
if (!empty($attr['rfc822'])) {
$res = sprintf($f, "dt::rfc822(strtotime(\$_ctx->posts->postExpiredDate()),\$_ctx->posts->post_tz)");
$res = sprintf($f, "dt::rfc822(strtotime(dcCore::app()->ctx->posts->postExpiredDate()),dcCore::app()->ctx->posts->post_tz)");
} elseif (!empty($attr['iso8601'])) {
$res = sprintf($f, "dt::iso8601(strtotime(\$_ctx->posts->postExpiredDate(),\$_ctx->posts->post_tz)");
$res = sprintf($f, "dt::iso8601(strtotime(dcCore::app()->ctx->posts->postExpiredDate(),dcCore::app()->ctx->posts->post_tz)");
} elseif ($format) {
$res = sprintf($f, "dt::dt2str('" . $format . "',\$_ctx->posts->postExpiredDate())");
$res = sprintf($f, "dt::dt2str('" . $format . "',dcCore::app()->ctx->posts->postExpiredDate())");
} else {
$res = sprintf($f, "dt::dt2str(\$core->blog->settings->system->date_format,\$_ctx->posts->postExpiredDate())");
$res = sprintf($f, "dt::dt2str(dcCore::app()->blog->settings->system->date_format,dcCore::app()->ctx->posts->postExpiredDate())");
}
return '<?php if (null !== $_ctx->posts->postExpiredDate()) { echo ' . $res . '; } ?>';
return '<?php if (null !== dcCore::app()->ctx->posts->postExpiredDate()) { echo ' . $res . '; } ?>';
}
/**
@ -264,11 +263,11 @@ class tplPostExpired
public static function EntryExpiredTime($attr)
{
return
'<?php if (null !== $_ctx->posts->postExpiredDate()) { echo ' . sprintf(
$GLOBALS['core']->tpl->getFilters($attr), "dt::dt2str(" .
'<?php if (null !== dcCore::app()->ctx->posts->postExpiredDate()) { echo ' . sprintf(
dcCore::app()->tpl->getFilters($attr), "dt::dt2str(" .
(!empty($attr['format']) ?
"'" . addslashes($attr['format']) . "'" : "\$core->blog->settings->system->time_format"
) . ",\$_ctx->posts->postExpiredDate())"
"'" . addslashes($attr['format']) . "'" : "dcCore::app()->blog->settings->system->time_format"
) . ",dcCore::app()->ctx->posts->postExpiredDate())"
) . '; } ?>';
}