1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
site.php
См. документацию.
1<?php
2
9
10namespace Bitrix\Main;
11
12use Bitrix\Main\ORM\Fields;
13
31{
32 protected const CACHE_TTL = 86400;
33
34 protected static $documentRootCache = [];
35
36 public static function getDocumentRoot($siteId = null)
37 {
38 if ($siteId === null)
39 {
40 $siteId = Application::getInstance()->getContext()->getSite();
41 }
42
43 if (!isset(self::$documentRootCache[$siteId]))
44 {
45 $site = static::getRow([
46 "filter" => ["=LID" => $siteId],
47 "cache" => ["ttl" => static::CACHE_TTL],
48 ]);
49
50 if ($site && ($docRoot = $site["DOC_ROOT"]) && ($docRoot <> ''))
51 {
52 if (!IO\Path::isAbsolute($docRoot))
53 {
54 $docRoot = IO\Path::combine(Application::getDocumentRoot(), $docRoot);
55 }
56 self::$documentRootCache[$siteId] = $docRoot;
57 }
58 else
59 {
60 self::$documentRootCache[$siteId] = Application::getDocumentRoot();
61 }
62 }
63
64 return self::$documentRootCache[$siteId];
65 }
66
67 public static function getTableName()
68 {
69 return 'b_lang';
70 }
71
72 public static function getMap()
73 {
75 $helper = $connection->getSqlHelper();
76
77 return array(
78 'LID' => array(
79 'data_type' => 'string',
80 'primary' => true,
81 ),
82 'ID' => array(
83 'data_type' => 'string',
84 'expression' => array('%s', 'LID'),
85 ),
86 'SORT' => array(
87 'data_type' => 'integer',
88 ),
89 'DEF' => array(
90 'data_type' => 'boolean',
91 'values' => array('N', 'Y'),
92 ),
93 'ACTIVE' => array(
94 'data_type' => 'boolean',
95 'values' => array('N', 'Y'),
96 ),
97 'NAME' => array(
98 'data_type' => 'string',
99 ),
100 'DIR' => array(
101 'data_type' => 'string',
102 ),
103 'LANGUAGE_ID' => array(
104 'data_type' => 'string',
105 ),
106 'DOC_ROOT' => array(
107 'data_type' => 'string',
108 ),
109 'DOMAIN_LIMITED' => array(
110 'data_type' => 'boolean',
111 'values' => array('N', 'Y'),
112 ),
113 'SERVER_NAME' => array(
114 'data_type' => 'string',
115 ),
116 'SITE_NAME' => array(
117 'data_type' => 'string',
118 ),
119 'EMAIL' => array(
120 'data_type' => 'string',
121 ),
122 'CULTURE_ID' => array(
123 'data_type' => 'integer',
124 ),
125 'CULTURE' => array(
126 'data_type' => 'Bitrix\Main\Localization\Culture',
127 'reference' => array('=this.CULTURE_ID' => 'ref.ID'),
128 'join_type' => 'INNER',
129 ),
130 'LANGUAGE' => array(
131 'data_type' => 'Bitrix\Main\Localization\Language',
132 'reference' => array('=this.LANGUAGE_ID' => 'ref.ID'),
133 'join_type' => 'INNER',
134 ),
135 (new Fields\ExpressionField('DIR_LENGTH', $helper->getLengthFunction('%s'), 'DIR')),
136 (new Fields\ExpressionField('DOC_ROOT_LENGTH', $helper->getIsNullFunction($helper->getLengthFunction('%s'), '0'), 'DOC_ROOT')),
137 );
138 }
139
140 public static function getByDomain(string $host, string $directory)
141 {
142 $site = null;
143
144 $sites = static::getList([
145 'select' => ['*'],
146 'filter' => ['=ACTIVE' => 'Y'],
147 'order' => [
148 'DIR_LENGTH' => 'DESC',
149 'DOMAIN_LIMITED' => 'DESC',
150 'SORT' => 'ASC',
151 ],
152 'cache' => ['ttl' => static::CACHE_TTL],
153 ])->fetchAll();
154
155 $result = SiteDomainTable::getList([
156 'select' => ['LD_LID' => 'LID', 'LD_DOMAIN' => 'DOMAIN'],
157 'order' => ['DOMAIN_LENGTH' => 'DESC'],
158 'cache' => ['ttl' => static::CACHE_TTL],
159 ]);
160
161 $domains = [];
162 while ($row = $result->fetch())
163 {
164 $domains[$row['LD_LID']][] = $row;
165 }
166
167 $join = [];
168 foreach ($sites as $row)
169 {
170 //LEFT JOIN
171 $left = true;
172 //LEFT JOIN b_lang_domain LD ON L.LID=LD.LID
173 if (array_key_exists($row['LID'], $domains))
174 {
175 foreach ($domains[$row['LID']] as $dom)
176 {
177 //AND '".$DB->ForSql($CURR_DOMAIN, 255)."' LIKE CONCAT('%', LD.DOMAIN)
178 if (strcasecmp(mb_substr(".".$host, -mb_strlen("." . $dom['LD_DOMAIN'])), "." . $dom['LD_DOMAIN']) == 0)
179 {
180 $join[] = $row + $dom;
181 $left = false;
182 }
183 }
184 }
185 if ($left)
186 {
187 $join[] = $row + ['LD_LID' => '', 'LD_DOMAIN' => ''];
188 }
189 }
190
191 $rows = [];
192 foreach ($join as $row)
193 {
194 //WHERE ('".$DB->ForSql($cur_dir)."' LIKE CONCAT(L.DIR, '%') OR LD.LID IS NOT NULL)
195 if ($row['LD_LID'] != '' || strcasecmp(mb_substr($directory, 0, mb_strlen($row['DIR'])), $row['DIR']) == 0)
196 {
197 $rows[] = $row;
198 }
199 }
200
201 foreach ($rows as $row)
202 {
203 if (
204 (strcasecmp(mb_substr($directory, 0, mb_strlen($row['DIR'])), $row['DIR']) == 0)
205 && (($row['DOMAIN_LIMITED'] == 'Y' && $row['LD_LID'] != '') || $row['DOMAIN_LIMITED'] != 'Y')
206 )
207 {
208 $site = $row;
209 break;
210 }
211 }
212
213 if ($site === null)
214 {
215 foreach ($rows as $row)
216 {
217 if (strncasecmp($directory, $row['DIR'], mb_strlen($directory)) == 0)
218 {
219 $site = $row;
220 break;
221 }
222 }
223 }
224
225 if($site === null)
226 {
227 foreach ($rows as $row)
228 {
229 if (($row['DOMAIN_LIMITED'] == 'Y' && $row['LD_LID'] != '') || $row['DOMAIN_LIMITED'] != 'Y')
230 {
231 $site = $row;
232 break;
233 }
234 }
235 }
236
237 if ($site === null && !empty($rows))
238 {
239 $site = $rows[0];
240 }
241
242 if ($site === null)
243 {
244 $site = static::getList([
245 'select' => ['*'],
246 'filter' => ['=ACTIVE' => 'Y'],
247 'order' => [
248 'DEF' => 'DESC',
249 'SORT' => 'ASC',
250 ],
251 'cache' => ['ttl' => static::CACHE_TTL],
252 ])->fetch();
253 }
254
255 if ($site)
256 {
257 // unset fields added from left join
258 unset($site['LD_LID'], $site['LD_DOMAIN']);
259 }
260
261 return $site;
262 }
263
264 public static function getDefaultSite(array $selectFields = ['*']): ?EO_Site
265 {
266 return static::getList([
267 'select' => $selectFields,
268 'filter' => ['=DEF' => 'Y', '=ACTIVE' => 'Y'],
269 'limit' => 1,
270 'cache' => ['ttl' => static::CACHE_TTL],
271 ])->fetchObject();
272 }
273
274 public static function getDefaultLanguageId(): ?string
275 {
276 // using the same cache
277 return static::getDefaultSite(['LID', 'LANGUAGE_ID'])?->getLanguageId();
278 }
279
280 public static function getDefaultSiteId(): ?string
281 {
282 // using the same cache
283 return static::getDefaultSite(['LID', 'LANGUAGE_ID'])?->getLid();
284 }
285
286 public static function cleanCache(): void
287 {
288 parent::cleanCache();
289 self::$documentRootCache = [];
290 }
291}
$connection
Определения actionsdefinitions.php:38
static getDocumentRoot()
Определения application.php:736
static getInstance()
Определения application.php:98
static getConnection($name="")
Определения application.php:638
Определения orm.php:16557
Определения site.php:31
static getDefaultLanguageId()
Определения site.php:274
static getMap()
Определения site.php:72
static cleanCache()
Определения site.php:286
static getByDomain(string $host, string $directory)
Определения site.php:140
static getDefaultSite(array $selectFields=[' *'])
Определения site.php:264
static getDocumentRoot($siteId=null)
Определения site.php:36
const CACHE_TTL
Определения site.php:32
static getDefaultSiteId()
Определения site.php:280
static $documentRootCache
Определения site.php:34
static getTableName()
Определения site.php:67
$sites
Определения clear_component_cache.php:15
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14
$selectFields
Определения iblock_catalog_list.php:160
$docRoot
Определения options.php:20
$siteId
Определения ajax.php:8
Определения directory.php:3
$host
Определения mysql_to_pgsql.php:32
$rows
Определения options.php:264
$site
Определения yandex_run.php:614