Beispiel #1
0
 function IndexIBlockElement($arFields, $entity_id, $entity_type, $feature, $operation, $path_template, $arFieldList)
 {
     $ID = intval($arFields["ID"]);
     $IBLOCK_ID = intval($arFields["IBLOCK_ID"]);
     $IBLOCK_SECTION_ID = is_array($arFields["IBLOCK_SECTION"]) ? $arFields["IBLOCK_SECTION"][0] : $arFields["IBLOCK_SECTION"];
     $arItem = array();
     if ($entity_type == "G") {
         $url = str_replace(array("#group_id#", "#user_alias#", "#section_id#", "#element_id#", "#action#", "#task_id#", "#name#"), array($entity_id, "group_" . $entity_id, $IBLOCK_SECTION_ID, $arFields["ID"], "view", $arFields["ID"], urlencode($arFields["NAME"])), $path_template);
     } else {
         $url = str_replace(array("#user_id#", "#user_alias#", "#section_id#", "#element_id#", "#action#", "#task_id#"), array($entity_id, "user_" . $entity_id, $IBLOCK_SECTION_ID, $arFields["ID"], "view", $arFields["ID"]), $path_template);
     }
     $body = "";
     if ($feature == "wiki") {
         $CWikiParser = new CWikiParser();
     }
     foreach ($arFieldList as $field) {
         if ($field == "PREVIEW_TEXT" || $field == "DETAIL_TEXT") {
             if (isset($CWikiParser)) {
                 $arFields[$field] = HTMLToTxt($CWikiParser->parseForSearch($arFields[$field]));
             } elseif (isset($arFields[$field . "_TYPE"]) && $arFields[$field . "_TYPE"] === "html") {
                 $arFields[$field] = HTMLToTxt($arFields[$field]);
             }
         }
         $body .= $arFields[$field] . "\n\r";
     }
     if (isset($CWikiParser)) {
         $title = preg_replace('/^category:/i' . BX_UTF_PCRE_MODIFIER, GetMessage('CATEGORY_NAME') . ':', $arFields['NAME']);
     } else {
         $title = $arFields["NAME"];
     }
     $arPermissions = $this->GetSearchGroups($entity_type, $entity_id, $feature, $operation);
     if (CIBlock::GetArrayByID($IBLOCK_ID, "RIGHTS_MODE") == "E") {
         $obElementRights = new CIBlockElementRights($IBLOCK_ID, $arFields["ID"]);
         $arPermissions = $obElementRights->GetGroups(array("element_read"));
     }
     $arSearchIndexParams = $this->GetSearchParams($entity_type, $entity_id, $feature, $operation);
     CSearch::Index("socialnetwork", $ID, array("LAST_MODIFIED" => ConvertTimeStamp(time() + CTimeZone::GetOffset(), "FULL"), "TITLE" => $title, "BODY" => $body, "SITE_ID" => array(SITE_ID => $url), "PARAM1" => CIBlock::GetArrayByID($IBLOCK_ID, "IBLOCK_TYPE_ID"), "PARAM2" => $IBLOCK_ID, "PARAM3" => $feature, "TAGS" => $arFields["TAGS"], "PERMISSIONS" => $arPermissions, "PARAMS" => $arSearchIndexParams), true);
     if (defined("BX_COMP_MANAGED_CACHE")) {
         $GLOBALS["CACHE_MANAGER"]->ClearByTag("sonet_search_" . $entity_type . "_" . $entity_id);
     }
 }
