Add Index Listener
This commit is contained in:
@@ -9,32 +9,28 @@ class MeilisearchEventMarkerListener
|
|||||||
{
|
{
|
||||||
public function onParseTemplate(Template $template): void
|
public function onParseTemplate(Template $template): void
|
||||||
{
|
{
|
||||||
// ✅ Nur Event-Reader
|
// DEBUG: Immer sichtbar, sobald parseTemplate überhaupt läuft
|
||||||
|
$GLOBALS['MEILISEARCH_MARKERS']['event']['debug_hook'] = 'parseTemplate_called:' . $template->getName();
|
||||||
|
|
||||||
if ($template->getName() !== 'mod_eventreader') {
|
if ($template->getName() !== 'mod_eventreader') {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ✅ Event kommt DIREKT aus dem Template
|
// DEBUG: Was ist im Template vorhanden?
|
||||||
if (
|
$GLOBALS['MEILISEARCH_MARKERS']['event']['debug_has_event_prop'] = isset($template->event) ? 'yes' : 'no';
|
||||||
!isset($template->event) ||
|
|
||||||
!$template->event instanceof CalendarEventsModel
|
if (!isset($template->event) || !$template->event instanceof CalendarEventsModel) {
|
||||||
) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$event = $template->event;
|
$event = $template->event;
|
||||||
|
|
||||||
$priority = (int) ($event->priority ?? 0);
|
$GLOBALS['MEILISEARCH_MARKERS']['event'] = array_merge(
|
||||||
$keywords = trim((string) ($event->keywords ?? ''));
|
$GLOBALS['MEILISEARCH_MARKERS']['event'] ?? [],
|
||||||
|
[
|
||||||
if ($priority <= 0 && $keywords === '') {
|
'priority' => (int) ($event->priority ?? 0),
|
||||||
return;
|
'keywords' => trim((string) ($event->keywords ?? '')),
|
||||||
}
|
]
|
||||||
|
);
|
||||||
// ✅ In globale Marker schreiben (merge-fähig)
|
|
||||||
$GLOBALS['MEILISEARCH_MARKERS']['event'] = [
|
|
||||||
'priority' => $priority > 0 ? $priority : null,
|
|
||||||
'keywords' => $keywords !== '' ? $keywords : null,
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -10,19 +10,21 @@ class MeilisearchPageMarkerListener
|
|||||||
{
|
{
|
||||||
public function onOutputFrontendTemplate(string $buffer, string $template): string
|
public function onOutputFrontendTemplate(string $buffer, string $template): string
|
||||||
{
|
{
|
||||||
|
// Nur im Frontend
|
||||||
if (!isset($GLOBALS['objPage']) || !$GLOBALS['objPage'] instanceof PageModel) {
|
if (!isset($GLOBALS['objPage']) || !$GLOBALS['objPage'] instanceof PageModel) {
|
||||||
return $buffer;
|
return $buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ✅ Vorhandene Marker (event/news) übernehmen
|
// 🔹 Marker aus vorherigen Listenern übernehmen
|
||||||
$markers = $GLOBALS['MEILISEARCH_MARKERS'] ?? [];
|
$markers = $GLOBALS['MEILISEARCH_MARKERS'] ?? [];
|
||||||
|
|
||||||
$page = $GLOBALS['objPage'];
|
$page = $GLOBALS['objPage'];
|
||||||
|
|
||||||
$priority = (int) ($page->priority ?? 0);
|
// --- Page-Daten ---
|
||||||
$keywords = trim((string) ($page->keywords ?? ''));
|
$pagePriority = (int) ($page->priority ?? 0);
|
||||||
|
$pageKeywords = trim((string) ($page->keywords ?? ''));
|
||||||
|
|
||||||
// ✅ searchimage: Page → Fallback
|
// --- Page searchimage → Fallback ---
|
||||||
$searchImageUuid = null;
|
$searchImageUuid = null;
|
||||||
|
|
||||||
if (!empty($page->searchimage)) {
|
if (!empty($page->searchimage)) {
|
||||||
@@ -32,19 +34,21 @@ class MeilisearchPageMarkerListener
|
|||||||
if (!$searchImageUuid) {
|
if (!$searchImageUuid) {
|
||||||
$fallback = Config::get('meilisearch_fallback_image');
|
$fallback = Config::get('meilisearch_fallback_image');
|
||||||
if ($fallback) {
|
if ($fallback) {
|
||||||
// tl_settings speichert varbinary(16) → UUID
|
|
||||||
$searchImageUuid = StringUtil::binToUuid($fallback);
|
$searchImageUuid = StringUtil::binToUuid($fallback);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ✅ Page-Marker NUR ergänzen, nicht alles überschreiben
|
// Page-Marker nur ergänzen (niemals löschen)
|
||||||
$markers['page'] = [
|
$markers['page'] = array_merge(
|
||||||
'priority' => $priority > 0 ? $priority : null,
|
$markers['page'] ?? [],
|
||||||
'keywords' => $keywords !== '' ? $keywords : null,
|
[
|
||||||
|
'priority' => $pagePriority > 0 ? $pagePriority : null,
|
||||||
|
'keywords' => $pageKeywords !== '' ? $pageKeywords : null,
|
||||||
'searchimage' => $searchImageUuid ?: null,
|
'searchimage' => $searchImageUuid ?: null,
|
||||||
];
|
]
|
||||||
|
);
|
||||||
|
|
||||||
// ✅ Ausgabe bauen
|
// 🔹 Ausgabe bauen
|
||||||
$lines = ['MEILISEARCH'];
|
$lines = ['MEILISEARCH'];
|
||||||
|
|
||||||
foreach ($markers as $scope => $data) {
|
foreach ($markers as $scope => $data) {
|
||||||
@@ -61,6 +65,7 @@ class MeilisearchPageMarkerListener
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Wenn nichts drinsteht → nichts anhängen
|
||||||
if (count($lines) === 1) {
|
if (count($lines) === 1) {
|
||||||
return $buffer;
|
return $buffer;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,4 +25,6 @@ $GLOBALS['TL_HOOKS']['parseTemplate'][] = [
|
|||||||
'onParseTemplate',
|
'onParseTemplate',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
if (!isset($GLOBALS['MEILISEARCH_MARKERS'])) {
|
||||||
$GLOBALS['MEILISEARCH_MARKERS'] = [];
|
$GLOBALS['MEILISEARCH_MARKERS'] = [];
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user