1 | <?php |
---|
2 | /* |
---|
3 | Plugin Name: Comments Blacklist |
---|
4 | Version: auto |
---|
5 | Description: Define a list of words which are not authorized in a comment. |
---|
6 | Plugin URI: auto |
---|
7 | Author: Mistic |
---|
8 | Author URI: http://www.strangeplanet.fr |
---|
9 | */ |
---|
10 | |
---|
11 | defined('PHPWG_ROOT_PATH') or die('Hacking attempt!'); |
---|
12 | |
---|
13 | global $conf; |
---|
14 | |
---|
15 | define('COMM_BLACKLIST_ID', basename(dirname(__FILE__))); |
---|
16 | define('COMM_BLACKLIST_PATH' , PHPWG_PLUGINS_PATH . COMM_BLACKLIST_ID . '/'); |
---|
17 | define('COMM_BLACKLIST_ADMIN', get_root_url() . 'admin.php?page=plugin-' . COMM_BLACKLIST_ID); |
---|
18 | define('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 | |
---|
24 | if (defined('IN_ADMIN')) |
---|
25 | { |
---|
26 | add_event_handler('get_admin_plugin_menu_links', 'comm_blacklist_admin_plugin_menu_links'); |
---|
27 | } |
---|
28 | else |
---|
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 | */ |
---|
37 | function 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 | */ |
---|
49 | function 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 | } |
---|