- // Get (safe!) HTML and text versions of the content
-
- $rendered = common_purify($sourceContent);
- $content = common_strip_html($rendered);
-
- $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::getKV('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));
- }
- 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 ($activity->context instanceof ActivityContext) {
-
- foreach ($activity->context->attention as $uri=>$type) {
- try {
- $profile = Profile::fromUri($uri);
- if ($profile->isGroup()) {
- $options['groups'][] = $profile->id;
- } else {
- $options['replies'][] = $uri;
- }
- } catch (UnknownUriException $e) {
- 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::getKV('uri',
- $activity->context->replyToID);
- if (!empty($orig)) {
- $options['reply_to'] = $orig->id;
- }
- }
-
- $location = $activity->context->location;
-
- if ($location) {
- $options['lat'] = $location->lat;
- $options['lon'] = $location->lon;
- if ($location->location_id) {
- $options['location_ns'] = $location->location_ns;
- $options['location_id'] = $location->location_id;
- }
- }
- }
-
- // Atom categories <-> hashtags
-
- foreach ($activity->categories as $cat) {
- if ($cat->term) {
- $term = common_canonical_tag($cat->term);
- if ($term) {
- $options['tags'][] = $term;
- }
- }
- }
-
- // Atom enclosures -> attachment URLs
- foreach ($activity->enclosures as $href) {
- // @fixme save these locally or....?
- $options['urls'][] = $href;
- }
-
- $saved = Notice::saveNew($this->target->id,
- $content,
- 'atompub', // TODO: deal with this
- $options);
-
- return $saved;