- Модуль: mail
- Путь к файлу: ~/bitrix/modules/mail/lib/user.php
- Класс: BitrixMailUser
- Вызов: User::getReplyTo
static function getReplyTo($siteId, $userId, $entityType, $entityId, $entityLink = null, $backurl = null)
{
$filter = array(
'=SITE_ID' => $siteId,
'=USER_ID' => $userId,
'=ENTITY_TYPE' => $entityType,
'=ENTITY_ID' => $entityId
);
$userRelation = UserRelationsTable::getList(array('filter' => $filter))->fetch();
if (empty($userRelation))
{
$filter['=SITE_ID'] = null;
$userRelation = UserRelationsTable::getList(array('filter' => $filter))->fetch();
}
if (empty($userRelation))
{
if (empty($entityLink))
return false;
$userRelation = array(
'SITE_ID' => $siteId,
'TOKEN' => base_convert(md5(time().MainSecurityRandom::getBytes(6)), 16, 36),
'USER_ID' => $userId,
'ENTITY_TYPE' => $entityType,
'ENTITY_ID' => $entityId,
'ENTITY_LINK' => $entityLink,
'BACKURL' => $backurl
);
if (!UserRelationsTable::add($userRelation)->isSuccess())
return false;
}
$site = MainSiteTable::getByPrimary($siteId)->fetch();
$context = MainApplication::getInstance()->getContext();
$scheme = $context->getRequest()->isHttps() ? 'https' : 'http';
$domain = $site['SERVER_NAME'] ?: COption::getOptionString('main', 'server_name', '');
if (preg_match('/^(?.+):(?d+)$/', $domain, $matches))
{
$domain = $matches['domain'];
$port = $matches['port'];
}
else
{
$port = $context->getServer()->getServerPort();
}
$port = in_array($port, array(80, 443)) ? '' : ':'.$port;
$path = ltrim(trim($site['DIR'], '/') . '/pub/entry.php', '/');
$replyTo = sprintf('rpl%s@%s', $userRelation['TOKEN'], $domain);
$backUrl = sprintf('%s://%s%s/%s#%s', $scheme, $domain, $port, $path, $userRelation['TOKEN']);
return array($replyTo, $backUrl);
}