示例#1
0
 public function __construct()
 {
     parent::__construct();
     get_instance()->config->load('site_config', TRUE);
     // $api = get_instance()->config->item('google_app', 'site_config');
     // $this->api_key = $api['simple_api_key'];
     $this->api_key = Api_key::value('google', 'developer_key');
     if (empty($this->api_key)) {
         throw new Exception('Setup google api key.');
     }
 }
示例#2
0
 public function grabber(array $directory_user)
 {
     log_message('TASK_DEBUG', __FUNCTION__ . ' > ' . 'Reviews grabber');
     try {
         $directoryUser = new Directory_User($directory_user['id']);
         if (!$directoryUser->exists()) {
             throw new Exception('Directory_User id:' . $directory_user['id'] . ' doesn\'t exist');
         }
         $directory = $directoryUser->directory->get();
         if (!$directory->exists()) {
             throw new Exception('Directory id:' . $directory_user['directory_id'] . ' doesn\'t exist');
         }
         if (!$directory->status) {
             throw new Exception('Directory id:' . $directory_user['directory_id'] . ' is disabled');
         }
         $link = !empty($directory_user['additional']) ? $directory_user['additional'] : $directory_user['link'];
         log_message('TASK_DEBUG', __FUNCTION__ . ' > ' . 'Try to grabb - ' . $directory->name);
         $aac = $this->getAAC();
         $user = new User($directory_user['user_id']);
         if (!$user->exists()) {
             return;
         }
         $aac->setUser($user);
         $directory_parcer = Directory_Parser::factory($directory->type)->set_url($link);
         $reviews = $directory_parcer->get_reviews();
         /**
          * Store additional data to
          */
         if ($directory_parcer instanceof Directory_Interface_UserStorage) {
             $directoryUser->setAdditional($directory_parcer->getDataToStore())->save();
         }
     } catch (Exception $e) {
         log_message('TASK_ERROR', __FUNCTION__ . ' > ' . 'Reviews: ' . $e->getMessage());
         throw $e;
     }
     //$today_midnight = strtotime('-7 day midnight');
     $today_midnight = strtotime('-14 day midnight');
     if (is_array($reviews) && !empty($reviews)) {
         foreach ($reviews as $_review) {
             $review_model = new Review();
             $review_model->from_array($_review);
             $review_model->user_id = $directory_user['user_id'];
             $review_model->directory_id = $directory_user['directory_id'];
             $review_model->profile_id = $directory_user['profile_id'];
             $review_model->posted_date = date('Y-m-d', $_review['posted']);
             $review_model->save();
             log_message('TASK_DEBUG', __FUNCTION__ . ' > ' . 'Review saved');
         }
     }
 }
示例#3
0
 public function google_autocomplete()
 {
     $term = $this->input->get('term');
     $term = trim($term);
     $type = 'Google_Places';
     if (empty($term) || !DM_Directory::isActiveByType($type)) {
         exit;
     }
     $data = array();
     try {
         $google_paces = Directory_Parser::factory($type);
         $data = $google_paces->autocomplete($term);
     } catch (Exception $e) {
         exit;
     }
     header('Content-Type: application/json');
     echo json_encode($data);
     exit;
 }
示例#4
0
 protected function grabb($directory_user)
 {
     log_message('TASK_ERROR', __FUNCTION__ . ' > ' . 'Reviews grabber');
     try {
         $directory = new DM_Directory($directory_user['directory_id']);
         if (!$directory->exists()) {
             throw new Exception('Directory id:' . $directory_user['directory_id'] . ' doesn\'t exist');
         }
         if (!$directory->status) {
             throw new Exception('Directory id:' . $directory_user['directory_id'] . ' is disabled');
         }
         $link = !empty($directory_user['additional']) && !($directory->type == 'Foursquare') ? $directory_user['additional'] : $directory_user['link'];
         $directory_parcer = Directory_Parser::factory($directory->type)->set_url($link);
         //For fousquare only
         $directory_parcer->set_directory_user($directory_user);
         $reviews = $directory_parcer->get_reviews();
     } catch (Exception $e) {
         log_message('TASK_ERROR', __FUNCTION__ . ' > ' . 'Reviews: ' . $e->getMessage());
         throw $e;
     }
     //$today_midnight = strtotime('-7 day midnight');
     $today_midnight = strtotime('-34 day midnight');
     if (is_array($reviews) && !empty($reviews)) {
         foreach ($reviews as $_review) {
             $review_model = new Review();
             $review_model->from_array($_review);
             $review_model->user_id = $directory_user['user_id'];
             $review_model->directory_id = $directory_user['directory_id'];
             $review_model->posted_date = date('Y-m-d', $_review['posted']);
             $review_model->save();
             if (!$review_model->id) {
                 var_dump($review_model->error);
             }
             log_message('TASK_ERROR', __FUNCTION__ . ' > ' . 'Review saved');
             // notify user about new review
             if ($_review['posted'] > $today_midnight && !empty($review_model->id) && !empty($directory_user['user_id']) && !empty($directory_user['notify'])) {
                 $obj = Reviews_notification::addOne($directory_user['user_id'], $review_model->id);
                 if (!$obj->id) {
                     echo 'Error notification: ' . date('d-m-Y H:i') . ' - ' . $obj->error->string . PHP_EOL;
                 }
             }
         }
     }
 }
