activityReport/_public.php

175 lines
6.2 KiB
PHP
Raw Normal View History

<?php
2021-09-02 22:18:08 +00:00
/**
* @brief activityReport, a plugin for Dotclear 2
2022-11-18 20:24:30 +00:00
*
2021-09-02 22:18:08 +00:00
* @package Dotclear
* @subpackage Plugin
2022-11-18 20:24:30 +00:00
*
2021-09-02 22:18:08 +00:00
* @author Jean-Christian Denis and contributors
2022-11-18 20:24:30 +00:00
*
2021-09-02 22:18:08 +00:00
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
2021-09-02 22:51:23 +00:00
if (!defined('DC_RC_PATH')) {
return null;
}
2022-11-18 20:24:30 +00:00
if (!defined('ACTIVITY_REPORT_V2')) {
2021-09-02 22:51:23 +00:00
return null;
}
2022-11-18 20:24:30 +00:00
dcCore::app()->tpl->setPath(dcCore::app()->tpl->getPath(), __DIR__ . '/default-templates/tpl');
dcCore::app()->tpl->addBlock('activityReports', ['activityReportPublicTpl','activityReports']);
dcCore::app()->tpl->addValue('activityReportFeedID', ['activityReportPublicTpl','activityReportFeedID']);
dcCore::app()->tpl->addValue('activityReportTitle', ['activityReportPublicTpl','activityReportTitle']);
dcCore::app()->tpl->addValue('activityReportDate', ['activityReportPublicTpl','activityReportDate']);
dcCore::app()->tpl->addValue('activityReportContent', ['activityReportPublicTpl','activityReportContent']);
class activityReportPublicUrl extends dcUrlHandlers
{
2022-11-18 20:24:30 +00:00
public static function feed(?string $args): void
2021-09-02 22:18:08 +00:00
{
2021-09-02 22:51:23 +00:00
if (!preg_match('/^(atom|rss2)\/(.+)$/', $args, $m)) {
2021-09-02 22:18:08 +00:00
self::p404();
2022-11-18 20:24:30 +00:00
2021-09-02 22:18:08 +00:00
return;
}
2022-11-18 20:24:30 +00:00
if (!defined('ACTIVITY_REPORT_V2')) {
2021-09-02 22:18:08 +00:00
self::p404();
2022-11-18 20:24:30 +00:00
2021-09-02 22:18:08 +00:00
return;
}
2022-11-18 20:24:30 +00:00
if (!dcCore::app()->activityReport->getSetting('active')) {
2021-09-02 22:18:08 +00:00
self::p404();
2022-11-18 20:24:30 +00:00
2021-09-02 22:18:08 +00:00
return;
}
$mime = $m[1] == 'atom' ? 'application/atom+xml' : 'application/xml';
2022-11-18 20:24:30 +00:00
if (false === dcCore::app()->activityReport->checkUserCode($m[2])) {
2021-09-02 22:18:08 +00:00
self::p404();
2022-11-18 20:24:30 +00:00
2021-09-02 22:18:08 +00:00
return;
}
2022-11-18 20:24:30 +00:00
dcCore::app()->ctx->nb_entry_per_page = (int) dcCore::app()->blog->settings->system->nb_post_per_feed;
dcCore::app()->ctx->short_feed_items = (int) dcCore::app()->blog->settings->system->short_feed_items;
2021-09-02 22:18:08 +00:00
2022-11-18 20:24:30 +00:00
header('X-Robots-Tag: ' . context::robotsPolicy(dcCore::app()->blog->settings->system->robots_policy, ''));
2021-09-02 22:51:23 +00:00
self::serveDocument('activityreport-' . $m[1] . '.xml', $mime);
2021-09-02 22:18:08 +00:00
}
}
class activityReportPublicTpl
{
2021-09-02 22:51:23 +00:00
public static function activityReports($attr, $content)
2021-09-02 22:18:08 +00:00
{
$lastn = 0;
if (isset($attr['lastn'])) {
2022-11-18 20:24:30 +00:00
$lastn = abs((int) $attr['lastn']) + 0;
2021-09-02 22:18:08 +00:00
}
2022-11-18 20:24:30 +00:00
$p = '$_page_number = dcCore::app()->public->getPageNumber(); if ($_page_number < 1) { $_page_number = 1; }' . "\n\$params = array();\n";
2021-09-02 22:18:08 +00:00
if ($lastn > 0) {
2021-09-02 22:51:23 +00:00
$p .= "\$params['limit'] = " . $lastn . ";\n";
2021-09-02 22:18:08 +00:00
} else {
2022-11-18 20:24:30 +00:00
$p .= "\$params['limit'] = dcCore::app()->ctx->nb_entry_per_page;\n";
2021-09-02 22:18:08 +00:00
}
2022-11-18 20:24:30 +00:00
if (!isset($attr['ignore_pagination']) || $attr['ignore_pagination'] == '0') {
2021-09-02 22:18:08 +00:00
$p .= "\$params['limit'] = array(((\$_page_number-1)*\$params['limit']),\$params['limit']);\n";
} else {
$p .= "\$params['limit'] = array(0, \$params['limit']);\n";
}
2022-11-18 20:24:30 +00:00
return
2021-09-02 22:51:23 +00:00
"<?php \n" .
$p .
2022-11-18 20:24:30 +00:00
'dcCore::app()->ctx->activityreport_params = $params; ' . "\n" .
'dcCore::app()->ctx->activityreports = dcCore::app()->activityReport->getLogs($params); unset($params); ' . "\n" .
'while (dcCore::app()->ctx->activityreports->fetch()) : ?>' . $content . '<?php endwhile; ' .
'dcCore::app()->ctx->pop("activityreports"); dcCore::app()->ctx->pop("activityreport_params"); ' . "\n" .
'?>';
2021-09-02 22:18:08 +00:00
}
public static function activityReportFeedID($attr)
{
2022-11-18 20:24:30 +00:00
return
'urn:md5:<?php echo md5(dcCore::app()->ctx->activityreports->blog_id.' .
'dcCore::app()->ctx->activityreports->activity_id.dcCore::app()->ctx->activityreports->activity_dt); ' .
2021-09-02 22:18:08 +00:00
'?>';
}
public static function activityReportTitle($attr)
{
2022-11-18 20:24:30 +00:00
$f = dcCore::app()->tpl->getFilters($attr);
return '<?php echo ' . sprintf($f, 'activityReportContext::parseTitle()') . '; ?>';
2021-09-02 22:18:08 +00:00
}
public static function activityReportContent($attr)
{
2022-11-18 20:24:30 +00:00
$f = dcCore::app()->tpl->getFilters($attr);
return '<?php echo ' . sprintf($f, 'activityReportContext::parseContent()') . '; ?>';
2021-09-02 22:18:08 +00:00
}
public static function activityReportDate($attr)
{
$format = '';
if (!empty($attr['format'])) {
$format = addslashes($attr['format']);
}
$iso8601 = !empty($attr['iso8601']);
2022-11-18 20:24:30 +00:00
$rfc822 = !empty($attr['rfc822']);
2021-09-02 22:18:08 +00:00
2022-11-18 20:24:30 +00:00
$f = dcCore::app()->tpl->getFilters($attr);
2021-09-02 22:18:08 +00:00
if ($rfc822) {
2022-11-18 20:24:30 +00:00
return '<?php echo ' . sprintf($f, 'dt::rfc822(strtotime(dcCore::app()->ctx->activityreports->activity_dt),dcCore::app()->blog->settings->system->blog_timezone)') . '; ?>';
2021-09-02 22:18:08 +00:00
} elseif ($iso8601) {
2022-11-18 20:24:30 +00:00
return '<?php echo ' . sprintf($f, 'dt::iso8601(strtotime(dcCore::app()->ctx->activityreports->activity_dt),dcCore::app()->blog->settings->system->blog_timezone)') . '; ?>';
2021-09-02 22:18:08 +00:00
} elseif (!empty($format)) {
2022-11-18 20:24:30 +00:00
return '<?php echo ' . sprintf($f, "dt::dt2str('" . $format . "',dcCore::app()->ctx->activityreports->activity_dt)") . '; ?>';
2021-09-02 22:18:08 +00:00
}
2022-11-18 20:24:30 +00:00
return '<?php echo ' . sprintf($f, 'dt::dt2str(dcCore::app()->blog->settings->system->date_format,dcCore::app()->ctx->activityreports->activity_dt)') . '; ?>';
2021-09-02 22:18:08 +00:00
}
}
class activityReportContext
{
2021-09-02 22:18:08 +00:00
public static function parseTitle()
{
2022-11-18 20:24:30 +00:00
$groups = dcCore::app()->activityReport->getGroups();
2021-09-02 22:18:08 +00:00
2022-11-18 20:24:30 +00:00
$group = dcCore::app()->ctx->activityreports->activity_group;
$action = dcCore::app()->ctx->activityreports->activity_action;
2021-09-02 22:18:08 +00:00
if (!empty($groups[$group]['actions'][$action]['title'])) {
return __($groups[$group]['actions'][$action]['title']);
}
2022-11-18 20:24:30 +00:00
2021-09-02 22:18:08 +00:00
return '';
}
public static function parseContent()
{
2022-11-18 20:24:30 +00:00
$groups = dcCore::app()->activityReport->getGroups();
2021-09-02 22:18:08 +00:00
2022-11-18 20:24:30 +00:00
$group = dcCore::app()->ctx->activityreports->activity_group;
$action = dcCore::app()->ctx->activityreports->activity_action;
$logs = dcCore::app()->ctx->activityreports->activity_logs;
$logs = dcCore::app()->activityReport->decode($logs);
2021-09-02 22:18:08 +00:00
if (!empty($groups[$group]['actions'][$action]['msg'])) {
2022-11-18 20:24:30 +00:00
dcCore::app()->initWikiComment();
return dcCore::app()->wikiTransform(vsprintf(__($groups[$group]['actions'][$action]['msg']), $logs));
2021-09-02 22:18:08 +00:00
}
2022-11-18 20:24:30 +00:00
2021-09-02 22:18:08 +00:00
return '';
}
2022-11-18 20:24:30 +00:00
}