private function searchAccountInDB($username, $social_network) { switch ($social_network) { case 'facebook': $data = FacebookPage::whereUsername($username)->first(['fb_id', 'username', 'name']); break; case 'twitter': $data = TwitterProfile::whereScreenName($username)->first(['screen_name', 'name', 'picture']); break; case 'instagram': $data = InstagramProfile::whereUsername($username)->first(['username', 'name', 'picture']); break; default: return 'Invalid method'; break; } if ($data) { $page['username'] = strtolower(isset($data['username']) ? $data['username'] : $data['screen_name']); $page['name'] = !empty($data['name']) ? $data['name'] : $page['username']; $page['picture'] = $social_network == 'facebook' ? 'http://graph.facebook.com/' . $data['fb_id'] . '/picture?height=200&type=normal&width=200' : str_replace('_normal.', '_200x200.', $data['picture']); return $page; } else { return NULL; } }
public function getProfile($username) { $var_cache = 'instagramProfile' . $username; if (!Cache::has($var_cache)) { $data = InstagramProfile::whereUsername($username)->first(); if ($data) { $profile = NULL; $profile['username'] = strtolower($data['username']); $profile['name'] = $data['name']; $profile['bio'] = $data['bio']; $profile['website'] = $data['website']; $profile['picture'] = str_replace('_normal.', '.', $data['picture']); $auxformat = explode("-", $data['in_owloo_from']); $year = $auxformat[0]; $day = $auxformat[2]; $month = strtolower($this->getMonth($auxformat[1], 'large')); $profile['in_owloo_from'] = $day . ' ' . $month . ' ' . $year; $profile['followed_by_count'] = $this->owloo_number_format($data['followed_by_count']); $profile['follows_count'] = $this->owloo_number_format($data['follows_count']); $profile['media_count'] = $this->owloo_number_format($data['media_count']); $profile['followed_by_history_30'] = json_decode($data['followed_by_history_30'], true); $profile['followed_by_grow']['grow_1'] = $this->formatGrow($data['followed_by_grow_1'], $data['followed_by_count']); $profile['followed_by_grow']['grow_7'] = $this->formatGrow($data['followed_by_grow_7'], $data['followed_by_count']); $profile['followed_by_grow']['grow_15'] = $this->formatGrow($data['followed_by_grow_15'], $data['followed_by_count']); $profile['followed_by_grow']['grow_30'] = $this->formatGrow($data['followed_by_grow_30'], $data['followed_by_count']); $profile['most_mentions'] = json_decode($data['most_mentions'], true); $profile['most_hashtags'] = json_decode($data['most_hashtags'], true); $profile['last_post'] = json_decode($data['last_post'], true); Cache::put($var_cache, $profile, 1440); } else { return 'Invalid method'; } } return Cache::get($var_cache); }
public function getProfile($username) { $var_cache = 'instagramProfile' . $username; //if (!Cache::has($var_cache)) { if (true) { $data = InstagramProfile::whereUsername($username)->first(); if ($data) { $profile = NULL; $profile['username'] = strtolower($data['username']); $profile['name'] = !empty($data['name']) ? $data['name'] : $data['username']; $profile['bio'] = $data['bio']; $profile['website'] = $data['website']; $profile['picture'] = str_replace('_normal.', '.', $data['picture']); $auxformat = explode("-", $data['in_owloo_from']); $year = $auxformat[0]; $day = $auxformat[2]; $month = strtoupper($this->getMonth($auxformat[1], 'large')); $profile['in_owloo_from'] = substr($month, 0, 3) . substr($year, 2, 2); $profile['followed_by_count'] = $this->owloo_number_format($data['followed_by_count']); $profile['followed_by_count_str'] = $this->owloo_number_format_str($data['followed_by_count']); $profile['follows_count'] = $this->owloo_number_format($data['follows_count']); $profile['follows_count_str'] = $this->owloo_number_format_str($data['follows_count']); $profile['media_count'] = $this->owloo_number_format($data['media_count']); $profile['media_count_str'] = $this->owloo_number_format_str($data['media_count']); $profile['general_ranking'] = $this->owloo_number_format($data['general_ranking']); $charts = json_decode($data['charts'], true); $charts = array('followers' => $this->owloo_chart_data_format($charts['followers'], true), 'daily_followers_grow' => $this->owloo_chart_data_format($charts['daily_followers_grow'], true), 'daily_following_grow' => $this->owloo_chart_data_format($charts['daily_following_grow'], true)); $profile['charts'] = $charts; $profile['followers_accumulate_down_30'] = $this->owloo_number_format($data['accumulate_down_30']); $profile['followed_by_grow']['grow_1'] = $this->formatGrow($data['followed_by_grow_1'], $data['followed_by_count']); $profile['followed_by_grow']['grow_7'] = $this->formatGrow($data['followed_by_grow_7'], $data['followed_by_count']); $profile['followed_by_grow']['grow_15'] = $this->formatGrow($data['followed_by_grow_15'], $data['followed_by_count']); $profile['followed_by_grow']['grow_30'] = $this->formatGrow($data['followed_by_grow_30'], $data['followed_by_count']); $most_mentions = json_decode($data['most_mentions'], true); $profile['most_hashtags'] = json_decode($data['most_hashtags'], true); $limit = count($profile['most_hashtags']); $first_hashtag = NULL; $hashtags = array(); for ($i = 0; $i < $limit; $i++) { $profile['most_hashtags'][$i]['count'] = $this->owloo_number_format($profile['most_hashtags'][$i]['count']); $profile['most_hashtags'][$i]['class'] = ''; if ($i == 0) { $profile['most_hashtags'][$i]['class'] = 'big'; $first_hashtag = $profile['most_hashtags'][$i]; } else { $hashtags[] = $profile['most_hashtags'][$i]; if ($i == 3) { $hashtags[] = $first_hashtag; } } } $profile['most_hashtags'] = $hashtags; $limit = count($most_mentions); for ($i = 0; $i < $limit; $i++) { $most_mentions[$i]['count'] = $this->owloo_number_format($most_mentions[$i]['count']); if ($i < 2) { $most_mentions['big'][] = $most_mentions[$i]; } else { $most_mentions['normal'][] = $most_mentions[$i]; } } $profile['most_mentions'] = array('big' => $most_mentions['big'], 'normal' => $most_mentions['normal']); $profile['last_post'] = json_decode($data['last_post'], true); $profile['post_by_engagement_rate'] = json_decode($data['post_by_engagement_rate'], true); Cache::put($var_cache, $profile, 1440); } else { return 'Invalid method'; } } return Cache::get($var_cache); }