From 807214f65813733f82d052d2c6b0d0c580d30e3c Mon Sep 17 00:00:00 2001 From: Jean-Christian Denis Date: Sun, 20 Nov 2022 21:13:56 +0100 Subject: [PATCH] release 0.10 --- CHANGELOG.md | 4 +- README.md | 16 ++- _admin.php | 225 +++++++++++++++++++-------------------- _config.php | 97 +++++++++-------- _define.php | 30 +++--- _install.php | 109 ++++++++++--------- _public.php | 129 +++++++++++----------- dcstore.xml | 21 ++-- locales/en/resources.php | 7 +- locales/fr/resources.php | 7 +- 10 files changed, 327 insertions(+), 318 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fe87380..2cf84be 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,5 @@ -0.9.3 -- [ ] ? +0.10 2022.11.20 +- fix compatibility with Dotclear 2.24 (required) 0.9.2 - 2021.09.02 - update license bloc to phpdoc diff --git a/README.md b/README.md index 099947d..6d68b58 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ [![Release](https://img.shields.io/github/v/release/JcDenis/fac)](https://github.com/JcDenis/fac/releases) [![Date](https://img.shields.io/github/release-date/JcDenis/fac)](https://github.com/JcDenis/fac/releases) [![Issues](https://img.shields.io/github/issues/JcDenis/fac)](https://github.com/JcDenis/fac/issues) -[![Dotclear](https://img.shields.io/badge/dotclear-v2.19-blue.svg)](https://fr.dotclear.org/download) +[![Dotclear](https://img.shields.io/badge/dotclear-v2.24-blue.svg)](https://fr.dotclear.org/download) [![Dotaddict](https://img.shields.io/badge/dotaddict-official-green.svg)](https://plugins.dotaddict.org/dc2/details/fac) [![License](https://img.shields.io/github/license/JcDenis/fac)](https://github.com/JcDenis/fac/blob/master/LICENSE) @@ -22,7 +22,7 @@ to link en extenal feed to the bottom of an entry. * superadmin to configure feeds formats * admin permissions to configure plugin * usage,contentadmin permissions to link feeds - * Dotclear 2.19 + * Dotclear 2.24 * A theme that contents behavior publicEntryAfterContent ## USAGE @@ -39,8 +39,14 @@ to link a feed to this post. You can also add or remove feed to multiple post from posts actions page. This plugins also supports pages from plugin "muppet". -## MORE +## LINKS - * License : GNU GPL v2 + * License : [GNU GPL v2](https://www.gnu.org/licenses/old-licenses/lgpl-2.0.html) * Source & contribution : [GitHub Page](https://github.com/JcDenis/fac) - * Packages & details: [Dotaddict Page](https://plugins.dotaddict.org/dc2/details/fac) \ No newline at end of file + * Packages & details: [Dotaddict Page](https://plugins.dotaddict.org/dc2/details/fac) + +## CONTRIBUTORS + + * Jean-Christian Denis + + You are welcome to contribute to this code. \ No newline at end of file diff --git a/_admin.php b/_admin.php index 03c108d..04244b0 100644 --- a/_admin.php +++ b/_admin.php @@ -1,31 +1,30 @@ blog->settings->addNamespace('fac'); +dcCore::app()->blog->settings->addNamespace('fac'); # Admin behaviors -$core->addBehavior('adminBlogPreferencesForm', ['facAdmin', 'adminBlogPreferencesForm']); -$core->addBehavior('adminBeforeBlogSettingsUpdate', ['facAdmin', 'adminBeforeBlogSettingsUpdate']); -$core->addBehavior('adminPostHeaders', ['facAdmin', 'adminPostHeaders']); -$core->addBehavior('adminPostFormItems', ['facAdmin', 'adminPostFormItems']); -$core->addBehavior('adminAfterPostCreate', ['facAdmin', 'adminAfterPostSave']); -$core->addBehavior('adminAfterPostUpdate', ['facAdmin', 'adminAfterPostSave']); -$core->addBehavior('adminBeforePostDelete', ['facAdmin', 'adminBeforePostDelete']); -$core->addBehavior('adminPostsActionsPage', ['facAdmin', 'adminPostsActionsPage']); +dcCore::app()->addBehavior('adminBlogPreferencesFormV2', ['facAdmin', 'adminBlogPreferencesForm']); +dcCore::app()->addBehavior('adminBeforeBlogSettingsUpdate', ['facAdmin', 'adminBeforeBlogSettingsUpdate']); +dcCore::app()->addBehavior('adminPostHeaders', ['facAdmin', 'adminPostHeaders']); +dcCore::app()->addBehavior('adminPostFormItems', ['facAdmin', 'adminPostFormItems']); +dcCore::app()->addBehavior('adminAfterPostCreate', ['facAdmin', 'adminAfterPostSave']); +dcCore::app()->addBehavior('adminAfterPostUpdate', ['facAdmin', 'adminAfterPostSave']); +dcCore::app()->addBehavior('adminBeforePostDelete', ['facAdmin', 'adminBeforePostDelete']); +dcCore::app()->addBehavior('adminPostsActions', ['facAdmin', 'adminPostsActionsPage']); /** * @ingroup DC_PLUGIN_FAC @@ -36,67 +35,66 @@ class facAdmin { /** * Get combos of types of supported public pages - * - * @param dcCore $core dcCore instance + * * @return array List of post type and name */ - public static function getPostsTypes(dcCore $core) + public static function getPostsTypes() { $types = [ - __('home page') => 'default', - __('post pages') => 'post', - __('tags pages') => 'tag', - __('archives pages') => 'archive', - __('category pages') => 'category', - __('entries feed') => 'feed' + __('home page') => 'default', + __('post pages') => 'post', + __('tags pages') => 'tag', + __('archives pages') => 'archive', + __('category pages') => 'category', + __('entries feed') => 'feed', ]; - if ($core->plugins->moduleExists('muppet')) { - foreach(muppet::getPostTypes() as $k => $v) { + if (dcCore::app()->plugins->moduleExists('muppet')) { + foreach (muppet::getPostTypes() as $k => $v) { $types[sprintf( __('"%s" pages from extension muppet'), $v['name'] )] = $k; } } + return $types; } /** * Add settings to blog preference - * - * @param dcCore $core dcCore instance + * * @param dcSettings $blog_settings dcSettings instance */ - public static function adminBlogPreferencesForm(dcCore $core, dcSettings $blog_settings) + public static function adminBlogPreferencesForm(dcSettings $blog_settings) { echo '

Feed after content

' . - '

' . + '

' . __('To add feed to an entry edit this entry and put in sidebar the url of the feed and select a format.') . '

'; - if ($core->auth->isSuperAdmin()) { - echo '

adminurl->get('admin.plugins', [ + 'module' => 'fac', + 'conf' => 1, + 'redir' => dcCore::app()->adminurl->get('admin.blog.pref') . '#fac_params', ]) . '">' . __('Configure formats') . '

'; } - echo + echo '
' . '
' . '
' . __('Activation') . '
' . '

' . '

' . - __("You can manage related feed to display for each post with a predefined format.") . + __('You can manage related feed to display for each post with a predefined format.') . '

' . '
' . __('Feed') . '
' . '

' . form::field('fac_defaultfeedtitle', 65, 255, (string) $blog_settings->fac->fac_defaultfeedtitle) . '

' . '

' . __('Use %T to insert title of feed.') . '

' . '

' . '
' . '
' . @@ -106,7 +104,7 @@ class facAdmin if (!is_array($fac_public_tpltypes)) { $fac_public_tpltypes = []; } - foreach(self::getPostsTypes($core) as $k => $v) { + foreach (self::getPostsTypes() as $k => $v) { echo '

'; } - echo + echo '
' . '
' . - '
' . + '
' . '
'; } /** * Save blog settings - * + * * @param dcSettings $blog_settings dcSettings instance */ public static function adminBeforeBlogSettingsUpdate(dcSettings $blog_settings) @@ -138,7 +136,7 @@ class facAdmin /** * Add javascript (toggle) - * + * * @return string HTML head */ public static function adminPostHeaders() @@ -148,84 +146,77 @@ class facAdmin /** * 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) { - global $core; - - if (!$core->blog->settings->fac->fac_active) { + if (!dcCore::app()->blog->settings->fac->fac_active) { return null; } # Get existing linked feed $fac_url = $fac_format = ''; if ($post) { - - $rs = $core->meta->getMetadata([ + $rs = dcCore::app()->meta->getMetadata([ 'meta_type' => 'fac', - 'post_id' => $post->post_id, - 'limit' => 1 + 'post_id' => $post->post_id, + 'limit' => 1, ]); $fac_url = $rs->isEmpty() ? '' : $rs->meta_id; - $rs = $core->meta->getMetadata([ + $rs = dcCore::app()->meta->getMetadata([ 'meta_type' => 'facformat', - 'post_id' => $post->post_id, - 'limit' => 1 + 'post_id' => $post->post_id, + 'limit' => 1, ]); $fac_format = $rs->isEmpty() ? '' : $rs->meta_id; } # Set linked feed form items - $sidebar_items['options-box']['items']['fac'] = - self::formFeed($core, $fac_url, $fac_format); + $sidebar_items['options-box']['items']['fac'] = self::formFeed($fac_url, $fac_format); } /** * Save linked feed - * + * * @param cursor $cur Current post cursor * @param integer $post_id Post id */ public static function adminAfterPostSave(cursor $cur, $post_id) { - global $core; - - if (!isset($_POST['fac_url']) + if (!isset($_POST['fac_url']) || !isset($_POST['fac_format'])) { return null; } # Delete old linked feed - self::delFeed($core, $post_id); + self::delFeed($post_id); # Add new linked feed - self::addFeed($core, $post_id, $_POST); + self::addFeed($post_id, $_POST); } /** * Delete linked feed on post edition - * + * * @param integer $post_id Post id */ public static function adminBeforePostDelete($post_id) { - self::delFeed($GLOBALS['core'], $post_id); + self::delFeed($post_id); } /** * Add actions to posts page combo - * - * @param dcCore $core dcCore instance - * @param dcPostsActionsPage $ap dcPostsActionsPage instance + * + * @param dcPostsActions $pa dcPostsActionsPage instance */ - public static function adminPostsActionsPage(dcCore $core, dcPostsActionsPage $pa) + public static function adminPostsActionsPage(dcPostsActions $pa) { - if (!$core->blog->settings->fac->fac_active) { + if (!dcCore::app()->blog->settings->fac->fac_active) { return null; } @@ -234,7 +225,10 @@ class facAdmin ['facAdmin', 'callbackAdd'] ); - if (!$core->auth->check('delete,contentadmin', $core->blog->id)) { + if (!dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([ + dcAuth::PERMISSION_DELETE, + dcAuth::PERMISSION_CONTENT_ADMIN, + ]), dcCore::app()->blog->id)) { return null; } $pa->addAction( @@ -245,12 +239,11 @@ class facAdmin /** * Posts actions callback to remove linked feed - * - * @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(); @@ -259,13 +252,16 @@ class facAdmin } # No right - if (!$core->auth->check('delete,contentadmin',$core->blog->id)) { + if (!dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([ + dcAuth::PERMISSION_DELETE, + dcAuth::PERMISSION_CONTENT_ADMIN, + ]), dcCore::app()->blog->id)) { throw new Exception(__('No enough right')); } # Delete unused feed - foreach($posts_ids as $post_id) { - self::delFeed($core, $post_id); + foreach ($posts_ids as $post_id) { + self::delFeed($post_id); } dcPage::addSuccessNotice(__('Linked feed deleted.')); @@ -274,14 +270,13 @@ class facAdmin /** * Posts actions callback to add linked feed - * - * @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 + # No entry $posts_ids = $pa->getIDs(); if (empty($posts_ids)) { throw new Exception(__('No entry selected')); @@ -290,9 +285,9 @@ class facAdmin # Save action if (!empty($post['fac_url']) && !empty($post['fac_format'])) { - foreach($posts_ids as $post_id) { - self::delFeed($core, $post_id); - self::addFeed($core, $post_id, $post); + foreach ($posts_ids as $post_id) { + self::delFeed($post_id); + self::addFeed($post_id, $post); } dcPage::addSuccessNotice(__('Linked feed added.')); @@ -302,9 +297,9 @@ class facAdmin } else { $pa->beginPage( dcPage::breadcrumb([ - html::escapeHTML($core->blog->name) => '', - $pa->getCallerTitle() => $pa->getRedirection(true), - __('Linked feed to this selection') => '' + html::escapeHTML(dcCore::app()->blog->name) => '', + $pa->getCallerTitle() => $pa->getRedirection(true), + __('Linked feed to this selection') => '', ]) ); @@ -312,10 +307,10 @@ class facAdmin '
' . $pa->getCheckboxes() . - self::formFeed($core) . + self::formFeed() . '

' . - $core->formNonce() . + dcCore::app()->formNonce() . $pa->getHiddenFields() . form::hidden(['action'], 'fac_add') . '

' . @@ -327,20 +322,19 @@ class facAdmin /** * Linked feed form field - * - * @param dcCore $core dcCore instance + * * @param string $url Feed URL * @param string $format Feed format - * @return string Feed form content + * @return null|string Feed form content */ - protected static function formFeed(dcCore $core, $url = '', $format = '') + protected static function formFeed($url = '', $format = '') { - if (!$core->blog->settings->fac->fac_active) { + if (!dcCore::app()->blog->settings->fac->fac_active) { return null; } - return - '
' . + return + '
' . '
' . __('Linked feed') . '
' . '

' . @@ -355,7 +349,7 @@ class facAdmin __('Format:') . '' . form::combo( 'fac_format', - self::comboFac($core), + self::comboFac(), $format, 'maximal' ) . '

' . @@ -365,19 +359,18 @@ class facAdmin /** * List of fac formats - * - * @param dcCore $core dcCore instance + * * @return array List of fac formats */ - protected static function comboFac(dcCore $core) + protected static function comboFac() { - $formats = @unserialize($core->blog->settings->fac->fac_formats); + $formats = @unserialize(dcCore::app()->blog->settings->fac->fac_formats); if (!is_array($formats) || empty($formats)) { return []; } $res = []; - foreach($formats as $uid => $f) { + foreach ($formats as $uid => $f) { $res[$f['name']] = $uid; } @@ -386,42 +379,40 @@ class facAdmin /** * Delete linked feed - * - * @param dcCore $core dcCore instance + * * @param integer $post_id Post id */ - protected static function delFeed(dcCore $core, $post_id) + protected static function delFeed($post_id) { - $post_id = (integer) $post_id; - $core->meta->delPostMeta($post_id, 'fac'); - $core->meta->delPostMeta($post_id, 'facformat'); + $post_id = (int) $post_id; + dcCore::app()->meta->delPostMeta($post_id, 'fac'); + dcCore::app()->meta->delPostMeta($post_id, 'facformat'); } /** * Add linked feed - * - * @param dcCore $core dcCore instance + * * @param integer $post_id Post id - * @param array $options Feed options + * @param array|ArrayObject $options Feed options */ - protected static function addFeed($core, $post_id, $options) + protected static function addFeed($post_id, $options) { - if (empty($options['fac_url']) + if (empty($options['fac_url']) || empty($options['fac_format'])) { return null; } - $post_id = (integer) $post_id; + $post_id = (int) $post_id; - $core->meta->setPostMeta( + dcCore::app()->meta->setPostMeta( $post_id, 'fac', $options['fac_url'] ); - $core->meta->setPostMeta( + dcCore::app()->meta->setPostMeta( $post_id, 'facformat', $options['fac_format'] ); } -} \ No newline at end of file +} diff --git a/_config.php b/_config.php index 49428ac..c57518d 100644 --- a/_config.php +++ b/_config.php @@ -1,30 +1,29 @@ auth->isSuperAdmin()) { +if (!dcCore::app()->auth->isSuperAdmin()) { return null; } -$redir = empty($_REQUEST['redir']) ? - $list->getURL() . '#plugins' : $_REQUEST['redir']; +$redir = empty($_REQUEST['redir']) ? + dcCore::app()->admin->list->getURL() . '#plugins' : $_REQUEST['redir']; # -- Get settings -- -$core->blog->settings->addNamespace('fac'); -$s = $core->blog->settings->fac; +dcCore::app()->blog->settings->addNamespace('fac'); +$s = dcCore::app()->blog->settings->fac; $fac_formats = @unserialize($s->fac_formats); @@ -37,7 +36,7 @@ if (!empty($_POST['save'])) { try { $fac_formats = []; - foreach($_POST['fac_formats'] as $uid => $f) { + foreach ($_POST['fac_formats'] as $uid => $f) { if (!empty($f['name'])) { $fac_formats[$uid] = $f; } @@ -46,31 +45,31 @@ if (!empty($_POST['save'])) { // fix 2021.08.21 : formats are now global $s->drop('fac_formats'); $s->put( - 'fac_formats', - serialize($fac_formats), - 'string', - 'Formats of feeds contents', - true, + 'fac_formats', + serialize($fac_formats), + 'string', + 'Formats of feeds contents', + true, true ); - $core->blog->triggerBlog(); + dcCore::app()->blog->triggerBlog(); - dcPage::addSuccessNotice( + dcAdminNotices::addSuccessNotice( __('Configuration successfully updated.') ); http::redirect( - $list->getURL('module=fac&conf=1&redir=' . $list->getRedir()) + dcCore::app()->admin->list->getURL('module=fac&conf=1&redir=' . dcCore::app()->admin->list->getRedir()) ); } catch (Exception $e) { - $core->error->add($e->getMessage()); + dcCore::app()->error->add($e->getMessage()); } } # -- Display form -- $i = 1; -foreach($fac_formats as $uid => $f) { +foreach ($fac_formats as $uid => $f) { if (empty($f['name'])) { continue; } @@ -86,7 +85,7 @@ foreach($fac_formats as $uid => $f) { form::field( [ 'fac_formats[' . $uid . '][name]', - 'fac_formats_' . $uid . '_name' + 'fac_formats_' . $uid . '_name', ], 20, 255, @@ -102,7 +101,7 @@ foreach($fac_formats as $uid => $f) { form::field( [ 'fac_formats[' . $uid . '][dateformat]', - 'fac_formats_' . $uid . '_dateformat' + 'fac_formats_' . $uid . '_dateformat', ], 20, 255, @@ -118,7 +117,7 @@ foreach($fac_formats as $uid => $f) { form::field( [ 'fac_formats[' . $uid . '][lineslimit]', - 'fac_formats_' . $uid . '_lineslimit' + 'fac_formats_' . $uid . '_lineslimit', ], 5, 4, @@ -136,7 +135,7 @@ foreach($fac_formats as $uid => $f) { form::field( [ 'fac_formats[' . $uid . '][linestitletext]', - 'fac_formats_' . $uid . '_linestitletext' + 'fac_formats_' . $uid . '_linestitletext', ], 20, 255, @@ -157,7 +156,7 @@ foreach($fac_formats as $uid => $f) { form::field( [ 'fac_formats[' . $uid . '][linestitleover]', - 'fac_formats_' . $uid . '_linestitleover' + 'fac_formats_' . $uid . '_linestitleover', ], 20, 255, @@ -178,7 +177,7 @@ foreach($fac_formats as $uid => $f) { form::field( [ 'fac_formats[' . $uid . '][linestitlelength]', - 'fac_formats_' . $uid . '_linestitlelength' + 'fac_formats_' . $uid . '_linestitlelength', ], 5, 4, @@ -195,7 +194,7 @@ foreach($fac_formats as $uid => $f) { form::checkbox( [ 'fac_formats[' . $uid . '][showlinesdescription]', - 'fac_formats_' . $uid . '_showlinesdescription' + 'fac_formats_' . $uid . '_showlinesdescription', ], 1, !empty($f['showlinesdescription']) @@ -206,11 +205,11 @@ foreach($fac_formats as $uid => $f) { form::checkbox( [ 'fac_formats[' . $uid . '][linesdescriptionnohtml]', - 'fac_formats_' . $uid . '_linesdescriptionnohtml' + 'fac_formats_' . $uid . '_linesdescriptionnohtml', ], 1, !empty($f['linesdescriptionnohtml']) - ). + ) . __('Remove html of description') . '

' . form::field( [ 'fac_formats[' . $uid . '][name]', - 'fac_formats_' . $uid . '_name' + 'fac_formats_' . $uid . '_name', ], 20, 255, '', 'maximal' ) . '

-

'. +

' . __('In order to remove a format, leave its name empty.') . '

@@ -304,7 +303,7 @@ __('Date format:') . '' . form::field( [ 'fac_formats[' . $uid . '][dateformat]', - 'fac_formats_' . $uid . '_dateformat' + 'fac_formats_' . $uid . '_dateformat', ], 20, 255, @@ -320,7 +319,7 @@ __('Entries limit:') . '' . form::field( [ 'fac_formats[' . $uid . '][lineslimit]', - 'fac_formats_' . $uid . '_lineslimit' + 'fac_formats_' . $uid . '_lineslimit', ], 5, 4, @@ -338,7 +337,7 @@ __('Title format:') . '' . form::field( [ 'fac_formats[' . $uid . '][linestitletext]', - 'fac_formats_' . $uid . '_linestitletext' + 'fac_formats_' . $uid . '_linestitletext', ], 20, 255, @@ -355,11 +354,11 @@ __('Format can be:') . '

' . +__('Over title format:') . '' . form::field( [ 'fac_formats[' . $uid . '][linestitleover]', - 'fac_formats_' . $uid . '_linestitleover' + 'fac_formats_' . $uid . '_linestitleover', ], 20, 255, @@ -380,14 +379,14 @@ __('Maximum length of title:') . '' . form::field( [ 'fac_formats[' . $uid . '][linestitlelength]', - 'fac_formats_' . $uid . '_linestitlelength' + 'fac_formats_' . $uid . '_linestitlelength', ], 5, 4, 150, 'maximal' ) . '

-

' . +

' . __('Leave lengh empty for no limit.') . '

@@ -397,7 +396,7 @@ __('Leave lengh empty for no limit.') . form::checkbox( [ 'fac_formats[' . $uid . '][showlinesdescription]', - 'fac_formats_' . $uid . '_showlinesdescription' + 'fac_formats_' . $uid . '_showlinesdescription', ], 1, 0 @@ -408,7 +407,7 @@ __('Show description of entries') . '

form::checkbox( [ 'fac_formats[' . $uid . '][linesdescriptionnohtml]', - 'fac_formats_' . $uid . '_linesdescriptionnohtml' + 'fac_formats_' . $uid . '_linesdescriptionnohtml', ], 1, 1 @@ -420,7 +419,7 @@ __('Maximum length of description:') . '' . form::field( [ 'fac_formats[' . $uid . '][linesdescriptionlength]', - 'fac_formats_' . $uid . '_linesdescriptionlength' + 'fac_formats_' . $uid . '_linesdescriptionlength', ], 5, 4, @@ -437,7 +436,7 @@ __('Leave lengh empty for no limit.') . form::checkbox( [ 'fac_formats[' . $uid . '][showlinescontent]', - 'fac_formats_' . $uid . '_showlinescontent' + 'fac_formats_' . $uid . '_showlinescontent', ], 1, 0 @@ -448,7 +447,7 @@ __('Show content of entries') . '

form::checkbox( [ 'fac_formats[' . $uid . '][linescontentnohtml]', - 'fac_formats_' . $uid . '_linescontentnohtml' + 'fac_formats_' . $uid . '_linescontentnohtml', ], 1, 1 @@ -460,7 +459,7 @@ __('Maximum length of content:') . '' . form::field( [ 'fac_formats[' . $uid . '][linescontentlength]', - 'fac_formats_' . $uid . '_linescontentlength' + 'fac_formats_' . $uid . '_linescontentlength', ], 5, 4, @@ -504,4 +503,4 @@ __('To add feed to an entry edit this entry and put in sidebar the url of the fe
'; -dcPage::helpBlock('fac'); \ No newline at end of file +dcPage::helpBlock('fac'); diff --git a/_define.php b/_define.php index 9e89d06..7e0d6a3 100644 --- a/_define.php +++ b/_define.php @@ -1,16 +1,15 @@ registerModule( 'Feed after content', 'Add RSS/Atom feeds after entries content', 'Jean-Christian Denis and Contributors', - '0.9.3', + '0.10', [ - 'requires' => [['core', '2.19']], - 'permissions' => 'usage,contentadmin', - 'type' => 'plugin', - 'support' => 'https://github.com/JcDenis/fac', - 'details' => 'https://plugins.dotaddict.org/dc2/details/fac', + 'requires' => [['core', '2.24']], + 'permissions' => dcCore::app()->auth->makePermissions([ + dcAuth::PERMISSION_USAGE, + dcAuth::PERMISSION_CONTENT_ADMIN, + ]), + 'type' => 'plugin', + 'support' => 'https://github.com/JcDenis/fac', + 'details' => 'https://plugins.dotaddict.org/dc2/details/fac', 'repository' => 'https://raw.githubusercontent.com/JcDenis/fac/master/repository.xml', - 'settings' => [ - 'blog' => '#params.fac_params' - ] + 'settings' => [ + 'blog' => '#params.fac_params', + ], ] -); \ No newline at end of file +); diff --git a/_install.php b/_install.php index fd76d33..b1258f5 100644 --- a/_install.php +++ b/_install.php @@ -1,117 +1,126 @@ [ - 'name' => 'default', - 'dateformat' => '', - 'lineslimit' => '5', - 'linestitletext' => '%T', - 'linestitleover' => '%D', - 'linestitlelength' => '150', - 'showlinesdescription' => '0', - 'linesdescriptionlength' => '350', - 'linesdescriptionnohtml' => '1', - 'showlinescontent' => '0', - 'linescontentlength' => '350', - 'linescontentnohtml' => '1' + 'name' => 'default', + 'dateformat' => '', + 'lineslimit' => '5', + 'linestitletext' => '%T', + 'linestitleover' => '%D', + 'linestitlelength' => '150', + 'showlinesdescription' => '0', + 'linesdescriptionlength' => '350', + 'linesdescriptionnohtml' => '1', + 'showlinescontent' => '0', + 'linescontentlength' => '350', + 'linescontentnohtml' => '1', ], uniqid() => [ - 'name' => 'full', - 'dateformat' => '', - 'lineslimit' => '20', - 'linestitletext' => '%T', - 'linestitleover' => '%D - %E', - 'linestitlelength' => '', - 'showlinesdescription' => '1', - 'linesdescriptionlength' => '', - 'linesdescriptionnohtml' => '1', - 'showlinescontent' => '1', - 'linescontentlength' => '', - 'linescontentnohtml' => '1' - ] + 'name' => 'full', + 'dateformat' => '', + 'lineslimit' => '20', + 'linestitletext' => '%T', + 'linestitleover' => '%D - %E', + 'linestitlelength' => '', + 'showlinesdescription' => '1', + 'linesdescriptionlength' => '', + 'linesdescriptionnohtml' => '1', + 'showlinescontent' => '1', + 'linescontentlength' => '', + 'linescontentnohtml' => '1', + ], ]), 'string', false, - true + true, ], [ 'fac_defaultfeedtitle', 'Default title of feed', '%T', - 'string' + 'string', ], [ 'fac_showfeeddesc', 'Show description of feed', 1, - 'boolean' - ] + 'boolean', + ], ]; # -- 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; } # Check Dotclear version - if (!method_exists('dcUtils', 'versionsCompare') + if (!method_exists('dcUtils', 'versionsCompare') || dcUtils::versionsCompare(DC_VERSION, $dc_min, '<', false)) { throw new Exception(sprintf( - '%s requires Dotclear %s', $mod_id, $dc_min + '%s requires Dotclear %s', + $mod_id, + $dc_min )); } # Set module settings - $core->blog->settings->addNamespace($mod_id); - foreach($mod_conf as $v) { - $core->blog->settings->{$mod_id}->put( - $v[0], $v[2], $v[3], $v[1], false, true + dcCore::app()->blog->settings->addNamespace($mod_id); + foreach ($mod_conf as $v) { + dcCore::app()->blog->settings->{$mod_id}->put( + $v[0], + $v[2], + $v[3], + $v[1], + false, + true ); } # 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; -} \ No newline at end of file +} diff --git a/_public.php b/_public.php index 4286feb..6d510c5 100644 --- a/_public.php +++ b/_public.php @@ -1,23 +1,22 @@ addBehavior( +dcCore::app()->addBehavior( 'publicEntryAfterContent', - array('facPublic', 'publicEntryAfterContent') + ['facPublic', 'publicEntryAfterContent'] ); /** @@ -29,64 +28,64 @@ class facPublic { /** * Add feed after entry - * + * * @param dcCore $core dcCore instance * @param context $_ctx context instance */ public static function publicEntryAfterContent(dcCore $core, context $_ctx) { - $core->blog->settings->addNamespace('fac'); + dcCore::app()->blog->settings->addNamespace('fac'); # Not active or not a post - if (!$core->blog->settings->fac->fac_active - || !$_ctx->exists('posts')) { + if (!dcCore::app()->blog->settings->fac->fac_active + || !dcCore::app()->ctx->exists('posts')) { return null; } # Not in page to show - $types = @unserialize($core->blog->settings->fac->fac_public_tpltypes); + $types = @unserialize((string) dcCore::app()->blog->settings->fac->fac_public_tpltypes); if (!is_array($types) - || !in_array($core->url->type,$types)) { + || !in_array(dcCore::app()->url->type, $types)) { return null; } # Get related feed - $fac_url = $core->meta->getMetadata([ + $fac_url = dcCore::app()->meta->getMetadata([ 'meta_type' => 'fac', - 'post_id' => $_ctx->posts->post_id, - 'limit' => 1 + 'post_id' => dcCore::app()->ctx->posts->post_id, + 'limit' => 1, ]); if ($fac_url->isEmpty()) { return null; } # Get related format - $fac_format = $core->meta->getMetadata([ + $fac_format = dcCore::app()->meta->getMetadata([ 'meta_type' => 'facformat', - 'post_id' => $_ctx->posts->post_id, - 'limit' => 1 + 'post_id' => dcCore::app()->ctx->posts->post_id, + 'limit' => 1, ]); if ($fac_format->isEmpty()) { return null; } # Get format info - $default_format = array( - 'name' => 'default', - 'dateformat' => '', - 'lineslimit' => '5', - 'linestitletext' => '%T', - 'linestitleover' => '%D', - 'linestitlelength' => '150', - 'showlinesdescription' => '0', + $default_format = [ + 'name' => 'default', + 'dateformat' => '', + 'lineslimit' => '5', + 'linestitletext' => '%T', + 'linestitleover' => '%D', + 'linestitlelength' => '150', + 'showlinesdescription' => '0', 'linesdescriptionlength' => '350', 'linesdescriptionnohtml' => '1', - 'showlinescontent' => '0', - 'linescontentlength' => '350', - 'linescontentnohtml' => '1' - ); + 'showlinescontent' => '0', + 'linescontentlength' => '350', + 'linescontentnohtml' => '1', + ]; - $formats = @unserialize($core->blog->settings->fac->fac_formats); + $formats = @unserialize((string) dcCore::app()->blog->settings->fac->fac_formats); if (empty($formats) || !is_array($formats) || !isset($formats[$fac_format->meta_id])) { @@ -100,6 +99,7 @@ class facPublic # Read feed url $cache = is_dir(DC_TPL_CACHE . '/fac') ? DC_TPL_CACHE . '/fac' : null; + try { $feed = feedReader::quickParse($fac_url->meta_id, $cache); } catch (Exception $e) { @@ -113,91 +113,90 @@ class facPublic # Feed title $feedtitle = ''; - if ('' != $core->blog->settings->fac->fac_defaultfeedtitle) { - $feedtitle = '

' . html::escapeHTML(empty($feed->title) ? + if ('' != dcCore::app()->blog->settings->fac->fac_defaultfeedtitle) { + $feedtitle = '

' . html::escapeHTML( + empty($feed->title) ? str_replace( '%T', __('a related feed'), - $core->blog->settings->fac->fac_defaultfeedtitle - ) : + dcCore::app()->blog->settings->fac->fac_defaultfeedtitle + ) : str_replace( '%T', $feed->title, - $core->blog->settings->fac->fac_defaultfeedtitle + dcCore::app()->blog->settings->fac->fac_defaultfeedtitle ) ) . '

'; } # Feed desc $feeddesc = ''; - if ($core->blog->settings->fac->fac_showfeeddesc + if (dcCore::app()->blog->settings->fac->fac_showfeeddesc && '' != $feed->description) { - $feeddesc = - '

' . context::global_filters( - $feed->description, + $feeddesc = '

' . context::global_filters( + $feed->description, ['encode_xml', 'remove_html'] ) . '

'; } # Date format - $dateformat = '' != $format['dateformat'] ? + $dateformat = '' != $format['dateformat'] ? $format['dateformat'] : - $core->blog->settings->system->date_format . ',' . $core->blog->settings->system->time_format; + dcCore::app()->blog->settings->system->date_format . ',' . dcCore::app()->blog->settings->system->time_format; # Enrties limit - $entrieslimit = abs((integer) $format['lineslimit']); - $uselimit = $entrieslimit > 0 ? true : false; + $entrieslimit = abs((int) $format['lineslimit']); + $uselimit = $entrieslimit > 0 ? true : false; - echo + echo '
' . $feedtitle . $feeddesc . '
'; $i = 0; foreach ($feed->items as $item) { - # Format date $date = dt::dt2str($dateformat, $item->pubdate); # Entries title $title = context::global_filters( str_replace( - array( + [ '%D', '%T', '%A', '%E', - '%C' - ), - array( + '%C', + ], + [ $date, $item->title, $item->creator, $item->description, - $item->content - ), + $item->content, + ], $format['linestitletext'] ), - ['remove_html', 'cut_string' => abs((integer) $format['linestitlelength'])], + ['remove_html', 'cut_string' => abs((int) $format['linestitlelength'])], ); # Entries over title $overtitle = context::global_filters( str_replace( - array( + [ '%D', '%T', '%A', '%E', - '%C' - ), - array( + '%C', + ], + [ $date, $item->title, $item->creator, $item->description, - $item->content - ), + $item->content, + ], $format['linestitleover'] ), ['remove_html', 'cut_string' => 350], @@ -205,23 +204,23 @@ class facPublic # Entries description $description = ''; - if ($format['showlinesdescription'] + if ($format['showlinesdescription'] && '' != $item->description) { $description = '
' . context::global_filters( $item->description, - ['remove_html' => (integer) $format['linesdescriptionnohtml'], 'cut_string' => abs((integer) $format['linesdescriptionlength'])] + ['remove_html' => (int) $format['linesdescriptionnohtml'], 'cut_string' => abs((int) $format['linesdescriptionlength'])] ) . '
'; } # Entries content $content = ''; - if ($format['showlinescontent'] + if ($format['showlinescontent'] && '' != $item->content) { - $content = '
'. + $content = '
' . context::global_filters( $item->content, - ['remove_html' => (integer) $format['linescontentnohtml'], 'cut_string' => abs((integer) $format['linescontentlength'])] + ['remove_html' => (int) $format['linescontentnohtml'], 'cut_string' => abs((int) $format['linescontentlength'])] ) . '
'; } @@ -237,4 +236,4 @@ class facPublic } echo '
'; } -} \ No newline at end of file +} diff --git a/dcstore.xml b/dcstore.xml index 393aed1..4e2719e 100644 --- a/dcstore.xml +++ b/dcstore.xml @@ -1,12 +1,13 @@ + - -Feed after content -0.9.2 -Jean-Christian Denis and Contributors -Add RSS/Atom feeds after entries content -https://github.com/JcDenis/fac/releases/download/v0.9.2/plugin-fac.zip -2.19 -https://plugins.dotaddict.org/dc2/details/fac -https://github.com/JcDenis/fac - + + Feed after content + 0.10 + Jean-Christian Denis and Contributors + Add RSS/Atom feeds after entries content + https://github.com/JcDenis/fac/releases/download/v0.10/plugin-fac.zip + 2.24 + https://plugins.dotaddict.org/dc2/details/fac + https://github.com/JcDenis/fac + diff --git a/locales/en/resources.php b/locales/en/resources.php index 549b317..a011b3d 100644 --- a/locales/en/resources.php +++ b/locales/en/resources.php @@ -1,10 +1,11 @@ resources['help']['fac'] = __DIR__ . '/help/fac.html'; diff --git a/locales/fr/resources.php b/locales/fr/resources.php index 549b317..a011b3d 100644 --- a/locales/fr/resources.php +++ b/locales/fr/resources.php @@ -1,10 +1,11 @@ resources['help']['fac'] = __DIR__ . '/help/fac.html';