';
var $sitemapFileHeader;
var $sitemapFileBuffer = '';
var $sitemapxml_max_entrys;
var $sitemapxml_max_size;
var $timezone;
var $fb_maxsize = 4096;
var $fb = '';
var $fp = null;
var $fn = '';
var $time_ping;
var $statisticTotalTime = 0;
var $statisticTotalQueries = 0;
var $statisticTotalQueriesTime = 0;
var $statisticModuleTime = 0;
var $statisticModuleQueries = 0;
var $statisticModuleQueriesTime = 0;
function zen_SiteMapXML($inline=false, $ping=false, $rebuild=false, $genxml=true) {
global $db;
$this->statisticTotalTime = microtime(true);
$this->statisticTotalQueries = $db->count_queries;
$this->statisticTotalQueriesTime = $db->total_query_time;
$this->statisticModuleTime = microtime(true);
$this->statisticModuleQueries = $db->count_queries;
$this->statisticModuleQueriesTime = $db->total_query_time;
$this->sitemap = 'sitemap';
$this->videomap = 'videomap';
$this->sitemapindex = SITEMAPXML_SITEMAPINDEX . '.xml';
$this->compress = (SITEMAPXML_COMPRESS == 'true' ? true : false);
$this->duplicatedLinks = array();
$this->sitemapItems = array();
$this->dir_ws = trim(SITEMAPXML_DIR_WS);
$this->dir_ws = rtrim($this->dir_ws, '/');
if ($this->dir_ws != '') {
$this->dir_ws .= '/';
}
$this->savepath = DIR_FS_CATALOG . $this->dir_ws;
$this->savepathIndex = DIR_FS_CATALOG;
$this->base_url = HTTP_SERVER . DIR_WS_CATALOG . $this->dir_ws;
$this->base_url_index = HTTP_SERVER . DIR_WS_CATALOG;
$this->submit_url = utf8_encode(urlencode($this->base_url . $this->sitemapindex));
$this->submitFlag = true;
$this->inline = $inline;
$this->ping = $ping;
$this->rebuild = $rebuild;
$this->checkDublicates = SITEMAPXML_CHECK_DUBLICATES;
$db->Execute("DROP TABLE IF EXISTS " . TABLE_SITEMAPXML_TEMP);
if ($this->checkDublicates == 'mysql') {
$sql = "CREATE TABLE IF NOT EXISTS " . TABLE_SITEMAPXML_TEMP . " (
`url_hash` CHAR(32) NOT NULL ,
PRIMARY KEY (`url_hash`)
) ENGINE = MEMORY;";
$db->Execute($sql);
}
$this->checkurl = (SITEMAPXML_CHECK_URL == 'true' ? true : false);
$this->genxml = $genxml;
$this->sitemapFileFooter = '';
$this->sitemapFileBuffer = '';
$this->sitemapxml_max_entrys = SITEMAPXML_MAX_ENTRYS;
$this->sitemapxml_max_size = SITEMAPXML_MAX_SIZE-strlen($this->sitemapFileFooter);
global $lng;
if (!is_object($lng)) {
$lng = new language();
}
$this->languageSession = array(
'language' => $_SESSION['language'],
'languages_id' => $_SESSION['languages_id'],
'languages_code' => $_SESSION['languages_code'],
);
$languagesIDsArray = array();
foreach ($lng->catalog_languages as $language) {
$this->languages[$language['id']] = array(
'directory' => $language['directory'],
'id' => $language['id'],
'code' => $language['code'],
);
$languagesIDsArray [] = $language['id'];
if ($language['code'] == DEFAULT_LANGUAGE) {
$this->default_language_id = $language['id'];
}
}
if (SITEMAPXML_USE_ONLY_DEFAULT_LANGUAGE == 'true') {
$languagesIDsArray = array($this->default_language_id);
}
$this->languagesIDs = implode(',', $languagesIDsArray );
$this->languagesCount = sizeof($languagesIDsArray );
$this->sitemapItems = array();
$timezone = date('O');
$this->timezone = substr($timezone, 0, 3) . ':' . substr($timezone, 3, 2);
$this->magicSeo = false;
if (function_exists('unMagicSeoDoSeo')) {
$this->magicSeo = true;
}
if ($this->inline) {
ob_start();
}
$this->time_ping = time();
}
function SitemapOpen($file, $last_date=0, $type='sitemap') {
if (strlen($this->sitemapFileBuffer) > 0) $this->SitemapClose();
if (!$this->genxml) return false;
$this->sitemapFile = $file;
$this->sitemapType = $type;
$this->sitemapFileName = $this->_getNameFileXML($file);
if ($this->_checkFTimeSitemap($this->sitemapFileName, $last_date) == false) return false;
if ($file == 'index') {
$rc = $this->_fileOpen($this->sitemapFileName, $this->savepathIndex);
} else {
$rc = $this->_fileOpen($this->sitemapFileName);
}
if (!$rc) return false;
$this->_SitemapReSet();
$this->sitemapFileBuffer .= $this->_SitemapXMLHeader();
if ($file != 'index') {
$i = strpos($this->sitemapFileName, '.');
$name = substr($this->sitemapFileName, 0, $i);
$ext = substr($this->sitemapFileName, $i);
if ($sitemapFiles = glob($this->savepath . $name . '*' . $ext)) {
foreach ($sitemapFiles as $fn) {
if ($fn == $this->savepath . $this->sitemapFileName) continue;
if (preg_match('@^' . preg_quote($this->savepath . $name) . '([\d]{3})' . preg_quote($ext) . '$@', $fn, $m) && filesize($fn) > 0) {
if ($this->dir_ws != '') {
unlink($fn);
} else {
$fp = fopen($fn, 'w');
fclose($fp);
}
}
}
}
}
return true;
}
function SitemapSetMaxItems($maxItems) {
$this->sitemapFileItemsMax = $maxItems;
return true;
}
function writeItem($link, $parms='', $language_id=0, $lastmod='', $changefreq='', $xtra='') {
if ($lastmod != '') {
$lastmod = strtotime($lastmod);
}
$langParm = $this->getLanguageParameter($language_id);
if ($langParm !== false) {
$_SESSION['language'] = $this->languages[$language_id]['directory'];
$_SESSION['languages_id'] = $this->languages[$language_id]['id'];
$_SESSION['languages_code'] = $this->languages[$language_id]['code'];
if (substr($link, 0, 7) != 'http://' && substr($link, 0, 8) != 'https://') {
if ($parms != '' && $langParm != '') {
$langParm = '&' . $langParm;
}
$link = zen_href_link($link, $parms . $langParm, 'NONSSL', false);
} else {
if ($langParm != '') {
$langParm = (strpos($link, '?') === false ? '?' . $langParm : '&' . $langParm);
}
}
$_SESSION['language'] = $this->languageSession['language'];
$_SESSION['languages_id'] = $this->languageSession['languages_id'];
$_SESSION['languages_code'] = $this->languageSession['languages_code'];
$this->SitemapWriteItem($link, $lastmod, $changefreq, $xtra);
}
}
function SitemapWriteItem($loc, $lastmod='', $changefreq='', $xtra='') {
$time_now = time();
if ($this->time_ping >= $time_now + 30) {
$this->time_ping = $time_now;
header('X-pmaPing: Pong');
}
if (!$this->genxml) return false;
if ($this->magicSeo) {
$href = '
loc';
$out = unMagicSeoDoSeo($href);
$loc = substr($out, 21, -23);
}
if (!$this->_checkDublicateLoc($loc)) return false;
if ($this->checkurl) {
if (!($info = $this->_curlExecute($loc, 'header')) || $info['http_code'] != 200) return false;
}
$itemRecord = '';
$itemRecord .= ' ' . "\n";
$itemRecord .= ' ' . utf8_encode($loc) . '' . "\n";
if (isset($lastmod) && zen_not_null($lastmod) && (int)$lastmod > 0) {
$itemRecord .= ' ' . $this->_LastModFormat($lastmod) . '' . "\n";
}
if (zen_not_null($changefreq) && $changefreq != 'no') {
$itemRecord .= ' ' . $changefreq . '' . "\n";
}
if ($this->sitemapFileItemsMax > 0) {
$itemRecord .= ' ' . number_format(max((($this->sitemapFileItemsMax-$this->sitemapFileItemsTotal)/$this->sitemapFileItemsMax), 0.10), 2, '.', '') . '' . "\n";
}
if (isset($xtra) && zen_not_null($xtra)) {
$itemRecord .= $xtra;
}
$itemRecord .= ' ' . "\n";
if ($this->sitemapFileItems >= $this->sitemapxml_max_entrys || $this->sitemapFileSize+strlen($itemRecord) >= $this->sitemapxml_max_size) {
$this->_SitemapCloseFile();
$this->sitemapFileName = $this->_getNameFileXML($this->sitemapFile . str_pad($this->sitemapFileNameNumber, 3, '0', STR_PAD_LEFT));
if (!$this->_fileOpen($this->sitemapFileName)) return false;
$this->_SitemapReSetFile();
$this->sitemapFileBuffer .= $this->_SitemapXMLHeader();
}
$this->sitemapFileBuffer .= $itemRecord;
$this->_fileWrite($this->sitemapFileBuffer);
$this->sitemapFileSize += strlen($this->sitemapFileBuffer);
$this->sitemapFileSizeTotal += strlen($this->sitemapFileBuffer);
$this->sitemapFileItems++;
$this->sitemapFileItemsTotal++;
$this->sitemapFileBuffer = '';
return true;
}
function SitemapClose() {
global $db;
$this->_SitemapCloseFile();
if ($this->sitemapFileItemsTotal > 0) {
$total_time = microtime(true) - $this->statisticModuleTime;
$total_queries = $db->count_queries - $this->statisticModuleQueries;
$total_queries_time = $db->total_query_time - $this->statisticModuleQueriesTime;
echo sprintf(TEXT_TOTAL_SITEMAP, ($this->sitemapFileNameNumber+1), $this->sitemapFileItemsTotal, $this->sitemapFileSizeTotal, $this->timefmt($total_time), $total_queries, $this->timefmt($total_queries_time)) . '
';
}
$this->_SitemapReSet();
}
// generate sitemap index file
function GenerateSitemapIndex() {
global $db;
if ($this->genxml) {
echo '' . TEXT_HEAD_SITEMAP_INDEX . '
';
$this->SitemapOpen('index', 0, 'index');
$records_count = 0;
$sitemapFiles = array();
if ($files = glob($this->savepath . $this->sitemap . '*' . '.xml')) {
$sitemapFiles = array_merge($sitemapFiles, $files);
}
if ($files = glob($this->savepath . $this->sitemap . '*' . '.xml.gz')) {
$sitemapFiles = array_merge($sitemapFiles, $files);
}
clearstatcache();
foreach ($sitemapFiles as $filename) {
$filenameBase = basename($filename);
if ($filenameBase != $this->sitemapindex && filesize($filename) > 0) {
$fileURL = $this->base_url . $filenameBase;
echo TEXT_INCLUDE_FILE . $filename . ' (' . $fileURL . ')' . '
';
$itemRecord = '';
$itemRecord .= ' ' . "\n";
$itemRecord .= ' ' . $fileURL . '' . "\n";
$itemRecord .= ' ' . $this->_LastModFormat(filemtime($filename)) . '' . "\n";
$itemRecord .= ' ' . "\n";
$this->sitemapFileBuffer .= $itemRecord;
$this->_fileWrite($this->sitemapFileBuffer);
$this->sitemapFileSize += strlen($this->sitemapFileBuffer);
$this->sitemapFileSizeTotal += strlen($this->sitemapFileBuffer);
$this->sitemapFileItems++;
$this->sitemapFileItemsTotal++;
$this->sitemapFileBuffer = '';
}
}
$data = '';
$this->sitemapFileSizeTotal += strlen($data);
$this->_fileWrite($data);
$this->_fileClose();
echo TEXT_URL_FILE . '' . $this->base_url_index . $this->sitemapFileName . '' . '
';
echo sprintf(TEXT_WRITTEN, $this->sitemapFileItems++, $this->sitemapFileSizeTotal, filesize($this->savepathIndex . $this->sitemapFileName)) . '
';
}
$db->Execute("DROP TABLE IF EXISTS " . TABLE_SITEMAPXML_TEMP);
if ($this->checkDublicates == 'mysql') {
}
if ($this->inline) {
if ($this->submitFlag) {
ob_end_clean();
$this->_outputSitemapIndex();
} else {
ob_end_flush();
}
}
if ($this->ping) {
if ($this->inline) {
ob_start();
}
$this->_SitemapPing();
if ($this->inline) {
ob_end_clean();
}
}
if ($this->inline) {
die();
}
}
// retrieve full cPath from category ID
function GetFullcPath($cID) {
global $db;
static $parent_cache = array();
$cats = array();
$cats[] = $cID;
$sql = "SELECT parent_id, categories_id
FROM " . TABLE_CATEGORIES . "
WHERE categories_id=:categoriesID";
$sql = $db->bindVars($sql, ':categoriesID', $cID, 'integer');
$parent = $db->Execute($sql);
while (!$parent->EOF && $parent->fields['parent_id'] != 0) {
$parent_cache[(int)$parent->fields['categories_id']] = (int)$parent->fields['parent_id'];
$cats[] = $parent->fields['parent_id'];
if (isset($parent_cache[(int)$parent->fields['parent_id']])) {
$parent->fields['parent_id'] = $parent_cache[(int)$parent->fields['parent_id']];
} else {
$sql = "SELECT parent_id, categories_id
FROM " . TABLE_CATEGORIES . "
WHERE categories_id=:categoriesID";
$sql = $db->bindVars($sql, ':categoriesID', $parent->fields['parent_id'], 'integer');
$parent = $db->Execute($sql);
}
}
$cats = array_reverse($cats);
$cPath = implode('_', $cats);
return $cPath;
}
function setCheckURL($checkurl) {
$this->checkurl = $checkurl;
}
function setStylesheet($stylesheet) {
$this->stylesheet = $stylesheet;
}
function getLanguageParameter($language_id=0, $lang_parm='language') {
$code = '';
if (!isset($language_id) || $language_id == 0) {
$language_id = $this->default_language_id;
}
if (!isset($this->languages[$language_id]['code'])) {
return false;
}
if (SITEMAPXML_USE_LANGUAGE_PARM != 'false' && (($this->languages[$language_id]['code'] != DEFAULT_LANGUAGE && $this->languagesCount > 1) || SITEMAPXML_USE_LANGUAGE_PARM == 'all')) {
$code = $lang_parm . '=' . $this->languages[$language_id]['code'];
}
return $code;
}
function getLanguageDirectory($language_id) {
if (isset($this->languages[$language_id])) {
$directory = $this->languages[$language_id]['directory'];
} else {
$directory = false;
}
return $directory;
}
function getLanguagesIDs() {
return $this->languagesIDs;
}
function dbTableExist($table) {
global $db;
$exist = false;
if (defined($table)) {
$sql = "SHOW TABLES LIKE :tableName";
$sql = $db->bindVars($sql, ':tableName', constant($table), 'string');
$check_query = $db->Execute($sql);
if (!$check_query->EOF) {
$exist = true;
}
}
return $exist;
}
function dbColumnExist($table, $column) {
global $db;
$exist = false;
$sql = "SHOW COLUMNS FROM :tableName LIKE :columnName";
$sql = $db->bindVars($sql, ':tableName', $table, 'noquotestring');
$sql = $db->bindVars($sql, ':columnName', $column, 'string');
$check_query = $db->Execute($sql);
if (!$check_query->EOF) {
$exist = true;
}
return $exist;
}
function imagesTags($images, $caption='true', $license_url='') {
$tags = '';
foreach ($images as $image) {
$image['title'] = htmlspecialchars($image['title']);
$loc = HTTP_SERVER . DIR_WS_CATALOG . $image['file'];
$tags .= ' ' . "\n";
$tags .= ' ' . $this->_clear_url($loc) . '' . "\n";
if ($caption == 'true') {
$tags .= ' ' . $image['title'] . '' . "\n";
$tags .= ' ' . $image['title'] . '' . "\n";
}
if ($license_url != '') {
if (substr($license_url, 0, 7) != 'http://' && substr($license_url, 0, 8) != 'https://') {
$license_url = HTTP_SERVER . DIR_WS_CATALOG . $license_url;
}
$tags .= ' ' . $this->_clear_url($license_url) . '' . "\n";
}
$tags .= ' ' . "\n";
}
return $tags;
}
/////////////////////////
function _checkFTimeSitemap($filename, $last_date=0) {
// TODO: Multifiles
if ($this->rebuild == true) return true;
if ($last_date == 0) return true;
clearstatcache();
if ( SITEMAPXML_USE_EXISTING_FILES == 'true'
&& file_exists($this->savepath . $filename)
&& (filemtime($this->savepath . $filename) >= strtotime($last_date))
&& filesize($this->savepath . $filename) > 0) {
echo '"' . $filename . '" ' . TEXT_FILE_NOT_CHANGED . '
';
return false;
}
return true;
}
function _getNameFileXML($filename) {
switch ($this->sitemapType) {
case 'index':
$filename = $this->sitemapindex;
break;
case 'video':
$filename = $this->videomap . $filename . '.xml' . ($this->compress ? '.gz' : '');
break;
case 'sitemap':
default:
$filename = $this->sitemap . $filename . '.xml' . ($this->compress ? '.gz' : '');
break;
}
return $filename;
}
// format the LastMod field
function _LastModFormat($date) {
if (SITEMAPXML_LASTMOD_FORMAT == 'full') {
return gmdate('Y-m-d\TH:i:s', $date) . $this->timezone;
} else {
return gmdate('Y-m-d', $date);
}
}
function _SitemapXMLHeader() {
$header = '';
$header .= '' . "\n";
$header .= ($this->stylesheet != '' ? 'stylesheet . '"?'.'>' . "\n" : "");
switch ($this->sitemapType) {
case 'index':
$header .= '' . "\n";
$header .= '' . "\n";
return $header;
}
function _SitemapPing() {
if ($this->submitFlag && SITEMAPXML_PING_URLS !== '') {
echo '' . TEXT_HEAD_PING . '
';
$pingURLs = explode(";", SITEMAPXML_PING_URLS);
foreach ($pingURLs as $pingURL) {
$pingURLarray = explode("=>", $pingURL);
if (!isset($pingURLarray[1])) $pingURLarray[1] = $pingURLarray[0];
$pingURLarray[0] = trim($pingURLarray[0]);
$pingURLarray[1] = trim($pingURLarray[1]);
$pingFullURL = sprintf($pingURLarray[1], $this->submit_url);
echo '' . TEXT_HEAD_PING . ' ' . $pingURLarray[0] . '
';
echo $pingFullURL . '
';
echo '';
if ($info = $this->_curlExecute($pingFullURL, 'page')) {
echo $this->_clearHTML($info['html_page']);
}
echo '
';
}
}
}
function _clearHTML($html) {
$html = str_replace(" ", " ", $html);
$html = preg_replace("@\s\s+@", " ", $html);
$html = preg_replace('@(.*)'.'head>@si', '', $html);
$html = preg_replace('@