From 80ef3946d016eeeef1682e73eddffb222d8db149 Mon Sep 17 00:00:00 2001
From: Evan Prodromou
Date: Thu, 18 Feb 2010 06:36:32 -0500
Subject: more work on salmon
---
plugins/OStatus/actions/salmon.php | 140 +++++++++++++++++++++++++++++++++++--
1 file changed, 133 insertions(+), 7 deletions(-)
(limited to 'plugins/OStatus')
diff --git a/plugins/OStatus/actions/salmon.php b/plugins/OStatus/actions/salmon.php
index c79d09c95..9ca019826 100644
--- a/plugins/OStatus/actions/salmon.php
+++ b/plugins/OStatus/actions/salmon.php
@@ -62,20 +62,146 @@ class SalmonAction extends Action
// XXX: check the signature
$this->act = new Activity($dom->documentElement);
+
+ return true;
}
function handle($args)
{
- common_log(LOG_DEBUG, 'Salmon: incoming post for user: '. $user_id);
+ common_log(LOG_INFO, 'Salmon: incoming post for user '. $this->user->id);
// TODO : Insert new $xml -> notice code
- switch ($this->act->verb)
- {
- case Activity::POST:
- case Activity::SHARE:
- case Activity::FAVORITE:
- case Activity::FOLLOW:
+ if (Event::handle('StartHandleSalmon', array($this->user, $this->activity))) {
+ switch ($this->act->verb)
+ {
+ case ActivityVerb::POST:
+ $this->handlePost();
+ break;
+ case ActivityVerb::SHARE:
+ $this->handleShare();
+ break;
+ case ActivityVerb::FAVORITE:
+ $this->handleFavorite();
+ break;
+ case ActivityVerb::FOLLOW:
+ case ActivityVerb::FRIEND:
+ $this->handleFollow();
+ break;
+ }
+ Event::handle('EndHandleSalmon', array($this->user, $this->activity));
+ }
+ }
+
+ function handlePost()
+ {
+ switch ($this->act->object->type) {
+ case ActivityObject::ARTICLE:
+ case ActivityObject::BLOGENTRY:
+ case ActivityObject::NOTE:
+ case ActivityObject::STATUS:
+ case ActivityObject::COMMENT:
+ break;
+ default:
+ throw new Exception("Can't handle that kind of post.");
+ }
+
+ $profile = $this->ensureProfile();
+ }
+
+ function handleFollow()
+ {
+ }
+
+ function handleFavorite()
+ {
+ }
+
+ function handleShare()
+ {
+ }
+
+ function ensureProfile()
+ {
+ $actor = $this->act->actor;
+
+ if (empty($actor->id)) {
+ throw new Exception("Received a salmon slap from unidentified actor.");
+ }
+
+ $ostatusProfile = Ostatus_profile::staticGet('homeuri', $actor->id);
+
+ if (empty($ostatusProfile)) {
+ return $this->createProfile();
+ } else {
+ // XXX: can we receive a salmon slap from a group...?
+ assert(!empty($ostatusProfile->profile_id));
+ return Profile::staticGet($ostatusProfile->profile_id);
+ }
+ }
+
+ function createProfile()
+ {
+ $actor = $this->act->actor;
+
+ $profile = new Profile();
+
+ $profile->nickname = $this->nicknameFromURI($actor->id);
+
+ if (empty($profile->nickname)) {
+ $profile->nickname = common_nicknamize($actor->title);
+ }
+
+ $profile->fullname = $actor->title;
+ $profile->bio = $actor->summary; // XXX: is that right?
+ $profile->profileurl = $actor->link; // XXX: is that right?
+ $profile->created = common_sql_now();
+
+ $id = $profile->insert();
+
+ if (empty($id)) {
+ common_log_db_error($profile, 'INSERT', __FILE__);
+ throw new Exception("Couldn't save new profile for $actor->id\n");
+ }
+
+ // XXX: add avatars
+
+ $op = new Ostatus_profile();
+
+ $op->profile_id = $id;
+ $op->homeuri = $actor->id;
+ $op->created = $profile->created;
+
+ // XXX: determine feed URI from source or Webfinger or whatever
+
+ $id = $op->insert();
+
+ if (empty($id)) {
+ common_log_db_error($op, 'INSERT', __FILE__);
+ throw new Exception("Couldn't save new ostatus profile for $actor->id\n");
+ }
+
+ return $profile;
+ }
+
+ function nicknameFromURI($uri)
+ {
+ preg_match('/(\w+):/', $uri, $matches);
+
+ $protocol = $matches[1];
+
+ switch ($protocol) {
+ case 'acct':
+ case 'mailto':
+ if (preg_match("/^$protocol:(.*)?@.*\$/", $uri, $matches)) {
+ return common_canonical_nickname($matches[1]);
+ }
+ return null;
+ case 'http':
+ return common_url_to_nickname($uri);
+ break;
+ default:
+ return null;
}
}
}
--
cgit v1.2.3-54-g00ecf
From 22ff358ba8d1fd0396136e1de570d788dd0727b6 Mon Sep 17 00:00:00 2001
From: Brion Vibber
Date: Thu, 18 Feb 2010 18:20:48 +0000
Subject: OStatus sub/unsub updates: - fix for PuSH unsub verification - send
Salmon notification on unsub
---
lib/atom10entry.php | 5 +--
lib/atom10feed.php | 11 +++++-
lib/atomnoticefeed.php | 8 ++--
plugins/OStatus/OStatusPlugin.php | 55 ++++++++++++++++++++++++---
plugins/OStatus/actions/pushcallback.php | 2 +-
plugins/OStatus/actions/pushhub.php | 9 +++--
plugins/OStatus/actions/salmon.php | 2 +
plugins/OStatus/classes/HubSub.php | 11 ++----
plugins/OStatus/classes/Ostatus_profile.php | 44 +++++++++++----------
plugins/OStatus/lib/activity.php | 6 +++
plugins/OStatus/lib/hubverifyqueuehandler.php | 3 +-
11 files changed, 108 insertions(+), 48 deletions(-)
(limited to 'plugins/OStatus')
diff --git a/lib/atom10entry.php b/lib/atom10entry.php
index 5710c80fc..f8f16d594 100644
--- a/lib/atom10entry.php
+++ b/lib/atom10entry.php
@@ -27,8 +27,7 @@
* @link http://status.net/
*/
-if (!defined('STATUSNET')
-{
+if (!defined('STATUSNET')) {
exit(1);
}
@@ -87,7 +86,7 @@ class Atom10Entry extends XMLStringer
*
* @return void
*/
- function validate
+ function validate()
{
}
diff --git a/lib/atom10feed.php b/lib/atom10feed.php
index 14a3beb83..5e17b20d3 100644
--- a/lib/atom10feed.php
+++ b/lib/atom10feed.php
@@ -78,7 +78,7 @@ class Atom10Feed extends XMLStringer
$this->authors = array();
$this->links = array();
$this->entries = array();
- $this->addNamespace('xmlns', 'http://www.w3.org/2005/Atom');
+ $this->addNamespace('', 'http://www.w3.org/2005/Atom');
}
/**
@@ -162,7 +162,14 @@ class Atom10Feed extends XMLStringer
{
$this->xw->startDocument('1.0', 'UTF-8');
$commonAttrs = array('xml:lang' => 'en-US');
- $commonAttrs = array_merge($commonAttrs, $this->namespaces);
+ foreach ($this->namespaces as $prefix => $uri) {
+ if ($prefix == '') {
+ $attr = 'xmlns';
+ } else {
+ $attr = 'xmlns:' . $prefix;
+ }
+ $commonAttrs[$attr] = $uri;
+ }
$this->elementStart('feed', $commonAttrs);
$this->element('id', null, $this->id);
diff --git a/lib/atomnoticefeed.php b/lib/atomnoticefeed.php
index b7a60bde6..7653f9154 100644
--- a/lib/atomnoticefeed.php
+++ b/lib/atomnoticefeed.php
@@ -50,23 +50,23 @@ class AtomNoticeFeed extends Atom10Feed
// Feeds containing notice info use these namespaces
$this->addNamespace(
- 'xmlns:thr',
+ 'thr',
'http://purl.org/syndication/thread/1.0'
);
$this->addNamespace(
- 'xmlns:georss',
+ 'georss',
'http://www.georss.org/georss'
);
$this->addNamespace(
- 'xmlns:activity',
+ 'activity',
'http://activitystrea.ms/spec/1.0/'
);
// XXX: What should the uri be?
$this->addNamespace(
- 'xmlns:ostatus',
+ 'ostatus',
'http://ostatus.org/schema/1.0'
);
}
diff --git a/plugins/OStatus/OStatusPlugin.php b/plugins/OStatus/OStatusPlugin.php
index b6c9fa1d4..e548a151c 100644
--- a/plugins/OStatus/OStatusPlugin.php
+++ b/plugins/OStatus/OStatusPlugin.php
@@ -112,7 +112,7 @@ class OStatusPlugin extends Plugin
* Set up a PuSH hub link to our internal link for canonical timeline
* Atom feeds for users and groups.
*/
- function onStartApiAtom(AtomNoticeFeed $feed)
+ function onStartApiAtom($feed)
{
$id = null;
@@ -171,6 +171,12 @@ class OStatusPlugin extends Plugin
{
$base = dirname(__FILE__);
$lower = strtolower($cls);
+ $map = array('activityverb' => 'activity',
+ 'activityobject' => 'activity',
+ 'activityutils' => 'activity');
+ if (isset($map[$lower])) {
+ $lower = $map[$lower];
+ }
$files = array("$base/classes/$cls.php",
"$base/lib/$lower.php");
if (substr($lower, -6) == 'action') {
@@ -253,18 +259,45 @@ class OStatusPlugin extends Plugin
}
/**
- * Garbage collect unused feeds on unsubscribe
+ * Notify remote server when one of our users subscribes.
+ * @fixme Check and restart the PuSH subscription if needed
+ *
+ * @param User $user
+ * @param Profile $other
+ * @return hook return value
+ */
+ function onEndSubscribe($user, $other)
+ {
+ $oprofile = Ostatus_profile::staticGet('profile_id', $other->id);
+ if ($oprofile) {
+ // Notify the remote server of the unsub, if supported.
+ $oprofile->notify($user->getProfile(), ActivityVerb::FOLLOW, $oprofile);
+ }
+ return true;
+ }
+
+ /**
+ * Notify remote server and garbage collect unused feeds on unsubscribe.
+ * @fixme send these operations to background queues
+ *
+ * @param User $user
+ * @param Profile $other
+ * @return hook return value
*/
function onEndUnsubscribe($user, $other)
{
- $profile = Ostatus_profile::staticGet('profile_id', $other->id);
- if ($feed) {
+ $oprofile = Ostatus_profile::staticGet('profile_id', $other->id);
+ if ($oprofile) {
+ // Notify the remote server of the unsub, if supported.
+ $oprofile->notify($user->getProfile(), ActivityVerb::UNFOLLOW, $oprofile);
+
+ // Drop the PuSH subscription if there are no other subscribers.
$sub = new Subscription();
$sub->subscribed = $other->id;
$sub->limit(1);
if (!$sub->find(true)) {
- common_log(LOG_INFO, "Unsubscribing from now-unused feed $feed->feeduri on hub $feed->huburi");
- $profile->unsubscribe();
+ common_log(LOG_INFO, "Unsubscribing from now-unused feed $oprofile->feeduri on hub $oprofile->huburi");
+ $oprofile->unsubscribe();
}
}
return true;
@@ -290,6 +323,16 @@ class OStatusPlugin extends Plugin
return true;
}
+ /**
+ * Override the "from ostatus" bit in notice lists to link to the
+ * original post and show the domain it came from.
+ *
+ * @param Notice in $notice
+ * @param string out &$name
+ * @param string out &$url
+ * @param string out &$title
+ * @return mixed hook return code
+ */
function onStartNoticeSourceLink($notice, &$name, &$url, &$title)
{
if ($notice->source == 'ostatus') {
diff --git a/plugins/OStatus/actions/pushcallback.php b/plugins/OStatus/actions/pushcallback.php
index 388c8f9c3..ed859a32f 100644
--- a/plugins/OStatus/actions/pushcallback.php
+++ b/plugins/OStatus/actions/pushcallback.php
@@ -89,7 +89,7 @@ class PushCallbackAction extends Action
if ($profile->verify_token !== $verify_token) {
common_log(LOG_WARNING, __METHOD__ . ": bogus hub callback with bad token \"$verify_token\" for feed $topic");
- throw new ServerError("Bogus hub callback: bad token", 404);
+ throw new ServerException("Bogus hub callback: bad token", 404);
}
if ($mode != $profile->sub_state) {
diff --git a/plugins/OStatus/actions/pushhub.php b/plugins/OStatus/actions/pushhub.php
index 13ec09d52..19599d815 100644
--- a/plugins/OStatus/actions/pushhub.php
+++ b/plugins/OStatus/actions/pushhub.php
@@ -83,6 +83,7 @@ class PushHubAction extends Action
{
$feed = $this->argUrl('hub.topic');
$callback = $this->argUrl('hub.callback');
+ $token = $this->arg('hub.verify_token', null);
common_log(LOG_DEBUG, __METHOD__ . ": checking sub'd to $feed $callback");
if ($this->getSub($feed, $callback)) {
@@ -96,7 +97,6 @@ class PushHubAction extends Action
$sub = new HubSub();
$sub->topic = $feed;
$sub->callback = $callback;
- $sub->verify_token = $this->arg('hub.verify_token', null);
$sub->secret = $this->arg('hub.secret', null);
if (strlen($sub->secret) > 200) {
throw new ClientException("hub.secret must be no longer than 200 chars", 400);
@@ -115,7 +115,7 @@ class PushHubAction extends Action
// @fixme check errors ;)
- $data = array('sub' => $sub, 'mode' => 'subscribe');
+ $data = array('sub' => $sub, 'mode' => 'subscribe', 'token' => $token);
$qm = QueueManager::get();
$qm->enqueue($data, 'hubverify');
@@ -130,6 +130,8 @@ class PushHubAction extends Action
* 202 Accepted - request saved and awaiting verification
* 204 No Content - already subscribed
* 400 Bad Request - invalid params or rejected feed
+ *
+ * @fixme background this
*/
function unsubscribe()
{
@@ -138,7 +140,8 @@ class PushHubAction extends Action
$sub = $this->getSub($feed, $callback);
if ($sub) {
- if ($sub->verify('unsubscribe')) {
+ $token = $this->arg('hub.verify_token', null);
+ if ($sub->verify('unsubscribe', $token)) {
$sub->delete();
common_log(LOG_INFO, "PuSH unsubscribed $feed for $callback");
} else {
diff --git a/plugins/OStatus/actions/salmon.php b/plugins/OStatus/actions/salmon.php
index 9ca019826..224134cd7 100644
--- a/plugins/OStatus/actions/salmon.php
+++ b/plugins/OStatus/actions/salmon.php
@@ -34,6 +34,8 @@ class SalmonAction extends Action
function prepare($args)
{
+ parent::prepare($args);
+
if ($_SERVER['REQUEST_METHOD'] != 'POST') {
$this->clientError(_('This method requires a POST.'));
}
diff --git a/plugins/OStatus/classes/HubSub.php b/plugins/OStatus/classes/HubSub.php
index 7071ee5b4..0cd4281f8 100644
--- a/plugins/OStatus/classes/HubSub.php
+++ b/plugins/OStatus/classes/HubSub.php
@@ -30,7 +30,6 @@ class HubSub extends Memcached_DataObject
public $topic;
public $callback;
public $secret;
- public $verify_token;
public $challenge;
public $lease;
public $sub_start;
@@ -62,7 +61,6 @@ class HubSub extends Memcached_DataObject
'topic' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,
'callback' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,
'secret' => DB_DATAOBJECT_STR,
- 'verify_token' => DB_DATAOBJECT_STR,
'challenge' => DB_DATAOBJECT_STR,
'lease' => DB_DATAOBJECT_INT,
'sub_start' => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME,
@@ -84,8 +82,6 @@ class HubSub extends Memcached_DataObject
255, false),
new ColumnDef('secret', 'text',
null, true),
- new ColumnDef('verify_token', 'text',
- null, true),
new ColumnDef('challenge', 'varchar',
32, true),
new ColumnDef('lease', 'int',
@@ -154,8 +150,9 @@ class HubSub extends Memcached_DataObject
/**
* Send a verification ping to subscriber
* @param string $mode 'subscribe' or 'unsubscribe'
+ * @param string $token hub.verify_token value, if provided by client
*/
- function verify($mode)
+ function verify($mode, $token=null)
{
assert($mode == 'subscribe' || $mode == 'unsubscribe');
@@ -172,8 +169,8 @@ class HubSub extends Memcached_DataObject
if ($mode == 'subscribe') {
$params['hub.lease_seconds'] = $this->lease;
}
- if ($this->verify_token) {
- $params['hub.verify_token'] = $this->verify_token;
+ if ($token !== null) {
+ $params['hub.verify_token'] = $token;
}
$url = $this->callback . '?' . http_build_query($params, '', '&'); // @fixme ugly urls
diff --git a/plugins/OStatus/classes/Ostatus_profile.php b/plugins/OStatus/classes/Ostatus_profile.php
index be01cdfe1..486417617 100644
--- a/plugins/OStatus/classes/Ostatus_profile.php
+++ b/plugins/OStatus/classes/Ostatus_profile.php
@@ -484,7 +484,7 @@ class Ostatus_profile extends Memcached_DataObject
} else {
$this->sub_end = null;
}
- $this->lastupdate = common_sql_date();
+ $this->lastupdate = common_sql_now();
return $this->update($original);
}
@@ -497,12 +497,13 @@ class Ostatus_profile extends Memcached_DataObject
{
$original = clone($this);
- $this->verify_token = null;
- $this->secret = null;
- $this->sub_state = null;
- $this->sub_start = null;
- $this->sub_end = null;
- $this->lastupdate = common_sql_date();
+ // @fixme these should all be null, but DB_DataObject doesn't save null values...?????
+ $this->verify_token = '';
+ $this->secret = '';
+ $this->sub_state = '';
+ $this->sub_start = '';
+ $this->sub_end = '';
+ $this->lastupdate = common_sql_now();
return $this->update($original);
}
@@ -527,24 +528,25 @@ class Ostatus_profile extends Memcached_DataObject
':' . $actor->id .
':' . time(); // @fixme
- $entry = new Atom10Entry();
+ //$entry = new Atom10Entry();
+ $entry = new XMLStringer();
$entry->elementStart('entry');
$entry->element('id', null, $id);
$entry->element('title', null, $text);
$entry->element('summary', null, $text);
- $entry->element('published', null, common_date_w3dtf());
+ $entry->element('published', null, common_date_w3dtf(time()));
$entry->element('activity:verb', null, $verb);
- $entry->raw($profile->asAtomAuthor());
- $entry->raw($profile->asActivityActor());
+ $entry->raw($actor->asAtomAuthor());
+ $entry->raw($actor->asActivityActor());
$entry->raw($object->asActivityNoun('object'));
- $entry->elmentEnd('entry');
+ $entry->elementEnd('entry');
$feed = $this->atomFeed($actor);
- $feed->initFeed();
+ #$feed->initFeed();
$feed->addEntry($entry);
- $feed->renderEntries();
- $feed->endFeed();
+ #$feed->renderEntries();
+ #$feed->endFeed();
$xml = $feed->getString();
common_log(LOG_INFO, "Posting to Salmon endpoint $salmon: $xml");
@@ -568,7 +570,7 @@ class Ostatus_profile extends Memcached_DataObject
$feed = new Atom10Feed();
// @fixme should these be set up somewhere else?
$feed->addNamespace('activity', 'http://activitystrea.ms/spec/1.0/');
- $feed->addNamesapce('thr', 'http://purl.org/syndication/thread/1.0');
+ $feed->addNamespace('thr', 'http://purl.org/syndication/thread/1.0');
$feed->addNamespace('georss', 'http://www.georss.org/georss');
$feed->addNamespace('ostatus', 'http://ostatus.org/schema/1.0');
@@ -579,14 +581,14 @@ class Ostatus_profile extends Memcached_DataObject
$feed->setUpdated(time());
$feed->setPublished(time());
- $feed->addLink(common_url('ApiTimelineUser',
- array('id' => $actor->id,
- 'type' => 'atom')),
+ $feed->addLink(common_local_url('ApiTimelineUser',
+ array('id' => $actor->id,
+ 'type' => 'atom')),
array('rel' => 'self',
'type' => 'application/atom+xml'));
- $feed->addLink(common_url('userbyid',
- array('id' => $actor->id)),
+ $feed->addLink(common_local_url('userbyid',
+ array('id' => $actor->id)),
array('rel' => 'alternate',
'type' => 'text/html'));
diff --git a/plugins/OStatus/lib/activity.php b/plugins/OStatus/lib/activity.php
index f137946ab..3ed613dc7 100644
--- a/plugins/OStatus/lib/activity.php
+++ b/plugins/OStatus/lib/activity.php
@@ -303,6 +303,12 @@ class ActivityVerb
const FRIEND = 'http://activitystrea.ms/schema/1.0/make-friend';
const JOIN = 'http://activitystrea.ms/schema/1.0/join';
const TAG = 'http://activitystrea.ms/schema/1.0/tag';
+
+ // Custom OStatus verbs for the flipside until they're standardized
+ const DELETE = 'http://ostatus.org/schema/1.0/unfollow';
+ const UNFAVORITE = 'http://ostatus.org/schema/1.0/unfavorite';
+ const UNFOLLOW = 'http://ostatus.org/schema/1.0/unfollow';
+ const LEAVE = 'http://ostatus.org/schema/1.0/leave';
}
/**
diff --git a/plugins/OStatus/lib/hubverifyqueuehandler.php b/plugins/OStatus/lib/hubverifyqueuehandler.php
index 125d13a77..7ce9e1431 100644
--- a/plugins/OStatus/lib/hubverifyqueuehandler.php
+++ b/plugins/OStatus/lib/hubverifyqueuehandler.php
@@ -33,13 +33,14 @@ class HubVerifyQueueHandler extends QueueHandler
{
$sub = $data['sub'];
$mode = $data['mode'];
+ $token = $data['token'];
assert($sub instanceof HubSub);
assert($mode === 'subscribe' || $mode === 'unsubscribe');
common_log(LOG_INFO, __METHOD__ . ": $mode $sub->callback $sub->topic");
try {
- $sub->verify($mode);
+ $sub->verify($mode, $token);
} catch (Exception $e) {
common_log(LOG_ERR, "Failed PuSH $mode verify to $sub->callback for $sub->topic: " .
$e->getMessage());
--
cgit v1.2.3-54-g00ecf
From 0dac13d197248bf24ea51cb7911d32286764c0c8 Mon Sep 17 00:00:00 2001
From: Brion Vibber
Date: Thu, 18 Feb 2010 21:22:21 +0000
Subject: OStatus refactoring to clean up profile vs feed and fix up
subscription issues. PuSH subscription maintenance broken back out to
FeedSub, letting Ostatus_profile deal with the profile level (user or group,
with unique id URI)
---
plugins/OStatus/OStatusPlugin.php | 53 +--
plugins/OStatus/actions/feedsubsettings.php | 99 ++---
plugins/OStatus/actions/pushcallback.php | 22 +-
plugins/OStatus/actions/salmon.php | 32 +-
plugins/OStatus/classes/FeedSub.php | 443 ++++++++++++++++++++++
plugins/OStatus/classes/Ostatus_profile.php | 544 +++++++++-------------------
plugins/OStatus/lib/feeddiscovery.php | 50 ++-
plugins/OStatus/lib/feedmunger.php | 350 ------------------
8 files changed, 741 insertions(+), 852 deletions(-)
create mode 100644 plugins/OStatus/classes/FeedSub.php
delete mode 100644 plugins/OStatus/lib/feedmunger.php
(limited to 'plugins/OStatus')
diff --git a/plugins/OStatus/OStatusPlugin.php b/plugins/OStatus/OStatusPlugin.php
index e548a151c..4ebe4551e 100644
--- a/plugins/OStatus/OStatusPlugin.php
+++ b/plugins/OStatus/OStatusPlugin.php
@@ -1,17 +1,7 @@
-Author URI: http://status.net/
-*/
-
/*
* StatusNet - the distributed open-source microblogging tool
- * Copyright (C) 2009, StatusNet, Inc.
+ * Copyright (C) 2009-2010, StatusNet, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@@ -28,17 +18,12 @@ Author URI: http://status.net/
*/
/**
- * @package FeedSubPlugin
+ * @package OStatusPlugin
* @maintainer Brion Vibber
*/
if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
-define('FEEDSUB_SERVICE', 100); // fixme -- avoid hardcoding these?
-
-// We bundle the XML_Parse_Feed library...
-set_include_path(get_include_path() . PATH_SEPARATOR . dirname(__FILE__) . '/extlib');
-
class FeedSubException extends Exception
{
}
@@ -258,24 +243,6 @@ class OStatusPlugin extends Plugin
}
}
- /**
- * Notify remote server when one of our users subscribes.
- * @fixme Check and restart the PuSH subscription if needed
- *
- * @param User $user
- * @param Profile $other
- * @return hook return value
- */
- function onEndSubscribe($user, $other)
- {
- $oprofile = Ostatus_profile::staticGet('profile_id', $other->id);
- if ($oprofile) {
- // Notify the remote server of the unsub, if supported.
- $oprofile->notify($user->getProfile(), ActivityVerb::FOLLOW, $oprofile);
- }
- return true;
- }
-
/**
* Notify remote server and garbage collect unused feeds on unsubscribe.
* @fixme send these operations to background queues
@@ -309,6 +276,7 @@ class OStatusPlugin extends Plugin
function onCheckSchema() {
$schema = Schema::get();
$schema->ensureTable('ostatus_profile', Ostatus_profile::schemaDef());
+ $schema->ensureTable('feedsub', FeedSub::schemaDef());
$schema->ensureTable('hubsub', HubSub::schemaDef());
return true;
}
@@ -345,4 +313,19 @@ class OStatusPlugin extends Plugin
return false;
}
}
+
+ /**
+ * Send incoming PuSH feeds for OStatus endpoints in for processing.
+ *
+ * @param FeedSub $feedsub
+ * @param DOMDocument $feed
+ * @return mixed hook return code
+ */
+ function onStartFeedSubReceive($feedsub, $feed)
+ {
+ $oprofile = Ostatus_profile::staticGet('feeduri', $feedsub->uri);
+ if ($oprofile) {
+ $oprofile->processFeed($feed);
+ }
+ }
}
diff --git a/plugins/OStatus/actions/feedsubsettings.php b/plugins/OStatus/actions/feedsubsettings.php
index 6933c9bf2..3e1d0aa82 100644
--- a/plugins/OStatus/actions/feedsubsettings.php
+++ b/plugins/OStatus/actions/feedsubsettings.php
@@ -26,7 +26,7 @@ if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
class FeedSubSettingsAction extends ConnectSettingsAction
{
- protected $feedurl;
+ protected $profile_uri;
protected $preview;
protected $munger;
@@ -88,7 +88,10 @@ class FeedSubSettingsAction extends ConnectSettingsAction
$this->elementStart('ul', 'form_data');
$this->elementStart('li', array('id' => 'settings_twitter_login_button'));
- $this->input('feedurl', _('Feed URL'), $this->feedurl, _('Enter the URL of a PubSubHubbub-enabled feed'));
+ $this->input('profile_uri',
+ _m('Feed URL'),
+ $this->profile_uri,
+ _m('Enter the profile URL of a PubSubHubbub-enabled feed'));
$this->elementEnd('li');
$this->elementEnd('ul');
@@ -145,79 +148,55 @@ class FeedSubSettingsAction extends ConnectSettingsAction
*/
function validateFeed()
{
- $feedurl = trim($this->arg('feedurl'));
+ $profile_uri = trim($this->arg('profile_uri'));
- if ($feedurl == '') {
- $this->showForm(_m('Empty feed URL!'));
+ if ($profile_uri == '') {
+ $this->showForm(_m('Empty remote profile URL!'));
return;
}
- $this->feedurl = $feedurl;
+ $this->profile_uri = $profile_uri;
- // Get the canonical feed URI and check it
+ // @fixme validate, normalize bla bla
try {
- $discover = new FeedDiscovery();
- $uri = $discover->discoverFromURL($feedurl);
+ $oprofile = Ostatus_profile::ensureProfile($this->profile_uri);
+ $this->oprofile = $oprofile;
+ return true;
} catch (FeedSubBadURLException $e) {
- $this->showForm(_m('Invalid URL or could not reach server.'));
- return false;
+ $err = _m('Invalid URL or could not reach server.');
} catch (FeedSubBadResponseException $e) {
- $this->showForm(_m('Cannot read feed; server returned error.'));
- return false;
+ $err = _m('Cannot read feed; server returned error.');
} catch (FeedSubEmptyException $e) {
- $this->showForm(_m('Cannot read feed; server returned an empty page.'));
- return false;
+ $err = _m('Cannot read feed; server returned an empty page.');
} catch (FeedSubBadHTMLException $e) {
- $this->showForm(_m('Bad HTML, could not find feed link.'));
- return false;
+ $err = _m('Bad HTML, could not find feed link.');
} catch (FeedSubNoFeedException $e) {
- $this->showForm(_m('Could not find a feed linked from this URL.'));
- return false;
+ $err = _m('Could not find a feed linked from this URL.');
} catch (FeedSubUnrecognizedTypeException $e) {
- $this->showForm(_m('Not a recognized feed type.'));
- return false;
+ $err = _m('Not a recognized feed type.');
} catch (FeedSubException $e) {
// Any new ones we forgot about
- $this->showForm(_m('Bad feed URL.'));
- return false;
+ $err = sprintf(_m('Bad feed URL: %s %s'), get_class($e), $e->getMessage());
}
-
- $this->munger = $discover->feedMunger();
- $this->profile = $this->munger->ostatusProfile();
- if ($this->profile->huburi == '' && !common_config('feedsub', 'nohub')) {
- $this->showForm(_m('Feed is not PuSH-enabled; cannot subscribe.'));
- return false;
- }
-
- return true;
+ $this->showForm($err);
+ return false;
}
function saveFeed()
{
if ($this->validateFeed()) {
$this->preview = true;
- $this->profile = Ostatus_profile::ensureProfile($this->munger);
- if (!$this->profile) {
- throw new ServerException("Feed profile was not saved properly.");
- }
-
- // If not already in use, subscribe to updates via the hub
- if ($this->profile->sub_start) {
- common_log(LOG_INFO, __METHOD__ . ": double the fun! new sub for {$this->profile->feeduri} last subbed {$this->profile->sub_start}");
- } else {
- $ok = $this->profile->subscribe();
- common_log(LOG_INFO, __METHOD__ . ": sub was $ok");
- if (!$ok) {
- $this->showForm(_m('Feed subscription failed! Bad response from hub.'));
- return;
- }
- }
// And subscribe the current user to the local profile
$user = common_current_user();
- if ($this->profile->isGroup()) {
- $group = $this->profile->localGroup();
+ if (!$this->oprofile->subscribe()) {
+ $this->showForm(_m("Failed to set up server-to-server subscription."));
+ return;
+ }
+
+ if ($this->oprofile->isGroup()) {
+ $group = $this->oprofile->localGroup();
if ($user->isMember($group)) {
$this->showForm(_m('Already a member!'));
} elseif (Group_member::join($this->profile->group_id, $user->id)) {
@@ -226,13 +205,13 @@ class FeedSubSettingsAction extends ConnectSettingsAction
$this->showForm(_m('Remote group join failed!'));
}
} else {
- $local = $this->profile->localProfile();
+ $local = $this->oprofile->localProfile();
if ($user->isSubscribed($local)) {
$this->showForm(_m('Already subscribed!'));
- } elseif ($user->subscribeTo($local)) {
- $this->showForm(_m('Feed subscribed!'));
+ } elseif ($this->oprofile->subscribeLocalToRemote($user)) {
+ $this->showForm(_m('Remote user subscribed!'));
} else {
- $this->showForm(_m('Feed subscription failed!'));
+ $this->showForm(_m('Remote subscription failed!'));
}
}
}
@@ -248,17 +227,7 @@ class FeedSubSettingsAction extends ConnectSettingsAction
function previewFeed()
{
- $profile = $this->munger->ostatusProfile();
- $notice = $this->munger->notice(0, true); // preview
-
- if ($notice) {
- $this->element('b', null, 'Preview of latest post from this feed:');
-
- $item = new NoticeList($notice, $this);
- $item->show();
- } else {
- $this->element('b', null, 'No posts in this feed yet.');
- }
+ $this->text('Profile preview should go here');
}
function showScripts()
diff --git a/plugins/OStatus/actions/pushcallback.php b/plugins/OStatus/actions/pushcallback.php
index ed859a32f..7e1227a66 100644
--- a/plugins/OStatus/actions/pushcallback.php
+++ b/plugins/OStatus/actions/pushcallback.php
@@ -48,9 +48,9 @@ class PushCallbackAction extends Action
throw new ServerException('Empty or invalid feed id', 400);
}
- $profile = Ostatus_profile::staticGet('id', $feedid);
- if (!$profile) {
- throw new ServerException('Unknown OStatus/PuSH feed id ' . $feedid, 400);
+ $feedsub = FeedSub::staticGet('id', $feedid);
+ if (!$feedsub) {
+ throw new ServerException('Unknown PuSH feed id ' . $feedid, 400);
}
$hmac = '';
@@ -62,7 +62,7 @@ class PushCallbackAction extends Action
// @fixme Queue this to a background process; we should return
// as quickly as possible from a distribution POST.
- $profile->postUpdates($post, $hmac);
+ $feedsub->receive($post, $hmac);
}
/**
@@ -81,29 +81,29 @@ class PushCallbackAction extends Action
throw new ServerException("Bogus hub callback: bad mode", 404);
}
- $profile = Ostatus_profile::staticGet('feeduri', $topic);
- if (!$profile) {
+ $feedsub = FeedSub::staticGet('uri', $topic);
+ if (!$feedsub) {
common_log(LOG_WARNING, __METHOD__ . ": bogus hub callback for unknown feed $topic");
throw new ServerException("Bogus hub callback: unknown feed", 404);
}
- if ($profile->verify_token !== $verify_token) {
+ if ($feedsub->verify_token !== $verify_token) {
common_log(LOG_WARNING, __METHOD__ . ": bogus hub callback with bad token \"$verify_token\" for feed $topic");
throw new ServerException("Bogus hub callback: bad token", 404);
}
- if ($mode != $profile->sub_state) {
- common_log(LOG_WARNING, __METHOD__ . ": bogus hub callback with bad mode \"$mode\" for feed $topic in state \"{$profile->sub_state}\"");
+ if ($mode != $feedsub->sub_state) {
+ common_log(LOG_WARNING, __METHOD__ . ": bogus hub callback with bad mode \"$mode\" for feed $topic in state \"{$feedsub->sub_state}\"");
throw new ServerException("Bogus hub callback: mode doesn't match subscription state.", 404);
}
// OK!
if ($mode == 'subscribe') {
common_log(LOG_INFO, __METHOD__ . ': sub confirmed');
- $profile->confirmSubscribe($lease_seconds);
+ $feedsub->confirmSubscribe($lease_seconds);
} else {
common_log(LOG_INFO, __METHOD__ . ": unsub confirmed; deleting sub record for $topic");
- $profile->confirmUnsubscribe();
+ $feedsub->confirmUnsubscribe();
}
print $challenge;
}
diff --git a/plugins/OStatus/actions/salmon.php b/plugins/OStatus/actions/salmon.php
index 224134cd7..ea5b8e4ea 100644
--- a/plugins/OStatus/actions/salmon.php
+++ b/plugins/OStatus/actions/salmon.php
@@ -68,6 +68,9 @@ class SalmonAction extends Action
return true;
}
+ /**
+ * @fixme probably call Ostatus_profile::processFeed
+ */
function handle($args)
{
common_log(LOG_INFO, 'Salmon: incoming post for user '. $this->user->id);
@@ -95,6 +98,9 @@ class SalmonAction extends Action
}
}
+ /**
+ * @fixme probably call Ostatus_profile::processFeed
+ */
function handlePost()
{
switch ($this->act->object->type) {
@@ -111,14 +117,23 @@ class SalmonAction extends Action
$profile = $this->ensureProfile();
}
+ /**
+ * @fixme probably call Ostatus_profile::processFeed
+ */
function handleFollow()
{
}
+ /**
+ * @fixme probably call Ostatus_profile::processFeed
+ */
function handleFavorite()
{
}
+ /**
+ * @fixme probably call Ostatus_profile::processFeed
+ */
function handleShare()
{
}
@@ -131,17 +146,13 @@ class SalmonAction extends Action
throw new Exception("Received a salmon slap from unidentified actor.");
}
- $ostatusProfile = Ostatus_profile::staticGet('homeuri', $actor->id);
-
- if (empty($ostatusProfile)) {
- return $this->createProfile();
- } else {
- // XXX: can we receive a salmon slap from a group...?
- assert(!empty($ostatusProfile->profile_id));
- return Profile::staticGet($ostatusProfile->profile_id);
- }
+ $ostatusProfile = Ostatus_profile::ensureActorProfile($this->act);
+ return $oprofile->localProfile();
}
+ /**
+ * @fixme anything new in here probably should be merged into Ostatus_profile::ensureActorProfile and friends
+ */
function createProfile()
{
$actor = $this->act->actor;
@@ -186,6 +197,9 @@ class SalmonAction extends Action
return $profile;
}
+ /**
+ * @fixme should be merged into Ostatus_profile
+ */
function nicknameFromURI($uri)
{
preg_match('/(\w+):/', $uri, $matches);
diff --git a/plugins/OStatus/classes/FeedSub.php b/plugins/OStatus/classes/FeedSub.php
new file mode 100644
index 000000000..dc2c0b710
--- /dev/null
+++ b/plugins/OStatus/classes/FeedSub.php
@@ -0,0 +1,443 @@
+.
+ */
+
+/**
+ * @package OStatusPlugin
+ * @maintainer Brion Vibber
+ */
+
+/*
+PuSH subscription flow:
+
+ $profile->subscribe()
+ generate random verification token
+ save to verify_token
+ sends a sub request to the hub...
+
+ main/push/callback
+ hub sends confirmation back to us via GET
+ We verify the request, then echo back the challenge.
+ On our end, we save the time we subscribed and the lease expiration
+
+ main/push/callback
+ hub sends us updates via POST
+
+*/
+
+class FeedDBException extends FeedSubException
+{
+ public $obj;
+
+ function __construct($obj)
+ {
+ parent::__construct('Database insert failure');
+ $this->obj = $obj;
+ }
+}
+
+/**
+ * FeedSub handles low-level PubHubSubbub (PuSH) subscriptions.
+ * Higher-level behavior building OStatus stuff on top is handled
+ * under Ostatus_profile.
+ */
+class FeedSub extends Memcached_DataObject
+{
+ public $__table = 'feedsub';
+
+ public $id;
+ public $feeduri;
+
+ // PuSH subscription data
+ public $huburi;
+ public $secret;
+ public $verify_token;
+ public $sub_state; // subscribe, active, unsubscribe, inactive
+ public $sub_start;
+ public $sub_end;
+ public $last_update;
+
+ public $created;
+ public $modified;
+
+ public /*static*/ function staticGet($k, $v=null)
+ {
+ return parent::staticGet(__CLASS__, $k, $v);
+ }
+
+ /**
+ * return table definition for DB_DataObject
+ *
+ * DB_DataObject needs to know something about the table to manipulate
+ * instances. This method provides all the DB_DataObject needs to know.
+ *
+ * @return array array of column definitions
+ */
+
+ function table()
+ {
+ return array('id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
+ 'uri' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,
+ 'huburi' => DB_DATAOBJECT_STR,
+ 'secret' => DB_DATAOBJECT_STR,
+ 'verify_token' => DB_DATAOBJECT_STR,
+ 'sub_state' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,
+ 'sub_start' => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME,
+ 'sub_end' => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME,
+ 'last_update' => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME + DB_DATAOBJECT_NOTNULL,
+ 'created' => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME + DB_DATAOBJECT_NOTNULL,
+ 'modified' => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME + DB_DATAOBJECT_NOTNULL);
+ }
+
+ static function schemaDef()
+ {
+ return array(new ColumnDef('id', 'integer',
+ /*size*/ null,
+ /*nullable*/ false,
+ /*key*/ 'PRI',
+ /*default*/ '0',
+ /*extra*/ null,
+ /*auto_increment*/ true),
+ new ColumnDef('uri', 'varchar',
+ 255, false, 'UNI'),
+ new ColumnDef('huburi', 'text',
+ null, true),
+ new ColumnDef('verify_token', 'text',
+ null, true),
+ new ColumnDef('secret', 'text',
+ null, true),
+ new ColumnDef('sub_state', "enum('subscribe','active','unsubscribe','inactive')",
+ null, false),
+ new ColumnDef('sub_start', 'datetime',
+ null, true),
+ new ColumnDef('sub_end', 'datetime',
+ null, true),
+ new ColumnDef('last_update', 'datetime',
+ null, false),
+ new ColumnDef('created', 'datetime',
+ null, false),
+ new ColumnDef('modified', 'datetime',
+ null, false));
+ }
+
+ /**
+ * return key definitions for DB_DataObject
+ *
+ * DB_DataObject needs to know about keys that the table has; this function
+ * defines them.
+ *
+ * @return array key definitions
+ */
+
+ function keys()
+ {
+ return array_keys($this->keyTypes());
+ }
+
+ /**
+ * return key definitions for Memcached_DataObject
+ *
+ * Our caching system uses the same key definitions, but uses a different
+ * method to get them.
+ *
+ * @return array key definitions
+ */
+
+ function keyTypes()
+ {
+ return array('id' => 'K', 'uri' => 'U');
+ }
+
+ function sequenceKey()
+ {
+ return array('id', true, false);
+ }
+
+ /**
+ * Fetch the StatusNet-side profile for this feed
+ * @return Profile
+ */
+ public function localProfile()
+ {
+ if ($this->profile_id) {
+ return Profile::staticGet('id', $this->profile_id);
+ }
+ return null;
+ }
+
+ /**
+ * Fetch the StatusNet-side profile for this feed
+ * @return Profile
+ */
+ public function localGroup()
+ {
+ if ($this->group_id) {
+ return User_group::staticGet('id', $this->group_id);
+ }
+ return null;
+ }
+
+ /**
+ * @param string $feeduri
+ * @return FeedSub
+ * @throws FeedSubException if feed is invalid or lacks PuSH setup
+ */
+ public static function ensureFeed($feeduri)
+ {
+ $current = self::staticGet('uri', $feeduri);
+ if ($current) {
+ return $current;
+ }
+
+ $discover = new FeedDiscovery();
+ $discover->discoverFromFeedURL($feeduri);
+
+ $huburi = $discover->getAtomLink('hub');
+ if (!$huburi) {
+ throw new FeedSubNoHubException();
+ }
+
+ $feedsub = new FeedSub();
+ $feedsub->uri = $feeduri;
+ $feedsub->huburi = $huburi;
+ $feedsub->sub_state = 'inactive';
+
+ $feedsub->created = common_sql_now();
+ $feedsub->modified = common_sql_now();
+
+ $result = $feedsub->insert();
+ if (empty($result)) {
+ throw new FeedDBException($feedsub);
+ }
+
+ return $feedsub;
+ }
+
+ /**
+ * Send a subscription request to the hub for this feed.
+ * The hub will later send us a confirmation POST to /main/push/callback.
+ *
+ * @return bool true on success, false on failure
+ * @throws ServerException if feed state is not valid
+ */
+ public function subscribe($mode='subscribe')
+ {
+ if ($this->sub_state && $this->sub_state != 'inactive') {
+ throw new ServerException("Attempting to start PuSH subscription to feed in state $this->sub_state");
+ }
+ if (empty($this->huburi)) {
+ if (common_config('feedsub', 'nohub')) {
+ // Fake it! We're just testing remote feeds w/o hubs.
+ return true;
+ } else {
+ throw new ServerException("Attempting to start PuSH subscription for feed with no hub");
+ }
+ }
+
+ return $this->doSubscribe('subscribe');
+ }
+
+ /**
+ * Send a PuSH unsubscription request to the hub for this feed.
+ * The hub will later send us a confirmation POST to /main/push/callback.
+ *
+ * @return bool true on success, false on failure
+ * @throws ServerException if feed state is not valid
+ */
+ public function unsubscribe() {
+ if ($this->sub_state != 'active') {
+ throw new ServerException("Attempting to end PuSH subscription to feed in state $this->sub_state");
+ }
+ if (empty($this->huburi)) {
+ if (common_config('feedsub', 'nohub')) {
+ // Fake it! We're just testing remote feeds w/o hubs.
+ return true;
+ } else {
+ throw new ServerException("Attempting to end PuSH subscription for feed with no hub");
+ }
+ }
+
+ return $this->doSubscribe('unsubscribe');
+ }
+
+ protected function doSubscribe($mode)
+ {
+ $orig = clone($this);
+ $this->verify_token = common_good_rand(16);
+ if ($mode == 'subscribe') {
+ $this->secret = common_good_rand(32);
+ }
+ $this->sub_state = $mode;
+ $this->update($orig);
+ unset($orig);
+
+ try {
+ $callback = common_local_url('pushcallback', array('feed' => $this->id));
+ $headers = array('Content-Type: application/x-www-form-urlencoded');
+ $post = array('hub.mode' => $mode,
+ 'hub.callback' => $callback,
+ 'hub.verify' => 'async',
+ 'hub.verify_token' => $this->verify_token,
+ 'hub.secret' => $this->secret,
+ //'hub.lease_seconds' => 0,
+ 'hub.topic' => $this->uri);
+ $client = new HTTPClient();
+ $response = $client->post($this->huburi, $headers, $post);
+ $status = $response->getStatus();
+ if ($status == 202) {
+ common_log(LOG_INFO, __METHOD__ . ': sub req ok, awaiting verification callback');
+ return true;
+ } else if ($status == 204) {
+ common_log(LOG_INFO, __METHOD__ . ': sub req ok and verified');
+ return true;
+ } else if ($status >= 200 && $status < 300) {
+ common_log(LOG_ERR, __METHOD__ . ": sub req returned unexpected HTTP $status: " . $response->getBody());
+ return false;
+ } else {
+ common_log(LOG_ERR, __METHOD__ . ": sub req failed with HTTP $status: " . $response->getBody());
+ return false;
+ }
+ } catch (Exception $e) {
+ // wtf!
+ common_log(LOG_ERR, __METHOD__ . ": error \"{$e->getMessage()}\" hitting hub $this->huburi subscribing to $this->uri");
+
+ $orig = clone($this);
+ $this->verify_token = null;
+ $this->sub_state = null;
+ $this->update($orig);
+ unset($orig);
+
+ return false;
+ }
+ }
+
+ /**
+ * Save PuSH subscription confirmation.
+ * Sets approximate lease start and end times and finalizes state.
+ *
+ * @param int $lease_seconds provided hub.lease_seconds parameter, if given
+ */
+ public function confirmSubscribe($lease_seconds=0)
+ {
+ $original = clone($this);
+
+ $this->sub_state = 'active';
+ $this->sub_start = common_sql_date(time());
+ if ($lease_seconds > 0) {
+ $this->sub_end = common_sql_date(time() + $lease_seconds);
+ } else {
+ $this->sub_end = null;
+ }
+ $this->lastupdate = common_sql_now();
+
+ return $this->update($original);
+ }
+
+ /**
+ * Save PuSH unsubscription confirmation.
+ * Wipes active PuSH sub info and resets state.
+ */
+ public function confirmUnsubscribe()
+ {
+ $original = clone($this);
+
+ // @fixme these should all be null, but DB_DataObject doesn't save null values...?????
+ $this->verify_token = '';
+ $this->secret = '';
+ $this->sub_state = '';
+ $this->sub_start = '';
+ $this->sub_end = '';
+ $this->lastupdate = common_sql_now();
+
+ return $this->update($original);
+ }
+
+ /**
+ * Accept updates from a PuSH feed. If validated, this object and the
+ * feed (as a DOMDocument) will be passed to the StartFeedSubHandleFeed
+ * and EndFeedSubHandleFeed events for processing.
+ *
+ * @param string $post source of Atom or RSS feed
+ * @param string $hmac X-Hub-Signature header, if present
+ */
+ public function receive($post, $hmac)
+ {
+ common_log(LOG_INFO, __METHOD__ . ": packet for \"$this->uri\"! $hmac $post");
+
+ if ($this->sub_state != 'active') {
+ common_log(LOG_ERR, __METHOD__ . ": ignoring PuSH for inactive feed $this->uri (in state '$this->sub_state')");
+ return;
+ }
+
+ if ($post === '') {
+ common_log(LOG_ERR, __METHOD__ . ": ignoring empty post");
+ return;
+ }
+
+ if (!$this->validatePushSig($post, $hmac)) {
+ // Per spec we silently drop input with a bad sig,
+ // while reporting receipt to the server.
+ return;
+ }
+
+ $feed = new DOMDocument();
+ if (!$feed->loadXML($post)) {
+ // @fixme might help to include the err message
+ common_log(LOG_ERR, __METHOD__ . ": ignoring invalid XML");
+ return;
+ }
+
+ Event::handle('StartFeedSubReceive', array($this, $feed));
+ Event::handle('EndFeedSubReceive', array($this, $feed));
+ }
+
+ /**
+ * Validate the given Atom chunk and HMAC signature against our
+ * shared secret that was set up at subscription time.
+ *
+ * If we don't have a shared secret, there should be no signature.
+ * If we we do, our the calculated HMAC should match theirs.
+ *
+ * @param string $post raw XML source as POSTed to us
+ * @param string $hmac X-Hub-Signature HTTP header value, or empty
+ * @return boolean true for a match
+ */
+ protected function validatePushSig($post, $hmac)
+ {
+ if ($this->secret) {
+ if (preg_match('/^sha1=([0-9a-fA-F]{40})$/', $hmac, $matches)) {
+ $their_hmac = strtolower($matches[1]);
+ $our_hmac = hash_hmac('sha1', $post, $this->secret);
+ if ($their_hmac === $our_hmac) {
+ return true;
+ }
+ common_log(LOG_ERR, __METHOD__ . ": ignoring PuSH with bad SHA-1 HMAC: got $their_hmac, expected $our_hmac");
+ } else {
+ common_log(LOG_ERR, __METHOD__ . ": ignoring PuSH with bogus HMAC '$hmac'");
+ }
+ } else {
+ if (empty($hmac)) {
+ return true;
+ } else {
+ common_log(LOG_ERR, __METHOD__ . ": ignoring PuSH with unexpected HMAC '$hmac'");
+ }
+ }
+ return false;
+ }
+
+}
diff --git a/plugins/OStatus/classes/Ostatus_profile.php b/plugins/OStatus/classes/Ostatus_profile.php
index 486417617..1ce8ac491 100644
--- a/plugins/OStatus/classes/Ostatus_profile.php
+++ b/plugins/OStatus/classes/Ostatus_profile.php
@@ -18,62 +18,24 @@
*/
/**
- * @package FeedSubPlugin
+ * @package OStatusPlugin
* @maintainer Brion Vibber
*/
-/*
-PuSH subscription flow:
-
- $profile->subscribe()
- generate random verification token
- save to verify_token
- sends a sub request to the hub...
-
- main/push/callback
- hub sends confirmation back to us via GET
- We verify the request, then echo back the challenge.
- On our end, we save the time we subscribed and the lease expiration
-
- main/push/callback
- hub sends us updates via POST
-
-*/
-
-class FeedDBException extends FeedSubException
-{
- public $obj;
-
- function __construct($obj)
- {
- parent::__construct('Database insert failure');
- $this->obj = $obj;
- }
-}
-
class Ostatus_profile extends Memcached_DataObject
{
public $__table = 'ostatus_profile';
- public $id;
+ public $uri;
+
public $profile_id;
public $group_id;
public $feeduri;
- public $homeuri;
-
- // PuSH subscription data
- public $huburi;
- public $secret;
- public $verify_token;
- public $sub_state; // subscribe, active, unsubscribe
- public $sub_start;
- public $sub_end;
-
public $salmonuri;
public $created;
- public $lastupdate;
+ public $modified;
public /*static*/ function staticGet($k, $v=null)
{
@@ -91,56 +53,30 @@ class Ostatus_profile extends Memcached_DataObject
function table()
{
- return array('id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
+ return array('uri' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,
'profile_id' => DB_DATAOBJECT_INT,
'group_id' => DB_DATAOBJECT_INT,
'feeduri' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,
- 'homeuri' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,
- 'huburi' => DB_DATAOBJECT_STR,
- 'secret' => DB_DATAOBJECT_STR,
- 'verify_token' => DB_DATAOBJECT_STR,
- 'sub_state' => DB_DATAOBJECT_STR,
- 'sub_start' => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME,
- 'sub_end' => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME,
'salmonuri' => DB_DATAOBJECT_STR,
'created' => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME + DB_DATAOBJECT_NOTNULL,
- 'lastupdate' => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME + DB_DATAOBJECT_NOTNULL);
+ 'modified' => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME + DB_DATAOBJECT_NOTNULL);
}
static function schemaDef()
{
- return array(new ColumnDef('id', 'integer',
- /*size*/ null,
- /*nullable*/ false,
- /*key*/ 'PRI',
- /*default*/ '0',
- /*extra*/ null,
- /*auto_increment*/ true),
+ return array(new ColumnDef('uri', 'varchar',
+ 255, false, 'PRI'),
new ColumnDef('profile_id', 'integer',
null, true, 'UNI'),
new ColumnDef('group_id', 'integer',
null, true, 'UNI'),
new ColumnDef('feeduri', 'varchar',
255, false, 'UNI'),
- new ColumnDef('homeuri', 'varchar',
- 255, false),
- new ColumnDef('huburi', 'text',
- null, true),
- new ColumnDef('verify_token', 'varchar',
- 32, true),
- new ColumnDef('secret', 'varchar',
- 64, true),
- new ColumnDef('sub_state', "enum('subscribe','active','unsubscribe')",
- null, true),
- new ColumnDef('sub_start', 'datetime',
- null, true),
- new ColumnDef('sub_end', 'datetime',
- null, true),
new ColumnDef('salmonuri', 'text',
null, true),
new ColumnDef('created', 'datetime',
null, false),
- new ColumnDef('lastupdate', 'datetime',
+ new ColumnDef('modified', 'datetime',
null, false));
}
@@ -169,12 +105,12 @@ class Ostatus_profile extends Memcached_DataObject
function keyTypes()
{
- return array('id' => 'K', 'profile_id' => 'U', 'group_id' => 'U', 'feeduri' => 'U');
+ return array('uri' => 'K', 'profile_id' => 'U', 'group_id' => 'U', 'feeduri' => 'U');
}
function sequenceKey()
{
- return array('id', true, false);
+ return array(false, false, false);
}
/**
@@ -201,101 +137,6 @@ class Ostatus_profile extends Memcached_DataObject
return null;
}
- /**
- * @param FeedMunger $munger
- * @param boolean $isGroup is this a group record?
- * @return Ostatus_profile
- */
- public static function ensureProfile($munger)
- {
- $profile = $munger->ostatusProfile();
-
- $current = self::staticGet('feeduri', $profile->feeduri);
- if ($current) {
- // @fixme we should probably update info as necessary
- return $current;
- }
-
- $profile->query('BEGIN');
-
- try {
- $local = $munger->profile();
-
- if ($profile->isGroup()) {
- $group = new User_group();
- $group->nickname = $local->nickname . '@remote'; // @fixme
- $group->fullname = $local->fullname;
- $group->homepage = $local->homepage;
- $group->location = $local->location;
- $group->created = $local->created;
- $group->insert();
- if (empty($result)) {
- throw new FeedDBException($group);
- }
- $profile->group_id = $group->id;
- } else {
- $result = $local->insert();
- if (empty($result)) {
- throw new FeedDBException($local);
- }
- $profile->profile_id = $local->id;
- }
-
- $profile->created = common_sql_now();
- $profile->lastupdate = common_sql_now();
- $result = $profile->insert();
- if (empty($result)) {
- throw new FeedDBException($profile);
- }
-
- $profile->query('COMMIT');
- } catch (FeedDBException $e) {
- common_log_db_error($e->obj, 'INSERT', __FILE__);
- $profile->query('ROLLBACK');
- return false;
- }
-
- $avatar = $munger->getAvatar();
- if ($avatar) {
- try {
- $profile->updateAvatar($avatar);
- } catch (Exception $e) {
- common_log(LOG_ERR, "Exception setting OStatus avatar: " .
- $e->getMessage());
- }
- }
-
- return $profile;
- }
-
- /**
- * Download and update given avatar image
- * @param string $url
- * @throws Exception in various failure cases
- */
- public function updateAvatar($url)
- {
- // @fixme this should be better encapsulated
- // ripped from oauthstore.php (for old OMB client)
- $temp_filename = tempnam(sys_get_temp_dir(), 'listener_avatar');
- copy($url, $temp_filename);
-
- // @fixme should we be using different ids?
- $imagefile = new ImageFile($this->id, $temp_filename);
- $filename = Avatar::filename($this->id,
- image_type_to_extension($imagefile->type),
- null,
- common_timestamp());
- rename($temp_filename, Avatar::path($filename));
- if ($this->isGroup()) {
- $group = $this->localGroup();
- $group->setOriginal($filename);
- } else {
- $profile = $this->localProfile();
- $profile->setOriginal($filename);
- }
- }
-
/**
* Returns an XML string fragment with profile information as an
* Activity Streams noun object with the given element type.
@@ -345,7 +186,7 @@ class Ostatus_profile extends Memcached_DataObject
$xs->element(
'id',
null,
- $this->homeuri); // ?
+ $this->uri); // ?
$xs->element('title', null, $self->getBestName());
$xs->element(
@@ -370,142 +211,95 @@ class Ostatus_profile extends Memcached_DataObject
}
/**
- * Send a subscription request to the hub for this feed.
- * The hub will later send us a confirmation POST to /main/push/callback.
+ * Subscribe a local user to this remote user.
+ * PuSH subscription will be started if necessary, and we'll
+ * send a Salmon notification to the remote server if available
+ * notifying them of the sub.
*
- * @return bool true on success, false on failure
- * @throws ServerException if feed state is not valid
+ * @param User $user
+ * @return boolean success
+ * @throws FeedException
*/
- public function subscribe($mode='subscribe')
+ public function subscribeLocalToRemote(User $user)
{
- if ($this->sub_state != '') {
- throw new ServerException("Attempting to start PuSH subscription to feed in state $this->sub_state");
+ if ($this->isGroup()) {
+ throw new ServerException("Can't subscribe to a remote group");
}
- if (empty($this->huburi)) {
- if (common_config('feedsub', 'nohub')) {
- // Fake it! We're just testing remote feeds w/o hubs.
+
+ if ($this->subscribe()) {
+ if ($user->subscribeTo($this->localProfile())) {
+ $this->notify($user->getProfile(), ActivityVerb::FOLLOW, $this);
return true;
- } else {
- throw new ServerException("Attempting to start PuSH subscription for feed with no hub");
}
}
-
- return $this->doSubscribe('subscribe');
+ return false;
}
/**
- * Send a PuSH unsubscription request to the hub for this feed.
- * The hub will later send us a confirmation POST to /main/push/callback.
+ * Mark this remote profile as subscribing to the given local user,
+ * and send appropriate notifications to the user.
*
- * @return bool true on success, false on failure
- * @throws ServerException if feed state is not valid
+ * This will generally be in response to a subscription notification
+ * from a foreign site to our local Salmon response channel.
+ *
+ * @param User $user
+ * @return boolean success
*/
- public function unsubscribe() {
- if ($this->sub_state != 'active') {
- throw new ServerException("Attempting to end PuSH subscription to feed in state $this->sub_state");
- }
- if (empty($this->huburi)) {
- if (common_config('feedsub', 'nohub')) {
- // Fake it! We're just testing remote feeds w/o hubs.
- return true;
- } else {
- throw new ServerException("Attempting to end PuSH subscription for feed with no hub");
- }
- }
-
- return $this->doSubscribe('unsubscribe');
- }
-
- protected function doSubscribe($mode)
+ public function subscribeRemoteToLocal(User $user)
{
- $orig = clone($this);
- $this->verify_token = common_good_rand(16);
- if ($mode == 'subscribe') {
- $this->secret = common_good_rand(32);
- }
- $this->sub_state = $mode;
- $this->update($orig);
- unset($orig);
-
- try {
- $callback = common_local_url('pushcallback', array('feed' => $this->id));
- $headers = array('Content-Type: application/x-www-form-urlencoded');
- $post = array('hub.mode' => $mode,
- 'hub.callback' => $callback,
- 'hub.verify' => 'async',
- 'hub.verify_token' => $this->verify_token,
- 'hub.secret' => $this->secret,
- //'hub.lease_seconds' => 0,
- 'hub.topic' => $this->feeduri);
- $client = new HTTPClient();
- $response = $client->post($this->huburi, $headers, $post);
- $status = $response->getStatus();
- if ($status == 202) {
- common_log(LOG_INFO, __METHOD__ . ': sub req ok, awaiting verification callback');
- return true;
- } else if ($status == 204) {
- common_log(LOG_INFO, __METHOD__ . ': sub req ok and verified');
- return true;
- } else if ($status >= 200 && $status < 300) {
- common_log(LOG_ERR, __METHOD__ . ": sub req returned unexpected HTTP $status: " . $response->getBody());
- return false;
- } else {
- common_log(LOG_ERR, __METHOD__ . ": sub req failed with HTTP $status: " . $response->getBody());
- return false;
- }
- } catch (Exception $e) {
- // wtf!
- common_log(LOG_ERR, __METHOD__ . ": error \"{$e->getMessage()}\" hitting hub $this->huburi subscribing to $this->feeduri");
+ if ($this->isGroup()) {
+ throw new ServerException("Remote groups can't subscribe to local users");
+ }
- $orig = clone($this);
- $this->verify_token = null;
- $this->sub_state = null;
- $this->update($orig);
- unset($orig);
+ // @fixme use regular channels for subbing, once they accept remote profiles
+ $sub = new Subscription();
+ $sub->subscriber = $this->profile_id;
+ $sub->subscribed = $user->id;
+ $sub->created = common_sql_now(); // current time
- return false;
+ if ($sub->insert()) {
+ // @fixme use subs_notify() if refactored to take profiles?
+ mail_subscribe_notify_profile($user, $this->localProfile());
+ return true;
}
+ return false;
}
/**
- * Save PuSH subscription confirmation.
- * Sets approximate lease start and end times and finalizes state.
+ * Send a subscription request to the hub for this feed.
+ * The hub will later send us a confirmation POST to /main/push/callback.
*
- * @param int $lease_seconds provided hub.lease_seconds parameter, if given
+ * @return bool true on success, false on failure
+ * @throws ServerException if feed state is not valid
*/
- public function confirmSubscribe($lease_seconds=0)
+ public function subscribe($mode='subscribe')
{
- $original = clone($this);
-
- $this->sub_state = 'active';
- $this->sub_start = common_sql_date(time());
- if ($lease_seconds > 0) {
- $this->sub_end = common_sql_date(time() + $lease_seconds);
- } else {
- $this->sub_end = null;
+ $feedsub = FeedSub::ensureFeed($this->feeduri);
+ if ($feedsub->sub_state == 'active' || $feedsub->sub_state == 'subscribe') {
+ return true;
+ } else if ($feedsub->sub_state == '' || $feedsub->sub_state == 'inactive') {
+ return $feedsub->subscribe();
+ } else if ('unsubscribe') {
+ throw new FeedSubException("Unsub is pending, can't subscribe...");
}
- $this->lastupdate = common_sql_now();
-
- return $this->update($original);
}
/**
- * Save PuSH unsubscription confirmation.
- * Wipes active PuSH sub info and resets state.
+ * Send a PuSH unsubscription request to the hub for this feed.
+ * The hub will later send us a confirmation POST to /main/push/callback.
+ *
+ * @return bool true on success, false on failure
+ * @throws ServerException if feed state is not valid
*/
- public function confirmUnsubscribe()
- {
- $original = clone($this);
-
- // @fixme these should all be null, but DB_DataObject doesn't save null values...?????
- $this->verify_token = '';
- $this->secret = '';
- $this->sub_state = '';
- $this->sub_start = '';
- $this->sub_end = '';
- $this->lastupdate = common_sql_now();
-
- return $this->update($original);
+ public function unsubscribe() {
+ $feedsub = FeedSub::staticGet('uri', $this->feeduri);
+ if ($feedsub->sub_state == 'active') {
+ return $feedsub->unsubscribe();
+ } else if ($feedsub->sub_state == '' || $feedsub->sub_state == 'inactive' || $feedsub->sub_state == 'unsubscribe') {
+ return true;
+ } else if ($feedsub->sub_state == 'subscribe') {
+ throw new FeedSubException("Feed is awaiting subscription, can't unsub...");
+ }
}
/**
@@ -543,10 +337,7 @@ class Ostatus_profile extends Memcached_DataObject
$entry->elementEnd('entry');
$feed = $this->atomFeed($actor);
- #$feed->initFeed();
$feed->addEntry($entry);
- #$feed->renderEntries();
- #$feed->endFeed();
$xml = $feed->getString();
common_log(LOG_INFO, "Posting to Salmon endpoint $salmon: $xml");
@@ -600,36 +391,10 @@ class Ostatus_profile extends Memcached_DataObject
* Currently assumes that all items in the feed are new,
* coming from a PuSH hub.
*
- * @param string $post source of Atom or RSS feed
- * @param string $hmac X-Hub-Signature header, if present
+ * @param DOMDocument $feed
*/
- public function postUpdates($post, $hmac)
+ public function processFeed($feed)
{
- common_log(LOG_INFO, __METHOD__ . ": packet for \"$this->feeduri\"! $hmac $post");
-
- if ($this->sub_state != 'active') {
- common_log(LOG_ERR, __METHOD__ . ": ignoring PuSH for inactive feed $this->feeduri (in state '$this->sub_state')");
- return;
- }
-
- if ($post === '') {
- common_log(LOG_ERR, __METHOD__ . ": ignoring empty post");
- return;
- }
-
- if (!$this->validatePushSig($post, $hmac)) {
- // Per spec we silently drop input with a bad sig,
- // while reporting receipt to the server.
- return;
- }
-
- $feed = new DOMDocument();
- if (!$feed->loadXML($post)) {
- // @fixme might help to include the err message
- common_log(LOG_ERR, __METHOD__ . ": ignoring invalid XML");
- return;
- }
-
$entries = $feed->getElementsByTagNameNS(Activity::ATOM, 'entry');
if ($entries->length == 0) {
common_log(LOG_ERR, __METHOD__ . ": no entries in feed update, ignoring");
@@ -642,40 +407,6 @@ class Ostatus_profile extends Memcached_DataObject
}
}
- /**
- * Validate the given Atom chunk and HMAC signature against our
- * shared secret that was set up at subscription time.
- *
- * If we don't have a shared secret, there should be no signature.
- * If we we do, our the calculated HMAC should match theirs.
- *
- * @param string $post raw XML source as POSTed to us
- * @param string $hmac X-Hub-Signature HTTP header value, or empty
- * @return boolean true for a match
- */
- protected function validatePushSig($post, $hmac)
- {
- if ($this->secret) {
- if (preg_match('/^sha1=([0-9a-fA-F]{40})$/', $hmac, $matches)) {
- $their_hmac = strtolower($matches[1]);
- $our_hmac = hash_hmac('sha1', $post, $this->secret);
- if ($their_hmac === $our_hmac) {
- return true;
- }
- common_log(LOG_ERR, __METHOD__ . ": ignoring PuSH with bad SHA-1 HMAC: got $their_hmac, expected $our_hmac");
- } else {
- common_log(LOG_ERR, __METHOD__ . ": ignoring PuSH with bogus HMAC '$hmac'");
- }
- } else {
- if (empty($hmac)) {
- return true;
- } else {
- common_log(LOG_ERR, __METHOD__ . ": ignoring PuSH with unexpected HMAC '$hmac'");
- }
- }
- return false;
- }
-
/**
* Process a posted entry from this feed source.
*
@@ -704,14 +435,14 @@ class Ostatus_profile extends Memcached_DataObject
{
if ($this->isGroup()) {
// @fixme validate these profiles in some way!
- $oprofile = $this->ensureActorProfile($activity);
+ $oprofile = self::ensureActorProfile($activity);
} else {
- $actorUri = $this->getActorProfileURI($activity);
- if ($actorUri == $this->homeuri) {
+ $actorUri = self::getActorProfileURI($activity);
+ if ($actorUri == $this->uri) {
// @fixme check if profile info has changed and update it
} else {
// @fixme drop or reject the messages once we've got the canonical profile URI recorded sanely
- common_log(LOG_INFO, "OStatus: Warning: non-group post with unexpected author: $actorUri expected $this->homeuri");
+ common_log(LOG_INFO, "OStatus: Warning: non-group post with unexpected author: $actorUri expected $this->uri");
//return;
}
$oprofile = $this;
@@ -787,6 +518,65 @@ class Ostatus_profile extends Memcached_DataObject
return false;
}
+ /**
+ * @param string $profile_url
+ * @return Ostatus_profile
+ * @throws FeedSubException
+ */
+ public static function ensureProfile($profile_uri)
+ {
+ // Get the canonical feed URI and check it
+ $discover = new FeedDiscovery();
+ $feeduri = $discover->discoverFromURL($profile_uri);
+
+ $feedsub = FeedSub::ensureFeed($feeduri, $discover->feed);
+ $huburi = $discover->getAtomLink('hub');
+ $salmonuri = $discover->getAtomLink('salmon');
+
+ if (!$huburi) {
+ // We can only deal with folks with a PuSH hub
+ throw new FeedSubNoHubException();
+ }
+
+ // Ok this is going to be a terrible hack!
+ // Won't be suitable for groups, empty feeds, or getting
+ // info that's only available on the profile page.
+ $entries = $discover->feed->getElementsByTagNameNS(Activity::ATOM, 'entry');
+ if (!$entries || $entries->length == 0) {
+ throw new FeedSubException('empty feed');
+ }
+ $first = new Activity($entries->item(0), $discover->feed);
+ return self::ensureActorProfile($first, $feeduri);
+ }
+
+ /**
+ * Download and update given avatar image
+ * @param string $url
+ * @throws Exception in various failure cases
+ */
+ protected function updateAvatar($url)
+ {
+ // @fixme this should be better encapsulated
+ // ripped from oauthstore.php (for old OMB client)
+ $temp_filename = tempnam(sys_get_temp_dir(), 'listener_avatar');
+ copy($url, $temp_filename);
+
+ // @fixme should we be using different ids?
+ $imagefile = new ImageFile($this->id, $temp_filename);
+ $filename = Avatar::filename($this->id,
+ image_type_to_extension($imagefile->type),
+ null,
+ common_timestamp());
+ rename($temp_filename, Avatar::path($filename));
+ if ($this->isGroup()) {
+ $group = $this->localGroup();
+ $group->setOriginal($filename);
+ } else {
+ $profile = $this->localProfile();
+ $profile->setOriginal($filename);
+ }
+ }
+
/**
* Get an appropriate avatar image source URL, if available.
*
@@ -794,7 +584,7 @@ class Ostatus_profile extends Memcached_DataObject
* @param DOMElement $feed
* @return string
*/
- function getAvatar($actor, $feed)
+ protected static function getAvatar($actor, $feed)
{
$url = '';
$icon = '';
@@ -833,13 +623,18 @@ class Ostatus_profile extends Memcached_DataObject
}
/**
- * @fixme move off of ostatus_profile or static?
+ * Fetch, or build if necessary, an Ostatus_profile for the actor
+ * in a given Activity Streams activity.
+ *
+ * @param Activity $activity
+ * @param string $feeduri if we already know the canonical feed URI!
+ * @return Ostatus_profile
*/
- function ensureActorProfile($activity)
+ public static function ensureActorProfile($activity, $feeduri=null)
{
- $profile = $this->getActorProfile($activity);
+ $profile = self::getActorProfile($activity);
if (!$profile) {
- $profile = $this->createActorProfile($activity);
+ $profile = self::createActorProfile($activity, $feeduri);
}
return $profile;
}
@@ -848,10 +643,10 @@ class Ostatus_profile extends Memcached_DataObject
* @param Activity $activity
* @return mixed matching Ostatus_profile or false if none known
*/
- function getActorProfile($activity)
+ protected static function getActorProfile($activity)
{
- $homeuri = $this->getActorProfileURI($activity);
- return Ostatus_profile::staticGet('homeuri', $homeuri);
+ $homeuri = self::getActorProfileURI($activity);
+ return self::staticGet('uri', $homeuri);
}
/**
@@ -859,7 +654,7 @@ class Ostatus_profile extends Memcached_DataObject
* @return string
* @throws ServerException
*/
- function getActorProfileURI($activity)
+ protected static function getActorProfileURI($activity)
{
$opts = array('allowed_schemes' => array('http', 'https'));
$actor = $activity->actor;
@@ -873,14 +668,19 @@ class Ostatus_profile extends Memcached_DataObject
}
/**
- *
+ * @fixme validate stuff somewhere
*/
- function createActorProfile($activity)
+ protected static function createActorProfile($activity, $feeduri=null)
{
- $actor = $activity->actor();
- $homeuri = $this->getActivityProfileURI($activity);
- $nickname = $this->getAuthorNick($activity);
- $avatar = $this->getAvatar($actor, $feed);
+ $actor = $activity->actor;
+ $homeuri = self::getActorProfileURI($activity);
+ $nickname = self::getAuthorNick($activity);
+ $avatar = self::getAvatar($actor, $feed);
+
+ if (!$homeuri) {
+ common_log(LOG_DEBUG, __METHOD__ . " empty actor profile URI: " . var_export($activity, true));
+ throw new ServerException("No profile URI");
+ }
$profile = new Profile();
$profile->nickname = $nickname;
@@ -894,9 +694,7 @@ class Ostatus_profile extends Memcached_DataObject
// @todo lat/lon/location?
$ok = $profile->insert();
- if ($ok) {
- $this->updateAvatar($profile, $avatar);
- } else {
+ if (!$ok) {
throw new ServerException("Can't save local profile");
}
@@ -904,11 +702,15 @@ class Ostatus_profile extends Memcached_DataObject
// or need to split out some of the feed stuff
// so we can leave it empty until later.
$oprofile = new Ostatus_profile();
- $oprofile->homeuri = $homeuri;
+ $oprofile->uri = $homeuri;
+ if ($feeduri) {
+ $oprofile->feeduri = $feeduri;
+ }
$oprofile->profile_id = $profile->id;
$ok = $oprofile->insert();
if ($ok) {
+ $oprofile->updateAvatar($avatar);
return $oprofile;
} else {
throw new ServerException("Can't save OStatus profile");
@@ -920,13 +722,13 @@ class Ostatus_profile extends Memcached_DataObject
* @param Activity $activity
* @return string
*/
- function getAuthorNick($activity)
+ protected static function getAuthorNick($activity)
{
// @fixme not technically part of the actor?
foreach (array($activity->entry, $activity->feed) as $source) {
- $author = ActivityUtil::child($source, 'author', Activity::ATOM);
+ $author = ActivityUtils::child($source, 'author', Activity::ATOM);
if ($author) {
- $name = ActivityUtil::child($author, 'name', Activity::ATOM);
+ $name = ActivityUtils::child($author, 'name', Activity::ATOM);
if ($name) {
return trim($name->textContent);
}
diff --git a/plugins/OStatus/lib/feeddiscovery.php b/plugins/OStatus/lib/feeddiscovery.php
index 39985fc90..7afb71bdc 100644
--- a/plugins/OStatus/lib/feeddiscovery.php
+++ b/plugins/OStatus/lib/feeddiscovery.php
@@ -48,6 +48,14 @@ class FeedSubNoFeedException extends FeedSubException
{
}
+class FeedSubBadXmlException extends FeedSubException
+{
+}
+
+class FeedSubNoHubException extends FeedSubException
+{
+}
+
/**
* Given a web page or feed URL, discover the final location of the feed
* and return its current contents.
@@ -57,21 +65,25 @@ class FeedSubNoFeedException extends FeedSubException
* if ($feed->discoverFromURL($url)) {
* print $feed->uri;
* print $feed->type;
- * processFeed($feed->body);
+ * processFeed($feed->feed); // DOMDocument
* }
*/
class FeedDiscovery
{
public $uri;
public $type;
- public $body;
+ public $feed;
+ /** Post-initialize query helper... */
+ public function getLink($rel, $type=null)
+ {
+ // @fixme check for non-Atom links in RSS2 feeds as well
+ return self::getAtomLink($rel, $type);
+ }
- public function feedMunger()
+ public function getAtomLink($rel, $type=null)
{
- require_once 'XML/Feed/Parser.php';
- $feed = new XML_Feed_Parser($this->body, false, false, true); // @fixme
- return new FeedMunger($feed, $this->uri);
+ return ActivityUtils::getLink($this->feed->documentElement, $rel, $type);
}
/**
@@ -90,6 +102,7 @@ class FeedDiscovery
$client = new HTTPClient();
$response = $client->get($url);
} catch (HTTP_Request2_Exception $e) {
+ common_log(LOG_ERR, __METHOD__ . " Failure for $url - " . $e->getMessage());
throw new FeedSubBadURLException($e);
}
@@ -107,7 +120,12 @@ class FeedDiscovery
return $this->initFromResponse($response);
}
-
+
+ function discoverFromFeedURL($url)
+ {
+ return $this->discoverFromURL($url, false);
+ }
+
function initFromResponse($response)
{
if (!$response->isOk()) {
@@ -122,16 +140,26 @@ class FeedDiscovery
$type = $response->getHeader('Content-Type');
if (preg_match('!^(text/xml|application/xml|application/(rss|atom)\+xml)!i', $type)) {
- $this->uri = $sourceurl;
- $this->type = $type;
- $this->body = $body;
- return true;
+ return $this->init($sourceurl, $type, $body);
} else {
common_log(LOG_WARNING, "Unrecognized feed type $type for $sourceurl");
throw new FeedSubUnrecognizedTypeException($type);
}
}
+ function init($sourceurl, $type, $body)
+ {
+ $feed = new DOMDocument();
+ if ($feed->loadXML($body)) {
+ $this->uri = $sourceurl;
+ $this->type = $type;
+ $this->feed = $feed;
+ return $this->uri;
+ } else {
+ throw new FeedSubBadXmlException($url);
+ }
+ }
+
/**
* @param string $url source URL, used to resolve relative links
* @param string $body HTML body text
diff --git a/plugins/OStatus/lib/feedmunger.php b/plugins/OStatus/lib/feedmunger.php
deleted file mode 100644
index e8c46de90..000000000
--- a/plugins/OStatus/lib/feedmunger.php
+++ /dev/null
@@ -1,350 +0,0 @@
-.
- */
-
-/**
- * @package FeedSubPlugin
- * @maintainer Brion Vibber
- */
-
-if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
-
-class FeedSubPreviewNotice extends Notice
-{
- protected $fetched = true;
-
- function __construct($profile)
- {
- $this->profile = $profile;
- $this->profile_id = 0;
- }
-
- function getProfile()
- {
- return $this->profile;
- }
-
- function find()
- {
- return true;
- }
-
- function fetch()
- {
- $got = $this->fetched;
- $this->fetched = false;
- return $got;
- }
-}
-
-class FeedSubPreviewProfile extends Profile
-{
- function getAvatar($width, $height=null)
- {
- return new FeedSubPreviewAvatar($width, $height, $this->avatar);
- }
-}
-
-class FeedSubPreviewAvatar extends Avatar
-{
- function __construct($width, $height, $remote)
- {
- $this->remoteImage = $remote;
- }
-
- function displayUrl() {
- return $this->remoteImage;
- }
-}
-
-class FeedMunger
-{
- /**
- * @param XML_Feed_Parser $feed
- */
- function __construct($feed, $url=null)
- {
- $this->feed = $feed;
- $this->url = $url;
- }
-
- function ostatusProfile()
- {
- $profile = new Ostatus_profile();
- $profile->feeduri = $this->url;
- $profile->homeuri = $this->feed->link;
- $profile->huburi = $this->getHubLink();
- $salmon = $this->getSalmonLink();
- if ($salmon) {
- $profile->salmonuri = $salmon;
- }
- return $profile;
- }
-
- function getAtomLink($item, $attribs=array())
- {
- // XML_Feed_Parser gets confused by multiple elements.
- $dom = $item->model;
-
- // Note that RSS feeds would embed an so this should work for both.
- /// http://code.google.com/p/pubsubhubbub/wiki/RssFeeds
- //
- $links = $dom->getElementsByTagNameNS('http://www.w3.org/2005/Atom', 'link');
- for ($i = 0; $i < $links->length; $i++) {
- $node = $links->item($i);
- if ($node->hasAttributes()) {
- $href = $node->attributes->getNamedItem('href');
- if ($href) {
- $matches = 0;
- foreach ($attribs as $name => $val) {
- $attrib = $node->attributes->getNamedItem($name);
- if ($attrib && $attrib->value == $val) {
- $matches++;
- }
- }
- if ($matches == count($attribs)) {
- return $href->value;
- }
- }
- }
- }
- return false;
- }
-
- function getRssLink($item)
- {
- // XML_Feed_Parser gets confused by multiple elements.
- $dom = $item->model;
-
- // Note that RSS feeds would embed an so this should work for both.
- /// http://code.google.com/p/pubsubhubbub/wiki/RssFeeds
- //
- $links = $dom->getElementsByTagName('link');
- for ($i = 0; $i < $links->length; $i++) {
- $node = $links->item($i);
- if (!$node->hasAttributes()) {
- return $node->textContent;
- }
- }
- return false;
- }
-
- function getAltLink($item)
- {
- // Check for an atom link...
- $link = $this->getAtomLink($item, array('rel' => 'alternate', 'type' => 'text/html'));
- if (!$link) {
- $link = $this->getRssLink($item);
- }
- return $link;
- }
-
- function getHubLink()
- {
- return $this->getAtomLink($this->feed, array('rel' => 'hub'));
- }
-
- function getSalmonLink()
- {
- return $this->getAtomLink($this->feed, array('rel' => 'salmon'));
- }
-
- function getSelfLink()
- {
- return $this->getAtomLink($this->feed, array('rel' => 'self'));
- }
-
- /**
- * Get an appropriate avatar image source URL, if available.
- * @return mixed string or false
- */
- function getAvatar()
- {
- $logo = $this->feed->logo;
- if ($logo) {
- return $logo;
- }
- $icon = $this->feed->icon;
- if ($icon) {
- return $icon;
- }
- return common_path('plugins/OStatus/images/48px-Feed-icon.svg.png');
- }
-
- function profile($preview=false)
- {
- if ($preview) {
- $profile = new FeedSubPreviewProfile();
- } else {
- $profile = new Profile();
- }
-
- // @todo validate/normalize nick?
- $profile->nickname = $this->feed->title;
- $profile->fullname = $this->feed->title;
- $profile->homepage = $this->getAltLink($this->feed);
- $profile->bio = $this->feed->description;
- $profile->profileurl = $this->getAltLink($this->feed);
-
- if ($preview) {
- $profile->avatar = $this->getAvatar();
- }
-
- // @todo tags from categories
- // @todo lat/lon/location?
-
- return $profile;
- }
-
- function notice($index=1, $preview=false)
- {
- $entry = $this->feed->getEntryByOffset($index);
- if (!$entry) {
- return null;
- }
-
- if ($preview) {
- $notice = new FeedSubPreviewNotice($this->profile(true));
- $notice->id = -1;
- } else {
- $notice = new Notice();
- $notice->profile_id = $this->profileIdForEntry($index);
- }
-
- $link = $this->getAltLink($entry);
- if (empty($link)) {
- if (preg_match('!^https?://!', $entry->id)) {
- $link = $entry->id;
- common_log(LOG_DEBUG, "No link on entry, using URL from id: $link");
- }
- }
- $notice->uri = $link;
- $notice->url = $link;
- $notice->content = $this->noticeFromEntry($entry);
- $notice->rendered = common_render_content($notice->content, $notice); // @fixme this is failing on group posts
- $notice->created = common_sql_date($entry->updated); // @fixme
- $notice->is_local = Notice::GATEWAY;
- $notice->source = 'feed';
-
- $location = $this->getLocation($entry);
- if ($location) {
- if ($location->location_id) {
- $notice->location_ns = $location->location_ns;
- $notice->location_id = $location->location_id;
- }
- $notice->lat = $location->lat;
- $notice->lon = $location->lon;
- }
-
- return $notice;
- }
-
- function profileIdForEntry($index=1)
- {
- // hack hack hack
- // should get profile for this entry's author...
- $feeduri = $this->getSelfLink();
- $remote = Ostatus_profile::staticGet('feeduri', $feeduri);
- if ($remote) {
- return $remote->profile_id;
- } else {
- throw new Exception("Can't find feed profile for $feeduri");
- }
- }
-
- /**
- * Parse location given as a GeoRSS-simple point, if provided.
- * http://www.georss.org/simple
- *
- * @param feed item $entry
- * @return mixed Location or false
- */
- function getLocation($entry)
- {
- $dom = $entry->model;
- $points = $dom->getElementsByTagNameNS('http://www.georss.org/georss', 'point');
-
- for ($i = 0; $i < $points->length; $i++) {
- $point = $points->item(0)->textContent;
- $point = str_replace(',', ' ', $point); // per spec "treat commas as whitespace"
- $point = preg_replace('/\s+/', ' ', $point);
- $point = trim($point);
- $coords = explode(' ', $point);
- if (count($coords) == 2) {
- list($lat, $lon) = $coords;
- if (is_numeric($lat) && is_numeric($lon)) {
- common_log(LOG_INFO, "Looking up location for $lat $lon from georss");
- return Location::fromLatLon($lat, $lon);
- }
- }
- common_log(LOG_ERR, "Ignoring bogus georss:point value $point");
- }
-
- return false;
- }
-
- /**
- * @param XML_Feed_Type $entry
- * @return string notice text, within post size limit
- */
- function noticeFromEntry($entry)
- {
- $max = Notice::maxContent();
- $ellipsis = "\xe2\x80\xa6"; // U+2026 HORIZONTAL ELLIPSIS
- $title = $entry->title;
- $link = $entry->link;
-
- // @todo We can get 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.
-
- $title = $entry->title;
- $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);
-
- // 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;
- }
-}
--
cgit v1.2.3-54-g00ecf
From 48edade751cca3ac7363808264a76c470a520528 Mon Sep 17 00:00:00 2001
From: Evan Prodromou
Date: Thu, 18 Feb 2010 22:18:14 -0500
Subject: add ActivityContext class and test it
---
plugins/OStatus/actions/salmon.php | 1 +
plugins/OStatus/classes/Ostatus_profile.php | 32 +----------
plugins/OStatus/lib/activity.php | 85 +++++++++++++++++++++++++++-
plugins/OStatus/tests/ActivityParseTests.php | 53 ++++++++++++++++-
4 files changed, 138 insertions(+), 33 deletions(-)
(limited to 'plugins/OStatus')
diff --git a/plugins/OStatus/actions/salmon.php b/plugins/OStatus/actions/salmon.php
index ea5b8e4ea..e9d6015f4 100644
--- a/plugins/OStatus/actions/salmon.php
+++ b/plugins/OStatus/actions/salmon.php
@@ -71,6 +71,7 @@ class SalmonAction extends Action
/**
* @fixme probably call Ostatus_profile::processFeed
*/
+
function handle($args)
{
common_log(LOG_INFO, 'Salmon: incoming post for user '. $this->user->id);
diff --git a/plugins/OStatus/classes/Ostatus_profile.php b/plugins/OStatus/classes/Ostatus_profile.php
index 1ce8ac491..e0cb467e5 100644
--- a/plugins/OStatus/classes/Ostatus_profile.php
+++ b/plugins/OStatus/classes/Ostatus_profile.php
@@ -488,36 +488,6 @@ class Ostatus_profile extends Memcached_DataObject
$params);
}
- /**
- * Parse location given as a GeoRSS-simple point, if provided.
- * http://www.georss.org/simple
- *
- * @param feed item $entry
- * @return mixed Location or false
- */
- function getLocation($dom)
- {
- $points = $dom->getElementsByTagNameNS('http://www.georss.org/georss', 'point');
-
- for ($i = 0; $i < $points->length; $i++) {
- $point = $points->item(0)->textContent;
- $point = str_replace(',', ' ', $point); // per spec "treat commas as whitespace"
- $point = preg_replace('/\s+/', ' ', $point);
- $point = trim($point);
- $coords = explode(' ', $point);
- if (count($coords) == 2) {
- list($lat, $lon) = $coords;
- if (is_numeric($lat) && is_numeric($lon)) {
- common_log(LOG_INFO, "Looking up location for $lat $lon from georss");
- return Location::fromLatLon($lat, $lon);
- }
- }
- common_log(LOG_ERR, "Ignoring bogus georss:point value $point");
- }
-
- return false;
- }
-
/**
* @param string $profile_url
* @return Ostatus_profile
@@ -560,7 +530,7 @@ class Ostatus_profile extends Memcached_DataObject
// ripped from oauthstore.php (for old OMB client)
$temp_filename = tempnam(sys_get_temp_dir(), 'listener_avatar');
copy($url, $temp_filename);
-
+
// @fixme should we be using different ids?
$imagefile = new ImageFile($this->id, $temp_filename);
$filename = Avatar::filename($this->id,
diff --git a/plugins/OStatus/lib/activity.php b/plugins/OStatus/lib/activity.php
index 3ed613dc7..5bc8f78e5 100644
--- a/plugins/OStatus/lib/activity.php
+++ b/plugins/OStatus/lib/activity.php
@@ -311,6 +311,87 @@ class ActivityVerb
const LEAVE = 'http://ostatus.org/schema/1.0/leave';
}
+class ActivityContext
+{
+ public $replyToID;
+ public $replyToUrl;
+ public $location;
+ public $attention = array();
+ public $conversation;
+
+ const THR = 'http://purl.org/syndication/thread/1.0';
+ const GEORSS = 'http://www.georss.org/georss';
+ const OSTATUS = 'http://ostatus.org/schema/1.0';
+
+ const INREPLYTO = 'in-reply-to';
+ const REF = 'ref';
+ const HREF = 'href';
+
+ const POINT = 'point';
+
+ const ATTENTION = 'ostatus:attention';
+ const CONVERSATION = 'ostatus:conversation';
+
+ function __construct($element)
+ {
+ $replyToEl = ActivityUtils::child($element, self::INREPLYTO, self::THR);
+
+ if (!empty($replyToEl)) {
+ $this->replyToID = $replyToEl->getAttribute(self::REF);
+ $this->replyToUrl = $replyToEl->getAttribute(self::HREF);
+ }
+
+ $this->location = $this->getLocation($element);
+
+ $this->conversation = ActivityUtils::getLink($element, self::CONVERSATION);
+
+ // Multiple attention links allowed
+
+ $links = $element->getElementsByTagNameNS(ActivityUtils::ATOM, ActivityUtils::LINK);
+
+ for ($i = 0; $i < $links->length; $i++) {
+
+ $link = $links->item($i);
+
+ $linkRel = $link->getAttribute(ActivityUtils::REL);
+
+ if ($linkRel == self::ATTENTION) {
+ $this->attention[] = $link->getAttribute(self::HREF);
+ }
+ }
+ }
+
+ /**
+ * Parse location given as a GeoRSS-simple point, if provided.
+ * http://www.georss.org/simple
+ *
+ * @param feed item $entry
+ * @return mixed Location or false
+ */
+ function getLocation($dom)
+ {
+ $points = $dom->getElementsByTagNameNS(self::GEORSS, self::POINT);
+
+ for ($i = 0; $i < $points->length; $i++) {
+ $point = $points->item($i)->textContent;
+ $point = str_replace(',', ' ', $point); // per spec "treat commas as whitespace"
+ $point = preg_replace('/\s+/', ' ', $point);
+ $point = trim($point);
+ $coords = explode(' ', $point);
+ if (count($coords) == 2) {
+ list($lat, $lon) = $coords;
+ if (is_numeric($lat) && is_numeric($lon)) {
+ common_log(LOG_INFO, "Looking up location for $lat $lon from georss");
+ return Location::fromLatLon($lat, $lon);
+ }
+ }
+ common_log(LOG_ERR, "Ignoring bogus georss:point value $point");
+ }
+
+ return null;
+ }
+}
+
/**
* An activity in the ActivityStrea.ms world
*
@@ -426,7 +507,9 @@ class Activity
$contextEl = $this->_child($entry, self::CONTEXT);
if (!empty($contextEl)) {
- $this->context = new ActivityObject($contextEl);
+ $this->context = new ActivityContext($contextEl);
+ } else {
+ $this->context = new ActivityContext($entry);
}
$targetEl = $this->_child($entry, self::TARGET);
diff --git a/plugins/OStatus/tests/ActivityParseTests.php b/plugins/OStatus/tests/ActivityParseTests.php
index fa8bcdda2..35b4b0f9d 100644
--- a/plugins/OStatus/tests/ActivityParseTests.php
+++ b/plugins/OStatus/tests/ActivityParseTests.php
@@ -57,12 +57,35 @@ class ActivityParseTests extends PHPUnit_Framework_TestCase
$this->assertEquals($act->object->summary, 'Some text.');
$this->assertEquals($act->object->link, 'http://example.org/2003/12/13/atom03.html');
- $this->assertTrue(empty($act->context));
+ $this->assertFalse(empty($act->context));
+
$this->assertTrue(empty($act->target));
$this->assertEquals($act->entry, $entry);
$this->assertEquals($act->feed, $feed);
}
+
+ public function testExample4()
+ {
+ global $_example4;
+ $dom = DOMDocument::loadXML($_example4);
+
+ $entry = $dom->documentElement;
+
+ $act = new Activity($entry);
+
+ $this->assertFalse(empty($act));
+ $this->assertEquals(1266547958, $act->time);
+ $this->assertEquals('http://example.net/notice/14', $act->link);
+
+ $this->assertFalse(empty($act->context));
+ $this->assertEquals('http://example.net/notice/12', $act->context->replyToID);
+ $this->assertEquals('http://example.net/notice/12', $act->context->replyToUrl);
+ $this->assertEquals('http://example.net/conversation/11', $act->context->conversation);
+ $this->assertEquals(array('http://example.net/user/1'), $act->context->attention);
+
+ $this->assertFalse(empty($act->actor));
+ }
}
$_example1 = <<
EXAMPLE3;
+
+$_example4 = <<
+
+ @evan now is the time for all good men to come to the aid of their country. #thetime
+ @evan now is the time for all good men to come to the aid of their country. #thetime
+
+ spock
+ http://example.net/user/2
+
+
+ http://activitystrea.ms/schema/1.0/person
+ http://example.net/user/2
+ spock
+
+
+
+ http://example.net/notice/14
+ 2010-02-19T02:52:38+00:00
+ 2010-02-19T02:52:38+00:00
+
+
+
+
+ @<span class="vcard"><a href="http://example.net/user/1" class="url"><span class="fn nickname">evan</span></a></span> now is the time for all good men to come to the aid of their country. #<span class="tag"><a href="http://example.net/tag/thetime" rel="tag">thetime</a></span>
+
+
+EXAMPLE4;
--
cgit v1.2.3-54-g00ecf
From 114eb310ca4f53e09c98f2337850829a9036c133 Mon Sep 17 00:00:00 2001
From: Brion Vibber
Date: Fri, 19 Feb 2010 10:29:06 -0800
Subject: OStatus: fix up Salmon endpoint detection/saving, timestamp fixes.
---
plugins/OStatus/actions/salmon.php | 2 +-
plugins/OStatus/classes/FeedSub.php | 2 +-
plugins/OStatus/classes/Ostatus_profile.php | 18 +++++++++++++-----
3 files changed, 15 insertions(+), 7 deletions(-)
(limited to 'plugins/OStatus')
diff --git a/plugins/OStatus/actions/salmon.php b/plugins/OStatus/actions/salmon.php
index e9d6015f4..2da9db9eb 100644
--- a/plugins/OStatus/actions/salmon.php
+++ b/plugins/OStatus/actions/salmon.php
@@ -142,7 +142,7 @@ class SalmonAction extends Action
function ensureProfile()
{
$actor = $this->act->actor;
-
+ common_log(LOG_DEBUG, "Received salmon bit: " . var_export($this->act, true));
if (empty($actor->id)) {
throw new Exception("Received a salmon slap from unidentified actor.");
}
diff --git a/plugins/OStatus/classes/FeedSub.php b/plugins/OStatus/classes/FeedSub.php
index dc2c0b710..bf9d063fa 100644
--- a/plugins/OStatus/classes/FeedSub.php
+++ b/plugins/OStatus/classes/FeedSub.php
@@ -99,7 +99,7 @@ class FeedSub extends Memcached_DataObject
'sub_state' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,
'sub_start' => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME,
'sub_end' => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME,
- 'last_update' => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME + DB_DATAOBJECT_NOTNULL,
+ 'last_update' => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME,
'created' => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME + DB_DATAOBJECT_NOTNULL,
'modified' => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME + DB_DATAOBJECT_NOTNULL);
}
diff --git a/plugins/OStatus/classes/Ostatus_profile.php b/plugins/OStatus/classes/Ostatus_profile.php
index e0cb467e5..319b76a66 100644
--- a/plugins/OStatus/classes/Ostatus_profile.php
+++ b/plugins/OStatus/classes/Ostatus_profile.php
@@ -328,7 +328,7 @@ class Ostatus_profile extends Memcached_DataObject
$entry->element('id', null, $id);
$entry->element('title', null, $text);
$entry->element('summary', null, $text);
- $entry->element('published', null, common_date_w3dtf(time()));
+ $entry->element('published', null, common_date_w3dtf(common_sql_now()));
$entry->element('activity:verb', null, $verb);
$entry->raw($actor->asAtomAuthor());
@@ -516,7 +516,7 @@ class Ostatus_profile extends Memcached_DataObject
throw new FeedSubException('empty feed');
}
$first = new Activity($entries->item(0), $discover->feed);
- return self::ensureActorProfile($first, $feeduri);
+ return self::ensureActorProfile($first, $feeduri, $salmonuri);
}
/**
@@ -598,13 +598,14 @@ class Ostatus_profile extends Memcached_DataObject
*
* @param Activity $activity
* @param string $feeduri if we already know the canonical feed URI!
+ * @param string $salmonuri if we already know the salmon return channel URI
* @return Ostatus_profile
*/
- public static function ensureActorProfile($activity, $feeduri=null)
+ public static function ensureActorProfile($activity, $feeduri=null, $salmonuri=null)
{
$profile = self::getActorProfile($activity);
if (!$profile) {
- $profile = self::createActorProfile($activity, $feeduri);
+ $profile = self::createActorProfile($activity, $feeduri, $salmonuri);
}
return $profile;
}
@@ -640,7 +641,7 @@ class Ostatus_profile extends Memcached_DataObject
/**
* @fixme validate stuff somewhere
*/
- protected static function createActorProfile($activity, $feeduri=null)
+ protected static function createActorProfile($activity, $feeduri=null, $salmonuri=null)
{
$actor = $activity->actor;
$homeuri = self::getActorProfileURI($activity);
@@ -674,10 +675,17 @@ class Ostatus_profile extends Memcached_DataObject
$oprofile = new Ostatus_profile();
$oprofile->uri = $homeuri;
if ($feeduri) {
+ // If we don't have these, we can look them up later.
$oprofile->feeduri = $feeduri;
+ if ($salmonuri) {
+ $oprofile->salmonuri = $salmonuri;
+ }
}
$oprofile->profile_id = $profile->id;
+ $oprofile->created = common_sql_now();
+ $oprofile->modified = common_sql_now();
+
$ok = $oprofile->insert();
if ($ok) {
$oprofile->updateAvatar($avatar);
--
cgit v1.2.3-54-g00ecf
From a1a3ab1c58cf8636c4e9ac6b9d44bdc18946a547 Mon Sep 17 00:00:00 2001
From: Brion Vibber
Date: Fri, 19 Feb 2010 12:08:07 -0800
Subject: OStatus: hooked up follow/unfollow events on Salmon endpoint to
create/destroy remote subscriber relationships
---
plugins/OStatus/OStatusPlugin.php | 9 +++-
plugins/OStatus/actions/feedsubsettings.php | 8 ----
plugins/OStatus/actions/salmon.php | 66 +++++++++++++++++++++++++----
plugins/OStatus/classes/Ostatus_profile.php | 22 +++++++---
4 files changed, 81 insertions(+), 24 deletions(-)
(limited to 'plugins/OStatus')
diff --git a/plugins/OStatus/OStatusPlugin.php b/plugins/OStatus/OStatusPlugin.php
index 4ebe4551e..4c43d8a30 100644
--- a/plugins/OStatus/OStatusPlugin.php
+++ b/plugins/OStatus/OStatusPlugin.php
@@ -253,17 +253,22 @@ class OStatusPlugin extends Plugin
*/
function onEndUnsubscribe($user, $other)
{
+ if ($user instanceof Profile) {
+ $profile = $user;
+ } else if ($user instanceof Profile) {
+ $profile = $user->getProfile();
+ }
$oprofile = Ostatus_profile::staticGet('profile_id', $other->id);
if ($oprofile) {
// Notify the remote server of the unsub, if supported.
- $oprofile->notify($user->getProfile(), ActivityVerb::UNFOLLOW, $oprofile);
+ $oprofile->notify($profile, ActivityVerb::UNFOLLOW, $oprofile);
// Drop the PuSH subscription if there are no other subscribers.
$sub = new Subscription();
$sub->subscribed = $other->id;
$sub->limit(1);
if (!$sub->find(true)) {
- common_log(LOG_INFO, "Unsubscribing from now-unused feed $oprofile->feeduri on hub $oprofile->huburi");
+ common_log(LOG_INFO, "Unsubscribing from now-unused feed $oprofile->feeduri");
$oprofile->unsubscribe();
}
}
diff --git a/plugins/OStatus/actions/feedsubsettings.php b/plugins/OStatus/actions/feedsubsettings.php
index 3e1d0aa82..aee4cee9a 100644
--- a/plugins/OStatus/actions/feedsubsettings.php
+++ b/plugins/OStatus/actions/feedsubsettings.php
@@ -68,14 +68,6 @@ class FeedSubSettingsAction extends ConnectSettingsAction
$profile = $user->getProfile();
- $fuser = null;
-
- $flink = Foreign_link::getByUserID($user->id, FEEDSUB_SERVICE);
-
- if (!empty($flink)) {
- $fuser = $flink->getForeignUser();
- }
-
$this->elementStart('form', array('method' => 'post',
'id' => 'form_settings_feedsub',
'class' => 'form_settings',
diff --git a/plugins/OStatus/actions/salmon.php b/plugins/OStatus/actions/salmon.php
index 2da9db9eb..1ed322ed2 100644
--- a/plugins/OStatus/actions/salmon.php
+++ b/plugins/OStatus/actions/salmon.php
@@ -63,13 +63,17 @@ class SalmonAction extends Action
// XXX: check that document element is Atom entry
// XXX: check the signature
- $this->act = new Activity($dom->documentElement);
+ $entries = $dom->getElementsByTagNameNS(Activity::ATOM, 'entry');
+ if ($entries && $entries->length) {
+ // @fixme is it legit to have multiple entries?
+ $this->act = new Activity($entries->item(0), $dom->documentElement);
+ }
return true;
}
/**
- * @fixme probably call Ostatus_profile::processFeed
+ * Check the posted activity type and break out to appropriate processing.
*/
function handle($args)
@@ -94,13 +98,19 @@ class SalmonAction extends Action
case ActivityVerb::FRIEND:
$this->handleFollow();
break;
+ case ActivityVerb::UNFOLLOW:
+ $this->handleUnfollow();
+ break;
}
Event::handle('EndHandleSalmon', array($this->user, $this->activity));
}
}
/**
- * @fixme probably call Ostatus_profile::processFeed
+ * We've gotten a post event on the Salmon backchannel, probably a reply.
+ *
+ * @todo validate if we need to handle this post, then call into
+ * ostatus_profile's general incoming-post handling.
*/
function handlePost()
{
@@ -116,43 +126,81 @@ class SalmonAction extends Action
}
$profile = $this->ensureProfile();
+ // @fixme do something with the post
}
/**
- * @fixme probably call Ostatus_profile::processFeed
+ * We've gotten a follow/subscribe notification from a remote user.
+ * Save a subscription relationship for them.
*/
function handleFollow()
{
+ $oprofile = $this->ensureProfile();
+ if ($oprofile) {
+ common_log(LOG_INFO, "Setting up subscription from remote {$oprofile->uri} to local {$this->user->nickname}");
+ $oprofile->subscribeRemoteToLocal($this->user);
+ } else {
+ common_log(LOG_INFO, "Can't set up subscription from remote; missing profile.");
+ }
+ }
+
+ /**
+ * We've gotten an unfollow/unsubscribe notification from a remote user.
+ * Check if we have a subscription relationship for them and kill it.
+ *
+ * @fixme probably catch exceptions on fail?
+ */
+ function handleUnfollow()
+ {
+ $oprofile = $this->ensureProfile();
+ if ($oprofile) {
+ common_log(LOG_INFO, "Canceling subscription from remote {$oprofile->uri} to local {$this->user->nickname}");
+ Subscription::cancel($oprofile->localProfile(), $this->user->getProfile());
+ } else {
+ common_log(LOG_ERR, "Can't cancel subscription from remote, didn't find the profile");
+ }
}
/**
- * @fixme probably call Ostatus_profile::processFeed
+ * Remote user likes one of our posts.
+ * Confirm the post is ours, and save a local favorite event.
*/
function handleFavorite()
{
}
/**
- * @fixme probably call Ostatus_profile::processFeed
+ * Remote user doesn't like one of our posts after all!
+ * Confirm the post is ours, and save a local favorite event.
+ */
+ function handleUnfavorite()
+ {
+ }
+
+ /**
+ * Hmmmm
*/
function handleShare()
{
}
+ /**
+ * @return Ostatus_profile
+ */
function ensureProfile()
{
$actor = $this->act->actor;
common_log(LOG_DEBUG, "Received salmon bit: " . var_export($this->act, true));
if (empty($actor->id)) {
+ common_log(LOG_ERR, "broken actor: " . var_export($actor, true));
throw new Exception("Received a salmon slap from unidentified actor.");
}
- $ostatusProfile = Ostatus_profile::ensureActorProfile($this->act);
- return $oprofile->localProfile();
+ return Ostatus_profile::ensureActorProfile($this->act);
}
/**
- * @fixme anything new in here probably should be merged into Ostatus_profile::ensureActorProfile and friends
+ * @fixme merge into Ostatus_profile::ensureActorProfile and friends
*/
function createProfile()
{
diff --git a/plugins/OStatus/classes/Ostatus_profile.php b/plugins/OStatus/classes/Ostatus_profile.php
index 319b76a66..97d8eec10 100644
--- a/plugins/OStatus/classes/Ostatus_profile.php
+++ b/plugins/OStatus/classes/Ostatus_profile.php
@@ -310,8 +310,15 @@ class Ostatus_profile extends Memcached_DataObject
* @param $verb eg Activity::SUBSCRIBE or Activity::JOIN
* @param $object object of the action; if null, the remote entity itself is assumed
*/
- public function notify(Profile $actor, $verb, $object=null)
+ public function notify($actor, $verb, $object=null)
{
+ if (!($actor instanceof Profile)) {
+ $type = gettype($actor);
+ if ($type == 'object') {
+ $type = get_class($actor);
+ }
+ throw new ServerException("Invalid actor passed to " . __METHOD__ . ": " . $type);
+ }
if ($object == null) {
$object = $this;
}
@@ -340,7 +347,7 @@ class Ostatus_profile extends Memcached_DataObject
$feed->addEntry($entry);
$xml = $feed->getString();
- common_log(LOG_INFO, "Posting to Salmon endpoint $salmon: $xml");
+ common_log(LOG_INFO, "Posting to Salmon endpoint $this->salmonuri: $xml");
$salmon = new Salmon(); // ?
$salmon->post($this->salmonuri, $xml);
@@ -531,9 +538,14 @@ class Ostatus_profile extends Memcached_DataObject
$temp_filename = tempnam(sys_get_temp_dir(), 'listener_avatar');
copy($url, $temp_filename);
+ if ($this->isGroup()) {
+ $id = $this->group_id;
+ } else {
+ $id = $this->profile_id;
+ }
// @fixme should we be using different ids?
- $imagefile = new ImageFile($this->id, $temp_filename);
- $filename = Avatar::filename($this->id,
+ $imagefile = new ImageFile($id, $temp_filename);
+ $filename = Avatar::filename($id,
image_type_to_extension($imagefile->type),
null,
common_timestamp());
@@ -646,7 +658,7 @@ class Ostatus_profile extends Memcached_DataObject
$actor = $activity->actor;
$homeuri = self::getActorProfileURI($activity);
$nickname = self::getAuthorNick($activity);
- $avatar = self::getAvatar($actor, $feed);
+ $avatar = self::getAvatar($actor, $activity->feed);
if (!$homeuri) {
common_log(LOG_DEBUG, __METHOD__ . " empty actor profile URI: " . var_export($activity, true));
--
cgit v1.2.3-54-g00ecf
From b0327506a491f029b239ae703e1acb1d42ae299c Mon Sep 17 00:00:00 2001
From: Evan Prodromou
Date: Fri, 19 Feb 2010 16:37:07 -0500
Subject: some more salmon stuff
---
plugins/OStatus/actions/salmon.php | 90 +++++++++++++++++++++++++++++++++++++-
1 file changed, 89 insertions(+), 1 deletion(-)
(limited to 'plugins/OStatus')
diff --git a/plugins/OStatus/actions/salmon.php b/plugins/OStatus/actions/salmon.php
index e9d6015f4..7356c489a 100644
--- a/plugins/OStatus/actions/salmon.php
+++ b/plugins/OStatus/actions/salmon.php
@@ -112,24 +112,112 @@ class SalmonAction extends Action
case ActivityObject::COMMENT:
break;
default:
- throw new Exception("Can't handle that kind of post.");
+ throw new ClientException("Can't handle that kind of post.");
+ }
+
+ // Notice must either be a) in reply to a notice by this user
+ // or b) to the attention of this user
+
+ $context = $this->act->context;
+
+ if (!empty($context->replyToID)) {
+ $notice = Notice::staticGet('uri', $context->replyToID);
+ if (empty($notice)) {
+ throw new ClientException("In reply to unknown notice");
+ }
+ if ($notice->profile_id != $this->user->id) {
+ throw new ClientException("In reply to a notice not by this user");
+ }
+ } else if (!empty($context->attention)) {
+ if (!in_array($context->attention, $this->user->uri)) {
+ throw new ClientException("To the attention of user(s) not including this one!");
+ }
+ } else {
+ throw new ClientException("Not to anyone in reply to anything!");
}
$profile = $this->ensureProfile();
+
}
/**
* @fixme probably call Ostatus_profile::processFeed
*/
+
function handleFollow()
{
+ $object = $this->act->object;
+
+ if ($object->id != $this->user->uri) {
+ throw new ClientException("Subscription notice not for this user.");
+ }
+
+ $profile = $this->ensureProfile();
+
+ $sub = Subscription::pkeyGet(array('subscriber' => $profile->id,
+ 'subscribed' => $this->user->id));
+
+ if (!empty($sub)) {
+ throw new ClientException("Already subscribed.");
+ }
+
+ if ($this->user->hasBlocked($profile)) {
+ throw new ClientException("Already subscribed.");
+ }
+
}
/**
* @fixme probably call Ostatus_profile::processFeed
*/
+
function handleFavorite()
{
+ // WORST VARIABLE NAME EVER
+ $object = $this->act->object;
+
+ switch ($this->act->object->type) {
+ case ActivityObject::ARTICLE:
+ case ActivityObject::BLOGENTRY:
+ case ActivityObject::NOTE:
+ case ActivityObject::STATUS:
+ case ActivityObject::COMMENT:
+ break;
+ default:
+ throw new ClientException("Can't handle that kind of object for liking/faving.");
+ }
+
+ $notice = Notice::staticGet('uri', $object->id);
+
+ if (empty($notice)) {
+ throw new ClientException("Notice with ID $object->id unknown.");
+ }
+
+ if ($notice->profile_id != $this->user->id) {
+ throw new ClientException("Notice with ID $object->id not posted by $this->user->id.");
+ }
+
+ $profile = $this->ensureProfile();
+
+ $old = Fave::pkeyGet(array('user_id' => $profile->id,
+ 'notice_id' => $notice->id));
+
+ if (!empty($old)) {
+ throw new ClientException("We already know that's a fave!");
+ }
+
+ $fave = new Fave();
+
+ // @fixme need to change this attribute name, maybe references
+ $fave->user_id = $profile->id;
+ $fave->notice_id = $notice->id;
+
+ $result = $fave->insert();
+
+ if (!$result) {
+ common_log_db_error($fave, 'INSERT', __FILE__);
+ throw new ServerException('Could not save new favorite.');
+ }
}
/**
--
cgit v1.2.3-54-g00ecf
From 557df3d3f78dbfce656c4c8e3ddf82ee0e34da0a Mon Sep 17 00:00:00 2001
From: Brion Vibber
Date: Fri, 19 Feb 2010 16:21:17 -0800
Subject: OStatus: sub/unsub notifications working again. Fixed up
autodetection of feed info at profile setup time
---
plugins/OStatus/OStatusPlugin.php | 2 ++
plugins/OStatus/actions/salmon.php | 13 +++++++++---
plugins/OStatus/classes/Ostatus_profile.php | 31 +++++++++++++++++++----------
plugins/OStatus/lib/salmon.php | 3 +++
4 files changed, 35 insertions(+), 14 deletions(-)
(limited to 'plugins/OStatus')
diff --git a/plugins/OStatus/OStatusPlugin.php b/plugins/OStatus/OStatusPlugin.php
index 4c43d8a30..1b58d3c35 100644
--- a/plugins/OStatus/OStatusPlugin.php
+++ b/plugins/OStatus/OStatusPlugin.php
@@ -331,6 +331,8 @@ class OStatusPlugin extends Plugin
$oprofile = Ostatus_profile::staticGet('feeduri', $feedsub->uri);
if ($oprofile) {
$oprofile->processFeed($feed);
+ } else {
+ common_log(LOG_DEBUG, "No ostatus profile for incoming feed $feedsub->uri");
}
}
}
diff --git a/plugins/OStatus/actions/salmon.php b/plugins/OStatus/actions/salmon.php
index 7a4474ff6..43d79cf4a 100644
--- a/plugins/OStatus/actions/salmon.php
+++ b/plugins/OStatus/actions/salmon.php
@@ -34,6 +34,8 @@ class SalmonAction extends Action
function prepare($args)
{
+ StatusNet::setApi(true); // Send smaller error pages
+
parent::prepare($args);
if ($_SERVER['REQUEST_METHOD'] != 'POST') {
@@ -63,8 +65,12 @@ class SalmonAction extends Action
// XXX: check that document element is Atom entry
// XXX: check the signature
- $this->act = new Activity($dom->documentElement);
-
+ // We need to run an entry into Activity, so get the first one
+ $entries = $dom->getElementsByTagNameNS(Activity::ATOM, 'entry');
+ if ($entries && $entries->length) {
+ // @fixme is it legit to have multiple entries?
+ $this->act = new Activity($entries->item(0), $dom->documentElement);
+ }
return true;
}
@@ -74,7 +80,9 @@ class SalmonAction extends Action
function handle($args)
{
+ StatusNet::setApi(true); // Send smaller error pages
common_log(LOG_INFO, 'Salmon: incoming post for user '. $this->user->id);
+ common_log(LOG_DEBUG, "Received salmon bit: " . var_export($this->act, true));
// TODO : Insert new $xml -> notice code
@@ -254,7 +262,6 @@ class SalmonAction extends Action
function ensureProfile()
{
$actor = $this->act->actor;
- common_log(LOG_DEBUG, "Received salmon bit: " . var_export($this->act, true));
if (empty($actor->id)) {
common_log(LOG_ERR, "broken actor: " . var_export($actor, true));
throw new Exception("Received a salmon slap from unidentified actor.");
diff --git a/plugins/OStatus/classes/Ostatus_profile.php b/plugins/OStatus/classes/Ostatus_profile.php
index 97d8eec10..5fe135f96 100644
--- a/plugins/OStatus/classes/Ostatus_profile.php
+++ b/plugins/OStatus/classes/Ostatus_profile.php
@@ -56,7 +56,7 @@ class Ostatus_profile extends Memcached_DataObject
return array('uri' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,
'profile_id' => DB_DATAOBJECT_INT,
'group_id' => DB_DATAOBJECT_INT,
- 'feeduri' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,
+ 'feeduri' => DB_DATAOBJECT_STR,
'salmonuri' => DB_DATAOBJECT_STR,
'created' => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME + DB_DATAOBJECT_NOTNULL,
'modified' => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME + DB_DATAOBJECT_NOTNULL);
@@ -71,7 +71,7 @@ class Ostatus_profile extends Memcached_DataObject
new ColumnDef('group_id', 'integer',
null, true, 'UNI'),
new ColumnDef('feeduri', 'varchar',
- 255, false, 'UNI'),
+ 255, true, 'UNI'),
new ColumnDef('salmonuri', 'text',
null, true),
new ColumnDef('created', 'datetime',
@@ -272,7 +272,7 @@ class Ostatus_profile extends Memcached_DataObject
* @return bool true on success, false on failure
* @throws ServerException if feed state is not valid
*/
- public function subscribe($mode='subscribe')
+ public function subscribe()
{
$feedsub = FeedSub::ensureFeed($this->feeduri);
if ($feedsub->sub_state == 'active' || $feedsub->sub_state == 'subscribe') {
@@ -506,7 +506,7 @@ class Ostatus_profile extends Memcached_DataObject
$discover = new FeedDiscovery();
$feeduri = $discover->discoverFromURL($profile_uri);
- $feedsub = FeedSub::ensureFeed($feeduri, $discover->feed);
+ //$feedsub = FeedSub::ensureFeed($feeduri, $discover->feed);
$huburi = $discover->getAtomLink('hub');
$salmonuri = $discover->getAtomLink('salmon');
@@ -665,6 +665,20 @@ class Ostatus_profile extends Memcached_DataObject
throw new ServerException("No profile URI");
}
+ if (!$feeduri || !$salmonuri) {
+ // Get the canonical feed URI and check it
+ $discover = new FeedDiscovery();
+ $feeduri = $discover->discoverFromURL($homeuri);
+
+ $huburi = $discover->getAtomLink('hub');
+ $salmonuri = $discover->getAtomLink('salmon');
+
+ if (!$huburi) {
+ // We can only deal with folks with a PuSH hub
+ throw new FeedSubNoHubException();
+ }
+ }
+
$profile = new Profile();
$profile->nickname = $nickname;
$profile->fullname = $actor->displayName;
@@ -686,13 +700,8 @@ class Ostatus_profile extends Memcached_DataObject
// so we can leave it empty until later.
$oprofile = new Ostatus_profile();
$oprofile->uri = $homeuri;
- if ($feeduri) {
- // If we don't have these, we can look them up later.
- $oprofile->feeduri = $feeduri;
- if ($salmonuri) {
- $oprofile->salmonuri = $salmonuri;
- }
- }
+ $oprofile->feeduri = $feeduri;
+ $oprofile->salmonuri = $salmonuri;
$oprofile->profile_id = $profile->id;
$oprofile->created = common_sql_now();
diff --git a/plugins/OStatus/lib/salmon.php b/plugins/OStatus/lib/salmon.php
index 8c77222a6..df17a7006 100644
--- a/plugins/OStatus/lib/salmon.php
+++ b/plugins/OStatus/lib/salmon.php
@@ -41,9 +41,12 @@ class Salmon
$client->setBody($xml);
$response = $client->post($endpoint_uri, $headers);
} catch (HTTP_Request2_Exception $e) {
+ common_log(LOG_ERR, "Salmon post to $endpoint_uri failed: " . $e->getMessage());
return false;
}
if ($response->getStatus() != 200) {
+ common_log(LOG_ERR, "Salmon at $endpoint_uri returned status " .
+ $response->getStatus() . ': ' . $response->getBody());
return false;
}
--
cgit v1.2.3-54-g00ecf
From 50db2d5d69a8769dc2ddcc937afb130bcce0971d Mon Sep 17 00:00:00 2001
From: Brion Vibber
Date: Fri, 19 Feb 2010 17:01:38 -0800
Subject: OStatus: Salmon notifications now being generated moderately
correctly. :) Needs to be an not a .
---
plugins/OStatus/actions/salmon.php | 12 +++++-------
plugins/OStatus/classes/Ostatus_profile.php | 15 +++++++++------
2 files changed, 14 insertions(+), 13 deletions(-)
(limited to 'plugins/OStatus')
diff --git a/plugins/OStatus/actions/salmon.php b/plugins/OStatus/actions/salmon.php
index 43d79cf4a..f7c86dc0c 100644
--- a/plugins/OStatus/actions/salmon.php
+++ b/plugins/OStatus/actions/salmon.php
@@ -62,15 +62,13 @@ class SalmonAction extends Action
$dom = DOMDocument::loadXML($xml);
- // XXX: check that document element is Atom entry
+ if ($dom->documentElement->namespaceURI != Activity::ATOM ||
+ $dom->documentElement->localName != 'entry') {
+ $this->clientError(_m('Salmon post must be an Atom entry.'));
+ }
// XXX: check the signature
- // We need to run an entry into Activity, so get the first one
- $entries = $dom->getElementsByTagNameNS(Activity::ATOM, 'entry');
- if ($entries && $entries->length) {
- // @fixme is it legit to have multiple entries?
- $this->act = new Activity($entries->item(0), $dom->documentElement);
- }
+ $this->act = new Activity($dom->documentElement);
return true;
}
diff --git a/plugins/OStatus/classes/Ostatus_profile.php b/plugins/OStatus/classes/Ostatus_profile.php
index 5fe135f96..b14b4c9a3 100644
--- a/plugins/OStatus/classes/Ostatus_profile.php
+++ b/plugins/OStatus/classes/Ostatus_profile.php
@@ -329,9 +329,15 @@ class Ostatus_profile extends Memcached_DataObject
':' . $actor->id .
':' . time(); // @fixme
- //$entry = new Atom10Entry();
+ // @fixme consolidate all these NS settings somewhere
+ $attributes = array('xmlns' => Activity::ATOM,
+ 'xmlns:activity' => 'http://activitystrea.ms/spec/1.0/',
+ 'xmlns:thr' => 'http://purl.org/syndication/thread/1.0',
+ 'xmlns:georss' => 'http://www.georss.org/georss',
+ 'xmlns:ostatus' => 'http://ostatus.org/schema/1.0');
+
$entry = new XMLStringer();
- $entry->elementStart('entry');
+ $entry->elementStart('entry', $attributes);
$entry->element('id', null, $id);
$entry->element('title', null, $text);
$entry->element('summary', null, $text);
@@ -343,10 +349,7 @@ class Ostatus_profile extends Memcached_DataObject
$entry->raw($object->asActivityNoun('object'));
$entry->elementEnd('entry');
- $feed = $this->atomFeed($actor);
- $feed->addEntry($entry);
-
- $xml = $feed->getString();
+ $xml = $entry->getString();
common_log(LOG_INFO, "Posting to Salmon endpoint $this->salmonuri: $xml");
$salmon = new Salmon(); // ?
--
cgit v1.2.3-54-g00ecf
From 2df3bbc80b6c9dd44134bcf3b5b4a09ea1a803d1 Mon Sep 17 00:00:00 2001
From: Evan Prodromou
Date: Sat, 20 Feb 2010 11:12:43 -0500
Subject: Move some salmon processing to a superclass
Moved some salmon processing to a superclass so we could handle group
salmon posts, too.
---
plugins/OStatus/OStatusPlugin.php | 4 +-
plugins/OStatus/actions/groupsalmon.php | 108 ++++++++++
plugins/OStatus/actions/salmon.php | 341 --------------------------------
plugins/OStatus/actions/usersalmon.php | 0
plugins/OStatus/lib/salmonaction.php | 231 ++++++++++++++++++++++
5 files changed, 341 insertions(+), 343 deletions(-)
create mode 100644 plugins/OStatus/actions/groupsalmon.php
delete mode 100644 plugins/OStatus/actions/salmon.php
create mode 100644 plugins/OStatus/actions/usersalmon.php
create mode 100644 plugins/OStatus/lib/salmonaction.php
(limited to 'plugins/OStatus')
diff --git a/plugins/OStatus/OStatusPlugin.php b/plugins/OStatus/OStatusPlugin.php
index 1b58d3c35..e1f3fd9d3 100644
--- a/plugins/OStatus/OStatusPlugin.php
+++ b/plugins/OStatus/OStatusPlugin.php
@@ -63,10 +63,10 @@ class OStatusPlugin extends Plugin
// Salmon endpoint
$m->connect('main/salmon/user/:id',
- array('action' => 'salmon'),
+ array('action' => 'usersalmon'),
array('id' => '[0-9]+'));
$m->connect('main/salmon/group/:id',
- array('action' => 'salmongroup'),
+ array('action' => 'groupsalmon'),
array('id' => '[0-9]+'));
return true;
}
diff --git a/plugins/OStatus/actions/groupsalmon.php b/plugins/OStatus/actions/groupsalmon.php
new file mode 100644
index 000000000..64ae9f3cc
--- /dev/null
+++ b/plugins/OStatus/actions/groupsalmon.php
@@ -0,0 +1,108 @@
+.
+ */
+
+/**
+ * @package OStatusPlugin
+ * @author James Walker
+ */
+
+if (!defined('STATUSNET')) {
+ exit(1);
+}
+
+class GroupsalmonAction extends SalmonAction
+{
+ var $group = null;
+
+ function prepare($args)
+ {
+ parent::prepare($args);
+
+ $id = $this->trimmed('id');
+
+ if (!$id) {
+ $this->clientError(_('No ID.'));
+ }
+
+ $this->group = User_group::staticGet('id', $id);
+
+ if (empty($this->group)) {
+ $this->clientError(_('No such group.'));
+ }
+
+ return true;
+ }
+
+ /**
+ * We've gotten a post event on the Salmon backchannel, probably a reply.
+ */
+
+ function handlePost()
+ {
+ switch ($this->act->object->type) {
+ case ActivityObject::ARTICLE:
+ case ActivityObject::BLOGENTRY:
+ case ActivityObject::NOTE:
+ case ActivityObject::STATUS:
+ case ActivityObject::COMMENT:
+ break;
+ default:
+ throw new ClientException("Can't handle that kind of post.");
+ }
+
+ // Notice must be to the attention of this group
+
+ $context = $this->act->context;
+
+ if (empty($context->attention)) {
+ throw new ClientException("Not to the attention of anyone.");
+ } else {
+ $uri = common_local_url('groupbyid', array('id' => $this->group->id));
+ if (!in_array($context->attention, $uri)) {
+ throw new ClientException("Not to the attention of this group.");
+ }
+ }
+
+ $profile = $this->ensureProfile();
+ // @fixme save the post
+ }
+
+ /**
+ * We've gotten a follow/subscribe notification from a remote user.
+ * Save a subscription relationship for them.
+ */
+
+ function handleFollow()
+ {
+ $this->handleJoin(); // ???
+ }
+
+ function handleUnfollow()
+ {
+ }
+
+ /**
+ * A remote user joined our group.
+ */
+
+ function handleJoin()
+ {
+ }
+
+}
diff --git a/plugins/OStatus/actions/salmon.php b/plugins/OStatus/actions/salmon.php
deleted file mode 100644
index f7c86dc0c..000000000
--- a/plugins/OStatus/actions/salmon.php
+++ /dev/null
@@ -1,341 +0,0 @@
-.
- */
-
-/**
- * @package OStatusPlugin
- * @author James Walker
- */
-
-if (!defined('STATUSNET')) {
- exit(1);
-}
-
-class SalmonAction extends Action
-{
- var $user = null;
- var $xml = null;
- var $activity = null;
-
- function prepare($args)
- {
- StatusNet::setApi(true); // Send smaller error pages
-
- parent::prepare($args);
-
- if ($_SERVER['REQUEST_METHOD'] != 'POST') {
- $this->clientError(_('This method requires a POST.'));
- }
-
- if ($_SERVER['CONTENT_TYPE'] != 'application/atom+xml') {
- $this->clientError(_('Salmon requires application/atom+xml'));
- }
-
- $id = $this->trimmed('id');
-
- if (!$id) {
- $this->clientError(_('No ID.'));
- }
-
- $this->user = User::staticGet($id);
-
- if (empty($this->user)) {
- $this->clientError(_('No such user.'));
- }
-
- $xml = file_get_contents('php://input');
-
- $dom = DOMDocument::loadXML($xml);
-
- if ($dom->documentElement->namespaceURI != Activity::ATOM ||
- $dom->documentElement->localName != 'entry') {
- $this->clientError(_m('Salmon post must be an Atom entry.'));
- }
- // XXX: check the signature
-
- $this->act = new Activity($dom->documentElement);
- return true;
- }
-
- /**
- * Check the posted activity type and break out to appropriate processing.
- */
-
- function handle($args)
- {
- StatusNet::setApi(true); // Send smaller error pages
- common_log(LOG_INFO, 'Salmon: incoming post for user '. $this->user->id);
- common_log(LOG_DEBUG, "Received salmon bit: " . var_export($this->act, true));
-
- // TODO : Insert new $xml -> notice code
-
- if (Event::handle('StartHandleSalmon', array($this->user, $this->activity))) {
- switch ($this->act->verb)
- {
- case ActivityVerb::POST:
- $this->handlePost();
- break;
- case ActivityVerb::SHARE:
- $this->handleShare();
- break;
- case ActivityVerb::FAVORITE:
- $this->handleFavorite();
- break;
- case ActivityVerb::FOLLOW:
- case ActivityVerb::FRIEND:
- $this->handleFollow();
- break;
- case ActivityVerb::UNFOLLOW:
- $this->handleUnfollow();
- break;
- }
- Event::handle('EndHandleSalmon', array($this->user, $this->activity));
- }
- }
-
- /**
- * We've gotten a post event on the Salmon backchannel, probably a reply.
- *
- * @todo validate if we need to handle this post, then call into
- * ostatus_profile's general incoming-post handling.
- */
- function handlePost()
- {
- switch ($this->act->object->type) {
- case ActivityObject::ARTICLE:
- case ActivityObject::BLOGENTRY:
- case ActivityObject::NOTE:
- case ActivityObject::STATUS:
- case ActivityObject::COMMENT:
- break;
- default:
- throw new ClientException("Can't handle that kind of post.");
- }
-
- // Notice must either be a) in reply to a notice by this user
- // or b) to the attention of this user
-
- $context = $this->act->context;
-
- if (!empty($context->replyToID)) {
- $notice = Notice::staticGet('uri', $context->replyToID);
- if (empty($notice)) {
- throw new ClientException("In reply to unknown notice");
- }
- if ($notice->profile_id != $this->user->id) {
- throw new ClientException("In reply to a notice not by this user");
- }
- } else if (!empty($context->attention)) {
- if (!in_array($context->attention, $this->user->uri)) {
- throw new ClientException("To the attention of user(s) not including this one!");
- }
- } else {
- throw new ClientException("Not to anyone in reply to anything!");
- }
-
- $profile = $this->ensureProfile();
- // @fixme do something with the post
- }
-
- /**
- * We've gotten a follow/subscribe notification from a remote user.
- * Save a subscription relationship for them.
- */
-
- function handleFollow()
- {
- $oprofile = $this->ensureProfile();
- if ($oprofile) {
- common_log(LOG_INFO, "Setting up subscription from remote {$oprofile->uri} to local {$this->user->nickname}");
- $oprofile->subscribeRemoteToLocal($this->user);
- } else {
- common_log(LOG_INFO, "Can't set up subscription from remote; missing profile.");
- }
- }
-
- /**
- * We've gotten an unfollow/unsubscribe notification from a remote user.
- * Check if we have a subscription relationship for them and kill it.
- *
- * @fixme probably catch exceptions on fail?
- */
- function handleUnfollow()
- {
- $oprofile = $this->ensureProfile();
- if ($oprofile) {
- common_log(LOG_INFO, "Canceling subscription from remote {$oprofile->uri} to local {$this->user->nickname}");
- Subscription::cancel($oprofile->localProfile(), $this->user->getProfile());
- } else {
- common_log(LOG_ERR, "Can't cancel subscription from remote, didn't find the profile");
- }
- }
-
- /**
- * Remote user likes one of our posts.
- * Confirm the post is ours, and save a local favorite event.
- */
-
- function handleFavorite()
- {
- // WORST VARIABLE NAME EVER
- $object = $this->act->object;
-
- switch ($this->act->object->type) {
- case ActivityObject::ARTICLE:
- case ActivityObject::BLOGENTRY:
- case ActivityObject::NOTE:
- case ActivityObject::STATUS:
- case ActivityObject::COMMENT:
- break;
- default:
- throw new ClientException("Can't handle that kind of object for liking/faving.");
- }
-
- $notice = Notice::staticGet('uri', $object->id);
-
- if (empty($notice)) {
- throw new ClientException("Notice with ID $object->id unknown.");
- }
-
- if ($notice->profile_id != $this->user->id) {
- throw new ClientException("Notice with ID $object->id not posted by $this->user->id.");
- }
-
- $profile = $this->ensureProfile();
-
- $old = Fave::pkeyGet(array('user_id' => $profile->id,
- 'notice_id' => $notice->id));
-
- if (!empty($old)) {
- throw new ClientException("We already know that's a fave!");
- }
-
- $fave = new Fave();
-
- // @fixme need to change this attribute name, maybe references
- $fave->user_id = $profile->id;
- $fave->notice_id = $notice->id;
-
- $result = $fave->insert();
-
- if (!$result) {
- common_log_db_error($fave, 'INSERT', __FILE__);
- throw new ServerException('Could not save new favorite.');
- }
- }
-
- /**
- * Remote user doesn't like one of our posts after all!
- * Confirm the post is ours, and save a local favorite event.
- */
- function handleUnfavorite()
- {
- }
-
- /**
- * Hmmmm
- */
- function handleShare()
- {
- }
-
- /**
- * @return Ostatus_profile
- */
- function ensureProfile()
- {
- $actor = $this->act->actor;
- if (empty($actor->id)) {
- common_log(LOG_ERR, "broken actor: " . var_export($actor, true));
- throw new Exception("Received a salmon slap from unidentified actor.");
- }
-
- return Ostatus_profile::ensureActorProfile($this->act);
- }
-
- /**
- * @fixme merge into Ostatus_profile::ensureActorProfile and friends
- */
- function createProfile()
- {
- $actor = $this->act->actor;
-
- $profile = new Profile();
-
- $profile->nickname = $this->nicknameFromURI($actor->id);
-
- if (empty($profile->nickname)) {
- $profile->nickname = common_nicknamize($actor->title);
- }
-
- $profile->fullname = $actor->title;
- $profile->bio = $actor->summary; // XXX: is that right?
- $profile->profileurl = $actor->link; // XXX: is that right?
- $profile->created = common_sql_now();
-
- $id = $profile->insert();
-
- if (empty($id)) {
- common_log_db_error($profile, 'INSERT', __FILE__);
- throw new Exception("Couldn't save new profile for $actor->id\n");
- }
-
- // XXX: add avatars
-
- $op = new Ostatus_profile();
-
- $op->profile_id = $id;
- $op->homeuri = $actor->id;
- $op->created = $profile->created;
-
- // XXX: determine feed URI from source or Webfinger or whatever
-
- $id = $op->insert();
-
- if (empty($id)) {
- common_log_db_error($op, 'INSERT', __FILE__);
- throw new Exception("Couldn't save new ostatus profile for $actor->id\n");
- }
-
- return $profile;
- }
-
- /**
- * @fixme should be merged into Ostatus_profile
- */
- function nicknameFromURI($uri)
- {
- preg_match('/(\w+):/', $uri, $matches);
-
- $protocol = $matches[1];
-
- switch ($protocol) {
- case 'acct':
- case 'mailto':
- if (preg_match("/^$protocol:(.*)?@.*\$/", $uri, $matches)) {
- return common_canonical_nickname($matches[1]);
- }
- return null;
- case 'http':
- return common_url_to_nickname($uri);
- break;
- default:
- return null;
- }
- }
-}
diff --git a/plugins/OStatus/actions/usersalmon.php b/plugins/OStatus/actions/usersalmon.php
new file mode 100644
index 000000000..e69de29bb
diff --git a/plugins/OStatus/lib/salmonaction.php b/plugins/OStatus/lib/salmonaction.php
new file mode 100644
index 000000000..7085e4583
--- /dev/null
+++ b/plugins/OStatus/lib/salmonaction.php
@@ -0,0 +1,231 @@
+.
+ */
+
+/**
+ * @package OStatusPlugin
+ * @author James Walker
+ */
+
+if (!defined('STATUSNET')) {
+ exit(1);
+}
+
+class SalmonAction extends Action
+{
+ var $xml = null;
+ var $activity = null;
+
+ function prepare($args)
+ {
+ StatusNet::setApi(true); // Send smaller error pages
+
+ parent::prepare($args);
+
+ if ($_SERVER['REQUEST_METHOD'] != 'POST') {
+ $this->clientError(_('This method requires a POST.'));
+ }
+
+ if ($_SERVER['CONTENT_TYPE'] != 'application/atom+xml') {
+ $this->clientError(_('Salmon requires application/atom+xml'));
+ }
+
+ $xml = file_get_contents('php://input');
+
+ $dom = DOMDocument::loadXML($xml);
+
+ if ($dom->documentElement->namespaceURI != Activity::ATOM ||
+ $dom->documentElement->localName != 'entry') {
+ $this->clientError(_m('Salmon post must be an Atom entry.'));
+ }
+ // XXX: check the signature
+
+ $this->act = new Activity($dom->documentElement);
+ return true;
+ }
+
+ /**
+ * Check the posted activity type and break out to appropriate processing.
+ */
+
+ function handle($args)
+ {
+ StatusNet::setApi(true); // Send smaller error pages
+
+ // TODO : Insert new $xml -> notice code
+
+ if (Event::handle('StartHandleSalmon', array($this->activity))) {
+ switch ($this->act->verb)
+ {
+ case ActivityVerb::POST:
+ $this->handlePost();
+ break;
+ case ActivityVerb::SHARE:
+ $this->handleShare();
+ break;
+ case ActivityVerb::FAVORITE:
+ $this->handleFavorite();
+ break;
+ case ActivityVerb::FOLLOW:
+ case ActivityVerb::FRIEND:
+ $this->handleFollow();
+ break;
+ case ActivityVerb::UNFOLLOW:
+ $this->handleUnfollow();
+ break;
+ case ActivityVerb::JOIN:
+ $this->handleJoin();
+ break;
+ default:
+ throw new ClientException(_("Unimplemented."));
+ }
+ Event::handle('EndHandleSalmon', array($this->activity));
+ }
+ }
+
+ function handlePost()
+ {
+ throw new ClientException(_("Unimplemented!"));
+ }
+
+ function handleFollow()
+ {
+ throw new ClientException(_("Unimplemented!"));
+ }
+
+ function handleUnfollow()
+ {
+ throw new ClientException(_("Unimplemented!"));
+ }
+
+ function handleFavorite()
+ {
+ throw new ClientException(_("Unimplemented!"));
+ }
+
+ /**
+ * Remote user doesn't like one of our posts after all!
+ * Confirm the post is ours, and delete a local favorite event.
+ */
+
+ function handleUnfavorite()
+ {
+ throw new ClientException(_("Unimplemented!"));
+ }
+
+ /**
+ * Hmmmm
+ */
+ function handleShare()
+ {
+ throw new ClientException(_("Unimplemented!"));
+ }
+
+ /**
+ * Hmmmm
+ */
+ function handleJoin()
+ {
+ throw new ClientException(_("Unimplemented!"));
+ }
+
+ /**
+ * @return Ostatus_profile
+ */
+ function ensureProfile()
+ {
+ $actor = $this->act->actor;
+ if (empty($actor->id)) {
+ common_log(LOG_ERR, "broken actor: " . var_export($actor, true));
+ throw new Exception("Received a salmon slap from unidentified actor.");
+ }
+
+ return Ostatus_profile::ensureActorProfile($this->act);
+ }
+
+ /**
+ * @fixme merge into Ostatus_profile::ensureActorProfile and friends
+ */
+ function createProfile()
+ {
+ $actor = $this->act->actor;
+
+ $profile = new Profile();
+
+ $profile->nickname = $this->nicknameFromURI($actor->id);
+
+ if (empty($profile->nickname)) {
+ $profile->nickname = common_nicknamize($actor->title);
+ }
+
+ $profile->fullname = $actor->title;
+ $profile->bio = $actor->summary; // XXX: is that right?
+ $profile->profileurl = $actor->link; // XXX: is that right?
+ $profile->created = common_sql_now();
+
+ $id = $profile->insert();
+
+ if (empty($id)) {
+ common_log_db_error($profile, 'INSERT', __FILE__);
+ throw new Exception("Couldn't save new profile for $actor->id\n");
+ }
+
+ // XXX: add avatars
+
+ $op = new Ostatus_profile();
+
+ $op->profile_id = $id;
+ $op->homeuri = $actor->id;
+ $op->created = $profile->created;
+
+ // XXX: determine feed URI from source or Webfinger or whatever
+
+ $id = $op->insert();
+
+ if (empty($id)) {
+ common_log_db_error($op, 'INSERT', __FILE__);
+ throw new Exception("Couldn't save new ostatus profile for $actor->id\n");
+ }
+
+ return $profile;
+ }
+
+ /**
+ * @fixme should be merged into Ostatus_profile
+ */
+ function nicknameFromURI($uri)
+ {
+ preg_match('/(\w+):/', $uri, $matches);
+
+ $protocol = $matches[1];
+
+ switch ($protocol) {
+ case 'acct':
+ case 'mailto':
+ if (preg_match("/^$protocol:(.*)?@.*\$/", $uri, $matches)) {
+ return common_canonical_nickname($matches[1]);
+ }
+ return null;
+ case 'http':
+ return common_url_to_nickname($uri);
+ break;
+ default:
+ return null;
+ }
+ }
+}
--
cgit v1.2.3-54-g00ecf
From ed45df045f661e9c3b85e0657986c99c320914f0 Mon Sep 17 00:00:00 2001
From: Evan Prodromou
Date: Sat, 20 Feb 2010 11:17:54 -0500
Subject: Cool bug! Technically good PHP syntax
---
plugins/OStatus/classes/Ostatus_profile.php | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
(limited to 'plugins/OStatus')
diff --git a/plugins/OStatus/classes/Ostatus_profile.php b/plugins/OStatus/classes/Ostatus_profile.php
index b14b4c9a3..9f5c60561 100644
--- a/plugins/OStatus/classes/Ostatus_profile.php
+++ b/plugins/OStatus/classes/Ostatus_profile.php
@@ -149,7 +149,6 @@ class Ostatus_profile extends Memcached_DataObject
function asActivityNoun($element)
{
$xs = new XMLStringer(true);
-
$avatarHref = Avatar::defaultImage(AVATAR_PROFILE_SIZE);
$avatarType = 'image/png';
if ($this->isGroup()) {
@@ -173,8 +172,8 @@ class Ostatus_profile extends Memcached_DataObject
$self = $this->localProfile();
$avatar = $self->getAvatar(AVATAR_PROFILE_SIZE);
if ($avatar) {
- $avatarHref = $avatar->
- $avatarType = $avatar->mediatype;
+ $avatarHref = $avatar->url;
+ $avatarType = $avatar->mediatype;
}
}
$xs->elementStart('activity:' . $element);
@@ -672,10 +671,10 @@ class Ostatus_profile extends Memcached_DataObject
// Get the canonical feed URI and check it
$discover = new FeedDiscovery();
$feeduri = $discover->discoverFromURL($homeuri);
-
+
$huburi = $discover->getAtomLink('hub');
$salmonuri = $discover->getAtomLink('salmon');
-
+
if (!$huburi) {
// We can only deal with folks with a PuSH hub
throw new FeedSubNoHubException();
--
cgit v1.2.3-54-g00ecf
From ab4ec095e811f86c50fbc1cd71144b11d6b86d50 Mon Sep 17 00:00:00 2001
From: Evan Prodromou
Date: Sat, 20 Feb 2010 11:38:05 -0500
Subject: adjust URI, URL, and location in Ostatus_profile::processPost
---
plugins/OStatus/classes/Ostatus_profile.php | 25 +++++++++++++++----------
1 file changed, 15 insertions(+), 10 deletions(-)
(limited to 'plugins/OStatus')
diff --git a/plugins/OStatus/classes/Ostatus_profile.php b/plugins/OStatus/classes/Ostatus_profile.php
index 9f5c60561..4dd565288 100644
--- a/plugins/OStatus/classes/Ostatus_profile.php
+++ b/plugins/OStatus/classes/Ostatus_profile.php
@@ -457,28 +457,33 @@ class Ostatus_profile extends Memcached_DataObject
$oprofile = $this;
}
- if ($activity->object->link) {
- $sourceUri = $activity->object->link;
- } else if (preg_match('!^https?://!', $activity->object->id)) {
- $sourceUri = $activity->object->id;
- } else {
- common_log(LOG_INFO, "OStatus: ignoring post with no source link: id $activity->object->id");
- return;
- }
+ $sourceUri = $activity->object->id;
$dupe = Notice::staticGet('uri', $sourceUri);
+
if ($dupe) {
- common_log(LOG_INFO, "OStatus: ignoring duplicate post: $noticeLink");
+ common_log(LOG_INFO, "OStatus: ignoring duplicate post: $sourceUri");
return;
}
+ $sourceUrl = null;
+
+ if ($activity->object->link) {
+ $sourceUrl = $activity->object->link;
+ } else if (preg_match('!^https?://!', $activity->object->id)) {
+ $sourceUrl = $activity->object->id;
+ }
+
// @fixme sanitize and save HTML content if available
+
$content = $activity->object->title;
$params = array('is_local' => Notice::REMOTE_OMB,
+ 'url' => $sourceUrl,
'uri' => $sourceUri);
- $location = $this->getEntryLocation($activity->entry);
+ $location = $activity->context->location;
+
if ($location) {
$params['lat'] = $location->lat;
$params['lon'] = $location->lon;
--
cgit v1.2.3-54-g00ecf
From 866b6470629b570b9f817553f85f6d8e801f0d43 Mon Sep 17 00:00:00 2001
From: Evan Prodromou
Date: Sat, 20 Feb 2010 11:48:42 -0500
Subject: add hooks for OStatus notification on subscribe/unsubscribe
---
plugins/OStatus/OStatusPlugin.php | 44 +++++++++++++++++++++++++++++++++++++++
1 file changed, 44 insertions(+)
(limited to 'plugins/OStatus')
diff --git a/plugins/OStatus/OStatusPlugin.php b/plugins/OStatus/OStatusPlugin.php
index e1f3fd9d3..9e6d03177 100644
--- a/plugins/OStatus/OStatusPlugin.php
+++ b/plugins/OStatus/OStatusPlugin.php
@@ -335,4 +335,48 @@ class OStatusPlugin extends Plugin
common_log(LOG_DEBUG, "No ostatus profile for incoming feed $feedsub->uri");
}
}
+
+ function onEndSubscribe($subscriber, $other)
+ {
+ $user = User::staticGet('id', $subscriber->id);
+
+ if (empty($user)) {
+ return true;
+ }
+
+ $oprofile = Ostatus_profile::staticGet('profile_id', $other->id);
+
+ if (empty($oprofile)) {
+ return true;
+ }
+
+ // We have a local user subscribing to a remote profile; make the
+ // magic happen!
+
+ $oprofile->notify($subscriber, ActivityVerb::FOLLOW);
+
+ return true;
+ }
+
+ function onEndUnsubscribe($subscriber, $other)
+ {
+ $user = User::staticGet('id', $subscriber->id);
+
+ if (empty($user)) {
+ return true;
+ }
+
+ $oprofile = Ostatus_profile::staticGet('profile_id', $other->id);
+
+ if (empty($oprofile)) {
+ return true;
+ }
+
+ // We have a local user subscribing to a remote profile; make the
+ // magic happen!
+
+ $oprofile->notify($subscriber, ActivityVerb::UNFOLLOW);
+
+ return true;
+ }
}
--
cgit v1.2.3-54-g00ecf
From 97b01432e7903797e39205e46a51394feac54292 Mon Sep 17 00:00:00 2001
From: Brion Vibber
Date: Sat, 20 Feb 2010 10:06:28 -0800
Subject: drop no-longer-used XML_Feed_Parser extlib package from OStatus
plugin
---
plugins/OStatus/extlib/README | 9 -
plugins/OStatus/extlib/XML/Feed/Parser.php | 351 ----------------
plugins/OStatus/extlib/XML/Feed/Parser/Atom.php | 365 ----------------
.../OStatus/extlib/XML/Feed/Parser/AtomElement.php | 261 ------------
.../OStatus/extlib/XML/Feed/Parser/Exception.php | 42 --
plugins/OStatus/extlib/XML/Feed/Parser/RSS09.php | 214 ----------
.../extlib/XML/Feed/Parser/RSS09Element.php | 62 ---
plugins/OStatus/extlib/XML/Feed/Parser/RSS1.php | 277 ------------
plugins/OStatus/extlib/XML/Feed/Parser/RSS11.php | 276 ------------
.../extlib/XML/Feed/Parser/RSS11Element.php | 151 -------
.../OStatus/extlib/XML/Feed/Parser/RSS1Element.php | 116 -----
plugins/OStatus/extlib/XML/Feed/Parser/RSS2.php | 335 ---------------
.../OStatus/extlib/XML/Feed/Parser/RSS2Element.php | 171 --------
plugins/OStatus/extlib/XML/Feed/Parser/Type.php | 467 ---------------------
.../extlib/XML/Feed/samples/atom10-entryonly.xml | 28 --
.../extlib/XML/Feed/samples/atom10-example1.xml | 20 -
.../extlib/XML/Feed/samples/atom10-example2.xml | 45 --
.../OStatus/extlib/XML/Feed/samples/delicious.feed | 177 --------
.../OStatus/extlib/XML/Feed/samples/flickr.feed | 184 --------
.../extlib/XML/Feed/samples/grwifi-atom.xml | 7 -
plugins/OStatus/extlib/XML/Feed/samples/hoder.xml | 102 -----
.../extlib/XML/Feed/samples/illformed_atom10.xml | 13 -
.../extlib/XML/Feed/samples/rss091-complete.xml | 47 ---
.../XML/Feed/samples/rss091-international.xml | 30 --
.../extlib/XML/Feed/samples/rss091-simple.xml | 15 -
.../extlib/XML/Feed/samples/rss092-sample.xml | 103 -----
.../extlib/XML/Feed/samples/rss10-example1.xml | 62 ---
.../extlib/XML/Feed/samples/rss10-example2.xml | 67 ---
.../OStatus/extlib/XML/Feed/samples/rss2sample.xml | 42 --
.../extlib/XML/Feed/samples/sixapart-jp.xml | 226 ----------
.../extlib/XML/Feed/samples/technorati.feed | 54 ---
plugins/OStatus/extlib/XML/Feed/schemas/atom.rnc | 338 ---------------
plugins/OStatus/extlib/XML/Feed/schemas/rss10.rnc | 113 -----
plugins/OStatus/extlib/XML/Feed/schemas/rss11.rnc | 218 ----------
.../OStatus/extlib/xml-feed-parser-bug-16416.patch | 14 -
plugins/OStatus/tests/FeedMungerTest.php | 147 -------
36 files changed, 5149 deletions(-)
delete mode 100644 plugins/OStatus/extlib/README
delete mode 100755 plugins/OStatus/extlib/XML/Feed/Parser.php
delete mode 100644 plugins/OStatus/extlib/XML/Feed/Parser/Atom.php
delete mode 100755 plugins/OStatus/extlib/XML/Feed/Parser/AtomElement.php
delete mode 100755 plugins/OStatus/extlib/XML/Feed/Parser/Exception.php
delete mode 100755 plugins/OStatus/extlib/XML/Feed/Parser/RSS09.php
delete mode 100755 plugins/OStatus/extlib/XML/Feed/Parser/RSS09Element.php
delete mode 100755 plugins/OStatus/extlib/XML/Feed/Parser/RSS1.php
delete mode 100755 plugins/OStatus/extlib/XML/Feed/Parser/RSS11.php
delete mode 100755 plugins/OStatus/extlib/XML/Feed/Parser/RSS11Element.php
delete mode 100755 plugins/OStatus/extlib/XML/Feed/Parser/RSS1Element.php
delete mode 100644 plugins/OStatus/extlib/XML/Feed/Parser/RSS2.php
delete mode 100755 plugins/OStatus/extlib/XML/Feed/Parser/RSS2Element.php
delete mode 100644 plugins/OStatus/extlib/XML/Feed/Parser/Type.php
delete mode 100755 plugins/OStatus/extlib/XML/Feed/samples/atom10-entryonly.xml
delete mode 100755 plugins/OStatus/extlib/XML/Feed/samples/atom10-example1.xml
delete mode 100755 plugins/OStatus/extlib/XML/Feed/samples/atom10-example2.xml
delete mode 100755 plugins/OStatus/extlib/XML/Feed/samples/delicious.feed
delete mode 100755 plugins/OStatus/extlib/XML/Feed/samples/flickr.feed
delete mode 100755 plugins/OStatus/extlib/XML/Feed/samples/grwifi-atom.xml
delete mode 100755 plugins/OStatus/extlib/XML/Feed/samples/hoder.xml
delete mode 100755 plugins/OStatus/extlib/XML/Feed/samples/illformed_atom10.xml
delete mode 100755 plugins/OStatus/extlib/XML/Feed/samples/rss091-complete.xml
delete mode 100755 plugins/OStatus/extlib/XML/Feed/samples/rss091-international.xml
delete mode 100755 plugins/OStatus/extlib/XML/Feed/samples/rss091-simple.xml
delete mode 100755 plugins/OStatus/extlib/XML/Feed/samples/rss092-sample.xml
delete mode 100755 plugins/OStatus/extlib/XML/Feed/samples/rss10-example1.xml
delete mode 100755 plugins/OStatus/extlib/XML/Feed/samples/rss10-example2.xml
delete mode 100755 plugins/OStatus/extlib/XML/Feed/samples/rss2sample.xml
delete mode 100755 plugins/OStatus/extlib/XML/Feed/samples/sixapart-jp.xml
delete mode 100755 plugins/OStatus/extlib/XML/Feed/samples/technorati.feed
delete mode 100755 plugins/OStatus/extlib/XML/Feed/schemas/atom.rnc
delete mode 100755 plugins/OStatus/extlib/XML/Feed/schemas/rss10.rnc
delete mode 100755 plugins/OStatus/extlib/XML/Feed/schemas/rss11.rnc
delete mode 100644 plugins/OStatus/extlib/xml-feed-parser-bug-16416.patch
delete mode 100644 plugins/OStatus/tests/FeedMungerTest.php
(limited to 'plugins/OStatus')
diff --git a/plugins/OStatus/extlib/README b/plugins/OStatus/extlib/README
deleted file mode 100644
index 799b40c47..000000000
--- a/plugins/OStatus/extlib/README
+++ /dev/null
@@ -1,9 +0,0 @@
-XML_Feed_Parser 1.0.3 is not currently actively maintained, and has
-a nasty bug which breaks getting the feed target link from WordPress
-feeds and possibly others that are RSS2-formatted but include an
- self-link element as well.
-
-Patch from this bug report is included:
-http://pear.php.net/bugs/bug.php?id=16416
-
-If upgrading, be sure that fix is included with the future upgrade!
diff --git a/plugins/OStatus/extlib/XML/Feed/Parser.php b/plugins/OStatus/extlib/XML/Feed/Parser.php
deleted file mode 100755
index ffe8220a5..000000000
--- a/plugins/OStatus/extlib/XML/Feed/Parser.php
+++ /dev/null
@@ -1,351 +0,0 @@
-
- * @copyright 2005 James Stewart
- * @license http://www.gnu.org/copyleft/lesser.html GNU LGPL
- * @version CVS: $Id: Parser.php,v 1.24 2006/08/15 13:04:00 jystewart Exp $
- * @link http://pear.php.net/package/XML_Feed_Parser/
- */
-
-/**
- * XML_Feed_Parser_Type is an abstract class required by all of our
- * feed types. It makes sense to load it here to keep the other files
- * clean.
- */
-require_once 'XML/Feed/Parser/Type.php';
-
-/**
- * We will throw exceptions when errors occur.
- */
-require_once 'XML/Feed/Parser/Exception.php';
-
-/**
- * This is the core of the XML_Feed_Parser package. It identifies feed types
- * and abstracts access to them. It is an iterator, allowing for easy access
- * to the entire feed.
- *
- * @author James Stewart
- * @version Release: 1.0.3
- * @package XML_Feed_Parser
- */
-class XML_Feed_Parser implements Iterator
-{
- /**
- * This is where we hold the feed object
- * @var Object
- */
- private $feed;
-
- /**
- * To allow for extensions, we make a public reference to the feed model
- * @var DOMDocument
- */
- public $model;
-
- /**
- * A map between entry ID and offset
- * @var array
- */
- protected $idMappings = array();
-
- /**
- * A storage space for Namespace URIs.
- * @var array
- */
- private $feedNamespaces = array(
- 'rss2' => array(
- 'http://backend.userland.com/rss',
- 'http://backend.userland.com/rss2',
- 'http://blogs.law.harvard.edu/tech/rss'));
- /**
- * Detects feed types and instantiate appropriate objects.
- *
- * Our constructor takes care of detecting feed types and instantiating
- * appropriate classes. For now we're going to treat Atom 0.3 as Atom 1.0
- * but raise a warning. I do not intend to introduce full support for
- * Atom 0.3 as it has been deprecated, but others are welcome to.
- *
- * @param string $feed XML serialization of the feed
- * @param bool $strict Whether or not to validate the feed
- * @param bool $suppressWarnings Trigger errors for deprecated feed types?
- * @param bool $tidy Whether or not to try and use the tidy library on input
- */
- function __construct($feed, $strict = false, $suppressWarnings = false, $tidy = false)
- {
- $this->model = new DOMDocument;
- if (! $this->model->loadXML($feed)) {
- if (extension_loaded('tidy') && $tidy) {
- $tidy = new tidy;
- $tidy->parseString($feed,
- array('input-xml' => true, 'output-xml' => true));
- $tidy->cleanRepair();
- if (! $this->model->loadXML((string) $tidy)) {
- throw new XML_Feed_Parser_Exception('Invalid input: this is not ' .
- 'valid XML');
- }
- } else {
- throw new XML_Feed_Parser_Exception('Invalid input: this is not valid XML');
- }
-
- }
-
- /* detect feed type */
- $doc_element = $this->model->documentElement;
- $error = false;
-
- switch (true) {
- case ($doc_element->namespaceURI == 'http://www.w3.org/2005/Atom'):
- require_once 'XML/Feed/Parser/Atom.php';
- require_once 'XML/Feed/Parser/AtomElement.php';
- $class = 'XML_Feed_Parser_Atom';
- break;
- case ($doc_element->namespaceURI == 'http://purl.org/atom/ns#'):
- require_once 'XML/Feed/Parser/Atom.php';
- require_once 'XML/Feed/Parser/AtomElement.php';
- $class = 'XML_Feed_Parser_Atom';
- $error = 'Atom 0.3 deprecated, using 1.0 parser which won\'t provide ' .
- 'all options';
- break;
- case ($doc_element->namespaceURI == 'http://purl.org/rss/1.0/' ||
- ($doc_element->hasChildNodes() && $doc_element->childNodes->length > 1
- && $doc_element->childNodes->item(1)->namespaceURI ==
- 'http://purl.org/rss/1.0/')):
- require_once 'XML/Feed/Parser/RSS1.php';
- require_once 'XML/Feed/Parser/RSS1Element.php';
- $class = 'XML_Feed_Parser_RSS1';
- break;
- case ($doc_element->namespaceURI == 'http://purl.org/rss/1.1/' ||
- ($doc_element->hasChildNodes() && $doc_element->childNodes->length > 1
- && $doc_element->childNodes->item(1)->namespaceURI ==
- 'http://purl.org/rss/1.1/')):
- require_once 'XML/Feed/Parser/RSS11.php';
- require_once 'XML/Feed/Parser/RSS11Element.php';
- $class = 'XML_Feed_Parser_RSS11';
- break;
- case (($doc_element->hasChildNodes() && $doc_element->childNodes->length > 1
- && $doc_element->childNodes->item(1)->namespaceURI ==
- 'http://my.netscape.com/rdf/simple/0.9/') ||
- $doc_element->namespaceURI == 'http://my.netscape.com/rdf/simple/0.9/'):
- require_once 'XML/Feed/Parser/RSS09.php';
- require_once 'XML/Feed/Parser/RSS09Element.php';
- $class = 'XML_Feed_Parser_RSS09';
- break;
- case ($doc_element->tagName == 'rss' and
- $doc_element->hasAttribute('version') &&
- $doc_element->getAttribute('version') == 0.91):
- $error = 'RSS 0.91 has been superceded by RSS2.0. Using RSS2.0 parser.';
- require_once 'XML/Feed/Parser/RSS2.php';
- require_once 'XML/Feed/Parser/RSS2Element.php';
- $class = 'XML_Feed_Parser_RSS2';
- break;
- case ($doc_element->tagName == 'rss' and
- $doc_element->hasAttribute('version') &&
- $doc_element->getAttribute('version') == 0.92):
- $error = 'RSS 0.92 has been superceded by RSS2.0. Using RSS2.0 parser.';
- require_once 'XML/Feed/Parser/RSS2.php';
- require_once 'XML/Feed/Parser/RSS2Element.php';
- $class = 'XML_Feed_Parser_RSS2';
- break;
- case (in_array($doc_element->namespaceURI, $this->feedNamespaces['rss2'])
- || $doc_element->tagName == 'rss'):
- if (! $doc_element->hasAttribute('version') ||
- $doc_element->getAttribute('version') != 2) {
- $error = 'RSS version not specified. Parsing as RSS2.0';
- }
- require_once 'XML/Feed/Parser/RSS2.php';
- require_once 'XML/Feed/Parser/RSS2Element.php';
- $class = 'XML_Feed_Parser_RSS2';
- break;
- default:
- throw new XML_Feed_Parser_Exception('Feed type unknown');
- break;
- }
-
- if (! $suppressWarnings && ! empty($error)) {
- trigger_error($error, E_USER_WARNING);
- }
-
- /* Instantiate feed object */
- $this->feed = new $class($this->model, $strict);
- }
-
- /**
- * Proxy to allow feed element names to be used as method names
- *
- * For top-level feed elements we will provide access using methods or
- * attributes. This function simply passes on a request to the appropriate
- * feed type object.
- *
- * @param string $call - the method being called
- * @param array $attributes
- */
- function __call($call, $attributes)
- {
- $attributes = array_pad($attributes, 5, false);
- list($a, $b, $c, $d, $e) = $attributes;
- return $this->feed->$call($a, $b, $c, $d, $e);
- }
-
- /**
- * Proxy to allow feed element names to be used as attribute names
- *
- * To allow variable-like access to feed-level data we use this
- * method. It simply passes along to __call() which in turn passes
- * along to the relevant object.
- *
- * @param string $val - the name of the variable required
- */
- function __get($val)
- {
- return $this->feed->$val;
- }
-
- /**
- * Provides iteration functionality.
- *
- * Of course we must be able to iterate... This function simply increases
- * our internal counter.
- */
- function next()
- {
- if (isset($this->current_item) &&
- $this->current_item <= $this->feed->numberEntries - 1) {
- ++$this->current_item;
- } else if (! isset($this->current_item)) {
- $this->current_item = 0;
- } else {
- return false;
- }
- }
-
- /**
- * Return XML_Feed_Type object for current element
- *
- * @return XML_Feed_Parser_Type Object
- */
- function current()
- {
- return $this->getEntryByOffset($this->current_item);
- }
-
- /**
- * For iteration -- returns the key for the current stage in the array.
- *
- * @return int
- */
- function key()
- {
- return $this->current_item;
- }
-
- /**
- * For iteration -- tells whether we have reached the
- * end.
- *
- * @return bool
- */
- function valid()
- {
- return $this->current_item < $this->feed->numberEntries;
- }
-
- /**
- * For iteration -- resets the internal counter to the beginning.
- */
- function rewind()
- {
- $this->current_item = 0;
- }
-
- /**
- * Provides access to entries by ID if one is specified in the source feed.
- *
- * As well as allowing the items to be iterated over we want to allow
- * users to be able to access a specific entry. This is one of two ways of
- * doing that, the other being by offset. This method can be quite slow
- * if dealing with a large feed that hasn't yet been processed as it
- * instantiates objects for every entry until it finds the one needed.
- *
- * @param string $id Valid ID for the given feed format
- * @return XML_Feed_Parser_Type|false
- */
- function getEntryById($id)
- {
- if (isset($this->idMappings[$id])) {
- return $this->getEntryByOffset($this->idMappings[$id]);
- }
-
- /*
- * Since we have not yet encountered that ID, let's go through all the
- * remaining entries in order till we find it.
- * This is a fairly slow implementation, but it should work.
- */
- return $this->feed->getEntryById($id);
- }
-
- /**
- * Retrieve entry by numeric offset, starting from zero.
- *
- * As well as allowing the items to be iterated over we want to allow
- * users to be able to access a specific entry. This is one of two ways of
- * doing that, the other being by ID.
- *
- * @param int $offset The position of the entry within the feed, starting from 0
- * @return XML_Feed_Parser_Type|false
- */
- function getEntryByOffset($offset)
- {
- if ($offset < $this->feed->numberEntries) {
- if (isset($this->feed->entries[$offset])) {
- return $this->feed->entries[$offset];
- } else {
- try {
- $this->feed->getEntryByOffset($offset);
- } catch (Exception $e) {
- return false;
- }
- $id = $this->feed->entries[$offset]->getID();
- $this->idMappings[$id] = $offset;
- return $this->feed->entries[$offset];
- }
- } else {
- return false;
- }
- }
-
- /**
- * Retrieve version details from feed type class.
- *
- * @return void
- * @author James Stewart
- */
- function version()
- {
- return $this->feed->version;
- }
-
- /**
- * Returns a string representation of the feed.
- *
- * @return String
- **/
- function __toString()
- {
- return $this->feed->__toString();
- }
-}
-?>
\ No newline at end of file
diff --git a/plugins/OStatus/extlib/XML/Feed/Parser/Atom.php b/plugins/OStatus/extlib/XML/Feed/Parser/Atom.php
deleted file mode 100644
index c7e218a1e..000000000
--- a/plugins/OStatus/extlib/XML/Feed/Parser/Atom.php
+++ /dev/null
@@ -1,365 +0,0 @@
-
- * @copyright 2005 James Stewart
- * @license http://www.gnu.org/copyleft/lesser.html GNU LGPL 2.1
- * @version CVS: $Id: Atom.php,v 1.29 2008/03/30 22:00:36 jystewart Exp $
- * @link http://pear.php.net/package/XML_Feed_Parser/
-*/
-
-/**
- * This is the class that determines how we manage Atom 1.0 feeds
- *
- * How we deal with constructs:
- * date - return as unix datetime for use with the 'date' function unless specified otherwise
- * text - return as is. optional parameter will give access to attributes
- * person - defaults to name, but parameter based access
- *
- * @author James Stewart
- * @version Release: 1.0.3
- * @package XML_Feed_Parser
- */
-class XML_Feed_Parser_Atom extends XML_Feed_Parser_Type
-{
- /**
- * The URI of the RelaxNG schema used to (optionally) validate the feed
- * @var string
- */
- private $relax = 'atom.rnc';
-
- /**
- * We're likely to use XPath, so let's keep it global
- * @var DOMXPath
- */
- public $xpath;
-
- /**
- * When performing XPath queries we will use this prefix
- * @var string
- */
- private $xpathPrefix = '//';
-
- /**
- * The feed type we are parsing
- * @var string
- */
- public $version = 'Atom 1.0';
-
- /**
- * The class used to represent individual items
- * @var string
- */
- protected $itemClass = 'XML_Feed_Parser_AtomElement';
-
- /**
- * The element containing entries
- * @var string
- */
- protected $itemElement = 'entry';
-
- /**
- * Here we map those elements we're not going to handle individually
- * to the constructs they are. The optional second parameter in the array
- * tells the parser whether to 'fall back' (not apt. at the feed level) or
- * fail if the element is missing. If the parameter is not set, the function
- * will simply return false and leave it to the client to decide what to do.
- * @var array
- */
- protected $map = array(
- 'author' => array('Person'),
- 'contributor' => array('Person'),
- 'icon' => array('Text'),
- 'logo' => array('Text'),
- 'id' => array('Text', 'fail'),
- 'rights' => array('Text'),
- 'subtitle' => array('Text'),
- 'title' => array('Text', 'fail'),
- 'updated' => array('Date', 'fail'),
- 'link' => array('Link'),
- 'generator' => array('Text'),
- 'category' => array('Category'));
-
- /**
- * Here we provide a few mappings for those very special circumstances in
- * which it makes sense to map back to the RSS2 spec. Key is RSS2 version
- * value is an array consisting of the equivalent in atom and any attributes
- * needed to make the mapping.
- * @var array
- */
- protected $compatMap = array(
- 'guid' => array('id'),
- 'links' => array('link'),
- 'tags' => array('category'),
- 'contributors' => array('contributor'));
-
- /**
- * Our constructor does nothing more than its parent.
- *
- * @param DOMDocument $xml A DOM object representing the feed
- * @param bool (optional) $string Whether or not to validate this feed
- */
- function __construct(DOMDocument $model, $strict = false)
- {
- $this->model = $model;
-
- if ($strict) {
- if (! $this->model->relaxNGValidateSource($this->relax)) {
- throw new XML_Feed_Parser_Exception('Failed required validation');
- }
- }
-
- $this->xpath = new DOMXPath($this->model);
- $this->xpath->registerNamespace('atom', 'http://www.w3.org/2005/Atom');
- $this->numberEntries = $this->count('entry');
- }
-
- /**
- * Implement retrieval of an entry based on its ID for atom feeds.
- *
- * This function uses XPath to get the entry based on its ID. If DOMXPath::evaluate
- * is available, we also use that to store a reference to the entry in the array
- * used by getEntryByOffset so that method does not have to seek out the entry
- * if it's requested that way.
- *
- * @param string $id any valid Atom ID.
- * @return XML_Feed_Parser_AtomElement
- */
- function getEntryById($id)
- {
- if (isset($this->idMappings[$id])) {
- return $this->entries[$this->idMappings[$id]];
- }
-
- $entries = $this->xpath->query("//atom:entry[atom:id='$id']");
-
- if ($entries->length > 0) {
- $xmlBase = $entries->item(0)->baseURI;
- $entry = new $this->itemClass($entries->item(0), $this, $xmlBase);
-
- if (in_array('evaluate', get_class_methods($this->xpath))) {
- $offset = $this->xpath->evaluate("count(preceding-sibling::atom:entry)", $entries->item(0));
- $this->entries[$offset] = $entry;
- }
-
- $this->idMappings[$id] = $entry;
-
- return $entry;
- }
-
- }
-
- /**
- * Retrieves data from a person construct.
- *
- * Get a person construct. We default to the 'name' element but allow
- * access to any of the elements.
- *
- * @param string $method The name of the person construct we want
- * @param array $arguments An array which we hope gives a 'param'
- * @return string|false
- */
- protected function getPerson($method, $arguments)
- {
- $offset = empty($arguments[0]) ? 0 : $arguments[0];
- $parameter = empty($arguments[1]['param']) ? 'name' : $arguments[1]['param'];
- $section = $this->model->getElementsByTagName($method);
-
- if ($parameter == 'url') {
- $parameter = 'uri';
- }
-
- if ($section->length <= $offset) {
- return false;
- }
-
- $param = $section->item($offset)->getElementsByTagName($parameter);
- if ($param->length == 0) {
- return false;
- }
- return $param->item(0)->nodeValue;
- }
-
- /**
- * Retrieves an element's content where that content is a text construct.
- *
- * Get a text construct. When calling this method, the two arguments
- * allowed are 'offset' and 'attribute', so $parser->subtitle() would
- * return the content of the element, while $parser->subtitle(false, 'type')
- * would return the value of the type attribute.
- *
- * @todo Clarify overlap with getContent()
- * @param string $method The name of the text construct we want
- * @param array $arguments An array which we hope gives a 'param'
- * @return string
- */
- protected function getText($method, $arguments)
- {
- $offset = empty($arguments[0]) ? 0: $arguments[0];
- $attribute = empty($arguments[1]) ? false : $arguments[1];
- $tags = $this->model->getElementsByTagName($method);
-
- if ($tags->length <= $offset) {
- return false;
- }
-
- $content = $tags->item($offset);
-
- if (! $content->hasAttribute('type')) {
- $content->setAttribute('type', 'text');
- }
- $type = $content->getAttribute('type');
-
- if (! empty($attribute) and
- ! ($method == 'generator' and $attribute == 'name')) {
- if ($content->hasAttribute($attribute)) {
- return $content->getAttribute($attribute);
- } else if ($attribute == 'href' and $content->hasAttribute('uri')) {
- return $content->getAttribute('uri');
- }
- return false;
- }
-
- return $this->parseTextConstruct($content);
- }
-
- /**
- * Extract content appropriately from atom text constructs
- *
- * Because of different rules applied to the content element and other text
- * constructs, they are deployed as separate functions, but they share quite
- * a bit of processing. This method performs the core common process, which is
- * to apply the rules for different mime types in order to extract the content.
- *
- * @param DOMNode $content the text construct node to be parsed
- * @return String
- * @author James Stewart
- **/
- protected function parseTextConstruct(DOMNode $content)
- {
- if ($content->hasAttribute('type')) {
- $type = $content->getAttribute('type');
- } else {
- $type = 'text';
- }
-
- if (strpos($type, 'text/') === 0) {
- $type = 'text';
- }
-
- switch ($type) {
- case 'text':
- case 'html':
- return $content->textContent;
- break;
- case 'xhtml':
- $container = $content->getElementsByTagName('div');
- if ($container->length == 0) {
- return false;
- }
- $contents = $container->item(0);
- if ($contents->hasChildNodes()) {
- /* Iterate through, applying xml:base and store the result */
- $result = '';
- foreach ($contents->childNodes as $node) {
- $result .= $this->traverseNode($node);
- }
- return $result;
- }
- break;
- case preg_match('@^[a-zA-Z]+/[a-zA-Z+]*xml@i', $type) > 0:
- return $content;
- break;
- case 'application/octet-stream':
- default:
- return base64_decode(trim($content->nodeValue));
- break;
- }
- return false;
- }
- /**
- * Get a category from the entry.
- *
- * A feed or entry can have any number of categories. A category can have the
- * attributes term, scheme and label.
- *
- * @param string $method The name of the text construct we want
- * @param array $arguments An array which we hope gives a 'param'
- * @return string
- */
- function getCategory($method, $arguments)
- {
- $offset = empty($arguments[0]) ? 0: $arguments[0];
- $attribute = empty($arguments[1]) ? 'term' : $arguments[1];
- $categories = $this->model->getElementsByTagName('category');
- if ($categories->length <= $offset) {
- $category = $categories->item($offset);
- if ($category->hasAttribute($attribute)) {
- return $category->getAttribute($attribute);
- }
- }
- return false;
- }
-
- /**
- * This element must be present at least once with rel="feed". This element may be
- * present any number of further times so long as there is no clash. If no 'rel' is
- * present and we're asked for one, we follow the example of the Universal Feed
- * Parser and presume 'alternate'.
- *
- * @param int $offset the position of the link within the container
- * @param string $attribute the attribute name required
- * @param array an array of attributes to search by
- * @return string the value of the attribute
- */
- function getLink($offset = 0, $attribute = 'href', $params = false)
- {
- if (is_array($params) and !empty($params)) {
- $terms = array();
- $alt_predicate = '';
- $other_predicate = '';
-
- foreach ($params as $key => $value) {
- if ($key == 'rel' && $value == 'alternate') {
- $alt_predicate = '[not(@rel) or @rel="alternate"]';
- } else {
- $terms[] = "@$key='$value'";
- }
- }
- if (!empty($terms)) {
- $other_predicate = '[' . join(' and ', $terms) . ']';
- }
- $query = $this->xpathPrefix . 'atom:link' . $alt_predicate . $other_predicate;
- $links = $this->xpath->query($query);
- } else {
- $links = $this->model->getElementsByTagName('link');
- }
- if ($links->length > $offset) {
- if ($links->item($offset)->hasAttribute($attribute)) {
- $value = $links->item($offset)->getAttribute($attribute);
- if ($attribute == 'href') {
- $value = $this->addBase($value, $links->item($offset));
- }
- return $value;
- } else if ($attribute == 'rel') {
- return 'alternate';
- }
- }
- return false;
- }
-}
-
-?>
\ No newline at end of file
diff --git a/plugins/OStatus/extlib/XML/Feed/Parser/AtomElement.php b/plugins/OStatus/extlib/XML/Feed/Parser/AtomElement.php
deleted file mode 100755
index 063ecb617..000000000
--- a/plugins/OStatus/extlib/XML/Feed/Parser/AtomElement.php
+++ /dev/null
@@ -1,261 +0,0 @@
-
- * @copyright 2005 James Stewart
- * @license http://www.gnu.org/copyleft/lesser.html GNU LGPL 2.1
- * @version CVS: $Id: AtomElement.php,v 1.19 2007/03/26 12:43:11 jystewart Exp $
- * @link http://pear.php.net/package/XML_Feed_Parser/
- */
-
-/**
- * This class provides support for atom entries. It will usually be called by
- * XML_Feed_Parser_Atom with which it shares many methods.
- *
- * @author James Stewart
- * @version Release: 1.0.3
- * @package XML_Feed_Parser
- */
-class XML_Feed_Parser_AtomElement extends XML_Feed_Parser_Atom
-{
- /**
- * This will be a reference to the parent object for when we want
- * to use a 'fallback' rule
- * @var XML_Feed_Parser_Atom
- */
- protected $parent;
-
- /**
- * When performing XPath queries we will use this prefix
- * @var string
- */
- private $xpathPrefix = '';
-
- /**
- * xml:base values inherited by the element
- * @var string
- */
- protected $xmlBase;
-
- /**
- * Here we provide a few mappings for those very special circumstances in
- * which it makes sense to map back to the RSS2 spec or to manage other
- * compatibilities (eg. with the Univeral Feed Parser). Key is the other version's
- * name for the command, value is an array consisting of the equivalent in our atom
- * api and any attributes needed to make the mapping.
- * @var array
- */
- protected $compatMap = array(
- 'guid' => array('id'),
- 'links' => array('link'),
- 'tags' => array('category'),
- 'contributors' => array('contributor'));
-
- /**
- * Our specific element map
- * @var array
- */
- protected $map = array(
- 'author' => array('Person', 'fallback'),
- 'contributor' => array('Person'),
- 'id' => array('Text', 'fail'),
- 'published' => array('Date'),
- 'updated' => array('Date', 'fail'),
- 'title' => array('Text', 'fail'),
- 'rights' => array('Text', 'fallback'),
- 'summary' => array('Text'),
- 'content' => array('Content'),
- 'link' => array('Link'),
- 'enclosure' => array('Enclosure'),
- 'category' => array('Category'));
-
- /**
- * Store useful information for later.
- *
- * @param DOMElement $element - this item as a DOM element
- * @param XML_Feed_Parser_Atom $parent - the feed of which this is a member
- */
- function __construct(DOMElement $element, $parent, $xmlBase = '')
- {
- $this->model = $element;
- $this->parent = $parent;
- $this->xmlBase = $xmlBase;
- $this->xpathPrefix = "//atom:entry[atom:id='" . $this->id . "']/";
- $this->xpath = $this->parent->xpath;
- }
-
- /**
- * Provides access to specific aspects of the author data for an atom entry
- *
- * Author data at the entry level is more complex than at the feed level.
- * If atom:author is not present for the entry we need to look for it in
- * an atom:source child of the atom:entry. If it's not there either, then
- * we look to the parent for data.
- *
- * @param array
- * @return string
- */
- function getAuthor($arguments)
- {
- /* Find out which part of the author data we're looking for */
- if (isset($arguments['param'])) {
- $parameter = $arguments['param'];
- } else {
- $parameter = 'name';
- }
-
- $test = $this->model->getElementsByTagName('author');
- if ($test->length > 0) {
- $item = $test->item(0);
- return $item->getElementsByTagName($parameter)->item(0)->nodeValue;
- }
-
- $source = $this->model->getElementsByTagName('source');
- if ($source->length > 0) {
- $test = $this->model->getElementsByTagName('author');
- if ($test->length > 0) {
- $item = $test->item(0);
- return $item->getElementsByTagName($parameter)->item(0)->nodeValue;
- }
- }
- return $this->parent->getAuthor($arguments);
- }
-
- /**
- * Returns the content of the content element or info on a specific attribute
- *
- * This element may or may not be present. It cannot be present more than
- * once. It may have a 'src' attribute, in which case there's no content
- * If not present, then the entry must have link with rel="alternate".
- * If there is content we return it, if not and there's a 'src' attribute
- * we return the value of that instead. The method can take an 'attribute'
- * argument, in which case we return the value of that attribute if present.
- * eg. $item->content("type") will return the type of the content. It is
- * recommended that all users check the type before getting the content to
- * ensure that their script is capable of handling the type of returned data.
- * (data carried in the content element can be either 'text', 'html', 'xhtml',
- * or any standard MIME type).
- *
- * @return string|false
- */
- protected function getContent($method, $arguments = array())
- {
- $attribute = empty($arguments[0]) ? false : $arguments[0];
- $tags = $this->model->getElementsByTagName('content');
-
- if ($tags->length == 0) {
- return false;
- }
-
- $content = $tags->item(0);
-
- if (! $content->hasAttribute('type')) {
- $content->setAttribute('type', 'text');
- }
- if (! empty($attribute)) {
- return $content->getAttribute($attribute);
- }
-
- $type = $content->getAttribute('type');
-
- if (! empty($attribute)) {
- if ($content->hasAttribute($attribute))
- {
- return $content->getAttribute($attribute);
- }
- return false;
- }
-
- if ($content->hasAttribute('src')) {
- return $content->getAttribute('src');
- }
-
- return $this->parseTextConstruct($content);
- }
-
- /**
- * For compatibility, this method provides a mapping to access enclosures.
- *
- * The Atom spec doesn't provide for an enclosure element, but it is
- * generally supported using the link element with rel='enclosure'.
- *
- * @param string $method - for compatibility with our __call usage
- * @param array $arguments - for compatibility with our __call usage
- * @return array|false
- */
- function getEnclosure($method, $arguments = array())
- {
- $offset = isset($arguments[0]) ? $arguments[0] : 0;
- $query = "//atom:entry[atom:id='" . $this->getText('id', false) .
- "']/atom:link[@rel='enclosure']";
-
- $encs = $this->parent->xpath->query($query);
- if ($encs->length > $offset) {
- try {
- if (! $encs->item($offset)->hasAttribute('href')) {
- return false;
- }
- $attrs = $encs->item($offset)->attributes;
- $length = $encs->item($offset)->hasAttribute('length') ?
- $encs->item($offset)->getAttribute('length') : false;
- return array(
- 'url' => $attrs->getNamedItem('href')->value,
- 'type' => $attrs->getNamedItem('type')->value,
- 'length' => $length);
- } catch (Exception $e) {
- return false;
- }
- }
- return false;
- }
-
- /**
- * Get details of this entry's source, if available/relevant
- *
- * Where an atom:entry is taken from another feed then the aggregator
- * is supposed to include an atom:source element which replicates at least
- * the atom:id, atom:title, and atom:updated metadata from the original
- * feed. Atom:source therefore has a very similar structure to atom:feed
- * and if we find it we will return it as an XML_Feed_Parser_Atom object.
- *
- * @return XML_Feed_Parser_Atom|false
- */
- function getSource()
- {
- $test = $this->model->getElementsByTagName('source');
- if ($test->length == 0) {
- return false;
- }
- $source = new XML_Feed_Parser_Atom($test->item(0));
- }
-
- /**
- * Get the entry as an XML string
- *
- * Return an XML serialization of the feed, should it be required. Most
- * users however, will already have a serialization that they used when
- * instantiating the object.
- *
- * @return string XML serialization of element
- */
- function __toString()
- {
- $simple = simplexml_import_dom($this->model);
- return $simple->asXML();
- }
-}
-
-?>
\ No newline at end of file
diff --git a/plugins/OStatus/extlib/XML/Feed/Parser/Exception.php b/plugins/OStatus/extlib/XML/Feed/Parser/Exception.php
deleted file mode 100755
index 1e76e3f85..000000000
--- a/plugins/OStatus/extlib/XML/Feed/Parser/Exception.php
+++ /dev/null
@@ -1,42 +0,0 @@
-
- * @copyright 2005 James Stewart
- * @license http://www.gnu.org/copyleft/lesser.html GNU LGPL
- * @version CVS: $Id: Exception.php,v 1.3 2005/11/07 01:52:35 jystewart Exp $
- * @link http://pear.php.net/package/XML_Feed_Parser/
- */
-
-/**
- * We are extending PEAR_Exception
- */
-require_once 'PEAR/Exception.php';
-
-/**
- * XML_Feed_Parser_Exception is a simple extension of PEAR_Exception, existing
- * to help with identification of the source of exceptions.
- *
- * @author James Stewart
- * @version Release: 1.0.3
- * @package XML_Feed_Parser
- */
-class XML_Feed_Parser_Exception extends PEAR_Exception
-{
-
-}
-
-?>
\ No newline at end of file
diff --git a/plugins/OStatus/extlib/XML/Feed/Parser/RSS09.php b/plugins/OStatus/extlib/XML/Feed/Parser/RSS09.php
deleted file mode 100755
index 07f38f911..000000000
--- a/plugins/OStatus/extlib/XML/Feed/Parser/RSS09.php
+++ /dev/null
@@ -1,214 +0,0 @@
-
- * @copyright 2005 James Stewart
- * @license http://www.gnu.org/copyleft/lesser.html GNU LGPL 2.1
- * @version CVS: $Id: RSS09.php,v 1.5 2006/07/26 21:18:46 jystewart Exp $
- * @link http://pear.php.net/package/XML_Feed_Parser/
- */
-
-/**
- * This class handles RSS0.9 feeds.
- *
- * @author James Stewart
- * @version Release: 1.0.3
- * @package XML_Feed_Parser
- * @todo Find a Relax NG URI we can use
- */
-class XML_Feed_Parser_RSS09 extends XML_Feed_Parser_Type
-{
- /**
- * The URI of the RelaxNG schema used to (optionally) validate the feed
- * @var string
- */
- private $relax = '';
-
- /**
- * We're likely to use XPath, so let's keep it global
- * @var DOMXPath
- */
- protected $xpath;
-
- /**
- * The feed type we are parsing
- * @var string
- */
- public $version = 'RSS 0.9';
-
- /**
- * The class used to represent individual items
- * @var string
- */
- protected $itemClass = 'XML_Feed_Parser_RSS09Element';
-
- /**
- * The element containing entries
- * @var string
- */
- protected $itemElement = 'item';
-
- /**
- * Here we map those elements we're not going to handle individually
- * to the constructs they are. The optional second parameter in the array
- * tells the parser whether to 'fall back' (not apt. at the feed level) or
- * fail if the element is missing. If the parameter is not set, the function
- * will simply return false and leave it to the client to decide what to do.
- * @var array
- */
- protected $map = array(
- 'title' => array('Text'),
- 'link' => array('Text'),
- 'description' => array('Text'),
- 'image' => array('Image'),
- 'textinput' => array('TextInput'));
-
- /**
- * Here we map some elements to their atom equivalents. This is going to be
- * quite tricky to pull off effectively (and some users' methods may vary)
- * but is worth trying. The key is the atom version, the value is RSS2.
- * @var array
- */
- protected $compatMap = array(
- 'title' => array('title'),
- 'link' => array('link'),
- 'subtitle' => array('description'));
-
- /**
- * We will be working with multiple namespaces and it is useful to
- * keep them together
- * @var array
- */
- protected $namespaces = array(
- 'rdf' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#');
-
- /**
- * Our constructor does nothing more than its parent.
- *
- * @todo RelaxNG validation
- * @param DOMDocument $xml A DOM object representing the feed
- * @param bool (optional) $string Whether or not to validate this feed
- */
- function __construct(DOMDocument $model, $strict = false)
- {
- $this->model = $model;
-
- $this->xpath = new DOMXPath($model);
- foreach ($this->namespaces as $key => $value) {
- $this->xpath->registerNamespace($key, $value);
- }
- $this->numberEntries = $this->count('item');
- }
-
- /**
- * Included for compatibility -- will not work with RSS 0.9
- *
- * This is not something that will work with RSS0.9 as it does not have
- * clear restrictions on the global uniqueness of IDs.
- *
- * @param string $id any valid ID.
- * @return false
- */
- function getEntryById($id)
- {
- return false;
- }
-
- /**
- * Get details of the image associated with the feed.
- *
- * @return array|false an array simply containing the child elements
- */
- protected function getImage()
- {
- $images = $this->model->getElementsByTagName('image');
- if ($images->length > 0) {
- $image = $images->item(0);
- $details = array();
- if ($image->hasChildNodes()) {
- $details = array(
- 'title' => $image->getElementsByTagName('title')->item(0)->value,
- 'link' => $image->getElementsByTagName('link')->item(0)->value,
- 'url' => $image->getElementsByTagName('url')->item(0)->value);
- } else {
- $details = array('title' => false,
- 'link' => false,
- 'url' => $image->attributes->getNamedItem('resource')->nodeValue);
- }
- $details = array_merge($details,
- array('description' => false, 'height' => false, 'width' => false));
- if (! empty($details)) {
- return $details;
- }
- }
- return false;
- }
-
- /**
- * The textinput element is little used, but in the interests of
- * completeness we will support it.
- *
- * @return array|false
- */
- protected function getTextInput()
- {
- $inputs = $this->model->getElementsByTagName('textinput');
- if ($inputs->length > 0) {
- $input = $inputs->item(0);
- $results = array();
- $results['title'] = isset(
- $input->getElementsByTagName('title')->item(0)->value) ?
- $input->getElementsByTagName('title')->item(0)->value : null;
- $results['description'] = isset(
- $input->getElementsByTagName('description')->item(0)->value) ?
- $input->getElementsByTagName('description')->item(0)->value : null;
- $results['name'] = isset(
- $input->getElementsByTagName('name')->item(0)->value) ?
- $input->getElementsByTagName('name')->item(0)->value : null;
- $results['link'] = isset(
- $input->getElementsByTagName('link')->item(0)->value) ?
- $input->getElementsByTagName('link')->item(0)->value : null;
- if (empty($results['link']) &&
- $input->attributes->getNamedItem('resource')) {
- $results['link'] = $input->attributes->getNamedItem('resource')->nodeValue;
- }
- if (! empty($results)) {
- return $results;
- }
- }
- return false;
- }
-
- /**
- * Get details of a link from the feed.
- *
- * In RSS1 a link is a text element but in order to ensure that we resolve
- * URLs properly we have a special function for them.
- *
- * @return string
- */
- function getLink($offset = 0, $attribute = 'href', $params = false)
- {
- $links = $this->model->getElementsByTagName('link');
- if ($links->length <= $offset) {
- return false;
- }
- $link = $links->item($offset);
- return $this->addBase($link->nodeValue, $link);
- }
-}
-
-?>
\ No newline at end of file
diff --git a/plugins/OStatus/extlib/XML/Feed/Parser/RSS09Element.php b/plugins/OStatus/extlib/XML/Feed/Parser/RSS09Element.php
deleted file mode 100755
index d41f36e8d..000000000
--- a/plugins/OStatus/extlib/XML/Feed/Parser/RSS09Element.php
+++ /dev/null
@@ -1,62 +0,0 @@
-
- * @copyright 2005 James Stewart
- * @license http://www.gnu.org/copyleft/lesser.html GNU LGPL 2.1
- * @version CVS: $Id: RSS09Element.php,v 1.4 2006/06/30 17:41:56 jystewart Exp $
- * @link http://pear.php.net/package/XML_Feed_Parser/
- */
-
-/*
- * This class provides support for RSS 0.9 entries. It will usually be called by
- * XML_Feed_Parser_RSS09 with which it shares many methods.
- *
- * @author James Stewart
- * @version Release: 1.0.3
- * @package XML_Feed_Parser
- */
-class XML_Feed_Parser_RSS09Element extends XML_Feed_Parser_RSS09
-{
- /**
- * This will be a reference to the parent object for when we want
- * to use a 'fallback' rule
- * @var XML_Feed_Parser_RSS09
- */
- protected $parent;
-
- /**
- * Our specific element map
- * @var array
- */
- protected $map = array(
- 'title' => array('Text'),
- 'link' => array('Link'));
-
- /**
- * Store useful information for later.
- *
- * @param DOMElement $element - this item as a DOM element
- * @param XML_Feed_Parser_RSS1 $parent - the feed of which this is a member
- */
- function __construct(DOMElement $element, $parent, $xmlBase = '')
- {
- $this->model = $element;
- $this->parent = $parent;
- }
-}
-
-?>
\ No newline at end of file
diff --git a/plugins/OStatus/extlib/XML/Feed/Parser/RSS1.php b/plugins/OStatus/extlib/XML/Feed/Parser/RSS1.php
deleted file mode 100755
index 60c9938ba..000000000
--- a/plugins/OStatus/extlib/XML/Feed/Parser/RSS1.php
+++ /dev/null
@@ -1,277 +0,0 @@
-
- * @copyright 2005 James Stewart
- * @license http://www.gnu.org/copyleft/lesser.html GNU LGPL 2.1
- * @version CVS: $Id: RSS1.php,v 1.10 2006/07/27 13:52:05 jystewart Exp $
- * @link http://pear.php.net/package/XML_Feed_Parser/
- */
-
-/**
- * This class handles RSS1.0 feeds.
- *
- * @author James Stewart
- * @version Release: 1.0.3
- * @package XML_Feed_Parser
- * @todo Find a Relax NG URI we can use
- */
-class XML_Feed_Parser_RSS1 extends XML_Feed_Parser_Type
-{
- /**
- * The URI of the RelaxNG schema used to (optionally) validate the feed
- * @var string
- */
- private $relax = 'rss10.rnc';
-
- /**
- * We're likely to use XPath, so let's keep it global
- * @var DOMXPath
- */
- protected $xpath;
-
- /**
- * The feed type we are parsing
- * @var string
- */
- public $version = 'RSS 1.0';
-
- /**
- * The class used to represent individual items
- * @var string
- */
- protected $itemClass = 'XML_Feed_Parser_RSS1Element';
-
- /**
- * The element containing entries
- * @var string
- */
- protected $itemElement = 'item';
-
- /**
- * Here we map those elements we're not going to handle individually
- * to the constructs they are. The optional second parameter in the array
- * tells the parser whether to 'fall back' (not apt. at the feed level) or
- * fail if the element is missing. If the parameter is not set, the function
- * will simply return false and leave it to the client to decide what to do.
- * @var array
- */
- protected $map = array(
- 'title' => array('Text'),
- 'link' => array('Text'),
- 'description' => array('Text'),
- 'image' => array('Image'),
- 'textinput' => array('TextInput'),
- 'updatePeriod' => array('Text'),
- 'updateFrequency' => array('Text'),
- 'updateBase' => array('Date'),
- 'rights' => array('Text'), # dc:rights
- 'description' => array('Text'), # dc:description
- 'creator' => array('Text'), # dc:creator
- 'publisher' => array('Text'), # dc:publisher
- 'contributor' => array('Text'), # dc:contributor
- 'date' => array('Date') # dc:contributor
- );
-
- /**
- * Here we map some elements to their atom equivalents. This is going to be
- * quite tricky to pull off effectively (and some users' methods may vary)
- * but is worth trying. The key is the atom version, the value is RSS2.
- * @var array
- */
- protected $compatMap = array(
- 'title' => array('title'),
- 'link' => array('link'),
- 'subtitle' => array('description'),
- 'author' => array('creator'),
- 'updated' => array('date'));
-
- /**
- * We will be working with multiple namespaces and it is useful to
- * keep them together
- * @var array
- */
- protected $namespaces = array(
- 'rdf' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
- 'rss' => 'http://purl.org/rss/1.0/',
- 'dc' => 'http://purl.org/rss/1.0/modules/dc/',
- 'content' => 'http://purl.org/rss/1.0/modules/content/',
- 'sy' => 'http://web.resource.org/rss/1.0/modules/syndication/');
-
- /**
- * Our constructor does nothing more than its parent.
- *
- * @param DOMDocument $xml A DOM object representing the feed
- * @param bool (optional) $string Whether or not to validate this feed
- */
- function __construct(DOMDocument $model, $strict = false)
- {
- $this->model = $model;
- if ($strict) {
- $validate = $this->model->relaxNGValidate(self::getSchemaDir .
- DIRECTORY_SEPARATOR . $this->relax);
- if (! $validate) {
- throw new XML_Feed_Parser_Exception('Failed required validation');
- }
- }
-
- $this->xpath = new DOMXPath($model);
- foreach ($this->namespaces as $key => $value) {
- $this->xpath->registerNamespace($key, $value);
- }
- $this->numberEntries = $this->count('item');
- }
-
- /**
- * Allows retrieval of an entry by ID where the rdf:about attribute is used
- *
- * This is not really something that will work with RSS1 as it does not have
- * clear restrictions on the global uniqueness of IDs. We will employ the
- * _very_ hit and miss method of selecting entries based on the rdf:about
- * attribute. If DOMXPath::evaluate is available, we also use that to store
- * a reference to the entry in the array used by getEntryByOffset so that
- * method does not have to seek out the entry if it's requested that way.
- *
- * @param string $id any valid ID.
- * @return XML_Feed_Parser_RSS1Element
- */
- function getEntryById($id)
- {
- if (isset($this->idMappings[$id])) {
- return $this->entries[$this->idMappings[$id]];
- }
-
- $entries = $this->xpath->query("//rss:item[@rdf:about='$id']");
- if ($entries->length > 0) {
- $classname = $this->itemClass;
- $entry = new $classname($entries->item(0), $this);
- if (in_array('evaluate', get_class_methods($this->xpath))) {
- $offset = $this->xpath->evaluate("count(preceding-sibling::rss:item)", $entries->item(0));
- $this->entries[$offset] = $entry;
- }
- $this->idMappings[$id] = $entry;
- return $entry;
- }
- return false;
- }
-
- /**
- * Get details of the image associated with the feed.
- *
- * @return array|false an array simply containing the child elements
- */
- protected function getImage()
- {
- $images = $this->model->getElementsByTagName('image');
- if ($images->length > 0) {
- $image = $images->item(0);
- $details = array();
- if ($image->hasChildNodes()) {
- $details = array(
- 'title' => $image->getElementsByTagName('title')->item(0)->value,
- 'link' => $image->getElementsByTagName('link')->item(0)->value,
- 'url' => $image->getElementsByTagName('url')->item(0)->value);
- } else {
- $details = array('title' => false,
- 'link' => false,
- 'url' => $image->attributes->getNamedItem('resource')->nodeValue);
- }
- $details = array_merge($details, array('description' => false, 'height' => false, 'width' => false));
- if (! empty($details)) {
- return $details;
- }
- }
- return false;
- }
-
- /**
- * The textinput element is little used, but in the interests of
- * completeness we will support it.
- *
- * @return array|false
- */
- protected function getTextInput()
- {
- $inputs = $this->model->getElementsByTagName('textinput');
- if ($inputs->length > 0) {
- $input = $inputs->item(0);
- $results = array();
- $results['title'] = isset(
- $input->getElementsByTagName('title')->item(0)->value) ?
- $input->getElementsByTagName('title')->item(0)->value : null;
- $results['description'] = isset(
- $input->getElementsByTagName('description')->item(0)->value) ?
- $input->getElementsByTagName('description')->item(0)->value : null;
- $results['name'] = isset(
- $input->getElementsByTagName('name')->item(0)->value) ?
- $input->getElementsByTagName('name')->item(0)->value : null;
- $results['link'] = isset(
- $input->getElementsByTagName('link')->item(0)->value) ?
- $input->getElementsByTagName('link')->item(0)->value : null;
- if (empty($results['link']) and
- $input->attributes->getNamedItem('resource')) {
- $results['link'] =
- $input->attributes->getNamedItem('resource')->nodeValue;
- }
- if (! empty($results)) {
- return $results;
- }
- }
- return false;
- }
-
- /**
- * Employs various techniques to identify the author
- *
- * Dublin Core provides the dc:creator, dc:contributor, and dc:publisher
- * elements for defining authorship in RSS1. We will try each of those in
- * turn in order to simulate the atom author element and will return it
- * as text.
- *
- * @return array|false
- */
- function getAuthor()
- {
- $options = array('creator', 'contributor', 'publisher');
- foreach ($options as $element) {
- $test = $this->model->getElementsByTagName($element);
- if ($test->length > 0) {
- return $test->item(0)->value;
- }
- }
- return false;
- }
-
- /**
- * Retrieve a link
- *
- * In RSS1 a link is a text element but in order to ensure that we resolve
- * URLs properly we have a special function for them.
- *
- * @return string
- */
- function getLink($offset = 0, $attribute = 'href', $params = false)
- {
- $links = $this->model->getElementsByTagName('link');
- if ($links->length <= $offset) {
- return false;
- }
- $link = $links->item($offset);
- return $this->addBase($link->nodeValue, $link);
- }
-}
-
-?>
\ No newline at end of file
diff --git a/plugins/OStatus/extlib/XML/Feed/Parser/RSS11.php b/plugins/OStatus/extlib/XML/Feed/Parser/RSS11.php
deleted file mode 100755
index 3cd1ef15d..000000000
--- a/plugins/OStatus/extlib/XML/Feed/Parser/RSS11.php
+++ /dev/null
@@ -1,276 +0,0 @@
-
- * @copyright 2005 James Stewart
- * @license http://www.gnu.org/copyleft/lesser.html GNU LGPL 2.1
- * @version CVS: $Id: RSS11.php,v 1.6 2006/07/27 13:52:05 jystewart Exp $
- * @link http://pear.php.net/package/XML_Feed_Parser/
- */
-
-/**
- * This class handles RSS1.1 feeds. RSS1.1 is documented at:
- * http://inamidst.com/rss1.1/
- *
- * @author James Stewart
- * @version Release: 1.0.3
- * @package XML_Feed_Parser
- * @todo Support for RDF:List
- * @todo Ensure xml:lang is accessible to users
- */
-class XML_Feed_Parser_RSS11 extends XML_Feed_Parser_Type
-{
- /**
- * The URI of the RelaxNG schema used to (optionally) validate the feed
- * @var string
- */
- private $relax = 'rss11.rnc';
-
- /**
- * We're likely to use XPath, so let's keep it global
- * @var DOMXPath
- */
- protected $xpath;
-
- /**
- * The feed type we are parsing
- * @var string
- */
- public $version = 'RSS 1.0';
-
- /**
- * The class used to represent individual items
- * @var string
- */
- protected $itemClass = 'XML_Feed_Parser_RSS1Element';
-
- /**
- * The element containing entries
- * @var string
- */
- protected $itemElement = 'item';
-
- /**
- * Here we map those elements we're not going to handle individually
- * to the constructs they are. The optional second parameter in the array
- * tells the parser whether to 'fall back' (not apt. at the feed level) or
- * fail if the element is missing. If the parameter is not set, the function
- * will simply return false and leave it to the client to decide what to do.
- * @var array
- */
- protected $map = array(
- 'title' => array('Text'),
- 'link' => array('Text'),
- 'description' => array('Text'),
- 'image' => array('Image'),
- 'updatePeriod' => array('Text'),
- 'updateFrequency' => array('Text'),
- 'updateBase' => array('Date'),
- 'rights' => array('Text'), # dc:rights
- 'description' => array('Text'), # dc:description
- 'creator' => array('Text'), # dc:creator
- 'publisher' => array('Text'), # dc:publisher
- 'contributor' => array('Text'), # dc:contributor
- 'date' => array('Date') # dc:contributor
- );
-
- /**
- * Here we map some elements to their atom equivalents. This is going to be
- * quite tricky to pull off effectively (and some users' methods may vary)
- * but is worth trying. The key is the atom version, the value is RSS2.
- * @var array
- */
- protected $compatMap = array(
- 'title' => array('title'),
- 'link' => array('link'),
- 'subtitle' => array('description'),
- 'author' => array('creator'),
- 'updated' => array('date'));
-
- /**
- * We will be working with multiple namespaces and it is useful to
- * keep them together. We will retain support for some common RSS1.0 modules
- * @var array
- */
- protected $namespaces = array(
- 'rdf' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
- 'rss' => 'http://purl.org/net/rss1.1#',
- 'dc' => 'http://purl.org/rss/1.0/modules/dc/',
- 'content' => 'http://purl.org/rss/1.0/modules/content/',
- 'sy' => 'http://web.resource.org/rss/1.0/modules/syndication/');
-
- /**
- * Our constructor does nothing more than its parent.
- *
- * @param DOMDocument $xml A DOM object representing the feed
- * @param bool (optional) $string Whether or not to validate this feed
- */
- function __construct(DOMDocument $model, $strict = false)
- {
- $this->model = $model;
-
- if ($strict) {
- $validate = $this->model->relaxNGValidate(self::getSchemaDir .
- DIRECTORY_SEPARATOR . $this->relax);
- if (! $validate) {
- throw new XML_Feed_Parser_Exception('Failed required validation');
- }
- }
-
- $this->xpath = new DOMXPath($model);
- foreach ($this->namespaces as $key => $value) {
- $this->xpath->registerNamespace($key, $value);
- }
- $this->numberEntries = $this->count('item');
- }
-
- /**
- * Attempts to identify an element by ID given by the rdf:about attribute
- *
- * This is not really something that will work with RSS1.1 as it does not have
- * clear restrictions on the global uniqueness of IDs. We will employ the
- * _very_ hit and miss method of selecting entries based on the rdf:about
- * attribute. Please note that this is even more hit and miss with RSS1.1 than
- * with RSS1.0 since RSS1.1 does not require the rdf:about attribute for items.
- *
- * @param string $id any valid ID.
- * @return XML_Feed_Parser_RSS1Element
- */
- function getEntryById($id)
- {
- if (isset($this->idMappings[$id])) {
- return $this->entries[$this->idMappings[$id]];
- }
-
- $entries = $this->xpath->query("//rss:item[@rdf:about='$id']");
- if ($entries->length > 0) {
- $classname = $this->itemClass;
- $entry = new $classname($entries->item(0), $this);
- return $entry;
- }
- return false;
- }
-
- /**
- * Get details of the image associated with the feed.
- *
- * @return array|false an array simply containing the child elements
- */
- protected function getImage()
- {
- $images = $this->model->getElementsByTagName('image');
- if ($images->length > 0) {
- $image = $images->item(0);
- $details = array();
- if ($image->hasChildNodes()) {
- $details = array(
- 'title' => $image->getElementsByTagName('title')->item(0)->value,
- 'url' => $image->getElementsByTagName('url')->item(0)->value);
- if ($image->getElementsByTagName('link')->length > 0) {
- $details['link'] =
- $image->getElementsByTagName('link')->item(0)->value;
- }
- } else {
- $details = array('title' => false,
- 'link' => false,
- 'url' => $image->attributes->getNamedItem('resource')->nodeValue);
- }
- $details = array_merge($details,
- array('description' => false, 'height' => false, 'width' => false));
- if (! empty($details)) {
- return $details;
- }
- }
- return false;
- }
-
- /**
- * The textinput element is little used, but in the interests of
- * completeness we will support it.
- *
- * @return array|false
- */
- protected function getTextInput()
- {
- $inputs = $this->model->getElementsByTagName('textinput');
- if ($inputs->length > 0) {
- $input = $inputs->item(0);
- $results = array();
- $results['title'] = isset(
- $input->getElementsByTagName('title')->item(0)->value) ?
- $input->getElementsByTagName('title')->item(0)->value : null;
- $results['description'] = isset(
- $input->getElementsByTagName('description')->item(0)->value) ?
- $input->getElementsByTagName('description')->item(0)->value : null;
- $results['name'] = isset(
- $input->getElementsByTagName('name')->item(0)->value) ?
- $input->getElementsByTagName('name')->item(0)->value : null;
- $results['link'] = isset(
- $input->getElementsByTagName('link')->item(0)->value) ?
- $input->getElementsByTagName('link')->item(0)->value : null;
- if (empty($results['link']) and
- $input->attributes->getNamedItem('resource')) {
- $results['link'] = $input->attributes->getNamedItem('resource')->nodeValue;
- }
- if (! empty($results)) {
- return $results;
- }
- }
- return false;
- }
-
- /**
- * Attempts to discern authorship
- *
- * Dublin Core provides the dc:creator, dc:contributor, and dc:publisher
- * elements for defining authorship in RSS1. We will try each of those in
- * turn in order to simulate the atom author element and will return it
- * as text.
- *
- * @return array|false
- */
- function getAuthor()
- {
- $options = array('creator', 'contributor', 'publisher');
- foreach ($options as $element) {
- $test = $this->model->getElementsByTagName($element);
- if ($test->length > 0) {
- return $test->item(0)->value;
- }
- }
- return false;
- }
-
- /**
- * Retrieve a link
- *
- * In RSS1 a link is a text element but in order to ensure that we resolve
- * URLs properly we have a special function for them.
- *
- * @return string
- */
- function getLink($offset = 0, $attribute = 'href', $params = false)
- {
- $links = $this->model->getElementsByTagName('link');
- if ($links->length <= $offset) {
- return false;
- }
- $link = $links->item($offset);
- return $this->addBase($link->nodeValue, $link);
- }
-}
-
-?>
\ No newline at end of file
diff --git a/plugins/OStatus/extlib/XML/Feed/Parser/RSS11Element.php b/plugins/OStatus/extlib/XML/Feed/Parser/RSS11Element.php
deleted file mode 100755
index 75918beda..000000000
--- a/plugins/OStatus/extlib/XML/Feed/Parser/RSS11Element.php
+++ /dev/null
@@ -1,151 +0,0 @@
-
- * @copyright 2005 James Stewart
- * @license http://www.gnu.org/copyleft/lesser.html GNU LGPL 2.1
- * @version CVS: $Id: RSS11Element.php,v 1.4 2006/06/30 17:41:56 jystewart Exp $
- * @link http://pear.php.net/package/XML_Feed_Parser/
- */
-
-/*
- * This class provides support for RSS 1.1 entries. It will usually be called by
- * XML_Feed_Parser_RSS11 with which it shares many methods.
- *
- * @author James Stewart
- * @version Release: 1.0.3
- * @package XML_Feed_Parser
- */
-class XML_Feed_Parser_RSS11Element extends XML_Feed_Parser_RSS11
-{
- /**
- * This will be a reference to the parent object for when we want
- * to use a 'fallback' rule
- * @var XML_Feed_Parser_RSS1
- */
- protected $parent;
-
- /**
- * Our specific element map
- * @var array
- */
- protected $map = array(
- 'id' => array('Id'),
- 'title' => array('Text'),
- 'link' => array('Link'),
- 'description' => array('Text'), # or dc:description
- 'category' => array('Category'),
- 'rights' => array('Text'), # dc:rights
- 'creator' => array('Text'), # dc:creator
- 'publisher' => array('Text'), # dc:publisher
- 'contributor' => array('Text'), # dc:contributor
- 'date' => array('Date'), # dc:date
- 'content' => array('Content')
- );
-
- /**
- * Here we map some elements to their atom equivalents. This is going to be
- * quite tricky to pull off effectively (and some users' methods may vary)
- * but is worth trying. The key is the atom version, the value is RSS1.
- * @var array
- */
- protected $compatMap = array(
- 'content' => array('content'),
- 'updated' => array('lastBuildDate'),
- 'published' => array('pubdate'),
- 'subtitle' => array('description'),
- 'updated' => array('date'),
- 'author' => array('creator'),
- 'contributor' => array('contributor')
- );
-
- /**
- * Store useful information for later.
- *
- * @param DOMElement $element - this item as a DOM element
- * @param XML_Feed_Parser_RSS1 $parent - the feed of which this is a member
- */
- function __construct(DOMElement $element, $parent, $xmlBase = '')
- {
- $this->model = $element;
- $this->parent = $parent;
- }
-
- /**
- * If an rdf:about attribute is specified, return that as an ID
- *
- * There is no established way of showing an ID for an RSS1 entry. We will
- * simulate it using the rdf:about attribute of the entry element. This cannot
- * be relied upon for unique IDs but may prove useful.
- *
- * @return string|false
- */
- function getId()
- {
- if ($this->model->attributes->getNamedItem('about')) {
- return $this->model->attributes->getNamedItem('about')->nodeValue;
- }
- return false;
- }
-
- /**
- * Return the entry's content
- *
- * The official way to include full content in an RSS1 entry is to use
- * the content module's element 'encoded'. Often, however, the 'description'
- * element is used instead. We will offer that as a fallback.
- *
- * @return string|false
- */
- function getContent()
- {
- $options = array('encoded', 'description');
- foreach ($options as $element) {
- $test = $this->model->getElementsByTagName($element);
- if ($test->length == 0) {
- continue;
- }
- if ($test->item(0)->hasChildNodes()) {
- $value = '';
- foreach ($test->item(0)->childNodes as $child) {
- if ($child instanceof DOMText) {
- $value .= $child->nodeValue;
- } else {
- $simple = simplexml_import_dom($child);
- $value .= $simple->asXML();
- }
- }
- return $value;
- } else if ($test->length > 0) {
- return $test->item(0)->nodeValue;
- }
- }
- return false;
- }
-
- /**
- * How RSS1.1 should support for enclosures is not clear. For now we will return
- * false.
- *
- * @return false
- */
- function getEnclosure()
- {
- return false;
- }
-}
-
-?>
\ No newline at end of file
diff --git a/plugins/OStatus/extlib/XML/Feed/Parser/RSS1Element.php b/plugins/OStatus/extlib/XML/Feed/Parser/RSS1Element.php
deleted file mode 100755
index 8e36d5a9b..000000000
--- a/plugins/OStatus/extlib/XML/Feed/Parser/RSS1Element.php
+++ /dev/null
@@ -1,116 +0,0 @@
-
- * @copyright 2005 James Stewart
- * @license http://www.gnu.org/copyleft/lesser.html GNU LGPL 2.1
- * @version CVS: $Id: RSS1Element.php,v 1.6 2006/06/30 17:41:56 jystewart Exp $
- * @link http://pear.php.net/package/XML_Feed_Parser/
- */
-
-/*
- * This class provides support for RSS 1.0 entries. It will usually be called by
- * XML_Feed_Parser_RSS1 with which it shares many methods.
- *
- * @author James Stewart
- * @version Release: 1.0.3
- * @package XML_Feed_Parser
- */
-class XML_Feed_Parser_RSS1Element extends XML_Feed_Parser_RSS1
-{
- /**
- * This will be a reference to the parent object for when we want
- * to use a 'fallback' rule
- * @var XML_Feed_Parser_RSS1
- */
- protected $parent;
-
- /**
- * Our specific element map
- * @var array
- */
- protected $map = array(
- 'id' => array('Id'),
- 'title' => array('Text'),
- 'link' => array('Link'),
- 'description' => array('Text'), # or dc:description
- 'category' => array('Category'),
- 'rights' => array('Text'), # dc:rights
- 'creator' => array('Text'), # dc:creator
- 'publisher' => array('Text'), # dc:publisher
- 'contributor' => array('Text'), # dc:contributor
- 'date' => array('Date'), # dc:date
- 'content' => array('Content')
- );
-
- /**
- * Here we map some elements to their atom equivalents. This is going to be
- * quite tricky to pull off effectively (and some users' methods may vary)
- * but is worth trying. The key is the atom version, the value is RSS1.
- * @var array
- */
- protected $compatMap = array(
- 'content' => array('content'),
- 'updated' => array('lastBuildDate'),
- 'published' => array('pubdate'),
- 'subtitle' => array('description'),
- 'updated' => array('date'),
- 'author' => array('creator'),
- 'contributor' => array('contributor')
- );
-
- /**
- * Store useful information for later.
- *
- * @param DOMElement $element - this item as a DOM element
- * @param XML_Feed_Parser_RSS1 $parent - the feed of which this is a member
- */
- function __construct(DOMElement $element, $parent, $xmlBase = '')
- {
- $this->model = $element;
- $this->parent = $parent;
- }
-
- /**
- * If an rdf:about attribute is specified, return it as an ID
- *
- * There is no established way of showing an ID for an RSS1 entry. We will
- * simulate it using the rdf:about attribute of the entry element. This cannot
- * be relied upon for unique IDs but may prove useful.
- *
- * @return string|false
- */
- function getId()
- {
- if ($this->model->attributes->getNamedItem('about')) {
- return $this->model->attributes->getNamedItem('about')->nodeValue;
- }
- return false;
- }
-
- /**
- * How RSS1 should support for enclosures is not clear. For now we will return
- * false.
- *
- * @return false
- */
- function getEnclosure()
- {
- return false;
- }
-}
-
-?>
\ No newline at end of file
diff --git a/plugins/OStatus/extlib/XML/Feed/Parser/RSS2.php b/plugins/OStatus/extlib/XML/Feed/Parser/RSS2.php
deleted file mode 100644
index 0936bd2f5..000000000
--- a/plugins/OStatus/extlib/XML/Feed/Parser/RSS2.php
+++ /dev/null
@@ -1,335 +0,0 @@
-
- * @copyright 2005 James Stewart
- * @license http://www.gnu.org/copyleft/lesser.html GNU LGPL 2.1
- * @version CVS: $Id: RSS2.php,v 1.12 2008/03/08 18:16:45 jystewart Exp $
- * @link http://pear.php.net/package/XML_Feed_Parser/
- */
-
-/**
- * This class handles RSS2 feeds.
- *
- * @author James Stewart
- * @version Release: 1.0.3
- * @package XML_Feed_Parser
- */
-class XML_Feed_Parser_RSS2 extends XML_Feed_Parser_Type
-{
- /**
- * The URI of the RelaxNG schema used to (optionally) validate the feed
- * @var string
- */
- private $relax = 'rss20.rnc';
-
- /**
- * We're likely to use XPath, so let's keep it global
- * @var DOMXPath
- */
- protected $xpath;
-
- /**
- * The feed type we are parsing
- * @var string
- */
- public $version = 'RSS 2.0';
-
- /**
- * The class used to represent individual items
- * @var string
- */
- protected $itemClass = 'XML_Feed_Parser_RSS2Element';
-
- /**
- * The element containing entries
- * @var string
- */
- protected $itemElement = 'item';
-
- /**
- * Here we map those elements we're not going to handle individually
- * to the constructs they are. The optional second parameter in the array
- * tells the parser whether to 'fall back' (not apt. at the feed level) or
- * fail if the element is missing. If the parameter is not set, the function
- * will simply return false and leave it to the client to decide what to do.
- * @var array
- */
- protected $map = array(
- 'ttl' => array('Text'),
- 'pubDate' => array('Date'),
- 'lastBuildDate' => array('Date'),
- 'title' => array('Text'),
- 'link' => array('Link'),
- 'description' => array('Text'),
- 'language' => array('Text'),
- 'copyright' => array('Text'),
- 'managingEditor' => array('Text'),
- 'webMaster' => array('Text'),
- 'category' => array('Text'),
- 'generator' => array('Text'),
- 'docs' => array('Text'),
- 'ttl' => array('Text'),
- 'image' => array('Image'),
- 'skipDays' => array('skipDays'),
- 'skipHours' => array('skipHours'));
-
- /**
- * Here we map some elements to their atom equivalents. This is going to be
- * quite tricky to pull off effectively (and some users' methods may vary)
- * but is worth trying. The key is the atom version, the value is RSS2.
- * @var array
- */
- protected $compatMap = array(
- 'title' => array('title'),
- 'rights' => array('copyright'),
- 'updated' => array('lastBuildDate'),
- 'subtitle' => array('description'),
- 'date' => array('pubDate'),
- 'author' => array('managingEditor'));
-
- protected $namespaces = array(
- 'dc' => 'http://purl.org/rss/1.0/modules/dc/',
- 'content' => 'http://purl.org/rss/1.0/modules/content/');
-
- /**
- * Our constructor does nothing more than its parent.
- *
- * @param DOMDocument $xml A DOM object representing the feed
- * @param bool (optional) $string Whether or not to validate this feed
- */
- function __construct(DOMDocument $model, $strict = false)
- {
- $this->model = $model;
-
- if ($strict) {
- if (! $this->model->relaxNGValidate($this->relax)) {
- throw new XML_Feed_Parser_Exception('Failed required validation');
- }
- }
-
- $this->xpath = new DOMXPath($this->model);
- foreach ($this->namespaces as $key => $value) {
- $this->xpath->registerNamespace($key, $value);
- }
- $this->numberEntries = $this->count('item');
- }
-
- /**
- * Retrieves an entry by ID, if the ID is specified with the guid element
- *
- * This is not really something that will work with RSS2 as it does not have
- * clear restrictions on the global uniqueness of IDs. But we can emulate
- * it by allowing access based on the 'guid' element. If DOMXPath::evaluate
- * is available, we also use that to store a reference to the entry in the array
- * used by getEntryByOffset so that method does not have to seek out the entry
- * if it's requested that way.
- *
- * @param string $id any valid ID.
- * @return XML_Feed_Parser_RSS2Element
- */
- function getEntryById($id)
- {
- if (isset($this->idMappings[$id])) {
- return $this->entries[$this->idMappings[$id]];
- }
-
- $entries = $this->xpath->query("//item[guid='$id']");
- if ($entries->length > 0) {
- $entry = new $this->itemElement($entries->item(0), $this);
- if (in_array('evaluate', get_class_methods($this->xpath))) {
- $offset = $this->xpath->evaluate("count(preceding-sibling::item)", $entries->item(0));
- $this->entries[$offset] = $entry;
- }
- $this->idMappings[$id] = $entry;
- return $entry;
- }
- }
-
- /**
- * Get a category from the element
- *
- * The category element is a simple text construct which can occur any number
- * of times. We allow access by offset or access to an array of results.
- *
- * @param string $call for compatibility with our overloading
- * @param array $arguments - arg 0 is the offset, arg 1 is whether to return as array
- * @return string|array|false
- */
- function getCategory($call, $arguments = array())
- {
- $categories = $this->model->getElementsByTagName('category');
- $offset = empty($arguments[0]) ? 0 : $arguments[0];
- $array = empty($arguments[1]) ? false : true;
- if ($categories->length <= $offset) {
- return false;
- }
- if ($array) {
- $list = array();
- foreach ($categories as $category) {
- array_push($list, $category->nodeValue);
- }
- return $list;
- }
- return $categories->item($offset)->nodeValue;
- }
-
- /**
- * Get details of the image associated with the feed.
- *
- * @return array|false an array simply containing the child elements
- */
- protected function getImage()
- {
- $images = $this->xpath->query("//image");
- if ($images->length > 0) {
- $image = $images->item(0);
- $desc = $image->getElementsByTagName('description');
- $description = $desc->length ? $desc->item(0)->nodeValue : false;
- $heigh = $image->getElementsByTagName('height');
- $height = $heigh->length ? $heigh->item(0)->nodeValue : false;
- $widt = $image->getElementsByTagName('width');
- $width = $widt->length ? $widt->item(0)->nodeValue : false;
- return array(
- 'title' => $image->getElementsByTagName('title')->item(0)->nodeValue,
- 'link' => $image->getElementsByTagName('link')->item(0)->nodeValue,
- 'url' => $image->getElementsByTagName('url')->item(0)->nodeValue,
- 'description' => $description,
- 'height' => $height,
- 'width' => $width);
- }
- return false;
- }
-
- /**
- * The textinput element is little used, but in the interests of
- * completeness...
- *
- * @return array|false
- */
- function getTextInput()
- {
- $inputs = $this->model->getElementsByTagName('input');
- if ($inputs->length > 0) {
- $input = $inputs->item(0);
- return array(
- 'title' => $input->getElementsByTagName('title')->item(0)->value,
- 'description' =>
- $input->getElementsByTagName('description')->item(0)->value,
- 'name' => $input->getElementsByTagName('name')->item(0)->value,
- 'link' => $input->getElementsByTagName('link')->item(0)->value);
- }
- return false;
- }
-
- /**
- * Utility function for getSkipDays and getSkipHours
- *
- * This is a general function used by both getSkipDays and getSkipHours. It simply
- * returns an array of the values of the children of the appropriate tag.
- *
- * @param string $tagName The tag name (getSkipDays or getSkipHours)
- * @return array|false
- */
- protected function getSkips($tagName)
- {
- $hours = $this->model->getElementsByTagName($tagName);
- if ($hours->length == 0) {
- return false;
- }
- $skipHours = array();
- foreach($hours->item(0)->childNodes as $hour) {
- if ($hour instanceof DOMElement) {
- array_push($skipHours, $hour->nodeValue);
- }
- }
- return $skipHours;
- }
-
- /**
- * Retrieve skipHours data
- *
- * The skiphours element provides a list of hours on which this feed should
- * not be checked. We return an array of those hours (integers, 24 hour clock)
- *
- * @return array
- */
- function getSkipHours()
- {
- return $this->getSkips('skipHours');
- }
-
- /**
- * Retrieve skipDays data
- *
- * The skipdays element provides a list of days on which this feed should
- * not be checked. We return an array of those days.
- *
- * @return array
- */
- function getSkipDays()
- {
- return $this->getSkips('skipDays');
- }
-
- /**
- * Return content of the little-used 'cloud' element
- *
- * The cloud element is rarely used. It is designed to provide some details
- * of a location to update the feed.
- *
- * @return array an array of the attributes of the element
- */
- function getCloud()
- {
- $cloud = $this->model->getElementsByTagName('cloud');
- if ($cloud->length == 0) {
- return false;
- }
- $cloudData = array();
- foreach ($cloud->item(0)->attributes as $attribute) {
- $cloudData[$attribute->name] = $attribute->value;
- }
- return $cloudData;
- }
-
- /**
- * Get link URL
- *
- * In RSS2 a link is a text element but in order to ensure that we resolve
- * URLs properly we have a special function for them. We maintain the
- * parameter used by the atom getLink method, though we only use the offset
- * parameter.
- *
- * @param int $offset The position of the link within the feed. Starts from 0
- * @param string $attribute The attribute of the link element required
- * @param array $params An array of other parameters. Not used.
- * @return string
- */
- function getLink($offset, $attribute = 'href', $params = array())
- {
- $xPath = new DOMXPath($this->model);
- $links = $xPath->query('//link');
-
- if ($links->length <= $offset) {
- return false;
- }
- $link = $links->item($offset);
- return $this->addBase($link->nodeValue, $link);
- }
-}
-
-?>
\ No newline at end of file
diff --git a/plugins/OStatus/extlib/XML/Feed/Parser/RSS2Element.php b/plugins/OStatus/extlib/XML/Feed/Parser/RSS2Element.php
deleted file mode 100755
index 6edf910dc..000000000
--- a/plugins/OStatus/extlib/XML/Feed/Parser/RSS2Element.php
+++ /dev/null
@@ -1,171 +0,0 @@
-
- * @copyright 2005 James Stewart
- * @license http://www.gnu.org/copyleft/lesser.html GNU LGPL 2.1
- * @version CVS: $Id: RSS2Element.php,v 1.11 2006/07/26 21:18:47 jystewart Exp $
- * @link http://pear.php.net/package/XML_Feed_Parser/
- */
-
-/**
- * This class provides support for RSS 2.0 entries. It will usually be
- * called by XML_Feed_Parser_RSS2 with which it shares many methods.
- *
- * @author James Stewart
- * @version Release: 1.0.3
- * @package XML_Feed_Parser
- */
-class XML_Feed_Parser_RSS2Element extends XML_Feed_Parser_RSS2
-{
- /**
- * This will be a reference to the parent object for when we want
- * to use a 'fallback' rule
- * @var XML_Feed_Parser_RSS2
- */
- protected $parent;
-
- /**
- * Our specific element map
- * @var array
- */
- protected $map = array(
- 'title' => array('Text'),
- 'guid' => array('Guid'),
- 'description' => array('Text'),
- 'author' => array('Text'),
- 'comments' => array('Text'),
- 'enclosure' => array('Enclosure'),
- 'pubDate' => array('Date'),
- 'source' => array('Source'),
- 'link' => array('Text'),
- 'content' => array('Content'));
-
- /**
- * Here we map some elements to their atom equivalents. This is going to be
- * quite tricky to pull off effectively (and some users' methods may vary)
- * but is worth trying. The key is the atom version, the value is RSS2.
- * @var array
- */
- protected $compatMap = array(
- 'id' => array('guid'),
- 'updated' => array('lastBuildDate'),
- 'published' => array('pubdate'),
- 'guidislink' => array('guid', 'ispermalink'),
- 'summary' => array('description'));
-
- /**
- * Store useful information for later.
- *
- * @param DOMElement $element - this item as a DOM element
- * @param XML_Feed_Parser_RSS2 $parent - the feed of which this is a member
- */
- function __construct(DOMElement $element, $parent, $xmlBase = '')
- {
- $this->model = $element;
- $this->parent = $parent;
- }
-
- /**
- * Get the value of the guid element, if specified
- *
- * guid is the closest RSS2 has to atom's ID. It is usually but not always a
- * URI. The one attribute that RSS2 can posess is 'ispermalink' which specifies
- * whether the guid is itself dereferencable. Use of guid is not obligatory,
- * but is advisable. To get the guid you would call $item->id() (for atom
- * compatibility) or $item->guid(). To check if this guid is a permalink call
- * $item->guid("ispermalink").
- *
- * @param string $method - the method name being called
- * @param array $params - parameters required
- * @return string the guid or value of ispermalink
- */
- protected function getGuid($method, $params)
- {
- $attribute = (isset($params[0]) and $params[0] == 'ispermalink') ?
- true : false;
- $tag = $this->model->getElementsByTagName('guid');
- if ($tag->length > 0) {
- if ($attribute) {
- if ($tag->hasAttribute("ispermalink")) {
- return $tag->getAttribute("ispermalink");
- }
- }
- return $tag->item(0)->nodeValue;
- }
- return false;
- }
-
- /**
- * Access details of file enclosures
- *
- * The RSS2 spec is ambiguous as to whether an enclosure element must be
- * unique in a given entry. For now we will assume it needn't, and allow
- * for an offset.
- *
- * @param string $method - the method being called
- * @param array $parameters - we expect the first of these to be our offset
- * @return array|false
- */
- protected function getEnclosure($method, $parameters)
- {
- $encs = $this->model->getElementsByTagName('enclosure');
- $offset = isset($parameters[0]) ? $parameters[0] : 0;
- if ($encs->length > $offset) {
- try {
- if (! $encs->item($offset)->hasAttribute('url')) {
- return false;
- }
- $attrs = $encs->item($offset)->attributes;
- return array(
- 'url' => $attrs->getNamedItem('url')->value,
- 'length' => $attrs->getNamedItem('length')->value,
- 'type' => $attrs->getNamedItem('type')->value);
- } catch (Exception $e) {
- return false;
- }
- }
- return false;
- }
-
- /**
- * Get the entry source if specified
- *
- * source is an optional sub-element of item. Like atom:source it tells
- * us about where the entry came from (eg. if it's been copied from another
- * feed). It is not a rich source of metadata in the same way as atom:source
- * and while it would be good to maintain compatibility by returning an
- * XML_Feed_Parser_RSS2 element, it makes a lot more sense to return an array.
- *
- * @return array|false
- */
- protected function getSource()
- {
- $get = $this->model->getElementsByTagName('source');
- if ($get->length) {
- $source = $get->item(0);
- $array = array(
- 'content' => $source->nodeValue);
- foreach ($source->attributes as $attribute) {
- $array[$attribute->name] = $attribute->value;
- }
- return $array;
- }
- return false;
- }
-}
-
-?>
\ No newline at end of file
diff --git a/plugins/OStatus/extlib/XML/Feed/Parser/Type.php b/plugins/OStatus/extlib/XML/Feed/Parser/Type.php
deleted file mode 100644
index 75052619b..000000000
--- a/plugins/OStatus/extlib/XML/Feed/Parser/Type.php
+++ /dev/null
@@ -1,467 +0,0 @@
-
- * @copyright 2005 James Stewart
- * @license http://www.gnu.org/copyleft/lesser.html GNU LGPL 2.1
- * @version CVS: $Id: Type.php,v 1.25 2008/03/08 18:39:09 jystewart Exp $
- * @link http://pear.php.net/package/XML_Feed_Parser/
- */
-
-/**
- * This abstract class provides some general methods that are likely to be
- * implemented exactly the same way for all feed types.
- *
- * @package XML_Feed_Parser
- * @author James Stewart
- * @version Release: 1.0.3
- */
-abstract class XML_Feed_Parser_Type
-{
- /**
- * Where we store our DOM object for this feed
- * @var DOMDocument
- */
- public $model;
-
- /**
- * For iteration we'll want a count of the number of entries
- * @var int
- */
- public $numberEntries;
-
- /**
- * Where we store our entry objects once instantiated
- * @var array
- */
- public $entries = array();
-
- /**
- * Store mappings between entry IDs and their position in the feed
- */
- public $idMappings = array();
-
- /**
- * Proxy to allow use of element names as method names
- *
- * We are not going to provide methods for every entry type so this
- * function will allow for a lot of mapping. We rely pretty heavily
- * on this to handle our mappings between other feed types and atom.
- *
- * @param string $call - the method attempted
- * @param array $arguments - arguments to that method
- * @return mixed
- */
- function __call($call, $arguments = array())
- {
- if (! is_array($arguments)) {
- $arguments = array();
- }
-
- if (isset($this->compatMap[$call])) {
- $tempMap = $this->compatMap;
- $tempcall = array_pop($tempMap[$call]);
- if (! empty($tempMap)) {
- $arguments = array_merge($arguments, $tempMap[$call]);
- }
- $call = $tempcall;
- }
-
- /* To be helpful, we allow a case-insensitive search for this method */
- if (! isset($this->map[$call])) {
- foreach (array_keys($this->map) as $key) {
- if (strtoupper($key) == strtoupper($call)) {
- $call = $key;
- break;
- }
- }
- }
-
- if (empty($this->map[$call])) {
- return false;
- }
-
- $method = 'get' . $this->map[$call][0];
- if ($method == 'getLink') {
- $offset = empty($arguments[0]) ? 0 : $arguments[0];
- $attribute = empty($arguments[1]) ? 'href' : $arguments[1];
- $params = isset($arguments[2]) ? $arguments[2] : array();
- return $this->getLink($offset, $attribute, $params);
- }
- if (method_exists($this, $method)) {
- return $this->$method($call, $arguments);
- }
-
- return false;
- }
-
- /**
- * Proxy to allow use of element names as attribute names
- *
- * For many elements variable-style access will be desirable. This function
- * provides for that.
- *
- * @param string $value - the variable required
- * @return mixed
- */
- function __get($value)
- {
- return $this->__call($value, array());
- }
-
- /**
- * Utility function to help us resolve xml:base values
- *
- * We have other methods which will traverse the DOM and work out the different
- * xml:base declarations we need to be aware of. We then need to combine them.
- * If a declaration starts with a protocol then we restart the string. If it
- * starts with a / then we add on to the domain name. Otherwise we simply tag
- * it on to the end.
- *
- * @param string $base - the base to add the link to
- * @param string $link
- */
- function combineBases($base, $link)
- {
- if (preg_match('/^[A-Za-z]+:\/\//', $link)) {
- return $link;
- } else if (preg_match('/^\//', $link)) {
- /* Extract domain and suffix link to that */
- preg_match('/^([A-Za-z]+:\/\/.*)?\/*/', $base, $results);
- $firstLayer = $results[0];
- return $firstLayer . "/" . $link;
- } else if (preg_match('/^\.\.\//', $base)) {
- /* Step up link to find place to be */
- preg_match('/^((\.\.\/)+)(.*)$/', $link, $bases);
- $suffix = $bases[3];
- $count = preg_match_all('/\.\.\//', $bases[1], $steps);
- $url = explode("/", $base);
- for ($i = 0; $i <= $count; $i++) {
- array_pop($url);
- }
- return implode("/", $url) . "/" . $suffix;
- } else if (preg_match('/^(?!\/$)/', $base)) {
- $base = preg_replace('/(.*\/).*$/', '$1', $base) ;
- return $base . $link;
- } else {
- /* Just stick it on the end */
- return $base . $link;
- }
- }
-
- /**
- * Determine whether we need to apply our xml:base rules
- *
- * Gets us the xml:base data and then processes that with regard
- * to our current link.
- *
- * @param string
- * @param DOMElement
- * @return string
- */
- function addBase($link, $element)
- {
- if (preg_match('/^[A-Za-z]+:\/\//', $link)) {
- return $link;
- }
-
- return $this->combineBases($element->baseURI, $link);
- }
-
- /**
- * Get an entry by its position in the feed, starting from zero
- *
- * As well as allowing the items to be iterated over we want to allow
- * users to be able to access a specific entry. This is one of two ways of
- * doing that, the other being by ID.
- *
- * @param int $offset
- * @return XML_Feed_Parser_RSS1Element
- */
- function getEntryByOffset($offset)
- {
- if (! isset($this->entries[$offset])) {
- $entries = $this->model->getElementsByTagName($this->itemElement);
- if ($entries->length > $offset) {
- $xmlBase = $entries->item($offset)->baseURI;
- $this->entries[$offset] = new $this->itemClass(
- $entries->item($offset), $this, $xmlBase);
- if ($id = $this->entries[$offset]->id) {
- $this->idMappings[$id] = $this->entries[$offset];
- }
- } else {
- throw new XML_Feed_Parser_Exception('No entries found');
- }
- }
-
- return $this->entries[$offset];
- }
-
- /**
- * Return a date in seconds since epoch.
- *
- * Get a date construct. We use PHP's strtotime to return it as a unix datetime, which
- * is the number of seconds since 1970-01-01 00:00:00.
- *
- * @link http://php.net/strtotime
- * @param string $method The name of the date construct we want
- * @param array $arguments Included for compatibility with our __call usage
- * @return int|false datetime
- */
- protected function getDate($method, $arguments)
- {
- $time = $this->model->getElementsByTagName($method);
- if ($time->length == 0 || empty($time->item(0)->nodeValue)) {
- return false;
- }
- return strtotime($time->item(0)->nodeValue);
- }
-
- /**
- * Get a text construct.
- *
- * @param string $method The name of the text construct we want
- * @param array $arguments Included for compatibility with our __call usage
- * @return string
- */
- protected function getText($method, $arguments = array())
- {
- $tags = $this->model->getElementsByTagName($method);
- if ($tags->length > 0) {
- $value = $tags->item(0)->nodeValue;
- return $value;
- }
- return false;
- }
-
- /**
- * Apply various rules to retrieve category data.
- *
- * There is no single way of declaring a category in RSS1/1.1 as there is in RSS2
- * and Atom. Instead the usual approach is to use the dublin core namespace to
- * declare categories. For example delicious use both:
- * PEAR and:
- *
- * to declare a categorisation of 'PEAR'.
- *
- * We need to be sensitive to this where possible.
- *
- * @param string $call for compatibility with our overloading
- * @param array $arguments - arg 0 is the offset, arg 1 is whether to return as array
- * @return string|array|false
- */
- protected function getCategory($call, $arguments)
- {
- $categories = $this->model->getElementsByTagName('subject');
- $offset = empty($arguments[0]) ? 0 : $arguments[0];
- $array = empty($arguments[1]) ? false : true;
- if ($categories->length <= $offset) {
- return false;
- }
- if ($array) {
- $list = array();
- foreach ($categories as $category) {
- array_push($list, $category->nodeValue);
- }
- return $list;
- }
- return $categories->item($offset)->nodeValue;
- }
-
- /**
- * Count occurrences of an element
- *
- * This function will tell us how many times the element $type
- * appears at this level of the feed.
- *
- * @param string $type the element we want to get a count of
- * @return int
- */
- protected function count($type)
- {
- if ($tags = $this->model->getElementsByTagName($type)) {
- return $tags->length;
- }
- return 0;
- }
-
- /**
- * Part of our xml:base processing code
- *
- * We need a couple of methods to access XHTML content stored in feeds.
- * This is because we dereference all xml:base references before returning
- * the element. This method handles the attributes.
- *
- * @param DOMElement $node The DOM node we are iterating over
- * @return string
- */
- function processXHTMLAttributes($node) {
- $return = '';
- foreach ($node->attributes as $attribute) {
- if ($attribute->name == 'src' or $attribute->name == 'href') {
- $attribute->value = $this->addBase(htmlentities($attribute->value, NULL, 'utf-8'), $attribute);
- }
- if ($attribute->name == 'base') {
- continue;
- }
- $return .= $attribute->name . '="' . htmlentities($attribute->value, NULL, 'utf-8') .'" ';
- }
- if (! empty($return)) {
- return ' ' . trim($return);
- }
- return '';
- }
-
- /**
- * Convert HTML entities based on the current character set.
- *
- * @param String
- * @return String
- */
- function processEntitiesForNodeValue($node)
- {
- if (function_exists('iconv')) {
- $current_encoding = $node->ownerDocument->encoding;
- $value = iconv($current_encoding, 'UTF-8', $node->nodeValue);
- } else if ($current_encoding == 'iso-8859-1') {
- $value = utf8_encode($node->nodeValue);
- } else {
- $value = $node->nodeValue;
- }
-
- $decoded = html_entity_decode($value, NULL, 'UTF-8');
- return htmlentities($decoded, NULL, 'UTF-8');
- }
-
- /**
- * Part of our xml:base processing code
- *
- * We need a couple of methods to access XHTML content stored in feeds.
- * This is because we dereference all xml:base references before returning
- * the element. This method recurs through the tree descending from the node
- * and builds our string.
- *
- * @param DOMElement $node The DOM node we are processing
- * @return string
- */
- function traverseNode($node)
- {
- $content = '';
-
- /* Add the opening of this node to the content */
- if ($node instanceof DOMElement) {
- $content .= '<' . $node->tagName .
- $this->processXHTMLAttributes($node) . '>';
- }
-
- /* Process children */
- if ($node->hasChildNodes()) {
- foreach ($node->childNodes as $child) {
- $content .= $this->traverseNode($child);
- }
- }
-
- if ($node instanceof DOMText) {
- $content .= $this->processEntitiesForNodeValue($node);
- }
-
- /* Add the closing of this node to the content */
- if ($node instanceof DOMElement) {
- $content .= '' . $node->tagName . '>';
- }
-
- return $content;
- }
-
- /**
- * Get content from RSS feeds (atom has its own implementation)
- *
- * The official way to include full content in an RSS1 entry is to use
- * the content module's element 'encoded', and RSS2 feeds often duplicate that.
- * Often, however, the 'description' element is used instead. We will offer that
- * as a fallback. Atom uses its own approach and overrides this method.
- *
- * @return string|false
- */
- protected function getContent()
- {
- $options = array('encoded', 'description');
- foreach ($options as $element) {
- $test = $this->model->getElementsByTagName($element);
- if ($test->length == 0) {
- continue;
- }
- if ($test->item(0)->hasChildNodes()) {
- $value = '';
- foreach ($test->item(0)->childNodes as $child) {
- if ($child instanceof DOMText) {
- $value .= $child->nodeValue;
- } else {
- $simple = simplexml_import_dom($child);
- $value .= $simple->asXML();
- }
- }
- return $value;
- } else if ($test->length > 0) {
- return $test->item(0)->nodeValue;
- }
- }
- return false;
- }
-
- /**
- * Checks if this element has a particular child element.
- *
- * @param String
- * @param Integer
- * @return bool
- **/
- function hasKey($name, $offset = 0)
- {
- $search = $this->model->getElementsByTagName($name);
- return $search->length > $offset;
- }
-
- /**
- * Return an XML serialization of the feed, should it be required. Most
- * users however, will already have a serialization that they used when
- * instantiating the object.
- *
- * @return string XML serialization of element
- */
- function __toString()
- {
- $simple = simplexml_import_dom($this->model);
- return $simple->asXML();
- }
-
- /**
- * Get directory holding RNG schemas. Method is based on that
- * found in Contact_AddressBook.
- *
- * @return string PEAR data directory.
- * @access public
- * @static
- */
- static function getSchemaDir()
- {
- require_once 'PEAR/Config.php';
- $config = new PEAR_Config;
- return $config->get('data_dir') . '/XML_Feed_Parser/schemas';
- }
-}
-
-?>
\ No newline at end of file
diff --git a/plugins/OStatus/extlib/XML/Feed/samples/atom10-entryonly.xml b/plugins/OStatus/extlib/XML/Feed/samples/atom10-entryonly.xml
deleted file mode 100755
index 02e1c5800..000000000
--- a/plugins/OStatus/extlib/XML/Feed/samples/atom10-entryonly.xml
+++ /dev/null
@@ -1,28 +0,0 @@
-
-
- Atom draft-07 snapshot
-
-
- tag:example.org,2003:3.2397
- 2005-07-10T12:29:29Z
- 2003-12-13T08:29:29-04:00
-
- Mark Pilgrim
- http://example.org/
- f8dy@example.com
-
-
- Sam Ruby
-
-
- Joe Gregorio
-
-
-
-
[Update: The Atom draft is finished.]
-
-
-
\ No newline at end of file
diff --git a/plugins/OStatus/extlib/XML/Feed/samples/atom10-example1.xml b/plugins/OStatus/extlib/XML/Feed/samples/atom10-example1.xml
deleted file mode 100755
index d181d2b6f..000000000
--- a/plugins/OStatus/extlib/XML/Feed/samples/atom10-example1.xml
+++ /dev/null
@@ -1,20 +0,0 @@
-
-
-
- Example Feed
-
- 2003-12-13T18:30:02Z
-
- John Doe
-
- urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6
-
-
- Atom-Powered Robots Run Amok
-
- urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a
- 2003-12-13T18:30:02Z
- Some text.
-
-
-
\ No newline at end of file
diff --git a/plugins/OStatus/extlib/XML/Feed/samples/atom10-example2.xml b/plugins/OStatus/extlib/XML/Feed/samples/atom10-example2.xml
deleted file mode 100755
index 98abf9d54..000000000
--- a/plugins/OStatus/extlib/XML/Feed/samples/atom10-example2.xml
+++ /dev/null
@@ -1,45 +0,0 @@
-
-
- dive into mark
-
- A <em>lot</em> of effort
- went into making this effortless
-
- 2005-07-31T12:29:29Z
- tag:example.org,2003:3
-
-
- Copyright (c) 2003, Mark Pilgrim
-
- Example Toolkit
-
-
- Atom draft-07 snapshot
-
-
- tag:example.org,2003:3.2397
- 2005-07-31T12:29:29Z
- 2003-12-13T08:29:29-04:00
-
- Mark Pilgrim
- http://example.org/
- f8dy@example.com
-
-
- Sam Ruby
-
-
- Joe Gregorio
-
-
-
-
[Update: The Atom draft is finished.]
-
-
-
-
\ No newline at end of file
diff --git a/plugins/OStatus/extlib/XML/Feed/samples/delicious.feed b/plugins/OStatus/extlib/XML/Feed/samples/delicious.feed
deleted file mode 100755
index 32f9fa493..000000000
--- a/plugins/OStatus/extlib/XML/Feed/samples/delicious.feed
+++ /dev/null
@@ -1,177 +0,0 @@
-
-
-
-
-del.icio.us/tag/greenbelt
-http://del.icio.us/tag/greenbelt
-Text
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-Greenbelt - Homepage Section
-http://www.greenbelt.org.uk/
-jonnybaker
-2005-05-16T16:30:38Z
-greenbelt
-
-
-
-
-
-
-
-
-Greenbelt festival (uk)
-http://www.greenbelt.org.uk/
-sssshhhh
-2005-05-14T18:19:40Z
-audiology festival gigs greenbelt
-
-
-
-
-
-
-
-
-
-
-
-Natuerlichwien.at - Rundumadum
-http://www.natuerlichwien.at/rundumadum/dergruenguertel/
-egmilman47
-2005-05-06T21:33:41Z
-Austria Vienna Wien greenbelt nature walking
-
-
-
-
-
-
-
-
-
-
-
-
-
-Tank - GBMediaWiki
-http://www.flickerweb.co.uk/wiki/index.php/Tank#Seminars
-jystewart
-2005-03-21T22:44:11Z
-greenbelt
-
-
-
-
-
-
-
-
-Greenbelt homepage
-http://www.greenbelt.ca/home.htm
-Gooberoo
-2005-03-01T22:43:17Z
-greenbelt ontario
-
-
-
-
-
-
-
-
-
-Pip Wilson bhp ...... blog
-http://pipwilsonbhp.blogspot.com/
-sssshhhh
-2004-12-27T11:20:51Z
-Greenbelt friend ideas links thinking weblog
-
-
-
-
-
-
-
-
-
-
-
-
-
-maggi dawn
-http://maggidawn.typepad.com/maggidawn/
-sssshhhh
-2004-12-27T11:20:11Z
-Greenbelt ideas links thinking weblog
-
-
-
-
-
-
-
-
-
-
-
-
-John Davies
-http://www.johndavies.org/
-sssshhhh
-2004-12-27T11:18:37Z
-Greenbelt ideas links thinking weblog
-
-
-
-
-
-
-
-
-
-
-
-
-jonnybaker
-http://jonnybaker.blogs.com/
-sssshhhh
-2004-12-27T11:18:17Z
-Greenbelt event ideas links resources thinking weblog youth
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/plugins/OStatus/extlib/XML/Feed/samples/flickr.feed b/plugins/OStatus/extlib/XML/Feed/samples/flickr.feed
deleted file mode 100755
index 57e83af57..000000000
--- a/plugins/OStatus/extlib/XML/Feed/samples/flickr.feed
+++ /dev/null
@@ -1,184 +0,0 @@
-
-
-
- jamesstewart - Everyone's Tagged Photos
-
-
- A feed of jamesstewart - Everyone's Tagged Photos
- 2005-08-01T18:50:26Z
- Flickr
-
-
- Oma and James
-
-
- tag:flickr.com,2004:/photo/30367516
- 2005-08-01T18:50:26Z
- 2005-08-01T18:50:26Z
- <p><a href="http://www.flickr.com/people/30484029@N00/">kstewart</a> posted a photo:</p>
-
-<p><a href="http://www.flickr.com/photos/30484029@N00/30367516/" title="Oma and James"><img src="http://photos23.flickr.com/30367516_1f685a16e8_m.jpg" width="240" height="180" alt="Oma and James" style="border: 1px solid #000000;" /></a></p>
-
-<p>I have a beautiful Oma and a gorgeous husband.</p>
-
- kstewart
- http://www.flickr.com/people/30484029@N00/
-
- jamesstewart oma stoelfamily
-
-
-
-
- tag:flickr.com,2004:/photo/21376174
- 2005-06-25T02:00:35Z
- 2005-06-25T02:00:35Z
- <p><a href="http://www.flickr.com/people/buddscreek/">Lan Rover</a> posted a photo:</p>
-
-<p><a href="http://www.flickr.com/photos/buddscreek/21376174/" title=""><img src="http://photos17.flickr.com/21376174_4314fd8d5c_m.jpg" width="240" height="160" alt="" style="border: 1px solid #000000;" /></a></p>
-
-<p>AMA Motocross Championship 2005, Budds Creek, Maryland</p>
-
- Lan Rover
- http://www.flickr.com/people/buddscreek/
-
- amamotocrosschampionship buddscreek maryland 2005 fathersday motocrossnational rickycarmichael 259 jamesstewart 4
-
-
-
-
- tag:flickr.com,2004:/photo/21375650
- 2005-06-25T01:56:24Z
- 2005-06-25T01:56:24Z
- <p><a href="http://www.flickr.com/people/buddscreek/">Lan Rover</a> posted a photo:</p>
-
-<p><a href="http://www.flickr.com/photos/buddscreek/21375650/" title=""><img src="http://photos16.flickr.com/21375650_5c60e0dab1_m.jpg" width="240" height="160" alt="" style="border: 1px solid #000000;" /></a></p>
-
-
-
- Lan Rover
- http://www.flickr.com/people/buddscreek/
-
- amamotocrosschampionship buddscreek maryland 2005 fathersday motocrossnational 259 jamesstewart
-
-
-
-
- tag:flickr.com,2004:/photo/21375345
- 2005-06-25T01:54:11Z
- 2005-06-25T01:54:11Z
- <p><a href="http://www.flickr.com/people/buddscreek/">Lan Rover</a> posted a photo:</p>
-
-<p><a href="http://www.flickr.com/photos/buddscreek/21375345/" title=""><img src="http://photos15.flickr.com/21375345_4205fdd22b_m.jpg" width="160" height="240" alt="" style="border: 1px solid #000000;" /></a></p>
-
-
-
- Lan Rover
- http://www.flickr.com/people/buddscreek/
-
- amamotocrosschampionship buddscreek maryland 2005 fathersday motocrossnational 259 jamesstewart
-
-
- Lunch with Kari & James, café in the crypt of St Martin in the fields
-
- tag:flickr.com,2004:/photo/16516618
- 2005-05-30T21:56:39Z
- 2005-05-30T21:56:39Z
- <p><a href="http://www.flickr.com/people/fidothe/">fidothe</a> posted a photo:</p>
-
-<p><a href="http://www.flickr.com/photos/fidothe/16516618/" title="Lunch with Kari & James, café in the crypt of St Martin in the fields"><img src="http://photos14.flickr.com/16516618_afaa4a395e_m.jpg" width="240" height="180" alt="Lunch with Kari & James, café in the crypt of St Martin in the fields" style="border: 1px solid #000000;" /></a></p>
-
-
-
- fidothe
- http://www.flickr.com/people/fidothe/
-
- nokia7610 london stmartininthefields clarepatterson jamesstewart parvinstewart jimstewart susanstewart
-
-
- Stewart keeping it low over the obstacle.
-
- tag:flickr.com,2004:/photo/10224728
- 2005-04-21T07:30:29Z
- 2005-04-21T07:30:29Z
- <p><a href="http://www.flickr.com/people/pqbon/">pqbon</a> posted a photo:</p>
-
-<p><a href="http://www.flickr.com/photos/pqbon/10224728/" title="Stewart keeping it low over the obstacle."><img src="http://photos7.flickr.com/10224728_b756341957_m.jpg" width="240" height="180" alt="Stewart keeping it low over the obstacle." style="border: 1px solid #000000;" /></a></p>
-
-
-
- pqbon
- http://www.flickr.com/people/pqbon/
-
- ama hangtown motocross jamesstewart bubba
-
-
- king james stewart
-
- tag:flickr.com,2004:/photo/7152910
- 2005-03-22T21:53:37Z
- 2005-03-22T21:53:37Z
- <p><a href="http://www.flickr.com/people/jjlook/">jj look</a> posted a photo:</p>
-
-<p><a href="http://www.flickr.com/photos/jjlook/7152910/" title="king james stewart"><img src="http://photos7.flickr.com/7152910_a02ab5a750_m.jpg" width="180" height="240" alt="king james stewart" style="border: 1px solid #000000;" /></a></p>
-
-<p>11th</p>
-
- jj look
- http://www.flickr.com/people/jjlook/
-
- dilomar05 eastside austin texas 78702 kingjames stewart jamesstewart borrowed
-
-
- It's a Grind, downtown Grand Rapids (James, Susan, Jim, Harv, Lawson)
-
- tag:flickr.com,2004:/photo/1586562
- 2004-11-20T09:34:28Z
- 2004-11-20T09:34:28Z
- <p><a href="http://www.flickr.com/people/fidothe/">fidothe</a> posted a photo:</p>
-
-<p><a href="http://www.flickr.com/photos/fidothe/1586562/" title="It's a Grind, downtown Grand Rapids (James, Susan, Jim, Harv, Lawson)"><img src="http://photos2.flickr.com/1586562_0bc5313a3e_m.jpg" width="240" height="180" alt="It's a Grind, downtown Grand Rapids (James, Susan, Jim, Harv, Lawson)" style="border: 1px solid #000000;" /></a></p>
-
-
-
- fidothe
- http://www.flickr.com/people/fidothe/
-
- holiday grandrapids jamesstewart
-
-
- It's a Grind, downtown Grand Rapids (James, Susan, Jim, Harv, Lawson)
-
- tag:flickr.com,2004:/photo/1586539
- 2004-11-20T09:28:16Z
- 2004-11-20T09:28:16Z
- <p><a href="http://www.flickr.com/people/fidothe/">fidothe</a> posted a photo:</p>
-
-<p><a href="http://www.flickr.com/photos/fidothe/1586539/" title="It's a Grind, downtown Grand Rapids (James, Susan, Jim, Harv, Lawson)"><img src="http://photos2.flickr.com/1586539_c51e5f2e7a_m.jpg" width="240" height="180" alt="It's a Grind, downtown Grand Rapids (James, Susan, Jim, Harv, Lawson)" style="border: 1px solid #000000;" /></a></p>
-
-
-
- fidothe
- http://www.flickr.com/people/fidothe/
-
- holiday grandrapids jamesstewart
-
-
- It's a Grind, James and Jim can't decide)
-
- tag:flickr.com,2004:/photo/1586514
- 2004-11-20T09:25:05Z
- 2004-11-20T09:25:05Z
- <p><a href="http://www.flickr.com/people/fidothe/">fidothe</a> posted a photo:</p>
-
-<p><a href="http://www.flickr.com/photos/fidothe/1586514/" title="It's a Grind, James and Jim can't decide)"><img src="http://photos2.flickr.com/1586514_733c2dfa3e_m.jpg" width="240" height="180" alt="It's a Grind, James and Jim can't decide)" style="border: 1px solid #000000;" /></a></p>
-
-
-
- fidothe
- http://www.flickr.com/people/fidothe/
-
- holiday grandrapids jamesstewart johnkentish
-
-
-
\ No newline at end of file
diff --git a/plugins/OStatus/extlib/XML/Feed/samples/grwifi-atom.xml b/plugins/OStatus/extlib/XML/Feed/samples/grwifi-atom.xml
deleted file mode 100755
index c351d3c16..000000000
--- a/plugins/OStatus/extlib/XML/Feed/samples/grwifi-atom.xml
+++ /dev/null
@@ -1,7 +0,0 @@
-
Updates to Grand Rapids WiFi hotspot details2005-09-01T15:43:01-05:00WiFi Hotspots in Grand Rapids, MIhttp://grwifi.net/atom/locationsCreative Commons Attribution-NonCommercial-ShareAlike 2.0 http://creativecommons.org/licenses/by-nc-sa/2.0/ Hotspot Details Updated: Sweetwatershttp://grwifi.net/location/sweetwaters2005-09-01T15:43:01-05:00
The details of the WiFi hotspot at: Sweetwaters have been updated. Find out more at:
-http://grwifi.net/location/sweetwaters
Jameshttp://jystewart.netjames@jystewart.netwifi hotspotHotspot Details Updated: Common Ground Coffee Shophttp://grwifi.net/location/common-ground2005-09-01T15:42:39-05:00
The details of the WiFi hotspot at: Common Ground Coffee Shop have been updated. Find out more at:
-http://grwifi.net/location/common-ground
Jameshttp://jystewart.netjames@jystewart.netwifi hotspotHotspot Details Updated: Grand Rapids Public Library, Main Branchhttp://grwifi.net/location/grpl-main-branch2005-09-01T15:42:20-05:00
The details of the WiFi hotspot at: Grand Rapids Public Library, Main Branch have been updated. Find out more at:
-http://grwifi.net/location/grpl-main-branch
Jameshttp://jystewart.netjames@jystewart.netwifi hotspotHotspot Details Updated: Four Friends Coffee Househttp://grwifi.net/location/four-friends2005-09-01T15:41:35-05:00
The details of the WiFi hotspot at: Four Friends Coffee House have been updated. Find out more at:
-http://grwifi.net/location/four-friends
Jameshttp://jystewart.netjames@jystewart.netwifi hotspotHotspot Details Updated: Barnes and Noble, Rivertown Crossingshttp://grwifi.net/location/barnes-noble-rivertown2005-09-01T15:40:41-05:00
The details of the WiFi hotspot at: Barnes and Noble, Rivertown Crossings have been updated. Find out more at:
-http://grwifi.net/location/barnes-noble-rivertown
Jameshttp://jystewart.netjames@jystewart.netwifi hotspotHotspot Details Updated: The Boss Sports Bar & Grillehttp://grwifi.net/location/boss-sports-bar2005-09-01T15:40:19-05:00
The details of the WiFi hotspot at: The Boss Sports Bar & Grille have been updated. Find out more at:
-http://grwifi.net/location/boss-sports-bar
Jameshttp://jystewart.netjames@jystewart.netwifi hotspot
\ No newline at end of file
diff --git a/plugins/OStatus/extlib/XML/Feed/samples/hoder.xml b/plugins/OStatus/extlib/XML/Feed/samples/hoder.xml
deleted file mode 100755
index 099463570..000000000
--- a/plugins/OStatus/extlib/XML/Feed/samples/hoder.xml
+++ /dev/null
@@ -1,102 +0,0 @@
-
-
-
-
-Editor: Myself (Persian)
-http://editormyself.info
-This is a Persian (Farsi) weblog, written by Hossein Derakhshan (aka, Hoder), an Iranian Multimedia designer and a journalist who lives in Toronto since Dec 2000. He also keeps an English weblog with the same name.
-en-us
-hoder@hotmail.com
-2005-10-12T19:45:32-05:00
-
-hourly
-1
-2000-01-01T12:00+00:00
-
-
-
-لينکدونی | جلسهی امریکن انترپرایز برای تقسیم قومی ایران
-http://www.aei.org/events/type.upcoming,eventID.1166,filter.all/event_detail.asp
-چطور بعضیها فکر میکنند دست راستیهای آمریکا از خامنهای ملیگراترند
-14645@http://i.hoder.com/
-iran
-2005-10-12T19:45:32-05:00
-
-
-
-لينکدونی | به صبحانه آگهی بدهید
-http://www.adbrite.com/mb/commerce/purchase_form.php?opid=24346&afsid=1
-خیلی ارزان و راحت است
-14644@http://i.hoder.com/
-media/journalism
-2005-10-12T17:23:15-05:00
-
-
-
-لينکدونی | نیروی انتظامی چگونه تابوهای همجنسگرایانه را میشکند؛ فرنگوپولیس
-http://farangeopolis.blogspot.com/2005/10/blog-post_08.html
-از پس و پیش و حاشیهی این ماجرا میتوان یک مستند بینظیر ساخت
-14643@http://i.hoder.com/
-soc_popculture
-2005-10-12T17:06:40-05:00
-
-
-
-لينکدونی | بازتاب توقیف شد
-http://www.baztab.com/news/30201.php
-اگر گفتید یک وبسایت را چطور توقیف میکنند؟ لابد ماوسشان را قایم میکنند.
-14642@http://i.hoder.com/
-media/journalism
-2005-10-12T14:41:57-05:00
-
-
-
-لينکدونی | رشد وب در سال 2005 از همیشه بیشتر بوده است" بی.بی.سی
-http://news.bbc.co.uk/2/hi/technology/4325918.stm
-
-14640@http://i.hoder.com/
-tech
-2005-10-12T13:04:46-05:00
-
-
-
-
-
-==قرعه کشی گرین کارد به زودی شروع میشود==
-http://nice.newsxphotos.biz/05/09/2007_dv_lottery_registration_to_begin_oct_5_14589.php
-
-14613@http://vagrantly.com
-ads03
-2005-09-27T04:49:22-05:00
-
-
-
-
-
-
-
-
-پروژهی هاروارد، قدم دوم
-http://editormyself.info/archives/2005/10/051012_014641.shtml
-اگر یادتان باشد چند وقت پیش نوشتم که دانشگاه هاروارد پروژهای دارد با نام آواهای جهانی که در آن به وبلاگهای غیر انگلیسیزبان میپردازد. خواشتم که اگر کسی علاقه دارد ایمیل بزند. تعداد زیادی جواب دادند و ابراز علاقه کردند. حالا وقت قدم دوم است.
-
-
قدم دوم این است که برای اینکه مسوولین پروژه بتوانند تصمیم بگیرند که با چه کسی کار کنند، میخواهند نمونهی کارهای علاقمندان مشارکت در این پرزوه را ببینند.
-
-
برای همین از همهی علاقماندان، حتی کسانی که قبلا اعلام آمادگی نکرده بودند، میخواهم که یک موضوع رایج این روزهای وبلاگستان فارسی را انتخاب کنند و در هفتصد کلمه، به انگلیسی، بنویسند که وبلاگدارهای دربارهاش چه میگویند. لینک به پنج، شش وبلاگ و بازنویسی آنچه آنها از جنبههای گوناگون دربارهی آن موضوع نوشتهاند با نقل قول مستقیم از آنها (البته ترجمه شده از فارسی) کافی است. دو سه جمله هم اول کار توضیح دهید که چرا این موضوع مهم است.
-
-
متن نمونه را به آدرس ایمیل من hoder@hoder.com و نیز برای افراد زیر تا روز دوشنبه بفرستید:
-ربکا : rmackinnon@cyber.law.harvard.edu
-هیثم: haitham.sabbah@gmail.com
9月21日に開設されたこのブログは、ブラジル、ホンジュラス、ニカラグア、メキシコ、キューバの5か国を巡る「Latin America 2005」ツアーに合わせ、そのツアーの模様を同行マネージャーがレポートしていきます。
-さらに今月2日からは宮沢和史自身が日々録音した声をPodcastingするという点でも、ブログを使ったユニークなプロモーションとなっています。