enhancePostContent/src/Filter/EpcFilterReplace.php

61 lines
1.7 KiB
PHP
Raw Normal View History

2022-12-21 21:27:20 +00:00
<?php
/**
* @brief enhancePostContent, 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
*/
2023-04-09 08:17:36 +00:00
declare(strict_types=1);
namespace Dotclear\Plugin\enhancePostContent\Filter;
2022-12-21 21:27:20 +00:00
2023-04-09 08:17:36 +00:00
use Dotclear\Plugin\enhancePostContent\Epc;
use Dotclear\Plugin\enhancePostContent\EpcFilter;
class EpcFilterReplace extends EpcFilter
2022-12-21 21:27:20 +00:00
{
protected string $id = 'replace';
protected function initProperties(): array
2022-12-21 21:27:20 +00:00
{
return [
2022-12-21 21:27:20 +00:00
'priority' => 200,
'name' => __('Replace'),
'help' => __('Replace some text. First term of the list is the text to replace and second term the replacement.'),
'has_list' => true,
'htmltag' => 'pre,code',
2022-12-21 21:27:20 +00:00
'class' => ['span.epc-replace'],
'replace' => '<span class="epc-replace">%s</span>',
];
}
2022-12-21 21:27:20 +00:00
protected function initSettings(): array
{
return [
2022-12-21 21:27:20 +00:00
'nocase' => true,
'plural' => true,
'style' => ['font-style: italic;'],
'notag' => 'h1,h2,h3',
'tplValues' => ['EntryContent'],
'pubPages' => ['post.html'],
];
2022-12-21 21:27:20 +00:00
}
2023-04-09 08:17:36 +00:00
public function publicContent(string $tag, array $args): void
2022-12-21 21:27:20 +00:00
{
while ($this->records()->fetch()) {
2023-04-09 08:17:36 +00:00
$args[0] = Epc::replaceString(
$this->records()->f('epc_key'),
sprintf($this->replace, $this->records()->f('epc_value'), '\\2'),
2022-12-21 21:27:20 +00:00
$args[0],
$this
);
}
}
}