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
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

View File

@ -490,7 +490,14 @@ class dfrn {
if ($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)
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,16 @@ class dfrn {
/// - poco:region
/// - 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
$tags = array();
$tagelements = $xpath->evaluate($element."/poco:tags/text()", $context);
@ -1262,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;
}
@ -1280,13 +1297,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 +1316,7 @@ class dfrn {
$poco["generation"] = 2;
$poco["photo"] = $author["avatar"];
$poco["hide"] = $hide;
update_gcontact($poco);
}

View File

@ -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");

View File

@ -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);
}

View File

@ -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"]);
@ -1391,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;
}
/**
@ -1417,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"];
@ -1447,6 +1451,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 +1477,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 +1490,7 @@ function get_gcontact_id($contact) {
dbesc(datetime_convert()),
dbesc($contact["location"]),
dbesc($contact["about"]),
intval($contact["hide"]),
intval($contact["generation"])
);
@ -1535,6 +1544,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 +1559,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;
@ -1657,6 +1672,44 @@ 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);
update_gcontact($gcontact);
}
/**
* @brief Fetches users of given GNU Social server
*

View File

@ -15,8 +15,12 @@ function noscrape_init(&$a) {
profile_load($a,$which,$profile);
if(!$a->profile['net-publish'])
killme();
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);
exit;
}
$keywords = ((x($a->profile,'pub_keywords')) ? $a->profile['pub_keywords'] : '');
$keywords = str_replace(array('#',',',' ',',,'),array('',' ',',',','),$keywords);

View File

@ -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),
@ -499,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());
}
}
}

View File

@ -1,6 +1,7 @@
<?php
require_once('include/group.php');
require_once('include/socgraph.php');
function get_theme_config_file($theme){
$a = get_app();
@ -602,7 +603,7 @@ function settings_post(&$a) {
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(datetime_convert()),
intval(local_user())
@ -614,13 +615,14 @@ function settings_post(&$a) {
$url = $_SESSION['my_url'];
if($url && strlen(get_config('system','directory')))
proc_run('php',"include/directory.php","$url");
}
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) {
@ -629,7 +631,7 @@ function settings_post(&$a) {
}
goaway('settings' );
goaway('settings');
return; // NOTREACHED
}
@ -1279,7 +1281,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'),