[Beta] Limit smilies per Post 0.9.6

A place for MOD Authors to post and receive feedback on MODs still in development. No MODs within this forum should be used within a live environment! No new topics are allowed in this forum.
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

IMPORTANT: MOD Development Forum rules

On February 1, 2009 this forum will be set to read only as part of retiring of phpBB2.
R. U. Serious
Registered User
Posts: 830
Joined: Mon Feb 11, 2002 2:07 pm

[Beta] Limit smilies per Post 0.9.6

Post by R. U. Serious »

Try this out and tell me if it works for you, I hope I have not forgotten anything. Also please look if the instructions are ok.

If somebody wants to add an adminCP-option to replace the hardcoded '8', please go ahead. ;)

Code: Select all

############################################################## 
## MOD Title: LimitSmiliesPerPost
## MOD Author: R. U. Serious <[email protected]> www.handykoelsch.de
## MOD Description: This will display an error message, when the number of smilies
##		    used in a post is more than 8. 
## MOD Version: 0.9.6 
## 
## Installation Level: easy 
## Installation Time: 8 Minutes 
## Files To Edit: posting.php,
##                    includes/bbcode.php,
##                    languages/lang_english/lang_main.php
############################################################## 
## For Security Purposes, Please Check: http://www.phpbb.com/mods/downloads/ for the 
## latest version of this MOD. Downloading this MOD from other sites could cause malicious code 
## to enter into your phpBB Forum. As such, phpBB will not offer support for MOD's not offered 
## in our MOD-Database, located at: http://www.phpbb.com/mods/downloads/ 
############################################################## 
## Author Notes:  
## 
############################################################## 
## Before Adding This MOD To Your Forum, You Should Back Up All Files Related To This MOD 
############################################################## 

# 
#-----[ OPEN ]------------------------------------------ 
# 
includes/bbcode.php

# 
#-----[ FIND ]------------------------------------------ 
# 
function smiley_sort($a, $b)

# 
#-----[ BEFORE, ADD ]------------------------------------------ 
# 
//BEGIN LimitSmiliesPerPost MOD
function smilies_count($message) 
{ 
   static $orig, $repl; 

   if (!isset($orig)) 
   { 
      global $db, $board_config; 
      $orig = $repl = array(); 

      $sql = 'SELECT code, smile_url FROM ' . SMILIES_TABLE; 

      if( !$result = $db->sql_query($sql) ) 
      { 
         message_die(GENERAL_ERROR, "Couldn't obtain smilies data", "", __LINE__, __FILE__, $sql); 
      } 

      $smilies = $db->sql_fetchrowset($result); 

      usort($smilies, 'smiley_sort'); 
      $number=0;
      for($i = 0; $i < count($smilies); $i++) 
      { 
         $orig[] = "/(?<=.\W|\W.|^\W)" . phpbb_preg_quote($smilies[$i]['code'], "/") . "(?=.\W|\W.|\W$)/"; 
         $repl[] = '<img src="'. $board_config['smilies_path'] . '/' . $smilies[$i]['smile_url'] . '" alt="' . $smilies[$i]['smile_url'] . '" border="0" />'; 

	     $number += preg_match_all($orig[$i], ' ' . $message . ' ', $repl ); 
//		 $message = preg_replace($orig[$i], $repl[$i], ' ' . $message . ' '); 
//		 $message = substr($message, 1, -1); 
      } 
   } 
   return $number; 
}
//END LimitSmiliesPerPost MOD

# 
#-----[ OPEN ]------------------------------------------ 
# 
language/lang_english/lang_main.php

# 
#-----[ FIND ]------------------------------------------ 
# 
//
// That's all Folks!
// -------------------------------------------------

# 
#-----[ AFTER, ADD ]------------------------------------------ 
# 
$lang['limitsmilies_error'] = "You can use a maximum of 8 smilies in a single post.<br /><br /> However your current post contains %s smilies."; // %s - number of smilies


# 
#-----[ OPEN ]------------------------------------------ 
# 
posting.php

# 
#-----[ FIND ]------------------------------------------ 
# This is for preview-warning
obtain_word_list($orig_word, $replacement_word);

# 
#-----[ AFTER, ADD ]------------------------------------------ 
# 
		$number_of_smilies=smilies_count($message);
		if ($number_of_smilies > 8) 
		{
			message_die(GENERAL_ERROR, sprintf( $lang['limitsmilies_error'], $number_of_smilies));
		}


# 
#-----[ FIND ]------------------------------------------ 
# This is for posting/submit-warning
			$bbcode_uid = '';

# 
#-----[ AFTER, ADD ]------------------------------------------ 
# 
			$number_of_smilies=smilies_count($message);
			if ($number_of_smilies > 8) 
			{
				message_die(GENERAL_ERROR, 'test'.sprintf( $lang['limitsmilies_error'], $number_of_smilies));
			}


# 
#-----[ SAVE/CLOSE ALL FILES ]------------------------------------------ 
# 
# EoM 
Last edited by R. U. Serious on Wed Sep 03, 2003 8:41 am, edited 5 times in total.
Narc0sis
Registered User
Posts: 662
Joined: Tue Apr 09, 2002 12:59 am
Contact:

