update _ admin code

This commit is contained in:
Jean-Christian Paul Denis 2021-09-12 02:24:36 +02:00
parent 8d1c821dd8
commit 3758459308
Signed by: JcDenis
GPG Key ID: 1B5B8C5B90B6C951

View File

@ -12,67 +12,40 @@
*/ */
if (!defined('DC_CONTEXT_ADMIN')) { if (!defined('DC_CONTEXT_ADMIN')) {
return null; return null;
} }
# Namespace for settings
$core->blog->settings->addNamespace('zoneclearFeedServer'); $core->blog->settings->addNamespace('zoneclearFeedServer');
# Check if latest version is installed
if ($core->getVersion('zoneclearFeedServer') !=
$core->plugins->moduleInfo('zoneclearFeedServer', 'version')) {
return null;
}
# Widgets
require_once dirname(__FILE__) . '/_widgets.php'; require_once dirname(__FILE__) . '/_widgets.php';
# Admin menu $_menu['Plugins']->addItem(
$_menu['Blog']->addItem(
__('Feeds server'), __('Feeds server'),
'plugin.php?p=zoneclearFeedServer', $core->adminurl->get('admin.plugin.zoneclearFeedServer'),
'index.php?pf=zoneclearFeedServer/icon.png', dcPage::getPF('zoneclearFeedServer/icon.png'),
preg_match( preg_match(
'/plugin.php\?p=zoneclearFeedServer(&.*)?$/', '/' . preg_quote($core->adminurl->get('admin.plugin.zoneclearFeedServer')) . '(&.*)?$/',
$_SERVER['REQUEST_URI'] $_SERVER['REQUEST_URI']
), ),
$core->auth->check('admin', $core->blog->id) $core->auth->check('admin', $core->blog->id)
); );
# Delete related info about feed post in meta table # Delete related info about feed post in meta table
$core->addBehavior( $core->addBehavior('adminBeforePostDelete',['zcfsAdminBehaviors', 'adminBeforePostDelete']);
'adminBeforePostDelete',
array('zcfsAdminBehaviors', 'adminBeforePostDelete')
);
if ($core->auth->check('admin', $core->blog->id)) { if ($core->auth->check('admin', $core->blog->id)) {
# Dashboard icon # Dashboard icon
$core->addBehavior( $core->addBehavior('adminDashboardFavorites', ['zcfsAdminBehaviors', 'adminDashboardFavorites']);
'adminDashboardFavorites',
array('zcfsAdminBehaviors', 'adminDashboardFavorites')
);
# Add info about feed on post page sidebar # Add info about feed on post page sidebar
$core->addBehavior( $core->addBehavior('adminPostHeaders', ['zcfsAdminBehaviors', 'adminPostHeaders']);
'adminPostHeaders', $core->addBehavior('adminPostFormItems', ['zcfsAdminBehaviors', 'adminPostFormItems']);
array('zcfsAdminBehaviors', 'adminPostHeaders')
);
$core->addBehavior(
'adminPostFormItems',
array('zcfsAdminBehaviors', 'adminPostFormItems')
);
} }
# Take care about tweakurls (thanks Mathieu M.) # Take care about tweakurls (thanks Mathieu M.)
if (version_compare($core->plugins->moduleInfo('tweakurls', 'version'), '0.8', '>=')) { if (version_compare($core->plugins->moduleInfo('tweakurls', 'version'), '0.8', '>=')) {
$core->addbehavior( $core->addbehavior('zcfsAfterPostCreate', ['zoneclearFeedServer', 'tweakurlsAfterPostCreate']);
'zcfsAfterPostCreate',
array('zoneclearFeedServer', 'tweakurlsAfterPostCreate')
);
} }
/** /**
@ -88,22 +61,16 @@ class zcfsAdminBehaviors
* @param dcCore $core dcCore instance * @param dcCore $core dcCore instance
* @param arrayObject $favs Array of favorites * @param arrayObject $favs Array of favorites
*/ */
public static function adminDashboardFavorites(dcCore $core, $favs) public static function adminDashboardFavorites(dcCore $core, dcFavorites $favs)
{ {
$favs->register('zcfs', array( $favs->register('zcfs', array(
'title' => __('Feeds server'), 'title' => __('Feeds server'),
'url' => 'plugin.php?p=zoneclearFeedServer', 'url' => $core->adminurl->get('admin.plugin.zoneclearFeedServer'),
'small-icon' => 'index.php?pf=zoneclearFeedServer/icon.png', 'small-icon' => dcPage::getPF('zoneclearFeedServer/icon.png'),
'large-icon' => 'index.php?pf=zoneclearFeedServer/icon-big.png', 'large-icon' => dcPage::getPF('zoneclearFeedServer/icon-big.png'),
'permissions' => 'usage,contentadmin', 'permissions' => 'usage,contentadmin',
'active_cb' => array( 'active_cb' => ['zcfsAdminBehaviors', 'adminDashboardFavoritesActive'],
'zcfsAdminBehaviors', 'dashboard_cb' => ['zcfsAdminBehaviors', 'adminDashboardFavoritesCallback']
'adminDashboardFavoritesActive'
),
'dashboard_cb' => array(
'zcfsAdminBehaviors',
'adminDashboardFavoritesCallback'
)
)); ));
} }
@ -129,23 +96,18 @@ class zcfsAdminBehaviors
public static function adminDashboardFavoritesCallback(dcCore $core, $fav) public static function adminDashboardFavoritesCallback(dcCore $core, $fav)
{ {
$zcfs = new zoneclearFeedServer($core); $zcfs = new zoneclearFeedServer($core);
$count = $zcfs->getFeeds(array(
'feed_status' => '0'
), true)->f(0);
$count = $zcfs->getFeeds(['feed_status' => '0'], true)->f(0);
if (!$count) { if (!$count) {
return null; return null;
} }
$fav['title'] .= '<br />'.sprintf( $fav['title'] .= '<br />'.sprintf(__('%s feed disabled', '%s feeds disabled', $count), $count);
__('%s feed disabled', '%s feeds disabled', $count), $fav['large-icon'] = dcPage::getPF('zoneclearFeedServer/icon-big-update.png');
$count $fav['url'] = $core->adminurl->get(
'admin.plugin.zoneclearFeedServer',
['part' => 'feeds', 'sortby' => 'feed_status', 'order' => 'asc']
); );
$fav['url'] = 'plugin.php?p=zoneclearFeedServer&part=feeds'.
'&sortby=feed_status&order=asc';
$fav['large-icon'] = 'index.php?pf=zoneclearFeedServer'.
'/icon-big-update.png';
} }
/** /**
@ -155,9 +117,7 @@ class zcfsAdminBehaviors
*/ */
public static function adminPostHeaders() public static function adminPostHeaders()
{ {
return dcPage::jsLoad( return dcPage::jsLoad(dcPage::getPF('zoneclearFeedServer/js/post.js'));
'index.php?pf=zoneclearFeedServer/js/post.js'
);
} }
/** /**
@ -170,57 +130,58 @@ class zcfsAdminBehaviors
public static function adminPostFormItems(ArrayObject $main_items, ArrayObject $sidebar_items, $post) public static function adminPostFormItems(ArrayObject $main_items, ArrayObject $sidebar_items, $post)
{ {
if ($post === null || $post->post_type != 'post') { if ($post === null || $post->post_type != 'post') {
return null; return null;
} }
global $core; global $core;
$url = $core->meta->getMetadata(array( $url = $core->meta->getMetadata([
'post_id' => $post->post_id, 'post_id' => $post->post_id,
'meta_type' => 'zoneclearfeed_url', 'meta_type' => 'zoneclearfeed_url',
'limit' => 1 'limit' => 1
)); ]);
$url = $url->isEmpty() ? '' : $url->meta_id; $url = $url->isEmpty() ? '' : $url->meta_id;
if (!$url) { if (!$url) {
return null; return null;
} }
$author = $core->meta->getMetadata(array( $author = $core->meta->getMetadata([
'post_id' => $post->post_id, 'post_id' => $post->post_id,
'meta_type' => 'zoneclearfeed_author', 'meta_type' => 'zoneclearfeed_author',
'limit' => 1 'limit' => 1
)); ]);
$author = $author->isEmpty() ? '' : $author->meta_id; $author = $author->isEmpty() ? '' : $author->meta_id;
$site = $core->meta->getMetadata(array( $site = $core->meta->getMetadata([
'post_id' => $post->post_id, 'post_id' => $post->post_id,
'meta_type' => 'zoneclearfeed_site', 'meta_type' => 'zoneclearfeed_site',
'limit' => 1 'limit' => 1
)); ]);
$site = $site->isEmpty() ? '' : $site->meta_id; $site = $site->isEmpty() ? '' : $site->meta_id;
$sitename = $core->meta->getMetadata(array( $sitename = $core->meta->getMetadata([
'post_id' => $post->post_id, 'post_id' => $post->post_id,
'meta_type' => 'zoneclearfeed_sitename', 'meta_type' => 'zoneclearfeed_sitename',
'limit' => 1 'limit' => 1
)); ]);
$sitename = $sitename->isEmpty() ? '' : $sitename->meta_id; $sitename = $sitename->isEmpty() ? '' : $sitename->meta_id;
$edit = ''; $edit = '';
if ($core->auth->check('admin', $core->blog->id)) { if ($core->auth->check('admin', $core->blog->id)) {
$fid = $core->meta->getMetadata(array( $fid = $core->meta->getMetadata([
'post_id' => $post->post_id, 'post_id' => $post->post_id,
'meta_type' => 'zoneclearfeed_id', 'meta_type' => 'zoneclearfeed_id',
'limit' => 1 'limit' => 1
)); ]);
if (!$fid->isEmpty()) { if (!$fid->isEmpty()) {
$edit = $edit = sprintf(
'<p><a href="plugin.php?p=zoneclearFeedServer'. '<p><a href="%s">%s</a></p>',
'&amp;part=feed&amp;feed_id='.$fid->meta_id. $core->adminurl->get(
'">'.__('Edit this feed').'</a></p>'; 'admin.plugin.zoneclearFeedServer',
['part' => 'feed', 'feed' => $fid->meta_id]
),
__('Edit this feed')
);
} }
} }
@ -247,13 +208,13 @@ class zcfsAdminBehaviors
$core->con->execute( $core->con->execute(
'DELETE FROM ' . $core->prefix . 'meta ' . 'DELETE FROM ' . $core->prefix . 'meta ' .
'WHERE post_id = ' . ((integer) $post_id) . ' ' . 'WHERE post_id = ' . ((integer) $post_id) . ' ' .
'AND meta_type '.$core->con->in(array( 'AND meta_type ' . $core->con->in([
'zoneclearfeed_url', 'zoneclearfeed_url',
'zoneclearfeed_author', 'zoneclearfeed_author',
'zoneclearfeed_site', 'zoneclearfeed_site',
'zoneclearfeed_sitename', 'zoneclearfeed_sitename',
'zoneclearfeed_id' 'zoneclearfeed_id'
)).' ' ]).' '
); );
} }
} }