Beispiel #2
0
 public static function OnSearchReindex($NS = array(), $oCallback = NULL, $callback_method = "")
 {
     /** @global CUserTypeManager $USER_FIELD_MANAGER */
     global $USER_FIELD_MANAGER;
     /** $global CDatabase $DB */
     global $DB;
     $strNSJoin1 = "";
     $strNSFilter1 = "";
     $strNSFilter2 = "";
     $strNSFilter3 = "";
     $arResult = array();
     if ($NS["MODULE"] == "iblock" && strlen($NS["ID"]) > 0) {
         $arrTmp = explode(".", $NS["ID"]);
         $strNSFilter1 = " AND B.ID>=" . IntVal($arrTmp[0]) . " ";
         if (substr($arrTmp[1], 0, 1) != 'S') {
             $strNSFilter2 = " AND BE.ID>" . IntVal($arrTmp[1]) . " ";
         } else {
             $strNSFilter2 = false;
             $strNSFilter3 = " AND BS.ID>" . IntVal(substr($arrTmp[1], 1)) . " ";
         }
     }
     if ($NS["SITE_ID"] != "") {
         $strNSJoin1 .= " INNER JOIN b_iblock_site BS ON BS.IBLOCK_ID=B.ID ";
         $strNSFilter1 .= " AND BS.SITE_ID='" . $DB->ForSQL($NS["SITE_ID"]) . "' ";
     }
     $strSql = "\n\t\t\tSELECT B.ID, B.IBLOCK_TYPE_ID, B.INDEX_ELEMENT, B.INDEX_SECTION, B.RIGHTS_MODE,\n\t\t\t\tB.IBLOCK_TYPE_ID, B.CODE as IBLOCK_CODE, B.XML_ID as IBLOCK_EXTERNAL_ID\n\t\t\tFROM b_iblock B\n\t\t\t" . $strNSJoin1 . "\n\t\t\tWHERE B.ACTIVE = 'Y'\n\t\t\t\tAND (B.INDEX_ELEMENT='Y' OR B.INDEX_SECTION='Y')\n\t\t\t\t" . $strNSFilter1 . "\n\t\t\tORDER BY B.ID\n\t\t";
     $dbrIBlock = $DB->Query($strSql);
     while ($arIBlock = $dbrIBlock->Fetch()) {
         $IBLOCK_ID = $arIBlock["ID"];
         $arGroups = array();
         $strSql = "SELECT GROUP_ID " . "FROM b_iblock_group " . "WHERE IBLOCK_ID= " . $IBLOCK_ID . " " . "\tAND PERMISSION>='R' " . "\tAND GROUP_ID>1 " . "ORDER BY GROUP_ID";
         $dbrIBlockGroup = $DB->Query($strSql);
         while ($arIBlockGroup = $dbrIBlockGroup->Fetch()) {
             $arGroups[] = $arIBlockGroup["GROUP_ID"];
             if ($arIBlockGroup["GROUP_ID"] == 2) {
                 break;
             }
         }
         $arSITE = array();
         $strSql = "SELECT SITE_ID " . "FROM b_iblock_site " . "WHERE IBLOCK_ID= " . $IBLOCK_ID;
         $dbrIBlockSite = $DB->Query($strSql);
         while ($arIBlockSite = $dbrIBlockSite->Fetch()) {
             $arSITE[] = $arIBlockSite["SITE_ID"];
         }
         if ($arIBlock["INDEX_ELEMENT"] == 'Y' && $strNSFilter2 !== false) {
             $strSql = "SELECT BE.ID, BE.NAME, BE.TAGS, " . "\t" . $DB->DateToCharFunction("BE.ACTIVE_FROM") . " as DATE_FROM, " . "\t" . $DB->DateToCharFunction("BE.ACTIVE_TO") . " as DATE_TO, " . "\t" . $DB->DateToCharFunction("BE.TIMESTAMP_X") . " as LAST_MODIFIED, " . "\tBE.PREVIEW_TEXT_TYPE, BE.PREVIEW_TEXT, " . "\tBE.DETAIL_TEXT_TYPE, BE.DETAIL_TEXT, " . "\tBE.XML_ID as EXTERNAL_ID, BE.CODE, " . "\tBE.IBLOCK_SECTION_ID " . "FROM b_iblock_element BE " . "WHERE BE.IBLOCK_ID=" . $IBLOCK_ID . " " . "\tAND BE.ACTIVE='Y' " . CIBlockElement::WF_GetSqlLimit("BE.", "N") . $strNSFilter2 . "ORDER BY BE.ID ";
             //For MySQL we have to solve client out of memory
             //problem by limiting the query
             if ($DB->type == "MYSQL") {
                 $limit = 1000;
                 $strSql .= " LIMIT " . $limit;
             } else {
                 $limit = false;
             }
             $dbrIBlockElement = $DB->Query($strSql);
             while ($arIBlockElement = $dbrIBlockElement->Fetch()) {
                 $DETAIL_URL = "=ID=" . $arIBlockElement["ID"] . "&EXTERNAL_ID=" . $arIBlockElement["EXTERNAL_ID"] . "&CODE=" . $arIBlockElement["CODE"] . "&IBLOCK_SECTION_ID=" . $arIBlockElement["IBLOCK_SECTION_ID"] . "&IBLOCK_TYPE_ID=" . $arIBlock["IBLOCK_TYPE_ID"] . "&IBLOCK_ID=" . $IBLOCK_ID . "&IBLOCK_CODE=" . $arIBlock["IBLOCK_CODE"] . "&IBLOCK_EXTERNAL_ID=" . $arIBlock["IBLOCK_EXTERNAL_ID"];
                 $BODY = ($arIBlockElement["PREVIEW_TEXT_TYPE"] == "html" ? CSearch::KillTags($arIBlockElement["PREVIEW_TEXT"]) : $arIBlockElement["PREVIEW_TEXT"]) . "\r\n" . ($arIBlockElement["DETAIL_TEXT_TYPE"] == "html" ? CSearch::KillTags($arIBlockElement["DETAIL_TEXT"]) : $arIBlockElement["DETAIL_TEXT"]);
                 $dbrProperties = CIBlockElement::GetProperty($IBLOCK_ID, $arIBlockElement["ID"], "sort", "asc", array("ACTIVE" => "Y", "SEARCHABLE" => "Y"));
                 while ($arProperties = $dbrProperties->Fetch()) {
                     $BODY .= "\r\n";
                     if (strlen($arProperties["USER_TYPE"]) > 0) {
                         $UserType = CIBlockProperty::GetUserType($arProperties["USER_TYPE"]);
                     } else {
                         $UserType = array();
                     }
                     if (array_key_exists("GetSearchContent", $UserType)) {
                         $BODY .= CSearch::KillTags(call_user_func_array($UserType["GetSearchContent"], array($arProperties['ID'], array("VALUE" => $arProperties["VALUE"]), array())));
                     } elseif (array_key_exists("GetPublicViewHTML", $UserType)) {
                         $BODY .= CSearch::KillTags(call_user_func_array($UserType["GetPublicViewHTML"], array($arProperties['ID'], array("VALUE" => $arProperties["VALUE"]), array())));
                     } elseif ($arProperties["PROPERTY_TYPE"] == 'L') {
                         $BODY .= $arProperties["VALUE_ENUM"];
                     } elseif ($arProperties["PROPERTY_TYPE"] == 'F') {
                         $arFile = CIBlockElement::__GetFileContent($arProperties["VALUE"]);
                         if (is_array($arFile)) {
                             $BODY .= $arFile["CONTENT"];
                             $arIBlockElement["TAGS"] .= "," . $arFile["PROPERTIES"][COption::GetOptionString("search", "page_tag_property")];
                         }
                     } else {
                         $BODY .= $arProperties["VALUE"];
                     }
                 }
                 if ($arIBlock["RIGHTS_MODE"] !== "E") {
                     $arPermissions = $arGroups;
                 } else {
                     $obElementRights = new CIBlockElementRights($IBLOCK_ID, $arIBlockElement["ID"]);
                     $arPermissions = $obElementRights->GetGroups(array("element_read"));
                 }
                 $Result = array("ID" => $arIBlockElement["ID"], "LAST_MODIFIED" => strlen($arIBlockElement["DATE_FROM"]) > 0 ? $arIBlockElement["DATE_FROM"] : $arIBlockElement["LAST_MODIFIED"], "TITLE" => $arIBlockElement["NAME"], "BODY" => $BODY, "TAGS" => $arIBlockElement["TAGS"], "SITE_ID" => $arSITE, "PARAM1" => $arIBlock["IBLOCK_TYPE_ID"], "PARAM2" => $IBLOCK_ID, "DATE_FROM" => strlen($arIBlockElement["DATE_FROM"]) > 0 ? $arIBlockElement["DATE_FROM"] : false, "DATE_TO" => strlen($arIBlockElement["DATE_TO"]) > 0 ? $arIBlockElement["DATE_TO"] : false, "PERMISSIONS" => $arPermissions, "URL" => $DETAIL_URL);
                 if ($oCallback) {
                     $res = call_user_func(array($oCallback, $callback_method), $Result);
                     if (!$res) {
                         return $IBLOCK_ID . "." . $arIBlockElement["ID"];
                     }
                 } else {
                     $arResult[] = $Result;
                 }
                 if ($limit !== false) {
                     $limit--;
                     if ($limit <= 0) {
                         return $IBLOCK_ID . "." . $arIBlockElement["ID"];
                     }
                 }
             }
         }
         if ($arIBlock["INDEX_SECTION"] == 'Y') {
             $strSql = "SELECT BS.ID, BS.NAME, " . "\t" . $DB->DateToCharFunction("BS.TIMESTAMP_X") . " as LAST_MODIFIED, " . "\tBS.DESCRIPTION_TYPE, BS.DESCRIPTION, BS.XML_ID as EXTERNAL_ID, BS.CODE, " . "\tBS.IBLOCK_ID " . "FROM b_iblock_section BS " . "WHERE BS.IBLOCK_ID=" . $IBLOCK_ID . " " . "\tAND BS.GLOBAL_ACTIVE='Y' " . $strNSFilter3 . "ORDER BY BS.ID ";
             $dbrIBlockSection = $DB->Query($strSql);
             while ($arIBlockSection = $dbrIBlockSection->Fetch()) {
                 $DETAIL_URL = "=ID=" . $arIBlockSection["ID"] . "&EXTERNAL_ID=" . $arIBlockSection["EXTERNAL_ID"] . "&CODE=" . $arIBlockSection["CODE"] . "&IBLOCK_TYPE_ID=" . $arIBlock["IBLOCK_TYPE_ID"] . "&IBLOCK_ID=" . $arIBlockSection["IBLOCK_ID"] . "&IBLOCK_CODE=" . $arIBlock["IBLOCK_CODE"] . "&IBLOCK_EXTERNAL_ID=" . $arIBlock["IBLOCK_EXTERNAL_ID"];
                 $BODY = $arIBlockSection["DESCRIPTION_TYPE"] == "html" ? CSearch::KillTags($arIBlockSection["DESCRIPTION"]) : $arIBlockSection["DESCRIPTION"];
                 $BODY .= $USER_FIELD_MANAGER->OnSearchIndex("IBLOCK_" . $arIBlockSection["IBLOCK_ID"] . "_SECTION", $arIBlockSection["ID"]);
                 if ($arIBlock["RIGHTS_MODE"] !== "E") {
                     $arPermissions = $arGroups;
                 } else {
                     $obSectionRights = new CIBlockSectionRights($IBLOCK_ID, $arIBlockSection["ID"]);
                     $arPermissions = $obSectionRights->GetGroups(array("section_read"));
                 }
                 $Result = array("ID" => "S" . $arIBlockSection["ID"], "LAST_MODIFIED" => $arIBlockSection["LAST_MODIFIED"], "TITLE" => $arIBlockSection["NAME"], "BODY" => $BODY, "SITE_ID" => $arSITE, "PARAM1" => $arIBlock["IBLOCK_TYPE_ID"], "PARAM2" => $IBLOCK_ID, "PERMISSIONS" => $arPermissions, "URL" => $DETAIL_URL);
                 if ($oCallback) {
                     $res = call_user_func(array($oCallback, $callback_method), $Result);
                     if (!$res) {
                         return $IBLOCK_ID . ".S" . $arIBlockSection["ID"];
                     }
                 } else {
                     $arResult[] = $Result;
                 }
             }
         }
         $strNSFilter2 = "";
         $strNSFilter3 = "";
     }
     if ($oCallback) {
         return false;
     }
     return $arResult;
 }
