From e3da549ab5a96583ded2f4bc3d7b31e5d46fc44b Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Sun, 1 Feb 2015 10:26:35 +0100 Subject: [PATCH] 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 b09da9c17f..e9e0fd360a 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 a6429bbf49..30bd8b6074 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 affd59d489..c3099e2196 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 f2fde57878..217e0685be 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"]; + } + } } }