Beispiel #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;
 }
Beispiel #2
0
 /**
  * Get the average rank over the week
  * 
  * @access public
  * @static  
  * @return int
  */
 public static function setRankingKeys($url = false)
 {
     $xpath = self::_getXPath($url);
     $nodes = @$xpath->query("//*[@id='rank']/table/tr");
     if (5 == $nodes->length) {
         self::$_rankKeys = array('1d' => 2, '7d' => 3, '1m' => 4, '3m' => 5);
     } else {
         if (4 == $nodes->length) {
             self::$_rankKeys = array('1d' => 0, '7d' => 2, '1m' => 3, '3m' => 4);
         } else {
             if (3 == $nodes->length) {
                 self::$_rankKeys = array('1d' => 0, '7d' => 0, '1m' => 2, '3m' => 3);
             } else {
                 if (2 == $nodes->length) {
                     self::$_rankKeys = array('1d' => 0, '7d' => 0, '1m' => 0, '3m' => 2);
                 }
             }
         }
     }
 }