function save_notice(&$req, &$consumer, &$token) { $version = $req->get_parameter('omb_version'); if ($version != OMB_VERSION_01) { $this->clientError(_('Unsupported OMB version'), 400); return false; } # First, check to see $listenee = $req->get_parameter('omb_listenee'); $remote_profile = Remote_profile::staticGet('uri', $listenee); if (!$remote_profile) { $this->clientError(_('Profile unknown'), 403); return false; } $sub = Subscription::staticGet('token', $token->key); if (!$sub) { $this->clientError(_('No such subscription'), 403); return false; } $content = $req->get_parameter('omb_notice_content'); $content_shortened = common_shorten_links($content); if (mb_strlen($content_shortened) > 140) { $this->clientError(_('Invalid notice content'), 400); return false; } $notice_uri = $req->get_parameter('omb_notice'); if (!Validate::uri($notice_uri) && !common_valid_tag($notice_uri)) { $this->clientError(_('Invalid notice uri'), 400); return false; } $notice_url = $req->get_parameter('omb_notice_url'); if ($notice_url && !common_valid_http_url($notice_url)) { $this->clientError(_('Invalid notice url'), 400); return false; } $notice = Notice::staticGet('uri', $notice_uri); if (!$notice) { $notice = Notice::saveNew($remote_profile->id, $content, 'omb', false, null, $notice_uri); if (is_string($notice)) { common_server_serror($notice, 500); return false; } common_broadcast_notice($notice, true); } return true; }
function new_access_token($token, $consumer) { common_debug('new_access_token("' . $token->key . '","' . $consumer->key . '")', __FILE__); $rt = new Token(); $rt->consumer_key = $consumer->key; $rt->tok = $token->key; $rt->type = 0; // request if ($rt->find(true) && $rt->state == 1) { // authorized common_debug('request token found.', __FILE__); $at = new Token(); $at->consumer_key = $consumer->key; $at->tok = common_good_rand(16); $at->secret = common_good_rand(16); $at->type = 1; // access $at->created = DB_DataObject_Cast::dateTime(); if (!$at->insert()) { $e = $at->_lastError; common_debug('access token "' . $at->tok . '" not inserted: "' . $e->message . '"', __FILE__); return null; } else { common_debug('access token "' . $at->tok . '" inserted', __FILE__); // burn the old one $orig_rt = clone $rt; $rt->state = 2; // used if (!$rt->update($orig_rt)) { return null; } common_debug('request token "' . $rt->tok . '" updated', __FILE__); // Update subscription // XXX: mixing levels here $sub = Subscription::staticGet('token', $rt->tok); if (!$sub) { return null; } common_debug('subscription for request token found', __FILE__); $orig_sub = clone $sub; $sub->token = $at->tok; $sub->secret = $at->secret; if (!$sub->update($orig_sub)) { return null; } else { common_debug('subscription updated to use access token', __FILE__); return new OAuthToken($at->tok, $at->secret); } } } else { return null; } }
function onEndNoticeAsActivity($notice, &$activity) { switch ($notice->verb) { case ActivityVerb::FAVORITE: $fave = Fave::staticGet('uri', $notice->uri); if (!empty($fave)) { $notice = Notice::staticGet('id', $fave->notice_id); if (!empty($notice)) { $cur = common_current_user(); $target = $notice->asActivity($cur); if ($target->verb == ActivityVerb::POST) { // "I like the thing you posted" $activity->objects = $target->objects; } else { // "I like that you did whatever you did" $activity->objects = array($target); } } } break; case ActivityVerb::UNFAVORITE: // FIXME: do something here break; case ActivityVerb::JOIN: $mem = Group_member::staticGet('uri', $notice->uri); if (!empty($mem)) { $group = $mem->getGroup(); $activity->objects = array(ActivityObject::fromGroup($group)); } break; case ActivityVerb::LEAVE: // FIXME: ???? break; case ActivityVerb::FOLLOW: $sub = Subscription::staticGet('uri', $notice->uri); if (!empty($sub)) { $profile = Profile::staticGet('id', $sub->subscribed); if (!empty($profile)) { $activity->objects = array(ActivityObject::fromProfile($profile)); } } break; case ActivityVerb::UNFOLLOW: // FIXME: ???? break; } return true; }