/** * Daily social statistic collect * Add new access token to Queue * * @access public * @return void */ public function run() { $types = array('facebook', 'twitter', 'linkedin', 'google', 'instagram'); $tokens = Access_token::inst()->where_in('type', $types)->get(); $aac = $this->getAAC(); $acceptedUsersIds = array(); $now = new \DateTime('UTC'); foreach ($tokens as $_token) { $now->modify('1 minutes'); $user = new User($_token->user_id); if (!$user->exists()) { continue; } $aac->setUser($user); if (!$aac->isGrantedPlan('social_activity')) { continue; } $args = $_token->to_array(); foreach ($_token->social_group->get() as $profile) { $args['profile_id'] = $profile->id; if (!in_array($args['user_id'], $acceptedUsersIds) && $args['type'] != 'instagram') { array_push($acceptedUsersIds, $args['user_id']); } } } $this->jobQueue->addJob('tasks/social_reports_task/statistic', $acceptedUsersIds, array('thread' => self::SOCIAL_THREAD)); }
/** * Create access token for linkedin * * @access public * @return void */ public function add_new_account($profile_id) { if ($this->_ci->session->userdata('linkedin_token_secret')) { $verifier = $_GET['oauth_verifier']; $oauth_token = $_GET['oauth_token']; $response = $this->_linkedin->retrieveTokenAccess($oauth_token, $this->_ci->session->userdata('linkedin_token_secret'), $verifier); $this->_ci->session->unset_userdata('linkedin_token_secret'); $token = serialize($response['linkedin']); $access_token = new Access_token(); $profile = Linkedin::xmlToArray($this->_linkedin->profile('~:(id,formatted-name,picture-url)')['linkedin'])['person']['children']; $tokens = array('token' => null, 'secret_token' => null, 'data' => $token, 'name' => $profile['formatted-name']['content'], 'username' => $profile['id']['content'], 'image' => $profile['picture-url']['content']); $token = $access_token->add_token($tokens, 'linkedin', $this->_user_id); $social_group = new Social_group($profile_id); $social_group->save(array('access_token' => $token)); } }
/** * Daily social statistic collect * Add new access token to Queue * * @access public * @return void */ public function run() { $types = array('twitter'); $tokens = Access_token::inst()->where_in('type', $types)->get(); $aac = $this->getAAC(); $now = new \DateTime('UTC'); foreach ($tokens as $_token) { $now->modify('1 minutes'); $user = new User($_token->user_id); if (!$user->exists()) { continue; } $aac->setUser($user); if (!$aac->isGrantedPlan('social_activity')) { continue; } $args = $_token->to_array(); foreach ($_token->social_group->get() as $profile) { $args['profile_id'] = $profile->id; //Twitter tasks $this->jobQueue->addJob('tasks/twitter_task/searchUsers', $args, array('thread' => self::SOCIAL_THREAD, 'execute_after' => $now)); $this->jobQueue->addJob('tasks/twitter_task/updateFollowers', $args, array('thread' => self::SOCIAL_THREAD, 'execute_after' => $now)); $this->jobQueue->addJob('tasks/twitter_task/randomRetweet', $args, array('thread' => self::SOCIAL_THREAD, 'execute_after' => $now)); $this->jobQueue->addJob('tasks/twitter_task/randomFavourite', $args, array('thread' => self::SOCIAL_THREAD, 'execute_after' => $now)); $this->jobQueue->addJob('tasks/twitter_task/sendWelcomeMessage', $args, array('thread' => self::SOCIAL_THREAD, 'execute_after' => $now)); $this->jobQueue->addJob('tasks/twitter_task/followNewFollowers', $args, array('thread' => self::SOCIAL_THREAD, 'execute_after' => $now)); $this->jobQueue->addJob('tasks/twitter_task/unfollowUnsubscribedUsers', $args, array('thread' => self::SOCIAL_THREAD, 'execute_after' => $now)); } } }
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 __construct() { parent::__construct($this->website_part); $this->lang->load('analytics', $this->language); JsSettings::instance()->add(['i18n' => $this->lang->load('analytics', $this->language)]); $this->access_token = Access_token::getByTypeAndUserIdAndProfileId('googlea', $this->c_user->id, $this->profile->id); $this->load->library('google_analytics/ga_use'); // default date range $this->dates = array('from' => date($this->date_format, strtotime('-30 days')), 'to' => date($this->date_format)); }
/** * Load config and google access token model */ public function __construct() { parent::__construct($this->website_part); $this->load->config('site_config', TRUE); // $this->analytics_settings = $this->config->item('google_app', 'site_config'); $this->analytics_settings = Api_key::build_config('google', $this->config->item('google_app', 'site_config')); $this->analytics_settings['client_secret'] = $this->analytics_settings['secret']; $this->analytics_settings['redirect_uri'] = site_url('settings/analytics/connect'); $this->access_token = Access_token::inst()->get_one_by_type('google', $this->c_user->id); }
/** * Get Linkedin activities and add it to database * * @access public * @return void */ public function getLinkedinUpdates() { $access_tokens = Access_token::getAllByTypeAndUserIdAsArray('linkedin', $this->user_id); foreach ($access_tokens as $access_token) { /* @var Socializer_Linkedin $linkedin */ $linkedin = $this->socializer->factory('Linkedin', $this->user_id, $access_token); if ($linkedin) { $linkedin->getUpdates(); } } }
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 __construct() { parent::__construct(); $this->lang->load('crm', $this->language); JsSettings::instance()->add(['i18n' => $this->lang->load('crm', $this->language)]); $this->load->config('site_config', TRUE); $this->crmManager = $this->get('core.crm.manager'); $this->activeSocials = Access_token::inst()->get_crm_user_socials($this->c_user->id, $this->profile->id); $hasDirectories = Crm_directory::inst()->hasDirectories($this->c_user->id, $this->profile->id); $this->template->set('hasDirectories', $hasDirectories); $hasRequested = Crm_directory::inst()->hasRequested($this->c_user->id, $this->profile->id); $this->template->set('hasRequested', $hasRequested); //CssJs::getInst()->add_css('crm.css'); CssJs::getInst()->add_js('controller/crm/index.js'); $this->load->helper('clicable_links'); }
/** * @param array $keys * @param User $user * @param int $profile_id * * @return array */ public static function getByKeysAsArray($keys, $user, $profile_id) { $config = Config::create()->where('key', $keys[0])->get(1); $return = array(); $available_configs = $config->available_config->get()->all_to_array(); foreach ($available_configs as $available_config) { $tokens = Access_token::getAllByTypeAndUserIdAndProfileIdAsArray($available_config['type'], $user->id, $profile_id); $config = new Config($available_config['config_id']); $config = $config->to_array(); foreach ($tokens as $token) { $_element = array('token' => $token, 'config' => $config, 'values' => array()); foreach ($keys as $key) { $_element['values'][$key] = $user->ifUserHasConfigValue($key, $token['id']); } $return[$available_config->type][] = $_element; } } return $return; }
/** * 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; }
/** * Grab results for single mention keyword * * @param array $mention_keyword_array * @internal array $keyword_array - mention keyword model arrayed * */ public function grabber($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($user->id, $mention_keyword->profile_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)); $access_tokens = Access_token::getAllByTypeAndUserIdAndProfileIdAsArray($social, $user->id, $mention_keyword->profile_id); foreach ($access_tokens as $access_token) { if ($social === 'facebook') { $data = $mentioner->posts($mention_keyword_data, $mention_keyword_array, $access_token); } else { if ($social === 'twitter') { $data = $mentioner->tweets($mention_keyword_data, $mention_keyword_array, $access_token); } else { if ($social === 'google') { $data = $mentioner->activities($mention_keyword_data, $mention_keyword_array, $access_token); } else { if ($social === 'instagram') { $data = $mentioner->tags($mention_keyword_data, $mention_keyword_array, $access_token); } 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', $access_token['id'])) { $autoFollowTwitter = true; /* @var Core\Service\Radar\Radar $radar */ $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'); $mention->access_token_id = $access_token['id']; $mention->profile_id = $mention_keyword->profile_id; $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 ($autoFollowTwitter && Arr::path($row, 'other_fields.following') == false && ($conditions['twitter_followers'] <= $followers || $conditions['twitter_tweet_retweets'] <= $retweetCount)) { /* @var Core\Service\Radar\Radar $radar */ $radar->twitterMentionFollow($mention, $access_token); } 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) { $mentionFacebook = new Mention_facebook(); $mentionFacebook->friends_count = $friendsCount; $mentionFacebook->comments_count = $commentsCount; $mentionFacebook->likes_count = $likesCount; $mentionFacebook->mention_id = $mention->id; $mentionFacebook->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) { $mentionGoogle = new Mention_google(); $mentionGoogle->people_count = $peopleCount; $mentionGoogle->comments_count = $commentsCount; $mentionGoogle->plusoners_count = $plusonersCount; $mentionGoogle->resharers_count = $resharersCount; $mentionGoogle->mention_id = $mention->id; $mentionGoogle->save(); } break; case 'instagram': $commentsCount = (int) Arr::path($row, 'other_fields.instagram_comments'); $likesCount = (int) Arr::path($row, 'other_fields.instagram_likes'); if ($commentsCount || $likesCount) { $mentionInstagram = new Mention_instagram(); $mentionInstagram->instagram_comments = $commentsCount; $mentionInstagram->instagram_likes = $likesCount; $mentionInstagram->mention_id = $mention->id; $mentionInstagram->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; } }
/** * Check for not-updated-today, not-deleted keywords * And set for mentions update if exist */ public function queue_mention_keywords_for_update() { // get all keywords, that are not set for deletion // and they have a date of last request more then one day ago $mention_keywords = Mention_keyword::inst()->get_for_cron_update(); if (!$mention_keywords->exists()) { log_message('CRON_ERROR', __FUNCTION__ . ' > ' . 'No mention keywords for update'); return; } $today = date('U', strtotime('today')); $yesterday = date('U', strtotime('yesterday')); $users_cache = array(); $aac = $this->getAAC(); /** @var Mention_keyword $mention_keyword */ foreach ($mention_keywords as $mention_keyword) { $user = new User($mention_keyword->user_id); if (!$user->exists()) { continue; } $aac->setUser($user); if (!$aac->planHasFeature('brand_reputation_monitoring')) { continue; } if (!isset($users_cache[$mention_keyword->user_id])) { $users_cache[$mention_keyword->user_id] = 0; } $usersBrandReputationMonitoring = $aac->getPlanFeatureValue('brand_reputation_monitoring'); //$aac->isGrantedPlan('brand_reputation_monitoring') if ($usersBrandReputationMonitoring && $users_cache[$mention_keyword->user_id] >= $usersBrandReputationMonitoring) { break; } $users_cache[$mention_keyword->user_id]++; // if keywords has some socials set as grabbed, but also has non-requested date // clear all socials to try to grab mentions again if ($mention_keyword->grabbed_socials && $mention_keyword->requested_at && $mention_keyword->requested_at < $yesterday) { $mention_keyword->grabbed_socials = NULL; $saved = $mention_keyword->save(); if (!$saved) { log_message('CRON_ERROR', __FUNCTION__ . ' > ' . 'Not updated grabbs: ' . $mention_keyword->error->string); } else { log_message('CRON_SUCCESS', __FUNCTION__ . ' > ' . 'Not updated grabbs cleared'); } } // get socials user has tokens for $socials_for_update = Access_token::inst()->get_user_socials($mention_keyword->user_id, $mention_keyword->profile_id, ['facebook']); // get socials that were already grabbed $grabbed_socials = $mention_keyword->get_grabbed_socials_as_array(); // get socials that were not grabbed yet $socials = array_diff($socials_for_update, $grabbed_socials); if (count($socials)) { foreach ($socials as $social) { $args = $mention_keyword->to_array(); $args['social'] = $social; try { $this->jobQueue->addJob('tasks/mentions_task/grabber', $args, array('thread' => self::MENTIONS_THREAD)); log_message('CRON_SUCCESS', __FUNCTION__ . ' > ' . 'Adding Mentions : ' . $social); } catch (Exception $e) { log_message('CRON_ERROR', __FUNCTION__ . ' > ' . 'Failed mention : ' . $social . ' ; ' . $e->getMessage()); throw $e; } } } else { $mention_keyword->requested_at = $today; $mention_keyword->grabbed_socials = NULL; $saved = $mention_keyword->save(); if ($saved) { log_message('CRON_SUCCESS', __FUNCTION__ . ' > ' . 'Marked as grabbed : mkwid ' . $mention_keyword->id); } else { log_message('CRON_ERROR', __FUNCTION__ . ' > ' . 'Not marked as grabbed : mkwid ' . $mention_keyword->id . ' : ' . $mention_keyword->error->string); } } } $ids_str = implode(', ', array_values($mention_keywords->all_to_single_array('id'))); log_message('CRON_SUCCESS', __FUNCTION__ . ' > Mention keywords for update ids: ' . $ids_str); return; }
/** * Detach ga account (remove from db) * * @param $id */ public function logout($id) { $access_token = new Access_token($id); $access_token->delete(); $this->addFlash(lang('logged_out_success'), 'success'); redirect('settings/analytics'); }
private function _validate_video($feeds) { $errors = array(); if (empty($feeds['image_name'])) { $errors['image_name'] = lang('video_error'); } if (isset($feeds['title'])) { if (empty($feeds['title'])) { $errors['title'] = lang('video_title_error'); } } else { $errors['title'] = lang('video_title_error'); } $youtube_token = Access_token::inst()->get_youtube_token($feeds['user_id']); foreach ($feeds['post_to_groups'] as $group_id) { if (Social_group::hasSocialAccountByType($group_id, 'twitter') || Social_group::hasSocialAccountByType($group_id, 'linkedin')) { if (!$youtube_token->exists()) { $errors['post_to_groups[]'] = lang('youtube_error'); break; } } } return $errors; }
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(); }
/** * Check for not-updated-today, not-deleted crm directories * And set for crm activities update if exist */ public function queue_crm_directories_for_update() { // get all crm directories, that are not set for deletion // and they have a date of last request more then one day ago $crmDirectories = Crm_directory::inst()->getForUpdate(); if (!$crmDirectories->exists()) { log_message('CRON_ERROR', __FUNCTION__ . ' > ' . 'No crm directories for update'); return; } $today = date('U', strtotime('today')); $yesterday = date('U', strtotime('yesterday')); $users_cache = array(); $aac = $this->getAAC(); foreach ($crmDirectories as $directory) { $user = new User($directory->user_id); if (!$user->exists()) { continue; } $aac->setUser($user); if (!$aac->planHasFeature('crm')) { continue; } if (!isset($users_cache[$directory->user_id])) { $users_cache[$directory->user_id] = 0; } $usersCrm = $aac->getPlanFeatureValue('crm'); //$aac->isGrantedPlan('crm') if ($usersCrm && $users_cache[$directory->user_id] >= $usersCrm) { break; } $users_cache[$directory->user_id]++; // if directory has some socials set as grabbed, but also has non-requested date // clear all socials to try to grab activities again if ($directory->grabbed_socials && $directory->requested_at && $directory->requested_at < $yesterday) { $directory->grabbed_socials = NULL; $saved = $directory->save(); if (!$saved) { log_message('CRON_ERROR', __FUNCTION__ . ' > ' . 'Not updated grabbs: ' . $directory->error->string); } else { log_message('CRON_SUCCESS', __FUNCTION__ . ' > ' . 'Not updated grabbs cleared'); } } // get socials user has tokens for $socials_for_update = Access_token::inst()->get_crm_user_socials($directory->user_id, $directory->profile_id, ['facebook']); // get socials that were already grabbed $grabbed_socials = $directory->get_grabbed_socials_as_array(); // get socials that were not grabbed yet $socials = array_diff($socials_for_update, $grabbed_socials); if (count($socials)) { foreach ($socials as $social) { $args = $directory->to_array(); $args['social'] = $social; try { $this->jobQueue->addJob('tasks/crm_directory_task/grabber', $args, array('thread' => self::CRM_THREAD)); log_message('CRON_SUCCESS', __FUNCTION__ . ' > ' . 'Adding directories : ' . $social); } catch (Exception $e) { log_message('CRON_ERROR', __FUNCTION__ . ' > ' . 'Failed directory : ' . $social . ' ; ' . $e->getMessage()); throw $e; } } } else { $directory->requested_at = $today; $directory->grabbed_socials = NULL; $saved = $directory->save(); if ($saved) { log_message('CRON_SUCCESS', __FUNCTION__ . ' > ' . 'Marked as grabbed : mkwid ' . $directory->id); } else { log_message('CRON_ERROR', __FUNCTION__ . ' > ' . 'Not marked as grabbed : mkwid ' . $directory->id . ' : ' . $directory->error->string); } } } $ids_str = implode(', ', array_values($directory->all_to_single_array('id'))); log_message('CRON_SUCCESS', __FUNCTION__ . ' > Crm directories for update ids: ' . $ids_str); return; }
protected function grabbercrms($directory_array) { try { $directory_id = Arr::get($directory_array, 'id'); $directory = new Crm_directory($directory_id); $error_info = 'mkwid: ' . Arr::get($directory_array, 'social', 'no soc') . '/' . $directory_id; if (!$directory->exists()) { throw new Exception($error_info . ' doesn\'t exist.'); } if ($directory->is_deleted) { throw new Exception($error_info . ' is set for deletion.'); } if (!$directory->user_id) { throw new Exception($error_info . ' has no user id.'); } $user = new User($directory->user_id); if (!$user->exists()) { throw new Exception($error_info . ' has no user'); } $social = Arr::get($directory_array, 'social'); if (is_null($social)) { throw new Exception($error_info . ' invalid social'); } $user_socials = Access_token::inst()->get_crm_user_socials($directory->user_id); if (!in_array($social, $user_socials)) { throw new Exception($error_info . ' invalid social'); } $this->load->library('crmer'); $crmer = Crmer::factory($user->id); if ($social === 'facebook') { $data = $crmer->getCrmPosts($directory_array); } else { if ($social === 'twitter') { $data = $crmer->getCrmTweets($directory_array); } else { if ($social === 'instagram') { $data = $crmer->getCrmActivities($directory_array); } else { $data = array(); } } } if (!is_array($data)) { throw new Exception($error_info . ' no results for mentions, not an array. mkwid: '); } foreach ($data as $original_id => $row) { $activity = new Crm_directory_activity(); $activity->where(array('crm_directory_id' => $directory_array['id'], 'original_id' => $original_id))->get(1); $activity->social = $social; $activity->original_id = Arr::get($row, 'original_id'); $activity->created_at = Arr::get($row, 'created_at'); $message = Arr::get($row, 'message'); $trimMessage = strlen($message) > 4000 ? substr($message, 0, 4000) : $message; $activity->message = $trimMessage; $activity->creator_id = Arr::get($row, 'creator_id'); $activity->creator_name = Arr::get($row, 'creator_name'); $activity->creator_image_url = Arr::get($row, 'creator_image_url'); $activity->other_fields = serialize(Arr::get($row, 'other_fields', array())); $activity->source = Arr::get($row, 'source'); $relations = array('crm_directory' => $directory); $saved = $activity->save($relations); if (!$saved) { log_message('TASK_ERROR', __FUNCTION__ . ' > ' . 'Activity not saved for mkwid: ' . $error_info . ' grabbed: ' . $activity->error->string); } } // get socials that were already grabbed $grabbed_socials = $directory->get_grabbed_socials_as_array(); if (!in_array($social, $grabbed_socials)) { $grabbed_socials[] = $social; $now = date('U'); $directory->grabbed_socials = implode(',', $grabbed_socials); $directory->grabbed_at = $now; $saved = $directory->save(); if (!$saved) { log_message('TASK_ERROR', __FUNCTION__ . ' > ' . 'Mention keyword not saved for mkwid: ' . $error_info . ' grabbed: ' . $activity->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; } }
/** * Return html of feed * * @return string */ private function getHtmlData($mentions) { $htmlData = ''; if ($mentions->exists()) { foreach ($mentions as $mention) { $this->load->library('Socializer/socializer'); $access_token = Access_token::inst($mention->access_token_id)->to_array(); /* @var Socializer_Facebook $facebook */ $facebook = Socializer::factory('Facebook', $this->c_user->id, $access_token); $fbUserImage = $facebook->get_profile_picture(); $social = $mention->social; $wlist = new Influencers_whitelist(); $wlist->add($this->c_user->id, $mention->creator_id, $social); $radar = $this->get('core.radar'); if ($social == 'facebook') { $mention->creator_image_url = $facebook->get_profile_picture($mention->creator_id); $mention->user_image = $fbUserImage; } $mention->actions = in_array($social, $this->activeSocials); $mention->created_at = $radar->formatRadarDate($mention->created_at); $mention->profileUrl = $radar->getProfileUrl($mention->social); $content = $this->template->block('_content', '/influencers/blocks/' . $social, array('mention' => $mention)); $blockData = array('mention' => $mention, 'content' => $content); $htmlData .= $this->load->view('influencers/blocks/_feed', $blockData, true); } } return $htmlData; }
/** * Used to get Instagram access token * After - return redirect url * * @access public * * @param $profile_id * * @return string * @throws OAuthException */ public function add_new_account($profile_id) { $auth_instagram = $this->authorize($_GET['code']); if (isset($auth_instagram->access_token)) { $access_token = new Access_token(); $tokens = array('token' => $auth_instagram->access_token, 'secret_token' => null, 'instance_id' => $auth_instagram->user->id, 'image' => $auth_instagram->user->profile_picture, 'name' => $auth_instagram->user->full_name, 'username' => $auth_instagram->user->username); $token = $access_token->add_token($tokens, 'instagram', $this->_user_id); $social_group = new Social_group($profile_id); $social_group->save(array('access_token' => $token)); $redirect_url = site_url('settings/socialmedia'); } else { throw new OAuthException(lang('not_connected_error', ['Instagram'])); } return $redirect_url; }
/** * Used to add new record to Access Tokens Table * * @access public * * @param $oauth_verifier - $_REQUEST['code'] from controller * @param $profile_id * * @return string * @throws Exception */ public function add_new_account($oauth_verifier, $profile_id) { $oauth_token = $this->_ci->session->userdata('oauth_token'); $oauth_token_secret = $this->_ci->session->userdata('oauth_token_secret'); $connection = new TwitterOAuth($this->_config['consumer_key'], $this->_config['consumer_secret'], $oauth_token, $oauth_token_secret); $token_credentials = $connection->getAccessToken($oauth_verifier); $tokens = array('token' => $token_credentials['oauth_token'], 'secret_token' => $token_credentials['oauth_token_secret']); try { if (empty($this->_user_id)) { throw new Exception("There in no active user to connect to twitter."); } $tokens['username'] = $token_credentials['screen_name']; $socialFullInfo = $this->get_user_full_info($tokens['username']); if (empty($socialFullInfo->name)) { throw new Exception("Invalid twitter's user data. Please try to reconnect."); } $tokens['name'] = $socialFullInfo->name; $tokens['image'] = $socialFullInfo->profile_image_url; $access_token = new Access_token(); $token = $access_token->add_token($tokens, 'twitter', $this->_user_id); if (!$token->exists()) { throw new Exception("Cant save twitter access data. Please try to reconnect."); } $social_group = new Social_group($profile_id); $social_group->save(array('access_token' => $token)); } catch (Exception $e) { throw $e; } $redirect_url = site_url('settings/socialmedia'); return $redirect_url; }
/** * Check access to view the page * If user haven't access token for selected social - redirect to Social Settings page * * @access private * @param $type * @return bool */ private function _check_access($type) { $tokens = Access_token::inst()->get_by_type($type, $this->c_user->id, $this->profile->id); if (empty($tokens)) { return false; } else { return true; } }
/** * @param integer $user_id * @param null $group_id * @param array $exclude types * * @return array */ public static function getTokensArrayForGroup($user_id, $group_id = null, $exclude = array()) { $access = new Access_token(); $tokens = array(); $group = new Social_group($group_id); foreach (self::$types as $type) { if (in_array($type, $exclude)) { continue; } $tokens_array = $access->get_array_by_type($type, $user_id); if (!empty($tokens_array)) { if ($group->exists()) { foreach ($tokens_array as &$token) { if ($group->access_token->where('id', $token['id'])->get()->exists()) { $token['in_group'] = true; } else { $token['in_group'] = false; } } } $tokens[$type] = $tokens_array; } else { $tokens[$type] = array(); } } return $tokens; }
public function soc() { $types = array('facebook', 'twitter'); foreach ($types as $type) { $tokens = Access_token::getAllByType($type); $values_array = array(); foreach ($tokens as $_token) { $user_id = (int) $_token->user_id; $profiles = $_token->social_group->get(); foreach ($profiles as $profile) { $profile_id = $profile->id; // Queue_Item::add('tasks/social_reports_task/statistic', $args); $this->load->library('Socializer/socializer'); if (!isset($values_array[$type])) { $values_array[$type] = array(); } if (!isset($values_array[$type][$user_id][$profile_id])) { $values_array[$type][$user_id][$profile_id] = 0; } if ($type == 'twitter') { /* @var Socializer_Twitter $twitter */ $twitter = Socializer::factory('Twitter', $user_id, $_token); $values_array[$type][$user_id][$profile_id] += $twitter->get_followers_count(); } elseif ($type == 'facebook') { /* @var Socializer_Facebook $facebook */ $facebook = Socializer::factory('Facebook', $user_id, $_token); $values_array[$type][$user_id][$profile_id] += $facebook->get_page_likes_count(); } } } foreach ($values_array as $type => $values) { foreach ($values as $user_id => $value) { foreach ($value as $profile_id => $_value) { $this->_save_values($user_id, $profile_id, $_value, $type); } } } } }
/** * Check - is user have access to post into socials * Get Access Tokens for Facebook / Twitter from our database * Also need to check - is user select some Facebook fanpage * * @access private * @return array */ private function _check_socials_access() { return Access_token::inst()->check_socials_access($this->c_user->id); }
/** * Used to get facebook access token * Use Facebook SDK API library * After - return redirect url * * @access public * * @param $profile_id * * @return string */ public function add_new_account($profile_id) { $login_url = $this->_facebook->getLoginUrl(array('scope' => 'read_stream, manage_pages, user_videos, user_likes, publish_actions, publish_pages')); if ($this->_facebook->getUser()) { $profile = $this->get_profile(); $picture = $this->get_profile_picture($profile['id']); $access_token = new Access_token(); $tokens = array('token' => $this->_facebook->getAccessToken(), 'secret_token' => null, 'image' => $picture, 'name' => $profile['name'], 'username' => $profile['id']); $token = $access_token->add_token($tokens, 'facebook', $this->_user_id); $social_group = new Social_group($profile_id); $social_group->save(array('access_token' => $token)); $redirect_url = site_url('settings/socialmedia/edit_account/' . $token->id); } else { $redirect_url = $login_url; } return $redirect_url; }
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); }
public function get_analytics_data() { if ($this->template->is_ajax()) { $id = $this->input->post('access_token_id'); $period = $this->input->post('period'); $to = new DateTime('UTC'); $from = new DateTime('UTC'); $from->modify('-' . $period); $token = Access_token::inst($id); $data = $token->social_analytics->get_by_period($from->format('Y-m-d'), $to->format('Y-m-d'))->all_to_array(); $answer = [Social_analytics::RETWEETS_ANALYTICS_TYPE => [], Social_analytics::FAVOURITES_ANALYTICS_TYPE => [], Social_analytics::NEW_FOLLOWING_ANALYTICS_TYPE => [], Social_analytics::NEW_UNFOLLOWERS_ANALYTICS_TYPE => [], Social_analytics::NEW_FOLLOWING_BY_SEARCH_ANALYTICS_TYPE => [], Social_analytics::NEW_UNFOLLOWING_ANALYTICS_TYPE => []]; foreach ($data as $el) { $answer[$el['type']][$el['date']] = $el['value']; } $social_values = Social_value::inst(); $social_values->set_values($this->c_user->id, $this->profile->id, array('from' => $from->format('Y-m-d'), 'to' => $to->format('Y-m-d'), 'type' => 'twitter')); $answer['followers'] = $social_values->get_data()['twitter']; unset($answer['followers']['']); echo json_encode($answer); } }
/** * Get crm activities * * @param $directoryArray * @return array */ public function getCrmActivities($directoryArray) { log_message('TASK_SUCCESS', __FUNCTION__ . ' > ' . ' called in mentioner'); if (empty($directoryArray['instagram_link'])) { log_message('TASK_ERROR', __FUNCTION__ . ' > ' . 'no link for directory id=' . $directoryArray['id']); return; } $access_token = Access_token::getOneByTypeAndUserIdAndProfileIdAsArray('instagram', $this->userId, $this->profileId); /* @var Socializer_Instagram $instagram */ $instagram = $this->socializer->factory('Instagram', $this->userId, $access_token); $params = array('limit' => $this->limit, 'since' => strtotime('yesterday'), 'until' => strtotime('tomorrow')); $params['continue_from'] = isset($directoryArray['continue_from']) ? $directoryArray['continue_from'] : null; $userId = $instagram->getUserFromLink($directoryArray['instagram_link']); if (!$userId) { log_message('TASK_ERROR', __FUNCTION__ . ' > ' . 'invalid username in directory id=' . $directoryArray['id']); return; } $result = array(); while (true) { sleep(1); try { $data = $instagram->activities($userId, $params); } catch (Exception $e) { log_message('TASK_ERROR', __FUNCTION__ . ' > ' . $e->getMessage()); $data = null; } if (!is_array($data)) { break; } list($parsed, $parsed_count) = $this->parseActivities($data); $result = array_merge($result, $parsed); // check if per task limit reached if (count($result) >= $this->maxPerRequest - $this->limit) { // if reached create another task $lastResult = end($result); $directoryArray['continue_from'] = $lastResult->id; if (!$this->test) { log_message('TASK_SUCCESS', __FUNCTION__ . ' > ' . 'loop; extra queue'); $this->jobQueue->addJob('tasks/mentions_task/grabber', $directoryArray, array('thread' => CLI_controller::CRM_THREAD)); } break; } if (count($data) < $this->limit) { break; } } log_message('TASK_SUCCESS', __FUNCTION__ . ' fetched - ' . count($result)); return $result; }