Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
sitemapruntime.php
1
<?php
9
namespace
Bitrix\Seo
;
10
11
use
Bitrix\Main\Entity
;
12
use
Bitrix\Main\Text\Converter
;
13
use
Bitrix\Main\IO\File
;
14
use
Bitrix\Main\IO\Path
;
15
34
class
SitemapRuntimeTable
extends
Entity\DataManager
35
{
36
const
ACTIVE
=
'Y'
;
37
const
INACTIVE
=
'N'
;
38
39
const
ITEM_TYPE_DIR
=
'D'
;
40
const
ITEM_TYPE_FILE
=
'F'
;
41
const
ITEM_TYPE_IBLOCK
=
'I'
;
42
const
ITEM_TYPE_SECTION
=
'S'
;
43
const
ITEM_TYPE_ELEMENT
=
'E'
;
44
const
ITEM_TYPE_FORUM
=
'G'
;
45
const
ITEM_TYPE_TOPIC
=
'T'
;
46
47
const
PROCESSED
=
'Y'
;
48
const
UNPROCESSED
=
'N'
;
49
50
public
static
function
getFilePath
()
51
{
52
return
__FILE__;
53
}
54
55
public
static
function
getTableName
()
56
{
57
return
'b_seo_sitemap_runtime'
;
58
}
59
60
public
static
function
getMap
()
61
{
62
$fieldsMap = [
63
'ID'
=> [
64
'data_type'
=>
'integer'
,
65
'primary'
=>
true
,
66
'autocomplete'
=>
true
,
67
],
68
'PID'
=> [
69
'data_type'
=>
'integer'
,
70
'required'
=>
true
,
71
],
72
'PROCESSED'
=> [
73
'data_type'
=>
'boolean'
,
74
'values'
=> [
self::UNPROCESSED
,
self::PROCESSED
],
75
],
76
'ITEM_PATH'
=> [
77
'data_type'
=>
'string'
,
78
],
79
'ITEM_ID'
=> [
80
'data_type'
=>
'integer'
,
81
],
82
'ITEM_TYPE'
=> [
83
'data_type'
=>
'enum'
,
84
'values'
=> [
85
self::ITEM_TYPE_DIR
,
86
self::ITEM_TYPE_FILE
,
87
self::ITEM_TYPE_IBLOCK
,
88
self::ITEM_TYPE_SECTION
,
89
self::ITEM_TYPE_ELEMENT
,
90
self::ITEM_TYPE_FORUM
,
91
self::ITEM_TYPE_TOPIC
,
92
],
93
],
94
'ACTIVE'
=> [
95
'data_type'
=>
'boolean'
,
96
'values'
=> [
self::INACTIVE
,
self::ACTIVE
],
97
],
98
'ACTIVE_ELEMENT'
=> [
99
'data_type'
=>
'boolean'
,
100
'values'
=> [
self::INACTIVE
,
self::ACTIVE
],
101
],
102
];
103
104
return
$fieldsMap;
105
}
106
107
108
public
static
function
clearByPid
($PID)
109
{
110
$connection = \Bitrix\Main\Application::getConnection();
111
$query = $connection->query(
"
112
DELETE
113
FROM "
. self::getTableName() .
"
114
WHERE PID='"
. intval($PID) .
"'
115
"
);
116
}
117
}
118
119
120
class
SitemapRuntime
121
extends
SitemapFile
122
{
123
const
PROGRESS_WIDTH
= 500;
124
125
protected
$PID
= 0;
126
private
$originalFile = NULL;
127
128
public
function
__construct
(
$PID
, $fileName, $arSettings)
129
{
130
$this->PID =
$PID
;
131
132
if
($this->partFile ==
''
)
133
{
134
$this->partFile = $fileName;
135
}
136
137
// normalize slashes
138
$fileName = Path::normalize($fileName);
139
// divide directory and path tp correctly add prefix
140
$lastSlashPosition = mb_strrpos($fileName,
"/"
);
141
$fileDirectory =
''
;
142
if
($lastSlashPosition !==
false
)
143
{
144
$fileDirectory = mb_substr($fileName, 0, $lastSlashPosition + 1);
145
$fileName = mb_substr($fileName, $lastSlashPosition + 1);
146
}
147
148
parent::__construct($fileDirectory . $this->
getPrefix
() . $fileName, $arSettings);
149
}
150
156
protected
function
reInit
($fileName)
157
{
158
$this->
__construct
($this->PID, $fileName, $this->settings);
159
}
160
161
public
function
putSitemapContent
(
SitemapFile
$sitemapFile)
162
{
163
// always write in new empty file - this is necessary
164
if
($this->
isExists
())
165
$this->
delete
();
166
167
if
($sitemapFile->
isExists
())
168
{
169
$this->
putContents
($sitemapFile->
getContents
());
170
$this->partChanged =
true
;
171
$this->footerClosed =
true
;
172
}
173
else
174
{
175
$this->
addHeader
();
176
}
177
}
178
179
180
public
function
setOriginalFile
(
SitemapFile
$sitemapFile)
181
{
182
if
(isset($sitemapFile))
183
$this->originalFile = $sitemapFile;
184
}
185
195
public
function
appendIBlockEntry
($url, $modifiedDate)
196
{
197
// if not set original file - to use as common sitemap file
198
if
(!$this->originalFile)
199
{
200
parent::appendIBlockEntry($url, $modifiedDate);
201
return
;
202
}
203
204
if
($this->originalFile->isExists())
205
{
206
// move sitemapfile to end, find name of last part
207
while
($this->originalFile->isSplitNeeded())
208
{
209
$filename = $this->originalFile->split();
210
}
211
212
// if part was changed - create new runtime part file
213
if
(isset($filename) && $filename)
214
$this->
reInit
($filename);
215
216
$this->
putSitemapContent
($this->originalFile);
217
$e = [];
218
$this->
appendEntry
(array(
219
'XML_LOC'
=> $this->settings[
'PROTOCOL'
] .
'://'
. \CBXPunycode::toASCII($this->settings[
'DOMAIN'
], $e) . $url,
220
'XML_LASTMOD'
=> date(
'c'
, $modifiedDate - \CTimeZone::getOffset()),
221
));
222
}
223
else
224
{
225
$this->
addHeader
();
226
$this->
addIBlockEntry
($url, $modifiedDate);
227
$this->
addFooter
();
228
}
229
}
230
234
public
function
finish
()
235
{
236
foreach
($this->partList as $key => $partName)
237
{
238
$f =
new
File
(Path::combine($this->
getDirectoryName
(), $partName));
239
$f->rename(str_replace($this->
getPrefix
(),
''
, $f->getPath()));
240
$this->partList[$key] = $f->getName();
241
}
242
243
if
($this->
isCurrentPartNotEmpty
())
244
{
245
if
(!$this->footerClosed)
246
$this->
addFooter
();
247
$this->
rename
(str_replace($this->
getPrefix
(),
''
, $this->
getPath
()));
248
}
249
}
250
251
protected
function
getPrefix
()
252
{
253
return
'~'
.
$this->PID
;
254
}
255
256
public
static
function
showProgress
($text, $title, $v)
257
{
258
$v = $v >= 0 ? $v : 0;
259
260
if
($v < 100)
261
{
262
$msg = new \CAdminMessage(array(
263
"TYPE"
=>
"PROGRESS"
,
264
"HTML"
=>
true
,
265
"MESSAGE"
=> $title,
266
"DETAILS"
=>
"#PROGRESS_BAR#<div style=\"width: "
. self::PROGRESS_WIDTH .
"px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding-top: 20px;\">"
. Converter::getHtmlConverter()->encode($text) .
"</div>"
,
267
"PROGRESS_TOTAL"
=> 100,
268
"PROGRESS_VALUE"
=> $v,
269
"PROGRESS_TEMPLATE"
=>
'#PROGRESS_PERCENT#'
,
270
"PROGRESS_WIDTH"
=> self::PROGRESS_WIDTH,
271
));
272
}
273
else
274
{
275
$msg = new \CAdminMessage(array(
276
"TYPE"
=>
"OK"
,
277
"MESSAGE"
=> $title,
278
"DETAILS"
=> $text,
279
));
280
}
281
282
return
$msg->show();
283
}
284
}
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\ORM\Entity
Definition
entity.php:26
Bitrix\Main\Text\Converter
Definition
converter.php:5
Bitrix\Seo\SitemapFile
Definition
sitemapfile.php:22
Bitrix\Seo\SitemapFile\addIBlockEntry
addIBlockEntry($url, $modifiedDate)
Definition
sitemapfile.php:361
Bitrix\Seo\SitemapFile\addFooter
addFooter()
Definition
sitemapfile.php:401
Bitrix\Seo\SitemapFile\addHeader
addHeader()
Definition
sitemapfile.php:107
Bitrix\Seo\SitemapFile\appendEntry
appendEntry($entry)
Definition
sitemapfile.php:247
Bitrix\Seo\SitemapFile\isCurrentPartNotEmpty
isCurrentPartNotEmpty()
Definition
sitemapfile.php:225
Bitrix\Seo\SitemapRuntime
Definition
sitemapruntime.php:122
Bitrix\Seo\SitemapRuntime\__construct
__construct($PID, $fileName, $arSettings)
Definition
sitemapruntime.php:128
Bitrix\Seo\SitemapRuntime\appendIBlockEntry
appendIBlockEntry($url, $modifiedDate)
Definition
sitemapruntime.php:195
Bitrix\Seo\SitemapRuntime\getPrefix
getPrefix()
Definition
sitemapruntime.php:251
Bitrix\Seo\SitemapRuntime\$PID
$PID
Definition
sitemapruntime.php:125
Bitrix\Seo\SitemapRuntime\finish
finish()
Definition
sitemapruntime.php:234
Bitrix\Seo\SitemapRuntime\reInit
reInit($fileName)
Definition
sitemapruntime.php:156
Bitrix\Seo\SitemapRuntime\putSitemapContent
putSitemapContent(SitemapFile $sitemapFile)
Definition
sitemapruntime.php:161
Bitrix\Seo\SitemapRuntime\showProgress
static showProgress($text, $title, $v)
Definition
sitemapruntime.php:256
Bitrix\Seo\SitemapRuntime\PROGRESS_WIDTH
const PROGRESS_WIDTH
Definition
sitemapruntime.php:123
Bitrix\Seo\SitemapRuntime\setOriginalFile
setOriginalFile(SitemapFile $sitemapFile)
Definition
sitemapruntime.php:180
Bitrix\Seo\SitemapRuntimeTable
Definition
sitemapruntime.php:35
Bitrix\Seo\SitemapRuntimeTable\PROCESSED
const PROCESSED
Definition
sitemapruntime.php:47
Bitrix\Seo\SitemapRuntimeTable\ITEM_TYPE_TOPIC
const ITEM_TYPE_TOPIC
Definition
sitemapruntime.php:45
Bitrix\Seo\SitemapRuntimeTable\getMap
static getMap()
Definition
sitemapruntime.php:60
Bitrix\Seo\SitemapRuntimeTable\ITEM_TYPE_ELEMENT
const ITEM_TYPE_ELEMENT
Definition
sitemapruntime.php:43
Bitrix\Seo\SitemapRuntimeTable\ITEM_TYPE_FILE
const ITEM_TYPE_FILE
Definition
sitemapruntime.php:40
Bitrix\Seo\SitemapRuntimeTable\clearByPid
static clearByPid($PID)
Definition
sitemapruntime.php:108
Bitrix\Seo\SitemapRuntimeTable\getFilePath
static getFilePath()
Definition
sitemapruntime.php:50
Bitrix\Seo\SitemapRuntimeTable\ITEM_TYPE_DIR
const ITEM_TYPE_DIR
Definition
sitemapruntime.php:39
Bitrix\Seo\SitemapRuntimeTable\UNPROCESSED
const UNPROCESSED
Definition
sitemapruntime.php:48
Bitrix\Seo\SitemapRuntimeTable\ACTIVE
const ACTIVE
Definition
sitemapruntime.php:36
Bitrix\Seo\SitemapRuntimeTable\ITEM_TYPE_SECTION
const ITEM_TYPE_SECTION
Definition
sitemapruntime.php:42
Bitrix\Seo\SitemapRuntimeTable\ITEM_TYPE_FORUM
const ITEM_TYPE_FORUM
Definition
sitemapruntime.php:44
Bitrix\Seo\SitemapRuntimeTable\INACTIVE
const INACTIVE
Definition
sitemapruntime.php:37
Bitrix\Seo\SitemapRuntimeTable\ITEM_TYPE_IBLOCK
const ITEM_TYPE_IBLOCK
Definition
sitemapruntime.php:41
Bitrix\Seo\SitemapRuntimeTable\getTableName
static getTableName()
Definition
sitemapruntime.php:55
Bitrix\Seo
modules
seo
lib
sitemapruntime.php
Создано системой
1.10.0