From: Mikael Nordfeldth Date: Wed, 5 Nov 2014 18:44:22 +0000 (+0100) Subject: Notice_source checks in better code style X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=7ea067a0dc0093d73bf512c85cc519646980f5a1;p=quix0rs-gnu-social.git Notice_source checks in better code style --- diff --git a/actions/apisearchatom.php b/actions/apisearchatom.php index fdf95f1ce9..b686edb00a 100644 --- a/actions/apisearchatom.php +++ b/actions/apisearchatom.php @@ -339,7 +339,7 @@ class ApiSearchAtomAction extends ApiPrivateAuthAction $source = null; $ns = $notice->getSource(); - if ($ns) { + if ($ns instanceof Notice_source) { if (!empty($ns->name) && !empty($ns->url)) { $source = 'url) diff --git a/lib/jsonsearchresultslist.php b/lib/jsonsearchresultslist.php index 357ab9be5d..0f764a72be 100644 --- a/lib/jsonsearchresultslist.php +++ b/lib/jsonsearchresultslist.php @@ -264,7 +264,7 @@ class ResultItem break; default: $ns = Notice_source::getKV($source); - if ($ns) { + if ($ns instanceof Notice_source) { $source_name = '' . $ns->name . ''; } break; diff --git a/lib/noticelistitem.php b/lib/noticelistitem.php index 81fcb72caa..d12a584022 100644 --- a/lib/noticelistitem.php +++ b/lib/noticelistitem.php @@ -417,48 +417,50 @@ class NoticeListItem extends Widget { $ns = $this->notice->getSource(); - if ($ns) { - // TRANS: A possible notice source (web interface). - $source_name = (empty($ns->name)) ? ($ns->code ? _($ns->code) : _m('SOURCE','web')) : _($ns->name); - $this->out->text(' '); - $this->out->elementStart('span', 'source'); - // @todo FIXME: probably i18n issue. If "from" is followed by text, that should be a parameter to "from" (from %s). - // TRANS: Followed by notice source. - $this->out->text(_('from')); - $this->out->text(' '); + if (!$ns instanceof Notice_source) { + return false; + } - $name = $source_name; - $url = $ns->url; - $title = null; + // TRANS: A possible notice source (web interface). + $source_name = (empty($ns->name)) ? ($ns->code ? _($ns->code) : _m('SOURCE','web')) : _($ns->name); + $this->out->text(' '); + $this->out->elementStart('span', 'source'); + // @todo FIXME: probably i18n issue. If "from" is followed by text, that should be a parameter to "from" (from %s). + // TRANS: Followed by notice source. + $this->out->text(_('from')); + $this->out->text(' '); - if (Event::handle('StartNoticeSourceLink', array($this->notice, &$name, &$url, &$title))) { - $name = $source_name; - $url = $ns->url; - } - Event::handle('EndNoticeSourceLink', array($this->notice, &$name, &$url, &$title)); + $name = $source_name; + $url = $ns->url; + $title = null; - // if $ns->name and $ns->url are populated we have - // configured a source attr somewhere - if (!empty($name) && !empty($url)) { - $this->out->elementStart('span', 'device'); + if (Event::handle('StartNoticeSourceLink', array($this->notice, &$name, &$url, &$title))) { + $name = $source_name; + $url = $ns->url; + } + Event::handle('EndNoticeSourceLink', array($this->notice, &$name, &$url, &$title)); - $attrs = array( - 'href' => $url, - 'rel' => 'external' - ); + // if $ns->name and $ns->url are populated we have + // configured a source attr somewhere + if (!empty($name) && !empty($url)) { + $this->out->elementStart('span', 'device'); - if (!empty($title)) { - $attrs['title'] = $title; - } + $attrs = array( + 'href' => $url, + 'rel' => 'external' + ); - $this->out->element('a', $attrs, $name); - $this->out->elementEnd('span'); - } else { - $this->out->element('span', 'device', $name); + if (!empty($title)) { + $attrs['title'] = $title; } + $this->out->element('a', $attrs, $name); $this->out->elementEnd('span'); + } else { + $this->out->element('span', 'device', $name); } + + $this->out->elementEnd('span'); } /**