summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorBrion Vibber <brion@pobox.com>2010-02-08 14:06:36 -0800
committerBrion Vibber <brion@pobox.com>2010-02-08 14:58:12 -0800
commit384387c9b05aefb438f5dbe7e272b1f234ede172 (patch)
tree7ac5935467b748c98782800846165b864a3588f7 /plugins
parentdc09453a77f33c4dfdff306321ce93cf5fbd2d57 (diff)
OStatus cleanup...
* Treat linkless feed posts as status updates; drop the "New post:" prefix and quotes on them. * Use stable user IDs for atom/rss2 feed links instead of unstable nicknames * Pull Atom feed preferentially when subscribing -- can now put the remote user's profile page straight into the feed subscription form and get to the right place. * Clean up naming for push endpoints
Diffstat (limited to 'plugins')
-rw-r--r--plugins/OStatus/OStatusPlugin.php8
-rw-r--r--plugins/OStatus/actions/pushcallback.php (renamed from plugins/OStatus/actions/feedsubcallback.php)2
-rw-r--r--plugins/OStatus/actions/pushhub.php (renamed from plugins/OStatus/actions/hub.php)2
-rw-r--r--plugins/OStatus/classes/Feedinfo.php2
-rw-r--r--plugins/OStatus/lib/feeddiscovery.php22
-rw-r--r--plugins/OStatus/lib/feedmunger.php47
6 files changed, 52 insertions, 31 deletions
diff --git a/plugins/OStatus/OStatusPlugin.php b/plugins/OStatus/OStatusPlugin.php
index 941912112..4e8b892c6 100644
--- a/plugins/OStatus/OStatusPlugin.php
+++ b/plugins/OStatus/OStatusPlugin.php
@@ -53,10 +53,10 @@ class OStatusPlugin extends Plugin
*/
function onRouterInitialized($m)
{
- $m->connect('push/hub', array('action' => 'hub'));
+ $m->connect('main/push/hub', array('action' => 'pushhub'));
- $m->connect('feedsub/callback/:feed',
- array('action' => 'feedsubcallback'),
+ $m->connect('main/push/callback/:feed',
+ array('action' => 'pushcallback'),
array('feed' => '[0-9]+'));
$m->connect('settings/feedsub',
array('action' => 'feedsubsettings'));
@@ -97,7 +97,7 @@ class OStatusPlugin extends Plugin
// Canonical form of id in URL?
// Updates will be handled for our internal PuSH hub.
$action->element('link', array('rel' => 'hub',
- 'href' => common_local_url('hub')));
+ 'href' => common_local_url('pushhub')));
}
}
return true;
diff --git a/plugins/OStatus/actions/feedsubcallback.php b/plugins/OStatus/actions/pushcallback.php
index c57ea5b10..a5e02e08f 100644
--- a/plugins/OStatus/actions/feedsubcallback.php
+++ b/plugins/OStatus/actions/pushcallback.php
@@ -25,7 +25,7 @@
if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
-class FeedSubCallbackAction extends Action
+class PushCallbackAction extends Action
{
function handle()
{
diff --git a/plugins/OStatus/actions/hub.php b/plugins/OStatus/actions/pushhub.php
index 5caf4b48e..901c18f70 100644
--- a/plugins/OStatus/actions/hub.php
+++ b/plugins/OStatus/actions/pushhub.php
@@ -37,7 +37,7 @@ Things to consider...
*/
-class HubAction extends Action
+class PushHubAction extends Action
{
function arg($arg, $def=null)
{
diff --git a/plugins/OStatus/classes/Feedinfo.php b/plugins/OStatus/classes/Feedinfo.php
index f29d08cb0..107faf012 100644
--- a/plugins/OStatus/classes/Feedinfo.php
+++ b/plugins/OStatus/classes/Feedinfo.php
@@ -248,7 +248,7 @@ class Feedinfo extends Memcached_DataObject
#$this->verify_token = $token;
#$this->update(); // @fixme
try {
- $callback = common_local_url('feedsubcallback', array('feed' => $this->id));
+ $callback = common_local_url('pushcallback', array('feed' => $this->id));
$headers = array('Content-Type: application/x-www-form-urlencoded');
$post = array('hub.mode' => 'subscribe',
'hub.callback' => $callback,
diff --git a/plugins/OStatus/lib/feeddiscovery.php b/plugins/OStatus/lib/feeddiscovery.php
index 9bc7892fb..39985fc90 100644
--- a/plugins/OStatus/lib/feeddiscovery.php
+++ b/plugins/OStatus/lib/feeddiscovery.php
@@ -168,7 +168,13 @@ class FeedDiscovery
}
// Ok... now on to the links!
+ // Types listed in order of priority -- we'll prefer Atom if available.
// @fixme merge with the munger link checks
+ $feeds = array(
+ 'application/atom+xml' => false,
+ 'application/rss+xml' => false,
+ );
+
$nodes = $dom->getElementsByTagName('link');
for ($i = 0; $i < $nodes->length; $i++) {
$node = $nodes->item($i);
@@ -181,17 +187,21 @@ class FeedDiscovery
$type = trim($type->value);
$href = trim($href->value);
- $feedTypes = array(
- 'application/rss+xml',
- 'application/atom+xml',
- );
- if (trim($rel) == 'alternate' && in_array($type, $feedTypes)) {
- return $this->resolveURI($href, $base);
+ if (trim($rel) == 'alternate' && array_key_exists($type, $feeds) && empty($feeds[$type])) {
+ // Save the first feed found of each type...
+ $feeds[$type] = $this->resolveURI($href, $base);
}
}
}
}
+ // Return the highest-priority feed found
+ foreach ($feeds as $type => $url) {
+ if ($url) {
+ return $url;
+ }
+ }
+
return false;
}
diff --git a/plugins/OStatus/lib/feedmunger.php b/plugins/OStatus/lib/feedmunger.php
index eeb8d2df3..948017702 100644
--- a/plugins/OStatus/lib/feedmunger.php
+++ b/plugins/OStatus/lib/feedmunger.php
@@ -235,34 +235,45 @@ class FeedMunger
*/
function noticeFromEntry($entry)
{
+ $max = Notice::maxContent();
+ $ellipsis = "\xe2\x80\xa6"; // U+2026 HORIZONTAL ELLIPSIS
$title = $entry->title;
$link = $entry->link;
-
+
// @todo We can get <category> entries like this:
// $cats = $entry->getCategory('category', array(0, true));
// but it feels like an awful hack. If it's accessible cleanly,
// try adding #hashtags from the categories/tags on a post.
-
- // @todo Should we force a language here?
- $format = _m('New post: "%1$s" %2$s');
+
$title = $entry->title;
$link = $this->getAltLink($entry);
- $out = sprintf($format, $title, $link);
-
- // Trim link if needed...
- $max = Notice::maxContent();
- if (mb_strlen($out) > $max) {
- $link = common_shorten_url($link);
+ if ($link) {
+ // Blog post or such...
+ // @todo Should we force a language here?
+ $format = _m('New post: "%1$s" %2$s');
$out = sprintf($format, $title, $link);
- }
- // Trim title if needed...
- if (mb_strlen($out) > $max) {
- $ellipsis = "\xe2\x80\xa6"; // U+2026 HORIZONTAL ELLIPSIS
- $used = mb_strlen($out) - mb_strlen($title);
- $available = $max - $used - mb_strlen($ellipsis);
- $title = mb_substr($title, 0, $available) . $ellipsis;
- $out = sprintf($format, $title, $link);
+ // Trim link if needed...
+ if (mb_strlen($out) > $max) {
+ $link = common_shorten_url($link);
+ $out = sprintf($format, $title, $link);
+ }
+
+ // Trim title if needed...
+ if (mb_strlen($out) > $max) {
+ $used = mb_strlen($out) - mb_strlen($title);
+ $available = $max - $used - mb_strlen($ellipsis);
+ $title = mb_substr($title, 0, $available) . $ellipsis;
+ $out = sprintf($format, $title, $link);
+ }
+ } else {
+ // No link? Consider a bare status update.
+ if (mb_strlen($title) > $max) {
+ $available = $max - mb_strlen($ellipsis);
+ $out = mb_substr($title, 0, $available) . $ellipsis;
+ } else {
+ $out = $title;
+ }
}
return $out;