]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/noticelistitem.php
Merge branch 'issue-326' into 'master'
[quix0rs-gnu-social.git] / lib / noticelistitem.php
index dc171409f41e8042040c38a174a242d3c0c9f3cd..5468310ea3d5c70e3487cc13a95fa1488571ee70 100644 (file)
@@ -64,6 +64,7 @@ class NoticeListItem extends Widget
     protected $options = true;
     protected $maxchars = 0;   // if <= 0 it means use full posts
     protected $item_tag = 'li';
+    protected $pa = null;
 
     /**
      * constructor
@@ -150,7 +151,19 @@ class NoticeListItem extends Widget
         $this->elementStart('section', array('class'=>'notice-headers'));
         $this->showNoticeTitle();
         $this->showAuthor();
-        if ($this->addressees) { $this->showAddressees(); }
+
+        if (!empty($this->notice->reply_to) || count($this->getProfileAddressees()) > 0) {
+            $this->elementStart('div', array('class' => 'parents'));
+            try {
+                $this->showParent();
+            } catch (NoParentNoticeException $e) {
+                // no parent notice
+            } catch (InvalidUrlException $e) {
+                // parent had an invalid URL so we can't show it
+            }
+            if ($this->addressees) { $this->showAddressees(); }
+            $this->elementEnd('div');
+        }
         $this->elementEnd('section');
     }
 
@@ -166,8 +179,9 @@ class NoticeListItem extends Widget
     function showNoticeTitle()
     {
         if (Event::handle('StartShowNoticeTitle', array($this))) {
-            $this->element('a', array('href' => $this->notice->getUrl(),
-                                      'class' => 'notice-title'),
+            $nameClass = $this->notice->getTitle(false) ? 'p-name ' : '';
+            $this->element('a', array('href' => $this->notice->getUri(),
+                                      'class' => $nameClass . 'u-uid'),
                            $this->notice->getTitle());
             Event::handle('EndShowNoticeTitle', array($this));
         }
@@ -176,6 +190,7 @@ class NoticeListItem extends Widget
     function showNoticeInfo()
     {
         if (Event::handle('StartShowNoticeInfo', array($this))) {
+            $this->showContextLink();
             $this->showNoticeLink();
             $this->showNoticeSource();
             $this->showNoticeLocation();
@@ -214,8 +229,10 @@ class NoticeListItem extends Widget
             if ($this->notice->scope != 0 && $this->notice->scope != 1) {
                 $class .= ' limited-scope';
             }
-            if (!empty($this->notice->source)) {
-                $class .= ' notice-source-'.$this->notice->source;
+            try {
+                $class .= ' notice-source-'.common_to_alphanumeric($this->notice->source);
+            } catch (Exception $e) {
+                // either source or what we filtered out was a zero-length string
             }
             $id_prefix = (strlen($this->id_prefix) ? $this->id_prefix . '-' : '');
             $this->out->elementStart($this->item_tag, array('class' => $class,
@@ -234,9 +251,10 @@ class NoticeListItem extends Widget
 
     function showAuthor()
     {
-        $attrs = array('href' => $this->profile->profileurl,
-                       'class' => 'h-card p-author',
-                       'title' => $this->profile->getNickname());
+        $attrs = array('href' => $this->profile->getUrl(),
+                       'class' => 'h-card',
+                       'title' => $this->profile->getHtmlTitle());
+        if(empty($this->repeat)) { $attrs['class'] .= ' p-author'; }
 
         if (Event::handle('StartShowNoticeItemAuthor', array($this->profile, $this->out, &$attrs))) {
             $this->out->elementStart('a', $attrs);
@@ -247,6 +265,19 @@ class NoticeListItem extends Widget
         }
     }
 
+    function showParent()
+    {
+        $this->out->element(
+            'a',
+            array(
+                'href' => $this->notice->getParent()->getUrl(),
+                'class' => 'u-in-reply-to',
+                'rel' => 'in-reply-to'
+            ),
+            'in reply to'
+        );
+    }
+
     function showAddressees()
     {
         $pa = $this->getProfileAddressees();
@@ -255,7 +286,7 @@ class NoticeListItem extends Widget
             $this->out->elementStart('ul', 'addressees');
             $first = true;
             foreach ($pa as $addr) {
-                $this->out->elementStart('li', 'h-card');
+                $this->out->elementStart('li');
                 $text = $addr['text'];
                 unset($addr['text']);
                 $this->out->element('a', $addr, $text);
@@ -267,24 +298,31 @@ class NoticeListItem extends Widget
 
     function getProfileAddressees()
     {
-        $pa = array();
+        if($this->pa) { return $this->pa; }
+        $this->pa = array();
 
-        $attentions = $this->getReplyProfiles();
+        $attentions = $this->getAttentionProfiles();
 
         foreach ($attentions as $attn) {
-            $class = $attn->isGroup() ? 'group' : 'account';
-            $pa[] = array('href' => $attn->profileurl,
-                          'title' => $attn->getNickname(),
-                          'class' => "addressee {$class}",
-                          'text' => $attn->getStreamName());
+            if ($attn->isGroup()) {
+                $class = 'group';
+                $profileurl = common_local_url('groupbyid', array('id' => $attn->getGroup()->getID()));
+            } else {
+                $class = 'account';
+                $profileurl = common_local_url('userbyid', array('id' => $attn->getID()));
+            }
+            $this->pa[] = array('href' => $profileurl,
+                                'title' => $attn->getHtmlTitle(),
+                                'class' => "addressee {$class} p-name u-url",
+                                'text' => $attn->getStreamName());
         }
 
-        return $pa;
+        return $this->pa;
     }
 
-    function getReplyProfiles()
+    function getAttentionProfiles()
     {
-        return $this->notice->getReplyProfiles();
+        return $this->notice->getAttentionProfiles();
     }
 
     /**
@@ -313,17 +351,13 @@ class NoticeListItem extends Widget
     function showContent()
     {
         // FIXME: URL, image, video, audio
-        $this->out->elementStart('article', array('class' => 'e-content'));
+        $nameClass = $this->notice->getTitle(false) ? '' : 'p-name ';
+        $this->out->elementStart('article', array('class' => $nameClass . 'e-content'));
         if (Event::handle('StartShowNoticeContent', array($this->notice, $this->out, $this->out->getScoped()))) {
             if ($this->maxchars > 0 && mb_strlen($this->notice->content) > $this->maxchars) {
                 $this->out->text(mb_substr($this->notice->content, 0, $this->maxchars) . '[…]');
-            } elseif ($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->raw($this->notice->getRendered());
             }
             Event::handle('EndShowNoticeContent', array($this->notice, $this->out, $this->out->getScoped()));
         }
@@ -346,15 +380,10 @@ class NoticeListItem extends Widget
      */
     function showNoticeLink()
     {
-        $this->out->elementStart('a', array('rel' => 'bookmark',
-                                            'class' => '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');
     }
 
     /**
@@ -368,7 +397,6 @@ class NoticeListItem extends Widget
      */
     function showNoticeLocation()
     {
-        return;
         try {
             $location = Notice_location::locFromStored($this->notice);
         } catch (NoResultException $e) {
@@ -516,9 +544,22 @@ class NoticeListItem extends Widget
         if (!$this->notice->isLocal()) {
             $class .= ' external';
         }
+
+        try {
+            if($this->repeat) {
+                $this->out->element('a',
+                            array('href' => $this->repeat->getUrl(),
+                                  'class' => 'u-url'),
+                            '');
+                $class = str_replace('u-url', 'u-repost-of', $class);
+            }
+        } catch (InvalidUrlException $e) {
+            // no permalink available
+        }
+
         try {
             $this->out->element('a',
-                        array('href' => $this->notice->getUrl(),
+                        array('href' => $this->notice->getUrl(true),
                               'class' => $class),
                         // TRANS: Addition in notice list item for single-notice view.
                         _('permalink'));
@@ -527,6 +568,18 @@ class NoticeListItem extends Widget
         }
     }
 
+    /**
+     * Show link to conversation view.
+     */
+    function showContextLink()
+    {
+        $this->out->element('a', array('rel' => 'bookmark',
+                                            'class' => 'timestamp',
+                                            'href' => Conversation::getUrlFromNotice($this->notice)),
+                            // TRANS: A link to the conversation view of a notice, on the local server.
+                            _('In conversation'));
+    }
+
     /**
      * show a link to reply to the current notice
      *