]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Merge branch '0.9.x' into noactor
authorEvan Prodromou <evan@status.net>
Wed, 29 Dec 2010 23:29:29 +0000 (15:29 -0800)
committerEvan Prodromou <evan@status.net>
Wed, 29 Dec 2010 23:29:29 +0000 (15:29 -0800)
actions/apitimelinegroup.php
lib/activity.php
lib/activityobject.php
lib/atom10feed.php
lib/atomcategory.php
lib/atomgroupnoticefeed.php
lib/atomusernoticefeed.php
lib/poco.php
lib/pocoaddress.php
lib/pocourl.php
plugins/OStatus/OStatusPlugin.php

index a85da4b0f35c1dddd62ed132a7d4f0a5ae7e5619..e1bc102e450edc54b2df4fe35b25887a89dac310 100644 (file)
@@ -125,10 +125,6 @@ class ApiTimelineGroupAction extends ApiPrivateAuthAction
             header('Content-Type: application/atom+xml; charset=utf-8');
 
             try {
-                $atom->addAuthorRaw($this->group->asAtomAuthor());
-                $atom->setActivitySubject($this->group->asActivitySubject());
-                $atom->setId($self);
-                $atom->setSelfLink($self);
                 $atom->addEntryFromNotices($this->notices);
                 $this->raw($atom->getString());
             } catch (Atom10FeedException $e) {
index 3458c76b9a6d3ef61f33659abde74011d226a61d..8d7ae1540b7b23b06daba33d30ff580a13227235 100644 (file)
@@ -377,13 +377,7 @@ class Activity
         $xs->element('updated', null, $published);
             
         if ($author) {
-            $xs->elementStart('author');
-            $xs->element('uri', array(), $this->actor->id);
-            if ($this->actor->title) {
-                $xs->element('name', array(), $this->actor->title);
-            }
-            $xs->elementEnd('author');
-            $this->actor->outputTo($xs, 'activity:actor');
+            $this->actor->outputTo($xs, 'author');
         }
 
         if ($this->verb != ActivityVerb::POST || count($this->objects) != 1) {
@@ -446,7 +440,7 @@ class Activity
         }
 
         foreach ($this->categories as $cat) {
-            $xs->raw($cat->asString());
+            $cat->outputTo($xs);
         }
 
         // can be either URLs or enclosure objects
index 5185d7761055951ab86a3cff18a8322c38384f25..f774dd3c8bc0abdf35d1d474e4cfbb45628358b7 100644 (file)
@@ -172,10 +172,39 @@ class ActivityObject
 
     private function _fromAuthor($element)
     {
-        $this->type  = self::PERSON; // XXX: is this fair?
-        $this->title = $this->_childContent($element, self::NAME);
+        $this->type = $this->_childContent($element,
+                                           Activity::OBJECTTYPE,
+                                           Activity::SPEC);
 
-        $this->id = $this->_childContent($element, self::URI);
+        if (empty($this->type)) {
+            $this->type = self::PERSON; // XXX: is this fair?
+        }
+        
+        // start with <atom:title>
+
+        $title = ActivityUtils::childHtmlContent($element, self::TITLE);
+
+        if (!empty($title)) {
+            $this->title = html_entity_decode(strip_tags($title), ENT_QUOTES, 'UTF-8');
+        }
+
+        // fall back to <atom:name>
+
+        if (empty($this->title)) {
+            $this->title = $this->_childContent($element, self::NAME);
+        }
+
+        // start with <atom:id>
+
+        $this->id = $this->_childContent($element, self::ID);
+
+        // fall back to <atom:uri>
+
+        if (empty($this->id)) {
+            $this->id = $this->_childContent($element, self::URI);
+        }
+
+        // fall further back to <atom:email>
 
         if (empty($this->id)) {
             $email = $this->_childContent($element, self::EMAIL);
@@ -184,6 +213,14 @@ class ActivityObject
                 $this->id = 'mailto:'.$email;
             }
         }
+
+        $this->link = ActivityUtils::getPermalink($element);
+
+        // fall finally back to <link rel=alternate>
+
+        if (empty($this->id) && !empty($this->link)) { // fallback if there's no ID
+            $this->id = $this->link;
+        }
     }
 
     private function _fromAtomEntry($element)
