function entities_to_umlauts($string, $charset_out = DEFAULT_CHARSET) { $string = charset_to_utf8($string, LINK_CHARSET, true); //if(utf8_check($string)) // this check is to much time-consuming (this may fail only if AddDefaultCharset is set) $string = utf8_to_charset($string, $charset_out); return $string; }
function search_make_sql_part($words, $match, $columns) { // $words are utf-8 encoded, will be converted to DEFAULT_CHARSET below if (empty($words) || empty($columns)) { return '(1=1)'; } global $database; // check if we can use SQL'S "LIKE" // work-around for WB'S missing-SET-NAMES-problem static $checked = FALSE; if ($checked === FALSE) { $checked = TRUE; $lowers = array('utf8' => "á", 'iso' => "�"); $uppers = array('utf8' => "Á", 'iso' => "�"); switch (DEFAULT_CHARSET) { case 'utf-8': $lo = $lowers['utf8']; $up = $uppers['utf8']; break; case 'iso-8859-1': case 'iso-8859-2': case 'iso-8859-3': case 'iso-8859-4': case 'iso-8859-5': case 'iso-8859-7': case 'iso-8859-9': case 'iso-8859-10': $lo = $lowers['iso']; $up = $uppers['iso']; break; default: $checked = 'check failed'; // we can't handle arabic,hebrew,thai } if ($checked === TRUE && ($query = $database->query("SELECT UPPER('{$lo}')='{$up}'"))) { $res = $query->fetchRow(); if ($res[0] == 0) { $checked = 'check failed'; } } else { $checked = 'check failed'; } } require_once WB_PATH . '/framework/functions-utf8.php'; global $search_table_sql_local; $altnum = count($search_table_sql_local); if ($match == 'all') { $op = 'AND'; } else { $op = ' OR'; } // keep the leading space! // create sql-template $sql = ''; $i = 0; foreach ($words as $w) { if (empty($w)) { continue; } $w_alts = $e_alts = array(); if ($altnum) { for ($x = 0; $x < $altnum; $x++) { $w_alts[$x] = strtr($w, $search_table_sql_local[$x]); } } else { $w_alts[0] = $w; } $w_alts = array_unique($w_alts); foreach ($w_alts as $a) { $tmp = htmlentities($a, ENT_COMPAT, 'UTF-8'); // if the missing-SET-NAMES-issue appears and $tmp contains non-ascii characters: exit and use the normal (slow) search-function instead if ($checked !== TRUE && preg_match('/[\\x80-\\xFF]/', $tmp)) { return '(1=1)'; } // missing-SET-NAMES-issue $e_alts[] = $tmp; } $sql .= ""; foreach ($w_alts as $a) { $sql .= "{{COL}} LIKE '%" . addslashes(utf8_to_charset($a)) . "%' OR "; } if (isset($e_alts[$i]) && $e_alts[$i] != $w) { $sql .= " {{COL}} LIKE '%" . addslashes($e_alts[$i]) . "%'"; } else { $sql = substr($sql, 0, strlen($sql) - 4); $sql .= ''; } $sql .= " {$op} "; $i++; } $sql = substr($sql, 0, strlen($sql) - 5); $sql_template = $sql; // create SQL-string from template $sql = '('; foreach ($columns as $c) { $sql .= '('; $sql .= str_replace('{{COL}}', $c, $sql_template); $sql .= ") OR "; } $sql = substr($sql, 0, strlen($sql) - 4); $sql .= ')'; return $sql; }