-function poco_contact_from_body($body, $created, $cid, $uid) {
- preg_replace_callback("/\[share(.*?)\].*?\[\/share\]/ism",
- function ($match) use ($created, $cid, $uid){
- return(sub_poco_from_share($match, $created, $cid, $uid));
- }, $body);
-}
-
-function sub_poco_from_share($share, $created, $cid, $uid) {
- $profile = "";
- preg_match("/profile='(.*?)'/ism", $share[1], $matches);
- if ($matches[1] != "")
- $profile = $matches[1];
-
- preg_match('/profile="(.*?)"/ism', $share[1], $matches);
- if ($matches[1] != "")
- $profile = $matches[1];
-
- if ($profile == "")
- return;
-
- logger("prepare poco_check for profile ".$profile, LOGGER_DEBUG);
- poco_check($profile, "", "", "", "", "", "", "", "", $created, 3, $cid, $uid);
-}
-
-function poco_store($item) {
-
- // Isn't it public?
- if ($item['private'])
- return;
-
- // Or is it from a network where we don't store the global contacts?
- if (!in_array($item["network"], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS, NETWORK_STATUSNET, "")))
- return;
-
- // Is it a global copy?
- $store_gcontact = ($item["uid"] == 0);
-
- // Is it a comment on a global copy?
- if (!$store_gcontact AND ($item["uri"] != $item["parent-uri"])) {
- $q = q("SELECT `id` FROM `item` WHERE `uri`='%s' AND `uid` = 0", $item["parent-uri"]);
- $store_gcontact = count($q);
- }
-
- if (!$store_gcontact)
- return;
-
- // "3" means: We don't know this contact directly (Maybe a reshared item)
- $generation = 3;
- $network = "";
- $profile_url = $item["author-link"];
-
- // Is it a user from our server?
- $q = q("SELECT `id` FROM `contact` WHERE `self` AND `nurl` = '%s' LIMIT 1",
- dbesc(normalise_link($item["author-link"])));
- if (count($q)) {
- logger("Our user (generation 1): ".$item["author-link"], LOGGER_DEBUG);
- $generation = 1;
- $network = NETWORK_DFRN;
- } else { // Is it a contact from a user on our server?
- $q = q("SELECT `network`, `url` FROM `contact` WHERE `uid` != 0 AND `network` != ''
- AND (`nurl` = '%s' OR `alias` IN ('%s', '%s')) AND `network` != '%s' LIMIT 1",
- dbesc(normalise_link($item["author-link"])),
- dbesc(normalise_link($item["author-link"])),
- dbesc($item["author-link"]),
- dbesc(NETWORK_STATUSNET));
- if (count($q)) {
- $generation = 2;
- $network = $q[0]["network"];
- $profile_url = $q[0]["url"];
- logger("Known contact (generation 2): ".$profile_url, LOGGER_DEBUG);
- }
- }
-
- if ($generation == 3)
- logger("Unknown contact (generation 3): ".$item["author-link"], LOGGER_DEBUG);
-
- poco_check($profile_url, $item["author-name"], $network, $item["author-avatar"], "", "", "", "", "", $item["received"], $generation, $item["contact-id"], $item["uid"]);
-
- // Maybe its a body with a shared item? Then extract a global contact from it.
- poco_contact_from_body($item["body"], $item["received"], $item["contact-id"], $item["uid"]);
-}
-