2020-08-14 15:24:14 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This file is part of Zwii.
|
|
|
|
*
|
|
|
|
* For full copyright and license information, please see the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*
|
|
|
|
* @author Rémi Jean <remi.jean@outlook.com>
|
|
|
|
* @copyright Copyright (C) 2008-2018, Rémi Jean
|
2020-08-16 10:55:52 +02:00
|
|
|
* @author Frédéric Tempez <frederic.tempez@outlook.com>
|
2023-01-09 10:23:32 +01:00
|
|
|
* @copyright Copyright (C) 2018-2023, Frédéric Tempez
|
2021-04-05 08:59:24 +02:00
|
|
|
* @author Sylvain Lelièvre <lelievresylvain@free.fr>
|
|
|
|
* @copyright Copyright (C) 2020-2021, Sylvain Lelièvre
|
2022-12-29 17:02:20 +01:00
|
|
|
* @license CC Attribution-NonCommercial-NoDerivatives 4.0 International
|
2020-09-01 20:48:40 +02:00
|
|
|
* @link http://zwiicms.fr/
|
2020-08-14 15:24:14 +02:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2022-10-16 17:44:04 +02:00
|
|
|
class search extends common
|
|
|
|
{
|
2020-08-14 15:24:14 +02:00
|
|
|
|
2023-07-21 21:48:41 +02:00
|
|
|
const VERSION = '3.0';
|
2021-02-18 10:07:05 +01:00
|
|
|
const REALNAME = 'Recherche';
|
2021-05-03 16:32:36 +02:00
|
|
|
const DATADIRECTORY = self::DATA_DIR . 'search/';
|
2021-02-18 10:07:05 +01:00
|
|
|
|
2020-08-14 15:24:14 +02:00
|
|
|
public static $actions = [
|
2020-08-16 10:43:09 +02:00
|
|
|
'index' => self::GROUP_VISITOR,
|
2023-07-05 18:04:42 +02:00
|
|
|
'config' => self::GROUP_EDITOR
|
2020-08-14 15:24:14 +02:00
|
|
|
];
|
|
|
|
|
2020-08-20 16:11:11 +02:00
|
|
|
// Variables pour l'affichage des résultats
|
2020-08-14 16:00:42 +02:00
|
|
|
public static $resultList = '';
|
2020-08-19 15:18:57 +02:00
|
|
|
public static $resultError = '';
|
2020-08-14 16:00:42 +02:00
|
|
|
public static $resultTitle = '';
|
2020-08-14 15:24:14 +02:00
|
|
|
|
2020-08-20 16:11:11 +02:00
|
|
|
// Variables pour le dialogue avec le formulaire
|
2020-08-15 09:35:43 +02:00
|
|
|
public static $motclef = '';
|
2020-08-25 21:01:10 +02:00
|
|
|
public static $motentier = true;
|
2020-08-20 16:11:11 +02:00
|
|
|
public static $previewLength = [
|
|
|
|
100 => '100 caractères',
|
|
|
|
200 => '200 caractères',
|
|
|
|
300 => '300 caractères',
|
|
|
|
400 => '400 caractères',
|
|
|
|
];
|
2020-08-15 09:35:43 +02:00
|
|
|
|
2020-08-14 16:09:46 +02:00
|
|
|
|
2021-04-05 08:59:24 +02:00
|
|
|
/**
|
|
|
|
* Mise à jour du module
|
|
|
|
* Appelée par les fonctions index et config
|
|
|
|
*/
|
2022-10-16 17:44:04 +02:00
|
|
|
private function update()
|
|
|
|
{
|
2021-06-05 17:43:09 +02:00
|
|
|
|
|
|
|
|
2021-08-20 11:39:04 +02:00
|
|
|
// le module n'est pas initialisé
|
2022-10-16 17:44:04 +02:00
|
|
|
if (
|
|
|
|
$this->getData(['module', $this->getUrl(0), 'config']) === NULL
|
|
|
|
|| $this->getData(['module', $this->getUrl(0), 'theme']) === NULL
|
2023-06-29 17:01:27 +02:00
|
|
|
|| !file_exists(self::DATADIRECTORY . $this->getUrl(0) . '/theme.css')
|
2022-10-16 17:44:04 +02:00
|
|
|
) {
|
2021-08-20 11:39:04 +02:00
|
|
|
$this->init();
|
|
|
|
}
|
|
|
|
|
2022-10-16 17:44:04 +02:00
|
|
|
$versionData = $this->getData(['module', $this->getUrl(0), 'config', 'versionData']);
|
|
|
|
|
2021-06-05 17:38:11 +02:00
|
|
|
// Mise à jour 2.2
|
2022-10-16 17:44:04 +02:00
|
|
|
if (version_compare($versionData, '2.2', '<')) {
|
2021-06-07 10:57:03 +02:00
|
|
|
if (is_dir(self::DATADIRECTORY . 'pages/')) {
|
|
|
|
// Déplacer les données du dossier Pages
|
|
|
|
$this->copyDir(self::DATADIRECTORY . 'pages/' . $this->getUrl(0), self::DATADIRECTORY . $this->getUrl(0));
|
2023-07-19 18:07:12 +02:00
|
|
|
$this->deleteDir(self::DATADIRECTORY . 'pages/');
|
2021-06-07 10:57:03 +02:00
|
|
|
}
|
2021-06-05 17:38:11 +02:00
|
|
|
// Mettre à jour la version
|
2022-10-16 17:44:04 +02:00
|
|
|
$this->setData(['module', $this->getUrl(0), 'config', 'versionData', '2.2']);
|
2021-06-05 17:38:11 +02:00
|
|
|
}
|
2021-04-05 08:59:24 +02:00
|
|
|
}
|
|
|
|
|
2021-04-05 15:32:04 +02:00
|
|
|
/**
|
2021-04-08 19:29:40 +02:00
|
|
|
* Initialisation du module
|
2021-04-05 15:32:04 +02:00
|
|
|
*/
|
2022-10-16 17:44:04 +02:00
|
|
|
private function init()
|
|
|
|
{
|
2021-04-05 15:32:04 +02:00
|
|
|
|
2021-04-09 08:48:48 +02:00
|
|
|
|
2022-10-16 17:44:04 +02:00
|
|
|
$fileCSS = self::DATADIRECTORY . $this->getUrl(0) . '/theme.css';
|
2021-04-08 19:29:40 +02:00
|
|
|
|
2021-04-12 17:54:31 +02:00
|
|
|
if ($this->getData(['module', $this->getUrl(0)]) === null) {
|
2021-06-05 17:43:09 +02:00
|
|
|
// Données du module
|
2021-04-12 17:54:31 +02:00
|
|
|
require_once('module/search/ressource/defaultdata.php');
|
2022-10-16 17:44:04 +02:00
|
|
|
$this->setData(['module', $this->getUrl(0), 'config', init::$defaultConfig]);
|
2021-04-12 17:54:31 +02:00
|
|
|
// Données de thème
|
2022-10-16 17:44:04 +02:00
|
|
|
$this->setData(['module', $this->getUrl(0), 'theme', init::$defaultTheme]);
|
|
|
|
$this->setData(['module', $this->getUrl(0), 'theme', 'style', self::DATADIRECTORY . $this->getUrl(0) . '/theme.css']);
|
2021-05-14 17:52:07 +02:00
|
|
|
// Recharger la page pour éviter une config vide
|
|
|
|
header("Refresh:0");
|
2021-04-08 11:45:06 +02:00
|
|
|
}
|
2021-04-05 15:32:04 +02:00
|
|
|
|
2021-04-12 17:54:31 +02:00
|
|
|
// Dossier de l'instance
|
2021-06-05 17:21:07 +02:00
|
|
|
if (!is_dir(self::DATADIRECTORY . $this->getUrl(0))) {
|
2022-10-16 17:44:04 +02:00
|
|
|
mkdir(self::DATADIRECTORY . $this->getUrl(0), 0755, true);
|
2021-04-12 17:54:31 +02:00
|
|
|
}
|
2021-04-08 11:45:06 +02:00
|
|
|
|
2021-04-12 17:54:31 +02:00
|
|
|
// Check la présence de la feuille de style
|
2022-10-16 17:44:04 +02:00
|
|
|
if (!file_exists(self::DATADIRECTORY . $this->getUrl(0) . '/theme.css')) {
|
2021-04-12 17:54:31 +02:00
|
|
|
// Générer la feuille de CSS
|
2022-10-16 17:44:04 +02:00
|
|
|
$style = '.keywordColor {background: ' . $this->getData(['module', $this->getUrl(0), 'theme', 'keywordColor']) . ';}';
|
2021-04-12 17:54:31 +02:00
|
|
|
// Sauver la feuille de style
|
2022-10-16 17:44:04 +02:00
|
|
|
file_put_contents(self::DATADIRECTORY . $this->getUrl(0) . '/theme.css', $style);
|
2021-04-12 17:54:31 +02:00
|
|
|
// Stocker le nom de la feuille de style
|
2022-10-16 17:44:04 +02:00
|
|
|
$this->setData(['module', $this->getUrl(0), 'theme', 'style', $fileCSS]);
|
2021-04-12 17:54:31 +02:00
|
|
|
}
|
2021-04-05 15:32:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-04-05 08:59:24 +02:00
|
|
|
// Configuration vide
|
2022-10-16 17:44:04 +02:00
|
|
|
public function config()
|
|
|
|
{
|
2021-04-05 08:59:24 +02:00
|
|
|
|
2021-04-09 08:48:48 +02:00
|
|
|
// Mise à jour des données de module
|
|
|
|
$this->update();
|
|
|
|
|
2023-06-29 17:01:27 +02:00
|
|
|
if (
|
2023-06-30 09:09:39 +02:00
|
|
|
$this->getUser('permission', __CLASS__, __FUNCTION__) === true &&
|
2023-06-29 17:01:27 +02:00
|
|
|
$this->isPost()
|
|
|
|
) {
|
2021-04-05 08:59:24 +02:00
|
|
|
|
|
|
|
// Générer la feuille de CSS
|
2021-04-08 19:29:40 +02:00
|
|
|
$style = '.keywordColor {background:' . $this->getInput('searchKeywordColor') . ';}';
|
2021-04-05 08:59:24 +02:00
|
|
|
|
2022-10-19 10:31:31 +02:00
|
|
|
$success = is_int(file_put_contents(self::DATADIRECTORY . $this->getUrl(0) . '/theme.css', $style));
|
2021-04-05 08:59:24 +02:00
|
|
|
// Fin feuille de style
|
|
|
|
|
2020-08-16 15:59:37 +02:00
|
|
|
// Soumission du formulaire
|
2023-06-29 17:01:27 +02:00
|
|
|
$this->setData([
|
|
|
|
'module', $this->getUrl(0),
|
|
|
|
'config',
|
|
|
|
[
|
|
|
|
'submitText' => $this->getInput('searchSubmitText'),
|
|
|
|
'placeHolder' => $this->getInput('searchPlaceHolder'),
|
|
|
|
'resultHideContent' => $this->getInput('searchResultHideContent', helper::FILTER_BOOLEAN),
|
|
|
|
'previewLength' => $this->getInput('searchPreviewLength', helper::FILTER_INT),
|
|
|
|
'versionData' => $this->getData(['module', $this->getUrl(0), 'config', 'versionData'])
|
|
|
|
]
|
|
|
|
]);
|
|
|
|
$this->setData([
|
|
|
|
'module', $this->getUrl(0),
|
|
|
|
'theme',
|
|
|
|
[
|
|
|
|
'keywordColor' => $this->getInput('searchKeywordColor'),
|
|
|
|
'style' => $success ? self::DATADIRECTORY . $this->getUrl(0) . '/theme.css' : '',
|
|
|
|
]
|
|
|
|
]);
|
2021-01-13 18:45:39 +01:00
|
|
|
|
2020-08-19 18:46:00 +02:00
|
|
|
|
2020-08-16 15:59:37 +02:00
|
|
|
// Valeurs en sortie, affichage du formulaire
|
|
|
|
$this->addOutput([
|
|
|
|
'redirect' => helper::baseUrl() . $this->getUrl(),
|
2023-06-29 17:01:27 +02:00
|
|
|
'notification' => $success ? 'Modifications enregistrées' : 'Modifications non enregistrées !',
|
2022-10-19 10:31:31 +02:00
|
|
|
'state' => $success
|
2020-08-16 15:59:37 +02:00
|
|
|
]);
|
|
|
|
}
|
2020-08-16 10:43:09 +02:00
|
|
|
// Valeurs en sortie, affichage du formulaire
|
|
|
|
$this->addOutput([
|
2022-10-14 09:36:30 +02:00
|
|
|
'title' => helper::translate('Configuration du module'),
|
2020-08-19 18:46:00 +02:00
|
|
|
'view' => 'config',
|
|
|
|
'vendor' => [
|
|
|
|
'tinycolorpicker'
|
|
|
|
]
|
2020-08-16 10:43:09 +02:00
|
|
|
]);
|
|
|
|
}
|
2020-08-14 16:09:46 +02:00
|
|
|
|
2022-10-16 17:44:04 +02:00
|
|
|
public function index()
|
|
|
|
{
|
2021-04-05 15:32:04 +02:00
|
|
|
|
2021-04-09 08:48:48 +02:00
|
|
|
// Mise à jour des données de module
|
|
|
|
$this->update();
|
|
|
|
|
2023-06-29 17:01:27 +02:00
|
|
|
if (
|
|
|
|
$this->isPost()
|
|
|
|
) {
|
2020-08-14 15:24:14 +02:00
|
|
|
//Initialisations variables
|
|
|
|
$success = true;
|
2020-08-17 16:51:18 +02:00
|
|
|
$result = [];
|
2020-08-14 15:24:14 +02:00
|
|
|
$notification = '';
|
2022-10-16 17:44:04 +02:00
|
|
|
$total = '';
|
2020-08-14 15:24:14 +02:00
|
|
|
|
|
|
|
// Récupération du mot clef passé par le formulaire de ...view/index.php, avec caractères accentués
|
2022-10-16 17:44:04 +02:00
|
|
|
self::$motclef = $this->getInput('searchMotphraseclef');
|
2021-04-05 08:59:24 +02:00
|
|
|
// Variable de travail, on conserve la variable globale pour l'affichage du résultat
|
|
|
|
$motclef = self::$motclef;
|
|
|
|
|
|
|
|
// Suppression des mots < 3 caractères et des articles > 2 caractères de la chaîne $motclef
|
|
|
|
$arraymotclef = explode(' ', $motclef);
|
|
|
|
$motclef = '';
|
2022-10-16 17:44:04 +02:00
|
|
|
foreach ($arraymotclef as $key => $value) {
|
2023-06-29 17:01:27 +02:00
|
|
|
if (strlen($value) > 2 && $value !== 'les' && $value !== 'des' && $value !== 'une' && $value !== 'aux')
|
|
|
|
$motclef .= $value . ' ';
|
2021-04-05 08:59:24 +02:00
|
|
|
}
|
|
|
|
// Suppression du dernier ' '
|
2023-06-29 17:01:27 +02:00
|
|
|
if ($motclef !== '')
|
|
|
|
$motclef = substr($motclef, 0, strlen($motclef) - 1);
|
2020-08-14 15:24:14 +02:00
|
|
|
|
|
|
|
// Récupération de l'état de l'option mot entier passé par le même formulaire
|
2022-10-16 17:44:04 +02:00
|
|
|
self::$motentier = $this->getInput('searchMotentier', helper::FILTER_BOOLEAN);
|
|
|
|
|
|
|
|
if ($motclef !== '') {
|
|
|
|
foreach ($this->getHierarchy(null, false, null) as $parentId => $childIds) {
|
|
|
|
if (
|
2023-06-29 17:01:27 +02:00
|
|
|
$this->getData(['page', $parentId, 'disable']) === false &&
|
2022-10-16 17:44:04 +02:00
|
|
|
$this->getUser('group') >= $this->getData(['page', $parentId, 'group']) &&
|
|
|
|
$this->getData(['page', $parentId, 'block']) !== 'bar'
|
|
|
|
) {
|
2020-08-14 15:24:14 +02:00
|
|
|
$url = $parentId;
|
|
|
|
$titre = $this->getData(['page', $parentId, 'title']);
|
2022-09-02 18:45:55 +02:00
|
|
|
//$content = file_get_contents(self::DATA_DIR . self::$i18nContent . '/content/' . $this->getData(['page', $parentId, 'content']));
|
|
|
|
$content = $this->getPage($parentId, self::$i18nContent);
|
2023-06-29 17:01:27 +02:00
|
|
|
$content = $titre . ' ' . $content;
|
2020-08-14 15:24:14 +02:00
|
|
|
// Pages sauf pages filles et articles de blog
|
2023-06-29 17:01:27 +02:00
|
|
|
$tempData = $this->occurrence($url, $titre, $content, $motclef, self::$motentier);
|
2022-10-16 17:44:04 +02:00
|
|
|
if (is_array($tempData)) {
|
|
|
|
$result[] = $tempData;
|
2020-08-17 16:51:18 +02:00
|
|
|
}
|
2020-08-14 15:24:14 +02:00
|
|
|
}
|
|
|
|
|
2022-10-16 17:44:04 +02:00
|
|
|
foreach ($childIds as $childId) {
|
|
|
|
// Sous page
|
|
|
|
if (
|
|
|
|
$this->getData(['page', $childId, 'disable']) === false &&
|
|
|
|
$this->getUser('group') >= $this->getData(['page', $parentId, 'group']) &&
|
|
|
|
$this->getData(['page', $parentId, 'block']) !== 'bar'
|
|
|
|
) {
|
|
|
|
$url = $childId;
|
|
|
|
$titre = $this->getData(['page', $childId, 'title']);
|
|
|
|
//$content = file_get_contents(self::DATA_DIR . self::$i18nContent . '/content/' . $this->getData(['page', $childId, 'content']));
|
|
|
|
$content = $this->getPage($childId, self::$i18nContent);
|
2023-06-29 17:01:27 +02:00
|
|
|
$content = $titre . ' ' . $content;
|
2022-10-16 17:44:04 +02:00
|
|
|
//Pages filles
|
2023-06-29 17:01:27 +02:00
|
|
|
$tempData = $this->occurrence($url, $titre, $content, $motclef, self::$motentier);
|
2022-10-16 17:44:04 +02:00
|
|
|
if (is_array($tempData)) {
|
|
|
|
$result[] = $tempData;
|
2020-08-14 15:24:14 +02:00
|
|
|
}
|
2022-10-16 17:44:04 +02:00
|
|
|
}
|
2020-08-14 15:24:14 +02:00
|
|
|
|
2022-10-16 17:44:04 +02:00
|
|
|
// Articles d'une sous-page blog ou de news
|
|
|
|
if ($this->getData(['module', $childId, 'posts'])) {
|
|
|
|
foreach ($this->getData(['module', $childId, 'posts']) as $articleId => $article) {
|
|
|
|
if ($this->getData(['module', $childId, 'posts', $articleId, 'state']) === true) {
|
|
|
|
$url = $childId . '/' . $articleId;
|
|
|
|
$titre = $article['title'];
|
|
|
|
$contenu = ' ' . $titre . ' ' . $article['content'];
|
|
|
|
// Articles de sous-page de type blog
|
2023-06-29 17:01:27 +02:00
|
|
|
$tempData = $this->occurrence($url, $titre, $contenu, $motclef, self::$motentier);
|
2022-10-16 17:44:04 +02:00
|
|
|
if (is_array($tempData)) {
|
|
|
|
$result[] = $tempData;
|
2020-08-14 15:24:14 +02:00
|
|
|
}
|
2022-10-16 17:44:04 +02:00
|
|
|
}
|
2020-08-14 15:24:14 +02:00
|
|
|
}
|
2022-10-16 17:44:04 +02:00
|
|
|
}
|
|
|
|
}
|
2020-08-14 15:24:14 +02:00
|
|
|
|
2021-08-14 21:54:28 +02:00
|
|
|
// Articles d'un blog ou de news
|
2022-10-16 17:44:04 +02:00
|
|
|
if ($this->getData(['module', $parentId, 'posts'])) {
|
2022-05-26 19:37:47 +02:00
|
|
|
|
2022-10-16 17:44:04 +02:00
|
|
|
foreach ($this->getData(['module', $parentId, 'posts']) as $articleId => $article) {
|
|
|
|
if ($this->getData(['module', $parentId, 'posts', $articleId, 'state']) === true) {
|
|
|
|
$url = $parentId . '/' . $articleId;
|
2020-08-14 15:24:14 +02:00
|
|
|
$titre = $article['title'];
|
2020-09-15 20:35:32 +02:00
|
|
|
$contenu = ' ' . $titre . ' ' . $article['content'];
|
2023-06-29 17:01:27 +02:00
|
|
|
$tempData = $this->occurrence($url, $titre, $contenu, $motclef, self::$motentier);
|
2022-10-16 17:44:04 +02:00
|
|
|
if (is_array($tempData)) {
|
|
|
|
$result[] = $tempData;
|
2020-08-17 16:51:18 +02:00
|
|
|
}
|
2020-08-14 15:24:14 +02:00
|
|
|
}
|
2022-10-16 17:44:04 +02:00
|
|
|
}
|
2020-08-14 15:24:14 +02:00
|
|
|
}
|
2020-08-19 15:18:57 +02:00
|
|
|
}
|
|
|
|
// Message de synthèse de la recherche
|
2022-10-16 17:44:04 +02:00
|
|
|
if (count($result) === 0) {
|
2022-10-13 18:21:08 +02:00
|
|
|
self::$resultTitle = helper::translate('Aucun résultat');
|
|
|
|
self::$resultError = helper::translate('Avez-vous pensé aux accents ?');
|
2022-10-16 17:44:04 +02:00
|
|
|
} else {
|
2020-08-19 15:18:57 +02:00
|
|
|
self::$resultError = '';
|
2022-10-13 18:21:08 +02:00
|
|
|
//self::$resultTitle = sprintf(' %s',helper::translate('Résultat de votre recherche'));
|
2020-08-19 15:18:57 +02:00
|
|
|
rsort($result);
|
|
|
|
foreach ($result as $key => $value) {
|
2022-10-16 17:44:04 +02:00
|
|
|
$r[] = $value['preview'];
|
2020-08-17 16:51:18 +02:00
|
|
|
}
|
2020-08-19 15:18:57 +02:00
|
|
|
// Générer une chaine de caractères
|
2022-10-16 17:44:04 +02:00
|
|
|
self::$resultList = implode("", $r);
|
2020-08-17 16:51:18 +02:00
|
|
|
}
|
|
|
|
}
|
2020-08-19 15:18:57 +02:00
|
|
|
|
2020-08-14 15:24:14 +02:00
|
|
|
// Valeurs en sortie, affichage du résultat
|
|
|
|
$this->addOutput([
|
2020-08-16 15:59:37 +02:00
|
|
|
'view' => 'index',
|
|
|
|
'showBarEditButton' => true,
|
2021-04-05 08:59:24 +02:00
|
|
|
'showPageContent' => !$this->getData(['module', $this->getUrl(0), 'config', 'resultHideContent']),
|
2022-08-30 20:29:50 +02:00
|
|
|
'style' => file_exists($this->getData(['module', $this->getUrl(0), 'theme', 'style']))
|
2023-06-29 17:01:27 +02:00
|
|
|
? $this->getData(['module', $this->getUrl(0), 'theme', 'style'])
|
|
|
|
: ''
|
2020-08-14 15:24:14 +02:00
|
|
|
]);
|
|
|
|
} else {
|
|
|
|
// Valeurs en sortie, affichage du formulaire
|
|
|
|
$this->addOutput([
|
|
|
|
'view' => 'index',
|
|
|
|
'showBarEditButton' => true,
|
|
|
|
'showPageContent' => true
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Fonction de recherche des occurrences dans $contenu
|
|
|
|
// Renvoie le résultat sous forme de chaîne
|
|
|
|
private function occurrence($url, $titre, $contenu, $motclef, $motentier)
|
|
|
|
{
|
|
|
|
// Nettoyage de $contenu : on enlève tout ce qui est inclus entre < et >
|
2022-10-16 17:44:04 +02:00
|
|
|
$contenu = preg_replace('/<[^>]*>/', ' ', $contenu);
|
2020-08-14 15:24:14 +02:00
|
|
|
// Accentuation
|
|
|
|
$contenu = html_entity_decode($contenu);
|
2020-08-19 15:18:57 +02:00
|
|
|
|
2020-08-26 19:54:17 +02:00
|
|
|
// Découper le chaîne en tenant compte des quillemets
|
|
|
|
$a = str_getcsv(html_entity_decode($motclef), ' ');
|
|
|
|
|
2020-08-25 23:16:47 +02:00
|
|
|
// Construire la clé de recherche selon options de recherche
|
|
|
|
$keywords = '/(';
|
2021-04-05 08:59:24 +02:00
|
|
|
|
2020-08-25 23:16:47 +02:00
|
|
|
foreach ($a as $key => $value) {
|
2021-04-05 08:59:24 +02:00
|
|
|
|
2022-10-16 17:44:04 +02:00
|
|
|
$keywords .= $motentier === true ? $value . '|' : '\b' . $value . '\b|';
|
2020-08-25 23:16:47 +02:00
|
|
|
}
|
2022-10-16 17:44:04 +02:00
|
|
|
$keywords = substr($keywords, 0, strlen($keywords) - 1);
|
2020-08-25 23:16:47 +02:00
|
|
|
$keywords .= ')/i';
|
2022-10-16 17:44:04 +02:00
|
|
|
$keywords = str_replace('+', ' ', $keywords);
|
2020-08-25 23:16:47 +02:00
|
|
|
|
|
|
|
// Rechercher
|
2022-10-16 17:44:04 +02:00
|
|
|
$valid = preg_match_all($keywords, $contenu, $matches, PREG_OFFSET_CAPTURE);
|
|
|
|
if ($valid > 0) {
|
2020-08-19 15:18:57 +02:00
|
|
|
if (($matches[0][0][1]) > 0) {
|
2023-06-29 17:01:27 +02:00
|
|
|
$resultat = sprintf('<h2><a href="./?%s" target="_blank" rel="noopener">%s (%s)</a></h2>', $url, $titre, count($matches[0]));
|
2020-08-18 19:07:28 +02:00
|
|
|
// Création de l'aperçu
|
|
|
|
// Eviter de découper avec une valeur négative
|
2020-08-19 15:18:57 +02:00
|
|
|
$d = $matches[0][0][1] - 50 < 0 ? 1 : $matches[0][0][1] - 50;
|
2020-08-18 19:07:28 +02:00
|
|
|
// Rechercher l'espace le plus proche
|
2022-10-16 17:44:04 +02:00
|
|
|
$d = $d >= 1 ? strpos($contenu, ' ', $d) : $d;
|
2020-08-18 19:07:28 +02:00
|
|
|
// Découper l'aperçu
|
2022-10-16 17:44:04 +02:00
|
|
|
$t = substr($contenu, $d, $this->getData(['module', $this->getUrl(0), 'config', 'previewLength']));
|
2020-08-18 19:07:28 +02:00
|
|
|
// Applique une mise en évidence
|
2022-10-16 17:44:04 +02:00
|
|
|
$t = preg_replace($keywords, '<span class= "keywordColor">\1</span>', $t);
|
2020-08-18 19:07:28 +02:00
|
|
|
// Sauver résultat
|
2022-10-16 17:44:04 +02:00
|
|
|
$resultat .= '<p class="searchResult">' . $t . '...</p>';
|
2022-10-13 18:21:08 +02:00
|
|
|
|
2020-08-19 15:18:57 +02:00
|
|
|
//}
|
|
|
|
return ([
|
|
|
|
'matches' => count($matches[0]),
|
|
|
|
'preview' => $resultat
|
|
|
|
]);
|
2020-08-14 15:24:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-06-29 17:01:27 +02:00
|
|
|
}
|