-
Notifications
You must be signed in to change notification settings - Fork 0
/
eventListFunctios.php
69 lines (52 loc) · 1.79 KB
/
eventListFunctios.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
require 'vendor/autoload.php';
//usage: printEvents(array("bla"),5);
echo "<?php header('Access-Control-Allow-Origin: *'); ?>\n\r";
use ICal\ICal;
$ical = new ICal("./MYical.ics");
$events = $ical->events();
date_default_timezone_set($ical->calendarTimeZone());
function printEvents($filters = array(),$max = 0){
global $ical, $events;
$printCount = 0;
foreach ($events as $event) {
if($max != 0 && $printCount >= $max)
return 1; //more events exist
if($ical->iCalDateToUnixTimestamp($event->dtend) < time())
continue;
if(count($filters) == 0){
printEvent($event);
$printCount++;
}
else{
foreach($filters as $filter){
if(preg_match("/\[[\s\S]*" . $filter . "[\s\S]*\]/",$event->summary)){
printEvent($event);
$printCount++;
break;
}
}
}
}
return 0; //no more events
}
function printEvent($event){
global $ical;
$begin = date_create();
date_timestamp_set($begin,$ical->iCalDateToUnixTimestamp($event->dtstart));
$line = $begin->format('d.m.') . " - ";
$end = date_create();
date_timestamp_set($end,$ical->iCalDateToUnixTimestamp($event->dtend) - 1);
$line .= $end->format('d.m.') . " - ";
$name = $event->summary;
$name = preg_replace("/\[[\s\S]*\]/","",$name);
$line .= $name;
preg_match("/(https?:\/\/[^\s]+)/", $event->description, $output_array);
if(count($output_array) > 0){
$link = str_replace("\\n","",$output_array[0]);
$link = str_replace("\\r","",$link);
$line = "<a href='" . $link . "'>" . $line . "</a>";
}
echo $line . "<br>\n\r";
}
?>