/** * Imports all likes from a facebook account to store it in the mongodb * * @param int $online_identity */ public static function importInterests($online_identity) { $token = AuthTokenTable::getByUserAndOnlineIdentity($online_identity->getUserId(), $online_identity->getId()); if (!$token) { $online_identity->deactivate(); throw new Exception('damn theres no token!', '666'); } // get likes $response = UrlUtils::sendGetRequest("https://graph.facebook.com/me/likes?access_token=" . $token->getTokenKey()); // mongo manager $dm = MongoManager::getDM(); // check likes if ($response && ($objects = json_decode($response, true))) { if (!isset($objects['data'])) { return false; } // iterate and save in mongodb foreach ($objects["data"] as $object) { $interest = $dm->getRepository('Documents\\Interest')->upsert($object); // check interest if ($interest) { $user_interest = $dm->getRepository('Documents\\UserInterest')->upsert($online_identity, $interest); } } } return; }
protected function getAuthToken() { $lToken = AuthTokenTable::getByUserAndOnlineIdentity($this->onlineIdentity->getUserId(), $this->onlineIdentity->getId()); if (!$lToken) { $this->onlineIdentity->setSocialPublishingEnabled(false); $this->onlineIdentity->save(); } return $lToken; }
/** * import twitter contacts * * @author Matthias Pfefferle * @author Karina Mies */ public static function importContacts($pOnlineIdentity) { $lToken = AuthTokenTable::getByUserAndOnlineIdentity($pOnlineIdentity->getUserId(), $pOnlineIdentity->getId()); // get api informations if (!$lToken) { $pOnlineIdentity->deactivate(); throw new Exception('damn theres no token!', '666'); } $lConsumer = new OAuthConsumer(sfConfig::get("app_xing_oauth_token"), sfConfig::get("app_xing_oauth_secret")); $lJson = OAuthClient::get($lConsumer, $lToken->getTokenKey(), $lToken->getTokenSecret(), "https://api.xing.com/v1/users/me/contact_ids.json"); $lJsonFriendsObject = json_decode($lJson, true); sfContext::getInstance()->getLogger()->notice(print_r($lJsonFriendsObject, true)); self::importFriends($pOnlineIdentity, $lJsonFriendsObject); }
/** * import twitter contacts * * @author Matthias Pfefferle * @author Karina Mies */ public static function importContacts($pOnlineIdentity) { $lToken = AuthTokenTable::getByUserAndOnlineIdentity($pOnlineIdentity->getUserId(), $pOnlineIdentity->getId()); // get api informations if (!$lToken) { $pOnlineIdentity->deactivate(); throw new Exception('damn theres no token!', '666'); } $lConsumer = new OAuthConsumer(sfConfig::get("app_linkedin_oauth_token"), sfConfig::get("app_linkedin_oauth_secret")); $lXml = OAuthClient::get($lConsumer, $lToken->getTokenKey(), $lToken->getTokenSecret(), "http://api.linkedin.com/v1/people/~/connections:(id)"); $lFriendObject = simplexml_load_string($lXml); $lXml = OAuthClient::get($lConsumer, $lToken->getTokenKey(), $lToken->getTokenSecret(), "http://api.linkedin.com/v1/people/~:(id,site-standard-profile-request,summary,picture-url,first-name,last-name,date-of-birth,location)"); $lProfileArray = XmlUtils::XML2Array($lXml); @self::importFriends($pOnlineIdentity, $lFriendObject); @self::updateIdentity($pOnlineIdentity, $lProfileArray); }
/** * import twitter contacts * * @author Matthias Pfefferle * @author Karina Mies */ public static function importContacts($pOnlineIdentity) { $lToken = AuthTokenTable::getByUserAndOnlineIdentity($pOnlineIdentity->getUserId(), $pOnlineIdentity->getId()); // get api informations if (!$lToken) { $pOnlineIdentity->deactivate(); throw new Exception('damn theres no token!', '666'); } $lConsumer = new OAuthConsumer(sfConfig::get("app_twitter_oauth_token"), sfConfig::get("app_twitter_oauth_secret")); $lJson = OAuthClient::get($lConsumer, $lToken->getTokenKey(), $lToken->getTokenSecret(), "http://api.twitter.com/1.1/followers/ids.json?id=" . $pOnlineIdentity->getOriginalId()); $lJsonFriendsObject = json_decode($lJson); // get api informations $lJson = OAuthClient::get($lConsumer, $lToken->getTokenKey(), $lToken->getTokenSecret(), "http://api.twitter.com/1.1/users/show.json?user_id=" . $pOnlineIdentity->getOriginalId()); $lJsonUserObject = json_decode($lJson); self::importFriends($pOnlineIdentity, $lJsonFriendsObject); self::updateIdentity($pOnlineIdentity, $lJsonUserObject); }
/** * add identifier * * @author Matthias Pfefferle * @param User $pUser * @param AuthToken $pAuthToken * @return OnlineIdentity */ public function addIdentifier($user, $pOAuthToken) { $lAccessToken = $this->getAccessToken($pOAuthToken); //var_dump($lAccessToken);die(); // get params $lParams = $lAccessToken->params; $lParamsArray = array(); // extract params parse_str($lParams, $lParamsArray); //$lConsumer = new OAuthConsumer(sfConfig::get("app_linkedin_oauth_token"), sfConfig::get("app_linkedin_oauth_secret")); $json = OAuthClient::post($this->getConsumer(), $lParamsArray['oauth_token'], $lParamsArray['oauth_token_secret'], "http://api.tumblr.com/v2/user/info"); $json = json_decode($json, true); foreach ($json['response']['user']['blogs'] as $blog) { $user_name = $blog['name']; $auth_identifier = "http://" . $user_name . ".tumblr.com"; // ask for online identity $online_identity = OnlineIdentityTable::retrieveByAuthIdentifier($auth_identifier); // check if user already exists if ($online_identity) { if ($online_identity->getUserId() && $user->getId() == $online_identity->getUserId()) { if (!$online_identity->getActive()) { $online_identity->setActive(true); } else { //throw new sfException("online identity already added", 1); continue; } } elseif ($online_identity->getUserId() && $user->getId() != $online_identity->getUserId()) { //throw new sfException("online identity already added by someone else", 2); continue; } } else { // check online identity $online_identity = OnlineIdentityTable::addOnlineIdentity($auth_identifier, $user_name, $this->aCommunityId); } $this->completeOnlineIdentity($online_identity, $blog, $user, $auth_identifier); // save new token AuthTokenTable::saveToken($user->getId(), $online_identity->getId(), $lParamsArray['oauth_token'], $lParamsArray['oauth_token_secret'], true); } return $user; }
/** * add identifier * * @author Matthias Pfefferle * @param User $pUser * @param AuthToken $pAuthToken * @return OnlineIdentity */ public function addIdentifier($pUser, $pOAuthToken) { $lAccessToken = $this->getAccessToken($pOAuthToken); // get params $lParams = $lAccessToken->params; $lParamsArray = array(); // extract params parse_str($lParams, $lParamsArray); $lXml = OAuthClient::get($this->getConsumer(), $lParamsArray['oauth_token'], $lParamsArray['oauth_token_secret'], "http://api.linkedin.com/v1/people/~:(id,site-standard-profile-request,summary,picture-url,first-name,last-name,date-of-birth,location)"); $lProfileArray = XmlUtils::XML2Array($lXml); //var_dump($lProfileArray);die(); // identifier $lLinkedInId = $lProfileArray['id']; $lProfileUri = "http://www.linkedin.com/profile/view?id=" . $lLinkedInId; // ask for online identity $lOnlineIdentity = OnlineIdentityTable::retrieveByAuthIdentifier($lProfileUri); // check if user already exists if ($lOnlineIdentity) { if ($lOnlineIdentity->getUserId() && $pUser->getId() == $lOnlineIdentity->getUserId()) { if (!$lOnlineIdentity->getActive()) { $lOnlineIdentity->setActive(true); } else { throw new sfException("online identity already added", 1); } } elseif ($lOnlineIdentity->getUserId() && $pUser->getId() != $lOnlineIdentity->getUserId()) { throw new sfException("online identity already added by someone else", 2); } } else { // new online identity if no exist $lOnlineIdentity = OnlineIdentityTable::addOnlineIdentity($lProfileUri, $lLinkedInId, $this->aCommunityId, $lProfileUri); } $this->completeOnlineIdentity($lOnlineIdentity, $lProfileArray, $pUser); AuthTokenTable::saveToken($pUser->getId(), $lOnlineIdentity->getId(), $lParamsArray['oauth_token'], $lParamsArray['oauth_token_secret'], true); return $lOnlineIdentity; }
/** * add identifier * * @author Matthias Pfefferle * @param User $pUser * @param AuthToken $pAuthToken * @return OnlineIdentity */ public function addIdentifier($pUser, $pCode) { $lAccessToken = $this->getAccessToken($pCode); // get params $lParamsArray = array(); // extract params $lAccessToken = json_decode($lAccessToken, true); $lJsonObject = json_decode(UrlUtils::sendGetRequest("https://api.flattr.com/rest/v2/user", array("Authorization: Bearer " . $lAccessToken["access_token"]))); // facebook identifier $lIdentifier = $lJsonObject->link; // ask for online identity $lOnlineIdentity = OnlineIdentityTable::retrieveByAuthIdentifier($lIdentifier); // check if user already exists if ($lOnlineIdentity) { if ($lOnlineIdentity->getUserId() && $pUser->getId() == $lOnlineIdentity->getUserId()) { if (!$lOnlineIdentity->getActive()) { $lOnlineIdentity->setActive(true); } else { throw new sfException("online identity already added", 1); } } elseif ($lOnlineIdentity->getUserId() && $pUser->getId() != $lOnlineIdentity->getUserId()) { throw new sfException("online identity already added by someone else", 2); } } else { // check online identity $lOnlineIdentity = OnlineIdentityTable::addOnlineIdentity($lJsonObject->link, $lJsonObject->username, $this->aCommunityId, $lIdentifier); } // use api complete informations $this->completeOnlineIdentity($lOnlineIdentity, $lJsonObject, $pUser, $lIdentifier); // signup,add new AuthTokenTable::saveToken($pUser->getId(), $lOnlineIdentity->getId(), $lAccessToken["access_token"], null, true); // signup,add new return $lOnlineIdentity; }
/** * add identifier * * @author Matthias Pfefferle * @param User $pUser * @param AuthToken $pAuthToken * @return OnlineIdentity */ public function addIdentifier($user, $pOAuthToken) { $lAccessToken = $this->getAccessToken($pOAuthToken); // get params $lParams = $lAccessToken->params; $lParamsArray = array(); // extract params parse_str($lParams, $lParamsArray); $json = OAuthClient::get($this->getConsumer(), $lParamsArray['oauth_token'], $lParamsArray['oauth_token_secret'], "https://api.xing.com/v1/users/me"); $json = json_decode($json, true); $xing_user = $json['users'][0]; $auth_identifier = $xing_user["permalink"]; // ask for online identity $online_identity = OnlineIdentityTable::retrieveByOriginalId($xing_user['id'], $this->getCommunity()->getid()); // check if user already exists if ($online_identity) { if ($online_identity->getUserId() && $user->getId() == $online_identity->getUserId()) { if (!$online_identity->getActive()) { $online_identity->setActive(true); } else { throw new sfException("online identity already added", 1); } } elseif ($online_identity->getUserId() && $user->getId() != $online_identity->getUserId()) { throw new sfException("online identity already added by someone else", 2); } } else { // check online identity $online_identity = OnlineIdentityTable::addOnlineIdentity($auth_identifier, $xing_user['id'], $this->aCommunityId); } $this->completeOnlineIdentity($online_identity, $xing_user, $user, $auth_identifier); // save new token AuthTokenTable::saveToken($user->getId(), $online_identity->getId(), $lParamsArray['oauth_token'], $lParamsArray['oauth_token_secret'], true); return $user; }
/** * add identifier * * @author Matthias Pfefferle * @param User $pUser * @param AuthToken $pAuthToken * @return OnlineIdentity */ public function addIdentifier($pUser, $pOAuthToken) { $lAccessToken = $this->getAccessToken($pOAuthToken); // get api informations $lJson = OAuthClient::get($this->getConsumer(), $lParamsArray['oauth_token'], $lParamsArray['oauth_token_secret'], "http://api.yigg.local/profiles/me"); $lJsonObject = json_decode($lJson); // ask for online identity $lOnlineIdentity = OnlineIdentityTable::retrieveByOriginalId($lJsonObject->id, $this->aCommunityId); // check if user already exists if ($lOnlineIdentity) { if ($lOnlineIdentity->getUserId() && $pUser->getId() == $lOnlineIdentity->getUserId()) { if (!$lOnlineIdentity->getActive()) { $lOnlineIdentity->setActive(true); } else { throw new sfException("online identity already added", 1); } } elseif ($lOnlineIdentity->getUserId() && $pUser->getId() != $lOnlineIdentity->getUserId()) { throw new sfException("online identity already added by someone else", 2); } } else { // get auth identifier foreach ($lJsonObject->urls as $url) { if ($url['type'] == "profile") { $lIdentifier = $url['value']; } } // check online identity $lOnlineIdentity = OnlineIdentityTable::addOnlineIdentity($lIdentifier, $lJsonObject->id, $this->aCommunityId); } $this->completeOnlineIdentity($lOnlineIdentity, $lJsonObject, $pUser, $lIdentifier); AuthTokenTable::saveToken($pUser->getId(), $lOnlineIdentity->getId(), $lParamsArray['oauth_token'], $lParamsArray['oauth_token_secret'], true); return $lOnlineIdentity; }
public function testGetUsersAuthTokens() { $lUserHugo = UserTable::getByIdentifier('hugo'); $lTokens = AuthTokenTable::getTokensForUserQuery($lUserHugo->getId()); $this->assertEquals(2, count($lTokens)); }
/** * add identifier * * @author Matthias Pfefferle * @param User $pUser * @param AuthToken $pAuthToken * @return OnlineIdentity */ public function addIdentifier($pUser, $pOAuthToken) { $lAccessToken = $this->getAccessToken($pOAuthToken); // get params $lParams = $lAccessToken->params; $lParamsArray = array(); // extract params parse_str($lParams, $lParamsArray); // twitter identifier $lIdentifier = "http://twitter.com/account/profile?user_id=" . $lParamsArray['user_id']; // ask for online identity $lOnlineIdentity = OnlineIdentityTable::retrieveByAuthIdentifier($lIdentifier); // check if user already exists if ($lOnlineIdentity) { if ($lOnlineIdentity->getUserId() && $pUser->getId() == $lOnlineIdentity->getUserId()) { if (!$lOnlineIdentity->getActive()) { $lOnlineIdentity->setActive(true); } else { throw new sfException("online identity already added", 1); } } elseif ($lOnlineIdentity->getUserId() && $pUser->getId() != $lOnlineIdentity->getUserId()) { throw new sfException("online identity already added by someone else", 2); } } else { // check online identity $lOnlineIdentity = OnlineIdentityTable::addOnlineIdentity("http://twitter.com/" . $lParamsArray['screen_name'], $lParamsArray['user_id'], $this->aCommunityId); } // get api informations $lJson = OAuthClient::get($this->getConsumer(), $lParamsArray['oauth_token'], $lParamsArray['oauth_token_secret'], "https://api.twitter.com/1.1/users/show.json?user_id=" . $lParamsArray['user_id']); $lJsonObject = json_decode($lJson); $this->completeOnlineIdentity($lOnlineIdentity, $lJsonObject, $pUser, $lIdentifier); AuthTokenTable::saveToken($pUser->getId(), $lOnlineIdentity->getId(), $lParamsArray['oauth_token'], $lParamsArray['oauth_token_secret'], true); return $lOnlineIdentity; }
/** * add identifier * * @author Matthias Pfefferle * @param User $pUser * @param AuthToken $pAuthToken * @return OnlineIdentity */ public function addIdentifier($pUser, $pCode) { $lAccessToken = $this->getAccessToken($pCode); // get params $lParamsArray = array(); // extract params parse_str($lAccessToken, $lParamsArray); $lJsonObject = json_decode(UrlUtils::sendGetRequest("https://graph.facebook.com/me?access_token=" . $lParamsArray['access_token'] . "&locale=en_US")); // facebook identifier $lIdentifier = "http://www.facebook.com/profile.php?id=" . $lJsonObject->id; // ask for online identity $lOnlineIdentity = OnlineIdentityTable::retrieveByAuthIdentifier($lIdentifier); // check if user already exists if ($lOnlineIdentity) { if ($lOnlineIdentity->getUserId() && $pUser->getId() == $lOnlineIdentity->getUserId()) { if (!$lOnlineIdentity->getActive()) { $lOnlineIdentity->setActive(true); } else { throw new sfException("online identity already added", 1); } } elseif ($lOnlineIdentity->getUserId() && $pUser->getId() != $lOnlineIdentity->getUserId()) { throw new sfException("online identity already added by someone else", 2); } } else { // check online identity $lOnlineIdentity = OnlineIdentityTable::addOnlineIdentity($lJsonObject->link, $lJsonObject->id, $this->aCommunityId); } // use api complete informations $this->completeOnlineIdentity($lOnlineIdentity, $lJsonObject, $pUser, $lIdentifier); // signup,add new AuthTokenTable::saveToken($pUser->getId(), $lOnlineIdentity->getId(), $lParamsArray['access_token'], null, true); // signup,add new return $lOnlineIdentity; }