示例#1
5
 function getData()
 {
     $session = JFactory::getSession();
     $post = JRequest::get('post');
     $redsocialhelper = new redsocialhelper();
     $login = $redsocialhelper->getsettings();
     if (!isset($post['generatetoken'])) {
         return JText::_('PLEASE_SELECT_SECTION');
     }
     switch ($post['generatetoken']) {
         case 'facebook':
             $fb_profile_id = $session->set('fb_profile_id', $post['fb_profile_id']);
             $app_id = $login['app_id'];
             $app_secret = $login['app_secret'];
             require_once JPATH_SITE . '/components/com_redsocialstream/helpers/facebook/facebook.php';
             $redirect_url = urlencode(JURI::base() . "index.php?option=com_redsocialstream&view=access_token");
             header("location: https://www.facebook.com/dialog/oauth?client_id=" . $login['app_id'] . "&redirect_uri=" . $redirect_url . "&scope=manage_pages,publish_stream&manage_pages=1&publish_stream=1");
             break;
         case 'linkedin':
             //Linkedin APi Key
             $api_key = $login['linked_api_key'];
             //Linkedin Secret Key
             $secret_key = $login['linked_secret_key'];
             $redirect_url = JURI::base() . "index.php?option=com_redsocialstream&view=access_token";
             $linkedin_profile_id = $session->set('linkedin_profile_id', $post['linkedin_profile_id']);
             $API_CONFIG = array('appKey' => $api_key, 'appSecret' => $secret_key, 'callbackUrl' => $redirect_url);
             $linkedin = new LinkedIn($API_CONFIG);
             $response = $linkedin->retrieveTokenRequest();
             if ($response['success'] === TRUE) {
                 $session->set('oauthReqToken', $response['linkedin']);
                 // redirect the user to the LinkedIn authentication/authorisation page to initiate validation.
                 header('Location: ' . LINKEDIN::_URL_AUTH . $response['linkedin']['oauth_token']);
                 exit;
             }
             break;
     }
 }
示例#2
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);
 }
示例#3
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;
 }