]> git.mxchange.org Git - friendica.git/commitdiff
finalise spam storage model, begin driver changes.
authorfriendica <info@friendica.com>
Tue, 6 Mar 2012 07:20:42 +0000 (23:20 -0800)
committerfriendica <info@friendica.com>
Tue, 6 Mar 2012 07:20:42 +0000 (23:20 -0800)
library/spam/b8/storage/storage_frndc.php

index 7702c108b310dc0b2090e6907170d4c0d8a2dbcd..62909d47159dad02a25b1c6b3f7c03531a155111 100644 (file)
@@ -174,20 +174,44 @@ class b8_storage_frndc extends b8_storage_base
                                array_push($where, $token);
                        }
 
-                       $where = 'token IN ("' . implode('", "', $where) . '")';
+                       $where = 'term IN ("' . implode('", "', $where) . '")';
                }
 
                else {
                        $token = dbesc($token);
-                       $where = 'token = "' . $token . '"';
+                       $where = 'term = "' . $token . '"';
                }
 
                # ... and fetch the data
 
                $result = q('
-                       SELECT *
-                       FROM ' . $this->config['table_name'] . '
-                       WHERE ' . $where . ' AND uid = ' . $uid );
+                       SELECT * FROM spam WHERE ' . $where . ' AND uid = ' . $uid );
+
+
+               $returned_tokens = array();
+               if(count($result)) {
+                       foreach($result as $rr)
+                               $returned_tokens[] = $rr['term'];
+               }
+               $to_create = array();
+
+               if(count($tokens) > 0) {
+                       foreach($tokens as $token)
+                               if(! in_array($token,$returned_tokens))
+                                       $to_create[] = str_tolower($token); 
+               }
+               if(count($to_create)) {
+                       $sql = '';
+                       foreach($to_create as $term) {
+                               if(strlen($sql))
+                                       $sql .= ',';
+                               $sql .= sprintf("(term,datetime,uid) values('%s','%s',%d)",
+                                       dbesc(str_tolower($term))
+                                       dbesc(datetime_convert()),
+                                       intval($uid)
+                               );
+                       q("insert into spam " . $sql);
+               }
 
                return $result;