- Модуль: main
- Путь к файлу: ~/bitrix/modules/main/classes/general/user.php
- Класс: CAllUser
- Вызов: CAllUser::FormatName
static function FormatName($NAME_TEMPLATE, $arUser, $bUseLogin = false, $bHTMLSpec = true, $enabledEmptyNameStub = true)
{
if (isset($arUser["ID"]))
{
$ID = intval($arUser['ID']);
}
else
{
$ID = '';
}
$NAME_SHORT = (($arUser['NAME'] ?? '') != '' ? mb_substr($arUser['NAME'], 0, 1) . '.' : '');
$LAST_NAME_SHORT = (($arUser['LAST_NAME'] ?? '') != '' ? mb_substr($arUser['LAST_NAME'], 0, 1) . '.' : '');
$SECOND_NAME_SHORT = (($arUser['SECOND_NAME'] ?? '') != '' ? mb_substr($arUser['SECOND_NAME'], 0, 1) . '.' : '');
$res = str_replace(
['#TITLE#', '#NAME#', '#LAST_NAME#', '#SECOND_NAME#', '#NAME_SHORT#', '#LAST_NAME_SHORT#', '#SECOND_NAME_SHORT#', '#EMAIL#', '#ID#'],
[($arUser['TITLE'] ?? ''), ($arUser['NAME'] ?? ''), ($arUser['LAST_NAME'] ?? ''), ($arUser['SECOND_NAME'] ?? ''), $NAME_SHORT, $LAST_NAME_SHORT, $SECOND_NAME_SHORT, ($arUser['EMAIL'] ?? ''), $ID],
$NAME_TEMPLATE
);
while (strpos($res, ' ') !== false)
{
$res = str_replace(' ', ' ', $res);
}
$res = trim($res);
$res_check = '';
if (strpos($NAME_TEMPLATE, '#NAME#') !== false || strpos($NAME_TEMPLATE, '#NAME_SHORT#') !== false)
{
$res_check .= $arUser['NAME'] ?? '';
}
if (strpos($NAME_TEMPLATE, '#LAST_NAME#') !== false || strpos($NAME_TEMPLATE, '#LAST_NAME_SHORT#') !== false)
{
$res_check .= $arUser['LAST_NAME'] ?? '';
}
if (strpos($NAME_TEMPLATE, '#SECOND_NAME#') !== false || strpos($NAME_TEMPLATE, '#SECOND_NAME_SHORT#') !== false)
{
$res_check .= $arUser['SECOND_NAME'] ?? '';
}
if (trim($res_check) == '')
{
if ($bUseLogin && !empty($arUser['LOGIN']))
{
$res = $arUser['LOGIN'];
}
elseif ($enabledEmptyNameStub)
{
$res = GetMessage('FORMATNAME_NONAME');
}
else
{
$res = '';
}
if (strpos($NAME_TEMPLATE, '[#ID#]') !== false)
{
$res .= " [" . $ID . "]";
}
}
if ($bHTMLSpec)
{
$res = htmlspecialcharsbx($res);
}
$res = str_replace(['#NOBR#', '#/NOBR#'], '', $res);
return $res;
}