activityReport/_public.php

173 lines
5.8 KiB
PHP
Raw Normal View History

<?php
2021-09-02 22:18:08 +00:00
/**
* @brief activityReport, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Jean-Christian Denis and contributors
*
* @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;
}
if (!defined('ACTIVITY_REPORT')) {
return null;
}
2021-09-02 22:51:23 +00:00
$core->tpl->setPath($core->tpl->getPath(), dirname(__FILE__).'/default-templates/tpl');
$core->tpl->addBlock('activityReports', ['activityReportPublicTpl','activityReports']);
$core->tpl->addValue('activityReportFeedID', ['activityReportPublicTpl','activityReportFeedID']);
$core->tpl->addValue('activityReportTitle', ['activityReportPublicTpl','activityReportTitle']);
$core->tpl->addValue('activityReportDate', ['activityReportPublicTpl','activityReportDate']);
$core->tpl->addValue('activityReportContent', ['activityReportPublicTpl','activityReportContent']);
class activityReportPublicUrl extends dcUrlHandlers
{
2021-09-02 22:18:08 +00:00
public static function feed($args)
{
global $core, $_ctx;
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();
return;
}
2021-09-02 22:51:23 +00:00
if (!defined('ACTIVITY_REPORT')) {
2021-09-02 22:18:08 +00:00
self::p404();
return;
}
2021-09-02 22:51:23 +00:00
if (!$core->activityReport->getSetting('active')) {
2021-09-02 22:18:08 +00:00
self::p404();
return;
}
$mime = $m[1] == 'atom' ? 'application/atom+xml' : 'application/xml';
if (false === $core->activityReport->checkUserCode($m[2])) {
self::p404();
return;
}
$_ctx->nb_entry_per_page = $core->blog->settings->system->nb_post_per_feed;
$_ctx->short_feed_items = $core->blog->settings->system->short_feed_items;
2021-09-02 22:51:23 +00:00
header('X-Robots-Tag: '. context::robotsPolicy($core->blog->settings->system->robots_policy, ''));
self::serveDocument('activityreport-' . $m[1] . '.xml', $mime);
2021-09-02 22:18:08 +00:00
return;
}
}
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'])) {
2021-09-02 22:51:23 +00:00
$lastn = abs((integer) $attr['lastn']) + 0;
2021-09-02 22:18:08 +00:00
}
2021-09-02 22:51:23 +00:00
$p = 'if (!isset($_page_number)) { $_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 {
$p .= "\$params['limit'] = \$_ctx->nb_entry_per_page;\n";
}
if (!isset($attr['ignore_pagination']) || $attr['ignore_pagination'] == "0") {
$p .= "\$params['limit'] = array(((\$_page_number-1)*\$params['limit']),\$params['limit']);\n";
} else {
$p .= "\$params['limit'] = array(0, \$params['limit']);\n";
}
2021-09-02 22:51:23 +00:00
return
"<?php \n" .
$p .
'$_ctx->activityreport_params = $params; ' . "\n" .
'$_ctx->activityreports = $core->activityReport->getLogs($params); unset($params); ' . "\n" .
'while ($_ctx->activityreports->fetch()) : ?>'.$content.'<?php endwhile; ' .
'$_ctx->activityreports = null; $_ctx->activityreport_params = null; ' . "\n" .
2021-09-02 22:18:08 +00:00
"?>";
}
public static function activityReportFeedID($attr)
{
return
2021-09-02 22:51:23 +00:00
'urn:md5:<?php echo md5($_ctx->activityreports->blog_id.' .
'$_ctx->activityreports->activity_id.$_ctx->activityreports->activity_dt); ' .
2021-09-02 22:18:08 +00:00
'?>';
}
public static function activityReportTitle($attr)
{
$f = $GLOBALS['core']->tpl->getFilters($attr);
2021-09-02 22:51:23 +00:00
return '<?php echo ' . sprintf($f,'activityReportContext::parseTitle()') . '; ?>';
2021-09-02 22:18:08 +00:00
}
public static function activityReportContent($attr)
{
$f = $GLOBALS['core']->tpl->getFilters($attr);
2021-09-02 22:51:23 +00:00
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']);
$rfc822 = !empty($attr['rfc822']);
$f = $GLOBALS['core']->tpl->getFilters($attr);
if ($rfc822) {
2021-09-02 22:51:23 +00:00
return '<?php echo ' . sprintf($f,"dt::rfc822(strtotime(\$_ctx->activityreports->activity_dt),\$core->blog->settings->system->blog_timezone)") . '; ?>';
2021-09-02 22:18:08 +00:00
} elseif ($iso8601) {
2021-09-02 22:51:23 +00:00
return '<?php echo ' . sprintf($f,"dt::iso8601(strtotime(\$_ctx->activityreports->activity_dt),\$core->blog->settings->system->blog_timezone)") . '; ?>';
2021-09-02 22:18:08 +00:00
} elseif (!empty($format)) {
2021-09-02 22:51:23 +00:00
return '<?php echo ' . sprintf($f,"dt::dt2str('" . $format . "',\$_ctx->activityreports->activity_dt)") . '; ?>';
2021-09-02 22:18:08 +00:00
} else {
2021-09-02 22:51:23 +00:00
return '<?php echo ' . sprintf($f,"dt::dt2str(\$core->blog->settings->system->date_format,\$_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()
{
global $core,$_ctx;
$groups = $core->activityReport->getGroups();
$group = $_ctx->activityreports->activity_group;
$action = $_ctx->activityreports->activity_action;
if (!empty($groups[$group]['actions'][$action]['title'])) {
return __($groups[$group]['actions'][$action]['title']);
}
return '';
}
public static function parseContent()
{
global $core,$_ctx;
$groups = $core->activityReport->getGroups();
$group = $_ctx->activityreports->activity_group;
$action = $_ctx->activityreports->activity_action;
$logs = $_ctx->activityreports->activity_logs;
$logs = $core->activityReport->decode($logs);
if (!empty($groups[$group]['actions'][$action]['msg'])) {
$core->initWikiComment();
return $core->wikiTransform(vsprintf(__($groups[$group]['actions'][$action]['msg']),$logs));
}
return '';
}
}