enhancePostContent/inc/class.epcfiltersearch.php

62 lines
1.5 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
*/
if (!defined('DC_RC_PATH')) {
return null;
}
class epcFilterSearch extends epcFilter
{
protected function init(): string
{
$this->setProperties([
'priority' => 100,
'name' => __('Search'),
'help' => __('Highlight searched words.'),
'htmltag' => '',
'class' => ['span.epc-search'],
'replace' => '<span class="epc-search" title="' . __('Search') . '">%s</span>',
]);
$this->setSettings([
'nocase' => true,
'plural' => true,
'style' => ['color: #FFCC66;'],
'notag' => 'h1,h2,h3',
'tplValues' => ['EntryContent'],
'pubPages' => ['search.html'],
]);
return 'search';
}
public function publicContent($tag, $args)
{
if (empty(dcCore::app()->public->search)) {
return null;
}
$searchs = explode(' ', dcCore::app()->public->search);
foreach ($searchs as $k => $v) {
$args[0] = enhancePostContent::replaceString(
$v,
sprintf($this->replace, '\\1'),
$args[0],
$this
);
}
return null;
}
}