HMBeaty Posted November 2, 2011 Share Posted November 2, 2011 Good afternoon everyone First off, I'm in the process of creating a modification for another user on vBulletin which lets you set the minimum character count a member is allowed to post. I made that pretty quickly using the default code from vBulletin, however, now he's found that his users are getting around this new restriction he's put in place. Here is the code I'm currently using: global $vbulletin; $restricted_groups = explode(',', $vbulletin->options['usml_postminchar_usergroups']); $restricted_users = explode(',', $vbulletin->options['usml_postminchar_users']); $this->registry->options['usml_postminchar_count'] = intval($this->registry->options['usml_postminchar_count']); if ($vbulletin->options['usml_postminchar_onoff']) { if (in_array($vbulletin->userinfo['userid'], $restricted_users) OR is_member_of($vbulletin->userinfo, $restricted_groups)) { if ($this->registry->options['usml_postminchar_count'] <= 0) { $this->registry->options['usml_postminchar_count'] = 1; } if (vbstrlen(strip_bbcode($pagetext, $this->registry->options['ignorequotechars'])) < $this->registry->options['usml_postminchar_count']) { $this->error('tooshort', $this->registry->options['usml_postminchar_count']); return false; } } } The new addition to this that he's asking for is to count spaces as characters, and exclude all.....non-letters from the character count (such as !@#$%^&*:;"'{}[]<>,./\|) Could anyone help me figure out how to do this please? Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/250309-counting-spaces-as-characters-and-excluding-from-character-count/ Share on other sites More sharing options...
xyph Posted November 2, 2011 Share Posted November 2, 2011 <?php // Minimum amount of characters $minsize = 15; // Characters that 'count' - space, a-z, A-Z $counted = array_merge( array(' '), range('a','z'), range('A','Z') ); // Content to check $post = 'This is a post that must match the minimum size'; // Split post into individual characters $post_split = str_split( $post ); // This will hold our current count of characters that 'count' $count = 0; // Loop through characters until $count >= $minsize foreach( $post_split as $char ) { if( in_array($char, $counted) ) $count++; if( $count >= $minsize ) break; } // Double check that $minsize has been met if( $count >= $minsize ) echo 'Post was long enough'; else echo 'Post not long enough'; ?> It's not exactly efficient, and it won't work for accented characters, though it could be made to work with them. Keep in mind, the more characters you want to 'allow' the longer the in_array will take to execute. I don't know of any other way to do it, but this seems like an odd requirement. Perhaps if you specified the actual problem we could provide a better way to accomplish it. Quote Link to comment https://forums.phpfreaks.com/topic/250309-counting-spaces-as-characters-and-excluding-from-character-count/#findComment-1284342 Share on other sites More sharing options...
HMBeaty Posted November 2, 2011 Author Share Posted November 2, 2011 I guess the best way I could explain the request would be to post the PM conversation between us. So here we are .... Do you have AIM' date=' Yahoo or MSN messenger?[/quote'] Hi Brooks, Sorry for my late reply. I went to bed and couldn't get your last message. If you have gmail I can use valdet.shehu@gmail.com for chat. I don't use Yahoo or MSN anymore. If need be I will create a new account and be ready. I am at work so chatting isn't allowed on firewall but I can be available for chat after 2 PM EST. Does that work for you? I appreciate your time and I look forward to your reply. Best regards, Val. No, I won't be available at that time as I don't get off work until 8pm EST. I went ahead and whipped something up though if you want to go ahead and test it. It was developed on my vB 4 test site, but should still work for vB 3 since a few of my other modifications use a similar code to function. You can download it here: http://www.usmilitarylife.com/minchar.zip Let me know how it works for you Brooks, this works very well. I just installed it, tested it with one of my dummy accounts and it works just as I expected. Excellent work. One thing which I would ask, is if you can incorporate a solution so users are prevented from bypassing the character limit, when they just type blank spaces etc... In other words blank spaces not to be counted. There is a solution for that here, but it is archived and I cannot access it. Maybe you as a moderator can access the files here http://www.vbulletin.org/forum/showthread.php?t=67263 My users are quite savvy and would probably find a way to bypass the limits with blank spaces. Nevertheless, it's wonderful work and I really appreciate your time. Thank you very much. My best regards, Val from Kosovo. Incidentally, as you have a website about military life, families etc... are/were you also a US servicemember? I served as an interpreter for US Army for 4 years and I have many many great memories. Correction, I am not a moderator I'm an advisor, therefore, I don't have permission to access that particular modification. I am also (at the moment) not quite sure on how to count blank spaces as characters, but I'm sure I can figure something out Hi Brooks, Many thanks for your answer. Sorry for mixing your position. Please take as much time as you need. I am in no big rush. I have applied the hack and it's already showing its effects, however, I noticed that one particular user started to bypass this by typing a bunch of punctuation marks and hiding them by wrapping them in white color. Is theer a way to also exclude ,.;:'"/?!@ and other non-letter/number symbols from character count? A simple regex expression inside your hack could maybe help. I know this one ^[a-zA-Z0-9@\._ ]+$ helps me to get rid of unwanted characters in user registration form, btu that all I know, and anything past that is unknown to me. Best regards, Val. Also, upon reading this again, I botched the request a little. It seems he does NOT want to count the spaces as characters. Sorry for the confusion Quote Link to comment https://forums.phpfreaks.com/topic/250309-counting-spaces-as-characters-and-excluding-from-character-count/#findComment-1284344 Share on other sites More sharing options...
xyph Posted November 2, 2011 Share Posted November 2, 2011 That's easy enough to fix in my posted example. If you can't do it yourself, you need to buy a book or take a class or something. You didn't explain exactly what he was trying to prevent though. How are 15 spaces any different than 15 'a' characters used in trying to bypass this minimum limit? How are 15 punctuation marks different than 15 letters hidden in the same color as the background? Unless you're ready to check for MANY, MANY situations, there will always be ways to make nonsense, wasted posts. User intervention and moderation is how this is fixed. Delete the offending posts, or ban the user making them. Force CAPTCHA on users will less than x number of posts to discourage spammers or people from simply making new accounts to annoy. Let me know if any of this helps. Quote Link to comment https://forums.phpfreaks.com/topic/250309-counting-spaces-as-characters-and-excluding-from-character-count/#findComment-1284361 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.