コード例 #1
0
 function remoteSubscription()
 {
     if (!$this->nickname) {
         $this->showForm(_('No such user.'));
         return;
     }
     $user = User::staticGet('nickname', $this->nickname);
     $this->profile_url = $this->trimmed('profile_url');
     if (!$this->profile_url) {
         $this->showForm(_('No such user.'));
         return;
     }
     if (!common_valid_http_url($this->profile_url)) {
         $this->showForm(_('Invalid profile URL (bad format)'));
         return;
     }
     try {
         $service = new OMB_Service_Consumer($this->profile_url, common_root_url(), omb_oauth_datastore());
     } catch (OMB_InvalidYadisException $e) {
         $this->showForm(_('Not a valid profile URL (no YADIS document or ' . 'invalid XRDS defined).'));
         return;
     }
     if ($service->getServiceURI(OAUTH_ENDPOINT_REQUEST) == common_local_url('requesttoken') || User::staticGet('uri', $service->getRemoteUserURI())) {
         $this->showForm(_('That’s a local profile! Login to subscribe.'));
         return;
     }
     try {
         $service->requestToken();
     } catch (OMB_RemoteServiceException $e) {
         $this->showForm(_('Couldn’t get a request token.'));
         return;
     }
     /* Create an OMB_Profile from $user. */
     $profile = $user->getProfile();
     if (!$profile) {
         common_log_db_error($user, 'SELECT', __FILE__);
         $this->serverError(_('User without matching profile.'));
         return;
     }
     $target_url = $service->requestAuthorization(profile_to_omb_profile($user->uri, $profile), common_local_url('finishremotesubscribe'));
     common_ensure_session();
     $_SESSION['oauth_authorization_request'] = serialize($service);
     /* Redirect to the remote service for authorization. */
     common_redirect($target_url, 303);
 }
コード例 #2
0
 /**
  * Publish a profile update
  *
  * Posts the current profile as an OMB profile update. This includes
  * updating the stored profile and posting it to subscribed users.
  *
  * @access public
  *
  * @return array An array mapping subscriber URIs to the exception posting
  *               to them has raised; Empty array if no exception occured
  */
 public function updateProfile()
 {
     $uri = $this->user->getIdentifierURI();
     $this->datastore->saveProfile($this->user);
     $subscribers = $this->datastore->getSubscriptions($uri);
     /* No one to post to. */
     if (is_null($subscribers)) {
         return array();
     }
     require_once 'service_consumer.php';
     $err = array();
     foreach ($subscribers as $subscriber) {
         try {
             $service = new OMB_Service_Consumer($subscriber['uri'], $uri, $this->datastore);
             $service->setToken($subscriber['token'], $subscriber['secret']);
             $service->updateProfile($this->user);
         } catch (Exception $e) {
             $err[$subscriber['uri']] = $e;
             continue;
         }
     }
     return $err;
 }