Пример #1
0
 /**
  * {@inheritdoc}
  */
 function initialize()
 {
     if (!$this->config["keys"]["key"] || !$this->config["keys"]["secret"]) {
         throw new Exception("Your application key and secret are required in order to connect to {$this->providerId}.", 4);
     }
     if (!class_exists('OAuthConsumer', false)) {
         require_once Hybrid_Auth::$config["path_libraries"] . "OAuth/OAuth.php";
     }
     require_once Hybrid_Auth::$config["path_libraries"] . "LinkedIn/LinkedIn.php";
     $this->api = new LinkedIn(array('appKey' => $this->config["keys"]["key"], 'appSecret' => $this->config["keys"]["secret"], 'callbackUrl' => $this->endpoint));
     if ($this->token("access_token_linkedin")) {
         $this->api->setTokenAccess($this->token("access_token_linkedin"));
     }
 }
 function get_resume_data()
 {
     $this->_check_auth();
     $API_CONFIG = $this->config->item('LINKEDIN_KEYS');
     $OBJ_linkedin = new LinkedIn($API_CONFIG);
     $OBJ_linkedin->setTokenAccess($this->session->userdata('access'));
     $OBJ_linkedin->setResponseFormat(LINKEDIN::_RESPONSE_JSON);
     $resumeResponse = $OBJ_linkedin->profile('~:(first-name,last-name,formatted-name,industry,skills,summary,specialties,positions,picture-url,educations,interests,headline,phone-numbers,email-address,member-url-resources)');
     if ($resumeResponse['success'] === TRUE) {
         $resumeData = json_decode($resumeResponse['linkedin'], true);
         //print_r($resumeData);
         $this->load->model('resume');
         $userId = $this->session->userdata('user_id');
         $resumeData = array();
         $resumeData['user_id'] = $userId;
         $resumeData['json_data'] = $resumeResponse['linkedin'];
         $resumeData['update_date'] = date('Y-m-d h:i:s');
         if (!$this->resume->exist($userId)) {
             $resumeData['create_date'] = date('Y-m-d h:i:s');
             $resumeId = $this->resume->create($resumeData);
         } else {
             $resumeId = $this->resume->update_user_id($userId, $resumeData);
         }
         redirect('/builder/customize/' . $resumeId, 'refresh');
     }
 }
Пример #3
0
 /**
  * {@inheritdoc}
  */
 function initialize()
 {
     if (!$this->config["keys"]["key"] || !$this->config["keys"]["secret"]) {
         throw new Exception("Your application key and secret are required in order to connect to {$this->providerId}.", 4);
     }
     if (empty($this->config['fields'])) {
         $this->config['fields'] = array('id', 'first-name', 'last-name', 'public-profile-url', 'picture-url', 'email-address', 'date-of-birth', 'phone-numbers', 'summary', 'positions');
     }
     if (!class_exists('OAuthConsumer', false)) {
         require_once Hybrid_Auth::$config["path_libraries"] . "OAuth/OAuth.php";
     }
     require_once Hybrid_Auth::$config["path_libraries"] . "LinkedIn/LinkedIn.php";
     $this->api = new LinkedIn(array('appKey' => $this->config["keys"]["key"], 'appSecret' => $this->config["keys"]["secret"], 'callbackUrl' => $this->endpoint));
     if ($this->token("access_token_linkedin")) {
         $this->api->setTokenAccess($this->token("access_token_linkedin"));
     }
 }
Пример #4
0
 protected function getAPI()
 {
     $OAuth2 = nxcSocialNetworksOAuth2::getInstanceByType('linkedin');
     $OAuth2Token = $OAuth2->getToken();
     $API = new LinkedIn(array('appKey' => $OAuth2->appSettings['key'], 'appSecret' => $OAuth2->appSettings['secret'], 'callbackUrl' => null));
     $API->setTokenAccess(array('oauth_token' => $OAuth2Token->attribute('token'), 'oauth_token_secret' => $OAuth2Token->attribute('secret')));
     return $API;
 }
Пример #5
0
 private function _startLinkedinHandshake($req_type, $credentials)
 {
     $session = self::oauth_session_exists();
     $app = JFactory::getApplication();
     require_once dirname(__FILE__) . DS . 'jobboard' . DS . 'lib' . DS . 'linkedin' . DS . 'linkedin_3.1.1.class.php';
     $API_CONFIG = array('appKey' => $credentials['key'], 'appSecret' => $credentials['secret'], 'callbackUrl' => null);
     switch ($req_type) {
         case 'initiate':
             $API_CONFIG['callbackUrl'] = JURI::root() . 'index.php?option=com_jobboard&view=user&task=getlinkedinprof&' . $req_type . '=initiate&' . LINKEDIN::_GET_RESPONSE . '=1&Itemid=' . $this->_itemid;
             $OBJ_linkedin = new LinkedIn($API_CONFIG);
             $_GET[LINKEDIN::_GET_RESPONSE] = isset($_GET[LINKEDIN::_GET_RESPONSE]) ? $_GET[LINKEDIN::_GET_RESPONSE] : '';
             if (!$_GET[LINKEDIN::_GET_RESPONSE]) {
                 $response = $OBJ_linkedin->retrieveTokenRequest();
                 if ($response['success'] === TRUE) {
                     $session_oauth = $session->get('oauth');
                     $session_oauth['oauth']['linkedin']['request'] = $response['linkedin'];
                     $session->set('oauth', $session_oauth);
                     $app->redirect(LINKEDIN::_URL_AUTH . $response['linkedin']['oauth_token']);
                 } else {
                     $msg = JText::_('PLG_JOBBOARD_REQUEST_TOKEN_RETRIEVAL_FAILED');
                     $app->redirect('index.php?option=com_jobboard&view=user&task=addcv&Itemid=' . $this->_itemid, $msg, 'error');
                 }
             } else {
                 self::_processResponse(&$OBJ_linkedin);
             }
             return self::_getLinkedInProfile(&$OBJ_linkedin);
             break;
         case 'revoke':
             $session_oauth = $session->get('oauth');
             $OBJ_linkedin = new LinkedIn($API_CONFIG);
             $OBJ_linkedin->setTokenAccess($session_oauth['oauth']['linkedin']['access']);
             $response = $OBJ_linkedin->revoke();
             if ($response['success'] === TRUE) {
                 if ($session->clear('oauth')) {
                     $msg = JText::_('PLG_JOBBOARD_AUTH_REVOKE_SUCCESS');
                     $msg_type = 'Message';
                 } else {
                     $msg = JText::_('PLG_JOBBOARD_SESSION_CLEAR_FAILED');
                     $msg_type = 'error';
                 }
             } else {
                 $msg = JText::_('PLG_JOBBOARD_AUTH_REVOKE_FAILED');
                 $msg_type = 'error';
             }
             $app->redirect('index.php?option=com_jobboard&view=user&task=addcv&Itemid=' . $this->_itemid, $msg, $msg_type);
             break;
         default:
             break;
     }
 }
Пример #6
0
 private function loadProfiles($person, $personIsUser)
 {
     $profiles = array();
     if (!empty($person['facebook_access_token']) && (!$personIsUser || $this->mergeNetwork != 'Facebook')) {
         try {
             //$params = array('access_token' => $user['facebook_access_token']);
             $facebookProfile = SessionManager::getInstance()->getFacebook()->api('/' . $person['facebook_id']);
         } catch (FacebookApiException $e) {
             Debug::l('Error loading Facebook profile for ' . ($personIsUser ? 'current' : 'other') . ' user. ' . $e);
         }
         if (isset($facebookProfile)) {
             $profiles[] = '<a href="' . $facebookProfile['link'] . '" target="_blank" class="profile"><img src="https://graph.facebook.com/' . $person['facebook_id'] . '/picture?type=square" /> ' . $facebookProfile['name'] . ' on Facebook</a>';
         }
     }
     if (!empty($person['linkedin_access_token']) && (!$personIsUser || $this->mergeNetwork != 'LinkedIn')) {
         $API_CONFIG = array('appKey' => LI_API_KEY, 'appSecret' => LI_SECRET, 'callbackUrl' => '');
         $OBJ_linkedin = new LinkedIn($API_CONFIG);
         $OBJ_linkedin->setTokenAccess(unserialize($person['linkedin_access_token']));
         try {
             $linkedInProfile = $OBJ_linkedin->profile('id=' . $person['linkedin_id'] . ':(first-name,last-name,public-profile-url,picture-url)');
         } catch (ErrorException $e) {
             Debug::l('Error loading LinkedIn profile for ' . ($personIsUser ? 'current' : 'other') . ' user. ' . $e);
         }
         if ($linkedInProfile['success'] === TRUE) {
             $linkedInProfile['linkedin'] = new SimpleXMLElement($linkedInProfile['linkedin']);
             if ($linkedInProfile['linkedin']->getName() == 'person') {
                 $li_pr = (string) $linkedInProfile['linkedin']->{'public-profile-url'};
                 $li_pi = (string) $linkedInProfile['linkedin']->{'picture-url'};
                 $li_fn = (string) $linkedInProfile['linkedin']->{'first-name'};
                 $li_ln = (string) $linkedInProfile['linkedin']->{'last-name'};
                 $profiles[] = '<a href="' . $li_pr . '" target="_blank" class="profile"><img src="' . $li_pi . '" /> ' . $li_fn . ' ' . $li_ln . ' on LinkedIn</a>';
             }
         }
     }
     if (!empty($person['twitter_access_token']) && ($personIsUser || $this->mergeNetwork != 'Twitter')) {
         try {
             $twitterAccessToken = unserialize($person['twitter_access_token']);
             $twitter = new TwitterOAuth(TW_CONSUMER, TW_SECRET, $twitterAccessToken['oauth_token'], $twitterAccessToken['oauth_token_secret']);
             $twitter->format = 'json';
             $twitterProfile = $twitter->get('users/show', array('user_id' => $person['twitter_id']));
         } catch (ErrorException $e) {
             Debug::l('Error loading Twitter profile for ' . ($personIsUser ? 'current' : 'other') . ' user. ' . $e);
         }
         if (isset($twitterProfile)) {
             $profiles[] = '<a href="http://twitter.com/' . $twitterProfile->screen_name . '" target="_blank" class="profile"><img src="' . $twitterProfile->profile_image_url . '" /> @' . $twitterProfile->screen_name . ' on Twitter</a>';
         }
     }
     return $profiles;
 }
