zoneclearFeedServer/inc/class.zcfsurlhandler.php

103 lines
3.2 KiB
PHP
Raw Normal View History

2022-12-10 21:20:42 +00:00
<?php
/**
* @brief zoneclearFeedServer, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Jean-Christian Denis, BG, Pierre Van Glabeke
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
if (!defined('DC_RC_PATH')) {
return null;
}
/**
* @ingroup DC_PLUGIN_ZONECLEARFEEDSERVER
* @brief Mix your blog with a feeds planet - url handler methods.
* @since 2.6
*/
class zcfsUrlHandler extends dcUrlHandlers
{
/**
* Feeds source page and update methods.
*
* @param array $args Page arguments
* @return mixed
*/
public static function zcFeedsPage($args)
{
$s = dcCore::app()->blog->settings->__get(basename(dirname('../' . __DIR__)));
# Not active
if (!$s->zoneclearFeedServer_active) {
self::p404();
return null;
}
# Update feeds (from ajax or other post resquest)
if ($args == '/zcfsupd' && 3 == $s->zoneclearFeedServer_bhv_pub_upd) {
$msg = '';
if (!empty($_POST['blogId']) && html::escapeJS(dcCore::app()->blog->id) == $_POST['blogId']) {
try {
$zc = new zoneclearFeedServer();
if ($zc->checkFeedsUpdate()) {
$msg = sprintf(
2022-12-10 22:02:38 +00:00
'<status>%s</status><message>%s</message>',
2022-12-10 21:20:42 +00:00
'ok',
'Feeds updated successfully'
);
}
} catch (Exception $e) {
}
}
if (empty($msg)) {
$msg = sprintf(
2022-12-10 22:02:38 +00:00
'<status>%s</status><message>%s</message>',
2022-12-10 21:20:42 +00:00
'failed',
'Failed to update feeds'
);
}
header('Content-Type: application/xml; charset=UTF-8');
echo
'<?xml version="1.0" encoding="utf-8"?> ' . "\n" .
'<response><rsp>' . "\n" .
$msg . "\n" .
'</rsp></response>';
exit(1);
# Server js
} elseif ($args == '/zcfsupd.js' && 3 == $s->zoneclearFeedServer_bhv_pub_upd) {
dcCore::app()->tpl->setPath(dcCore::app()->tpl->getPath(), __DIR__ . '/default-templates');
self::serveDocument(
'zcfsupd.js',
'text/javascript',
false,
false
);
# Server feeds description page
} elseif (in_array($args, ['', '/']) && $s->zoneclearFeedServer_pub_active) {
$tplset = dcCore::app()->themes->moduleInfo(dcCore::app()->blog->settings->system->theme, 'tplset');
$path = __DIR__ . '/default-templates/';
if (!empty($tplset) && is_dir($path . $tplset)) {
dcCore::app()->tpl->setPath(dcCore::app()->tpl->getPath(), $path . $tplset);
} else {
dcCore::app()->tpl->setPath(dcCore::app()->tpl->getPath(), $path . DC_DEFAULT_TPLSET);
}
self::serveDocument('zcfeeds.html');
}
# Unknow
else {
self::p404();
}
return null;
}
}