• Модуль: fileman
  • Путь к файлу: ~/bitrix/modules/fileman/classes/general/snippets.php
  • Класс: CSnippets
  • Вызов: CSnippets::RenameCategory
static function RenameCategory($params)
{
	global $APPLICATION;
	$res = false;
	if (is_array($params) && isset($params['path'], $params['new_name']))
	{
		$path = CFileMan::SecurePathVar($params['path']);
		$template = (isset($params['template']) && $params['template'] !== '') ? CFileMan::SecurePathVar($params['template']) : '.default';
		$basePath = self::GetBasePath($template);
		$categoryPath = $basePath.'/'.$path;

		$io = CBXVirtualIo::GetInstance();
		$newCategoryPath = $io->ExtractPathFromPath($categoryPath).'/'.$params['new_name'];
		if($io->DirectoryExists($categoryPath) && !$io->DirectoryExists($newCategoryPath))
		{
			$res = $io->Rename($categoryPath, $newCategoryPath);
		}

		$io = CBXVirtualIo::GetInstance();
		if($io->FileExists($basePath."/.content.php"))
		{
			$contentSrc = $APPLICATION->GetFileContent($basePath."/.content.php");
			$newPath = ltrim($io->ExtractPathFromPath($path).'/'.$params['new_name'], '/');
			$processedNewPath = CUtil::addslashes($newPath);
			$contentSrc = preg_replace("/\$SNIPPETS\['".$path."\//", '$SNIPPETS[''.$processedNewPath.'/', $contentSrc);
			$APPLICATION->SaveFileContent($basePath."/.content.php", $contentSrc);
		}

		CSnippets::ClearCache();
	}
	return $res;
}