Exemple #1
0
function profile_to_omb_profile($uri, $profile, $force = false)
{
    $omb_profile = new OMB_Profile($uri);
    $omb_profile->setNickname($profile->nickname);
    $omb_profile->setLicenseURL(common_config('license', 'url'));
    if (!is_null($profile->fullname)) {
        $omb_profile->setFullname($profile->fullname);
    } elseif ($force) {
        $omb_profile->setFullname('');
    }
    if (!is_null($profile->homepage)) {
        $omb_profile->setHomepage($profile->homepage);
    } elseif ($force) {
        $omb_profile->setHomepage('');
    }
    if (!is_null($profile->bio)) {
        $omb_profile->setBio($profile->bio);
    } elseif ($force) {
        $omb_profile->setBio('');
    }
    if (!is_null($profile->location)) {
        $omb_profile->setLocation($profile->location);
    } elseif ($force) {
        $omb_profile->setLocation('');
    }
    if (!is_null($profile->profileurl)) {
        $omb_profile->setProfileURL($profile->profileurl);
    } elseif ($force) {
        $omb_profile->setProfileURL('');
    }
    $avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE);
    if ($avatar) {
        $omb_profile->setAvatarURL($avatar->url);
    } elseif ($force) {
        $omb_profile->setAvatarURL('');
    }
    return $omb_profile;
}
 /**
  * Handle an user authorization request.
  *
  * Parses an authorization request. This includes OAuth and OMB
  * verification.
  * Throws exceptions on failures. Returns an OMB_Profile object representing
  * the remote user.
  *
  * The OMB_Profile passed to the constructor of OMB_Service_Provider should
  * not represent the user specified in the authorization request, but the
  * one currently logged in to the service. This condition being satisfied,
  * handleUserAuth will check whether the listener specified in the request
  * is identical to the logged in user.
  *
  * @access public
  *
  * @return OMB_Profile The profile of the soon-to-be subscribed, i. e.
  *                     remote user
  */
 public function handleUserAuth()
 {
     OMB_Helper::removeMagicQuotesFromRequest();
     /* Verify the request token. */
     $this->token = $this->datastore->lookup_token(null, "request", $_GET['oauth_token']);
     if (is_null($this->token)) {
         throw new OAuthException('The given request token has not been ' . 'issued by this service.');
     }
     /* Verify the OMB part. */
     if ($_GET['omb_version'] !== OMB_VERSION) {
         throw OMB_RemoteServiceException::forRequest(OAUTH_ENDPOINT_AUTHORIZE, 'Wrong OMB version ' . $_GET['omb_version']);
     }
     if ($_GET['omb_listener'] !== $this->user->getIdentifierURI()) {
         throw OMB_RemoteServiceException::forRequest(OAUTH_ENDPOINT_AUTHORIZE, 'Wrong OMB listener ' . $_GET['omb_listener']);
     }
     foreach (array('omb_listenee', 'omb_listenee_profile', 'omb_listenee_nickname', 'omb_listenee_license') as $param) {
         if (!isset($_GET[$param]) || is_null($_GET[$param])) {
             throw OMB_RemoteServiceException::forRequest(OAUTH_ENDPOINT_AUTHORIZE, "Required parameter '{$param}' not found");
         }
     }
     /* Store given callback for later use. */
     if (isset($_GET['oauth_callback']) && $_GET['oauth_callback'] !== '') {
         $this->callback = $_GET['oauth_callback'];
         if (!OMB_Helper::validateURL($this->callback)) {
             throw OMB_RemoteServiceException::forRequest(OAUTH_ENDPOINT_AUTHORIZE, 'Invalid callback URL specified');
         }
     }
     $this->remote_user = OMB_Profile::fromParameters($_GET, 'omb_listenee');
     return $this->remote_user;
 }
 /**
  * Inform the service about a profile update
  *
  * Sends an updated profile to the service.
  *
  * @param OMB_Profile $profile The profile that has changed
  *
  * @access public
  */
 public function updateProfile($profile)
 {
     $params = $profile->asParameters('omb_listenee', true);
     $this->performOMBAction(OMB_ENDPOINT_UPDATEPROFILE, $params, $profile->getIdentifierURI());
 }
 /**
  * Builds an OMB_Profile object from array
  *
  * The method builds an OMB_Profile object from the passed parameters array. The
  * array MUST provide a profile URI. The array fields HAVE TO be named according
  * to the OMB standard. The prefix (omb_listener or omb_listenee) is passed as a
  * parameter.
  *
  * @param string $parameters An array containing the profile parameters.
  * @param string $prefix     The common prefix of the profile parameter keys.
  *
  * @access public
  *
  * @returns OMB_Profile The built OMB_Profile.
  */
 public static function fromParameters($parameters, $prefix)
 {
     if (!isset($parameters[$prefix])) {
         throw new OMB_InvalidParameterException('', 'profile', $prefix);
     }
     $profile = new OMB_Profile($parameters[$prefix]);
     $profile->updateFromParameters($parameters, $prefix);
     return $profile;
 }