]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/microappplugin.php
adminUpdates setting not available now
[quix0rs-gnu-social.git] / lib / microappplugin.php
index 1c886d5a6918874219cd3e4a1276bf677b3adedc..ec67d9fe2e30c8dc17172c93886401b0428c43db 100644 (file)
@@ -162,6 +162,14 @@ abstract class MicroAppPlugin extends Plugin
      */
     abstract function deleteRelated($notice);
 
+    /**
+     *
+     */
+    public function newFormAction() {
+        // such as 'newbookmark' or 'newevent' route
+        return 'new'.$this->tag();
+    }
+
     /**
      * Check if a given notice object should be handled by this micro-app
      * plugin.
@@ -175,7 +183,7 @@ abstract class MicroAppPlugin extends Plugin
      */
     function isMyNotice($notice) {
         $types = $this->types();
-        return in_array($notice->object_type, $types);
+        return ($notice->verb == ActivityVerb::POST) && in_array($notice->object_type, $types);
     }
 
     /**
@@ -193,6 +201,8 @@ abstract class MicroAppPlugin extends Plugin
     function isMyActivity($activity) {
         $types = $this->types();
         return (count($activity->objects) == 1 &&
+                ($activity->objects[0] instanceof ActivityObject) &&
+                ($activity->verb == ActivityVerb::POST) &&
                 in_array($activity->objects[0]->type, $types));
     }
 
@@ -244,11 +254,11 @@ abstract class MicroAppPlugin extends Plugin
      */
     function onNoticeDeleteRelated($notice)
     {
-        if ($this->isMyNotice($notice)) {
-            $this->deleteRelated($notice);
+        if (!$this->isMyNotice($notice)) {
+            return true;
         }
 
-        return true;
+        $this->deleteRelated($notice);
     }
 
     /**
@@ -329,12 +339,12 @@ abstract class MicroAppPlugin extends Plugin
      */
     function onStartActivityObjectFromNotice($notice, &$object)
     {
-        if ($this->isMyNotice($notice)) {
-            $object = $this->activityObjectFromNotice($notice);
-            return false;
+        if (!$this->isMyNotice($notice)) {
+            return true;
         }
 
-        return true;
+        $object = $this->activityObjectFromNotice($notice);
+        return false;
     }
 
     /**
@@ -347,29 +357,28 @@ abstract class MicroAppPlugin extends Plugin
      */
     function onStartHandleFeedEntryWithProfile($activity, $oprofile, &$notice)
     {
-        if ($this->isMyActivity($activity)) {
-
-            $actor = $oprofile->checkAuthorship($activity);
+        if (!$this->isMyActivity($activity)) {
+            return true;
+        }
 
-            if (empty($actor)) {
-                // TRANS: Client exception thrown when no author for an activity was found.
-                throw new ClientException(_('Cannot get author for activity.'));
-            }
+        $actor = $oprofile->checkAuthorship($activity);
 
-            $object = $activity->objects[0];
+        if (!$actor instanceof Ostatus_profile) {
+            // TRANS: Client exception thrown when no author for an activity was found.
+            throw new ClientException(_('Cannot get author for activity.'));
+        }
 
-            $options = array('uri' => $object->id,
-                             'url' => $object->link,
-                             'is_local' => Notice::REMOTE,
-                             'source' => 'ostatus');
+        $object = $activity->objects[0];
 
-            // $actor is an ostatus_profile
-            $notice = $this->saveNoticeFromActivity($activity, $actor->localProfile(), $options);
+        $options = array('uri' => $object->id,
+                         'url' => $object->link,
+                         'is_local' => Notice::REMOTE,
+                         'source' => 'ostatus');
 
-            return false;
-        }
+        // $actor is an ostatus_profile
+        $notice = $this->saveNoticeFromActivity($activity, $actor->localProfile(), $options);
 
-        return true;
+        return false;
     }
 
     /**
@@ -383,51 +392,50 @@ abstract class MicroAppPlugin extends Plugin
 
     function onStartHandleSalmonTarget($activity, $target)
     {
-        if ($this->isMyActivity($activity)) {
-            $this->log(LOG_INFO, "Checking {$activity->id} as a valid Salmon slap.");
-
-            if ($target instanceof User_group) {
-                $uri = $target->getUri();
-                if (!in_array($uri, $activity->context->attention)) {
-                    // @todo FIXME: please document (i18n).
-                    // TRANS: Client exception thrown when ...
-                    throw new ClientException(_('Bookmark not posted to this group.'));
-                }
-            } else if ($target instanceof User) {
-                $uri      = $target->uri;
-                $original = null;
-                if (!empty($activity->context->replyToID)) {
-                    $original = Notice::staticGet('uri',
-                                                  $activity->context->replyToID);
-                }
-                if (!in_array($uri, $activity->context->attention) &&
-                    (empty($original) ||
-                     $original->profile_id != $target->id)) {
-                    // @todo FIXME: Please document (i18n).
-                    // TRANS: Client exception when ...
-                    throw new ClientException(_('Object not posted to this user.'));
-                }
-            } else {
-                // TRANS: Server exception thrown when a micro app plugin uses a target that cannot be handled.
-                throw new ServerException(_('Do not know how to handle this kind of target.'));
-            }
+        if (!$this->isMyActivity($activity)) {
+            return true;
+        }
 
-            $actor = Ostatus_profile::ensureActivityObjectProfile($activity->actor);
+        $this->log(LOG_INFO, "Checking {$activity->id} as a valid Salmon slap.");
 
-            $object = $activity->objects[0];
+        if ($target instanceof User_group) {
+            $uri = $target->getUri();
+            if (!array_key_exists($uri, $activity->context->attention)) {
+                // @todo FIXME: please document (i18n).
+                // TRANS: Client exception thrown when ...
+                throw new ClientException(_('Object not posted to this group.'));
+            }
+        } else if ($target instanceof User) {
+            $uri      = $target->uri;
+            $original = null;
+            if (!empty($activity->context->replyToID)) {
+                $original = Notice::getKV('uri', $activity->context->replyToID);
+            }
+            if (!array_key_exists($uri, $activity->context->attention) &&
+                (empty($original) ||
+                 $original->profile_id != $target->id)) {
+                // @todo FIXME: Please document (i18n).
+                // TRANS: Client exception when ...
+                throw new ClientException(_('Object not posted to this user.'));
+            }
+        } else {
+            // TRANS: Server exception thrown when a micro app plugin uses a target that cannot be handled.
+            throw new ServerException(_('Do not know how to handle this kind of target.'));
+        }
 
-            $options = array('uri' => $object->id,
-                             'url' => $object->link,
-                             'is_local' => Notice::REMOTE,
-                             'source' => 'ostatus');
+        $actor = Ostatus_profile::ensureActivityObjectProfile($activity->actor);
 
-            // $actor is an ostatus_profile
-            $this->saveNoticeFromActivity($activity, $actor->localProfile(), $options);
+        $object = $activity->objects[0];
 
-            return false;
-        }
+        $options = array('uri' => $object->id,
+                         'url' => $object->link,
+                         'is_local' => Notice::REMOTE,
+                         'source' => 'ostatus');
 
-        return true;
+        // $actor is an ostatus_profile
+        $this->saveNoticeFromActivity($activity, $actor->localProfile(), $options);
+
+        return false;
     }
 
     /**
@@ -441,19 +449,18 @@ abstract class MicroAppPlugin extends Plugin
      */
     function onStartAtomPubNewActivity(&$activity, $user, &$notice)
     {
-        if ($this->isMyActivity($activity)) {
+        if (!$this->isMyActivity($activity)) {
+            return true;
+        }
 
-            $options = array('source' => 'atompub');
+        $options = array('source' => 'atompub');
 
-            // $user->getProfile() is a Profile
-            $this->saveNoticeFromActivity($activity,
-                                          $user->getProfile(),
-                                          $options);
+        // $user->getProfile() is a Profile
+        $notice = $this->saveNoticeFromActivity($activity,
+                                                $user->getProfile(),
+                                                $options);
 
-            return false;
-        }
-
-        return true;
+        return false;
     }
 
     /**
@@ -469,27 +476,26 @@ abstract class MicroAppPlugin extends Plugin
      */
     function onStartImportActivity($user, $author, $activity, $trusted, &$done)
     {
-        if ($this->isMyActivity($activity)) {
-
-            $obj = $activity->objects[0];
+        if (!$this->isMyActivity($activity)) {
+            return true;
+        }
 
-            $options = array('uri' => $object->id,
-                             'url' => $object->link,
-                             'source' => 'restore');
+        $obj = $activity->objects[0];
 
-            // $user->getProfile() is a Profile
-            $saved = $this->saveNoticeFromActivity($activity,
-                                                   $user->getProfile(),
-                                                   $options);
+        $options = array('uri' => $object->id,
+                         'url' => $object->link,
+                         'source' => 'restore');
 
-            if (!empty($saved)) {
-                $done = true;
-            }
+        // $user->getProfile() is a Profile
+        $saved = $this->saveNoticeFromActivity($activity,
+                                               $user->getProfile(),
+                                               $options);
 
-            return false;
+        if (!empty($saved)) {
+            $done = true;
         }
 
-        return true;
+        return false;
     }
 
     /**
@@ -534,7 +540,9 @@ abstract class MicroAppPlugin extends Plugin
 
     function onStartShowEntryForms(&$tabs)
     {
-        $tabs[$this->tag()] = $this->appTitle();
+        $tabs[$this->tag()] = array('title' => $this->appTitle(),
+                                    'href'  => common_local_url($this->newFormAction()),
+                                   );
         return true;
     }