• Welcome to Simple Machines Community Forum. Please login or sign up.
January 18, 2022, 11:21:49 PM

News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord


Limit smilies per post

Started by Owdy, December 29, 2003, 09:40:13 AM

Previous topic - Next topic

Owdy

Is there way to ad some max number limit to smilies per post? Some people use smilies like corn flakes and its anoying.
Former Lead Support Specialist

Tarvitsetko apua SMF foorumisi kanssa? Otan työtehtäviä vastaan, lue:http://www.simplemachines.org/community/index.php?topic=375918.0

[Unknown]

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]

Owdy

Wow, thanks! Ok, what happends if user passes that limit? Is there show non-image smilies instead?
Former Lead Support Specialist

Tarvitsetko apua SMF foorumisi kanssa? Otan työtehtäviä vastaan, lue:http://www.simplemachines.org/community/index.php?topic=375918.0

Owdy

Hmmm, that aint working:
$message = preg_replace($smileyfromcache, $smileytocache, $message, 4);
Former Lead Support Specialist

Tarvitsetko apua SMF foorumisi kanssa? Otan työtehtäviä vastaan, lue:http://www.simplemachines.org/community/index.php?topic=375918.0

[Unknown]

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]

Owdy

Aaah, it limits only one kind of smilie per time. That works. How about that all kinds?
Former Lead Support Specialist

Tarvitsetko apua SMF foorumisi kanssa? Otan työtehtäviä vastaan, lue:http://www.simplemachines.org/community/index.php?topic=375918.0

[Unknown]

More difficult... would require parsing and stuff... at that point, imho, it would be better to simply turn off smileys entirely.

-[Unknown]

Owdy

Former Lead Support Specialist

Tarvitsetko apua SMF foorumisi kanssa? Otan työtehtäviä vastaan, lue:http://www.simplemachines.org/community/index.php?topic=375918.0

Grudge

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...
I'm only a half geek really...

Owdy

Yeah Grudge, that would be helpful. Please do so :D


Former Lead Support Specialist

Tarvitsetko apua SMF foorumisi kanssa? Otan työtehtäviä vastaan, lue:http://www.simplemachines.org/community/index.php?topic=375918.0

Grudge

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
I'm only a half geek really...

Owdy

Grudge, that worked perfectly. THank u! :D
Former Lead Support Specialist

Tarvitsetko apua SMF foorumisi kanssa? Otan työtehtäviä vastaan, lue:http://www.simplemachines.org/community/index.php?topic=375918.0

Owdy

Hmmm, how can i ad back link in that smoothly?
Former Lead Support Specialist

Tarvitsetko apua SMF foorumisi kanssa? Otan työtehtäviä vastaan, lue:http://www.simplemachines.org/community/index.php?topic=375918.0

Grudge

I assume you mean so members don't lose their posts... OK. I'll come up with something a sec :)
I'm only a half geek really...

Owdy

Former Lead Support Specialist

Tarvitsetko apua SMF foorumisi kanssa? Otan työtehtäviä vastaan, lue:http://www.simplemachines.org/community/index.php?topic=375918.0

Grudge

December 31, 2003, 06:11:45 AM #15 Last Edit: December 31, 2003, 06:13:17 AM by Grudge
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
I'm only a half geek really...

Owdy

December 31, 2003, 08:08:20 AM #16 Last Edit: December 31, 2003, 08:29:53 AM by 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
Former Lead Support Specialist

Tarvitsetko apua SMF foorumisi kanssa? Otan työtehtäviä vastaan, lue:http://www.simplemachines.org/community/index.php?topic=375918.0

Owdy

January 04, 2004, 05:42:55 AM #17 Last Edit: January 04, 2004, 05:49:48 AM by ­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:
$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';
Former Lead Support Specialist

Tarvitsetko apua SMF foorumisi kanssa? Otan työtehtäviä vastaan, lue:http://www.simplemachines.org/community/index.php?topic=375918.0

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

<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 :)
I'm only a half geek really...

Owdy

January 04, 2004, 09:41:38 AM #19 Last Edit: May 30, 2004, 05:31:52 PM by Owdy
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';

}

Former Lead Support Specialist

Tarvitsetko apua SMF foorumisi kanssa? Otan työtehtäviä vastaan, lue:http://www.simplemachines.org/community/index.php?topic=375918.0

Advertisement: