From 8992577bb63ba38bc3479dbbd8cf764ca1b15de5 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Wed, 4 May 2016 09:30:55 +0200 Subject: [PATCH 1/8] Better handling of hidden profiles --- include/socgraph.php | 6 ++++++ mod/settings.php | 10 +++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/include/socgraph.php b/include/socgraph.php index 0acd2793aa..b2b84808b1 100644 --- a/include/socgraph.php +++ b/include/socgraph.php @@ -1535,6 +1535,7 @@ function update_gcontact($contact) { unset($fields["url"]); unset($fields["updated"]); + unset($fields["hide"]); // Bugfix: We had an error in the storing of keywords which lead to the "0" // This value is still transmitted via poco. @@ -1549,6 +1550,11 @@ function update_gcontact($contact) { if (!isset($contact[$field]) OR ($contact[$field] == "")) $contact[$field] = $r[0][$field]; + if (!isset($contact["hide"])) + $contact["hide"] = $r[0]["hide"]; + + $fields["hide"] = $r[0]["hide"]; + if ($contact["network"] == NETWORK_STATUSNET) $contact["network"] = NETWORK_OSTATUS; diff --git a/mod/settings.php b/mod/settings.php index c7659212bf..1a7905ef64 100644 --- a/mod/settings.php +++ b/mod/settings.php @@ -1,6 +1,7 @@ $username, "generation" => 1, "hide" => ($hidewall OR !$net_publish), + "network" => NETWORK_DFRN, "url" => $r[0]["url"], "updated" => datetime_convert()); + + update_gcontact($gcontact); + } require_once('include/profile_update.php'); profile_change(); From fbc54045224f1fef2caf6d5b635bc864e62b7e45 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Wed, 4 May 2016 23:21:30 +0200 Subject: [PATCH 2/8] DFRN: "Hidewall" is now transmitted, "hide" is respected in dfrn and ostatus. --- include/dfrn.php | 29 +++++++++++++++++++++++++---- include/diaspora.php | 38 +++----------------------------------- include/ostatus.php | 2 ++ include/socgraph.php | 9 +++++++-- 4 files changed, 37 insertions(+), 41 deletions(-) diff --git a/include/dfrn.php b/include/dfrn.php index f6f4366029..7173421860 100644 --- a/include/dfrn.php +++ b/include/dfrn.php @@ -561,6 +561,13 @@ class dfrn { } } + // Is the profile hidden or shouldn't be published in the net? Then add the "hide" element + $r = q("SELECT `id` FROM `profile` INNER JOIN `user` ON `user`.`uid` = `profile`.`uid` + WHERE `hidewall` OR NOT `net-publish` AND `user`.`uid` = %d", + intval($owner['uid'])); + if ($r) + xml::add_element($doc, $author, "dfrn:hide", "true"); + return $author; } @@ -1126,7 +1133,7 @@ class dfrn { $author["link"] = $xpath->evaluate($element."/atom:uri/text()", $context)->item(0)->nodeValue; $r = q("SELECT `id`, `uid`, `url`, `network`, `avatar-date`, `name-date`, `uri-date`, `addr`, - `name`, `nick`, `about`, `location`, `keywords`, `bdyear`, `bd` + `name`, `nick`, `about`, `location`, `keywords`, `bdyear`, `bd`, `hidden` FROM `contact` WHERE `uid` = %d AND `nurl` = '%s' AND `network` != '%s'", intval($importer["uid"]), dbesc(normalise_link($author["link"])), dbesc(NETWORK_STATUSNET)); if ($r) { @@ -1210,6 +1217,19 @@ class dfrn { /// - poco:region /// - poco:country + // The profile is searchable if it contains poco data + $searchable = (isset($poco["name"]) OR isset($poco["nick"]) OR isset($poco["about"]) OR isset($poco["location"])); + + // If the "hide" element is present then the profile isn't searchable. + // Since this element is new (version >= 3.5), we need the check above as well. + if ($xpath->evaluate($element."/dfrn:hide/text()", $context)->item(0)->nodeValue == "true") + $searchable = false; + + // If the contact isn't searchable then set the contact to "hidden". + // Problem: This can be manually overridden by the user. + if (!$searchable) + $contact["hidden"] = true; + // Save the keywords into the contact table $tags = array(); $tagelements = $xpath->evaluate($element."/poco:tags/text()", $context); @@ -1280,13 +1300,13 @@ class dfrn { logger("Update contact data for contact ".$contact["id"]." (".$contact["nick"].")", LOGGER_DEBUG); q("UPDATE `contact` SET `name` = '%s', `nick` = '%s', `about` = '%s', `location` = '%s', - `addr` = '%s', `keywords` = '%s', `bdyear` = '%s', `bd` = '%s', + `addr` = '%s', `keywords` = '%s', `bdyear` = '%s', `bd` = '%s', `hidden` = %d, `name-date` = '%s', `uri-date` = '%s' WHERE `id` = %d AND `network` = '%s'", dbesc($contact["name"]), dbesc($contact["nick"]), dbesc($contact["about"]), dbesc($contact["location"]), dbesc($contact["addr"]), dbesc($contact["keywords"]), dbesc($contact["bdyear"]), - dbesc($contact["bd"]), dbesc($contact["name-date"]), dbesc($contact["uri-date"]), - intval($contact["id"]), dbesc($contact["network"])); + dbesc($contact["bd"]), intval($contact["hidden"]), dbesc($contact["name-date"]), + dbesc($contact["uri-date"]), intval($contact["id"]), dbesc($contact["network"])); } update_contact_avatar($author["avatar"], $importer["uid"], $contact["id"], @@ -1299,6 +1319,7 @@ class dfrn { $poco["generation"] = 2; $poco["photo"] = $author["avatar"]; + $poco["hide"] = !$searchable; update_gcontact($poco); } diff --git a/include/diaspora.php b/include/diaspora.php index 0556511857..3a21130246 100644 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -2,43 +2,11 @@ /** * @file include/diaspora.php * @brief The implementation of the diaspora protocol - * - * Checklist: - * - * Checked: - * - send status - * - send comment - * - send like - * - send mail - * - send status retraction - * - send comment retraction on own post - * - send like retraction on own post - * - send comment retraction on diaspora post - * - send like retraction on diaspora post - * - receive status - * - receive reshare - * - receive comment - * - receive like - * - receive connect request - * - receive profile data - * - receive mail - * - receive comment retraction - * - receive like retraction - * - relay comment - * - relay like - * - relay comment retraction from diaspora - * - relay comment retraction from friendica - * - relay like retraction from diaspora - * - relay like retraction from friendica - * - send share - * - * Should work: - * - receive account deletion - * - send unshare - * - * Unchecked: */ +/// @todo reshare of some reshare doesn't work well, see guid c1d534b0ed19013358694860008dbc6c +// 14f571c0f244013358694860008dbc6c + require_once("include/items.php"); require_once("include/bb2diaspora.php"); require_once("include/Scrape.php"); diff --git a/include/ostatus.php b/include/ostatus.php index b798a605f9..918dec5f32 100644 --- a/include/ostatus.php +++ b/include/ostatus.php @@ -161,6 +161,7 @@ class ostatus { } $contact["generation"] = 2; + $contact["hide"] = false; // OStatus contacts are never hidden $contact["photo"] = $author["author-avatar"]; update_gcontact($contact); } @@ -691,6 +692,7 @@ class ostatus { } } + $contact["hide"] = false; // OStatus contacts are never hidden update_gcontact($contact); } diff --git a/include/socgraph.php b/include/socgraph.php index b2b84808b1..07418a7177 100644 --- a/include/socgraph.php +++ b/include/socgraph.php @@ -1447,6 +1447,10 @@ function get_gcontact_id($contact) { if ($contact["network"] == NETWORK_STATUSNET) $contact["network"] = NETWORK_OSTATUS; + // All new contacts are hidden by default + if (!isset($contact["hide"])) + $contact["hide"] = true; + // Replace alternate OStatus user format with the primary one fix_alternate_contact_address($contact); @@ -1469,8 +1473,8 @@ function get_gcontact_id($contact) { $doprobing = (((time() - $last_contact) > (90 * 86400)) AND ((time() - $last_failure) > (90 * 86400))); } } else { - q("INSERT INTO `gcontact` (`name`, `nick`, `addr` , `network`, `url`, `nurl`, `photo`, `created`, `updated`, `location`, `about`, `generation`) - VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d)", + q("INSERT INTO `gcontact` (`name`, `nick`, `addr` , `network`, `url`, `nurl`, `photo`, `created`, `updated`, `location`, `about`, `hide`, `generation`) + VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d)", dbesc($contact["name"]), dbesc($contact["nick"]), dbesc($contact["addr"]), @@ -1482,6 +1486,7 @@ function get_gcontact_id($contact) { dbesc(datetime_convert()), dbesc($contact["location"]), dbesc($contact["about"]), + intval($contact["hide"]), intval($contact["generation"]) ); From ed485b9d616d8f8eba765c7a6551b854eb655c1a Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Wed, 4 May 2016 23:50:31 +0200 Subject: [PATCH 3/8] Set "hide" in noscrape --- include/socgraph.php | 10 +++++++--- mod/noscrape.php | 6 +++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/include/socgraph.php b/include/socgraph.php index 07418a7177..a43d710fbd 100644 --- a/include/socgraph.php +++ b/include/socgraph.php @@ -453,8 +453,11 @@ function poco_last_updated($profile, $force = false) { "network" => $server[0]["network"], "generation" => $gcontacts[0]["generation"]); - $contact["name"] = $noscrape["fn"]; - $contact["community"] = $noscrape["comm"]; + if (isset($noscrape["fn"])) + $contact["name"] = $noscrape["fn"]; + + if (isset($noscrape["comm"])) + $contact["community"] = $noscrape["comm"]; if (isset($noscrape["tags"])) { $keywords = implode(" ", $noscrape["tags"]); @@ -466,7 +469,8 @@ function poco_last_updated($profile, $force = false) { if ($location) $contact["location"] = $location; - $contact["notify"] = $noscrape["dfrn-notify"]; + if (isset($noscrape["dfrn-notify"])) + $contact["notify"] = $noscrape["dfrn-notify"]; // Remove all fields that are not present in the gcontact table unset($noscrape["fn"]); diff --git a/mod/noscrape.php b/mod/noscrape.php index 4be1a740cd..42931cf382 100644 --- a/mod/noscrape.php +++ b/mod/noscrape.php @@ -15,8 +15,12 @@ function noscrape_init(&$a) { profile_load($a,$which,$profile); - if(!$a->profile['net-publish']) + if(!$a->profile['net-publish']) { + header('Content-type: application/json; charset=utf-8'); + $json_info = array("hide" => true); + echo json_encode($json_info); killme(); + } $keywords = ((x($a->profile,'pub_keywords')) ? $a->profile['pub_keywords'] : ''); $keywords = str_replace(array('#',',',' ',',,'),array('',' ',',',','),$keywords); From 683cdcc19ef261f5fe632838a1e14567fc874ba2 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Thu, 5 May 2016 00:29:54 +0200 Subject: [PATCH 4/8] Changed check for searchability --- include/dfrn.php | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/include/dfrn.php b/include/dfrn.php index 7173421860..79b1a98370 100644 --- a/include/dfrn.php +++ b/include/dfrn.php @@ -1217,13 +1217,8 @@ class dfrn { /// - poco:region /// - poco:country - // The profile is searchable if it contains poco data - $searchable = (isset($poco["name"]) OR isset($poco["nick"]) OR isset($poco["about"]) OR isset($poco["location"])); - // If the "hide" element is present then the profile isn't searchable. - // Since this element is new (version >= 3.5), we need the check above as well. - if ($xpath->evaluate($element."/dfrn:hide/text()", $context)->item(0)->nodeValue == "true") - $searchable = false; + $searchable = !($xpath->evaluate($element."/dfrn:hide/text()", $context)->item(0)->nodeValue == "true"); // If the contact isn't searchable then set the contact to "hidden". // Problem: This can be manually overridden by the user. From 90155da59a27b75c784e09f7243354174ad2522a Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Thu, 5 May 2016 06:46:23 +0200 Subject: [PATCH 5/8] The "hide" element is included in the feed as well. --- include/dfrn.php | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/include/dfrn.php b/include/dfrn.php index 79b1a98370..daa1aae25c 100644 --- a/include/dfrn.php +++ b/include/dfrn.php @@ -490,6 +490,13 @@ class dfrn { if ($birthday) xml::add_element($doc, $author, "dfrn:birthday", $birthday); + // Is the profile hidden or shouldn't be published in the net? Then add the "hide" element + $r = q("SELECT `id` FROM `profile` INNER JOIN `user` ON `user`.`uid` = `profile`.`uid` + WHERE `hidewall` OR NOT `net-publish` AND `user`.`uid` = %d", + intval($owner['uid'])); + if ($r) + xml::add_element($doc, $author, "dfrn:hide", "true"); + // The following fields will only be generated if this isn't for a public feed if ($public) return $author; @@ -561,13 +568,6 @@ class dfrn { } } - // Is the profile hidden or shouldn't be published in the net? Then add the "hide" element - $r = q("SELECT `id` FROM `profile` INNER JOIN `user` ON `user`.`uid` = `profile`.`uid` - WHERE `hidewall` OR NOT `net-publish` AND `user`.`uid` = %d", - intval($owner['uid'])); - if ($r) - xml::add_element($doc, $author, "dfrn:hide", "true"); - return $author; } @@ -1218,11 +1218,13 @@ class dfrn { /// - poco:country // If the "hide" element is present then the profile isn't searchable. - $searchable = !($xpath->evaluate($element."/dfrn:hide/text()", $context)->item(0)->nodeValue == "true"); + $hide = intval($xpath->evaluate($element."/dfrn:hide/text()", $context)->item(0)->nodeValue == "true"); + + logger("Hidden status for contact ".$contact["url"].": ".$hide, LOGGER_DEBUG); // If the contact isn't searchable then set the contact to "hidden". // Problem: This can be manually overridden by the user. - if (!$searchable) + if ($hide) $contact["hidden"] = true; // Save the keywords into the contact table @@ -1277,17 +1279,17 @@ class dfrn { unset($fields["name-date"]); unset($fields["uri-date"]); - // Update check for this field has to be done differently + // Update check for this field has to be done differently $datefields = array("name-date", "uri-date"); foreach ($datefields AS $field) if (strtotime($contact[$field]) > strtotime($r[0][$field])) { - logger("Difference for contact ".$contact["id"]." in field '".$field."'. Old value: '".$contact[$field]."', new value '".$r[0][$field]."'", LOGGER_DEBUG); + logger("Difference for contact ".$contact["id"]." in field '".$field."'. New value: '".$contact[$field]."', old value '".$r[0][$field]."'", LOGGER_DEBUG); $update = true; } foreach ($fields AS $field => $data) if ($contact[$field] != $r[0][$field]) { - logger("Difference for contact ".$contact["id"]." in field '".$field."'. Old value: '".$contact[$field]."', new value '".$r[0][$field]."'", LOGGER_DEBUG); + logger("Difference for contact ".$contact["id"]." in field '".$field."'. New value: '".$contact[$field]."', old value '".$r[0][$field]."'", LOGGER_DEBUG); $update = true; } @@ -1314,7 +1316,7 @@ class dfrn { $poco["generation"] = 2; $poco["photo"] = $author["avatar"]; - $poco["hide"] = !$searchable; + $poco["hide"] = $hide; update_gcontact($poco); } From 3df235e5bd2666fdb4043e374d1df15414a355bd Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Thu, 5 May 2016 12:02:51 +0200 Subject: [PATCH 6/8] The global contact for server users is now stored directly --- include/dfrn.php | 4 ++-- mod/noscrape.php | 4 ++-- mod/profiles.php | 13 ++++++++++++- mod/settings.php | 9 ++++++--- 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/include/dfrn.php b/include/dfrn.php index daa1aae25c..f1b325b571 100644 --- a/include/dfrn.php +++ b/include/dfrn.php @@ -492,12 +492,12 @@ class dfrn { // Is the profile hidden or shouldn't be published in the net? Then add the "hide" element $r = q("SELECT `id` FROM `profile` INNER JOIN `user` ON `user`.`uid` = `profile`.`uid` - WHERE `hidewall` OR NOT `net-publish` AND `user`.`uid` = %d", + WHERE (`hidewall` OR NOT `net-publish`) AND `user`.`uid` = %d", intval($owner['uid'])); if ($r) xml::add_element($doc, $author, "dfrn:hide", "true"); - // The following fields will only be generated if this isn't for a public feed + // The following fields will only be generated if the data isn't meant for a public feed if ($public) return $author; diff --git a/mod/noscrape.php b/mod/noscrape.php index 42931cf382..2a04605469 100644 --- a/mod/noscrape.php +++ b/mod/noscrape.php @@ -15,11 +15,11 @@ function noscrape_init(&$a) { profile_load($a,$which,$profile); - if(!$a->profile['net-publish']) { + if (!$a->profile['net-publish'] OR $a->profile['hidewall']) { header('Content-type: application/json; charset=utf-8'); $json_info = array("hide" => true); echo json_encode($json_info); - killme(); + exit; } $keywords = ((x($a->profile,'pub_keywords')) ? $a->profile['pub_keywords'] : ''); diff --git a/mod/profiles.php b/mod/profiles.php index 39382fbdd5..4ab35455ce 100644 --- a/mod/profiles.php +++ b/mod/profiles.php @@ -484,7 +484,7 @@ function profiles_post(&$a) { if($is_default) { $location = formatted_location(array("locality" => $locality, "region" => $region, "country-name" => $country_name)); - $r = q("UPDATE `contact` SET `about` = '%s', `location` = '%s', `keywords` = '%s', `gender` = '%s' WHERE `self` = 1 AND `uid` = %d", + q("UPDATE `contact` SET `about` = '%s', `location` = '%s', `keywords` = '%s', `gender` = '%s' WHERE `self` AND `uid` = %d", dbesc($about), dbesc($location), dbesc($pub_keywords), @@ -492,6 +492,17 @@ function profiles_post(&$a) { intval(local_user()) ); + $r = q("SELECT `avatar`, `notify`, `url` FROM `contact` WHERE `self` AND `uid` = %d", + intval(local_user())); + + $gcontact = array("name" => $name, "location" => $location, "about" => $about, + "gender" => $gender, "keywords" => $pub_keywords, "birthday" => $dob, + "photo" => $r[0]["avatar"], "notify" => $r[0]["notify"], + "generation" => 1, "network" => NETWORK_DFRN, + "url" => $r[0]["url"], "updated" => datetime_convert()); + + update_gcontact($gcontact); + // Update global directory in background $url = $_SESSION['my_url']; if($url && strlen(get_config('system','directory'))) diff --git a/mod/settings.php b/mod/settings.php index 1a7905ef64..682bee3756 100644 --- a/mod/settings.php +++ b/mod/settings.php @@ -620,9 +620,12 @@ function settings_post(&$a) { $r = q("SELECT `url` FROM `contact` WHERE `self` AND `uid` = %d", intval(local_user())); if ($r) { + $nickname = $a->user['nickname']; + $addr = $nickname.'@'.str_replace(array("http://", "https://"), "", App::get_baseurl()); $gcontact = array("name" => $username, "generation" => 1, "hide" => ($hidewall OR !$net_publish), + "nick" => $nickname, "addr" => $addr, + "connect" => $addr, "server_url" => App::get_baseurl(), "network" => NETWORK_DFRN, "url" => $r[0]["url"], "updated" => datetime_convert()); - update_gcontact($gcontact); } @@ -637,7 +640,7 @@ function settings_post(&$a) { } - goaway('settings' ); + goaway('settings'); return; // NOTREACHED } @@ -1287,7 +1290,7 @@ function settings_content(&$a) { '$notify7' => array('notify7', t('You are tagged in a post'), ($notify & NOTIFY_TAGSELF), NOTIFY_TAGSELF, ''), '$notify8' => array('notify8', t('You are poked/prodded/etc. in a post'), ($notify & NOTIFY_POKE), NOTIFY_POKE, ''), - '$desktop_notifications' => array('desktop_notifications', t('Activate desktop notifications') , false, t('Show desktop popup on new notifications')), + '$desktop_notifications' => array('desktop_notifications', t('Activate desktop notifications') , false, t('Show desktop popup on new notifications')), '$email_textonly' => array('email_textonly', t('Text-only notification emails'), get_pconfig(local_user(),'system','email_textonly'), From de431e185e81cf7fe3f73b2977f777c040964479 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Thu, 5 May 2016 15:08:05 +0200 Subject: [PATCH 7/8] New function to update the global contact for the user id. --- include/socgraph.php | 59 ++++++++++++++++++++++++++++++++++++-------- mod/profiles.php | 14 +++-------- mod/settings.php | 15 +++-------- 3 files changed, 55 insertions(+), 33 deletions(-) diff --git a/include/socgraph.php b/include/socgraph.php index a43d710fbd..d6aae1975e 100644 --- a/include/socgraph.php +++ b/include/socgraph.php @@ -1395,23 +1395,23 @@ function poco_discover_server($data, $default_generation = 0) { * @return string Contact url with the wanted parts */ function clean_contact_url($url) { - $parts = parse_url($url); + $parts = parse_url($url); - if (!isset($parts["scheme"]) OR !isset($parts["host"])) - return $url; + if (!isset($parts["scheme"]) OR !isset($parts["host"])) + return $url; - $new_url = $parts["scheme"]."://".$parts["host"]; + $new_url = $parts["scheme"]."://".$parts["host"]; - if (isset($parts["port"])) - $new_url .= ":".$parts["port"]; + if (isset($parts["port"])) + $new_url .= ":".$parts["port"]; - if (isset($parts["path"])) - $new_url .= $parts["path"]; + if (isset($parts["path"])) + $new_url .= $parts["path"]; if ($new_url != $url) logger("Cleaned contact url ".$url." to ".$new_url." - Called by: ".App::callstack(), LOGGER_DEBUG); - return $new_url; + return $new_url; } /** @@ -1421,7 +1421,7 @@ function clean_contact_url($url) { */ function fix_alternate_contact_address(&$contact) { if (($contact["network"] == NETWORK_OSTATUS) AND poco_alternate_ostatus_url($contact["url"])) { - $data = probe_url($contact["url"]); + $data = probe_url($contact["url"]); if ($contact["network"] == NETWORK_OSTATUS) { logger("Fix primary url from ".$contact["url"]." to ".$data["url"]." - Called by: ".App::callstack(), LOGGER_DEBUG); $contact["url"] = $data["url"]; @@ -1672,6 +1672,45 @@ function update_gcontact_from_probe($url) { update_gcontact($data); } +/** + * @brief Update the gcontact entry for a given user id + * + * @param int $uid User ID + */ +function update_gcontact_for_user($uid) { + $r = q("SELECT `profile`.`locality`, `profile`.`region`, `profile`.`country-name`, + `profile`.`name`, `profile`.`about`, `profile`.`gender`, + `profile`.`pub_keywords`, `profile`.`dob`, `profile`.`photo`, + `profile`.`net-publish`, `user`.`nickname`, `user`.`hidewall`, + `contact`.`notify`, `contact`.`url`, `contact`.`addr` + FROM `profile` + INNER JOIN `user` ON `user`.`uid` = `profile`.`uid` + INNER JOIN `contact` ON `contact`.`uid` = `profile`.`uid` + WHERE `profile`.`uid` = %d AND `profile`.`is-default` AND `contact`.`self`", + intval($uid)); + + $location = formatted_location(array("locality" => $r[0]["locality"], "region" => $r[0]["region"], + "country-name" => $r[0]["country-name"])); + + // The "addr" field was added in 3.4.3 so it can be empty for older users + if ($r[0]["addr"] != "") + $addr = $r[0]["nickname"].'@'.str_replace(array("http://", "https://"), "", App::get_baseurl()); + else + $addr = $r[0]["addr"]; + + $gcontact = array("name" => $r[0]["name"], "location" => $location, "about" => $r[0]["about"], + "gender" => $r[0]["gender"], "keywords" => $r[0]["pub_keywords"], + "birthday" => $r[0]["dob"], "photo" => $r[0]["photo"], + "notify" => $r[0]["notify"], "url" => $r[0]["url"], + "hide" => ($r[0]["hidewall"] OR !$r[0]["net-publish"]), + "nick" => $r[0]["nickname"], "addr" => $addr, + "connect" => $addr, "server_url" => App::get_baseurl(), + "generation" => 1, "network" => NETWORK_DFRN, + "updated" => datetime_convert()); + + update_gcontact($gcontact); +} + /** * @brief Fetches users of given GNU Social server * diff --git a/mod/profiles.php b/mod/profiles.php index 4ab35455ce..780a279b54 100644 --- a/mod/profiles.php +++ b/mod/profiles.php @@ -492,17 +492,6 @@ function profiles_post(&$a) { intval(local_user()) ); - $r = q("SELECT `avatar`, `notify`, `url` FROM `contact` WHERE `self` AND `uid` = %d", - intval(local_user())); - - $gcontact = array("name" => $name, "location" => $location, "about" => $about, - "gender" => $gender, "keywords" => $pub_keywords, "birthday" => $dob, - "photo" => $r[0]["avatar"], "notify" => $r[0]["notify"], - "generation" => 1, "network" => NETWORK_DFRN, - "url" => $r[0]["url"], "updated" => datetime_convert()); - - update_gcontact($gcontact); - // Update global directory in background $url = $_SESSION['my_url']; if($url && strlen(get_config('system','directory'))) @@ -510,6 +499,9 @@ function profiles_post(&$a) { require_once('include/profile_update.php'); profile_change(); + + // Update the global contact for the user + update_gcontact_for_user(local_user()); } } } diff --git a/mod/settings.php b/mod/settings.php index 682bee3756..5168589f79 100644 --- a/mod/settings.php +++ b/mod/settings.php @@ -615,23 +615,14 @@ function settings_post(&$a) { $url = $_SESSION['my_url']; if($url && strlen(get_config('system','directory'))) proc_run('php',"include/directory.php","$url"); - - } - - $r = q("SELECT `url` FROM `contact` WHERE `self` AND `uid` = %d", intval(local_user())); - if ($r) { - $nickname = $a->user['nickname']; - $addr = $nickname.'@'.str_replace(array("http://", "https://"), "", App::get_baseurl()); - $gcontact = array("name" => $username, "generation" => 1, "hide" => ($hidewall OR !$net_publish), - "nick" => $nickname, "addr" => $addr, - "connect" => $addr, "server_url" => App::get_baseurl(), - "network" => NETWORK_DFRN, "url" => $r[0]["url"], "updated" => datetime_convert()); - update_gcontact($gcontact); } require_once('include/profile_update.php'); profile_change(); + // Update the global contact for the user + update_gcontact_for_user(local_user()); + //$_SESSION['theme'] = $theme; if($email_changed && $a->config['register_policy'] == REGISTER_VERIFY) { From bd1030b2460ab7709b37ec65d99116a87b286887 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Thu, 5 May 2016 15:38:28 +0200 Subject: [PATCH 8/8] Update the global contact entries for local users on a regular base --- include/cron.php | 6 ++++++ include/socgraph.php | 3 +-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/include/cron.php b/include/cron.php index 00dd500704..c1e4338d6f 100644 --- a/include/cron.php +++ b/include/cron.php @@ -410,6 +410,12 @@ function cron_repair_database() { // There was an issue where the nick vanishes from the contact table q("UPDATE `contact` INNER JOIN `user` ON `contact`.`uid` = `user`.`uid` SET `nick` = `nickname` WHERE `self` AND `nick`=''"); + // Update the global contacts for local users + $r = q("SELECT `uid` FROM `user` WHERE `verified` AND NOT `blocked` AND NOT `account_removed` AND NOT `account_expired`"); + if ($r) + foreach ($r AS $user) + update_gcontact_for_user($user["uid"]); + /// @todo /// - remove thread entries without item /// - remove sign entries without item diff --git a/include/socgraph.php b/include/socgraph.php index d6aae1975e..3718f82306 100644 --- a/include/socgraph.php +++ b/include/socgraph.php @@ -1705,8 +1705,7 @@ function update_gcontact_for_user($uid) { "hide" => ($r[0]["hidewall"] OR !$r[0]["net-publish"]), "nick" => $r[0]["nickname"], "addr" => $addr, "connect" => $addr, "server_url" => App::get_baseurl(), - "generation" => 1, "network" => NETWORK_DFRN, - "updated" => datetime_convert()); + "generation" => 1, "network" => NETWORK_DFRN); update_gcontact($gcontact); }