• Модуль: main
  • Путь к файлу: ~/bitrix/modules/main/classes/general/component_util.php
  • Класс: CComponentUtil
  • Вызов: CComponentUtil::__GetComponentsTree
static function __GetComponentsTree($filterNamespace = false, $arNameFilter = false, $arFilter = false)
{
	$arTree = array();
	$io = CBXVirtualIo::GetInstance();
	$folders = array(
		"/local/components",
		"/bitrix/components",
	);

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

					if (is_dir($_SERVER["DOCUMENT_ROOT"].$componentFolder."/".$file))
					{
						if (CComponentUtil::isComponent($componentFolder."/".$file))
						{
							// It's component
							if ($filterNamespace !== false && $filterNamespace <> '')
								continue;
							if ($arNameFilter !== false && !CComponentUtil::CheckComponentName($file, $arNameFilter))
								continue;

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

								$arComponentDescription = array();
								include($_SERVER["DOCUMENT_ROOT"].$componentFolder."/".$file."/.description.php");

								if (isset($arFilter["TYPE"]) && $arFilter["TYPE"] != $arComponentDescription["TYPE"])
									continue;

								if (array_key_exists("PATH", $arComponentDescription) && array_key_exists("ID", $arComponentDescription["PATH"]))
								{
									$arComponent = array();
									$arComponent["NAME"] = $file;
									$arComponent["TYPE"] = (array_key_exists("TYPE", $arComponentDescription) ? $arComponentDescription["TYPE"] : "");
									$arComponent["NAMESPACE"] = "";
									$arComponent["TITLE"] = trim($arComponentDescription["NAME"]);
									$arComponent["DESCRIPTION"] = $arComponentDescription["DESCRIPTION"];

									if (array_key_exists("ICON", $arComponentDescription))
									{
										$arComponentDescription["ICON"] = ltrim($arComponentDescription["ICON"], "/");
										if($arComponentDescription["ICON"] != "" && $io->FileExists($io->RelativeToAbsolutePath($componentFolder."/".$file."/".$arComponentDescription["ICON"])))
											$arComponent["ICON"] = $componentFolder."/".$file."/".$arComponentDescription["ICON"];
										else
											$arComponent["ICON"] = "/bitrix/images/fileman/htmledit2/component.gif";
									}
									if (array_key_exists("COMPLEX", $arComponentDescription) && $arComponentDescription["COMPLEX"] == "Y")
										$arComponent["COMPLEX"] = "Y";
									else
										$arComponent["COMPLEX"] = "N";
									$arComponent["SORT"] = intval($arComponentDescription["SORT"]);
									if ($arComponent["SORT"] <= 0)
										$arComponent["SORT"] = 100;

									$arComponent["SCREENSHOT"] = array();
									if (array_key_exists("SCREENSHOT", $arComponentDescription))
									{
										if (!is_array($arComponentDescription["SCREENSHOT"]))
											$arComponentDescription["SCREENSHOT"] = array($arComponentDescription["SCREENSHOT"]);

										for ($i = 0, $cnt = count($arComponentDescription["SCREENSHOT"]); $i < $cnt; $i++)
											$arComponent["SCREENSHOT"][] = $componentFolder."/".$file.$arComponentDescription["SCREENSHOT"][$i];
									}

									CComponentUtil::__BuildTree($arComponentDescription["PATH"], $arTree, $arComponent);
								}
							}
						}
						else
						{
							// It's not a component
							if ($filterNamespace !== false && ($filterNamespace == '' || $filterNamespace != $file))
								continue;

							if ($handle1 = opendir($_SERVER["DOCUMENT_ROOT"].$componentFolder."/".$file))
							{
								while (($file1 = readdir($handle1)) !== false)
								{
									if ($file1 == "." || $file1 == "..")
										continue;

									if (is_dir($_SERVER["DOCUMENT_ROOT"].$componentFolder."/".$file."/".$file1))
									{
										if (CComponentUtil::isComponent($componentFolder."/".$file."/".$file1))
										{
											if ($arNameFilter !== false && !CComponentUtil::CheckComponentName($file1, $arNameFilter))
												continue;
											// It's component
											if (file_exists($_SERVER["DOCUMENT_ROOT"].$componentFolder."/".$file."/".$file1."/.description.php"))
											{
												CComponentUtil::__IncludeLang($componentFolder."/".$file."/".$file1, ".description.php");

												$arComponentDescription = array();
												include($_SERVER["DOCUMENT_ROOT"].$componentFolder."/".$file."/".$file1."/.description.php");

												if (isset($arFilter["TYPE"]) && (!isset($arComponentDescription["TYPE"]) || $arFilter["TYPE"] != $arComponentDescription["TYPE"]))
													continue;

												if (array_key_exists("PATH", $arComponentDescription) && array_key_exists("ID", $arComponentDescription["PATH"]))
												{
													$arComponent = array();
													$arComponent["NAME"] = $file.":".$file1;
													$arComponent["TYPE"] = (array_key_exists("TYPE", $arComponentDescription) ? $arComponentDescription["TYPE"] : "");
													$arComponent["NAMESPACE"] = $file;
													$arComponent["TITLE"] = trim($arComponentDescription["NAME"]);
													$arComponent["DESCRIPTION"] = $arComponentDescription["DESCRIPTION"];
													if (array_key_exists("ICON", $arComponentDescription))
													{
														$arComponentDescription["ICON"] = ltrim($arComponentDescription["ICON"], "/");
														if($arComponentDescription["ICON"] != "" && $io->FileExists($io->RelativeToAbsolutePath($componentFolder."/".$file."/".$file1."/".$arComponentDescription["ICON"])))
															$arComponent["ICON"] = $componentFolder."/".$file."/".$file1."/".$arComponentDescription["ICON"];
														else
															$arComponent["ICON"] = "/bitrix/images/fileman/htmledit2/component.gif";
													}
													if (array_key_exists("COMPLEX", $arComponentDescription) && $arComponentDescription["COMPLEX"] == "Y")
														$arComponent["COMPLEX"] = "Y";
													else
														$arComponent["COMPLEX"] = "N";
													$arComponent["SORT"] = intval($arComponentDescription["SORT"] ?? 0);
													if ($arComponent["SORT"] <= 0)
														$arComponent["SORT"] = 100;

													$arComponent["SCREENSHOT"] = array();
													if (array_key_exists("SCREENSHOT", $arComponentDescription))
													{
														if (!is_array($arComponentDescription["SCREENSHOT"]))
															$arComponentDescription["SCREENSHOT"] = array($arComponentDescription["SCREENSHOT"]);

														for ($i = 0, $cnt = count($arComponentDescription["SCREENSHOT"]); $i < $cnt; $i++)
															$arComponent["SCREENSHOT"][] = $componentFolder."/".$file."/".$file1.$arComponentDescription["SCREENSHOT"][$i];
													}

													CComponentUtil::__BuildTree($arComponentDescription["PATH"], $arTree, $arComponent);
												}
											}
										}
									}
								}
								closedir($handle1);
							}
						}
					}
				}
				closedir($handle);
			}
		}
	}

	return $arTree;
}