zoneclearFeedServer/src/Frontend.php

119 lines
3.7 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
*/
2023-05-07 22:40:58 +00:00
declare(strict_types=1);
2015-04-25 19:25:03 +00:00
2023-05-07 22:40:58 +00:00
namespace Dotclear\Plugin\zoneclearFeedServer;
2015-04-25 19:25:03 +00:00
2023-05-07 22:40:58 +00:00
use dcCore;
use dcNsProcess;
use dcUtils;
use Dotclear\Database\MetaRecord;
use Dotclear\Helper\Html\Html;
use Exception;
2015-04-25 19:25:03 +00:00
2023-05-07 22:40:58 +00:00
/**
* Frontend prepend.
*/
class Frontend extends dcNsProcess
{
public static function init(): bool
{
static::$init = My::phpCompliant();
2015-04-25 19:25:03 +00:00
2023-05-07 22:40:58 +00:00
return static::$init;
}
2015-04-25 19:25:03 +00:00
2023-05-07 22:40:58 +00:00
public static function process(): bool
{
if (!static::$init) {
return false;
}
2015-04-25 19:25:03 +00:00
2023-05-07 22:40:58 +00:00
$s = ZoneclearFeedServer::instance()->settings;
2015-04-25 19:25:03 +00:00
2023-05-07 22:40:58 +00:00
dcCore::app()->addBehaviors([
// posts record
'coreBlogGetPosts' => function (MetaRecord $rs): void {
RsExtPosts::$brother_extensions = $rs->extensions();
$rs->extend(RsExtPosts::class);
},
// breadcrumb
'publicBreadcrumb' => function (string $context, string $separator): string {
return $context == 'zoneclearFeedsPage' ? __('List of feeds') : '';
},
// widgets registration
'initWidgets' => [Widgets::class, 'init'],
]);
// Register template blocks
foreach (My::TPL_BLOCKS as $block) {
dcCore::app()->tpl->addBlock('zc' . $block, [Template::class, $block]);
}
// Register template values
foreach (My::TPL_VALUES as $value) {
dcCore::app()->tpl->addValue('zc' . $value, [Template::class, $value]);
}
// module not active
if (!$s->active) {
return true;
}
2015-04-25 19:25:03 +00:00
2023-05-07 22:40:58 +00:00
// feeds update methods
if (1 == $s->bhv_pub_upd) {
dcCore::app()->addBehavior('publicBeforeDocumentV2', function (): void {
if (in_array(dcCore::app()->url->type, ['default', 'feed'])) {
try {
ZoneclearFeedServer::instance()->checkFeedsUpdate();
} catch (Exception $e) {
}
};
});
} elseif (2 == $s->bhv_pub_upd) {
dcCore::app()->addBehavior('publicAfterDocumentV2', function (): void {
try {
ZoneclearFeedServer::instance()->checkFeedsUpdate();
} catch (Exception $e) {
pdump($e);
}
});
} elseif (3 == $s->bhv_pub_upd) {
dcCore::app()->addBehavior('publicHeadContent', function (): void {
if (is_null(dcCore::app()->blog) || dcCore::app()->url->type != 'default') {
return;
}
$blog_url = Html::escapeJS(
dcCore::app()->blog->url .
dcCore::app()->url->getBase('zoneclearFeedsPage') .
'/zcfsupd'
);
$blog_id = Html::escapeJS(dcCore::app()->blog->id);
echo
"\n<!-- JS for zoneclearFeedServer --> \n" .
dcUtils::jsLoad(dcCore::app()->blog->url . dcCore::app()->url->getBase('zoneclearFeedsPage') . '/zcfsupd.js') .
"<script type=\"text/javascript\"> \n//<![CDATA[\n" .
' $(function(){if(!document.getElementById){return;} ' .
" $('body').zoneclearFeedServer({blog_url:'" .
$blog_url . "',blog_id:'" . $blog_id . "'}); " .
" })\n" .
"//]]>\n</script>\n";
});
}
return true;
}
2023-05-07 22:40:58 +00:00
}