aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Oster <parasytic@users.sourceforge.net>2010-02-09 18:06:33 +0000
committerJason Oster <parasytic@users.sourceforge.net>2010-02-09 18:06:33 +0000
commit36380c2546c970bffb131644d95f376ac5688c9a (patch)
treeb679d2674976a3b44390d8bbeb2497353770d30b
parent6f43ce3da6131d96ba5e56f2279d279a30d65db6 (diff)
downloadphpicalendar-36380c2546c970bffb131644d95f376ac5688c9a.tar.gz
phpicalendar-36380c2546c970bffb131644d95f376ac5688c9a.tar.bz2
phpicalendar-36380c2546c970bffb131644d95f376ac5688c9a.zip
Some fixes for the search page
-rw-r--r--functions/template.php129
-rw-r--r--search.php97
2 files changed, 115 insertions, 111 deletions
diff --git a/functions/template.php b/functions/template.php
index 22a52ee..d00c890 100644
--- a/functions/template.php
+++ b/functions/template.php
@@ -144,13 +144,16 @@ class Page {
global $phpiCal_config, $getdate, $cal, $the_arr, $printview, $dateFormat_day, $timeFormat, $week_start, $week_end, $lang;
preg_match("!<\!-- switch results on -->(.*)<\!-- switch results off -->!Uis", $this->page, $match1);
- preg_match("!<\!-- switch recur on -->(.*)<\!-- loop recur off -->!Uis", $this->page, $match2);
+ preg_match("!<\!-- switch recur on -->(.*)<\!-- switch recur off -->!Uis", $this->page, $match2);
preg_match("!<\!-- switch exceptions on -->(.*)<\!-- switch exceptions off -->!Uis", $this->page, $match3);
$loop_event = trim($match1[1]);
$loop_recur = trim($match2[1]);
$loop_except = trim($match3[1]);
$parse_month = date ("Ym", strtotime($getdate));
+ $events_found = 0;
+ $some_events = '';
+ $final = '';
if (isset($the_arr)){
// Pull out each event
foreach($the_arr as $key => $val) {
@@ -162,83 +165,83 @@ class Page {
if ($val['event_text']) {
$event_text = stripslashes(urldecode($val['event_text']));
$description = stripslashes(urldecode($val['description']));
- $location = stripslashes(urldecode($val['location']));
+ $location = stripslashes(urldecode($val['location']));
$event_start = $val['event_start'];
$event_end = $val['event_end'];
if (isset($val['display_end'])) $event_end = $val['display_end'];
- if (!$val['event_start']) {
- $event_start = $lang['l_all_day'];
- $event_start2 = '';
- $event_end = '';
- } else {
- $event_start = date ($timeFormat, strtotime ($event_start));
- $event_end = date ($timeFormat, strtotime ($event_end));
- $event_start = $event_start .' - '.$event_end;
- }
+ if (!$val['event_start']) {
+ $event_start = $lang['l_all_day'];
+ $event_start2 = '';
+ $event_end = '';
+ } else {
+ $event_start = date ($timeFormat, strtotime ($event_start));
+ $event_end = date ($timeFormat, strtotime ($event_end));
+ $event_start = $event_start .' - '.$event_end;
}
+ }
- if ($description == '') {
- $events_tmp = preg_replace('!<\!-- switch description_events on -->.*<\!-- switch description_events off -->!Uis', '', $events_tmp);
- }
- if (!isset($val['exceptions'])) {
- $events_tmp = preg_replace('!<\!-- switch exceptions on -->.*<\!-- switch exceptions off -->!Uis', '', $events_tmp);
- }else{
- $some_exceptions = "";
- foreach ($val['exceptions'] as $except_val){
- $except_tmp = $loop_except;
-
- $except_date = strtotime($except_val['date']);
- $except_date = localizeDate ('%A, %B %e %Y', $except_date);
- $except_tmp = str_replace('{DAYOFMONTH}', $except_date, $except_tmp);
-
- $except_event_start = date ($timeFormat, strtotime ($except_val['event_start']));
- $except_event_end = date ($timeFormat, strtotime ($except_val['event_end']));
- $except_event_start = $except_event_start .' - '.$except_event_end;
-
- $except_tmp = str_replace('{EVENT_START}', $except_event_start, $except_tmp);
-
- $except_event_text = stripslashes(urldecode($except_val['event_text']));
- $except_tmp = str_replace('{EVENT_TEXT}', $except_event_text, $except_tmp);
-
- #is there a recur in the exception?
- if (!$except_val['recur']) {
- $except_tmp = preg_replace('!<\!-- switch except_recur on -->.*<\!-- switch except_recur off -->!Uis', '', $except_tmp);
- }else{
- $except_tmp = str_replace('{EXCEPT_RECUR}', $except_val['recur'], $except_tmp);
- }
- #is there a description in the exception?
- if (!$except_val['description']) {
- $except_tmp = preg_replace('!<\!-- switch except_description on -->.*<\!-- switch except_description off -->!Uis', '', $except_tmp);
- }else{
- $except_description = stripslashes(urldecode($except_val['description']));
- $except_tmp = str_replace('{EXCEPT_DESCRIPTION}', $except_description, $except_tmp);
- }
- $some_exceptions .= $except_tmp;
+ if ($description == '') {
+ $events_tmp = preg_replace('!<\!-- switch description_events on -->.*<\!-- switch description_events off -->!Uis', '', $events_tmp);
+ }
+ if (!isset($val['exceptions'])) {
+ $events_tmp = preg_replace('!<\!-- switch exceptions on -->.*<\!-- switch exceptions off -->!Uis', '', $events_tmp);
+ }else{
+ $some_exceptions = "";
+ foreach ($val['exceptions'] as $except_val){
+ $except_tmp = $loop_except;
- }
- $events_tmp = preg_replace('!<\!-- switch exceptions on -->.*<\!-- switch exceptions off -->!Uis', $some_exceptions,$events_tmp );
+ $except_date = strtotime($except_val['date']);
+ $except_date = localizeDate ('%A, %B %e %Y', $except_date);
+ $except_tmp = str_replace('{DAYOFMONTH}', $except_date, $except_tmp);
+ $except_event_start = date ($timeFormat, strtotime ($except_val['event_start']));
+ $except_event_end = date ($timeFormat, strtotime ($except_val['event_end']));
+ $except_event_start = $except_event_start .' - '.$except_event_end;
- }
+ $except_tmp = str_replace('{EVENT_START}', $except_event_start, $except_tmp);
+
+ $except_event_text = stripslashes(urldecode($except_val['event_text']));
+ $except_tmp = str_replace('{EVENT_TEXT}', $except_event_text, $except_tmp);
+
+ #is there a recur in the exception?
+ if (!$except_val['recur']) {
+ $except_tmp = preg_replace('!<\!-- switch except_recur on -->.*<\!-- switch except_recur off -->!Uis', '', $except_tmp);
+ }else{
+ $except_tmp = str_replace('{EXCEPT_RECUR}', $except_val['recur'], $except_tmp);
+ }
+ #is there a description in the exception?
+ if (!$except_val['description']) {
+ $except_tmp = preg_replace('!<\!-- switch except_description on -->.*<\!-- switch except_description off -->!Uis', '', $except_tmp);
+ }else{
+ $except_description = stripslashes(urldecode($except_val['description']));
+ $except_tmp = str_replace('{EXCEPT_DESCRIPTION}', $except_description, $except_tmp);
+ }
+ $some_exceptions .= $except_tmp;
- if (!$val['recur']) {
- $events_tmp = preg_replace('!<\!-- switch recur on -->.*<\!-- switch recur off -->!Uis', '', $events_tmp);
- $events_tmp = str_replace('{L_STARTING_ON}', '', $events_tmp);
- }else{
- $events_tmp = str_replace('{RECUR}', $val['recur'], $events_tmp);
}
+ $events_tmp = preg_replace('!<\!-- switch exceptions on -->.*<\!-- switch exceptions off -->!Uis', $some_exceptions,$events_tmp );
+
+
+ }
+
+ if (!$val['recur']) {
+ $events_tmp = preg_replace('!<\!-- switch recur on -->.*<\!-- switch recur off -->!Uis', '', $events_tmp);
+ $events_tmp = str_replace('{L_STARTING_ON}', '', $events_tmp);
+ }else{
+ $events_tmp = str_replace('{RECUR}', $val['recur'], $events_tmp);
+ }
- $search = array('{EVENT_START}', '{EVENT_TEXT}', '{DESCRIPTION}','{LOCATION}');
- $replace = array($event_start, $event_text, $description, $location);
- $events_tmp = str_replace($search, $replace, $events_tmp);
- $some_events .= $events_tmp;
- $events_tmp = $loop_event;
+ $search = array('{EVENT_START}', '{EVENT_TEXT}', '{DESCRIPTION}','{LOCATION}');
+ $replace = array($event_start, $event_text, $description, $location);
+ $events_tmp = str_replace($search, $replace, $events_tmp);
+ $some_events .= $events_tmp;
+ $events_tmp = $loop_event;
$some_events = str_replace('{KEY}', $val['date'], $some_events);
$some_events = str_replace('{DAYOFMONTH}', $dayofmonth, $some_events);
- $final .= $day_tmp.$some_events;
- unset ($day_tmp, $some_events);
+ $final .= $some_events;
+ $some_events = '';
}
}
diff --git a/search.php b/search.php
index 75a3dd6..7932870 100644
--- a/search.php
+++ b/search.php
@@ -11,9 +11,10 @@ $display_date = $lang['l_results'];
if (isset($_SERVER['HTTP_REFERER']) && $_SERVER['HTTP_REFERER'] != '') {
$back_page = $_SERVER['HTTP_REFERER'];
} else {
- $back_page = BASE.$default_view.'.php?cal='.$cal.'&amp;getdate='.$getdate;
+ $back_page = BASE.$phpiCal_config->default_view.'.php?cal='.$cal.'&amp;getdate='.$getdate;
}
+$query = '';
$search_valid = false;
if (isset($_GET['query']) && $_GET['query'] != '') {
$query = $_GET['query'];
@@ -21,7 +22,7 @@ if (isset($_GET['query']) && $_GET['query'] != '') {
}
$search_box = '';
-$search_box .=
+$search_box .=
'<form action="search.php" method="get">'."\n".
'<input type="hidden" name="cpath" value="'.$cpath.'">'."\n".
'<input type="hidden" name="cal" value="'.$cal.'">'."\n".
@@ -47,10 +48,15 @@ if ($search_valid) {
if (is_array($event_tmp)) {
if (!isset($the_arr[$uid_tmp]) || isset($event_tmp['exception'])) {
#print_r($format_search_arr);
+ #print_r($event_tmp);
#echo "<br>this event:".$event_tmp['event_text']."<br>";
- $results1 = search_boolean($format_search_arr,$event_tmp['event_text']);
-
- if (!$results1) {
+ $results1 = false;
+ $results2 = false;
+ if (isset($event_tmp['event_text'])) {
+ $results1 = search_boolean($format_search_arr,$event_tmp['event_text']);
+ }
+
+ if (!$results1 && isset($event_tmp['description'])) {
$results2 = search_boolean($format_search_arr,$event_tmp['description']);
}
if ($results1 || $results2) {
@@ -73,7 +79,7 @@ if ($search_valid) {
}
}
} else {
- $formatted_search = '<b>'.$no_query_lang.'</b>';
+ $formatted_search = '<b>'.$lang['l_no_query'].'</b>';
}
$search_ended = getmicrotime();
@@ -89,21 +95,21 @@ function format_search($search_str) {
$or_str_arr = array();
$search_str = strtolower($search_str);
-
+
if ($search_str == ' ') return array(false,$and_arr,$or_arr,$not_arr);
-
+
// clean up search string
$search_str = trim($search_str);
$search_str = str_replace(' and ', ' ', $search_str);
$search_str = str_replace(' - ', ' ', $search_str);
$search_str = ereg_replace('[[:space:]]+',' ', $search_str);
$search_str = str_replace(' not ', ' -', $search_str);
-
+
// start out with an AND array of all the items
$and_arr = explode(' ', $search_str);
$count = count($and_arr);
$j = 0;
-
+
// build an OR array from the items in AND
for($i=0;$i<$count;$i++) {
if ($i != 0 && $and_arr[$i] == 'or') {
@@ -131,48 +137,48 @@ function format_search($search_str) {
array_splice($and_arr,$key,1);
}
}
-
+
// prepare our formatted search string
if (count($and_arr) > 1) {
$final_str_arr[] = implode('</b> AND <b>', $and_arr);
} elseif (isset($and_arr[0]) && $and_arr[0] != '') {
$final_str_arr[] = $and_arr[0];
}
-
+
if (count($or_str_arr) > 1) {
$final_str_arr[] = implode('</b> AND <b>', $or_str_arr);
} elseif (isset($or_str_arr[0]) && $or_str_arr[0] != '') {
$final_str_arr[] = $or_str_arr[0];
}
-
+
if (count($not_arr) > 1) {
$final_str_arr[] = '-'.implode('</b> AND <b>-', $not_arr);
} elseif (isset($not_arr[0]) && $not_arr[0] != '') {
$final_str_arr[] = '-'.$not_arr[0];
}
-
+
if (count($final_str_arr) > 1) {
$formatted_search = '<b>'.implode('</b> AND <b>', $final_str_arr).'</b>';
} else {
$formatted_search = '<b>'.$final_str_arr[0].'</b>';
}
-
+
return array($formatted_search, $and_arr, $or_arr, $not_arr);
}
-// takes an array made by format_search() and checks to see if it
+// takes an array made by format_search() and checks to see if it
// it matches against a string
function search_boolean($needle_arr, $haystack) {
// init arrays
$and_arr = $needle_arr[1];
$or_arr = $needle_arr[2];
$not_arr = $needle_arr[3];
-
+
if (!$needle_arr[0]) return false;
if ((sizeof($and_arr) == 0) &&
(sizeof($or_arr) == 0) &&
(sizeof($not_arr) == 0)) return false;
-
+
// compare lowercase versions of the strings
$haystack = strtolower($haystack);
@@ -182,7 +188,7 @@ function search_boolean($needle_arr, $haystack) {
return false;
}
}
-
+
// check against the AND
foreach($and_arr as $s) {
#echo "haystack: $haystack<br>needle: $s<br>";
@@ -190,7 +196,7 @@ function search_boolean($needle_arr, $haystack) {
return false;
}
}
-
+
// check against the OR
foreach($or_arr as $or) {
$is_false = true;
@@ -199,13 +205,13 @@ function search_boolean($needle_arr, $haystack) {
if (is_string(strstr($haystack,substr($s,1))) == false) {
$is_false = false;
break;
- }
+ }
} elseif (is_string(strstr($haystack,$s)) == true) {
$is_false = false;
break;
}
}
- if ($is_false) return false;
+ if ($is_false) return false;
}
// if we haven't returned false, then we return true
# echo "return true<br>";
@@ -214,23 +220,28 @@ function search_boolean($needle_arr, $haystack) {
function format_recur($arr) {
global $format_recur_lang, $monthsofyear_lang, $daysofweek_lang;
-
+
$d = $format_recur_lang['delimiter'];
- $int = $arr['INTERVAL'];
- $tmp = (($int == '1') ? 0 : 1);
-
- $freq = $arr['FREQ'];
- $freq = $format_recur_lang[$freq][$tmp];
-
+
+ $int = '';
+ $freq = '';
+ if (isset($arr['INTERVAL']) && isset($arr['FREQ'])) {
+ $int = $arr['INTERVAL'];
+ $tmp = (($int == '1') ? 0 : 1);
+
+ $freq = $arr['FREQ'];
+ $freq = $format_recur_lang[$freq][$tmp];
+ }
+
if (isset($arr['COUNT'])) $for = str_replace('%int%',$arr['COUNT'],$format_recur_lang['count']);
elseif (isset($arr['UNTIL'])) $for = str_replace('%date%',$arr['UNTIL'], $format_recur_lang['until']);
else $for = '';
-
+
$print = $format_recur_lang['start'];
$print = str_replace('%int%', $int, $print);
$print = str_replace('%freq%', $freq, $print);
$print = str_replace('%for%', $for, $print);
-
+
if (isset($arr['BYMONTH'])) {
$list = '';
$last = count($arr['BYMONTH']) - 1;
@@ -241,7 +252,7 @@ function format_recur($arr) {
$print .= '<br />'."\n";
$print .= str_replace('%list%', $list, $format_recur_lang['bymonth']);
}
-
+
if (isset($arr['BYMONTHDAY'])) {
$list = '';
if ($arr['BYMONTHDAY'][(count($arr['BYMONTHDAY']) - 1)] == '0') unset($arr['BYMONTHDAY'][$last]);
@@ -256,7 +267,7 @@ function format_recur($arr) {
$print .= '<br />'."\n";
$print .= str_replace('%list%', $list, $format_recur_lang['bymonthday']);
}
-
+
if (isset($arr['BYDAY'])) {
$list = '';
$last = count($arr['BYDAY']) - 1;
@@ -272,7 +283,7 @@ function format_recur($arr) {
$print .= '<br />'."\n";
$print .= str_replace('%list%', $list, $format_recur_lang['byday']);
}
-
+
return $print;
}
@@ -281,7 +292,7 @@ $page = new Page(BASE.'templates/'.$phpiCal_config->template.'/search.tpl');
$page->draw_search($page);
-
+
$page->replace_files(array(
'header' => BASE.'templates/'.$phpiCal_config->template.'/header.tpl',
'footer' => BASE.'templates/'.$phpiCal_config->template.'/footer.tpl',
@@ -315,20 +326,10 @@ $page->replace_tags(array(
'rss_powered' => $rss_powered,
'rss_available' => '',
'rss_valid' => '',
- 'show_search' => $show_search,
- 'next_month' => $next_month,
- 'prev_month' => $prev_month,
'show_goto' => '',
'is_logged_in' => '',
- 'list_jumps' => $list_jumps,
- 'list_icals' => $list_icals,
- 'list_years' => $list_years,
- 'list_months' => $list_months,
- 'list_weeks' => $list_weeks,
- 'legend' => $list_calcolors,
'current_view' => $current_view,
- 'style_select' => $style_select,
- 'sidebar_date' => $sidebar_date,
+ 'style_select' => '',
'l_goprint' => $lang['l_goprint'],
'l_preferences' => $lang['l_preferences'],
'l_calendar' => $lang['l_calendar'],
@@ -344,7 +345,7 @@ $page->replace_tags(array(
'l_download' => $lang['l_download'],
'l_this_months' => $lang['l_this_months'],
'l_powered_by' => $lang['l_powered_by'],
- 'l_this_site_is' => $lang['l_this_site_is']
+ 'l_this_site_is' => $lang['l_this_site_is']
));
@@ -353,4 +354,4 @@ $page->output();
#echo "<pre>";
#print_r($the_arr);
#echo "</pre>";
-?> \ No newline at end of file
+?>

© 2014-2024 Faster IT GmbH | imprint | privacy policy