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 | |
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')
-rw-r--r-- | phpBB/includes/functions.php | 2 | ||||
-rw-r--r-- | phpBB/includes/functions_posting.php | 2 | ||||
-rw-r--r-- | phpBB/includes/message_parser.php | 61 | ||||
-rw-r--r-- | phpBB/posting.php | 2 |
4 files changed, 27 insertions, 40 deletions
diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index a2f8ad7138..8f53c55e8d 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -836,7 +836,7 @@ function obtain_attach_extensions(&$extensions) } else { - // Don't count on forbidden extensions table, because it is not allowed to allow forbidden extensions at all + // The rule is to only allow those extensions defined. ;) $sql = 'SELECT e.extension, g.* FROM ' . EXTENSIONS_TABLE . ' e, ' . EXTENSION_GROUPS_TABLE . ' g WHERE e.group_id = g.group_id diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index a25c44f5e3..f06da1e412 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -38,7 +38,7 @@ function generate_smilies($mode) ); } - $sql = 'SELECT emoticon, code, smile_url, smile_width, smile_height + $sql = 'SELECT * FROM ' . SMILIES_TABLE . (($mode == 'inline') ? ' WHERE display_on_posting = 1 ' : '') . ' ORDER BY smile_order'; 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); diff --git a/phpBB/posting.php b/phpBB/posting.php index 28dc49a8a4..0fdf3bf7b6 100644 --- a/phpBB/posting.php +++ b/phpBB/posting.php @@ -521,7 +521,7 @@ if ($submit || $preview || $refresh) // Faster than crc32 - $check_value = (($enable_html+1) << 16) + (($enable_bbcode+1) << 8) + (($enable_smilies+1) << 4) + (($enable_urls+1) << 2) + (($enable_sig+1) << 1); + $check_value = (($preview || $refresh) && isset($_POST['status_switch'])) ? intval($_POST['status_switch']) : (($enable_html+1) << 16) + (($enable_bbcode+1) << 8) + (($enable_smilies+1) << 4) + (($enable_urls+1) << 2) + (($enable_sig+1) << 1); $status_switch = (isset($_POST['status_switch']) && intval($_POST['status_switch']) != $check_value) ? true : false; |