From 9be9f44757ba04be79cf5b4d93118cd9d71f0135 Mon Sep 17 00:00:00 2001 From: Jean-Christian Denis Date: Tue, 15 Nov 2022 21:05:21 +0100 Subject: [PATCH] prepare to DC 2.24, fix feed update --- _admin.php | 105 +++++++------- _config.php | 32 ++--- _define.php | 8 +- _install.php | 14 +- _prepend.php | 18 ++- _public.php | 205 ++++++++++++++-------------- _uninstall.php | 2 +- _widgets.php | 40 +++--- cron-script.php | 22 +-- inc/class.zcfs.feedsactions.php | 86 ++++++------ inc/class.zoneclear.feed.server.php | 146 ++++++++++---------- inc/lib.zcfs.activityreport.php | 48 +++---- inc/lib.zcfs.list.php | 55 ++++---- index.php | 122 ++++++++--------- 14 files changed, 441 insertions(+), 462 deletions(-) diff --git a/_admin.php b/_admin.php index 3e552de..c80b7a7 100644 --- a/_admin.php +++ b/_admin.php @@ -14,39 +14,38 @@ if (!defined('DC_CONTEXT_ADMIN')) { return null; } -$core->blog->settings->addNamespace('zoneclearFeedServer'); +dcCore::app()->blog->settings->addNamespace('zoneclearFeedServer'); -require_once dirname(__FILE__) . '/_widgets.php'; +require_once __DIR__ . '/_widgets.php'; -$_menu['Plugins']->addItem( +dcCore::app()->menu[dcAdmin::MENU_PLUGINS]->addItem( __('Feeds server'), - $core->adminurl->get('admin.plugin.zoneclearFeedServer'), + dcCore::app()->adminurl->get('admin.plugin.zoneclearFeedServer'), dcPage::getPF('zoneclearFeedServer/icon.png'), preg_match( - '/' . preg_quote($core->adminurl->get('admin.plugin.zoneclearFeedServer')) . '(&.*)?$/', + '/' . preg_quote(dcCore::app()->adminurl->get('admin.plugin.zoneclearFeedServer')) . '(&.*)?$/', $_SERVER['REQUEST_URI'] ), - $core->auth->check('admin', $core->blog->id) + dcCore::app()->auth->check('admin', dcCore::app()->blog->id) ); # Delete related info about feed post in meta table -$core->addBehavior('adminBeforePostDelete', ['zcfsAdminBehaviors', 'adminBeforePostDelete']); - -if ($core->auth->check('admin', $core->blog->id)) { +dcCore::app()->addBehavior('adminBeforePostDelete', ['zcfsAdminBehaviors', 'adminBeforePostDelete']); +if (dcCore::app()->auth->check('admin', dcCore::app()->blog->id)) { # Dashboard icon - $core->addBehavior('adminDashboardFavorites', ['zcfsAdminBehaviors', 'adminDashboardFavorites']); + dcCore::app()->addBehavior('adminDashboardFavoritesV2', ['zcfsAdminBehaviors', 'adminDashboardFavorites']); # User pref - $core->addBehavior('adminColumnsLists', ['zcfsAdminBehaviors', 'adminColumnsLists']); - $core->addBehavior('adminFiltersLists', ['zcfsAdminBehaviors', 'adminFiltersLists']); + dcCore::app()->addBehavior('adminColumnsListsV2', ['zcfsAdminBehaviors', 'adminColumnsLists']); + dcCore::app()->addBehavior('adminFiltersListsV2', ['zcfsAdminBehaviors', 'adminFiltersLists']); # Add info about feed on post page sidebar - $core->addBehavior('adminPostHeaders', ['zcfsAdminBehaviors', 'adminPostHeaders']); - $core->addBehavior('adminPostFormItems', ['zcfsAdminBehaviors', 'adminPostFormItems']); + dcCore::app()->addBehavior('adminPostHeaders', ['zcfsAdminBehaviors', 'adminPostHeaders']); + dcCore::app()->addBehavior('adminPostFormItems', ['zcfsAdminBehaviors', 'adminPostFormItems']); } # Take care about tweakurls (thanks Mathieu M.) -if (version_compare($core->plugins->moduleInfo('tweakurls', 'version'), '0.8', '>=')) { - $core->addbehavior('zcfsAfterPostCreate', ['zoneclearFeedServer', 'tweakurlsAfterPostCreate']); +if (version_compare(dcCore::app()->plugins->moduleInfo('tweakurls', 'version'), '0.8', '>=')) { + dcCore::app()->addbehavior('zcfsAfterPostCreate', ['zoneclearFeedServer', 'tweakurlsAfterPostCreate']); } /** @@ -63,7 +62,7 @@ class zcfsAdminBehaviors __('Name') => 'lowername', __('Frequency') => 'feed_upd_int', __('Update date') => 'feed_upd_last', - __('Status') => 'feed_status' + __('Status') => 'feed_status', ]; } @@ -74,26 +73,25 @@ class zcfsAdminBehaviors __('Title') => 'post_title', __('Category') => 'cat_title', __('Author') => 'user_id', - __('Status') => 'post_status' + __('Status') => 'post_status', ]; } /** * Favorites. * - * @param dcCore $core dcCore instance - * @param arrayObject $favs Array of favorites + * @param dcFavorites $favs Array of favorites */ - public static function adminDashboardFavorites(dcCore $core, dcFavorites $favs) + public static function adminDashboardFavorites(dcFavorites $favs) { $favs->register('zcfs', [ 'title' => __('Feeds server'), - 'url' => $core->adminurl->get('admin.plugin.zoneclearFeedServer'), + 'url' => dcCore::app()->adminurl->get('admin.plugin.zoneclearFeedServer'), 'small-icon' => dcPage::getPF('zoneclearFeedServer/icon.png'), 'large-icon' => dcPage::getPF('zoneclearFeedServer/icon-big.png'), 'permissions' => 'usage,contentadmin', 'active_cb' => ['zcfsAdminBehaviors', 'adminDashboardFavoritesActive'], - 'dashboard_cb' => ['zcfsAdminBehaviors', 'adminDashboardFavoritesCallback'] + 'dashboard_cb' => ['zcfsAdminBehaviors', 'adminDashboardFavoritesCallback'], ]); } @@ -113,12 +111,11 @@ class zcfsAdminBehaviors /** * Favorites hack. * - * @param dcCore $core dcCore instance * @param arrayObject $fav Fav attributes */ - public static function adminDashboardFavoritesCallback(dcCore $core, $fav) + public static function adminDashboardFavoritesCallback($fav) { - $zcfs = new zoneclearFeedServer($core); + $zcfs = new zoneclearFeedServer(); $count = $zcfs->getFeeds(['feed_status' => '0'], true)->f(0); if (!$count) { @@ -127,7 +124,7 @@ class zcfsAdminBehaviors $fav['title'] .= '
' . sprintf(__('%s feed disabled', '%s feeds disabled', $count), $count); $fav['large-icon'] = dcPage::getPF('zoneclearFeedServer/icon-big-update.png'); - $fav['url'] = $core->adminurl->get( + $fav['url'] = dcCore::app()->adminurl->get( 'admin.plugin.zoneclearFeedServer', ['part' => 'feeds', 'sortby' => 'feed_status', 'order' => 'asc'] ); @@ -136,10 +133,9 @@ class zcfsAdminBehaviors /** * User pref columns lists. * - * @param dcCore $core dcCore instance * @param arrayObject $cols Columns */ - public static function adminColumnsLists(dcCore $core, $cols) + public static function adminColumnsLists($cols) { $cols['zcfs_feeds'] = [ __('Feeds server: Feeds'), @@ -147,40 +143,39 @@ class zcfsAdminBehaviors 'desc' => [true, __('Feed')], 'period' => [true, __('Frequency')], 'update' => [true, __('Last update')], - 'entries' => [true, __('Entries')] - ] + 'entries' => [true, __('Entries')], + ], ]; $cols['zcfs_entries'] = [ __('Feeds server: Entries'), [ 'date' => [true, __('Date')], 'category' => [true, __('Category')], - 'author' => [true, __('Author')] - ] + 'author' => [true, __('Author')], + ], ]; } /** * User pref filters options. * - * @param dcCore $core dcCore instance * @param arrayObject $sorts Sort options */ - public static function adminFiltersLists(dcCore $core, $sorts) + public static function adminFiltersLists($sorts) { $sorts['zcfs_feeds'] = [ __('Feeds server: Feeds'), self::feedsSortbyCombo(), 'lowername', 'asc', - [__('feeds per page'), 30] + [__('feeds per page'), 30], ]; $sorts['zcfs_entries'] = [ __('Feeds server: Entries'), self::entriesSortbyCombo(), 'post_dt', 'desc', - [__('entries per page'), 30] + [__('entries per page'), 30], ]; } @@ -207,50 +202,48 @@ class zcfsAdminBehaviors return null; } - global $core; - - $url = $core->meta->getMetadata([ + $url = dcCore::app()->meta->getMetadata([ 'post_id' => $post->post_id, 'meta_type' => 'zoneclearfeed_url', - 'limit' => 1 + 'limit' => 1, ]); $url = $url->isEmpty() ? '' : $url->meta_id; if (!$url) { return null; } - $author = $core->meta->getMetadata([ + $author = dcCore::app()->meta->getMetadata([ 'post_id' => $post->post_id, 'meta_type' => 'zoneclearfeed_author', - 'limit' => 1 + 'limit' => 1, ]); $author = $author->isEmpty() ? '' : $author->meta_id; - $site = $core->meta->getMetadata([ + $site = dcCore::app()->meta->getMetadata([ 'post_id' => $post->post_id, 'meta_type' => 'zoneclearfeed_site', - 'limit' => 1 + 'limit' => 1, ]); $site = $site->isEmpty() ? '' : $site->meta_id; - $sitename = $core->meta->getMetadata([ + $sitename = dcCore::app()->meta->getMetadata([ 'post_id' => $post->post_id, 'meta_type' => 'zoneclearfeed_sitename', - 'limit' => 1 + 'limit' => 1, ]); $sitename = $sitename->isEmpty() ? '' : $sitename->meta_id; $edit = ''; - if ($core->auth->check('admin', $core->blog->id)) { - $fid = $core->meta->getMetadata([ + if (dcCore::app()->auth->check(dcAuth::PERMISSION_CONTENT_ADMIN, dcCore::app()->blog->id)) { + $fid = dcCore::app()->meta->getMetadata([ 'post_id' => $post->post_id, 'meta_type' => 'zoneclearfeed_id', - 'limit' => 1 + 'limit' => 1, ]); if (!$fid->isEmpty()) { $edit = sprintf( '

%s

', - $core->adminurl->get( + dcCore::app()->adminurl->get( 'admin.plugin.zoneclearFeedServer', ['part' => 'feed', 'feed_id' => $fid->meta_id] ), @@ -276,17 +269,15 @@ class zcfsAdminBehaviors */ public static function adminBeforePostDelete($post_id) { - global $core; - - $core->con->execute( - 'DELETE FROM ' . $core->prefix . 'meta ' . + dcCore::app()->con->execute( + 'DELETE FROM ' . dcCore::app()->prefix . dcMeta::META_TABLE_NAME . ' ' . 'WHERE post_id = ' . ((int) $post_id) . ' ' . - 'AND meta_type ' . $core->con->in([ + 'AND meta_type ' . dcCore::app()->con->in([ 'zoneclearfeed_url', 'zoneclearfeed_author', 'zoneclearfeed_site', 'zoneclearfeed_sitename', - 'zoneclearfeed_id' + 'zoneclearfeed_id', ]) . ' ' ); } diff --git a/_config.php b/_config.php index 8efce9a..596a447 100644 --- a/_config.php +++ b/_config.php @@ -14,11 +14,11 @@ if (!defined('DC_CONTEXT_MODULE')) { return null; } -$redir = empty($_REQUEST['redir']) ? $list->getURL() . '#plugins' : $_REQUEST['redir']; +$redir = empty($_REQUEST['redir']) ? dcCore::app()->admin->list->getURL() . '#plugins' : $_REQUEST['redir']; # -- Get settings -- -$core->blog->settings->addNamespace('zoneclearFeedServer'); -$s = $core->blog->settings->zoneclearFeedServer; +dcCore::app()->blog->settings->addNamespace('zoneclearFeedServer'); +$s = dcCore::app()->blog->settings->zoneclearFeedServer; $active = (bool) $s->zoneclearFeedServer_active; $pub_active = (bool) $s->zoneclearFeedServer_pub_active; @@ -41,7 +41,7 @@ if (!is_array($post_title_redir)) { $post_title_redir = []; } -$zc = new zoneclearFeedServer($core); +$zc = new zoneclearFeedServer(); # -- Set settings -- if (!empty($_POST['save'])) { @@ -72,17 +72,17 @@ if (!empty($_POST['save'])) { $s->put('zoneclearFeedServer_post_title_redir', serialize($post_title_redir)); $s->put('zoneclearFeedServer_user', $feeduser); - $core->blog->triggerBlog(); + dcCore::app()->blog->triggerBlog(); - dcPage::addSuccessNotice( + dcAdminNotices::addSuccessNotice( __('Configuration successfully updated.') ); - $core->adminurl->redirect( + dcCore::app()->adminurl->redirect( 'admin.plugins', - ['module' => 'zoneclearFeedServer', 'conf' => 1, 'redir' => $list->getRedir()] + ['module' => 'zoneclearFeedServer', 'conf' => 1, 'redir' => dcCore::app()->admin->list->getRedir()] ); } catch (Exception $e) { - $core->error->add($e->getMessage()); + dcCore::app()->error->add($e->getMessage()); } } @@ -92,20 +92,20 @@ $combo_pubupd = [ __('Disable') => 0, __('Before display') => 1, __('After display') => 2, - __('Through Ajax') => 3 + __('Through Ajax') => 3, ]; $combo_status = [ __('Unpublished') => 0, - __('Published') => 1 + __('Published') => 1, ]; $combo_tagcase = [ __('Keep source case') => 0, __('First upper case') => 1, __('All lower case') => 2, - __('All upper case') => 3 + __('All upper case') => 3, ]; -$pub_page_url = $core->blog->url . $core->url->getBase('zoneclearFeedsPage'); +$pub_page_url = dcCore::app()->blog->url . dcCore::app()->url->getBase('zoneclearFeedsPage'); # -- Display form -- @@ -124,7 +124,7 @@ __('Enable plugin') . '

'; -if ($core->blog->settings->zoneclearFeedServer->zoneclearFeedServer_pub_active) { +if (dcCore::app()->blog->settings->zoneclearFeedServer->zoneclearFeedServer_pub_active) { echo sprintf( '

%s

', $pub_page_url, @@ -168,7 +168,7 @@ form::checkbox('pub_active', 1, $pub_active) . __('Enable public page') . '' . __('Redirect to original post on:') . '