From 5996d80c0918001f5c69f8d52681fc16aa003297 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Thu, 6 May 2010 21:29:04 +0000 Subject: [PATCH 1/9] Ticket #2184: recognize Palm Pre / WebOS browsers for MobileProfile One-line addition of 'webos' to the keywords list. --- plugins/MobileProfile/MobileProfilePlugin.php | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/MobileProfile/MobileProfilePlugin.php b/plugins/MobileProfile/MobileProfilePlugin.php index 1c61b4fe52..a3dc4de465 100644 --- a/plugins/MobileProfile/MobileProfilePlugin.php +++ b/plugins/MobileProfile/MobileProfilePlugin.php @@ -138,6 +138,7 @@ class MobileProfilePlugin extends WAP20Plugin 'vodafone', 'wap1', 'wap2', + 'webos', 'windows ce' ); From b547079b280b9fa2f8877aab7ad5cd3761f500b9 Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Wed, 5 May 2010 22:35:16 -0700 Subject: [PATCH 2/9] Add xmlns:statusnet and statusnet:notice_info element to Atom entries for notices --- classes/Notice.php | 17 +++++++++++++++-- lib/atomnoticefeed.php | 9 ++++++++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/classes/Notice.php b/classes/Notice.php index c0828674d1..e82a825268 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -1172,7 +1172,7 @@ class Notice extends Memcached_DataObject return $groups; } - function asAtomEntry($namespace=false, $source=false, $author=true) + function asAtomEntry($namespace=false, $source=false, $author=true, $cur=null) { $profile = $this->getProfile(); @@ -1185,7 +1185,8 @@ class Notice extends Memcached_DataObject 'xmlns:activity' => 'http://activitystrea.ms/spec/1.0/', 'xmlns:media' => 'http://purl.org/syndication/atommedia', 'xmlns:poco' => 'http://portablecontacts.net/spec/1.0', - 'xmlns:ostatus' => 'http://ostatus.org/schema/1.0'); + 'xmlns:ostatus' => 'http://ostatus.org/schema/1.0', + 'xmlns:statusnet' => 'http://status.net/ont/'); } else { $attrs = array(); } @@ -1211,6 +1212,18 @@ class Notice extends Memcached_DataObject $xs->element('icon', null, $profile->avatarUrl(AVATAR_PROFILE_SIZE)); $xs->element('updated', null, common_date_w3dtf($this->created)); + + $noticeInfoAttr = array( + 'local_id' => $this->id, // local notice ID (useful to clients for ordering) + 'source' => $this->source // the client name (source attribution) + // @todo source source_link + ); + + if (!empty($cur)) { + $noticeInfoAttr['favorited'] = ($cur->hasFave($this)) ? 'true' : 'false'; + } + + $xs->element('statusnet:notice_info', $noticeInfoAttr, null); } if ($source) { diff --git a/lib/atomnoticefeed.php b/lib/atomnoticefeed.php index e4df731fe0..35a45118ce 100644 --- a/lib/atomnoticefeed.php +++ b/lib/atomnoticefeed.php @@ -79,6 +79,11 @@ class AtomNoticeFeed extends Atom10Feed 'ostatus', 'http://ostatus.org/schema/1.0' ); + + $this->addNamespace( + 'statusnet', + 'http://status.net/ont/' + ); } /** @@ -110,7 +115,9 @@ class AtomNoticeFeed extends Atom10Feed $source = $this->showSource(); $author = $this->showAuthor(); - $this->addEntryRaw($notice->asAtomEntry(false, $source, $author)); + $cur = common_current_user(); + + $this->addEntryRaw($notice->asAtomEntry(false, $source, $author, $cur)); } function showSource() From 22fde00defe79a153ed77ddf6a4e63dd7fef6743 Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Thu, 6 May 2010 00:20:10 -0700 Subject: [PATCH 3/9] Refactor and centralize notice source link calculation --- actions/twitapisearchatom.php | 15 ++++++++-- classes/Notice.php | 39 +++++++++++++++++++++++- lib/apiaction.php | 51 ++++++++----------------------- lib/noticelist.php | 56 ++++++++++++++++------------------- 4 files changed, 90 insertions(+), 71 deletions(-) diff --git a/actions/twitapisearchatom.php b/actions/twitapisearchatom.php index 24aa619bd7..3eb54ccc36 100644 --- a/actions/twitapisearchatom.php +++ b/actions/twitapisearchatom.php @@ -342,10 +342,21 @@ class TwitapisearchatomAction extends ApiAction 'rel' => 'related', 'href' => $profile->avatarUrl())); - // TODO: Here is where we'd put in a link to an atom feed for threads + // @todo: Here is where we'd put in a link to an atom feed for threads + + $source = null; + + $ns = $notice->getSource(); + if ($ns) { + if (!empty($ns->name) && !empty($ns->url)) { + $source = '' . $ns->name . ''; + } else { + $source = $ns->code; + } + } $this->element("twitter:source", null, - htmlentities($this->sourceLink($notice->source))); + htmlentities($source)); $this->elementStart('author'); diff --git a/classes/Notice.php b/classes/Notice.php index e82a825268..cd27376a4a 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -704,7 +704,7 @@ class Notice extends Memcached_DataObject /** * Is this notice part of an active conversation? - * + * * @return boolean true if other messages exist in the same * conversation, false if this is the only one */ @@ -1812,4 +1812,41 @@ class Notice extends Memcached_DataObject return $result; } + + /** + * Get the source of the notice + * + * @return Notice_source $ns A notice source object. 'code' is the only attribute + * guaranteed to be populated. + */ + 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::staticGet($this->source); + if (!$ns) { + $ns = new Notice_source(); + $ns->code = $this->source; + $app = Oauth_application::staticGet('name', $this->source); + if ($app) { + $ns->name = $app->name; + $ns->url = $app->source_url; + } + } + break; + } + } + return $ns; + } + } diff --git a/lib/apiaction.php b/lib/apiaction.php index a3c34a91bf..8c4dc6c262 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 = '' . $ns->name . ''; + } 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 = '' . $name . ''; - } - - 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 5265326b27..c42e4fb600 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); From 292ea33dbddeee881474b8f98507213a7d8c159c Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Thu, 6 May 2010 00:44:56 -0700 Subject: [PATCH 4/9] Add source link attr to statusnet:notice_info element in Atom output for notices --- classes/Notice.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/classes/Notice.php b/classes/Notice.php index cd27376a4a..b3cfb28138 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -1216,8 +1216,14 @@ class Notice extends Memcached_DataObject $noticeInfoAttr = array( 'local_id' => $this->id, // local notice ID (useful to clients for ordering) 'source' => $this->source // the client name (source attribution) - // @todo source source_link - ); + ); + + $ns = $this->getSource(); + if ($ns) { + if (!empty($ns->url)) { + $noticeInfoAttr['source_link'] = htmlentities($ns->url); + } + } if (!empty($cur)) { $noticeInfoAttr['favorited'] = ($cur->hasFave($this)) ? 'true' : 'false'; From 209fd12cd033c62619c68ac17a4fa70b1e981169 Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Thu, 6 May 2010 00:55:17 -0700 Subject: [PATCH 5/9] HTML entity encode source link URLs in plain XML output and add rel="nofollow" to them --- actions/twitapisearchatom.php | 2 +- lib/apiaction.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/actions/twitapisearchatom.php b/actions/twitapisearchatom.php index 3eb54ccc36..6c740c4902 100644 --- a/actions/twitapisearchatom.php +++ b/actions/twitapisearchatom.php @@ -349,7 +349,7 @@ class TwitapisearchatomAction extends ApiAction $ns = $notice->getSource(); if ($ns) { if (!empty($ns->name) && !empty($ns->url)) { - $source = '' . $ns->name . ''; + $source = '' . $ns->name . ''; } else { $source = $ns->code; } diff --git a/lib/apiaction.php b/lib/apiaction.php index 8c4dc6c262..2608be227a 100644 --- a/lib/apiaction.php +++ b/lib/apiaction.php @@ -319,13 +319,13 @@ class ApiAction extends Action $ns = $notice->getSource(); if ($ns) { if (!empty($ns->name) && !empty($ns->url)) { - $source = '' . $ns->name . ''; + $source = '' . $ns->name . ''; } else { $source = $ns->code; } } - $twitter_status['source'] = $source; + $twitter_status['source'] = htmlentities($source); $twitter_status['id'] = intval($notice->id); $replier_profile = null; From ce177400f876a1e48f38ef18635d5ecf486a6867 Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Thu, 6 May 2010 19:52:25 +0000 Subject: [PATCH 6/9] - OStatusPlugin should return true if it doesn't need to handle source attribution - Remove stray break statement from NoticeList --- lib/noticelist.php | 1 - plugins/OStatus/OStatusPlugin.php | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/noticelist.php b/lib/noticelist.php index c42e4fb600..c7dc9d29d9 100644 --- a/lib/noticelist.php +++ b/lib/noticelist.php @@ -530,7 +530,6 @@ class NoticeListItem extends Widget } else { $this->out->element('span', 'device', $name); } - break; } $this->out->elementEnd('span'); } diff --git a/plugins/OStatus/OStatusPlugin.php b/plugins/OStatus/OStatusPlugin.php index f183bc7aea..d3a92755cc 100644 --- a/plugins/OStatus/OStatusPlugin.php +++ b/plugins/OStatus/OStatusPlugin.php @@ -452,6 +452,7 @@ class OStatusPlugin extends Plugin return false; } } + return true; } /** From ee8c9d142251566f87ee0780b5788549cc0a0c12 Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Thu, 6 May 2010 20:25:20 +0000 Subject: [PATCH 7/9] Allow OStatusPlugin to set the source attribution title --- lib/noticelist.php | 57 ++++++++++++++++++++++------------------------ 1 file changed, 27 insertions(+), 30 deletions(-) diff --git a/lib/noticelist.php b/lib/noticelist.php index c7dc9d29d9..432ea78d5b 100644 --- a/lib/noticelist.php +++ b/lib/noticelist.php @@ -497,40 +497,37 @@ class NoticeListItem extends Widget $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($ns->name) && empty($ns->url)) { - // otherwise it's from normal channel such as web or api - $this->out->element('span', 'device', $source_name); + 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 { - $name = null; - $url = null; - $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 (!empty($name) && !empty($url)) { - $this->out->elementStart('span', 'device'); - - $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); - } + $this->out->element('span', 'device', $name); } + $this->out->elementEnd('span'); } } From 869bc32d0d8cd68d75483e33c62d8ea9f1cc8e2c Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Thu, 6 May 2010 21:36:13 +0000 Subject: [PATCH 8/9] Remove errant double HTML entity encoding in API source attribution --- actions/twitapisearchatom.php | 9 ++++++--- classes/Notice.php | 2 +- lib/apiaction.php | 8 ++++++-- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/actions/twitapisearchatom.php b/actions/twitapisearchatom.php index 6c740c4902..51e8a8881b 100644 --- a/actions/twitapisearchatom.php +++ b/actions/twitapisearchatom.php @@ -349,14 +349,17 @@ class TwitapisearchatomAction extends ApiAction $ns = $notice->getSource(); if ($ns) { if (!empty($ns->name) && !empty($ns->url)) { - $source = '' . $ns->name . ''; + $source = '' + . htmlspecialchars($ns->name) + . ''; } else { $source = $ns->code; } } - $this->element("twitter:source", null, - htmlentities($source)); + $this->element("twitter:source", null, $source); $this->elementStart('author'); diff --git a/classes/Notice.php b/classes/Notice.php index b3cfb28138..875bcaa020 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -1221,7 +1221,7 @@ class Notice extends Memcached_DataObject $ns = $this->getSource(); if ($ns) { if (!empty($ns->url)) { - $noticeInfoAttr['source_link'] = htmlentities($ns->url); + $noticeInfoAttr['source_link'] = $ns->url; } } diff --git a/lib/apiaction.php b/lib/apiaction.php index 2608be227a..42aa08ef7d 100644 --- a/lib/apiaction.php +++ b/lib/apiaction.php @@ -319,13 +319,17 @@ class ApiAction extends Action $ns = $notice->getSource(); if ($ns) { if (!empty($ns->name) && !empty($ns->url)) { - $source = '' . $ns->name . ''; + $source = '' + . htmlspecialchars($ns->name) + . ''; } else { $source = $ns->code; } } - $twitter_status['source'] = htmlentities($source); + $twitter_status['source'] = $source; $twitter_status['id'] = intval($notice->id); $replier_profile = null; From 79153869505c9bfb41b7e49b757f233dc19530bb Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Fri, 7 May 2010 01:28:37 +0000 Subject: [PATCH 9/9] Allow plugins to load their styles for mobile view; fixes bad realtime button layout --- plugins/MobileProfile/MobileProfilePlugin.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/plugins/MobileProfile/MobileProfilePlugin.php b/plugins/MobileProfile/MobileProfilePlugin.php index a3dc4de465..6076bbde0b 100644 --- a/plugins/MobileProfile/MobileProfilePlugin.php +++ b/plugins/MobileProfile/MobileProfilePlugin.php @@ -255,6 +255,10 @@ class MobileProfilePlugin extends WAP20Plugin $action->cssLink('plugins/MobileProfile/mp-handheld.css',null,'handheld'); } + // Allow other plugins to load their styles. + Event::handle('EndShowStatusNetStyles', array($action)); + Event::handle('EndShowLaconicaStyles', array($action)); + return false; }