Add UFC_Ip
authorRaphaël Barrois <raphael.barrois@polytechnique.org>
Mon, 15 Feb 2010 13:49:40 +0000 (14:49 +0100)
committerRaphaël Barrois <raphael.barrois@polytechnique.org>
Mon, 15 Feb 2010 13:49:40 +0000 (14:49 +0100)
Signed-off-by: Raphaël Barrois <raphael.barrois@polytechnique.org>
classes/userfilter.php
include/ufbuilder.inc.php

index e8aa2f2..20b9247 100644 (file)
@@ -76,6 +76,28 @@ class UFC_Hruid implements UserFilterCondition
 }
 // }}}
 
+// {{{ class UFC_Ip
+/** Filters users based on one of their last IPs
+ * @param $ip IP from which connection are checked
+ */
+class UFC_Ip implements UserFilterCondition
+{
+    private $ip;
+
+    public function __construct($ip)
+    {
+        $this->ip = $ip;
+    }
+
+    public function buildCondition(PlFilter &$uf)
+    {
+        $sub = $uf->addLoggerFilter();
+        $ip = ip_to_uint($this->ip);
+        return XDB::format($sub . '.ip = {?} OR ' . $sub . '.forward_ip = {?}', $ip, $ip);
+    }
+}
+// }}}
+
 // {{{ class UFC_Comment
 class UFC_Comment implements UserFilterCondition
 {
@@ -1827,6 +1849,25 @@ class UserFilter extends PlFilter
         }
     }
 
+    /** LOGGER
+     */
+
+    private $with_logger = false;
+    public function addLoggerFilter()
+    {
+        $this->with_logger = true;
+        $this->requireAccounts();
+        return 'ls';
+    }
+    protected function loggerJoins()
+    {
+        $joins = array();
+        if ($this->with_logger) {
+            $joins['ls'] = new PlSqlJoin(PlSqlJoin::MODE_LEFT, 'log_sessions', '$ME.uid = $UID');
+        }
+        return $joins;
+    }
+
     /** NAMES
      */
 
index 92e0841..611756b 100644 (file)
@@ -469,8 +469,7 @@ class UFBF_Quick extends UFB_Field
         if (S::admin() && strpos($s, '@') !== false) {
             return new UFC_Email($s);
         } else if (S::admin() && preg_match('/[0-9]+\.([0-9]+|%)\.([0-9]+|%)\.([0-9]+|%)/', $s)) {
-            // TODO: create UFC_Ip
-//            $this->conds->addChild(new UFC_Ip($s));
+            $this->conds->addChild(new UFC_Ip($s));
             return;
         }