@@ -93,56 +93,56 @@ discard block |
||
| 93 | 93 | var $maxInclTemplateSize = 1000000; // maximum length of template string when including subtemplates |
| 94 | 94 | var $template; // Template file data |
| 95 | 95 | var $varTab; // variables table, array index is variable no |
| 96 | - // Fields: |
|
| 97 | - // varName // variable name |
|
| 98 | - // varValue // variable value |
|
| 96 | + // Fields: |
|
| 97 | + // varName // variable name |
|
| 98 | + // varValue // variable value |
|
| 99 | 99 | var $varTabCnt; // no of entries used in VarTab |
| 100 | 100 | var $varNameToNoMap; // maps variable names to variable numbers |
| 101 | 101 | var $varRefTab; // variable references table |
| 102 | - // Contains an entry for each variable reference in the template. Ordered by TemplatePos. |
|
| 103 | - // Fields: |
|
| 104 | - // varNo // variable no |
|
| 105 | - // tPosBegin // template position of begin of variable reference |
|
| 106 | - // tPosEnd // template position of end of variable reference |
|
| 107 | - // blockNo // block no of the (innermost) block that contains this variable reference |
|
| 108 | - // blockVarNo // block variable no. Index into BlockInstTab.BlockVarTab |
|
| 102 | + // Contains an entry for each variable reference in the template. Ordered by TemplatePos. |
|
| 103 | + // Fields: |
|
| 104 | + // varNo // variable no |
|
| 105 | + // tPosBegin // template position of begin of variable reference |
|
| 106 | + // tPosEnd // template position of end of variable reference |
|
| 107 | + // blockNo // block no of the (innermost) block that contains this variable reference |
|
| 108 | + // blockVarNo // block variable no. Index into BlockInstTab.BlockVarTab |
|
| 109 | 109 | var $varRefTabCnt; // no of entries used in VarRefTab |
| 110 | 110 | var $blockTab; // Blocks table, array index is block no |
| 111 | - // Contains an entry for each block in the template. Ordered by TPosBegin. |
|
| 112 | - // Fields: |
|
| 113 | - // blockName // block name |
|
| 114 | - // nextWithSameName; // block no of next block with same name or -1 (blocks are backward linked in relation to template position) |
|
| 115 | - // tPosBegin // template position of begin of block |
|
| 116 | - // tPosContentsBegin // template pos of begin of block contents |
|
| 117 | - // tPosContentsEnd // template pos of end of block contents |
|
| 118 | - // tPosEnd // template position of end of block |
|
| 119 | - // nestingLevel // block nesting level |
|
| 120 | - // parentBlockNo // block no of parent block |
|
| 121 | - // definitionIsOpen // true while $BeginBlock processed but no $EndBlock |
|
| 122 | - // instances // number of instances of this block |
|
| 123 | - // firstBlockInstNo // block instance no of first instance of this block or -1 |
|
| 124 | - // lastBlockInstNo // block instance no of last instance of this block or -1 |
|
| 125 | - // currBlockInstNo // current block instance no, used during generation of output file |
|
| 126 | - // blockVarCnt // no of variables in block |
|
| 127 | - // blockVarNoToVarNoMap // maps block variable numbers to variable numbers |
|
| 128 | - // firstVarRefNo // variable reference no of first variable of this block or -1 |
|
| 111 | + // Contains an entry for each block in the template. Ordered by TPosBegin. |
|
| 112 | + // Fields: |
|
| 113 | + // blockName // block name |
|
| 114 | + // nextWithSameName; // block no of next block with same name or -1 (blocks are backward linked in relation to template position) |
|
| 115 | + // tPosBegin // template position of begin of block |
|
| 116 | + // tPosContentsBegin // template pos of begin of block contents |
|
| 117 | + // tPosContentsEnd // template pos of end of block contents |
|
| 118 | + // tPosEnd // template position of end of block |
|
| 119 | + // nestingLevel // block nesting level |
|
| 120 | + // parentBlockNo // block no of parent block |
|
| 121 | + // definitionIsOpen // true while $BeginBlock processed but no $EndBlock |
|
| 122 | + // instances // number of instances of this block |
|
| 123 | + // firstBlockInstNo // block instance no of first instance of this block or -1 |
|
| 124 | + // lastBlockInstNo // block instance no of last instance of this block or -1 |
|
| 125 | + // currBlockInstNo // current block instance no, used during generation of output file |
|
| 126 | + // blockVarCnt // no of variables in block |
|
| 127 | + // blockVarNoToVarNoMap // maps block variable numbers to variable numbers |
|
| 128 | + // firstVarRefNo // variable reference no of first variable of this block or -1 |
|
| 129 | 129 | var $blockTabCnt; // no of entries used in BlockTab |
| 130 | 130 | var $blockNameToNoMap; // maps block names to block numbers |
| 131 | 131 | var $openBlocksTab; |
| 132 | - // During parsing, this table contains the block numbers of the open parent blocks (nested outer blocks). |
|
| 133 | - // Indexed by the block nesting level. |
|
| 132 | + // During parsing, this table contains the block numbers of the open parent blocks (nested outer blocks). |
|
| 133 | + // Indexed by the block nesting level. |
|
| 134 | 134 | var $blockInstTab; // block instances table |
| 135 | - // This table contains an entry for each block instance that has been added. |
|
| 136 | - // Indexed by BlockInstNo. |
|
| 137 | - // Fields: |
|
| 138 | - // blockNo // block number |
|
| 139 | - // instanceLevel // instance level of this block |
|
| 140 | - // InstanceLevel is an instance counter per block. |
|
| 141 | - // (In contrast to blockInstNo, which is an instance counter over the instances of all blocks) |
|
| 142 | - // parentInstLevel // instance level of parent block |
|
| 143 | - // nextBlockInstNo // pointer to next instance of this block or -1 |
|
| 144 | - // Forward chain for instances of same block. |
|
| 145 | - // blockVarTab // block instance variables |
|
| 135 | + // This table contains an entry for each block instance that has been added. |
|
| 136 | + // Indexed by BlockInstNo. |
|
| 137 | + // Fields: |
|
| 138 | + // blockNo // block number |
|
| 139 | + // instanceLevel // instance level of this block |
|
| 140 | + // InstanceLevel is an instance counter per block. |
|
| 141 | + // (In contrast to blockInstNo, which is an instance counter over the instances of all blocks) |
|
| 142 | + // parentInstLevel // instance level of parent block |
|
| 143 | + // nextBlockInstNo // pointer to next instance of this block or -1 |
|
| 144 | + // Forward chain for instances of same block. |
|
| 145 | + // blockVarTab // block instance variables |
|
| 146 | 146 | var $blockInstTabCnt; // no of entries used in BlockInstTab |
| 147 | 147 | |
| 148 | 148 | var $currentNestingLevel; // Current block nesting level during parsing. |
@@ -173,8 +173,8 @@ discard block |
||
| 173 | 173 | */ |
| 174 | 174 | function readTemplateFromFile ($fileName) {
|
| 175 | 175 | if (!$this->readFileIntoString($fileName,$s)) {
|
| 176 | - $this->triggerError ("Error while reading template file " . $fileName . ".");
|
|
| 177 | - return false; } |
|
| 176 | + $this->triggerError ("Error while reading template file " . $fileName . ".");
|
|
| 177 | + return false; } |
|
| 178 | 178 | if (!$this->setTemplateString($s)) return false; |
| 179 | 179 | return true; } |
| 180 | 180 | |
@@ -200,8 +200,8 @@ discard block |
||
| 200 | 200 | function loadSubtemplate ($subtemplateName, &$s) {
|
| 201 | 201 | $subtemplateFileName = $this->combineFileSystemPath($this->subtemplateBasePath,$subtemplateName); |
| 202 | 202 | if (!$this->readFileIntoString($subtemplateFileName,$s)) {
|
| 203 | - $this->triggerError ("Error while reading subtemplate file " . $subtemplateFileName . ".");
|
|
| 204 | - return false; } |
|
| 203 | + $this->triggerError ("Error while reading subtemplate file " . $subtemplateFileName . ".");
|
|
| 204 | + return false; } |
|
| 205 | 205 | return true; } |
| 206 | 206 | |
| 207 | 207 | //--- template parsing ---------------------------------------------------------------------------------------------- |
@@ -271,17 +271,17 @@ discard block |
||
| 271 | 271 | function parseTemplateCommands() {
|
| 272 | 272 | $p = 0; |
| 273 | 273 | while (true) {
|
| 274 | - $p0 = strpos($this->template,'<!--',$p); |
|
| 275 | - if ($p0 === false) break; |
|
| 276 | - $p = strpos($this->template,'-->',$p0); |
|
| 277 | - if ($p === false) {
|
|
| 278 | - $this->triggerError ("Invalid HTML comment in template at offset $p0.");
|
|
| 279 | - return false; } |
|
| 280 | - $p += 3; |
|
| 281 | - $cmdL = substr($this->template,$p0+4,$p-$p0-7); |
|
| 282 | - if (!$this->processTemplateCommand($cmdL,$p0,$p,$resumeFromStart)) |
|
| 283 | - return false; |
|
| 284 | - if ($resumeFromStart) $p = $p0; } |
|
| 274 | + $p0 = strpos($this->template,'<!--',$p); |
|
| 275 | + if ($p0 === false) break; |
|
| 276 | + $p = strpos($this->template,'-->',$p0); |
|
| 277 | + if ($p === false) {
|
|
| 278 | + $this->triggerError ("Invalid HTML comment in template at offset $p0.");
|
|
| 279 | + return false; } |
|
| 280 | + $p += 3; |
|
| 281 | + $cmdL = substr($this->template,$p0+4,$p-$p0-7); |
|
| 282 | + if (!$this->processTemplateCommand($cmdL,$p0,$p,$resumeFromStart)) |
|
| 283 | + return false; |
|
| 284 | + if ($resumeFromStart) $p = $p0; } |
|
| 285 | 285 | return true; } |
| 286 | 286 | |
| 287 | 287 | /** |
@@ -295,24 +295,24 @@ discard block |
||
| 295 | 295 | if (!$this->parseWord($cmdL,$p,$cmd)) return true; |
| 296 | 296 | $parms = substr($cmdL,$p); |
| 297 | 297 | switch (strtoupper($cmd)) {
|
| 298 | - case '$BEGINBLOCK': |
|
| 299 | - if (!$this->processBeginBlockCmd($parms,$cmdTPosBegin,$cmdTPosEnd)) |
|
| 300 | - return false; |
|
| 301 | - break; |
|
| 302 | - case '$ENDBLOCK': |
|
| 303 | - if (!$this->processEndBlockCmd($parms,$cmdTPosBegin,$cmdTPosEnd)) |
|
| 304 | - return false; |
|
| 305 | - break; |
|
| 306 | - case '$INCLUDE': |
|
| 307 | - if (!$this->processincludeCmd($parms,$cmdTPosBegin,$cmdTPosEnd)) |
|
| 308 | - return false; |
|
| 309 | - $resumeFromStart = true; |
|
| 310 | - break; |
|
| 311 | - default: |
|
| 312 | - if ($cmd{0} == '$' && !(strlen($cmd) >= 2 && $cmd{1} == '{')) {
|
|
| 313 | - $this->triggerError ("Unknown command \"$cmd\" in template at offset $cmdTPosBegin.");
|
|
| 314 | - return false; }} |
|
| 315 | - return true; } |
|
| 298 | + case '$BEGINBLOCK': |
|
| 299 | + if (!$this->processBeginBlockCmd($parms,$cmdTPosBegin,$cmdTPosEnd)) |
|
| 300 | + return false; |
|
| 301 | + break; |
|
| 302 | + case '$ENDBLOCK': |
|
| 303 | + if (!$this->processEndBlockCmd($parms,$cmdTPosBegin,$cmdTPosEnd)) |
|
| 304 | + return false; |
|
| 305 | + break; |
|
| 306 | + case '$INCLUDE': |
|
| 307 | + if (!$this->processincludeCmd($parms,$cmdTPosBegin,$cmdTPosEnd)) |
|
| 308 | + return false; |
|
| 309 | + $resumeFromStart = true; |
|
| 310 | + break; |
|
| 311 | + default: |
|
| 312 | + if ($cmd{0} == '$' && !(strlen($cmd) >= 2 && $cmd{1} == '{')) {
|
|
| 313 | + $this->triggerError ("Unknown command \"$cmd\" in template at offset $cmdTPosBegin.");
|
|
| 314 | + return false; }} |
|
| 315 | + return true; } |
|
| 316 | 316 | |
| 317 | 317 | /** |
| 318 | 318 | * Processes the $BeginBlock command. |
@@ -322,11 +322,11 @@ discard block |
||
| 322 | 322 | function processBeginBlockCmd ($parms, $cmdTPosBegin, $cmdTPosEnd) {
|
| 323 | 323 | $p = 0; |
| 324 | 324 | if (!$this->parseWord($parms,$p,$blockName)) {
|
| 325 | - $this->triggerError ("Missing block name in \$BeginBlock command in template at offset $cmdTPosBegin.");
|
|
| 326 | - return false; } |
|
| 325 | + $this->triggerError ("Missing block name in \$BeginBlock command in template at offset $cmdTPosBegin.");
|
|
| 326 | + return false; } |
|
| 327 | 327 | if (trim(substr($parms,$p)) != '') {
|
| 328 | - $this->triggerError ("Extra parameter in \$BeginBlock command in template at offset $cmdTPosBegin.");
|
|
| 329 | - return false; } |
|
| 328 | + $this->triggerError ("Extra parameter in \$BeginBlock command in template at offset $cmdTPosBegin.");
|
|
| 329 | + return false; } |
|
| 330 | 330 | $this->registerBlock ($blockName, $blockNo); |
| 331 | 331 | $btr =& $this->blockTab[$blockNo]; |
| 332 | 332 | $btr['tPosBegin'] = $cmdTPosBegin; |
@@ -336,8 +336,8 @@ discard block |
||
| 336 | 336 | $this->openBlocksTab[$this->currentNestingLevel] = $blockNo; |
| 337 | 337 | $this->currentNestingLevel += 1; |
| 338 | 338 | if ($this->currentNestingLevel > $this->maxNestingLevel) {
|
| 339 | - $this->triggerError ("Block nesting overflow in template at offset $cmdTPosBegin.");
|
|
| 340 | - return false; } |
|
| 339 | + $this->triggerError ("Block nesting overflow in template at offset $cmdTPosBegin.");
|
|
| 340 | + return false; } |
|
| 341 | 341 | return true; } |
| 342 | 342 | |
| 343 | 343 | /** |
@@ -348,22 +348,22 @@ discard block |
||
| 348 | 348 | function processEndBlockCmd ($parms, $cmdTPosBegin, $cmdTPosEnd) {
|
| 349 | 349 | $p = 0; |
| 350 | 350 | if (!$this->parseWord($parms,$p,$blockName)) {
|
| 351 | - $this->triggerError ("Missing block name in \$EndBlock command in template at offset $cmdTPosBegin.");
|
|
| 352 | - return false; } |
|
| 351 | + $this->triggerError ("Missing block name in \$EndBlock command in template at offset $cmdTPosBegin.");
|
|
| 352 | + return false; } |
|
| 353 | 353 | if (trim(substr($parms,$p)) != '') {
|
| 354 | - $this->triggerError ("Extra parameter in \$EndBlock command in template at offset $cmdTPosBegin.");
|
|
| 355 | - return false; } |
|
| 354 | + $this->triggerError ("Extra parameter in \$EndBlock command in template at offset $cmdTPosBegin.");
|
|
| 355 | + return false; } |
|
| 356 | 356 | if (!$this->lookupBlockName($blockName,$blockNo)) {
|
| 357 | - $this->triggerError ("Undefined block name \"$blockName\" in \$EndBlock command in template at offset $cmdTPosBegin.");
|
|
| 358 | - return false; } |
|
| 357 | + $this->triggerError ("Undefined block name \"$blockName\" in \$EndBlock command in template at offset $cmdTPosBegin.");
|
|
| 358 | + return false; } |
|
| 359 | 359 | $this->currentNestingLevel -= 1; |
| 360 | 360 | $btr =& $this->blockTab[$blockNo]; |
| 361 | 361 | if (!$btr['definitionIsOpen']) {
|
| 362 | - $this->triggerError ("Multiple \$EndBlock command for block \"$blockName\" in template at offset $cmdTPosBegin.");
|
|
| 363 | - return false; } |
|
| 362 | + $this->triggerError ("Multiple \$EndBlock command for block \"$blockName\" in template at offset $cmdTPosBegin.");
|
|
| 363 | + return false; } |
|
| 364 | 364 | if ($btr['nestingLevel'] != $this->currentNestingLevel) {
|
| 365 | - $this->triggerError ("Block nesting level mismatch at \$EndBlock command for block \"$blockName\" in template at offset $cmdTPosBegin.");
|
|
| 366 | - return false; } |
|
| 365 | + $this->triggerError ("Block nesting level mismatch at \$EndBlock command for block \"$blockName\" in template at offset $cmdTPosBegin.");
|
|
| 366 | + return false; } |
|
| 367 | 367 | $btr['tPosContentsEnd'] = $cmdTPosBegin; |
| 368 | 368 | $btr['tPosEnd'] = $cmdTPosEnd; |
| 369 | 369 | $btr['definitionIsOpen'] = false; |
@@ -378,7 +378,7 @@ discard block |
||
| 378 | 378 | $btr = array(); |
| 379 | 379 | $btr['blockName'] = $blockName; |
| 380 | 380 | if (!$this->lookupBlockName($blockName,$btr['nextWithSameName'])) |
| 381 | - $btr['nextWithSameName'] = -1; |
|
| 381 | + $btr['nextWithSameName'] = -1; |
|
| 382 | 382 | $btr['definitionIsOpen'] = true; |
| 383 | 383 | $btr['instances'] = 0; |
| 384 | 384 | $btr['firstBlockInstNo'] = -1; |
@@ -395,13 +395,13 @@ discard block |
||
| 395 | 395 | */ |
| 396 | 396 | function checkBlockDefinitionsComplete() {
|
| 397 | 397 | for ($blockNo=0; $blockNo < $this->blockTabCnt; $blockNo++) {
|
| 398 | - $btr =& $this->blockTab[$blockNo]; |
|
| 399 | - if ($btr['definitionIsOpen']) {
|
|
| 400 | - $this->triggerError ("Missing \$EndBlock command in template for block " . $btr['blockName'] . ".");
|
|
| 401 | - return false; }} |
|
| 398 | + $btr =& $this->blockTab[$blockNo]; |
|
| 399 | + if ($btr['definitionIsOpen']) {
|
|
| 400 | + $this->triggerError ("Missing \$EndBlock command in template for block " . $btr['blockName'] . ".");
|
|
| 401 | + return false; }} |
|
| 402 | 402 | if ($this->currentNestingLevel != 0) {
|
| 403 | - $this->triggerError ("Block nesting level error at end of template.");
|
|
| 404 | - return false; } |
|
| 403 | + $this->triggerError ("Block nesting level error at end of template.");
|
|
| 404 | + return false; } |
|
| 405 | 405 | return true; } |
| 406 | 406 | |
| 407 | 407 | /** |
@@ -412,11 +412,11 @@ discard block |
||
| 412 | 412 | function processIncludeCmd ($parms, $cmdTPosBegin, $cmdTPosEnd) {
|
| 413 | 413 | $p = 0; |
| 414 | 414 | if (!$this->parseWordOrQuotedString($parms,$p,$subtemplateName)) {
|
| 415 | - $this->triggerError ("Missing or invalid subtemplate name in \$Include command in template at offset $cmdTPosBegin.");
|
|
| 416 | - return false; } |
|
| 415 | + $this->triggerError ("Missing or invalid subtemplate name in \$Include command in template at offset $cmdTPosBegin.");
|
|
| 416 | + return false; } |
|
| 417 | 417 | if (trim(substr($parms,$p)) != '') {
|
| 418 | - $this->triggerError ("Extra parameter in \$include command in template at offset $cmdTPosBegin.");
|
|
| 419 | - return false; } |
|
| 418 | + $this->triggerError ("Extra parameter in \$include command in template at offset $cmdTPosBegin.");
|
|
| 419 | + return false; } |
|
| 420 | 420 | return $this->insertSubtemplate($subtemplateName,$cmdTPosBegin,$cmdTPosEnd); } |
| 421 | 421 | |
| 422 | 422 | /** |
@@ -426,8 +426,8 @@ discard block |
||
| 426 | 426 | */ |
| 427 | 427 | function insertSubtemplate ($subtemplateName, $tPos1, $tPos2) {
|
| 428 | 428 | if (strlen($this->template) > $this->maxInclTemplateSize) {
|
| 429 | - $this->triggerError ("Subtemplate include aborted because the internal template string is longer than $this->maxInclTemplateSize characters.");
|
|
| 430 | - return false; } |
|
| 429 | + $this->triggerError ("Subtemplate include aborted because the internal template string is longer than $this->maxInclTemplateSize characters.");
|
|
| 430 | + return false; } |
|
| 431 | 431 | if (!$this->loadSubtemplate($subtemplateName,$subtemplate)) return false; |
| 432 | 432 | // (Copying the template to insert a subtemplate is a bit slow. In a future implementation of MiniTemplator, |
| 433 | 433 | // a table could be used that contains references to the string fragments.) |
@@ -442,19 +442,19 @@ discard block |
||
| 442 | 442 | function parseTemplateVariables() {
|
| 443 | 443 | $p = 0; |
| 444 | 444 | while (true) {
|
| 445 | - $p = strpos($this->template, '${', $p);
|
|
| 446 | - if ($p === false) break; |
|
| 447 | - $p0 = $p; |
|
| 448 | - $p = strpos($this->template, '}', $p); |
|
| 449 | - if ($p === false) {
|
|
| 450 | - $this->triggerError ("Invalid variable reference in template at offset $p0.");
|
|
| 451 | - return false; } |
|
| 452 | - $p += 1; |
|
| 453 | - $varName = trim(substr($this->template, $p0+2, $p-$p0-3)); |
|
| 454 | - if (strlen($varName) == 0) {
|
|
| 455 | - $this->triggerError ("Empty variable name in template at offset $p0.");
|
|
| 456 | - return false; } |
|
| 457 | - $this->registerVariableReference ($varName, $p0, $p); } |
|
| 445 | + $p = strpos($this->template, '${', $p);
|
|
| 446 | + if ($p === false) break; |
|
| 447 | + $p0 = $p; |
|
| 448 | + $p = strpos($this->template, '}', $p); |
|
| 449 | + if ($p === false) {
|
|
| 450 | + $this->triggerError ("Invalid variable reference in template at offset $p0.");
|
|
| 451 | + return false; } |
|
| 452 | + $p += 1; |
|
| 453 | + $varName = trim(substr($this->template, $p0+2, $p-$p0-3)); |
|
| 454 | + if (strlen($varName) == 0) {
|
|
| 455 | + $this->triggerError ("Empty variable name in template at offset $p0.");
|
|
| 456 | + return false; } |
|
| 457 | + $this->registerVariableReference ($varName, $p0, $p); } |
|
| 458 | 458 | return true; } |
| 459 | 459 | |
| 460 | 460 | /** |
@@ -462,7 +462,7 @@ discard block |
||
| 462 | 462 | */ |
| 463 | 463 | function registerVariableReference ($varName, $tPosBegin, $tPosEnd) {
|
| 464 | 464 | if (!$this->lookupVariableName($varName,$varNo)) |
| 465 | - $this->registerVariable($varName,$varNo); |
|
| 465 | + $this->registerVariable($varName,$varNo); |
|
| 466 | 466 | $varRefNo = $this->varRefTabCnt++; |
| 467 | 467 | $vrtr =& $this->varRefTab[$varRefNo]; |
| 468 | 468 | $vrtr = array(); |
@@ -490,27 +490,27 @@ discard block |
||
| 490 | 490 | $activeBlockNo = 0; |
| 491 | 491 | $nextBlockNo = 1; |
| 492 | 492 | while ($varRefNo < $this->varRefTabCnt) {
|
| 493 | - $vrtr =& $this->varRefTab[$varRefNo]; |
|
| 494 | - $varRefTPos = $vrtr['tPosBegin']; |
|
| 495 | - $varNo = $vrtr['varNo']; |
|
| 496 | - if ($varRefTPos >= $this->blockTab[$activeBlockNo]['tPosEnd']) {
|
|
| 497 | - $activeBlockNo = $this->blockTab[$activeBlockNo]['parentBlockNo']; |
|
| 498 | - continue; } |
|
| 499 | - if ($nextBlockNo < $this->blockTabCnt) {
|
|
| 500 | - if ($varRefTPos >= $this->blockTab[$nextBlockNo]['tPosBegin']) {
|
|
| 501 | - $activeBlockNo = $nextBlockNo; |
|
| 502 | - $nextBlockNo += 1; |
|
| 503 | - continue; }} |
|
| 504 | - $btr =& $this->blockTab[$activeBlockNo]; |
|
| 505 | - if ($varRefTPos < $btr['tPosBegin']) |
|
| 506 | - $this->programLogicError(1); |
|
| 507 | - $blockVarNo = $btr['blockVarCnt']++; |
|
| 508 | - $btr['blockVarNoToVarNoMap'][$blockVarNo] = $varNo; |
|
| 509 | - if ($btr['firstVarRefNo'] == -1) |
|
| 510 | - $btr['firstVarRefNo'] = $varRefNo; |
|
| 511 | - $vrtr['blockNo'] = $activeBlockNo; |
|
| 512 | - $vrtr['blockVarNo'] = $blockVarNo; |
|
| 513 | - $varRefNo += 1; }} |
|
| 493 | + $vrtr =& $this->varRefTab[$varRefNo]; |
|
| 494 | + $varRefTPos = $vrtr['tPosBegin']; |
|
| 495 | + $varNo = $vrtr['varNo']; |
|
| 496 | + if ($varRefTPos >= $this->blockTab[$activeBlockNo]['tPosEnd']) {
|
|
| 497 | + $activeBlockNo = $this->blockTab[$activeBlockNo]['parentBlockNo']; |
|
| 498 | + continue; } |
|
| 499 | + if ($nextBlockNo < $this->blockTabCnt) {
|
|
| 500 | + if ($varRefTPos >= $this->blockTab[$nextBlockNo]['tPosBegin']) {
|
|
| 501 | + $activeBlockNo = $nextBlockNo; |
|
| 502 | + $nextBlockNo += 1; |
|
| 503 | + continue; }} |
|
| 504 | + $btr =& $this->blockTab[$activeBlockNo]; |
|
| 505 | + if ($varRefTPos < $btr['tPosBegin']) |
|
| 506 | + $this->programLogicError(1); |
|
| 507 | + $blockVarNo = $btr['blockVarCnt']++; |
|
| 508 | + $btr['blockVarNoToVarNoMap'][$blockVarNo] = $varNo; |
|
| 509 | + if ($btr['firstVarRefNo'] == -1) |
|
| 510 | + $btr['firstVarRefNo'] = $varRefNo; |
|
| 511 | + $vrtr['blockNo'] = $activeBlockNo; |
|
| 512 | + $vrtr['blockVarNo'] = $blockVarNo; |
|
| 513 | + $varRefNo += 1; }} |
|
| 514 | 514 | |
| 515 | 515 | //--- build up (template variables and blocks) ---------------------------------------------------------------------- |
| 516 | 516 | |
@@ -524,12 +524,12 @@ discard block |
||
| 524 | 524 | */ |
| 525 | 525 | function reset() {
|
| 526 | 526 | for ($varNo=0; $varNo<$this->varTabCnt; $varNo++) |
| 527 | - $this->varTab[$varNo]['varValue'] = ''; |
|
| 527 | + $this->varTab[$varNo]['varValue'] = ''; |
|
| 528 | 528 | for ($blockNo=0; $blockNo<$this->blockTabCnt; $blockNo++) {
|
| 529 | - $btr =& $this->blockTab[$blockNo]; |
|
| 530 | - $btr['instances'] = 0; |
|
| 531 | - $btr['firstBlockInstNo'] = -1; |
|
| 532 | - $btr['lastBlockInstNo'] = -1; } |
|
| 529 | + $btr =& $this->blockTab[$blockNo]; |
|
| 530 | + $btr['instances'] = 0; |
|
| 531 | + $btr['firstBlockInstNo'] = -1; |
|
| 532 | + $btr['lastBlockInstNo'] = -1; } |
|
| 533 | 533 | $this->blockInstTab = array(); |
| 534 | 534 | $this->blockInstTabCnt = 0; } |
| 535 | 535 | |
@@ -551,9 +551,9 @@ discard block |
||
| 551 | 551 | function setVariable ($variableName, $variableValue, $isOptional=false) {
|
| 552 | 552 | if (!$this->templateValid) {$this->triggerError ("Template not valid."); return false; }
|
| 553 | 553 | if (!$this->lookupVariableName($variableName,$varNo)) {
|
| 554 | - if ($isOptional) return true; |
|
| 555 | - $this->triggerError ("Variable \"$variableName\" not defined in template.");
|
|
| 556 | - return false; } |
|
| 554 | + if ($isOptional) return true; |
|
| 555 | + $this->triggerError ("Variable \"$variableName\" not defined in template.");
|
|
| 556 | + return false; } |
|
| 557 | 557 | $this->varTab[$varNo]['varValue'] = $variableValue; |
| 558 | 558 | return true; } |
| 559 | 559 | |
@@ -605,11 +605,11 @@ discard block |
||
| 605 | 605 | function addBlock($blockName) {
|
| 606 | 606 | if (!$this->templateValid) {$this->triggerError ("Template not valid."); return false; }
|
| 607 | 607 | if (!$this->lookupBlockName($blockName,$blockNo)) {
|
| 608 | - $this->triggerError ("Block \"$blockName\" not defined in template.");
|
|
| 609 | - return false; } |
|
| 608 | + $this->triggerError ("Block \"$blockName\" not defined in template.");
|
|
| 609 | + return false; } |
|
| 610 | 610 | while ($blockNo != -1) {
|
| 611 | - $this->addBlockByNo($blockNo); |
|
| 612 | - $blockNo = $this->blockTab[$blockNo]['nextWithSameName']; } |
|
| 611 | + $this->addBlockByNo($blockNo); |
|
| 612 | + $blockNo = $this->blockTab[$blockNo]['nextWithSameName']; } |
|
| 613 | 613 | return true; } |
| 614 | 614 | |
| 615 | 615 | /** |
@@ -620,25 +620,25 @@ discard block |
||
| 620 | 620 | $this->registerBlockInstance ($blockInstNo); |
| 621 | 621 | $bitr =& $this->blockInstTab[$blockInstNo]; |
| 622 | 622 | if ($btr['firstBlockInstNo'] == -1) |
| 623 | - $btr['firstBlockInstNo'] = $blockInstNo; |
|
| 623 | + $btr['firstBlockInstNo'] = $blockInstNo; |
|
| 624 | 624 | if ($btr['lastBlockInstNo'] != -1) |
| 625 | - $this->blockInstTab[$btr['lastBlockInstNo']]['nextBlockInstNo'] = $blockInstNo; |
|
| 626 | - // set forward pointer of chain |
|
| 625 | + $this->blockInstTab[$btr['lastBlockInstNo']]['nextBlockInstNo'] = $blockInstNo; |
|
| 626 | + // set forward pointer of chain |
|
| 627 | 627 | $btr['lastBlockInstNo'] = $blockInstNo; |
| 628 | 628 | $parentBlockNo = $btr['parentBlockNo']; |
| 629 | 629 | $blockVarCnt = $btr['blockVarCnt']; |
| 630 | 630 | $bitr['blockNo'] = $blockNo; |
| 631 | 631 | $bitr['instanceLevel'] = $btr['instances']++; |
| 632 | 632 | if ($parentBlockNo == -1) |
| 633 | - $bitr['parentInstLevel'] = -1; |
|
| 634 | - else |
|
| 635 | - $bitr['parentInstLevel'] = $this->blockTab[$parentBlockNo]['instances']; |
|
| 633 | + $bitr['parentInstLevel'] = -1; |
|
| 634 | + else |
|
| 635 | + $bitr['parentInstLevel'] = $this->blockTab[$parentBlockNo]['instances']; |
|
| 636 | 636 | $bitr['nextBlockInstNo'] = -1; |
| 637 | 637 | $bitr['blockVarTab'] = array(); |
| 638 | 638 | // copy instance variables for this block |
| 639 | 639 | for ($blockVarNo=0; $blockVarNo<$blockVarCnt; $blockVarNo++) {
|
| 640 | - $varNo = $btr['blockVarNoToVarNoMap'][$blockVarNo]; |
|
| 641 | - $bitr['blockVarTab'][$blockVarNo] = $this->varTab[$varNo]['varValue']; }} |
|
| 640 | + $varNo = $btr['blockVarNoToVarNoMap'][$blockVarNo]; |
|
| 641 | + $bitr['blockVarTab'][$blockVarNo] = $this->varTab[$varNo]['varValue']; }} |
|
| 642 | 642 | |
| 643 | 643 | /** |
| 644 | 644 | * @access private |
@@ -706,10 +706,10 @@ discard block |
||
| 706 | 706 | function generateOutputPage() {
|
| 707 | 707 | if (!$this->templateValid) {$this->triggerError ("Template not valid."); return false; }
|
| 708 | 708 | if ($this->blockTab[0]['instances'] == 0) |
| 709 | - $this->addBlockByNo (0); // add main block |
|
| 709 | + $this->addBlockByNo (0); // add main block |
|
| 710 | 710 | for ($blockNo=0; $blockNo < $this->blockTabCnt; $blockNo++) {
|
| 711 | - $btr =& $this->blockTab[$blockNo]; |
|
| 712 | - $btr['currBlockInstNo'] = $btr['firstBlockInstNo']; } |
|
| 711 | + $btr =& $this->blockTab[$blockNo]; |
|
| 712 | + $btr['currBlockInstNo'] = $btr['firstBlockInstNo']; } |
|
| 713 | 713 | $this->outputError = false; |
| 714 | 714 | $this->writeBlockInstances (0, -1); |
| 715 | 715 | if ($this->outputError) return false; |
@@ -724,14 +724,14 @@ discard block |
||
| 724 | 724 | function writeBlockInstances ($blockNo, $parentInstLevel) {
|
| 725 | 725 | $btr =& $this->blockTab[$blockNo]; |
| 726 | 726 | while (!$this->outputError) {
|
| 727 | - $blockInstNo = $btr['currBlockInstNo']; |
|
| 728 | - if ($blockInstNo == -1) break; |
|
| 729 | - $bitr =& $this->blockInstTab[$blockInstNo]; |
|
| 730 | - if ($bitr['parentInstLevel'] < $parentInstLevel) |
|
| 731 | - $this->programLogicError (2); |
|
| 732 | - if ($bitr['parentInstLevel'] > $parentInstLevel) break; |
|
| 733 | - $this->writeBlockInstance ($blockInstNo); |
|
| 734 | - $btr['currBlockInstNo'] = $bitr['nextBlockInstNo']; }} |
|
| 727 | + $blockInstNo = $btr['currBlockInstNo']; |
|
| 728 | + if ($blockInstNo == -1) break; |
|
| 729 | + $bitr =& $this->blockInstTab[$blockInstNo]; |
|
| 730 | + if ($bitr['parentInstLevel'] < $parentInstLevel) |
|
| 731 | + $this->programLogicError (2); |
|
| 732 | + if ($bitr['parentInstLevel'] > $parentInstLevel) break; |
|
| 733 | + $this->writeBlockInstance ($blockInstNo); |
|
| 734 | + $btr['currBlockInstNo'] = $bitr['nextBlockInstNo']; }} |
|
| 735 | 735 | |
| 736 | 736 | /** |
| 737 | 737 | * @access private |
@@ -744,46 +744,46 @@ discard block |
||
| 744 | 744 | $subBlockNo = $blockNo + 1; |
| 745 | 745 | $varRefNo = $btr['firstVarRefNo']; |
| 746 | 746 | while (!$this->outputError) {
|
| 747 | - $tPos2 = $btr['tPosContentsEnd']; |
|
| 748 | - $kind = 0; // assume end-of-block |
|
| 749 | - if ($varRefNo != -1 && $varRefNo < $this->varRefTabCnt) { // check for variable reference
|
|
| 750 | - $vrtr =& $this->varRefTab[$varRefNo]; |
|
| 751 | - if ($vrtr['tPosBegin'] < $tPos) {
|
|
| 752 | - $varRefNo += 1; |
|
| 753 | - continue; } |
|
| 754 | - if ($vrtr['tPosBegin'] < $tPos2) {
|
|
| 755 | - $tPos2 = $vrtr['tPosBegin']; |
|
| 756 | - $kind = 1; }} |
|
| 757 | - if ($subBlockNo < $this->blockTabCnt) { // check for subblock
|
|
| 758 | - $subBtr =& $this->blockTab[$subBlockNo]; |
|
| 759 | - if ($subBtr['tPosBegin'] < $tPos) {
|
|
| 760 | - $subBlockNo += 1; |
|
| 761 | - continue; } |
|
| 762 | - if ($subBtr['tPosBegin'] < $tPos2) {
|
|
| 763 | - $tPos2 = $subBtr['tPosBegin']; |
|
| 764 | - $kind = 2; }} |
|
| 765 | - if ($tPos2 > $tPos) |
|
| 766 | - $this->writeString (substr($this->template,$tPos,$tPos2-$tPos)); |
|
| 767 | - switch ($kind) {
|
|
| 768 | - case 0: // end of block |
|
| 769 | - return; |
|
| 770 | - case 1: // variable |
|
| 771 | - $vrtr =& $this->varRefTab[$varRefNo]; |
|
| 772 | - if ($vrtr['blockNo'] != $blockNo) |
|
| 773 | - $this->programLogicError (4); |
|
| 774 | - $variableValue = $bitr['blockVarTab'][$vrtr['blockVarNo']]; |
|
| 775 | - $this->writeString ($variableValue); |
|
| 776 | - $tPos = $vrtr['tPosEnd']; |
|
| 777 | - $varRefNo += 1; |
|
| 778 | - break; |
|
| 779 | - case 2: // sub block |
|
| 780 | - $subBtr =& $this->blockTab[$subBlockNo]; |
|
| 781 | - if ($subBtr['parentBlockNo'] != $blockNo) |
|
| 782 | - $this->programLogicError (3); |
|
| 783 | - $this->writeBlockInstances ($subBlockNo, $bitr['instanceLevel']); // recursive call |
|
| 784 | - $tPos = $subBtr['tPosEnd']; |
|
| 785 | - $subBlockNo += 1; |
|
| 786 | - break; }}} |
|
| 747 | + $tPos2 = $btr['tPosContentsEnd']; |
|
| 748 | + $kind = 0; // assume end-of-block |
|
| 749 | + if ($varRefNo != -1 && $varRefNo < $this->varRefTabCnt) { // check for variable reference
|
|
| 750 | + $vrtr =& $this->varRefTab[$varRefNo]; |
|
| 751 | + if ($vrtr['tPosBegin'] < $tPos) {
|
|
| 752 | + $varRefNo += 1; |
|
| 753 | + continue; } |
|
| 754 | + if ($vrtr['tPosBegin'] < $tPos2) {
|
|
| 755 | + $tPos2 = $vrtr['tPosBegin']; |
|
| 756 | + $kind = 1; }} |
|
| 757 | + if ($subBlockNo < $this->blockTabCnt) { // check for subblock
|
|
| 758 | + $subBtr =& $this->blockTab[$subBlockNo]; |
|
| 759 | + if ($subBtr['tPosBegin'] < $tPos) {
|
|
| 760 | + $subBlockNo += 1; |
|
| 761 | + continue; } |
|
| 762 | + if ($subBtr['tPosBegin'] < $tPos2) {
|
|
| 763 | + $tPos2 = $subBtr['tPosBegin']; |
|
| 764 | + $kind = 2; }} |
|
| 765 | + if ($tPos2 > $tPos) |
|
| 766 | + $this->writeString (substr($this->template,$tPos,$tPos2-$tPos)); |
|
| 767 | + switch ($kind) {
|
|
| 768 | + case 0: // end of block |
|
| 769 | + return; |
|
| 770 | + case 1: // variable |
|
| 771 | + $vrtr =& $this->varRefTab[$varRefNo]; |
|
| 772 | + if ($vrtr['blockNo'] != $blockNo) |
|
| 773 | + $this->programLogicError (4); |
|
| 774 | + $variableValue = $bitr['blockVarTab'][$vrtr['blockVarNo']]; |
|
| 775 | + $this->writeString ($variableValue); |
|
| 776 | + $tPos = $vrtr['tPosEnd']; |
|
| 777 | + $varRefNo += 1; |
|
| 778 | + break; |
|
| 779 | + case 2: // sub block |
|
| 780 | + $subBtr =& $this->blockTab[$subBlockNo]; |
|
| 781 | + if ($subBtr['parentBlockNo'] != $blockNo) |
|
| 782 | + $this->programLogicError (3); |
|
| 783 | + $this->writeBlockInstances ($subBlockNo, $bitr['instanceLevel']); // recursive call |
|
| 784 | + $tPos = $subBtr['tPosEnd']; |
|
| 785 | + $subBlockNo += 1; |
|
| 786 | + break; }}} |
|
| 787 | 787 | |
| 788 | 788 | /** |
| 789 | 789 | * @access private |
@@ -791,17 +791,17 @@ discard block |
||
| 791 | 791 | function writeString ($s) {
|
| 792 | 792 | if ($this->outputError) return; |
| 793 | 793 | switch ($this->outputMode) {
|
| 794 | - case 0: // output to PHP output stream |
|
| 795 | - if (!print($s)) |
|
| 796 | - $this->outputError = true; |
|
| 797 | - break; |
|
| 798 | - case 1: // output to file |
|
| 799 | - $rc = fwrite($this->outputFileHandle, $s); |
|
| 800 | - if ($rc === false) $this->outputError = true; |
|
| 801 | - break; |
|
| 802 | - case 2: // output to string |
|
| 803 | - $this->outputString .= $s; |
|
| 804 | - break; }} |
|
| 794 | + case 0: // output to PHP output stream |
|
| 795 | + if (!print($s)) |
|
| 796 | + $this->outputError = true; |
|
| 797 | + break; |
|
| 798 | + case 1: // output to file |
|
| 799 | + $rc = fwrite($this->outputFileHandle, $s); |
|
| 800 | + if ($rc === false) $this->outputError = true; |
|
| 801 | + break; |
|
| 802 | + case 2: // output to string |
|
| 803 | + $this->outputString .= $s; |
|
| 804 | + break; }} |
|
| 805 | 805 | |
| 806 | 806 | //--- name lookup routines ------------------------------------------------------------------------------------------ |
| 807 | 807 | |
@@ -838,9 +838,9 @@ discard block |
||
| 838 | 838 | */ |
| 839 | 839 | function readFileIntoString ($fileName, &$s) {
|
| 840 | 840 | if (function_exists('version_compare') && version_compare(phpversion(),"4.3.0",">=")) {
|
| 841 | - $s = file_get_contents($fileName); |
|
| 842 | - if ($s === false) return false; |
|
| 843 | - return true; } |
|
| 841 | + $s = file_get_contents($fileName); |
|
| 842 | + if ($s === false) return false; |
|
| 843 | + return true; } |
|
| 844 | 844 | $fh = fopen($fileName,"rb"); |
| 845 | 845 | if ($fh === false) return false; |
| 846 | 846 | $fileSize = filesize($fileName); |
@@ -888,9 +888,9 @@ discard block |
||
| 888 | 888 | while ($p < $sLen && ord($s{$p}) <= 32) $p++;
|
| 889 | 889 | if ($p >= $sLen) return false; |
| 890 | 890 | if (substr($s,$p,1) == '"') |
| 891 | - return $this->parseQuotedString($s,$p,$w); |
|
| 892 | - else |
|
| 893 | - return $this->parseWord($s,$p,$w); } |
|
| 891 | + return $this->parseQuotedString($s,$p,$w); |
|
| 892 | + else |
|
| 893 | + return $this->parseWord($s,$p,$w); } |
|
| 894 | 894 | |
| 895 | 895 | /** |
| 896 | 896 | * Combine two file system paths. |
@@ -901,9 +901,9 @@ discard block |
||
| 901 | 901 | $s = $path1; |
| 902 | 902 | if (substr($s,-1) != '\\' && substr($s,-1) != '/') $s = $s . "/"; |
| 903 | 903 | if (substr($path2,0,1) == '\\' || substr($path2,0,1) == '/') |
| 904 | - $s = $s . substr($path2,1); |
|
| 905 | - else |
|
| 906 | - $s = $s . $path2; |
|
| 904 | + $s = $s . substr($path2,1); |
|
| 905 | + else |
|
| 906 | + $s = $s . $path2; |
|
| 907 | 907 | return $s; } |
| 908 | 908 | |
| 909 | 909 | /** |
@@ -295,23 +295,23 @@ discard block |
||
| 295 | 295 | if (!$this->parseWord($cmdL,$p,$cmd)) return true; |
| 296 | 296 | $parms = substr($cmdL,$p); |
| 297 | 297 | switch (strtoupper($cmd)) {
|
| 298 | - case '$BEGINBLOCK': |
|
| 299 | - if (!$this->processBeginBlockCmd($parms,$cmdTPosBegin,$cmdTPosEnd)) |
|
| 300 | - return false; |
|
| 301 | - break; |
|
| 302 | - case '$ENDBLOCK': |
|
| 303 | - if (!$this->processEndBlockCmd($parms,$cmdTPosBegin,$cmdTPosEnd)) |
|
| 304 | - return false; |
|
| 305 | - break; |
|
| 306 | - case '$INCLUDE': |
|
| 307 | - if (!$this->processincludeCmd($parms,$cmdTPosBegin,$cmdTPosEnd)) |
|
| 308 | - return false; |
|
| 309 | - $resumeFromStart = true; |
|
| 310 | - break; |
|
| 311 | - default: |
|
| 312 | - if ($cmd{0} == '$' && !(strlen($cmd) >= 2 && $cmd{1} == '{')) {
|
|
| 313 | - $this->triggerError ("Unknown command \"$cmd\" in template at offset $cmdTPosBegin.");
|
|
| 314 | - return false; }} |
|
| 298 | + case '$BEGINBLOCK': |
|
| 299 | + if (!$this->processBeginBlockCmd($parms,$cmdTPosBegin,$cmdTPosEnd)) |
|
| 300 | + return false; |
|
| 301 | + break; |
|
| 302 | + case '$ENDBLOCK': |
|
| 303 | + if (!$this->processEndBlockCmd($parms,$cmdTPosBegin,$cmdTPosEnd)) |
|
| 304 | + return false; |
|
| 305 | + break; |
|
| 306 | + case '$INCLUDE': |
|
| 307 | + if (!$this->processincludeCmd($parms,$cmdTPosBegin,$cmdTPosEnd)) |
|
| 308 | + return false; |
|
| 309 | + $resumeFromStart = true; |
|
| 310 | + break; |
|
| 311 | + default: |
|
| 312 | + if ($cmd{0} == '$' && !(strlen($cmd) >= 2 && $cmd{1} == '{')) {
|
|
| 313 | + $this->triggerError ("Unknown command \"$cmd\" in template at offset $cmdTPosBegin.");
|
|
| 314 | + return false; }} |
|
| 315 | 315 | return true; } |
| 316 | 316 | |
| 317 | 317 | /** |
@@ -765,25 +765,25 @@ discard block |
||
| 765 | 765 | if ($tPos2 > $tPos) |
| 766 | 766 | $this->writeString (substr($this->template,$tPos,$tPos2-$tPos)); |
| 767 | 767 | switch ($kind) {
|
| 768 | - case 0: // end of block |
|
| 769 | - return; |
|
| 770 | - case 1: // variable |
|
| 771 | - $vrtr =& $this->varRefTab[$varRefNo]; |
|
| 772 | - if ($vrtr['blockNo'] != $blockNo) |
|
| 773 | - $this->programLogicError (4); |
|
| 774 | - $variableValue = $bitr['blockVarTab'][$vrtr['blockVarNo']]; |
|
| 775 | - $this->writeString ($variableValue); |
|
| 776 | - $tPos = $vrtr['tPosEnd']; |
|
| 777 | - $varRefNo += 1; |
|
| 778 | - break; |
|
| 779 | - case 2: // sub block |
|
| 780 | - $subBtr =& $this->blockTab[$subBlockNo]; |
|
| 781 | - if ($subBtr['parentBlockNo'] != $blockNo) |
|
| 782 | - $this->programLogicError (3); |
|
| 783 | - $this->writeBlockInstances ($subBlockNo, $bitr['instanceLevel']); // recursive call |
|
| 784 | - $tPos = $subBtr['tPosEnd']; |
|
| 785 | - $subBlockNo += 1; |
|
| 786 | - break; }}} |
|
| 768 | + case 0: // end of block |
|
| 769 | + return; |
|
| 770 | + case 1: // variable |
|
| 771 | + $vrtr =& $this->varRefTab[$varRefNo]; |
|
| 772 | + if ($vrtr['blockNo'] != $blockNo) |
|
| 773 | + $this->programLogicError (4); |
|
| 774 | + $variableValue = $bitr['blockVarTab'][$vrtr['blockVarNo']]; |
|
| 775 | + $this->writeString ($variableValue); |
|
| 776 | + $tPos = $vrtr['tPosEnd']; |
|
| 777 | + $varRefNo += 1; |
|
| 778 | + break; |
|
| 779 | + case 2: // sub block |
|
| 780 | + $subBtr =& $this->blockTab[$subBlockNo]; |
|
| 781 | + if ($subBtr['parentBlockNo'] != $blockNo) |
|
| 782 | + $this->programLogicError (3); |
|
| 783 | + $this->writeBlockInstances ($subBlockNo, $bitr['instanceLevel']); // recursive call |
|
| 784 | + $tPos = $subBtr['tPosEnd']; |
|
| 785 | + $subBlockNo += 1; |
|
| 786 | + break; }}} |
|
| 787 | 787 | |
| 788 | 788 | /** |
| 789 | 789 | * @access private |
@@ -791,17 +791,17 @@ discard block |
||
| 791 | 791 | function writeString ($s) {
|
| 792 | 792 | if ($this->outputError) return; |
| 793 | 793 | switch ($this->outputMode) {
|
| 794 | - case 0: // output to PHP output stream |
|
| 795 | - if (!print($s)) |
|
| 796 | - $this->outputError = true; |
|
| 797 | - break; |
|
| 798 | - case 1: // output to file |
|
| 799 | - $rc = fwrite($this->outputFileHandle, $s); |
|
| 800 | - if ($rc === false) $this->outputError = true; |
|
| 801 | - break; |
|
| 802 | - case 2: // output to string |
|
| 803 | - $this->outputString .= $s; |
|
| 804 | - break; }} |
|
| 794 | + case 0: // output to PHP output stream |
|
| 795 | + if (!print($s)) |
|
| 796 | + $this->outputError = true; |
|
| 797 | + break; |
|
| 798 | + case 1: // output to file |
|
| 799 | + $rc = fwrite($this->outputFileHandle, $s); |
|
| 800 | + if ($rc === false) $this->outputError = true; |
|
| 801 | + break; |
|
| 802 | + case 2: // output to string |
|
| 803 | + $this->outputString .= $s; |
|
| 804 | + break; }} |
|
| 805 | 805 | |
| 806 | 806 | //--- name lookup routines ------------------------------------------------------------------------------------------ |
| 807 | 807 | |
@@ -89,16 +89,16 @@ discard block |
||
| 89 | 89 | * @access private |
| 90 | 90 | */ |
| 91 | 91 | |
| 92 | -var $maxNestingLevel = 50; // maximum number of block nestings |
|
| 93 | -var $maxInclTemplateSize = 1000000; // maximum length of template string when including subtemplates |
|
| 94 | -var $template; // Template file data |
|
| 95 | -var $varTab; // variables table, array index is variable no |
|
| 92 | +var $maxNestingLevel = 50; // maximum number of block nestings |
|
| 93 | +var $maxInclTemplateSize = 1000000; // maximum length of template string when including subtemplates |
|
| 94 | +var $template; // Template file data |
|
| 95 | +var $varTab; // variables table, array index is variable no |
|
| 96 | 96 | // Fields: |
| 97 | 97 | // varName // variable name |
| 98 | 98 | // varValue // variable value |
| 99 | -var $varTabCnt; // no of entries used in VarTab |
|
| 100 | -var $varNameToNoMap; // maps variable names to variable numbers |
|
| 101 | -var $varRefTab; // variable references table |
|
| 99 | +var $varTabCnt; // no of entries used in VarTab |
|
| 100 | +var $varNameToNoMap; // maps variable names to variable numbers |
|
| 101 | +var $varRefTab; // variable references table |
|
| 102 | 102 | // Contains an entry for each variable reference in the template. Ordered by TemplatePos. |
| 103 | 103 | // Fields: |
| 104 | 104 | // varNo // variable no |
@@ -106,8 +106,8 @@ discard block |
||
| 106 | 106 | // tPosEnd // template position of end of variable reference |
| 107 | 107 | // blockNo // block no of the (innermost) block that contains this variable reference |
| 108 | 108 | // blockVarNo // block variable no. Index into BlockInstTab.BlockVarTab |
| 109 | -var $varRefTabCnt; // no of entries used in VarRefTab |
|
| 110 | -var $blockTab; // Blocks table, array index is block no |
|
| 109 | +var $varRefTabCnt; // no of entries used in VarRefTab |
|
| 110 | +var $blockTab; // Blocks table, array index is block no |
|
| 111 | 111 | // Contains an entry for each block in the template. Ordered by TPosBegin. |
| 112 | 112 | // Fields: |
| 113 | 113 | // blockName // block name |
@@ -126,12 +126,12 @@ discard block |
||
| 126 | 126 | // blockVarCnt // no of variables in block |
| 127 | 127 | // blockVarNoToVarNoMap // maps block variable numbers to variable numbers |
| 128 | 128 | // firstVarRefNo // variable reference no of first variable of this block or -1 |
| 129 | -var $blockTabCnt; // no of entries used in BlockTab |
|
| 130 | -var $blockNameToNoMap; // maps block names to block numbers |
|
| 129 | +var $blockTabCnt; // no of entries used in BlockTab |
|
| 130 | +var $blockNameToNoMap; // maps block names to block numbers |
|
| 131 | 131 | var $openBlocksTab; |
| 132 | 132 | // During parsing, this table contains the block numbers of the open parent blocks (nested outer blocks). |
| 133 | 133 | // Indexed by the block nesting level. |
| 134 | -var $blockInstTab; // block instances table |
|
| 134 | +var $blockInstTab; // block instances table |
|
| 135 | 135 | // This table contains an entry for each block instance that has been added. |
| 136 | 136 | // Indexed by BlockInstNo. |
| 137 | 137 | // Fields: |
@@ -143,14 +143,14 @@ discard block |
||
| 143 | 143 | // nextBlockInstNo // pointer to next instance of this block or -1 |
| 144 | 144 | // Forward chain for instances of same block. |
| 145 | 145 | // blockVarTab // block instance variables |
| 146 | -var $blockInstTabCnt; // no of entries used in BlockInstTab |
|
| 146 | +var $blockInstTabCnt; // no of entries used in BlockInstTab |
|
| 147 | 147 | |
| 148 | -var $currentNestingLevel; // Current block nesting level during parsing. |
|
| 149 | -var $templateValid; // true if a valid template is prepared |
|
| 150 | -var $outputMode; // 0 = to PHP output stream, 1 = to file, 2 = to string |
|
| 151 | -var $outputFileHandle; // file handle during writing of output file |
|
| 152 | -var $outputError; // true when an output error occurred |
|
| 153 | -var $outputString; // string buffer for the generated HTML page |
|
| 148 | +var $currentNestingLevel; // Current block nesting level during parsing. |
|
| 149 | +var $templateValid; // true if a valid template is prepared |
|
| 150 | +var $outputMode; // 0 = to PHP output stream, 1 = to file, 2 = to string |
|
| 151 | +var $outputFileHandle; // file handle during writing of output file |
|
| 152 | +var $outputError; // true when an output error occurred |
|
| 153 | +var $outputString; // string buffer for the generated HTML page |
|
| 154 | 154 | |
| 155 | 155 | /**#@-*/ |
| 156 | 156 | |
@@ -171,9 +171,9 @@ discard block |
||
| 171 | 171 | * @return boolean true on success, false on error. |
| 172 | 172 | * @access public |
| 173 | 173 | */ |
| 174 | -function readTemplateFromFile ($fileName) {
|
|
| 175 | - if (!$this->readFileIntoString($fileName,$s)) {
|
|
| 176 | - $this->triggerError ("Error while reading template file " . $fileName . ".");
|
|
| 174 | +function readTemplateFromFile($fileName) {
|
|
| 175 | + if (!$this->readFileIntoString($fileName, $s)) {
|
|
| 176 | + $this->triggerError("Error while reading template file ".$fileName.".");
|
|
| 177 | 177 | return false; } |
| 178 | 178 | if (!$this->setTemplateString($s)) return false; |
| 179 | 179 | return true; } |
@@ -184,7 +184,7 @@ discard block |
||
| 184 | 184 | * @return boolean true on success, false on error. |
| 185 | 185 | * @access public |
| 186 | 186 | */ |
| 187 | -function setTemplateString ($templateString) {
|
|
| 187 | +function setTemplateString($templateString) {
|
|
| 188 | 188 | $this->templateValid = false; |
| 189 | 189 | $this->template = $templateString; |
| 190 | 190 | if (!$this->parseTemplate()) return false; |
@@ -197,10 +197,10 @@ discard block |
||
| 197 | 197 | * @return boolean true on success, false on error. |
| 198 | 198 | * @access private |
| 199 | 199 | */ |
| 200 | -function loadSubtemplate ($subtemplateName, &$s) {
|
|
| 201 | - $subtemplateFileName = $this->combineFileSystemPath($this->subtemplateBasePath,$subtemplateName); |
|
| 202 | - if (!$this->readFileIntoString($subtemplateFileName,$s)) {
|
|
| 203 | - $this->triggerError ("Error while reading subtemplate file " . $subtemplateFileName . ".");
|
|
| 200 | +function loadSubtemplate($subtemplateName, &$s) {
|
|
| 201 | + $subtemplateFileName = $this->combineFileSystemPath($this->subtemplateBasePath, $subtemplateName); |
|
| 202 | + if (!$this->readFileIntoString($subtemplateFileName, $s)) {
|
|
| 203 | + $this->triggerError("Error while reading subtemplate file ".$subtemplateFileName.".");
|
|
| 204 | 204 | return false; } |
| 205 | 205 | return true; } |
| 206 | 206 | |
@@ -243,7 +243,7 @@ discard block |
||
| 243 | 243 | function beginMainBlock() {
|
| 244 | 244 | $blockNo = 0; |
| 245 | 245 | $this->registerBlock('@@InternalMainBlock@@', $blockNo);
|
| 246 | - $bte =& $this->blockTab[$blockNo]; |
|
| 246 | + $bte = & $this->blockTab[$blockNo]; |
|
| 247 | 247 | $bte['tPosBegin'] = 0; |
| 248 | 248 | $bte['tPosContentsBegin'] = 0; |
| 249 | 249 | $bte['nestingLevel'] = 0; |
@@ -257,7 +257,7 @@ discard block |
||
| 257 | 257 | * @access private |
| 258 | 258 | */ |
| 259 | 259 | function endMainBlock() {
|
| 260 | - $bte =& $this->blockTab[0]; |
|
| 260 | + $bte = & $this->blockTab[0]; |
|
| 261 | 261 | $bte['tPosContentsEnd'] = strlen($this->template); |
| 262 | 262 | $bte['tPosEnd'] = strlen($this->template); |
| 263 | 263 | $bte['definitionIsOpen'] = false; |
@@ -271,15 +271,15 @@ discard block |
||
| 271 | 271 | function parseTemplateCommands() {
|
| 272 | 272 | $p = 0; |
| 273 | 273 | while (true) {
|
| 274 | - $p0 = strpos($this->template,'<!--',$p); |
|
| 274 | + $p0 = strpos($this->template, '<!--', $p); |
|
| 275 | 275 | if ($p0 === false) break; |
| 276 | - $p = strpos($this->template,'-->',$p0); |
|
| 276 | + $p = strpos($this->template, '-->', $p0); |
|
| 277 | 277 | if ($p === false) {
|
| 278 | - $this->triggerError ("Invalid HTML comment in template at offset $p0.");
|
|
| 278 | + $this->triggerError("Invalid HTML comment in template at offset $p0.");
|
|
| 279 | 279 | return false; } |
| 280 | 280 | $p += 3; |
| 281 | - $cmdL = substr($this->template,$p0+4,$p-$p0-7); |
|
| 282 | - if (!$this->processTemplateCommand($cmdL,$p0,$p,$resumeFromStart)) |
|
| 281 | + $cmdL = substr($this->template, $p0 + 4, $p - $p0 - 7); |
|
| 282 | + if (!$this->processTemplateCommand($cmdL, $p0, $p, $resumeFromStart)) |
|
| 283 | 283 | return false; |
| 284 | 284 | if ($resumeFromStart) $p = $p0; } |
| 285 | 285 | return true; } |
@@ -288,29 +288,29 @@ discard block |
||
| 288 | 288 | * @return boolean true on success, false on error. |
| 289 | 289 | * @access private |
| 290 | 290 | */ |
| 291 | -function processTemplateCommand ($cmdL, $cmdTPosBegin, $cmdTPosEnd, &$resumeFromStart) {
|
|
| 291 | +function processTemplateCommand($cmdL, $cmdTPosBegin, $cmdTPosEnd, &$resumeFromStart) {
|
|
| 292 | 292 | $resumeFromStart = false; |
| 293 | 293 | $p = 0; |
| 294 | 294 | $cmd = ''; |
| 295 | - if (!$this->parseWord($cmdL,$p,$cmd)) return true; |
|
| 296 | - $parms = substr($cmdL,$p); |
|
| 295 | + if (!$this->parseWord($cmdL, $p, $cmd)) return true; |
|
| 296 | + $parms = substr($cmdL, $p); |
|
| 297 | 297 | switch (strtoupper($cmd)) {
|
| 298 | 298 | case '$BEGINBLOCK': |
| 299 | - if (!$this->processBeginBlockCmd($parms,$cmdTPosBegin,$cmdTPosEnd)) |
|
| 299 | + if (!$this->processBeginBlockCmd($parms, $cmdTPosBegin, $cmdTPosEnd)) |
|
| 300 | 300 | return false; |
| 301 | 301 | break; |
| 302 | 302 | case '$ENDBLOCK': |
| 303 | - if (!$this->processEndBlockCmd($parms,$cmdTPosBegin,$cmdTPosEnd)) |
|
| 303 | + if (!$this->processEndBlockCmd($parms, $cmdTPosBegin, $cmdTPosEnd)) |
|
| 304 | 304 | return false; |
| 305 | 305 | break; |
| 306 | 306 | case '$INCLUDE': |
| 307 | - if (!$this->processincludeCmd($parms,$cmdTPosBegin,$cmdTPosEnd)) |
|
| 307 | + if (!$this->processincludeCmd($parms, $cmdTPosBegin, $cmdTPosEnd)) |
|
| 308 | 308 | return false; |
| 309 | 309 | $resumeFromStart = true; |
| 310 | 310 | break; |
| 311 | 311 | default: |
| 312 | 312 | if ($cmd{0} == '$' && !(strlen($cmd) >= 2 && $cmd{1} == '{')) {
|
| 313 | - $this->triggerError ("Unknown command \"$cmd\" in template at offset $cmdTPosBegin.");
|
|
| 313 | + $this->triggerError("Unknown command \"$cmd\" in template at offset $cmdTPosBegin.");
|
|
| 314 | 314 | return false; }} |
| 315 | 315 | return true; } |
| 316 | 316 | |
@@ -319,24 +319,24 @@ discard block |
||
| 319 | 319 | * @return boolean true on success, false on error. |
| 320 | 320 | * @access private |
| 321 | 321 | */ |
| 322 | -function processBeginBlockCmd ($parms, $cmdTPosBegin, $cmdTPosEnd) {
|
|
| 322 | +function processBeginBlockCmd($parms, $cmdTPosBegin, $cmdTPosEnd) {
|
|
| 323 | 323 | $p = 0; |
| 324 | - if (!$this->parseWord($parms,$p,$blockName)) {
|
|
| 325 | - $this->triggerError ("Missing block name in \$BeginBlock command in template at offset $cmdTPosBegin.");
|
|
| 324 | + if (!$this->parseWord($parms, $p, $blockName)) {
|
|
| 325 | + $this->triggerError("Missing block name in \$BeginBlock command in template at offset $cmdTPosBegin.");
|
|
| 326 | 326 | return false; } |
| 327 | - if (trim(substr($parms,$p)) != '') {
|
|
| 328 | - $this->triggerError ("Extra parameter in \$BeginBlock command in template at offset $cmdTPosBegin.");
|
|
| 327 | + if (trim(substr($parms, $p)) != '') {
|
|
| 328 | + $this->triggerError("Extra parameter in \$BeginBlock command in template at offset $cmdTPosBegin.");
|
|
| 329 | 329 | return false; } |
| 330 | - $this->registerBlock ($blockName, $blockNo); |
|
| 331 | - $btr =& $this->blockTab[$blockNo]; |
|
| 330 | + $this->registerBlock($blockName, $blockNo); |
|
| 331 | + $btr = & $this->blockTab[$blockNo]; |
|
| 332 | 332 | $btr['tPosBegin'] = $cmdTPosBegin; |
| 333 | 333 | $btr['tPosContentsBegin'] = $cmdTPosEnd; |
| 334 | 334 | $btr['nestingLevel'] = $this->currentNestingLevel; |
| 335 | - $btr['parentBlockNo'] = $this->openBlocksTab[$this->currentNestingLevel-1]; |
|
| 335 | + $btr['parentBlockNo'] = $this->openBlocksTab[$this->currentNestingLevel - 1]; |
|
| 336 | 336 | $this->openBlocksTab[$this->currentNestingLevel] = $blockNo; |
| 337 | 337 | $this->currentNestingLevel += 1; |
| 338 | 338 | if ($this->currentNestingLevel > $this->maxNestingLevel) {
|
| 339 | - $this->triggerError ("Block nesting overflow in template at offset $cmdTPosBegin.");
|
|
| 339 | + $this->triggerError("Block nesting overflow in template at offset $cmdTPosBegin.");
|
|
| 340 | 340 | return false; } |
| 341 | 341 | return true; } |
| 342 | 342 | |
@@ -345,24 +345,24 @@ discard block |
||
| 345 | 345 | * @return boolean true on success, false on error. |
| 346 | 346 | * @access private |
| 347 | 347 | */ |
| 348 | -function processEndBlockCmd ($parms, $cmdTPosBegin, $cmdTPosEnd) {
|
|
| 348 | +function processEndBlockCmd($parms, $cmdTPosBegin, $cmdTPosEnd) {
|
|
| 349 | 349 | $p = 0; |
| 350 | - if (!$this->parseWord($parms,$p,$blockName)) {
|
|
| 351 | - $this->triggerError ("Missing block name in \$EndBlock command in template at offset $cmdTPosBegin.");
|
|
| 350 | + if (!$this->parseWord($parms, $p, $blockName)) {
|
|
| 351 | + $this->triggerError("Missing block name in \$EndBlock command in template at offset $cmdTPosBegin.");
|
|
| 352 | 352 | return false; } |
| 353 | - if (trim(substr($parms,$p)) != '') {
|
|
| 354 | - $this->triggerError ("Extra parameter in \$EndBlock command in template at offset $cmdTPosBegin.");
|
|
| 353 | + if (trim(substr($parms, $p)) != '') {
|
|
| 354 | + $this->triggerError("Extra parameter in \$EndBlock command in template at offset $cmdTPosBegin.");
|
|
| 355 | 355 | return false; } |
| 356 | - if (!$this->lookupBlockName($blockName,$blockNo)) {
|
|
| 357 | - $this->triggerError ("Undefined block name \"$blockName\" in \$EndBlock command in template at offset $cmdTPosBegin.");
|
|
| 356 | + if (!$this->lookupBlockName($blockName, $blockNo)) {
|
|
| 357 | + $this->triggerError("Undefined block name \"$blockName\" in \$EndBlock command in template at offset $cmdTPosBegin.");
|
|
| 358 | 358 | return false; } |
| 359 | 359 | $this->currentNestingLevel -= 1; |
| 360 | - $btr =& $this->blockTab[$blockNo]; |
|
| 360 | + $btr = & $this->blockTab[$blockNo]; |
|
| 361 | 361 | if (!$btr['definitionIsOpen']) {
|
| 362 | - $this->triggerError ("Multiple \$EndBlock command for block \"$blockName\" in template at offset $cmdTPosBegin.");
|
|
| 362 | + $this->triggerError("Multiple \$EndBlock command for block \"$blockName\" in template at offset $cmdTPosBegin.");
|
|
| 363 | 363 | return false; } |
| 364 | 364 | if ($btr['nestingLevel'] != $this->currentNestingLevel) {
|
| 365 | - $this->triggerError ("Block nesting level mismatch at \$EndBlock command for block \"$blockName\" in template at offset $cmdTPosBegin.");
|
|
| 365 | + $this->triggerError("Block nesting level mismatch at \$EndBlock command for block \"$blockName\" in template at offset $cmdTPosBegin.");
|
|
| 366 | 366 | return false; } |
| 367 | 367 | $btr['tPosContentsEnd'] = $cmdTPosBegin; |
| 368 | 368 | $btr['tPosEnd'] = $cmdTPosEnd; |
@@ -374,10 +374,10 @@ discard block |
||
| 374 | 374 | */ |
| 375 | 375 | function registerBlock($blockName, &$blockNo) {
|
| 376 | 376 | $blockNo = $this->blockTabCnt++; |
| 377 | - $btr =& $this->blockTab[$blockNo]; |
|
| 377 | + $btr = & $this->blockTab[$blockNo]; |
|
| 378 | 378 | $btr = array(); |
| 379 | 379 | $btr['blockName'] = $blockName; |
| 380 | - if (!$this->lookupBlockName($blockName,$btr['nextWithSameName'])) |
|
| 380 | + if (!$this->lookupBlockName($blockName, $btr['nextWithSameName'])) |
|
| 381 | 381 | $btr['nextWithSameName'] = -1; |
| 382 | 382 | $btr['definitionIsOpen'] = true; |
| 383 | 383 | $btr['instances'] = 0; |
@@ -394,13 +394,13 @@ discard block |
||
| 394 | 394 | * @access private |
| 395 | 395 | */ |
| 396 | 396 | function checkBlockDefinitionsComplete() {
|
| 397 | - for ($blockNo=0; $blockNo < $this->blockTabCnt; $blockNo++) {
|
|
| 398 | - $btr =& $this->blockTab[$blockNo]; |
|
| 397 | + for ($blockNo = 0; $blockNo < $this->blockTabCnt; $blockNo++) {
|
|
| 398 | + $btr = & $this->blockTab[$blockNo]; |
|
| 399 | 399 | if ($btr['definitionIsOpen']) {
|
| 400 | - $this->triggerError ("Missing \$EndBlock command in template for block " . $btr['blockName'] . ".");
|
|
| 400 | + $this->triggerError("Missing \$EndBlock command in template for block ".$btr['blockName'].".");
|
|
| 401 | 401 | return false; }} |
| 402 | 402 | if ($this->currentNestingLevel != 0) {
|
| 403 | - $this->triggerError ("Block nesting level error at end of template.");
|
|
| 403 | + $this->triggerError("Block nesting level error at end of template.");
|
|
| 404 | 404 | return false; } |
| 405 | 405 | return true; } |
| 406 | 406 | |
@@ -409,29 +409,29 @@ discard block |
||
| 409 | 409 | * @return boolean true on success, false on error. |
| 410 | 410 | * @access private |
| 411 | 411 | */ |
| 412 | -function processIncludeCmd ($parms, $cmdTPosBegin, $cmdTPosEnd) {
|
|
| 412 | +function processIncludeCmd($parms, $cmdTPosBegin, $cmdTPosEnd) {
|
|
| 413 | 413 | $p = 0; |
| 414 | - if (!$this->parseWordOrQuotedString($parms,$p,$subtemplateName)) {
|
|
| 415 | - $this->triggerError ("Missing or invalid subtemplate name in \$Include command in template at offset $cmdTPosBegin.");
|
|
| 414 | + if (!$this->parseWordOrQuotedString($parms, $p, $subtemplateName)) {
|
|
| 415 | + $this->triggerError("Missing or invalid subtemplate name in \$Include command in template at offset $cmdTPosBegin.");
|
|
| 416 | 416 | return false; } |
| 417 | - if (trim(substr($parms,$p)) != '') {
|
|
| 418 | - $this->triggerError ("Extra parameter in \$include command in template at offset $cmdTPosBegin.");
|
|
| 417 | + if (trim(substr($parms, $p)) != '') {
|
|
| 418 | + $this->triggerError("Extra parameter in \$include command in template at offset $cmdTPosBegin.");
|
|
| 419 | 419 | return false; } |
| 420 | - return $this->insertSubtemplate($subtemplateName,$cmdTPosBegin,$cmdTPosEnd); } |
|
| 420 | + return $this->insertSubtemplate($subtemplateName, $cmdTPosBegin, $cmdTPosEnd); } |
|
| 421 | 421 | |
| 422 | 422 | /** |
| 423 | 423 | * Processes the $Include command. |
| 424 | 424 | * @return boolean true on success, false on error. |
| 425 | 425 | * @access private |
| 426 | 426 | */ |
| 427 | -function insertSubtemplate ($subtemplateName, $tPos1, $tPos2) {
|
|
| 427 | +function insertSubtemplate($subtemplateName, $tPos1, $tPos2) {
|
|
| 428 | 428 | if (strlen($this->template) > $this->maxInclTemplateSize) {
|
| 429 | - $this->triggerError ("Subtemplate include aborted because the internal template string is longer than $this->maxInclTemplateSize characters.");
|
|
| 429 | + $this->triggerError("Subtemplate include aborted because the internal template string is longer than $this->maxInclTemplateSize characters.");
|
|
| 430 | 430 | return false; } |
| 431 | - if (!$this->loadSubtemplate($subtemplateName,$subtemplate)) return false; |
|
| 431 | + if (!$this->loadSubtemplate($subtemplateName, $subtemplate)) return false; |
|
| 432 | 432 | // (Copying the template to insert a subtemplate is a bit slow. In a future implementation of MiniTemplator, |
| 433 | 433 | // a table could be used that contains references to the string fragments.) |
| 434 | - $this->template = substr($this->template,0,$tPos1) . $subtemplate . substr($this->template,$tPos2); |
|
| 434 | + $this->template = substr($this->template, 0, $tPos1).$subtemplate.substr($this->template, $tPos2); |
|
| 435 | 435 | return true; } |
| 436 | 436 | |
| 437 | 437 | /** |
@@ -447,24 +447,24 @@ discard block |
||
| 447 | 447 | $p0 = $p; |
| 448 | 448 | $p = strpos($this->template, '}', $p); |
| 449 | 449 | if ($p === false) {
|
| 450 | - $this->triggerError ("Invalid variable reference in template at offset $p0.");
|
|
| 450 | + $this->triggerError("Invalid variable reference in template at offset $p0.");
|
|
| 451 | 451 | return false; } |
| 452 | 452 | $p += 1; |
| 453 | - $varName = trim(substr($this->template, $p0+2, $p-$p0-3)); |
|
| 453 | + $varName = trim(substr($this->template, $p0 + 2, $p - $p0 - 3)); |
|
| 454 | 454 | if (strlen($varName) == 0) {
|
| 455 | - $this->triggerError ("Empty variable name in template at offset $p0.");
|
|
| 455 | + $this->triggerError("Empty variable name in template at offset $p0.");
|
|
| 456 | 456 | return false; } |
| 457 | - $this->registerVariableReference ($varName, $p0, $p); } |
|
| 457 | + $this->registerVariableReference($varName, $p0, $p); } |
|
| 458 | 458 | return true; } |
| 459 | 459 | |
| 460 | 460 | /** |
| 461 | 461 | * @access private |
| 462 | 462 | */ |
| 463 | -function registerVariableReference ($varName, $tPosBegin, $tPosEnd) {
|
|
| 464 | - if (!$this->lookupVariableName($varName,$varNo)) |
|
| 465 | - $this->registerVariable($varName,$varNo); |
|
| 463 | +function registerVariableReference($varName, $tPosBegin, $tPosEnd) {
|
|
| 464 | + if (!$this->lookupVariableName($varName, $varNo)) |
|
| 465 | + $this->registerVariable($varName, $varNo); |
|
| 466 | 466 | $varRefNo = $this->varRefTabCnt++; |
| 467 | - $vrtr =& $this->varRefTab[$varRefNo]; |
|
| 467 | + $vrtr = & $this->varRefTab[$varRefNo]; |
|
| 468 | 468 | $vrtr = array(); |
| 469 | 469 | $vrtr['tPosBegin'] = $tPosBegin; |
| 470 | 470 | $vrtr['tPosEnd'] = $tPosEnd; |
@@ -473,9 +473,9 @@ discard block |
||
| 473 | 473 | /** |
| 474 | 474 | * @access private |
| 475 | 475 | */ |
| 476 | -function registerVariable ($varName, &$varNo) {
|
|
| 476 | +function registerVariable($varName, &$varNo) {
|
|
| 477 | 477 | $varNo = $this->varTabCnt++; |
| 478 | - $vtr =& $this->varTab[$varNo]; |
|
| 478 | + $vtr = & $this->varTab[$varNo]; |
|
| 479 | 479 | $vtr = array(); |
| 480 | 480 | $vtr['varName'] = $varName; |
| 481 | 481 | $vtr['varValue'] = ''; |
@@ -490,7 +490,7 @@ discard block |
||
| 490 | 490 | $activeBlockNo = 0; |
| 491 | 491 | $nextBlockNo = 1; |
| 492 | 492 | while ($varRefNo < $this->varRefTabCnt) {
|
| 493 | - $vrtr =& $this->varRefTab[$varRefNo]; |
|
| 493 | + $vrtr = & $this->varRefTab[$varRefNo]; |
|
| 494 | 494 | $varRefTPos = $vrtr['tPosBegin']; |
| 495 | 495 | $varNo = $vrtr['varNo']; |
| 496 | 496 | if ($varRefTPos >= $this->blockTab[$activeBlockNo]['tPosEnd']) {
|
@@ -501,7 +501,7 @@ discard block |
||
| 501 | 501 | $activeBlockNo = $nextBlockNo; |
| 502 | 502 | $nextBlockNo += 1; |
| 503 | 503 | continue; }} |
| 504 | - $btr =& $this->blockTab[$activeBlockNo]; |
|
| 504 | + $btr = & $this->blockTab[$activeBlockNo]; |
|
| 505 | 505 | if ($varRefTPos < $btr['tPosBegin']) |
| 506 | 506 | $this->programLogicError(1); |
| 507 | 507 | $blockVarNo = $btr['blockVarCnt']++; |
@@ -523,10 +523,10 @@ discard block |
||
| 523 | 523 | * @access public |
| 524 | 524 | */ |
| 525 | 525 | function reset() {
|
| 526 | - for ($varNo=0; $varNo<$this->varTabCnt; $varNo++) |
|
| 526 | + for ($varNo = 0; $varNo < $this->varTabCnt; $varNo++) |
|
| 527 | 527 | $this->varTab[$varNo]['varValue'] = ''; |
| 528 | - for ($blockNo=0; $blockNo<$this->blockTabCnt; $blockNo++) {
|
|
| 529 | - $btr =& $this->blockTab[$blockNo]; |
|
| 528 | + for ($blockNo = 0; $blockNo < $this->blockTabCnt; $blockNo++) {
|
|
| 529 | + $btr = & $this->blockTab[$blockNo]; |
|
| 530 | 530 | $btr['instances'] = 0; |
| 531 | 531 | $btr['firstBlockInstNo'] = -1; |
| 532 | 532 | $btr['lastBlockInstNo'] = -1; } |
@@ -548,11 +548,11 @@ discard block |
||
| 548 | 548 | * $isOptional is false). |
| 549 | 549 | * @access public |
| 550 | 550 | */ |
| 551 | -function setVariable ($variableName, $variableValue, $isOptional=false) {
|
|
| 552 | - if (!$this->templateValid) {$this->triggerError ("Template not valid."); return false; }
|
|
| 553 | - if (!$this->lookupVariableName($variableName,$varNo)) {
|
|
| 551 | +function setVariable($variableName, $variableValue, $isOptional = false) {
|
|
| 552 | + if (!$this->templateValid) {$this->triggerError("Template not valid."); return false; }
|
|
| 553 | + if (!$this->lookupVariableName($variableName, $varNo)) {
|
|
| 554 | 554 | if ($isOptional) return true; |
| 555 | - $this->triggerError ("Variable \"$variableName\" not defined in template.");
|
|
| 555 | + $this->triggerError("Variable \"$variableName\" not defined in template.");
|
|
| 556 | 556 | return false; } |
| 557 | 557 | $this->varTab[$varNo]['varValue'] = $variableValue; |
| 558 | 558 | return true; } |
@@ -575,8 +575,8 @@ discard block |
||
| 575 | 575 | * $isOptional is false). |
| 576 | 576 | * @access public |
| 577 | 577 | */ |
| 578 | -function setVariableEsc ($variableName, $variableValue, $isOptional=false) {
|
|
| 579 | - return $this->setVariable($variableName,htmlspecialchars($variableValue,ENT_QUOTES),$isOptional); } |
|
| 578 | +function setVariableEsc($variableName, $variableValue, $isOptional = false) {
|
|
| 579 | + return $this->setVariable($variableName, htmlspecialchars($variableValue, ENT_QUOTES), $isOptional); } |
|
| 580 | 580 | |
| 581 | 581 | /** |
| 582 | 582 | * Checks whether a variable with the specified name exists within the template. |
@@ -585,9 +585,9 @@ discard block |
||
| 585 | 585 | * variable with the specified name exists in the template. |
| 586 | 586 | * @access public |
| 587 | 587 | */ |
| 588 | -function variableExists ($variableName) {
|
|
| 589 | - if (!$this->templateValid) {$this->triggerError ("Template not valid."); return false; }
|
|
| 590 | - return $this->lookupVariableName($variableName,$varNo); } |
|
| 588 | +function variableExists($variableName) {
|
|
| 589 | + if (!$this->templateValid) {$this->triggerError("Template not valid."); return false; }
|
|
| 590 | + return $this->lookupVariableName($variableName, $varNo); } |
|
| 591 | 591 | |
| 592 | 592 | /** |
| 593 | 593 | * Adds an instance of a template block. |
@@ -603,9 +603,9 @@ discard block |
||
| 603 | 603 | * @access public |
| 604 | 604 | */ |
| 605 | 605 | function addBlock($blockName) {
|
| 606 | - if (!$this->templateValid) {$this->triggerError ("Template not valid."); return false; }
|
|
| 607 | - if (!$this->lookupBlockName($blockName,$blockNo)) {
|
|
| 608 | - $this->triggerError ("Block \"$blockName\" not defined in template.");
|
|
| 606 | + if (!$this->templateValid) {$this->triggerError("Template not valid."); return false; }
|
|
| 607 | + if (!$this->lookupBlockName($blockName, $blockNo)) {
|
|
| 608 | + $this->triggerError("Block \"$blockName\" not defined in template.");
|
|
| 609 | 609 | return false; } |
| 610 | 610 | while ($blockNo != -1) {
|
| 611 | 611 | $this->addBlockByNo($blockNo); |
@@ -615,10 +615,10 @@ discard block |
||
| 615 | 615 | /** |
| 616 | 616 | * @access private |
| 617 | 617 | */ |
| 618 | -function addBlockByNo ($blockNo) {
|
|
| 619 | - $btr =& $this->blockTab[$blockNo]; |
|
| 620 | - $this->registerBlockInstance ($blockInstNo); |
|
| 621 | - $bitr =& $this->blockInstTab[$blockInstNo]; |
|
| 618 | +function addBlockByNo($blockNo) {
|
|
| 619 | + $btr = & $this->blockTab[$blockNo]; |
|
| 620 | + $this->registerBlockInstance($blockInstNo); |
|
| 621 | + $bitr = & $this->blockInstTab[$blockInstNo]; |
|
| 622 | 622 | if ($btr['firstBlockInstNo'] == -1) |
| 623 | 623 | $btr['firstBlockInstNo'] = $blockInstNo; |
| 624 | 624 | if ($btr['lastBlockInstNo'] != -1) |
@@ -636,14 +636,14 @@ discard block |
||
| 636 | 636 | $bitr['nextBlockInstNo'] = -1; |
| 637 | 637 | $bitr['blockVarTab'] = array(); |
| 638 | 638 | // copy instance variables for this block |
| 639 | - for ($blockVarNo=0; $blockVarNo<$blockVarCnt; $blockVarNo++) {
|
|
| 639 | + for ($blockVarNo = 0; $blockVarNo < $blockVarCnt; $blockVarNo++) {
|
|
| 640 | 640 | $varNo = $btr['blockVarNoToVarNoMap'][$blockVarNo]; |
| 641 | 641 | $bitr['blockVarTab'][$blockVarNo] = $this->varTab[$varNo]['varValue']; }} |
| 642 | 642 | |
| 643 | 643 | /** |
| 644 | 644 | * @access private |
| 645 | 645 | */ |
| 646 | -function registerBlockInstance (&$blockInstNo) {
|
|
| 646 | +function registerBlockInstance(&$blockInstNo) {
|
|
| 647 | 647 | $blockInstNo = $this->blockInstTabCnt++; } |
| 648 | 648 | |
| 649 | 649 | /** |
@@ -653,9 +653,9 @@ discard block |
||
| 653 | 653 | * block with the specified name exists in the template. |
| 654 | 654 | * @access public |
| 655 | 655 | */ |
| 656 | -function blockExists ($blockName) {
|
|
| 657 | - if (!$this->templateValid) {$this->triggerError ("Template not valid."); return false; }
|
|
| 658 | - return $this->lookupBlockName($blockName,$blockNo); } |
|
| 656 | +function blockExists($blockName) {
|
|
| 657 | + if (!$this->templateValid) {$this->triggerError("Template not valid."); return false; }
|
|
| 658 | + return $this->lookupBlockName($blockName, $blockNo); } |
|
| 659 | 659 | |
| 660 | 660 | //--- output generation --------------------------------------------------------------------------------------------- |
| 661 | 661 | |
@@ -664,7 +664,7 @@ discard block |
||
| 664 | 664 | * @return boolean true on success, false on error. |
| 665 | 665 | * @access public |
| 666 | 666 | */ |
| 667 | -function generateOutput () {
|
|
| 667 | +function generateOutput() {
|
|
| 668 | 668 | $this->outputMode = 0; |
| 669 | 669 | if (!$this->generateOutputPage()) return false; |
| 670 | 670 | return true; } |
@@ -675,13 +675,13 @@ discard block |
||
| 675 | 675 | * @return boolean true on success, false on error. |
| 676 | 676 | * @access public |
| 677 | 677 | */ |
| 678 | -function generateOutputToFile ($fileName) {
|
|
| 679 | - $fh = fopen($fileName,"wb"); |
|
| 678 | +function generateOutputToFile($fileName) {
|
|
| 679 | + $fh = fopen($fileName, "wb"); |
|
| 680 | 680 | if ($fh === false) return false; |
| 681 | 681 | $this->outputMode = 1; |
| 682 | 682 | $this->outputFileHandle = $fh; |
| 683 | 683 | $ok = $this->generateOutputPage(); |
| 684 | - fclose ($fh); |
|
| 684 | + fclose($fh); |
|
| 685 | 685 | return $ok; } |
| 686 | 686 | |
| 687 | 687 | /** |
@@ -691,7 +691,7 @@ discard block |
||
| 691 | 691 | * @return boolean true on success, false on error. |
| 692 | 692 | * @access public |
| 693 | 693 | */ |
| 694 | -function generateOutputToString (&$outputString) {
|
|
| 694 | +function generateOutputToString(&$outputString) {
|
|
| 695 | 695 | $outputString = "Error"; |
| 696 | 696 | $this->outputMode = 2; |
| 697 | 697 | $this->outputString = ""; |
@@ -704,14 +704,14 @@ discard block |
||
| 704 | 704 | * @return boolean true on success, false on error. |
| 705 | 705 | */ |
| 706 | 706 | function generateOutputPage() {
|
| 707 | - if (!$this->templateValid) {$this->triggerError ("Template not valid."); return false; }
|
|
| 707 | + if (!$this->templateValid) {$this->triggerError("Template not valid."); return false; }
|
|
| 708 | 708 | if ($this->blockTab[0]['instances'] == 0) |
| 709 | - $this->addBlockByNo (0); // add main block |
|
| 710 | - for ($blockNo=0; $blockNo < $this->blockTabCnt; $blockNo++) {
|
|
| 711 | - $btr =& $this->blockTab[$blockNo]; |
|
| 709 | + $this->addBlockByNo(0); // add main block |
|
| 710 | + for ($blockNo = 0; $blockNo < $this->blockTabCnt; $blockNo++) {
|
|
| 711 | + $btr = & $this->blockTab[$blockNo]; |
|
| 712 | 712 | $btr['currBlockInstNo'] = $btr['firstBlockInstNo']; } |
| 713 | 713 | $this->outputError = false; |
| 714 | - $this->writeBlockInstances (0, -1); |
|
| 714 | + $this->writeBlockInstances(0, -1); |
|
| 715 | 715 | if ($this->outputError) return false; |
| 716 | 716 | return true; } |
| 717 | 717 | |
@@ -721,33 +721,33 @@ discard block |
||
| 721 | 721 | * Called recursively. |
| 722 | 722 | * @access private |
| 723 | 723 | */ |
| 724 | -function writeBlockInstances ($blockNo, $parentInstLevel) {
|
|
| 725 | - $btr =& $this->blockTab[$blockNo]; |
|
| 724 | +function writeBlockInstances($blockNo, $parentInstLevel) {
|
|
| 725 | + $btr = & $this->blockTab[$blockNo]; |
|
| 726 | 726 | while (!$this->outputError) {
|
| 727 | 727 | $blockInstNo = $btr['currBlockInstNo']; |
| 728 | 728 | if ($blockInstNo == -1) break; |
| 729 | - $bitr =& $this->blockInstTab[$blockInstNo]; |
|
| 729 | + $bitr = & $this->blockInstTab[$blockInstNo]; |
|
| 730 | 730 | if ($bitr['parentInstLevel'] < $parentInstLevel) |
| 731 | - $this->programLogicError (2); |
|
| 731 | + $this->programLogicError(2); |
|
| 732 | 732 | if ($bitr['parentInstLevel'] > $parentInstLevel) break; |
| 733 | - $this->writeBlockInstance ($blockInstNo); |
|
| 733 | + $this->writeBlockInstance($blockInstNo); |
|
| 734 | 734 | $btr['currBlockInstNo'] = $bitr['nextBlockInstNo']; }} |
| 735 | 735 | |
| 736 | 736 | /** |
| 737 | 737 | * @access private |
| 738 | 738 | */ |
| 739 | 739 | function writeBlockInstance($blockInstNo) {
|
| 740 | - $bitr =& $this->blockInstTab[$blockInstNo]; |
|
| 740 | + $bitr = & $this->blockInstTab[$blockInstNo]; |
|
| 741 | 741 | $blockNo = $bitr['blockNo']; |
| 742 | - $btr =& $this->blockTab[$blockNo]; |
|
| 742 | + $btr = & $this->blockTab[$blockNo]; |
|
| 743 | 743 | $tPos = $btr['tPosContentsBegin']; |
| 744 | 744 | $subBlockNo = $blockNo + 1; |
| 745 | 745 | $varRefNo = $btr['firstVarRefNo']; |
| 746 | 746 | while (!$this->outputError) {
|
| 747 | 747 | $tPos2 = $btr['tPosContentsEnd']; |
| 748 | - $kind = 0; // assume end-of-block |
|
| 748 | + $kind = 0; // assume end-of-block |
|
| 749 | 749 | if ($varRefNo != -1 && $varRefNo < $this->varRefTabCnt) { // check for variable reference
|
| 750 | - $vrtr =& $this->varRefTab[$varRefNo]; |
|
| 750 | + $vrtr = & $this->varRefTab[$varRefNo]; |
|
| 751 | 751 | if ($vrtr['tPosBegin'] < $tPos) {
|
| 752 | 752 | $varRefNo += 1; |
| 753 | 753 | continue; } |
@@ -755,7 +755,7 @@ discard block |
||
| 755 | 755 | $tPos2 = $vrtr['tPosBegin']; |
| 756 | 756 | $kind = 1; }} |
| 757 | 757 | if ($subBlockNo < $this->blockTabCnt) { // check for subblock
|
| 758 | - $subBtr =& $this->blockTab[$subBlockNo]; |
|
| 758 | + $subBtr = & $this->blockTab[$subBlockNo]; |
|
| 759 | 759 | if ($subBtr['tPosBegin'] < $tPos) {
|
| 760 | 760 | $subBlockNo += 1; |
| 761 | 761 | continue; } |
@@ -763,24 +763,24 @@ discard block |
||
| 763 | 763 | $tPos2 = $subBtr['tPosBegin']; |
| 764 | 764 | $kind = 2; }} |
| 765 | 765 | if ($tPos2 > $tPos) |
| 766 | - $this->writeString (substr($this->template,$tPos,$tPos2-$tPos)); |
|
| 766 | + $this->writeString(substr($this->template, $tPos, $tPos2 - $tPos)); |
|
| 767 | 767 | switch ($kind) {
|
| 768 | 768 | case 0: // end of block |
| 769 | 769 | return; |
| 770 | 770 | case 1: // variable |
| 771 | - $vrtr =& $this->varRefTab[$varRefNo]; |
|
| 771 | + $vrtr = & $this->varRefTab[$varRefNo]; |
|
| 772 | 772 | if ($vrtr['blockNo'] != $blockNo) |
| 773 | - $this->programLogicError (4); |
|
| 773 | + $this->programLogicError(4); |
|
| 774 | 774 | $variableValue = $bitr['blockVarTab'][$vrtr['blockVarNo']]; |
| 775 | - $this->writeString ($variableValue); |
|
| 775 | + $this->writeString($variableValue); |
|
| 776 | 776 | $tPos = $vrtr['tPosEnd']; |
| 777 | 777 | $varRefNo += 1; |
| 778 | 778 | break; |
| 779 | 779 | case 2: // sub block |
| 780 | - $subBtr =& $this->blockTab[$subBlockNo]; |
|
| 780 | + $subBtr = & $this->blockTab[$subBlockNo]; |
|
| 781 | 781 | if ($subBtr['parentBlockNo'] != $blockNo) |
| 782 | - $this->programLogicError (3); |
|
| 783 | - $this->writeBlockInstances ($subBlockNo, $bitr['instanceLevel']); // recursive call |
|
| 782 | + $this->programLogicError(3); |
|
| 783 | + $this->writeBlockInstances($subBlockNo, $bitr['instanceLevel']); // recursive call |
|
| 784 | 784 | $tPos = $subBtr['tPosEnd']; |
| 785 | 785 | $subBlockNo += 1; |
| 786 | 786 | break; }}} |
@@ -788,7 +788,7 @@ discard block |
||
| 788 | 788 | /** |
| 789 | 789 | * @access private |
| 790 | 790 | */ |
| 791 | -function writeString ($s) {
|
|
| 791 | +function writeString($s) {
|
|
| 792 | 792 | if ($this->outputError) return; |
| 793 | 793 | switch ($this->outputMode) {
|
| 794 | 794 | case 0: // output to PHP output stream |
@@ -810,8 +810,8 @@ discard block |
||
| 810 | 810 | * @return boolean true on success, false if the variable is not found. |
| 811 | 811 | * @access private |
| 812 | 812 | */ |
| 813 | -function lookupVariableName ($varName, &$varNo) {
|
|
| 814 | - $x =& $this->varNameToNoMap[strtoupper($varName)]; |
|
| 813 | +function lookupVariableName($varName, &$varNo) {
|
|
| 814 | + $x = & $this->varNameToNoMap[strtoupper($varName)]; |
|
| 815 | 815 | if (!isset($x)) return false; |
| 816 | 816 | $varNo = $x; |
| 817 | 817 | return true; } |
@@ -823,8 +823,8 @@ discard block |
||
| 823 | 823 | * @return boolean true on success, false when the block is not found. |
| 824 | 824 | * @access private |
| 825 | 825 | */ |
| 826 | -function lookupBlockName ($blockName, &$blockNo) {
|
|
| 827 | - $x =& $this->blockNameToNoMap[strtoupper($blockName)]; |
|
| 826 | +function lookupBlockName($blockName, &$blockNo) {
|
|
| 827 | + $x = & $this->blockNameToNoMap[strtoupper($blockName)]; |
|
| 828 | 828 | if (!isset($x)) return false; |
| 829 | 829 | $blockNo = $x; |
| 830 | 830 | return true; } |
@@ -836,17 +836,17 @@ discard block |
||
| 836 | 836 | * @return boolean true on success, false on error. |
| 837 | 837 | * @access private |
| 838 | 838 | */ |
| 839 | -function readFileIntoString ($fileName, &$s) {
|
|
| 840 | - if (function_exists('version_compare') && version_compare(phpversion(),"4.3.0",">=")) {
|
|
| 839 | +function readFileIntoString($fileName, &$s) {
|
|
| 840 | + if (function_exists('version_compare') && version_compare(phpversion(), "4.3.0", ">=")) {
|
|
| 841 | 841 | $s = file_get_contents($fileName); |
| 842 | 842 | if ($s === false) return false; |
| 843 | 843 | return true; } |
| 844 | - $fh = fopen($fileName,"rb"); |
|
| 844 | + $fh = fopen($fileName, "rb"); |
|
| 845 | 845 | if ($fh === false) return false; |
| 846 | 846 | $fileSize = filesize($fileName); |
| 847 | - if ($fileSize === false) {fclose ($fh); return false; }
|
|
| 848 | - $s = fread($fh,$fileSize); |
|
| 849 | - fclose ($fh); |
|
| 847 | + if ($fileSize === false) {fclose($fh); return false; }
|
|
| 848 | + $s = fread($fh, $fileSize); |
|
| 849 | + fclose($fh); |
|
| 850 | 850 | if (strlen($s) != $fileSize) return false; |
| 851 | 851 | return true; } |
| 852 | 852 | |
@@ -854,7 +854,7 @@ discard block |
||
| 854 | 854 | * @access private |
| 855 | 855 | * @return boolean true on success, false when the end of the string is reached. |
| 856 | 856 | */ |
| 857 | -function parseWord ($s, &$p, &$w) {
|
|
| 857 | +function parseWord($s, &$p, &$w) {
|
|
| 858 | 858 | $sLen = strlen($s); |
| 859 | 859 | while ($p < $sLen && ord($s{$p}) <= 32) $p++;
|
| 860 | 860 | if ($p >= $sLen) return false; |
@@ -867,11 +867,11 @@ discard block |
||
| 867 | 867 | * @access private |
| 868 | 868 | * @return boolean true on success, false on error. |
| 869 | 869 | */ |
| 870 | -function parseQuotedString ($s, &$p, &$w) {
|
|
| 870 | +function parseQuotedString($s, &$p, &$w) {
|
|
| 871 | 871 | $sLen = strlen($s); |
| 872 | 872 | while ($p < $sLen && ord($s{$p}) <= 32) $p++;
|
| 873 | 873 | if ($p >= $sLen) return false; |
| 874 | - if (substr($s,$p,1) != '"') return false; |
|
| 874 | + if (substr($s, $p, 1) != '"') return false; |
|
| 875 | 875 | $p++; $p0 = $p; |
| 876 | 876 | while ($p < $sLen && $s{$p} != '"') $p++;
|
| 877 | 877 | if ($p >= $sLen) return false; |
@@ -883,39 +883,39 @@ discard block |
||
| 883 | 883 | * @access private |
| 884 | 884 | * @return boolean true on success, false on error. |
| 885 | 885 | */ |
| 886 | -function parseWordOrQuotedString ($s, &$p, &$w) {
|
|
| 886 | +function parseWordOrQuotedString($s, &$p, &$w) {
|
|
| 887 | 887 | $sLen = strlen($s); |
| 888 | 888 | while ($p < $sLen && ord($s{$p}) <= 32) $p++;
|
| 889 | 889 | if ($p >= $sLen) return false; |
| 890 | - if (substr($s,$p,1) == '"') |
|
| 891 | - return $this->parseQuotedString($s,$p,$w); |
|
| 890 | + if (substr($s, $p, 1) == '"') |
|
| 891 | + return $this->parseQuotedString($s, $p, $w); |
|
| 892 | 892 | else |
| 893 | - return $this->parseWord($s,$p,$w); } |
|
| 893 | + return $this->parseWord($s, $p, $w); } |
|
| 894 | 894 | |
| 895 | 895 | /** |
| 896 | 896 | * Combine two file system paths. |
| 897 | 897 | * @access private |
| 898 | 898 | */ |
| 899 | -function combineFileSystemPath ($path1, $path2) {
|
|
| 899 | +function combineFileSystemPath($path1, $path2) {
|
|
| 900 | 900 | if ($path1 == '' || $path2 == '') return $path2; |
| 901 | 901 | $s = $path1; |
| 902 | - if (substr($s,-1) != '\\' && substr($s,-1) != '/') $s = $s . "/"; |
|
| 903 | - if (substr($path2,0,1) == '\\' || substr($path2,0,1) == '/') |
|
| 904 | - $s = $s . substr($path2,1); |
|
| 902 | + if (substr($s, -1) != '\\' && substr($s, -1) != '/') $s = $s."/"; |
|
| 903 | + if (substr($path2, 0, 1) == '\\' || substr($path2, 0, 1) == '/') |
|
| 904 | + $s = $s.substr($path2, 1); |
|
| 905 | 905 | else |
| 906 | - $s = $s . $path2; |
|
| 906 | + $s = $s.$path2; |
|
| 907 | 907 | return $s; } |
| 908 | 908 | |
| 909 | 909 | /** |
| 910 | 910 | * @access private |
| 911 | 911 | */ |
| 912 | -function triggerError ($msg) {
|
|
| 913 | - trigger_error ("MiniTemplator error: $msg", E_USER_ERROR); }
|
|
| 912 | +function triggerError($msg) {
|
|
| 913 | + trigger_error("MiniTemplator error: $msg", E_USER_ERROR); }
|
|
| 914 | 914 | |
| 915 | 915 | /** |
| 916 | 916 | * @access private |
| 917 | 917 | */ |
| 918 | -function programLogicError ($errorId) {
|
|
| 918 | +function programLogicError($errorId) {
|
|
| 919 | 919 | die ("MiniTemplator: Program logic error $errorId.\n"); }
|
| 920 | 920 | |
| 921 | 921 | } |
@@ -175,7 +175,9 @@ discard block |
||
| 175 | 175 | if (!$this->readFileIntoString($fileName,$s)) {
|
| 176 | 176 | $this->triggerError ("Error while reading template file " . $fileName . ".");
|
| 177 | 177 | return false; } |
| 178 | - if (!$this->setTemplateString($s)) return false; |
|
| 178 | + if (!$this->setTemplateString($s)) { |
|
| 179 | + return false; |
|
| 180 | + } |
|
| 179 | 181 | return true; } |
| 180 | 182 | |
| 181 | 183 | /** |
@@ -187,7 +189,9 @@ discard block |
||
| 187 | 189 | function setTemplateString ($templateString) {
|
| 188 | 190 | $this->templateValid = false; |
| 189 | 191 | $this->template = $templateString; |
| 190 | - if (!$this->parseTemplate()) return false; |
|
| 192 | + if (!$this->parseTemplate()) { |
|
| 193 | + return false; |
|
| 194 | + } |
|
| 191 | 195 | $this->reset(); |
| 192 | 196 | $this->templateValid = true; |
| 193 | 197 | return true; } |
@@ -214,10 +218,16 @@ discard block |
||
| 214 | 218 | function parseTemplate() {
|
| 215 | 219 | $this->initParsing(); |
| 216 | 220 | $this->beginMainBlock(); |
| 217 | - if (!$this->parseTemplateCommands()) return false; |
|
| 221 | + if (!$this->parseTemplateCommands()) { |
|
| 222 | + return false; |
|
| 223 | + } |
|
| 218 | 224 | $this->endMainBlock(); |
| 219 | - if (!$this->checkBlockDefinitionsComplete()) return false; |
|
| 220 | - if (!$this->parseTemplateVariables()) return false; |
|
| 225 | + if (!$this->checkBlockDefinitionsComplete()) { |
|
| 226 | + return false; |
|
| 227 | + } |
|
| 228 | + if (!$this->parseTemplateVariables()) { |
|
| 229 | + return false; |
|
| 230 | + } |
|
| 221 | 231 | $this->associateVariablesWithBlocks(); |
| 222 | 232 | return true; } |
| 223 | 233 | |
@@ -272,16 +282,22 @@ discard block |
||
| 272 | 282 | $p = 0; |
| 273 | 283 | while (true) {
|
| 274 | 284 | $p0 = strpos($this->template,'<!--',$p); |
| 275 | - if ($p0 === false) break; |
|
| 285 | + if ($p0 === false) { |
|
| 286 | + break; |
|
| 287 | + } |
|
| 276 | 288 | $p = strpos($this->template,'-->',$p0); |
| 277 | 289 | if ($p === false) {
|
| 278 | 290 | $this->triggerError ("Invalid HTML comment in template at offset $p0.");
|
| 279 | 291 | return false; } |
| 280 | 292 | $p += 3; |
| 281 | 293 | $cmdL = substr($this->template,$p0+4,$p-$p0-7); |
| 282 | - if (!$this->processTemplateCommand($cmdL,$p0,$p,$resumeFromStart)) |
|
| 283 | - return false; |
|
| 284 | - if ($resumeFromStart) $p = $p0; } |
|
| 294 | + if (!$this->processTemplateCommand($cmdL,$p0,$p,$resumeFromStart)) { |
|
| 295 | + return false; |
|
| 296 | + } |
|
| 297 | + if ($resumeFromStart) { |
|
| 298 | + $p = $p0; |
|
| 299 | + } |
|
| 300 | + } |
|
| 285 | 301 | return true; } |
| 286 | 302 | |
| 287 | 303 | /** |
@@ -292,20 +308,25 @@ discard block |
||
| 292 | 308 | $resumeFromStart = false; |
| 293 | 309 | $p = 0; |
| 294 | 310 | $cmd = ''; |
| 295 | - if (!$this->parseWord($cmdL,$p,$cmd)) return true; |
|
| 311 | + if (!$this->parseWord($cmdL,$p,$cmd)) { |
|
| 312 | + return true; |
|
| 313 | + } |
|
| 296 | 314 | $parms = substr($cmdL,$p); |
| 297 | 315 | switch (strtoupper($cmd)) {
|
| 298 | 316 | case '$BEGINBLOCK': |
| 299 | - if (!$this->processBeginBlockCmd($parms,$cmdTPosBegin,$cmdTPosEnd)) |
|
| 300 | - return false; |
|
| 317 | + if (!$this->processBeginBlockCmd($parms,$cmdTPosBegin,$cmdTPosEnd)) { |
|
| 318 | + return false; |
|
| 319 | + } |
|
| 301 | 320 | break; |
| 302 | 321 | case '$ENDBLOCK': |
| 303 | - if (!$this->processEndBlockCmd($parms,$cmdTPosBegin,$cmdTPosEnd)) |
|
| 304 | - return false; |
|
| 322 | + if (!$this->processEndBlockCmd($parms,$cmdTPosBegin,$cmdTPosEnd)) { |
|
| 323 | + return false; |
|
| 324 | + } |
|
| 305 | 325 | break; |
| 306 | 326 | case '$INCLUDE': |
| 307 | - if (!$this->processincludeCmd($parms,$cmdTPosBegin,$cmdTPosEnd)) |
|
| 308 | - return false; |
|
| 327 | + if (!$this->processincludeCmd($parms,$cmdTPosBegin,$cmdTPosEnd)) { |
|
| 328 | + return false; |
|
| 329 | + } |
|
| 309 | 330 | $resumeFromStart = true; |
| 310 | 331 | break; |
| 311 | 332 | default: |
@@ -377,8 +398,9 @@ discard block |
||
| 377 | 398 | $btr =& $this->blockTab[$blockNo]; |
| 378 | 399 | $btr = array(); |
| 379 | 400 | $btr['blockName'] = $blockName; |
| 380 | - if (!$this->lookupBlockName($blockName,$btr['nextWithSameName'])) |
|
| 381 | - $btr['nextWithSameName'] = -1; |
|
| 401 | + if (!$this->lookupBlockName($blockName,$btr['nextWithSameName'])) { |
|
| 402 | + $btr['nextWithSameName'] = -1; |
|
| 403 | + } |
|
| 382 | 404 | $btr['definitionIsOpen'] = true; |
| 383 | 405 | $btr['instances'] = 0; |
| 384 | 406 | $btr['firstBlockInstNo'] = -1; |
@@ -428,7 +450,9 @@ discard block |
||
| 428 | 450 | if (strlen($this->template) > $this->maxInclTemplateSize) {
|
| 429 | 451 | $this->triggerError ("Subtemplate include aborted because the internal template string is longer than $this->maxInclTemplateSize characters.");
|
| 430 | 452 | return false; } |
| 431 | - if (!$this->loadSubtemplate($subtemplateName,$subtemplate)) return false; |
|
| 453 | + if (!$this->loadSubtemplate($subtemplateName,$subtemplate)) { |
|
| 454 | + return false; |
|
| 455 | + } |
|
| 432 | 456 | // (Copying the template to insert a subtemplate is a bit slow. In a future implementation of MiniTemplator, |
| 433 | 457 | // a table could be used that contains references to the string fragments.) |
| 434 | 458 | $this->template = substr($this->template,0,$tPos1) . $subtemplate . substr($this->template,$tPos2); |
@@ -443,7 +467,9 @@ discard block |
||
| 443 | 467 | $p = 0; |
| 444 | 468 | while (true) {
|
| 445 | 469 | $p = strpos($this->template, '${', $p);
|
| 446 | - if ($p === false) break; |
|
| 470 | + if ($p === false) { |
|
| 471 | + break; |
|
| 472 | + } |
|
| 447 | 473 | $p0 = $p; |
| 448 | 474 | $p = strpos($this->template, '}', $p); |
| 449 | 475 | if ($p === false) {
|
@@ -461,8 +487,9 @@ discard block |
||
| 461 | 487 | * @access private |
| 462 | 488 | */ |
| 463 | 489 | function registerVariableReference ($varName, $tPosBegin, $tPosEnd) {
|
| 464 | - if (!$this->lookupVariableName($varName,$varNo)) |
|
| 465 | - $this->registerVariable($varName,$varNo); |
|
| 490 | + if (!$this->lookupVariableName($varName,$varNo)) { |
|
| 491 | + $this->registerVariable($varName,$varNo); |
|
| 492 | + } |
|
| 466 | 493 | $varRefNo = $this->varRefTabCnt++; |
| 467 | 494 | $vrtr =& $this->varRefTab[$varRefNo]; |
| 468 | 495 | $vrtr = array(); |
@@ -502,12 +529,14 @@ discard block |
||
| 502 | 529 | $nextBlockNo += 1; |
| 503 | 530 | continue; }} |
| 504 | 531 | $btr =& $this->blockTab[$activeBlockNo]; |
| 505 | - if ($varRefTPos < $btr['tPosBegin']) |
|
| 506 | - $this->programLogicError(1); |
|
| 532 | + if ($varRefTPos < $btr['tPosBegin']) { |
|
| 533 | + $this->programLogicError(1); |
|
| 534 | + } |
|
| 507 | 535 | $blockVarNo = $btr['blockVarCnt']++; |
| 508 | 536 | $btr['blockVarNoToVarNoMap'][$blockVarNo] = $varNo; |
| 509 | - if ($btr['firstVarRefNo'] == -1) |
|
| 510 | - $btr['firstVarRefNo'] = $varRefNo; |
|
| 537 | + if ($btr['firstVarRefNo'] == -1) { |
|
| 538 | + $btr['firstVarRefNo'] = $varRefNo; |
|
| 539 | + } |
|
| 511 | 540 | $vrtr['blockNo'] = $activeBlockNo; |
| 512 | 541 | $vrtr['blockVarNo'] = $blockVarNo; |
| 513 | 542 | $varRefNo += 1; }} |
@@ -523,8 +552,9 @@ discard block |
||
| 523 | 552 | * @access public |
| 524 | 553 | */ |
| 525 | 554 | function reset() {
|
| 526 | - for ($varNo=0; $varNo<$this->varTabCnt; $varNo++) |
|
| 527 | - $this->varTab[$varNo]['varValue'] = ''; |
|
| 555 | + for ($varNo=0; $varNo<$this->varTabCnt; $varNo++) { |
|
| 556 | + $this->varTab[$varNo]['varValue'] = ''; |
|
| 557 | + } |
|
| 528 | 558 | for ($blockNo=0; $blockNo<$this->blockTabCnt; $blockNo++) {
|
| 529 | 559 | $btr =& $this->blockTab[$blockNo]; |
| 530 | 560 | $btr['instances'] = 0; |
@@ -551,7 +581,9 @@ discard block |
||
| 551 | 581 | function setVariable ($variableName, $variableValue, $isOptional=false) {
|
| 552 | 582 | if (!$this->templateValid) {$this->triggerError ("Template not valid."); return false; }
|
| 553 | 583 | if (!$this->lookupVariableName($variableName,$varNo)) {
|
| 554 | - if ($isOptional) return true; |
|
| 584 | + if ($isOptional) { |
|
| 585 | + return true; |
|
| 586 | + } |
|
| 555 | 587 | $this->triggerError ("Variable \"$variableName\" not defined in template.");
|
| 556 | 588 | return false; } |
| 557 | 589 | $this->varTab[$varNo]['varValue'] = $variableValue; |
@@ -619,20 +651,23 @@ discard block |
||
| 619 | 651 | $btr =& $this->blockTab[$blockNo]; |
| 620 | 652 | $this->registerBlockInstance ($blockInstNo); |
| 621 | 653 | $bitr =& $this->blockInstTab[$blockInstNo]; |
| 622 | - if ($btr['firstBlockInstNo'] == -1) |
|
| 623 | - $btr['firstBlockInstNo'] = $blockInstNo; |
|
| 624 | - if ($btr['lastBlockInstNo'] != -1) |
|
| 625 | - $this->blockInstTab[$btr['lastBlockInstNo']]['nextBlockInstNo'] = $blockInstNo; |
|
| 654 | + if ($btr['firstBlockInstNo'] == -1) { |
|
| 655 | + $btr['firstBlockInstNo'] = $blockInstNo; |
|
| 656 | + } |
|
| 657 | + if ($btr['lastBlockInstNo'] != -1) { |
|
| 658 | + $this->blockInstTab[$btr['lastBlockInstNo']]['nextBlockInstNo'] = $blockInstNo; |
|
| 659 | + } |
|
| 626 | 660 | // set forward pointer of chain |
| 627 | 661 | $btr['lastBlockInstNo'] = $blockInstNo; |
| 628 | 662 | $parentBlockNo = $btr['parentBlockNo']; |
| 629 | 663 | $blockVarCnt = $btr['blockVarCnt']; |
| 630 | 664 | $bitr['blockNo'] = $blockNo; |
| 631 | 665 | $bitr['instanceLevel'] = $btr['instances']++; |
| 632 | - if ($parentBlockNo == -1) |
|
| 633 | - $bitr['parentInstLevel'] = -1; |
|
| 634 | - else |
|
| 635 | - $bitr['parentInstLevel'] = $this->blockTab[$parentBlockNo]['instances']; |
|
| 666 | + if ($parentBlockNo == -1) { |
|
| 667 | + $bitr['parentInstLevel'] = -1; |
|
| 668 | + } else { |
|
| 669 | + $bitr['parentInstLevel'] = $this->blockTab[$parentBlockNo]['instances']; |
|
| 670 | + } |
|
| 636 | 671 | $bitr['nextBlockInstNo'] = -1; |
| 637 | 672 | $bitr['blockVarTab'] = array(); |
| 638 | 673 | // copy instance variables for this block |
@@ -666,7 +701,9 @@ discard block |
||
| 666 | 701 | */ |
| 667 | 702 | function generateOutput () {
|
| 668 | 703 | $this->outputMode = 0; |
| 669 | - if (!$this->generateOutputPage()) return false; |
|
| 704 | + if (!$this->generateOutputPage()) { |
|
| 705 | + return false; |
|
| 706 | + } |
|
| 670 | 707 | return true; } |
| 671 | 708 | |
| 672 | 709 | /** |
@@ -677,7 +714,9 @@ discard block |
||
| 677 | 714 | */ |
| 678 | 715 | function generateOutputToFile ($fileName) {
|
| 679 | 716 | $fh = fopen($fileName,"wb"); |
| 680 | - if ($fh === false) return false; |
|
| 717 | + if ($fh === false) { |
|
| 718 | + return false; |
|
| 719 | + } |
|
| 681 | 720 | $this->outputMode = 1; |
| 682 | 721 | $this->outputFileHandle = $fh; |
| 683 | 722 | $ok = $this->generateOutputPage(); |
@@ -695,7 +734,9 @@ discard block |
||
| 695 | 734 | $outputString = "Error"; |
| 696 | 735 | $this->outputMode = 2; |
| 697 | 736 | $this->outputString = ""; |
| 698 | - if (!$this->generateOutputPage()) return false; |
|
| 737 | + if (!$this->generateOutputPage()) { |
|
| 738 | + return false; |
|
| 739 | + } |
|
| 699 | 740 | $outputString = $this->outputString; |
| 700 | 741 | return true; } |
| 701 | 742 | |
@@ -705,14 +746,18 @@ discard block |
||
| 705 | 746 | */ |
| 706 | 747 | function generateOutputPage() {
|
| 707 | 748 | if (!$this->templateValid) {$this->triggerError ("Template not valid."); return false; }
|
| 708 | - if ($this->blockTab[0]['instances'] == 0) |
|
| 709 | - $this->addBlockByNo (0); // add main block |
|
| 749 | + if ($this->blockTab[0]['instances'] == 0) { |
|
| 750 | + $this->addBlockByNo (0); |
|
| 751 | + } |
|
| 752 | + // add main block |
|
| 710 | 753 | for ($blockNo=0; $blockNo < $this->blockTabCnt; $blockNo++) {
|
| 711 | 754 | $btr =& $this->blockTab[$blockNo]; |
| 712 | 755 | $btr['currBlockInstNo'] = $btr['firstBlockInstNo']; } |
| 713 | 756 | $this->outputError = false; |
| 714 | 757 | $this->writeBlockInstances (0, -1); |
| 715 | - if ($this->outputError) return false; |
|
| 758 | + if ($this->outputError) { |
|
| 759 | + return false; |
|
| 760 | + } |
|
| 716 | 761 | return true; } |
| 717 | 762 | |
| 718 | 763 | /** |
@@ -725,11 +770,16 @@ discard block |
||
| 725 | 770 | $btr =& $this->blockTab[$blockNo]; |
| 726 | 771 | while (!$this->outputError) {
|
| 727 | 772 | $blockInstNo = $btr['currBlockInstNo']; |
| 728 | - if ($blockInstNo == -1) break; |
|
| 773 | + if ($blockInstNo == -1) { |
|
| 774 | + break; |
|
| 775 | + } |
|
| 729 | 776 | $bitr =& $this->blockInstTab[$blockInstNo]; |
| 730 | - if ($bitr['parentInstLevel'] < $parentInstLevel) |
|
| 731 | - $this->programLogicError (2); |
|
| 732 | - if ($bitr['parentInstLevel'] > $parentInstLevel) break; |
|
| 777 | + if ($bitr['parentInstLevel'] < $parentInstLevel) { |
|
| 778 | + $this->programLogicError (2); |
|
| 779 | + } |
|
| 780 | + if ($bitr['parentInstLevel'] > $parentInstLevel) { |
|
| 781 | + break; |
|
| 782 | + } |
|
| 733 | 783 | $this->writeBlockInstance ($blockInstNo); |
| 734 | 784 | $btr['currBlockInstNo'] = $bitr['nextBlockInstNo']; }} |
| 735 | 785 | |
@@ -762,15 +812,17 @@ discard block |
||
| 762 | 812 | if ($subBtr['tPosBegin'] < $tPos2) {
|
| 763 | 813 | $tPos2 = $subBtr['tPosBegin']; |
| 764 | 814 | $kind = 2; }} |
| 765 | - if ($tPos2 > $tPos) |
|
| 766 | - $this->writeString (substr($this->template,$tPos,$tPos2-$tPos)); |
|
| 815 | + if ($tPos2 > $tPos) { |
|
| 816 | + $this->writeString (substr($this->template,$tPos,$tPos2-$tPos)); |
|
| 817 | + } |
|
| 767 | 818 | switch ($kind) {
|
| 768 | 819 | case 0: // end of block |
| 769 | 820 | return; |
| 770 | 821 | case 1: // variable |
| 771 | 822 | $vrtr =& $this->varRefTab[$varRefNo]; |
| 772 | - if ($vrtr['blockNo'] != $blockNo) |
|
| 773 | - $this->programLogicError (4); |
|
| 823 | + if ($vrtr['blockNo'] != $blockNo) { |
|
| 824 | + $this->programLogicError (4); |
|
| 825 | + } |
|
| 774 | 826 | $variableValue = $bitr['blockVarTab'][$vrtr['blockVarNo']]; |
| 775 | 827 | $this->writeString ($variableValue); |
| 776 | 828 | $tPos = $vrtr['tPosEnd']; |
@@ -778,8 +830,9 @@ discard block |
||
| 778 | 830 | break; |
| 779 | 831 | case 2: // sub block |
| 780 | 832 | $subBtr =& $this->blockTab[$subBlockNo]; |
| 781 | - if ($subBtr['parentBlockNo'] != $blockNo) |
|
| 782 | - $this->programLogicError (3); |
|
| 833 | + if ($subBtr['parentBlockNo'] != $blockNo) { |
|
| 834 | + $this->programLogicError (3); |
|
| 835 | + } |
|
| 783 | 836 | $this->writeBlockInstances ($subBlockNo, $bitr['instanceLevel']); // recursive call |
| 784 | 837 | $tPos = $subBtr['tPosEnd']; |
| 785 | 838 | $subBlockNo += 1; |
@@ -789,15 +842,20 @@ discard block |
||
| 789 | 842 | * @access private |
| 790 | 843 | */ |
| 791 | 844 | function writeString ($s) {
|
| 792 | - if ($this->outputError) return; |
|
| 845 | + if ($this->outputError) { |
|
| 846 | + return; |
|
| 847 | + } |
|
| 793 | 848 | switch ($this->outputMode) {
|
| 794 | 849 | case 0: // output to PHP output stream |
| 795 | - if (!print($s)) |
|
| 796 | - $this->outputError = true; |
|
| 850 | + if (!print($s)) { |
|
| 851 | + $this->outputError = true; |
|
| 852 | + } |
|
| 797 | 853 | break; |
| 798 | 854 | case 1: // output to file |
| 799 | 855 | $rc = fwrite($this->outputFileHandle, $s); |
| 800 | - if ($rc === false) $this->outputError = true; |
|
| 856 | + if ($rc === false) { |
|
| 857 | + $this->outputError = true; |
|
| 858 | + } |
|
| 801 | 859 | break; |
| 802 | 860 | case 2: // output to string |
| 803 | 861 | $this->outputString .= $s; |
@@ -812,7 +870,9 @@ discard block |
||
| 812 | 870 | */ |
| 813 | 871 | function lookupVariableName ($varName, &$varNo) {
|
| 814 | 872 | $x =& $this->varNameToNoMap[strtoupper($varName)]; |
| 815 | - if (!isset($x)) return false; |
|
| 873 | + if (!isset($x)) { |
|
| 874 | + return false; |
|
| 875 | + } |
|
| 816 | 876 | $varNo = $x; |
| 817 | 877 | return true; } |
| 818 | 878 | |
@@ -825,7 +885,9 @@ discard block |
||
| 825 | 885 | */ |
| 826 | 886 | function lookupBlockName ($blockName, &$blockNo) {
|
| 827 | 887 | $x =& $this->blockNameToNoMap[strtoupper($blockName)]; |
| 828 | - if (!isset($x)) return false; |
|
| 888 | + if (!isset($x)) { |
|
| 889 | + return false; |
|
| 890 | + } |
|
| 829 | 891 | $blockNo = $x; |
| 830 | 892 | return true; } |
| 831 | 893 | |
@@ -839,15 +901,21 @@ discard block |
||
| 839 | 901 | function readFileIntoString ($fileName, &$s) {
|
| 840 | 902 | if (function_exists('version_compare') && version_compare(phpversion(),"4.3.0",">=")) {
|
| 841 | 903 | $s = file_get_contents($fileName); |
| 842 | - if ($s === false) return false; |
|
| 904 | + if ($s === false) { |
|
| 905 | + return false; |
|
| 906 | + } |
|
| 843 | 907 | return true; } |
| 844 | 908 | $fh = fopen($fileName,"rb"); |
| 845 | - if ($fh === false) return false; |
|
| 909 | + if ($fh === false) { |
|
| 910 | + return false; |
|
| 911 | + } |
|
| 846 | 912 | $fileSize = filesize($fileName); |
| 847 | 913 | if ($fileSize === false) {fclose ($fh); return false; }
|
| 848 | 914 | $s = fread($fh,$fileSize); |
| 849 | 915 | fclose ($fh); |
| 850 | - if (strlen($s) != $fileSize) return false; |
|
| 916 | + if (strlen($s) != $fileSize) { |
|
| 917 | + return false; |
|
| 918 | + } |
|
| 851 | 919 | return true; } |
| 852 | 920 | |
| 853 | 921 | /** |
@@ -856,10 +924,16 @@ discard block |
||
| 856 | 924 | */ |
| 857 | 925 | function parseWord ($s, &$p, &$w) {
|
| 858 | 926 | $sLen = strlen($s); |
| 859 | - while ($p < $sLen && ord($s{$p}) <= 32) $p++;
|
|
| 860 | - if ($p >= $sLen) return false; |
|
| 927 | + while ($p < $sLen && ord($s{$p}) <= 32) { |
|
| 928 | + $p++; |
|
| 929 | + } |
|
| 930 | + if ($p >= $sLen) { |
|
| 931 | + return false; |
|
| 932 | + } |
|
| 861 | 933 | $p0 = $p; |
| 862 | - while ($p < $sLen && ord($s{$p}) > 32) $p++;
|
|
| 934 | + while ($p < $sLen && ord($s{$p}) > 32) { |
|
| 935 | + $p++; |
|
| 936 | + } |
|
| 863 | 937 | $w = substr($s, $p0, $p - $p0); |
| 864 | 938 | return true; } |
| 865 | 939 | |
@@ -869,12 +943,22 @@ discard block |
||
| 869 | 943 | */ |
| 870 | 944 | function parseQuotedString ($s, &$p, &$w) {
|
| 871 | 945 | $sLen = strlen($s); |
| 872 | - while ($p < $sLen && ord($s{$p}) <= 32) $p++;
|
|
| 873 | - if ($p >= $sLen) return false; |
|
| 874 | - if (substr($s,$p,1) != '"') return false; |
|
| 946 | + while ($p < $sLen && ord($s{$p}) <= 32) { |
|
| 947 | + $p++; |
|
| 948 | + } |
|
| 949 | + if ($p >= $sLen) { |
|
| 950 | + return false; |
|
| 951 | + } |
|
| 952 | + if (substr($s,$p,1) != '"') { |
|
| 953 | + return false; |
|
| 954 | + } |
|
| 875 | 955 | $p++; $p0 = $p; |
| 876 | - while ($p < $sLen && $s{$p} != '"') $p++;
|
|
| 877 | - if ($p >= $sLen) return false; |
|
| 956 | + while ($p < $sLen && $s{$p} != '"') { |
|
| 957 | + $p++; |
|
| 958 | + } |
|
| 959 | + if ($p >= $sLen) { |
|
| 960 | + return false; |
|
| 961 | + } |
|
| 878 | 962 | $w = substr($s, $p0, $p - $p0); |
| 879 | 963 | $p++; |
| 880 | 964 | return true; } |
@@ -885,25 +969,36 @@ discard block |
||
| 885 | 969 | */ |
| 886 | 970 | function parseWordOrQuotedString ($s, &$p, &$w) {
|
| 887 | 971 | $sLen = strlen($s); |
| 888 | - while ($p < $sLen && ord($s{$p}) <= 32) $p++;
|
|
| 889 | - if ($p >= $sLen) return false; |
|
| 890 | - if (substr($s,$p,1) == '"') |
|
| 891 | - return $this->parseQuotedString($s,$p,$w); |
|
| 892 | - else |
|
| 893 | - return $this->parseWord($s,$p,$w); } |
|
| 972 | + while ($p < $sLen && ord($s{$p}) <= 32) { |
|
| 973 | + $p++; |
|
| 974 | + } |
|
| 975 | + if ($p >= $sLen) { |
|
| 976 | + return false; |
|
| 977 | + } |
|
| 978 | + if (substr($s,$p,1) == '"') { |
|
| 979 | + return $this->parseQuotedString($s,$p,$w); |
|
| 980 | + } else { |
|
| 981 | + return $this->parseWord($s,$p,$w); |
|
| 982 | + } |
|
| 983 | + } |
|
| 894 | 984 | |
| 895 | 985 | /** |
| 896 | 986 | * Combine two file system paths. |
| 897 | 987 | * @access private |
| 898 | 988 | */ |
| 899 | 989 | function combineFileSystemPath ($path1, $path2) {
|
| 900 | - if ($path1 == '' || $path2 == '') return $path2; |
|
| 990 | + if ($path1 == '' || $path2 == '') { |
|
| 991 | + return $path2; |
|
| 992 | + } |
|
| 901 | 993 | $s = $path1; |
| 902 | - if (substr($s,-1) != '\\' && substr($s,-1) != '/') $s = $s . "/"; |
|
| 903 | - if (substr($path2,0,1) == '\\' || substr($path2,0,1) == '/') |
|
| 904 | - $s = $s . substr($path2,1); |
|
| 905 | - else |
|
| 906 | - $s = $s . $path2; |
|
| 994 | + if (substr($s,-1) != '\\' && substr($s,-1) != '/') { |
|
| 995 | + $s = $s . "/"; |
|
| 996 | + } |
|
| 997 | + if (substr($path2,0,1) == '\\' || substr($path2,0,1) == '/') { |
|
| 998 | + $s = $s . substr($path2,1); |
|
| 999 | + } else { |
|
| 1000 | + $s = $s . $path2; |
|
| 1001 | + } |
|
| 907 | 1002 | return $s; } |
| 908 | 1003 | |
| 909 | 1004 | /** |
@@ -17,254 +17,254 @@ |
||
| 17 | 17 | // http://creativecommons.org/publicdomain/zero/1.0/ |
| 18 | 18 | |
| 19 | 19 | class jimIcon { |
| 20 | - // Get an image color from a string |
|
| 21 | - function get_color($str, $img) { |
|
| 22 | - $b = ord($str[0]); |
|
| 23 | - $g = ord($str[1]); |
|
| 24 | - $r = ord($str[2]); |
|
| 25 | - if (strlen($str) > 3) { |
|
| 26 | - $a = 127 - (ord($str[3]) / 2); |
|
| 27 | - if ($a != 0 && $a != 127) |
|
| 28 | - $this->had_alpha = 1; |
|
| 29 | - } else { |
|
| 30 | - $a = 0; |
|
| 31 | - } |
|
| 32 | - if ($a != 127) |
|
| 33 | - $this->all_transaprent = 0; |
|
| 34 | - return imagecolorallocatealpha($img, $r, $g, $b, $a); |
|
| 35 | - } |
|
| 20 | + // Get an image color from a string |
|
| 21 | + function get_color($str, $img) { |
|
| 22 | + $b = ord($str[0]); |
|
| 23 | + $g = ord($str[1]); |
|
| 24 | + $r = ord($str[2]); |
|
| 25 | + if (strlen($str) > 3) { |
|
| 26 | + $a = 127 - (ord($str[3]) / 2); |
|
| 27 | + if ($a != 0 && $a != 127) |
|
| 28 | + $this->had_alpha = 1; |
|
| 29 | + } else { |
|
| 30 | + $a = 0; |
|
| 31 | + } |
|
| 32 | + if ($a != 127) |
|
| 33 | + $this->all_transaprent = 0; |
|
| 34 | + return imagecolorallocatealpha($img, $r, $g, $b, $a); |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - // Given a string with the contents of an .ICO, |
|
| 38 | - // return a GD image of the icon, or false on error. |
|
| 39 | - function fromiconstring($ico) { |
|
| 40 | - $this->error = "(unknown error)"; |
|
| 41 | - $this->had_alpha = 0; |
|
| 37 | + // Given a string with the contents of an .ICO, |
|
| 38 | + // return a GD image of the icon, or false on error. |
|
| 39 | + function fromiconstring($ico) { |
|
| 40 | + $this->error = "(unknown error)"; |
|
| 41 | + $this->had_alpha = 0; |
|
| 42 | 42 | |
| 43 | - // Read header |
|
| 44 | - if (strlen($ico) < 6) { |
|
| 45 | - $this->error = "too short"; |
|
| 46 | - return false; |
|
| 47 | - } |
|
| 48 | - $h = unpack("vzero/vtype/vnum", $ico); |
|
| 43 | + // Read header |
|
| 44 | + if (strlen($ico) < 6) { |
|
| 45 | + $this->error = "too short"; |
|
| 46 | + return false; |
|
| 47 | + } |
|
| 48 | + $h = unpack("vzero/vtype/vnum", $ico); |
|
| 49 | 49 | |
| 50 | - // Must be ICO format with at least one image |
|
| 51 | - if ($h["zero"] != 0 || $h["type"] != 1 || $h["num"] == 0) { |
|
| 52 | - // See if we can just parse it with GD directly |
|
| 53 | - // if it's not ICO format; maybe it was a mislabeled |
|
| 54 | - // PNG or something. |
|
| 55 | - $i = @imagecreatefromstring($ico); |
|
| 56 | - if ($i) { |
|
| 57 | - imagesavealpha($i, true); |
|
| 58 | - return $i; |
|
| 59 | - } |
|
| 60 | - $this->error = "not ICO or other image"; |
|
| 61 | - return false; |
|
| 62 | - } |
|
| 50 | + // Must be ICO format with at least one image |
|
| 51 | + if ($h["zero"] != 0 || $h["type"] != 1 || $h["num"] == 0) { |
|
| 52 | + // See if we can just parse it with GD directly |
|
| 53 | + // if it's not ICO format; maybe it was a mislabeled |
|
| 54 | + // PNG or something. |
|
| 55 | + $i = @imagecreatefromstring($ico); |
|
| 56 | + if ($i) { |
|
| 57 | + imagesavealpha($i, true); |
|
| 58 | + return $i; |
|
| 59 | + } |
|
| 60 | + $this->error = "not ICO or other image"; |
|
| 61 | + return false; |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - // Read directory entries to find the biggest image |
|
| 65 | - $most_pixels = 0; |
|
| 66 | - for ($i = 0; $i < $h["num"]; $i++) { |
|
| 67 | - $entry = substr($ico, 6 + 16 * $i, 16); |
|
| 68 | - if (!$entry || strlen($entry) < 16) |
|
| 69 | - continue; |
|
| 70 | - $e = unpack("Cwidth/" . |
|
| 71 | - "Cheight/" . |
|
| 72 | - "Ccolors/" . |
|
| 73 | - "Czero/" . |
|
| 74 | - "vplanes/" . |
|
| 75 | - "vbpp/" . |
|
| 76 | - "Vsize/" . |
|
| 77 | - "Voffset/", |
|
| 78 | - $entry); |
|
| 79 | - if ($e["width"] == 0) |
|
| 80 | - $e["width"] = 256; |
|
| 81 | - if ($e["height"] == 0) |
|
| 82 | - $e["height"] = 256; |
|
| 83 | - if ($e["zero"] != 0) { |
|
| 84 | - $this->error = "nonzero reserved field"; |
|
| 85 | - return false; |
|
| 86 | - } |
|
| 87 | - $pixels = $e["width"] * $e["height"]; |
|
| 88 | - if ($pixels > $most_pixels) { |
|
| 89 | - $most_pixels = $pixels; |
|
| 90 | - $most = $e; |
|
| 91 | - } |
|
| 92 | - } |
|
| 93 | - if ($most_pixels == 0) { |
|
| 94 | - $this->error = "no pixels"; |
|
| 95 | - return false; |
|
| 96 | - } |
|
| 97 | - $e = $most; |
|
| 64 | + // Read directory entries to find the biggest image |
|
| 65 | + $most_pixels = 0; |
|
| 66 | + for ($i = 0; $i < $h["num"]; $i++) { |
|
| 67 | + $entry = substr($ico, 6 + 16 * $i, 16); |
|
| 68 | + if (!$entry || strlen($entry) < 16) |
|
| 69 | + continue; |
|
| 70 | + $e = unpack("Cwidth/" . |
|
| 71 | + "Cheight/" . |
|
| 72 | + "Ccolors/" . |
|
| 73 | + "Czero/" . |
|
| 74 | + "vplanes/" . |
|
| 75 | + "vbpp/" . |
|
| 76 | + "Vsize/" . |
|
| 77 | + "Voffset/", |
|
| 78 | + $entry); |
|
| 79 | + if ($e["width"] == 0) |
|
| 80 | + $e["width"] = 256; |
|
| 81 | + if ($e["height"] == 0) |
|
| 82 | + $e["height"] = 256; |
|
| 83 | + if ($e["zero"] != 0) { |
|
| 84 | + $this->error = "nonzero reserved field"; |
|
| 85 | + return false; |
|
| 86 | + } |
|
| 87 | + $pixels = $e["width"] * $e["height"]; |
|
| 88 | + if ($pixels > $most_pixels) { |
|
| 89 | + $most_pixels = $pixels; |
|
| 90 | + $most = $e; |
|
| 91 | + } |
|
| 92 | + } |
|
| 93 | + if ($most_pixels == 0) { |
|
| 94 | + $this->error = "no pixels"; |
|
| 95 | + return false; |
|
| 96 | + } |
|
| 97 | + $e = $most; |
|
| 98 | 98 | |
| 99 | - // Extract image data |
|
| 100 | - $data = substr($ico, $e["offset"], $e["size"]); |
|
| 101 | - if (!$data || strlen($data) != $e["size"]) { |
|
| 102 | - $this->error = "bad image data"; |
|
| 103 | - return false; |
|
| 104 | - } |
|
| 99 | + // Extract image data |
|
| 100 | + $data = substr($ico, $e["offset"], $e["size"]); |
|
| 101 | + if (!$data || strlen($data) != $e["size"]) { |
|
| 102 | + $this->error = "bad image data"; |
|
| 103 | + return false; |
|
| 104 | + } |
|
| 105 | 105 | |
| 106 | - // See if we can parse it (might be PNG format here) |
|
| 107 | - $i = @imagecreatefromstring($data); |
|
| 108 | - if ($i) { |
|
| 109 | - imagesavealpha($img, true); |
|
| 110 | - return $i; |
|
| 111 | - } |
|
| 106 | + // See if we can parse it (might be PNG format here) |
|
| 107 | + $i = @imagecreatefromstring($data); |
|
| 108 | + if ($i) { |
|
| 109 | + imagesavealpha($img, true); |
|
| 110 | + return $i; |
|
| 111 | + } |
|
| 112 | 112 | |
| 113 | - // Must be a BMP. Parse it ourselves. |
|
| 114 | - $img = imagecreatetruecolor($e["width"], $e["height"]); |
|
| 115 | - imagesavealpha($img, true); |
|
| 116 | - $bg = imagecolorallocatealpha($img, 255, 0, 0, 127); |
|
| 117 | - imagefill($img, 0, 0, $bg); |
|
| 113 | + // Must be a BMP. Parse it ourselves. |
|
| 114 | + $img = imagecreatetruecolor($e["width"], $e["height"]); |
|
| 115 | + imagesavealpha($img, true); |
|
| 116 | + $bg = imagecolorallocatealpha($img, 255, 0, 0, 127); |
|
| 117 | + imagefill($img, 0, 0, $bg); |
|
| 118 | 118 | |
| 119 | - // Skip over the BITMAPCOREHEADER or BITMAPINFOHEADER; |
|
| 120 | - // we'll just assume the palette and pixel data follow |
|
| 121 | - // in the most obvious format as described by the icon |
|
| 122 | - // directory entry. |
|
| 123 | - $bitmapinfo = unpack("Vsize", $data); |
|
| 124 | - if ($bitmapinfo["size"] == 40) { |
|
| 125 | - $info = unpack("Vsize/" . |
|
| 126 | - "Vwidth/" . |
|
| 127 | - "Vheight/" . |
|
| 128 | - "vplanes/" . |
|
| 129 | - "vbpp/" . |
|
| 130 | - "Vcompress/" . |
|
| 131 | - "Vsize/" . |
|
| 132 | - "Vxres/" . |
|
| 133 | - "Vyres/" . |
|
| 134 | - "Vpalcolors/" . |
|
| 135 | - "Vimpcolors/", $data); |
|
| 136 | - if ($e["bpp"] == 0) { |
|
| 137 | - $e["bpp"] = $info["bpp"]; |
|
| 138 | - } |
|
| 139 | - } |
|
| 140 | - $data = substr($data, $bitmapinfo["size"]); |
|
| 119 | + // Skip over the BITMAPCOREHEADER or BITMAPINFOHEADER; |
|
| 120 | + // we'll just assume the palette and pixel data follow |
|
| 121 | + // in the most obvious format as described by the icon |
|
| 122 | + // directory entry. |
|
| 123 | + $bitmapinfo = unpack("Vsize", $data); |
|
| 124 | + if ($bitmapinfo["size"] == 40) { |
|
| 125 | + $info = unpack("Vsize/" . |
|
| 126 | + "Vwidth/" . |
|
| 127 | + "Vheight/" . |
|
| 128 | + "vplanes/" . |
|
| 129 | + "vbpp/" . |
|
| 130 | + "Vcompress/" . |
|
| 131 | + "Vsize/" . |
|
| 132 | + "Vxres/" . |
|
| 133 | + "Vyres/" . |
|
| 134 | + "Vpalcolors/" . |
|
| 135 | + "Vimpcolors/", $data); |
|
| 136 | + if ($e["bpp"] == 0) { |
|
| 137 | + $e["bpp"] = $info["bpp"]; |
|
| 138 | + } |
|
| 139 | + } |
|
| 140 | + $data = substr($data, $bitmapinfo["size"]); |
|
| 141 | 141 | |
| 142 | - $height = $e["height"]; |
|
| 143 | - $width = $e["width"]; |
|
| 144 | - $bpp = $e["bpp"]; |
|
| 142 | + $height = $e["height"]; |
|
| 143 | + $width = $e["width"]; |
|
| 144 | + $bpp = $e["bpp"]; |
|
| 145 | 145 | |
| 146 | - // For indexed images, we only support 1, 4, or 8 BPP |
|
| 147 | - switch ($bpp) { |
|
| 148 | - case 1: |
|
| 149 | - case 4: |
|
| 150 | - case 8: |
|
| 151 | - $indexed = 1; |
|
| 152 | - break; |
|
| 153 | - case 24: |
|
| 154 | - case 32: |
|
| 155 | - $indexed = 0; |
|
| 156 | - break; |
|
| 157 | - default: |
|
| 158 | - $this->error = "bad BPP $bpp"; |
|
| 159 | - return false; |
|
| 160 | - } |
|
| 146 | + // For indexed images, we only support 1, 4, or 8 BPP |
|
| 147 | + switch ($bpp) { |
|
| 148 | + case 1: |
|
| 149 | + case 4: |
|
| 150 | + case 8: |
|
| 151 | + $indexed = 1; |
|
| 152 | + break; |
|
| 153 | + case 24: |
|
| 154 | + case 32: |
|
| 155 | + $indexed = 0; |
|
| 156 | + break; |
|
| 157 | + default: |
|
| 158 | + $this->error = "bad BPP $bpp"; |
|
| 159 | + return false; |
|
| 160 | + } |
|
| 161 | 161 | |
| 162 | - $offset = 0; |
|
| 163 | - if ($indexed) { |
|
| 164 | - $palette = array(); |
|
| 165 | - $this->all_transparent = 1; |
|
| 166 | - for ($i = 0; $i < (1 << $bpp); $i++) { |
|
| 167 | - $entry = substr($data, $i * 4, 4); |
|
| 168 | - $palette[$i] = $this->get_color($entry, $img); |
|
| 169 | - } |
|
| 170 | - $offset = $i * 4; |
|
| 162 | + $offset = 0; |
|
| 163 | + if ($indexed) { |
|
| 164 | + $palette = array(); |
|
| 165 | + $this->all_transparent = 1; |
|
| 166 | + for ($i = 0; $i < (1 << $bpp); $i++) { |
|
| 167 | + $entry = substr($data, $i * 4, 4); |
|
| 168 | + $palette[$i] = $this->get_color($entry, $img); |
|
| 169 | + } |
|
| 170 | + $offset = $i * 4; |
|
| 171 | 171 | |
| 172 | - // Hack for some icons: if everything was transparent, |
|
| 173 | - // discard alpha channel. |
|
| 174 | - if ($this->all_transparent) { |
|
| 175 | - for ($i = 0; $i < (1 << $bpp); $i++) { |
|
| 176 | - $palette[$i] &= 0xffffff; |
|
| 177 | - } |
|
| 178 | - } |
|
| 179 | - } |
|
| 172 | + // Hack for some icons: if everything was transparent, |
|
| 173 | + // discard alpha channel. |
|
| 174 | + if ($this->all_transparent) { |
|
| 175 | + for ($i = 0; $i < (1 << $bpp); $i++) { |
|
| 176 | + $palette[$i] &= 0xffffff; |
|
| 177 | + } |
|
| 178 | + } |
|
| 179 | + } |
|
| 180 | 180 | |
| 181 | - // Assume image data follows in bottom-up order. |
|
| 182 | - // First the "XOR" image |
|
| 183 | - if ((strlen($data) - $offset) < ($bpp * $height * $width / 8)) { |
|
| 184 | - $this->error = "short data"; |
|
| 185 | - return false; |
|
| 186 | - } |
|
| 187 | - $XOR = array(); |
|
| 188 | - for ($y = $height - 1; $y >= 0; $y--) { |
|
| 189 | - $x = 0; |
|
| 190 | - while ($x < $width) { |
|
| 191 | - if (!$indexed) { |
|
| 192 | - $bytes = $bpp / 8; |
|
| 193 | - $entry = substr($data, $offset, $bytes); |
|
| 194 | - $pixel = $this->get_color($entry, $img); |
|
| 195 | - $XOR[$y][$x] = $pixel; |
|
| 196 | - $x++; |
|
| 197 | - $offset += $bytes; |
|
| 198 | - } elseif ($bpp == 1) { |
|
| 199 | - $p = ord($data[$offset]); |
|
| 200 | - for ($b = 0x80; $b > 0; $b >>= 1) { |
|
| 201 | - if ($p & $b) { |
|
| 202 | - $pixel = $palette[1]; |
|
| 203 | - } else { |
|
| 204 | - $pixel = $palette[0]; |
|
| 205 | - } |
|
| 206 | - $XOR[$y][$x] = $pixel; |
|
| 207 | - $x++; |
|
| 208 | - } |
|
| 209 | - $offset++; |
|
| 210 | - } elseif ($bpp == 4) { |
|
| 211 | - $p = ord($data[$offset]); |
|
| 212 | - $pixel1 = $palette[$p >> 4]; |
|
| 213 | - $pixel2 = $palette[$p & 0x0f]; |
|
| 214 | - $XOR[$y][$x] = $pixel1; |
|
| 215 | - $XOR[$y][$x+1] = $pixel2; |
|
| 216 | - $x += 2; |
|
| 217 | - $offset++; |
|
| 218 | - } elseif ($bpp == 8) { |
|
| 219 | - $pixel = $palette[ord($data[$offset])]; |
|
| 220 | - $XOR[$y][$x] = $pixel; |
|
| 221 | - $x += 1; |
|
| 222 | - $offset++; |
|
| 223 | - } else { |
|
| 224 | - $this->error = "bad BPP"; |
|
| 225 | - return false; |
|
| 226 | - } |
|
| 227 | - } |
|
| 228 | - // End of row padding |
|
| 229 | - while ($offset & 3) |
|
| 230 | - $offset++; |
|
| 231 | - } |
|
| 181 | + // Assume image data follows in bottom-up order. |
|
| 182 | + // First the "XOR" image |
|
| 183 | + if ((strlen($data) - $offset) < ($bpp * $height * $width / 8)) { |
|
| 184 | + $this->error = "short data"; |
|
| 185 | + return false; |
|
| 186 | + } |
|
| 187 | + $XOR = array(); |
|
| 188 | + for ($y = $height - 1; $y >= 0; $y--) { |
|
| 189 | + $x = 0; |
|
| 190 | + while ($x < $width) { |
|
| 191 | + if (!$indexed) { |
|
| 192 | + $bytes = $bpp / 8; |
|
| 193 | + $entry = substr($data, $offset, $bytes); |
|
| 194 | + $pixel = $this->get_color($entry, $img); |
|
| 195 | + $XOR[$y][$x] = $pixel; |
|
| 196 | + $x++; |
|
| 197 | + $offset += $bytes; |
|
| 198 | + } elseif ($bpp == 1) { |
|
| 199 | + $p = ord($data[$offset]); |
|
| 200 | + for ($b = 0x80; $b > 0; $b >>= 1) { |
|
| 201 | + if ($p & $b) { |
|
| 202 | + $pixel = $palette[1]; |
|
| 203 | + } else { |
|
| 204 | + $pixel = $palette[0]; |
|
| 205 | + } |
|
| 206 | + $XOR[$y][$x] = $pixel; |
|
| 207 | + $x++; |
|
| 208 | + } |
|
| 209 | + $offset++; |
|
| 210 | + } elseif ($bpp == 4) { |
|
| 211 | + $p = ord($data[$offset]); |
|
| 212 | + $pixel1 = $palette[$p >> 4]; |
|
| 213 | + $pixel2 = $palette[$p & 0x0f]; |
|
| 214 | + $XOR[$y][$x] = $pixel1; |
|
| 215 | + $XOR[$y][$x+1] = $pixel2; |
|
| 216 | + $x += 2; |
|
| 217 | + $offset++; |
|
| 218 | + } elseif ($bpp == 8) { |
|
| 219 | + $pixel = $palette[ord($data[$offset])]; |
|
| 220 | + $XOR[$y][$x] = $pixel; |
|
| 221 | + $x += 1; |
|
| 222 | + $offset++; |
|
| 223 | + } else { |
|
| 224 | + $this->error = "bad BPP"; |
|
| 225 | + return false; |
|
| 226 | + } |
|
| 227 | + } |
|
| 228 | + // End of row padding |
|
| 229 | + while ($offset & 3) |
|
| 230 | + $offset++; |
|
| 231 | + } |
|
| 232 | 232 | |
| 233 | - // Now the "AND" image, which is 1 bit per pixel. Ignore |
|
| 234 | - // if some of our image data already had alpha values, |
|
| 235 | - // or if there isn't enough data left. |
|
| 236 | - if ($this->had_alpha || |
|
| 237 | - ((strlen($data) - $offset) < ($height * $width / 8))) { |
|
| 238 | - // Just return what we've got |
|
| 239 | - for ($y = 0; $y < $height; $y++) { |
|
| 240 | - for ($x = 0; $x < $width; $x++) { |
|
| 241 | - imagesetpixel($img, $x, $y, |
|
| 242 | - $XOR[$y][$x]); |
|
| 243 | - } |
|
| 244 | - } |
|
| 245 | - return $img; |
|
| 246 | - } |
|
| 233 | + // Now the "AND" image, which is 1 bit per pixel. Ignore |
|
| 234 | + // if some of our image data already had alpha values, |
|
| 235 | + // or if there isn't enough data left. |
|
| 236 | + if ($this->had_alpha || |
|
| 237 | + ((strlen($data) - $offset) < ($height * $width / 8))) { |
|
| 238 | + // Just return what we've got |
|
| 239 | + for ($y = 0; $y < $height; $y++) { |
|
| 240 | + for ($x = 0; $x < $width; $x++) { |
|
| 241 | + imagesetpixel($img, $x, $y, |
|
| 242 | + $XOR[$y][$x]); |
|
| 243 | + } |
|
| 244 | + } |
|
| 245 | + return $img; |
|
| 246 | + } |
|
| 247 | 247 | |
| 248 | - // Mask what we have with the "AND" image |
|
| 249 | - for ($y = $height - 1; $y >= 0; $y--) { |
|
| 250 | - $x = 0; |
|
| 251 | - while ($x < $width) { |
|
| 252 | - for ($b = 0x80; |
|
| 253 | - $b > 0 && $x < $width; $b >>= 1) { |
|
| 254 | - if (!(ord($data[$offset]) & $b)) { |
|
| 255 | - imagesetpixel($img, $x, $y, |
|
| 256 | - $XOR[$y][$x]); |
|
| 257 | - } |
|
| 258 | - $x++; |
|
| 259 | - } |
|
| 260 | - $offset++; |
|
| 261 | - } |
|
| 248 | + // Mask what we have with the "AND" image |
|
| 249 | + for ($y = $height - 1; $y >= 0; $y--) { |
|
| 250 | + $x = 0; |
|
| 251 | + while ($x < $width) { |
|
| 252 | + for ($b = 0x80; |
|
| 253 | + $b > 0 && $x < $width; $b >>= 1) { |
|
| 254 | + if (!(ord($data[$offset]) & $b)) { |
|
| 255 | + imagesetpixel($img, $x, $y, |
|
| 256 | + $XOR[$y][$x]); |
|
| 257 | + } |
|
| 258 | + $x++; |
|
| 259 | + } |
|
| 260 | + $offset++; |
|
| 261 | + } |
|
| 262 | 262 | |
| 263 | - // End of row padding |
|
| 264 | - while ($offset & 3) |
|
| 265 | - $offset++; |
|
| 266 | - } |
|
| 267 | - return $img; |
|
| 268 | - } |
|
| 263 | + // End of row padding |
|
| 264 | + while ($offset & 3) |
|
| 265 | + $offset++; |
|
| 266 | + } |
|
| 267 | + return $img; |
|
| 268 | + } |
|
| 269 | 269 | } |
| 270 | 270 | ?> |
| 271 | 271 | \ No newline at end of file |
@@ -67,13 +67,13 @@ discard block |
||
| 67 | 67 | $entry = substr($ico, 6 + 16 * $i, 16); |
| 68 | 68 | if (!$entry || strlen($entry) < 16) |
| 69 | 69 | continue; |
| 70 | - $e = unpack("Cwidth/" . |
|
| 71 | - "Cheight/" . |
|
| 72 | - "Ccolors/" . |
|
| 73 | - "Czero/" . |
|
| 74 | - "vplanes/" . |
|
| 75 | - "vbpp/" . |
|
| 76 | - "Vsize/" . |
|
| 70 | + $e = unpack("Cwidth/". |
|
| 71 | + "Cheight/". |
|
| 72 | + "Ccolors/". |
|
| 73 | + "Czero/". |
|
| 74 | + "vplanes/". |
|
| 75 | + "vbpp/". |
|
| 76 | + "Vsize/". |
|
| 77 | 77 | "Voffset/", |
| 78 | 78 | $entry); |
| 79 | 79 | if ($e["width"] == 0) |
@@ -122,16 +122,16 @@ discard block |
||
| 122 | 122 | // directory entry. |
| 123 | 123 | $bitmapinfo = unpack("Vsize", $data); |
| 124 | 124 | if ($bitmapinfo["size"] == 40) { |
| 125 | - $info = unpack("Vsize/" . |
|
| 126 | - "Vwidth/" . |
|
| 127 | - "Vheight/" . |
|
| 128 | - "vplanes/" . |
|
| 129 | - "vbpp/" . |
|
| 130 | - "Vcompress/" . |
|
| 131 | - "Vsize/" . |
|
| 132 | - "Vxres/" . |
|
| 133 | - "Vyres/" . |
|
| 134 | - "Vpalcolors/" . |
|
| 125 | + $info = unpack("Vsize/". |
|
| 126 | + "Vwidth/". |
|
| 127 | + "Vheight/". |
|
| 128 | + "vplanes/". |
|
| 129 | + "vbpp/". |
|
| 130 | + "Vcompress/". |
|
| 131 | + "Vsize/". |
|
| 132 | + "Vxres/". |
|
| 133 | + "Vyres/". |
|
| 134 | + "Vpalcolors/". |
|
| 135 | 135 | "Vimpcolors/", $data); |
| 136 | 136 | if ($e["bpp"] == 0) { |
| 137 | 137 | $e["bpp"] = $info["bpp"]; |
@@ -212,7 +212,7 @@ discard block |
||
| 212 | 212 | $pixel1 = $palette[$p >> 4]; |
| 213 | 213 | $pixel2 = $palette[$p & 0x0f]; |
| 214 | 214 | $XOR[$y][$x] = $pixel1; |
| 215 | - $XOR[$y][$x+1] = $pixel2; |
|
| 215 | + $XOR[$y][$x + 1] = $pixel2; |
|
| 216 | 216 | $x += 2; |
| 217 | 217 | $offset++; |
| 218 | 218 | } elseif ($bpp == 8) { |
@@ -24,13 +24,15 @@ discard block |
||
| 24 | 24 | $r = ord($str[2]); |
| 25 | 25 | if (strlen($str) > 3) { |
| 26 | 26 | $a = 127 - (ord($str[3]) / 2); |
| 27 | - if ($a != 0 && $a != 127) |
|
| 28 | - $this->had_alpha = 1; |
|
| 27 | + if ($a != 0 && $a != 127) { |
|
| 28 | + $this->had_alpha = 1; |
|
| 29 | + } |
|
| 29 | 30 | } else { |
| 30 | 31 | $a = 0; |
| 31 | 32 | } |
| 32 | - if ($a != 127) |
|
| 33 | - $this->all_transaprent = 0; |
|
| 33 | + if ($a != 127) { |
|
| 34 | + $this->all_transaprent = 0; |
|
| 35 | + } |
|
| 34 | 36 | return imagecolorallocatealpha($img, $r, $g, $b, $a); |
| 35 | 37 | } |
| 36 | 38 | |
@@ -65,8 +67,9 @@ discard block |
||
| 65 | 67 | $most_pixels = 0; |
| 66 | 68 | for ($i = 0; $i < $h["num"]; $i++) { |
| 67 | 69 | $entry = substr($ico, 6 + 16 * $i, 16); |
| 68 | - if (!$entry || strlen($entry) < 16) |
|
| 69 | - continue; |
|
| 70 | + if (!$entry || strlen($entry) < 16) { |
|
| 71 | + continue; |
|
| 72 | + } |
|
| 70 | 73 | $e = unpack("Cwidth/" . |
| 71 | 74 | "Cheight/" . |
| 72 | 75 | "Ccolors/" . |
@@ -76,10 +79,12 @@ discard block |
||
| 76 | 79 | "Vsize/" . |
| 77 | 80 | "Voffset/", |
| 78 | 81 | $entry); |
| 79 | - if ($e["width"] == 0) |
|
| 80 | - $e["width"] = 256; |
|
| 81 | - if ($e["height"] == 0) |
|
| 82 | - $e["height"] = 256; |
|
| 82 | + if ($e["width"] == 0) { |
|
| 83 | + $e["width"] = 256; |
|
| 84 | + } |
|
| 85 | + if ($e["height"] == 0) { |
|
| 86 | + $e["height"] = 256; |
|
| 87 | + } |
|
| 83 | 88 | if ($e["zero"] != 0) { |
| 84 | 89 | $this->error = "nonzero reserved field"; |
| 85 | 90 | return false; |
@@ -226,8 +231,9 @@ discard block |
||
| 226 | 231 | } |
| 227 | 232 | } |
| 228 | 233 | // End of row padding |
| 229 | - while ($offset & 3) |
|
| 230 | - $offset++; |
|
| 234 | + while ($offset & 3) { |
|
| 235 | + $offset++; |
|
| 236 | + } |
|
| 231 | 237 | } |
| 232 | 238 | |
| 233 | 239 | // Now the "AND" image, which is 1 bit per pixel. Ignore |
@@ -261,8 +267,9 @@ discard block |
||
| 261 | 267 | } |
| 262 | 268 | |
| 263 | 269 | // End of row padding |
| 264 | - while ($offset & 3) |
|
| 265 | - $offset++; |
|
| 270 | + while ($offset & 3) { |
|
| 271 | + $offset++; |
|
| 272 | + } |
|
| 266 | 273 | } |
| 267 | 274 | return $img; |
| 268 | 275 | } |
@@ -4,17 +4,17 @@ |
||
| 4 | 4 | require_once "jimIcon.php"; |
| 5 | 5 | |
| 6 | 6 | class floIconIcon { |
| 7 | - function getImageResource() { |
|
| 8 | - return $this->img; |
|
| 9 | - } |
|
| 7 | + function getImageResource() { |
|
| 8 | + return $this->img; |
|
| 9 | + } |
|
| 10 | 10 | } |
| 11 | 11 | |
| 12 | 12 | class floIcon { |
| 13 | - function readICO($file) { |
|
| 14 | - $jim = new jimIcon(); |
|
| 15 | - $icon = new floIconIcon(); |
|
| 16 | - $icon->img = $jim->fromiconstring(file_get_contents($file)); |
|
| 17 | - $this->images = array($icon); |
|
| 18 | - } |
|
| 13 | + function readICO($file) { |
|
| 14 | + $jim = new jimIcon(); |
|
| 15 | + $icon = new floIconIcon(); |
|
| 16 | + $icon->img = $jim->fromiconstring(file_get_contents($file)); |
|
| 17 | + $this->images = array($icon); |
|
| 18 | + } |
|
| 19 | 19 | } |
| 20 | 20 | ?> |
@@ -45,10 +45,10 @@ |
||
| 45 | 45 | // Supported output formats |
| 46 | 46 | |
| 47 | 47 | define('QR_FORMAT_TEXT', 0);
|
| 48 | - define('QR_FORMAT_PNG', 1);
|
|
| 48 | + define('QR_FORMAT_PNG', 1);
|
|
| 49 | 49 | |
| 50 | 50 | class qrstr {
|
| 51 | 51 | public static function set(&$srctab, $x, $y, $repl, $replLen = false) {
|
| 52 | - $srctab[$y] = substr_replace($srctab[$y], ($replLen !== false)?substr($repl,0,$replLen):$repl, $x, ($replLen !== false)?$replLen:strlen($repl)); |
|
| 52 | + $srctab[$y] = substr_replace($srctab[$y], ($replLen !== false) ?substr($repl, 0, $replLen) : $repl, $x, ($replLen !== false) ? $replLen : strlen($repl)); |
|
| 53 | 53 | } |
| 54 | 54 | } |
| 55 | 55 | \ No newline at end of file |
@@ -25,46 +25,46 @@ |
||
| 25 | 25 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 26 | 26 | */ |
| 27 | 27 | |
| 28 | - $QR_BASEDIR = dirname(__FILE__).DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR; |
|
| 29 | - $QR_TOOLSDIR = dirname(__FILE__).DIRECTORY_SEPARATOR; |
|
| 28 | + $QR_BASEDIR = dirname(__FILE__).DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR; |
|
| 29 | + $QR_TOOLSDIR = dirname(__FILE__).DIRECTORY_SEPARATOR; |
|
| 30 | 30 | |
| 31 | - $outputFile = $QR_BASEDIR.'phpqrcode.php'; |
|
| 31 | + $outputFile = $QR_BASEDIR.'phpqrcode.php'; |
|
| 32 | 32 | |
| 33 | - // Required libs |
|
| 33 | + // Required libs |
|
| 34 | 34 | |
| 35 | - $fileList = array( |
|
| 36 | - $QR_BASEDIR.'qrconst.php', |
|
| 37 | - $QR_TOOLSDIR.'merged_config.php', |
|
| 38 | - $QR_BASEDIR.'qrtools.php', |
|
| 39 | - $QR_BASEDIR.'qrspec.php', |
|
| 40 | - $QR_BASEDIR.'qrimage.php', |
|
| 41 | - $QR_BASEDIR.'qrinput.php', |
|
| 42 | - $QR_BASEDIR.'qrbitstream.php', |
|
| 43 | - $QR_BASEDIR.'qrsplit.php', |
|
| 44 | - $QR_BASEDIR.'qrrscode.php', |
|
| 45 | - $QR_BASEDIR.'qrmask.php', |
|
| 46 | - $QR_BASEDIR.'qrencode.php' |
|
| 47 | - ); |
|
| 35 | + $fileList = array( |
|
| 36 | + $QR_BASEDIR.'qrconst.php', |
|
| 37 | + $QR_TOOLSDIR.'merged_config.php', |
|
| 38 | + $QR_BASEDIR.'qrtools.php', |
|
| 39 | + $QR_BASEDIR.'qrspec.php', |
|
| 40 | + $QR_BASEDIR.'qrimage.php', |
|
| 41 | + $QR_BASEDIR.'qrinput.php', |
|
| 42 | + $QR_BASEDIR.'qrbitstream.php', |
|
| 43 | + $QR_BASEDIR.'qrsplit.php', |
|
| 44 | + $QR_BASEDIR.'qrrscode.php', |
|
| 45 | + $QR_BASEDIR.'qrmask.php', |
|
| 46 | + $QR_BASEDIR.'qrencode.php' |
|
| 47 | + ); |
|
| 48 | 48 | |
| 49 | - $headerFile = $QR_TOOLSDIR.'merged_header.php'; |
|
| 50 | - $versionFile = $QR_BASEDIR.'VERSION'; |
|
| 49 | + $headerFile = $QR_TOOLSDIR.'merged_header.php'; |
|
| 50 | + $versionFile = $QR_BASEDIR.'VERSION'; |
|
| 51 | 51 | |
| 52 | - $outputCode = ''; |
|
| 52 | + $outputCode = ''; |
|
| 53 | 53 | |
| 54 | - foreach($fileList as $fileName) {
|
|
| 55 | - $outputCode .= "\n\n".'//---- '.basename($fileName).' -----------------------------'."\n\n"; |
|
| 56 | - $anotherCode = file_get_contents($fileName); |
|
| 57 | - $anotherCode = preg_replace ('/^<\?php/', '', $anotherCode);
|
|
| 58 | - $anotherCode = preg_replace ('/\?>\*$/', '', $anotherCode);
|
|
| 59 | - $outputCode .= "\n\n".$anotherCode."\n\n"; |
|
| 60 | - } |
|
| 54 | + foreach($fileList as $fileName) {
|
|
| 55 | + $outputCode .= "\n\n".'//---- '.basename($fileName).' -----------------------------'."\n\n"; |
|
| 56 | + $anotherCode = file_get_contents($fileName); |
|
| 57 | + $anotherCode = preg_replace ('/^<\?php/', '', $anotherCode);
|
|
| 58 | + $anotherCode = preg_replace ('/\?>\*$/', '', $anotherCode);
|
|
| 59 | + $outputCode .= "\n\n".$anotherCode."\n\n"; |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | 62 | $versionDataEx = explode("\n", file_get_contents($versionFile));
|
| 63 | 63 | |
| 64 | - $outputContents = file_get_contents($headerFile); |
|
| 65 | - $outputContents .= "\n\n/*\n * Version: ".trim($versionDataEx[0])."\n * Build: ".trim($versionDataEx[1])."\n */\n\n"; |
|
| 66 | - $outputContents .= $outputCode; |
|
| 64 | + $outputContents = file_get_contents($headerFile); |
|
| 65 | + $outputContents .= "\n\n/*\n * Version: ".trim($versionDataEx[0])."\n * Build: ".trim($versionDataEx[1])."\n */\n\n"; |
|
| 66 | + $outputContents .= $outputCode; |
|
| 67 | 67 | |
| 68 | - file_put_contents($outputFile, $outputContents); |
|
| 68 | + file_put_contents($outputFile, $outputContents); |
|
| 69 | 69 | |
| 70 | - |
|
| 71 | 70 | \ No newline at end of file |
| 71 | + |
|
| 72 | 72 | \ No newline at end of file |
@@ -51,11 +51,11 @@ |
||
| 51 | 51 | |
| 52 | 52 | $outputCode = ''; |
| 53 | 53 | |
| 54 | - foreach($fileList as $fileName) {
|
|
| 54 | + foreach ($fileList as $fileName) {
|
|
| 55 | 55 | $outputCode .= "\n\n".'//---- '.basename($fileName).' -----------------------------'."\n\n"; |
| 56 | 56 | $anotherCode = file_get_contents($fileName); |
| 57 | - $anotherCode = preg_replace ('/^<\?php/', '', $anotherCode);
|
|
| 58 | - $anotherCode = preg_replace ('/\?>\*$/', '', $anotherCode);
|
|
| 57 | + $anotherCode = preg_replace('/^<\?php/', '', $anotherCode);
|
|
| 58 | + $anotherCode = preg_replace('/\?>\*$/', '', $anotherCode);
|
|
| 59 | 59 | $outputCode .= "\n\n".$anotherCode."\n\n"; |
| 60 | 60 | } |
| 61 | 61 | |
@@ -5,13 +5,13 @@ |
||
| 5 | 5 | * Config file, tuned-up for merged verion |
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | - define('QR_CACHEABLE', false); // use cache - more disk reads but less CPU power, masks and format templates are stored there
|
|
| 9 | - define('QR_CACHE_DIR', false); // used when QR_CACHEABLE === true
|
|
| 10 | - define('QR_LOG_DIR', false); // default error logs dir
|
|
| 8 | + define('QR_CACHEABLE', false); // use cache - more disk reads but less CPU power, masks and format templates are stored there
|
|
| 9 | + define('QR_CACHE_DIR', false); // used when QR_CACHEABLE === true
|
|
| 10 | + define('QR_LOG_DIR', false); // default error logs dir
|
|
| 11 | 11 | |
| 12 | - 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
|
|
| 13 | - 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
|
|
| 14 | - define('QR_DEFAULT_MASK', 2); // when QR_FIND_BEST_MASK === false
|
|
| 12 | + 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
|
|
| 13 | + 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
|
|
| 14 | + define('QR_DEFAULT_MASK', 2); // when QR_FIND_BEST_MASK === false
|
|
| 15 | 15 | |
| 16 | - 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
|
|
| 17 | - |
|
| 18 | 16 | \ No newline at end of file |
| 17 | + 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
|
|
| 18 | + |
|
| 19 | 19 | \ No newline at end of file |
@@ -5,13 +5,13 @@ |
||
| 5 | 5 | * Config file, tuned-up for merged verion |
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | - define('QR_CACHEABLE', false); // use cache - more disk reads but less CPU power, masks and format templates are stored there
|
|
| 9 | - define('QR_CACHE_DIR', false); // used when QR_CACHEABLE === true
|
|
| 10 | - define('QR_LOG_DIR', false); // default error logs dir
|
|
| 8 | + define('QR_CACHEABLE', false); // use cache - more disk reads but less CPU power, masks and format templates are stored there
|
|
| 9 | + define('QR_CACHE_DIR', false); // used when QR_CACHEABLE === true
|
|
| 10 | + define('QR_LOG_DIR', false); // default error logs dir
|
|
| 11 | 11 | |
| 12 | - 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
|
|
| 13 | - 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
|
|
| 14 | - define('QR_DEFAULT_MASK', 2); // when QR_FIND_BEST_MASK === false
|
|
| 12 | + 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
|
|
| 13 | + 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
|
|
| 14 | + define('QR_DEFAULT_MASK', 2); // when QR_FIND_BEST_MASK === false
|
|
| 15 | 15 | |
| 16 | - 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
|
|
| 16 | + 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
|
|
| 17 | 17 | |
| 18 | 18 | \ No newline at end of file |
@@ -25,156 +25,156 @@ |
||
| 25 | 25 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 26 | 26 | */ |
| 27 | 27 | |
| 28 | - class QRbitstream {
|
|
| 28 | + class QRbitstream {
|
|
| 29 | 29 | |
| 30 | - public $data = array(); |
|
| 30 | + public $data = array(); |
|
| 31 | 31 | |
| 32 | - //---------------------------------------------------------------------- |
|
| 33 | - public function size() |
|
| 34 | - {
|
|
| 35 | - return count($this->data); |
|
| 36 | - } |
|
| 32 | + //---------------------------------------------------------------------- |
|
| 33 | + public function size() |
|
| 34 | + {
|
|
| 35 | + return count($this->data); |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | - //---------------------------------------------------------------------- |
|
| 39 | - public function allocate($setLength) |
|
| 40 | - {
|
|
| 41 | - $this->data = array_fill(0, $setLength, 0); |
|
| 42 | - return 0; |
|
| 43 | - } |
|
| 38 | + //---------------------------------------------------------------------- |
|
| 39 | + public function allocate($setLength) |
|
| 40 | + {
|
|
| 41 | + $this->data = array_fill(0, $setLength, 0); |
|
| 42 | + return 0; |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - //---------------------------------------------------------------------- |
|
| 46 | - public static function newFromNum($bits, $num) |
|
| 47 | - {
|
|
| 48 | - $bstream = new QRbitstream(); |
|
| 49 | - $bstream->allocate($bits); |
|
| 45 | + //---------------------------------------------------------------------- |
|
| 46 | + public static function newFromNum($bits, $num) |
|
| 47 | + {
|
|
| 48 | + $bstream = new QRbitstream(); |
|
| 49 | + $bstream->allocate($bits); |
|
| 50 | 50 | |
| 51 | - $mask = 1 << ($bits - 1); |
|
| 52 | - for($i=0; $i<$bits; $i++) {
|
|
| 53 | - if($num & $mask) {
|
|
| 54 | - $bstream->data[$i] = 1; |
|
| 55 | - } else {
|
|
| 56 | - $bstream->data[$i] = 0; |
|
| 57 | - } |
|
| 58 | - $mask = $mask >> 1; |
|
| 59 | - } |
|
| 51 | + $mask = 1 << ($bits - 1); |
|
| 52 | + for($i=0; $i<$bits; $i++) {
|
|
| 53 | + if($num & $mask) {
|
|
| 54 | + $bstream->data[$i] = 1; |
|
| 55 | + } else {
|
|
| 56 | + $bstream->data[$i] = 0; |
|
| 57 | + } |
|
| 58 | + $mask = $mask >> 1; |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - return $bstream; |
|
| 62 | - } |
|
| 61 | + return $bstream; |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - //---------------------------------------------------------------------- |
|
| 65 | - public static function newFromBytes($size, $data) |
|
| 66 | - {
|
|
| 67 | - $bstream = new QRbitstream(); |
|
| 68 | - $bstream->allocate($size * 8); |
|
| 69 | - $p=0; |
|
| 64 | + //---------------------------------------------------------------------- |
|
| 65 | + public static function newFromBytes($size, $data) |
|
| 66 | + {
|
|
| 67 | + $bstream = new QRbitstream(); |
|
| 68 | + $bstream->allocate($size * 8); |
|
| 69 | + $p=0; |
|
| 70 | 70 | |
| 71 | - for($i=0; $i<$size; $i++) {
|
|
| 72 | - $mask = 0x80; |
|
| 73 | - for($j=0; $j<8; $j++) {
|
|
| 74 | - if($data[$i] & $mask) {
|
|
| 75 | - $bstream->data[$p] = 1; |
|
| 76 | - } else {
|
|
| 77 | - $bstream->data[$p] = 0; |
|
| 78 | - } |
|
| 79 | - $p++; |
|
| 80 | - $mask = $mask >> 1; |
|
| 81 | - } |
|
| 82 | - } |
|
| 71 | + for($i=0; $i<$size; $i++) {
|
|
| 72 | + $mask = 0x80; |
|
| 73 | + for($j=0; $j<8; $j++) {
|
|
| 74 | + if($data[$i] & $mask) {
|
|
| 75 | + $bstream->data[$p] = 1; |
|
| 76 | + } else {
|
|
| 77 | + $bstream->data[$p] = 0; |
|
| 78 | + } |
|
| 79 | + $p++; |
|
| 80 | + $mask = $mask >> 1; |
|
| 81 | + } |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | - return $bstream; |
|
| 85 | - } |
|
| 84 | + return $bstream; |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | - //---------------------------------------------------------------------- |
|
| 88 | - public function append(QRbitstream $arg) |
|
| 89 | - {
|
|
| 90 | - if (is_null($arg)) {
|
|
| 91 | - return -1; |
|
| 92 | - } |
|
| 87 | + //---------------------------------------------------------------------- |
|
| 88 | + public function append(QRbitstream $arg) |
|
| 89 | + {
|
|
| 90 | + if (is_null($arg)) {
|
|
| 91 | + return -1; |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - if($arg->size() == 0) {
|
|
| 95 | - return 0; |
|
| 96 | - } |
|
| 94 | + if($arg->size() == 0) {
|
|
| 95 | + return 0; |
|
| 96 | + } |
|
| 97 | 97 | |
| 98 | - if($this->size() == 0) {
|
|
| 99 | - $this->data = $arg->data; |
|
| 100 | - return 0; |
|
| 101 | - } |
|
| 98 | + if($this->size() == 0) {
|
|
| 99 | + $this->data = $arg->data; |
|
| 100 | + return 0; |
|
| 101 | + } |
|
| 102 | 102 | |
| 103 | - $this->data = array_values(array_merge($this->data, $arg->data)); |
|
| 103 | + $this->data = array_values(array_merge($this->data, $arg->data)); |
|
| 104 | 104 | |
| 105 | - return 0; |
|
| 106 | - } |
|
| 105 | + return 0; |
|
| 106 | + } |
|
| 107 | 107 | |
| 108 | - //---------------------------------------------------------------------- |
|
| 109 | - public function appendNum($bits, $num) |
|
| 110 | - {
|
|
| 111 | - if ($bits == 0) |
|
| 112 | - return 0; |
|
| 108 | + //---------------------------------------------------------------------- |
|
| 109 | + public function appendNum($bits, $num) |
|
| 110 | + {
|
|
| 111 | + if ($bits == 0) |
|
| 112 | + return 0; |
|
| 113 | 113 | |
| 114 | - $b = QRbitstream::newFromNum($bits, $num); |
|
| 114 | + $b = QRbitstream::newFromNum($bits, $num); |
|
| 115 | 115 | |
| 116 | - if(is_null($b)) |
|
| 117 | - return -1; |
|
| 116 | + if(is_null($b)) |
|
| 117 | + return -1; |
|
| 118 | 118 | |
| 119 | - $ret = $this->append($b); |
|
| 120 | - unset($b); |
|
| 119 | + $ret = $this->append($b); |
|
| 120 | + unset($b); |
|
| 121 | 121 | |
| 122 | - return $ret; |
|
| 123 | - } |
|
| 122 | + return $ret; |
|
| 123 | + } |
|
| 124 | 124 | |
| 125 | - //---------------------------------------------------------------------- |
|
| 126 | - public function appendBytes($size, $data) |
|
| 127 | - {
|
|
| 128 | - if ($size == 0) |
|
| 129 | - return 0; |
|
| 125 | + //---------------------------------------------------------------------- |
|
| 126 | + public function appendBytes($size, $data) |
|
| 127 | + {
|
|
| 128 | + if ($size == 0) |
|
| 129 | + return 0; |
|
| 130 | 130 | |
| 131 | - $b = QRbitstream::newFromBytes($size, $data); |
|
| 131 | + $b = QRbitstream::newFromBytes($size, $data); |
|
| 132 | 132 | |
| 133 | - if(is_null($b)) |
|
| 134 | - return -1; |
|
| 133 | + if(is_null($b)) |
|
| 134 | + return -1; |
|
| 135 | 135 | |
| 136 | - $ret = $this->append($b); |
|
| 137 | - unset($b); |
|
| 136 | + $ret = $this->append($b); |
|
| 137 | + unset($b); |
|
| 138 | 138 | |
| 139 | - return $ret; |
|
| 140 | - } |
|
| 139 | + return $ret; |
|
| 140 | + } |
|
| 141 | 141 | |
| 142 | - //---------------------------------------------------------------------- |
|
| 143 | - public function toByte() |
|
| 144 | - {
|
|
| 142 | + //---------------------------------------------------------------------- |
|
| 143 | + public function toByte() |
|
| 144 | + {
|
|
| 145 | 145 | |
| 146 | - $size = $this->size(); |
|
| 146 | + $size = $this->size(); |
|
| 147 | 147 | |
| 148 | - if($size == 0) {
|
|
| 149 | - return array(); |
|
| 150 | - } |
|
| 148 | + if($size == 0) {
|
|
| 149 | + return array(); |
|
| 150 | + } |
|
| 151 | 151 | |
| 152 | - $data = array_fill(0, (int)(($size + 7) / 8), 0); |
|
| 153 | - $bytes = (int)($size / 8); |
|
| 152 | + $data = array_fill(0, (int)(($size + 7) / 8), 0); |
|
| 153 | + $bytes = (int)($size / 8); |
|
| 154 | 154 | |
| 155 | - $p = 0; |
|
| 155 | + $p = 0; |
|
| 156 | 156 | |
| 157 | - for($i=0; $i<$bytes; $i++) {
|
|
| 158 | - $v = 0; |
|
| 159 | - for($j=0; $j<8; $j++) {
|
|
| 160 | - $v = $v << 1; |
|
| 161 | - $v |= $this->data[$p]; |
|
| 162 | - $p++; |
|
| 163 | - } |
|
| 164 | - $data[$i] = $v; |
|
| 165 | - } |
|
| 157 | + for($i=0; $i<$bytes; $i++) {
|
|
| 158 | + $v = 0; |
|
| 159 | + for($j=0; $j<8; $j++) {
|
|
| 160 | + $v = $v << 1; |
|
| 161 | + $v |= $this->data[$p]; |
|
| 162 | + $p++; |
|
| 163 | + } |
|
| 164 | + $data[$i] = $v; |
|
| 165 | + } |
|
| 166 | 166 | |
| 167 | - if($size & 7) {
|
|
| 168 | - $v = 0; |
|
| 169 | - for($j=0; $j<($size & 7); $j++) {
|
|
| 170 | - $v = $v << 1; |
|
| 171 | - $v |= $this->data[$p]; |
|
| 172 | - $p++; |
|
| 173 | - } |
|
| 174 | - $data[$bytes] = $v; |
|
| 175 | - } |
|
| 167 | + if($size & 7) {
|
|
| 168 | + $v = 0; |
|
| 169 | + for($j=0; $j<($size & 7); $j++) {
|
|
| 170 | + $v = $v << 1; |
|
| 171 | + $v |= $this->data[$p]; |
|
| 172 | + $p++; |
|
| 173 | + } |
|
| 174 | + $data[$bytes] = $v; |
|
| 175 | + } |
|
| 176 | 176 | |
| 177 | - return $data; |
|
| 178 | - } |
|
| 177 | + return $data; |
|
| 178 | + } |
|
| 179 | 179 | |
| 180 | - } |
|
| 180 | + } |
|
@@ -49,8 +49,8 @@ discard block |
||
| 49 | 49 | $bstream->allocate($bits); |
| 50 | 50 | |
| 51 | 51 | $mask = 1 << ($bits - 1); |
| 52 | - for($i=0; $i<$bits; $i++) {
|
|
| 53 | - if($num & $mask) {
|
|
| 52 | + for ($i = 0; $i < $bits; $i++) {
|
|
| 53 | + if ($num & $mask) {
|
|
| 54 | 54 | $bstream->data[$i] = 1; |
| 55 | 55 | } else {
|
| 56 | 56 | $bstream->data[$i] = 0; |
@@ -66,12 +66,12 @@ discard block |
||
| 66 | 66 | {
|
| 67 | 67 | $bstream = new QRbitstream(); |
| 68 | 68 | $bstream->allocate($size * 8); |
| 69 | - $p=0; |
|
| 69 | + $p = 0; |
|
| 70 | 70 | |
| 71 | - for($i=0; $i<$size; $i++) {
|
|
| 71 | + for ($i = 0; $i < $size; $i++) {
|
|
| 72 | 72 | $mask = 0x80; |
| 73 | - for($j=0; $j<8; $j++) {
|
|
| 74 | - if($data[$i] & $mask) {
|
|
| 73 | + for ($j = 0; $j < 8; $j++) {
|
|
| 74 | + if ($data[$i] & $mask) {
|
|
| 75 | 75 | $bstream->data[$p] = 1; |
| 76 | 76 | } else {
|
| 77 | 77 | $bstream->data[$p] = 0; |
@@ -91,11 +91,11 @@ discard block |
||
| 91 | 91 | return -1; |
| 92 | 92 | } |
| 93 | 93 | |
| 94 | - if($arg->size() == 0) {
|
|
| 94 | + if ($arg->size() == 0) {
|
|
| 95 | 95 | return 0; |
| 96 | 96 | } |
| 97 | 97 | |
| 98 | - if($this->size() == 0) {
|
|
| 98 | + if ($this->size() == 0) {
|
|
| 99 | 99 | $this->data = $arg->data; |
| 100 | 100 | return 0; |
| 101 | 101 | } |
@@ -113,7 +113,7 @@ discard block |
||
| 113 | 113 | |
| 114 | 114 | $b = QRbitstream::newFromNum($bits, $num); |
| 115 | 115 | |
| 116 | - if(is_null($b)) |
|
| 116 | + if (is_null($b)) |
|
| 117 | 117 | return -1; |
| 118 | 118 | |
| 119 | 119 | $ret = $this->append($b); |
@@ -130,7 +130,7 @@ discard block |
||
| 130 | 130 | |
| 131 | 131 | $b = QRbitstream::newFromBytes($size, $data); |
| 132 | 132 | |
| 133 | - if(is_null($b)) |
|
| 133 | + if (is_null($b)) |
|
| 134 | 134 | return -1; |
| 135 | 135 | |
| 136 | 136 | $ret = $this->append($b); |
@@ -145,18 +145,18 @@ discard block |
||
| 145 | 145 | |
| 146 | 146 | $size = $this->size(); |
| 147 | 147 | |
| 148 | - if($size == 0) {
|
|
| 148 | + if ($size == 0) {
|
|
| 149 | 149 | return array(); |
| 150 | 150 | } |
| 151 | 151 | |
| 152 | - $data = array_fill(0, (int)(($size + 7) / 8), 0); |
|
| 153 | - $bytes = (int)($size / 8); |
|
| 152 | + $data = array_fill(0, (int) (($size + 7) / 8), 0); |
|
| 153 | + $bytes = (int) ($size / 8); |
|
| 154 | 154 | |
| 155 | 155 | $p = 0; |
| 156 | 156 | |
| 157 | - for($i=0; $i<$bytes; $i++) {
|
|
| 157 | + for ($i = 0; $i < $bytes; $i++) {
|
|
| 158 | 158 | $v = 0; |
| 159 | - for($j=0; $j<8; $j++) {
|
|
| 159 | + for ($j = 0; $j < 8; $j++) {
|
|
| 160 | 160 | $v = $v << 1; |
| 161 | 161 | $v |= $this->data[$p]; |
| 162 | 162 | $p++; |
@@ -164,9 +164,9 @@ discard block |
||
| 164 | 164 | $data[$i] = $v; |
| 165 | 165 | } |
| 166 | 166 | |
| 167 | - if($size & 7) {
|
|
| 167 | + if ($size & 7) {
|
|
| 168 | 168 | $v = 0; |
| 169 | - for($j=0; $j<($size & 7); $j++) {
|
|
| 169 | + for ($j = 0; $j < ($size & 7); $j++) {
|
|
| 170 | 170 | $v = $v << 1; |
| 171 | 171 | $v |= $this->data[$p]; |
| 172 | 172 | $p++; |
@@ -108,13 +108,15 @@ discard block |
||
| 108 | 108 | //---------------------------------------------------------------------- |
| 109 | 109 | public function appendNum($bits, $num) |
| 110 | 110 | {
|
| 111 | - if ($bits == 0) |
|
| 112 | - return 0; |
|
| 111 | + if ($bits == 0) { |
|
| 112 | + return 0; |
|
| 113 | + } |
|
| 113 | 114 | |
| 114 | 115 | $b = QRbitstream::newFromNum($bits, $num); |
| 115 | 116 | |
| 116 | - if(is_null($b)) |
|
| 117 | - return -1; |
|
| 117 | + if(is_null($b)) { |
|
| 118 | + return -1; |
|
| 119 | + } |
|
| 118 | 120 | |
| 119 | 121 | $ret = $this->append($b); |
| 120 | 122 | unset($b); |
@@ -125,13 +127,15 @@ discard block |
||
| 125 | 127 | //---------------------------------------------------------------------- |
| 126 | 128 | public function appendBytes($size, $data) |
| 127 | 129 | {
|
| 128 | - if ($size == 0) |
|
| 129 | - return 0; |
|
| 130 | + if ($size == 0) { |
|
| 131 | + return 0; |
|
| 132 | + } |
|
| 130 | 133 | |
| 131 | 134 | $b = QRbitstream::newFromBytes($size, $data); |
| 132 | 135 | |
| 133 | - if(is_null($b)) |
|
| 134 | - return -1; |
|
| 136 | + if(is_null($b)) { |
|
| 137 | + return -1; |
|
| 138 | + } |
|
| 135 | 139 | |
| 136 | 140 | $ret = $this->append($b); |
| 137 | 141 | unset($b); |
@@ -30,282 +30,282 @@ |
||
| 30 | 30 | * License along with this library; if not, write to the Free Software |
| 31 | 31 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 32 | 32 | */ |
| 33 | - class QRsplit {
|
|
| 33 | + class QRsplit {
|
|
| 34 | 34 | |
| 35 | - public $dataStr = ''; |
|
| 36 | - public $input; |
|
| 37 | - public $modeHint; |
|
| 35 | + public $dataStr = ''; |
|
| 36 | + public $input; |
|
| 37 | + public $modeHint; |
|
| 38 | 38 | |
| 39 | - //---------------------------------------------------------------------- |
|
| 40 | - public function __construct($dataStr, $input, $modeHint) |
|
| 41 | - {
|
|
| 42 | - $this->dataStr = $dataStr; |
|
| 43 | - $this->input = $input; |
|
| 44 | - $this->modeHint = $modeHint; |
|
| 45 | - } |
|
| 39 | + //---------------------------------------------------------------------- |
|
| 40 | + public function __construct($dataStr, $input, $modeHint) |
|
| 41 | + {
|
|
| 42 | + $this->dataStr = $dataStr; |
|
| 43 | + $this->input = $input; |
|
| 44 | + $this->modeHint = $modeHint; |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - //---------------------------------------------------------------------- |
|
| 48 | - public static function isdigitat($str, $pos) |
|
| 49 | - {
|
|
| 50 | - if ($pos >= strlen($str)) |
|
| 51 | - return false; |
|
| 47 | + //---------------------------------------------------------------------- |
|
| 48 | + public static function isdigitat($str, $pos) |
|
| 49 | + {
|
|
| 50 | + if ($pos >= strlen($str)) |
|
| 51 | + return false; |
|
| 52 | 52 | |
| 53 | - return ((ord($str[$pos]) >= ord('0'))&&(ord($str[$pos]) <= ord('9')));
|
|
| 54 | - } |
|
| 53 | + return ((ord($str[$pos]) >= ord('0'))&&(ord($str[$pos]) <= ord('9')));
|
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - //---------------------------------------------------------------------- |
|
| 57 | - public static function isalnumat($str, $pos) |
|
| 58 | - {
|
|
| 59 | - if ($pos >= strlen($str)) |
|
| 60 | - return false; |
|
| 56 | + //---------------------------------------------------------------------- |
|
| 57 | + public static function isalnumat($str, $pos) |
|
| 58 | + {
|
|
| 59 | + if ($pos >= strlen($str)) |
|
| 60 | + return false; |
|
| 61 | 61 | |
| 62 | - return (QRinput::lookAnTable(ord($str[$pos])) >= 0); |
|
| 63 | - } |
|
| 62 | + return (QRinput::lookAnTable(ord($str[$pos])) >= 0); |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - //---------------------------------------------------------------------- |
|
| 66 | - public function identifyMode($pos) |
|
| 67 | - {
|
|
| 68 | - if ($pos >= strlen($this->dataStr)) |
|
| 69 | - return QR_MODE_NUL; |
|
| 65 | + //---------------------------------------------------------------------- |
|
| 66 | + public function identifyMode($pos) |
|
| 67 | + {
|
|
| 68 | + if ($pos >= strlen($this->dataStr)) |
|
| 69 | + return QR_MODE_NUL; |
|
| 70 | 70 | |
| 71 | - $c = $this->dataStr[$pos]; |
|
| 71 | + $c = $this->dataStr[$pos]; |
|
| 72 | 72 | |
| 73 | - if(self::isdigitat($this->dataStr, $pos)) {
|
|
| 74 | - return QR_MODE_NUM; |
|
| 75 | - } else if(self::isalnumat($this->dataStr, $pos)) {
|
|
| 76 | - return QR_MODE_AN; |
|
| 77 | - } else if($this->modeHint == QR_MODE_KANJI) {
|
|
| 73 | + if(self::isdigitat($this->dataStr, $pos)) {
|
|
| 74 | + return QR_MODE_NUM; |
|
| 75 | + } else if(self::isalnumat($this->dataStr, $pos)) {
|
|
| 76 | + return QR_MODE_AN; |
|
| 77 | + } else if($this->modeHint == QR_MODE_KANJI) {
|
|
| 78 | 78 | |
| 79 | - if ($pos+1 < strlen($this->dataStr)) |
|
| 80 | - {
|
|
| 81 | - $d = $this->dataStr[$pos+1]; |
|
| 82 | - $word = (ord($c) << 8) | ord($d); |
|
| 83 | - if(($word >= 0x8140 && $word <= 0x9ffc) || ($word >= 0xe040 && $word <= 0xebbf)) {
|
|
| 84 | - return QR_MODE_KANJI; |
|
| 85 | - } |
|
| 86 | - } |
|
| 87 | - } |
|
| 79 | + if ($pos+1 < strlen($this->dataStr)) |
|
| 80 | + {
|
|
| 81 | + $d = $this->dataStr[$pos+1]; |
|
| 82 | + $word = (ord($c) << 8) | ord($d); |
|
| 83 | + if(($word >= 0x8140 && $word <= 0x9ffc) || ($word >= 0xe040 && $word <= 0xebbf)) {
|
|
| 84 | + return QR_MODE_KANJI; |
|
| 85 | + } |
|
| 86 | + } |
|
| 87 | + } |
|
| 88 | 88 | |
| 89 | - return QR_MODE_8; |
|
| 90 | - } |
|
| 89 | + return QR_MODE_8; |
|
| 90 | + } |
|
| 91 | 91 | |
| 92 | - //---------------------------------------------------------------------- |
|
| 93 | - public function eatNum() |
|
| 94 | - {
|
|
| 95 | - $ln = QRspec::lengthIndicator(QR_MODE_NUM, $this->input->getVersion()); |
|
| 92 | + //---------------------------------------------------------------------- |
|
| 93 | + public function eatNum() |
|
| 94 | + {
|
|
| 95 | + $ln = QRspec::lengthIndicator(QR_MODE_NUM, $this->input->getVersion()); |
|
| 96 | 96 | |
| 97 | - $p = 0; |
|
| 98 | - while(self::isdigitat($this->dataStr, $p)) {
|
|
| 99 | - $p++; |
|
| 100 | - } |
|
| 97 | + $p = 0; |
|
| 98 | + while(self::isdigitat($this->dataStr, $p)) {
|
|
| 99 | + $p++; |
|
| 100 | + } |
|
| 101 | 101 | |
| 102 | - $run = $p; |
|
| 103 | - $mode = $this->identifyMode($p); |
|
| 102 | + $run = $p; |
|
| 103 | + $mode = $this->identifyMode($p); |
|
| 104 | 104 | |
| 105 | - if($mode == QR_MODE_8) {
|
|
| 106 | - $dif = QRinput::estimateBitsModeNum($run) + 4 + $ln |
|
| 107 | - + QRinput::estimateBitsMode8(1) // + 4 + l8 |
|
| 108 | - - QRinput::estimateBitsMode8($run + 1); // - 4 - l8 |
|
| 109 | - if($dif > 0) {
|
|
| 110 | - return $this->eat8(); |
|
| 111 | - } |
|
| 112 | - } |
|
| 113 | - if($mode == QR_MODE_AN) {
|
|
| 114 | - $dif = QRinput::estimateBitsModeNum($run) + 4 + $ln |
|
| 115 | - + QRinput::estimateBitsModeAn(1) // + 4 + la |
|
| 116 | - - QRinput::estimateBitsModeAn($run + 1);// - 4 - la |
|
| 117 | - if($dif > 0) {
|
|
| 118 | - return $this->eatAn(); |
|
| 119 | - } |
|
| 120 | - } |
|
| 105 | + if($mode == QR_MODE_8) {
|
|
| 106 | + $dif = QRinput::estimateBitsModeNum($run) + 4 + $ln |
|
| 107 | + + QRinput::estimateBitsMode8(1) // + 4 + l8 |
|
| 108 | + - QRinput::estimateBitsMode8($run + 1); // - 4 - l8 |
|
| 109 | + if($dif > 0) {
|
|
| 110 | + return $this->eat8(); |
|
| 111 | + } |
|
| 112 | + } |
|
| 113 | + if($mode == QR_MODE_AN) {
|
|
| 114 | + $dif = QRinput::estimateBitsModeNum($run) + 4 + $ln |
|
| 115 | + + QRinput::estimateBitsModeAn(1) // + 4 + la |
|
| 116 | + - QRinput::estimateBitsModeAn($run + 1);// - 4 - la |
|
| 117 | + if($dif > 0) {
|
|
| 118 | + return $this->eatAn(); |
|
| 119 | + } |
|
| 120 | + } |
|
| 121 | 121 | |
| 122 | - $ret = $this->input->append(QR_MODE_NUM, $run, str_split($this->dataStr)); |
|
| 123 | - if($ret < 0) |
|
| 124 | - return -1; |
|
| 122 | + $ret = $this->input->append(QR_MODE_NUM, $run, str_split($this->dataStr)); |
|
| 123 | + if($ret < 0) |
|
| 124 | + return -1; |
|
| 125 | 125 | |
| 126 | - return $run; |
|
| 127 | - } |
|
| 126 | + return $run; |
|
| 127 | + } |
|
| 128 | 128 | |
| 129 | - //---------------------------------------------------------------------- |
|
| 130 | - public function eatAn() |
|
| 131 | - {
|
|
| 132 | - $la = QRspec::lengthIndicator(QR_MODE_AN, $this->input->getVersion()); |
|
| 133 | - $ln = QRspec::lengthIndicator(QR_MODE_NUM, $this->input->getVersion()); |
|
| 129 | + //---------------------------------------------------------------------- |
|
| 130 | + public function eatAn() |
|
| 131 | + {
|
|
| 132 | + $la = QRspec::lengthIndicator(QR_MODE_AN, $this->input->getVersion()); |
|
| 133 | + $ln = QRspec::lengthIndicator(QR_MODE_NUM, $this->input->getVersion()); |
|
| 134 | 134 | |
| 135 | - $p = 0; |
|
| 135 | + $p = 0; |
|
| 136 | 136 | |
| 137 | - while(self::isalnumat($this->dataStr, $p)) {
|
|
| 138 | - if(self::isdigitat($this->dataStr, $p)) {
|
|
| 139 | - $q = $p; |
|
| 140 | - while(self::isdigitat($this->dataStr, $q)) {
|
|
| 141 | - $q++; |
|
| 142 | - } |
|
| 137 | + while(self::isalnumat($this->dataStr, $p)) {
|
|
| 138 | + if(self::isdigitat($this->dataStr, $p)) {
|
|
| 139 | + $q = $p; |
|
| 140 | + while(self::isdigitat($this->dataStr, $q)) {
|
|
| 141 | + $q++; |
|
| 142 | + } |
|
| 143 | 143 | |
| 144 | - $dif = QRinput::estimateBitsModeAn($p) // + 4 + la |
|
| 145 | - + QRinput::estimateBitsModeNum($q - $p) + 4 + $ln |
|
| 146 | - - QRinput::estimateBitsModeAn($q); // - 4 - la |
|
| 144 | + $dif = QRinput::estimateBitsModeAn($p) // + 4 + la |
|
| 145 | + + QRinput::estimateBitsModeNum($q - $p) + 4 + $ln |
|
| 146 | + - QRinput::estimateBitsModeAn($q); // - 4 - la |
|
| 147 | 147 | |
| 148 | - if($dif < 0) {
|
|
| 149 | - break; |
|
| 150 | - } else {
|
|
| 151 | - $p = $q; |
|
| 152 | - } |
|
| 153 | - } else {
|
|
| 154 | - $p++; |
|
| 155 | - } |
|
| 156 | - } |
|
| 148 | + if($dif < 0) {
|
|
| 149 | + break; |
|
| 150 | + } else {
|
|
| 151 | + $p = $q; |
|
| 152 | + } |
|
| 153 | + } else {
|
|
| 154 | + $p++; |
|
| 155 | + } |
|
| 156 | + } |
|
| 157 | 157 | |
| 158 | - $run = $p; |
|
| 158 | + $run = $p; |
|
| 159 | 159 | |
| 160 | - if(!self::isalnumat($this->dataStr, $p)) {
|
|
| 161 | - $dif = QRinput::estimateBitsModeAn($run) + 4 + $la |
|
| 162 | - + QRinput::estimateBitsMode8(1) // + 4 + l8 |
|
| 163 | - - QRinput::estimateBitsMode8($run + 1); // - 4 - l8 |
|
| 164 | - if($dif > 0) {
|
|
| 165 | - return $this->eat8(); |
|
| 166 | - } |
|
| 167 | - } |
|
| 160 | + if(!self::isalnumat($this->dataStr, $p)) {
|
|
| 161 | + $dif = QRinput::estimateBitsModeAn($run) + 4 + $la |
|
| 162 | + + QRinput::estimateBitsMode8(1) // + 4 + l8 |
|
| 163 | + - QRinput::estimateBitsMode8($run + 1); // - 4 - l8 |
|
| 164 | + if($dif > 0) {
|
|
| 165 | + return $this->eat8(); |
|
| 166 | + } |
|
| 167 | + } |
|
| 168 | 168 | |
| 169 | - $ret = $this->input->append(QR_MODE_AN, $run, str_split($this->dataStr)); |
|
| 170 | - if($ret < 0) |
|
| 171 | - return -1; |
|
| 169 | + $ret = $this->input->append(QR_MODE_AN, $run, str_split($this->dataStr)); |
|
| 170 | + if($ret < 0) |
|
| 171 | + return -1; |
|
| 172 | 172 | |
| 173 | - return $run; |
|
| 174 | - } |
|
| 173 | + return $run; |
|
| 174 | + } |
|
| 175 | 175 | |
| 176 | - //---------------------------------------------------------------------- |
|
| 177 | - public function eatKanji() |
|
| 178 | - {
|
|
| 179 | - $p = 0; |
|
| 176 | + //---------------------------------------------------------------------- |
|
| 177 | + public function eatKanji() |
|
| 178 | + {
|
|
| 179 | + $p = 0; |
|
| 180 | 180 | |
| 181 | - while($this->identifyMode($p) == QR_MODE_KANJI) {
|
|
| 182 | - $p += 2; |
|
| 183 | - } |
|
| 181 | + while($this->identifyMode($p) == QR_MODE_KANJI) {
|
|
| 182 | + $p += 2; |
|
| 183 | + } |
|
| 184 | 184 | |
| 185 | - $ret = $this->input->append(QR_MODE_KANJI, $p, str_split($this->dataStr)); |
|
| 186 | - if($ret < 0) |
|
| 187 | - return -1; |
|
| 185 | + $ret = $this->input->append(QR_MODE_KANJI, $p, str_split($this->dataStr)); |
|
| 186 | + if($ret < 0) |
|
| 187 | + return -1; |
|
| 188 | 188 | |
| 189 | - return $ret; |
|
| 190 | - } |
|
| 189 | + return $ret; |
|
| 190 | + } |
|
| 191 | 191 | |
| 192 | - //---------------------------------------------------------------------- |
|
| 193 | - public function eat8() |
|
| 194 | - {
|
|
| 195 | - $la = QRspec::lengthIndicator(QR_MODE_AN, $this->input->getVersion()); |
|
| 196 | - $ln = QRspec::lengthIndicator(QR_MODE_NUM, $this->input->getVersion()); |
|
| 192 | + //---------------------------------------------------------------------- |
|
| 193 | + public function eat8() |
|
| 194 | + {
|
|
| 195 | + $la = QRspec::lengthIndicator(QR_MODE_AN, $this->input->getVersion()); |
|
| 196 | + $ln = QRspec::lengthIndicator(QR_MODE_NUM, $this->input->getVersion()); |
|
| 197 | 197 | |
| 198 | - $p = 1; |
|
| 199 | - $dataStrLen = strlen($this->dataStr); |
|
| 198 | + $p = 1; |
|
| 199 | + $dataStrLen = strlen($this->dataStr); |
|
| 200 | 200 | |
| 201 | - while($p < $dataStrLen) {
|
|
| 201 | + while($p < $dataStrLen) {
|
|
| 202 | 202 | |
| 203 | - $mode = $this->identifyMode($p); |
|
| 204 | - if($mode == QR_MODE_KANJI) {
|
|
| 205 | - break; |
|
| 206 | - } |
|
| 207 | - if($mode == QR_MODE_NUM) {
|
|
| 208 | - $q = $p; |
|
| 209 | - while(self::isdigitat($this->dataStr, $q)) {
|
|
| 210 | - $q++; |
|
| 211 | - } |
|
| 212 | - $dif = QRinput::estimateBitsMode8($p) // + 4 + l8 |
|
| 213 | - + QRinput::estimateBitsModeNum($q - $p) + 4 + $ln |
|
| 214 | - - QRinput::estimateBitsMode8($q); // - 4 - l8 |
|
| 215 | - if($dif < 0) {
|
|
| 216 | - break; |
|
| 217 | - } else {
|
|
| 218 | - $p = $q; |
|
| 219 | - } |
|
| 220 | - } else if($mode == QR_MODE_AN) {
|
|
| 221 | - $q = $p; |
|
| 222 | - while(self::isalnumat($this->dataStr, $q)) {
|
|
| 223 | - $q++; |
|
| 224 | - } |
|
| 225 | - $dif = QRinput::estimateBitsMode8($p) // + 4 + l8 |
|
| 226 | - + QRinput::estimateBitsModeAn($q - $p) + 4 + $la |
|
| 227 | - - QRinput::estimateBitsMode8($q); // - 4 - l8 |
|
| 228 | - if($dif < 0) {
|
|
| 229 | - break; |
|
| 230 | - } else {
|
|
| 231 | - $p = $q; |
|
| 232 | - } |
|
| 233 | - } else {
|
|
| 234 | - $p++; |
|
| 235 | - } |
|
| 236 | - } |
|
| 203 | + $mode = $this->identifyMode($p); |
|
| 204 | + if($mode == QR_MODE_KANJI) {
|
|
| 205 | + break; |
|
| 206 | + } |
|
| 207 | + if($mode == QR_MODE_NUM) {
|
|
| 208 | + $q = $p; |
|
| 209 | + while(self::isdigitat($this->dataStr, $q)) {
|
|
| 210 | + $q++; |
|
| 211 | + } |
|
| 212 | + $dif = QRinput::estimateBitsMode8($p) // + 4 + l8 |
|
| 213 | + + QRinput::estimateBitsModeNum($q - $p) + 4 + $ln |
|
| 214 | + - QRinput::estimateBitsMode8($q); // - 4 - l8 |
|
| 215 | + if($dif < 0) {
|
|
| 216 | + break; |
|
| 217 | + } else {
|
|
| 218 | + $p = $q; |
|
| 219 | + } |
|
| 220 | + } else if($mode == QR_MODE_AN) {
|
|
| 221 | + $q = $p; |
|
| 222 | + while(self::isalnumat($this->dataStr, $q)) {
|
|
| 223 | + $q++; |
|
| 224 | + } |
|
| 225 | + $dif = QRinput::estimateBitsMode8($p) // + 4 + l8 |
|
| 226 | + + QRinput::estimateBitsModeAn($q - $p) + 4 + $la |
|
| 227 | + - QRinput::estimateBitsMode8($q); // - 4 - l8 |
|
| 228 | + if($dif < 0) {
|
|
| 229 | + break; |
|
| 230 | + } else {
|
|
| 231 | + $p = $q; |
|
| 232 | + } |
|
| 233 | + } else {
|
|
| 234 | + $p++; |
|
| 235 | + } |
|
| 236 | + } |
|
| 237 | 237 | |
| 238 | - $run = $p; |
|
| 239 | - $ret = $this->input->append(QR_MODE_8, $run, str_split($this->dataStr)); |
|
| 238 | + $run = $p; |
|
| 239 | + $ret = $this->input->append(QR_MODE_8, $run, str_split($this->dataStr)); |
|
| 240 | 240 | |
| 241 | - if($ret < 0) |
|
| 242 | - return -1; |
|
| 241 | + if($ret < 0) |
|
| 242 | + return -1; |
|
| 243 | 243 | |
| 244 | - return $run; |
|
| 245 | - } |
|
| 244 | + return $run; |
|
| 245 | + } |
|
| 246 | 246 | |
| 247 | - //---------------------------------------------------------------------- |
|
| 248 | - public function splitString() |
|
| 249 | - {
|
|
| 250 | - while (strlen($this->dataStr) > 0) |
|
| 251 | - {
|
|
| 252 | - if($this->dataStr == '') |
|
| 253 | - return 0; |
|
| 247 | + //---------------------------------------------------------------------- |
|
| 248 | + public function splitString() |
|
| 249 | + {
|
|
| 250 | + while (strlen($this->dataStr) > 0) |
|
| 251 | + {
|
|
| 252 | + if($this->dataStr == '') |
|
| 253 | + return 0; |
|
| 254 | 254 | |
| 255 | - $mode = $this->identifyMode(0); |
|
| 255 | + $mode = $this->identifyMode(0); |
|
| 256 | 256 | |
| 257 | - switch ($mode) {
|
|
| 258 | - case QR_MODE_NUM: $length = $this->eatNum(); break; |
|
| 259 | - case QR_MODE_AN: $length = $this->eatAn(); break; |
|
| 260 | - case QR_MODE_KANJI: |
|
| 261 | - if ($this->modeHint == QR_MODE_KANJI) |
|
| 262 | - $length = $this->eatKanji(); |
|
| 263 | - else $length = $this->eat8(); |
|
| 264 | - break; |
|
| 265 | - default: $length = $this->eat8(); break; |
|
| 257 | + switch ($mode) {
|
|
| 258 | + case QR_MODE_NUM: $length = $this->eatNum(); break; |
|
| 259 | + case QR_MODE_AN: $length = $this->eatAn(); break; |
|
| 260 | + case QR_MODE_KANJI: |
|
| 261 | + if ($this->modeHint == QR_MODE_KANJI) |
|
| 262 | + $length = $this->eatKanji(); |
|
| 263 | + else $length = $this->eat8(); |
|
| 264 | + break; |
|
| 265 | + default: $length = $this->eat8(); break; |
|
| 266 | 266 | |
| 267 | - } |
|
| 267 | + } |
|
| 268 | 268 | |
| 269 | - if($length == 0) return 0; |
|
| 270 | - if($length < 0) return -1; |
|
| 269 | + if($length == 0) return 0; |
|
| 270 | + if($length < 0) return -1; |
|
| 271 | 271 | |
| 272 | - $this->dataStr = substr($this->dataStr, $length); |
|
| 273 | - } |
|
| 274 | - } |
|
| 272 | + $this->dataStr = substr($this->dataStr, $length); |
|
| 273 | + } |
|
| 274 | + } |
|
| 275 | 275 | |
| 276 | - //---------------------------------------------------------------------- |
|
| 277 | - public function toUpper() |
|
| 278 | - {
|
|
| 279 | - $stringLen = strlen($this->dataStr); |
|
| 280 | - $p = 0; |
|
| 276 | + //---------------------------------------------------------------------- |
|
| 277 | + public function toUpper() |
|
| 278 | + {
|
|
| 279 | + $stringLen = strlen($this->dataStr); |
|
| 280 | + $p = 0; |
|
| 281 | 281 | |
| 282 | - while ($p<$stringLen) {
|
|
| 283 | - $mode = self::identifyMode(substr($this->dataStr, $p)); |
|
| 284 | - if($mode == QR_MODE_KANJI) {
|
|
| 285 | - $p += 2; |
|
| 286 | - } else {
|
|
| 287 | - if (ord($this->dataStr[$p]) >= ord('a') && ord($this->dataStr[$p]) <= ord('z')) {
|
|
| 288 | - $this->dataStr[$p] = chr(ord($this->dataStr[$p]) - 32); |
|
| 289 | - } |
|
| 290 | - $p++; |
|
| 291 | - } |
|
| 292 | - } |
|
| 282 | + while ($p<$stringLen) {
|
|
| 283 | + $mode = self::identifyMode(substr($this->dataStr, $p)); |
|
| 284 | + if($mode == QR_MODE_KANJI) {
|
|
| 285 | + $p += 2; |
|
| 286 | + } else {
|
|
| 287 | + if (ord($this->dataStr[$p]) >= ord('a') && ord($this->dataStr[$p]) <= ord('z')) {
|
|
| 288 | + $this->dataStr[$p] = chr(ord($this->dataStr[$p]) - 32); |
|
| 289 | + } |
|
| 290 | + $p++; |
|
| 291 | + } |
|
| 292 | + } |
|
| 293 | 293 | |
| 294 | - return $this->dataStr; |
|
| 295 | - } |
|
| 294 | + return $this->dataStr; |
|
| 295 | + } |
|
| 296 | 296 | |
| 297 | - //---------------------------------------------------------------------- |
|
| 298 | - public static function splitStringToQRinput($string, QRinput $input, $modeHint, $casesensitive = true) |
|
| 299 | - {
|
|
| 300 | - if(is_null($string) || $string == '\0' || $string == '') {
|
|
| 301 | - throw new Exception('empty string!!!');
|
|
| 302 | - } |
|
| 297 | + //---------------------------------------------------------------------- |
|
| 298 | + public static function splitStringToQRinput($string, QRinput $input, $modeHint, $casesensitive = true) |
|
| 299 | + {
|
|
| 300 | + if(is_null($string) || $string == '\0' || $string == '') {
|
|
| 301 | + throw new Exception('empty string!!!');
|
|
| 302 | + } |
|
| 303 | 303 | |
| 304 | - $split = new QRsplit($string, $input, $modeHint); |
|
| 304 | + $split = new QRsplit($string, $input, $modeHint); |
|
| 305 | 305 | |
| 306 | - if(!$casesensitive) |
|
| 307 | - $split->toUpper(); |
|
| 306 | + if(!$casesensitive) |
|
| 307 | + $split->toUpper(); |
|
| 308 | 308 | |
| 309 | - return $split->splitString(); |
|
| 310 | - } |
|
| 311 | - } |
|
| 309 | + return $split->splitString(); |
|
| 310 | + } |
|
| 311 | + } |
|
@@ -255,14 +255,14 @@ |
||
| 255 | 255 | $mode = $this->identifyMode(0); |
| 256 | 256 | |
| 257 | 257 | switch ($mode) {
|
| 258 | - case QR_MODE_NUM: $length = $this->eatNum(); break; |
|
| 259 | - case QR_MODE_AN: $length = $this->eatAn(); break; |
|
| 260 | - case QR_MODE_KANJI: |
|
| 261 | - if ($this->modeHint == QR_MODE_KANJI) |
|
| 262 | - $length = $this->eatKanji(); |
|
| 263 | - else $length = $this->eat8(); |
|
| 264 | - break; |
|
| 265 | - default: $length = $this->eat8(); break; |
|
| 258 | + case QR_MODE_NUM: $length = $this->eatNum(); break; |
|
| 259 | + case QR_MODE_AN: $length = $this->eatAn(); break; |
|
| 260 | + case QR_MODE_KANJI: |
|
| 261 | + if ($this->modeHint == QR_MODE_KANJI) |
|
| 262 | + $length = $this->eatKanji(); |
|
| 263 | + else $length = $this->eat8(); |
|
| 264 | + break; |
|
| 265 | + default: $length = $this->eat8(); break; |
|
| 266 | 266 | |
| 267 | 267 | } |
| 268 | 268 | |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | if ($pos >= strlen($str)) |
| 51 | 51 | return false; |
| 52 | 52 | |
| 53 | - return ((ord($str[$pos]) >= ord('0'))&&(ord($str[$pos]) <= ord('9')));
|
|
| 53 | + return ((ord($str[$pos]) >= ord('0')) && (ord($str[$pos]) <= ord('9')));
|
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | //---------------------------------------------------------------------- |
@@ -70,17 +70,17 @@ discard block |
||
| 70 | 70 | |
| 71 | 71 | $c = $this->dataStr[$pos]; |
| 72 | 72 | |
| 73 | - if(self::isdigitat($this->dataStr, $pos)) {
|
|
| 73 | + if (self::isdigitat($this->dataStr, $pos)) {
|
|
| 74 | 74 | return QR_MODE_NUM; |
| 75 | - } else if(self::isalnumat($this->dataStr, $pos)) {
|
|
| 75 | + } else if (self::isalnumat($this->dataStr, $pos)) {
|
|
| 76 | 76 | return QR_MODE_AN; |
| 77 | - } else if($this->modeHint == QR_MODE_KANJI) {
|
|
| 77 | + } else if ($this->modeHint == QR_MODE_KANJI) {
|
|
| 78 | 78 | |
| 79 | - if ($pos+1 < strlen($this->dataStr)) |
|
| 79 | + if ($pos + 1 < strlen($this->dataStr)) |
|
| 80 | 80 | {
|
| 81 | - $d = $this->dataStr[$pos+1]; |
|
| 81 | + $d = $this->dataStr[$pos + 1]; |
|
| 82 | 82 | $word = (ord($c) << 8) | ord($d); |
| 83 | - if(($word >= 0x8140 && $word <= 0x9ffc) || ($word >= 0xe040 && $word <= 0xebbf)) {
|
|
| 83 | + if (($word >= 0x8140 && $word <= 0x9ffc) || ($word >= 0xe040 && $word <= 0xebbf)) {
|
|
| 84 | 84 | return QR_MODE_KANJI; |
| 85 | 85 | } |
| 86 | 86 | } |
@@ -95,32 +95,32 @@ discard block |
||
| 95 | 95 | $ln = QRspec::lengthIndicator(QR_MODE_NUM, $this->input->getVersion()); |
| 96 | 96 | |
| 97 | 97 | $p = 0; |
| 98 | - while(self::isdigitat($this->dataStr, $p)) {
|
|
| 98 | + while (self::isdigitat($this->dataStr, $p)) {
|
|
| 99 | 99 | $p++; |
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | $run = $p; |
| 103 | 103 | $mode = $this->identifyMode($p); |
| 104 | 104 | |
| 105 | - if($mode == QR_MODE_8) {
|
|
| 105 | + if ($mode == QR_MODE_8) {
|
|
| 106 | 106 | $dif = QRinput::estimateBitsModeNum($run) + 4 + $ln |
| 107 | 107 | + QRinput::estimateBitsMode8(1) // + 4 + l8 |
| 108 | 108 | - QRinput::estimateBitsMode8($run + 1); // - 4 - l8 |
| 109 | - if($dif > 0) {
|
|
| 109 | + if ($dif > 0) {
|
|
| 110 | 110 | return $this->eat8(); |
| 111 | 111 | } |
| 112 | 112 | } |
| 113 | - if($mode == QR_MODE_AN) {
|
|
| 113 | + if ($mode == QR_MODE_AN) {
|
|
| 114 | 114 | $dif = QRinput::estimateBitsModeNum($run) + 4 + $ln |
| 115 | 115 | + QRinput::estimateBitsModeAn(1) // + 4 + la |
| 116 | - - QRinput::estimateBitsModeAn($run + 1);// - 4 - la |
|
| 117 | - if($dif > 0) {
|
|
| 116 | + - QRinput::estimateBitsModeAn($run + 1); // - 4 - la |
|
| 117 | + if ($dif > 0) {
|
|
| 118 | 118 | return $this->eatAn(); |
| 119 | 119 | } |
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | $ret = $this->input->append(QR_MODE_NUM, $run, str_split($this->dataStr)); |
| 123 | - if($ret < 0) |
|
| 123 | + if ($ret < 0) |
|
| 124 | 124 | return -1; |
| 125 | 125 | |
| 126 | 126 | return $run; |
@@ -129,15 +129,15 @@ discard block |
||
| 129 | 129 | //---------------------------------------------------------------------- |
| 130 | 130 | public function eatAn() |
| 131 | 131 | {
|
| 132 | - $la = QRspec::lengthIndicator(QR_MODE_AN, $this->input->getVersion()); |
|
| 132 | + $la = QRspec::lengthIndicator(QR_MODE_AN, $this->input->getVersion()); |
|
| 133 | 133 | $ln = QRspec::lengthIndicator(QR_MODE_NUM, $this->input->getVersion()); |
| 134 | 134 | |
| 135 | 135 | $p = 0; |
| 136 | 136 | |
| 137 | - while(self::isalnumat($this->dataStr, $p)) {
|
|
| 138 | - if(self::isdigitat($this->dataStr, $p)) {
|
|
| 137 | + while (self::isalnumat($this->dataStr, $p)) {
|
|
| 138 | + if (self::isdigitat($this->dataStr, $p)) {
|
|
| 139 | 139 | $q = $p; |
| 140 | - while(self::isdigitat($this->dataStr, $q)) {
|
|
| 140 | + while (self::isdigitat($this->dataStr, $q)) {
|
|
| 141 | 141 | $q++; |
| 142 | 142 | } |
| 143 | 143 | |
@@ -145,7 +145,7 @@ discard block |
||
| 145 | 145 | + QRinput::estimateBitsModeNum($q - $p) + 4 + $ln |
| 146 | 146 | - QRinput::estimateBitsModeAn($q); // - 4 - la |
| 147 | 147 | |
| 148 | - if($dif < 0) {
|
|
| 148 | + if ($dif < 0) {
|
|
| 149 | 149 | break; |
| 150 | 150 | } else {
|
| 151 | 151 | $p = $q; |
@@ -157,17 +157,17 @@ discard block |
||
| 157 | 157 | |
| 158 | 158 | $run = $p; |
| 159 | 159 | |
| 160 | - if(!self::isalnumat($this->dataStr, $p)) {
|
|
| 160 | + if (!self::isalnumat($this->dataStr, $p)) {
|
|
| 161 | 161 | $dif = QRinput::estimateBitsModeAn($run) + 4 + $la |
| 162 | 162 | + QRinput::estimateBitsMode8(1) // + 4 + l8 |
| 163 | 163 | - QRinput::estimateBitsMode8($run + 1); // - 4 - l8 |
| 164 | - if($dif > 0) {
|
|
| 164 | + if ($dif > 0) {
|
|
| 165 | 165 | return $this->eat8(); |
| 166 | 166 | } |
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | $ret = $this->input->append(QR_MODE_AN, $run, str_split($this->dataStr)); |
| 170 | - if($ret < 0) |
|
| 170 | + if ($ret < 0) |
|
| 171 | 171 | return -1; |
| 172 | 172 | |
| 173 | 173 | return $run; |
@@ -178,12 +178,12 @@ discard block |
||
| 178 | 178 | {
|
| 179 | 179 | $p = 0; |
| 180 | 180 | |
| 181 | - while($this->identifyMode($p) == QR_MODE_KANJI) {
|
|
| 181 | + while ($this->identifyMode($p) == QR_MODE_KANJI) {
|
|
| 182 | 182 | $p += 2; |
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | $ret = $this->input->append(QR_MODE_KANJI, $p, str_split($this->dataStr)); |
| 186 | - if($ret < 0) |
|
| 186 | + if ($ret < 0) |
|
| 187 | 187 | return -1; |
| 188 | 188 | |
| 189 | 189 | return $ret; |
@@ -198,34 +198,34 @@ discard block |
||
| 198 | 198 | $p = 1; |
| 199 | 199 | $dataStrLen = strlen($this->dataStr); |
| 200 | 200 | |
| 201 | - while($p < $dataStrLen) {
|
|
| 201 | + while ($p < $dataStrLen) {
|
|
| 202 | 202 | |
| 203 | 203 | $mode = $this->identifyMode($p); |
| 204 | - if($mode == QR_MODE_KANJI) {
|
|
| 204 | + if ($mode == QR_MODE_KANJI) {
|
|
| 205 | 205 | break; |
| 206 | 206 | } |
| 207 | - if($mode == QR_MODE_NUM) {
|
|
| 207 | + if ($mode == QR_MODE_NUM) {
|
|
| 208 | 208 | $q = $p; |
| 209 | - while(self::isdigitat($this->dataStr, $q)) {
|
|
| 209 | + while (self::isdigitat($this->dataStr, $q)) {
|
|
| 210 | 210 | $q++; |
| 211 | 211 | } |
| 212 | 212 | $dif = QRinput::estimateBitsMode8($p) // + 4 + l8 |
| 213 | 213 | + QRinput::estimateBitsModeNum($q - $p) + 4 + $ln |
| 214 | 214 | - QRinput::estimateBitsMode8($q); // - 4 - l8 |
| 215 | - if($dif < 0) {
|
|
| 215 | + if ($dif < 0) {
|
|
| 216 | 216 | break; |
| 217 | 217 | } else {
|
| 218 | 218 | $p = $q; |
| 219 | 219 | } |
| 220 | - } else if($mode == QR_MODE_AN) {
|
|
| 220 | + } else if ($mode == QR_MODE_AN) {
|
|
| 221 | 221 | $q = $p; |
| 222 | - while(self::isalnumat($this->dataStr, $q)) {
|
|
| 222 | + while (self::isalnumat($this->dataStr, $q)) {
|
|
| 223 | 223 | $q++; |
| 224 | 224 | } |
| 225 | 225 | $dif = QRinput::estimateBitsMode8($p) // + 4 + l8 |
| 226 | 226 | + QRinput::estimateBitsModeAn($q - $p) + 4 + $la |
| 227 | 227 | - QRinput::estimateBitsMode8($q); // - 4 - l8 |
| 228 | - if($dif < 0) {
|
|
| 228 | + if ($dif < 0) {
|
|
| 229 | 229 | break; |
| 230 | 230 | } else {
|
| 231 | 231 | $p = $q; |
@@ -238,7 +238,7 @@ discard block |
||
| 238 | 238 | $run = $p; |
| 239 | 239 | $ret = $this->input->append(QR_MODE_8, $run, str_split($this->dataStr)); |
| 240 | 240 | |
| 241 | - if($ret < 0) |
|
| 241 | + if ($ret < 0) |
|
| 242 | 242 | return -1; |
| 243 | 243 | |
| 244 | 244 | return $run; |
@@ -249,7 +249,7 @@ discard block |
||
| 249 | 249 | {
|
| 250 | 250 | while (strlen($this->dataStr) > 0) |
| 251 | 251 | {
|
| 252 | - if($this->dataStr == '') |
|
| 252 | + if ($this->dataStr == '') |
|
| 253 | 253 | return 0; |
| 254 | 254 | |
| 255 | 255 | $mode = $this->identifyMode(0); |
@@ -266,8 +266,8 @@ discard block |
||
| 266 | 266 | |
| 267 | 267 | } |
| 268 | 268 | |
| 269 | - if($length == 0) return 0; |
|
| 270 | - if($length < 0) return -1; |
|
| 269 | + if ($length == 0) return 0; |
|
| 270 | + if ($length < 0) return -1; |
|
| 271 | 271 | |
| 272 | 272 | $this->dataStr = substr($this->dataStr, $length); |
| 273 | 273 | } |
@@ -279,9 +279,9 @@ discard block |
||
| 279 | 279 | $stringLen = strlen($this->dataStr); |
| 280 | 280 | $p = 0; |
| 281 | 281 | |
| 282 | - while ($p<$stringLen) {
|
|
| 282 | + while ($p < $stringLen) {
|
|
| 283 | 283 | $mode = self::identifyMode(substr($this->dataStr, $p)); |
| 284 | - if($mode == QR_MODE_KANJI) {
|
|
| 284 | + if ($mode == QR_MODE_KANJI) {
|
|
| 285 | 285 | $p += 2; |
| 286 | 286 | } else {
|
| 287 | 287 | if (ord($this->dataStr[$p]) >= ord('a') && ord($this->dataStr[$p]) <= ord('z')) {
|
@@ -297,13 +297,13 @@ discard block |
||
| 297 | 297 | //---------------------------------------------------------------------- |
| 298 | 298 | public static function splitStringToQRinput($string, QRinput $input, $modeHint, $casesensitive = true) |
| 299 | 299 | {
|
| 300 | - if(is_null($string) || $string == '\0' || $string == '') {
|
|
| 300 | + if (is_null($string) || $string == '\0' || $string == '') {
|
|
| 301 | 301 | throw new Exception('empty string!!!');
|
| 302 | 302 | } |
| 303 | 303 | |
| 304 | 304 | $split = new QRsplit($string, $input, $modeHint); |
| 305 | 305 | |
| 306 | - if(!$casesensitive) |
|
| 306 | + if (!$casesensitive) |
|
| 307 | 307 | $split->toUpper(); |
| 308 | 308 | |
| 309 | 309 | return $split->splitString(); |
@@ -47,8 +47,9 @@ discard block |
||
| 47 | 47 | //---------------------------------------------------------------------- |
| 48 | 48 | public static function isdigitat($str, $pos) |
| 49 | 49 | {
|
| 50 | - if ($pos >= strlen($str)) |
|
| 51 | - return false; |
|
| 50 | + if ($pos >= strlen($str)) { |
|
| 51 | + return false; |
|
| 52 | + } |
|
| 52 | 53 | |
| 53 | 54 | return ((ord($str[$pos]) >= ord('0'))&&(ord($str[$pos]) <= ord('9')));
|
| 54 | 55 | } |
@@ -56,8 +57,9 @@ discard block |
||
| 56 | 57 | //---------------------------------------------------------------------- |
| 57 | 58 | public static function isalnumat($str, $pos) |
| 58 | 59 | {
|
| 59 | - if ($pos >= strlen($str)) |
|
| 60 | - return false; |
|
| 60 | + if ($pos >= strlen($str)) { |
|
| 61 | + return false; |
|
| 62 | + } |
|
| 61 | 63 | |
| 62 | 64 | return (QRinput::lookAnTable(ord($str[$pos])) >= 0); |
| 63 | 65 | } |
@@ -65,8 +67,9 @@ discard block |
||
| 65 | 67 | //---------------------------------------------------------------------- |
| 66 | 68 | public function identifyMode($pos) |
| 67 | 69 | {
|
| 68 | - if ($pos >= strlen($this->dataStr)) |
|
| 69 | - return QR_MODE_NUL; |
|
| 70 | + if ($pos >= strlen($this->dataStr)) { |
|
| 71 | + return QR_MODE_NUL; |
|
| 72 | + } |
|
| 70 | 73 | |
| 71 | 74 | $c = $this->dataStr[$pos]; |
| 72 | 75 | |
@@ -120,8 +123,9 @@ discard block |
||
| 120 | 123 | } |
| 121 | 124 | |
| 122 | 125 | $ret = $this->input->append(QR_MODE_NUM, $run, str_split($this->dataStr)); |
| 123 | - if($ret < 0) |
|
| 124 | - return -1; |
|
| 126 | + if($ret < 0) { |
|
| 127 | + return -1; |
|
| 128 | + } |
|
| 125 | 129 | |
| 126 | 130 | return $run; |
| 127 | 131 | } |
@@ -167,8 +171,9 @@ discard block |
||
| 167 | 171 | } |
| 168 | 172 | |
| 169 | 173 | $ret = $this->input->append(QR_MODE_AN, $run, str_split($this->dataStr)); |
| 170 | - if($ret < 0) |
|
| 171 | - return -1; |
|
| 174 | + if($ret < 0) { |
|
| 175 | + return -1; |
|
| 176 | + } |
|
| 172 | 177 | |
| 173 | 178 | return $run; |
| 174 | 179 | } |
@@ -183,8 +188,9 @@ discard block |
||
| 183 | 188 | } |
| 184 | 189 | |
| 185 | 190 | $ret = $this->input->append(QR_MODE_KANJI, $p, str_split($this->dataStr)); |
| 186 | - if($ret < 0) |
|
| 187 | - return -1; |
|
| 191 | + if($ret < 0) { |
|
| 192 | + return -1; |
|
| 193 | + } |
|
| 188 | 194 | |
| 189 | 195 | return $ret; |
| 190 | 196 | } |
@@ -238,8 +244,9 @@ discard block |
||
| 238 | 244 | $run = $p; |
| 239 | 245 | $ret = $this->input->append(QR_MODE_8, $run, str_split($this->dataStr)); |
| 240 | 246 | |
| 241 | - if($ret < 0) |
|
| 242 | - return -1; |
|
| 247 | + if($ret < 0) { |
|
| 248 | + return -1; |
|
| 249 | + } |
|
| 243 | 250 | |
| 244 | 251 | return $run; |
| 245 | 252 | } |
@@ -249,8 +256,9 @@ discard block |
||
| 249 | 256 | {
|
| 250 | 257 | while (strlen($this->dataStr) > 0) |
| 251 | 258 | {
|
| 252 | - if($this->dataStr == '') |
|
| 253 | - return 0; |
|
| 259 | + if($this->dataStr == '') { |
|
| 260 | + return 0; |
|
| 261 | + } |
|
| 254 | 262 | |
| 255 | 263 | $mode = $this->identifyMode(0); |
| 256 | 264 | |
@@ -258,16 +266,22 @@ discard block |
||
| 258 | 266 | case QR_MODE_NUM: $length = $this->eatNum(); break; |
| 259 | 267 | case QR_MODE_AN: $length = $this->eatAn(); break; |
| 260 | 268 | case QR_MODE_KANJI: |
| 261 | - if ($this->modeHint == QR_MODE_KANJI) |
|
| 262 | - $length = $this->eatKanji(); |
|
| 263 | - else $length = $this->eat8(); |
|
| 269 | + if ($this->modeHint == QR_MODE_KANJI) { |
|
| 270 | + $length = $this->eatKanji(); |
|
| 271 | + } else { |
|
| 272 | + $length = $this->eat8(); |
|
| 273 | + } |
|
| 264 | 274 | break; |
| 265 | 275 | default: $length = $this->eat8(); break; |
| 266 | 276 | |
| 267 | 277 | } |
| 268 | 278 | |
| 269 | - if($length == 0) return 0; |
|
| 270 | - if($length < 0) return -1; |
|
| 279 | + if($length == 0) { |
|
| 280 | + return 0; |
|
| 281 | + } |
|
| 282 | + if($length < 0) { |
|
| 283 | + return -1; |
|
| 284 | + } |
|
| 271 | 285 | |
| 272 | 286 | $this->dataStr = substr($this->dataStr, $length); |
| 273 | 287 | } |
@@ -303,8 +317,9 @@ discard block |
||
| 303 | 317 | |
| 304 | 318 | $split = new QRsplit($string, $input, $modeHint); |
| 305 | 319 | |
| 306 | - if(!$casesensitive) |
|
| 307 | - $split->toUpper(); |
|
| 320 | + if(!$casesensitive) { |
|
| 321 | + $split->toUpper(); |
|
| 322 | + } |
|
| 308 | 323 | |
| 309 | 324 | return $split->splitString(); |
| 310 | 325 | } |
@@ -25,705 +25,705 @@ |
||
| 25 | 25 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 26 | 26 | */ |
| 27 | 27 | |
| 28 | - define('STRUCTURE_HEADER_BITS', 20);
|
|
| 29 | - define('MAX_STRUCTURED_SYMBOLS', 16);
|
|
| 28 | + define('STRUCTURE_HEADER_BITS', 20);
|
|
| 29 | + define('MAX_STRUCTURED_SYMBOLS', 16);
|
|
| 30 | 30 | |
| 31 | - class QRinputItem {
|
|
| 31 | + class QRinputItem {
|
|
| 32 | 32 | |
| 33 | - public $mode; |
|
| 34 | - public $size; |
|
| 35 | - public $data; |
|
| 36 | - public $bstream; |
|
| 37 | - |
|
| 38 | - public function __construct($mode, $size, $data, $bstream = null) |
|
| 39 | - {
|
|
| 40 | - $setData = array_slice($data, 0, $size); |
|
| 33 | + public $mode; |
|
| 34 | + public $size; |
|
| 35 | + public $data; |
|
| 36 | + public $bstream; |
|
| 37 | + |
|
| 38 | + public function __construct($mode, $size, $data, $bstream = null) |
|
| 39 | + {
|
|
| 40 | + $setData = array_slice($data, 0, $size); |
|
| 41 | 41 | |
| 42 | - if (count($setData) < $size) {
|
|
| 43 | - $setData = array_merge($setData, array_fill(0,$size-count($setData),0)); |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - if(!QRinput::check($mode, $size, $setData)) {
|
|
| 47 | - throw new Exception('Error m:'.$mode.',s:'.$size.',d:'.join(',',$setData));
|
|
| 48 | - return null; |
|
| 49 | - } |
|
| 42 | + if (count($setData) < $size) {
|
|
| 43 | + $setData = array_merge($setData, array_fill(0,$size-count($setData),0)); |
|
| 44 | + } |
|
| 45 | + |
|
| 46 | + if(!QRinput::check($mode, $size, $setData)) {
|
|
| 47 | + throw new Exception('Error m:'.$mode.',s:'.$size.',d:'.join(',',$setData));
|
|
| 48 | + return null; |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - $this->mode = $mode; |
|
| 52 | - $this->size = $size; |
|
| 53 | - $this->data = $setData; |
|
| 54 | - $this->bstream = $bstream; |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - //---------------------------------------------------------------------- |
|
| 58 | - public function encodeModeNum($version) |
|
| 59 | - {
|
|
| 60 | - try {
|
|
| 51 | + $this->mode = $mode; |
|
| 52 | + $this->size = $size; |
|
| 53 | + $this->data = $setData; |
|
| 54 | + $this->bstream = $bstream; |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + //---------------------------------------------------------------------- |
|
| 58 | + public function encodeModeNum($version) |
|
| 59 | + {
|
|
| 60 | + try {
|
|
| 61 | 61 | |
| 62 | - $words = (int)($this->size / 3); |
|
| 63 | - $bs = new QRbitstream(); |
|
| 62 | + $words = (int)($this->size / 3); |
|
| 63 | + $bs = new QRbitstream(); |
|
| 64 | 64 | |
| 65 | - $val = 0x1; |
|
| 66 | - $bs->appendNum(4, $val); |
|
| 67 | - $bs->appendNum(QRspec::lengthIndicator(QR_MODE_NUM, $version), $this->size); |
|
| 68 | - |
|
| 69 | - for($i=0; $i<$words; $i++) {
|
|
| 70 | - $val = (ord($this->data[$i*3 ]) - ord('0')) * 100;
|
|
| 71 | - $val += (ord($this->data[$i*3+1]) - ord('0')) * 10;
|
|
| 72 | - $val += (ord($this->data[$i*3+2]) - ord('0'));
|
|
| 73 | - $bs->appendNum(10, $val); |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - if($this->size - $words * 3 == 1) {
|
|
| 77 | - $val = ord($this->data[$words*3]) - ord('0');
|
|
| 78 | - $bs->appendNum(4, $val); |
|
| 79 | - } else if($this->size - $words * 3 == 2) {
|
|
| 80 | - $val = (ord($this->data[$words*3 ]) - ord('0')) * 10;
|
|
| 81 | - $val += (ord($this->data[$words*3+1]) - ord('0'));
|
|
| 82 | - $bs->appendNum(7, $val); |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - $this->bstream = $bs; |
|
| 86 | - return 0; |
|
| 65 | + $val = 0x1; |
|
| 66 | + $bs->appendNum(4, $val); |
|
| 67 | + $bs->appendNum(QRspec::lengthIndicator(QR_MODE_NUM, $version), $this->size); |
|
| 68 | + |
|
| 69 | + for($i=0; $i<$words; $i++) {
|
|
| 70 | + $val = (ord($this->data[$i*3 ]) - ord('0')) * 100;
|
|
| 71 | + $val += (ord($this->data[$i*3+1]) - ord('0')) * 10;
|
|
| 72 | + $val += (ord($this->data[$i*3+2]) - ord('0'));
|
|
| 73 | + $bs->appendNum(10, $val); |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + if($this->size - $words * 3 == 1) {
|
|
| 77 | + $val = ord($this->data[$words*3]) - ord('0');
|
|
| 78 | + $bs->appendNum(4, $val); |
|
| 79 | + } else if($this->size - $words * 3 == 2) {
|
|
| 80 | + $val = (ord($this->data[$words*3 ]) - ord('0')) * 10;
|
|
| 81 | + $val += (ord($this->data[$words*3+1]) - ord('0'));
|
|
| 82 | + $bs->appendNum(7, $val); |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + $this->bstream = $bs; |
|
| 86 | + return 0; |
|
| 87 | 87 | |
| 88 | - } catch (Exception $e) {
|
|
| 89 | - return -1; |
|
| 90 | - } |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - //---------------------------------------------------------------------- |
|
| 94 | - public function encodeModeAn($version) |
|
| 95 | - {
|
|
| 96 | - try {
|
|
| 97 | - $words = (int)($this->size / 2); |
|
| 98 | - $bs = new QRbitstream(); |
|
| 88 | + } catch (Exception $e) {
|
|
| 89 | + return -1; |
|
| 90 | + } |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + //---------------------------------------------------------------------- |
|
| 94 | + public function encodeModeAn($version) |
|
| 95 | + {
|
|
| 96 | + try {
|
|
| 97 | + $words = (int)($this->size / 2); |
|
| 98 | + $bs = new QRbitstream(); |
|
| 99 | 99 | |
| 100 | - $bs->appendNum(4, 0x02); |
|
| 101 | - $bs->appendNum(QRspec::lengthIndicator(QR_MODE_AN, $version), $this->size); |
|
| 100 | + $bs->appendNum(4, 0x02); |
|
| 101 | + $bs->appendNum(QRspec::lengthIndicator(QR_MODE_AN, $version), $this->size); |
|
| 102 | 102 | |
| 103 | - for($i=0; $i<$words; $i++) {
|
|
| 104 | - $val = (int)QRinput::lookAnTable(ord($this->data[$i*2 ])) * 45; |
|
| 105 | - $val += (int)QRinput::lookAnTable(ord($this->data[$i*2+1])); |
|
| 103 | + for($i=0; $i<$words; $i++) {
|
|
| 104 | + $val = (int)QRinput::lookAnTable(ord($this->data[$i*2 ])) * 45; |
|
| 105 | + $val += (int)QRinput::lookAnTable(ord($this->data[$i*2+1])); |
|
| 106 | 106 | |
| 107 | - $bs->appendNum(11, $val); |
|
| 108 | - } |
|
| 107 | + $bs->appendNum(11, $val); |
|
| 108 | + } |
|
| 109 | 109 | |
| 110 | - if($this->size & 1) {
|
|
| 111 | - $val = QRinput::lookAnTable(ord($this->data[$words * 2])); |
|
| 112 | - $bs->appendNum(6, $val); |
|
| 113 | - } |
|
| 110 | + if($this->size & 1) {
|
|
| 111 | + $val = QRinput::lookAnTable(ord($this->data[$words * 2])); |
|
| 112 | + $bs->appendNum(6, $val); |
|
| 113 | + } |
|
| 114 | 114 | |
| 115 | - $this->bstream = $bs; |
|
| 116 | - return 0; |
|
| 115 | + $this->bstream = $bs; |
|
| 116 | + return 0; |
|
| 117 | 117 | |
| 118 | - } catch (Exception $e) {
|
|
| 119 | - return -1; |
|
| 120 | - } |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - //---------------------------------------------------------------------- |
|
| 124 | - public function encodeMode8($version) |
|
| 125 | - {
|
|
| 126 | - try {
|
|
| 127 | - $bs = new QRbitstream(); |
|
| 128 | - |
|
| 129 | - $bs->appendNum(4, 0x4); |
|
| 130 | - $bs->appendNum(QRspec::lengthIndicator(QR_MODE_8, $version), $this->size); |
|
| 131 | - |
|
| 132 | - for($i=0; $i<$this->size; $i++) {
|
|
| 133 | - $bs->appendNum(8, ord($this->data[$i])); |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - $this->bstream = $bs; |
|
| 137 | - return 0; |
|
| 118 | + } catch (Exception $e) {
|
|
| 119 | + return -1; |
|
| 120 | + } |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + //---------------------------------------------------------------------- |
|
| 124 | + public function encodeMode8($version) |
|
| 125 | + {
|
|
| 126 | + try {
|
|
| 127 | + $bs = new QRbitstream(); |
|
| 128 | + |
|
| 129 | + $bs->appendNum(4, 0x4); |
|
| 130 | + $bs->appendNum(QRspec::lengthIndicator(QR_MODE_8, $version), $this->size); |
|
| 131 | + |
|
| 132 | + for($i=0; $i<$this->size; $i++) {
|
|
| 133 | + $bs->appendNum(8, ord($this->data[$i])); |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + $this->bstream = $bs; |
|
| 137 | + return 0; |
|
| 138 | 138 | |
| 139 | - } catch (Exception $e) {
|
|
| 140 | - return -1; |
|
| 141 | - } |
|
| 142 | - } |
|
| 139 | + } catch (Exception $e) {
|
|
| 140 | + return -1; |
|
| 141 | + } |
|
| 142 | + } |
|
| 143 | 143 | |
| 144 | - //---------------------------------------------------------------------- |
|
| 145 | - public function encodeModeKanji($version) |
|
| 146 | - {
|
|
| 147 | - try {
|
|
| 144 | + //---------------------------------------------------------------------- |
|
| 145 | + public function encodeModeKanji($version) |
|
| 146 | + {
|
|
| 147 | + try {
|
|
| 148 | 148 | |
| 149 | - $bs = new QRbitrtream(); |
|
| 149 | + $bs = new QRbitrtream(); |
|
| 150 | 150 | |
| 151 | - $bs->appendNum(4, 0x8); |
|
| 152 | - $bs->appendNum(QRspec::lengthIndicator(QR_MODE_KANJI, $version), (int)($this->size / 2)); |
|
| 153 | - |
|
| 154 | - for($i=0; $i<$this->size; $i+=2) {
|
|
| 155 | - $val = (ord($this->data[$i]) << 8) | ord($this->data[$i+1]); |
|
| 156 | - if($val <= 0x9ffc) {
|
|
| 157 | - $val -= 0x8140; |
|
| 158 | - } else {
|
|
| 159 | - $val -= 0xc140; |
|
| 160 | - } |
|
| 151 | + $bs->appendNum(4, 0x8); |
|
| 152 | + $bs->appendNum(QRspec::lengthIndicator(QR_MODE_KANJI, $version), (int)($this->size / 2)); |
|
| 153 | + |
|
| 154 | + for($i=0; $i<$this->size; $i+=2) {
|
|
| 155 | + $val = (ord($this->data[$i]) << 8) | ord($this->data[$i+1]); |
|
| 156 | + if($val <= 0x9ffc) {
|
|
| 157 | + $val -= 0x8140; |
|
| 158 | + } else {
|
|
| 159 | + $val -= 0xc140; |
|
| 160 | + } |
|
| 161 | 161 | |
| 162 | - $h = ($val >> 8) * 0xc0; |
|
| 163 | - $val = ($val & 0xff) + $h; |
|
| 162 | + $h = ($val >> 8) * 0xc0; |
|
| 163 | + $val = ($val & 0xff) + $h; |
|
| 164 | 164 | |
| 165 | - $bs->appendNum(13, $val); |
|
| 166 | - } |
|
| 165 | + $bs->appendNum(13, $val); |
|
| 166 | + } |
|
| 167 | 167 | |
| 168 | - $this->bstream = $bs; |
|
| 169 | - return 0; |
|
| 168 | + $this->bstream = $bs; |
|
| 169 | + return 0; |
|
| 170 | 170 | |
| 171 | - } catch (Exception $e) {
|
|
| 172 | - return -1; |
|
| 173 | - } |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - //---------------------------------------------------------------------- |
|
| 177 | - public function encodeModeStructure() |
|
| 178 | - {
|
|
| 179 | - try {
|
|
| 180 | - $bs = new QRbitstream(); |
|
| 171 | + } catch (Exception $e) {
|
|
| 172 | + return -1; |
|
| 173 | + } |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + //---------------------------------------------------------------------- |
|
| 177 | + public function encodeModeStructure() |
|
| 178 | + {
|
|
| 179 | + try {
|
|
| 180 | + $bs = new QRbitstream(); |
|
| 181 | 181 | |
| 182 | - $bs->appendNum(4, 0x03); |
|
| 183 | - $bs->appendNum(4, ord($this->data[1]) - 1); |
|
| 184 | - $bs->appendNum(4, ord($this->data[0]) - 1); |
|
| 185 | - $bs->appendNum(8, ord($this->data[2])); |
|
| 182 | + $bs->appendNum(4, 0x03); |
|
| 183 | + $bs->appendNum(4, ord($this->data[1]) - 1); |
|
| 184 | + $bs->appendNum(4, ord($this->data[0]) - 1); |
|
| 185 | + $bs->appendNum(8, ord($this->data[2])); |
|
| 186 | 186 | |
| 187 | - $this->bstream = $bs; |
|
| 188 | - return 0; |
|
| 187 | + $this->bstream = $bs; |
|
| 188 | + return 0; |
|
| 189 | 189 | |
| 190 | - } catch (Exception $e) {
|
|
| 191 | - return -1; |
|
| 192 | - } |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - //---------------------------------------------------------------------- |
|
| 196 | - public function estimateBitStreamSizeOfEntry($version) |
|
| 197 | - {
|
|
| 198 | - $bits = 0; |
|
| 199 | - |
|
| 200 | - if($version == 0) |
|
| 201 | - $version = 1; |
|
| 202 | - |
|
| 203 | - switch($this->mode) {
|
|
| 204 | - case QR_MODE_NUM: $bits = QRinput::estimateBitsModeNum($this->size); break; |
|
| 205 | - case QR_MODE_AN: $bits = QRinput::estimateBitsModeAn($this->size); break; |
|
| 206 | - case QR_MODE_8: $bits = QRinput::estimateBitsMode8($this->size); break; |
|
| 207 | - case QR_MODE_KANJI: $bits = QRinput::estimateBitsModeKanji($this->size);break; |
|
| 208 | - case QR_MODE_STRUCTURE: return STRUCTURE_HEADER_BITS; |
|
| 209 | - default: |
|
| 210 | - return 0; |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - $l = QRspec::lengthIndicator($this->mode, $version); |
|
| 214 | - $m = 1 << $l; |
|
| 215 | - $num = (int)(($this->size + $m - 1) / $m); |
|
| 216 | - |
|
| 217 | - $bits += $num * (4 + $l); |
|
| 218 | - |
|
| 219 | - return $bits; |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - //---------------------------------------------------------------------- |
|
| 223 | - public function encodeBitStream($version) |
|
| 224 | - {
|
|
| 225 | - try {
|
|
| 190 | + } catch (Exception $e) {
|
|
| 191 | + return -1; |
|
| 192 | + } |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + //---------------------------------------------------------------------- |
|
| 196 | + public function estimateBitStreamSizeOfEntry($version) |
|
| 197 | + {
|
|
| 198 | + $bits = 0; |
|
| 199 | + |
|
| 200 | + if($version == 0) |
|
| 201 | + $version = 1; |
|
| 202 | + |
|
| 203 | + switch($this->mode) {
|
|
| 204 | + case QR_MODE_NUM: $bits = QRinput::estimateBitsModeNum($this->size); break; |
|
| 205 | + case QR_MODE_AN: $bits = QRinput::estimateBitsModeAn($this->size); break; |
|
| 206 | + case QR_MODE_8: $bits = QRinput::estimateBitsMode8($this->size); break; |
|
| 207 | + case QR_MODE_KANJI: $bits = QRinput::estimateBitsModeKanji($this->size);break; |
|
| 208 | + case QR_MODE_STRUCTURE: return STRUCTURE_HEADER_BITS; |
|
| 209 | + default: |
|
| 210 | + return 0; |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + $l = QRspec::lengthIndicator($this->mode, $version); |
|
| 214 | + $m = 1 << $l; |
|
| 215 | + $num = (int)(($this->size + $m - 1) / $m); |
|
| 216 | + |
|
| 217 | + $bits += $num * (4 + $l); |
|
| 218 | + |
|
| 219 | + return $bits; |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + //---------------------------------------------------------------------- |
|
| 223 | + public function encodeBitStream($version) |
|
| 224 | + {
|
|
| 225 | + try {
|
|
| 226 | 226 | |
| 227 | - unset($this->bstream); |
|
| 228 | - $words = QRspec::maximumWords($this->mode, $version); |
|
| 227 | + unset($this->bstream); |
|
| 228 | + $words = QRspec::maximumWords($this->mode, $version); |
|
| 229 | 229 | |
| 230 | - if($this->size > $words) {
|
|
| 230 | + if($this->size > $words) {
|
|
| 231 | 231 | |
| 232 | - $st1 = new QRinputItem($this->mode, $words, $this->data); |
|
| 233 | - $st2 = new QRinputItem($this->mode, $this->size - $words, array_slice($this->data, $words)); |
|
| 232 | + $st1 = new QRinputItem($this->mode, $words, $this->data); |
|
| 233 | + $st2 = new QRinputItem($this->mode, $this->size - $words, array_slice($this->data, $words)); |
|
| 234 | 234 | |
| 235 | - $st1->encodeBitStream($version); |
|
| 236 | - $st2->encodeBitStream($version); |
|
| 235 | + $st1->encodeBitStream($version); |
|
| 236 | + $st2->encodeBitStream($version); |
|
| 237 | 237 | |
| 238 | - $this->bstream = new QRbitstream(); |
|
| 239 | - $this->bstream->append($st1->bstream); |
|
| 240 | - $this->bstream->append($st2->bstream); |
|
| 238 | + $this->bstream = new QRbitstream(); |
|
| 239 | + $this->bstream->append($st1->bstream); |
|
| 240 | + $this->bstream->append($st2->bstream); |
|
| 241 | 241 | |
| 242 | - unset($st1); |
|
| 243 | - unset($st2); |
|
| 242 | + unset($st1); |
|
| 243 | + unset($st2); |
|
| 244 | 244 | |
| 245 | - } else {
|
|
| 245 | + } else {
|
|
| 246 | 246 | |
| 247 | - $ret = 0; |
|
| 247 | + $ret = 0; |
|
| 248 | 248 | |
| 249 | - switch($this->mode) {
|
|
| 250 | - case QR_MODE_NUM: $ret = $this->encodeModeNum($version); break; |
|
| 251 | - case QR_MODE_AN: $ret = $this->encodeModeAn($version); break; |
|
| 252 | - case QR_MODE_8: $ret = $this->encodeMode8($version); break; |
|
| 253 | - case QR_MODE_KANJI: $ret = $this->encodeModeKanji($version);break; |
|
| 254 | - case QR_MODE_STRUCTURE: $ret = $this->encodeModeStructure(); break; |
|
| 249 | + switch($this->mode) {
|
|
| 250 | + case QR_MODE_NUM: $ret = $this->encodeModeNum($version); break; |
|
| 251 | + case QR_MODE_AN: $ret = $this->encodeModeAn($version); break; |
|
| 252 | + case QR_MODE_8: $ret = $this->encodeMode8($version); break; |
|
| 253 | + case QR_MODE_KANJI: $ret = $this->encodeModeKanji($version);break; |
|
| 254 | + case QR_MODE_STRUCTURE: $ret = $this->encodeModeStructure(); break; |
|
| 255 | 255 | |
| 256 | - default: |
|
| 257 | - break; |
|
| 258 | - } |
|
| 256 | + default: |
|
| 257 | + break; |
|
| 258 | + } |
|
| 259 | 259 | |
| 260 | - if($ret < 0) |
|
| 261 | - return -1; |
|
| 262 | - } |
|
| 260 | + if($ret < 0) |
|
| 261 | + return -1; |
|
| 262 | + } |
|
| 263 | 263 | |
| 264 | - return $this->bstream->size(); |
|
| 264 | + return $this->bstream->size(); |
|
| 265 | 265 | |
| 266 | - } catch (Exception $e) {
|
|
| 267 | - return -1; |
|
| 268 | - } |
|
| 269 | - } |
|
| 270 | - }; |
|
| 266 | + } catch (Exception $e) {
|
|
| 267 | + return -1; |
|
| 268 | + } |
|
| 269 | + } |
|
| 270 | + }; |
|
| 271 | 271 | |
| 272 | - //########################################################################## |
|
| 272 | + //########################################################################## |
|
| 273 | 273 | |
| 274 | - class QRinput {
|
|
| 274 | + class QRinput {
|
|
| 275 | 275 | |
| 276 | - public $items; |
|
| 276 | + public $items; |
|
| 277 | 277 | |
| 278 | - private $version; |
|
| 279 | - private $level; |
|
| 278 | + private $version; |
|
| 279 | + private $level; |
|
| 280 | 280 | |
| 281 | - //---------------------------------------------------------------------- |
|
| 282 | - public function __construct($version = 0, $level = QR_ECLEVEL_L) |
|
| 283 | - {
|
|
| 284 | - if ($version < 0 || $version > QRSPEC_VERSION_MAX || $level > QR_ECLEVEL_H) {
|
|
| 285 | - throw new Exception('Invalid version no');
|
|
| 286 | - return NULL; |
|
| 287 | - } |
|
| 281 | + //---------------------------------------------------------------------- |
|
| 282 | + public function __construct($version = 0, $level = QR_ECLEVEL_L) |
|
| 283 | + {
|
|
| 284 | + if ($version < 0 || $version > QRSPEC_VERSION_MAX || $level > QR_ECLEVEL_H) {
|
|
| 285 | + throw new Exception('Invalid version no');
|
|
| 286 | + return NULL; |
|
| 287 | + } |
|
| 288 | 288 | |
| 289 | - $this->version = $version; |
|
| 290 | - $this->level = $level; |
|
| 291 | - } |
|
| 292 | - |
|
| 293 | - //---------------------------------------------------------------------- |
|
| 294 | - public function getVersion() |
|
| 295 | - {
|
|
| 296 | - return $this->version; |
|
| 297 | - } |
|
| 298 | - |
|
| 299 | - //---------------------------------------------------------------------- |
|
| 300 | - public function setVersion($version) |
|
| 301 | - {
|
|
| 302 | - if($version < 0 || $version > QRSPEC_VERSION_MAX) {
|
|
| 303 | - throw new Exception('Invalid version no');
|
|
| 304 | - return -1; |
|
| 305 | - } |
|
| 306 | - |
|
| 307 | - $this->version = $version; |
|
| 308 | - |
|
| 309 | - return 0; |
|
| 310 | - } |
|
| 311 | - |
|
| 312 | - //---------------------------------------------------------------------- |
|
| 313 | - public function getErrorCorrectionLevel() |
|
| 314 | - {
|
|
| 315 | - return $this->level; |
|
| 316 | - } |
|
| 317 | - |
|
| 318 | - //---------------------------------------------------------------------- |
|
| 319 | - public function setErrorCorrectionLevel($level) |
|
| 320 | - {
|
|
| 321 | - if($level > QR_ECLEVEL_H) {
|
|
| 322 | - throw new Exception('Invalid ECLEVEL');
|
|
| 323 | - return -1; |
|
| 324 | - } |
|
| 325 | - |
|
| 326 | - $this->level = $level; |
|
| 327 | - |
|
| 328 | - return 0; |
|
| 329 | - } |
|
| 330 | - |
|
| 331 | - //---------------------------------------------------------------------- |
|
| 332 | - public function appendEntry(QRinputItem $entry) |
|
| 333 | - {
|
|
| 334 | - $this->items[] = $entry; |
|
| 335 | - } |
|
| 336 | - |
|
| 337 | - //---------------------------------------------------------------------- |
|
| 338 | - public function append($mode, $size, $data) |
|
| 339 | - {
|
|
| 340 | - try {
|
|
| 341 | - $entry = new QRinputItem($mode, $size, $data); |
|
| 342 | - $this->items[] = $entry; |
|
| 343 | - return 0; |
|
| 344 | - } catch (Exception $e) {
|
|
| 345 | - return -1; |
|
| 346 | - } |
|
| 347 | - } |
|
| 348 | - |
|
| 349 | - //---------------------------------------------------------------------- |
|
| 350 | - |
|
| 351 | - public function insertStructuredAppendHeader($size, $index, $parity) |
|
| 352 | - {
|
|
| 353 | - if( $size > MAX_STRUCTURED_SYMBOLS ) {
|
|
| 354 | - throw new Exception('insertStructuredAppendHeader wrong size');
|
|
| 355 | - } |
|
| 289 | + $this->version = $version; |
|
| 290 | + $this->level = $level; |
|
| 291 | + } |
|
| 292 | + |
|
| 293 | + //---------------------------------------------------------------------- |
|
| 294 | + public function getVersion() |
|
| 295 | + {
|
|
| 296 | + return $this->version; |
|
| 297 | + } |
|
| 298 | + |
|
| 299 | + //---------------------------------------------------------------------- |
|
| 300 | + public function setVersion($version) |
|
| 301 | + {
|
|
| 302 | + if($version < 0 || $version > QRSPEC_VERSION_MAX) {
|
|
| 303 | + throw new Exception('Invalid version no');
|
|
| 304 | + return -1; |
|
| 305 | + } |
|
| 306 | + |
|
| 307 | + $this->version = $version; |
|
| 308 | + |
|
| 309 | + return 0; |
|
| 310 | + } |
|
| 311 | + |
|
| 312 | + //---------------------------------------------------------------------- |
|
| 313 | + public function getErrorCorrectionLevel() |
|
| 314 | + {
|
|
| 315 | + return $this->level; |
|
| 316 | + } |
|
| 317 | + |
|
| 318 | + //---------------------------------------------------------------------- |
|
| 319 | + public function setErrorCorrectionLevel($level) |
|
| 320 | + {
|
|
| 321 | + if($level > QR_ECLEVEL_H) {
|
|
| 322 | + throw new Exception('Invalid ECLEVEL');
|
|
| 323 | + return -1; |
|
| 324 | + } |
|
| 325 | + |
|
| 326 | + $this->level = $level; |
|
| 327 | + |
|
| 328 | + return 0; |
|
| 329 | + } |
|
| 330 | + |
|
| 331 | + //---------------------------------------------------------------------- |
|
| 332 | + public function appendEntry(QRinputItem $entry) |
|
| 333 | + {
|
|
| 334 | + $this->items[] = $entry; |
|
| 335 | + } |
|
| 336 | + |
|
| 337 | + //---------------------------------------------------------------------- |
|
| 338 | + public function append($mode, $size, $data) |
|
| 339 | + {
|
|
| 340 | + try {
|
|
| 341 | + $entry = new QRinputItem($mode, $size, $data); |
|
| 342 | + $this->items[] = $entry; |
|
| 343 | + return 0; |
|
| 344 | + } catch (Exception $e) {
|
|
| 345 | + return -1; |
|
| 346 | + } |
|
| 347 | + } |
|
| 348 | + |
|
| 349 | + //---------------------------------------------------------------------- |
|
| 350 | + |
|
| 351 | + public function insertStructuredAppendHeader($size, $index, $parity) |
|
| 352 | + {
|
|
| 353 | + if( $size > MAX_STRUCTURED_SYMBOLS ) {
|
|
| 354 | + throw new Exception('insertStructuredAppendHeader wrong size');
|
|
| 355 | + } |
|
| 356 | 356 | |
| 357 | - if( $index <= 0 || $index > MAX_STRUCTURED_SYMBOLS ) {
|
|
| 358 | - throw new Exception('insertStructuredAppendHeader wrong index');
|
|
| 359 | - } |
|
| 357 | + if( $index <= 0 || $index > MAX_STRUCTURED_SYMBOLS ) {
|
|
| 358 | + throw new Exception('insertStructuredAppendHeader wrong index');
|
|
| 359 | + } |
|
| 360 | 360 | |
| 361 | - $buf = array($size, $index, $parity); |
|
| 361 | + $buf = array($size, $index, $parity); |
|
| 362 | 362 | |
| 363 | - try {
|
|
| 364 | - $entry = new QRinputItem(QR_MODE_STRUCTURE, 3, buf); |
|
| 365 | - array_unshift($this->items, $entry); |
|
| 366 | - return 0; |
|
| 367 | - } catch (Exception $e) {
|
|
| 368 | - return -1; |
|
| 369 | - } |
|
| 370 | - } |
|
| 371 | - |
|
| 372 | - //---------------------------------------------------------------------- |
|
| 373 | - public function calcParity() |
|
| 374 | - {
|
|
| 375 | - $parity = 0; |
|
| 363 | + try {
|
|
| 364 | + $entry = new QRinputItem(QR_MODE_STRUCTURE, 3, buf); |
|
| 365 | + array_unshift($this->items, $entry); |
|
| 366 | + return 0; |
|
| 367 | + } catch (Exception $e) {
|
|
| 368 | + return -1; |
|
| 369 | + } |
|
| 370 | + } |
|
| 371 | + |
|
| 372 | + //---------------------------------------------------------------------- |
|
| 373 | + public function calcParity() |
|
| 374 | + {
|
|
| 375 | + $parity = 0; |
|
| 376 | 376 | |
| 377 | - foreach($this->items as $item) {
|
|
| 378 | - if($item->mode != QR_MODE_STRUCTURE) {
|
|
| 379 | - for($i=$item->size-1; $i>=0; $i--) {
|
|
| 380 | - $parity ^= $item->data[$i]; |
|
| 381 | - } |
|
| 382 | - } |
|
| 383 | - } |
|
| 384 | - |
|
| 385 | - return $parity; |
|
| 386 | - } |
|
| 387 | - |
|
| 388 | - //---------------------------------------------------------------------- |
|
| 389 | - public static function checkModeNum($size, $data) |
|
| 390 | - {
|
|
| 391 | - for($i=0; $i<$size; $i++) {
|
|
| 392 | - if((ord($data[$i]) < ord('0')) || (ord($data[$i]) > ord('9'))){
|
|
| 393 | - return false; |
|
| 394 | - } |
|
| 395 | - } |
|
| 396 | - |
|
| 397 | - return true; |
|
| 398 | - } |
|
| 399 | - |
|
| 400 | - //---------------------------------------------------------------------- |
|
| 401 | - public static function estimateBitsModeNum($size) |
|
| 402 | - {
|
|
| 403 | - $w = (int)$size / 3; |
|
| 404 | - $bits = $w * 10; |
|
| 377 | + foreach($this->items as $item) {
|
|
| 378 | + if($item->mode != QR_MODE_STRUCTURE) {
|
|
| 379 | + for($i=$item->size-1; $i>=0; $i--) {
|
|
| 380 | + $parity ^= $item->data[$i]; |
|
| 381 | + } |
|
| 382 | + } |
|
| 383 | + } |
|
| 384 | + |
|
| 385 | + return $parity; |
|
| 386 | + } |
|
| 387 | + |
|
| 388 | + //---------------------------------------------------------------------- |
|
| 389 | + public static function checkModeNum($size, $data) |
|
| 390 | + {
|
|
| 391 | + for($i=0; $i<$size; $i++) {
|
|
| 392 | + if((ord($data[$i]) < ord('0')) || (ord($data[$i]) > ord('9'))){
|
|
| 393 | + return false; |
|
| 394 | + } |
|
| 395 | + } |
|
| 396 | + |
|
| 397 | + return true; |
|
| 398 | + } |
|
| 399 | + |
|
| 400 | + //---------------------------------------------------------------------- |
|
| 401 | + public static function estimateBitsModeNum($size) |
|
| 402 | + {
|
|
| 403 | + $w = (int)$size / 3; |
|
| 404 | + $bits = $w * 10; |
|
| 405 | 405 | |
| 406 | - switch($size - $w * 3) {
|
|
| 407 | - case 1: |
|
| 408 | - $bits += 4; |
|
| 409 | - break; |
|
| 410 | - case 2: |
|
| 411 | - $bits += 7; |
|
| 412 | - break; |
|
| 413 | - default: |
|
| 414 | - break; |
|
| 415 | - } |
|
| 416 | - |
|
| 417 | - return $bits; |
|
| 418 | - } |
|
| 419 | - |
|
| 420 | - //---------------------------------------------------------------------- |
|
| 421 | - public static $anTable = array( |
|
| 422 | - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
|
| 423 | - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
|
| 424 | - 36, -1, -1, -1, 37, 38, -1, -1, -1, -1, 39, 40, -1, 41, 42, 43, |
|
| 425 | - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 44, -1, -1, -1, -1, -1, |
|
| 426 | - -1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, |
|
| 427 | - 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, -1, -1, -1, -1, -1, |
|
| 428 | - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
|
| 429 | - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 |
|
| 430 | - ); |
|
| 431 | - |
|
| 432 | - //---------------------------------------------------------------------- |
|
| 433 | - public static function lookAnTable($c) |
|
| 434 | - {
|
|
| 435 | - return (($c > 127)?-1:self::$anTable[$c]); |
|
| 436 | - } |
|
| 437 | - |
|
| 438 | - //---------------------------------------------------------------------- |
|
| 439 | - public static function checkModeAn($size, $data) |
|
| 440 | - {
|
|
| 441 | - for($i=0; $i<$size; $i++) {
|
|
| 442 | - if (self::lookAnTable(ord($data[$i])) == -1) {
|
|
| 443 | - return false; |
|
| 444 | - } |
|
| 445 | - } |
|
| 446 | - |
|
| 447 | - return true; |
|
| 448 | - } |
|
| 449 | - |
|
| 450 | - //---------------------------------------------------------------------- |
|
| 451 | - public static function estimateBitsModeAn($size) |
|
| 452 | - {
|
|
| 453 | - $w = (int)($size / 2); |
|
| 454 | - $bits = $w * 11; |
|
| 406 | + switch($size - $w * 3) {
|
|
| 407 | + case 1: |
|
| 408 | + $bits += 4; |
|
| 409 | + break; |
|
| 410 | + case 2: |
|
| 411 | + $bits += 7; |
|
| 412 | + break; |
|
| 413 | + default: |
|
| 414 | + break; |
|
| 415 | + } |
|
| 416 | + |
|
| 417 | + return $bits; |
|
| 418 | + } |
|
| 419 | + |
|
| 420 | + //---------------------------------------------------------------------- |
|
| 421 | + public static $anTable = array( |
|
| 422 | + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
|
| 423 | + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
|
| 424 | + 36, -1, -1, -1, 37, 38, -1, -1, -1, -1, 39, 40, -1, 41, 42, 43, |
|
| 425 | + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 44, -1, -1, -1, -1, -1, |
|
| 426 | + -1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, |
|
| 427 | + 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, -1, -1, -1, -1, -1, |
|
| 428 | + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
|
| 429 | + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 |
|
| 430 | + ); |
|
| 431 | + |
|
| 432 | + //---------------------------------------------------------------------- |
|
| 433 | + public static function lookAnTable($c) |
|
| 434 | + {
|
|
| 435 | + return (($c > 127)?-1:self::$anTable[$c]); |
|
| 436 | + } |
|
| 437 | + |
|
| 438 | + //---------------------------------------------------------------------- |
|
| 439 | + public static function checkModeAn($size, $data) |
|
| 440 | + {
|
|
| 441 | + for($i=0; $i<$size; $i++) {
|
|
| 442 | + if (self::lookAnTable(ord($data[$i])) == -1) {
|
|
| 443 | + return false; |
|
| 444 | + } |
|
| 445 | + } |
|
| 446 | + |
|
| 447 | + return true; |
|
| 448 | + } |
|
| 449 | + |
|
| 450 | + //---------------------------------------------------------------------- |
|
| 451 | + public static function estimateBitsModeAn($size) |
|
| 452 | + {
|
|
| 453 | + $w = (int)($size / 2); |
|
| 454 | + $bits = $w * 11; |
|
| 455 | 455 | |
| 456 | - if($size & 1) {
|
|
| 457 | - $bits += 6; |
|
| 458 | - } |
|
| 456 | + if($size & 1) {
|
|
| 457 | + $bits += 6; |
|
| 458 | + } |
|
| 459 | 459 | |
| 460 | - return $bits; |
|
| 461 | - } |
|
| 460 | + return $bits; |
|
| 461 | + } |
|
| 462 | 462 | |
| 463 | - //---------------------------------------------------------------------- |
|
| 464 | - public static function estimateBitsMode8($size) |
|
| 465 | - {
|
|
| 466 | - return $size * 8; |
|
| 467 | - } |
|
| 468 | - |
|
| 469 | - //---------------------------------------------------------------------- |
|
| 470 | - public function estimateBitsModeKanji($size) |
|
| 471 | - {
|
|
| 472 | - return (int)(($size / 2) * 13); |
|
| 473 | - } |
|
| 474 | - |
|
| 475 | - //---------------------------------------------------------------------- |
|
| 476 | - public static function checkModeKanji($size, $data) |
|
| 477 | - {
|
|
| 478 | - if($size & 1) |
|
| 479 | - return false; |
|
| 480 | - |
|
| 481 | - for($i=0; $i<$size; $i+=2) {
|
|
| 482 | - $val = (ord($data[$i]) << 8) | ord($data[$i+1]); |
|
| 483 | - if( $val < 0x8140 |
|
| 484 | - || ($val > 0x9ffc && $val < 0xe040) |
|
| 485 | - || $val > 0xebbf) {
|
|
| 486 | - return false; |
|
| 487 | - } |
|
| 488 | - } |
|
| 489 | - |
|
| 490 | - return true; |
|
| 491 | - } |
|
| 492 | - |
|
| 493 | - /*********************************************************************** |
|
| 463 | + //---------------------------------------------------------------------- |
|
| 464 | + public static function estimateBitsMode8($size) |
|
| 465 | + {
|
|
| 466 | + return $size * 8; |
|
| 467 | + } |
|
| 468 | + |
|
| 469 | + //---------------------------------------------------------------------- |
|
| 470 | + public function estimateBitsModeKanji($size) |
|
| 471 | + {
|
|
| 472 | + return (int)(($size / 2) * 13); |
|
| 473 | + } |
|
| 474 | + |
|
| 475 | + //---------------------------------------------------------------------- |
|
| 476 | + public static function checkModeKanji($size, $data) |
|
| 477 | + {
|
|
| 478 | + if($size & 1) |
|
| 479 | + return false; |
|
| 480 | + |
|
| 481 | + for($i=0; $i<$size; $i+=2) {
|
|
| 482 | + $val = (ord($data[$i]) << 8) | ord($data[$i+1]); |
|
| 483 | + if( $val < 0x8140 |
|
| 484 | + || ($val > 0x9ffc && $val < 0xe040) |
|
| 485 | + || $val > 0xebbf) {
|
|
| 486 | + return false; |
|
| 487 | + } |
|
| 488 | + } |
|
| 489 | + |
|
| 490 | + return true; |
|
| 491 | + } |
|
| 492 | + |
|
| 493 | + /*********************************************************************** |
|
| 494 | 494 | * Validation |
| 495 | 495 | **********************************************************************/ |
| 496 | 496 | |
| 497 | - public static function check($mode, $size, $data) |
|
| 498 | - {
|
|
| 499 | - if($size <= 0) |
|
| 500 | - return false; |
|
| 501 | - |
|
| 502 | - switch($mode) {
|
|
| 503 | - case QR_MODE_NUM: return self::checkModeNum($size, $data); break; |
|
| 504 | - case QR_MODE_AN: return self::checkModeAn($size, $data); break; |
|
| 505 | - case QR_MODE_KANJI: return self::checkModeKanji($size, $data); break; |
|
| 506 | - case QR_MODE_8: return true; break; |
|
| 507 | - case QR_MODE_STRUCTURE: return true; break; |
|
| 497 | + public static function check($mode, $size, $data) |
|
| 498 | + {
|
|
| 499 | + if($size <= 0) |
|
| 500 | + return false; |
|
| 501 | + |
|
| 502 | + switch($mode) {
|
|
| 503 | + case QR_MODE_NUM: return self::checkModeNum($size, $data); break; |
|
| 504 | + case QR_MODE_AN: return self::checkModeAn($size, $data); break; |
|
| 505 | + case QR_MODE_KANJI: return self::checkModeKanji($size, $data); break; |
|
| 506 | + case QR_MODE_8: return true; break; |
|
| 507 | + case QR_MODE_STRUCTURE: return true; break; |
|
| 508 | 508 | |
| 509 | - default: |
|
| 510 | - break; |
|
| 511 | - } |
|
| 512 | - |
|
| 513 | - return false; |
|
| 514 | - } |
|
| 515 | - |
|
| 516 | - |
|
| 517 | - //---------------------------------------------------------------------- |
|
| 518 | - public function estimateBitStreamSize($version) |
|
| 519 | - {
|
|
| 520 | - $bits = 0; |
|
| 521 | - |
|
| 522 | - foreach($this->items as $item) {
|
|
| 523 | - $bits += $item->estimateBitStreamSizeOfEntry($version); |
|
| 524 | - } |
|
| 525 | - |
|
| 526 | - return $bits; |
|
| 527 | - } |
|
| 528 | - |
|
| 529 | - //---------------------------------------------------------------------- |
|
| 530 | - public function estimateVersion() |
|
| 531 | - {
|
|
| 532 | - $version = 0; |
|
| 533 | - $prev = 0; |
|
| 534 | - do {
|
|
| 535 | - $prev = $version; |
|
| 536 | - $bits = $this->estimateBitStreamSize($prev); |
|
| 537 | - $version = QRspec::getMinimumVersion((int)(($bits + 7) / 8), $this->level); |
|
| 538 | - if ($version < 0) {
|
|
| 539 | - return -1; |
|
| 540 | - } |
|
| 541 | - } while ($version > $prev); |
|
| 542 | - |
|
| 543 | - return $version; |
|
| 544 | - } |
|
| 545 | - |
|
| 546 | - //---------------------------------------------------------------------- |
|
| 547 | - public static function lengthOfCode($mode, $version, $bits) |
|
| 548 | - {
|
|
| 549 | - $payload = $bits - 4 - QRspec::lengthIndicator($mode, $version); |
|
| 550 | - switch($mode) {
|
|
| 551 | - case QR_MODE_NUM: |
|
| 552 | - $chunks = (int)($payload / 10); |
|
| 553 | - $remain = $payload - $chunks * 10; |
|
| 554 | - $size = $chunks * 3; |
|
| 555 | - if($remain >= 7) {
|
|
| 556 | - $size += 2; |
|
| 557 | - } else if($remain >= 4) {
|
|
| 558 | - $size += 1; |
|
| 559 | - } |
|
| 560 | - break; |
|
| 561 | - case QR_MODE_AN: |
|
| 562 | - $chunks = (int)($payload / 11); |
|
| 563 | - $remain = $payload - $chunks * 11; |
|
| 564 | - $size = $chunks * 2; |
|
| 565 | - if($remain >= 6) |
|
| 566 | - $size++; |
|
| 567 | - break; |
|
| 568 | - case QR_MODE_8: |
|
| 569 | - $size = (int)($payload / 8); |
|
| 570 | - break; |
|
| 571 | - case QR_MODE_KANJI: |
|
| 572 | - $size = (int)(($payload / 13) * 2); |
|
| 573 | - break; |
|
| 574 | - case QR_MODE_STRUCTURE: |
|
| 575 | - $size = (int)($payload / 8); |
|
| 576 | - break; |
|
| 577 | - default: |
|
| 578 | - $size = 0; |
|
| 579 | - break; |
|
| 580 | - } |
|
| 509 | + default: |
|
| 510 | + break; |
|
| 511 | + } |
|
| 512 | + |
|
| 513 | + return false; |
|
| 514 | + } |
|
| 515 | + |
|
| 516 | + |
|
| 517 | + //---------------------------------------------------------------------- |
|
| 518 | + public function estimateBitStreamSize($version) |
|
| 519 | + {
|
|
| 520 | + $bits = 0; |
|
| 521 | + |
|
| 522 | + foreach($this->items as $item) {
|
|
| 523 | + $bits += $item->estimateBitStreamSizeOfEntry($version); |
|
| 524 | + } |
|
| 525 | + |
|
| 526 | + return $bits; |
|
| 527 | + } |
|
| 528 | + |
|
| 529 | + //---------------------------------------------------------------------- |
|
| 530 | + public function estimateVersion() |
|
| 531 | + {
|
|
| 532 | + $version = 0; |
|
| 533 | + $prev = 0; |
|
| 534 | + do {
|
|
| 535 | + $prev = $version; |
|
| 536 | + $bits = $this->estimateBitStreamSize($prev); |
|
| 537 | + $version = QRspec::getMinimumVersion((int)(($bits + 7) / 8), $this->level); |
|
| 538 | + if ($version < 0) {
|
|
| 539 | + return -1; |
|
| 540 | + } |
|
| 541 | + } while ($version > $prev); |
|
| 542 | + |
|
| 543 | + return $version; |
|
| 544 | + } |
|
| 545 | + |
|
| 546 | + //---------------------------------------------------------------------- |
|
| 547 | + public static function lengthOfCode($mode, $version, $bits) |
|
| 548 | + {
|
|
| 549 | + $payload = $bits - 4 - QRspec::lengthIndicator($mode, $version); |
|
| 550 | + switch($mode) {
|
|
| 551 | + case QR_MODE_NUM: |
|
| 552 | + $chunks = (int)($payload / 10); |
|
| 553 | + $remain = $payload - $chunks * 10; |
|
| 554 | + $size = $chunks * 3; |
|
| 555 | + if($remain >= 7) {
|
|
| 556 | + $size += 2; |
|
| 557 | + } else if($remain >= 4) {
|
|
| 558 | + $size += 1; |
|
| 559 | + } |
|
| 560 | + break; |
|
| 561 | + case QR_MODE_AN: |
|
| 562 | + $chunks = (int)($payload / 11); |
|
| 563 | + $remain = $payload - $chunks * 11; |
|
| 564 | + $size = $chunks * 2; |
|
| 565 | + if($remain >= 6) |
|
| 566 | + $size++; |
|
| 567 | + break; |
|
| 568 | + case QR_MODE_8: |
|
| 569 | + $size = (int)($payload / 8); |
|
| 570 | + break; |
|
| 571 | + case QR_MODE_KANJI: |
|
| 572 | + $size = (int)(($payload / 13) * 2); |
|
| 573 | + break; |
|
| 574 | + case QR_MODE_STRUCTURE: |
|
| 575 | + $size = (int)($payload / 8); |
|
| 576 | + break; |
|
| 577 | + default: |
|
| 578 | + $size = 0; |
|
| 579 | + break; |
|
| 580 | + } |
|
| 581 | 581 | |
| 582 | - $maxsize = QRspec::maximumWords($mode, $version); |
|
| 583 | - if($size < 0) $size = 0; |
|
| 584 | - if($size > $maxsize) $size = $maxsize; |
|
| 582 | + $maxsize = QRspec::maximumWords($mode, $version); |
|
| 583 | + if($size < 0) $size = 0; |
|
| 584 | + if($size > $maxsize) $size = $maxsize; |
|
| 585 | 585 | |
| 586 | - return $size; |
|
| 587 | - } |
|
| 586 | + return $size; |
|
| 587 | + } |
|
| 588 | 588 | |
| 589 | - //---------------------------------------------------------------------- |
|
| 590 | - public function createBitStream() |
|
| 591 | - {
|
|
| 592 | - $total = 0; |
|
| 589 | + //---------------------------------------------------------------------- |
|
| 590 | + public function createBitStream() |
|
| 591 | + {
|
|
| 592 | + $total = 0; |
|
| 593 | 593 | |
| 594 | - foreach($this->items as $item) {
|
|
| 595 | - $bits = $item->encodeBitStream($this->version); |
|
| 594 | + foreach($this->items as $item) {
|
|
| 595 | + $bits = $item->encodeBitStream($this->version); |
|
| 596 | 596 | |
| 597 | - if($bits < 0) |
|
| 598 | - return -1; |
|
| 597 | + if($bits < 0) |
|
| 598 | + return -1; |
|
| 599 | 599 | |
| 600 | - $total += $bits; |
|
| 601 | - } |
|
| 602 | - |
|
| 603 | - return $total; |
|
| 604 | - } |
|
| 605 | - |
|
| 606 | - //---------------------------------------------------------------------- |
|
| 607 | - public function convertData() |
|
| 608 | - {
|
|
| 609 | - $ver = $this->estimateVersion(); |
|
| 610 | - if($ver > $this->getVersion()) {
|
|
| 611 | - $this->setVersion($ver); |
|
| 612 | - } |
|
| 613 | - |
|
| 614 | - for(;;) {
|
|
| 615 | - $bits = $this->createBitStream(); |
|
| 600 | + $total += $bits; |
|
| 601 | + } |
|
| 602 | + |
|
| 603 | + return $total; |
|
| 604 | + } |
|
| 605 | + |
|
| 606 | + //---------------------------------------------------------------------- |
|
| 607 | + public function convertData() |
|
| 608 | + {
|
|
| 609 | + $ver = $this->estimateVersion(); |
|
| 610 | + if($ver > $this->getVersion()) {
|
|
| 611 | + $this->setVersion($ver); |
|
| 612 | + } |
|
| 613 | + |
|
| 614 | + for(;;) {
|
|
| 615 | + $bits = $this->createBitStream(); |
|
| 616 | 616 | |
| 617 | - if($bits < 0) |
|
| 618 | - return -1; |
|
| 617 | + if($bits < 0) |
|
| 618 | + return -1; |
|
| 619 | 619 | |
| 620 | - $ver = QRspec::getMinimumVersion((int)(($bits + 7) / 8), $this->level); |
|
| 621 | - if($ver < 0) {
|
|
| 622 | - throw new Exception('WRONG VERSION');
|
|
| 623 | - return -1; |
|
| 624 | - } else if($ver > $this->getVersion()) {
|
|
| 625 | - $this->setVersion($ver); |
|
| 626 | - } else {
|
|
| 627 | - break; |
|
| 628 | - } |
|
| 629 | - } |
|
| 630 | - |
|
| 631 | - return 0; |
|
| 632 | - } |
|
| 633 | - |
|
| 634 | - //---------------------------------------------------------------------- |
|
| 635 | - public function appendPaddingBit(&$bstream) |
|
| 636 | - {
|
|
| 637 | - $bits = $bstream->size(); |
|
| 638 | - $maxwords = QRspec::getDataLength($this->version, $this->level); |
|
| 639 | - $maxbits = $maxwords * 8; |
|
| 640 | - |
|
| 641 | - if ($maxbits == $bits) {
|
|
| 642 | - return 0; |
|
| 643 | - } |
|
| 644 | - |
|
| 645 | - if ($maxbits - $bits < 5) {
|
|
| 646 | - return $bstream->appendNum($maxbits - $bits, 0); |
|
| 647 | - } |
|
| 648 | - |
|
| 649 | - $bits += 4; |
|
| 650 | - $words = (int)(($bits + 7) / 8); |
|
| 651 | - |
|
| 652 | - $padding = new QRbitstream(); |
|
| 653 | - $ret = $padding->appendNum($words * 8 - $bits + 4, 0); |
|
| 620 | + $ver = QRspec::getMinimumVersion((int)(($bits + 7) / 8), $this->level); |
|
| 621 | + if($ver < 0) {
|
|
| 622 | + throw new Exception('WRONG VERSION');
|
|
| 623 | + return -1; |
|
| 624 | + } else if($ver > $this->getVersion()) {
|
|
| 625 | + $this->setVersion($ver); |
|
| 626 | + } else {
|
|
| 627 | + break; |
|
| 628 | + } |
|
| 629 | + } |
|
| 630 | + |
|
| 631 | + return 0; |
|
| 632 | + } |
|
| 633 | + |
|
| 634 | + //---------------------------------------------------------------------- |
|
| 635 | + public function appendPaddingBit(&$bstream) |
|
| 636 | + {
|
|
| 637 | + $bits = $bstream->size(); |
|
| 638 | + $maxwords = QRspec::getDataLength($this->version, $this->level); |
|
| 639 | + $maxbits = $maxwords * 8; |
|
| 640 | + |
|
| 641 | + if ($maxbits == $bits) {
|
|
| 642 | + return 0; |
|
| 643 | + } |
|
| 644 | + |
|
| 645 | + if ($maxbits - $bits < 5) {
|
|
| 646 | + return $bstream->appendNum($maxbits - $bits, 0); |
|
| 647 | + } |
|
| 648 | + |
|
| 649 | + $bits += 4; |
|
| 650 | + $words = (int)(($bits + 7) / 8); |
|
| 651 | + |
|
| 652 | + $padding = new QRbitstream(); |
|
| 653 | + $ret = $padding->appendNum($words * 8 - $bits + 4, 0); |
|
| 654 | 654 | |
| 655 | - if($ret < 0) |
|
| 656 | - return $ret; |
|
| 655 | + if($ret < 0) |
|
| 656 | + return $ret; |
|
| 657 | 657 | |
| 658 | - $padlen = $maxwords - $words; |
|
| 658 | + $padlen = $maxwords - $words; |
|
| 659 | 659 | |
| 660 | - if($padlen > 0) {
|
|
| 660 | + if($padlen > 0) {
|
|
| 661 | 661 | |
| 662 | - $padbuf = array(); |
|
| 663 | - for($i=0; $i<$padlen; $i++) {
|
|
| 664 | - $padbuf[$i] = ($i&1)?0x11:0xec; |
|
| 665 | - } |
|
| 662 | + $padbuf = array(); |
|
| 663 | + for($i=0; $i<$padlen; $i++) {
|
|
| 664 | + $padbuf[$i] = ($i&1)?0x11:0xec; |
|
| 665 | + } |
|
| 666 | 666 | |
| 667 | - $ret = $padding->appendBytes($padlen, $padbuf); |
|
| 667 | + $ret = $padding->appendBytes($padlen, $padbuf); |
|
| 668 | 668 | |
| 669 | - if($ret < 0) |
|
| 670 | - return $ret; |
|
| 669 | + if($ret < 0) |
|
| 670 | + return $ret; |
|
| 671 | 671 | |
| 672 | - } |
|
| 672 | + } |
|
| 673 | 673 | |
| 674 | - $ret = $bstream->append($padding); |
|
| 674 | + $ret = $bstream->append($padding); |
|
| 675 | 675 | |
| 676 | - return $ret; |
|
| 677 | - } |
|
| 676 | + return $ret; |
|
| 677 | + } |
|
| 678 | 678 | |
| 679 | - //---------------------------------------------------------------------- |
|
| 680 | - public function mergeBitStream() |
|
| 681 | - {
|
|
| 682 | - if($this->convertData() < 0) {
|
|
| 683 | - return null; |
|
| 684 | - } |
|
| 679 | + //---------------------------------------------------------------------- |
|
| 680 | + public function mergeBitStream() |
|
| 681 | + {
|
|
| 682 | + if($this->convertData() < 0) {
|
|
| 683 | + return null; |
|
| 684 | + } |
|
| 685 | 685 | |
| 686 | - $bstream = new QRbitstream(); |
|
| 686 | + $bstream = new QRbitstream(); |
|
| 687 | 687 | |
| 688 | - foreach($this->items as $item) {
|
|
| 689 | - $ret = $bstream->append($item->bstream); |
|
| 690 | - if($ret < 0) {
|
|
| 691 | - return null; |
|
| 692 | - } |
|
| 693 | - } |
|
| 688 | + foreach($this->items as $item) {
|
|
| 689 | + $ret = $bstream->append($item->bstream); |
|
| 690 | + if($ret < 0) {
|
|
| 691 | + return null; |
|
| 692 | + } |
|
| 693 | + } |
|
| 694 | 694 | |
| 695 | - return $bstream; |
|
| 696 | - } |
|
| 695 | + return $bstream; |
|
| 696 | + } |
|
| 697 | 697 | |
| 698 | - //---------------------------------------------------------------------- |
|
| 699 | - public function getBitStream() |
|
| 700 | - {
|
|
| 698 | + //---------------------------------------------------------------------- |
|
| 699 | + public function getBitStream() |
|
| 700 | + {
|
|
| 701 | 701 | |
| 702 | - $bstream = $this->mergeBitStream(); |
|
| 702 | + $bstream = $this->mergeBitStream(); |
|
| 703 | 703 | |
| 704 | - if($bstream == null) {
|
|
| 705 | - return null; |
|
| 706 | - } |
|
| 704 | + if($bstream == null) {
|
|
| 705 | + return null; |
|
| 706 | + } |
|
| 707 | 707 | |
| 708 | - $ret = $this->appendPaddingBit($bstream); |
|
| 709 | - if($ret < 0) {
|
|
| 710 | - return null; |
|
| 711 | - } |
|
| 712 | - |
|
| 713 | - return $bstream; |
|
| 714 | - } |
|
| 715 | - |
|
| 716 | - //---------------------------------------------------------------------- |
|
| 717 | - public function getByteStream() |
|
| 718 | - {
|
|
| 719 | - $bstream = $this->getBitStream(); |
|
| 720 | - if($bstream == null) {
|
|
| 721 | - return null; |
|
| 722 | - } |
|
| 708 | + $ret = $this->appendPaddingBit($bstream); |
|
| 709 | + if($ret < 0) {
|
|
| 710 | + return null; |
|
| 711 | + } |
|
| 712 | + |
|
| 713 | + return $bstream; |
|
| 714 | + } |
|
| 715 | + |
|
| 716 | + //---------------------------------------------------------------------- |
|
| 717 | + public function getByteStream() |
|
| 718 | + {
|
|
| 719 | + $bstream = $this->getBitStream(); |
|
| 720 | + if($bstream == null) {
|
|
| 721 | + return null; |
|
| 722 | + } |
|
| 723 | 723 | |
| 724 | - return $bstream->toByte(); |
|
| 725 | - } |
|
| 726 | - } |
|
| 724 | + return $bstream->toByte(); |
|
| 725 | + } |
|
| 726 | + } |
|
| 727 | 727 | |
| 728 | 728 | |
| 729 | - |
|
| 730 | 729 | \ No newline at end of file |
| 730 | + |
|
| 731 | 731 | \ No newline at end of file |
@@ -201,13 +201,13 @@ discard block |
||
| 201 | 201 | $version = 1; |
| 202 | 202 | |
| 203 | 203 | switch($this->mode) {
|
| 204 | - case QR_MODE_NUM: $bits = QRinput::estimateBitsModeNum($this->size); break; |
|
| 205 | - case QR_MODE_AN: $bits = QRinput::estimateBitsModeAn($this->size); break; |
|
| 206 | - case QR_MODE_8: $bits = QRinput::estimateBitsMode8($this->size); break; |
|
| 207 | - case QR_MODE_KANJI: $bits = QRinput::estimateBitsModeKanji($this->size);break; |
|
| 208 | - case QR_MODE_STRUCTURE: return STRUCTURE_HEADER_BITS; |
|
| 209 | - default: |
|
| 210 | - return 0; |
|
| 204 | + case QR_MODE_NUM: $bits = QRinput::estimateBitsModeNum($this->size); break; |
|
| 205 | + case QR_MODE_AN: $bits = QRinput::estimateBitsModeAn($this->size); break; |
|
| 206 | + case QR_MODE_8: $bits = QRinput::estimateBitsMode8($this->size); break; |
|
| 207 | + case QR_MODE_KANJI: $bits = QRinput::estimateBitsModeKanji($this->size);break; |
|
| 208 | + case QR_MODE_STRUCTURE: return STRUCTURE_HEADER_BITS; |
|
| 209 | + default: |
|
| 210 | + return 0; |
|
| 211 | 211 | } |
| 212 | 212 | |
| 213 | 213 | $l = QRspec::lengthIndicator($this->mode, $version); |
@@ -247,14 +247,14 @@ discard block |
||
| 247 | 247 | $ret = 0; |
| 248 | 248 | |
| 249 | 249 | switch($this->mode) {
|
| 250 | - case QR_MODE_NUM: $ret = $this->encodeModeNum($version); break; |
|
| 251 | - case QR_MODE_AN: $ret = $this->encodeModeAn($version); break; |
|
| 252 | - case QR_MODE_8: $ret = $this->encodeMode8($version); break; |
|
| 253 | - case QR_MODE_KANJI: $ret = $this->encodeModeKanji($version);break; |
|
| 254 | - case QR_MODE_STRUCTURE: $ret = $this->encodeModeStructure(); break; |
|
| 250 | + case QR_MODE_NUM: $ret = $this->encodeModeNum($version); break; |
|
| 251 | + case QR_MODE_AN: $ret = $this->encodeModeAn($version); break; |
|
| 252 | + case QR_MODE_8: $ret = $this->encodeMode8($version); break; |
|
| 253 | + case QR_MODE_KANJI: $ret = $this->encodeModeKanji($version);break; |
|
| 254 | + case QR_MODE_STRUCTURE: $ret = $this->encodeModeStructure(); break; |
|
| 255 | 255 | |
| 256 | - default: |
|
| 257 | - break; |
|
| 256 | + default: |
|
| 257 | + break; |
|
| 258 | 258 | } |
| 259 | 259 | |
| 260 | 260 | if($ret < 0) |
@@ -404,14 +404,14 @@ discard block |
||
| 404 | 404 | $bits = $w * 10; |
| 405 | 405 | |
| 406 | 406 | switch($size - $w * 3) {
|
| 407 | - case 1: |
|
| 408 | - $bits += 4; |
|
| 409 | - break; |
|
| 410 | - case 2: |
|
| 411 | - $bits += 7; |
|
| 412 | - break; |
|
| 413 | - default: |
|
| 414 | - break; |
|
| 407 | + case 1: |
|
| 408 | + $bits += 4; |
|
| 409 | + break; |
|
| 410 | + case 2: |
|
| 411 | + $bits += 7; |
|
| 412 | + break; |
|
| 413 | + default: |
|
| 414 | + break; |
|
| 415 | 415 | } |
| 416 | 416 | |
| 417 | 417 | return $bits; |
@@ -500,14 +500,14 @@ discard block |
||
| 500 | 500 | return false; |
| 501 | 501 | |
| 502 | 502 | switch($mode) {
|
| 503 | - case QR_MODE_NUM: return self::checkModeNum($size, $data); break; |
|
| 504 | - case QR_MODE_AN: return self::checkModeAn($size, $data); break; |
|
| 505 | - case QR_MODE_KANJI: return self::checkModeKanji($size, $data); break; |
|
| 506 | - case QR_MODE_8: return true; break; |
|
| 507 | - case QR_MODE_STRUCTURE: return true; break; |
|
| 503 | + case QR_MODE_NUM: return self::checkModeNum($size, $data); break; |
|
| 504 | + case QR_MODE_AN: return self::checkModeAn($size, $data); break; |
|
| 505 | + case QR_MODE_KANJI: return self::checkModeKanji($size, $data); break; |
|
| 506 | + case QR_MODE_8: return true; break; |
|
| 507 | + case QR_MODE_STRUCTURE: return true; break; |
|
| 508 | 508 | |
| 509 | - default: |
|
| 510 | - break; |
|
| 509 | + default: |
|
| 510 | + break; |
|
| 511 | 511 | } |
| 512 | 512 | |
| 513 | 513 | return false; |
@@ -548,35 +548,35 @@ discard block |
||
| 548 | 548 | {
|
| 549 | 549 | $payload = $bits - 4 - QRspec::lengthIndicator($mode, $version); |
| 550 | 550 | switch($mode) {
|
| 551 | - case QR_MODE_NUM: |
|
| 552 | - $chunks = (int)($payload / 10); |
|
| 553 | - $remain = $payload - $chunks * 10; |
|
| 554 | - $size = $chunks * 3; |
|
| 555 | - if($remain >= 7) {
|
|
| 556 | - $size += 2; |
|
| 557 | - } else if($remain >= 4) {
|
|
| 558 | - $size += 1; |
|
| 559 | - } |
|
| 560 | - break; |
|
| 561 | - case QR_MODE_AN: |
|
| 562 | - $chunks = (int)($payload / 11); |
|
| 563 | - $remain = $payload - $chunks * 11; |
|
| 564 | - $size = $chunks * 2; |
|
| 565 | - if($remain >= 6) |
|
| 566 | - $size++; |
|
| 567 | - break; |
|
| 568 | - case QR_MODE_8: |
|
| 569 | - $size = (int)($payload / 8); |
|
| 570 | - break; |
|
| 571 | - case QR_MODE_KANJI: |
|
| 572 | - $size = (int)(($payload / 13) * 2); |
|
| 573 | - break; |
|
| 574 | - case QR_MODE_STRUCTURE: |
|
| 575 | - $size = (int)($payload / 8); |
|
| 576 | - break; |
|
| 577 | - default: |
|
| 578 | - $size = 0; |
|
| 579 | - break; |
|
| 551 | + case QR_MODE_NUM: |
|
| 552 | + $chunks = (int)($payload / 10); |
|
| 553 | + $remain = $payload - $chunks * 10; |
|
| 554 | + $size = $chunks * 3; |
|
| 555 | + if($remain >= 7) {
|
|
| 556 | + $size += 2; |
|
| 557 | + } else if($remain >= 4) {
|
|
| 558 | + $size += 1; |
|
| 559 | + } |
|
| 560 | + break; |
|
| 561 | + case QR_MODE_AN: |
|
| 562 | + $chunks = (int)($payload / 11); |
|
| 563 | + $remain = $payload - $chunks * 11; |
|
| 564 | + $size = $chunks * 2; |
|
| 565 | + if($remain >= 6) |
|
| 566 | + $size++; |
|
| 567 | + break; |
|
| 568 | + case QR_MODE_8: |
|
| 569 | + $size = (int)($payload / 8); |
|
| 570 | + break; |
|
| 571 | + case QR_MODE_KANJI: |
|
| 572 | + $size = (int)(($payload / 13) * 2); |
|
| 573 | + break; |
|
| 574 | + case QR_MODE_STRUCTURE: |
|
| 575 | + $size = (int)($payload / 8); |
|
| 576 | + break; |
|
| 577 | + default: |
|
| 578 | + $size = 0; |
|
| 579 | + break; |
|
| 580 | 580 | } |
| 581 | 581 | |
| 582 | 582 | $maxsize = QRspec::maximumWords($mode, $version); |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 26 | 26 | */ |
| 27 | 27 | |
| 28 | - define('STRUCTURE_HEADER_BITS', 20);
|
|
| 28 | + define('STRUCTURE_HEADER_BITS', 20);
|
|
| 29 | 29 | define('MAX_STRUCTURED_SYMBOLS', 16);
|
| 30 | 30 | |
| 31 | 31 | class QRinputItem {
|
@@ -40,11 +40,11 @@ discard block |
||
| 40 | 40 | $setData = array_slice($data, 0, $size); |
| 41 | 41 | |
| 42 | 42 | if (count($setData) < $size) {
|
| 43 | - $setData = array_merge($setData, array_fill(0,$size-count($setData),0)); |
|
| 43 | + $setData = array_merge($setData, array_fill(0, $size - count($setData), 0)); |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | - if(!QRinput::check($mode, $size, $setData)) {
|
|
| 47 | - throw new Exception('Error m:'.$mode.',s:'.$size.',d:'.join(',',$setData));
|
|
| 46 | + if (!QRinput::check($mode, $size, $setData)) {
|
|
| 47 | + throw new Exception('Error m:'.$mode.',s:'.$size.',d:'.join(',', $setData));
|
|
| 48 | 48 | return null; |
| 49 | 49 | } |
| 50 | 50 | |
@@ -59,26 +59,26 @@ discard block |
||
| 59 | 59 | {
|
| 60 | 60 | try {
|
| 61 | 61 | |
| 62 | - $words = (int)($this->size / 3); |
|
| 62 | + $words = (int) ($this->size / 3); |
|
| 63 | 63 | $bs = new QRbitstream(); |
| 64 | 64 | |
| 65 | 65 | $val = 0x1; |
| 66 | 66 | $bs->appendNum(4, $val); |
| 67 | 67 | $bs->appendNum(QRspec::lengthIndicator(QR_MODE_NUM, $version), $this->size); |
| 68 | 68 | |
| 69 | - for($i=0; $i<$words; $i++) {
|
|
| 70 | - $val = (ord($this->data[$i*3 ]) - ord('0')) * 100;
|
|
| 71 | - $val += (ord($this->data[$i*3+1]) - ord('0')) * 10;
|
|
| 72 | - $val += (ord($this->data[$i*3+2]) - ord('0'));
|
|
| 69 | + for ($i = 0; $i < $words; $i++) {
|
|
| 70 | + $val = (ord($this->data[$i * 3]) - ord('0')) * 100;
|
|
| 71 | + $val += (ord($this->data[$i * 3 + 1]) - ord('0')) * 10;
|
|
| 72 | + $val += (ord($this->data[$i * 3 + 2]) - ord('0'));
|
|
| 73 | 73 | $bs->appendNum(10, $val); |
| 74 | 74 | } |
| 75 | 75 | |
| 76 | - if($this->size - $words * 3 == 1) {
|
|
| 77 | - $val = ord($this->data[$words*3]) - ord('0');
|
|
| 76 | + if ($this->size - $words * 3 == 1) {
|
|
| 77 | + $val = ord($this->data[$words * 3]) - ord('0');
|
|
| 78 | 78 | $bs->appendNum(4, $val); |
| 79 | - } else if($this->size - $words * 3 == 2) {
|
|
| 80 | - $val = (ord($this->data[$words*3 ]) - ord('0')) * 10;
|
|
| 81 | - $val += (ord($this->data[$words*3+1]) - ord('0'));
|
|
| 79 | + } else if ($this->size - $words * 3 == 2) {
|
|
| 80 | + $val = (ord($this->data[$words * 3]) - ord('0')) * 10;
|
|
| 81 | + $val += (ord($this->data[$words * 3 + 1]) - ord('0'));
|
|
| 82 | 82 | $bs->appendNum(7, $val); |
| 83 | 83 | } |
| 84 | 84 | |
@@ -94,20 +94,20 @@ discard block |
||
| 94 | 94 | public function encodeModeAn($version) |
| 95 | 95 | {
|
| 96 | 96 | try {
|
| 97 | - $words = (int)($this->size / 2); |
|
| 97 | + $words = (int) ($this->size / 2); |
|
| 98 | 98 | $bs = new QRbitstream(); |
| 99 | 99 | |
| 100 | 100 | $bs->appendNum(4, 0x02); |
| 101 | 101 | $bs->appendNum(QRspec::lengthIndicator(QR_MODE_AN, $version), $this->size); |
| 102 | 102 | |
| 103 | - for($i=0; $i<$words; $i++) {
|
|
| 104 | - $val = (int)QRinput::lookAnTable(ord($this->data[$i*2 ])) * 45; |
|
| 105 | - $val += (int)QRinput::lookAnTable(ord($this->data[$i*2+1])); |
|
| 103 | + for ($i = 0; $i < $words; $i++) {
|
|
| 104 | + $val = (int) QRinput::lookAnTable(ord($this->data[$i * 2])) * 45; |
|
| 105 | + $val += (int) QRinput::lookAnTable(ord($this->data[$i * 2 + 1])); |
|
| 106 | 106 | |
| 107 | 107 | $bs->appendNum(11, $val); |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | - if($this->size & 1) {
|
|
| 110 | + if ($this->size & 1) {
|
|
| 111 | 111 | $val = QRinput::lookAnTable(ord($this->data[$words * 2])); |
| 112 | 112 | $bs->appendNum(6, $val); |
| 113 | 113 | } |
@@ -129,7 +129,7 @@ discard block |
||
| 129 | 129 | $bs->appendNum(4, 0x4); |
| 130 | 130 | $bs->appendNum(QRspec::lengthIndicator(QR_MODE_8, $version), $this->size); |
| 131 | 131 | |
| 132 | - for($i=0; $i<$this->size; $i++) {
|
|
| 132 | + for ($i = 0; $i < $this->size; $i++) {
|
|
| 133 | 133 | $bs->appendNum(8, ord($this->data[$i])); |
| 134 | 134 | } |
| 135 | 135 | |
@@ -149,11 +149,11 @@ discard block |
||
| 149 | 149 | $bs = new QRbitrtream(); |
| 150 | 150 | |
| 151 | 151 | $bs->appendNum(4, 0x8); |
| 152 | - $bs->appendNum(QRspec::lengthIndicator(QR_MODE_KANJI, $version), (int)($this->size / 2)); |
|
| 152 | + $bs->appendNum(QRspec::lengthIndicator(QR_MODE_KANJI, $version), (int) ($this->size / 2)); |
|
| 153 | 153 | |
| 154 | - for($i=0; $i<$this->size; $i+=2) {
|
|
| 155 | - $val = (ord($this->data[$i]) << 8) | ord($this->data[$i+1]); |
|
| 156 | - if($val <= 0x9ffc) {
|
|
| 154 | + for ($i = 0; $i < $this->size; $i += 2) {
|
|
| 155 | + $val = (ord($this->data[$i]) << 8) | ord($this->data[$i + 1]); |
|
| 156 | + if ($val <= 0x9ffc) {
|
|
| 157 | 157 | $val -= 0x8140; |
| 158 | 158 | } else {
|
| 159 | 159 | $val -= 0xc140; |
@@ -177,7 +177,7 @@ discard block |
||
| 177 | 177 | public function encodeModeStructure() |
| 178 | 178 | {
|
| 179 | 179 | try {
|
| 180 | - $bs = new QRbitstream(); |
|
| 180 | + $bs = new QRbitstream(); |
|
| 181 | 181 | |
| 182 | 182 | $bs->appendNum(4, 0x03); |
| 183 | 183 | $bs->appendNum(4, ord($this->data[1]) - 1); |
@@ -197,14 +197,14 @@ discard block |
||
| 197 | 197 | {
|
| 198 | 198 | $bits = 0; |
| 199 | 199 | |
| 200 | - if($version == 0) |
|
| 200 | + if ($version == 0) |
|
| 201 | 201 | $version = 1; |
| 202 | 202 | |
| 203 | - switch($this->mode) {
|
|
| 204 | - case QR_MODE_NUM: $bits = QRinput::estimateBitsModeNum($this->size); break; |
|
| 205 | - case QR_MODE_AN: $bits = QRinput::estimateBitsModeAn($this->size); break; |
|
| 206 | - case QR_MODE_8: $bits = QRinput::estimateBitsMode8($this->size); break; |
|
| 207 | - case QR_MODE_KANJI: $bits = QRinput::estimateBitsModeKanji($this->size);break; |
|
| 203 | + switch ($this->mode) {
|
|
| 204 | + case QR_MODE_NUM: $bits = QRinput::estimateBitsModeNum($this->size); break; |
|
| 205 | + case QR_MODE_AN: $bits = QRinput::estimateBitsModeAn($this->size); break; |
|
| 206 | + case QR_MODE_8: $bits = QRinput::estimateBitsMode8($this->size); break; |
|
| 207 | + case QR_MODE_KANJI: $bits = QRinput::estimateBitsModeKanji($this->size); break; |
|
| 208 | 208 | case QR_MODE_STRUCTURE: return STRUCTURE_HEADER_BITS; |
| 209 | 209 | default: |
| 210 | 210 | return 0; |
@@ -212,7 +212,7 @@ discard block |
||
| 212 | 212 | |
| 213 | 213 | $l = QRspec::lengthIndicator($this->mode, $version); |
| 214 | 214 | $m = 1 << $l; |
| 215 | - $num = (int)(($this->size + $m - 1) / $m); |
|
| 215 | + $num = (int) (($this->size + $m - 1) / $m); |
|
| 216 | 216 | |
| 217 | 217 | $bits += $num * (4 + $l); |
| 218 | 218 | |
@@ -227,7 +227,7 @@ discard block |
||
| 227 | 227 | unset($this->bstream); |
| 228 | 228 | $words = QRspec::maximumWords($this->mode, $version); |
| 229 | 229 | |
| 230 | - if($this->size > $words) {
|
|
| 230 | + if ($this->size > $words) {
|
|
| 231 | 231 | |
| 232 | 232 | $st1 = new QRinputItem($this->mode, $words, $this->data); |
| 233 | 233 | $st2 = new QRinputItem($this->mode, $this->size - $words, array_slice($this->data, $words)); |
@@ -246,18 +246,18 @@ discard block |
||
| 246 | 246 | |
| 247 | 247 | $ret = 0; |
| 248 | 248 | |
| 249 | - switch($this->mode) {
|
|
| 250 | - case QR_MODE_NUM: $ret = $this->encodeModeNum($version); break; |
|
| 251 | - case QR_MODE_AN: $ret = $this->encodeModeAn($version); break; |
|
| 252 | - case QR_MODE_8: $ret = $this->encodeMode8($version); break; |
|
| 253 | - case QR_MODE_KANJI: $ret = $this->encodeModeKanji($version);break; |
|
| 254 | - case QR_MODE_STRUCTURE: $ret = $this->encodeModeStructure(); break; |
|
| 249 | + switch ($this->mode) {
|
|
| 250 | + case QR_MODE_NUM: $ret = $this->encodeModeNum($version); break; |
|
| 251 | + case QR_MODE_AN: $ret = $this->encodeModeAn($version); break; |
|
| 252 | + case QR_MODE_8: $ret = $this->encodeMode8($version); break; |
|
| 253 | + case QR_MODE_KANJI: $ret = $this->encodeModeKanji($version); break; |
|
| 254 | + case QR_MODE_STRUCTURE: $ret = $this->encodeModeStructure(); break; |
|
| 255 | 255 | |
| 256 | 256 | default: |
| 257 | 257 | break; |
| 258 | 258 | } |
| 259 | 259 | |
| 260 | - if($ret < 0) |
|
| 260 | + if ($ret < 0) |
|
| 261 | 261 | return -1; |
| 262 | 262 | } |
| 263 | 263 | |
@@ -299,7 +299,7 @@ discard block |
||
| 299 | 299 | //---------------------------------------------------------------------- |
| 300 | 300 | public function setVersion($version) |
| 301 | 301 | {
|
| 302 | - if($version < 0 || $version > QRSPEC_VERSION_MAX) {
|
|
| 302 | + if ($version < 0 || $version > QRSPEC_VERSION_MAX) {
|
|
| 303 | 303 | throw new Exception('Invalid version no');
|
| 304 | 304 | return -1; |
| 305 | 305 | } |
@@ -318,7 +318,7 @@ discard block |
||
| 318 | 318 | //---------------------------------------------------------------------- |
| 319 | 319 | public function setErrorCorrectionLevel($level) |
| 320 | 320 | {
|
| 321 | - if($level > QR_ECLEVEL_H) {
|
|
| 321 | + if ($level > QR_ECLEVEL_H) {
|
|
| 322 | 322 | throw new Exception('Invalid ECLEVEL');
|
| 323 | 323 | return -1; |
| 324 | 324 | } |
@@ -350,11 +350,11 @@ discard block |
||
| 350 | 350 | |
| 351 | 351 | public function insertStructuredAppendHeader($size, $index, $parity) |
| 352 | 352 | {
|
| 353 | - if( $size > MAX_STRUCTURED_SYMBOLS ) {
|
|
| 353 | + if ($size > MAX_STRUCTURED_SYMBOLS) {
|
|
| 354 | 354 | throw new Exception('insertStructuredAppendHeader wrong size');
|
| 355 | 355 | } |
| 356 | 356 | |
| 357 | - if( $index <= 0 || $index > MAX_STRUCTURED_SYMBOLS ) {
|
|
| 357 | + if ($index <= 0 || $index > MAX_STRUCTURED_SYMBOLS) {
|
|
| 358 | 358 | throw new Exception('insertStructuredAppendHeader wrong index');
|
| 359 | 359 | } |
| 360 | 360 | |
@@ -374,9 +374,9 @@ discard block |
||
| 374 | 374 | {
|
| 375 | 375 | $parity = 0; |
| 376 | 376 | |
| 377 | - foreach($this->items as $item) {
|
|
| 378 | - if($item->mode != QR_MODE_STRUCTURE) {
|
|
| 379 | - for($i=$item->size-1; $i>=0; $i--) {
|
|
| 377 | + foreach ($this->items as $item) {
|
|
| 378 | + if ($item->mode != QR_MODE_STRUCTURE) {
|
|
| 379 | + for ($i = $item->size - 1; $i >= 0; $i--) {
|
|
| 380 | 380 | $parity ^= $item->data[$i]; |
| 381 | 381 | } |
| 382 | 382 | } |
@@ -388,8 +388,8 @@ discard block |
||
| 388 | 388 | //---------------------------------------------------------------------- |
| 389 | 389 | public static function checkModeNum($size, $data) |
| 390 | 390 | {
|
| 391 | - for($i=0; $i<$size; $i++) {
|
|
| 392 | - if((ord($data[$i]) < ord('0')) || (ord($data[$i]) > ord('9'))){
|
|
| 391 | + for ($i = 0; $i < $size; $i++) {
|
|
| 392 | + if ((ord($data[$i]) < ord('0')) || (ord($data[$i]) > ord('9'))) {
|
|
| 393 | 393 | return false; |
| 394 | 394 | } |
| 395 | 395 | } |
@@ -400,10 +400,10 @@ discard block |
||
| 400 | 400 | //---------------------------------------------------------------------- |
| 401 | 401 | public static function estimateBitsModeNum($size) |
| 402 | 402 | {
|
| 403 | - $w = (int)$size / 3; |
|
| 403 | + $w = (int) $size / 3; |
|
| 404 | 404 | $bits = $w * 10; |
| 405 | 405 | |
| 406 | - switch($size - $w * 3) {
|
|
| 406 | + switch ($size - $w * 3) {
|
|
| 407 | 407 | case 1: |
| 408 | 408 | $bits += 4; |
| 409 | 409 | break; |
@@ -422,7 +422,7 @@ discard block |
||
| 422 | 422 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 423 | 423 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 424 | 424 | 36, -1, -1, -1, 37, 38, -1, -1, -1, -1, 39, 40, -1, 41, 42, 43, |
| 425 | - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 44, -1, -1, -1, -1, -1, |
|
| 425 | + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 44, -1, -1, -1, -1, -1, |
|
| 426 | 426 | -1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, |
| 427 | 427 | 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, -1, -1, -1, -1, -1, |
| 428 | 428 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
@@ -432,13 +432,13 @@ discard block |
||
| 432 | 432 | //---------------------------------------------------------------------- |
| 433 | 433 | public static function lookAnTable($c) |
| 434 | 434 | {
|
| 435 | - return (($c > 127)?-1:self::$anTable[$c]); |
|
| 435 | + return (($c > 127) ?-1 : self::$anTable[$c]); |
|
| 436 | 436 | } |
| 437 | 437 | |
| 438 | 438 | //---------------------------------------------------------------------- |
| 439 | 439 | public static function checkModeAn($size, $data) |
| 440 | 440 | {
|
| 441 | - for($i=0; $i<$size; $i++) {
|
|
| 441 | + for ($i = 0; $i < $size; $i++) {
|
|
| 442 | 442 | if (self::lookAnTable(ord($data[$i])) == -1) {
|
| 443 | 443 | return false; |
| 444 | 444 | } |
@@ -450,10 +450,10 @@ discard block |
||
| 450 | 450 | //---------------------------------------------------------------------- |
| 451 | 451 | public static function estimateBitsModeAn($size) |
| 452 | 452 | {
|
| 453 | - $w = (int)($size / 2); |
|
| 453 | + $w = (int) ($size / 2); |
|
| 454 | 454 | $bits = $w * 11; |
| 455 | 455 | |
| 456 | - if($size & 1) {
|
|
| 456 | + if ($size & 1) {
|
|
| 457 | 457 | $bits += 6; |
| 458 | 458 | } |
| 459 | 459 | |
@@ -469,18 +469,18 @@ discard block |
||
| 469 | 469 | //---------------------------------------------------------------------- |
| 470 | 470 | public function estimateBitsModeKanji($size) |
| 471 | 471 | {
|
| 472 | - return (int)(($size / 2) * 13); |
|
| 472 | + return (int) (($size / 2) * 13); |
|
| 473 | 473 | } |
| 474 | 474 | |
| 475 | 475 | //---------------------------------------------------------------------- |
| 476 | 476 | public static function checkModeKanji($size, $data) |
| 477 | 477 | {
|
| 478 | - if($size & 1) |
|
| 478 | + if ($size & 1) |
|
| 479 | 479 | return false; |
| 480 | 480 | |
| 481 | - for($i=0; $i<$size; $i+=2) {
|
|
| 482 | - $val = (ord($data[$i]) << 8) | ord($data[$i+1]); |
|
| 483 | - if( $val < 0x8140 |
|
| 481 | + for ($i = 0; $i < $size; $i += 2) {
|
|
| 482 | + $val = (ord($data[$i]) << 8) | ord($data[$i + 1]); |
|
| 483 | + if ($val < 0x8140 |
|
| 484 | 484 | || ($val > 0x9ffc && $val < 0xe040) |
| 485 | 485 | || $val > 0xebbf) {
|
| 486 | 486 | return false; |
@@ -496,12 +496,12 @@ discard block |
||
| 496 | 496 | |
| 497 | 497 | public static function check($mode, $size, $data) |
| 498 | 498 | {
|
| 499 | - if($size <= 0) |
|
| 499 | + if ($size <= 0) |
|
| 500 | 500 | return false; |
| 501 | 501 | |
| 502 | - switch($mode) {
|
|
| 503 | - case QR_MODE_NUM: return self::checkModeNum($size, $data); break; |
|
| 504 | - case QR_MODE_AN: return self::checkModeAn($size, $data); break; |
|
| 502 | + switch ($mode) {
|
|
| 503 | + case QR_MODE_NUM: return self::checkModeNum($size, $data); break; |
|
| 504 | + case QR_MODE_AN: return self::checkModeAn($size, $data); break; |
|
| 505 | 505 | case QR_MODE_KANJI: return self::checkModeKanji($size, $data); break; |
| 506 | 506 | case QR_MODE_8: return true; break; |
| 507 | 507 | case QR_MODE_STRUCTURE: return true; break; |
@@ -519,7 +519,7 @@ discard block |
||
| 519 | 519 | {
|
| 520 | 520 | $bits = 0; |
| 521 | 521 | |
| 522 | - foreach($this->items as $item) {
|
|
| 522 | + foreach ($this->items as $item) {
|
|
| 523 | 523 | $bits += $item->estimateBitStreamSizeOfEntry($version); |
| 524 | 524 | } |
| 525 | 525 | |
@@ -534,7 +534,7 @@ discard block |
||
| 534 | 534 | do {
|
| 535 | 535 | $prev = $version; |
| 536 | 536 | $bits = $this->estimateBitStreamSize($prev); |
| 537 | - $version = QRspec::getMinimumVersion((int)(($bits + 7) / 8), $this->level); |
|
| 537 | + $version = QRspec::getMinimumVersion((int) (($bits + 7) / 8), $this->level); |
|
| 538 | 538 | if ($version < 0) {
|
| 539 | 539 | return -1; |
| 540 | 540 | } |
@@ -547,32 +547,32 @@ discard block |
||
| 547 | 547 | public static function lengthOfCode($mode, $version, $bits) |
| 548 | 548 | {
|
| 549 | 549 | $payload = $bits - 4 - QRspec::lengthIndicator($mode, $version); |
| 550 | - switch($mode) {
|
|
| 550 | + switch ($mode) {
|
|
| 551 | 551 | case QR_MODE_NUM: |
| 552 | - $chunks = (int)($payload / 10); |
|
| 552 | + $chunks = (int) ($payload / 10); |
|
| 553 | 553 | $remain = $payload - $chunks * 10; |
| 554 | 554 | $size = $chunks * 3; |
| 555 | - if($remain >= 7) {
|
|
| 555 | + if ($remain >= 7) {
|
|
| 556 | 556 | $size += 2; |
| 557 | - } else if($remain >= 4) {
|
|
| 557 | + } else if ($remain >= 4) {
|
|
| 558 | 558 | $size += 1; |
| 559 | 559 | } |
| 560 | 560 | break; |
| 561 | 561 | case QR_MODE_AN: |
| 562 | - $chunks = (int)($payload / 11); |
|
| 562 | + $chunks = (int) ($payload / 11); |
|
| 563 | 563 | $remain = $payload - $chunks * 11; |
| 564 | 564 | $size = $chunks * 2; |
| 565 | - if($remain >= 6) |
|
| 565 | + if ($remain >= 6) |
|
| 566 | 566 | $size++; |
| 567 | 567 | break; |
| 568 | 568 | case QR_MODE_8: |
| 569 | - $size = (int)($payload / 8); |
|
| 569 | + $size = (int) ($payload / 8); |
|
| 570 | 570 | break; |
| 571 | 571 | case QR_MODE_KANJI: |
| 572 | - $size = (int)(($payload / 13) * 2); |
|
| 572 | + $size = (int) (($payload / 13) * 2); |
|
| 573 | 573 | break; |
| 574 | 574 | case QR_MODE_STRUCTURE: |
| 575 | - $size = (int)($payload / 8); |
|
| 575 | + $size = (int) ($payload / 8); |
|
| 576 | 576 | break; |
| 577 | 577 | default: |
| 578 | 578 | $size = 0; |
@@ -580,8 +580,8 @@ discard block |
||
| 580 | 580 | } |
| 581 | 581 | |
| 582 | 582 | $maxsize = QRspec::maximumWords($mode, $version); |
| 583 | - if($size < 0) $size = 0; |
|
| 584 | - if($size > $maxsize) $size = $maxsize; |
|
| 583 | + if ($size < 0) $size = 0; |
|
| 584 | + if ($size > $maxsize) $size = $maxsize; |
|
| 585 | 585 | |
| 586 | 586 | return $size; |
| 587 | 587 | } |
@@ -591,10 +591,10 @@ discard block |
||
| 591 | 591 | {
|
| 592 | 592 | $total = 0; |
| 593 | 593 | |
| 594 | - foreach($this->items as $item) {
|
|
| 594 | + foreach ($this->items as $item) {
|
|
| 595 | 595 | $bits = $item->encodeBitStream($this->version); |
| 596 | 596 | |
| 597 | - if($bits < 0) |
|
| 597 | + if ($bits < 0) |
|
| 598 | 598 | return -1; |
| 599 | 599 | |
| 600 | 600 | $total += $bits; |
@@ -607,21 +607,21 @@ discard block |
||
| 607 | 607 | public function convertData() |
| 608 | 608 | {
|
| 609 | 609 | $ver = $this->estimateVersion(); |
| 610 | - if($ver > $this->getVersion()) {
|
|
| 610 | + if ($ver > $this->getVersion()) {
|
|
| 611 | 611 | $this->setVersion($ver); |
| 612 | 612 | } |
| 613 | 613 | |
| 614 | - for(;;) {
|
|
| 614 | + for (;;) {
|
|
| 615 | 615 | $bits = $this->createBitStream(); |
| 616 | 616 | |
| 617 | - if($bits < 0) |
|
| 617 | + if ($bits < 0) |
|
| 618 | 618 | return -1; |
| 619 | 619 | |
| 620 | - $ver = QRspec::getMinimumVersion((int)(($bits + 7) / 8), $this->level); |
|
| 621 | - if($ver < 0) {
|
|
| 620 | + $ver = QRspec::getMinimumVersion((int) (($bits + 7) / 8), $this->level); |
|
| 621 | + if ($ver < 0) {
|
|
| 622 | 622 | throw new Exception('WRONG VERSION');
|
| 623 | 623 | return -1; |
| 624 | - } else if($ver > $this->getVersion()) {
|
|
| 624 | + } else if ($ver > $this->getVersion()) {
|
|
| 625 | 625 | $this->setVersion($ver); |
| 626 | 626 | } else {
|
| 627 | 627 | break; |
@@ -647,26 +647,26 @@ discard block |
||
| 647 | 647 | } |
| 648 | 648 | |
| 649 | 649 | $bits += 4; |
| 650 | - $words = (int)(($bits + 7) / 8); |
|
| 650 | + $words = (int) (($bits + 7) / 8); |
|
| 651 | 651 | |
| 652 | 652 | $padding = new QRbitstream(); |
| 653 | 653 | $ret = $padding->appendNum($words * 8 - $bits + 4, 0); |
| 654 | 654 | |
| 655 | - if($ret < 0) |
|
| 655 | + if ($ret < 0) |
|
| 656 | 656 | return $ret; |
| 657 | 657 | |
| 658 | 658 | $padlen = $maxwords - $words; |
| 659 | 659 | |
| 660 | - if($padlen > 0) {
|
|
| 660 | + if ($padlen > 0) {
|
|
| 661 | 661 | |
| 662 | 662 | $padbuf = array(); |
| 663 | - for($i=0; $i<$padlen; $i++) {
|
|
| 664 | - $padbuf[$i] = ($i&1)?0x11:0xec; |
|
| 663 | + for ($i = 0; $i < $padlen; $i++) {
|
|
| 664 | + $padbuf[$i] = ($i & 1) ? 0x11 : 0xec; |
|
| 665 | 665 | } |
| 666 | 666 | |
| 667 | 667 | $ret = $padding->appendBytes($padlen, $padbuf); |
| 668 | 668 | |
| 669 | - if($ret < 0) |
|
| 669 | + if ($ret < 0) |
|
| 670 | 670 | return $ret; |
| 671 | 671 | |
| 672 | 672 | } |
@@ -679,15 +679,15 @@ discard block |
||
| 679 | 679 | //---------------------------------------------------------------------- |
| 680 | 680 | public function mergeBitStream() |
| 681 | 681 | {
|
| 682 | - if($this->convertData() < 0) {
|
|
| 682 | + if ($this->convertData() < 0) {
|
|
| 683 | 683 | return null; |
| 684 | 684 | } |
| 685 | 685 | |
| 686 | 686 | $bstream = new QRbitstream(); |
| 687 | 687 | |
| 688 | - foreach($this->items as $item) {
|
|
| 688 | + foreach ($this->items as $item) {
|
|
| 689 | 689 | $ret = $bstream->append($item->bstream); |
| 690 | - if($ret < 0) {
|
|
| 690 | + if ($ret < 0) {
|
|
| 691 | 691 | return null; |
| 692 | 692 | } |
| 693 | 693 | } |
@@ -701,12 +701,12 @@ discard block |
||
| 701 | 701 | |
| 702 | 702 | $bstream = $this->mergeBitStream(); |
| 703 | 703 | |
| 704 | - if($bstream == null) {
|
|
| 704 | + if ($bstream == null) {
|
|
| 705 | 705 | return null; |
| 706 | 706 | } |
| 707 | 707 | |
| 708 | 708 | $ret = $this->appendPaddingBit($bstream); |
| 709 | - if($ret < 0) {
|
|
| 709 | + if ($ret < 0) {
|
|
| 710 | 710 | return null; |
| 711 | 711 | } |
| 712 | 712 | |
@@ -717,7 +717,7 @@ discard block |
||
| 717 | 717 | public function getByteStream() |
| 718 | 718 | {
|
| 719 | 719 | $bstream = $this->getBitStream(); |
| 720 | - if($bstream == null) {
|
|
| 720 | + if ($bstream == null) {
|
|
| 721 | 721 | return null; |
| 722 | 722 | } |
| 723 | 723 | |
@@ -197,8 +197,9 @@ discard block |
||
| 197 | 197 | {
|
| 198 | 198 | $bits = 0; |
| 199 | 199 | |
| 200 | - if($version == 0) |
|
| 201 | - $version = 1; |
|
| 200 | + if($version == 0) { |
|
| 201 | + $version = 1; |
|
| 202 | + } |
|
| 202 | 203 | |
| 203 | 204 | switch($this->mode) {
|
| 204 | 205 | case QR_MODE_NUM: $bits = QRinput::estimateBitsModeNum($this->size); break; |
@@ -257,8 +258,9 @@ discard block |
||
| 257 | 258 | break; |
| 258 | 259 | } |
| 259 | 260 | |
| 260 | - if($ret < 0) |
|
| 261 | - return -1; |
|
| 261 | + if($ret < 0) { |
|
| 262 | + return -1; |
|
| 263 | + } |
|
| 262 | 264 | } |
| 263 | 265 | |
| 264 | 266 | return $this->bstream->size(); |
@@ -475,8 +477,9 @@ discard block |
||
| 475 | 477 | //---------------------------------------------------------------------- |
| 476 | 478 | public static function checkModeKanji($size, $data) |
| 477 | 479 | {
|
| 478 | - if($size & 1) |
|
| 479 | - return false; |
|
| 480 | + if($size & 1) { |
|
| 481 | + return false; |
|
| 482 | + } |
|
| 480 | 483 | |
| 481 | 484 | for($i=0; $i<$size; $i+=2) {
|
| 482 | 485 | $val = (ord($data[$i]) << 8) | ord($data[$i+1]); |
@@ -496,8 +499,9 @@ discard block |
||
| 496 | 499 | |
| 497 | 500 | public static function check($mode, $size, $data) |
| 498 | 501 | {
|
| 499 | - if($size <= 0) |
|
| 500 | - return false; |
|
| 502 | + if($size <= 0) { |
|
| 503 | + return false; |
|
| 504 | + } |
|
| 501 | 505 | |
| 502 | 506 | switch($mode) {
|
| 503 | 507 | case QR_MODE_NUM: return self::checkModeNum($size, $data); break; |
@@ -562,8 +566,9 @@ discard block |
||
| 562 | 566 | $chunks = (int)($payload / 11); |
| 563 | 567 | $remain = $payload - $chunks * 11; |
| 564 | 568 | $size = $chunks * 2; |
| 565 | - if($remain >= 6) |
|
| 566 | - $size++; |
|
| 569 | + if($remain >= 6) { |
|
| 570 | + $size++; |
|
| 571 | + } |
|
| 567 | 572 | break; |
| 568 | 573 | case QR_MODE_8: |
| 569 | 574 | $size = (int)($payload / 8); |
@@ -580,8 +585,12 @@ discard block |
||
| 580 | 585 | } |
| 581 | 586 | |
| 582 | 587 | $maxsize = QRspec::maximumWords($mode, $version); |
| 583 | - if($size < 0) $size = 0; |
|
| 584 | - if($size > $maxsize) $size = $maxsize; |
|
| 588 | + if($size < 0) { |
|
| 589 | + $size = 0; |
|
| 590 | + } |
|
| 591 | + if($size > $maxsize) { |
|
| 592 | + $size = $maxsize; |
|
| 593 | + } |
|
| 585 | 594 | |
| 586 | 595 | return $size; |
| 587 | 596 | } |
@@ -594,8 +603,9 @@ discard block |
||
| 594 | 603 | foreach($this->items as $item) {
|
| 595 | 604 | $bits = $item->encodeBitStream($this->version); |
| 596 | 605 | |
| 597 | - if($bits < 0) |
|
| 598 | - return -1; |
|
| 606 | + if($bits < 0) { |
|
| 607 | + return -1; |
|
| 608 | + } |
|
| 599 | 609 | |
| 600 | 610 | $total += $bits; |
| 601 | 611 | } |
@@ -614,8 +624,9 @@ discard block |
||
| 614 | 624 | for(;;) {
|
| 615 | 625 | $bits = $this->createBitStream(); |
| 616 | 626 | |
| 617 | - if($bits < 0) |
|
| 618 | - return -1; |
|
| 627 | + if($bits < 0) { |
|
| 628 | + return -1; |
|
| 629 | + } |
|
| 619 | 630 | |
| 620 | 631 | $ver = QRspec::getMinimumVersion((int)(($bits + 7) / 8), $this->level); |
| 621 | 632 | if($ver < 0) {
|
@@ -652,8 +663,9 @@ discard block |
||
| 652 | 663 | $padding = new QRbitstream(); |
| 653 | 664 | $ret = $padding->appendNum($words * 8 - $bits + 4, 0); |
| 654 | 665 | |
| 655 | - if($ret < 0) |
|
| 656 | - return $ret; |
|
| 666 | + if($ret < 0) { |
|
| 667 | + return $ret; |
|
| 668 | + } |
|
| 657 | 669 | |
| 658 | 670 | $padlen = $maxwords - $words; |
| 659 | 671 | |
@@ -666,8 +678,9 @@ discard block |
||
| 666 | 678 | |
| 667 | 679 | $ret = $padding->appendBytes($padlen, $padbuf); |
| 668 | 680 | |
| 669 | - if($ret < 0) |
|
| 670 | - return $ret; |
|
| 681 | + if($ret < 0) { |
|
| 682 | + return $ret; |
|
| 683 | + } |
|
| 671 | 684 | |
| 672 | 685 | } |
| 673 | 686 | |