activityReport/src/Context.php

87 lines
2.3 KiB
PHP
Raw Normal View History

<?php
/**
* @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
*/
declare(strict_types=1);
namespace Dotclear\Plugin\activityReport;
use dcCore;
2023-05-11 22:37:45 +00:00
use Dotclear\Database\MetaRecord;
/**
* Template helper.
*/
class Context
{
/**
* Parse title.
*
* @return string The parsed title
*/
public static function parseTitle(): string
{
2023-05-11 22:37:45 +00:00
if (!dcCore::app()->ctx
|| !dcCore::app()->ctx->exists('activityreports')
|| !(dcCore::app()->ctx->__get('activityreports') instanceof MetaRecord)
) {
return '';
}
2023-05-11 22:37:45 +00:00
$group = dcCore::app()->ctx->__get('activityreports')->f('activity_group');
$action = dcCore::app()->ctx->__get('activityreports')->f('activity_action');
2023-05-11 22:37:45 +00:00
if (!is_string($group)
|| !is_string($action)
|| !ActivityReport::instance()->groups->get($group)->has($action)
) {
return '';
}
return __(ActivityReport::instance()->groups->get($group)->get($action)->title);
}
/**
* Parse content.
*
* @return string The parsed content
*/
public static function parseContent(): string
{
2023-05-11 22:37:45 +00:00
if (!dcCore::app()->ctx
|| !dcCore::app()->ctx->exists('activityreports')
|| !(dcCore::app()->ctx->__get('activityreports') instanceof MetaRecord)
) {
return '';
}
2023-05-11 22:37:45 +00:00
$group = dcCore::app()->ctx->__get('activityreports')->f('activity_group');
$action = dcCore::app()->ctx->__get('activityreports')->f('activity_action');
$logs = dcCore::app()->ctx->__get('activityreports')->f('activity_logs');
$logs = json_decode(is_string($logs) ? $logs : '', true);
2023-05-11 22:37:45 +00:00
if (!is_string($group)
|| !is_string($action)
|| !is_array($logs)
|| !ActivityReport::instance()->groups->get($group)->has($action)
) {
return '';
}
dcCore::app()->initWikiComment();
return dcCore::app()->wikiTransform(vsprintf(
__(ActivityReport::instance()->groups->get($group)->get($action)->message),
$logs
));
}
}