Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.

Differences Between: [Versions 310 and 400] [Versions 39 and 400] [Versions 400 and 401] [Versions 400 and 402] [Versions 400 and 403]

(no description)

Author: Nicola Asuni
Version: 1.0.010
File Size: 2868 lines (80 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

QRcode:: (98 methods):
  __construct()
  getBarcodeArray()
  binarize()
  encodeString()
  encodeMask()
  setFrameAt()
  getFrameAt()
  getNextPosition()
  init()
  getCode()
  writeFormatInformation()
  mask0()
  mask1()
  mask2()
  mask3()
  mask4()
  mask5()
  mask6()
  mask7()
  generateMaskNo()
  makeMaskNo()
  makeMask()
  calcN1N3()
  evaluateSymbol()
  mask()
  isdigitat()
  isalnumat()
  identifyMode()
  eatNum()
  eatAn()
  eatKanji()
  eat8()
  splitString()
  toUpper()
  newInputItem()
  encodeModeNum()
  encodeModeAn()
  encodeMode8()
  encodeModeKanji()
  encodeModeStructure()
  encodeBitStream()
  appendNewInputItem()
  insertStructuredAppendHeader()
  calcParity()
  checkModeNum()
  lookAnTable()
  checkModeAn()
  estimateBitsModeNum()
  estimateBitsModeAn()
  estimateBitsMode8()
  estimateBitsModeKanji()
  checkModeKanji()
  check()
  estimateBitStreamSize()
  estimateVersion()
  lengthOfCode()
  createBitStream()
  convertData()
  appendPaddingBit()
  mergeBitStream()
  getBitStream()
  getByteStream()
  allocate()
  newFromNum()
  newFromBytes()
  appendBitstream()
  appendNum()
  appendBytes()
  bitstreamToByte()
  qrstrset()
  getDataLength()
  getECCLength()
  getWidth()
  getRemainder()
  getMinimumVersion()
  lengthIndicator()
  maximumWords()
  getEccSpec()
  putAlignmentMarker()
  putAlignmentPattern()
  getVersionPattern()
  getFormatInfo()
  putFinderPattern()
  createFrame()
  newFrame()
  rsBlockNum()
  rsBlockNum1()
  rsDataCodes1()
  rsEccCodes1()
  rsBlockNum2()
  rsDataCodes2()
  rsEccCodes2()
  rsDataLength()
  rsEccLength()
  init_rs()
  modnn()
  init_rs_char()
  encode_rs_char()

Defines 98 functions

  str_split()

Class: QRcode  - X-Ref


__construct($code, $eclevel = 'L')   X-Ref
This is the class constructor.
Creates a QRcode object

param: $code (string) code to represent using QRcode
param: $eclevel (string) error level: <ul><li>L : About 7% or less errors can be corrected.</li><li>M : About 15% or less errors can be corrected.</li><li>Q : About 25% or less errors can be corrected.</li><li>H : About 30% or less errors can be corrected.</li></ul>

getBarcodeArray()   X-Ref
Returns a barcode array which is readable by TCPDF

return: array barcode array readable by TCPDF;

binarize($frame)   X-Ref
Convert the frame in binary form

return: array frame in binary form
param: $frame (array) array to binarize

encodeString($string)   X-Ref
Encode the input string to QR code

param: $string (string) input string to encode

encodeMask($mask)   X-Ref
Encode mask

param: $mask (int) masking mode

setFrameAt($at, $val)   X-Ref
Set frame value at specified position

param: $at (array) x,y position
param: $val (int) value of the character to set

getFrameAt($at)   X-Ref
Get frame value at specified position

return: value at specified position
param: $at (array) x,y position

getNextPosition()   X-Ref
Return the next frame position

return: array of x,y coordinates

init($spec)   X-Ref
Initialize code.

return: 0 in case of success, -1 in case of error
param: $spec (array) array of ECC specification

getCode()   X-Ref
Return Reed-Solomon block code.

return: array rsblocks

writeFormatInformation($width, &$frame, $mask, $level)   X-Ref
Write Format Information on frame and returns the number of black bits

return: int blacks
param: $width (int) frame width
param: $frame (array) frame
param: $mask (array) masking mode
param: $level (int) error correction level

mask0($x, $y)   X-Ref
mask0

return: int mask
param: $x (int) X position
param: $y (int) Y position

mask1($x, $y)   X-Ref
mask1

return: int mask
param: $x (int) X position
param: $y (int) Y position

mask2($x, $y)   X-Ref
mask2

return: int mask
param: $x (int) X position
param: $y (int) Y position

mask3($x, $y)   X-Ref
mask3

return: int mask
param: $x (int) X position
param: $y (int) Y position

mask4($x, $y)   X-Ref
mask4

return: int mask
param: $x (int) X position
param: $y (int) Y position

mask5($x, $y)   X-Ref
mask5

return: int mask
param: $x (int) X position
param: $y (int) Y position

mask6($x, $y)   X-Ref
mask6

return: int mask
param: $x (int) X position
param: $y (int) Y position

mask7($x, $y)   X-Ref
mask7

return: int mask
param: $x (int) X position
param: $y (int) Y position

generateMaskNo($maskNo, $width, $frame)   X-Ref
Return bitmask

return: array bitmask
param: $maskNo (int) mask number
param: $width (int) width
param: $frame (array) frame

makeMaskNo($maskNo, $width, $s, &$d, $maskGenOnly=false)   X-Ref
makeMaskNo

return: int b
param: $maskNo (int)
param: $width (int)
param: $s (int)
param: $d (int)
param: $maskGenOnly (boolean)

makeMask($width, $frame, $maskNo, $level)   X-Ref
makeMask

return: array mask
param: $width (int)
param: $frame (array)
param: $maskNo (int)
param: $level (int)

calcN1N3($length)   X-Ref
calcN1N3

return: int demerit
param: $length (int)

evaluateSymbol($width, $frame)   X-Ref
evaluateSymbol

return: int demerit
param: $width (int)
param: $frame (array)

mask($width, $frame, $level)   X-Ref
mask

return: array best mask
param: $width (int)
param: $frame (array)
param: $level (int)

isdigitat($str, $pos)   X-Ref
Return true if the character at specified position is a number

return: boolean true of false
param: $str (string) string
param: $pos (int) characted position

isalnumat($str, $pos)   X-Ref
Return true if the character at specified position is an alphanumeric character

return: boolean true of false
param: $str (string) string
param: $pos (int) characted position

identifyMode($pos)   X-Ref
identifyMode

return: int mode
param: $pos (int)

eatNum()   X-Ref
eatNum

return: int run

eatAn()   X-Ref
eatAn

return: int run

eatKanji()   X-Ref
eatKanji

return: int run

eat8()   X-Ref
eat8

return: int run

splitString()   X-Ref
splitString

return: (int)

toUpper()   X-Ref
toUpper


newInputItem($mode, $size, $data, $bstream=null)   X-Ref
newInputItem

return: array input item
param: $mode (int)
param: $size (int)
param: $data (array)
param: $bstream (array)

encodeModeNum($inputitem, $version)   X-Ref
encodeModeNum

return: array input item
param: $inputitem (array)
param: $version (int)

encodeModeAn($inputitem, $version)   X-Ref
encodeModeAn

return: array input item
param: $inputitem (array)
param: $version (int)

encodeMode8($inputitem, $version)   X-Ref
encodeMode8

return: array input item
param: $inputitem (array)
param: $version (int)

encodeModeKanji($inputitem, $version)   X-Ref
encodeModeKanji

return: array input item
param: $inputitem (array)
param: $version (int)

encodeModeStructure($inputitem)   X-Ref
encodeModeStructure

return: array input item
param: $inputitem (array)

encodeBitStream($inputitem, $version)   X-Ref
encodeBitStream

return: array input item
param: $inputitem (array)
param: $version (int)

appendNewInputItem($items, $mode, $size, $data)   X-Ref
Append data to an input object.
The data is copied and appended to the input object.

return: items
param: $items (arrray) input items
param: $mode (int) encoding mode.
param: $size (int) size of data (byte).
param: $data (array) array of input data.

insertStructuredAppendHeader($items, $size, $index, $parity)   X-Ref
insertStructuredAppendHeader

return: array items
param: $items (array)
param: $size (int)
param: $index (int)
param: $parity (int)

calcParity($items)   X-Ref
calcParity

return: int parity
param: $items (array)

checkModeNum($size, $data)   X-Ref
checkModeNum

return: boolean true or false
param: $size (int)
param: $data (array)

lookAnTable($c)   X-Ref
Look up the alphabet-numeric convesion table (see JIS X0510:2004, pp.19).

return: value
param: $c (int) character value

checkModeAn($size, $data)   X-Ref
checkModeAn

return: boolean true or false
param: $size (int)
param: $data (array)

estimateBitsModeNum($size)   X-Ref
estimateBitsModeNum

return: int number of bits
param: $size (int)

estimateBitsModeAn($size)   X-Ref
estimateBitsModeAn

return: int number of bits
param: $size (int)

estimateBitsMode8($size)   X-Ref
estimateBitsMode8

return: int number of bits
param: $size (int)

estimateBitsModeKanji($size)   X-Ref
estimateBitsModeKanji

return: int number of bits
param: $size (int)

checkModeKanji($size, $data)   X-Ref
checkModeKanji

return: boolean true or false
param: $size (int)
param: $data (array)

check($mode, $size, $data)   X-Ref
Validate the input data.

return: boolean true in case of valid data, false otherwise
param: $mode (int) encoding mode.
param: $size (int) size of data (byte).
param: $data (array) data to validate

estimateBitStreamSize($items, $version)   X-Ref
estimateBitStreamSize

return: int bits
param: $items (array)
param: $version (int)

estimateVersion($items)   X-Ref
estimateVersion

return: int version
param: $items (array)

lengthOfCode($mode, $version, $bits)   X-Ref
lengthOfCode

return: int size
param: $mode (int)
param: $version (int)
param: $bits (int)

createBitStream($items)   X-Ref
createBitStream

return: array of items and total bits
param: $items (array)

convertData($items)   X-Ref
convertData

return: array items
param: $items (array)

appendPaddingBit($bstream)   X-Ref
Append Padding Bit to bitstream

return: array bitstream
param: $bstream (array)

mergeBitStream($items)   X-Ref
mergeBitStream

return: array bitstream
param: $items (array) items

getBitStream($items)   X-Ref
Returns a stream of bits.

return: array padded merged byte stream
param: $items (int)

getByteStream($items)   X-Ref
Pack all bit streams padding bits into a byte array.

return: array padded merged byte stream
param: $items (int)

allocate($setLength)   X-Ref
Return an array with zeros

return: array
param: $setLength (int) array size

newFromNum($bits, $num)   X-Ref
Return new bitstream from number

return: array bitstream
param: $bits (int) number of bits
param: $num (int) number

newFromBytes($size, $data)   X-Ref
Return new bitstream from bytes

return: array bitstream
param: $size (int) size
param: $data (array) bytes

appendBitstream($bitstream, $append)   X-Ref
Append one bitstream to another

return: array bitstream
param: $bitstream (array) original bitstream
param: $append (array) bitstream to append

appendNum($bitstream, $bits, $num)   X-Ref
Append one bitstream created from number to another

return: array bitstream
param: $bitstream (array) original bitstream
param: $bits (int) number of bits
param: $num (int) number

appendBytes($bitstream, $size, $data)   X-Ref
Append one bitstream created from bytes to another

return: array bitstream
param: $bitstream (array) original bitstream
param: $size (int) size
param: $data (array) bytes

bitstreamToByte($bstream)   X-Ref
Convert bitstream to bytes

return: array of bytes
param: $bstream (array) original bitstream

qrstrset($srctab, $x, $y, $repl, $replLen=false)   X-Ref
Replace a value on the array at the specified position

return: array srctab
param: $srctab (array)
param: $x (int) X position
param: $y (int) Y position
param: $repl (string) value to replace
param: $replLen (int) length of the repl string

getDataLength($version, $level)   X-Ref
Return maximum data code length (bytes) for the version.

return: int maximum size (bytes)
param: $version (int) version
param: $level (int) error correction level

getECCLength($version, $level)   X-Ref
Return maximum error correction code length (bytes) for the version.

return: int ECC size (bytes)
param: $version (int) version
param: $level (int) error correction level

getWidth($version)   X-Ref
Return the width of the symbol for the version.

return: int width
param: $version (int) version

getRemainder($version)   X-Ref
Return the numer of remainder bits.

return: int number of remainder bits
param: $version (int) version

getMinimumVersion($size, $level)   X-Ref
Return a version number that satisfies the input code length.

return: int version number
param: $size (int) input code length (bytes)
param: $level (int) error correction level

lengthIndicator($mode, $version)   X-Ref
Return the size of length indicator for the mode and version.

return: int the size of the appropriate length indicator (bits).
param: $mode (int) encoding mode
param: $version (int) version

maximumWords($mode, $version)   X-Ref
Return the maximum length for the mode and version.

return: int the maximum length (bytes)
param: $mode (int) encoding mode
param: $version (int) version

getEccSpec($version, $level, $spec)   X-Ref
Return an array of ECC specification.

return: array spec
param: $version (int) version
param: $level (int) error correction level
param: $spec (array) an array of ECC specification contains as following: {# of type1 blocks, # of data code, # of ecc code, # of type2 blocks, # of data code}

putAlignmentMarker($frame, $ox, $oy)   X-Ref
Put an alignment marker.

return: array frame
param: $frame (array) frame
param: $ox (int) X center coordinate of the pattern
param: $oy (int) Y center coordinate of the pattern

putAlignmentPattern($version, $frame, $width)   X-Ref
Put an alignment pattern.

return: array frame
param: $version (int) version
param: $frame (array) frame
param: $width (int) width

getVersionPattern($version)   X-Ref
Return BCH encoded version information pattern that is used for the symbol of version 7 or greater. Use lower 18 bits.

return: BCH encoded version information pattern
param: $version (int) version

getFormatInfo($mask, $level)   X-Ref
Return BCH encoded format information pattern.

return: BCH encoded format information pattern
param: $mask (array)
param: $level (int) error correction level

putFinderPattern($frame, $ox, $oy)   X-Ref
Put a finder pattern.

return: array frame
param: $frame (array) frame
param: $ox (int) X center coordinate of the pattern
param: $oy (int) Y center coordinate of the pattern

createFrame($version)   X-Ref
Return a copy of initialized frame.

return: Array of unsigned char.
param: $version (int) version

newFrame($version)   X-Ref
Set new frame for the specified version.

return: Array of unsigned char.
param: $version (int) version

rsBlockNum($spec)   X-Ref
Return block number 0

return: int value
param: $spec (array)

rsBlockNum1($spec)   X-Ref
Return block number 1

return: int value
param: $spec (array)

rsDataCodes1($spec)   X-Ref
Return data codes 1

return: int value
param: $spec (array)

rsEccCodes1($spec)   X-Ref
Return ecc codes 1

return: int value
param: $spec (array)

rsBlockNum2($spec)   X-Ref
Return block number 2

return: int value
param: $spec (array)

rsDataCodes2($spec)   X-Ref
Return data codes 2

return: int value
param: $spec (array)

rsEccCodes2($spec)   X-Ref
Return ecc codes 2

return: int value
param: $spec (array)

rsDataLength($spec)   X-Ref
Return data length

return: int value
param: $spec (array)

rsEccLength($spec)   X-Ref
Return ecc length

return: int value
param: $spec (array)

init_rs($symsize, $gfpoly, $fcr, $prim, $nroots, $pad)   X-Ref
Initialize a Reed-Solomon codec and add it to existing rsitems

return: array Array of RS values:<ul><li>mm = Bits per symbol;</li><li>nn = Symbols per block;</li><li>alpha_to = log lookup table array;</li><li>index_of = Antilog lookup table array;</li><li>genpoly = Generator polynomial array;</li><li>nroots = Number of generator;</li><li>roots = number of parity symbols;</li><li>fcr = First consecutive root, index form;</li><li>prim = Primitive element, index form;</li><li>iprim = prim-th root of 1, index form;</li><li>pad = Padding bytes in shortened block;</li><li>gfpoly</ul>.
param: $symsize (int) symbol size, bits
param: $gfpoly (int)  Field generator polynomial coefficients
param: $fcr (int)  first root of RS code generator polynomial, index form
param: $prim (int)  primitive element to generate polynomial roots
param: $nroots (int) RS code generator polynomial degree (number of roots)
param: $pad (int)  padding bytes at front of shortened block

modnn($rs, $x)   X-Ref
modnn

return: int X osition
param: $rs (array) RS values
param: $x (int) X position

init_rs_char($symsize, $gfpoly, $fcr, $prim, $nroots, $pad)   X-Ref
Initialize a Reed-Solomon codec and returns an array of values.

return: array Array of RS values:<ul><li>mm = Bits per symbol;</li><li>nn = Symbols per block;</li><li>alpha_to = log lookup table array;</li><li>index_of = Antilog lookup table array;</li><li>genpoly = Generator polynomial array;</li><li>nroots = Number of generator;</li><li>roots = number of parity symbols;</li><li>fcr = First consecutive root, index form;</li><li>prim = Primitive element, index form;</li><li>iprim = prim-th root of 1, index form;</li><li>pad = Padding bytes in shortened block;</li><li>gfpoly</ul>.
param: $symsize (int) symbol size, bits
param: $gfpoly (int)  Field generator polynomial coefficients
param: $fcr (int)  first root of RS code generator polynomial, index form
param: $prim (int)  primitive element to generate polynomial roots
param: $nroots (int) RS code generator polynomial degree (number of roots)
param: $pad (int)  padding bytes at front of shortened block

encode_rs_char($rs, $data, $parity)   X-Ref
Encode a Reed-Solomon codec and returns the parity array

return: parity array
param: $rs (array) RS values
param: $data (array) data
param: $parity (array) parity

Functions that are not part of a class:

str_split($string, $split_length=1)   X-Ref
Convert a string to an array (needed for PHP4 compatibility)

return: If the optional split_length  parameter is specified, the returned array will be broken down into chunks with each being split_length  in length, otherwise each chunk will be one character in length. FALSE is returned if split_length is less than 1. If the split_length length exceeds the length of string , the entire string is returned as the first (and only) array element.
param: $string (string) The input string.
param: $split_length (int) Maximum length of the chunk.