diff --git a/CHANGELOG.md b/CHANGELOG.md index 57f026b..a96c351 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +fac 0.9 + * split superadmin and admin config + * move blog settings from plugin config to blog pref + * fix help + * use php short array code + fac 0.8.1 * fix context filters diff --git a/README.md b/README.md index 1ca864b..967abbc 100644 --- a/README.md +++ b/README.md @@ -12,9 +12,10 @@ to link en extenal feed to the bottom of an entry. fac requires: + * superadmin to configure feeds formats * admin permissions to configure plugin * usage,contentadmin permissions to link feeds - * Dotclear 2.6 + * Dotclear 2.19 * A theme that contents behavior publicEntryAfterContent ## USAGE @@ -22,6 +23,9 @@ to link en extenal feed to the bottom of an entry. First install fac, manualy from a zip package or from Dotaddict repository. (See Dotclear's documentation to know how do this) +Superadmin can configure, add, remove feeds formats on plugins configuration. +Admin can configure fac activation et selected page where to display feeds. + When you edit a post you have a new sidebar menu called "Linked feed" to link a feed to this post. diff --git a/_admin.php b/_admin.php index 9c22eb9..35e937b 100644 --- a/_admin.php +++ b/_admin.php @@ -17,12 +17,9 @@ if (!defined('DC_CONTEXT_ADMIN')) { $core->blog->settings->addNamespace('fac'); -# Not active -if (!$core->blog->settings->fac->fac_active) { - return null; -} - # 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']); @@ -37,6 +34,101 @@ $core->addBehavior('adminPostsActionsPage', ['facAdmin', 'adminPostsActionsPage' */ 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) + { + $types = [ + __('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) { + $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) + { + 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.') . + '

' . + '
' . + '
' . + '
' . __('Activation') . '
' . + '

' . + '

' . + __("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.') . '

' . + '

' . + '
' . + '
' . + '
' . __('Show feed after content on:') . '
'; + + $fac_public_tpltypes = @unserialize($blog_settings->fac->fac_public_tpltypes); + if (!is_array($fac_public_tpltypes)) { + $fac_public_tpltypes = []; + } + foreach(self::getPostsTypes($core) as $k => $v) { + echo ' +

'; + } + + echo + '
' . + '
' . + '
' . + '
'; + + } + + /** + * Save blog settings + * + * @param dcSettings $blog_settings dcSettings instance + */ + public static function adminBeforeBlogSettingsUpdate(dcSettings $blog_settings) + { + $blog_settings->fac->put('fac_active', !empty($_POST['fac_active'])); + $blog_settings->fac->put('fac_public_tpltypes', serialize($_POST['fac_public_tpltypes'])); + $blog_settings->fac->put('fac_defaultfeedtitle', (string) $_POST['fac_defaultfeedtitle']); + $blog_settings->fac->put('fac_showfeeddesc', !empty($_POST['fac_showfeeddesc'])); + } + /** * Add javascript (toggle) * @@ -58,22 +150,26 @@ class facAdmin { global $core; + if (!$core->blog->settings->fac->fac_active) { + return null; + } + # Get existing linked feed $fac_url = $fac_format = ''; if ($post) { - $rs = $core->meta->getMetadata(array( + $rs = $core->meta->getMetadata([ 'meta_type' => 'fac', 'post_id' => $post->post_id, 'limit' => 1 - )); + ]); $fac_url = $rs->isEmpty() ? '' : $rs->meta_id; - $rs = $core->meta->getMetadata(array( + $rs = $core->meta->getMetadata([ 'meta_type' => 'facformat', 'post_id' => $post->post_id, 'limit' => 1 - )); + ]); $fac_format = $rs->isEmpty() ? '' : $rs->meta_id; } @@ -122,25 +218,21 @@ class facAdmin */ public static function adminPostsActionsPage(dcCore $core, dcPostsActionsPage $pa) { + if (!$core->blog->settings->fac->fac_active) { + return null; + } + $pa->addAction( - array( - __('Linked feed') => array( - __('Add feed') => 'fac_add' - ) - ), - array('facAdmin', 'callbackAdd') + [__('Linked feed') => [__('Add feed') => 'fac_add']], + ['facAdmin', 'callbackAdd'] ); if (!$core->auth->check('delete,contentadmin', $core->blog->id)) { return null; } $pa->addAction( - array( - __('Linked feed') => array( - __('Remove feed') => 'fac_remove' - ) - ), - array('facAdmin', 'callbackRemove') + [__('Linked feed') => [__('Remove feed') => 'fac_remove']], + ['facAdmin', 'callbackRemove'] ); } @@ -164,7 +256,7 @@ class facAdmin throw new Exception(__('No enough right')); } - # Delete expired date + # Delete unused feed foreach($posts_ids as $post_id) { self::delFeed($core, $post_id); } @@ -182,7 +274,7 @@ class facAdmin */ public static function callbackAdd(dcCore $core, dcPostsActionsPage $pa, ArrayObject $post) { - # No entry + # No entry $posts_ids = $pa->getIDs(); if (empty($posts_ids)) { throw new Exception(__('No entry selected')); @@ -202,11 +294,11 @@ class facAdmin # Display form } else { $pa->beginPage( - dcPage::breadcrumb(array( + dcPage::breadcrumb([ html::escapeHTML($core->blog->name) => '', $pa->getCallerTitle() => $pa->getRedirection(true), __('Linked feed to this selection') => '' - )) + ]) ); echo @@ -218,7 +310,7 @@ class facAdmin '

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

