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;
$ns = $notice->getSource();
if ($ns) {
if ($ns instanceof Notice_source) {
if (!empty($ns->name) && !empty($ns->url)) {
$source = '<a href="'
. htmlspecialchars($ns->url)

View File

@ -139,30 +139,32 @@ class Message extends Managed_DataObject
function getSource()
{
if (empty($this->source)) {
return false;
}
$ns = new Notice_source();
if (!empty($this->source)) {
switch ($this->source) {
case 'web':
case 'xmpp':
case 'mail':
case 'omb':
case 'system':
case 'api':
switch ($this->source) {
case 'web':
case 'xmpp':
case 'mail':
case 'omb':
case 'system':
case 'api':
$ns->code = $this->source;
break;
default:
$ns = Notice_source::getKV($this->source);
if (!$ns instanceof Notice_source) {
$ns = new Notice_source();
$ns->code = $this->source;
break;
default:
$ns = Notice_source::getKV($this->source);
if (!$ns) {
$ns = new Notice_source();
$ns->code = $this->source;
$app = Oauth_application::getKV('name', $this->source);
if ($app) {
$ns->name = $app->name;
$ns->url = $app->source_url;
}
$app = Oauth_application::getKV('name', $this->source);
if ($app) {
$ns->name = $app->name;
$ns->url = $app->source_url;
}
break;
}
break;
}
return $ns;
}
@ -204,7 +206,7 @@ class Message extends Managed_DataObject
$source = $this->getSource();
if ($source) {
if ($source instanceof Notice_source) {
$act->generator = ActivityObject::fromNoticeSource($source);
}

View File

@ -2407,31 +2407,34 @@ class Notice extends Managed_DataObject
*/
function getSource()
{
$ns = new Notice_source();
if (!empty($this->source)) {
switch ($this->source) {
case 'web':
case 'xmpp':
case 'mail':
case 'omb':
case 'system':
case 'api':
$ns->code = $this->source;
break;
default:
$ns = Notice_source::getKV($this->source);
if (!$ns) {
$ns = new Notice_source();
$ns->code = $this->source;
$app = Oauth_application::getKV('name', $this->source);
if ($app) {
$ns->name = $app->name;
$ns->url = $app->source_url;
}
}
break;
}
if (empty($this->source)) {
return false;
}
$ns = new Notice_source();
switch ($this->source) {
case 'web':
case 'xmpp':
case 'mail':
case 'omb':
case 'system':
case 'api':
$ns->code = $this->source;
break;
default:
$ns = Notice_source::getKV($this->source);
if (!$ns) {
$ns = new Notice_source();
$ns->code = $this->source;
$app = Oauth_application::getKV('name', $this->source);
if ($app) {
$ns->name = $app->name;
$ns->url = $app->source_url;
}
}
break;
}
return $ns;
}

View File

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

View File

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

View File

@ -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');
}
/**