diff --git a/CHANGELOG.md b/CHANGELOG.md index 32a1b64..fdf3bd2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/README.md b/README.md index d3bb84c..9e36d8e 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/_admin.php b/_admin.php index aa2008c..698d0f2 100644 --- a/_admin.php +++ b/_admin.php @@ -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'), diff --git a/_config.php b/_config.php index 9a9ee1b..8f58882 100644 --- a/_config.php +++ b/_config.php @@ -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') . '

'; -if ($s->zoneclearFeedServer_pub_active) { +if ($s->pub_active) { echo sprintf( '

%s

', $pub_page_url, diff --git a/_define.php b/_define.php index 11cd55d..6b2bb30 100644 --- a/_define.php +++ b/_define.php @@ -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([ diff --git a/_install.php b/_install.php index 504ecb2..e666ded 100644 --- a/_install.php +++ b/_install.php @@ -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) { diff --git a/_prepend.php b/_prepend.php index 8ea3d9f..361c1e0 100644 --- a/_prepend.php +++ b/_prepend.php @@ -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 diff --git a/_public.php b/_public.php index ec334f5..4e42445 100644 --- a/_public.php +++ b/_public.php @@ -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']); } diff --git a/_widgets.php b/_widgets.php index 405e890..5811f54 100644 --- a/_widgets.php +++ b/_widgets.php @@ -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( '

%s

', 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( '%s', dcCore::app()->blog->url . dcCore::app()->url->getBase('zoneclearFeedsPage'), diff --git a/cron-script.php b/cron-script.php index 43e9b3b..e1faca5 100644 --- a/cron-script.php +++ b/cron-script.php @@ -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(); diff --git a/dcstore.xml b/dcstore.xml index 3d34bd6..73f5742 100644 --- a/dcstore.xml +++ b/dcstore.xml @@ -2,12 +2,12 @@ Feeds server - 2022.11.26 + 2022.12.11 Jean-Christian Denis, BG, Pierre Van Glabeke Mix your blog with a feeds planet - https://github.com/JcDenis/zoneclearFeedServer/releases/download/v2022.11.26/plugin-zoneclearFeedServer.zip + https://github.com/JcDenis/zoneclearFeedServer/releases/download/v2022.12.11/plugin-zoneclearFeedServer.zip 2.24 - https://plugins.dotaddict.org/dc2/details/pacKman + https://plugins.dotaddict.org/dc2/details/zoneclearFeedServer https://github.com/JcDenis/zoneclearFeedServer diff --git a/inc/class.zcfsrsextposts.php b/inc/class.zcfsrsextposts.php index 4d803bc..9b30c1d 100644 --- a/inc/class.zcfsrsextposts.php +++ b/inc/class.zcfsrsextposts.php @@ -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( diff --git a/inc/class.zcfsupgrade.php b/inc/class.zcfsupgrade.php new file mode 100644 index 0000000..b75e38f --- /dev/null +++ b/inc/class.zcfsupgrade.php @@ -0,0 +1,54 @@ +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' "); + } + } +} diff --git a/inc/class.zcfsurlhandler.php b/inc/class.zcfsurlhandler.php index 4e72f76..e6e11ed 100644 --- a/inc/class.zcfsurlhandler.php +++ b/inc/class.zcfsurlhandler.php @@ -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)) { diff --git a/inc/class.zoneclearfeedserver.php b/inc/class.zoneclearfeedserver.php index 45d466d..30457a8 100644 --- a/inc/class.zoneclearfeedserver.php +++ b/inc/class.zoneclearfeedserver.php @@ -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; } @@ -426,11 +426,11 @@ class zoneclearFeedServer return false; } - $enabled = false; + $enabled = false; $updates = false; $loop_mem = []; - $limit = abs((int) $s->zoneclearFeedServer_update_limit); + $limit = abs((int) $s->update_limit); if ($limit < 1) { $limit = 10; } @@ -441,7 +441,7 @@ class zoneclearFeedServer while ($f->fetch()) { # Check if feed need update - if ($id + if ($id || $i < $limit && $f->feed_status == 1 && ($time > $f->feed_upd_last + $f->feed_upd_int) ) { if (!$enabled) { @@ -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 diff --git a/index.php b/index.php index d8abad2..d10e7b7 100644 --- a/index.php +++ b/index.php @@ -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 '' . __('Feeds server') . '' .