Beispiel #1
0
 public function __construct()
 {
     parent::__construct($this->website_part);
     $this->lang->load('rank', $this->language);
     JsSettings::instance()->add(['i18n' => $this->lang->load('rank', $this->language)]);
     $this->all_periods = array('0' => strtotime('today'), '1' => strtotime('-1 month 1 day'), '2' => strtotime('-3 months 1 day'), '3' => strtotime('-6 months 1 day'), '4' => strtotime('-1 year 1 day'));
     $this->all_periods_names = array('0' => lang('period_all_time'), '1' => lang('period_1_month'), '2' => lang('period_3_months'), '3' => lang('period_6_months'), '4' => lang('period_1_year'));
     $has_address = User_additional::inst()->get_by_user_and_profile($this->c_user->id, $this->profile->id)->address_id;
     if (!$has_address) {
         $this->configured['no_address'] = TRUE;
     }
     $has_keywords = Keyword::inst()->has_keywords($this->c_user->id, $this->profile->id);
     if (!$has_keywords) {
         $this->configured['no_keywords'] = TRUE;
     }
     $first_rank_date = Keyword::inst()->first_rank_date($this->c_user->id, $this->profile->id);
     $first_rank_time = strtotime($first_rank_date);
     $has_results = (bool) $first_rank_date;
     if (!$has_results) {
         $this->configured['no_results'] = TRUE;
     }
     // set available periods depending on first rank update
     foreach ($this->all_periods as $key => $value) {
         if ($value >= $first_rank_time) {
             $this->available_periods[$key] = $value;
             $this->available_periods_names[$key] = $this->all_periods_names[$key];
         }
     }
     $this->load->library('gls');
 }
Beispiel #2
0
 public function social($social = 'facebook')
 {
     $this->load->helper('clicable_links');
     //$social = ($social === 'twitter') ? $social : 'facebook';
     $has_access = Access_token::inst()->get_by_type($social, $this->c_user->id)->exists();
     $this->template->set('has_access', $has_access);
     if ($has_access) {
         $page = max(1, intval(Arr::get($_GET, 'page', 1)));
         $per_page = 10;
         $keyword = Arr::get($_GET, 'keyword', 0);
         $keyword_query_str = $keyword ? '&keyword=' . $keyword : '';
         $keywords = Mention_keyword::inst()->dropdown($this->c_user->id);
         $use_dates = Arr::get($_GET, 'from') || Arr::get($_GET, 'to');
         $from = date('M j, Y', strtotime(Arr::get($_GET, 'from', 'yesterday')));
         $to = date('M j, Y', strtotime(Arr::get($_GET, 'to', 'today')));
         list($from, $to) = $this->getDatesFromRequest();
         $formatedFrom = $from->format($this->dateFormat);
         $formatedTo = $to->format($this->dateFormat);
         $dates = array('from' => $formatedFrom, 'to' => $formatedTo);
         $dates_query_str = '&from=' . urlencode($formatedFrom) . '&to=' . urlencode($formatedTo);
         $this->template->set('dates', $dates);
         $this->template->set('use_dates', $use_dates);
         $mentions = Mention::inst()->by_social($this->c_user->id, $social);
         if ($keyword) {
             $mentions->where('mention_keyword_id', $keyword);
         }
         $mentions->where('created_at >=', $from->getTimestamp())->where('created_at <=', $to->getTimestamp());
         $mentions->get_paged($page, $per_page);
         $keywords_for_highlight = Mention_keyword::inst()->get_for_highlight($this->c_user->id, intval($keyword));
         JsSettings::instance()->add(array('non_ajax_pagination' => true, 'keywords' => $keywords_for_highlight, 'keyword_query_str' => $keyword_query_str, 'keyword_query_id' => $keyword, 'dates_query_str' => $dates_query_str, 'dates' => $dates));
         CssJs::getInst()->c_js('social/activity', $social)->c_js();
         if ($social === 'facebook') {
             $profile_photo = User_additional::inst()->get_value($this->c_user->id, 'facebook_profile_photo');
             if (is_null($profile_photo)) {
                 try {
                     $this->load->library('Socializer/socializer');
                     $facebook = Socializer::factory('Facebook', $this->c_user->id);
                     $profile_picture = $facebook->get_profile_picture();
                     if (isset($profile_picture['picture']['data']['url'])) {
                         $profile_photo = $profile_picture['picture']['data']['url'];
                     }
                     if ($profile_photo) {
                         User_additional::inst()->set_value($this->c_user->id, 'facebook_profile_photo', $profile_photo);
                     }
                 } catch (Exception $e) {
                     $this->template->set('socializer_error', $e->getMessage());
                 }
             }
             $this->template->set('profile_photo', $profile_photo);
         }
         $this->template->set('keyword', $keyword);
         $this->template->set('keyword_query_str', $keyword_query_str);
         $this->template->set('keywords', $keywords);
         $this->template->set('mentions', $mentions);
     }
     $this->template->set('social', $social);
     $this->template->render();
 }
 /**
  * Grab results for single keyword
  * 
  * @param $keyword_array (array) - keyword model arrayed
  * @throws Exception
  */
 public function grabber($keyword_array)
 {
     try {
         $keyword_id = isset($keyword_array['id']) ? $keyword_array['id'] : NULL;
         $keyword = new Keyword($keyword_id);
         if (!$keyword->exists()) {
             throw new Exception('kwid: ' . $keyword_id . ' doesn\'t exist.');
         }
         if ($keyword->is_deleted) {
             throw new Exception('kwid: ' . $keyword->id . ' is set for deletion.');
         }
         $user_additional = User_additional::inst()->get_by_user_and_profile($keyword->user_id, $keyword->profile_id);
         if (!$user_additional->exists()) {
             throw new Exception('No user additional model for user: '******' ; kwid: ' . $keyword->id);
         }
         if (!$user_additional->address_id) {
             throw new Exception('No address id for user: '******'; kwid: ' . $keyword->id);
         }
         $this->load->config('site_config', TRUE);
         // $google_app_config = $this->config->item('google_app', 'site_config');
         $google_app_config = Api_key::build_config('google', $this->config->item('google_app', 'site_config'));
         $this->load->library('gls');
         $gls = new Gls();
         // important
         $gls->set(array('key' => $google_app_config['developer_key']));
         $gls->request($keyword->keyword);
         if ($gls->success()) {
             $rank = $gls->location_rank($user_additional->address_id);
             if (is_null($rank)) {
                 throw new Exception('no results for rank. kwid: ' . $keyword->id);
             }
             $keyword_rank = new Keyword_rank();
             $keyword_rank->where(array('keyword_id' => $keyword->id, 'date' => date('Y-m-d')))->get(1);
             $keyword_rank->keyword_id = $keyword->id;
             $keyword_rank->date = date('Y-m-d');
             $keyword_rank->rank = intval($rank);
             $keyword_rank->save();
             log_message('TASK_SUCCESS', __FUNCTION__ . ' > ' . 'GLS Rank grabbed for kwid: ' . $keyword->id . ' -> ' . $rank);
         } else {
             throw new Exception('Google Rank Grabber Error: ' . $gls->error());
         }
     } catch (Exception $e) {
         //echo 'error: '.$e->getMessage().PHP_EOL;
         log_message('TASK_ERROR', __FUNCTION__ . ' > ' . $e->getMessage());
         throw $e;
     }
 }
