public function split_words($text, $idx) { // Remove BBCode $text = preg_replace('%\\[/?(b|u|s|ins|del|em|i|h|colou?r|quote|code|img|url|email|list|topic|post|forum|user)(?:\\=[^\\]]*)?\\]%', ' ', $text); // Remove any apostrophes or dashes which aren't part of words $text = substr(Utils::ucp_preg_replace('%((?<=[^\\p{L}\\p{N}])[\'\\-]|[\'\\-](?=[^\\p{L}\\p{N}]))%u', '', ' ' . $text . ' '), 1, -1); // Remove punctuation and symbols (actually anything that isn't a letter or number), allow apostrophes and dashes (and % * if we aren't indexing) $text = Utils::ucp_preg_replace('%(?![\'\\-' . ($idx ? '' : '\\%\\*') . '])[^\\p{L}\\p{N}]+%u', ' ', $text); // Replace multiple whitespace or dashes $text = preg_replace('%(\\s){2,}%u', '\\1', $text); // Fill an array with all the words $words = array_unique(explode(' ', $text)); // Remove any words that should not be indexed foreach ($words as $key => $value) { // If the word shouldn't be indexed, remove it if (!$this->validate_search_word($value, $idx)) { unset($words[$key]); } } return $words; }
public function check_username($username, $errors, $exclude_id = null) { // Include UTF-8 function require_once ForumEnv::get('FEATHER_ROOT') . 'featherbb/Helpers/utf8/strcasecmp.php'; translate('register'); translate('prof_reg'); // Convert multiple whitespace characters into one (to prevent people from registering with indistinguishable usernames) $username = preg_replace('%\\s+%s', ' ', $username); // Validate username if (Utils::strlen($username) < 2) { $errors[] = __('Username too short'); } elseif (Utils::strlen($username) > 25) { // This usually doesn't happen since the form element only accepts 25 characters $errors[] = __('Username too long'); } elseif (!strcasecmp($username, 'Guest') || !utf8_strcasecmp($username, __('Guest'))) { $errors[] = __('Username guest'); } elseif (filter_var($username, FILTER_VALIDATE_IP)) { $errors[] = __('Username IP'); } elseif ((strpos($username, '[') !== false || strpos($username, ']') !== false) && strpos($username, '\'') !== false && strpos($username, '"') !== false) { $errors[] = __('Username reserved chars'); } elseif (preg_match('%(?:\\[/?(?:b|u|s|ins|del|em|i|h|colou?r|quote|code|img|url|email|list|\\*|topic|post|forum|user)\\]|\\[(?:img|url|quote|list)=)%i', $username)) { $errors[] = __('Username BBCode'); } // Check username for any censored words if (ForumSettings::get('o_censoring') == '1' && Utils::censor($username) != $username) { $errors[] = __('Username censor'); } // Check that the username (or a too similar username) is not already registered $query = !is_null($exclude_id) ? ' AND id!=' . $exclude_id : ''; $result = DB::for_table('online')->raw_query('SELECT username FROM ' . ForumSettings::get('db_prefix') . 'users WHERE (UPPER(username)=UPPER(:username1) OR UPPER(username)=UPPER(:username2)) AND id>1' . $query, array(':username1' => $username, ':username2' => Utils::ucp_preg_replace('%[^\\p{L}\\p{N}]%u', '', $username)))->find_one(); if ($result) { $busy = $result['username']; $errors[] = __('Username dupe 1') . ' ' . Utils::escape($busy) . '. ' . __('Username dupe 2'); } // Check username for any banned usernames foreach (Container::get('bans') as $cur_ban) { if ($cur_ban['username'] != '' && utf8_strtolower($username) == utf8_strtolower($cur_ban['username'])) { $errors[] = __('Banned username'); break; } } return $errors; }