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;
|
||||
}
|
||||
|
||||
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
|
||||
'<div class="fieldset"><h4 id="fac_params">Feed after content</h4>' .
|
||||
@ -74,7 +74,7 @@ class facAdmin
|
||||
'</p>';
|
||||
if (dcCore::app()->auth->isSuperAdmin()) {
|
||||
echo '<p><a href="' . dcCore::app()->adminurl->get('admin.plugins', [
|
||||
'module' => 'fac',
|
||||
'module' => basename(__DIR__),
|
||||
'conf' => 1,
|
||||
'redir' => dcCore::app()->adminurl->get('admin.blog.pref') . '#fac_params',
|
||||
]) . '">' . __('Configure formats') . '</a></p>';
|
||||
@ -84,23 +84,23 @@ class facAdmin
|
||||
'<div class="col">' .
|
||||
'<h5>' . __('Activation') . '</h5>' .
|
||||
'<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>' .
|
||||
'<p class="form-note">' .
|
||||
__('You can manage related feed to display for each post with a predefined format.') .
|
||||
'</p>' .
|
||||
'<h5>' . __('Feed') . '</h5>' .
|
||||
'<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><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>' .
|
||||
'</div>' .
|
||||
'<div class="col">' .
|
||||
'<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)) {
|
||||
$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 [];
|
||||
}
|
||||
|
13
_config.php
13
_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());
|
||||
|
50
_install.php
50
_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],
|
||||
|
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()->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 = '<h3>' . 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')
|
||||
)
|
||||
) . '</h3>';
|
||||
}
|
||||
|
||||
# Feed desc
|
||||
$feeddesc = '';
|
||||
if (dcCore::app()->blog->settings->fac->fac_showfeeddesc
|
||||
if (dcCore::app()->blog->settings->get(basename(__DIR__))->get('showfeeddesc')
|
||||
&& '' != $feed->description) {
|
||||
$feeddesc = '<p>' . 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']);
|
||||
|
Loading…
Reference in New Issue
Block a user