Commit cb371d65 authored by Evan Prodromou's avatar Evan Prodromou

add hooks for atom pub posts

parent b60b9b4f
...@@ -1158,3 +1158,11 @@ StartRevokeRole: when a role is being revoked ...@@ -1158,3 +1158,11 @@ StartRevokeRole: when a role is being revoked
EndRevokeRole: when a role has been revoked EndRevokeRole: when a role has been revoked
- $profile: profile that lost the role - $profile: profile that lost the role
- $role: string name of the role - $role: string name of the role
StartAtomPubNewActivity: When a new activity comes in through Atom Pub API
- &$activity: received activity
EndAtomPubNewActivity: When a new activity comes in through Atom Pub API
- $activity: received activity
- $notice: notice that was created
...@@ -325,20 +325,38 @@ class ApiTimelineUserAction extends ApiBareAuthAction ...@@ -325,20 +325,38 @@ class ApiTimelineUserAction extends ApiBareAuthAction
$activity = new Activity($dom->documentElement); $activity = new Activity($dom->documentElement);
if ($activity->verb != ActivityVerb::POST) { if (Event::handle('StartAtomPubNewActivity', array(&$activity))) {
$this->clientError(_('Can only handle post activities.'));
return;
}
$note = $activity->objects[0]; if ($activity->verb != ActivityVerb::POST) {
$this->clientError(_('Can only handle post activities.'));
return;
}
if (!in_array($note->type, array(ActivityObject::NOTE, $note = $activity->objects[0];
ActivityObject::BLOGENTRY,
ActivityObject::STATUS))) { if (!in_array($note->type, array(ActivityObject::NOTE,
$this->clientError(sprintf(_('Cannot handle activity object type "%s"', ActivityObject::BLOGENTRY,
$note->type))); ActivityObject::STATUS))) {
return; $this->clientError(sprintf(_('Cannot handle activity object type "%s"',
$note->type)));
return;
}
$saved = $this->postNote($activity);
Event::handle('EndAtomPubNewActivity', array($activity, $saved));
}
if (!empty($saved)) {
header("Location: " . common_local_url('ApiStatusesShow', array('notice_id' => $saved->id,
'format' => 'atom')));
$this->showSingleAtomStatus($saved);
} }
}
function postNote($activity)
{
$note = $activity->objects[0];
// Use summary as fallback for content // Use summary as fallback for content
...@@ -458,11 +476,7 @@ class ApiTimelineUserAction extends ApiBareAuthAction ...@@ -458,11 +476,7 @@ class ApiTimelineUserAction extends ApiBareAuthAction
'atompub', // TODO: deal with this 'atompub', // TODO: deal with this
$options); $options);
if (!empty($saved)) { return $saved;
header("Location: " . common_local_url('ApiStatusesShow', array('notice_id' => $saved->id,
'format' => 'atom')));
$this->showSingleAtomStatus($saved);
}
} }
function purify($content) function purify($content)
......
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