/[drupal]/contributions/modules/abuse/watchlist/watchlist.module
ViewVC logotype

Diff of /contributions/modules/abuse/watchlist/watchlist.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.4.6.3 by btmash, Fri Jul 18 15:52:51 2008 UTC revision 1.4.6.4 by btmash, Wed Oct 15 17:50:58 2008 UTC
# Line 1  Line 1 
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_');
# Line 28  function watchlist_menu() { Line 33  function watchlist_menu() {
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':
# Line 178  function watchlist_admin_settings_form_v Line 183  function watchlist_admin_settings_form_v
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) {
# Line 235  function watchlist_test_settings_form_su Line 243  function watchlist_test_settings_form_su
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";
# Line 263  function watchlist_js_test_settings_form Line 271  function watchlist_js_test_settings_form
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);
# Line 281  function watchlist_nodeapi(&$node, $op, Line 289  function watchlist_nodeapi(&$node, $op,
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'];
# Line 299  function watchlist_comment(&$comment, $o Line 307  function watchlist_comment(&$comment, $o
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;
# Line 316  function watchlist_user($op, &$edit, &$a Line 324  function watchlist_user($op, &$edit, &$a
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  }  }
# Line 328  function watchlist_invoke_extra_text($no Line 336  function watchlist_invoke_extra_text($no
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)) {
# Line 398  function _watchlist_generate_list($wordl Line 407  function _watchlist_generate_list($wordl
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      }      }
# Line 426  function _watchlist_report_generated($ob Line 435  function _watchlist_report_generated($ob
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;
# Line 439  function _watchlist_report_generated($ob Line 448  function _watchlist_report_generated($ob
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) {

Legend:
Removed from v.1.4.6.3  
changed lines
  Added in v.1.4.6.4

  ViewVC Help
Powered by ViewVC 1.1.3