Ejemplo n.º 1
0
 /**
  * Construct function
  * Sets the codeigniter instance variable and loads the lang file
  * @param integer|null $user_id
  * @param array|null $token
  */
 function __construct($user_id, $token)
 {
     $this->_ci =& get_instance();
     $this->_ci->config->load('social_credentials');
     $this->_config = Api_key::build_config('facebook', $this->_ci->config->item('facebook'));
     $this->_user_id = $user_id;
     $this->_facebook = new Facebook($this->_config);
     $this->_token = $token;
     if (isset($this->_token['id'])) {
         $this->_facebook->destroySession();
         $this->_facebook->setAccessToken($this->_token['token1']);
         $page = Facebook_Fanpage::inst()->get_selected_page($this->_user_id, $this->_token['id']);
         if ($page->id) {
             $this->_fanpage_id = $page->fanpage_id;
             $this->_profile_id = $page->profile_id;
         }
     }
 }
Ejemplo n.º 2
0
 public function index()
 {
     $this->form_validation->set_rules('first_name', 'First Name', 'required|xss_clean');
     $this->form_validation->set_rules('last_name', 'Last Name', 'required|xss_clean');
     if (isset($_POST) && !empty($_POST)) {
         $config = $this->config->config;
         if (!$config['change_settings']) {
             $this->addFlash('<span class="err_icon"></span>Demo version settings can\'t be changed');
         } else {
             $data = array('first_name' => $this->input->post('first_name'), 'last_name' => $this->input->post('last_name'));
             if ($this->input->post('old_password')) {
                 $old_password = $this->input->post('old_password');
                 $ion_model = new Ion_auth_model();
                 $valid_old = $ion_model->hash_password_db($this->c_user->id, $old_password);
                 $password_min = $this->config->item('min_password_length', 'ion_auth');
                 $password_max = $this->config->item('max_password_length', 'ion_auth');
                 $this->form_validation->set_rules('new_password', 'New Password', 'required|min_length[' . $password_min . ']|max_length[' . $password_max . ']|matches[confirm_password]');
                 $this->form_validation->set_rules('confirm_password', 'Confirm New Password', 'required');
                 if ($valid_old) {
                     $data['password'] = $this->input->post('new_password');
                 } else {
                     $this->form_validation->create_error('Invalid Old Password');
                 }
             }
             if ($this->form_validation->run() === TRUE) {
                 $update = $this->ion_auth->update($this->c_user->id, $data);
                 if ($update) {
                     $this->addFlash('Personal Settings Updated', 'success');
                     redirect('settings/personal');
                 } else {
                     $this->addFlash($this->ion_auth->errors());
                 }
             } else {
                 if (validation_errors()) {
                     $this->addFlash(validation_errors());
                 }
             }
         }
     }
     $this->template->set('email', $this->c_user->email);
     $this->template->set('first_name', $this->form_validation->set_value('first_name', $this->c_user->first_name));
     $this->template->set('last_name', $this->form_validation->set_value('last_name', $this->c_user->last_name));
     /*directories*/
     $directories = DM_Directory::get_all_sorted();
     $raw_dir_user = Directory_User::get_by_user($this->c_user->id);
     $user_directories = $raw_dir_user->to_dir_array();
     $is_notified = $raw_dir_user->isNotified();
     CssJs::getInst()->c_js();
     JsSettings::instance()->add(array('autocomplete_directories_url' => site_url('settings/directories/google_autocomplete')));
     $parsers = array();
     foreach ($directories as $_dir) {
         try {
             $parsers[$_dir->id] = Directory_Parser::factory($_dir->type);
         } catch (Exception $e) {
             $parsers[$_dir->id] = new stdClass();
         }
     }
     $receive_emails = $this->getAAC()->isGrantedPlan('email_notifications');
     $this->template->set('is_notified', $is_notified);
     $this->template->set('parsers', $parsers);
     $this->template->set('directories', $directories);
     $this->template->set('user_directories', $user_directories);
     $this->template->set('receive_emails', $receive_emails);
     /*end directories*/
     /*google keywords*/
     $this->load->config('site_config', TRUE);
     $keywords_config = $this->config->item('keywords', 'site_config');
     $keywords_count = isset($keywords_config['count']) && $keywords_config['count'] ? $keywords_config['count'] : 10;
     // get user additional info (address)
     $user_additional = User_additional::inst()->get_by_user_id($this->c_user->id);
     // get available keywords
     $keywords = Keyword::inst()->get_user_keywords($this->c_user->id);
     // escape keywords names and website name
     $address_name = isset($address_name) ? HTML::chars($address_name) : HTML::chars($user_additional->address);
     $keywords_names = isset($keywords_names) ? HTML::chars_arr($keywords_names) : HTML::chars_arr(array_values($keywords->all_to_single_array('keyword')));
     JsSettings::instance()->add(array('autocomplete_keywords_url' => site_url('settings/keywords/google_autocomplete')));
     CssJs::getInst()->c_js();
     $this->template->set('address_id', $user_additional->address_id);
     $this->template->set('address_name', $address_name);
     $this->template->set('keywords_names', $keywords_names);
     $this->template->set('keywords_count', $keywords_count);
     /*end google keywords*/
     /*socialmedia settings*/
     $this->load->library('Socializer/socializer');
     $this->load->config('timezones');
     CssJs::getInst()->c_js('settings/socialmedia', 'index')->c_js('settings/socialmedia', 'twitter');
     $tokens = new Access_token();
     $linkedin_data = $tokens->get_linkedin_token($this->c_user->id);
     $this->template->set('linkedin_token', $linkedin_data->id);
     $facebook_data = $tokens->get_facebook_token($this->c_user->id);
     if ($facebook_data->id) {
         try {
             $facebook = Socializer::factory('Facebook', $this->c_user->id);
             $user_facebook_pages = $facebook->get_user_pages();
             $this->template->set('fb_pages', $user_facebook_pages);
             $selected_fanpage = Facebook_Fanpage::inst()->get_selected_page($this->c_user->id);
             $this->template->set('selected_fanpage_id', $selected_fanpage->fanpage_id);
         } catch (Exception $e) {
             if ($e->getCode() !== Socializer::FBERRCODE) {
                 $this->addFlash($e->getMessage());
             }
         }
     }
     $this->template->set('facebook_token', $facebook_data->id);
     $twitter_data = $tokens->get_twitter_token($this->c_user->id);
     $this->template->set('twitter_token', $twitter_data->id);
     $youtube_data = $tokens->get_youtube_token($this->c_user->id);
     $this->template->set('youtube_token', $youtube_data->id);
     $google_data = $tokens->get_google_token($this->c_user->id);
     $this->template->set('google_token', $google_data->id);
     $instagram_data = $tokens->get_instagram_token($this->c_user->id);
     $this->template->set('instagram_token', $instagram_data->id);
     $timezones = $this->config->item('timezones');
     $this->template->set('timezones', $timezones);
     $current_timezone = User_timezone::get_user_timezone($this->c_user->id, TRUE);
     $this->template->set('current_timezone', $current_timezone);
     /*end socialmedia settings*/
     /*mention keywords*/
     $this->load->config('site_config', TRUE);
     $keywords_config = $this->config->item('mention_keywords', 'site_config');
     $config_count = isset($keywords_config['count']) && $keywords_config['count'] ? $keywords_config['count'] : 10;
     $availableKeywordsCount = $this->getAAC()->getPlanFeatureValue('brand_reputation_monitoring');
     if ($availableKeywordsCount) {
         $config_count = $availableKeywordsCount;
     }
     $keywords = Mention_keyword::inst()->get_user_keywords($this->c_user->id);
     JsSettings::instance()->add(array('max_keywords' => $config_count));
     CssJs::getInst()->add_js(array('libs/handlebar.js', 'libs/handlebars_helpers.js'));
     $this->template->set('keywords', $keywords);
     $this->template->set('config_count', $config_count);
     /*end mention keywords*/
     /*analytics*/
     $analyticsData = array();
     if ($this->session->flashdata('ga_redirect_to_accounts')) {
         if (!$this->access_token->token1 or !$this->access_token->token2) {
             $analyticsData['error'] = 'Please, connect your Google Analytics account.';
         } else {
             JsSettings::instance()->add(array('analytics' => array('get_accounts_url' => site_url('settings/analytics/get_accounts'))));
             CssJs::getInst()->c_js();
             $analyticsData['account_info'] = $this->access_token->account_info();
         }
     } else {
         JsSettings::instance()->add(array('analytics' => array('client_id' => $this->analytics_settings['client_id'], 'redirect_uri' => $this->analytics_settings['redirect_uri'])));
         CssJs::getInst()->c_js();
         $analyticsData['access_token'] = $this->access_token;
         $analyticsData['account_info'] = $this->access_token->account_info();
     }
     $this->template->set('analyticsData', $analyticsData);
     /*end analytics*/
     CssJs::getInst()->add_js('controller/settings/index.js');
     $this->template->render();
 }