' . ''; @@ -236,6 +328,10 @@ class facAdmin */ protected static function formFeed(dcCore $core, $url = '', $format = '') { + if (!$core->blog->settings->fac->fac_active) { + return null; + } + return '
' . '
' . __('Linked feed') . '
' . @@ -270,10 +366,10 @@ class facAdmin { $formats = @unserialize($core->blog->settings->fac->fac_formats); if (!is_array($formats) || empty($formats)) { - return array(); + return []; } - $res = array(); + $res = []; foreach($formats as $uid => $f) { $res[$f['name']] = $uid; } diff --git a/_config.php b/_config.php index 8254d19..4392759 100644 --- a/_config.php +++ b/_config.php @@ -18,49 +18,20 @@ if (!defined('DC_CONTEXT_MODULE')) { $redir = empty($_REQUEST['redir']) ? $list->getURL() . '#plugins' : $_REQUEST['redir']; -# -- Combos of types of supported public pages -- -$types = [ - __('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) { - $types[sprintf( - __('"%s" pages from extension muppet'), - $v['name'] - )] = $k; - } -} - # -- Get settings -- $core->blog->settings->addNamespace('fac'); $s = $core->blog->settings->fac; -$fac_active = (boolean) $s->fac_active; -$fac_defaultfeedtitle = (string) $s->fac_defaultfeedtitle; -$fac_showfeeddesc = (boolean) $s->fac_showfeeddesc; -$fac_public_tpltypes = @unserialize($s->fac_public_tpltypes); -$fac_formats = @unserialize($s->fac_formats); +$fac_formats = @unserialize($s->fac_formats); -if (!is_array($fac_public_tpltypes)) { - $fac_public_tpltypes = array(); -} if (!is_array($fac_formats)) { - $fac_formats = array(); + $fac_formats = []; } # -- Set settings -- if (!empty($_POST['save'])) { try { - $fac_active = !empty($_POST['fac_active']); - $fac_defaultfeedtitle = (string) $_POST['fac_defaultfeedtitle']; - $fac_showfeeddesc = !empty($_POST['fac_showfeeddesc']); - $fac_public_tpltypes = $_POST['fac_public_tpltypes']; - $fac_formats = array(); + $fac_formats = []; foreach($_POST['fac_formats'] as $uid => $f) { if (!empty($f['name'])) { @@ -68,11 +39,16 @@ if (!empty($_POST['save'])) { } } - $s->put('fac_active', $fac_active); - $s->put('fac_defaultfeedtitle', $fac_defaultfeedtitle); - $s->put('fac_showfeeddesc', $fac_showfeeddesc); - $s->put('fac_public_tpltypes', serialize($fac_public_tpltypes)); - $s->put('fac_formats', serialize($fac_formats)); + // 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, + true + ); $core->blog->triggerBlog(); @@ -82,47 +58,12 @@ if (!empty($_POST['save'])) { http::redirect( $list->getURL('module=fac&conf=1&redir=' . $list->getRedir()) ); - } - catch (Exception $e) { + } catch (Exception $e) { $core->error->add($e->getMessage()); } } # -- Display form -- -echo ' -
-

' . __('Activation') . '

- -

- -
' . __('Show feed after content on:') . '
'; - -foreach($types as $k => $v) { - echo ' -

'; -} -echo ' -
- -
-

' . __('Feed') . '

- -

