From e403cc58e0f623c70da4018a6eb869464dc97996 Mon Sep 17 00:00:00 2001
From: Michael Klier <chi@chimeric.de>
Date: Sun, 12 Oct 2008 19:48:49 +0200
Subject: [PATCH] FS#1024 new Event COMMON_WORDBLOCK_BLOCKED

	This event allows action plugins to take action if a wordblock occurs.

	Event data:
		data[matches] 	- array of wordblock matches
		data[userinfo]  - detailed userinfo
			[ip]		- ip address
			[user]		- username (if logged in)
			[name]		- real name (if logged in)
			[mail]		- mail address (if logged in)

darcs-hash:20081012174849-23886-0ac42addc14ee3e36e961272de229a6002d052e9.gz
---
 inc/common.php | 28 ++++++++++++++++++++++++++--
 1 file changed, 26 insertions(+), 2 deletions(-)

diff --git a/inc/common.php b/inc/common.php
index a8a6dd5ff..1532c523a 100644
--- a/inc/common.php
+++ b/inc/common.php
@@ -510,11 +510,26 @@ function script($script='doku.php'){
  * Checks the wikitext against a list of blocked expressions
  * returns true if the text contains any bad words
  *
+ * Triggers COMMON_WORDBLOCK_BLOCKED
+ *
+ *  Action Plugins can use this event to inspect the blocked data
+ *  and gain information about the user who was blocked.
+ *
+ *  Event data:
+ *    data['matches']  - array of matches
+ *    data['userinfo'] - information about the blocked user
+ *      [ip]           - ip address
+ *      [user]         - username (if logged in)
+ *      [mail]         - mail address (if logged in)
+ *      [name]         - real name (if logged in)
+ *
  * @author Andreas Gohr <andi@splitbrain.org>
+ * Michael Klier <chi@chimeric.de>
  */
 function checkwordblock(){
   global $TEXT;
   global $conf;
+  global $INFO;
 
   if(!$conf['usewordblock']) return false;
 
@@ -542,8 +557,17 @@ function checkwordblock(){
       if(empty($block)) continue;
       $re[]  = $block;
     }
-    if(count($re) && preg_match('#('.join('|',$re).')#si',$text)) {
-      return true;
+    if(count($re) && preg_match('#('.join('|',$re).')#si',$text,$matches)) {
+      //prepare event data
+      $data['matches'] = $matches;
+      $data['userinfo']['ip'] = $_SERVER['REMOTE_ADDR'];
+      if($_SERVER['REMOTE_USER']) {
+          $data['userinfo']['user'] = $_SERVER['REMOTE_USER'];
+          $data['userinfo']['name'] = $INFO['userinfo']['name'];
+          $data['userinfo']['mail'] = $INFO['userinfo']['mail'];
+      }
+      $callback = create_function('', 'return true;');
+      return trigger_event('COMMON_WORDBLOCK_BLOCKED', $data, $callback, true); 
     }
   }
   return false;
-- 
GitLab