]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/Share/SharePlugin.php
Merge branch 'tagprofile-ajax-fix' into 'nightly'
[quix0rs-gnu-social.git] / plugins / Share / SharePlugin.php
index 582f7d3e2e0de4e2a4b1d893230e59ba97052a97..c337efbaeca10660b02376212f006df46cee722e 100644 (file)
@@ -40,6 +40,14 @@ class SharePlugin extends ActivityVerbHandlerPlugin
         return array(ActivityVerb::SHARE);
     }
 
+    // Share is a bit special and $act->objects[0] should be an Activity
+    // instead of ActivityObject! Therefore also $act->objects[0]->type is not set.
+    public function isMyActivity(Activity $act) {
+        return (count($act->objects) == 1
+            && ($act->objects[0] instanceof Activity)
+            && $this->isMyVerb($act->verb));
+    }
+
     public function onRouterInitialized(URLMapper $m)
     {
         // Web UI actions
@@ -122,6 +130,12 @@ class SharePlugin extends ActivityVerbHandlerPlugin
             return false;
         }
 
+        // Setting this here because when the algorithm gets back to
+        // Notice::saveActivity it will update the Notice object.
+        $stored->repeat_of = $sharedNotice->getID();
+        $stored->conversation = $sharedNotice->conversation;
+        $stored->object_type = ActivityUtils::resolveUri(ActivityObject::ACTIVITY, true);
+
         // We don't have to save a repeat in a separate table, we can
         // find repeats by just looking at the notice.repeat_of field.
 
@@ -147,7 +161,7 @@ class SharePlugin extends ActivityVerbHandlerPlugin
     public function extendActivity(Notice $stored, Activity $act, Profile $scoped=null)
     {
         // TODO: How to handle repeats of deleted notices?
-        $target = Notice::getById($stored->repeat_of);
+        $target = Notice::getByID($stored->repeat_of);
         // TRANS: A repeat activity's title. %1$s is repeater's nickname
         //        and %2$s is the repeated user's nickname.
         $act->title = sprintf(_('%1$s repeated a notice by %2$s'),
@@ -176,6 +190,31 @@ class SharePlugin extends ActivityVerbHandlerPlugin
 
     // Layout stuff
 
+    /**
+     * show a link to the author of repeat
+     *
+     * FIXME: Some repeat stuff still in lib/noticelistitem.php! ($nli->repeat etc.)
+     */
+    public function onEndShowNoticeInfo(NoticeListItem $nli)
+    {
+        if (!empty($nli->repeat)) {
+            $repeater = $nli->repeat->getProfile();
+
+            $attrs = array('href' => $repeater->getUrl(),
+                           'class' => 'h-card p-author',
+                           'title' => $repeater->getFancyName());
+
+            $nli->out->elementStart('span', 'repeat h-entry');
+
+            // TRANS: Addition in notice list item if notice was repeated. Followed by a span with a nickname.
+            $nli->out->raw(_('Repeated by').' ');
+
+            $nli->out->element('a', $attrs, $repeater->getNickname());
+
+            $nli->out->elementEnd('span');
+        }
+    }
+
     public function onEndShowThreadedNoticeTailItems(NoticeListItem $nli, Notice $notice, &$threadActive)
     {
         if ($nli instanceof ThreadedNoticeListSubItem) {
@@ -230,6 +269,34 @@ class SharePlugin extends ActivityVerbHandlerPlugin
         // pass
     }
 
+    // API stuff
+
+    /**
+     * Typically just used to fill out Twitter-compatible API status data.
+     *
+     * FIXME: Make all the calls before this end up with a Notice instead of ArrayWrapper please...
+     */
+    public function onNoticeSimpleStatusArray($notice, array &$status, Profile $scoped=null, array $args=array())
+    {
+        $status['repeated'] = $scoped instanceof Profile
+                            ? $scoped->hasRepeated($notice)
+                            : false;
+
+        if ($status['repeated'] === true) {
+            // Qvitter API wants the "repeated_id" value set too.
+            $repeated = Notice::pkeyGet(array('profile_id' => $scoped->getID(),
+                                              'repeat_of' => $notice->getID()));
+            $status['repeated_id'] = $repeated->getID();
+        }
+    }
+
+    public function onTwitterUserArray(Profile $profile, array &$userdata, Profile $scoped=null, array $args=array())
+    {
+        $userdata['favourites_count'] = Fave::countByProfile($profile);
+    }
+
+    // Command stuff
+
     /**
      * EndInterpretCommand for RepeatPlugin will handle the 'repeat' command
      * using the class RepeatCommand.