示例#5
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();
 }
示例#6
0
 public function grabber(array $directory_user)
 {
     try {
         $directory = new DM_Directory($directory_user['directory_id']);
         if (!$directory->exists()) {
             throw new Exception('Directory id:' . $directory_user['directory_id'] . ' doesn\'t exist');
         }
         if (!$directory->status) {
             throw new Exception('Directory id:' . $directory_user['directory_id'] . ' is disabled');
         }
         $link = !empty($directory_user['additional']) ? $directory_user['additional'] : $directory_user['link'];
         $directory_parcer = Directory_Parser::factory($directory->type)->set_url($link);
         $reviews = $directory_parcer->get_reviews();
     } catch (Exception $e) {
         throw $e;
     }
     //$today_midnight = strtotime('-7 day midnight');
     $today_midnight = strtotime('-14 day midnight');
     foreach ($reviews as $_review) {
         $review_model = new Review();
         $review_model->from_array($_review);
         $review_model->user_id = $directory_user['user_id'];
         $review_model->directory_id = $directory_user['directory_id'];
         $review_model->posted_date = date('Y-m-d', $_review['posted']);
         $review_model->save();
         // notify user about new review
         if (!empty($directory_user['notify_status']) && $_review['posted'] > $today_midnight && !empty($review_model->id) && !empty($directory_user['user_id']) && !empty($directory_user['notify'])) {
             $obj = Reviews_notification::addOne($directory_user['user_id'], $review_model->id);
             if (!$obj->id) {
                 echo 'Error notification: ' . date('d-m-Y H:i') . ' - ' . $obj->error->string . PHP_EOL;
             }
         }
     }
 }
示例#7
0
 /**
  * Update user's directories
  *
  * @param       $user_id
  * @param       $profile_id
  * @param       $directories_ids
  * @param array $additions
  *
  * @return array
  */
 public static function update_user_dir($user_id, $profile_id, $directories_ids, $additions = array())
 {
     $errors = array();
     $obj = new self();
     $table = $obj->table;
     $obj = new self();
     $old_options = array();
     foreach ($obj->where(array('user_id' => $user_id, 'profile_id' => $profile_id))->get() as $old_option) {
         $old_options[$old_option->directory_id] = $old_option->to_array();
     }
     $sql = "DELETE FROM {$table} WHERE user_id = {$user_id} AND profile_id = {$profile_id}";
     $obj->db->query($sql);
     if (empty($directories_ids)) {
         return;
     }
     $notify = empty($additions['notify']) ? 0 : 1;
     foreach ($directories_ids as $dir_id => $link) {
         $directory = new DM_Directory($dir_id);
         if (!$directory->exists()) {
             $errors[] = 'Directory #' . $dir_id . '(' . $link . ') doesn\'t exist';
             continue;
         }
         try {
             $directory_parcer = Directory_Parser::factory($directory->type);
         } catch (Exception $e) {
             $errors[] = 'Directory\'s #' . $directory->id . '(' . $directory->name . ') parser doesn\'t configured';
             continue;
         }
         if (!$directory_parcer->valid_url($link)) {
             $errors[] = 'Invalid url for directory ' . $directory->name;
             continue;
         }
         if (empty($old_options[$dir_id]) || $link !== $old_options[$dir_id]['link']) {
             Review::deleteByUserDirectory($user_id, $dir_id);
         }
         $new_settings = new self();
         $new_settings->from_array(array('user_id' => $user_id, 'profile_id' => $profile_id, 'link' => $link, 'directory_id' => $dir_id, 'notify' => $notify));
         $new_settings->save();
     }
     return $errors;
 }