forked from GNUsocial/gnu-social
Notice_source checks in better code style
This commit is contained in:
parent
5e4f93cc7d
commit
7ea067a0dc
@ -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
|
|||||||
|
|
||||||
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
|
|||||||
|
|
||||||
$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
|
|||||||
*/
|
*/
|
||||||
function getSource()
|
function getSource()
|
||||||
{
|
{
|
||||||
$ns = new Notice_source();
|
if (empty($this->source)) {
|
||||||
if (!empty($this->source)) {
|
return false;
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$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;
|
return $ns;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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
|
|||||||
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
|
|||||||
{
|
{
|
||||||
$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;
|
|
||||||
$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');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user