Post Reply 
Check comment content on submit
07-Jan-2011, 07:57 PM
Post: #1
Check comment content on submit
Well, allowing users to add comments is quite nice feature to bring some interactivity to a website
But if I had to choose between "useless comment" and "no cmment"? I would choose "no comment"
What I mean by "useless cmment" is comments like:
veryyyyyy gooood
tra lal laaaaaaa
So is there any mean to detect such comments and block them, displaying an errror message?
Bad comments for me also includes arabic comments written in latin characters!!! Huh It looks ugly and less professional for my website Big Grin
So can I also block any comment written with character other than arabic? (Arabic are like: ا ب ت ج ح خ ....)
Back when I was using phpbb3 forum software, I had the following code to ensure that usernames choosen by new registred members contain only arabic characters plus numerics:
Code:
$regex = '[\p{Arabic}0-9-[\]_+ ]*\p{Arabic}+[\p{Arabic}0-9-[\]_+ ]*';
is it possible to reuse it to acheive my goal? Blush
Find all posts by this user
Quote this message in a reply
07-Jan-2011, 10:42 PM
Post: #2
RE: Check comment content on submit
Yeah it's possible that the script could check the comment against a list of dictionary words and then return a percentage of the matches found, however this might noticeably slow down the processing speed. I will certainly look into it for a future version.

Blocking any comment not entirely written in Arabic should be fairly simple. There would probably need to be a loop which looks at every character of the comment using the regex that you supplied to see whether it's Arabic or not and to set a flag if it's not. Then after the loop has finished it would produce an error if any of the characters were flagged.

Have you completed the interview?
Find all posts by this user
Quote this message in a reply
07-Jan-2011, 11:46 PM
Post: #3
RE: Check comment content on submit
How would you write the name of, say, an English company in Arabic (like Google)? Usually what people do is just type it in English. Wouldn't it be better to check if most of the characters are non-English in that case?

I'm giving you three guesses...
Find all posts by this user
Quote this message in a reply
07-Jan-2011, 11:46 PM
Post: #4
RE: Check comment content on submit
(07-Jan-2011 10:42 PM)Steven Wrote:  Yeah it's possible that the script could check the comment against a list of dictionary words and then return a percentage of the matches found
Yes, It would be a handy feature. Admins can define bad words. This will help fight spam
In the followin coment: "tra lal laaaaaaa", maybe we need only to block repetitive characters

(07-Jan-2011 10:42 PM)Steven Wrote:  Blocking any comment not entirely written in Arabic should be fairly simple.
Well, you answer make me realise that the logic is more complicated !!! In fact, I want only to ensure that there is at least ONE arabic characters, because based on my own experience, users never mix alphabets !!! they use either arabic or latin. So a chack for at least ONE arabic characters would me than sufficient
Find all posts by this user
Quote this message in a reply
08-Jan-2011, 12:29 AM
Post: #5
RE: Check comment content on submit
(07-Jan-2011 11:46 PM)Static Wrote:  Wouldn't it be better to check if most of the characters are non-English in that case?
Yes, This is exactely what I mean: check if most...
Find all posts by this user
Quote this message in a reply
08-Jan-2011, 01:43 PM
Post: #6
RE: Check comment content on submit
This function, designed for v1.2, makes sure that there is at least one Arabic character:
PHP Code:
function comment_check_arabic ($comment) { //checks whether comment is arabic

if (!preg_match("/\p{Arabic}/u"$comment)) {
    
error("The comment entered is not Arabic. Please write it in Arabic.");
}
    
//end of comment-check-arabic function 

Add the above function inside comments/includes/functions/processor.php

Then in comments/includes/app/processor.php, find this part:
PHP Code:
if ($approve_images) {
    
comment_detect_image($comment); //detect images in comment


And add this on the line below it:
PHP Code:
comment_check_arabic($comment); 

Have you completed the interview?
Find all posts by this user
Quote this message in a reply
08-Jan-2011, 02:55 PM
Post: #7
RE: Check comment content on submit
Working great
Thanks a lot Wink
Find all posts by this user
Quote this message in a reply
Post Reply 


Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Comment # Module JMG 3 125 21-Apr-2013 06:26 PM
Last Post: Steven
  Administration / Comment list : Quick approve pier 1 294 13-Aug-2012 01:42 PM
Last Post: Steven
  Extra comment fields adding through admin corculator 0 429 25-Feb-2012 03:30 PM
Last Post: corculator
  Reply to comment Static 82 5,074 28-Sep-2010 06:00 PM
Last Post: Static
  Comment Title & BBcode Static 23 1,896 14-Aug-2010 01:29 PM
Last Post: Steven
  Better page/comment management Static 0 311 12-Aug-2010 11:46 PM
Last Post: Static

Forum Jump:


User(s) browsing this thread: 1 Guest(s)