• Модуль: webdav
  • Путь к файлу: ~/bitrix/modules/webdav/classes/iblock.php
  • Класс: CWebDavIblock
  • Вызов: CWebDavIblock::__construct
public function __construct($IBLOCK_ID, $base_url, $arParams = array())
{
	$arParams = (is_array($arParams) ? $arParams : array());

	$this->_originalParams = $arParams;
	$this->_symlinkMode = !empty($arParams['symlinkMode']);
	$this->_symlinkSectionData = empty($arParams['symlinkSectionData'])? array() : $arParams['symlinkSectionData'];
	$this->_symlinkRealRootSectionData = empty($arParams['symlinkRealRootSectionData'])? array() : $arParams['symlinkRealRootSectionData'];

	$this->IBLOCK_ID = $IBLOCK_ID;
	$this->IBLOCK_TYPE = $arParams["IBLOCK_TYPE"];
	$this->FORUM_ID = ((isset($arParams['FORUM_ID']) && (intval($arParams['FORUM_ID']) > 0)) ? intval($arParams['FORUM_ID']) : null);

	$this->cachePathBase = str_replace(array("///", "//"), "/", "/".SITE_ID."/webdav/".$this->IBLOCK_ID."/");
	$this->CACHE_PATH = $this->cachePathBase;
	$this->CACHE_TIME = array_key_exists("CACHE_TIME", $arParams) ? $arParams["CACHE_TIME"] : 0;
	$this->cacheType = array_key_exists("CACHE_TYPE", $arParams) ? $arParams["CACHE_TYPE"] : "N";

	if ($this->cacheType == "Y" ||
		(
			$this->cacheType == "A" &&
			COption::GetOptionString("main", "component_cache_on", "Y") == "Y"
		)
	)
	{
		$this->CACHE_TIME = intval($arParams["CACHE_TIME"]);
	}
	else
	{
		$this->CACHE_TIME = 0;
	}
	$arParams["CACHE_TIME"] = $this->CACHE_TIME;

	if ($this->CACHE_TIME > 0)
	{
		$this->CACHE_OBJ = new CPHPCache();
	}

	if (!$this->SetRootSection($arParams["ROOT_SECTION_ID"], false, empty($arParams['PLEASE_DO_NOT_MAKE_REDIRECT']))) // socnet
	{
		$this->arError[] = array(
			"id" => "root_section_is_not_found",
			"text" => GetMessage("WD_ROOT_SECTION_NOT_FOUND"));
	}
	else
	{
		if (self::$first_run)
			AddEventHandler("iblock", "OnAfterIBlockSectionAdd", array($this, "UpdateRootSection"));
	}

	if (
		(COption::GetOptionString('webdav', 'webdav_socnet', 'Y') === 'Y')
		&& (self::$first_run)
		&& CModule::IncludeModule("socialnetwork")
	)
	{
		$obDavEventHandler = CWebDavSocNetEvent::GetRuntime();
		$obDavEventHandler->object = $this;
		AddEventHandler("webdav", "OnFileAdd",				array($obDavEventHandler, "SocnetLogFileAdd"));
		AddEventHandler("webdav", "OnFileAdd",				array($obDavEventHandler, "SocnetNotify"));
		AddEventHandler("webdav", "OnFileUpdate",			array($obDavEventHandler, "SocnetLogFileUpdate"));
		AddEventHandler("webdav", "OnFileMoveFinished",		array($obDavEventHandler, "SocnetLogFileMove"));
		AddEventHandler("webdav", "OnFileTrash",			array($obDavEventHandler, "SocnetLogFileDelete"));
		AddEventHandler("webdav", "OnFileDelete",			array($obDavEventHandler, "SocnetLogFileDelete"));
		if (CModule::IncludeModule('forum'))
		{
			AddEventHandler("forum", "onAfterMessageAdd",	 array($obDavEventHandler, "SocnetLogMessageAdd"));
			AddEventHandler("forum", "onAfterMessageDelete", array($obDavEventHandler, "SocnetLogMessageDelete"));
			AddEventHandler("forum", "onAfterMessageUpdate", array($obDavEventHandler, "SocnetLogMessageUpdate"));
		}
	}

	parent::__construct($base_url);

	if (!IsModuleInstalled("iblock"))
	{
		$this->arError[] = array(
			"id" => "module iblock is not installed. ",
			"text" => GetMessage("W_IBLOCK_IS_NOT_INSTALLED"));
		return false;
	}

	$this->e_rights = (CIBlock::GetArrayByID($IBLOCK_ID, "RIGHTS_MODE") === "E");

	if ($this->e_rights)
		$this->permission_real = 'X';
	else
		$this->permission_real = $this->GetPermission('IBLOCK', $this->IBLOCK_ID);

	$this->permission = (empty($arParams["PERMISSION"]) ? $this->permission_real : $arParams["PERMISSION"]);

	if ($GLOBALS['USER']->CanDoOperation('webdav_change_settings'))
		$this->permission = $this->permission_real = 'X';

	$this->check_creator = false;
	if ($this->permission_real < "W" && $this->permission > $this->permission_real)
		$this->check_creator = ($arParams["CHECK_CREATOR"] == "Y" ? true : false);

	$this->USER["GROUPS"] = $GLOBALS["USER"]->GetUserGroupArray();

	$this->workflow = false;
	if (CIBlock::GetArrayByID($IBLOCK_ID, "WORKFLOW") != "N" && IsModuleInstalled("workflow"))
	{
		CModule::IncludeModule("workflow");
		$this->workflow = 'workflow';
		$this->permission_wf_edit = true;
		if ($this->permission == "U" && !CWorkflow::IsAdmin())
		{
			$this->permission_wf_edit = false;
			$db_res = CWorkflowStatus::GetDropDownList("Y",  "desc");
			if ($db_res && $res = $db_res->Fetch())
			{
				do
				{
					if (CIBlockElement::WF_GetStatusPermission($res["REFERENCE_ID"]) >= 2)
					{
						$this->permission_wf_edit = true;
						break;
					}
				} while ($res = $db_res->Fetch());
			}
		}
	}
	elseif (IsModuleInstalled("bizproc"))
	{
		CModule::IncludeModule("bizproc");
		$this->workflow = (CIBlock::GetArrayByID($IBLOCK_ID, "BIZPROC") != "N" ? 'bizproc' : 'bizproc_limited');
		$this->wfParams['AUTO_PUBLISH'] = "N";
		if (isset($arParams['AUTO_PUBLISH']))
			$this->wfParams['AUTO_PUBLISH'] = (($arParams['AUTO_PUBLISH'] == "Y") ? "Y" : "N");
		if (isset($arParams['FILES_AUTO_PUBLISH']))
			$this->wfParams['AUTO_PUBLISH'] = (($arParams['FILES_AUTO_PUBLISH'] == "Y") ? "Y" : "N");
		$this->wfParams['DOCUMENT_TYPE'] = array("webdav", "CIBlockDocumentWebdav", "iblock_".$IBLOCK_ID);
		if (is_array($arParams["DOCUMENT_TYPE"]))
		{
			$this->wfParams['DOCUMENT_TYPE'][1] = $arParams["DOCUMENT_TYPE"][1];
			$this->wfParams['DOCUMENT_TYPE'][2] = $arParams["DOCUMENT_TYPE"][2];
		}

		if (self::$first_run)
			AddEventHandler('bizproc', 'OnBeforeDeleteFileFromHistory', array('CWebdavDocumentHistory', 'OnBeforeDeleteFileFromHistory'));

		if ($this->wfParams['DOCUMENT_TYPE'][1] == "CIBlockDocumentWebdavSocnet")
		{
			if ($this->workflow == 'bizproc')
			{
				$tmp = explode("_", $this->wfParams['DOCUMENT_TYPE'][2]);
				if (intval($tmp[3]) > 0)
				{
					$arFilter = array(
						"IBLOCK_ID" => $IBLOCK_ID,
						"SOCNET_GROUP_ID" => false,
						"SECTION_ID" => 0);
					if ($tmp[2] == "user")
					{
						$arFilter["CREATED_BY"] = $tmp[3];
						//we don't use BP in user lib;
						$this->workflow = 'bizproc_limited';
					}
					else
					{
						$arFilter["SOCNET_GROUP_ID"] = $tmp[3];
						$db_res = CIBlockSection::GetList(array(), $arFilter, false, array("ID", "UF_USE_BP"));
						if ($db_res && $res = $db_res->Fetch())
						{
							$this->workflow = ($res["UF_USE_BP"] == "N" ? 'bizproc_limited' : 'bizproc');
						}
					}
				}
			}
			if (method_exists($this->wfParams['DOCUMENT_TYPE'][1], "GetUserGroups"))
			{
				$this->USER["GROUPS"] = call_user_func_array(
					array($this->wfParams['DOCUMENT_TYPE'][1], "GetUserGroups"),
					array($this->wfParams['DOCUMENT_TYPE'], null, $GLOBALS["USER"]->GetID()));
			}
		}
		if ($this->workflow == 'bizproc')
		{
			AddEventHandler('webdav', 'OnBizprocPublishDocument', array($this, 'OnBizprocPublishDocument'));
		}
	}

	$this->file_prop = mb_strtoupper(isset($arParams["NAME_FILE_PROPERTY"])? $arParams["NAME_FILE_PROPERTY"] : "FILE");

	if ($this->permission == "U" && $this->workflow != "workflow" && $this->workflow != "bizproc")
		$this->permission = "R";

	if ($arParams["SHORT_PATH_TEMPLATE"])
		$this->short_path_template = $arParams["SHORT_PATH_TEMPLATE"];

	if ($arParams["ATTRIBUTES"])
		$this->attributes = $arParams["ATTRIBUTES"];

	$this->_check_iblock_prop(array(
		"WEBDAV_INFO" => array(
			"name" => GetMessage("WD_PROPERTY_WEBDAV_INFO"),
			"type" => "S"
		),
		"WEBDAV_SIZE" => array(
			"name" => GetMessage("WD_PROPERTY_FILE_SIZE"),
			"type" => "N"
		),
		static::PROPERTY_VERSION => array(
			"name" => GetMessage("WD_PROPERTY_VERSION"),
			"type" => "N"
		),
		$this->file_prop => array(
			"name" => GetMessage("WD_PROPERTY_NAME_FILE"),
			"type" => "F",
			"properties" => array("SEARCHABLE" => "Y")
		)
	));

	$oIB = new CIBlock;
	$arIBlock = $oIB->GetArrayByID($this->IBLOCK_ID);
	if(!array_key_exists("NOT_SAVE_SUG_FILES", $arParams))
	{
		if (mb_strpos($arIBlock['CODE'], 'shared_files') !== false)
		{
			// without trailing slash redirects POST request to GET request
			if ($this->base_url <> '')
				$this->LibOptions('shared_files', false, SITE_ID, array('id' => $this->IBLOCK_ID, 'base_url' => $this->base_url.'/'));
		}
		elseif (mb_strpos($arIBlock['CODE'], 'group_files') !== false)
		{
			$this->LibOptions('group_files', false, SITE_ID, array('id' => $this->IBLOCK_ID));
		}
		elseif (mb_strpos($arIBlock['CODE'], 'user_files') !== false)
		{
			$this->LibOptions('user_files', false, SITE_ID, array('id' => $this->IBLOCK_ID));
		}
	}

	if ($arIBlock['INDEX_SECTION'] == 'Y' && trim($arIBlock['SECTION_PAGE_URL']) == '')
	{
		$arIBlock['SECTION_PAGE_URL'] = str_replace(array("///", "//"), "/", $arIBlock['LIST_PAGE_URL'] . "/folder/view/#SECTION_ID#/");
		$oIB->Update($this->IBLOCK_ID, $arIBlock);
	}

	$this->GetUfEntity();

	self::$first_run = false;
}