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>
29 class Ostatus_profile extends Managed_DataObject
31 public $__table = 'ostatus_profile';
40 public $avatar; // remote URL of the last avatar we saved
45 public /*static*/ function staticGet($k, $v=null)
47 return parent::staticGet(__CLASS__, $k, $v);
51 * Return table definition for Schema setup and DB_DataObject usage.
53 * @return array array of column definitions
56 static function schemaDef()
60 'uri' => array('type' => 'varchar', 'length' => 255, 'not null' => true),
61 'profile_id' => array('type' => 'integer'),
62 'group_id' => array('type' => 'integer'),
63 'feeduri' => array('type' => 'varchar', 'length' => 255),
64 'salmonuri' => array('type' => 'varchar', 'length' => 255),
65 'avatar' => array('type' => 'text'),
66 'created' => array('type' => 'datetime', 'not null' => true),
67 'modified' => array('type' => 'datetime', 'not null' => true),
69 'primary key' => array('uri'),
70 'unique keys' => array(
71 'ostatus_profile_profile_id_idx' => array('profile_id'),
72 'ostatus_profile_group_id_idx' => array('group_id'),
73 'ostatus_profile_feeduri_idx' => array('feeduri'),
75 'foreign keys' => array(
76 'ostatus_profile_profile_id_fkey' => array('profile', array('profile_id' => 'id')),
77 'ostatus_profile_group_id_fkey' => array('user_group', array('group_id' => 'id')),
83 * Fetch the StatusNet-side profile for this feed
86 public function localProfile()
88 if ($this->profile_id) {
89 return Profile::staticGet('id', $this->profile_id);
95 * Fetch the StatusNet-side profile for this feed
98 public function localGroup()
100 if ($this->group_id) {
101 return User_group::staticGet('id', $this->group_id);
107 * Returns an ActivityObject describing this remote user or group profile.
108 * Can then be used to generate Atom chunks.
110 * @return ActivityObject
112 function asActivityObject()
114 if ($this->isGroup()) {
115 return ActivityObject::fromGroup($this->localGroup());
117 return ActivityObject::fromProfile($this->localProfile());
122 * Returns an XML string fragment with profile information as an
123 * Activity Streams noun object with the given element type.
125 * Assumes that 'activity' namespace has been previously defined.
127 * @fixme replace with wrappers on asActivityObject when it's got everything.
129 * @param string $element one of 'actor', 'subject', 'object', 'target'
132 function asActivityNoun($element)
134 if ($this->isGroup()) {
135 $noun = ActivityObject::fromGroup($this->localGroup());
136 return $noun->asString('activity:' . $element);
138 $noun = ActivityObject::fromProfile($this->localProfile());
139 return $noun->asString('activity:' . $element);
144 * @return boolean true if this is a remote group
148 if ($this->profile_id && !$this->group_id) {
150 } else if ($this->group_id && !$this->profile_id) {
152 } else if ($this->group_id && $this->profile_id) {
153 // TRANS: Server exception.
154 throw new ServerException(sprintf(_m('Invalid ostatus_profile state: both group and profile IDs set for %s.'),$this->uri));
156 // TRANS: Server exception.
157 throw new ServerException(sprintf(_m('Invalid ostatus_profile state: both group and profile IDs empty for %s.'),$this->uri));
162 * Send a subscription request to the hub for this feed.
163 * The hub will later send us a confirmation POST to /main/push/callback.
165 * @return bool true on success, false on failure
166 * @throws ServerException if feed state is not valid
168 public function subscribe()
170 $feedsub = FeedSub::ensureFeed($this->feeduri);
171 if ($feedsub->sub_state == 'active') {
172 // Active subscription, we don't need to do anything.
175 // Inactive or we got left in an inconsistent state.
176 // Run a subscription request to make sure we're current!
177 return $feedsub->subscribe();
182 * Check if this remote profile has any active local subscriptions, and
183 * if not drop the PuSH subscription feed.
185 * @return bool true on success, false on failure
187 public function unsubscribe() {
188 $this->garbageCollect();
192 * Check if this remote profile has any active local subscriptions, and
193 * if not drop the PuSH subscription feed.
197 public function garbageCollect()
199 $feedsub = FeedSub::staticGet('uri', $this->feeduri);
200 return $feedsub->garbageCollect();
204 * Check if this remote profile has any active local subscriptions, so the
205 * PuSH subscription layer can decide if it can drop the feed.
207 * This gets called via the FeedSubSubscriberCount event when running
208 * FeedSub::garbageCollect().
212 public function subscriberCount()
214 if ($this->isGroup()) {
215 $members = $this->localGroup()->getMembers(0, 1);
216 $count = $members->N;
218 $count = $this->localProfile()->subscriberCount();
220 common_log(LOG_INFO, __METHOD__ . " SUB COUNT BEFORE: $count");
222 // Other plugins may be piggybacking on OStatus without having
223 // an active group or user-to-user subscription we know about.
224 Event::handle('Ostatus_profileSubscriberCount', array($this, &$count));
225 common_log(LOG_INFO, __METHOD__ . " SUB COUNT AFTER: $count");
231 * Send an Activity Streams notification to the remote Salmon endpoint,
234 * @param Profile $actor Actor who did the activity
235 * @param string $verb Activity::SUBSCRIBE or Activity::JOIN
236 * @param Object $object object of the action; must define asActivityNoun($tag)
238 public function notify($actor, $verb, $object=null)
240 if (!($actor instanceof Profile)) {
241 $type = gettype($actor);
242 if ($type == 'object') {
243 $type = get_class($actor);
245 // TRANS: Server exception.
246 // TRANS: %1$s is the method name the exception occured in, %2$s is the actor type.
247 throw new ServerException(sprintf(_m('Invalid actor passed to %1$s: %2$s.'),__METHOD__,$type));
249 if ($object == null) {
252 if ($this->salmonuri) {
255 $id = TagURI::mint('%s:%s:%s',
258 common_date_iso8601(time()));
260 // @fixme consolidate all these NS settings somewhere
261 $attributes = array('xmlns' => Activity::ATOM,
262 'xmlns:activity' => 'http://activitystrea.ms/spec/1.0/',
263 'xmlns:thr' => 'http://purl.org/syndication/thread/1.0',
264 'xmlns:georss' => 'http://www.georss.org/georss',
265 'xmlns:ostatus' => 'http://ostatus.org/schema/1.0',
266 'xmlns:poco' => 'http://portablecontacts.net/spec/1.0',
267 'xmlns:media' => 'http://purl.org/syndication/atommedia');
269 $entry = new XMLStringer();
270 $entry->elementStart('entry', $attributes);
271 $entry->element('id', null, $id);
272 $entry->element('title', null, $text);
273 $entry->element('summary', null, $text);
274 $entry->element('published', null, common_date_w3dtf(common_sql_now()));
276 $entry->element('activity:verb', null, $verb);
277 $entry->raw($actor->asAtomAuthor());
278 $entry->raw($actor->asActivityActor());
279 $entry->raw($object->asActivityNoun('object'));
280 $entry->elementEnd('entry');
282 $xml = $entry->getString();
283 common_log(LOG_INFO, "Posting to Salmon endpoint $this->salmonuri: $xml");
285 $salmon = new Salmon(); // ?
286 return $salmon->post($this->salmonuri, $xml, $actor);
292 * Send a Salmon notification ping immediately, and confirm that we got
293 * an acceptable response from the remote site.
295 * @param mixed $entry XML string, Notice, or Activity
296 * @return boolean success
298 public function notifyActivity($entry, $actor)
300 if ($this->salmonuri) {
301 $salmon = new Salmon();
302 return $salmon->post($this->salmonuri, $this->notifyPrepXml($entry), $actor);
309 * Queue a Salmon notification for later. If queues are disabled we'll
310 * send immediately but won't get the return value.
312 * @param mixed $entry XML string, Notice, or Activity
313 * @return boolean success
315 public function notifyDeferred($entry, $actor)
317 if ($this->salmonuri) {
318 $data = array('salmonuri' => $this->salmonuri,
319 'entry' => $this->notifyPrepXml($entry),
320 'actor' => $actor->id);
322 $qm = QueueManager::get();
323 return $qm->enqueue($data, 'salmon');
329 protected function notifyPrepXml($entry)
331 $preamble = '<?xml version="1.0" encoding="UTF-8" ?' . '>';
332 if (is_string($entry)) {
334 } else if ($entry instanceof Activity) {
335 return $preamble . $entry->asString(true);
336 } else if ($entry instanceof Notice) {
337 return $preamble . $entry->asAtomEntry(true, true);
339 // TRANS: Server exception.
340 throw new ServerException(_m('Invalid type passed to Ostatus_profile::notify. It must be XML string or Activity entry.'));
344 function getBestName()
346 if ($this->isGroup()) {
347 return $this->localGroup()->getBestName();
349 return $this->localProfile()->getBestName();
354 * Read and post notices for updates from the feed.
355 * Currently assumes that all items in the feed are new,
356 * coming from a PuSH hub.
358 * @param DOMDocument $doc
359 * @param string $source identifier ("push")
361 public function processFeed(DOMDocument $doc, $source)
363 $feed = $doc->documentElement;
365 if ($feed->localName == 'feed' && $feed->namespaceURI == Activity::ATOM) {
366 $this->processAtomFeed($feed, $source);
367 } else if ($feed->localName == 'rss') { // @fixme check namespace
368 $this->processRssFeed($feed, $source);
370 throw new Exception(_m('Unknown feed format.'));
374 public function processAtomFeed(DOMElement $feed, $source)
376 $entries = $feed->getElementsByTagNameNS(Activity::ATOM, 'entry');
377 if ($entries->length == 0) {
378 common_log(LOG_ERR, __METHOD__ . ": no entries in feed update, ignoring");
382 for ($i = 0; $i < $entries->length; $i++) {
383 $entry = $entries->item($i);
384 $this->processEntry($entry, $feed, $source);
388 public function processRssFeed(DOMElement $rss, $source)
390 $channels = $rss->getElementsByTagName('channel');
392 if ($channels->length == 0) {
393 throw new Exception(_m('RSS feed without a channel.'));
394 } else if ($channels->length > 1) {
395 common_log(LOG_WARNING, __METHOD__ . ": more than one channel in an RSS feed");
398 $channel = $channels->item(0);
400 $items = $channel->getElementsByTagName('item');
402 for ($i = 0; $i < $items->length; $i++) {
403 $item = $items->item($i);
404 $this->processEntry($item, $channel, $source);
409 * Process a posted entry from this feed source.
411 * @param DOMElement $entry
412 * @param DOMElement $feed for context
413 * @param string $source identifier ("push" or "salmon")
416 public function processEntry($entry, $feed, $source)
418 $activity = new Activity($entry, $feed);
420 if (Event::handle('StartHandleFeedEntry', array($activity))) {
422 // @todo process all activity objects
423 switch ($activity->objects[0]->type) {
424 case ActivityObject::ARTICLE:
425 case ActivityObject::BLOGENTRY:
426 case ActivityObject::NOTE:
427 case ActivityObject::STATUS:
428 case ActivityObject::COMMENT:
430 if ($activity->verb == ActivityVerb::POST) {
431 $this->processPost($activity, $source);
433 common_log(LOG_INFO, "Ignoring activity with unrecognized verb $activity->verb");
437 // TRANS: Client exception.
438 throw new ClientException(_m('Can\'t handle that kind of post.'));
441 Event::handle('EndHandleFeedEntry', array($activity));
446 * Process an incoming post activity from this remote feed.
447 * @param Activity $activity
448 * @param string $method 'push' or 'salmon'
449 * @return mixed saved Notice or false
450 * @fixme break up this function, it's getting nasty long
452 public function processPost($activity, $method)
454 if ($this->isGroup()) {
455 // A group feed will contain posts from multiple authors.
456 // @fixme validate these profiles in some way!
457 $oprofile = self::ensureActorProfile($activity);
458 if ($oprofile->isGroup()) {
459 // Groups can't post notices in StatusNet.
460 common_log(LOG_WARNING, "OStatus: skipping post with group listed as author: $oprofile->uri in feed from $this->uri");
464 $actor = $activity->actor;
467 // OK here! assume the default
468 } else if ($actor->id == $this->uri || $actor->link == $this->uri) {
469 $this->updateFromActivityObject($actor);
470 } else if ($actor->id) {
471 // We have an ActivityStreams actor with an explicit ID that doesn't match the feed owner.
472 // This isn't what we expect from mainline OStatus person feeds!
473 // Group feeds go down another path, with different validation...
474 // Most likely this is a plain ol' blog feed of some kind which
475 // doesn't match our expectations. We'll take the entry, but ignore
476 // the <author> info.
477 common_log(LOG_WARNING, "Got an actor '{$actor->title}' ({$actor->id}) on single-user feed for {$this->uri}");
479 // Plain <author> without ActivityStreams actor info.
480 // We'll just ignore this info for now and save the update under the feed's identity.
486 // It's not always an ActivityObject::NOTE, but... let's just say it is.
488 $note = $activity->objects[0];
490 // The id URI will be used as a unique identifier for for the notice,
491 // protecting against duplicate saves. It isn't required to be a URL;
492 // tag: URIs for instance are found in Google Buzz feeds.
493 $sourceUri = $note->id;
494 $dupe = Notice::staticGet('uri', $sourceUri);
496 common_log(LOG_INFO, "OStatus: ignoring duplicate post: $sourceUri");
500 // We'll also want to save a web link to the original notice, if provided.
503 $sourceUrl = $note->link;
504 } else if ($activity->link) {
505 $sourceUrl = $activity->link;
506 } else if (preg_match('!^https?://!', $note->id)) {
507 $sourceUrl = $note->id;
510 // Use summary as fallback for content
512 if (!empty($note->content)) {
513 $sourceContent = $note->content;
514 } else if (!empty($note->summary)) {
515 $sourceContent = $note->summary;
516 } else if (!empty($note->title)) {
517 $sourceContent = $note->title;
519 // @fixme fetch from $sourceUrl?
520 // TRANS: Client exception. %s is a source URL.
521 throw new ClientException(sprintf(_m('No content for notice %s.'),$sourceUri));
524 // Get (safe!) HTML and text versions of the content
526 $rendered = $this->purify($sourceContent);
527 $content = html_entity_decode(strip_tags($rendered), ENT_QUOTES, 'UTF-8');
529 $shortened = common_shorten_links($content);
531 // If it's too long, try using the summary, and make the
532 // HTML an attachment.
536 if (Notice::contentTooLong($shortened)) {
537 $attachment = $this->saveHTMLFile($note->title, $rendered);
538 $summary = html_entity_decode(strip_tags($note->summary), ENT_QUOTES, 'UTF-8');
539 if (empty($summary)) {
542 $shortSummary = common_shorten_links($summary);
543 if (Notice::contentTooLong($shortSummary)) {
544 $url = common_shorten_url($sourceUrl);
545 $shortSummary = substr($shortSummary,
547 Notice::maxContent() - (mb_strlen($url) + 2));
548 $content = $shortSummary . ' ' . $url;
550 // We mark up the attachment link specially for the HTML output
551 // so we can fold-out the full version inline.
553 // @fixme I18N this tooltip will be saved with the site's default language
554 // TRANS: Shown when a notice is longer than supported and/or when attachments are present. At runtime this will usually be replaced with localized text from StatusNet core messages.
555 $showMoreText = _m('Show more');
556 $attachUrl = common_local_url('attachment',
557 array('attachment' => $attachment->id));
558 $rendered = common_render_text($shortSummary) .
559 '<a href="' . htmlspecialchars($attachUrl) .'"'.
560 ' class="attachment more"' .
561 ' title="'. htmlspecialchars($showMoreText) . '">' .
567 $options = array('is_local' => Notice::REMOTE_OMB,
570 'rendered' => $rendered,
571 'replies' => array(),
576 // Check for optional attributes...
578 if (!empty($activity->time)) {
579 $options['created'] = common_sql_date($activity->time);
582 if ($activity->context) {
583 // Any individual or group attn: targets?
584 $replies = $activity->context->attention;
585 $options['groups'] = $this->filterReplies($oprofile, $replies);
586 $options['replies'] = $replies;
588 // Maintain direct reply associations
589 // @fixme what about conversation ID?
590 if (!empty($activity->context->replyToID)) {
591 $orig = Notice::staticGet('uri',
592 $activity->context->replyToID);
594 $options['reply_to'] = $orig->id;
598 $location = $activity->context->location;
600 $options['lat'] = $location->lat;
601 $options['lon'] = $location->lon;
602 if ($location->location_id) {
603 $options['location_ns'] = $location->location_ns;
604 $options['location_id'] = $location->location_id;
609 // Atom categories <-> hashtags
610 foreach ($activity->categories as $cat) {
612 $term = common_canonical_tag($cat->term);
614 $options['tags'][] = $term;
619 // Atom enclosures -> attachment URLs
620 foreach ($activity->enclosures as $href) {
621 // @fixme save these locally or....?
622 $options['urls'][] = $href;
626 $saved = Notice::saveNew($oprofile->profile_id,
631 Ostatus_source::saveNew($saved, $this, $method);
632 if (!empty($attachment)) {
633 File_to_post::processNew($attachment->id, $saved->id);
636 } catch (Exception $e) {
637 common_log(LOG_ERR, "OStatus save of remote message $sourceUri failed: " . $e->getMessage());
640 common_log(LOG_INFO, "OStatus saved remote message $sourceUri as notice id $saved->id");
647 protected function purify($html)
649 require_once INSTALLDIR.'/extlib/htmLawed/htmLawed.php';
650 $config = array('safe' => 1,
651 'deny_attribute' => 'id,style,on*');
652 return htmLawed($html, $config);
656 * Filters a list of recipient ID URIs to just those for local delivery.
657 * @param Ostatus_profile local profile of sender
658 * @param array in/out &$attention_uris set of URIs, will be pruned on output
659 * @return array of group IDs
661 protected function filterReplies($sender, &$attention_uris)
663 common_log(LOG_DEBUG, "Original reply recipients: " . implode(', ', $attention_uris));
666 foreach (array_unique($attention_uris) as $recipient) {
667 // Is the recipient a local user?
668 $user = User::staticGet('uri', $recipient);
670 // @fixme sender verification, spam etc?
671 $replies[] = $recipient;
675 // Is the recipient a local group?
676 // $group = User_group::staticGet('uri', $recipient);
677 $id = OStatusPlugin::localGroupFromUrl($recipient);
679 $group = User_group::staticGet('id', $id);
681 // Deliver to all members of this local group if allowed.
682 $profile = $sender->localProfile();
683 if ($profile->isMember($group)) {
684 $groups[] = $group->id;
686 common_log(LOG_DEBUG, "Skipping reply to local group $group->nickname as sender $profile->id is not a member");
690 common_log(LOG_DEBUG, "Skipping reply to bogus group $recipient");
694 // Is the recipient a remote user or group?
696 $oprofile = Ostatus_profile::ensureProfileURI($recipient);
697 if ($oprofile->isGroup()) {
698 // Deliver to local members of this remote group.
699 // @fixme sender verification?
700 $groups[] = $oprofile->group_id;
702 // may be canonicalized or something
703 $replies[] = $oprofile->uri;
706 } catch (Exception $e) {
707 // Neither a recognizable local nor remote user!
708 common_log(LOG_DEBUG, "Skipping reply to unrecognized profile $recipient: " . $e->getMessage());
712 $attention_uris = $replies;
713 common_log(LOG_DEBUG, "Local reply recipients: " . implode(', ', $replies));
714 common_log(LOG_DEBUG, "Local group recipients: " . implode(', ', $groups));
719 * Look up and if necessary create an Ostatus_profile for the remote entity
720 * with the given profile page URL. This should never return null -- you
721 * will either get an object or an exception will be thrown.
723 * @param string $profile_url
724 * @return Ostatus_profile
725 * @throws Exception on various error conditions
726 * @throws OStatusShadowException if this reference would obscure a local user/group
729 public static function ensureProfileURL($profile_url, $hints=array())
731 $oprofile = self::getFromProfileURL($profile_url);
733 if (!empty($oprofile)) {
737 $hints['profileurl'] = $profile_url;
742 $client = new HTTPClient();
743 $client->setHeader('Accept', 'text/html,application/xhtml+xml');
744 $response = $client->get($profile_url);
746 if (!$response->isOk()) {
747 // TRANS: Exception. %s is a profile URL.
748 throw new Exception(sprintf(_m('Could not reach profile page %s.'),$profile_url));
751 // Check if we have a non-canonical URL
753 $finalUrl = $response->getUrl();
755 if ($finalUrl != $profile_url) {
757 $hints['profileurl'] = $finalUrl;
759 $oprofile = self::getFromProfileURL($finalUrl);
761 if (!empty($oprofile)) {
766 // Try to get some hCard data
768 $body = $response->getBody();
770 $hcardHints = DiscoveryHints::hcardHints($body, $finalUrl);
772 if (!empty($hcardHints)) {
773 $hints = array_merge($hints, $hcardHints);
776 // Check if they've got an LRDD header
778 $lrdd = LinkHeader::getLink($response, 'lrdd', 'application/xrd+xml');
782 $xrd = Discovery::fetchXrd($lrdd);
783 $xrdHints = DiscoveryHints::fromXRD($xrd);
785 $hints = array_merge($hints, $xrdHints);
788 // If discovery found a feedurl (probably from LRDD), use it.
790 if (array_key_exists('feedurl', $hints)) {
791 return self::ensureFeedURL($hints['feedurl'], $hints);
794 // Get the feed URL from HTML
796 $discover = new FeedDiscovery();
798 $feedurl = $discover->discoverFromHTML($finalUrl, $body);
800 if (!empty($feedurl)) {
801 $hints['feedurl'] = $feedurl;
802 return self::ensureFeedURL($feedurl, $hints);
806 throw new Exception(sprintf(_m('Could not find a feed URL for profile page %s.'),$finalUrl));
810 * Look up the Ostatus_profile, if present, for a remote entity with the
811 * given profile page URL. Will return null for both unknown and invalid
814 * @return mixed Ostatus_profile or null
815 * @throws OStatusShadowException for local profiles
817 static function getFromProfileURL($profile_url)
819 $profile = Profile::staticGet('profileurl', $profile_url);
821 if (empty($profile)) {
825 // Is it a known Ostatus profile?
827 $oprofile = Ostatus_profile::staticGet('profile_id', $profile->id);
829 if (!empty($oprofile)) {
833 // Is it a local user?
835 $user = User::staticGet('id', $profile->id);
838 // @todo i18n FIXME: use sprintf and add i18n (?)
839 throw new OStatusShadowException($profile, "'$profile_url' is the profile for local user '{$user->nickname}'.");
842 // Continue discovery; it's a remote profile
843 // for OMB or some other protocol, may also
850 * Look up and if necessary create an Ostatus_profile for remote entity
851 * with the given update feed. This should never return null -- you will
852 * either get an object or an exception will be thrown.
854 * @return Ostatus_profile
857 public static function ensureFeedURL($feed_url, $hints=array())
859 $discover = new FeedDiscovery();
861 $feeduri = $discover->discoverFromFeedURL($feed_url);
862 $hints['feedurl'] = $feeduri;
864 $huburi = $discover->getHubLink();
865 $hints['hub'] = $huburi;
866 $salmonuri = $discover->getAtomLink(Salmon::NS_REPLIES);
867 $hints['salmon'] = $salmonuri;
869 if (!$huburi && !common_config('feedsub', 'fallback_hub')) {
870 // We can only deal with folks with a PuSH hub
871 throw new FeedSubNoHubException();
874 $feedEl = $discover->root;
876 if ($feedEl->tagName == 'feed') {
877 return self::ensureAtomFeed($feedEl, $hints);
878 } else if ($feedEl->tagName == 'channel') {
879 return self::ensureRssChannel($feedEl, $hints);
881 throw new FeedSubBadXmlException($feeduri);
886 * Look up and, if necessary, create an Ostatus_profile for the remote
887 * profile with the given Atom feed - actually loaded from the feed.
888 * This should never return null -- you will either get an object or
889 * an exception will be thrown.
891 * @param DOMElement $feedEl root element of a loaded Atom feed
892 * @param array $hints additional discovery information passed from higher levels
893 * @fixme should this be marked public?
894 * @return Ostatus_profile
897 public static function ensureAtomFeed($feedEl, $hints)
899 // Try to get a profile from the feed activity:subject
901 $subject = ActivityUtils::child($feedEl, Activity::SUBJECT, Activity::SPEC);
903 if (!empty($subject)) {
904 $subjObject = new ActivityObject($subject);
905 return self::ensureActivityObjectProfile($subjObject, $hints);
908 // Otherwise, try the feed author
910 $author = ActivityUtils::child($feedEl, Activity::AUTHOR, Activity::ATOM);
912 if (!empty($author)) {
913 $authorObject = new ActivityObject($author);
914 return self::ensureActivityObjectProfile($authorObject, $hints);
917 // Sheesh. Not a very nice feed! Let's try fingerpoken in the
920 $entries = $feedEl->getElementsByTagNameNS(Activity::ATOM, 'entry');
922 if (!empty($entries) && $entries->length > 0) {
924 $entry = $entries->item(0);
926 $actor = ActivityUtils::child($entry, Activity::ACTOR, Activity::SPEC);
928 if (!empty($actor)) {
929 $actorObject = new ActivityObject($actor);
930 return self::ensureActivityObjectProfile($actorObject, $hints);
934 $author = ActivityUtils::child($entry, Activity::AUTHOR, Activity::ATOM);
936 if (!empty($author)) {
937 $authorObject = new ActivityObject($author);
938 return self::ensureActivityObjectProfile($authorObject, $hints);
942 // XXX: make some educated guesses here
943 throw new FeedSubException(_m('Can\'t find enough profile information to make a feed.'));
947 * Look up and, if necessary, create an Ostatus_profile for the remote
948 * profile with the given RSS feed - actually loaded from the feed.
949 * This should never return null -- you will either get an object or
950 * an exception will be thrown.
952 * @param DOMElement $feedEl root element of a loaded RSS feed
953 * @param array $hints additional discovery information passed from higher levels
954 * @fixme should this be marked public?
955 * @return Ostatus_profile
958 public static function ensureRssChannel($feedEl, $hints)
960 // Special-case for Posterous. They have some nice metadata in their
961 // posterous:author elements. We should use them instead of the channel.
963 $items = $feedEl->getElementsByTagName('item');
965 if ($items->length > 0) {
966 $item = $items->item(0);
967 $authorEl = ActivityUtils::child($item, ActivityObject::AUTHOR, ActivityObject::POSTEROUS);
968 if (!empty($authorEl)) {
969 $obj = ActivityObject::fromPosterousAuthor($authorEl);
970 // Posterous has multiple authors per feed, and multiple feeds
971 // per author. We check if this is the "main" feed for this author.
972 if (array_key_exists('profileurl', $hints) &&
973 !empty($obj->poco) &&
974 common_url_to_nickname($hints['profileurl']) == $obj->poco->preferredUsername) {
975 return self::ensureActivityObjectProfile($obj, $hints);
980 // @fixme we should check whether this feed has elements
981 // with different <author> or <dc:creator> elements, and... I dunno.
982 // Do something about that.
984 $obj = ActivityObject::fromRssChannel($feedEl);
986 return self::ensureActivityObjectProfile($obj, $hints);
990 * Download and update given avatar image
993 * @throws Exception in various failure cases
995 protected function updateAvatar($url)
997 if ($url == $this->avatar) {
998 // We've already got this one.
1001 if (!common_valid_http_url($url)) {
1002 throw new ServerException(sprintf(_m("Invalid avatar URL %s."), $url));
1005 if ($this->isGroup()) {
1006 $self = $this->localGroup();
1008 $self = $this->localProfile();
1011 throw new ServerException(sprintf(
1012 _m("Tried to update avatar for unsaved remote profile %s."),
1016 // @fixme this should be better encapsulated
1017 // ripped from oauthstore.php (for old OMB client)
1018 $temp_filename = tempnam(sys_get_temp_dir(), 'listener_avatar');
1020 if (!copy($url, $temp_filename)) {
1021 throw new ServerException(sprintf(_m("Unable to fetch avatar from %s."), $url));
1024 if ($this->isGroup()) {
1025 $id = $this->group_id;
1027 $id = $this->profile_id;
1029 // @fixme should we be using different ids?
1030 $imagefile = new ImageFile($id, $temp_filename);
1031 $filename = Avatar::filename($id,
1032 image_type_to_extension($imagefile->type),
1034 common_timestamp());
1035 rename($temp_filename, Avatar::path($filename));
1036 } catch (Exception $e) {
1037 unlink($temp_filename);
1040 // @fixme hardcoded chmod is lame, but seems to be necessary to
1041 // keep from accidentally saving images from command-line (queues)
1042 // that can't be read from web server, which causes hard-to-notice
1043 // problems later on:
1045 // http://status.net/open-source/issues/2663
1046 chmod(Avatar::path($filename), 0644);
1048 $self->setOriginal($filename);
1050 $orig = clone($this);
1051 $this->avatar = $url;
1052 $this->update($orig);
1056 * Pull avatar URL from ActivityObject or profile hints
1058 * @param ActivityObject $object
1059 * @param array $hints
1060 * @return mixed URL string or false
1063 public static function getActivityObjectAvatar($object, $hints=array())
1065 if ($object->avatarLinks) {
1067 // Take the exact-size avatar, or the largest avatar, or the first avatar if all sizeless
1068 foreach ($object->avatarLinks as $avatar) {
1069 if ($avatar->width == AVATAR_PROFILE_SIZE && $avatar->height = AVATAR_PROFILE_SIZE) {
1074 if (!$best || $avatar->width > $best->width) {
1079 } else if (array_key_exists('avatar', $hints)) {
1080 return $hints['avatar'];
1086 * Get an appropriate avatar image source URL, if available.
1088 * @param ActivityObject $actor
1089 * @param DOMElement $feed
1093 protected static function getAvatar($actor, $feed)
1097 if ($actor->avatar) {
1098 $url = trim($actor->avatar);
1101 // Check <atom:logo> and <atom:icon> on the feed
1102 $els = $feed->childNodes();
1103 if ($els && $els->length) {
1104 for ($i = 0; $i < $els->length; $i++) {
1105 $el = $els->item($i);
1106 if ($el->namespaceURI == Activity::ATOM) {
1107 if (empty($url) && $el->localName == 'logo') {
1108 $url = trim($el->textContent);
1111 if (empty($icon) && $el->localName == 'icon') {
1112 // Use as a fallback
1113 $icon = trim($el->textContent);
1118 if ($icon && !$url) {
1123 $opts = array('allowed_schemes' => array('http', 'https'));
1124 if (Validate::uri($url, $opts)) {
1128 return common_path('plugins/OStatus/images/96px-Feed-icon.svg.png');
1132 * Fetch, or build if necessary, an Ostatus_profile for the actor
1133 * in a given Activity Streams activity.
1134 * This should never return null -- you will either get an object or
1135 * an exception will be thrown.
1137 * @param Activity $activity
1138 * @param string $feeduri if we already know the canonical feed URI!
1139 * @param string $salmonuri if we already know the salmon return channel URI
1140 * @return Ostatus_profile
1144 public static function ensureActorProfile($activity, $hints=array())
1146 return self::ensureActivityObjectProfile($activity->actor, $hints);
1150 * Fetch, or build if necessary, an Ostatus_profile for the profile
1151 * in a given Activity Streams object (can be subject, actor, or object).
1152 * This should never return null -- you will either get an object or
1153 * an exception will be thrown.
1155 * @param ActivityObject $object
1156 * @param array $hints additional discovery information passed from higher levels
1157 * @return Ostatus_profile
1161 public static function ensureActivityObjectProfile($object, $hints=array())
1163 $profile = self::getActivityObjectProfile($object);
1165 $profile->updateFromActivityObject($object, $hints);
1167 $profile = self::createActivityObjectProfile($object, $hints);
1173 * @param Activity $activity
1174 * @return mixed matching Ostatus_profile or false if none known
1175 * @throws ServerException if feed info invalid
1177 public static function getActorProfile($activity)
1179 return self::getActivityObjectProfile($activity->actor);
1183 * @param ActivityObject $activity
1184 * @return mixed matching Ostatus_profile or false if none known
1185 * @throws ServerException if feed info invalid
1187 protected static function getActivityObjectProfile($object)
1189 $uri = self::getActivityObjectProfileURI($object);
1190 return Ostatus_profile::staticGet('uri', $uri);
1194 * Get the identifier URI for the remote entity described
1195 * by this ActivityObject. This URI is *not* guaranteed to be
1196 * a resolvable HTTP/HTTPS URL.
1198 * @param ActivityObject $object
1200 * @throws ServerException if feed info invalid
1202 protected static function getActivityObjectProfileURI($object)
1205 if (ActivityUtils::validateUri($object->id)) {
1210 // If the id is missing or invalid (we've seen feeds mistakenly listing
1211 // things like local usernames in that field) then we'll use the profile
1212 // page link, if valid.
1213 if ($object->link && common_valid_http_url($object->link)) {
1214 return $object->link;
1216 throw new ServerException("No author ID URI found.");
1220 * @fixme validate stuff somewhere
1224 * Create local ostatus_profile and profile/user_group entries for
1225 * the provided remote user or group.
1226 * This should never return null -- you will either get an object or
1227 * an exception will be thrown.
1229 * @param ActivityObject $object
1230 * @param array $hints
1232 * @return Ostatus_profile
1234 protected static function createActivityObjectProfile($object, $hints=array())
1236 $homeuri = $object->id;
1240 common_log(LOG_DEBUG, __METHOD__ . " empty actor profile URI: " . var_export($activity, true));
1241 throw new Exception("No profile URI");
1244 $user = User::staticGet('uri', $homeuri);
1246 // TRANS: Exception.
1247 throw new Exception(_m('Local user can\'t be referenced as remote.'));
1250 if (OStatusPlugin::localGroupFromUrl($homeuri)) {
1251 // TRANS: Exception.
1252 throw new Exception(_m('Local group can\'t be referenced as remote.'));
1255 if (array_key_exists('feedurl', $hints)) {
1256 $feeduri = $hints['feedurl'];
1258 $discover = new FeedDiscovery();
1259 $feeduri = $discover->discoverFromURL($homeuri);
1262 if (array_key_exists('salmon', $hints)) {
1263 $salmonuri = $hints['salmon'];
1266 $discover = new FeedDiscovery();
1267 $discover->discoverFromFeedURL($hints['feedurl']);
1269 $salmonuri = $discover->getAtomLink(Salmon::NS_REPLIES);
1272 if (array_key_exists('hub', $hints)) {
1273 $huburi = $hints['hub'];
1276 $discover = new FeedDiscovery();
1277 $discover->discoverFromFeedURL($hints['feedurl']);
1279 $huburi = $discover->getHubLink();
1282 if (!$huburi && !common_config('feedsub', 'fallback_hub')) {
1283 // We can only deal with folks with a PuSH hub
1284 throw new FeedSubNoHubException();
1287 $oprofile = new Ostatus_profile();
1289 $oprofile->uri = $homeuri;
1290 $oprofile->feeduri = $feeduri;
1291 $oprofile->salmonuri = $salmonuri;
1293 $oprofile->created = common_sql_now();
1294 $oprofile->modified = common_sql_now();
1296 if ($object->type == ActivityObject::PERSON) {
1297 $profile = new Profile();
1298 $profile->created = common_sql_now();
1299 self::updateProfile($profile, $object, $hints);
1301 $oprofile->profile_id = $profile->insert();
1302 if (!$oprofile->profile_id) {
1303 // TRANS: Exception.
1304 throw new ServerException(_m('Can\'t save local profile.'));
1307 $group = new User_group();
1308 $group->uri = $homeuri;
1309 $group->created = common_sql_now();
1310 self::updateGroup($group, $object, $hints);
1312 $oprofile->group_id = $group->insert();
1313 if (!$oprofile->group_id) {
1314 // TRANS: Exception.
1315 throw new ServerException(_m('Can\'t save local profile.'));
1319 $ok = $oprofile->insert();
1322 // TRANS: Exception.
1323 throw new ServerException(_m('Can\'t save OStatus profile.'));
1326 $avatar = self::getActivityObjectAvatar($object, $hints);
1330 $oprofile->updateAvatar($avatar);
1331 } catch (Exception $ex) {
1332 // Profile is saved, but Avatar is messed up. We're
1333 // just going to continue.
1334 common_log(LOG_WARNING, "Exception saving OStatus profile avatar: ". $ex->getMessage());
1342 * Save any updated profile information to our local copy.
1343 * @param ActivityObject $object
1344 * @param array $hints
1346 public function updateFromActivityObject($object, $hints=array())
1348 if ($this->isGroup()) {
1349 $group = $this->localGroup();
1350 self::updateGroup($group, $object, $hints);
1352 $profile = $this->localProfile();
1353 self::updateProfile($profile, $object, $hints);
1355 $avatar = self::getActivityObjectAvatar($object, $hints);
1358 $this->updateAvatar($avatar);
1359 } catch (Exception $ex) {
1360 common_log(LOG_WARNING, "Exception saving OStatus profile avatar: " . $ex->getMessage());
1365 public static function updateProfile($profile, $object, $hints=array())
1367 $orig = clone($profile);
1369 $profile->nickname = self::getActivityObjectNickname($object, $hints);
1371 if (!empty($object->title)) {
1372 $profile->fullname = $object->title;
1373 } else if (array_key_exists('fullname', $hints)) {
1374 $profile->fullname = $hints['fullname'];
1377 if (!empty($object->link)) {
1378 $profile->profileurl = $object->link;
1379 } else if (array_key_exists('profileurl', $hints)) {
1380 $profile->profileurl = $hints['profileurl'];
1381 } else if (Validate::uri($object->id, array('allowed_schemes' => array('http', 'https')))) {
1382 $profile->profileurl = $object->id;
1385 $profile->bio = self::getActivityObjectBio($object, $hints);
1386 $profile->location = self::getActivityObjectLocation($object, $hints);
1387 $profile->homepage = self::getActivityObjectHomepage($object, $hints);
1389 if (!empty($object->geopoint)) {
1390 $location = ActivityContext::locationFromPoint($object->geopoint);
1391 if (!empty($location)) {
1392 $profile->lat = $location->lat;
1393 $profile->lon = $location->lon;
1397 // @fixme tags/categories
1398 // @todo tags from categories
1401 common_log(LOG_DEBUG, "Updating OStatus profile $profile->id from remote info $object->id: " . var_export($object, true) . var_export($hints, true));
1402 $profile->update($orig);
1406 protected static function updateGroup($group, $object, $hints=array())
1408 $orig = clone($group);
1410 $group->nickname = self::getActivityObjectNickname($object, $hints);
1411 $group->fullname = $object->title;
1413 if (!empty($object->link)) {
1414 $group->mainpage = $object->link;
1415 } else if (array_key_exists('profileurl', $hints)) {
1416 $group->mainpage = $hints['profileurl'];
1419 // @todo tags from categories
1420 $group->description = self::getActivityObjectBio($object, $hints);
1421 $group->location = self::getActivityObjectLocation($object, $hints);
1422 $group->homepage = self::getActivityObjectHomepage($object, $hints);
1425 common_log(LOG_DEBUG, "Updating OStatus group $group->id from remote info $object->id: " . var_export($object, true) . var_export($hints, true));
1426 $group->update($orig);
1430 protected static function getActivityObjectHomepage($object, $hints=array())
1433 $poco = $object->poco;
1435 if (!empty($poco)) {
1436 $url = $poco->getPrimaryURL();
1437 if ($url && $url->type == 'homepage') {
1438 $homepage = $url->value;
1442 // @todo Try for a another PoCo URL?
1447 protected static function getActivityObjectLocation($object, $hints=array())
1451 if (!empty($object->poco) &&
1452 isset($object->poco->address->formatted)) {
1453 $location = $object->poco->address->formatted;
1454 } else if (array_key_exists('location', $hints)) {
1455 $location = $hints['location'];
1458 if (!empty($location)) {
1459 if (mb_strlen($location) > 255) {
1460 $location = mb_substr($note, 0, 255 - 3) . ' … ';
1464 // @todo Try to find location some othe way? Via goerss point?
1469 protected static function getActivityObjectBio($object, $hints=array())
1473 if (!empty($object->poco)) {
1474 $note = $object->poco->note;
1475 } else if (array_key_exists('bio', $hints)) {
1476 $note = $hints['bio'];
1479 if (!empty($note)) {
1480 if (Profile::bioTooLong($note)) {
1481 // XXX: truncate ok?
1482 $bio = mb_substr($note, 0, Profile::maxBio() - 3) . ' … ';
1488 // @todo Try to get bio info some other way?
1493 public static function getActivityObjectNickname($object, $hints=array())
1495 if ($object->poco) {
1496 if (!empty($object->poco->preferredUsername)) {
1497 return common_nicknamize($object->poco->preferredUsername);
1501 if (!empty($object->nickname)) {
1502 return common_nicknamize($object->nickname);
1505 if (array_key_exists('nickname', $hints)) {
1506 return $hints['nickname'];
1509 // Try the profile url (like foo.example.com or example.com/user/foo)
1511 $profileUrl = ($object->link) ? $object->link : $hints['profileurl'];
1513 if (!empty($profileUrl)) {
1514 $nickname = self::nicknameFromURI($profileUrl);
1517 // Try the URI (may be a tag:, http:, acct:, ...
1519 if (empty($nickname)) {
1520 $nickname = self::nicknameFromURI($object->id);
1523 // Try a Webfinger if one was passed (way) down
1525 if (empty($nickname)) {
1526 if (array_key_exists('webfinger', $hints)) {
1527 $nickname = self::nicknameFromURI($hints['webfinger']);
1533 if (empty($nickname)) {
1534 $nickname = common_nicknamize($object->title);
1540 protected static function nicknameFromURI($uri)
1542 preg_match('/(\w+):/', $uri, $matches);
1544 $protocol = $matches[1];
1546 switch ($protocol) {
1549 if (preg_match("/^$protocol:(.*)?@.*\$/", $uri, $matches)) {
1550 return common_canonical_nickname($matches[1]);
1554 return common_url_to_nickname($uri);
1562 * Look up, and if necessary create, an Ostatus_profile for the remote
1563 * entity with the given webfinger address.
1564 * This should never return null -- you will either get an object or
1565 * an exception will be thrown.
1567 * @param string $addr webfinger address
1568 * @return Ostatus_profile
1569 * @throws Exception on error conditions
1570 * @throws OStatusShadowException if this reference would obscure a local user/group
1572 public static function ensureWebfinger($addr)
1574 // First, try the cache
1576 $uri = self::cacheGet(sprintf('ostatus_profile:webfinger:%s', $addr));
1578 if ($uri !== false) {
1579 if (is_null($uri)) {
1580 // Negative cache entry
1581 // TRANS: Exception.
1582 throw new Exception(_m('Not a valid webfinger address.'));
1584 $oprofile = Ostatus_profile::staticGet('uri', $uri);
1585 if (!empty($oprofile)) {
1590 // Try looking it up
1592 $oprofile = Ostatus_profile::staticGet('uri', 'acct:'.$addr);
1594 if (!empty($oprofile)) {
1595 self::cacheSet(sprintf('ostatus_profile:webfinger:%s', $addr), $oprofile->uri);
1599 // Now, try some discovery
1601 $disco = new Discovery();
1604 $xrd = $disco->lookup($addr);
1605 } catch (Exception $e) {
1606 // Save negative cache entry so we don't waste time looking it up again.
1607 // @fixme distinguish temporary failures?
1608 self::cacheSet(sprintf('ostatus_profile:webfinger:%s', $addr), null);
1609 // TRANS: Exception.
1610 throw new Exception(_m('Not a valid webfinger address.'));
1613 $hints = array('webfinger' => $addr);
1615 $dhints = DiscoveryHints::fromXRD($xrd);
1617 $hints = array_merge($hints, $dhints);
1619 // If there's an Hcard, let's grab its info
1621 if (array_key_exists('hcard', $hints)) {
1622 if (!array_key_exists('profileurl', $hints) ||
1623 $hints['hcard'] != $hints['profileurl']) {
1624 $hcardHints = DiscoveryHints::fromHcardUrl($hints['hcard']);
1625 $hints = array_merge($hcardHints, $hints);
1629 // If we got a feed URL, try that
1631 if (array_key_exists('feedurl', $hints)) {
1633 common_log(LOG_INFO, "Discovery on acct:$addr with feed URL " . $hints['feedurl']);
1634 $oprofile = self::ensureFeedURL($hints['feedurl'], $hints);
1635 self::cacheSet(sprintf('ostatus_profile:webfinger:%s', $addr), $oprofile->uri);
1637 } catch (Exception $e) {
1638 common_log(LOG_WARNING, "Failed creating profile from feed URL '$feedUrl': " . $e->getMessage());
1643 // If we got a profile page, try that!
1645 if (array_key_exists('profileurl', $hints)) {
1647 common_log(LOG_INFO, "Discovery on acct:$addr with profile URL $profileUrl");
1648 $oprofile = self::ensureProfileURL($hints['profileurl'], $hints);
1649 self::cacheSet(sprintf('ostatus_profile:webfinger:%s', $addr), $oprofile->uri);
1651 } catch (OStatusShadowException $e) {
1652 // We've ended up with a remote reference to a local user or group.
1653 // @fixme ideally we should be able to say who it was so we can
1654 // go back and refer to it the regular way
1656 } catch (Exception $e) {
1657 common_log(LOG_WARNING, "Failed creating profile from profile URL '$profileUrl': " . $e->getMessage());
1660 // @fixme this means an error discovering from profile page
1661 // may give us a corrupt entry using the webfinger URI, which
1662 // will obscure the correct page-keyed profile later on.
1669 if (array_key_exists('salmon', $hints)) {
1671 $salmonEndpoint = $hints['salmon'];
1673 // An account URL, a salmon endpoint, and a dream? Not much to go
1674 // on, but let's give it a try
1676 $uri = 'acct:'.$addr;
1678 $profile = new Profile();
1680 $profile->nickname = self::nicknameFromUri($uri);
1681 $profile->created = common_sql_now();
1683 if (isset($profileUrl)) {
1684 $profile->profileurl = $profileUrl;
1687 $profile_id = $profile->insert();
1690 common_log_db_error($profile, 'INSERT', __FILE__);
1691 // TRANS: Exception. %s is a webfinger address.
1692 throw new Exception(sprintf(_m('Couldn\'t save profile for "%s".'),$addr));
1695 $oprofile = new Ostatus_profile();
1697 $oprofile->uri = $uri;
1698 $oprofile->salmonuri = $salmonEndpoint;
1699 $oprofile->profile_id = $profile_id;
1700 $oprofile->created = common_sql_now();
1702 if (isset($feedUrl)) {
1703 $profile->feeduri = $feedUrl;
1706 $result = $oprofile->insert();
1709 common_log_db_error($oprofile, 'INSERT', __FILE__);
1710 // TRANS: Exception. %s is a webfinger address.
1711 throw new Exception(sprintf(_m('Couldn\'t save ostatus_profile for "%s".'),$addr));
1714 self::cacheSet(sprintf('ostatus_profile:webfinger:%s', $addr), $oprofile->uri);
1718 // TRANS: Exception. %s is a webfinger address.
1719 throw new Exception(sprintf(_m('Couldn\'t find a valid profile for "%s".'),$addr));
1723 * Store the full-length scrubbed HTML of a remote notice to an attachment
1724 * file on our server. We'll link to this at the end of the cropped version.
1726 * @param string $title plaintext for HTML page's title
1727 * @param string $rendered HTML fragment for HTML page's body
1730 function saveHTMLFile($title, $rendered)
1732 $final = sprintf("<!DOCTYPE html>\n" .
1734 '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">' .
1735 '<title>%s</title>' .
1737 '<body>%s</body></html>',
1738 htmlspecialchars($title),
1741 $filename = File::filename($this->localProfile(),
1742 'ostatus', // ignored?
1745 $filepath = File::path($filename);
1747 file_put_contents($filepath, $final);
1751 $file->filename = $filename;
1752 $file->url = File::url($filename);
1753 $file->size = filesize($filepath);
1754 $file->date = time();
1755 $file->mimetype = 'text/html';
1757 $file_id = $file->insert();
1759 if ($file_id === false) {
1760 common_log_db_error($file, "INSERT", __FILE__);
1761 throw new ServerException(_m('Could not store HTML content of long post as file.'));
1767 static function ensureProfileURI($uri)
1771 // First, try to query it
1773 $oprofile = Ostatus_profile::staticGet('uri', $uri);
1775 // If unfound, do discovery stuff
1777 if (empty($oprofile)) {
1778 if (preg_match("/^(\w+)\:(.*)/", $uri, $match)) {
1779 $protocol = $match[1];
1780 switch ($protocol) {
1783 $oprofile = Ostatus_profile::ensureProfileURL($uri);
1788 $oprofile = Ostatus_profile::ensureWebfinger($rest);
1790 common_log("Unrecognized URI protocol for profile: $protocol ($uri)");
1800 * Exception indicating we've got a remote reference to a local user,
1801 * not a remote user!
1803 * If we can ue a local profile after all, it's available as $e->profile.
1805 class OStatusShadowException extends Exception
1810 * @param Profile $profile
1811 * @param string $message
1813 function __construct($profile, $message) {
1814 $this->profile = $profile;
1815 parent::__construct($message);