Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
sitemapindex.php
1
<?php
8
namespace
Bitrix\Seo
;
9
10
use
Bitrix\Main\Text\Converter
;
11
17
class
SitemapIndex
18
extends
SitemapFile
19
{
20
const
FILE_HEADER
=
'<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'
;
21
const
FILE_FOOTER
=
'</sitemapindex>'
;
22
23
const
ENTRY_TPL
=
'<sitemap><loc>%s</loc><lastmod>%s</lastmod></sitemap>'
;
24
25
public
function
createIndex
($arIndex)
26
{
27
$str = self::XML_HEADER.self::FILE_HEADER;
28
29
foreach
($arIndex as $file)
30
{
31
if
(!$file->isSystem() && $file->isExists())
32
{
33
$e = [];
34
$str .= sprintf(
35
self::ENTRY_TPL,
36
Converter::getXmlConverter()->encode($this->settings[
'PROTOCOL'
].
'://'
.\CBXPunycode::toASCII($this->settings[
'DOMAIN'
], $e).$this->
getFileUrl
($file)),
37
date(
'c'
, $file->getModificationTime())
38
);
39
}
40
}
41
42
$str .=
self::FILE_FOOTER
;
43
44
$this->
putContents
($str);
45
}
46
47
public
function
appendIndexEntry
($file)
48
{
49
if
($this->
isExists
() && $file->isExists())
50
{
51
$e = [];
52
$fileUrlEnc = Converter::getXmlConverter()->encode($this->settings[
'PROTOCOL'
].
'://'
.\CBXPunycode::toASCII($this->settings[
'DOMAIN'
], $e).$this->
getFileUrl
($file));
53
54
$contents = $this->
getContents
();
55
56
$reg =
"/"
.sprintf(preg_quote(self::ENTRY_TPL,
"/"
), preg_quote($fileUrlEnc,
"/"
),
"[^<]*"
).
"/"
;
57
58
$newEntry = sprintf(
59
self::ENTRY_TPL,
60
$fileUrlEnc,
61
date(
'c'
, $file->getModificationTime($file))
62
);
63
64
$count = 0;
65
$contents = preg_replace($reg, $newEntry, $contents, 1, $count);
66
67
if
($count <= 0)
68
{
69
$contents = mb_substr($contents, 0, -mb_strlen(self::FILE_FOOTER))
70
.$newEntry.self::FILE_FOOTER;
71
}
72
73
$this->
putContents
($contents);
74
}
75
else
76
{
77
$this->
createIndex
(array($file));
78
}
79
}
80
}
Bitrix\Main\IO\File\getContents
getContents()
Definition
file.php:57
Bitrix\Main\IO\File\putContents
putContents($data, $flags=self::REWRITE)
Definition
file.php:65
Bitrix\Main\IO\File\isExists
isExists()
Definition
file.php:51
Bitrix\Main\Text\Converter
Definition
converter.php:5
Bitrix\Seo\SitemapFile
Definition
sitemapfile.php:22
Bitrix\Seo\SitemapFile\getFileUrl
getFileUrl(File $f)
Definition
sitemapfile.php:455
Bitrix\Seo\SitemapIndex
Definition
sitemapindex.php:19
Bitrix\Seo\SitemapIndex\createIndex
createIndex($arIndex)
Definition
sitemapindex.php:25
Bitrix\Seo\SitemapIndex\FILE_FOOTER
const FILE_FOOTER
Definition
sitemapindex.php:21
Bitrix\Seo\SitemapIndex\FILE_HEADER
const FILE_HEADER
Definition
sitemapindex.php:20
Bitrix\Seo\SitemapIndex\ENTRY_TPL
const ENTRY_TPL
Definition
sitemapindex.php:23
Bitrix\Seo\SitemapIndex\appendIndexEntry
appendIndexEntry($file)
Definition
sitemapindex.php:47
Bitrix\Seo
modules
seo
lib
sitemapindex.php
Создано системой
1.10.0