This commit is contained in:
Jürgen Mummert
2025-12-23 12:43:31 +01:00
parent 9aa3597c2e
commit c71554b18c
2 changed files with 134 additions and 7 deletions
+80 -4
View File
@@ -12,21 +12,46 @@ class IndexPageListener
public function onIndexPage(string $content, array &$data, array &$set): void public function onIndexPage(string $content, array &$data, array &$set): void
{ {
$debug = (PHP_SAPI === 'cli');
if ($debug) {
echo "\n=============================\n";
echo "INDEXPAGE LISTENER\n";
echo "URL: " . ($set['url'] ?? $data['url'] ?? '[unknown]') . "\n";
}
// Marker vorhanden? // Marker vorhanden?
if (!str_contains($content, 'MEILISEARCH_JSON')) { if (!str_contains($content, 'MEILISEARCH_JSON')) {
if ($debug) {
echo "❌ MEILISEARCH_JSON not found\n";
echo "=============================\n";
}
return; return;
} }
if ($debug) {
echo "✔ MEILISEARCH_JSON marker found\n";
}
// JSON aus Kommentar extrahieren + parsen // JSON aus Kommentar extrahieren + parsen
$parsed = $this->extractMeilisearchJson($content); $parsed = $this->extractMeilisearchJson($content);
if ($parsed === null) { if ($parsed === null) {
if ($debug) {
echo "❌ JSON could not be parsed\n";
echo "=============================\n";
}
return; return;
} }
if ($debug) {
echo "✔ JSON parsed successfully:\n";
print_r($parsed);
}
/* /*
* ===================== * =====================
* PRIORITY (event > news > page) * PRIORITY
* ===================== * =====================
*/ */
$priority = $priority =
@@ -36,11 +61,15 @@ class IndexPageListener
if ($priority !== null && $priority !== '') { if ($priority !== null && $priority !== '') {
$set['priority'] = (int) $priority; $set['priority'] = (int) $priority;
if ($debug) {
echo "✔ priority set to: {$set['priority']}\n";
}
} }
/* /*
* ===================== * =====================
* KEYWORDS (merge) * KEYWORDS
* ===================== * =====================
*/ */
$keywordSources = [ $keywordSources = [
@@ -64,11 +93,15 @@ class IndexPageListener
if ($kw) { if ($kw) {
$set['keywords'] = implode(' ', array_unique($kw)); $set['keywords'] = implode(' ', array_unique($kw));
if ($debug) {
echo "✔ keywords set to: {$set['keywords']}\n";
}
} }
/* /*
* ===================== * =====================
* IMAGEPATH (event > news > page > custom) * IMAGEPATH
* ===================== * =====================
*/ */
$image = $image =
@@ -77,28 +110,71 @@ class IndexPageListener
$parsed['page']['searchimage'] ?? null ?? $parsed['page']['searchimage'] ?? null ??
$parsed['custom']['searchimage'] ?? null; $parsed['custom']['searchimage'] ?? null;
if ($debug) {
echo "Resolved image UUID: ";
var_dump($image);
}
if (is_string($image) && $image !== '') { if (is_string($image) && $image !== '') {
if ($debug) {
echo "→ Calling MeilisearchImageHelper\n";
}
$path = $this->imageHelper->getImagePathFromUuid($image); $path = $this->imageHelper->getImagePathFromUuid($image);
if ($debug) {
echo "← Image helper returned: ";
var_dump($path);
}
if ($path !== null) { if ($path !== null) {
$set['imagepath'] = $path; $set['imagepath'] = $path;
if ($debug) {
echo "✔ imagepath set to: {$set['imagepath']}\n";
}
} elseif ($debug) {
echo "❌ image helper returned NULL\n";
} }
} }
/* /*
* ===================== * =====================
* STARTDATE (event.date/news.date => timestamp) * STARTDATE
* ===================== * =====================
*/ */
$date = $date =
$parsed['event']['date'] ?? null ?? $parsed['event']['date'] ?? null ??
$parsed['news']['date'] ?? null; $parsed['news']['date'] ?? null;
if ($debug) {
echo "Resolved date: ";
var_dump($date);
}
if (is_string($date) && $date !== '') { if (is_string($date) && $date !== '') {
$ts = strtotime($date); $ts = strtotime($date);
if ($ts !== false) { if ($ts !== false) {
$set['startDate'] = $ts; $set['startDate'] = $ts;
if ($debug) {
echo "✔ startDate set to timestamp: {$set['startDate']}\n";
} }
} elseif ($debug) {
echo "❌ strtotime failed\n";
}
}
if ($debug) {
echo "---- FINAL \$set ----\n";
print_r([
'priority' => $set['priority'] ?? null,
'keywords' => $set['keywords'] ?? null,
'imagepath' => $set['imagepath'] ?? null,
'startDate' => $set['startDate'] ?? null,
]);
echo "=============================\n";
} }
} }
+54 -3
View File
@@ -16,21 +16,51 @@ class MeilisearchImageHelper
public function getImagePathFromUuid(string $uuid): ?string public function getImagePathFromUuid(string $uuid): ?string
{ {
if (PHP_SAPI === 'cli') {
echo "\n[MeilisearchImageHelper]\n";
echo "UUID received: $uuid\n";
}
$file = FilesModel::findByUuid($uuid); $file = FilesModel::findByUuid($uuid);
if ($file === null) { if ($file === null) {
if (PHP_SAPI === 'cli') {
echo "❌ FilesModel::findByUuid() returned NULL\n";
}
return null; return null;
} }
if (PHP_SAPI === 'cli') {
echo "✔ File found: {$file->path}\n";
}
// SVG niemals skalieren // SVG niemals skalieren
if (str_ends_with(strtolower($file->path), '.svg')) { if (str_ends_with(strtolower($file->path), '.svg')) {
return '/' . ltrim($file->path, '/'); $path = '/' . ltrim($file->path, '/');
if (PHP_SAPI === 'cli') {
echo "✔ SVG detected, returning original path:\n";
echo "$path\n";
}
return $path;
} }
$sizeId = (int) Config::get('meilisearch_imagesize'); $sizeId = (int) Config::get('meilisearch_imagesize');
if (PHP_SAPI === 'cli') {
echo "Image size ID from tl_settings: $sizeId\n";
}
if ($sizeId <= 0) { if ($sizeId <= 0) {
return '/' . ltrim($file->path, '/'); $path = '/' . ltrim($file->path, '/');
if (PHP_SAPI === 'cli') {
echo "⚠ No image size set, returning original path:\n";
echo "$path\n";
}
return $path;
} }
$figure = $this->imageStudio $figure = $this->imageStudio
@@ -39,8 +69,29 @@ class MeilisearchImageHelper
->setSize($sizeId) ->setSize($sizeId)
->build(); ->build();
if (!$figure) {
if (PHP_SAPI === 'cli') {
echo "❌ Figure build returned NULL\n";
}
return null;
}
$image = $figure->getImage(); $image = $figure->getImage();
return $image ? $image->getImageSrc() : null; if ($image === null) {
if (PHP_SAPI === 'cli') {
echo "❌ Figure->getImage() returned NULL\n";
}
return null;
}
$src = $image->getImageSrc();
if (PHP_SAPI === 'cli') {
echo "✔ Processed image path:\n";
echo "$src\n";
}
return $src ?: null;
} }
} }