function split_words($text, $idx) { // Remove any apostrophes or dashes which aren't part of words $text = substr(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 = 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 (!validate_search_word($value, $idx)) { unset($words[$key]); } } return $words; }
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|left|center|right|hr|justify)(?:\\=[^\\]]*)?\\]%', ' ', $text); // Remove any apostrophes or dashes which aren't part of words $text = substr(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 = 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 (!validate_search_word($value, $idx)) { unset($words[$key]); } } return $words; }
} else { if (preg_match('%[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}%', $username) || preg_match('%((([0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}:[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){5}:([0-9A-Fa-f]{1,4}:)?[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){4}:([0-9A-Fa-f]{1,4}:){0,2}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){3}:([0-9A-Fa-f]{1,4}:){0,3}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){2}:([0-9A-Fa-f]{1,4}:){0,4}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}((\\b((25[0-5])|(1\\d{2})|(2[0-4]\\d)|(\\d{1,2}))\\b)\\.){3}(\\b((25[0-5])|(1\\d{2})|(2[0-4]\\d)|(\\d{1,2}))\\b))|(([0-9A-Fa-f]{1,4}:){0,5}:((\\b((25[0-5])|(1\\d{2})|(2[0-4]\\d)|(\\d{1,2}))\\b)\\.){3}(\\b((25[0-5])|(1\\d{2})|(2[0-4]\\d)|(\\d{1,2}))\\b))|(::([0-9A-Fa-f]{1,4}:){0,5}((\\b((25[0-5])|(1\\d{2})|(2[0-4]\\d)|(\\d{1,2}))\\b)\\.){3}(\\b((25[0-5])|(1\\d{2})|(2[0-4]\\d)|(\\d{1,2}))\\b))|([0-9A-Fa-f]{1,4}::([0-9A-Fa-f]{1,4}:){0,5}[0-9A-Fa-f]{1,4})|(::([0-9A-Fa-f]{1,4}:){0,6}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){1,7}:))%', $username)) { $errors[$id][] = $lang_update['Username IP format error']; } else { if ((strpos($username, '[') !== false || strpos($username, ']') !== false) && strpos($username, '\'') !== false && strpos($username, '"') !== false) { $errors[$id][] = $lang_update['Username bad characters error']; } else { if (preg_match('%(?:\\[/?(?:b|u|s|ins|del|em|i|h|colou?r|quote|code|img|url|email|list|\\*)\\]|\\[(?:img|url|quote|list)=)%i', $username)) { $errors[$id][] = $lang_update['Username BBCode error']; } } } } } } $result = $db->query('SELECT username FROM ' . $db->prefix . 'users WHERE (UPPER(username)=UPPER(\'' . $db->escape($username) . '\') OR UPPER(username)=UPPER(\'' . $db->escape(ucp_preg_replace('%[^\\p{L}\\p{N}]%u', '', $username)) . '\')) AND id>1') or error('Unable to fetch user info', __FILE__, __LINE__, $db->error()); if ($db->num_rows($result)) { $busy = $db->result($result); $errors[$id][] = sprintf($lang_update['Username duplicate error'], pun_htmlspecialchars($busy)); } if (empty($errors[$id])) { $old_username = $cur_user['username']; $_SESSION['dupe_users'][$id]['username'] = $cur_user['username'] = $username; $temp = array(); foreach ($cur_user as $idx => $value) { $temp[$idx] = is_null($value) ? 'NULL' : '\'' . $db->escape($value) . '\''; } // Insert the renamed user $db->query('INSERT INTO ' . $db->prefix . 'users(' . implode(',', array_keys($temp)) . ') VALUES (' . implode(',', array_values($temp)) . ')') or error('Unable to insert data to new table', __FILE__, __LINE__, $db->error()); // Renaming a user also affects a bunch of other stuff, lets fix that too... $db->query('UPDATE ' . $db->prefix . 'posts SET poster=\'' . $db->escape($username) . '\' WHERE poster_id=' . $id) or error('Unable to update posts', __FILE__, __LINE__, $db->error());
function do_smilies($text) { global $luna_config; $smilies = get_smilies(); $text = ' ' . $text . ' '; foreach ($smilies as $smiley_text => $smiley_img) { if (strpos($text, $smiley_text) !== false) { if ($luna_config['o_emoji'] == 1) { $text = ucp_preg_replace('%(?<=[>\\s])' . preg_quote($smiley_text, '%') . '(?=[^\\p{L}\\p{N}])%um', '<span class="emoji">' . $smiley_img . '</span>', $text); } else { $text = ucp_preg_replace('%(?<=[>\\s])' . preg_quote($smiley_text, '%') . '(?=[^\\p{L}\\p{N}])%um', '<img src="' . luna_htmlspecialchars(get_base_url(true) . '/img/smilies/' . $smiley_img) . '" width="' . $luna_config['o_emoji_size'] . '" height="' . $luna_config['o_emoji_size'] . '" alt="' . substr($smiley_img, 0, strrpos($smiley_img, '.')) . '" />', $text); } } } return substr($text, 1, -1); }
function ucp_preg_replace_callback($pattern, $replace, $subject) { return ucp_preg_replace($pattern, $replace, $subject, true); }
/** * Rename duplicate users * * @param array $cur_user */ function convert_users_dupe($cur_user) { global $session; $old_username = $cur_user['username']; $suffix = 1; // Find new free username while (true) { $username = $old_username . $suffix; $result = $this->db->query('SELECT username FROM ' . $this->db->prefix . 'users WHERE (UPPER(username)=UPPER(\'' . $this->db->escape($username) . '\') OR UPPER(username)=UPPER(\'' . $this->db->escape(ucp_preg_replace('%[^\\p{L}\\p{N}]%u', '', $username)) . '\')) AND id>1') or conv_error('Unable to fetch user info', __FILE__, __LINE__, $this->db->error()); if (!$this->db->num_rows($result)) { break; } } $session['dupe_users'][$cur_user['id']]['username'] = $cur_user['username'] = $username; $temp = array(); foreach ($cur_user as $idx => $value) { $temp[$idx] = $value === null ? 'NULL' : '\'' . $this->db->escape($value) . '\''; } // Insert the renamed user $this->db->query('INSERT INTO ' . $this->db->prefix . 'users(' . implode(',', array_keys($temp)) . ') VALUES (' . implode(',', array_values($temp)) . ')') or conv_error('Unable to insert data to new table', __FILE__, __LINE__, $this->db->error()); // Renaming a user also affects a bunch of other stuff, lets fix that too... $this->db->query('UPDATE ' . $this->db->prefix . 'posts SET poster=\'' . $this->db->escape($username) . '\' WHERE poster_id=' . $cur_user['id']) or conv_error('Unable to update posts', __FILE__, __LINE__, $this->db->error()); // The following must compare using collation utf8_bin otherwise we will accidently update posts/topics/etc belonging to both of the duplicate users, not just the one we renamed! $this->db->query('UPDATE ' . $this->db->prefix . 'posts SET edited_by=\'' . $this->db->escape($username) . '\' WHERE edited_by=\'' . $this->db->escape($old_username) . '\' COLLATE utf8_bin') or conv_error('Unable to update posts', __FILE__, __LINE__, $this->db->error()); $this->db->query('UPDATE ' . $this->db->prefix . 'topics SET poster=\'' . $this->db->escape($username) . '\' WHERE poster=\'' . $this->db->escape($old_username) . '\' COLLATE utf8_bin') or conv_error('Unable to update topics', __FILE__, __LINE__, $this->db->error()); $this->db->query('UPDATE ' . $this->db->prefix . 'topics SET last_poster=\'' . $this->db->escape($username) . '\' WHERE last_poster=\'' . $this->db->escape($old_username) . '\' COLLATE utf8_bin') or conv_error('Unable to update topics', __FILE__, __LINE__, $this->db->error()); $this->db->query('UPDATE ' . $this->db->prefix . 'forums SET last_poster=\'' . $this->db->escape($username) . '\' WHERE last_poster=\'' . $this->db->escape($old_username) . '\' COLLATE utf8_bin') or conv_error('Unable to update forums', __FILE__, __LINE__, $this->db->error()); $this->db->query('UPDATE ' . $this->db->prefix . 'online SET ident=\'' . $this->db->escape($username) . '\' WHERE ident=\'' . $this->db->escape($old_username) . '\' COLLATE utf8_bin') or conv_error('Unable to update online list', __FILE__, __LINE__, $this->db->error()); // If the user is a moderator or an administrator we have to update the moderator lists $result = $this->db->query('SELECT g_moderator FROM ' . $this->db->prefix . 'groups WHERE g_id=' . $cur_user['group_id']) or conv_error('Unable to fetch group', __FILE__, __LINE__, $this->db->error()); $group_mod = $this->db->result($result); if ($cur_user['group_id'] == PUN_ADMIN || $group_mod == '1') { $result = $this->db->query('SELECT id, moderators FROM ' . $this->db->prefix . 'forums') or conv_error('Unable to fetch forum list', __FILE__, __LINE__, $this->db->error()); while ($cur_forum = $this->db->fetch_assoc($result)) { $cur_moderators = $cur_forum['moderators'] != '' ? unserialize($cur_forum['moderators']) : array(); if (in_array($cur_user['id'], $cur_moderators)) { unset($cur_moderators[$old_username]); $cur_moderators[$username] = $cur_user['id']; uksort($cur_moderators, 'utf8_strcasecmp'); $this->db->query('UPDATE ' . $this->db->prefix . 'forums SET moderators=\'' . $this->db->escape(serialize($cur_moderators)) . '\' WHERE id=' . $cur_forum['id']) or conv_error('Unable to update forum', __FILE__, __LINE__, $this->db->error()); } } } $session['dupe_users'][$cur_user['id']]['old_username'] = $old_username; }
function censor_words($text) { static $search_for, $replace_with; // If not already built in a previous call, build an array of censor words and their replacement text if (!isset($search_for)) { if (file_exists(FORUM_CACHE_DIR . 'cache_censoring.php')) { include FORUM_CACHE_DIR . 'cache_censoring.php'; } if (!defined('FEATHER_CENSOR_LOADED')) { if (!defined('FORUM_CACHE_FUNCTIONS_LOADED')) { require FEATHER_ROOT . 'include/cache.php'; } generate_censoring_cache(); require FORUM_CACHE_DIR . 'cache_censoring.php'; } } if (!empty($search_for)) { $text = substr(ucp_preg_replace($search_for, $replace_with, ' ' . $text . ' '), 1, -1); } return $text; }
function do_smilies($text) { global $smilies; $text = ' ' . $text . ' '; foreach ($smilies as $smiley_text => $smiley_img) { if (strpos($text, $smiley_text) !== false) { $text = ucp_preg_replace('%(?<=[>\\s])' . preg_quote($smiley_text, '%') . '(?=[^\\p{L}\\p{N}])%um', '<img src="' . pun_htmlspecialchars(get_base_url(true) . '/img/smilies/' . $smiley_img) . '" width="15" height="15" alt="' . substr($smiley_img, 0, strrpos($smiley_img, '.')) . '" />', $text); } } return substr($text, 1, -1); }
private function do_smilies($text) { $this->config['o_smilies_dir'] = $this->config['o_smilies_dir'] != '' ? $this->config['o_smilies_dir'] : panther_htmlspecialchars(get_base_url() . '/' . $this->config['o_smilies_path'] . '/'); $text = ' ' . $text . ' '; foreach ($this->smilies as $smiley_text => $smiley_img) { if (strpos($text, $smiley_text) !== false) { $text = ucp_preg_replace('%(?<=[>\\s])' . preg_quote($smiley_text, '%') . '(?=[^\\p{L}\\p{N}])%um', '<img src="' . $this->config['o_smilies_dir'] . $smiley_img . '" width="15" height="15" alt="' . substr($smiley_img, 0, strrpos($smiley_img, '.')) . '" />', $text); } } return substr($text, 1, -1); }
function censor_words($text) { global $cache, $db; static $censors; // If not already built in a previous call, build an array of censor words and their replacement text if (!isset($censors)) { $censors = $cache->get('censors'); if ($censors === Flux_Cache::NOT_FOUND) { $censors = array(); $query = $db->select(array('search_for' => 'c.search_for', 'replace_with' => 'c.replace_with'), 'censoring AS c'); $params = array(); $result = $query->run($params); foreach ($result as $cur_censor) { $cur_censor['search_for'] = '/(?<=[^\\p{L}\\p{N}])(' . str_replace('\\*', '[\\p{L}\\p{N}]*?', preg_quote($cur_censor['search_for'], '/')) . ')(?=[^\\p{L}\\p{N}])/iu'; $censors[$cur_censor['search_for']] = $cur_censor['replace_with']; } unset($result, $query, $params); $cache->set('censors', $censors); } } if (!empty($censors)) { $text = substr(ucp_preg_replace(array_keys($censors), array_values($censors), ' ' . $text . ' '), 1, -1); } return $text; }