| | |
| | | |
| | | /** |
| | | * Normalize the given string for fulltext search. |
| | | * Currently only optimized for Latin-1 characters; to be extended |
| | | * Currently only optimized for ISO-8859-1 and ISO-8859-2 characters; to be extended |
| | | * |
| | | * @param string Input string (UTF-8) |
| | | * @param boolean True to return list of words as array |
| | |
| | | // split by words |
| | | $arr = self::tokenize_string($str); |
| | | |
| | | // detect character set |
| | | if (utf8_encode(utf8_decode($str)) == $str) { |
| | | // ISO-8859-1 (or ASCII) |
| | | preg_match_all('/./u', 'äâàåáãæçéêëèïîìíñöôòøõóüûùúýÿ', $keys); |
| | | preg_match_all('/./', 'aaaaaaaceeeeiiiinoooooouuuuyy', $values); |
| | | |
| | | $mapping = array_combine($keys[0], $values[0]); |
| | | $mapping = array_merge($mapping, array('ß' => 'ss', 'ae' => 'a', 'oe' => 'o', 'ue' => 'u')); |
| | | } |
| | | else if (rcube_charset::convert(rcube_charset::convert($str, 'UTF-8', 'ISO-8859-2'), 'ISO-8859-2', 'UTF-8') == $str) { |
| | | // ISO-8859-2 |
| | | preg_match_all('/./u', 'ąáâäćçčéęëěíîłľĺńňóôöŕřśšşťţůúűüźžżý', $keys); |
| | | preg_match_all('/./', 'aaaaccceeeeiilllnnooorrsssttuuuuzzzy', $values); |
| | | |
| | | $mapping = array_combine($keys[0], $values[0]); |
| | | $mapping = array_merge($mapping, array('ß' => 'ss', 'ae' => 'a', 'oe' => 'o', 'ue' => 'u')); |
| | | } |
| | | |
| | | foreach ($arr as $i => $part) { |
| | | if (utf8_encode(utf8_decode($part)) == $part) { // is latin-1 ? |
| | | $arr[$i] = utf8_encode(strtr(strtolower(strtr(utf8_decode($part), |
| | | 'ÇçäâàåéêëèïîìÅÉöôòüûùÿøØáíóúñÑÁÂÀãÃÊËÈÍÎÏÓÔõÕÚÛÙýÝ', |
| | | 'ccaaaaeeeeiiiaeooouuuyooaiounnaaaaaeeeiiioooouuuyy')), |
| | | array('ß' => 'ss', 'ae' => 'a', 'oe' => 'o', 'ue' => 'u'))); |
| | | $part = mb_strtolower($part); |
| | | |
| | | if (!empty($mapping)) { |
| | | $part = strtr($part, $mapping); |
| | | } |
| | | else |
| | | $arr[$i] = mb_strtolower($part); |
| | | |
| | | $arr[$i] = $part; |
| | | } |
| | | |
| | | return $as_array ? $arr : join(" ", $arr); |
| | |
| | | return $password; |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Find out if the string content means true or false |