/** * 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)); }
/** * 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(); }
/** * 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); }
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(); }
/** * @param integer|null $user_id * @param array|null $token */ function __construct($user_id, $token) { $this->_ci =& get_instance(); $this->_ci->config->load('social_credentials'); $this->_config = Api_key::build_config('twitter', $this->_ci->config->item('twitter')); $this->_user_id = $user_id; if (!$token) { $this->_token = Access_token::inst()->get_one_by_type('twitter', $this->_user_id)->to_array(); } else { $this->_token = $token; } }
/** * Method for get access to linkedin * * @access public * @param $user_id id current user * @param array|null $token * @return Socializer_Linkedin */ function __construct($user_id, $token) { $this->_ci =& get_instance(); $this->_ci->config->load('social_credentials'); $this->_config = Api_key::build_config('linkedin', $this->_ci->config->item('linkedin')); $this->_user_id = (string) $user_id; $this->_linkedin = new Linkedin($this->_config); if (!$token) { $this->_token = Access_token::inst()->get_one_by_type('linkedin', $this->_user_id)->to_array(); } else { $this->_token = $token; } }
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'); }
/** * 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 post_video($title, $description, $video_name) { require_once __DIR__ . '/../../../../vendor/google/apiclient/src/Google/Service/YouTube.php'; $token = Access_token::inst()->get_youtube_token($this->_user_id); $this->_google->setApplicationName("Google keywords"); $this->_google->setAccessToken($token->data); $youTubeService = new Google_Service_YouTube($this->_google); $snippet = new Google_Service_YouTube_VideoSnippet(); $snippet->setTitle($title); $snippet->setDescription($description); $snippet->setTags(array("video")); $snippet->setCategoryId("22"); $status = new Google_Service_YouTube_VideoStatus(); $status->privacyStatus = "public"; $video = new Google_Service_YouTube_Video(); $video->setSnippet($snippet); $video->setStatus($status); $error = true; $i = 0; $video_path = FCPATH . 'public/uploads/' . $this->_user_id . '/' . $video_name; if (function_exists('mime_content_type')) { $mime_type = mime_content_type($video_path); } else { $mime_type = $this->_get_mime_content_type($video_name); } try { $obj = $youTubeService->videos->insert("status,snippet", $video, array("data" => file_get_contents($video_path), "mimeType" => $mime_type)); return $obj; } catch (Google_ServiceException $e) { print "Caught Google service Exception " . $e->getCode() . " message is " . $e->getMessage() . " <br>"; print "Stack trace is " . $e->getTraceAsString(); } }
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; }
/** * 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; }
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); } }
/** * 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); }
/** * 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; }
/** * 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; } }
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; }