search.php File Reference
Go to the source code of this file.
Functions
- tep_parse_search_string ($search_str= '', &$objects)
- tep_checkdate ($date_to_check, $format_string, &$date_array)
- tep_is_leap_year ($year)
- get_list_option_dipso ()
- tep_list_option_value_dipso ()
Function Documentation
| get_list_option_dipso | ( | ) |
Definition at line 285 of file search.php.
Referenced by tep_list_option_value_dipso().
00285 { 00286 global $languages_id; 00287 $DB=Database::getInstance(); 00288 $list=array(); 00289 // static $list; 00290 // if(count($list)>0) return $list; 00291 $attributes_query = $DB->query("select products_options_id as id,products_options_name as text from " . TABLE_PRODUCTS_OPTIONS . " where language_id = '" . (int)$languages_id . "'"); 00292 while ($attributes = $attributes_query->fetchAssoc()) { 00293 $list[]=$attributes; 00294 } 00295 return $list; 00296 }
| tep_checkdate | ( | $ | date_to_check, | |
| $ | format_string, | |||
| &$ | date_array | |||
| ) |
Definition at line 164 of file search.php.
00164 { 00165 $separator_idx = -1; 00166 00167 $separators = array('-', ' ', '/', '.'); 00168 $month_abbr = array('jan','feb','mar','apr','may','jun','jul','aug','sep','oct','nov','dec'); 00169 $no_of_days = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); 00170 00171 $format_string = strtolower($format_string); 00172 00173 if (strlen($date_to_check) != strlen($format_string)) { 00174 return false; 00175 } 00176 00177 $size = sizeof($separators); 00178 for ($i=0; $i<$size; $i++) { 00179 $pos_separator = strpos($date_to_check, $separators[$i]); 00180 if ($pos_separator != false) { 00181 $date_separator_idx = $i; 00182 break; 00183 } 00184 } 00185 00186 for ($i=0; $i<$size; $i++) { 00187 $pos_separator = strpos($format_string, $separators[$i]); 00188 if ($pos_separator != false) { 00189 $format_separator_idx = $i; 00190 break; 00191 } 00192 } 00193 00194 if ($date_separator_idx != $format_separator_idx) { 00195 return false; 00196 } 00197 00198 if ($date_separator_idx != -1) { 00199 $format_string_array = explode( $separators[$date_separator_idx], $format_string ); 00200 if (sizeof($format_string_array) != 3) { 00201 return false; 00202 } 00203 00204 $date_to_check_array = explode( $separators[$date_separator_idx], $date_to_check ); 00205 if (sizeof($date_to_check_array) != 3) { 00206 return false; 00207 } 00208 00209 $size = sizeof($format_string_array); 00210 for ($i=0; $i<$size; $i++) { 00211 if ($format_string_array[$i] == 'mm' || $format_string_array[$i] == 'mmm') $month = $date_to_check_array[$i]; 00212 if ($format_string_array[$i] == 'dd') $day = $date_to_check_array[$i]; 00213 if ( ($format_string_array[$i] == 'yyyy') || ($format_string_array[$i] == 'aaaa') ) $year = $date_to_check_array[$i]; 00214 } 00215 } else { 00216 if (strlen($format_string) == 8 || strlen($format_string) == 9) { 00217 $pos_month = strpos($format_string, 'mmm'); 00218 if ($pos_month != false) { 00219 $month = substr( $date_to_check, $pos_month, 3 ); 00220 $size = sizeof($month_abbr); 00221 for ($i=0; $i<$size; $i++) { 00222 if ($month == $month_abbr[$i]) { 00223 $month = $i; 00224 break; 00225 } 00226 } 00227 } else { 00228 $month = substr($date_to_check, strpos($format_string, 'mm'), 2); 00229 } 00230 } else { 00231 return false; 00232 } 00233 00234 $day = substr($date_to_check, strpos($format_string, 'dd'), 2); 00235 $year = substr($date_to_check, strpos($format_string, 'yyyy'), 4); 00236 } 00237 00238 if (strlen($year) != 4) { 00239 return false; 00240 } 00241 00242 if (!settype($year, 'integer') || !settype($month, 'integer') || !settype($day, 'integer')) { 00243 return false; 00244 } 00245 00246 if ($month > 12 || $month < 1) { 00247 return false; 00248 } 00249 00250 if ($day < 1) { 00251 return false; 00252 } 00253 00254 if (tep_is_leap_year($year)) { 00255 $no_of_days[1] = 29; 00256 } 00257 00258 if ($day > $no_of_days[$month - 1]) { 00259 return false; 00260 } 00261 00262 $date_array = array($year, $month, $day); 00263 00264 return true; 00265 }
| tep_is_leap_year | ( | $ | year | ) |
Definition at line 269 of file search.php.
Referenced by tep_checkdate().
| tep_list_option_value_dipso | ( | ) |
Definition at line 303 of file search.php.
00303 { 00304 global $languages_id; 00305 $DB=Database::getInstance(); 00306 00307 foreach(get_list_option_dipso() as $attributes) { 00308 $option_values_list = array(); 00309 $option_values_query = $DB->query('SELECT pv.products_options_values_id AS id, pv.products_options_values_name AS text FROM ('. TABLE_PRODUCTS_OPTIONS_VALUES . ' pv, '. TABLE_PRODUCTS_OPTIONS .' po) LEFT JOIN ' . TABLE_PRODUCTS_OPTIONS_VALUES_TO_PRODUCTS_OPTIONS . ' popv ON pv.products_options_values_id = popv.products_options_values_id WHERE popv.products_options_id = po.products_options_id AND po.products_options_id =' . (int)$attributes['id'] . ' AND po.language_id ='. (int)$languages_id . ' GROUP BY pv.products_options_values_id, products_options_values_name'); 00310 00311 while ($option_values = $option_values_query->fetchAssoc()) { 00312 $option_values_list[] = $option_values; 00313 } 00314 echo tep_draw_pull_down_menu($attributes['text'],$attributes['text'], $option_values_list); 00315 } 00316 }
| tep_parse_search_string | ( | $ | search_str = '', |
|
| &$ | objects | |||
| ) |
Definition at line 13 of file search.php.
00013 { 00014 $search_str = trim(strtolower($search_str)); 00015 00016 // Break up $search_str on whitespace; quoted string will be reconstructed later 00017 $pieces = preg_split('/[[:space:]]+/', $search_str); 00018 $objects = array(); 00019 $tmpstring = ''; 00020 $flag = ''; 00021 00022 for ($k=0; $k<count($pieces); $k++) { 00023 while (substr($pieces[$k], 0, 1) == '(') { 00024 $objects[] = '('; 00025 if (strlen($pieces[$k]) > 1) { 00026 $pieces[$k] = substr($pieces[$k], 1); 00027 } else { 00028 $pieces[$k] = ''; 00029 } 00030 } 00031 00032 $post_objects = array(); 00033 00034 while (substr($pieces[$k], -1) == ')') { 00035 $post_objects[] = ')'; 00036 if (strlen($pieces[$k]) > 1) { 00037 $pieces[$k] = substr($pieces[$k], 0, -1); 00038 } else { 00039 $pieces[$k] = ''; 00040 } 00041 } 00042 00043 // Check individual words 00044 00045 if ( (substr($pieces[$k], -1) != '"') && (substr($pieces[$k], 0, 1) != '"') ) { 00046 $objects[] = trim($pieces[$k]); 00047 00048 for ($j=0; $j<count($post_objects); $j++) { 00049 $objects[] = $post_objects[$j]; 00050 } 00051 } else { 00052 /* This means that the $piece is either the beginning or the end of a string. 00053 So, we'll slurp up the $pieces and stick them together until we get to the 00054 end of the string or run out of pieces. 00055 */ 00056 00057 // Add this word to the $tmpstring, starting the $tmpstring 00058 $tmpstring = trim(preg_replace('/"/', ' ', $pieces[$k])); 00059 00060 // Check for one possible exception to the rule. That there is a single quoted word. 00061 if (substr($pieces[$k], -1 ) == '"') { 00062 // Turn the flag off for future iterations 00063 $flag = 'off'; 00064 00065 $objects[] = trim($pieces[$k]); 00066 00067 for ($j=0; $j<count($post_objects); $j++) { 00068 $objects[] = $post_objects[$j]; 00069 } 00070 00071 unset($tmpstring); 00072 00073 // Stop looking for the end of the string and move onto the next word. 00074 continue; 00075 } 00076 00077 // Otherwise, turn on the flag to indicate no quotes have been found attached to this word in the string. 00078 $flag = 'on'; 00079 00080 // Move on to the next word 00081 $k++; 00082 00083 // Keep reading until the end of the string as long as the $flag is on 00084 00085 while ( ($flag == 'on') && ($k < count($pieces)) ) { 00086 while (substr($pieces[$k], -1) == ')') { 00087 $post_objects[] = ')'; 00088 if (strlen($pieces[$k]) > 1) { 00089 $pieces[$k] = substr($pieces[$k], 0, -1); 00090 } else { 00091 $pieces[$k] = ''; 00092 } 00093 } 00094 00095 // If the word doesn't end in double quotes, append it to the $tmpstring. 00096 if (substr($pieces[$k], -1) != '"') { 00097 // Tack this word onto the current string entity 00098 $tmpstring .= ' ' . $pieces[$k]; 00099 00100 // Move on to the next word 00101 $k++; 00102 continue; 00103 } else { 00104 /* If the $piece ends in double quotes, strip the double quotes, tack the 00105 $piece onto the tail of the string, push the $tmpstring onto the $haves, 00106 kill the $tmpstring, turn the $flag "off", and return. 00107 */ 00108 $tmpstring .= ' ' . trim(preg_replace('/"/', ' ', $pieces[$k])); 00109 00110 // Push the $tmpstring onto the array of stuff to search for 00111 $objects[] = trim($tmpstring); 00112 00113 for ($j=0; $j<count($post_objects); $j++) { 00114 $objects[] = $post_objects[$j]; 00115 } 00116 00117 unset($tmpstring); 00118 00119 // Turn off the flag to exit the loop 00120 $flag = 'off'; 00121 } 00122 } 00123 } 00124 } 00125 00126 // add default logical operators if needed 00127 $temp = array(); 00128 for($i=0; $i<(count($objects)-1); $i++) { 00129 $temp[] = $objects[$i]; 00130 if ( ($objects[$i] != 'and') && 00131 ($objects[$i] != 'or') && 00132 ($objects[$i] != '(') && 00133 ($objects[$i+1] != 'and') && 00134 ($objects[$i+1] != 'or') && 00135 ($objects[$i+1] != ')') ) { 00136 $temp[] = ADVANCED_SEARCH_DEFAULT_OPERATOR; 00137 } 00138 } 00139 $temp[] = $objects[$i]; 00140 $objects = $temp; 00141 00142 $keyword_count = 0; 00143 $operator_count = 0; 00144 $balance = 0; 00145 for($i=0; $i<count($objects); $i++) { 00146 if ($objects[$i] == '(') $balance --; 00147 if ($objects[$i] == ')') $balance ++; 00148 if ( ($objects[$i] == 'and') || ($objects[$i] == 'or') ) { 00149 $operator_count ++; 00150 } elseif ( ($objects[$i]) && ($objects[$i] != '(') && ($objects[$i] != ')') ) { 00151 $keyword_count ++; 00152 } 00153 } 00154 00155 if ( ($operator_count < $keyword_count) && ($balance == 0) ) { 00156 return true; 00157 } else { 00158 return false; 00159 } 00160 }
