]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
add hooks for atom pub posts
authorEvan Prodromou <evan@status.net>
Mon, 15 Nov 2010 16:54:42 +0000 (11:54 -0500)
committerEvan Prodromou <evan@status.net>
Mon, 15 Nov 2010 16:54:42 +0000 (11:54 -0500)
EVENTS.txt
actions/apitimelineuser.php

index 8e730945a41b34aa024301c9a057b2dd7fa6de75..2df21f01a37f7bac7a130a308bc98f907108801d 100644 (file)
@@ -1158,3 +1158,11 @@ StartRevokeRole: when a role is being revoked
 EndRevokeRole: when a role has been revoked
 - $profile: profile that lost the role
 - $role: string name of the role
+
+StartAtomPubNewActivity: When a new activity comes in through Atom Pub API
+- &$activity: received activity
+
+EndAtomPubNewActivity: When a new activity comes in through Atom Pub API
+- $activity: received activity
+- $notice: notice that was created
+
index 69cd9c2cb45af293c3669466b374ae4236b1bf2e..7e76636460ad54b8761f37b4946eafcff7c65381 100644 (file)
@@ -325,20 +325,38 @@ class ApiTimelineUserAction extends ApiBareAuthAction
 
         $activity = new Activity($dom->documentElement);
 
-        if ($activity->verb != ActivityVerb::POST) {
-            $this->clientError(_('Can only handle post activities.'));
-            return;
-        }
+        if (Event::handle('StartAtomPubNewActivity', array(&$activity))) {
 
-        $note = $activity->objects[0];
+            if ($activity->verb != ActivityVerb::POST) {
+                $this->clientError(_('Can only handle post activities.'));
+                return;
+            }
 
-        if (!in_array($note->type, array(ActivityObject::NOTE,
-                                         ActivityObject::BLOGENTRY,
-                                         ActivityObject::STATUS))) {
-            $this->clientError(sprintf(_('Cannot handle activity object type "%s"',
-                                         $note->type)));
-            return;
+            $note = $activity->objects[0];
+
+            if (!in_array($note->type, array(ActivityObject::NOTE,
+                                             ActivityObject::BLOGENTRY,
+                                             ActivityObject::STATUS))) {
+                $this->clientError(sprintf(_('Cannot handle activity object type "%s"',
+                                             $note->type)));
+                return;
+            }
+
+            $saved = $this->postNote($activity);
+
+            Event::handle('EndAtomPubNewActivity', array($activity, $saved));
+        }
+
+        if (!empty($saved)) {
+            header("Location: " . common_local_url('ApiStatusesShow', array('notice_id' => $saved->id,
+                                                                            'format' => 'atom')));
+            $this->showSingleAtomStatus($saved);
         }
+    }
+
+    function postNote($activity)
+    {
+        $note = $activity->objects[0];
 
         // Use summary as fallback for content
 
@@ -458,11 +476,7 @@ class ApiTimelineUserAction extends ApiBareAuthAction
                                  'atompub', // TODO: deal with this
                                  $options);
 
-        if (!empty($saved)) {
-            header("Location: " . common_local_url('ApiStatusesShow', array('notice_id' => $saved->id,
-                                                                            'format' => 'atom')));
-            $this->showSingleAtomStatus($saved);
-        }
+        return $saved;
     }
 
     function purify($content)