]> git.mxchange.org Git - friendica.git/blobdiff - include/dfrn.php
Merge pull request #3626 from annando/issue-3616
[friendica.git] / include / dfrn.php
index 1b97f39a2d939b404c273eb6759f07ac4f84e552..78802563a625d6fcd6fdc0ef2ee4a46a6fcea05f 100644 (file)
@@ -284,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
         *
@@ -1902,7 +1958,7 @@ class dfrn {
                                return false;
                        }
 
-                       $r = q("UPDATE `item` SET `title` = '%s', `body` = '%s', `tag` = '%s', `edited` = '%s', `changed` = '%s' WHERE `uri` = '%s' AND `uid` = %d",
+                       $r = q("UPDATE `item` SET `title` = '%s', `body` = '%s', `tag` = '%s', `edited` = '%s', `changed` = '%s' WHERE `uri` = '%s' AND `uid` IN (0, %d)",
                                dbesc($item["title"]),
                                dbesc($item["body"]),
                                dbesc($item["tag"]),
@@ -1923,12 +1979,12 @@ class dfrn {
 
                // update last-child if it changes
                if ($item["last-child"] && ($item["last-child"] != $current["last-child"])) {
-                       $r = q("UPDATE `item` SET `last-child` = 0, `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
+                       $r = q("UPDATE `item` SET `last-child` = 0, `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` IN (0, %d)",
                                dbesc(datetime_convert()),
                                dbesc($item["parent-uri"]),
                                intval($importer["importer_uid"])
                        );
-                       $r = q("UPDATE `item` SET `last-child` = %d , `changed` = '%s' WHERE `uri` = '%s' AND `uid` = %d",
+                       $r = q("UPDATE `item` SET `last-child` = %d , `changed` = '%s' WHERE `uri` = '%s' AND `uid` IN (0, %d)",
                                intval($item["last-child"]),
                                dbesc(datetime_convert()),
                                dbesc($item["uri"]),
@@ -2688,7 +2744,7 @@ class dfrn {
                        if ($entrytype == DFRN_TOP_LEVEL) {
                                $r = q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s',
                                                `body` = '', `title` = ''
-                                       WHERE `parent-uri` = '%s' AND `uid` = %d",
+                                       WHERE `parent-uri` = '%s' AND `uid` IN (0, %d)",
                                                dbesc($when),
                                                dbesc(datetime_convert()),
                                                dbesc($uri),
@@ -2700,7 +2756,7 @@ class dfrn {
                        } else {
                                $r = q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s',
                                                `body` = '', `title` = ''
-                                       WHERE `uri` = '%s' AND `uid` = %d",
+                                       WHERE `uri` = '%s' AND `uid` IN (0, %d)",
                                                dbesc($when),
                                                dbesc(datetime_convert()),
                                                dbesc($uri),
@@ -2711,7 +2767,7 @@ class dfrn {
                                update_thread_uri($uri, $importer["importer_uid"]);
                                if ($item["last-child"]) {
                                        // ensure that last-child is set in case the comment that had it just got wiped.
-                                       q("UPDATE `item` SET `last-child` = 0, `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d ",
+                                       q("UPDATE `item` SET `last-child` = 0, `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` IN (0, %d)",
                                                dbesc(datetime_convert()),
                                                dbesc($item["parent-uri"]),
                                                intval($item["uid"])