]> git.mxchange.org Git - friendica.git/blobdiff - src/Protocol/DFRN.php
"CheckServer" is now "UpdateGServer"
[friendica.git] / src / Protocol / DFRN.php
index 1e841f3047834758a21830e6bec7655e16393867..f7a8f693902e37591cc4b72b0f2c99440f4a1c19 100644 (file)
@@ -32,9 +32,10 @@ use Friendica\Model\Profile;
 use Friendica\Model\User;
 use Friendica\Network\Probe;
 use Friendica\Object\Image;
-use Friendica\Protocol\Activity\ANamespace;
+use Friendica\Protocol\ActivityNamespace;
 use Friendica\Util\Crypto;
 use Friendica\Util\DateTimeFormat;
+use Friendica\Util\Images;
 use Friendica\Util\Network;
 use Friendica\Util\Strings;
 use Friendica\Util\XML;
@@ -381,18 +382,18 @@ class DFRN
                $type = 'html';
 
                if ($conversation) {
-                       $root = $doc->createElementNS(ANamespace::ATOM1, 'feed');
+                       $root = $doc->createElementNS(ActivityNamespace::ATOM1, 'feed');
                        $doc->appendChild($root);
 
-                       $root->setAttribute("xmlns:thr", ANamespace::THREAD);
-                       $root->setAttribute("xmlns:at", ANamespace::TOMB);
-                       $root->setAttribute("xmlns:media", ANamespace::MEDIA);
-                       $root->setAttribute("xmlns:dfrn", ANamespace::DFRN);
-                       $root->setAttribute("xmlns:activity", ANamespace::ACTIVITY);
-                       $root->setAttribute("xmlns:georss", ANamespace::GEORSS);
-                       $root->setAttribute("xmlns:poco", ANamespace::POCO);
-                       $root->setAttribute("xmlns:ostatus", ANamespace::OSTATUS);
-                       $root->setAttribute("xmlns:statusnet", ANamespace::STATUSNET);
+                       $root->setAttribute("xmlns:thr", ActivityNamespace::THREAD);
+                       $root->setAttribute("xmlns:at", ActivityNamespace::TOMB);
+                       $root->setAttribute("xmlns:media", ActivityNamespace::MEDIA);
+                       $root->setAttribute("xmlns:dfrn", ActivityNamespace::DFRN);
+                       $root->setAttribute("xmlns:activity", ActivityNamespace::ACTIVITY);
+                       $root->setAttribute("xmlns:georss", ActivityNamespace::GEORSS);
+                       $root->setAttribute("xmlns:poco", ActivityNamespace::POCO);
+                       $root->setAttribute("xmlns:ostatus", ActivityNamespace::OSTATUS);
+                       $root->setAttribute("xmlns:statusnet", ActivityNamespace::STATUSNET);
 
                        //$root = self::addHeader($doc, $owner, "dfrn:owner", "", false);
 
@@ -504,7 +505,7 @@ class DFRN
                        $uid
                );
                $photos = [];
-               $ext = Image::supportedTypes();
+               $ext = Images::supportedTypes();
 
                foreach ($rp as $p) {
                        $photos[$p['scale']] = System::baseUrl().'/photo/'.$p['resource-id'].'-'.$p['scale'].'.'.$ext[$p['type']];
@@ -556,18 +557,18 @@ class DFRN
                        $alternatelink = $owner['url'];
                }
 
-               $root = $doc->createElementNS(ANamespace::ATOM1, 'feed');
+               $root = $doc->createElementNS(ActivityNamespace::ATOM1, 'feed');
                $doc->appendChild($root);
 
-               $root->setAttribute("xmlns:thr", ANamespace::THREAD);
-               $root->setAttribute("xmlns:at", ANamespace::TOMB);
-               $root->setAttribute("xmlns:media", ANamespace::MEDIA);
-               $root->setAttribute("xmlns:dfrn", ANamespace::DFRN);
-               $root->setAttribute("xmlns:activity", ANamespace::ACTIVITY);
-               $root->setAttribute("xmlns:georss", ANamespace::GEORSS);
-               $root->setAttribute("xmlns:poco", ANamespace::POCO);
-               $root->setAttribute("xmlns:ostatus", ANamespace::OSTATUS);
-               $root->setAttribute("xmlns:statusnet", ANamespace::STATUSNET);
+               $root->setAttribute("xmlns:thr", ActivityNamespace::THREAD);
+               $root->setAttribute("xmlns:at", ActivityNamespace::TOMB);
+               $root->setAttribute("xmlns:media", ActivityNamespace::MEDIA);
+               $root->setAttribute("xmlns:dfrn", ActivityNamespace::DFRN);
+               $root->setAttribute("xmlns:activity", ActivityNamespace::ACTIVITY);
+               $root->setAttribute("xmlns:georss", ActivityNamespace::GEORSS);
+               $root->setAttribute("xmlns:poco", ActivityNamespace::POCO);
+               $root->setAttribute("xmlns:ostatus", ActivityNamespace::OSTATUS);
+               $root->setAttribute("xmlns:statusnet", ActivityNamespace::STATUSNET);
 
                XML::addElement($doc, $root, "id", System::baseUrl()."/profile/".$owner["nick"]);
                XML::addElement($doc, $root, "title", $owner["name"]);
