@@ -143,9 +143,9 @@ discard block |
||
| 143 | 143 | |
| 144 | 144 | return $pdo; |
| 145 | 145 | } catch (Exception $e) { |
| 146 | - print "<div class='alert alert-danger'>" . $e->getMessage() . "</div>"; |
|
| 147 | - return null; |
|
| 148 | - } |
|
| 146 | + print "<div class='alert alert-danger'>" . $e->getMessage() . "</div>"; |
|
| 147 | + return null; |
|
| 148 | + } |
|
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | function make_config($DB_TYPE, $DB_HOST, $DB_USER, $DB_NAME, $DB_PASS, |
@@ -322,13 +322,13 @@ discard block |
||
| 322 | 322 | array_push($notices, "PHP support for Internationalization Functions is required to handle Internationalized Domain Names."); |
| 323 | 323 | } |
| 324 | 324 | |
| 325 | - if ($DB_TYPE == "mysql" && !function_exists("mysqli_connect")) { |
|
| 326 | - array_push($notices, "PHP extension for MySQL (mysqli) is missing. This may prevent legacy plugins from working."); |
|
| 327 | - } |
|
| 325 | + if ($DB_TYPE == "mysql" && !function_exists("mysqli_connect")) { |
|
| 326 | + array_push($notices, "PHP extension for MySQL (mysqli) is missing. This may prevent legacy plugins from working."); |
|
| 327 | + } |
|
| 328 | 328 | |
| 329 | - if ($DB_TYPE == "pgsql" && !function_exists("pg_connect")) { |
|
| 329 | + if ($DB_TYPE == "pgsql" && !function_exists("pg_connect")) { |
|
| 330 | 330 | array_push($notices, "PHP extension for PostgreSQL is missing. This may prevent legacy plugins from working."); |
| 331 | - } |
|
| 331 | + } |
|
| 332 | 332 | |
| 333 | 333 | if (count($notices) > 0) { |
| 334 | 334 | print_notice("Configuration check succeeded with minor problems:"); |
@@ -429,7 +429,7 @@ discard block |
||
| 429 | 429 | print "<h2>Initializing database...</h2>"; |
| 430 | 430 | |
| 431 | 431 | $lines = explode(";", preg_replace("/[\r\n]/", "", |
| 432 | - file_get_contents("../schema/ttrss_schema_".basename($DB_TYPE).".sql"))); |
|
| 432 | + file_get_contents("../schema/ttrss_schema_".basename($DB_TYPE).".sql"))); |
|
| 433 | 433 | |
| 434 | 434 | foreach ($lines as $line) { |
| 435 | 435 | if (strpos($line, "--") !== 0 && $line) { |
@@ -438,7 +438,7 @@ discard block |
||
| 438 | 438 | if (!$res) { |
| 439 | 439 | print_notice("Query: $line"); |
| 440 | 440 | print_error("Error: " . implode(", ", $pdo->errorInfo())); |
| 441 | - } |
|
| 441 | + } |
|
| 442 | 442 | } |
| 443 | 443 | } |
| 444 | 444 | |
@@ -87,8 +87,8 @@ discard block |
||
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | /** |
| 90 | - * @SuppressWarnings(unused) |
|
| 91 | - */ |
|
| 90 | + * @SuppressWarnings(unused) |
|
| 91 | + */ |
|
| 92 | 92 | function sigchld_handler($signal) { |
| 93 | 93 | $running_jobs = reap_children(); |
| 94 | 94 | |
@@ -142,7 +142,7 @@ discard block |
||
| 142 | 142 | print "Tiny Tiny RSS update daemon.\n\n"; |
| 143 | 143 | print "Options:\n"; |
| 144 | 144 | print " --log FILE - log messages to FILE\n"; |
| 145 | - print " --log-level N - log verbosity level\n"; |
|
| 145 | + print " --log-level N - log verbosity level\n"; |
|
| 146 | 146 | print " --tasks N - amount of update tasks to spawn\n"; |
| 147 | 147 | print " default: " . MAX_JOBS . "\n"; |
| 148 | 148 | print " --interval N - task spawn interval\n"; |
@@ -151,21 +151,21 @@ discard block |
||
| 151 | 151 | return; |
| 152 | 152 | } |
| 153 | 153 | |
| 154 | - Debug::set_enabled(true); |
|
| 155 | - |
|
| 156 | - if (isset($options["log-level"])) { |
|
| 157 | - Debug::set_loglevel((int)$options["log-level"]); |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - if (isset($options["log"])) { |
|
| 161 | - Debug::set_quiet(isset($options['quiet'])); |
|
| 162 | - Debug::set_logfile($options["log"]); |
|
| 163 | - Debug::log("Logging to " . $options["log"]); |
|
| 164 | - } else { |
|
| 165 | - if (isset($options['quiet'])) { |
|
| 166 | - Debug::set_loglevel(Debug::$LOG_DISABLED); |
|
| 167 | - } |
|
| 168 | - } |
|
| 154 | + Debug::set_enabled(true); |
|
| 155 | + |
|
| 156 | + if (isset($options["log-level"])) { |
|
| 157 | + Debug::set_loglevel((int)$options["log-level"]); |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + if (isset($options["log"])) { |
|
| 161 | + Debug::set_quiet(isset($options['quiet'])); |
|
| 162 | + Debug::set_logfile($options["log"]); |
|
| 163 | + Debug::log("Logging to " . $options["log"]); |
|
| 164 | + } else { |
|
| 165 | + if (isset($options['quiet'])) { |
|
| 166 | + Debug::set_loglevel(Debug::$LOG_DISABLED); |
|
| 167 | + } |
|
| 168 | + } |
|
| 169 | 169 | |
| 170 | 170 | if (isset($options["tasks"])) { |
| 171 | 171 | Debug::log("Set to spawn " . $options["tasks"] . " children."); |
@@ -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 | /** |
@@ -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 |
@@ -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 | ?> |
@@ -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 |
@@ -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 |
@@ -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 | + } |
|
@@ -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 | + } |
|