Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
Sitemap.php
1<?php
2
4
5use \Bitrix\Main\Entity;
6use \Bitrix\Main\Localization\Loc;
8
9Loc::loadMessages(__FILE__);
10
11class SitemapTable extends Entity\DataManager
12{
13 const SETTINGS_DEFAULT_FILE_MASK = '*.php,*.html';
14
15 const ACTIVE = 'Y';
16 const INACTIVE = 'N';
17
18 public static function getFilePath()
19 {
20 return __FILE__;
21 }
22
23 public static function getTableName()
24 {
25 return 'b_seo_sitemap';
26 }
27
28 public static function getMap()
29 {
30 $fieldsMap = [
31 'ID' => [
32 'data_type' => 'integer',
33 'primary' => true,
34 'autocomplete' => true,
35 ],
36 'TIMESTAMP_X' => [
37 'data_type' => 'datetime'
38 ],
39 'SITE_ID' => [
40 'data_type' => 'string',
41 'required' => true,
42 ],
43 'ACTIVE' => [
44 'data_type' => 'boolean',
45 'values' => [self::INACTIVE, self::ACTIVE]
46 ],
47 'NAME' => [
48 'data_type' => 'string',
49 'required' => true,
50 'title' => Loc::getMessage('SITEMAP_NAME_TITLE'),
51 ],
52 'DATE_RUN' => [
53 'data_type' => 'datetime',
54 ],
55 'SETTINGS' => [
56 'data_type' => 'text',
57 ],
58 ];
59
60 return $fieldsMap;
61 }
62
63 protected static function compileMask($mask)
64 {
65 if($mask <> '')
66 {
67 $arMask = preg_split("/[\s,;]+/", $mask);
68
69 foreach ($arMask as $key => $subMask)
70 {
71 if($subMask <> '')
72 {
73 $arMask[$key] = str_replace(
74 array("___ALL___", "___ONE___"),
75 array(".*?", "."),
76 preg_quote(str_replace(
77 array("*", "?"),
78 array("___ALL___", "___ONE___"),
79 $subMask
80 ))
81 );
82 }
83 else
84 {
85 unset($arMask[$key]);
86 }
87 }
88
89 return "/^(".implode('|', $arMask).")$/i".BX_UTF_PCRE_MODIFIER;
90 }
91 else
92 {
93 return "/.*/i".BX_UTF_PCRE_MODIFIER;
94 }
95 }
96
102 public static function prepareSettings($arSettings)
103 {
104 if(is_array($arSettings))
105 {
106 $arSettings['FILE_MASK_REGEXP'] = self::compileMask($arSettings['FILE_MASK']);
107
108 if(!isset($arSettings['DIR']) || !is_array($arSettings['DIR']))
109 {
110 $arSettings['DIR'] = array();
111 }
112
113 if(isset($arSettings['FILE']) && is_array($arSettings['FILE']))
114 {
115 ksort($arSettings['FILE'], SORT_STRING);
116
117 foreach($arSettings['FILE'] as $file => $value)
118 {
119 $pos = mb_strrpos($file, '/');
120 $parentDir = $pos > 0? mb_substr($file, 0, $pos) : '/';
121
122 if(isset($arSettings['DIR'][$parentDir]) && $arSettings['DIR'][$parentDir] == $value)
123 {
124 unset($arSettings['FILE'][$file]);
125 }
126 }
127 }
128
129 if(isset($arSettings['DIR']) && is_array($arSettings['DIR']))
130 {
131 krsort($arSettings['DIR'], SORT_STRING);
132
133 foreach($arSettings['DIR'] as $dir => $value)
134 {
135 if($dir != '/')
136 {
137 $pos = mb_strrpos($dir, '/');
138 $parentDir = mb_substr($dir, 0, $pos);
139
140 if($parentDir == '')
141 $parentDir = '/';
142
143 if(isset($arSettings['DIR'][$parentDir]) && $arSettings['DIR'][$parentDir] == $value)
144 {
145 unset($arSettings['DIR'][$dir]);
146 }
147 }
148 }
149
150 $arSettings['DIR'] = array_reverse($arSettings['DIR']);
151 }
152
153 if(isset($arSettings['IBLOCK_ACTIVE']) && is_array($arSettings['IBLOCK_ACTIVE']))
154 {
155 foreach($arSettings['IBLOCK_ACTIVE'] as $iblockId => $value)
156 {
157 if ($value == 'N')
158 {
159 unset($arSettings['IBLOCK_LIST'][$iblockId]);
160 unset($arSettings['IBLOCK_SECTION'][$iblockId]);
161 unset($arSettings['IBLOCK_ELEMENT'][$iblockId]);
162 unset($arSettings['IBLOCK_SECTION_SECTION'][$iblockId]);
163 unset($arSettings['IBLOCK_SECTION_ELEMENT'][$iblockId]);
164 }
165 }
166 }
167
168 if(isset($arSettings['FORUM_ACTIVE']) && is_array($arSettings['FORUM_ACTIVE']))
169 {
170 foreach($arSettings['FORUM_ACTIVE'] as $forumId => $value)
171 {
172 if ($value == 'N')
173 {
174 unset($arSettings['FORUM_TOPIC'][$forumId]);
175 }
176 }
177 }
178 }
179
180 return $arSettings;
181 }
182
189 public static function fullDelete(int $id): void
190 {
191 $delRes = self::delete($id);
192 if ($delRes->isSuccess())
193 {
198 }
199 }
200}
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
static clearBySitemap(int $sitemapId)
Definition Job.php:224