示例#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));
     }
 }
示例#2
0
 /**
  * Then user click on 'edit' in the schedule list - we need to load some of forms
  * Let's load form from created early scripts (create pages)
  *
  * @access   public
  *
  * @param $social_post
  *
  * @return string
  * @internal param $category_id
  */
 private function _get_edit_post_form($social_post)
 {
     $post = new Social_post($social_post->id);
     $isMedia = $post->isMediaPost();
     $this->load->helper('MY_url_helper');
     $this->load->helper('Image_designer_helper');
     $this->load->config('timezones');
     $block_data = Access_token::inst()->check_socials_access($this->c_user->id);
     $block_data['social_post'] = $social_post;
     $block_data['isMedia'] = $isMedia;
     $block_data['isSupportScheduledPosts'] = $this->isSupportScheduledPosts;
     $block_data['is_user_set_timezone'] = User_timezone::is_user_set_timezone($this->c_user->id);
     $socials = array('twitter' => 'twitter', 'facebook' => 'facebook', 'linkedin' => 'linkedin');
     foreach ($socials as $social) {
         if (!Social_group::hasSocialAccountByType($this->profile->id, $social)) {
             unset($socials[$social]);
         }
     }
     $block_data['socials'] = $socials;
     $block_data['imageDesignerImages'] = Image_designer::getImages();
     $html = $this->template->block('_edit_form', 'social/create/blocks/_post_update', $block_data);
     return $html;
 }
示例#3
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);
     }
 }
示例#4
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;
 }
示例#5
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;
 }
示例#6
0
 /**
  * @param integer $group_id
  * @param array   $exclude types
  * @param bool    $has_twitter_marketing_tools
  *
  * @return array
  */
 public static function getGroupTokensArray($group_id, $exclude = array(), $has_twitter_marketing_tools = false)
 {
     $tokens = array();
     foreach (self::$types as $type) {
         if (in_array($type, $exclude)) {
             continue;
         }
         $has_configs = count(Available_config::getByTypeAsArray($type)) || $type == 'facebook' ? true : false;
         if ($has_configs && $type == 'twitter') {
             $has_configs = $has_twitter_marketing_tools;
         }
         $tokens_array = Social_group::getAccountByTypeAsArray($group_id, $type);
         foreach ($tokens_array as &$token) {
             $token['has_configs'] = $has_configs;
         }
         if (!empty($tokens_array)) {
             $tokens[$type] = $tokens_array;
         } else {
             $tokens[$type] = array();
         }
     }
     return $tokens;
 }
示例#7
0
 public function postGoogle()
 {
     $this->load->library('Socializer/socializer');
     $google = Socializer::factory('Google', $this->c_user->id, Social_group::getAccountByTypeAsArray($this->profile->id, 'google')[0]);
     $google->post();
 }
示例#8
0
 private function _validate_video($feeds)
 {
     $errors = array();
     if (empty($feeds['image_name'])) {
         $errors['image_name'] = lang('video_error');
     }
     if (isset($feeds['title'])) {
         if (empty($feeds['title'])) {
             $errors['title'] = lang('video_title_error');
         }
     } else {
         $errors['title'] = lang('video_title_error');
     }
     $youtube_token = Access_token::inst()->get_youtube_token($feeds['user_id']);
     foreach ($feeds['post_to_groups'] as $group_id) {
         if (Social_group::hasSocialAccountByType($group_id, 'twitter') || Social_group::hasSocialAccountByType($group_id, 'linkedin')) {
             if (!$youtube_token->exists()) {
                 $errors['post_to_groups[]'] = lang('youtube_error');
                 break;
             }
         }
     }
     return $errors;
 }
示例#9
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;
 }
示例#10
0
 /**
  * Used to get access url from Google (Youtube and Google have same OAUTH system)
  * Use Socializer Library
  * After - redirect to access url
  *
  * @access public
  * @return void
  */
 public function google()
 {
     try {
         if (Social_group::hasSocialAccountByType($this->profile->id, 'google')) {
             $this->addFlash(lang('already_has_account_error', ['Google']), 'error');
             redirect('settings/socialmedia');
         }
         $this->load->library('Socializer/socializer');
         /* @var Socializer_Google $google_socializer */
         $google_socializer = Socializer::factory('Google', $this->c_user->id);
         $redirect_uri = $google_socializer->get_access_url();
         redirect($redirect_uri);
     } catch (Exception $e) {
         $this->addFlash($e->getMessage());
         redirect('settings/socialmedia');
     }
 }
示例#11
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;
     }
 }