本文整理汇总了PHP中Foreign_link::getByForeignID方法的典型用法代码示例。如果您正苦于以下问题:PHP Foreign_link::getByForeignID方法的具体用法?PHP Foreign_link::getByForeignID怎么用?PHP Foreign_link::getByForeignID使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Foreign_link
的用法示例。
在下文中一共展示了Foreign_link::getByForeignID方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
示例2: 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);
}
}
}
示例3: 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!');
}
}
示例4: 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;
}
示例5: 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) {
$flink = Foreign_link::getByForeignID(TWITTER_SERVICE, $receiver);
if ($flink) {
// @fixme this should go through more regular channels?
Inbox::insertNotice($flink->user_id, $notice->id);
}
}
return true;
}
示例6: 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) {
$flink = Foreign_link::getByForeignID($receiver, TWITTER_SERVICE);
if ($flink) {
common_log(LOG_DEBUG, "TweetInQueueHandler - Got flink so add notice " . $notice->id . " to inbox " . $flink->user_id);
// @fixme this should go through more regular channels?
Inbox::insertNotice($flink->user_id, $notice->id);
} else {
common_log(LOG_DEBUG, "TweetInQueueHandler - No flink found for foreign user " . $receiver);
}
}
return true;
}
示例7: save_twitter_friends
function save_twitter_friends($user, $twitter_id, $screen_name, $password)
{
$friends = retreive_twitter_friends($twitter_id, $screen_name, $password);
if (is_null($friends)) {
common_debug("Twitter bridge - Couldn't get friends data from Twitter.");
return false;
}
foreach ($friends as $friend) {
$friend_name = $friend->screen_name;
$friend_id = $friend->id;
// Update or create the Foreign_user record
if (!save_twitter_user($friend_id, $friend_name)) {
return false;
}
// Check to see if there's a related local user
$flink = Foreign_link::getByForeignID($friend_id, 1);
if ($flink) {
// Get associated user and subscribe her
$friend_user = User::staticGet('id', $flink->user_id);
subs_subscribe_to($user, $friend_user);
common_debug("Twitter bridge - subscribed {$friend_user->nickname} to {$user->nickname}.");
}
}
return true;
}
示例8: saveStatusMentions
function saveStatusMentions($notice, $status)
{
$mentions = array();
if (empty($status->entities) || empty($status->entities->user_mentions)) {
return;
}
foreach ($status->entities->user_mentions as $mention) {
$flink = Foreign_link::getByForeignID($mention->id, TWITTER_SERVICE);
if (!empty($flink)) {
$user = User::staticGet('id', $flink->user_id);
if (!empty($user)) {
$reply = new Reply();
$reply->notice_id = $notice->id;
$reply->profile_id = $user->id;
$reply->modified = $notice->created;
common_log(LOG_INFO, __METHOD__ . ": saving reply: notice {$notice->id} to profile {$user->id}");
$id = $reply->insert();
}
}
}
}
示例9: subscribeTwitterFriends
function subscribeTwitterFriends($flink)
{
$friends = $this->fetchTwitterFriends($flink);
if (empty($friends)) {
common_debug($this->name() . ' - Couldn\'t get friends from Twitter for ' . "Twitter user {$flink->foreign_id}.");
return false;
}
$user = $flink->getUser();
foreach ($friends as $friend) {
$friend_name = $friend->screen_name;
$friend_id = (int) $friend->id;
// Update or create the Foreign_user record for each
// Twitter friend
if (!save_twitter_user($friend_id, $friend_name)) {
common_log(LOG_WARNING, $this->name() . " - Couldn't save {$screen_name}'s friend, {$friend_name}.");
continue;
}
// Check to see if there's a related local user
$friend_flink = Foreign_link::getByForeignID($friend_id, TWITTER_SERVICE);
if (!empty($friend_flink)) {
// Get associated user and subscribe her
$friend_user = User::staticGet('id', $friend_flink->user_id);
if (!empty($friend_user)) {
$result = subs_subscribe_to($user, $friend_user);
if ($result === true) {
common_log(LOG_INFO, $this->name() . ' - Subscribed ' . "{$friend_user->nickname} to {$user->nickname}.");
} else {
common_debug($this->name() . ' - Tried subscribing ' . "{$friend_user->nickname} to {$user->nickname} - " . $result);
}
}
}
}
return true;
}
示例10: tryLogin
function tryLogin()
{
common_debug('TwitterBridge Plugin - ' . "Trying login for Twitter user {$this->twuid}.");
$flink = Foreign_link::getByForeignID($this->twuid, TWITTER_SERVICE);
if (!empty($flink)) {
$user = $flink->getUser();
if (!empty($user)) {
common_debug('TwitterBridge Plugin - ' . "Logged in Twitter user {$flink->foreign_id} as user {$user->id} ({$user->nickname})");
common_set_user($user);
common_real_login(true);
$this->goHome($user->nickname);
}
} else {
common_debug('TwitterBridge Plugin - ' . "No flink found for twuid: {$this->twuid} - new user");
$this->showForm(null, $this->bestNewNickname());
}
}
示例11: tryLogin
function tryLogin()
{
common_debug("Trying Facebook Login...");
$flink = Foreign_link::getByForeignID($this->fbuid, FACEBOOK_CONNECT_SERVICE);
if ($flink) {
$user = $flink->getUser();
if (!empty($user)) {
common_debug("Logged in Facebook user {$flink->foreign_id} as user {$user->id} ({$user->nickname})");
common_set_user($user);
common_real_login(true);
$this->goHome($user->nickname);
}
} else {
common_debug("No flink found for fbuid: {$this->fbuid}");
$this->showForm(null, $this->bestNewNickname());
}
}
示例12: subscribeTwitterFriends
function subscribeTwitterFriends(Foreign_link $flink)
{
try {
$profile = $flink->getProfile();
} catch (NoResultException $e) {
common_log(LOG_WARNING, 'Foreign_link has no matching local profile for local ID: ' . $flink->user_id);
}
$friends = $this->fetchTwitterFriends($flink);
if (empty($friends)) {
common_debug($this->name() . ' - Couldn\'t get friends from Twitter for ' . "Twitter user {$flink->foreign_id}.");
return false;
}
foreach ($friends as $friend) {
$friend_name = $friend->screen_name;
$friend_id = (int) $friend->id;
// Update or create the Foreign_user record for each
// Twitter friend
if (!save_twitter_user($friend_id, $friend_name)) {
common_log(LOG_WARNING, $this->name() . " - Couldn't save {$screen_name}'s friend, {$friend_name}.");
continue;
}
// Check to see if there's a related local user and try to subscribe
try {
$friend_flink = Foreign_link::getByForeignID($friend_id, TWITTER_SERVICE);
// Get associated user and subscribe her
$friend_profile = $friend_flink->getProfile();
Subscription::start($profile, $friend_profile);
common_log(LOG_INFO, $this->name() . ' - Subscribed ' . "{$friend_profile->nickname} to {$profile->nickname}.");
} catch (NoResultException $e) {
// either no foreign link for this friend's foreign ID or no profile found on local ID.
} catch (Exception $e) {
common_debug($this->name() . ' - Tried and failed subscribing ' . "{$friend_profile->nickname} to {$profile->nickname} - " . $e->getMessage());
}
}
return true;
}
示例13: saveStatusMentions
function saveStatusMentions($notice, $status)
{
$mentions = array();
if (empty($status->entities) || empty($status->entities->user_mentions)) {
return;
}
foreach ($status->entities->user_mentions as $mention) {
try {
$flink = Foreign_link::getByForeignID($mention->id, TWITTER_SERVICE);
$user = $flink->getUser();
$reply = new Reply();
$reply->notice_id = $notice->id;
$reply->profile_id = $user->id;
$reply->modified = $notice->created;
common_log(LOG_INFO, __METHOD__ . ": saving reply: notice {$notice->id} to profile {$user->id}");
$id = $reply->insert();
} catch (NoSuchUserException $e) {
common_log(LOG_WARNING, 'No local user found for Foreign_link with id: ' . $mention->id);
} catch (NoResultException $e) {
common_log(LOG_WARNING, 'No foreign link or profile found for Foreign_link with id: ' . $mention->id);
}
}
}
示例14: tryLogin
function tryLogin()
{
$flink = Foreign_link::getByForeignID($this->fbuid, FACEBOOK_SERVICE);
if (!empty($flink)) {
$user = $flink->getUser();
if (!empty($user)) {
common_log(LOG_INFO, sprintf('Logged in Facebook user %s as user %d (%s)', $this->fbuid, $user->nickname, $user->id), __FILE__);
common_set_user($user);
common_real_login(true);
// clear out the stupid cookie
setcookie('fb_access_token', '', time() - 3600);
// one hour ago
$this->goHome($user->nickname);
}
} else {
$this->showForm(null, $this->bestNewNickname());
}
}
示例15: tryLogin
function tryLogin()
{
common_debug(sprintf('Trying login for Facebook user %s', $this->fbuid), __FILE__);
$flink = Foreign_link::getByForeignID($this->fbuid, FACEBOOK_SERVICE);
if (!empty($flink)) {
$user = $flink->getUser();
if (!empty($user)) {
common_log(LOG_INFO, sprintf('Logged in Facebook user %s as user %d (%s)', $this->fbuid, $user->nickname, $user->id), __FILE__);
common_set_user($user);
common_real_login(true);
$this->goHome($user->nickname);
}
} else {
common_debug(sprintf('No flink found for fbuid: %s - new user', $this->fbuid), __FILE__);
$this->showForm(null, $this->bestNewNickname());
}
}