/** * Carrega a tela inicial, exibe gráficos informando sessões e localização de acessos */ public function indexAction() { $this->session->start(); if ($this->session->get("user_id") != NULL) { $vars = $this->getUserLoggedInformation(); $vars['menus'] = $this->getSideBarMenus(); $google_account = GoogleAccounts::findFirst(); if ($google_account->google_analytics_active) { $result_countries = Analytics::getCountryOriginAccess($google_account->google_account_login, $google_account->google_account_key_file_name); foreach ($result_countries as $id => $country) { $countries[$id] = $country[0]; $sessions_country[$id] = $country[1]; } $sessions = Analytics::getAccessPerMonth($google_account->google_account_login, $google_account->google_account_key_file_name); $vars['sessions'] = $sessions['sessions']; $vars['months'] = $sessions['months']; $vars['total_sessions'] = $sessions['total_sessions']; $vars['countries'] = $countries; $vars['sessions_country'] = $sessions_country; $vars['pageviews'] = Analytics::getPageViews($google_account->google_account_login, $google_account->google_account_key_file_name); } else { $vars['sessions'] = 0; $vars['total_sessions'] = 0; $vars['pageviews'] = 0; } if ($google_account->google_adsense_active) { $vars['earnings'] = Adsense::getEarnings($google_account->google_account_login, $google_account->google_account_key_file_name); } $this->view->setVars($vars); } }
/** * Busca no banco de dados informações sobre acessos ao blog (Google Analytics), * seguidores do Twitter (Twitter API) e curtidas da página do facebook informada; * Caso os dados sobre tais APIS e redes sociais não estejam configurados, todos os valores são retornados como 0 * @return array Array Contendo informações sobre Google Analytics, Twitter e Facebook */ public function getApiSocialsData() { //Dados do google analytics $google_account = GoogleAccounts::findFirst(); $vars['analytics_active'] = $google_account->google_analytics_active; if (!empty($google_account) && $google_account->google_analytics_active) { $data_analytics = Analytics::getAccessPerMonth($google_account->google_account_login, $google_account->google_account_key_file_name); $vars['sessions'] = $data_analytics['sessions']; $vars['months'] = $data_analytics['months']; $vars['total_sessions'] = $data_analytics['total_sessions']; } else { $vars['total_sessions'] = 0; $vars['months'] = $this->mountArrayMonths(); } //Dados do Twitter $tw_account = TwitterAccounts::findFirst(); $vars['tw_active'] = $tw_account->twitter_active; if (!empty($tw_account) && $tw_account->twitter_active) { $bearer_token = TwitterSdk::generateBearerToken($tw_account->twitter_account_app_id, $tw_account->twitter_account_app_secret); $data_twitter = TwitterSdk::getLookupTwitterProfileBlog($bearer_token, $tw_account->twitter_account_username); $vars['followers_count'] = $data_twitter[0]['followers_count']; } else { $vars['followers_count'] = 0; } //Dados do Facebook $fb_page = FacebookPages::findFirst(); $vars['fb_active'] = $fb_page->facebook_active; if (!empty($fb_page) && $fb_page->facebook_active) { $facebook = Facebook::facebookCount("https://www.facebook.com/" . $fb_page->facebook_page_name); $vars['facebook_likes'] = $facebook[0]['like_count']; } else { $vars['facebook_likes'] = 0; } return $vars; }