Пример #7
0
                ?>
            <ul>
              <li><a href="#manage">Manage LinkedIn Authorization</a></li>
            </ul>
            <?php 
            }
            ?>
          
          <hr />
          
          <h2 id="manage">Manage LinkedIn Authorization:</h2>
          <?php 
            if ($_SESSION['oauth']['linkedin']['authorized'] === TRUE) {
                // user is already connected
                $OBJ_linkedin = new LinkedIn($API_CONFIG);
                $OBJ_linkedin->setTokenAccess($_SESSION['oauth']['linkedin']['access']);
                ?>
            <form id="linkedin_revoke_form" action="<?php 
                echo $_SERVER['PHP_SELF'];
                ?>
" method="get">
              <input type="hidden" name="<?php 
                echo LINKEDIN::_GET_TYPE;
                ?>
" id="<?php 
                echo LINKEDIN::_GET_TYPE;
                ?>
" value="revoke" />
              <input type="submit" value="Revoke Authorization" />
            </form>
            
Пример #8
0
 public function linkedin()
 {
     try {
         $API_CONFIG = array('appKey' => '75wpz389ifrzbq', 'appSecret' => 'ZYEG6gBlFhhUAkfR', 'callbackUrl' => NULL);
         define('DEMO_GROUP', '4010474');
         define('DEMO_GROUP_NAME', 'Simple LI Demo');
         define('PORT_HTTP', '80');
         define('PORT_HTTP_SSL', '443');
         $_GET['lType'] = isset($_GET['lType']) ? $_GET['lType'] : '';
         switch ($_GET['lType']) {
             case 'initiate':
                 if ($_SERVER['HTTPS'] == 'on') {
                     $protocol = 'https';
                 } else {
                     $protocol = 'http';
                 }
                 $API_CONFIG['callbackUrl'] = $protocol . '://' . $_SERVER['SERVER_NAME'] . ($_SERVER['SERVER_PORT'] != PORT_HTTP || $_SERVER['SERVER_PORT'] != PORT_HTTP_SSL ? ':' . $_SERVER['SERVER_PORT'] : '') . $_SERVER['PHP_SELF'] . '?' . LINKEDIN::_GET_TYPE . '=initiate&' . LINKEDIN::_GET_RESPONSE . '=1';
                 $OBJ_linkedin = new LinkedIn($API_CONFIG);
                 $_GET[LINKEDIN::_GET_RESPONSE] = isset($_GET[LINKEDIN::_GET_RESPONSE]) ? $_GET[LINKEDIN::_GET_RESPONSE] : '';
                 if (!$_GET[LINKEDIN::_GET_RESPONSE]) {
                     $response = $OBJ_linkedin->retrieveTokenRequest();
                     if ($response['success'] === TRUE) {
                         $_SESSION['oauth']['linkedin']['request'] = $response['linkedin'];
                         header('Location: ' . LINKEDIN::_URL_AUTH . $response['linkedin']['oauth_token']);
                     } else {
                         echo "Request token retrieval failed:<br /><br />RESPONSE:<br /><br /><pre>" . print_r($response, TRUE) . "</pre><br /><br />LINKEDIN OBJ:<br /><br /><pre>" . print_r($OBJ_linkedin, TRUE) . "</pre>";
                     }
                 } else {
                     $response = $OBJ_linkedin->retrieveTokenAccess($_SESSION['oauth']['linkedin']['request']['oauth_token'], $_SESSION['oauth']['linkedin']['request']['oauth_token_secret'], $_GET['oauth_verifier']);
                     if ($response['success'] === TRUE) {
                         $_SESSION['oauth']['linkedin']['access'] = $response['linkedin'];
                         $_SESSION['oauth']['linkedin']['authorized'] = TRUE;
                         header('Location: ' . $_SERVER['PHP_SELF']);
                     } else {
                         echo "Access token retrieval failed:<br /><br />RESPONSE:<br /><br /><pre>" . print_r($response, TRUE) . "</pre><br /><br />LINKEDIN OBJ:<br /><br /><pre>" . print_r($OBJ_linkedin, TRUE) . "</pre>";
                     }
                 }
                 break;
             case 'revoke':
                 if (!oauth_session_exists()) {
                     throw new LinkedInException('This script requires session support, which doesn\'t appear to be working correctly.');
                 }
                 $OBJ_linkedin = new LinkedIn($API_CONFIG);
                 $OBJ_linkedin->setTokenAccess($_SESSION['oauth']['linkedin']['access']);
                 $response = $OBJ_linkedin->revoke();
                 if ($response['success'] === TRUE) {
                     session_unset();
                     $_SESSION = array();
                     if (session_destroy()) {
                         header('Location: ' . $_SERVER['PHP_SELF']);
                     } else {
                         echo "Error clearing user's session";
                     }
                 } else {
                     echo "Error revoking user's token:<br /><br />RESPONSE:<br /><br /><pre>" . print_r($response, TRUE) . "</pre><br /><br />LINKEDIN OBJ:<br /><br /><pre>" . print_r($OBJ_linkedin, TRUE) . "</pre>";
                 }
                 break;
             default:
                 $_SESSION['oauth']['linkedin']['authorized'] = isset($_SESSION['oauth']['linkedin']['authorized']) ? $_SESSION['oauth']['linkedin']['authorized'] : FALSE;
                 if ($_SESSION['oauth']['linkedin']['authorized'] === TRUE) {
                     $OBJ_linkedin = new LinkedIn($API_CONFIG);
                     $OBJ_linkedin->setTokenAccess($_SESSION['oauth']['linkedin']['access']);
                     $OBJ_linkedin->setResponseFormat(LINKEDIN::_RESPONSE_XML);
                     $response = $OBJ_linkedin->group(DEMO_GROUP, ':(relation-to-viewer:(membership-state))');
                     if ($response['success'] === TRUE) {
                         $result = new SimpleXMLElement($response['linkedin']);
                         $membership = $result->{'relation-to-viewer'}->{'membership-state'}->code;
                         $in_demo_group = $membership == 'non-member' || $membership == 'blocked' ? FALSE : TRUE;
                     } else {
                         echo "Error retrieving group membership information: <br /><br />RESPONSE:<br /><br /><pre>" . print_r($response, TRUE) . "</pre>";
                     }
                 } else {
                 }
                 if ($_SESSION['oauth']['linkedin']['authorized'] === TRUE) {
                     $response = $OBJ_linkedin->profile('~:(id,first-name,last-name,picture-url)');
                     if ($response['success'] === TRUE) {
                         $response['linkedin'] = new SimpleXMLElement($response['linkedin']);
                         echo "<pre>" . print_r($response['linkedin'], TRUE) . "</pre>";
                     } else {
                         echo "Error retrieving profile information:<br /><br />RESPONSE:<br /><br /><pre>" . print_r($response) . "</pre>";
                     }
                 } else {
                 }
                 break;
         }
     } catch (LinkedInException $e) {
         echo $e->getMessage();
     }
     $this->setErrorMessage('success', 'Registered & Login Successfully');
 }
Пример #9
0
 public function __construct()
 {
     session_start();
     header('Content-type: text/json');
     // Get the website user
     $userId = SessionManager::getInstance()->getUserId();
     $json['result'] = 'true';
     // Make sure a user is logged in
     if (!isset($userId)) {
         $json['result'] = 'false';
         $json['title'] = (string) Content::c()->errors->session->title;
         $json['message'] = (string) Content::c()->errors->session->no_session;
         echo json_encode($json);
         exit;
     }
     // Validate input
     if (empty($_POST['introducee1Name']) || empty($_POST['introducee1FacebookId']) && empty($_POST['introducee1LinkedInId']) && empty($_POST['introducee1TwitterId']) || empty($_POST['introducee2Name']) || empty($_POST['introducee2FacebookId']) && empty($_POST['introducee2LinkedInId']) && empty($_POST['introducee2TwitterId'])) {
         $json['result'] = 'false';
         $json['title'] = (string) Content::c()->errors->input->title;
         $json['message'] = (string) Content::c()->errors->input->introduction_not_created;
         echo json_encode($json);
         exit;
     }
     // Make sure the introducees are unique
     if (!empty($_POST['introducee1FacebookId']) && !empty($_POST['introducee2FacebookId']) && $_POST['introducee1FacebookId'] == $_POST['introducee2FacebookId'] || !empty($_POST['introducee1LinkedInId']) && !empty($_POST['introducee2LinkedInId']) && $_POST['introducee1LinkedInId'] == $_POST['introducee2LinkedInId'] || !empty($_POST['introducee1TwitterId']) && !empty($_POST['introducee2TwitterId']) && $_POST['introducee1TwitterId'] == $_POST['introducee2TwitterId']) {
         $json['result'] = 'false';
         $json['title'] = (string) Content::c()->errors->input->title;
         $json['message'] = (string) Content::c()->errors->input->introduce_to_self;
         echo json_encode($json);
         exit;
     }
     // Connect to the database
     $db = Database::getInstance();
     $introducee1 = new Person(array('name' => $_POST['introducee1Name'], 'facebookId' => !empty($_POST['introducee1FacebookId']) ? $_POST['introducee1FacebookId'] : '', 'linkedInId' => !empty($_POST['introducee1LinkedInId']) ? $_POST['introducee1LinkedInId'] : null, 'twitterId' => !empty($_POST['introducee1TwitterId']) ? $_POST['introducee1TwitterId'] : null));
     $introducee2 = new Person(array('name' => $_POST['introducee2Name'], 'facebookId' => !empty($_POST['introducee2FacebookId']) ? $_POST['introducee2FacebookId'] : '', 'linkedInId' => !empty($_POST['introducee2LinkedInId']) ? $_POST['introducee2LinkedInId'] : null, 'twitterId' => !empty($_POST['introducee2TwitterId']) ? $_POST['introducee2TwitterId'] : null));
     // See if the introducees are already in our database, that would be nice!
     if (!empty($_POST['introducee1FacebookId'])) {
         $introducee1->getDataFromFacebookId($_POST['introducee1FacebookId']);
     } elseif (!empty($_POST['introducee1LinkedInId'])) {
         $introducee1->getDataFromLinkedInId($_POST['introducee1LinkedInId']);
     } elseif (!empty($_POST['introducee1TwitterId'])) {
         $introducee1->getDataFromTwitterId($_POST['introducee1TwitterId']);
     }
     if (!empty($_POST['introducee2FacebookId'])) {
         $introducee2->getDataFromFacebookId($_POST['introducee2FacebookId']);
     } elseif (!empty($_POST['introducee2LinkedInId'])) {
         $introducee2->getDataFromLinkedInId($_POST['introducee2LinkedInId']);
     } elseif (!empty($_POST['introducee2TwitterId'])) {
         $introducee2->getDataFromTwitterId($_POST['introducee2TwitterId']);
     }
     // Make sure the introducees are still unique
     if ($introducee1->getFacebookId() != null && $introducee1->getFacebookId() == $introducee2->getFacebookId() || $introducee1->getLinkedInId() != null && $introducee1->getLinkedInId() == $introducee2->getLinkedInId() || $introducee1->getTwitterId() != null && $introducee1->getTwitterId() == $introducee2->getTwitterId()) {
         $json['result'] = 'false';
         $json['title'] = (string) Content::c()->errors->input->title;
         $json['message'] = (string) Content::c()->errors->input->introduce_to_self;
         echo json_encode($json);
         exit;
     }
     // If the introducees aren't in the database yet, add them
     $introducee1->addToDatabase();
     $introducee2->addToDatabase();
     // If the introducees are on LinkedIn, add their public profile URL and picture to the DB
     if ($introducee1->getLinkedInId() != null || $introducee2->getLinkedInId() != null) {
         // Connect to LinkedIn API
         $sth = $db->prepare('SELECT id, access_token FROM linkedin WHERE person_id = :person_id');
         $sth->execute(array(':person_id' => $userId));
         $userDetails = $sth->fetch(PDO::FETCH_ASSOC);
         if (!empty($userDetails['access_token'])) {
             $linkedInAccessToken = $userDetails['access_token'];
             // Create LinkedIn object
             $API_CONFIG = array('appKey' => LI_API_KEY, 'appSecret' => LI_SECRET, 'callbackUrl' => '');
             $OBJ_linkedin = new LinkedIn($API_CONFIG);
             $OBJ_linkedin->setTokenAccess(unserialize($linkedInAccessToken));
             // Which introducees are on LinkedIn?
             $profilesToRequest = array();
             if ($introducee1->getLinkedInId() != null) {
                 $profilesToRequest[] = 'id=' . $introducee1->getLinkedInId();
             }
             if ($introducee2->getLinkedInId() != null) {
                 $profilesToRequest[] = 'id=' . $introducee2->getLinkedInId();
             }
             try {
                 $linkedInProfiles = $OBJ_linkedin->profileNew('::(' . implode(',', $profilesToRequest) . '):(id,public-profile-url,picture-url)');
             } catch (ErrorException $e) {
             }
             if ($linkedInProfiles['success'] === TRUE) {
                 $linkedInProfiles['linkedin'] = new SimpleXMLElement($linkedInProfiles['linkedin']);
                 if ($linkedInProfiles['linkedin']->getName() == 'people') {
                     foreach ($linkedInProfiles['linkedin']->person as $person) {
                         $id = (string) $person->id;
                         $url = (string) $person->{'public-profile-url'};
                         $pic = (string) $person->{'picture-url'};
                         if ($id && ($url || $pic)) {
                             $update = $db->prepare('REPLACE INTO temp_linkedin SET linkedin_id = :linkedin_id, time=NOW(), profile_url = :profile_url, picture_url = :picture_url');
                             $update->execute(array(':linkedin_id' => $id, ':profile_url' => $url, ':picture_url' => $pic));
                         }
                     }
                 }
             }
         }
     }
     // If the introducees are on Twitter, add their screen name and picture to the DB
     if ($introducee1->getTwitterId() != null || $introducee2->getTwitterId() != null) {
         // Which introducees are on Twitter?
         $profilesToRequest = array();
         if ($introducee1->getTwitterId() != null) {
             $profilesToRequest[] = $introducee1->getTwitterId();
         }
         if ($introducee2->getTwitterId() != null) {
             $profilesToRequest[] = $introducee2->getTwitterId();
         }
         // Connect to Twitter API
         $sth = $db->prepare('SELECT id, access_token FROM twitter WHERE person_id = :person_id');
         $sth->execute(array(':person_id' => $userId));
         $userDetails = $sth->fetch(PDO::FETCH_ASSOC);
         if (!empty($userDetails['access_token'])) {
             $twitterAccessToken = unserialize($userDetails['access_token']);
             try {
                 $twitter = new TwitterOAuth(TW_CONSUMER, TW_SECRET, $twitterAccessToken['oauth_token'], $twitterAccessToken['oauth_token_secret']);
                 $twitter->format = 'json';
                 $twitterProfiles = $twitter->get('users/lookup', array('user_id' => implode(',', $profilesToRequest)));
                 foreach ($twitterProfiles as $friend) {
                     $id = (string) $friend->id;
                     $screenName = (string) $friend->screen_name;
                     $pic = (string) $friend->profile_image_url;
                     $protected = (string) $friend->protected;
                     if ($id && ($screenName || $pic || $protected)) {
                         $update = $db->prepare('REPLACE INTO temp_twitter SET twitter_id = :twitter_id, time=NOW(), screen_name = :screen_name, picture_url = :picture_url, protected = :protected');
                         $update->execute(array(':twitter_id' => $id, ':screen_name' => $screenName, ':picture_url' => $pic, ':protected' => $protected));
                     }
                 }
             } catch (ErrorException $e) {
                 // Could not post to Twitter. Bad access token?
                 Debug::l('Error posting to Twitter ' . $e);
             }
         }
     }
     $linkPassword = BaseConvert::generatePassword();
     // Add the introduction to the database
     $insert = $db->prepare('INSERT INTO introduction (introducer_id, introducee1_id, introducee2_id, time, link_password) VALUES (:introducer_id, :introducee1_id, :introducee2_id, NOW(), :link_password)');
     $insert->execute(array(':introducer_id' => $userId, ':introducee1_id' => $introducee1->getId(), ':introducee2_id' => $introducee2->getId(), ':link_password' => $linkPassword));
     $introId = $db->lastInsertId();
     // Add the links for each introducee
     $linkPassword1 = BaseConvert::generatePassword();
     $linkPassword2 = BaseConvert::generatePassword();
     $insert = $db->prepare('INSERT INTO link (introduction_id, person_id, link_password) VALUES (:introduction_id, :person_id, :link_password)');
     $insert->execute(array(':introduction_id' => $introId, ':person_id' => $introducee1->getId(), ':link_password' => $linkPassword1));
     $insert->execute(array(':introduction_id' => $introId, ':person_id' => $introducee2->getId(), ':link_password' => $linkPassword2));
     // If there is a message, add it to the database
     if (!empty($_POST["message"])) {
         $message = htmlentities(trim($_POST['message']), ENT_QUOTES, 'UTF-8');
         if (!empty($message)) {
             $insert = $db->prepare('INSERT INTO message (body, time, introduction_id, writer_id) VALUES (:body, NOW(), :introduction_id, :writer_id)');
             $insert->execute(array(':body' => $message, ':introduction_id' => $introId, ':writer_id' => $userId));
         }
     }
     // Return the success message, which will tell the Javascript to redirect the user to the send-introduction page
     $json['result'] = 'true';
     $json['link'] = APP_URL . '/' . Content::l() . '/send-introduction/';
     $json['time'] = Debug::getInstance()->getTimeElapsed();
     echo json_encode($json);
 }
Пример #10
0
function updateLinkedInStatus()
{
    $API_CONFIG = array('appKey' => LINKEDIN_API_KEY_PUBLIC, 'appSecret' => LINKEDIN_API_KEY_PRIVATE, 'callbackUrl' => NULL);
    $sql = "select `username`, `access_token`, `access_token_secret` FROM `love_users` where `linkedin_share` = 1;";
    $result = mysql_query($sql);
    while ($row = mysql_fetch_assoc($result)) {
        $sql = "select  count(*) as loves ,count(distinct giver) as givers from love_love where receiver = '" . $row['username'] . "' and at > DATE_SUB(CURDATE(),INTERVAL 7 DAY);";
        $result2 = mysql_query($sql);
        $row2 = mysql_fetch_assoc($result2);
        if ((int) $row2['givers'] > 0 && (int) $row2['loves'] > 0) {
            $OBJ_linkedin = new LinkedIn($API_CONFIG);
            $OBJ_linkedin->setTokenAccess(array('oauth_token' => $row['access_token'], 'oauth_token_secret' => $row['access_token_secret']));
            $response = $OBJ_linkedin->share('new', array('comment' => "This week's love stats: " . $row2['loves'] . " love from " . $row2['givers'] . " people."), FALSE);
            //DEBUG OAUTH TOKENS IF NEEDED
            /*
            if($response['success'] === TRUE) {
                error_log("DATA SENT TO LINKEDIN!");
            } else {
                error_log("Error revoking user's token:<br /><br />RESPONSE:<br /><br /><pre>" . print_r($response, TRUE) . "</pre><br /><br />LINKEDIN OBJ:<br /><br /><pre>" . print_r($OBJ_linkedin, TRUE) . "</pre>");
            }
            */
        }
    }
}
Пример #11
0
<?php

header('Content-type: application/json');
require '../config/keys.php';
require '../lib/linkedin/linkedin_3.2.0.class.php';
$API_CONFIG = $linkedin['config'];
$OBJ_linkedin = new LinkedIn($API_CONFIG);
$OBJ_linkedin->setTokenAccess($linkedin['access']);
$OBJ_linkedin->setResponseFormat(LINKEDIN::_RESPONSE_JSON);
$json = $OBJ_linkedin->profile('~:(first-name,last-name,formatted-name,industry,skills,summary,specialties,positions,picture-url,educations,interests,headline,phone-numbers,email-address,member-url-resources)');
$info = json_decode($json['linkedin']);
$node = array('name' => $info->formattedName, 'headline' => $info->headline, 'picture_url' => $info->pictureUrl, 'summary' => $info->summary, 'work_history' => $info->positions->values, 'meta' => 'Powered by LinkedIn', 'profile_url' => 'http://www.linkedin.com/in/njhamann');
if ($json['success'] === TRUE) {
    if (isset($_GET['raw']) && $_GET['raw'] == '1') {
        echo json_encode($info);
    } else {
        echo json_encode($node);
    }
}
Пример #12
0
 public function setAccess($access)
 {
     $access = EasyBlogHelper::getRegistry($access);
     return parent::setTokenAccess(array('oauth_token' => $access->get('token'), 'oauth_token_secret' => $access->get('secret')));
 }
Пример #13
0
 function linkedin()
 {
     $cookie_name = "linkedin_oauth_" . SETTING::linkedInAPI;
     //Check if Cookie exists &&  Login is enabled
     if ($this->repository->get_data("linkedinLogin") && isset($_COOKIE[$cookie_name]) && $_COOKIE[$cookie_name]) {
         $credentials_json = $_COOKIE[$cookie_name];
         // where PHP stories cookies
         $credentials = json_decode($credentials_json);
         // validate signature
         if ($credentials->signature_version == 1) {
             if ($credentials->signature_order && is_array($credentials->signature_order)) {
                 $base_string = '';
                 // build base string from values ordered by signature_order
                 foreach ($credentials->signature_order as $key) {
                     if (isset($credentials->{$key})) {
                         $base_string .= $credentials->{$key};
                     } else {
                         print "missing signature parameter: {$key}";
                     }
                 }
                 // hex encode an HMAC-SHA1 string
                 $signature = base64_encode(hash_hmac('sha1', $base_string, SETTING::linkedInSecret, true));
                 // check if our signature matches the cookie's
                 if ($signature == $credentials->signature) {
                     //Signature is authentic, use the stuff
                     require_once 'linkedin_3.3.0.class.php';
                     $linkedin = new LinkedIn(array('appKey' => SETTING::linkedInAPI, 'appSecret' => SETTING::linkedInSecret, 'callbackUrl' => NULL));
                     $tokens = $linkedin->exchangeToken($credentials->access_token);
                     //Find member_id
                     $sql = "SELECT id, nonce  FROM Users WHERE linkedin_id = '" . $credentials->member_id . "'";
                     $result = mysql_query($sql);
                     if (mysql_num_rows($result) == 1) {
                         $row = mysql_fetch_assoc($result);
                         $userId = $row["id"];
                         $this->setSession($row["id"], $row["nonce"]);
                         //UPDATE LinkedinToken
                         $sql = "UPDATE Users SET linkedin_token = '" . $tokens["linkedin"]["oauth_token"] . "', linkedin_token_secret = '" . $tokens["linkedin"]["oauth_token_secret"] . "' WHERE " . $this->USER_ID . " = " . $userId;
                         $query = mysql_query($sql);
                     }
                     //No member found, check if user already exists based upon usernam = email
                     if (mysql_num_rows($result) == 0) {
                         //print_r($tokens);
                         $linkedin->setTokenAccess($tokens["linkedin"]);
                         $result = $linkedin->profile("~:(email-address)?format=json");
                         $result = json_decode($result["linkedin"], true);
                         $sql = "SELECT id, nonce FROM Users WHERE " . $this->USER_NAME . " = '" . $result["emailAddress"] . "'";
                         $query = mysql_query($sql);
                         if (mysql_num_rows($query) == 1) {
                             //Combination is known
                             $row = mysql_fetch_assoc($query);
                             //print_r($row);
                             $userId = $row["id"];
                             $this->setSession($row["id"], $row["nonce"]);
                             //UPDATE LinkedinToken
                             $sql = "UPDATE Users SET linkedin_token = '" . $tokens["linkedin"]["oauth_token"] . "', linkedin_token_secret = '" . $tokens["linkedin"]["oauth_token_secret"] . "', linkedin_id = '" . $credentials->member_id . "' WHERE " . $this->USER_ID . " = " . $userId;
                             $query = mysql_query($sql);
                             //Perform import of LinkedIn data
                             require_once "user.class.php";
                             $user = new user($userId, $this->errorClass, $this->notificationClass);
                             $user->getLinkedInData();
                         } else {
                             //Combination is not known, create new profile if stated
                             if ($this->repository->get_data("linkedinRegister") == 1) {
                                 $email = $result["emailAddress"];
                                 $nonce = $this->create_nonce();
                                 $user_ip = $this->repository->get_data('userIPv4');
                                 $email_hash = $this->hash_password($email, $nonce);
                                 //Define the reference number for the user
                                 $sql = "SELECT MAX(`reference_number`) as maximum FROM Users WHERE created_on >= '" . date("Y") . "-01-01' AND created_on <= '" . date("Y") . "-12-31'";
                                 $result = mysql_fetch_assoc(mysql_query($sql));
                                 $reference_number = $result["maximum"] + 1;
                                 //Create public profile hash
                                 $profile_hash = $this->hash_password($reference_number, $nonce);
                                 //INSERT NEW USER TO DB
                                 $query = sprintf("INSERT INTO " . $this->USER_TABLE . " (" . $this->USER_NAME . ", " . $this->USER_IP_REGISTER . ", " . $this->USER_CREATION . ", confirm_hash, nonce, account_status, reference_number, profile_hash) VALUES ('%s','%s', NOW(), '%s','%s', 0,'%s','%s')", $email, $user_ip, $email_hash, $nonce, $reference_number, $profile_hash);
                                 $result = mysql_query($query);
                                 if (!$result) {
                                     $this->errorClass->add_error(202);
                                 } else {
                                     //INSERT Clientnr to DB
                                     $sql = "SELECT * FROM Users WHERE id = " . mysql_insert_id();
                                     $result = mysql_query($sql);
                                     $user = mysql_fetch_assoc($result);
                                     $date = strtotime($user["created_on"]);
                                     $sql = "UPDATE Users SET client_number = \"K" . date('ym', $date) . "" . sprintf('%04d', $user["reference_number"]) . "\" WHERE id = " . $user["id"];
                                     $result = mysql_query($sql);
                                     $this->setSession($user["id"], $nonce);
                                     //UPDATE LinkedinToken
                                     $sql = "UPDATE Users SET linkedin_token = '" . $tokens["linkedin"]["oauth_token"] . "', linkedin_token_secret = '" . $tokens["linkedin"]["oauth_token_secret"] . "', linkedin_id = '" . $credentials->member_id . "' WHERE " . $this->USER_ID . " = " . $user["id"];
                                     $query = mysql_query($sql);
                                     //Perform import of LinkedIn data
                                     require_once "user.class.php";
                                     $user = new user($user["id"], $this->errorClass, $this->notificationClass);
                                     $user->getLinkedInData();
                                     header("Location:" . Setting::baseUrl . "/users/complete_account.php");
                                     exit;
                                 }
                             } else {
                                 $this->notificationClass->add_note("Het emailadres die je gebruikt bij LinkedIn is niet bij ons bekend. Log in met je emailadres en wachtwoord en koppel je profiel met LinkedIn in je accountinstellingen of <a href=\"index.php?linkedinLogin=1&linkedinRegister=1\">registreer</a> met je LinkedIn account");
                             }
                         }
                     }
                     //print "signature validation succeeded";
                 } else {
                     print "signature validation failed";
                 }
             } else {
                 print "signature order missing";
             }
         } else {
             print "unknown cookie version";
         }
     }
 }
Пример #14
0
 function postFeeds()
 {
     $model = $this->getModel('postfeeds');
     $post = JRequest::get('post');
     $option = JRequest::getVar('option');
     $fb_array = array();
     $tw_array = array();
     $ln_array = array();
     $allfeeds = $post['all'];
     $fbfeeds = $post['facebook'];
     $twitterfeeds = $post['twitter'];
     $linkedinfeeds = $post['linkedin'];
     if (count($allfeeds) > 0) {
         $fb_array = $allfeeds;
         $tw_array = $allfeeds;
         $ln_array = $allfeeds;
     }
     if (count($fbfeeds) > 0) {
         $fb_union_array = array_merge($fb_array, $fbfeeds);
         $fb_array = array_unique($fb_union_array);
     }
     if (count($twitterfeeds) > 0) {
         $tw_union_array = array_merge($tw_array, $twitterfeeds);
         $tw_array = array_unique($tw_union_array);
     }
     if (count($linkedinfeeds) > 0) {
         $ln_union_array = array_merge($ln_array, $linkedinfeeds);
         $ln_array = array_unique($ln_union_array);
     }
     // For Repost
     $repostfeeds = $post['repost'];
     for ($r = 0; $r < count($repostfeeds); $r++) {
         $article_id = $repostfeeds[$r];
         $rePostData = $model->getPostedFeedData($article_id);
         if ($rePostData[0]->facebook) {
             $fb_repost_arr[] = $rePostData[0]->article_id;
         }
         if ($rePostData[0]->twitter) {
             $tw_repost_arr[] = $rePostData[0]->article_id;
         }
         if ($rePostData[0]->linkedin) {
             $ln_repost_arr[] = $rePostData[0]->article_id;
         }
     }
     if (count($fb_repost_arr) > 0) {
         $fb_repost_union_array = array_merge($fb_array, $fb_repost_arr);
         $fb_array = array_unique($fb_repost_union_array);
     }
     if (count($tw_repost_arr) > 0) {
         $tw_repost_union_array = array_merge($tw_array, $tw_repost_arr);
         $tw_array = array_unique($tw_repost_union_array);
     }
     if (count($ln_repost_arr) > 0) {
         $ln_repost_union_array = array_merge($ln_array, $ln_repost_arr);
         $ln_array = array_unique($ln_repost_union_array);
     }
     // End for Repost
     $redsocialhelper = new redsocialhelper();
     $login = $redsocialhelper->getsettings();
     // For Facebook Post
     for ($f = 0; $f < count($fb_array); $f++) {
         //Get Article Data
         $article = $model->getArticleData($fb_array[$f]);
         // For Facebook
         $app_id = $login['app_id'];
         $app_secret = $login['app_secret'];
         $facebook = new Facebook(array('appId' => $app_id, 'secret' => $app_secret, 'cookie' => true));
         $result_fb_token = $redsocialhelper->getFbAccessToken();
         $fb_token = $result_fb_token[0]->fb_token;
         $profile_id = $result_fb_token[0]->profile_id;
         //'413610368700619';
         $profile_name = $redsocialhelper->getProfilename($profile_id);
         $attachment = array('message' => strip_tags($article[0]->introtext), 'access_token' => $fb_token);
         $userWall = $facebook->api('/' . $profile_name . '/feed', 'post', $attachment);
         $postedData = $model->savePostedFeedData($fb_array[$f], "facebook");
         // End for Facebook
     }
     // End
     // For Twitter Post
     for ($t = 0; $t < count($tw_array); $t++) {
         //Get Article Data
         $article = $model->getArticleData($tw_array[$t]);
         //your app's consumer key
         $consumer_key = $login['twitter_consumer_key'];
         //your app's secret key
         $consumer_secret = $login['twitter_consumer_sec'];
         $twitter_token_result = $redsocialhelper->getTwitterAccessToken();
         $twitter_token = $twitter_token_result[0]->twitter_token;
         $twitter_secret = $twitter_token_result[0]->twitter_secret;
         $post_feed = strip_tags(substr($article[0]->introtext, 0, 140));
         $twitteroauth = new TwitterOAuth($consumer_key, $consumer_secret, $twitter_token, $twitter_secret);
         $twitterpost = $twitteroauth->post('statuses/update', array('status' => $post_feed));
         $postedData = $model->savePostedFeedData($tw_array[$t], "twitter");
     }
     // End
     // For LinkedIN
     for ($l = 0; $l < count($ln_array); $l++) {
         //Get Article Data
         $article = $model->getArticleData($ln_array[$l]);
         // LinkedinApi key
         $api_key = $login['linked_api_key'];
         //LinkedinSecret key
         $secret_key = $login['linked_secret_key'];
         $access_tokens = $redsocialhelper->getLinkedinAccessToken();
         $API_CONFIG = array('appKey' => $api_key, 'appSecret' => $secret_key, 'callbackUrl' => "");
         $linkedin = new LinkedIn($API_CONFIG);
         $access_token = $access_tokens[0]->linkedin_token;
         $access_secret = $access_tokens[0]->linkedin_secret;
         $token = array("oauth_token" => $access_token, "oauth_token_secret" => $access_secret);
         $linkedin->setTokenAccess($token);
         $response = $linkedin->updateNetwork(strip_tags(substr($article[0]->introtext, 0, 999)));
         $postedData = $model->savePostedFeedData($ln_array[$l], "linkedin");
     }
     // End for LinkedIN
     $msg = JText::_("COM_REDSOCIALSTREAM_FEED_POSTED_SUCCESSFULLY");
     $link = 'index.php?option=' . $option . '&view=postfeeds';
     $this->setRedirect($link, $msg);
 }
Пример #15
0
    function getLinkedinProfile($req_type)
    {
        $session = LinkedinHelper::oauth_session_exists();
        $app = JFactory::getApplication();
        // include the LinkedIn class
        require_once 'linkedin_3.1.1.class.php';
        // display constants
        $API_CONFIG = array('appKey' => 'r7xckk3gxdfg', 'appSecret' => 'fJQh57Ex2Qg7YyPi', 'callbackUrl' => NULL);
        define('CONNECTION_COUNT', 20);
        define('PORT_HTTP', '80');
        define('PORT_HTTP_SSL', '443');
        define('UPDATE_COUNT', 10);
        // set index
        //$_REQUEST[LINKEDIN::_GET_TYPE] = (isset($_REQUEST[LINKEDIN::_GET_TYPE])) ? $_REQUEST[LINKEDIN::_GET_TYPE] : '';
        switch ($req_type) {
            case 'initiate':
                /**
                 * Handle user initiated LinkedIn connection, create the LinkedIn object.
                 */
                // check for the correct http protocol (i.e. is this script being served via http or https)
                if (isset($_SERVER['HTTPS'])) {
                    if ($_SERVER['HTTPS'] == 'on') {
                        $protocol = 'https';
                    } else {
                        $protocol = 'http';
                    }
                } else {
                    $protocol = 'http';
                }
                // set the callback url
                $API_CONFIG['callbackUrl'] = $protocol . '://' . $_SERVER['SERVER_NAME'] . ($_SERVER['SERVER_PORT'] != PORT_HTTP || $_SERVER['SERVER_PORT'] != PORT_HTTP_SSL ? ':' . $_SERVER['SERVER_PORT'] : '') . $_SERVER['PHP_SELF'] . '?' . $req_type . '=initiate&' . LINKEDIN::_GET_RESPONSE . '=1';
                // $API_CONFIG['callbackUrl'] = JRoute::_('index.php?option=com_jobboard&view=user') . '&' . $req_type . '=initiate&' . LINKEDIN::_GET_RESPONSE . '=1';
                //  echo $API_CONFIG['callbackUrl'];die;
                $OBJ_linkedin = new LinkedIn($API_CONFIG);
                // check for response from LinkedIn
                $_GET[LINKEDIN::_GET_RESPONSE] = isset($_GET[LINKEDIN::_GET_RESPONSE]) ? $_GET[LINKEDIN::_GET_RESPONSE] : '';
                if (!$_GET[LINKEDIN::_GET_RESPONSE]) {
                    // LinkedIn hasn't sent us a response, the user is initiating the connection
                    // send a request for a LinkedIn access token
                    $response = $OBJ_linkedin->retrieveTokenRequest();
                    //echo 'response: '.'<pre>'.print_r($response, true).'</pre>';
                    if ($response['success'] === TRUE) {
                        // store the request token
                        $session_oauth = $session->get('oauth');
                        $session_oauth['oauth']['linkedin']['request'] = $response['linkedin'];
                        $session->set('oauth', $session_oauth);
                        //redirect the user to the LinkedIn authentication/authorisation page to initiate validation.
                        $app->redirect(LINKEDIN::_URL_AUTH . $response['linkedin']['oauth_token']);
                    } else {
                        $profile_assoc = array();
                        $profile_assoc['response'] = false;
                        $profile_assoc['msg'] = "Request token retrieval failed:<br /><br />RESPONSE:<br /><br /><pre>";
                        return $profile_assoc;
                        // bad token request
                    }
                } else {
                    // LinkedIn has sent a response
                    // user has cancelled LinkedIn authentication
                    if (JRequest::getString('oauth_problem') == 'user_refused') {
                        $app->redirect('index.php?option=com_jobboard&view=user&task=addcv', JText::_('COM_JOBBOARD_IMPORTLINKEDINCANCELLED'));
                    }
                    // user has granted permission, take the temp access token, the user's secret and the verifier to request the user's real secret key
                    $session_oauth = $session->get('oauth');
                    $response = $OBJ_linkedin->retrieveTokenAccess($session_oauth['oauth']['linkedin']['request']['oauth_token'], $session_oauth['oauth']['linkedin']['request']['oauth_token_secret'], $_GET['oauth_verifier']);
                    if ($response['success'] === TRUE) {
                        // the request went through without an error, gather user's 'access' tokens
                        $session_oauth['oauth']['linkedin']['access'] = $response['linkedin'];
                        // set the user as authorized for future quick reference
                        $session_oauth['oauth']['linkedin']['authorized'] = TRUE;
                        $session->set('oauth', $session_oauth);
                    } else {
                        // bad token access
                        echo "Access token retrieval failed:<br /><br />RESPONSE:<br /><br /><pre>" . print_r($response, TRUE) . "</pre><br /><br />LINKEDIN OBJ:<br /><br /><pre>" . print_r($OBJ_linkedin, TRUE) . "</pre>";
                    }
                }
                $response = $OBJ_linkedin->profile('~:(id,first-name,last-name,summary,educations,positions,skills)');
                if ($response['success'] === TRUE) {
                    $profile = new SimpleXMLElement($response['linkedin']);
                    $profile_json = json_encode($profile);
                    $profile_assoc = array_unique(json_decode($profile_json, TRUE), SORT_REGULAR);
                    $profile_assoc['response'] = $response['success'];
                } else {
                    // profile retrieval failed
                    $profile_assoc = array();
                    $profile_assoc['response'] = false;
                }
                return $profile_assoc;
                break;
            case 'revoke':
                /**
                 * Handle authorization revocation.
                 */
                $session_oauth = $session->get('oauth');
                $OBJ_linkedin = new LinkedIn($API_CONFIG);
                $OBJ_linkedin->setTokenAccess($session_oauth['oauth']['linkedin']['access']);
                $response = $OBJ_linkedin->revoke();
                if ($response['success'] === TRUE) {
                    // revocation successful, clear session
                    if ($session->clear('oauth')) {
                        // session destroyed
                        //header('Location: ' . $_SERVER['PHP_SELF']);
                    } else {
                        // session not destroyed
                        echo "Error clearing user's session";
                    }
                } else {
                    // revocation failed
                    echo "Error revoking user's token:<br /><br />RESPONSE:<br /><br /><pre>" . print_r($response, TRUE) . "</pre><br /><br />LINKEDIN OBJ:<br /><br /><pre>" . print_r($OBJ_linkedin, TRUE) . "</pre>";
                }
                break;
            default:
                // nothing being passed back, display demo page
                // check PHP version
                if (version_compare(PHP_VERSION, '5.0.0', '<')) {
                    throw new LinkedInException('You must be running version 5.x or greater of PHP to use this library.');
                }
                // check for cURL
                if (extension_loaded('curl')) {
                    $curl_version = curl_version();
                    $curl_version = $curl_version['version'];
                } else {
                    throw new LinkedInException('You must load the cURL extension to use this library.');
                }
                $session_oauth = $session->get('oauth');
                if (!isset($session_oauth['oauth']['linkedin']['authorized'])) {
                    $session_oauth['oauth']['linkedin']['authorized'] = FALSE;
                    $session->set('oauth', $session_oauth);
                }
                if ($session_oauth['oauth']['linkedin']['authorized'] === TRUE) {
                    // user is already connected
                    $OBJ_linkedin = new LinkedIn($API_CONFIG);
                    $OBJ_linkedin->setTokenAccess($session_oauth['oauth']['linkedin']['access']);
                    ?>

                  <?php 
                    //$response = $OBJ_linkedin->profile('~:(id,first-name,last-name,picture-url)');
                    $response = $OBJ_linkedin->profile('~:(id,first-name,last-name,summary,educations,positions,skills)');
                    if ($response['success'] === TRUE) {
                        //$response['linkedin'] = new SimpleXMLElement($response['linkedin']);
                        // echo "<pre>" . print_r($response['linkedin'], TRUE) . "</pre>";
                        $profile = new SimpleXMLElement($response['linkedin']);
                        $profile_json = json_encode($profile);
                        return json_decode($profile_json, TRUE);
                    } else {
                        // profile retrieval failed
                        echo "Error retrieving profile information:<br /><br />RESPONSE:<br /><br /><pre>" . print_r($response) . "</pre>";
                    }
                } else {
                    // user isn't connected
                    ?>
                  <?php 
                }
                ?>
            <?php 
                break;
        }
    }
Пример #16
0
 /**
  * Similar to onAuthenticate, except we already have a logged in user, we're just linking accounts
  *
  * @param   array  $options
  * @return  void
  */
 public function link($options = array())
 {
     $jsession = App::get('session');
     // Set up linkedin configuration
     $linkedin_config['appKey'] = $this->params->get('api_key');
     $linkedin_config['appSecret'] = $this->params->get('app_secret');
     // Create Object
     $linkedin_client = new LinkedIn($linkedin_config);
     if (!Request::getVar('oauth_verifier', NULL)) {
         // User didn't authorize our app, or, clicked cancel
         App::redirect(Route::url('index.php?option=com_members&id=' . User::get('id') . '&active=account'), Lang::txt('PLG_AUTHENTICATION_LINKEDIN_MUST_AUTHORIZE_TO_LOGIN', App::get('sitename')), 'error');
     }
     // LinkedIn has sent a response, user has granted permission, take the temp access token,
     // the user's secret and the verifier to request the user's real secret key
     $request = $jsession->get('linkedin.oauth.request');
     $reply = $linkedin_client->retrieveTokenAccess($request['oauth_token'], $request['oauth_token_secret'], Request::getVar('oauth_verifier'));
     if ($reply['success'] === TRUE) {
         // The request went through without an error, gather user's 'access' tokens
         $jsession->set('linkedin.oauth.access', $reply['linkedin']);
         // Set the user as authorized for future quick reference
         $jsession->set('linkedin.oauth.authorized', TRUE);
     } else {
         return new Exception(Lang::txt('Access token retrieval failed'), 500);
     }
     if ($jsession->get('linkedin.oauth.authorized') == TRUE) {
         $linkedin_client->setTokenAccess($jsession->get('linkedin.oauth.access'));
         // Get the linked in profile
         $profile = $linkedin_client->profile('~:(id,first-name,last-name,email-address)');
         $profile = $profile['linkedin'];
         // Parse the profile XML
         $profile = new SimpleXMLElement($profile);
         // Get the profile values
         $li_id = $profile->{'id'};
         $username = (string) $li_id;
         // (make sure this is unique)
         $hzad = \Hubzero\Auth\Domain::getInstance('authentication', 'linkedin', '');
         // Create the link
         if (\Hubzero\Auth\Link::getInstance($hzad->id, $username)) {
             // This linkedin account is already linked to another hub account
             App::redirect(Route::url('index.php?option=com_members&id=' . User::get('id') . '&active=account'), Lang::txt('PLG_AUTHENTICATION_LINKEDIN_ACCOUNT_ALREADY_LINKED'), 'error');
         } else {
             $hzal = \Hubzero\Auth\Link::find_or_create('authentication', 'linkedin', null, $username);
             $hzal->user_id = User::get('id');
             $hzal->email = (string) $profile->{'email-address'};
             $hzal->update();
         }
     } else {
         // User didn't authorize our app, or, clicked cancel
         App::redirect(Route::url('index.php?option=com_members&id=' . User::get('id') . '&active=account'), Lang::txt('PLG_AUTHENTICATION_LINKEDIN_MUST_AUTHORIZE_TO_LINK', Config::get('sitename')), 'error');
     }
 }
Пример #17
0
 function test($ltype = '', $response = '', $oauth_token = '', $oauth_verfier = '')
 {
     $this->data['success'] = FALSE;
     function oauth_session_exists()
     {
         if (is_array($_SESSION) && array_key_exists('oauth', $_SESSION)) {
             return TRUE;
         } else {
             return FALSE;
         }
     }
     try {
         // include the LinkedIn class
         //require_once('linkedin_3.2.0.class.php');
         // start the session
         // if(!session_start()) {
         // throw new LinkedInException('This script requires session support, which appears to be disabled according to session_start().');
         // }
         // display constants
         if (isset($_REQUEST['invitation_key'])) {
             $this->data['invitation_key_val'] = $_REQUEST['invitation_key'];
         } elseif ($this->input->post('invitation_key')) {
             $this->data['invitation_key_val'] = $this->input->post('invitation_key');
         } else {
             $this->data['invitation_key_val'] = '';
         }
         if (isset($_REQUEST['email_val'])) {
             $this->data['email_val'] = $_REQUEST['email_val'];
         } elseif ($this->input->post('email_val')) {
             $this->data['email_val'] = $this->input->post('email_val');
         } else {
             $this->data['email_val'] = '';
         }
         $API_CONFIG = array('appKey' => 'ctfw9ywn6vrm', 'appSecret' => 'T2G5ccnIfGytPAdt', 'callbackUrl' => NULL);
         define('DEMO_GROUP', '4010474');
         define('DEMO_GROUP_NAME', 'Simple LI Demo');
         define('PORT_HTTP', '80');
         define('PORT_HTTP_SSL', '443');
         // set index
         //echo "<script type='text/javascript'>console.log('@".LINKEDIN::_GET_TYPE."".print_r($this->uri)."')</script>";
         $_REQUEST[LINKEDIN::_GET_TYPE] = isset($_REQUEST[LINKEDIN::_GET_TYPE]) ? $_REQUEST[LINKEDIN::_GET_TYPE] : '';
         //echo "<script type='text/javascript'>console.log('@".$_REQUEST[LINKEDIN::_GET_TYPE]."')</script>";
         switch ($_REQUEST[LINKEDIN::_GET_TYPE]) {
             case 'initiate':
                 /**
                  * Handle user initiated LinkedIn connection, create the LinkedIn object.
                  */
                 // check for the correct http protocol (i.e. is this script being served via http or https)
                 if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
                     $protocol = 'https';
                 } else {
                     $protocol = 'http';
                 }
                 // set the callback url
                 $API_CONFIG['callbackUrl'] = $protocol . '://' . $_SERVER['SERVER_NAME'] . ($_SERVER['SERVER_PORT'] != PORT_HTTP || $_SERVER['SERVER_PORT'] != PORT_HTTP_SSL ? ':' . $_SERVER['SERVER_PORT'] : '') . $_SERVER['PHP_SELF'] . '?' . LINKEDIN::_GET_TYPE . '=initiate&' . LINKEDIN::_GET_RESPONSE . '=1';
                 $OBJ_linkedin = new LinkedIn($API_CONFIG);
                 // check for response from LinkedIn
                 $_GET[LINKEDIN::_GET_RESPONSE] = isset($_GET[LINKEDIN::_GET_RESPONSE]) ? $_GET[LINKEDIN::_GET_RESPONSE] : '';
                 if (!$_GET[LINKEDIN::_GET_RESPONSE]) {
                     // LinkedIn hasn't sent us a response, the user is initiating the connection
                     // send a request for a LinkedIn access token
                     $response = $OBJ_linkedin->retrieveTokenRequest();
                     if ($response['success'] === TRUE) {
                         // store the request token
                         $_SESSION['oauth']['linkedin']['request'] = $response['linkedin'];
                         // redirect the user to the LinkedIn authentication/authorisation page to initiate validation.
                         header('Location: ' . LINKEDIN::_URL_AUTH . $response['linkedin']['oauth_token']);
                     } else {
                         // bad token request
                         echo "Request token retrieval failed:<br /><br />RESPONSE:<br /><br /><pre>" . print_r($response, TRUE) . "</pre><br /><br />LINKEDIN OBJ:<br /><br /><pre>" . print_r($OBJ_linkedin, TRUE) . "</pre>";
                     }
                 } else {
                     // LinkedIn has sent a response, user has granted permission, take the temp access token, the user's secret and the verifier to request the user's real secret key
                     $response = $OBJ_linkedin->retrieveTokenAccess($_SESSION['oauth']['linkedin']['request']['oauth_token'], $_SESSION['oauth']['linkedin']['request']['oauth_token_secret'], $_GET['oauth_verifier']);
                     if ($response['success'] === TRUE) {
                         // the request went through without an error, gather user's 'access' tokens
                         $_SESSION['oauth']['linkedin']['access'] = $response['linkedin'];
                         $this->data['success'] = TRUE;
                         $this->data['status'] = TRUE;
                         $response['linkedin'] = new SimpleXMLElement($response['linkedin']);
                         // set the user as authorized for future quick reference
                         $_SESSION['oauth']['linkedin']['authorized'] = TRUE;
                         // redirect the user back to the demo page
                         header('Location: ' . $_SERVER['PHP_SELF']);
                     } else {
                         // bad token access
                         echo "Access token retrieval failed:<br /><br />RESPONSE:<br /><br /><pre>" . print_r($response, TRUE) . "</pre><br /><br />LINKEDIN OBJ:<br /><br /><pre>" . print_r($OBJ_linkedin, TRUE) . "</pre>";
                     }
                 }
                 break;
             default:
                 // nothing being passed back, display demo page
                 // check PHP version
                 if (version_compare(PHP_VERSION, '5.0.0', '<')) {
                     throw new LinkedInException('You must be running version 5.x or greater of PHP to use this library.');
                 }
                 // check for cURL
                 if (extension_loaded('curl')) {
                     $curl_version = curl_version();
                     $curl_version = $curl_version['version'];
                 } else {
                     throw new LinkedInException('You must load the cURL extension to use this library.');
                 }
                 $_SESSION['oauth']['linkedin']['authorized'] = isset($_SESSION['oauth']['linkedin']['authorized']) ? $_SESSION['oauth']['linkedin']['authorized'] : FALSE;
                 if ($_SESSION['oauth']['linkedin']['authorized'] === TRUE) {
                     $OBJ_linkedin = new LinkedIn($API_CONFIG);
                     $OBJ_linkedin->setTokenAccess($_SESSION['oauth']['linkedin']['access']);
                     $OBJ_linkedin->setResponseFormat(LINKEDIN::_RESPONSE_XML);
                 } else {
                 }
                 if ($_SESSION['oauth']['linkedin']['authorized'] === TRUE) {
                     // user is already connected
                     $application_key = $OBJ_linkedin->getApplicationKey();
                     $this->data['success'] = FALSE;
                     $response = $OBJ_linkedin->profile('~:(id,first-name,last-name,picture-url)');
                     $this->data['response'] = $response;
                     if ($response['success'] === TRUE) {
                         $this->data['success'] = TRUE;
                         $this->data['status'] = TRUE;
                         $response['linkedin'] = new SimpleXMLElement($response['linkedin']);
                         //var_dump($response['linkedin']);
                         $this->data['response'] = $response['linkedin'];
                     } else {
                         $this->data['status'] = FALSE;
                         // request failed
                     }
                 } else {
                     // user isn't connected
                 }
                 break;
         }
     } catch (LinkedInException $e) {
         // exception raised by library call
         $e->getMessage();
     }
     $this->data['invitation_key'] = array('name' => 'invitation_key', 'id' => 'invitation_key', 'value' => $this->data['invitation_key_val'], 'type' => 'hidden');
     $this->data['first_name'] = array('name' => 'first_name', 'id' => 'first_name', 'type' => 'text', 'value' => $this->form_validation->set_value('first_name'), 'placeholder' => 'First Name', 'required' => 'required');
     $this->data['last_name'] = array('name' => 'last_name', 'id' => 'last_name', 'type' => 'text', 'value' => $this->form_validation->set_value('last_name'), 'placeholder' => 'Last Name', 'required' => 'required');
     $this->data['email'] = array('name' => 'email', 'id' => 'email', 'type' => 'text', 'value' => $this->data['email_val'], 'placeholder' => 'Email', 'required' => 'required', 'readonly' => 'readonly');
     $this->data['password'] = array('name' => 'password', 'id' => 'password', 'type' => 'password', 'value' => $this->form_validation->set_value('password'), 'placeholder' => 'Password', 'required' => 'required');
     $this->data['password_confirm'] = array('name' => 'password_confirm', 'id' => 'password_confirm', 'type' => 'password', 'value' => $this->form_validation->set_value('password_confirm'), 'placeholder' => 'Confirm Password', 'required' => 'required');
     // Render View
     //$this->load->view('auth/create_user', $this->data);
     $this->data['main_content'] = '/auth/signup';
     $this->load->view('includes/tmpl_singlebox', $this->data);
 }
