Index: trunk/extensions/MultilingualLiquidThreads/LiquidThreads/classes/View.php |
— | — | @@ -936,7 +936,6 @@ |
937 | 937 | $error = $ot->moveTo( $nt, true, "Changed thread subject: $reason" ); |
938 | 938 | if ( $error !== true ) { |
939 | 939 | throw new MWException( "Got error $error trying to move pages." ); |
940 | | - return false; |
941 | 940 | } |
942 | 941 | |
943 | 942 | # Move the talk page if relevant, if it exists, and if we've been told to |
Index: trunk/extensions/MultilingualLiquidThreads/LiquidThreads/pages/SpecialNewMessages.php |
— | — | @@ -2,7 +2,7 @@ |
3 | 3 | if ( !defined( 'MEDIAWIKI' ) ) die; |
4 | 4 | |
5 | 5 | class SpecialNewMessages extends SpecialPage { |
6 | | - private $user, $output, $request, $title; |
| 6 | + private $user, $output, $request; |
7 | 7 | |
8 | 8 | function __construct() { |
9 | 9 | parent::__construct( 'NewMessages' ); |
— | — | @@ -13,13 +13,11 @@ |
14 | 14 | * @see SpecialPage::getDescription |
15 | 15 | */ |
16 | 16 | function getDescription() { |
17 | | - wfLoadExtensionMessages( 'LiquidThreads' ); |
18 | 17 | return wfMsg( 'lqt_newmessages-title' ); |
19 | 18 | } |
20 | 19 | |
21 | 20 | function execute( $par ) { |
22 | 21 | global $wgOut, $wgRequest, $wgUser; |
23 | | - wfLoadExtensionMessages( 'LiquidThreads' ); |
24 | 22 | $this->user = $wgUser; |
25 | 23 | $this->output = $wgOut; |
26 | 24 | $this->request = $wgRequest; |
Index: trunk/extensions/ExternalData/ED_Utils.php |
— | — | @@ -455,8 +455,6 @@ |
456 | 456 | return false; |
457 | 457 | } |
458 | 458 | } |
459 | | - // we shouldn't ever get here, but just in case... |
460 | | - return false; |
461 | 459 | } |
462 | 460 | |
463 | 461 | static public function getDataFromURL( $url, $format ) { |
Index: trunk/extensions/Babel/Babel.class.php |
— | — | @@ -10,7 +10,7 @@ |
11 | 11 | * Various values from the message cache. |
12 | 12 | */ |
13 | 13 | private $_prefixes, $_suffixes, $_cellspacing, $_directionality, $_url, |
14 | | - $_title, $_footer; |
| 14 | + $_footer; |
15 | 15 | |
16 | 16 | /** |
17 | 17 | * Render the Babel tower. |
Index: trunk/extensions/SocialProfile/UserProfile/UserProfileClass.php |
— | — | @@ -117,13 +117,12 @@ |
118 | 118 | } |
119 | 119 | |
120 | 120 | function formatBirthday( $birthday ) { |
121 | | - global $wgLang; |
122 | 121 | $dob = explode( '-', $birthday ); |
123 | 122 | if ( count( $dob ) == 3 ) { |
124 | 123 | $month = $dob[1]; |
125 | 124 | $day = $dob[2]; |
126 | 125 | return date( "F jS", mktime( 0, 0, 0, $month, $day ) ); |
127 | | - return $day . ' ' . $wgLang->getMonthNameGen( $month ); |
| 126 | + r//eturn $day . ' ' . $wgLang->getMonthNameGen( $month ); |
128 | 127 | } |
129 | 128 | return $birthday; |
130 | 129 | } |
Index: trunk/extensions/InlineScripts/interpreter/Scanner.php |
— | — | @@ -144,7 +144,7 @@ |
145 | 145 | $this->mPos++; |
146 | 146 | } |
147 | 147 | } |
148 | | - throw new ISUserVisibleException( 'unclosedstring', $this->mPos, array() );; |
| 148 | + throw new ISUserVisibleException( 'unclosedstring', $this->mPos, array() ); |
149 | 149 | } |
150 | 150 | |
151 | 151 | // Find operators |
Index: trunk/extensions/Cassandra/Cassandra_body.php |
— | — | @@ -76,8 +76,6 @@ |
77 | 77 | } catch ( TException $e ) { |
78 | 78 | throw new MWCassandraException( $e ); |
79 | 79 | } |
80 | | - |
81 | | - return false; |
82 | 80 | } |
83 | 81 | |
84 | 82 | private function connect( $cluster ) { |
Index: trunk/extensions/FBConnect/FBConnect.php |
— | — | @@ -173,11 +173,6 @@ |
174 | 174 | // If PHP's version doesn't support the Reflection API, then exit |
175 | 175 | die( 'PHP version (' . phpversion() . ') must be great enough to support the Reflection API' ); |
176 | 176 | // Or list the extensions here manually... |
177 | | - $hooks = array( |
178 | | - 'AuthPluginSetup', 'UserLoadFromSession', |
179 | | - 'RenderPreferencesForm', 'PersonalUrls', |
180 | | - 'ParserAfterTidy', 'BeforePageDisplay', /*...*/ |
181 | | - ); |
182 | 177 | } |
183 | 178 | return $hooks; |
184 | 179 | } |
Index: trunk/extensions/SemanticResultFormats/GraphViz/SRF_Process.php |
— | — | @@ -363,9 +363,7 @@ |
364 | 364 | $debug = ''; |
365 | 365 | if ( $this->m_isDebugSet ) $debug = '<pre>' . $graphInput . '</pre>'; |
366 | 366 | |
367 | | - return $result . $debug; ; |
368 | | - |
369 | | - |
| 367 | + return $result . $debug; |
370 | 368 | } |
371 | 369 | } |
372 | 370 | |
Index: trunk/extensions/TradeTrack/SpecialTradeTrack.php |
— | — | @@ -162,9 +162,6 @@ |
163 | 163 | array( 'src' => 'js/jquery.NobleCount.js', 'version' => 1 ), |
164 | 164 | ); |
165 | 165 | |
166 | | - private static $messages = array(); |
167 | | - private static $scripts = array(); |
168 | | - |
169 | 166 | /** |
170 | 167 | * This is our errors array. |
171 | 168 | */ |
— | — | @@ -172,7 +169,6 @@ |
173 | 170 | |
174 | 171 | function __construct() { |
175 | 172 | parent::__construct( 'TradeTrack' ); |
176 | | - wfLoadExtensionMessages( 'TradeTrack' ); |
177 | 173 | } |
178 | 174 | |
179 | 175 | /** |
Index: trunk/extensions/QrCode/phpqrcode/qrencode.php |
— | — | @@ -77,7 +77,6 @@ |
78 | 78 | $ret = $this->init($spec); |
79 | 79 | if($ret < 0) { |
80 | 80 | throw new Exception('block alloc error'); |
81 | | - return null; |
82 | 81 | } |
83 | 82 | |
84 | 83 | $this->count = 0; |
— | — | @@ -245,7 +244,6 @@ |
246 | 245 | { |
247 | 246 | if(string == NULL) { |
248 | 247 | throw new Exception('empty string!'); |
249 | | - return NULL; |
250 | 248 | } |
251 | 249 | |
252 | 250 | $input = new QRinput($version, $level); |
— | — | @@ -265,7 +263,6 @@ |
266 | 264 | |
267 | 265 | if($hint != QR_MODE_8 && $hint != QR_MODE_KANJI) { |
268 | 266 | throw new Exception('bad hint'); |
269 | | - return NULL; |
270 | 267 | } |
271 | 268 | |
272 | 269 | $input = new QRinput($version, $level); |
Index: trunk/extensions/QrCode/phpqrcode/qrinput.php |
— | — | @@ -45,7 +45,6 @@ |
46 | 46 | |
47 | 47 | if(!QRinput::check($mode, $size, $setData)) { |
48 | 48 | throw new Exception('Error m:'.$mode.',s:'.$size.',d:'.join(',',$setData)); |
49 | | - return null; |
50 | 49 | } |
51 | 50 | |
52 | 51 | $this->mode = $mode; |
— | — | @@ -320,7 +319,6 @@ |
321 | 320 | { |
322 | 321 | if($level > QR_ECLEVEL_H) { |
323 | 322 | throw new Exception('Invalid ECLEVEL'); |
324 | | - return -1; |
325 | 323 | } |
326 | 324 | |
327 | 325 | $this->level = $level; |
— | — | @@ -620,7 +618,6 @@ |
621 | 619 | $ver = QRspec::getMinimumVersion((int)(($bits + 7) / 8), $this->level); |
622 | 620 | if($ver < 0) { |
623 | 621 | throw new Exception('WRONG VERSION'); |
624 | | - return -1; |
625 | 622 | } else if($ver > $this->getVersion()) { |
626 | 623 | $this->setVersion($ver); |
627 | 624 | } else { |
Index: trunk/extensions/QrCode/phpqrcode/phpqrcode.php |
— | — | @@ -1,39 +1,39 @@ |
2 | | -<?php
|
3 | | -
|
4 | | -/*
|
5 | | - * PHP QR Code encoder
|
6 | | - *
|
7 | | - * This file contains MERGED version of PHP QR Code library.
|
8 | | - * It was auto-generated from full version for your convenience.
|
9 | | - *
|
10 | | - * This merged version was configured to not requre any external files,
|
11 | | - * with disabled cache, error loging and weker but faster mask matching.
|
12 | | - * If you need tune it up please use non-merged version.
|
13 | | - *
|
14 | | - * For full version, documentation, examples of use please visit:
|
15 | | - *
|
16 | | - * http://phpqrcode.sourceforge.net/
|
17 | | - * https://sourceforge.net/projects/phpqrcode/
|
18 | | - *
|
19 | | - * PHP QR Code is distributed under LGPL 3
|
20 | | - * Copyright (C) 2010 Dominik Dzienia <deltalab at poczta dot fm>
|
21 | | - *
|
22 | | - * This library is free software; you can redistribute it and/or
|
23 | | - * modify it under the terms of the GNU Lesser General Public
|
24 | | - * License as published by the Free Software Foundation; either
|
25 | | - * version 3 of the License, or any later version.
|
26 | | - *
|
27 | | - * This library is distributed in the hope that it will be useful,
|
28 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
29 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
30 | | - * Lesser General Public License for more details.
|
31 | | - *
|
32 | | - * You should have received a copy of the GNU Lesser General Public
|
33 | | - * License along with this library; if not, write to the Free Software
|
34 | | - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
35 | | - */
|
36 | | -
|
| 2 | +<?php |
| 3 | + |
| 4 | +/* |
| 5 | + * PHP QR Code encoder |
| 6 | + * |
| 7 | + * This file contains MERGED version of PHP QR Code library. |
| 8 | + * It was auto-generated from full version for your convenience. |
| 9 | + * |
| 10 | + * This merged version was configured to not requre any external files, |
| 11 | + * with disabled cache, error loging and weker but faster mask matching. |
| 12 | + * If you need tune it up please use non-merged version. |
| 13 | + * |
| 14 | + * For full version, documentation, examples of use please visit: |
| 15 | + * |
| 16 | + * http://phpqrcode.sourceforge.net/ |
| 17 | + * https://sourceforge.net/projects/phpqrcode/ |
| 18 | + * |
| 19 | + * PHP QR Code is distributed under LGPL 3 |
| 20 | + * Copyright (C) 2010 Dominik Dzienia <deltalab at poczta dot fm> |
| 21 | + * |
| 22 | + * This library is free software; you can redistribute it and/or |
| 23 | + * modify it under the terms of the GNU Lesser General Public |
| 24 | + * License as published by the Free Software Foundation; either |
| 25 | + * version 3 of the License, or any later version. |
| 26 | + * |
| 27 | + * This library is distributed in the hope that it will be useful, |
| 28 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 29 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 30 | + * Lesser General Public License for more details. |
| 31 | + * |
| 32 | + * You should have received a copy of the GNU Lesser General Public |
| 33 | + * License along with this library; if not, write to the Free Software |
| 34 | + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 35 | + */ |
37 | 36 | |
| 37 | + |
38 | 38 | |
39 | 39 | /* |
40 | 40 | * Version: 1.1.3 |
— | — | @@ -46,59 +46,59 @@ |
47 | 47 | |
48 | 48 | |
49 | 49 | |
50 | | -
|
51 | | -
|
52 | | -/*
|
53 | | - * PHP QR Code encoder
|
54 | | - *
|
55 | | - * Common constants
|
56 | | - *
|
57 | | - * Based on libqrencode C library distributed under LGPL 2.1
|
58 | | - * Copyright (C) 2006, 2007, 2008, 2009 Kentaro Fukuchi <fukuchi@megaui.net>
|
59 | | - *
|
60 | | - * PHP QR Code is distributed under LGPL 3
|
61 | | - * Copyright (C) 2010 Dominik Dzienia <deltalab at poczta dot fm>
|
62 | | - *
|
63 | | - * This library is free software; you can redistribute it and/or
|
64 | | - * modify it under the terms of the GNU Lesser General Public
|
65 | | - * License as published by the Free Software Foundation; either
|
66 | | - * version 3 of the License, or any later version.
|
67 | | - *
|
68 | | - * This library is distributed in the hope that it will be useful,
|
69 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
70 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
71 | | - * Lesser General Public License for more details.
|
72 | | - *
|
73 | | - * You should have received a copy of the GNU Lesser General Public
|
74 | | - * License along with this library; if not, write to the Free Software
|
75 | | - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
76 | | - */
|
77 | | -
|
78 | | - // Encoding modes
|
79 | | -
|
80 | | - define('QR_MODE_NUL', -1);
|
81 | | - define('QR_MODE_NUM', 0);
|
82 | | - define('QR_MODE_AN', 1);
|
83 | | - define('QR_MODE_8', 2);
|
84 | | - define('QR_MODE_KANJI', 3);
|
85 | | - define('QR_MODE_STRUCTURE', 4);
|
86 | | -
|
87 | | - // Levels of error correction.
|
88 | | -
|
89 | | - define('QR_ECLEVEL_L', 0);
|
90 | | - define('QR_ECLEVEL_M', 1);
|
91 | | - define('QR_ECLEVEL_Q', 2);
|
92 | | - define('QR_ECLEVEL_H', 3);
|
93 | | -
|
94 | | - // Supported output formats
|
95 | | -
|
96 | | - define('QR_FORMAT_TEXT', 0);
|
97 | | - define('QR_FORMAT_PNG', 1);
|
98 | | -
|
99 | | - class qrstr {
|
100 | | - public static function set(&$srctab, $x, $y, $repl, $replLen = false) {
|
101 | | - $srctab[$y] = substr_replace($srctab[$y], ($replLen !== false)?substr($repl,0,$replLen):$repl, $x, ($replLen !== false)?$replLen:strlen($repl));
|
102 | | - }
|
| 50 | + |
| 51 | + |
| 52 | +/* |
| 53 | + * PHP QR Code encoder |
| 54 | + * |
| 55 | + * Common constants |
| 56 | + * |
| 57 | + * Based on libqrencode C library distributed under LGPL 2.1 |
| 58 | + * Copyright (C) 2006, 2007, 2008, 2009 Kentaro Fukuchi <fukuchi@megaui.net> |
| 59 | + * |
| 60 | + * PHP QR Code is distributed under LGPL 3 |
| 61 | + * Copyright (C) 2010 Dominik Dzienia <deltalab at poczta dot fm> |
| 62 | + * |
| 63 | + * This library is free software; you can redistribute it and/or |
| 64 | + * modify it under the terms of the GNU Lesser General Public |
| 65 | + * License as published by the Free Software Foundation; either |
| 66 | + * version 3 of the License, or any later version. |
| 67 | + * |
| 68 | + * This library is distributed in the hope that it will be useful, |
| 69 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 70 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 71 | + * Lesser General Public License for more details. |
| 72 | + * |
| 73 | + * You should have received a copy of the GNU Lesser General Public |
| 74 | + * License along with this library; if not, write to the Free Software |
| 75 | + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 76 | + */ |
| 77 | + |
| 78 | + // Encoding modes |
| 79 | + |
| 80 | + define('QR_MODE_NUL', -1); |
| 81 | + define('QR_MODE_NUM', 0); |
| 82 | + define('QR_MODE_AN', 1); |
| 83 | + define('QR_MODE_8', 2); |
| 84 | + define('QR_MODE_KANJI', 3); |
| 85 | + define('QR_MODE_STRUCTURE', 4); |
| 86 | + |
| 87 | + // Levels of error correction. |
| 88 | + |
| 89 | + define('QR_ECLEVEL_L', 0); |
| 90 | + define('QR_ECLEVEL_M', 1); |
| 91 | + define('QR_ECLEVEL_Q', 2); |
| 92 | + define('QR_ECLEVEL_H', 3); |
| 93 | + |
| 94 | + // Supported output formats |
| 95 | + |
| 96 | + define('QR_FORMAT_TEXT', 0); |
| 97 | + define('QR_FORMAT_PNG', 1); |
| 98 | + |
| 99 | + class qrstr { |
| 100 | + public static function set(&$srctab, $x, $y, $repl, $replLen = false) { |
| 101 | + $srctab[$y] = substr_replace($srctab[$y], ($replLen !== false)?substr($repl,0,$replLen):$repl, $x, ($replLen !== false)?$replLen:strlen($repl)); |
| 102 | + } |
103 | 103 | } |
104 | 104 | |
105 | 105 | |
— | — | @@ -107,23 +107,23 @@ |
108 | 108 | |
109 | 109 | |
110 | 110 | |
111 | | -
|
112 | | -/*
|
113 | | - * PHP QR Code encoder
|
114 | | - *
|
115 | | - * Config file, tuned-up for merged verion
|
116 | | - */
|
117 | | -
|
118 | | - define('QR_CACHEABLE', false); // use cache - more disk reads but less CPU power, masks and format templates are stored there
|
119 | | - define('QR_CACHE_DIR', false); // used when QR_CACHEABLE === true
|
120 | | - define('QR_LOG_DIR', false); // default error logs dir
|
121 | | -
|
122 | | - define('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
|
123 | | - define('QR_FIND_FROM_RANDOM', 2); // if false, checks all masks available, otherwise value tells count of masks need to be checked, mask id are got randomly
|
124 | | - define('QR_DEFAULT_MASK', 2); // when QR_FIND_BEST_MASK === false
|
125 | | -
|
126 | | - define('QR_PNG_MAXIMUM_SIZE', 1024); // maximum allowed png image width (in pixels), tune to make sure GD and PHP can handle such big images
|
| 111 | + |
| 112 | +/* |
| 113 | + * PHP QR Code encoder |
| 114 | + * |
| 115 | + * Config file, tuned-up for merged verion |
| 116 | + */ |
| 117 | + |
| 118 | + define('QR_CACHEABLE', false); // use cache - more disk reads but less CPU power, masks and format templates are stored there |
| 119 | + define('QR_CACHE_DIR', false); // used when QR_CACHEABLE === true |
| 120 | + define('QR_LOG_DIR', false); // default error logs dir |
| 121 | + |
| 122 | + define('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 |
| 123 | + define('QR_FIND_FROM_RANDOM', 2); // if false, checks all masks available, otherwise value tells count of masks need to be checked, mask id are got randomly |
| 124 | + define('QR_DEFAULT_MASK', 2); // when QR_FIND_BEST_MASK === false |
127 | 125 | |
| 126 | + define('QR_PNG_MAXIMUM_SIZE', 1024); // maximum allowed png image width (in pixels), tune to make sure GD and PHP can handle such big images |
| 127 | + |
128 | 128 | |
129 | 129 | |
130 | 130 | |
— | — | @@ -131,776 +131,776 @@ |
132 | 132 | |
133 | 133 | |
134 | 134 | |
135 | | -
|
136 | | -/*
|
137 | | - * PHP QR Code encoder
|
138 | | - *
|
139 | | - * Toolset, handy and debug utilites.
|
140 | | - *
|
141 | | - * PHP QR Code is distributed under LGPL 3
|
142 | | - * Copyright (C) 2010 Dominik Dzienia <deltalab at poczta dot fm>
|
143 | | - *
|
144 | | - * This library is free software; you can redistribute it and/or
|
145 | | - * modify it under the terms of the GNU Lesser General Public
|
146 | | - * License as published by the Free Software Foundation; either
|
147 | | - * version 3 of the License, or any later version.
|
148 | | - *
|
149 | | - * This library is distributed in the hope that it will be useful,
|
150 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
151 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
152 | | - * Lesser General Public License for more details.
|
153 | | - *
|
154 | | - * You should have received a copy of the GNU Lesser General Public
|
155 | | - * License along with this library; if not, write to the Free Software
|
156 | | - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
157 | | - */
|
158 | | -
|
159 | | - class QRtools {
|
160 | | -
|
161 | | - //----------------------------------------------------------------------
|
162 | | - public static function binarize($frame)
|
163 | | - {
|
164 | | - $len = count($frame);
|
165 | | - foreach ($frame as &$frameLine) {
|
166 | | -
|
167 | | - for($i=0; $i<$len; $i++) {
|
168 | | - $frameLine[$i] = (ord($frameLine[$i])&1)?'1':'0';
|
169 | | - }
|
170 | | - }
|
171 | | -
|
172 | | - return $frame;
|
173 | | - }
|
174 | | -
|
175 | | - //----------------------------------------------------------------------
|
176 | | - public static function tcpdfBarcodeArray($code, $mode = 'QR,L', $tcPdfVersion = '4.5.037')
|
177 | | - {
|
178 | | - $barcode_array = array();
|
179 | | -
|
180 | | - if (!is_array($mode))
|
181 | | - $mode = explode(',', $mode);
|
182 | | -
|
183 | | - $eccLevel = 'L';
|
184 | | -
|
185 | | - if (count($mode) > 1) {
|
186 | | - $eccLevel = $mode[1];
|
187 | | - }
|
188 | | -
|
189 | | - $qrTab = QRcode::text($code, false, $eccLevel);
|
190 | | - $size = count($qrTab);
|
191 | | -
|
192 | | - $barcode_array['num_rows'] = $size;
|
193 | | - $barcode_array['num_cols'] = $size;
|
194 | | - $barcode_array['bcode'] = array();
|
195 | | -
|
196 | | - foreach ($qrTab as $line) {
|
197 | | - $arrAdd = array();
|
198 | | - foreach(str_split($line) as $char)
|
199 | | - $arrAdd[] = ($char=='1')?1:0;
|
200 | | - $barcode_array['bcode'][] = $arrAdd;
|
201 | | - }
|
202 | | -
|
203 | | - return $barcode_array;
|
204 | | - }
|
205 | | -
|
206 | | - //----------------------------------------------------------------------
|
207 | | - public static function clearCache()
|
208 | | - {
|
209 | | - self::$frames = array();
|
210 | | - }
|
211 | | -
|
212 | | - //----------------------------------------------------------------------
|
213 | | - public static function buildCache()
|
214 | | - {
|
215 | | - QRtools::markTime('before_build_cache');
|
216 | | -
|
217 | | - $mask = new QRmask();
|
218 | | - for ($a=1; $a <= QRSPEC_VERSION_MAX; $a++) {
|
219 | | - $frame = QRspec::newFrame($a);
|
220 | | - if (QR_IMAGE) {
|
221 | | - $fileName = QR_CACHE_DIR.'frame_'.$a.'.png';
|
222 | | - QRimage::png(self::binarize($frame), $fileName, 1, 0);
|
223 | | - }
|
224 | | -
|
225 | | - $width = count($frame);
|
226 | | - $bitMask = array_fill(0, $width, array_fill(0, $width, 0));
|
227 | | - for ($maskNo=0; $maskNo<8; $maskNo++)
|
228 | | - $mask->makeMaskNo($maskNo, $width, $frame, $bitMask, true);
|
229 | | - }
|
230 | | -
|
231 | | - QRtools::markTime('after_build_cache');
|
232 | | - }
|
233 | | -
|
234 | | - //----------------------------------------------------------------------
|
235 | | - public static function log($outfile, $err)
|
236 | | - {
|
237 | | - if (QR_LOG_DIR !== false) {
|
238 | | - if ($err != '') {
|
239 | | - if ($outfile !== false) {
|
240 | | - file_put_contents(QR_LOG_DIR.basename($outfile).'-errors.txt', date('Y-m-d H:i:s').': '.$err, FILE_APPEND);
|
241 | | - } else {
|
242 | | - file_put_contents(QR_LOG_DIR.'errors.txt', date('Y-m-d H:i:s').': '.$err, FILE_APPEND);
|
243 | | - }
|
244 | | - }
|
245 | | - }
|
246 | | - }
|
247 | | -
|
248 | | - //----------------------------------------------------------------------
|
249 | | - public static function dumpMask($frame)
|
250 | | - {
|
251 | | - $width = count($frame);
|
252 | | - for($y=0;$y<$width;$y++) {
|
253 | | - for($x=0;$x<$width;$x++) {
|
254 | | - echo ord($frame[$y][$x]).',';
|
255 | | - }
|
256 | | - }
|
257 | | - }
|
258 | | -
|
259 | | - //----------------------------------------------------------------------
|
260 | | - public static function markTime($markerId)
|
261 | | - {
|
262 | | - list($usec, $sec) = explode(" ", microtime());
|
263 | | - $time = ((float)$usec + (float)$sec);
|
264 | | -
|
265 | | - if (!isset($GLOBALS['qr_time_bench']))
|
266 | | - $GLOBALS['qr_time_bench'] = array();
|
267 | | -
|
268 | | - $GLOBALS['qr_time_bench'][$markerId] = $time;
|
269 | | - }
|
270 | | -
|
271 | | - //----------------------------------------------------------------------
|
272 | | - public static function timeBenchmark()
|
273 | | - {
|
274 | | - self::markTime('finish');
|
275 | | -
|
276 | | - $lastTime = 0;
|
277 | | - $startTime = 0;
|
278 | | - $p = 0;
|
279 | | -
|
280 | | - echo '<table cellpadding="3" cellspacing="1">
|
281 | | - <thead><tr style="border-bottom:1px solid silver"><td colspan="2" style="text-align:center">BENCHMARK</td></tr></thead>
|
282 | | - <tbody>';
|
283 | | -
|
284 | | - foreach($GLOBALS['qr_time_bench'] as $markerId=>$thisTime) {
|
285 | | - if ($p > 0) {
|
286 | | - echo '<tr><th style="text-align:right">till '.$markerId.': </th><td>'.number_format($thisTime-$lastTime, 6).'s</td></tr>';
|
287 | | - } else {
|
288 | | - $startTime = $thisTime;
|
289 | | - }
|
290 | | -
|
291 | | - $p++;
|
292 | | - $lastTime = $thisTime;
|
293 | | - }
|
294 | | -
|
295 | | - echo '</tbody><tfoot>
|
296 | | - <tr style="border-top:2px solid black"><th style="text-align:right">TOTAL: </th><td>'.number_format($lastTime-$startTime, 6).'s</td></tr>
|
297 | | - </tfoot>
|
298 | | - </table>';
|
299 | | - }
|
300 | | -
|
301 | | - }
|
302 | | -
|
303 | | - //##########################################################################
|
304 | | -
|
305 | | - QRtools::markTime('start');
|
| 135 | + |
| 136 | +/* |
| 137 | + * PHP QR Code encoder |
| 138 | + * |
| 139 | + * Toolset, handy and debug utilites. |
| 140 | + * |
| 141 | + * PHP QR Code is distributed under LGPL 3 |
| 142 | + * Copyright (C) 2010 Dominik Dzienia <deltalab at poczta dot fm> |
| 143 | + * |
| 144 | + * This library is free software; you can redistribute it and/or |
| 145 | + * modify it under the terms of the GNU Lesser General Public |
| 146 | + * License as published by the Free Software Foundation; either |
| 147 | + * version 3 of the License, or any later version. |
| 148 | + * |
| 149 | + * This library is distributed in the hope that it will be useful, |
| 150 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 151 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 152 | + * Lesser General Public License for more details. |
| 153 | + * |
| 154 | + * You should have received a copy of the GNU Lesser General Public |
| 155 | + * License along with this library; if not, write to the Free Software |
| 156 | + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 157 | + */ |
| 158 | + |
| 159 | + class QRtools { |
306 | 160 | |
| 161 | + //---------------------------------------------------------------------- |
| 162 | + public static function binarize($frame) |
| 163 | + { |
| 164 | + $len = count($frame); |
| 165 | + foreach ($frame as &$frameLine) { |
| 166 | + |
| 167 | + for($i=0; $i<$len; $i++) { |
| 168 | + $frameLine[$i] = (ord($frameLine[$i])&1)?'1':'0'; |
| 169 | + } |
| 170 | + } |
| 171 | + |
| 172 | + return $frame; |
| 173 | + } |
| 174 | + |
| 175 | + //---------------------------------------------------------------------- |
| 176 | + public static function tcpdfBarcodeArray($code, $mode = 'QR,L', $tcPdfVersion = '4.5.037') |
| 177 | + { |
| 178 | + $barcode_array = array(); |
| 179 | + |
| 180 | + if (!is_array($mode)) |
| 181 | + $mode = explode(',', $mode); |
| 182 | + |
| 183 | + $eccLevel = 'L'; |
| 184 | + |
| 185 | + if (count($mode) > 1) { |
| 186 | + $eccLevel = $mode[1]; |
| 187 | + } |
| 188 | + |
| 189 | + $qrTab = QRcode::text($code, false, $eccLevel); |
| 190 | + $size = count($qrTab); |
| 191 | + |
| 192 | + $barcode_array['num_rows'] = $size; |
| 193 | + $barcode_array['num_cols'] = $size; |
| 194 | + $barcode_array['bcode'] = array(); |
| 195 | + |
| 196 | + foreach ($qrTab as $line) { |
| 197 | + $arrAdd = array(); |
| 198 | + foreach(str_split($line) as $char) |
| 199 | + $arrAdd[] = ($char=='1')?1:0; |
| 200 | + $barcode_array['bcode'][] = $arrAdd; |
| 201 | + } |
| 202 | + |
| 203 | + return $barcode_array; |
| 204 | + } |
| 205 | + |
| 206 | + //---------------------------------------------------------------------- |
| 207 | + public static function clearCache() |
| 208 | + { |
| 209 | + self::$frames = array(); |
| 210 | + } |
| 211 | + |
| 212 | + //---------------------------------------------------------------------- |
| 213 | + public static function buildCache() |
| 214 | + { |
| 215 | + QRtools::markTime('before_build_cache'); |
| 216 | + |
| 217 | + $mask = new QRmask(); |
| 218 | + for ($a=1; $a <= QRSPEC_VERSION_MAX; $a++) { |
| 219 | + $frame = QRspec::newFrame($a); |
| 220 | + if (QR_IMAGE) { |
| 221 | + $fileName = QR_CACHE_DIR.'frame_'.$a.'.png'; |
| 222 | + QRimage::png(self::binarize($frame), $fileName, 1, 0); |
| 223 | + } |
| 224 | + |
| 225 | + $width = count($frame); |
| 226 | + $bitMask = array_fill(0, $width, array_fill(0, $width, 0)); |
| 227 | + for ($maskNo=0; $maskNo<8; $maskNo++) |
| 228 | + $mask->makeMaskNo($maskNo, $width, $frame, $bitMask, true); |
| 229 | + } |
| 230 | + |
| 231 | + QRtools::markTime('after_build_cache'); |
| 232 | + } |
307 | 233 | |
| 234 | + //---------------------------------------------------------------------- |
| 235 | + public static function log($outfile, $err) |
| 236 | + { |
| 237 | + if (QR_LOG_DIR !== false) { |
| 238 | + if ($err != '') { |
| 239 | + if ($outfile !== false) { |
| 240 | + file_put_contents(QR_LOG_DIR.basename($outfile).'-errors.txt', date('Y-m-d H:i:s').': '.$err, FILE_APPEND); |
| 241 | + } else { |
| 242 | + file_put_contents(QR_LOG_DIR.'errors.txt', date('Y-m-d H:i:s').': '.$err, FILE_APPEND); |
| 243 | + } |
| 244 | + } |
| 245 | + } |
| 246 | + } |
| 247 | + |
| 248 | + //---------------------------------------------------------------------- |
| 249 | + public static function dumpMask($frame) |
| 250 | + { |
| 251 | + $width = count($frame); |
| 252 | + for($y=0;$y<$width;$y++) { |
| 253 | + for($x=0;$x<$width;$x++) { |
| 254 | + echo ord($frame[$y][$x]).','; |
| 255 | + } |
| 256 | + } |
| 257 | + } |
| 258 | + |
| 259 | + //---------------------------------------------------------------------- |
| 260 | + public static function markTime($markerId) |
| 261 | + { |
| 262 | + list($usec, $sec) = explode(" ", microtime()); |
| 263 | + $time = ((float)$usec + (float)$sec); |
| 264 | + |
| 265 | + if (!isset($GLOBALS['qr_time_bench'])) |
| 266 | + $GLOBALS['qr_time_bench'] = array(); |
| 267 | + |
| 268 | + $GLOBALS['qr_time_bench'][$markerId] = $time; |
| 269 | + } |
| 270 | + |
| 271 | + //---------------------------------------------------------------------- |
| 272 | + public static function timeBenchmark() |
| 273 | + { |
| 274 | + self::markTime('finish'); |
| 275 | + |
| 276 | + $lastTime = 0; |
| 277 | + $startTime = 0; |
| 278 | + $p = 0; |
308 | 279 | |
| 280 | + echo '<table cellpadding="3" cellspacing="1"> |
| 281 | + <thead><tr style="border-bottom:1px solid silver"><td colspan="2" style="text-align:center">BENCHMARK</td></tr></thead> |
| 282 | + <tbody>'; |
309 | 283 | |
| 284 | + foreach($GLOBALS['qr_time_bench'] as $markerId=>$thisTime) { |
| 285 | + if ($p > 0) { |
| 286 | + echo '<tr><th style="text-align:right">till '.$markerId.': </th><td>'.number_format($thisTime-$lastTime, 6).'s</td></tr>'; |
| 287 | + } else { |
| 288 | + $startTime = $thisTime; |
| 289 | + } |
| 290 | + |
| 291 | + $p++; |
| 292 | + $lastTime = $thisTime; |
| 293 | + } |
| 294 | + |
| 295 | + echo '</tbody><tfoot> |
| 296 | + <tr style="border-top:2px solid black"><th style="text-align:right">TOTAL: </th><td>'.number_format($lastTime-$startTime, 6).'s</td></tr> |
| 297 | + </tfoot> |
| 298 | + </table>'; |
| 299 | + } |
| 300 | + |
| 301 | + } |
| 302 | + |
| 303 | + //########################################################################## |
| 304 | + |
| 305 | + QRtools::markTime('start'); |
| 306 | + |
| 307 | + |
| 308 | + |
| 309 | + |
310 | 310 | //---- qrspec.php ----------------------------- |
311 | 311 | |
312 | 312 | |
313 | 313 | |
314 | | -
|
315 | | -/*
|
316 | | - * PHP QR Code encoder
|
317 | | - *
|
318 | | - * QR Code specifications
|
319 | | - *
|
320 | | - * Based on libqrencode C library distributed under LGPL 2.1
|
321 | | - * Copyright (C) 2006, 2007, 2008, 2009 Kentaro Fukuchi <fukuchi@megaui.net>
|
322 | | - *
|
323 | | - * PHP QR Code is distributed under LGPL 3
|
324 | | - * Copyright (C) 2010 Dominik Dzienia <deltalab at poczta dot fm>
|
325 | | - *
|
326 | | - * The following data / specifications are taken from
|
327 | | - * "Two dimensional symbol -- QR-code -- Basic Specification" (JIS X0510:2004)
|
328 | | - * or
|
329 | | - * "Automatic identification and data capture techniques --
|
330 | | - * QR Code 2005 bar code symbology specification" (ISO/IEC 18004:2006)
|
331 | | - *
|
332 | | - * This library is free software; you can redistribute it and/or
|
333 | | - * modify it under the terms of the GNU Lesser General Public
|
334 | | - * License as published by the Free Software Foundation; either
|
335 | | - * version 3 of the License, or any later version.
|
336 | | - *
|
337 | | - * This library is distributed in the hope that it will be useful,
|
338 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
339 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
340 | | - * Lesser General Public License for more details.
|
341 | | - *
|
342 | | - * You should have received a copy of the GNU Lesser General Public
|
343 | | - * License along with this library; if not, write to the Free Software
|
344 | | - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
345 | | - */
|
346 | | -
|
347 | | - define('QRSPEC_VERSION_MAX', 40);
|
348 | | - define('QRSPEC_WIDTH_MAX', 177);
|
349 | | -
|
350 | | - define('QRCAP_WIDTH', 0);
|
351 | | - define('QRCAP_WORDS', 1);
|
352 | | - define('QRCAP_REMINDER', 2);
|
353 | | - define('QRCAP_EC', 3);
|
354 | | -
|
355 | | - class QRspec {
|
356 | | -
|
357 | | - public static $capacity = array(
|
358 | | - array( 0, 0, 0, array( 0, 0, 0, 0)),
|
359 | | - array( 21, 26, 0, array( 7, 10, 13, 17)), // 1
|
360 | | - array( 25, 44, 7, array( 10, 16, 22, 28)),
|
361 | | - array( 29, 70, 7, array( 15, 26, 36, 44)),
|
362 | | - array( 33, 100, 7, array( 20, 36, 52, 64)),
|
363 | | - array( 37, 134, 7, array( 26, 48, 72, 88)), // 5
|
364 | | - array( 41, 172, 7, array( 36, 64, 96, 112)),
|
365 | | - array( 45, 196, 0, array( 40, 72, 108, 130)),
|
366 | | - array( 49, 242, 0, array( 48, 88, 132, 156)),
|
367 | | - array( 53, 292, 0, array( 60, 110, 160, 192)),
|
368 | | - array( 57, 346, 0, array( 72, 130, 192, 224)), //10
|
369 | | - array( 61, 404, 0, array( 80, 150, 224, 264)),
|
370 | | - array( 65, 466, 0, array( 96, 176, 260, 308)),
|
371 | | - array( 69, 532, 0, array( 104, 198, 288, 352)),
|
372 | | - array( 73, 581, 3, array( 120, 216, 320, 384)),
|
373 | | - array( 77, 655, 3, array( 132, 240, 360, 432)), //15
|
374 | | - array( 81, 733, 3, array( 144, 280, 408, 480)),
|
375 | | - array( 85, 815, 3, array( 168, 308, 448, 532)),
|
376 | | - array( 89, 901, 3, array( 180, 338, 504, 588)),
|
377 | | - array( 93, 991, 3, array( 196, 364, 546, 650)),
|
378 | | - array( 97, 1085, 3, array( 224, 416, 600, 700)), //20
|
379 | | - array(101, 1156, 4, array( 224, 442, 644, 750)),
|
380 | | - array(105, 1258, 4, array( 252, 476, 690, 816)),
|
381 | | - array(109, 1364, 4, array( 270, 504, 750, 900)),
|
382 | | - array(113, 1474, 4, array( 300, 560, 810, 960)),
|
383 | | - array(117, 1588, 4, array( 312, 588, 870, 1050)), //25
|
384 | | - array(121, 1706, 4, array( 336, 644, 952, 1110)),
|
385 | | - array(125, 1828, 4, array( 360, 700, 1020, 1200)),
|
386 | | - array(129, 1921, 3, array( 390, 728, 1050, 1260)),
|
387 | | - array(133, 2051, 3, array( 420, 784, 1140, 1350)),
|
388 | | - array(137, 2185, 3, array( 450, 812, 1200, 1440)), //30
|
389 | | - array(141, 2323, 3, array( 480, 868, 1290, 1530)),
|
390 | | - array(145, 2465, 3, array( 510, 924, 1350, 1620)),
|
391 | | - array(149, 2611, 3, array( 540, 980, 1440, 1710)),
|
392 | | - array(153, 2761, 3, array( 570, 1036, 1530, 1800)),
|
393 | | - array(157, 2876, 0, array( 570, 1064, 1590, 1890)), //35
|
394 | | - array(161, 3034, 0, array( 600, 1120, 1680, 1980)),
|
395 | | - array(165, 3196, 0, array( 630, 1204, 1770, 2100)),
|
396 | | - array(169, 3362, 0, array( 660, 1260, 1860, 2220)),
|
397 | | - array(173, 3532, 0, array( 720, 1316, 1950, 2310)),
|
398 | | - array(177, 3706, 0, array( 750, 1372, 2040, 2430)) //40
|
399 | | - );
|
400 | | -
|
401 | | - //----------------------------------------------------------------------
|
402 | | - public static function getDataLength($version, $level)
|
403 | | - {
|
404 | | - return self::$capacity[$version][QRCAP_WORDS] - self::$capacity[$version][QRCAP_EC][$level];
|
405 | | - }
|
406 | | -
|
407 | | - //----------------------------------------------------------------------
|
408 | | - public static function getECCLength($version, $level)
|
409 | | - {
|
410 | | - return self::$capacity[$version][QRCAP_EC][$level];
|
411 | | - }
|
412 | | -
|
413 | | - //----------------------------------------------------------------------
|
414 | | - public static function getWidth($version)
|
415 | | - {
|
416 | | - return self::$capacity[$version][QRCAP_WIDTH];
|
417 | | - }
|
418 | | -
|
419 | | - //----------------------------------------------------------------------
|
420 | | - public static function getRemainder($version)
|
421 | | - {
|
422 | | - return self::$capacity[$version][QRCAP_REMINDER];
|
423 | | - }
|
424 | | -
|
425 | | - //----------------------------------------------------------------------
|
426 | | - public static function getMinimumVersion($size, $level)
|
427 | | - {
|
428 | | -
|
429 | | - for($i=1; $i<= QRSPEC_VERSION_MAX; $i++) {
|
430 | | - $words = self::$capacity[$i][QRCAP_WORDS] - self::$capacity[$i][QRCAP_EC][$level];
|
431 | | - if($words >= $size)
|
432 | | - return $i;
|
433 | | - }
|
434 | | -
|
435 | | - return -1;
|
436 | | - }
|
437 | | -
|
438 | | - //######################################################################
|
439 | | -
|
440 | | - public static $lengthTableBits = array(
|
441 | | - array(10, 12, 14),
|
442 | | - array( 9, 11, 13),
|
443 | | - array( 8, 16, 16),
|
444 | | - array( 8, 10, 12)
|
445 | | - );
|
446 | | -
|
447 | | - //----------------------------------------------------------------------
|
448 | | - public static function lengthIndicator($mode, $version)
|
449 | | - {
|
450 | | - if ($mode == QR_MODE_STRUCTURE)
|
451 | | - return 0;
|
452 | | -
|
453 | | - if ($version <= 9) {
|
454 | | - $l = 0;
|
455 | | - } else if ($version <= 26) {
|
456 | | - $l = 1;
|
457 | | - } else {
|
458 | | - $l = 2;
|
459 | | - }
|
460 | | -
|
461 | | - return self::$lengthTableBits[$mode][$l];
|
462 | | - }
|
463 | | -
|
464 | | - //----------------------------------------------------------------------
|
465 | | - public static function maximumWords($mode, $version)
|
466 | | - {
|
467 | | - if($mode == QR_MODE_STRUCTURE)
|
468 | | - return 3;
|
469 | | -
|
470 | | - if($version <= 9) {
|
471 | | - $l = 0;
|
472 | | - } else if($version <= 26) {
|
473 | | - $l = 1;
|
474 | | - } else {
|
475 | | - $l = 2;
|
476 | | - }
|
477 | | -
|
478 | | - $bits = self::$lengthTableBits[$mode][$l];
|
479 | | - $words = (1 << $bits) - 1;
|
480 | | -
|
481 | | - if($mode == QR_MODE_KANJI) {
|
482 | | - $words *= 2; // the number of bytes is required
|
483 | | - }
|
484 | | -
|
485 | | - return $words;
|
486 | | - }
|
487 | | -
|
488 | | - // Error correction code -----------------------------------------------
|
489 | | - // Table of the error correction code (Reed-Solomon block)
|
490 | | - // See Table 12-16 (pp.30-36), JIS X0510:2004.
|
491 | | -
|
492 | | - public static $eccTable = array(
|
493 | | - array(array( 0, 0), array( 0, 0), array( 0, 0), array( 0, 0)),
|
494 | | - array(array( 1, 0), array( 1, 0), array( 1, 0), array( 1, 0)), // 1
|
495 | | - array(array( 1, 0), array( 1, 0), array( 1, 0), array( 1, 0)),
|
496 | | - array(array( 1, 0), array( 1, 0), array( 2, 0), array( 2, 0)),
|
497 | | - array(array( 1, 0), array( 2, 0), array( 2, 0), array( 4, 0)),
|
498 | | - array(array( 1, 0), array( 2, 0), array( 2, 2), array( 2, 2)), // 5
|
499 | | - array(array( 2, 0), array( 4, 0), array( 4, 0), array( 4, 0)),
|
500 | | - array(array( 2, 0), array( 4, 0), array( 2, 4), array( 4, 1)),
|
501 | | - array(array( 2, 0), array( 2, 2), array( 4, 2), array( 4, 2)),
|
502 | | - array(array( 2, 0), array( 3, 2), array( 4, 4), array( 4, 4)),
|
503 | | - array(array( 2, 2), array( 4, 1), array( 6, 2), array( 6, 2)), //10
|
504 | | - array(array( 4, 0), array( 1, 4), array( 4, 4), array( 3, 8)),
|
505 | | - array(array( 2, 2), array( 6, 2), array( 4, 6), array( 7, 4)),
|
506 | | - array(array( 4, 0), array( 8, 1), array( 8, 4), array(12, 4)),
|
507 | | - array(array( 3, 1), array( 4, 5), array(11, 5), array(11, 5)),
|
508 | | - array(array( 5, 1), array( 5, 5), array( 5, 7), array(11, 7)), //15
|
509 | | - array(array( 5, 1), array( 7, 3), array(15, 2), array( 3, 13)),
|
510 | | - array(array( 1, 5), array(10, 1), array( 1, 15), array( 2, 17)),
|
511 | | - array(array( 5, 1), array( 9, 4), array(17, 1), array( 2, 19)),
|
512 | | - array(array( 3, 4), array( 3, 11), array(17, 4), array( 9, 16)),
|
513 | | - array(array( 3, 5), array( 3, 13), array(15, 5), array(15, 10)), //20
|
514 | | - array(array( 4, 4), array(17, 0), array(17, 6), array(19, 6)),
|
515 | | - array(array( 2, 7), array(17, 0), array( 7, 16), array(34, 0)),
|
516 | | - array(array( 4, 5), array( 4, 14), array(11, 14), array(16, 14)),
|
517 | | - array(array( 6, 4), array( 6, 14), array(11, 16), array(30, 2)),
|
518 | | - array(array( 8, 4), array( 8, 13), array( 7, 22), array(22, 13)), //25
|
519 | | - array(array(10, 2), array(19, 4), array(28, 6), array(33, 4)),
|
520 | | - array(array( 8, 4), array(22, 3), array( 8, 26), array(12, 28)),
|
521 | | - array(array( 3, 10), array( 3, 23), array( 4, 31), array(11, 31)),
|
522 | | - array(array( 7, 7), array(21, 7), array( 1, 37), array(19, 26)),
|
523 | | - array(array( 5, 10), array(19, 10), array(15, 25), array(23, 25)), //30
|
524 | | - array(array(13, 3), array( 2, 29), array(42, 1), array(23, 28)),
|
525 | | - array(array(17, 0), array(10, 23), array(10, 35), array(19, 35)),
|
526 | | - array(array(17, 1), array(14, 21), array(29, 19), array(11, 46)),
|
527 | | - array(array(13, 6), array(14, 23), array(44, 7), array(59, 1)),
|
528 | | - array(array(12, 7), array(12, 26), array(39, 14), array(22, 41)), //35
|
529 | | - array(array( 6, 14), array( 6, 34), array(46, 10), array( 2, 64)),
|
530 | | - array(array(17, 4), array(29, 14), array(49, 10), array(24, 46)),
|
531 | | - array(array( 4, 18), array(13, 32), array(48, 14), array(42, 32)),
|
532 | | - array(array(20, 4), array(40, 7), array(43, 22), array(10, 67)),
|
533 | | - array(array(19, 6), array(18, 31), array(34, 34), array(20, 61)),//40
|
534 | | - );
|
535 | | -
|
536 | | - //----------------------------------------------------------------------
|
537 | | - // CACHEABLE!!!
|
538 | | -
|
539 | | - public static function getEccSpec($version, $level, array &$spec)
|
540 | | - {
|
541 | | - if (count($spec) < 5) {
|
542 | | - $spec = array(0,0,0,0,0);
|
543 | | - }
|
544 | | -
|
545 | | - $b1 = self::$eccTable[$version][$level][0];
|
546 | | - $b2 = self::$eccTable[$version][$level][1];
|
547 | | - $data = self::getDataLength($version, $level);
|
548 | | - $ecc = self::getECCLength($version, $level);
|
549 | | -
|
550 | | - if($b2 == 0) {
|
551 | | - $spec[0] = $b1;
|
552 | | - $spec[1] = (int)($data / $b1);
|
553 | | - $spec[2] = (int)($ecc / $b1);
|
554 | | - $spec[3] = 0;
|
555 | | - $spec[4] = 0;
|
556 | | - } else {
|
557 | | - $spec[0] = $b1;
|
558 | | - $spec[1] = (int)($data / ($b1 + $b2));
|
559 | | - $spec[2] = (int)($ecc / ($b1 + $b2));
|
560 | | - $spec[3] = $b2;
|
561 | | - $spec[4] = $spec[1] + 1;
|
562 | | - }
|
563 | | - }
|
564 | | -
|
565 | | - // Alignment pattern ---------------------------------------------------
|
566 | | -
|
567 | | - // Positions of alignment patterns.
|
568 | | - // This array includes only the second and the third position of the
|
569 | | - // alignment patterns. Rest of them can be calculated from the distance
|
570 | | - // between them.
|
571 | | -
|
572 | | - // See Table 1 in Appendix E (pp.71) of JIS X0510:2004.
|
573 | | -
|
574 | | - public static $alignmentPattern = array(
|
575 | | - array( 0, 0),
|
576 | | - array( 0, 0), array(18, 0), array(22, 0), array(26, 0), array(30, 0), // 1- 5
|
577 | | - array(34, 0), array(22, 38), array(24, 42), array(26, 46), array(28, 50), // 6-10
|
578 | | - array(30, 54), array(32, 58), array(34, 62), array(26, 46), array(26, 48), //11-15
|
579 | | - array(26, 50), array(30, 54), array(30, 56), array(30, 58), array(34, 62), //16-20
|
580 | | - array(28, 50), array(26, 50), array(30, 54), array(28, 54), array(32, 58), //21-25
|
581 | | - array(30, 58), array(34, 62), array(26, 50), array(30, 54), array(26, 52), //26-30
|
582 | | - array(30, 56), array(34, 60), array(30, 58), array(34, 62), array(30, 54), //31-35
|
583 | | - array(24, 50), array(28, 54), array(32, 58), array(26, 54), array(30, 58), //35-40
|
584 | | - );
|
585 | | -
|
586 | | -
|
587 | | - /** --------------------------------------------------------------------
|
588 | | - * Put an alignment marker.
|
589 | | - * @param frame
|
590 | | - * @param width
|
591 | | - * @param ox,oy center coordinate of the pattern
|
592 | | - */
|
593 | | - public static function putAlignmentMarker(array &$frame, $ox, $oy)
|
594 | | - {
|
595 | | - $finder = array(
|
596 | | - "\xa1\xa1\xa1\xa1\xa1",
|
597 | | - "\xa1\xa0\xa0\xa0\xa1",
|
598 | | - "\xa1\xa0\xa1\xa0\xa1",
|
599 | | - "\xa1\xa0\xa0\xa0\xa1",
|
600 | | - "\xa1\xa1\xa1\xa1\xa1"
|
601 | | - );
|
602 | | -
|
603 | | - $yStart = $oy-2;
|
604 | | - $xStart = $ox-2;
|
605 | | -
|
606 | | - for($y=0; $y<5; $y++) {
|
607 | | - QRstr::set($frame, $xStart, $yStart+$y, $finder[$y]);
|
608 | | - }
|
609 | | - }
|
610 | | -
|
611 | | - //----------------------------------------------------------------------
|
612 | | - public static function putAlignmentPattern($version, &$frame, $width)
|
613 | | - {
|
614 | | - if($version < 2)
|
615 | | - return;
|
616 | | -
|
617 | | - $d = self::$alignmentPattern[$version][1] - self::$alignmentPattern[$version][0];
|
618 | | - if($d < 0) {
|
619 | | - $w = 2;
|
620 | | - } else {
|
621 | | - $w = (int)(($width - self::$alignmentPattern[$version][0]) / $d + 2);
|
622 | | - }
|
623 | | -
|
624 | | - if($w * $w - 3 == 1) {
|
625 | | - $x = self::$alignmentPattern[$version][0];
|
626 | | - $y = self::$alignmentPattern[$version][0];
|
627 | | - self::putAlignmentMarker($frame, $x, $y);
|
628 | | - return;
|
629 | | - }
|
630 | | -
|
631 | | - $cx = self::$alignmentPattern[$version][0];
|
632 | | - for($x=1; $x<$w - 1; $x++) {
|
633 | | - self::putAlignmentMarker($frame, 6, $cx);
|
634 | | - self::putAlignmentMarker($frame, $cx, 6);
|
635 | | - $cx += $d;
|
636 | | - }
|
637 | | -
|
638 | | - $cy = self::$alignmentPattern[$version][0];
|
639 | | - for($y=0; $y<$w-1; $y++) {
|
640 | | - $cx = self::$alignmentPattern[$version][0];
|
641 | | - for($x=0; $x<$w-1; $x++) {
|
642 | | - self::putAlignmentMarker($frame, $cx, $cy);
|
643 | | - $cx += $d;
|
644 | | - }
|
645 | | - $cy += $d;
|
646 | | - }
|
647 | | - }
|
648 | | -
|
649 | | - // Version information pattern -----------------------------------------
|
650 | | -
|
651 | | - // Version information pattern (BCH coded).
|
652 | | - // See Table 1 in Appendix D (pp.68) of JIS X0510:2004.
|
653 | | -
|
654 | | - // size: [QRSPEC_VERSION_MAX - 6]
|
655 | | -
|
656 | | - public static $versionPattern = array(
|
657 | | - 0x07c94, 0x085bc, 0x09a99, 0x0a4d3, 0x0bbf6, 0x0c762, 0x0d847, 0x0e60d,
|
658 | | - 0x0f928, 0x10b78, 0x1145d, 0x12a17, 0x13532, 0x149a6, 0x15683, 0x168c9,
|
659 | | - 0x177ec, 0x18ec4, 0x191e1, 0x1afab, 0x1b08e, 0x1cc1a, 0x1d33f, 0x1ed75,
|
660 | | - 0x1f250, 0x209d5, 0x216f0, 0x228ba, 0x2379f, 0x24b0b, 0x2542e, 0x26a64,
|
661 | | - 0x27541, 0x28c69
|
662 | | - );
|
663 | | -
|
664 | | - //----------------------------------------------------------------------
|
665 | | - public static function getVersionPattern($version)
|
666 | | - {
|
667 | | - if($version < 7 || $version > QRSPEC_VERSION_MAX)
|
668 | | - return 0;
|
669 | | -
|
670 | | - return self::$versionPattern[$version -7];
|
671 | | - }
|
672 | | -
|
673 | | - // Format information --------------------------------------------------
|
674 | | - // See calcFormatInfo in tests/test_qrspec.c (orginal qrencode c lib)
|
675 | | -
|
676 | | - public static $formatInfo = array(
|
677 | | - array(0x77c4, 0x72f3, 0x7daa, 0x789d, 0x662f, 0x6318, 0x6c41, 0x6976),
|
678 | | - array(0x5412, 0x5125, 0x5e7c, 0x5b4b, 0x45f9, 0x40ce, 0x4f97, 0x4aa0),
|
679 | | - array(0x355f, 0x3068, 0x3f31, 0x3a06, 0x24b4, 0x2183, 0x2eda, 0x2bed),
|
680 | | - array(0x1689, 0x13be, 0x1ce7, 0x19d0, 0x0762, 0x0255, 0x0d0c, 0x083b)
|
681 | | - );
|
682 | | -
|
683 | | - public static function getFormatInfo($mask, $level)
|
684 | | - {
|
685 | | - if($mask < 0 || $mask > 7)
|
686 | | - return 0;
|
687 | | -
|
688 | | - if($level < 0 || $level > 3)
|
689 | | - return 0;
|
690 | | -
|
691 | | - return self::$formatInfo[$level][$mask];
|
692 | | - }
|
693 | | -
|
694 | | - // Frame ---------------------------------------------------------------
|
695 | | - // Cache of initial frames.
|
696 | | -
|
697 | | - public static $frames = array();
|
698 | | -
|
699 | | - /** --------------------------------------------------------------------
|
700 | | - * Put a finder pattern.
|
701 | | - * @param frame
|
702 | | - * @param width
|
703 | | - * @param ox,oy upper-left coordinate of the pattern
|
704 | | - */
|
705 | | - public static function putFinderPattern(&$frame, $ox, $oy)
|
706 | | - {
|
707 | | - $finder = array(
|
708 | | - "\xc1\xc1\xc1\xc1\xc1\xc1\xc1",
|
709 | | - "\xc1\xc0\xc0\xc0\xc0\xc0\xc1",
|
710 | | - "\xc1\xc0\xc1\xc1\xc1\xc0\xc1",
|
711 | | - "\xc1\xc0\xc1\xc1\xc1\xc0\xc1",
|
712 | | - "\xc1\xc0\xc1\xc1\xc1\xc0\xc1",
|
713 | | - "\xc1\xc0\xc0\xc0\xc0\xc0\xc1",
|
714 | | - "\xc1\xc1\xc1\xc1\xc1\xc1\xc1"
|
715 | | - );
|
716 | | -
|
717 | | - for($y=0; $y<7; $y++) {
|
718 | | - QRstr::set($frame, $ox, $oy+$y, $finder[$y]);
|
719 | | - }
|
720 | | - }
|
721 | | -
|
722 | | - //----------------------------------------------------------------------
|
723 | | - public static function createFrame($version)
|
724 | | - {
|
725 | | - $width = self::$capacity[$version][QRCAP_WIDTH];
|
726 | | - $frameLine = str_repeat ("\0", $width);
|
727 | | - $frame = array_fill(0, $width, $frameLine);
|
728 | | -
|
729 | | - // Finder pattern
|
730 | | - self::putFinderPattern($frame, 0, 0);
|
731 | | - self::putFinderPattern($frame, $width - 7, 0);
|
732 | | - self::putFinderPattern($frame, 0, $width - 7);
|
733 | | -
|
734 | | - // Separator
|
735 | | - $yOffset = $width - 7;
|
736 | | -
|
737 | | - for($y=0; $y<7; $y++) {
|
738 | | - $frame[$y][7] = "\xc0";
|
739 | | - $frame[$y][$width - 8] = "\xc0";
|
740 | | - $frame[$yOffset][7] = "\xc0";
|
741 | | - $yOffset++;
|
742 | | - }
|
743 | | -
|
744 | | - $setPattern = str_repeat("\xc0", 8);
|
745 | | -
|
746 | | - QRstr::set($frame, 0, 7, $setPattern);
|
747 | | - QRstr::set($frame, $width-8, 7, $setPattern);
|
748 | | - QRstr::set($frame, 0, $width - 8, $setPattern);
|
749 | | -
|
750 | | - // Format info
|
751 | | - $setPattern = str_repeat("\x84", 9);
|
752 | | - QRstr::set($frame, 0, 8, $setPattern);
|
753 | | - QRstr::set($frame, $width - 8, 8, $setPattern, 8);
|
754 | | -
|
755 | | - $yOffset = $width - 8;
|
756 | | -
|
757 | | - for($y=0; $y<8; $y++,$yOffset++) {
|
758 | | - $frame[$y][8] = "\x84";
|
759 | | - $frame[$yOffset][8] = "\x84";
|
760 | | - }
|
761 | | -
|
762 | | - // Timing pattern
|
763 | | -
|
764 | | - for($i=1; $i<$width-15; $i++) {
|
765 | | - $frame[6][7+$i] = chr(0x90 | ($i & 1));
|
766 | | - $frame[7+$i][6] = chr(0x90 | ($i & 1));
|
767 | | - }
|
768 | | -
|
769 | | - // Alignment pattern
|
770 | | - self::putAlignmentPattern($version, $frame, $width);
|
771 | | -
|
772 | | - // Version information
|
773 | | - if($version >= 7) {
|
774 | | - $vinf = self::getVersionPattern($version);
|
775 | | -
|
776 | | - $v = $vinf;
|
777 | | -
|
778 | | - for($x=0; $x<6; $x++) {
|
779 | | - for($y=0; $y<3; $y++) {
|
780 | | - $frame[($width - 11)+$y][$x] = chr(0x88 | ($v & 1));
|
781 | | - $v = $v >> 1;
|
782 | | - }
|
783 | | - }
|
784 | | -
|
785 | | - $v = $vinf;
|
786 | | - for($y=0; $y<6; $y++) {
|
787 | | - for($x=0; $x<3; $x++) {
|
788 | | - $frame[$y][$x+($width - 11)] = chr(0x88 | ($v & 1));
|
789 | | - $v = $v >> 1;
|
790 | | - }
|
791 | | - }
|
792 | | - }
|
793 | | -
|
794 | | - // and a little bit...
|
795 | | - $frame[$width - 8][8] = "\x81";
|
796 | | -
|
797 | | - return $frame;
|
798 | | - }
|
799 | | -
|
800 | | - //----------------------------------------------------------------------
|
801 | | - public static function debug($frame, $binary_mode = false)
|
802 | | - {
|
803 | | - if ($binary_mode) {
|
804 | | -
|
805 | | - foreach ($frame as &$frameLine) {
|
806 | | - $frameLine = join('<span class="m"> </span>', explode('0', $frameLine));
|
807 | | - $frameLine = join('██', explode('1', $frameLine));
|
808 | | - }
|
809 | | -
|
810 | | - ?>
|
811 | | - <style>
|
812 | | - .m { background-color: white; }
|
813 | | - </style>
|
814 | | - <?php
|
815 | | - echo '<pre><tt><br/ ><br/ ><br/ > ';
|
816 | | - echo join("<br/ > ", $frame);
|
817 | | - echo '</tt></pre><br/ ><br/ ><br/ ><br/ ><br/ ><br/ >';
|
818 | | -
|
819 | | - } else {
|
820 | | -
|
821 | | - foreach ($frame as &$frameLine) {
|
822 | | - $frameLine = join('<span class="m"> </span>', explode("\xc0", $frameLine));
|
823 | | - $frameLine = join('<span class="m">▒</span>', explode("\xc1", $frameLine));
|
824 | | - $frameLine = join('<span class="p"> </span>', explode("\xa0", $frameLine));
|
825 | | - $frameLine = join('<span class="p">▒</span>', explode("\xa1", $frameLine));
|
826 | | - $frameLine = join('<span class="s">◇</span>', explode("\x84", $frameLine)); //format 0
|
827 | | - $frameLine = join('<span class="s">◆</span>', explode("\x85", $frameLine)); //format 1
|
828 | | - $frameLine = join('<span class="x">☢</span>', explode("\x81", $frameLine)); //special bit
|
829 | | - $frameLine = join('<span class="c"> </span>', explode("\x90", $frameLine)); //clock 0
|
830 | | - $frameLine = join('<span class="c">◷</span>', explode("\x91", $frameLine)); //clock 1
|
831 | | - $frameLine = join('<span class="f"> </span>', explode("\x88", $frameLine)); //version
|
832 | | - $frameLine = join('<span class="f">▒</span>', explode("\x89", $frameLine)); //version
|
833 | | - $frameLine = join('♦', explode("\x01", $frameLine));
|
834 | | - $frameLine = join('⋅', explode("\0", $frameLine));
|
835 | | - }
|
836 | | -
|
837 | | - ?>
|
838 | | - <style>
|
839 | | - .p { background-color: yellow; }
|
840 | | - .m { background-color: #00FF00; }
|
841 | | - .s { background-color: #FF0000; }
|
842 | | - .c { background-color: aqua; }
|
843 | | - .x { background-color: pink; }
|
844 | | - .f { background-color: gold; }
|
845 | | - </style>
|
846 | | - <?php
|
847 | | - echo "<pre><tt>";
|
848 | | - echo join("<br/ >", $frame);
|
849 | | - echo "</tt></pre>";
|
850 | | -
|
851 | | - }
|
852 | | - }
|
853 | | -
|
854 | | - //----------------------------------------------------------------------
|
855 | | - public static function serial($frame)
|
856 | | - {
|
857 | | - return gzcompress(join("\n", $frame), 9);
|
858 | | - }
|
859 | | -
|
860 | | - //----------------------------------------------------------------------
|
861 | | - public static function unserial($code)
|
862 | | - {
|
863 | | - return explode("\n", gzuncompress($code));
|
864 | | - }
|
865 | | -
|
866 | | - //----------------------------------------------------------------------
|
867 | | - public static function newFrame($version)
|
868 | | - {
|
869 | | - if($version < 1 || $version > QRSPEC_VERSION_MAX)
|
870 | | - return null;
|
871 | | -
|
872 | | - if(!isset(self::$frames[$version])) {
|
873 | | -
|
874 | | - $fileName = QR_CACHE_DIR.'frame_'.$version.'.dat';
|
875 | | -
|
876 | | - if (QR_CACHEABLE) {
|
877 | | - if (file_exists($fileName)) {
|
878 | | - self::$frames[$version] = self::unserial(file_get_contents($fileName));
|
879 | | - } else {
|
880 | | - self::$frames[$version] = self::createFrame($version);
|
881 | | - file_put_contents($fileName, self::serial(self::$frames[$version]));
|
882 | | - }
|
883 | | - } else {
|
884 | | - self::$frames[$version] = self::createFrame($version);
|
885 | | - }
|
886 | | - }
|
887 | | -
|
888 | | - if(is_null(self::$frames[$version]))
|
889 | | - return null;
|
890 | | -
|
891 | | - return self::$frames[$version];
|
892 | | - }
|
893 | | -
|
894 | | - //----------------------------------------------------------------------
|
895 | | - public static function rsBlockNum($spec) { return $spec[0] + $spec[3]; }
|
896 | | - public static function rsBlockNum1($spec) { return $spec[0]; }
|
897 | | - public static function rsDataCodes1($spec) { return $spec[1]; }
|
898 | | - public static function rsEccCodes1($spec) { return $spec[2]; }
|
899 | | - public static function rsBlockNum2($spec) { return $spec[3]; }
|
900 | | - public static function rsDataCodes2($spec) { return $spec[4]; }
|
901 | | - public static function rsEccCodes2($spec) { return $spec[2]; }
|
902 | | - public static function rsDataLength($spec) { return ($spec[0] * $spec[1]) + ($spec[3] * $spec[4]); }
|
903 | | - public static function rsEccLength($spec) { return ($spec[0] + $spec[3]) * $spec[2]; }
|
904 | | -
|
| 314 | + |
| 315 | +/* |
| 316 | + * PHP QR Code encoder |
| 317 | + * |
| 318 | + * QR Code specifications |
| 319 | + * |
| 320 | + * Based on libqrencode C library distributed under LGPL 2.1 |
| 321 | + * Copyright (C) 2006, 2007, 2008, 2009 Kentaro Fukuchi <fukuchi@megaui.net> |
| 322 | + * |
| 323 | + * PHP QR Code is distributed under LGPL 3 |
| 324 | + * Copyright (C) 2010 Dominik Dzienia <deltalab at poczta dot fm> |
| 325 | + * |
| 326 | + * The following data / specifications are taken from |
| 327 | + * "Two dimensional symbol -- QR-code -- Basic Specification" (JIS X0510:2004) |
| 328 | + * or |
| 329 | + * "Automatic identification and data capture techniques -- |
| 330 | + * QR Code 2005 bar code symbology specification" (ISO/IEC 18004:2006) |
| 331 | + * |
| 332 | + * This library is free software; you can redistribute it and/or |
| 333 | + * modify it under the terms of the GNU Lesser General Public |
| 334 | + * License as published by the Free Software Foundation; either |
| 335 | + * version 3 of the License, or any later version. |
| 336 | + * |
| 337 | + * This library is distributed in the hope that it will be useful, |
| 338 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 339 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 340 | + * Lesser General Public License for more details. |
| 341 | + * |
| 342 | + * You should have received a copy of the GNU Lesser General Public |
| 343 | + * License along with this library; if not, write to the Free Software |
| 344 | + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 345 | + */ |
| 346 | + |
| 347 | + define('QRSPEC_VERSION_MAX', 40); |
| 348 | + define('QRSPEC_WIDTH_MAX', 177); |
| 349 | + |
| 350 | + define('QRCAP_WIDTH', 0); |
| 351 | + define('QRCAP_WORDS', 1); |
| 352 | + define('QRCAP_REMINDER', 2); |
| 353 | + define('QRCAP_EC', 3); |
| 354 | + |
| 355 | + class QRspec { |
| 356 | + |
| 357 | + public static $capacity = array( |
| 358 | + array( 0, 0, 0, array( 0, 0, 0, 0)), |
| 359 | + array( 21, 26, 0, array( 7, 10, 13, 17)), // 1 |
| 360 | + array( 25, 44, 7, array( 10, 16, 22, 28)), |
| 361 | + array( 29, 70, 7, array( 15, 26, 36, 44)), |
| 362 | + array( 33, 100, 7, array( 20, 36, 52, 64)), |
| 363 | + array( 37, 134, 7, array( 26, 48, 72, 88)), // 5 |
| 364 | + array( 41, 172, 7, array( 36, 64, 96, 112)), |
| 365 | + array( 45, 196, 0, array( 40, 72, 108, 130)), |
| 366 | + array( 49, 242, 0, array( 48, 88, 132, 156)), |
| 367 | + array( 53, 292, 0, array( 60, 110, 160, 192)), |
| 368 | + array( 57, 346, 0, array( 72, 130, 192, 224)), //10 |
| 369 | + array( 61, 404, 0, array( 80, 150, 224, 264)), |
| 370 | + array( 65, 466, 0, array( 96, 176, 260, 308)), |
| 371 | + array( 69, 532, 0, array( 104, 198, 288, 352)), |
| 372 | + array( 73, 581, 3, array( 120, 216, 320, 384)), |
| 373 | + array( 77, 655, 3, array( 132, 240, 360, 432)), //15 |
| 374 | + array( 81, 733, 3, array( 144, 280, 408, 480)), |
| 375 | + array( 85, 815, 3, array( 168, 308, 448, 532)), |
| 376 | + array( 89, 901, 3, array( 180, 338, 504, 588)), |
| 377 | + array( 93, 991, 3, array( 196, 364, 546, 650)), |
| 378 | + array( 97, 1085, 3, array( 224, 416, 600, 700)), //20 |
| 379 | + array(101, 1156, 4, array( 224, 442, 644, 750)), |
| 380 | + array(105, 1258, 4, array( 252, 476, 690, 816)), |
| 381 | + array(109, 1364, 4, array( 270, 504, 750, 900)), |
| 382 | + array(113, 1474, 4, array( 300, 560, 810, 960)), |
| 383 | + array(117, 1588, 4, array( 312, 588, 870, 1050)), //25 |
| 384 | + array(121, 1706, 4, array( 336, 644, 952, 1110)), |
| 385 | + array(125, 1828, 4, array( 360, 700, 1020, 1200)), |
| 386 | + array(129, 1921, 3, array( 390, 728, 1050, 1260)), |
| 387 | + array(133, 2051, 3, array( 420, 784, 1140, 1350)), |
| 388 | + array(137, 2185, 3, array( 450, 812, 1200, 1440)), //30 |
| 389 | + array(141, 2323, 3, array( 480, 868, 1290, 1530)), |
| 390 | + array(145, 2465, 3, array( 510, 924, 1350, 1620)), |
| 391 | + array(149, 2611, 3, array( 540, 980, 1440, 1710)), |
| 392 | + array(153, 2761, 3, array( 570, 1036, 1530, 1800)), |
| 393 | + array(157, 2876, 0, array( 570, 1064, 1590, 1890)), //35 |
| 394 | + array(161, 3034, 0, array( 600, 1120, 1680, 1980)), |
| 395 | + array(165, 3196, 0, array( 630, 1204, 1770, 2100)), |
| 396 | + array(169, 3362, 0, array( 660, 1260, 1860, 2220)), |
| 397 | + array(173, 3532, 0, array( 720, 1316, 1950, 2310)), |
| 398 | + array(177, 3706, 0, array( 750, 1372, 2040, 2430)) //40 |
| 399 | + ); |
| 400 | + |
| 401 | + //---------------------------------------------------------------------- |
| 402 | + public static function getDataLength($version, $level) |
| 403 | + { |
| 404 | + return self::$capacity[$version][QRCAP_WORDS] - self::$capacity[$version][QRCAP_EC][$level]; |
| 405 | + } |
| 406 | + |
| 407 | + //---------------------------------------------------------------------- |
| 408 | + public static function getECCLength($version, $level) |
| 409 | + { |
| 410 | + return self::$capacity[$version][QRCAP_EC][$level]; |
| 411 | + } |
| 412 | + |
| 413 | + //---------------------------------------------------------------------- |
| 414 | + public static function getWidth($version) |
| 415 | + { |
| 416 | + return self::$capacity[$version][QRCAP_WIDTH]; |
| 417 | + } |
| 418 | + |
| 419 | + //---------------------------------------------------------------------- |
| 420 | + public static function getRemainder($version) |
| 421 | + { |
| 422 | + return self::$capacity[$version][QRCAP_REMINDER]; |
| 423 | + } |
| 424 | + |
| 425 | + //---------------------------------------------------------------------- |
| 426 | + public static function getMinimumVersion($size, $level) |
| 427 | + { |
| 428 | + |
| 429 | + for($i=1; $i<= QRSPEC_VERSION_MAX; $i++) { |
| 430 | + $words = self::$capacity[$i][QRCAP_WORDS] - self::$capacity[$i][QRCAP_EC][$level]; |
| 431 | + if($words >= $size) |
| 432 | + return $i; |
| 433 | + } |
| 434 | + |
| 435 | + return -1; |
| 436 | + } |
| 437 | + |
| 438 | + //###################################################################### |
| 439 | + |
| 440 | + public static $lengthTableBits = array( |
| 441 | + array(10, 12, 14), |
| 442 | + array( 9, 11, 13), |
| 443 | + array( 8, 16, 16), |
| 444 | + array( 8, 10, 12) |
| 445 | + ); |
| 446 | + |
| 447 | + //---------------------------------------------------------------------- |
| 448 | + public static function lengthIndicator($mode, $version) |
| 449 | + { |
| 450 | + if ($mode == QR_MODE_STRUCTURE) |
| 451 | + return 0; |
| 452 | + |
| 453 | + if ($version <= 9) { |
| 454 | + $l = 0; |
| 455 | + } else if ($version <= 26) { |
| 456 | + $l = 1; |
| 457 | + } else { |
| 458 | + $l = 2; |
| 459 | + } |
| 460 | + |
| 461 | + return self::$lengthTableBits[$mode][$l]; |
| 462 | + } |
| 463 | + |
| 464 | + //---------------------------------------------------------------------- |
| 465 | + public static function maximumWords($mode, $version) |
| 466 | + { |
| 467 | + if($mode == QR_MODE_STRUCTURE) |
| 468 | + return 3; |
| 469 | + |
| 470 | + if($version <= 9) { |
| 471 | + $l = 0; |
| 472 | + } else if($version <= 26) { |
| 473 | + $l = 1; |
| 474 | + } else { |
| 475 | + $l = 2; |
| 476 | + } |
| 477 | + |
| 478 | + $bits = self::$lengthTableBits[$mode][$l]; |
| 479 | + $words = (1 << $bits) - 1; |
| 480 | + |
| 481 | + if($mode == QR_MODE_KANJI) { |
| 482 | + $words *= 2; // the number of bytes is required |
| 483 | + } |
| 484 | + |
| 485 | + return $words; |
| 486 | + } |
| 487 | + |
| 488 | + // Error correction code ----------------------------------------------- |
| 489 | + // Table of the error correction code (Reed-Solomon block) |
| 490 | + // See Table 12-16 (pp.30-36), JIS X0510:2004. |
| 491 | + |
| 492 | + public static $eccTable = array( |
| 493 | + array(array( 0, 0), array( 0, 0), array( 0, 0), array( 0, 0)), |
| 494 | + array(array( 1, 0), array( 1, 0), array( 1, 0), array( 1, 0)), // 1 |
| 495 | + array(array( 1, 0), array( 1, 0), array( 1, 0), array( 1, 0)), |
| 496 | + array(array( 1, 0), array( 1, 0), array( 2, 0), array( 2, 0)), |
| 497 | + array(array( 1, 0), array( 2, 0), array( 2, 0), array( 4, 0)), |
| 498 | + array(array( 1, 0), array( 2, 0), array( 2, 2), array( 2, 2)), // 5 |
| 499 | + array(array( 2, 0), array( 4, 0), array( 4, 0), array( 4, 0)), |
| 500 | + array(array( 2, 0), array( 4, 0), array( 2, 4), array( 4, 1)), |
| 501 | + array(array( 2, 0), array( 2, 2), array( 4, 2), array( 4, 2)), |
| 502 | + array(array( 2, 0), array( 3, 2), array( 4, 4), array( 4, 4)), |
| 503 | + array(array( 2, 2), array( 4, 1), array( 6, 2), array( 6, 2)), //10 |
| 504 | + array(array( 4, 0), array( 1, 4), array( 4, 4), array( 3, 8)), |
| 505 | + array(array( 2, 2), array( 6, 2), array( 4, 6), array( 7, 4)), |
| 506 | + array(array( 4, 0), array( 8, 1), array( 8, 4), array(12, 4)), |
| 507 | + array(array( 3, 1), array( 4, 5), array(11, 5), array(11, 5)), |
| 508 | + array(array( 5, 1), array( 5, 5), array( 5, 7), array(11, 7)), //15 |
| 509 | + array(array( 5, 1), array( 7, 3), array(15, 2), array( 3, 13)), |
| 510 | + array(array( 1, 5), array(10, 1), array( 1, 15), array( 2, 17)), |
| 511 | + array(array( 5, 1), array( 9, 4), array(17, 1), array( 2, 19)), |
| 512 | + array(array( 3, 4), array( 3, 11), array(17, 4), array( 9, 16)), |
| 513 | + array(array( 3, 5), array( 3, 13), array(15, 5), array(15, 10)), //20 |
| 514 | + array(array( 4, 4), array(17, 0), array(17, 6), array(19, 6)), |
| 515 | + array(array( 2, 7), array(17, 0), array( 7, 16), array(34, 0)), |
| 516 | + array(array( 4, 5), array( 4, 14), array(11, 14), array(16, 14)), |
| 517 | + array(array( 6, 4), array( 6, 14), array(11, 16), array(30, 2)), |
| 518 | + array(array( 8, 4), array( 8, 13), array( 7, 22), array(22, 13)), //25 |
| 519 | + array(array(10, 2), array(19, 4), array(28, 6), array(33, 4)), |
| 520 | + array(array( 8, 4), array(22, 3), array( 8, 26), array(12, 28)), |
| 521 | + array(array( 3, 10), array( 3, 23), array( 4, 31), array(11, 31)), |
| 522 | + array(array( 7, 7), array(21, 7), array( 1, 37), array(19, 26)), |
| 523 | + array(array( 5, 10), array(19, 10), array(15, 25), array(23, 25)), //30 |
| 524 | + array(array(13, 3), array( 2, 29), array(42, 1), array(23, 28)), |
| 525 | + array(array(17, 0), array(10, 23), array(10, 35), array(19, 35)), |
| 526 | + array(array(17, 1), array(14, 21), array(29, 19), array(11, 46)), |
| 527 | + array(array(13, 6), array(14, 23), array(44, 7), array(59, 1)), |
| 528 | + array(array(12, 7), array(12, 26), array(39, 14), array(22, 41)), //35 |
| 529 | + array(array( 6, 14), array( 6, 34), array(46, 10), array( 2, 64)), |
| 530 | + array(array(17, 4), array(29, 14), array(49, 10), array(24, 46)), |
| 531 | + array(array( 4, 18), array(13, 32), array(48, 14), array(42, 32)), |
| 532 | + array(array(20, 4), array(40, 7), array(43, 22), array(10, 67)), |
| 533 | + array(array(19, 6), array(18, 31), array(34, 34), array(20, 61)),//40 |
| 534 | + ); |
| 535 | + |
| 536 | + //---------------------------------------------------------------------- |
| 537 | + // CACHEABLE!!! |
| 538 | + |
| 539 | + public static function getEccSpec($version, $level, array &$spec) |
| 540 | + { |
| 541 | + if (count($spec) < 5) { |
| 542 | + $spec = array(0,0,0,0,0); |
| 543 | + } |
| 544 | + |
| 545 | + $b1 = self::$eccTable[$version][$level][0]; |
| 546 | + $b2 = self::$eccTable[$version][$level][1]; |
| 547 | + $data = self::getDataLength($version, $level); |
| 548 | + $ecc = self::getECCLength($version, $level); |
| 549 | + |
| 550 | + if($b2 == 0) { |
| 551 | + $spec[0] = $b1; |
| 552 | + $spec[1] = (int)($data / $b1); |
| 553 | + $spec[2] = (int)($ecc / $b1); |
| 554 | + $spec[3] = 0; |
| 555 | + $spec[4] = 0; |
| 556 | + } else { |
| 557 | + $spec[0] = $b1; |
| 558 | + $spec[1] = (int)($data / ($b1 + $b2)); |
| 559 | + $spec[2] = (int)($ecc / ($b1 + $b2)); |
| 560 | + $spec[3] = $b2; |
| 561 | + $spec[4] = $spec[1] + 1; |
| 562 | + } |
| 563 | + } |
| 564 | + |
| 565 | + // Alignment pattern --------------------------------------------------- |
| 566 | + |
| 567 | + // Positions of alignment patterns. |
| 568 | + // This array includes only the second and the third position of the |
| 569 | + // alignment patterns. Rest of them can be calculated from the distance |
| 570 | + // between them. |
| 571 | + |
| 572 | + // See Table 1 in Appendix E (pp.71) of JIS X0510:2004. |
| 573 | + |
| 574 | + public static $alignmentPattern = array( |
| 575 | + array( 0, 0), |
| 576 | + array( 0, 0), array(18, 0), array(22, 0), array(26, 0), array(30, 0), // 1- 5 |
| 577 | + array(34, 0), array(22, 38), array(24, 42), array(26, 46), array(28, 50), // 6-10 |
| 578 | + array(30, 54), array(32, 58), array(34, 62), array(26, 46), array(26, 48), //11-15 |
| 579 | + array(26, 50), array(30, 54), array(30, 56), array(30, 58), array(34, 62), //16-20 |
| 580 | + array(28, 50), array(26, 50), array(30, 54), array(28, 54), array(32, 58), //21-25 |
| 581 | + array(30, 58), array(34, 62), array(26, 50), array(30, 54), array(26, 52), //26-30 |
| 582 | + array(30, 56), array(34, 60), array(30, 58), array(34, 62), array(30, 54), //31-35 |
| 583 | + array(24, 50), array(28, 54), array(32, 58), array(26, 54), array(30, 58), //35-40 |
| 584 | + ); |
| 585 | + |
| 586 | + |
| 587 | + /** -------------------------------------------------------------------- |
| 588 | + * Put an alignment marker. |
| 589 | + * @param frame |
| 590 | + * @param width |
| 591 | + * @param ox,oy center coordinate of the pattern |
| 592 | + */ |
| 593 | + public static function putAlignmentMarker(array &$frame, $ox, $oy) |
| 594 | + { |
| 595 | + $finder = array( |
| 596 | + "\xa1\xa1\xa1\xa1\xa1", |
| 597 | + "\xa1\xa0\xa0\xa0\xa1", |
| 598 | + "\xa1\xa0\xa1\xa0\xa1", |
| 599 | + "\xa1\xa0\xa0\xa0\xa1", |
| 600 | + "\xa1\xa1\xa1\xa1\xa1" |
| 601 | + ); |
| 602 | + |
| 603 | + $yStart = $oy-2; |
| 604 | + $xStart = $ox-2; |
| 605 | + |
| 606 | + for($y=0; $y<5; $y++) { |
| 607 | + QRstr::set($frame, $xStart, $yStart+$y, $finder[$y]); |
| 608 | + } |
| 609 | + } |
| 610 | + |
| 611 | + //---------------------------------------------------------------------- |
| 612 | + public static function putAlignmentPattern($version, &$frame, $width) |
| 613 | + { |
| 614 | + if($version < 2) |
| 615 | + return; |
| 616 | + |
| 617 | + $d = self::$alignmentPattern[$version][1] - self::$alignmentPattern[$version][0]; |
| 618 | + if($d < 0) { |
| 619 | + $w = 2; |
| 620 | + } else { |
| 621 | + $w = (int)(($width - self::$alignmentPattern[$version][0]) / $d + 2); |
| 622 | + } |
| 623 | + |
| 624 | + if($w * $w - 3 == 1) { |
| 625 | + $x = self::$alignmentPattern[$version][0]; |
| 626 | + $y = self::$alignmentPattern[$version][0]; |
| 627 | + self::putAlignmentMarker($frame, $x, $y); |
| 628 | + return; |
| 629 | + } |
| 630 | + |
| 631 | + $cx = self::$alignmentPattern[$version][0]; |
| 632 | + for($x=1; $x<$w - 1; $x++) { |
| 633 | + self::putAlignmentMarker($frame, 6, $cx); |
| 634 | + self::putAlignmentMarker($frame, $cx, 6); |
| 635 | + $cx += $d; |
| 636 | + } |
| 637 | + |
| 638 | + $cy = self::$alignmentPattern[$version][0]; |
| 639 | + for($y=0; $y<$w-1; $y++) { |
| 640 | + $cx = self::$alignmentPattern[$version][0]; |
| 641 | + for($x=0; $x<$w-1; $x++) { |
| 642 | + self::putAlignmentMarker($frame, $cx, $cy); |
| 643 | + $cx += $d; |
| 644 | + } |
| 645 | + $cy += $d; |
| 646 | + } |
| 647 | + } |
| 648 | + |
| 649 | + // Version information pattern ----------------------------------------- |
| 650 | + |
| 651 | + // Version information pattern (BCH coded). |
| 652 | + // See Table 1 in Appendix D (pp.68) of JIS X0510:2004. |
| 653 | + |
| 654 | + // size: [QRSPEC_VERSION_MAX - 6] |
| 655 | + |
| 656 | + public static $versionPattern = array( |
| 657 | + 0x07c94, 0x085bc, 0x09a99, 0x0a4d3, 0x0bbf6, 0x0c762, 0x0d847, 0x0e60d, |
| 658 | + 0x0f928, 0x10b78, 0x1145d, 0x12a17, 0x13532, 0x149a6, 0x15683, 0x168c9, |
| 659 | + 0x177ec, 0x18ec4, 0x191e1, 0x1afab, 0x1b08e, 0x1cc1a, 0x1d33f, 0x1ed75, |
| 660 | + 0x1f250, 0x209d5, 0x216f0, 0x228ba, 0x2379f, 0x24b0b, 0x2542e, 0x26a64, |
| 661 | + 0x27541, 0x28c69 |
| 662 | + ); |
| 663 | + |
| 664 | + //---------------------------------------------------------------------- |
| 665 | + public static function getVersionPattern($version) |
| 666 | + { |
| 667 | + if($version < 7 || $version > QRSPEC_VERSION_MAX) |
| 668 | + return 0; |
| 669 | + |
| 670 | + return self::$versionPattern[$version -7]; |
| 671 | + } |
| 672 | + |
| 673 | + // Format information -------------------------------------------------- |
| 674 | + // See calcFormatInfo in tests/test_qrspec.c (orginal qrencode c lib) |
| 675 | + |
| 676 | + public static $formatInfo = array( |
| 677 | + array(0x77c4, 0x72f3, 0x7daa, 0x789d, 0x662f, 0x6318, 0x6c41, 0x6976), |
| 678 | + array(0x5412, 0x5125, 0x5e7c, 0x5b4b, 0x45f9, 0x40ce, 0x4f97, 0x4aa0), |
| 679 | + array(0x355f, 0x3068, 0x3f31, 0x3a06, 0x24b4, 0x2183, 0x2eda, 0x2bed), |
| 680 | + array(0x1689, 0x13be, 0x1ce7, 0x19d0, 0x0762, 0x0255, 0x0d0c, 0x083b) |
| 681 | + ); |
| 682 | + |
| 683 | + public static function getFormatInfo($mask, $level) |
| 684 | + { |
| 685 | + if($mask < 0 || $mask > 7) |
| 686 | + return 0; |
| 687 | + |
| 688 | + if($level < 0 || $level > 3) |
| 689 | + return 0; |
| 690 | + |
| 691 | + return self::$formatInfo[$level][$mask]; |
| 692 | + } |
| 693 | + |
| 694 | + // Frame --------------------------------------------------------------- |
| 695 | + // Cache of initial frames. |
| 696 | + |
| 697 | + public static $frames = array(); |
| 698 | + |
| 699 | + /** -------------------------------------------------------------------- |
| 700 | + * Put a finder pattern. |
| 701 | + * @param frame |
| 702 | + * @param width |
| 703 | + * @param ox,oy upper-left coordinate of the pattern |
| 704 | + */ |
| 705 | + public static function putFinderPattern(&$frame, $ox, $oy) |
| 706 | + { |
| 707 | + $finder = array( |
| 708 | + "\xc1\xc1\xc1\xc1\xc1\xc1\xc1", |
| 709 | + "\xc1\xc0\xc0\xc0\xc0\xc0\xc1", |
| 710 | + "\xc1\xc0\xc1\xc1\xc1\xc0\xc1", |
| 711 | + "\xc1\xc0\xc1\xc1\xc1\xc0\xc1", |
| 712 | + "\xc1\xc0\xc1\xc1\xc1\xc0\xc1", |
| 713 | + "\xc1\xc0\xc0\xc0\xc0\xc0\xc1", |
| 714 | + "\xc1\xc1\xc1\xc1\xc1\xc1\xc1" |
| 715 | + ); |
| 716 | + |
| 717 | + for($y=0; $y<7; $y++) { |
| 718 | + QRstr::set($frame, $ox, $oy+$y, $finder[$y]); |
| 719 | + } |
| 720 | + } |
| 721 | + |
| 722 | + //---------------------------------------------------------------------- |
| 723 | + public static function createFrame($version) |
| 724 | + { |
| 725 | + $width = self::$capacity[$version][QRCAP_WIDTH]; |
| 726 | + $frameLine = str_repeat ("\0", $width); |
| 727 | + $frame = array_fill(0, $width, $frameLine); |
| 728 | + |
| 729 | + // Finder pattern |
| 730 | + self::putFinderPattern($frame, 0, 0); |
| 731 | + self::putFinderPattern($frame, $width - 7, 0); |
| 732 | + self::putFinderPattern($frame, 0, $width - 7); |
| 733 | + |
| 734 | + // Separator |
| 735 | + $yOffset = $width - 7; |
| 736 | + |
| 737 | + for($y=0; $y<7; $y++) { |
| 738 | + $frame[$y][7] = "\xc0"; |
| 739 | + $frame[$y][$width - 8] = "\xc0"; |
| 740 | + $frame[$yOffset][7] = "\xc0"; |
| 741 | + $yOffset++; |
| 742 | + } |
| 743 | + |
| 744 | + $setPattern = str_repeat("\xc0", 8); |
| 745 | + |
| 746 | + QRstr::set($frame, 0, 7, $setPattern); |
| 747 | + QRstr::set($frame, $width-8, 7, $setPattern); |
| 748 | + QRstr::set($frame, 0, $width - 8, $setPattern); |
| 749 | + |
| 750 | + // Format info |
| 751 | + $setPattern = str_repeat("\x84", 9); |
| 752 | + QRstr::set($frame, 0, 8, $setPattern); |
| 753 | + QRstr::set($frame, $width - 8, 8, $setPattern, 8); |
| 754 | + |
| 755 | + $yOffset = $width - 8; |
| 756 | + |
| 757 | + for($y=0; $y<8; $y++,$yOffset++) { |
| 758 | + $frame[$y][8] = "\x84"; |
| 759 | + $frame[$yOffset][8] = "\x84"; |
| 760 | + } |
| 761 | + |
| 762 | + // Timing pattern |
| 763 | + |
| 764 | + for($i=1; $i<$width-15; $i++) { |
| 765 | + $frame[6][7+$i] = chr(0x90 | ($i & 1)); |
| 766 | + $frame[7+$i][6] = chr(0x90 | ($i & 1)); |
| 767 | + } |
| 768 | + |
| 769 | + // Alignment pattern |
| 770 | + self::putAlignmentPattern($version, $frame, $width); |
| 771 | + |
| 772 | + // Version information |
| 773 | + if($version >= 7) { |
| 774 | + $vinf = self::getVersionPattern($version); |
| 775 | + |
| 776 | + $v = $vinf; |
| 777 | + |
| 778 | + for($x=0; $x<6; $x++) { |
| 779 | + for($y=0; $y<3; $y++) { |
| 780 | + $frame[($width - 11)+$y][$x] = chr(0x88 | ($v & 1)); |
| 781 | + $v = $v >> 1; |
| 782 | + } |
| 783 | + } |
| 784 | + |
| 785 | + $v = $vinf; |
| 786 | + for($y=0; $y<6; $y++) { |
| 787 | + for($x=0; $x<3; $x++) { |
| 788 | + $frame[$y][$x+($width - 11)] = chr(0x88 | ($v & 1)); |
| 789 | + $v = $v >> 1; |
| 790 | + } |
| 791 | + } |
| 792 | + } |
| 793 | + |
| 794 | + // and a little bit... |
| 795 | + $frame[$width - 8][8] = "\x81"; |
| 796 | + |
| 797 | + return $frame; |
| 798 | + } |
| 799 | + |
| 800 | + //---------------------------------------------------------------------- |
| 801 | + public static function debug($frame, $binary_mode = false) |
| 802 | + { |
| 803 | + if ($binary_mode) { |
| 804 | + |
| 805 | + foreach ($frame as &$frameLine) { |
| 806 | + $frameLine = join('<span class="m"> </span>', explode('0', $frameLine)); |
| 807 | + $frameLine = join('██', explode('1', $frameLine)); |
| 808 | + } |
| 809 | + |
| 810 | + ?> |
| 811 | + <style> |
| 812 | + .m { background-color: white; } |
| 813 | + </style> |
| 814 | + <?php |
| 815 | + echo '<pre><tt><br/ ><br/ ><br/ > '; |
| 816 | + echo join("<br/ > ", $frame); |
| 817 | + echo '</tt></pre><br/ ><br/ ><br/ ><br/ ><br/ ><br/ >'; |
| 818 | + |
| 819 | + } else { |
| 820 | + |
| 821 | + foreach ($frame as &$frameLine) { |
| 822 | + $frameLine = join('<span class="m"> </span>', explode("\xc0", $frameLine)); |
| 823 | + $frameLine = join('<span class="m">▒</span>', explode("\xc1", $frameLine)); |
| 824 | + $frameLine = join('<span class="p"> </span>', explode("\xa0", $frameLine)); |
| 825 | + $frameLine = join('<span class="p">▒</span>', explode("\xa1", $frameLine)); |
| 826 | + $frameLine = join('<span class="s">◇</span>', explode("\x84", $frameLine)); //format 0 |
| 827 | + $frameLine = join('<span class="s">◆</span>', explode("\x85", $frameLine)); //format 1 |
| 828 | + $frameLine = join('<span class="x">☢</span>', explode("\x81", $frameLine)); //special bit |
| 829 | + $frameLine = join('<span class="c"> </span>', explode("\x90", $frameLine)); //clock 0 |
| 830 | + $frameLine = join('<span class="c">◷</span>', explode("\x91", $frameLine)); //clock 1 |
| 831 | + $frameLine = join('<span class="f"> </span>', explode("\x88", $frameLine)); //version |
| 832 | + $frameLine = join('<span class="f">▒</span>', explode("\x89", $frameLine)); //version |
| 833 | + $frameLine = join('♦', explode("\x01", $frameLine)); |
| 834 | + $frameLine = join('⋅', explode("\0", $frameLine)); |
| 835 | + } |
| 836 | + |
| 837 | + ?> |
| 838 | + <style> |
| 839 | + .p { background-color: yellow; } |
| 840 | + .m { background-color: #00FF00; } |
| 841 | + .s { background-color: #FF0000; } |
| 842 | + .c { background-color: aqua; } |
| 843 | + .x { background-color: pink; } |
| 844 | + .f { background-color: gold; } |
| 845 | + </style> |
| 846 | + <?php |
| 847 | + echo "<pre><tt>"; |
| 848 | + echo join("<br/ >", $frame); |
| 849 | + echo "</tt></pre>"; |
| 850 | + |
| 851 | + } |
| 852 | + } |
| 853 | + |
| 854 | + //---------------------------------------------------------------------- |
| 855 | + public static function serial($frame) |
| 856 | + { |
| 857 | + return gzcompress(join("\n", $frame), 9); |
| 858 | + } |
| 859 | + |
| 860 | + //---------------------------------------------------------------------- |
| 861 | + public static function unserial($code) |
| 862 | + { |
| 863 | + return explode("\n", gzuncompress($code)); |
| 864 | + } |
| 865 | + |
| 866 | + //---------------------------------------------------------------------- |
| 867 | + public static function newFrame($version) |
| 868 | + { |
| 869 | + if($version < 1 || $version > QRSPEC_VERSION_MAX) |
| 870 | + return null; |
| 871 | + |
| 872 | + if(!isset(self::$frames[$version])) { |
| 873 | + |
| 874 | + $fileName = QR_CACHE_DIR.'frame_'.$version.'.dat'; |
| 875 | + |
| 876 | + if (QR_CACHEABLE) { |
| 877 | + if (file_exists($fileName)) { |
| 878 | + self::$frames[$version] = self::unserial(file_get_contents($fileName)); |
| 879 | + } else { |
| 880 | + self::$frames[$version] = self::createFrame($version); |
| 881 | + file_put_contents($fileName, self::serial(self::$frames[$version])); |
| 882 | + } |
| 883 | + } else { |
| 884 | + self::$frames[$version] = self::createFrame($version); |
| 885 | + } |
| 886 | + } |
| 887 | + |
| 888 | + if(is_null(self::$frames[$version])) |
| 889 | + return null; |
| 890 | + |
| 891 | + return self::$frames[$version]; |
| 892 | + } |
| 893 | + |
| 894 | + //---------------------------------------------------------------------- |
| 895 | + public static function rsBlockNum($spec) { return $spec[0] + $spec[3]; } |
| 896 | + public static function rsBlockNum1($spec) { return $spec[0]; } |
| 897 | + public static function rsDataCodes1($spec) { return $spec[1]; } |
| 898 | + public static function rsEccCodes1($spec) { return $spec[2]; } |
| 899 | + public static function rsBlockNum2($spec) { return $spec[3]; } |
| 900 | + public static function rsDataCodes2($spec) { return $spec[4]; } |
| 901 | + public static function rsEccCodes2($spec) { return $spec[2]; } |
| 902 | + public static function rsDataLength($spec) { return ($spec[0] * $spec[1]) + ($spec[3] * $spec[4]); } |
| 903 | + public static function rsEccLength($spec) { return ($spec[0] + $spec[3]) * $spec[2]; } |
| 904 | + |
905 | 905 | } |
906 | 906 | |
907 | 907 | |
— | — | @@ -909,100 +909,100 @@ |
910 | 910 | |
911 | 911 | |
912 | 912 | |
913 | | -
|
914 | | -/*
|
915 | | - * PHP QR Code encoder
|
916 | | - *
|
917 | | - * Image output of code using GD2
|
918 | | - *
|
919 | | - * PHP QR Code is distributed under LGPL 3
|
920 | | - * Copyright (C) 2010 Dominik Dzienia <deltalab at poczta dot fm>
|
921 | | - *
|
922 | | - * This library is free software; you can redistribute it and/or
|
923 | | - * modify it under the terms of the GNU Lesser General Public
|
924 | | - * License as published by the Free Software Foundation; either
|
925 | | - * version 3 of the License, or any later version.
|
926 | | - *
|
927 | | - * This library is distributed in the hope that it will be useful,
|
928 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
929 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
930 | | - * Lesser General Public License for more details.
|
931 | | - *
|
932 | | - * You should have received a copy of the GNU Lesser General Public
|
933 | | - * License along with this library; if not, write to the Free Software
|
934 | | - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
935 | | - */
|
936 | | -
|
937 | | - define('QR_IMAGE', true);
|
938 | | -
|
939 | | - class QRimage {
|
940 | | -
|
941 | | - //----------------------------------------------------------------------
|
942 | | - public static function png($frame, $filename = false, $pixelPerPoint = 4, $outerFrame = 4,$saveandprint=FALSE)
|
943 | | - {
|
944 | | - $image = self::image($frame, $pixelPerPoint, $outerFrame);
|
945 | | -
|
946 | | - if ($filename === false) {
|
947 | | - Header("Content-type: image/png");
|
948 | | - ImagePng($image);
|
949 | | - } else {
|
950 | | - if($saveandprint===TRUE){
|
951 | | - ImagePng($image, $filename);
|
952 | | - header("Content-type: image/png");
|
953 | | - ImagePng($image);
|
954 | | - }else{
|
955 | | - ImagePng($image, $filename);
|
956 | | - }
|
957 | | - }
|
958 | | -
|
959 | | - ImageDestroy($image);
|
960 | | - }
|
961 | | -
|
962 | | - //----------------------------------------------------------------------
|
963 | | - public static function jpg($frame, $filename = false, $pixelPerPoint = 8, $outerFrame = 4, $q = 85)
|
964 | | - {
|
965 | | - $image = self::image($frame, $pixelPerPoint, $outerFrame);
|
966 | | -
|
967 | | - if ($filename === false) {
|
968 | | - Header("Content-type: image/jpeg");
|
969 | | - ImageJpeg($image, null, $q);
|
970 | | - } else {
|
971 | | - ImageJpeg($image, $filename, $q);
|
972 | | - }
|
973 | | -
|
974 | | - ImageDestroy($image);
|
975 | | - }
|
976 | | -
|
977 | | - //----------------------------------------------------------------------
|
978 | | - private static function image($frame, $pixelPerPoint = 4, $outerFrame = 4)
|
979 | | - {
|
980 | | - $h = count($frame);
|
981 | | - $w = strlen($frame[0]);
|
982 | | -
|
983 | | - $imgW = $w + 2*$outerFrame;
|
984 | | - $imgH = $h + 2*$outerFrame;
|
985 | | -
|
986 | | - $base_image =ImageCreate($imgW, $imgH);
|
987 | | -
|
988 | | - $col[0] = ImageColorAllocate($base_image,255,255,255);
|
989 | | - $col[1] = ImageColorAllocate($base_image,0,0,0);
|
990 | | -
|
991 | | - imagefill($base_image, 0, 0, $col[0]);
|
992 | | -
|
993 | | - for($y=0; $y<$h; $y++) {
|
994 | | - for($x=0; $x<$w; $x++) {
|
995 | | - if ($frame[$y][$x] == '1') {
|
996 | | - ImageSetPixel($base_image,$x+$outerFrame,$y+$outerFrame,$col[1]);
|
997 | | - }
|
998 | | - }
|
999 | | - }
|
1000 | | -
|
1001 | | - $target_image =ImageCreate($imgW * $pixelPerPoint, $imgH * $pixelPerPoint);
|
1002 | | - ImageCopyResized($target_image, $base_image, 0, 0, 0, 0, $imgW * $pixelPerPoint, $imgH * $pixelPerPoint, $imgW, $imgH);
|
1003 | | - ImageDestroy($base_image);
|
1004 | | -
|
1005 | | - return $target_image;
|
1006 | | - }
|
| 913 | + |
| 914 | +/* |
| 915 | + * PHP QR Code encoder |
| 916 | + * |
| 917 | + * Image output of code using GD2 |
| 918 | + * |
| 919 | + * PHP QR Code is distributed under LGPL 3 |
| 920 | + * Copyright (C) 2010 Dominik Dzienia <deltalab at poczta dot fm> |
| 921 | + * |
| 922 | + * This library is free software; you can redistribute it and/or |
| 923 | + * modify it under the terms of the GNU Lesser General Public |
| 924 | + * License as published by the Free Software Foundation; either |
| 925 | + * version 3 of the License, or any later version. |
| 926 | + * |
| 927 | + * This library is distributed in the hope that it will be useful, |
| 928 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 929 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 930 | + * Lesser General Public License for more details. |
| 931 | + * |
| 932 | + * You should have received a copy of the GNU Lesser General Public |
| 933 | + * License along with this library; if not, write to the Free Software |
| 934 | + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 935 | + */ |
| 936 | + |
| 937 | + define('QR_IMAGE', true); |
| 938 | + |
| 939 | + class QRimage { |
| 940 | + |
| 941 | + //---------------------------------------------------------------------- |
| 942 | + public static function png($frame, $filename = false, $pixelPerPoint = 4, $outerFrame = 4,$saveandprint=FALSE) |
| 943 | + { |
| 944 | + $image = self::image($frame, $pixelPerPoint, $outerFrame); |
| 945 | + |
| 946 | + if ($filename === false) { |
| 947 | + Header("Content-type: image/png"); |
| 948 | + ImagePng($image); |
| 949 | + } else { |
| 950 | + if($saveandprint===TRUE){ |
| 951 | + ImagePng($image, $filename); |
| 952 | + header("Content-type: image/png"); |
| 953 | + ImagePng($image); |
| 954 | + }else{ |
| 955 | + ImagePng($image, $filename); |
| 956 | + } |
| 957 | + } |
| 958 | + |
| 959 | + ImageDestroy($image); |
| 960 | + } |
| 961 | + |
| 962 | + //---------------------------------------------------------------------- |
| 963 | + public static function jpg($frame, $filename = false, $pixelPerPoint = 8, $outerFrame = 4, $q = 85) |
| 964 | + { |
| 965 | + $image = self::image($frame, $pixelPerPoint, $outerFrame); |
| 966 | + |
| 967 | + if ($filename === false) { |
| 968 | + Header("Content-type: image/jpeg"); |
| 969 | + ImageJpeg($image, null, $q); |
| 970 | + } else { |
| 971 | + ImageJpeg($image, $filename, $q); |
| 972 | + } |
| 973 | + |
| 974 | + ImageDestroy($image); |
| 975 | + } |
| 976 | + |
| 977 | + //---------------------------------------------------------------------- |
| 978 | + private static function image($frame, $pixelPerPoint = 4, $outerFrame = 4) |
| 979 | + { |
| 980 | + $h = count($frame); |
| 981 | + $w = strlen($frame[0]); |
| 982 | + |
| 983 | + $imgW = $w + 2*$outerFrame; |
| 984 | + $imgH = $h + 2*$outerFrame; |
| 985 | + |
| 986 | + $base_image =ImageCreate($imgW, $imgH); |
| 987 | + |
| 988 | + $col[0] = ImageColorAllocate($base_image,255,255,255); |
| 989 | + $col[1] = ImageColorAllocate($base_image,0,0,0); |
| 990 | + |
| 991 | + imagefill($base_image, 0, 0, $col[0]); |
| 992 | + |
| 993 | + for($y=0; $y<$h; $y++) { |
| 994 | + for($x=0; $x<$w; $x++) { |
| 995 | + if ($frame[$y][$x] == '1') { |
| 996 | + ImageSetPixel($base_image,$x+$outerFrame,$y+$outerFrame,$col[1]); |
| 997 | + } |
| 998 | + } |
| 999 | + } |
| 1000 | + |
| 1001 | + $target_image =ImageCreate($imgW * $pixelPerPoint, $imgH * $pixelPerPoint); |
| 1002 | + ImageCopyResized($target_image, $base_image, 0, 0, 0, 0, $imgW * $pixelPerPoint, $imgH * $pixelPerPoint, $imgW, $imgH); |
| 1003 | + ImageDestroy($base_image); |
| 1004 | + |
| 1005 | + return $target_image; |
| 1006 | + } |
1007 | 1007 | } |
1008 | 1008 | |
1009 | 1009 | |
— | — | @@ -1011,1240 +1011,1235 @@ |
1012 | 1012 | |
1013 | 1013 | |
1014 | 1014 | |
1015 | | -
|
1016 | | -/*
|
1017 | | - * PHP QR Code encoder
|
1018 | | - *
|
1019 | | - * Input encoding class
|
1020 | | - *
|
1021 | | - * Based on libqrencode C library distributed under LGPL 2.1
|
1022 | | - * Copyright (C) 2006, 2007, 2008, 2009 Kentaro Fukuchi <fukuchi@megaui.net>
|
1023 | | - *
|
1024 | | - * PHP QR Code is distributed under LGPL 3
|
1025 | | - * Copyright (C) 2010 Dominik Dzienia <deltalab at poczta dot fm>
|
1026 | | - *
|
1027 | | - * This library is free software; you can redistribute it and/or
|
1028 | | - * modify it under the terms of the GNU Lesser General Public
|
1029 | | - * License as published by the Free Software Foundation; either
|
1030 | | - * version 3 of the License, or any later version.
|
1031 | | - *
|
1032 | | - * This library is distributed in the hope that it will be useful,
|
1033 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
1034 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
1035 | | - * Lesser General Public License for more details.
|
1036 | | - *
|
1037 | | - * You should have received a copy of the GNU Lesser General Public
|
1038 | | - * License along with this library; if not, write to the Free Software
|
1039 | | - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
1040 | | - */
|
1041 | | -
|
1042 | | - define('STRUCTURE_HEADER_BITS', 20);
|
1043 | | - define('MAX_STRUCTURED_SYMBOLS', 16);
|
1044 | | -
|
1045 | | - class QRinputItem {
|
1046 | | -
|
1047 | | - public $mode;
|
1048 | | - public $size;
|
1049 | | - public $data;
|
1050 | | - public $bstream;
|
1051 | | -
|
1052 | | - public function __construct($mode, $size, $data, $bstream = null)
|
1053 | | - {
|
1054 | | - $setData = array_slice($data, 0, $size);
|
1055 | | -
|
1056 | | - if (count($setData) < $size) {
|
1057 | | - $setData = array_merge($setData, array_fill(0,$size-count($setData),0));
|
1058 | | - }
|
1059 | | -
|
1060 | | - if(!QRinput::check($mode, $size, $setData)) {
|
1061 | | - throw new Exception('Error m:'.$mode.',s:'.$size.',d:'.join(',',$setData));
|
1062 | | - return null;
|
1063 | | - }
|
1064 | | -
|
1065 | | - $this->mode = $mode;
|
1066 | | - $this->size = $size;
|
1067 | | - $this->data = $setData;
|
1068 | | - $this->bstream = $bstream;
|
1069 | | - }
|
1070 | | -
|
1071 | | - //----------------------------------------------------------------------
|
1072 | | - public function encodeModeNum($version)
|
1073 | | - {
|
1074 | | - try {
|
1075 | | -
|
1076 | | - $words = (int)($this->size / 3);
|
1077 | | - $bs = new QRbitstream();
|
1078 | | -
|
1079 | | - $val = 0x1;
|
1080 | | - $bs->appendNum(4, $val);
|
1081 | | - $bs->appendNum(QRspec::lengthIndicator(QR_MODE_NUM, $version), $this->size);
|
1082 | | -
|
1083 | | - for($i=0; $i<$words; $i++) {
|
1084 | | - $val = (ord($this->data[$i*3 ]) - ord('0')) * 100;
|
1085 | | - $val += (ord($this->data[$i*3+1]) - ord('0')) * 10;
|
1086 | | - $val += (ord($this->data[$i*3+2]) - ord('0'));
|
1087 | | - $bs->appendNum(10, $val);
|
1088 | | - }
|
1089 | | -
|
1090 | | - if($this->size - $words * 3 == 1) {
|
1091 | | - $val = ord($this->data[$words*3]) - ord('0');
|
1092 | | - $bs->appendNum(4, $val);
|
1093 | | - } else if($this->size - $words * 3 == 2) {
|
1094 | | - $val = (ord($this->data[$words*3 ]) - ord('0')) * 10;
|
1095 | | - $val += (ord($this->data[$words*3+1]) - ord('0'));
|
1096 | | - $bs->appendNum(7, $val);
|
1097 | | - }
|
1098 | | -
|
1099 | | - $this->bstream = $bs;
|
1100 | | - return 0;
|
1101 | | -
|
1102 | | - } catch (Exception $e) {
|
1103 | | - return -1;
|
1104 | | - }
|
1105 | | - }
|
1106 | | -
|
1107 | | - //----------------------------------------------------------------------
|
1108 | | - public function encodeModeAn($version)
|
1109 | | - {
|
1110 | | - try {
|
1111 | | - $words = (int)($this->size / 2);
|
1112 | | - $bs = new QRbitstream();
|
1113 | | -
|
1114 | | - $bs->appendNum(4, 0x02);
|
1115 | | - $bs->appendNum(QRspec::lengthIndicator(QR_MODE_AN, $version), $this->size);
|
1116 | | -
|
1117 | | - for($i=0; $i<$words; $i++) {
|
1118 | | - $val = (int)QRinput::lookAnTable(ord($this->data[$i*2 ])) * 45;
|
1119 | | - $val += (int)QRinput::lookAnTable(ord($this->data[$i*2+1]));
|
1120 | | -
|
1121 | | - $bs->appendNum(11, $val);
|
1122 | | - }
|
1123 | | -
|
1124 | | - if($this->size & 1) {
|
1125 | | - $val = QRinput::lookAnTable(ord($this->data[$words * 2]));
|
1126 | | - $bs->appendNum(6, $val);
|
1127 | | - }
|
1128 | | -
|
1129 | | - $this->bstream = $bs;
|
1130 | | - return 0;
|
1131 | | -
|
1132 | | - } catch (Exception $e) {
|
1133 | | - return -1;
|
1134 | | - }
|
1135 | | - }
|
1136 | | -
|
1137 | | - //----------------------------------------------------------------------
|
1138 | | - public function encodeMode8($version)
|
1139 | | - {
|
1140 | | - try {
|
1141 | | - $bs = new QRbitstream();
|
1142 | | -
|
1143 | | - $bs->appendNum(4, 0x4);
|
1144 | | - $bs->appendNum(QRspec::lengthIndicator(QR_MODE_8, $version), $this->size);
|
1145 | | -
|
1146 | | - for($i=0; $i<$this->size; $i++) {
|
1147 | | - $bs->appendNum(8, ord($this->data[$i]));
|
1148 | | - }
|
1149 | | -
|
1150 | | - $this->bstream = $bs;
|
1151 | | - return 0;
|
1152 | | -
|
1153 | | - } catch (Exception $e) {
|
1154 | | - return -1;
|
1155 | | - }
|
1156 | | - }
|
1157 | | -
|
1158 | | - //----------------------------------------------------------------------
|
1159 | | - public function encodeModeKanji($version)
|
1160 | | - {
|
1161 | | - try {
|
1162 | | -
|
1163 | | - $bs = new QRbitrtream();
|
1164 | | -
|
1165 | | - $bs->appendNum(4, 0x8);
|
1166 | | - $bs->appendNum(QRspec::lengthIndicator(QR_MODE_KANJI, $version), (int)($this->size / 2));
|
1167 | | -
|
1168 | | - for($i=0; $i<$this->size; $i+=2) {
|
1169 | | - $val = (ord($this->data[$i]) << 8) | ord($this->data[$i+1]);
|
1170 | | - if($val <= 0x9ffc) {
|
1171 | | - $val -= 0x8140;
|
1172 | | - } else {
|
1173 | | - $val -= 0xc140;
|
1174 | | - }
|
1175 | | -
|
1176 | | - $h = ($val >> 8) * 0xc0;
|
1177 | | - $val = ($val & 0xff) + $h;
|
1178 | | -
|
1179 | | - $bs->appendNum(13, $val);
|
1180 | | - }
|
1181 | | -
|
1182 | | - $this->bstream = $bs;
|
1183 | | - return 0;
|
1184 | | -
|
1185 | | - } catch (Exception $e) {
|
1186 | | - return -1;
|
1187 | | - }
|
1188 | | - }
|
1189 | | -
|
1190 | | - //----------------------------------------------------------------------
|
1191 | | - public function encodeModeStructure()
|
1192 | | - {
|
1193 | | - try {
|
1194 | | - $bs = new QRbitstream();
|
1195 | | -
|
1196 | | - $bs->appendNum(4, 0x03);
|
1197 | | - $bs->appendNum(4, ord($this->data[1]) - 1);
|
1198 | | - $bs->appendNum(4, ord($this->data[0]) - 1);
|
1199 | | - $bs->appendNum(8, ord($this->data[2]));
|
1200 | | -
|
1201 | | - $this->bstream = $bs;
|
1202 | | - return 0;
|
1203 | | -
|
1204 | | - } catch (Exception $e) {
|
1205 | | - return -1;
|
1206 | | - }
|
1207 | | - }
|
1208 | | -
|
1209 | | - //----------------------------------------------------------------------
|
1210 | | - public function estimateBitStreamSizeOfEntry($version)
|
1211 | | - {
|
1212 | | - $bits = 0;
|
1213 | | -
|
1214 | | - if($version == 0)
|
1215 | | - $version = 1;
|
1216 | | -
|
1217 | | - switch($this->mode) {
|
1218 | | - case QR_MODE_NUM: $bits = QRinput::estimateBitsModeNum($this->size); break;
|
1219 | | - case QR_MODE_AN: $bits = QRinput::estimateBitsModeAn($this->size); break;
|
1220 | | - case QR_MODE_8: $bits = QRinput::estimateBitsMode8($this->size); break;
|
1221 | | - case QR_MODE_KANJI: $bits = QRinput::estimateBitsModeKanji($this->size);break;
|
1222 | | - case QR_MODE_STRUCTURE: return STRUCTURE_HEADER_BITS;
|
1223 | | - default:
|
1224 | | - return 0;
|
1225 | | - }
|
1226 | | -
|
1227 | | - $l = QRspec::lengthIndicator($this->mode, $version);
|
1228 | | - $m = 1 << $l;
|
1229 | | - $num = (int)(($this->size + $m - 1) / $m);
|
1230 | | -
|
1231 | | - $bits += $num * (4 + $l);
|
1232 | | -
|
1233 | | - return $bits;
|
1234 | | - }
|
1235 | | -
|
1236 | | - //----------------------------------------------------------------------
|
1237 | | - public function encodeBitStream($version)
|
1238 | | - {
|
1239 | | - try {
|
1240 | | -
|
1241 | | - unset($this->bstream);
|
1242 | | - $words = QRspec::maximumWords($this->mode, $version);
|
1243 | | -
|
1244 | | - if($this->size > $words) {
|
1245 | | -
|
1246 | | - $st1 = new QRinputItem($this->mode, $words, $this->data);
|
1247 | | - $st2 = new QRinputItem($this->mode, $this->size - $words, array_slice($this->data, $words));
|
1248 | | -
|
1249 | | - $st1->encodeBitStream($version);
|
1250 | | - $st2->encodeBitStream($version);
|
1251 | | -
|
1252 | | - $this->bstream = new QRbitstream();
|
1253 | | - $this->bstream->append($st1->bstream);
|
1254 | | - $this->bstream->append($st2->bstream);
|
1255 | | -
|
1256 | | - unset($st1);
|
1257 | | - unset($st2);
|
1258 | | -
|
1259 | | - } else {
|
1260 | | -
|
1261 | | - $ret = 0;
|
1262 | | -
|
1263 | | - switch($this->mode) {
|
1264 | | - case QR_MODE_NUM: $ret = $this->encodeModeNum($version); break;
|
1265 | | - case QR_MODE_AN: $ret = $this->encodeModeAn($version); break;
|
1266 | | - case QR_MODE_8: $ret = $this->encodeMode8($version); break;
|
1267 | | - case QR_MODE_KANJI: $ret = $this->encodeModeKanji($version);break;
|
1268 | | - case QR_MODE_STRUCTURE: $ret = $this->encodeModeStructure(); break;
|
1269 | | -
|
1270 | | - default:
|
1271 | | - break;
|
1272 | | - }
|
1273 | | -
|
1274 | | - if($ret < 0)
|
1275 | | - return -1;
|
1276 | | - }
|
1277 | | -
|
1278 | | - return $this->bstream->size();
|
1279 | | -
|
1280 | | - } catch (Exception $e) {
|
1281 | | - return -1;
|
1282 | | - }
|
1283 | | - }
|
1284 | | - };
|
1285 | | -
|
1286 | | - //##########################################################################
|
1287 | | -
|
1288 | | - class QRinput {
|
1289 | | -
|
1290 | | - public $items;
|
1291 | | -
|
1292 | | - private $version;
|
1293 | | - private $level;
|
1294 | | -
|
1295 | | - //----------------------------------------------------------------------
|
1296 | | - public function __construct($version = 0, $level = QR_ECLEVEL_L)
|
1297 | | - {
|
1298 | | - if ($version < 0 || $version > QRSPEC_VERSION_MAX || $level > QR_ECLEVEL_H) {
|
1299 | | - throw new Exception('Invalid version no');
|
1300 | | - return NULL;
|
1301 | | - }
|
1302 | | -
|
1303 | | - $this->version = $version;
|
1304 | | - $this->level = $level;
|
1305 | | - }
|
1306 | | -
|
1307 | | - //----------------------------------------------------------------------
|
1308 | | - public function getVersion()
|
1309 | | - {
|
1310 | | - return $this->version;
|
1311 | | - }
|
1312 | | -
|
1313 | | - //----------------------------------------------------------------------
|
1314 | | - public function setVersion($version)
|
1315 | | - {
|
1316 | | - if($version < 0 || $version > QRSPEC_VERSION_MAX) {
|
1317 | | - throw new Exception('Invalid version no');
|
1318 | | - return -1;
|
1319 | | - }
|
1320 | | -
|
1321 | | - $this->version = $version;
|
1322 | | -
|
1323 | | - return 0;
|
1324 | | - }
|
1325 | | -
|
1326 | | - //----------------------------------------------------------------------
|
1327 | | - public function getErrorCorrectionLevel()
|
1328 | | - {
|
1329 | | - return $this->level;
|
1330 | | - }
|
1331 | | -
|
1332 | | - //----------------------------------------------------------------------
|
1333 | | - public function setErrorCorrectionLevel($level)
|
1334 | | - {
|
1335 | | - if($level > QR_ECLEVEL_H) {
|
1336 | | - throw new Exception('Invalid ECLEVEL');
|
1337 | | - return -1;
|
1338 | | - }
|
1339 | | -
|
1340 | | - $this->level = $level;
|
1341 | | -
|
1342 | | - return 0;
|
1343 | | - }
|
1344 | | -
|
1345 | | - //----------------------------------------------------------------------
|
1346 | | - public function appendEntry(QRinputItem $entry)
|
1347 | | - {
|
1348 | | - $this->items[] = $entry;
|
1349 | | - }
|
1350 | | -
|
1351 | | - //----------------------------------------------------------------------
|
1352 | | - public function append($mode, $size, $data)
|
1353 | | - {
|
1354 | | - try {
|
1355 | | - $entry = new QRinputItem($mode, $size, $data);
|
1356 | | - $this->items[] = $entry;
|
1357 | | - return 0;
|
1358 | | - } catch (Exception $e) {
|
1359 | | - return -1;
|
1360 | | - }
|
1361 | | - }
|
1362 | | -
|
1363 | | - //----------------------------------------------------------------------
|
1364 | | -
|
1365 | | - public function insertStructuredAppendHeader($size, $index, $parity)
|
1366 | | - {
|
1367 | | - if( $size > MAX_STRUCTURED_SYMBOLS ) {
|
1368 | | - throw new Exception('insertStructuredAppendHeader wrong size');
|
1369 | | - }
|
1370 | | -
|
1371 | | - if( $index <= 0 || $index > MAX_STRUCTURED_SYMBOLS ) {
|
1372 | | - throw new Exception('insertStructuredAppendHeader wrong index');
|
1373 | | - }
|
1374 | | -
|
1375 | | - $buf = array($size, $index, $parity);
|
1376 | | -
|
1377 | | - try {
|
1378 | | - $entry = new QRinputItem(QR_MODE_STRUCTURE, 3, buf);
|
1379 | | - array_unshift($this->items, $entry);
|
1380 | | - return 0;
|
1381 | | - } catch (Exception $e) {
|
1382 | | - return -1;
|
1383 | | - }
|
1384 | | - }
|
1385 | | -
|
1386 | | - //----------------------------------------------------------------------
|
1387 | | - public function calcParity()
|
1388 | | - {
|
1389 | | - $parity = 0;
|
1390 | | -
|
1391 | | - foreach($this->items as $item) {
|
1392 | | - if($item->mode != QR_MODE_STRUCTURE) {
|
1393 | | - for($i=$item->size-1; $i>=0; $i--) {
|
1394 | | - $parity ^= $item->data[$i];
|
1395 | | - }
|
1396 | | - }
|
1397 | | - }
|
1398 | | -
|
1399 | | - return $parity;
|
1400 | | - }
|
1401 | | -
|
1402 | | - //----------------------------------------------------------------------
|
1403 | | - public static function checkModeNum($size, $data)
|
1404 | | - {
|
1405 | | - for($i=0; $i<$size; $i++) {
|
1406 | | - if((ord($data[$i]) < ord('0')) || (ord($data[$i]) > ord('9'))){
|
1407 | | - return false;
|
1408 | | - }
|
1409 | | - }
|
1410 | | -
|
1411 | | - return true;
|
1412 | | - }
|
1413 | | -
|
1414 | | - //----------------------------------------------------------------------
|
1415 | | - public static function estimateBitsModeNum($size)
|
1416 | | - {
|
1417 | | - $w = (int)$size / 3;
|
1418 | | - $bits = $w * 10;
|
1419 | | -
|
1420 | | - switch($size - $w * 3) {
|
1421 | | - case 1:
|
1422 | | - $bits += 4;
|
1423 | | - break;
|
1424 | | - case 2:
|
1425 | | - $bits += 7;
|
1426 | | - break;
|
1427 | | - default:
|
1428 | | - break;
|
1429 | | - }
|
1430 | | -
|
1431 | | - return $bits;
|
1432 | | - }
|
1433 | | -
|
1434 | | - //----------------------------------------------------------------------
|
1435 | | - public static $anTable = array(
|
1436 | | - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
1437 | | - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
1438 | | - 36, -1, -1, -1, 37, 38, -1, -1, -1, -1, 39, 40, -1, 41, 42, 43,
|
1439 | | - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 44, -1, -1, -1, -1, -1,
|
1440 | | - -1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
|
1441 | | - 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, -1, -1, -1, -1, -1,
|
1442 | | - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
1443 | | - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
|
1444 | | - );
|
1445 | | -
|
1446 | | - //----------------------------------------------------------------------
|
1447 | | - public static function lookAnTable($c)
|
1448 | | - {
|
1449 | | - return (($c > 127)?-1:self::$anTable[$c]);
|
1450 | | - }
|
1451 | | -
|
1452 | | - //----------------------------------------------------------------------
|
1453 | | - public static function checkModeAn($size, $data)
|
1454 | | - {
|
1455 | | - for($i=0; $i<$size; $i++) {
|
1456 | | - if (self::lookAnTable(ord($data[$i])) == -1) {
|
1457 | | - return false;
|
1458 | | - }
|
1459 | | - }
|
1460 | | -
|
1461 | | - return true;
|
1462 | | - }
|
1463 | | -
|
1464 | | - //----------------------------------------------------------------------
|
1465 | | - public static function estimateBitsModeAn($size)
|
1466 | | - {
|
1467 | | - $w = (int)($size / 2);
|
1468 | | - $bits = $w * 11;
|
1469 | | -
|
1470 | | - if($size & 1) {
|
1471 | | - $bits += 6;
|
1472 | | - }
|
1473 | | -
|
1474 | | - return $bits;
|
1475 | | - }
|
1476 | | -
|
1477 | | - //----------------------------------------------------------------------
|
1478 | | - public static function estimateBitsMode8($size)
|
1479 | | - {
|
1480 | | - return $size * 8;
|
1481 | | - }
|
1482 | | -
|
1483 | | - //----------------------------------------------------------------------
|
1484 | | - public function estimateBitsModeKanji($size)
|
1485 | | - {
|
1486 | | - return (int)(($size / 2) * 13);
|
1487 | | - }
|
1488 | | -
|
1489 | | - //----------------------------------------------------------------------
|
1490 | | - public static function checkModeKanji($size, $data)
|
1491 | | - {
|
1492 | | - if($size & 1)
|
1493 | | - return false;
|
1494 | | -
|
1495 | | - for($i=0; $i<$size; $i+=2) {
|
1496 | | - $val = (ord($data[$i]) << 8) | ord($data[$i+1]);
|
1497 | | - if( $val < 0x8140
|
1498 | | - || ($val > 0x9ffc && $val < 0xe040)
|
1499 | | - || $val > 0xebbf) {
|
1500 | | - return false;
|
1501 | | - }
|
1502 | | - }
|
1503 | | -
|
1504 | | - return true;
|
1505 | | - }
|
1506 | | -
|
1507 | | - /***********************************************************************
|
1508 | | - * Validation
|
1509 | | - **********************************************************************/
|
1510 | | -
|
1511 | | - public function check($mode, $size, $data)
|
1512 | | - {
|
1513 | | - if($size <= 0)
|
1514 | | - return false;
|
1515 | | -
|
1516 | | - switch($mode) {
|
1517 | | - case QR_MODE_NUM: return self::checkModeNum($size, $data); break;
|
1518 | | - case QR_MODE_AN: return self::checkModeAn($size, $data); break;
|
1519 | | - case QR_MODE_KANJI: return self::checkModeKanji($size, $data); break;
|
1520 | | - case QR_MODE_8: return true; break;
|
1521 | | - case QR_MODE_STRUCTURE: return true; break;
|
1522 | | -
|
1523 | | - default:
|
1524 | | - break;
|
1525 | | - }
|
1526 | | -
|
1527 | | - return false;
|
1528 | | - }
|
1529 | | -
|
1530 | | -
|
1531 | | - //----------------------------------------------------------------------
|
1532 | | - public function estimateBitStreamSize($version)
|
1533 | | - {
|
1534 | | - $bits = 0;
|
1535 | | -
|
1536 | | - foreach($this->items as $item) {
|
1537 | | - $bits += $item->estimateBitStreamSizeOfEntry($version);
|
1538 | | - }
|
1539 | | -
|
1540 | | - return $bits;
|
1541 | | - }
|
1542 | | -
|
1543 | | - //----------------------------------------------------------------------
|
1544 | | - public function estimateVersion()
|
1545 | | - {
|
1546 | | - $version = 0;
|
1547 | | - $prev = 0;
|
1548 | | - do {
|
1549 | | - $prev = $version;
|
1550 | | - $bits = $this->estimateBitStreamSize($prev);
|
1551 | | - $version = QRspec::getMinimumVersion((int)(($bits + 7) / 8), $this->level);
|
1552 | | - if ($version < 0) {
|
1553 | | - return -1;
|
1554 | | - }
|
1555 | | - } while ($version > $prev);
|
1556 | | -
|
1557 | | - return $version;
|
1558 | | - }
|
1559 | | -
|
1560 | | - //----------------------------------------------------------------------
|
1561 | | - public static function lengthOfCode($mode, $version, $bits)
|
1562 | | - {
|
1563 | | - $payload = $bits - 4 - QRspec::lengthIndicator($mode, $version);
|
1564 | | - switch($mode) {
|
1565 | | - case QR_MODE_NUM:
|
1566 | | - $chunks = (int)($payload / 10);
|
1567 | | - $remain = $payload - $chunks * 10;
|
1568 | | - $size = $chunks * 3;
|
1569 | | - if($remain >= 7) {
|
1570 | | - $size += 2;
|
1571 | | - } else if($remain >= 4) {
|
1572 | | - $size += 1;
|
1573 | | - }
|
1574 | | - break;
|
1575 | | - case QR_MODE_AN:
|
1576 | | - $chunks = (int)($payload / 11);
|
1577 | | - $remain = $payload - $chunks * 11;
|
1578 | | - $size = $chunks * 2;
|
1579 | | - if($remain >= 6)
|
1580 | | - $size++;
|
1581 | | - break;
|
1582 | | - case QR_MODE_8:
|
1583 | | - $size = (int)($payload / 8);
|
1584 | | - break;
|
1585 | | - case QR_MODE_KANJI:
|
1586 | | - $size = (int)(($payload / 13) * 2);
|
1587 | | - break;
|
1588 | | - case QR_MODE_STRUCTURE:
|
1589 | | - $size = (int)($payload / 8);
|
1590 | | - break;
|
1591 | | - default:
|
1592 | | - $size = 0;
|
1593 | | - break;
|
1594 | | - }
|
1595 | | -
|
1596 | | - $maxsize = QRspec::maximumWords($mode, $version);
|
1597 | | - if($size < 0) $size = 0;
|
1598 | | - if($size > $maxsize) $size = $maxsize;
|
1599 | | -
|
1600 | | - return $size;
|
1601 | | - }
|
1602 | | -
|
1603 | | - //----------------------------------------------------------------------
|
1604 | | - public function createBitStream()
|
1605 | | - {
|
1606 | | - $total = 0;
|
1607 | | -
|
1608 | | - foreach($this->items as $item) {
|
1609 | | - $bits = $item->encodeBitStream($this->version);
|
1610 | | -
|
1611 | | - if($bits < 0)
|
1612 | | - return -1;
|
1613 | | -
|
1614 | | - $total += $bits;
|
1615 | | - }
|
1616 | | -
|
1617 | | - return $total;
|
1618 | | - }
|
1619 | | -
|
1620 | | - //----------------------------------------------------------------------
|
1621 | | - public function convertData()
|
1622 | | - {
|
1623 | | - $ver = $this->estimateVersion();
|
1624 | | - if($ver > $this->getVersion()) {
|
1625 | | - $this->setVersion($ver);
|
1626 | | - }
|
1627 | | -
|
1628 | | - for(;;) {
|
1629 | | - $bits = $this->createBitStream();
|
1630 | | -
|
1631 | | - if($bits < 0)
|
1632 | | - return -1;
|
1633 | | -
|
1634 | | - $ver = QRspec::getMinimumVersion((int)(($bits + 7) / 8), $this->level);
|
1635 | | - if($ver < 0) {
|
1636 | | - throw new Exception('WRONG VERSION');
|
1637 | | - return -1;
|
1638 | | - } else if($ver > $this->getVersion()) {
|
1639 | | - $this->setVersion($ver);
|
1640 | | - } else {
|
1641 | | - break;
|
1642 | | - }
|
1643 | | - }
|
1644 | | -
|
1645 | | - return 0;
|
1646 | | - }
|
1647 | | -
|
1648 | | - //----------------------------------------------------------------------
|
1649 | | - public function appendPaddingBit(&$bstream)
|
1650 | | - {
|
1651 | | - $bits = $bstream->size();
|
1652 | | - $maxwords = QRspec::getDataLength($this->version, $this->level);
|
1653 | | - $maxbits = $maxwords * 8;
|
1654 | | -
|
1655 | | - if ($maxbits == $bits) {
|
1656 | | - return 0;
|
1657 | | - }
|
1658 | | -
|
1659 | | - if ($maxbits - $bits < 5) {
|
1660 | | - return $bstream->appendNum($maxbits - $bits, 0);
|
1661 | | - }
|
1662 | | -
|
1663 | | - $bits += 4;
|
1664 | | - $words = (int)(($bits + 7) / 8);
|
1665 | | -
|
1666 | | - $padding = new QRbitstream();
|
1667 | | - $ret = $padding->appendNum($words * 8 - $bits + 4, 0);
|
1668 | | -
|
1669 | | - if($ret < 0)
|
1670 | | - return $ret;
|
1671 | | -
|
1672 | | - $padlen = $maxwords - $words;
|
1673 | | -
|
1674 | | - if($padlen > 0) {
|
1675 | | -
|
1676 | | - $padbuf = array();
|
1677 | | - for($i=0; $i<$padlen; $i++) {
|
1678 | | - $padbuf[$i] = ($i&1)?0x11:0xec;
|
1679 | | - }
|
1680 | | -
|
1681 | | - $ret = $padding->appendBytes($padlen, $padbuf);
|
1682 | | -
|
1683 | | - if($ret < 0)
|
1684 | | - return $ret;
|
1685 | | -
|
1686 | | - }
|
1687 | | -
|
1688 | | - $ret = $bstream->append($padding);
|
1689 | | -
|
1690 | | - return $ret;
|
1691 | | - }
|
1692 | | -
|
1693 | | - //----------------------------------------------------------------------
|
1694 | | - public function mergeBitStream()
|
1695 | | - {
|
1696 | | - if($this->convertData() < 0) {
|
1697 | | - return null;
|
1698 | | - }
|
1699 | | -
|
1700 | | - $bstream = new QRbitstream();
|
1701 | | -
|
1702 | | - foreach($this->items as $item) {
|
1703 | | - $ret = $bstream->append($item->bstream);
|
1704 | | - if($ret < 0) {
|
1705 | | - return null;
|
1706 | | - }
|
1707 | | - }
|
1708 | | -
|
1709 | | - return $bstream;
|
1710 | | - }
|
1711 | | -
|
1712 | | - //----------------------------------------------------------------------
|
1713 | | - public function getBitStream()
|
1714 | | - {
|
1715 | | -
|
1716 | | - $bstream = $this->mergeBitStream();
|
1717 | | -
|
1718 | | - if($bstream == null) {
|
1719 | | - return null;
|
1720 | | - }
|
1721 | | -
|
1722 | | - $ret = $this->appendPaddingBit($bstream);
|
1723 | | - if($ret < 0) {
|
1724 | | - return null;
|
1725 | | - }
|
1726 | | -
|
1727 | | - return $bstream;
|
1728 | | - }
|
1729 | | -
|
1730 | | - //----------------------------------------------------------------------
|
1731 | | - public function getByteStream()
|
1732 | | - {
|
1733 | | - $bstream = $this->getBitStream();
|
1734 | | - if($bstream == null) {
|
1735 | | - return null;
|
1736 | | - }
|
1737 | | -
|
1738 | | - return $bstream->toByte();
|
1739 | | - }
|
1740 | | - }
|
1741 | | -
|
1742 | | -
|
| 1015 | + |
| 1016 | +/* |
| 1017 | + * PHP QR Code encoder |
| 1018 | + * |
| 1019 | + * Input encoding class |
| 1020 | + * |
| 1021 | + * Based on libqrencode C library distributed under LGPL 2.1 |
| 1022 | + * Copyright (C) 2006, 2007, 2008, 2009 Kentaro Fukuchi <fukuchi@megaui.net> |
| 1023 | + * |
| 1024 | + * PHP QR Code is distributed under LGPL 3 |
| 1025 | + * Copyright (C) 2010 Dominik Dzienia <deltalab at poczta dot fm> |
| 1026 | + * |
| 1027 | + * This library is free software; you can redistribute it and/or |
| 1028 | + * modify it under the terms of the GNU Lesser General Public |
| 1029 | + * License as published by the Free Software Foundation; either |
| 1030 | + * version 3 of the License, or any later version. |
| 1031 | + * |
| 1032 | + * This library is distributed in the hope that it will be useful, |
| 1033 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 1034 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 1035 | + * Lesser General Public License for more details. |
| 1036 | + * |
| 1037 | + * You should have received a copy of the GNU Lesser General Public |
| 1038 | + * License along with this library; if not, write to the Free Software |
| 1039 | + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 1040 | + */ |
| 1041 | + |
| 1042 | + define('STRUCTURE_HEADER_BITS', 20); |
| 1043 | + define('MAX_STRUCTURED_SYMBOLS', 16); |
| 1044 | + |
| 1045 | + class QRinputItem { |
1743 | 1046 | |
| 1047 | + public $mode; |
| 1048 | + public $size; |
| 1049 | + public $data; |
| 1050 | + public $bstream; |
1744 | 1051 | |
| 1052 | + public function __construct($mode, $size, $data, $bstream = null) |
| 1053 | + { |
| 1054 | + $setData = array_slice($data, 0, $size); |
| 1055 | + |
| 1056 | + if (count($setData) < $size) { |
| 1057 | + $setData = array_merge($setData, array_fill(0,$size-count($setData),0)); |
| 1058 | + } |
| 1059 | + |
| 1060 | + if(!QRinput::check($mode, $size, $setData)) { |
| 1061 | + throw new Exception('Error m:'.$mode.',s:'.$size.',d:'.join(',',$setData)); |
| 1062 | + } |
| 1063 | + |
| 1064 | + $this->mode = $mode; |
| 1065 | + $this->size = $size; |
| 1066 | + $this->data = $setData; |
| 1067 | + $this->bstream = $bstream; |
| 1068 | + } |
| 1069 | + |
| 1070 | + //---------------------------------------------------------------------- |
| 1071 | + public function encodeModeNum($version) |
| 1072 | + { |
| 1073 | + try { |
| 1074 | + |
| 1075 | + $words = (int)($this->size / 3); |
| 1076 | + $bs = new QRbitstream(); |
| 1077 | + |
| 1078 | + $val = 0x1; |
| 1079 | + $bs->appendNum(4, $val); |
| 1080 | + $bs->appendNum(QRspec::lengthIndicator(QR_MODE_NUM, $version), $this->size); |
1745 | 1081 | |
| 1082 | + for($i=0; $i<$words; $i++) { |
| 1083 | + $val = (ord($this->data[$i*3 ]) - ord('0')) * 100; |
| 1084 | + $val += (ord($this->data[$i*3+1]) - ord('0')) * 10; |
| 1085 | + $val += (ord($this->data[$i*3+2]) - ord('0')); |
| 1086 | + $bs->appendNum(10, $val); |
| 1087 | + } |
1746 | 1088 | |
| 1089 | + if($this->size - $words * 3 == 1) { |
| 1090 | + $val = ord($this->data[$words*3]) - ord('0'); |
| 1091 | + $bs->appendNum(4, $val); |
| 1092 | + } else if($this->size - $words * 3 == 2) { |
| 1093 | + $val = (ord($this->data[$words*3 ]) - ord('0')) * 10; |
| 1094 | + $val += (ord($this->data[$words*3+1]) - ord('0')); |
| 1095 | + $bs->appendNum(7, $val); |
| 1096 | + } |
| 1097 | + |
| 1098 | + $this->bstream = $bs; |
| 1099 | + return 0; |
| 1100 | + |
| 1101 | + } catch (Exception $e) { |
| 1102 | + return -1; |
| 1103 | + } |
| 1104 | + } |
| 1105 | + |
| 1106 | + //---------------------------------------------------------------------- |
| 1107 | + public function encodeModeAn($version) |
| 1108 | + { |
| 1109 | + try { |
| 1110 | + $words = (int)($this->size / 2); |
| 1111 | + $bs = new QRbitstream(); |
| 1112 | + |
| 1113 | + $bs->appendNum(4, 0x02); |
| 1114 | + $bs->appendNum(QRspec::lengthIndicator(QR_MODE_AN, $version), $this->size); |
| 1115 | + |
| 1116 | + for($i=0; $i<$words; $i++) { |
| 1117 | + $val = (int)QRinput::lookAnTable(ord($this->data[$i*2 ])) * 45; |
| 1118 | + $val += (int)QRinput::lookAnTable(ord($this->data[$i*2+1])); |
| 1119 | + |
| 1120 | + $bs->appendNum(11, $val); |
| 1121 | + } |
| 1122 | + |
| 1123 | + if($this->size & 1) { |
| 1124 | + $val = QRinput::lookAnTable(ord($this->data[$words * 2])); |
| 1125 | + $bs->appendNum(6, $val); |
| 1126 | + } |
| 1127 | + |
| 1128 | + $this->bstream = $bs; |
| 1129 | + return 0; |
| 1130 | + |
| 1131 | + } catch (Exception $e) { |
| 1132 | + return -1; |
| 1133 | + } |
| 1134 | + } |
| 1135 | + |
| 1136 | + //---------------------------------------------------------------------- |
| 1137 | + public function encodeMode8($version) |
| 1138 | + { |
| 1139 | + try { |
| 1140 | + $bs = new QRbitstream(); |
| 1141 | + |
| 1142 | + $bs->appendNum(4, 0x4); |
| 1143 | + $bs->appendNum(QRspec::lengthIndicator(QR_MODE_8, $version), $this->size); |
| 1144 | + |
| 1145 | + for($i=0; $i<$this->size; $i++) { |
| 1146 | + $bs->appendNum(8, ord($this->data[$i])); |
| 1147 | + } |
| 1148 | + |
| 1149 | + $this->bstream = $bs; |
| 1150 | + return 0; |
| 1151 | + |
| 1152 | + } catch (Exception $e) { |
| 1153 | + return -1; |
| 1154 | + } |
| 1155 | + } |
| 1156 | + |
| 1157 | + //---------------------------------------------------------------------- |
| 1158 | + public function encodeModeKanji($version) |
| 1159 | + { |
| 1160 | + try { |
| 1161 | + |
| 1162 | + $bs = new QRbitrtream(); |
| 1163 | + |
| 1164 | + $bs->appendNum(4, 0x8); |
| 1165 | + $bs->appendNum(QRspec::lengthIndicator(QR_MODE_KANJI, $version), (int)($this->size / 2)); |
| 1166 | + |
| 1167 | + for($i=0; $i<$this->size; $i+=2) { |
| 1168 | + $val = (ord($this->data[$i]) << 8) | ord($this->data[$i+1]); |
| 1169 | + if($val <= 0x9ffc) { |
| 1170 | + $val -= 0x8140; |
| 1171 | + } else { |
| 1172 | + $val -= 0xc140; |
| 1173 | + } |
| 1174 | + |
| 1175 | + $h = ($val >> 8) * 0xc0; |
| 1176 | + $val = ($val & 0xff) + $h; |
| 1177 | + |
| 1178 | + $bs->appendNum(13, $val); |
| 1179 | + } |
| 1180 | + |
| 1181 | + $this->bstream = $bs; |
| 1182 | + return 0; |
| 1183 | + |
| 1184 | + } catch (Exception $e) { |
| 1185 | + return -1; |
| 1186 | + } |
| 1187 | + } |
| 1188 | + |
| 1189 | + //---------------------------------------------------------------------- |
| 1190 | + public function encodeModeStructure() |
| 1191 | + { |
| 1192 | + try { |
| 1193 | + $bs = new QRbitstream(); |
| 1194 | + |
| 1195 | + $bs->appendNum(4, 0x03); |
| 1196 | + $bs->appendNum(4, ord($this->data[1]) - 1); |
| 1197 | + $bs->appendNum(4, ord($this->data[0]) - 1); |
| 1198 | + $bs->appendNum(8, ord($this->data[2])); |
| 1199 | + |
| 1200 | + $this->bstream = $bs; |
| 1201 | + return 0; |
| 1202 | + |
| 1203 | + } catch (Exception $e) { |
| 1204 | + return -1; |
| 1205 | + } |
| 1206 | + } |
| 1207 | + |
| 1208 | + //---------------------------------------------------------------------- |
| 1209 | + public function estimateBitStreamSizeOfEntry($version) |
| 1210 | + { |
| 1211 | + $bits = 0; |
| 1212 | + |
| 1213 | + if($version == 0) |
| 1214 | + $version = 1; |
| 1215 | + |
| 1216 | + switch($this->mode) { |
| 1217 | + case QR_MODE_NUM: $bits = QRinput::estimateBitsModeNum($this->size); break; |
| 1218 | + case QR_MODE_AN: $bits = QRinput::estimateBitsModeAn($this->size); break; |
| 1219 | + case QR_MODE_8: $bits = QRinput::estimateBitsMode8($this->size); break; |
| 1220 | + case QR_MODE_KANJI: $bits = QRinput::estimateBitsModeKanji($this->size);break; |
| 1221 | + case QR_MODE_STRUCTURE: return STRUCTURE_HEADER_BITS; |
| 1222 | + default: |
| 1223 | + return 0; |
| 1224 | + } |
| 1225 | + |
| 1226 | + $l = QRspec::lengthIndicator($this->mode, $version); |
| 1227 | + $m = 1 << $l; |
| 1228 | + $num = (int)(($this->size + $m - 1) / $m); |
| 1229 | + |
| 1230 | + $bits += $num * (4 + $l); |
| 1231 | + |
| 1232 | + return $bits; |
| 1233 | + } |
| 1234 | + |
| 1235 | + //---------------------------------------------------------------------- |
| 1236 | + public function encodeBitStream($version) |
| 1237 | + { |
| 1238 | + try { |
| 1239 | + |
| 1240 | + unset($this->bstream); |
| 1241 | + $words = QRspec::maximumWords($this->mode, $version); |
| 1242 | + |
| 1243 | + if($this->size > $words) { |
| 1244 | + |
| 1245 | + $st1 = new QRinputItem($this->mode, $words, $this->data); |
| 1246 | + $st2 = new QRinputItem($this->mode, $this->size - $words, array_slice($this->data, $words)); |
| 1247 | + |
| 1248 | + $st1->encodeBitStream($version); |
| 1249 | + $st2->encodeBitStream($version); |
| 1250 | + |
| 1251 | + $this->bstream = new QRbitstream(); |
| 1252 | + $this->bstream->append($st1->bstream); |
| 1253 | + $this->bstream->append($st2->bstream); |
| 1254 | + |
| 1255 | + unset($st1); |
| 1256 | + unset($st2); |
| 1257 | + |
| 1258 | + } else { |
| 1259 | + |
| 1260 | + $ret = 0; |
| 1261 | + |
| 1262 | + switch($this->mode) { |
| 1263 | + case QR_MODE_NUM: $ret = $this->encodeModeNum($version); break; |
| 1264 | + case QR_MODE_AN: $ret = $this->encodeModeAn($version); break; |
| 1265 | + case QR_MODE_8: $ret = $this->encodeMode8($version); break; |
| 1266 | + case QR_MODE_KANJI: $ret = $this->encodeModeKanji($version);break; |
| 1267 | + case QR_MODE_STRUCTURE: $ret = $this->encodeModeStructure(); break; |
| 1268 | + |
| 1269 | + default: |
| 1270 | + break; |
| 1271 | + } |
| 1272 | + |
| 1273 | + if($ret < 0) |
| 1274 | + return -1; |
| 1275 | + } |
| 1276 | + |
| 1277 | + return $this->bstream->size(); |
| 1278 | + |
| 1279 | + } catch (Exception $e) { |
| 1280 | + return -1; |
| 1281 | + } |
| 1282 | + } |
| 1283 | + }; |
| 1284 | + |
| 1285 | + //########################################################################## |
| 1286 | + |
| 1287 | + class QRinput { |
| 1288 | + |
| 1289 | + public $items; |
| 1290 | + |
| 1291 | + private $version; |
| 1292 | + private $level; |
| 1293 | + |
| 1294 | + //---------------------------------------------------------------------- |
| 1295 | + public function __construct($version = 0, $level = QR_ECLEVEL_L) |
| 1296 | + { |
| 1297 | + if ($version < 0 || $version > QRSPEC_VERSION_MAX || $level > QR_ECLEVEL_H) { |
| 1298 | + throw new Exception('Invalid version no'); |
| 1299 | + } |
| 1300 | + |
| 1301 | + $this->version = $version; |
| 1302 | + $this->level = $level; |
| 1303 | + } |
| 1304 | + |
| 1305 | + //---------------------------------------------------------------------- |
| 1306 | + public function getVersion() |
| 1307 | + { |
| 1308 | + return $this->version; |
| 1309 | + } |
| 1310 | + |
| 1311 | + //---------------------------------------------------------------------- |
| 1312 | + public function setVersion($version) |
| 1313 | + { |
| 1314 | + if($version < 0 || $version > QRSPEC_VERSION_MAX) { |
| 1315 | + throw new Exception('Invalid version no'); |
| 1316 | + } |
| 1317 | + |
| 1318 | + $this->version = $version; |
| 1319 | + |
| 1320 | + return 0; |
| 1321 | + } |
| 1322 | + |
| 1323 | + //---------------------------------------------------------------------- |
| 1324 | + public function getErrorCorrectionLevel() |
| 1325 | + { |
| 1326 | + return $this->level; |
| 1327 | + } |
| 1328 | + |
| 1329 | + //---------------------------------------------------------------------- |
| 1330 | + public function setErrorCorrectionLevel($level) |
| 1331 | + { |
| 1332 | + if($level > QR_ECLEVEL_H) { |
| 1333 | + throw new Exception('Invalid ECLEVEL'); |
| 1334 | + } |
| 1335 | + |
| 1336 | + $this->level = $level; |
| 1337 | + |
| 1338 | + return 0; |
| 1339 | + } |
| 1340 | + |
| 1341 | + //---------------------------------------------------------------------- |
| 1342 | + public function appendEntry(QRinputItem $entry) |
| 1343 | + { |
| 1344 | + $this->items[] = $entry; |
| 1345 | + } |
| 1346 | + |
| 1347 | + //---------------------------------------------------------------------- |
| 1348 | + public function append($mode, $size, $data) |
| 1349 | + { |
| 1350 | + try { |
| 1351 | + $entry = new QRinputItem($mode, $size, $data); |
| 1352 | + $this->items[] = $entry; |
| 1353 | + return 0; |
| 1354 | + } catch (Exception $e) { |
| 1355 | + return -1; |
| 1356 | + } |
| 1357 | + } |
| 1358 | + |
| 1359 | + //---------------------------------------------------------------------- |
| 1360 | + |
| 1361 | + public function insertStructuredAppendHeader($size, $index, $parity) |
| 1362 | + { |
| 1363 | + if( $size > MAX_STRUCTURED_SYMBOLS ) { |
| 1364 | + throw new Exception('insertStructuredAppendHeader wrong size'); |
| 1365 | + } |
| 1366 | + |
| 1367 | + if( $index <= 0 || $index > MAX_STRUCTURED_SYMBOLS ) { |
| 1368 | + throw new Exception('insertStructuredAppendHeader wrong index'); |
| 1369 | + } |
| 1370 | + |
| 1371 | + $buf = array($size, $index, $parity); |
| 1372 | + |
| 1373 | + try { |
| 1374 | + $entry = new QRinputItem(QR_MODE_STRUCTURE, 3, buf); |
| 1375 | + array_unshift($this->items, $entry); |
| 1376 | + return 0; |
| 1377 | + } catch (Exception $e) { |
| 1378 | + return -1; |
| 1379 | + } |
| 1380 | + } |
| 1381 | + |
| 1382 | + //---------------------------------------------------------------------- |
| 1383 | + public function calcParity() |
| 1384 | + { |
| 1385 | + $parity = 0; |
| 1386 | + |
| 1387 | + foreach($this->items as $item) { |
| 1388 | + if($item->mode != QR_MODE_STRUCTURE) { |
| 1389 | + for($i=$item->size-1; $i>=0; $i--) { |
| 1390 | + $parity ^= $item->data[$i]; |
| 1391 | + } |
| 1392 | + } |
| 1393 | + } |
| 1394 | + |
| 1395 | + return $parity; |
| 1396 | + } |
| 1397 | + |
| 1398 | + //---------------------------------------------------------------------- |
| 1399 | + public static function checkModeNum($size, $data) |
| 1400 | + { |
| 1401 | + for($i=0; $i<$size; $i++) { |
| 1402 | + if((ord($data[$i]) < ord('0')) || (ord($data[$i]) > ord('9'))){ |
| 1403 | + return false; |
| 1404 | + } |
| 1405 | + } |
| 1406 | + |
| 1407 | + return true; |
| 1408 | + } |
| 1409 | + |
| 1410 | + //---------------------------------------------------------------------- |
| 1411 | + public static function estimateBitsModeNum($size) |
| 1412 | + { |
| 1413 | + $w = (int)$size / 3; |
| 1414 | + $bits = $w * 10; |
| 1415 | + |
| 1416 | + switch($size - $w * 3) { |
| 1417 | + case 1: |
| 1418 | + $bits += 4; |
| 1419 | + break; |
| 1420 | + case 2: |
| 1421 | + $bits += 7; |
| 1422 | + break; |
| 1423 | + default: |
| 1424 | + break; |
| 1425 | + } |
| 1426 | + |
| 1427 | + return $bits; |
| 1428 | + } |
| 1429 | + |
| 1430 | + //---------------------------------------------------------------------- |
| 1431 | + public static $anTable = array( |
| 1432 | + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 1433 | + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 1434 | + 36, -1, -1, -1, 37, 38, -1, -1, -1, -1, 39, 40, -1, 41, 42, 43, |
| 1435 | + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 44, -1, -1, -1, -1, -1, |
| 1436 | + -1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, |
| 1437 | + 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, -1, -1, -1, -1, -1, |
| 1438 | + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 1439 | + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 |
| 1440 | + ); |
| 1441 | + |
| 1442 | + //---------------------------------------------------------------------- |
| 1443 | + public static function lookAnTable($c) |
| 1444 | + { |
| 1445 | + return (($c > 127)?-1:self::$anTable[$c]); |
| 1446 | + } |
| 1447 | + |
| 1448 | + //---------------------------------------------------------------------- |
| 1449 | + public static function checkModeAn($size, $data) |
| 1450 | + { |
| 1451 | + for($i=0; $i<$size; $i++) { |
| 1452 | + if (self::lookAnTable(ord($data[$i])) == -1) { |
| 1453 | + return false; |
| 1454 | + } |
| 1455 | + } |
| 1456 | + |
| 1457 | + return true; |
| 1458 | + } |
| 1459 | + |
| 1460 | + //---------------------------------------------------------------------- |
| 1461 | + public static function estimateBitsModeAn($size) |
| 1462 | + { |
| 1463 | + $w = (int)($size / 2); |
| 1464 | + $bits = $w * 11; |
| 1465 | + |
| 1466 | + if($size & 1) { |
| 1467 | + $bits += 6; |
| 1468 | + } |
| 1469 | + |
| 1470 | + return $bits; |
| 1471 | + } |
| 1472 | + |
| 1473 | + //---------------------------------------------------------------------- |
| 1474 | + public static function estimateBitsMode8($size) |
| 1475 | + { |
| 1476 | + return $size * 8; |
| 1477 | + } |
| 1478 | + |
| 1479 | + //---------------------------------------------------------------------- |
| 1480 | + public function estimateBitsModeKanji($size) |
| 1481 | + { |
| 1482 | + return (int)(($size / 2) * 13); |
| 1483 | + } |
| 1484 | + |
| 1485 | + //---------------------------------------------------------------------- |
| 1486 | + public static function checkModeKanji($size, $data) |
| 1487 | + { |
| 1488 | + if($size & 1) |
| 1489 | + return false; |
| 1490 | + |
| 1491 | + for($i=0; $i<$size; $i+=2) { |
| 1492 | + $val = (ord($data[$i]) << 8) | ord($data[$i+1]); |
| 1493 | + if( $val < 0x8140 |
| 1494 | + || ($val > 0x9ffc && $val < 0xe040) |
| 1495 | + || $val > 0xebbf) { |
| 1496 | + return false; |
| 1497 | + } |
| 1498 | + } |
| 1499 | + |
| 1500 | + return true; |
| 1501 | + } |
| 1502 | + |
| 1503 | + /*********************************************************************** |
| 1504 | + * Validation |
| 1505 | + **********************************************************************/ |
| 1506 | + |
| 1507 | + public function check($mode, $size, $data) |
| 1508 | + { |
| 1509 | + if($size <= 0) |
| 1510 | + return false; |
| 1511 | + |
| 1512 | + switch($mode) { |
| 1513 | + case QR_MODE_NUM: return self::checkModeNum($size, $data); break; |
| 1514 | + case QR_MODE_AN: return self::checkModeAn($size, $data); break; |
| 1515 | + case QR_MODE_KANJI: return self::checkModeKanji($size, $data); break; |
| 1516 | + case QR_MODE_8: return true; break; |
| 1517 | + case QR_MODE_STRUCTURE: return true; break; |
| 1518 | + |
| 1519 | + default: |
| 1520 | + break; |
| 1521 | + } |
| 1522 | + |
| 1523 | + return false; |
| 1524 | + } |
| 1525 | + |
| 1526 | + |
| 1527 | + //---------------------------------------------------------------------- |
| 1528 | + public function estimateBitStreamSize($version) |
| 1529 | + { |
| 1530 | + $bits = 0; |
| 1531 | + |
| 1532 | + foreach($this->items as $item) { |
| 1533 | + $bits += $item->estimateBitStreamSizeOfEntry($version); |
| 1534 | + } |
| 1535 | + |
| 1536 | + return $bits; |
| 1537 | + } |
| 1538 | + |
| 1539 | + //---------------------------------------------------------------------- |
| 1540 | + public function estimateVersion() |
| 1541 | + { |
| 1542 | + $version = 0; |
| 1543 | + $prev = 0; |
| 1544 | + do { |
| 1545 | + $prev = $version; |
| 1546 | + $bits = $this->estimateBitStreamSize($prev); |
| 1547 | + $version = QRspec::getMinimumVersion((int)(($bits + 7) / 8), $this->level); |
| 1548 | + if ($version < 0) { |
| 1549 | + return -1; |
| 1550 | + } |
| 1551 | + } while ($version > $prev); |
| 1552 | + |
| 1553 | + return $version; |
| 1554 | + } |
| 1555 | + |
| 1556 | + //---------------------------------------------------------------------- |
| 1557 | + public static function lengthOfCode($mode, $version, $bits) |
| 1558 | + { |
| 1559 | + $payload = $bits - 4 - QRspec::lengthIndicator($mode, $version); |
| 1560 | + switch($mode) { |
| 1561 | + case QR_MODE_NUM: |
| 1562 | + $chunks = (int)($payload / 10); |
| 1563 | + $remain = $payload - $chunks * 10; |
| 1564 | + $size = $chunks * 3; |
| 1565 | + if($remain >= 7) { |
| 1566 | + $size += 2; |
| 1567 | + } else if($remain >= 4) { |
| 1568 | + $size += 1; |
| 1569 | + } |
| 1570 | + break; |
| 1571 | + case QR_MODE_AN: |
| 1572 | + $chunks = (int)($payload / 11); |
| 1573 | + $remain = $payload - $chunks * 11; |
| 1574 | + $size = $chunks * 2; |
| 1575 | + if($remain >= 6) |
| 1576 | + $size++; |
| 1577 | + break; |
| 1578 | + case QR_MODE_8: |
| 1579 | + $size = (int)($payload / 8); |
| 1580 | + break; |
| 1581 | + case QR_MODE_KANJI: |
| 1582 | + $size = (int)(($payload / 13) * 2); |
| 1583 | + break; |
| 1584 | + case QR_MODE_STRUCTURE: |
| 1585 | + $size = (int)($payload / 8); |
| 1586 | + break; |
| 1587 | + default: |
| 1588 | + $size = 0; |
| 1589 | + break; |
| 1590 | + } |
| 1591 | + |
| 1592 | + $maxsize = QRspec::maximumWords($mode, $version); |
| 1593 | + if($size < 0) $size = 0; |
| 1594 | + if($size > $maxsize) $size = $maxsize; |
| 1595 | + |
| 1596 | + return $size; |
| 1597 | + } |
| 1598 | + |
| 1599 | + //---------------------------------------------------------------------- |
| 1600 | + public function createBitStream() |
| 1601 | + { |
| 1602 | + $total = 0; |
| 1603 | + |
| 1604 | + foreach($this->items as $item) { |
| 1605 | + $bits = $item->encodeBitStream($this->version); |
| 1606 | + |
| 1607 | + if($bits < 0) |
| 1608 | + return -1; |
| 1609 | + |
| 1610 | + $total += $bits; |
| 1611 | + } |
| 1612 | + |
| 1613 | + return $total; |
| 1614 | + } |
| 1615 | + |
| 1616 | + //---------------------------------------------------------------------- |
| 1617 | + public function convertData() |
| 1618 | + { |
| 1619 | + $ver = $this->estimateVersion(); |
| 1620 | + if($ver > $this->getVersion()) { |
| 1621 | + $this->setVersion($ver); |
| 1622 | + } |
| 1623 | + |
| 1624 | + for(;;) { |
| 1625 | + $bits = $this->createBitStream(); |
| 1626 | + |
| 1627 | + if($bits < 0) |
| 1628 | + return -1; |
| 1629 | + |
| 1630 | + $ver = QRspec::getMinimumVersion((int)(($bits + 7) / 8), $this->level); |
| 1631 | + if($ver < 0) { |
| 1632 | + throw new Exception('WRONG VERSION'); |
| 1633 | + } else if($ver > $this->getVersion()) { |
| 1634 | + $this->setVersion($ver); |
| 1635 | + } else { |
| 1636 | + break; |
| 1637 | + } |
| 1638 | + } |
| 1639 | + |
| 1640 | + return 0; |
| 1641 | + } |
| 1642 | + |
| 1643 | + //---------------------------------------------------------------------- |
| 1644 | + public function appendPaddingBit(&$bstream) |
| 1645 | + { |
| 1646 | + $bits = $bstream->size(); |
| 1647 | + $maxwords = QRspec::getDataLength($this->version, $this->level); |
| 1648 | + $maxbits = $maxwords * 8; |
| 1649 | + |
| 1650 | + if ($maxbits == $bits) { |
| 1651 | + return 0; |
| 1652 | + } |
| 1653 | + |
| 1654 | + if ($maxbits - $bits < 5) { |
| 1655 | + return $bstream->appendNum($maxbits - $bits, 0); |
| 1656 | + } |
| 1657 | + |
| 1658 | + $bits += 4; |
| 1659 | + $words = (int)(($bits + 7) / 8); |
| 1660 | + |
| 1661 | + $padding = new QRbitstream(); |
| 1662 | + $ret = $padding->appendNum($words * 8 - $bits + 4, 0); |
| 1663 | + |
| 1664 | + if($ret < 0) |
| 1665 | + return $ret; |
| 1666 | + |
| 1667 | + $padlen = $maxwords - $words; |
| 1668 | + |
| 1669 | + if($padlen > 0) { |
| 1670 | + |
| 1671 | + $padbuf = array(); |
| 1672 | + for($i=0; $i<$padlen; $i++) { |
| 1673 | + $padbuf[$i] = ($i&1)?0x11:0xec; |
| 1674 | + } |
| 1675 | + |
| 1676 | + $ret = $padding->appendBytes($padlen, $padbuf); |
| 1677 | + |
| 1678 | + if($ret < 0) |
| 1679 | + return $ret; |
| 1680 | + |
| 1681 | + } |
| 1682 | + |
| 1683 | + $ret = $bstream->append($padding); |
| 1684 | + |
| 1685 | + return $ret; |
| 1686 | + } |
| 1687 | + |
| 1688 | + //---------------------------------------------------------------------- |
| 1689 | + public function mergeBitStream() |
| 1690 | + { |
| 1691 | + if($this->convertData() < 0) { |
| 1692 | + return null; |
| 1693 | + } |
| 1694 | + |
| 1695 | + $bstream = new QRbitstream(); |
| 1696 | + |
| 1697 | + foreach($this->items as $item) { |
| 1698 | + $ret = $bstream->append($item->bstream); |
| 1699 | + if($ret < 0) { |
| 1700 | + return null; |
| 1701 | + } |
| 1702 | + } |
| 1703 | + |
| 1704 | + return $bstream; |
| 1705 | + } |
| 1706 | + |
| 1707 | + //---------------------------------------------------------------------- |
| 1708 | + public function getBitStream() |
| 1709 | + { |
| 1710 | + |
| 1711 | + $bstream = $this->mergeBitStream(); |
| 1712 | + |
| 1713 | + if($bstream == null) { |
| 1714 | + return null; |
| 1715 | + } |
| 1716 | + |
| 1717 | + $ret = $this->appendPaddingBit($bstream); |
| 1718 | + if($ret < 0) { |
| 1719 | + return null; |
| 1720 | + } |
| 1721 | + |
| 1722 | + return $bstream; |
| 1723 | + } |
| 1724 | + |
| 1725 | + //---------------------------------------------------------------------- |
| 1726 | + public function getByteStream() |
| 1727 | + { |
| 1728 | + $bstream = $this->getBitStream(); |
| 1729 | + if($bstream == null) { |
| 1730 | + return null; |
| 1731 | + } |
| 1732 | + |
| 1733 | + return $bstream->toByte(); |
| 1734 | + } |
| 1735 | + } |
| 1736 | + |
| 1737 | + |
| 1738 | + |
| 1739 | + |
| 1740 | + |
| 1741 | + |
1747 | 1742 | //---- qrbitstream.php ----------------------------- |
1748 | 1743 | |
1749 | 1744 | |
1750 | 1745 | |
1751 | | -
|
1752 | | -/*
|
1753 | | - * PHP QR Code encoder
|
1754 | | - *
|
1755 | | - * Bitstream class
|
1756 | | - *
|
1757 | | - * Based on libqrencode C library distributed under LGPL 2.1
|
1758 | | - * Copyright (C) 2006, 2007, 2008, 2009 Kentaro Fukuchi <fukuchi@megaui.net>
|
1759 | | - *
|
1760 | | - * PHP QR Code is distributed under LGPL 3
|
1761 | | - * Copyright (C) 2010 Dominik Dzienia <deltalab at poczta dot fm>
|
1762 | | - *
|
1763 | | - * This library is free software; you can redistribute it and/or
|
1764 | | - * modify it under the terms of the GNU Lesser General Public
|
1765 | | - * License as published by the Free Software Foundation; either
|
1766 | | - * version 3 of the License, or any later version.
|
1767 | | - *
|
1768 | | - * This library is distributed in the hope that it will be useful,
|
1769 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
1770 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
1771 | | - * Lesser General Public License for more details.
|
1772 | | - *
|
1773 | | - * You should have received a copy of the GNU Lesser General Public
|
1774 | | - * License along with this library; if not, write to the Free Software
|
1775 | | - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
1776 | | - */
|
1777 | | -
|
1778 | | - class QRbitstream {
|
1779 | | -
|
1780 | | - public $data = array();
|
1781 | | -
|
1782 | | - //----------------------------------------------------------------------
|
1783 | | - public function size()
|
1784 | | - {
|
1785 | | - return count($this->data);
|
1786 | | - }
|
1787 | | -
|
1788 | | - //----------------------------------------------------------------------
|
1789 | | - public function allocate($setLength)
|
1790 | | - {
|
1791 | | - $this->data = array_fill(0, $setLength, 0);
|
1792 | | - return 0;
|
1793 | | - }
|
1794 | | -
|
1795 | | - //----------------------------------------------------------------------
|
1796 | | - public static function newFromNum($bits, $num)
|
1797 | | - {
|
1798 | | - $bstream = new QRbitstream();
|
1799 | | - $bstream->allocate($bits);
|
1800 | | -
|
1801 | | - $mask = 1 << ($bits - 1);
|
1802 | | - for($i=0; $i<$bits; $i++) {
|
1803 | | - if($num & $mask) {
|
1804 | | - $bstream->data[$i] = 1;
|
1805 | | - } else {
|
1806 | | - $bstream->data[$i] = 0;
|
1807 | | - }
|
1808 | | - $mask = $mask >> 1;
|
1809 | | - }
|
1810 | | -
|
1811 | | - return $bstream;
|
1812 | | - }
|
1813 | | -
|
1814 | | - //----------------------------------------------------------------------
|
1815 | | - public static function newFromBytes($size, $data)
|
1816 | | - {
|
1817 | | - $bstream = new QRbitstream();
|
1818 | | - $bstream->allocate($size * 8);
|
1819 | | - $p=0;
|
1820 | | -
|
1821 | | - for($i=0; $i<$size; $i++) {
|
1822 | | - $mask = 0x80;
|
1823 | | - for($j=0; $j<8; $j++) {
|
1824 | | - if($data[$i] & $mask) {
|
1825 | | - $bstream->data[$p] = 1;
|
1826 | | - } else {
|
1827 | | - $bstream->data[$p] = 0;
|
1828 | | - }
|
1829 | | - $p++;
|
1830 | | - $mask = $mask >> 1;
|
1831 | | - }
|
1832 | | - }
|
1833 | | -
|
1834 | | - return $bstream;
|
1835 | | - }
|
1836 | | -
|
1837 | | - //----------------------------------------------------------------------
|
1838 | | - public function append(QRbitstream $arg)
|
1839 | | - {
|
1840 | | - if (is_null($arg)) {
|
1841 | | - return -1;
|
1842 | | - }
|
1843 | | -
|
1844 | | - if($arg->size() == 0) {
|
1845 | | - return 0;
|
1846 | | - }
|
1847 | | -
|
1848 | | - if($this->size() == 0) {
|
1849 | | - $this->data = $arg->data;
|
1850 | | - return 0;
|
1851 | | - }
|
1852 | | -
|
1853 | | - $this->data = array_values(array_merge($this->data, $arg->data));
|
1854 | | -
|
1855 | | - return 0;
|
1856 | | - }
|
1857 | | -
|
1858 | | - //----------------------------------------------------------------------
|
1859 | | - public function appendNum($bits, $num)
|
1860 | | - {
|
1861 | | - if ($bits == 0)
|
1862 | | - return 0;
|
1863 | | -
|
1864 | | - $b = QRbitstream::newFromNum($bits, $num);
|
1865 | | -
|
1866 | | - if(is_null($b))
|
1867 | | - return -1;
|
1868 | | -
|
1869 | | - $ret = $this->append($b);
|
1870 | | - unset($b);
|
1871 | | -
|
1872 | | - return $ret;
|
1873 | | - }
|
1874 | | -
|
1875 | | - //----------------------------------------------------------------------
|
1876 | | - public function appendBytes($size, $data)
|
1877 | | - {
|
1878 | | - if ($size == 0)
|
1879 | | - return 0;
|
1880 | | -
|
1881 | | - $b = QRbitstream::newFromBytes($size, $data);
|
1882 | | -
|
1883 | | - if(is_null($b))
|
1884 | | - return -1;
|
1885 | | -
|
1886 | | - $ret = $this->append($b);
|
1887 | | - unset($b);
|
1888 | | -
|
1889 | | - return $ret;
|
1890 | | - }
|
1891 | | -
|
1892 | | - //----------------------------------------------------------------------
|
1893 | | - public function toByte()
|
1894 | | - {
|
1895 | | -
|
1896 | | - $size = $this->size();
|
1897 | | -
|
1898 | | - if($size == 0) {
|
1899 | | - return array();
|
1900 | | - }
|
1901 | | -
|
1902 | | - $data = array_fill(0, (int)(($size + 7) / 8), 0);
|
1903 | | - $bytes = (int)($size / 8);
|
1904 | | -
|
1905 | | - $p = 0;
|
1906 | | -
|
1907 | | - for($i=0; $i<$bytes; $i++) {
|
1908 | | - $v = 0;
|
1909 | | - for($j=0; $j<8; $j++) {
|
1910 | | - $v = $v << 1;
|
1911 | | - $v |= $this->data[$p];
|
1912 | | - $p++;
|
1913 | | - }
|
1914 | | - $data[$i] = $v;
|
1915 | | - }
|
1916 | | -
|
1917 | | - if($size & 7) {
|
1918 | | - $v = 0;
|
1919 | | - for($j=0; $j<($size & 7); $j++) {
|
1920 | | - $v = $v << 1;
|
1921 | | - $v |= $this->data[$p];
|
1922 | | - $p++;
|
1923 | | - }
|
1924 | | - $data[$bytes] = $v;
|
1925 | | - }
|
1926 | | -
|
1927 | | - return $data;
|
1928 | | - }
|
1929 | | -
|
1930 | | - }
|
1931 | 1746 | |
| 1747 | +/* |
| 1748 | + * PHP QR Code encoder |
| 1749 | + * |
| 1750 | + * Bitstream class |
| 1751 | + * |
| 1752 | + * Based on libqrencode C library distributed under LGPL 2.1 |
| 1753 | + * Copyright (C) 2006, 2007, 2008, 2009 Kentaro Fukuchi <fukuchi@megaui.net> |
| 1754 | + * |
| 1755 | + * PHP QR Code is distributed under LGPL 3 |
| 1756 | + * Copyright (C) 2010 Dominik Dzienia <deltalab at poczta dot fm> |
| 1757 | + * |
| 1758 | + * This library is free software; you can redistribute it and/or |
| 1759 | + * modify it under the terms of the GNU Lesser General Public |
| 1760 | + * License as published by the Free Software Foundation; either |
| 1761 | + * version 3 of the License, or any later version. |
| 1762 | + * |
| 1763 | + * This library is distributed in the hope that it will be useful, |
| 1764 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 1765 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 1766 | + * Lesser General Public License for more details. |
| 1767 | + * |
| 1768 | + * You should have received a copy of the GNU Lesser General Public |
| 1769 | + * License along with this library; if not, write to the Free Software |
| 1770 | + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 1771 | + */ |
| 1772 | + |
| 1773 | + class QRbitstream { |
| 1774 | + |
| 1775 | + public $data = array(); |
| 1776 | + |
| 1777 | + //---------------------------------------------------------------------- |
| 1778 | + public function size() |
| 1779 | + { |
| 1780 | + return count($this->data); |
| 1781 | + } |
| 1782 | + |
| 1783 | + //---------------------------------------------------------------------- |
| 1784 | + public function allocate($setLength) |
| 1785 | + { |
| 1786 | + $this->data = array_fill(0, $setLength, 0); |
| 1787 | + return 0; |
| 1788 | + } |
| 1789 | + |
| 1790 | + //---------------------------------------------------------------------- |
| 1791 | + public static function newFromNum($bits, $num) |
| 1792 | + { |
| 1793 | + $bstream = new QRbitstream(); |
| 1794 | + $bstream->allocate($bits); |
| 1795 | + |
| 1796 | + $mask = 1 << ($bits - 1); |
| 1797 | + for($i=0; $i<$bits; $i++) { |
| 1798 | + if($num & $mask) { |
| 1799 | + $bstream->data[$i] = 1; |
| 1800 | + } else { |
| 1801 | + $bstream->data[$i] = 0; |
| 1802 | + } |
| 1803 | + $mask = $mask >> 1; |
| 1804 | + } |
1932 | 1805 | |
| 1806 | + return $bstream; |
| 1807 | + } |
| 1808 | + |
| 1809 | + //---------------------------------------------------------------------- |
| 1810 | + public static function newFromBytes($size, $data) |
| 1811 | + { |
| 1812 | + $bstream = new QRbitstream(); |
| 1813 | + $bstream->allocate($size * 8); |
| 1814 | + $p=0; |
1933 | 1815 | |
| 1816 | + for($i=0; $i<$size; $i++) { |
| 1817 | + $mask = 0x80; |
| 1818 | + for($j=0; $j<8; $j++) { |
| 1819 | + if($data[$i] & $mask) { |
| 1820 | + $bstream->data[$p] = 1; |
| 1821 | + } else { |
| 1822 | + $bstream->data[$p] = 0; |
| 1823 | + } |
| 1824 | + $p++; |
| 1825 | + $mask = $mask >> 1; |
| 1826 | + } |
| 1827 | + } |
1934 | 1828 | |
| 1829 | + return $bstream; |
| 1830 | + } |
| 1831 | + |
| 1832 | + //---------------------------------------------------------------------- |
| 1833 | + public function append(QRbitstream $arg) |
| 1834 | + { |
| 1835 | + if (is_null($arg)) { |
| 1836 | + return -1; |
| 1837 | + } |
| 1838 | + |
| 1839 | + if($arg->size() == 0) { |
| 1840 | + return 0; |
| 1841 | + } |
| 1842 | + |
| 1843 | + if($this->size() == 0) { |
| 1844 | + $this->data = $arg->data; |
| 1845 | + return 0; |
| 1846 | + } |
| 1847 | + |
| 1848 | + $this->data = array_values(array_merge($this->data, $arg->data)); |
| 1849 | + |
| 1850 | + return 0; |
| 1851 | + } |
| 1852 | + |
| 1853 | + //---------------------------------------------------------------------- |
| 1854 | + public function appendNum($bits, $num) |
| 1855 | + { |
| 1856 | + if ($bits == 0) |
| 1857 | + return 0; |
| 1858 | + |
| 1859 | + $b = QRbitstream::newFromNum($bits, $num); |
| 1860 | + |
| 1861 | + if(is_null($b)) |
| 1862 | + return -1; |
| 1863 | + |
| 1864 | + $ret = $this->append($b); |
| 1865 | + unset($b); |
| 1866 | + |
| 1867 | + return $ret; |
| 1868 | + } |
| 1869 | + |
| 1870 | + //---------------------------------------------------------------------- |
| 1871 | + public function appendBytes($size, $data) |
| 1872 | + { |
| 1873 | + if ($size == 0) |
| 1874 | + return 0; |
| 1875 | + |
| 1876 | + $b = QRbitstream::newFromBytes($size, $data); |
| 1877 | + |
| 1878 | + if(is_null($b)) |
| 1879 | + return -1; |
| 1880 | + |
| 1881 | + $ret = $this->append($b); |
| 1882 | + unset($b); |
| 1883 | + |
| 1884 | + return $ret; |
| 1885 | + } |
| 1886 | + |
| 1887 | + //---------------------------------------------------------------------- |
| 1888 | + public function toByte() |
| 1889 | + { |
| 1890 | + |
| 1891 | + $size = $this->size(); |
| 1892 | + |
| 1893 | + if($size == 0) { |
| 1894 | + return array(); |
| 1895 | + } |
| 1896 | + |
| 1897 | + $data = array_fill(0, (int)(($size + 7) / 8), 0); |
| 1898 | + $bytes = (int)($size / 8); |
| 1899 | + |
| 1900 | + $p = 0; |
| 1901 | + |
| 1902 | + for($i=0; $i<$bytes; $i++) { |
| 1903 | + $v = 0; |
| 1904 | + for($j=0; $j<8; $j++) { |
| 1905 | + $v = $v << 1; |
| 1906 | + $v |= $this->data[$p]; |
| 1907 | + $p++; |
| 1908 | + } |
| 1909 | + $data[$i] = $v; |
| 1910 | + } |
| 1911 | + |
| 1912 | + if($size & 7) { |
| 1913 | + $v = 0; |
| 1914 | + for($j=0; $j<($size & 7); $j++) { |
| 1915 | + $v = $v << 1; |
| 1916 | + $v |= $this->data[$p]; |
| 1917 | + $p++; |
| 1918 | + } |
| 1919 | + $data[$bytes] = $v; |
| 1920 | + } |
| 1921 | + |
| 1922 | + return $data; |
| 1923 | + } |
| 1924 | + |
| 1925 | + } |
| 1926 | + |
| 1927 | + |
| 1928 | + |
| 1929 | + |
1935 | 1930 | //---- qrsplit.php ----------------------------- |
1936 | 1931 | |
1937 | 1932 | |
1938 | 1933 | |
1939 | | -
|
1940 | | -/*
|
1941 | | - * PHP QR Code encoder
|
1942 | | - *
|
1943 | | - * Input splitting classes
|
1944 | | - *
|
1945 | | - * Based on libqrencode C library distributed under LGPL 2.1
|
1946 | | - * Copyright (C) 2006, 2007, 2008, 2009 Kentaro Fukuchi <fukuchi@megaui.net>
|
1947 | | - *
|
1948 | | - * PHP QR Code is distributed under LGPL 3
|
1949 | | - * Copyright (C) 2010 Dominik Dzienia <deltalab at poczta dot fm>
|
1950 | | - *
|
1951 | | - * The following data / specifications are taken from
|
1952 | | - * "Two dimensional symbol -- QR-code -- Basic Specification" (JIS X0510:2004)
|
1953 | | - * or
|
1954 | | - * "Automatic identification and data capture techniques --
|
1955 | | - * QR Code 2005 bar code symbology specification" (ISO/IEC 18004:2006)
|
1956 | | - *
|
1957 | | - * This library is free software; you can redistribute it and/or
|
1958 | | - * modify it under the terms of the GNU Lesser General Public
|
1959 | | - * License as published by the Free Software Foundation; either
|
1960 | | - * version 3 of the License, or any later version.
|
1961 | | - *
|
1962 | | - * This library is distributed in the hope that it will be useful,
|
1963 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
1964 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
1965 | | - * Lesser General Public License for more details.
|
1966 | | - *
|
1967 | | - * You should have received a copy of the GNU Lesser General Public
|
1968 | | - * License along with this library; if not, write to the Free Software
|
1969 | | - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
1970 | | - */
|
1971 | | - class QRsplit {
|
1972 | | -
|
1973 | | - public $dataStr = '';
|
1974 | | - public $input;
|
1975 | | - public $modeHint;
|
1976 | | -
|
1977 | | - //----------------------------------------------------------------------
|
1978 | | - public function __construct($dataStr, $input, $modeHint)
|
1979 | | - {
|
1980 | | - $this->dataStr = $dataStr;
|
1981 | | - $this->input = $input;
|
1982 | | - $this->modeHint = $modeHint;
|
1983 | | - }
|
1984 | | -
|
1985 | | - //----------------------------------------------------------------------
|
1986 | | - public static function isdigitat($str, $pos)
|
1987 | | - {
|
1988 | | - if ($pos >= strlen($str))
|
1989 | | - return false;
|
1990 | | -
|
1991 | | - return ((ord($str[$pos]) >= ord('0'))&&(ord($str[$pos]) <= ord('9')));
|
1992 | | - }
|
1993 | | -
|
1994 | | - //----------------------------------------------------------------------
|
1995 | | - public static function isalnumat($str, $pos)
|
1996 | | - {
|
1997 | | - if ($pos >= strlen($str))
|
1998 | | - return false;
|
1999 | | -
|
2000 | | - return (QRinput::lookAnTable(ord($str[$pos])) >= 0);
|
2001 | | - }
|
2002 | | -
|
2003 | | - //----------------------------------------------------------------------
|
2004 | | - public function identifyMode($pos)
|
2005 | | - {
|
2006 | | - if ($pos >= strlen($this->dataStr))
|
2007 | | - return QR_MODE_NUL;
|
2008 | | -
|
2009 | | - $c = $this->dataStr[$pos];
|
2010 | | -
|
2011 | | - if(self::isdigitat($this->dataStr, $pos)) {
|
2012 | | - return QR_MODE_NUM;
|
2013 | | - } else if(self::isalnumat($this->dataStr, $pos)) {
|
2014 | | - return QR_MODE_AN;
|
2015 | | - } else if($this->modeHint == QR_MODE_KANJI) {
|
2016 | | -
|
2017 | | - if ($pos+1 < strlen($this->dataStr))
|
2018 | | - {
|
2019 | | - $d = $this->dataStr[$pos+1];
|
2020 | | - $word = (ord($c) << 8) | ord($d);
|
2021 | | - if(($word >= 0x8140 && $word <= 0x9ffc) || ($word >= 0xe040 && $word <= 0xebbf)) {
|
2022 | | - return QR_MODE_KANJI;
|
2023 | | - }
|
2024 | | - }
|
2025 | | - }
|
2026 | | -
|
2027 | | - return QR_MODE_8;
|
2028 | | - }
|
2029 | | -
|
2030 | | - //----------------------------------------------------------------------
|
2031 | | - public function eatNum()
|
2032 | | - {
|
2033 | | - $ln = QRspec::lengthIndicator(QR_MODE_NUM, $this->input->getVersion());
|
2034 | | -
|
2035 | | - $p = 0;
|
2036 | | - while(self::isdigitat($this->dataStr, $p)) {
|
2037 | | - $p++;
|
2038 | | - }
|
2039 | | -
|
2040 | | - $run = $p;
|
2041 | | - $mode = $this->identifyMode($p);
|
2042 | | -
|
2043 | | - if($mode == QR_MODE_8) {
|
2044 | | - $dif = QRinput::estimateBitsModeNum($run) + 4 + $ln
|
2045 | | - + QRinput::estimateBitsMode8(1) // + 4 + l8
|
2046 | | - - QRinput::estimateBitsMode8($run + 1); // - 4 - l8
|
2047 | | - if($dif > 0) {
|
2048 | | - return $this->eat8();
|
2049 | | - }
|
2050 | | - }
|
2051 | | - if($mode == QR_MODE_AN) {
|
2052 | | - $dif = QRinput::estimateBitsModeNum($run) + 4 + $ln
|
2053 | | - + QRinput::estimateBitsModeAn(1) // + 4 + la
|
2054 | | - - QRinput::estimateBitsModeAn($run + 1);// - 4 - la
|
2055 | | - if($dif > 0) {
|
2056 | | - return $this->eatAn();
|
2057 | | - }
|
2058 | | - }
|
2059 | | -
|
2060 | | - $ret = $this->input->append(QR_MODE_NUM, $run, str_split($this->dataStr));
|
2061 | | - if($ret < 0)
|
2062 | | - return -1;
|
2063 | | -
|
2064 | | - return $run;
|
2065 | | - }
|
2066 | | -
|
2067 | | - //----------------------------------------------------------------------
|
2068 | | - public function eatAn()
|
2069 | | - {
|
2070 | | - $la = QRspec::lengthIndicator(QR_MODE_AN, $this->input->getVersion());
|
2071 | | - $ln = QRspec::lengthIndicator(QR_MODE_NUM, $this->input->getVersion());
|
2072 | | -
|
2073 | | - $p = 0;
|
2074 | | -
|
2075 | | - while(self::isalnumat($this->dataStr, $p)) {
|
2076 | | - if(self::isdigitat($this->dataStr, $p)) {
|
2077 | | - $q = $p;
|
2078 | | - while(self::isdigitat($this->dataStr, $q)) {
|
2079 | | - $q++;
|
2080 | | - }
|
2081 | | -
|
2082 | | - $dif = QRinput::estimateBitsModeAn($p) // + 4 + la
|
2083 | | - + QRinput::estimateBitsModeNum($q - $p) + 4 + $ln
|
2084 | | - - QRinput::estimateBitsModeAn($q); // - 4 - la
|
2085 | | -
|
2086 | | - if($dif < 0) {
|
2087 | | - break;
|
2088 | | - } else {
|
2089 | | - $p = $q;
|
2090 | | - }
|
2091 | | - } else {
|
2092 | | - $p++;
|
2093 | | - }
|
2094 | | - }
|
2095 | | -
|
2096 | | - $run = $p;
|
2097 | | -
|
2098 | | - if(!self::isalnumat($this->dataStr, $p)) {
|
2099 | | - $dif = QRinput::estimateBitsModeAn($run) + 4 + $la
|
2100 | | - + QRinput::estimateBitsMode8(1) // + 4 + l8
|
2101 | | - - QRinput::estimateBitsMode8($run + 1); // - 4 - l8
|
2102 | | - if($dif > 0) {
|
2103 | | - return $this->eat8();
|
2104 | | - }
|
2105 | | - }
|
2106 | | -
|
2107 | | - $ret = $this->input->append(QR_MODE_AN, $run, str_split($this->dataStr));
|
2108 | | - if($ret < 0)
|
2109 | | - return -1;
|
2110 | | -
|
2111 | | - return $run;
|
2112 | | - }
|
2113 | | -
|
2114 | | - //----------------------------------------------------------------------
|
2115 | | - public function eatKanji()
|
2116 | | - {
|
2117 | | - $p = 0;
|
2118 | | -
|
2119 | | - while($this->identifyMode($p) == QR_MODE_KANJI) {
|
2120 | | - $p += 2;
|
2121 | | - }
|
2122 | | -
|
2123 | | - $ret = $this->input->append(QR_MODE_KANJI, $p, str_split($this->dataStr));
|
2124 | | - if($ret < 0)
|
2125 | | - return -1;
|
2126 | | -
|
2127 | | - return $run;
|
2128 | | - }
|
2129 | | -
|
2130 | | - //----------------------------------------------------------------------
|
2131 | | - public function eat8()
|
2132 | | - {
|
2133 | | - $la = QRspec::lengthIndicator(QR_MODE_AN, $this->input->getVersion());
|
2134 | | - $ln = QRspec::lengthIndicator(QR_MODE_NUM, $this->input->getVersion());
|
2135 | | -
|
2136 | | - $p = 1;
|
2137 | | - $dataStrLen = strlen($this->dataStr);
|
2138 | | -
|
2139 | | - while($p < $dataStrLen) {
|
2140 | | -
|
2141 | | - $mode = $this->identifyMode($p);
|
2142 | | - if($mode == QR_MODE_KANJI) {
|
2143 | | - break;
|
2144 | | - }
|
2145 | | - if($mode == QR_MODE_NUM) {
|
2146 | | - $q = $p;
|
2147 | | - while(self::isdigitat($this->dataStr, $q)) {
|
2148 | | - $q++;
|
2149 | | - }
|
2150 | | - $dif = QRinput::estimateBitsMode8($p) // + 4 + l8
|
2151 | | - + QRinput::estimateBitsModeNum($q - $p) + 4 + $ln
|
2152 | | - - QRinput::estimateBitsMode8($q); // - 4 - l8
|
2153 | | - if($dif < 0) {
|
2154 | | - break;
|
2155 | | - } else {
|
2156 | | - $p = $q;
|
2157 | | - }
|
2158 | | - } else if($mode == QR_MODE_AN) {
|
2159 | | - $q = $p;
|
2160 | | - while(self::isalnumat($this->dataStr, $q)) {
|
2161 | | - $q++;
|
2162 | | - }
|
2163 | | - $dif = QRinput::estimateBitsMode8($p) // + 4 + l8
|
2164 | | - + QRinput::estimateBitsModeAn($q - $p) + 4 + $la
|
2165 | | - - QRinput::estimateBitsMode8($q); // - 4 - l8
|
2166 | | - if($dif < 0) {
|
2167 | | - break;
|
2168 | | - } else {
|
2169 | | - $p = $q;
|
2170 | | - }
|
2171 | | - } else {
|
2172 | | - $p++;
|
2173 | | - }
|
2174 | | - }
|
2175 | | -
|
2176 | | - $run = $p;
|
2177 | | - $ret = $this->input->append(QR_MODE_8, $run, str_split($this->dataStr));
|
2178 | | -
|
2179 | | - if($ret < 0)
|
2180 | | - return -1;
|
2181 | | -
|
2182 | | - return $run;
|
2183 | | - }
|
2184 | | -
|
2185 | | - //----------------------------------------------------------------------
|
2186 | | - public function splitString()
|
2187 | | - {
|
2188 | | - while (strlen($this->dataStr) > 0)
|
2189 | | - {
|
2190 | | - if($this->dataStr == '')
|
2191 | | - return 0;
|
2192 | | -
|
2193 | | - $mode = $this->identifyMode(0);
|
2194 | | -
|
2195 | | - switch ($mode) {
|
2196 | | - case QR_MODE_NUM: $length = $this->eatNum(); break;
|
2197 | | - case QR_MODE_AN: $length = $this->eatAn(); break;
|
2198 | | - case QR_MODE_KANJI:
|
2199 | | - if ($hint == QR_MODE_KANJI)
|
2200 | | - $length = $this->eatKanji();
|
2201 | | - else $length = $this->eat8();
|
2202 | | - break;
|
2203 | | - default: $length = $this->eat8(); break;
|
2204 | | -
|
2205 | | - }
|
2206 | | -
|
2207 | | - if($length == 0) return 0;
|
2208 | | - if($length < 0) return -1;
|
2209 | | -
|
2210 | | - $this->dataStr = substr($this->dataStr, $length);
|
2211 | | - }
|
2212 | | - }
|
2213 | | -
|
2214 | | - //----------------------------------------------------------------------
|
2215 | | - public function toUpper()
|
2216 | | - {
|
2217 | | - $stringLen = strlen($this->dataStr);
|
2218 | | - $p = 0;
|
2219 | | -
|
2220 | | - while ($p<$stringLen) {
|
2221 | | - $mode = self::identifyMode(substr($this->dataStr, $p), $this->modeHint);
|
2222 | | - if($mode == QR_MODE_KANJI) {
|
2223 | | - $p += 2;
|
2224 | | - } else {
|
2225 | | - if (ord($this->dataStr[$p]) >= ord('a') && ord($this->dataStr[$p]) <= ord('z')) {
|
2226 | | - $this->dataStr[$p] = chr(ord($this->dataStr[$p]) - 32);
|
2227 | | - }
|
2228 | | - $p++;
|
2229 | | - }
|
2230 | | - }
|
2231 | | -
|
2232 | | - return $this->dataStr;
|
2233 | | - }
|
2234 | | -
|
2235 | | - //----------------------------------------------------------------------
|
2236 | | - public static function splitStringToQRinput($string, QRinput $input, $modeHint, $casesensitive = true)
|
2237 | | - {
|
2238 | | - if(is_null($string) || $string == '\0' || $string == '') {
|
2239 | | - throw new Exception('empty string!!!');
|
2240 | | - }
|
2241 | | -
|
2242 | | - $split = new QRsplit($string, $input, $modeHint);
|
2243 | | -
|
2244 | | - if(!$casesensitive)
|
2245 | | - $split->toUpper();
|
2246 | | -
|
2247 | | - return $split->splitString();
|
2248 | | - }
|
| 1934 | + |
| 1935 | +/* |
| 1936 | + * PHP QR Code encoder |
| 1937 | + * |
| 1938 | + * Input splitting classes |
| 1939 | + * |
| 1940 | + * Based on libqrencode C library distributed under LGPL 2.1 |
| 1941 | + * Copyright (C) 2006, 2007, 2008, 2009 Kentaro Fukuchi <fukuchi@megaui.net> |
| 1942 | + * |
| 1943 | + * PHP QR Code is distributed under LGPL 3 |
| 1944 | + * Copyright (C) 2010 Dominik Dzienia <deltalab at poczta dot fm> |
| 1945 | + * |
| 1946 | + * The following data / specifications are taken from |
| 1947 | + * "Two dimensional symbol -- QR-code -- Basic Specification" (JIS X0510:2004) |
| 1948 | + * or |
| 1949 | + * "Automatic identification and data capture techniques -- |
| 1950 | + * QR Code 2005 bar code symbology specification" (ISO/IEC 18004:2006) |
| 1951 | + * |
| 1952 | + * This library is free software; you can redistribute it and/or |
| 1953 | + * modify it under the terms of the GNU Lesser General Public |
| 1954 | + * License as published by the Free Software Foundation; either |
| 1955 | + * version 3 of the License, or any later version. |
| 1956 | + * |
| 1957 | + * This library is distributed in the hope that it will be useful, |
| 1958 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 1959 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 1960 | + * Lesser General Public License for more details. |
| 1961 | + * |
| 1962 | + * You should have received a copy of the GNU Lesser General Public |
| 1963 | + * License along with this library; if not, write to the Free Software |
| 1964 | + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 1965 | + */ |
| 1966 | + class QRsplit { |
| 1967 | + |
| 1968 | + public $dataStr = ''; |
| 1969 | + public $input; |
| 1970 | + public $modeHint; |
| 1971 | + |
| 1972 | + //---------------------------------------------------------------------- |
| 1973 | + public function __construct($dataStr, $input, $modeHint) |
| 1974 | + { |
| 1975 | + $this->dataStr = $dataStr; |
| 1976 | + $this->input = $input; |
| 1977 | + $this->modeHint = $modeHint; |
| 1978 | + } |
| 1979 | + |
| 1980 | + //---------------------------------------------------------------------- |
| 1981 | + public static function isdigitat($str, $pos) |
| 1982 | + { |
| 1983 | + if ($pos >= strlen($str)) |
| 1984 | + return false; |
| 1985 | + |
| 1986 | + return ((ord($str[$pos]) >= ord('0'))&&(ord($str[$pos]) <= ord('9'))); |
| 1987 | + } |
| 1988 | + |
| 1989 | + //---------------------------------------------------------------------- |
| 1990 | + public static function isalnumat($str, $pos) |
| 1991 | + { |
| 1992 | + if ($pos >= strlen($str)) |
| 1993 | + return false; |
| 1994 | + |
| 1995 | + return (QRinput::lookAnTable(ord($str[$pos])) >= 0); |
| 1996 | + } |
| 1997 | + |
| 1998 | + //---------------------------------------------------------------------- |
| 1999 | + public function identifyMode($pos) |
| 2000 | + { |
| 2001 | + if ($pos >= strlen($this->dataStr)) |
| 2002 | + return QR_MODE_NUL; |
| 2003 | + |
| 2004 | + $c = $this->dataStr[$pos]; |
| 2005 | + |
| 2006 | + if(self::isdigitat($this->dataStr, $pos)) { |
| 2007 | + return QR_MODE_NUM; |
| 2008 | + } else if(self::isalnumat($this->dataStr, $pos)) { |
| 2009 | + return QR_MODE_AN; |
| 2010 | + } else if($this->modeHint == QR_MODE_KANJI) { |
| 2011 | + |
| 2012 | + if ($pos+1 < strlen($this->dataStr)) |
| 2013 | + { |
| 2014 | + $d = $this->dataStr[$pos+1]; |
| 2015 | + $word = (ord($c) << 8) | ord($d); |
| 2016 | + if(($word >= 0x8140 && $word <= 0x9ffc) || ($word >= 0xe040 && $word <= 0xebbf)) { |
| 2017 | + return QR_MODE_KANJI; |
| 2018 | + } |
| 2019 | + } |
| 2020 | + } |
| 2021 | + |
| 2022 | + return QR_MODE_8; |
| 2023 | + } |
| 2024 | + |
| 2025 | + //---------------------------------------------------------------------- |
| 2026 | + public function eatNum() |
| 2027 | + { |
| 2028 | + $ln = QRspec::lengthIndicator(QR_MODE_NUM, $this->input->getVersion()); |
| 2029 | + |
| 2030 | + $p = 0; |
| 2031 | + while(self::isdigitat($this->dataStr, $p)) { |
| 2032 | + $p++; |
| 2033 | + } |
| 2034 | + |
| 2035 | + $run = $p; |
| 2036 | + $mode = $this->identifyMode($p); |
| 2037 | + |
| 2038 | + if($mode == QR_MODE_8) { |
| 2039 | + $dif = QRinput::estimateBitsModeNum($run) + 4 + $ln |
| 2040 | + + QRinput::estimateBitsMode8(1) // + 4 + l8 |
| 2041 | + - QRinput::estimateBitsMode8($run + 1); // - 4 - l8 |
| 2042 | + if($dif > 0) { |
| 2043 | + return $this->eat8(); |
| 2044 | + } |
| 2045 | + } |
| 2046 | + if($mode == QR_MODE_AN) { |
| 2047 | + $dif = QRinput::estimateBitsModeNum($run) + 4 + $ln |
| 2048 | + + QRinput::estimateBitsModeAn(1) // + 4 + la |
| 2049 | + - QRinput::estimateBitsModeAn($run + 1);// - 4 - la |
| 2050 | + if($dif > 0) { |
| 2051 | + return $this->eatAn(); |
| 2052 | + } |
| 2053 | + } |
| 2054 | + |
| 2055 | + $ret = $this->input->append(QR_MODE_NUM, $run, str_split($this->dataStr)); |
| 2056 | + if($ret < 0) |
| 2057 | + return -1; |
| 2058 | + |
| 2059 | + return $run; |
| 2060 | + } |
| 2061 | + |
| 2062 | + //---------------------------------------------------------------------- |
| 2063 | + public function eatAn() |
| 2064 | + { |
| 2065 | + $la = QRspec::lengthIndicator(QR_MODE_AN, $this->input->getVersion()); |
| 2066 | + $ln = QRspec::lengthIndicator(QR_MODE_NUM, $this->input->getVersion()); |
| 2067 | + |
| 2068 | + $p = 0; |
| 2069 | + |
| 2070 | + while(self::isalnumat($this->dataStr, $p)) { |
| 2071 | + if(self::isdigitat($this->dataStr, $p)) { |
| 2072 | + $q = $p; |
| 2073 | + while(self::isdigitat($this->dataStr, $q)) { |
| 2074 | + $q++; |
| 2075 | + } |
| 2076 | + |
| 2077 | + $dif = QRinput::estimateBitsModeAn($p) // + 4 + la |
| 2078 | + + QRinput::estimateBitsModeNum($q - $p) + 4 + $ln |
| 2079 | + - QRinput::estimateBitsModeAn($q); // - 4 - la |
| 2080 | + |
| 2081 | + if($dif < 0) { |
| 2082 | + break; |
| 2083 | + } else { |
| 2084 | + $p = $q; |
| 2085 | + } |
| 2086 | + } else { |
| 2087 | + $p++; |
| 2088 | + } |
| 2089 | + } |
| 2090 | + |
| 2091 | + $run = $p; |
| 2092 | + |
| 2093 | + if(!self::isalnumat($this->dataStr, $p)) { |
| 2094 | + $dif = QRinput::estimateBitsModeAn($run) + 4 + $la |
| 2095 | + + QRinput::estimateBitsMode8(1) // + 4 + l8 |
| 2096 | + - QRinput::estimateBitsMode8($run + 1); // - 4 - l8 |
| 2097 | + if($dif > 0) { |
| 2098 | + return $this->eat8(); |
| 2099 | + } |
| 2100 | + } |
| 2101 | + |
| 2102 | + $ret = $this->input->append(QR_MODE_AN, $run, str_split($this->dataStr)); |
| 2103 | + if($ret < 0) |
| 2104 | + return -1; |
| 2105 | + |
| 2106 | + return $run; |
| 2107 | + } |
| 2108 | + |
| 2109 | + //---------------------------------------------------------------------- |
| 2110 | + public function eatKanji() |
| 2111 | + { |
| 2112 | + $p = 0; |
| 2113 | + |
| 2114 | + while($this->identifyMode($p) == QR_MODE_KANJI) { |
| 2115 | + $p += 2; |
| 2116 | + } |
| 2117 | + |
| 2118 | + $ret = $this->input->append(QR_MODE_KANJI, $p, str_split($this->dataStr)); |
| 2119 | + if($ret < 0) |
| 2120 | + return -1; |
| 2121 | + |
| 2122 | + return $ret; |
| 2123 | + } |
| 2124 | + |
| 2125 | + //---------------------------------------------------------------------- |
| 2126 | + public function eat8() |
| 2127 | + { |
| 2128 | + $la = QRspec::lengthIndicator(QR_MODE_AN, $this->input->getVersion()); |
| 2129 | + $ln = QRspec::lengthIndicator(QR_MODE_NUM, $this->input->getVersion()); |
| 2130 | + |
| 2131 | + $p = 1; |
| 2132 | + $dataStrLen = strlen($this->dataStr); |
| 2133 | + |
| 2134 | + while($p < $dataStrLen) { |
| 2135 | + |
| 2136 | + $mode = $this->identifyMode($p); |
| 2137 | + if($mode == QR_MODE_KANJI) { |
| 2138 | + break; |
| 2139 | + } |
| 2140 | + if($mode == QR_MODE_NUM) { |
| 2141 | + $q = $p; |
| 2142 | + while(self::isdigitat($this->dataStr, $q)) { |
| 2143 | + $q++; |
| 2144 | + } |
| 2145 | + $dif = QRinput::estimateBitsMode8($p) // + 4 + l8 |
| 2146 | + + QRinput::estimateBitsModeNum($q - $p) + 4 + $ln |
| 2147 | + - QRinput::estimateBitsMode8($q); // - 4 - l8 |
| 2148 | + if($dif < 0) { |
| 2149 | + break; |
| 2150 | + } else { |
| 2151 | + $p = $q; |
| 2152 | + } |
| 2153 | + } else if($mode == QR_MODE_AN) { |
| 2154 | + $q = $p; |
| 2155 | + while(self::isalnumat($this->dataStr, $q)) { |
| 2156 | + $q++; |
| 2157 | + } |
| 2158 | + $dif = QRinput::estimateBitsMode8($p) // + 4 + l8 |
| 2159 | + + QRinput::estimateBitsModeAn($q - $p) + 4 + $la |
| 2160 | + - QRinput::estimateBitsMode8($q); // - 4 - l8 |
| 2161 | + if($dif < 0) { |
| 2162 | + break; |
| 2163 | + } else { |
| 2164 | + $p = $q; |
| 2165 | + } |
| 2166 | + } else { |
| 2167 | + $p++; |
| 2168 | + } |
| 2169 | + } |
| 2170 | + |
| 2171 | + $run = $p; |
| 2172 | + $ret = $this->input->append(QR_MODE_8, $run, str_split($this->dataStr)); |
| 2173 | + |
| 2174 | + if($ret < 0) |
| 2175 | + return -1; |
| 2176 | + |
| 2177 | + return $run; |
| 2178 | + } |
| 2179 | + |
| 2180 | + //---------------------------------------------------------------------- |
| 2181 | + public function splitString() |
| 2182 | + { |
| 2183 | + while (strlen($this->dataStr) > 0) |
| 2184 | + { |
| 2185 | + if($this->dataStr == '') |
| 2186 | + return 0; |
| 2187 | + |
| 2188 | + $mode = $this->identifyMode(0); |
| 2189 | + |
| 2190 | + switch ($mode) { |
| 2191 | + case QR_MODE_NUM: $length = $this->eatNum(); break; |
| 2192 | + case QR_MODE_AN: $length = $this->eatAn(); break; |
| 2193 | + case QR_MODE_KANJI: |
| 2194 | + if ($hint == QR_MODE_KANJI) |
| 2195 | + $length = $this->eatKanji(); |
| 2196 | + else $length = $this->eat8(); |
| 2197 | + break; |
| 2198 | + default: $length = $this->eat8(); break; |
| 2199 | + |
| 2200 | + } |
| 2201 | + |
| 2202 | + if($length == 0) return 0; |
| 2203 | + if($length < 0) return -1; |
| 2204 | + |
| 2205 | + $this->dataStr = substr($this->dataStr, $length); |
| 2206 | + } |
| 2207 | + } |
| 2208 | + |
| 2209 | + //---------------------------------------------------------------------- |
| 2210 | + public function toUpper() |
| 2211 | + { |
| 2212 | + $stringLen = strlen($this->dataStr); |
| 2213 | + $p = 0; |
| 2214 | + |
| 2215 | + while ($p<$stringLen) { |
| 2216 | + $mode = self::identifyMode(substr($this->dataStr, $p), $this->modeHint); |
| 2217 | + if($mode == QR_MODE_KANJI) { |
| 2218 | + $p += 2; |
| 2219 | + } else { |
| 2220 | + if (ord($this->dataStr[$p]) >= ord('a') && ord($this->dataStr[$p]) <= ord('z')) { |
| 2221 | + $this->dataStr[$p] = chr(ord($this->dataStr[$p]) - 32); |
| 2222 | + } |
| 2223 | + $p++; |
| 2224 | + } |
| 2225 | + } |
| 2226 | + |
| 2227 | + return $this->dataStr; |
| 2228 | + } |
| 2229 | + |
| 2230 | + //---------------------------------------------------------------------- |
| 2231 | + public static function splitStringToQRinput($string, QRinput $input, $modeHint, $casesensitive = true) |
| 2232 | + { |
| 2233 | + if(is_null($string) || $string == '\0' || $string == '') { |
| 2234 | + throw new Exception('empty string!!!'); |
| 2235 | + } |
| 2236 | + |
| 2237 | + $split = new QRsplit($string, $input, $modeHint); |
| 2238 | + |
| 2239 | + if(!$casesensitive) |
| 2240 | + $split->toUpper(); |
| 2241 | + |
| 2242 | + return $split->splitString(); |
| 2243 | + } |
2249 | 2244 | } |
2250 | 2245 | |
2251 | 2246 | |
— | — | @@ -2253,1060 +2248,1055 @@ |
2254 | 2249 | |
2255 | 2250 | |
2256 | 2251 | |
2257 | | -
|
2258 | | -/*
|
2259 | | - * PHP QR Code encoder
|
2260 | | - *
|
2261 | | - * Reed-Solomon error correction support
|
2262 | | - *
|
2263 | | - * Copyright (C) 2002, 2003, 2004, 2006 Phil Karn, KA9Q
|
2264 | | - * (libfec is released under the GNU Lesser General Public License.)
|
2265 | | - *
|
2266 | | - * Based on libqrencode C library distributed under LGPL 2.1
|
2267 | | - * Copyright (C) 2006, 2007, 2008, 2009 Kentaro Fukuchi <fukuchi@megaui.net>
|
2268 | | - *
|
2269 | | - * PHP QR Code is distributed under LGPL 3
|
2270 | | - * Copyright (C) 2010 Dominik Dzienia <deltalab at poczta dot fm>
|
2271 | | - *
|
2272 | | - * This library is free software; you can redistribute it and/or
|
2273 | | - * modify it under the terms of the GNU Lesser General Public
|
2274 | | - * License as published by the Free Software Foundation; either
|
2275 | | - * version 3 of the License, or any later version.
|
2276 | | - *
|
2277 | | - * This library is distributed in the hope that it will be useful,
|
2278 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2279 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
2280 | | - * Lesser General Public License for more details.
|
2281 | | - *
|
2282 | | - * You should have received a copy of the GNU Lesser General Public
|
2283 | | - * License along with this library; if not, write to the Free Software
|
2284 | | - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
2285 | | - */
|
2286 | | -
|
2287 | | - class QRrsItem {
|
2288 | | -
|
2289 | | - public $mm; // Bits per symbol
|
2290 | | - public $nn; // Symbols per block (= (1<<mm)-1)
|
2291 | | - public $alpha_to = array(); // log lookup table
|
2292 | | - public $index_of = array(); // Antilog lookup table
|
2293 | | - public $genpoly = array(); // Generator polynomial
|
2294 | | - public $nroots; // Number of generator roots = number of parity symbols
|
2295 | | - public $fcr; // First consecutive root, index form
|
2296 | | - public $prim; // Primitive element, index form
|
2297 | | - public $iprim; // prim-th root of 1, index form
|
2298 | | - public $pad; // Padding bytes in shortened block
|
2299 | | - public $gfpoly;
|
2300 | | -
|
2301 | | - //----------------------------------------------------------------------
|
2302 | | - public function modnn($x)
|
2303 | | - {
|
2304 | | - while ($x >= $this->nn) {
|
2305 | | - $x -= $this->nn;
|
2306 | | - $x = ($x >> $this->mm) + ($x & $this->nn);
|
2307 | | - }
|
2308 | | -
|
2309 | | - return $x;
|
2310 | | - }
|
2311 | | -
|
2312 | | - //----------------------------------------------------------------------
|
2313 | | - public static function init_rs_char($symsize, $gfpoly, $fcr, $prim, $nroots, $pad)
|
2314 | | - {
|
2315 | | - // Common code for intializing a Reed-Solomon control block (char or int symbols)
|
2316 | | - // Copyright 2004 Phil Karn, KA9Q
|
2317 | | - // May be used under the terms of the GNU Lesser General Public License (LGPL)
|
2318 | | -
|
2319 | | - $rs = null;
|
2320 | | -
|
2321 | | - // Check parameter ranges
|
2322 | | - if($symsize < 0 || $symsize > 8) return $rs;
|
2323 | | - if($fcr < 0 || $fcr >= (1<<$symsize)) return $rs;
|
2324 | | - if($prim <= 0 || $prim >= (1<<$symsize)) return $rs;
|
2325 | | - if($nroots < 0 || $nroots >= (1<<$symsize)) return $rs; // Can't have more roots than symbol values!
|
2326 | | - if($pad < 0 || $pad >= ((1<<$symsize) -1 - $nroots)) return $rs; // Too much padding
|
2327 | | -
|
2328 | | - $rs = new QRrsItem();
|
2329 | | - $rs->mm = $symsize;
|
2330 | | - $rs->nn = (1<<$symsize)-1;
|
2331 | | - $rs->pad = $pad;
|
2332 | | -
|
2333 | | - $rs->alpha_to = array_fill(0, $rs->nn+1, 0);
|
2334 | | - $rs->index_of = array_fill(0, $rs->nn+1, 0);
|
2335 | | -
|
2336 | | - // PHP style macro replacement ;)
|
2337 | | - $NN =& $rs->nn;
|
2338 | | - $A0 =& $NN;
|
2339 | | -
|
2340 | | - // Generate Galois field lookup tables
|
2341 | | - $rs->index_of[0] = $A0; // log(zero) = -inf
|
2342 | | - $rs->alpha_to[$A0] = 0; // alpha**-inf = 0
|
2343 | | - $sr = 1;
|
2344 | | -
|
2345 | | - for($i=0; $i<$rs->nn; $i++) {
|
2346 | | - $rs->index_of[$sr] = $i;
|
2347 | | - $rs->alpha_to[$i] = $sr;
|
2348 | | - $sr <<= 1;
|
2349 | | - if($sr & (1<<$symsize)) {
|
2350 | | - $sr ^= $gfpoly;
|
2351 | | - }
|
2352 | | - $sr &= $rs->nn;
|
2353 | | - }
|
2354 | | -
|
2355 | | - if($sr != 1){
|
2356 | | - // field generator polynomial is not primitive!
|
2357 | | - $rs = NULL;
|
2358 | | - return $rs;
|
2359 | | - }
|
2360 | | -
|
2361 | | - /* Form RS code generator polynomial from its roots */
|
2362 | | - $rs->genpoly = array_fill(0, $nroots+1, 0);
|
2363 | | -
|
2364 | | - $rs->fcr = $fcr;
|
2365 | | - $rs->prim = $prim;
|
2366 | | - $rs->nroots = $nroots;
|
2367 | | - $rs->gfpoly = $gfpoly;
|
2368 | | -
|
2369 | | - /* Find prim-th root of 1, used in decoding */
|
2370 | | - for($iprim=1;($iprim % $prim) != 0;$iprim += $rs->nn)
|
2371 | | - ; // intentional empty-body loop!
|
2372 | | -
|
2373 | | - $rs->iprim = (int)($iprim / $prim);
|
2374 | | - $rs->genpoly[0] = 1;
|
2375 | | -
|
2376 | | - for ($i = 0,$root=$fcr*$prim; $i < $nroots; $i++, $root += $prim) {
|
2377 | | - $rs->genpoly[$i+1] = 1;
|
2378 | | -
|
2379 | | - // Multiply rs->genpoly[] by @**(root + x)
|
2380 | | - for ($j = $i; $j > 0; $j--) {
|
2381 | | - if ($rs->genpoly[$j] != 0) {
|
2382 | | - $rs->genpoly[$j] = $rs->genpoly[$j-1] ^ $rs->alpha_to[$rs->modnn($rs->index_of[$rs->genpoly[$j]] + $root)];
|
2383 | | - } else {
|
2384 | | - $rs->genpoly[$j] = $rs->genpoly[$j-1];
|
2385 | | - }
|
2386 | | - }
|
2387 | | - // rs->genpoly[0] can never be zero
|
2388 | | - $rs->genpoly[0] = $rs->alpha_to[$rs->modnn($rs->index_of[$rs->genpoly[0]] + $root)];
|
2389 | | - }
|
2390 | | -
|
2391 | | - // convert rs->genpoly[] to index form for quicker encoding
|
2392 | | - for ($i = 0; $i <= $nroots; $i++)
|
2393 | | - $rs->genpoly[$i] = $rs->index_of[$rs->genpoly[$i]];
|
2394 | | -
|
2395 | | - return $rs;
|
2396 | | - }
|
2397 | | -
|
2398 | | - //----------------------------------------------------------------------
|
2399 | | - public function encode_rs_char($data, &$parity)
|
2400 | | - {
|
2401 | | - $MM =& $this->mm;
|
2402 | | - $NN =& $this->nn;
|
2403 | | - $ALPHA_TO =& $this->alpha_to;
|
2404 | | - $INDEX_OF =& $this->index_of;
|
2405 | | - $GENPOLY =& $this->genpoly;
|
2406 | | - $NROOTS =& $this->nroots;
|
2407 | | - $FCR =& $this->fcr;
|
2408 | | - $PRIM =& $this->prim;
|
2409 | | - $IPRIM =& $this->iprim;
|
2410 | | - $PAD =& $this->pad;
|
2411 | | - $A0 =& $NN;
|
2412 | | -
|
2413 | | - $parity = array_fill(0, $NROOTS, 0);
|
2414 | | -
|
2415 | | - for($i=0; $i< ($NN-$NROOTS-$PAD); $i++) {
|
2416 | | -
|
2417 | | - $feedback = $INDEX_OF[$data[$i] ^ $parity[0]];
|
2418 | | - if($feedback != $A0) {
|
2419 | | - // feedback term is non-zero
|
2420 | | -
|
2421 | | - // This line is unnecessary when GENPOLY[NROOTS] is unity, as it must
|
2422 | | - // always be for the polynomials constructed by init_rs()
|
2423 | | - $feedback = $this->modnn($NN - $GENPOLY[$NROOTS] + $feedback);
|
2424 | | -
|
2425 | | - for($j=1;$j<$NROOTS;$j++) {
|
2426 | | - $parity[$j] ^= $ALPHA_TO[$this->modnn($feedback + $GENPOLY[$NROOTS-$j])];
|
2427 | | - }
|
2428 | | - }
|
2429 | | -
|
2430 | | - // Shift
|
2431 | | - array_shift($parity);
|
2432 | | - if($feedback != $A0) {
|
2433 | | - array_push($parity, $ALPHA_TO[$this->modnn($feedback + $GENPOLY[0])]);
|
2434 | | - } else {
|
2435 | | - array_push($parity, 0);
|
2436 | | - }
|
2437 | | - }
|
2438 | | - }
|
2439 | | - }
|
2440 | | -
|
2441 | | - //##########################################################################
|
2442 | | -
|
2443 | | - class QRrs {
|
2444 | | -
|
2445 | | - public static $items = array();
|
2446 | | -
|
2447 | | - //----------------------------------------------------------------------
|
2448 | | - public static function init_rs($symsize, $gfpoly, $fcr, $prim, $nroots, $pad)
|
2449 | | - {
|
2450 | | - foreach(self::$items as $rs) {
|
2451 | | - if($rs->pad != $pad) continue;
|
2452 | | - if($rs->nroots != $nroots) continue;
|
2453 | | - if($rs->mm != $symsize) continue;
|
2454 | | - if($rs->gfpoly != $gfpoly) continue;
|
2455 | | - if($rs->fcr != $fcr) continue;
|
2456 | | - if($rs->prim != $prim) continue;
|
2457 | | -
|
2458 | | - return $rs;
|
2459 | | - }
|
2460 | | -
|
2461 | | - $rs = QRrsItem::init_rs_char($symsize, $gfpoly, $fcr, $prim, $nroots, $pad);
|
2462 | | - array_unshift(self::$items, $rs);
|
2463 | | -
|
2464 | | - return $rs;
|
2465 | | - }
|
| 2252 | + |
| 2253 | +/* |
| 2254 | + * PHP QR Code encoder |
| 2255 | + * |
| 2256 | + * Reed-Solomon error correction support |
| 2257 | + * |
| 2258 | + * Copyright (C) 2002, 2003, 2004, 2006 Phil Karn, KA9Q |
| 2259 | + * (libfec is released under the GNU Lesser General Public License.) |
| 2260 | + * |
| 2261 | + * Based on libqrencode C library distributed under LGPL 2.1 |
| 2262 | + * Copyright (C) 2006, 2007, 2008, 2009 Kentaro Fukuchi <fukuchi@megaui.net> |
| 2263 | + * |
| 2264 | + * PHP QR Code is distributed under LGPL 3 |
| 2265 | + * Copyright (C) 2010 Dominik Dzienia <deltalab at poczta dot fm> |
| 2266 | + * |
| 2267 | + * This library is free software; you can redistribute it and/or |
| 2268 | + * modify it under the terms of the GNU Lesser General Public |
| 2269 | + * License as published by the Free Software Foundation; either |
| 2270 | + * version 3 of the License, or any later version. |
| 2271 | + * |
| 2272 | + * This library is distributed in the hope that it will be useful, |
| 2273 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 2274 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 2275 | + * Lesser General Public License for more details. |
| 2276 | + * |
| 2277 | + * You should have received a copy of the GNU Lesser General Public |
| 2278 | + * License along with this library; if not, write to the Free Software |
| 2279 | + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 2280 | + */ |
| 2281 | + |
| 2282 | + class QRrsItem { |
| 2283 | + |
| 2284 | + public $mm; // Bits per symbol |
| 2285 | + public $nn; // Symbols per block (= (1<<mm)-1) |
| 2286 | + public $alpha_to = array(); // log lookup table |
| 2287 | + public $index_of = array(); // Antilog lookup table |
| 2288 | + public $genpoly = array(); // Generator polynomial |
| 2289 | + public $nroots; // Number of generator roots = number of parity symbols |
| 2290 | + public $fcr; // First consecutive root, index form |
| 2291 | + public $prim; // Primitive element, index form |
| 2292 | + public $iprim; // prim-th root of 1, index form |
| 2293 | + public $pad; // Padding bytes in shortened block |
| 2294 | + public $gfpoly; |
| 2295 | + |
| 2296 | + //---------------------------------------------------------------------- |
| 2297 | + public function modnn($x) |
| 2298 | + { |
| 2299 | + while ($x >= $this->nn) { |
| 2300 | + $x -= $this->nn; |
| 2301 | + $x = ($x >> $this->mm) + ($x & $this->nn); |
| 2302 | + } |
| 2303 | + |
| 2304 | + return $x; |
| 2305 | + } |
| 2306 | + |
| 2307 | + //---------------------------------------------------------------------- |
| 2308 | + public static function init_rs_char($symsize, $gfpoly, $fcr, $prim, $nroots, $pad) |
| 2309 | + { |
| 2310 | + // Common code for intializing a Reed-Solomon control block (char or int symbols) |
| 2311 | + // Copyright 2004 Phil Karn, KA9Q |
| 2312 | + // May be used under the terms of the GNU Lesser General Public License (LGPL) |
| 2313 | + |
| 2314 | + $rs = null; |
| 2315 | + |
| 2316 | + // Check parameter ranges |
| 2317 | + if($symsize < 0 || $symsize > 8) return $rs; |
| 2318 | + if($fcr < 0 || $fcr >= (1<<$symsize)) return $rs; |
| 2319 | + if($prim <= 0 || $prim >= (1<<$symsize)) return $rs; |
| 2320 | + if($nroots < 0 || $nroots >= (1<<$symsize)) return $rs; // Can't have more roots than symbol values! |
| 2321 | + if($pad < 0 || $pad >= ((1<<$symsize) -1 - $nroots)) return $rs; // Too much padding |
| 2322 | + |
| 2323 | + $rs = new QRrsItem(); |
| 2324 | + $rs->mm = $symsize; |
| 2325 | + $rs->nn = (1<<$symsize)-1; |
| 2326 | + $rs->pad = $pad; |
| 2327 | + |
| 2328 | + $rs->alpha_to = array_fill(0, $rs->nn+1, 0); |
| 2329 | + $rs->index_of = array_fill(0, $rs->nn+1, 0); |
| 2330 | + |
| 2331 | + // PHP style macro replacement ;) |
| 2332 | + $NN =& $rs->nn; |
| 2333 | + $A0 =& $NN; |
| 2334 | + |
| 2335 | + // Generate Galois field lookup tables |
| 2336 | + $rs->index_of[0] = $A0; // log(zero) = -inf |
| 2337 | + $rs->alpha_to[$A0] = 0; // alpha**-inf = 0 |
| 2338 | + $sr = 1; |
| 2339 | + |
| 2340 | + for($i=0; $i<$rs->nn; $i++) { |
| 2341 | + $rs->index_of[$sr] = $i; |
| 2342 | + $rs->alpha_to[$i] = $sr; |
| 2343 | + $sr <<= 1; |
| 2344 | + if($sr & (1<<$symsize)) { |
| 2345 | + $sr ^= $gfpoly; |
| 2346 | + } |
| 2347 | + $sr &= $rs->nn; |
| 2348 | + } |
| 2349 | + |
| 2350 | + if($sr != 1){ |
| 2351 | + // field generator polynomial is not primitive! |
| 2352 | + $rs = NULL; |
| 2353 | + return $rs; |
| 2354 | + } |
| 2355 | + |
| 2356 | + /* Form RS code generator polynomial from its roots */ |
| 2357 | + $rs->genpoly = array_fill(0, $nroots+1, 0); |
| 2358 | + |
| 2359 | + $rs->fcr = $fcr; |
| 2360 | + $rs->prim = $prim; |
| 2361 | + $rs->nroots = $nroots; |
| 2362 | + $rs->gfpoly = $gfpoly; |
| 2363 | + |
| 2364 | + /* Find prim-th root of 1, used in decoding */ |
| 2365 | + for($iprim=1;($iprim % $prim) != 0;$iprim += $rs->nn) |
| 2366 | + ; // intentional empty-body loop! |
| 2367 | + |
| 2368 | + $rs->iprim = (int)($iprim / $prim); |
| 2369 | + $rs->genpoly[0] = 1; |
| 2370 | + |
| 2371 | + for ($i = 0,$root=$fcr*$prim; $i < $nroots; $i++, $root += $prim) { |
| 2372 | + $rs->genpoly[$i+1] = 1; |
| 2373 | + |
| 2374 | + // Multiply rs->genpoly[] by @**(root + x) |
| 2375 | + for ($j = $i; $j > 0; $j--) { |
| 2376 | + if ($rs->genpoly[$j] != 0) { |
| 2377 | + $rs->genpoly[$j] = $rs->genpoly[$j-1] ^ $rs->alpha_to[$rs->modnn($rs->index_of[$rs->genpoly[$j]] + $root)]; |
| 2378 | + } else { |
| 2379 | + $rs->genpoly[$j] = $rs->genpoly[$j-1]; |
| 2380 | + } |
| 2381 | + } |
| 2382 | + // rs->genpoly[0] can never be zero |
| 2383 | + $rs->genpoly[0] = $rs->alpha_to[$rs->modnn($rs->index_of[$rs->genpoly[0]] + $root)]; |
| 2384 | + } |
| 2385 | + |
| 2386 | + // convert rs->genpoly[] to index form for quicker encoding |
| 2387 | + for ($i = 0; $i <= $nroots; $i++) |
| 2388 | + $rs->genpoly[$i] = $rs->index_of[$rs->genpoly[$i]]; |
| 2389 | + |
| 2390 | + return $rs; |
| 2391 | + } |
| 2392 | + |
| 2393 | + //---------------------------------------------------------------------- |
| 2394 | + public function encode_rs_char($data, &$parity) |
| 2395 | + { |
| 2396 | + $MM =& $this->mm; |
| 2397 | + $NN =& $this->nn; |
| 2398 | + $ALPHA_TO =& $this->alpha_to; |
| 2399 | + $INDEX_OF =& $this->index_of; |
| 2400 | + $GENPOLY =& $this->genpoly; |
| 2401 | + $NROOTS =& $this->nroots; |
| 2402 | + $FCR =& $this->fcr; |
| 2403 | + $PRIM =& $this->prim; |
| 2404 | + $IPRIM =& $this->iprim; |
| 2405 | + $PAD =& $this->pad; |
| 2406 | + $A0 =& $NN; |
| 2407 | + |
| 2408 | + $parity = array_fill(0, $NROOTS, 0); |
| 2409 | + |
| 2410 | + for($i=0; $i< ($NN-$NROOTS-$PAD); $i++) { |
| 2411 | + |
| 2412 | + $feedback = $INDEX_OF[$data[$i] ^ $parity[0]]; |
| 2413 | + if($feedback != $A0) { |
| 2414 | + // feedback term is non-zero |
| 2415 | + |
| 2416 | + // This line is unnecessary when GENPOLY[NROOTS] is unity, as it must |
| 2417 | + // always be for the polynomials constructed by init_rs() |
| 2418 | + $feedback = $this->modnn($NN - $GENPOLY[$NROOTS] + $feedback); |
| 2419 | + |
| 2420 | + for($j=1;$j<$NROOTS;$j++) { |
| 2421 | + $parity[$j] ^= $ALPHA_TO[$this->modnn($feedback + $GENPOLY[$NROOTS-$j])]; |
| 2422 | + } |
| 2423 | + } |
| 2424 | + |
| 2425 | + // Shift |
| 2426 | + array_shift($parity); |
| 2427 | + if($feedback != $A0) { |
| 2428 | + array_push($parity, $ALPHA_TO[$this->modnn($feedback + $GENPOLY[0])]); |
| 2429 | + } else { |
| 2430 | + array_push($parity, 0); |
| 2431 | + } |
| 2432 | + } |
| 2433 | + } |
2466 | 2434 | } |
| 2435 | + |
| 2436 | + //########################################################################## |
| 2437 | + |
| 2438 | + class QRrs { |
| 2439 | + |
| 2440 | + public static $items = array(); |
| 2441 | + |
| 2442 | + //---------------------------------------------------------------------- |
| 2443 | + public static function init_rs($symsize, $gfpoly, $fcr, $prim, $nroots, $pad) |
| 2444 | + { |
| 2445 | + foreach(self::$items as $rs) { |
| 2446 | + if($rs->pad != $pad) continue; |
| 2447 | + if($rs->nroots != $nroots) continue; |
| 2448 | + if($rs->mm != $symsize) continue; |
| 2449 | + if($rs->gfpoly != $gfpoly) continue; |
| 2450 | + if($rs->fcr != $fcr) continue; |
| 2451 | + if($rs->prim != $prim) continue; |
2467 | 2452 | |
| 2453 | + return $rs; |
| 2454 | + } |
2468 | 2455 | |
| 2456 | + $rs = QRrsItem::init_rs_char($symsize, $gfpoly, $fcr, $prim, $nroots, $pad); |
| 2457 | + array_unshift(self::$items, $rs); |
2469 | 2458 | |
| 2459 | + return $rs; |
| 2460 | + } |
| 2461 | + } |
| 2462 | + |
| 2463 | + |
| 2464 | + |
2470 | 2465 | //---- qrmask.php ----------------------------- |
2471 | 2466 | |
2472 | 2467 | |
2473 | 2468 | |
2474 | | -
|
2475 | | -/*
|
2476 | | - * PHP QR Code encoder
|
2477 | | - *
|
2478 | | - * Masking
|
2479 | | - *
|
2480 | | - * Based on libqrencode C library distributed under LGPL 2.1
|
2481 | | - * Copyright (C) 2006, 2007, 2008, 2009 Kentaro Fukuchi <fukuchi@megaui.net>
|
2482 | | - *
|
2483 | | - * PHP QR Code is distributed under LGPL 3
|
2484 | | - * Copyright (C) 2010 Dominik Dzienia <deltalab at poczta dot fm>
|
2485 | | - *
|
2486 | | - * This library is free software; you can redistribute it and/or
|
2487 | | - * modify it under the terms of the GNU Lesser General Public
|
2488 | | - * License as published by the Free Software Foundation; either
|
2489 | | - * version 3 of the License, or any later version.
|
2490 | | - *
|
2491 | | - * This library is distributed in the hope that it will be useful,
|
2492 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2493 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
2494 | | - * Lesser General Public License for more details.
|
2495 | | - *
|
2496 | | - * You should have received a copy of the GNU Lesser General Public
|
2497 | | - * License along with this library; if not, write to the Free Software
|
2498 | | - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
2499 | | - */
|
2500 | | -
|
2501 | | - define('N1', 3);
|
2502 | | - define('N2', 3);
|
2503 | | - define('N3', 40);
|
2504 | | - define('N4', 10);
|
2505 | | -
|
2506 | | - class QRmask {
|
2507 | | -
|
2508 | | - public $runLength = array();
|
2509 | | -
|
2510 | | - //----------------------------------------------------------------------
|
2511 | | - public function __construct()
|
2512 | | - {
|
2513 | | - $this->runLength = array_fill(0, QRSPEC_WIDTH_MAX + 1, 0);
|
2514 | | - }
|
2515 | | -
|
2516 | | - //----------------------------------------------------------------------
|
2517 | | - public function writeFormatInformation($width, &$frame, $mask, $level)
|
2518 | | - {
|
2519 | | - $blacks = 0;
|
2520 | | - $format = QRspec::getFormatInfo($mask, $level);
|
2521 | | -
|
2522 | | - for($i=0; $i<8; $i++) {
|
2523 | | - if($format & 1) {
|
2524 | | - $blacks += 2;
|
2525 | | - $v = 0x85;
|
2526 | | - } else {
|
2527 | | - $v = 0x84;
|
2528 | | - }
|
2529 | | -
|
2530 | | - $frame[8][$width - 1 - $i] = chr($v);
|
2531 | | - if($i < 6) {
|
2532 | | - $frame[$i][8] = chr($v);
|
2533 | | - } else {
|
2534 | | - $frame[$i + 1][8] = chr($v);
|
2535 | | - }
|
2536 | | - $format = $format >> 1;
|
2537 | | - }
|
2538 | | -
|
2539 | | - for($i=0; $i<7; $i++) {
|
2540 | | - if($format & 1) {
|
2541 | | - $blacks += 2;
|
2542 | | - $v = 0x85;
|
2543 | | - } else {
|
2544 | | - $v = 0x84;
|
2545 | | - }
|
2546 | | -
|
2547 | | - $frame[$width - 7 + $i][8] = chr($v);
|
2548 | | - if($i == 0) {
|
2549 | | - $frame[8][7] = chr($v);
|
2550 | | - } else {
|
2551 | | - $frame[8][6 - $i] = chr($v);
|
2552 | | - }
|
2553 | | -
|
2554 | | - $format = $format >> 1;
|
2555 | | - }
|
2556 | | -
|
2557 | | - return $blacks;
|
2558 | | - }
|
2559 | | -
|
2560 | | - //----------------------------------------------------------------------
|
2561 | | - public function mask0($x, $y) { return ($x+$y)&1; }
|
2562 | | - public function mask1($x, $y) { return ($y&1); }
|
2563 | | - public function mask2($x, $y) { return ($x%3); }
|
2564 | | - public function mask3($x, $y) { return ($x+$y)%3; }
|
2565 | | - public function mask4($x, $y) { return (((int)($y/2))+((int)($x/3)))&1; }
|
2566 | | - public function mask5($x, $y) { return (($x*$y)&1)+($x*$y)%3; }
|
2567 | | - public function mask6($x, $y) { return ((($x*$y)&1)+($x*$y)%3)&1; }
|
2568 | | - public function mask7($x, $y) { return ((($x*$y)%3)+(($x+$y)&1))&1; }
|
2569 | | -
|
2570 | | - //----------------------------------------------------------------------
|
2571 | | - private function generateMaskNo($maskNo, $width, $frame)
|
2572 | | - {
|
2573 | | - $bitMask = array_fill(0, $width, array_fill(0, $width, 0));
|
2574 | | -
|
2575 | | - for($y=0; $y<$width; $y++) {
|
2576 | | - for($x=0; $x<$width; $x++) {
|
2577 | | - if(ord($frame[$y][$x]) & 0x80) {
|
2578 | | - $bitMask[$y][$x] = 0;
|
2579 | | - } else {
|
2580 | | - $maskFunc = call_user_func(array($this, 'mask'.$maskNo), $x, $y);
|
2581 | | - $bitMask[$y][$x] = ($maskFunc == 0)?1:0;
|
2582 | | - }
|
2583 | | -
|
2584 | | - }
|
2585 | | - }
|
2586 | | -
|
2587 | | - return $bitMask;
|
2588 | | - }
|
2589 | | -
|
2590 | | - //----------------------------------------------------------------------
|
2591 | | - public static function serial($bitFrame)
|
2592 | | - {
|
2593 | | - $codeArr = array();
|
2594 | | -
|
2595 | | - foreach ($bitFrame as $line)
|
2596 | | - $codeArr[] = join('', $line);
|
2597 | | -
|
2598 | | - return gzcompress(join("\n", $codeArr), 9);
|
2599 | | - }
|
2600 | | -
|
2601 | | - //----------------------------------------------------------------------
|
2602 | | - public static function unserial($code)
|
2603 | | - {
|
2604 | | - $codeArr = array();
|
2605 | | -
|
2606 | | - $codeLines = explode("\n", gzuncompress($code));
|
2607 | | - foreach ($codeLines as $line)
|
2608 | | - $codeArr[] = str_split($line);
|
2609 | | -
|
2610 | | - return $codeArr;
|
2611 | | - }
|
2612 | | -
|
2613 | | - //----------------------------------------------------------------------
|
2614 | | - public function makeMaskNo($maskNo, $width, $s, &$d, $maskGenOnly = false)
|
2615 | | - {
|
2616 | | - $b = 0;
|
2617 | | - $bitMask = array();
|
2618 | | -
|
2619 | | - $fileName = QR_CACHE_DIR.'mask_'.$maskNo.DIRECTORY_SEPARATOR.'mask_'.$width.'_'.$maskNo.'.dat';
|
2620 | | -
|
2621 | | - if (QR_CACHEABLE) {
|
2622 | | - if (file_exists($fileName)) {
|
2623 | | - $bitMask = self::unserial(file_get_contents($fileName));
|
2624 | | - } else {
|
2625 | | - $bitMask = $this->generateMaskNo($maskNo, $width, $s, $d);
|
2626 | | - if (!file_exists(QR_CACHE_DIR.'mask_'.$maskNo))
|
2627 | | - mkdir(QR_CACHE_DIR.'mask_'.$maskNo);
|
2628 | | - file_put_contents($fileName, self::serial($bitMask));
|
2629 | | - }
|
2630 | | - } else {
|
2631 | | - $bitMask = $this->generateMaskNo($maskNo, $width, $s, $d);
|
2632 | | - }
|
2633 | | -
|
2634 | | - if ($maskGenOnly)
|
2635 | | - return;
|
2636 | | -
|
2637 | | - $d = $s;
|
2638 | | -
|
2639 | | - for($y=0; $y<$width; $y++) {
|
2640 | | - for($x=0; $x<$width; $x++) {
|
2641 | | - if($bitMask[$y][$x] == 1) {
|
2642 | | - $d[$y][$x] = chr(ord($s[$y][$x]) ^ (int)$bitMask[$y][$x]);
|
2643 | | - }
|
2644 | | - $b += (int)(ord($d[$y][$x]) & 1);
|
2645 | | - }
|
2646 | | - }
|
2647 | | -
|
2648 | | - return $b;
|
2649 | | - }
|
2650 | | -
|
2651 | | - //----------------------------------------------------------------------
|
2652 | | - public function makeMask($width, $frame, $maskNo, $level)
|
2653 | | - {
|
2654 | | - $masked = array_fill(0, $width, str_repeat("\0", $width));
|
2655 | | - $this->makeMaskNo($maskNo, $width, $frame, $masked);
|
2656 | | - $this->writeFormatInformation($width, $masked, $maskNo, $level);
|
2657 | | -
|
2658 | | - return $masked;
|
2659 | | - }
|
2660 | | -
|
2661 | | - //----------------------------------------------------------------------
|
2662 | | - public function calcN1N3($length)
|
2663 | | - {
|
2664 | | - $demerit = 0;
|
2665 | | -
|
2666 | | - for($i=0; $i<$length; $i++) {
|
2667 | | -
|
2668 | | - if($this->runLength[$i] >= 5) {
|
2669 | | - $demerit += (N1 + ($this->runLength[$i] - 5));
|
2670 | | - }
|
2671 | | - if($i & 1) {
|
2672 | | - if(($i >= 3) && ($i < ($length-2)) && ($this->runLength[$i] % 3 == 0)) {
|
2673 | | - $fact = (int)($this->runLength[$i] / 3);
|
2674 | | - if(($this->runLength[$i-2] == $fact) &&
|
2675 | | - ($this->runLength[$i-1] == $fact) &&
|
2676 | | - ($this->runLength[$i+1] == $fact) &&
|
2677 | | - ($this->runLength[$i+2] == $fact)) {
|
2678 | | - if(($this->runLength[$i-3] < 0) || ($this->runLength[$i-3] >= (4 * $fact))) {
|
2679 | | - $demerit += N3;
|
2680 | | - } else if((($i+3) >= $length) || ($this->runLength[$i+3] >= (4 * $fact))) {
|
2681 | | - $demerit += N3;
|
2682 | | - }
|
2683 | | - }
|
2684 | | - }
|
2685 | | - }
|
2686 | | - }
|
2687 | | - return $demerit;
|
2688 | | - }
|
2689 | | -
|
2690 | | - //----------------------------------------------------------------------
|
2691 | | - public function evaluateSymbol($width, $frame)
|
2692 | | - {
|
2693 | | - $head = 0;
|
2694 | | - $demerit = 0;
|
2695 | | -
|
2696 | | - for($y=0; $y<$width; $y++) {
|
2697 | | - $head = 0;
|
2698 | | - $this->runLength[0] = 1;
|
2699 | | -
|
2700 | | - $frameY = $frame[$y];
|
2701 | | -
|
2702 | | - if ($y>0)
|
2703 | | - $frameYM = $frame[$y-1];
|
2704 | | -
|
2705 | | - for($x=0; $x<$width; $x++) {
|
2706 | | - if(($x > 0) && ($y > 0)) {
|
2707 | | - $b22 = ord($frameY[$x]) & ord($frameY[$x-1]) & ord($frameYM[$x]) & ord($frameYM[$x-1]);
|
2708 | | - $w22 = ord($frameY[$x]) | ord($frameY[$x-1]) | ord($frameYM[$x]) | ord($frameYM[$x-1]);
|
2709 | | -
|
2710 | | - if(($b22 | ($w22 ^ 1))&1) {
|
2711 | | - $demerit += N2;
|
2712 | | - }
|
2713 | | - }
|
2714 | | - if(($x == 0) && (ord($frameY[$x]) & 1)) {
|
2715 | | - $this->runLength[0] = -1;
|
2716 | | - $head = 1;
|
2717 | | - $this->runLength[$head] = 1;
|
2718 | | - } else if($x > 0) {
|
2719 | | - if((ord($frameY[$x]) ^ ord($frameY[$x-1])) & 1) {
|
2720 | | - $head++;
|
2721 | | - $this->runLength[$head] = 1;
|
2722 | | - } else {
|
2723 | | - $this->runLength[$head]++;
|
2724 | | - }
|
2725 | | - }
|
2726 | | - }
|
2727 | | -
|
2728 | | - $demerit += $this->calcN1N3($head+1);
|
2729 | | - }
|
2730 | | -
|
2731 | | - for($x=0; $x<$width; $x++) {
|
2732 | | - $head = 0;
|
2733 | | - $this->runLength[0] = 1;
|
2734 | | -
|
2735 | | - for($y=0; $y<$width; $y++) {
|
2736 | | - if($y == 0 && (ord($frame[$y][$x]) & 1)) {
|
2737 | | - $this->runLength[0] = -1;
|
2738 | | - $head = 1;
|
2739 | | - $this->runLength[$head] = 1;
|
2740 | | - } else if($y > 0) {
|
2741 | | - if((ord($frame[$y][$x]) ^ ord($frame[$y-1][$x])) & 1) {
|
2742 | | - $head++;
|
2743 | | - $this->runLength[$head] = 1;
|
2744 | | - } else {
|
2745 | | - $this->runLength[$head]++;
|
2746 | | - }
|
2747 | | - }
|
2748 | | - }
|
2749 | | -
|
2750 | | - $demerit += $this->calcN1N3($head+1);
|
2751 | | - }
|
2752 | | -
|
2753 | | - return $demerit;
|
2754 | | - }
|
2755 | | -
|
2756 | | -
|
2757 | | - //----------------------------------------------------------------------
|
2758 | | - public function mask($width, $frame, $level)
|
2759 | | - {
|
2760 | | - $minDemerit = PHP_INT_MAX;
|
2761 | | - $bestMaskNum = 0;
|
2762 | | - $bestMask = array();
|
2763 | | -
|
2764 | | - $checked_masks = array(0,1,2,3,4,5,6,7);
|
2765 | | -
|
2766 | | - if (QR_FIND_FROM_RANDOM !== false) {
|
2767 | | -
|
2768 | | - $howManuOut = 8-(QR_FIND_FROM_RANDOM % 9);
|
2769 | | - for ($i = 0; $i < $howManuOut; $i++) {
|
2770 | | - $remPos = rand (0, count($checked_masks)-1);
|
2771 | | - unset($checked_masks[$remPos]);
|
2772 | | - $checked_masks = array_values($checked_masks);
|
2773 | | - }
|
2774 | | -
|
2775 | | - }
|
2776 | | -
|
2777 | | - $bestMask = $frame;
|
2778 | | -
|
2779 | | - foreach($checked_masks as $i) {
|
2780 | | - $mask = array_fill(0, $width, str_repeat("\0", $width));
|
2781 | | -
|
2782 | | - $demerit = 0;
|
2783 | | - $blacks = 0;
|
2784 | | - $blacks = $this->makeMaskNo($i, $width, $frame, $mask);
|
2785 | | - $blacks += $this->writeFormatInformation($width, $mask, $i, $level);
|
2786 | | - $blacks = (int)(100 * $blacks / ($width * $width));
|
2787 | | - $demerit = (int)((int)(abs($blacks - 50) / 5) * N4);
|
2788 | | - $demerit += $this->evaluateSymbol($width, $mask);
|
2789 | | -
|
2790 | | - if($demerit < $minDemerit) {
|
2791 | | - $minDemerit = $demerit;
|
2792 | | - $bestMask = $mask;
|
2793 | | - $bestMaskNum = $i;
|
2794 | | - }
|
2795 | | - }
|
2796 | | -
|
2797 | | - return $bestMask;
|
2798 | | - }
|
2799 | | -
|
2800 | | - //----------------------------------------------------------------------
|
2801 | | - }
|
2802 | 2469 | |
| 2470 | +/* |
| 2471 | + * PHP QR Code encoder |
| 2472 | + * |
| 2473 | + * Masking |
| 2474 | + * |
| 2475 | + * Based on libqrencode C library distributed under LGPL 2.1 |
| 2476 | + * Copyright (C) 2006, 2007, 2008, 2009 Kentaro Fukuchi <fukuchi@megaui.net> |
| 2477 | + * |
| 2478 | + * PHP QR Code is distributed under LGPL 3 |
| 2479 | + * Copyright (C) 2010 Dominik Dzienia <deltalab at poczta dot fm> |
| 2480 | + * |
| 2481 | + * This library is free software; you can redistribute it and/or |
| 2482 | + * modify it under the terms of the GNU Lesser General Public |
| 2483 | + * License as published by the Free Software Foundation; either |
| 2484 | + * version 3 of the License, or any later version. |
| 2485 | + * |
| 2486 | + * This library is distributed in the hope that it will be useful, |
| 2487 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 2488 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 2489 | + * Lesser General Public License for more details. |
| 2490 | + * |
| 2491 | + * You should have received a copy of the GNU Lesser General Public |
| 2492 | + * License along with this library; if not, write to the Free Software |
| 2493 | + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 2494 | + */ |
| 2495 | + |
| 2496 | + define('N1', 3); |
| 2497 | + define('N2', 3); |
| 2498 | + define('N3', 40); |
| 2499 | + define('N4', 10); |
2803 | 2500 | |
| 2501 | + class QRmask { |
| 2502 | + |
| 2503 | + public $runLength = array(); |
| 2504 | + |
| 2505 | + //---------------------------------------------------------------------- |
| 2506 | + public function __construct() |
| 2507 | + { |
| 2508 | + $this->runLength = array_fill(0, QRSPEC_WIDTH_MAX + 1, 0); |
| 2509 | + } |
| 2510 | + |
| 2511 | + //---------------------------------------------------------------------- |
| 2512 | + public function writeFormatInformation($width, &$frame, $mask, $level) |
| 2513 | + { |
| 2514 | + $blacks = 0; |
| 2515 | + $format = QRspec::getFormatInfo($mask, $level); |
2804 | 2516 | |
| 2517 | + for($i=0; $i<8; $i++) { |
| 2518 | + if($format & 1) { |
| 2519 | + $blacks += 2; |
| 2520 | + $v = 0x85; |
| 2521 | + } else { |
| 2522 | + $v = 0x84; |
| 2523 | + } |
| 2524 | + |
| 2525 | + $frame[8][$width - 1 - $i] = chr($v); |
| 2526 | + if($i < 6) { |
| 2527 | + $frame[$i][8] = chr($v); |
| 2528 | + } else { |
| 2529 | + $frame[$i + 1][8] = chr($v); |
| 2530 | + } |
| 2531 | + $format = $format >> 1; |
| 2532 | + } |
| 2533 | + |
| 2534 | + for($i=0; $i<7; $i++) { |
| 2535 | + if($format & 1) { |
| 2536 | + $blacks += 2; |
| 2537 | + $v = 0x85; |
| 2538 | + } else { |
| 2539 | + $v = 0x84; |
| 2540 | + } |
| 2541 | + |
| 2542 | + $frame[$width - 7 + $i][8] = chr($v); |
| 2543 | + if($i == 0) { |
| 2544 | + $frame[8][7] = chr($v); |
| 2545 | + } else { |
| 2546 | + $frame[8][6 - $i] = chr($v); |
| 2547 | + } |
| 2548 | + |
| 2549 | + $format = $format >> 1; |
| 2550 | + } |
2805 | 2551 | |
| 2552 | + return $blacks; |
| 2553 | + } |
| 2554 | + |
| 2555 | + //---------------------------------------------------------------------- |
| 2556 | + public function mask0($x, $y) { return ($x+$y)&1; } |
| 2557 | + public function mask1($x, $y) { return ($y&1); } |
| 2558 | + public function mask2($x, $y) { return ($x%3); } |
| 2559 | + public function mask3($x, $y) { return ($x+$y)%3; } |
| 2560 | + public function mask4($x, $y) { return (((int)($y/2))+((int)($x/3)))&1; } |
| 2561 | + public function mask5($x, $y) { return (($x*$y)&1)+($x*$y)%3; } |
| 2562 | + public function mask6($x, $y) { return ((($x*$y)&1)+($x*$y)%3)&1; } |
| 2563 | + public function mask7($x, $y) { return ((($x*$y)%3)+(($x+$y)&1))&1; } |
| 2564 | + |
| 2565 | + //---------------------------------------------------------------------- |
| 2566 | + private function generateMaskNo($maskNo, $width, $frame) |
| 2567 | + { |
| 2568 | + $bitMask = array_fill(0, $width, array_fill(0, $width, 0)); |
| 2569 | + |
| 2570 | + for($y=0; $y<$width; $y++) { |
| 2571 | + for($x=0; $x<$width; $x++) { |
| 2572 | + if(ord($frame[$y][$x]) & 0x80) { |
| 2573 | + $bitMask[$y][$x] = 0; |
| 2574 | + } else { |
| 2575 | + $maskFunc = call_user_func(array($this, 'mask'.$maskNo), $x, $y); |
| 2576 | + $bitMask[$y][$x] = ($maskFunc == 0)?1:0; |
| 2577 | + } |
| 2578 | + |
| 2579 | + } |
| 2580 | + } |
| 2581 | + |
| 2582 | + return $bitMask; |
| 2583 | + } |
| 2584 | + |
| 2585 | + //---------------------------------------------------------------------- |
| 2586 | + public static function serial($bitFrame) |
| 2587 | + { |
| 2588 | + $codeArr = array(); |
| 2589 | + |
| 2590 | + foreach ($bitFrame as $line) |
| 2591 | + $codeArr[] = join('', $line); |
| 2592 | + |
| 2593 | + return gzcompress(join("\n", $codeArr), 9); |
| 2594 | + } |
| 2595 | + |
| 2596 | + //---------------------------------------------------------------------- |
| 2597 | + public static function unserial($code) |
| 2598 | + { |
| 2599 | + $codeArr = array(); |
| 2600 | + |
| 2601 | + $codeLines = explode("\n", gzuncompress($code)); |
| 2602 | + foreach ($codeLines as $line) |
| 2603 | + $codeArr[] = str_split($line); |
| 2604 | + |
| 2605 | + return $codeArr; |
| 2606 | + } |
| 2607 | + |
| 2608 | + //---------------------------------------------------------------------- |
| 2609 | + public function makeMaskNo($maskNo, $width, $s, &$d, $maskGenOnly = false) |
| 2610 | + { |
| 2611 | + $b = 0; |
| 2612 | + $bitMask = array(); |
| 2613 | + |
| 2614 | + $fileName = QR_CACHE_DIR.'mask_'.$maskNo.DIRECTORY_SEPARATOR.'mask_'.$width.'_'.$maskNo.'.dat'; |
| 2615 | + |
| 2616 | + if (QR_CACHEABLE) { |
| 2617 | + if (file_exists($fileName)) { |
| 2618 | + $bitMask = self::unserial(file_get_contents($fileName)); |
| 2619 | + } else { |
| 2620 | + $bitMask = $this->generateMaskNo($maskNo, $width, $s, $d); |
| 2621 | + if (!file_exists(QR_CACHE_DIR.'mask_'.$maskNo)) |
| 2622 | + mkdir(QR_CACHE_DIR.'mask_'.$maskNo); |
| 2623 | + file_put_contents($fileName, self::serial($bitMask)); |
| 2624 | + } |
| 2625 | + } else { |
| 2626 | + $bitMask = $this->generateMaskNo($maskNo, $width, $s, $d); |
| 2627 | + } |
| 2628 | + |
| 2629 | + if ($maskGenOnly) |
| 2630 | + return; |
| 2631 | + |
| 2632 | + $d = $s; |
| 2633 | + |
| 2634 | + for($y=0; $y<$width; $y++) { |
| 2635 | + for($x=0; $x<$width; $x++) { |
| 2636 | + if($bitMask[$y][$x] == 1) { |
| 2637 | + $d[$y][$x] = chr(ord($s[$y][$x]) ^ (int)$bitMask[$y][$x]); |
| 2638 | + } |
| 2639 | + $b += (int)(ord($d[$y][$x]) & 1); |
| 2640 | + } |
| 2641 | + } |
| 2642 | + |
| 2643 | + return $b; |
| 2644 | + } |
| 2645 | + |
| 2646 | + //---------------------------------------------------------------------- |
| 2647 | + public function makeMask($width, $frame, $maskNo, $level) |
| 2648 | + { |
| 2649 | + $masked = array_fill(0, $width, str_repeat("\0", $width)); |
| 2650 | + $this->makeMaskNo($maskNo, $width, $frame, $masked); |
| 2651 | + $this->writeFormatInformation($width, $masked, $maskNo, $level); |
| 2652 | + |
| 2653 | + return $masked; |
| 2654 | + } |
| 2655 | + |
| 2656 | + //---------------------------------------------------------------------- |
| 2657 | + public function calcN1N3($length) |
| 2658 | + { |
| 2659 | + $demerit = 0; |
| 2660 | + |
| 2661 | + for($i=0; $i<$length; $i++) { |
| 2662 | + |
| 2663 | + if($this->runLength[$i] >= 5) { |
| 2664 | + $demerit += (N1 + ($this->runLength[$i] - 5)); |
| 2665 | + } |
| 2666 | + if($i & 1) { |
| 2667 | + if(($i >= 3) && ($i < ($length-2)) && ($this->runLength[$i] % 3 == 0)) { |
| 2668 | + $fact = (int)($this->runLength[$i] / 3); |
| 2669 | + if(($this->runLength[$i-2] == $fact) && |
| 2670 | + ($this->runLength[$i-1] == $fact) && |
| 2671 | + ($this->runLength[$i+1] == $fact) && |
| 2672 | + ($this->runLength[$i+2] == $fact)) { |
| 2673 | + if(($this->runLength[$i-3] < 0) || ($this->runLength[$i-3] >= (4 * $fact))) { |
| 2674 | + $demerit += N3; |
| 2675 | + } else if((($i+3) >= $length) || ($this->runLength[$i+3] >= (4 * $fact))) { |
| 2676 | + $demerit += N3; |
| 2677 | + } |
| 2678 | + } |
| 2679 | + } |
| 2680 | + } |
| 2681 | + } |
| 2682 | + return $demerit; |
| 2683 | + } |
| 2684 | + |
| 2685 | + //---------------------------------------------------------------------- |
| 2686 | + public function evaluateSymbol($width, $frame) |
| 2687 | + { |
| 2688 | + $head = 0; |
| 2689 | + $demerit = 0; |
| 2690 | + |
| 2691 | + for($y=0; $y<$width; $y++) { |
| 2692 | + $head = 0; |
| 2693 | + $this->runLength[0] = 1; |
| 2694 | + |
| 2695 | + $frameY = $frame[$y]; |
| 2696 | + |
| 2697 | + if ($y>0) |
| 2698 | + $frameYM = $frame[$y-1]; |
| 2699 | + |
| 2700 | + for($x=0; $x<$width; $x++) { |
| 2701 | + if(($x > 0) && ($y > 0)) { |
| 2702 | + $b22 = ord($frameY[$x]) & ord($frameY[$x-1]) & ord($frameYM[$x]) & ord($frameYM[$x-1]); |
| 2703 | + $w22 = ord($frameY[$x]) | ord($frameY[$x-1]) | ord($frameYM[$x]) | ord($frameYM[$x-1]); |
| 2704 | + |
| 2705 | + if(($b22 | ($w22 ^ 1))&1) { |
| 2706 | + $demerit += N2; |
| 2707 | + } |
| 2708 | + } |
| 2709 | + if(($x == 0) && (ord($frameY[$x]) & 1)) { |
| 2710 | + $this->runLength[0] = -1; |
| 2711 | + $head = 1; |
| 2712 | + $this->runLength[$head] = 1; |
| 2713 | + } else if($x > 0) { |
| 2714 | + if((ord($frameY[$x]) ^ ord($frameY[$x-1])) & 1) { |
| 2715 | + $head++; |
| 2716 | + $this->runLength[$head] = 1; |
| 2717 | + } else { |
| 2718 | + $this->runLength[$head]++; |
| 2719 | + } |
| 2720 | + } |
| 2721 | + } |
| 2722 | + |
| 2723 | + $demerit += $this->calcN1N3($head+1); |
| 2724 | + } |
| 2725 | + |
| 2726 | + for($x=0; $x<$width; $x++) { |
| 2727 | + $head = 0; |
| 2728 | + $this->runLength[0] = 1; |
| 2729 | + |
| 2730 | + for($y=0; $y<$width; $y++) { |
| 2731 | + if($y == 0 && (ord($frame[$y][$x]) & 1)) { |
| 2732 | + $this->runLength[0] = -1; |
| 2733 | + $head = 1; |
| 2734 | + $this->runLength[$head] = 1; |
| 2735 | + } else if($y > 0) { |
| 2736 | + if((ord($frame[$y][$x]) ^ ord($frame[$y-1][$x])) & 1) { |
| 2737 | + $head++; |
| 2738 | + $this->runLength[$head] = 1; |
| 2739 | + } else { |
| 2740 | + $this->runLength[$head]++; |
| 2741 | + } |
| 2742 | + } |
| 2743 | + } |
| 2744 | + |
| 2745 | + $demerit += $this->calcN1N3($head+1); |
| 2746 | + } |
| 2747 | + |
| 2748 | + return $demerit; |
| 2749 | + } |
| 2750 | + |
| 2751 | + |
| 2752 | + //---------------------------------------------------------------------- |
| 2753 | + public function mask($width, $frame, $level) |
| 2754 | + { |
| 2755 | + $minDemerit = PHP_INT_MAX; |
| 2756 | + $bestMaskNum = 0; |
| 2757 | + $bestMask = array(); |
| 2758 | + |
| 2759 | + $checked_masks = array(0,1,2,3,4,5,6,7); |
| 2760 | + |
| 2761 | + if (QR_FIND_FROM_RANDOM !== false) { |
| 2762 | + |
| 2763 | + $howManuOut = 8-(QR_FIND_FROM_RANDOM % 9); |
| 2764 | + for ($i = 0; $i < $howManuOut; $i++) { |
| 2765 | + $remPos = rand (0, count($checked_masks)-1); |
| 2766 | + unset($checked_masks[$remPos]); |
| 2767 | + $checked_masks = array_values($checked_masks); |
| 2768 | + } |
| 2769 | + |
| 2770 | + } |
| 2771 | + |
| 2772 | + $bestMask = $frame; |
| 2773 | + |
| 2774 | + foreach($checked_masks as $i) { |
| 2775 | + $mask = array_fill(0, $width, str_repeat("\0", $width)); |
| 2776 | + |
| 2777 | + $demerit = 0; |
| 2778 | + $blacks = 0; |
| 2779 | + $blacks = $this->makeMaskNo($i, $width, $frame, $mask); |
| 2780 | + $blacks += $this->writeFormatInformation($width, $mask, $i, $level); |
| 2781 | + $blacks = (int)(100 * $blacks / ($width * $width)); |
| 2782 | + $demerit = (int)((int)(abs($blacks - 50) / 5) * N4); |
| 2783 | + $demerit += $this->evaluateSymbol($width, $mask); |
| 2784 | + |
| 2785 | + if($demerit < $minDemerit) { |
| 2786 | + $minDemerit = $demerit; |
| 2787 | + $bestMask = $mask; |
| 2788 | + $bestMaskNum = $i; |
| 2789 | + } |
| 2790 | + } |
| 2791 | + |
| 2792 | + return $bestMask; |
| 2793 | + } |
| 2794 | + |
| 2795 | + //---------------------------------------------------------------------- |
| 2796 | + } |
| 2797 | + |
| 2798 | + |
| 2799 | + |
| 2800 | + |
2806 | 2801 | //---- qrencode.php ----------------------------- |
2807 | 2802 | |
2808 | 2803 | |
2809 | 2804 | |
2810 | | -
|
2811 | | -/*
|
2812 | | - * PHP QR Code encoder
|
2813 | | - *
|
2814 | | - * Main encoder classes.
|
2815 | | - *
|
2816 | | - * Based on libqrencode C library distributed under LGPL 2.1
|
2817 | | - * Copyright (C) 2006, 2007, 2008, 2009 Kentaro Fukuchi <fukuchi@megaui.net>
|
2818 | | - *
|
2819 | | - * PHP QR Code is distributed under LGPL 3
|
2820 | | - * Copyright (C) 2010 Dominik Dzienia <deltalab at poczta dot fm>
|
2821 | | - *
|
2822 | | - * This library is free software; you can redistribute it and/or
|
2823 | | - * modify it under the terms of the GNU Lesser General Public
|
2824 | | - * License as published by the Free Software Foundation; either
|
2825 | | - * version 3 of the License, or any later version.
|
2826 | | - *
|
2827 | | - * This library is distributed in the hope that it will be useful,
|
2828 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2829 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
2830 | | - * Lesser General Public License for more details.
|
2831 | | - *
|
2832 | | - * You should have received a copy of the GNU Lesser General Public
|
2833 | | - * License along with this library; if not, write to the Free Software
|
2834 | | - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
2835 | | - */
|
2836 | | -
|
2837 | | - class QRrsblock {
|
2838 | | - public $dataLength;
|
2839 | | - public $data = array();
|
2840 | | - public $eccLength;
|
2841 | | - public $ecc = array();
|
2842 | | -
|
2843 | | - public function __construct($dl, $data, $el, &$ecc, QRrsItem $rs)
|
2844 | | - {
|
2845 | | - $rs->encode_rs_char($data, $ecc);
|
2846 | | -
|
2847 | | - $this->dataLength = $dl;
|
2848 | | - $this->data = $data;
|
2849 | | - $this->eccLength = $el;
|
2850 | | - $this->ecc = $ecc;
|
2851 | | - }
|
2852 | | - };
|
2853 | | -
|
2854 | | - //##########################################################################
|
2855 | | -
|
2856 | | - class QRrawcode {
|
2857 | | - public $version;
|
2858 | | - public $datacode = array();
|
2859 | | - public $ecccode = array();
|
2860 | | - public $blocks;
|
2861 | | - public $rsblocks = array(); //of RSblock
|
2862 | | - public $count;
|
2863 | | - public $dataLength;
|
2864 | | - public $eccLength;
|
2865 | | - public $b1;
|
2866 | | -
|
2867 | | - //----------------------------------------------------------------------
|
2868 | | - public function __construct(QRinput $input)
|
2869 | | - {
|
2870 | | - $spec = array(0,0,0,0,0);
|
2871 | | -
|
2872 | | - $this->datacode = $input->getByteStream();
|
2873 | | - if(is_null($this->datacode)) {
|
2874 | | - throw new Exception('null imput string');
|
2875 | | - }
|
2876 | | -
|
2877 | | - QRspec::getEccSpec($input->getVersion(), $input->getErrorCorrectionLevel(), $spec);
|
2878 | | -
|
2879 | | - $this->version = $input->getVersion();
|
2880 | | - $this->b1 = QRspec::rsBlockNum1($spec);
|
2881 | | - $this->dataLength = QRspec::rsDataLength($spec);
|
2882 | | - $this->eccLength = QRspec::rsEccLength($spec);
|
2883 | | - $this->ecccode = array_fill(0, $this->eccLength, 0);
|
2884 | | - $this->blocks = QRspec::rsBlockNum($spec);
|
2885 | | -
|
2886 | | - $ret = $this->init($spec);
|
2887 | | - if($ret < 0) {
|
2888 | | - throw new Exception('block alloc error');
|
2889 | | - return null;
|
2890 | | - }
|
2891 | | -
|
2892 | | - $this->count = 0;
|
2893 | | - }
|
2894 | | -
|
2895 | | - //----------------------------------------------------------------------
|
2896 | | - public function init(array $spec)
|
2897 | | - {
|
2898 | | - $dl = QRspec::rsDataCodes1($spec);
|
2899 | | - $el = QRspec::rsEccCodes1($spec);
|
2900 | | - $rs = QRrs::init_rs(8, 0x11d, 0, 1, $el, 255 - $dl - $el);
|
2901 | | -
|
2902 | | -
|
2903 | | - $blockNo = 0;
|
2904 | | - $dataPos = 0;
|
2905 | | - $eccPos = 0;
|
2906 | | - for($i=0; $i<QRspec::rsBlockNum1($spec); $i++) {
|
2907 | | - $ecc = array_slice($this->ecccode,$eccPos);
|
2908 | | - $this->rsblocks[$blockNo] = new QRrsblock($dl, array_slice($this->datacode, $dataPos), $el, $ecc, $rs);
|
2909 | | - $this->ecccode = array_merge(array_slice($this->ecccode,0, $eccPos), $ecc);
|
2910 | | -
|
2911 | | - $dataPos += $dl;
|
2912 | | - $eccPos += $el;
|
2913 | | - $blockNo++;
|
2914 | | - }
|
2915 | | -
|
2916 | | - if(QRspec::rsBlockNum2($spec) == 0)
|
2917 | | - return 0;
|
2918 | | -
|
2919 | | - $dl = QRspec::rsDataCodes2($spec);
|
2920 | | - $el = QRspec::rsEccCodes2($spec);
|
2921 | | - $rs = QRrs::init_rs(8, 0x11d, 0, 1, $el, 255 - $dl - $el);
|
2922 | | -
|
2923 | | - if($rs == NULL) return -1;
|
2924 | | -
|
2925 | | - for($i=0; $i<QRspec::rsBlockNum2($spec); $i++) {
|
2926 | | - $ecc = array_slice($this->ecccode,$eccPos);
|
2927 | | - $this->rsblocks[$blockNo] = new QRrsblock($dl, array_slice($this->datacode, $dataPos), $el, $ecc, $rs);
|
2928 | | - $this->ecccode = array_merge(array_slice($this->ecccode,0, $eccPos), $ecc);
|
2929 | | -
|
2930 | | - $dataPos += $dl;
|
2931 | | - $eccPos += $el;
|
2932 | | - $blockNo++;
|
2933 | | - }
|
2934 | | -
|
2935 | | - return 0;
|
2936 | | - }
|
2937 | | -
|
2938 | | - //----------------------------------------------------------------------
|
2939 | | - public function getCode()
|
2940 | | - {
|
2941 | | - $ret;
|
2942 | | -
|
2943 | | - if($this->count < $this->dataLength) {
|
2944 | | - $row = $this->count % $this->blocks;
|
2945 | | - $col = $this->count / $this->blocks;
|
2946 | | - if($col >= $this->rsblocks[0]->dataLength) {
|
2947 | | - $row += $this->b1;
|
2948 | | - }
|
2949 | | - $ret = $this->rsblocks[$row]->data[$col];
|
2950 | | - } else if($this->count < $this->dataLength + $this->eccLength) {
|
2951 | | - $row = ($this->count - $this->dataLength) % $this->blocks;
|
2952 | | - $col = ($this->count - $this->dataLength) / $this->blocks;
|
2953 | | - $ret = $this->rsblocks[$row]->ecc[$col];
|
2954 | | - } else {
|
2955 | | - return 0;
|
2956 | | - }
|
2957 | | - $this->count++;
|
2958 | | -
|
2959 | | - return $ret;
|
2960 | | - }
|
2961 | | - }
|
2962 | | -
|
2963 | | - //##########################################################################
|
2964 | | -
|
2965 | | - class QRcode {
|
2966 | | -
|
2967 | | - public $version;
|
2968 | | - public $width;
|
2969 | | - public $data;
|
2970 | | -
|
2971 | | - //----------------------------------------------------------------------
|
2972 | | - public function encodeMask(QRinput $input, $mask)
|
2973 | | - {
|
2974 | | - if($input->getVersion() < 0 || $input->getVersion() > QRSPEC_VERSION_MAX) {
|
2975 | | - throw new Exception('wrong version');
|
2976 | | - }
|
2977 | | - if($input->getErrorCorrectionLevel() > QR_ECLEVEL_H) {
|
2978 | | - throw new Exception('wrong level');
|
2979 | | - }
|
2980 | | -
|
2981 | | - $raw = new QRrawcode($input);
|
2982 | | -
|
2983 | | - QRtools::markTime('after_raw');
|
2984 | | -
|
2985 | | - $version = $raw->version;
|
2986 | | - $width = QRspec::getWidth($version);
|
2987 | | - $frame = QRspec::newFrame($version);
|
2988 | | -
|
2989 | | - $filler = new FrameFiller($width, $frame);
|
2990 | | - if(is_null($filler)) {
|
2991 | | - return NULL;
|
2992 | | - }
|
2993 | | -
|
2994 | | - // inteleaved data and ecc codes
|
2995 | | - for($i=0; $i<$raw->dataLength + $raw->eccLength; $i++) {
|
2996 | | - $code = $raw->getCode();
|
2997 | | - $bit = 0x80;
|
2998 | | - for($j=0; $j<8; $j++) {
|
2999 | | - $addr = $filler->next();
|
3000 | | - $filler->setFrameAt($addr, 0x02 | (($bit & $code) != 0));
|
3001 | | - $bit = $bit >> 1;
|
3002 | | - }
|
3003 | | - }
|
3004 | | -
|
3005 | | - QRtools::markTime('after_filler');
|
3006 | | -
|
3007 | | - unset($raw);
|
3008 | | -
|
3009 | | - // remainder bits
|
3010 | | - $j = QRspec::getRemainder($version);
|
3011 | | - for($i=0; $i<$j; $i++) {
|
3012 | | - $addr = $filler->next();
|
3013 | | - $filler->setFrameAt($addr, 0x02);
|
3014 | | - }
|
3015 | | -
|
3016 | | - $frame = $filler->frame;
|
3017 | | - unset($filler);
|
3018 | | -
|
3019 | | -
|
3020 | | - // masking
|
3021 | | - $maskObj = new QRmask();
|
3022 | | - if($mask < 0) {
|
3023 | | -
|
3024 | | - if (QR_FIND_BEST_MASK) {
|
3025 | | - $masked = $maskObj->mask($width, $frame, $input->getErrorCorrectionLevel());
|
3026 | | - } else {
|
3027 | | - $masked = $maskObj->makeMask($width, $frame, (intval(QR_DEFAULT_MASK) % 8), $input->getErrorCorrectionLevel());
|
3028 | | - }
|
3029 | | - } else {
|
3030 | | - $masked = $maskObj->makeMask($width, $frame, $mask, $input->getErrorCorrectionLevel());
|
3031 | | - }
|
3032 | | -
|
3033 | | - if($masked == NULL) {
|
3034 | | - return NULL;
|
3035 | | - }
|
3036 | | -
|
3037 | | - QRtools::markTime('after_mask');
|
3038 | | -
|
3039 | | - $this->version = $version;
|
3040 | | - $this->width = $width;
|
3041 | | - $this->data = $masked;
|
3042 | | -
|
3043 | | - return $this;
|
3044 | | - }
|
3045 | | -
|
3046 | | - //----------------------------------------------------------------------
|
3047 | | - public function encodeInput(QRinput $input)
|
3048 | | - {
|
3049 | | - return $this->encodeMask($input, -1);
|
3050 | | - }
|
3051 | | -
|
3052 | | - //----------------------------------------------------------------------
|
3053 | | - public function encodeString8bit($string, $version, $level)
|
3054 | | - {
|
3055 | | - if(string == NULL) {
|
3056 | | - throw new Exception('empty string!');
|
3057 | | - return NULL;
|
3058 | | - }
|
3059 | | -
|
3060 | | - $input = new QRinput($version, $level);
|
3061 | | - if($input == NULL) return NULL;
|
3062 | | -
|
3063 | | - $ret = $input->append($input, QR_MODE_8, strlen($string), str_split($string));
|
3064 | | - if($ret < 0) {
|
3065 | | - unset($input);
|
3066 | | - return NULL;
|
3067 | | - }
|
3068 | | - return $this->encodeInput($input);
|
3069 | | - }
|
3070 | | -
|
3071 | | - //----------------------------------------------------------------------
|
3072 | | - public function encodeString($string, $version, $level, $hint, $casesensitive)
|
3073 | | - {
|
3074 | | -
|
3075 | | - if($hint != QR_MODE_8 && $hint != QR_MODE_KANJI) {
|
3076 | | - throw new Exception('bad hint');
|
3077 | | - return NULL;
|
3078 | | - }
|
3079 | | -
|
3080 | | - $input = new QRinput($version, $level);
|
3081 | | - if($input == NULL) return NULL;
|
3082 | | -
|
3083 | | - $ret = QRsplit::splitStringToQRinput($string, $input, $hint, $casesensitive);
|
3084 | | - if($ret < 0) {
|
3085 | | - return NULL;
|
3086 | | - }
|
3087 | | -
|
3088 | | - return $this->encodeInput($input);
|
3089 | | - }
|
3090 | | -
|
3091 | | - //----------------------------------------------------------------------
|
3092 | | - public static function png($text, $outfile = false, $level = QR_ECLEVEL_L, $size = 3, $margin = 4, $saveandprint=false)
|
3093 | | - {
|
3094 | | - $enc = QRencode::factory($level, $size, $margin);
|
3095 | | - return $enc->encodePNG($text, $outfile, $saveandprint=false);
|
3096 | | - }
|
3097 | | -
|
3098 | | - //----------------------------------------------------------------------
|
3099 | | - public static function text($text, $outfile = false, $level = QR_ECLEVEL_L, $size = 3, $margin = 4)
|
3100 | | - {
|
3101 | | - $enc = QRencode::factory($level, $size, $margin);
|
3102 | | - return $enc->encode($text, $outfile);
|
3103 | | - }
|
3104 | | -
|
3105 | | - //----------------------------------------------------------------------
|
3106 | | - public static function raw($text, $outfile = false, $level = QR_ECLEVEL_L, $size = 3, $margin = 4)
|
3107 | | - {
|
3108 | | - $enc = QRencode::factory($level, $size, $margin);
|
3109 | | - return $enc->encodeRAW($text, $outfile);
|
3110 | | - }
|
3111 | | - }
|
3112 | | -
|
3113 | | - //##########################################################################
|
3114 | | -
|
3115 | | - class FrameFiller {
|
3116 | | -
|
3117 | | - public $width;
|
3118 | | - public $frame;
|
3119 | | - public $x;
|
3120 | | - public $y;
|
3121 | | - public $dir;
|
3122 | | - public $bit;
|
3123 | | -
|
3124 | | - //----------------------------------------------------------------------
|
3125 | | - public function __construct($width, &$frame)
|
3126 | | - {
|
3127 | | - $this->width = $width;
|
3128 | | - $this->frame = $frame;
|
3129 | | - $this->x = $width - 1;
|
3130 | | - $this->y = $width - 1;
|
3131 | | - $this->dir = -1;
|
3132 | | - $this->bit = -1;
|
3133 | | - }
|
3134 | | -
|
3135 | | - //----------------------------------------------------------------------
|
3136 | | - public function setFrameAt($at, $val)
|
3137 | | - {
|
3138 | | - $this->frame[$at['y']][$at['x']] = chr($val);
|
3139 | | - }
|
3140 | | -
|
3141 | | - //----------------------------------------------------------------------
|
3142 | | - public function getFrameAt($at)
|
3143 | | - {
|
3144 | | - return ord($this->frame[$at['y']][$at['x']]);
|
3145 | | - }
|
3146 | | -
|
3147 | | - //----------------------------------------------------------------------
|
3148 | | - public function next()
|
3149 | | - {
|
3150 | | - do {
|
3151 | | -
|
3152 | | - if($this->bit == -1) {
|
3153 | | - $this->bit = 0;
|
3154 | | - return array('x'=>$this->x, 'y'=>$this->y);
|
3155 | | - }
|
3156 | | -
|
3157 | | - $x = $this->x;
|
3158 | | - $y = $this->y;
|
3159 | | - $w = $this->width;
|
3160 | | -
|
3161 | | - if($this->bit == 0) {
|
3162 | | - $x--;
|
3163 | | - $this->bit++;
|
3164 | | - } else {
|
3165 | | - $x++;
|
3166 | | - $y += $this->dir;
|
3167 | | - $this->bit--;
|
3168 | | - }
|
3169 | | -
|
3170 | | - if($this->dir < 0) {
|
3171 | | - if($y < 0) {
|
3172 | | - $y = 0;
|
3173 | | - $x -= 2;
|
3174 | | - $this->dir = 1;
|
3175 | | - if($x == 6) {
|
3176 | | - $x--;
|
3177 | | - $y = 9;
|
3178 | | - }
|
3179 | | - }
|
3180 | | - } else {
|
3181 | | - if($y == $w) {
|
3182 | | - $y = $w - 1;
|
3183 | | - $x -= 2;
|
3184 | | - $this->dir = -1;
|
3185 | | - if($x == 6) {
|
3186 | | - $x--;
|
3187 | | - $y -= 8;
|
3188 | | - }
|
3189 | | - }
|
3190 | | - }
|
3191 | | - if($x < 0 || $y < 0) return null;
|
3192 | | -
|
3193 | | - $this->x = $x;
|
3194 | | - $this->y = $y;
|
3195 | | -
|
3196 | | - } while(ord($this->frame[$y][$x]) & 0x80);
|
3197 | | -
|
3198 | | - return array('x'=>$x, 'y'=>$y);
|
3199 | | - }
|
3200 | | -
|
3201 | | - } ;
|
3202 | | -
|
3203 | | - //##########################################################################
|
3204 | | -
|
3205 | | - class QRencode {
|
3206 | | -
|
3207 | | - public $casesensitive = true;
|
3208 | | - public $eightbit = false;
|
3209 | | -
|
3210 | | - public $version = 0;
|
3211 | | - public $size = 3;
|
3212 | | - public $margin = 4;
|
3213 | | -
|
3214 | | - public $structured = 0; // not supported yet
|
3215 | | -
|
3216 | | - public $level = QR_ECLEVEL_L;
|
3217 | | - public $hint = QR_MODE_8;
|
3218 | | -
|
3219 | | - //----------------------------------------------------------------------
|
3220 | | - public static function factory($level = QR_ECLEVEL_L, $size = 3, $margin = 4)
|
3221 | | - {
|
3222 | | - $enc = new QRencode();
|
3223 | | - $enc->size = $size;
|
3224 | | - $enc->margin = $margin;
|
3225 | | -
|
3226 | | - switch ($level.'') {
|
3227 | | - case '0':
|
3228 | | - case '1':
|
3229 | | - case '2':
|
3230 | | - case '3':
|
3231 | | - $enc->level = $level;
|
3232 | | - break;
|
3233 | | - case 'l':
|
3234 | | - case 'L':
|
3235 | | - $enc->level = QR_ECLEVEL_L;
|
3236 | | - break;
|
3237 | | - case 'm':
|
3238 | | - case 'M':
|
3239 | | - $enc->level = QR_ECLEVEL_M;
|
3240 | | - break;
|
3241 | | - case 'q':
|
3242 | | - case 'Q':
|
3243 | | - $enc->level = QR_ECLEVEL_Q;
|
3244 | | - break;
|
3245 | | - case 'h':
|
3246 | | - case 'H':
|
3247 | | - $enc->level = QR_ECLEVEL_H;
|
3248 | | - break;
|
3249 | | - }
|
3250 | | -
|
3251 | | - return $enc;
|
3252 | | - }
|
3253 | | -
|
3254 | | - //----------------------------------------------------------------------
|
3255 | | - public function encodeRAW($intext, $outfile = false)
|
3256 | | - {
|
3257 | | - $code = new QRcode();
|
3258 | | -
|
3259 | | - if($this->eightbit) {
|
3260 | | - $code->encodeString8bit($intext, $this->version, $this->level);
|
3261 | | - } else {
|
3262 | | - $code->encodeString($intext, $this->version, $this->level, $this->hint, $this->casesensitive);
|
3263 | | - }
|
3264 | | -
|
3265 | | - return $code->data;
|
3266 | | - }
|
3267 | | -
|
3268 | | - //----------------------------------------------------------------------
|
3269 | | - public function encode($intext, $outfile = false)
|
3270 | | - {
|
3271 | | - $code = new QRcode();
|
3272 | | -
|
3273 | | - if($this->eightbit) {
|
3274 | | - $code->encodeString8bit($intext, $this->version, $this->level);
|
3275 | | - } else {
|
3276 | | - $code->encodeString($intext, $this->version, $this->level, $this->hint, $this->casesensitive);
|
3277 | | - }
|
3278 | | -
|
3279 | | - QRtools::markTime('after_encode');
|
3280 | | -
|
3281 | | - if ($outfile!== false) {
|
3282 | | - file_put_contents($outfile, join("\n", QRtools::binarize($code->data)));
|
3283 | | - } else {
|
3284 | | - return QRtools::binarize($code->data);
|
3285 | | - }
|
3286 | | - }
|
3287 | | -
|
3288 | | - //----------------------------------------------------------------------
|
3289 | | - public function encodePNG($intext, $outfile = false,$saveandprint=false)
|
3290 | | - {
|
3291 | | - try {
|
3292 | | -
|
3293 | | - ob_start();
|
3294 | | - $tab = $this->encode($intext);
|
3295 | | - $err = ob_get_contents();
|
3296 | | - ob_end_clean();
|
3297 | | -
|
3298 | | - if ($err != '')
|
3299 | | - QRtools::log($outfile, $err);
|
3300 | | -
|
3301 | | - $maxSize = (int)(QR_PNG_MAXIMUM_SIZE / (count($tab)+2*$this->margin));
|
3302 | | -
|
3303 | | - QRimage::png($tab, $outfile, min(max(1, $this->size), $maxSize), $this->margin,$saveandprint);
|
3304 | | -
|
3305 | | - } catch (Exception $e) {
|
3306 | | -
|
3307 | | - QRtools::log($outfile, $e->getMessage());
|
3308 | | -
|
3309 | | - }
|
3310 | | - }
|
3311 | | - }
|
3312 | 2805 | |
| 2806 | +/* |
| 2807 | + * PHP QR Code encoder |
| 2808 | + * |
| 2809 | + * Main encoder classes. |
| 2810 | + * |
| 2811 | + * Based on libqrencode C library distributed under LGPL 2.1 |
| 2812 | + * Copyright (C) 2006, 2007, 2008, 2009 Kentaro Fukuchi <fukuchi@megaui.net> |
| 2813 | + * |
| 2814 | + * PHP QR Code is distributed under LGPL 3 |
| 2815 | + * Copyright (C) 2010 Dominik Dzienia <deltalab at poczta dot fm> |
| 2816 | + * |
| 2817 | + * This library is free software; you can redistribute it and/or |
| 2818 | + * modify it under the terms of the GNU Lesser General Public |
| 2819 | + * License as published by the Free Software Foundation; either |
| 2820 | + * version 3 of the License, or any later version. |
| 2821 | + * |
| 2822 | + * This library is distributed in the hope that it will be useful, |
| 2823 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 2824 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 2825 | + * Lesser General Public License for more details. |
| 2826 | + * |
| 2827 | + * You should have received a copy of the GNU Lesser General Public |
| 2828 | + * License along with this library; if not, write to the Free Software |
| 2829 | + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 2830 | + */ |
| 2831 | + |
| 2832 | + class QRrsblock { |
| 2833 | + public $dataLength; |
| 2834 | + public $data = array(); |
| 2835 | + public $eccLength; |
| 2836 | + public $ecc = array(); |
| 2837 | + |
| 2838 | + public function __construct($dl, $data, $el, &$ecc, QRrsItem $rs) |
| 2839 | + { |
| 2840 | + $rs->encode_rs_char($data, $ecc); |
| 2841 | + |
| 2842 | + $this->dataLength = $dl; |
| 2843 | + $this->data = $data; |
| 2844 | + $this->eccLength = $el; |
| 2845 | + $this->ecc = $ecc; |
| 2846 | + } |
| 2847 | + }; |
| 2848 | + |
| 2849 | + //########################################################################## |
3313 | 2850 | |
| 2851 | + class QRrawcode { |
| 2852 | + public $version; |
| 2853 | + public $datacode = array(); |
| 2854 | + public $ecccode = array(); |
| 2855 | + public $blocks; |
| 2856 | + public $rsblocks = array(); //of RSblock |
| 2857 | + public $count; |
| 2858 | + public $dataLength; |
| 2859 | + public $eccLength; |
| 2860 | + public $b1; |
| 2861 | + |
| 2862 | + //---------------------------------------------------------------------- |
| 2863 | + public function __construct(QRinput $input) |
| 2864 | + { |
| 2865 | + $spec = array(0,0,0,0,0); |
| 2866 | + |
| 2867 | + $this->datacode = $input->getByteStream(); |
| 2868 | + if(is_null($this->datacode)) { |
| 2869 | + throw new Exception('null imput string'); |
| 2870 | + } |
| 2871 | + |
| 2872 | + QRspec::getEccSpec($input->getVersion(), $input->getErrorCorrectionLevel(), $spec); |
| 2873 | + |
| 2874 | + $this->version = $input->getVersion(); |
| 2875 | + $this->b1 = QRspec::rsBlockNum1($spec); |
| 2876 | + $this->dataLength = QRspec::rsDataLength($spec); |
| 2877 | + $this->eccLength = QRspec::rsEccLength($spec); |
| 2878 | + $this->ecccode = array_fill(0, $this->eccLength, 0); |
| 2879 | + $this->blocks = QRspec::rsBlockNum($spec); |
| 2880 | + |
| 2881 | + $ret = $this->init($spec); |
| 2882 | + if($ret < 0) { |
| 2883 | + throw new Exception('block alloc error'); |
| 2884 | + } |
| 2885 | + |
| 2886 | + $this->count = 0; |
| 2887 | + } |
| 2888 | + |
| 2889 | + //---------------------------------------------------------------------- |
| 2890 | + public function init(array $spec) |
| 2891 | + { |
| 2892 | + $dl = QRspec::rsDataCodes1($spec); |
| 2893 | + $el = QRspec::rsEccCodes1($spec); |
| 2894 | + $rs = QRrs::init_rs(8, 0x11d, 0, 1, $el, 255 - $dl - $el); |
| 2895 | + |
| 2896 | + |
| 2897 | + $blockNo = 0; |
| 2898 | + $dataPos = 0; |
| 2899 | + $eccPos = 0; |
| 2900 | + for($i=0; $i<QRspec::rsBlockNum1($spec); $i++) { |
| 2901 | + $ecc = array_slice($this->ecccode,$eccPos); |
| 2902 | + $this->rsblocks[$blockNo] = new QRrsblock($dl, array_slice($this->datacode, $dataPos), $el, $ecc, $rs); |
| 2903 | + $this->ecccode = array_merge(array_slice($this->ecccode,0, $eccPos), $ecc); |
| 2904 | + |
| 2905 | + $dataPos += $dl; |
| 2906 | + $eccPos += $el; |
| 2907 | + $blockNo++; |
| 2908 | + } |
| 2909 | + |
| 2910 | + if(QRspec::rsBlockNum2($spec) == 0) |
| 2911 | + return 0; |
| 2912 | + |
| 2913 | + $dl = QRspec::rsDataCodes2($spec); |
| 2914 | + $el = QRspec::rsEccCodes2($spec); |
| 2915 | + $rs = QRrs::init_rs(8, 0x11d, 0, 1, $el, 255 - $dl - $el); |
| 2916 | + |
| 2917 | + if($rs == NULL) return -1; |
| 2918 | + |
| 2919 | + for($i=0; $i<QRspec::rsBlockNum2($spec); $i++) { |
| 2920 | + $ecc = array_slice($this->ecccode,$eccPos); |
| 2921 | + $this->rsblocks[$blockNo] = new QRrsblock($dl, array_slice($this->datacode, $dataPos), $el, $ecc, $rs); |
| 2922 | + $this->ecccode = array_merge(array_slice($this->ecccode,0, $eccPos), $ecc); |
| 2923 | + |
| 2924 | + $dataPos += $dl; |
| 2925 | + $eccPos += $el; |
| 2926 | + $blockNo++; |
| 2927 | + } |
| 2928 | + |
| 2929 | + return 0; |
| 2930 | + } |
| 2931 | + |
| 2932 | + //---------------------------------------------------------------------- |
| 2933 | + public function getCode() |
| 2934 | + { |
| 2935 | + if($this->count < $this->dataLength) { |
| 2936 | + $row = $this->count % $this->blocks; |
| 2937 | + $col = $this->count / $this->blocks; |
| 2938 | + if($col >= $this->rsblocks[0]->dataLength) { |
| 2939 | + $row += $this->b1; |
| 2940 | + } |
| 2941 | + $ret = $this->rsblocks[$row]->data[$col]; |
| 2942 | + } else if($this->count < $this->dataLength + $this->eccLength) { |
| 2943 | + $row = ($this->count - $this->dataLength) % $this->blocks; |
| 2944 | + $col = ($this->count - $this->dataLength) / $this->blocks; |
| 2945 | + $ret = $this->rsblocks[$row]->ecc[$col]; |
| 2946 | + } else { |
| 2947 | + return 0; |
| 2948 | + } |
| 2949 | + $this->count++; |
| 2950 | + |
| 2951 | + return $ret; |
| 2952 | + } |
| 2953 | + } |
| 2954 | + |
| 2955 | + //########################################################################## |
| 2956 | + |
| 2957 | + class QRcode { |
| 2958 | + |
| 2959 | + public $version; |
| 2960 | + public $width; |
| 2961 | + public $data; |
| 2962 | + |
| 2963 | + //---------------------------------------------------------------------- |
| 2964 | + public function encodeMask(QRinput $input, $mask) |
| 2965 | + { |
| 2966 | + if($input->getVersion() < 0 || $input->getVersion() > QRSPEC_VERSION_MAX) { |
| 2967 | + throw new Exception('wrong version'); |
| 2968 | + } |
| 2969 | + if($input->getErrorCorrectionLevel() > QR_ECLEVEL_H) { |
| 2970 | + throw new Exception('wrong level'); |
| 2971 | + } |
| 2972 | + |
| 2973 | + $raw = new QRrawcode($input); |
| 2974 | + |
| 2975 | + QRtools::markTime('after_raw'); |
| 2976 | + |
| 2977 | + $version = $raw->version; |
| 2978 | + $width = QRspec::getWidth($version); |
| 2979 | + $frame = QRspec::newFrame($version); |
| 2980 | + |
| 2981 | + $filler = new FrameFiller($width, $frame); |
| 2982 | + if(is_null($filler)) { |
| 2983 | + return NULL; |
| 2984 | + } |
| 2985 | + |
| 2986 | + // inteleaved data and ecc codes |
| 2987 | + for($i=0; $i<$raw->dataLength + $raw->eccLength; $i++) { |
| 2988 | + $code = $raw->getCode(); |
| 2989 | + $bit = 0x80; |
| 2990 | + for($j=0; $j<8; $j++) { |
| 2991 | + $addr = $filler->next(); |
| 2992 | + $filler->setFrameAt($addr, 0x02 | (($bit & $code) != 0)); |
| 2993 | + $bit = $bit >> 1; |
| 2994 | + } |
| 2995 | + } |
| 2996 | + |
| 2997 | + QRtools::markTime('after_filler'); |
| 2998 | + |
| 2999 | + unset($raw); |
| 3000 | + |
| 3001 | + // remainder bits |
| 3002 | + $j = QRspec::getRemainder($version); |
| 3003 | + for($i=0; $i<$j; $i++) { |
| 3004 | + $addr = $filler->next(); |
| 3005 | + $filler->setFrameAt($addr, 0x02); |
| 3006 | + } |
| 3007 | + |
| 3008 | + $frame = $filler->frame; |
| 3009 | + unset($filler); |
| 3010 | + |
| 3011 | + |
| 3012 | + // masking |
| 3013 | + $maskObj = new QRmask(); |
| 3014 | + if($mask < 0) { |
| 3015 | + |
| 3016 | + if (QR_FIND_BEST_MASK) { |
| 3017 | + $masked = $maskObj->mask($width, $frame, $input->getErrorCorrectionLevel()); |
| 3018 | + } else { |
| 3019 | + $masked = $maskObj->makeMask($width, $frame, (intval(QR_DEFAULT_MASK) % 8), $input->getErrorCorrectionLevel()); |
| 3020 | + } |
| 3021 | + } else { |
| 3022 | + $masked = $maskObj->makeMask($width, $frame, $mask, $input->getErrorCorrectionLevel()); |
| 3023 | + } |
| 3024 | + |
| 3025 | + if($masked == NULL) { |
| 3026 | + return NULL; |
| 3027 | + } |
| 3028 | + |
| 3029 | + QRtools::markTime('after_mask'); |
| 3030 | + |
| 3031 | + $this->version = $version; |
| 3032 | + $this->width = $width; |
| 3033 | + $this->data = $masked; |
| 3034 | + |
| 3035 | + return $this; |
| 3036 | + } |
| 3037 | + |
| 3038 | + //---------------------------------------------------------------------- |
| 3039 | + public function encodeInput(QRinput $input) |
| 3040 | + { |
| 3041 | + return $this->encodeMask($input, -1); |
| 3042 | + } |
| 3043 | + |
| 3044 | + //---------------------------------------------------------------------- |
| 3045 | + public function encodeString8bit($string, $version, $level) |
| 3046 | + { |
| 3047 | + if($string == NULL) { |
| 3048 | + throw new Exception('empty string!'); |
| 3049 | + } |
| 3050 | + |
| 3051 | + $input = new QRinput($version, $level); |
| 3052 | + if($input == NULL) return NULL; |
| 3053 | + |
| 3054 | + $ret = $input->append($input, QR_MODE_8, strlen($string), str_split($string)); |
| 3055 | + if($ret < 0) { |
| 3056 | + unset($input); |
| 3057 | + return NULL; |
| 3058 | + } |
| 3059 | + return $this->encodeInput($input); |
| 3060 | + } |
| 3061 | + |
| 3062 | + //---------------------------------------------------------------------- |
| 3063 | + public function encodeString($string, $version, $level, $hint, $casesensitive) |
| 3064 | + { |
| 3065 | + |
| 3066 | + if($hint != QR_MODE_8 && $hint != QR_MODE_KANJI) { |
| 3067 | + throw new Exception('bad hint'); |
| 3068 | + } |
| 3069 | + |
| 3070 | + $input = new QRinput($version, $level); |
| 3071 | + if($input == NULL) return NULL; |
| 3072 | + |
| 3073 | + $ret = QRsplit::splitStringToQRinput($string, $input, $hint, $casesensitive); |
| 3074 | + if($ret < 0) { |
| 3075 | + return NULL; |
| 3076 | + } |
| 3077 | + |
| 3078 | + return $this->encodeInput($input); |
| 3079 | + } |
| 3080 | + |
| 3081 | + //---------------------------------------------------------------------- |
| 3082 | + public static function png($text, $outfile = false, $level = QR_ECLEVEL_L, $size = 3, $margin = 4, $saveandprint=false) |
| 3083 | + { |
| 3084 | + $enc = QRencode::factory($level, $size, $margin); |
| 3085 | + return $enc->encodePNG($text, $outfile, $saveandprint=false); |
| 3086 | + } |
| 3087 | + |
| 3088 | + //---------------------------------------------------------------------- |
| 3089 | + public static function text($text, $outfile = false, $level = QR_ECLEVEL_L, $size = 3, $margin = 4) |
| 3090 | + { |
| 3091 | + $enc = QRencode::factory($level, $size, $margin); |
| 3092 | + return $enc->encode($text, $outfile); |
| 3093 | + } |
| 3094 | + |
| 3095 | + //---------------------------------------------------------------------- |
| 3096 | + public static function raw($text, $outfile = false, $level = QR_ECLEVEL_L, $size = 3, $margin = 4) |
| 3097 | + { |
| 3098 | + $enc = QRencode::factory($level, $size, $margin); |
| 3099 | + return $enc->encodeRAW($text, $outfile); |
| 3100 | + } |
| 3101 | + } |
| 3102 | + |
| 3103 | + //########################################################################## |
| 3104 | + |
| 3105 | + class FrameFiller { |
| 3106 | + |
| 3107 | + public $width; |
| 3108 | + public $frame; |
| 3109 | + public $x; |
| 3110 | + public $y; |
| 3111 | + public $dir; |
| 3112 | + public $bit; |
| 3113 | + |
| 3114 | + //---------------------------------------------------------------------- |
| 3115 | + public function __construct($width, &$frame) |
| 3116 | + { |
| 3117 | + $this->width = $width; |
| 3118 | + $this->frame = $frame; |
| 3119 | + $this->x = $width - 1; |
| 3120 | + $this->y = $width - 1; |
| 3121 | + $this->dir = -1; |
| 3122 | + $this->bit = -1; |
| 3123 | + } |
| 3124 | + |
| 3125 | + //---------------------------------------------------------------------- |
| 3126 | + public function setFrameAt($at, $val) |
| 3127 | + { |
| 3128 | + $this->frame[$at['y']][$at['x']] = chr($val); |
| 3129 | + } |
| 3130 | + |
| 3131 | + //---------------------------------------------------------------------- |
| 3132 | + public function getFrameAt($at) |
| 3133 | + { |
| 3134 | + return ord($this->frame[$at['y']][$at['x']]); |
| 3135 | + } |
| 3136 | + |
| 3137 | + //---------------------------------------------------------------------- |
| 3138 | + public function next() |
| 3139 | + { |
| 3140 | + do { |
| 3141 | + |
| 3142 | + if($this->bit == -1) { |
| 3143 | + $this->bit = 0; |
| 3144 | + return array('x'=>$this->x, 'y'=>$this->y); |
| 3145 | + } |
| 3146 | + |
| 3147 | + $x = $this->x; |
| 3148 | + $y = $this->y; |
| 3149 | + $w = $this->width; |
| 3150 | + |
| 3151 | + if($this->bit == 0) { |
| 3152 | + $x--; |
| 3153 | + $this->bit++; |
| 3154 | + } else { |
| 3155 | + $x++; |
| 3156 | + $y += $this->dir; |
| 3157 | + $this->bit--; |
| 3158 | + } |
| 3159 | + |
| 3160 | + if($this->dir < 0) { |
| 3161 | + if($y < 0) { |
| 3162 | + $y = 0; |
| 3163 | + $x -= 2; |
| 3164 | + $this->dir = 1; |
| 3165 | + if($x == 6) { |
| 3166 | + $x--; |
| 3167 | + $y = 9; |
| 3168 | + } |
| 3169 | + } |
| 3170 | + } else { |
| 3171 | + if($y == $w) { |
| 3172 | + $y = $w - 1; |
| 3173 | + $x -= 2; |
| 3174 | + $this->dir = -1; |
| 3175 | + if($x == 6) { |
| 3176 | + $x--; |
| 3177 | + $y -= 8; |
| 3178 | + } |
| 3179 | + } |
| 3180 | + } |
| 3181 | + if($x < 0 || $y < 0) return null; |
| 3182 | + |
| 3183 | + $this->x = $x; |
| 3184 | + $this->y = $y; |
| 3185 | + |
| 3186 | + } while(ord($this->frame[$y][$x]) & 0x80); |
| 3187 | + |
| 3188 | + return array('x'=>$x, 'y'=>$y); |
| 3189 | + } |
| 3190 | + |
| 3191 | + } ; |
| 3192 | + |
| 3193 | + //########################################################################## |
| 3194 | + |
| 3195 | + class QRencode { |
| 3196 | + |
| 3197 | + public $casesensitive = true; |
| 3198 | + public $eightbit = false; |
| 3199 | + |
| 3200 | + public $version = 0; |
| 3201 | + public $size = 3; |
| 3202 | + public $margin = 4; |
| 3203 | + |
| 3204 | + public $structured = 0; // not supported yet |
| 3205 | + |
| 3206 | + public $level = QR_ECLEVEL_L; |
| 3207 | + public $hint = QR_MODE_8; |
| 3208 | + |
| 3209 | + //---------------------------------------------------------------------- |
| 3210 | + public static function factory($level = QR_ECLEVEL_L, $size = 3, $margin = 4) |
| 3211 | + { |
| 3212 | + $enc = new QRencode(); |
| 3213 | + $enc->size = $size; |
| 3214 | + $enc->margin = $margin; |
| 3215 | + |
| 3216 | + switch ($level.'') { |
| 3217 | + case '0': |
| 3218 | + case '1': |
| 3219 | + case '2': |
| 3220 | + case '3': |
| 3221 | + $enc->level = $level; |
| 3222 | + break; |
| 3223 | + case 'l': |
| 3224 | + case 'L': |
| 3225 | + $enc->level = QR_ECLEVEL_L; |
| 3226 | + break; |
| 3227 | + case 'm': |
| 3228 | + case 'M': |
| 3229 | + $enc->level = QR_ECLEVEL_M; |
| 3230 | + break; |
| 3231 | + case 'q': |
| 3232 | + case 'Q': |
| 3233 | + $enc->level = QR_ECLEVEL_Q; |
| 3234 | + break; |
| 3235 | + case 'h': |
| 3236 | + case 'H': |
| 3237 | + $enc->level = QR_ECLEVEL_H; |
| 3238 | + break; |
| 3239 | + } |
| 3240 | + |
| 3241 | + return $enc; |
| 3242 | + } |
| 3243 | + |
| 3244 | + //---------------------------------------------------------------------- |
| 3245 | + public function encodeRAW($intext, $outfile = false) |
| 3246 | + { |
| 3247 | + $code = new QRcode(); |
| 3248 | + |
| 3249 | + if($this->eightbit) { |
| 3250 | + $code->encodeString8bit($intext, $this->version, $this->level); |
| 3251 | + } else { |
| 3252 | + $code->encodeString($intext, $this->version, $this->level, $this->hint, $this->casesensitive); |
| 3253 | + } |
| 3254 | + |
| 3255 | + return $code->data; |
| 3256 | + } |
| 3257 | + |
| 3258 | + //---------------------------------------------------------------------- |
| 3259 | + public function encode($intext, $outfile = false) |
| 3260 | + { |
| 3261 | + $code = new QRcode(); |
| 3262 | + |
| 3263 | + if($this->eightbit) { |
| 3264 | + $code->encodeString8bit($intext, $this->version, $this->level); |
| 3265 | + } else { |
| 3266 | + $code->encodeString($intext, $this->version, $this->level, $this->hint, $this->casesensitive); |
| 3267 | + } |
| 3268 | + |
| 3269 | + QRtools::markTime('after_encode'); |
| 3270 | + |
| 3271 | + if ($outfile!== false) { |
| 3272 | + file_put_contents($outfile, join("\n", QRtools::binarize($code->data))); |
| 3273 | + } else { |
| 3274 | + return QRtools::binarize($code->data); |
| 3275 | + } |
| 3276 | + } |
| 3277 | + |
| 3278 | + //---------------------------------------------------------------------- |
| 3279 | + public function encodePNG($intext, $outfile = false,$saveandprint=false) |
| 3280 | + { |
| 3281 | + try { |
| 3282 | + |
| 3283 | + ob_start(); |
| 3284 | + $tab = $this->encode($intext); |
| 3285 | + $err = ob_get_contents(); |
| 3286 | + ob_end_clean(); |
| 3287 | + |
| 3288 | + if ($err != '') |
| 3289 | + QRtools::log($outfile, $err); |
| 3290 | + |
| 3291 | + $maxSize = (int)(QR_PNG_MAXIMUM_SIZE / (count($tab)+2*$this->margin)); |
| 3292 | + |
| 3293 | + QRimage::png($tab, $outfile, min(max(1, $this->size), $maxSize), $this->margin,$saveandprint); |
| 3294 | + |
| 3295 | + } catch (Exception $e) { |
| 3296 | + |
| 3297 | + QRtools::log($outfile, $e->getMessage()); |
| 3298 | + |
| 3299 | + } |
| 3300 | + } |
| 3301 | + } |
| 3302 | + |
| 3303 | + |
Index: trunk/extensions/MwEmbed/MwEmbed/includes/NamedResourceLoader.php |
— | — | @@ -57,7 +57,6 @@ |
58 | 58 | if ( !is_file( $mwEmbedAbsolutePath . '/loader.js' ) ) { |
59 | 59 | // throw error no mwEmbed found |
60 | 60 | throw new MWException( "mwEmbed loader.js missing check \$wgMwEmbedDirectory path\n" ); |
61 | | - return false; |
62 | 61 | } |
63 | 62 | |
64 | 63 | // Process the mwEmbed loader file: |
— | — | @@ -126,7 +125,6 @@ |
127 | 126 | // Check for the loader.js |
128 | 127 | if( !is_file( $modulePath . '/loader.js' ) ){ |
129 | 128 | throw new MWException( "Javascript Module $moduleName missing loader.js file\n" ); |
130 | | - return false; |
131 | 129 | } |
132 | 130 | |
133 | 131 | $fileContent = file_get_contents( $modulePath . '/loader.js'); |
Index: trunk/extensions/MetavidWiki/includes/MV_ImageGallery.php |
— | — | @@ -12,7 +12,6 @@ |
13 | 13 | if ( !defined( 'MEDIAWIKI' ) ) die( 1 ); |
14 | 14 | class MV_ImageGallery extends ImageGallery { |
15 | 15 | private $mAttribs = array(); |
16 | | - private $contextTitle = false; |
17 | 16 | |
18 | 17 | private $mPerRow = 4; // How many images wide should the gallery be? |
19 | 18 | private $mWidths = 160, $mHeights = 120; // How wide/tall each thumbnail should be |
Index: trunk/extensions/MetavidWiki/includes/MV_Index.php |
— | — | @@ -256,7 +256,7 @@ |
257 | 257 | $vars, |
258 | 258 | $conds, |
259 | 259 | __METHOD__, |
260 | | - $options ); ; |
| 260 | + $options ); |
261 | 261 | } |
262 | 262 | function remove_by_stream_id( $stream_id ) { |
263 | 263 | $dbw = wfGetDB( DB_WRITE ); |
Index: trunk/extensions/MetavidWiki/skins/mv_embed/flvServer/FLV/Tag.php |
— | — | @@ -50,7 +50,5 @@ |
51 | 51 | default: |
52 | 52 | return new FLV_Tag_Generic( $hdr ); |
53 | 53 | } |
54 | | - return null; |
55 | 54 | } |
56 | | - |
57 | 55 | } |
Index: trunk/extensions/TimedMediaHandler/TimedMediaHandler_body.php |
— | — | @@ -458,7 +458,6 @@ |
459 | 459 | $doOutput ){ |
460 | 460 | output_iframe_page( $title ); |
461 | 461 | exit(); |
462 | | - return false; |
463 | 462 | } |
464 | 463 | return true; |
465 | 464 | } |
— | — | @@ -647,7 +646,6 @@ |
648 | 647 | |
649 | 648 | if(!$wgEnableIframeEmbed){ |
650 | 649 | throw new MWException( __METHOD__ .' is not enabled' ); |
651 | | - return false; |
652 | 650 | } |
653 | 651 | |
654 | 652 | $videoParam['width'] = ( isset( $_GET['width'] ) ) ? intval( $_GET['width'] ) : '400'; |
Index: trunk/extensions/FCKeditor/FCKeditor.body.php |
— | — | @@ -18,8 +18,6 @@ |
19 | 19 | class FCKeditor_MediaWiki { |
20 | 20 | public $showFCKEditor; |
21 | 21 | private $count = array(); |
22 | | - private $wgFCKBypassText = ''; |
23 | | - private $debug = 0; |
24 | 22 | private $excludedNamespaces; |
25 | 23 | private $oldTextBox1; |
26 | 24 | static $nsToggles = array( |
Index: trunk/extensions/QPoll/Excel/Excel_Format.php |
— | — | @@ -1008,8 +1008,8 @@ |
1009 | 1009 | return $this->raiseError("Invalid value for angle.". |
1010 | 1010 | " Possible values are: 0, 90, 270 and -1 ". |
1011 | 1011 | "for stacking top-to-bottom."); |
1012 | | - $this->_rotation = 0; |
1013 | | - break; |
| 1012 | + //$this->_rotation = 0; |
| 1013 | + //break; |
1014 | 1014 | } |
1015 | 1015 | } |
1016 | 1016 | |
Index: trunk/extensions/DeleteQueue/Views/DeleteQueueViewReview.php |
— | — | @@ -302,7 +302,7 @@ |
303 | 303 | default: |
304 | 304 | // Invalid action |
305 | 305 | $dbw->commit(); |
306 | | - return wfMsg( 'deletequeue-review-badaction' ); ; |
| 306 | + return wfMsg( 'deletequeue-review-badaction' ); |
307 | 307 | } |
308 | 308 | |
309 | 309 | if ( $processed ) { |
Index: trunk/extensions/JSBreadCrumbs/JSBreadCrumbs.hooks.php |
— | — | @@ -1,8 +1,5 @@ |
2 | 2 | <?php |
3 | 3 | class JSBreadCrumbsHooks { |
4 | | - |
5 | | - private static $variables = array(); |
6 | | - |
7 | 4 | /** |
8 | 5 | * BeforePageDisplay hook |
9 | 6 | */ |