diff options
author | Meik Sievertsen <acydburn@phpbb.com> | 2003-08-28 17:32:18 +0000 |
---|---|---|
committer | Meik Sievertsen <acydburn@phpbb.com> | 2003-08-28 17:32:18 +0000 |
commit | 964edc86936fba9f0729cc8930cc3a0c75b25998 (patch) | |
tree | c213179d6c4c359ccb38bd64b78884449c00fa40 /phpBB/includes/message_parser.php | |
parent | 5b6e9931b3ecca5efc8087f7d9ee7254153b8d09 (diff) | |
download | forums-964edc86936fba9f0729cc8930cc3a0c75b25998.tar forums-964edc86936fba9f0729cc8930cc3a0c75b25998.tar.gz forums-964edc86936fba9f0729cc8930cc3a0c75b25998.tar.bz2 forums-964edc86936fba9f0729cc8930cc3a0c75b25998.tar.xz forums-964edc86936fba9f0729cc8930cc3a0c75b25998.zip |
saved one query by moving max smilie check to the emoticons function
git-svn-id: file:///svn/phpbb/trunk@4451 89ea8834-ac86-4346-8a33-228a782c2dd0
Diffstat (limited to 'phpBB/includes/message_parser.php')
-rw-r--r-- | phpBB/includes/message_parser.php | 61 |
1 files changed, 24 insertions, 37 deletions
diff --git a/phpBB/includes/message_parser.php b/phpBB/includes/message_parser.php index 665e9bb982..16b6208975 100644 --- a/phpBB/includes/message_parser.php +++ b/phpBB/includes/message_parser.php @@ -79,37 +79,7 @@ class parse_message if (!strlen($this->message) || (intval($config['max_post_chars']) && strlen($this->message) > intval($config['max_post_chars']))) { $this->warn_msg[] = (!strlen($this->message)) ? $user->lang['TOO_FEW_CHARS'] : $user->lang['TOO_MANY_CHARS']; - } - - // Smiley check - if (intval($config['max_post_smilies']) && $smilies) - { - // NOTE: couldn't we move this to emoticons()? they both use the same rowset - $sql = "SELECT code - FROM " . SMILIES_TABLE; - $result = $db->sql_query($sql); - - $match = 0; - while ($row = $db->sql_fetchrow($result)) - { - if (preg_match_all('#('. preg_quote($row['code'], '#') . ')#', $this->message, $matches)) - { - $match++; - } - - if ($match > intval($config['max_post_smilies'])) - { - $this->warn_msg[] = $user->lang['TOO_MANY_SMILIES']; - break; - } - } - $db->sql_freeresult($result); - unset($matches); - } - - if ($this->warn_msg) - { - return implode('<br />', $this->warn_msg); + return $this->warn_msg; } $this->html($html); @@ -636,12 +606,17 @@ class parse_message } } - function emoticons($smile) + function emoticons($smilie) { - global $db, $user, $phpbb_root_path; + global $db, $user, $phpbb_root_path, $config; + + if (!$smilie) + { + return; + } - $sql = "SELECT * - FROM " . SMILIES_TABLE; + $sql = 'SELECT * + FROM ' . SMILIES_TABLE; $result = $db->sql_query($sql); if ($row = $db->sql_fetchrow($result)) @@ -649,11 +624,23 @@ class parse_message $match = $replace = array(); do { - $match[] = "#(?<=.\W|\W.|^\W)" . preg_quote($row['code'], '#') . "(?=.\W|\W.|\W$)#"; - $replace[] = '<!-- s' . $row['code'] . ' --><img src="{SMILE_PATH}/' . $phpbb_root_path . $row['smile_url'] . '" border="0" alt="' . $row['emoticon'] . '" title="' . $row['emoticon'] . '" /><!-- s' . $row['code'] . ' -->'; + $match[] = '#(' . preg_quote($row['code'], '#') . ')#'; +// $match[] = "#(?<=.\W|\W.|^\W)" . preg_quote($row['code'], '#') . "(?=.\W|\W.|\W$)#"; + $replace[] = '<!-- s' . $row['code'] . ' --><img src="{SMILE_PATH}/' . $row['smile_url'] . '" border="0" alt="' . $row['emoticon'] . '" title="' . $row['emoticon'] . '" /><!-- s' . $row['code'] . ' -->'; } while ($row = $db->sql_fetchrow($result)); + if ($config['max_post_smilies']) + { + $num_matches = preg_match_all('#' . str_replace('#', '', implode('|', $match)) . '#', $this->message, $matches); + + if ($num_matches !== FALSE && $num_matches > intval($config['max_post_smilies'])) + { + $this->warn_msg[] = $user->lang['TOO_MANY_SMILIES']; + return; + } + } + $this->message = preg_replace($match, $replace, ' ' . $this->message . ' '); } $db->sql_freeresult($result); |