X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=lib%2Fnoticelistitem.php;h=81fcb72caa77f25d7922b1fc31306a9609d78a08;hb=5e4f93cc7da1150b2ee3846b4fff86230275a20e;hp=734342819db553f49eb797e6c2de798926643dcc;hpb=09ef1fff69147d06c9bbc7bd25a66999c13b3a0b;p=quix0rs-gnu-social.git diff --git a/lib/noticelistitem.php b/lib/noticelistitem.php index 734342819d..81fcb72caa 100644 --- a/lib/noticelistitem.php +++ b/lib/noticelistitem.php @@ -28,11 +28,7 @@ * @link http://status.net/ */ -if (!defined('STATUSNET')) { - // This check helps protect against security problems; - // your code file can't be executed directly from the web. - exit(1); -} +if (!defined('GNUSOCIAL')) { exit(1); } /** * widget for displaying a single notice @@ -69,12 +65,12 @@ class NoticeListItem extends Widget * * @param Notice $notice The notice we'll display */ - function __construct($notice, $out=null) + function __construct(Notice $notice, Action $out=null) { parent::__construct($out); if (!empty($notice->repeat_of)) { $original = Notice::getKV('id', $notice->repeat_of); - if (empty($original)) { // could have been deleted + if (!$original instanceof Notice) { // could have been deleted $this->notice = $notice; } else { $this->notice = $original; @@ -117,20 +113,33 @@ class NoticeListItem extends Widget function showNotice() { - $this->out->elementStart('div', 'entry-title'); - $this->showAuthor(); - $this->showContent(); - $this->out->elementEnd('div'); + if (Event::handle('StartShowNoticeItemNotice', array($this))) { + $this->showNoticeTitle(); + $this->showAuthor(); + $this->showAddressees(); + $this->showContent(); + Event::handle('EndShowNoticeItemNotice', array($this)); + } + } + + function showNoticeTitle() + { + if (Event::handle('StartShowNoticeTitle', array($this))) { + $this->element('a', array('href' => $this->notice->getUrl(), + 'class' => 'p-name metadata'), + $this->notice->getTitle()); + Event::handle('EndShowNoticeTitle', array($this)); + } } function showNoticeInfo() { - $this->out->elementStart('div', 'entry-content'); + $this->out->elementStart('div', 'entry-metadata'); if (Event::handle('StartShowNoticeInfo', array($this))) { $this->showNoticeLink(); $this->showNoticeSource(); $this->showNoticeLocation(); - $this->showContext(); + $this->showPermalink(); $this->showRepeat(); Event::handle('EndShowNoticeInfo', array($this)); } @@ -145,7 +154,6 @@ class NoticeListItem extends Widget if ($user) { $this->out->elementStart('div', 'notice-options'); if (Event::handle('StartShowNoticeOptionItems', array($this))) { - $this->showFaveForm(); $this->showReplyLink(); $this->showRepeatForm(); $this->showDeleteLink(); @@ -166,7 +174,7 @@ class NoticeListItem extends Widget { if (Event::handle('StartOpenNoticeListItemElement', array($this))) { $id = (empty($this->repeat)) ? $this->notice->id : $this->repeat->id; - $class = 'hentry notice'; + $class = 'h-entry notice'; if ($this->notice->scope != 0 && $this->notice->scope != 1) { $class .= ' limited-scope'; } @@ -179,28 +187,6 @@ class NoticeListItem extends Widget } } - /** - * show the "favorite" form - * - * @return void - */ - function showFaveForm() - { - if (Event::handle('StartShowFaveForm', array($this))) { - $user = common_current_user(); - if ($user) { - if ($user->hasFave($this->notice)) { - $disfavor = new DisfavorForm($this->out, $this->notice); - $disfavor->show(); - } else { - $favor = new FavorForm($this->out, $this->notice); - $favor->show(); - } - } - Event::handle('EndShowFaveForm', array($this)); - } - } - /** * show the author of a notice * @@ -211,32 +197,17 @@ class NoticeListItem extends Widget function showAuthor() { - $this->out->elementStart('div', 'author'); - - $this->out->elementStart('span', 'vcard author'); - $attrs = array('href' => $this->profile->profileurl, - 'class' => 'url', - 'title' => $this->profile->nickname); + 'class' => 'h-card p-author', + 'title' => $this->profile->getNickname()); - $this->out->elementStart('a', $attrs); - $this->showAvatar(); - $this->out->text(' '); - $user = common_current_user(); - if (!empty($user) && $user->streamNicknames()) { - $this->out->element('span',array('class' => 'fn'), - $this->profile->nickname); - } else { - $this->out->element('span',array('class' => 'fn'), - $this->profile->getBestName()); + if (Event::handle('StartShowNoticeItemAuthor', array($this->profile, $this->out, &$attrs))) { + $this->out->elementStart('a', $attrs); + $this->showAvatar($this->profile); + $this->out->text($this->profile->getStreamName()); + $this->out->elementEnd('a'); + Event::handle('EndShowNoticeItemAuthor', array($this->profile, $this->out)); } - $this->out->elementEnd('a'); - - $this->out->elementEnd('span'); - - $this->showAddressees(); - - $this->out->elementEnd('div'); } function showAddressees() @@ -244,21 +215,16 @@ class NoticeListItem extends Widget $pa = $this->getProfileAddressees(); if (!empty($pa)) { - $this->out->elementStart('span', 'addressees'); + $this->out->elementStart('ul', 'addressees'); $first = true; foreach ($pa as $addr) { - if (!$first) { - // TRANS: Separator in profile addressees list. - $this->out->text(_m('SEPARATOR',', ')); - } else { - // Start of profile addressees list. - $first = false; - } + $this->out->elementStart('li', 'h-card'); $text = $addr['text']; unset($addr['text']); $this->out->element('a', $addr, $text); + $this->out->elementEnd('li'); } - $this->out->elementEnd('span', 'addressees'); + $this->out->elementEnd('ul', 'addressees'); } } @@ -268,16 +234,12 @@ class NoticeListItem extends Widget $attentions = $this->getReplyProfiles(); - $user = common_current_user(); - - $streamNicknames = !empty($user) && $user->streamNicknames(); - foreach ($attentions as $attn) { $class = $attn->isGroup() ? 'group' : 'account'; $pa[] = array('href' => $attn->profileurl, - 'title' => $attn->nickname, + 'title' => $attn->getNickname(), 'class' => "addressee {$class}", - 'text' => ($streamNicknames) ? $attn->nickname : $attn->getBestName()); + 'text' => $attn->getStreamName()); } return $pa; @@ -288,35 +250,6 @@ class NoticeListItem extends Widget return $this->notice->getReplyProfiles(); } - /** - * show the avatar of the notice's author - * - * This will use the default avatar if no avatar is assigned for the author. - * It makes a link to the author's profile. - * - * @return void - */ - function showAvatar() - { - $avatar_size = $this->avatarSize(); - - $avatarUrl = $this->profile->avatarUrl($avatar_size); - - $this->out->element('img', array('src' => $avatarUrl, - 'class' => 'avatar photo', - 'width' => $avatar_size, - 'height' => $avatar_size, - 'alt' => - ($this->profile->fullname) ? - $this->profile->fullname : - $this->profile->nickname)); - } - - function avatarSize() - { - return AVATAR_STREAM_SIZE; - } - /** * show the nickname of the author * @@ -326,8 +259,8 @@ class NoticeListItem extends Widget */ function showNickname() { - $this->out->raw('' . - htmlspecialchars($this->profile->nickname) . + $this->out->raw('' . + htmlspecialchars($this->profile->getNickname()) . ''); } @@ -343,16 +276,19 @@ class NoticeListItem extends Widget function showContent() { // FIXME: URL, image, video, audio - $this->out->elementStart('p', array('class' => 'entry-content')); - if ($this->notice->rendered) { - $this->out->raw($this->notice->rendered); - } else { - // XXX: may be some uncooked notices in the DB, - // we cook them right now. This should probably disappear in future - // versions (>> 0.4.x) - $this->out->raw(common_render_content($this->notice->content, $this->notice)); + $this->out->elementStart('div', array('class' => 'e-content')); + if (Event::handle('StartShowNoticeContent', array($this->notice, $this->out, $this->out->getScoped()))) { + if ($this->notice->rendered) { + $this->out->raw($this->notice->rendered); + } else { + // XXX: may be some uncooked notices in the DB, + // we cook them right now. This should probably disappear in future + // versions (>> 0.4.x) + $this->out->raw(common_render_content($this->notice->content, $this->notice)); + } + Event::handle('EndShowNoticeContent', array($this->notice, $this->out, $this->out->getScoped())); } - $this->out->elementEnd('p'); + $this->out->elementEnd('div'); } function showNoticeAttachments() { @@ -365,25 +301,19 @@ class NoticeListItem extends Widget /** * show the link to the main page for the notice * - * Displays a link to the page for a notice, with "relative" time. Tries to - * get remote notice URLs correct, but doesn't always succeed. + * Displays a local link to the rendered notice, with "relative" time. * * @return void */ function showNoticeLink() { - $noticeurl = $this->notice->bestUrl(); - - // above should always return an URL - - assert(!empty($noticeurl)); - $this->out->elementStart('a', array('rel' => 'bookmark', - 'class' => 'timestamp', - 'href' => $noticeurl)); - $dt = common_date_iso8601($this->notice->created); - $this->out->element('abbr', array('class' => 'published', - 'title' => $dt), + 'class' => 'u-url timestamp', + 'href' => Conversation::getUrlFromNotice($this->notice))); + $this->out->element('time', array('class' => 'dt-published', + 'datetime' => common_date_iso8601($this->notice->created), + // TRANS: Timestamp title (tooltip text) for NoticeListItem + 'title' => common_exact_date($this->notice->created)), common_date_string($this->notice->created)); $this->out->elementEnd('a'); } @@ -532,41 +462,19 @@ class NoticeListItem extends Widget } /** - * show link to notice this notice is a reply to + * show link to single-notice view for this notice item * - * If this notice is a reply, show a link to the notice it is replying to. The - * heavy lifting for figuring out replies happens at save time. + * A permalink that goes to this specific object and nothing else * * @return void */ - function showContext() + function showPermalink() { - if ($this->notice->hasConversation()) { - $conv = Conversation::getKV( - 'id', - $this->notice->conversation - ); - $convurl = $conv->uri; - if (!empty($convurl)) { - $this->out->text(' '); - $this->out->element( - 'a', - array( - 'href' => $convurl.'#notice-'.$this->notice->id, - 'class' => 'response'), - // TRANS: Addition in notice list item if notice is part of a conversation. - _('in context') - ); - } else { - $msg = sprintf( - "Couldn't find Conversation ID %d to make 'in context'" - . "link for Notice ID %d", - $this->notice->conversation, - $this->notice->id - ); - common_log(LOG_WARNING, $msg); - } - } + $this->out->element('a', + array('href' => $this->notice->getLocalUrl(), + 'class' => 'permalink'), + // TRANS: Addition in notice list item for single-notice view. + _('permalink')); } /** @@ -581,21 +489,15 @@ class NoticeListItem extends Widget $repeater = Profile::getKV('id', $this->repeat->profile_id); $attrs = array('href' => $repeater->profileurl, - 'class' => 'url'); + 'class' => 'h-card p-author', + 'title' => $repeater->getFancyName()); - if (!empty($repeater->fullname)) { - $attrs['title'] = $repeater->fullname . ' (' . $repeater->nickname . ')'; - } - - $this->out->elementStart('span', 'repeat vcard'); + $this->out->elementStart('span', 'repeat h-entry'); // TRANS: Addition in notice list item if notice was repeated. Followed by a span with a nickname. - $this->out->raw(_('Repeated by')); - $this->out->raw(' '); + $this->out->raw(_('Repeated by').' '); - $this->out->elementStart('a', $attrs); - $this->out->element('span', 'fn nickname', $repeater->nickname); - $this->out->elementEnd('a'); + $this->out->element('a', $attrs, $repeater->getNickname()); $this->out->elementEnd('span'); } @@ -614,7 +516,7 @@ class NoticeListItem extends Widget if (common_logged_in()) { $this->out->text(' '); $reply_url = common_local_url('newnotice', - array('replyto' => $this->profile->nickname, 'inreplyto' => $this->notice->id)); + array('replyto' => $this->profile->getNickname(), 'inreplyto' => $this->notice->id)); $this->out->elementStart('a', array('href' => $reply_url, 'class' => 'notice_reply', // TRANS: Link title in notice list item to reply to a notice.