• Модуль: fileman
  • Путь к файлу: ~/bitrix/modules/fileman/classes/general/medialib.php
  • Класс: CMedialib
  • Вызов: CMedialib::GetItemViewHTML
static function GetItemViewHTML($itemId)
{
	$arItem = CMedialibItem::GetList(array('id' => $itemId));
	if (is_array($arItem) && count($arItem) > 0)
	{
		$events = GetModuleEvents("fileman", "OnMedialibItemView");
		$bHandled = false;
		while($arEvent = $events->Fetch())
		{
			$arRes = ExecuteModuleEventEx($arEvent, array($arItem[0]));
			if (!$arRes || !is_array($arRes))
				continue;
			$bHandled = true;
		}
	}

	if (!$bHandled)
	{
		$item = $arItem[0];

		// Default view
		$ext = mb_strtolower(GetFileExtension($item['PATH']));
		$videoExt = array('flv', 'mp4', 'wmv', 'avi');
		$soundExt = array('aac', 'mp3', 'wma');

		if ($item['TYPE'] == 'image' || mb_strpos($item['CONTENT_TYPE'], 'image') !== false)
		{
			if(mb_substr($item['PATH'], 0, 1) !== '/' || $item['PATH'] !== $item['PATH_EXTERNAL'])
			{
				$src = $item['PATH_EXTERNAL'];
			}
			else
			{
				$src = $item['PATH'];
			}

			// It's image
			$arRes = array(
				"html" => "",
				"width" => intval($item['WIDTH']),
				"height" => intval($item['HEIGHT'])
			);
		}
		else if (mb_strpos($item['CONTENT_TYPE'], 'video') !== false || in_array($ext, $videoExt))
		{
			global $APPLICATION;
			$item['WIDTH'] = 400;
			$item['HEIGHT'] = 300;

			ob_start();
			$APPLICATION->IncludeComponent(
				"bitrix:player",
				"",
				array(
					"PLAYER_TYPE" => "auto",
					"PATH" => $item['PATH'],
					"WIDTH" => $item['WIDTH'],
					"HEIGHT" => $item['HEIGHT'],
					"FILE_TITLE" => $item['NAME'],
					"FILE_DESCRIPTION" => "",
					//"SKIN_PATH" => "/bitrix/components/bitrix/player/mediaplayer/skins",
					//"SKIN" => "bitrix.swf",
					"WMODE" => "transparent",
					"WMODE_WMV" => "windowless",
					"SHOW_CONTROLS" => "Y",
					"BUFFER_LENGTH" => "3",
					"ALLOW_SWF" => "N"
				),
				false,
				array('HIDE_ICONS' => 'Y')
			);
			$s = ob_get_contents();
			ob_end_clean();

			$arRes = array(
				"html" => $s,
				"width" => $item['WIDTH'],
				"height" => $item['HEIGHT']
			);
		}
		else if (mb_strpos($item['CONTENT_TYPE'], 'audio') !== false || in_array($ext, $soundExt))
		{
			global $APPLICATION;
			$item['WIDTH'] = 300;
			$item['HEIGHT'] = 24;

			ob_start();
			$APPLICATION->IncludeComponent(
				"bitrix:player",
				"",
				array(
					"PROVIDER" => "sound",
					"PLAYER_TYPE" => "auto",
					"PATH" => $item['PATH'],
					"WIDTH" => $item['WIDTH'],
					"HEIGHT" => $item['HEIGHT'],
					"FILE_TITLE" => $item['NAME'],
					"FILE_DESCRIPTION" => "",
					"WMODE" => "transparent",
					"WMODE_WMV" => "windowless",
					"SHOW_CONTROLS" => "Y",
					"BUFFER_LENGTH" => "3",
					"ALLOW_SWF" => "N"
				),
				false,
				array('HIDE_ICONS' => 'Y')
			);
			$s = "
".ob_get_contents()."
"; ob_end_clean(); $arRes = array( "html" => $s, "width" => $item['WIDTH'], "height" => $item['HEIGHT'] ); } } ?>