summaryrefslogtreecommitdiff
path: root/plugins/OStatus/classes
diff options
context:
space:
mode:
authorBrion Vibber <brion@pobox.com>2010-02-21 18:54:06 -0800
committerBrion Vibber <brion@pobox.com>2010-02-21 18:54:06 -0800
commitd3996996e483bc8ee1b4c9a38bc3ad17baabb8c0 (patch)
tree90cbe4986bc5624575fdce011623f0c85c0f1275 /plugins/OStatus/classes
parent78ca45c7a05dea911c58097a8c57be470dafee01 (diff)
parent273c0e036347891570a02502715345f5bbb7b143 (diff)
Merge branch 'testing' of gitorious.org:statusnet/mainline into testing
Diffstat (limited to 'plugins/OStatus/classes')
-rw-r--r--plugins/OStatus/classes/Ostatus_profile.php103
1 files changed, 103 insertions, 0 deletions
diff --git a/plugins/OStatus/classes/Ostatus_profile.php b/plugins/OStatus/classes/Ostatus_profile.php
index b67e20202..700168c11 100644
--- a/plugins/OStatus/classes/Ostatus_profile.php
+++ b/plugins/OStatus/classes/Ostatus_profile.php
@@ -845,4 +845,107 @@ class Ostatus_profile extends Memcached_DataObject
return null;
}
}
+
+ public static function ensureWebfinger($addr)
+ {
+ // First, look it up
+
+ $oprofile = Ostatus_profile::staticGet('uri', 'acct:'.$addr);
+
+ if (!empty($oprofile)) {
+ return $oprofile;
+ }
+
+ // Now, try some discovery
+
+ $wf = new Webfinger();
+
+ $result = $wf->lookup($addr);
+
+ if (!$result) {
+ return null;
+ }
+
+ foreach ($result->links as $link) {
+ switch ($link['rel']) {
+ case Webfinger::PROFILEPAGE:
+ $profileUrl = $link['href'];
+ break;
+ case 'salmon':
+ $salmonEndpoint = $link['href'];
+ break;
+ case Webfinger::UPDATESFROM:
+ $feedUrl = $link['href'];
+ break;
+ default:
+ common_log(LOG_NOTICE, "Don't know what to do with rel = '{$link['rel']}'");
+ break;
+ }
+ }
+
+ // If we got a feed URL, try that
+
+ if (isset($feedUrl)) {
+ try {
+ $oprofile = self::ensureProfile($feedUrl);
+ return $oprofile;
+ } catch (Exception $e) {
+ common_log(LOG_WARNING, "Failed creating profile from feed URL '$feedUrl': " . $e->getMessage());
+ // keep looking
+ }
+ }
+
+ // If we got a profile page, try that!
+
+ if (isset($profileUrl)) {
+ try {
+ $oprofile = self::ensureProfile($profileUrl);
+ return $oprofile;
+ } catch (Exception $e) {
+ common_log(LOG_WARNING, "Failed creating profile from profile URL '$profileUrl': " . $e->getMessage());
+ // keep looking
+ }
+ }
+
+ // XXX: try hcard
+ // XXX: try FOAF
+
+ if (isset($salmonEndpoint)) {
+
+ // An account URL, a salmon endpoint, and a dream? Not much to go
+ // on, but let's give it a try
+
+ $uri = 'acct:'.$addr;
+
+ $profile = new Profile();
+
+ $profile->nickname = self::nicknameFromUri($uri);
+ $profile->created = common_sql_now();
+
+ $profile_id = $profile->insert();
+
+ if (!$profile_id) {
+ common_log_db_error($profile, 'INSERT', __FILE__);
+ throw new Exception("Couldn't save profile for '$addr'");
+ }
+
+ $oprofile = new Ostatus_profile();
+
+ $oprofile->uri = $uri;
+ $oprofile->salmonuri = $salmonEndpoint;
+ $oprofile->profile_id = $profile_id;
+ $oprofile->created = common_sql_now();
+
+ $result = $oprofile->insert();
+
+ if (!$result) {
+ common_log_db_error($oprofile, 'INSERT', __FILE__);
+ throw new Exception("Couldn't save ostatus_profile for '$addr'");
+ }
+
+ return $oprofile;
+ }
+
+ return null;
+ }
}