Is there way to ad some max number limit to smilies per post? Some people use smilies like corn flakes and its anoying.
Hahahah... corn flakes... oh, that's great...
Yeah, it's easy ;). Open Sources/Subs.php... and.. find...
$message = preg_replace($smileyfromcache, $smileytocache, $message);
Replace it with:
$message = preg_replace($smileyfromcache, $smileytocache, $message, PUT MAX SMILEY NUMBER HERE!);
-[Unknown]
Wow, thanks! Ok, what happends if user passes that limit? Is there show non-image smilies instead?
Hmmm, that aint working:
$message = preg_replace($smileyfromcache, $smileytocache, $message, 4);
Hmm... it should...?
If I posted the :) smiley 5 times, with that in there, it should only parse the first four. Please note that it will parse the first four of ANY type of smiley, so if I do :) :( I can get 8 in. It'd take more work to make it only 4 of all kinds per post.
-[Unknown]
Aaah, it limits only one kind of smilie per time. That works. How about that all kinds?
More difficult... would require parsing and stuff... at that point, imho, it would be better to simply turn off smileys entirely.
-[Unknown]
Ok, thanks!
Kinda related. I made a tiny mod for YABB SE that limits the total amount of images (including smilies of course) in a post to a number set in the admin panel, and throws up an error if they go over it. If it helps I'll spend a few minutes making it SMF compatible and post it...
Yeah Grudge, that would be helpful. Please do so :D
OK. Well... my old code was *really* bad and this isn't much better but it's quick and easy.
Open sources/post.php
Find:
// Preparse code. (Zef)
if ($user_info['is_guest'])
$user_info['name'] = $_POST['guestname'];
preparsecode($_POST['message']);
Add directly under it:
$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))
fatal_error('You may not use more than ' . $smileyLimit . ' smileys in your post!');
Then just change $smileyLimit to the limit. Note - this counts smileys and images (it's better this way). It pretty n00bie like code but it should work and not mess up people posting code etc :)
If you want to count just smilies make the line starting $prev equal:
$prev = substr_count($_POST['message'],'<IMG') + substr_count($_POST['message'],'<img') + substr_count($_POST['message'],'[img') + substr_count($_POST['message'],'[IMG');
Hope this works - haven't tested it. No blamesies if it doesn't :P
Grudge, that worked perfectly. THank u! :D
Hmmm, how can i ad back link in that smoothly?
I assume you mean so members don't lose their posts... OK. I'll come up with something a sec :)
Yes, thats what i ment. :)
OK. This is gonna be harder ;) Remove the code you added before and instead add:
$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';
Just after:
if (htmltrim__recursive($_POST['message']) == '')
$post_errors[] = 'no_message';
if (strlen($_POST['message']) > $MaxMessLen)
$post_errors[] = 'long_message';
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:
<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>
BEFORE
<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>';
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
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
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:
$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';
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
<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>
It should INSTEAD read:
' . (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>' : '') . '
Sorry :)
Perfect! Thanks! :D
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';
}