connect_error) { die("Verbindung fehlgeschlagen: " . $conn->connect_error); } $conn->set_charset("utf8mb4"); ?> Archiv katholisches Rundfunkreferat

Archiv katholisches Rundfunkreferat

Hinweise zur Suche:
• Mehrere Begriffe durch Leerzeichen trennen – es werden nur Ergebnisse angezeigt, die alle Begriffe enthalten.
• Jahreszahlen (z. B. 2013) finden alle Beiträge aus diesem Jahr.
• Monatsangaben (z. B. 12.2013) finden alle Beiträge aus diesem Monat.
• Genaue Daten (z. B. 13.12.2013) finden Beiträge von diesem Tag.
• Wörter wie Katholisch Rundfunk suchen beide Begriffe im Text und Teaser.

= 1 && $month <= 12) { $conditions[] = "(header LIKE ? OR bodytext LIKE ? OR (YEAR(FROM_UNIXTIME(`date`)) = ? AND MONTH(FROM_UNIXTIME(`date`)) = ?))"; $params[] = "%$t%"; $params[] = "%$t%"; $params[] = $year; $params[] = $month; $types .= "ssii"; continue; } } // 3) DD.MM.YYYY oder D.M.YYYY if (preg_match('/^(\d{1,2})\.(\d{1,2})\.(\d{4})$/', $t, $m)) { $day = (int)$m[1]; $month = (int)$m[2]; $year = (int)$m[3]; if ($month >= 1 && $month <= 12 && $day >= 1 && $day <= 31) { $conditions[] = "(header LIKE ? OR bodytext LIKE ? OR (YEAR(FROM_UNIXTIME(`date`)) = ? AND MONTH(FROM_UNIXTIME(`date`)) = ? AND DAY(FROM_UNIXTIME(`date`)) = ?))"; $params[] = "%$t%"; $params[] = "%$t%"; $params[] = $year; $params[] = $month; $params[] = $day; $types .= "ssiii"; continue; } } // 4) Fallback: normaler Text-Suchbegriff + Datum-String-Abgleich (YYYY-MM-DD) $conditions[] = "(header LIKE ? OR bodytext LIKE ? OR FROM_UNIXTIME(`date`, '%Y-%m-%d') LIKE ?)"; $params[] = "%$t%"; $params[] = "%$t%"; $params[] = "%$t%"; $types .= "sss"; } if (count($conditions) === 0) { echo "

❌ Keine gültigen Suchbegriffe.

"; } else { $whereSQL = implode(" AND ", $conditions); // --- Gesamtanzahl Treffer --- $count_sql = "SELECT COUNT(*) as total FROM tt_content WHERE $whereSQL"; $count_stmt = $conn->prepare($count_sql); if ($count_stmt === false) { die("Prepare fehlgeschlagen (COUNT): " . $conn->error); } // bind params (call_user_func_array benötigt Referenzen) $bindParams = []; $bindParams[] = $types; foreach ($params as $k => $v) { $bindParams[] = &$params[$k]; } call_user_func_array([$count_stmt, 'bind_param'], $bindParams); $count_stmt->execute(); $count_result = $count_stmt->get_result(); $total = (int)$count_result->fetch_assoc()['total']; $count_stmt->close(); if ($total > 0) { // --- Ergebnisse der aktuellen Seite --- $sql = "SELECT uid, header, bodytext, `date` FROM tt_content WHERE $whereSQL ORDER BY `date` DESC LIMIT ? OFFSET ?"; $stmt = $conn->prepare($sql); if ($stmt === false) { die("Prepare fehlgeschlagen (SELECT): " . $conn->error); } $paramsFull = array_merge($params, [$results_per_page, $offset]); $typesFull = $types . "ii"; $bindParams = []; $bindParams[] = $typesFull; foreach ($paramsFull as $k => $v) { $bindParams[] = &$paramsFull[$k]; } call_user_func_array([$stmt, 'bind_param'], $bindParams); $stmt->execute(); $result = $stmt->get_result(); while ($row = $result->fetch_assoc()) { $header = htmlspecialchars($row["header"], ENT_QUOTES, 'UTF-8'); $bodytext = $row["bodytext"]; // Treffer markieren (für jeden Term) foreach ($terms as $t) { $tt = trim($t); if ($tt === '') continue; $pattern = "/" . preg_quote($tt, "/") . "/i"; $header = preg_replace($pattern, "$0", $header); $bodytext = preg_replace_callback($pattern, function($matches){ return "{$matches[0]}"; }, $bodytext); } $datum = date("d.m.Y", (int)$row["date"]); echo "
"; echo "
Veröffentlicht am: $datum | UID: " . $row["uid"] . "
"; echo "

" . $header . "

"; echo $bodytext; echo "
"; } $stmt->close(); // --- Pagination (Seitennummern) --- $total_pages = (int)ceil($total / $results_per_page); if ($total_pages > 1) { echo ""; } } else { echo "

❌ Keine Ergebnisse gefunden.

"; } } } $conn->close(); ?>