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
|
|
|
*/
|
2022-12-10 21:20:42 +00:00
|
|
|
if (!defined('DC_CONTEXT_ADMIN')) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
class zcfsFeedsActions extends dcActions
|
2015-04-25 19:25:03 +00:00
|
|
|
{
|
2021-09-11 09:56:57 +00:00
|
|
|
public $zcfs;
|
|
|
|
|
2022-11-15 20:05:21 +00:00
|
|
|
public function __construct($uri, $redirect_args = [])
|
2021-09-11 09:56:57 +00:00
|
|
|
{
|
2022-11-15 20:05:21 +00:00
|
|
|
$this->zcfs = new zoneclearFeedServer();
|
2021-09-11 09:56:57 +00:00
|
|
|
|
2022-11-15 20:05:21 +00:00
|
|
|
parent::__construct($uri, $redirect_args);
|
2021-09-12 20:35:57 +00:00
|
|
|
$this->redirect_fields = [
|
2022-11-15 20:05:21 +00:00
|
|
|
'sortby', 'order', 'page', 'nb',
|
2021-09-12 20:35:57 +00:00
|
|
|
];
|
2021-09-11 09:56:57 +00:00
|
|
|
$this->field_entries = 'feeds';
|
2021-11-06 15:30:19 +00:00
|
|
|
$this->caller_title = __('Feeds');
|
2021-09-11 09:56:57 +00:00
|
|
|
$this->loadDefaults();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function loadDefaults()
|
|
|
|
{
|
2022-12-10 21:20:42 +00:00
|
|
|
zcfsDefaultFeedsActions::zcfsFeedsActions($this);
|
|
|
|
dcCore::app()->callBehavior('zcfsFeedsActions', $this);
|
2021-09-11 09:56:57 +00:00
|
|
|
}
|
|
|
|
|
2021-09-12 20:35:57 +00:00
|
|
|
public function beginPage($breadcrumb = '', $head = '')
|
2021-09-11 09:56:57 +00:00
|
|
|
{
|
2021-11-06 15:30:19 +00:00
|
|
|
echo
|
2021-09-12 20:35:57 +00:00
|
|
|
'<html><head><title>' . __('Feeds server') . '</title>' .
|
|
|
|
dcPage::jsLoad('js/_posts_actions.js') .
|
|
|
|
$head .
|
|
|
|
'</script></head><body>' .
|
|
|
|
$breadcrumb .
|
|
|
|
'<p><a class="back" href="' . $this->getRedirection(true) . '">' .
|
|
|
|
__('Back to feeds list') . '</a></p>';
|
2021-09-11 09:56:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function endPage()
|
|
|
|
{
|
2021-09-12 20:35:57 +00:00
|
|
|
echo '</body></html>';
|
2021-09-11 09:56:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function error(Exception $e)
|
|
|
|
{
|
2022-11-15 20:05:21 +00:00
|
|
|
dcCore::app()->error->add($e->getMessage());
|
2021-09-12 20:35:57 +00:00
|
|
|
$this->beginPage(
|
|
|
|
dcPage::breadcrumb([
|
2022-11-15 20:05:21 +00:00
|
|
|
html::escapeHTML(dcCore::app()->blog->name) => '',
|
|
|
|
$this->getCallerTitle() => $this->getRedirection(true),
|
|
|
|
__('Feeds actions') => '',
|
2021-09-12 20:35:57 +00:00
|
|
|
])
|
|
|
|
);
|
2021-09-11 09:56:57 +00:00
|
|
|
$this->endPage();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function fetchEntries($from)
|
|
|
|
{
|
|
|
|
if (!empty($from['feeds'])) {
|
|
|
|
$params['feed_id'] = $from['feeds'];
|
|
|
|
|
|
|
|
$feeds = $this->zcfs->getFeeds($params);
|
2021-11-06 15:30:19 +00:00
|
|
|
while ($feeds->fetch()) {
|
2021-09-11 09:56:57 +00:00
|
|
|
$this->entries[$feeds->feed_id] = $feeds->feed_name;
|
|
|
|
}
|
|
|
|
$this->rs = $feeds;
|
2021-09-12 20:35:57 +00:00
|
|
|
} else {
|
2022-11-15 20:05:21 +00:00
|
|
|
$this->rs = dcCore::app()->con->select(
|
2022-11-30 20:54:14 +00:00
|
|
|
'SELECT blog_id FROM ' . dcCore::app()->prefix . dcBlog::BLOG_TABLE_NAME . ' WHERE false'
|
2021-09-11 09:56:57 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2015-04-25 19:25:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ingroup DC_PLUGIN_ZONECLEARFEEDSERVER
|
|
|
|
* @brief Feeds server - Default actions methods
|
|
|
|
* @since 2.6
|
|
|
|
* @see dcDefaultPostsActionsPage for mor info
|
|
|
|
*/
|
|
|
|
class zcfsDefaultFeedsActions
|
|
|
|
{
|
2022-12-10 21:20:42 +00:00
|
|
|
public static function zcfsFeedsActions(zcfsFeedsActions $ap)
|
2021-09-11 09:56:57 +00:00
|
|
|
{
|
|
|
|
$ap->addAction(
|
2021-09-12 20:35:57 +00:00
|
|
|
[__('Change category') => 'changecat'],
|
|
|
|
['zcfsDefaultFeedsActions', 'doChangeCategory']
|
2021-09-11 09:56:57 +00:00
|
|
|
);
|
|
|
|
$ap->addAction(
|
2021-09-12 20:35:57 +00:00
|
|
|
[__('Change update interval') => 'changeint'],
|
|
|
|
['zcfsDefaultFeedsActions', 'doChangeInterval']
|
2021-09-11 09:56:57 +00:00
|
|
|
);
|
|
|
|
$ap->addAction(
|
2021-09-12 20:35:57 +00:00
|
|
|
[__('Disable feed update') => 'disablefeed'],
|
|
|
|
['zcfsDefaultFeedsActions', 'doEnableFeed']
|
2021-09-11 09:56:57 +00:00
|
|
|
);
|
|
|
|
$ap->addAction(
|
2021-09-12 20:35:57 +00:00
|
|
|
[__('Enable feed update') => 'enablefeed'],
|
|
|
|
['zcfsDefaultFeedsActions', 'doEnableFeed']
|
2021-09-11 09:56:57 +00:00
|
|
|
);
|
|
|
|
$ap->addAction(
|
2021-09-12 20:35:57 +00:00
|
|
|
[__('Reset last update') => 'resetupdlast'],
|
|
|
|
['zcfsDefaultFeedsActions', 'doResetUpdate']
|
2021-09-11 09:56:57 +00:00
|
|
|
);
|
|
|
|
$ap->addAction(
|
2021-09-12 20:35:57 +00:00
|
|
|
[__('Update (check) feed') => 'updatefeed'],
|
|
|
|
['zcfsDefaultFeedsActions', 'doUpdateFeed']
|
2021-09-11 09:56:57 +00:00
|
|
|
);
|
|
|
|
$ap->addAction(
|
2021-09-12 20:35:57 +00:00
|
|
|
[__('Delete related posts') => 'deletepost'],
|
|
|
|
['zcfsDefaultFeedsActions', 'doDeletePost']
|
2021-09-11 09:56:57 +00:00
|
|
|
);
|
|
|
|
$ap->addAction(
|
2021-09-12 20:35:57 +00:00
|
|
|
[__('Delete feed (without related posts)') => 'deletefeed'],
|
|
|
|
['zcfsDefaultFeedsActions', 'doDeleteFeed']
|
2021-09-11 09:56:57 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-12-10 21:20:42 +00:00
|
|
|
public static function doEnableFeed(zcfsFeedsActions $ap, $post)
|
2021-09-11 09:56:57 +00:00
|
|
|
{
|
|
|
|
$enable = $ap->getAction() == 'enablefeed';
|
2021-11-06 15:30:19 +00:00
|
|
|
$ids = $ap->getIDs();
|
2021-09-11 09:56:57 +00:00
|
|
|
|
|
|
|
if (empty($ids)) {
|
|
|
|
throw new Exception(__('No feeds selected'));
|
|
|
|
}
|
|
|
|
|
2021-11-06 15:30:19 +00:00
|
|
|
foreach ($ids as $id) {
|
2021-09-11 09:56:57 +00:00
|
|
|
$ap->zcfs->enableFeed($id, $enable);
|
|
|
|
}
|
|
|
|
|
2022-11-15 20:05:21 +00:00
|
|
|
dcAdminNotices::addSuccessNotice(sprintf(
|
2021-09-11 09:56:57 +00:00
|
|
|
$enable ?
|
|
|
|
__(
|
|
|
|
'%d feed has been successfully enabled.',
|
|
|
|
'%d feeds have been successfully enabled.',
|
|
|
|
count($ids)
|
|
|
|
)
|
|
|
|
:
|
|
|
|
__(
|
|
|
|
'%d feed has been successfully disabled.',
|
|
|
|
'%d feeds have been successfully disabled.',
|
|
|
|
count($ids)
|
2021-11-06 15:30:19 +00:00
|
|
|
),
|
2021-09-11 09:56:57 +00:00
|
|
|
count($ids)
|
|
|
|
));
|
|
|
|
$ap->redirect(true);
|
|
|
|
}
|
|
|
|
|
2022-12-10 21:20:42 +00:00
|
|
|
public static function doDeletePost(zcfsFeedsActions $ap, $post)
|
2021-09-11 09:56:57 +00:00
|
|
|
{
|
2021-09-12 20:35:57 +00:00
|
|
|
$types = [
|
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-09-12 20:35:57 +00:00
|
|
|
];
|
2021-09-11 09:56:57 +00:00
|
|
|
|
|
|
|
$ids = $ap->getIDs();
|
|
|
|
|
|
|
|
if (empty($ids)) {
|
|
|
|
throw new Exception(__('No feeds selected'));
|
|
|
|
}
|
|
|
|
|
2021-11-06 15:30:19 +00:00
|
|
|
foreach ($ids as $id) {
|
2021-09-12 20:35:57 +00:00
|
|
|
$posts = $ap->zcfs->getPostsByFeed([
|
2022-11-15 20:05:21 +00:00
|
|
|
'feed_id' => $id,
|
2021-09-12 20:35:57 +00:00
|
|
|
]);
|
2021-09-11 09:56:57 +00:00
|
|
|
|
2021-11-06 15:30:19 +00:00
|
|
|
while ($posts->fetch()) {
|
2022-11-15 20:05:21 +00:00
|
|
|
dcCore::app()->blog->delPost($posts->post_id);
|
|
|
|
dcCore::app()->con->execute(
|
|
|
|
'DELETE FROM ' . dcCore::app()->prefix . dcMeta::META_TABLE_NAME . ' ' .
|
2021-09-12 20:35:57 +00:00
|
|
|
'WHERE post_id = ' . $posts->post_id . ' ' .
|
2022-11-15 20:05:21 +00:00
|
|
|
'AND meta_type ' . dcCore::app()->con->in($types) . ' '
|
2021-09-11 09:56:57 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-15 20:05:21 +00:00
|
|
|
dcAdminNotices::addSuccessNotice(
|
2021-11-06 15:30:19 +00:00
|
|
|
__('Entries have been successfully deleted.')
|
2021-09-11 09:56:57 +00:00
|
|
|
);
|
|
|
|
$ap->redirect(true);
|
|
|
|
}
|
|
|
|
|
2022-12-10 21:20:42 +00:00
|
|
|
public static function doDeleteFeed(zcfsFeedsActions $ap, $post)
|
2021-09-11 09:56:57 +00:00
|
|
|
{
|
|
|
|
$ids = $ap->getIDs();
|
|
|
|
|
|
|
|
if (empty($ids)) {
|
|
|
|
throw new Exception(__('No feeds selected'));
|
|
|
|
}
|
|
|
|
|
2021-11-06 15:30:19 +00:00
|
|
|
foreach ($ids as $id) {
|
2021-09-11 09:56:57 +00:00
|
|
|
$ap->zcfs->delFeed($id);
|
|
|
|
}
|
|
|
|
|
2022-11-15 20:05:21 +00:00
|
|
|
dcAdminNotices::addSuccessNotice(sprintf(
|
2021-09-11 09:56:57 +00:00
|
|
|
__(
|
|
|
|
'%d feed has been successfully deleted.',
|
|
|
|
'%d feeds have been successfully deleted.',
|
|
|
|
count($ids)
|
|
|
|
),
|
|
|
|
count($ids)
|
|
|
|
));
|
|
|
|
$ap->redirect(true);
|
|
|
|
}
|
|
|
|
|
2022-12-10 21:20:42 +00:00
|
|
|
public static function doUpdateFeed(zcfsFeedsActions $ap, $post)
|
2021-09-11 09:56:57 +00:00
|
|
|
{
|
|
|
|
$ids = $ap->getIDs();
|
|
|
|
|
|
|
|
if (empty($ids)) {
|
|
|
|
throw new Exception(__('No feeds selected'));
|
|
|
|
}
|
|
|
|
|
2021-11-06 15:30:19 +00:00
|
|
|
foreach ($ids as $id) {
|
2021-09-11 09:56:57 +00:00
|
|
|
$ap->zcfs->checkFeedsUpdate($id, true);
|
|
|
|
}
|
|
|
|
|
2022-11-15 20:05:21 +00:00
|
|
|
dcAdminNotices::addSuccessNotice(sprintf(
|
2021-09-11 09:56:57 +00:00
|
|
|
__(
|
|
|
|
'%d feed has been successfully updated.',
|
|
|
|
'%d feeds have been successfully updated.',
|
|
|
|
count($ids)
|
|
|
|
),
|
|
|
|
count($ids)
|
|
|
|
));
|
|
|
|
$ap->redirect(true);
|
|
|
|
}
|
|
|
|
|
2022-12-10 21:20:42 +00:00
|
|
|
public static function doResetUpdate(zcfsFeedsActions $ap, $post)
|
2021-09-11 09:56:57 +00:00
|
|
|
{
|
|
|
|
$ids = $ap->getIDs();
|
|
|
|
|
|
|
|
if (empty($ids)) {
|
|
|
|
throw new Exception(__('No feeds selected'));
|
|
|
|
}
|
|
|
|
|
2021-11-06 15:30:19 +00:00
|
|
|
foreach ($ids as $id) {
|
|
|
|
$cur = $ap->zcfs->openCursor();
|
2021-09-11 09:56:57 +00:00
|
|
|
$cur->feed_upd_last = 0;
|
|
|
|
$ap->zcfs->updFeed($id, $cur);
|
|
|
|
$ap->zcfs->checkFeedsUpdate($id, true);
|
|
|
|
}
|
|
|
|
|
2022-11-15 20:05:21 +00:00
|
|
|
dcAdminNotices::addSuccessNotice(sprintf(
|
2021-09-11 09:56:57 +00:00
|
|
|
__(
|
|
|
|
'Last update of %s feed successfully reseted.',
|
|
|
|
'Last update of %s feeds successfully reseted.',
|
|
|
|
count($ids)
|
|
|
|
),
|
|
|
|
count($ids)
|
|
|
|
));
|
|
|
|
$ap->redirect(true);
|
|
|
|
}
|
|
|
|
|
2022-12-10 21:20:42 +00:00
|
|
|
public static function doChangeCategory(zcfsFeedsActions $ap, $post)
|
2021-09-11 09:56:57 +00:00
|
|
|
{
|
|
|
|
if (isset($post['upd_cat_id'])) {
|
|
|
|
$ids = $ap->getIDs();
|
|
|
|
|
|
|
|
if (empty($ids)) {
|
|
|
|
throw new Exception(__('No feeds selected'));
|
|
|
|
}
|
|
|
|
|
2021-11-06 15:30:19 +00:00
|
|
|
$cat_id = abs((int) $post['upd_cat_id']);
|
2021-09-11 09:56:57 +00:00
|
|
|
|
2021-11-06 15:30:19 +00:00
|
|
|
foreach ($ids as $id) {
|
|
|
|
$cur = $ap->zcfs->openCursor();
|
2021-09-11 09:56:57 +00:00
|
|
|
$cur->cat_id = $cat_id == 0 ? null : $cat_id;
|
|
|
|
$ap->zcfs->updFeed($id, $cur);
|
|
|
|
}
|
|
|
|
|
2022-11-15 20:05:21 +00:00
|
|
|
dcAdminNotices::addSuccessNotice(sprintf(
|
2021-09-11 09:56:57 +00:00
|
|
|
__(
|
|
|
|
'Category of %s feed successfully changed.',
|
|
|
|
'Category of %s feeds successfully changed.',
|
|
|
|
count($ids)
|
|
|
|
),
|
|
|
|
count($ids)
|
|
|
|
));
|
|
|
|
$ap->redirect(true);
|
2021-09-12 20:35:57 +00:00
|
|
|
} else {
|
2021-09-11 09:56:57 +00:00
|
|
|
$categories_combo = dcAdminCombos::getCategoriesCombo(
|
2022-11-15 20:05:21 +00:00
|
|
|
dcCore::app()->blog->getCategories()
|
2021-09-11 09:56:57 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
$ap->beginPage(
|
2021-09-12 20:35:57 +00:00
|
|
|
dcPage::breadcrumb([
|
2022-11-15 20:05:21 +00:00
|
|
|
html::escapeHTML(dcCore::app()->blog->name) => '',
|
|
|
|
__('Feeds server') => '',
|
|
|
|
$ap->getCallerTitle() => $ap->getRedirection(true),
|
|
|
|
__('Change category for this selection') => '',
|
2021-11-06 15:30:19 +00:00
|
|
|
])
|
|
|
|
);
|
2021-09-11 09:56:57 +00:00
|
|
|
|
|
|
|
echo
|
2021-09-12 20:35:57 +00:00
|
|
|
'<form action="' . $ap->getURI() . '" method="post">' .
|
|
|
|
$ap->getCheckboxes() .
|
|
|
|
'<p><label for="upd_cat_id" class="classic">' . __('Category:') . '</label> ' .
|
|
|
|
form::combo(['upd_cat_id'], $categories_combo, '') .
|
2022-11-15 20:05:21 +00:00
|
|
|
dcCore::app()->formNonce() .
|
2021-09-12 20:35:57 +00:00
|
|
|
$ap->getHiddenFields() .
|
2021-11-06 15:30:19 +00:00
|
|
|
form::hidden(['action'], 'changecat') .
|
2021-09-12 20:35:57 +00:00
|
|
|
'<input type="submit" value="' . __('Save') . '" /></p>' .
|
2021-09-11 09:56:57 +00:00
|
|
|
'</form>';
|
|
|
|
|
|
|
|
$ap->endPage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-10 21:20:42 +00:00
|
|
|
public static function doChangeInterval(zcfsFeedsActions $ap, $post)
|
2021-09-11 09:56:57 +00:00
|
|
|
{
|
|
|
|
if (isset($post['upd_upd_int'])) {
|
|
|
|
$ids = $ap->getIDs();
|
|
|
|
|
|
|
|
if (empty($ids)) {
|
|
|
|
throw new Exception(__('No feeds selected'));
|
|
|
|
}
|
|
|
|
|
2021-11-06 15:30:19 +00:00
|
|
|
$upd_int = abs((int) $post['upd_upd_int']);
|
2021-09-11 09:56:57 +00:00
|
|
|
|
2021-11-06 15:30:19 +00:00
|
|
|
foreach ($ids as $id) {
|
|
|
|
$cur = $ap->zcfs->openCursor();
|
2021-09-11 09:56:57 +00:00
|
|
|
$cur->feed_upd_int = $upd_int;
|
|
|
|
$ap->zcfs->updFeed($id, $cur);
|
|
|
|
}
|
|
|
|
|
2022-11-15 20:05:21 +00:00
|
|
|
dcAdminNotices::addSuccessNotice(sprintf(
|
2021-09-11 09:56:57 +00:00
|
|
|
__(
|
|
|
|
'Update frequency of %s feed successfully changed.',
|
|
|
|
'Update frequency of %s feeds successfully changed.',
|
|
|
|
count($ids)
|
|
|
|
),
|
|
|
|
count($ids)
|
|
|
|
));
|
|
|
|
$ap->redirect(true);
|
2021-11-06 15:30:19 +00:00
|
|
|
} else {
|
2021-09-11 09:56:57 +00:00
|
|
|
$ap->beginPage(
|
|
|
|
dcPage::breadcrumb(
|
2021-09-12 20:35:57 +00:00
|
|
|
[
|
2022-11-15 20:05:21 +00:00
|
|
|
html::escapeHTML(dcCore::app()->blog->name) => '',
|
2021-11-06 15:30:19 +00:00
|
|
|
__('Feeds server') => '',
|
|
|
|
$ap->getCallerTitle() => $ap->getRedirection(true),
|
2022-11-15 20:05:21 +00:00
|
|
|
__('Change update frequency for this selection') => '',
|
2021-11-06 15:30:19 +00:00
|
|
|
]
|
|
|
|
)
|
|
|
|
);
|
2021-09-11 09:56:57 +00:00
|
|
|
|
|
|
|
echo
|
2021-09-12 20:35:57 +00:00
|
|
|
'<form action="' . $ap->getURI() . '" method="post">' .
|
|
|
|
$ap->getCheckboxes() .
|
|
|
|
'<p><label for="upd_upd_int" class="classic">' . __('Frequency:') . '</label> ' .
|
|
|
|
form::combo(['upd_upd_int'], $ap->zcfs->getAllUpdateInterval(), '') .
|
2022-11-15 20:05:21 +00:00
|
|
|
dcCore::app()->formNonce() .
|
2021-09-12 20:35:57 +00:00
|
|
|
$ap->getHiddenFields() .
|
|
|
|
form::hidden(['action'], 'changeint') .
|
|
|
|
'<input type="submit" value="' . __('Save') . '" /></p>' .
|
2021-09-11 09:56:57 +00:00
|
|
|
'</form>';
|
|
|
|
|
|
|
|
$ap->endPage();
|
|
|
|
}
|
|
|
|
}
|
2021-11-06 15:30:19 +00:00
|
|
|
}
|