Bugfix
This commit is contained in:
@@ -2,23 +2,8 @@
|
|||||||
|
|
||||||
namespace MummertMedia\ContaoMeilisearchBundle\EventListener;
|
namespace MummertMedia\ContaoMeilisearchBundle\EventListener;
|
||||||
|
|
||||||
use Contao\System;
|
|
||||||
use MummertMedia\ContaoMeilisearchBundle\Service\MeilisearchImageHelper;
|
|
||||||
|
|
||||||
class IndexPageListener
|
class IndexPageListener
|
||||||
{
|
{
|
||||||
private ?MeilisearchImageHelper $imageHelper = null;
|
|
||||||
|
|
||||||
private function getImageHelper(): MeilisearchImageHelper
|
|
||||||
{
|
|
||||||
if ($this->imageHelper === null) {
|
|
||||||
$this->imageHelper = System::getContainer()
|
|
||||||
->get(MeilisearchImageHelper::class);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->imageHelper;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function onIndexPage(string $content, array &$data, array &$set): void
|
public function onIndexPage(string $content, array &$data, array &$set): void
|
||||||
{
|
{
|
||||||
// Marker vorhanden?
|
// Marker vorhanden?
|
||||||
@@ -26,13 +11,17 @@ class IndexPageListener
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// JSON aus Kommentar extrahieren + parsen
|
||||||
$parsed = $this->extractMeilisearchJson($content);
|
$parsed = $this->extractMeilisearchJson($content);
|
||||||
|
|
||||||
if ($parsed === null) {
|
if ($parsed === null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* PRIORITY
|
* =====================
|
||||||
|
* PRIORITY (event > news > page)
|
||||||
|
* =====================
|
||||||
*/
|
*/
|
||||||
$priority =
|
$priority =
|
||||||
$parsed['event']['priority'] ?? null ??
|
$parsed['event']['priority'] ?? null ??
|
||||||
@@ -44,19 +33,25 @@ class IndexPageListener
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* KEYWORDS
|
* =====================
|
||||||
|
* KEYWORDS (merge)
|
||||||
|
* =====================
|
||||||
*/
|
*/
|
||||||
|
$keywordSources = [
|
||||||
|
$parsed['event']['keywords'] ?? null,
|
||||||
|
$parsed['news']['keywords'] ?? null,
|
||||||
|
$parsed['page']['keywords'] ?? null,
|
||||||
|
];
|
||||||
|
|
||||||
$kw = [];
|
$kw = [];
|
||||||
foreach ([
|
foreach ($keywordSources as $s) {
|
||||||
$parsed['event']['keywords'] ?? null,
|
if (!is_string($s) || trim($s) === '') {
|
||||||
$parsed['news']['keywords'] ?? null,
|
continue;
|
||||||
$parsed['page']['keywords'] ?? null,
|
}
|
||||||
] as $s) {
|
|
||||||
if (is_string($s)) {
|
foreach (preg_split('/\s+/', trim($s)) ?: [] as $p) {
|
||||||
foreach (preg_split('/\s+/', trim($s)) as $p) {
|
if ($p !== '') {
|
||||||
if ($p !== '') {
|
$kw[] = $p;
|
||||||
$kw[] = $p;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -66,7 +61,9 @@ class IndexPageListener
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* IMAGEPATH
|
* =====================
|
||||||
|
* IMAGEPATH (event > news > page > custom)
|
||||||
|
* =====================
|
||||||
*/
|
*/
|
||||||
$image =
|
$image =
|
||||||
$parsed['event']['searchimage'] ?? null ??
|
$parsed['event']['searchimage'] ?? null ??
|
||||||
@@ -75,20 +72,19 @@ class IndexPageListener
|
|||||||
$parsed['custom']['searchimage'] ?? null;
|
$parsed['custom']['searchimage'] ?? null;
|
||||||
|
|
||||||
if (is_string($image) && $image !== '') {
|
if (is_string($image) && $image !== '') {
|
||||||
$path = $this->getImageHelper()->getImagePathFromUuid($image);
|
$set['imagepath'] = trim($image);
|
||||||
if ($path !== null) {
|
|
||||||
$set['imagepath'] = $path;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* STARTDATE
|
* =====================
|
||||||
|
* STARTDATE (event.date/news.date => timestamp)
|
||||||
|
* =====================
|
||||||
*/
|
*/
|
||||||
$date =
|
$date =
|
||||||
$parsed['event']['date'] ?? null ??
|
$parsed['event']['date'] ?? null ??
|
||||||
$parsed['news']['date'] ?? null;
|
$parsed['news']['date'] ?? null;
|
||||||
|
|
||||||
if (is_string($date)) {
|
if (is_string($date) && $date !== '') {
|
||||||
$ts = strtotime($date);
|
$ts = strtotime($date);
|
||||||
if ($ts !== false) {
|
if ($ts !== false) {
|
||||||
$set['startDate'] = $ts;
|
$set['startDate'] = $ts;
|
||||||
|
|||||||
Reference in New Issue
Block a user