- Модуль: mail
- Путь к файлу: ~/bitrix/modules/mail/classes/general/mail.php
- Класс: CAllMailMessage
- Вызов: CAllMailMessage::trimContent
static function trimContent(array &$fields, $trimLength, $filters)
{
foreach ($filters as $filter)
{
if (is_array($filter))
{
$filter = array_filter(
$filter,
function ($name) use ($fields)
{
return isset($fields[$name]);
}
);
$totalLength = array_reduce(
$filter,
function ($total, $name) use ($fields)
{
$length = BinaryString::getLength($fields[$name]);
return $total + $length;
},
0
);
if ($totalLength === 0)
{
continue;
}
$overLength = 0;
foreach ($filter as $subFilter)
{
$length = BinaryString::getLength($fields[$subFilter]);
$ratio = $length / $totalLength;
$over = ceil($trimLength * $ratio);
$newLength = $length - $over;
$fields[$subFilter] = $newLength > 0 ? BinaryString::getSubstring($fields[$subFilter], 0, $newLength) : '';
$overLength += $newLength > 0 ? $over : $length;
}
$trimLength -= $overLength;
}
else
{
if (isset($fields[$filter]))
{
$length = BinaryString::getLength($fields[$filter]);
$newLength = $length - $trimLength;
$fields[$filter] = $newLength > 0 ? BinaryString::getSubstring($fields[$filter], 0, $newLength) : '';
$trimLength -= $newLength > 0 ? $trimLength : $length;
}
}
if ($trimLength <= 0)
{
break;
}
}
return $fields;
}