summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorZach Copley <zach@status.net>2010-05-06 00:20:10 -0700
committerZach Copley <zach@status.net>2010-05-06 21:48:11 +0000
commit22fde00defe79a153ed77ddf6a4e63dd7fef6743 (patch)
tree2d17dd355e6a931c600115c0f9e6d37a7b2b108e /lib
parentb547079b280b9fa2f8877aab7ad5cd3761f500b9 (diff)
Refactor and centralize notice source link calculation
Diffstat (limited to 'lib')
-rw-r--r--lib/apiaction.php51
-rw-r--r--lib/noticelist.php56
2 files changed, 39 insertions, 68 deletions
diff --git a/lib/apiaction.php b/lib/apiaction.php
index a3c34a91b..8c4dc6c26 100644
--- a/lib/apiaction.php
+++ b/lib/apiaction.php
@@ -313,7 +313,19 @@ class ApiAction extends Action
$twitter_status['created_at'] = $this->dateTwitter($notice->created);
$twitter_status['in_reply_to_status_id'] = ($notice->reply_to) ?
intval($notice->reply_to) : null;
- $twitter_status['source'] = $this->sourceLink($notice->source);
+
+ $source = null;
+
+ $ns = $notice->getSource();
+ if ($ns) {
+ if (!empty($ns->name) && !empty($ns->url)) {
+ $source = '<a href="' . $ns->url . '">' . $ns->name . '</a>';
+ } else {
+ $source = $ns->code;
+ }
+ }
+
+ $twitter_status['source'] = $source;
$twitter_status['id'] = intval($notice->id);
$replier_profile = null;
@@ -1354,43 +1366,6 @@ class ApiAction extends Action
}
}
- function sourceLink($source)
- {
- $source_name = _($source);
- switch ($source) {
- case 'web':
- case 'xmpp':
- case 'mail':
- case 'omb':
- case 'api':
- break;
- default:
-
- $name = null;
- $url = null;
-
- $ns = Notice_source::staticGet($source);
-
- if ($ns) {
- $name = $ns->name;
- $url = $ns->url;
- } else {
- $app = Oauth_application::staticGet('name', $source);
- if ($app) {
- $name = $app->name;
- $url = $app->source_url;
- }
- }
-
- if (!empty($name) && !empty($url)) {
- $source_name = '<a href="' . $url . '">' . $name . '</a>';
- }
-
- break;
- }
- return $source_name;
- }
-
/**
* Returns query argument or default value if not found. Certain
* parameters used throughout the API are lightly scrubbed and
diff --git a/lib/noticelist.php b/lib/noticelist.php
index 5265326b2..c42e4fb60 100644
--- a/lib/noticelist.php
+++ b/lib/noticelist.php
@@ -488,48 +488,44 @@ class NoticeListItem extends Widget
function showNoticeSource()
{
- if ($this->notice->source) {
+ $ns = $this->notice->getSource();
+
+ if ($ns) {
+ $source_name = _($ns->code);
$this->out->text(' ');
$this->out->elementStart('span', 'source');
$this->out->text(_('from'));
- $source_name = _($this->notice->source);
$this->out->text(' ');
- switch ($this->notice->source) {
- case 'web':
- case 'xmpp':
- case 'mail':
- case 'omb':
- case 'system':
- case 'api':
- $this->out->element('span', 'device', $source_name);
- break;
- default:
- $name = $source_name;
- $url = null;
+ // if $ns->name and $ns->url are populated we have
+ // configured a source attr somewhere
+ if (empty($ns->name) && empty($ns->url)) {
+ // otherwise it's from normal channel such as web or api
+ $this->out->element('span', 'device', $source_name);
+ } else {
+ $name = null;
+ $url = null;
+ $title = null;
if (Event::handle('StartNoticeSourceLink', array($this->notice, &$name, &$url, &$title))) {
- $ns = Notice_source::staticGet($this->notice->source);
-
- if ($ns) {
- $name = $ns->name;
- $url = $ns->url;
- } else {
- $app = Oauth_application::staticGet('name', $this->notice->source);
- if ($app) {
- $name = $app->name;
- $url = $app->source_url;
- }
- }
+ $name = $source_name;
+ $url = $ns->url;
}
Event::handle('EndNoticeSourceLink', array($this->notice, &$name, &$url, &$title));
if (!empty($name) && !empty($url)) {
$this->out->elementStart('span', 'device');
- $this->out->element('a', array('href' => $url,
- 'rel' => 'external',
- 'title' => $title),
- $name);
+
+ $attrs = array(
+ 'href' => $url,
+ 'rel' => 'external'
+ );
+
+ if (isset($title)) {
+ $attrs['title'] = $title;
+ }
+
+ $this->out->element('a', $attrs, $name);
$this->out->elementEnd('span');
} else {
$this->out->element('span', 'device', $name);