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(); }
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 index($social = null) { $this->load->helper('clicable_links'); /* @var Core\Service\Radar\Radar $radar */ $radar = $this->get('core.radar'); $this->config->load('web_radar'); $limit = $this->config->config['mentions_limit']; $offset = Arr::get($_GET, 'offset', 0); $radar->addFilterParams(array('user_id' => $this->c_user->id, 'profile_id' => $this->profile->id))->setLimit($limit)->setOffset($offset); $socials = $radar->getSocials(); if ($social && !in_array($social, $socials)) { $social = null; } $this->activeSocials = Access_token::inst()->get_user_socials($this->c_user->id, $this->profile->id); list($from, $to) = $this->getDatesFromRequest(); if ($keyword = Arr::get($_GET, 'keyword', 0)) { $radar->addFilterParams(array('mention_keyword_id' => $keyword)); } if ($social) { $radar->addFilterParams(array('social' => $social)); } if ($from) { $radar->addFilterParams(array('from' => $from->getTimestamp())); } if ($to) { $radar->addFilterParams(array('to' => $to->getTimestamp())); } $mentions = $radar->getRadarMentions(); $feed = $this->getHtmlData($mentions); if ($this->template->is_ajax()) { echo json_encode(array('html' => $feed)); exit; } $keywordQueryStr = $keyword ? '&keyword=' . $keyword : ''; $formatedFrom = $from->format($this->dateFormat); $formatedTo = $to->format($this->dateFormat); $dates = array('from' => $formatedFrom, 'to' => $formatedTo); $keywords = Mention_keyword::inst()->dropdown($this->c_user->id, $this->profile->id); $keywordsForHighlight = Mention_keyword::inst()->get_for_highlight($this->c_user->id, intval($keyword)); CssJs::getInst()->add_js(array('controller/webradar/index.js', 'libs/jsUtils.min.js')); JsSettings::instance()->add(array('non_ajax_pagination' => true, 'keywords' => $keywordsForHighlight, 'keyword_query_id' => $keyword, 'keyword_query_str' => $keywordQueryStr, 'social' => $social, 'socials' => $socials, 'dates' => $dates)); $this->template->set('dates', $dates); $this->template->set('dateRange', $diff = $from->diff($to)->format("%a")); $this->template->set('keyword', $keyword); $this->template->set('keywordQueryStr', $keywordQueryStr); $this->template->set('keywords', $keywords); $this->template->set('socials', $socials); $this->template->set('feed', $feed); $socialName = $social ? ucfirst($social) : lang('all_mentions'); $this->template->set('social', $socialName); $this->template->current_view = 'social/webradar/index'; $this->template->render(); }
public function index() { $this->load->helper('clicable_links'); $radar = $this->get('core.radar'); $this->config->load('web_radar'); $limit = $this->config->config['mentions_limit']; $offset = Arr::get($_GET, 'offset', 0); $radar->addFilterParams(array('user_id' => $this->c_user->id))->setLimit($limit)->setOffset($offset); $socials = $radar->getSocials(); $this->activeSocials = Access_token::inst()->get_user_socials($this->c_user->id, $this->profile->id); //$this->fbUserImageUrl = $radar->getFBUserImage($this->c_user->id); $from = date($this->dateFormat, strtotime(Arr::get($_GET, 'from', 'yesterday'))); $to = date($this->dateFormat, strtotime(Arr::get($_GET, 'to', 'today'))); list($from, $to) = $this->getDatesFromRequest(); if ($keyword = Arr::get($_GET, 'keyword', 0)) { $radar->addFilterParams(array('mention_keyword_id' => $keyword)); } if ($social = Arr::get($_GET, 'social', 0)) { $radar->addFilterParams(array('social' => $social)); } if ($from) { $radar->addFilterParams(array('from' => $from->getTimestamp())); } if ($to) { $radar->addFilterParams(array('to' => $to->getTimestamp())); } $mentions = $radar->getRadarInfluencers($this->c_user->id); $feed = $this->getHtmlData($mentions); if ($this->template->is_ajax()) { echo json_encode(array('html' => $feed)); exit; } $keywordQueryStr = $keyword ? '&keyword=' . $keyword : ''; $formatedFrom = $from->format($this->dateFormat); $formatedTo = $to->format($this->dateFormat); $dates = array('from' => $formatedFrom, 'to' => $formatedTo); $keywords = Mention_keyword::inst()->dropdown($this->c_user->id, $this->profile->id); $keywordsForHighlight = Mention_keyword::inst()->get_for_highlight($this->c_user->id, intval($keyword)); CssJs::getInst()->c_js(); JsSettings::instance()->add(array('non_ajax_pagination' => true, 'keywords' => $keywordsForHighlight, 'keyword_query_id' => $keyword, 'keyword_query_str' => $keywordQueryStr, 'socials' => $socials, 'dates' => $dates)); $this->template->set('dates', $dates); $this->template->set('keyword', $keyword); $this->template->set('keywordQueryStr', $keywordQueryStr); $this->template->set('keywords', $keywords); $this->template->set('socials', $socials); $this->template->set('feed', $feed); $this->template->render(); }
protected function grabberments($mention_keyword_array) { try { $mention_keyword_id = Arr::get($mention_keyword_array, 'id'); $mention_keyword = new Mention_keyword($mention_keyword_id); $error_info = 'mkwid: ' . Arr::get($mention_keyword_array, 'social', 'no soc') . '/' . $mention_keyword_id; if (!$mention_keyword->exists()) { throw new Exception($error_info . ' doesn\'t exist.'); } if ($mention_keyword->is_deleted) { throw new Exception($error_info . ' is set for deletion.'); } if (!$mention_keyword->user_id) { throw new Exception($error_info . ' has no user id.'); } $user = new User($mention_keyword->user_id); if (!$user->exists()) { throw new Exception($error_info . ' has no user'); } $social = Arr::get($mention_keyword_array, 'social'); if (is_null($social)) { throw new Exception($error_info . ' invalid social'); } $user_socials = Access_token::inst()->get_user_socials($mention_keyword->user_id); if (!in_array($social, $user_socials)) { throw new Exception($error_info . ' invalid social'); } $this->load->library('mentioner'); $mentioner = Mentioner::factory($user->id); $mention_keyword_data = array_merge($mention_keyword_array, array('keyword' => $mention_keyword->keyword, 'exact' => $mention_keyword->exact, 'other_fields' => $mention_keyword->other_fields)); if ($social === 'facebook') { $data = $mentioner->posts($mention_keyword_data, $mention_keyword_array); } else { if ($social === 'twitter') { $data = $mentioner->tweets($mention_keyword_data, $mention_keyword_array); } else { if ($social === 'google') { $data = $mentioner->activities($mention_keyword_data, $mention_keyword_array); } else { if ($social === 'instagram') { $data = $mentioner->tags($mention_keyword_data, $mention_keyword_array); } else { $data = array(); } } } } if (!is_array($data)) { throw new Exception($error_info . ' no results for mentions, not an array. mkwid: '); } if ($user->ifUserHasConfigValue('auto_follow_twitter')) { $autoFollowTwitter = true; $radar = $this->get('core.radar'); $conditions = Influencers_condition::allToOptionsArray(); } else { $autoFollowTwitter = false; } foreach ($data as $original_id => $row) { $mention = new Mention(); $mention->where(array('mention_keyword_id' => $mention_keyword->id, 'original_id' => $original_id))->get(1); $mention->social = $social; $mention->original_id = Arr::get($row, 'original_id'); $mention->created_at = Arr::get($row, 'created_at'); $message = Arr::get($row, 'message'); $trimMessage = strlen($message) > 4000 ? substr($message, 0, 4000) : $message; $mention->message = $trimMessage; $mention->creator_id = Arr::get($row, 'creator_id'); $mention->creator_name = Arr::get($row, 'creator_name'); $mention->creator_image_url = Arr::get($row, 'creator_image_url'); $mention->other_fields = serialize(Arr::get($row, 'other_fields', array())); $mention->source = Arr::get($row, 'source'); $relations = array('user' => $user, 'mention_keyword' => $mention_keyword); $saved = $mention->save($relations); if (!$saved) { log_message('TASK_ERROR', __FUNCTION__ . ' > ' . 'Mention not saved for mkwid: ' . $error_info . ' grabbed: ' . $mention->error->string); } else { switch ($social) { case 'twitter': $followers = (int) Arr::path($row, 'other_fields.creator_followers_count'); $retweetCount = (int) Arr::path($row, 'other_fields.retweet_count'); if ($followers || $retweetCount) { $mentionTwitter = new Mention_twitter(); $mentionTwitter->followers_count = $followers; $mentionTwitter->retweet_count = $retweetCount; $mentionTwitter->mention_id = $mention->id; $mentionTwitter->save(); } break; case 'facebook': $friendsCount = (int) Arr::path($row, 'other_fields.friends_count'); $commentsCount = (int) Arr::path($row, 'other_fields.comments'); $likesCount = (int) Arr::path($row, 'other_fields.likes'); if ($friendsCount || $commentsCount || $likesCount) { $mentionTwitter = new Mention_facebook(); $mentionTwitter->friends_count = $friendsCount; $mentionTwitter->comments_count = $commentsCount; $mentionTwitter->likes_count = $likesCount; $mentionTwitter->mention_id = $mention->id; $mentionTwitter->save(); } break; case 'google': $peopleCount = (int) Arr::path($row, 'other_fields.people_count'); $commentsCount = (int) Arr::path($row, 'other_fields.comments'); $plusonersCount = (int) Arr::path($row, 'other_fields.plusoners'); $resharersCount = (int) Arr::path($row, 'other_fields.resharers'); if ($peopleCount || $commentsCount || $plusonersCount || $resharersCount) { $mentionTwitter = new Mention_google(); $mentionTwitter->people_count = $peopleCount; $mentionTwitter->comments_count = $commentsCount; $mentionTwitter->plusoners_count = $plusonersCount; $mentionTwitter->resharers_count = $resharersCount; $mentionTwitter->mention_id = $mention->id; $mentionTwitter->save(); } break; } } } // get socials that were already grabbed $grabbed_socials = $mention_keyword->get_grabbed_socials_as_array(); if (!in_array($social, $grabbed_socials)) { $grabbed_socials[] = $social; $now = date('U'); $mention_keyword->grabbed_socials = implode(',', $grabbed_socials); $mention_keyword->grabbed_at = $now; $saved = $mention_keyword->save(); if (!$saved) { log_message('TASK_ERROR', __FUNCTION__ . ' > ' . 'Mention keyword not saved for mkwid: ' . $error_info . ' grabbed: ' . $mention->error->string); } } log_message('TASK_SUCCESS', __FUNCTION__ . ' > ' . 'Mentions for mkwid: ' . $error_info . ' grabbed'); } catch (Exception $e) { log_message('TASK_ERROR', __FUNCTION__ . ' > ' . $e->getMessage()); return; // throw $e; } }
/** * Remove single mention keyword with all collected mentions * * @param array $mention_keyword_array - mention keyword model arrayed * * @throws Exception */ public function remove_deleted($mention_keyword_array) { try { $mention_keyword_id = isset($mention_keyword_array['id']) ? $mention_keyword_array['id'] : null; $mention_keyword = new Mention_keyword($mention_keyword_id); if (!$mention_keyword->exists()) { throw new Exception('mkwid: ' . $mention_keyword_id . ' doesn\'t exist.'); } $mention_keyword_mentions = Mention::inst()->get_by_mention_keyword_id($mention_keyword_id); $mention_keyword_mentions->delete_all(); $mention_keyword->delete(); log_message('TASK_SUCCESS', __FUNCTION__ . ' > ' . 'Mention keyword and mentions for mkwid: ' . $mention_keyword_array['id'] . ' deleted'); } catch (Exception $e) { log_message('TASK_ERROR', __FUNCTION__ . ' > ' . $e->getMessage()); return; // throw $e; } }
/** * Check mention keywords set for deletion * And move them to queue * * minutely ? */ public function queue_deleted_mention_keywords() { $keywords = Mention_keyword::inst()->get_by_is_deleted(1); if (!$keywords->exists()) { log_message('CRON_ERROR', __FUNCTION__ . ' > ' . 'No keywords for removal'); return; } foreach ($keywords as $keyword) { $args = $keyword->to_array(); $this->jobQueue->addJob('tasks/mentions_task/remove_deleted', $args, array('thread' => self::MENTIONS_THREAD)); } $ids_str = implode(', ', array_values($keywords->all_to_single_array('id'))); log_message('CRON_SUCCESS', __FUNCTION__ . ' > ' . 'Mention keywords for removal ids: ' . $ids_str); return; }
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(); }
/** * Form with mentions keywords list */ public function index() { $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, $this->profile->id); $new_keywords = array(); $errors = array(); $saved_ids = array(0); // '0' to prevent datamapper error caused by empty array $delete = true; if ($post = $this->input->post()) { unset($post['submit']); $grouped = Arr::collect($post); if ($availableKeywordsCount && count($grouped) > $config_count) { $planError = lang('keywords_count_error', [$config_count]); $errors[] = $planError; $delete = false; } else { foreach ($grouped as $id => $data) { if (empty($data['keyword'])) { continue; } if (strpos($id, 'new_') === 0) { $keyword = Mention_keyword::inst()->fill_from_array($data, $this->c_user->id, $this->profile->id); $new_keywords[$id] = $keyword; } else { $keyword = Mention_keyword::inst()->fill_from_array($data, $this->c_user->id, $this->profile->id, $id); if ($keyword->id !== $id) { $new_keywords[$id] = $keyword; } } if ($keyword->save()) { $saved_ids[] = $keyword->id; } else { $errors[$id] = $keyword->error->string; } } } if (empty($errors)) { if ($delete) { Mention_keyword::inst()->set_deleted($this->c_user->id, $this->profile->id, $saved_ids); } $this->addFlash(lang('keywords_saved_success'), 'success'); redirect('settings/mention_keywords'); } else { $this->addFlash(implode('<br>', Arr::map('strip_tags', $errors))); } } JsSettings::instance()->add(array('max_keywords' => $config_count)); CssJs::getInst()->c_js(); $outp_keywords = array(); foreach ($keywords as $keyword) { $outp_keywords[$keyword->id] = $keyword; } $outp_keywords = array_merge($outp_keywords, $new_keywords); $this->template->set('keywords', $outp_keywords); $this->template->set('errors', $errors); $this->template->set('config_count', $config_count); $this->template->render(); }