• Модуль: webdav
  • Путь к файлу: ~/bitrix/modules/webdav/classes/general.php
  • Класс: CWebDavBase
  • Вызов: CWebDavBase::base_PROPFIND
function base_PROPFIND()
{
	global $APPLICATION;
	$options = Array();
	$files	 = Array();

	$options['path'] = $this->_path;
	$options['depth'] = (array_key_exists('HTTP_DEPTH', $_SERVER) ? $_SERVER['HTTP_DEPTH'] : 'infinity');

	$propinfo = new __CParsePropfind;
	$propinfo->LoadFromPhpInput();
	if (!$propinfo->success)
	{
		$this->ThrowError('400 Error', 'WEBDAV_PROPFIND_PARSE', '', __FILE__ .' '. __LINE__);
		return;
	}

	$options['props'] = $propinfo->props;
	if (is_string($result = $this->PROPFIND($options, $files)))
	{
		$this->SetStatus($result);
		header('Content-length: 0');
		header('Connection: close');
		return;
	}

	$ns_hash = array();
	$ns_defs = 'xmlns:ns0="urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/"';

	foreach ($files['files'] as $filekey => $file)
	{
		if (!isset($file['props']) /*|| !is_array($file['props'])*/) // always array from _get_file_info_arr
			continue;

		foreach ($file['props'] as $key => $prop)
		{
			switch($options['props'])
			{
				case 'all':
					break;
				case 'names':
					unset($files['files'][$filekey]['props'][$key]['val']);
					break;
				default:
					break;
			}

			if (empty($prop['ns']))
				continue;
			$ns = $prop['ns'];
			if ($ns == 'DAV:')
				continue;
			if (isset($ns_hash[$ns]))
				continue;

			$ns_name = 'ns' . (count($ns_hash) + 1);
			$ns_hash[$ns] = $ns_name;
			$ns_defs .= " xmlns:$ns_name="$ns"";
		}

		if (is_array($options['props']))
		{
			foreach ($options['props'] as $reqprop)
			{
				if ($reqprop['name']=='')
					continue;

				$found = false;

				foreach ($file['props'] as $prop)
				{
					if ($reqprop['name'] == $prop['name'] && @$reqprop['xmlns'] == $prop['ns'])
					{
						$found = true;
						break;
					}
				}

				if (!$found)
				{
					if ($reqprop['xmlns']==='DAV:' && $reqprop['name']==='lockdiscovery')
					{
						$files['files'][$filekey]['props'][] = $this->_mkprop('DAV:', 'lockdiscovery', $this->lockdiscovery($files['files'][$filekey]['path']));
					}
					else
					{
						if ($reqprop['name'] != 'save-profile-form-location')
						{
							$files['files'][$filekey]['noprops'][] = $this->_mkprop($reqprop['xmlns'], $reqprop['name'], '');

							if ($reqprop['xmlns'] != 'DAV:' && !isset($ns_hash[$reqprop['xmlns']]))
							{
								$ns_name = 'ns' . (count($ns_hash) + 1);
								$ns_hash[$reqprop['xmlns']] = $ns_name;
								$ns_defs .= ' xmlns:' . $ns_name . '="' . $reqprop['xmlns'] . '"';
							}
						}
					}
				}
			}
		}
	}

	$this->SetStatus('207 Multi-Status');
	header('Content-Type: text/xml; charset="utf-8"');
	echo "n";
	echo "n";

	foreach ($files['files'] as $file)
	{
		if (!is_array($file) || empty($file) || !isset($file['path']))
			continue;
		$path = $file['path'];
		if (!is_string($path) || $path==='')
			continue;

		echo " n";

		$href = $this->urlencode($APPLICATION->ConvertCharset($this->base_url, SITE_CHARSET, 'UTF-8') . $path);

		echo "	$hrefn";

		if (isset($file['props']) && is_array($file['props']))
		{
			echo "	 n";
			echo "	  n";

			foreach ($file['props'] as $key => $prop) {

				//if (!is_array($prop)) // from _get_file_info_arr - always array, if _mkprop
					//continue;
				if (!isset($prop['name']))
					continue;
				if ($prop['name'] == 'UNDELETE')
					continue;

				if (!isset($prop['val']) || $prop['val'] === '' || $prop['val'] === false)
				{
					if ($prop['ns']=='DAV:')
					{
						echo "	   n";
					}
					else if (!empty($prop["ns"]))
					{
						echo "	   <".$ns_hash[$prop['ns']].":".$prop['name']."/>n";
					}
					else
					{
						echo "	   <".$prop['name']." xmlns=""/>";
					}
				}
				else if ($prop['ns'] == 'DAV:')
				{
					switch ($prop['name'])
					{
						case 'creationdate':
							echo "	   " ,
								gmdate('Y-m-d\TH:i:s\Z', $prop['val']),
								"n";
							break;
						case 'getlastmodified':
							echo "	   ",
								gmdate('D, d M Y H:i:s ', $prop['val']),
								"GMTn";
							break;
						case 'resourcetype':
							echo "	   n";
							break;
						case 'supportedlock':
							echo "	   ".$prop['val']."n";
							break;
						case 'lockdiscovery':
							echo "	   n";
							echo $prop["val"];
							echo "	   n";
							break;
						default:
							echo "	   "
							//. $this->_prop_encode(htmlspecialcharsbx($prop['val']))
							. htmlspecialcharsbx($prop['val'])
							.	  "n";
							break;
					}
				}
				else
				{
					if ($prop['ns'])
					{
						echo "	   <" . $ns_hash[$prop["ns"]] . ":".$prop['name'].">",
							htmlspecialcharsbx($prop['val']) ,
							"n";
					}
					else
					{
						echo "	   <".$prop['name']." xmlns="">",
							htmlspecialcharsbx($prop['val']),
							"n";
					}
				}
			}

			echo "	 n";
			echo "	 HTTP/1.1 200 OKn";
			echo "	n";
		}

		if (isset($file['noprops']))
		{
			echo "	 n";
			echo "	  n";

			foreach ($file['noprops'] as $key => $prop)
			{
				if ($prop['ns'] == 'DAV:')
				{
					echo "	   n";
				}
				else if ($prop['ns'] == '')
				{
					echo "	   <".$prop['name']." xmlns=""/>n";
				}
				else
				{
					echo "	   <" . $ns_hash[$prop["ns"]] . ":".$prop['name']."/>n";
				}
			}

			echo "	 n";
			echo "	 HTTP/1.1 404 Not Foundn";
			echo "	n";
		}

		echo " n";
	}

	echo "n";
}