@@ -498,14 +535,21 @@ class ActivityObject
 
         $xo->element('activity:object-type', null, $this->type);
 
-        $xo->element(self::ID, null, $this->id);
+        // <author> uses URI
+
+        if ($tag == 'author') {
+            $xo->element(self::URI, null, $this->id);
+        } else {
+            $xo->element(self::ID, null, $this->id);
+        }
 
         if (!empty($this->title)) {
-            $xo->element(
-                self::TITLE,
-                null,
-                common_xml_safe_str($this->title)
-            );
+            $name = common_xml_safe_str($this->title);
+            if ($tag == 'author') {
+                $xo->element(self::NAME, null, $name);
+            } else {
+                $xo->element(self::TITLE, null, $name);
+            }
         }
 
         if (!empty($this->summary)) {
@@ -563,7 +607,7 @@ class ActivityObject
         }
 
         if (!empty($this->poco)) {
-            $xo->raw($this->poco->asString());
+            $this->poco->outputTo($xo);
         }
 
         foreach ($this->extra as $el) {
index 3ae9dc81be077c3b387202ffdb49800cc565245e..881df6605f3d05565afc6d850c666fd94fe9ff9b 100644 (file)
@@ -146,15 +146,16 @@ class Atom10Feed extends XMLStringer
     }
 
     /**
-     * Add a activity feed subject via raw XML string
+     * Deprecated <activity:subject>; ignored
      *
      * @param string $xmlSubject An XML string representation of the subject
      *
      * @return void
      */
+
     function setActivitySubject($xmlSubject)
     {
-        $this->subject = $xmlSubject;
+        throw new ServerException(_('Don\'t use this method!'));
     }
 
     function getNamespaces()
index 9763023f7589c151ed4e24c2cea51fa93f7e951b..e527877cb090347bdf064222369756dcaede3346 100644 (file)
@@ -59,6 +59,13 @@ class AtomCategory
     }
 
     function asString()
+    {
+        $xs = new XMLStringer();
+        $this->outputTo($xs);
+        return $xs->getString();
+    }
+
+    function outputTo($xo)
     {
         $attribs = array();
         if ($this->term !== null) {
@@ -70,8 +77,6 @@ class AtomCategory
         if ($this->label !== null) {
             $attribs['label'] = $this->label;
         }
-        $xs = new XMLStringer();
-        $xs->element('category', $attribs);
-        return $xs->getString();
+        $xo->element('category', $attribs);
     }
 }
index 39a1fd456efa02a3a89f553d4469f8ddbbf705a2..5b6fcf42952b1e24ee255234b16157907b8cfb07 100644 (file)
@@ -85,8 +85,9 @@ class AtomGroupNoticeFeed extends AtomNoticeFeed
         $this->setId($self);
         $this->setSelfLink($self);
 
-        $this->addAuthorRaw($group->asAtomAuthor());
-        $this->setActivitySubject($group->asActivitySubject());
+        $ao = ActivityObject::fromGroup($group);
+
+        $this->addAuthorRaw($ao->asString('author'));
 
         $this->addLink($group->homeUrl());
     }
index ec368f5ca1648b9c447bbea3abe01a6e800db95c..5ca089b859a85d753f7af13903e598e9eb876d95 100644 (file)
@@ -60,8 +60,8 @@ class AtomUserNoticeFeed extends AtomNoticeFeed
         $this->user = $user;
         if (!empty($user)) {
             $profile = $user->getProfile();
-            $this->addAuthor($profile->nickname, $user->uri);
-            $this->setActivitySubject($profile->asActivityNoun('subject'));
+            $ao = ActivityObject::fromProfile($profile);
+            $this->addAuthorRaw($ao->asString('author'));
         }
 
         // TRANS: Title in atom user notice feed. %s is a user name.
