From 7ea067a0dc0093d73bf512c85cc519646980f5a1 Mon Sep 17 00:00:00 2001 From: Mikael Nordfeldth Date: Wed, 5 Nov 2014 19:44:22 +0100 Subject: [PATCH] Notice_source checks in better code style --- actions/apisearchatom.php | 2 +- classes/Message.php | 44 +++++++++--------- classes/Notice.php | 51 +++++++++++---------- lib/apiaction.php | 2 +- lib/jsonsearchresultslist.php | 2 +- lib/noticelistitem.php | 84 ++++++++++++++++++----------------- 6 files changed, 96 insertions(+), 89 deletions(-) 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(' '); - - $name = $source_name; - $url = $ns->url; - $title = null; - - 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)); - - // 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'); - - $attrs = array( - 'href' => $url, - 'rel' => 'external' - ); - - 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'); + if (!$ns instanceof Notice_source) { + return false; } + + // 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(' '); + + $name = $source_name; + $url = $ns->url; + $title = null; + + 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)); + + // 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'); + + $attrs = array( + 'href' => $url, + 'rel' => 'external' + ); + + 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'); } /**