From: <ji...@us...> - 2008-12-16 15:46:31
|
Update of /cvsroot/phpicalendar/phpicalendar/functions/parse In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv2088/functions/parse Modified Files: end_vevent.php recur_functions.php Log Message: progress on recurrence Index: end_vevent.php =================================================================== RCS file: /cvsroot/phpicalendar/phpicalendar/functions/parse/end_vevent.php,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** end_vevent.php 16 Dec 2008 07:55:50 -0000 1.4 --- end_vevent.php 16 Dec 2008 15:46:24 -0000 1.5 *************** *** 190,195 **** /* ============================ Load $recur_data ============================ ! $recur_data 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 --- 190,194 ---- /* ============================ Load $recur_data ============================ ! $recur_data is an array of unix times for days of recurrences of an event. This code handles repeats at the day level or above. The next loop handles the times. RDATE is currently not supported *************** *** 211,223 **** $end_range_unixtime = $mArray_end+60*60*24; $start_date_unixtime = strtotime($start_date); ! $next_range_unixtime = $start_date_unixtime; if(isset($until) && $end_range_unixtime > $until_unixtime) $end_range_unixtime = $until_unixtime; if(!isset($rrule_array['FREQ'])){ $end_range_unixtime = strtotime($end_date); $count = 1; } - // if the beginning of our range is less than the start of the item, we may as well set it equal to it - if ($next_range_unixtime < $start_date_unixtime) $next_range_unixtime = $start_date_unixtime; - // convert wkst to a 3 char day for strtotime to work $wkst3char = two2threeCharDays($wkst); --- 210,226 ---- $end_range_unixtime = $mArray_end+60*60*24; $start_date_unixtime = strtotime($start_date); ! $next_range_unixtime = $start_date_unixtime; ! ! #conditions where we can not iterate over the whole range ! if($count == 1000000 && $interval == 1) $next_range_unixtime = $mArray_begin; ! // if the beginning of our range is less than the start of the item, we may as well set it equal to it ! if ($next_range_unixtime < $start_date_unixtime) $next_range_unixtime = $start_date_unixtime; ! if(isset($until) && $end_range_unixtime > $until_unixtime) $end_range_unixtime = $until_unixtime; + if($freq_type == 'year') $end_range_unixtime += 366*24*60*60; if(!isset($rrule_array['FREQ'])){ $end_range_unixtime = strtotime($end_date); $count = 1; } // convert wkst to a 3 char day for strtotime to work $wkst3char = two2threeCharDays($wkst); *************** *** 226,230 **** 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 "<pre>$summary\n\tstart mArray time:".date("Ymd his",$mArray_begin)."\n\tstart range time:".date("Ymd his",$next_range_unixtime)."\n\tend range time ".date("Ymd his",$end_range_unixtime)."</pre>"; $recur_data = array(); while ($next_range_unixtime <= $end_range_unixtime && $count > 0) { --- 229,233 ---- 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 "<pre>$summary\n\tstart mArray time:".date("Ymd his",$mArray_begin)."\n\tstart range time:".date("Ymd his",$next_range_unixtime)."\n\tend range time ".date("Ymd his",$end_range_unixtime)."\n"; $recur_data = array(); while ($next_range_unixtime <= $end_range_unixtime && $count > 0) { *************** *** 243,247 **** break; case 'month': ! $times = expand_bymonthday(array($next_range_unixtime)); foreach($times as $time){ add_recur(expand_byday($time)); --- 246,251 ---- break; case 'month': ! $time = mktime(12,0,0,$month,date("d",$start_unixtime),$year); ! $times = expand_bymonthday(array($time)); foreach($times as $time){ add_recur(expand_byday($time)); *************** *** 249,257 **** break; case 'year': ! $times = expand_bymonth($next_range_unixtime); ! $times = expand_byweekno($times); $times = expand_byyearday($times); $times = expand_bymonthday($times); - foreach($times as $time){ add_recur(expand_byday($time)); --- 253,260 ---- break; case 'year': ! $times = expand_bymonth($next_range_unixtime); ! $times = expand_byweekno($times); $times = expand_byyearday($times); $times = expand_bymonthday($times); foreach($times as $time){ add_recur(expand_byday($time)); *************** *** 262,275 **** break 2; } ! $next_range_unixtime = strtotime('+'.$interval.' '.$freq_type, $next_range_unixtime); } #end while loop sort($recur_data); - echo "<pre>$summary recur_data:"; - #var_dump($recur_data); - foreach($recur_data as $time) echo "\n".date("Ymd his",$time); - echo "</pre>"; ! # 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_unixtime,0,2); $recur_data_minute = @substr($start_unixtime,2,2); --- 265,274 ---- break 2; } ! $next_range_unixtime = strtotime('+'.$interval.' '.$freq_type, $next_range_unixtime); echo "\nnext $interval $freq_type".date("Ymd",$next_range_unixtime)."\n"; } #end while loop sort($recur_data); ! /* ============================ Use $recur_data array to write the master array ============================*/ ! // This used to use 5 different blocks to write the array... can it be reduced further? $recur_data_hour = @substr($start_unixtime,0,2); $recur_data_minute = @substr($start_unixtime,2,2); *************** *** 279,366 **** $recur_data_day = date('d', $recur_data_unixtime); $recur_data_date = $recur_data_year.$recur_data_month.$recur_data_day; ! if ( !in_array($recur_data_date, $except_dates) ) { ! if (isset($allday_start) && $allday_start != '') { ! $start_time2 = $recur_data_unixtime; ! $end_time2 = strtotime('+'.$diff_allday_days.' days', $recur_data_unixtime); ! 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 >= $phpiCal_config->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 ! $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, --- 278,330 ---- $recur_data_day = date('d', $recur_data_unixtime); $recur_data_date = $recur_data_year.$recur_data_month.$recur_data_day; ! ! if (isset($allday_start) && $allday_start != '') { ! $start_time2 = $recur_data_unixtime; ! $end_time2 = strtotime('+'.$diff_allday_days.' days', $recur_data_unixtime); ! 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 >= $phpiCal_config->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, *************** *** 371,375 **** 'status' => $status, 'class' => $class, ! 'spans_day' => false, 'location' => $location, 'organizer' => serialize($organizer), --- 335,339 ---- 'status' => $status, 'class' => $class, ! 'spans_day' => true, 'location' => $location, 'organizer' => serialize($organizer), *************** *** 380,390 **** '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); ! } } } } --- 344,389 ---- '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 + $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); + } } + } Index: recur_functions.php =================================================================== RCS file: /cvsroot/phpicalendar/phpicalendar/functions/parse/recur_functions.php,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** recur_functions.php 16 Dec 2008 07:55:50 -0000 1.2 --- recur_functions.php 16 Dec 2008 15:46:24 -0000 1.3 *************** *** 25,35 **** function add_recur($times,$freq=''){ ! global $recur_data, $count, $mArray_begin, $mArray_end; if (!is_array($times)) $times = array($times); $times = array_unique($times); ! sort($times); /*BYMONTH, BYWEEKNO, BYYEARDAY, BYMONTHDAY, BYDAY, BYHOUR, BYMINUTE, BYSECOND and BYSETPOS*/ ! $times = restrict_bymonth($times,$freq); $times = restrict_byweekno($times,$freq); $times = restrict_byyearday($times,$freq); --- 25,35 ---- function add_recur($times,$freq=''){ ! global $recur_data, $count, $mArray_begin, $mArray_end, $except_dates; if (!is_array($times)) $times = array($times); $times = array_unique($times); ! sort($times); /*BYMONTH, BYWEEKNO, BYYEARDAY, BYMONTHDAY, BYDAY, BYHOUR, BYMINUTE, BYSECOND and BYSETPOS*/ ! $times = restrict_bymonth($times,$freq); $times = restrict_byweekno($times,$freq); $times = restrict_byyearday($times,$freq); *************** *** 39,43 **** foreach ($times as $time){ ! if(isset($time) ) $count--; if($time >= $mArray_begin && $time <= $mArray_end && $count >= 0) $recur_data[] = $time; } --- 39,44 ---- foreach ($times as $time){ ! echo "time:". date("Ymd",$time); ! if(isset($time) && !in_array(date("Ymd",$time), $except_dates)) $count--; if($time >= $mArray_begin && $time <= $mArray_end && $count >= 0) $recur_data[] = $time; } *************** *** 46,51 **** function expand_bymonth($time){ global $bymonth, $year, $start_unixtime; ! if(empty($bymonth)) $bymonth = date("m", $start_unixtime); ! foreach ($bymonth as $m) $times[] = strtotime("$year".str_pad($m,2,"0",STR_PAD_LEFT).date("d",$start_unixtime)); return $times; } --- 47,55 ---- function expand_bymonth($time){ global $bymonth, $year, $start_unixtime; ! if(empty($bymonth)) $bymonth = array(date("m", $start_unixtime)); ! foreach ($bymonth as $m){ ! $time = mktime(12,0,0,$m,date("d",$start_unixtime),$year); #echo "exm:".date("Ymd",$time)."\n"; ! $times[] = $time; ! } return $times; } *************** *** 83,87 **** global $bymonthday, $year, $month; if (empty($bymonthday)) return $times; ! foreach($times as $time) foreach($bymonthday as $monthday) $new_times[] = strtotime("$year.$month".str_pad($monthday,2,"0",STR_PAD_LEFT)); return $new_times; } --- 87,91 ---- global $bymonthday, $year, $month; if (empty($bymonthday)) return $times; ! foreach($times as $time) foreach($bymonthday as $monthday) $new_times[] = mktime(12,0,0,$month,$monthday,$year); return $new_times; } *************** *** 89,93 **** function expand_byday($time){ global $freq_type, $byday, $wkst3char, $year, $month, $start_unixtime; ! if (empty($byday)) return array(strtotime("$year$month".date("d",$start_unixtime))); $the_sunday = dateOfWeek(date("Ymd",$time), $wkst3char); # echo "$freq_type, ".print_r($byday,true)."$wkst3char $the_sunday"; --- 93,97 ---- function expand_byday($time){ global $freq_type, $byday, $wkst3char, $year, $month, $start_unixtime; ! if (empty($byday)) return array($time); $the_sunday = dateOfWeek(date("Ymd",$time), $wkst3char); # echo "$freq_type, ".print_r($byday,true)."$wkst3char $the_sunday"; *************** *** 114,121 **** case 'year': $week_arr = array(1,2,3,4,5); ! if(!isset($byday_arr[2])) $week_arr = array($byday_arr[2]); $month_start = strtotime(date("Ym01",$time)); foreach($week_arr as $week){ ! $next_date_time = strtotime($byday_arr[1].$week.$on_day, $month_start); # check that we're still in the same month if (date("m",$next_date_time) == date("m",$month_start) ) $times[] = $next_date_time; --- 118,125 ---- case 'year': $week_arr = array(1,2,3,4,5); ! if(isset($byday_arr[2])) $week_arr = array($byday_arr[2]); $month_start = strtotime(date("Ym01",$time)); foreach($week_arr as $week){ ! $next_date_time = strtotime($byday_arr[1].$week.$on_day,$month_start); # check that we're still in the same month if (date("m",$next_date_time) == date("m",$month_start) ) $times[] = $next_date_time; *************** *** 127,130 **** --- 131,135 ---- } } + dump_times($times); return $times; } *************** *** 134,138 **** global $bymonth; if (empty($bymonth)) return $times; ! foreach ($times as $time) if(in_array(date("m", $time), $bymonth)) $new_times[] = $time; return $new_times; } --- 139,146 ---- global $bymonth; if (empty($bymonth)) return $times; ! $new_times=array(); ! foreach ($times as $time){ ! if(in_array(date("m", $time), $bymonth)) $new_times[] = $time; ! } return $new_times; } *************** *** 140,143 **** --- 148,152 ---- global $byweekno; if(empty($byweekno)) return $times; + $new_times=array(); foreach ($times as $time) if(in_array(date("W", $time), $byweekno)) $new_times[] = $time; return $new_times; *************** *** 147,150 **** --- 156,160 ---- global $byyearday; if(empty($byyearday)) return $times; + $new_times=array(); foreach ($times as $time) if(in_array(date("z", $time), $byyearday)) $new_times[] = $time; return $new_times; *************** *** 154,157 **** --- 164,168 ---- global $bymonthday; if(empty($bymonthday)) return $times; + $new_times=array(); foreach ($times as $time) if(in_array(date("j", $time), $bymonthday)) $new_times[] = $time; return $new_times; *************** *** 160,164 **** global $byday; if(empty($byday)) return $times; ! foreach($byday as $key=>$day) $byday3[] = two2threeCharDays($day); foreach ($times as $time) if(in_array(strtolower(date("D", $time)), $byday3)) $new_times[] = $time; return $new_times; --- 171,185 ---- global $byday; if(empty($byday)) return $times; ! foreach($byday as $key=>$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); ! $byday3[] = two2threeCharDays($byday_arr[3]); ! } ! $new_times=array(); foreach ($times as $time) if(in_array(strtolower(date("D", $time)), $byday3)) $new_times[] = $time; return $new_times; *************** *** 168,171 **** --- 189,193 ---- global $rrule_array, $bysetpos; if(empty($bysetpos)) return $times; + $new_times=array(); $n = count($times); foreach($bysetpos as $setpos){ *************** *** 173,175 **** } return $new_times; ! } \ No newline at end of file --- 195,205 ---- } return $new_times; ! } ! ! function dump_times($recur_data){ ! global $summary; ! echo "<pre>$summary recur_data:"; ! var_dump($recur_data); ! foreach($recur_data as $time) echo "\n".date("Ymd his",$time); ! echo "</pre>"; ! } |