[
  {
    "path": ".gitignore",
    "content": ".idea\n"
  },
  {
    "path": "LICENSE",
    "content": "                  GNU LESSER GENERAL PUBLIC LICENSE\r\n                       Version 3, 29 June 2007\r\n\r\n Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>\r\n Everyone is permitted to copy and distribute verbatim copies\r\n of this license document, but changing it is not allowed.\r\n\r\n\r\n  This version of the GNU Lesser General Public License incorporates\r\nthe terms and conditions of version 3 of the GNU General Public\r\nLicense, supplemented by the additional permissions listed below.\r\n\r\n  0. Additional Definitions.\r\n\r\n  As used herein, \"this License\" refers to version 3 of the GNU Lesser\r\nGeneral Public License, and the \"GNU GPL\" refers to version 3 of the GNU\r\nGeneral Public License.\r\n\r\n  \"The Library\" refers to a covered work governed by this License,\r\nother than an Application or a Combined Work as defined below.\r\n\r\n  An \"Application\" is any work that makes use of an interface provided\r\nby the Library, but which is not otherwise based on the Library.\r\nDefining a subclass of a class defined by the Library is deemed a mode\r\nof using an interface provided by the Library.\r\n\r\n  A \"Combined Work\" is a work produced by combining or linking an\r\nApplication with the Library.  The particular version of the Library\r\nwith which the Combined Work was made is also called the \"Linked\r\nVersion\".\r\n\r\n  The \"Minimal Corresponding Source\" for a Combined Work means the\r\nCorresponding Source for the Combined Work, excluding any source code\r\nfor portions of the Combined Work that, considered in isolation, are\r\nbased on the Application, and not on the Linked Version.\r\n\r\n  The \"Corresponding Application Code\" for a Combined Work means the\r\nobject code and/or source code for the Application, including any data\r\nand utility programs needed for reproducing the Combined Work from the\r\nApplication, but excluding the System Libraries of the Combined Work.\r\n\r\n  1. Exception to Section 3 of the GNU GPL.\r\n\r\n  You may convey a covered work under sections 3 and 4 of this License\r\nwithout being bound by section 3 of the GNU GPL.\r\n\r\n  2. Conveying Modified Versions.\r\n\r\n  If you modify a copy of the Library, and, in your modifications, a\r\nfacility refers to a function or data to be supplied by an Application\r\nthat uses the facility (other than as an argument passed when the\r\nfacility is invoked), then you may convey a copy of the modified\r\nversion:\r\n\r\n   a) under this License, provided that you make a good faith effort to\r\n   ensure that, in the event an Application does not supply the\r\n   function or data, the facility still operates, and performs\r\n   whatever part of its purpose remains meaningful, or\r\n\r\n   b) under the GNU GPL, with none of the additional permissions of\r\n   this License applicable to that copy.\r\n\r\n  3. Object Code Incorporating Material from Library Header Files.\r\n\r\n  The object code form of an Application may incorporate material from\r\na header file that is part of the Library.  You may convey such object\r\ncode under terms of your choice, provided that, if the incorporated\r\nmaterial is not limited to numerical parameters, data structure\r\nlayouts and accessors, or small macros, inline functions and templates\r\n(ten or fewer lines in length), you do both of the following:\r\n\r\n   a) Give prominent notice with each copy of the object code that the\r\n   Library is used in it and that the Library and its use are\r\n   covered by this License.\r\n\r\n   b) Accompany the object code with a copy of the GNU GPL and this license\r\n   document.\r\n\r\n  4. Combined Works.\r\n\r\n  You may convey a Combined Work under terms of your choice that,\r\ntaken together, effectively do not restrict modification of the\r\nportions of the Library contained in the Combined Work and reverse\r\nengineering for debugging such modifications, if you also do each of\r\nthe following:\r\n\r\n   a) Give prominent notice with each copy of the Combined Work that\r\n   the Library is used in it and that the Library and its use are\r\n   covered by this License.\r\n\r\n   b) Accompany the Combined Work with a copy of the GNU GPL and this license\r\n   document.\r\n\r\n   c) For a Combined Work that displays copyright notices during\r\n   execution, include the copyright notice for the Library among\r\n   these notices, as well as a reference directing the user to the\r\n   copies of the GNU GPL and this license document.\r\n\r\n   d) Do one of the following:\r\n\r\n       0) Convey the Minimal Corresponding Source under the terms of this\r\n       License, and the Corresponding Application Code in a form\r\n       suitable for, and under terms that permit, the user to\r\n       recombine or relink the Application with a modified version of\r\n       the Linked Version to produce a modified Combined Work, in the\r\n       manner specified by section 6 of the GNU GPL for conveying\r\n       Corresponding Source.\r\n\r\n       1) Use a suitable shared library mechanism for linking with the\r\n       Library.  A suitable mechanism is one that (a) uses at run time\r\n       a copy of the Library already present on the user's computer\r\n       system, and (b) will operate properly with a modified version\r\n       of the Library that is interface-compatible with the Linked\r\n       Version.\r\n\r\n   e) Provide Installation Information, but only if you would otherwise\r\n   be required to provide such information under section 6 of the\r\n   GNU GPL, and only to the extent that such information is\r\n   necessary to install and execute a modified version of the\r\n   Combined Work produced by recombining or relinking the\r\n   Application with a modified version of the Linked Version. (If\r\n   you use option 4d0, the Installation Information must accompany\r\n   the Minimal Corresponding Source and Corresponding Application\r\n   Code. If you use option 4d1, you must provide the Installation\r\n   Information in the manner specified by section 6 of the GNU GPL\r\n   for conveying Corresponding Source.)\r\n\r\n  5. Combined Libraries.\r\n\r\n  You may place library facilities that are a work based on the\r\nLibrary side by side in a single library together with other library\r\nfacilities that are not Applications and are not covered by this\r\nLicense, and convey such a combined library under terms of your\r\nchoice, if you do both of the following:\r\n\r\n   a) Accompany the combined library with a copy of the same work based\r\n   on the Library, uncombined with any other library facilities,\r\n   conveyed under the terms of this License.\r\n\r\n   b) Give prominent notice with the combined library that part of it\r\n   is a work based on the Library, and explaining where to find the\r\n   accompanying uncombined form of the same work.\r\n\r\n  6. Revised Versions of the GNU Lesser General Public License.\r\n\r\n  The Free Software Foundation may publish revised and/or new versions\r\nof the GNU Lesser General Public License from time to time. Such new\r\nversions will be similar in spirit to the present version, but may\r\ndiffer in detail to address new problems or concerns.\r\n\r\n  Each version is given a distinguishing version number. If the\r\nLibrary as you received it specifies that a certain numbered version\r\nof the GNU Lesser General Public License \"or any later version\"\r\napplies to it, you have the option of following the terms and\r\nconditions either of that published version or of any later version\r\npublished by the Free Software Foundation. If the Library as you\r\nreceived it does not specify a version number of the GNU Lesser\r\nGeneral Public License, you may choose any version of the GNU Lesser\r\nGeneral Public License ever published by the Free Software Foundation.\r\n\r\n  If the Library as you received it specifies that a proxy can decide\r\nwhether future versions of the GNU Lesser General Public License shall\r\napply, that proxy's public statement of acceptance of any version is\r\npermanent authorization for you to choose that version for the\r\nLibrary.\r\n"
  },
  {
    "path": "VERSION",
    "content": "1.1.5\r\n2012021604\r\n"
  },
  {
    "path": "composer.json",
    "content": "{\n    \"name\": \"aferrandini/phpqrcode\",\n    \"description\": \"PHPQRCode porting and changed for PHP 5.3 compatibility\",\n    \"keywords\": [\"php\", \"qrcode\", \"barcode\"],\n    \"homepage\": \"https://github.com/aferrandini/PHPQRCode\",\n    \"type\": \"library\",\n    \"license\": \"MIT\",\n    \"authors\": [\n        {\n            \"name\": \"Ariel Ferrandini\",\n            \"email\": \"arielferrandini@gmail.com\",\n            \"homepage\": \"http://www.ferrandini.com/\"\n        }\n    ],\n    \"require\": {\n        \"php\": \">=5.3.0\"\n    },\n    \"autoload\": {\n        \"psr-0\": { \"PHPQRCode\": \"lib/\" }\n    },\n    \"abandoned\": \"endroid/qr-code\"\n}\n"
  },
  {
    "path": "lib/PHPQRCode/Autoloader.php",
    "content": "<?php\n/**\n * Autoloader\n *\n * Copyright (c) 2006 - 2011 PHPExcel\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\n *\n * @category   PHPQRCode\n * @package    PHPQRCode\n */\n\nnamespace PHPQRCode;\n\nclass Autoloader\n{\n\tpublic static function register()\n    {\n\t\tspl_autoload_register(array(new self, 'autoload'));\n    }\n\n\tpublic static function autoload($class)\n    {\n\t\tif ((class_exists($class)) || (strpos($class, 'PHPQRCode') !== 0)) {\n\t\t\treturn false;\n\t\t}\n\n\t\t$file =\tdirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR\n            . str_replace(array('\\\\', \"\\0\"), array('/', ''), $class).'.php';\n\n\t\tif (is_file($file)) {\n\t\t\trequire $file;\n\t\t}\n    }\n\n}"
  },
  {
    "path": "lib/PHPQRCode/Constants.php",
    "content": "<?php\n/**\n * Constants.php\n *\n * Created by arielferrandini\n */\n\nnamespace PHPQRCode;\n\nclass Constants\n{\n    const QR_CACHEABLE = false;\n    const QR_CACHE_DIR = ''; //dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR;\n    const QR_LOG_DIR   = '/tmp/qrcode_log/';\n\n    const QR_FIND_BEST_MASK = true;\n    const QR_FIND_FROM_RANDOM = false;\n    const QR_DEFAULT_MASK = 2;\n\n    const QR_PNG_MAXIMUM_SIZE =  1024;\n\n    // Encoding modes\n\tconst QR_MODE_NUL = -1;\n\tconst QR_MODE_NUM = 0;\n\tconst QR_MODE_AN = 1;\n\tconst QR_MODE_8 = 2;\n\tconst QR_MODE_KANJI = 3;\n\tconst QR_MODE_STRUCTURE = 4;\n\n\t// Levels of error correction.\n\tconst QR_ECLEVEL_L = 0;\n\tconst QR_ECLEVEL_M = 1;\n\tconst QR_ECLEVEL_Q = 2;\n\tconst QR_ECLEVEL_H = 3;\n\n\t// Supported output formats\n\tconst QR_FORMAT_TEXT = 0;\n\tconst QR_FORMAT_PNG =  1;\n\n    const QR_IMAGE =  true;\n\n    const STRUCTURE_HEADER_BITS =  20;\n    const MAX_STRUCTURED_SYMBOLS = 16;\n\n    // Maks\n    const N1 = 3;\n\tconst N2 = 3;\n\tconst N3 = 40;\n\tconst N4 = 10;\n\n    const QRSPEC_VERSION_MAX = 40;\n    const QRSPEC_WIDTH_MAX =   177;\n\n    const QRCAP_WIDTH =        0;\n    const QRCAP_WORDS =        1;\n    const QRCAP_REMINDER =     2;\n    const QRCAP_EC =           3;\n}\n"
  },
  {
    "path": "lib/PHPQRCode/FrameFiller.php",
    "content": "<?php\n/**\n * FrameFiller.php\n *\n * Created by arielferrandini\n */\n\nnamespace PHPQRCode;\n\nclass FrameFiller {\n\n    public $width;\n    public $frame;\n    public $x;\n    public $y;\n    public $dir;\n    public $bit;\n\n    //----------------------------------------------------------------------\n    public function __construct($width, &$frame)\n    {\n        $this->width = $width;\n        $this->frame = $frame;\n        $this->x = $width - 1;\n        $this->y = $width - 1;\n        $this->dir = -1;\n        $this->bit = -1;\n    }\n\n    //----------------------------------------------------------------------\n    public function setFrameAt($at, $val)\n    {\n        $this->frame[$at['y']][$at['x']] = chr($val);\n    }\n\n    //----------------------------------------------------------------------\n    public function getFrameAt($at)\n    {\n        return ord($this->frame[$at['y']][$at['x']]);\n    }\n\n    //----------------------------------------------------------------------\n    public function next()\n    {\n        do {\n\n            if($this->bit == -1) {\n                $this->bit = 0;\n                return array('x'=>$this->x, 'y'=>$this->y);\n            }\n\n            $x = $this->x;\n            $y = $this->y;\n            $w = $this->width;\n\n            if($this->bit == 0) {\n                $x--;\n                $this->bit++;\n            } else {\n                $x++;\n                $y += $this->dir;\n                $this->bit--;\n            }\n\n            if($this->dir < 0) {\n                if($y < 0) {\n                    $y = 0;\n                    $x -= 2;\n                    $this->dir = 1;\n                    if($x == 6) {\n                        $x--;\n                        $y = 9;\n                    }\n                }\n            } else {\n                if($y == $w) {\n                    $y = $w - 1;\n                    $x -= 2;\n                    $this->dir = -1;\n                    if($x == 6) {\n                        $x--;\n                        $y -= 8;\n                    }\n                }\n            }\n            if($x < 0 || $y < 0) return null;\n\n            $this->x = $x;\n            $this->y = $y;\n\n        } while(ord($this->frame[$y][$x]) & 0x80);\n\n        return array('x'=>$x, 'y'=>$y);\n    }\n\n} ;"
  },
  {
    "path": "lib/PHPQRCode/QRbitstream.php",
    "content": "<?php\r\n/*\r\n * PHP QR Code encoder\r\n *\r\n * Bitstream class\r\n *\r\n * Based on libqrencode C library distributed under LGPL 2.1\r\n * Copyright (C) 2006, 2007, 2008, 2009 Kentaro Fukuchi <fukuchi@megaui.net>\r\n *\r\n * PHP QR Code is distributed under LGPL 3\r\n * Copyright (C) 2010 Dominik Dzienia <deltalab at poczta dot fm>\r\n *\r\n * This library is free software; you can redistribute it and/or\r\n * modify it under the terms of the GNU Lesser General Public\r\n * License as published by the Free Software Foundation; either\r\n * version 3 of the License, or any later version.\r\n *\r\n * This library is distributed in the hope that it will be useful,\r\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\r\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r\n * Lesser General Public License for more details.\r\n *\r\n * You should have received a copy of the GNU Lesser General Public\r\n * License along with this library; if not, write to the Free Software\r\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA\r\n */\r\n\r\nnamespace PHPQRCode;\r\n\r\nclass QRbitstream {\r\n\r\n    public $data = array();\r\n\r\n    //----------------------------------------------------------------------\r\n    public function size()\r\n    {\r\n        return count($this->data);\r\n    }\r\n\r\n    //----------------------------------------------------------------------\r\n    public function allocate($setLength)\r\n    {\r\n        $this->data = array_fill(0, $setLength, 0);\r\n        return 0;\r\n    }\r\n\r\n    //----------------------------------------------------------------------\r\n    public static function newFromNum($bits, $num)\r\n    {\r\n        $bstream = new QRbitstream();\r\n        $bstream->allocate($bits);\r\n\r\n        $mask = 1 << ($bits - 1);\r\n        for($i=0; $i<$bits; $i++) {\r\n            if($num & $mask) {\r\n                $bstream->data[$i] = 1;\r\n            } else {\r\n                $bstream->data[$i] = 0;\r\n            }\r\n            $mask = $mask >> 1;\r\n        }\r\n\r\n        return $bstream;\r\n    }\r\n\r\n    //----------------------------------------------------------------------\r\n    public static function newFromBytes($size, $data)\r\n    {\r\n        $bstream = new QRbitstream();\r\n        $bstream->allocate($size * 8);\r\n        $p=0;\r\n\r\n        for($i=0; $i<$size; $i++) {\r\n            $mask = 0x80;\r\n            for($j=0; $j<8; $j++) {\r\n                if($data[$i] & $mask) {\r\n                    $bstream->data[$p] = 1;\r\n                } else {\r\n                    $bstream->data[$p] = 0;\r\n                }\r\n                $p++;\r\n                $mask = $mask >> 1;\r\n            }\r\n        }\r\n\r\n        return $bstream;\r\n    }\r\n\r\n    //----------------------------------------------------------------------\r\n    public function append(QRbitstream $arg)\r\n    {\r\n        if (is_null($arg)) {\r\n            return -1;\r\n        }\r\n\r\n        if($arg->size() == 0) {\r\n            return 0;\r\n        }\r\n\r\n        if($this->size() == 0) {\r\n            $this->data = $arg->data;\r\n            return 0;\r\n        }\r\n\r\n        $this->data = array_values(array_merge($this->data, $arg->data));\r\n\r\n        return 0;\r\n    }\r\n\r\n    //----------------------------------------------------------------------\r\n    public function appendNum($bits, $num)\r\n    {\r\n        if ($bits == 0)\r\n            return 0;\r\n\r\n        $b = QRbitstream::newFromNum($bits, $num);\r\n\r\n        if(is_null($b))\r\n            return -1;\r\n\r\n        $ret = $this->append($b);\r\n        unset($b);\r\n\r\n        return $ret;\r\n    }\r\n\r\n    //----------------------------------------------------------------------\r\n    public function appendBytes($size, $data)\r\n    {\r\n        if ($size == 0)\r\n            return 0;\r\n\r\n        $b = QRbitstream::newFromBytes($size, $data);\r\n\r\n        if(is_null($b))\r\n            return -1;\r\n\r\n        $ret = $this->append($b);\r\n        unset($b);\r\n\r\n        return $ret;\r\n    }\r\n\r\n    //----------------------------------------------------------------------\r\n    public function toByte()\r\n    {\r\n\r\n        $size = $this->size();\r\n\r\n        if($size == 0) {\r\n            return array();\r\n        }\r\n\r\n        $data = array_fill(0, (int)(($size + 7) / 8), 0);\r\n        $bytes = (int)($size / 8);\r\n\r\n        $p = 0;\r\n\r\n        for($i=0; $i<$bytes; $i++) {\r\n            $v = 0;\r\n            for($j=0; $j<8; $j++) {\r\n                $v = $v << 1;\r\n                $v |= $this->data[$p];\r\n                $p++;\r\n            }\r\n            $data[$i] = $v;\r\n        }\r\n\r\n        if($size & 7) {\r\n            $v = 0;\r\n            for($j=0; $j<($size & 7); $j++) {\r\n                $v = $v << 1;\r\n                $v |= $this->data[$p];\r\n                $p++;\r\n            }\r\n            $data[$bytes] = $v;\r\n        }\r\n\r\n        return $data;\r\n    }\r\n\r\n}"
  },
  {
    "path": "lib/PHPQRCode/QRcode.php",
    "content": "<?php\n/**\n * QRcode.php\n *\n * Created by arielferrandini\n */\n\nnamespace PHPQRCode;\n\nuse Exception;\n\nclass QRcode {\n\n    public $version;\n    public $width;\n    public $data;\n\n    //----------------------------------------------------------------------\n    public function encodeMask(QRinput $input, $mask)\n    {\n        if($input->getVersion() < 0 || $input->getVersion() > Constants::QRSPEC_VERSION_MAX) {\n            throw new Exception('wrong version');\n        }\n        if($input->getErrorCorrectionLevel() > Constants::QR_ECLEVEL_H) {\n            throw new Exception('wrong level');\n        }\n\n        $raw = new QRrawcode($input);\n\n        QRtools::markTime('after_raw');\n\n        $version = $raw->version;\n        $width = QRspec::getWidth($version);\n        $frame = QRspec::newFrame($version);\n\n        $filler = new FrameFiller($width, $frame);\n        if(is_null($filler)) {\n            return NULL;\n        }\n\n        // inteleaved data and ecc codes\n        for($i=0; $i<$raw->dataLength + $raw->eccLength; $i++) {\n            $code = $raw->getCode();\n            $bit = 0x80;\n            for($j=0; $j<8; $j++) {\n                $addr = $filler->next();\n                $filler->setFrameAt($addr, 0x02 | (($bit & $code) != 0));\n                $bit = $bit >> 1;\n            }\n        }\n\n        QRtools::markTime('after_filler');\n\n        unset($raw);\n\n        // remainder bits\n        $j = QRspec::getRemainder($version);\n        for($i=0; $i<$j; $i++) {\n            $addr = $filler->next();\n            $filler->setFrameAt($addr, 0x02);\n        }\n\n        $frame = $filler->frame;\n        unset($filler);\n\n\n        // masking\n        $maskObj = new QRmask();\n        if($mask < 0) {\n\n            if (Constants::QR_FIND_BEST_MASK) {\n                $masked = $maskObj->mask($width, $frame, $input->getErrorCorrectionLevel());\n            } else {\n                $masked = $maskObj->makeMask($width, $frame, (intval(Constants::QR_DEFAULT_MASK) % 8), $input->getErrorCorrectionLevel());\n            }\n        } else {\n            $masked = $maskObj->makeMask($width, $frame, $mask, $input->getErrorCorrectionLevel());\n        }\n\n        if($masked == NULL) {\n            return NULL;\n        }\n\n        QRtools::markTime('after_mask');\n\n        $this->version = $version;\n        $this->width = $width;\n        $this->data = $masked;\n\n        return $this;\n    }\n\n    //----------------------------------------------------------------------\n    public function encodeInput(QRinput $input)\n    {\n        return $this->encodeMask($input, -1);\n    }\n\n    //----------------------------------------------------------------------\n    public function encodeString8bit($string, $version, $level)\n    {\n        if(string == NULL) {\n            throw new Exception('empty string!');\n            return NULL;\n        }\n\n        $input = new QRinput($version, $level);\n        if($input == NULL) return NULL;\n\n        $ret = $input->append($input, Constants::QR_MODE_8, strlen($string), str_split($string));\n        if($ret < 0) {\n            unset($input);\n            return NULL;\n        }\n        return $this->encodeInput($input);\n    }\n\n    //----------------------------------------------------------------------\n    public function encodeString($string, $version, $level, $hint, $casesensitive)\n    {\n\n        if($hint != Constants::QR_MODE_8 && $hint != Constants::QR_MODE_KANJI) {\n            throw new Exception('bad hint');\n            return NULL;\n        }\n\n        $input = new QRinput($version, $level);\n        if($input == NULL) return NULL;\n\n        $ret = QRsplit::splitStringToQRinput($string, $input, $hint, $casesensitive);\n        if($ret < 0) {\n            return NULL;\n        }\n\n        return $this->encodeInput($input);\n    }\n\n    //----------------------------------------------------------------------\n    public static function png($text, $outfile = false, $level = Constants::QR_ECLEVEL_L, $size = 3, $margin = 4, $saveandprint=false)\n    {\n        $enc = QRencode::factory($level, $size, $margin);\n        return $enc->encodePNG($text, $outfile, $saveandprint);\n    }\n\n    //----------------------------------------------------------------------\n    public static function text($text, $outfile = false, $level = Constants::QR_ECLEVEL_L, $size = 3, $margin = 4)\n    {\n        $enc = QRencode::factory($level, $size, $margin);\n        return $enc->encode($text, $outfile);\n    }\n\n    //----------------------------------------------------------------------\n    public static function raw($text, $outfile = false, $level = Constants::QR_ECLEVEL_L, $size = 3, $margin = 4)\n    {\n        $enc = QRencode::factory($level, $size, $margin);\n        return $enc->encodeRAW($text, $outfile);\n    }\n}\n"
  },
  {
    "path": "lib/PHPQRCode/QRencode.php",
    "content": "<?php\r\n/*\r\n * PHP QR Code encoder\r\n *\r\n * Main encoder classes.\r\n *\r\n * Based on libqrencode C library distributed under LGPL 2.1\r\n * Copyright (C) 2006, 2007, 2008, 2009 Kentaro Fukuchi <fukuchi@megaui.net>\r\n *\r\n * PHP QR Code is distributed under LGPL 3\r\n * Copyright (C) 2010 Dominik Dzienia <deltalab at poczta dot fm>\r\n *\r\n * This library is free software; you can redistribute it and/or\r\n * modify it under the terms of the GNU Lesser General Public\r\n * License as published by the Free Software Foundation; either\r\n * version 3 of the License, or any later version.\r\n *\r\n * This library is distributed in the hope that it will be useful,\r\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\r\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r\n * Lesser General Public License for more details.\r\n *\r\n * You should have received a copy of the GNU Lesser General Public\r\n * License along with this library; if not, write to the Free Software\r\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA\r\n */\r\n\r\nnamespace PHPQRCode;\r\n\r\nuse Exception;\r\n\r\nclass QRencode {\r\n\r\n    public $casesensitive = true;\r\n    public $eightbit = false;\r\n\r\n    public $version = 0;\r\n    public $size = 3;\r\n    public $margin = 4;\r\n\r\n    public $structured = 0; // not supported yet\r\n\r\n    public $level = Constants::QR_ECLEVEL_L;\r\n    public $hint = Constants::QR_MODE_8;\r\n\r\n    //----------------------------------------------------------------------\r\n    public static function factory($level = Constants::QR_ECLEVEL_L, $size = 3, $margin = 4)\r\n    {\r\n        $enc = new QRencode();\r\n        $enc->size = $size;\r\n        $enc->margin = $margin;\r\n\r\n        switch ($level.'') {\r\n            case '0':\r\n            case '1':\r\n            case '2':\r\n            case '3':\r\n                    $enc->level = $level;\r\n                break;\r\n            case 'l':\r\n            case 'L':\r\n                    $enc->level = Constants::QR_ECLEVEL_L;\r\n                break;\r\n            case 'm':\r\n            case 'M':\r\n                    $enc->level = Constants::QR_ECLEVEL_M;\r\n                break;\r\n            case 'q':\r\n            case 'Q':\r\n                    $enc->level = Constants::QR_ECLEVEL_Q;\r\n                break;\r\n            case 'h':\r\n            case 'H':\r\n                    $enc->level = Constants::QR_ECLEVEL_H;\r\n                break;\r\n        }\r\n\r\n        return $enc;\r\n    }\r\n\r\n    //----------------------------------------------------------------------\r\n    public function encodeRAW($intext, $outfile = false)\r\n    {\r\n        $code = new QRcode();\r\n\r\n        if($this->eightbit) {\r\n            $code->encodeString8bit($intext, $this->version, $this->level);\r\n        } else {\r\n            $code->encodeString($intext, $this->version, $this->level, $this->hint, $this->casesensitive);\r\n        }\r\n\r\n        return $code->data;\r\n    }\r\n\r\n    //----------------------------------------------------------------------\r\n    public function encode($intext, $outfile = false)\r\n    {\r\n        $code = new QRcode();\r\n\r\n        if($this->eightbit) {\r\n            $code->encodeString8bit($intext, $this->version, $this->level);\r\n        } else {\r\n            $code->encodeString($intext, $this->version, $this->level, $this->hint, $this->casesensitive);\r\n        }\r\n\r\n        QRtools::markTime('after_encode');\r\n\r\n        if ($outfile!== false) {\r\n            file_put_contents($outfile, join(\"\\n\", QRtools::binarize($code->data)));\r\n        } else {\r\n            return QRtools::binarize($code->data);\r\n        }\r\n    }\r\n\r\n    //----------------------------------------------------------------------\r\n    public function encodePNG($intext, $outfile = false,$saveandprint=false)\r\n    {\r\n        try {\r\n            ob_start();\r\n            $tab = $this->encode($intext);\r\n            $err = ob_get_contents();\r\n            ob_end_clean();\r\n\r\n            if ($err != '')\r\n                QRtools::log($outfile, \"ERROR: \" . $err);\r\n\r\n            $maxSize = (int)(Constants::QR_PNG_MAXIMUM_SIZE / (count($tab)+2*$this->margin));\r\n\r\n            QRimage::png($tab, $outfile, min(max(1, $this->size), $maxSize), $this->margin,$saveandprint);\r\n        } catch (Exception $e) {\r\n            echo $e->getMessage();\r\n            die();\r\n\r\n            QRtools::log($outfile, $e->getMessage());\r\n        }\r\n    }\r\n}\r\n"
  },
  {
    "path": "lib/PHPQRCode/QRimage.php",
    "content": "<?php\r\n/*\r\n * PHP QR Code encoder\r\n *\r\n * Image output of code using GD2\r\n *\r\n * PHP QR Code is distributed under LGPL 3\r\n * Copyright (C) 2010 Dominik Dzienia <deltalab at poczta dot fm>\r\n *\r\n * This library is free software; you can redistribute it and/or\r\n * modify it under the terms of the GNU Lesser General Public\r\n * License as published by the Free Software Foundation; either\r\n * version 3 of the License, or any later version.\r\n *\r\n * This library is distributed in the hope that it will be useful,\r\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\r\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r\n * Lesser General Public License for more details.\r\n *\r\n * You should have received a copy of the GNU Lesser General Public\r\n * License along with this library; if not, write to the Free Software\r\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA\r\n */\r\n\r\nnamespace PHPQRCode;\r\n\r\nclass QRimage {\r\n\r\n    //----------------------------------------------------------------------\r\n    public static function png($frame, $filename = false, $pixelPerPoint = 4, $outerFrame = 4,$saveandprint=FALSE)\r\n    {\r\n        $image = self::image($frame, $pixelPerPoint, $outerFrame);\r\n\r\n        if ($filename === false) {\r\n            Header(\"Content-type: image/png\");\r\n            ImagePng($image);\r\n        } else {\r\n            if($saveandprint===TRUE){\r\n                ImagePng($image, $filename);\r\n                header(\"Content-type: image/png\");\r\n                ImagePng($image);\r\n            }else{\r\n                ImagePng($image, $filename);\r\n            }\r\n        }\r\n\r\n        ImageDestroy($image);\r\n    }\r\n\r\n    //----------------------------------------------------------------------\r\n    public static function jpg($frame, $filename = false, $pixelPerPoint = 8, $outerFrame = 4, $q = 85)\r\n    {\r\n        $image = self::image($frame, $pixelPerPoint, $outerFrame);\r\n\r\n        if ($filename === false) {\r\n            Header(\"Content-type: image/jpeg\");\r\n            ImageJpeg($image, null, $q);\r\n        } else {\r\n            ImageJpeg($image, $filename, $q);\r\n        }\r\n\r\n        ImageDestroy($image);\r\n    }\r\n\r\n    //----------------------------------------------------------------------\r\n    public static function image($frame, $pixelPerPoint = 4, $outerFrame = 4)\r\n    {\r\n        $h = count($frame);\r\n        $w = strlen($frame[0]);\r\n\r\n        $imgW = $w + 2*$outerFrame;\r\n        $imgH = $h + 2*$outerFrame;\r\n\r\n        $base_image =ImageCreate($imgW, $imgH);\r\n\r\n        $col[0] = ImageColorAllocate($base_image,255,255,255);\r\n        $col[1] = ImageColorAllocate($base_image,0,0,0);\r\n\r\n        imagefill($base_image, 0, 0, $col[0]);\r\n\r\n        for($y=0; $y<$h; $y++) {\r\n            for($x=0; $x<$w; $x++) {\r\n                if ($frame[$y][$x] == '1') {\r\n                    ImageSetPixel($base_image,$x+$outerFrame,$y+$outerFrame,$col[1]);\r\n                }\r\n            }\r\n        }\r\n\r\n        $target_image =ImageCreate($imgW * $pixelPerPoint, $imgH * $pixelPerPoint);\r\n        ImageCopyResized($target_image, $base_image, 0, 0, 0, 0, $imgW * $pixelPerPoint, $imgH * $pixelPerPoint, $imgW, $imgH);\r\n        ImageDestroy($base_image);\r\n\r\n        return $target_image;\r\n    }\r\n}"
  },
  {
    "path": "lib/PHPQRCode/QRinput.php",
    "content": "<?php\r\n/*\r\n * PHP QR Code encoder\r\n *\r\n * Input encoding class\r\n *\r\n * Based on libqrencode C library distributed under LGPL 2.1\r\n * Copyright (C) 2006, 2007, 2008, 2009 Kentaro Fukuchi <fukuchi@megaui.net>\r\n *\r\n * PHP QR Code is distributed under LGPL 3\r\n * Copyright (C) 2010 Dominik Dzienia <deltalab at poczta dot fm>\r\n *\r\n * This library is free software; you can redistribute it and/or\r\n * modify it under the terms of the GNU Lesser General Public\r\n * License as published by the Free Software Foundation; either\r\n * version 3 of the License, or any later version.\r\n *\r\n * This library is distributed in the hope that it will be useful,\r\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\r\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r\n * Lesser General Public License for more details.\r\n *\r\n * You should have received a copy of the GNU Lesser General Public\r\n * License along with this library; if not, write to the Free Software\r\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA\r\n */\r\n\r\nnamespace PHPQRCode;\r\n\r\nuse Exception;\r\n\r\nclass QRinput {\r\n\r\n    public $items;\r\n\r\n    private $version;\r\n    private $level;\r\n\r\n    //----------------------------------------------------------------------\r\n    public function __construct($version = 0, $level = Constants::QR_ECLEVEL_L)\r\n    {\r\n        if ($version < 0 || $version > Constants::QRSPEC_VERSION_MAX || $level > Constants::QR_ECLEVEL_H) {\r\n            throw new Exception('Invalid version no');\r\n            return NULL;\r\n        }\r\n\r\n        $this->version = $version;\r\n        $this->level = $level;\r\n    }\r\n\r\n    //----------------------------------------------------------------------\r\n    public function getVersion()\r\n    {\r\n        return $this->version;\r\n    }\r\n\r\n    //----------------------------------------------------------------------\r\n    public function setVersion($version)\r\n    {\r\n        if($version < 0 || $version > Constants::QRSPEC_VERSION_MAX) {\r\n            throw new Exception('Invalid version no');\r\n            return -1;\r\n        }\r\n\r\n        $this->version = $version;\r\n\r\n        return 0;\r\n    }\r\n\r\n    //----------------------------------------------------------------------\r\n    public function getErrorCorrectionLevel()\r\n    {\r\n        return $this->level;\r\n    }\r\n\r\n    //----------------------------------------------------------------------\r\n    public function setErrorCorrectionLevel($level)\r\n    {\r\n        if($level > Constants::QR_ECLEVEL_H) {\r\n            throw new Exception('Invalid ECLEVEL');\r\n            return -1;\r\n        }\r\n\r\n        $this->level = $level;\r\n\r\n        return 0;\r\n    }\r\n\r\n    //----------------------------------------------------------------------\r\n    public function appendEntry(QRinputItem $entry)\r\n    {\r\n        $this->items[] = $entry;\r\n    }\r\n\r\n    //----------------------------------------------------------------------\r\n    public function append($mode, $size, $data)\r\n    {\r\n        try {\r\n            $entry = new QRinputItem($mode, $size, $data);\r\n            $this->items[] = $entry;\r\n            return 0;\r\n        } catch (Exception $e) {\r\n            return -1;\r\n        }\r\n    }\r\n\r\n    //----------------------------------------------------------------------\r\n\r\n    public function insertStructuredAppendHeader($size, $index, $parity)\r\n    {\r\n        if( $size > Constants::MAX_STRUCTURED_SYMBOLS ) {\r\n            throw new Exception('insertStructuredAppendHeader wrong size');\r\n        }\r\n\r\n        if( $index <= 0 || $index > Constants::MAX_STRUCTURED_SYMBOLS ) {\r\n            throw new Exception('insertStructuredAppendHeader wrong index');\r\n        }\r\n\r\n        $buf = array($size, $index, $parity);\r\n\r\n        try {\r\n            $entry = new QRinputItem(Constants::QR_MODE_STRUCTURE, 3, buf);\r\n            array_unshift($this->items, $entry);\r\n            return 0;\r\n        } catch (Exception $e) {\r\n            return -1;\r\n        }\r\n    }\r\n\r\n    //----------------------------------------------------------------------\r\n    public function calcParity()\r\n    {\r\n        $parity = 0;\r\n\r\n        foreach($this->items as $item) {\r\n            if($item->mode != Constants::QR_MODE_STRUCTURE) {\r\n                for($i=$item->size-1; $i>=0; $i--) {\r\n                    $parity ^= $item->data[$i];\r\n                }\r\n            }\r\n        }\r\n\r\n        return $parity;\r\n    }\r\n\r\n    //----------------------------------------------------------------------\r\n    public static function checkModeNum($size, $data)\r\n    {\r\n        for($i=0; $i<$size; $i++) {\r\n            if((ord($data[$i]) < ord('0')) || (ord($data[$i]) > ord('9'))){\r\n                return false;\r\n            }\r\n        }\r\n\r\n        return true;\r\n    }\r\n\r\n    //----------------------------------------------------------------------\r\n    public static function estimateBitsModeNum($size)\r\n    {\r\n        $w = (int)$size / 3;\r\n        $bits = $w * 10;\r\n\r\n        switch($size - $w * 3) {\r\n            case 1:\r\n                $bits += 4;\r\n                break;\r\n            case 2:\r\n                $bits += 7;\r\n                break;\r\n            default:\r\n                break;\r\n        }\r\n\r\n        return $bits;\r\n    }\r\n\r\n    //----------------------------------------------------------------------\r\n    public static $anTable = array(\r\n        -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,\r\n        -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,\r\n        36, -1, -1, -1, 37, 38, -1, -1, -1, -1, 39, 40, -1, 41, 42, 43,\r\n         0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 44, -1, -1, -1, -1, -1,\r\n        -1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,\r\n        25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, -1, -1, -1, -1, -1,\r\n        -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,\r\n        -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1\r\n    );\r\n\r\n    //----------------------------------------------------------------------\r\n    public static function lookAnTable($c)\r\n    {\r\n        return (($c > 127)?-1:self::$anTable[$c]);\r\n    }\r\n\r\n    //----------------------------------------------------------------------\r\n    public static function checkModeAn($size, $data)\r\n    {\r\n        for($i=0; $i<$size; $i++) {\r\n            if (self::lookAnTable(ord($data[$i])) == -1) {\r\n                return false;\r\n            }\r\n        }\r\n\r\n        return true;\r\n    }\r\n\r\n    //----------------------------------------------------------------------\r\n    public static function estimateBitsModeAn($size)\r\n    {\r\n        $w = (int)($size / 2);\r\n        $bits = $w * 11;\r\n\r\n        if($size & 1) {\r\n            $bits += 6;\r\n        }\r\n\r\n        return $bits;\r\n    }\r\n\r\n    //----------------------------------------------------------------------\r\n    public static function estimateBitsMode8($size)\r\n    {\r\n        return $size * 8;\r\n    }\r\n\r\n    //----------------------------------------------------------------------\r\n    public function estimateBitsModeKanji($size)\r\n    {\r\n        return (int)(($size / 2) * 13);\r\n    }\r\n\r\n    //----------------------------------------------------------------------\r\n    public static function checkModeKanji($size, $data)\r\n    {\r\n        if($size & 1)\r\n            return false;\r\n\r\n        for($i=0; $i<$size; $i+=2) {\r\n            $val = (ord($data[$i]) << 8) | ord($data[$i+1]);\r\n            if( $val < 0x8140\r\n            || ($val > 0x9ffc && $val < 0xe040)\r\n            || $val > 0xebbf) {\r\n                return false;\r\n            }\r\n        }\r\n\r\n        return true;\r\n    }\r\n\r\n    /***********************************************************************\r\n     * Validation\r\n     **********************************************************************/\r\n\r\n    public static function check($mode, $size, $data)\r\n    {\r\n        if($size <= 0)\r\n            return false;\r\n\r\n        switch($mode) {\r\n            case Constants::QR_MODE_NUM:       return self::checkModeNum($size, $data);   break;\r\n            case Constants::QR_MODE_AN:        return self::checkModeAn($size, $data);    break;\r\n            case Constants::QR_MODE_KANJI:     return self::checkModeKanji($size, $data); break;\r\n            case Constants::QR_MODE_8:         return true; break;\r\n            case Constants::QR_MODE_STRUCTURE: return true; break;\r\n\r\n            default:\r\n                break;\r\n        }\r\n\r\n        return false;\r\n    }\r\n\r\n\r\n    //----------------------------------------------------------------------\r\n    public function estimateBitStreamSize($version)\r\n    {\r\n        $bits = 0;\r\n\r\n        foreach($this->items as $item) {\r\n            $bits += $item->estimateBitStreamSizeOfEntry($version);\r\n        }\r\n\r\n        return $bits;\r\n    }\r\n\r\n    //----------------------------------------------------------------------\r\n    public function estimateVersion()\r\n    {\r\n        $version = 0;\r\n        $prev = 0;\r\n        do {\r\n            $prev = $version;\r\n            $bits = $this->estimateBitStreamSize($prev);\r\n            $version = QRspec::getMinimumVersion((int)(($bits + 7) / 8), $this->level);\r\n            if ($version < 0) {\r\n                return -1;\r\n            }\r\n        } while ($version > $prev);\r\n\r\n        return $version;\r\n    }\r\n\r\n    //----------------------------------------------------------------------\r\n    public static function lengthOfCode($mode, $version, $bits)\r\n    {\r\n        $payload = $bits - 4 - QRspec::lengthIndicator($mode, $version);\r\n        switch($mode) {\r\n            case Constants::QR_MODE_NUM:\r\n                $chunks = (int)($payload / 10);\r\n                $remain = $payload - $chunks * 10;\r\n                $size = $chunks * 3;\r\n                if($remain >= 7) {\r\n                    $size += 2;\r\n                } else if($remain >= 4) {\r\n                    $size += 1;\r\n                }\r\n                break;\r\n            case Constants::QR_MODE_AN:\r\n                $chunks = (int)($payload / 11);\r\n                $remain = $payload - $chunks * 11;\r\n                $size = $chunks * 2;\r\n                if($remain >= 6)\r\n                    $size++;\r\n                break;\r\n            case Constants::QR_MODE_8:\r\n                $size = (int)($payload / 8);\r\n                break;\r\n            case Constants::QR_MODE_KANJI:\r\n                $size = (int)(($payload / 13) * 2);\r\n                break;\r\n            case Constants::QR_MODE_STRUCTURE:\r\n                $size = (int)($payload / 8);\r\n                break;\r\n            default:\r\n                $size = 0;\r\n                break;\r\n        }\r\n\r\n        $maxsize = QRspec::maximumWords($mode, $version);\r\n        if($size < 0) $size = 0;\r\n        if($size > $maxsize) $size = $maxsize;\r\n\r\n        return $size;\r\n    }\r\n\r\n    //----------------------------------------------------------------------\r\n    public function createBitStream()\r\n    {\r\n        $total = 0;\r\n\r\n        foreach($this->items as $item) {\r\n            $bits = $item->encodeBitStream($this->version);\r\n\r\n            if($bits < 0)\r\n                return -1;\r\n\r\n            $total += $bits;\r\n        }\r\n\r\n        return $total;\r\n    }\r\n\r\n    //----------------------------------------------------------------------\r\n    public function convertData()\r\n    {\r\n        $ver = $this->estimateVersion();\r\n        if($ver > $this->getVersion()) {\r\n            $this->setVersion($ver);\r\n        }\r\n\r\n        for(;;) {\r\n            $bits = $this->createBitStream();\r\n\r\n            if($bits < 0)\r\n                return -1;\r\n\r\n            $ver = QRspec::getMinimumVersion((int)(($bits + 7) / 8), $this->level);\r\n            if($ver < 0) {\r\n                throw new Exception('WRONG VERSION');\r\n                return -1;\r\n            } else if($ver > $this->getVersion()) {\r\n                $this->setVersion($ver);\r\n            } else {\r\n                break;\r\n            }\r\n        }\r\n\r\n        return 0;\r\n    }\r\n\r\n    //----------------------------------------------------------------------\r\n    public function appendPaddingBit(&$bstream)\r\n    {\r\n        $bits = $bstream->size();\r\n        $maxwords = QRspec::getDataLength($this->version, $this->level);\r\n        $maxbits = $maxwords * 8;\r\n\r\n        if ($maxbits == $bits) {\r\n            return 0;\r\n        }\r\n\r\n        if ($maxbits - $bits < 5) {\r\n            return $bstream->appendNum($maxbits - $bits, 0);\r\n        }\r\n\r\n        $bits += 4;\r\n        $words = (int)(($bits + 7) / 8);\r\n\r\n        $padding = new QRbitstream();\r\n        $ret = $padding->appendNum($words * 8 - $bits + 4, 0);\r\n\r\n        if($ret < 0)\r\n            return $ret;\r\n\r\n        $padlen = $maxwords - $words;\r\n\r\n        if($padlen > 0) {\r\n\r\n            $padbuf = array();\r\n            for($i=0; $i<$padlen; $i++) {\r\n                $padbuf[$i] = ($i&1)?0x11:0xec;\r\n            }\r\n\r\n            $ret = $padding->appendBytes($padlen, $padbuf);\r\n\r\n            if($ret < 0)\r\n                return $ret;\r\n\r\n        }\r\n\r\n        $ret = $bstream->append($padding);\r\n\r\n        return $ret;\r\n    }\r\n\r\n    //----------------------------------------------------------------------\r\n    public function mergeBitStream()\r\n    {\r\n        if($this->convertData() < 0) {\r\n            return null;\r\n        }\r\n\r\n        $bstream = new QRbitstream();\r\n\r\n        foreach($this->items as $item) {\r\n            $ret = $bstream->append($item->bstream);\r\n            if($ret < 0) {\r\n                return null;\r\n            }\r\n        }\r\n\r\n        return $bstream;\r\n    }\r\n\r\n    //----------------------------------------------------------------------\r\n    public function getBitStream()\r\n    {\r\n\r\n        $bstream = $this->mergeBitStream();\r\n\r\n        if($bstream == null) {\r\n            return null;\r\n        }\r\n\r\n        $ret = $this->appendPaddingBit($bstream);\r\n        if($ret < 0) {\r\n            return null;\r\n        }\r\n\r\n        return $bstream;\r\n    }\r\n\r\n    //----------------------------------------------------------------------\r\n    public function getByteStream()\r\n    {\r\n        $bstream = $this->getBitStream();\r\n        if($bstream == null) {\r\n            return null;\r\n        }\r\n\r\n        return $bstream->toByte();\r\n    }\r\n}\r\n\r\n\r\n"
  },
  {
    "path": "lib/PHPQRCode/QRinputItem.php",
    "content": "<?php\n\nnamespace PHPQRCode;\n\nuse Exception;\n\nclass QRinputItem {\n\n    public $mode;\n    public $size;\n    public $data;\n    public $bstream;\n\n    public function __construct($mode, $size, $data, $bstream = null)\n    {\n        $setData = array_slice($data, 0, $size);\n\n        if (count($setData) < $size) {\n            $setData = array_merge($setData, array_fill(0,$size-count($setData),0));\n        }\n\n        if(!QRinput::check($mode, $size, $setData)) {\n            throw new Exception('Error m:'.$mode.',s:'.$size.',d:'.join(',',$setData));\n            return null;\n        }\n\n        $this->mode = $mode;\n        $this->size = $size;\n        $this->data = $setData;\n        $this->bstream = $bstream;\n    }\n\n    //----------------------------------------------------------------------\n    public function encodeModeNum($version)\n    {\n        try {\n\n            $words = (int)($this->size / 3);\n            $bs = new QRbitstream();\n\n            $val = 0x1;\n            $bs->appendNum(4, $val);\n            $bs->appendNum(QRspec::lengthIndicator(Constants::QR_MODE_NUM, $version), $this->size);\n\n            for($i=0; $i<$words; $i++) {\n                $val  = (ord($this->data[$i*3  ]) - ord('0')) * 100;\n                $val += (ord($this->data[$i*3+1]) - ord('0')) * 10;\n                $val += (ord($this->data[$i*3+2]) - ord('0'));\n                $bs->appendNum(10, $val);\n            }\n\n            if($this->size - $words * 3 == 1) {\n                $val = ord($this->data[$words*3]) - ord('0');\n                $bs->appendNum(4, $val);\n            } else if($this->size - $words * 3 == 2) {\n                $val  = (ord($this->data[$words*3  ]) - ord('0')) * 10;\n                $val += (ord($this->data[$words*3+1]) - ord('0'));\n                $bs->appendNum(7, $val);\n            }\n\n            $this->bstream = $bs;\n            return 0;\n\n        } catch (Exception $e) {\n            return -1;\n        }\n    }\n\n    //----------------------------------------------------------------------\n    public function encodeModeAn($version)\n    {\n        try {\n            $words = (int)($this->size / 2);\n            $bs = new QRbitstream();\n\n            $bs->appendNum(4, 0x02);\n            $bs->appendNum(QRspec::lengthIndicator(Constants::QR_MODE_AN, $version), $this->size);\n\n            for($i=0; $i<$words; $i++) {\n                $val  = (int)QRinput::lookAnTable(ord($this->data[$i*2  ])) * 45;\n                $val += (int)QRinput::lookAnTable(ord($this->data[$i*2+1]));\n\n                $bs->appendNum(11, $val);\n            }\n\n            if($this->size & 1) {\n                $val = QRinput::lookAnTable(ord($this->data[$words * 2]));\n                $bs->appendNum(6, $val);\n            }\n\n            $this->bstream = $bs;\n            return 0;\n\n        } catch (Exception $e) {\n            return -1;\n        }\n    }\n\n    //----------------------------------------------------------------------\n    public function encodeMode8($version)\n    {\n        try {\n            $bs = new QRbitstream();\n\n            $bs->appendNum(4, 0x4);\n            $bs->appendNum(QRspec::lengthIndicator(Constants::QR_MODE_8, $version), $this->size);\n\n            for($i=0; $i<$this->size; $i++) {\n                $bs->appendNum(8, ord($this->data[$i]));\n            }\n\n            $this->bstream = $bs;\n            return 0;\n\n        } catch (Exception $e) {\n            return -1;\n        }\n    }\n\n    //----------------------------------------------------------------------\n    public function encodeModeKanji($version)\n    {\n        try {\n\n            $bs = new QRbitstream();\n\n            $bs->appendNum(4, 0x8);\n            $bs->appendNum(QRspec::lengthIndicator(Constants::QR_MODE_KANJI, $version), (int)($this->size / 2));\n\n            for($i=0; $i<$this->size; $i+=2) {\n                $val = (ord($this->data[$i]) << 8) | ord($this->data[$i+1]);\n                if($val <= 0x9ffc) {\n                    $val -= 0x8140;\n                } else {\n                    $val -= 0xc140;\n                }\n\n                $h = ($val >> 8) * 0xc0;\n                $val = ($val & 0xff) + $h;\n\n                $bs->appendNum(13, $val);\n            }\n\n            $this->bstream = $bs;\n            return 0;\n\n        } catch (Exception $e) {\n            return -1;\n        }\n    }\n\n    //----------------------------------------------------------------------\n    public function encodeModeStructure()\n    {\n        try {\n            $bs =  new QRbitstream();\n\n            $bs->appendNum(4, 0x03);\n            $bs->appendNum(4, ord($this->data[1]) - 1);\n            $bs->appendNum(4, ord($this->data[0]) - 1);\n            $bs->appendNum(8, ord($this->data[2]));\n\n            $this->bstream = $bs;\n            return 0;\n\n        } catch (Exception $e) {\n            return -1;\n        }\n    }\n\n    //----------------------------------------------------------------------\n    public function estimateBitStreamSizeOfEntry($version)\n    {\n        $bits = 0;\n\n        if($version == 0)\n            $version = 1;\n\n        switch($this->mode) {\n            case Constants::QR_MODE_NUM:        $bits = QRinput::estimateBitsModeNum($this->size);    break;\n            case Constants::QR_MODE_AN:        $bits = QRinput::estimateBitsModeAn($this->size);    break;\n            case Constants::QR_MODE_8:            $bits = QRinput::estimateBitsMode8($this->size);    break;\n            case Constants::QR_MODE_KANJI:        $bits = QRinput::estimateBitsModeKanji($this->size);break;\n            case Constants::QR_MODE_STRUCTURE:    return Constants::STRUCTURE_HEADER_BITS;\n            default:\n                return 0;\n        }\n\n        $l = QRspec::lengthIndicator($this->mode, $version);\n        $m = 1 << $l;\n        $num = (int)(($this->size + $m - 1) / $m);\n\n        $bits += $num * (4 + $l);\n\n        return $bits;\n    }\n\n    //----------------------------------------------------------------------\n    public function encodeBitStream($version)\n    {\n        try {\n\n            unset($this->bstream);\n            $words = QRspec::maximumWords($this->mode, $version);\n\n            if($this->size > $words) {\n\n                $st1 = new QRinputItem($this->mode, $words, $this->data);\n                $st2 = new QRinputItem($this->mode, $this->size - $words, array_slice($this->data, $words));\n\n                $st1->encodeBitStream($version);\n                $st2->encodeBitStream($version);\n\n                $this->bstream = new QRbitstream();\n                $this->bstream->append($st1->bstream);\n                $this->bstream->append($st2->bstream);\n\n                unset($st1);\n                unset($st2);\n\n            } else {\n\n                $ret = 0;\n\n                switch($this->mode) {\n                    case Constants::QR_MODE_NUM:        $ret = $this->encodeModeNum($version);    break;\n                    case Constants::QR_MODE_AN:        $ret = $this->encodeModeAn($version);    break;\n                    case Constants::QR_MODE_8:            $ret = $this->encodeMode8($version);    break;\n                    case Constants::QR_MODE_KANJI:        $ret = $this->encodeModeKanji($version);break;\n                    case Constants::QR_MODE_STRUCTURE:    $ret = $this->encodeModeStructure();    break;\n\n                    default:\n                        break;\n                }\n\n                if($ret < 0)\n                    return -1;\n            }\n\n            return $this->bstream->size();\n\n        } catch (Exception $e) {\n            return -1;\n        }\n    }\n}\n"
  },
  {
    "path": "lib/PHPQRCode/QRmask.php",
    "content": "<?php\r\n/*\r\n * PHP QR Code encoder\r\n *\r\n * Masking\r\n *\r\n * Based on libqrencode C library distributed under LGPL 2.1\r\n * Copyright (C) 2006, 2007, 2008, 2009 Kentaro Fukuchi <fukuchi@megaui.net>\r\n *\r\n * PHP QR Code is distributed under LGPL 3\r\n * Copyright (C) 2010 Dominik Dzienia <deltalab at poczta dot fm>\r\n *\r\n * This library is free software; you can redistribute it and/or\r\n * modify it under the terms of the GNU Lesser General Public\r\n * License as published by the Free Software Foundation; either\r\n * version 3 of the License, or any later version.\r\n *\r\n * This library is distributed in the hope that it will be useful,\r\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\r\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r\n * Lesser General Public License for more details.\r\n *\r\n * You should have received a copy of the GNU Lesser General Public\r\n * License along with this library; if not, write to the Free Software\r\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA\r\n */\r\n\r\nnamespace PHPQRCode;\r\n\r\nclass QRmask {\r\n\r\n    public $runLength = array();\r\n\r\n    //----------------------------------------------------------------------\r\n    public function __construct()\r\n    {\r\n        $this->runLength = array_fill(0, Constants::QRSPEC_WIDTH_MAX + 1, 0);\r\n    }\r\n\r\n    //----------------------------------------------------------------------\r\n    public function writeFormatInformation($width, &$frame, $mask, $level)\r\n    {\r\n        $blacks = 0;\r\n        $format =  QRspec::getFormatInfo($mask, $level);\r\n\r\n        for($i=0; $i<8; $i++) {\r\n            if($format & 1) {\r\n                $blacks += 2;\r\n                $v = 0x85;\r\n            } else {\r\n                $v = 0x84;\r\n            }\r\n\r\n            $frame[8][$width - 1 - $i] = chr($v);\r\n            if($i < 6) {\r\n                $frame[$i][8] = chr($v);\r\n            } else {\r\n                $frame[$i + 1][8] = chr($v);\r\n            }\r\n            $format = $format >> 1;\r\n        }\r\n\r\n        for($i=0; $i<7; $i++) {\r\n            if($format & 1) {\r\n                $blacks += 2;\r\n                $v = 0x85;\r\n            } else {\r\n                $v = 0x84;\r\n            }\r\n\r\n            $frame[$width - 7 + $i][8] = chr($v);\r\n            if($i == 0) {\r\n                $frame[8][7] = chr($v);\r\n            } else {\r\n                $frame[8][6 - $i] = chr($v);\r\n            }\r\n\r\n            $format = $format >> 1;\r\n        }\r\n\r\n        return $blacks;\r\n    }\r\n\r\n    //----------------------------------------------------------------------\r\n    public function mask0($x, $y) { return ($x+$y)&1;                       }\r\n    public function mask1($x, $y) { return ($y&1);                          }\r\n    public function mask2($x, $y) { return ($x%3);                          }\r\n    public function mask3($x, $y) { return ($x+$y)%3;                       }\r\n    public function mask4($x, $y) { return (((int)($y/2))+((int)($x/3)))&1; }\r\n    public function mask5($x, $y) { return (($x*$y)&1)+($x*$y)%3;           }\r\n    public function mask6($x, $y) { return ((($x*$y)&1)+($x*$y)%3)&1;       }\r\n    public function mask7($x, $y) { return ((($x*$y)%3)+(($x+$y)&1))&1;     }\r\n\r\n    //----------------------------------------------------------------------\r\n    private function generateMaskNo($maskNo, $width, $frame)\r\n    {\r\n        $bitMask = array_fill(0, $width, array_fill(0, $width, 0));\r\n\r\n        for($y=0; $y<$width; $y++) {\r\n            for($x=0; $x<$width; $x++) {\r\n                if(ord($frame[$y][$x]) & 0x80) {\r\n                    $bitMask[$y][$x] = 0;\r\n                } else {\r\n                    $maskFunc = call_user_func(array($this, 'mask'.$maskNo), $x, $y);\r\n                    $bitMask[$y][$x] = ($maskFunc == 0)?1:0;\r\n                }\r\n\r\n            }\r\n        }\r\n\r\n        return $bitMask;\r\n    }\r\n\r\n    //----------------------------------------------------------------------\r\n    public static function serial($bitFrame)\r\n    {\r\n        $codeArr = array();\r\n\r\n        foreach ($bitFrame as $line)\r\n            $codeArr[] = join('', $line);\r\n\r\n        return gzcompress(join(\"\\n\", $codeArr), 9);\r\n    }\r\n\r\n    //----------------------------------------------------------------------\r\n    public static function unserial($code)\r\n    {\r\n        $codeArr = array();\r\n\r\n        $codeLines = explode(\"\\n\", gzuncompress($code));\r\n        foreach ($codeLines as $line)\r\n            $codeArr[] = str_split($line);\r\n\r\n        return $codeArr;\r\n    }\r\n\r\n    //----------------------------------------------------------------------\r\n    public function makeMaskNo($maskNo, $width, $s, &$d, $maskGenOnly = false)\r\n    {\r\n        $b = 0;\r\n        $bitMask = array();\r\n\r\n        $fileName = Constants::QR_CACHE_DIR.'mask_'.$maskNo.DIRECTORY_SEPARATOR.'mask_'.$width.'_'.$maskNo.'.dat';\r\n\r\n        if (Constants::QR_CACHEABLE) {\r\n            if (file_exists($fileName)) {\r\n                $bitMask = self::unserial(file_get_contents($fileName));\r\n            } else {\r\n                $bitMask = $this->generateMaskNo($maskNo, $width, $s, $d);\r\n                if (!file_exists(Constants::QR_CACHE_DIR.'mask_'.$maskNo))\r\n                    mkdir(Constants::QR_CACHE_DIR.'mask_'.$maskNo);\r\n                file_put_contents($fileName, self::serial($bitMask));\r\n            }\r\n        } else {\r\n            $bitMask = $this->generateMaskNo($maskNo, $width, $s, $d);\r\n        }\r\n\r\n        if ($maskGenOnly)\r\n            return;\r\n\r\n        $d = $s;\r\n\r\n        for($y=0; $y<$width; $y++) {\r\n            for($x=0; $x<$width; $x++) {\r\n                if($bitMask[$y][$x] == 1) {\r\n                    $d[$y][$x] = chr(ord($s[$y][$x]) ^ (int)$bitMask[$y][$x]);\r\n                }\r\n                $b += (int)(ord($d[$y][$x]) & 1);\r\n            }\r\n        }\r\n\r\n        return $b;\r\n    }\r\n\r\n    //----------------------------------------------------------------------\r\n    public function makeMask($width, $frame, $maskNo, $level)\r\n    {\r\n        $masked = array_fill(0, $width, str_repeat(\"\\0\", $width));\r\n        $this->makeMaskNo($maskNo, $width, $frame, $masked);\r\n        $this->writeFormatInformation($width, $masked, $maskNo, $level);\r\n\r\n        return $masked;\r\n    }\r\n\r\n    //----------------------------------------------------------------------\r\n    public function calcN1N3($length)\r\n    {\r\n        $demerit = 0;\r\n\r\n        for($i=0; $i<$length; $i++) {\r\n\r\n            if($this->runLength[$i] >= 5) {\r\n                $demerit += (Constants::N1 + ($this->runLength[$i] - 5));\r\n            }\r\n            if($i & 1) {\r\n                if(($i >= 3) && ($i < ($length-2)) && ($this->runLength[$i] % 3 == 0)) {\r\n                    $fact = (int)($this->runLength[$i] / 3);\r\n                    if(($this->runLength[$i-2] == $fact) &&\r\n                       ($this->runLength[$i-1] == $fact) &&\r\n                       ($this->runLength[$i+1] == $fact) &&\r\n                       ($this->runLength[$i+2] == $fact)) {\r\n                        if(($this->runLength[$i-3] < 0) || ($this->runLength[$i-3] >= (4 * $fact))) {\r\n                            $demerit += Constants::N3;\r\n                        } else if((($i+3) >= $length) || ($this->runLength[$i+3] >= (4 * $fact))) {\r\n                            $demerit += Constants::N3;\r\n                        }\r\n                    }\r\n                }\r\n            }\r\n        }\r\n        return $demerit;\r\n    }\r\n\r\n    //----------------------------------------------------------------------\r\n    public function evaluateSymbol($width, $frame)\r\n    {\r\n        $head = 0;\r\n        $demerit = 0;\r\n\r\n        for($y=0; $y<$width; $y++) {\r\n            $head = 0;\r\n            $this->runLength[0] = 1;\r\n\r\n            $frameY = $frame[$y];\r\n\r\n            if ($y>0)\r\n                $frameYM = $frame[$y-1];\r\n\r\n            for($x=0; $x<$width; $x++) {\r\n                if(($x > 0) && ($y > 0)) {\r\n                    $b22 = ord($frameY[$x]) & ord($frameY[$x-1]) & ord($frameYM[$x]) & ord($frameYM[$x-1]);\r\n                    $w22 = ord($frameY[$x]) | ord($frameY[$x-1]) | ord($frameYM[$x]) | ord($frameYM[$x-1]);\r\n\r\n                    if(($b22 | ($w22 ^ 1))&1) {\r\n                        $demerit += Constants::N2;\r\n                    }\r\n                }\r\n                if(($x == 0) && (ord($frameY[$x]) & 1)) {\r\n                    $this->runLength[0] = -1;\r\n                    $head = 1;\r\n                    $this->runLength[$head] = 1;\r\n                } else if($x > 0) {\r\n                    if((ord($frameY[$x]) ^ ord($frameY[$x-1])) & 1) {\r\n                        $head++;\r\n                        $this->runLength[$head] = 1;\r\n                    } else {\r\n                        $this->runLength[$head]++;\r\n                    }\r\n                }\r\n            }\r\n\r\n            $demerit += $this->calcN1N3($head+1);\r\n        }\r\n\r\n        for($x=0; $x<$width; $x++) {\r\n            $head = 0;\r\n            $this->runLength[0] = 1;\r\n\r\n            for($y=0; $y<$width; $y++) {\r\n                if($y == 0 && (ord($frame[$y][$x]) & 1)) {\r\n                    $this->runLength[0] = -1;\r\n                    $head = 1;\r\n                    $this->runLength[$head] = 1;\r\n                } else if($y > 0) {\r\n                    if((ord($frame[$y][$x]) ^ ord($frame[$y-1][$x])) & 1) {\r\n                        $head++;\r\n                        $this->runLength[$head] = 1;\r\n                    } else {\r\n                        $this->runLength[$head]++;\r\n                    }\r\n                }\r\n            }\r\n\r\n            $demerit += $this->calcN1N3($head+1);\r\n        }\r\n\r\n        return $demerit;\r\n    }\r\n\r\n\r\n    //----------------------------------------------------------------------\r\n    public function mask($width, $frame, $level)\r\n    {\r\n        $minDemerit = PHP_INT_MAX;\r\n        $bestMaskNum = 0;\r\n        $bestMask = array();\r\n\r\n        $checked_masks = array(0,1,2,3,4,5,6,7);\r\n\r\n        if (Constants::QR_FIND_FROM_RANDOM !== false) {\r\n\r\n            $howManuOut = 8-(Constants::QR_FIND_FROM_RANDOM % 9);\r\n            for ($i = 0; $i <  $howManuOut; $i++) {\r\n                $remPos = rand (0, count($checked_masks)-1);\r\n                unset($checked_masks[$remPos]);\r\n                $checked_masks = array_values($checked_masks);\r\n            }\r\n\r\n        }\r\n\r\n        $bestMask = $frame;\r\n\r\n        foreach($checked_masks as $i) {\r\n            $mask = array_fill(0, $width, str_repeat(\"\\0\", $width));\r\n\r\n            $demerit = 0;\r\n            $blacks = 0;\r\n            $blacks  = $this->makeMaskNo($i, $width, $frame, $mask);\r\n            $blacks += $this->writeFormatInformation($width, $mask, $i, $level);\r\n            $blacks  = (int)(100 * $blacks / ($width * $width));\r\n            $demerit = (int)((int)(abs($blacks - 50) / 5) * Constants::N4);\r\n            $demerit += $this->evaluateSymbol($width, $mask);\r\n\r\n            if($demerit < $minDemerit) {\r\n                $minDemerit = $demerit;\r\n                $bestMask = $mask;\r\n                $bestMaskNum = $i;\r\n            }\r\n        }\r\n\r\n        return $bestMask;\r\n    }\r\n\r\n    //----------------------------------------------------------------------\r\n}\r\n"
  },
  {
    "path": "lib/PHPQRCode/QRrawcode.php",
    "content": "<?php\n/**\n * QRrawcode.php\n *\n * Created by arielferrandini\n */\n\nnamespace PHPQRCode;\n\nuse Exception;\n\nclass QRrawcode {\n    public $version;\n    public $datacode = array();\n    public $ecccode = array();\n    public $blocks;\n    public $rsblocks = array(); //of RSblock\n    public $count;\n    public $dataLength;\n    public $eccLength;\n    public $b1;\n\n    //----------------------------------------------------------------------\n    public function __construct(QRinput $input)\n    {\n        $spec = array(0,0,0,0,0);\n\n        $this->datacode = $input->getByteStream();\n        if(is_null($this->datacode)) {\n            throw new Exception('null input string');\n        }\n\n        QRspec::getEccSpec($input->getVersion(), $input->getErrorCorrectionLevel(), $spec);\n\n        $this->version = $input->getVersion();\n        $this->b1 = QRspec::rsBlockNum1($spec);\n        $this->dataLength = QRspec::rsDataLength($spec);\n        $this->eccLength = QRspec::rsEccLength($spec);\n        $this->ecccode = array_fill(0, $this->eccLength, 0);\n        $this->blocks = QRspec::rsBlockNum($spec);\n\n        $ret = $this->init($spec);\n        if($ret < 0) {\n            throw new Exception('block alloc error');\n            return null;\n        }\n\n        $this->count = 0;\n    }\n\n    //----------------------------------------------------------------------\n    public function init(array $spec)\n    {\n        $dl = QRspec::rsDataCodes1($spec);\n        $el = QRspec::rsEccCodes1($spec);\n        $rs = QRrs::init_rs(8, 0x11d, 0, 1, $el, 255 - $dl - $el);\n\n\n        $blockNo = 0;\n        $dataPos = 0;\n        $eccPos = 0;\n        for($i=0; $i<QRspec::rsBlockNum1($spec); $i++) {\n            $ecc = array_slice($this->ecccode,$eccPos);\n            $this->rsblocks[$blockNo] = new QRrsblock($dl, array_slice($this->datacode, $dataPos), $el,  $ecc, $rs);\n            $this->ecccode = array_merge(array_slice($this->ecccode,0, $eccPos), $ecc);\n\n            $dataPos += $dl;\n            $eccPos += $el;\n            $blockNo++;\n        }\n\n        if(QRspec::rsBlockNum2($spec) == 0)\n            return 0;\n\n        $dl = QRspec::rsDataCodes2($spec);\n        $el = QRspec::rsEccCodes2($spec);\n        $rs = QRrs::init_rs(8, 0x11d, 0, 1, $el, 255 - $dl - $el);\n\n        if($rs == NULL) return -1;\n\n        for($i=0; $i<QRspec::rsBlockNum2($spec); $i++) {\n            $ecc = array_slice($this->ecccode,$eccPos);\n            $this->rsblocks[$blockNo] = new QRrsblock($dl, array_slice($this->datacode, $dataPos), $el, $ecc, $rs);\n            $this->ecccode = array_merge(array_slice($this->ecccode,0, $eccPos), $ecc);\n\n            $dataPos += $dl;\n            $eccPos += $el;\n            $blockNo++;\n        }\n\n        return 0;\n    }\n\n    //----------------------------------------------------------------------\n    public function getCode()\n    {\n        $ret = null;\n\n        if($this->count < $this->dataLength) {\n            $row = $this->count % $this->blocks;\n            $col = $this->count / $this->blocks;\n            if($col >= $this->rsblocks[0]->dataLength) {\n                $row += $this->b1;\n            }\n            $ret = $this->rsblocks[$row]->data[$col];\n        } else if($this->count < $this->dataLength + $this->eccLength) {\n            $row = ($this->count - $this->dataLength) % $this->blocks;\n            $col = ($this->count - $this->dataLength) / $this->blocks;\n            $ret = $this->rsblocks[$row]->ecc[$col];\n        } else {\n            return 0;\n        }\n        $this->count++;\n\n        return $ret;\n    }\n}\n"
  },
  {
    "path": "lib/PHPQRCode/QRrs.php",
    "content": "<?php\r\n/*\r\n * PHP QR Code encoder\r\n *\r\n * Reed-Solomon error correction support\r\n * \r\n * Copyright (C) 2002, 2003, 2004, 2006 Phil Karn, KA9Q\r\n * (libfec is released under the GNU Lesser General Public License.)\r\n *\r\n * Based on libqrencode C library distributed under LGPL 2.1\r\n * Copyright (C) 2006, 2007, 2008, 2009 Kentaro Fukuchi <fukuchi@megaui.net>\r\n *\r\n * PHP QR Code is distributed under LGPL 3\r\n * Copyright (C) 2010 Dominik Dzienia <deltalab at poczta dot fm>\r\n *\r\n * This library is free software; you can redistribute it and/or\r\n * modify it under the terms of the GNU Lesser General Public\r\n * License as published by the Free Software Foundation; either\r\n * version 3 of the License, or any later version.\r\n *\r\n * This library is distributed in the hope that it will be useful,\r\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\r\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r\n * Lesser General Public License for more details.\r\n *\r\n * You should have received a copy of the GNU Lesser General Public\r\n * License along with this library; if not, write to the Free Software\r\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA\r\n */\r\n\r\nnamespace PHPQRCode;\r\n\r\nclass QRrs {\r\n\r\n    public static $items = array();\r\n\r\n    //----------------------------------------------------------------------\r\n    public static function init_rs($symsize, $gfpoly, $fcr, $prim, $nroots, $pad)\r\n    {\r\n        foreach(self::$items as $rs) {\r\n            if($rs->pad != $pad)       continue;\r\n            if($rs->nroots != $nroots) continue;\r\n            if($rs->mm != $symsize)    continue;\r\n            if($rs->gfpoly != $gfpoly) continue;\r\n            if($rs->fcr != $fcr)       continue;\r\n            if($rs->prim != $prim)     continue;\r\n\r\n            return $rs;\r\n        }\r\n\r\n        $rs = QRrsItem::init_rs_char($symsize, $gfpoly, $fcr, $prim, $nroots, $pad);\r\n        array_unshift(self::$items, $rs);\r\n\r\n        return $rs;\r\n    }\r\n}"
  },
  {
    "path": "lib/PHPQRCode/QRrsItem.php",
    "content": "<?php\n/**\n * QRrsItem.php\n *\n * Created by arielferrandini\n */\n\nnamespace PHPQRCode;\n\nclass QRrsItem {\n\n    public $mm;                  // Bits per symbol\n    public $nn;                  // Symbols per block (= (1<<mm)-1)\n    public $alpha_to = array();  // log lookup table\n    public $index_of = array();  // Antilog lookup table\n    public $genpoly = array();   // Generator polynomial\n    public $nroots;              // Number of generator roots = number of parity symbols\n    public $fcr;                 // First consecutive root, index form\n    public $prim;                // Primitive element, index form\n    public $iprim;               // prim-th root of 1, index form\n    public $pad;                 // Padding bytes in shortened block\n    public $gfpoly;\n\n    //----------------------------------------------------------------------\n    public function modnn($x)\n    {\n        while ($x >= $this->nn) {\n            $x -= $this->nn;\n            $x = ($x >> $this->mm) + ($x & $this->nn);\n        }\n\n        return $x;\n    }\n\n    //----------------------------------------------------------------------\n    public static function init_rs_char($symsize, $gfpoly, $fcr, $prim, $nroots, $pad)\n    {\n        // Common code for intializing a Reed-Solomon control block (char or int symbols)\n        // Copyright 2004 Phil Karn, KA9Q\n        // May be used under the terms of the GNU Lesser General Public License (LGPL)\n\n        $rs = null;\n\n        // Check parameter ranges\n        if($symsize < 0 || $symsize > 8)                     return $rs;\n        if($fcr < 0 || $fcr >= (1<<$symsize))                return $rs;\n        if($prim <= 0 || $prim >= (1<<$symsize))             return $rs;\n        if($nroots < 0 || $nroots >= (1<<$symsize))          return $rs; // Can't have more roots than symbol values!\n        if($pad < 0 || $pad >= ((1<<$symsize) -1 - $nroots)) return $rs; // Too much padding\n\n        $rs = new QRrsItem();\n        $rs->mm = $symsize;\n        $rs->nn = (1<<$symsize)-1;\n        $rs->pad = $pad;\n\n        $rs->alpha_to = array_fill(0, $rs->nn+1, 0);\n        $rs->index_of = array_fill(0, $rs->nn+1, 0);\n\n        // PHP style macro replacement ;)\n        $NN =& $rs->nn;\n        $A0 =& $NN;\n\n        // Generate Galois field lookup tables\n        $rs->index_of[0] = $A0; // log(zero) = -inf\n        $rs->alpha_to[$A0] = 0; // alpha**-inf = 0\n        $sr = 1;\n\n        for($i=0; $i<$rs->nn; $i++) {\n            $rs->index_of[$sr] = $i;\n            $rs->alpha_to[$i] = $sr;\n            $sr <<= 1;\n            if($sr & (1<<$symsize)) {\n                $sr ^= $gfpoly;\n            }\n            $sr &= $rs->nn;\n        }\n\n        if($sr != 1){\n            // field generator polynomial is not primitive!\n            $rs = NULL;\n            return $rs;\n        }\n\n        /* Form RS code generator polynomial from its roots */\n        $rs->genpoly = array_fill(0, $nroots+1, 0);\n\n        $rs->fcr = $fcr;\n        $rs->prim = $prim;\n        $rs->nroots = $nroots;\n        $rs->gfpoly = $gfpoly;\n\n        /* Find prim-th root of 1, used in decoding */\n        for($iprim=1;($iprim % $prim) != 0;$iprim += $rs->nn)\n        ; // intentional empty-body loop!\n\n        $rs->iprim = (int)($iprim / $prim);\n        $rs->genpoly[0] = 1;\n\n        for ($i = 0,$root=$fcr*$prim; $i < $nroots; $i++, $root += $prim) {\n            $rs->genpoly[$i+1] = 1;\n\n            // Multiply rs->genpoly[] by  @**(root + x)\n            for ($j = $i; $j > 0; $j--) {\n                if ($rs->genpoly[$j] != 0) {\n                    $rs->genpoly[$j] = $rs->genpoly[$j-1] ^ $rs->alpha_to[$rs->modnn($rs->index_of[$rs->genpoly[$j]] + $root)];\n                } else {\n                    $rs->genpoly[$j] = $rs->genpoly[$j-1];\n                }\n            }\n            // rs->genpoly[0] can never be zero\n            $rs->genpoly[0] = $rs->alpha_to[$rs->modnn($rs->index_of[$rs->genpoly[0]] + $root)];\n        }\n\n        // convert rs->genpoly[] to index form for quicker encoding\n        for ($i = 0; $i <= $nroots; $i++)\n            $rs->genpoly[$i] = $rs->index_of[$rs->genpoly[$i]];\n\n        return $rs;\n    }\n\n    //----------------------------------------------------------------------\n    public function encode_rs_char($data, &$parity)\n    {\n        $MM       =& $this->mm;\n        $NN       =& $this->nn;\n        $ALPHA_TO =& $this->alpha_to;\n        $INDEX_OF =& $this->index_of;\n        $GENPOLY  =& $this->genpoly;\n        $NROOTS   =& $this->nroots;\n        $FCR      =& $this->fcr;\n        $PRIM     =& $this->prim;\n        $IPRIM    =& $this->iprim;\n        $PAD      =& $this->pad;\n        $A0       =& $NN;\n\n        $parity = array_fill(0, $NROOTS, 0);\n\n        for($i=0; $i< ($NN-$NROOTS-$PAD); $i++) {\n\n            $feedback = $INDEX_OF[$data[$i] ^ $parity[0]];\n            if($feedback != $A0) {\n                // feedback term is non-zero\n\n                // This line is unnecessary when GENPOLY[NROOTS] is unity, as it must\n                // always be for the polynomials constructed by init_rs()\n                $feedback = $this->modnn($NN - $GENPOLY[$NROOTS] + $feedback);\n\n                for($j=1;$j<$NROOTS;$j++) {\n                    $parity[$j] ^= $ALPHA_TO[$this->modnn($feedback + $GENPOLY[$NROOTS-$j])];\n                }\n            }\n\n            // Shift\n            array_shift($parity);\n            if($feedback != $A0) {\n                array_push($parity, $ALPHA_TO[$this->modnn($feedback + $GENPOLY[0])]);\n            } else {\n                array_push($parity, 0);\n            }\n        }\n    }\n}"
  },
  {
    "path": "lib/PHPQRCode/QRrsblock.php",
    "content": "<?php\n/**\n * QRrsblock.php\n *\n * Created by arielferrandini\n */\n\nnamespace PHPQRCode;\n\nclass QRrsblock {\n    public $dataLength;\n    public $data = array();\n    public $eccLength;\n    public $ecc = array();\n\n    public function __construct($dl, $data, $el, &$ecc, QRrsItem $rs)\n    {\n        $rs->encode_rs_char($data, $ecc);\n\n        $this->dataLength = $dl;\n        $this->data = $data;\n        $this->eccLength = $el;\n        $this->ecc = $ecc;\n    }\n};"
  },
  {
    "path": "lib/PHPQRCode/QRspec.php",
    "content": "<?php\r\n/*\r\n * PHP QR Code encoder\r\n *\r\n * QR Code specifications\r\n *\r\n * Based on libqrencode C library distributed under LGPL 2.1\r\n * Copyright (C) 2006, 2007, 2008, 2009 Kentaro Fukuchi <fukuchi@megaui.net>\r\n *\r\n * PHP QR Code is distributed under LGPL 3\r\n * Copyright (C) 2010 Dominik Dzienia <deltalab at poczta dot fm>\r\n *\r\n * The following data / specifications are taken from\r\n * \"Two dimensional symbol -- QR-code -- Basic Specification\" (JIS X0510:2004)\r\n *  or\r\n * \"Automatic identification and data capture techniques -- \r\n *  QR Code 2005 bar code symbology specification\" (ISO/IEC 18004:2006)\r\n *\r\n * This library is free software; you can redistribute it and/or\r\n * modify it under the terms of the GNU Lesser General Public\r\n * License as published by the Free Software Foundation; either\r\n * version 3 of the License, or any later version.\r\n *\r\n * This library is distributed in the hope that it will be useful,\r\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\r\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r\n * Lesser General Public License for more details.\r\n *\r\n * You should have received a copy of the GNU Lesser General Public\r\n * License along with this library; if not, write to the Free Software\r\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA\r\n */\r\n\r\nnamespace PHPQRCode;\r\n\r\nclass QRspec {\r\n\r\n    public static $capacity = array(\r\n        array(  0,    0, 0, array(   0,    0,    0,    0)),\r\n        array( 21,   26, 0, array(   7,   10,   13,   17)), // 1\r\n        array( 25,   44, 7, array(  10,   16,   22,   28)),\r\n        array( 29,   70, 7, array(  15,   26,   36,   44)),\r\n        array( 33,  100, 7, array(  20,   36,   52,   64)),\r\n        array( 37,  134, 7, array(  26,   48,   72,   88)), // 5\r\n        array( 41,  172, 7, array(  36,   64,   96,  112)),\r\n        array( 45,  196, 0, array(  40,   72,  108,  130)),\r\n        array( 49,  242, 0, array(  48,   88,  132,  156)),\r\n        array( 53,  292, 0, array(  60,  110,  160,  192)),\r\n        array( 57,  346, 0, array(  72,  130,  192,  224)), //10\r\n        array( 61,  404, 0, array(  80,  150,  224,  264)),\r\n        array( 65,  466, 0, array(  96,  176,  260,  308)),\r\n        array( 69,  532, 0, array( 104,  198,  288,  352)),\r\n        array( 73,  581, 3, array( 120,  216,  320,  384)),\r\n        array( 77,  655, 3, array( 132,  240,  360,  432)), //15\r\n        array( 81,  733, 3, array( 144,  280,  408,  480)),\r\n        array( 85,  815, 3, array( 168,  308,  448,  532)),\r\n        array( 89,  901, 3, array( 180,  338,  504,  588)),\r\n        array( 93,  991, 3, array( 196,  364,  546,  650)),\r\n        array( 97, 1085, 3, array( 224,  416,  600,  700)), //20\r\n        array(101, 1156, 4, array( 224,  442,  644,  750)),\r\n        array(105, 1258, 4, array( 252,  476,  690,  816)),\r\n        array(109, 1364, 4, array( 270,  504,  750,  900)),\r\n        array(113, 1474, 4, array( 300,  560,  810,  960)),\r\n        array(117, 1588, 4, array( 312,  588,  870, 1050)), //25\r\n        array(121, 1706, 4, array( 336,  644,  952, 1110)),\r\n        array(125, 1828, 4, array( 360,  700, 1020, 1200)),\r\n        array(129, 1921, 3, array( 390,  728, 1050, 1260)),\r\n        array(133, 2051, 3, array( 420,  784, 1140, 1350)),\r\n        array(137, 2185, 3, array( 450,  812, 1200, 1440)), //30\r\n        array(141, 2323, 3, array( 480,  868, 1290, 1530)),\r\n        array(145, 2465, 3, array( 510,  924, 1350, 1620)),\r\n        array(149, 2611, 3, array( 540,  980, 1440, 1710)),\r\n        array(153, 2761, 3, array( 570, 1036, 1530, 1800)),\r\n        array(157, 2876, 0, array( 570, 1064, 1590, 1890)), //35\r\n        array(161, 3034, 0, array( 600, 1120, 1680, 1980)),\r\n        array(165, 3196, 0, array( 630, 1204, 1770, 2100)),\r\n        array(169, 3362, 0, array( 660, 1260, 1860, 2220)),\r\n        array(173, 3532, 0, array( 720, 1316, 1950, 2310)),\r\n        array(177, 3706, 0, array( 750, 1372, 2040, 2430)) //40\r\n    );\r\n\r\n    //----------------------------------------------------------------------\r\n    public static function getDataLength($version, $level)\r\n    {\r\n        return self::$capacity[$version][Constants::QRCAP_WORDS] - self::$capacity[$version][Constants::QRCAP_EC][$level];\r\n    }\r\n\r\n    //----------------------------------------------------------------------\r\n    public static function getECCLength($version, $level)\r\n    {\r\n        return self::$capacity[$version][Constants::QRCAP_EC][$level];\r\n    }\r\n\r\n    //----------------------------------------------------------------------\r\n    public static function getWidth($version)\r\n    {\r\n        return self::$capacity[$version][Constants::QRCAP_WIDTH];\r\n    }\r\n\r\n    //----------------------------------------------------------------------\r\n    public static function getRemainder($version)\r\n    {\r\n        return self::$capacity[$version][Constants::QRCAP_REMINDER];\r\n    }\r\n\r\n    //----------------------------------------------------------------------\r\n    public static function getMinimumVersion($size, $level)\r\n    {\r\n\r\n        for($i=1; $i<= Constants::QRSPEC_VERSION_MAX; $i++) {\r\n            $words  = self::$capacity[$i][Constants::QRCAP_WORDS] - self::$capacity[$i][Constants::QRCAP_EC][$level];\r\n            if($words >= $size)\r\n                return $i;\r\n        }\r\n\r\n        return -1;\r\n    }\r\n\r\n    //######################################################################\r\n\r\n    public static $lengthTableBits = array(\r\n        array(10, 12, 14),\r\n        array( 9, 11, 13),\r\n        array( 8, 16, 16),\r\n        array( 8, 10, 12)\r\n    );\r\n\r\n    //----------------------------------------------------------------------\r\n    public static function lengthIndicator($mode, $version)\r\n    {\r\n        if ($mode == Constants::QR_MODE_STRUCTURE)\r\n            return 0;\r\n\r\n        if ($version <= 9) {\r\n            $l = 0;\r\n        } else if ($version <= 26) {\r\n            $l = 1;\r\n        } else {\r\n            $l = 2;\r\n        }\r\n\r\n        return self::$lengthTableBits[$mode][$l];\r\n    }\r\n\r\n    //----------------------------------------------------------------------\r\n    public static function maximumWords($mode, $version)\r\n    {\r\n        if($mode == Constants::QR_MODE_STRUCTURE)\r\n            return 3;\r\n\r\n        if($version <= 9) {\r\n            $l = 0;\r\n        } else if($version <= 26) {\r\n            $l = 1;\r\n        } else {\r\n            $l = 2;\r\n        }\r\n\r\n        $bits = self::$lengthTableBits[$mode][$l];\r\n        $words = (1 << $bits) - 1;\r\n\r\n        if($mode == Constants::QR_MODE_KANJI) {\r\n            $words *= 2; // the number of bytes is required\r\n        }\r\n\r\n        return $words;\r\n    }\r\n\r\n    // Error correction code -----------------------------------------------\r\n    // Table of the error correction code (Reed-Solomon block)\r\n    // See Table 12-16 (pp.30-36), JIS X0510:2004.\r\n\r\n    public static $eccTable = array(\r\n        array(array( 0,  0), array( 0,  0), array( 0,  0), array( 0,  0)),\r\n        array(array( 1,  0), array( 1,  0), array( 1,  0), array( 1,  0)), // 1\r\n        array(array( 1,  0), array( 1,  0), array( 1,  0), array( 1,  0)),\r\n        array(array( 1,  0), array( 1,  0), array( 2,  0), array( 2,  0)),\r\n        array(array( 1,  0), array( 2,  0), array( 2,  0), array( 4,  0)),\r\n        array(array( 1,  0), array( 2,  0), array( 2,  2), array( 2,  2)), // 5\r\n        array(array( 2,  0), array( 4,  0), array( 4,  0), array( 4,  0)),\r\n        array(array( 2,  0), array( 4,  0), array( 2,  4), array( 4,  1)),\r\n        array(array( 2,  0), array( 2,  2), array( 4,  2), array( 4,  2)),\r\n        array(array( 2,  0), array( 3,  2), array( 4,  4), array( 4,  4)),\r\n        array(array( 2,  2), array( 4,  1), array( 6,  2), array( 6,  2)), //10\r\n        array(array( 4,  0), array( 1,  4), array( 4,  4), array( 3,  8)),\r\n        array(array( 2,  2), array( 6,  2), array( 4,  6), array( 7,  4)),\r\n        array(array( 4,  0), array( 8,  1), array( 8,  4), array(12,  4)),\r\n        array(array( 3,  1), array( 4,  5), array(11,  5), array(11,  5)),\r\n        array(array( 5,  1), array( 5,  5), array( 5,  7), array(11,  7)), //15\r\n        array(array( 5,  1), array( 7,  3), array(15,  2), array( 3, 13)),\r\n        array(array( 1,  5), array(10,  1), array( 1, 15), array( 2, 17)),\r\n        array(array( 5,  1), array( 9,  4), array(17,  1), array( 2, 19)),\r\n        array(array( 3,  4), array( 3, 11), array(17,  4), array( 9, 16)),\r\n        array(array( 3,  5), array( 3, 13), array(15,  5), array(15, 10)), //20\r\n        array(array( 4,  4), array(17,  0), array(17,  6), array(19,  6)),\r\n        array(array( 2,  7), array(17,  0), array( 7, 16), array(34,  0)),\r\n        array(array( 4,  5), array( 4, 14), array(11, 14), array(16, 14)),\r\n        array(array( 6,  4), array( 6, 14), array(11, 16), array(30,  2)),\r\n        array(array( 8,  4), array( 8, 13), array( 7, 22), array(22, 13)), //25\r\n        array(array(10,  2), array(19,  4), array(28,  6), array(33,  4)),\r\n        array(array( 8,  4), array(22,  3), array( 8, 26), array(12, 28)),\r\n        array(array( 3, 10), array( 3, 23), array( 4, 31), array(11, 31)),\r\n        array(array( 7,  7), array(21,  7), array( 1, 37), array(19, 26)),\r\n        array(array( 5, 10), array(19, 10), array(15, 25), array(23, 25)), //30\r\n        array(array(13,  3), array( 2, 29), array(42,  1), array(23, 28)),\r\n        array(array(17,  0), array(10, 23), array(10, 35), array(19, 35)),\r\n        array(array(17,  1), array(14, 21), array(29, 19), array(11, 46)),\r\n        array(array(13,  6), array(14, 23), array(44,  7), array(59,  1)),\r\n        array(array(12,  7), array(12, 26), array(39, 14), array(22, 41)), //35\r\n        array(array( 6, 14), array( 6, 34), array(46, 10), array( 2, 64)),\r\n        array(array(17,  4), array(29, 14), array(49, 10), array(24, 46)),\r\n        array(array( 4, 18), array(13, 32), array(48, 14), array(42, 32)),\r\n        array(array(20,  4), array(40,  7), array(43, 22), array(10, 67)),\r\n        array(array(19,  6), array(18, 31), array(34, 34), array(20, 61)),//40\r\n    );\r\n\r\n    //----------------------------------------------------------------------\r\n    // CACHEABLE!!!\r\n\r\n    public static function getEccSpec($version, $level, array &$spec)\r\n    {\r\n        if (count($spec) < 5) {\r\n            $spec = array(0,0,0,0,0);\r\n        }\r\n\r\n        $b1   = self::$eccTable[$version][$level][0];\r\n        $b2   = self::$eccTable[$version][$level][1];\r\n        $data = self::getDataLength($version, $level);\r\n        $ecc  = self::getECCLength($version, $level);\r\n\r\n        if($b2 == 0) {\r\n            $spec[0] = $b1;\r\n            $spec[1] = (int)($data / $b1);\r\n            $spec[2] = (int)($ecc / $b1);\r\n            $spec[3] = 0;\r\n            $spec[4] = 0;\r\n        } else {\r\n            $spec[0] = $b1;\r\n            $spec[1] = (int)($data / ($b1 + $b2));\r\n            $spec[2] = (int)($ecc  / ($b1 + $b2));\r\n            $spec[3] = $b2;\r\n            $spec[4] = $spec[1] + 1;\r\n        }\r\n    }\r\n\r\n    // Alignment pattern ---------------------------------------------------\r\n\r\n    // Positions of alignment patterns.\r\n    // This array includes only the second and the third position of the\r\n    // alignment patterns. Rest of them can be calculated from the distance\r\n    // between them.\r\n\r\n    // See Table 1 in Appendix E (pp.71) of JIS X0510:2004.\r\n\r\n    public static $alignmentPattern = array(\r\n        array( 0,  0),\r\n        array( 0,  0), array(18,  0), array(22,  0), array(26,  0), array(30,  0), // 1- 5\r\n        array(34,  0), array(22, 38), array(24, 42), array(26, 46), array(28, 50), // 6-10\r\n        array(30, 54), array(32, 58), array(34, 62), array(26, 46), array(26, 48), //11-15\r\n        array(26, 50), array(30, 54), array(30, 56), array(30, 58), array(34, 62), //16-20\r\n        array(28, 50), array(26, 50), array(30, 54), array(28, 54), array(32, 58), //21-25\r\n        array(30, 58), array(34, 62), array(26, 50), array(30, 54), array(26, 52), //26-30\r\n        array(30, 56), array(34, 60), array(30, 58), array(34, 62), array(30, 54), //31-35\r\n        array(24, 50), array(28, 54), array(32, 58), array(26, 54), array(30, 58), //35-40\r\n    );\r\n\r\n\r\n    /** --------------------------------------------------------------------\r\n     * Put an alignment marker.\r\n     * @param frame\r\n     * @param width\r\n     * @param ox,oy center coordinate of the pattern\r\n     */\r\n    public static function putAlignmentMarker(array &$frame, $ox, $oy)\r\n    {\r\n        $finder = array(\r\n            \"\\xa1\\xa1\\xa1\\xa1\\xa1\",\r\n            \"\\xa1\\xa0\\xa0\\xa0\\xa1\",\r\n            \"\\xa1\\xa0\\xa1\\xa0\\xa1\",\r\n            \"\\xa1\\xa0\\xa0\\xa0\\xa1\",\r\n            \"\\xa1\\xa1\\xa1\\xa1\\xa1\"\r\n        );\r\n\r\n        $yStart = $oy-2;\r\n        $xStart = $ox-2;\r\n\r\n        for($y=0; $y<5; $y++) {\r\n            QRstr::set($frame, $xStart, $yStart+$y, $finder[$y]);\r\n        }\r\n    }\r\n\r\n    //----------------------------------------------------------------------\r\n    public static function putAlignmentPattern($version, &$frame, $width)\r\n    {\r\n        if($version < 2)\r\n            return;\r\n\r\n        $d = self::$alignmentPattern[$version][1] - self::$alignmentPattern[$version][0];\r\n        if($d < 0) {\r\n            $w = 2;\r\n        } else {\r\n            $w = (int)(($width - self::$alignmentPattern[$version][0]) / $d + 2);\r\n        }\r\n\r\n        if($w * $w - 3 == 1) {\r\n            $x = self::$alignmentPattern[$version][0];\r\n            $y = self::$alignmentPattern[$version][0];\r\n            self::putAlignmentMarker($frame, $x, $y);\r\n            return;\r\n        }\r\n\r\n        $cx = self::$alignmentPattern[$version][0];\r\n        for($x=1; $x<$w - 1; $x++) {\r\n            self::putAlignmentMarker($frame, 6, $cx);\r\n            self::putAlignmentMarker($frame, $cx,  6);\r\n            $cx += $d;\r\n        }\r\n\r\n        $cy = self::$alignmentPattern[$version][0];\r\n        for($y=0; $y<$w-1; $y++) {\r\n            $cx = self::$alignmentPattern[$version][0];\r\n            for($x=0; $x<$w-1; $x++) {\r\n                self::putAlignmentMarker($frame, $cx, $cy);\r\n                $cx += $d;\r\n            }\r\n            $cy += $d;\r\n        }\r\n    }\r\n\r\n    // Version information pattern -----------------------------------------\r\n\r\n    // Version information pattern (BCH coded).\r\n    // See Table 1 in Appendix D (pp.68) of JIS X0510:2004.\r\n\r\n    // size: [Constants::QRSPEC_VERSION_MAX - 6]\r\n\r\n    public static $versionPattern = array(\r\n        0x07c94, 0x085bc, 0x09a99, 0x0a4d3, 0x0bbf6, 0x0c762, 0x0d847, 0x0e60d,\r\n        0x0f928, 0x10b78, 0x1145d, 0x12a17, 0x13532, 0x149a6, 0x15683, 0x168c9,\r\n        0x177ec, 0x18ec4, 0x191e1, 0x1afab, 0x1b08e, 0x1cc1a, 0x1d33f, 0x1ed75,\r\n        0x1f250, 0x209d5, 0x216f0, 0x228ba, 0x2379f, 0x24b0b, 0x2542e, 0x26a64,\r\n        0x27541, 0x28c69\r\n    );\r\n\r\n    //----------------------------------------------------------------------\r\n    public static function getVersionPattern($version)\r\n    {\r\n        if($version < 7 || $version > Constants::QRSPEC_VERSION_MAX)\r\n            return 0;\r\n\r\n        return self::$versionPattern[$version -7];\r\n    }\r\n\r\n    // Format information --------------------------------------------------\r\n    // See calcFormatInfo in tests/test_qrspec.c (orginal qrencode c lib)\r\n\r\n    public static $formatInfo = array(\r\n        array(0x77c4, 0x72f3, 0x7daa, 0x789d, 0x662f, 0x6318, 0x6c41, 0x6976),\r\n        array(0x5412, 0x5125, 0x5e7c, 0x5b4b, 0x45f9, 0x40ce, 0x4f97, 0x4aa0),\r\n        array(0x355f, 0x3068, 0x3f31, 0x3a06, 0x24b4, 0x2183, 0x2eda, 0x2bed),\r\n        array(0x1689, 0x13be, 0x1ce7, 0x19d0, 0x0762, 0x0255, 0x0d0c, 0x083b)\r\n    );\r\n\r\n    public static function getFormatInfo($mask, $level)\r\n    {\r\n        if($mask < 0 || $mask > 7)\r\n            return 0;\r\n\r\n        if($level < 0 || $level > 3)\r\n            return 0;\r\n\r\n        return self::$formatInfo[$level][$mask];\r\n    }\r\n\r\n    // Frame ---------------------------------------------------------------\r\n    // Cache of initial frames.\r\n\r\n    public static $frames = array();\r\n\r\n    /** --------------------------------------------------------------------\r\n     * Put a finder pattern.\r\n     * @param frame\r\n     * @param width\r\n     * @param ox,oy upper-left coordinate of the pattern\r\n     */\r\n    public static function putFinderPattern(&$frame, $ox, $oy)\r\n    {\r\n        $finder = array(\r\n            \"\\xc1\\xc1\\xc1\\xc1\\xc1\\xc1\\xc1\",\r\n            \"\\xc1\\xc0\\xc0\\xc0\\xc0\\xc0\\xc1\",\r\n            \"\\xc1\\xc0\\xc1\\xc1\\xc1\\xc0\\xc1\",\r\n            \"\\xc1\\xc0\\xc1\\xc1\\xc1\\xc0\\xc1\",\r\n            \"\\xc1\\xc0\\xc1\\xc1\\xc1\\xc0\\xc1\",\r\n            \"\\xc1\\xc0\\xc0\\xc0\\xc0\\xc0\\xc1\",\r\n            \"\\xc1\\xc1\\xc1\\xc1\\xc1\\xc1\\xc1\"\r\n        );\r\n\r\n        for($y=0; $y<7; $y++) {\r\n            QRstr::set($frame, $ox, $oy+$y, $finder[$y]);\r\n        }\r\n    }\r\n\r\n    //----------------------------------------------------------------------\r\n    public static function createFrame($version)\r\n    {\r\n        $width = self::$capacity[$version][Constants::QRCAP_WIDTH];\r\n        $frameLine = str_repeat (\"\\0\", $width);\r\n        $frame = array_fill(0, $width, $frameLine);\r\n\r\n        // Finder pattern\r\n        self::putFinderPattern($frame, 0, 0);\r\n        self::putFinderPattern($frame, $width - 7, 0);\r\n        self::putFinderPattern($frame, 0, $width - 7);\r\n\r\n        // Separator\r\n        $yOffset = $width - 7;\r\n\r\n        for($y=0; $y<7; $y++) {\r\n            $frame[$y][7] = \"\\xc0\";\r\n            $frame[$y][$width - 8] = \"\\xc0\";\r\n            $frame[$yOffset][7] = \"\\xc0\";\r\n            $yOffset++;\r\n        }\r\n\r\n        $setPattern = str_repeat(\"\\xc0\", 8);\r\n\r\n        QRstr::set($frame, 0, 7, $setPattern);\r\n        QRstr::set($frame, $width-8, 7, $setPattern);\r\n        QRstr::set($frame, 0, $width - 8, $setPattern);\r\n\r\n        // Format info\r\n        $setPattern = str_repeat(\"\\x84\", 9);\r\n        QRstr::set($frame, 0, 8, $setPattern);\r\n        QRstr::set($frame, $width - 8, 8, $setPattern, 8);\r\n\r\n        $yOffset = $width - 8;\r\n\r\n        for($y=0; $y<8; $y++,$yOffset++) {\r\n            $frame[$y][8] = \"\\x84\";\r\n            $frame[$yOffset][8] = \"\\x84\";\r\n        }\r\n\r\n        // Timing pattern\r\n\r\n        for($i=1; $i<$width-15; $i++) {\r\n            $frame[6][7+$i] = chr(0x90 | ($i & 1));\r\n            $frame[7+$i][6] = chr(0x90 | ($i & 1));\r\n        }\r\n\r\n        // Alignment pattern\r\n        self::putAlignmentPattern($version, $frame, $width);\r\n\r\n        // Version information\r\n        if($version >= 7) {\r\n            $vinf = self::getVersionPattern($version);\r\n\r\n            $v = $vinf;\r\n\r\n            for($x=0; $x<6; $x++) {\r\n                for($y=0; $y<3; $y++) {\r\n                    $frame[($width - 11)+$y][$x] = chr(0x88 | ($v & 1));\r\n                    $v = $v >> 1;\r\n                }\r\n            }\r\n\r\n            $v = $vinf;\r\n            for($y=0; $y<6; $y++) {\r\n                for($x=0; $x<3; $x++) {\r\n                    $frame[$y][$x+($width - 11)] = chr(0x88 | ($v & 1));\r\n                    $v = $v >> 1;\r\n                }\r\n            }\r\n        }\r\n\r\n        // and a little bit...\r\n        $frame[$width - 8][8] = \"\\x81\";\r\n\r\n        return $frame;\r\n    }\r\n\r\n    //----------------------------------------------------------------------\r\n    public static function debug($frame, $binary_mode = false)\r\n    {\r\n        if ($binary_mode) {\r\n\r\n                foreach ($frame as &$frameLine) {\r\n                    $frameLine = join('<span class=\"m\">&nbsp;&nbsp;</span>', explode('0', $frameLine));\r\n                    $frameLine = join('&#9608;&#9608;', explode('1', $frameLine));\r\n                }\r\n\r\n                ?>\r\n            <style>\r\n                .m { background-color: white; }\r\n            </style>\r\n            <?php\r\n                echo '<pre><tt><br/ ><br/ ><br/ >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';\r\n                echo join(\"<br/ >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\", $frame);\r\n                echo '</tt></pre><br/ ><br/ ><br/ ><br/ ><br/ ><br/ >';\r\n\r\n        } else {\r\n\r\n            foreach ($frame as &$frameLine) {\r\n                $frameLine = join('<span class=\"m\">&nbsp;</span>',  explode(\"\\xc0\", $frameLine));\r\n                $frameLine = join('<span class=\"m\">&#9618;</span>', explode(\"\\xc1\", $frameLine));\r\n                $frameLine = join('<span class=\"p\">&nbsp;</span>',  explode(\"\\xa0\", $frameLine));\r\n                $frameLine = join('<span class=\"p\">&#9618;</span>', explode(\"\\xa1\", $frameLine));\r\n                $frameLine = join('<span class=\"s\">&#9671;</span>', explode(\"\\x84\", $frameLine)); //format 0\r\n                $frameLine = join('<span class=\"s\">&#9670;</span>', explode(\"\\x85\", $frameLine)); //format 1\r\n                $frameLine = join('<span class=\"x\">&#9762;</span>', explode(\"\\x81\", $frameLine)); //special bit\r\n                $frameLine = join('<span class=\"c\">&nbsp;</span>',  explode(\"\\x90\", $frameLine)); //clock 0\r\n                $frameLine = join('<span class=\"c\">&#9719;</span>', explode(\"\\x91\", $frameLine)); //clock 1\r\n                $frameLine = join('<span class=\"f\">&nbsp;</span>',  explode(\"\\x88\", $frameLine)); //version\r\n                $frameLine = join('<span class=\"f\">&#9618;</span>', explode(\"\\x89\", $frameLine)); //version\r\n                $frameLine = join('&#9830;', explode(\"\\x01\", $frameLine));\r\n                $frameLine = join('&#8901;', explode(\"\\0\", $frameLine));\r\n            }\r\n\r\n            ?>\r\n            <style>\r\n                .p { background-color: yellow; }\r\n                .m { background-color: #00FF00; }\r\n                .s { background-color: #FF0000; }\r\n                .c { background-color: aqua; }\r\n                .x { background-color: pink; }\r\n                .f { background-color: gold; }\r\n            </style>\r\n            <?php\r\n            echo \"<pre><tt>\";\r\n            echo join(\"<br/ >\", $frame);\r\n            echo \"</tt></pre>\";\r\n\r\n        }\r\n    }\r\n\r\n    //----------------------------------------------------------------------\r\n    public static function serial($frame)\r\n    {\r\n        return gzcompress(join(\"\\n\", $frame), 9);\r\n    }\r\n\r\n    //----------------------------------------------------------------------\r\n    public static function unserial($code)\r\n    {\r\n        return explode(\"\\n\", gzuncompress($code));\r\n    }\r\n\r\n    //----------------------------------------------------------------------\r\n    public static function newFrame($version)\r\n    {\r\n        if($version < 1 || $version > Constants::QRSPEC_VERSION_MAX)\r\n            return null;\r\n\r\n        if(!isset(self::$frames[$version])) {\r\n\r\n            $fileName = Constants::QR_CACHE_DIR.'frame_'.$version.'.dat';\r\n\r\n            if (Constants::QR_CACHEABLE) {\r\n                if (file_exists($fileName)) {\r\n                    self::$frames[$version] = self::unserial(file_get_contents($fileName));\r\n                } else {\r\n                    self::$frames[$version] = self::createFrame($version);\r\n                    file_put_contents($fileName, self::serial(self::$frames[$version]));\r\n                }\r\n            } else {\r\n                self::$frames[$version] = self::createFrame($version);\r\n            }\r\n        }\r\n\r\n        if(is_null(self::$frames[$version]))\r\n            return null;\r\n\r\n        return self::$frames[$version];\r\n    }\r\n\r\n    //----------------------------------------------------------------------\r\n    public static function rsBlockNum($spec)     { return $spec[0] + $spec[3]; }\r\n    public static function rsBlockNum1($spec)    { return $spec[0]; }\r\n    public static function rsDataCodes1($spec)   { return $spec[1]; }\r\n    public static function rsEccCodes1($spec)    { return $spec[2]; }\r\n    public static function rsBlockNum2($spec)    { return $spec[3]; }\r\n    public static function rsDataCodes2($spec)   { return $spec[4]; }\r\n    public static function rsEccCodes2($spec)    { return $spec[2]; }\r\n    public static function rsDataLength($spec)   { return ($spec[0] * $spec[1]) + ($spec[3] * $spec[4]);    }\r\n    public static function rsEccLength($spec)    { return ($spec[0] + $spec[3]) * $spec[2]; }\r\n\r\n}"
  },
  {
    "path": "lib/PHPQRCode/QRsplit.php",
    "content": "<?php\r\n/*\r\n * PHP QR Code encoder\r\n *\r\n * Input splitting classes\r\n *\r\n * Based on libqrencode C library distributed under LGPL 2.1\r\n * Copyright (C) 2006, 2007, 2008, 2009 Kentaro Fukuchi <fukuchi@megaui.net>\r\n *\r\n * PHP QR Code is distributed under LGPL 3\r\n * Copyright (C) 2010 Dominik Dzienia <deltalab at poczta dot fm>\r\n *\r\n * The following data / specifications are taken from\r\n * \"Two dimensional symbol -- QR-code -- Basic Specification\" (JIS X0510:2004)\r\n *  or\r\n * \"Automatic identification and data capture techniques --\r\n *  QR Code 2005 bar code symbology specification\" (ISO/IEC 18004:2006)\r\n *\r\n * This library is free software; you can redistribute it and/or\r\n * modify it under the terms of the GNU Lesser General Public\r\n * License as published by the Free Software Foundation; either\r\n * version 3 of the License, or any later version.\r\n *\r\n * This library is distributed in the hope that it will be useful,\r\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\r\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r\n * Lesser General Public License for more details.\r\n *\r\n * You should have received a copy of the GNU Lesser General Public\r\n * License along with this library; if not, write to the Free Software\r\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA\r\n */\r\n\r\nnamespace PHPQRCode;\r\n\r\nuse Exception;\r\n\r\nclass QRsplit {\r\n\r\n    public $dataStr = '';\r\n    public $input;\r\n    public $modeHint;\r\n\r\n    //----------------------------------------------------------------------\r\n    public function __construct($dataStr, $input, $modeHint)\r\n    {\r\n        $this->dataStr  = $dataStr;\r\n        $this->input    = $input;\r\n        $this->modeHint = $modeHint;\r\n    }\r\n\r\n    //----------------------------------------------------------------------\r\n    public static function isdigitat($str, $pos)\r\n    {\r\n        if ($pos >= strlen($str))\r\n            return false;\r\n\r\n        return ((ord($str[$pos]) >= ord('0'))&&(ord($str[$pos]) <= ord('9')));\r\n    }\r\n\r\n    //----------------------------------------------------------------------\r\n    public static function isalnumat($str, $pos)\r\n    {\r\n        if ($pos >= strlen($str))\r\n            return false;\r\n\r\n        return (QRinput::lookAnTable(ord($str[$pos])) >= 0);\r\n    }\r\n\r\n    //----------------------------------------------------------------------\r\n    public function identifyMode($pos)\r\n    {\r\n        if ($pos >= strlen($this->dataStr))\r\n            return Constants::QR_MODE_NUL;\r\n\r\n        $c = $this->dataStr[$pos];\r\n\r\n        if(self::isdigitat($this->dataStr, $pos)) {\r\n            return Constants::QR_MODE_NUM;\r\n        } else if(self::isalnumat($this->dataStr, $pos)) {\r\n            return Constants::QR_MODE_AN;\r\n        } else if($this->modeHint == Constants::QR_MODE_KANJI) {\r\n\r\n            if ($pos+1 < strlen($this->dataStr))\r\n            {\r\n                $d = $this->dataStr[$pos+1];\r\n                $word = (ord($c) << 8) | ord($d);\r\n                if(($word >= 0x8140 && $word <= 0x9ffc) || ($word >= 0xe040 && $word <= 0xebbf)) {\r\n                    return Constants::QR_MODE_KANJI;\r\n                }\r\n            }\r\n        }\r\n\r\n        return Constants::QR_MODE_8;\r\n    }\r\n\r\n    //----------------------------------------------------------------------\r\n    public function eatNum()\r\n    {\r\n        $ln = QRspec::lengthIndicator(Constants::QR_MODE_NUM, $this->input->getVersion());\r\n\r\n        $p = 0;\r\n        while(self::isdigitat($this->dataStr, $p)) {\r\n            $p++;\r\n        }\r\n\r\n        $run = $p;\r\n        $mode = $this->identifyMode($p);\r\n\r\n        if($mode == Constants::QR_MODE_8) {\r\n            $dif = QRinput::estimateBitsModeNum($run) + 4 + $ln\r\n                 + QRinput::estimateBitsMode8(1)         // + 4 + l8\r\n                 - QRinput::estimateBitsMode8($run + 1); // - 4 - l8\r\n            if($dif > 0) {\r\n                return $this->eat8();\r\n            }\r\n        }\r\n        if($mode == Constants::QR_MODE_AN) {\r\n            $dif = QRinput::estimateBitsModeNum($run) + 4 + $ln\r\n                 + QRinput::estimateBitsModeAn(1)        // + 4 + la\r\n                 - QRinput::estimateBitsModeAn($run + 1);// - 4 - la\r\n            if($dif > 0) {\r\n                return $this->eatAn();\r\n            }\r\n        }\r\n\r\n        $ret = $this->input->append(Constants::QR_MODE_NUM, $run, str_split($this->dataStr));\r\n        if($ret < 0)\r\n            return -1;\r\n\r\n        return $run;\r\n    }\r\n\r\n    //----------------------------------------------------------------------\r\n    public function eatAn()\r\n    {\r\n        $la = QRspec::lengthIndicator(Constants::QR_MODE_AN,  $this->input->getVersion());\r\n        $ln = QRspec::lengthIndicator(Constants::QR_MODE_NUM, $this->input->getVersion());\r\n\r\n        $p = 0;\r\n\r\n        while(self::isalnumat($this->dataStr, $p)) {\r\n            if(self::isdigitat($this->dataStr, $p)) {\r\n                $q = $p;\r\n                while(self::isdigitat($this->dataStr, $q)) {\r\n                    $q++;\r\n                }\r\n\r\n                $dif = QRinput::estimateBitsModeAn($p) // + 4 + la\r\n                     + QRinput::estimateBitsModeNum($q - $p) + 4 + $ln\r\n                     - QRinput::estimateBitsModeAn($q); // - 4 - la\r\n\r\n                if($dif < 0) {\r\n                    break;\r\n                } else {\r\n                    $p = $q;\r\n                }\r\n            } else {\r\n                $p++;\r\n            }\r\n        }\r\n\r\n        $run = $p;\r\n\r\n        if(!self::isalnumat($this->dataStr, $p)) {\r\n            $dif = QRinput::estimateBitsModeAn($run) + 4 + $la\r\n                 + QRinput::estimateBitsMode8(1) // + 4 + l8\r\n                 - QRinput::estimateBitsMode8($run + 1); // - 4 - l8\r\n            if($dif > 0) {\r\n                return $this->eat8();\r\n            }\r\n        }\r\n\r\n        $ret = $this->input->append(Constants::QR_MODE_AN, $run, str_split($this->dataStr));\r\n        if($ret < 0)\r\n            return -1;\r\n\r\n        return $run;\r\n    }\r\n\r\n    //----------------------------------------------------------------------\r\n    public function eatKanji()\r\n    {\r\n        $p = 0;\r\n\r\n        while($this->identifyMode($p) == Constants::QR_MODE_KANJI) {\r\n            $p += 2;\r\n        }\r\n\r\n        $ret = $this->input->append(Constants::QR_MODE_KANJI, $p, str_split($this->dataStr));\r\n        if($ret < 0)\r\n            return -1;\r\n\r\n        return $ret;\r\n    }\r\n\r\n    //----------------------------------------------------------------------\r\n    public function eat8()\r\n    {\r\n        $la = QRspec::lengthIndicator(Constants::QR_MODE_AN, $this->input->getVersion());\r\n        $ln = QRspec::lengthIndicator(Constants::QR_MODE_NUM, $this->input->getVersion());\r\n\r\n        $p = 1;\r\n        $dataStrLen = strlen($this->dataStr);\r\n\r\n        while($p < $dataStrLen) {\r\n\r\n            $mode = $this->identifyMode($p);\r\n            if($mode == Constants::QR_MODE_KANJI) {\r\n                break;\r\n            }\r\n            if($mode == Constants::QR_MODE_NUM) {\r\n                $q = $p;\r\n                while(self::isdigitat($this->dataStr, $q)) {\r\n                    $q++;\r\n                }\r\n                $dif = QRinput::estimateBitsMode8($p) // + 4 + l8\r\n                     + QRinput::estimateBitsModeNum($q - $p) + 4 + $ln\r\n                     - QRinput::estimateBitsMode8($q); // - 4 - l8\r\n                if($dif < 0) {\r\n                    break;\r\n                } else {\r\n                    $p = $q;\r\n                }\r\n            } else if($mode == Constants::QR_MODE_AN) {\r\n                $q = $p;\r\n                while(self::isalnumat($this->dataStr, $q)) {\r\n                    $q++;\r\n                }\r\n                $dif = QRinput::estimateBitsMode8($p)  // + 4 + l8\r\n                     + QRinput::estimateBitsModeAn($q - $p) + 4 + $la\r\n                     - QRinput::estimateBitsMode8($q); // - 4 - l8\r\n                if($dif < 0) {\r\n                    break;\r\n                } else {\r\n                    $p = $q;\r\n                }\r\n            } else {\r\n                $p++;\r\n            }\r\n        }\r\n\r\n        $run = $p;\r\n        $ret = $this->input->append(Constants::QR_MODE_8, $run, str_split($this->dataStr));\r\n\r\n        if($ret < 0)\r\n            return -1;\r\n\r\n        return $run;\r\n    }\r\n\r\n    //----------------------------------------------------------------------\r\n    public function splitString()\r\n    {\r\n        while (strlen($this->dataStr) > 0)\r\n        {\r\n            if($this->dataStr == '')\r\n                return 0;\r\n\r\n            $mode = $this->identifyMode(0);\r\n\r\n            switch ($mode) {\r\n                case Constants::QR_MODE_NUM: $length = $this->eatNum(); break;\r\n                case Constants::QR_MODE_AN:  $length = $this->eatAn(); break;\r\n                case Constants::QR_MODE_KANJI:\r\n                    if ($hint == Constants::QR_MODE_KANJI)\r\n                            $length = $this->eatKanji();\r\n                    else    $length = $this->eat8();\r\n                    break;\r\n                default: $length = $this->eat8(); break;\r\n\r\n            }\r\n\r\n            if($length == 0) return 0;\r\n            if($length < 0)  return -1;\r\n\r\n            $this->dataStr = substr($this->dataStr, $length);\r\n        }\r\n    }\r\n\r\n    //----------------------------------------------------------------------\r\n    public function toUpper()\r\n    {\r\n        $stringLen = strlen($this->dataStr);\r\n        $p = 0;\r\n\r\n        while ($p<$stringLen) {\r\n            $mode = self::identifyMode(substr($this->dataStr, $p), $this->modeHint);\r\n            if($mode == Constants::QR_MODE_KANJI) {\r\n                $p += 2;\r\n            } else {\r\n                if (ord($this->dataStr[$p]) >= ord('a') && ord($this->dataStr[$p]) <= ord('z')) {\r\n                    $this->dataStr[$p] = chr(ord($this->dataStr[$p]) - 32);\r\n                }\r\n                $p++;\r\n            }\r\n        }\r\n\r\n        return $this->dataStr;\r\n    }\r\n\r\n    //----------------------------------------------------------------------\r\n    public static function splitStringToQRinput($string, QRinput $input, $modeHint, $casesensitive = true)\r\n    {\r\n        if(is_null($string) || $string == '\\0' || $string == '') {\r\n            throw new Exception('empty string!!!');\r\n        }\r\n\r\n        $split = new QRsplit($string, $input, $modeHint);\r\n\r\n        if(!$casesensitive)\r\n            $split->toUpper();\r\n\r\n        return $split->splitString();\r\n    }\r\n}\r\n"
  },
  {
    "path": "lib/PHPQRCode/QRstr.php",
    "content": "<?php\n\n/*\n * PHP QR Code encoder\n *\n * Common constants\n *\n * Based on libqrencode C library distributed under LGPL 2.1\n * Copyright (C) 2006, 2007, 2008, 2009 Kentaro Fukuchi <fukuchi@megaui.net>\n *\n * PHP QR Code is distributed under LGPL 3\n * Copyright (C) 2010 Dominik Dzienia <deltalab at poczta dot fm>\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 3 of the License, or any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA\n */\n\nnamespace PHPQRCode;\n\nclass QRstr {\n    public static function set(&$srctab, $x, $y, $repl, $replLen = false) {\n        $srctab[$y] = substr_replace($srctab[$y], ($replLen !== false)?substr($repl,0,$replLen):$repl, $x, ($replLen !== false)?$replLen:strlen($repl));\n    }\n}"
  },
  {
    "path": "lib/PHPQRCode/QRtools.php",
    "content": "<?php\r\n/*\r\n * PHP QR Code encoder\r\n *\r\n * Toolset, handy and debug utilites.\r\n *\r\n * PHP QR Code is distributed under LGPL 3\r\n * Copyright (C) 2010 Dominik Dzienia <deltalab at poczta dot fm>\r\n *\r\n * This library is free software; you can redistribute it and/or\r\n * modify it under the terms of the GNU Lesser General Public\r\n * License as published by the Free Software Foundation; either\r\n * version 3 of the License, or any later version.\r\n *\r\n * This library is distributed in the hope that it will be useful,\r\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\r\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r\n * Lesser General Public License for more details.\r\n *\r\n * You should have received a copy of the GNU Lesser General Public\r\n * License along with this library; if not, write to the Free Software\r\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA\r\n */\r\n\r\nnamespace PHPQRCode;\r\n\r\nclass QRtools {\r\n\r\n    //----------------------------------------------------------------------\r\n    public static function binarize($frame)\r\n    {\r\n        $len = count($frame);\r\n        foreach ($frame as &$frameLine) {\r\n\r\n            for($i=0; $i<$len; $i++) {\r\n                $frameLine[$i] = (ord($frameLine[$i])&1)?'1':'0';\r\n            }\r\n        }\r\n\r\n        return $frame;\r\n    }\r\n\r\n    //----------------------------------------------------------------------\r\n    public static function tcpdfBarcodeArray($code, $mode = 'QR,L', $tcPdfVersion = '4.5.037')\r\n    {\r\n        $barcode_array = array();\r\n\r\n        if (!is_array($mode))\r\n            $mode = explode(',', $mode);\r\n\r\n        $eccLevel = 'L';\r\n\r\n        if (count($mode) > 1) {\r\n            $eccLevel = $mode[1];\r\n        }\r\n\r\n        $qrTab = QRcode::text($code, false, $eccLevel);\r\n        $size = count($qrTab);\r\n\r\n        $barcode_array['num_rows'] = $size;\r\n        $barcode_array['num_cols'] = $size;\r\n        $barcode_array['bcode'] = array();\r\n\r\n        foreach ($qrTab as $line) {\r\n            $arrAdd = array();\r\n            foreach(str_split($line) as $char)\r\n                $arrAdd[] = ($char=='1')?1:0;\r\n            $barcode_array['bcode'][] = $arrAdd;\r\n        }\r\n\r\n        return $barcode_array;\r\n    }\r\n\r\n    //----------------------------------------------------------------------\r\n    public static function clearCache()\r\n    {\r\n        self::$frames = array();\r\n    }\r\n\r\n    //----------------------------------------------------------------------\r\n    public static function buildCache()\r\n    {\r\n        QRtools::markTime('before_build_cache');\r\n\r\n        $mask = new QRmask();\r\n        for ($a=1; $a <= Constants::QRSPEC_VERSION_MAX; $a++) {\r\n            $frame = QRspec::newFrame($a);\r\n            if (Constants::QR_IMAGE) {\r\n                $fileName = Constants::QR_CACHE_DIR.'frame_'.$a.'.png';\r\n                QRimage::png(self::binarize($frame), $fileName, 1, 0);\r\n            }\r\n\r\n            $width = count($frame);\r\n            $bitMask = array_fill(0, $width, array_fill(0, $width, 0));\r\n            for ($maskNo=0; $maskNo<8; $maskNo++)\r\n                $mask->makeMaskNo($maskNo, $width, $frame, $bitMask, true);\r\n        }\r\n\r\n        QRtools::markTime('after_build_cache');\r\n    }\r\n\r\n    //----------------------------------------------------------------------\r\n    public static function log($outfile, $err)\r\n    {\r\n        if (Constants::QR_LOG_DIR !== false) {\r\n            if ($err != '') {\r\n                if ($outfile !== false) {\r\n                    file_put_contents(Constants::QR_LOG_DIR.basename($outfile).'-errors.txt', date('Y-m-d H:i:s').': '.$err, FILE_APPEND);\r\n                } else {\r\n                    file_put_contents(Constants::QR_LOG_DIR.'errors.txt', date('Y-m-d H:i:s').': '.$err, FILE_APPEND);\r\n                }\r\n            }\r\n        }\r\n    }\r\n\r\n    //----------------------------------------------------------------------\r\n    public static function dumpMask($frame)\r\n    {\r\n        $width = count($frame);\r\n        for($y=0;$y<$width;$y++) {\r\n            for($x=0;$x<$width;$x++) {\r\n                echo ord($frame[$y][$x]).',';\r\n            }\r\n        }\r\n    }\r\n\r\n    //----------------------------------------------------------------------\r\n    public static function markTime($markerId)\r\n    {\r\n        list($usec, $sec) = explode(\" \", microtime());\r\n        $time = ((float)$usec + (float)$sec);\r\n\r\n        if (!isset($GLOBALS['qr_time_bench']))\r\n            $GLOBALS['qr_time_bench'] = array();\r\n\r\n        $GLOBALS['qr_time_bench'][$markerId] = $time;\r\n    }\r\n\r\n    //----------------------------------------------------------------------\r\n    public static function timeBenchmark()\r\n    {\r\n        self::markTime('finish');\r\n\r\n        $lastTime = 0;\r\n        $startTime = 0;\r\n        $p = 0;\r\n\r\n        echo '<table cellpadding=\"3\" cellspacing=\"1\">\r\n                <thead><tr style=\"border-bottom:1px solid silver\"><td colspan=\"2\" style=\"text-align:center\">BENCHMARK</td></tr></thead>\r\n                <tbody>';\r\n\r\n        foreach($GLOBALS['qr_time_bench'] as $markerId=>$thisTime) {\r\n            if ($p > 0) {\r\n                echo '<tr><th style=\"text-align:right\">till '.$markerId.': </th><td>'.number_format($thisTime-$lastTime, 6).'s</td></tr>';\r\n            } else {\r\n                $startTime = $thisTime;\r\n            }\r\n\r\n            $p++;\r\n            $lastTime = $thisTime;\r\n        }\r\n\r\n        echo '</tbody><tfoot>\r\n            <tr style=\"border-top:2px solid black\"><th style=\"text-align:right\">TOTAL: </th><td>'.number_format($lastTime-$startTime, 6).'s</td></tr>\r\n        </tfoot>\r\n        </table>';\r\n    }\r\n\r\n}\r\n\r\nQRtools::markTime('start');\r\n"
  },
  {
    "path": "lib/PHPQRCode.php",
    "content": "<?php\n/**\n * PHPQRCode.php\n *\n * Created by arielferrandini\n */\n$QR_BASEDIR = dirname(__FILE__).DIRECTORY_SEPARATOR;\n\n// Required libs\n\n/*\n * PHP QR Code encoder\n *\n * Config file, feel free to modify\n */\n\ndefine('QR_CACHEABLE', true);                                                               // use cache - more disk reads but less CPU power, masks and format templates are stored there\ndefine('QR_CACHE_DIR', dirname(__FILE__).DIRECTORY_SEPARATOR.'cache'.DIRECTORY_SEPARATOR);  // used when QR_CACHEABLE === true\ndefine('QR_LOG_DIR', dirname(__FILE__).DIRECTORY_SEPARATOR);                                // default error logs dir\n\ndefine('QR_FIND_BEST_MASK', true);                                                          // if true, estimates best mask (spec. default, but extremally slow; set to false to significant performance boost but (propably) worst quality code\ndefine('QR_FIND_FROM_RANDOM', false);                                                       // if false, checks all masks available, otherwise value tells count of masks need to be checked, mask id are got randomly\ndefine('QR_DEFAULT_MASK', 2);                                                               // when QR_FIND_BEST_MASK === false\n\ndefine('QR_PNG_MAXIMUM_SIZE',  1024);\n\n\n// Supported output formats\n\ndefine('QR_FORMAT_TEXT', 0);\ndefine('QR_FORMAT_PNG',  1);\n\n/** PHPQRCode root directory */\nif (!defined('PHPQRCODE_ROOT')) {\n\tdefine('PHPQRCODE_ROOT', dirname(__FILE__) . '/');\n\trequire(PHPQRCODE_ROOT . 'PHPQRCode/Autoloader.php');\n}\n\nclass PHPQRCode\n{\n\n}\n"
  },
  {
    "path": "readme.md",
    "content": "# This repository is Abandoned!\nPlease see [endroid/qr-code](https://github.com/endroid/qr-code)\n\n\n# PHP QRCode Library\n\nTo install this library please follow the next steps:\n\n## Install the library using `composer`:\n\nAdd the required module to your `composer.json` file:\n\n    {\n        \"require\": {\n            ...\n            \"aferrandini/phpqrcode\": \"1.0.1\"\n            ...\n        }\n    }\n\nThen run the command `composer update`.\n\n\n## Usage\n\nSample code:\n\n    \\PHPQRCode\\QRcode::png(\"Test\", \"/tmp/qrcode.png\", 'L', 4, 2);\n\nThis code will generate a PNG file on '/tmp/qrcode.png' with a QRCode that contains the word 'Test'.\n\n## Acknowledgements\n\nThis library is an import of PHP QR Code by Dominik Dzienia that you can find at http://phpqrcode.sourceforge.net\n\nBased on C libqrencode library (ver. 3.1.1), Copyright (C) 2006-2010 by Kentaro Fukuchi\nhttp://megaui.net/fukuchi/works/qrencode/index.en.html\n\nQR Code is registered trademarks of DENSO WAVE INCORPORATED in JAPAN and other countries.\n\nReed-Solomon code encoder is written by Phil Karn, KA9Q. Copyright (C) 2002, 2003, 2004, 2006 Phil Karn, KA9Q\n"
  }
]