source: extensions/comments_blacklist/main.inc.php @ 28836

Last change on this file since 28836 was 28836, checked in by mistic100, 10 years ago

use new maintain class

File size: 1.9 KB
Line 
1<?php 
2/*
3Plugin Name: Comments Blacklist
4Version: auto
5Description: Define a list of words which are not authorized in a comment.
6Plugin URI: auto
7Author: Mistic
8Author URI: http://www.strangeplanet.fr
9*/
10
11defined('PHPWG_ROOT_PATH') or die('Hacking attempt!');
12
13global $conf;
14
15define('COMM_BLACKLIST_ID',    basename(dirname(__FILE__)));
16define('COMM_BLACKLIST_PATH' , PHPWG_PLUGINS_PATH . COMM_BLACKLIST_ID . '/');
17define('COMM_BLACKLIST_ADMIN', get_root_url() . 'admin.php?page=plugin-' . COMM_BLACKLIST_ID);
18define('COMM_BLACKLIST_FILE',  PHPWG_ROOT_PATH . PWG_LOCAL_DIR . 'comments_blacklist.txt');
19
20
21$conf['comments_blacklist'] = safe_unserialize($conf['comments_blacklist']);
22
23
24if (defined('IN_ADMIN'))
25{
26  add_event_handler('get_admin_plugin_menu_links', 'comm_blacklist_admin_plugin_menu_links');
27}
28else
29{
30  add_event_handler('user_comment_check', 'comm_blacklist_user_comment_check', EVENT_HANDLER_PRIORITY_NEUTRAL, 2);
31}
32
33
34/**
35 * admin link
36 */
37function comm_blacklist_admin_plugin_menu_links($menu) 
38{
39  $menu[] = array(
40    'NAME' => 'Comments Blacklist',
41    'URL' => COMM_BLACKLIST_ADMIN,
42    );
43  return $menu;
44}
45
46/**
47 * comment check
48 */
49function comm_blacklist_user_comment_check($comment_action, $comm)
50{
51  global $conf;
52 
53  if ($comment_action==$conf['comments_blacklist']['action']
54      or $comment_action=='reject' or !isset($comm['content'])
55    )
56  {
57    return $comment_action;
58  }
59 
60  $blacklist = @file(COMM_BLACKLIST_FILE, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
61 
62  if (empty($blacklist))
63  {
64    return $comment_action;
65  }
66 
67  $blacklist = array_map(create_function('$w', 'return preg_quote($w);'), $blacklist);
68  $blacklist = implode('|', $blacklist);
69 
70  if (preg_match('#\b('.$blacklist.')\b#i', $comm['content']) or
71      (isset($comm['author']) and preg_match('#\b('.$blacklist.')\b#i', $comm['author']))
72    )
73  {
74    return $conf['comments_blacklist']['action'];
75  }
76 
77  return $comment_action;
78}
Note: See TracBrowser for help on using the repository browser.