diff --git a/CHANGELOG b/CHANGELOG.md similarity index 61% rename from CHANGELOG rename to CHANGELOG.md index 5ca8a8d..d455b6a 100644 --- a/CHANGELOG +++ b/CHANGELOG.md @@ -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 \ No newline at end of file diff --git a/README.md b/README.md index 1c29d80..b25750e 100644 --- a/README.md +++ b/README.md @@ -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) \ No newline at end of file diff --git a/_admin.php b/_admin.php index c8ccca0..46d3abc 100644 --- a/_admin.php +++ b/_admin.php @@ -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; + return null; } # Check plugin version if ($core->getVersion('postExpired') != $core->plugins->moduleInfo('postExpired', 'version')) { - - return null; + return null; } # Check user right if (!$core->auth->check('contentadmin', $core->blog->id)) { - - return null; + return null; } # Admin behaviors $core->addBehavior( - 'adminPostsActionsPage', - array('adminBehaviorPostExpired', 'adminPostsActionsPage') + 'adminPostsActionsPage', + ['adminBehaviorPostExpired', 'adminPostsActionsPage'] ); $core->addBehavior( - 'adminPagesActionsPage', - array('adminBehaviorPostExpired', 'adminPostsActionsPage') + 'adminPagesActionsPage', + ['adminBehaviorPostExpired', 'adminPostsActionsPage'] ); $core->addBehavior( - 'adminPostHeaders', - array('adminBehaviorPostExpired', 'adminPostHeaders') + 'adminPostHeaders', + ['adminBehaviorPostExpired', 'adminPostHeaders'] ); $core->addBehavior( - 'adminPageHeaders', - array('adminBehaviorPostExpired', 'adminPostHeaders') + 'adminPageHeaders', + ['adminBehaviorPostExpired', 'adminPostHeaders'] ); $core->addBehavior( - 'adminPostFormItems', - array('adminBehaviorPostExpired', 'adminPostFormItems') + 'adminPostFormItems', + ['adminBehaviorPostExpired', 'adminPostFormItems'] ); $core->addBehavior( - 'adminPageFormItems', - array('adminBehaviorPostExpired', 'adminPostFormItems') + 'adminPageFormItems', + ['adminBehaviorPostExpired', 'adminPostFormItems'] ); $core->addBehavior( - 'adminBeforePostDelete', - array('adminBehaviorPostExpired', 'adminBeforePostDelete') + 'adminBeforePostDelete', + ['adminBehaviorPostExpired', 'adminBeforePostDelete'] ); $core->addBehavior( - 'adminBeforePageDelete', - array('adminBehaviorPostExpired', 'adminBeforePostDelete') + 'adminBeforePageDelete', + ['adminBehaviorPostExpired', 'adminBeforePostDelete'] ); $core->addBehavior( - 'adminAfterPostUpdate', - array('adminBehaviorPostExpired', 'adminAfterPostSave') + 'adminAfterPostUpdate', + ['adminBehaviorPostExpired', 'adminAfterPostSave'] ); $core->addBehavior( - 'adminAfterPageUpdate', - array('adminBehaviorPostExpired', 'adminAfterPostSave') + 'adminAfterPageUpdate', + ['adminBehaviorPostExpired', 'adminAfterPostSave'] ); $core->addBehavior( - 'adminAfterPostCreate', - array('adminBehaviorPostExpired', 'adminAfterPostSave') + 'adminAfterPostCreate', + ['adminBehaviorPostExpired', 'adminAfterPostSave'] ); $core->addBehavior( - 'adminAfterPageCreate', - array('adminBehaviorPostExpired', 'adminAfterPostSave') + 'adminAfterPageCreate', + ['adminBehaviorPostExpired', 'adminAfterPostSave'] ); /** @@ -86,430 +82,424 @@ $core->addBehavior( */ 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) - { - $pa->addAction( - array( - __('Expired entries') => array( - __('Add expired date') => 'post_expired_add' - ) - ), - array('adminBehaviorPostExpired', 'callbackAdd') - ); + /** + * Add actions to posts page combo + * + * @param dcCore $core dcCore instance + * @param dcPostsActionsPage $ap dcPostsActionsPage instance + */ + public static function adminPostsActionsPage(dcCore $core, dcPostsActionsPage $pa) + { + $pa->addAction( + array( + __('Expired entries') => array( + __('Add expired date') => 'post_expired_add' + ) + ), + array('adminBehaviorPostExpired', 'callbackAdd') + ); - $pa->addAction( - array( - __('Expired entries') => array( - __('Remove expired date') => 'post_expired_remove' - ) - ), - array('adminBehaviorPostExpired', 'callbackRemove') - ); - } + $pa->addAction( + array( + __('Expired entries') => array( + __('Remove expired date') => 'post_expired_remove' + ) + ), + array('adminBehaviorPostExpired', 'callbackRemove') + ); + } - /** - * Add javascript for date field and toggle - * - * @return string HTML head - */ - public static function adminPostHeaders() - { - return dcPage::jsLoad('index.php?pf=postExpired/js/postexpired.js'); - } + /** + * Add javascript for date field and toggle + * + * @return string HTML head + */ + public static function adminPostHeaders() + { + return dcPage::jsLoad('index.php?pf=postExpired/js/postexpired.js'); + } - /** - * Add form to post sidebar - * - * @param ArrayObject $main_items Main items - * @param ArrayObject $sidebar_items Sidebar items - * @param record $post Post record or null - */ - public static function adminPostFormItems(ArrayObject $main_items, ArrayObject $sidebar_items, $post) - { - if ($post === null) { + /** + * Add form to post sidebar + * + * @param ArrayObject $main_items Main items + * @param ArrayObject $sidebar_items Sidebar items + * @param record $post Post record or null + */ + public static function adminPostFormItems(ArrayObject $main_items, ArrayObject $sidebar_items, $post) + { + 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'), - 'items' => self::fieldsPostExpired( - $GLOBALS['core'], - $post->post_type, - $post->post_id - ) - ); - } + /** + * Delete expired date on post edition + * + * @param integer $post_id Post id + */ + public static function adminBeforePostDelete($post_id) + { + self::delPostExpired($GLOBALS['core'], $post_id); + } - /** - * Delete expired date on post edition - * - * @param integer $post_id Post id - */ - public static function adminBeforePostDelete($post_id) - { - self::delPostExpired($GLOBALS['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; - /** - * 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); - 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']) - || !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); - } - } + /** + * 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 callbackAdd(dcCore $core, dcPostsActionsPage $pa, ArrayObject $post) + { + # No entry + $posts_ids = $pa->getIDs(); + if (empty($posts_ids)) { + throw new Exception(__('No entry selected')); + } - /** - * 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 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 + 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']))) { + foreach($posts_ids as $post_id) { + self::delPostExpired($core, $post_id); + self::setPostExpired($core, $post_id, $post); + } - # Add epired date - 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'])) - ) { - foreach($posts_ids as $post_id) { - self::delPostExpired($core, $post_id); - self::setPostExpired($core, $post_id, $post); - } + dcPage::addSuccessNotice(__('Expired date added.')); + $pa->redirect(true); - dcPage::addSuccessNotice(__('Expired date added.')); - $pa->redirect(true); - } + # Display form + } else { + # Get records to know post type + $posts = $pa->getRS(); - # Display form - else { - # Get records to know post type - $posts = $pa->getRS(); + $pa->beginPage( + dcPage::breadcrumb(array( + html::escapeHTML($core->blog->name) => '', + $pa->getCallerTitle() => $pa->getRedirection(true), + __('Add expired date to this selection') => '' + )), + dcPage::jsDatePicker() . + self::adminPostHeaders() + ); - $pa->beginPage( - dcPage::breadcrumb(array( - html::escapeHTML($core->blog->name) => '', - $pa->getCallerTitle() => $pa->getRedirection(true), - __('Add expired date to this selection') => '' - )), - dcPage::jsDatePicker(). - self::adminPostHeaders() - ); + echo + '
' . + $pa->getCheckboxes() . - echo - ''. - $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') . + '

