Exemplo n.º 1
0
 /**
  * Create access token for linkedin
  *
  * @access public
  * @return void
  */
 public function add_new_account($profile_id)
 {
     if ($this->_ci->session->userdata('linkedin_token_secret')) {
         $verifier = $_GET['oauth_verifier'];
         $oauth_token = $_GET['oauth_token'];
         $response = $this->_linkedin->retrieveTokenAccess($oauth_token, $this->_ci->session->userdata('linkedin_token_secret'), $verifier);
         $this->_ci->session->unset_userdata('linkedin_token_secret');
         $token = serialize($response['linkedin']);
         $access_token = new Access_token();
         $profile = Linkedin::xmlToArray($this->_linkedin->profile('~:(id,formatted-name,picture-url)')['linkedin'])['person']['children'];
         $tokens = array('token' => null, 'secret_token' => null, 'data' => $token, 'name' => $profile['formatted-name']['content'], 'username' => $profile['id']['content'], 'image' => $profile['picture-url']['content']);
         $token = $access_token->add_token($tokens, 'linkedin', $this->_user_id);
         $social_group = new Social_group($profile_id);
         $social_group->save(array('access_token' => $token));
     }
 }
Exemplo n.º 2
0
 public function changeActive()
 {
     if ($this->template->is_ajax()) {
         $post = $this->input->post();
         $social_groups = $this->c_user->social_group->get();
         $result = array('success' => true);
         foreach ($social_groups as $social_group) {
             $social_group->is_active = false;
             $social_group->save();
         }
         $social_group = new Social_group($post['id']);
         if ($social_group->exists()) {
             $social_group->is_active = true;
             if ($social_group->save()) {
                 $result['message'] = lang('profile_updated_successfully');
             } else {
                 $result['success'] = false;
                 $result['message'] = lang('profile_saving_error');
             }
         } else {
             $result['success'] = false;
             $result['message'] = lang('profile_saving_error');
         }
         echo json_encode($result);
     }
 }
Exemplo n.º 3
0
 /**
  * Used to get facebook access token
  * Use Facebook SDK API library
  * After - return redirect url
  *
  * @access public
  *
  * @param $profile_id
  *
  * @return string
  */
 public function add_new_account($profile_id)
 {
     $login_url = $this->_facebook->getLoginUrl(array('scope' => 'read_stream, manage_pages, user_videos, user_likes, publish_actions, publish_pages'));
     if ($this->_facebook->getUser()) {
         $profile = $this->get_profile();
         $picture = $this->get_profile_picture($profile['id']);
         $access_token = new Access_token();
         $tokens = array('token' => $this->_facebook->getAccessToken(), 'secret_token' => null, 'image' => $picture, 'name' => $profile['name'], 'username' => $profile['id']);
         $token = $access_token->add_token($tokens, 'facebook', $this->_user_id);
         $social_group = new Social_group($profile_id);
         $social_group->save(array('access_token' => $token));
         $redirect_url = site_url('settings/socialmedia/edit_account/' . $token->id);
     } else {
         $redirect_url = $login_url;
     }
     return $redirect_url;
 }
Exemplo n.º 4
0
 /**
  * Used to get Instagram access token
  * After - return redirect url
  *
  * @access public
  *
  * @param $profile_id
  *
  * @return string
  * @throws OAuthException
  */
 public function add_new_account($profile_id)
 {
     $auth_instagram = $this->authorize($_GET['code']);
     if (isset($auth_instagram->access_token)) {
         $access_token = new Access_token();
         $tokens = array('token' => $auth_instagram->access_token, 'secret_token' => null, 'instance_id' => $auth_instagram->user->id, 'image' => $auth_instagram->user->profile_picture, 'name' => $auth_instagram->user->full_name, 'username' => $auth_instagram->user->username);
         $token = $access_token->add_token($tokens, 'instagram', $this->_user_id);
         $social_group = new Social_group($profile_id);
         $social_group->save(array('access_token' => $token));
         $redirect_url = site_url('settings/socialmedia');
     } else {
         throw new OAuthException(lang('not_connected_error', ['Instagram']));
     }
     return $redirect_url;
 }
Exemplo n.º 5
0
 /**
  * Used to add new record to Access Tokens Table
  *
  * @access public
  *
  * @param $oauth_verifier - $_REQUEST['code'] from controller
  * @param $profile_id
  *
  * @return string
  * @throws Exception
  */
 public function add_new_account($oauth_verifier, $profile_id)
 {
     $oauth_token = $this->_ci->session->userdata('oauth_token');
     $oauth_token_secret = $this->_ci->session->userdata('oauth_token_secret');
     $connection = new TwitterOAuth($this->_config['consumer_key'], $this->_config['consumer_secret'], $oauth_token, $oauth_token_secret);
     $token_credentials = $connection->getAccessToken($oauth_verifier);
     $tokens = array('token' => $token_credentials['oauth_token'], 'secret_token' => $token_credentials['oauth_token_secret']);
     try {
         if (empty($this->_user_id)) {
             throw new Exception("There in no active user to connect to twitter.");
         }
         $tokens['username'] = $token_credentials['screen_name'];
         $socialFullInfo = $this->get_user_full_info($tokens['username']);
         if (empty($socialFullInfo->name)) {
             throw new Exception("Invalid twitter's user data. Please try to reconnect.");
         }
         $tokens['name'] = $socialFullInfo->name;
         $tokens['image'] = $socialFullInfo->profile_image_url;
         $access_token = new Access_token();
         $token = $access_token->add_token($tokens, 'twitter', $this->_user_id);
         if (!$token->exists()) {
             throw new Exception("Cant save twitter access data. Please try to reconnect.");
         }
         $social_group = new Social_group($profile_id);
         $social_group->save(array('access_token' => $token));
     } catch (Exception $e) {
         throw $e;
     }
     $redirect_url = site_url('settings/socialmedia');
     return $redirect_url;
 }
Exemplo n.º 6
0
 /**
  * Used to add new record to Access Tokens Table
  *
  * @access public
  *
  * @param $profile_id
  *
  * @return string
  */
 public function add_new_account($profile_id)
 {
     if (isset($_GET['code'])) {
         require_once __DIR__ . '/../../../../vendor/google/apiclient/src/Google/Service/Plus.php';
         $plusService = new Google_Service_Plus($this->_google);
         $this->_google->authenticate($_GET['code']);
         $token = $this->_google->getAccessToken();
         $access_token = new Access_token();
         $profile = $plusService->people->get('me');
         $tokens = array('token' => null, 'secret_token' => null, 'data' => $token, 'name' => $profile['displayName'], 'image' => $profile['image']['url'], 'username' => $profile['id']);
         $mtype = $this->getMediaType();
         $token = $access_token->add_token($tokens, $mtype, $this->_user_id);
         $social_group = new Social_group($profile_id);
         $social_group->save(array('access_token' => $token));
         $redirect_url = site_url('settings/socialmedia');
         return $redirect_url;
     }
 }