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 | define('COMM_BLACKLIST_ID', basename(dirname(__FILE__))); |
---|
14 | define('COMM_BLACKLIST_PATH' , PHPWG_PLUGINS_PATH . COMM_BLACKLIST_ID . '/'); |
---|
15 | define('COMM_BLACKLIST_ADMIN', get_root_url() . 'admin.php?page=plugin-' . COMM_BLACKLIST_ID); |
---|
16 | define('COMM_BLACKLIST_FILE', PHPWG_ROOT_PATH . PWG_LOCAL_DIR . 'comments_blacklist.txt'); |
---|
17 | define('COMM_BLACKLIST_VERSION', 'auto'); |
---|
18 | |
---|
19 | |
---|
20 | add_event_handler('init', 'comm_blacklist_init'); |
---|
21 | |
---|
22 | if (defined('IN_ADMIN')) |
---|
23 | { |
---|
24 | add_event_handler('get_admin_plugin_menu_links', 'comm_blacklist_admin_plugin_menu_links'); |
---|
25 | } |
---|
26 | else |
---|
27 | { |
---|
28 | add_event_handler('user_comment_check', 'comm_blacklist_user_comment_check', EVENT_HANDLER_PRIORITY_NEUTRAL, 2); |
---|
29 | } |
---|
30 | |
---|
31 | |
---|
32 | /** |
---|
33 | * plugin initialization |
---|
34 | */ |
---|
35 | function comm_blacklist_init() |
---|
36 | { |
---|
37 | global $conf; |
---|
38 | |
---|
39 | include_once(COMM_BLACKLIST_PATH . 'maintain.inc.php'); |
---|
40 | $maintain = new comments_blacklist_maintain(COMM_BLACKLIST_ID); |
---|
41 | $maintain->autoUpdate(COMM_BLACKLIST_VERSION, 'install'); |
---|
42 | |
---|
43 | $conf['comments_blacklist'] = unserialize($conf['comments_blacklist']); |
---|
44 | } |
---|
45 | |
---|
46 | /** |
---|
47 | * admin link |
---|
48 | */ |
---|
49 | function comm_blacklist_admin_plugin_menu_links($menu) |
---|
50 | { |
---|
51 | $menu[] = array( |
---|
52 | 'NAME' => 'Comments Blacklist', |
---|
53 | 'URL' => COMM_BLACKLIST_ADMIN, |
---|
54 | ); |
---|
55 | return $menu; |
---|
56 | } |
---|
57 | |
---|
58 | /** |
---|
59 | * comment check |
---|
60 | */ |
---|
61 | function comm_blacklist_user_comment_check($comment_action, $comm) |
---|
62 | { |
---|
63 | global $conf; |
---|
64 | |
---|
65 | if ($comment_action==$conf['comments_blacklist']['action'] |
---|
66 | or $comment_action=='reject' or !isset($comm['content']) |
---|
67 | ) |
---|
68 | { |
---|
69 | return $comment_action; |
---|
70 | } |
---|
71 | |
---|
72 | $blacklist = @file(COMM_BLACKLIST_FILE, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); |
---|
73 | |
---|
74 | if (empty($blacklist)) |
---|
75 | { |
---|
76 | return $comment_action; |
---|
77 | } |
---|
78 | |
---|
79 | $blacklist = array_map(create_function('$w', 'return preg_quote($w);'), $blacklist); |
---|
80 | $blacklist = implode('|', $blacklist); |
---|
81 | |
---|
82 | if (preg_match('#\b('.$blacklist.')\b#i', $comm['content']) or |
---|
83 | (isset($comm['author']) and preg_match('#\b('.$blacklist.')\b#i', $comm['author'])) |
---|
84 | ) |
---|
85 | { |
---|
86 | return $conf['comments_blacklist']['action']; |
---|
87 | } |
---|
88 | |
---|
89 | return $comment_action; |
---|
90 | } |
---|