From 323ff31fbd59181f4cd9a3fc4da40a1f9ff8bc99 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sat, 20 Mar 2010 16:53:30 -0500 Subject: special-case Posterous author element for activity actor --- lib/activity.php | 18 +++++++++--------- lib/activityobject.php | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 9 deletions(-) (limited to 'lib') diff --git a/lib/activity.php b/lib/activity.php index b1744e68f..691ace1f6 100644 --- a/lib/activity.php +++ b/lib/activity.php @@ -238,17 +238,17 @@ class Activity $this->time = strtotime($pubDateEl->textContent); } - $authorEl = $this->_child($item, self::AUTHOR, self::RSS); - - if (!empty($authorEl)) { + if ($authorEl = $this->_child($item, self::AUTHOR, self::RSS)) { $this->actor = ActivityObject::fromRssAuthor($authorEl); + } else if ($dcCreatorEl = $this->_child($item, self::CREATOR, self::DC)) { + $this->actor = ActivityObject::fromDcCreator($dcCreatorEl); + } else if ($posterousEl = $this->_child($item, ActivityObject::AUTHOR, ActivityObject::POSTEROUS)) { + // Special case for Posterous.com + $this->actor = ActivityObject::fromPosterousAuthor($posterousEl); + } else if (!empty($channel)) { + $this->actor = ActivityObject::fromRssChannel($channel); } else { - $dcCreatorEl = $this->_child($item, self::CREATOR, self::DC); - if (!empty($dcCreatorEl)) { - $this->actor = ActivityObject::fromDcCreator($dcCreatorEl); - } else if (!empty($channel)) { - $this->actor = ActivityObject::fromRssChannel($channel); - } + // No actor! } $this->title = ActivityUtils::childContent($item, ActivityObject::TITLE, self::RSS); diff --git a/lib/activityobject.php b/lib/activityobject.php index b1e9071ed..18e3e21dd 100644 --- a/lib/activityobject.php +++ b/lib/activityobject.php @@ -80,6 +80,13 @@ class ActivityObject const URI = 'uri'; const EMAIL = 'email'; + const POSTEROUS = 'http://posterous.com/help/rss/1.0'; + const AUTHOR = 'author'; + const USERIMAGE = 'userImage'; + const PROFILEURL = 'profileUrl'; + const NICKNAME = 'nickName'; + const DISPLAYNAME = 'displayName'; + public $element; public $type; public $id; @@ -296,6 +303,31 @@ class ActivityObject return $obj; } + public static function fromPosterousAuthor($el) + { + $obj = new ActivityObject(); + + $obj->type = ActivityObject::PERSON; // @fixme any others...? + + $userImage = ActivityUtils::childContent($el, self::USERIMAGE, self::POSTEROUS); + + if (!empty($userImage)) { + $obj->avatarLinks[] = $userImage; + } + + $obj->link = ActivityUtils::childContent($el, self::PROFILEURL, self::POSTEROUS); + $obj->id = $obj->link; + + $obj->poco = new PoCo(); + + $obj->poco->preferredUsername = ActivityUtils::childContent($el, self::NICKNAME, self::POSTEROUS); + $obj->poco->displayName = ActivityUtils::childContent($el, self::DISPLAYNAME, self::POSTEROUS); + + $obj->title = $obj->poco->displayName; + + return $obj; + } + private function _childContent($element, $tag, $namespace=ActivityUtils::ATOM) { return ActivityUtils::childContent($element, $tag, $namespace); -- cgit v1.2.3-54-g00ecf From 11a86d046e30a7fe76d242c5dd2e54ed9a808ab2 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sat, 20 Mar 2010 16:55:36 -0500 Subject: move atom category to its own file, too --- lib/activity.php | 45 ------------------------------ lib/atomcategory.php | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+), 45 deletions(-) create mode 100644 lib/atomcategory.php (limited to 'lib') diff --git a/lib/activity.php b/lib/activity.php index 691ace1f6..bd1d5d56c 100644 --- a/lib/activity.php +++ b/lib/activity.php @@ -362,48 +362,3 @@ class Activity } } -class AtomCategory -{ - public $term; - public $scheme; - public $label; - - function __construct($element=null) - { - if ($element && $element->attributes) { - $this->term = $this->extract($element, 'term'); - $this->scheme = $this->extract($element, 'scheme'); - $this->label = $this->extract($element, 'label'); - } - } - - protected function extract($element, $attrib) - { - $node = $element->attributes->getNamedItemNS(Activity::ATOM, $attrib); - if ($node) { - return trim($node->textContent); - } - $node = $element->attributes->getNamedItem($attrib); - if ($node) { - return trim($node->textContent); - } - return null; - } - - function asString() - { - $attribs = array(); - if ($this->term !== null) { - $attribs['term'] = $this->term; - } - if ($this->scheme !== null) { - $attribs['scheme'] = $this->scheme; - } - if ($this->label !== null) { - $attribs['label'] = $this->label; - } - $xs = new XMLStringer(); - $xs->element('category', $attribs); - return $xs->asString(); - } -} diff --git a/lib/atomcategory.php b/lib/atomcategory.php new file mode 100644 index 000000000..4cc3b4f4d --- /dev/null +++ b/lib/atomcategory.php @@ -0,0 +1,77 @@ +. + * + * @category Feed + * @package StatusNet + * @author Evan Prodromou + * @author Zach Copley + * @copyright 2010 StatusNet, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPLv3 + * @link http://status.net/ + */ + +if (!defined('STATUSNET')) { + exit(1); +} + +class AtomCategory +{ + public $term; + public $scheme; + public $label; + + function __construct($element=null) + { + if ($element && $element->attributes) { + $this->term = $this->extract($element, 'term'); + $this->scheme = $this->extract($element, 'scheme'); + $this->label = $this->extract($element, 'label'); + } + } + + protected function extract($element, $attrib) + { + $node = $element->attributes->getNamedItemNS(Activity::ATOM, $attrib); + if ($node) { + return trim($node->textContent); + } + $node = $element->attributes->getNamedItem($attrib); + if ($node) { + return trim($node->textContent); + } + return null; + } + + function asString() + { + $attribs = array(); + if ($this->term !== null) { + $attribs['term'] = $this->term; + } + if ($this->scheme !== null) { + $attribs['scheme'] = $this->scheme; + } + if ($this->label !== null) { + $attribs['label'] = $this->label; + } + $xs = new XMLStringer(); + $xs->element('category', $attribs); + return $xs->asString(); + } +} -- cgit v1.2.3-54-g00ecf From 97bd7e22da893ac2d93e66d7f4747358713e739b Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sat, 20 Mar 2010 17:18:24 -0500 Subject: correct creation of avatar links for RSS and Posterous elements --- lib/activityobject.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/activityobject.php b/lib/activityobject.php index 18e3e21dd..e5cea727b 100644 --- a/lib/activityobject.php +++ b/lib/activityobject.php @@ -297,7 +297,10 @@ class ActivityObject $imageEl = ActivityUtils::child($el, Activity::IMAGE, Activity::RSS); if (!empty($imageEl)) { - $obj->avatarLinks[] = ActivityUtils::childContent($imageEl, Activity::URL, Activity::RSS); + $url = ActivityUtils::childContent($imageEl, Activity::URL, Activity::RSS); + $al = new AvatarLink(); + $al->url = $url; + $obj->avatarLinks[] = $al; } return $obj; @@ -312,7 +315,9 @@ class ActivityObject $userImage = ActivityUtils::childContent($el, self::USERIMAGE, self::POSTEROUS); if (!empty($userImage)) { - $obj->avatarLinks[] = $userImage; + $al = new AvatarLink(); + $al->url = $userImage; + $obj->avatarLinks[] = $al; } $obj->link = ActivityUtils::childContent($el, self::PROFILEURL, self::POSTEROUS); -- cgit v1.2.3-54-g00ecf From fcb614d0eb1f98bf8704654ed06e1f9d9733d359 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Sun, 21 Mar 2010 16:25:12 -0700 Subject: Pull info as well as when we have an old-style ActivityStreams feed. This fixes subscription setup for Cliqset feeds, which currently have a bogus activity:actor/atom:id but a good atom:author/atom:uri --- lib/activityobject.php | 21 +++++++++++++++++++-- lib/activityutils.php | 22 ++++++++++++++++++++++ plugins/OStatus/classes/Ostatus_profile.php | 6 +----- 3 files changed, 42 insertions(+), 7 deletions(-) (limited to 'lib') diff --git a/lib/activityobject.php b/lib/activityobject.php index e5cea727b..0a358ccab 100644 --- a/lib/activityobject.php +++ b/lib/activityobject.php @@ -156,7 +156,11 @@ class ActivityObject { $this->type = self::PERSON; // XXX: is this fair? $this->title = $this->_childContent($element, self::NAME); - $this->id = $this->_childContent($element, self::URI); + + $id = $this->_childContent($element, self::URI); + if (ActivityUtils::validateUri($id)) { + $this->id = $id; + } if (empty($this->id)) { $email = $this->_childContent($element, self::EMAIL); @@ -169,6 +173,15 @@ class ActivityObject private function _fromAtomEntry($element) { + if ($element->localName == 'actor') { + // Old-fashioned ... + // First pull anything from , then we'll add on top. + $author = ActivityUtils::child($element->parentNode, 'author'); + if ($author) { + $this->_fromAuthor($author); + } + } + $this->type = $this->_childContent($element, Activity::OBJECTTYPE, Activity::SPEC); @@ -176,7 +189,11 @@ class ActivityObject $this->type = ActivityObject::NOTE; } - $this->id = $this->_childContent($element, self::ID); + $id = $this->_childContent($element, self::ID); + if (ActivityUtils::validateUri($id)) { + $this->id = $id; + } + $this->summary = ActivityUtils::childHtmlContent($element, self::SUMMARY); $this->content = ActivityUtils::getContent($element); diff --git a/lib/activityutils.php b/lib/activityutils.php index c85a3db55..a7e99fb11 100644 --- a/lib/activityutils.php +++ b/lib/activityutils.php @@ -240,4 +240,26 @@ class ActivityUtils throw new ClientException(_("Can't handle embedded Base64 content yet.")); } } + + /** + * Is this a valid URI for remote profile/notice identification? + * Does not have to be a resolvable URL. + * @param string $uri + * @return boolean + */ + static function validateUri($uri) + { + if (Validate::uri($uri)) { + return true; + } + + // Possibly an upstream bug; tag: URIs aren't validated properly + // unless you explicitly ask for them. All other schemes are accepted + // for basic URI validation without asking. + if (Validate::uri($uri, array('allowed_scheme' => array('tag')))) { + return true; + } + + return false; + } } diff --git a/plugins/OStatus/classes/Ostatus_profile.php b/plugins/OStatus/classes/Ostatus_profile.php index 5595a9d29..e33509c47 100644 --- a/plugins/OStatus/classes/Ostatus_profile.php +++ b/plugins/OStatus/classes/Ostatus_profile.php @@ -1170,11 +1170,7 @@ class Ostatus_profile extends Memcached_DataObject protected static function getActivityObjectProfileURI($object) { if ($object->id) { - // Possibly an upstream bug; tag: URIs are rejected unless you - // explicitly ask for them. All other schemes are accepted for - // basic URI validation without asking. - if (Validate::uri($object->id) || - Validate::uri($object->id, array('allowed_scheme' => array('tag')))) { + if (ActivityUtils::validateUri($object->id)) { return $object->id; } } -- cgit v1.2.3-54-g00ecf