Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
Runtime.php
1
<?php
2
3
namespace
Bitrix\Seo\Sitemap\File
;
4
5
use
Bitrix\Main\Text\Converter
;
6
use
Bitrix\Main\IO\File
;
7
use
Bitrix\Main\IO\Path
;
8
9
class
Runtime
extends
Base
10
{
11
const
PROGRESS_WIDTH
= 500;
12
13
protected
$PID
= 0;
14
private
$originalFile = NULL;
15
16
public
function
__construct
(
$PID
, $fileName, $arSettings)
17
{
18
$this->PID =
$PID
;
19
20
if
($this->partFile ==
''
)
21
{
22
$this->partFile = $fileName;
23
}
24
25
// normalize slashes
26
$fileName =
Path::normalize
($fileName);
27
// divide directory and path tp correctly add prefix
28
$lastSlashPosition = mb_strrpos($fileName,
"/"
);
29
$fileDirectory =
''
;
30
if
($lastSlashPosition !==
false
)
31
{
32
$fileDirectory = mb_substr($fileName, 0, $lastSlashPosition + 1);
33
$fileName = mb_substr($fileName, $lastSlashPosition + 1);
34
}
35
36
parent::__construct($fileDirectory . $this->
getPrefix
() . $fileName, $arSettings);
37
}
38
44
protected
function
reInit
($fileName)
45
{
46
$this->
__construct
($this->PID, $fileName, $this->settings);
47
}
48
49
public
function
putSitemapContent
(
Base
$sitemapFile)
50
{
51
// always write in new empty file - this is necessary
52
if
($this->
isExists
())
53
$this->
delete
();
54
55
if
($sitemapFile->
isExists
())
56
{
57
$this->
putContents
($sitemapFile->
getContents
());
58
$this->partChanged =
true
;
59
$this->footerClosed =
true
;
60
}
61
else
62
{
63
$this->
addHeader
();
64
}
65
}
66
67
68
public
function
setOriginalFile
(
Base
$sitemapFile)
69
{
70
if
(isset($sitemapFile))
71
{
72
$this->originalFile = $sitemapFile;
73
}
74
}
75
85
public
function
appendIBlockEntry
($url, $modifiedDate)
86
{
87
// if not set original file - to use as common sitemap file
88
if
(!$this->originalFile)
89
{
90
parent::appendIBlockEntry($url, $modifiedDate);
91
return
;
92
}
93
94
if
($this->originalFile->isExists())
95
{
96
// move sitemapfile to end, find name of last part
97
while
($this->originalFile->isSplitNeeded())
98
{
99
$filename = $this->originalFile->split();
100
}
101
102
// if part was changed - create new runtime part file
103
if
(isset($filename) && $filename)
104
$this->
reInit
($filename);
105
106
$this->
putSitemapContent
($this->originalFile);
107
$e = [];
108
$this->
appendEntry
(array(
109
'XML_LOC'
=> $this->settings[
'PROTOCOL'
] .
'://'
. \CBXPunycode::toASCII($this->settings[
'DOMAIN'
], $e) . $url,
110
'XML_LASTMOD'
=> date(
'c'
, $modifiedDate - \CTimeZone::getOffset()),
111
));
112
}
113
else
114
{
115
$this->
addHeader
();
116
$this->
addIBlockEntry
($url, $modifiedDate);
117
$this->
addFooter
();
118
}
119
}
120
124
public
function
finish
()
125
{
126
foreach
($this->partList as $key => $partName)
127
{
128
$f =
new
File
(
Path::combine
($this->
getDirectoryName
(), $partName));
129
$f->rename(str_replace($this->
getPrefix
(),
''
, $f->getPath()));
130
$this->partList[$key] = $f->getName();
131
}
132
133
if
($this->
isCurrentPartNotEmpty
())
134
{
135
if
(!$this->footerClosed)
136
{
137
$this->
addFooter
();
138
}
139
$this->
rename
(str_replace($this->
getPrefix
(),
''
, $this->
getPath
()));
140
}
141
}
142
143
protected
function
getPrefix
()
144
{
145
return
'~'
.
$this->PID
;
146
}
147
}
Bitrix\Main\IO\File
Definition
file.php:7
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\IO\FileSystemEntry\getPath
getPath()
Definition
filesystementry.php:66
Bitrix\Main\IO\FileSystemEntry\getDirectoryName
getDirectoryName()
Definition
filesystementry.php:61
Bitrix\Main\IO\FileSystemEntry\rename
rename($newPath)
Definition
filesystementry.php:98
Bitrix\Main\IO\Path
Definition
path.php:11
Bitrix\Main\IO\Path\normalize
static normalize($path)
Definition
path.php:26
Bitrix\Main\IO\Path\combine
static combine()
Definition
path.php:221
Bitrix\Main\Text\Converter
Definition
converter.php:5
Bitrix\Seo\Sitemap\File\Base
Definition
Base.php:20
Bitrix\Seo\Sitemap\File\Base\addIBlockEntry
addIBlockEntry($url, $modifiedDate)
Definition
Base.php:364
Bitrix\Seo\Sitemap\File\Base\addFooter
addFooter()
Definition
Base.php:414
Bitrix\Seo\Sitemap\File\Base\addHeader
addHeader()
Definition
Base.php:105
Bitrix\Seo\Sitemap\File\Base\appendEntry
appendEntry($entry)
Definition
Base.php:245
Bitrix\Seo\Sitemap\File\Base\isCurrentPartNotEmpty
isCurrentPartNotEmpty()
Definition
Base.php:223
Bitrix\Seo\Sitemap\File\Runtime
Definition
Runtime.php:10
Bitrix\Seo\Sitemap\File\Runtime\putSitemapContent
putSitemapContent(Base $sitemapFile)
Definition
Runtime.php:49
Bitrix\Seo\Sitemap\File\Runtime\setOriginalFile
setOriginalFile(Base $sitemapFile)
Definition
Runtime.php:68
Bitrix\Seo\Sitemap\File\Runtime\__construct
__construct($PID, $fileName, $arSettings)
Definition
Runtime.php:16
Bitrix\Seo\Sitemap\File\Runtime\appendIBlockEntry
appendIBlockEntry($url, $modifiedDate)
Definition
Runtime.php:85
Bitrix\Seo\Sitemap\File\Runtime\getPrefix
getPrefix()
Definition
Runtime.php:143
Bitrix\Seo\Sitemap\File\Runtime\$PID
$PID
Definition
Runtime.php:13
Bitrix\Seo\Sitemap\File\Runtime\finish
finish()
Definition
Runtime.php:124
Bitrix\Seo\Sitemap\File\Runtime\reInit
reInit($fileName)
Definition
Runtime.php:44
Bitrix\Seo\Sitemap\File\Runtime\PROGRESS_WIDTH
const PROGRESS_WIDTH
Definition
Runtime.php:11
Bitrix\Seo\Sitemap\File
Definition
Base.php:8
modules
seo
lib
Sitemap
File
Runtime.php
Создано системой
1.10.0