本文整理汇总了PHP中Foreign_link类的典型用法代码示例。如果您正苦于以下问题:PHP Foreign_link类的具体用法?PHP Foreign_link怎么用?PHP Foreign_link使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Foreign_link类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getByForeignID
static function getByForeignID($foreign_id, $service)
{
$flink = new Foreign_link();
$flink->service = $service;
$flink->foreign_id = $foreign_id;
$flink->limit(1);
if ($flink->find(true)) {
return $flink;
}
return null;
}
示例2: getByForeignID
static function getByForeignID($foreign_id, $service)
{
if (empty($foreign_id) || empty($service)) {
return null;
} else {
$flink = new Foreign_link();
$flink->service = $service;
$flink->foreign_id = $foreign_id;
$flink->limit(1);
$result = $flink->find(true);
return empty($result) ? null : $flink;
}
}
示例3: getByForeignID
static function getByForeignID($foreign_id, $service)
{
if (empty($foreign_id) || empty($service)) {
throw new ServerException('Empty foreign_id or service for Foreign_link::getByForeignID');
}
$flink = new Foreign_link();
$flink->service = $service;
$flink->foreign_id = $foreign_id;
$flink->limit(1);
if (!$flink->find(true)) {
throw new NoResultException($flink);
}
return $flink;
}
示例4: handle
function handle($data)
{
// JSON object with Twitter data
$status = $data['status'];
// Twitter user ID this incoming data belongs to.
$receiver = $data['for_user'];
$importer = new TwitterImport();
$notice = $importer->importStatus($status);
if ($notice instanceof Notice) {
try {
$flink = Foreign_link::getByForeignID($receiver, TWITTER_SERVICE);
common_log(LOG_DEBUG, "TweetInQueueHandler - Got flink so add notice " . $notice->id . " to attentions for user " . $flink->user_id);
try {
Attention::saveNew($notice, $flink->getProfile());
} catch (Exception $e) {
// Log the exception, but make sure we don't bail out, we
// still have a queue item to remove here-after.
common_log(LOG_ERR, "Failed adding notice {$notice->id} to attentions for user {$flink->user_id}: " . $e->getMessage());
}
} catch (NoResultException $e) {
common_log(LOG_DEBUG, "TweetInQueueHandler - No flink found for foreign user " . $receiver);
}
}
return true;
}
示例5: handle
/**
* Handler method
*
* @param array $args is ignored since it's now passed in in prepare()
*/
function handle($args)
{
parent::handle($args);
$data = $this->facebook->getSignedRequest();
if (isset($data['user_id'])) {
$fbuid = $data['user_id'];
$flink = Foreign_link::getByForeignID($fbuid, FACEBOOK_SERVICE);
$user = $flink->getUser();
// Remove the link to Facebook
$result = $flink->delete();
if (!$result) {
common_log_db_error($flink, 'DELETE', __FILE__);
common_log(LOG_WARNING, sprintf('Unable to delete Facebook foreign link ' . 'for %s (%d), fbuid %d', $user->nickname, $user->id, $fbuid), __FILE__);
return;
}
common_log(LOG_INFO, sprintf('Facebook callback: %s (%d), fbuid %d has deauthorized ' . 'the Facebook application.', $user->nickname, $user->id, $fbuid), __FILE__);
// Warn the user about being locked out of their account
// if we can.
if (empty($user->password) && !empty($user->email)) {
Facebookclient::emailWarn($user);
} else {
common_log(LOG_WARNING, sprintf('%s (%d), fbuid %d has deauthorized his/her Facebook ' . 'connection but hasn\'t set a password so s/he ' . 'is locked out.', $user->nickname, $user->id, $fbuid), __FILE__);
}
} else {
if (!empty($data)) {
common_log(LOG_WARNING, sprintf('Facebook called the deauthorize callback ' . ' but didn\'t provide a user ID.'), __FILE__);
} else {
// It probably wasn't Facebook that hit this action,
// so redirect to the public timeline
common_redirect(common_local_url('public'), 303);
}
}
}
示例6: 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;
}
示例7: handle
function handle($args)
{
parent::handle($args);
$secret = common_config('facebook', 'secret');
$sig = '';
ksort($_POST);
foreach ($_POST as $key => $val) {
if (substr($key, 0, 7) == 'fb_sig_') {
$sig .= substr($key, 7) . '=' . $val;
}
}
$sig .= $secret;
$verify = md5($sig);
if ($verify == $this->arg('fb_sig')) {
$flink = Foreign_link::getByForeignID($this->arg('fb_sig_user'), 2);
common_debug("Removing foreign link to Facebook - local user ID: {$flink->user_id}, Facebook ID: {$flink->foreign_id}");
$result = $flink->delete();
if (!$result) {
common_log_db_error($flink, 'DELETE', __FILE__);
$this->serverError(_('Couldn\'t remove Facebook user.'));
return;
}
} else {
# Someone bad tried to remove facebook link?
common_log(LOG_ERR, "Someone from {$_SERVER['REMOTE_ADDR']} " . 'unsuccessfully tried to remove a foreign link to Facebook!');
}
}
示例8: 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;
}
示例9: 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!
}
}
示例10: 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);
}
示例11: prepare
function prepare($argarray)
{
parent::prepare($argarray);
$this->facebook = getFacebook();
$this->fbuid = $this->facebook->require_login();
$this->action = $this->trimmed('action');
$app_props = $this->facebook->api_client->Admin_getAppProperties(array('canvas_name', 'application_name'));
$this->app_uri = 'http://apps.facebook.com/' . $app_props['canvas_name'];
$this->app_name = $app_props['application_name'];
$this->flink = Foreign_link::getByForeignID($this->fbuid, FACEBOOK_SERVICE);
return true;
}
示例12: 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;
}
示例13: __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();
}
}
示例14: 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;
}
示例15: 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;
}