Simple Machines Community Forum

Customizing SMF => Tips and Tricks => Topic started by: Owdy on December 29, 2003, 09:40:13 AM

Title: Limit smilies per post
Post by: Owdy on December 29, 2003, 09:40:13 AM
Is there way to ad some max number limit to smilies per post? Some people use smilies like corn flakes and its anoying.
Title: Re: Limit smilies per post
Post by: [Unknown] on December 29, 2003, 09:41:43 AM
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]
Title: Re: Limit smilies per post
Post by: Owdy on December 29, 2003, 09:45:49 AM
Wow, thanks! Ok, what happends if user passes that limit? Is there show non-image smilies instead?
Title: Re: Limit smilies per post
Post by: Owdy on December 29, 2003, 09:52:03 AM
Hmmm, that aint working:
$message = preg_replace($smileyfromcache, $smileytocache, $message, 4);
Title: Re: Limit smilies per post
Post by: [Unknown] on December 29, 2003, 09:56:54 AM
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]
Title: Re: Limit smilies per post
Post by: Owdy on December 29, 2003, 09:59:09 AM
Aaah, it limits only one kind of smilie per time. That works. How about that all kinds?
Title: Re: Limit smilies per post
Post by: [Unknown] on December 29, 2003, 10:01:24 AM
More difficult... would require parsing and stuff... at that point, imho, it would be better to simply turn off smileys entirely.

-[Unknown]
Title: Re: Limit smilies per post
Post by: Owdy on December 29, 2003, 10:02:50 AM
Ok, thanks!
Title: Re: Limit smilies per post
Post by: Grudge on December 29, 2003, 10:25:14 AM
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...
Title: Re: Limit smilies per post
Post by: Owdy on December 29, 2003, 10:27:59 AM
Yeah Grudge, that would be helpful. Please do so :D


Title: Re: Limit smilies per post
Post by: Grudge on December 29, 2003, 10:46:59 AM
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
Title: Re: Limit smilies per post
Post by: Owdy on December 31, 2003, 05:05:20 AM
Grudge, that worked perfectly. THank u! :D
Title: Re: Limit smilies per post
Post by: Owdy on December 31, 2003, 05:13:38 AM
Hmmm, how can i ad back link in that smoothly?
Title: Re: Limit smilies per post
Post by: Grudge on December 31, 2003, 06:02:16 AM
I assume you mean so members don't lose their posts... OK. I'll come up with something a sec :)
Title: Re: Limit smilies per post
Post by: Owdy on December 31, 2003, 06:03:56 AM
Yes, thats what i ment. :)
Title: Re: Limit smilies per post
Post by: Grudge on December 31, 2003, 06:11:45 AM
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
Title: Re: Limit smilies per post
Post by: Owdy on December 31, 2003, 08:08:20 AM
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
Title: Re: Limit smilies per post
Post by: Owdy on January 04, 2004, 05:42:55 AM
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';
Title: Re: Limit smilies per post
Post by: Grudge on January 04, 2004, 09:30:21 AM
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 :)
Title: Re: Limit smilies per post
Post by: Owdy on January 04, 2004, 09:41:38 AM
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';

}