示例#1
0
 public static function OnChangeFileComponent($path, $site)
 {
     /** @global CMain $APPLICATION */
     global $APPLICATION;
     // kind of optimization
     if (!HasScriptExtension($path)) {
         return;
     }
     $docRoot = CSite::GetSiteDocRoot($site);
     CUrlRewriter::Delete(array("SITE_ID" => $site, "PATH" => $path, "ID" => "NULL"));
     if (class_exists("\\Bitrix\\Main\\Application", false)) {
         \Bitrix\Main\Component\ParametersTable::deleteByFilter(array("SITE_ID" => $site, "REAL_PATH" => $path));
     }
     $fileSrc = $APPLICATION->GetFileContent($docRoot . $path);
     $arComponents = PHPParser::ParseScript($fileSrc);
     for ($i = 0, $cnt = count($arComponents); $i < $cnt; $i++) {
         if (class_exists("\\Bitrix\\Main\\Application", false)) {
             $isSEF = is_array($arComponents[$i]["DATA"]["PARAMS"]) && $arComponents[$i]["DATA"]["PARAMS"]["SEF_MODE"] == "Y";
             \Bitrix\Main\Component\ParametersTable::add(array('SITE_ID' => $site, 'COMPONENT_NAME' => $arComponents[$i]["DATA"]["COMPONENT_NAME"], 'TEMPLATE_NAME' => $arComponents[$i]["DATA"]["TEMPLATE_NAME"], 'REAL_PATH' => $path, 'SEF_MODE' => $isSEF ? \Bitrix\Main\Component\ParametersTable::SEF_MODE : \Bitrix\Main\Component\ParametersTable::NOT_SEF_MODE, 'SEF_FOLDER' => $isSEF ? $arComponents[$i]["DATA"]["PARAMS"]["SEF_FOLDER"] : null, 'START_CHAR' => $arComponents[$i]["START"], 'END_CHAR' => $arComponents[$i]["END"], 'PARAMETERS' => serialize($arComponents[$i]["DATA"]["PARAMS"])));
         }
         if (isset($arComponents[$i]["DATA"]["PARAMS"]) && is_array($arComponents[$i]["DATA"]["PARAMS"])) {
             if (array_key_exists("SEF_MODE", $arComponents[$i]["DATA"]["PARAMS"]) && $arComponents[$i]["DATA"]["PARAMS"]["SEF_MODE"] == "Y") {
                 if (array_key_exists("SEF_RULE", $arComponents[$i]["DATA"]["PARAMS"])) {
                     $ruleMaker = new \Bitrix\Main\UrlRewriterRuleMaker();
                     $ruleMaker->process($arComponents[$i]["DATA"]["PARAMS"]["SEF_RULE"]);
                     CUrlRewriter::Add(array("SITE_ID" => $site, "CONDITION" => $ruleMaker->getCondition(), "RULE" => $ruleMaker->getRule(), "ID" => $arComponents[$i]["DATA"]["COMPONENT_NAME"], "PATH" => $path));
                 } else {
                     CUrlRewriter::Add(array("SITE_ID" => $site, "CONDITION" => "#^" . $arComponents[$i]["DATA"]["PARAMS"]["SEF_FOLDER"] . "#", "ID" => $arComponents[$i]["DATA"]["COMPONENT_NAME"], "PATH" => $path));
                 }
             }
         }
     }
 }
示例#2
0
 public static function ReindexFile($path, $SEARCH_SESS_ID = "", $max_file_size = 0)
 {
     global $APPLICATION;
     CMain::InitPathVars($site, $path);
     $DOC_ROOT = CSite::GetSiteDocRoot($site);
     if (!CUrlRewriter::CheckPath($path)) {
         return 0;
     }
     if ($max_file_size > 0 && filesize($DOC_ROOT . "/" . $path) > $max_file_size * 1024) {
         return 0;
     }
     $filesrc = $APPLICATION->GetFileContent($DOC_ROOT . "/" . $path);
     if (!$filesrc || $filesrc == "") {
         return 0;
     }
     $arComponents = PHPParser::ParseScript($filesrc);
     for ($i = 0, $cnt = count($arComponents); $i < $cnt; $i++) {
         if ($arComponents[$i]["DATA"]["PARAMS"]["SEF_MODE"] == "Y") {
             if (array_key_exists("SEF_RULE", $arComponents[$i]["DATA"]["PARAMS"])) {
                 $ruleMaker = new \Bitrix\Main\UrlRewriterRuleMaker();
                 $ruleMaker->process($arComponents[$i]["DATA"]["PARAMS"]["SEF_RULE"]);
                 CUrlRewriter::Add(array("SITE_ID" => $site, "CONDITION" => $ruleMaker->getCondition(), "RULE" => $ruleMaker->getRule(), "ID" => $arComponents[$i]["DATA"]["COMPONENT_NAME"], "PATH" => $path));
             } else {
                 CUrlRewriter::Add(array("SITE_ID" => $site, "CONDITION" => "#^" . $arComponents[$i]["DATA"]["PARAMS"]["SEF_FOLDER"] . "#", "RULE" => "", "ID" => $arComponents[$i]["DATA"]["COMPONENT_NAME"], "PATH" => $path));
             }
         }
     }
     return true;
 }