• Модуль: main
  • Путь к файлу: ~/bitrix/modules/main/classes/general/component_util.php
  • Класс: CComponentUtil
  • Вызов: CComponentUtil::GetTemplatesList
static function GetTemplatesList($componentName, $currentTemplate = false)
{
	$arTemplatesList = array();

	$componentName = trim($componentName);
	if ($componentName == '')
		return $arTemplatesList;

	$path2Comp = CComponentEngine::MakeComponentPath($componentName);
	if ($path2Comp == '')
		return $arTemplatesList;

	$componentPath = getLocalPath("components".$path2Comp);

	if (!CComponentUtil::isComponent($componentPath))
	{
		return $arTemplatesList;
	}

	$templateFolders = array();
	$arExists = array();
	$folders = array(
		"/local/templates",
		BX_PERSONAL_ROOT."/templates",
	);

	foreach($folders as $folder)
	{
		if(file_exists($_SERVER["DOCUMENT_ROOT"].$folder))
		{
			if ($handle = opendir($_SERVER["DOCUMENT_ROOT"].$folder))
			{
				while (($file = readdir($handle)) !== false)
				{
					if ($file == "." || $file == "..")
						continue;

					if ($currentTemplate !== false && $currentTemplate != $file || $file == ".default")
						continue;

					if (file_exists($_SERVER["DOCUMENT_ROOT"].$folder."/".$file."/components".$path2Comp))
					{
						$templateFolders[] = array(
							"path" => $folder."/".$file."/components".$path2Comp,
							"template" => $file,
						);
					}
				}
				closedir($handle);

				if (file_exists($_SERVER["DOCUMENT_ROOT"].$folder."/.default/components".$path2Comp))
				{
					$templateFolders[] = array(
						"path" => $folder."/.default/components".$path2Comp,
						"template" => ".default",
					);
				}
			}
		}
	}

	$templateFolders[] = array(
		"path" => $componentPath."/templates",
		"template" => "",
	);

	foreach($templateFolders as $templateFolder)
	{
		$templateFolderPath = $templateFolder["path"];
		if ($handle1 = @opendir($_SERVER["DOCUMENT_ROOT"].$templateFolderPath))
		{
			while (($file1 = readdir($handle1)) !== false)
			{
				if ($file1 == "." || $file1 == "..")
					continue;

				if (in_array($file1, $arExists))
					continue;

				$arTemplate = array(
					"NAME" => $file1,
					"TEMPLATE" => $templateFolder["template"],
				);

				if (file_exists($_SERVER["DOCUMENT_ROOT"].$templateFolderPath."/".$file1."/.description.php"))
				{
					CComponentUtil::__IncludeLang($templateFolderPath."/".$file1, ".description.php");

					$arTemplateDescription = array();
					include($_SERVER["DOCUMENT_ROOT"].$templateFolderPath."/".$file1."/.description.php");

					$arTemplate["TITLE"] = $arTemplateDescription["NAME"];
					$arTemplate["DESCRIPTION"] = $arTemplateDescription["DESCRIPTION"];
				}

				$arTemplatesList[] = $arTemplate;
				$arExists[] = $arTemplate["NAME"];
			}
			@closedir($handle1);
		}
	}

	return $arTemplatesList;
}