psCacheWarmer
".$this->_getSitemapUrl()."
---
";
if($this->_checkAuthentification()) {
$aUrls = $this->_getSitemapContent();
if(!empty(Registry::getConfig()->getShopConfVar('psCacheWarmerSitemapUrl')) && count($aUrls) > 0) {
foreach($aUrls as $sUrl) {
$oCurl = curl_init();
curl_setopt($oCurl, CURLOPT_URL, $sUrl);
curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($oCurl, CURLOPT_CONNECTTIMEOUT, 25);
curl_setopt($oCurl, CURLOPT_HEADER, true);
$sUsername = Registry::getConfig()->getShopConfVar('psCacheWarmerUser');
$sPassword = Registry::getConfig()->getShopConfVar('psCacheWarmerPass');
curl_setopt($oCurl, CURLOPT_USERPWD, $sUsername . ":" . $sPassword);
curl_exec($oCurl);
$httpStatus = curl_getinfo($oCurl, CURLINFO_HTTP_CODE);
if(curl_error($oCurl)) {
$sMessage .= 'ERROR '.$httpStatus.': ' . curl_error($oCurl) . '
';
} else {
if(trim($httpStatus) == '500')
{
$sMessage .= 'ERROR '.$httpStatus.': ' . $sUrl. '
';
}
else{
$sMessage .= 'OK '.$httpStatus.': ' . $sUrl . '
';
}
}
curl_close($oCurl);
}
} else {
$sMessage .= 'Keine Daten vorhanden!';
}
} else {
$sMessage .= 'Authentifizierung fehlgeschlagen!';
}
echo '
'.$sMessage.''; exit; } /** * Returens urls from sitemap * * @return array urls */ protected function _getSitemapContent($sSitemapUrl = "") { $aUrls = array(); if(empty($sSitemapUrl)) { $sSitemapUrl = $this->_getSitemapUrl(); } $sUsername = Registry::getConfig()->getShopConfVar('psCacheWarmerUser'); $sPassword = Registry::getConfig()->getShopConfVar('psCacheWarmerPass'); $sSitemapUrl = str_replace("://", "://".$sUsername.":".$sPassword."@", $sSitemapUrl); $sSitemapXmlData = @file_get_contents($sSitemapUrl); if($oSitemap = @simplexml_load_string($sSitemapXmlData)) { if (count($oSitemap->sitemap) > 0) { foreach ($oSitemap->sitemap as $oSubSitemap) { $sNextSitemapUrl = (string)$oSubSitemap->loc; $aUrls = array_merge($aUrls, $this->_getSitemapContent($sNextSitemapUrl)); } } if(count($oSitemap->url) > 0) { foreach($oSitemap->url as $oSitemapUrl) { $aUrls[] = (string)$oSitemapUrl->loc; } } } #print_r($aUrls); return $aUrls; } /** * Returens sitemap url * * @return string sitemap url */ protected function _getSitemapUrl() { $sSitemapUrl = Registry::getConfig()->getConfigParam('sShopURL'); $sSitemapUrl .= Registry::getConfig()->getShopConfVar('psCacheWarmerSitemapUrl'); return $sSitemapUrl; } /** * Checks authentification * * @return bool true|false */ protected function _checkAuthentification() { $oConfig = Registry::getConfig(); $sKey = Registry::getConfig()->getRequestParameter("key"); $sSavedKey = $oConfig->getShopConfVar('psCacheWarmerKey', $oConfig->getShopId()); if($sSavedKey == $sKey) { return true; } return false; } }