1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-03-14 04:30:29 +01:00

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
This commit is contained in:
Meik Sievertsen 2003-08-28 17:32:18 +00:00
parent 5b6e9931b3
commit 964edc8693
4 changed files with 27 additions and 40 deletions

View File

@ -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

View File

@ -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';

View File

@ -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;
$sql = "SELECT *
FROM " . SMILIES_TABLE;
if (!$smilie)
{
return;
}
$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);

View File

@ -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;