]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/noticelist.php
Merge branch 'testing' into 0.9.x
[quix0rs-gnu-social.git] / lib / noticelist.php
index 7319a62ea76f7961b07f428256f8a222c7f90d6e..0d4cd4dd91c7d87ab68a89065be58121b1f345fc 100644 (file)
@@ -167,8 +167,13 @@ class NoticeListItem extends Widget
     {
         parent::__construct($out);
         if (!empty($notice->repeat_of)) {
-            $this->notice = Notice::staticGet('id', $notice->repeat_of);
-            $this->repeat = $notice;
+            $original = Notice::staticGet('id', $notice->repeat_of);
+            if (empty($original)) { // could have been deleted
+                $this->notice = $notice;
+            } else {
+                $this->notice = $original;
+                $this->repeat = $notice;
+            }
         } else {
             $this->notice  = $notice;
         }
@@ -186,6 +191,14 @@ class NoticeListItem extends Widget
 
     function show()
     {
+        if (empty($this->notice)) {
+            common_log(LOG_WARNING, "Trying to show missing notice; skipping.");
+            return;
+        } else if (empty($this->profile)) {
+            common_log(LOG_WARNING, "Trying to show missing profile (" . $this->notice->profile_id . "); skipping.");
+            return;
+        }
+
         $this->showStart();
         if (Event::handle('StartShowNoticeItem', array($this))) {
             $this->showNotice();
@@ -238,8 +251,9 @@ class NoticeListItem extends Widget
     {
         // XXX: RDFa
         // TODO: add notice_type class e.g., notice_video, notice_image
+        $id = (empty($this->repeat)) ? $this->notice->id : $this->repeat->id;
         $this->out->elementStart('li', array('class' => 'hentry notice',
-                                             'id' => 'notice-' . $this->notice->id));
+                                             'id' => 'notice-' . $id));
     }
 
     /**
@@ -280,6 +294,7 @@ class NoticeListItem extends Widget
         }
         $this->out->elementStart('a', $attrs);
         $this->showAvatar();
+        $this->out->text(' ');
         $this->showNickname();
         $this->out->elementEnd('a');
         $this->out->elementEnd('span');
@@ -365,12 +380,12 @@ class NoticeListItem extends Widget
 
     function showNoticeLink()
     {
-        if($this->notice->is_local){
-            $noticeurl = common_local_url('shownotice',
-                                      array('notice' => $this->notice->id));
-        }else{
-            $noticeurl = $this->notice->uri;
-        }
+        $noticeurl = $this->notice->bestUrl();
+
+        // above should always return an URL
+
+        assert(!empty($noticeurl));
+
         $this->out->elementStart('a', array('rel' => 'bookmark',
                                             'class' => 'timestamp',
                                             'href' => $noticeurl));
@@ -418,17 +433,23 @@ class NoticeListItem extends Widget
 
         $url  = $location->getUrl();
 
+        $this->out->text(' ');
         $this->out->elementStart('span', array('class' => 'location'));
         $this->out->text(_('at'));
+        $this->out->text(' ');
         if (empty($url)) {
-            $this->out->element('span', array('class' => 'geo',
+            $this->out->element('abbr', array('class' => 'geo',
                                               'title' => $latlon),
                                 $name);
         } else {
-            $this->out->element('a', array('class' => 'geo',
-                                           'title' => $latlon,
-                                           'href' => $url),
-                                $name);
+            $xstr = new XMLStringer(false);
+            $xstr->elementStart('a', array('href' => $url,
+                                           'rel' => 'external'));
+            $xstr->element('abbr', array('class' => 'geo',
+                                         'title' => $latlon),
+                           $name);
+            $xstr->elementEnd('a');
+            $this->out->raw($xstr->getString());
         }
         $this->out->elementEnd('span');
     }
@@ -459,9 +480,11 @@ class NoticeListItem extends Widget
     function showNoticeSource()
     {
         if ($this->notice->source) {
+            $this->out->text(' ');
             $this->out->elementStart('span', 'source');
             $this->out->text(_('from'));
             $source_name = _($this->notice->source);
+            $this->out->text(' ');
             switch ($this->notice->source) {
              case 'web':
              case 'xmpp':
@@ -472,15 +495,35 @@ class NoticeListItem extends Widget
                 $this->out->element('span', 'device', $source_name);
                 break;
              default:
-                $ns = Notice_source::staticGet($this->notice->source);
-                if ($ns) {
+
+                $name = $source_name;
+                $url  = null;
+
+                if (Event::handle('StartNoticeSourceLink', array($this->notice, &$name, &$url, &$title))) {
+                    $ns = Notice_source::staticGet($this->notice->source);
+
+                    if ($ns) {
+                        $name = $ns->name;
+                        $url  = $ns->url;
+                    } else {
+                        $app = Oauth_application::staticGet('name', $this->notice->source);
+                        if ($app) {
+                            $name = $app->name;
+                            $url  = $app->source_url;
+                        }
+                    }
+                }
+                Event::handle('EndNoticeSourceLink', array($this->notice, &$name, &$url, &$title));
+
+                if (!empty($name) && !empty($url)) {
                     $this->out->elementStart('span', 'device');
-                    $this->out->element('a', array('href' => $ns->url,
-                                                   'rel' => 'external'),
-                                        $ns->name);
+                    $this->out->element('a', array('href' => $url,
+                                                   'rel' => 'external',
+                                                   'title' => $title),
+                                        $name);
                     $this->out->elementEnd('span');
                 } else {
-                    $this->out->element('span', 'device', $source_name);
+                    $this->out->element('span', 'device', $name);
                 }
                 break;
             }
@@ -500,21 +543,40 @@ class NoticeListItem extends Widget
     function showContext()
     {
         $hasConversation = false;
-        if( !empty($this->notice->conversation)
-            && $this->notice->conversation != $this->notice->id){
-            $hasConversation = true;
-        }else{
-            $conversation = Notice::conversationStream($this->notice->id, 1, 1);
-            if($conversation->N > 0){
+        if (!empty($this->notice->conversation)) {
+            $conversation = Notice::conversationStream(
+                $this->notice->conversation,
+                1,
+                1
+            );
+            if ($conversation->N > 0) {
                 $hasConversation = true;
             }
         }
-        if ($hasConversation){
-            $convurl = common_local_url('conversation',
-                                         array('id' => $this->notice->conversation));
-            $this->out->element('a', array('href' => $convurl.'#notice-'.$this->notice->id,
-                                           'class' => 'response'),
-                                _('in context'));
+        if ($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'),
+                    _('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);
+            }
         }
     }
 
@@ -537,29 +599,14 @@ class NoticeListItem extends Widget
                 $attrs['title'] = $repeater->fullname . ' (' . $repeater->nickname . ')';
             }
 
-            $this->out->elementStart('span', 'repeat');
-
-            $this->out->elementStart('a', $attrs);
-
-            $avatar = $repeater->getAvatar(AVATAR_MINI_SIZE);
+            $this->out->elementStart('span', 'repeat vcard');
 
-            $this->out->element('img', array('src' => ($avatar) ?
-                                             $avatar->displayUrl() :
-                                             Avatar::defaultImage(AVATAR_MINI_SIZE),
-                                             'class' => 'avatar photo',
-                                             'width' => AVATAR_MINI_SIZE,
-                                             'height' => AVATAR_MINI_SIZE,
-                                             'alt' =>
-                                             ($repeater->fullname) ?
-                                             $repeater->fullname :
-                                             $repeater->nickname));
+            $this->out->raw(_('Repeated by'));
 
+            $this->out->elementStart('a', $attrs);
+            $this->out->element('span', 'fn nickname', $repeater->nickname);
             $this->out->elementEnd('a');
 
-            $text_link = XMLStringer::estring('a', $attrs, $repeater->nickname);
-
-            $this->out->raw(sprintf(_('Repeated by %s'), $text_link));
-
             $this->out->elementEnd('span');
         }
     }
@@ -576,12 +623,14 @@ class NoticeListItem extends Widget
     function showReplyLink()
     {
         if (common_logged_in()) {
+            $this->out->text(' ');
             $reply_url = common_local_url('newnotice',
                                           array('replyto' => $this->profile->nickname, 'inreplyto' => $this->notice->id));
             $this->out->elementStart('a', array('href' => $reply_url,
                                                 'class' => 'notice_reply',
                                                 'title' => _('Reply to this notice')));
             $this->out->text(_('Reply'));
+            $this->out->text(' ');
             $this->out->element('span', 'notice_id', $this->notice->id);
             $this->out->elementEnd('a');
         }
@@ -597,11 +646,13 @@ class NoticeListItem extends Widget
     {
         $user = common_current_user();
 
-        if (!empty($user) &&
-            ($this->notice->profile_id == $user->id || $user->hasRight(Right::DELETEOTHERSNOTICE))) {
+        $todel = (empty($this->repeat)) ? $this->notice : $this->repeat;
 
+        if (!empty($user) &&
+            ($todel->profile_id == $user->id || $user->hasRight(Right::DELETEOTHERSNOTICE))) {
+            $this->out->text(' ');
             $deleteurl = common_local_url('deletenotice',
-                                          array('notice' => $this->notice->id));
+                                          array('notice' => $todel->id));
             $this->out->element('a', array('href' => $deleteurl,
                                            'class' => 'notice_delete',
                                            'title' => _('Delete this notice')), _('Delete'));
@@ -618,9 +669,12 @@ class NoticeListItem extends Widget
     {
         $user = common_current_user();
         if ($user && $user->id != $this->notice->profile_id) {
+            $this->out->text(' ');
             $profile = $user->getProfile();
             if ($profile->hasRepeated($this->notice->id)) {
-                $this->out->text(_('Repeated'));
+                $this->out->element('span', array('class' => 'repeated',
+                                                  'title' => _('Notice repeated')),
+                                            _('Repeated'));
             } else {
                 $rf = new RepeatForm($this->out, $this->notice);
                 $rf->show();