index 2157062b3798202b9c6a3da5b5b636a890ab515e..d7b082163ee21eb4199be57d17463f49f21f7fc5 100644 (file)
@@ -211,30 +211,34 @@ class PoCo
     function asString()
     {
         $xs = new XMLStringer(true);
-        $xs->element(
+        $this->outputTo($xs);
+        return $xs->getString();
+    }
+
+    function outputTo($xo)
+    {
+        $xo->element(
             'poco:preferredUsername',
             null,
             $this->preferredUsername
         );
 
-        $xs->element(
+        $xo->element(
             'poco:displayName',
             null,
             $this->displayName
         );
 
         if (!empty($this->note)) {
-            $xs->element('poco:note', null, common_xml_safe_str($this->note));
+            $xo->element('poco:note', null, common_xml_safe_str($this->note));
         }
 
         if (!empty($this->address)) {
-            $xs->raw($this->address->asString());
+            $this->address->outputTo($xo);
         }
 
         foreach ($this->urls as $url) {
-            $xs->raw($url->asString());
+            $url->outputTo($xo);
         }
-
-        return $xs->getString();
     }
 }
index 60873bdc42cd6f7e56c84d415004ea02f2131895..d9f6ff2bdefa8ea988cbb6200a30c2ffa71bd0f7 100644 (file)
@@ -42,15 +42,18 @@ class PoCoAddress
     // @todo Other address fields
 
     function asString()
+    {
+        $xs = new XMLStringer(true);
+        $this->outputTo($xs);
+        return $xs->getString();
+    }
+
+    function outputTo($xo)
     {
         if (!empty($this->formatted)) {
-            $xs = new XMLStringer(true);
-            $xs->elementStart('poco:address');
-            $xs->element('poco:formatted', null, common_xml_safe_str($this->formatted));
-            $xs->elementEnd('poco:address');
-            return $xs->getString();
+            $xo->elementStart('poco:address');
+            $xo->element('poco:formatted', null, common_xml_safe_str($this->formatted));
+            $xo->elementEnd('poco:address');
         }
-
-        return null;
     }
 }
index 803484d760bd3b93ef9c19b84e1bf767aac64781..786793b280d67e2ec53735eb4a1fb4bc8effcff6 100644 (file)
@@ -53,13 +53,18 @@ class PoCoURL
     function asString()
     {
         $xs = new XMLStringer(true);
-        $xs->elementStart('poco:urls');
-        $xs->element('poco:type', null, $this->type);
-        $xs->element('poco:value', null, $this->value);
+        $this->outputTo($xs);
+        return $xs->getString();
+    }
+
+    function outputTo($xo)
+    {
+        $xo->elementStart('poco:urls');
+        $xo->element('poco:type', null, $this->type);
+        $xo->element('poco:value', null, $this->value);
         if (!empty($this->primary)) {
-            $xs->element('poco:primary', null, 'true');
+            $xo->element('poco:primary', null, 'true');
         }
-        $xs->elementEnd('poco:urls');
-        return $xs->getString();
+        $xo->elementEnd('poco:urls');
     }
 }
index d0b64e87694d41ffe09fb382820abe6735d8d236..86bd15e0b73491f67619e062e124e1c2d103fa08 100644 (file)
@@ -145,12 +145,10 @@ class OStatusPlugin extends Plugin
             $user = $feed->getUser();
             $id   = $user->id;
             $profile = $user->getProfile();
-            $feed->setActivitySubject($profile->asActivityNoun('subject'));
         } else if ($feed instanceof AtomGroupNoticeFeed) {
             $salmonAction = 'groupsalmon';
             $group = $feed->getGroup();
             $id = $group->id;
-            $feed->setActivitySubject($group->asActivitySubject());
         } else {
             return true;
         }