Пример #18
0
/**
* Revoke Authorization.
*/
function bb_li_revoke()
{
    $API_CONFIG = array('appKey' => bb_get_option('li_app_id'), 'appSecret' => bb_get_option('li_secret'), 'callbackUrl' => NULL);
    // check the session
    try {
        $_SESSION['oauth']['linkedin']['authorized'] = isset($_SESSION['oauth']['linkedin']['authorized']) ? $_SESSION['oauth']['linkedin']['authorized'] : FALSE;
        if ($_SESSION['oauth']['linkedin']['authorized'] === TRUE) {
            $OBJ_linkedin = new LinkedIn($API_CONFIG);
            $OBJ_linkedin->setTokenAccess($_SESSION['oauth']['linkedin']['access']);
            $response = $OBJ_linkedin->revoke();
            //bb_die($response['info']['http_code']);
            if ($response['success'] == TRUE || $response['info']['http_code'] == 200) {
                // revocation successful, logout and clear session
                $var = 'oauth';
                unset($_SESSION[$var]);
                session_unregister($var);
                //bb_die(bb_get_option('uri'));
                //bb_safe_redirect(bb_get_option('uri').'bb-login.php?logout=1');
                $redirect_url = $_REQUEST['li_bb_revoke'];
                if (strpos($redirect_url, bb_get_option('uri')) !== 0) {
                    $redirect_url = bb_get_option('uri');
                }
                bb_safe_redirect($redirect_url);
                exit;
            } else {
                // revocation failed
                bb_die("revocation failed");
            }
        }
    } catch (LinkedInException $e) {
        error_log($e);
    }
}
 public static function linkedin_old()
 {
     $id = ESSBSocialFansCounterHelper::get_option('linkedin.id');
     $account_type = ESSBSocialFansCounterHelper::get_option('linkedin.account_type', 'company');
     $app_key = ESSBSocialFansCounterHelper::get_option('linkedin.app_key');
     $app_secret = ESSBSocialFansCounterHelper::get_option('linkedin.app_secret');
     $oauth_token = ESSBSocialFansCounterHelper::get_option('linkedin.oauth_token');
     $oauth_token_secret = ESSBSocialFansCounterHelper::get_option('linkedin.oauth_token_secret');
     if (empty($id) || empty($app_secret) || empty($app_key) || $account_type == 'profile' && (empty($oauth_token) || empty($oauth_token_secret))) {
         return 0;
     }
     $opt = array('appKey' => $app_key, 'appSecret' => $app_secret, 'callbackUrl' => '');
     $api = new LinkedIn($opt);
     if ($account_type == 'company') {
         $response = $api->company(trim('universal-name=' . $id . ':(num-followers)'));
     } elseif ($account_type == 'group') {
         $response = $api->group($id, ':(num-members)');
     } else {
         $api->setTokenAccess(array('oauth_token' => $oauth_token, 'oauth_token_secret' => $oauth_token_secret));
         $response = $api->statistics($id);
     }
     if (false == $response['success']) {
         return false;
     }
     $xml = new SimpleXMLElement($response['linkedin']);
     $count = 0;
     if ($account_type == 'company') {
         if (isset($xml->{'num-followers'})) {
             $count = current($xml->{'num-followers'});
         }
     }
     if ($account_type == 'group') {
         if (isset($xml->{'num-members'})) {
             $count = current($xml->{'num-members'});
         }
     }
     if ($account_type == 'profile') {
         if (isset($xml->property)) {
             $count = (string) $xml->property[0];
         }
     }
     return $count;
 }
