+ if(isset($entry->updated))
+ $updated = date("Y-m-d H:i:s", strtotime($entry->updated));
+
+ if(isset($entry->network))
+ $network = $entry->network;
+
+ if(isset($entry->currentLocation))
+ $location = $entry->currentLocation;
+
+ if(isset($entry->aboutMe))
+ $about = html2bbcode($entry->aboutMe);
+
+ if(isset($entry->gender))
+ $gender = $entry->gender;
+
+ if(isset($entry->generation) AND ($entry->generation > 0))
+ $generation = ++$entry->generation;
+
+ if(isset($entry->tags))
+ foreach($entry->tags as $tag)
+ $keywords = implode(", ", $tag);
+
+ // If you query a Friendica server for its profiles, the network has to be Friendica
+ if ($uid == 0)
+ $network = NETWORK_DFRN;
+
+ poco_check($profile_url, $name, $network, $profile_photo, $about, $location, $gender, $keywords, $connect_url, $updated, $generation, $cid, $uid, $zcid);
+
+ // Update the Friendica contacts. Diaspora is doing it via a message. (See include/diaspora.php)
+ if (($location != "") OR ($about != "") OR ($keywords != "") OR ($gender != ""))
+ q("UPDATE `contact` SET `location` = '%s', `about` = '%s', `keywords` = '%s', `gender` = '%s'
+ WHERE `nurl` = '%s' AND NOT `self` AND `network` = '%s'",
+ dbesc($location),
+ dbesc($about),
+ dbesc($keywords),
+ dbesc($gender),
+ dbesc(normalise_link($profile_url)),
+ dbesc(NETWORK_DFRN));
+ }
+ logger("poco_load: loaded $total entries",LOGGER_DEBUG);
+
+ q("DELETE FROM `glink` WHERE `cid` = %d AND `uid` = %d AND `zcid` = %d AND `updated` < UTC_TIMESTAMP - INTERVAL 2 DAY",
+ intval($cid),
+ intval($uid),
+ intval($zcid)
+ );
+
+}
+
+function poco_check($profile_url, $name, $network, $profile_photo, $about, $location, $gender, $keywords, $connect_url, $updated, $generation, $cid = 0, $uid = 0, $zcid = 0) {
+
+ $a = get_app();
+
+ // Generation:
+ // 0: No definition
+ // 1: Profiles on this server
+ // 2: Contacts of profiles on this server
+ // 3: Contacts of contacts of profiles on this server
+ // 4: ...
+
+ $gcid = "";
+
+ if ($profile_url == "")
+ return $gcid;
+
+ // Don't store the statusnet connector as network
+ // We can't simply set this to NETWORK_OSTATUS since the connector could have fetched posts from friendica as well
+ if ($network == NETWORK_STATUSNET)
+ $network = "";
+
+ // The global contacts should contain the original picture, not the cached one
+ if (($generation != 1) AND stristr(normalise_link($profile_photo), normalise_link($a->get_baseurl()."/photo/")))
+ $profile_photo = "";
+
+ $r = q("SELECT `network` FROM `contact` WHERE `nurl` = '%s' AND `network` != '' AND `network` != '%s' LIMIT 1",
+ dbesc(normalise_link($profile_url)), dbesc(NETWORK_STATUSNET)
+ );
+ if(count($r))
+ $network = $r[0]["network"];
+
+ if (($network == "") OR ($network == NETWORK_OSTATUS)) {
+ $r = q("SELECT `network`, `url` FROM `contact` WHERE `alias` IN ('%s', '%s') AND `network` != '' AND `network` != '%s' LIMIT 1",
+ dbesc($profile_url), dbesc(normalise_link($profile_url)), dbesc(NETWORK_STATUSNET)
+ );
+ if(count($r)) {
+ $network = $r[0]["network"];
+ $profile_url = $r[0]["url"];
+ }
+ }
+
+ $x = q("SELECT * FROM `gcontact` WHERE `nurl` = '%s' LIMIT 1",
+ dbesc(normalise_link($profile_url))
+ );
+ if(count($x) AND ($network == "") AND ($x[0]["network"] != NETWORK_STATUSNET))
+ $network = $x[0]["network"];
+
+ if (($network == "") OR ($name == "") OR ($profile_photo == "")) {
+ require_once("include/Scrape.php");
+
+ $data = probe_url($profile_url);
+ $network = $data["network"];
+ $name = $data["name"];
+ $profile_url = $data["url"];
+ $profile_photo = $data["photo"];
+ }
+
+ if (count($x) AND ($x[0]["network"] == "") AND ($network != "")) {
+ q("UPDATE `gcontact` SET `network` = '%s' WHERE `nurl` = '%s'",
+ dbesc($network),