60 public static function getList($siteId, $arFilter = array(), $arOrder = array())
65 $arUrlRewrite = static::loadRules($siteId);
69 foreach ($arResultKeys as $key)
70 $arResult[] = $arUrlRewrite[$key];
72 if (!empty($arOrder) && !empty($arResult))
74 $arOrderKeys = array_keys($arOrder);
75 $orderBy = array_shift($arOrderKeys);
76 $orderDir = $arOrder[$orderBy];
78 $orderBy = mb_strtoupper($orderBy);
79 $orderDir = mb_strtoupper($orderDir);
81 $orderDir = (($orderDir ==
"DESC") ? SORT_DESC : SORT_ASC);
84 foreach ($arResult as $key => $row)
85 $ar[$key] = $row[$orderBy];
87 array_multisort($ar, $orderDir, $arResult);
93 protected static function filterRules(array $arUrlRewrite, array $arFilter)
95 $arResultKeys = array();
97 foreach ($arUrlRewrite as $keyRule => $arRule)
100 foreach ($arFilter as $keyFilter => $valueFilter)
103 if (mb_substr($keyFilter, 0, 1) ===
"!")
106 $keyFilter = mb_substr($keyFilter, 1);
109 if ($keyFilter ===
'QUERY')
110 $isMatchedTmp = preg_match($arRule[
"CONDITION"], $valueFilter);
111 elseif ($keyFilter ===
'CONDITION')
112 $isMatchedTmp = ($arRule[
"CONDITION"] == $valueFilter);
113 elseif ($keyFilter ===
'ID')
114 $isMatchedTmp = (isset($arRule[
"ID"]) && ($arRule[
"ID"] == $valueFilter));
115 elseif ($keyFilter ===
'PATH')
116 $isMatchedTmp = ($arRule[
"PATH"] == $valueFilter);
120 $isMatched = ($isNegative xor $isMatchedTmp);
127 $arResultKeys[] = $keyRule;
130 return $arResultKeys;
182 public static function update($siteId, $arFilter, $arFields)
187 $arUrlRewrite = static::loadRules($siteId);
190 foreach ($arResultKeys as $key)
192 if (array_key_exists(
"CONDITION", $arFields))
193 $arUrlRewrite[$key][
"CONDITION"] = $arFields[
"CONDITION"];
194 if (array_key_exists(
"RULE", $arFields))
195 $arUrlRewrite[$key][
"RULE"] = $arFields[
"RULE"];
196 if (array_key_exists(
"ID", $arFields))
197 $arUrlRewrite[$key][
"ID"] = $arFields[
"ID"];
198 if (array_key_exists(
"PATH", $arFields))
199 $arUrlRewrite[$key][
"PATH"] = $arFields[
"PATH"];
200 if (array_key_exists(
"SORT", $arFields))
201 $arUrlRewrite[$key][
"SORT"] = intval($arFields[
"SORT"]);
204 uasort($arUrlRewrite, array(
'\Bitrix\Main\UrlRewriter',
"recordsCompare"));
206 static::saveRules($siteId, $arUrlRewrite);
209 public static function delete($siteId, $arFilter)
214 $arUrlRewrite = static::loadRules($siteId);
217 foreach ($arResultKeys as $key)
218 unset($arUrlRewrite[$key]);
220 uasort($arUrlRewrite, array(
'\Bitrix\Main\UrlRewriter',
"recordsCompare"));
222 static::saveRules($siteId, $arUrlRewrite);
225 public static function reindexAll($maxExecutionTime = 0, $ns = array())
231 if ($maxExecutionTime <= 0)
238 "SESS_ID" => md5(uniqid(
"")),
239 "max_execution_time" => $nsOld[
"max_execution_time"],
240 "stepped" => $nsOld[
"stepped"],
241 "max_file_size" => $nsOld[
"max_file_size"]
244 if (!empty($nsOld[
"SITE_ID"]))
245 $ns[
"SITE_ID"] = $nsOld[
"SITE_ID"];
247 $ns[
"CNT"] = intval($ns[
"CNT"] ?? 0);
250 $filterRootPath =
"";
254 "select" => array(
"LID",
"DOC_ROOT",
"DIR"),
255 "filter" => array(
"=ACTIVE" =>
"Y"),
258 while ($ar = $db->fetch())
260 if (empty($ar[
"DOC_ROOT"]))
264 "site_id" => $ar[
"LID"],
265 "root" => $ar[
"DOC_ROOT"],
266 "path" =>
IO\Path::combine($ar[
"DOC_ROOT"], $ar[
"DIR"])
269 if (!empty($ns[
"SITE_ID"]) && $ns[
"SITE_ID"] == $ar[
"LID"])
270 $filterRootPath = $ar[
"DOC_ROOT"];
273 if (!empty($ns[
"SITE_ID"]) && !empty($filterRootPath))
275 $arSitesTmp = array();
276 $arKeys = array_keys($arSites);
277 foreach ($arKeys as $key)
279 if ($arSites[$key][
"root"] == $filterRootPath)
280 $arSitesTmp[] = $arSites[$key];
282 $arSites = $arSitesTmp;
288 $la = mb_strlen($a[
"path"]);
289 $lb = mb_strlen($b[
"path"]);
292 if ($a[
"site_id"] == $b[
"site_id"])
295 return ($a[
"site_id"] > $b[
"site_id"]) ? -1 : 1;
297 return ($la > $lb) ? -1 : 1;
301 if ($ns[
"CLEAR"] !=
"Y")
303 $arAlreadyDeleted = array();
304 foreach ($arSites as $site)
306 Component\ParametersTable::deleteBySiteId($site[
"site_id"]);
307 if (!in_array($site[
"root"], $arAlreadyDeleted))
313 $arAlreadyDeleted[] = $site[
"root"];
321 $arAlreadyParsed = array();
322 foreach ($arSites as $site)
324 if (in_array($site[
"root"], $arAlreadyParsed))
326 $arAlreadyParsed[] = $site[
"root"];
328 if ($maxExecutionTime > 0 && !empty($ns[
"FLG"])
329 && mb_substr($ns[
"ID"].
"/", 0, mb_strlen($site[
"root"].
"/")) != $site[
"root"].
"/")
334 static::recursiveReindex($site[
"root"],
"/", $arSites, $maxExecutionTime, $ns);
336 if ($maxExecutionTime > 0 && !empty($ns[
"FLG"]))
343 protected static function recursiveReindex($rootPath, $path, $arSites, $maxExecutionTime, &$ns)
345 $pathAbs = IO\Path::combine($rootPath, $path);
348 foreach ($arSites as $site)
350 if (mb_substr($pathAbs.
"/", 0, mb_strlen($site[
"path"].
"/")) == $site[
"path"].
"/")
352 $siteId = $site[
"site_id"];
360 if (!$dir->isExists())
363 $arChildren = $dir->getChildren();
364 foreach ($arChildren as $child)
366 if ($child->isDirectory())
368 if ($child->isSystem())
372 if ($maxExecutionTime <= 0
374 || mb_substr($ns[
"ID"].
"/", 0, mb_strlen($child->getPath().
"/")) == $child->getPath().
"/"
377 if (static::recursiveReindex($rootPath, mb_substr($child->getPath(), mb_strlen($rootPath)), $arSites, $maxExecutionTime, $ns) ===
false)
388 if ($maxExecutionTime > 0 && $ns[
"FLG"] <>
''
389 && $ns[
"ID"] == $child->getPath())
393 elseif (empty($ns[
"FLG"]))
395 $ID = static::reindexFile($siteId, $rootPath, mb_substr($child->getPath(), mb_strlen($rootPath)), $ns[
"max_file_size"]);
397 $ns[
"CNT"] = intval($ns[
"CNT"]) + 1;
400 if ($maxExecutionTime > 0
401 && (microtime(
true) - START_EXEC_TIME > $maxExecutionTime))
404 $ns[
"ID"] = $child->getPath();
412 public static function reindexFile($siteId, $rootPath, $path, $maxFileSize = 0)
414 $pathAbs = IO\Path::combine($rootPath, $path);
416 if (!static::checkPath($pathAbs))
420 if ($maxFileSize > 0 && $file->getSize() > $maxFileSize * 1024)
423 $fileSrc = $file->getContents();
425 if (!$fileSrc || $fileSrc ==
"")
428 $arComponents = \PHPParser::parseScript($fileSrc);
430 for ($i = 0, $cnt = count($arComponents); $i < $cnt; $i++)
432 $sef = (is_array($arComponents[$i][
"DATA"][
"PARAMS"]) && $arComponents[$i][
"DATA"][
"PARAMS"][
"SEF_MODE"] ==
"Y");
434 Component\ParametersTable::add(
436 'SITE_ID' => $siteId,
437 'COMPONENT_NAME' => $arComponents[$i][
"DATA"][
"COMPONENT_NAME"],
438 'TEMPLATE_NAME' => $arComponents[$i][
"DATA"][
"TEMPLATE_NAME"],
439 'REAL_PATH' => $path,
441 'SEF_FOLDER' => ($sef? $arComponents[$i][
"DATA"][
"PARAMS"][
"SEF_FOLDER"] :
null),
442 'START_CHAR' => $arComponents[$i][
"START"],
443 'END_CHAR' => $arComponents[$i][
"END"],
444 'PARAMETERS' => serialize($arComponents[$i][
"DATA"][
"PARAMS"]),
450 if (array_key_exists(
"SEF_RULE", $arComponents[$i][
"DATA"][
"PARAMS"]))
453 $ruleMaker->
process($arComponents[$i][
"DATA"][
"PARAMS"][
"SEF_RULE"]);
456 "CONDITION" => $ruleMaker->getCondition(),
457 "RULE" => $ruleMaker->getRule(),
458 "ID" => $arComponents[$i][
"DATA"][
"COMPONENT_NAME"],
460 "SORT" => self::DEFAULT_SORT,
466 "CONDITION" =>
"#^".$arComponents[$i][
"DATA"][
"PARAMS"][
"SEF_FOLDER"].
"#",
468 "ID" => $arComponents[$i][
"DATA"][
"COMPONENT_NAME"],
470 "SORT" => self::DEFAULT_SORT,
474 static::add($siteId, $arFields);
483 static $searchMasksCache =
false;
484 if (is_array($searchMasksCache))
486 $arExc = $searchMasksCache[
"exc"];
487 $arInc = $searchMasksCache[
"inc"];
494 $inc = Config\Option::get(
"main",
"urlrewrite_include_mask",
"*.php");
495 $inc = str_replace(
"'",
"\\'", str_replace(
"*",
".*?", str_replace(
"?",
".", str_replace(
".",
"\\.", str_replace(
"\\",
"/", $inc)))));
496 $arIncTmp = explode(
";", $inc);
497 foreach ($arIncTmp as $preg_mask)
498 if (trim($preg_mask) <>
'')
499 $arInc[] =
"'^".trim($preg_mask).
"$'";
501 $exc = Config\Option::get(
"main",
"urlrewrite_exclude_mask",
"/bitrix/*;");
502 $exc = str_replace(
"'",
"\\'", str_replace(
"*",
".*?", str_replace(
"?",
".", str_replace(
".",
"\\.", str_replace(
"\\",
"/", $exc)))));
503 $arExcTmp = explode(
";", $exc);
504 foreach ($arExcTmp as $preg_mask)
505 if (trim($preg_mask) <>
'')
506 $arExc[] =
"'^".trim($preg_mask).
"$'";
508 $searchMasksCache = array(
"exc" => $arExc,
"inc" => $arInc);
511 $file = IO\Path::getName($path);
512 if (mb_substr($file, 0, 1) ===
".")
515 foreach ($arExc as $preg_mask)
516 if (preg_match($preg_mask, $path))
519 foreach ($arInc as $preg_mask)
520 if (preg_match($preg_mask, $path))