From 328a925bafcd69ecfda5fc8101e1a0dc667c5434 Mon Sep 17 00:00:00 2001 From: jwangen Date: Mon, 28 Oct 2002 05:20:08 +0000 Subject: spruced up search, fixed a few bugs in sidebar and month_bottom, and a few various changes in the parser and date_functions --- functions/date_functions.php | 2 +- functions/ical_parser.php | 48 ++++++++----- month_bottom.php | 10 +-- search.php | 157 ++++++++++++++++++++++++++++++++++++++++--- sidebar.php | 12 ++-- 5 files changed, 194 insertions(+), 35 deletions(-) diff --git a/functions/date_functions.php b/functions/date_functions.php index 4683caa..893e61a 100644 --- a/functions/date_functions.php +++ b/functions/date_functions.php @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/functions/ical_parser.php b/functions/ical_parser.php index 4a9eeb7..f06e982 100644 --- a/functions/ical_parser.php +++ b/functions/ical_parser.php @@ -180,10 +180,11 @@ if ($parse_file) { } if (($end > $mArray_begin) && ($end < $mArray_end)) { while ($start != $end) { - $start_date = date('Ymd', $start); - $master_array[($start_date)][('-1')][$uid]= array ('event_text' => $summary, 'description' => $description); + $start_date2 = date('Ymd', $start); + $master_array[($start_date2)][('-1')][$uid]= array ('event_text' => $summary, 'description' => $description); $start = strtotime('+1 day', $start); } + if (!$write_processed) $master_array[($start_date)]['-1'][$uid]['exception'] = true; } } @@ -191,7 +192,7 @@ if ($parse_file) { if ((isset($start_time) && $start_time != '') && (!isset($allday_start) || $allday_start == '')) { $nbrOfOverlaps = checkOverlap($start_date, $start_time, $end_time); $master_array[($start_date)][($hour.$minute)][$uid] = array ('event_start' => $start_time, 'event_text' => $summary, 'event_end' => $end_time, 'event_length' => $length, 'event_overlap' => $nbrOfOverlaps, 'description' => $description); - + if (!$write_processed) $master_array[($start_date)][($hour.$minute)][$uid]['exception'] = true; } // Handling of the recurring events, RRULE @@ -201,6 +202,8 @@ if ($parse_file) { // if ((is_array($rrule_array)) && ($allday_written != TRUE)) { if (is_array($rrule_array)) { if (isset($allday_start) && $allday_start != '') { + $hour = '-'; + $minute = '1'; $rrule_array['START_DAY'] = $allday_start; $rrule_array['END_DAY'] = $allday_end; $rrule_array['END'] = 'end'; @@ -248,9 +251,11 @@ if ($parse_file) { case 'MINUTELY': $freq_type = 'minute'; break; case 'SECONDLY': $freq_type = 'second'; break; } + $master_array[($start_date)][($hour.$minute)][$uid]['recur'][$key] = ucfirst($freq_type); break; case 'COUNT': $count = $val; + $master_array[($start_date)][($hour.$minute)][$uid]['recur'][$key] = $count; break; case 'UNTIL': $until = ereg_replace('T', '', $val); @@ -274,47 +279,59 @@ if ($parse_file) { if ($regs[4] < 12) $until = strtotime('-1 day', $until); } + $master_array[($start_date)][($hour.$minute)][$uid]['recur'][$key] = localizeDate($dateFormat_week,$until); break; case 'INTERVAL': $number = $val; + $master_array[($start_date)][($hour.$minute)][$uid]['recur'][$key] = $number; break; case 'BYSECOND': $bysecond = $val; $bysecond = split (',', $bysecond); + $master_array[($start_date)][($hour.$minute)][$uid]['recur'][$key] = $bysecond; break; case 'BYMINUTE': $byminute = $val; $byminute = split (',', $byminute); + $master_array[($start_date)][($hour.$minute)][$uid]['recur'][$key] = $byminute; break; case 'BYHOUR': $byhour = $val; $byhour = split (',', $byhour); + $master_array[($start_date)][($hour.$minute)][$uid]['recur'][$key] = $byhour; break; case 'BYDAY': $byday = $val; $byday = split (',', $byday); + $master_array[($start_date)][($hour.$minute)][$uid]['recur'][$key] = $byday; break; case 'BYMONTHDAY': $bymonthday = $val; $bymonthday = split (',', $bymonthday); + $master_array[($start_date)][($hour.$minute)][$uid]['recur'][$key] = $bymonthday; break; case 'BYYEARDAY': $byyearday = $val; $byyearday = split (',', $byyearday); + $master_array[($start_date)][($hour.$minute)][$uid]['recur'][$key] = $byyearday; break; case 'BYWEEKNO': $byweekno = $val; $byweekno = split (',', $byweekno); + $master_array[($start_date)][($hour.$minute)][$uid]['recur'][$key] = $byweekno; break; case 'BYMONTH': $bymonth = $val; $bymonth = split (',', $bymonth); + $master_array[($start_date)][($hour.$minute)][$uid]['recur'][$key] = $bymonth; break; case 'BYSETPOS': $bysetpos = $val; + $master_array[($start_date)][($hour.$minute)][$uid]['recur'][$key] = $bysetpos; break; case 'WKST': $wkst = $val; + $master_array[($start_date)][($hour.$minute)][$uid]['recur'][$key] = $wkst; break; case 'END': @@ -368,10 +385,10 @@ if ($parse_file) { if (is_array($bymonthday)) { // loop through the days on which this event happens foreach($bymonthday as $day) { - if ($day != '0') { - $day = str_pad($day, 2, '0', STR_PAD_LEFT); - $next_date_time = strtotime(date('Y-m-',$next_range_time).$day); - $next_date = date('Ymd', $next_date_time); + $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; } } @@ -379,9 +396,9 @@ if ($parse_file) { } 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]); + ereg ('([\-\+]{0,1})([0-9]{1})([A-Z]{2})', $day, $byday_arr); + $nth = $byday_arr[2]-1; + $on_day = two2threeCharDays($byday_arr[3]); $next_date_time = strtotime($on_day.' +'.$nth.' week', $next_range_time); $next_date = date('Ymd', $next_date_time); $recur_data[] = $next_date_time; @@ -392,18 +409,17 @@ if ($parse_file) { if (!isset($bymonth)) $bymonth[] = date('m', $start_date_time); foreach($bymonth as $month) { $year = date('Y', $next_range_time); - $month = str_pad($month, 2, '0', STR_PAD_LEFT); if (is_array($byday)) { - $checkdate_time = strtotime($year.$month.'01'); + $checkdate_time = mktime(0,0,0,$month,1,$year); 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]); + ereg ('([\-\+]{0,1})([0-9]{1})([A-Z]{2})', $day, $byday_arr); + $nth = $byday_arr[2]-1; + $on_day = two2threeCharDays($byday_arr[3]); $next_date_time = strtotime($on_day.' +'.$nth.' week', $checkdate_time); } } else { $day = date('d', $start_date_time); - $next_date_time = strtotime($year.$month.$day); + $next_date_time = mktime(0,0,0,$month,$day,$year); } $recur_data[] = $next_date_time; } diff --git a/month_bottom.php b/month_bottom.php index 925bd6f..41c3c5d 100644 --- a/month_bottom.php +++ b/month_bottom.php @@ -8,6 +8,8 @@ $next_day = date("Ymd", strtotime("+1 day", $unix_time)); $prev_day = date("Ymd", strtotime("-1 day", $unix_time)); + + $fake_getdate_time = strtotime($this_year.'-'.$this_month.'-15'); ?>
@@ -27,7 +29,7 @@
- + @@ -57,7 +59,7 @@ - + @@ -284,7 +286,7 @@ '."\n". ''."\n". ''."\n". - ''."\n". + ''."\n". ''."\n". ''; @@ -52,15 +52,24 @@ if ($search_valid) { if (is_array($date_tmp)) { foreach($date_tmp as $time_tmp) { if (is_array($time_tmp)) { - foreach ($time_tmp as $event_tmp) { + foreach ($time_tmp as $uid_tmp => $event_tmp) { if (is_array($event_tmp)) { - $results1 = search_boolean($format_search_arr,$event_tmp['event_text']); - if (!$results1) { - $results2 = search_boolean($format_search_arr,$event_tmp['description']); - } - if ($results1 || $results2) { - $event_tmp['date'] = $date_key_tmp; - $the_arr[] = $event_tmp; + if (!isset($the_arr[$uid_tmp]) || isset($event_tmp['exception'])) { + $results1 = search_boolean($format_search_arr,$event_tmp['event_text']); + if (!$results1) { + $results2 = search_boolean($format_search_arr,$event_tmp['description']); + } + if ($results1 || $results2) { + $event_tmp['date'] = $date_key_tmp; + if (isset($event_tmp['recur'])) { + $event_tmp['recur'] = format_recur($event_tmp['recur']); + } + if (isset($the_arr[$uid_tmp])) { + $the_arr[$uid_tmp]['exceptions'][] = $event_tmp; + } else { + $the_arr[$uid_tmp] = $event_tmp; + } + } } } } @@ -168,6 +177,13 @@ $search_took = number_format(($search_ended-$search_started),3); echo "\n"; echo "\n"; echo "\n"; + if (isset($val['recur'])) { + $recur = $val['recur']; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + } if ($val["description"]) { echo "\n"; echo "\n"; @@ -178,6 +194,61 @@ $search_took = number_format(($search_ended-$search_started),3); echo "\n"; echo "\n"; echo "\n"; + if (isset($val['exceptions'])) { + foreach($val['exceptions'] as $val2) { + $key = $val2['date']; + $dayofmonth = strtotime ($key); + $dayofmonth = localizeDate ($dateFormat_day, $dayofmonth); + echo "\n"; + echo ""; + echo "\n"; + + if ($val2["event_text"]) { + $event_text = stripslashes(urldecode($val2["event_text"])); + $description = stripslashes(urldecode($val2["description"])); + $event_start = $val2["event_start"]; + $event_end = $val2["event_end"]; + $event_start = date ($timeFormat, strtotime ("$event_start")); + $event_end = date ($timeFormat, strtotime ("$event_end")); + $event_start = "$event_start - $event_end"; + if (!$val2["event_start"]) { + $event_start = "$all_day_lang"; + $event_start2 = ''; + $event_end = ''; + } + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + } + } + } } } } else { @@ -339,6 +410,74 @@ function search_boolean($needle_arr, $haystack) { return true; } +function format_recur($arr) { + global $monthsofyearshort_lang, $daysofweekshort_lang; + $freq = $arr['FREQ'].(($arr['INTERVAL'] == 1) ? ' ' : 's '); + $int = $arr['INTERVAL']; + if (isset($arr['COUNT'])) $times = $arr['COUNT'].' time'.(($arr['COUNT'] == 1) ? ' ' : 's '); + if (isset($arr['UNTIL'])) $until = 'until '.$arr['UNTIL'].' '; + $by = ''; + if (isset($arr['BYMONTH'])) { + $by .= 'on '; + $count = count($arr['BYMONTH']); + $last = $count - 1; + if ($count == 1) { + $month = $arr['BYMONTH'][0]; + $by .= $monthsofyearshort_lang[($month-1)]; + } else { + foreach ($arr['BYMONTH'] as $key => $month) { + if ($key == $last) $by .= $monthsofyearshort_lang[($month-1)]; + else $by .= $monthsofyearshort_lang[($month-1)].', '; + } + } + $by .= ' '; + } + + if (isset($arr['BYMONTHDAY'])) { + $by .= 'on '; + $last = count($arr['BYMONTHDAY']) - 1; + if ($arr['BYMONTHDAY'][$last] == '0') unset($arr['BYMONTHDAY'][$last]); + $count = count($arr['BYMONTHDAY']); + $last = $count - 1; + if ($count == 1) { + ereg('([\-]{0,1})([0-9]{1,2})',$arr['BYMONTHDAY'][0],$regs); + list($junk,$sign,$day) = $regs; + $by .= $day; + } else { + foreach ($arr['BYMONTHDAY'] as $key => $day) { + ereg('([\-]{0,1})([0-9]{1,2})',$day,$regs); + list($junk,$sign,$day) = $regs; + if ($key == $last) $by .= $day; + else $by .= $day.', '; + } + } + $by .= ' '; + } + if (isset($arr['BYDAY'])) { + $by .= 'on '; + $count = count($arr['BYDAY']); + $last = $count-1; + if ($count == 1) { + ereg('([\-]{0,1})([0-9]{0,1})([A-Z]{2})',$arr['BYDAY'][0],$regs); + list($junk,$sign,$day_num,$day_txt) = $regs; + $num = two2threeCharDays($day_txt,false); + if ($day_num != '') $by .= $day_num.' '; + $by .= $daysofweekshort_lang[$num]; + } else { + foreach ($arr['BYDAY'] as $key => $day) { + ereg('([\-]{0,1})([0-9]{0,1})([A-Z]{2})',$day,$regs); + list($junk,$sign,$day_num,$day_txt) = $regs; + $num = two2threeCharDays($day_txt,false); + if ($day_num != '') $by .= $day_num.' '; + if ($key == $last) $by .= $daysofweekshort_lang[$num]; + else $by .= $daysofweekshort_lang[$num].', '; + } + } + $by .= ' '; + } + return 'Every '.$int.' '.$freq.$times.$until.$by; +} + function getmicrotime() { list($usec, $sec) = explode(' ',microtime()); return ((float)$usec + (float)$sec); diff --git a/sidebar.php b/sidebar.php index 1c929fb..fa9469a 100644 --- a/sidebar.php +++ b/sidebar.php @@ -225,7 +225,9 @@
$summary_lang:$event_text
Recurring event:$recur
$description_lang:
Exception: $dayofmonth
\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + if (isset($val2['recur'])) { + $recur = $val2['recur']; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + } + if ($val2["description"]) { + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + } + echo "
$time_lang:$event_start
$summary_lang:$event_text
Recurring event:$recur
$description_lang:$description
\n"; + echo "

- + - + @@ -263,7 +265,7 @@
@@ -233,7 +235,7 @@