Topic: How can I limit the amount of emoticons(smilies) that can be posted in

How can I limit the amount of emoticons(smilies) that can be posted in a post?

Re: How can I limit the amount of emoticons(smilies) that can be posted in

Have a look at the function do_smilies() in include/parser.php.

Re: How can I limit the amount of emoticons(smilies) that can be posted in

Reines wrote:

Have a look at the function do_smilies() in include/parser.php.

There is no do_smilies() function (or similar) in parser.php ....

Re: How can I limit the amount of emoticons(smilies) that can be posted in

err, yes there is...

//
// Convert a series of smilies to images
//
function do_smilies($text)
{
        global $smiley_text, $smiley_img;

        $text = ' '.$text.' ';

        $num_smilies = count($smiley_text);
        for ($i = 0; $i < $num_smilies; ++$i)
                $text = preg_replace("#(?<=.\W|\W.|^\W)".preg_quote($smiley_text[$i], '#')."(?=.\W|\W.|\W$)#m", '$1<img src="img/smilies/'.$smiley_img[$i].'" width="15" height="15" alt="'.substr($smiley_img[$i], 0, strrpos($smiley_img[$i], '.')).'" />$2', $text);

        return substr($text, 1, -1);
}

Re: How can I limit the amount of emoticons(smilies) that can be posted in

Smartys wrote:

err, yes there is...

//
// Convert a series of smilies to images
//
function do_smilies($text)
{
        global $smiley_text, $smiley_img;

        $text = ' '.$text.' ';

        $num_smilies = count($smiley_text);
        for ($i = 0; $i < $num_smilies; ++$i)
                $text = preg_replace("#(?<=.\W|\W.|^\W)".preg_quote($smiley_text[$i], '#')."(?=.\W|\W.|\W$)#m", '$1<img src="img/smilies/'.$smiley_img[$i].'" width="15" height="15" alt="'.substr($smiley_img[$i], 0, strrpos($smiley_img[$i], '.')).'" />$2', $text);

        return substr($text, 1, -1);
}

Ah, good call.

Now how do I edit it to only parse a max of 5 emoticons per post?

Re: How can I limit the amount of emoticons(smilies) that can be posted in

I'd try
FIND

$num_smilies = count($smiley_text);

AFTER, ADD

if ($num_smilies > 5)
        $num_smilies = 5;

Re: How can I limit the amount of emoticons(smilies) that can be posted in

Smartys wrote:

I'd try
FIND

$num_smilies = count($smiley_text);

AFTER, ADD

if ($num_smilies > 5)
        $num_smilies = 5;

That didn't quite do it. I was messing around with it a bit and couldn't get it.

Anyone got any ideas? :confused:

Re: How can I limit the amount of emoticons(smilies) that can be posted in

Oh, whoops, I know why big_smile
Yeah, it's not a simple thing to do that tongue
I guess the easiest way would be to write a new function (or mod do_smilies) to tell you how many smilies are in a post and use that knowledge in post.php and edit.php to reject posts that are over

Re: How can I limit the amount of emoticons(smilies) that can be posted in

Smartys wrote:

Oh, whoops, I know why big_smile
Yeah, it's not a simple thing to do that tongue
I guess the easiest way would be to write a new function (or mod do_smilies) to tell you how many smilies are in a post and use that knowledge in post.php and edit.php to reject posts that are over

I hate to ask, but i'm not really good enough in php to be able to do that. If you (or anyone else) has some free time, maybe helping me out with creating that code?

smile

TIA!

10 (edited by Smartys 2006-06-02 22:36)

Re: How can I limit the amount of emoticons(smilies) that can be posted in

OK

I think this should be the same in both files

FIND

    // Validate BBCode syntax
    if ($pun_config['p_message_bbcode'] == '1' && strpos($message, '[') !== false && strpos($message, ']') !== false)
    {
        require PUN_ROOT.'include/parser.php';
        $message = preparse_bbcode($message, $errors);
    }

AFTER, ADD

require_once PUN_ROOT.'include/parser.php';
if (check_smilies($message) > 5)
    $errors[] = 'You have too many smilies in your post: the maximum is 5';

parser.php

Add this to the end

