Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there) https://friendi.ca
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
friendica/include/dfrn.php

2550 lines
86 KiB

<?php
/**
* @file include/dfrn.php
* @brief The implementation of the dfrn protocol
*
* @see https://github.com/friendica/friendica/wiki/Protocol and
* https://github.com/friendica/friendica/blob/master/spec/dfrn2.pdf
*/
require_once("include/Contact.php");
require_once("include/ostatus.php");
require_once("include/enotify.php");
require_once("include/threads.php");
require_once("include/socgraph.php");
require_once("include/items.php");
require_once("include/tags.php");
require_once("include/files.php");
require_once("include/event.php");
require_once("include/text.php");
require_once("include/oembed.php");
require_once("include/html2bbcode.php");
require_once("include/bbcode.php");
require_once("include/xml.php");
/**
* @brief This class contain functions to create and send DFRN XML files
*
*/
class dfrn {
const DFRN_TOP_LEVEL = 0; // Top level posting
const DFRN_REPLY = 1; // Regular reply that is stored locally
const DFRN_REPLY_RC = 2; // Reply that will be relayed
/**
* @brief Generates the atom entries for delivery.php
*
* This function is used whenever content is transmitted via DFRN.
*
* @param array $items Item elements
* @param array $owner Owner record
*
* @return string DFRN entries
*/
public static function entries($items,$owner) {
$doc = new DOMDocument('1.0', 'utf-8');
$doc->formatOutput = true;
$root = self::add_header($doc, $owner, "dfrn:owner", "", false);
if(! count($items))
return trim($doc->saveXML());
foreach($items as $item) {
$entry = self::entry($doc, "text", $item, $owner, $item["entry:comment-allow"], $item["entry:cid"]);
$root->appendChild($entry);
}
return(trim($doc->saveXML()));
}
/**
* @brief Generate an atom feed for the given user
*
* This function is called when another server is pulling data from the user feed.
*
* @param string $dfrn_id DFRN ID from the requesting party
* @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, $onlyheader = false) {
$a = get_app();
$sitefeed = ((strlen($owner_nick)) ? false : true); // not yet implemented, need to rewrite huge chunks of following logic
$public_feed = (($dfrn_id) ? false : true);
$starred = false; // not yet implemented, possible security issues
$converse = false;
if($public_feed && $a->argc > 2) {
for($x = 2; $x < $a->argc; $x++) {
if($a->argv[$x] == 'converse')
$converse = true;
if($a->argv[$x] == 'starred')
$starred = true;
if($a->argv[$x] == 'category' && $a->argc > ($x + 1) && strlen($a->argv[$x+1]))
$category = $a->argv[$x+1];
}
}
// default permissions - anonymous user
$sql_extra = " AND `item`.`allow_cid` = '' AND `item`.`allow_gid` = '' AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = '' ";
$r = q("SELECT `contact`.*, `user`.`nickname`, `user`.`timezone`, `user`.`page-flags`, `user`.`account-type`
FROM `contact` INNER JOIN `user` ON `user`.`uid` = `contact`.`uid`
WHERE `contact`.`self` AND `user`.`nickname` = '%s' LIMIT 1",
dbesc($owner_nick)
);
if(! dbm::is_result($r))
killme();
$owner = $r[0];
$owner_id = $owner['uid'];
$owner_nick = $owner['nickname'];
$sql_post_table = "";
if(! $public_feed) {
$sql_extra = '';
switch($direction) {
case (-1):
$sql_extra = sprintf(" AND `issued-id` = '%s' ", dbesc($dfrn_id));
$my_id = $dfrn_id;
break;
case 0:
$sql_extra = sprintf(" AND `issued-id` = '%s' AND `duplex` = 1 ", dbesc($dfrn_id));
$my_id = '1:' . $dfrn_id;
break;
case 1:
$sql_extra = sprintf(" AND `dfrn-id` = '%s' AND `duplex` = 1 ", dbesc($dfrn_id));
$my_id = '0:' . $dfrn_id;
break;
default:
return false;
break; // NOTREACHED
}
$r = q("SELECT * FROM `contact` WHERE NOT `blocked` AND `contact`.`uid` = %d $sql_extra LIMIT 1",
intval($owner_id)
);
if(! dbm::is_result($r))
killme();
$contact = $r[0];
require_once('include/security.php');
$groups = init_groups_visitor($contact['id']);
if(count($groups)) {
for($x = 0; $x < count($groups); $x ++)
$groups[$x] = '<' . intval($groups[$x]) . '>' ;
$gs = implode('|', $groups);
} else
$gs = '<<>>' ; // Impossible to match
$sql_extra = sprintf("
AND ( `allow_cid` = '' OR `allow_cid` REGEXP '<%d>' )
AND ( `deny_cid` = '' OR NOT `deny_cid` REGEXP '<%d>' )
AND ( `allow_gid` = '' OR `allow_gid` REGEXP '%s' )
AND ( `deny_gid` = '' OR NOT `deny_gid` REGEXP '%s')
",
intval($contact['id']),
intval($contact['id']),
dbesc($gs),
dbesc($gs)
);
}
if($public_feed)
$sort = 'DESC';
else
$sort = 'ASC';
if(! strlen($last_update))
$last_update = 'now -30 days';
if(isset($category)) {
$sql_post_table = sprintf("INNER JOIN (SELECT `oid` FROM `term` WHERE `term` = '%s' AND `otype` = %d AND `type` = %d AND `uid` = %d ORDER BY `tid` DESC) AS `term` ON `item`.`id` = `term`.`oid` ",
dbesc(protect_sprintf($category)), intval(TERM_OBJ_POST), intval(TERM_CATEGORY), intval($owner_id));
//$sql_extra .= file_tag_file_query('item',$category,'category');
}
if($public_feed) {
if(! $converse)
$sql_extra .= " AND `contact`.`self` = 1 ";
}
$check_date = datetime_convert('UTC','UTC',$last_update,'Y-m-d H:i:s');
$r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
`contact`.`name`, `contact`.`network`, `contact`.`photo`, `contact`.`url`,
`contact`.`name-date`, `contact`.`uri-date`, `contact`.`avatar-date`,
`contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
`sign`.`signed_text`, `sign`.`signature`, `sign`.`signer`
FROM `item` USE INDEX (`uid_wall_changed`, `uid_type_changed`) $sql_post_table
STRAIGHT_JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
AND (NOT `contact`.`blocked` OR `contact`.`pending`)
LEFT JOIN `sign` ON `sign`.`iid` = `item`.`id`
WHERE `item`.`uid` = %d AND `item`.`visible` AND NOT `item`.`moderated` AND `item`.`parent` != 0
AND `item`.`wall` AND `item`.`changed` > '%s'
$sql_extra
ORDER BY `item`.`parent` ".$sort.", `item`.`created` ASC LIMIT 0, 300",
intval($owner_id),
dbesc($check_date),
dbesc($sort)
);
// Will check further below if this actually returned results.
// We will provide an empty feed if that is the case.
$items = $r;
$doc = new DOMDocument('1.0', 'utf-8');
$doc->formatOutput = true;
$alternatelink = $owner['url'];
if(isset($category))
$alternatelink .= "/category/".$category;
if ($public_feed)
$author = "dfrn:owner";
else
$author = "author";
$root = self::add_header($doc, $owner, $author, $alternatelink, true);
// This hook can't work anymore
// call_hooks('atom_feed', $atom);
if (!count($items) OR $onlyheader) {
$atom = trim($doc->saveXML());
call_hooks('atom_feed_end', $atom);
return $atom;
}
foreach($items as $item) {
// prevent private email from leaking.
if($item['network'] == NETWORK_MAIL)
continue;
// public feeds get html, our own nodes use bbcode
if($public_feed) {
$type = 'html';
// catch any email that's in a public conversation and make sure it doesn't leak
if($item['private'])
continue;
} else
$type = 'text';
$entry = self::entry($doc, $type, $item, $owner, true);
$root->appendChild($entry);
}
$atom = trim($doc->saveXML());
call_hooks('atom_feed_end', $atom);
return $atom;
}
/**
* @brief Create XML text for DFRN mails
*
* @param array $item message elements
* @param array $owner Owner record
*
* @return string DFRN mail
*/
public static function mail($item, $owner) {
$doc = new DOMDocument('1.0', 'utf-8');
$doc->formatOutput = true;
$root = self::add_header($doc, $owner, "dfrn:owner", "", false);
$mail = $doc->createElement("dfrn:mail");
$sender = $doc->createElement("dfrn:sender");
xml::add_element($doc, $sender, "dfrn:name", $owner['name']);
xml::add_element($doc, $sender, "dfrn:uri", $owner['url']);
xml::add_element($doc, $sender, "dfrn:avatar", $owner['thumb']);
$mail->appendChild($sender);
xml::add_element($doc, $mail, "dfrn:id", $item['uri']);
xml::add_element($doc, $mail, "dfrn:in-reply-to", $item['parent-uri']);
xml::add_element($doc, $mail, "dfrn:sentdate", datetime_convert('UTC', 'UTC', $item['created'] . '+00:00' , ATOM_TIME));
xml::add_element($doc, $mail, "dfrn:subject", $item['title']);
xml::add_element($doc, $mail, "dfrn:content", $item['body']);
$root->appendChild($mail);
return(trim($doc->saveXML()));
}
/**
* @brief Create XML text for DFRN friend suggestions
*
* @param array $item suggestion elements
* @param array $owner Owner record
*
* @return string DFRN suggestions
*/
public static function fsuggest($item, $owner) {
$doc = new DOMDocument('1.0', 'utf-8');
$doc->formatOutput = true;
$root = self::add_header($doc, $owner, "dfrn:owner", "", false);
$suggest = $doc->createElement("dfrn:suggest");
xml::add_element($doc, $suggest, "dfrn:url", $item['url']);
xml::add_element($doc, $suggest, "dfrn:name", $item['name']);
xml::add_element($doc, $suggest, "dfrn:photo", $item['photo']);
xml::add_element($doc, $suggest, "dfrn:request", $item['request']);
xml::add_element($doc, $suggest, "dfrn:note", $item['note']);
$root->appendChild($suggest);
return(trim($doc->saveXML()));
}
/**
* @brief Create XML text for DFRN relocations
*
* @param array $owner Owner record
* @param int $uid User ID
*
* @return string DFRN relocations
*/
public static function relocate($owner, $uid) {
/* get site pubkey. this could be a new installation with no site keys*/
$pubkey = get_config('system','site_pubkey');
if(! $pubkey) {
$res = new_keypair(1024);
set_config('system','site_prvkey', $res['prvkey']);
set_config('system','site_pubkey', $res['pubkey']);
}
$rp = q("SELECT `resource-id` , `scale`, type FROM `photo`
WHERE `profile` = 1 AND `uid` = %d ORDER BY scale;", $uid);
$photos = array();
$ext = Photo::supportedTypes();
foreach($rp as $p)
$photos[$p['scale']] = app::get_baseurl().'/photo/'.$p['resource-id'].'-'.$p['scale'].'.'.$ext[$p['type']];
unset($rp, $ext);
$doc = new DOMDocument('1.0', 'utf-8');
$doc->formatOutput = true;
$root = self::add_header($doc, $owner, "dfrn:owner", "", false);
$relocate = $doc->createElement("dfrn:relocate");
xml::add_element($doc, $relocate, "dfrn:url", $owner['url']);
xml::add_element($doc, $relocate, "dfrn:name", $owner['name']);
xml::add_element($doc, $relocate, "dfrn:addr", $owner['addr']);
xml::add_element($doc, $relocate, "dfrn:avatar", $owner['avatar']);
xml::add_element($doc, $relocate, "dfrn:photo", $photos[4]);
xml::add_element($doc, $relocate, "dfrn:thumb", $photos[5]);
xml::add_element($doc, $relocate, "dfrn:micro", $photos[6]);
xml::add_element($doc, $relocate, "dfrn:request", $owner['request']);
xml::add_element($doc, $relocate, "dfrn:confirm", $owner['confirm']);
xml::add_element($doc, $relocate, "dfrn:notify", $owner['notify']);
xml::add_element($doc, $relocate, "dfrn:poll", $owner['poll']);
xml::add_element($doc, $relocate, "dfrn:sitepubkey", get_config('system','site_pubkey'));
$root->appendChild($relocate);
return(trim($doc->saveXML()));
}
/**
* @brief Adds the header elements for the DFRN protocol
*
* @param object $doc XML document
* @param array $owner Owner record
* @param string $authorelement Element name for the author
* @param string $alternatelink link to profile or category
* @param bool $public Is it a header for public posts?
*
* @return object XML root object
*/
private function add_header($doc, $owner, $authorelement, $alternatelink = "", $public = false) {
if ($alternatelink == "")
$alternatelink = $owner['url'];
$root = $doc->createElementNS(NAMESPACE_ATOM1, 'feed');
$doc->appendChild($root);
$root->setAttribute("xmlns:thr", NAMESPACE_THREAD);
$root->setAttribute("xmlns:at", NAMESPACE_TOMB);
$root->setAttribute("xmlns:media", NAMESPACE_MEDIA);
$root->setAttribute("xmlns:dfrn", NAMESPACE_DFRN);
$root->setAttribute("xmlns:activity", NAMESPACE_ACTIVITY);
$root->setAttribute("xmlns:georss", NAMESPACE_GEORSS);
$root->setAttribute("xmlns:poco", NAMESPACE_POCO);
$root->setAttribute("xmlns:ostatus", NAMESPACE_OSTATUS);
$root->setAttribute("xmlns:statusnet", NAMESPACE_STATUSNET);
xml::add_element($doc, $root, "id", app::get_baseurl()."/profile/".$owner["nick"]);
xml::add_element($doc, $root, "title", $owner["name"]);
$attributes = array("uri" => "https://friendi.ca", "version" => FRIENDICA_VERSION."-".DB_UPDATE_VERSION);
xml::add_element($doc, $root, "generator", FRIENDICA_PLATFORM, $attributes);
$attributes = array("rel" => "license", "href" => "http://creativecommons.org/licenses/by/3.0/");
xml::add_element($doc, $root, "link", "", $attributes);
$attributes = array("rel" => "alternate", "type" => "text/html", "href" => $alternatelink);
xml::add_element($doc, $root, "link", "", $attributes);
if ($public) {
// DFRN itself doesn't uses this. But maybe someone else wants to subscribe to the public feed.
ostatus::hublinks($doc, $root);
$attributes = array("rel" => "salmon", "href" => app::get_baseurl()."/salmon/".$owner["nick"]);
xml::add_element($doc, $root, "link", "", $attributes);
$attributes = array("rel" => "http://salmon-protocol.org/ns/salmon-replies", "href" => app::get_baseurl()."/salmon/".$owner["nick"]);
xml::add_element($doc, $root, "link", "", $attributes);
$attributes = array("rel" => "http://salmon-protocol.org/ns/salmon-mention", "href" => app::get_baseurl()."/salmon/".$owner["nick"]);
xml::add_element($doc, $root, "link", "", $attributes);
}
// For backward compatibility we keep this element
if ($owner['page-flags'] == PAGE_COMMUNITY)
xml::add_element($doc, $root, "dfrn:community", 1);
// The former element is replaced by this one
xml::add_element($doc, $root, "dfrn:account_type", $owner["account-type"]);
/// @todo We need a way to transmit the different page flags like "PAGE_PRVGROUP"
xml::add_element($doc, $root, "updated", datetime_convert("UTC", "UTC", "now", ATOM_TIME));
$author = self::add_author($doc, $owner, $authorelement, $public);
$root->appendChild($author);
return $root;
}
/**
* @brief Adds the author element in the header for the DFRN protocol
*
* @param object $doc XML document
* @param array $owner Owner record
* @param string $authorelement Element name for the author
*
* @return object XML author object
*/
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);
$uridate = datetime_convert('UTC', 'UTC', $owner['uri-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);
else
$attributes = array();
xml::add_element($doc, $author, "name", $owner["name"], $attributes);
xml::add_element($doc, $author, "uri", app::get_baseurl().'/profile/'.$owner["nickname"], $attributes);
xml::add_element($doc, $author, "dfrn:handle", $owner["addr"], $attributes);
$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["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);
// 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`.`xmpp`, `profile`.`dob`
FROM `profile`
INNER JOIN `user` ON `user`.`uid` = `profile`.`uid`
WHERE `profile`.`is-default` AND NOT `user`.`hidewall` AND `user`.`uid` = %d",
intval($owner['uid']));
if ($r) {
$profile = $r[0];
xml::add_element($doc, $author, "poco:displayName", $profile["name"]);
xml::add_element($doc, $author, "poco:updated", $namdate);
if (trim($profile["dob"]) != "0000-00-00")
xml::add_element($doc, $author, "poco:birthday", "0000-".date("m-d", strtotime($profile["dob"])));
xml::add_element($doc, $author, "poco:note", $profile["about"]);
xml::add_element($doc, $author, "poco:preferredUsername", $profile["nickname"]);
$savetz = date_default_timezone_get();
date_default_timezone_set($profile["timezone"]);
xml::add_element($doc, $author, "poco:utcOffset", date("P"));
date_default_timezone_set($savetz);
if (trim($profile["homepage"]) != "") {
$urls = $doc->createElement("poco:urls");
xml::add_element($doc, $urls, "poco:type", "homepage");
xml::add_element($doc, $urls, "poco:value", $profile["homepage"]);
xml::add_element($doc, $urls, "poco:primary", "true");
$author->appendChild($urls);
}
if (trim($profile["pub_keywords"]) != "") {
$keywords = explode(",", $profile["pub_keywords"]);
foreach ($keywords AS $keyword)
xml::add_element($doc, $author, "poco:tags", trim($keyword));
}
if (trim($profile["xmpp"]) != "") {
$ims = $doc->createElement("poco:ims");
xml::add_element($doc, $ims, "poco:type", "xmpp");
xml::add_element($doc, $ims, "poco:value", $profile["xmpp"]);
xml::add_element($doc, $ims, "poco:primary", "true");
$author->appendChild($ims);
}
if (trim($profile["locality"].$profile["region"].$profile["country-name"]) != "") {
$element = $doc->createElement("poco:address");
xml::add_element($doc, $element, "poco:formatted", formatted_location($profile));
if (trim($profile["locality"]) != "")
xml::add_element($doc, $element, "poco:locality", $profile["locality"]);
if (trim($profile["region"]) != "")
xml::add_element($doc, $element, "poco:region", $profile["region"]);
if (trim($profile["country-name"]) != "")
xml::add_element($doc, $element, "poco:country", $profile["country-name"]);
$author->appendChild($element);
}
}
return $author;
}
/**
* @brief Adds the author elements in the "entry" elements of the DFRN protocol
*
* @param object $doc XML document
* @param string $element Element name for the author
* @param string $contact_url Link of the contact
* @param array $items Item elements
*
* @return object XML author object
*/
private function add_entry_author($doc, $element, $contact_url, $item) {
$contact = get_contact_details_by_url($contact_url, $item["uid"]);
$author = $doc->createElement($element);
xml::add_element($doc, $author, "name", $contact["name"]);
xml::add_element($doc, $author, "uri", $contact["url"]);
xml::add_element($doc, $author, "dfrn:handle", $contact["addr"]);
/// @Todo
/// - Check real image type and image size
/// - Check which of these boths elements we should use
$attributes = array(
"rel" => "photo",
"type" => "image/jpeg",
"media:width" => 80,
"media:height" => 80,
"href" => $contact["photo"]);
xml::add_element($doc, $author, "link", "", $attributes);
$attributes = array(
"rel" => "avatar",
"type" => "image/jpeg",
"media:width" => 80,
"media:height" => 80,
"href" => $contact["photo"]);
xml::add_element($doc, $author, "link", "", $attributes);
return $author;
}
/**
* @brief Adds the activity elements
*
* @param object $doc XML document
* @param string $element Element name for the activity
* @param string $activity activity value
*
* @return object XML activity object
*/
private function create_activity($doc, $element, $activity) {
if($activity) {
$entry = $doc->createElement($element);
$r = parse_xml_string($activity, false);
if(!$r)
return false;
if($r->type)
xml::add_element($doc, $entry, "activity:object-type", $r->type);
if($r->id)
xml::add_element($doc, $entry, "id", $r->id);
if($r->title)
xml::add_element($doc, $entry, "title", $r->title);
if($r->link) {
if(substr($r->link,0,1) == '<') {
if(strstr($r->link,'&') && (! strstr($r->link,'&amp;')))
$r->link = str_replace('&','&amp;', $r->link);
$r->link = preg_replace('/\<link(.*?)\"\>/','<link$1"/>',$r->link);
// XML does need a single element as root element so we add a dummy element here
$data = parse_xml_string("<dummy>".$r->link."</dummy>", false);
if (is_object($data)) {
foreach ($data->link AS $link) {
$attributes = array();
foreach ($link->attributes() AS $parameter => $value)
$attributes[$parameter] = $value;
xml::add_element($doc, $entry, "link", "", $attributes);
}
}
} else {
$attributes = array("rel" => "alternate", "type" => "text/html", "href" => $r->link);
xml::add_element($doc, $entry, "link", "", $attributes);
}
}
if($r->content)
xml::add_element($doc, $entry, "content", bbcode($r->content), array("type" => "html"));
return $entry;
}
return false;
}
/**
* @brief Adds the elements for attachments
*
* @param object $doc XML document
* @param object $root XML root
* @param array $item Item element
*
* @return object XML attachment object
*/
private function get_attachment($doc, $root, $item) {
$arr = explode('[/attach],',$item['attach']);
if(count($arr)) {
foreach($arr as $r) {
$matches = false;
$cnt = preg_match('|\[attach\]href=\"(.*?)\" length=\"(.*?)\" type=\"(.*?)\" title=\"(.*?)\"|',$r,$matches);
if($cnt) {
$attributes = array("rel" => "enclosure",
"href" => $matches[1],
"type" => $matches[3]);
if(intval($matches[2]))
$attributes["length"] = intval($matches[2]);
if(trim($matches[4]) != "")
$attributes["title"] = trim($matches[4]);
xml::add_element($doc, $root, "link", "", $attributes);
}
}
}
}
/**
* @brief Adds the "entry" elements for the DFRN protocol
*
* @param object $doc XML document
* @param string $type "text" or "html"
* @param array $item Item element
* @param array $owner Owner record
* @param bool $comment Trigger the sending of the "comment" element
* @param int $cid Contact ID of the recipient
*
* @return object XML entry object
*/
private function entry($doc, $type, $item, $owner, $comment = false, $cid = 0) {
$mentioned = array();
if(!$item['parent'])
return;
if($item['deleted']) {
$attributes = array("ref" => $item['uri'], "when" => datetime_convert('UTC','UTC',$item['edited'] . '+00:00',ATOM_TIME));
return xml::create_element($doc, "at:deleted-entry", "", $attributes);
}
$entry = $doc->createElement("entry");
if($item['allow_cid'] || $item['allow_gid'] || $item['deny_cid'] || $item['deny_gid'])
$body = fix_private_photos($item['body'],$owner['uid'],$item,$cid);
else
$body = $item['body'];
// Remove the abstract element. It is only locally important.
$body = remove_abstract($body);
if ($type == 'html') {
$htmlbody = $body;
if ($item['title'] != "")
$htmlbody = "[b]".$item['title']."[/b]\n\n".$htmlbody;
$htmlbody = bbcode($htmlbody, false, false, 7);
}
$author = self::add_entry_author($doc, "author", $item["author-link"], $item);
$entry->appendChild($author);
$dfrnowner = self::add_entry_author($doc, "dfrn:owner", $item["owner-link"], $item);
$entry->appendChild($dfrnowner);
if(($item['parent'] != $item['id']) || ($item['parent-uri'] !== $item['uri']) || (($item['thr-parent'] !== '') && ($item['thr-parent'] !== $item['uri']))) {
$parent = q("SELECT `guid` FROM `item` WHERE `id` = %d", intval($item["parent"]));
$parent_item = (($item['thr-parent']) ? $item['thr-parent'] : $item['parent-uri']);
$attributes = array("ref" => $parent_item, "type" => "text/html",
"href" => app::get_baseurl().'/display/'.$parent[0]['guid'],
"dfrn:diaspora_guid" => $parent[0]['guid']);
xml::add_element($doc, $entry, "thr:in-reply-to", "", $attributes);
}
xml::add_element($doc, $entry, "id", $item["uri"]);
xml::add_element($doc, $entry, "title", $item["title"]);