Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
Runtime.php
1<?php
2
4
8
9class 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}
putContents($data, $flags=self::REWRITE)
Definition file.php:65
getPath()
getDirectoryName()
rename($newPath)
static normalize($path)
Definition path.php:26
static combine()
Definition path.php:221
addIBlockEntry($url, $modifiedDate)
Definition Base.php:364
putSitemapContent(Base $sitemapFile)
Definition Runtime.php:49
setOriginalFile(Base $sitemapFile)
Definition Runtime.php:68
__construct($PID, $fileName, $arSettings)
Definition Runtime.php:16
appendIBlockEntry($url, $modifiedDate)
Definition Runtime.php:85