]> git.mxchange.org Git - friendica.git/commitdiff
Salmons with Mastodon seem to work now
authorMichael <heluecht@pirati.ca>
Thu, 27 Apr 2017 20:38:46 +0000 (20:38 +0000)
committerMichael <heluecht@pirati.ca>
Thu, 27 Apr 2017 20:38:46 +0000 (20:38 +0000)
boot.php
database.sql
include/dba.php
include/dbstructure.php
include/dfrn.php
include/diaspora.php
include/items.php
include/ostatus.php

index 480001475b7b0b106a46da573601b705e39ec399..1851f845795bfc80938efd5d2b6ee97d6ec98be8 100644 (file)
--- a/boot.php
+++ b/boot.php
@@ -368,6 +368,7 @@ define ( 'NAMESPACE_FEED',            'http://schemas.google.com/g/2010#updates-
 define ( 'NAMESPACE_OSTATUS',         'http://ostatus.org/schema/1.0' );
 define ( 'NAMESPACE_STATUSNET',       'http://status.net/schema/api/1/' );
 define ( 'NAMESPACE_ATOM1',           'http://www.w3.org/2005/Atom' );
+define ( 'NAMESPACE_MASTODON',        'http://mastodon.social/schema/1.0' );
 /* @}*/
 
 /**
index e9a4ee2e4c2af206e22ed92a0ff786f6adcbc1fc..c8010e1e20f0e449a4deb61dbc2aea91f4ee5a5f 100644 (file)
@@ -211,8 +211,10 @@ CREATE TABLE IF NOT EXISTS `conversation` (
        `item-uri` varbinary(255) NOT NULL,
        `reply-to-uri` varbinary(255) NOT NULL DEFAULT '',
        `conversation-uri` varbinary(255) NOT NULL DEFAULT '',
+       `conversation-href` varbinary(255) NOT NULL DEFAULT '',
        `protocol` tinyint(1) unsigned NOT NULL DEFAULT 0,
        `source` mediumtext,
+       `received` datetime NOT NULL DEFAULT '0001-01-01 00:00:00',
         PRIMARY KEY(`item-uri`),
         INDEX `conversation-uri` (`conversation-uri`)
 ) DEFAULT COLLATE utf8mb4_general_ci;
index 5846d49484d54a9c228e448354a6e0ddd1cf2bd1..7e9979cf9ece0957a80b393cf4711ab2e9e9d2ff 100644 (file)
@@ -634,7 +634,29 @@ class dba {
                if (is_bool($stmt)) {
                        $retval = $stmt;
                } else {
-                       $retval = (self::rows($stmt) > 0);
+                       $retval = (self::num_rows($stmt) > 0);
+               }
+
+               self::close($stmt);
+
+               return $retval;
+       }
+
+       /**
+        * @brief Fetches the first row
+        *
+        * @param string $sql SQL statement
+        * @return array first row of query
+        */
+       static public function fetch_first($sql) {
+               $args = func_get_args();
+
+               $stmt = call_user_func_array('self::p', $args);
+
+               if (is_bool($stmt)) {
+                       $retval = $stmt;
+               } else {
+                       $retval = self::fetch($stmt);
                }
 
                self::close($stmt);
index 5260a87a330f48c30efec0fb0d992409566565f9..156d3eb645cb1a50faeb9576a1a961a914547e47 100644 (file)
@@ -814,12 +814,13 @@ function db_definition() {
                                        "item-uri" => array("type" => "varbinary(255)", "not null" => "1", "primary" => "1"),
                                        "reply-to-uri" => array("type" => "varbinary(255)", "not null" => "1", "default" => ""),
                                        "conversation-uri" => array("type" => "varbinary(255)", "not null" => "1", "default" => ""),
+                                       "conversation-href" => array("type" => "varbinary(255)", "not null" => "1", "default" => ""),
                                        "protocol" => array("type" => "tinyint(1) unsigned", "not null" => "1", "default" => "0"),
                                        "source" => array("type" => "mediumtext"),
                                        "received" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
                                        ),
                        "indexes" => array(
-                                       "PRIMARY" => array("item-uri"),
+                                       "PRIMARY" => array("item-uri", "protocol"),
                                        "conversation-uri" => array("conversation-uri"),
                                        )
                        );
index ddebf1e9bf60210d575a337a7e38f976b8472340..5977ed9a0c254c044516c70035bb1acf1b0a963a 100644 (file)
@@ -817,6 +817,28 @@ class dfrn {
                        xml::add_element($doc, $entry, "thr:in-reply-to", "", $attributes);
                }
 
+               // Add conversation data. This is used for OStatus
+               $conversation_href = App::get_baseurl()."/display/".$owner["nick"]."/".$item["parent"];
+               $conversation_uri = $conversation_href;
+
+               if (isset($parent_item)) {
+                       $r = dba::fetch_first("SELECT `conversation-uri`, `conversation-href` FROM `conversation` WHERE `item-uri` = ?", $item['parent-uri']);
+                       if (dbm::is_result($r)) {
+                               if ($r['conversation-uri'] != '') {
+                                       $conversation_uri = $r['conversation-uri'];
+                               }
+                               if ($r['conversation-href'] != '') {
+                                       $conversation_href = $r['conversation-href'];
+                               }
+                       }
+               }
+
+               $attributes = array(
+                               "href" => $conversation_href,
+                               "ref" => $conversation_uri);
+
+               xml::add_element($doc, $entry, "ostatus:conversation", $conversation_uri, $attributes);
+
                xml::add_element($doc, $entry, "id", $item["uri"]);
                xml::add_element($doc, $entry, "title", $item["title"]);
 
@@ -2209,12 +2231,16 @@ class dfrn {
         * @param array $importer Record of the importer user mixed with contact of the content
         * @todo Add type-hints
         */
-       private static function process_entry($header, $xpath, $entry, $importer) {
+       private static function process_entry($header, $xpath, $entry, $importer, $xml) {
 
                logger("Processing entries");
 
                $item = $header;
 
+               $item["protocol"] = PROTOCOL_DFRN;
+
+               $item["source"] = $xml;
+
                // Get the uri
                $item["uri"] = $xpath->query("atom:id/text()", $entry)->item(0)->nodeValue;
 
@@ -2373,6 +2399,20 @@ class dfrn {
                        self::parse_links($links, $item);
                }
 
+               $item['conversation-uri'] = $xpath->query('ostatus:conversation/text()', $entry)->item(0)->nodeValue;
+
+               $conv = $xpath->query('ostatus:conversation', $entry);
+               if (is_object($conv->item(0))) {
+                       foreach ($conv->item(0)->attributes AS $attributes) {
+                               if ($attributes->name == "ref") {
+                                       $item['conversation-uri'] = $attributes->textContent;
+                               }
+                               if ($attributes->name == "href") {
+                                       $item['conversation-href'] = $attributes->textContent;
+                               }
+                       }
+               }
+
                // Is it a reply or a top level posting?
                $item["parent-uri"] = $item["uri"];
 
@@ -2801,7 +2841,7 @@ class dfrn {
                if (!$sort_by_date) {
                        $entries = $xpath->query("/atom:feed/atom:entry");
                        foreach ($entries AS $entry) {
-                               self::process_entry($header, $xpath, $entry, $importer);
+                               self::process_entry($header, $xpath, $entry, $importer, $xml);
                        }
                } else {
                        $newentries = array();
@@ -2815,7 +2855,7 @@ class dfrn {
                        ksort($newentries);
 
                        foreach ($newentries AS $entry) {
-                               self::process_entry($header, $xpath, $entry, $importer);
+                               self::process_entry($header, $xpath, $entry, $importer, $xml);
                        }
                }
                logger("Import done for user " . $importer["uid"] . " from contact " . $importer["id"], LOGGER_DEBUG);
index b8eff62b1130f2a25ecd1503d043d130240b8704..b926f21da934ef63ffbf9d4a3ff3fa183f248e80 100644 (file)
@@ -1308,7 +1308,9 @@ class Diaspora {
                }
 
                $datarray["object-type"] = ACTIVITY_OBJ_COMMENT;
-               $datarray["object"] = $xml;
+
+               $datarray["protocol"] = PROTOCOL_DIASPORA;
+               $datarray["source"] = $xml;
 
                $datarray["changed"] = $datarray["created"] = $datarray["edited"] = $created_at;
 
@@ -2278,7 +2280,8 @@ class Diaspora {
                $datarray["verb"] = ACTIVITY_POST;
                $datarray["gravity"] = GRAVITY_PARENT;
 
-               $datarray["object"] = $xml;
+               $datarray["protocol"] = PROTOCOL_DIASPORA;
+               $datarray["source"] = $xml;
 
                $prefix = share_header($original_item["author-name"], $original_item["author-link"], $original_item["author-avatar"],
                                        $original_item["guid"], $original_item["created"], $orig_url);
@@ -2481,7 +2484,8 @@ class Diaspora {
                $datarray["verb"] = ACTIVITY_POST;
                $datarray["gravity"] = GRAVITY_PARENT;
 
-               $datarray["object"] = $xml;
+               $datarray["protocol"] = PROTOCOL_DIASPORA;
+               $datarray["source"] = $xml;
 
                $datarray["body"] = self::replace_people_guid($body, $contact["url"]);
 
index 3bf0a001c6a06d5a438df5de3e3f04a7b2a3ecb0..dcc99e8bd964878bc6e19e4a2c84e5e3160294ca 100644 (file)
@@ -693,39 +693,37 @@ function item_store($arr, $force_parent = false, $notify = false, $dontcache = f
 
        if (in_array($arr['network'], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS))) {
                $conversation = array('item-uri' => $arr['uri'], 'received' => dbm::date());
+
                if (isset($arr['thr-parent'])) {
                        if ($arr['thr-parent'] != $arr['uri']) {
                                $conversation['reply-to-uri'] = $arr['thr-parent'];
                        }
                }
+
                if (isset($arr['conversation-uri'])) {
                        $conversation['conversation-uri'] = $arr['conversation-uri'];
-                       unset($arr['conversation-uri']);
                }
 
-               if ($arr['network'] == NETWORK_DFRN) {
-                       $conversation['protocol'] = PROTOCOL_DFRN;
-               } elseif ($arr['network'] == NETWORK_DIASPORA) {
-                       $conversation['protocol'] = PROTOCOL_DIASPORA;
+               if (isset($arr['conversation-href'])) {
+                       $conversation['conversation-href'] = $arr['conversation-href'];
                }
 
                if (isset($arr['protocol'])) {
                        $conversation['protocol'] = $arr['protocol'];
-                       unset($arr['protocol']);
-               }
-               if (isset($arr['object'])) {
-                       $conversation['source'] = $arr['object'];
-                       if (in_array($arr['network'], array(NETWORK_DIASPORA, NETWORK_OSTATUS))) {
-                               unset($arr['object']);
-                       }
                }
+
                if (isset($arr['source'])) {
                        $conversation['source'] = $arr['source'];
-                       unset($arr['source']);
                }
+
                dba::insert('conversation', $conversation);
        }
 
+       unset($arr['conversation-uri']);
+       unset($arr['conversation-href']);
+       unset($arr['protocol']);
+       unset($arr['source']);
+
        if ($arr['parent-uri'] === $arr['uri']) {
                $parent_id = 0;
                $parent_deleted = 0;
index 54d67d66edaf432a239883336f24c6c51ac15e96..1800a9cc815fb8d18b7465c4197f09c3f7cf3aa8 100644 (file)
@@ -420,6 +420,19 @@ class ostatus {
                        $item["created"] = $xpath->query('atom:published/text()', $entry)->item(0)->nodeValue;
                        $item["edited"] = $xpath->query('atom:updated/text()', $entry)->item(0)->nodeValue;
                        $conversation = $xpath->query('ostatus:conversation/text()', $entry)->item(0)->nodeValue;
+                       $item['conversation-uri'] = $conversation;
+
+                       $conv = $xpath->query('ostatus:conversation', $entry);
+                       if (is_object($conv->item(0))) {
+                               foreach ($conv->item(0)->attributes AS $attributes) {
+                                       if ($attributes->name == "ref") {
+                                               $item['conversation-uri'] = $attributes->textContent;
+                                       }
+                                       if ($attributes->name == "href") {
+                                               $item['conversation-href'] = $attributes->textContent;
+                                       }
+                               }
+                       }
 
                        $related = "";
 
@@ -473,6 +486,10 @@ class ostatus {
                                                                break;
                                                        case "ostatus:conversation":
                                                                $conversation = $attribute['href'];
+                                                               $item['conversation-href'] = $conversation;
+                                                               if (!isset($item['conversation-uri'])) {
+                                                                       $item['conversation-uri'] = $item['conversation-href'];
+                                                               }
                                                                break;
                                                        case "enclosure":
                                                                $enclosure = $attribute['href'];
@@ -1162,6 +1179,10 @@ class ostatus {
                        $arr["author-avatar"] = $arr["owner-avatar"];
                        $arr["body"] = add_page_info_to_body(html2bbcode($single_conv->content));
 
+                       if (isset($single_conv->status_net->conversation)) {
+                               $arr['conversation-uri'] = $single_conv->status_net->conversation;
+                       }
+
                        if (isset($single_conv->status_net->notice_info->source))
                                $arr["app"] = strip_tags($single_conv->status_net->notice_info->source);
                        elseif (isset($single_conv->statusnet->notice_info->source))
@@ -1408,6 +1429,7 @@ class ostatus {
                $root->setAttribute("xmlns:poco", NAMESPACE_POCO);
                $root->setAttribute("xmlns:ostatus", NAMESPACE_OSTATUS);
                $root->setAttribute("xmlns:statusnet", NAMESPACE_STATUSNET);
+               $root->setAttribute("xmlns:mastodon", NAMESPACE_MASTODON);
 
                $attributes = array("uri" => "https://friendi.ca", "version" => FRIENDICA_VERSION."-".DB_UPDATE_VERSION);
                xml::add_element($doc, $root, "generator", FRIENDICA_PLATFORM, $attributes);
@@ -1546,14 +1568,16 @@ class ostatus {
         */
        private function add_author($doc, $owner) {
 
-               $r = q("SELECT `homepage` FROM `profile` WHERE `uid` = %d AND `is-default` LIMIT 1", intval($owner["uid"]));
+               $r = q("SELECT `homepage`, `publish` FROM `profile` WHERE `uid` = %d AND `is-default` LIMIT 1", intval($owner["uid"]));
                if ($r)
                        $profile = $r[0];
 
                $author = $doc->createElement("author");
+               xml::add_element($doc, $author, "id", $owner["url"]);
                xml::add_element($doc, $author, "activity:object-type", ACTIVITY_OBJ_PERSON);
                xml::add_element($doc, $author, "uri", $owner["url"]);
-               xml::add_element($doc, $author, "name", $owner["name"]);
+               xml::add_element($doc, $author, "name", $owner["nick"]);
+               xml::add_element($doc, $author, "email", $owner["addr"]);
                xml::add_element($doc, $author, "summary", bbcode($owner["about"], false, false, 7));
 
                $attributes = array("rel" => "alternate", "type" => "text/html", "href" => $owner["url"]);
@@ -1600,6 +1624,9 @@ class ostatus {
                        xml::add_element($doc, $author, "statusnet:profile_info", "", array("local_id" => $owner["uid"]));
                }
 
+               if ($profile["publish"]) {
+                       xml::add_element($doc, $author, "mastodon:scope", "public");
+               }
                return $author;
        }
 
@@ -1773,7 +1800,7 @@ class ostatus {
                self::entry_content($doc, $as_object, $repeated_item, $owner, "", "", false);
 
                $author = self::add_author($doc, $contact);
-                $as_object->appendChild($author);
+               $as_object->appendChild($author);
 
                $as_object2 = $doc->createElement("activity:object");
 
@@ -1995,6 +2022,7 @@ class ostatus {
                        $entry->setAttribute("xmlns:poco", NAMESPACE_POCO);
                        $entry->setAttribute("xmlns:ostatus", NAMESPACE_OSTATUS);
                        $entry->setAttribute("xmlns:statusnet", NAMESPACE_STATUSNET);
+                       $entry->setAttribute("xmlns:mastodon", NAMESPACE_MASTODON);
 
                        $author = self::add_author($doc, $owner);
                        $entry->appendChild($author);
@@ -2061,39 +2089,54 @@ class ostatus {
                        $parent = q("SELECT `guid`, `author-link`, `owner-link` FROM `item` WHERE `id` = %d", intval($item["parent"]));
                        $parent_item = (($item['thr-parent']) ? $item['thr-parent'] : $item['parent-uri']);
 
+                       $thrparent = q("SELECT `guid`, `author-link`, `owner-link`, `plink` FROM `item` WHERE `uid` = %d AND `uri` = '%s'",
+                                       intval($owner["uid"]),
+                                       dbesc($parent_item));
+                       if ($thrparent) {
+                               $mentioned[$thrparent[0]["author-link"]] = $thrparent[0]["author-link"];
+                               $mentioned[$thrparent[0]["owner-link"]] = $thrparent[0]["owner-link"];
+                               $parent_plink = $thrparent[0]["plink"];
+                       } else {
+                               $mentioned[$parent[0]["author-link"]] = $parent[0]["author-link"];
+                               $mentioned[$parent[0]["owner-link"]] = $parent[0]["owner-link"];
+                               $parent_plink = App::get_baseurl()."/display/".$parent[0]["guid"];
+                       }
+
                        $attributes = array(
                                        "ref" => $parent_item,
-                                       "type" => "text/html",
-                                       "href" => App::get_baseurl()."/display/".$parent[0]["guid"]);
+                                       "href" => $parent_plink);
                        xml::add_element($doc, $entry, "thr:in-reply-to", "", $attributes);
 
                        $attributes = array(
                                        "rel" => "related",
-                                       "href" => App::get_baseurl()."/display/".$parent[0]["guid"]);
+                                       "href" => $parent_plink);
                        xml::add_element($doc, $entry, "link", "", $attributes);
+               }
 
-                       $mentioned[$parent[0]["author-link"]] = $parent[0]["author-link"];
-                       $mentioned[$parent[0]["owner-link"]] = $parent[0]["owner-link"];
+               if (intval($item["parent"]) > 0) {
+                       $conversation_href = App::get_baseurl()."/display/".$owner["nick"]."/".$item["parent"];
+                       $conversation_uri = $conversation_href;
 
-                       $thrparent = q("SELECT `guid`, `author-link`, `owner-link` FROM `item` WHERE `uid` = %d AND `uri` = '%s'",
-                                       intval($owner["uid"]),
-                                       dbesc($parent_item));
-                       if ($thrparent) {
-                               $mentioned[$thrparent[0]["author-link"]] = $thrparent[0]["author-link"];
-                               $mentioned[$thrparent[0]["owner-link"]] = $thrparent[0]["owner-link"];
+                       if (isset($parent_item)) {
+                               $r = dba::fetch_first("SELECT `conversation-uri`, `conversation-href` FROM `conversation` WHERE `item-uri` = ?", $parent_item);
+                               if (dbm::is_result($r)) {
+                                       if ($r['conversation-uri'] != '') {
+                                               $conversation_uri = $r['conversation-uri'];
+                                       }
+                                       if ($r['conversation-href'] != '') {
+                                               $conversation_href = $r['conversation-href'];
+                                       }
+                               }
                        }
-               }
 
-               if (intval($item["parent"]) > 0) {
-                       $conversation = App::get_baseurl()."/display/".$owner["nick"]."/".$item["parent"];
-                       xml::add_element($doc, $entry, "link", "", array("rel" => "ostatus:conversation", "href" => $conversation));
+                       xml::add_element($doc, $entry, "link", "", array("rel" => "ostatus:conversation", "href" => $conversation_href));
 
                        $attributes = array(
-                                       "href" => $conversation,
+                                       "href" => $conversation_href,
                                        "local_id" => $item["parent"],
-                                       "ref" => $conversation);
+                                       "ref" => $conversation_uri);
 
-                       xml::add_element($doc, $entry, "ostatus:conversation", $conversation, $attributes);
+                       xml::add_element($doc, $entry, "ostatus:conversation", $conversation_uri, $attributes);
                }
 
                $tags = item_getfeedtags($item);
@@ -2131,6 +2174,7 @@ class ostatus {
                        xml::add_element($doc, $entry, "link", "", array("rel" => "mentioned",
                                                                        "ostatus:object-type" => "http://activitystrea.ms/schema/1.0/collection",
                                                                        "href" => "http://activityschema.org/collection/public"));
+                       xml::add_element($doc, $entry, "mastodon:scope", "public");
                }
 
                if(count($tags))