+ common_text($fullname);
+ }
+ common_element_end('div');
+ }
+ if ($location) {
+ common_element('div', 'location', $location);
+ }
+ if ($bio) {
+ common_element('div', 'bio', $bio);
+ }
+ common_element_start('div', 'license');
+ common_element('a', array('href' => $license,
+ 'class' => 'license'),
+ $license);
+ common_element_end('div');
+ common_element_end('div');
+ common_element_start('form', array('method' => 'post',
+ 'id' => 'userauthorization',
+ 'name' => 'userauthorization',
+ 'action' => common_local_url('userauthorization')));
+ common_hidden('token', common_session_token());
+ common_submit('accept', _('Accept'));
+ common_submit('reject', _('Reject'));
+ common_element_end('form');
+ common_show_footer();
+ }
+
+ function send_authorization() {
+ $req = $this->get_stored_request();
+
+ if (!$req) {
+ common_user_error(_('No authorization request!'));
+ return;
+ }
+
+ $callback = $req->get_parameter('oauth_callback');
+
+ if ($this->arg('accept')) {
+ if (!$this->authorize_token($req)) {
+ $this->client_error(_('Error authorizing token'));
+ }
+ if (!$this->save_remote_profile($req)) {
+ $this->client_error(_('Error saving remote profile'));
+ }
+ if (!$callback) {
+ $this->show_accept_message($req->get_parameter('oauth_token'));
+ } else {
+ $params = array();
+ $params['oauth_token'] = $req->get_parameter('oauth_token');
+ $params['omb_version'] = OMB_VERSION_01;
+ $user = User::staticGet('uri', $req->get_parameter('omb_listener'));
+ $profile = $user->getProfile();
+ if (!$profile) {
+ common_log_db_error($user, 'SELECT', __FILE__);
+ $this->server_error(_('User without matching profile'));
+ return;
+ }
+ $params['omb_listener_nickname'] = $user->nickname;
+ $params['omb_listener_profile'] = common_local_url('showstream',
+ array('nickname' => $user->nickname));
+ if ($profile->fullname) {
+ $params['omb_listener_fullname'] = $profile->fullname;
+ }
+ if ($profile->homepage) {
+ $params['omb_listener_homepage'] = $profile->homepage;
+ }
+ if ($profile->bio) {
+ $params['omb_listener_bio'] = $profile->bio;
+ }
+ if ($profile->location) {
+ $params['omb_listener_location'] = $profile->location;
+ }
+ $avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE);
+ if ($avatar) {
+ $params['omb_listener_avatar'] = $avatar->url;
+ }
+ $parts = array();
+ foreach ($params as $k => $v) {
+ $parts[] = $k . '=' . OAuthUtil::urlencodeRFC3986($v);
+ }
+ $query_string = implode('&', $parts);
+ $parsed = parse_url($callback);
+ $url = $callback . (($parsed['query']) ? '&' : '?') . $query_string;
+ common_redirect($url, 303);
+ }
+ } else {
+ if (!$callback) {
+ $this->show_reject_message();
+ } else {
+ # XXX: not 100% sure how to signal failure... just redirect without token?
+ common_redirect($callback, 303);
+ }
+ }
+ }
+
+ function authorize_token(&$req) {
+ $consumer_key = $req->get_parameter('oauth_consumer_key');
+ $token_field = $req->get_parameter('oauth_token');
+ common_debug('consumer key = "'.$consumer_key.'"', __FILE__);
+ common_debug('token field = "'.$token_field.'"', __FILE__);
+ $rt = new Token();
+ $rt->consumer_key = $consumer_key;
+ $rt->tok = $token_field;
+ $rt->type = 0;
+ $rt->state = 0;
+ common_debug('request token to look up: "'.print_r($rt,TRUE).'"');
+ if ($rt->find(true)) {
+ common_debug('found request token to authorize', __FILE__);
+ $orig_rt = clone($rt);
+ $rt->state = 1; # Authorized but not used
+ if ($rt->update($orig_rt)) {
+ common_debug('updated request token so it is authorized', __FILE__);
+ return true;