本文整理汇总了PHP中Foreign_link::getByUserID方法的典型用法代码示例。如果您正苦于以下问题:PHP Foreign_link::getByUserID方法的具体用法?PHP Foreign_link::getByUserID怎么用?PHP Foreign_link::getByUserID使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Foreign_link
的用法示例。
在下文中一共展示了Foreign_link::getByUserID方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: facebookBroadcastNotice
function facebookBroadcastNotice($notice)
{
$facebook = getFacebook();
$flink = Foreign_link::getByUserID($notice->profile_id, FACEBOOK_SERVICE);
$fbuid = $flink->foreign_id;
if (isFacebookBound($notice, $flink)) {
$status = null;
// Get the status 'verb' (prefix) the user has set
try {
$prefix = $facebook->api_client->data_getUserPreference(FACEBOOK_NOTICE_PREFIX, $fbuid);
$status = "{$prefix} {$notice->content}";
} catch (FacebookRestClientException $e) {
common_log(LOG_ERR, $e->getMessage());
return false;
}
// Okay, we're good to go!
try {
$facebook->api_client->users_setStatus($status, $fbuid, false, true);
updateProfileBox($facebook, $flink, $notice);
} catch (FacebookRestClientException $e) {
common_log(LOG_ERR, $e->getMessage());
return false;
// Should we remove flink if this fails?
}
}
return true;
}
示例2: prepare
/**
* For initializing members of the class.
*
* @param array $argarray misc. arguments
*
* @return boolean true
*/
function prepare($args)
{
parent::prepare($args);
$this->facebook = new Facebook(array('appId' => common_config('facebook', 'appid'), 'secret' => common_config('facebook', 'secret'), 'cookie' => true));
$this->user = common_current_user();
$this->flink = Foreign_link::getByUserID($this->user->id, FACEBOOK_SERVICE);
return true;
}
示例3: doPreparation
protected function doPreparation()
{
try {
$this->flink = Foreign_link::getByUserID($this->scoped->getID(), TWITTER_SERVICE);
$this->fuser = $this->flink->getForeignUser();
} catch (NoResultException $e) {
// No foreign link found for this user!
}
}
示例4: twitterAuthForUser
/**
*
* @param User $user
* @return TwitterOAuthClient
*/
function twitterAuthForUser(User $user)
{
$flink = Foreign_link::getByUserID($user->id, TWITTER_SERVICE);
$token = TwitterOAuthClient::unpackToken($flink->credentials);
if (!$token) {
throw new ServerException("No Twitter OAuth credentials for this user.");
}
return new TwitterOAuthClient($token->key, $token->secret);
}
示例5: handle
/**
* Handler method
*
* @param array $args is ignored since it's now passed in in prepare()
*
* @return nothing
*/
function handle($args)
{
parent::handle($args);
if (common_logged_in()) {
$user = common_current_user();
$flink = Foreign_link::getByUserID($user->id, TWITTER_SERVICE);
// If there's already a foreign link record and a foreign user
// it means the accounts are already linked, and this is unecessary.
// So go back.
if (isset($flink)) {
$fuser = $flink->getForeignUser();
if (!empty($fuser)) {
common_redirect(common_local_url('twittersettings'));
}
}
}
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
// User was not logged in to StatusNet before
$this->twuid = $this->trimmed('twuid');
$this->tw_fields = array('screen_name' => $this->trimmed('tw_fields_screen_name'), 'fullname' => $this->trimmed('tw_fields_fullname'));
$this->access_token = new OAuthToken($this->trimmed('access_token_key'), $this->trimmed('access_token_secret'));
$token = $this->trimmed('token');
if (!$token || $token != common_session_token()) {
// TRANS: Client error displayed when the session token does not match or is not given.
$this->showForm(_m('There was a problem with your session token. Try again, please.'));
return;
}
if ($this->arg('create')) {
if (!$this->boolean('license')) {
// TRANS: Form validation error displayed when the checkbox to agree to the license has not been checked.
$this->showForm(_m('You cannot register if you do not agree to the license.'), $this->trimmed('newname'));
return;
}
$this->createNewUser();
} else {
if ($this->arg('connect')) {
$this->connectNewUser();
} else {
common_debug('Twitter bridge - ' . print_r($this->args, true));
// TRANS: Form validation error displayed when an unhandled error occurs.
$this->showForm(_m('Something weird happened.'), $this->trimmed('newname'));
}
}
} else {
// $this->oauth_token is only populated once Twitter authorizes our
// request token. If it's empty we're at the beginning of the auth
// process
if (empty($this->oauth_token)) {
$this->authorizeRequestToken();
} else {
$this->saveAccessToken();
}
}
}
示例6: broadcast_twitter
function broadcast_twitter($notice)
{
$flink = Foreign_link::getByUserID($notice->profile_id, TWITTER_SERVICE);
if (is_twitter_bound($notice, $flink)) {
if (TwitterOAuthClient::isPackedToken($flink->credentials)) {
return broadcast_oauth($notice, $flink);
} else {
return broadcast_basicauth($notice, $flink);
}
}
return true;
}
示例7: __construct
/**
*
* @param Notice $notice the notice to manipulate
* @param Profile $profile local user to act as; if left empty, the notice's poster will be used.
*/
function __construct($notice, $profile = null)
{
$this->facebook = self::getFacebook();
if (empty($this->facebook)) {
throw new FacebookApiException("Could not create Facebook client! Bad application ID or secret?");
}
$this->notice = $notice;
$profile_id = $profile ? $profile->id : $notice->profile_id;
$this->flink = Foreign_link::getByUserID($profile_id, FACEBOOK_SERVICE);
if (!empty($this->flink)) {
$this->user = $this->flink->getUser();
}
}
示例8: facebookBroadcastNotice
function facebookBroadcastNotice($notice)
{
$facebook = getFacebook();
$flink = Foreign_link::getByUserID($notice->profile_id, FACEBOOK_SERVICE);
if (isFacebookBound($notice, $flink)) {
// Okay, we're good to go, update the FB status
$status = null;
$fbuid = $flink->foreign_id;
$user = $flink->getUser();
$attachments = $notice->attachments();
try {
// Get the status 'verb' (prefix) the user has set
// XXX: Does this call count against our per user FB request limit?
// If so we should consider storing verb elsewhere or not storing
$prefix = trim($facebook->api_client->data_getUserPreference(FACEBOOK_NOTICE_PREFIX, $fbuid));
$status = "{$prefix} {$notice->content}";
$can_publish = $facebook->api_client->users_hasAppPermission('publish_stream', $fbuid);
$can_update = $facebook->api_client->users_hasAppPermission('status_update', $fbuid);
if (!empty($attachments) && $can_publish == 1) {
$fbattachment = format_attachments($attachments);
$facebook->api_client->stream_publish($status, $fbattachment, null, null, $fbuid);
common_log(LOG_INFO, "Posted notice {$notice->id} w/attachment " . "to Facebook user's stream (fbuid = {$fbuid}).");
} elseif ($can_update == 1 || $can_publish == 1) {
$facebook->api_client->users_setStatus($status, $fbuid, false, true);
common_log(LOG_INFO, "Posted notice {$notice->id} to Facebook " . "as a status update (fbuid = {$fbuid}).");
} else {
$msg = "Not sending notice {$notice->id} to Facebook " . "because user {$user->nickname} hasn't given the " . 'Facebook app \'status_update\' or \'publish_stream\' permission.';
common_log(LOG_WARNING, $msg);
}
// Finally, attempt to update the user's profile box
if ($can_publish == 1 || $can_update == 1) {
updateProfileBox($facebook, $flink, $notice);
}
} catch (FacebookRestClientException $e) {
$code = $e->getCode();
$msg = "Facebook returned error code {$code}: " . $e->getMessage() . ' - ' . "Unable to update Facebook status (notice {$notice->id}) " . "for {$user->nickname} (user id: {$user->id})!";
common_log(LOG_WARNING, $msg);
if ($code == 100 || $code == 200 || $code == 250) {
// 100 The account is 'inactive' (probably - this is not well documented)
// 200 The application does not have permission to operate on the passed in uid parameter.
// 250 Updating status requires the extended permission status_update or publish_stream.
// see: http://wiki.developers.facebook.com/index.php/Users.setStatus#Example_Return_XML
remove_facebook_app($flink);
} else {
// Try sending again later.
return false;
}
}
}
return true;
}
示例9: facebookBroadcastNotice
function facebookBroadcastNotice($notice)
{
$facebook = getFacebook();
$flink = Foreign_link::getByUserID($notice->profile_id, FACEBOOK_SERVICE);
if (isFacebookBound($notice, $flink)) {
// Okay, we're good to go, update the FB status
$fbuid = $flink->foreign_id;
$user = $flink->getUser();
try {
// Check permissions
common_debug('FacebookPlugin - checking for publish_stream permission for user ' . "{$user->nickname} ({$user->id}), Facebook UID: {$fbuid}");
// NOTE: $facebook->api_client->users_hasAppPermission('publish_stream', $fbuid)
// has been returning bogus results, so we're using FQL to check for
// publish_stream permission now
$fql = "SELECT publish_stream FROM permissions WHERE uid = {$fbuid}";
$result = $facebook->api_client->fql_query($fql);
$canPublish = 0;
if (!empty($result)) {
$canPublish = $result[0]['publish_stream'];
}
if ($canPublish == 1) {
common_debug("FacebookPlugin - {$user->nickname} ({$user->id}), Facebook UID: {$fbuid} " . 'has publish_stream permission.');
} else {
common_debug("FacebookPlugin - {$user->nickname} ({$user->id}), Facebook UID: {$fbuid} " . 'does NOT have publish_stream permission. Facebook ' . 'returned: ' . var_export($result, true));
}
common_debug('FacebookPlugin - checking for status_update permission for user ' . "{$user->nickname} ({$user->id}), Facebook UID: {$fbuid}. ");
$canUpdate = $facebook->api_client->users_hasAppPermission('status_update', $fbuid);
if ($canUpdate == 1) {
common_debug("FacebookPlugin - {$user->nickname} ({$user->id}), Facebook UID: {$fbuid} " . 'has status_update permission.');
} else {
common_debug("FacebookPlugin - {$user->nickname} ({$user->id}), Facebook UID: {$fbuid} " . 'does NOT have status_update permission. Facebook ' . 'returned: ' . var_export($canPublish, true));
}
// Post to Facebook
if ($notice->hasAttachments() && $canPublish == 1) {
publishStream($notice, $user, $fbuid);
} elseif ($canUpdate == 1 || $canPublish == 1) {
statusUpdate($notice, $user, $fbuid);
} else {
$msg = "FacebookPlugin - Not sending notice {$notice->id} to Facebook " . "because user {$user->nickname} has not given the " . 'Facebook app \'status_update\' or \'publish_stream\' permission.';
common_log(LOG_WARNING, $msg);
}
// Finally, attempt to update the user's profile box
if ($canPublish == 1 || $canUpdate == 1) {
updateProfileBox($facebook, $flink, $notice, $user);
}
} catch (FacebookRestClientException $e) {
return handleFacebookError($e, $notice, $flink);
}
}
return true;
}
示例10: __construct
/**
*
* @param Notice $notice the notice to manipulate
* @param Profile $profile local user to act as; if left empty, the notice's poster will be used.
*/
function __construct($notice, $profile = null)
{
$this->facebook = self::getFacebook();
if (empty($this->facebook)) {
throw new FacebookApiException("Could not create Facebook client! Bad application ID or secret?");
}
$this->notice = $notice;
$profile_id = $profile ? $profile->id : $notice->profile_id;
try {
$this->flink = Foreign_link::getByUserID($profile_id, FACEBOOK_SERVICE);
$this->user = $this->flink->getUser();
} catch (NoResultException $e) {
// at least $this->flink could've gotten set to something,
// but the logic that was here before didn't care, so let's not care either
}
}
示例11: doPreparation
protected function doPreparation()
{
$this->oauth_token = $this->arg('oauth_token');
$this->verifier = $this->arg('oauth_verifier');
if ($this->scoped instanceof Profile) {
try {
$flink = Foreign_link::getByUserID($this->scoped->getID(), TWITTER_SERVICE);
$fuser = $flink->getForeignUser();
// If there's already a foreign link record and a foreign user
// (no exceptions were thrown when fetching either of them...)
// it means the accounts are already linked, and this is unecessary.
// So go back.
common_redirect(common_local_url('twittersettings'));
} catch (NoResultException $e) {
// but if we don't have a foreign user linked, let's continue authorization procedure.
}
}
}
示例12: doPreparation
protected function doPreparation()
{
$this->facebook = new Facebook(array('appId' => common_config('facebook', 'appid'), 'secret' => common_config('facebook', 'secret'), 'cookie' => true));
$this->flink = Foreign_link::getByUserID($this->scoped->getID(), FACEBOOK_SERVICE);
}
示例13: onEndDisfavorNotice
/**
* Notify remote users when their notices get de-favorited.
*
* @param Profile $profile Profile person doing the de-faving
* @param Notice $notice Notice being favored
*
* @return hook return value
*/
function onEndDisfavorNotice(Profile $profile, Notice $notice)
{
$flink = Foreign_link::getByUserID($profile->id, TWITTER_SERVICE);
// twitter service
if (empty($flink)) {
return true;
}
if (!TwitterOAuthClient::isPackedToken($flink->credentials)) {
$this->log(LOG_INFO, "Skipping fave processing for {$profile->id} since link is not OAuth.");
return true;
}
$status_id = twitter_status_id($notice);
if (empty($status_id)) {
return true;
}
$token = TwitterOAuthClient::unpackToken($flink->credentials);
$client = new TwitterOAuthClient($token->key, $token->secret);
$client->favoritesDestroy($status_id);
return true;
}
示例14: savePreferences
/**
* Save user's Twitter-bridging preferences
*
* @return void
*/
function savePreferences()
{
$noticesend = $this->boolean('noticesend');
$noticerecv = $this->boolean('noticerecv');
$friendsync = $this->boolean('friendsync');
$replysync = $this->boolean('replysync');
$user = common_current_user();
$flink = Foreign_link::getByUserID($user->id, TWITTER_SERVICE);
if (empty($flink)) {
common_log_db_error($flink, 'SELECT', __FILE__);
$this->showForm(_m('Couldn\'t save Twitter preferences.'));
return;
}
$original = clone $flink;
$flink->set_flags($noticesend, $noticerecv, $replysync, $friendsync);
$result = $flink->update($original);
if ($result === false) {
common_log_db_error($flink, 'UPDATE', __FILE__);
$this->showForm(_m('Couldn\'t save Twitter preferences.'));
return;
}
$this->showForm(_m('Twitter preferences saved.'), true);
}
示例15: onEndShowHeadElements
public function onEndShowHeadElements(Action $action)
{
if ($action instanceof ShowNoticeAction) {
// Showing a notice
$notice = Notice::getKV('id', $action->arg('notice'));
try {
$flink = Foreign_link::getByUserID($notice->profile_id, TWITTER_SERVICE);
$fuser = Foreign_user::getForeignUser($flink->foreign_id, TWITTER_SERVICE);
} catch (NoResultException $e) {
return true;
}
$statusId = twitter_status_id($notice);
if ($notice instanceof Notice && $notice->isLocal() && $statusId) {
$tweetUrl = 'https://twitter.com/' . $fuser->nickname . '/status/' . $statusId;
$action->element('link', array('rel' => 'syndication', 'href' => $tweetUrl));
}
}
if (!$action instanceof AttachmentAction) {
return true;
}
/* Twitter card support. See https://dev.twitter.com/docs/cards */
/* @fixme: should we display twitter cards only for attachments posted
* by local users ? Seems mandatory to display twitter:creator
*
* Author: jbfavre
*/
switch ($action->attachment->mimetype) {
case 'image/pjpeg':
case 'image/jpeg':
case 'image/jpg':
case 'image/png':
case 'image/gif':
$action->element('meta', array('name' => 'twitter:card', 'content' => 'photo'), null);
$action->element('meta', array('name' => 'twitter:url', 'content' => common_local_url('attachment', array('attachment' => $action->attachment->id))), null);
$action->element('meta', array('name' => 'twitter:image', 'content' => $action->attachment->url));
$action->element('meta', array('name' => 'twitter:title', 'content' => $action->attachment->title));
$ns = new AttachmentNoticeSection($action);
$notices = $ns->getNotices();
$noticeArray = $notices->fetchAll();
// Should not have more than 1 notice for this attachment.
if (count($noticeArray) != 1) {
break;
}
$post = $noticeArray[0];
try {
$flink = Foreign_link::getByUserID($post->profile_id, TWITTER_SERVICE);
$fuser = Foreign_user::getForeignUser($flink->foreign_id, TWITTER_SERVICE);
$action->element('meta', array('name' => 'twitter:creator', 'content' => '@' . $fuser->nickname));
} catch (NoResultException $e) {
// no foreign link and/or user for Twitter on this profile ID
}
break;
default:
break;
}
return true;
}