From b1563901b07c57d0957a760296c12431637c2bb0 Mon Sep 17 00:00:00 2001 From: jwangen Date: Thu, 3 Oct 2002 05:41:40 +0000 Subject: Moved init.inc.php and ical_parser into the functions directory --- config.inc.php | 4 +- day.php | 2 +- event.php | 2 +- functions/ical_parser.php | 657 ++++++++++++++++++++++++++++++++++++++++++++++ functions/init.inc.php | 53 ++++ ical_parser.php | 657 ---------------------------------------------- index.php | 2 +- init.inc.php | 53 ---- month.php | 2 +- week.php | 2 +- 10 files changed, 717 insertions(+), 717 deletions(-) create mode 100644 functions/ical_parser.php create mode 100644 functions/init.inc.php delete mode 100644 ical_parser.php delete mode 100644 init.inc.php diff --git a/config.inc.php b/config.inc.php index 44e6c37..835b5c7 100644 --- a/config.inc.php +++ b/config.inc.php @@ -4,8 +4,8 @@ $style_sheet = "silver"; // Themes support $calendar_path = "./calendars"; // path to directory with calendars $default_view = "day"; // default view for calendars = "day", "week", "month" $default_cal = "Home"; // exact filename of calendar without .ics -$language = "English"; // Language support - "English", "Polish", "German", "French", "Dutch", "Danish", "Italian", "Japanese", "Norwegian" -$week_start_day = "Sunday"; // Day of the week your week starts on +$language = "english"; // Language support - "English", "Polish", "German", "French", "Dutch", "Danish", "Italian", "Japanese", "Norwegian" +$week_start_day = "sunday"; // Day of the week your week starts on $use_sessions = "yes"; // For speedy performance on web servers, not good for localhost use. $day_start = "0700"; // Start time for day grid $gridLength = "15"; // grid distance in minutes for day view diff --git a/day.php b/day.php index d867f8b..70bfed6 100644 --- a/day.php +++ b/day.php @@ -8,7 +8,7 @@ if (isset($HTTP_GET_VARS["jumpto_day"])) { } } $current_view = "day"; -include("./ical_parser.php"); +include("./functions/ical_parser.php"); diff --git a/event.php b/event.php index b0bd2de..0aa0be1 100644 --- a/event.php +++ b/event.php @@ -1,6 +1,6 @@ ", $summary); + $summary = stripslashes($summary); + $description = str_replace("\\n", "
", $description); + $mArray_begin = mktime (0,0,0,1,1,$this_year); + $mArray_end = mktime (0,0,0,1,10,($this_year + 1)); + + if ($start_time != "") { + ereg ("([0-9]{2})([0-9]{2})", $start_time, $time); + ereg ("([0-9]{2})([0-9]{2})", $end_time, $time2); + $length = ($time2[1]*60+$time2[2]) - ($time[1]*60+$time[2]); + + $drawKey = drawEventTimes($start_time, $end_time); + ereg ("([0-9]{2})([0-9]{2})", $drawKey["draw_start"], $time3); + $hour = $time3[1]; + $minute = $time3[2]; + } + + + // Handling of the all day events +// to go back to old allday way, add to this if--> && ($rrule_array == "") + if (($allday_start != "")) { + $start = strtotime("$allday_start"); + $end = strtotime("$allday_end"); + if (($end > $mArray_begin) && ($end < $mArray_end)) { + while ($start != $end) { + $start_date = date("Ymd", $start); + $master_array[($start_date)][("-1")][]= array ("event_text" => "$summary", "description" => $description); + $start = strtotime("+1 day", $start); + } + } + } + + + // Handling of the recurring events, RRULE + // This will be quite a bit of work, thats for sure. + if (is_array($rrule_array)) { + if ($allday_start != "") { + $rrule_array["START_DAY"] = $allday_start; + $rrule_array["END_DAY"] = $allday_end; + $rrule_array["END"] = "end"; + $recur_start = $allday_start; + $start_date = $allday_start; + $diff_allday_days = dayCompare($allday_end, $allday_start); + } else { + $rrule_array["START_DATE"] = $start_date; + $rrule_array["START_TIME"] = $start_time; + $rrule_array["END_TIME"] = $end_time; + $rrule_array["END"] = "end"; + } + //print_r($rrule_array); + foreach ($rrule_array as $key => $val) { + if ($key == "FREQ") { + if ($val == "YEARLY") { + $interval = "yyyy"; + } elseif ($val == "MONTHLY") { + $interval = "m"; + } elseif ($val == "WEEKLY") { + $interval = "ww"; + } elseif ($val == "DAILY") { + $interval = "d"; + } elseif ($val == "HOURLY") { + $interval = "h"; + } elseif ($val == "MINUTELY") { + $interval = "n"; + } elseif ($val == "SECONDLY") { + $interval = "s"; + } + } elseif ($key == "COUNT") { + $count = $val; + + } elseif ($key == "UNTIL") { + $until = ereg_replace("T", "", $val); + ereg ("([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{0,2})([0-9]{0,2})", $until, $regs); + $year = $regs[1]; + $month = $regs[2]; + $day = $regs[3]; + $until = strtotime("$year$month$day"); + + } elseif ($key == "INTERVAL") { + $number = $val; + + } elseif ($key == "BYSECOND") { + $bysecond = $val; + $bysecond = split (",", $bysecond); + + } elseif ($key == "BYMINUTE") { + $byminute = $val; + $byminute = split (",", $byminute); + + } elseif ($key == "BYHOUR") { + $byhour = $val; + $byhour = split (",", $byhour); + + } elseif ($key == "BYDAY") { + $byday = $val; + $byday = split (",", $byday); + + } elseif ($key == "BYMONTHDAY") { + $bymonthday = $val; + $bymonthday = split (",", $bymonthday); + //print_r ($bymonthday); + + } elseif ($key == "BYYEARDAY") { + $byyearday = $val; + $byyearday = split (",", $byyearday); + + } elseif ($key == "BYWEEKNO") { + $byweekno = $val; + $byweekno = split (",", $byweekno); + + } elseif ($key == "BYMONTH") { + $bymonth = $val; + $bymonth = split (",", $bymonth); + + } elseif ($key == "BYSETPOS") { + $bysetpos = $val; + + } elseif ($key == "WKST") { + $wkst = $val; + + } elseif ($key == "END") { +// to go back to old allday way, uncomment this set + /* + if ($allday_start != "") { + + // Since we hit the end of the RRULE array, lets do something. + // Below handles yearly, montly, weekly, daily all-day events. + // $start_of_vevent is the date the recurring event starts. + // $end_of_vevent is the date the recurring event stops. + // $count and $count_to check for the COUNT feature + // $until checks for the UNTIL feature, makes sure we don't recur past it. + + $start_of_vevent = strtotime("$allday_start"); + $end_of_vevent = strtotime("$allday_end"); + $count_to = 0; + if (!$until) $until = $mArray_end; + if ($start_of_vevent < $mArray_end) { + do { + // This steps through each day of a multiple all-day event and adds to master array + // Every all day event should pass through here at least once if its recurring. + $start = $start_of_vevent; + $end = $end_of_vevent; + while ($start != $end) { + $start_date = date("Ymd", $start); + if (($end > $mArray_begin) && ($end < $mArray_end)) { + $master_array[($start_date)][("-1")][]= array ("event_text" => "$summary", "description" => $description); + } + $start = strtotime("+1 day", $start); + } + $start_of_vevent = DateAdd ($interval, $number, $start_of_vevent); + $end_of_vevent = DateAdd ($interval, $number, $end_of_vevent); + $count_to++; + } while (($start_of_vevent < $mArray_end) && ($count != $count_to) && ($start_of_vevent < $until)); + } + + // Let's take care of recurring events that are not all day events + // DAILY and WEEKLY recurrences seem to work fine. Need feedback. + // Known bug, doesn't look at UNTIL or COUNT yet. + } else { + */ + // again, $parse_to_year is set to January 10 of the upcoming year + $parse_to_year_time = mktime(0,0,0,1,10,($this_year + 1)); + $start_date_time = strtotime($start_date); + $this_month_start_time = strtotime("$this_year-$this_month-01"); + + $start_range_time = strtotime("-1 month -2 day", $this_month_start_time); + $end_range_time = strtotime("+2 month +2 day", $this_month_start_time); + + // NOTE: This part not in use for the time being. We are choosing to fill out 3 months time. + // depending on which view we're looking at, we do one month or one week + // one day is more difficult, I think, so I wrapped that into the week. We'll have to + // add another case for "year" once that's added. + /* + if ($current_view == "month") { + $start_range_time = strtotime("$this_year-$this_month-01"); + $end_range_time = strtotime("+1 month +1 week", $start_range_time); + } else { + $start_range_time = strtotime(dateOfWeek($getdate, $week_start_day)); + $end_range_time = strtotime("+1 week", $start_range_time); + } + */ + + // if $until isn't set yet, we set it to the end of our range we're looking at + if (!$until) $until = $end_range_time; + $end_date_time = $until; + + // If the $end_range_time is less than the $start_date_time, or $start_range_time is greater + // than $end_date_time, we may as well forget the whole thing + // It doesn't do us any good to spend time adding data we aren't even looking at + // this will prevent the year view from taking way longer than it needs to + if ($end_range_time >= $start_date_time && $start_range_time <= $end_date_time) { + + // if the beginning of our range is less than the start of the item, we may as well set it equal to it + if ($start_range_time < $start_date_time) $start_range_time = $start_date_time; + if ($end_range_time > $end_date_time) $end_range_time = $end_date_time; + + // initialze the time we will increment + $next_range_time = $start_range_time; + + $count_to = 0; + // start at the $start_range and go until we hit the end of our range. + while (($next_range_time >= $start_range_time) && ($next_range_time <= $end_range_time) && ($count_to != $count)) { + + // handling WEEKLY events here + if ($rrule_array["FREQ"] == "WEEKLY") { + + // use weekCompare to see if we even have this event this week + $diff_weeks = weekCompare(date("Ymd",$next_range_time), $start_date); + if ($diff_weeks < $count) { + if ($week_diff % $number == 0) { + $interval = $number; + // loop through the days on which this event happens + foreach($byday as $day) { + + // use my fancy little function to get the date of each day + $day = two2threeCharDays($day); + $next_date = dateOfWeek(date("Ymd", $next_range_time),$day); + $next_date_time = strtotime($next_date); + + if (($next_date_time > $start_date_time) && ($next_date_time <= $end_date_time) && ($count_to != $count) && !in_array($next_date, $except_dates)) { + // add it to the array if it passes inspection, it allows the first time to be + // written by the master data writer (hence the > instead of >=) otherwise we can special case these + // before, the first one would get entered twice and show up twice + // $next_date can fall up to a week behind $next_range_time because of how dateOfWeek works + // so we have to check this again. It uses $except_dates so it doesn't add to $master_array + // on days that have been deleted by the user + if ($allday_start != "") { + + $start_time = $next_date_time; + $end_time = strtotime("+$diff_allday_days days", $next_date_time); + while ($start_time < $end_time) { + $start_date2 = date("Ymd", $start_time); + $master_array[($start_date2)][("-1")][]= array ("event_text" => "$summary", "description" => $description); + $start_time = strtotime("+1 day", $start_time); + } + } else { +// check for overlapping events + $nbrOfOverlaps = checkOverlap(); +// writes to $master array here + $master_array[($next_date)][($hour.$minute)][] = array ("event_start" => $start_time, "event_text" => $summary, "event_end" => $end_time, "event_length" => $length, "event_overlap" => $nbrOfOverlaps, "description" => $description); + } + } + } + } else { + $interval = 1; + } + $next_range_time = strtotime("+$interval week", $next_range_time); + } else { + // end the loop because we aren't going to write this event anyway + $count_to = $count; + } + + + // handling DAILY events here + } elseif ($rrule_array["FREQ"] == "DAILY") { + + // use dayCompare to see if we even have this event this day + $diff_days = dayCompare(date("Ymd",$next_range_time), $start_date); + if ($diff_days < $count) { + if ($diff_days % $number == 0) { + $interval = $number; + $next_date = date("Ymd", $next_range_time); + $next_date_time = strtotime($next_date); + + if (($next_date_time > $start_date_time) && ($next_date_time <= $end_date_time) && ($count_to != $count) && !in_array($next_date, $except_dates)) { + if ($allday_start != "") { + + $start_time = $next_date_time; + $end_time = strtotime("+$diff_allday_days days", $next_date_time); + while ($start_time < $end_time) { + $start_date2 = date("Ymd", $start_time); + $master_array[($start_date2)][("-1")][]= array ("event_text" => "$summary", "description" => $description); + $start_time = strtotime("+1 day", $start_time); + } + } else { +// check for overlapping events + $nbrOfOverlaps = checkOverlap(); +// writes to $master array here + $master_array[($next_date)][($hour.$minute)][] = array ("event_start" => $start_time, "event_text" => $summary, "event_end" => $end_time, "event_length" => $length, "event_overlap" => $nbrOfOverlaps, "description" => $description); + } + } + } else { + $interval = 1; + } + $next_range_time = strtotime("+$interval day", $next_range_time); + } else { + // end the loop because we aren't going to write this event anyway + $count_to = $count; + } + + + // handling MONTHLY events here + } elseif ($rrule_array["FREQ"] == "MONTHLY") { + $next_range_time = strtotime(date("Y-m-01", $next_range_time)); + // use monthCompare to see if we even have this event this month + + $diff_months = monthCompare(date("Ymd",$next_range_time), $start_date); + if ($diff_months < $count) { + if ($diff_months % $number == 0) { + $interval = $number; + + // month has two cases, either $bymonthday or $byday + if (is_array($bymonthday)) { + + // loop through the days on which this event happens + foreach($bymonthday as $day) { + if ($day != "0") { + $next_date_time = strtotime(date("Y-m-",$next_range_time).$day); + $next_date = date("Ymd", $next_date_time); + if (($next_date_time > $start_date_time) && ($next_date_time <= $end_date_time) && ($count_to != $count) && !in_array($next_date, $except_dates)) { + if ($allday_start != "") { + $start_time = $next_date_time; + $end_time = strtotime("+$diff_allday_days days", $next_date_time); + while ($start_time < $end_time) { + $start_date2 = date("Ymd", $start_time); + $master_array[($start_date2)][("-1")][]= array ("event_text" => "$summary", "description" => $description); + $start_time = strtotime("+1 day", $start_time); + } + } else { +// check for overlapping events + $nbrOfOverlaps = checkOverlap(); +// writes to $master array here + $master_array[($next_date)][($hour.$minute)][] = array ("event_start" => $start_time, "event_text" => $summary, "event_end" => $end_time, "event_length" => $length, "event_overlap" => $nbrOfOverlaps, "description" => $description); + } + } + } + } + + // our other case + } else { + // loop through the days on which this event happens + foreach($byday as $day) { + ereg ("([0-9]{1})([A-Z]{2})", $day, $byday_arr); + $nth = $byday_arr[1]-1; + $on_day = two2threeCharDays($byday_arr[2]); + $next_date_time = strtotime("$on_day +$nth week", $next_range_time); + $next_date = date("Ymd", $next_date_time); + if (($next_date_time > $start_date_time) && ($next_date_time <= $end_date_time) && ($count_to != $count) && !in_array($next_date, $except_dates)) { + + if ($allday_start != "") { + + $start_time = $next_date_time; + $end_time = strtotime("+$diff_allday_days days", $next_date_time); + while ($start_time < $end_time) { + $start_date2 = date("Ymd", $start_time); + $master_array[($start_date2)][("-1")][]= array ("event_text" => "$summary", "description" => $description); + $start_time = strtotime("+1 day", $start_time); + } + } else { +// check for overlapping events + $nbrOfOverlaps = checkOverlap(); +// writes to $master array here + $master_array[($next_date)][($hour.$minute)][] = array ("event_start" => $start_time, "event_text" => $summary, "event_end" => $end_time, "event_length" => $length, "event_overlap" => $nbrOfOverlaps, "description" => $description); + } + } + } + } + } else { + $interval = 1; + } + $next_range_time = strtotime("+$interval month", $next_range_time); + } else { + // end the loop because we aren't going to write this event anyway + $count_to = $count; + } + + // handle yearly events + } elseif ($rrule_array["FREQ"] == "YEARLY") { + // use yearCompare to see if we even have this event this year + $the_month_day = date("d", $start_date_time); + $diff_years = yearCompare(date("Ymd",$next_range_time), $start_date); + if ($diff_years < $count) { + if ($diff_years % $number == 0) { + foreach($bymonth as $month) { + if (is_array($byday)) { + $next_range_time = strtotime("$this_year-$month-01"); + foreach($byday as $day) { + ereg ("([0-9]{1})([A-Z]{2})", $day, $byday_arr); + $nth = $byday_arr[1]-1; + $on_day = two2threeCharDays($byday_arr[2]); + $next_date_time = strtotime("$on_day +$nth week", $next_range_time); + + } + } else { + $next_date_time = strtotime("$this_year-$month-$the_month_day", $next_range_time); + } + if (($next_date_time > $start_date_time) && ($next_date_time <= $end_date_time) && ($count_to != $count) && !in_array($next_date, $except_dates)) { + if ($allday_start != "") { + + $start_time = $next_date_time; + $end_time = strtotime("+$diff_allday_days days", $next_date_time); + while ($start_time < $end_time) { + $start_date2 = date("Ymd", $start_time); + $master_array[($start_date2)][("-1")][]= array ("event_text" => "$summary", "description" => $description); + $start_time = strtotime("+1 day", $start_time); + } + } else { +// check for overlapping events + $nbrOfOverlaps = checkOverlap(); +// writes to $master array here + $master_array[($next_date)][($hour.$minute)][] = array ("event_start" => $start_time, "event_text" => $summary, "event_end" => $end_time, "event_length" => $length, "event_overlap" => $nbrOfOverlaps, "description" => $description); + } + } + } + } else { + $interval = 1; + } + $next_range_time = strtotime("+$interval year", $next_range_time); + } else { + // end the loop because we aren't going to write this event anyway + $count_to = $count; + } + + // anything else we need to end the loop + } else { + $next_range_time = $end_range_time + 100; + $count_to = $count; + } + } +// to go back to old allday way, uncomment this bracket + // } + } + } + } + } + + // Let's write all the data to the master array + if (($start_time != "") && ($allday_start == "")) { +// check for overlapping events + $nbrOfOverlaps = checkOverlap(); + +// writes to $master array here + $master_array[($start_date)][($hour.$minute)][] = array ("event_start" => $start_time, "event_text" => $summary, "event_end" => $end_time, "event_length" => $length, "event_overlap" => $nbrOfOverlaps, "description" => $description); + } + + + + + + } else { + + $field = ""; + $data = ""; + + sscanf($line, "%[^:]:%[^\n]", &$field, &$data); + + 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_date = $year . $month . $day; + $end_time = $hour . $minute; + + } elseif (strstr($field, "EXDATE;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]; + + $except_dates[] = $year . $month . $day; + $except_times[] = $hour . $minute; + + } elseif (strstr($field, "SUMMARY")) { + $summary = $data; + + } elseif (strstr($field, "DESCRIPTION")) { + $description = $data; + + } elseif (strstr($field, "X-WR-CALNAME")) { + $calendar_name = $data; + + } elseif (strstr($field, "DTSTART;VALUE=DATE")) { + $allday_start = $data; + // echo "$allday_start"; + + } elseif (strstr($field, "DTEND;VALUE=DATE")) { + $allday_end = $data; + + } elseif (strstr($field, "DURATION")) { + + if (($first_duration = TRUE) && (!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 ($duration[2] = "W") { + $weeks = $duration[1]; + } else { + $days = $duration[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); + $first_duration = FALSE; + } + + } elseif (strstr($field, "RRULE")) { + // $data = "RRULE:FREQ=YEARLY;INTERVAL=2;BYMONTH=1;BYDAY=SU;BYHOUR=8,9;BYMINUTE=30"; + $data = ereg_replace ("RRULE:", "", $data); + $rrule = split (";", $data); + foreach ($rrule as $recur) { + ereg ("(.*)=(.*)", $recur, $regs); + $rrule_array[$regs[1]] = $regs[2]; + } + } elseif (strstr($field, "ATTENDEE")) { + $attendee = $data; + // echo "$attendee"; + + } + } +} + +// Sort the array by absolute date. +if (is_array($master_array)) { + ksort($master_array); + reset($master_array); + + // sort the sub (day) arrays so the times are in order + foreach (array_keys($master_array) as $k) { + if (is_array($master_array[$k])) { + ksort($master_array[$k]); + reset($master_array[$k]); + } + } +} + + + +// Store information in the session +/*if ($use_sessions == "yes") { + session_start(); + session_register( "aArray", "aYear", "aLanguage", "aCalendar" ); + $aArray = $master_array; + $aYear = $this_year; + $aLanguage = $language; + $aCalendar = $cal; +}*/ + + +// End the session +//} + +//If you want to see the values in the arrays, uncomment below. +//print "
";
+//print_r($master_array);
+//print_r($overlap_array);
+//print_r($day_array);
+//print_r($rrule);			
+//print "
"; + + +?> \ No newline at end of file diff --git a/functions/init.inc.php b/functions/init.inc.php new file mode 100644 index 0000000..7525fbc --- /dev/null +++ b/functions/init.inc.php @@ -0,0 +1,53 @@ += "4.2.0") + + { + extract($HTTP_GET_VARS); + extract($HTTP_POST_VARS); + } + +include('./config.inc.php'); + +// subscribe link prefix, doesn't need to be user configureable +$fullpath = 'webcal://'.$HTTP_SERVER_VARS['SERVER_NAME'].dirname($HTTP_SERVER_VARS['PHP_SELF']).'/'.$calendar_path.'/'; + + +// language support +$language = strtolower($language); +$lang_file = "./languages/$language.inc.php"; + +if (file_exists($lang_file)) { + include($lang_file); +} else { +// Not sure if we should print this warning or not. It would inform the user +// why the language isn't working. + print "File \"$lang_file\" does not exist, defaulting to English

"; + include("../languages/english.inc.php"); +} + +// $cal_displayname is $cal_filename with occurrences of "32" replaced with " " +// $cal_filename should always be the filename of the calendar without .ics +if (isset($HTTP_GET_VARS["cal"])) { + $cal_filename = stripslashes(urldecode($HTTP_GET_VARS["cal"])); +} else { + $cal_filename = $default_cal; +} + +$cal_displayname = str_replace("32", " ", $cal_filename); +$cal = urlencode($cal_filename); + +if (!isset($filename)) { + $filename = $calendar_path."/".$cal_filename.".ics"; + if (!file_exists($filename)) { + $dir_handle = @opendir($calendar_path) or die("Unable to open $calendar_path"); + while ($file = readdir($dir_handle)) { + if (substr($file, -4) == ".ics") { + $filename = $calendar_path."/".$file; + break; + } + } + } +} + +?> \ No newline at end of file diff --git a/ical_parser.php b/ical_parser.php deleted file mode 100644 index 74ac113..0000000 --- a/ical_parser.php +++ /dev/null @@ -1,657 +0,0 @@ -", $summary); - $summary = stripslashes($summary); - $description = str_replace("\\n", "
", $description); - $mArray_begin = mktime (0,0,0,1,1,$this_year); - $mArray_end = mktime (0,0,0,1,10,($this_year + 1)); - - if ($start_time != "") { - ereg ("([0-9]{2})([0-9]{2})", $start_time, $time); - ereg ("([0-9]{2})([0-9]{2})", $end_time, $time2); - $length = ($time2[1]*60+$time2[2]) - ($time[1]*60+$time[2]); - - $drawKey = drawEventTimes($start_time, $end_time); - ereg ("([0-9]{2})([0-9]{2})", $drawKey["draw_start"], $time3); - $hour = $time3[1]; - $minute = $time3[2]; - } - - - // Handling of the all day events -// to go back to old allday way, add to this if--> && ($rrule_array == "") - if (($allday_start != "")) { - $start = strtotime("$allday_start"); - $end = strtotime("$allday_end"); - if (($end > $mArray_begin) && ($end < $mArray_end)) { - while ($start != $end) { - $start_date = date("Ymd", $start); - $master_array[($start_date)][("-1")][]= array ("event_text" => "$summary", "description" => $description); - $start = strtotime("+1 day", $start); - } - } - } - - - // Handling of the recurring events, RRULE - // This will be quite a bit of work, thats for sure. - if (is_array($rrule_array)) { - if ($allday_start != "") { - $rrule_array["START_DAY"] = $allday_start; - $rrule_array["END_DAY"] = $allday_end; - $rrule_array["END"] = "end"; - $recur_start = $allday_start; - $start_date = $allday_start; - $diff_allday_days = dayCompare($allday_end, $allday_start); - } else { - $rrule_array["START_DATE"] = $start_date; - $rrule_array["START_TIME"] = $start_time; - $rrule_array["END_TIME"] = $end_time; - $rrule_array["END"] = "end"; - } - //print_r($rrule_array); - foreach ($rrule_array as $key => $val) { - if ($key == "FREQ") { - if ($val == "YEARLY") { - $interval = "yyyy"; - } elseif ($val == "MONTHLY") { - $interval = "m"; - } elseif ($val == "WEEKLY") { - $interval = "ww"; - } elseif ($val == "DAILY") { - $interval = "d"; - } elseif ($val == "HOURLY") { - $interval = "h"; - } elseif ($val == "MINUTELY") { - $interval = "n"; - } elseif ($val == "SECONDLY") { - $interval = "s"; - } - } elseif ($key == "COUNT") { - $count = $val; - - } elseif ($key == "UNTIL") { - $until = ereg_replace("T", "", $val); - ereg ("([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{0,2})([0-9]{0,2})", $until, $regs); - $year = $regs[1]; - $month = $regs[2]; - $day = $regs[3]; - $until = strtotime("$year$month$day"); - - } elseif ($key == "INTERVAL") { - $number = $val; - - } elseif ($key == "BYSECOND") { - $bysecond = $val; - $bysecond = split (",", $bysecond); - - } elseif ($key == "BYMINUTE") { - $byminute = $val; - $byminute = split (",", $byminute); - - } elseif ($key == "BYHOUR") { - $byhour = $val; - $byhour = split (",", $byhour); - - } elseif ($key == "BYDAY") { - $byday = $val; - $byday = split (",", $byday); - - } elseif ($key == "BYMONTHDAY") { - $bymonthday = $val; - $bymonthday = split (",", $bymonthday); - //print_r ($bymonthday); - - } elseif ($key == "BYYEARDAY") { - $byyearday = $val; - $byyearday = split (",", $byyearday); - - } elseif ($key == "BYWEEKNO") { - $byweekno = $val; - $byweekno = split (",", $byweekno); - - } elseif ($key == "BYMONTH") { - $bymonth = $val; - $bymonth = split (",", $bymonth); - - } elseif ($key == "BYSETPOS") { - $bysetpos = $val; - - } elseif ($key == "WKST") { - $wkst = $val; - - } elseif ($key == "END") { -// to go back to old allday way, uncomment this set - /* - if ($allday_start != "") { - - // Since we hit the end of the RRULE array, lets do something. - // Below handles yearly, montly, weekly, daily all-day events. - // $start_of_vevent is the date the recurring event starts. - // $end_of_vevent is the date the recurring event stops. - // $count and $count_to check for the COUNT feature - // $until checks for the UNTIL feature, makes sure we don't recur past it. - - $start_of_vevent = strtotime("$allday_start"); - $end_of_vevent = strtotime("$allday_end"); - $count_to = 0; - if (!$until) $until = $mArray_end; - if ($start_of_vevent < $mArray_end) { - do { - // This steps through each day of a multiple all-day event and adds to master array - // Every all day event should pass through here at least once if its recurring. - $start = $start_of_vevent; - $end = $end_of_vevent; - while ($start != $end) { - $start_date = date("Ymd", $start); - if (($end > $mArray_begin) && ($end < $mArray_end)) { - $master_array[($start_date)][("-1")][]= array ("event_text" => "$summary", "description" => $description); - } - $start = strtotime("+1 day", $start); - } - $start_of_vevent = DateAdd ($interval, $number, $start_of_vevent); - $end_of_vevent = DateAdd ($interval, $number, $end_of_vevent); - $count_to++; - } while (($start_of_vevent < $mArray_end) && ($count != $count_to) && ($start_of_vevent < $until)); - } - - // Let's take care of recurring events that are not all day events - // DAILY and WEEKLY recurrences seem to work fine. Need feedback. - // Known bug, doesn't look at UNTIL or COUNT yet. - } else { - */ - // again, $parse_to_year is set to January 10 of the upcoming year - $parse_to_year_time = mktime(0,0,0,1,10,($this_year + 1)); - $start_date_time = strtotime($start_date); - $this_month_start_time = strtotime("$this_year-$this_month-01"); - - $start_range_time = strtotime("-1 month -2 day", $this_month_start_time); - $end_range_time = strtotime("+2 month +2 day", $this_month_start_time); - - // NOTE: This part not in use for the time being. We are choosing to fill out 3 months time. - // depending on which view we're looking at, we do one month or one week - // one day is more difficult, I think, so I wrapped that into the week. We'll have to - // add another case for "year" once that's added. - /* - if ($current_view == "month") { - $start_range_time = strtotime("$this_year-$this_month-01"); - $end_range_time = strtotime("+1 month +1 week", $start_range_time); - } else { - $start_range_time = strtotime(dateOfWeek($getdate, $week_start_day)); - $end_range_time = strtotime("+1 week", $start_range_time); - } - */ - - // if $until isn't set yet, we set it to the end of our range we're looking at - if (!$until) $until = $end_range_time; - $end_date_time = $until; - - // If the $end_range_time is less than the $start_date_time, or $start_range_time is greater - // than $end_date_time, we may as well forget the whole thing - // It doesn't do us any good to spend time adding data we aren't even looking at - // this will prevent the year view from taking way longer than it needs to - if ($end_range_time >= $start_date_time && $start_range_time <= $end_date_time) { - - // if the beginning of our range is less than the start of the item, we may as well set it equal to it - if ($start_range_time < $start_date_time) $start_range_time = $start_date_time; - if ($end_range_time > $end_date_time) $end_range_time = $end_date_time; - - // initialze the time we will increment - $next_range_time = $start_range_time; - - $count_to = 0; - // start at the $start_range and go until we hit the end of our range. - while (($next_range_time >= $start_range_time) && ($next_range_time <= $end_range_time) && ($count_to != $count)) { - - // handling WEEKLY events here - if ($rrule_array["FREQ"] == "WEEKLY") { - - // use weekCompare to see if we even have this event this week - $diff_weeks = weekCompare(date("Ymd",$next_range_time), $start_date); - if ($diff_weeks < $count) { - if ($week_diff % $number == 0) { - $interval = $number; - // loop through the days on which this event happens - foreach($byday as $day) { - - // use my fancy little function to get the date of each day - $day = two2threeCharDays($day); - $next_date = dateOfWeek(date("Ymd", $next_range_time),$day); - $next_date_time = strtotime($next_date); - - if (($next_date_time > $start_date_time) && ($next_date_time <= $end_date_time) && ($count_to != $count) && !in_array($next_date, $except_dates)) { - // add it to the array if it passes inspection, it allows the first time to be - // written by the master data writer (hence the > instead of >=) otherwise we can special case these - // before, the first one would get entered twice and show up twice - // $next_date can fall up to a week behind $next_range_time because of how dateOfWeek works - // so we have to check this again. It uses $except_dates so it doesn't add to $master_array - // on days that have been deleted by the user - if ($allday_start != "") { - - $start_time = $next_date_time; - $end_time = strtotime("+$diff_allday_days days", $next_date_time); - while ($start_time < $end_time) { - $start_date2 = date("Ymd", $start_time); - $master_array[($start_date2)][("-1")][]= array ("event_text" => "$summary", "description" => $description); - $start_time = strtotime("+1 day", $start_time); - } - } else { -// check for overlapping events - $nbrOfOverlaps = checkOverlap(); -// writes to $master array here - $master_array[($next_date)][($hour.$minute)][] = array ("event_start" => $start_time, "event_text" => $summary, "event_end" => $end_time, "event_length" => $length, "event_overlap" => $nbrOfOverlaps, "description" => $description); - } - } - } - } else { - $interval = 1; - } - $next_range_time = strtotime("+$interval week", $next_range_time); - } else { - // end the loop because we aren't going to write this event anyway - $count_to = $count; - } - - - // handling DAILY events here - } elseif ($rrule_array["FREQ"] == "DAILY") { - - // use dayCompare to see if we even have this event this day - $diff_days = dayCompare(date("Ymd",$next_range_time), $start_date); - if ($diff_days < $count) { - if ($diff_days % $number == 0) { - $interval = $number; - $next_date = date("Ymd", $next_range_time); - $next_date_time = strtotime($next_date); - - if (($next_date_time > $start_date_time) && ($next_date_time <= $end_date_time) && ($count_to != $count) && !in_array($next_date, $except_dates)) { - if ($allday_start != "") { - - $start_time = $next_date_time; - $end_time = strtotime("+$diff_allday_days days", $next_date_time); - while ($start_time < $end_time) { - $start_date2 = date("Ymd", $start_time); - $master_array[($start_date2)][("-1")][]= array ("event_text" => "$summary", "description" => $description); - $start_time = strtotime("+1 day", $start_time); - } - } else { -// check for overlapping events - $nbrOfOverlaps = checkOverlap(); -// writes to $master array here - $master_array[($next_date)][($hour.$minute)][] = array ("event_start" => $start_time, "event_text" => $summary, "event_end" => $end_time, "event_length" => $length, "event_overlap" => $nbrOfOverlaps, "description" => $description); - } - } - } else { - $interval = 1; - } - $next_range_time = strtotime("+$interval day", $next_range_time); - } else { - // end the loop because we aren't going to write this event anyway - $count_to = $count; - } - - - // handling MONTHLY events here - } elseif ($rrule_array["FREQ"] == "MONTHLY") { - $next_range_time = strtotime(date("Y-m-01", $next_range_time)); - // use monthCompare to see if we even have this event this month - - $diff_months = monthCompare(date("Ymd",$next_range_time), $start_date); - if ($diff_months < $count) { - if ($diff_months % $number == 0) { - $interval = $number; - - // month has two cases, either $bymonthday or $byday - if (is_array($bymonthday)) { - - // loop through the days on which this event happens - foreach($bymonthday as $day) { - if ($day != "0") { - $next_date_time = strtotime(date("Y-m-",$next_range_time).$day); - $next_date = date("Ymd", $next_date_time); - if (($next_date_time > $start_date_time) && ($next_date_time <= $end_date_time) && ($count_to != $count) && !in_array($next_date, $except_dates)) { - if ($allday_start != "") { - $start_time = $next_date_time; - $end_time = strtotime("+$diff_allday_days days", $next_date_time); - while ($start_time < $end_time) { - $start_date2 = date("Ymd", $start_time); - $master_array[($start_date2)][("-1")][]= array ("event_text" => "$summary", "description" => $description); - $start_time = strtotime("+1 day", $start_time); - } - } else { -// check for overlapping events - $nbrOfOverlaps = checkOverlap(); -// writes to $master array here - $master_array[($next_date)][($hour.$minute)][] = array ("event_start" => $start_time, "event_text" => $summary, "event_end" => $end_time, "event_length" => $length, "event_overlap" => $nbrOfOverlaps, "description" => $description); - } - } - } - } - - // our other case - } else { - // loop through the days on which this event happens - foreach($byday as $day) { - ereg ("([0-9]{1})([A-Z]{2})", $day, $byday_arr); - $nth = $byday_arr[1]-1; - $on_day = two2threeCharDays($byday_arr[2]); - $next_date_time = strtotime("$on_day +$nth week", $next_range_time); - $next_date = date("Ymd", $next_date_time); - if (($next_date_time > $start_date_time) && ($next_date_time <= $end_date_time) && ($count_to != $count) && !in_array($next_date, $except_dates)) { - - if ($allday_start != "") { - - $start_time = $next_date_time; - $end_time = strtotime("+$diff_allday_days days", $next_date_time); - while ($start_time < $end_time) { - $start_date2 = date("Ymd", $start_time); - $master_array[($start_date2)][("-1")][]= array ("event_text" => "$summary", "description" => $description); - $start_time = strtotime("+1 day", $start_time); - } - } else { -// check for overlapping events - $nbrOfOverlaps = checkOverlap(); -// writes to $master array here - $master_array[($next_date)][($hour.$minute)][] = array ("event_start" => $start_time, "event_text" => $summary, "event_end" => $end_time, "event_length" => $length, "event_overlap" => $nbrOfOverlaps, "description" => $description); - } - } - } - } - } else { - $interval = 1; - } - $next_range_time = strtotime("+$interval month", $next_range_time); - } else { - // end the loop because we aren't going to write this event anyway - $count_to = $count; - } - - // handle yearly events - } elseif ($rrule_array["FREQ"] == "YEARLY") { - // use yearCompare to see if we even have this event this year - $the_month_day = date("d", $start_date_time); - $diff_years = yearCompare(date("Ymd",$next_range_time), $start_date); - if ($diff_years < $count) { - if ($diff_years % $number == 0) { - foreach($bymonth as $month) { - if (is_array($byday)) { - $next_range_time = strtotime("$this_year-$month-01"); - foreach($byday as $day) { - ereg ("([0-9]{1})([A-Z]{2})", $day, $byday_arr); - $nth = $byday_arr[1]-1; - $on_day = two2threeCharDays($byday_arr[2]); - $next_date_time = strtotime("$on_day +$nth week", $next_range_time); - - } - } else { - $next_date_time = strtotime("$this_year-$month-$the_month_day", $next_range_time); - } - if (($next_date_time > $start_date_time) && ($next_date_time <= $end_date_time) && ($count_to != $count) && !in_array($next_date, $except_dates)) { - if ($allday_start != "") { - - $start_time = $next_date_time; - $end_time = strtotime("+$diff_allday_days days", $next_date_time); - while ($start_time < $end_time) { - $start_date2 = date("Ymd", $start_time); - $master_array[($start_date2)][("-1")][]= array ("event_text" => "$summary", "description" => $description); - $start_time = strtotime("+1 day", $start_time); - } - } else { -// check for overlapping events - $nbrOfOverlaps = checkOverlap(); -// writes to $master array here - $master_array[($next_date)][($hour.$minute)][] = array ("event_start" => $start_time, "event_text" => $summary, "event_end" => $end_time, "event_length" => $length, "event_overlap" => $nbrOfOverlaps, "description" => $description); - } - } - } - } else { - $interval = 1; - } - $next_range_time = strtotime("+$interval year", $next_range_time); - } else { - // end the loop because we aren't going to write this event anyway - $count_to = $count; - } - - // anything else we need to end the loop - } else { - $next_range_time = $end_range_time + 100; - $count_to = $count; - } - } -// to go back to old allday way, uncomment this bracket - // } - } - } - } - } - - // Let's write all the data to the master array - if (($start_time != "") && ($allday_start == "")) { -// check for overlapping events - $nbrOfOverlaps = checkOverlap(); - -// writes to $master array here - $master_array[($start_date)][($hour.$minute)][] = array ("event_start" => $start_time, "event_text" => $summary, "event_end" => $end_time, "event_length" => $length, "event_overlap" => $nbrOfOverlaps, "description" => $description); - } - - - - - - } else { - - $field = ""; - $data = ""; - - sscanf($line, "%[^:]:%[^\n]", &$field, &$data); - - 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_date = $year . $month . $day; - $end_time = $hour . $minute; - - } elseif (strstr($field, "EXDATE;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]; - - $except_dates[] = $year . $month . $day; - $except_times[] = $hour . $minute; - - } elseif (strstr($field, "SUMMARY")) { - $summary = $data; - - } elseif (strstr($field, "DESCRIPTION")) { - $description = $data; - - } elseif (strstr($field, "X-WR-CALNAME")) { - $calendar_name = $data; - - } elseif (strstr($field, "DTSTART;VALUE=DATE")) { - $allday_start = $data; - // echo "$allday_start"; - - } elseif (strstr($field, "DTEND;VALUE=DATE")) { - $allday_end = $data; - - } elseif (strstr($field, "DURATION")) { - - if (($first_duration = TRUE) && (!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 ($duration[2] = "W") { - $weeks = $duration[1]; - } else { - $days = $duration[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); - $first_duration = FALSE; - } - - } elseif (strstr($field, "RRULE")) { - // $data = "RRULE:FREQ=YEARLY;INTERVAL=2;BYMONTH=1;BYDAY=SU;BYHOUR=8,9;BYMINUTE=30"; - $data = ereg_replace ("RRULE:", "", $data); - $rrule = split (";", $data); - foreach ($rrule as $recur) { - ereg ("(.*)=(.*)", $recur, $regs); - $rrule_array[$regs[1]] = $regs[2]; - } - } elseif (strstr($field, "ATTENDEE")) { - $attendee = $data; - // echo "$attendee"; - - } - } -} - -// Sort the array by absolute date. -if (is_array($master_array)) { - ksort($master_array); - reset($master_array); - - // sort the sub (day) arrays so the times are in order - foreach (array_keys($master_array) as $k) { - if (is_array($master_array[$k])) { - ksort($master_array[$k]); - reset($master_array[$k]); - } - } -} - - - -// Store information in the session -/*if ($use_sessions == "yes") { - session_start(); - session_register( "aArray", "aYear", "aLanguage", "aCalendar" ); - $aArray = $master_array; - $aYear = $this_year; - $aLanguage = $language; - $aCalendar = $cal; -}*/ - - -// End the session -//} - -//If you want to see the values in the arrays, uncomment below. -//print "
";
-//print_r($master_array);
-//print_r($overlap_array);
-//print_r($day_array);
-//print_r($rrule);			
-//print "
"; - - -?> \ No newline at end of file diff --git a/index.php b/index.php index 1e7975a..177c4e3 100644 --- a/index.php +++ b/index.php @@ -1,6 +1,6 @@ = "4.2.0") - - { - extract($HTTP_GET_VARS); - extract($HTTP_POST_VARS); - } - -include('./config.inc.php'); - -// subscribe link prefix, doesn't need to be user configureable -$fullpath = 'webcal://'.$HTTP_SERVER_VARS['SERVER_NAME'].dirname($HTTP_SERVER_VARS['PHP_SELF']).'/'.$calendar_path.'/'; - - -// language support -$language = strtolower($language); -$lang_file = "./languages/$language.inc.php"; - -if (file_exists($lang_file)) { - include($lang_file); -} else { -// Not sure if we should print this warning or not. It would inform the user -// why the language isn't working. - print "File \"$lang_file\" does not exist, defaulting to English

"; - include("./languages/english.inc.php"); -} - -// $cal_displayname is $cal_filename with occurrences of "32" replaced with " " -// $cal_filename should always be the filename of the calendar without .ics -if (isset($HTTP_GET_VARS["cal"])) { - $cal_filename = stripslashes(urldecode($HTTP_GET_VARS["cal"])); -} else { - $cal_filename = $default_cal; -} - -$cal_displayname = str_replace("32", " ", $cal_filename); -$cal = urlencode($cal_filename); - -if (!isset($filename)) { - $filename = $calendar_path."/".$cal_filename.".ics"; - if (!file_exists($filename)) { - $dir_handle = @opendir($calendar_path) or die("Unable to open $calendar_path"); - while ($file = readdir($dir_handle)) { - if (substr($file, -4) == ".ics") { - $filename = $calendar_path."/".$file; - break; - } - } - } -} - -?> \ No newline at end of file diff --git a/month.php b/month.php index cc33e26..3a5fdd4 100644 --- a/month.php +++ b/month.php @@ -1,6 +1,6 @@