Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
Index.php
1<?php
9
11
15class 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}
putContents($data, $flags=self::REWRITE)
Definition file.php:65
createIndex(array $arIndex)
Definition Index.php:22