' . -form::field('fac_defaultfeedtitle', 65, 255, $fac_defaultfeedtitle) . '

-

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

- -

- -
'; $i = 1; foreach($fac_formats as $uid => $f) { @@ -139,10 +80,10 @@ foreach($fac_formats as $uid => $f) {

' . form::field( - array( + [ 'fac_formats[' . $uid . '][name]', 'fac_formats_' . $uid . '_name' - ), + ], 20, 255, empty($f['name']) ? '' : $f['name'], @@ -155,10 +96,10 @@ foreach($fac_formats as $uid => $f) {

' . form::field( - array( + [ 'fac_formats[' . $uid . '][dateformat]', 'fac_formats_' . $uid . '_dateformat' - ), + ], 20, 255, empty($f['dateformat']) ? '' : $f['dateformat'], @@ -171,10 +112,10 @@ foreach($fac_formats as $uid => $f) {

' . form::field( - array( + [ 'fac_formats[' . $uid . '][lineslimit]', 'fac_formats_' . $uid . '_lineslimit' - ), + ], 5, 4, empty($f['lineslimit']) ? '' : $f['lineslimit'], @@ -189,10 +130,10 @@ foreach($fac_formats as $uid => $f) {

' . form::field( - array( + [ 'fac_formats[' . $uid . '][linestitletext]', 'fac_formats_' . $uid . '_linestitletext' - ), + ], 20, 255, empty($f['linestitletext']) ? '' : $f['linestitletext'], @@ -210,10 +151,10 @@ foreach($fac_formats as $uid => $f) {

' . form::field( - array( + [ 'fac_formats[' . $uid . '][linestitleover]', 'fac_formats_' . $uid . '_linestitleover' - ), + ], 20, 255, empty($f['linestitleover']) ? '' : $f['linestitleover'], @@ -231,10 +172,10 @@ foreach($fac_formats as $uid => $f) {

' . form::field( - array( + [ 'fac_formats[' . $uid . '][linestitlelength]', 'fac_formats_' . $uid . '_linestitlelength' - ), + ], 5, 4, empty($f['linestitlelength']) ? '' : $f['linestitlelength'], @@ -248,10 +189,10 @@ foreach($fac_formats as $uid => $f) {

' . form::field( - array( + [ 'fac_formats[' . $uid . '][linesdescriptionlength]', 'fac_formats_' . $uid . '_linesdescriptionlength' - ), + ], 5, 4, empty($f['linesdescriptionlength']) ? '' : $f['linesdescriptionlength'], @@ -288,10 +229,10 @@ foreach($fac_formats as $uid => $f) {

' . form::field( - array( + [ 'fac_formats[' . $uid . '][linescontentlength]', 'fac_formats_' . $uid . '_linescontentlength' - ), + ], 5, 4, empty($f['linescontentlength']) ? '' : $f['linescontentlength'], @@ -341,10 +282,10 @@ echo '

' . form::field( - array( + [ 'fac_formats[' . $uid . '][name]', 'fac_formats_' . $uid . '_name' - ), + ], 20, 255, '', @@ -357,10 +298,10 @@ __('In order to remove a format, leave its name empty.') .

' . form::field( - array( + [ 'fac_formats[' . $uid . '][dateformat]', 'fac_formats_' . $uid . '_dateformat' - ), + ], 20, 255, '', @@ -373,10 +314,10 @@ __('Use date format of Dotclear or leave empty to use default date format of blo

' . form::field( - array( + [ 'fac_formats[' . $uid . '][lineslimit]', 'fac_formats_' . $uid . '_lineslimit' - ), + ], 5, 4, 5, @@ -391,10 +332,10 @@ __('Leave lengh empty for no limit.') .

' . form::field( - array( + [ 'fac_formats[' . $uid . '][linestitletext]', 'fac_formats_' . $uid . '_linestitletext' - ), + ], 20, 255, '%T', @@ -412,10 +353,10 @@ __('Format can be:') .

' . form::field( - array( + [ 'fac_formats[' . $uid . '][linestitleover]', 'fac_formats_' . $uid . '_linestitleover' - ), + ], 20, 255, '%D', @@ -433,10 +374,10 @@ __('Format can be:') .

' . form::field( - array( + [ 'fac_formats[' . $uid . '][linestitlelength]', 'fac_formats_' . $uid . '_linestitlelength' - ), + ], 5, 4, 150, @@ -450,10 +391,10 @@ __('Leave lengh empty for no limit.') .

