Пример #1
0
 protected function _fetchAccountsList()
 {
     $hClient =& Sh404sefHelperAnalytics::getHttpClient();
     $hClient->resetParameters($clearAll = true);
     // build the request
     $sefConfig = Sh404sefFactory::getConfig();
     $accountIdBits = explode('-', trim($sefConfig->analyticsId));
     if (empty($accountIdBits) || count($accountIdBits) < 3) {
         throw new Sh404sefExceptionDefault(JText::sprintf('COM_SH404SEF_ERROR_CHECKING_ANALYTICS', 'Invalid account Id'));
     }
     $accoundId = $accountIdBits[1];
     // set target API url
     $hClient->setUri($this->_endPoint . 'management/accounts/' . $accoundId . '/webproperties/' . trim($sefConfig->analyticsId) . '/profiles?key=' . $this->_getAppKey());
     // make sure we use GET
     $hClient->setMethod(Sh_Zend_Http_Client::GET);
     // set headers required by Google Analytics
     $headers = array('GData-Version' => 2, 'Authorization' => 'GoogleLogin auth=' . $this->_Auth);
     $hClient->setHeaders($headers);
     //perform request
     // establish connection with available methods
     $adapters = array('Sh_Zend_Http_Client_Adapter_Curl', 'Sh_Zend_Http_Client_Adapter_Socket');
     $rawResponse = null;
     // perform connect request
     foreach ($adapters as $adapter) {
         try {
             $hClient->setAdapter($adapter);
             $response = $hClient->request();
             break;
         } catch (Exception $e) {
             // need that to be Exception, so as to catch Sh_Zend_Exceptions.. as well
             // we failed, let's try another method
         }
     }
     // return if error
     if (empty($response)) {
         $msg = 'unknown code';
         throw new Sh404sefExceptionDefault(JText::sprintf('COM_SH404SEF_ERROR_CHECKING_ANALYTICS', $msg));
     }
     if (empty($response) || !is_object($response) || $response->isError()) {
         $msg = method_exists($response, 'getStatus') ? $response->getStatus() : 'unknown code';
         throw new Sh404sefExceptionDefault(JText::sprintf('COM_SH404SEF_ERROR_CHECKING_ANALYTICS', $msg));
     }
     // analyze response
     // check if authentified
     Sh404sefHelperAnalytics::verifyAuthResponse($response);
     $xml = simplexml_load_string($response->getBody());
     if (!empty($xml->entry)) {
         foreach ($xml->entry as $entry) {
             $account = new StdClass();
             $bits = explode('/', (string) $entry->id);
             $account->id = array_pop($bits);
             $account->title = str_replace('Google Analytics Profile ', '', (string) $entry->title);
             $this->_accounts[] = clone $account;
         }
     }
 }
 /**
  *
  * @param object $config
  * @param array $options
  * @param object $client
  */
 public function fetchData($config, $options, $Auth, $endPoint, $appKey)
 {
     // store parameters
     $this->_config = $config;
     $this->_options = $options;
     $this->_Auth = $Auth;
     $this->_endPoint = $endPoint;
     $this->_appKey = $appKey;
     // get a http client
     $this->_client =& Sh404sefHelperAnalytics::getHttpClient();
     // response object
     $this->_formatedResponse = new stdClass();
     // read data from Google
     $this->_getData();
     // processing of global data always happens
     $this->_addFiguresVisits();
     // call methods to create each of the report sub parts
     switch ($this->_options['subrequest']) {
         case 'visits':
             // create a graph of visits
             $this->_formatedResponse->images['visits'] = $this->_createVisitsGraph();
             break;
         case 'sources':
             // create a graph of traffic sources
             $this->_formatedResponse->images['sources'] = $this->_createSourcesGraph();
             break;
         case 'perf':
             $this->_addCustomVars();
             break;
         case 'top5referrers':
             $this->_addFiguresReferrers();
             break;
         case 'top5urls':
             $this->_addFiguresUrls();
             break;
         case 'topsocialfb':
             $this->_addFiguresSocialFB();
             break;
         case 'topsocialtweeter':
             $this->_addFiguresSocialTweeter();
             break;
         case 'topsocialpinterest':
             $this->_addFiguresSocialPinterest();
             break;
         case 'topsocialplusone':
             $this->_addFiguresSocialPlusOne();
             break;
         case 'topsocialplusonepage':
             $this->_addFiguresSocialPlusOnePage();
             break;
     }
     // send back to caller
     return $this->_formatedResponse;
 }
  /**
   * Connects to analytics supplier
   *
   * Meant to be overloaded by adapter
   *
   * @param $config , sef config object, holding connecton parameters
   */
  protected function _connect() {

    // get the http client
    $hClient = & Sh404sefHelperAnalytics::getHttpClient();

    // establish connection with available methods
    $adapters = array( 'Sh_Zend_Http_Client_Adapter_Curl', 'Sh_Zend_Http_Client_Adapter_Socket');
    $rawResponse = null;

    // perform connect request
    foreach( $adapters as $adapter) {
      try {
        $hClient->setAdapter( $adapter);
        $rawResponse = $hClient->request();
        break;
      } catch (Exception $e) {  // need that to be Exception, so as to catch Sh_Zend_Exceptions.. as well
        // we failed, let's try another method
        //echo '<br />exception in _connect' . $e->getMessage();
      }
    }

    // return if error
    if (empty( $rawResponse)) {
      $msg = 'unknown code';
      throw new Sh404sefExceptionDefault( JText::sprintf('COM_SH404SEF_ERROR_CHECKING_ANALYTICS', $msg));
    }
    if (!is_object( $rawResponse) || $rawResponse->isError()) {
      $msg = method_exists( $rawResponse, 'getStatus') ? $rawResponse->getStatus() : 'unknown code';
      throw new Sh404sefExceptionDefault( JText::sprintf('COM_SH404SEF_ERROR_CHECKING_ANALYTICS', $msg));
    }

    // success, return response
    return $rawResponse;

  }
