Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 3.9.x will end* 10 May 2021 (12 months).
  • Bug fixes for security issues in 3.9.x will end* 8 May 2023 (36 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

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

(no description)

Author: Nicola Asuni
Version: 1.0.010
File Size: 2867 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

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

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

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

getNextPosition()   X-Ref
Return the next frame position

return: array of x,y coordinates

init($spec)   X-Ref
Initialize code.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

calcN1N3($length)   X-Ref
calcN1N3

param: $length (int)
return: int demerit

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

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

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

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

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

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

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

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

identifyMode($pos)   X-Ref
identifyMode

param: $pos (int)
return: int mode

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

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

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

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

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

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

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

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

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

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

encodeModeStructure($inputitem)   X-Ref
encodeModeStructure

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

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

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

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

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

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

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

calcParity($items)   X-Ref
calcParity

param: $items (array)
return: int parity

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

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

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

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

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

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

estimateBitsModeNum($size)   X-Ref
estimateBitsModeNum

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

estimateBitsModeAn($size)   X-Ref
estimateBitsModeAn

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

estimateBitsMode8($size)   X-Ref
estimateBitsMode8

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

estimateBitsModeKanji($size)   X-Ref
estimateBitsModeKanji

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

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

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

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

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

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

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

estimateVersion($items)   X-Ref
estimateVersion

param: $items (array)
return: int version

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

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

createBitStream($items)   X-Ref
createBitStream

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

convertData($items)   X-Ref
convertData

param: $items (array)
return: array items

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

param: $bstream (array)
return: array bitstream

mergeBitStream($items)   X-Ref
mergeBitStream

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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
return: array srctab

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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}
return: array spec

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

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

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

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

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.

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

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

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

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

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

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

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

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

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

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

param: $spec (array)
return: int value

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

param: $spec (array)
return: int value

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

param: $spec (array)
return: int value

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

param: $spec (array)
return: int value

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

param: $spec (array)
return: int value

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

param: $spec (array)
return: int value

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

param: $spec (array)
return: int value

rsDataLength($spec)   X-Ref
Return data length

param: $spec (array)
return: int value

rsEccLength($spec)   X-Ref
Return ecc length

param: $spec (array)
return: int value

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

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
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>.

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

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

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

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
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>.

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

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

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)

param: $string (string) The input string.
param: $split_length (int) Maximum length of the chunk.
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.