public function process() { $code = $this->getProperty('code'); if (!empty($code)) { $client = $this->bigbrother->loadOAuth(); // https://developers.google.com/identity/protocols/OAuth2InstalledApp $authParams = array('code' => $code, 'redirect_uri' => 'urn:ietf:wg:oauth:2.0:oob', 'scope' => 'https://www.googleapis.com/auth/analytics.readonly', 'grant_type' => 'authorization_code'); $result = false; try { $result = $client->getAccessToken($this->bigbrother->oauthTokenEndpoint, 'authorization_code', $authParams); } catch (Exception $e) { $this->modx->log(modX::LOG_LEVEL_ERROR, 'Exception during getAccessToken: ' . $e->getMessage()); } if (is_array($result) && $result['code'] == 200) { $accessToken = $result['result']['access_token']; $refreshToken = $result['result']['refresh_token']; $expiresIn = $result['result']['expires_in']; $this->modx->getCacheManager()->set('access_token', $accessToken, $expiresIn, $this->bigbrother->cacheOptions); $this->bigbrother->updateOption('refresh_token', $refreshToken, 'text-password'); return $this->success('', array('text' => $this->modx->lexicon('bigbrother.authorize_success'))); } return $this->failure('Unable to complete oAuth2 flow: <pre>' . print_r($result, true) . '</pre>'); } return $this->failure('No code provided.'); }
public function process() { if (!$this->ga->loadOAuth()) { return $this->failure($this->modx->lexicon('bigbrother.err_load_oauth')); } $result = $this->callAPI($this->ga->baseUrl . 'management/accounts/~all/webproperties/~all/profiles'); if (!empty($this->error)) { return $this->failure($this->error); } $output = $account = array(); $assign = $this->getProperty('assign', false); if ($assign) { $account['name'] = $this->modx->lexicon('bigbrother.user_account_default'); $account['id'] = $this->modx->lexicon('bigbrother.user_account_default'); $output[] = $account; } $total = 0; // Get account list foreach ($result['items'] as $value) { $account['id'] = $value['id']; $account['name'] = $value['name']; $account['websiteUrl'] = $value['websiteUrl']; $account['webPropertyId'] = $value['webPropertyId']; $output[] = $account; $total += 1; } //$this->ga->updateOption('total_account', $result['totalResults']); $this->ga->updateOption('total_account', $total); return $this->success('', $output); }
public function process() { $date = $this->ga->getDates(); $url = $this->ga->buildUrl($date['begin'], $date['end'], array('ga:date'), $this->metrics, array('-ga:visits')); $cacheKey = $this->ga->cacheKey; $fromCache = $this->modx->cacheManager->get($cacheKey); if (!empty($fromCache)) { return $this->success('Fetched data from cache', $fromCache, true); } if (!$this->ga->loadOAuth()) { return $this->failure('Could not load the OAuth file.'); } if (!$this->ga->getReport($url)) { return $this->failure($this->ga->getOutput()); } $this->formatData(); $date = $this->ga->getDates('Y-m-d', true); $url = $this->ga->buildUrl($date['begin'], $date['end'], null, $this->metrics, array('-ga:visits')); if (!$this->ga->getReport($url)) { return $this->failure($this->ga->getOutput()); } $this->compareData(); $this->modx->cacheManager->set($cacheKey, $this->output, $this->ga->getOption('cache_timeout')); return $this->success('Fetched data from Google', $this->output); }
public function process() { $date = $this->ga->getDates(); $beforeDate = $this->ga->getDates('Y-m-d', true); $url = $this->ga->buildUrl($date['begin'], $date['end'], array('ga:date'), $this->metrics); $cacheKey = md5($this->ga->cacheKey); $fromCache = $this->modx->cacheManager->get($cacheKey); if (!empty($fromCache)) { return $this->success('Fetched data from cache', $fromCache); } if (!$this->ga->loadOAuth()) { return $this->failure('Could not load the OAuth file.'); } if (!$this->ga->getReport($url)) { return $this->failure($this->ga->getOutput()); } $this->addSerie(); // Get the second area for comparion $url = $this->ga->buildUrl($beforeDate['begin'], $beforeDate['end'], array('ga:date'), $this->metrics); if (!$this->ga->getReport($url)) { return $this->failure($this->ga->getOutput()); } $this->addSerie(true); $this->modx->cacheManager->set($cacheKey, $this->series, $this->ga->getOption('cache_timeout')); return $this->success('Fetched data from Google', $this->series); }
public function process() { $date = $this->ga->getDates(); $url = $this->ga->buildUrl($date['begin'], $date['end'], $this->dimensions, $this->metrics, $this->sort); $cacheKey = $this->ga->cacheKey; $fromCache = $this->modx->cacheManager->get($cacheKey); if (!empty($fromCache)) { return $this->success('Fetched data from cache', $fromCache, true); } if (!$this->ga->loadOAuth()) { return $this->failure('Could not load the OAuth file.'); } if (!$this->ga->getReport($url)) { return $this->failure($this->ga->getOutput()); } $this->addSerie(); $this->modx->cacheManager->set($cacheKey, $this->series, $this->ga->getOption('cache_timeout')); return $this->success('Fetched data from Google', $this->series); }
public function process() { $date = $this->ga->getDates(); $url = $this->ga->buildUrl($date['begin'], $date['end'], $this->dimension, $this->metrics, array('-ga:visits'), $this->filters, $this->limit); $cacheKey = $this->ga->cacheKey; $fromCache = $this->modx->cacheManager->get($cacheKey); if (!empty($fromCache)) { return $this->success('Fetched data from cache', $fromCache, true); } if (!$this->ga->loadOAuth()) { return $this->failure('Could not load the OAuth file.'); } if (!$this->ga->getReport($url)) { return $this->failure($this->ga->getOutput()); } $this->visits = $this->ga->getTotalVisits($date['begin'], $date['end']); $response = $this->iterate(); $this->modx->cacheManager->set($cacheKey, $response, $this->ga->getOption('cache_timeout')); return $this->success('Fetched data from Google', $response); }