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?
You are not logged in. Please login or register.
PunBB Forums → PunBB 1.2 troubleshooting → 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?
Have a look at the function do_smilies() in include/parser.php.
Have a look at the function do_smilies() in include/parser.php.
There is no do_smilies() function (or similar) in parser.php ....
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);
}
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?
I'd try
FIND
$num_smilies = count($smiley_text);
AFTER, ADD
if ($num_smilies > 5)
$num_smilies = 5;
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:
Oh, whoops, I know why
Yeah, it's not a simple thing to do that
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
Oh, whoops, I know why
Yeah, it's not a simple thing to do that
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?
TIA!
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;
}
Smartys,
WOW, thanks for the quick reply.
However, that still isn't doing anything.
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
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...
And when you try and post more than 5 smilies it allows it?
And when you try and post more than 5 smilies it allows it?
Yes
Link?
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
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...
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 922Hm. 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
Hmm.. I restored the code back to original. I'll try to re-enter it and see what happens.
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.
Can you email me a copy of your parser.php (smartys@gmail.com)
Can you email me a copy of your parser.php (smartys@gmail.com)
on its way
Smartys wrote:Can you email me a copy of your parser.php (smartys@gmail.com)
on its way
The copy you sent me doesn't have the new function in it
PunBB Forums → PunBB 1.2 troubleshooting → How can I limit the amount of emoticons(smilies) that can be posted in
Powered by PunBB, supported by Informer Technologies, Inc.