]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/noticelistitem.php
No nickname in profile listing
[quix0rs-gnu-social.git] / lib / noticelistitem.php
index 08053bceb6b45cf4fa7645eccf48425ede628049..c05d8cdca9e1f92c10b7672b9f4e257b3ac53328 100644 (file)
  * @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, HTMLOutputter $out=null)
     {
         parent::__construct($out);
         if (!empty($notice->repeat_of)) {
-            $original = Notice::staticGet('id', $notice->repeat_of);
-            if (empty($original)) { // could have been deleted
+            $original = Notice::getKV('id', $notice->repeat_of);
+            if (!$original instanceof Notice) { // could have been deleted
                 $this->notice = $notice;
             } else {
                 $this->notice = $original;
@@ -117,20 +113,32 @@ class NoticeListItem extends Widget
 
     function showNotice()
     {
-        $this->out->elementStart('div', 'entry-title');
+        $this->showNoticeTitle();
         $this->showAuthor();
+        $this->showAddressees();
         $this->showContent();
-        $this->out->elementEnd('div');
+    }
+
+    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();
+            if ($this->notice->hasConversation()) {
+                $this->showContext();
+            }
             $this->showRepeat();
             Event::handle('EndShowNoticeInfo', array($this));
         }
@@ -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';
             }
@@ -211,100 +219,46 @@ 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());
-        }
+        $this->showAvatar($this->profile);
+        $this->out->text($this->profile->getStreamName());
         $this->out->elementEnd('a');
-
-        $this->out->elementEnd('span');
-
-        $this->showAddressees();
-
-        $this->out->elementEnd('div');
     }
 
     function showAddressees()
     {
-        $ga = $this->getGroupAddressees();
         $pa = $this->getProfileAddressees();
 
-        $a = array_merge($ga, $pa);
-
-        if (!empty($a)) {
-            $this->out->elementStart('span', 'addressees');
+        if (!empty($pa)) {
+            $this->out->elementStart('ul', 'addressees');
             $first = true;
-            foreach ($a as $addr) {
-                if (!$first) {
-                    // TRANS: Separator in profile addressees list.
-                    $this->out->text(_m('SEPARATOR',', '));
-                } else {
-                    // Start of profile addressees list.
-                    $first = false;
-                }
+            foreach ($pa as $addr) {
+                $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');
         }
     }
 
-    function getGroupAddressees()
-    {
-        $ga = array();
-
-        $groups = $this->getGroups();
-
-        $user = common_current_user();
-
-        $streamNicknames = !empty($user) && $user->streamNicknames();
-
-        foreach ($groups as $group) {
-            $ga[] = array('href' => $group->homeUrl(),
-                          'title' => $group->nickname,
-                          'class' => 'addressee group',
-                          'text' => ($streamNicknames) ? $group->nickname : $group->getBestName());
-        }
-
-        return $ga;
-    }
-
-    function getGroups()
-    {
-        return $this->notice->getGroups();
-    }
-
     function getProfileAddressees()
     {
         $pa = array();
 
-        $replies = $this->getReplyProfiles();
+        $attentions = $this->getReplyProfiles();
 
-        $user = common_current_user();
-
-        $streamNicknames = !empty($user) && $user->streamNicknames();
-
-        foreach ($replies as $reply) {
-            $pa[] = array('href' => $reply->profileurl,
-                          'title' => $reply->nickname,
-                          'class' => 'addressee account',
-                          'text' => ($streamNicknames) ? $reply->nickname : $reply->getBestName());
+        foreach ($attentions as $attn) {
+            $class = $attn->isGroup() ? 'group' : 'account';
+            $pa[] = array('href' => $attn->profileurl,
+                          'title' => $attn->getNickname(),
+                          'class' => "addressee {$class}",
+                          'text' => $attn->getStreamName());
         }
 
         return $pa;
@@ -315,37 +269,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();
-
-        $avatar = $this->profile->getAvatar($avatar_size);
-
-        $this->out->element('img', array('src' => ($avatar) ?
-                                         $avatar->displayUrl() :
-                                         Avatar::defaultImage($avatar_size),
-                                         '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
      *
@@ -355,8 +278,8 @@ class NoticeListItem extends Widget
      */
     function showNickname()
     {
-        $this->out->raw('<span class="nickname fn">' .
-                        htmlspecialchars($this->profile->nickname) .
+        $this->out->raw('<span class="p-name">' .
+                        htmlspecialchars($this->profile->getNickname()) .
                         '</span>');
     }
 
@@ -372,7 +295,7 @@ class NoticeListItem extends Widget
     function showContent()
     {
         // FIXME: URL, image, video, audio
-        $this->out->elementStart('p', array('class' => 'entry-content'));
+        $this->out->elementStart('div', array('class' => 'e-content'));
         if ($this->notice->rendered) {
             $this->out->raw($this->notice->rendered);
         } else {
@@ -381,7 +304,7 @@ class NoticeListItem extends Widget
             // versions (>> 0.4.x)
             $this->out->raw(common_render_content($this->notice->content, $this->notice));
         }
-        $this->out->elementEnd('p');
+        $this->out->elementEnd('div');
     }
 
     function showNoticeAttachments() {
@@ -394,25 +317,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' => $this->notice->getLocalUrl()));
+        $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');
     }
@@ -570,32 +487,11 @@ class NoticeListItem extends Widget
      */
     function showContext()
     {
-        if ($this->notice->hasConversation()) {
-            $conv = Conversation::staticGet(
-                '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->getConversationUrl(),
+                                  'class' => 'conversation'),
+                            // TRANS: Addition in notice list item if notice is part of a conversation.
+                            _('in context'));
     }
 
     /**
@@ -607,24 +503,18 @@ class NoticeListItem extends Widget
     {
         if (!empty($this->repeat)) {
 
-            $repeater = Profile::staticGet('id', $this->repeat->profile_id);
+            $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');
         }
@@ -643,7 +533,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.
@@ -695,7 +585,7 @@ class NoticeListItem extends Widget
                 $user->id != $this->notice->profile_id) {
                 $this->out->text(' ');
                 $profile = $user->getProfile();
-                if ($profile->hasRepeated($this->notice->id)) {
+                if ($profile->hasRepeated($this->notice)) {
                     $this->out->element('span', array('class' => 'repeated',
                                                       // TRANS: Title for repeat form status in notice list when a notice has been repeated.
                                                       'title' => _('Notice repeated.')),