@@ -940,18 +941,18 @@ class DFRN
                if (!$single) {
                        $entry = $doc->createElement("entry");
                } else {
-                       $entry = $doc->createElementNS(ANamespace::ATOM1, 'entry');
+                       $entry = $doc->createElementNS(ActivityNamespace::ATOM1, 'entry');
                        $doc->appendChild($entry);
 
-                       $entry->setAttribute("xmlns:thr", ANamespace::THREAD);
-                       $entry->setAttribute("xmlns:at", ANamespace::TOMB);
-                       $entry->setAttribute("xmlns:media", ANamespace::MEDIA);
-                       $entry->setAttribute("xmlns:dfrn", ANamespace::DFRN);
-                       $entry->setAttribute("xmlns:activity", ANamespace::ACTIVITY);
-                       $entry->setAttribute("xmlns:georss", ANamespace::GEORSS);
-                       $entry->setAttribute("xmlns:poco", ANamespace::POCO);
-                       $entry->setAttribute("xmlns:ostatus", ANamespace::OSTATUS);
-                       $entry->setAttribute("xmlns:statusnet", ANamespace::STATUSNET);
+                       $entry->setAttribute("xmlns:thr", ActivityNamespace::THREAD);
+                       $entry->setAttribute("xmlns:at", ActivityNamespace::TOMB);
+                       $entry->setAttribute("xmlns:media", ActivityNamespace::MEDIA);
+                       $entry->setAttribute("xmlns:dfrn", ActivityNamespace::DFRN);
+                       $entry->setAttribute("xmlns:activity", ActivityNamespace::ACTIVITY);
+                       $entry->setAttribute("xmlns:georss", ActivityNamespace::GEORSS);
+                       $entry->setAttribute("xmlns:poco", ActivityNamespace::POCO);
+                       $entry->setAttribute("xmlns:ostatus", ActivityNamespace::OSTATUS);
+                       $entry->setAttribute("xmlns:statusnet", ActivityNamespace::STATUSNET);
                }
 
                if ($item['private']) {
@@ -1078,9 +1079,9 @@ class DFRN
                if ($item['object-type'] != "") {
                        XML::addElement($doc, $entry, "activity:object-type", $item['object-type']);
                } elseif ($item['id'] == $item['parent']) {
-                       XML::addElement($doc, $entry, "activity:object-type", Activity::OBJ_NOTE);
+                       XML::addElement($doc, $entry, "activity:object-type", Activity\ObjectType::NOTE);
                } else {
-                       XML::addElement($doc, $entry, "activity:object-type", Activity::OBJ_COMMENT);
+                       XML::addElement($doc, $entry, "activity:object-type", Activity\ObjectType::COMMENT);
                }
 
                $actobj = self::createActivity($doc, "activity:object", $item['object']);
@@ -1123,7 +1124,7 @@ class DFRN
                                        "link",
                                        "",
                                        ["rel" => "mentioned",
-                                                       "ostatus:object-type" => Activity::OBJ_GROUP,
+                                                       "ostatus:object-type" => Activity\ObjectType::GROUP,
                                                        "href" => $mention]
                                );
                        } else {
@@ -1133,7 +1134,7 @@ class DFRN
                                        "link",
                                        "",
                                        ["rel" => "mentioned",
-                                                       "ostatus:object-type" => Activity::OBJ_PERSON,
+                                                       "ostatus:object-type" => Activity\ObjectType::PERSON,
                                                        "href" => $mention]
                                );
                        }
@@ -1749,7 +1750,7 @@ class DFRN
                $obj_doc = new DOMDocument("1.0", "utf-8");
                $obj_doc->formatOutput = true;
 
-               $obj_element = $obj_doc->createElementNS( ANamespace::ATOM1, $element);
+               $obj_element = $obj_doc->createElementNS( ActivityNamespace::ATOM1, $element);
 
                $activity_type = $xpath->query("activity:object-type/text()", $activity)->item(0)->nodeValue;
                XML::addElement($obj_doc, $obj_element, "type", $activity_type);