Пример #20
0
 private function loadLinkedInFriends()
 {
     // If we have loaded the user's LinkedIn friends already in the last 12 hours, just reuse them
     $cacheQ = $this->db->prepare('SELECT facebook_id, linkedin_id, twitter_id, name FROM temp_friend WHERE temp_friends_id = (SELECT id FROM temp_friends WHERE linkedin_id = :linkedin_id AND time > DATE_SUB(NOW(), INTERVAL 12 HOUR) ORDER BY time DESC LIMIT 1)');
     $cacheQ->execute(array(':linkedin_id' => $this->userDetails['id']));
     $cache = $cacheQ->fetchAll(PDO::FETCH_ASSOC);
     $this->printCachedFriendsIfSet($cache);
     // Load friends from LinkedIn
     $API_CONFIG = array('appKey' => LI_API_KEY, 'appSecret' => LI_SECRET, 'callbackUrl' => '');
     $OBJ_linkedin = new LinkedIn($API_CONFIG);
     $OBJ_linkedin->setTokenAccess(unserialize($this->userDetails['access_token']));
     try {
         $linkedInFriends = $OBJ_linkedin->profile('id=' . $this->userDetails['id'] . '/connections:(id,first-name,last-name)');
     } catch (ErrorException $e) {
         $this->printAccessTokenError($e);
     }
     if ($linkedInFriends['success'] === TRUE) {
         $linkedInFriends['linkedin'] = new SimpleXMLElement($linkedInFriends['linkedin']);
     }
     // Catch LinkedIn error
     if ($linkedInFriends['success'] !== TRUE || $linkedInFriends['linkedin']->getName() != 'connections') {
         $this->printAccessTokenError('Success !== TRUE');
     }
     // No friends? :-(
     if (count($linkedInFriends['linkedin']->children()) == 0) {
         $json['result'] = 'false';
         echo json_encode($json);
         exit;
     }
     // Cache the LinkedIn friends so we don't have to query the LinkedIn API again soon
     $insert = $this->db->prepare('INSERT INTO temp_friends (time, linkedin_id) VALUES (NOW(), :linkedin_id)');
     $insert->execute(array(':linkedin_id' => $this->userDetails['id']));
     $tempFriendsId = $this->db->lastInsertId();
     $friendIds = array();
     foreach ($linkedInFriends['linkedin']->person as $friend) {
         $id = (string) $friend->id;
         $friendIds[] = $this->db->quote($id);
         $json['friends'][$id]['linkedInId'] = $id;
         $json['friends'][$id]['name'] = $friend->{'first-name'} . ' ' . $friend->{'last-name'};
     }
     $extraInfoQ = $this->db->prepare('SELECT f.id as facebookId, l.id as linkedInId, t.id as twitterId FROM linkedin l, person p LEFT JOIN facebook f ON p.id = f.person_id LEFT JOIN twitter t ON p.id = t.person_id WHERE p.id = l.person_id AND l.id IN (' . implode(',', $friendIds) . ')');
     $extraInfoQ->execute();
     $extraInfo = $extraInfoQ->fetchAll(PDO::FETCH_ASSOC);
     $json = $this->updateTemporaryFriends($json, $extraInfo, $tempFriendsId);
     // Delete old caches of friend list
     $clearQ = $this->db->prepare('DELETE FROM temp_friends WHERE linkedin_id = :linkedin_id AND time < DATE_SUB(NOW(), INTERVAL 12 HOUR)');
     $clearQ->execute(array(':linkedin_id' => $this->userDetails['id']));
     // Output successful result
     $json['result'] = 'true';
     $json['time'] = Debug::getInstance()->getTimeElapsed();
     echo json_encode($json);
     exit;
 }
