public function getPage($username) { if (!Cache::has('facebookPage' . $username)) { $data = FacebookPage::whereUsername($username)->first(); if ($data) { $page['username'] = strtolower($data['username']); $page['name'] = $data['name']; $page['about'] = $data['about']; $page['description'] = $data['description']; $page['link'] = $data['link']; $page['picture'] = 'http://graph.facebook.com/' . $data['fb_id'] . '/picture?height=50&type=normal&width=50'; $page['cover'] = $data['cover']; $page['is_verified'] = $data['is_verified']; $auxformat = explode("-", $data['in_owloo_from']); $year = $auxformat[0]; $day = $auxformat[2]; $month = strtolower($this->getMonth($auxformat[1], 'large')); $page['in_owloo_from'] = $day . ' ' . $month . ' ' . $year; $page['likes'] = $this->owloo_number_format($data['likes']); $page['likes_history_30'] = json_decode($data['likes_history_30'], true); $page['likes_history_30']['series_data'] = array_map(function ($n) { return intval($n); }, explode(",", $page['likes_history_30']['series_data'])); $page['likes_history_30']['x_axis'] = array_map(function ($n) { return str_replace("'", "", $n); }, explode(",", $page['likes_history_30']['x_axis'])); $page['likes_grow']['grow_1'] = $this->formatGrow($data['likes_grow_1'], $data['likes']); $page['likes_grow']['grow_7'] = $this->formatGrow($data['likes_grow_7'], $data['likes']); $page['likes_grow']['grow_15'] = $this->formatGrow($data['likes_grow_15'], $data['likes']); $page['likes_grow']['grow_30'] = $this->formatGrow($data['likes_grow_30'], $data['likes']); //$page['likes_grow']['grow_60'] = $this->formatGrow($data['likes_grow_60'], $data['likes']); $page['talking_about'] = $this->owloo_number_format($data['talking_about']); $page['talking_about_history_30'] = json_decode($data['talking_about_history_30'], true); //$page['talking_about_grow']['grow_1'] = $this->formatGrow($data['talking_about_grow_1'], $data['talking_about']); $page['talking_about_grow']['grow_7'] = $this->formatGrow($data['talking_about_grow_7'], $data['talking_about']); //$page['talking_about_grow']['grow_15'] = $this->formatGrow($data['talking_about_grow_15'], $data['talking_about']); $page['talking_about_grow']['grow_30'] = $this->formatGrow($data['talking_about_grow_30'], $data['talking_about']); //$page['talking_about_grow']['grow_60'] = $this->formatGrow($data['talking_about_grow_60'], $data['talking_about']); $page['pta'] = 0; if ($data['likes'] > 0) { $page['pta'] = $this->owlooFormatPorcent($data['talking_about'], $data['likes']); } if (!empty($data['country_code'])) { $page['location'] = true; $page['country']['code'] = strtolower($data['country_code']); $page['country']['name'] = $data['country_name']; //$page['country']['url_name'] = $this->convert_string_to_url($data['country_name_en']); $page['country']['ranking'] = $data['country_ranking']; $page['country']['audience'] = $this->owloo_number_format($data['country_audience']); } else { $page['location'] = false; $page['country']['code'] = strtolower($data['first_country_code']); $page['country']['name'] = $data['first_country_name']; //$page['country']['url_name'] = $this->convert_string_to_url($data['first_country_name_en']); $page['country']['ranking'] = $data['first_local_fans_country_ranking']; $page['country']['audience'] = $this->owloo_number_format($data['first_local_fans_country_audience']); } $page['first_country']['code'] = strtolower($data['first_country_code']); $page['first_country']['name'] = $data['first_country_name']; //$page['first_country']['url_name'] = $this->convert_string_to_url($data['first_country_name_en']); $page['first_country']['audience'] = $this->owloo_number_format($data['first_local_fans_country_audience']); $page['first_country']['ranking'] = $data['first_local_fans_country_ranking']; $page['category']['id'] = $data['category_id']; $page['category']['name'] = $data['category_name']; $page['sub_category']['id'] = $data['sub_category_id']; $page['sub_category']['name'] = $data['sub_category_name']; $page['general_ranking'] = $data['general_ranking']; $page['local_countries'] = array(); $local_countries = FacebookPageLocalFans::where('id_page', $data['id_page'])->orderBy('likes_local_fans', 'DESC')->get(['country_code', 'country_name', 'country_name_en', 'likes_local_fans']); foreach ($local_countries as $local_country) { if ($local_country['country_code'] == $data['first_country_code']) { $page['first_country']['likes'] = $this->owloo_number_format($local_country['likes_local_fans']); $page['first_country']['market_share_percent'] = $this->owlooFormatPorcent($local_country['likes_local_fans'], $data['first_local_fans_country_audience']); } if (strtolower($local_country['country_code']) == $page['country']['code']) { $page['country']['likes'] = $this->owloo_number_format($local_country['likes_local_fans']); $page['country']['market_share_percent'] = $this->owlooFormatPorcent($local_country['likes_local_fans'], $data['country_audience']); } $page['local_countries'][] = array('code' => strtolower($local_country['country_code']), 'name' => $local_country['country_name'], 'likes' => $this->owloo_number_format($local_country['likes_local_fans']), 'likes_percent' => $this->owlooFormatPorcent($local_country['likes_local_fans'], $data['likes'])); } Cache::put('facebookPage' . $username, $page, 1440); } else { return 'Invalid method'; } } return Cache::get('facebookPage' . $username); }
public function getPage($username) { $var_cache = 'facebookPage' . ucfirst($username); // if (!Cache::has($var_cache)) { if (true) { $data = FacebookPage::whereUsername($username)->first(); if ($data) { $page['username'] = strtolower($data['username']); $page['name'] = $data['name']; $page['about'] = $data['about']; $page['description'] = $data['description']; $page['link'] = $data['link']; $page['picture'] = 'http://graph.facebook.com/' . $data['fb_id'] . '/picture?height=200&type=normal&width=200'; $page['cover'] = $data['cover']; $page['is_verified'] = $data['is_verified']; $auxformat = explode("-", $data['in_owloo_from']); $year = $auxformat[0]; $day = $auxformat[2]; $month = strtolower($this->getMonth($auxformat[1], 'large')); $page['in_owloo_from'] = $day . ' ' . $month . ' ' . $year; $page['likes'] = $this->owloo_number_format($data['likes']); $page['likes_str'] = $this->owloo_number_format_str($data['likes']); $charts = json_decode($data['charts'], true); $charts = array('likes' => $this->owloo_chart_data_format($charts['likes'], true), 'daily_likes_grow' => $this->owloo_chart_data_format($charts['daily_likes_grow'], true), 'talking_about' => $this->owloo_chart_data_format($charts['talking_about'], true)); $accumulate_down_30 = $charts['likes']['accumulate_down']; unset($charts['likes']['accumulate_down']); $page['charts'] = $charts; $page['likes_grow']['grow_1'] = $this->formatGrow($data['likes_grow_1'], $data['likes']); $page['likes_grow']['grow_7'] = $this->formatGrow($data['likes_grow_7'], $data['likes']); $page['likes_grow']['grow_15'] = $this->formatGrow($data['likes_grow_15'], $data['likes']); $page['likes_grow']['grow_30'] = $this->formatGrow($data['likes_grow_30'], $data['likes']); //$page['likes_grow']['grow_60'] = $this->formatGrow($data['likes_grow_60'], $data['likes']); $page['accumulate_down_30'] = $this->formatGrow($accumulate_down_30, $data['likes']); $page['talking_about'] = $this->owloo_number_format($data['talking_about']); //$page['talking_about_grow']['grow_1'] = $this->formatGrow($data['talking_about_grow_1'], $data['talking_about']); $page['talking_about_grow']['grow_7'] = $this->formatGrow($data['talking_about_grow_7'], $data['talking_about']); //$page['talking_about_grow']['grow_15'] = $this->formatGrow($data['talking_about_grow_15'], $data['talking_about']); $page['talking_about_grow']['grow_30'] = $this->formatGrow($data['talking_about_grow_30'], $data['talking_about']); //$page['talking_about_grow']['grow_60'] = $this->formatGrow($data['talking_about_grow_60'], $data['talking_about']); $page['pta'] = 0; if ($data['likes'] > 0) { $page['pta'] = $this->owlooFormatPorcent($data['talking_about'], $data['likes']); } if (!empty($data['country_code'])) { $page['location'] = true; $page['country']['code'] = strtolower($data['country_code']); $page['country']['name'] = $data['country_name']; //$page['country']['slug'] = $data['slug']; $page['country']['ranking'] = $data['country_ranking']; $page['country']['audience'] = $this->owloo_number_format($data['country_audience']); } else { $page['location'] = false; $page['country']['code'] = strtolower($data['first_country_code']); $page['country']['name'] = $data['first_country_name']; //$page['country']['slug'] = $data['first_country_slug']; $page['country']['ranking'] = $data['first_local_fans_country_ranking']; $page['country']['audience'] = $this->owloo_number_format($data['first_local_fans_country_audience']); } $page['first_country']['code'] = strtolower($data['first_country_code']); $page['first_country']['name'] = $data['first_country_name']; //$page['first_country']['slug'] = $data['first_country_slug']; $page['first_country']['audience'] = $this->owloo_number_format($data['first_local_fans_country_audience']); $page['first_country']['ranking'] = $data['first_local_fans_country_ranking']; $page['category']['id'] = $data['category_id']; $page['category']['name'] = $data['category_name']; $page['sub_category']['id'] = $data['sub_category_id']; $page['sub_category']['name'] = $data['sub_category_name']; $page['general_ranking'] = $this->owloo_number_format($data['general_ranking']); $page['local_countries'] = array(); $local_countries = FacebookPageLocalFans::where('id_page', $data['id_page'])->orderBy('likes_local_fans', 'DESC')->get(['country_code', 'country_name', 'country_slug', 'likes_local_fans']); foreach ($local_countries as $local_country) { if ($local_country['country_code'] == $data['first_country_code']) { $page['first_country']['likes'] = $this->owloo_number_format($local_country['likes_local_fans']); $page['first_country']['market_share_percent'] = $this->owlooFormatPorcent($local_country['likes_local_fans'], $data['first_local_fans_country_audience']); } if (strtolower($local_country['country_code']) == $page['country']['code']) { $page['country']['likes'] = $this->owloo_number_format($local_country['likes_local_fans']); $page['country']['market_share_percent'] = $this->owlooFormatPorcent($local_country['likes_local_fans'], $data['country_audience']); } $page['local_countries'][] = array('code' => strtolower($local_country['country_code']), 'name' => $local_country['country_name'], 'likes' => $this->owloo_number_format($local_country['likes_local_fans']), 'likes_percent' => $this->owlooFormatPorcent($local_country['likes_local_fans'], $data['likes'])); } Cache::put($var_cache, $page, 1440); } else { return 'Invalid method'; } } return Cache::get($var_cache); }