コード例 #1
0
 /**
  * Execute the action
  *
  * @return	void
  */
 public function execute()
 {
     // call parent, this will probably add some general CSS/JS or other required files
     parent::execute();
     // fork is no longer authorized to collect analytics data
     if (BackendAnalyticsHelper::getStatus() == 'UNAUTHORIZED') {
         // remove all parameters from the module settings
         BackendModel::setModuleSetting($this->getModule(), 'session_token', null);
         BackendModel::setModuleSetting($this->getModule(), 'account_name', null);
         BackendModel::setModuleSetting($this->getModule(), 'table_id', null);
         BackendModel::setModuleSetting($this->getModule(), 'profile_title', null);
         // remove cache files
         BackendAnalyticsModel::removeCacheFiles();
         // clear tables
         BackendAnalyticsModel::clearTables();
         // return status
         $this->output(self::OK, array('status' => 'unauthorized', 'message' => BL::msg('Redirecting')), 'No longer authorized.');
     }
     // get data
     $this->getData();
     // get html
     $referrersHtml = $this->parseReferrers();
     $keywordsHtml = $this->parseKeywords();
     // return status
     $this->output(self::OK, array('status' => 'success', 'referrersHtml' => $referrersHtml, 'keywordsHtml' => $keywordsHtml, 'date' => BL::lbl('Today'), 'message' => BL::msg('RefreshedTrafficSources')), 'Data has been retrieved.');
 }
コード例 #2
0
 /**
  * Execute the action
  */
 public function execute()
 {
     parent::execute();
     // fork is no longer authorized to collect analytics data
     if (BackendAnalyticsHelper::getStatus() == 'UNAUTHORIZED') {
         // remove all parameters from the module settings
         BackendModel::setModuleSetting('analytics', 'session_token', null);
         BackendModel::setModuleSetting('analytics', 'account_name', null);
         BackendModel::setModuleSetting('analytics', 'table_id', null);
         BackendModel::setModuleSetting('analytics', 'profile_title', null);
         BackendAnalyticsModel::removeCacheFiles();
         BackendAnalyticsModel::clearTables();
         return;
     }
     $this->getData();
 }
コード例 #3
0
 /**
  * Execute the action
  *
  * @return	void
  */
 public function execute()
 {
     // call parent, this will probably add some general CSS/JS or other required files
     parent::execute();
     // fork is no longer authorized to collect analytics data
     if (BackendAnalyticsHelper::getStatus() == 'UNAUTHORIZED') {
         // remove all parameters from the module settings
         BackendModel::setModuleSetting('analytics', 'session_token', null);
         BackendModel::setModuleSetting('analytics', 'account_name', null);
         BackendModel::setModuleSetting('analytics', 'table_id', null);
         BackendModel::setModuleSetting('analytics', 'profile_title', null);
         // remove cache files
         BackendAnalyticsModel::removeCacheFiles();
         // clear tables
         BackendAnalyticsModel::clearTables();
         // stop here
         return;
     }
     // get data
     $this->getData();
 }
コード例 #4
0
 /**
  * Execute the action
  *
  * @return	void
  */
 public function execute()
 {
     // call parent, this will probably add some general CSS/JS or other required files
     parent::execute();
     // get parameters
     $page = trim(SpoonFilter::getPostValue('page', null, ''));
     $identifier = trim(SpoonFilter::getPostValue('identifier', null, ''));
     // validate
     if ($page == '' || $identifier == '') {
         $this->output(self::BAD_REQUEST, null, 'No page provided.');
     }
     // init vars
     $filename = BACKEND_CACHE_PATH . '/analytics/' . $page . '_' . $identifier . '.txt';
     // does the temporary file still exits?
     $status = SpoonFile::getContent($filename);
     // no file - create one
     if ($status === false) {
         // create file with initial counter
         SpoonFile::setContent($filename, 'missing1');
         // return status
         $this->output(self::OK, array('status' => false), 'Temporary file was missing. We created one.');
     }
     // busy status
     if (strpos($status, 'busy') !== false) {
         // get counter
         $counter = (int) substr($status, 4) + 1;
         // file's been busy for more than hundred cycles - just stop here
         if ($counter > 100) {
             // remove file
             SpoonFile::delete($filename);
             // return status
             $this->output(self::ERROR, array('status' => 'timeout'), 'Error while retrieving data - the script took too long to retrieve data.');
         }
         // change file content to increase counter
         SpoonFile::setContent($filename, 'busy' . $counter);
         // return status
         $this->output(self::OK, array('status' => 'busy'), 'Data is being retrieved. (' . $counter . ')');
     }
     // unauthorized status
     if ($status == 'unauthorized') {
         // remove file
         SpoonFile::delete($filename);
         // remove all parameters from the module settings
         BackendModel::setModuleSetting($this->getModule(), 'session_token', null);
         BackendModel::setModuleSetting($this->getModule(), 'account_name', null);
         BackendModel::setModuleSetting($this->getModule(), 'table_id', null);
         BackendModel::setModuleSetting($this->getModule(), 'profile_title', null);
         // remove cache files
         BackendAnalyticsModel::removeCacheFiles();
         // clear tables
         BackendAnalyticsModel::clearTables();
         // return status
         $this->output(self::OK, array('status' => 'unauthorized'), 'No longer authorized.');
     }
     // done status
     if ($status == 'done') {
         // remove file
         SpoonFile::delete($filename);
         // return status
         $this->output(self::OK, array('status' => 'done'), 'Data retrieved.');
     }
     // missing status
     if (strpos($status, 'missing') !== false) {
         // get counter
         $counter = (int) substr($status, 7) + 1;
         // file's been missing for more than ten cycles - just stop here
         if ($counter > 10) {
             // remove file
             SpoonFile::delete($filename);
             // return status
             $this->output(self::ERROR, array('status' => 'missing'), 'Error while retrieving data - file was never created.');
         }
         // change file content to increase counter
         SpoonFile::setContent($filename, 'missing' . $counter);
         // return status
         $this->output(self::OK, array('status' => 'busy'), 'Temporary file was still in status missing. (' . $counter . ')');
     }
     /* FALLBACK - SOMETHING WENT WRONG */
     // remove file
     SpoonFile::delete($filename);
     // return status
     $this->output(self::ERROR, array('status' => 'error'), 'Error while retrieving data.');
 }