@@ -2116,7 +2117,7 @@ class DFRN
                }
                $xo = XML::parseString($item["object"], false);
 
-               if (($xo->type == Activity::OBJ_PERSON) && ($xo->id)) {
+               if (($xo->type == Activity\ObjectType::PERSON) && ($xo->id)) {
                        // somebody was poked/prodded. Was it me?
                        $Blink = '';
                        foreach ($xo->link as $l) {
@@ -2237,11 +2238,11 @@ class DFRN
                                $is_like = false;
                        }
 
-                       if (($item["verb"] == Activity::TAG) && ($item["object-type"] == Activity::OBJ_TAGTERM)) {
+                       if (($item["verb"] == Activity::TAG) && ($item["object-type"] == Activity\ObjectType::TAGTERM)) {
                                $xo = XML::parseString($item["object"], false);
                                $xt = XML::parseString($item["target"], false);
 
-                               if ($xt->type == Activity::OBJ_NOTE) {
+                               if ($xt->type == Activity\ObjectType::NOTE) {
                                        $item_tag = Item::selectFirst(['id', 'tag'], ['uri' => $xt->id, 'uid' => $importer["importer_uid"]]);
 
                                        if (!DBA::isResult($item_tag)) {
@@ -2516,7 +2517,7 @@ class DFRN
                // Now assign the rest of the values that depend on the type of the message
                if (in_array($entrytype, [DFRN::REPLY, DFRN::REPLY_RC])) {
                        if (!isset($item["object-type"])) {
-                               $item["object-type"] = Activity::OBJ_COMMENT;
+                               $item["object-type"] = Activity\ObjectType::COMMENT;
                        }
 
                        if ($item["contact-id"] != $owner["contact-id"]) {
@@ -2536,15 +2537,18 @@ class DFRN
                        }
                }
 
+               // Ensure to have the correct share data
+               $item = Item::addShareDataFromOriginal($item);
+
                if ($entrytype == DFRN::REPLY_RC) {
                        $item["wall"] = 1;
                } elseif ($entrytype == DFRN::TOP_LEVEL) {
                        if (!isset($item["object-type"])) {
-                               $item["object-type"] = Activity::OBJ_NOTE;
+                               $item["object-type"] = Activity\ObjectType::NOTE;
                        }
 
                        // Is it an event?
-                       if (($item["object-type"] == Activity::OBJ_EVENT) && !$owner_unknown) {
+                       if (($item["object-type"] == Activity\ObjectType::EVENT) && !$owner_unknown) {
                                Logger::log("Item ".$item["uri"]." seems to contain an event.", Logger::DEBUG);
                                $ev = Event::fromBBCode($item["body"]);
                                if ((!empty($ev['desc']) || !empty($ev['summary'])) && !empty($ev['start'])) {
@@ -2730,16 +2734,16 @@ class DFRN
                @$doc->loadXML($xml);
 
                $xpath = new DOMXPath($doc);
-               $xpath->registerNamespace("atom", ANamespace::ATOM1);
-               $xpath->registerNamespace("thr", ANamespace::THREAD);
-               $xpath->registerNamespace("at", ANamespace::TOMB);
-               $xpath->registerNamespace("media", ANamespace::MEDIA);
-               $xpath->registerNamespace("dfrn", ANamespace::DFRN);
-               $xpath->registerNamespace("activity", ANamespace::ACTIVITY);
-               $xpath->registerNamespace("georss", ANamespace::GEORSS);
-               $xpath->registerNamespace("poco", ANamespace::POCO);
-               $xpath->registerNamespace("ostatus", ANamespace::OSTATUS);
-               $xpath->registerNamespace("statusnet", ANamespace::STATUSNET);
+               $xpath->registerNamespace("atom", ActivityNamespace::ATOM1);
+               $xpath->registerNamespace("thr", ActivityNamespace::THREAD);
+               $xpath->registerNamespace("at", ActivityNamespace::TOMB);
+               $xpath->registerNamespace("media", ActivityNamespace::MEDIA);
+               $xpath->registerNamespace("dfrn", ActivityNamespace::DFRN);
+               $xpath->registerNamespace("activity", ActivityNamespace::ACTIVITY);
+               $xpath->registerNamespace("georss", ActivityNamespace::GEORSS);
+               $xpath->registerNamespace("poco", ActivityNamespace::POCO);
+               $xpath->registerNamespace("ostatus", ActivityNamespace::OSTATUS);
+               $xpath->registerNamespace("statusnet", ActivityNamespace::STATUSNET);
 
                $header = [];
                $header["uid"] = $importer["importer_uid"];