Esempio n. 1
0
 function showContent()
 {
     $notice = $this->nli->notice;
     $out = $this->nli->out;
     $nb = Bookmark::getByNotice($notice);
     if (empty($nb)) {
         common_log(LOG_ERR, "No bookmark for notice {$notice->id}");
         parent::showContent();
         return;
     } else {
         if (empty($nb->url)) {
             common_log(LOG_ERR, "No url for bookmark {$nb->id} for notice {$notice->id}");
             parent::showContent();
             return;
         }
     }
     $profile = $notice->getProfile();
     $out->elementStart('p', array('class' => 'entry-content'));
     // 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 = $notice->getReplies();
     $tags = $notice->getTags();
     if (!empty($replies) || !empty($tags)) {
         $out->elementStart('ul', array('class' => 'bookmark-tags'));
         foreach ($replies as $reply) {
             $other = Profile::staticGet('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);
     }
     $out->elementEnd('p');
 }
 function showContent()
 {
     $notice = $this->nli->notice;
     $out = $this->nli->out;
     $out->elementStart('p', array('class' => 'entry-content'));
     $nb = Bookmark::getByNotice($notice);
     $profile = $notice->getProfile();
     $atts = $notice->attachments();
     if (count($atts) < 1) {
         // Something wrong; let default code deal with it.
         // TRANS: Exception thrown when a bookmark has no attachments.
         // TRANS: %1$s is a bookmark ID, %2$s is a notice ID (number).
         throw new Exception(sprintf(_m('Bookmark %1$s (notice %2$d) has no attachments.'), $nb->id, $notice->id));
     }
     $att = $atts[0];
     $out->elementStart('h3');
     $out->element('a', array('href' => $att->url, 'class' => 'bookmark-title'), $nb->title);
     $out->elementEnd('h3');
     // Replies look like "for:" tags
     $replies = $notice->getReplies();
     $tags = $notice->getTags();
     if (!empty($replies) || !empty($tags)) {
         $out->elementStart('ul', array('class' => 'bookmark-tags'));
         foreach ($replies as $reply) {
             $other = Profile::staticGet('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);
     }
     $out->elementEnd('p');
 }
Esempio n. 3
0
 function activityObjectFromNotice($notice)
 {
     assert($this->isMyNotice($notice));
     common_log(LOG_INFO, "Formatting notice {$notice->uri} as a bookmark.");
     $object = new ActivityObject();
     $nb = Bookmark::getByNotice($notice);
     $object->id = $notice->uri;
     $object->type = ActivityObject::BOOKMARK;
     $object->title = $nb->title;
     $object->summary = $nb->description;
     $object->link = $notice->bestUrl();
     // 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.'));
     }
     $target = $attachments[0];
     $attrs = array('rel' => 'related', 'href' => $target->url);
     if (!empty($target->title)) {
         $attrs['title'] = $target->title;
     }
     $object->extra[] = array('link', $attrs, null);
     // Attributes of the thumbnail, if any
     $thumbnail = $target->getThumbnail();
     if (!empty($thumbnail)) {
         $tattrs = array('rel' => 'preview', 'href' => $thumbnail->url);
         if (!empty($thumbnail->width)) {
             $tattrs['media:width'] = $thumbnail->width;
         }
         if (!empty($thumbnail->height)) {
             $tattrs['media:height'] = $thumbnail->height;
         }
         $object->extra[] = array('link', $attrs, null);
     }
     return $object;
 }
Esempio n. 4
0
 /**
  * Output our CSS class for bookmark notice list elements
  *
  * @param NoticeListItem $nli The item being shown
  *
  * @return boolean hook value
  */
 function onStartOpenNoticeListItemElement($nli)
 {
     $nb = Bookmark::getByNotice($nli->notice);
     if (!empty($nb)) {
         $id = empty($nli->repeat) ? $nli->notice->id : $nli->repeat->id;
         $nli->out->elementStart('li', array('class' => 'hentry notice bookmark', 'id' => 'notice-' . $id));
         Event::handle('EndOpenNoticeListItemElement', array($nli));
         return false;
     }
     return true;
 }