Beispiel #3
0
 function UpdateSearch($ID, $bOverWrite = false)
 {
     if (!CModule::IncludeModule("search")) {
         return;
     }
     global $DB;
     $ID = Intval($ID);
     static $strElementSql = false;
     if (!$strElementSql) {
         $strElementSql = "\n\t\t\t\tSELECT BE.ID, BE.NAME, BE.XML_ID as EXTERNAL_ID,\n\t\t\t\t\tBE.PREVIEW_TEXT_TYPE, BE.PREVIEW_TEXT, BE.CODE,\n\t\t\t\t\tBE.TAGS,\n\t\t\t\t\tBE.DETAIL_TEXT_TYPE, BE.DETAIL_TEXT, BE.IBLOCK_ID, B.IBLOCK_TYPE_ID,\n\t\t\t\t\t" . $DB->DateToCharFunction("BE.TIMESTAMP_X") . " as LAST_MODIFIED,\n\t\t\t\t\t" . $DB->DateToCharFunction("BE.ACTIVE_FROM") . " as DATE_FROM,\n\t\t\t\t\t" . $DB->DateToCharFunction("BE.ACTIVE_TO") . " as DATE_TO,\n\t\t\t\t\tBE.IBLOCK_SECTION_ID,\n\t\t\t\t\tB.CODE as IBLOCK_CODE, B.XML_ID as IBLOCK_EXTERNAL_ID, B.DETAIL_PAGE_URL,\n\t\t\t\t\tB.VERSION, B.RIGHTS_MODE, B.SOCNET_GROUP_ID\n\t\t\t\tFROM b_iblock_element BE, b_iblock B\n\t\t\t\tWHERE BE.IBLOCK_ID=B.ID\n\t\t\t\t\tAND B.ACTIVE='Y'\n\t\t\t\t\tAND BE.ACTIVE='Y'\n\t\t\t\t\tAND B.INDEX_ELEMENT='Y'\n\t\t\t\t\t" . CIBlockElement::WF_GetSqlLimit("BE.", "N") . "\n\t\t\t\t\tAND BE.ID=";
     }
     $dbrIBlockElement = $DB->Query($strElementSql . $ID);
     if ($arIBlockElement = $dbrIBlockElement->Fetch()) {
         $IBLOCK_ID = $arIBlockElement["IBLOCK_ID"];
         $DETAIL_URL = "=ID=" . urlencode($arIBlockElement["ID"]) . "&EXTERNAL_ID=" . urlencode($arIBlockElement["EXTERNAL_ID"]) . "&IBLOCK_SECTION_ID=" . urlencode($arIBlockElement["IBLOCK_SECTION_ID"]) . "&IBLOCK_TYPE_ID=" . urlencode($arIBlockElement["IBLOCK_TYPE_ID"]) . "&IBLOCK_ID=" . urlencode($arIBlockElement["IBLOCK_ID"]) . "&IBLOCK_CODE=" . urlencode($arIBlockElement["IBLOCK_CODE"]) . "&IBLOCK_EXTERNAL_ID=" . urlencode($arIBlockElement["IBLOCK_EXTERNAL_ID"]) . "&CODE=" . urlencode($arIBlockElement["CODE"]);
         static $arGroups = array();
         if (!array_key_exists($IBLOCK_ID, $arGroups)) {
             $arGroups[$IBLOCK_ID] = array();
             $strSql = "SELECT GROUP_ID " . "FROM b_iblock_group " . "WHERE IBLOCK_ID= " . $IBLOCK_ID . " " . "\tAND PERMISSION>='R' " . "ORDER BY GROUP_ID";
             $dbrIBlockGroup = $DB->Query($strSql);
             while ($arIBlockGroup = $dbrIBlockGroup->Fetch()) {
                 $arGroups[$IBLOCK_ID][] = $arIBlockGroup["GROUP_ID"];
                 if ($arIBlockGroup["GROUP_ID"] == 2) {
                     break;
                 }
             }
         }
         static $arSITE = array();
         if (!array_key_exists($IBLOCK_ID, $arSITE)) {
             $arSITE[$IBLOCK_ID] = array();
             $strSql = "SELECT SITE_ID " . "FROM b_iblock_site " . "WHERE IBLOCK_ID= " . $IBLOCK_ID;
             $dbrIBlockSite = $DB->Query($strSql);
             while ($arIBlockSite = $dbrIBlockSite->Fetch()) {
                 $arSITE[$IBLOCK_ID][] = $arIBlockSite["SITE_ID"];
             }
         }
         $BODY = ($arIBlockElement["PREVIEW_TEXT_TYPE"] == "html" ? CSearch::KillTags($arIBlockElement["PREVIEW_TEXT"]) : $arIBlockElement["PREVIEW_TEXT"]) . "\r\n" . ($arIBlockElement["DETAIL_TEXT_TYPE"] == "html" ? CSearch::KillTags($arIBlockElement["DETAIL_TEXT"]) : $arIBlockElement["DETAIL_TEXT"]);
         static $arProperties = array();
         if (!array_key_exists($IBLOCK_ID, $arProperties)) {
             $arProperties[$IBLOCK_ID] = array();
             $rsProperties = CIBlockProperty::GetList(array("sort" => "asc", "id" => "asc"), array("IBLOCK_ID" => $IBLOCK_ID, "ACTIVE" => "Y", "SEARCHABLE" => "Y", "CHECK_PERMISSIONS" => "N"));
             while ($ar = $rsProperties->Fetch()) {
                 if (strlen($ar["USER_TYPE"]) > 0) {
                     $arUT = CIBlockProperty::GetUserType($ar["USER_TYPE"]);
                     if (array_key_exists("GetSearchContent", $arUT)) {
                         $ar["GetSearchContent"] = $arUT["GetSearchContent"];
                     } elseif (array_key_exists("GetPublicViewHTML", $arUT)) {
                         $ar["GetSearchContent"] = $arUT["GetPublicViewHTML"];
                     }
                 }
                 $arProperties[$IBLOCK_ID][$ar["ID"]] = $ar;
             }
         }
         //Read current property values from database
         $strProperties = "";
         if (count($arProperties[$IBLOCK_ID]) > 0) {
             if ($arIBlockElement["VERSION"] == 1) {
                 $rs = $DB->Query("\n\t\t\t\t\t\tselect *\n\t\t\t\t\t\tfrom b_iblock_element_property\n\t\t\t\t\t\twhere IBLOCK_ELEMENT_ID=" . $arIBlockElement["ID"] . "\n\t\t\t\t\t\tAND IBLOCK_PROPERTY_ID in (" . implode(", ", array_keys($arProperties[$IBLOCK_ID])) . ")\n\t\t\t\t\t");
                 while ($ar = $rs->Fetch()) {
                     $strProperties .= "\r\n";
                     $arProperty = $arProperties[$IBLOCK_ID][$ar["IBLOCK_PROPERTY_ID"]];
                     if ($arProperty["GetSearchContent"]) {
                         $strProperties .= CSearch::KillTags(call_user_func_array($arProperty["GetSearchContent"], array($arProperty, array("VALUE" => $ar["VALUE"]), array())));
                     } elseif ($arProperty["PROPERTY_TYPE"] == 'L') {
                         $arEnum = CIBlockPropertyEnum::GetByID($ar["VALUE"]);
                         if ($arEnum !== false) {
                             $strProperties .= $arEnum["VALUE"];
                         }
                     } elseif ($arProperty["PROPERTY_TYPE"] == 'F') {
                         $arFile = CIBlockElement::__GetFileContent($ar["VALUE"]);
                         if (is_array($arFile)) {
                             $strProperties .= $arFile["CONTENT"];
                             $arIBlockElement["TAGS"] .= "," . $arFile["PROPERTIES"][COption::GetOptionString("search", "page_tag_property")];
                         }
                     } else {
                         $strProperties .= $ar["VALUE"];
                     }
                 }
             } else {
                 $rs = $DB->Query("\n\t\t\t\t\t\tselect *\n\t\t\t\t\t\tfrom b_iblock_element_prop_m" . $IBLOCK_ID . "\n\t\t\t\t\t\twhere IBLOCK_ELEMENT_ID=" . $arIBlockElement["ID"] . "\n\t\t\t\t\t\tAND IBLOCK_PROPERTY_ID in (" . implode(", ", array_keys($arProperties[$IBLOCK_ID])) . ")\n\t\t\t\t\t");
                 while ($ar = $rs->Fetch()) {
                     $strProperties .= "\r\n";
                     $arProperty = $arProperties[$IBLOCK_ID][$ar["IBLOCK_PROPERTY_ID"]];
                     if ($arProperty["GetSearchContent"]) {
                         $strProperties .= CSearch::KillTags(call_user_func_array($arProperty["GetSearchContent"], array($arProperty, array("VALUE" => $ar["VALUE"]), array())));
                     } elseif ($arProperty["PROPERTY_TYPE"] == 'L') {
                         $arEnum = CIBlockPropertyEnum::GetByID($ar["VALUE"]);
                         if ($arEnum !== false) {
                             $strProperties .= $arEnum["VALUE"];
                         }
                     } elseif ($arProperty["PROPERTY_TYPE"] == 'F') {
                         $arFile = CIBlockElement::__GetFileContent($ar["VALUE"]);
                         if (is_array($arFile)) {
                             $strProperties .= $arFile["CONTENT"];
                             $arIBlockElement["TAGS"] .= "," . $arFile["PROPERTIES"][COption::GetOptionString("search", "page_tag_property")];
                         }
                     } else {
                         $strProperties .= $ar["VALUE"];
                     }
                 }
                 $rs = $DB->Query("\n\t\t\t\t\t\tselect *\n\t\t\t\t\t\tfrom b_iblock_element_prop_s" . $IBLOCK_ID . "\n\t\t\t\t\t\twhere IBLOCK_ELEMENT_ID=" . $arIBlockElement["ID"] . "\n\t\t\t\t\t");
                 if ($ar = $rs->Fetch()) {
                     foreach ($arProperties[$IBLOCK_ID] as $property_id => $property) {
                         if (array_key_exists("PROPERTY_" . $property_id, $ar) && $property["MULTIPLE"] == "N" && strlen($ar["PROPERTY_" . $property_id]) > 0) {
                             $strProperties .= "\r\n";
                             if ($property["GetSearchContent"]) {
                                 $strProperties .= CSearch::KillTags(call_user_func_array($property["GetSearchContent"], array($property, array("VALUE" => $ar["PROPERTY_" . $property_id]), array())));
                             } elseif ($property["PROPERTY_TYPE"] == 'L') {
                                 $arEnum = CIBlockPropertyEnum::GetByID($ar["PROPERTY_" . $property_id]);
                                 if ($arEnum !== false) {
                                     $strProperties .= $arEnum["VALUE"];
                                 }
                             } elseif ($property["PROPERTY_TYPE"] == 'F') {
                                 $arFile = CIBlockElement::__GetFileContent($ar["PROPERTY_" . $property_id]);
                                 if (is_array($arFile)) {
                                     $strProperties .= $arFile["CONTENT"];
                                     $arIBlockElement["TAGS"] .= "," . $arFile["PROPERTIES"][COption::GetOptionString("search", "page_tag_property")];
                                 }
                             } else {
                                 $strProperties .= $ar["PROPERTY_" . $property_id];
                             }
                         }
                     }
                 }
             }
         }
         $BODY .= $strProperties;
         if ($arIBlockElement["RIGHTS_MODE"] !== "E") {
             $arPermissions = $arGroups[$IBLOCK_ID];
         } else {
             $obElementRights = new CIBlockElementRights($IBLOCK_ID, $arIBlockElement["ID"]);
             $arPermissions = $obElementRights->GetGroups(array("element_read"));
         }
         $arFields = array("LAST_MODIFIED" => strlen($arIBlockElement["DATE_FROM"]) > 0 ? $arIBlockElement["DATE_FROM"] : $arIBlockElement["LAST_MODIFIED"], "DATE_FROM" => strlen($arIBlockElement["DATE_FROM"]) > 0 ? $arIBlockElement["DATE_FROM"] : false, "DATE_TO" => strlen($arIBlockElement["DATE_TO"]) > 0 ? $arIBlockElement["DATE_TO"] : false, "TITLE" => $arIBlockElement["NAME"], "PARAM1" => $arIBlockElement["IBLOCK_TYPE_ID"], "PARAM2" => $IBLOCK_ID, "SITE_ID" => $arSITE[$IBLOCK_ID], "PERMISSIONS" => $arPermissions, "URL" => $DETAIL_URL, "BODY" => $BODY, "TAGS" => $arIBlockElement["TAGS"]);
         if ($arIBlockElement["SOCNET_GROUP_ID"] > 0) {
             $arFields["PARAMS"] = array("socnet_group" => $arIBlockElement["SOCNET_GROUP_ID"]);
         }
         CSearch::Index("iblock", $ID, $arFields, $bOverWrite);
     } else {
         CSearch::DeleteIndex("iblock", $ID);
     }
 }
