zoneclearFeedServer/_admin.php

294 lines
9.3 KiB
PHP
Raw Normal View History

2015-04-25 19:25:03 +00:00
<?php
/**
* @brief zoneclearFeedServer, a plugin for Dotclear 2
2021-11-06 15:30:19 +00:00
*
* @package Dotclear
* @subpackage Plugin
2021-11-06 15:30:19 +00:00
*
* @author Jean-Christian Denis, BG, Pierre Van Glabeke
2021-11-06 15:30:19 +00:00
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
2015-04-25 19:25:03 +00:00
if (!defined('DC_CONTEXT_ADMIN')) {
return null;
2015-04-25 19:25:03 +00:00
}
$core->blog->settings->addNamespace('zoneclearFeedServer');
2021-09-12 00:24:36 +00:00
require_once dirname(__FILE__) . '/_widgets.php';
2015-04-25 19:25:03 +00:00
2021-09-12 00:24:36 +00:00
$_menu['Plugins']->addItem(
__('Feeds server'),
2021-09-12 00:24:36 +00:00
$core->adminurl->get('admin.plugin.zoneclearFeedServer'),
dcPage::getPF('zoneclearFeedServer/icon.png'),
preg_match(
2021-11-06 15:30:19 +00:00
'/' . preg_quote($core->adminurl->get('admin.plugin.zoneclearFeedServer')) . '(&.*)?$/',
$_SERVER['REQUEST_URI']
),
$core->auth->check('admin', $core->blog->id)
2015-04-25 19:25:03 +00:00
);
# Delete related info about feed post in meta table
2021-11-06 15:30:19 +00:00
$core->addBehavior('adminBeforePostDelete', ['zcfsAdminBehaviors', 'adminBeforePostDelete']);
2015-04-25 19:25:03 +00:00
if ($core->auth->check('admin', $core->blog->id)) {
# Dashboard icon
2021-09-12 00:24:36 +00:00
$core->addBehavior('adminDashboardFavorites', ['zcfsAdminBehaviors', 'adminDashboardFavorites']);
# User pref
$core->addBehavior('adminColumnsLists', ['zcfsAdminBehaviors', 'adminColumnsLists']);
$core->addBehavior('adminFiltersLists', ['zcfsAdminBehaviors', 'adminFiltersLists']);
# Add info about feed on post page sidebar
2021-09-12 00:24:36 +00:00
$core->addBehavior('adminPostHeaders', ['zcfsAdminBehaviors', 'adminPostHeaders']);
$core->addBehavior('adminPostFormItems', ['zcfsAdminBehaviors', 'adminPostFormItems']);
2015-04-25 19:25:03 +00:00
}
# Take care about tweakurls (thanks Mathieu M.)
if (version_compare($core->plugins->moduleInfo('tweakurls', 'version'), '0.8', '>=')) {
2021-09-12 00:24:36 +00:00
$core->addbehavior('zcfsAfterPostCreate', ['zoneclearFeedServer', 'tweakurlsAfterPostCreate']);
2015-04-25 19:25:03 +00:00
}
/**
* @ingroup DC_PLUGIN_ZONECLEARFEEDSERVER
* @brief Mix your blog with a feeds planet - admin methods.
* @since 2.6
*/
class zcfsAdminBehaviors
{
public static function feedsSortbyCombo()
{
return [
2021-10-28 20:55:43 +00:00
__('Date') => 'feed_upddt',
__('Name') => 'lowername',
__('Frequency') => 'feed_upd_int',
__('Update date') => 'feed_upd_last',
__('Status') => 'feed_status'
];
}
public static function entriesSortbyCombo()
{
return [
__('Date') => 'post_dt',
__('Title') => 'post_title',
__('Category') => 'cat_title',
__('Author') => 'user_id',
__('Status') => 'post_status'
];
}
/**
* Favorites.
*
* @param dcCore $core dcCore instance
* @param arrayObject $favs Array of favorites
*/
2021-09-12 00:24:36 +00:00
public static function adminDashboardFavorites(dcCore $core, dcFavorites $favs)
{
2021-10-10 09:42:30 +00:00
$favs->register('zcfs', [
'title' => __('Feeds server'),
2021-09-12 00:24:36 +00:00
'url' => $core->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']
2021-10-10 09:42:30 +00:00
]);
}
/**
* Favorites selection.
*
* @param string $request Requested page
* @param array $params Requested parameters
*/
public static function adminDashboardFavoritesActive($request, $params)
{
2021-11-06 15:30:19 +00:00
return $request == 'plugin.php'
&& isset($params['p'])
&& $params['p'] == 'zoneclearFeedServer';
}
/**
* Favorites hack.
*
* @param dcCore $core dcCore instance
* @param arrayObject $fav Fav attributes
*/
public static function adminDashboardFavoritesCallback(dcCore $core, $fav)
{
$zcfs = new zoneclearFeedServer($core);
2021-09-12 00:24:36 +00:00
$count = $zcfs->getFeeds(['feed_status' => '0'], true)->f(0);
if (!$count) {
return null;
}
2021-11-06 15:30:19 +00:00
$fav['title'] .= '<br />' . sprintf(__('%s feed disabled', '%s feeds disabled', $count), $count);
2021-09-12 00:24:36 +00:00
$fav['large-icon'] = dcPage::getPF('zoneclearFeedServer/icon-big-update.png');
2021-11-06 15:30:19 +00:00
$fav['url'] = $core->adminurl->get(
'admin.plugin.zoneclearFeedServer',
2021-09-12 00:24:36 +00:00
['part' => 'feeds', 'sortby' => 'feed_status', 'order' => 'asc']
);
}
/**
* User pref columns lists.
*
* @param dcCore $core dcCore instance
* @param arrayObject $cols Columns
*/
public static function adminColumnsLists(dcCore $core, $cols)
{
$cols['zcfs_feeds'] = [
__('Feeds server: Feeds'),
[
2021-11-06 15:30:19 +00:00
'desc' => [true, __('Feed')],
'period' => [true, __('Frequency')],
'update' => [true, __('Last update')],
'entries' => [true, __('Entries')]
]
];
$cols['zcfs_entries'] = [
__('Feeds server: Entries'),
[
2021-11-06 15:30:19 +00:00
'date' => [true, __('Date')],
'category' => [true, __('Category')],
'author' => [true, __('Author')]
]
];
}
/**
* User pref filters options.
*
* @param dcCore $core dcCore instance
* @param arrayObject $sorts Sort options
*/
public static function adminFiltersLists(dcCore $core, $sorts)
{
$sorts['zcfs_feeds'] = [
__('Feeds server: Feeds'),
self::feedsSortbyCombo(),
'lowername',
'asc',
[__('feeds per page'), 30]
];
$sorts['zcfs_entries'] = [
__('Feeds server: Entries'),
self::entriesSortbyCombo(),
'post_dt',
'desc',
[__('entries per page'), 30]
];
}
/**
* Add javascript for toggle to post edition page header.
2021-11-06 15:30:19 +00:00
*
* @return string Page header
*/
public static function adminPostHeaders()
{
2021-09-12 00:24:36 +00:00
return dcPage::jsLoad(dcPage::getPF('zoneclearFeedServer/js/post.js'));
}
/**
* Add form to post sidebar.
2021-11-06 15:30:19 +00:00
*
* @param ArrayObject $main_items Main items
* @param ArrayObject $sidebar_items Sidebar items
* @param record $post Post record or null
*/
public static function adminPostFormItems(ArrayObject $main_items, ArrayObject $sidebar_items, $post)
{
if ($post === null || $post->post_type != 'post') {
return null;
}
global $core;
2021-09-12 00:24:36 +00:00
$url = $core->meta->getMetadata([
'post_id' => $post->post_id,
'meta_type' => 'zoneclearfeed_url',
'limit' => 1
]);
$url = $url->isEmpty() ? '' : $url->meta_id;
if (!$url) {
return null;
}
2021-09-12 00:24:36 +00:00
$author = $core->meta->getMetadata([
'post_id' => $post->post_id,
'meta_type' => 'zoneclearfeed_author',
'limit' => 1
]);
$author = $author->isEmpty() ? '' : $author->meta_id;
2021-09-12 00:24:36 +00:00
$site = $core->meta->getMetadata([
'post_id' => $post->post_id,
'meta_type' => 'zoneclearfeed_site',
'limit' => 1
]);
$site = $site->isEmpty() ? '' : $site->meta_id;
2021-09-12 00:24:36 +00:00
$sitename = $core->meta->getMetadata([
'post_id' => $post->post_id,
'meta_type' => 'zoneclearfeed_sitename',
'limit' => 1
]);
$sitename = $sitename->isEmpty() ? '' : $sitename->meta_id;
$edit = '';
if ($core->auth->check('admin', $core->blog->id)) {
2021-09-12 00:24:36 +00:00
$fid = $core->meta->getMetadata([
'post_id' => $post->post_id,
'meta_type' => 'zoneclearfeed_id',
'limit' => 1
]);
if (!$fid->isEmpty()) {
2021-09-12 00:24:36 +00:00
$edit = sprintf(
'<p><a href="%s">%s</a></p>',
$core->adminurl->get(
2021-11-06 15:30:19 +00:00
'admin.plugin.zoneclearFeedServer',
2021-10-10 09:42:30 +00:00
['part' => 'feed', 'feed_id' => $fid->meta_id]
2021-09-12 00:24:36 +00:00
),
__('Edit this feed')
);
}
}
2021-11-06 15:30:19 +00:00
$sidebar_items['options-box']['items']['zcfs'] = '<div id="zcfs">' .
2021-09-12 00:24:36 +00:00
'<h5>' . __('Feed source') . '</h5>' .
'<p>' .
'<a href="' . $url . '" title="' . $author . ' - ' . $url . '">' . __('feed URL') . '</a> - ' .
'<a href="' . $site . '" title="' . $sitename . ' - ' . $site . '">' . __('site URL') . '</a>' .
'</p>' .
$edit .
'</div>';
}
/**
* Delete related info about feed post in meta table.
2021-11-06 15:30:19 +00:00
*
* @param integer $post_id Post id
*/
public static function adminBeforePostDelete($post_id)
{
global $core;
$core->con->execute(
2021-09-12 00:24:36 +00:00
'DELETE FROM ' . $core->prefix . 'meta ' .
2021-11-06 15:30:19 +00:00
'WHERE post_id = ' . ((int) $post_id) . ' ' .
2021-09-12 00:24:36 +00:00
'AND meta_type ' . $core->con->in([
'zoneclearfeed_url',
'zoneclearfeed_author',
'zoneclearfeed_site',
'zoneclearfeed_sitename',
'zoneclearfeed_id'
2021-11-06 15:30:19 +00:00
]) . ' '
);
}
2021-11-06 15:30:19 +00:00
}