Example #1
0
 function PROPFIND(&$options, &$files, $arParams = array())
 {
     global $DB;
     if (empty($files)) {
         $files = array();
     }
     $files["files"] = array();
     $arParams = is_array($arParams) ? $arParams : array();
     if ($this->e_rights) {
         $options['check_permissions'] = false;
     }
     $this->IsDir($options);
     $arParamsIsDir = $this->arParams;
     $arResult = array("NAV_RESULT" => false, "RESULT" => array());
     if ($arParamsIsDir["not_found"] === true) {
         $msg = $arParamsIsDir['parent_id'] === false ? GetMessage("WD_FOLDER_NOT_FOUND") : GetMessage("WD_FILE_NOT_FOUND");
         return $this->ThrowError("404 Not Found", "DESTINATION_FILE_OR_FOLDER_IS_NOT_FOUND", $msg, __LINE__);
     } elseif ($arParamsIsDir["is_dir"] != true) {
         $db_res = $this->_get_mixed_list(intVal($arParamsIsDir["parent_id"]), $arParams, intVal($arParamsIsDir["item_id"]));
         if ($db_res && ($res = $db_res->Fetch())) {
             if ($this->MetaNames($res)) {
                 $files["files"]["F" . $res["ID"]] = $this->_get_file_info_arr($res, $arParams);
                 if ($arParams["return"] == "array") {
                     $files["files"]["F" . $res["ID"]] = $res;
                 }
                 $arResult["RESULT"]["E" . $res["ID"]] = $res;
                 // dummy
             }
         }
     } else {
         if (!empty($arParamsIsDir['dir_array'][self::UF_LINK_SECTION_ID])) {
             $linkWebdav = new self($arParamsIsDir['dir_array'][self::UF_LINK_IBLOCK_ID], $this->base_url . $this->_path, array_merge($this->_originalParams, array('ROOT_SECTION_ID' => $arParamsIsDir['dir_array'][self::UF_LINK_SECTION_ID], 'symlinkMode' => true, 'symlinkSectionData' => $arParamsIsDir['dir_array'], 'symlinkRealRootSectionData' => $this->arRootSection)));
             $options = array('path' => '/', 'depth' => 1, 'check_permissions' => false);
             $params = array_merge($arParams, array('PARENT_ID' => $arParamsIsDir['dir_array'][self::UF_LINK_SECTION_ID]));
             $linkWebdav->_path = $this->_path;
             return $linkWebdav->PROPFIND($options, $files, $params);
         }
         //simple detect symlink
         list($contextType, $contextEntityId) = $this->getContextData();
         if ($arParamsIsDir['dir_array']) {
             $sectionData = $this->getSectionDataForLinkAnalyze($arParamsIsDir['dir_array']['ID'], array('IBLOCK_ID' => $arParamsIsDir['dir_array']['IBLOCK_ID'], 'ID' => $arParamsIsDir['dir_array']['ID']));
             if (!$this->_symlinkMode && CWebDavSymlinkHelper::isLink($contextType, $contextEntityId, $sectionData)) {
                 $symlinkSectionData = CWebDavSymlinkHelper::getLinkData($contextType, $contextEntityId, $sectionData);
             }
         }
         if (!empty($symlinkSectionData)) {
             $linkWebdav = new self($symlinkSectionData[self::UF_LINK_IBLOCK_ID], $this->base_url . $this->_path, array_merge($this->_originalParams, array('ROOT_SECTION_ID' => $symlinkSectionData[self::UF_LINK_SECTION_ID], 'symlinkMode' => true, 'symlinkSectionData' => $symlinkSectionData, 'symlinkRealRootSectionData' => $this->arRootSection)));
             $options = array('path' => '/', 'depth' => 1, 'check_permissions' => false);
             $params = array_merge($arParams, array('PARENT_ID' => $arParamsIsDir['dir_array']['ID']));
             $linkWebdav->_path = $this->_path;
             return $linkWebdav->PROPFIND($options, $files, $params);
         }
         if ($arParamsIsDir["item_id"] <= 0 || $this->arRootSection["ID"] == $arParamsIsDir["item_id"]) {
             $files["files"]["iblock"] = $this->get_iblock_info($arr);
             if ($this->_symlinkMode) {
                 $files["files"]["iblock"]['path'] = $this->_path;
                 if (SITE_CHARSET != "UTF-8") {
                     $files["files"]["iblock"]['path'] = $GLOBALS["APPLICATION"]->ConvertCharset($this->_path, SITE_CHARSET, "UTF-8");
                 }
             }
             $arResult["IBLOCK"] = $arr;
         } else {
             $arResult["SECTION"] = $this->arParams["dir_array"];
             if ($this->MetaNames($arResult["SECTION"])) {
                 $files["files"]["section"] = $this->_get_section_info_arr($arResult["SECTION"]);
             } else {
                 unset($arResult["SECTION"]);
             }
         }
         if (!empty($options["depth"])) {
             if (intVal($arParamsIsDir["item_id"]) <= 0) {
                 $arParamsIsDir["item_id"] = $this->arRootSection ? $this->arRootSection["ID"] : $arParamsIsDir["item_id"];
             }
             // content search
             $arSearchResults = array();
             if (isset($arParams["FILTER"]["content"]) && strlen($arParams["FILTER"]["content"]) > 0 && IsModuleInstalled('search') && CModule::IncludeModule('search')) {
                 $obSearch = new CSearch();
                 if (preg_match("/\\.[a-zA-Z]{3,4}\$/", $arParams["FILTER"]["content"])) {
                     $arParams["FILTER"]["content"] = '"' . $arParams["FILTER"]["content"] . '"';
                 }
                 $arSearchParams = array("QUERY" => $arParams["FILTER"]["content"]);
                 if (!$this->arRootSection) {
                     $arSearchParams += array("MODULE_ID" => "iblock", "PARAM_2" => $this->IBLOCK_ID);
                 } else {
                     if (isset($this->attributes['user_id'])) {
                         $arSearchParams += array("PARAMS" => array("socnet_user" => $this->attributes['user_id']));
                     } elseif (isset($this->attributes['group_id'])) {
                         $arSearchParams += array("PARAMS" => array("socnet_group" => $this->attributes['group_id']));
                     }
                 }
                 $obSearch->Search($arSearchParams);
                 if ($obSearch->errorno != 0) {
                     $arResult["ERROR_MESSAGE"] = $obSearch->error;
                 } else {
                     while ($arSearchResultItem = $obSearch->GetNext()) {
                         $arSearchResults[$arSearchResultItem['ITEM_ID']] = true;
                     }
                 }
             }
             $arSearchOptParams = array_flip(array("SHOW_NEW", "SHOW_HISTORY", "FILE_SIZE_multiply"));
             $arParams["function"] = "propfind";
             $parentID = isset($arParams["FILTER"]) ? sizeof(array_diff_key($arParams["FILTER"], $arSearchOptParams)) == 0 ? $arParamsIsDir["item_id"] : null : $arParamsIsDir["item_id"];
             if (isset($arParams["PARENT_ID"]) && intval($arParams["PARENT_ID"]) > 0) {
                 $parentID = $arParams["PARENT_ID"];
             }
             if (!empty($arParams["FILTER"])) {
                 $arParams["FILTER"]["SHOW_NEW"] = "Y";
             }
             if ($this->meta_state == "TRASH" && $this->workflow == "bizproc") {
                 $arParams["FILTER"]["SHOW_HISTORY"] = "Y";
             }
             if (isset($arParams["FILTER"]["doctype"])) {
                 $arFileTypes = @unserialize(COption::GetOptionString("webdav", "file_types"));
                 if ($arFileTypes !== false) {
                     foreach ($arFileTypes as $arFileType) {
                         if ($arParams["FILTER"]["doctype"] == $arFileType["ID"]) {
                             $arParams["FILTER"]["extension"] = str_replace(".", "", $arFileType["EXTENSIONS"]);
                         }
                     }
                 }
                 unset($arParams["FILTER"]["doctype"]);
             }
             if (isset($arParams["FILTER"]["extension"])) {
                 $arFltExtensions = array_map('strtoupper', explode(" ", $arParams["FILTER"]["extension"]));
             }
             //$arResult["NAV_RESULT"] = $db_res;
             if (isset($arParams["FILTER"]["content"]) && sizeof(array_diff_key($arParams["FILTER"], $arSearchOptParams)) === 1) {
                 // there is only content search
                 unset($arParams["FILTER"]["content"]);
                 unset($arParams["FILTER"]["FILE_SIZE_multiply"]);
                 foreach ($arSearchResults as $itemID => $nopValue) {
                     $arParams["FILTER"]["ID"] = $itemID;
                     $db_res = $this->_get_mixed_list(null, $arParams);
                     if ($db_res && ($res = $db_res->Fetch())) {
                         if ($this->MetaNames($res)) {
                             if ($res["TYPE"] == "S") {
                                 if (!$this->MetaSectionHide($res)) {
                                     $files["files"]["S" . $res["ID"]] = $this->_get_section_info_arr($res);
                                     $arResult["RESULT"]["S" . $res["ID"]] = $res;
                                 }
                             } else {
                                 $files["files"]["F" . $res["ID"]] = $this->_get_file_info_arr($res, $arParams);
                                 $arResult["RESULT"]["E" . $res["ID"]] = $res;
                             }
                         }
                     }
                 }
             } else {
                 // there are some other fields to search
                 $db_res = $this->_get_mixed_list($parentID, $arParams);
                 if ($db_res && ($res = $db_res->Fetch())) {
                     do {
                         if (!empty($arSearchResults) && !isset($arSearchResults[$res["ID"]])) {
                             continue;
                         }
                         $this->_parse_webdav_info($res);
                         if ($this->meta_state != 'TRASH' && isset($res['PROPS']['BX:']['UNDELETE'])) {
                             continue;
                         }
                         if ($this->MetaNames($res)) {
                             if ($res["TYPE"] == "S") {
                                 if (!$this->MetaSectionHide($res)) {
                                     if (empty($arParams["FILTER"]) || $this->meta_state == "TRASH" || !empty($arParams['FILTER']['SHOW_SECTIONS'])) {
                                         $files["files"]["S" . $res["ID"]] = $this->_get_section_info_arr($res);
                                         $arResult["RESULT"]["S" . $res["ID"]] = $res;
                                     }
                                 }
                             } else {
                                 if (isset($arFltExtensions)) {
                                     $ext = GetFileExtension($res["NAME"]);
                                     if (!in_array(strtoupper($ext), $arFltExtensions)) {
                                         continue;
                                     }
                                 }
                                 $files["files"]["F" . $res["ID"]] = $this->_get_file_info_arr($res, $arParams);
                                 $arResult["RESULT"]["E" . $res["ID"]] = $res;
                             }
                         }
                     } while ($res = $db_res->Fetch());
                 }
             }
         }
     }
     if ($this->e_rights && sizeof($arResult['RESULT']) <= 0 && !$this->GetPermission('SECTION', $arParamsIsDir['item_id'], 'section_read')) {
         $options['check_permissions'] = true;
         $arParamsIsDir = $this->GetObject($options);
         if ($arParamsIsDir["not_found"] === true) {
             return $this->ThrowError("404 Not Found", "DESTINATION_FILE_OR_FOLDER_IS_NOT_FOUND", GetMessage("WD_FOLDER_NOT_FOUND"), __LINE__);
         }
     }
     if ($arParams["return"] == "array") {
         return $arResult;
     } elseif ($arParams["return"] == "nav_result") {
         $arResult["NAV_RESULT"] = new CDBResult();
         $arResult["NAV_RESULT"]->InitFromArray($arResult["RESULT"]);
         return $arResult;
     }
     return true;
 }