' . + '
'; - $core->formNonce(). - $pa->getHiddenFields(). - form::hidden(array('action'), 'post_expired_add'). - '

'. - ''; + $pa->endPage(); + } + } - $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')); + } - /** - * 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 + foreach($posts_ids as $post_id) { + self::delPostExpired($core, $post_id); + } - # Delete expired date - foreach($posts_ids as $post_id) { - self::delPostExpired($core, $post_id); - } + dcPage::addSuccessNotice(__('Expired date deleted.')); + $pa->redirect(true); + } - 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 - * - * @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'); - } + /** + * 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) + { + $post_expired = array( + 'status'=> '', + 'category'=> '', + 'selected'=> '', + 'comment'=> '', + 'trackback' => '', + 'date'=> date( + 'Y-m-d H:i:00', + strtotime($post['post_expired_date']) + ) + ); - /** - * 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) - { - $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'])) { + $post_expired['status'] = + (string) $post['post_expired_status']; + } + 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']; + } - if (!empty($post['post_expired_status'])) { - $post_expired['status'] = - (string) $post['post_expired_status']; - } - 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, + 'post_expired', + encodePostExpired($post_expired) + ); + } - $core->meta->setPostMeta( - $post_id, - 'post_expired', - encodePostExpired($post_expired) - ); - } + /** + * 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(); - /** - * 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) { - if ($post_id) { + $rs = $core->meta->getMeta( + 'post_expired', + 1, + null, + $post_id + ); - $rs = $core->meta->getMeta( - 'post_expired', - 1, - null, - $post_id - ); + if (!$rs->isEmpty()) { + $post_expired = decodePostExpired($rs->meta_id); + } + } - if (!$rs->isEmpty()) { - $post_expired = decodePostExpired($rs->meta_id); - } - } + $fields['post_expired_date'] = + '

' . + form::field( + 'post_expired_date', + 16, + 16, + empty($post_expired['date']) ? + '' : $post_expired['date'] + ) . '

'; - $fields['post_expired_date'] = - '

'. - form::field( - 'post_expired_date', - 16, - 16, - empty($post_expired['date']) ? - '' : $post_expired['date'] - ).'

'; + $fields['post_expired_status'] = + '
' . __('On this date, change:') . '
' . + '

' . + form::combo( + 'post_expired_status', + self::statusCombo(), + empty($post_expired['status']) ? + '' : $post_expired['status'] + ) . '

'; - $fields['post_expired_status'] = - '
'.__('On this date, change:').'
'. - '

'. - form::combo( - 'post_expired_status', - self::statusCombo(), - empty($post_expired['status']) ? - '' : $post_expired['status'] - ).'

'; + if ($post_type == 'post') { - if ($post_type == 'post') { + $fields['post_expired_category'] = + '

' . + form::combo( + 'post_expired_category', + self::categoriesCombo( + $core->blog->getCategories( + array('post_type' => 'post') + ) + ), + empty($post_expired['category']) ? + '' : $post_expired['category'] + ) . '

'; - $fields['post_expired_category'] = - '

'. - form::combo( - 'post_expired_category', - self::categoriesCombo( - $core->blog->getCategories( - array('post_type' => 'post') - ) - ), - empty($post_expired['category']) ? - '' : $post_expired['category'] - ).'

'; + $fields['post_expired_selected'] = + '

' . + form::combo( + 'post_expired_selected', + self::selectedCombo(), + empty($post_expired['selected']) ? + '' : $post_expired['selected'] + ) . '

'; + } - $fields['post_expired_selected'] = - '

'. - form::combo( - 'post_expired_selected', - self::selectedCombo(), - empty($post_expired['selected']) ? - '' : $post_expired['selected'] - ).'

'; - } + $fields['post_expired_comment'] = + '

' . + form::combo( + 'post_expired_comment', + self::commentCombo(), + empty($post_expired['comment']) ? + '' : $post_expired['comment'] + ) . '

'; - $fields['post_expired_comment'] = - '

'. - form::combo( - 'post_expired_comment', - self::commentCombo(), - empty($post_expired['comment']) ? - '' : $post_expired['comment'] - ).'

'; + $fields['post_expired_trackback'] = + '

' . + form::combo( + 'post_expired_trackback', + self::trackbackCombo(), + empty($post_expired['trackback']) ? + '' : $post_expired['trackback'] + ) . '

'; - $fields['post_expired_trackback'] = - '

'. - form::combo( - 'post_expired_trackback', - self::trackbackCombo(), - empty($post_expired['trackback']) ? - '' : $post_expired['trackback'] - ).'

'; + return $fields; + } - 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(); + } - /** - * 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 $categories_combo; + } - 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 - * - * @return array Status combo - */ - protected static function statusCombo() - { - return array( - __('Not changed') => '', - __('Published') => '!1', - __('Pending') => '!-2', - __('Unpublished') => '!0' - ); - } + /** + * Custom comment status combo + * + * @return array Comment status combo + */ + protected static function commentCombo() + { + return array( + __('Not changed') => '', + __('Opened') => '!1', + __('Closed') => '!0' + ); + } - /** - * Custom selection combo - * - * @return array Selection combo - */ - protected static function selectedCombo() - { - return array( - __('Not changed') => '', - __('Selected') => '!1', - __('Not selected') => '!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' - ); - } -} + /** + * Custom trackback status combo + * + * @return array Trackback status combo + */ + protected static function trackbackCombo() + { + return array( + __('Not changed') => '', + __('Opened') => '!1', + __('Closed') => '!0' + ); + } +} \ No newline at end of file diff --git a/_define.php b/_define.php index d2bdb65..d8fe0b3 100644 --- a/_define.php +++ b/_define.php @@ -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( - 'permissions' => 'usage,contentadmin', - 'type' => 'plugin', - 'dc_min' => '2.6', - 'support' => 'http://jcd.lv/q=postExpired', - 'details' => 'http://plugins.dotaddict.org/dc2/details/postExpired' - ) -); + '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.18', + 'support' => 'https://github.com/JcDenis/postExpired', + 'details' => 'https://plugins.dotaddict.org/dc2/details/postExpired' + ] +); \ No newline at end of file diff --git a/_install.php b/_install.php index b4970f8..95ab4be 100644 --- a/_install.php +++ b/_install.php @@ -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,49 +12,41 @@ # -- END LICENSE BLOCK ------------------------------------ if (!defined('DC_CONTEXT_ADMIN')) { - - return null; + 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; + } - # Check module version - if (version_compare( - $core->getVersion($mod_id), - $core->plugins->moduleInfo($mod_id, 'version'), - '>=' - )) { + # Check Dotclear version + if (!method_exists('dcUtils', 'versionsCompare') + || dcUtils::versionsCompare(DC_VERSION, $dc_min, '<', false)) { + 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 - if (!method_exists('dcUtils', 'versionsCompare') - || dcUtils::versionsCompare(DC_VERSION, $dc_min, '<', false)) { - throw new Exception(sprintf( - '%s requires Dotclear %s', $mod_id, $dc_min - )); - } + return true; +} catch (Exception $e) { + $core->error->add($e->getMessage()); - # Set module version - $core->setVersion( - $mod_id, - $core->plugins->moduleInfo($mod_id, 'version') - ); - - return true; -} -catch (Exception $e) { - $core->error->add($e->getMessage()); - - return false; -} - -?> \ No newline at end of file + return false; +} \ No newline at end of file diff --git a/_prepend.php b/_prepend.php index 71b1a9a..c17d400 100644 --- a/_prepend.php +++ b/_prepend.php @@ -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,8 +12,7 @@ # -- END LICENSE BLOCK ------------------------------------ if (!defined('DC_RC_PATH')) { - - return null; + return null; } /** @@ -28,12 +26,12 @@ if (!defined('DC_RC_PATH')) { */ function encodePostExpired($in) { - $out = array(); - foreach($in as $k => $v) { - $out[] = $k.'|'.$v; - } + $out = array(); + foreach($in as $k => $v) { + $out[] = $k . '|' . $v; + } - return implode(';', $out); + return implode(';', $out); } /** @@ -44,11 +42,11 @@ function encodePostExpired($in) */ function decodePostExpired($in) { - $out = array(); - foreach(explode(';', $in) as $v) { - $v = explode('|', $v); - $out[$v[0]] = $v[1]; - } + $out = array(); + foreach(explode(';', $in) as $v) { + $v = explode('|', $v); + $out[$v[0]] = $v[1]; + } - return $out; + return $out; } \ No newline at end of file diff --git a/_public.php b/_public.php index f27c87d..994a92d 100644 --- a/_public.php +++ b/_public.php @@ -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,13 +12,11 @@ # -- END LICENSE BLOCK ------------------------------------ if (!defined('DC_RC_PATH')) { - - return null; + return null; } if ($core->getVersion('postExpired') != $core->plugins->moduleInfo('postExpired', 'version')) { - - return null; + return null; } __('Expired on'); @@ -27,26 +24,26 @@ __('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', - array('publicBehaviorPostExpired', 'publicBeforeDocument') - ); + $core->addBehavior( + 'publicBeforeDocument', + ['publicBehaviorPostExpired', 'publicBeforeDocument'] + ); } $core->addBehavior( - 'coreBlogGetPosts', - array('publicBehaviorPostExpired', 'coreBlogGetPosts') + 'coreBlogGetPosts', + ['publicBehaviorPostExpired', 'coreBlogGetPosts'] ); $core->tpl->addBlock( - 'EntryExpiredIf', - array('tplPostExpired', 'EntryExpiredIf') + 'EntryExpiredIf', + ['tplPostExpired', 'EntryExpiredIf'] ); $core->tpl->addValue( - 'EntryExpiredDate', - array('tplPostExpired', 'EntryExpiredDate') + 'EntryExpiredDate', + ['tplPostExpired', 'EntryExpiredDate'] ); $core->tpl->addValue( - 'EntryExpiredTime', - array('tplPostExpired', 'EntryExpiredTime') + 'EntryExpiredTime', + ['tplPostExpired', 'EntryExpiredTime'] ); /** @@ -56,120 +53,117 @@ $core->tpl->addValue( */ class publicBehaviorPostExpired { - /** - * Check if there are expired dates - * - * @param dcCore $core dcCore instance - */ - public static function publicBeforeDocument(dcCore $core) - { - # 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)."' ". - // Removed for quick compatibility with some plugins - //"AND P.post_type = 'post' ". - "AND META.meta_type = 'post_expired' " - ); + /** + * Check if there are expired dates + * + * @param dcCore $core dcCore instance + */ + public static function publicBeforeDocument(dcCore $core) + { + # 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) . "' " . + // Removed for quick compatibility with some plugins + //"AND P.post_type = 'post' " . + "AND META.meta_type = 'post_expired' " + ); - # No expired date - if ($posts->isEmpty()) { + # No expired date + if ($posts->isEmpty()) { + return null; + } - return null; - } + # Get curent timestamp + $now = dt::toUTC(time()); - # Get curent timestamp - $now = dt::toUTC(time()); + # Prepared post cursor + $post_cur = $core->con->openCursor($core->prefix . 'post'); - # Prepared post cursor - $post_cur = $core->con->openCursor($core->prefix.'post'); + # Loop through marked posts + $updated = false; + while($posts->fetch()) { - # Loop through marked posts - $updated = false; - while($posts->fetch()) { + # Decode meta record + $post_expired = decodePostExpired($posts->meta_id); - # Decode meta record - $post_expired = decodePostExpired($posts->meta_id); + # 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) { + # Delete meta for expired date + $core->auth->sudo( + array($core->meta, 'delPostMeta'), + $posts->post_id, + 'post_expired' + ); - # 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) - { - # Delete meta for expired date - $core->auth->sudo( - array($core->meta, 'delPostMeta'), - $posts->post_id, - 'post_expired' - ); + # Prepare post cursor + $post_cur->clean(); + $post_cur->post_upddt = date('Y-m-d H:i:s', $now_tz); - # Prepare post cursor - $post_cur->clean(); - $post_cur->post_upddt = date('Y-m-d H:i:s', $now_tz); + # Loop through actions + foreach($post_expired as $k => $v) { + if (empty($v)) { + continue; + } - # Loop through actions - foreach($post_expired as $k => $v) - { - if (empty($v)) { - continue; - } + # values are prefixed by "!" + $v = (integer) substr($v, 1); - # values are prefixed by "!" - $v = (integer) substr($v, 1); + # Put value in post cursor + switch($k) + { + case 'status': + $post_cur->post_status = $v; + break; - # Put value in post cursor - switch($k) - { - case 'status': - $post_cur->post_status = $v; - break; + case 'category': + $post_cur->cat_id = $v ? $v : null; + break; - case 'category': - $post_cur->cat_id = $v ? $v : null; - break; + case 'selected': + $post_cur->post_selected = $v; + break; - case 'selected': - $post_cur->post_selected = $v; - break; + case 'comment': + $post_cur->post_open_comment = $v; + break; - case 'comment': - $post_cur->post_open_comment = $v; - break; + case 'trackback': + $post_cur->post_open_tb = $v; + break; + } + } - case 'trackback': - $post_cur->post_open_tb = $v; - break; - } - } + # Update post + $post_cur->update( + 'WHERE post_id = ' . $posts->post_id . ' ' . + "AND blog_id = '" . $core->con->escape($core->blog->id) . "' " + ); - # Update post - $post_cur->update( - 'WHERE post_id = '.$posts->post_id.' '. - "AND blog_id = '".$core->con->escape($core->blog->id)."' " - ); + $updated = true; + } + } - $updated = true; - } - } + # Say blog is updated + if ($updated) { + $core->blog->triggerBlog(); + } + } - # Say blog is updated - if ($updated) { - $core->blog->triggerBlog(); - } - } - - /** - * Extends posts record with expired date - * - * @param record $rs Post recordset - */ - public static function coreBlogGetPosts(record $rs) - { - $rs->extend('rsExtPostExpiredPublic'); - } + /** + * Extends posts record with expired date + * + * @param record $rs Post recordset + */ + public static function coreBlogGetPosts(record $rs) + { + $rs->extend('rsExtPostExpiredPublic'); + } } /** @@ -179,32 +173,31 @@ class publicBehaviorPostExpired */ class rsExtPostExpiredPublic extends rsExtPost { - /** - * Retrieve expired date of a post - * - * @param record $rs Post recordset - * @return string Expired date or null - */ - public static function postExpiredDate(record $rs) - { - 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 - )); + /** + * Retrieve expired date of a post + * + * @param record $rs Post recordset + * @return string Expired date or null + */ + public static function postExpiredDate(record $rs) + { + 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 + )); - 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)); - $rs->postexpired[$rs->post_id] = $v['date']; - } - - return $rs->postexpired[$rs->post_id]; - } + return $rs->postexpired[$rs->post_id]; + } } /** @@ -214,81 +207,87 @@ class rsExtPostExpiredPublic extends rsExtPost */ class tplPostExpired { - /** - * Template condition to check if there is an expired date - * - * @param array $attr Block attributes - * @param string $content Block content - */ - public static function EntryExpiredIf($attr, $content) - { - $if = array(); - $operator = isset($attr['operator']) ? - self::getOperator($attr['operator']) : '&&'; + /** + * Template condition to check if there is an expired date + * + * @param array $attr Block attributes + * @param string $content Block content + */ + public static function EntryExpiredIf($attr, $content) + { + $if = array(); + $operator = isset($attr['operator']) ? + self::getOperator($attr['operator']) : '&&'; - if (isset($attr['has_date'])) { - $sign = (boolean) $attr['has_date'] ? '!' : '='; - $if[] = '(null '.$sign.'== $_ctx->posts->postExpiredDate())'; - } - else { - $if[] = '(null !== $_ctx->posts->postExpiredDate())'; - } + if (isset($attr['has_date'])) { + $sign = (boolean) $attr['has_date'] ? '!' : '='; + $if[] = '(null ' . $sign . '== $_ctx->posts->postExpiredDate())'; + } else { + $if[] = '(null !== $_ctx->posts->postExpiredDate())'; + } - return - "\n". - $content. - "\n"; - } + return + "\n" . + $content . + "\n"; + } - /** - * Template for expired date - * - * @param array $attr Value attributes - */ - public static function EntryExpiredDate($attr) - { - $format = !empty($attr['format']) ? - addslashes($attr['format']) : ''; - $f = $GLOBALS['core']->tpl->getFilters($attr); + /** + * Template for expired date + * + * @param array $attr Value attributes + */ + public static function EntryExpiredDate($attr) + { + $format = !empty($attr['format']) ? + 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 'posts->postExpiredDate()) { echo '.$res.'; } ?>'; - } + return 'posts->postExpiredDate()) { echo ' . $res . '; } ?>'; + } - /** - * Template for expired time - * - * @param array $attr Value attributes - */ - public static function EntryExpiredTime($attr) - { - return '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())").'; } ?>'; - } + /** + * Template for expired time + * + * @param array $attr Value attributes + */ + public static function EntryExpiredTime($attr) + { + return + '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 - * - * @param string $op Operator - */ - protected static function getOperator($op) - { - switch (strtolower($op)) - { - case 'or': - case '||': - return '||'; - case 'and': - case '&&': - default: - return '&&'; - } - } -} + /** + * Parse tempalte attributes oprerator + * + * @param string $op Operator + */ + protected static function getOperator($op) + { + switch (strtolower($op)) + { + case 'or': + case '||': + return '||'; + case 'and': + case '&&': + default: + return '&&'; + } + } +} \ No newline at end of file