/** * Get by remote Pingomatic server stats flash object, parse it * and get rid of undesired tags * * @access public * @return mixed HTML code only for object/embed tags */ public function getPingomaticStats(JMapHttp $httpClient) { // Detect uri scheme $instance = JUri::getInstance(); $this->urischeme = $instance->isSSL() ? 'https' : 'http'; // Get stats from remote URI $url = $this->urischeme . '://pingomatic.com/stats/'; // Try to get informations try { // Fake a user agent to avoid Pingomatic empty response $response = $httpClient->get($url, array('User-Agent' => 'Mozilla/5.0'))->body; if ($response) { // make links from relative to absolute $replacedResponse = preg_replace('/href="\\//i', 'href="' . $this->urischeme . '://pingomatic.com/', $response); $replacedResponse = preg_replace('/src="\\//i', 'src="' . $this->urischeme . '://pingomatic.com/', $replacedResponse); $replacedResponse = preg_replace('/charts.swf/i', $this->urischeme . '://pingomatic.com/stats/charts.swf', $replacedResponse); // Keep only object/embed tags $replacedResponse = strip_tags($replacedResponse, '<object>,<embed>'); preg_match('/(<object)([a-zA-Z0-9=\\-\\/\\.,<>\\?_\\&#:;"\\s]*)(<\\/object>)/im', $replacedResponse, $matches); if (isset($matches[0]) && $matches[0]) { return $matches[0]; } } } catch (JMapException $e) { return null; } catch (Exception $e) { return null; } }
/** * Get by remote server informations for new updates of this extension * * @access public * @return mixed An object json decoded from server if update information retrieved correctly otherwise false */ public function getUpdates(JMapHttp $httpClient) { // Updates server remote URI $option = $this->getState('option'); if (!$option) { return false; } $url = SERVER_REMOTE_URI . $option . UPDATES_FORMAT; // Try to get informations try { $response = $httpClient->get($url)->body; if ($response) { $decodedUpdateInfos = json_decode($response); } return $decodedUpdateInfos; } catch (JMapException $e) { return false; } catch (Exception $e) { return false; } }
/** * Main get data method * * @access public * @return Object[] */ public function getData() { // Load data from XML file, parse it to load records $cachedSitemapFilePath = JPATH_COMPONENT_ADMINISTRATOR . '/cache/analyzer/'; // Has sitemap some vars such as lang or Itemid? $sitemapLang = $this->getState('sitemaplang', ''); $sitemapLinksLang = $sitemapLang ? $sitemapLang . '/' : ''; $sitemapLang = $sitemapLang ? '_' . $sitemapLang : ''; $sitemapDataset = $this->getState('sitemapdataset', ''); $sitemapDataset = $sitemapDataset ? '_dataset' . (int) $sitemapDataset : ''; $sitemapItemid = $this->getState('sitemapitemid', ''); $sitemapItemid = $sitemapItemid ? '_menuid' . (int) $sitemapItemid : ''; // Final name $cachedSitemapFilename = 'sitemap_xml' . $sitemapLang . $sitemapDataset . $sitemapItemid . '.xml'; // Start processing try { // Now check if the file correctly exists if (JFile::exists($cachedSitemapFilePath . $cachedSitemapFilename)) { $loadedSitemapXML = simplexml_load_file($cachedSitemapFilePath . $cachedSitemapFilename); } else { throw new JMapException(JText::sprintf('COM_JMAP_ANALYZER_NOCACHED_FILE_EXISTS', $this->_db->getErrorMsg()), 'error'); } // Execute HTTP request and associate HTTP response code with each record links $httpClient = new JMapHttp(); if ($loadedSitemapXML->url->count()) { // Manage splice pagination here for the XML records $convertedIteratorToArray = iterator_to_array($loadedSitemapXML->url, false); // Store number of records for pagination $this->recordsNumber = count($convertedIteratorToArray); // Execute pagination splicing if any limit is set $limit = $this->getState('limit'); if ($limit) { $loadedSitemapXML = array_splice($convertedIteratorToArray, $this->getState('limitstart'), $this->getState('limit')); } else { $loadedSitemapXML = $convertedIteratorToArray; } // Now start the Analyzer $siteRouter = JRouterSite::getInstance('site', array('mode' => JROUTER_MODE_SEF)); if (version_compare(JVERSION, '3.4', '>=')) { JApplicationCms::getInstance('site')->loadLanguage(); } $headers = array('Accept' => 'text/html', 'User-Agent' => 'Googlebot-Image/1.0'); foreach ($loadedSitemapXML as $url) { $httpResponse = $httpClient->get($url->loc, $headers); $url->httpstatus = $httpResponse->code; // Find informations about the link, component and menu itemid if any, need a workaround to parse correctly from backend $baseAdmin = JURI::base(); $baseSite = str_replace('/administrator', '', $baseAdmin); $fakedUrl = str_replace($baseSite, $baseAdmin, $url->loc); $fakedUrl = str_replace($sitemapLinksLang, '', $fakedUrl); // Now instantiate and parse the faked url from backend, replacing the uri base it will be = site $uriObject = JURI::getInstance((string) $fakedUrl); $parseUri = $siteRouter->parse($uriObject); // Now augment the object to show informations $url->component = isset($parseUri['option']) ? $parseUri['option'] : JText::_('COM_JMAP_ANALYZER_NOINFO'); $url->menuId = isset($parseUri['Itemid']) ? $parseUri['Itemid'] : JText::_('COM_JMAP_ANALYZER_NOINFO'); $url->menuTitle = JText::_('COM_JMAP_ANALYZER_NOINFO'); // Translate human menu if (isset($parseUri['Itemid'])) { $query = "SELECT" . $this->_db->quoteName('title') . "\n FROM #__menu" . "\n WHERE " . $this->_db->quoteName('id') . " = " . (int) $parseUri['Itemid']; $menuTitle = $this->_db->setQuery($query)->loadResult(); $url->menuTitle = $menuTitle; } } // Perform array sorting if any $order = $this->getState('order', null); $jmapAnalyzerOrderDir = $this->getState('order_dir', 'asc'); if ($order == 'httpstatus') { function cmpAsc($a, $b) { return (int) $a->httpstatus < (int) $b->httpstatus ? -1 : 1; } function cmpDesc($a, $b) { return (int) $a->httpstatus > (int) $b->httpstatus ? -1 : 1; } $callbackName = $jmapAnalyzerOrderDir == 'asc' ? 'cmpAsc' : 'cmpDesc'; usort($loadedSitemapXML, $callbackName); } if ($order == 'link') { function cmpAsc($a, $b) { return strcmp($a->loc, $b->loc); } function cmpDesc($a, $b) { return strcmp($b->loc, $a->loc); } $callbackName = $jmapAnalyzerOrderDir == 'asc' ? 'cmpAsc' : 'cmpDesc'; usort($loadedSitemapXML, $callbackName); } } else { throw new JMapException(JText::sprintf('COM_JMAP_ANALYZER_EMPTY_SITEMAP', $this->_db->getErrorMsg()), 'notice'); } } catch (JMapException $e) { $this->app->enqueueMessage($e->getMessage(), $e->getErrorLevel()); $loadedSitemapXML = array(); } catch (Exception $e) { $jmapException = new JMapException($e->getMessage(), 'error'); $this->app->enqueueMessage($jmapException->getMessage(), $jmapException->getErrorLevel()); $loadedSitemapXML = array(); } return $loadedSitemapXML; }