Beispiel #4
0
 /**
  * Form with keywords list
  */
 public function index()
 {
     $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_and_profile($this->c_user->id, $this->profile->id);
     // get available keywords
     $keywords = Keyword::inst()->get_user_keywords($this->c_user->id, $this->profile->id);
     if ($this->input->post()) {
         // validate posted address name
         $new_address_name = $this->input->post('address');
         $adress_error_string = User_additional::validate_address($this->input->post());
         // validate posted keywords
         $new_keywords_names = array_slice($this->input->post('keywords'), 0, $keywords_count);
         $keywords_errors = Keyword::validate_keywords($new_keywords_names);
         // chek for errors
         if (empty($adress_error_string) && empty($keywords_errors)) {
             $user_additional = $user_additional->update_address($this->input->post(), $this->c_user->id, $this->profile->id);
             $keywords = $keywords->update_keywords($new_keywords_names, $this->c_user->id, $this->profile->id);
             $this->addFlash(lang('keywords_saved_success'), 'success');
         } else {
             $address_name = $new_address_name;
             $keywords_names = array_slice(array_values($this->input->post('keywords')), 0, $keywords_count);
             $errors = array('keywords' => $keywords_errors, 'address' => $adress_error_string);
             $this->addFlash($errors);
         }
         redirect('settings/keywords');
     }
     // 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_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);
     $this->template->render();
 }
Beispiel #5
0
 public function grank($keyword_id)
 {
     $keyword = new Keyword($keyword_id);
     $user_additional = User_additional::inst()->get_by_user_id($keyword->user_id);
     $this->load->config('site_config', TRUE);
     // $google_app_config = $this->config->item('google_app', 'site_config');
     $google_app_config = Api_key::build_config('google', $this->config->item('google_app', 'site_config'));
     $gls = $this->load->library('gls');
     $gls->set(array('key' => $google_app_config['developer_key']));
     $gls->request($keyword->keyword);
     if ($gls->success()) {
         $rank = $gls->location_rank($user_additional->address_id);
         if (is_null($rank)) {
             throw new Exception('No results for rank');
         }
         echo 'Rank: ' . $rank;
     } else {
         throw new Exception('Google Rank Grabber Error: ' . $gls->error());
     }
     echo '<hr>';
     echo '<pre>';
     var_dump($gls->dirty());
 }
 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();
 }
Beispiel #7
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);
 }
Beispiel #8
0
 public function getLocation()
 {
     $user_additional = User_additional::inst()->get_by_user_id(3);
     $this->load->config('site_config', TRUE);
     // $google_app_config = $this->config->item('google_app', 'site_config');
     $google_app_config = Api_key::build_config('google', $this->config->item('google_app', 'site_config'));
     $this->load->library('gls');
     $gls = new Gls();
     // important
     $gls->set(array('key' => $google_app_config['developer_key']));
     $gls->request('social');
     if ($gls->success()) {
         $rank = $gls->location_rank($user_additional->address_id);
         echo $rank;
     } else {
         throw new Exception('Google Rank Grabber Error: ' . $gls->error());
     }
 }
Beispiel #9
0
 /**
  * Used to connect user to Facebook account
  * Use Socializer Library
  * Add new record to 'Access tokens' and redirect to settings/socialmedia page
  *
  * @access public
  * @return void
  */
 public function facebook()
 {
     try {
         if (Social_group::hasSocialAccountByType($this->profile->id, 'facebook')) {
             $this->addFlash('This profile already has facebook account. Delete it or choose another profile.', 'error');
             redirect('settings/socialmedia');
         }
         $this->load->library('Socializer/socializer');
         /* @var Socializer_Facebook $facebook_socializer */
         $facebook_socializer = Socializer::factory('Facebook', $this->c_user->id);
         $redirect_url = $facebook_socializer->add_new_account($this->profile->id);
         $this->addFlash(lang('connected_success'), 'success');
         User_additional::inst()->unset_value($this->c_user->id, 'facebook_profile_photo');
         redirect($redirect_url);
     } catch (Exception $e) {
         $this->addFlash($e->getMessage(), 'error');
         redirect('settings/socialmedia');
     }
 }