From 344210bd6d58a8fa1e01c16b9c0366e44e1a6146 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Sun, 25 Jan 2015 00:19:59 +0100 Subject: [PATCH] Global contacts are now added with reshares as well. Better support for "aboutme" and "location" in poco. --- include/items.php | 19 ++++++++++++++----- include/socgraph.php | 41 ++++++++++++++++++++++++++++++++++++++++- mod/poco.php | 11 +++++++++-- 3 files changed, 63 insertions(+), 8 deletions(-) diff --git a/include/items.php b/include/items.php index 77337fe0d9..45f762fa59 100644 --- a/include/items.php +++ b/include/items.php @@ -1350,6 +1350,9 @@ function item_store($arr,$force_parent = false, $notify = false, $dontcache = fa return 0; } + // Store the unescaped version + $unescaped = $arr; + dbesc_array($arr); logger('item_store: ' . print_r($arr,true), LOGGER_DATA); @@ -1360,10 +1363,12 @@ function item_store($arr,$force_parent = false, $notify = false, $dontcache = fa . implode("', '", array_values($arr)) . "')" ); - // find the item we just created + // And restore it + $arr = $unescaped; + // find the item we just created $r = q("SELECT `id` FROM `item` WHERE `uri` = '%s' AND `uid` = %d ORDER BY `id` ASC ", - $arr['uri'], // already dbesc'd + dbesc($arr['uri']), intval($arr['uid']) ); @@ -1374,8 +1379,12 @@ function item_store($arr,$force_parent = false, $notify = false, $dontcache = fa // 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["network"], $arr["author-avatar"], "", $arr["received"], $arr['contact-id'], $arr['uid']); + array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS, NETWORK_STATUSNET, ""))) { + poco_check($arr["author-link"], $arr["author-name"], $arr["network"], $arr["author-avatar"], "", $arr["received"], $arr["contact-id"], $arr["uid"]); + + // Maybe its a body with a shared item? Then extract a global contact from it. + poco_contact_from_body($arr["body"], $arr["received"], $arr["contact-id"], $arr["uid"]); + } // 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. @@ -1437,7 +1446,7 @@ function item_store($arr,$force_parent = false, $notify = false, $dontcache = fa if(count($r) > 1) { logger('item_store: duplicated post occurred. Removing duplicates.'); q("DELETE FROM `item` WHERE `uri` = '%s' AND `uid` = %d AND `id` != %d ", - $arr['uri'], + dbesc($arr['uri']), intval($arr['uid']), intval($current_post) ); diff --git a/include/socgraph.php b/include/socgraph.php index 0a85037901..b6bfa6831f 100644 --- a/include/socgraph.php +++ b/include/socgraph.php @@ -115,7 +115,22 @@ function poco_load($cid,$uid = 0,$zcid = 0,$url = null) { function poco_check($profile_url, $name, $network, $profile_photo, $connect_url, $updated, $cid = 0, $uid = 0, $zcid = 0) { $gcid = ""; - if (($profile_url == "") OR ($name == "") OR ($profile_photo == "")) + if ($profile_url == "") + return $gcid; + + if (($network == "") OR ($name == "") OR ($profile_photo == "")) { + require_once("include/Scrape.php"); + + $data = probe_url($profile_url, PROBE_DIASPORA); + $network = $data["network"]; + $name = $data["name"]; + $profile_photo = $data["photo"]; + } + + if (!in_array($network, array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_DIASPORA, NETWORK_STATUSNET))) + return $gcid; + + if (($name == "") OR ($profile_photo == "")) return $gcid; logger("profile-check URL: ".$profile_url." name: ".$name." avatar: ".$profile_photo, LOGGER_DEBUG); @@ -194,6 +209,30 @@ function poco_check($profile_url, $name, $network, $profile_photo, $connect_url, return $gcid; } +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, $cid, $uid); +} + function count_common_friends($uid,$cid) { $r = q("SELECT count(*) as `total` diff --git a/mod/poco.php b/mod/poco.php index 154f13c7ec..e7302a9621 100644 --- a/mod/poco.php +++ b/mod/poco.php @@ -83,8 +83,9 @@ function poco_init(&$a) { if($system_mode) { - $r = q("SELECT * FROM `contact` WHERE `self` = 1 AND `network` IN ('%s', '%s', '%s', '%s', '') - AND `uid` IN (SELECT `uid` FROM `pconfig` WHERE `cat` = 'system' AND `k` = 'suggestme' AND `v` = 1) LIMIT %d, %d", + $r = q("SELECT `contact`.*, `profile`.`about` AS `pabout`, `profile`.`locality` AS `plocation` FROM `contact` INNER JOIN `profile` ON `profile`.`uid` = `contact`.`uid` + WHERE `self` = 1 AND `network` IN ('%s', '%s', '%s', '%s', '') + AND `contact`.`uid` IN (SELECT `uid` FROM `pconfig` WHERE `cat` = 'system' AND `k` = 'suggestme' AND `v` = 1) LIMIT %d, %d", dbesc(NETWORK_DFRN), dbesc(NETWORK_DIASPORA), dbesc(NETWORK_OSTATUS), @@ -143,6 +144,12 @@ function poco_init(&$a) { if(is_array($r)) { if(count($r)) { foreach($r as $rr) { + if (($rr['about'] == "") AND isset($rr['pabout'])) + $rr['about'] = $rr['pabout']; + + if (($rr['location'] == "") AND isset($rr['plocation'])) + $rr['location'] = $rr['plocation']; + $entry = array(); if($fields_ret['id']) $entry['id'] = $rr['id']; -- 2.39.5