Пример #21
0
 function getlinkedindata($linkedlistdata)
 {
     $session = JFactory::getSession();
     $redsocialhelper = new redsocialhelper();
     $login = $redsocialhelper->getsettings();
     global $mainframe;
     $api_key = $login['linked_api_key'];
     // Linkedin Api key
     $secret_key = $login['linked_secret_key'];
     //Linkedin Secret key
     $access_tokens = $this->getLinkedinAccessToken();
     include JPATH_SITE . '/components/com_redsocialstream/helpers/linkedin/linkedin.php';
     require_once JPATH_SITE . '/components/com_redsocialstream/helpers/twitter/OAuth.php';
     $API_CONFIG = array('appKey' => $api_key, 'appSecret' => $secret_key, 'callbackUrl' => "");
     $linkedin = new LinkedIn($API_CONFIG);
     $access_token = $access_tokens[0]->linkedin_token;
     $access_secret = $access_tokens[0]->linkedin_secret;
     $token = array("oauth_token" => $access_token, "oauth_token_secret" => $access_secret);
     $linkedin->setTokenAccess($token);
     $query = '?type=SHAR&count=30';
     $response = $linkedin->updates($query);
     if ($response['success'] === TRUE) {
         $updates = new SimpleXMLElement($response['linkedin']);
         if ((int) $updates['total'] > 0) {
             $i = 0;
             foreach ($updates->update as $update) {
                 $person = $update->{'update-content'}->person;
                 $share = $update->{'update-content'}->person->{'current-share'};
                 $linkedinlist[$i]['data'] = $update;
                 $linkedinlist[$i]['created_time'] = date("Y-m-d", trim($share->timestamp));
                 $linkedinlist[$i]['type'] = 'linkedin';
                 $savedata[$i]['group_id'] = $linkedlistdata['group_id'];
                 $savedata[$i]['type'] = LINKEDIN;
                 $savedata[$i]['ext_profile_id'] = $person->{id};
                 $savedata[$i]['ext_post_id'] = $share->{id};
                 $savedata[$i]['ext_post_name'] = $person->{'first-name'} . ' ' . $person->{'last-name'};
                 if (isset($share->comment)) {
                     $savedata[$i]['message'] = addslashes($share->comment);
                 }
                 $savedata[$i]['title'] = '';
                 $savedata[$i]['source_link'] = $person->{'site-standard-profile-request'}->url;
                 $savedata[$i]['created_time'] = date("Y-m-d", trim($share->timestamp));
                 $savedata[$i]['duration'] = '';
                 $savedata[$i]['profile_id'] = $linkedlistdata['profile_id'];
                 $savedata[$i]['published'] = 1;
                 $savedata[$i]['thumb_uri'] = $person->{'picture-url'};
                 $i++;
             }
         }
     }
     if (isset($savedata)) {
         $this->savePost($savedata);
     }
     return $linkedinlist;
 }
 function index()
 {
     $API_CONFIG = $this->config->item('LINKEDIN_KEYS');
     define('DEMO_GROUP', '4010474');
     define('DEMO_GROUP_NAME', 'Simple LI Demo');
     define('PORT_HTTP', '80');
     define('PORT_HTTP_SSL', '443');
     $_REQUEST[LINKEDIN::_GET_TYPE] = isset($_REQUEST[LINKEDIN::_GET_TYPE]) ? $_REQUEST[LINKEDIN::_GET_TYPE] : '';
     switch ($_REQUEST[LINKEDIN::_GET_TYPE]) {
         case 'initiate':
             // check for the correct http protocol (i.e. is this script being served via http or https)
             if ($this->input->server('HTTPS') == 'on') {
                 $protocol = 'https';
             } else {
                 $protocol = 'http';
             }
             // set the callback url
             $API_CONFIG['callbackUrl'] = $protocol . '://' . $_SERVER['SERVER_NAME'] . ($_SERVER['SERVER_PORT'] != PORT_HTTP || $_SERVER['SERVER_PORT'] != PORT_HTTP_SSL ? ':' . $_SERVER['SERVER_PORT'] : '') . $_SERVER['PHP_SELF'] . '?' . LINKEDIN::_GET_TYPE . '=initiate&' . LINKEDIN::_GET_RESPONSE . '=1';
             $OBJ_linkedin = new LinkedIn($API_CONFIG);
             // check for response from LinkedIn
             $_GET[LINKEDIN::_GET_RESPONSE] = isset($_GET[LINKEDIN::_GET_RESPONSE]) ? $_GET[LINKEDIN::_GET_RESPONSE] : '';
             if (!$_GET[LINKEDIN::_GET_RESPONSE]) {
                 // LinkedIn hasn't sent us a response, the user is initiating the connection
                 // send a request for a LinkedIn access token
                 $response = $OBJ_linkedin->retrieveTokenRequest();
                 if ($response['success'] === TRUE) {
                     // store the request token
                     //$_SESSION['oauth']['linkedin']['request'] = $response['linkedin'];
                     $response['linkedin']['request'] = $response['linkedin'];
                     $this->session->set_userdata($response['linkedin']);
                     // redirect the user to the LinkedIn authentication/authorisation page to initiate validation.
                     header('Location: ' . LINKEDIN::_URL_AUTH . $response['linkedin']['oauth_token']);
                 } else {
                     // bad token request
                     echo "Request token retrieval failed:<br /><br />RESPONSE:<br /><br /><pre>" . print_r($response, TRUE) . "</pre><br /><br />LINKEDIN OBJ:<br /><br /><pre>" . print_r($OBJ_linkedin, TRUE) . "</pre>";
                 }
             } else {
                 $sess = $this->session->all_userdata();
                 // LinkedIn has sent a response, user has granted permission, take the temp access token, the user's secret and the verifier to request the user's real secret key
                 $response = $OBJ_linkedin->retrieveTokenAccess($sess['request']['oauth_token'], $sess['request']['oauth_token_secret'], $_GET['oauth_verifier']);
                 //$response = $OBJ_linkedin->retrieveTokenAccess($_SESSION['oauth']['linkedin']['request']['oauth_token'], $_SESSION['oauth']['linkedin']['request']['oauth_token_secret'], $_GET['oauth_verifier']);
                 if ($response['success'] === TRUE) {
                     // the request went through without an error, gather user's 'access' tokens
                     //$sess['access'] = $response['linkedin'];
                     $this->session->set_userdata('access', $response['linkedin']);
                     $this->session->set_userdata('authorized', TRUE);
                     // set the user as authorized for future quick reference
                     //save the shit to the db
                     $OBJ_linkedin = new LinkedIn($API_CONFIG);
                     $OBJ_linkedin->setTokenAccess($this->session->userdata('access'));
                     $OBJ_linkedin->setResponseFormat(LINKEDIN::_RESPONSE_JSON);
                     $userResponse = $OBJ_linkedin->profile('~:(id,first-name,last-name,picture-url,email-address)');
                     if ($userResponse['success'] === TRUE) {
                         $userData = json_decode($userResponse['linkedin'], true);
                         $this->load->model('user');
                         $this->load->model('billing');
                         if (!$this->user->exist($userData['id'])) {
                             $userId = $this->user->create($userData);
                             $userId = $this->billing->create(FALSE, $userId);
                             $this->session->set_userdata('user_id', $userId);
                         } else {
                             $user = $this->user->get_by_id($userData['id']);
                             $this->session->set_userdata('user_id', $user[0]->id);
                         }
                     }
                     redirect('/builder/get_resume_data', 'refresh');
                     // redirect the user back to the demo page
                     //header('Location: ' . $_SERVER['PHP_SELF']);
                 } else {
                     echo "Access token retrieval failed:<br /><br />RESPONSE:<br /><br /><pre>" . print_r($response, TRUE) . "</pre><br /><br />LINKEDIN OBJ:<br /><br /><pre>" . print_r($OBJ_linkedin, TRUE) . "</pre>";
                 }
             }
             break;
         case 'revoke':
             // check the session
             /*
             if(!$this->oauth_session_exists()) {
               throw new LinkedInException('This script requires session support, which doesn\'t appear to be working correctly.');
             }
             */
             $OBJ_linkedin = new LinkedIn($API_CONFIG);
             $OBJ_linkedin->setTokenAccess($this->session->userdata('access'));
             $response = $OBJ_linkedin->revoke();
             if ($response['success'] === TRUE) {
                 // revocation successful, clear session
                 $this->session->sess_destroy();
                 redirect('/marketing', 'refresh');
             } else {
                 // revocation failed
                 echo "Error revoking user's token:<br /><br />RESPONSE:<br /><br /><pre>" . print_r($response, TRUE) . "</pre><br /><br />LINKEDIN OBJ:<br /><br /><pre>" . print_r($OBJ_linkedin, TRUE) . "</pre>";
             }
             break;
         default:
     }
     $isLoggedIn = $this->session->userdata('authorized') ? $this->session->userdata('authorized') : FALSE;
     if ($isLoggedIn) {
         redirect('/builder/get_resume_data', 'refresh');
     }
     $this->load->model('resume');
     $resumeData = $this->resume->get_by_id(1);
     $resumeJsonData = json_encode($resumeData);
     $viewData = array('isLoggedIn' => $isLoggedIn, 'json_data' => $resumeJsonData);
     $this->load->view('marketing/home', $viewData);
 }
