Commit b8e97ac7 authored by Zach Copley's avatar Zach Copley

Some initial media parsing

- Activity now returns a list of activity objects
- Processing of photo objects
parent 073e3a15
......@@ -53,6 +53,7 @@ class Activity
{
const SPEC = 'http://activitystrea.ms/spec/1.0/';
const SCHEMA = 'http://activitystrea.ms/schema/1.0/';
const MEDIA = 'http://purl.org/syndication/atommedia';
const VERB = 'verb';
const OBJECT = 'object';
......@@ -85,7 +86,7 @@ class Activity
public $actor; // an ActivityObject
public $verb; // a string (the URL)
public $object; // an ActivityObject
public $objects = array(); // an array of ActivityObjects
public $target; // an ActivityObject
public $context; // an ActivityObject
public $time; // Time of the activity
......@@ -161,12 +162,15 @@ class Activity
// XXX: do other implied stuff here
}
$objectEl = $this->_child($entry, self::OBJECT);
$objectEls = $entry->getElementsByTagNameNS(self::SPEC, self::OBJECT);
if (!empty($objectEl)) {
$this->object = new ActivityObject($objectEl);
if ($objectEls->length > 0) {
for ($i = 0; $i < $objectEls->length; $i++) {
$objectEl = $objectEls->item($i);
$this->objects[] = new ActivityObject($objectEl);
}
} else {
$this->object = new ActivityObject($entry);
$this->objects[] = new ActivityObject($entry);
}
$actorEl = $this->_child($entry, self::ACTOR);
......@@ -280,8 +284,8 @@ class Activity
}
}
$this->object = new ActivityObject($item);
$this->context = new ActivityContext($item);
$this->objects[] = new ActivityObject($item);
$this->context = new ActivityContext($item);
}
/**
......@@ -339,8 +343,10 @@ class Activity
$xs->element('activity:verb', null, $this->verb);
if ($this->object) {
$xs->raw($this->object->asString());
if (!empty($this->objects)) {
foreach($this->objects as $object) {
$xs->raw($object->asString());
}
}
if ($this->target) {
......
......@@ -100,6 +100,13 @@ class ActivityObject
public $poco;
public $displayName;
// @todo move this stuff to it's own PHOTO activity object
const MEDIA_DESCRIPTION = 'description';
public $thumbnail;
public $largerImage;
public $description;
/**
* Constructor
*
......@@ -150,6 +157,19 @@ class ActivityObject
$this->poco = new PoCo($element);
}
if ($this->type == self::PHOTO) {
$this->thumbnail = ActivityUtils::getLink($element, 'preview');
$this->largerImage = ActivityUtils::getLink($element, 'enclosure');
$this->description = ActivityUtils::childContent(
$element,
ActivityObject::MEDIA_DESCRIPTION,
Activity::MEDIA
);
}
}
private function _fromAuthor($element)
......
......@@ -60,7 +60,8 @@ class GroupsalmonAction extends SalmonAction
function handlePost()
{
switch ($this->act->object->type) {
// @fixme process all objects?
switch ($this->act->objects[0]->type) {
case ActivityObject::ARTICLE:
case ActivityObject::BLOGENTRY:
case ActivityObject::NOTE:
......
......@@ -55,9 +55,10 @@ class UsersalmonAction extends SalmonAction
*/
function handlePost()
{
common_log(LOG_INFO, "Received post of '{$this->act->object->id}' from '{$this->act->actor->id}'");
common_log(LOG_INFO, "Received post of '{$this->act->objects[0]->id}' from '{$this->act->actor->id}'");
switch ($this->act->object->type) {
// @fixme: process all activity objects?
switch ($this->act->objects[0]->type) {
case ActivityObject::ARTICLE:
case ActivityObject::BLOGENTRY:
case ActivityObject::NOTE:
......
......@@ -494,7 +494,7 @@ class Ostatus_profile extends Memcached_DataObject
// It's not always an ActivityObject::NOTE, but... let's just say it is.
$note = $activity->object;
$note = $activity->objects[0];
// The id URI will be used as a unique identifier for for the notice,
// protecting against duplicate saves. It isn't required to be a URL;
......
......@@ -102,7 +102,7 @@ function importActivityStream($user, $doc)
for ($i = $entries->length - 1; $i >= 0; $i--) {
$entry = $entries->item($i);
$activity = new Activity($entry, $feed);
$object = $activity->object;
$object = $activity->objects[0];
if (!have_option('q', 'quiet')) {
print $activity->content . "\n";
}
......
This diff is collapsed.
......@@ -66,11 +66,11 @@ class UserFeedParseTests extends PHPUnit_Framework_TestCase
// test the post
//var_export($act1);
$this->assertEquals($act1->object->type, 'http://activitystrea.ms/schema/1.0/note');
$this->assertEquals($act1->object->title, 'And now for something completely insane...');
$this->assertEquals($act1->objects[0]->type, 'http://activitystrea.ms/schema/1.0/note');
$this->assertEquals($act1->objects[0]->title, 'And now for something completely insane...');
$this->assertEquals($act1->object->content, 'And now for something completely insane...');
$this->assertEquals($act1->object->id, 'http://localhost/statusnet/notice/3');
$this->assertEquals($act1->objects[0]->content, 'And now for something completely insane...');
$this->assertEquals($act1->objects[0]->id, 'http://localhost/statusnet/notice/3');
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment