Exemplo n.º 1
0
 /**
  * Main get data method, retrieve model data using the Google API
  * Search results are based on parsing of automated queries
  *
  * @access public
  * @return Object[]
  */
 public function getData()
 {
     // Check if it's a search by keyword
     $keyword = $this->getState('searchword', null);
     $serpSearch = $keyword ? $keyword : 'site:' . $this->getComponentParams()->get('seostats_custom_link', JUri::root(false));
     $customHeaders = array('countrytld' => $this->getState('countriestld', null), 'acceptlanguage' => $this->getState('acceptlanguage', null));
     try {
         if (!function_exists('curl_init')) {
             throw new JMapException(JText::_('COM_JMAP_CURL_NOT_SUPPORTED'), 'error');
         }
         $result = JMapSeostatsServicesGoogle::getSerps($serpSearch, $this->getState('limitstart', 0), $customHeaders);
         if (!$result) {
             throw new JMapException(JText::_('COM_JMAP_ERROR_RETRIEVING_INDEXING') . $this->_db->getErrorMsg(), 'notice');
         }
         $this->setState('serpsearch', $serpSearch);
     } catch (JMapException $e) {
         $this->app->enqueueMessage($e->getMessage(), $e->getErrorLevel());
         $result = array();
     } catch (Exception $e) {
         $jmapException = new JMapException($e->getMessage(), 'error');
         $this->app->enqueueMessage($jmapException->getMessage(), $jmapException->getErrorLevel());
         $result = array();
     }
     return $result;
 }
Exemplo n.º 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;
 }