Example #1
0
 /**
  * Pull data for a remote profile and check if it's valid.
  * Fills out error UI string in $this->error
  * Fills out $this->oprofile on success.
  *
  * @return boolean
  */
 function pullRemoteProfile()
 {
     $this->profile_uri = $this->trimmed('profile');
     try {
         if (Validate::email($this->profile_uri)) {
             $this->oprofile = Ostatus_profile::ensureWebfinger($this->profile_uri);
         } else {
             if (Validate::uri($this->profile_uri)) {
                 $this->oprofile = Ostatus_profile::ensureProfileURL($this->profile_uri);
             } else {
                 // TRANS: Error message in OStatus plugin. Do not translate the domain names example.com
                 // TRANS: and example.net, as these are official standard domain names for use in examples.
                 $this->error = _m("Sorry, we could not reach that address. Please make sure that the OStatus address is like nickname@example.com or http://example.net/nickname.");
                 common_debug('Invalid address format.', __FILE__);
                 return false;
             }
         }
         return true;
     } catch (FeedSubBadURLException $e) {
         // TRANS: Error message in OStatus plugin. Do not translate the domain names example.com
         // TRANS: and example.net, as these are official standard domain names for use in examples.
         $this->error = _m('Sorry, we could not reach that address. Please make sure that the OStatus address is like nickname@example.com or http://example.net/nickname.');
         common_debug('Invalid URL or could not reach server.', __FILE__);
     } catch (FeedSubBadResponseException $e) {
         // TRANS: Error text.
         $this->error = _m('Sorry, we could not reach that feed. Please try that OStatus address again later.');
         common_debug('Cannot read feed; server returned error.', __FILE__);
     } catch (FeedSubEmptyException $e) {
         // TRANS: Error text.
         $this->error = _m('Sorry, we could not reach that feed. Please try that OStatus address again later.');
         common_debug('Cannot read feed; server returned an empty page.', __FILE__);
     } catch (FeedSubBadHTMLException $e) {
         // TRANS: Error text.
         $this->error = _m('Sorry, we could not reach that feed. Please try that OStatus address again later.');
         common_debug('Bad HTML, could not find feed link.', __FILE__);
     } catch (FeedSubNoFeedException $e) {
         // TRANS: Error text.
         $this->error = _m("Sorry, we could not reach that feed. Please try that OStatus address again later.");
         common_debug('Could not find a feed linked from this URL.', __FILE__);
     } catch (FeedSubUnrecognizedTypeException $e) {
         // TRANS: Error text.
         $this->error = _m("Sorry, we could not reach that feed. Please try that OStatus address again later.");
         common_debug('Not a recognized feed type.', __FILE__);
     } catch (Exception $e) {
         // Any new ones we forgot about
         // TRANS: Error message in OStatus plugin. Do not translate the domain names example.com
         // TRANS: and example.net, as these are official standard domain names for use in examples.
         $this->error = _m("Sorry, we could not reach that address. Please make sure that the OStatus address is like nickname@example.com or http://example.net/nickname.");
         common_debug(sprintf('Bad feed URL: %s %s', get_class($e), $e->getMessage()), __FILE__);
     }
     return false;
 }
 static function ensureProfileURI($uri)
 {
     $oprofile = null;
     // First, try to query it
     $oprofile = Ostatus_profile::staticGet('uri', $uri);
     // If unfound, do discovery stuff
     if (empty($oprofile)) {
         if (preg_match("/^(\\w+)\\:(.*)/", $uri, $match)) {
             $protocol = $match[1];
             switch ($protocol) {
                 case 'http':
                 case 'https':
                     $oprofile = Ostatus_profile::ensureProfileURL($uri);
                     break;
                 case 'acct':
                 case 'mailto':
                     $rest = $match[2];
                     $oprofile = Ostatus_profile::ensureWebfinger($rest);
                     break;
                 default:
                     throw new ServerException("Unrecognized URI protocol for profile: {$protocol} ({$uri})");
                     break;
             }
         } else {
             throw new ServerException("No URI protocol for profile: ({$uri})");
         }
     }
     return $oprofile;
 }
Example #3
0
 static function ensureProfileURI($uri)
 {
     $oprofile = null;
     // First, try to query it
     $oprofile = Ostatus_profile::staticGet('uri', $uri);
     // If unfound, do discovery stuff
     if (empty($oprofile)) {
         if (preg_match("/^(\\w+)\\:(.*)/", $uri, $match)) {
             $protocol = $match[1];
             switch ($protocol) {
                 case 'http':
                 case 'https':
                     $oprofile = Ostatus_profile::ensureProfileURL($uri);
                     break;
                 case 'acct':
                 case 'mailto':
                     $rest = $match[2];
                     $oprofile = Ostatus_profile::ensureWebfinger($rest);
                     break;
                 default:
                     // TRANS: Server exception.
                     // TRANS: %1$s is a protocol, %2$s is a URI.
                     throw new ServerException(sprintf(_m('Unrecognized URI protocol for profile: %1$s (%2$s).'), $protocol, $uri));
                     break;
             }
         } else {
             // TRANS: Server exception. %s is a URI.
             throw new ServerException(sprintf(_m('No URI protocol for profile: %s.'), $uri));
         }
     }
     return $oprofile;
 }
 protected function pullRemoteProfile($arg)
 {
     $oprofile = null;
     if (preg_match('!^((?:\\w+\\.)*\\w+@(?:\\w+\\.)*\\w+(?:\\w+\\-\\w+)*\\.\\w+)$!', $arg)) {
         // webfinger lookup
         try {
             return Ostatus_profile::ensureWebfinger($arg);
         } catch (Exception $e) {
             common_log(LOG_ERR, 'Webfinger lookup failed for ' . $arg . ': ' . $e->getMessage());
         }
     }
     // Look for profile URLs, with or without scheme:
     $urls = array();
     if (preg_match('!^https?://((?:\\w+\\.)*\\w+(?:\\w+\\-\\w+)*\\.\\w+(?:/\\w+)+)$!', $arg)) {
         $urls[] = $arg;
     }
     if (preg_match('!^((?:\\w+\\.)*\\w+(?:\\w+\\-\\w+)*\\.\\w+(?:/\\w+)+)$!', $arg)) {
         $schemes = array('http', 'https');
         foreach ($schemes as $scheme) {
             $urls[] = "{$scheme}://{$arg}";
         }
     }
     foreach ($urls as $url) {
         try {
             return Ostatus_profile::ensureProfileURL($url);
         } catch (Exception $e) {
             common_log(LOG_ERR, 'Profile lookup failed for ' . $arg . ': ' . $e->getMessage());
         }
     }
     return null;
 }