Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
sitemapindex.php
1<?php
8namespace Bitrix\Seo;
9
11
18 extends SitemapFile
19{
20 const FILE_HEADER = '<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
21 const FILE_FOOTER = '</sitemapindex>';
22
23 const ENTRY_TPL = '<sitemap><loc>%s</loc><lastmod>%s</lastmod></sitemap>';
24
25 public function createIndex($arIndex)
26 {
27 $str = self::XML_HEADER.self::FILE_HEADER;
28
29 foreach ($arIndex as $file)
30 {
31 if(!$file->isSystem() && $file->isExists())
32 {
33 $e = [];
34 $str .= sprintf(
35 self::ENTRY_TPL,
36 Converter::getXmlConverter()->encode($this->settings['PROTOCOL'].'://'.\CBXPunycode::toASCII($this->settings['DOMAIN'], $e).$this->getFileUrl($file)),
37 date('c', $file->getModificationTime())
38 );
39 }
40 }
41
42 $str .= self::FILE_FOOTER;
43
44 $this->putContents($str);
45 }
46
47 public function appendIndexEntry($file)
48 {
49 if($this->isExists() && $file->isExists())
50 {
51 $e = [];
52 $fileUrlEnc = Converter::getXmlConverter()->encode($this->settings['PROTOCOL'].'://'.\CBXPunycode::toASCII($this->settings['DOMAIN'], $e).$this->getFileUrl($file));
53
54 $contents = $this->getContents();
55
56 $reg = "/".sprintf(preg_quote(self::ENTRY_TPL, "/"), preg_quote($fileUrlEnc, "/"), "[^<]*")."/";
57
58 $newEntry = sprintf(
59 self::ENTRY_TPL,
60 $fileUrlEnc,
61 date('c', $file->getModificationTime($file))
62 );
63
64 $count = 0;
65 $contents = preg_replace($reg, $newEntry, $contents, 1, $count);
66
67 if($count <= 0)
68 {
69 $contents = mb_substr($contents, 0, -mb_strlen(self::FILE_FOOTER))
70 .$newEntry.self::FILE_FOOTER;
71 }
72
73 $this->putContents($contents);
74 }
75 else
76 {
77 $this->createIndex(array($file));
78 }
79 }
80}
putContents($data, $flags=self::REWRITE)
Definition file.php:65