Ejemplo n.º 3
0
 public function delete($user_id = NULL)
 {
     $user = $this->prepare_user($user_id);
     if ($this->ion_auth->is_admin($user_id)) {
         $url = 'manage_admins';
     } elseif ($this->ion_auth->is_manager($user_id)) {
         $url = 'manage_accounts';
     } else {
         $url = 'admin_users';
     }
     if ($this->ion_auth->is_collaborator($user_id)) {
         $this->c_user->delete($user);
     }
     $user_deleted = $this->ion_auth->delete_user($user->id);
     if (!$user_deleted) {
         $this->addFlash(lang('delete_error', [$this->ion_auth->errors()]));
         redirect('admin/admin_users');
     }
     $sender = $this->get('core.mail.sender');
     $sender->sendUserDeleteMail(array('user' => $user));
     $access_token = new Access_token();
     $access_token->where('user_id', $user->id)->get()->delete_all();
     $directory_user = new Directory_User();
     $directory_user->where('user_id', $user->id)->get()->delete_all();
     $facebook_fanpage = new Facebook_Fanpage();
     $facebook_fanpage->where('user_id', $user->id)->get()->delete_all();
     $keyword = new Keyword();
     $keyword->where('user_id', $user->id)->get();
     foreach ($keyword as $k) {
         $keyword_rank = new Keyword_rank();
         $keyword_rank->where('keyword_id', $k->id)->get()->delete_all();
     }
     $keyword->delete_all();
     $media = new Media();
     $media->where('user_id', $user->id)->get()->delete_all();
     $post = new Post();
     $post->where('user_id', $user->id)->get();
     foreach ($post as $p) {
         $post_social = new Post_social();
         $post_social->where('post_id', $p->id)->get()->delete_all();
     }
     $post->delete_all();
     $review = new Review();
     $review->where('user_id', $user->id)->get()->delete_all();
     $reviews_notification = new Reviews_notification();
     $reviews_notification->where('user_id', $user->id)->get()->delete_all();
     $rss_feeds_users = new Rss_feeds_users();
     $rss_feeds_users->where('user_id', $user->id)->get()->delete_all();
     $social_post = new Social_post();
     $social_post->where('user_id', $user->id)->get()->delete_all();
     $social_value = new Social_value();
     $social_value->where('user_id', $user->id)->get()->delete_all();
     $user_additional = new User_additional();
     $user_additional->where('user_id', $user->id)->get()->delete_all();
     $user_feed = new User_feed();
     $user_feed->where('user_id', $user->id)->get()->delete_all();
     $user_timezone = new User_timezone();
     $user_timezone->where('user_id', $user->id)->get()->delete_all();
     $this->addFlash(lang('delete_success'), 'success');
     redirect('admin/' . $url);
 }
