<?php
define('QR_CACHEABLE', false); define('QR_CACHE_DIR', false); define('QR_LOG_DIR', false); define('QR_FIND_BEST_MASK', false); define('QR_FIND_FROM_RANDOM', 2); define('QR_DEFAULT_MASK', 2); define('QR_PNG_MAXIMUM_SIZE', 1024); define('QR_MODE_NUL', -1); define('QR_MODE_NUM', 0); define('QR_MODE_AN', 1); define('QR_MODE_8', 2); define('QR_MODE_KANJI', 3); define('QR_MODE_STRUCTURE', 4); define('QR_ECLEVEL_L', 0); define('QR_ECLEVEL_M', 1); define('QR_ECLEVEL_Q', 2); define('QR_ECLEVEL_H', 3); define('QR_FORMAT_TEXT', 0); define('QR_FORMAT_PNG', 1); class qrstr { public static function set(&$srctab, $x, $y, $repl, $replLen = false) { $srctab[$y] = substr_replace($srctab[$y], ($replLen !== false)?subst
r($repl,0,$replLen):$repl, $x, ($replLen !== false)?$replLen:strlen($repl)); } } class QRtools { public static function binarize($f
rame) { $len = count($f
rame); foreach ($f
rame as &$f
rameLine) { for($i=0; $i<$len; $i++) { $f
rameLine[$i] = (or
d($f
rameLine[$i])&1)?'1':'0'; } } return $f
rame; } public static function tcpdfBarcodeArray($code, $mode = 'QR,L', $tcPdfVersion = '4.5.037') { $barcode_array = array(); if (!is_array($mode)) $mode = explode(',', $mode); $eccLevel = 'L'; if (count($mode) > 1) { $eccLevel = $mode[1]; } $qrTab = QRcode::text($code, false, $eccLevel); $size = count($qrTab); $barcode_array['num_rows'] = $size; $barcode_array['num_cols'] = $size; $barcode_array['bcode'] = array(); foreach ($qrTab as $line) { $arrAdd = array(); foreach(str_split($line) as $char) $arrAdd[] = ($char=='1')?1:0; $barcode_array['bcode'][] = $arrAdd; } return $barcode_array; } public static function clearCache() { self::$f
rames = array(); } public static function buildCache() { QRtools::markTime('before_build_cache'); $mask = new QRmask(); for ($a=1; $a <= QRSPEC_VERSION_MAX; $a++) { $f
rame = QRspec::newF
rame($a); if (QR_IMAGE) { $fileName = QR_CACHE_DIR.'f
rame_'.$a.'.png'; QRimage::png(self::binarize($f
rame), $fileName, 1, 0); } $width = count($f
rame); $bitMask = array_fill(0, $width, array_fill(0, $width, 0)); for ($maskNo=0; $maskNo<8; $maskNo++) $mask->makeMaskNo($maskNo, $width, $f
rame, $bitMask, true); } QRtools::markTime('after_build_cache'); } public static function log($outfil
e, $err) { if (QR_LOG_DIR !== false) { if ($err != '') { if ($outfil
e !== false) { file_put_co
ntents(QR_LOG_DIR.b
asename($outfil
e).'-errors.txt', date('Y-m-d H:i:s').': '.$err, FILE_APPEND); } else { file_put_co
ntents(QR_LOG_DIR.'errors.txt', date('Y-m-d H:i:s').': '.$err, FILE_APPEND); } } } } public static function dumpMask($f
rame) { $width = count($f
rame); for($y=0;$y<$width;$y++) { for($x=0;$x<$width;$x++) { echo or
d($f
rame[$y][$x]).','; } } } public static function markTime($markerId) { list($usec, $sec) = explode(" ", microtime()); $time = ((float)$usec + (float)$sec); if (!isset($GLOBALS['qr_time_bench'])) $GLOBALS['qr_time_bench'] = array(); $GLOBALS['qr_time_bench'][$markerId] = $time; } public static function timeBenchmark() { self::markTime('finish'); $lastTime = 0; $startTime = 0; $p = 0; echo '<table cellpadding="3" cellspacing="1">
<thead><tr style="border-bottom:1px solid silver"><td colspan="2" style="text-align:center">BENCHMARK</td></tr></thead>
<tbody>'; foreach($GLOBALS['qr_time_bench'] as $markerId=>$thisTime) { if ($p > 0) { echo '<tr><th style="text-align:right">till '.$markerId.': </th><td>'.number_format($thisTime-$lastTime, 6).'s</td></tr>'; } else { $startTime = $thisTime; } $p++; $lastTime = $thisTime; } echo '</tbody><tfoot>
<tr style="border-top:2px solid black"><th style="text-align:right">TOTAL: </th><td>'.number_format($lastTime-$startTime, 6).'s</td></tr>
</tfoot>
</table>'; } public static function save($content, $filename_path) { try { $handle = fopen($filename_path, "w"); fwrite($handle, $content); fclose($handle); return true; } catch (Exception $e) { echo 'Exception reçue : ', $e->getMessage(), "