From e3da549ab5a96583ded2f4bc3d7b31e5d46fc44b Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Sun, 1 Feb 2015 10:26:35 +0100 Subject: [PATCH 1/7] Reshared diaspora items that aren't on this server are now stored with uid=0 --- boot.php | 10 +++--- include/Contact.php | 74 ++++++++++++++++++++++++++++++++++++++++++++ include/diaspora.php | 15 +++------ mod/display.php | 24 ++++++++++++++ 4 files changed, 108 insertions(+), 15 deletions(-) diff --git a/boot.php b/boot.php index b09da9c17..e9e0fd360 100644 --- a/boot.php +++ b/boot.php @@ -1405,11 +1405,11 @@ if(! function_exists('get_max_import_size')) { if(! function_exists('profile_load')) { function profile_load(&$a, $nickname, $profile = 0, $profiledata = array()) { - $user = q("select uid from user where nickname = '%s' limit 1", + $user = q("SELECT `uid` FROM `user` WHERE `nickname` = '%s' LIMIT 1", dbesc($nickname) ); - if(! ($user && count($user))) { + if(!$user && count($user) && !count($profiledata)) { logger('profile error: ' . $a->query_string, LOGGER_DEBUG); notice( t('Requested account is not available.') . EOL ); $a->error = 404; @@ -1440,7 +1440,7 @@ if(! function_exists('profile_load')) { intval($profile_int) ); } - if((! $r) && (! count($r))) { + if((!$r) && (!count($r))) { $r = q("SELECT `profile`.`uid` AS `profile_uid`, `profile`.* , `contact`.`avatar-date` AS picdate, `user`.* FROM `profile` INNER JOIN `contact` on `contact`.`uid` = `profile`.`uid` INNER JOIN `user` ON `profile`.`uid` = `user`.`uid` WHERE `user`.`nickname` = '%s' AND `profile`.`is-default` = 1 and `contact`.`self` = 1 LIMIT 1", @@ -1448,7 +1448,7 @@ if(! function_exists('profile_load')) { ); } - if(($r === false) || (! count($r))) { + if(($r === false) || (!count($r)) && !count($profiledata)) { logger('profile error: ' . $a->query_string, LOGGER_DEBUG); notice( t('Requested profile is not available.') . EOL ); $a->error = 404; @@ -1457,7 +1457,7 @@ if(! function_exists('profile_load')) { // fetch user tags if this isn't the default profile - if(! $r[0]['is-default']) { + if(!$r[0]['is-default']) { $x = q("select `pub_keywords` from `profile` where uid = %d and `is-default` = 1 limit 1", intval($r[0]['profile_uid']) ); diff --git a/include/Contact.php b/include/Contact.php index a6429bbf4..30bd8b607 100644 --- a/include/Contact.php +++ b/include/Contact.php @@ -293,3 +293,77 @@ function contacts_not_grouped($uid,$start = 0,$count = 0) { return $r; } +function get_contact($url, $uid = 0) { + require_once("include/Scrape.php"); + + $data = array(); + + // is it an address in the format user@server.tld? + if (!strstr($url, "http") OR strstr($url, "@")) { + $data = probe_url($url); + $url = $data["url"]; + if ($url == "") + return 0; + } + + $contact = q("SELECT `id` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d", + dbesc(normalise_link($url)), + intval($uid)); + if ($contact) + return($contact[0]["id"]); + + if (!count($data)) + $data = probe_url($url); + + // Does this address belongs to a valid network? + if (!in_array($data["network"], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_DIASPORA))) + return 0; + + q("INSERT INTO `contact` (`uid`, `created`, `url`, `nurl`, `addr`, `alias`, `notify`, `poll`, + `name`, `nick`, `photo`, `network`, `pubkey`, `rel`, `priority`, + `batch`, `request`, `confirm`, `poco`, + `writable`, `blocked`, `readonly`, `pending`) + VALUES (%d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, '%s', '%s', '%s', '%s', 1, 0, 0, 0)", + intval($uid), + dbesc(datetime_convert()), + dbesc($data["url"]), + dbesc(normalise_link($data["url"])), + dbesc($data["addr"]), + dbesc($data["alias"]), + dbesc($data["notify"]), + dbesc($data["poll"]), + dbesc($data["name"]), + dbesc($data["nick"]), + dbesc($data["photo"]), + dbesc($data["network"]), + dbesc($data["pubkey"]), + intval(CONTACT_IS_SHARING), + intval($data["priority"]), + dbesc($data["batch"]), + dbesc($data["request"]), + dbesc($data["confirm"]), + dbesc($data["poco"]) + ); + + $contact = q("SELECT `id` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d", + dbesc(normalise_link($url)), + intval($uid)); + if (!$contact) + return 0; + + require_once("Photo.php"); + + $photos = import_profile_photo($data["photo"],$uid,$contact[0]["id"]); + + q("UPDATE `contact` SET `photo` = '%s', `thumb` = '%s', `micro` = '%s', `name-date` = '%s', `uri-date` = '%s', `avatar-date` = '%s' WHERE `id` = %d", + dbesc($photos[0]), + dbesc($photos[1]), + dbesc($photos[2]), + dbesc(datetime_convert()), + dbesc(datetime_convert()), + dbesc(datetime_convert()), + intval($contact[0]["id"]) + ); + + return $contact[0]["id"]; +} diff --git a/include/diaspora.php b/include/diaspora.php index affd59d48..c3099e219 100755 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -897,13 +897,6 @@ function diaspora_post($importer,$xml,$msg) { $message_id = item_store($datarray); - //if($message_id) { - // q("update item set plink = '%s' where id = %d", - // dbesc($a->get_baseurl() . '/display/' . $importer['nickname'] . '/' . $message_id), - // intval($message_id) - // ); - //} - return; } @@ -1102,7 +1095,8 @@ function diaspora_reshare($importer,$xml,$msg) { $orig_created = $item["created"]; $orig_author = $item["author"]; $orig_guid = $item["guid"]; - //$create_original_post = ($body != ""); + $create_original_post = ($body != ""); + $orig_url = $a->get_baseurl()."/display/".$orig_guid; } } @@ -1164,12 +1158,13 @@ function diaspora_reshare($importer,$xml,$msg) { $datarray['visible'] = ((strlen($body)) ? 1 : 0); // Store the original item of a reshare - // Deactivated by now. Items without a matching contact can't be shown via "mod/display.php" by now. if ($create_original_post) { + require_once("include/Contact.php"); + $datarray2 = $datarray; $datarray2['uid'] = 0; - $datarray2['contact-id'] = 0; + $datarray2['contact-id'] = get_contact($person['url'], 0); $datarray2['guid'] = $orig_guid; $datarray2['uri'] = $datarray2['parent-uri'] = $orig_author.':'.$orig_guid; $datarray2['changed'] = $datarray2['created'] = $datarray2['edited'] = datetime_convert('UTC','UTC',$orig_created); diff --git a/mod/display.php b/mod/display.php index f2fde5787..217e0685b 100644 --- a/mod/display.php +++ b/mod/display.php @@ -41,6 +41,18 @@ function display_init(&$a) { $itemuid = $r[0]["uid"]; } } + + // Is it an item with uid=0? + if ($nick == "") { + $r = q("SELECT `item`.`id`, `item`.`parent`, `item`.`author-name`, + `item`.`author-link`, `item`.`author-avatar`, `item`.`network`, `item`.`uid`, `item`.`body` + FROM `item` WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0 + AND `item`.`allow_cid` = '' AND `item`.`allow_gid` = '' + AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = '' + AND `item`.`private` = 0 AND `item`.`uid` = 0 + AND `item`.`guid` = '%s'", $a->argv[1]); + // AND `item`.`private` = 0 AND `item`.`wall` = 1 + } if (count($r)) { if ($r[0]["id"] != $r[0]["parent"]) $r = q("SELECT `id`, `author-name`, `author-link`, `author-avatar`, `network`, `body`, `uid` FROM `item` @@ -252,6 +264,18 @@ function display_content(&$a, $update = 0) { $nick = $r[0]["nickname"]; } } + if ($nick == "") { + $r = q("SELECT `item`.`id` FROM `item` + WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0 + AND `item`.`allow_cid` = '' AND `item`.`allow_gid` = '' + AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = '' + AND `item`.`private` = 0 AND `item`.`uid` = 0 + AND `item`.`guid` = '%s'", $a->argv[1]); + // AND `item`.`private` = 0 AND `item`.`wall` = 1 + if (count($r)) { + $item_id = $r[0]["id"]; + } + } } } From b95d34f9dbb7dd46d059ebff36b38084ddcb2282 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Sun, 1 Feb 2015 13:32:05 +0100 Subject: [PATCH 2/7] Aliases are now handled correctly. The public item copy gets a "real" contact id as well. --- include/Contact.php | 120 +++++++++++++++++++++++++++----------------- include/Scrape.php | 6 ++- include/threads.php | 4 +- 3 files changed, 82 insertions(+), 48 deletions(-) diff --git a/include/Contact.php b/include/Contact.php index 30bd8b607..59c40599b 100644 --- a/include/Contact.php +++ b/include/Contact.php @@ -15,7 +15,7 @@ function user_remove($uid) { call_hooks('remove_user',$r[0]); - // save username (actually the nickname as it is guaranteed + // save username (actually the nickname as it is guaranteed // unique), so it cannot be re-registered in the future. q("insert into userd ( username ) values ( '%s' )", @@ -191,7 +191,7 @@ if(! function_exists('contact_photo_menu')){ function contact_photo_menu($contact) { $a = get_app(); - + $contact_url=""; $pm_url=""; $status_link=""; @@ -222,24 +222,24 @@ function contact_photo_menu($contact) { $contact_url = $a->get_baseurl() . '/contacts/' . $contact['id']; $posts_link = $a->get_baseurl() . '/network/0?nets=all&cid=' . $contact['id']; $contact_drop_link = $a->get_baseurl() . "/contacts/" . $contact['id'] . '/drop?confirm=1'; - + $menu = Array( 'poke' => array(t("Poke"), $poke_link), 'status' => array(t("View Status"), $status_link), 'profile' => array(t("View Profile"), $profile_link), - 'photos' => array(t("View Photos"), $photos_link), - 'network' => array(t("Network Posts"), $posts_link), + 'photos' => array(t("View Photos"), $photos_link), + 'network' => array(t("Network Posts"), $posts_link), 'edit' => array(t("Edit Contact"), $contact_url), 'drop' => array(t("Drop Contact"), $contact_drop_link), 'pm' => array(t("Send PM"), $pm_url), ); - - + + $args = array('contact' => $contact, 'menu' => &$menu); - + call_hooks('contact_photo_menu', $args); - + /* $o = ""; foreach($menu as $k=>$v){ if ($v!="") { @@ -297,6 +297,7 @@ function get_contact($url, $uid = 0) { require_once("include/Scrape.php"); $data = array(); + $contactid = 0; // is it an address in the format user@server.tld? if (!strstr($url, "http") OR strstr($url, "@")) { @@ -306,11 +307,24 @@ function get_contact($url, $uid = 0) { return 0; } - $contact = q("SELECT `id` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d", + $contact = q("SELECT `id`, `avatar-date` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d", dbesc(normalise_link($url)), intval($uid)); - if ($contact) - return($contact[0]["id"]); + + if (!$contact) + $contact = q("SELECT `id`, `avatar-date` FROM `contact` WHERE `alias` = '%s' AND `uid` = %d", + dbesc(normalise_link($url)), + intval($uid)); + + if ($contact) { + $contactid = $contact[0]["id"]; + + //$update_photo = ($contact[0]['avatar-date'] < datetime_convert('','','now -2 days')); + $update_photo = ($contact[0]['avatar-date'] < datetime_convert('','','now -12 hours')); + + if (!$update_photo) + return($contactid); + } if (!count($data)) $data = probe_url($url); @@ -319,51 +333,65 @@ function get_contact($url, $uid = 0) { if (!in_array($data["network"], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_DIASPORA))) return 0; - q("INSERT INTO `contact` (`uid`, `created`, `url`, `nurl`, `addr`, `alias`, `notify`, `poll`, - `name`, `nick`, `photo`, `network`, `pubkey`, `rel`, `priority`, - `batch`, `request`, `confirm`, `poco`, - `writable`, `blocked`, `readonly`, `pending`) - VALUES (%d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, '%s', '%s', '%s', '%s', 1, 0, 0, 0)", - intval($uid), - dbesc(datetime_convert()), - dbesc($data["url"]), - dbesc(normalise_link($data["url"])), - dbesc($data["addr"]), - dbesc($data["alias"]), - dbesc($data["notify"]), - dbesc($data["poll"]), - dbesc($data["name"]), - dbesc($data["nick"]), - dbesc($data["photo"]), - dbesc($data["network"]), - dbesc($data["pubkey"]), - intval(CONTACT_IS_SHARING), - intval($data["priority"]), - dbesc($data["batch"]), - dbesc($data["request"]), - dbesc($data["confirm"]), - dbesc($data["poco"]) - ); + // tempory programming. Can be deleted after 2015-02-07 + if (($data["alias"] == "") AND (normalise_link($data["url"]) != normalise_link($url))) + $data["alias"] = normalise_link($url); - $contact = q("SELECT `id` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d", - dbesc(normalise_link($url)), - intval($uid)); - if (!$contact) - return 0; + if ($contactid == 0) { + q("INSERT INTO `contact` (`uid`, `created`, `url`, `nurl`, `addr`, `alias`, `notify`, `poll`, + `name`, `nick`, `photo`, `network`, `pubkey`, `rel`, `priority`, + `batch`, `request`, `confirm`, `poco`, + `writable`, `blocked`, `readonly`, `pending`) + VALUES (%d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, '%s', '%s', '%s', '%s', 1, 0, 0, 0)", + intval($uid), + dbesc(datetime_convert()), + dbesc($data["url"]), + dbesc(normalise_link($data["url"])), + dbesc($data["addr"]), + dbesc($data["alias"]), + dbesc($data["notify"]), + dbesc($data["poll"]), + dbesc($data["name"]), + dbesc($data["nick"]), + dbesc($data["photo"]), + dbesc($data["network"]), + dbesc($data["pubkey"]), + intval(CONTACT_IS_SHARING), + intval($data["priority"]), + dbesc($data["batch"]), + dbesc($data["request"]), + dbesc($data["confirm"]), + dbesc($data["poco"]) + ); + + $contact = q("SELECT `id` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d", + dbesc(normalise_link($data["url"])), + intval($uid)); + if (!$contact) + return 0; + + $contactid = $contact[0]["id"]; + } require_once("Photo.php"); - $photos = import_profile_photo($data["photo"],$uid,$contact[0]["id"]); + $photos = import_profile_photo($data["photo"],$uid,$contactid); - q("UPDATE `contact` SET `photo` = '%s', `thumb` = '%s', `micro` = '%s', `name-date` = '%s', `uri-date` = '%s', `avatar-date` = '%s' WHERE `id` = %d", + q("UPDATE `contact` SET `photo` = '%s', `thumb` = '%s', `micro` = '%s', + `addr` = '%s', `alias` = '%s', `name` = '%s', `nick` = '%s', + `name-date` = '%s', `uri-date` = '%s', `avatar-date` = '%s' WHERE `id` = %d", dbesc($photos[0]), dbesc($photos[1]), dbesc($photos[2]), + dbesc($data["addr"]), + dbesc($data["alias"]), + dbesc($data["name"]), + dbesc($data["nick"]), dbesc(datetime_convert()), dbesc(datetime_convert()), dbesc(datetime_convert()), - intval($contact[0]["id"]) + intval($contactid) ); - return $contact[0]["id"]; + return $contactid; } diff --git a/include/Scrape.php b/include/Scrape.php index 7df86d9f2..c74fd879c 100644 --- a/include/Scrape.php +++ b/include/Scrape.php @@ -433,7 +433,7 @@ function probe_url($url, $mode = PROBE_NORMAL) { // to a contact on incoming messages to prevent spam, and we won't know which one // to match. So in case of two, one of them is stored as an alias. Only store URL's // and not webfinger user@host aliases. If they've got more than two non-email style - // aliases, let's hope we're lucky and get one that matches the feed author-uri because + // aliases, let's hope we're lucky and get one that matches the feed author-uri because // otherwise we're screwed. foreach($links as $link) { @@ -448,6 +448,10 @@ function probe_url($url, $mode = PROBE_NORMAL) { } } } + + // If the profile is different from the url then the url is abviously an alias + if (($alias == "") AND ($profile != "") AND !$at_addr AND (normalise_link($profile) != normalise_link($url))) + $alias = $url; } elseif($mode == PROBE_NORMAL) { diff --git a/include/threads.php b/include/threads.php index e9a0d7f1f..bd0cb0489 100644 --- a/include/threads.php +++ b/include/threads.php @@ -66,9 +66,11 @@ function add_thread($itemid, $onlyshadow = false) { if (!$r) { // Preparing public shadow (removing user specific data) require_once("include/items.php"); + require_once("include/Contact.php"); + unset($item[0]['id']); $item[0]['uid'] = 0; - $item[0]['contact-id'] = 0; + $item[0]['contact-id'] = get_contact($item[0]['author-link'], 0); $public_shadow = item_store($item[0], false, false, true); logger("add_thread: Stored public shadow for post ".$itemid." under id ".$public_shadow, LOGGER_DEBUG); From 75c60b259576cb53f669901d710c01a721ec84b4 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Sun, 1 Feb 2015 16:32:58 +0100 Subject: [PATCH 3/7] The alias can - or can not - be an SSL link. --- include/Contact.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/include/Contact.php b/include/Contact.php index 59c40599b..6777df65a 100644 --- a/include/Contact.php +++ b/include/Contact.php @@ -312,15 +312,17 @@ function get_contact($url, $uid = 0) { intval($uid)); if (!$contact) - $contact = q("SELECT `id`, `avatar-date` FROM `contact` WHERE `alias` = '%s' AND `uid` = %d", + $contact = q("SELECT `id`, `avatar-date` FROM `contact` WHERE `alias` IN ('%s', '%s') AND `uid` = %d", + dbesc($url), dbesc(normalise_link($url)), intval($uid)); if ($contact) { $contactid = $contact[0]["id"]; - //$update_photo = ($contact[0]['avatar-date'] < datetime_convert('','','now -2 days')); - $update_photo = ($contact[0]['avatar-date'] < datetime_convert('','','now -12 hours')); + // Update the contact every 7 days + $update_photo = ($contact[0]['avatar-date'] < datetime_convert('','','now -7 days')); + //$update_photo = ($contact[0]['avatar-date'] < datetime_convert('','','now -12 hours')); if (!$update_photo) return($contactid); From 9d155a62f9468ad6cd6b5372fbea0a1f94c56977 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Sun, 1 Feb 2015 21:54:44 +0100 Subject: [PATCH 4/7] New function to fetch and store an item based on the guid. --- include/diaspora.php | 54 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/include/diaspora.php b/include/diaspora.php index c3099e219..3f9d9b119 100755 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -901,6 +901,60 @@ function diaspora_post($importer,$xml,$msg) { } +function diaspora_store_by_guid($guid, $server) { + require_once("include/Contact.php"); + + $item = diaspora_fetch_message($guid, $server); + + if (!$item) + return false; + + $body = $item["body"]; + $str_tags = $item["tag"]; + $app = $item["app"]; + $created = $item["created"]; + $author = $item["author"]; + $guid = $item["guid"]; + $private = $item["private"]; + + $message_id = $author.':'.$guid; + $r = q("SELECT `id` FROM `item` WHERE `uid` = 0 AND `uri` = '%s' AND `guid` = '%s' LIMIT 1", + dbesc($message_id), + dbesc($guid) + ); + if(count($r)) + return true; + + $person = find_diaspora_person_by_handle($author); + + $datarray = array(); + + $datarray['uid'] = 0; + $datarray['contact-id'] = get_contact($person['url'], 0); + $datarray['wall'] = 0; + $datarray['network'] = NETWORK_DIASPORA; + $datarray['guid'] = $guid; + $datarray['uri'] = $datarray['parent-uri'] = $message_id; + $datarray['changed'] = $datarray['created'] = $datarray['edited'] = datetime_convert('UTC','UTC',$created); + $datarray['private'] = $private; + $datarray['parent'] = 0; + $datarray['plink'] = 'https://'.substr($author,strpos($author,'@')+1).'/posts/'.$guid; + $datarray['author-name'] = $person['name']; + $datarray['author-link'] = $person['url']; + $datarray['author-avatar'] = ((x($person,'thumb')) ? $person['thumb'] : $person['photo']); + $datarray['owner-name'] = $datarray['author-name']; + $datarray['owner-link'] = $datarray['author-link']; + $datarray['owner-avatar'] = $datarray['author-avatar']; + $datarray['body'] = $body; + $datarray['tag'] = $str_tags; + $datarray['app'] = $app; + $datarray['visible'] = ((strlen($body)) ? 1 : 0); + + $message_id = item_store($datarray); + + return $message_id; +} + function diaspora_fetch_message($guid, $server, $level = 0) { if ($level > 5) From 80ee58f8aac8a216091bf9afae8a4c445733f914 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Mon, 2 Feb 2015 20:24:19 +0100 Subject: [PATCH 5/7] Just an added to-do comment --- include/diaspora.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/diaspora.php b/include/diaspora.php index 3f9d9b119..631e9fba9 100755 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -952,6 +952,9 @@ function diaspora_store_by_guid($guid, $server) { $message_id = item_store($datarray); + // To-Do: + // Looking if there is some subscribe mechanism in Diaspora to get all comments for this post + return $message_id; } From 86a968002d1efc4a8629d3080a9cf38eb5baabe8 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Tue, 3 Feb 2015 00:29:21 +0100 Subject: [PATCH 6/7] Look for links to diaspora posts and try to fetch them if they aren't on the system. --- include/diaspora.php | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/include/diaspora.php b/include/diaspora.php index 67d36e70f..88a8e5e55 100755 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -895,15 +895,38 @@ function diaspora_post($importer,$xml,$msg) { $datarray['visible'] = ((strlen($body)) ? 1 : 0); + DiasporaFetchGuid($datarray); $message_id = item_store($datarray); return; } +function DiasporaFetchGuid($item) { + preg_replace_callback("&\[url=/posts/([^\[\]]*)\](.*)\[\/url\]&Usi", + function ($match) use ($item){ + return(DiasporaFetchGuidSub($match, $item)); + },$item["body"]); +} + +function DiasporaFetchGuidSub($match, $item) { + $a = get_app(); + + $author = parse_url($item["author-link"]); + $authorserver = $author["scheme"]."://".$author["host"]; + + $owner = parse_url($item["owner-link"]); + $ownerserver = $owner["scheme"]."://".$owner["host"]; + + if (!diaspora_store_by_guid($match[1], $authorserver)) + diaspora_store_by_guid($match[1], $ownerserver); +} + function diaspora_store_by_guid($guid, $server) { require_once("include/Contact.php"); + logger("fetching item ".$guid." from ".$server, LOGGER_DEBUG); + $item = diaspora_fetch_message($guid, $server); if (!$item) @@ -923,7 +946,7 @@ function diaspora_store_by_guid($guid, $server) { dbesc($guid) ); if(count($r)) - return true; + return $r[0]["id"]; $person = find_diaspora_person_by_handle($author); @@ -950,6 +973,7 @@ function diaspora_store_by_guid($guid, $server) { $datarray['app'] = $app; $datarray['visible'] = ((strlen($body)) ? 1 : 0); + DiasporaFetchGuid($datarray); $message_id = item_store($datarray); // To-Do: @@ -1235,11 +1259,13 @@ function diaspora_reshare($importer,$xml,$msg) { $datarray2['owner-avatar'] = $datarray2['author-avatar']; $datarray2['body'] = $body; + DiasporaFetchGuid($datarray2); $message_id = item_store($datarray2); logger("Store original item ".$orig_guid." under message id ".$message_id); } + DiasporaFetchGuid($datarray); $message_id = item_store($datarray); return; @@ -1332,6 +1358,7 @@ function diaspora_asphoto($importer,$xml,$msg) { $datarray['app'] = 'Diaspora/Cubbi.es'; + DiasporaFetchGuid($datarray); $message_id = item_store($datarray); //if($message_id) { @@ -1512,6 +1539,7 @@ function diaspora_comment($importer,$xml,$msg) { if(($parent_item['origin']) && (! $parent_author_signature)) $datarray['app'] = 'Diaspora'; + DiasporaFetchGuid($datarray); $message_id = item_store($datarray); //if($message_id) { From 226b551c8585fd6eff56926d009e9ce479d85794 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Tue, 3 Feb 2015 07:00:01 +0100 Subject: [PATCH 7/7] Only some code beautification. --- include/diaspora.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/include/diaspora.php b/include/diaspora.php index 88a8e5e55..f7537ef63 100755 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -946,12 +946,11 @@ function diaspora_store_by_guid($guid, $server) { dbesc($guid) ); if(count($r)) - return $r[0]["id"]; + return $r[0]["id"]; $person = find_diaspora_person_by_handle($author); $datarray = array(); - $datarray['uid'] = 0; $datarray['contact-id'] = get_contact($person['url'], 0); $datarray['wall'] = 0;