Ejemplo n.º 4
0
 /**
  * Check - is user have access to post into socials
  * Get Access Tokens for Facebook / Twitter from our database
  * Also need to check - is user select some Facebook fanpage
  *
  * @access public
  * @param $user_id
  * @return array
  */
 public function check_socials_access($user_id)
 {
     $instagram_token = self::getByTypeAndUserId('instagram', $user_id);
     $linkedin_token = self::getByTypeAndUserId('linkedin', $user_id);
     $twitter_token = self::getByTypeAndUserId('twitter', $user_id);
     $facebook_token = self::getByTypeAndUserId('facebook', $user_id);
     $youtube_token = self::getByTypeAndUserId('youtube', $user_id);
     $fan_page = Facebook_Fanpage::inst()->get_selected_page($user_id, $this->id);
     return array('is_authorized_in_facebook' => $facebook_token->exists(), 'is_authorized_in_twitter' => $twitter_token->exists(), 'is_have_fan_page' => $fan_page->exists(), 'is_authorized_in_linkedin' => $linkedin_token->exists(), 'is_authorized_in_youtube' => $youtube_token->exists(), 'is_authorized_in_instagram' => $instagram_token->exists());
 }
Ejemplo n.º 5
0
 /**
  * Used to save selected Facebook fanpage
  * Available after user connect to facebook (see 'facebook' method)
  *
  * @access public
  * @return void
  */
 public function save_facebook_preferences()
 {
     $post = $this->input->post();
     try {
         if (!(isset($post['fan_page_id']) && $post['fan_page_id'] != '0')) {
             throw new Exception(lang('fanpage_error'));
         }
         $this->load->library('Socializer/socializer');
         /* @var Socializer_Facebook $facebook */
         $facebook = Socializer::factory('Facebook', $this->c_user->id);
         $userdata = $facebook->get_profile();
         Facebook_Fanpage::inst()->save_selected_page($this->c_user->id, $post['fan_page_id'], $userdata['id']);
         $this->addFlash(lang('fanpage_save_success'), 'success');
     } catch (Exception $e) {
         $this->addFlash($e->getMessage());
     }
     redirect(site_url('settings/socialmedia/'));
 }