In 4images 1.7.9 the search with more than one keyword, the use of operators (AND OR NOT) and two-word-keywords like "red car" is not working properly.
To fix this please apply this patch to the 3 files:
/includes/functions.php
/search.php
/includes/search_utils.php
The patched files are attached to this post (see below).
The fix will also be included in the next release of 4images.
Tip: If you want to search for a two-word-keyword like "red car", then you have to enter the ".
1.) search in
/includes/functions.php:
foreach ($split_keywords as $key => $val) {
$keywords .= (($keywords != "" ) ? ", " : "")."<a href=\"".$site_sess->url(ROOT_PATH."search.php?search_keywords=".urlencode($val))."\">".format_text($val, 2)."</a>";
and replace with:
foreach ($split_keywords as $key => $val) {
$url_val = $val;
if (strpos($url_val, ' ') !== false) {
$url_val = '"' . $url_val . '"';
}
$keywords .= (($keywords != "" ) ? ", " : "")."<a href=\"".$site_sess->url(ROOT_PATH."search.php?search_keywords=".urlencode($url_val))."\">".format_text($val, 2)."</a>";
2.) search in
/search.php:
$split_words = prepare_searchwords($search_keywords, true);
and replace with:
$split_words = prepare_searchwords_for_search($search_keywords);
3.) in
/includes/search_utils.php:
search for
function prepare_searchwords($val, $for_search = false)
insert above:
function prepare_searchwords_for_search($val)
{
$val = strip_tags(trim(stripslashes($val)));
$val = convert_special($val);
$val = strtolower($val);
$val = str_replace(array('+', '-'), array(' and ', ' not '), $val);
$val = preg_replace('/\s+/', ' ', $val);
$tokens = array();
for ($nextToken = strtok($val, ' '); $nextToken !== false; $nextToken = strtok(' ')) {
if ($nextToken[0] == '"') {
$nextToken = $nextToken[strlen($nextToken)-1] == '"' ? substr($nextToken, 1, -1) : substr($nextToken, 1) . ' ' . strtok('"');
}
$tokens[] = $nextToken;
}
return $tokens;
}
search for
"#[\n\t\r^\$\(\)<>\"\|@\?%~\+\.\[\]{}:\/=!§\\\\]+#s"and replace with
"#[\n\t\r^\$\(\)<>\"\|,@\?%~\+\.\[\]{}:\/=!§\\\\]+#s"3.1) search:
function prepare_searchwords($val, $for_search = false)
{
insert below:
// Backwards compatibility
if ($for_search) {
return prepare_searchwords_for_search($val);
}
3.2) search:
if ($for_search) {
$search_array = array(
"/\s+\+/",
"/\s+\-/"
);
$replace_array = array(
" and ",
" not "
);
$val = preg_replace($search_array, $replace_array, $val);
} else {
$val = str_replace("*", "", $val);
}
and replace with:
$val = str_replace("*", "", $val);
3.3) search:
array_walk($split_words, 'trim_value');
and replace with:
$split_words = array_map('trim', $split_words);
$split_words = array_map('strip_tags', $split_words);
$split_words = array_map('convert_special', $split_words);
$split_words = array_map('strtolower', $split_words);
3.4) search:
if ($for_search && ($word == "and" || $word == "und" || $word == "or" || $word == "oder" || $word == "not")) {
$clean_words[] = $word;
and replace with:
if ($word == "and" || $word == "und" || $word == "or" || $word == "oder" || $word == "not") {
3.5) search and remove:
}
if ($for_search) {
// Add whole string for image_keyword search
$clean_words[] = implode(' ', $clean_words);