- Модуль: intranet
- Путь к файлу: ~/bitrix/modules/intranet/lib/integration/rest/configuration/entity/theme.php
- Класс: BitrixIntranetIntegrationRestConfigurationEntityTheme
- Вызов: Theme::import
static function import($params)
{
$result = null;
if (
Helper::checkAccessManifest($params, static::$accessManifest)
&& !empty($params['CONTENT']['DATA'])
)
{
$result = [];
$themePicker = ThemePicker::getInstance();
$data = $params['CONTENT']['DATA'];
if (!empty($data['CODE']))
{
$theme = $themePicker->getStandardTheme($data['ID']);
if (is_array($theme))
{
$success = $themePicker->setCurrentThemeId($theme['id']);
if ($success && ThemePicker::isAdmin())
{
$themePicker->setDefaultTheme($theme['id']);
CacheProvider::deleteUserCache();
}
else
{
$result['ERROR_MESSAGES'] = Loc::getMessage('INTRANET_CONFIGURATION_THEME_ERROR_SET_DEFAULT');
}
}
else
{
$result['ERROR_MESSAGES'] = Loc::getMessage('INTRANET_CONFIGURATION_THEME_ERROR_NOT_FOUND');
}
}
else
{
try
{
$themeId = false;
$saveData = [
'textColor' => $data['TEXT_COLOR'],
];
if ($data['BACKGROUND_COLOR'] <> '')
{
$saveData['bgColor'] = $data['BACKGROUND_COLOR'];
}
if ($data['BACKGROUND_IMAGE'] > 0)
{
$structure = new BitrixRestConfigurationStructure($params['CONTEXT_USER']);
$file = $structure->getUnpackFile($data['BACKGROUND_IMAGE']);
if ($file && $file['PATH'] && $file['NAME'])
{
//on create check file extensions, copy file with real name to tmp folder
$tmpFolder = $structure->getFolder();
if ($tmpFolder)
{
$folder = $tmpFolder.'tmp_files/';
if (CheckDirPath($folder))
{
$image = File::getFileContents($file['PATH']);
File::putFileContents($folder.$file['NAME'], $image);
$saveData['bgImage'] = CFile::MakeFileArray($folder.$file['NAME']);
}
}
}
}
if (!$saveData['bgImage'] && !$saveData['bgColor'] && $data['ID'])
{
$themeList = $themePicker->getList();
$key = array_search($data['ID'], array_column($themeList, 'id'));
if ($key !== false)
{
$themeId = $themeList[$key]['id'];
}
}
if (!$themeId)
{
$themeId = $themePicker->create($saveData);
}
if ($themeId)
{
$success = $themePicker->setCurrentThemeId($themeId);
if ($success && ThemePicker::isAdmin())
{
$themePicker->setDefaultTheme($themeId);
CacheProvider::deleteUserCache();
}
else
{
$result['ERROR_MESSAGES'] = Loc::getMessage('INTRANET_CONFIGURATION_THEME_ERROR_SET_DEFAULT');
}
}
}
catch (SystemException $e)
{
$result['ERROR_MESSAGES'] = $e->getMessage();
}
}
}
return $result;
}