public function index() { if ($this->c_user->isTrialPlanEnds()) { $this->addFlash(lang('subscription_ends_error', [site_url('subscript/plans')]), 'error'); } // UNCOMMENT TO USE // get average google rank for all keywords for chart in range $keyword_rank = Keyword::average_for_range($this->c_user->id, '-30 days', 'today'); // average result for all the range $keywords_trending = Keyword::average_for_range($this->c_user->id, '-30 days', 'today', FALSE); // average for each day in range // analytics data $google_access_token = Access_token::getByTypeAndUserId('googlea', $this->c_user->id); list($ga_visits_chart, $ga_visits_count) = $google_access_token->google_analytics_dashboard_visits(); $review = new Review(); $last_reviews_count = $review->last_period_count($this->c_user->id, $this->profile->id); $review->clear(); $social_values = Social_value::inst(); $social_values->set_values($this->c_user->id, $this->profile->id, array('from' => date('Y-m-d', strtotime('-30 days')), 'to' => date('Y-m-d', time()))); $all_socials_data = $social_values->get_data(); $monthly_trending = array('reviews' => $review->last_month_trending($this->c_user->id, $this->profile->id), 'traffic' => $ga_visits_chart, 'keywords' => $keywords_trending, 'twitter_followers' => $all_socials_data['twitter'], 'facebook_likes' => $all_socials_data['facebook']); $keywordsForHighlight = Mention_keyword::inst()->get_for_highlight($this->c_user->id, 0); CssJs::getInst()->add_js('www.google.com/jsapi', 'external', 'footer'); CssJs::getInst()->add_js(array('libs/lodash.compat.js', 'libs/highcharts/highcharts.js'))->c_js(); $opportunities = $this->getOpportunities(); if (!empty($opportunities['web_radar'])) { CssJs::getInst()->add_js('controller/webradar/index.js'); } JsSettings::instance()->add(array('monthly_trending' => $monthly_trending, 'dashboard' => true, 'keywords' => $keywordsForHighlight, 'opportunities' => $opportunities)); $summary = array('reviews' => (int) $last_reviews_count, 'fb_likes' => (int) $all_socials_data['likes_count'], 'twiter_followers' => (int) $all_socials_data['followers_count'], 'web_traffic' => (int) $ga_visits_count, 'google_rank' => (int) round($keyword_rank, 3)); $this->isSupportScheduledPosts = $this->getAAC()->isGrantedPlan('scheduled_posts'); $this->load->helper('my_url_helper'); $this->template->set('isSupportScheduledPosts', $this->isSupportScheduledPosts); $this->template->set('socials', Social_post::getActiveSocials($this->profile->id)); $this->is_user_set_timezone = User_timezone::is_user_set_timezone($this->c_user->id); JsSettings::instance()->add(array('twitterLimits' => array('maxLength' => 140, 'midLength' => 117, 'lowLength' => 94), 'twitterLimitsText' => lang('twitter_error'), 'linkedinLimits' => array('maxLength' => 400), 'linkedinLimitsText' => lang('linkedin_error'))); CssJs::getInst()->add_css(array('custom/pick-a-color-1.css')); CssJs::getInst()->add_js(array('libs/jq.file-uploader/jquery.iframe-transport.js', 'libs/jq.file-uploader/jquery.fileupload.js', 'libs/fabric/fabric.min.js', 'libs/fabric/StackBlur.js', 'libs/color/tinycolor-0.9.15.min.js', 'libs/color/pick-a-color-1.2.3.min.js')); CssJs::getInst()->c_js('social/create', 'post_update'); CssJs::getInst()->c_js('social/create', 'post_cron'); CssJs::getInst()->c_js('social/create', 'post_attachment'); CssJs::getInst()->c_js('social/create', 'social_limiter'); CssJs::getInst()->c_js('social/create', 'schedule_block'); CssJs::getInst()->c_js('social/create', 'bulk_upload'); $this->template->set('is_user_set_timezone', User_timezone::is_user_set_timezone($this->c_user->id)); $user_posts = Social_post::inst()->get_user_scheduled_posts($this->c_user->id, $this->profile->id, 1, 3, 'all'); $this->template->set('posts', $user_posts); $this->load->helper('Image_designer_helper'); $this->template->set('imageDesignerImages', Image_designer::getImages()); $this->template->set('summary', $summary); $this->template->set('opportunities', $opportunities); $this->template->set('need_welcome_notification', User_notification::needShowNotification($this->c_user->id, User_notification::WELCOME)); $this->template->render(); }
public function save_timezone() { if ($this->template->is_ajax()) { $response['success'] = false; $response['message'] = lang('timezone_error'); $post = $this->input->post(); if (isset($post['timezone'])) { User_timezone::save_timezone($this->c_user->id, $post['timezone']); $response['success'] = true; $response['message'] = lang('timezone_success'); } echo json_encode($response); } exit; }
/** * 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; }
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(); }
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); }
/** * @param $csv_filename * @param $user_id * @param $profile_id * * @return array */ static function getScheduledPostsArray($csv_filename, $user_id, $profile_id) { $error = ''; $posts = []; $row = 1; if (($handle = fopen($csv_filename, "r")) !== FALSE) { while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { $post = ['posting_type' => 'schedule', 'post_to_groups' => [$profile_id], 'timezone' => User_timezone::get_user_timezone($user_id)]; //VALIDATE SOCIALS. MUST BE IN FORMT social\social\social. if (isset($data[self::SOCIALS_POSITION])) { $validate_socials = self::validateSocials($data[self::SOCIALS_POSITION]); if ($validate_socials['success']) { $post['post_to_socials'] = $validate_socials['data']; } else { $error = self::getErrorMessage($row, self::SOCIALS_POSITION, $validate_socials['error']); break; } } else { $error = self::getErrorMessage($row, self::SOCIALS_POSITION, 'Can`t find socials'); break; } //VALIDATE SCHEDULED DATE if (!isset($data[self::YEAR_POSITION]) || !isset($data[self::MONTH_POSITION]) || !isset($data[self::DAY_POSITION]) || !isset($data[self::HOUR_POSITION]) || !isset($data[self::MINUTE_POSITION])) { $error = self::getErrorMessage($row, self::YEAR_POSITION . '-' . self::MINUTE_POSITION, 'Wrong scheduled date'); break; } else { $validate_scheduled_date = self::validateScheduleDate($data[self::YEAR_POSITION], $data[self::MONTH_POSITION], $data[self::DAY_POSITION], $data[self::HOUR_POSITION], $data[self::MINUTE_POSITION]); if ($validate_scheduled_date['success']) { $post['schedule_date'] = $validate_scheduled_date['data']; } else { $error = self::getErrorMessage($row, self::YEAR_POSITION . '-' . self::MINUTE_POSITION, $validate_scheduled_date['error']); break; } } //VALIDATE IMAGE if (isset($data[self::IMAGE_POSITION]) && !empty($data[self::IMAGE_POSITION])) { $validate_image = self::validateImage($data[self::IMAGE_POSITION], $user_id); if ($validate_image['success']) { $post['image_name'] = $validate_image['data']; } else { $error = self::getErrorMessage($row, self::IMAGE_POSITION, $validate_image['error']); break; } } //VALIDATE LINK if (isset($data[self::LINK_POSITION]) && !empty($data[self::LINK_POSITION])) { if (filter_var($data[self::LINK_POSITION], FILTER_VALIDATE_URL) === false || strstr($data[self::LINK_POSITION], '.') === false) { $error = self::getErrorMessage($row, self::LINK_POSITION, 'The URL is invalid. (Example: http://google.com)'); break; } else { $post['url'] = $data[self::LINK_POSITION]; } } //VALIDATE STATUS if (isset($data[self::STATUS_POSITION])) { $validate_status = self::validateStatus($data[self::STATUS_POSITION], $post); if ($validate_status['success']) { $post['description'] = $validate_status['data']; } else { $error = self::getErrorMessage($row, self::STATUS_POSITION, $validate_status['error']); break; } } else { $error = self::getErrorMessage($row, self::STATUS_POSITION, 'Status in required.'); break; } $row++; $posts[] = $post; } fclose($handle); } if ($error) { return ['success' => false, 'error' => $error]; } else { return ['success' => true, 'data' => $posts]; } }
public function add_cron_post($post) { if ($this->template->is_ajax()) { $post['post_to_groups'] = array($this->profile->id); $post['timezone'] = User_timezone::get_user_timezone($this->c_user->id); $post['user_id'] = $this->c_user->id; $errors = Social_post::validate_post($post); if (empty($errors)) { $errors = Social_post_cron::validate_cron($post); if (empty($errors)) { Social_post_cron::add_new_post($post, $this->c_user->id, $this->profile->id); $result['success'] = true; $result['message'] = lang('post_was_successfully_added'); } else { $result['success'] = false; $result['errors'] = $errors; } } else { $result['success'] = false; $result['errors'] = $errors; } echo json_encode($result); } exit; }
/** * Search users and follow them * * @param $args */ public function searchUsers($args) { $user_id = (int) $args['user_id']; $user = new User($user_id); $access_token_id = $args['id']; if (!$user->ifUserHasConfigValue('auto_follow_users_by_search', $access_token_id)) { return; } log_message('TASK_DEBUG', __FUNCTION__ . 'Twitter: start search users to follow.' . $this->getDebugInfo($user, $access_token_id)); $date = new DateTime('UTC 00:00:00'); $user_timezone = new DateTimeZone(User_timezone::get_user_timezone($user_id)); $timezone_offset = $user_timezone->getOffset($date) / 3600; $twitter = $this->inicializeTwitterSocializer($user_id, $args); $user_search_keywords = $user->getUserSearchKeywords($args['profile_id']); $number_of_added_users = $user->getDateToAddUserTwitter($access_token_id); $max_daily_auto_follow_users_by_search = (int) $user->ifUserHasConfigValue('max_daily_auto_follow_users_by_search', $access_token_id); $old_date = DateTime::createFromFormat('!Y-m-d', $number_of_added_users->date); if (!$number_of_added_users->id) { $number_of_added_users->date = $date->format('Y-m-d'); $number_of_added_users->setUserId($user_id); $number_of_added_users->token_id = $access_token_id; $number_of_added_users->count = 0; } elseif ($old_date < $date) { $number_of_added_users = new Number_of_added_users_twitter(); $number_of_added_users->date = $date->format('Y-m-d'); $number_of_added_users->setUserId($user_id); $number_of_added_users->count = 0; $number_of_added_users->token_id = $access_token_id; $number_of_added_users->save(); } elseif ($old_date > $date) { \log_message('TASK_SUCCESS', __FUNCTION__ . 'Twitter: ' . 'Twitter followers already added.' . "\n" . $this->getDebugInfo($user, $access_token_id)); return; } unset($old_date); $age_of_account = $user->ifUserHasConfigValue('age_of_account', $access_token_id); if (!$age_of_account) { $age_of_account = 0; } else { $age_of_account_splited = preg_split('/,/', $age_of_account); if (count($age_of_account_splited)) { if (count($age_of_account_splited) > 1) { $age_of_account = $age_of_account_splited; } } } $tweets_count = $user->ifUserHasConfigValue('number_of_tweets', $access_token_id); if (!$tweets_count) { $tweets_count = 0; } else { $tweets_count_splited = preg_split('/,/', $tweets_count); if (count($tweets_count_splited)) { if (count($tweets_count_splited) > 1) { $tweets_count = $tweets_count_splited; } } } foreach ($user_search_keywords as $user_search_keyword) { $other_field = $user_search_keyword->get_other_fields(); $query = $twitter->create_query($user_search_keyword->keyword, $other_field['include'], $other_field['exclude'], $user_search_keyword->exact); $queryArgs = ['min_followers' => $user_search_keyword->min_followers, 'max_followers' => $user_search_keyword->max_followers, 'max_id' => $user_search_keyword->max_id, 'age_of_account' => $age_of_account, 'tweets_count' => $tweets_count]; $users = $twitter->search_users($query, $queryArgs); foreach ($users['users'] as $twitter_user_id) { if (!$user->isUserHasTwitterFollower($twitter_user_id, $access_token_id)) { if ($max_daily_auto_follow_users_by_search && $max_daily_auto_follow_users_by_search > $number_of_added_users->count || !$max_daily_auto_follow_users_by_search) { $date = DateTime::createFromFormat('!Y-m-d', $number_of_added_users->date); $number_of_added_users->count += 1; $number_of_added_users->save(); } else { $date = DateTime::createFromFormat('!Y-m-d', $number_of_added_users->date); $date->modify('+1 days'); $number_of_added_users = new Number_of_added_users_twitter(); $number_of_added_users->date = $date->format('Y-m-d'); $number_of_added_users->setUserId($user_id); $number_of_added_users->token_id = $access_token_id; $number_of_added_users->count = 1; $number_of_added_users->save(); } $twitter_follower = new Twitter_follower(); $twitter_follower->setFollowerId($twitter_user_id); $twitter_follower->setUserId($user_id); $twitter_follower->setAccessTokenId($access_token_id); $start_date = clone $date; $start_date->modify($timezone_offset * -1 . ' hours'); $end_date = clone $date; $end_date->modify($timezone_offset * -1 . ' hours'); if ($end_date <= $start_date) { $end_date->modify('1 days'); } $twitter_follower->setStartFollowTime($user_search_keyword->getStartDateTime($start_date)->getTimestamp()); $twitter_follower->setEndFollowTime($user_search_keyword->getEndDateTime($end_date)->getTimestamp()); unset($start_date); unset($end_date); $twitter_follower->setNeedFollow(true); $twitter_follower->save(); } } log_message('TASK_SUCCESS', __FUNCTION__ . 'Twitter: ' . 'By keywords ' . $query . ' add ' . count($users['users']) . ' users.' . "\n" . $this->getDebugInfo($user, $access_token_id)); if ($user_search_keyword->max_id != $users['max_id']) { $user_search_keyword->max_id = $users['max_id']; } else { $user_search_keyword->max_id = null; } $user_search_keyword->save(); } }