| 1 |
<?php |
<?php |
| 2 |
// $Id$ |
// $Id$ |
| 3 |
|
|
| 4 |
|
/** |
| 5 |
|
* @file |
| 6 |
|
* Main module which implements core hooks for filter and/or send calls to the abuse module when questionable content is created. |
| 7 |
|
*/ |
| 8 |
|
|
| 9 |
define('CONFIGURE_WATCHLIST_SETTINGS', 'configure watchlist settings'); |
define('CONFIGURE_WATCHLIST_SETTINGS', 'configure watchlist settings'); |
| 10 |
define('WATCHLIST_PREMODERATE_CONTENT_TYPE', 'watchlist_premoderate_content_type_'); |
define('WATCHLIST_PREMODERATE_CONTENT_TYPE', 'watchlist_premoderate_content_type_'); |
| 11 |
define('WATCHLIST_MODERATE_CONTENT_TYPE', 'watchlist_moderate_content_type_'); |
define('WATCHLIST_MODERATE_CONTENT_TYPE', 'watchlist_moderate_content_type_'); |
| 33 |
} |
} |
| 34 |
|
|
| 35 |
function watchlist_filter($op, $delta = 0, $format = -1, $text = '') { |
function watchlist_filter($op, $delta = 0, $format = -1, $text = '') { |
| 36 |
switch($op) { |
switch ($op) { |
| 37 |
case 'list': |
case 'list': |
| 38 |
return array(0 => t('Bad words filter')); |
return array(0 => t('Bad words filter')); |
| 39 |
case 'description': |
case 'description': |
| 183 |
} |
} |
| 184 |
|
|
| 185 |
function _watchlist_admin_settings_validate_empty_line($list, $type) { |
function _watchlist_admin_settings_validate_empty_line($list, $type) { |
| 186 |
|
if (empty($list)) { |
| 187 |
|
return; |
| 188 |
|
} |
| 189 |
$words = str_replace(array("\r\n", "\r"), "\n", $list); |
$words = str_replace(array("\r\n", "\r"), "\n", $list); |
| 190 |
$wordlist = explode("\n", $words); |
$wordlist = explode("\n", $words); |
| 191 |
foreach ($wordlist as $num => $word) { |
foreach ($wordlist as $num => $word) { |
| 243 |
$op = $form_state['clicked_button']['#value']; |
$op = $form_state['clicked_button']['#value']; |
| 244 |
if (t('test') === $op) { |
if (t('test') === $op) { |
| 245 |
$matches = watchlist_checklist($values['text']); |
$matches = watchlist_checklist($values['text']); |
| 246 |
$content = '<em>Your Text:</em> ' .check_plain($values['text']). "<br />\n"; |
$content = '<em>Your Text:</em> '. check_plain($values['text']) ."<br />\n"; |
| 247 |
$content .= '<em>Filtered text:</em> '. watchlist_filter('process', 0, -1, $values['text']) ."<br />\n"; |
$content .= '<em>Filtered text:</em> '. watchlist_filter('process', 0, -1, $values['text']) ."<br />\n"; |
| 248 |
$content .= '<em>Matches against regular watchlist:</em> '. ((empty($matches['watchlist'])) ? 'none' : implode(', ', $matches['watchlist'])) ."<br />\n"; |
$content .= '<em>Matches against regular watchlist:</em> '. ((empty($matches['watchlist'])) ? 'none' : implode(', ', $matches['watchlist'])) ."<br />\n"; |
| 249 |
$content .= '<em>Matches against banned list:</em> '. ((empty($matches['bannedlist'])) ? 'none' : implode(', ', $matches['bannedlist'])) ."<br />\n"; |
$content .= '<em>Matches against banned list:</em> '. ((empty($matches['bannedlist'])) ? 'none' : implode(', ', $matches['bannedlist'])) ."<br />\n"; |
| 271 |
* Check the lists and if the content will be allowed, added to pending bin, or hidden from the site |
* Check the lists and if the content will be allowed, added to pending bin, or hidden from the site |
| 272 |
*/ |
*/ |
| 273 |
function watchlist_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) { |
function watchlist_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) { |
| 274 |
switch($op) { |
switch ($op) { |
| 275 |
case 'update': |
case 'update': |
| 276 |
case 'insert': |
case 'insert': |
| 277 |
$text = $node->title .' '. urldecode($node->body) .' '. watchlist_invoke_extra_text($node); |
$text = $node->title .' '. urldecode($node->body) .' '. watchlist_invoke_extra_text($node); |
| 289 |
*/ |
*/ |
| 290 |
|
|
| 291 |
function watchlist_comment(&$comment, $op) { |
function watchlist_comment(&$comment, $op) { |
| 292 |
switch($op) { |
switch ($op) { |
| 293 |
case 'update': |
case 'update': |
| 294 |
case 'insert': |
case 'insert': |
| 295 |
$text = $comment['subject'] .' '. $comment['comment']; |
$text = $comment['subject'] .' '. $comment['comment']; |
| 307 |
*/ |
*/ |
| 308 |
function watchlist_user($op, &$edit, &$account, $category = NULL) { |
function watchlist_user($op, &$edit, &$account, $category = NULL) { |
| 309 |
if (variable_get(WATCHLIST_MODERATE_CONTENT_TYPE .'users', 0)) { |
if (variable_get(WATCHLIST_MODERATE_CONTENT_TYPE .'users', 0)) { |
| 310 |
switch($op) { |
switch ($op) { |
| 311 |
case 'validate': |
case 'validate': |
| 312 |
$watchListMatch = watchlist_checklist($edit['name']); |
$watch_list_match = watchlist_checklist($edit['name']); |
| 313 |
if (sizeof($watchListMatch['watchlist']) > 0 || sizeof($watchListMatch['bannedlist']) > 0) { |
if (sizeof($watch_list_match['watchlist']) > 0 || sizeof($watch_list_match['bannedlist']) > 0) { |
| 314 |
form_set_error('name', t('Inappropriate name !name requested.', array('!name' => theme('placeholder', $edit['name'])))); |
form_set_error('name', t('Inappropriate name !name requested.', array('!name' => theme('placeholder', $edit['name'])))); |
| 315 |
} |
} |
| 316 |
break; |
break; |
| 324 |
*/ |
*/ |
| 325 |
function watchlist_invoke_extra_text($node) { |
function watchlist_invoke_extra_text($node) { |
| 326 |
$text = ''; |
$text = ''; |
| 327 |
foreach(module_implements('watchlist_extra_text') as $name) { |
foreach (module_implements('watchlist_extra_text') as $name) { |
| 328 |
$text .= module_invoke($name, 'watchlist_extra_text', $node) . ' '; |
$text .= module_invoke($name, 'watchlist_extra_text', $node) .' '; |
| 329 |
} |
} |
| 330 |
return trim($text); |
return trim($text); |
| 331 |
} |
} |
| 336 |
function watchlist_evaluate($object, $oid, $type, $matches) { |
function watchlist_evaluate($object, $oid, $type, $matches) { |
| 337 |
$generic_type = ($type === 'comment' || $type === 'user') ? $type : 'node'; |
$generic_type = ($type === 'comment' || $type === 'user') ? $type : 'node'; |
| 338 |
// Check if the content is to be pre-moderated |
// Check if the content is to be pre-moderated |
| 339 |
if (0 !== variable_get(WATCHLIST_PREMODERATE_CONTENT_TYPE.$type, 0)) { |
if (0 !== variable_get(WATCHLIST_PREMODERATE_CONTENT_TYPE . $type, 0)) { |
| 340 |
$banlist_matches = array_unique($matches['bannedlist'] + $matches['watchlist']); |
$banlist_matches = array_unique($matches['bannedlist'] + $matches['watchlist']); |
| 341 |
if (!empty($banlist_matches)) { |
if (!empty($banlist_matches)) { |
| 342 |
_watchlist_report_generated($object, $generic_type, $oid, $matches, TRUE, TRUE); |
_watchlist_report_generated($object, $generic_type, $oid, $matches, TRUE, TRUE); |
| 343 |
} else { |
} |
| 344 |
|
else { |
| 345 |
_watchlist_report_generated($object, $generic_type, $oid, $matches, TRUE, FALSE); |
_watchlist_report_generated($object, $generic_type, $oid, $matches, TRUE, FALSE); |
| 346 |
} |
} |
| 347 |
|
|
| 348 |
} |
} |
| 349 |
// Check if the content is to be moderated for banned words by the watchlist |
// Check if the content is to be moderated for banned words by the watchlist |
| 350 |
elseif (0 !== variable_get(WATCHLIST_MODERATE_CONTENT_TYPE.$type, 0)) { |
elseif (0 !== variable_get(WATCHLIST_MODERATE_CONTENT_TYPE . $type, 0)) { |
| 351 |
$watchlist_matches = $matches['watchlist']; |
$watchlist_matches = $matches['watchlist']; |
| 352 |
$banlist_matches = $matches['bannedlist']; |
$banlist_matches = $matches['bannedlist']; |
| 353 |
if (!empty($banlist_matches)) { |
if (!empty($banlist_matches)) { |
| 407 |
* Check the list of words against a list |
* Check the list of words against a list |
| 408 |
*/ |
*/ |
| 409 |
function _watchlist_checklist($text, $wordlist) { |
function _watchlist_checklist($text, $wordlist) { |
| 410 |
if(!empty($wordlist)) { |
if (!empty($wordlist)) { |
| 411 |
$matches = array(); |
$matches = array(); |
| 412 |
foreach($wordlist as $word) { |
foreach ($wordlist as $word) { |
| 413 |
$match = array(); |
$match = array(); |
| 414 |
if(preg_match($word, $text, $match)) { |
if (preg_match($word, $text, $match)) { |
| 415 |
$matches[] = $match[0]; |
$matches[] = $match[0]; |
| 416 |
} |
} |
| 417 |
} |
} |
| 435 |
); |
); |
| 436 |
// Alter status of the content if it is supposed to be premoderated or hidden (value sent by evaluation) |
// Alter status of the content if it is supposed to be premoderated or hidden (value sent by evaluation) |
| 437 |
if ($premoderated || $hidden) { |
if ($premoderated || $hidden) { |
| 438 |
switch($type) { |
switch ($type) { |
| 439 |
case 'user': |
case 'user': |
| 440 |
db_query("UPDATE {users} SET status=0 WHERE uid=%d", $oid); |
db_query("UPDATE {users} SET status=0 WHERE uid=%d", $oid); |
| 441 |
break; |
break; |
| 448 |
} |
} |
| 449 |
} |
} |
| 450 |
|
|
| 451 |
if ($hidden) { |
if ($hidden && $premoderated) { |
| 452 |
_abuse_set_status($type, $oid, ABUSE_HIDDEN); |
_abuse_set_status($type, $oid, ABUSE_HIDDEN); |
| 453 |
} else { |
} |
| 454 |
|
elseif ($hidden && !$premoderated) { |
| 455 |
|
_abuse_disable($type, $oid); |
| 456 |
|
} |
| 457 |
|
else { |
| 458 |
_abuse_set_status($type, $oid, ABUSE_PENDING); |
_abuse_set_status($type, $oid, ABUSE_PENDING); |
| 459 |
} |
} |
| 460 |
if (sizeof($matches['watchlist']) <= 0 && sizeof($matches['bannedlist']) <= 0) { |
if (sizeof($matches['watchlist']) <= 0 && sizeof($matches['bannedlist']) <= 0) { |