/**
  * 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;
 }
 /**
  * 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);
     }
 }
예제 #3
0
 /**
  * Atualiza os dados referente a API do google
  * @param  string $g_account email da conta informada
  * @param  $key_file_name Nome do arquivo de chave gerado pelo google
  * @param  $g_analytics_script script para verificação de acessos ao site pelo Google Analytics
  * @return boolean            true caso sucesso ou false caso ocorra alguma falha
  */
 public function updateGoogleAccount($g_account, $key_file_name, $g_analytics_script, $g_analytics_active, $g_adsense_active)
 {
     $google_account = GoogleAccounts::findFirst();
     $google_account->google_account_login = $g_account;
     $google_account->google_account_key_file_name = $key_file_name;
     $google_account->google_analytics_script = addslashes(htmlentities($g_analytics_script));
     $google_account->google_analytics_active = $g_analytics_active;
     $google_account->google_adsense_active = $g_adsense_active;
     $return = $google_account->save();
     return $return;
 }
예제 #4
0
 /**
  * Atualiza os dados da conta google no banco de dados
  */
 public function updateGoogleAccountsApiAccessAction()
 {
     $this->view->disable();
     $g_account = $this->request->getPost('g_account');
     if ($this->request->hasFiles() == true) {
         foreach ($this->request->getUploadedFiles() as $file) {
             $p12_key = $file;
         }
     }
     $g_script_analytics = $this->request->getPost("analytics_script");
     $g_analytics_active = $this->request->getPost("analytics_active") == 'on' ? true : false;
     $g_adsense_active = $this->request->getPost("adsense_active") == 'on' ? true : false;
     $google_account = GoogleAccounts::findFirst();
     $data['success'] = GoogleAccounts::updateGoogleAccount($g_account, $p12_key->getName(), $g_script_analytics, $g_analytics_active, $g_adsense_active);
     if ($data['success']) {
         //remove o arquivo antigo e insere o novo
         unlink(FOLDER_PROJECT . "keys/" . $google_account->google_account_key_file_name);
         $p12_key->moveTo(FOLDER_PROJECT . "keys/" . $p12_key->getName());
     }
     echo json_encode($data);
 }