From: <ji...@us...> - 2008-12-13 23:42:37
|
Update of /cvsroot/phpicalendar/phpicalendar/functions/parse In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv11617/functions/parse Modified Files: end_vevent.php parse_tzs.php Log Message: debug rrules; fix cookie injection vuln Index: end_vevent.php =================================================================== RCS file: /cvsroot/phpicalendar/phpicalendar/functions/parse/end_vevent.php,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** end_vevent.php 11 Dec 2008 23:48:39 -0000 1.1 --- end_vevent.php 13 Dec 2008 23:42:31 -0000 1.2 *************** *** 3,7 **** What happens in this file: ! 1. Initialization 2. */ --- 3,7 ---- What happens in this file: ! 1. Initialization: add information not present by default 2. */ *************** *** 90,94 **** $rrule_array['START_DATE'] = $start_date; $rrule_array['UNTIL'] = $start_date; ! $rrule_array['END'] = 'end'; } --- 90,94 ---- $rrule_array['START_DATE'] = $start_date; $rrule_array['UNTIL'] = $start_date; ! # $rrule_array['END'] = 'end'; } *************** *** 99,103 **** $rrule_array['START_DAY'] = $allday_start; # $rrule_array['END_DAY'] = $allday_end; # this doesn't seem to be used anywhere. ! $rrule_array['END'] = 'end'; $recur_start = $allday_start; $start_date = $allday_start; --- 99,103 ---- $rrule_array['START_DAY'] = $allday_start; # $rrule_array['END_DAY'] = $allday_end; # this doesn't seem to be used anywhere. ! # $rrule_array['END'] = 'end'; $recur_start = $allday_start; $start_date = $allday_start; *************** *** 111,115 **** $rrule_array['START_TIME'] = $start_time; $rrule_array['END_TIME'] = $end_time; ! $rrule_array['END'] = 'end'; } --- 111,115 ---- $rrule_array['START_TIME'] = $start_time; $rrule_array['END_TIME'] = $end_time; ! # $rrule_array['END'] = 'end'; } *************** *** 130,134 **** --- 130,137 ---- } + $freq_type = 'year'; + $interval = 1; + # Load $rrule_array foreach ($rrule_array as $key => $val) { switch($key) { *************** *** 160,165 **** case 'INTERVAL': if ($val > 0){ ! $number = $val; ! $recur_array[($start_date)][($hour.$minute)][$uid]['recur'][$key] = $number; } break; --- 163,168 ---- case 'INTERVAL': if ($val > 0){ ! $interval = $val; ! $recur_array[($start_date)][($hour.$minute)][$uid]['recur'][$key] = $interval; } break; *************** *** 212,616 **** $recur_array[($start_date)][($hour.$minute)][$uid]['recur'][$key] = $wkst; break; ! case 'END': ! ! $recur = $recur_array[($start_date)][($hour.$minute)][$uid]['recur']; ! ! // Modify the COUNT based on BYDAY ! if ((isset ($byday) && is_array($byday)) && (isset($count))) { ! $blah = sizeof($byday); ! $count = ($count / $blah); ! unset ($blah); ! } ! if (!isset($number)) $number = 1; ! // if $until isn't set yet, we set it to the end of our range we're looking at ! ! if (!isset($until)) $until = $end_range_time; ! if (!isset($abs_until)) $abs_until = date('YmdHis', $end_range_time); ! $end_date_time = $until; ! $start_range_time_tmp = $start_range_time; ! $end_range_time_tmp = $end_range_time; ! ! // 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_tmp >= $start_date_time && $start_range_time_tmp <= $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_tmp < $start_date_time){ ! $start_range_time_tmp = $start_date_time; ! } ! if ($end_range_time_tmp > $end_date_time) $end_range_time_tmp = $end_date_time; ! ! // initialize the time we will increment ! $next_range_time = $start_range_time_tmp; ! ! // FIXME: This is a hack to fix repetitions with $interval > 1 ! if ($count > 1 && $number > 1) $count = 1 + ($count - 1) * $number; ! ! $count_to = 0; ! // start at the $start_range and go until we hit the end of our range. ! if(!isset($wkst)) $wkst='SU'; ! $wkst3char = two2threeCharDays($wkst); ! # set first instance if it's in range ! if ($start_unixtime < $mArray_end && $end_unixtime > $mArray_begin){ ! $recur_data[] = $start_unixtime; ! } ! while (($next_range_time >= $start_range_time_tmp) && ($next_range_time <= $end_range_time_tmp) && ($count_to != $count)) { ! $func = $freq_type.'Compare'; ! $diff = $func(date('Ymd',$next_range_time), $start_date); ! if ($diff < $count) { ! if ($diff % $number == 0) { ! $interval = $number; ! switch ($rrule_array['FREQ']) { ! case 'DAILY': ! $next_date_time = $next_range_time; ! $recur_data[] = $next_date_time; ! break; ! case 'WEEKLY': ! // Populate $byday with the default day if it's not set. ! if (!isset($byday)) { ! $byday[] = strtoupper(substr(date('D', $start_date_time), 0, 2)); ! } ! if (is_array($byday)) { ! foreach($byday as $day) { ! $day = two2threeCharDays($day); ! #need to find the first day of the appropriate week. ! #dateOfweek uses weekstartday as a global variable. This has to be changed to $wkst, ! #but then needs to be reset for other functions ! $week_start_day_tmp = $week_start_day; ! $week_start_day = $wkst3char; ! ! $the_sunday = dateOfWeek(date("Ymd",$next_range_time), $wkst3char); ! $next_date_time = strtotime($day,strtotime($the_sunday)) + (12 * 60 * 60); ! $week_start_day = $week_start_day_tmp; #see above reset to global value ! ! #reset $next_range_time to first instance in this week. ! if ($next_date_time < $next_range_time){ ! $next_range_time = $next_date_time; ! } ! // Since this renders events from $next_range_time to $next_range_time + 1 week, I need to handle intervals ! // as well. This checks to see if $next_date_time is after $day_start (i.e., "next week"), and thus ! // if we need to add $interval weeks to $next_date_time. ! if ($next_date_time > strtotime($week_start_day, $next_range_time) && $interval > 1) { ! # $next_date_time = strtotime('+'.($interval - 1).' '.$freq_type, $next_date_time); ! } ! $recur_data[] = $next_date_time; ! } ! } ! break; ! case 'MONTHLY': ! if (empty($bymonth)) $bymonth = array(1,2,3,4,5,6,7,8,9,10,11,12); ! $next_range_time = strtotime(date('Y-m-01', $next_range_time)); ! $next_date_time = $next_date_time; ! if (isset($bysetpos)){ ! /* bysetpos code from dustinbutler ! start on day 1 or last day. ! if day matches any BYDAY the count is incremented. ! SETPOS = 4, need 4th match ! SETPOS = -1, need 1st match ! */ ! $year = date('Y', $next_range_time); ! $month = date('m', $next_range_time); ! if ($bysetpos > 0) { ! $next_day = '+1 day'; ! $day = 1; ! } else { ! $next_day = '-1 day'; ! $day = $totalDays[$month]; ! } ! $day = mktime(0, 0, 0, $month, $day, $year); ! $countMatch = 0; ! while ($countMatch != abs($bysetpos)) { ! /* Does this day match a BYDAY value? */ ! $thisDay = $day; ! $textDay = strtoupper(substr(date('D', $thisDay), 0, 2)); ! if (in_array($textDay, $byday)) { ! $countMatch++; ! } ! $day = strtotime($next_day, $thisDay); ! } ! $recur_data[] = $thisDay; ! }elseif ((isset($bymonthday)) && (!isset($byday))) { ! foreach($bymonthday as $day) { ! if ($day < 0) $day = ((date('t', $next_range_time)) + ($day)) + 1; ! $year = date('Y', $next_range_time); ! $month = date('m', $next_range_time); ! if (checkdate($month,$day,$year)) { ! $next_date_time = mktime(0,0,0,$month,$day,$year); ! $recur_data[] = $next_date_time; ! } ! } ! } elseif (is_array($byday)) { ! foreach($byday as $day) { ! ereg ('([-\+]{0,1})?([0-9]{1})?([A-Z]{2})', $day, $byday_arr); ! //Added for 2.0 when no modifier is set ! if ($byday_arr[2] != '') { ! $nth = $byday_arr[2]-1; ! } else { ! $nth = 0; ! } ! $on_day = two2threeCharDays($byday_arr[3]); ! $on_day_num = two2threeCharDays($byday_arr[3],false); ! if ((isset($byday_arr[1])) && ($byday_arr[1] == '-')) { ! $last_day_tmp = date('t',$next_range_time); ! $next_range_time = strtotime(date('Y-m-'.$last_day_tmp, $next_range_time)); ! $last_tmp = (date('w',$next_range_time) == $on_day_num) ? '' : 'last '; ! $next_date_time = strtotime($last_tmp.$on_day, $next_range_time) - ($nth * 604800); ! $month = date('m', $next_date_time); ! if (in_array($month, $bymonth)) { ! $recur_data[] = $next_date_time; ! } ! #reset next_range_time to start of month ! $next_range_time = strtotime(date('Y-m-'.'1', $next_range_time)); ! } elseif (isset($bymonthday) && (!empty($bymonthday))) { ! // This supports MONTHLY where BYDAY and BYMONTH are both set ! foreach($bymonthday as $day) { ! $year = date('Y', $next_range_time); ! $month = date('m', $next_range_time); ! if (checkdate($month,$day,$year)) { ! $next_date_time = mktime(0,0,0,$month,$day,$year); ! $daday = strtolower(strftime("%a", $next_date_time)); ! if ($daday == $on_day && in_array($month, $bymonth)) { ! $recur_data[] = $next_date_time; ! } ! } ! } ! } elseif ((isset($byday_arr[1])) && ($byday_arr[1] != '-')) { ! $next_date_time = strtotime($on_day, strtotime($on_day, $next_range_time) + $nth * 604800); ! $month = date('m', $next_date_time); ! if (in_array($month, $bymonth)) { ! if (isset($next_date_time) && $next_date_time != '') $recur_data[] = $next_date_time; ! } ! } ! $next_date = date('Ymd', $next_date_time); ! } ! } ! break; ! case 'YEARLY': ! if ((!isset($bymonth)) || (sizeof($bymonth) == 0)) { ! $m = date('m', $start_date_time); ! $bymonth = array("$m"); ! } ! foreach($bymonth as $month) { ! // Make sure the month & year used is within the start/end_range. ! if ($month < date('m', $next_range_time)) { ! $year = date('Y', $next_range_time); ! } else { ! $year = date('Y', $next_range_time); ! } ! if (isset($bysetpos)){ ! /* bysetpos code from dustinbutler ! start on day 1 or last day. ! if day matches any BYDAY the count is incremented. ! SETPOS = 4, need 4th match ! SETPOS = -1, need 1st match ! */ ! if ($bysetpos > 0) { ! $next_day = '+1 day'; ! $day = 1; ! } else { ! $next_day = '-1 day'; ! $day = date("t",$month); ! } ! $day = mktime(12, 0, 0, $month, $day, $year); ! $countMatch = 0; ! while ($countMatch != abs($bysetpos)) { ! /* Does this day match a BYDAY value? */ ! $thisDay = $day; ! $textDay = strtoupper(substr(date('D', $thisDay), 0, 2)); ! if (in_array($textDay, $byday)) { ! $countMatch++; ! } ! $day = strtotime($next_day, $thisDay); ! } ! $recur_data[] = $thisDay; ! } ! if ((isset($byday)) && (is_array($byday))) { ! $checkdate_time = mktime(0,0,0,$month,1,$year); ! foreach($byday as $day) { ! ereg ('([-\+]{0,1})?([0-9]{1})?([A-Z]{2})', $day, $byday_arr); ! if ($byday_arr[2] != '') { ! $nth = $byday_arr[2]-1; ! } else { ! $nth = 0; ! } ! $on_day = two2threeCharDays($byday_arr[3]); ! $on_day_num = two2threeCharDays($byday_arr[3],false); ! if ($byday_arr[1] == '-') { ! $last_day_tmp = date('t',$checkdate_time); ! $checkdate_time = strtotime(date('Y-m-'.$last_day_tmp, $checkdate_time)); ! $last_tmp = (date('w',$checkdate_time) == $on_day_num) ? '' : 'last '; ! $next_date_time = strtotime($last_tmp.$on_day.' -'.$nth.' week', $checkdate_time); ! } else { ! $next_date_time = strtotime($on_day.' +'.$nth.' week', $checkdate_time); ! } ! } ! } else { ! $day = date('d', $start_date_time); ! $next_date_time = mktime(0,0,0,$month,$day,$year+1); ! //echo date('Ymd',$next_date_time).$summary.'<br>'; ! } ! if (isset($next_date_time) && $next_date_time != '') $recur_data[] = $next_date_time; ! } ! if (isset($byyearday)) { ! foreach ($byyearday as $yearday) { ! ereg ('([-\+]{0,1})?([0-9]{1,3})', $yearday, $byyearday_arr); ! if ($byyearday_arr[1] == '-') { ! $ydtime = mktime(0,0,0,12,31,$this_year); ! $yearnum = $byyearday_arr[2] - 1; ! $next_date_time = strtotime('-'.$yearnum.' days', $ydtime); ! } else { ! $ydtime = mktime(0,0,0,1,1,$this_year); ! $yearnum = $byyearday_arr[2] - 1; ! $next_date_time = strtotime('+'.$yearnum.' days', $ydtime); ! } ! if (isset($next_date_time) && $next_date_time != '') $recur_data[] = $next_date_time; ! } ! } ! break; ! default: ! // anything else we need to end the loop ! $next_range_time = $end_range_time_tmp + 100; ! $count_to = $count; } } else { ! $interval = 1; ! } ! $next_range_time = strtotime('+'.$interval.' '.$freq_type, $next_range_time); ! } else { ! // end the loop because we aren't going to write this event anyway ! $count_to = $count; ! } ! // use the same code to write the data instead of always changing it 5 times ! if (isset($recur_data) && is_array($recur_data)) { ! $recur_data_hour = @substr($start_time,0,2); ! $recur_data_minute = @substr($start_time,2,2); ! foreach($recur_data as $recur_data_time) { ! $recur_data_year = date('Y', $recur_data_time); ! $recur_data_month = date('m', $recur_data_time); ! $recur_data_day = date('d', $recur_data_time); ! $recur_data_date = $recur_data_year.$recur_data_month.$recur_data_day; ! if (($recur_data_time >= $start_date_time) && ($recur_data_time <= $end_date_time) && ($count_to != $count) && !in_array($recur_data_date, $except_dates)) { ! if (isset($allday_start) && $allday_start != '') { ! $start_time2 = $recur_data_time; ! $end_time2 = strtotime('+'.$diff_allday_days.' days', $recur_data_time); ! while ($start_time2 < $end_time2) { ! $start_date2 = date('Ymd', $start_time2); ! $master_array[($start_date2)][('-1')][$uid] = array ( ! 'event_text' => $summary, ! 'description' => $description, ! 'location' => $location, ! 'organizer' => serialize($organizer), ! 'attendee' => serialize($attendee), ! 'calnumber' => $calnumber, ! 'calname' => $actual_calname, ! 'url' => $url, ! 'status' => $status, ! 'class' => $class, ! 'recur' => $recur ); ! $start_time2 = strtotime('+1 day', $start_time2); ! } ! } else { ! $start_unixtime_tmp = mktime($recur_data_hour,$recur_data_minute,0,$recur_data_month,$recur_data_day,$recur_data_year); ! $end_unixtime_tmp = $start_unixtime_tmp + $length; ! if (($end_time >= $bleed_time) && ($bleed_check == '-1')) { ! $start_tmp = strtotime(date('Ymd',$start_unixtime_tmp)); ! $end_date_tmp = date('Ymd',$end_unixtime_tmp); ! while ($start_tmp < $end_unixtime_tmp) { ! $start_date_tmp = date('Ymd',$start_tmp); ! if ($start_date_tmp == $recur_data_year.$recur_data_month.$recur_data_day) { ! $time_tmp = $hour.$minute; ! $start_time_tmp = $start_time; ! } else { ! $time_tmp = '0000'; ! $start_time_tmp = '0000'; ! } ! if ($start_date_tmp == $end_date_tmp) { ! $end_time_tmp = $end_time; ! } else { ! $end_time_tmp = '2400'; ! $display_end_tmp = $end_time; ! } ! ! // Let's double check the until to not write past it ! $until_check = $start_date_tmp.$time_tmp.'00'; ! if ($abs_until > $until_check) { ! $master_array[$start_date_tmp][$time_tmp][$uid] = array ( ! 'event_start' => $start_time_tmp, ! 'event_end' => $end_time_tmp, ! 'start_unixtime' => $start_unixtime_tmp, ! 'end_unixtime' => $end_unixtime_tmp, ! 'event_text' => $summary, ! 'event_length' => $length, ! 'event_overlap' => 0, ! 'description' => $description, ! 'status' => $status, ! 'class' => $class, ! 'spans_day' => true, ! 'location' => $location, ! 'organizer' => serialize($organizer), ! 'attendee' => serialize($attendee), ! 'calnumber' => $calnumber, ! 'calname' => $actual_calname, ! 'url' => $url, ! 'recur' => $recur); ! if (isset($display_end_tmp)){ ! $master_array[$start_date_tmp][$time_tmp][$uid]['display_end'] = $display_end_tmp; ! } ! checkOverlap($start_date_tmp, $time_tmp, $uid); } - $start_tmp = strtotime('+1 day',$start_tmp); } } else { ! if ($bleed_check == '-1') { ! $display_end_tmp = $end_time; ! $end_time_tmp1 = '2400'; ! ! } ! if (!isset($end_time_tmp1)) $end_time_tmp1 = $end_time; ! ! // Let's double check the until to not write past it ! $until_check = $recur_data_date.$hour.$minute.'00'; ! if ($abs_until > $until_check) { ! $master_array[($recur_data_date)][($hour.$minute)][$uid] = array ( ! 'event_start' => $start_time, ! 'event_end' => $end_time_tmp1, ! 'start_unixtime' => $start_unixtime_tmp, ! 'end_unixtime' => $end_unixtime_tmp, ! 'event_text' => $summary, ! 'event_length' => $length, ! 'event_overlap' => 0, ! 'description' => $description, ! 'status' => $status, ! 'class' => $class, ! 'spans_day' => false, ! 'location' => $location, ! 'organizer' => serialize($organizer), ! 'attendee' => serialize($attendee), ! 'calnumber' => $calnumber, ! 'calname' => $actual_calname, ! 'url' => $url, ! 'recur' => $recur); ! if (isset($display_end_tmp)){ ! $master_array[($recur_data_date)][($hour.$minute)][$uid]['display_end'] = $display_end_tmp; ! } ! checkOverlap($recur_data_date, ($hour.$minute), $uid); ! } } } } } } ! } #end while loop ! } # end if time compare ! unset($recur_data); ! } # end switch $key (rrule type) ! } # end foreach rrule --- 215,566 ---- $recur_array[($start_date)][($hour.$minute)][$uid]['recur'][$key] = $wkst; break; ! } ! } ! /* ! Load $recur_array ! $recur_array is an array of unix times for instances of an event. This code handles repeats. ! Note that dates with exceptions are counted as instances. ! RDATE is currently not supported ! */ ! # $recur is the recurrence info that goes into the master array for this VEVENT ! $recur = $recur_array[($start_date)][($hour.$minute)][$uid]['recur']; ! // if $until isn't set yet, we set it to the end of our range we're looking at ! if (!isset($until)) $until = $end_range_time; ! if (!isset($abs_until)) $abs_until = date('YmdHis', $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_tmp <= $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; ! // initialize the time we will increment ! $next_range_time = $start_range_time; ! ! // start at the $start_range and go until we hit the end of our range. ! if(!isset($wkst)) $wkst='SU'; ! $wkst3char = two2threeCharDays($wkst); ! # set first instance if it's in range ! $recur_data = array(); ! if ($start_unixtime < $mArray_end && $end_unixtime > $mArray_begin){ ! $recur_data[] = $start_unixtime; ! } ! /* ! The while loop below increments $next_range_time by $freq type. For the larger freq types, there is only ! one $next_range_time per repeat, but the BYXXX rules may write more than one event in that repeat cycle ! $next_date_time handles those instances within a $freq_type ! */ ! #echo "<br><br>$summary<br>next range time:".date("Ymd his",$next_range_time)." <br>start range time ".date("Ymd his",$start_range_time)." <br>end range time ".date("Ymd his",$end_range_time); ! while (($next_range_time >= $start_range_time) && ($next_range_time <= $end_range_time)) { ! # pick the right compare function from date_functions.php ! # $diff is the number of occurrences between start_date and next_range_time ! $func = $freq_type.'Compare'; ! $diff = $func(date('Ymd',$next_range_time), $start_date); ! $rcount = $diff; ! if(count($byday) > 1) $rcount = $diff * count($byday); ! if ($rcount < $count && $diff % $interval == 0) { ! $year = date('Y', $next_range_time); ! $month = date('m', $next_range_time); ! switch ($rrule_array['FREQ']) { ! case 'DAILY': ! $recur_data[] = $next_range_time; ! break; ! case 'WEEKLY': ! // Populate $byday with the default day if it's not set. ! if (!isset($byday)) $byday[] = strtoupper(substr(date('D', $start_date_time), 0, 2)); ! $the_sunday = dateOfWeek(date("Ymd",$next_range_time), $wkst3char); ! foreach($byday as $key=>$day) { ! $day = two2threeCharDays($day); ! #need to find the first day of the appropriate week. ! if ($key == 0){ ! $next_date_time = strtotime("next $day",strtotime($the_sunday)) + (12 * 60 * 60); ! }else{ ! $next_date_time = strtotime("next $day",$next_date_time) + (12 * 60 * 60); ! } ! $recur_data[] = $next_date_time; #echo "<br>$key $day ".strtotime("Ymd his", $next_date_time); ! } ! break; ! case 'MONTHLY': ! if (empty($bymonth)) $bymonth = array(1,2,3,4,5,6,7,8,9,10,11,12); ! if (!empty($bysetpos)){ ! /* bysetpos code from dustinbutler ! start on day 1 or last day. ! if day matches any BYDAY the count is incremented. ! SETPOS = 4, need 4th match ! SETPOS = -1, need 1st match ! */ ! if ($bysetpos > 0) { ! $next_day = '+1 day'; ! $day = 1; ! } else { ! $next_day = '-1 day'; ! $day = $totalDays[$month]; ! } ! $day = mktime(0, 0, 0, $month, $day, $year); ! $countMatch = 0; ! while ($countMatch != abs($bysetpos)) { ! /* Does this day match a BYDAY value? */ ! $thisDay = $day; ! $textDay = strtoupper(substr(date('D', $thisDay), 0, 2)); ! if (in_array($textDay, $byday)) { ! $countMatch++; ! } ! $day = strtotime($next_day, $thisDay); ! } ! if(in_array(date("m", $next_date_time), $bymonth)) $recur_data[] = $next_date_time; ! }elseif (count($bymonthday) > 0 && empty($byday)) { ! foreach($bymonthday as $day) { ! if ($day < 0) $day = ((date('t', $next_range_time)) + ($day)) + 1; ! if (checkdate($month,$day,$year)) { ! $next_date_time = mktime(0,0,0,$month,$day,$year); ! if(in_array(date("m", $next_date_time), $bymonth)) $recur_data[] = $next_date_time; ! } } } else { ! foreach($byday as $day) { ! /* set $byday_arr ! [0] => byday string, e.g. 4TH ! [1] => sign/modifier ! [2] => 4 number ! [3] => TH day abbr ! */ ! ereg ('([-\+]{0,1})?([0-9]{1})?([A-Z]{2})', $day, $byday_arr); ! $on_day = two2threeCharDays($byday_arr[3]); ! $next_date_time = strtotime($byday_arr[1].$byday_arr[2].$on_day, $next_range_time); ! if(empty($bymonthday) && in_array(date("m", $next_date_time), $bymonth)) $recur_data[] = $next_date_time; ! if (isset($bymonthday) && (!empty($bymonthday))) { ! // This supports MONTHLY where BYDAY and BYMONTH are both set ! foreach($bymonthday as $day) { ! if (checkdate($month,$day,$year)) { ! $next_date_time = mktime(0,0,0,$month,$day,$year); ! $daday = strtolower(strftime("%a", $next_date_time)); ! if ($daday == $on_day && in_array($month, $bymonth)) { ! if(in_array(date("m", $next_date_time), $bymonth)) $recur_data[] = $next_date_time; } } + } + } + } # end foreach $byday + } + break; + case 'YEARLY': + if ((!isset($bymonth)) || (sizeof($bymonth) == 0)) $bymonth = array(date('m', $start_date_time)); + foreach($bymonth as $month) { + if (isset($bysetpos)){ + /* bysetpos code from dustinbutler + start on day 1 or last day. + if day matches any BYDAY the count is incremented. + SETPOS = 4, need 4th match + SETPOS = -1, need 1st match + */ + if ($bysetpos > 0) { + $next_day = '+1 day'; + $day = 1; + } else { + $next_day = '-1 day'; + $day = date("t",$month); + } + $day = mktime(12, 0, 0, $month, $day, $year); + $countMatch = 0; + while ($countMatch != abs($bysetpos)) { + /* Does this day match a BYDAY value? */ + $thisDay = $day; + $textDay = strtoupper(substr(date('D', $thisDay), 0, 2)); + if (in_array($textDay, $byday)) { + $countMatch++; + } + $day = strtotime($next_day, $thisDay); + } + $recur_data[] = $thisDay; + } + if ((isset($byday)) && (is_array($byday))) { + $checkdate_time = mktime(0,0,0,$month,1,$year); + foreach($byday as $day) { + ereg ('([-\+]{0,1})?([0-9]{1})?([A-Z]{2})', $day, $byday_arr); + if ($byday_arr[2] != '') { + $nth = $byday_arr[2]-1; } else { ! $nth = 0; ! } ! $on_day = two2threeCharDays($byday_arr[3]); ! $on_day_num = two2threeCharDays($byday_arr[3],false); ! if ($byday_arr[1] == '-') { ! $last_day_tmp = date('t',$checkdate_time); ! $checkdate_time = strtotime(date('Y-m-'.$last_day_tmp, $checkdate_time)); ! $last_tmp = (date('w',$checkdate_time) == $on_day_num) ? '' : 'last '; ! $next_date_time = strtotime($last_tmp.$on_day.' -'.$nth.' week', $checkdate_time); ! } else { ! $next_date_time = strtotime($on_day.' +'.$nth.' week', $checkdate_time); } } + } else { + $day = date('d', $start_date_time); + $next_date_time = mktime(0,0,0,$month,$day,$year+1); + //echo date('Ymd',$next_date_time).$summary.'<br>'; } + if (isset($next_date_time) && $next_date_time != '') $recur_data[] = $next_date_time; } + if (isset($byyearday)) { + foreach ($byyearday as $yearday) { + ereg ('([-\+]{0,1})?([0-9]{1,3})', $yearday, $byyearday_arr); + if ($byyearday_arr[1] == '-') { + $ydtime = mktime(0,0,0,12,31,$this_year); + $yearnum = $byyearday_arr[2] - 1; + $next_date_time = strtotime('-'.$yearnum.' days', $ydtime); + } else { + $ydtime = mktime(0,0,0,1,1,$this_year); + $yearnum = $byyearday_arr[2] - 1; + $next_date_time = strtotime('+'.$yearnum.' days', $ydtime); + } + if (isset($next_date_time) && $next_date_time != '') $recur_data[] = $next_date_time; + } + } + break; + default: + // anything else we need to end the loop + $next_range_time = $end_range_time + 100; + } # end switch + } + $next_range_time = strtotime('+'.$interval.' '.$freq_type, $next_range_time); + } #end while loop + } # end if time compare + + + #foreach($recur_data as $time) echo "<br>".date("Ymd his",$time); + + + + # use recur_data array to write the master array + // use the same code to write the data instead of always changing it 5 times + $recur_data_hour = @substr($start_time,0,2); + $recur_data_minute = @substr($start_time,2,2); + foreach($recur_data as $recur_data_time) { + $recur_data_year = date('Y', $recur_data_time); + $recur_data_month = date('m', $recur_data_time); + $recur_data_day = date('d', $recur_data_time); + $recur_data_date = $recur_data_year.$recur_data_month.$recur_data_day; + if (($recur_data_time >= $start_date_time) && ($recur_data_time <= $end_date_time) && ($count_to != $count) && !in_array($recur_data_date, $except_dates)) { + if (isset($allday_start) && $allday_start != '') { + $start_time2 = $recur_data_time; + $end_time2 = strtotime('+'.$diff_allday_days.' days', $recur_data_time); + while ($start_time2 < $end_time2) { + $start_date2 = date('Ymd', $start_time2); + $master_array[($start_date2)][('-1')][$uid] = array ( + 'event_text' => $summary, + 'description' => $description, + 'location' => $location, + 'organizer' => serialize($organizer), + 'attendee' => serialize($attendee), + 'calnumber' => $calnumber, + 'calname' => $actual_calname, + 'url' => $url, + 'status' => $status, + 'class' => $class, + 'recur' => $recur ); + $start_time2 = strtotime('+1 day', $start_time2); + } + } else { + $start_unixtime_tmp = mktime($recur_data_hour,$recur_data_minute,0,$recur_data_month,$recur_data_day,$recur_data_year); + $end_unixtime_tmp = $start_unixtime_tmp + $length; + + if (($end_time >= $bleed_time) && ($bleed_check == '-1')) { + $start_tmp = strtotime(date('Ymd',$start_unixtime_tmp)); + $end_date_tmp = date('Ymd',$end_unixtime_tmp); + while ($start_tmp < $end_unixtime_tmp) { + $start_date_tmp = date('Ymd',$start_tmp); + if ($start_date_tmp == $recur_data_year.$recur_data_month.$recur_data_day) { + $time_tmp = $hour.$minute; + $start_time_tmp = $start_time; + } else { + $time_tmp = '0000'; + $start_time_tmp = '0000'; + } + if ($start_date_tmp == $end_date_tmp) { + $end_time_tmp = $end_time; + } else { + $end_time_tmp = '2400'; + $display_end_tmp = $end_time; + } + + // Let's double check the until to not write past it + $until_check = $start_date_tmp.$time_tmp.'00'; + if ($abs_until > $until_check) { + $master_array[$start_date_tmp][$time_tmp][$uid] = array ( + 'event_start' => $start_time_tmp, + 'event_end' => $end_time_tmp, + 'start_unixtime' => $start_unixtime_tmp, + 'end_unixtime' => $end_unixtime_tmp, + 'event_text' => $summary, + 'event_length' => $length, + 'event_overlap' => 0, + 'description' => $description, + 'status' => $status, + 'class' => $class, + 'spans_day' => true, + 'location' => $location, + 'organizer' => serialize($organizer), + 'attendee' => serialize($attendee), + 'calnumber' => $calnumber, + 'calname' => $actual_calname, + 'url' => $url, + 'recur' => $recur); + if (isset($display_end_tmp)){ + $master_array[$start_date_tmp][$time_tmp][$uid]['display_end'] = $display_end_tmp; + } + checkOverlap($start_date_tmp, $time_tmp, $uid); + } + $start_tmp = strtotime('+1 day',$start_tmp); } ! } else { ! if ($bleed_check == '-1') { ! $display_end_tmp = $end_time; ! $end_time_tmp1 = '2400'; ! ! } ! if (!isset($end_time_tmp1)) $end_time_tmp1 = $end_time; ! ! // Let's double check the until to not write past it ! $until_check = $recur_data_date.$hour.$minute.'00'; ! if ($abs_until > $until_check) { ! $master_array[($recur_data_date)][($hour.$minute)][$uid] = array ( ! 'event_start' => $start_time, ! 'event_end' => $end_time_tmp1, ! 'start_unixtime' => $start_unixtime_tmp, ! 'end_unixtime' => $end_unixtime_tmp, ! 'event_text' => $summary, ! 'event_length' => $length, ! 'event_overlap' => 0, ! 'description' => $description, ! 'status' => $status, ! 'class' => $class, ! 'spans_day' => false, ! 'location' => $location, ! 'organizer' => serialize($organizer), ! 'attendee' => serialize($attendee), ! 'calnumber' => $calnumber, ! 'calname' => $actual_calname, ! 'url' => $url, ! 'recur' => $recur); ! if (isset($display_end_tmp)){ ! $master_array[($recur_data_date)][($hour.$minute)][$uid]['display_end'] = $display_end_tmp; ! } ! checkOverlap($recur_data_date, ($hour.$minute), $uid); ! } ! } ! } ! } ! } ! ! unset($recur_data); Index: parse_tzs.php =================================================================== RCS file: /cvsroot/phpicalendar/phpicalendar/functions/parse/parse_tzs.php,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** parse_tzs.php 11 Dec 2008 23:48:39 -0000 1.1 --- parse_tzs.php 13 Dec 2008 23:42:31 -0000 1.2 *************** *** 2,6 **** $ifile = @fopen($filename, "r"); if ($ifile == FALSE) exit(error($lang['l_error_cantopen'], $filename)); ! $nextline = fgets($ifile, 1024); if (trim($nextline) != 'BEGIN:VCALENDAR') exit(error($lang['l_error_invalidcal'], $filename)); --- 2,6 ---- $ifile = @fopen($filename, "r"); if ($ifile == FALSE) exit(error($lang['l_error_cantopen'], $filename)); ! $nextline = fgets($ifile); if (trim($nextline) != 'BEGIN:VCALENDAR') exit(error($lang['l_error_invalidcal'], $filename)); *************** *** 25,40 **** case 'BEGIN:STANDARD': unset ($offset_s); break; case 'END:STANDARD': $offset_s = $offset_to; break; case 'BEGIN:DAYLIGHT': unset ($offset_d); break; case 'END:DAYLIGHT': $offset_d = $offset_to; break; case 'END:VTIMEZONE': ! $tz_array[$tz_id] = array($offset_s, $offset_d); #echo "<pre>$tz_id"; print_r($tz_array[$tz_id]);echo"</pre>"; break; default: --- 25,52 ---- case 'BEGIN:STANDARD': unset ($offset_s); + $is_std = true; break; case 'END:STANDARD': $offset_s = $offset_to; + $is_std = false; break; case 'BEGIN:DAYLIGHT': unset ($offset_d); + $is_daylight = true; break; case 'END:DAYLIGHT': $offset_d = $offset_to; + $is_daylight = false; break; case 'END:VTIMEZONE': ! $tz_array[$tz_id] = array( ! 0 => $offset_s, ! 1 => $offset_d, ! 'dt_start' => $begin_daylight, ! 'st_start' => $begin_std, ! 'st_name' => $st_name, ! 'dt_name' => $dt_name ! ! ); #echo "<pre>$tz_id"; print_r($tz_array[$tz_id]);echo"</pre>"; break; default: *************** *** 57,60 **** --- 69,80 ---- $offset_to = $data; break; + case 'DTSTART': + if($is_std) $begin_std = $data; + if($is_daylight) $begin_daylight = $data; + break; + case 'TZNAME': + if($is_std) $st_name = $data; + if($is_daylight) $dt_name = $data; + break; } } |