diff --git a/content/search-results.php b/content/search-results.php index 22c1024..bea0735 100644 --- a/content/search-results.php +++ b/content/search-results.php @@ -75,10 +75,12 @@ $resultCount = count($results);
-

- +

+ + title); ?> +

-

Kategorie: Beitrag

+

Von: author); ?>

diff --git a/includes/search.php b/includes/search.php index f36f60d..9cb0a10 100644 --- a/includes/search.php +++ b/includes/search.php @@ -2,10 +2,10 @@ Suchleiste. Wird via PHP später in alle Seiten eingebunden --> -
+ -
\ No newline at end of file + diff --git a/php/controller/search-results-controller.php b/php/controller/search-results-controller.php index 5a7ddc1..61c346a 100644 --- a/php/controller/search-results-controller.php +++ b/php/controller/search-results-controller.php @@ -24,6 +24,8 @@ if ($_SERVER["REQUEST_METHOD"] === "GET" && isset($_GET["q"])) { $_SESSION["message"] = "internal_error"; } } + header("Location: ../../index.php?pfad=search-results"); + exit(); } diff --git a/php/model/LocalArticleManager.php b/php/model/LocalArticleManager.php index 306d782..cfccf68 100644 --- a/php/model/LocalArticleManager.php +++ b/php/model/LocalArticleManager.php @@ -169,24 +169,34 @@ class LocalArticleManager implements ArticleManagerDAO { return $filteredArticles; } - public function search(string $keyword): array + // getarticlesbyauthor nutzen um auch nach kategorien zu suchen + public function search(string $keyword): array { - $results = []; - $contentFolder = __DIR__ . '/../content/'; - $files = glob($contentFolder . "*.php"); + // 1. Alle Artikel aus der JSON-Datei laden + $articles = $this->getAllArticles(); + $filteredArticles = []; - foreach ($files as $file) { - $content = file_get_contents($file); - if (stripos($content, $keyword) !== false) { - $filename = basename($file, ".php"); - $results[] = [ - 'title' => ucfirst($filename), - 'link' => "index.php?pfad=" . $filename - ]; + // 2. Artikel durchlaufen und filtern + foreach ($articles as $article) { + $inTitle = isset($article['title']) && stripos($article['title'], $keyword) !== false; + $inContent = isset($article['content']) && stripos($article['content'], $keyword) !== false; + + // Wenn das Keyword im Titel ODER im Inhalt vorkommt + if ($inTitle || $inContent) { + // Wir mappen die JSON-Daten auf ein echtes Article-Objekt (genau wie bei getArticlesByAuthor) + $filteredArticles[] = new Article( + intval($article['id']), + $article['title'], + $article['content'], + $article['author'], + $article['category'], + $article['tags'], + $article['creationDate'] + ); } } - return $results; + return $filteredArticles; } }