/**
  * 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;
 }
예제 #2
0
 /**
  * Atualiza os dados do twitter no banco de dados
  */
 public function updateTwitterAccountsApiAccessAction()
 {
     $this->view->disable();
     $tw_app_id = $this->request->getPost("app_id");
     $tw_app_secret = $this->request->getPost("app_secret");
     $tw_username = $this->request->getPost("username");
     $tw_active = $this->request->getPost("twitter_active") == 'on' ? true : false;
     $data['success'] = TwitterAccounts::updateTwitterAccount($tw_app_id, $tw_app_secret, $tw_username, $tw_active);
     echo json_encode($data);
 }