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 dcCore;
|
|
|
|
use Dotclear\Plugin\enhancePostContent\Epc;
|
|
|
|
use Dotclear\Plugin\enhancePostContent\EpcFilter;
|
|
|
|
|
|
|
|
class EpcFilterSearch extends EpcFilter
|
2022-12-21 21:27:20 +00:00
|
|
|
{
|
2023-04-09 21:52:07 +00:00
|
|
|
protected string $id = 'search';
|
|
|
|
|
|
|
|
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' => 100,
|
|
|
|
'name' => __('Search'),
|
|
|
|
'help' => __('Highlight searched words.'),
|
|
|
|
'htmltag' => '',
|
|
|
|
'class' => ['span.epc-search'],
|
|
|
|
'replace' => '<span class="epc-search" title="' . __('Search') . '">%s</span>',
|
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
|
|
|
'nocase' => true,
|
|
|
|
'plural' => true,
|
|
|
|
'style' => ['color: #FFCC66;'],
|
|
|
|
'notag' => 'h1,h2,h3',
|
|
|
|
'tplValues' => ['EntryContent'],
|
|
|
|
'pubPages' => ['search.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
|
|
|
{
|
|
|
|
if (empty(dcCore::app()->public->search)) {
|
2023-04-09 08:17:36 +00:00
|
|
|
return;
|
2022-12-21 21:27:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$searchs = explode(' ', dcCore::app()->public->search);
|
|
|
|
|
|
|
|
foreach ($searchs as $k => $v) {
|
2023-04-09 08:17:36 +00:00
|
|
|
$args[0] = Epc::replaceString(
|
2022-12-21 21:27:20 +00:00
|
|
|
$v,
|
|
|
|
sprintf($this->replace, '\\1'),
|
|
|
|
$args[0],
|
|
|
|
$this
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|