- Модуль: ui
- Путь к файлу: ~/bitrix/modules/ui/lib/barcode/barcodegenerator.php
- Класс: BitrixUIBarcodeBarcodeGenerator
- Вызов: BarcodeGenerator::ean_8_normalize
private function ean_8_normalize($data) {
$data = preg_replace('/[^0-9*]/', '', $data);
/* Set length to 8 digits. */
if (strlen($data) < 8) {
$midpoint = floor(strlen($data) / 2);
$left = substr($data, 0, $midpoint);
$center = str_repeat('0', 8 - strlen($data));
$right = substr($data, $midpoint);
$data = $left . $center . $right;
} else if (strlen($data) > 8) {
$left = substr($data, 0, 4);
$right = substr($data, -4);
$data = $left . $right;
}
/* Replace * with missing or check digit. */
while (($o = strrpos($data, '*')) !== false) {
$checksum = 0;
for ($i = 0; $i < 8; $i++) {
$digit = substr($data, $i, 1);
$checksum += (($i % 2) ? 1 : 3) * $digit;
}
$checksum *= (($o % 2) ? 9 : 3);
$left = substr($data, 0, $o);
$center = substr($checksum, -1);
$right = substr($data, $o + 1);
$data = $left . $center . $right;
}
return $data;
}