diff --git a/_admin.php b/_admin.php index 04244b0..aac7174 100644 --- a/_admin.php +++ b/_admin.php @@ -14,17 +14,17 @@ if (!defined('DC_CONTEXT_ADMIN')) { return null; } -dcCore::app()->blog->settings->addNamespace('fac'); +dcCore::app()->blog->settings->addNamespace(basename(__DIR__)); # Admin behaviors -dcCore::app()->addBehavior('adminBlogPreferencesFormV2', ['facAdmin', 'adminBlogPreferencesForm']); +dcCore::app()->addBehavior('adminBlogPreferencesFormV2', ['facAdmin', 'adminBlogPreferencesFormV2']); 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']); +dcCore::app()->addBehavior('adminPostsActions', ['facAdmin', 'adminPostsActions']); /** * @ingroup DC_PLUGIN_FAC @@ -65,7 +65,7 @@ class facAdmin * * @param dcSettings $blog_settings dcSettings instance */ - public static function adminBlogPreferencesForm(dcSettings $blog_settings) + public static function adminBlogPreferencesFormV2(dcSettings $blog_settings) { echo '

Feed after content

' . @@ -74,7 +74,7 @@ class facAdmin '

'; if (dcCore::app()->auth->isSuperAdmin()) { echo '

' . __('Configure formats') . '

'; @@ -84,23 +84,23 @@ class facAdmin '
' . '
' . __('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) . '

' . + form::field('fac_defaultfeedtitle', 65, 255, (string) $blog_settings->get(basename(__DIR__))->get('defaultfeedtitle')) . '

' . '

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

' . '

