X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;ds=sidebyside;f=include%2Fdfrn.php;h=a974056e655fe6906a722d12bd51c9187c32675e;hb=e2c0f04eeb0ca890465607d6d3305f08d2bfe862;hp=f6f43660296c39a555cfee7a7150fa37ea013eda;hpb=af37fa8293ea72e0f8b229f7fdad392b5e2fb912;p=friendica.git diff --git a/include/dfrn.php b/include/dfrn.php index f6f4366029..a974056e65 100644 --- a/include/dfrn.php +++ b/include/dfrn.php @@ -68,10 +68,11 @@ class dfrn { * @param string $owner_nick Owner nick name * @param string $last_update Date of the last update * @param int $direction Can be -1, 0 or 1. + * @param boolean $onlyheader Output only the header without content? (Default is "no") * * @return string DFRN feed entries */ - public static function feed($dfrn_id, $owner_nick, $last_update, $direction = 0) { + public static function feed($dfrn_id, $owner_nick, $last_update, $direction = 0, $onlyheader = false) { $a = get_app(); @@ -234,7 +235,7 @@ class dfrn { // This hook can't work anymore // call_hooks('atom_feed', $atom); - if(! count($items)) { + if (!count($items) OR $onlyheader) { $atom = trim($doc->saveXML()); call_hooks('atom_feed_end', $atom); @@ -462,38 +463,53 @@ class dfrn { */ private function add_author($doc, $owner, $authorelement, $public) { + // 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) + $hidewall = true; + else + $hidewall = false; + $author = $doc->createElement($authorelement); - $namdate = datetime_convert('UTC', 'UTC', $owner['name-date'].'+00:00' , ATOM_TIME); + $namdate = datetime_convert('UTC', 'UTC', $owner['name-date'].'+00:00', ATOM_TIME); $uridate = datetime_convert('UTC', 'UTC', $owner['uri-date'].'+00:00', ATOM_TIME); $picdate = datetime_convert('UTC', 'UTC', $owner['avatar-date'].'+00:00', ATOM_TIME); - $attributes = array("dfrn:updated" => $namdate); - xml::add_element($doc, $author, "name", $owner["name"], $attributes); + if (!$public OR !$hidewall) + $attributes = array("dfrn:updated" => $namdate); + else + $attributes = array(); - $attributes = array("dfrn:updated" => $namdate); + xml::add_element($doc, $author, "name", $owner["name"], $attributes); xml::add_element($doc, $author, "uri", app::get_baseurl().'/profile/'.$owner["nickname"], $attributes); - - $attributes = array("dfrn:updated" => $namdate); xml::add_element($doc, $author, "dfrn:handle", $owner["addr"], $attributes); - $attributes = array("rel" => "photo", "type" => "image/jpeg", "dfrn:updated" => $picdate, + $attributes = array("rel" => "photo", "type" => "image/jpeg", "media:width" => 175, "media:height" => 175, "href" => $owner['photo']); + + if (!$public OR !$hidewall) + $attributes["dfrn:updated"] = $picdate; + xml::add_element($doc, $author, "link", "", $attributes); - $attributes = array("rel" => "avatar", "type" => "image/jpeg", "dfrn:updated" => $picdate, - "media:width" => 175, "media:height" => 175, "href" => $owner['photo']); + $attributes["rel"] = "avatar"; xml::add_element($doc, $author, "link", "", $attributes); + if ($hidewall) + 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; + $birthday = feed_birthday($owner['uid'], $owner['timezone']); 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 - if ($public) - return $author; - // Only show contact details when we are allowed to $r = q("SELECT `profile`.`about`, `profile`.`name`, `profile`.`homepage`, `user`.`nickname`, `user`.`timezone`, `profile`.`locality`, `profile`.`region`, `profile`.`country-name`, `profile`.`pub_keywords`, `profile`.`dob` @@ -1126,7 +1142,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 +1226,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 +1288,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 +1306,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 +1325,7 @@ class dfrn { $poco["generation"] = 2; $poco["photo"] = $author["avatar"]; + $poco["hide"] = $hide; update_gcontact($poco); }