- $saved = null;
-
- if (Event::handle('StartAtomPubNewActivity', array(&$activity, $this->target->getUser(), &$saved))) {
- if ($activity->verb != ActivityVerb::POST) {
- // TRANS: Client error displayed when not using the POST verb. Do not translate POST.
- $this->clientError(_('Can only handle POST activities.'));
- }
-
- $note = $activity->objects[0];
-
- if (!in_array($note->type, array(ActivityObject::NOTE,
- ActivityObject::BLOGENTRY,
- ActivityObject::STATUS))) {
- // TRANS: Client error displayed when using an unsupported activity object type.
- // TRANS: %s is the unsupported activity object type.
- $this->clientError(sprintf(_('Cannot handle activity object type "%s".'),
- $note->type));
- }
-
- $saved = $this->postNote($activity);
-
- Event::handle('EndAtomPubNewActivity', array($activity, $this->target->getUser(), $saved));
- }
-
- if (!empty($saved)) {
- header('HTTP/1.1 201 Created');
- header("Location: " . common_local_url('ApiStatusesShow', array('id' => $saved->id,
- 'format' => 'atom')));
- $this->showSingleAtomStatus($saved);
- }
- }
-
- function postNote($activity)
- {
- $note = $activity->objects[0];
-
- // Use summary as fallback for content
-
- if (!empty($note->content)) {
- $sourceContent = $note->content;
- } else if (!empty($note->summary)) {
- $sourceContent = $note->summary;
- } else if (!empty($note->title)) {
- $sourceContent = $note->title;
- } else {
- // @fixme fetch from $sourceUrl?
- // TRANS: Client error displayed when posting a notice without content through the API.
- // TRANS: %d is the notice ID (number).
- $this->clientError(sprintf(_('No content for notice %d.'), $note->id));
- }
-
- // Get (safe!) HTML and text versions of the content
-
- $rendered = $this->purify($sourceContent);
- $content = common_strip_html($rendered);
-
- $shortened = $this->auth_user->shortenLinks($content);