+
+ 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;
+ }
+ }
+ return FALSE;
+ }
+
+ # XXX: refactor with similar code in finishremotesubscribe.php
+
+ function save_remote_profile(&$req) {
+ # FIXME: we should really do this when the consumer comes
+ # back for an access token. If they never do, we've got stuff in a
+ # weird state.
+
+ $nickname = $req->get_parameter('omb_listenee_nickname');
+ $fullname = $req->get_parameter('omb_listenee_fullname');
+ $profile_url = $req->get_parameter('omb_listenee_profile');
+ $homepage = $req->get_parameter('omb_listenee_homepage');
+ $bio = $req->get_parameter('omb_listenee_bio');
+ $location = $req->get_parameter('omb_listenee_location');
+ $avatar_url = $req->get_parameter('omb_listenee_avatar');
+
+ $listenee = $req->get_parameter('omb_listenee');
+ $remote = Remote_profile::staticGet('uri', $listenee);
+
+ if ($remote) {
+ $exists = true;
+ $profile = Profile::staticGet($remote->id);
+ $orig_remote = clone($remote);
+ $orig_profile = clone($profile);
+ } else {
+ $exists = false;
+ $remote = new Remote_profile();
+ $remote->uri = $listenee;
+ $profile = new Profile();
+ }
+
+ $profile->nickname = $nickname;
+ $profile->profileurl = $profile_url;
+
+ if ($fullname) {
+ $profile->fullname = $fullname;
+ }
+ if ($homepage) {
+ $profile->homepage = $homepage;
+ }
+ if ($bio) {
+ $profile->bio = $bio;
+ }
+ if ($location) {
+ $profile->location = $location;
+ }
+
+ if ($exists) {
+ $profile->update($orig_profile);
+ } else {
+ $profile->created = DB_DataObject_Cast::dateTime(); # current time
+ $id = $profile->insert();
+ if (!$id) {
+ return FALSE;
+ }
+ $remote->id = $id;
+ }
+
+ if ($exists) {
+ if (!$remote->update($orig_remote)) {
+ return FALSE;
+ }
+ } else {
+ $remote->created = DB_DataObject_Cast::dateTime(); # current time
+ if (!$remote->insert()) {
+ return FALSE;
+ }
+ }
+
+ if ($avatar_url) {
+ if (!$this->add_avatar($profile, $avatar_url)) {
+ return FALSE;
+ }
+ }
+
+ $user = common_current_user();
+ $datastore = omb_oauth_datastore();
+ $consumer = $this->get_consumer($datastore, $req);
+ $token = $this->get_token($datastore, $req, $consumer);
+
+ $sub = new Subscription();
+ $sub->subscriber = $user->id;
+ $sub->subscribed = $remote->id;
+ $sub->token = $token->key; # NOTE: request token, not valid for use!
+ $sub->created = DB_DataObject_Cast::dateTime(); # current time
+
+ if (!$sub->insert()) {
+ return FALSE;
+ }
+
+ return TRUE;
+ }
+
+ function add_avatar($profile, $url) {
+ $temp_filename = tempnam(sys_get_temp_dir(), 'listenee_avatar');
+ copy($url, $temp_filename);
+ return $profile->setOriginal($temp_filename);
+ }
+
+ function show_accept_message($tok) {
+ common_show_header(_('Subscription authorized'));
+ common_element('p', NULL,
+ _('The subscription has been authorized, but no '.
+ 'callback URL was passed. Check with the site\'s instructions for '.
+ 'details on how to authorize the subscription. Your subscription token is:'));
+ common_element('blockquote', 'token', $tok);
+ common_show_footer();
+ }
+
+ function show_reject_message($tok) {
+ common_show_header(_('Subscription rejected'));
+ common_element('p', NULL,
+ _('The subscription has been rejected, but no '.
+ 'callback URL was passed. Check with the site\'s instructions for '.
+ 'details on how to fully reject the subscription.'));
+ common_show_footer();
+ }
+