protected static function groupSectionCreate($groupId) { $groupLib = CWebDavIblock::LibOptions('group_files', false, SITE_ID); if (!$groupLib || !isset($groupLib['id']) || !($iblockId = intval($groupLib['id']))) { return false; } $result = CIBlockWebdavSocnet::GetSectionID($iblockId, 'group', $groupId); if (intval($result) > 0) { return $result; } $dbRes = CUserTypeEntity::GetList(array($by => $order), array("ENTITY_ID" => "IBLOCK_" . $iblockId . "_SECTION", "FIELD_NAME" => "UF_USE_BP")); if (!$dbRes || !($res = $dbRes->GetNext())) { $arFields = array("ENTITY_ID" => "IBLOCK_" . $iblockId . "_SECTION", "FIELD_NAME" => "UF_USE_BP", "USER_TYPE_ID" => "string", "MULTIPLE" => "N", "MANDATORY" => "N", "SETTINGS" => array("DEFAULT_VALUE" => "Y")); $arFieldName = array(); $rsLanguage = CLanguage::GetList($by, $order, array()); while ($arLanguage = $rsLanguage->Fetch()) { $dir = str_replace(array("\\", "//"), "/", dirname(__FILE__)); $dirs = explode("/", $dir); array_pop($dirs); $file = trim(implode("/", $dirs) . "/lang/" . $arLanguage["LID"] . "/include/webdav_settings.php"); $tmp_mess = __IncludeLang($file, true); $arFieldName[$arLanguage["LID"]] = empty($tmp_mess["SONET_UF_USE_BP"]) ? "Use Business Process" : $tmp_mess["SONET_UF_USE_BP"]; } $arFields["EDIT_FORM_LABEL"] = $arFieldName; $obUserField = new CUserTypeEntity(); $obUserField->Add($arFields); $GLOBALS["USER_FIELD_MANAGER"]->arFieldsCache = array(); } $arFields = array("IBLOCK_ID" => $iblockId, "ACTIVE" => "Y", "SOCNET_GROUP_ID" => false, "IBLOCK_SECTION_ID" => 0, "UF_USE_BP" => "N"); $arFields["SOCNET_GROUP_ID"] = $groupId; $arFields["NAME"] = GetMessage("SONET_GROUP_PREFIX") . $groupId; $dbGroup = CSocNetGroup::GetList(array(), array("ID" => (int) $groupId), false, false, array("ID", "SITE_ID", "NAME")); if ($arGroup = $dbGroup->Fetch()) { $arFields["NAME"] = GetMessage("SONET_GROUP_PREFIX") . $arGroup["NAME"]; } if (CIBlock::GetarrayByID($iblockId, "RIGHTS_MODE") === "E") { $arTasks = CWebDavIblock::GetTasks(); $arFields['RIGHTS'] = array('n0' => array('GROUP_CODE' => 'SG' . $arFields["SOCNET_GROUP_ID"] . '_A', 'TASK_ID' => $arTasks['X']), 'n1' => array('GROUP_CODE' => 'SG' . $arFields["SOCNET_GROUP_ID"] . '_E', 'TASK_ID' => $arTasks['W']), 'n2' => array('GROUP_CODE' => 'SG' . $arFields["SOCNET_GROUP_ID"] . '_K', 'TASK_ID' => $arTasks['W'])); } $GLOBALS["UF_USE_BP"] = $arFields["UF_USE_BP"]; $GLOBALS["USER_FIELD_MANAGER"]->EditFormAddFields("IBLOCK_" . $iblockId . "_SECTION", $arFields); $bs = new CIBlockSection(); $sectionId = $bs->Add($arFields); if (!$sectionId) { return false; } return $sectionId; }
if ($userLib && isset($userLib['id']) && ($iblockID = intval($userLib['id']))) { $sectionID = CIBlockWebdavSocnet::GetSectionID($iblockID, 'user', $userID); $libPath = CWebDavIblock::LibOptions('lib_paths', true, $iblockID); if ($libPath) { $tplUser = '******'; if ($tplPos = strpos($libPath, $tplUser)) { $libPath = substr($libPath, 0, $tplPos + strlen($tplUser)) . '/files/lib/'; } $libPath = str_replace('#user_id#', $userID, $libPath); } } if ($sectionID && $libPath) { $typeItems .= str_replace(array("#GROUP_ID#", "#GROUP_NAME#", "#LINK#", "#IBLOCK_ID#", "#SECTION_ID#"), array($userID, CUtil::JSEscape(GetMessage('WD_MY_DOCUMENTS')), CUtil::JSEscape($libPath), $iblockID, $sectionID), "'U#GROUP_ID#' : {'id' : 'U#GROUP_ID#', 'name' : '#GROUP_NAME#', 'type' : 'user', 'link' : '#LINK#', 'iblock_id': '#IBLOCK_ID#', 'section_id': '#SECTION_ID#'},\n"); } } $sharedLibID = CWebDavIblock::LibOptions('shared_files', false, SITE_ID); if ($sharedLibID && isset($sharedLibID['id']) && intval($sharedLibID['id']) > 0 && isset($sharedLibID['base_url']) && strlen($sharedLibID['base_url']) > 0) { if (substr($sharedLibID['base_url'], -1) == "/") { $sharedLibID['base_url'] .= "index.php"; } $typeItems .= str_replace(array("#GROUP_ID#", "#GROUP_NAME#", "#LINK#", "#IBLOCK_ID#"), array(intval($sharedLibID['id']), CUtil::JSEscape(GetMessage('WD_SHARED_DOCUMENTS')), CUtil::JSEscape($sharedLibID['base_url']), intval($sharedLibID['id'])), "'IB#GROUP_ID#' : {'id' : 'IB#GROUP_ID#', 'name' : '#GROUP_NAME#', 'type' : 'library', 'link' : '#LINK#', 'iblock_id': '#IBLOCK_ID#', 'section_id':'0'},\n"); } if (isset($arResult['USER_GROUPS'])) { foreach ($arResult['USER_GROUPS'] as $groupID => $arGroup) { if (intval($arGroup['SECTION_ID']) > 0) { $typeItems .= str_replace(array("#GROUP_ID#", "#GROUP_NAME#", "#LINK#", "#SECTION_ID#"), array(intval($groupID), CUtil::JSEscape($arGroup['GROUP_NAME']), CUtil::JSEscape($arGroup['PATH_FILES']), intval($arGroup['SECTION_ID'])), "'SG#GROUP_ID#' : {'id' : 'SG#GROUP_ID#', 'name' : '#GROUP_NAME#', 'type' : 'socnet', 'link' : '#LINK#', 'section_id': '#SECTION_ID#'},\n"); } } } $typeItems .= "}"; $disabledItems = array();
public static function getRootSectionDataForUser($userId) { $userLib = CWebDavIblock::LibOptions('user_files', false, SITE_ID); if ($userLib && isset($userLib['id']) && ($iblockId = intval($userLib['id']))) { $userSectionId = CWebDavIblock::getRootSectionIdForUser($iblockId, $userId); if ($userSectionId) { return array('IBLOCK_ID' => $iblockId, 'SECTION_ID' => $userSectionId); } } return array(); }
function CheckFields($arUserField, $value) { static $arRootID = array(); $fileExists = false; $arError = array(); if (!static::_checkRequiredModules()) { $arError[] = array('id' => 'WD_ERR_MODULES', 'text' => GetMessage('WD_ERR_MODULES')); } $arFile = static::_fileUnserialize($value); if ($arFile === false) { $arError[] = array('id' => 'WD_ERR_PARSE_FILE', 'text' => GetMessage('WD_ERR_PARSE_FILE')); } $checkRights = static::CheckRights($arFile['id']); if ($checkRights === null) { //mark to delete non exists file self::$UF_TO_DELETE[] = $value; return array(); } elseif ($checkRights === false) { $arError[] = array('id' => 'WD_ERR_IBLOCK404', 'text' => GetMessage('WD_ERR_IBLOCK404')); } if (sizeof($arError) <= 0 && isset($arFile['dest_section'])) { $ibe = new CIBlockElement(); $dbWDFile = $ibe->GetList(array(), array('ID' => $arFile['id']), false, false, array('ID', 'NAME', 'IBLOCK_SECTION_ID', 'IBLOCK_ID')); if ($dbWDFile && ($arWDFile = $dbWDFile->Fetch())) { $arFile['iblock'] = $arWDFile['IBLOCK_ID']; if ($arFile['dest_iblock'] != $arWDFile['IBLOCK_ID']) { $dbIBlock = CIBlock::GetList(array(), array('ID' => $arFile['dest_iblock'], 'CHECK_PERMISSIONS' => 'N')); if ($dbIBlock && ($arIBlock = $dbIBlock->Fetch())) { $arFile['iblock'] = $arIBlock['ID']; } else { $arError[] = array('id' => 'WD_ERR_IBLOCK404', 'text' => GetMessage('WD_ERR_IBLOCK404')); } } $arFile['section'] = $arWDFile['IBLOCK_SECTION_ID']; if ($arFile['dest_section'] != $arWDFile['IBLOCK_SECTION_ID'] || $arFile['iblock'] != $arWDFile['IBLOCK_ID']) { $arFile['section'] = false; if ($arFile['dest_section'] === 0) { $arFile['section'] = 0; } else { $dbWDSection = CIBlockSection::GetList(array(), array('ID' => $arFile['dest_section'], 'IBLOCK_ID' => $arFile['iblock'], 'CHECK_PERMISSIONS' => 'Y')); if ($dbWDSection && ($arWDSection = $dbWDSection->Fetch())) { $arFile['section'] = $arWDSection['ID']; } else { $dbWDSection = CIBlockSection::GetList(array(), array('ID' => $arFile['dest_section'], 'IBLOCK_ID' => $arFile['iblock'], 'CHECK_PERMISSIONS' => 'N')); if ($dbWDSection && ($arWDSection = $dbWDSection->Fetch())) { $arError[] = array('id' => 'WD_ERR_SECTION403', 'text' => GetMessage('WD_ERR_SECTION403')); } else { $arError[] = array('id' => 'WD_ERR_SECTION404', 'text' => GetMessage('WD_ERR_SECTION404')); } } } if (sizeof($arError) <= 0) { $arFileExistSearch = array('NAME' => $arWDFile['NAME'], 'IBLOCK_ID' => $arFile['dest_iblock'], 'SECTION_ID' => $arFile['dest_section']); $dbFileExist = CIBlockElement::GetList(array(), $arFileExistSearch, false, false, array('ID', 'PROPERTY_FILE')); if ($dbFileExist && ($arFileExists = $dbFileExist->Fetch())) { $fileExists = $arFileExists; //$arError[] = array('id' => 'WD_ERR_FILE_EXISTS', 'text' =>GetMessage('WD_ERR_FILE_EXISTS')); } } } if (sizeof($arError) <= 0) { if ($fileExists === false) { if ($arFile['iblock'] != $arWDFile['IBLOCK_ID']) { global $DB; $DB->startTransaction(); $newID = CWebDavIblock::_move_from_iblock_to_iblock($arWDFile['ID'], $arFile['iblock'], $arFile['section']); if (!$newID) { $DB->rollback(); $arError[] = array('id' => 'WD_ERR_ELEMENT_MOVE', 'text' => GetMessage('WD_ERR_PARSE_FILE')); } else { $DB->commit(); static::$UF_MOVED[$arWDFile['ID']] = $newID; } } elseif ($arFile['section'] != $arWDFile['IBLOCK_SECTION_ID']) { global $DB; $DB->startTransaction(); if (!$ibe->Update($arFile['id'], array('IBLOCK_SECTION' => $arFile['dest_section']))) { $DB->rollback(); $arError[] = array('id' => 'WD_ERR_IBLOCK_ELEMENT_UPDATE', 'text' => $ibe->LAST_MESSAGE); } $DB->commit(); } } else { if (!isset($arRootID[$arFile['iblock']])) { $userIBlockID = CWebDavIblock::LibOptions('user_files', false, SITE_ID); $userIBlockID = $userIBlockID['id']; $groupIBlockID = CWebDavIblock::LibOptions('group_files', false, SITE_ID); $groupIBlockID = $groupIBlockID['id']; if ($arFile['iblock'] == $userIBlockID || $arFile['iblock'] == $groupIBlockID) { $dbChain = CIBlockSection::GetNavChain($arFile['iblock'], $arFile['section']); if ($dbChain && ($arChain = $dbChain->Fetch())) { $arRootID[$arFile['iblock']] = $arChain['ID']; } } else { $arRootID[$arFile['iblock']] = false; } } $ob = null; $rootID = $arRootID[$arFile['iblock']]; if ($arFile['iblock'] == $userIBlockID) { $dbSocNetSection = CIBlockSection::GetList(array(), array('ID' => $rootID)); if ($dbSocNetSection && ($arSocNetSection = $dbSocNetSection->Fetch())) { $ob = new CWebDavIblock($arFile['iblock'], '', array("ROOT_SECTION_ID" => $rootID, 'DOCUMENT_TYPE' => array("webdav", "CIBlockDocumentWebdavSocnet", "iblock_" . $arFile['iblock'] . "_user_" . $arSocNetSection['CREATED_BY']))); } } elseif ($arFile['iblock'] == $groupIBlockID) { $dbSocNetSection = CIBlockSection::GetList(array(), array('ID' => $rootID)); if ($dbSocNetSection && ($arSocNetSection = $dbSocNetSection->Fetch())) { $ob = new CWebDavIblock($arFile['iblock'], '', array("ROOT_SECTION_ID" => $rootID, 'DOCUMENT_TYPE' => array("webdav", "CIBlockDocumentWebdavSocnet", "iblock_" . $arFile['iblock'] . "_group_" . $arSocNetSection['SOCNET_GROUP_ID']))); } } else { $ob = new CWebDavIblock($arFile['iblock'], '', array()); } if (!isset($ob)) { $arError[] = array("id" => "error_put", "text" => "Empty webdav object."); return $arError; } $dbFileNew = $ibe->GetList(array(), array('ID' => $arWDFile['ID'], 'IBLOCK_ID' => $arWDFile['IBLOCK_ID']), false, false, array('ID', 'PROPERTY_FILE')); if ($dbFileNew && ($arFileNew = $dbFileNew->Fetch())) { $fileNew = $arFileNew; //$arError[] = array('id' => 'WD_ERR_FILE_EXISTS', 'text' =>GetMessage('WD_ERR_FILE_EXISTS')); } $cFile = CFile::MakeFileArray($fileNew['PROPERTY_FILE_VALUE']); $options = array("new" => false, "FILE_NAME" => $arWDFile['NAME'], "IBLOCK_ID" => $arFile['iblock'], "IBLOCK_SECTION_ID" => $arFile['section'], "ELEMENT_ID" => $fileExists['ID'], "arFile" => $cFile); $GLOBALS["DB"]->StartTransaction(); if (!$ob->put_commit($options)) { $arError[] = array("id" => "error_put", "text" => $ob->LAST_ERROR); $GLOBALS["DB"]->Rollback(); } else { $GLOBALS["DB"]->Commit(); static::$UF_MOVED[$arWDFile['ID']] = $options['ELEMENT_ID']; } } } } } return $arError; }
public static function isLink($entityType, $entityId, $sectionData) { if ($entityType == self::ENTITY_TYPE_USER) { $userLib = CWebDavIblock::LibOptions('user_files', false, SITE_ID); if ($userLib && isset($userLib['id']) && ($iblockId = intval($userLib['id']))) { if ($iblockId != $sectionData['IBLOCK_ID']) { return true; } $chain = self::getNavChain($sectionData['IBLOCK_ID'], $sectionData['ID']); $rootSection = reset($chain); if ($rootSection['CREATED_BY'] != $entityId) { return true; } } return false; } elseif ($entityType == self::ENTITY_TYPE_GROUP) { $groupLib = CWebDavIblock::LibOptions('group_files', false, SITE_ID); if ($groupLib && isset($groupLib['id']) && ($iblockId = intval($groupLib['id']))) { if ($iblockId != $sectionData['IBLOCK_ID']) { return true; } $chain = self::getNavChain($sectionData['IBLOCK_ID'], $sectionData['ID']); $rootSection = reset($chain); if ($rootSection['SOCNET_GROUP_ID'] != $entityId) { return true; } } return false; } elseif ($entityType == self::ENTITY_TYPE_SECTION) { $margins = CIBlockSection::GetList(array(), array('ID' => $entityId, 'CHECK_PERMISSIONS' => 'N'), false, array('LEFT_MARGIN', 'RIGHT_MARGIN', 'IBLOCK_ID')); if (!$margins) { return null; } $margins = $margins->fetch(); if ($margins['IBLOCK_ID'] != $sectionData['IBLOCK_ID']) { return true; } if ($sectionData['ID'] == $entityId) { return false; } $isSubSection = CIBlockSection::GetList(array(), array('ID' => $sectionData['ID'], 'IBLOCK_ID' => $sectionData['IBLOCK_ID'], 'CHECK_PERMISSIONS' => 'N', '>LEFT_BORDER' => $margins['LEFT_MARGIN'], '<RIGHT_BORDER' => $margins['RIGHT_MARGIN']), false, array('ID')); if (!$isSubSection || !($isSubSection = $isSubSection->fetch())) { //not find real subsection === symlink return true; } return empty($isSubSection['ID']); } elseif ($entityType == self::ENTITY_TYPE_SHARED) { return false; } throw new Exception('Unknown type ' . $entityType); }
$storage = new CWebDavStorageCore(); $storage->setStorageId(array('IBLOCK_ID' => $data['IBLOCK_ID'], 'IBLOCK_SECTION_ID' => $data['SECTION_ID'])); $filename = $storage->regenerateNameIfNonUnique($wdElement['element_name'], $savedFolderId); $tmpFile = new CWebDavStubTmpFile(); if ($_REQUEST['v']) { list($arFileH, $optionsH, $fullpath, $filenameH) = $ob->getHistoryFileData($wdElement['element_array']['ID'], (int) $_REQUEST['v'], $p); $tmpFile->path = $fullpath; } else { $copyTmpFile = CFile::MakeFileArray($wdElement['element_array']['PROPERTY_FILE_VALUE']); $tmpFile->path = $copyTmpFile['tmp_name']; } $response = array(); try { $fileData = $storage->addFile($filename, $savedFolderId, $tmpFile); $savedName = CWebDavIblock::getSavedMetaData(); $pathToUserLib = str_replace(array('#USER_ID#', '#user_id#'), array($USER->GetID(), $USER->GetID()), CWebDavIblock::LibOptions('lib_paths', true, $data['IBLOCK_ID'])); $pathToUserLib = strstr($pathToUserLib, 'files/element', true) . 'files/lib'; $pathToUserLib = $pathToUserLib . '/' . $savedName['alias'] . '?result=doc' . $fileData['extra']['id']; $response = array('status' => 'success', 'newId' => $fileData['extra']['id'], 'viewUrl' => $pathToUserLib); } catch (Exception $e) { $response['status'] = 'error'; $fileData = array(); } CWebDavTools::sendJsonResponse($response); } } } } } elseif (!empty($_REQUEST['downloadHistory']) && !empty($_REQUEST['id'])) { $APPLICATION->RestartBuffer(); $APPLICATION->IncludeComponent('bitrix:webdav.element.history', '', array('webdav' => $ob, 'ajax' => false, 'elementId' => (int) $_REQUEST['id'], 'versionId' => (int) $_REQUEST['v'], 'fileId' => (int) $_REQUEST['f']));
public function SetSocnetVars($arResult, $arParams = array()) { if (isset($arParams['PATH_TO_SMILE'])) { $this->arPath["PATH_TO_SMILE"] = $arParams["PATH_TO_SMILE"]; } $this->bIsGroup = array_key_exists("GROUP", $arResult) || array_key_exists("VARIABLES", $arResult) && array_key_exists("group_id", $arResult['VARIABLES']); if ($this->bIsGroup && isset($arResult['VARIABLES']['group_id'])) { $this->entity_id = intval($arResult['VARIABLES']['group_id']); } if (isset($arParams['OBJECT'])) { $this->entity_id = $this->bIsGroup ? $arParams["OBJECT"]->attributes["group_id"] : $arParams["OBJECT"]->attributes["user_id"]; } $userID = $GLOBALS['USER']->GetID(); $this->arPath['PATH_TO_USER'] = isset($arParams["PATH_TO_USER"]) ? $arParams["PATH_TO_USER"] : (isset($arResult["PATH_TO_USER"]) ? $arResult["PATH_TO_USER"] : ''); $this->arPath['SEF_FOLDER'] = $arResult["SEF_FOLDER"]; if ($this->bIsGroup) { $this->arPath['PATH_TO_FILES'] = str_replace(array("#group_id#", "#path#"), array($this->entity_id, ''), $arResult["PATH_TO_GROUP_FILES"]); $this->arPath["ELEMENT_UPLOAD_URL"] = str_replace(array("#group_id#", "#section_id#"), array($this->entity_id, 0), $arResult["PATH_TO_GROUP_FILES_ELEMENT_UPLOAD"]); $this->arPath["ELEMENT_SHOW_INLINE_URL"] = str_replace(array("#group_id#", "#action#"), array($this->entity_id, 'VIEW'), $arResult["PATH_TO_GROUP_FILES_ELEMENT_EDIT"]); $this->arPath["ELEMENT_EDIT_INLINE_URL"] = str_replace(array("#group_id#", "#action#"), array($this->entity_id, 'EDIT'), $arResult["PATH_TO_GROUP_FILES_ELEMENT_EDIT"]); $this->arPath['ELEMENT_HISTORYGET_URL'] = str_replace("#group_id#", $this->entity_id, $arResult["PATH_TO_GROUP_FILES_ELEMENT_HISTORY_GET"]); } else { $this->arPath['PATH_TO_FILES'] = str_replace(array("#user_id#", "#path#"), array($userID, ''), $arResult["PATH_TO_USER_FILES"]); $this->arPath["ELEMENT_UPLOAD_URL"] = str_replace(array("#user_id#", "#section_id#"), array($userID, 0), $arResult["PATH_TO_USER_FILES_ELEMENT_UPLOAD"]); $this->arPath["ELEMENT_SHOW_INLINE_URL"] = str_replace(array("#user_id#", "#action#"), array($userID, 'VIEW'), $arResult["PATH_TO_USER_FILES_ELEMENT_EDIT"]); $this->arPath["ELEMENT_EDIT_INLINE_URL"] = str_replace(array("#user_id#", "#action#"), array($userID, 'EDIT'), $arResult["PATH_TO_USER_FILES_ELEMENT_EDIT"]); $this->arPath['ELEMENT_HISTORYGET_URL'] = str_replace("#user_id#", $userID, $arResult["PATH_TO_USER_FILES_ELEMENT_HISTORY_GET"]); } //$this->arPath['PATH_TO_GROUP'] = (isset($arParams['PATH_TO_GROUP'])?$arParams['PATH_TO_GROUP']:''); $this->arPath['PATH_TO_GROUP'] = isset($arParams["PATH_TO_GROUP"]) ? $arParams["PATH_TO_GROUP"] : (isset($arResult["PATH_TO_GROUP"]) ? $arResult["PATH_TO_GROUP"] : ''); $this->arPath['PATH_TO_USER'] = isset($arParams['PATH_TO_USER']) ? $arParams['PATH_TO_USER'] : ''; $this->arPath['PATH_TO_GROUP_FILES_ELEMENT'] = $arResult["PATH_TO_GROUP_FILES_ELEMENT"]; $this->arPath['PATH_TO_USER_FILES_ELEMENT'] = $arResult["PATH_TO_USER_FILES_ELEMENT"]; $this->event_id = ENTITY_FILES_SOCNET_EVENT_ID; $this->event_comments_id = ENTITY_FILES_SOCNET_COMMENTS_EVENT_ID; $this->IBlockID = array_key_exists("FILES_GROUP_IBLOCK_ID", $arParams) && intval($arParams["FILES_GROUP_IBLOCK_ID"]) > 0 ? $arParams["FILES_GROUP_IBLOCK_ID"] : (array_key_exists("FILES_USER_IBLOCK_ID", $arParams) && intval($arParams["FILES_USER_IBLOCK_ID"]) > 0 ? $arParams["FILES_USER_IBLOCK_ID"] : null); $this->forumID = array_key_exists("FILES_FORUM_ID", $arParams) && intval($arParams["FILES_FORUM_ID"]) > 0 ? $arParams["FILES_FORUM_ID"] : null; CWebDavIblock::LibOptions('lib_paths', true, $this->IBlockID, strlen($this->arPath['PATH_TO_GROUP_FILES_ELEMENT']) > 0 ? $this->arPath['PATH_TO_GROUP_FILES_ELEMENT'] : $this->arPath['PATH_TO_USER_FILES_ELEMENT']); }
public static function GetElementInfo($elementID, $checkPermissions = true) { if (!(IsModuleInstalled('iblock') && IsModuleInstalled('webdav') && CModule::IncludeModule('iblock') && CModule::IncludeModule('webdav'))) { return array(); } if ($checkPermissions && !self::CheckElementReadPermission($elementID)) { return array(); } $arElement = self::GetElement($elementID); if (!$arElement) { return array(); } if (self::$URL_TEMPLATES === null && method_exists('CWebDavIblock', 'GetULRsFromIBlockID')) { self::$URL_TEMPLATES = CWebDavIblock::GetULRsFromIBlockID($arElement['IBLOCK_ID']); } $showUrlTemplate = ''; $viewUrlTemplate = ''; $editUrlTemplate = ''; $deleteUrlTemplate = ''; if (is_array(self::$URL_TEMPLATES) && !empty(self::$URL_TEMPLATES)) { if (isset(self::$URL_TEMPLATES['view'])) { $showUrlTemplate = self::$URL_TEMPLATES['view']; } if (isset(self::$URL_TEMPLATES['history_get'])) { $viewUrlTemplate = self::$URL_TEMPLATES['history_get']; } if (isset(self::$URL_TEMPLATES['edit'])) { $editUrlTemplate = self::$URL_TEMPLATES['edit']; } if (isset(self::$URL_TEMPLATES['delete_dropped'])) { $deleteUrlTemplate = self::$URL_TEMPLATES['delete_dropped']; } } if ($showUrlTemplate === '') { $showUrlTemplate = CWebDavIblock::LibOptions('lib_paths', true, $arElement['IBLOCK_ID']); if (!is_string($showUrlTemplate)) { $showUrlTemplate = ''; } } if ($showUrlTemplate === '') { //HACK: Build default paths. if (\Bitrix\Main\ModuleManager::isModuleInstalled('bitrix24')) { $showUrlTemplate = '/docs/element/view/#ELEMENT_ID#/'; $viewUrlTemplate = '/docs/element/historyget/#ELEMENT_ID#/#ELEMENT_NAME#'; $editUrlTemplate = '/docs/element/edit/edit/#ELEMENT_ID#/'; } else { $showUrlTemplate = SITE_DIR . 'docs/shared/element/view/#ELEMENT_ID#/'; $viewUrlTemplate = SITE_DIR . 'docs/shared/element/historyget/#ELEMENT_ID#/#ELEMENT_NAME#'; $editUrlTemplate = SITE_DIR . 'docs/shared/element/edit/edit/#ELEMENT_ID#/'; } } $showUrl = self::PrepareUrl($showUrlTemplate, $arElement); $viewUrl = $viewUrlTemplate !== '' ? self::PrepareUrl($viewUrlTemplate, $arElement) : str_replace('view', 'historyget', $showUrl); $editUrl = $editUrlTemplate !== '' ? self::PrepareUrl($editUrlTemplate, $arElement) : str_replace('view', 'edit', $showUrl) . 'EDIT/'; $deleteUrl = $deleteUrlTemplate !== '' ? self::PrepareUrl($deleteUrlTemplate, $arElement) : preg_match('/\\/docs\\/shared\\//i', $showUrl) ? '' : str_replace('view', 'edit', $showUrl) . 'DELETE_DROPPED/'; $size = ''; $dbSize = CIBlockElement::GetProperty($arElement['IBLOCK_ID'], $arElement['ID'], array(), array('CODE' => 'WEBDAV_SIZE')); if ($dbSize && ($arSize = $dbSize->Fetch())) { $size = CFile::FormatSize($arSize['VALUE']); } return array('ID' => $elementID, 'NAME' => $arElement['NAME'], 'EDIT_URL' => $editUrl, 'VIEW_URL' => $viewUrl, 'DELETE_URL' => $deleteUrl, 'SHOW_URL' => $showUrl, 'SIZE' => $size); }
function WDUFUserFieldEdit(&$arParams, &$arResult) { global $APPLICATION; static $userIblockID = false; static $groupIblockID = false; static $iblockOptionTypes = array("group_files", "shared_files", "user_files"); static $iblockOptions = array(); static $arIBlock = array(); static $DROPPED = null; $arResult['ELEMENTS'] = array(); $arResult['JSON'] = array(); if (!CModule::IncludeModule('webdav')) { return false; } if ($DROPPED === null) { $DROPPED = CWebDavIblock::getDroppedMetaData(); $DROPPED = $DROPPED['name']; } $arResult['controlName'] = $arParams['arUserField']['FIELD_NAME']; $arValue = $arParams['arUserField']['VALUE']; if (is_array($arValue) && sizeof($arValue) > 0) { if (empty($iblockOptions)) { foreach ($iblockOptionTypes as $type) { $arOpt = CWebDavIblock::LibOptions($type, false, SITE_ID); if (is_set($arOpt, 'id') && intval($arOpt['id']) > 0) { $iblockOptions[$type] = $arOpt['id']; } } } foreach ($arValue as $elementID) { $elementID = intval($elementID); if ($elementID <= 0) { continue; } $title = ''; $dropped = false; $dbElement = CIBlockElement::GetList(array(), array('ID' => $elementID), false, false, array('ID', 'NAME', 'IBLOCK_ID', 'IBLOCK_SECTION_ID', 'SOCNET_GROUP_ID', 'CREATED_BY')); if ($dbElement && ($arElement = $dbElement->Fetch())) { $arSectionTree = WDUGetNavChainSections($arElement['IBLOCK_ID'], $arElement['IBLOCK_SECTION_ID'], false); $dropped = false; if (sizeof($arSectionTree) > 0 && $arSectionTree[0]['NAME'] == $DROPPED) { $title = GetMessage('WD_LOCAL_COPY_ONLY'); $dropped = true; } else { $type = array_search($arElement['IBLOCK_ID'], $iblockOptions); if ($type == 'group_files') { if (sizeof($arSectionTree) > 0) { $title = $arSectionTree[0]['NAME']; } } elseif ($type == 'user_files') { if (sizeof($arSectionTree) > 1 && $arSectionTree[1]['NAME'] == $DROPPED) { $title = GetMessage('WD_LOCAL_COPY_ONLY'); $dropped = true; } elseif (sizeof($arSectionTree) > 0) { $title = GetMessage('WD_MY_LIBRARY'); /*$l = sizeof($arSectionTree); for($i = 1; $i < $l; $i++) { $title .= " / " . $arSectionTree[$i]['NAME']; }*/ } } else { if (!isset($arIBlock[$arElement['IBLOCK_ID']])) { $dbIB = CIBlock::GetList(array(), array('ID' => $arElement['IBLOCK_ID'])); if ($dbIB && ($arIB = $dbIB->Fetch())) { $arIBlock[$arElement['IBLOCK_ID']] = $arIB; } } if (isset($arIBlock[$arElement['IBLOCK_ID']])) { $title = $arIBlock[$arElement['IBLOCK_ID']]['NAME']; } } } $arElement['FILE_SIZE'] = ''; $dbSize = CIBlockElement::GetProperty($arElement['IBLOCK_ID'], $arElement['ID'], array(), array('CODE' => 'WEBDAV_SIZE')); if ($dbSize && ($arSize = $dbSize->Fetch())) { $arElement['FILE_SIZE'] = CFile::FormatSize(intval($arSize['VALUE']), 0); } $arElement['FILE'] = array(); $dbSize = CIBlockElement::GetProperty($arElement['IBLOCK_ID'], $arElement['ID'], array(), array('CODE' => 'FILE')); if ($dbSize && ($arSize = $dbSize->Fetch())) { $arElement['FILE'] = CFile::GetFileArray($arSize['VALUE']); } $arSection =& $arSectionTree[0]; $detailPath = CWebDavIblock::LibOptions('lib_paths', true, $arElement['IBLOCK_ID']); $arPaths = WDUFGetPathOptions($detailPath, $arElement['IBLOCK_ID'], $arSection, $arElement); $arElement["URL_VIEW"] = $arPaths["path"]; $arElement["URL_EDIT"] = $arPaths["edit"]; $arElement["URL_DELETE_DROPPED"] = $arPaths["delete_dropped"]; $arElement["URL_GET"] = $arPaths["history_get"]; $arElement['DROPPED'] = $dropped; $arElement['TITLE'] = $title; $arResult['ELEMENTS'][] = $arElement; } } } // need to load Options for ajax dialogs $extDir = WDUFGetExtranetDir(); if ($extDir !== '') { $groupIBlockID = CWebDavIblock::LibOptions('group_files', false, SITE_ID); if (!($groupIBlockID && isset($groupIBlockID['id']) && intval($groupIBlockID['id']) > 0)) { $arGroups = CIBlockWebdavSocnet::GetUserGroups(0, false); if (sizeof($arGroups) > 0) { $arGroup = array_pop($arGroups); $groupFilesUrl = str_replace(array("///", "//"), "/", "/" . $extDir . '/workgroups/group/' . $arGroup['GROUP_ID'] . '/files/'); $arResult['JSON'][] = $groupFilesUrl; } } } else { $sharedLibID = CWebDavIblock::LibOptions('shared_files', false, SITE_ID); if (!($sharedLibID && isset($sharedLibID['id']) && intval($sharedLibID['id']) > 0 && isset($sharedLibID['base_url']) && strlen($sharedLibID['base_url']) > 0)) { if (!(CModule::IncludeModule('extranet') && strlen(CExtranet::GetExtranetSiteID()) > 0 && SITE_ID == CExtranet::GetExtranetSiteID())) { $arResult['JSON'][] = '/docs/'; $arResult['JSON'][] = '/docs/shared/'; } } $userIBlockID = CWebDavIblock::LibOptions('user_files', false, SITE_ID); if (!($userIBlockID && isset($userIBlockID['id']) && intval($userIBlockID['id']) > 0)) { $arResult['JSON'][] = '/company/personal/user/' . $GLOBALS['USER']->GetID() . '/files/lib/'; } $groupIBlockID = CWebDavIblock::LibOptions('group_files', false, SITE_ID); if (!($groupIBlockID && isset($groupIBlockID['id']) && intval($groupIBlockID['id']) > 0)) { $arGroups = CIBlockWebdavSocnet::GetUserGroups(0, false); if (sizeof($arGroups) > 0) { $arGroup = array_pop($arGroups); $arResult['JSON'][] = '/workgroups/group/' . $arGroup['GROUP_ID'] . '/files/'; } } } }