function omb_broadcast_profile($profile) { $user = User::staticGet('id', $profile->id); if (!$user) { return false; } $profile = $user->getProfile(); $omb_profile = profile_to_omb_profile($user->uri, $profile, true); /* Get remote users subscribed to this profile. */ $rp = new Remote_profile(); $rp->query('SELECT remote_profile.*, secret, token ' . 'FROM subscription JOIN remote_profile ' . 'ON subscription.subscriber = remote_profile.id ' . 'WHERE subscription.subscribed = ' . $profile->id . ' '); $posted = array(); while ($rp->fetch()) { if (isset($posted[$rp->updateprofileurl])) { /* We already posted to this url. */ continue; } common_debug('Posting to ' . $rp->updateprofileurl, __FILE__); /* Update profile. */ $service = new StatusNet_OMB_Service_Consumer(array(OMB_ENDPOINT_UPDATEPROFILE => $rp->updateprofileurl), $rp->uri); try { $service->setToken($rp->token, $rp->secret); $service->updateProfile($omb_profile); } catch (Exception $e) { common_log(LOG_ERR, 'Failed posting to ' . $rp->updateprofileurl); common_log(LOG_ERR, 'Error status ' . $e); continue; } $posted[$rp->updateprofileurl] = true; common_debug('Finished to ' . $rp->updateprofileurl, __FILE__); } return; }
function omb_broadcast_remote_subscribers($notice) { # First, get remote users subscribed to this profile $rp = new Remote_profile(); $rp->query('SELECT postnoticeurl, token, secret ' . 'FROM subscription JOIN remote_profile ' . 'ON subscription.subscriber = remote_profile.id ' . 'WHERE subscription.subscribed = ' . $notice->profile_id . ' '); $posted = array(); while ($rp->fetch()) { if (!$posted[$rp->postnoticeurl]) { common_log(LOG_DEBUG, 'Posting to ' . $rp->postnoticeurl); if (omb_post_notice_keys($notice, $rp->postnoticeurl, $rp->token, $rp->secret)) { common_log(LOG_DEBUG, 'Finished to ' . $rp->postnoticeurl); $posted[$rp->postnoticeurl] = true; } else { common_log(LOG_DEBUG, 'Failed posting to ' . $rp->postnoticeurl); } } } $rp->free(); unset($rp); return true; }