function check_smilies($text)
{
    global $smiley_text, $smiley_img;

    $text = ' '.$text.' ';

    $num_smilies = count($smiley_text);
        
    $num_message_smilies = 0;

    for ($i = 0; $i < $num_smilies; ++$i)
    {
        $text = preg_replace("#(?<=.\W|\W.|^\W)".preg_quote($smiley_text[$i], '#')."(?=.\W|\W.|\W$)#m", '$1<img src="img/smilies/'.$smiley_img[$i].'" width="15" height="15" alt="'.substr($smiley_img[$i], 0, strrpos($smiley_img[$i], '.')).'" />$2', $text, -1, $count);

        $num_message_smilies = $num_message_smilies + $count;
    }
    
    return $num_message_smilies;
}

Re: How can I limit the amount of emoticons(smilies) that can be posted in

Smartys,

WOW, thanks for the quick reply.

However, that still isn't doing anything. sad

Re: How can I limit the amount of emoticons(smilies) that can be posted in

Works fine for me

Although I would make one change:
Remove the new code I had you add to edit.php/post.php and follow this instead:

edit.php
FIND

    $hide_smilies = isset($_POST['hide_smilies']) ? intval($_POST['hide_smilies']) : 0;
    if ($hide_smilies != '1') $hide_smilies = '0';

AFTER, ADD

    require_once PUN_ROOT.'include/parser.php';
    if (check_smilies($message) > 5 && !$hide_smilies)
        $errors[] = 'You have too many smilies in your post: the maximum is 5';

post.php
FIND

    $hide_smilies = isset($_POST['hide_smilies']) ? 1 : 0;
    $subscribe = isset($_POST['subscribe']) ? 1 : 0;

AFTER, ADD

    require_once PUN_ROOT.'include/parser.php';
    if (check_smilies($message) > 5 && !$hide_smilies)
        $errors[] = 'You have too many smilies in your post: the maximum is 5';

That way people who aren't using smilies aren't affected

Keep in mind this isn't meant to change existing posts, just to forbid new posts with too many smilies

Re: How can I limit the amount of emoticons(smilies) that can be posted in

Smartys,

I appreciate your help, but I can't figure out why it isn't working for me! I'm doing it exactly as you say... sad

Re: How can I limit the amount of emoticons(smilies) that can be posted in

And when you try and post more than 5 smilies it allows it?

Re: How can I limit the amount of emoticons(smilies) that can be posted in

Smartys wrote:

And when you try and post more than 5 smilies it allows it?

Yes

Re: How can I limit the amount of emoticons(smilies) that can be posted in

Link?

Re: How can I limit the amount of emoticons(smilies) that can be posted in

Smartys wrote:

Link?

http://ffc.fcstuff.com/viewforum.php?id=3

Just try a test post as a guest user

18 (edited by Smartys 2006-06-02 23:45)

Re: How can I limit the amount of emoticons(smilies) that can be posted in

I'm getting a bunch of errors like this
Warning: Wrong parameter count for preg_replace() in /home/.ester/million1/ffc.fcstuff.com/include/parser.php on line 922

Re: How can I limit the amount of emoticons(smilies) that can be posted in

Smartys wrote:

I'm getting a bunch of errors like this
Warning: Wrong parameter count for preg_replace() in /home/.ester/million1/ffc.fcstuff.com/include/parser.php on line 922

Hm. I didn't get those when I tested...

20 (edited by Smartys 2006-06-02 23:50)

Re: How can I limit the amount of emoticons(smilies) that can be posted in

viperjosh wrote:
Smartys wrote:

I'm getting a bunch of errors like this
Warning: Wrong parameter count for preg_replace() in /home/.ester/million1/ffc.fcstuff.com/include/parser.php on line 922

Hm. I didn't get those when I tested...

I got them because I entered a username that was already taken: you don't see them when you post normally because you redirect away from the page after posting

Re: How can I limit the amount of emoticons(smilies) that can be posted in

Hmm.. I restored the code back to original. I'll try to re-enter it and see what happens.

Re: How can I limit the amount of emoticons(smilies) that can be posted in

Nope. Re entering the code did nothing. Also, I did see that error when trying to use a registered username, this was after entering your code.

Re: How can I limit the amount of emoticons(smilies) that can be posted in

Can you email me a copy of your parser.php (smartys@gmail.com)

Re: How can I limit the amount of emoticons(smilies) that can be posted in

Smartys wrote:

Can you email me a copy of your parser.php (smartys@gmail.com)

on its way smile

Re: How can I limit the amount of emoticons(smilies) that can be posted in

viperjosh wrote:
Smartys wrote:

Can you email me a copy of your parser.php (smartys@gmail.com)

on its way smile

The copy you sent me doesn't have the new function in it wink