• Модуль: intranet
  • Путь к файлу: ~/bitrix/modules/intranet/lib/integration/templates/bitrix24/themepicker.php
  • Класс: BitrixIntranetIntegrationTemplatesBitrix24ThemePicker
  • Вызов: ThemePicker::create
public function create(array $fields)
{
	if (count($this->getCustomThemesOptions()) > static::MAX_CUSTOM_THEMES)
	{
		throw new SystemException(
			Loc::getMessage(
				"INTRANET_B24_INTEGRATION_THEMES_LIMIT_EXCEEDED",
				array("#NUM#" => static::MAX_CUSTOM_THEMES)
			)
		);
	}

	$theme = array();
	if (isset($fields["bgColor"]) && preg_match("/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/", $fields["bgColor"]))
	{
		$theme["bgColor"] = $fields["bgColor"];
	}

	if (isset($fields["bgImage"]["tmp_name"]) && $fields["bgImage"]["tmp_name"] <> '')
	{
		$error = CFile::checkImageFile(
			$fields["bgImage"],
			static::getMaxUploadSize(),
			static::MAX_IMAGE_WIDTH,
			static::MAX_IMAGE_HEIGHT
		);

		if ($error <> '')
		{
			throw new SystemException($error);
		}

		$imageId = CFile::saveFile($fields["bgImage"], "bitrix24");
		if (!$imageId)
		{
			throw new SystemException(Loc::getMessage("INTRANET_B24_INTEGRATION_UPLOAD_ERROR"));
		}

		$theme["bgImage"] = $imageId;
	}

	if (empty($theme))
	{
		throw new SystemException(Loc::getMessage("INTRANET_B24_INTEGRATION_CANT_CREATE_THEME"));
	}

	$baseThemeId = isset($fields["textColor"]) && $fields["textColor"] === "dark" ? "dark" : "light";
	$subThemeId = $this->getCustomThemePrefix().time();
	$themeId = $baseThemeId.":".$subThemeId;

	$customThemes = $this->getCustomThemesOptions();
	$customThemes[$themeId] = $theme;
	$this->setCustomThemesOptions($customThemes);

	$this->setLastUsage($themeId);

	return $themeId;
}