This is the community forum. For a developer response use the Client Area.
Follow us on Facebook, Twitter and YouTube!

Check comment content on submit
#1

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
Reply
#2

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?
Reply
#3

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...
Reply
#4

(07-Jan-2011, 09: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, 09: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


Reply
#5

(07-Jan-2011, 10: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...

Reply
#6

This function, designed for v1.2, makes sure that there is at least one Arabic character:
PHP Code:
<?php 
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:
<?php 
if ($approve_images) {
comment_detect_image($comment); //detect images in comment
}

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

Have you completed the interview?
Reply
#7

Working great
Thanks a lot Wink
Reply


Possibly Related Threads…
Thread / Author Replies Views Last Post
Last Post by mariank
22-Dec-2013, 09:36 AM
Last Post by Steven
21-Apr-2013, 05:26 PM
Last Post by Static
28-Sep-2010, 05:00 PM
Last Post by Steven
14-Aug-2010, 12:29 PM
Last Post by Static
12-Aug-2010, 10:46 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)