Merge pull request #2507 from annando/1605-hidewall
Better implementation of "hidewall" with feeds
This commit is contained in:
commit
0b4565a72c
2 changed files with 46 additions and 34 deletions
|
@ -68,10 +68,11 @@ class dfrn {
|
||||||
* @param string $owner_nick Owner nick name
|
* @param string $owner_nick Owner nick name
|
||||||
* @param string $last_update Date of the last update
|
* @param string $last_update Date of the last update
|
||||||
* @param int $direction Can be -1, 0 or 1.
|
* @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
|
* @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();
|
$a = get_app();
|
||||||
|
|
||||||
|
@ -234,7 +235,7 @@ class dfrn {
|
||||||
// This hook can't work anymore
|
// This hook can't work anymore
|
||||||
// call_hooks('atom_feed', $atom);
|
// call_hooks('atom_feed', $atom);
|
||||||
|
|
||||||
if(! count($items)) {
|
if (!count($items) OR $onlyheader) {
|
||||||
$atom = trim($doc->saveXML());
|
$atom = trim($doc->saveXML());
|
||||||
|
|
||||||
call_hooks('atom_feed_end', $atom);
|
call_hooks('atom_feed_end', $atom);
|
||||||
|
@ -462,45 +463,53 @@ class dfrn {
|
||||||
*/
|
*/
|
||||||
private function add_author($doc, $owner, $authorelement, $public) {
|
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);
|
$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);
|
$uridate = datetime_convert('UTC', 'UTC', $owner['uri-date'].'+00:00', ATOM_TIME);
|
||||||
$picdate = datetime_convert('UTC', 'UTC', $owner['avatar-date'].'+00:00', ATOM_TIME);
|
$picdate = datetime_convert('UTC', 'UTC', $owner['avatar-date'].'+00:00', ATOM_TIME);
|
||||||
|
|
||||||
|
if (!$public OR !$hidewall)
|
||||||
$attributes = array("dfrn:updated" => $namdate);
|
$attributes = array("dfrn:updated" => $namdate);
|
||||||
|
else
|
||||||
|
$attributes = array();
|
||||||
|
|
||||||
xml::add_element($doc, $author, "name", $owner["name"], $attributes);
|
xml::add_element($doc, $author, "name", $owner["name"], $attributes);
|
||||||
|
|
||||||
$attributes = array("dfrn:updated" => $namdate);
|
|
||||||
xml::add_element($doc, $author, "uri", app::get_baseurl().'/profile/'.$owner["nickname"], $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);
|
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']);
|
"media:width" => 175, "media:height" => 175, "href" => $owner['photo']);
|
||||||
|
|
||||||
|
if (!$public OR !$hidewall)
|
||||||
|
$attributes["dfrn:updated"] = $picdate;
|
||||||
|
|
||||||
xml::add_element($doc, $author, "link", "", $attributes);
|
xml::add_element($doc, $author, "link", "", $attributes);
|
||||||
|
|
||||||
$attributes = array("rel" => "avatar", "type" => "image/jpeg", "dfrn:updated" => $picdate,
|
$attributes["rel"] = "avatar";
|
||||||
"media:width" => 175, "media:height" => 175, "href" => $owner['photo']);
|
|
||||||
xml::add_element($doc, $author, "link", "", $attributes);
|
xml::add_element($doc, $author, "link", "", $attributes);
|
||||||
|
|
||||||
$birthday = feed_birthday($owner['uid'], $owner['timezone']);
|
if ($hidewall)
|
||||||
|
|
||||||
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");
|
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
|
// 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;
|
||||||
|
|
||||||
|
$birthday = feed_birthday($owner['uid'], $owner['timezone']);
|
||||||
|
|
||||||
|
if ($birthday)
|
||||||
|
xml::add_element($doc, $author, "dfrn:birthday", $birthday);
|
||||||
|
|
||||||
// Only show contact details when we are allowed to
|
// Only show contact details when we are allowed to
|
||||||
$r = q("SELECT `profile`.`about`, `profile`.`name`, `profile`.`homepage`, `user`.`nickname`, `user`.`timezone`,
|
$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`
|
`profile`.`locality`, `profile`.`region`, `profile`.`country-name`, `profile`.`pub_keywords`, `profile`.`dob`
|
||||||
|
|
|
@ -25,6 +25,8 @@ function dfrn_poll_init(&$a) {
|
||||||
$dfrn_id = substr($dfrn_id,2);
|
$dfrn_id = substr($dfrn_id,2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$hidewall = false;
|
||||||
|
|
||||||
if(($dfrn_id === '') && (! x($_POST,'dfrn_id'))) {
|
if(($dfrn_id === '') && (! x($_POST,'dfrn_id'))) {
|
||||||
if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
|
if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
|
||||||
http_status_exit(403);
|
http_status_exit(403);
|
||||||
|
@ -37,14 +39,15 @@ function dfrn_poll_init(&$a) {
|
||||||
);
|
);
|
||||||
if (!$r)
|
if (!$r)
|
||||||
http_status_exit(404);
|
http_status_exit(404);
|
||||||
if(($r[0]['hidewall']) && (! local_user()))
|
|
||||||
http_status_exit(403);
|
$hidewall = ($r[0]['hidewall'] && !local_user());
|
||||||
|
|
||||||
$user = $r[0]['nickname'];
|
$user = $r[0]['nickname'];
|
||||||
}
|
}
|
||||||
|
|
||||||
logger('dfrn_poll: public feed request from ' . $_SERVER['REMOTE_ADDR'] . ' for ' . $user);
|
logger('dfrn_poll: public feed request from ' . $_SERVER['REMOTE_ADDR'] . ' for ' . $user);
|
||||||
header("Content-type: application/atom+xml");
|
header("Content-type: application/atom+xml");
|
||||||
echo dfrn::feed('', $user,$last_update);
|
echo dfrn::feed('', $user,$last_update, 0, $hidewall);
|
||||||
killme();
|
killme();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue