Merge pull request #2503 from annando/1605-hide-profile

Better handling of hidden profiles
This commit is contained in:
Tobias Diekershoff 2016-05-06 07:45:44 +02:00
commit 480c35fb86
8 changed files with 122 additions and 66 deletions

View file

@ -410,6 +410,12 @@ function cron_repair_database() {
// There was an issue where the nick vanishes from the contact table // 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`=''"); 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 /// @todo
/// - remove thread entries without item /// - remove thread entries without item
/// - remove sign entries without item /// - remove sign entries without item

View file

@ -490,7 +490,14 @@ class dfrn {
if ($birthday) if ($birthday)
xml::add_element($doc, $author, "dfrn:birthday", $birthday); xml::add_element($doc, $author, "dfrn:birthday", $birthday);
// The following fields will only be generated if this isn't for a public feed // 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 the data isn't meant for a public feed
if ($public) if ($public)
return $author; return $author;
@ -1126,7 +1133,7 @@ class dfrn {
$author["link"] = $xpath->evaluate($element."/atom:uri/text()", $context)->item(0)->nodeValue; $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`, $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'", FROM `contact` WHERE `uid` = %d AND `nurl` = '%s' AND `network` != '%s'",
intval($importer["uid"]), dbesc(normalise_link($author["link"])), dbesc(NETWORK_STATUSNET)); intval($importer["uid"]), dbesc(normalise_link($author["link"])), dbesc(NETWORK_STATUSNET));
if ($r) { if ($r) {
@ -1210,6 +1217,16 @@ class dfrn {
/// - poco:region /// - poco:region
/// - poco:country /// - poco:country
// If the "hide" element is present then the profile isn't searchable.
$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 ($hide)
$contact["hidden"] = true;
// Save the keywords into the contact table // Save the keywords into the contact table
$tags = array(); $tags = array();
$tagelements = $xpath->evaluate($element."/poco:tags/text()", $context); $tagelements = $xpath->evaluate($element."/poco:tags/text()", $context);
@ -1266,13 +1283,13 @@ class dfrn {
$datefields = array("name-date", "uri-date"); $datefields = array("name-date", "uri-date");
foreach ($datefields AS $field) foreach ($datefields AS $field)
if (strtotime($contact[$field]) > strtotime($r[0][$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; $update = true;
} }
foreach ($fields AS $field => $data) foreach ($fields AS $field => $data)
if ($contact[$field] != $r[0][$field]) { 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; $update = true;
} }
@ -1280,13 +1297,13 @@ class dfrn {
logger("Update contact data for contact ".$contact["id"]." (".$contact["nick"].")", LOGGER_DEBUG); logger("Update contact data for contact ".$contact["id"]." (".$contact["nick"].")", LOGGER_DEBUG);
q("UPDATE `contact` SET `name` = '%s', `nick` = '%s', `about` = '%s', `location` = '%s', 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' `name-date` = '%s', `uri-date` = '%s'
WHERE `id` = %d AND `network` = '%s'", WHERE `id` = %d AND `network` = '%s'",
dbesc($contact["name"]), dbesc($contact["nick"]), dbesc($contact["about"]), dbesc($contact["location"]), dbesc($contact["name"]), dbesc($contact["nick"]), dbesc($contact["about"]), dbesc($contact["location"]),
dbesc($contact["addr"]), dbesc($contact["keywords"]), dbesc($contact["bdyear"]), dbesc($contact["addr"]), dbesc($contact["keywords"]), dbesc($contact["bdyear"]),
dbesc($contact["bd"]), dbesc($contact["name-date"]), dbesc($contact["uri-date"]), dbesc($contact["bd"]), intval($contact["hidden"]), dbesc($contact["name-date"]),
intval($contact["id"]), dbesc($contact["network"])); dbesc($contact["uri-date"]), intval($contact["id"]), dbesc($contact["network"]));
} }
update_contact_avatar($author["avatar"], $importer["uid"], $contact["id"], update_contact_avatar($author["avatar"], $importer["uid"], $contact["id"],
@ -1299,6 +1316,7 @@ class dfrn {
$poco["generation"] = 2; $poco["generation"] = 2;
$poco["photo"] = $author["avatar"]; $poco["photo"] = $author["avatar"];
$poco["hide"] = $hide;
update_gcontact($poco); update_gcontact($poco);
} }

View file

@ -2,43 +2,11 @@
/** /**
* @file include/diaspora.php * @file include/diaspora.php
* @brief The implementation of the diaspora protocol * @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/items.php");
require_once("include/bb2diaspora.php"); require_once("include/bb2diaspora.php");
require_once("include/Scrape.php"); require_once("include/Scrape.php");

View file

@ -161,6 +161,7 @@ class ostatus {
} }
$contact["generation"] = 2; $contact["generation"] = 2;
$contact["hide"] = false; // OStatus contacts are never hidden
$contact["photo"] = $author["author-avatar"]; $contact["photo"] = $author["author-avatar"];
update_gcontact($contact); update_gcontact($contact);
} }
@ -691,6 +692,7 @@ class ostatus {
} }
} }
$contact["hide"] = false; // OStatus contacts are never hidden
update_gcontact($contact); update_gcontact($contact);
} }

View file

@ -453,7 +453,10 @@ function poco_last_updated($profile, $force = false) {
"network" => $server[0]["network"], "network" => $server[0]["network"],
"generation" => $gcontacts[0]["generation"]); "generation" => $gcontacts[0]["generation"]);
if (isset($noscrape["fn"]))
$contact["name"] = $noscrape["fn"]; $contact["name"] = $noscrape["fn"];
if (isset($noscrape["comm"]))
$contact["community"] = $noscrape["comm"]; $contact["community"] = $noscrape["comm"];
if (isset($noscrape["tags"])) { if (isset($noscrape["tags"])) {
@ -466,6 +469,7 @@ function poco_last_updated($profile, $force = false) {
if ($location) if ($location)
$contact["location"] = $location; $contact["location"] = $location;
if (isset($noscrape["dfrn-notify"]))
$contact["notify"] = $noscrape["dfrn-notify"]; $contact["notify"] = $noscrape["dfrn-notify"];
// Remove all fields that are not present in the gcontact table // Remove all fields that are not present in the gcontact table
@ -1447,6 +1451,10 @@ function get_gcontact_id($contact) {
if ($contact["network"] == NETWORK_STATUSNET) if ($contact["network"] == NETWORK_STATUSNET)
$contact["network"] = NETWORK_OSTATUS; $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 // Replace alternate OStatus user format with the primary one
fix_alternate_contact_address($contact); fix_alternate_contact_address($contact);
@ -1469,8 +1477,8 @@ function get_gcontact_id($contact) {
$doprobing = (((time() - $last_contact) > (90 * 86400)) AND ((time() - $last_failure) > (90 * 86400))); $doprobing = (((time() - $last_contact) > (90 * 86400)) AND ((time() - $last_failure) > (90 * 86400)));
} }
} else { } else {
q("INSERT INTO `gcontact` (`name`, `nick`, `addr` , `network`, `url`, `nurl`, `photo`, `created`, `updated`, `location`, `about`, `generation`) 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)", VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d)",
dbesc($contact["name"]), dbesc($contact["name"]),
dbesc($contact["nick"]), dbesc($contact["nick"]),
dbesc($contact["addr"]), dbesc($contact["addr"]),
@ -1482,6 +1490,7 @@ function get_gcontact_id($contact) {
dbesc(datetime_convert()), dbesc(datetime_convert()),
dbesc($contact["location"]), dbesc($contact["location"]),
dbesc($contact["about"]), dbesc($contact["about"]),
intval($contact["hide"]),
intval($contact["generation"]) intval($contact["generation"])
); );
@ -1535,6 +1544,7 @@ function update_gcontact($contact) {
unset($fields["url"]); unset($fields["url"]);
unset($fields["updated"]); unset($fields["updated"]);
unset($fields["hide"]);
// Bugfix: We had an error in the storing of keywords which lead to the "0" // Bugfix: We had an error in the storing of keywords which lead to the "0"
// This value is still transmitted via poco. // This value is still transmitted via poco.
@ -1549,6 +1559,11 @@ function update_gcontact($contact) {
if (!isset($contact[$field]) OR ($contact[$field] == "")) if (!isset($contact[$field]) OR ($contact[$field] == ""))
$contact[$field] = $r[0][$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) if ($contact["network"] == NETWORK_STATUSNET)
$contact["network"] = NETWORK_OSTATUS; $contact["network"] = NETWORK_OSTATUS;
@ -1657,6 +1672,44 @@ function update_gcontact_from_probe($url) {
update_gcontact($data); 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);
update_gcontact($gcontact);
}
/** /**
* @brief Fetches users of given GNU Social server * @brief Fetches users of given GNU Social server
* *

View file

@ -15,8 +15,12 @@ function noscrape_init(&$a) {
profile_load($a,$which,$profile); profile_load($a,$which,$profile);
if(!$a->profile['net-publish']) if (!$a->profile['net-publish'] OR $a->profile['hidewall']) {
killme(); header('Content-type: application/json; charset=utf-8');
$json_info = array("hide" => true);
echo json_encode($json_info);
exit;
}
$keywords = ((x($a->profile,'pub_keywords')) ? $a->profile['pub_keywords'] : ''); $keywords = ((x($a->profile,'pub_keywords')) ? $a->profile['pub_keywords'] : '');
$keywords = str_replace(array('#',',',' ',',,'),array('',' ',',',','),$keywords); $keywords = str_replace(array('#',',',' ',',,'),array('',' ',',',','),$keywords);

View file

@ -484,7 +484,7 @@ function profiles_post(&$a) {
if($is_default) { if($is_default) {
$location = formatted_location(array("locality" => $locality, "region" => $region, "country-name" => $country_name)); $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($about),
dbesc($location), dbesc($location),
dbesc($pub_keywords), dbesc($pub_keywords),
@ -499,6 +499,9 @@ function profiles_post(&$a) {
require_once('include/profile_update.php'); require_once('include/profile_update.php');
profile_change(); profile_change();
// Update the global contact for the user
update_gcontact_for_user(local_user());
} }
} }
} }

View file

@ -1,6 +1,7 @@
<?php <?php
require_once('include/group.php'); require_once('include/group.php');
require_once('include/socgraph.php');
function get_theme_config_file($theme){ function get_theme_config_file($theme){
$a = get_app(); $a = get_app();
@ -602,7 +603,7 @@ function settings_post(&$a) {
if($name_change) { if($name_change) {
q("UPDATE `contact` SET `name` = '%s', `name-date` = '%s' WHERE `uid` = %d AND `self` = 1", q("UPDATE `contact` SET `name` = '%s', `name-date` = '%s' WHERE `uid` = %d AND `self`",
dbesc($username), dbesc($username),
dbesc(datetime_convert()), dbesc(datetime_convert()),
intval(local_user()) intval(local_user())
@ -614,13 +615,14 @@ function settings_post(&$a) {
$url = $_SESSION['my_url']; $url = $_SESSION['my_url'];
if($url && strlen(get_config('system','directory'))) if($url && strlen(get_config('system','directory')))
proc_run('php',"include/directory.php","$url"); proc_run('php',"include/directory.php","$url");
} }
require_once('include/profile_update.php'); require_once('include/profile_update.php');
profile_change(); profile_change();
// Update the global contact for the user
update_gcontact_for_user(local_user());
//$_SESSION['theme'] = $theme; //$_SESSION['theme'] = $theme;
if($email_changed && $a->config['register_policy'] == REGISTER_VERIFY) { if($email_changed && $a->config['register_policy'] == REGISTER_VERIFY) {