From e5f5f1a20265569836cecf4d8bb3c340deef715a Mon Sep 17 00:00:00 2001 From: quenousimporte Date: Mon, 27 Jan 2025 09:01:28 +0100 Subject: [PATCH] refactor, add authent --- .htaccess | 4 + ics.php | 293 +++++++++++++++++++--------------------- settings.php.sample.php | 6 +- 3 files changed, 145 insertions(+), 158 deletions(-) create mode 100644 .htaccess diff --git a/.htaccess b/.htaccess new file mode 100644 index 0000000..53cac3b --- /dev/null +++ b/.htaccess @@ -0,0 +1,4 @@ + +RewriteEngine on +RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L] + \ No newline at end of file diff --git a/ics.php b/ics.php index 5b930aa..671def2 100644 --- a/ics.php +++ b/ics.php @@ -1,169 +1,150 @@ - - + -
- Evénements à venir -
- -
Récupération du calendrier...
- - - +$curl = curl_init(); +curl_setopt($curl, CURLOPT_URL, $davurl); +curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); +curl_setopt($curl, CURLOPT_USERPWD, $davuser . ':' . $davpassword); +curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); +$result = curl_exec($curl); +if (!$result) { + die('error'); +} +curl_close($curl); + +$params = []; +parse_str($_SERVER['QUERY_STRING'], $params); +$recent = isset($params['recent']) ? (int)$params['recent'] : 7; +$recentonly = isset($params['recentonly']); +$weblink = isset($params['weblink']) ? $params['weblink'] : ''; + +$html = "

Evénements à venir

"; +$html .= "

" . strftime('%A, %e %B %Y %H:%M') . "

"; +$html .= "
En gras: modifié les $recent derniers jours
"; +if ($weblink) { + $html .= "
Lien vers calendrier web
"; +} + +$o = ics2json($result); +$lastmodified = new DateTime(); +$lastmodified->modify("-$recent days"); +$group = []; +usort($o['VEVENTS'], function($a, $b) { + return $a['DTSTART'] <=> $b['DTSTART']; +}); + +foreach ($o['VEVENTS'] as $e) { + if ($e['DTSTART'] >= new DateTime() && (!$recentonly || $e['DTSTAMP'] >= $lastmodified)) { + + $formatteddate = strftime('%A %d %B %Y %H:%M', $e['DTSTART']->getTimestamp()); + $splitdate = explode(' ', $formatteddate); + $year = $splitdate[3]; + $month = $splitdate[2]; + $week = getWeek($e['DTSTART']); + if (!isset($group[$year])) { + $html .= "

$year

"; + $group[$year] = []; + } + if (!isset($group[$year][$month])) { + $html .= "

$month

"; + $group[$year][$month] = []; + } + if (!isset($group[$year][$month][$week])) { + $html .= "

Semaine $week

"; + $group[$year][$month][$week] = true; + } + $line = "
  • getTimestamp()) . "\">"; + if ($e['DTSTAMP'] >= $lastmodified) { + $line .= ""; + } + $line .= "$formatteddate: " . $e['SUMMARY']; + if ($e['DTSTAMP'] >= $lastmodified) { + $line .= ""; + } + $line .= '
  • '; + if ($e['DTSTAMP'] >= $lastmodified) { + $line = "$line"; + } + $html .= $line; + } +} +echo $html; +?> + + + \ No newline at end of file diff --git a/settings.php.sample.php b/settings.php.sample.php index 3de1331..b229194 100644 --- a/settings.php.sample.php +++ b/settings.php.sample.php @@ -1,4 +1,6 @@