]> git.mxchange.org Git - friendica.git/commitdiff
We have an alternate link
authorMichael <heluecht@pirati.ca>
Tue, 6 Jun 2017 21:56:25 +0000 (21:56 +0000)
committerMichael <heluecht@pirati.ca>
Tue, 6 Jun 2017 21:56:25 +0000 (21:56 +0000)
include/dfrn.php
mod/display.php
view/templates/display-head.tpl

index 7e4d7af2bcceabe423bbe911fab8739b9eca6b2b..5d0e6337a42ff4e49f71c0f806fb089b156e7489 100644 (file)
@@ -284,6 +284,65 @@ 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'];
+
+               $author = "dfrn:owner";
+               //$author = "author";
+
+               $root = self::add_header($doc, $owner, $author, $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
         *
index bc0ba388bfa4dedfc2071015ca5b502ee0bff780..e31b89998cc6bd406b4f0825b735e493bea3f957 100644 (file)
@@ -11,6 +11,17 @@ function display_init(App $a) {
        $nick = (($a->argc > 1) ? $a->argv[1] : '');
        $profiledata = array();
 
+       if ($a->argc == 3) {
+               if (substr($a->argv[2], -5) == '.atom') {
+                       require_once('include/dfrn.php');
+                       $item_id = substr($a->argv[2], 0, -5);
+                       $xml = dfrn::itemFeed($item_id);
+                       header("Content-type: application/atom+xml");
+                       echo $xml;
+                       http_status_exit(($xml) ? 200 : 500);
+               }
+       }
+
        // If there is only one parameter, then check if this parameter could be a guid
        if ($a->argc == 2) {
                $nick = "";
@@ -278,11 +289,17 @@ function display_content(App $a, $update = 0) {
                return;
        }
 
-       $alternate = App::get_baseurl().'/display/'.$nick.'/'.$item_id.'.atom';
+       // We are displaying an "alternate" link if that post was public. See issue 2864
+       $items = q("SELECT `id` FROM `item` WHERE `id` = %d AND NOT `private` AND `wall`", intval($item_id));
+       if (dbm::is_result($items)) {
+               $alternate = App::get_baseurl().'/display/'.$nick.'/'.$item_id.'.atom';
+       } else {
+               $alternate = '';
+       }
+
        $a->page['htmlhead'] .= replace_macros(get_markup_template('display-head.tpl'),
                                array('$alternate' => $alternate));
 
-
        $groups = array();
 
        $contact = null;
index f4d050eec23e7933b6ffb9c68d85bdb068fb4910..dda816214624576873eadf3d00389cc0f9ffd579 100644 (file)
@@ -1,4 +1,4 @@
-<link href='{{$alternate}}' rel='alternate' type='application/atom+xml'>
+{{if $alternate}}<link href='{{$alternate}}' rel='alternate' type='application/atom+xml'>{{/if}}
 <script>
 $(document).ready(function() {
        $(".comment-edit-wrapper textarea").editor_autocomplete(baseurl+"/acl");