]> git.mxchange.org Git - friendica.git/commitdiff
While storing an item, now every contact is stored in the gcontact table.
authorMichael Vogel <icarus@dabo.de>
Tue, 6 Jan 2015 06:23:11 +0000 (07:23 +0100)
committerMichael Vogel <icarus@dabo.de>
Tue, 6 Jan 2015 06:23:11 +0000 (07:23 +0100)
include/items.php
include/socgraph.php

index 9d1e36f39b124f400d4c559c692661984c9f0f9a..a7e996015e7fd6f9b48e45c71726ed57b84acf61 100644 (file)
@@ -11,6 +11,7 @@ require_once('include/text.php');
 require_once('include/email.php');
 require_once('include/ostatus_conversation.php');
 require_once('include/threads.php');
+require_once('include/socgraph.php');
 
 function get_feed_for(&$a, $dfrn_id, $owner_nick, $last_update, $direction = 0) {
 
@@ -1343,6 +1344,12 @@ function item_store($arr,$force_parent = false, $notify = false, $dontcache = fa
                $current_post = $r[0]['id'];
                logger('item_store: created item ' . $current_post);
 
+               // Add every contact to the global contact table
+               // Contacts from the statusnet connector are also added since you could add them in OStatus as well.
+               if (!$arr['private'] AND in_array($arr["network"],
+                       array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS, NETWORK_STATUSNET, "")))
+                       poco_check($arr["author-link"], $arr["author-name"], $arr["author-avatar"], "", $arr["received"]);
+
                // Set "success_update" to the date of the last time we heard from this contact
                // This can be used to filter for inactive contacts and poco.
                // Only do this for public postings to avoid privacy problems, since poco data is public.
index b9e890427ce1241d993e3ada0fc59567e08bd4b9..8b8eb915cc0b98eae96b8d9322d8be71aee92b21 100644 (file)
@@ -98,40 +98,8 @@ function poco_load($cid,$uid = 0,$zcid = 0,$url = null) {
                if((! $name) || (! $profile_url) || (! $profile_photo))
                        continue;
 
-               $x = q("SELECT * FROM `gcontact` WHERE `nurl` = '%s' LIMIT 1",
-                       dbesc(normalise_link($profile_url))
-               );
-
-               if(count($x)) {
-                       $gcid = $x[0]['id'];
+               $gcid = poco_check($profile_url, $name, $profile_photo, $connect_url, $updated);
 
-                       if($x[0]['name'] != $name || $x[0]['photo'] != $profile_photo || $x[0]['updated'] < $updated) {
-                               q("update gcontact set `name` = '%s', `photo` = '%s', `connect` = '%s', `url` = '%s', `updated` = '%s'
-                                       where `nurl` = '%s'",
-                                       dbesc($name),
-                                       dbesc($profile_photo),
-                                       dbesc($connect_url),
-                                       dbesc($profile_url),
-                                       dbesc($updated),
-                                       dbesc(normalise_link($profile_url))
-                               );
-                       }
-               } else {
-                       q("insert into `gcontact` (`name`,`url`,`nurl`,`photo`,`connect`, `updated`)
-                               values ( '%s', '%s', '%s', '%s','%s') ",
-                               dbesc($name),
-                               dbesc($profile_url),
-                               dbesc(normalise_link($profile_url)),
-                               dbesc($profile_photo),
-                               dbesc($connect_url),
-                               dbesc($updated)
-                       );
-                       $x = q("SELECT * FROM `gcontact` WHERE `nurl` = '%s' LIMIT 1",
-                               dbesc(normalise_link($profile_url))
-                       );
-                       if(count($x))
-                               $gcid = $x[0]['id'];
-               }
                if(! $gcid)
                        return;
 
@@ -178,6 +146,50 @@ function poco_load($cid,$uid = 0,$zcid = 0,$url = null) {
 
 }
 
+function poco_check($profile_url, $name, $profile_photo, $connect_url, $updated) {
+       $gcid = "";
+
+       if (($profile_url == "") OR ($name == "") OR ($profile_photo == ""))
+               return $gcid;
+
+       logger("profile-check URL: ".$profile_url." name: ".$name." avatar: ".$profile_photo, LOGGER_DEBUG);
+
+       $x = q("SELECT * FROM `gcontact` WHERE `nurl` = '%s' LIMIT 1",
+               dbesc(normalise_link($profile_url))
+       );
+
+       if(count($x)) {
+               $gcid = $x[0]['id'];
+
+               if($x[0]['name'] != $name || $x[0]['photo'] != $profile_photo || $x[0]['updated'] < $updated) {
+                       q("update gcontact set `name` = '%s', `photo` = '%s', `connect` = '%s', `url` = '%s', `updated` = '%s'
+                               where `nurl` = '%s'",
+                               dbesc($name),
+                               dbesc($profile_photo),
+                               dbesc($connect_url),
+                               dbesc($profile_url),
+                               dbesc($updated),
+                               dbesc(normalise_link($profile_url))
+                       );
+               }
+       } else {
+               q("insert into `gcontact` (`name`,`url`,`nurl`,`photo`,`connect`, `updated`)
+                       values ('%s', '%s', '%s', '%s','%s', '%s')",
+                       dbesc($name),
+                       dbesc($profile_url),
+                       dbesc(normalise_link($profile_url)),
+                       dbesc($profile_photo),
+                       dbesc($connect_url),
+                       dbesc($updated)
+               );
+               $x = q("SELECT * FROM `gcontact` WHERE `nurl` = '%s' LIMIT 1",
+                       dbesc(normalise_link($profile_url))
+               );
+               if(count($x))
+                       $gcid = $x[0]['id'];
+       }
+       return $gcid;
+}
 
 function count_common_friends($uid,$cid) {