• Модуль: fileman
  • Путь к файлу: ~/bitrix/modules/fileman/classes/general/snippets.php
  • Класс: CSnippets
  • Вызов: CSnippets::ReadDir
static function ReadDir(&$arSNIPPETS, &$arKeys, $path, $template, $level = 0, $parent = "")
{
	$basePath = self::GetBasePath($template);
	$io = CBXVirtualIo::GetInstance();
	if(!$io->DirectoryExists($basePath))
		return;

	$imagesPath = $basePath."/images";

	CSnippets::WriteHtaccess($imagesPath);
	$bpPath = $basePath.($path == "" ? "" : "/").$path;

	$d = $io->GetDirectory($bpPath);
	$arChildren = $d->GetChildren();
	foreach ($arChildren as $child)
	{
		$file = $child->GetName();
		if($file == ".htaccess" || $file == ".content.php" || ($level == 0 && $file == "images"))
			continue;

		$filePath = $child->GetPathWithName();
		if($child->IsDirectory()) //if this is subfolder
		{
			$new_path = "".$path.($path == "" ? "" : "/").$file;
			CSnippets::ReadDir($arSNIPPETS, $arKeys, $new_path, $template, $level + 1, $file);
		}
		else // File
		{
			$name = $file;
			$ext = $child->GetExtension();

			// Rename file *.* => *.snp
			if ($ext != 'snp')
			{
				$name = str_replace($ext, "snp", $name);
				if (mb_strpos($name, ".snp") === false)
				{
					$name = $name.".snp";
				}

				if (!$io->FileExists($bpPath."/".$name))
				{
					$io->Rename($filePath, $bpPath."/".$name);
				}
				else
				{
					for ($n = 1; $n < 256; $n++)
					{
						$name_ = str_replace(".snp", "(".$n.").snp", $name);
						if (!$io->FileExists($bpPath."/".$name_))
						{
							$name = $name_;
							$io->Rename($filePath, $bpPath."/".$name);
							break;
						}
					}
				}
			}

			$key = $path.($path != '' ? '/' : '').$name;
			$arSNIPPETS[$key] = Array(
				'name' => $name,
				'path' => $path,
				'title' => $name,
				'thumb' => '',
				'code' => CSnippets::GetCode($bpPath."/".$name),
				'description' => "",
				'template' => $template,
				'level' => $level,
				'parent' => $parent
			);

			$arKeys[$key] = Array(
				'name' => $name,
				'path' => $path,
				'title' => $name,
				'description' => ""
			);
		}
	}
}