AVE.CMS v3.28
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

193 lines
5.5 KiB

7 years ago
<?php
7 years ago
/**
* AVE.cms
*
* @package AVE.cms
* @version 3.x
* @filesource
* @copyright © 2007-2014 AVE.cms, http://www.ave-cms.ru
*
* @license GPL v.2
*/
7 years ago
7 years ago
define ('START_MICROTIME', microtime());
7 years ago
7 years ago
define ('BASE_DIR', str_replace("\\", "/", rtrim($_SERVER['DOCUMENT_ROOT'], '/')));
7 years ago
5 years ago
define ('USE_STATIC_DATA', false);
7 years ago
if (! @filesize(BASE_DIR . '/config/db.config.php'))
7 years ago
{
7 years ago
header ('Location: Location:install/index.php');
7 years ago
exit;
}
7 years ago
7 years ago
if (substr($_SERVER['REQUEST_URI'], 0, strlen('/index.php?')) != '/index.php?')
7 years ago
$_SERVER['REQUEST_URI'] = str_ireplace('_','-',$_SERVER['REQUEST_URI']);
7 years ago
7 years ago
require_once (BASE_DIR . '/inc/init.php');
7 years ago
7 years ago
$abs_path = str_ireplace(BASE_DIR, '/', str_replace("\\", "/", dirname(dirname(__FILE__))));
7 years ago
7 years ago
// Проверяем настройку на публикацию документов
7 years ago
$publish = get_settings('use_doctime')
7 years ago
? 'AND doc.document_published < UNIX_TIMESTAMP() AND doc.document_expire > UNIX_TIMESTAMP()'
7 years ago
: '';
7 years ago
7 years ago
// Начало
$_start = 0;
// Конец
$_end = 2000;
// Часть
$parts = 1;
7 years ago
$changefreq = array(
'0' => 'always',
'1' => 'hourly',
'2' => 'daily',
'3' => 'weekly',
'4' => 'monthly',
'5' => 'yearly',
'6' => 'never'
);
7 years ago
if (! isset($_REQUEST['id'])):
7 years ago
// Вытаскиваем кол-во документов
$sql = "
7 years ago
SELECT STRAIGHT_JOIN
7 years ago
COUNT(doc.Id) AS count
7 years ago
FROM
7 years ago
" . PREFIX . "_documents AS doc
7 years ago
LEFT JOIN
7 years ago
" . PREFIX . "_rubrics AS rub
7 years ago
ON rub.Id = doc.rubric_id
LEFT JOIN
7 years ago
" . PREFIX . "_rubric_templates AS tmpl
ON tmpl.rubric_id = rub.Id
LEFT JOIN
" . PREFIX . "_rubric_permissions AS rubperm
ON rubperm.rubric_id = rub.Id
7 years ago
WHERE
7 years ago
# Не пустой шаблон
(rub.rubric_template NOT LIKE '' OR tmpl.template NOT LIKE '')
# Статус документа = 1
7 years ago
AND doc.document_status = 1
7 years ago
# Документ не удален
7 years ago
AND doc.document_deleted = 1
$publish
7 years ago
# Документ не равен 1
AND doc.Id != 1
# Документ не равен 404 ошибке
7 years ago
AND doc.Id != " . PAGE_NOT_FOUND_ID . "
7 years ago
# Документы разрешены для индексации
7 years ago
AND (document_meta_robots NOT LIKE '%noindex%' or document_meta_robots NOT LIKE '%nofollow%')
7 years ago
# Разрешены для просмотра гостям
7 years ago
AND (rubperm.user_group_id = 2 AND rubperm.rubric_permission LIKE '%docread%')
";
7 years ago
$num = $AVE_DB->Query($sql, SITEMAP_CACHE_LIFETIME, 'sitemap')->GetCell();
7 years ago
if ($num > $_end)
$parts = ceil($num/$_end);
7 years ago
header ('Content-type: text/xml');
7 years ago
echo '<?xml version="1.0" encoding="UTF-8"?>' . PHP_EOL;
echo '<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . PHP_EOL;
for ($i = 1; $i <= $parts; $i++):
?>
<sitemap>
7 years ago
<loc><?php echo HOST . '/sitemap-' . $i . '.xml'; ?></loc>
<lastmod><?php echo date("c"); ?></lastmod>
7 years ago
</sitemap>
7 years ago
<?php endfor;
7 years ago
echo '</sitemapindex>';
else:
?>
7 years ago
<?php
7 years ago
if ((int)$_REQUEST['id'] > 1)
$_start = ((int)$_REQUEST['id']-1) * $_end;
$sql = "
7 years ago
SELECT STRAIGHT_JOIN
7 years ago
doc.Id,
doc.document_alias,
doc.document_published,
doc.document_changed,
doc.document_sitemap_freq,
doc.document_sitemap_pr
7 years ago
FROM
" . PREFIX . "_documents AS doc
LEFT JOIN
" . PREFIX . "_rubrics AS rub
7 years ago
ON rub.Id = doc.rubric_id
7 years ago
LEFT JOIN
" . PREFIX . "_rubric_templates AS tmpl
ON tmpl.rubric_id = rub.Id
LEFT JOIN
" . PREFIX . "_rubric_permissions AS rubperm
ON rubperm.rubric_id = rub.Id
7 years ago
WHERE
7 years ago
# Не пустой шаблон
(rub.rubric_template NOT LIKE '' OR tmpl.template NOT LIKE '')
# Статус документа = 1
7 years ago
AND doc.document_status = 1
7 years ago
# Документ не удален
7 years ago
AND doc.document_deleted = 1
$publish
7 years ago
# Документ не равен 1
7 years ago
AND doc.Id != 1
7 years ago
# Документ не равен 404 ошибке
7 years ago
AND doc.Id != " . PAGE_NOT_FOUND_ID . "
7 years ago
# Документы разрешены для индексации
7 years ago
AND (document_meta_robots NOT LIKE '%noindex%' or document_meta_robots NOT LIKE '%nofollow%')
7 years ago
# Разрешены для просмотра гостям
7 years ago
AND (rubperm.user_group_id = 2 AND rubperm.rubric_permission LIKE '%docread%')
7 years ago
GROUP BY doc.Id
7 years ago
ORDER BY doc.document_published ASC
7 years ago
LIMIT ".$_start.",".$_end.";
7 years ago
";
7 years ago
$res = $AVE_DB->Query($sql, SITEMAP_CACHE_LIFETIME, 'sitemap', true, '.limit');
7 years ago
if (! $res->NumRows() && (int)$_REQUEST['id'] != 1)
7 years ago
{
report404();
$AVE_DB->clearCurrentCache('sitemap', $sql, '.limit');
header ($_SERVER['SERVER_PROTOCOL'] . ' 404 Not Found', true);
exit;
}
header ('Content-type: text/xml');
7 years ago
7 years ago
echo '<?xml version="1.0" encoding="UTF-8"?>' . PHP_EOL;
echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . PHP_EOL;
if ((int)$_REQUEST['id'] == 1):
?>
<url>
7 years ago
<loc><?php echo HOST . '/'; ?></loc>
<lastmod><?php echo date("c", time()); ?></lastmod>
7 years ago
<changefreq>weekly</changefreq>
<priority>0.8</priority>
</url>
7 years ago
<?php endif; ?>
<?php
7 years ago
while($row = $res->FetchAssocArray()):
7 years ago
$document_alias = $abs_path . $row['document_alias'] . URL_SUFF;
7 years ago
$document_alias = HOST . str_ireplace($abs_path . '/' . URL_SUFF, '/', $document_alias);
7 years ago
$date = $row["document_published"] ? date("c", $row["document_published"]) : date("c");
7 years ago
?>
<url>
7 years ago
<loc><?php echo $document_alias; ?></loc>
<lastmod><?php echo $date; ?></lastmod>
<changefreq><?php echo $changefreq[$row['document_sitemap_freq']]; ?></changefreq>
<priority><?php echo $row['document_sitemap_pr']; ?></priority>
7 years ago
</url>
7 years ago
<?php endwhile; ?>
7 years ago
</urlset>
7 years ago
<?php endif; ?>