]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/Bookmark/BookmarkPlugin.php
Merge branch 'master' into mmn_fixes
[quix0rs-gnu-social.git] / plugins / Bookmark / BookmarkPlugin.php
index e79b4bdec123857e9167188bc107442a1d72a7d4..904c7ee9c9e1817ebef74997ebd2a224c0a336a2 100644 (file)
@@ -297,79 +297,36 @@ class BookmarkPlugin extends MicroAppPlugin
      */
     protected function saveObjectFromActivity(Activity $activity, Notice $stored, array $options=array())
     {
-        $actobj = $activity->objects[0];
-
-        $relLinkEls = ActivityUtils::getLinks($actobj->element, 'related');
-
-        if (count($relLinkEls) !== 1) {
-            // TRANS: Client exception thrown when a bookmark is formatted incorrectly.
-            throw new ClientException(sprintf(_m('Expected exactly 1 link rel=related in a Bookmark, got %1$d.'), count($relLinkEls)));
-        }
-
-        return Bookmark::addNew($stored,
-                                 $actobj->title,
-                                 $relLinkEls[0]->getAttribute('href'),
-                                 $actobj->summary);
+        return Bookmark::saveActivityObject($activity->objects[0], $stored);
     }
 
-    function activityObjectFromNotice(Notice $notice)
+    public function onEndNoticeAsActivity(Notice $stored, Activity $act, Profile $scoped=null)
     {
-        assert($this->isMyNotice($notice));
-
-        common_log(LOG_INFO,
-                   "Formatting notice {$notice->uri} as a bookmark.");
-
-        $object = new ActivityObject();
-        $nb = Bookmark::fromStored($notice);
-
-        $object->id      = $notice->uri;
-        $object->type    = ActivityObject::BOOKMARK;
-        $object->title   = $nb->getTitle();
-        $object->summary = $nb->getDescription();
-        $object->link    = $notice->getUrl();
-
-        // Attributes of the URL
-
-        $attachments = $notice->attachments();
-
-        if (count($attachments) != 1) {
-            // TRANS: Server exception thrown when a bookmark has multiple attachments.
-            throw new ServerException(_m('Bookmark notice with the '.
-                                        'wrong number of attachments.'));
+        if (!$this->isMyNotice($stored)) {
+            return true;
         }
 
-        $target = $attachments[0];
-
-        $attrs = array('rel' => 'related',
-                       'href' => $target->getUrl());
-
-        if (!empty($target->title)) {
-            $attrs['title'] = $target->title;
-        }
-
-        $object->extra[] = array('link', $attrs, null);
-
-        // Attributes of the thumbnail, if any
-
-        try {
-            $thumbnail = $target->getThumbnail();
-            $tattrs = array('rel' => 'preview',
-                            'href' => $thumbnail->getUrl());
-
-            if (!empty($thumbnail->width)) {
-                $tattrs['media:width'] = $thumbnail->width;
-            }
-
-            if (!empty($thumbnail->height)) {
-                $tattrs['media:height'] = $thumbnail->height;
-            }
+        $this->extendActivity($stored, $act, $scoped);
+        return false;
+    }
 
-            $object->extra[] = array('link', $tattrs, null);
-        } catch (UnsupportedMediaException $e) {
-            // No image thumbnail metadata available
-        }
+    public function extendActivity(Notice $stored, Activity $act, Profile $scoped=null)
+    {
+        /*$hashtags = array();
+        $taglinks = array();
+
+        foreach ($tags as $tag) {
+            $hashtags[] = '#'.$tag;
+            $attrs      = array('href' => Notice_tag::url($tag),
+                                'rel'  => $tag,
+                                'class' => 'tag');
+            $taglinks[] = XMLStringer::estring('a', $attrs, $tag);
+        }*/
+    }
 
-        return $object;
+    function activityObjectFromNotice(Notice $notice)
+    {
+        return Bookmark::fromStored($notice)->asActivityObject();
     }
 
     function entryForm($out)
@@ -421,20 +378,10 @@ class BookmarkPlugin extends MicroAppPlugin
         return true;
     }
 
-    protected function showNoticeItemNotice(NoticeListItem $nli)
-    {
-        $nli->out->elementStart('div', 'entry-title');
-        $nli->showAuthor();
-        $nli->showContent();
-        $nli->out->elementEnd('div');
-    }
-
     protected function showNoticeContent(Notice $stored, HTMLOutputter $out, Profile $scoped=null)
     {
         $nb = Bookmark::fromStored($stored);
 
-        $profile = $stored->getProfile();
-
         // Whether to nofollow
         $attrs = array('href' => $nb->getUrl(), 'class' => 'bookmark-title');
 
@@ -447,7 +394,7 @@ class BookmarkPlugin extends MicroAppPlugin
         }
 
         $out->elementStart('h3');
-        $out->element('a', $attrs, $nb->title);
+        $out->element('a', $attrs, $nb->getTitle());
         $out->elementEnd('h3');
 
         // Replies look like "for:" tags
@@ -465,16 +412,14 @@ class BookmarkPlugin extends MicroAppPlugin
             $out->elementStart('ul', array('class' => 'bookmark-tags'));
 
             foreach ($replies as $reply) {
-                $other = Profile::getKV('id', $reply);
-                if (!empty($other)) {
-                    $out->elementStart('li');
-                    $out->element('a', array('rel' => 'tag',
-                                             'href' => $other->profileurl,
-                                             'title' => $other->getBestName()),
-                                  sprintf('for:%s', $other->nickname));
-                    $out->elementEnd('li');
-                    $out->text(' ');
-                }
+                $other = Profile::getByPK($reply);
+                $out->elementStart('li');
+                $out->element('a', array('rel' => 'tag',
+                                         'href' => $other->getUrl(),
+                                         'title' => $other->getBestName()),
+                              sprintf('for:%s', $other->getNickname()));
+                $out->elementEnd('li');
+                $out->text(' ');
             }
 
             foreach ($tags as $tag) {