Commit 7ea067a0 authored by mmn's avatar mmn

Notice_source checks in better code style

parent 5e4f93cc
......@@ -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)
......
......@@ -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);
}
......
......@@ -2407,31 +2407,34 @@ class Notice 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) {
$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;
}
......
......@@ -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)
......
......@@ -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;
......
......@@ -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');
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment