forked from GNUsocial/gnu-social
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
This commit is contained in:
parent
dc09453a77
commit
384387c9b0
@ -131,14 +131,14 @@ class ShowstreamAction extends ProfileAction
|
|||||||
new Feed(Feed::RSS2,
|
new Feed(Feed::RSS2,
|
||||||
common_local_url('ApiTimelineUser',
|
common_local_url('ApiTimelineUser',
|
||||||
array(
|
array(
|
||||||
'id' => $this->user->nickname,
|
'id' => $this->user->id,
|
||||||
'format' => 'rss')),
|
'format' => 'rss')),
|
||||||
sprintf(_('Notice feed for %s (RSS 2.0)'),
|
sprintf(_('Notice feed for %s (RSS 2.0)'),
|
||||||
$this->user->nickname)),
|
$this->user->nickname)),
|
||||||
new Feed(Feed::ATOM,
|
new Feed(Feed::ATOM,
|
||||||
common_local_url('ApiTimelineUser',
|
common_local_url('ApiTimelineUser',
|
||||||
array(
|
array(
|
||||||
'id' => $this->user->nickname,
|
'id' => $this->user->id,
|
||||||
'format' => 'atom')),
|
'format' => 'atom')),
|
||||||
sprintf(_('Notice feed for %s (Atom)'),
|
sprintf(_('Notice feed for %s (Atom)'),
|
||||||
$this->user->nickname)),
|
$this->user->nickname)),
|
||||||
|
@ -1176,6 +1176,10 @@ class Notice extends Memcached_DataObject
|
|||||||
// Figure out who that is.
|
// Figure out who that is.
|
||||||
|
|
||||||
$sender = Profile::staticGet('id', $profile_id);
|
$sender = Profile::staticGet('id', $profile_id);
|
||||||
|
if (empty($sender)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
$recipient = common_relative_profile($sender, $nickname, common_sql_now());
|
$recipient = common_relative_profile($sender, $nickname, common_sql_now());
|
||||||
|
|
||||||
if (empty($recipient)) {
|
if (empty($recipient)) {
|
||||||
|
@ -665,6 +665,9 @@ function common_valid_profile_tag($str)
|
|||||||
function common_at_link($sender_id, $nickname)
|
function common_at_link($sender_id, $nickname)
|
||||||
{
|
{
|
||||||
$sender = Profile::staticGet($sender_id);
|
$sender = Profile::staticGet($sender_id);
|
||||||
|
if (!$sender) {
|
||||||
|
return $nickname;
|
||||||
|
}
|
||||||
$recipient = common_relative_profile($sender, common_canonical_nickname($nickname));
|
$recipient = common_relative_profile($sender, common_canonical_nickname($nickname));
|
||||||
if ($recipient) {
|
if ($recipient) {
|
||||||
$user = User::staticGet('id', $recipient->id);
|
$user = User::staticGet('id', $recipient->id);
|
||||||
|
@ -53,10 +53,10 @@ class OStatusPlugin extends Plugin
|
|||||||
*/
|
*/
|
||||||
function onRouterInitialized($m)
|
function onRouterInitialized($m)
|
||||||
{
|
{
|
||||||
$m->connect('push/hub', array('action' => 'hub'));
|
$m->connect('main/push/hub', array('action' => 'pushhub'));
|
||||||
|
|
||||||
$m->connect('feedsub/callback/:feed',
|
$m->connect('main/push/callback/:feed',
|
||||||
array('action' => 'feedsubcallback'),
|
array('action' => 'pushcallback'),
|
||||||
array('feed' => '[0-9]+'));
|
array('feed' => '[0-9]+'));
|
||||||
$m->connect('settings/feedsub',
|
$m->connect('settings/feedsub',
|
||||||
array('action' => 'feedsubsettings'));
|
array('action' => 'feedsubsettings'));
|
||||||
@ -97,7 +97,7 @@ class OStatusPlugin extends Plugin
|
|||||||
// Canonical form of id in URL?
|
// Canonical form of id in URL?
|
||||||
// Updates will be handled for our internal PuSH hub.
|
// Updates will be handled for our internal PuSH hub.
|
||||||
$action->element('link', array('rel' => 'hub',
|
$action->element('link', array('rel' => 'hub',
|
||||||
'href' => common_local_url('hub')));
|
'href' => common_local_url('pushhub')));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
|
if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
|
||||||
|
|
||||||
|
|
||||||
class FeedSubCallbackAction extends Action
|
class PushCallbackAction extends Action
|
||||||
{
|
{
|
||||||
function handle()
|
function handle()
|
||||||
{
|
{
|
@ -37,7 +37,7 @@ Things to consider...
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
class HubAction extends Action
|
class PushHubAction extends Action
|
||||||
{
|
{
|
||||||
function arg($arg, $def=null)
|
function arg($arg, $def=null)
|
||||||
{
|
{
|
@ -248,7 +248,7 @@ class Feedinfo extends Memcached_DataObject
|
|||||||
#$this->verify_token = $token;
|
#$this->verify_token = $token;
|
||||||
#$this->update(); // @fixme
|
#$this->update(); // @fixme
|
||||||
try {
|
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');
|
$headers = array('Content-Type: application/x-www-form-urlencoded');
|
||||||
$post = array('hub.mode' => 'subscribe',
|
$post = array('hub.mode' => 'subscribe',
|
||||||
'hub.callback' => $callback,
|
'hub.callback' => $callback,
|
||||||
|
@ -168,7 +168,13 @@ class FeedDiscovery
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Ok... now on to the links!
|
// 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
|
// @fixme merge with the munger link checks
|
||||||
|
$feeds = array(
|
||||||
|
'application/atom+xml' => false,
|
||||||
|
'application/rss+xml' => false,
|
||||||
|
);
|
||||||
|
|
||||||
$nodes = $dom->getElementsByTagName('link');
|
$nodes = $dom->getElementsByTagName('link');
|
||||||
for ($i = 0; $i < $nodes->length; $i++) {
|
for ($i = 0; $i < $nodes->length; $i++) {
|
||||||
$node = $nodes->item($i);
|
$node = $nodes->item($i);
|
||||||
@ -181,17 +187,21 @@ class FeedDiscovery
|
|||||||
$type = trim($type->value);
|
$type = trim($type->value);
|
||||||
$href = trim($href->value);
|
$href = trim($href->value);
|
||||||
|
|
||||||
$feedTypes = array(
|
if (trim($rel) == 'alternate' && array_key_exists($type, $feeds) && empty($feeds[$type])) {
|
||||||
'application/rss+xml',
|
// Save the first feed found of each type...
|
||||||
'application/atom+xml',
|
$feeds[$type] = $this->resolveURI($href, $base);
|
||||||
);
|
|
||||||
if (trim($rel) == 'alternate' && in_array($type, $feedTypes)) {
|
|
||||||
return $this->resolveURI($href, $base);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Return the highest-priority feed found
|
||||||
|
foreach ($feeds as $type => $url) {
|
||||||
|
if ($url) {
|
||||||
|
return $url;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -235,6 +235,8 @@ class FeedMunger
|
|||||||
*/
|
*/
|
||||||
function noticeFromEntry($entry)
|
function noticeFromEntry($entry)
|
||||||
{
|
{
|
||||||
|
$max = Notice::maxContent();
|
||||||
|
$ellipsis = "\xe2\x80\xa6"; // U+2026 HORIZONTAL ELLIPSIS
|
||||||
$title = $entry->title;
|
$title = $entry->title;
|
||||||
$link = $entry->link;
|
$link = $entry->link;
|
||||||
|
|
||||||
@ -243,14 +245,15 @@ class FeedMunger
|
|||||||
// but it feels like an awful hack. If it's accessible cleanly,
|
// but it feels like an awful hack. If it's accessible cleanly,
|
||||||
// try adding #hashtags from the categories/tags on a post.
|
// 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;
|
$title = $entry->title;
|
||||||
$link = $this->getAltLink($entry);
|
$link = $this->getAltLink($entry);
|
||||||
|
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);
|
$out = sprintf($format, $title, $link);
|
||||||
|
|
||||||
// Trim link if needed...
|
// Trim link if needed...
|
||||||
$max = Notice::maxContent();
|
|
||||||
if (mb_strlen($out) > $max) {
|
if (mb_strlen($out) > $max) {
|
||||||
$link = common_shorten_url($link);
|
$link = common_shorten_url($link);
|
||||||
$out = sprintf($format, $title, $link);
|
$out = sprintf($format, $title, $link);
|
||||||
@ -258,12 +261,20 @@ class FeedMunger
|
|||||||
|
|
||||||
// Trim title if needed...
|
// Trim title if needed...
|
||||||
if (mb_strlen($out) > $max) {
|
if (mb_strlen($out) > $max) {
|
||||||
$ellipsis = "\xe2\x80\xa6"; // U+2026 HORIZONTAL ELLIPSIS
|
|
||||||
$used = mb_strlen($out) - mb_strlen($title);
|
$used = mb_strlen($out) - mb_strlen($title);
|
||||||
$available = $max - $used - mb_strlen($ellipsis);
|
$available = $max - $used - mb_strlen($ellipsis);
|
||||||
$title = mb_substr($title, 0, $available) . $ellipsis;
|
$title = mb_substr($title, 0, $available) . $ellipsis;
|
||||||
$out = sprintf($format, $title, $link);
|
$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;
|
return $out;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user