X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=plugins%2FBookmark%2FBookmarkPlugin.php;h=9ea83c4caf1f2263f43ff3952b5e550093b585fc;hb=bb31394cce356677c835717f775ee795ef700087;hp=0e3db1ed829c15fc161867eea069db59ab2ccde8;hpb=9f4bcbad8ae200d27cc2ba5244e2d878b8718c53;p=quix0rs-gnu-social.git diff --git a/plugins/Bookmark/BookmarkPlugin.php b/plugins/Bookmark/BookmarkPlugin.php index 0e3db1ed82..9ea83c4caf 100644 --- a/plugins/Bookmark/BookmarkPlugin.php +++ b/plugins/Bookmark/BookmarkPlugin.php @@ -109,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(); @@ -239,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 * @@ -473,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); @@ -538,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); + } + } }