Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
sitemapruntime.php
1<?php
9namespace Bitrix\Seo;
10
15
34class 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',
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' => [
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("
112DELETE
113FROM " . self::getTableName() . "
114WHERE PID='" . intval($PID) . "'
115");
116 }
117}
118
119
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}
putContents($data, $flags=self::REWRITE)
Definition file.php:65
getPath()
getDirectoryName()
rename($newPath)
addIBlockEntry($url, $modifiedDate)
__construct($PID, $fileName, $arSettings)
appendIBlockEntry($url, $modifiedDate)
putSitemapContent(SitemapFile $sitemapFile)
static showProgress($text, $title, $v)
setOriginalFile(SitemapFile $sitemapFile)