• Модуль: fileman
  • Путь к файлу: ~/bitrix/modules/fileman/classes/general/snippets.php
  • Класс: CSnippets
  • Вызов: CSnippets::Edit
static function Edit($Params)
{
	global $APPLICATION;
	$name = CFileMan::SecurePathVar($Params['name']);
	$title = $Params['title'];
	$description = $Params['description'];
	$path = CFileMan::SecurePathVar($Params['path']);
	$template = CFileMan::SecurePathVar($Params['template']);
	$site = $Params['site'];
	$code = $Params['code'];
	$basePath = self::GetBasePath($template);
	$templatePath = mb_substr($basePath, 0, -9);
	$thumb = $Params['thumb'] === false ? false : CFileMan::SecurePathVar($Params['thumb']);

	if (!file_exists($templatePath))
	{
		?>SaveFileContent($basePath.'/'.$key, $code);

	// 2. Rewrite title & description in .content.php
	if ($title || $description)
	{
		if (file_exists($basePath."/.content.php"))
			@include($basePath."/.content.php");
		else
			$SNIPPETS = array();

		if ($title)
			$SNIPPETS[$key]['title'] = $title;
		if ($description)
			$SNIPPETS[$key]['description'] = $description;

		$contentSrc = ''.chr(10);
		$contentSrc .= '$_arSn)
		{
			if (CSnippets::CheckFile(array('site' => $Params["site"], 'template' => $Params['template'], 'path' => $k)))
				$contentSrc .= '$SNIPPETS[''.CUtil::addslashes($k).''] = Array("title"=>''.Cutil::addslashes($_arSn['title'] ?? null).'', "description"=>''.Cutil::addslashes($_arSn['description'] ?? null).'');'.chr(10);
		}
		$contentSrc .= '?>';

		$APPLICATION->SaveFileContent($basePath."/.content.php", $contentSrc);
	}

	CSnippets::ClearCache();

	// 3. Handle thumbnail
	if ($thumb !== false)
	{
		if (mb_substr($thumb, 0, 1) == '/')
			$thumb = mb_substr($thumb, 1);

		$pos = mb_strrpos($name, ".");
		if ($pos === FALSE)
			return true;

		//delete existent thumbnail
		$f_name = mb_substr($name, 0, $pos);
		$img_path1 = BX_PERSONAL_ROOT.'/templates/'.$template.'/snippets/images/'.$path.($path == '' ?  '' : '/').$f_name;
		$DOC_ROOT = CSite::GetSiteDocRoot($site);
		$arExt = array("gif", "jpg", "jpeg", "png", "bmp");
		for ($i = 0, $c = count($arExt); $i < $c; $i++)
		{
			$p_ = $img_path1.".".$arExt[$i];
			if(file_exists($DOC_ROOT.$p_))
				CFileman::DeleteFile(Array($site, $p_));
		}

		if (empty($thumb) || mb_strrpos($thumb, '.') === FALSE)
			return true;

		// Copy Thumbnail
		$path_from_1 = $DOC_ROOT."/".$thumb;
		$path_from = '/'.$thumb;

		if (file_exists($path_from_1))
		{
			$pos = mb_strrpos($thumb, ".");
			$f_ext = ($pos !== FALSE)? mb_strtolower(mb_substr($thumb, $pos + 1)) : '';

			if (in_array($f_ext, $arExt))
			{
				$path_to = $img_path1.'.'.$f_ext;
				$strWarning_tmp = CFileMan::CopyEx(Array($site, $path_from), Array($site, $path_to));
			}
		}
	}
}