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