enhancePostContent/src/Filter/EpcFilterTag.php

84 lines
2.4 KiB
PHP
Raw Permalink Normal View History

2022-12-21 21:27:20 +00:00
<?php
2023-10-11 19:02:43 +00:00
2023-04-09 08:17:36 +00:00
declare(strict_types=1);
namespace Dotclear\Plugin\enhancePostContent\Filter;
use ArrayObject;
2023-10-07 22:35:35 +00:00
use Dotclear\App;
2023-04-09 08:17:36 +00:00
use Dotclear\Plugin\enhancePostContent\Epc;
use Dotclear\Plugin\enhancePostContent\EpcFilter;
use Dotclear\Plugin\widgets\WidgetsElement;
2022-12-21 21:27:20 +00:00
2023-10-11 19:02:43 +00:00
/**
* @brief enhancePostContent tag filter.
* @ingroup enhancePostContent
*
* @author Jean-Christian Denis
* @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
class EpcFilterTag extends EpcFilter
2022-12-21 21:27:20 +00:00
{
protected string $id = 'tag';
protected function initProperties(): array
2022-12-21 21:27:20 +00:00
{
return [
2023-04-21 22:21:30 +00:00
'priority' => 900,
'name' => __('Tag'),
'description' => __('Highlight tags of your blog.'),
'ignore' => ['pre','code','a'],
'class' => ['a.epc-tag'],
'replace' => '<a class="epc-tag" href="%s" title="' . __('Tag') . '">%s</a>',
'widget' => '<a href="%s" title="' . __('Tag') . '">%s</a>',
];
}
2022-12-21 21:27:20 +00:00
protected function initSettings(): array
{
return [
2023-04-21 22:21:30 +00:00
'style' => ['text-decoration: none; border-bottom: 3px double #CCCCCC;'],
'notag' => ['h1','h2','h3'],
'template' => ['EntryContent'],
'page' => ['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
{
2023-10-07 22:35:35 +00:00
if (!App::plugins()->moduleExists('tags')) {
2023-04-09 08:17:36 +00:00
return;
2022-12-21 21:27:20 +00:00
}
2023-10-07 22:35:35 +00:00
$metas = App::meta()->getMetadata(['meta_type' => 'tag']);
2022-12-21 21:27:20 +00:00
while ($metas->fetch()) {
2023-04-09 08:17:36 +00:00
$args[0] = Epc::replaceString(
$metas->f('meta_id'),
2023-10-07 22:35:35 +00:00
sprintf($this->replace, App::blog()->url() . App::url()->getBase('tag') . '/' . $metas->f('meta_id'), '\\1'),
2022-12-21 21:27:20 +00:00
$args[0],
$this
);
}
}
public function widgetList(string $content, WidgetsElement $w, ArrayObject $list): void
2022-12-21 21:27:20 +00:00
{
2023-10-07 22:35:35 +00:00
if (!App::plugins()->moduleExists('tags')) {
2023-04-09 08:17:36 +00:00
return;
2022-12-21 21:27:20 +00:00
}
2023-10-07 22:35:35 +00:00
$metas = App::meta()->getMetadata(['meta_type' => 'tag']);
2022-12-21 21:27:20 +00:00
while ($metas->fetch()) {
2023-04-09 08:17:36 +00:00
$list[] = Epc::matchString(
$metas->f('meta_id'),
2023-10-07 22:35:35 +00:00
sprintf($this->widget, App::blog()->url() . App::url()->getBase('tag') . '/' . $metas->f('meta_id'), '\\1'),
2022-12-21 21:27:20 +00:00
$content,
$this
);
}
}
}