update settings (short id and json_encode)
This commit is contained in:
parent
4ec48f950e
commit
89f54b08af
38
_admin.php
38
_admin.php
@ -14,17 +14,17 @@ if (!defined('DC_CONTEXT_ADMIN')) {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
dcCore::app()->blog->settings->addNamespace('fac');
|
dcCore::app()->blog->settings->addNamespace(basename(__DIR__));
|
||||||
|
|
||||||
# Admin behaviors
|
# Admin behaviors
|
||||||
dcCore::app()->addBehavior('adminBlogPreferencesFormV2', ['facAdmin', 'adminBlogPreferencesForm']);
|
dcCore::app()->addBehavior('adminBlogPreferencesFormV2', ['facAdmin', 'adminBlogPreferencesFormV2']);
|
||||||
dcCore::app()->addBehavior('adminBeforeBlogSettingsUpdate', ['facAdmin', 'adminBeforeBlogSettingsUpdate']);
|
dcCore::app()->addBehavior('adminBeforeBlogSettingsUpdate', ['facAdmin', 'adminBeforeBlogSettingsUpdate']);
|
||||||
dcCore::app()->addBehavior('adminPostHeaders', ['facAdmin', 'adminPostHeaders']);
|
dcCore::app()->addBehavior('adminPostHeaders', ['facAdmin', 'adminPostHeaders']);
|
||||||
dcCore::app()->addBehavior('adminPostFormItems', ['facAdmin', 'adminPostFormItems']);
|
dcCore::app()->addBehavior('adminPostFormItems', ['facAdmin', 'adminPostFormItems']);
|
||||||
dcCore::app()->addBehavior('adminAfterPostCreate', ['facAdmin', 'adminAfterPostSave']);
|
dcCore::app()->addBehavior('adminAfterPostCreate', ['facAdmin', 'adminAfterPostSave']);
|
||||||
dcCore::app()->addBehavior('adminAfterPostUpdate', ['facAdmin', 'adminAfterPostSave']);
|
dcCore::app()->addBehavior('adminAfterPostUpdate', ['facAdmin', 'adminAfterPostSave']);
|
||||||
dcCore::app()->addBehavior('adminBeforePostDelete', ['facAdmin', 'adminBeforePostDelete']);
|
dcCore::app()->addBehavior('adminBeforePostDelete', ['facAdmin', 'adminBeforePostDelete']);
|
||||||
dcCore::app()->addBehavior('adminPostsActions', ['facAdmin', 'adminPostsActionsPage']);
|
dcCore::app()->addBehavior('adminPostsActions', ['facAdmin', 'adminPostsActions']);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ingroup DC_PLUGIN_FAC
|
* @ingroup DC_PLUGIN_FAC
|
||||||
@ -65,7 +65,7 @@ class facAdmin
|
|||||||
*
|
*
|
||||||
* @param dcSettings $blog_settings dcSettings instance
|
* @param dcSettings $blog_settings dcSettings instance
|
||||||
*/
|
*/
|
||||||
public static function adminBlogPreferencesForm(dcSettings $blog_settings)
|
public static function adminBlogPreferencesFormV2(dcSettings $blog_settings)
|
||||||
{
|
{
|
||||||
echo
|
echo
|
||||||
'<div class="fieldset"><h4 id="fac_params">Feed after content</h4>' .
|
'<div class="fieldset"><h4 id="fac_params">Feed after content</h4>' .
|
||||||
@ -74,7 +74,7 @@ class facAdmin
|
|||||||
'</p>';
|
'</p>';
|
||||||
if (dcCore::app()->auth->isSuperAdmin()) {
|
if (dcCore::app()->auth->isSuperAdmin()) {
|
||||||
echo '<p><a href="' . dcCore::app()->adminurl->get('admin.plugins', [
|
echo '<p><a href="' . dcCore::app()->adminurl->get('admin.plugins', [
|
||||||
'module' => 'fac',
|
'module' => basename(__DIR__),
|
||||||
'conf' => 1,
|
'conf' => 1,
|
||||||
'redir' => dcCore::app()->adminurl->get('admin.blog.pref') . '#fac_params',
|
'redir' => dcCore::app()->adminurl->get('admin.blog.pref') . '#fac_params',
|
||||||
]) . '">' . __('Configure formats') . '</a></p>';
|
]) . '">' . __('Configure formats') . '</a></p>';
|
||||||
@ -84,23 +84,23 @@ class facAdmin
|
|||||||
'<div class="col">' .
|
'<div class="col">' .
|
||||||
'<h5>' . __('Activation') . '</h5>' .
|
'<h5>' . __('Activation') . '</h5>' .
|
||||||
'<p><label class="classic">' .
|
'<p><label class="classic">' .
|
||||||
form::checkbox('fac_active', '1', (bool) $blog_settings->fac->fac_active) .
|
form::checkbox('fac_active', '1', (bool) $blog_settings->get(basename(__DIR__))->get('active')) .
|
||||||
__('Enable "fac" extension') . '</label></p>' .
|
__('Enable "fac" extension') . '</label></p>' .
|
||||||
'<p class="form-note">' .
|
'<p class="form-note">' .
|
||||||
__('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.') .
|
||||||
'</p>' .
|
'</p>' .
|
||||||
'<h5>' . __('Feed') . '</h5>' .
|
'<h5>' . __('Feed') . '</h5>' .
|
||||||
'<p><label for="fac_defaultfeedtitle">' . __('Default title') . '</label>' .
|
'<p><label for="fac_defaultfeedtitle">' . __('Default title') . '</label>' .
|
||||||
form::field('fac_defaultfeedtitle', 65, 255, (string) $blog_settings->fac->fac_defaultfeedtitle) . '</p>' .
|
form::field('fac_defaultfeedtitle', 65, 255, (string) $blog_settings->get(basename(__DIR__))->get('defaultfeedtitle')) . '</p>' .
|
||||||
'<p class="form-note">' . __('Use %T to insert title of feed.') . '</p>' .
|
'<p class="form-note">' . __('Use %T to insert title of feed.') . '</p>' .
|
||||||
'<p><label class="classic" for="fac_showfeeddesc">' .
|
'<p><label class="classic" for="fac_showfeeddesc">' .
|
||||||
form::checkbox('fac_showfeeddesc', 1, (bool) $blog_settings->fac->fac_showfeeddesc) .
|
form::checkbox('fac_showfeeddesc', 1, (bool) $blog_settings->get(basename(__DIR__))->get('showfeeddesc')) .
|
||||||
__('Show description of feed') . '</label></p>' .
|
__('Show description of feed') . '</label></p>' .
|
||||||
'</div>' .
|
'</div>' .
|
||||||
'<div class="col">' .
|
'<div class="col">' .
|
||||||
'<h5>' . __('Show feed after content on:') . '</h5>';
|
'<h5>' . __('Show feed after content on:') . '</h5>';
|
||||||
|
|
||||||
$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)) {
|
if (!is_array($fac_public_tpltypes)) {
|
||||||
$fac_public_tpltypes = [];
|
$fac_public_tpltypes = [];
|
||||||
}
|
}
|
||||||
@ -128,10 +128,10 @@ class facAdmin
|
|||||||
*/
|
*/
|
||||||
public static function adminBeforeBlogSettingsUpdate(dcSettings $blog_settings)
|
public static function adminBeforeBlogSettingsUpdate(dcSettings $blog_settings)
|
||||||
{
|
{
|
||||||
$blog_settings->fac->put('fac_active', !empty($_POST['fac_active']));
|
$blog_settings->get(basename(__DIR__))->put('active', !empty($_POST['fac_active']));
|
||||||
$blog_settings->fac->put('fac_public_tpltypes', serialize($_POST['fac_public_tpltypes']));
|
$blog_settings->get(basename(__DIR__))->put('public_tpltypes', json_encode($_POST['fac_public_tpltypes']));
|
||||||
$blog_settings->fac->put('fac_defaultfeedtitle', (string) $_POST['fac_defaultfeedtitle']);
|
$blog_settings->get(basename(__DIR__))->put('defaultfeedtitle', (string) $_POST['fac_defaultfeedtitle']);
|
||||||
$blog_settings->fac->put('fac_showfeeddesc', !empty($_POST['fac_showfeeddesc']));
|
$blog_settings->get(basename(__DIR__))->put('showfeeddesc', !empty($_POST['fac_showfeeddesc']));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -141,7 +141,7 @@ class facAdmin
|
|||||||
*/
|
*/
|
||||||
public static function adminPostHeaders()
|
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)
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -214,9 +214,9 @@ class facAdmin
|
|||||||
*
|
*
|
||||||
* @param dcPostsActions $pa dcPostsActionsPage instance
|
* @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;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -329,7 +329,7 @@ class facAdmin
|
|||||||
*/
|
*/
|
||||||
protected static function formFeed($url = '', $format = '')
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -364,7 +364,7 @@ class facAdmin
|
|||||||
*/
|
*/
|
||||||
protected static function comboFac()
|
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)) {
|
if (!is_array($formats) || empty($formats)) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
13
_config.php
13
_config.php
@ -22,10 +22,9 @@ $redir = empty($_REQUEST['redir']) ?
|
|||||||
dcCore::app()->admin->list->getURL() . '#plugins' : $_REQUEST['redir'];
|
dcCore::app()->admin->list->getURL() . '#plugins' : $_REQUEST['redir'];
|
||||||
|
|
||||||
# -- Get settings --
|
# -- Get settings --
|
||||||
dcCore::app()->blog->settings->addNamespace('fac');
|
$s = dcCore::app()->blog->settings->addNamespace(basename(__DIR__));
|
||||||
$s = dcCore::app()->blog->settings->fac;
|
|
||||||
|
|
||||||
$fac_formats = @unserialize($s->fac_formats);
|
$fac_formats = json_decode($s->get('formats'), true);
|
||||||
|
|
||||||
if (!is_array($fac_formats)) {
|
if (!is_array($fac_formats)) {
|
||||||
$fac_formats = [];
|
$fac_formats = [];
|
||||||
@ -43,10 +42,10 @@ if (!empty($_POST['save'])) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// fix 2021.08.21 : formats are now global
|
// fix 2021.08.21 : formats are now global
|
||||||
$s->drop('fac_formats');
|
$s->drop('formats');
|
||||||
$s->put(
|
$s->put(
|
||||||
'fac_formats',
|
'formats',
|
||||||
serialize($fac_formats),
|
json_encode($fac_formats),
|
||||||
'string',
|
'string',
|
||||||
'Formats of feeds contents',
|
'Formats of feeds contents',
|
||||||
true,
|
true,
|
||||||
@ -59,7 +58,7 @@ if (!empty($_POST['save'])) {
|
|||||||
__('Configuration successfully updated.')
|
__('Configuration successfully updated.')
|
||||||
);
|
);
|
||||||
http::redirect(
|
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) {
|
} catch (Exception $e) {
|
||||||
dcCore::app()->error->add($e->getMessage());
|
dcCore::app()->error->add($e->getMessage());
|
||||||
|
50
_install.php
50
_install.php
@ -14,24 +14,24 @@ if (!defined('DC_CONTEXT_ADMIN')) {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
# -- Module specs --
|
// Module specs
|
||||||
$mod_conf = [
|
$mod_conf = [
|
||||||
[
|
[
|
||||||
'fac_active',
|
'active',
|
||||||
'Enabled fac plugin',
|
'Enabled fac plugin',
|
||||||
false,
|
false,
|
||||||
'boolean',
|
'boolean',
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'fac_public_tpltypes',
|
'public_tpltypes',
|
||||||
'List of templates types which used fac',
|
'List of templates types which used fac',
|
||||||
serialize(['post', 'tag', 'archive']),
|
json_encode(['post', 'tag', 'archive']),
|
||||||
'string',
|
'string',
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'fac_formats',
|
'formats',
|
||||||
'Formats of feeds contents',
|
'Formats of feeds contents',
|
||||||
serialize([
|
json_encode([
|
||||||
uniqid() => [
|
uniqid() => [
|
||||||
'name' => 'default',
|
'name' => 'default',
|
||||||
'dateformat' => '',
|
'dateformat' => '',
|
||||||
@ -66,32 +66,56 @@ $mod_conf = [
|
|||||||
true,
|
true,
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'fac_defaultfeedtitle',
|
'defaultfeedtitle',
|
||||||
'Default title of feed',
|
'Default title of feed',
|
||||||
'%T',
|
'%T',
|
||||||
'string',
|
'string',
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'fac_showfeeddesc',
|
'showfeeddesc',
|
||||||
'Show description of feed',
|
'Show description of feed',
|
||||||
1,
|
1,
|
||||||
'boolean',
|
'boolean',
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
# -- Nothing to change below --
|
// Nothing to change below
|
||||||
try {
|
try {
|
||||||
# Check module version
|
// Check module version
|
||||||
if (!dcCore::app()->newVersion(
|
if (!dcCore::app()->newVersion(
|
||||||
basename(__DIR__),
|
basename(__DIR__),
|
||||||
dcCore::app()->plugins->moduleInfo(basename(__DIR__), 'version')
|
dcCore::app()->plugins->moduleInfo(basename(__DIR__), 'version')
|
||||||
)) {
|
)) {
|
||||||
return null;
|
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__));
|
dcCore::app()->blog->settings->addNamespace(basename(__DIR__));
|
||||||
foreach ($mod_conf as $v) {
|
foreach ($mod_conf as $v) {
|
||||||
dcCore::app()->blog->settings->__get(basename(__DIR__))->put(
|
dcCore::app()->blog->settings->get(basename(__DIR__))->put(
|
||||||
$v[0],
|
$v[0],
|
||||||
$v[2],
|
$v[2],
|
||||||
$v[3],
|
$v[3],
|
||||||
|
18
_public.php
18
_public.php
@ -15,16 +15,16 @@ if (!defined('DC_RC_PATH')) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dcCore::app()->addBehavior('publicEntryAfterContent', function (dcCore $core, context $_ctx) {
|
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
|
# 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')) {
|
|| !dcCore::app()->ctx->exists('posts')) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Not in page to show
|
# 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)
|
if (!is_array($types)
|
||||||
|| !in_array(dcCore::app()->url->type, $types)) {
|
|| !in_array(dcCore::app()->url->type, $types)) {
|
||||||
return null;
|
return null;
|
||||||
@ -66,7 +66,7 @@ dcCore::app()->addBehavior('publicEntryAfterContent', function (dcCore $core, co
|
|||||||
'linescontentnohtml' => '1',
|
'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)
|
if (empty($formats)
|
||||||
|| !is_array($formats)
|
|| !is_array($formats)
|
||||||
|| !isset($formats[$fac_format->meta_id])) {
|
|| !isset($formats[$fac_format->meta_id])) {
|
||||||
@ -94,25 +94,25 @@ dcCore::app()->addBehavior('publicEntryAfterContent', function (dcCore $core, co
|
|||||||
|
|
||||||
# Feed title
|
# Feed title
|
||||||
$feedtitle = '';
|
$feedtitle = '';
|
||||||
if ('' != dcCore::app()->blog->settings->fac->fac_defaultfeedtitle) {
|
if ('' != dcCore::app()->blog->settings->get(basename(__DIR__))->get('defaultfeedtitle')) {
|
||||||
$feedtitle = '<h3>' . html::escapeHTML(
|
$feedtitle = '<h3>' . html::escapeHTML(
|
||||||
empty($feed->title) ?
|
empty($feed->title) ?
|
||||||
str_replace(
|
str_replace(
|
||||||
'%T',
|
'%T',
|
||||||
__('a related feed'),
|
__('a related feed'),
|
||||||
dcCore::app()->blog->settings->fac->fac_defaultfeedtitle
|
dcCore::app()->blog->settings->get(basename(__DIR__))->get('defaultfeedtitle')
|
||||||
) :
|
) :
|
||||||
str_replace(
|
str_replace(
|
||||||
'%T',
|
'%T',
|
||||||
$feed->title,
|
$feed->title,
|
||||||
dcCore::app()->blog->settings->fac->fac_defaultfeedtitle
|
dcCore::app()->blog->settings->get(basename(__DIR__))->get('defaultfeedtitle')
|
||||||
)
|
)
|
||||||
) . '</h3>';
|
) . '</h3>';
|
||||||
}
|
}
|
||||||
|
|
||||||
# Feed desc
|
# Feed desc
|
||||||
$feeddesc = '';
|
$feeddesc = '';
|
||||||
if (dcCore::app()->blog->settings->fac->fac_showfeeddesc
|
if (dcCore::app()->blog->settings->get(basename(__DIR__))->get('showfeeddesc')
|
||||||
&& '' != $feed->description) {
|
&& '' != $feed->description) {
|
||||||
$feeddesc = '<p>' . context::global_filters(
|
$feeddesc = '<p>' . context::global_filters(
|
||||||
$feed->description,
|
$feed->description,
|
||||||
@ -123,7 +123,7 @@ dcCore::app()->addBehavior('publicEntryAfterContent', function (dcCore $core, co
|
|||||||
# Date format
|
# Date format
|
||||||
$dateformat = '' != $format['dateformat'] ?
|
$dateformat = '' != $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
|
# Enrties limit
|
||||||
$entrieslimit = abs((int) $format['lineslimit']);
|
$entrieslimit = abs((int) $format['lineslimit']);
|
||||||
|
Loading…
Reference in New Issue
Block a user