/** * Important! * Make sure the cache directory is writable */ public static function buildCache() { static::markTime('before_build_cache'); $mask = new Mask(); for ($a = 1; $a <= Enum::QRSPEC_VERSION_MAX; $a++) { $frame = Specifications::newFrame($a); $cache_dir = static::getCacheDir(); $fileName = $cache_dir . 'frame_' . $a . '.png'; Image::png(static::binarize($frame), $fileName, 1, 0); $width = count($frame); $bitMask = array_fill(0, $width, array_fill(0, $width, 0)); for ($maskNo = 0; $maskNo < 8; $maskNo++) { $mask->makeMaskNo($maskNo, $width, $frame, $bitMask, true); } } static::markTime('after_build_cache'); }
/** * @param $width * @param $frame * @param $mask * @param $level * * @return int */ public function writeFormatInformation($width, &$frame, $mask, $level) { $blacks = 0; $format = Specifications::getFormatInfo($mask, $level); for ($i = 0; $i < 8; $i++) { if ($format & 1) { $blacks += 2; $v = 0x85; } else { $v = 0x84; } $frame[8][$width - 1 - $i] = chr($v); if ($i < 6) { $frame[$i][8] = chr($v); } else { $frame[$i + 1][8] = chr($v); } $format = $format >> 1; } for ($i = 0; $i < 7; $i++) { if ($format & 1) { $blacks += 2; $v = 0x85; } else { $v = 0x84; } $frame[$width - 7 + $i][8] = chr($v); if ($i == 0) { $frame[8][7] = chr($v); } else { $frame[8][6 - $i] = chr($v); } $format = $format >> 1; } return $blacks; }
/** * @return int */ public function eat8() { $la = Specifications::lengthIndicator(Enum::QR_MODE_AN, $this->input->getVersion()); $ln = Specifications::lengthIndicator(Enum::QR_MODE_NUM, $this->input->getVersion()); $p = 1; $dataStrLen = strlen($this->dataStr); while ($p < $dataStrLen) { $mode = $this->identifyMode($p); if ($mode == Enum::QR_MODE_KANJI) { break; } if ($mode == Enum::QR_MODE_NUM) { $q = $p; while (static::isDigitAt($this->dataStr, $q)) { $q++; } $dif = Input::estimateBitsMode8($p) + Input::estimateBitsModeNum($q - $p) + 4 + $ln - Input::estimateBitsMode8($q); // - 4 - l8 if ($dif < 0) { break; } else { $p = $q; } } else { if ($mode == Enum::QR_MODE_AN) { $q = $p; while (static::isAlNumAt($this->dataStr, $q)) { $q++; } $dif = Input::estimateBitsMode8($p) + Input::estimateBitsModeAn($q - $p) + 4 + $la - Input::estimateBitsMode8($q); // - 4 - l8 if ($dif < 0) { break; } else { $p = $q; } } else { $p++; } } } $run = $p; $ret = $this->input->append(Enum::QR_MODE_8, $run, str_split($this->dataStr)); if ($ret < 0) { return -1; } return $run; }
Loginbox V1.0 Aubrey Kilian <*****@*****.**> Released under the GNU General Public License ---------------------------------------------------------------------------------------*/ $box = new vamTemplate(); $box->assign('tpl_path', 'templates/' . CURRENT_TEMPLATE . '/'); $box_content = ''; require_once DIR_FS_INC . 'vam_get_subcategories.inc.php'; require_once DIR_WS_FUNCTIONS . 'products_specifications.php'; require_once DIR_WS_CLASSES . 'specifications.php'; // костыль для определения минимальной и максимальной цены для фильтра require_once DIR_FS_INC . 'get_price_range.inc.php'; if (isset($current_category_id)) { $minmax_price = get_price_range($current_category_id); } $spec_object = new Specifications(); if (SPECIFICATIONS_FILTERS_BOX == 'True') { $box_text = ''; //HTML string goes into the text part of the box $get_category = ''; if (isset($_GET['cat']) && isset($current_category_id) or FILTERS_MAIN_PAGE == 'False') { $get_category = "and s2c.categories_id = '" . $current_category_id . "'"; } if (!isset($_GET['f1'])) { $except_section = " AND s.specifications_id <> 52"; } $specs_query_raw = "select s.specifications_id,\n s.products_column_name,\n s.filter_class,\n s.filter_show_all,\n s.filter_display,\n sd.specification_name,\n sd.specification_prefix,\n sd.specification_suffix\n from " . TABLE_SPECIFICATION . " s,\n " . TABLE_SPECIFICATION_DESCRIPTION . " sd,\n " . TABLE_SPECIFICATION_GROUPS . " sg,\n " . TABLE_SPECIFICATIONS_TO_CATEGORIES . " s2c\n where s.specification_group_id = sg.specification_group_id\n and sg.specification_group_id = s2c.specification_group_id\n and sd.specifications_id = s.specifications_id\n " . $get_category . "\n and s.show_filter = 'True'\n and sg.show_filter = 'True'\n and sd.language_id = '" . $_SESSION['languages_id'] . "'\n " . $except_section . "\n order by s.specification_sort_order,\n sd.specification_name\n "; // print $specs_query_raw . "<br>\n"; $specs_query = vamDBquery($specs_query_raw); $first = true; while ($specs_array = vam_db_fetch_array($specs_query, true)) {
/** * @param $version * * @return int */ public function encodeBitStream($version) { try { unset($this->bStream); $words = Specifications::maximumWords($this->mode, $version); if ($this->size > $words) { $st1 = new InputItem($this->mode, $words, $this->data); $st2 = new InputItem($this->mode, $this->size - $words, array_slice($this->data, $words)); $st1->encodeBitStream($version); $st2->encodeBitStream($version); $this->bStream = new BitStream(); $this->bStream->append($st1->bStream); $this->bStream->append($st2->bStream); unset($st1); unset($st2); } else { $ret = 0; switch ($this->mode) { case Enum::QR_MODE_NUM: $ret = $this->encodeModeNum($version); break; case Enum::QR_MODE_AN: $ret = $this->encodeModeAn($version); break; case Enum::QR_MODE_8: $ret = $this->encodeMode8($version); break; case Enum::QR_MODE_KANJI: $ret = $this->encodeModeKanji($version); break; case Enum::QR_MODE_STRUCTURE: $ret = $this->encodeModeStructure(); break; default: break; } if ($ret < 0) { return -1; } } } catch (\Exception $e) { return -1; } return $this->bStream->size(); }
/** * @param BitStream $bStream * * @return int */ public function appendPaddingBit(BitStream &$bStream) { $bits = $bStream->size(); $maxWords = Specifications::getDataLength($this->version, $this->level); $maxBits = $maxWords * 8; if ($maxBits == $bits) { return 0; } if ($maxBits - $bits < 5) { return $bStream->appendNum($maxBits - $bits, 0); } $bits += 4; $words = (int) (($bits + 7) / 8); $padding = new BitStream(); $ret = $padding->appendNum($words * 8 - $bits + 4, 0); if ($ret < 0) { return $ret; } $padLen = $maxWords - $words; if ($padLen > 0) { $padBuf = []; for ($i = 0; $i < $padLen; $i++) { $padBuf[$i] = $i & 1 ? 0x11 : 0xec; } $ret = $padding->appendBytes($padLen, $padBuf); if ($ret < 0) { return $ret; } } $ret = $bStream->append($padding); return $ret; }
/** * @param array $spec * * @return int */ public function init(array $spec) { $dl = Specifications::rsDataCodes1($spec); $el = Specifications::rsEccCodes1($spec); $rs = Rs::initRs(8, 0x11d, 0, 1, $el, 255 - $dl - $el); $blockNo = 0; $dataPos = 0; $eccPos = 0; for ($i = 0; $i < Specifications::rsBlockNum1($spec); $i++) { $ecc = array_slice($this->eccCode, $eccPos); $this->rsBlocks[$blockNo] = new Block($dl, array_slice($this->dataCode, $dataPos), $el, $ecc, $rs); $this->eccCode = array_merge(array_slice($this->eccCode, 0, $eccPos), $ecc); $dataPos += $dl; $eccPos += $el; $blockNo++; } if (Specifications::rsBlockNum2($spec) == 0) { return 0; } $dl = Specifications::rsDataCodes2($spec); $el = Specifications::rsEccCodes2($spec); $rs = Rs::initRs(8, 0x11d, 0, 1, $el, 255 - $dl - $el); if ($rs == null) { return -1; } for ($i = 0; $i < Specifications::rsBlockNum2($spec); $i++) { $ecc = array_slice($this->eccCode, $eccPos); $this->rsBlocks[$blockNo] = new Block($dl, array_slice($this->dataCode, $dataPos), $el, $ecc, $rs); $this->eccCode = array_merge(array_slice($this->eccCode, 0, $eccPos), $ecc); $dataPos += $dl; $eccPos += $el; $blockNo++; } return 0; }
/** * @param Input $input * @param $mask * * @return $this|null * @throws \yii\base\InvalidParamException */ public function encodeMask(Input $input, $mask) { if ($input->getVersion() < 0 || $input->getVersion() > Enum::QRSPEC_VERSION_MAX) { throw new InvalidParamException('wrong version'); } if ($input->getErrorCorrectionLevel() > Enum::QR_ECLEVEL_H) { throw new InvalidParamException('wrong level'); } $raw = new RawCode($input); if ($this->benchmark) { Tools::markTime('after_raw'); } $version = $raw->version; $width = Specifications::getWidth($version); $frame = Specifications::newFrame($version); $filler = new FrameFiller($width, $frame); if (is_null($filler)) { return null; } // inteleaved data and ecc codes for ($i = 0; $i < $raw->dataLength + $raw->eccLength; $i++) { $code = $raw->getCode(); $bit = 0x80; for ($j = 0; $j < 8; $j++) { $addr = $filler->next(); $filler->setFrameAt($addr, 0x2 | ($bit & $code) != 0); $bit = $bit >> 1; } } if ($this->benchmark) { Tools::markTime('after_filler'); } unset($raw); // remainder bits $j = Specifications::getRemainder($version); for ($i = 0; $i < $j; $i++) { $addr = $filler->next(); $filler->setFrameAt($addr, 0x2); } $frame = $filler->frame; unset($filler); // masking $maskObj = new Mask(); if ($mask < 0) { if (Enum::QR_FIND_BEST_MASK) { $masked = $maskObj->mask($width, $frame, $input->getErrorCorrectionLevel()); } else { $masked = $maskObj->makeMask($width, $frame, intval(Enum::QR_DEFAULT_MASK) % 8, $input->getErrorCorrectionLevel()); } } else { $masked = $maskObj->makeMask($width, $frame, $mask, $input->getErrorCorrectionLevel()); } if (is_null($masked)) { return null; } if ($this->benchmark) { Tools::markTime('after_mask'); } $this->version = $version; $this->width = $width; $this->data = $masked; return $this; }