X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=lib%2Fnoticelist.php;h=78abf34a76d512bb6fd289fbd6f4a5ce4fabf153;hb=794fe16d691b61ef06df6bca0a580460eafa4931;hp=d4cd3ff6e5d21caf08c05e00633f1ded4d00d997;hpb=b3b3af9a2eff10c272bb213eccd3dd3060bc5830;p=quix0rs-gnu-social.git diff --git a/lib/noticelist.php b/lib/noticelist.php index d4cd3ff6e5..78abf34a76 100644 --- a/lib/noticelist.php +++ b/lib/noticelist.php @@ -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,10 +191,21 @@ 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(); - $this->showNotice(); - $this->showNoticeInfo(); - $this->showNoticeOptions(); + if (Event::handle('StartShowNoticeItem', array($this))) { + $this->showNotice(); + $this->showNoticeInfo(); + $this->showNoticeOptions(); + Event::handle('EndShowNoticeItem', array($this)); + } $this->showEnd(); } @@ -197,7 +222,9 @@ class NoticeListItem extends Widget $this->out->elementStart('div', 'entry-content'); $this->showNoticeLink(); $this->showNoticeSource(); + $this->showNoticeLocation(); $this->showContext(); + $this->showRepeat(); $this->out->elementEnd('div'); } @@ -208,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'); } @@ -223,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)); } /** @@ -350,7 +379,7 @@ class NoticeListItem extends Widget function showNoticeLink() { - if($this->notice->is_local){ + if($this->notice->is_local == Notice::LOCAL_PUBLIC || $this->notice->is_local == Notice::LOCAL_NONPUBLIC){ $noticeurl = common_local_url('shownotice', array('notice' => $this->notice->id)); }else{ @@ -366,6 +395,72 @@ class NoticeListItem extends Widget $this->out->elementEnd('a'); } + /** + * show the notice location + * + * shows the notice location in the correct language. + * + * If an URL is available, makes a link. Otherwise, just a span. + * + * @return void + */ + + function showNoticeLocation() + { + $id = $this->notice->id; + + $location = $this->notice->getLocation(); + + if (empty($location)) { + return; + } + + $name = $location->getName(); + + $lat = $this->notice->lat; + $lon = $this->notice->lon; + $latlon = (!empty($lat) && !empty($lon)) ? $lat.';'.$lon : ''; + + if (empty($name)) { + $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->elementStart('span', array('class' => 'location')); + $this->out->text(_('at')); + if (empty($url)) { + $this->out->element('span', array('class' => 'geo', + 'title' => $latlon), + $name); + } else { + $this->out->element('a', array('class' => 'geo', + 'title' => $latlon, + 'href' => $url), + $name); + } + $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); + } + /** * Show the source of the notice * @@ -437,6 +532,40 @@ 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')); + + $avatar = $repeater->getAvatar(AVATAR_MINI_SIZE); + + $this->out->elementStart('a', $attrs); + + $this->out->element('span', 'nickname', $repeater->nickname); + $this->out->elementEnd('a'); + + $this->out->elementEnd('span'); + } + } + /** * show a link to reply to the current notice * @@ -469,15 +598,42 @@ class NoticeListItem extends Widget function showDeleteLink() { $user = common_current_user(); - if ($user && $this->notice->profile_id == $user->id) { + + $todel = (empty($this->repeat)) ? $this->notice : $this->repeat; + + if (!empty($user) && + ($todel->profile_id == $user->id || $user->hasRight(Right::DELETEOTHERSNOTICE))) { + $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) { + $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 *