]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/Bookmark/BookmarkPlugin.php
Merge commit 'refs/merge-requests/23' of https://gitorious.org/social/mainline into...
[quix0rs-gnu-social.git] / plugins / Bookmark / BookmarkPlugin.php
index 1093b435aa39534c8d4195cedee35aaff6e9d67c..9ea83c4caf1f2263f43ff3952b5e550093b585fc 100644 (file)
@@ -48,6 +48,8 @@ class BookmarkPlugin extends MicroAppPlugin
     const VERSION         = '0.1';
     const IMPORTDELICIOUS = 'BookmarkPlugin:IMPORTDELICIOUS';
 
+    var $oldSaveNew = true;
+
     /**
      * Authorization for importing delicious bookmarks
      *
@@ -107,11 +109,11 @@ class BookmarkPlugin extends MicroAppPlugin
     /**
      * Map URLs to actions
      *
-     * @param Net_URL_Mapper $m path-to-action mapper
+     * @param URLMapper $m path-to-action mapper
      *
      * @return boolean hook value; true means continue processing, false means stop.
      */
-    function onRouterInitialized($m)
+    public function onRouterInitialized(URLMapper $m)
     {
         if (common_config('singleuser', 'enabled')) {
             $nickname = User::singleUserNickname();
@@ -237,39 +239,6 @@ class BookmarkPlugin extends MicroAppPlugin
         return true;
     }
 
-    /**
-     * Output our CSS class for bookmark notice list elements
-     *
-     * @param NoticeListItem $nli The item being shown
-     *
-     * @return boolean hook value
-     */
-
-    function onStartOpenNoticeListItemElement($nli)
-    {
-       if (!$this->isMyNotice($nli->notice)) {
-               return true;
-       }
-       
-        $nb = Bookmark::getByNotice($nli->notice);
-        
-        if (empty($nb)) {
-               $this->log(LOG_INFO, "Notice {$nli->notice->id} has bookmark class but no matching Bookmark record.");
-               return true;
-        }
-               
-           $id = (empty($nli->repeat)) ? $nli->notice->id : $nli->repeat->id;
-           $class = 'h-entry notice bookmark';
-           if ($nli->notice->scope != 0 && $nli->notice->scope != 1) {
-               $class .= ' limited-scope';
-           }
-           $nli->out->elementStart('li', array('class' => $class,
-                                               'id' => 'notice-' . $id));
-                                               
-           Event::handle('EndOpenNoticeListItemElement', array($nli));
-           return false;
-    }
-
     /**
      * Modify the default menu to link to our custom action
      *
@@ -471,19 +440,6 @@ class BookmarkPlugin extends MicroAppPlugin
         return $object;
     }
 
-    /**
-     * Given a notice list item, returns an adapter specific
-     * to this plugin.
-     *
-     * @param NoticeListItem $nli item to adapt
-     *
-     * @return NoticeListItemAdapter adapter or null
-     */
-    function adaptNoticeListItem($nli)
-    {
-        return new BookmarkListItem($nli);
-    }
-
     function entryForm($out)
     {
         return new InitialBookmarkForm($out);
@@ -536,4 +492,87 @@ 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::getByNotice($stored);
+
+        if (empty($nb)) {
+            common_log(LOG_ERR, "No bookmark for notice {$stored->id}");
+            parent::showContent();
+            return;
+        } else if (empty($nb->url)) {
+            common_log(LOG_ERR, "No url for bookmark {$nb->id} for notice {$stored->id}");
+            parent::showContent();
+            return;
+        }
+
+        $profile = $stored->getProfile();
+
+        // Whether to nofollow
+        $attrs = array('href' => $nb->url, 'class' => 'bookmark-title');
+
+        $nf = common_config('nofollow', 'external');
+
+        if ($nf == 'never' || ($nf == 'sometimes' and $out instanceof ShowstreamAction)) {
+            $attrs['rel'] = 'external';
+        } else {
+            $attrs['rel'] = 'nofollow external';
+        }
+
+        $out->elementStart('h3');
+        $out->element('a', $attrs, $nb->title);
+        $out->elementEnd('h3');
+
+        // Replies look like "for:" tags
+        $replies = $stored->getReplies();
+        $tags = $stored->getTags();
+
+        if (!empty($replies) || !empty($tags)) {
+
+            $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(' ');
+                }
+            }
+
+            foreach ($tags as $tag) {
+                $tag = trim($tag);
+                if (!empty($tag)) {
+                    $out->elementStart('li');
+                    $out->element('a',
+                                  array('rel' => 'tag',
+                                        'href' => Notice_tag::url($tag)),
+                                  $tag);
+                    $out->elementEnd('li');
+                    $out->text(' ');
+                }
+            }
+
+            $out->elementEnd('ul');
+        }
+
+        if (!empty($nb->description)) {
+            $out->element('p',
+                          array('class' => 'bookmark-description'),
+                          $nb->description);
+        }
+    }
 }