Esempio n. 1
0
 /**
  * Fetch SEO stats from remote services both Google and Alexa,
  * based on Seo stats lib that is able to calculate Google Page rank
  *
  *
  * @access private
  * @param Object[] $additionalModels Array for additional injected models type hinted by interface
  * @return Object
  */
 private function fetchSeoStats($additionalModels = null)
 {
     // Response JSON object
     $response = new stdClass();
     // Set the resulting array
     $pageRanksArray = array('googlerank' => JText::_('COM_JMAP_NA'), 'alexarank' => JText::_('COM_JMAP_NA'), 'alexabacklinks' => JText::_('COM_JMAP_NA'), 'alexapageloadtime' => JText::_('COM_JMAP_NA'), 'googleindexedlinks' => JText::_('COM_JMAP_NA'), 'alexagraph' => '');
     try {
         if (!function_exists('curl_init')) {
             throw new JMapException(JText::_('COM_JMAP_CURL_NOT_SUPPORTED'), 'error');
         }
         if (1 == ini_get('safe_mode') || 'on' === strtolower(ini_get('safe_mode'))) {
             throw new JMapException(JText::_('COM_JMAP_PHP_SAFEMODE_ON'), 'error');
         }
         // API REQUEST, define target URL, site default or custom url
         $siteUrl = JUri::root(false);
         $customUrl = JComponentHelper::getParams('com_jmap')->get('seostats_custom_link', null);
         $url = $customUrl ? $customUrl : $siteUrl;
         // Create a new SEOstats instance.
         $seostats = new JMapSeostats();
         // Bind the URL to the current SEOstats instance.
         if ($seostats->setUrl($url)) {
             $pageRanksArray['alexarank'] = JMapSeostatsServicesAlexa::getGlobalRank();
             $pageRanksArray['alexabacklinks'] = JMapSeostatsServicesAlexa::getBacklinkCount();
             $pageRanksArray['alexapageloadtime'] = JMapSeostatsServicesAlexa::getPageLoadTime();
             $pageRanksArray['alexagraph'] = JMapSeostatsServicesAlexa::getTrafficGraph(1, false, 800, 320, 12);
             $pageRanksArray['googlerank'] = JMapSeostatsServicesGoogle::getPageRank();
             $pageRanksArray['googleindexedlinks'] = JMapSeostatsServicesGoogle::getSiteindexTotal();
             // All completed succesfully
             $response->result = true;
             $response->seostats = $pageRanksArray;
         }
     } catch (JMapException $e) {
         $response->result = false;
         $response->exception_message = $e->getMessage();
         $response->errorlevel = $e->getErrorLevel();
         $response->seostats = $pageRanksArray;
         return $response;
     } catch (Exception $e) {
         $jmapException = new JMapException(JText::sprintf('COM_JMAP_ERROR_RETRIEVING_SEOSTATS', $e->getMessage()), 'error');
         $response->result = false;
         $response->exception_message = $jmapException->getMessage();
         $response->errorlevel = $e->getErrorLevel();
         $response->seostats = $pageRanksArray;
         return $response;
     }
     return $response;
 }