Ejemplo n.º 1
0
 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;
     }
 }
Ejemplo n.º 2
0
 public function getProfile($screen_name)
 {
     if (!Cache::has('twitterProfile' . $screen_name)) {
         $data = TwitterProfile::whereScreenName($screen_name)->first();
         if ($data) {
             $profile = NULL;
             $profile['screen_name'] = strtolower($data['screen_name']);
             $profile['name'] = $data['name'];
             $profile['description'] = $data['description'];
             $profile['picture'] = str_replace('_normal.', '.', $data['picture']);
             $profile['is_verified'] = $data['is_verified'];
             $profile['location'] = !empty($data['location']) ? $data['location'] : 'n/a';
             $profile['idiom'] = $this->getIdiom($data['idiom']);
             $auxformat = explode("-", $data['in_twitter_from']);
             $year = $auxformat[0];
             $day = $auxformat[2];
             $month = strtolower($this->getMonth($auxformat[1], 'large'));
             $profile['in_twitter_from'] = $day . ' ' . $month . ' ' . $year;
             $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['followers_count'] = $this->owloo_number_format($data['followers_count']);
             $profile['following_count'] = $this->owloo_number_format($data['following_count']);
             $profile['tweet_count'] = $this->owloo_number_format($data['tweet_count']);
             $profile['followers_history_30'] = json_decode($data['followers_history_30'], true);
             $cache['average_growth'] = $this->owloo_number_format($data['average_growth']);
             $profile['followers_grow']['grow_1'] = $this->formatGrow($data['followers_grow_1'], $data['followers_count']);
             $profile['followers_grow']['grow_7'] = $this->formatGrow($data['followers_grow_7'], $data['followers_count']);
             $profile['followers_grow']['grow_15'] = $this->formatGrow($data['followers_grow_15'], $data['followers_count']);
             $profile['followers_grow']['grow_30'] = $this->formatGrow($data['followers_grow_30'], $data['followers_count']);
             $profile['most_mentions'] = json_decode($data['most_mentions'], true);
             $profile['most_hashtags'] = json_decode($data['most_hashtags'], true);
             $profile['klout'] = json_decode($data['klout'], true);
             $profile['ff_ratio'] = 0;
             if ($data['following_count'] > 0) {
                 $profile['ff_ratio'] = $this->owlooFormatPorcent($data['followers_count'] / $data['following_count']);
             }
             Cache::put('twitterProfile' . $screen_name, $profile, 1440);
         } else {
             return 'Invalid method';
         }
     }
     return Cache::get('twitterProfile' . $screen_name);
 }
Ejemplo n.º 3
0
 public function getProfile($screen_name)
 {
     //if (!Cache::has('twitterProfile'.$screen_name)) {
     if (true) {
         $data = TwitterProfile::whereScreenName($screen_name)->first();
         if ($data) {
             $profile = NULL;
             $profile['screen_name'] = strtolower($data['screen_name']);
             $profile['name'] = $data['name'];
             $profile['description'] = $data['description'];
             $profile['picture'] = str_replace('_normal.', '.', $data['picture']);
             $profile['cover'] = $data['cover'];
             $profile['is_verified'] = $data['is_verified'];
             $profile['location'] = !empty($data['location']) ? $data['location'] : 'n/a';
             $profile['idiom'] = $this->getIdiom($data['idiom']);
             $auxformat = explode("-", $data['in_twitter_from']);
             $year = $auxformat[0];
             $day = $auxformat[2];
             $month = strtoupper($this->getMonth($auxformat[1], 'large'));
             $profile['in_twitter_from'] = substr($month, 0, 3) . substr($year, 2, 2);
             $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['followers_count'] = $this->owloo_number_format($data['followers_count']);
             $profile['followers_count_str'] = $this->owloo_number_format_str($data['followers_count']);
             $profile['following_count'] = $this->owloo_number_format($data['following_count']);
             $profile['following_count_str'] = $this->owloo_number_format_str($data['following_count']);
             $profile['tweet_count'] = $this->owloo_number_format($data['tweet_count']);
             $profile['tweet_count_str'] = $this->owloo_number_format_str($data['tweet_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), 'tweets_made_by_day' => $this->owloo_chart_data_format($charts['tweets_made_by_day'], true), 'tweets_made_by_day_of_the_week' => $this->owloo_chart_data_format($charts['tweets_made_by_day_of_the_week'], true));
             for ($i = 0; $i < count($charts['tweets_made_by_day_of_the_week']['x_axis']); $i++) {
                 $charts['tweets_made_by_day_of_the_week']['data'][] = array('name' => $charts['tweets_made_by_day_of_the_week']['x_axis'][$i], 'value' => $this->owloo_number_format($charts['tweets_made_by_day_of_the_week']['series_data'][$i]));
             }
             $profile['charts'] = $charts;
             $cache['average_growth'] = $this->owloo_number_format($data['average_growth']);
             $profile['followers_accumulate_down_30'] = $this->owloo_number_format($data['accumulate_down_30']);
             $profile['followers_grow']['grow_1'] = $this->formatGrow($data['followers_grow_1'], $data['followers_count']);
             $profile['followers_grow']['grow_1'] = $this->formatGrow($data['followers_grow_1'], $data['followers_count']);
             $profile['followers_grow']['grow_7'] = $this->formatGrow($data['followers_grow_7'], $data['followers_count']);
             $profile['followers_grow']['grow_15'] = $this->formatGrow($data['followers_grow_15'], $data['followers_count']);
             $profile['followers_grow']['grow_30'] = $this->formatGrow($data['followers_grow_30'], $data['followers_count']);
             $most_mentions = json_decode($data['most_mentions'], true);
             $profile['most_hashtags'] = json_decode($data['most_hashtags'], true);
             $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']);
             $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;
             $profile['klout'] = json_decode($data['klout'], true);
             $profile['ff_ratio']['value'] = 0;
             $profile['ff_ratio']['max_value'] = 100;
             if ($data['following_count'] > 0) {
                 $profile['ff_ratio']['value'] = $this->owlooFormatPorcent($data['followers_count'] / $data['following_count'], NULL, 2, '.', '');
                 if ($profile['ff_ratio']['value'] > 100) {
                     $profile['ff_ratio']['max_value'] = $profile['ff_ratio']['value'];
                 }
             }
             Cache::put('twitterProfile' . $screen_name, $profile, 1440);
         } else {
             return 'Invalid method';
         }
     }
     return Cache::get('twitterProfile' . $screen_name);
 }