We are no longer offering accounts on this server. Consider https://gitlab.freedesktop.org/ as a place to host projects.

Commit 7ea067a0 authored by mattl's avatar mattl

Notice_source checks in better code style

parent 5e4f93cc
...@@ -339,7 +339,7 @@ class ApiSearchAtomAction extends ApiPrivateAuthAction ...@@ -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)
......
...@@ -139,30 +139,32 @@ class Message extends Managed_DataObject ...@@ -139,30 +139,32 @@ 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': case 'mail':
case 'mail': case 'omb':
case 'omb': case 'system':
case 'system': case 'api':
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; $ns->code = $this->source;
break; $app = Oauth_application::getKV('name', $this->source);
default: if ($app) {
$ns = Notice_source::getKV($this->source); $ns->name = $app->name;
if (!$ns) { $ns->url = $app->source_url;
$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;
} }
break;
} }
return $ns; return $ns;
} }
...@@ -204,7 +206,7 @@ class Message extends Managed_DataObject ...@@ -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);
} }
......
...@@ -2407,31 +2407,34 @@ class Notice extends Managed_DataObject ...@@ -2407,31 +2407,34 @@ 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': case 'mail':
case 'mail': case 'omb':
case 'omb': case 'system':
case 'system': case 'api':
case 'api': $ns->code = $this->source;
break;
default:
$ns = Notice_source::getKV($this->source);
if (!$ns) {
$ns = new Notice_source();
$ns->code = $this->source; $ns->code = $this->source;
break; $app = Oauth_application::getKV('name', $this->source);
default: if ($app) {
$ns = Notice_source::getKV($this->source); $ns->name = $app->name;
if (!$ns) { $ns->url = $app->source_url;
$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;
} }
break;
} }
return $ns; return $ns;
} }
......
...@@ -331,7 +331,7 @@ class ApiAction extends Action ...@@ -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)
......
...@@ -264,7 +264,7 @@ class ResultItem ...@@ -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;
......
...@@ -417,48 +417,50 @@ class NoticeListItem extends Widget ...@@ -417,48 +417,50 @@ class NoticeListItem extends Widget
{ {
$ns = $this->notice->getSource(); $ns = $this->notice->getSource();
if ($ns) { if (!$ns instanceof Notice_source) {
// TRANS: A possible notice source (web interface). return false;
$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; // TRANS: A possible notice source (web interface).
$url = $ns->url; $source_name = (empty($ns->name)) ? ($ns->code ? _($ns->code) : _m('SOURCE','web')) : _($ns->name);
$title = null; $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;
$name = $source_name; $url = $ns->url;
$url = $ns->url; $title = null;
}
Event::handle('EndNoticeSourceLink', array($this->notice, &$name, &$url, &$title));
// if $ns->name and $ns->url are populated we have if (Event::handle('StartNoticeSourceLink', array($this->notice, &$name, &$url, &$title))) {
// configured a source attr somewhere $name = $source_name;
if (!empty($name) && !empty($url)) { $url = $ns->url;
$this->out->elementStart('span', 'device'); }
Event::handle('EndNoticeSourceLink', array($this->notice, &$name, &$url, &$title));
$attrs = array( // if $ns->name and $ns->url are populated we have
'href' => $url, // configured a source attr somewhere
'rel' => 'external' if (!empty($name) && !empty($url)) {
); $this->out->elementStart('span', 'device');
if (!empty($title)) { $attrs = array(
$attrs['title'] = $title; 'href' => $url,
} 'rel' => 'external'
);
$this->out->element('a', $attrs, $name); if (!empty($title)) {
$this->out->elementEnd('span'); $attrs['title'] = $title;
} else {
$this->out->element('span', 'device', $name);
} }
$this->out->element('a', $attrs, $name);
$this->out->elementEnd('span'); $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