update settings ids to shorter ones

This commit is contained in:
Jean-Christian Paul Denis 2022-12-11 20:18:26 +01:00
parent c29fa6fc91
commit ec3b92b997
Signed by: JcDenis
GPG Key ID: 1B5B8C5B90B6C951
16 changed files with 136 additions and 66 deletions

View File

@ -3,6 +3,18 @@
- [ ] add plugin muppet support (request Mathieu M.)
- [ ] add log for errors
- fix posts owner on feeds update
- fix permissions
- enhance feed update
- use constant for table name
- use new behaviors names
- use dc methods in widget
- use abstract plugin name
- split file by class
- clean prepend file
- clean install file
- update translation
2022.11.26
- use SVG icon
- fix missing dcCore (resources)

View File

@ -42,7 +42,7 @@ Once it's done you can manage your feeds from menu
## CONTRIBUTORS
* Jean-Christian Denis
* Jean-Christian Denis (author)
* BG
* Pierre Van Glabeke

View File

@ -22,8 +22,8 @@ $perm = dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([
dcAuth::PERMISSION_CONTENT_ADMIN,
]), dcCore::app()->blog->id);
if (dcCore::app()->blog->settings->__get(basename(__DIR__))->zoneclearFeedServer_active
&& '' != dcCore::app()->blog->settings->__get(basename(__DIR__))->zoneclearFeedServer_user
if (dcCore::app()->blog->settings->__get(basename(__DIR__))->active
&& '' != dcCore::app()->blog->settings->__get(basename(__DIR__))->user
) {
dcCore::app()->menu[dcAdmin::MENU_PLUGINS]->addItem(
__('Feeds server'),

View File

@ -20,16 +20,16 @@ $redir = empty($_REQUEST['redir']) ? dcCore::app()->admin->list->getURL() . '#pl
dcCore::app()->blog->settings->addNamespace(basename(__DIR__));
$s = dcCore::app()->blog->settings->__get(basename(__DIR__));
$active = (bool) $s->zoneclearFeedServer_active;
$pub_active = (bool) $s->zoneclearFeedServer_pub_active;
$post_status_new = (bool) $s->zoneclearFeedServer_post_status_new;
$bhv_pub_upd = (int) $s->zoneclearFeedServer_bhv_pub_upd;
$update_limit = (int) $s->zoneclearFeedServer_update_limit;
$keep_empty_feed = (bool) $s->zoneclearFeedServer_keep_empty_feed;
$tag_case = (int) $s->zoneclearFeedServer_tag_case;
$post_full_tpl = @unserialize($s->zoneclearFeedServer_post_full_tpl);
$post_title_redir = @unserialize($s->zoneclearFeedServer_post_title_redir);
$feeduser = (string) $s->zoneclearFeedServer_user;
$active = (bool) $s->active;
$pub_active = (bool) $s->pub_active;
$post_status_new = (bool) $s->post_status_new;
$bhv_pub_upd = (int) $s->bhv_pub_upd;
$update_limit = (int) $s->update_limit;
$keep_empty_feed = (bool) $s->keep_empty_feed;
$tag_case = (int) $s->tag_case;
$post_full_tpl = @unserialize($s->post_full_tpl);
$post_title_redir = @unserialize($s->post_title_redir);
$feeduser = (string) $s->user;
if ($update_limit < 1) {
$update_limit = 10;
@ -61,16 +61,16 @@ if (!empty($_POST['save'])) {
$limit = 10;
}
$s->put('zoneclearFeedServer_active', $active);
$s->put('zoneclearFeedServer_pub_active', $pub_active);
$s->put('zoneclearFeedServer_post_status_new', $post_status_new);
$s->put('zoneclearFeedServer_bhv_pub_upd', $bhv_pub_upd);
$s->put('zoneclearFeedServer_update_limit', $limit);
$s->put('zoneclearFeedServer_keep_empty_feed', $keep_empty_feed);
$s->put('zoneclearFeedServer_tag_case', $tag_case);
$s->put('zoneclearFeedServer_post_full_tpl', serialize($post_full_tpl));
$s->put('zoneclearFeedServer_post_title_redir', serialize($post_title_redir));
$s->put('zoneclearFeedServer_user', $feeduser);
$s->put('active', $active);
$s->put('pub_active', $pub_active);
$s->put('post_status_new', $post_status_new);
$s->put('bhv_pub_upd', $bhv_pub_upd);
$s->put('update_limit', $limit);
$s->put('keep_empty_feed', $keep_empty_feed);
$s->put('tag_case', $tag_case);
$s->put('post_full_tpl', serialize($post_full_tpl));
$s->put('post_title_redir', serialize($post_title_redir));
$s->put('user', $feeduser);
dcCore::app()->blog->triggerBlog();
@ -124,7 +124,7 @@ __('Enable plugin') . '</label></p>
<div class="fieldset">';
if ($s->zoneclearFeedServer_pub_active) {
if ($s->pub_active) {
echo sprintf(
'<p><a class="onblog_link outgoing" href="%s" title="%s">%s <img alt="" src="images/outgoing-link.svg"></a></p>',
$pub_page_url,

View File

@ -18,7 +18,7 @@ $this->registerModule(
'Feeds server',
'Mix your blog with a feeds planet',
'Jean-Christian Denis, BG, Pierre Van Glabeke',
'2022.11.26',
'2022.12.11',
[
'requires' => [['core', '2.24']],
'permissions' => dcCore::app()->auth->makePermissions([

View File

@ -15,7 +15,7 @@ if (!defined('DC_CONTEXT_ADMIN')) {
}
try {
# Check module version
// Check module version
if (!dcCore::app()->newVersion(
basename(__DIR__),
dcCore::app()->plugins->moduleInfo(basename(__DIR__), 'version')
@ -23,7 +23,10 @@ try {
return null;
}
# Tables
// Upgrade existing install
zcfsUpgrade::preUpgrade();
// Tables
$t = new dbStruct(dcCore::app()->con, dcCore::app()->prefix);
$t->{initZoneclearFeedServer::TABLE_NAME}
->feed_id('bigint', 0, false)
@ -54,19 +57,19 @@ try {
$ti = new dbStruct(dcCore::app()->con, dcCore::app()->prefix);
$changes = $ti->synchronize($t);
# Settings
// Settings
dcCore::app()->blog->settings->addNamespace(basename(__DIR__));
$s = dcCore::app()->blog->settings->__get(basename(__DIR__));
$s->put('zoneclearFeedServer_active', false, 'boolean', 'Enable zoneclearBlogServer', false, true);
$s->put('zoneclearFeedServer_pub_active', false, 'boolean', 'Enable public page of list of feeds', false, true);
$s->put('zoneclearFeedServer_post_status_new', true, 'boolean', 'Enable auto publish new posts', false, true);
$s->put('zoneclearFeedServer_bhv_pub_upd', 2, 'string', 'Auto update on public side (disable/before/after)', false, true);
$s->put('zoneclearFeedServer_update_limit', 1, 'integer', 'Number of feeds to update at one time', false, true);
$s->put('zoneclearFeedServer_keep_empty_feed', false, 'boolean', 'Keep active empty feeds', false, true);
$s->put('zoneclearFeedServer_tag_case', 0, 'integer', 'How to transform imported tags', false, true);
$s->put('zoneclearFeedServer_user', '', 'string', 'User id that has right on post', false, true);
$s->put('zoneclearFeedServer_post_full_tpl', serialize(['post', 'category', 'tag', 'archive']), 'string', 'List of templates types for full feed', false, true);
$s->put('zoneclearFeedServer_post_title_redir', serialize(['feed']), 'string', 'List of templates types for redirection to original post', false, true);
$s->put('active', false, 'boolean', 'Enable zoneclearBlogServer', false, true);
$s->put('pub_active', false, 'boolean', 'Enable public page of list of feeds', false, true);
$s->put('post_status_new', true, 'boolean', 'Enable auto publish new posts', false, true);
$s->put('bhv_pub_upd', 2, 'string', 'Auto update on public side (disable/before/after)', false, true);
$s->put('update_limit', 1, 'integer', 'Number of feeds to update at one time', false, true);
$s->put('keep_empty_feed', false, 'boolean', 'Keep active empty feeds', false, true);
$s->put('tag_case', 0, 'integer', 'How to transform imported tags', false, true);
$s->put('user', '', 'string', 'User id that has right on post', false, true);
$s->put('post_full_tpl', serialize(['post', 'category', 'tag', 'archive']), 'string', 'List of templates types for full feed', false, true);
$s->put('post_title_redir', serialize(['feed']), 'string', 'List of templates types for redirection to original post', false, true);
return true;
} catch (Exception $e) {

View File

@ -27,6 +27,7 @@ Clearbricks::lib()->autoload([
'zcfsRsExtPosts' => __DIR__ . '/inc/class.zcfsrsextposts.php',
'zcfsUrlHandler' => __DIR__ . '/inc/class.zcfsurlhandler.php',
'zcfsActivityReportBehaviors' => __DIR__ . '/inc/class.zcfsactivityreportbehaviors.php',
'zcfsUpgrade' => __DIR__ . '/inc/class.zcfsupgrade.php',
]);
// public url for page of description of the flux

View File

@ -23,14 +23,14 @@ require_once __DIR__ . '/_widgets.php';
dcCore::app()->addBehavior('coreBlogGetPosts', ['zcfsPublicBehaviors', 'coreBlogGetPosts']);
if (!$s->zoneclearFeedServer_active) {
if (!$s->active) {
return null;
}
if (1 == $s->zoneclearFeedServer_bhv_pub_upd) {
if (1 == $s->bhv_pub_upd) {
dcCore::app()->addBehavior('publicBeforeDocumentV2', ['zcfsPublicBehaviors', 'publicDocumentV2']);
} elseif (2 == $s->zoneclearFeedServer_bhv_pub_upd) {
} elseif (2 == $s->bhv_pub_upd) {
dcCore::app()->addBehavior('publicAfterDocumentV2', ['zcfsPublicBehaviors', 'publicAfterDocumentV2']);
} elseif (3 == $s->zoneclearFeedServer_bhv_pub_upd) {
} elseif (3 == $s->bhv_pub_upd) {
dcCore::app()->addBehavior('publicHeadContent', ['zcfsPublicBehaviors', 'publicHeadContent']);
}

View File

@ -152,7 +152,7 @@ class zoneclearFeedServerWidget
return null;
}
if (!dcCore::app()->blog->settings->__get(basename(__DIR__))->zoneclearFeedServer_active
if (!dcCore::app()->blog->settings->__get(basename(__DIR__))->active
|| !$w->checkHomeOnly(dcCore::app()->url->type)
) {
return null;
@ -184,7 +184,7 @@ class zoneclearFeedServerWidget
$i++;
}
$pub = '';
if ($w->pagelink && dcCore::app()->blog->settings->__get(basename(__DIR__))->zoneclearFeedServer_pub_active) {
if ($w->pagelink && dcCore::app()->blog->settings->__get(basename(__DIR__))->pub_active) {
$pub = sprintf(
'<p><strong><a href="%s">%s</a></strong></p>',
dcCore::app()->blog->url . dcCore::app()->url->getBase('zoneclearFeedsPage'),
@ -212,7 +212,7 @@ class zoneclearFeedServerWidget
return;
}
if (!dcCore::app()->blog->settings->__get(basename(__DIR__))->zoneclearFeedServer_active
if (!dcCore::app()->blog->settings->__get(basename(__DIR__))->active
|| !$w->checkHomeOnly(dcCore::app()->url->type)
) {
return null;
@ -232,7 +232,7 @@ class zoneclearFeedServerWidget
$text = $count ? sprintf(__('one source', '%d sources', $count), $count) : __('no sources');
if (dcCore::app()->blog->settings->__get(basename(__DIR__))->zoneclearFeedServer_pub_active) {
if (dcCore::app()->blog->settings->__get(basename(__DIR__))->pub_active) {
$text = sprintf(
'<a href="%s">%s</a>',
dcCore::app()->blog->url . dcCore::app()->url->getBase('zoneclearFeedsPage'),

View File

@ -82,7 +82,7 @@ if (!isset($opts['u']) || !dcCore::app()->auth->checkUser($opts['u'])) {
dcCore::app()->plugins->loadModules(DC_PLUGINS_ROOT);
dcCore::app()->blog->settings->addNamespace('zoneclearFeedServer');
dcCore::app()->blog->settings->addNamespace(basename(__DIR__));
try {
$zc = new zoneclearFeedServer();

View File

@ -2,12 +2,12 @@
<modules xmlns:da="http://dotaddict.org/da/">
<module id="zoneclearFeedServer">
<name>Feeds server</name>
<version>2022.11.26</version>
<version>2022.12.11</version>
<author>Jean-Christian Denis, BG, Pierre Van Glabeke</author>
<desc>Mix your blog with a feeds planet</desc>
<file>https://github.com/JcDenis/zoneclearFeedServer/releases/download/v2022.11.26/plugin-zoneclearFeedServer.zip</file>
<file>https://github.com/JcDenis/zoneclearFeedServer/releases/download/v2022.12.11/plugin-zoneclearFeedServer.zip</file>
<da:dcmin>2.24</da:dcmin>
<da:details>https://plugins.dotaddict.org/dc2/details/pacKman</da:details>
<da:details>https://plugins.dotaddict.org/dc2/details/zoneclearFeedServer</da:details>
<da:support>https://github.com/JcDenis/zoneclearFeedServer</da:support>
</module>
</modules>

View File

@ -106,7 +106,7 @@ class zcfsRsExtPosts extends rsExtPost
public static function getURL(dcRecord $rs): string
{
$url = $rs->zcFeed('url');
$types = @unserialize(dcCore::app()->blog->settings->__get(basename(dirname('../' . __DIR__)))->zoneclearFeedServer_post_title_redir);
$types = @unserialize(dcCore::app()->blog->settings->__get(basename(dirname('../' . __DIR__)))->post_title_redir);
$full = is_array($types) && in_array(dcCore::app()->url->type, $types);
return $url && $full ?
@ -127,7 +127,7 @@ class zcfsRsExtPosts extends rsExtPost
$content = self::zcFeedBrother('getContent', [&$rs, $absolute_urls]);
if ($url && $sitename && $rs->post_type == 'post') {
$types = @unserialize(dcCore::app()->blog->settings->__get(basename(dirname('../' . __DIR__)))->zoneclearFeedServer_post_full_tpl);
$types = @unserialize(dcCore::app()->blog->settings->__get(basename(dirname('../' . __DIR__)))->post_full_tpl);
if (is_array($types) && in_array(dcCore::app()->url->type, $types)) {
return $content . sprintf(

54
inc/class.zcfsupgrade.php Normal file
View File

@ -0,0 +1,54 @@
<?php
/**
* @brief zoneclearFeedServer, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Jean-Christian Denis, BG, Pierre Van Glabeke
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
if (!defined('DC_CONTEXT_ADMIN')) {
return null;
}
class zcfsUpgrade
{
public static function preUpgrade()
{
//$current = dcCore::app()->plugins->moduleInfo(basename(dirname('../' . __DIR__)), 'version');
$current = dcCore::app()->getVersion(basename(dirname('../' . __DIR__)));
if ($current && version_compare($current, '2022.12.10', '<')) {
self::preUpgrade20221210();
}
}
public static function postUpgrade()
{
}
// Rename settings
protected static function preUpgrade20221210()
{
$settings_ids = [
'zoneclearFeedServer_active' => 'active',
'zoneclearFeedServer_pub_active' => 'pub_active',
'zoneclearFeedServer_post_status_new' => 'psot_new_status',
'zoneclearFeedServer_bhv_pub_upd' => 'bhv_pub_upd',
'zoneclearFeedServer_update_limit' => 'update_limit',
'zoneclearFeedServer_keep_empty_feed' => 'keep_empty_feed',
'zoneclearFeedServer_tag_case' => 'tag_case',
'zoneclearFeedServer_user' => 'user',
'zoneclearFeedServer_post_full_tpl' => 'post_full_tpl',
'zoneclearFeedServer_post_title_redir' => 'post_title_redir',
];
foreach ($settings_ids as $old => $new) {
$cur = dcCore::app()->con->openCursor(dcCore::app()->prefix . dcNamespace::NS_TABLE_NAME);
$cur->setting_id = $new;
$cur->update("WHERE setting_id = '" . $old . "' and setting_ns = 'zoneclearFeedServer' ");
}
}
}

View File

@ -32,14 +32,14 @@ class zcfsUrlHandler extends dcUrlHandlers
$s = dcCore::app()->blog->settings->__get(basename(dirname('../' . __DIR__)));
# Not active
if (!$s->zoneclearFeedServer_active) {
if (!$s->active) {
self::p404();
return null;
}
# Update feeds (from ajax or other post resquest)
if ($args == '/zcfsupd' && 3 == $s->zoneclearFeedServer_bhv_pub_upd) {
if ($args == '/zcfsupd' && 3 == $s->bhv_pub_upd) {
$msg = '';
if (!empty($_POST['blogId']) && html::escapeJS(dcCore::app()->blog->id) == $_POST['blogId']) {
try {
@ -72,7 +72,7 @@ class zcfsUrlHandler extends dcUrlHandlers
exit(1);
# Server js
} elseif ($args == '/zcfsupd.js' && 3 == $s->zoneclearFeedServer_bhv_pub_upd) {
} elseif ($args == '/zcfsupd.js' && 3 == $s->bhv_pub_upd) {
dcCore::app()->tpl->setPath(dcCore::app()->tpl->getPath(), __DIR__ . '/default-templates');
self::serveDocument(
'zcfsupd.js',
@ -82,7 +82,7 @@ class zcfsUrlHandler extends dcUrlHandlers
);
# Server feeds description page
} elseif (in_array($args, ['', '/']) && $s->zoneclearFeedServer_pub_active) {
} elseif (in_array($args, ['', '/']) && $s->pub_active) {
$tplset = dcCore::app()->themes->moduleInfo(dcCore::app()->blog->settings->system->theme, 'tplset');
$path = __DIR__ . '/default-templates/';
if (!empty($tplset) && is_dir($path . $tplset)) {

View File

@ -398,7 +398,7 @@ class zoneclearFeedServer
$s = dcCore::app()->blog->settings->__get(basename(dirname('../' . __DIR__)));
# Not configured
if (!$s->zoneclearFeedServer_active || !$s->zoneclearFeedServer_user) {
if (!$s->active || !$s->user) {
return false;
}
@ -430,7 +430,7 @@ class zoneclearFeedServer
$updates = false;
$loop_mem = [];
$limit = abs((int) $s->zoneclearFeedServer_update_limit);
$limit = abs((int) $s->update_limit);
if ($limit < 1) {
$limit = 10;
}
@ -455,7 +455,7 @@ class zoneclearFeedServer
# Nothing to parse
if (!$feed) {
# Keep active empty feed or disable it ?
if (!$s->zoneclearFeedServer_keep_empty_feed) {
if (!$s->keep_empty_feed) {
$this->enableFeed($f->feed_id, false);
} else {
# Set update time of this feed
@ -533,7 +533,7 @@ class zoneclearFeedServer
# Post
$cur_post->user_id = dcCore::app()->auth->userID();
$cur_post->post_format = 'xhtml';
$cur_post->post_status = (int) $s->zoneclearFeedServer_post_status_new;
$cur_post->post_status = (int) $s->post_status_new;
$cur_post->post_open_comment = 0;
$cur_post->post_open_tb = 0;
@ -646,7 +646,7 @@ class zoneclearFeedServer
$formated_tags = [];
foreach ($tags as $tag) {
# Change tags case
switch ((int) $s->zoneclearFeedServer_tag_case) {
switch ((int) $s->tag_case) {
case 3: $tag = strtoupper($tag);
break;
@ -716,7 +716,7 @@ class zoneclearFeedServer
// backup current user
$this->user = dcCore::app()->auth->userID();
// set zcfs posts user
if (!dcCore::app()->auth->checkUser((string) dcCore::app()->blog->settings->__get(basename(dirname('../' . __DIR__)))->zoneclearFeedServer_user)) {
if (!dcCore::app()->auth->checkUser((string) dcCore::app()->blog->settings->__get(basename(dirname('../' . __DIR__)))->user)) {
throw new Exception('Unable to set user');
}
# Disable

View File

@ -28,8 +28,8 @@ dcPage::check(dcCore::app()->auth->makePermissions([
$zcfs = new zoneclearFeedServer();
# Not configured
if (!dcCore::app()->blog->settings->__get(basename(__DIR__))->zoneclearFeedServer_active
|| !dcCore::app()->blog->settings->__get(basename(__DIR__))->zoneclearFeedServer_user
if (!dcCore::app()->blog->settings->__get(basename(__DIR__))->active
|| !dcCore::app()->blog->settings->__get(basename(__DIR__))->user
) {
echo
'<html><head><title>' . __('Feeds server') . '</title></head><body>' .