X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;ds=sidebyside;f=include%2Fdfrn.php;h=a8f7644ff7dbf955b2c1b50237b1d8457bcaebcc;hb=1b5f1effa0ed7d7774f34ebb199fcbf9e6fd9f4b;hp=5977ed9a0c254c044516c70035bb1acf1b0a963a;hpb=0135b7e357064f5fc6e0983991e297b729b6f87a;p=friendica.git diff --git a/include/dfrn.php b/include/dfrn.php index 5977ed9a0c..a8f7644ff7 100644 --- a/include/dfrn.php +++ b/include/dfrn.php @@ -7,6 +7,8 @@ * https://github.com/friendica/friendica/blob/master/spec/dfrn2.pdf */ +use Friendica\App; + require_once("include/Contact.php"); require_once("include/ostatus.php"); require_once("include/enotify.php"); @@ -282,6 +284,62 @@ class dfrn { return $atom; } + /** + * @brief Generate an atom entry for a given item id + * + * @param int $item_id The item id + * + * @return string DFRN feed entry + */ + public static function itemFeed($item_id) { + $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` + 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`.`id` = %d AND `item`.`visible` AND NOT `item`.`moderated` AND `item`.`parent` != 0 + AND `item`.`wall` AND NOT `item`.`private`", + intval($item_id) + ); + + if (!dbm::is_result($r)) { + killme(); + } + + $item = $r[0]; + + $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`.`uid` = %d LIMIT 1", + intval($item['uid']) + ); + + if (!dbm::is_result($r)) { + killme(); + } + + $owner = $r[0]; + + $doc = new DOMDocument('1.0', 'utf-8'); + $doc->formatOutput = true; + + $alternatelink = $owner['url']; + + $root = self::add_header($doc, $owner, 'dfrn:owner', $alternatelink, true); + + $type = 'html'; + + $entry = self::entry($doc, $type, $item, $owner, true); + $root->appendChild($entry); + + $atom = trim($doc->saveXML()); + return $atom; + } + /** * @brief Create XML text for DFRN mails * @@ -370,7 +428,7 @@ class dfrn { $ext = Photo::supportedTypes(); foreach ($rp as $p) { - $photos[$p['scale']] = app::get_baseurl().'/photo/'.$p['resource-id'].'-'.$p['scale'].'.'.$ext[$p['type']]; + $photos[$p['scale']] = App::get_baseurl().'/photo/'.$p['resource-id'].'-'.$p['scale'].'.'.$ext[$p['type']]; } unset($rp, $ext); @@ -431,7 +489,7 @@ class dfrn { $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, "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); @@ -448,13 +506,13 @@ class dfrn { // 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"]); + $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"]); + $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"]); + $attributes = array("rel" => "http://salmon-protocol.org/ns/salmon-mention", "href" => App::get_baseurl()."/salmon/".$owner["nick"]); xml::add_element($doc, $root, "link", "", $attributes); } @@ -511,7 +569,7 @@ class dfrn { } 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, "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", @@ -812,7 +870,7 @@ class dfrn { $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'], + "href" => App::get_baseurl().'/display/'.$parent[0]['guid'], "dfrn:diaspora_guid" => $parent[0]['guid']); xml::add_element($doc, $entry, "thr:in-reply-to", "", $attributes); } @@ -854,7 +912,7 @@ class dfrn { // We save this value in "plink". Maybe we should read it from there as well? xml::add_element($doc, $entry, "link", "", array("rel" => "alternate", "type" => "text/html", - "href" => app::get_baseurl()."/display/".$item["guid"])); + "href" => App::get_baseurl()."/display/".$item["guid"])); // "comment-allow" is some old fashioned stuff for old Friendica versions. // It is included in the rewritten code for completeness