' . '
' . '
' . '
' . __('Show feed after content on:') . '
'; - $fac_public_tpltypes = @unserialize($blog_settings->fac->fac_public_tpltypes); + $fac_public_tpltypes = json_decode($blog_settings->get(basename(__DIR__))->get('public_tpltypes'), true); if (!is_array($fac_public_tpltypes)) { $fac_public_tpltypes = []; } @@ -128,10 +128,10 @@ class facAdmin */ 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'])); + $blog_settings->get(basename(__DIR__))->put('active', !empty($_POST['fac_active'])); + $blog_settings->get(basename(__DIR__))->put('public_tpltypes', json_encode($_POST['fac_public_tpltypes'])); + $blog_settings->get(basename(__DIR__))->put('defaultfeedtitle', (string) $_POST['fac_defaultfeedtitle']); + $blog_settings->get(basename(__DIR__))->put('showfeeddesc', !empty($_POST['fac_showfeeddesc'])); } /** @@ -141,7 +141,7 @@ class facAdmin */ public static function adminPostHeaders() { - return dcPage::jsLoad('index.php?pf=fac/js/admin.js'); + return dcPage::jsModuleLoad(basename(__DIR__) . '/js/admin.js'); } /** @@ -153,7 +153,7 @@ class facAdmin */ public static function adminPostFormItems(ArrayObject $main_items, ArrayObject $sidebar_items, $post) { - if (!dcCore::app()->blog->settings->fac->fac_active) { + if (!dcCore::app()->blog->settings->get(basename(__DIR__))->get('active')) { return null; } @@ -214,9 +214,9 @@ class facAdmin * * @param dcPostsActions $pa dcPostsActionsPage instance */ - public static function adminPostsActionsPage(dcPostsActions $pa) + public static function adminPostsActions(dcPostsActions $pa) { - if (!dcCore::app()->blog->settings->fac->fac_active) { + if (!dcCore::app()->blog->settings->get(basename(__DIR__))->get('active')) { return null; } @@ -329,7 +329,7 @@ class facAdmin */ protected static function formFeed($url = '', $format = '') { - if (!dcCore::app()->blog->settings->fac->fac_active) { + if (!dcCore::app()->blog->settings->get(basename(__DIR__))->get('active')) { return null; } @@ -364,7 +364,7 @@ class facAdmin */ protected static function comboFac() { - $formats = @unserialize(dcCore::app()->blog->settings->fac->fac_formats); + $formats = json_decode(dcCore::app()->blog->settings->get(basename(__DIR__))->get('formats'), true); if (!is_array($formats) || empty($formats)) { return []; } diff --git a/_config.php b/_config.php index c57518d..ce3e0d7 100644 --- a/_config.php +++ b/_config.php @@ -22,10 +22,9 @@ $redir = empty($_REQUEST['redir']) ? dcCore::app()->admin->list->getURL() . '#plugins' : $_REQUEST['redir']; # -- Get settings -- -dcCore::app()->blog->settings->addNamespace('fac'); -$s = dcCore::app()->blog->settings->fac; +$s = dcCore::app()->blog->settings->addNamespace(basename(__DIR__)); -$fac_formats = @unserialize($s->fac_formats); +$fac_formats = json_decode($s->get('formats'), true); if (!is_array($fac_formats)) { $fac_formats = []; @@ -43,10 +42,10 @@ if (!empty($_POST['save'])) { } // fix 2021.08.21 : formats are now global - $s->drop('fac_formats'); + $s->drop('formats'); $s->put( - 'fac_formats', - serialize($fac_formats), + 'formats', + json_encode($fac_formats), 'string', 'Formats of feeds contents', true, @@ -59,7 +58,7 @@ if (!empty($_POST['save'])) { __('Configuration successfully updated.') ); http::redirect( - dcCore::app()->admin->list->getURL('module=fac&conf=1&redir=' . dcCore::app()->admin->list->getRedir()) + dcCore::app()->admin->list->getURL('module=' . basename(__DIR__) . '&conf=1&redir=' . dcCore::app()->admin->list->getRedir()) ); } catch (Exception $e) { dcCore::app()->error->add($e->getMessage()); diff --git a/_install.php b/_install.php index bb55709..74fe4ba 100644 --- a/_install.php +++ b/_install.php @@ -14,24 +14,24 @@ if (!defined('DC_CONTEXT_ADMIN')) { return null; } -# -- Module specs -- +// Module specs $mod_conf = [ [ - 'fac_active', + 'active', 'Enabled fac plugin', false, 'boolean', ], [ - 'fac_public_tpltypes', + 'public_tpltypes', 'List of templates types which used fac', - serialize(['post', 'tag', 'archive']), + json_encode(['post', 'tag', 'archive']), 'string', ], [ - 'fac_formats', + 'formats', 'Formats of feeds contents', - serialize([ + json_encode([ uniqid() => [ 'name' => 'default', 'dateformat' => '', @@ -66,32 +66,56 @@ $mod_conf = [ true, ], [ - 'fac_defaultfeedtitle', + 'defaultfeedtitle', 'Default title of feed', '%T', 'string', ], [ - 'fac_showfeeddesc', + 'showfeeddesc', 'Show description of feed', 1, 'boolean', ], ]; -# -- Nothing to change below -- +// Nothing to change below try { - # Check module version + // Check module version if (!dcCore::app()->newVersion( - basename(__DIR__), + basename(__DIR__), dcCore::app()->plugins->moduleInfo(basename(__DIR__), 'version') )) { return null; } - # Set module settings + + // version < 1.0 : upgrade settings id and ns and array + $current = dcCore::app()->getVersion(basename(__DIR__)); + if ($current && version_compare($current, '1.0', '<')) { + $record = dcCore::app()->con->select( + 'SELECT * FROM ' . dcCore::app()->prefix . dcNamespace::NS_TABLE_NAME . ' ' . + "WHERE setting_ns = 'fac' " + ); + while ($record->fetch()) { + if (preg_match('/^fac_(.*?)$/', $record->setting_id, $match)) { + $cur = dcCore::app()->con->openCursor(dcCore::app()->prefix . dcNamespace::NS_TABLE_NAME); + if (in_array($record->setting_id, ['fac_public_tpltypes', 'fac_formats'])) { + $cur->setting_value = json_encode(@unserialize($record->setting_value)); + } + $cur->setting_id = $match[1]; + $cur->setting_ns = basename(__DIR__); + $cur->update( + "WHERE setting_id = '" . $record->setting_id . "' and setting_ns = 'fac' " . + 'AND blog_id ' . (null === $record->blog_id ? 'IS NULL ' : ("= '" . dcCore::app()->con->escape($record->blog_id) . "' ")) + ); + } + } + } + + // Set module settings dcCore::app()->blog->settings->addNamespace(basename(__DIR__)); foreach ($mod_conf as $v) { - dcCore::app()->blog->settings->__get(basename(__DIR__))->put( + dcCore::app()->blog->settings->get(basename(__DIR__))->put( $v[0], $v[2], $v[3], diff --git a/_public.php b/_public.php index f21cfac..091b216 100644 --- a/_public.php +++ b/_public.php @@ -15,16 +15,16 @@ if (!defined('DC_RC_PATH')) { } dcCore::app()->addBehavior('publicEntryAfterContent', function (dcCore $core, context $_ctx) { - dcCore::app()->blog->settings->addNamespace('fac'); + dcCore::app()->blog->settings->addNamespace(basename(__DIR__)); # Not active or not a post - if (!dcCore::app()->blog->settings->fac->fac_active + if (!dcCore::app()->blog->settings->get(basename(__DIR__))->get('active') || !dcCore::app()->ctx->exists('posts')) { return null; } # Not in page to show - $types = @unserialize((string) dcCore::app()->blog->settings->fac->fac_public_tpltypes); + $types = json_decode((string) dcCore::app()->blog->settings->get(basename(__DIR__))->get('public_tpltypes'), true); if (!is_array($types) || !in_array(dcCore::app()->url->type, $types)) { return null; @@ -66,7 +66,7 @@ dcCore::app()->addBehavior('publicEntryAfterContent', function (dcCore $core, co 'linescontentnohtml' => '1', ]; - $formats = @unserialize((string) dcCore::app()->blog->settings->fac->fac_formats); + $formats = json_decode((string) dcCore::app()->blog->settings->get(basename(__DIR__))->get('formats'), true); if (empty($formats) || !is_array($formats) || !isset($formats[$fac_format->meta_id])) { @@ -94,25 +94,25 @@ dcCore::app()->addBehavior('publicEntryAfterContent', function (dcCore $core, co # Feed title $feedtitle = ''; - if ('' != dcCore::app()->blog->settings->fac->fac_defaultfeedtitle) { + if ('' != dcCore::app()->blog->settings->get(basename(__DIR__))->get('defaultfeedtitle')) { $feedtitle = '

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

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

' . context::global_filters( $feed->description, @@ -123,7 +123,7 @@ dcCore::app()->addBehavior('publicEntryAfterContent', function (dcCore $core, co # Date format $dateformat = '' != $format['dateformat'] ? $format['dateformat'] : - dcCore::app()->blog->settings->system->date_format . ',' . dcCore::app()->blog->settings->system->time_format; + dcCore::app()->blog->settings->get('system')->get('date_format') . ',' . dcCore::app()->blog->settings->get('system')->get('time_format'); # Enrties limit $entrieslimit = abs((int) $format['lineslimit']);