コード例 #5
0
ファイル: settings.php プロジェクト: naujasdizainas/forkcms
 /**
  * Gets all the needed parameters to link a google analytics account to fork
  */
 private function getAnalyticsParameters()
 {
     $remove = SpoonFilter::getGetValue('remove', array('session_token', 'table_id'), null);
     // something has to be removed before proceeding
     if (!empty($remove)) {
         // the session token has te be removed
         if ($remove == 'session_token') {
             // remove all parameters from the module settings
             BackendModel::setModuleSetting($this->getModule(), 'session_token', null);
         }
         // remove all profile parameters from the module settings
         BackendModel::setModuleSetting($this->getModule(), 'account_name', null);
         BackendModel::setModuleSetting($this->getModule(), 'table_id', null);
         BackendModel::setModuleSetting($this->getModule(), 'profile_title', null);
         // remove cache files
         BackendAnalyticsModel::removeCacheFiles();
         // clear tables
         BackendAnalyticsModel::clearTables();
     }
     // get session token, account name, the profile's table id, the profile's title
     $this->sessionToken = BackendModel::getModuleSetting($this->getModule(), 'session_token', null);
     $this->accountName = BackendModel::getModuleSetting($this->getModule(), 'account_name', null);
     $this->tableId = BackendModel::getModuleSetting($this->getModule(), 'table_id', null);
     $this->profileTitle = BackendModel::getModuleSetting($this->getModule(), 'profile_title', null);
     // no session token
     if (!isset($this->sessionToken)) {
         $token = SpoonFilter::getGetValue('token', null, null);
         // a one time token is given in the get parameters
         if (!empty($token) && $token !== 'true') {
             // get google analytics instance
             $ga = BackendAnalyticsHelper::getGoogleAnalyticsInstance();
             // get a session token
             $this->sessionToken = $ga->getSessionToken($token);
             // store the session token in the settings
             BackendModel::setModuleSetting($this->getModule(), 'session_token', $this->sessionToken);
         }
     }
     // session id is present but there is no table_id
     if (isset($this->sessionToken) && !isset($this->tableId)) {
         // get google analytics instance
         $ga = BackendAnalyticsHelper::getGoogleAnalyticsInstance();
         // get all possible profiles in this account
         $this->profiles = $ga->getAnalyticsAccountList($this->sessionToken);
         // not authorized
         if ($this->profiles == 'UNAUTHORIZED') {
             // remove invalid session token
             BackendModel::setModuleSetting($this->getModule(), 'session_token', null);
             // redirect to the settings page without parameters
             $this->redirect(BackendModel::createURLForAction('settings'));
         } elseif (is_array($this->profiles)) {
             $tableId = SpoonFilter::getGetValue('table_id', null, null);
             // a table id is given in the get parameters
             if (!empty($tableId)) {
                 $profiles = array();
                 // set the table ids as keys
                 foreach ($this->profiles as $profile) {
                     $profiles[$profile['tableId']] = $profile;
                 }
                 // correct table id
                 if (isset($profiles[$tableId])) {
                     // save table id and account title
                     $this->tableId = $tableId;
                     $this->accountName = $profiles[$this->tableId]['accountName'];
                     $this->profileTitle = $profiles[$this->tableId]['title'];
                     $webPropertyId = $profiles[$this->tableId]['webPropertyId'];
                     // store the table id and account title in the settings
                     BackendModel::setModuleSetting($this->getModule(), 'account_name', $this->accountName);
                     BackendModel::setModuleSetting($this->getModule(), 'table_id', $this->tableId);
                     BackendModel::setModuleSetting($this->getModule(), 'profile_title', $this->profileTitle);
                     BackendModel::setModuleSetting($this->getModule(), 'web_property_id', $webPropertyId);
                 }
             }
         }
     }
 }