Bugfix
This commit is contained in:
@@ -6,22 +6,24 @@ use Contao\CoreBundle\ServiceAnnotation\Hook;
|
|||||||
|
|
||||||
class IndexPageListener
|
class IndexPageListener
|
||||||
{
|
{
|
||||||
/**
|
#[Hook('indexPage')]
|
||||||
* @Hook("indexPage")
|
|
||||||
*/
|
|
||||||
public function onIndexPage(string $content, array &$data, array &$set): void
|
public function onIndexPage(string $content, array &$data, array &$set): void
|
||||||
{
|
{
|
||||||
if (!str_contains($content, 'MEILISEARCH')) {
|
if (!str_contains($content, 'MEILISEARCH')) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (PHP_SAPI === 'cli') {
|
||||||
|
echo "INDEXPAGE LISTENER ACTIVE: " . ($set['url'] ?? '[no url in $set]') . "\n";
|
||||||
|
}
|
||||||
|
|
||||||
$markers = $this->extractMarkers($content);
|
$markers = $this->extractMarkers($content);
|
||||||
if ($markers === []) {
|
if ($markers === []) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* PRIORITY
|
* PRIORITY: event/news > page
|
||||||
*/
|
*/
|
||||||
if (isset($markers['event.priority'])) {
|
if (isset($markers['event.priority'])) {
|
||||||
$set['priority'] = (int) $markers['event.priority'];
|
$set['priority'] = (int) $markers['event.priority'];
|
||||||
@@ -32,30 +34,27 @@ class IndexPageListener
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* KEYWORDS (kombiniert)
|
* KEYWORDS: kombinieren (alle vorhandenen)
|
||||||
*/
|
*/
|
||||||
$keywords = [];
|
$keywords = [];
|
||||||
|
|
||||||
foreach (['event.keywords', 'news.keywords', 'page.keywords'] as $key) {
|
foreach (['event.keywords', 'news.keywords', 'page.keywords'] as $key) {
|
||||||
if (!empty($markers[$key])) {
|
if (!empty($markers[$key])) {
|
||||||
$keywords = array_merge(
|
$parts = preg_split('/\s+/', trim($markers[$key])) ?: [];
|
||||||
$keywords,
|
$keywords = array_merge($keywords, $parts);
|
||||||
preg_split('/\s+/', trim($markers[$key]))
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$keywords = array_values(array_unique(array_filter($keywords)));
|
||||||
if ($keywords !== []) {
|
if ($keywords !== []) {
|
||||||
$set['keywords'] = implode(' ', array_unique($keywords));
|
$set['keywords'] = implode(' ', $keywords);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* SEARCH IMAGE (UUID)
|
* SEARCH IMAGE UUID: event/news > page > custom
|
||||||
|
* (vorerst NUR UUID in tl_search)
|
||||||
*/
|
*/
|
||||||
foreach (
|
foreach (['event.searchimage', 'news.searchimage', 'page.searchimage', 'custom.searchimage'] as $key) {
|
||||||
['event.searchimage', 'news.searchimage', 'page.searchimage', 'custom.searchimage']
|
|
||||||
as $key
|
|
||||||
) {
|
|
||||||
if (!empty($markers[$key])) {
|
if (!empty($markers[$key])) {
|
||||||
$set['imagepath'] = trim($markers[$key]);
|
$set['imagepath'] = trim($markers[$key]);
|
||||||
break;
|
break;
|
||||||
@@ -63,11 +62,11 @@ class IndexPageListener
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* START DATE (Timestamp)
|
* START DATE: event/news.date -> Timestamp (sortierbar)
|
||||||
*/
|
*/
|
||||||
foreach (['event.date', 'news.date'] as $key) {
|
foreach (['event.date', 'news.date'] as $key) {
|
||||||
if (!empty($markers[$key])) {
|
if (!empty($markers[$key])) {
|
||||||
$ts = strtotime($markers[$key]);
|
$ts = strtotime(trim($markers[$key]));
|
||||||
if ($ts !== false) {
|
if ($ts !== false) {
|
||||||
$set['startDate'] = $ts;
|
$set['startDate'] = $ts;
|
||||||
}
|
}
|
||||||
@@ -76,7 +75,6 @@ class IndexPageListener
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private function extractMarkers(string $content): array
|
private function extractMarkers(string $content): array
|
||||||
{
|
{
|
||||||
if (!preg_match('/<!--\s*MEILISEARCH(.*?)-->/s', $content, $m)) {
|
if (!preg_match('/<!--\s*MEILISEARCH(.*?)-->/s', $content, $m)) {
|
||||||
@@ -84,10 +82,12 @@ class IndexPageListener
|
|||||||
}
|
}
|
||||||
|
|
||||||
$markers = [];
|
$markers = [];
|
||||||
foreach (preg_split('/\R/', trim($m[1])) as $line) {
|
foreach (preg_split('/\R/', trim($m[1])) ?: [] as $line) {
|
||||||
if (!str_contains($line, '=')) {
|
$line = trim($line);
|
||||||
|
if ($line === '' || !str_contains($line, '=')) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
[$k, $v] = explode('=', $line, 2);
|
[$k, $v] = explode('=', $line, 2);
|
||||||
$markers[trim($k)] = trim($v);
|
$markers[trim($k)] = trim($v);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user