Пример #1
0
 /**
  * Returns total amount of results for any Google search,
  * requesting the deprecated Websearch API.
  *
  * @param string $url
  *        	String, containing the query URL.
  * @return integer Returns the total search result count.
  */
 public static function getSearchResultsTotal($url = false)
 {
     $url = parent::getUrl($url);
     $url = sprintf(JMapSeostatsServices::$GOOGLE_APISEARCH_URL, 1, $url);
     $ret = static::_getPage($url);
     $obj = json_decode($ret);
     return !isset($obj->responseData->cursor->estimatedResultCount) ? parent::noDataDefaultValue() : intval($obj->responseData->cursor->estimatedResultCount);
 }
Пример #2
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;
 }
Пример #3
0
 /**
  *
  * @access public
  * @return boolean
  */
 public function setUrl($url)
 {
     if (false !== JMapSeostatsHelperUrl::isRfc($url)) {
         self::$_url = $url;
         self::$_host = JMapSeostatsHelperUrl::parseHost($url);
     } else {
         throw new JMapException(JText::_('COM_JMAP_INVALID_URL'), 'error');
     }
     return true;
 }
Пример #4
0
 /**
  * Get the rank by country
  *
  * @access public
  * @static
  * @return int
  */
 public static function getCountryRank($url = false)
 {
     $xpath = self::_getXPath($url);
     $node1 = self::parseDomByXpaths($xpath, array("//*[@id='traffic-rank-content']/div/span[2]/div[2]/span/span/h4/a", "//*[@id='traffic-rank-content']/div/span[2]/div[2]/span/span/h4/strong/a"));
     $node2 = self::parseDomByXpaths($xpath, array("//*[@id='traffic-rank-content']/div/span[2]/div[2]/span/span/div/strong/a", "//*[@id='traffic-rank-content']/div/span[2]/div[2]/span/span/div/strong"));
     if (!is_null($node2) && $node2->item(0)) {
         $rank = self::retInt(strip_tags($node2->item(0)->nodeValue));
         if ($node1->item(0) && 0 != $rank) {
             return array('rank' => $rank, 'country' => $node1->item(0)->nodeValue);
         }
     }
     return parent::noDataDefaultValue();
 }