]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/noticelist.php
Updated ShowGroup to Resolve Aliases Again.
[quix0rs-gnu-social.git] / lib / noticelist.php
index 4e5623ded60fee5ae43b52866b249af488025cec..28a563d875aff8c2e7ce621ba204ada667f9ee77 100644 (file)
@@ -147,6 +147,10 @@ class NoticeListItem extends Widget
 
     var $notice = null;
 
+    /** The notice that was repeated. */
+
+    var $repeat = null;
+
     /** The profile of the author of the notice, extracted once for convenience. */
 
     var $profile = null;
@@ -162,8 +166,18 @@ class NoticeListItem extends Widget
     function __construct($notice, $out=null)
     {
         parent::__construct($out);
-        $this->notice  = $notice;
-        $this->profile = $notice->getProfile();
+        if (!empty($notice->repeat_of)) {
+            $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;
+        }
+        $this->profile = $this->notice->getProfile();
     }
 
     /**
@@ -177,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();
@@ -199,9 +221,10 @@ class NoticeListItem extends Widget
     {
         $this->out->elementStart('div', 'entry-content');
         $this->showNoticeLink();
-        $this->showNoticeLocation();
         $this->showNoticeSource();
+        $this->showNoticeLocation();
         $this->showContext();
+        $this->showRepeat();
         $this->out->elementEnd('div');
     }
 
@@ -212,6 +235,7 @@ class NoticeListItem extends Widget
             $this->out->elementStart('div', 'notice-options');
             $this->showFaveForm();
             $this->showReplyLink();
+            $this->showRepeatForm();
             $this->showDeleteLink();
             $this->out->elementEnd('div');
         }
@@ -227,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));
     }
 
     /**
@@ -269,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');
@@ -347,19 +373,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 does not always succeed.
+     * get remote notice URLs correct, but doesn't always succeed.
      *
      * @return void
      */
 
     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));
@@ -392,20 +418,51 @@ class NoticeListItem extends Widget
 
         $name = $location->getName();
 
+        $lat = $this->notice->lat;
+        $lon = $this->notice->lon;
+        $latlon = (!empty($lat) && !empty($lon)) ? $lat.';'.$lon : '';
+
         if (empty($name)) {
-            // XXX: Could be a translation issue. Fall back to... something?
-            return;
+            $latdms = $this->decimalDegreesToDMS(abs($lat));
+            $londms = $this->decimalDegreesToDMS(abs($lon));
+            $name = sprintf(
+                _('%1$u°%2$u\'%3$u"%4$s %5$u°%6$u\'%7$u"%8$s'),
+                $latdms['deg'],$latdms['min'], $latdms['sec'],($lat>0?_('N'):_('S')),
+                $londms['deg'],$londms['min'], $londms['sec'],($lon>0?_('E'):_('W')));
         }
 
         $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' => 'location'), $name);
+            $this->out->element('abbr', array('class' => 'geo',
+                                              'title' => $latlon),
+                                $name);
         } else {
-            $this->out->element('a', array('class' => 'location',
-                                           'href' => $url),
+            $this->out->elementStart('a', array('href' => $url));
+            $this->out->element('abbr', array('class' => 'geo',
+                                              'title' => $latlon),
                                 $name);
+            $this->out->elementEnd('a');
         }
+        $this->out->elementEnd('span');
+    }
+
+    function decimalDegreesToDMS($dec)
+    {
+
+        $vars = explode(".",$dec);
+        $deg = $vars[0];
+        $tempma = "0.".$vars[1];
+
+        $tempma = $tempma * 3600;
+        $min = floor($tempma / 60);
+        $sec = $tempma - ($min*60);
+
+        return array("deg"=>$deg,"min"=>$min,"sec"=>$sec);
     }
 
     /**
@@ -420,9 +477,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':
@@ -433,15 +492,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;
             }
@@ -471,6 +550,7 @@ class NoticeListItem extends Widget
             }
         }
         if ($hasConversation){
+            $this->out->text(' ');
             $convurl = common_local_url('conversation',
                                          array('id' => $this->notice->conversation));
             $this->out->element('a', array('href' => $convurl.'#notice-'.$this->notice->id,
@@ -479,11 +559,42 @@ class NoticeListItem extends Widget
         }
     }
 
+    /**
+     * show a link to the author of repeat
+     *
+     * @return void
+     */
+
+    function showRepeat()
+    {
+        if (!empty($this->repeat)) {
+
+            $repeater = Profile::staticGet('id', $this->repeat->profile_id);
+
+            $attrs = array('href' => $repeater->profileurl,
+                           'class' => 'url');
+
+            if (!empty($repeater->fullname)) {
+                $attrs['title'] = $repeater->fullname . ' (' . $repeater->nickname . ')';
+            }
+
+            $this->out->elementStart('span', 'repeat vcard');
+
+            $this->out->raw(_('Repeated by'));
+
+            $this->out->elementStart('a', $attrs);
+            $this->out->element('span', 'fn nickname', $repeater->nickname);
+            $this->out->elementEnd('a');
+
+            $this->out->elementEnd('span');
+        }
+    }
+
     /**
      * show a link to reply to the current notice
      *
      * Should either do the reply in the current notice form (if available), or
-     * link out to the notice-posting form. A little flakey, does not always work.
+     * link out to the notice-posting form. A little flakey, doesn't always work.
      *
      * @return void
      */
@@ -491,12 +602,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');
         }
@@ -512,17 +625,42 @@ 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'));
         }
     }
 
+    /**
+     * show the form to repeat a notice
+     *
+     * @return void
+     */
+
+    function showRepeatForm()
+    {
+        $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->element('span', array('class' => 'repeated',
+                                                  'title' => _('Notice repeated')),
+                                            _('Repeated'));
+            } else {
+                $rf = new RepeatForm($this->out, $this->notice);
+                $rf->show();
+            }
+        }
+    }
+
     /**
      * finish the notice
      *