Notice_source checks in better code style

This commit is contained in:
Mikael Nordfeldth 2014-11-05 19:44:22 +01:00
parent 5e4f93cc7d
commit 7ea067a0dc
6 changed files with 96 additions and 89 deletions

View File

@ -339,7 +339,7 @@ class ApiSearchAtomAction extends ApiPrivateAuthAction
$source = null; $source = null;
$ns = $notice->getSource(); $ns = $notice->getSource();
if ($ns) { if ($ns instanceof Notice_source) {
if (!empty($ns->name) && !empty($ns->url)) { if (!empty($ns->name) && !empty($ns->url)) {
$source = '<a href="' $source = '<a href="'
. htmlspecialchars($ns->url) . htmlspecialchars($ns->url)

View File

@ -139,8 +139,11 @@ class Message extends Managed_DataObject
function getSource() function getSource()
{ {
if (empty($this->source)) {
return false;
}
$ns = new Notice_source(); $ns = new Notice_source();
if (!empty($this->source)) {
switch ($this->source) { switch ($this->source) {
case 'web': case 'web':
case 'xmpp': case 'xmpp':
@ -152,7 +155,7 @@ class Message extends Managed_DataObject
break; break;
default: default:
$ns = Notice_source::getKV($this->source); $ns = Notice_source::getKV($this->source);
if (!$ns) { if (!$ns instanceof Notice_source) {
$ns = new Notice_source(); $ns = new Notice_source();
$ns->code = $this->source; $ns->code = $this->source;
$app = Oauth_application::getKV('name', $this->source); $app = Oauth_application::getKV('name', $this->source);
@ -163,7 +166,6 @@ class Message extends Managed_DataObject
} }
break; break;
} }
}
return $ns; return $ns;
} }
@ -204,7 +206,7 @@ class Message extends Managed_DataObject
$source = $this->getSource(); $source = $this->getSource();
if ($source) { if ($source instanceof Notice_source) {
$act->generator = ActivityObject::fromNoticeSource($source); $act->generator = ActivityObject::fromNoticeSource($source);
} }

View File

@ -2407,8 +2407,11 @@ class Notice extends Managed_DataObject
*/ */
function getSource() function getSource()
{ {
if (empty($this->source)) {
return false;
}
$ns = new Notice_source(); $ns = new Notice_source();
if (!empty($this->source)) {
switch ($this->source) { switch ($this->source) {
case 'web': case 'web':
case 'xmpp': case 'xmpp':
@ -2431,7 +2434,7 @@ class Notice extends Managed_DataObject
} }
break; break;
} }
}
return $ns; return $ns;
} }

View File

@ -331,7 +331,7 @@ class ApiAction extends Action
$source = null; $source = null;
$ns = $notice->getSource(); $ns = $notice->getSource();
if ($ns) { if ($ns instanceof Notice_source) {
if (!empty($ns->name) && !empty($ns->url)) { if (!empty($ns->name) && !empty($ns->url)) {
$source = '<a href="' $source = '<a href="'
. htmlspecialchars($ns->url) . htmlspecialchars($ns->url)

View File

@ -264,7 +264,7 @@ class ResultItem
break; break;
default: default:
$ns = Notice_source::getKV($source); $ns = Notice_source::getKV($source);
if ($ns) { if ($ns instanceof Notice_source) {
$source_name = '<a href="' . $ns->url . '">' . $ns->name . '</a>'; $source_name = '<a href="' . $ns->url . '">' . $ns->name . '</a>';
} }
break; break;

View File

@ -417,7 +417,10 @@ class NoticeListItem extends Widget
{ {
$ns = $this->notice->getSource(); $ns = $this->notice->getSource();
if ($ns) { if (!$ns instanceof Notice_source) {
return false;
}
// TRANS: A possible notice source (web interface). // TRANS: A possible notice source (web interface).
$source_name = (empty($ns->name)) ? ($ns->code ? _($ns->code) : _m('SOURCE','web')) : _($ns->name); $source_name = (empty($ns->name)) ? ($ns->code ? _($ns->code) : _m('SOURCE','web')) : _($ns->name);
$this->out->text(' '); $this->out->text(' ');
@ -459,7 +462,6 @@ class NoticeListItem extends Widget
$this->out->elementEnd('span'); $this->out->elementEnd('span');
} }
}
/** /**
* show link to single-notice view for this notice item * show link to single-notice view for this notice item