Post by Narc0sis »

it works, only one small problem. i installed it and typed a post with 9 smilies in it to see the error message and it said

"testYou can use a maximum of 8 smilies in a single post.

However your current post contains 9 smilies."


is there any way i can get rid of that test word in the message?

also, not that it makes any difference in this mod, but i think its standard to put stuff before "That's all Folks! " in the lang file, not after.
User avatar
IDB
Registered User
Posts: 67
Joined: Thu Jan 17, 2002 10:52 pm
Location: Milwaukee, Wi
Contact:

Post by IDB »

Delete the word "test" in the last part of the code:


Change:

Code: Select all

# 
#-----[ AFTER, ADD ]------------------------------------------ 
# 
         $number_of_smilies=smilies_count($message); 
         if ($number_of_smilies > 8) 
         { 
            message_die(GENERAL_ERROR, 'test'.sprintf( $lang['limitsmilies_error'], $number_of_smilies)); 
         } 
To:

Code: Select all

# 
#-----[ AFTER, ADD ]------------------------------------------ 
# 
         $number_of_smilies=smilies_count($message); 
         if ($number_of_smilies > 8) 
         { 
            message_die(GENERAL_ERROR, sprintf( $lang['limitsmilies_error'], $number_of_smilies)); 
         } 
Regards, Ian.
Narc0sis
Registered User
Posts: 662
Joined: Tue Apr 09, 2002 12:59 am
Contact:

Post by Narc0sis »

thanks, i wasnt sure how to take that outta there
Duskette
Registered User
Posts: 118
Joined: Mon Jan 07, 2002 3:18 am
Location: Singapore
Contact:

Post by Duskette »

will having a back button together with the error message make this mod more user-friendly? :D
R. U. Serious
Registered User
Posts: 830
Joined: Mon Feb 11, 2002 2:07 pm

Post by R. U. Serious »

Thanks, I corrected that test-thingy. :oops:

edit @ tuck below: Yes, I corrected that, too. :D
Last edited by R. U. Serious on Tue Oct 22, 2002 6:45 pm, edited 1 time in total.
User avatar
tuck
Registered User
Posts: 222
Joined: Mon Jul 01, 2002 8:13 pm

just

Post by tuck »

a small thing on the how-to, you wrote to find /language/lang_english/
without pointing to the file which is lang_main.php :)

Ps: you can't even imagine how much this mod can be useful for me :D

Pps: can you do something to limit images? I tried a mod by fubonis but it does not work :cry:
Prisoner
Registered User
Posts: 8
Joined: Tue Sep 24, 2002 10:07 pm
Contact:

Post by Prisoner »

Worked fine for my board.

I did change it to a limit of 5 per message.

Thank you.
User avatar
tuck
Registered User
Posts: 222
Joined: Mon Jul 01, 2002 8:13 pm

It

Post by tuck »

works fine for me too, but users can post how many smilies they want simply using the bbcode (img) (/img) :wink:
That's why I asked for something on images too.
R. U. Serious
Registered User
Posts: 830
Joined: Mon Feb 11, 2002 2:07 pm

Re: It

Post by R. U. Serious »

tuck wrote: works fine for me too, but users can post how many smilies they want simply using the bbcode (img) (/img) :wink:
That's why I asked for something on images too.


If you allow only one image they can still compose an image consisting of many smilies next to each other and post that. You see, it is just about raising the bar and communicating what is desired/allowed and what is not. ;)
Ralendil
Registered User
Posts: 410
Joined: Thu May 30, 2002 9:13 pm
Location: France
Contact:

Post by Ralendil »

The mod to limit images and smilies already exist. (search in this forum)

Thx RU Serious. This was I have requested long time ago :)

Well done.
User avatar
tuck
Registered User
Posts: 222
Joined: Mon Jul 01, 2002 8:13 pm

I know

Post by tuck »

thanks but it does not work for me and anyway smiles limitations is not working
letimeric
Registered User
Posts: 59
Joined: Wed Sep 25, 2002 1:24 am

Post by letimeric »

its working but, when click back button and delete the smilies to the number specific, it add these smilies to the previous number of smilies

like
when post, 9
click on submit, i get the general error message
when click back, and delete 1
and click on submit, i get the general error message with 17 smilies being used...how come?
and click back, it keep adding again and again

this is error from quick reply box

thank you
Ralendil
Registered User
Posts: 410
Joined: Thu May 30, 2002 9:13 pm
Location: France
Contact:

Post by Ralendil »

letimeric wrote: its working but, when click back button and delete the smilies to the number specific, it add these smilies to the previous number of smilies

like
when post, 9
click on submit, i get the general error message
when click back, and delete 1
and click on submit, i get the general error message with 17 smilies being used...how come?
and click back, it keep adding again and again

this is error from quick reply box

thank you


I don't know the version of the quick reply you use (Smartor, Ohoo, Rusty version) but with Ohoo version it works perfectly...
this bug not appear...
letimeric
Registered User
Posts: 59
Joined: Wed Sep 25, 2002 1:24 am

Post by letimeric »

i'm using Advance Quick Reply with quote
Post Reply

Return to “[2.0.x] MODs in Development”