Beispiel #4
0
 function ReindexIBlock($iblock_id, $entity_type, $feature, $operation, $path_template, $arFieldList, $last_id)
 {
     global $DB;
     if (!CModule::IncludeModule("iblock")) {
         return false;
     }
     $arSections = array();
     $rsElements = CIBlockElement::GetList(array("ID" => "asc"), array("IBLOCK_ID" => $iblock_id, ">ID" => intval($last_id), "CHECK_PERMISSIONS" => "N"), false, false, array_merge(array("ID", "IBLOCK_ID", "IBLOCK_TYPE_ID", "NAME", "TAGS", "TIMESTAMP_X", "IBLOCK_SECTION_ID"), $arFieldList));
     while ($arFields = $rsElements->Fetch()) {
         if (!array_key_exists($arFields["IBLOCK_SECTION_ID"], $arSections)) {
             $rsPath = CIBlockSection::GetNavChain($arFields["IBLOCK_ID"], $arFields["IBLOCK_SECTION_ID"]);
             $arSection = $rsPath->Fetch();
             if ($entity_type == "G") {
                 $arSections[$arFields["IBLOCK_SECTION_ID"]] = intval($arSection["SOCNET_GROUP_ID"]);
             } else {
                 $arSections[$arFields["IBLOCK_SECTION_ID"]] = intval($arSection["CREATED_BY"]);
             }
         }
         $entity_id = $arSections[$arFields["IBLOCK_SECTION_ID"]];
         if ($entity_id) {
             $url = str_replace(array("#user_id#", "#group_id#", "#user_alias#", "#section_id#", "#element_id#", "#task_id#", "#name#"), array($entity_id, $entity_id, ($entity_type == "G" ? "group_" : "user_") . $entity_id, $arFields["IBLOCK_SECTION_ID"], $arFields["ID"], $arFields["ID"], urlencode($arFields["NAME"])), $path_template);
             $body = "";
             if ($feature == "wiki") {
                 $CWikiParser = new CWikiParser();
             }
             foreach ($arFieldList as $field) {
                 $text = "";
                 if ($field == "PREVIEW_TEXT" || $field == "DETAIL_TEXT") {
                     if (isset($CWikiParser)) {
                         $text = HTMLToTxt($CWikiParser->parseForSearch($arFields[$field]));
                     } elseif (isset($arFields[$field . "_TYPE"]) && $arFields[$field . "_TYPE"] === "html") {
                         $text = HTMLToTxt($arFields[$field]);
                     } else {
                         $text = $arFields[$field];
                     }
                 } elseif ($field == $this->_file_property) {
                     $arFile = CIBlockElement::__GetFileContent($arFields[$this->_file_property . "_VALUE"]);
                     if (is_array($arFile)) {
                         $text = $arFile["CONTENT"];
                         $arFields["TAGS"] .= "," . $arFile["PROPERTIES"][COption::GetOptionString("search", "page_tag_property")];
                     }
                 } elseif ($field == "PROPERTY_FORUM_TOPIC_ID") {
                     $topic_id = intval($arFields["PROPERTY_FORUM_TOPIC_ID_VALUE"]);
                     if ($topic_id) {
                         $this->UpdateForumTopicIndex($topic_id, $entity_type, $entity_id, $feature, $operation, $this->Url($url, array("MID" => "#message_id#"), "message#message_id#"));
                     }
                 }
                 $body .= $text . "\n\r";
             }
             if (isset($CWikiParser)) {
                 $title = preg_replace('/^category:/i' . BX_UTF_PCRE_MODIFIER, GetMessage('CATEGORY_NAME') . ':', $arFields['NAME']);
             } else {
                 $title = $arFields["NAME"];
             }
             $arPermissions = $this->GetSearchGroups($entity_type, $entity_id, $feature, $operation);
             if (CIBlock::GetArrayByID($arFields["IBLOCK_ID"], "RIGHTS_MODE") == "E") {
                 $obElementRights = new CIBlockElementRights($arFields["IBLOCK_ID"], $arFields["ID"]);
                 $arPermissions = $obElementRights->GetGroups(array("element_read"));
             }
             CSearch::Index("socialnetwork", $arFields["ID"], array("LAST_MODIFIED" => $arFields["TIMESTAMP_X"], "TITLE" => $title, "BODY" => $body, "SITE_ID" => array(SITE_ID => $url), "PARAM1" => $arFields["IBLOCK_TYPE_ID"], "PARAM2" => $arFields["IBLOCK_ID"], "PARAM3" => $entity_id, "TAGS" => $arFields["TAGS"], "PERMISSIONS" => $arPermissions, "PARAMS" => $this->GetSearchParams($entity_type, $entity_id, $feature, $operation), "REINDEX_FLAG" => true), true, $this->_sess_id);
             $this->_counter++;
         }
         if ($this->_end_time && $this->_end_time <= time()) {
             return $arFields["ID"];
         }
     }
     return false;
 }