Dateien nach „/“ hochladen
This commit is contained in:
commit
8cadeb6492
1 changed files with 169 additions and 0 deletions
169
ncagenda-code.php
Normal file
169
ncagenda-code.php
Normal file
|
@ -0,0 +1,169 @@
|
|||
<?php
|
||||
|
||||
|
||||
$search = $_GET["search"];
|
||||
|
||||
if (!$search) {
|
||||
$search = "";
|
||||
}
|
||||
|
||||
|
||||
|
||||
function parseICS($icsString) {
|
||||
|
||||
$events = [];
|
||||
preg_match_all('/BEGIN:VEVENT(.*?)END:VEVENT/s', $icsString, $matches);
|
||||
|
||||
foreach ($matches[1] as $event) {
|
||||
$data = [];
|
||||
|
||||
preg_match('/DTSTART.*?:(.*?)\n/', $event, $start);
|
||||
preg_match('/DTEND.*?:(.*?)\n/', $event, $end);
|
||||
preg_match('/SUMMARY:(.*?)\n/', $event, $summary);
|
||||
preg_match('/LOCATION:(.*?)\n/', $event, $location);
|
||||
|
||||
// DESCRIPTION erfassen (endet bei einer Zeile mit "GROSSBUCHSTABEN:" oder "GROSSBUCHSTABEN;")
|
||||
preg_match('/DESCRIPTION:(.*?)(?=\n[A-Z-]+[:;]|\n?$)/s', $event, $description);
|
||||
if (isset($description[1])) {
|
||||
$cleanedDescription = preg_replace("/\n /", "", trim($description[1])); // Umgebrochene Zeilen korrigieren
|
||||
// $cleanedDescription = preg_replace("/\\\\n/", "<br>", $cleanedDescription); // \n in <br> umwandeln
|
||||
} else {
|
||||
$cleanedDescription = '';
|
||||
}
|
||||
|
||||
// ATTACH erfassen (richtige Datei-URL extrahieren)
|
||||
preg_match('/ATTACH;.*?:([^\n]+)/', $event, $attach);
|
||||
$attachmentUrl = isset($attach[1]) ? trim($attach[1]) : '';
|
||||
|
||||
$data['DTSTART'] = $start[1] ?? '';
|
||||
$data['DTEND'] = $end[1] ?? '';
|
||||
$data['SUMMARY'] = $summary[1] ?? '';
|
||||
$data['LOCATION'] = $location[1] ?? '';
|
||||
$data['DESCRIPTION'] = $cleanedDescription;
|
||||
$data['ATTACH'] = $attachmentUrl;
|
||||
|
||||
$events[] = $data;
|
||||
}
|
||||
return $events;
|
||||
}
|
||||
|
||||
|
||||
// Datenbankverbindung
|
||||
include "includes/conn.php";
|
||||
|
||||
$conn = new mysqli($servername, $username, $password, $dbname);
|
||||
|
||||
// Verbindung prüfen
|
||||
if ($conn->connect_error) {
|
||||
die("Verbindung fehlgeschlagen: " . $conn->connect_error);
|
||||
}
|
||||
|
||||
$sql = "SELECT calendardata FROM `oc_calendarobjects` where calendardata LIKE '%$search%' and calendarid LIKE '90'";
|
||||
$result = $conn->query($sql);
|
||||
|
||||
$icsData = "";
|
||||
if ($result->num_rows > 0) {
|
||||
while ($row = $result->fetch_assoc()) {
|
||||
$icsData .= $row["calendardata"] . "\n";
|
||||
}
|
||||
}
|
||||
$conn->close();
|
||||
|
||||
$parsedEvents = parseICS($icsData);
|
||||
|
||||
|
||||
// Events nach Startdatum sortieren
|
||||
usort($parsedEvents, function ($a, $b) {
|
||||
return strcmp($a['DTSTART'], $b['DTSTART']);
|
||||
});
|
||||
?>
|
||||
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="de">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Kalender Events</title>
|
||||
<link rel="stylesheet" type="text/css" href="agendastyle.css" />
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="events">
|
||||
<?php foreach ($parsedEvents as $event): ?>
|
||||
<div class="event">
|
||||
|
||||
<details>
|
||||
<summary>
|
||||
<?php
|
||||
|
||||
$startDate = $event['DTSTART'];
|
||||
|
||||
if (str_contains($startDate, "Z")) {
|
||||
echo "international date format error";
|
||||
continue;
|
||||
}
|
||||
if (str_contains($startDate, "T")) {
|
||||
$startDate = substr($startDate, 0, -1);
|
||||
$date = DateTime::createFromFormat("Ymd\THis", $startDate);
|
||||
$formattedDate = $date->format("d.m.Y - H:i");
|
||||
echo $formattedDate;
|
||||
}
|
||||
else {
|
||||
$dateUnformatted = $startDate;
|
||||
$dateUnformatted = substr($dateUnformatted, 0, -1);
|
||||
$date = DateTime::createFromFormat("Ymd", $dateUnformatted);
|
||||
$formattedDate = $date->format("d.m.Y");
|
||||
echo $formattedDate;
|
||||
}
|
||||
?>
|
||||
<strong> <?php echo htmlspecialchars($event['SUMMARY']); ?></strong>
|
||||
|
||||
|
||||
</summary>
|
||||
|
||||
<div class="details">
|
||||
<p><strong>Start:</strong> <?php echo $formattedDate; ?>
|
||||
|
||||
<p><strong>End:</strong> <?php
|
||||
|
||||
$endDate = $event['DTEND'];
|
||||
|
||||
if (str_contains($endDate, "T")) {
|
||||
$dateUnformatted = $endDate;
|
||||
$dateUnformatted = substr($dateUnformatted, 0, -1);
|
||||
$date = DateTime::createFromFormat("Ymd\THis", $dateUnformatted);
|
||||
$formattedDate = $date->format("d.m.Y - H:i");
|
||||
echo $formattedDate;
|
||||
}
|
||||
else {
|
||||
$dateUnformatted = $endDate;
|
||||
$dateUnformatted = substr($dateUnformatted, 0, -1);
|
||||
$date = DateTime::createFromFormat("Ymd", $dateUnformatted);
|
||||
$formattedDate = $date->format("d.m.Y");
|
||||
echo $formattedDate;
|
||||
}
|
||||
?></p>
|
||||
|
||||
<p><strong>Place:</strong> <?php echo htmlspecialchars($event['LOCATION']); ?></p>
|
||||
<p><strong>Info:</strong> <?php echo str_replace('\n',"<br>", htmlspecialchars($event['DESCRIPTION'])); ?></p>
|
||||
<?php if (!empty($event['ATTACH'])): ?>
|
||||
<p><strong>Attach:</strong></p>
|
||||
<ul>
|
||||
<?php foreach ($event['ATTACH'] as $attach): ?>
|
||||
<li><a href="<?php echo htmlspecialchars($attach); ?>" target="_blank">Download</a></li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</details>
|
||||
|
||||
|
||||
|
||||
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</div>
|
Loading…
Add table
Reference in a new issue