Customizing SMF > Tips and Tricks
Limit smilies per post
Grudge:
OK. This is gonna be harder ;) Remove the code you added before and instead add:
--- Code: --- $smileyLimit = 12;
$prev = substr_count($_POST['message'],'<IMG') + substr_count($_POST['message'],'<img');
$tempmsg = DoUBBC($_POST['message'], 1);
if ((substr_count($tempmsg,'<IMG') + substr_count($tempmsg,'<img')) > ($prev + $smileyLimit))
$post_errors[] = 'smiley_limit';
--- End code ---
Just after:
--- Code: --- if (htmltrim__recursive($_POST['message']) == '')
$post_errors[] = 'no_message';
if (strlen($_POST['message']) > $MaxMessLen)
$post_errors[] = 'long_message';
--- End code ---
That was in sources/post.php. You now have to make a change in themes/default/post.php. Where you put this is up to you but I'm putting it above the subject box:
Add:
--- Code: --- <tr>
<td align="center" colspan="2">
<b' . (isset($context['post_error']['smiley_limit']) ? ' style="color: #FF0000;"' : '') . '>You May Not Use More Than 12 Smileys</b>
</td>
</tr>
--- End code ---
BEFORE
--- Code: --- <tr>
<td align="right">
<b' . (isset($context['post_error']['no_subject']) ? ' style="color: #FF0000;"' : '') . '>' . $txt[70] . ':</b>
</td>
<td>
<input type="text" name="subject"', $context['subject'] == '' ? '' : ' value="' . $context['subject'] . '"', ' size="40" maxlength="80" tabindex="1" />
</td>
</tr>';
--- End code ---
OK. That is all you need to change hopefully. It's not brilliant code once more but it should work. If they go over the limit it will return to the post screen with that error showing in red as if they had put in no subject etc.
Haven't tested it but it should work :D
Owdy:
And this counts only smilies? :)
edit: i used that count only smilies part from first code and now it works like a charm! Thank u !! :D
Owdy:
I just notised that text "You May Not Use More Than 12 Smileys" are showing in that post page every time. First it is black, then if u over that limit it turns red. Any ideas why? It shouldnt be there unless u make that error. I think that black version didnt are there earlyer.... strange....
Current code:
--- Code: ---$smileyLimit = 3;
$prev = substr_count($_POST['message'],'<IMG') + substr_count($_POST['message'],'<img') + substr_count($_POST['message'],'[img') + substr_count($_POST['message'],'[IMG');
$tempmsg = DoUBBC($_POST['message'], 1);
if ((substr_count($tempmsg,'<IMG') + substr_count($tempmsg,'<img')) > ($prev + $smileyLimit))
$post_errors[] = 'smiley_limit';
--- End code ---
Grudge:
Woooo.. big mistake on my part. Not with the code above though. Look at my post above where I told you to add this to themes/default/post.php
--- Code: --- <tr>
<td align="center" colspan="2">
<b' . (isset($context['post_error']['smiley_limit']) ? ' style="color: #FF0000;"' : '') . '>You May Not Use More Than 12 Smileys</b>
</td>
</tr>
--- End code ---
It should INSTEAD read:
--- Code: ---' . (isset($context['post_error']['smiley_limit']) ? '<tr>
<td align="center" colspan="2">
<b style="color: #FF0000;">You May Not Use More Than 12 Smileys</b>
</td>
</tr>' : '') . '
--- End code ---
Sorry :)
Owdy:
Perfect! Thanks! :D
--- Code: ---if (isset($_POST['message']))
{
$smileyLimit = 3;
$prev = substr_count($_POST['message'],'<IMG') + substr_count($_POST['message'],'<img') + substr_count($_POST['message'],'[img') + substr_count($_POST['message'],'[IMG');
$tempmsg = DoUBBC($_POST['message'], 1);
if ((substr_count($tempmsg,'<IMG') + substr_count($tempmsg,'<img')) > ($prev + $smileyLimit))
$post_errors[] = 'smiley_limit';
}
--- End code ---
Navigation
[0] Message Index
[*] Previous page
Go to full version