aboutsummaryrefslogtreecommitdiffstats
path: root/ical_parser.php
diff options
context:
space:
mode:
authorChad Little <clittle@users.sourceforge.net>2002-09-12 05:53:33 +0000
committerChad Little <clittle@users.sourceforge.net>2002-09-12 05:53:33 +0000
commit47595a135b3c12996802adb37f4c8fc6e1243661 (patch)
treea43c1c4cb72b7500b4875ee4dc0516c4c76f11f2 /ical_parser.php
parentc3cc149fd7c7790d51cecb9fdc373110aba0f2f3 (diff)
downloadphpicalendar-47595a135b3c12996802adb37f4c8fc6e1243661.tar.gz
phpicalendar-47595a135b3c12996802adb37f4c8fc6e1243661.tar.bz2
phpicalendar-47595a135b3c12996802adb37f4c8fc6e1243661.zip
*** empty log message ***
Diffstat (limited to 'ical_parser.php')
-rw-r--r--ical_parser.php1
1 files changed, 1 insertions, 0 deletions
diff --git a/ical_parser.php b/ical_parser.php
new file mode 100644
index 0000000..419764d
--- /dev/null
+++ b/ical_parser.php
@@ -0,0 +1 @@
+<? if(phpversion() >= "4.2.0") { extract($HTTP_POST_VARS); extract($HTTP_GET_VARS); } $day_array = array ("0700", "0730", "0800", "0830", "0900", "0930", "1000", "1030", "1100", "1130", "1200", "1230", "1300", "1330", "1400", "1430", "1500", "1530", "1600", "1630", "1700", "1730", "1800", "1830", "1900", "1930", "2000", "2030", "2100", "2130", "2200", "2230", "2300", "2330"); // what iCal file are we using $fullpath = "webcal://chadsdomain.com/ical/Home.ics"; $filename = "calendars/Home.ics"; // what date we want to get data for (for day calendar) if (!$getdate) $getdate = date("Ymd"); ereg ("([0-9]{4})([0-9]{2})([0-9]{2})", $getdate, $day_array2); $this_day = $day_array2[3]; $this_month = $day_array2[2]; $this_year = $day_array2[1]; // open the iCal file, read it into an array $contents = file($filename); $start_time = ""; $end_time = ""; $summary = ""; $allday_start = ""; $allday_end = ""; $i = 0; foreach($contents as $line) { if (strstr($line, "BEGIN:VEVENT")) { $start_time = ""; $end_time = ""; $summary = ""; $allday_start = ""; $allday_end = ""; $start = ""; $end = ""; $the_duration = ""; $beginning = ""; } elseif (strstr($line, "END:VEVENT")) { if ($start_time != "") { //echo "<b>Start</b> $start_time <b>End</B> $end_time <b>Summary</b> $summary<br>\n"; ereg ("([0-9]{2})([0-9]{2})", $start_time, $time); $hour = $time[1]; $minute = $time[2]; if($minute < 15) $minute = "00"; else if($minute >=15 && $minute < 45) $minute = "30"; else if($minute >= 45) { $hour = sprintf("%.02d", ($hour + 1)); $minute = "00"; } $master_array[($start_date)][($hour.$minute)]["event_start"] = $start_time; $master_array[($start_date)][($hour.$minute)]["event_text"] = $summary; } // Let's handle the all day fields if ($end_time != "") { $master_array[($start_date)][($hour.$minute)]["event_end"] = $end_time; ereg ("([0-9]{2})([0-9]{2})", $end_time, $time2); $length = round((($time2[1]*60+$time2[2]) - ($time[1]*60+$time[2]))/30); $master_array[($start_date)][($hour.$minute)]["event_length"] = $length; } if ($allday_start != "") { $start = strtotime("$allday_start"); $end = strtotime("$allday_end"); do { $start_date = date("Ymd", $start); $master_array[($start_date)][("0001")]["event_text"] = "$summary"; $i++; $start = ($start + (24*3600)); } while ($start != $end); } } else { $field = ""; $data = ""; sscanf($line, "%[^:]:%[^\n]", &$field, &$data); //echo $line . "<br>"; //echo $field . "<br>"; //echo $data . "<br>"; if(strstr($field, "DTSTART;TZID")) { $data = ereg_replace("T", "", $data); ereg ("([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{0,2})([0-9]{0,2})", $data, $regs); $year = $regs[1]; $month = $regs[2]; $day = $regs[3]; $hour = $regs[4]; $minute = $regs[5]; $start_date = $year . $month . $day; $start_time = $hour . $minute; } elseif (strstr($field, "DTEND;TZID")) { $data = ereg_replace("T", "", $data); ereg ("([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{0,2})([0-9]{0,2})", $data, $regs); $year = $regs[1]; $month = $regs[2]; $day = $regs[3]; $hour = $regs[4]; $minute = $regs[5]; $end_day = $year . $month . $day; $end_time = $hour . $minute; } elseif (strstr($field, "SUMMARY")) { $summary = $data; } elseif (strstr($field, "X-WR-CALNAME")) { $calendar_name = $data; } elseif (strstr($field, "DTSTART;VALUE=DATE")) { $allday_start = $data; } elseif (strstr($field, "DTEND;VALUE=DATE")) { $allday_end = $data; } elseif (strstr($field, "DURATION")) { ereg ("^P([0-9]{1,2})?([W,D]{0,1})?(T)?([0-9]{1,2})?(H)?([0-9]{1,2})?(M)?([0-9]{1,2})?(S)?", $data, $duration); if ($durartion[2] = "W") { $weeks = $durartion[1]; } else { $days = $durartion[1]; } $hours = $duration[4]; $minutes = $duration[6]; $seconds = $duration[8]; $the_duration = ($weeks * 60 * 60 * 24 * 7) + ($days * 60 * 60 * 24) + ($hours * 60 * 60) + ($minutes * 60) + ($seconds); $beginning = (strtotime($start_time) + $the_duration); $end_time = date ("Hi", $beginning); } } } // If you want to see the values in the arrays, uncomment below. // print_r($master_array); // print_r($day_array); ?> \ No newline at end of file

© 2014-2024 Faster IT GmbH | imprint | privacy policy