Пример #4
0
 /**
  * Connects to analytics supplier
  *
  * Meant to be overloaded by adapter
  *
  * @param $config , sef config object, holding connecton parameters
  */
 protected function _connect()
 {
     // get the http client
     $hClient = Sh404sefHelperAnalytics::getHttpClient();
     // establish connection with available methods
     $adapters = array('Zendshl_Http_Client_Adapter_Curl', 'Zendshl_Http_Client_Adapter_Socket');
     $rawResponse = null;
     // perform connect request
     foreach ($adapters as $adapter) {
         try {
             $hClient->setAdapter($adapter);
             $rawResponse = $hClient->request();
             break;
         } catch (Exception $e) {
             // we failed, let's try another method
         }
     }
     // return if error
     if (empty($rawResponse)) {
         $msg = 'unknown code';
         ShlSystem_Log::debug('sh404sef', '%s::%s::%d: %s', __CLASS__, __METHOD__, __LINE__, JText::sprintf('COM_SH404SEF_ERROR_CHECKING_ANALYTICS', $msg));
         throw new Sh404sefExceptionDefault(JText::sprintf('COM_SH404SEF_ERROR_CHECKING_ANALYTICS', $msg));
     }
     if (!is_object($rawResponse) || $rawResponse->isError()) {
         $msg = method_exists($rawResponse, 'getStatus') ? $rawResponse->getStatus() : 'unknown code';
         ShlSystem_Log::debug('sh404sef', '%s::%s::%d: %s', __CLASS__, __METHOD__, __LINE__, JText::sprintf('COM_SH404SEF_ERROR_CHECKING_ANALYTICS', $msg));
         throw new Sh404sefExceptionDefault(JText::sprintf('COM_SH404SEF_ERROR_CHECKING_ANALYTICS', $msg));
     }
     // success, return response
     return $rawResponse;
 }