- Add hard limit for smilies

git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@9772 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
Marek A. R 2009-07-17 13:56:24 +00:00
parent e4afce6075
commit 9b9298cfaa

View file

@ -231,7 +231,7 @@ class acp_icons
$data = $_images; $data = $_images;
} }
$colspan = (($mode == 'smilies') ? '7' : '5'); $colspan = (($mode == 'smilies') ? 7 : 5);
$colspan += ($icon_id) ? 1 : 0; $colspan += ($icon_id) ? 1 : 0;
$colspan += ($action == 'add') ? 2 : 0; $colspan += ($action == 'add') ? 2 : 0;
@ -348,6 +348,25 @@ class acp_icons
} }
} }
if ($mode == 'smilies' && $action == 'create')
{
$smiley_count = $this->item_count($table);
$addable_smileys_count = sizeof($images);
foreach ($images as $image)
{
if (!isset($image_add[$image]))
{
--$addable_smileys_count;
}
}
if ($smiley_count + $addable_smileys_count > SMILEY_LIMIT)
{
trigger_error(sprintf($user->lang['TOO_MANY_SMILIES'], SMILEY_LIMIT) . adm_back_link($this->u_action), E_USER_WARNING);
}
}
$icons_updated = 0; $icons_updated = 0;
$errors = array(); $errors = array();
foreach ($images as $image) foreach ($images as $image)
@ -495,7 +514,6 @@ class acp_icons
} }
} }
// The user has already selected a smilies_pak file // The user has already selected a smilies_pak file
if ($current == 'delete') if ($current == 'delete')
{ {
@ -541,6 +559,15 @@ class acp_icons
$db->sql_freeresult($result); $db->sql_freeresult($result);
} }
if ($mode == 'smilies')
{
$smiley_count = $this->item_count($table);
if ($smiley_count + sizeof($pak_ary) > SMILEY_LIMIT)
{
trigger_error(sprintf($user->lang['TOO_MANY_SMILIES'], SMILEY_LIMIT) . adm_back_link($this->u_action), E_USER_WARNING);
}
}
foreach ($pak_ary as $pak_entry) foreach ($pak_ary as $pak_entry)
{ {
$data = array(); $data = array();
@ -837,11 +864,7 @@ class acp_icons
$spacer = false; $spacer = false;
$pagination_start = request_var('start', 0); $pagination_start = request_var('start', 0);
$sql = "SELECT COUNT(*) AS count $item_count = $this->item_count($table);
FROM $table";
$result = $db->sql_query($sql);
$item_count = (int) $db->sql_fetchfield('count');
$db->sql_freeresult($result);
$sql = "SELECT * $sql = "SELECT *
FROM $table FROM $table
@ -877,6 +900,24 @@ class acp_icons
generate_pagination($this->u_action, $item_count, $config['smilies_per_page'], $pagination_start, true) generate_pagination($this->u_action, $item_count, $config['smilies_per_page'], $pagination_start, true)
); );
} }
/**
* Returns the count of smilies or icons in the database
*
* @param string $table The table of items to count.
* @return int number of items
*/
/* private */ function item_count($table)
{
global $db;
$sql = "SELECT COUNT(*) AS count
FROM $table";
$result = $db->sql_query($sql);
$item_count = (int) $db->sql_fetchfield('count');
$db->sql_freeresult($result);
return $item_count;
}
} }
?> ?>