2015-04-25 19:25:03 +00:00
|
|
|
<?php
|
2021-09-11 09:56:57 +00:00
|
|
|
/**
|
|
|
|
* @brief zoneclearFeedServer, a plugin for Dotclear 2
|
2021-11-06 15:30:19 +00:00
|
|
|
*
|
2021-09-11 09:56:57 +00:00
|
|
|
* @package Dotclear
|
|
|
|
* @subpackage Plugin
|
2021-11-06 15:30:19 +00:00
|
|
|
*
|
2021-09-11 09:56:57 +00:00
|
|
|
* @author Jean-Christian Denis, BG, Pierre Van Glabeke
|
2021-11-06 15:30:19 +00:00
|
|
|
*
|
2021-09-11 09:56:57 +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')) {
|
2021-09-11 09:56:57 +00:00
|
|
|
return null;
|
2015-04-25 19:25:03 +00:00
|
|
|
}
|
|
|
|
|
2022-11-15 20:05:21 +00:00
|
|
|
dcCore::app()->blog->settings->addNamespace('zoneclearFeedServer');
|
2015-04-25 19:25:03 +00:00
|
|
|
|
2022-11-15 20:05:21 +00:00
|
|
|
require_once __DIR__ . '/_widgets.php';
|
2015-04-25 19:25:03 +00:00
|
|
|
|
2022-11-15 20:05:21 +00:00
|
|
|
dcCore::app()->menu[dcAdmin::MENU_PLUGINS]->addItem(
|
2021-09-11 09:56:57 +00:00
|
|
|
__('Feeds server'),
|
2022-11-15 20:05:21 +00:00
|
|
|
dcCore::app()->adminurl->get('admin.plugin.zoneclearFeedServer'),
|
2022-11-26 14:18:27 +00:00
|
|
|
dcPage::getPF('zoneclearFeedServer/icon.svg'),
|
2021-09-11 09:56:57 +00:00
|
|
|
preg_match(
|
2022-11-15 20:05:21 +00:00
|
|
|
'/' . preg_quote(dcCore::app()->adminurl->get('admin.plugin.zoneclearFeedServer')) . '(&.*)?$/',
|
2021-09-11 09:56:57 +00:00
|
|
|
$_SERVER['REQUEST_URI']
|
|
|
|
),
|
2022-11-15 20:05:21 +00:00
|
|
|
dcCore::app()->auth->check('admin', dcCore::app()->blog->id)
|
2015-04-25 19:25:03 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
# Delete related info about feed post in meta table
|
2022-11-15 20:05:21 +00:00
|
|
|
dcCore::app()->addBehavior('adminBeforePostDelete', ['zcfsAdminBehaviors', 'adminBeforePostDelete']);
|
2015-04-25 19:25:03 +00:00
|
|
|
|
2022-11-15 20:05:21 +00:00
|
|
|
if (dcCore::app()->auth->check('admin', dcCore::app()->blog->id)) {
|
2021-09-11 09:56:57 +00:00
|
|
|
# Dashboard icon
|
2022-11-15 20:05:21 +00:00
|
|
|
dcCore::app()->addBehavior('adminDashboardFavoritesV2', ['zcfsAdminBehaviors', 'adminDashboardFavorites']);
|
2021-10-09 20:21:31 +00:00
|
|
|
# User pref
|
2022-11-15 20:05:21 +00:00
|
|
|
dcCore::app()->addBehavior('adminColumnsListsV2', ['zcfsAdminBehaviors', 'adminColumnsLists']);
|
|
|
|
dcCore::app()->addBehavior('adminFiltersListsV2', ['zcfsAdminBehaviors', 'adminFiltersLists']);
|
2021-09-11 09:56:57 +00:00
|
|
|
# Add info about feed on post page sidebar
|
2022-11-15 20:05:21 +00:00
|
|
|
dcCore::app()->addBehavior('adminPostHeaders', ['zcfsAdminBehaviors', 'adminPostHeaders']);
|
|
|
|
dcCore::app()->addBehavior('adminPostFormItems', ['zcfsAdminBehaviors', 'adminPostFormItems']);
|
2015-04-25 19:25:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Take care about tweakurls (thanks Mathieu M.)
|
2022-11-15 20:05:21 +00:00
|
|
|
if (version_compare(dcCore::app()->plugins->moduleInfo('tweakurls', 'version'), '0.8', '>=')) {
|
|
|
|
dcCore::app()->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
|
|
|
|
{
|
2021-10-09 20:21:31 +00:00
|
|
|
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',
|
2022-11-15 20:05:21 +00:00
|
|
|
__('Status') => 'feed_status',
|
2021-10-09 20:21:31 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2021-10-09 22:43:37 +00:00
|
|
|
public static function entriesSortbyCombo()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
__('Date') => 'post_dt',
|
|
|
|
__('Title') => 'post_title',
|
|
|
|
__('Category') => 'cat_title',
|
|
|
|
__('Author') => 'user_id',
|
2022-11-15 20:05:21 +00:00
|
|
|
__('Status') => 'post_status',
|
2021-10-09 22:43:37 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2021-09-11 09:56:57 +00:00
|
|
|
/**
|
|
|
|
* Favorites.
|
|
|
|
*
|
2022-11-15 20:05:21 +00:00
|
|
|
* @param dcFavorites $favs Array of favorites
|
2021-09-11 09:56:57 +00:00
|
|
|
*/
|
2022-11-15 20:05:21 +00:00
|
|
|
public static function adminDashboardFavorites(dcFavorites $favs)
|
2021-09-11 09:56:57 +00:00
|
|
|
{
|
2021-10-10 09:42:30 +00:00
|
|
|
$favs->register('zcfs', [
|
2021-09-11 09:56:57 +00:00
|
|
|
'title' => __('Feeds server'),
|
2022-11-15 20:05:21 +00:00
|
|
|
'url' => dcCore::app()->adminurl->get('admin.plugin.zoneclearFeedServer'),
|
2022-11-26 14:18:27 +00:00
|
|
|
'small-icon' => dcPage::getPF('zoneclearFeedServer/icon.svg'),
|
|
|
|
'large-icon' => dcPage::getPF('zoneclearFeedServer/icon.svg'),
|
2021-09-12 00:24:36 +00:00
|
|
|
'permissions' => 'usage,contentadmin',
|
|
|
|
'active_cb' => ['zcfsAdminBehaviors', 'adminDashboardFavoritesActive'],
|
2022-11-15 20:05:21 +00:00
|
|
|
'dashboard_cb' => ['zcfsAdminBehaviors', 'adminDashboardFavoritesCallback'],
|
2021-10-10 09:42:30 +00:00
|
|
|
]);
|
2021-09-11 09:56:57 +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'])
|
2021-09-11 09:56:57 +00:00
|
|
|
&& $params['p'] == 'zoneclearFeedServer';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Favorites hack.
|
|
|
|
*
|
|
|
|
* @param arrayObject $fav Fav attributes
|
|
|
|
*/
|
2022-11-15 20:05:21 +00:00
|
|
|
public static function adminDashboardFavoritesCallback($fav)
|
2021-09-11 09:56:57 +00:00
|
|
|
{
|
2022-11-15 20:05:21 +00:00
|
|
|
$zcfs = new zoneclearFeedServer();
|
2021-09-11 09:56:57 +00:00
|
|
|
|
2021-09-12 00:24:36 +00:00
|
|
|
$count = $zcfs->getFeeds(['feed_status' => '0'], true)->f(0);
|
2021-09-11 09:56:57 +00:00
|
|
|
if (!$count) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2021-11-06 15:30:19 +00:00
|
|
|
$fav['title'] .= '<br />' . sprintf(__('%s feed disabled', '%s feeds disabled', $count), $count);
|
2022-11-26 14:18:27 +00:00
|
|
|
$fav['large-icon'] = dcPage::getPF('zoneclearFeedServer/icon-pdate.svg');
|
2022-11-15 20:05:21 +00:00
|
|
|
$fav['url'] = dcCore::app()->adminurl->get(
|
2021-11-06 15:30:19 +00:00
|
|
|
'admin.plugin.zoneclearFeedServer',
|
2021-09-12 00:24:36 +00:00
|
|
|
['part' => 'feeds', 'sortby' => 'feed_status', 'order' => 'asc']
|
2021-09-11 09:56:57 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-10-09 20:21:31 +00:00
|
|
|
/**
|
|
|
|
* User pref columns lists.
|
|
|
|
*
|
|
|
|
* @param arrayObject $cols Columns
|
|
|
|
*/
|
2022-11-15 20:05:21 +00:00
|
|
|
public static function adminColumnsLists($cols)
|
2021-10-09 20:21:31 +00:00
|
|
|
{
|
|
|
|
$cols['zcfs_feeds'] = [
|
|
|
|
__('Feeds server: Feeds'),
|
|
|
|
[
|
2021-11-06 15:30:19 +00:00
|
|
|
'desc' => [true, __('Feed')],
|
|
|
|
'period' => [true, __('Frequency')],
|
|
|
|
'update' => [true, __('Last update')],
|
2022-11-15 20:05:21 +00:00
|
|
|
'entries' => [true, __('Entries')],
|
|
|
|
],
|
2021-10-09 20:21:31 +00:00
|
|
|
];
|
2021-10-09 22:43:37 +00:00
|
|
|
$cols['zcfs_entries'] = [
|
|
|
|
__('Feeds server: Entries'),
|
|
|
|
[
|
2021-11-06 15:30:19 +00:00
|
|
|
'date' => [true, __('Date')],
|
|
|
|
'category' => [true, __('Category')],
|
2022-11-15 20:05:21 +00:00
|
|
|
'author' => [true, __('Author')],
|
|
|
|
],
|
2021-10-09 22:43:37 +00:00
|
|
|
];
|
2021-10-09 20:21:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* User pref filters options.
|
|
|
|
*
|
|
|
|
* @param arrayObject $sorts Sort options
|
|
|
|
*/
|
2022-11-15 20:05:21 +00:00
|
|
|
public static function adminFiltersLists($sorts)
|
2021-10-09 20:21:31 +00:00
|
|
|
{
|
|
|
|
$sorts['zcfs_feeds'] = [
|
|
|
|
__('Feeds server: Feeds'),
|
|
|
|
self::feedsSortbyCombo(),
|
|
|
|
'lowername',
|
|
|
|
'asc',
|
2022-11-15 20:05:21 +00:00
|
|
|
[__('feeds per page'), 30],
|
2021-10-09 22:43:37 +00:00
|
|
|
];
|
|
|
|
$sorts['zcfs_entries'] = [
|
|
|
|
__('Feeds server: Entries'),
|
|
|
|
self::entriesSortbyCombo(),
|
|
|
|
'post_dt',
|
|
|
|
'desc',
|
2022-11-15 20:05:21 +00:00
|
|
|
[__('entries per page'), 30],
|
2021-10-09 20:21:31 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2021-09-11 09:56:57 +00:00
|
|
|
/**
|
|
|
|
* Add javascript for toggle to post edition page header.
|
2021-11-06 15:30:19 +00:00
|
|
|
*
|
2021-09-11 09:56:57 +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'));
|
2021-09-11 09:56:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add form to post sidebar.
|
2021-11-06 15:30:19 +00:00
|
|
|
*
|
2021-09-11 09:56:57 +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;
|
|
|
|
}
|
|
|
|
|
2022-11-15 20:05:21 +00:00
|
|
|
$url = dcCore::app()->meta->getMetadata([
|
2021-09-12 00:24:36 +00:00
|
|
|
'post_id' => $post->post_id,
|
|
|
|
'meta_type' => 'zoneclearfeed_url',
|
2022-11-15 20:05:21 +00:00
|
|
|
'limit' => 1,
|
2021-09-12 00:24:36 +00:00
|
|
|
]);
|
2021-09-11 09:56:57 +00:00
|
|
|
$url = $url->isEmpty() ? '' : $url->meta_id;
|
|
|
|
if (!$url) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2022-11-15 20:05:21 +00:00
|
|
|
$author = dcCore::app()->meta->getMetadata([
|
2021-09-12 00:24:36 +00:00
|
|
|
'post_id' => $post->post_id,
|
|
|
|
'meta_type' => 'zoneclearfeed_author',
|
2022-11-15 20:05:21 +00:00
|
|
|
'limit' => 1,
|
2021-09-12 00:24:36 +00:00
|
|
|
]);
|
2021-09-11 09:56:57 +00:00
|
|
|
$author = $author->isEmpty() ? '' : $author->meta_id;
|
|
|
|
|
2022-11-15 20:05:21 +00:00
|
|
|
$site = dcCore::app()->meta->getMetadata([
|
2021-09-12 00:24:36 +00:00
|
|
|
'post_id' => $post->post_id,
|
|
|
|
'meta_type' => 'zoneclearfeed_site',
|
2022-11-15 20:05:21 +00:00
|
|
|
'limit' => 1,
|
2021-09-12 00:24:36 +00:00
|
|
|
]);
|
2021-09-11 09:56:57 +00:00
|
|
|
$site = $site->isEmpty() ? '' : $site->meta_id;
|
|
|
|
|
2022-11-15 20:05:21 +00:00
|
|
|
$sitename = dcCore::app()->meta->getMetadata([
|
2021-09-12 00:24:36 +00:00
|
|
|
'post_id' => $post->post_id,
|
|
|
|
'meta_type' => 'zoneclearfeed_sitename',
|
2022-11-15 20:05:21 +00:00
|
|
|
'limit' => 1,
|
2021-09-12 00:24:36 +00:00
|
|
|
]);
|
2021-09-11 09:56:57 +00:00
|
|
|
$sitename = $sitename->isEmpty() ? '' : $sitename->meta_id;
|
|
|
|
|
|
|
|
$edit = '';
|
2022-11-15 20:05:21 +00:00
|
|
|
if (dcCore::app()->auth->check(dcAuth::PERMISSION_CONTENT_ADMIN, dcCore::app()->blog->id)) {
|
|
|
|
$fid = dcCore::app()->meta->getMetadata([
|
2021-09-12 00:24:36 +00:00
|
|
|
'post_id' => $post->post_id,
|
|
|
|
'meta_type' => 'zoneclearfeed_id',
|
2022-11-15 20:05:21 +00:00
|
|
|
'limit' => 1,
|
2021-09-12 00:24:36 +00:00
|
|
|
]);
|
2021-09-11 09:56:57 +00:00
|
|
|
if (!$fid->isEmpty()) {
|
2021-09-12 00:24:36 +00:00
|
|
|
$edit = sprintf(
|
|
|
|
'<p><a href="%s">%s</a></p>',
|
2022-11-15 20:05:21 +00:00
|
|
|
dcCore::app()->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-09-11 09:56:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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 .
|
2021-09-11 09:56:57 +00:00
|
|
|
'</div>';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete related info about feed post in meta table.
|
2021-11-06 15:30:19 +00:00
|
|
|
*
|
2021-09-11 09:56:57 +00:00
|
|
|
* @param integer $post_id Post id
|
|
|
|
*/
|
|
|
|
public static function adminBeforePostDelete($post_id)
|
|
|
|
{
|
2022-11-15 20:05:21 +00:00
|
|
|
dcCore::app()->con->execute(
|
|
|
|
'DELETE FROM ' . dcCore::app()->prefix . dcMeta::META_TABLE_NAME . ' ' .
|
2021-11-06 15:30:19 +00:00
|
|
|
'WHERE post_id = ' . ((int) $post_id) . ' ' .
|
2022-11-15 20:05:21 +00:00
|
|
|
'AND meta_type ' . dcCore::app()->con->in([
|
2021-09-11 09:56:57 +00:00
|
|
|
'zoneclearfeed_url',
|
|
|
|
'zoneclearfeed_author',
|
|
|
|
'zoneclearfeed_site',
|
|
|
|
'zoneclearfeed_sitename',
|
2022-11-15 20:05:21 +00:00
|
|
|
'zoneclearfeed_id',
|
2021-11-06 15:30:19 +00:00
|
|
|
]) . ' '
|
2021-09-11 09:56:57 +00:00
|
|
|
);
|
|
|
|
}
|
2021-11-06 15:30:19 +00:00
|
|
|
}
|