public static function newInstance() { if (!self::$instance instanceof self) { self::$instance = new self(); } return self::$instance; }
public function getFacebookData($fbProfiles) { if (count($fbProfiles) > 0) { $accessTokenData = RedSocialStreamHelper::getFacebookAccessToken(); include_once JPATH_COMPONENT . '/helpers/facebook/user.php'; $fbUser = new FacebookUser(); $fbDataList = array(); foreach ($fbProfiles as $key => $profile) { if (isset($accessTokenData->access_token) && !empty($accessTokenData->access_token)) { $fbFeedList = $fbUser->getFeeds($profile['title'], $accessTokenData->access_token); if (!empty($fbFeedList->data) && count($fbFeedList->data) > 0) { foreach ($fbFeedList->data as $feed) { $fbDataList[$profile['id']]['data'] = $feed; $fbDataList[$profile['id']]['created_time'] = strtotime($feed->created_time); $fbDataList[$profile['id']]['type'] = FACEBOOK; $fbDataList[$profile['id']]['ext_post_name'] = addslashes($feed->from->name); $fbDataList[$profile['id']]['ext_profile_id'] = addslashes($feed->from->id); $fbDataList[$profile['id']]['ext_post_id'] = addslashes($feed->id); $fbDataList[$profile['id']]['message'] = ""; if (isset($feed->message)) { $fbDataList[$profile['id']]['message'] = $feed->message; } if (isset($feed->story)) { $fbDataList[$profile['id']]['message'] .= $feed->story; } if (isset($fbDataList[$profile['id']]['message'])) { preg_match_all('/(http|https)\\:\\/\\/[a-zA-Z0-9\\-\\.]+\\.[a-zA-Z]{2,3}[^<]*/', str_replace("\n", "<br />", $fbDataList[$profile['id']]['message']), $out, PREG_PATTERN_ORDER); foreach ($out[0] as $link) { $fbDataList[$profile['id']]['message'] = str_replace($link, "<a href=\"" . $link . "\">" . $link . "</a>", $fbDataList[$profile['id']]['message']); } } if (isset($feed->picture)) { $fbDataList[$profile['id']]['message'] .= "<div class=\"description_image facebook\">"; $fbDataList[$profile['id']]['message'] .= "<img src=\"" . $feed->picture . "\">"; $fbDataList[$profile['id']]['message'] .= "</div>"; } $fbDataList[$profile['id']]['message'] = addslashes($fbDataList[$profile['id']]['message']); $fbDataList[$profile['id']]['title'] = ''; $fbDataList[$profile['id']]['source_link'] = "kildelink"; $fbDataList[$profile['id']]['created_time'] = date("Y-m-d H:i:s", strtotime($feed->created_time)); $fbDataList[$profile['id']]['duration'] = ''; $fbDataList[$profile['id']]['profile_id'] = $key; $fbDataList[$profile['id']]['group_id'] = $profile['group_id']; $fbDataList[$profile['id']]['published'] = 1; $fbDataList[$profile['id']]['thumb_uri'] = ''; } } } } return $fbDataList; } }
public function getUser($login) { if (empty($login)) { return new AnonymousUser(); } //use the cache if available. Don't use the cache for the special me user if ($this->useCache && $login != 'me') { $cacheFilename = "user_$login"; if ($this->cache === NULL) { $this->cache = new DiskCache(CACHE_DIR . "/Facebook", $this->cacheLifetime, TRUE); $this->cache->setSuffix('.json'); $this->cache->preserveFormat(); } if ($this->cache->isFresh($cacheFilename)) { $data = $this->cache->read($cacheFilename); } else { //get the data $url = sprintf("https://graph.facebook.com/%s?%s", $login, http_build_query(array( 'fields'=>'id,first_name,last_name,email,picture,gender', 'access_token'=>$this->access_token ))); if ($data = @file_get_contents($url)) { $this->cache->write($data, $cacheFilename); } } } else { //get the data $url = sprintf("https://graph.facebook.com/%s?%s", $login, http_build_query(array( 'fields'=>'id,first_name,last_name,email,picture,gender', 'access_token'=>$this->access_token ))); $data = @file_get_contents($url); } if ($data) { $json = @json_decode($data, true); if (isset($json['id'])) { $user = new FacebookUser($this); $user->setUserID($json['id']); $user->setFirstName($json['first_name']); $user->setLastName($json['last_name']); if (isset($json['email'])) { $user->setEmail($json['email']); } return $user; } } return false; }
public function authenticate(CakeRequest $request, CakeResponse $response) { $this->loadSettings(); $session = new CakeSession(); if (isset($request->query) && isset($request->query['code']) && isset($request->query['state'])) { if ($request->query['state'] == $session->read('state')) { $token_url = "https://graph.facebook.com/oauth/access_token?" . "client_id=" . $this->settings["app_id"] . "&redirect_uri=" . urlencode($this->settings["url"]) . "&client_secret=" . $this->settings["app_secret"] . "&code=" . $request->query['code']; //TODO: use cake method to make request $response = file_get_contents($token_url); $params = null; parse_str($response, $params); if (isset($params['access_token'])) { // Saves acces_token in Session //TODO: use cake method to save in session $_SESSION['access_token'] = $params['access_token']; // Get's user data from Facebook App::uses('FacebookUser', 'Facebook.Model'); $FacebookUser = new FacebookUser(); $FacebookUser->recursive = -1; $fb_user = $FacebookUser->getLoginData(); // Checks if user exists, if not saves it in db App::uses('User', 'Model'); $User = new User(); $user = $User->find("first", array("conditions" => array("User.uid" => $fb_user['FacebookUser']['uid']))); if (empty($user)) { $user = $FacebookUser->parseDataForDb($fb_user); $User->create(); $User->save($user); $user["User"]["id"] = $User->getLastInsertID(); } return $user["User"]; } } } return false; }
/** * Returns true if the specified Facebook user (default to current one) can * edit properties for the application. The user must be an administrator * or developer of the app and must also be an administrator of the wiki. */ function canEdit($fbUser = NULL) { global $facebook, $wgUser; if (!$fbUser instanceof FacebookUser) { $fbUser = new FacebookUser(); } // First, check MediaWiki permissions. Then check with Facebook if ($fbUser->getMWUser()->getId() == 0 || $fbUser->getMWUser()->getId() != $wgUser->getId()) { return false; } // If $wgFbUserRightsFromGroups is set, this should trigger a group check $groups = $fbUser->getMWUser()->getEffectiveGroups(); if (!in_array('sysop', $groups) && !in_array('fb-admin', $groups)) { return false; } // Check that the Facebook user has a development role with the application $roles = $this->getRoles(); if (!in_array($fbUser->getId(), $roles['administrators']) && !in_array($fbUser->getId(), $roles['developers'])) { return false; } return true; }
function insert_facebook_user_data($userId, $facebookId) { FacebookUser::newInstance()->insertFacebookUserData($userId, $facebookId); }
/** * If $wgFbDisableLogin is set, make sure the user gets logged out if their * Facebook session is destroyed. * * This hook was added in MediaWiki 1.14. */ static function UserLoadAfterLoadFromSession($user) { global $wgFbDisableLogin; // Don't mess with authentication on Special:Connect $title = $user->getSkin()->getTitle(); if (!empty($wgFbDisableLogin) && $user->isLoggedIn() && $title instanceof Title && !$title->isSpecial('Connect')) { $fbUser = new FacebookUser(); // If possible, force a preemptive ping to Facebook's servers. Otherwise, we // must wait until the next page view to pick up the user's Facebook login status #$fbUser->isLoggedIn($ping = true); if (!$fbUser->isLoggedIn() || $user->getId() != $fbUser->getMWUser()->getId()) { $user->logout(); } } return true; }
private function parseUser($entry) { $user = new FacebookUser(); $user->setUserID($entry['id']); $user->setName($entry['name']); $user->setImageURL(ImageLoader::cacheImage('https://graph.facebook.com/' . $entry['id'] . '/picture?type=square', array())); return $user; }
public function execute() { global $wgFbStreamlineLogin; if (!empty($wgFbStreamlineLogin)) { $params = $this->extractRequestParams(); $fbUser = new FacebookUser($params['id']); $id = $fbUser->getMWUser()->getId(); if ($id) { //wfLoadExtensionMessages('Facebook'); // Deprecated since 1.16 $specialConnect = new SpecialConnect(); $this->getResult()->addValue(null, null, $specialConnect->getLogoutAndContinueForm($params, $id)); } else { // TODO: Add a LogoutAndCreateNewUser form to SpecialConnect.php. For // now, return an empty response to send user to Special:Connect // (which displays an error message). } } }
/** * Remove the watch action from the user's Timeline when they unwatch an * article. */ public static function UnwatchArticleComplete(&$user, &$article) { global $facebook; if (self::getAction('watch')) { $fbUser = new FacebookUser(); if ($fbUser->getMWUser()->getId() == $user->getId()) { $object = FacebookOpenGraph::newObjectFromTitle($article->getTitle()); try { self::removeAction('watch', $object); } catch (FacebookApiException $e) { // echo $e->getType() . ": " . $e->getMessage() . "<br/>\n"; } } } return true; }
/** * This error page is shown when the user logs in to Facebook, but the * Facebook account is associated with a different user. * * A precondition is that a different MediaWiki user is logged in. So, ask * them to log out and continue. * * TODO: But what about the case where a Facebook user is logged in, but * not as a wiki user, and then logs into the wiki with the wrong account? */ private function logoutAndContinueView($userId) { global $wgOut; $wgOut->setPageTitle(wfMsg('facebook-logout-and-continue')); $fbUser = new FacebookUser(); $userinfo = $fbUser->getUserInfo(); $form = $this->getLogoutAndContinueForm($userinfo, $userId); // TODO //$form .= '<p>Not $userId? Log in as a different facebook user...</p>'; $wgOut->addHTML($form . "<br/>\n"); // Render the "Return to" text retrieved from the URL $wgOut->returnToMain(false, $this->mReturnTo, $this->mReturnToQuery); }
/** * Generates a unique username for a wiki account based on the prefix specified * in the message 'facebook-usernameprefix'. The number appended is equal to * the number of Facebook Connect to user ID associations in the user_fbconnect * table, so quite a few numbers will be skipped. However, this approach is * more scalable. For smaller wiki installations, uncomment the line $i = 1 to * have consecutive usernames starting at 1. */ static function generateUserName() { // Because $i is incremented the first time through the while loop $i = FacebookDB::countUsers(); // rough estimate $max = $i + 100; while ($i < PHP_INT_MAX && $i < $max) { $name = self::getUserNamePrefix() . $i; if (FacebookUser::userNameOK($name)) { return $name; } ++$i; } return $prefix; }