+ Event::handle('EndHandleFeedEntryWithProfile', array($activity, $this, $notice));
+ }
+
+ return $notice;
+ }
+
+ public function processShare($activity, $method)
+ {
+ $notice = null;
+
+ $oprofile = $this->checkAuthorship($activity);
+
+ if (empty($oprofile)) {
+ common_log(LOG_INFO, "No author matched share activity");
+ return null;
+ }
+
+ if (count($activity->objects) != 1) {
+ // TRANS: Client exception thrown when trying to share multiple activities at once.
+ throw new ClientException(_m('Can only handle share activities with exactly one object.'));
+ }
+
+ $shared = $activity->objects[0];
+
+ if (!($shared instanceof Activity)) {
+ // TRANS: Client exception thrown when trying to share a non-activity object.
+ throw new ClientException(_m('Can only handle shared activities.'));
+ }
+
+ $other = Ostatus_profile::ensureActivityObjectProfile($shared->actor);
+
+ // Save the item (or check for a dupe)
+
+ $sharedNotice = $other->processActivity($shared, $method);
+
+ if (empty($sharedNotice)) {
+ $sharedId = ($shared->id) ? $shared->id : $shared->objects[0]->id;
+ // TRANS: Client exception thrown when saving an activity share fails.
+ // TRANS: %s is a share ID.
+ throw new ClientException(sprintf(_m('Failed to save activity %s.'),
+ $sharedId));
+ }
+
+ // 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;
+ // tag: URIs for instance are found in Google Buzz feeds.
+
+ $sourceUri = $activity->id;
+
+ $dupe = Notice::getKV('uri', $sourceUri);
+ if ($dupe) {
+ common_log(LOG_INFO, "OStatus: ignoring duplicate post: $sourceUri");
+ return $dupe;
+ }
+
+ // We'll also want to save a web link to the original notice, if provided.
+
+ $sourceUrl = null;
+ if ($activity->link) {
+ $sourceUrl = $activity->link;
+ } else if ($activity->link) {
+ $sourceUrl = $activity->link;
+ } else if (preg_match('!^https?://!', $activity->id)) {
+ $sourceUrl = $activity->id;
+ }
+
+ // Use summary as fallback for content
+
+ if (!empty($activity->content)) {
+ $sourceContent = $activity->content;
+ } else if (!empty($activity->summary)) {
+ $sourceContent = $activity->summary;
+ } else if (!empty($activity->title)) {
+ $sourceContent = $activity->title;
+ } else {
+ // @todo FIXME: Fetch from $sourceUrl?
+ // TRANS: Client exception. %s is a source URI.
+ throw new ClientException(sprintf(_m('No content for notice %s.'),$sourceUri));
+ }
+
+ // 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 = common_shorten_links($content);
+
+ // If it's too long, try using the summary, and make the
+ // HTML an attachment.
+
+ $attachment = null;
+
+ if (Notice::contentTooLong($shortened)) {
+ $attachment = $this->saveHTMLFile($activity->title, $rendered);
+ $summary = html_entity_decode(strip_tags($activity->summary), ENT_QUOTES, 'UTF-8');
+ if (empty($summary)) {
+ $summary = $content;
+ }
+ $shortSummary = common_shorten_links($summary);
+ if (Notice::contentTooLong($shortSummary)) {
+ $url = common_shorten_url($sourceUrl);
+ $shortSummary = substr($shortSummary,
+ 0,
+ Notice::maxContent() - (mb_strlen($url) + 2));
+ $content = $shortSummary . ' ' . $url;
+
+ // We mark up the attachment link specially for the HTML output
+ // so we can fold-out the full version inline.
+
+ // @todo FIXME i18n: This tooltip will be saved with the site's default language
+ // TRANS: Shown when a notice is longer than supported and/or when attachments are present. At runtime
+ // TRANS: this will usually be replaced with localised text from StatusNet core messages.
+ $showMoreText = _m('Show more');
+ $attachUrl = common_local_url('attachment',
+ array('attachment' => $attachment->id));
+ $rendered = common_render_text($shortSummary) .
+ '<a href="' . htmlspecialchars($attachUrl) .'"'.
+ ' class="attachment more"' .
+ ' title="'. htmlspecialchars($showMoreText) . '">' .
+ '…' .
+ '</a>';
+ }