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

Last change on this file since 27299 was 26113, checked in by mistic100, 11 years ago

update for 2.6

File size: 2.3 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
13define('COMM_BLACKLIST_ID',      basename(dirname(__FILE__)));
14define('COMM_BLACKLIST_PATH' ,   PHPWG_PLUGINS_PATH . COMM_BLACKLIST_ID . '/');
15define('COMM_BLACKLIST_ADMIN',   get_root_url() . 'admin.php?page=plugin-' . COMM_BLACKLIST_ID);
16define('COMM_BLACKLIST_FILE',    PHPWG_ROOT_PATH . PWG_LOCAL_DIR . 'comments_blacklist.txt');
17define('COMM_BLACKLIST_VERSION', 'auto');
18
19
20add_event_handler('init', 'comm_blacklist_init');
21
22if (defined('IN_ADMIN'))
23{
24  add_event_handler('get_admin_plugin_menu_links', 'comm_blacklist_admin_plugin_menu_links');
25}
26else
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 */
35function 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 */
49function 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 */
61function 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}
Note: See TracBrowser for help on using the repository browser.