From fc4ef652b9565c913a805c3f4010cd1c95476196 Mon Sep 17 00:00:00 2001 From: Jim Hu Date: Thu, 18 Dec 2008 09:22:23 +0000 Subject: recurrence changes, add recur_tests calendars subdirectory, fix cpath --- functions/ical_parser.php | 2 +- functions/init/cpaths.php | 1 + functions/parse/end_vevent.php | 11 ++-- functions/parse/recur_functions.php | 110 +++++++++++++++++++++--------------- functions/template.php | 2 +- 5 files changed, 75 insertions(+), 51 deletions(-) (limited to 'functions') diff --git a/functions/ical_parser.php b/functions/ical_parser.php index e6d5b22..ce1f6b6 100644 --- a/functions/ical_parser.php +++ b/functions/ical_parser.php @@ -148,7 +148,7 @@ foreach ($cal_filelist as $cal_key=>$filename) { $location = ''; $url = ''; $type = ''; - $wkst = 'SU'; + $wkst = 'MO'; $except_dates = array(); $except_times = array(); diff --git a/functions/init/cpaths.php b/functions/init/cpaths.php index bcf2c11..dd6ae45 100644 --- a/functions/init/cpaths.php +++ b/functions/init/cpaths.php @@ -28,3 +28,4 @@ if (isset($user_template["$cpath"])){ if (isset($phpiCal_config->more_webcals) && is_array($phpiCal_config->more_webcals[$cpath])){ $list_webcals = array_merge($phpiCal_config->list_webcals, $phpiCal_config->more_webcals["$cpath"]); } +$phpiCal_config->setProperty('calendar_path',$calendar_path); \ No newline at end of file diff --git a/functions/parse/end_vevent.php b/functions/parse/end_vevent.php index eb78ee3..88f94fa 100644 --- a/functions/parse/end_vevent.php +++ b/functions/parse/end_vevent.php @@ -242,7 +242,7 @@ $next_date_time handles those instances within a $freq_type */ #echo "
$summary\n\tstart mArray time:".date("Ymd his",$mArray_begin)."\n\tnext_range_unixtime:".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) {
-	$year = date('Y', $next_range_unixtime); 
+	$year = date("Y", $next_range_unixtime); 
 	$month = date('m', $next_range_unixtime); 
 	$time = mktime(12,0,0,$month,date("d",$start_unixtime),$year);
 	switch ($freq_type){
@@ -253,16 +253,17 @@ while ($next_range_unixtime <= $end_range_unixtime && $count > 0) {
 			add_recur(expand_byday($next_range_unixtime));
 			break;
 		case 'month':
-			$times = expand_bymonthday(array($time));
+			if(!empty($bymonthday)) $time = mktime(12,0,0,$month,1,$year);
+			$times = expand_bymonthday(array($time));#echo "\n $month exp bymonthday";dump_times($times);
 			foreach($times as $time){ 
 				add_recur(expand_byday($time));
 			}
 			break;
 		case 'year':
 			$times = expand_bymonth($time); #echo "exp bymonth";dump_times($times);
-			$times = expand_byweekno($times); #echo "exp bymonth";dump_times($times);
-			$times = expand_byyearday($times); #echo "exp bymonth";dump_times($times);
-			$times = expand_bymonthday($times); #echo "exp bymonthday";dump_times($times);
+			$times = expand_byweekno($times); #echo "exp byweekno";dump_times($times);
+			$times = expand_byyearday($times); #echo "exp byyearday";dump_times($times);
+			$times = expand_bymonthday($times); #echo "\nexp bymonthday";dump_times($times);
 			foreach($times as $time){ 
 				add_recur(expand_byday($time));
 			}
diff --git a/functions/parse/recur_functions.php b/functions/parse/recur_functions.php
index e805e42..daf7399 100644
--- a/functions/parse/recur_functions.php
+++ b/functions/parse/recur_functions.php
@@ -27,53 +27,61 @@ function add_recur($times,$freq=''){
 	global $recur_data;
 	global $count, $mArray_begin, $mArray_end, $except_dates, $start_date_unixtime,$end_range_unixtime;	
 	if (!is_array($times)) $times = array($times);
-	#echo "add_recur";dump_times($times);
 	/*BYMONTH, BYWEEKNO, BYYEARDAY, BYMONTHDAY, BYDAY, BYHOUR,
    BYMINUTE, BYSECOND and BYSETPOS*/
 	$times = restrict_bymonth($times,$freq); 
-	$times = restrict_byweekno($times,$freq);
+#	$times = restrict_byweekno($times,$freq);
 	$times = restrict_byyearday($times,$freq);
 	$times = restrict_bymonthday($times,$freq);
 	$times = restrict_byday($times,$freq);
-	$times = restrict_bysetpos($times,$freq);#echo "restrict_bysetpos";
 	if($start_date_unixtime > $mArray_begin) $times[] = $start_date_unixtime;
+	$times = restrict_bysetpos($times,$freq);#echo "restrict_bysetpos";
 	$times = array_unique($times);
 	sort($times); 
 	$until_date = date("Ymd",$end_range_unixtime);
-#dump_times($times);
-#dump_times($recur_data);
 	foreach ($times as $time){ 
 		#echo "time:". date("Ymd",$time)."\n";
 		$date = date("Ymd",$time);
 		$time = strtotime("$date 12:00:00");
-		if(isset($time) && !in_array($time, $recur_data) && !in_array($date, $except_dates) && $time >= $start_date_unixtime && $date <= $until_date){ 
-			$count--; #echo ".";
-			if($time >= $mArray_begin && $time <= $mArray_end && $count >= 0) $recur_data[] = $time;
+		if(isset($time) && !in_array($time, $recur_data) && 
+			!in_array($date, $except_dates) && $time >= $start_date_unixtime && $date <= $until_date){ 
+			$count--; #echo "\n.$count\n";
+			if($time >= $mArray_begin && 
+			$time <= $mArray_end 
+			&& $count >= 0
+			) $recur_data[] = $time;
 		}
 	}
+#dump_times($recur_data);
 	return;
 }
 function expand_bymonth($time){
-	global $bymonth, $year, $start_unixtime;
+	global $bymonth, $byweekno, $bymonthday, $year, $start_unixtime, $freq_type;
+	if(!empty($byweekno)) return $times;
 	if(empty($bymonth)) $bymonth = array(date("m", $start_unixtime)); 
+	$d = date("d",$start_unixtime);
+	if (!empty($bymonthday)) $d = 1;
 	foreach ($bymonth as $m){ 
-		$time = mktime(12,0,0,$m,date("d",$start_unixtime),$year); #echo "exm:".date("Ymd",$time)."\n";
+		$time = mktime(12,0,0,$m,$d,$year); #echo "exm:".date("Ymd",$time)."\n";
 		$times[] = $time;
 	}	
 	return $times;	
 }
 function expand_byweekno($times){
-	global $byweekno, $year;
+	global $byweekno, $year, $freq_type, $wkst, $wkst3char;
+	# byweekno is only used when repeat is yearly
+	# when it's set, the input times are irrelevant
+	# it also needs a byday.
+	if ($freq_type != 'year') return $times;
 	if (empty($byweekno)) return $times;
-	$py = $year-1; 
-	$ny = $year+1;
-	foreach($times as $time){ 
-		foreach($byweekno as $weekno){ 
-			if($yearday >= 0) $day = strtotime("Jan 1 $year +$weekno weeks");
-			else $day = strtotime("Jan 1 $year $weekno weeks");
-			if(date("Y",$day == $year)) $new_times[] = $day;
-		}	
-	}	
+	$total_weeks = date("W",mktime(12,0,0,12,24,$year) ) +1;
+	$w1_start = strtotime("this $wkst3char", mktime(12,0,0,1,1,$year) ); 
+	foreach($byweekno as $weekno){ 
+		if($weekno < 0) $weekno = $weekno + $total_weeks;
+		#echo "\n $wkst3char w1st:".date("Ymd", $w1_start)." ".date("Ymd", mktime(12,0,0,1,1,$year))." weekno:$weekno";
+		$new_times[] = strtotime("+".(($weekno-1)*7)."days",$w1_start);
+	}
+	#dump_times($new_times);
 	return $new_times;
 }
 
@@ -82,13 +90,15 @@ function expand_byyearday($times){
 	if (empty($byyearday)) return $times;
 	$py = $year-1; 
 	$ny = $year+1;
+	$new_times = array();
 	foreach($times as $time){ 
 		foreach($byyearday as $yearday){
-			if($yearday > 0) $day = strtotime("Dec 31 $py +$yearday days");
-			else $day = strtotime("Jan 1 $ny $yearday days");
+			if($yearday > 0){ $day = strtotime("+$yearday days Dec 31, $py");#echo "\n".date("Ymd",$day)." = +$yearday days Dec 31, $py";
+			}else $day = strtotime("Jan 1 $ny $yearday days");
 			if(date("Y",$day == $year)) $new_times[] = $day;
 		}	
-	}	
+	}
+#	dump_times($new_times);
 	return $new_times;
 }
 
@@ -107,7 +117,7 @@ function expand_bymonthday($times){
 }
 
 function expand_byday($time){
-	global $freq_type, $byday, $wkst3char, $year, $month, $start_unixtime,$summary;
+	global $freq_type, $byday, $bymonth,$byweekno, $wkst3char, $year, $month, $start_unixtime, $summary;
 	if (empty($byday)) return array($time);
 	$times = array();
 	$the_sunday = dateOfWeek(date("Ymd",$time), $wkst3char);
@@ -119,7 +129,7 @@ function expand_byday($time){
 				[2] => 4 number
 				[3] => TH day abbr
 		*/
-		ereg ('([-\+]{0,1})?([0-9]{1})?([A-Z]{2})', $day, $byday_arr);
+		ereg ('([-\+]{0,1})?([0-9]+)?([A-Z]{2})', $day, $byday_arr);
 		$on_day = two2threeCharDays($byday_arr[3]);
 		switch($freq_type){
 			case 'week':
@@ -128,17 +138,28 @@ function expand_byday($time){
 				$times[] = $next_date_time; 
 				break;
 			case 'month':
+				$time = mktime(12,0,0,$month,1,$year);
 			case 'year':
-				$week_arr = array(1,2,3,4,5);
-				if(isset($byday_arr[2]) && $byday_arr[2] !='') $week_arr = array($byday_arr[2]); 
-				$month_start = strtotime(date("Ym00",$time));
-				$month_end = strtotime(date("Ymt",$time))+ (36 * 60 * 60);				
-				foreach($week_arr as $week){
-				#	echo "
$summary".$byday_arr[1].$week.$on_day,date("Ymd",$month_start)."\n";
-					if($byday_arr[1] == '-') $next_date_time = strtotime($byday_arr[1].$week.$on_day,$month_end);
-					else $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",$time) ) $times[] = $next_date_time; 
+				if(empty($byweekno)){
+					$week_arr = array(1,2,3,4,5);
+					if(isset($byday_arr[2]) && $byday_arr[2] !='') $week_arr = array($byday_arr[2]); 
+					$month_start = strtotime(date("Ym00",$time));
+					$month_end = strtotime(date("Ymt",$time))+ (36 * 60 * 60);
+					if($freq_type == 'year' && empty($bymonth)){
+						$month_start = mktime(12,0,0,1,0,$year);
+						$month_end   = mktime(12,0,0,1,1,$year+1);
+					}
+					foreach($week_arr as $week){
+						#echo "
$summary ".$byday_arr[1].$week.$on_day." st:".date("Ymd",$month_start)." t:".date("Ymd",$time)."\n";
+						if($byday_arr[1] == '-') $next_date_time = strtotime($byday_arr[1].$week.$on_day,$month_end);
+						else $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",$time) ) $times[] = $next_date_time; 
+					}
+				}else{
+					# byweekno should act like freq_type = week
+					$next_date_time = strtotime("this $on_day",strtotime($the_sunday)) + (12 * 60 * 60);					
+					$times[] = $next_date_time; 				
 				}
 				break;
 			default:
@@ -152,8 +173,8 @@ function expand_byday($time){
 
 
 function restrict_bymonth($times,$freq=''){
-	global $bymonth;
-	if (empty($bymonth)) return $times;
+	global $bymonth, $byyearday;
+	if (empty($bymonth) || !empty($byyearday)) return $times;
 	$new_times=array();
 	foreach ($times as $time){ 
 		if(in_array(date("m", $time), $bymonth)) $new_times[] = $time;
@@ -179,8 +200,9 @@ function restrict_byyearday($times,$freq=''){
 				if(date("L",$time)) $yearday += 1;
 			}	
 			$yearday_arr[] = $yearday;
-		}	
-		if(in_array(date("z", $time), $yearday_arr)) $new_times[] = $time;
+		}
+		# date(z,$time) gives 0 for Jan 1
+		if(in_array((date("z", $time)+1), $yearday_arr)) $new_times[] = $time;
 	}	
 	return $new_times;
 }
@@ -217,12 +239,12 @@ function restrict_byday($times,$freq=''){
 }
 
 function restrict_bysetpos($times,$freq=''){
-	global $rrule_array, $bysetpos;
+	global $bysetpos;
 	if(empty($bysetpos)) return $times;
-	$new_times=array();
-	$n = count($times);
+	sort($times);
+	$new_times=array(); 
 	foreach($bysetpos as $setpos){
-		$new_times[] = array_slice($times, $setpos, 1);
+		$new_times[] = implode('',array_slice($times, $setpos, 1));
 	}
 	return $new_times;	
 }
@@ -231,7 +253,7 @@ function restrict_bysetpos($times,$freq=''){
 function dump_times($times){
 	global $summary;
 	echo "
$summary times:";
-	var_dump($times);
+	#var_dump($times);
 	foreach($times as $time) echo "\ndate:".date("Ymd his",$time);
 	echo "
"; } diff --git a/functions/template.php b/functions/template.php index b6e1e2d..ed73672 100644 --- a/functions/template.php +++ b/functions/template.php @@ -946,7 +946,7 @@ class Page { } else { $start2 = date($timeFormat_small, $val['start_unixtime']); if ($type == 'large') { - $switch['EVENT'] .= '
'; + @$switch['EVENT'] .= '
'; $switch['EVENT'] .= openevent($daylink, $cal_time, $uid, $val, $month_event_lines, 10, 'ps3', "$start2 ").''; $switch['EVENT'] .= (isset($val['location']) && $val['location'] != '') ? "
".$val['location']."
" : ''; $switch['EVENT'] .= '
'; -- cgit v1.2.3