Пример #23
0
  </head>

  <body>
    <div class="topbar">
      <div class="fill">
        <div class="container">
          <a class="brand" href="#">LinkedIn Assestment - Falcon Social</a>
        </div>
      </div>
    </div>
    <div class="container">
          <?php 
            if (checkSession() === true) {
                // Bruger er allerede tilsluttet
                $SimpleLI = new LinkedIn($API_CONFIG);
                $SimpleLI->setTokenAccess($_SESSION['oauth']['linkedin']['access']);
                ?>
            
            <?php 
                $response = $SimpleLI->profile('~:(id,first-name,last-name,headline,industry,summary,location,picture-url,positions,educations,recommendations-received,connections)');
                if ($response['success'] === TRUE) {
                    $response['linkedin'] = new SimpleXMLElement($response['linkedin']);
                    $li_profile = $response['linkedin'];
                    ?>
          <div class="well">
            <img src="<?php 
                    echo $li_profile->{'picture-url'};
                    ?>
" style="float: left; padding-right: 10px;">
            <h1><?php 
                    echo $li_profile->{'first-name'} . ' ' . $li_profile->{'last-name'};
Пример #24
0
 public function getLinkedinData($linkedinProfiles)
 {
     $mainframe = JFactory::getApplication();
     $params = $mainframe->getparams();
     $limit = $params->get('limit');
     $linkedinDataList = array();
     if (count($linkedinProfiles) > 0) {
         $accessLinkedin = RedSocialStreamHelper::getLinkinAccessToken();
         include_once JPATH_COMPONENT . '/helpers/twitter/statuses.php';
         $twitterStatuses = new TwitterStatuses();
         foreach ($linkedinProfiles as $twitterProfile) {
             if (isset($accessLinkedin->access_token) && !empty($accessLinkedin->access_token)) {
                 $tweetList = $twitterStatuses->getUserTimeline($twitterProfile['title'], $accessLinkedin->access_token, $limit);
                 for ($i = 0; $i < count($tweetList); $i++) {
                     $tweet = $tweetList[$i];
                     $linkedinDataList[$twitterProfile['id']]['data'] = $tweet;
                     $linkedinDataList[$twitterProfile['id']]['profile_id'] = $twitterProfile['id'];
                     $linkedinDataList[$twitterProfile['id']]['title'] = '';
                     $linkedinDataList[$twitterProfile['id']]['type'] = TWITTER;
                     $linkedinDataList[$twitterProfile['id']]['group_id'] = $twitterProfile['group_id'];
                     $linkedinDataList[$twitterProfile['id']]['source_link'] = "https://twitter.com/" . $tweet->user->screen_name . "/status" . $tweet->id_str;
                     $linkedinDataList[$twitterProfile['id']]['thumb_uri'] = $tweet->user->profile_image_url;
                     if (isset($tweet->text)) {
                         $linkedinDataList[$twitterProfile['id']]['message'] = addslashes($tweet->text);
                     }
                     $linkedinDataList[$twitterProfile['id']]['ext_profile_id'] = $tweet->user->id;
                     $linkedinDataList[$twitterProfile['id']]['ext_post_id'] = $tweet->id_str;
                     $linkedinDataList[$twitterProfile['id']]['ext_post_name'] = $tweet->user->screen_name;
                     $linkedinDataList[$twitterProfile['id']]['duration'] = '';
                     $linkedinDataList[$twitterProfile['id']]['created_time'] = date("Y-m-d H:i:s", strtotime($tweet->created_at));
                     $linkedinDataList[$twitterProfile['id']]['published'] = 1;
                 }
             }
         }
     }
     return $linkedinDataList;
     $api_key = $login['linked_api_key'];
     // Linkedin Api key
     $secret_key = $login['linked_secret_key'];
     //Linkedin Secret key
     $access_tokens = $this->getLinkedinAccessToken();
     include JPATH_SITE . '/components/com_redsocialstream/helpers/linkedin/linkedin.php';
     require_once JPATH_SITE . '/components/com_redsocialstream/helpers/twitter/OAuth.php';
     $API_CONFIG = array('appKey' => $api_key, 'appSecret' => $secret_key, 'callbackUrl' => "");
     $linkedin = new LinkedIn($API_CONFIG);
     $access_token = $access_tokens[0]->linkedin_token;
     $access_secret = $access_tokens[0]->linkedin_secret;
     $token = array("oauth_token" => $access_token, "oauth_token_secret" => $access_secret);
     $linkedin->setTokenAccess($token);
     $query = '?type=SHAR&count=30';
     $response = $linkedin->updates($query);
     if ($response['success'] === TRUE) {
         $updates = new SimpleXMLElement($response['linkedin']);
         if ((int) $updates['total'] > 0) {
             $i = 0;
             foreach ($updates->update as $update) {
                 $person = $update->{'update-content'}->person;
                 $share = $update->{'update-content'}->person->{'current-share'};
                 $linkedinlist[$i]['data'] = $update;
                 $linkedinlist[$i]['created_time'] = date("Y-m-d", trim($share->timestamp));
                 $linkedinlist[$i]['type'] = 'linkedin';
                 $savedata[$i]['group_id'] = $linkedlistdata['group_id'];
                 $savedata[$i]['type'] = LINKEDIN;
                 $savedata[$i]['ext_profile_id'] = $person->{id};
                 $savedata[$i]['ext_post_id'] = $share->{id};
                 $savedata[$i]['ext_post_name'] = $person->{'first-name'} . ' ' . $person->{'last-name'};
                 if (isset($share->comment)) {
                     $savedata[$i]['message'] = addslashes($share->comment);
                 }
                 $savedata[$i]['title'] = '';
                 $savedata[$i]['source_link'] = $person->{'site-standard-profile-request'}->url;
                 $savedata[$i]['created_time'] = date("Y-m-d", trim($share->timestamp));
                 $savedata[$i]['duration'] = '';
                 $savedata[$i]['profile_id'] = $linkedlistdata['profile_id'];
                 $savedata[$i]['published'] = 1;
                 $savedata[$i]['thumb_uri'] = $person->{'picture-url'};
                 $i++;
             }
         }
     }
     if (isset($savedata)) {
         $this->savePost($savedata);
     }
     return $linkedinlist;
 }
Пример #25
0
 public function publishToLinkedIn()
 {
     if (empty($this->userDetails['linkedin_access_token'])) {
         return false;
     }
     // Create LinkedIn object
     $linkedInApiConfig = array('appKey' => LI_API_KEY, 'appSecret' => LI_SECRET, 'callbackUrl' => '');
     $linkedIn = new LinkedIn($linkedInApiConfig);
     try {
         $linkedIn->setTokenAccess(unserialize($this->userDetails['linkedin_access_token']));
     } catch (Error $e) {
         Debug::l('Error. Could not set LinkedIn access token. ' . $e);
         return false;
     }
     $subject = str_replace('INTRODUCER_NAME', $this->userName, Content::c()->introduce->linkedin->title);
     $message = str_replace('INTRODUCEE_NAME', $this->introducee->getName(), str_replace('INTRODUCER_NAME', $this->userName, str_replace('LINK', $this->introductionUrl, Content::c()->introduce->linkedin->message)));
     $response = $linkedIn->message(array($this->userDetails['linkedin_id']), $subject, $message);
     if ($response['success'] === TRUE) {
         return true;
     } else {
         return false;
     }
 }
Пример #26
0
 /**
  * this function will used to send string post
  * @param string $appKey
  * @param string $appSecret
  * @param string $user_oauth_token
  * @param string $user_oauth_token_secret
  * @param string $post
  * @return response done on success or faild on faild
  */
 static function linkedInPostUpdate($appKey, $appSecret, $user_oauth_token, $user_oauth_token_secret, $post)
 {
     //linkedIn config parameters
     $config = array('appKey' => $appKey, 'appSecret' => $appSecret, 'callbackUrl' => '');
     //create new linkedIn oauth object
     $oauth = new \LinkedIn($config);
     $linkedIn_oauth = array('oauth_token' => $user_oauth_token, 'oauth_token_secret' => $user_oauth_token_secret);
     //set user token
     $oauth->setTokenAccess($linkedIn_oauth);
     $response = $oauth->updateNetwork($post);
     if ($response['success'] === TRUE) {
         // status has been updated
         return new Response('done');
     } else {
         // an error occured
         //            echo "Error posting network update:<br /><br />RESPONSE:<br /><br /><pre>" . print_r($response, TRUE) . "</pre><br /><br />LINKEDIN OBJ:<br /><br /><pre>" . print_r($OBJ_linkedin, TRUE) . "</pre>";
         return new Response('faild');
     }
 }
Пример #27
0
require_once "class/frontend.class.php";
$front = Frontend::getInstance();
include_once "db_connect.php";
include_once "autoload.php";
require_once 'oauth/linkedin.class.php';
if (!$front->isUserLoggedIn()) {
    $front->getUser()->askUserToAuthenticate();
}
$messages = array();
$redirect = false;
if (isset($_POST['action'])) {
    if ($_POST['action'] == "revoke") {
        $API_CONFIG = array('appKey' => LINKEDIN_API_KEY_PUBLIC, 'appSecret' => LINKEDIN_API_KEY_PRIVATE, 'callbackUrl' => NULL);
        $OBJ_linkedin = new LinkedIn($API_CONFIG);
        $OBJ_linkedin->setTokenAccess(array('oauth_token' => $front->getUser()->getAccess_token(), 'oauth_token_secret' => $front->getUser()->getAccess_token_secret()));
        $OBJ_linkedin->revoke();
        $front->getUser()->deleteTokens();
    }
}
if (isset($_POST['nickname'])) {
    $nickname = trim($_POST['nickname']);
    $updateNickname = false;
    $updatePassword = false;
    if ($nickname != $_SESSION['nickname']) {
        if (strpos($nickname, ' ') !== false) {
            $front->getError()->setError("Your nickname cannot contain any spaces. Please try again.");
        } elseif (strlen($nickname) > MAX_NICKNAME_CHARS) {
            $front->getError()->setError("Your nickname must be less than " . MAX_NICKNAME_CHARS . " long.");
        } elseif (preg_match("/<(.|\n)*?>/", $nickname)) {
            $front->getError()->setError("Your nickname contained illegal characters. Please try again.");