From 8ca6cc32b2c789a3149861159ad258f2cb9491e3 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 28 Apr 2024 14:39:39 +0200 Subject: Adding upstream version 2.11.4. Signed-off-by: Daniel Baumann --- .../Zend/Validate/Barcode/AdapterAbstract.php | 314 +++++++++++++++++++++ .../Zend/Validate/Barcode/AdapterInterface.php | 68 +++++ library/vendor/Zend/Validate/Barcode/Code25.php | 61 ++++ .../Zend/Validate/Barcode/Code25interleaved.php | 61 ++++ library/vendor/Zend/Validate/Barcode/Code39.php | 97 +++++++ library/vendor/Zend/Validate/Barcode/Code39ext.php | 55 ++++ library/vendor/Zend/Validate/Barcode/Code93.php | 117 ++++++++ library/vendor/Zend/Validate/Barcode/Code93ext.php | 55 ++++ library/vendor/Zend/Validate/Barcode/Ean12.php | 51 ++++ library/vendor/Zend/Validate/Barcode/Ean13.php | 51 ++++ library/vendor/Zend/Validate/Barcode/Ean14.php | 51 ++++ library/vendor/Zend/Validate/Barcode/Ean18.php | 51 ++++ library/vendor/Zend/Validate/Barcode/Ean2.php | 55 ++++ library/vendor/Zend/Validate/Barcode/Ean5.php | 55 ++++ library/vendor/Zend/Validate/Barcode/Ean8.php | 68 +++++ library/vendor/Zend/Validate/Barcode/Gtin12.php | 51 ++++ library/vendor/Zend/Validate/Barcode/Gtin13.php | 51 ++++ library/vendor/Zend/Validate/Barcode/Gtin14.php | 51 ++++ library/vendor/Zend/Validate/Barcode/Identcode.php | 51 ++++ .../Zend/Validate/Barcode/Intelligentmail.php | 55 ++++ library/vendor/Zend/Validate/Barcode/Issn.php | 118 ++++++++ library/vendor/Zend/Validate/Barcode/Itf14.php | 51 ++++ library/vendor/Zend/Validate/Barcode/Leitcode.php | 51 ++++ library/vendor/Zend/Validate/Barcode/Planet.php | 51 ++++ library/vendor/Zend/Validate/Barcode/Postnet.php | 51 ++++ library/vendor/Zend/Validate/Barcode/Royalmail.php | 120 ++++++++ library/vendor/Zend/Validate/Barcode/Sscc.php | 51 ++++ library/vendor/Zend/Validate/Barcode/Upca.php | 51 ++++ library/vendor/Zend/Validate/Barcode/Upce.php | 68 +++++ 29 files changed, 2081 insertions(+) create mode 100644 library/vendor/Zend/Validate/Barcode/AdapterAbstract.php create mode 100644 library/vendor/Zend/Validate/Barcode/AdapterInterface.php create mode 100644 library/vendor/Zend/Validate/Barcode/Code25.php create mode 100644 library/vendor/Zend/Validate/Barcode/Code25interleaved.php create mode 100644 library/vendor/Zend/Validate/Barcode/Code39.php create mode 100644 library/vendor/Zend/Validate/Barcode/Code39ext.php create mode 100644 library/vendor/Zend/Validate/Barcode/Code93.php create mode 100644 library/vendor/Zend/Validate/Barcode/Code93ext.php create mode 100644 library/vendor/Zend/Validate/Barcode/Ean12.php create mode 100644 library/vendor/Zend/Validate/Barcode/Ean13.php create mode 100644 library/vendor/Zend/Validate/Barcode/Ean14.php create mode 100644 library/vendor/Zend/Validate/Barcode/Ean18.php create mode 100644 library/vendor/Zend/Validate/Barcode/Ean2.php create mode 100644 library/vendor/Zend/Validate/Barcode/Ean5.php create mode 100644 library/vendor/Zend/Validate/Barcode/Ean8.php create mode 100644 library/vendor/Zend/Validate/Barcode/Gtin12.php create mode 100644 library/vendor/Zend/Validate/Barcode/Gtin13.php create mode 100644 library/vendor/Zend/Validate/Barcode/Gtin14.php create mode 100644 library/vendor/Zend/Validate/Barcode/Identcode.php create mode 100644 library/vendor/Zend/Validate/Barcode/Intelligentmail.php create mode 100644 library/vendor/Zend/Validate/Barcode/Issn.php create mode 100644 library/vendor/Zend/Validate/Barcode/Itf14.php create mode 100644 library/vendor/Zend/Validate/Barcode/Leitcode.php create mode 100644 library/vendor/Zend/Validate/Barcode/Planet.php create mode 100644 library/vendor/Zend/Validate/Barcode/Postnet.php create mode 100644 library/vendor/Zend/Validate/Barcode/Royalmail.php create mode 100644 library/vendor/Zend/Validate/Barcode/Sscc.php create mode 100644 library/vendor/Zend/Validate/Barcode/Upca.php create mode 100644 library/vendor/Zend/Validate/Barcode/Upce.php (limited to 'library/vendor/Zend/Validate/Barcode') diff --git a/library/vendor/Zend/Validate/Barcode/AdapterAbstract.php b/library/vendor/Zend/Validate/Barcode/AdapterAbstract.php new file mode 100644 index 0000000..01e2409 --- /dev/null +++ b/library/vendor/Zend/Validate/Barcode/AdapterAbstract.php @@ -0,0 +1,314 @@ +getLength(); + if (is_array($length)) { + foreach ($length as $value) { + if ($fixum == $value) { + $found = true; + } + + if ($value == -1) { + $found = true; + } + } + } elseif ($fixum == $length) { + $found = true; + } elseif ($length == -1) { + $found = true; + } elseif ($length == 'even') { + $count = $fixum % 2; + $found = ($count == 0) ? true : false; + } elseif ($length == 'odd') { + $count = $fixum % 2; + $found = ($count == 1) ? true : false; + } + + return $found; + } + + /** + * Checks for allowed characters within the barcode + * + * @param string $value The barcode to check for allowed characters + * @return boolean + */ + public function checkChars($value) + { + if (!is_string($value)) { + return false; + } + + $characters = $this->getCharacters(); + if ($characters == 128) { + for ($x = 0; $x < 128; ++$x) { + $value = str_replace(chr($x), '', $value); + } + } else { + $chars = str_split($characters); + foreach ($chars as $char) { + $value = str_replace($char, '', $value); + } + } + + if (strlen($value) > 0) { + return false; + } + + return true; + } + + /** + * Validates the checksum + * + * @param string $value The barcode to check the checksum for + * @return boolean + */ + public function checksum($value) + { + $checksum = $this->getChecksum(); + if (!empty($checksum)) { + if (method_exists($this, $checksum)) { + return call_user_func(array($this, $checksum), $value); + } + } + + return false; + } + + /** + * Returns the allowed barcode length + * + * @return string + */ + public function getLength() + { + return $this->_length; + } + + /** + * Returns the allowed characters + * + * @return integer|string + */ + public function getCharacters() + { + return $this->_characters; + } + + /** + * Returns the checksum function name + * + */ + public function getChecksum() + { + return $this->_checksum; + } + + /** + * Returns if barcode uses checksum + * + * @return boolean + */ + public function getCheck() + { + return $this->_hasChecksum; + } + + /** + * Sets the checksum validation + * + * @param boolean $check + * @return Zend_Validate_Barcode_AdapterAbstract + */ + public function setCheck($check) + { + $this->_hasChecksum = (boolean) $check; + return $this; + } + + /** + * Validates the checksum (Modulo 10) + * GTIN implementation factor 3 + * + * @param string $value The barcode to validate + * @return boolean + */ + protected function _gtin($value) + { + $barcode = substr($value, 0, -1); + $sum = 0; + $length = strlen($barcode) - 1; + + for ($i = 0; $i <= $length; $i++) { + if (($i % 2) === 0) { + $sum += $barcode[$length - $i] * 3; + } else { + $sum += $barcode[$length - $i]; + } + } + + $calc = $sum % 10; + $checksum = ($calc === 0) ? 0 : (10 - $calc); + if ($value[$length + 1] != $checksum) { + return false; + } + + return true; + } + + /** + * Validates the checksum (Modulo 10) + * IDENTCODE implementation factors 9 and 4 + * + * @param string $value The barcode to validate + * @return boolean + */ + protected function _identcode($value) + { + $barcode = substr($value, 0, -1); + $sum = 0; + $length = strlen($value) - 2; + + for ($i = 0; $i <= $length; $i++) { + if (($i % 2) === 0) { + $sum += $barcode[$length - $i] * 4; + } else { + $sum += $barcode[$length - $i] * 9; + } + } + + $calc = $sum % 10; + $checksum = ($calc === 0) ? 0 : (10 - $calc); + if ($value[$length + 1] != $checksum) { + return false; + } + + return true; + } + + /** + * Validates the checksum (Modulo 10) + * CODE25 implementation factor 3 + * + * @param string $value The barcode to validate + * @return boolean + */ + protected function _code25($value) + { + $barcode = substr($value, 0, -1); + $sum = 0; + $length = strlen($barcode) - 1; + + for ($i = 0; $i <= $length; $i++) { + if (($i % 2) === 0) { + $sum += $barcode[$i] * 3; + } else { + $sum += $barcode[$i]; + } + } + + $calc = $sum % 10; + $checksum = ($calc === 0) ? 0 : (10 - $calc); + if ($value[$length + 1] != $checksum) { + return false; + } + + return true; + } + + /** + * Validates the checksum () + * POSTNET implementation + * + * @param string $value The barcode to validate + * @return boolean + */ + protected function _postnet($value) + { + $checksum = substr($value, -1, 1); + $values = str_split(substr($value, 0, -1)); + + $check = 0; + foreach($values as $row) { + $check += $row; + } + + $check %= 10; + $check = 10 - $check; + if ($check == $checksum) { + return true; + } + + return false; + } +} diff --git a/library/vendor/Zend/Validate/Barcode/AdapterInterface.php b/library/vendor/Zend/Validate/Barcode/AdapterInterface.php new file mode 100644 index 0000000..8e96eff --- /dev/null +++ b/library/vendor/Zend/Validate/Barcode/AdapterInterface.php @@ -0,0 +1,68 @@ +setCheck(false); + } +} diff --git a/library/vendor/Zend/Validate/Barcode/Code25interleaved.php b/library/vendor/Zend/Validate/Barcode/Code25interleaved.php new file mode 100644 index 0000000..c952781 --- /dev/null +++ b/library/vendor/Zend/Validate/Barcode/Code25interleaved.php @@ -0,0 +1,61 @@ +setCheck(false); + } +} diff --git a/library/vendor/Zend/Validate/Barcode/Code39.php b/library/vendor/Zend/Validate/Barcode/Code39.php new file mode 100644 index 0000000..e1554a1 --- /dev/null +++ b/library/vendor/Zend/Validate/Barcode/Code39.php @@ -0,0 +1,97 @@ + 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, + '7' => 7, '8' => 8, '9' => 9, 'A' => 10, 'B' => 11, 'C' => 12, 'D' => 13, + 'E' => 14, 'F' => 15, 'G' => 16, 'H' => 17, 'I' => 18, 'J' => 19, 'K' => 20, + 'L' => 21, 'M' => 22, 'N' => 23, 'O' => 24, 'P' => 25, 'Q' => 26, 'R' => 27, + 'S' => 28, 'T' => 29, 'U' => 30, 'V' => 31, 'W' => 32, 'X' => 33, 'Y' => 34, + 'Z' => 35, '-' => 36, '.' => 37, ' ' => 38, '$' => 39, '/' => 40, '+' => 41, + '%' => 42, + ); + + /** + * Constructor + * + * Sets check flag to false. + */ + public function __construct() + { + $this->setCheck(false); + } + + /** + * Validates the checksum (Modulo 43) + * + * @param string $value The barcode to validate + * @return boolean + */ + protected function _code39($value) + { + $checksum = substr($value, -1, 1); + $value = str_split(substr($value, 0, -1)); + $count = 0; + foreach($value as $char) { + $count += $this->_check[$char]; + } + + $mod = $count % 43; + if ($mod == $this->_check[$checksum]) { + return true; + } + + return false; + } +} diff --git a/library/vendor/Zend/Validate/Barcode/Code39ext.php b/library/vendor/Zend/Validate/Barcode/Code39ext.php new file mode 100644 index 0000000..a295694 --- /dev/null +++ b/library/vendor/Zend/Validate/Barcode/Code39ext.php @@ -0,0 +1,55 @@ +setCheck(false); + } +} diff --git a/library/vendor/Zend/Validate/Barcode/Code93.php b/library/vendor/Zend/Validate/Barcode/Code93.php new file mode 100644 index 0000000..2f83ee8 --- /dev/null +++ b/library/vendor/Zend/Validate/Barcode/Code93.php @@ -0,0 +1,117 @@ + 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, + '7' => 7, '8' => 8, '9' => 9, 'A' => 10, 'B' => 11, 'C' => 12, 'D' => 13, + 'E' => 14, 'F' => 15, 'G' => 16, 'H' => 17, 'I' => 18, 'J' => 19, 'K' => 20, + 'L' => 21, 'M' => 22, 'N' => 23, 'O' => 24, 'P' => 25, 'Q' => 26, 'R' => 27, + 'S' => 28, 'T' => 29, 'U' => 30, 'V' => 31, 'W' => 32, 'X' => 33, 'Y' => 34, + 'Z' => 35, '-' => 36, '.' => 37, ' ' => 38, '$' => 39, '/' => 40, '+' => 41, + '%' => 42, '!' => 43, '"' => 44, '§' => 45, '&' => 46, + ); + + /** + * Constructor + * + * Sets check flag to false. + */ + public function __construct() + { + $this->setCheck(false); + } + + /** + * Validates the checksum (Modulo CK) + * + * @param string $value The barcode to validate + * @return boolean + */ + protected function _code93($value) + { + $checksum = substr($value, -2, 2); + $value = str_split(substr($value, 0, -2)); + $count = 0; + $length = count($value) % 20; + foreach($value as $char) { + if ($length == 0) { + $length = 20; + } + + $count += $this->_check[$char] * $length; + --$length; + } + + $check = array_search(($count % 47), $this->_check); + $value[] = $check; + $count = 0; + $length = count($value) % 15; + foreach($value as $char) { + if ($length == 0) { + $length = 15; + } + + $count += $this->_check[$char] * $length; + --$length; + } + $check .= array_search(($count % 47), $this->_check); + + if ($check == $checksum) { + return true; + } + + return false; + } +} diff --git a/library/vendor/Zend/Validate/Barcode/Code93ext.php b/library/vendor/Zend/Validate/Barcode/Code93ext.php new file mode 100644 index 0000000..8795f00 --- /dev/null +++ b/library/vendor/Zend/Validate/Barcode/Code93ext.php @@ -0,0 +1,55 @@ +setCheck(false); + } +} diff --git a/library/vendor/Zend/Validate/Barcode/Ean12.php b/library/vendor/Zend/Validate/Barcode/Ean12.php new file mode 100644 index 0000000..67bb14c --- /dev/null +++ b/library/vendor/Zend/Validate/Barcode/Ean12.php @@ -0,0 +1,51 @@ +setCheck(false); + } +} diff --git a/library/vendor/Zend/Validate/Barcode/Ean5.php b/library/vendor/Zend/Validate/Barcode/Ean5.php new file mode 100644 index 0000000..74654a7 --- /dev/null +++ b/library/vendor/Zend/Validate/Barcode/Ean5.php @@ -0,0 +1,55 @@ +setCheck(false); + } +} diff --git a/library/vendor/Zend/Validate/Barcode/Ean8.php b/library/vendor/Zend/Validate/Barcode/Ean8.php new file mode 100644 index 0000000..7f61dfb --- /dev/null +++ b/library/vendor/Zend/Validate/Barcode/Ean8.php @@ -0,0 +1,68 @@ +setCheck(false); + } else { + $this->setCheck(true); + } + + return parent::checkLength($value); + } +} diff --git a/library/vendor/Zend/Validate/Barcode/Gtin12.php b/library/vendor/Zend/Validate/Barcode/Gtin12.php new file mode 100644 index 0000000..d94a1b5 --- /dev/null +++ b/library/vendor/Zend/Validate/Barcode/Gtin12.php @@ -0,0 +1,51 @@ +setCheck(false); + } +} diff --git a/library/vendor/Zend/Validate/Barcode/Issn.php b/library/vendor/Zend/Validate/Barcode/Issn.php new file mode 100644 index 0000000..49c705d --- /dev/null +++ b/library/vendor/Zend/Validate/Barcode/Issn.php @@ -0,0 +1,118 @@ +_checksum = '_issn'; + } else { + $this->_checksum = '_gtin'; + } + + return parent::checksum($value); + } + + /** + * Validates the checksum () + * ISSN implementation (reversed mod11) + * + * @param string $value The barcode to validate + * @return boolean + */ + protected function _issn($value) + { + $checksum = substr($value, -1, 1); + $values = str_split(substr($value, 0, -1)); + $check = 0; + $multi = 8; + foreach($values as $token) { + if ($token == 'X') { + $token = 10; + } + + $check += ($token * $multi); + --$multi; + } + + $check %= 11; + $check = 11 - $check; + if ($check == $checksum) { + return true; + } else if (($check == 10) && ($checksum == 'X')) { + return true; + } + + return false; + } +} diff --git a/library/vendor/Zend/Validate/Barcode/Itf14.php b/library/vendor/Zend/Validate/Barcode/Itf14.php new file mode 100644 index 0000000..0ed97d1 --- /dev/null +++ b/library/vendor/Zend/Validate/Barcode/Itf14.php @@ -0,0 +1,51 @@ + 1, '1' => 1, '2' => 1, '3' => 1, '4' => 1, '5' => 1, + '6' => 2, '7' => 2, '8' => 2, '9' => 2, 'A' => 2, 'B' => 2, + 'C' => 3, 'D' => 3, 'E' => 3, 'F' => 3, 'G' => 3, 'H' => 3, + 'I' => 4, 'J' => 4, 'K' => 4, 'L' => 4, 'M' => 4, 'N' => 4, + 'O' => 5, 'P' => 5, 'Q' => 5, 'R' => 5, 'S' => 5, 'T' => 5, + 'U' => 0, 'V' => 0, 'W' => 0, 'X' => 0, 'Y' => 0, 'Z' => 0, + ); + + protected $_columns = array( + '0' => 1, '1' => 2, '2' => 3, '3' => 4, '4' => 5, '5' => 0, + '6' => 1, '7' => 2, '8' => 3, '9' => 4, 'A' => 5, 'B' => 0, + 'C' => 1, 'D' => 2, 'E' => 3, 'F' => 4, 'G' => 5, 'H' => 0, + 'I' => 1, 'J' => 2, 'K' => 3, 'L' => 4, 'M' => 5, 'N' => 0, + 'O' => 1, 'P' => 2, 'Q' => 3, 'R' => 4, 'S' => 5, 'T' => 0, + 'U' => 1, 'V' => 2, 'W' => 3, 'X' => 4, 'Y' => 5, 'Z' => 0, + ); + + /** + * Checksum function + * @var string + */ + protected $_checksum = '_royalmail'; + + /** + * Validates the checksum () + * + * @param string $value The barcode to validate + * @return boolean + */ + protected function _royalmail($value) + { + $checksum = substr($value, -1, 1); + $values = str_split(substr($value, 0, -1)); + $rowvalue = 0; + $colvalue = 0; + foreach($values as $row) { + $rowvalue += $this->_rows[$row]; + $colvalue += $this->_columns[$row]; + } + + $rowvalue %= 6; + $colvalue %= 6; + + $rowchkvalue = array_keys($this->_rows, $rowvalue); + $colchkvalue = array_keys($this->_columns, $colvalue); + $chkvalue = current(array_intersect($rowchkvalue, $colchkvalue)); + if ($chkvalue == $checksum) { + return true; + } + + return false; + } + + /** + * Allows start and stop tag within checked chars + * + * @param string $value The barcode to check for allowed characters + * @return boolean + */ + public function checkChars($value) + { + if ($value[0] == '(') { + $value = substr($value, 1); + + if ($value[strlen($value) - 1] == ')') { + $value = substr($value, 0, -1); + } else { + return false; + } + } + + return parent::checkChars($value); + } +} diff --git a/library/vendor/Zend/Validate/Barcode/Sscc.php b/library/vendor/Zend/Validate/Barcode/Sscc.php new file mode 100644 index 0000000..e234bf1 --- /dev/null +++ b/library/vendor/Zend/Validate/Barcode/Sscc.php @@ -0,0 +1,51 @@ +setCheck(false); + } else { + $this->setCheck(true); + } + + return parent::checkLength($value); + } +} -- cgit v1.2.3