- $saved = null;
-
- if (Event::handle('StartAtomPubNewActivity', array(&$activity, $this->user, &$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.'));
- return;
- }
-
- $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));
- return;
- }
-
- $saved = $this->postNote($activity);
-
- Event::handle('EndAtomPubNewActivity', array($activity, $this->user, $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));
- return;
- }
-
- // Get (safe!) HTML and text versions of the content
-
- $rendered = $this->purify($sourceContent);
- $content = html_entity_decode(strip_tags($rendered), ENT_QUOTES, 'UTF-8');
-
- $shortened = $this->auth_user->shortenLinks($content);
-
- $options = array('is_local' => Notice::LOCAL_PUBLIC,
- 'rendered' => $rendered,
- 'replies' => array(),
- 'groups' => array(),
- 'tags' => array(),
- 'urls' => array());
-
- // accept remote URI (not necessarily a good idea)
-
- common_debug("Note ID is {$note->id}");
-
- if (!empty($note->id)) {
- $notice = Notice::staticGet('uri', trim($note->id));
-
- if (!empty($notice)) {
- // TRANS: Client error displayed when using another format than AtomPub.
- // TRANS: %s is the notice URI.
- $this->clientError(sprintf(_('Notice with URI "%s" already exists.'),
- $note->id));
- return;
- }
- common_log(LOG_NOTICE, "Saving client-supplied notice URI '$note->id'");
- $options['uri'] = $note->id;
- }
-
- // accept remote create time (also maybe not such a good idea)
-
- if (!empty($activity->time)) {
- common_log(LOG_NOTICE, "Saving client-supplied create time {$activity->time}");
- $options['created'] = common_sql_date($activity->time);
- }
-
- // Check for optional attributes...
-
- if (!empty($activity->context)) {
-
- foreach ($activity->context->attention as $uri) {
-
- $profile = Profile::fromURI($uri);
-
- if (!empty($profile)) {
- $options['replies'][] = $uri;
- } else {
- $group = User_group::staticGet('uri', $uri);
- if (!empty($group)) {
- $options['groups'][] = $uri;
- } else {
- // @fixme: hook for discovery here
- common_log(LOG_WARNING, sprintf('AtomPub post with unknown attention URI %s', $uri));
- }
- }
- }
-
- // Maintain direct reply associations
- // @fixme what about conversation ID?
-
- if (!empty($activity->context->replyToID)) {
- $orig = Notice::staticGet('uri',
- $activity->context->replyToID);
- if (!empty($orig)) {
- $options['reply_to'] = $orig->id;
- }
- }
-
- $location = $activity->context->location;