3 * StatusNet - the distributed open-source microblogging tool
4 * Copyright (C) 2009-2010, StatusNet, Inc.
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 if (!defined('STATUSNET')) {
25 * @package OStatusPlugin
26 * @maintainer Brion Vibber <brion@status.net>
28 class Ostatus_profile extends Memcached_DataObject
30 public $__table = 'ostatus_profile';
39 public $avatar; // remote URL of the last avatar we saved
44 public /*static*/ function staticGet($k, $v=null)
46 return parent::staticGet(__CLASS__, $k, $v);
50 * return table definition for DB_DataObject
52 * DB_DataObject needs to know something about the table to manipulate
53 * instances. This method provides all the DB_DataObject needs to know.
55 * @return array array of column definitions
59 return array('uri' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,
60 'profile_id' => DB_DATAOBJECT_INT,
61 'group_id' => DB_DATAOBJECT_INT,
62 'feeduri' => DB_DATAOBJECT_STR,
63 'salmonuri' => DB_DATAOBJECT_STR,
64 'avatar' => DB_DATAOBJECT_STR,
65 'created' => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME + DB_DATAOBJECT_NOTNULL,
66 'modified' => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME + DB_DATAOBJECT_NOTNULL);
69 static function schemaDef()
71 return array(new ColumnDef('uri', 'varchar',
73 new ColumnDef('profile_id', 'integer',
75 new ColumnDef('group_id', 'integer',
77 new ColumnDef('feeduri', 'varchar',
79 new ColumnDef('salmonuri', 'text',
81 new ColumnDef('avatar', 'text',
83 new ColumnDef('created', 'datetime',
85 new ColumnDef('modified', 'datetime',
90 * return key definitions for DB_DataObject
92 * DB_DataObject needs to know about keys that the table has; this function
95 * @return array key definitions
99 return array_keys($this->keyTypes());
103 * return key definitions for Memcached_DataObject
105 * Our caching system uses the same key definitions, but uses a different
106 * method to get them.
108 * @return array key definitions
112 return array('uri' => 'K', 'profile_id' => 'U', 'group_id' => 'U', 'feeduri' => 'U');
115 function sequenceKey()
117 return array(false, false, false);
121 * Fetch the StatusNet-side profile for this feed
124 public function localProfile()
126 if ($this->profile_id) {
127 return Profile::staticGet('id', $this->profile_id);
133 * Fetch the StatusNet-side profile for this feed
136 public function localGroup()
138 if ($this->group_id) {
139 return User_group::staticGet('id', $this->group_id);
145 * Returns an ActivityObject describing this remote user or group profile.
146 * Can then be used to generate Atom chunks.
148 * @return ActivityObject
150 function asActivityObject()
152 if ($this->isGroup()) {
153 return ActivityObject::fromGroup($this->localGroup());
155 return ActivityObject::fromProfile($this->localProfile());
160 * Returns an XML string fragment with profile information as an
161 * Activity Streams noun object with the given element type.
163 * Assumes that 'activity' namespace has been previously defined.
165 * @fixme replace with wrappers on asActivityObject when it's got everything.
167 * @param string $element one of 'actor', 'subject', 'object', 'target'
170 function asActivityNoun($element)
172 if ($this->isGroup()) {
173 $noun = ActivityObject::fromGroup($this->localGroup());
174 return $noun->asString('activity:' . $element);
176 $noun = ActivityObject::fromProfile($this->localProfile());
177 return $noun->asString('activity:' . $element);
182 * @return boolean true if this is a remote group
186 if ($this->profile_id && !$this->group_id) {
188 } else if ($this->group_id && !$this->profile_id) {
190 } else if ($this->group_id && $this->profile_id) {
191 // TRANS: Server exception. %s is a URI.
192 throw new ServerException(sprintf(_m('Invalid ostatus_profile state: both group and profile IDs set for %s.'),$this->uri));
194 // TRANS: Server exception. %s is a URI.
195 throw new ServerException(sprintf(_m('Invalid ostatus_profile state: both group and profile IDs empty for %s.'),$this->uri));
200 * Send a subscription request to the hub for this feed.
201 * The hub will later send us a confirmation POST to /main/push/callback.
203 * @return bool true on success, false on failure
204 * @throws ServerException if feed state is not valid
206 public function subscribe()
208 $feedsub = FeedSub::ensureFeed($this->feeduri);
209 if ($feedsub->sub_state == 'active') {
210 // Active subscription, we don't need to do anything.
213 // Inactive or we got left in an inconsistent state.
214 // Run a subscription request to make sure we're current!
215 return $feedsub->subscribe();
220 * Check if this remote profile has any active local subscriptions, and
221 * if not drop the PuSH subscription feed.
223 * @return bool true on success, false on failure
225 public function unsubscribe() {
226 $this->garbageCollect();
230 * Check if this remote profile has any active local subscriptions, and
231 * if not drop the PuSH subscription feed.
235 public function garbageCollect()
237 $feedsub = FeedSub::staticGet('uri', $this->feeduri);
238 return $feedsub->garbageCollect();
242 * Check if this remote profile has any active local subscriptions, so the
243 * PuSH subscription layer can decide if it can drop the feed.
245 * This gets called via the FeedSubSubscriberCount event when running
246 * FeedSub::garbageCollect().
250 public function subscriberCount()
252 if ($this->isGroup()) {
253 $members = $this->localGroup()->getMembers(0, 1);
254 $count = $members->N;
256 $count = $this->localProfile()->subscriberCount();
258 common_log(LOG_INFO, __METHOD__ . " SUB COUNT BEFORE: $count");
260 // Other plugins may be piggybacking on OStatus without having
261 // an active group or user-to-user subscription we know about.
262 Event::handle('Ostatus_profileSubscriberCount', array($this, &$count));
263 common_log(LOG_INFO, __METHOD__ . " SUB COUNT AFTER: $count");
269 * Send an Activity Streams notification to the remote Salmon endpoint,
272 * @param Profile $actor Actor who did the activity
273 * @param string $verb Activity::SUBSCRIBE or Activity::JOIN
274 * @param Object $object object of the action; must define asActivityNoun($tag)
276 public function notify($actor, $verb, $object=null)
278 if (!($actor instanceof Profile)) {
279 $type = gettype($actor);
280 if ($type == 'object') {
281 $type = get_class($actor);
283 // TRANS: Server exception.
284 // TRANS: %1$s is the method name the exception occured in, %2$s is the actor type.
285 throw new ServerException(sprintf(_m('Invalid actor passed to %1$s: %2$s.'),__METHOD__,$type));
287 if ($object == null) {
290 if ($this->salmonuri) {
293 $id = TagURI::mint('%s:%s:%s',
296 common_date_iso8601(time()));
298 // @fixme consolidate all these NS settings somewhere
299 $attributes = array('xmlns' => Activity::ATOM,
300 'xmlns:activity' => 'http://activitystrea.ms/spec/1.0/',
301 'xmlns:thr' => 'http://purl.org/syndication/thread/1.0',
302 'xmlns:georss' => 'http://www.georss.org/georss',
303 'xmlns:ostatus' => 'http://ostatus.org/schema/1.0',
304 'xmlns:poco' => 'http://portablecontacts.net/spec/1.0',
305 'xmlns:media' => 'http://purl.org/syndication/atommedia');
307 $entry = new XMLStringer();
308 $entry->elementStart('entry', $attributes);
309 $entry->element('id', null, $id);
310 $entry->element('title', null, $text);
311 $entry->element('summary', null, $text);
312 $entry->element('published', null, common_date_w3dtf(common_sql_now()));
314 $entry->element('activity:verb', null, $verb);
315 $entry->raw($actor->asAtomAuthor());
316 $entry->raw($actor->asActivityActor());
317 $entry->raw($object->asActivityNoun('object'));
318 $entry->elementEnd('entry');
320 $xml = $entry->getString();
321 common_log(LOG_INFO, "Posting to Salmon endpoint $this->salmonuri: $xml");
323 $salmon = new Salmon(); // ?
324 return $salmon->post($this->salmonuri, $xml, $actor);
330 * Send a Salmon notification ping immediately, and confirm that we got
331 * an acceptable response from the remote site.
333 * @param mixed $entry XML string, Notice, or Activity
334 * @return boolean success
336 public function notifyActivity($entry, $actor)
338 if ($this->salmonuri) {
339 $salmon = new Salmon();
340 return $salmon->post($this->salmonuri, $this->notifyPrepXml($entry), $actor);
347 * Queue a Salmon notification for later. If queues are disabled we'll
348 * send immediately but won't get the return value.
350 * @param mixed $entry XML string, Notice, or Activity
351 * @return boolean success
353 public function notifyDeferred($entry, $actor)
355 if ($this->salmonuri) {
356 $data = array('salmonuri' => $this->salmonuri,
357 'entry' => $this->notifyPrepXml($entry),
358 'actor' => $actor->id);
360 $qm = QueueManager::get();
361 return $qm->enqueue($data, 'salmon');
367 protected function notifyPrepXml($entry)
369 $preamble = '<?xml version="1.0" encoding="UTF-8" ?' . '>';
370 if (is_string($entry)) {
372 } else if ($entry instanceof Activity) {
373 return $preamble . $entry->asString(true);
374 } else if ($entry instanceof Notice) {
375 return $preamble . $entry->asAtomEntry(true, true);
377 // TRANS: Server exception.
378 throw new ServerException(_m('Invalid type passed to Ostatus_profile::notify. It must be XML string or Activity entry.'));
382 function getBestName()
384 if ($this->isGroup()) {
385 return $this->localGroup()->getBestName();
387 return $this->localProfile()->getBestName();
392 * Read and post notices for updates from the feed.
393 * Currently assumes that all items in the feed are new,
394 * coming from a PuSH hub.
396 * @param DOMDocument $doc
397 * @param string $source identifier ("push")
399 public function processFeed(DOMDocument $doc, $source)
401 $feed = $doc->documentElement;
403 if ($feed->localName == 'feed' && $feed->namespaceURI == Activity::ATOM) {
404 $this->processAtomFeed($feed, $source);
405 } else if ($feed->localName == 'rss') { // @fixme check namespace
406 $this->processRssFeed($feed, $source);
409 throw new Exception(_m('Unknown feed format.'));
413 public function processAtomFeed(DOMElement $feed, $source)
415 $entries = $feed->getElementsByTagNameNS(Activity::ATOM, 'entry');
416 if ($entries->length == 0) {
417 common_log(LOG_ERR, __METHOD__ . ": no entries in feed update, ignoring");
421 for ($i = 0; $i < $entries->length; $i++) {
422 $entry = $entries->item($i);
423 $this->processEntry($entry, $feed, $source);
427 public function processRssFeed(DOMElement $rss, $source)
429 $channels = $rss->getElementsByTagName('channel');
431 if ($channels->length == 0) {
433 throw new Exception(_m('RSS feed without a channel.'));
434 } else if ($channels->length > 1) {
435 common_log(LOG_WARNING, __METHOD__ . ": more than one channel in an RSS feed");
438 $channel = $channels->item(0);
440 $items = $channel->getElementsByTagName('item');
442 for ($i = 0; $i < $items->length; $i++) {
443 $item = $items->item($i);
444 $this->processEntry($item, $channel, $source);
449 * Process a posted entry from this feed source.
451 * @param DOMElement $entry
452 * @param DOMElement $feed for context
453 * @param string $source identifier ("push" or "salmon")
456 public function processEntry($entry, $feed, $source)
458 $activity = new Activity($entry, $feed);
460 if (Event::handle('StartHandleFeedEntry', array($activity))) {
462 // @todo process all activity objects
463 switch ($activity->objects[0]->type) {
464 case ActivityObject::ARTICLE:
465 case ActivityObject::BLOGENTRY:
466 case ActivityObject::NOTE:
467 case ActivityObject::STATUS:
468 case ActivityObject::COMMENT:
470 if ($activity->verb == ActivityVerb::POST) {
471 $this->processPost($activity, $source);
473 common_log(LOG_INFO, "Ignoring activity with unrecognized verb $activity->verb");
477 // TRANS: Client exception.
478 throw new ClientException(_m('Can\'t handle that kind of post.'));
481 Event::handle('EndHandleFeedEntry', array($activity));
486 * Process an incoming post activity from this remote feed.
487 * @param Activity $activity
488 * @param string $method 'push' or 'salmon'
489 * @return mixed saved Notice or false
490 * @fixme break up this function, it's getting nasty long
492 public function processPost($activity, $method)
494 if ($this->isGroup()) {
495 // A group feed will contain posts from multiple authors.
496 // @fixme validate these profiles in some way!
497 $oprofile = self::ensureActorProfile($activity);
498 if ($oprofile->isGroup()) {
499 // Groups can't post notices in StatusNet.
500 common_log(LOG_WARNING, "OStatus: skipping post with group listed as author: $oprofile->uri in feed from $this->uri");
504 $actor = $activity->actor;
507 // OK here! assume the default
508 } else if ($actor->id == $this->uri || $actor->link == $this->uri) {
509 $this->updateFromActivityObject($actor);
510 } else if ($actor->id) {
511 // We have an ActivityStreams actor with an explicit ID that doesn't match the feed owner.
512 // This isn't what we expect from mainline OStatus person feeds!
513 // Group feeds go down another path, with different validation...
514 // Most likely this is a plain ol' blog feed of some kind which
515 // doesn't match our expectations. We'll take the entry, but ignore
516 // the <author> info.
517 common_log(LOG_WARNING, "Got an actor '{$actor->title}' ({$actor->id}) on single-user feed for {$this->uri}");
519 // Plain <author> without ActivityStreams actor info.
520 // We'll just ignore this info for now and save the update under the feed's identity.
526 // It's not always an ActivityObject::NOTE, but... let's just say it is.
528 $note = $activity->objects[0];
530 // The id URI will be used as a unique identifier for for the notice,
531 // protecting against duplicate saves. It isn't required to be a URL;
532 // tag: URIs for instance are found in Google Buzz feeds.
533 $sourceUri = $note->id;
534 $dupe = Notice::staticGet('uri', $sourceUri);
536 common_log(LOG_INFO, "OStatus: ignoring duplicate post: $sourceUri");
540 // We'll also want to save a web link to the original notice, if provided.
543 $sourceUrl = $note->link;
544 } else if ($activity->link) {
545 $sourceUrl = $activity->link;
546 } else if (preg_match('!^https?://!', $note->id)) {
547 $sourceUrl = $note->id;
550 // Use summary as fallback for content
552 if (!empty($note->content)) {
553 $sourceContent = $note->content;
554 } else if (!empty($note->summary)) {
555 $sourceContent = $note->summary;
556 } else if (!empty($note->title)) {
557 $sourceContent = $note->title;
559 // @fixme fetch from $sourceUrl?
560 // TRANS: Client exception. %s is a source URI.
561 throw new ClientException(sprintf(_m('No content for notice %s.'),$sourceUri));
564 // Get (safe!) HTML and text versions of the content
566 $rendered = $this->purify($sourceContent);
567 $content = html_entity_decode(strip_tags($rendered), ENT_QUOTES, 'UTF-8');
569 $shortened = common_shorten_links($content);
571 // If it's too long, try using the summary, and make the
572 // HTML an attachment.
576 if (Notice::contentTooLong($shortened)) {
577 $attachment = $this->saveHTMLFile($note->title, $rendered);
578 $summary = html_entity_decode(strip_tags($note->summary), ENT_QUOTES, 'UTF-8');
579 if (empty($summary)) {
582 $shortSummary = common_shorten_links($summary);
583 if (Notice::contentTooLong($shortSummary)) {
584 $url = common_shorten_url($sourceUrl);
585 $shortSummary = substr($shortSummary,
587 Notice::maxContent() - (mb_strlen($url) + 2));
588 $content = $shortSummary . ' ' . $url;
590 // We mark up the attachment link specially for the HTML output
591 // so we can fold-out the full version inline.
593 // @fixme I18N this tooltip will be saved with the site's default language
594 // TRANS: Shown when a notice is longer than supported and/or when attachments are present. At runtime
595 // TRANS: this will usually be replaced with localised text from StatusNet core messages.
596 $showMoreText = _m('Show more');
597 $attachUrl = common_local_url('attachment',
598 array('attachment' => $attachment->id));
599 $rendered = common_render_text($shortSummary) .
600 '<a href="' . htmlspecialchars($attachUrl) .'"'.
601 ' class="attachment more"' .
602 ' title="'. htmlspecialchars($showMoreText) . '">' .
608 $options = array('is_local' => Notice::REMOTE_OMB,
611 'rendered' => $rendered,
612 'replies' => array(),
617 // Check for optional attributes...
619 if (!empty($activity->time)) {
620 $options['created'] = common_sql_date($activity->time);
623 if ($activity->context) {
624 // Any individual or group attn: targets?
625 $replies = $activity->context->attention;
626 $options['groups'] = $this->filterReplies($oprofile, $replies);
627 $options['replies'] = $replies;
629 // Maintain direct reply associations
630 // @fixme what about conversation ID?
631 if (!empty($activity->context->replyToID)) {
632 $orig = Notice::staticGet('uri',
633 $activity->context->replyToID);
635 $options['reply_to'] = $orig->id;
639 $location = $activity->context->location;
641 $options['lat'] = $location->lat;
642 $options['lon'] = $location->lon;
643 if ($location->location_id) {
644 $options['location_ns'] = $location->location_ns;
645 $options['location_id'] = $location->location_id;
650 // Atom categories <-> hashtags
651 foreach ($activity->categories as $cat) {
653 $term = common_canonical_tag($cat->term);
655 $options['tags'][] = $term;
660 // Atom enclosures -> attachment URLs
661 foreach ($activity->enclosures as $href) {
662 // @fixme save these locally or....?
663 $options['urls'][] = $href;
667 $saved = Notice::saveNew($oprofile->profile_id,
672 Ostatus_source::saveNew($saved, $this, $method);
673 if (!empty($attachment)) {
674 File_to_post::processNew($attachment->id, $saved->id);
677 } catch (Exception $e) {
678 common_log(LOG_ERR, "OStatus save of remote message $sourceUri failed: " . $e->getMessage());
681 common_log(LOG_INFO, "OStatus saved remote message $sourceUri as notice id $saved->id");
688 protected function purify($html)
690 require_once INSTALLDIR.'/extlib/htmLawed/htmLawed.php';
691 $config = array('safe' => 1,
692 'deny_attribute' => 'id,style,on*');
693 return htmLawed($html, $config);
697 * Filters a list of recipient ID URIs to just those for local delivery.
698 * @param Ostatus_profile local profile of sender
699 * @param array in/out &$attention_uris set of URIs, will be pruned on output
700 * @return array of group IDs
702 protected function filterReplies($sender, &$attention_uris)
704 common_log(LOG_DEBUG, "Original reply recipients: " . implode(', ', $attention_uris));
707 foreach (array_unique($attention_uris) as $recipient) {
708 // Is the recipient a local user?
709 $user = User::staticGet('uri', $recipient);
711 // @fixme sender verification, spam etc?
712 $replies[] = $recipient;
716 // Is the recipient a local group?
717 // $group = User_group::staticGet('uri', $recipient);
718 $id = OStatusPlugin::localGroupFromUrl($recipient);
720 $group = User_group::staticGet('id', $id);
722 // Deliver to all members of this local group if allowed.
723 $profile = $sender->localProfile();
724 if ($profile->isMember($group)) {
725 $groups[] = $group->id;
727 common_log(LOG_DEBUG, "Skipping reply to local group $group->nickname as sender $profile->id is not a member");
731 common_log(LOG_DEBUG, "Skipping reply to bogus group $recipient");
735 // Is the recipient a remote user or group?
737 $oprofile = Ostatus_profile::ensureProfileURI($recipient);
738 if ($oprofile->isGroup()) {
739 // Deliver to local members of this remote group.
740 // @fixme sender verification?
741 $groups[] = $oprofile->group_id;
743 // may be canonicalized or something
744 $replies[] = $oprofile->uri;
747 } catch (Exception $e) {
748 // Neither a recognizable local nor remote user!
749 common_log(LOG_DEBUG, "Skipping reply to unrecognized profile $recipient: " . $e->getMessage());
753 $attention_uris = $replies;
754 common_log(LOG_DEBUG, "Local reply recipients: " . implode(', ', $replies));
755 common_log(LOG_DEBUG, "Local group recipients: " . implode(', ', $groups));
760 * Look up and if necessary create an Ostatus_profile for the remote entity
761 * with the given profile page URL. This should never return null -- you
762 * will either get an object or an exception will be thrown.
764 * @param string $profile_url
765 * @return Ostatus_profile
766 * @throws Exception on various error conditions
767 * @throws OStatusShadowException if this reference would obscure a local user/group
770 public static function ensureProfileURL($profile_url, $hints=array())
772 $oprofile = self::getFromProfileURL($profile_url);
774 if (!empty($oprofile)) {
778 $hints['profileurl'] = $profile_url;
783 $client = new HTTPClient();
784 $client->setHeader('Accept', 'text/html,application/xhtml+xml');
785 $response = $client->get($profile_url);
787 if (!$response->isOk()) {
788 // TRANS: Exception. %s is a profile URL.
789 throw new Exception(sprintf(_m('Could not reach profile page %s.'),$profile_url));
792 // Check if we have a non-canonical URL
794 $finalUrl = $response->getUrl();
796 if ($finalUrl != $profile_url) {
798 $hints['profileurl'] = $finalUrl;
800 $oprofile = self::getFromProfileURL($finalUrl);
802 if (!empty($oprofile)) {
807 // Try to get some hCard data
809 $body = $response->getBody();
811 $hcardHints = DiscoveryHints::hcardHints($body, $finalUrl);
813 if (!empty($hcardHints)) {
814 $hints = array_merge($hints, $hcardHints);
817 // Check if they've got an LRDD header
819 $lrdd = LinkHeader::getLink($response, 'lrdd', 'application/xrd+xml');
823 $xrd = Discovery::fetchXrd($lrdd);
824 $xrdHints = DiscoveryHints::fromXRD($xrd);
826 $hints = array_merge($hints, $xrdHints);
829 // If discovery found a feedurl (probably from LRDD), use it.
831 if (array_key_exists('feedurl', $hints)) {
832 return self::ensureFeedURL($hints['feedurl'], $hints);
835 // Get the feed URL from HTML
837 $discover = new FeedDiscovery();
839 $feedurl = $discover->discoverFromHTML($finalUrl, $body);
841 if (!empty($feedurl)) {
842 $hints['feedurl'] = $feedurl;
843 return self::ensureFeedURL($feedurl, $hints);
846 // TRANS: Exception. %s is a URL.
847 throw new Exception(sprintf(_m('Could not find a feed URL for profile page %s.'),$finalUrl));
851 * Look up the Ostatus_profile, if present, for a remote entity with the
852 * given profile page URL. Will return null for both unknown and invalid
855 * @return mixed Ostatus_profile or null
856 * @throws OStatusShadowException for local profiles
858 static function getFromProfileURL($profile_url)
860 $profile = Profile::staticGet('profileurl', $profile_url);
862 if (empty($profile)) {
866 // Is it a known Ostatus profile?
868 $oprofile = Ostatus_profile::staticGet('profile_id', $profile->id);
870 if (!empty($oprofile)) {
874 // Is it a local user?
876 $user = User::staticGet('id', $profile->id);
879 // @todo i18n FIXME: use sprintf and add i18n (?)
880 throw new OStatusShadowException($profile, "'$profile_url' is the profile for local user '{$user->nickname}'.");
883 // Continue discovery; it's a remote profile
884 // for OMB or some other protocol, may also
891 * Look up and if necessary create an Ostatus_profile for remote entity
892 * with the given update feed. This should never return null -- you will
893 * either get an object or an exception will be thrown.
895 * @return Ostatus_profile
898 public static function ensureFeedURL($feed_url, $hints=array())
900 $discover = new FeedDiscovery();
902 $feeduri = $discover->discoverFromFeedURL($feed_url);
903 $hints['feedurl'] = $feeduri;
905 $huburi = $discover->getHubLink();
906 $hints['hub'] = $huburi;
907 $salmonuri = $discover->getAtomLink(Salmon::NS_REPLIES);
908 $hints['salmon'] = $salmonuri;
910 if (!$huburi && !common_config('feedsub', 'fallback_hub')) {
911 // We can only deal with folks with a PuSH hub
912 throw new FeedSubNoHubException();
915 $feedEl = $discover->root;
917 if ($feedEl->tagName == 'feed') {
918 return self::ensureAtomFeed($feedEl, $hints);
919 } else if ($feedEl->tagName == 'channel') {
920 return self::ensureRssChannel($feedEl, $hints);
922 throw new FeedSubBadXmlException($feeduri);
927 * Look up and, if necessary, create an Ostatus_profile for the remote
928 * profile with the given Atom feed - actually loaded from the feed.
929 * This should never return null -- you will either get an object or
930 * an exception will be thrown.
932 * @param DOMElement $feedEl root element of a loaded Atom feed
933 * @param array $hints additional discovery information passed from higher levels
934 * @fixme should this be marked public?
935 * @return Ostatus_profile
939 public static function ensureAtomFeed($feedEl, $hints)
941 $author = ActivityUtils::getFeedAuthor($feedEl);
943 if (empty($author)) {
944 // XXX: make some educated guesses here
945 // TRANS: Feed sub exception.
946 throw new FeedSubException(_m('Can\'t find enough profile '.
947 'information to make a feed.'));
950 return self::ensureActivityObjectProfile($author, $hints);
954 * Look up and, if necessary, create an Ostatus_profile for the remote
955 * profile with the given RSS feed - actually loaded from the feed.
956 * This should never return null -- you will either get an object or
957 * an exception will be thrown.
959 * @param DOMElement $feedEl root element of a loaded RSS feed
960 * @param array $hints additional discovery information passed from higher levels
961 * @fixme should this be marked public?
962 * @return Ostatus_profile
965 public static function ensureRssChannel($feedEl, $hints)
967 // Special-case for Posterous. They have some nice metadata in their
968 // posterous:author elements. We should use them instead of the channel.
970 $items = $feedEl->getElementsByTagName('item');
972 if ($items->length > 0) {
973 $item = $items->item(0);
974 $authorEl = ActivityUtils::child($item, ActivityObject::AUTHOR, ActivityObject::POSTEROUS);
975 if (!empty($authorEl)) {
976 $obj = ActivityObject::fromPosterousAuthor($authorEl);
977 // Posterous has multiple authors per feed, and multiple feeds
978 // per author. We check if this is the "main" feed for this author.
979 if (array_key_exists('profileurl', $hints) &&
980 !empty($obj->poco) &&
981 common_url_to_nickname($hints['profileurl']) == $obj->poco->preferredUsername) {
982 return self::ensureActivityObjectProfile($obj, $hints);
987 // @fixme we should check whether this feed has elements
988 // with different <author> or <dc:creator> elements, and... I dunno.
989 // Do something about that.
991 $obj = ActivityObject::fromRssChannel($feedEl);
993 return self::ensureActivityObjectProfile($obj, $hints);
997 * Download and update given avatar image
1000 * @throws Exception in various failure cases
1002 protected function updateAvatar($url)
1004 if ($url == $this->avatar) {
1005 // We've already got this one.
1008 if (!common_valid_http_url($url)) {
1009 // TRANS: Server exception. %s is a URL.
1010 throw new ServerException(sprintf(_m("Invalid avatar URL %s."), $url));
1013 if ($this->isGroup()) {
1014 $self = $this->localGroup();
1016 $self = $this->localProfile();
1019 throw new ServerException(sprintf(
1020 // TRANS: Server exception. %s is a URI.
1021 _m("Tried to update avatar for unsaved remote profile %s."),
1025 // @fixme this should be better encapsulated
1026 // ripped from oauthstore.php (for old OMB client)
1027 $temp_filename = tempnam(sys_get_temp_dir(), 'listener_avatar');
1029 if (!copy($url, $temp_filename)) {
1030 // TRANS: Server exception. %s is a URL.
1031 throw new ServerException(sprintf(_m("Unable to fetch avatar from %s."), $url));
1034 if ($this->isGroup()) {
1035 $id = $this->group_id;
1037 $id = $this->profile_id;
1039 // @fixme should we be using different ids?
1040 $imagefile = new ImageFile($id, $temp_filename);
1041 $filename = Avatar::filename($id,
1042 image_type_to_extension($imagefile->type),
1044 common_timestamp());
1045 rename($temp_filename, Avatar::path($filename));
1046 } catch (Exception $e) {
1047 unlink($temp_filename);
1050 // @fixme hardcoded chmod is lame, but seems to be necessary to
1051 // keep from accidentally saving images from command-line (queues)
1052 // that can't be read from web server, which causes hard-to-notice
1053 // problems later on:
1055 // http://status.net/open-source/issues/2663
1056 chmod(Avatar::path($filename), 0644);
1058 $self->setOriginal($filename);
1060 $orig = clone($this);
1061 $this->avatar = $url;
1062 $this->update($orig);
1066 * Pull avatar URL from ActivityObject or profile hints
1068 * @param ActivityObject $object
1069 * @param array $hints
1070 * @return mixed URL string or false
1073 public static function getActivityObjectAvatar($object, $hints=array())
1075 if ($object->avatarLinks) {
1077 // Take the exact-size avatar, or the largest avatar, or the first avatar if all sizeless
1078 foreach ($object->avatarLinks as $avatar) {
1079 if ($avatar->width == AVATAR_PROFILE_SIZE && $avatar->height = AVATAR_PROFILE_SIZE) {
1084 if (!$best || $avatar->width > $best->width) {
1089 } else if (array_key_exists('avatar', $hints)) {
1090 return $hints['avatar'];
1096 * Get an appropriate avatar image source URL, if available.
1098 * @param ActivityObject $actor
1099 * @param DOMElement $feed
1103 protected static function getAvatar($actor, $feed)
1107 if ($actor->avatar) {
1108 $url = trim($actor->avatar);
1111 // Check <atom:logo> and <atom:icon> on the feed
1112 $els = $feed->childNodes();
1113 if ($els && $els->length) {
1114 for ($i = 0; $i < $els->length; $i++) {
1115 $el = $els->item($i);
1116 if ($el->namespaceURI == Activity::ATOM) {
1117 if (empty($url) && $el->localName == 'logo') {
1118 $url = trim($el->textContent);
1121 if (empty($icon) && $el->localName == 'icon') {
1122 // Use as a fallback
1123 $icon = trim($el->textContent);
1128 if ($icon && !$url) {
1133 $opts = array('allowed_schemes' => array('http', 'https'));
1134 if (Validate::uri($url, $opts)) {
1138 return common_path('plugins/OStatus/images/96px-Feed-icon.svg.png');
1142 * Fetch, or build if necessary, an Ostatus_profile for the actor
1143 * in a given Activity Streams activity.
1144 * This should never return null -- you will either get an object or
1145 * an exception will be thrown.
1147 * @param Activity $activity
1148 * @param string $feeduri if we already know the canonical feed URI!
1149 * @param string $salmonuri if we already know the salmon return channel URI
1150 * @return Ostatus_profile
1154 public static function ensureActorProfile($activity, $hints=array())
1156 return self::ensureActivityObjectProfile($activity->actor, $hints);
1160 * Fetch, or build if necessary, an Ostatus_profile for the profile
1161 * in a given Activity Streams object (can be subject, actor, or object).
1162 * This should never return null -- you will either get an object or
1163 * an exception will be thrown.
1165 * @param ActivityObject $object
1166 * @param array $hints additional discovery information passed from higher levels
1167 * @return Ostatus_profile
1171 public static function ensureActivityObjectProfile($object, $hints=array())
1173 $profile = self::getActivityObjectProfile($object);
1175 $profile->updateFromActivityObject($object, $hints);
1177 $profile = self::createActivityObjectProfile($object, $hints);
1183 * @param Activity $activity
1184 * @return mixed matching Ostatus_profile or false if none known
1185 * @throws ServerException if feed info invalid
1187 public static function getActorProfile($activity)
1189 return self::getActivityObjectProfile($activity->actor);
1193 * @param ActivityObject $activity
1194 * @return mixed matching Ostatus_profile or false if none known
1195 * @throws ServerException if feed info invalid
1197 protected static function getActivityObjectProfile($object)
1199 $uri = self::getActivityObjectProfileURI($object);
1200 return Ostatus_profile::staticGet('uri', $uri);
1204 * Get the identifier URI for the remote entity described
1205 * by this ActivityObject. This URI is *not* guaranteed to be
1206 * a resolvable HTTP/HTTPS URL.
1208 * @param ActivityObject $object
1210 * @throws ServerException if feed info invalid
1212 protected static function getActivityObjectProfileURI($object)
1215 if (ActivityUtils::validateUri($object->id)) {
1220 // If the id is missing or invalid (we've seen feeds mistakenly listing
1221 // things like local usernames in that field) then we'll use the profile
1222 // page link, if valid.
1223 if ($object->link && common_valid_http_url($object->link)) {
1224 return $object->link;
1226 throw new ServerException("No author ID URI found.");
1230 * @fixme validate stuff somewhere
1234 * Create local ostatus_profile and profile/user_group entries for
1235 * the provided remote user or group.
1236 * This should never return null -- you will either get an object or
1237 * an exception will be thrown.
1239 * @param ActivityObject $object
1240 * @param array $hints
1242 * @return Ostatus_profile
1244 protected static function createActivityObjectProfile($object, $hints=array())
1246 $homeuri = $object->id;
1250 common_log(LOG_DEBUG, __METHOD__ . " empty actor profile URI: " . var_export($activity, true));
1251 throw new Exception("No profile URI");
1254 $user = User::staticGet('uri', $homeuri);
1256 // TRANS: Exception.
1257 throw new Exception(_m('Local user can\'t be referenced as remote.'));
1260 if (OStatusPlugin::localGroupFromUrl($homeuri)) {
1261 // TRANS: Exception.
1262 throw new Exception(_m('Local group can\'t be referenced as remote.'));
1265 if (array_key_exists('feedurl', $hints)) {
1266 $feeduri = $hints['feedurl'];
1268 $discover = new FeedDiscovery();
1269 $feeduri = $discover->discoverFromURL($homeuri);
1272 if (array_key_exists('salmon', $hints)) {
1273 $salmonuri = $hints['salmon'];
1276 $discover = new FeedDiscovery();
1277 $discover->discoverFromFeedURL($hints['feedurl']);
1279 $salmonuri = $discover->getAtomLink(Salmon::NS_REPLIES);
1282 if (array_key_exists('hub', $hints)) {
1283 $huburi = $hints['hub'];
1286 $discover = new FeedDiscovery();
1287 $discover->discoverFromFeedURL($hints['feedurl']);
1289 $huburi = $discover->getHubLink();
1292 if (!$huburi && !common_config('feedsub', 'fallback_hub')) {
1293 // We can only deal with folks with a PuSH hub
1294 throw new FeedSubNoHubException();
1297 $oprofile = new Ostatus_profile();
1299 $oprofile->uri = $homeuri;
1300 $oprofile->feeduri = $feeduri;
1301 $oprofile->salmonuri = $salmonuri;
1303 $oprofile->created = common_sql_now();
1304 $oprofile->modified = common_sql_now();
1306 if ($object->type == ActivityObject::PERSON) {
1307 $profile = new Profile();
1308 $profile->created = common_sql_now();
1309 self::updateProfile($profile, $object, $hints);
1311 $oprofile->profile_id = $profile->insert();
1312 if (!$oprofile->profile_id) {
1313 // TRANS: Server exception.
1314 throw new ServerException(_m('Can\'t save local profile.'));
1317 $group = new User_group();
1318 $group->uri = $homeuri;
1319 $group->created = common_sql_now();
1320 self::updateGroup($group, $object, $hints);
1322 $oprofile->group_id = $group->insert();
1323 if (!$oprofile->group_id) {
1324 // TRANS: Server exception.
1325 throw new ServerException(_m('Can\'t save local profile.'));
1329 $ok = $oprofile->insert();
1332 // TRANS: Server exception.
1333 throw new ServerException(_m('Can\'t save OStatus profile.'));
1336 $avatar = self::getActivityObjectAvatar($object, $hints);
1340 $oprofile->updateAvatar($avatar);
1341 } catch (Exception $ex) {
1342 // Profile is saved, but Avatar is messed up. We're
1343 // just going to continue.
1344 common_log(LOG_WARNING, "Exception saving OStatus profile avatar: ". $ex->getMessage());
1352 * Save any updated profile information to our local copy.
1353 * @param ActivityObject $object
1354 * @param array $hints
1356 public function updateFromActivityObject($object, $hints=array())
1358 if ($this->isGroup()) {
1359 $group = $this->localGroup();
1360 self::updateGroup($group, $object, $hints);
1362 $profile = $this->localProfile();
1363 self::updateProfile($profile, $object, $hints);
1365 $avatar = self::getActivityObjectAvatar($object, $hints);
1368 $this->updateAvatar($avatar);
1369 } catch (Exception $ex) {
1370 common_log(LOG_WARNING, "Exception saving OStatus profile avatar: " . $ex->getMessage());
1375 public static function updateProfile($profile, $object, $hints=array())
1377 $orig = clone($profile);
1379 $profile->nickname = self::getActivityObjectNickname($object, $hints);
1381 if (!empty($object->title)) {
1382 $profile->fullname = $object->title;
1383 } else if (array_key_exists('fullname', $hints)) {
1384 $profile->fullname = $hints['fullname'];
1387 if (!empty($object->link)) {
1388 $profile->profileurl = $object->link;
1389 } else if (array_key_exists('profileurl', $hints)) {
1390 $profile->profileurl = $hints['profileurl'];
1391 } else if (Validate::uri($object->id, array('allowed_schemes' => array('http', 'https')))) {
1392 $profile->profileurl = $object->id;
1395 $profile->bio = self::getActivityObjectBio($object, $hints);
1396 $profile->location = self::getActivityObjectLocation($object, $hints);
1397 $profile->homepage = self::getActivityObjectHomepage($object, $hints);
1399 if (!empty($object->geopoint)) {
1400 $location = ActivityContext::locationFromPoint($object->geopoint);
1401 if (!empty($location)) {
1402 $profile->lat = $location->lat;
1403 $profile->lon = $location->lon;
1407 // @fixme tags/categories
1408 // @todo tags from categories
1411 common_log(LOG_DEBUG, "Updating OStatus profile $profile->id from remote info $object->id: " . var_export($object, true) . var_export($hints, true));
1412 $profile->update($orig);
1416 protected static function updateGroup($group, $object, $hints=array())
1418 $orig = clone($group);
1420 $group->nickname = self::getActivityObjectNickname($object, $hints);
1421 $group->fullname = $object->title;
1423 if (!empty($object->link)) {
1424 $group->mainpage = $object->link;
1425 } else if (array_key_exists('profileurl', $hints)) {
1426 $group->mainpage = $hints['profileurl'];
1429 // @todo tags from categories
1430 $group->description = self::getActivityObjectBio($object, $hints);
1431 $group->location = self::getActivityObjectLocation($object, $hints);
1432 $group->homepage = self::getActivityObjectHomepage($object, $hints);
1435 common_log(LOG_DEBUG, "Updating OStatus group $group->id from remote info $object->id: " . var_export($object, true) . var_export($hints, true));
1436 $group->update($orig);
1440 protected static function getActivityObjectHomepage($object, $hints=array())
1443 $poco = $object->poco;
1445 if (!empty($poco)) {
1446 $url = $poco->getPrimaryURL();
1447 if ($url && $url->type == 'homepage') {
1448 $homepage = $url->value;
1452 // @todo Try for a another PoCo URL?
1457 protected static function getActivityObjectLocation($object, $hints=array())
1461 if (!empty($object->poco) &&
1462 isset($object->poco->address->formatted)) {
1463 $location = $object->poco->address->formatted;
1464 } else if (array_key_exists('location', $hints)) {
1465 $location = $hints['location'];
1468 if (!empty($location)) {
1469 if (mb_strlen($location) > 255) {
1470 $location = mb_substr($note, 0, 255 - 3) . ' … ';
1474 // @todo Try to find location some othe way? Via goerss point?
1479 protected static function getActivityObjectBio($object, $hints=array())
1483 if (!empty($object->poco)) {
1484 $note = $object->poco->note;
1485 } else if (array_key_exists('bio', $hints)) {
1486 $note = $hints['bio'];
1489 if (!empty($note)) {
1490 if (Profile::bioTooLong($note)) {
1491 // XXX: truncate ok?
1492 $bio = mb_substr($note, 0, Profile::maxBio() - 3) . ' … ';
1498 // @todo Try to get bio info some other way?
1503 public static function getActivityObjectNickname($object, $hints=array())
1505 if ($object->poco) {
1506 if (!empty($object->poco->preferredUsername)) {
1507 return common_nicknamize($object->poco->preferredUsername);
1511 if (!empty($object->nickname)) {
1512 return common_nicknamize($object->nickname);
1515 if (array_key_exists('nickname', $hints)) {
1516 return $hints['nickname'];
1519 // Try the profile url (like foo.example.com or example.com/user/foo)
1520 if (!empty($object->link)) {
1521 $profileUrl = $object->link;
1522 } else if (!empty($hints['profileurl'])) {
1523 $profileUrl = $hints['profileurl'];
1526 if (!empty($profileUrl)) {
1527 $nickname = self::nicknameFromURI($profileUrl);
1530 // Try the URI (may be a tag:, http:, acct:, ...
1532 if (empty($nickname)) {
1533 $nickname = self::nicknameFromURI($object->id);
1536 // Try a Webfinger if one was passed (way) down
1538 if (empty($nickname)) {
1539 if (array_key_exists('webfinger', $hints)) {
1540 $nickname = self::nicknameFromURI($hints['webfinger']);
1546 if (empty($nickname)) {
1547 $nickname = common_nicknamize($object->title);
1553 protected static function nicknameFromURI($uri)
1555 if (preg_match('/(\w+):/', $uri, $matches)) {
1556 $protocol = $matches[1];
1561 switch ($protocol) {
1564 if (preg_match("/^$protocol:(.*)?@.*\$/", $uri, $matches)) {
1565 return common_canonical_nickname($matches[1]);
1569 return common_url_to_nickname($uri);
1577 * Look up, and if necessary create, an Ostatus_profile for the remote
1578 * entity with the given webfinger address.
1579 * This should never return null -- you will either get an object or
1580 * an exception will be thrown.
1582 * @param string $addr webfinger address
1583 * @return Ostatus_profile
1584 * @throws Exception on error conditions
1585 * @throws OStatusShadowException if this reference would obscure a local user/group
1587 public static function ensureWebfinger($addr)
1589 // First, try the cache
1591 $uri = self::cacheGet(sprintf('ostatus_profile:webfinger:%s', $addr));
1593 if ($uri !== false) {
1594 if (is_null($uri)) {
1595 // Negative cache entry
1596 // TRANS: Exception.
1597 throw new Exception(_m('Not a valid webfinger address.'));
1599 $oprofile = Ostatus_profile::staticGet('uri', $uri);
1600 if (!empty($oprofile)) {
1605 // Try looking it up
1607 $oprofile = Ostatus_profile::staticGet('uri', 'acct:'.$addr);
1609 if (!empty($oprofile)) {
1610 self::cacheSet(sprintf('ostatus_profile:webfinger:%s', $addr), $oprofile->uri);
1614 // Now, try some discovery
1616 $disco = new Discovery();
1619 $xrd = $disco->lookup($addr);
1620 } catch (Exception $e) {
1621 // Save negative cache entry so we don't waste time looking it up again.
1622 // @fixme distinguish temporary failures?
1623 self::cacheSet(sprintf('ostatus_profile:webfinger:%s', $addr), null);
1624 // TRANS: Exception.
1625 throw new Exception(_m('Not a valid webfinger address.'));
1628 $hints = array('webfinger' => $addr);
1630 $dhints = DiscoveryHints::fromXRD($xrd);
1632 $hints = array_merge($hints, $dhints);
1634 // If there's an Hcard, let's grab its info
1636 if (array_key_exists('hcard', $hints)) {
1637 if (!array_key_exists('profileurl', $hints) ||
1638 $hints['hcard'] != $hints['profileurl']) {
1639 $hcardHints = DiscoveryHints::fromHcardUrl($hints['hcard']);
1640 $hints = array_merge($hcardHints, $hints);
1644 // If we got a feed URL, try that
1646 if (array_key_exists('feedurl', $hints)) {
1648 common_log(LOG_INFO, "Discovery on acct:$addr with feed URL " . $hints['feedurl']);
1649 $oprofile = self::ensureFeedURL($hints['feedurl'], $hints);
1650 self::cacheSet(sprintf('ostatus_profile:webfinger:%s', $addr), $oprofile->uri);
1652 } catch (Exception $e) {
1653 common_log(LOG_WARNING, "Failed creating profile from feed URL '$feedUrl': " . $e->getMessage());
1658 // If we got a profile page, try that!
1660 if (array_key_exists('profileurl', $hints)) {
1662 common_log(LOG_INFO, "Discovery on acct:$addr with profile URL $profileUrl");
1663 $oprofile = self::ensureProfileURL($hints['profileurl'], $hints);
1664 self::cacheSet(sprintf('ostatus_profile:webfinger:%s', $addr), $oprofile->uri);
1666 } catch (OStatusShadowException $e) {
1667 // We've ended up with a remote reference to a local user or group.
1668 // @fixme ideally we should be able to say who it was so we can
1669 // go back and refer to it the regular way
1671 } catch (Exception $e) {
1672 common_log(LOG_WARNING, "Failed creating profile from profile URL '$profileUrl': " . $e->getMessage());
1675 // @fixme this means an error discovering from profile page
1676 // may give us a corrupt entry using the webfinger URI, which
1677 // will obscure the correct page-keyed profile later on.
1684 if (array_key_exists('salmon', $hints)) {
1686 $salmonEndpoint = $hints['salmon'];
1688 // An account URL, a salmon endpoint, and a dream? Not much to go
1689 // on, but let's give it a try
1691 $uri = 'acct:'.$addr;
1693 $profile = new Profile();
1695 $profile->nickname = self::nicknameFromUri($uri);
1696 $profile->created = common_sql_now();
1698 if (isset($profileUrl)) {
1699 $profile->profileurl = $profileUrl;
1702 $profile_id = $profile->insert();
1705 common_log_db_error($profile, 'INSERT', __FILE__);
1706 // TRANS: Exception. %s is a webfinger address.
1707 throw new Exception(sprintf(_m('Couldn\'t save profile for "%s".'),$addr));
1710 $oprofile = new Ostatus_profile();
1712 $oprofile->uri = $uri;
1713 $oprofile->salmonuri = $salmonEndpoint;
1714 $oprofile->profile_id = $profile_id;
1715 $oprofile->created = common_sql_now();
1717 if (isset($feedUrl)) {
1718 $profile->feeduri = $feedUrl;
1721 $result = $oprofile->insert();
1724 common_log_db_error($oprofile, 'INSERT', __FILE__);
1725 // TRANS: Exception. %s is a webfinger address.
1726 throw new Exception(sprintf(_m('Couldn\'t save ostatus_profile for "%s".'),$addr));
1729 self::cacheSet(sprintf('ostatus_profile:webfinger:%s', $addr), $oprofile->uri);
1733 // TRANS: Exception. %s is a webfinger address.
1734 throw new Exception(sprintf(_m('Couldn\'t find a valid profile for "%s".'),$addr));
1738 * Store the full-length scrubbed HTML of a remote notice to an attachment
1739 * file on our server. We'll link to this at the end of the cropped version.
1741 * @param string $title plaintext for HTML page's title
1742 * @param string $rendered HTML fragment for HTML page's body
1745 function saveHTMLFile($title, $rendered)
1747 $final = sprintf("<!DOCTYPE html>\n" .
1749 '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">' .
1750 '<title>%s</title>' .
1752 '<body>%s</body></html>',
1753 htmlspecialchars($title),
1756 $filename = File::filename($this->localProfile(),
1757 'ostatus', // ignored?
1760 $filepath = File::path($filename);
1762 file_put_contents($filepath, $final);
1766 $file->filename = $filename;
1767 $file->url = File::url($filename);
1768 $file->size = filesize($filepath);
1769 $file->date = time();
1770 $file->mimetype = 'text/html';
1772 $file_id = $file->insert();
1774 if ($file_id === false) {
1775 common_log_db_error($file, "INSERT", __FILE__);
1776 // TRANS: Server exception.
1777 throw new ServerException(_m('Could not store HTML content of long post as file.'));
1783 static function ensureProfileURI($uri)
1787 // First, try to query it
1789 $oprofile = Ostatus_profile::staticGet('uri', $uri);
1791 // If unfound, do discovery stuff
1793 if (empty($oprofile)) {
1794 if (preg_match("/^(\w+)\:(.*)/", $uri, $match)) {
1795 $protocol = $match[1];
1796 switch ($protocol) {
1799 $oprofile = Ostatus_profile::ensureProfileURL($uri);
1804 $oprofile = Ostatus_profile::ensureWebfinger($rest);
1806 common_log("Unrecognized URI protocol for profile: $protocol ($uri)");
1816 * Exception indicating we've got a remote reference to a local user,
1817 * not a remote user!
1819 * If we can ue a local profile after all, it's available as $e->profile.
1821 class OStatusShadowException extends Exception
1826 * @param Profile $profile
1827 * @param string $message
1829 function __construct($profile, $message) {
1830 $this->profile = $profile;
1831 parent::__construct($message);