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;
|
|
|
|
|
2023-04-09 21:52:07 +00:00
|
|
|
use ArrayObject;
|
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-04-09 08:17:36 +00:00
|
|
|
class EpcFilterLink extends EpcFilter
|
2022-12-21 21:27:20 +00:00
|
|
|
{
|
2023-04-09 21:52:07 +00:00
|
|
|
protected string $id = 'link';
|
|
|
|
|
|
|
|
protected function initProperties(): array
|
2022-12-21 21:27:20 +00:00
|
|
|
{
|
2023-04-09 21:52:07 +00:00
|
|
|
return [
|
2022-12-21 21:27:20 +00:00
|
|
|
'priority' => 500,
|
|
|
|
'name' => __('Link'),
|
|
|
|
'help' => __('Link some words. First term of the list is the term to link and second term the link.'),
|
|
|
|
'has_list' => true,
|
2023-04-21 09:07:55 +00:00
|
|
|
'htmltag' => 'pre,code,a',
|
2022-12-21 21:27:20 +00:00
|
|
|
'class' => ['a.epc-link'],
|
|
|
|
'replace' => '<a class="epc-link" title="%s" href="%s">%s</a>',
|
|
|
|
'widget' => '<a title="%s" href="%s">%s</a>',
|
2023-04-09 21:52:07 +00:00
|
|
|
];
|
|
|
|
}
|
2022-12-21 21:27:20 +00:00
|
|
|
|
2023-04-09 21:52:07 +00:00
|
|
|
protected function initSettings(): array
|
|
|
|
{
|
|
|
|
return [
|
2022-12-21 21:27:20 +00:00
|
|
|
'style' => ['text-decoration: none; font-style: italic; color: #0000FF;'],
|
|
|
|
'notag' => 'a,h1,h2,h3',
|
|
|
|
'tplValues' => ['EntryContent'],
|
|
|
|
'pubPages' => ['post.html'],
|
2023-04-09 21:52:07 +00:00
|
|
|
];
|
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(
|
2023-04-09 21:52:07 +00:00
|
|
|
$this->records()->f('epc_key'),
|
|
|
|
sprintf($this->replace, '\\1', $this->records()->f('epc_value'), '\\1'),
|
2022-12-21 21:27:20 +00:00
|
|
|
$args[0],
|
|
|
|
$this
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-09 21:52:07 +00:00
|
|
|
public function widgetList(string $content, WidgetsElement $w, ArrayObject $list): void
|
2022-12-21 21:27:20 +00:00
|
|
|
{
|
|
|
|
while ($this->records()->fetch()) {
|
2023-04-09 08:17:36 +00:00
|
|
|
$list[] = Epc::matchString(
|
2023-04-09 21:52:07 +00:00
|
|
|
$this->records()->f('epc_key'),
|
|
|
|
sprintf($this->widget, $this->records()->f('epc_value'), $this->records()->f('epc_value'), '\\1'),
|
2022-12-21 21:27:20 +00:00
|
|
|
$content,
|
|
|
|
$this
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|