' . form::field( - array( + [ 'fac_formats[' . $uid . '][linesdescriptionlength]', 'fac_formats_' . $uid . '_linesdescriptionlength' - ), + ], 5, 4, 350, @@ -490,10 +431,10 @@ __('Leave lengh empty for no limit.') .

' . form::field( - array( + [ 'fac_formats[' . $uid . '][linescontentlength]', 'fac_formats_' . $uid . '_linescontentlength' - ), + ], 5, 4, 350, @@ -557,4 +498,6 @@ __('To add feed to an entry edit this entry and put in sidebar the url of the fe

-'; \ No newline at end of file +'; + +dcPage::helpBlock('fac'); \ No newline at end of file diff --git a/_define.php b/_define.php index 43768ba..997825a 100644 --- a/_define.php +++ b/_define.php @@ -23,7 +23,7 @@ $this->registerModule( [ 'permissions' => 'usage,contentadmin', 'type' => 'plugin', - 'dc_min' => '2.18', + 'dc_min' => '2.19', 'support' => 'https://github.com/JcDenis/fac', 'details' => 'https://plugins.dotaddict.org/dc2/details/fac' ] diff --git a/_install.php b/_install.php index dcccebb..dc2021f 100644 --- a/_install.php +++ b/_install.php @@ -16,27 +16,26 @@ if (!defined('DC_CONTEXT_ADMIN')) { } # -- Module specs -- - -$dc_min = '2.6'; +$dc_min = '2.19'; $mod_id = 'fac'; -$mod_conf = array( - array( +$mod_conf = [ + [ 'fac_active', 'Enabled fac plugin', false, 'boolean' - ), - array( + ], + [ 'fac_public_tpltypes', 'List of templates types which used fac', - serialize(array('post', 'tag', 'archive')), + serialize(['post', 'tag', 'archive']), 'string' - ), - array( + ], + [ 'fac_formats', 'Formats of feeds contents', - serialize(array( - uniqid() => array( + serialize([ + uniqid() => [ 'name' => 'default', 'dateformat' => '', 'lineslimit' => '5', @@ -49,8 +48,8 @@ $mod_conf = array( 'showlinescontent' => '0', 'linescontentlength' => '350', 'linescontentnohtml' => '1' - ), - uniqid() => array( + ], + uniqid() => [ 'name' => 'full', 'dateformat' => '', 'lineslimit' => '20', @@ -63,38 +62,35 @@ $mod_conf = array( 'showlinescontent' => '1', 'linescontentlength' => '', 'linescontentnohtml' => '1' - ) - )), - 'string' - ), - array( + ] + ]), + 'string', + false, + true + ], + [ 'fac_defaultfeedtitle', 'Default title of feed', '%T', 'string' - ), - array( + ], + [ 'fac_showfeeddesc', 'Show description of feed', 1, 'boolean' - ) -); + ] +]; # -- Nothing to change below -- - try { - # Check module version if (version_compare( $core->getVersion($mod_id), $core->plugins->moduleInfo($mod_id, 'version'), - '>=' - )) { - + '>=')) { return null; } - # Check Dotclear version if (!method_exists('dcUtils', 'versionsCompare') || dcUtils::versionsCompare(DC_VERSION, $dc_min, '<', false)) { @@ -102,7 +98,6 @@ try { '%s requires Dotclear %s', $mod_id, $dc_min )); } - # Set module settings $core->blog->settings->addNamespace($mod_id); foreach($mod_conf as $v) { @@ -110,17 +105,13 @@ try { $v[0], $v[2], $v[3], $v[1], false, true ); } - # Set module version $core->setVersion( $mod_id, $core->plugins->moduleInfo($mod_id, 'version') ); - return true; -} -catch (Exception $e) { +} catch (Exception $e) { $core->error->add($e->getMessage()); - return false; } \ No newline at end of file diff --git a/locales/en/help/fac.html b/locales/en/help/fac.html index f782827..792d9d9 100644 --- a/locales/en/help/fac.html +++ b/locales/en/help/fac.html @@ -10,9 +10,8 @@

If you want some help or contribute to the plugin fac, follow these links.

diff --git a/locales/fr/help/fac.html b/locales/fr/help/fac.html index 3add172..99b7a95 100644 --- a/locales/fr/help/fac.html +++ b/locales/fr/help/fac.html @@ -11,9 +11,8 @@

Si vous souhaitez plus d'aide ou apporter votre contribution à cette extension, voici quelques liens utiles.