@@ -72,41 +72,41 @@ discard block |
||
| 72 | 72 | function find_match($curlscore, $curcscore, $curgtlang, $langval, $charval, |
| 73 | 73 | $gtlang) |
| 74 | 74 | { |
| 75 | - if ($curlscore < $langval) { |
|
| 75 | + if ($curlscore < $langval) { |
|
| 76 | 76 | $curlscore = $langval; |
| 77 | 77 | $curcscore = $charval; |
| 78 | 78 | $curgtlang = $gtlang; |
| 79 | - } else if ($curlscore == $langval) { |
|
| 79 | + } else if ($curlscore == $langval) { |
|
| 80 | 80 | if ($curcscore < $charval) { |
| 81 | - $curcscore = $charval; |
|
| 82 | - $curgtlang = $gtlang; |
|
| 81 | + $curcscore = $charval; |
|
| 82 | + $curgtlang = $gtlang; |
|
| 83 | 83 | } |
| 84 | - } |
|
| 85 | - return array($curlscore, $curcscore, $curgtlang); |
|
| 84 | + } |
|
| 85 | + return array($curlscore, $curcscore, $curgtlang); |
|
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | function al2gt($gettextlangs, $mime) { |
| 89 | - /* default to "everything is acceptable", as RFC2616 specifies */ |
|
| 90 | - $acceptLang = (($_SERVER["HTTP_ACCEPT_LANGUAGE"] == '') ? '*' : $_SERVER["HTTP_ACCEPT_LANGUAGE"]); |
|
| 91 | - $acceptChar = (($_SERVER["HTTP_ACCEPT_CHARSET"] == '') ? '*' : $_SERVER["HTTP_ACCEPT_CHARSET"]); |
|
| 92 | - $alparts = @preg_split("/,/", $acceptLang); |
|
| 93 | - $acparts = @preg_split("/,/", $acceptChar); |
|
| 89 | + /* default to "everything is acceptable", as RFC2616 specifies */ |
|
| 90 | + $acceptLang = (($_SERVER["HTTP_ACCEPT_LANGUAGE"] == '') ? '*' : $_SERVER["HTTP_ACCEPT_LANGUAGE"]); |
|
| 91 | + $acceptChar = (($_SERVER["HTTP_ACCEPT_CHARSET"] == '') ? '*' : $_SERVER["HTTP_ACCEPT_CHARSET"]); |
|
| 92 | + $alparts = @preg_split("/,/", $acceptLang); |
|
| 93 | + $acparts = @preg_split("/,/", $acceptChar); |
|
| 94 | 94 | |
| 95 | - /* Parse the contents of the Accept-Language header.*/ |
|
| 96 | - foreach ($alparts as $part) { |
|
| 95 | + /* Parse the contents of the Accept-Language header.*/ |
|
| 96 | + foreach ($alparts as $part) { |
|
| 97 | 97 | $part = trim($part); |
| 98 | 98 | if (preg_match("/;/", $part)) { |
| 99 | - $lang = @preg_split("/;/", $part); |
|
| 100 | - $score = @preg_split("/=/", $lang[1]); |
|
| 101 | - $alscores[$lang[0]] = $score[1]; |
|
| 99 | + $lang = @preg_split("/;/", $part); |
|
| 100 | + $score = @preg_split("/=/", $lang[1]); |
|
| 101 | + $alscores[$lang[0]] = $score[1]; |
|
| 102 | 102 | } else { |
| 103 | - $alscores[$part] = 1; |
|
| 103 | + $alscores[$part] = 1; |
|
| 104 | + } |
|
| 104 | 105 | } |
| 105 | - } |
|
| 106 | 106 | |
| 107 | - /* Do the same for the Accept-Charset header. */ |
|
| 107 | + /* Do the same for the Accept-Charset header. */ |
|
| 108 | 108 | |
| 109 | - /* RFC2616: ``If no "*" is present in an Accept-Charset field, then |
|
| 109 | + /* RFC2616: ``If no "*" is present in an Accept-Charset field, then |
|
| 110 | 110 | * all character sets not explicitly mentioned get a quality value of |
| 111 | 111 | * 0, except for ISO-8859-1, which gets a quality value of 1 if not |
| 112 | 112 | * explicitly mentioned.'' |
@@ -114,31 +114,31 @@ discard block |
||
| 114 | 114 | * Making it 2 for the time being, so that we |
| 115 | 115 | * can distinguish between "not specified" and "specified as 1" later |
| 116 | 116 | * on. */ |
| 117 | - $acscores["ISO-8859-1"] = 2; |
|
| 117 | + $acscores["ISO-8859-1"] = 2; |
|
| 118 | 118 | |
| 119 | - foreach ($acparts as $part) { |
|
| 119 | + foreach ($acparts as $part) { |
|
| 120 | 120 | $part = trim($part); |
| 121 | 121 | if (preg_match("/;/", $part)) { |
| 122 | - $cs = @preg_split("/;/", $part); |
|
| 123 | - $score = @preg_split("/=/", $cs[1]); |
|
| 124 | - $acscores[strtoupper($cs[0])] = $score[1]; |
|
| 122 | + $cs = @preg_split("/;/", $part); |
|
| 123 | + $score = @preg_split("/=/", $cs[1]); |
|
| 124 | + $acscores[strtoupper($cs[0])] = $score[1]; |
|
| 125 | 125 | } else { |
| 126 | - $acscores[strtoupper($part)] = 1; |
|
| 126 | + $acscores[strtoupper($part)] = 1; |
|
| 127 | + } |
|
| 127 | 128 | } |
| 128 | - } |
|
| 129 | - if ($acscores["ISO-8859-1"] == 2) { |
|
| 129 | + if ($acscores["ISO-8859-1"] == 2) { |
|
| 130 | 130 | $acscores["ISO-8859-1"] = (isset($acscores["*"]) ? $acscores["*"] : 1); |
| 131 | - } |
|
| 131 | + } |
|
| 132 | 132 | |
| 133 | - /* |
|
| 133 | + /* |
|
| 134 | 134 | * Loop through the available languages/encodings, and pick the one |
| 135 | 135 | * with the highest score, excluding the ones with a charset the user |
| 136 | 136 | * did not include. |
| 137 | 137 | */ |
| 138 | - $curlscore = 0; |
|
| 139 | - $curcscore = 0; |
|
| 140 | - $curgtlang = null; |
|
| 141 | - foreach ($gettextlangs as $gtlang) { |
|
| 138 | + $curlscore = 0; |
|
| 139 | + $curcscore = 0; |
|
| 140 | + $curgtlang = null; |
|
| 141 | + foreach ($gettextlangs as $gtlang) { |
|
| 142 | 142 | |
| 143 | 143 | $tmp1 = preg_replace("/\_/", "-", $gtlang); |
| 144 | 144 | $tmp2 = @preg_split("/\./", $tmp1); |
@@ -147,38 +147,38 @@ discard block |
||
| 147 | 147 | $noct = @preg_split("/-/", $allang); |
| 148 | 148 | |
| 149 | 149 | $testvals = array( |
| 150 | - array(@$alscores[$allang], @$acscores[$gtcs]), |
|
| 151 | - array(@$alscores[$noct[0]], @$acscores[$gtcs]), |
|
| 152 | - array(@$alscores[$allang], @$acscores["*"]), |
|
| 153 | - array(@$alscores[$noct[0]], @$acscores["*"]), |
|
| 154 | - array(@$alscores["*"], @$acscores[$gtcs]), |
|
| 155 | - array(@$alscores["*"], @$acscores["*"])); |
|
| 150 | + array(@$alscores[$allang], @$acscores[$gtcs]), |
|
| 151 | + array(@$alscores[$noct[0]], @$acscores[$gtcs]), |
|
| 152 | + array(@$alscores[$allang], @$acscores["*"]), |
|
| 153 | + array(@$alscores[$noct[0]], @$acscores["*"]), |
|
| 154 | + array(@$alscores["*"], @$acscores[$gtcs]), |
|
| 155 | + array(@$alscores["*"], @$acscores["*"])); |
|
| 156 | 156 | |
| 157 | 157 | $found = false; |
| 158 | 158 | foreach ($testvals as $tval) { |
| 159 | - if (!$found && isset($tval[0]) && isset($tval[1])) { |
|
| 159 | + if (!$found && isset($tval[0]) && isset($tval[1])) { |
|
| 160 | 160 | $arr = find_match($curlscore, $curcscore, $curgtlang, $tval[0], |
| 161 | - $tval[1], $gtlang); |
|
| 161 | + $tval[1], $gtlang); |
|
| 162 | 162 | $curlscore = $arr[0]; |
| 163 | 163 | $curcscore = $arr[1]; |
| 164 | 164 | $curgtlang = $arr[2]; |
| 165 | 165 | $found = true; |
| 166 | - } |
|
| 166 | + } |
|
| 167 | + } |
|
| 167 | 168 | } |
| 168 | - } |
|
| 169 | 169 | |
| 170 | - /* We must re-parse the gettext-string now, since we may have found it |
|
| 170 | + /* We must re-parse the gettext-string now, since we may have found it |
|
| 171 | 171 | * through a "*" qualifier.*/ |
| 172 | 172 | |
| 173 | - $gtparts = @preg_split("/\./", $curgtlang); |
|
| 174 | - $tmp = strtolower($gtparts[0]); |
|
| 175 | - $lang = preg_replace("/\_/", "-", $tmp); |
|
| 176 | - $charset = $gtparts[1]; |
|
| 173 | + $gtparts = @preg_split("/\./", $curgtlang); |
|
| 174 | + $tmp = strtolower($gtparts[0]); |
|
| 175 | + $lang = preg_replace("/\_/", "-", $tmp); |
|
| 176 | + $charset = $gtparts[1]; |
|
| 177 | 177 | |
| 178 | - header("Content-Language: $lang"); |
|
| 179 | - header("Content-Type: $mime; charset=$charset"); |
|
| 178 | + header("Content-Language: $lang"); |
|
| 179 | + header("Content-Type: $mime; charset=$charset"); |
|
| 180 | 180 | |
| 181 | - return $curgtlang; |
|
| 181 | + return $curgtlang; |
|
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | ?> |
@@ -127,16 +127,16 @@ discard block |
||
| 127 | 127 | $bitmapinfo = unpack("Vsize", $data); |
| 128 | 128 | if ($bitmapinfo["size"] == 40) { |
| 129 | 129 | $info = unpack("Vsize/". |
| 130 | - "Vwidth/". |
|
| 131 | - "Vheight/". |
|
| 132 | - "vplanes/". |
|
| 133 | - "vbpp/". |
|
| 134 | - "Vcompress/". |
|
| 135 | - "Vsize/". |
|
| 136 | - "Vxres/". |
|
| 137 | - "Vyres/". |
|
| 138 | - "Vpalcolors/". |
|
| 139 | - "Vimpcolors/", $data); |
|
| 130 | + "Vwidth/". |
|
| 131 | + "Vheight/". |
|
| 132 | + "vplanes/". |
|
| 133 | + "vbpp/". |
|
| 134 | + "Vcompress/". |
|
| 135 | + "Vsize/". |
|
| 136 | + "Vxres/". |
|
| 137 | + "Vyres/". |
|
| 138 | + "Vpalcolors/". |
|
| 139 | + "Vimpcolors/", $data); |
|
| 140 | 140 | if ($e["bpp"] == 0) { |
| 141 | 141 | $e["bpp"] = $info["bpp"]; |
| 142 | 142 | } |
@@ -244,7 +244,7 @@ discard block |
||
| 244 | 244 | for ($y = 0; $y < $height; $y++) { |
| 245 | 245 | for ($x = 0; $x < $width; $x++) { |
| 246 | 246 | imagesetpixel($img, $x, $y, |
| 247 | - $XOR[$y][$x]); |
|
| 247 | + $XOR[$y][$x]); |
|
| 248 | 248 | } |
| 249 | 249 | } |
| 250 | 250 | return $img; |
@@ -255,10 +255,10 @@ discard block |
||
| 255 | 255 | $x = 0; |
| 256 | 256 | while ($x < $width) { |
| 257 | 257 | for ($b = 0x80; |
| 258 | - $b > 0 && $x < $width; $b >>= 1) { |
|
| 258 | + $b > 0 && $x < $width; $b >>= 1) { |
|
| 259 | 259 | if (!(ord($data[$offset]) & $b)) { |
| 260 | 260 | imagesetpixel($img, $x, $y, |
| 261 | - $XOR[$y][$x]); |
|
| 261 | + $XOR[$y][$x]); |
|
| 262 | 262 | } |
| 263 | 263 | $x++; |
| 264 | 264 | } |
@@ -161,7 +161,7 @@ discard block |
||
| 161 | 161 | * @access public |
| 162 | 162 | */ |
| 163 | 163 | function __construct() {
|
| 164 | - $this->templateValid = false; } |
|
| 164 | + $this->templateValid = false; } |
|
| 165 | 165 | |
| 166 | 166 | //--- template string handling -------------------------------------------------------------------------------------- |
| 167 | 167 | |
@@ -172,13 +172,13 @@ discard block |
||
| 172 | 172 | * @access public |
| 173 | 173 | */ |
| 174 | 174 | function readTemplateFromFile($fileName) {
|
| 175 | - if (!$this->readFileIntoString($fileName, $s)) {
|
|
| 176 | - $this->triggerError("Error while reading template file ".$fileName.".");
|
|
| 177 | - return false; } |
|
| 178 | - if (!$this->setTemplateString($s)) { |
|
| 179 | - return false; |
|
| 180 | - } |
|
| 181 | - return true; } |
|
| 175 | + if (!$this->readFileIntoString($fileName, $s)) {
|
|
| 176 | + $this->triggerError("Error while reading template file ".$fileName.".");
|
|
| 177 | + return false; } |
|
| 178 | + if (!$this->setTemplateString($s)) { |
|
| 179 | + return false; |
|
| 180 | + } |
|
| 181 | + return true; } |
|
| 182 | 182 | |
| 183 | 183 | /** |
| 184 | 184 | * Assigns a new template string. |
@@ -187,14 +187,14 @@ discard block |
||
| 187 | 187 | * @access public |
| 188 | 188 | */ |
| 189 | 189 | function setTemplateString($templateString) {
|
| 190 | - $this->templateValid = false; |
|
| 191 | - $this->template = $templateString; |
|
| 192 | - if (!$this->parseTemplate()) { |
|
| 193 | - return false; |
|
| 194 | - } |
|
| 195 | - $this->reset(); |
|
| 196 | - $this->templateValid = true; |
|
| 197 | - return true; } |
|
| 190 | + $this->templateValid = false; |
|
| 191 | + $this->template = $templateString; |
|
| 192 | + if (!$this->parseTemplate()) { |
|
| 193 | + return false; |
|
| 194 | + } |
|
| 195 | + $this->reset(); |
|
| 196 | + $this->templateValid = true; |
|
| 197 | + return true; } |
|
| 198 | 198 | |
| 199 | 199 | /** |
| 200 | 200 | * Loads the template string for a subtemplate (used for the $Include command). |
@@ -202,11 +202,11 @@ discard block |
||
| 202 | 202 | * @access private |
| 203 | 203 | */ |
| 204 | 204 | function loadSubtemplate($subtemplateName, &$s) {
|
| 205 | - $subtemplateFileName = $this->combineFileSystemPath($this->subtemplateBasePath, $subtemplateName); |
|
| 206 | - if (!$this->readFileIntoString($subtemplateFileName, $s)) {
|
|
| 207 | - $this->triggerError("Error while reading subtemplate file ".$subtemplateFileName.".");
|
|
| 208 | - return false; } |
|
| 209 | - return true; } |
|
| 205 | + $subtemplateFileName = $this->combineFileSystemPath($this->subtemplateBasePath, $subtemplateName); |
|
| 206 | + if (!$this->readFileIntoString($subtemplateFileName, $s)) {
|
|
| 207 | + $this->triggerError("Error while reading subtemplate file ".$subtemplateFileName.".");
|
|
| 208 | + return false; } |
|
| 209 | + return true; } |
|
| 210 | 210 | |
| 211 | 211 | //--- template parsing ---------------------------------------------------------------------------------------------- |
| 212 | 212 | |
@@ -216,34 +216,34 @@ discard block |
||
| 216 | 216 | * @access private |
| 217 | 217 | */ |
| 218 | 218 | function parseTemplate() {
|
| 219 | - $this->initParsing(); |
|
| 220 | - $this->beginMainBlock(); |
|
| 221 | - if (!$this->parseTemplateCommands()) { |
|
| 222 | - return false; |
|
| 223 | - } |
|
| 224 | - $this->endMainBlock(); |
|
| 225 | - if (!$this->checkBlockDefinitionsComplete()) { |
|
| 226 | - return false; |
|
| 227 | - } |
|
| 228 | - if (!$this->parseTemplateVariables()) { |
|
| 229 | - return false; |
|
| 230 | - } |
|
| 231 | - $this->associateVariablesWithBlocks(); |
|
| 232 | - return true; } |
|
| 219 | + $this->initParsing(); |
|
| 220 | + $this->beginMainBlock(); |
|
| 221 | + if (!$this->parseTemplateCommands()) { |
|
| 222 | + return false; |
|
| 223 | + } |
|
| 224 | + $this->endMainBlock(); |
|
| 225 | + if (!$this->checkBlockDefinitionsComplete()) { |
|
| 226 | + return false; |
|
| 227 | + } |
|
| 228 | + if (!$this->parseTemplateVariables()) { |
|
| 229 | + return false; |
|
| 230 | + } |
|
| 231 | + $this->associateVariablesWithBlocks(); |
|
| 232 | + return true; } |
|
| 233 | 233 | |
| 234 | 234 | /** |
| 235 | 235 | * @access private |
| 236 | 236 | */ |
| 237 | 237 | function initParsing() {
|
| 238 | - $this->varTab = array(); |
|
| 239 | - $this->varTabCnt = 0; |
|
| 240 | - $this->varNameToNoMap = array(); |
|
| 241 | - $this->varRefTab = array(); |
|
| 242 | - $this->varRefTabCnt = 0; |
|
| 243 | - $this->blockTab = array(); |
|
| 244 | - $this->blockTabCnt = 0; |
|
| 245 | - $this->blockNameToNoMap = array(); |
|
| 246 | - $this->openBlocksTab = array(); } |
|
| 238 | + $this->varTab = array(); |
|
| 239 | + $this->varTabCnt = 0; |
|
| 240 | + $this->varNameToNoMap = array(); |
|
| 241 | + $this->varRefTab = array(); |
|
| 242 | + $this->varRefTabCnt = 0; |
|
| 243 | + $this->blockTab = array(); |
|
| 244 | + $this->blockTabCnt = 0; |
|
| 245 | + $this->blockNameToNoMap = array(); |
|
| 246 | + $this->openBlocksTab = array(); } |
|
| 247 | 247 | |
| 248 | 248 | /** |
| 249 | 249 | * Registers the main block. |
@@ -251,27 +251,27 @@ discard block |
||
| 251 | 251 | * @access private |
| 252 | 252 | */ |
| 253 | 253 | function beginMainBlock() {
|
| 254 | - $blockNo = 0; |
|
| 255 | - $this->registerBlock('@@InternalMainBlock@@', $blockNo);
|
|
| 256 | - $bte = & $this->blockTab[$blockNo]; |
|
| 257 | - $bte['tPosBegin'] = 0; |
|
| 258 | - $bte['tPosContentsBegin'] = 0; |
|
| 259 | - $bte['nestingLevel'] = 0; |
|
| 260 | - $bte['parentBlockNo'] = -1; |
|
| 261 | - $bte['definitionIsOpen'] = true; |
|
| 262 | - $this->openBlocksTab[0] = $blockNo; |
|
| 263 | - $this->currentNestingLevel = 1; } |
|
| 254 | + $blockNo = 0; |
|
| 255 | + $this->registerBlock('@@InternalMainBlock@@', $blockNo);
|
|
| 256 | + $bte = & $this->blockTab[$blockNo]; |
|
| 257 | + $bte['tPosBegin'] = 0; |
|
| 258 | + $bte['tPosContentsBegin'] = 0; |
|
| 259 | + $bte['nestingLevel'] = 0; |
|
| 260 | + $bte['parentBlockNo'] = -1; |
|
| 261 | + $bte['definitionIsOpen'] = true; |
|
| 262 | + $this->openBlocksTab[0] = $blockNo; |
|
| 263 | + $this->currentNestingLevel = 1; } |
|
| 264 | 264 | |
| 265 | 265 | /** |
| 266 | 266 | * Completes the main block registration. |
| 267 | 267 | * @access private |
| 268 | 268 | */ |
| 269 | 269 | function endMainBlock() {
|
| 270 | - $bte = & $this->blockTab[0]; |
|
| 271 | - $bte['tPosContentsEnd'] = strlen($this->template); |
|
| 272 | - $bte['tPosEnd'] = strlen($this->template); |
|
| 273 | - $bte['definitionIsOpen'] = false; |
|
| 274 | - $this->currentNestingLevel -= 1; } |
|
| 270 | + $bte = & $this->blockTab[0]; |
|
| 271 | + $bte['tPosContentsEnd'] = strlen($this->template); |
|
| 272 | + $bte['tPosEnd'] = strlen($this->template); |
|
| 273 | + $bte['definitionIsOpen'] = false; |
|
| 274 | + $this->currentNestingLevel -= 1; } |
|
| 275 | 275 | |
| 276 | 276 | /** |
| 277 | 277 | * Parses commands within the template in the format "<!-- $command parameters -->". |
@@ -279,46 +279,46 @@ discard block |
||
| 279 | 279 | * @access private |
| 280 | 280 | */ |
| 281 | 281 | function parseTemplateCommands() {
|
| 282 | - $p = 0; |
|
| 283 | - while (true) {
|
|
| 284 | - $p0 = strpos($this->template, '<!--', $p); |
|
| 285 | - if ($p0 === false) break; |
|
| 286 | - $p = strpos($this->template, '-->', $p0); |
|
| 287 | - if ($p === false) {
|
|
| 288 | - $this->triggerError("Invalid HTML comment in template at offset $p0.");
|
|
| 289 | - return false; } |
|
| 290 | - $p += 3; |
|
| 291 | - $cmdL = substr($this->template, $p0 + 4, $p - $p0 - 7); |
|
| 292 | - if (!$this->processTemplateCommand($cmdL, $p0, $p, $resumeFromStart)) |
|
| 293 | - return false; |
|
| 294 | - if ($resumeFromStart) $p = $p0; } |
|
| 295 | - return true; } |
|
| 282 | + $p = 0; |
|
| 283 | + while (true) {
|
|
| 284 | + $p0 = strpos($this->template, '<!--', $p); |
|
| 285 | + if ($p0 === false) break; |
|
| 286 | + $p = strpos($this->template, '-->', $p0); |
|
| 287 | + if ($p === false) {
|
|
| 288 | + $this->triggerError("Invalid HTML comment in template at offset $p0.");
|
|
| 289 | + return false; } |
|
| 290 | + $p += 3; |
|
| 291 | + $cmdL = substr($this->template, $p0 + 4, $p - $p0 - 7); |
|
| 292 | + if (!$this->processTemplateCommand($cmdL, $p0, $p, $resumeFromStart)) |
|
| 293 | + return false; |
|
| 294 | + if ($resumeFromStart) $p = $p0; } |
|
| 295 | + return true; } |
|
| 296 | 296 | |
| 297 | 297 | /** |
| 298 | 298 | * @return boolean true on success, false on error. |
| 299 | 299 | * @access private |
| 300 | 300 | */ |
| 301 | 301 | function processTemplateCommand($cmdL, $cmdTPosBegin, $cmdTPosEnd, &$resumeFromStart) {
|
| 302 | - $resumeFromStart = false; |
|
| 303 | - $p = 0; |
|
| 304 | - $cmd = ''; |
|
| 305 | - if (!$this->parseWord($cmdL, $p, $cmd)) return true; |
|
| 306 | - $parms = substr($cmdL, $p); |
|
| 307 | - switch (strtoupper($cmd)) {
|
|
| 308 | - case '$BEGINBLOCK': |
|
| 302 | + $resumeFromStart = false; |
|
| 303 | + $p = 0; |
|
| 304 | + $cmd = ''; |
|
| 305 | + if (!$this->parseWord($cmdL, $p, $cmd)) return true; |
|
| 306 | + $parms = substr($cmdL, $p); |
|
| 307 | + switch (strtoupper($cmd)) {
|
|
| 308 | + case '$BEGINBLOCK': |
|
| 309 | 309 | if (!$this->processBeginBlockCmd($parms, $cmdTPosBegin, $cmdTPosEnd)) |
| 310 | 310 | return false; |
| 311 | - break; |
|
| 312 | - case '$ENDBLOCK': |
|
| 311 | + break; |
|
| 312 | + case '$ENDBLOCK': |
|
| 313 | 313 | if (!$this->processEndBlockCmd($parms, $cmdTPosBegin, $cmdTPosEnd)) |
| 314 | 314 | return false; |
| 315 | - break; |
|
| 316 | - case '$INCLUDE': |
|
| 315 | + break; |
|
| 316 | + case '$INCLUDE': |
|
| 317 | 317 | if (!$this->processincludeCmd($parms, $cmdTPosBegin, $cmdTPosEnd)) |
| 318 | 318 | return false; |
| 319 | - $resumeFromStart = true; |
|
| 320 | - break; |
|
| 321 | - default: |
|
| 319 | + $resumeFromStart = true; |
|
| 320 | + break; |
|
| 321 | + default: |
|
| 322 | 322 | if ($cmd{0} == '$' && !(strlen($cmd) >= 2 && $cmd{1} == '{')) {
|
| 323 | 323 | $this->triggerError("Unknown command \"$cmd\" in template at offset $cmdTPosBegin.");
|
| 324 | 324 | return false; }} |
@@ -330,25 +330,25 @@ discard block |
||
| 330 | 330 | * @access private |
| 331 | 331 | */ |
| 332 | 332 | function processBeginBlockCmd($parms, $cmdTPosBegin, $cmdTPosEnd) {
|
| 333 | - $p = 0; |
|
| 334 | - if (!$this->parseWord($parms, $p, $blockName)) {
|
|
| 335 | - $this->triggerError("Missing block name in \$BeginBlock command in template at offset $cmdTPosBegin.");
|
|
| 336 | - return false; } |
|
| 337 | - if (trim(substr($parms, $p)) != '') {
|
|
| 338 | - $this->triggerError("Extra parameter in \$BeginBlock command in template at offset $cmdTPosBegin.");
|
|
| 339 | - return false; } |
|
| 340 | - $this->registerBlock($blockName, $blockNo); |
|
| 341 | - $btr = & $this->blockTab[$blockNo]; |
|
| 342 | - $btr['tPosBegin'] = $cmdTPosBegin; |
|
| 343 | - $btr['tPosContentsBegin'] = $cmdTPosEnd; |
|
| 344 | - $btr['nestingLevel'] = $this->currentNestingLevel; |
|
| 345 | - $btr['parentBlockNo'] = $this->openBlocksTab[$this->currentNestingLevel - 1]; |
|
| 346 | - $this->openBlocksTab[$this->currentNestingLevel] = $blockNo; |
|
| 347 | - $this->currentNestingLevel += 1; |
|
| 348 | - if ($this->currentNestingLevel > $this->maxNestingLevel) {
|
|
| 349 | - $this->triggerError("Block nesting overflow in template at offset $cmdTPosBegin.");
|
|
| 350 | - return false; } |
|
| 351 | - return true; } |
|
| 333 | + $p = 0; |
|
| 334 | + if (!$this->parseWord($parms, $p, $blockName)) {
|
|
| 335 | + $this->triggerError("Missing block name in \$BeginBlock command in template at offset $cmdTPosBegin.");
|
|
| 336 | + return false; } |
|
| 337 | + if (trim(substr($parms, $p)) != '') {
|
|
| 338 | + $this->triggerError("Extra parameter in \$BeginBlock command in template at offset $cmdTPosBegin.");
|
|
| 339 | + return false; } |
|
| 340 | + $this->registerBlock($blockName, $blockNo); |
|
| 341 | + $btr = & $this->blockTab[$blockNo]; |
|
| 342 | + $btr['tPosBegin'] = $cmdTPosBegin; |
|
| 343 | + $btr['tPosContentsBegin'] = $cmdTPosEnd; |
|
| 344 | + $btr['nestingLevel'] = $this->currentNestingLevel; |
|
| 345 | + $btr['parentBlockNo'] = $this->openBlocksTab[$this->currentNestingLevel - 1]; |
|
| 346 | + $this->openBlocksTab[$this->currentNestingLevel] = $blockNo; |
|
| 347 | + $this->currentNestingLevel += 1; |
|
| 348 | + if ($this->currentNestingLevel > $this->maxNestingLevel) {
|
|
| 349 | + $this->triggerError("Block nesting overflow in template at offset $cmdTPosBegin.");
|
|
| 350 | + return false; } |
|
| 351 | + return true; } |
|
| 352 | 352 | |
| 353 | 353 | /** |
| 354 | 354 | * Processes the $EndBlock command. |
@@ -356,47 +356,47 @@ discard block |
||
| 356 | 356 | * @access private |
| 357 | 357 | */ |
| 358 | 358 | function processEndBlockCmd($parms, $cmdTPosBegin, $cmdTPosEnd) {
|
| 359 | - $p = 0; |
|
| 360 | - if (!$this->parseWord($parms, $p, $blockName)) {
|
|
| 361 | - $this->triggerError("Missing block name in \$EndBlock command in template at offset $cmdTPosBegin.");
|
|
| 362 | - return false; } |
|
| 363 | - if (trim(substr($parms, $p)) != '') {
|
|
| 364 | - $this->triggerError("Extra parameter in \$EndBlock command in template at offset $cmdTPosBegin.");
|
|
| 365 | - return false; } |
|
| 366 | - if (!$this->lookupBlockName($blockName, $blockNo)) {
|
|
| 367 | - $this->triggerError("Undefined block name \"$blockName\" in \$EndBlock command in template at offset $cmdTPosBegin.");
|
|
| 368 | - return false; } |
|
| 369 | - $this->currentNestingLevel -= 1; |
|
| 370 | - $btr = & $this->blockTab[$blockNo]; |
|
| 371 | - if (!$btr['definitionIsOpen']) {
|
|
| 372 | - $this->triggerError("Multiple \$EndBlock command for block \"$blockName\" in template at offset $cmdTPosBegin.");
|
|
| 373 | - return false; } |
|
| 374 | - if ($btr['nestingLevel'] != $this->currentNestingLevel) {
|
|
| 375 | - $this->triggerError("Block nesting level mismatch at \$EndBlock command for block \"$blockName\" in template at offset $cmdTPosBegin.");
|
|
| 376 | - return false; } |
|
| 377 | - $btr['tPosContentsEnd'] = $cmdTPosBegin; |
|
| 378 | - $btr['tPosEnd'] = $cmdTPosEnd; |
|
| 379 | - $btr['definitionIsOpen'] = false; |
|
| 380 | - return true; } |
|
| 359 | + $p = 0; |
|
| 360 | + if (!$this->parseWord($parms, $p, $blockName)) {
|
|
| 361 | + $this->triggerError("Missing block name in \$EndBlock command in template at offset $cmdTPosBegin.");
|
|
| 362 | + return false; } |
|
| 363 | + if (trim(substr($parms, $p)) != '') {
|
|
| 364 | + $this->triggerError("Extra parameter in \$EndBlock command in template at offset $cmdTPosBegin.");
|
|
| 365 | + return false; } |
|
| 366 | + if (!$this->lookupBlockName($blockName, $blockNo)) {
|
|
| 367 | + $this->triggerError("Undefined block name \"$blockName\" in \$EndBlock command in template at offset $cmdTPosBegin.");
|
|
| 368 | + return false; } |
|
| 369 | + $this->currentNestingLevel -= 1; |
|
| 370 | + $btr = & $this->blockTab[$blockNo]; |
|
| 371 | + if (!$btr['definitionIsOpen']) {
|
|
| 372 | + $this->triggerError("Multiple \$EndBlock command for block \"$blockName\" in template at offset $cmdTPosBegin.");
|
|
| 373 | + return false; } |
|
| 374 | + if ($btr['nestingLevel'] != $this->currentNestingLevel) {
|
|
| 375 | + $this->triggerError("Block nesting level mismatch at \$EndBlock command for block \"$blockName\" in template at offset $cmdTPosBegin.");
|
|
| 376 | + return false; } |
|
| 377 | + $btr['tPosContentsEnd'] = $cmdTPosBegin; |
|
| 378 | + $btr['tPosEnd'] = $cmdTPosEnd; |
|
| 379 | + $btr['definitionIsOpen'] = false; |
|
| 380 | + return true; } |
|
| 381 | 381 | |
| 382 | 382 | /** |
| 383 | 383 | * @access private |
| 384 | 384 | */ |
| 385 | 385 | function registerBlock($blockName, &$blockNo) {
|
| 386 | - $blockNo = $this->blockTabCnt++; |
|
| 387 | - $btr = & $this->blockTab[$blockNo]; |
|
| 388 | - $btr = array(); |
|
| 389 | - $btr['blockName'] = $blockName; |
|
| 390 | - if (!$this->lookupBlockName($blockName, $btr['nextWithSameName'])) |
|
| 391 | - $btr['nextWithSameName'] = -1; |
|
| 392 | - $btr['definitionIsOpen'] = true; |
|
| 393 | - $btr['instances'] = 0; |
|
| 394 | - $btr['firstBlockInstNo'] = -1; |
|
| 395 | - $btr['lastBlockInstNo'] = -1; |
|
| 396 | - $btr['blockVarCnt'] = 0; |
|
| 397 | - $btr['firstVarRefNo'] = -1; |
|
| 398 | - $btr['blockVarNoToVarNoMap'] = array(); |
|
| 399 | - $this->blockNameToNoMap[strtoupper($blockName)] = $blockNo; } |
|
| 386 | + $blockNo = $this->blockTabCnt++; |
|
| 387 | + $btr = & $this->blockTab[$blockNo]; |
|
| 388 | + $btr = array(); |
|
| 389 | + $btr['blockName'] = $blockName; |
|
| 390 | + if (!$this->lookupBlockName($blockName, $btr['nextWithSameName'])) |
|
| 391 | + $btr['nextWithSameName'] = -1; |
|
| 392 | + $btr['definitionIsOpen'] = true; |
|
| 393 | + $btr['instances'] = 0; |
|
| 394 | + $btr['firstBlockInstNo'] = -1; |
|
| 395 | + $btr['lastBlockInstNo'] = -1; |
|
| 396 | + $btr['blockVarCnt'] = 0; |
|
| 397 | + $btr['firstVarRefNo'] = -1; |
|
| 398 | + $btr['blockVarNoToVarNoMap'] = array(); |
|
| 399 | + $this->blockNameToNoMap[strtoupper($blockName)] = $blockNo; } |
|
| 400 | 400 | |
| 401 | 401 | /** |
| 402 | 402 | * Checks that all block definitions are closed. |
@@ -404,15 +404,15 @@ discard block |
||
| 404 | 404 | * @access private |
| 405 | 405 | */ |
| 406 | 406 | function checkBlockDefinitionsComplete() {
|
| 407 | - for ($blockNo = 0; $blockNo < $this->blockTabCnt; $blockNo++) {
|
|
| 408 | - $btr = & $this->blockTab[$blockNo]; |
|
| 409 | - if ($btr['definitionIsOpen']) {
|
|
| 410 | - $this->triggerError("Missing \$EndBlock command in template for block ".$btr['blockName'].".");
|
|
| 411 | - return false; }} |
|
| 412 | - if ($this->currentNestingLevel != 0) {
|
|
| 413 | - $this->triggerError("Block nesting level error at end of template.");
|
|
| 414 | - return false; } |
|
| 415 | - return true; } |
|
| 407 | + for ($blockNo = 0; $blockNo < $this->blockTabCnt; $blockNo++) {
|
|
| 408 | + $btr = & $this->blockTab[$blockNo]; |
|
| 409 | + if ($btr['definitionIsOpen']) {
|
|
| 410 | + $this->triggerError("Missing \$EndBlock command in template for block ".$btr['blockName'].".");
|
|
| 411 | + return false; }} |
|
| 412 | + if ($this->currentNestingLevel != 0) {
|
|
| 413 | + $this->triggerError("Block nesting level error at end of template.");
|
|
| 414 | + return false; } |
|
| 415 | + return true; } |
|
| 416 | 416 | |
| 417 | 417 | /** |
| 418 | 418 | * Processes the $Include command. |
@@ -420,14 +420,14 @@ discard block |
||
| 420 | 420 | * @access private |
| 421 | 421 | */ |
| 422 | 422 | function processIncludeCmd($parms, $cmdTPosBegin, $cmdTPosEnd) {
|
| 423 | - $p = 0; |
|
| 424 | - if (!$this->parseWordOrQuotedString($parms, $p, $subtemplateName)) {
|
|
| 425 | - $this->triggerError("Missing or invalid subtemplate name in \$Include command in template at offset $cmdTPosBegin.");
|
|
| 426 | - return false; } |
|
| 427 | - if (trim(substr($parms, $p)) != '') {
|
|
| 428 | - $this->triggerError("Extra parameter in \$include command in template at offset $cmdTPosBegin.");
|
|
| 429 | - return false; } |
|
| 430 | - return $this->insertSubtemplate($subtemplateName, $cmdTPosBegin, $cmdTPosEnd); } |
|
| 423 | + $p = 0; |
|
| 424 | + if (!$this->parseWordOrQuotedString($parms, $p, $subtemplateName)) {
|
|
| 425 | + $this->triggerError("Missing or invalid subtemplate name in \$Include command in template at offset $cmdTPosBegin.");
|
|
| 426 | + return false; } |
|
| 427 | + if (trim(substr($parms, $p)) != '') {
|
|
| 428 | + $this->triggerError("Extra parameter in \$include command in template at offset $cmdTPosBegin.");
|
|
| 429 | + return false; } |
|
| 430 | + return $this->insertSubtemplate($subtemplateName, $cmdTPosBegin, $cmdTPosEnd); } |
|
| 431 | 431 | |
| 432 | 432 | /** |
| 433 | 433 | * Processes the $Include command. |
@@ -435,14 +435,14 @@ discard block |
||
| 435 | 435 | * @access private |
| 436 | 436 | */ |
| 437 | 437 | function insertSubtemplate($subtemplateName, $tPos1, $tPos2) {
|
| 438 | - if (strlen($this->template) > $this->maxInclTemplateSize) {
|
|
| 439 | - $this->triggerError("Subtemplate include aborted because the internal template string is longer than $this->maxInclTemplateSize characters.");
|
|
| 440 | - return false; } |
|
| 441 | - if (!$this->loadSubtemplate($subtemplateName, $subtemplate)) return false; |
|
| 442 | - // (Copying the template to insert a subtemplate is a bit slow. In a future implementation of MiniTemplator, |
|
| 443 | - // a table could be used that contains references to the string fragments.) |
|
| 444 | - $this->template = substr($this->template, 0, $tPos1).$subtemplate.substr($this->template, $tPos2); |
|
| 445 | - return true; } |
|
| 438 | + if (strlen($this->template) > $this->maxInclTemplateSize) {
|
|
| 439 | + $this->triggerError("Subtemplate include aborted because the internal template string is longer than $this->maxInclTemplateSize characters.");
|
|
| 440 | + return false; } |
|
| 441 | + if (!$this->loadSubtemplate($subtemplateName, $subtemplate)) return false; |
|
| 442 | + // (Copying the template to insert a subtemplate is a bit slow. In a future implementation of MiniTemplator, |
|
| 443 | + // a table could be used that contains references to the string fragments.) |
|
| 444 | + $this->template = substr($this->template, 0, $tPos1).$subtemplate.substr($this->template, $tPos2); |
|
| 445 | + return true; } |
|
| 446 | 446 | |
| 447 | 447 | /** |
| 448 | 448 | * Parses variable references within the template in the format "${VarName}".
|
@@ -450,79 +450,79 @@ discard block |
||
| 450 | 450 | * @access private |
| 451 | 451 | */ |
| 452 | 452 | function parseTemplateVariables() {
|
| 453 | - $p = 0; |
|
| 454 | - while (true) {
|
|
| 455 | - $p = strpos($this->template, '${', $p);
|
|
| 456 | - if ($p === false) { |
|
| 457 | - break; |
|
| 458 | - } |
|
| 459 | - $p0 = $p; |
|
| 460 | - $p = strpos($this->template, '}', $p); |
|
| 461 | - if ($p === false) {
|
|
| 462 | - $this->triggerError("Invalid variable reference in template at offset $p0.");
|
|
| 463 | - return false; } |
|
| 464 | - $p += 1; |
|
| 465 | - $varName = trim(substr($this->template, $p0 + 2, $p - $p0 - 3)); |
|
| 466 | - if (strlen($varName) == 0) {
|
|
| 467 | - $this->triggerError("Empty variable name in template at offset $p0.");
|
|
| 468 | - return false; } |
|
| 469 | - $this->registerVariableReference($varName, $p0, $p); } |
|
| 470 | - return true; } |
|
| 453 | + $p = 0; |
|
| 454 | + while (true) {
|
|
| 455 | + $p = strpos($this->template, '${', $p);
|
|
| 456 | + if ($p === false) { |
|
| 457 | + break; |
|
| 458 | + } |
|
| 459 | + $p0 = $p; |
|
| 460 | + $p = strpos($this->template, '}', $p); |
|
| 461 | + if ($p === false) {
|
|
| 462 | + $this->triggerError("Invalid variable reference in template at offset $p0.");
|
|
| 463 | + return false; } |
|
| 464 | + $p += 1; |
|
| 465 | + $varName = trim(substr($this->template, $p0 + 2, $p - $p0 - 3)); |
|
| 466 | + if (strlen($varName) == 0) {
|
|
| 467 | + $this->triggerError("Empty variable name in template at offset $p0.");
|
|
| 468 | + return false; } |
|
| 469 | + $this->registerVariableReference($varName, $p0, $p); } |
|
| 470 | + return true; } |
|
| 471 | 471 | |
| 472 | 472 | /** |
| 473 | 473 | * @access private |
| 474 | 474 | */ |
| 475 | 475 | function registerVariableReference($varName, $tPosBegin, $tPosEnd) {
|
| 476 | - if (!$this->lookupVariableName($varName, $varNo)) |
|
| 477 | - $this->registerVariable($varName, $varNo); |
|
| 478 | - $varRefNo = $this->varRefTabCnt++; |
|
| 479 | - $vrtr = & $this->varRefTab[$varRefNo]; |
|
| 480 | - $vrtr = array(); |
|
| 481 | - $vrtr['tPosBegin'] = $tPosBegin; |
|
| 482 | - $vrtr['tPosEnd'] = $tPosEnd; |
|
| 483 | - $vrtr['varNo'] = $varNo; } |
|
| 476 | + if (!$this->lookupVariableName($varName, $varNo)) |
|
| 477 | + $this->registerVariable($varName, $varNo); |
|
| 478 | + $varRefNo = $this->varRefTabCnt++; |
|
| 479 | + $vrtr = & $this->varRefTab[$varRefNo]; |
|
| 480 | + $vrtr = array(); |
|
| 481 | + $vrtr['tPosBegin'] = $tPosBegin; |
|
| 482 | + $vrtr['tPosEnd'] = $tPosEnd; |
|
| 483 | + $vrtr['varNo'] = $varNo; } |
|
| 484 | 484 | |
| 485 | 485 | /** |
| 486 | 486 | * @access private |
| 487 | 487 | */ |
| 488 | 488 | function registerVariable($varName, &$varNo) {
|
| 489 | - $varNo = $this->varTabCnt++; |
|
| 490 | - $vtr = & $this->varTab[$varNo]; |
|
| 491 | - $vtr = array(); |
|
| 492 | - $vtr['varName'] = $varName; |
|
| 493 | - $vtr['varValue'] = ''; |
|
| 494 | - $this->varNameToNoMap[strtoupper($varName)] = $varNo; } |
|
| 489 | + $varNo = $this->varTabCnt++; |
|
| 490 | + $vtr = & $this->varTab[$varNo]; |
|
| 491 | + $vtr = array(); |
|
| 492 | + $vtr['varName'] = $varName; |
|
| 493 | + $vtr['varValue'] = ''; |
|
| 494 | + $this->varNameToNoMap[strtoupper($varName)] = $varNo; } |
|
| 495 | 495 | |
| 496 | 496 | /** |
| 497 | 497 | * Associates variable references with blocks. |
| 498 | 498 | * @access private |
| 499 | 499 | */ |
| 500 | 500 | function associateVariablesWithBlocks() {
|
| 501 | - $varRefNo = 0; |
|
| 502 | - $activeBlockNo = 0; |
|
| 503 | - $nextBlockNo = 1; |
|
| 504 | - while ($varRefNo < $this->varRefTabCnt) {
|
|
| 505 | - $vrtr = & $this->varRefTab[$varRefNo]; |
|
| 506 | - $varRefTPos = $vrtr['tPosBegin']; |
|
| 507 | - $varNo = $vrtr['varNo']; |
|
| 508 | - if ($varRefTPos >= $this->blockTab[$activeBlockNo]['tPosEnd']) {
|
|
| 509 | - $activeBlockNo = $this->blockTab[$activeBlockNo]['parentBlockNo']; |
|
| 510 | - continue; } |
|
| 511 | - if ($nextBlockNo < $this->blockTabCnt) {
|
|
| 512 | - if ($varRefTPos >= $this->blockTab[$nextBlockNo]['tPosBegin']) {
|
|
| 501 | + $varRefNo = 0; |
|
| 502 | + $activeBlockNo = 0; |
|
| 503 | + $nextBlockNo = 1; |
|
| 504 | + while ($varRefNo < $this->varRefTabCnt) {
|
|
| 505 | + $vrtr = & $this->varRefTab[$varRefNo]; |
|
| 506 | + $varRefTPos = $vrtr['tPosBegin']; |
|
| 507 | + $varNo = $vrtr['varNo']; |
|
| 508 | + if ($varRefTPos >= $this->blockTab[$activeBlockNo]['tPosEnd']) {
|
|
| 509 | + $activeBlockNo = $this->blockTab[$activeBlockNo]['parentBlockNo']; |
|
| 510 | + continue; } |
|
| 511 | + if ($nextBlockNo < $this->blockTabCnt) {
|
|
| 512 | + if ($varRefTPos >= $this->blockTab[$nextBlockNo]['tPosBegin']) {
|
|
| 513 | 513 | $activeBlockNo = $nextBlockNo; |
| 514 | 514 | $nextBlockNo += 1; |
| 515 | 515 | continue; }} |
| 516 | - $btr = & $this->blockTab[$activeBlockNo]; |
|
| 517 | - if ($varRefTPos < $btr['tPosBegin']) |
|
| 518 | - $this->programLogicError(1); |
|
| 519 | - $blockVarNo = $btr['blockVarCnt']++; |
|
| 520 | - $btr['blockVarNoToVarNoMap'][$blockVarNo] = $varNo; |
|
| 521 | - if ($btr['firstVarRefNo'] == -1) |
|
| 522 | - $btr['firstVarRefNo'] = $varRefNo; |
|
| 523 | - $vrtr['blockNo'] = $activeBlockNo; |
|
| 524 | - $vrtr['blockVarNo'] = $blockVarNo; |
|
| 525 | - $varRefNo += 1; }} |
|
| 516 | + $btr = & $this->blockTab[$activeBlockNo]; |
|
| 517 | + if ($varRefTPos < $btr['tPosBegin']) |
|
| 518 | + $this->programLogicError(1); |
|
| 519 | + $blockVarNo = $btr['blockVarCnt']++; |
|
| 520 | + $btr['blockVarNoToVarNoMap'][$blockVarNo] = $varNo; |
|
| 521 | + if ($btr['firstVarRefNo'] == -1) |
|
| 522 | + $btr['firstVarRefNo'] = $varRefNo; |
|
| 523 | + $vrtr['blockNo'] = $activeBlockNo; |
|
| 524 | + $vrtr['blockVarNo'] = $blockVarNo; |
|
| 525 | + $varRefNo += 1; }} |
|
| 526 | 526 | |
| 527 | 527 | //--- build up (template variables and blocks) ---------------------------------------------------------------------- |
| 528 | 528 | |
@@ -535,15 +535,15 @@ discard block |
||
| 535 | 535 | * @access public |
| 536 | 536 | */ |
| 537 | 537 | function reset() {
|
| 538 | - for ($varNo = 0; $varNo < $this->varTabCnt; $varNo++) |
|
| 539 | - $this->varTab[$varNo]['varValue'] = ''; |
|
| 540 | - for ($blockNo = 0; $blockNo < $this->blockTabCnt; $blockNo++) {
|
|
| 541 | - $btr = & $this->blockTab[$blockNo]; |
|
| 542 | - $btr['instances'] = 0; |
|
| 543 | - $btr['firstBlockInstNo'] = -1; |
|
| 544 | - $btr['lastBlockInstNo'] = -1; } |
|
| 545 | - $this->blockInstTab = array(); |
|
| 546 | - $this->blockInstTabCnt = 0; } |
|
| 538 | + for ($varNo = 0; $varNo < $this->varTabCnt; $varNo++) |
|
| 539 | + $this->varTab[$varNo]['varValue'] = ''; |
|
| 540 | + for ($blockNo = 0; $blockNo < $this->blockTabCnt; $blockNo++) {
|
|
| 541 | + $btr = & $this->blockTab[$blockNo]; |
|
| 542 | + $btr['instances'] = 0; |
|
| 543 | + $btr['firstBlockInstNo'] = -1; |
|
| 544 | + $btr['lastBlockInstNo'] = -1; } |
|
| 545 | + $this->blockInstTab = array(); |
|
| 546 | + $this->blockInstTabCnt = 0; } |
|
| 547 | 547 | |
| 548 | 548 | /** |
| 549 | 549 | * Sets a template variable. |
@@ -561,13 +561,13 @@ discard block |
||
| 561 | 561 | * @access public |
| 562 | 562 | */ |
| 563 | 563 | function setVariable($variableName, $variableValue, $isOptional = false) {
|
| 564 | - if (!$this->templateValid) {$this->triggerError("Template not valid."); return false; }
|
|
| 565 | - if (!$this->lookupVariableName($variableName, $varNo)) {
|
|
| 566 | - if ($isOptional) return true; |
|
| 567 | - $this->triggerError("Variable \"$variableName\" not defined in template.");
|
|
| 568 | - return false; } |
|
| 569 | - $this->varTab[$varNo]['varValue'] = $variableValue; |
|
| 570 | - return true; } |
|
| 564 | + if (!$this->templateValid) {$this->triggerError("Template not valid."); return false; }
|
|
| 565 | + if (!$this->lookupVariableName($variableName, $varNo)) {
|
|
| 566 | + if ($isOptional) return true; |
|
| 567 | + $this->triggerError("Variable \"$variableName\" not defined in template.");
|
|
| 568 | + return false; } |
|
| 569 | + $this->varTab[$varNo]['varValue'] = $variableValue; |
|
| 570 | + return true; } |
|
| 571 | 571 | |
| 572 | 572 | /** |
| 573 | 573 | * Sets a template variable to an escaped string. |
@@ -588,7 +588,7 @@ discard block |
||
| 588 | 588 | * @access public |
| 589 | 589 | */ |
| 590 | 590 | function setVariableEsc($variableName, $variableValue, $isOptional = false) {
|
| 591 | - return $this->setVariable($variableName, htmlspecialchars($variableValue, ENT_QUOTES), $isOptional); } |
|
| 591 | + return $this->setVariable($variableName, htmlspecialchars($variableValue, ENT_QUOTES), $isOptional); } |
|
| 592 | 592 | |
| 593 | 593 | /** |
| 594 | 594 | * Checks whether a variable with the specified name exists within the template. |
@@ -598,8 +598,8 @@ discard block |
||
| 598 | 598 | * @access public |
| 599 | 599 | */ |
| 600 | 600 | function variableExists($variableName) {
|
| 601 | - if (!$this->templateValid) {$this->triggerError("Template not valid."); return false; }
|
|
| 602 | - return $this->lookupVariableName($variableName, $varNo); } |
|
| 601 | + if (!$this->templateValid) {$this->triggerError("Template not valid."); return false; }
|
|
| 602 | + return $this->lookupVariableName($variableName, $varNo); } |
|
| 603 | 603 | |
| 604 | 604 | /** |
| 605 | 605 | * Adds an instance of a template block. |
@@ -615,48 +615,48 @@ discard block |
||
| 615 | 615 | * @access public |
| 616 | 616 | */ |
| 617 | 617 | function addBlock($blockName) {
|
| 618 | - if (!$this->templateValid) {$this->triggerError("Template not valid."); return false; }
|
|
| 619 | - if (!$this->lookupBlockName($blockName, $blockNo)) {
|
|
| 620 | - $this->triggerError("Block \"$blockName\" not defined in template.");
|
|
| 621 | - return false; } |
|
| 622 | - while ($blockNo != -1) {
|
|
| 623 | - $this->addBlockByNo($blockNo); |
|
| 624 | - $blockNo = $this->blockTab[$blockNo]['nextWithSameName']; } |
|
| 625 | - return true; } |
|
| 618 | + if (!$this->templateValid) {$this->triggerError("Template not valid."); return false; }
|
|
| 619 | + if (!$this->lookupBlockName($blockName, $blockNo)) {
|
|
| 620 | + $this->triggerError("Block \"$blockName\" not defined in template.");
|
|
| 621 | + return false; } |
|
| 622 | + while ($blockNo != -1) {
|
|
| 623 | + $this->addBlockByNo($blockNo); |
|
| 624 | + $blockNo = $this->blockTab[$blockNo]['nextWithSameName']; } |
|
| 625 | + return true; } |
|
| 626 | 626 | |
| 627 | 627 | /** |
| 628 | 628 | * @access private |
| 629 | 629 | */ |
| 630 | 630 | function addBlockByNo($blockNo) {
|
| 631 | - $btr = & $this->blockTab[$blockNo]; |
|
| 632 | - $this->registerBlockInstance($blockInstNo); |
|
| 633 | - $bitr = & $this->blockInstTab[$blockInstNo]; |
|
| 634 | - if ($btr['firstBlockInstNo'] == -1) |
|
| 635 | - $btr['firstBlockInstNo'] = $blockInstNo; |
|
| 636 | - if ($btr['lastBlockInstNo'] != -1) |
|
| 637 | - $this->blockInstTab[$btr['lastBlockInstNo']]['nextBlockInstNo'] = $blockInstNo; |
|
| 638 | - // set forward pointer of chain |
|
| 639 | - $btr['lastBlockInstNo'] = $blockInstNo; |
|
| 640 | - $parentBlockNo = $btr['parentBlockNo']; |
|
| 641 | - $blockVarCnt = $btr['blockVarCnt']; |
|
| 642 | - $bitr['blockNo'] = $blockNo; |
|
| 643 | - $bitr['instanceLevel'] = $btr['instances']++; |
|
| 644 | - if ($parentBlockNo == -1) |
|
| 645 | - $bitr['parentInstLevel'] = -1; |
|
| 631 | + $btr = & $this->blockTab[$blockNo]; |
|
| 632 | + $this->registerBlockInstance($blockInstNo); |
|
| 633 | + $bitr = & $this->blockInstTab[$blockInstNo]; |
|
| 634 | + if ($btr['firstBlockInstNo'] == -1) |
|
| 635 | + $btr['firstBlockInstNo'] = $blockInstNo; |
|
| 636 | + if ($btr['lastBlockInstNo'] != -1) |
|
| 637 | + $this->blockInstTab[$btr['lastBlockInstNo']]['nextBlockInstNo'] = $blockInstNo; |
|
| 638 | + // set forward pointer of chain |
|
| 639 | + $btr['lastBlockInstNo'] = $blockInstNo; |
|
| 640 | + $parentBlockNo = $btr['parentBlockNo']; |
|
| 641 | + $blockVarCnt = $btr['blockVarCnt']; |
|
| 642 | + $bitr['blockNo'] = $blockNo; |
|
| 643 | + $bitr['instanceLevel'] = $btr['instances']++; |
|
| 644 | + if ($parentBlockNo == -1) |
|
| 645 | + $bitr['parentInstLevel'] = -1; |
|
| 646 | 646 | else |
| 647 | - $bitr['parentInstLevel'] = $this->blockTab[$parentBlockNo]['instances']; |
|
| 648 | - $bitr['nextBlockInstNo'] = -1; |
|
| 649 | - $bitr['blockVarTab'] = array(); |
|
| 650 | - // copy instance variables for this block |
|
| 651 | - for ($blockVarNo = 0; $blockVarNo < $blockVarCnt; $blockVarNo++) {
|
|
| 652 | - $varNo = $btr['blockVarNoToVarNoMap'][$blockVarNo]; |
|
| 653 | - $bitr['blockVarTab'][$blockVarNo] = $this->varTab[$varNo]['varValue']; }} |
|
| 647 | + $bitr['parentInstLevel'] = $this->blockTab[$parentBlockNo]['instances']; |
|
| 648 | + $bitr['nextBlockInstNo'] = -1; |
|
| 649 | + $bitr['blockVarTab'] = array(); |
|
| 650 | + // copy instance variables for this block |
|
| 651 | + for ($blockVarNo = 0; $blockVarNo < $blockVarCnt; $blockVarNo++) {
|
|
| 652 | + $varNo = $btr['blockVarNoToVarNoMap'][$blockVarNo]; |
|
| 653 | + $bitr['blockVarTab'][$blockVarNo] = $this->varTab[$varNo]['varValue']; }} |
|
| 654 | 654 | |
| 655 | 655 | /** |
| 656 | 656 | * @access private |
| 657 | 657 | */ |
| 658 | 658 | function registerBlockInstance(&$blockInstNo) {
|
| 659 | - $blockInstNo = $this->blockInstTabCnt++; } |
|
| 659 | + $blockInstNo = $this->blockInstTabCnt++; } |
|
| 660 | 660 | |
| 661 | 661 | /** |
| 662 | 662 | * Checks whether a block with the specified name exists within the template. |
@@ -666,8 +666,8 @@ discard block |
||
| 666 | 666 | * @access public |
| 667 | 667 | */ |
| 668 | 668 | function blockExists($blockName) {
|
| 669 | - if (!$this->templateValid) {$this->triggerError("Template not valid."); return false; }
|
|
| 670 | - return $this->lookupBlockName($blockName, $blockNo); } |
|
| 669 | + if (!$this->templateValid) {$this->triggerError("Template not valid."); return false; }
|
|
| 670 | + return $this->lookupBlockName($blockName, $blockNo); } |
|
| 671 | 671 | |
| 672 | 672 | //--- output generation --------------------------------------------------------------------------------------------- |
| 673 | 673 | |
@@ -677,11 +677,11 @@ discard block |
||
| 677 | 677 | * @access public |
| 678 | 678 | */ |
| 679 | 679 | function generateOutput() {
|
| 680 | - $this->outputMode = 0; |
|
| 681 | - if (!$this->generateOutputPage()) { |
|
| 682 | - return false; |
|
| 683 | - } |
|
| 684 | - return true; } |
|
| 680 | + $this->outputMode = 0; |
|
| 681 | + if (!$this->generateOutputPage()) { |
|
| 682 | + return false; |
|
| 683 | + } |
|
| 684 | + return true; } |
|
| 685 | 685 | |
| 686 | 686 | /** |
| 687 | 687 | * Generates the HTML page and writes it to a file. |
@@ -690,13 +690,13 @@ discard block |
||
| 690 | 690 | * @access public |
| 691 | 691 | */ |
| 692 | 692 | function generateOutputToFile($fileName) {
|
| 693 | - $fh = fopen($fileName, "wb"); |
|
| 694 | - if ($fh === false) return false; |
|
| 695 | - $this->outputMode = 1; |
|
| 696 | - $this->outputFileHandle = $fh; |
|
| 697 | - $ok = $this->generateOutputPage(); |
|
| 698 | - fclose($fh); |
|
| 699 | - return $ok; } |
|
| 693 | + $fh = fopen($fileName, "wb"); |
|
| 694 | + if ($fh === false) return false; |
|
| 695 | + $this->outputMode = 1; |
|
| 696 | + $this->outputFileHandle = $fh; |
|
| 697 | + $ok = $this->generateOutputPage(); |
|
| 698 | + fclose($fh); |
|
| 699 | + return $ok; } |
|
| 700 | 700 | |
| 701 | 701 | /** |
| 702 | 702 | * Generates the HTML page and writes it to a string. |
@@ -706,30 +706,30 @@ discard block |
||
| 706 | 706 | * @access public |
| 707 | 707 | */ |
| 708 | 708 | function generateOutputToString(&$outputString) {
|
| 709 | - $outputString = "Error"; |
|
| 710 | - $this->outputMode = 2; |
|
| 711 | - $this->outputString = ""; |
|
| 712 | - if (!$this->generateOutputPage()) { |
|
| 713 | - return false; |
|
| 714 | - } |
|
| 715 | - $outputString = $this->outputString; |
|
| 716 | - return true; } |
|
| 709 | + $outputString = "Error"; |
|
| 710 | + $this->outputMode = 2; |
|
| 711 | + $this->outputString = ""; |
|
| 712 | + if (!$this->generateOutputPage()) { |
|
| 713 | + return false; |
|
| 714 | + } |
|
| 715 | + $outputString = $this->outputString; |
|
| 716 | + return true; } |
|
| 717 | 717 | |
| 718 | 718 | /** |
| 719 | 719 | * @access private |
| 720 | 720 | * @return boolean true on success, false on error. |
| 721 | 721 | */ |
| 722 | 722 | function generateOutputPage() {
|
| 723 | - if (!$this->templateValid) {$this->triggerError("Template not valid."); return false; }
|
|
| 724 | - if ($this->blockTab[0]['instances'] == 0) |
|
| 725 | - $this->addBlockByNo(0); // add main block |
|
| 726 | - for ($blockNo = 0; $blockNo < $this->blockTabCnt; $blockNo++) {
|
|
| 727 | - $btr = & $this->blockTab[$blockNo]; |
|
| 728 | - $btr['currBlockInstNo'] = $btr['firstBlockInstNo']; } |
|
| 729 | - $this->outputError = false; |
|
| 730 | - $this->writeBlockInstances(0, -1); |
|
| 731 | - if ($this->outputError) return false; |
|
| 732 | - return true; } |
|
| 723 | + if (!$this->templateValid) {$this->triggerError("Template not valid."); return false; }
|
|
| 724 | + if ($this->blockTab[0]['instances'] == 0) |
|
| 725 | + $this->addBlockByNo(0); // add main block |
|
| 726 | + for ($blockNo = 0; $blockNo < $this->blockTabCnt; $blockNo++) {
|
|
| 727 | + $btr = & $this->blockTab[$blockNo]; |
|
| 728 | + $btr['currBlockInstNo'] = $btr['firstBlockInstNo']; } |
|
| 729 | + $this->outputError = false; |
|
| 730 | + $this->writeBlockInstances(0, -1); |
|
| 731 | + if ($this->outputError) return false; |
|
| 732 | + return true; } |
|
| 733 | 733 | |
| 734 | 734 | /** |
| 735 | 735 | * Writes all instances of a block that are contained within a specific |
@@ -738,64 +738,64 @@ discard block |
||
| 738 | 738 | * @access private |
| 739 | 739 | */ |
| 740 | 740 | function writeBlockInstances($blockNo, $parentInstLevel) {
|
| 741 | - $btr = & $this->blockTab[$blockNo]; |
|
| 742 | - while (!$this->outputError) {
|
|
| 743 | - $blockInstNo = $btr['currBlockInstNo']; |
|
| 744 | - if ($blockInstNo == -1) break; |
|
| 745 | - $bitr = & $this->blockInstTab[$blockInstNo]; |
|
| 746 | - if ($bitr['parentInstLevel'] < $parentInstLevel) |
|
| 747 | - $this->programLogicError(2); |
|
| 748 | - if ($bitr['parentInstLevel'] > $parentInstLevel) break; |
|
| 749 | - $this->writeBlockInstance($blockInstNo); |
|
| 750 | - $btr['currBlockInstNo'] = $bitr['nextBlockInstNo']; }} |
|
| 741 | + $btr = & $this->blockTab[$blockNo]; |
|
| 742 | + while (!$this->outputError) {
|
|
| 743 | + $blockInstNo = $btr['currBlockInstNo']; |
|
| 744 | + if ($blockInstNo == -1) break; |
|
| 745 | + $bitr = & $this->blockInstTab[$blockInstNo]; |
|
| 746 | + if ($bitr['parentInstLevel'] < $parentInstLevel) |
|
| 747 | + $this->programLogicError(2); |
|
| 748 | + if ($bitr['parentInstLevel'] > $parentInstLevel) break; |
|
| 749 | + $this->writeBlockInstance($blockInstNo); |
|
| 750 | + $btr['currBlockInstNo'] = $bitr['nextBlockInstNo']; }} |
|
| 751 | 751 | |
| 752 | 752 | /** |
| 753 | 753 | * @access private |
| 754 | 754 | */ |
| 755 | 755 | function writeBlockInstance($blockInstNo) {
|
| 756 | - $bitr = & $this->blockInstTab[$blockInstNo]; |
|
| 757 | - $blockNo = $bitr['blockNo']; |
|
| 758 | - $btr = & $this->blockTab[$blockNo]; |
|
| 759 | - $tPos = $btr['tPosContentsBegin']; |
|
| 760 | - $subBlockNo = $blockNo + 1; |
|
| 761 | - $varRefNo = $btr['firstVarRefNo']; |
|
| 762 | - while (!$this->outputError) {
|
|
| 763 | - $tPos2 = $btr['tPosContentsEnd']; |
|
| 764 | - $kind = 0; // assume end-of-block |
|
| 765 | - if ($varRefNo != -1 && $varRefNo < $this->varRefTabCnt) { // check for variable reference
|
|
| 766 | - $vrtr = & $this->varRefTab[$varRefNo]; |
|
| 767 | - if ($vrtr['tPosBegin'] < $tPos) {
|
|
| 756 | + $bitr = & $this->blockInstTab[$blockInstNo]; |
|
| 757 | + $blockNo = $bitr['blockNo']; |
|
| 758 | + $btr = & $this->blockTab[$blockNo]; |
|
| 759 | + $tPos = $btr['tPosContentsBegin']; |
|
| 760 | + $subBlockNo = $blockNo + 1; |
|
| 761 | + $varRefNo = $btr['firstVarRefNo']; |
|
| 762 | + while (!$this->outputError) {
|
|
| 763 | + $tPos2 = $btr['tPosContentsEnd']; |
|
| 764 | + $kind = 0; // assume end-of-block |
|
| 765 | + if ($varRefNo != -1 && $varRefNo < $this->varRefTabCnt) { // check for variable reference
|
|
| 766 | + $vrtr = & $this->varRefTab[$varRefNo]; |
|
| 767 | + if ($vrtr['tPosBegin'] < $tPos) {
|
|
| 768 | 768 | $varRefNo += 1; |
| 769 | 769 | continue; } |
| 770 | - if ($vrtr['tPosBegin'] < $tPos2) {
|
|
| 770 | + if ($vrtr['tPosBegin'] < $tPos2) {
|
|
| 771 | 771 | $tPos2 = $vrtr['tPosBegin']; |
| 772 | 772 | $kind = 1; }} |
| 773 | - if ($subBlockNo < $this->blockTabCnt) { // check for subblock
|
|
| 774 | - $subBtr = & $this->blockTab[$subBlockNo]; |
|
| 775 | - if ($subBtr['tPosBegin'] < $tPos) {
|
|
| 773 | + if ($subBlockNo < $this->blockTabCnt) { // check for subblock
|
|
| 774 | + $subBtr = & $this->blockTab[$subBlockNo]; |
|
| 775 | + if ($subBtr['tPosBegin'] < $tPos) {
|
|
| 776 | 776 | $subBlockNo += 1; |
| 777 | 777 | continue; } |
| 778 | - if ($subBtr['tPosBegin'] < $tPos2) {
|
|
| 778 | + if ($subBtr['tPosBegin'] < $tPos2) {
|
|
| 779 | 779 | $tPos2 = $subBtr['tPosBegin']; |
| 780 | 780 | $kind = 2; }} |
| 781 | - if ($tPos2 > $tPos) |
|
| 782 | - $this->writeString(substr($this->template, $tPos, $tPos2 - $tPos)); |
|
| 783 | - switch ($kind) {
|
|
| 784 | - case 0: // end of block |
|
| 781 | + if ($tPos2 > $tPos) |
|
| 782 | + $this->writeString(substr($this->template, $tPos, $tPos2 - $tPos)); |
|
| 783 | + switch ($kind) {
|
|
| 784 | + case 0: // end of block |
|
| 785 | 785 | return; |
| 786 | - case 1: // variable |
|
| 786 | + case 1: // variable |
|
| 787 | 787 | $vrtr = & $this->varRefTab[$varRefNo]; |
| 788 | 788 | if ($vrtr['blockNo'] != $blockNo) |
| 789 | - $this->programLogicError(4); |
|
| 789 | + $this->programLogicError(4); |
|
| 790 | 790 | $variableValue = $bitr['blockVarTab'][$vrtr['blockVarNo']]; |
| 791 | 791 | $this->writeString($variableValue); |
| 792 | 792 | $tPos = $vrtr['tPosEnd']; |
| 793 | 793 | $varRefNo += 1; |
| 794 | 794 | break; |
| 795 | - case 2: // sub block |
|
| 795 | + case 2: // sub block |
|
| 796 | 796 | $subBtr = & $this->blockTab[$subBlockNo]; |
| 797 | 797 | if ($subBtr['parentBlockNo'] != $blockNo) |
| 798 | - $this->programLogicError(3); |
|
| 798 | + $this->programLogicError(3); |
|
| 799 | 799 | $this->writeBlockInstances($subBlockNo, $bitr['instanceLevel']); // recursive call |
| 800 | 800 | $tPos = $subBtr['tPosEnd']; |
| 801 | 801 | $subBlockNo += 1; |
@@ -805,19 +805,19 @@ discard block |
||
| 805 | 805 | * @access private |
| 806 | 806 | */ |
| 807 | 807 | function writeString($s) {
|
| 808 | - if ($this->outputError) return; |
|
| 809 | - switch ($this->outputMode) {
|
|
| 810 | - case 0: // output to PHP output stream |
|
| 808 | + if ($this->outputError) return; |
|
| 809 | + switch ($this->outputMode) {
|
|
| 810 | + case 0: // output to PHP output stream |
|
| 811 | 811 | if (!print($s)) |
| 812 | 812 | $this->outputError = true; |
| 813 | - break; |
|
| 814 | - case 1: // output to file |
|
| 813 | + break; |
|
| 814 | + case 1: // output to file |
|
| 815 | 815 | $rc = fwrite($this->outputFileHandle, $s); |
| 816 | - if ($rc === false) $this->outputError = true; |
|
| 817 | - break; |
|
| 818 | - case 2: // output to string |
|
| 816 | + if ($rc === false) $this->outputError = true; |
|
| 817 | + break; |
|
| 818 | + case 2: // output to string |
|
| 819 | 819 | $this->outputString .= $s; |
| 820 | - break; }} |
|
| 820 | + break; }} |
|
| 821 | 821 | |
| 822 | 822 | //--- name lookup routines ------------------------------------------------------------------------------------------ |
| 823 | 823 | |
@@ -827,10 +827,10 @@ discard block |
||
| 827 | 827 | * @access private |
| 828 | 828 | */ |
| 829 | 829 | function lookupVariableName($varName, &$varNo) {
|
| 830 | - $x = & $this->varNameToNoMap[strtoupper($varName)]; |
|
| 831 | - if (!isset($x)) return false; |
|
| 832 | - $varNo = $x; |
|
| 833 | - return true; } |
|
| 830 | + $x = & $this->varNameToNoMap[strtoupper($varName)]; |
|
| 831 | + if (!isset($x)) return false; |
|
| 832 | + $varNo = $x; |
|
| 833 | + return true; } |
|
| 834 | 834 | |
| 835 | 835 | /** |
| 836 | 836 | * Maps block name to block number. |
@@ -840,10 +840,10 @@ discard block |
||
| 840 | 840 | * @access private |
| 841 | 841 | */ |
| 842 | 842 | function lookupBlockName($blockName, &$blockNo) {
|
| 843 | - $x = & $this->blockNameToNoMap[strtoupper($blockName)]; |
|
| 844 | - if (!isset($x)) return false; |
|
| 845 | - $blockNo = $x; |
|
| 846 | - return true; } |
|
| 843 | + $x = & $this->blockNameToNoMap[strtoupper($blockName)]; |
|
| 844 | + if (!isset($x)) return false; |
|
| 845 | + $blockNo = $x; |
|
| 846 | + return true; } |
|
| 847 | 847 | |
| 848 | 848 | //--- general utility routines ----------------------------------------------------------------------------------------- |
| 849 | 849 | |
@@ -853,92 +853,92 @@ discard block |
||
| 853 | 853 | * @access private |
| 854 | 854 | */ |
| 855 | 855 | function readFileIntoString($fileName, &$s) {
|
| 856 | - if (function_exists('version_compare') && version_compare(phpversion(), "4.3.0", ">=")) {
|
|
| 857 | - $s = file_get_contents($fileName); |
|
| 858 | - if ($s === false) return false; |
|
| 859 | - return true; } |
|
| 860 | - $fh = fopen($fileName, "rb"); |
|
| 861 | - if ($fh === false) return false; |
|
| 862 | - $fileSize = filesize($fileName); |
|
| 863 | - if ($fileSize === false) {fclose($fh); return false; }
|
|
| 864 | - $s = fread($fh, $fileSize); |
|
| 865 | - fclose($fh); |
|
| 866 | - if (strlen($s) != $fileSize) return false; |
|
| 867 | - return true; } |
|
| 856 | + if (function_exists('version_compare') && version_compare(phpversion(), "4.3.0", ">=")) {
|
|
| 857 | + $s = file_get_contents($fileName); |
|
| 858 | + if ($s === false) return false; |
|
| 859 | + return true; } |
|
| 860 | + $fh = fopen($fileName, "rb"); |
|
| 861 | + if ($fh === false) return false; |
|
| 862 | + $fileSize = filesize($fileName); |
|
| 863 | + if ($fileSize === false) {fclose($fh); return false; }
|
|
| 864 | + $s = fread($fh, $fileSize); |
|
| 865 | + fclose($fh); |
|
| 866 | + if (strlen($s) != $fileSize) return false; |
|
| 867 | + return true; } |
|
| 868 | 868 | |
| 869 | 869 | /** |
| 870 | 870 | * @access private |
| 871 | 871 | * @return boolean true on success, false when the end of the string is reached. |
| 872 | 872 | */ |
| 873 | 873 | function parseWord($s, &$p, &$w) {
|
| 874 | - $sLen = strlen($s); |
|
| 875 | - while ($p < $sLen && ord($s{$p}) <= 32) { |
|
| 876 | - $p++; |
|
| 877 | - } |
|
| 878 | - if ($p >= $sLen) { |
|
| 879 | - return false; |
|
| 880 | - } |
|
| 881 | - $p0 = $p; |
|
| 882 | - while ($p < $sLen && ord($s{$p}) > 32) { |
|
| 883 | - $p++; |
|
| 884 | - } |
|
| 885 | - $w = substr($s, $p0, $p - $p0); |
|
| 886 | - return true; } |
|
| 874 | + $sLen = strlen($s); |
|
| 875 | + while ($p < $sLen && ord($s{$p}) <= 32) { |
|
| 876 | + $p++; |
|
| 877 | + } |
|
| 878 | + if ($p >= $sLen) { |
|
| 879 | + return false; |
|
| 880 | + } |
|
| 881 | + $p0 = $p; |
|
| 882 | + while ($p < $sLen && ord($s{$p}) > 32) { |
|
| 883 | + $p++; |
|
| 884 | + } |
|
| 885 | + $w = substr($s, $p0, $p - $p0); |
|
| 886 | + return true; } |
|
| 887 | 887 | |
| 888 | 888 | /** |
| 889 | 889 | * @access private |
| 890 | 890 | * @return boolean true on success, false on error. |
| 891 | 891 | */ |
| 892 | 892 | function parseQuotedString($s, &$p, &$w) {
|
| 893 | - $sLen = strlen($s); |
|
| 894 | - while ($p < $sLen && ord($s{$p}) <= 32) $p++;
|
|
| 895 | - if ($p >= $sLen) return false; |
|
| 896 | - if (substr($s, $p, 1) != '"') return false; |
|
| 897 | - $p++; $p0 = $p; |
|
| 898 | - while ($p < $sLen && $s{$p} != '"') $p++;
|
|
| 899 | - if ($p >= $sLen) return false; |
|
| 900 | - $w = substr($s, $p0, $p - $p0); |
|
| 901 | - $p++; |
|
| 902 | - return true; } |
|
| 893 | + $sLen = strlen($s); |
|
| 894 | + while ($p < $sLen && ord($s{$p}) <= 32) $p++;
|
|
| 895 | + if ($p >= $sLen) return false; |
|
| 896 | + if (substr($s, $p, 1) != '"') return false; |
|
| 897 | + $p++; $p0 = $p; |
|
| 898 | + while ($p < $sLen && $s{$p} != '"') $p++;
|
|
| 899 | + if ($p >= $sLen) return false; |
|
| 900 | + $w = substr($s, $p0, $p - $p0); |
|
| 901 | + $p++; |
|
| 902 | + return true; } |
|
| 903 | 903 | |
| 904 | 904 | /** |
| 905 | 905 | * @access private |
| 906 | 906 | * @return boolean true on success, false on error. |
| 907 | 907 | */ |
| 908 | 908 | function parseWordOrQuotedString($s, &$p, &$w) {
|
| 909 | - $sLen = strlen($s); |
|
| 910 | - while ($p < $sLen && ord($s{$p}) <= 32) $p++;
|
|
| 911 | - if ($p >= $sLen) return false; |
|
| 912 | - if (substr($s, $p, 1) == '"') |
|
| 913 | - return $this->parseQuotedString($s, $p, $w); |
|
| 909 | + $sLen = strlen($s); |
|
| 910 | + while ($p < $sLen && ord($s{$p}) <= 32) $p++;
|
|
| 911 | + if ($p >= $sLen) return false; |
|
| 912 | + if (substr($s, $p, 1) == '"') |
|
| 913 | + return $this->parseQuotedString($s, $p, $w); |
|
| 914 | 914 | else |
| 915 | - return $this->parseWord($s, $p, $w); } |
|
| 915 | + return $this->parseWord($s, $p, $w); } |
|
| 916 | 916 | |
| 917 | 917 | /** |
| 918 | 918 | * Combine two file system paths. |
| 919 | 919 | * @access private |
| 920 | 920 | */ |
| 921 | 921 | function combineFileSystemPath($path1, $path2) {
|
| 922 | - if ($path1 == '' || $path2 == '') return $path2; |
|
| 923 | - $s = $path1; |
|
| 924 | - if (substr($s, -1) != '\\' && substr($s, -1) != '/') $s = $s."/"; |
|
| 925 | - if (substr($path2, 0, 1) == '\\' || substr($path2, 0, 1) == '/') |
|
| 926 | - $s = $s.substr($path2, 1); |
|
| 922 | + if ($path1 == '' || $path2 == '') return $path2; |
|
| 923 | + $s = $path1; |
|
| 924 | + if (substr($s, -1) != '\\' && substr($s, -1) != '/') $s = $s."/"; |
|
| 925 | + if (substr($path2, 0, 1) == '\\' || substr($path2, 0, 1) == '/') |
|
| 926 | + $s = $s.substr($path2, 1); |
|
| 927 | 927 | else |
| 928 | - $s = $s.$path2; |
|
| 929 | - return $s; } |
|
| 928 | + $s = $s.$path2; |
|
| 929 | + return $s; } |
|
| 930 | 930 | |
| 931 | 931 | /** |
| 932 | 932 | * @access private |
| 933 | 933 | */ |
| 934 | 934 | function triggerError($msg) {
|
| 935 | - trigger_error("MiniTemplator error: $msg", E_USER_ERROR); }
|
|
| 935 | + trigger_error("MiniTemplator error: $msg", E_USER_ERROR); }
|
|
| 936 | 936 | |
| 937 | 937 | /** |
| 938 | 938 | * @access private |
| 939 | 939 | */ |
| 940 | 940 | function programLogicError($errorId) {
|
| 941 | - die ("MiniTemplator: Program logic error $errorId.\n"); }
|
|
| 941 | + die ("MiniTemplator: Program logic error $errorId.\n"); }
|
|
| 942 | 942 | |
| 943 | 943 | } |
| 944 | 944 | ?> |
@@ -21,148 +21,148 @@ |
||
| 21 | 21 | */ |
| 22 | 22 | |
| 23 | 23 | |
| 24 | - // Simple class to wrap file streams, string streams, etc. |
|
| 25 | - // seek is essential, and it should be byte stream |
|
| 24 | + // Simple class to wrap file streams, string streams, etc. |
|
| 25 | + // seek is essential, and it should be byte stream |
|
| 26 | 26 | class StreamReader { |
| 27 | - // should return a string [FIXME: perhaps return array of bytes?] |
|
| 28 | - function read($bytes) { |
|
| 27 | + // should return a string [FIXME: perhaps return array of bytes?] |
|
| 28 | + function read($bytes) { |
|
| 29 | 29 | return false; |
| 30 | - } |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | - // should return new position |
|
| 33 | - function seekto($position) { |
|
| 32 | + // should return new position |
|
| 33 | + function seekto($position) { |
|
| 34 | 34 | return false; |
| 35 | - } |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - // returns current position |
|
| 38 | - function currentpos() { |
|
| 37 | + // returns current position |
|
| 38 | + function currentpos() { |
|
| 39 | 39 | return false; |
| 40 | - } |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - // returns length of entire stream (limit for seekto()s) |
|
| 43 | - function length() { |
|
| 42 | + // returns length of entire stream (limit for seekto()s) |
|
| 43 | + function length() { |
|
| 44 | 44 | return false; |
| 45 | - } |
|
| 45 | + } |
|
| 46 | 46 | }; |
| 47 | 47 | |
| 48 | 48 | class StringReader { |
| 49 | - var $_pos; |
|
| 50 | - var $_str; |
|
| 49 | + var $_pos; |
|
| 50 | + var $_str; |
|
| 51 | 51 | |
| 52 | - function StringReader($str = '') { |
|
| 52 | + function StringReader($str = '') { |
|
| 53 | 53 | $this->_str = $str; |
| 54 | 54 | $this->_pos = 0; |
| 55 | - } |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - function read($bytes) { |
|
| 57 | + function read($bytes) { |
|
| 58 | 58 | $data = substr($this->_str, $this->_pos, $bytes); |
| 59 | 59 | $this->_pos += $bytes; |
| 60 | 60 | if (strlen($this->_str) < $this->_pos) |
| 61 | - $this->_pos = strlen($this->_str); |
|
| 61 | + $this->_pos = strlen($this->_str); |
|
| 62 | 62 | |
| 63 | 63 | return $data; |
| 64 | - } |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - function seekto($pos) { |
|
| 66 | + function seekto($pos) { |
|
| 67 | 67 | $this->_pos = $pos; |
| 68 | 68 | if (strlen($this->_str) < $this->_pos) |
| 69 | - $this->_pos = strlen($this->_str); |
|
| 69 | + $this->_pos = strlen($this->_str); |
|
| 70 | 70 | return $this->_pos; |
| 71 | - } |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - function currentpos() { |
|
| 73 | + function currentpos() { |
|
| 74 | 74 | return $this->_pos; |
| 75 | - } |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | - function length() { |
|
| 77 | + function length() { |
|
| 78 | 78 | return strlen($this->_str); |
| 79 | - } |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | 81 | }; |
| 82 | 82 | |
| 83 | 83 | |
| 84 | 84 | class FileReader { |
| 85 | - var $_pos; |
|
| 86 | - var $_fd; |
|
| 87 | - var $_length; |
|
| 85 | + var $_pos; |
|
| 86 | + var $_fd; |
|
| 87 | + var $_length; |
|
| 88 | 88 | |
| 89 | - function FileReader($filename) { |
|
| 89 | + function FileReader($filename) { |
|
| 90 | 90 | if (file_exists($filename)) { |
| 91 | 91 | |
| 92 | - $this->_length = filesize($filename); |
|
| 93 | - $this->_pos = 0; |
|
| 94 | - $this->_fd = fopen($filename, 'rb'); |
|
| 95 | - if (!$this->_fd) { |
|
| 92 | + $this->_length = filesize($filename); |
|
| 93 | + $this->_pos = 0; |
|
| 94 | + $this->_fd = fopen($filename, 'rb'); |
|
| 95 | + if (!$this->_fd) { |
|
| 96 | 96 | $this->error = 3; // Cannot read file, probably permissions |
| 97 | 97 | return false; |
| 98 | - } |
|
| 98 | + } |
|
| 99 | 99 | } else { |
| 100 | - $this->error = 2; // File doesn't exist |
|
| 101 | - return false; |
|
| 100 | + $this->error = 2; // File doesn't exist |
|
| 101 | + return false; |
|
| 102 | + } |
|
| 102 | 103 | } |
| 103 | - } |
|
| 104 | 104 | |
| 105 | - function read($bytes) { |
|
| 105 | + function read($bytes) { |
|
| 106 | 106 | if ($bytes) { |
| 107 | - fseek($this->_fd, $this->_pos); |
|
| 107 | + fseek($this->_fd, $this->_pos); |
|
| 108 | 108 | |
| 109 | - // PHP 5.1.1 does not read more than 8192 bytes in one fread() |
|
| 110 | - // the discussions at PHP Bugs suggest it's the intended behaviour |
|
| 111 | - $data = ''; |
|
| 112 | - while ($bytes > 0) { |
|
| 109 | + // PHP 5.1.1 does not read more than 8192 bytes in one fread() |
|
| 110 | + // the discussions at PHP Bugs suggest it's the intended behaviour |
|
| 111 | + $data = ''; |
|
| 112 | + while ($bytes > 0) { |
|
| 113 | 113 | $chunk = fread($this->_fd, $bytes); |
| 114 | 114 | $data .= $chunk; |
| 115 | 115 | $bytes -= strlen($chunk); |
| 116 | - } |
|
| 117 | - $this->_pos = ftell($this->_fd); |
|
| 116 | + } |
|
| 117 | + $this->_pos = ftell($this->_fd); |
|
| 118 | 118 | |
| 119 | - return $data; |
|
| 119 | + return $data; |
|
| 120 | 120 | } else { |
| 121 | 121 | return ''; |
| 122 | 122 | } |
| 123 | - } |
|
| 123 | + } |
|
| 124 | 124 | |
| 125 | - function seekto($pos) { |
|
| 125 | + function seekto($pos) { |
|
| 126 | 126 | fseek($this->_fd, $pos); |
| 127 | 127 | $this->_pos = ftell($this->_fd); |
| 128 | 128 | return $this->_pos; |
| 129 | - } |
|
| 129 | + } |
|
| 130 | 130 | |
| 131 | - function currentpos() { |
|
| 131 | + function currentpos() { |
|
| 132 | 132 | return $this->_pos; |
| 133 | - } |
|
| 133 | + } |
|
| 134 | 134 | |
| 135 | - function length() { |
|
| 135 | + function length() { |
|
| 136 | 136 | return $this->_length; |
| 137 | - } |
|
| 137 | + } |
|
| 138 | 138 | |
| 139 | - function close() { |
|
| 139 | + function close() { |
|
| 140 | 140 | fclose($this->_fd); |
| 141 | - } |
|
| 141 | + } |
|
| 142 | 142 | |
| 143 | 143 | }; |
| 144 | 144 | |
| 145 | 145 | // Preloads entire file in memory first, then creates a StringReader |
| 146 | 146 | // over it (it assumes knowledge of StringReader internals) |
| 147 | 147 | class CachedFileReader extends StringReader { |
| 148 | - function CachedFileReader($filename) { |
|
| 148 | + function CachedFileReader($filename) { |
|
| 149 | 149 | if (file_exists($filename)) { |
| 150 | 150 | |
| 151 | - $length = filesize($filename); |
|
| 152 | - $fd = fopen($filename, 'rb'); |
|
| 151 | + $length = filesize($filename); |
|
| 152 | + $fd = fopen($filename, 'rb'); |
|
| 153 | 153 | |
| 154 | - if (!$fd) { |
|
| 154 | + if (!$fd) { |
|
| 155 | 155 | $this->error = 3; // Cannot read file, probably permissions |
| 156 | 156 | return false; |
| 157 | - } |
|
| 158 | - $this->_str = fread($fd, $length); |
|
| 159 | - fclose($fd); |
|
| 157 | + } |
|
| 158 | + $this->_str = fread($fd, $length); |
|
| 159 | + fclose($fd); |
|
| 160 | 160 | |
| 161 | 161 | } else { |
| 162 | - $this->error = 2; // File doesn't exist |
|
| 163 | - return false; |
|
| 162 | + $this->error = 2; // File doesn't exist |
|
| 163 | + return false; |
|
| 164 | + } |
|
| 164 | 165 | } |
| 165 | - } |
|
| 166 | 166 | }; |
| 167 | 167 | |
| 168 | 168 | |
@@ -34,75 +34,75 @@ discard block |
||
| 34 | 34 | * that you don't want to keep in memory) |
| 35 | 35 | */ |
| 36 | 36 | class gettext_reader { |
| 37 | - //public: |
|
| 38 | - var $error = 0; // public variable that holds error code (0 if no error) |
|
| 39 | - |
|
| 40 | - //private: |
|
| 41 | - var $BYTEORDER = 0; // 0: low endian, 1: big endian |
|
| 42 | - var $STREAM = null; |
|
| 43 | - var $short_circuit = false; |
|
| 44 | - var $enable_cache = false; |
|
| 45 | - var $originals = null; // offset of original table |
|
| 46 | - var $translations = null; // offset of translation table |
|
| 47 | - var $pluralheader = null; // cache header field for plural forms |
|
| 48 | - var $total = 0; // total string count |
|
| 49 | - var $table_originals = null; // table for original strings (offsets) |
|
| 50 | - var $table_translations = null; // table for translated strings (offsets) |
|
| 51 | - var $cache_translations = null; // original -> translation mapping |
|
| 52 | - |
|
| 53 | - |
|
| 54 | - /* Methods */ |
|
| 55 | - |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * Reads a 32bit Integer from the Stream |
|
| 59 | - * |
|
| 60 | - * @access private |
|
| 61 | - * @return Integer from the Stream |
|
| 62 | - */ |
|
| 63 | - function readint() { |
|
| 64 | - if ($this->BYTEORDER == 0) { |
|
| 37 | + //public: |
|
| 38 | + var $error = 0; // public variable that holds error code (0 if no error) |
|
| 39 | + |
|
| 40 | + //private: |
|
| 41 | + var $BYTEORDER = 0; // 0: low endian, 1: big endian |
|
| 42 | + var $STREAM = null; |
|
| 43 | + var $short_circuit = false; |
|
| 44 | + var $enable_cache = false; |
|
| 45 | + var $originals = null; // offset of original table |
|
| 46 | + var $translations = null; // offset of translation table |
|
| 47 | + var $pluralheader = null; // cache header field for plural forms |
|
| 48 | + var $total = 0; // total string count |
|
| 49 | + var $table_originals = null; // table for original strings (offsets) |
|
| 50 | + var $table_translations = null; // table for translated strings (offsets) |
|
| 51 | + var $cache_translations = null; // original -> translation mapping |
|
| 52 | + |
|
| 53 | + |
|
| 54 | + /* Methods */ |
|
| 55 | + |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * Reads a 32bit Integer from the Stream |
|
| 59 | + * |
|
| 60 | + * @access private |
|
| 61 | + * @return Integer from the Stream |
|
| 62 | + */ |
|
| 63 | + function readint() { |
|
| 64 | + if ($this->BYTEORDER == 0) { |
|
| 65 | 65 | // low endian |
| 66 | 66 | $input = unpack('V', $this->STREAM->read(4)); |
| 67 | 67 | return array_shift($input); |
| 68 | - } else { |
|
| 68 | + } else { |
|
| 69 | 69 | // big endian |
| 70 | 70 | $input = unpack('N', $this->STREAM->read(4)); |
| 71 | 71 | return array_shift($input); |
| 72 | - } |
|
| 72 | + } |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | - function read($bytes) { |
|
| 75 | + function read($bytes) { |
|
| 76 | 76 | return $this->STREAM->read($bytes); |
| 77 | - } |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * Reads an array of Integers from the Stream |
|
| 81 | - * |
|
| 82 | - * @param int count How many elements should be read |
|
| 83 | - * @return Array of Integers |
|
| 84 | - */ |
|
| 85 | - function readintarray($count) { |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * Reads an array of Integers from the Stream |
|
| 81 | + * |
|
| 82 | + * @param int count How many elements should be read |
|
| 83 | + * @return Array of Integers |
|
| 84 | + */ |
|
| 85 | + function readintarray($count) { |
|
| 86 | 86 | if ($this->BYTEORDER == 0) { |
| 87 | 87 | // low endian |
| 88 | 88 | return unpack('V'.$count, $this->STREAM->read(4 * $count)); |
| 89 | - } else { |
|
| 89 | + } else { |
|
| 90 | 90 | // big endian |
| 91 | 91 | return unpack('N'.$count, $this->STREAM->read(4 * $count)); |
| 92 | - } |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * Constructor |
|
| 97 | - * |
|
| 98 | - * @param object Reader the StreamReader object |
|
| 99 | - * @param boolean enable_cache Enable or disable caching of strings (default on) |
|
| 100 | - */ |
|
| 101 | - function __construct($Reader, $enable_cache = true) { |
|
| 92 | + } |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * Constructor |
|
| 97 | + * |
|
| 98 | + * @param object Reader the StreamReader object |
|
| 99 | + * @param boolean enable_cache Enable or disable caching of strings (default on) |
|
| 100 | + */ |
|
| 101 | + function __construct($Reader, $enable_cache = true) { |
|
| 102 | 102 | // If there isn't a StreamReader, turn on short circuit mode. |
| 103 | 103 | if (!$Reader || isset($Reader->error)) { |
| 104 | - $this->short_circuit = true; |
|
| 105 | - return; |
|
| 104 | + $this->short_circuit = true; |
|
| 105 | + return; |
|
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | // Caching can be turned off |
@@ -114,12 +114,12 @@ discard block |
||
| 114 | 114 | $this->STREAM = $Reader; |
| 115 | 115 | $magic = $this->read(4); |
| 116 | 116 | if ($magic == $MAGIC1) { |
| 117 | - $this->BYTEORDER = 1; |
|
| 117 | + $this->BYTEORDER = 1; |
|
| 118 | 118 | } elseif ($magic == $MAGIC2) { |
| 119 | - $this->BYTEORDER = 0; |
|
| 119 | + $this->BYTEORDER = 0; |
|
| 120 | 120 | } else { |
| 121 | - $this->error = 1; // not MO file |
|
| 122 | - return false; |
|
| 121 | + $this->error = 1; // not MO file |
|
| 122 | + return false; |
|
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | // FIXME: Do we care about revision? We should. |
@@ -128,162 +128,162 @@ discard block |
||
| 128 | 128 | $this->total = $this->readint(); |
| 129 | 129 | $this->originals = $this->readint(); |
| 130 | 130 | $this->translations = $this->readint(); |
| 131 | - } |
|
| 132 | - |
|
| 133 | - /** |
|
| 134 | - * Loads the translation tables from the MO file into the cache |
|
| 135 | - * If caching is enabled, also loads all strings into a cache |
|
| 136 | - * to speed up translation lookups |
|
| 137 | - * |
|
| 138 | - * @access private |
|
| 139 | - */ |
|
| 140 | - function load_tables() { |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + /** |
|
| 134 | + * Loads the translation tables from the MO file into the cache |
|
| 135 | + * If caching is enabled, also loads all strings into a cache |
|
| 136 | + * to speed up translation lookups |
|
| 137 | + * |
|
| 138 | + * @access private |
|
| 139 | + */ |
|
| 140 | + function load_tables() { |
|
| 141 | 141 | if (is_array($this->cache_translations) && |
| 142 | 142 | is_array($this->table_originals) && |
| 143 | 143 | is_array($this->table_translations)) { |
| 144 | - return; |
|
| 144 | + return; |
|
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | /* get original and translations tables */ |
| 148 | 148 | if (!is_array($this->table_originals)) { |
| 149 | - $this->STREAM->seekto($this->originals); |
|
| 150 | - $this->table_originals = $this->readintarray($this->total * 2); |
|
| 149 | + $this->STREAM->seekto($this->originals); |
|
| 150 | + $this->table_originals = $this->readintarray($this->total * 2); |
|
| 151 | 151 | } |
| 152 | 152 | if (!is_array($this->table_translations)) { |
| 153 | - $this->STREAM->seekto($this->translations); |
|
| 154 | - $this->table_translations = $this->readintarray($this->total * 2); |
|
| 153 | + $this->STREAM->seekto($this->translations); |
|
| 154 | + $this->table_translations = $this->readintarray($this->total * 2); |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | if ($this->enable_cache) { |
| 158 | - $this->cache_translations = array(); |
|
| 159 | - /* read all strings in the cache */ |
|
| 160 | - for ($i = 0; $i < $this->total; $i++) { |
|
| 158 | + $this->cache_translations = array(); |
|
| 159 | + /* read all strings in the cache */ |
|
| 160 | + for ($i = 0; $i < $this->total; $i++) { |
|
| 161 | 161 | $this->STREAM->seekto($this->table_originals[$i * 2 + 2]); |
| 162 | 162 | $original = $this->STREAM->read($this->table_originals[$i * 2 + 1]); |
| 163 | 163 | $this->STREAM->seekto($this->table_translations[$i * 2 + 2]); |
| 164 | 164 | $translation = $this->STREAM->read($this->table_translations[$i * 2 + 1]); |
| 165 | 165 | $this->cache_translations[$original] = $translation; |
| 166 | - } |
|
| 167 | - } |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - /** |
|
| 171 | - * Returns a string from the "originals" table |
|
| 172 | - * |
|
| 173 | - * @access private |
|
| 174 | - * @param int num Offset number of original string |
|
| 175 | - * @return string Requested string if found, otherwise '' |
|
| 176 | - */ |
|
| 177 | - function get_original_string($num) { |
|
| 166 | + } |
|
| 167 | + } |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + /** |
|
| 171 | + * Returns a string from the "originals" table |
|
| 172 | + * |
|
| 173 | + * @access private |
|
| 174 | + * @param int num Offset number of original string |
|
| 175 | + * @return string Requested string if found, otherwise '' |
|
| 176 | + */ |
|
| 177 | + function get_original_string($num) { |
|
| 178 | 178 | $length = $this->table_originals[$num * 2 + 1]; |
| 179 | 179 | $offset = $this->table_originals[$num * 2 + 2]; |
| 180 | 180 | if (! $length) { |
| 181 | - return ''; |
|
| 181 | + return ''; |
|
| 182 | 182 | } |
| 183 | 183 | $this->STREAM->seekto($offset); |
| 184 | 184 | $data = $this->STREAM->read($length); |
| 185 | 185 | return (string)$data; |
| 186 | - } |
|
| 187 | - |
|
| 188 | - /** |
|
| 189 | - * Returns a string from the "translations" table |
|
| 190 | - * |
|
| 191 | - * @access private |
|
| 192 | - * @param int num Offset number of original string |
|
| 193 | - * @return string Requested string if found, otherwise '' |
|
| 194 | - */ |
|
| 195 | - function get_translation_string($num) { |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + /** |
|
| 189 | + * Returns a string from the "translations" table |
|
| 190 | + * |
|
| 191 | + * @access private |
|
| 192 | + * @param int num Offset number of original string |
|
| 193 | + * @return string Requested string if found, otherwise '' |
|
| 194 | + */ |
|
| 195 | + function get_translation_string($num) { |
|
| 196 | 196 | $length = $this->table_translations[$num * 2 + 1]; |
| 197 | 197 | $offset = $this->table_translations[$num * 2 + 2]; |
| 198 | 198 | if (! $length) { |
| 199 | - return ''; |
|
| 199 | + return ''; |
|
| 200 | 200 | } |
| 201 | 201 | $this->STREAM->seekto($offset); |
| 202 | 202 | $data = $this->STREAM->read($length); |
| 203 | 203 | return (string)$data; |
| 204 | - } |
|
| 205 | - |
|
| 206 | - /** |
|
| 207 | - * Binary search for string |
|
| 208 | - * |
|
| 209 | - * @access private |
|
| 210 | - * @param string string |
|
| 211 | - * @param int start (internally used in recursive function) |
|
| 212 | - * @param int end (internally used in recursive function) |
|
| 213 | - * @return int string number (offset in originals table) |
|
| 214 | - */ |
|
| 215 | - function find_string($string, $start = -1, $end = -1) { |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + /** |
|
| 207 | + * Binary search for string |
|
| 208 | + * |
|
| 209 | + * @access private |
|
| 210 | + * @param string string |
|
| 211 | + * @param int start (internally used in recursive function) |
|
| 212 | + * @param int end (internally used in recursive function) |
|
| 213 | + * @return int string number (offset in originals table) |
|
| 214 | + */ |
|
| 215 | + function find_string($string, $start = -1, $end = -1) { |
|
| 216 | 216 | if (($start == -1) or ($end == -1)) { |
| 217 | - // find_string is called with only one parameter, set start end end |
|
| 218 | - $start = 0; |
|
| 219 | - $end = $this->total; |
|
| 217 | + // find_string is called with only one parameter, set start end end |
|
| 218 | + $start = 0; |
|
| 219 | + $end = $this->total; |
|
| 220 | 220 | } |
| 221 | 221 | if (abs($start - $end) <= 1) { |
| 222 | - // We're done, now we either found the string, or it doesn't exist |
|
| 223 | - $txt = $this->get_original_string($start); |
|
| 224 | - if ($string == $txt) { |
|
| 225 | - return $start; |
|
| 226 | - } else { |
|
| 227 | - return -1; |
|
| 228 | - } |
|
| 222 | + // We're done, now we either found the string, or it doesn't exist |
|
| 223 | + $txt = $this->get_original_string($start); |
|
| 224 | + if ($string == $txt) { |
|
| 225 | + return $start; |
|
| 226 | + } else { |
|
| 227 | + return -1; |
|
| 228 | + } |
|
| 229 | 229 | } else if ($start > $end) { |
| 230 | - // start > end -> turn around and start over |
|
| 231 | - return $this->find_string($string, $end, $start); |
|
| 230 | + // start > end -> turn around and start over |
|
| 231 | + return $this->find_string($string, $end, $start); |
|
| 232 | 232 | } else { |
| 233 | - // Divide table in two parts |
|
| 234 | - $half = (int) (($start + $end) / 2); |
|
| 235 | - $cmp = strcmp($string, $this->get_original_string($half)); |
|
| 236 | - if ($cmp == 0) { |
|
| 237 | - // string is exactly in the middle => return it |
|
| 233 | + // Divide table in two parts |
|
| 234 | + $half = (int) (($start + $end) / 2); |
|
| 235 | + $cmp = strcmp($string, $this->get_original_string($half)); |
|
| 236 | + if ($cmp == 0) { |
|
| 237 | + // string is exactly in the middle => return it |
|
| 238 | 238 | return $half; |
| 239 | - } else if ($cmp < 0) { |
|
| 240 | - // The string is in the upper half |
|
| 239 | + } else if ($cmp < 0) { |
|
| 240 | + // The string is in the upper half |
|
| 241 | 241 | return $this->find_string($string, $start, $half); |
| 242 | - } else { |
|
| 243 | - // The string is in the lower half |
|
| 242 | + } else { |
|
| 243 | + // The string is in the lower half |
|
| 244 | 244 | return $this->find_string($string, $half, $end); |
| 245 | - } |
|
| 246 | - } |
|
| 247 | - } |
|
| 248 | - |
|
| 249 | - /** |
|
| 250 | - * Translates a string |
|
| 251 | - * |
|
| 252 | - * @access public |
|
| 253 | - * @param string string to be translated |
|
| 254 | - * @return string translated string (or original, if not found) |
|
| 255 | - */ |
|
| 256 | - function translate($string) { |
|
| 245 | + } |
|
| 246 | + } |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + /** |
|
| 250 | + * Translates a string |
|
| 251 | + * |
|
| 252 | + * @access public |
|
| 253 | + * @param string string to be translated |
|
| 254 | + * @return string translated string (or original, if not found) |
|
| 255 | + */ |
|
| 256 | + function translate($string) { |
|
| 257 | 257 | if ($this->short_circuit) { |
| 258 | - return $string; |
|
| 258 | + return $string; |
|
| 259 | 259 | } |
| 260 | 260 | $this->load_tables(); |
| 261 | 261 | |
| 262 | 262 | if ($this->enable_cache) { |
| 263 | - // Caching enabled, get translated string from cache |
|
| 264 | - if (array_key_exists($string, $this->cache_translations)) { |
|
| 265 | - return $this->cache_translations[$string]; |
|
| 266 | - } else { |
|
| 267 | - return $string; |
|
| 268 | - } |
|
| 263 | + // Caching enabled, get translated string from cache |
|
| 264 | + if (array_key_exists($string, $this->cache_translations)) { |
|
| 265 | + return $this->cache_translations[$string]; |
|
| 266 | + } else { |
|
| 267 | + return $string; |
|
| 268 | + } |
|
| 269 | 269 | } else { |
| 270 | - // Caching not enabled, try to find string |
|
| 271 | - $num = $this->find_string($string); |
|
| 272 | - if ($num == -1) { |
|
| 273 | - return $string; |
|
| 274 | - } else { |
|
| 275 | - return $this->get_translation_string($num); |
|
| 276 | - } |
|
| 277 | - } |
|
| 278 | - } |
|
| 279 | - |
|
| 280 | - /** |
|
| 281 | - * Sanitize plural form expression for use in PHP eval call. |
|
| 282 | - * |
|
| 283 | - * @access private |
|
| 284 | - * @return string sanitized plural form expression |
|
| 285 | - */ |
|
| 286 | - function sanitize_plural_expression($expr) { |
|
| 270 | + // Caching not enabled, try to find string |
|
| 271 | + $num = $this->find_string($string); |
|
| 272 | + if ($num == -1) { |
|
| 273 | + return $string; |
|
| 274 | + } else { |
|
| 275 | + return $this->get_translation_string($num); |
|
| 276 | + } |
|
| 277 | + } |
|
| 278 | + } |
|
| 279 | + |
|
| 280 | + /** |
|
| 281 | + * Sanitize plural form expression for use in PHP eval call. |
|
| 282 | + * |
|
| 283 | + * @access private |
|
| 284 | + * @return string sanitized plural form expression |
|
| 285 | + */ |
|
| 286 | + function sanitize_plural_expression($expr) { |
|
| 287 | 287 | // Get rid of disallowed characters. |
| 288 | 288 | $expr = preg_replace('@[^a-zA-Z0-9_:;\(\)\?\|\&=!<>+*/\%-]@', '', $expr); |
| 289 | 289 | |
@@ -292,75 +292,75 @@ discard block |
||
| 292 | 292 | $res = ''; |
| 293 | 293 | $p = 0; |
| 294 | 294 | for ($i = 0; $i < strlen($expr); $i++) { |
| 295 | - $ch = $expr[$i]; |
|
| 296 | - switch ($ch) { |
|
| 297 | - case '?': |
|
| 295 | + $ch = $expr[$i]; |
|
| 296 | + switch ($ch) { |
|
| 297 | + case '?': |
|
| 298 | 298 | $res .= ' ? ('; |
| 299 | 299 | $p++; |
| 300 | 300 | break; |
| 301 | - case ':': |
|
| 301 | + case ':': |
|
| 302 | 302 | $res .= ') : ('; |
| 303 | 303 | break; |
| 304 | - case ';': |
|
| 304 | + case ';': |
|
| 305 | 305 | $res .= str_repeat(')', $p).';'; |
| 306 | 306 | $p = 0; |
| 307 | 307 | break; |
| 308 | - default: |
|
| 308 | + default: |
|
| 309 | 309 | $res .= $ch; |
| 310 | - } |
|
| 310 | + } |
|
| 311 | 311 | } |
| 312 | 312 | return $res; |
| 313 | - } |
|
| 314 | - |
|
| 315 | - /** |
|
| 316 | - * Parse full PO header and extract only plural forms line. |
|
| 317 | - * |
|
| 318 | - * @access private |
|
| 319 | - * @return string verbatim plural form header field |
|
| 320 | - */ |
|
| 321 | - function extract_plural_forms_header_from_po_header($header) { |
|
| 313 | + } |
|
| 314 | + |
|
| 315 | + /** |
|
| 316 | + * Parse full PO header and extract only plural forms line. |
|
| 317 | + * |
|
| 318 | + * @access private |
|
| 319 | + * @return string verbatim plural form header field |
|
| 320 | + */ |
|
| 321 | + function extract_plural_forms_header_from_po_header($header) { |
|
| 322 | 322 | if (preg_match("/(^|\n)plural-forms: ([^\n]*)\n/i", $header, $regs)) { |
| 323 | - $expr = $regs[2]; |
|
| 323 | + $expr = $regs[2]; |
|
| 324 | 324 | } else { |
| 325 | - $expr = "nplurals=2; plural=n == 1 ? 0 : 1;"; |
|
| 325 | + $expr = "nplurals=2; plural=n == 1 ? 0 : 1;"; |
|
| 326 | 326 | } |
| 327 | 327 | return $expr; |
| 328 | - } |
|
| 329 | - |
|
| 330 | - /** |
|
| 331 | - * Get possible plural forms from MO header |
|
| 332 | - * |
|
| 333 | - * @access private |
|
| 334 | - * @return string plural form header |
|
| 335 | - */ |
|
| 336 | - function get_plural_forms() { |
|
| 328 | + } |
|
| 329 | + |
|
| 330 | + /** |
|
| 331 | + * Get possible plural forms from MO header |
|
| 332 | + * |
|
| 333 | + * @access private |
|
| 334 | + * @return string plural form header |
|
| 335 | + */ |
|
| 336 | + function get_plural_forms() { |
|
| 337 | 337 | // lets assume message number 0 is header |
| 338 | 338 | // this is true, right? |
| 339 | 339 | $this->load_tables(); |
| 340 | 340 | |
| 341 | 341 | // cache header field for plural forms |
| 342 | 342 | if (!is_string($this->pluralheader)) { |
| 343 | - if ($this->enable_cache) { |
|
| 343 | + if ($this->enable_cache) { |
|
| 344 | 344 | $header = $this->cache_translations[""]; |
| 345 | - } else { |
|
| 345 | + } else { |
|
| 346 | 346 | $header = $this->get_translation_string(0); |
| 347 | - } |
|
| 348 | - $expr = $this->extract_plural_forms_header_from_po_header($header); |
|
| 349 | - $this->pluralheader = $this->sanitize_plural_expression($expr); |
|
| 347 | + } |
|
| 348 | + $expr = $this->extract_plural_forms_header_from_po_header($header); |
|
| 349 | + $this->pluralheader = $this->sanitize_plural_expression($expr); |
|
| 350 | 350 | } |
| 351 | 351 | return $this->pluralheader; |
| 352 | - } |
|
| 353 | - |
|
| 354 | - /** |
|
| 355 | - * Detects which plural form to take |
|
| 356 | - * |
|
| 357 | - * @access private |
|
| 358 | - * @param n count |
|
| 359 | - * @return int array index of the right plural form |
|
| 360 | - */ |
|
| 361 | - function select_string($n) { |
|
| 352 | + } |
|
| 353 | + |
|
| 354 | + /** |
|
| 355 | + * Detects which plural form to take |
|
| 356 | + * |
|
| 357 | + * @access private |
|
| 358 | + * @param n count |
|
| 359 | + * @return int array index of the right plural form |
|
| 360 | + */ |
|
| 361 | + function select_string($n) { |
|
| 362 | 362 | if (!is_int($n)) { |
| 363 | - throw new InvalidArgumentException( |
|
| 363 | + throw new InvalidArgumentException( |
|
| 364 | 364 | "Select_string only accepts integers: ".$n); |
| 365 | 365 | } |
| 366 | 366 | $string = $this->get_plural_forms(); |
@@ -376,24 +376,24 @@ discard block |
||
| 376 | 376 | $plural = $total - 1; |
| 377 | 377 | } |
| 378 | 378 | return $plural; |
| 379 | - } |
|
| 380 | - |
|
| 381 | - /** |
|
| 382 | - * Plural version of gettext |
|
| 383 | - * |
|
| 384 | - * @access public |
|
| 385 | - * @param string single |
|
| 386 | - * @param string plural |
|
| 387 | - * @param string number |
|
| 388 | - * @return translated plural form |
|
| 389 | - */ |
|
| 390 | - function ngettext($single, $plural, $number) { |
|
| 379 | + } |
|
| 380 | + |
|
| 381 | + /** |
|
| 382 | + * Plural version of gettext |
|
| 383 | + * |
|
| 384 | + * @access public |
|
| 385 | + * @param string single |
|
| 386 | + * @param string plural |
|
| 387 | + * @param string number |
|
| 388 | + * @return translated plural form |
|
| 389 | + */ |
|
| 390 | + function ngettext($single, $plural, $number) { |
|
| 391 | 391 | if ($this->short_circuit) { |
| 392 | - if ($number != 1) { |
|
| 393 | - return $plural; |
|
| 394 | - } else { |
|
| 395 | - return $single; |
|
| 396 | - } |
|
| 392 | + if ($number != 1) { |
|
| 393 | + return $plural; |
|
| 394 | + } else { |
|
| 395 | + return $single; |
|
| 396 | + } |
|
| 397 | 397 | } |
| 398 | 398 | |
| 399 | 399 | // find out the appropriate form |
@@ -404,45 +404,45 @@ discard block |
||
| 404 | 404 | |
| 405 | 405 | |
| 406 | 406 | if ($this->enable_cache) { |
| 407 | - if (!array_key_exists($key, $this->cache_translations)) { |
|
| 407 | + if (!array_key_exists($key, $this->cache_translations)) { |
|
| 408 | 408 | return ($number != 1) ? $plural : $single; |
| 409 | - } else { |
|
| 409 | + } else { |
|
| 410 | 410 | $result = $this->cache_translations[$key]; |
| 411 | 411 | $list = explode(chr(0), $result); |
| 412 | 412 | return $list[$select]; |
| 413 | - } |
|
| 413 | + } |
|
| 414 | 414 | } else { |
| 415 | - $num = $this->find_string($key); |
|
| 416 | - if ($num == -1) { |
|
| 415 | + $num = $this->find_string($key); |
|
| 416 | + if ($num == -1) { |
|
| 417 | 417 | return ($number != 1) ? $plural : $single; |
| 418 | - } else { |
|
| 418 | + } else { |
|
| 419 | 419 | $result = $this->get_translation_string($num); |
| 420 | 420 | $list = explode(chr(0), $result); |
| 421 | 421 | return $list[$select]; |
| 422 | - } |
|
| 422 | + } |
|
| 423 | + } |
|
| 423 | 424 | } |
| 424 | - } |
|
| 425 | 425 | |
| 426 | - function pgettext($context, $msgid) { |
|
| 426 | + function pgettext($context, $msgid) { |
|
| 427 | 427 | $key = $context.chr(4).$msgid; |
| 428 | 428 | $ret = $this->translate($key); |
| 429 | 429 | if (strpos($ret, "\004") !== false) { |
| 430 | - return $msgid; |
|
| 430 | + return $msgid; |
|
| 431 | 431 | } else { |
| 432 | - return $ret; |
|
| 432 | + return $ret; |
|
| 433 | + } |
|
| 433 | 434 | } |
| 434 | - } |
|
| 435 | 435 | |
| 436 | - function npgettext($context, $singular, $plural, $number) { |
|
| 436 | + function npgettext($context, $singular, $plural, $number) { |
|
| 437 | 437 | $key = $context.chr(4).$singular; |
| 438 | 438 | $ret = $this->ngettext($key, $plural, $number); |
| 439 | 439 | if (strpos($ret, "\004") !== false) { |
| 440 | - return $singular; |
|
| 440 | + return $singular; |
|
| 441 | 441 | } else { |
| 442 | - return $ret; |
|
| 442 | + return $ret; |
|
| 443 | 443 | } |
| 444 | 444 | |
| 445 | - } |
|
| 445 | + } |
|
| 446 | 446 | } |
| 447 | 447 | |
| 448 | 448 | ?> |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | // LC_MESSAGES is not available if php-gettext is not loaded |
| 36 | 36 | // while the other constants are already available from session extension. |
| 37 | 37 | if (!defined('LC_MESSAGES')) { |
| 38 | - define('LC_MESSAGES', 5); |
|
| 38 | + define('LC_MESSAGES', 5); |
|
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | require('streams.php'); |
@@ -53,9 +53,9 @@ discard block |
||
| 53 | 53 | |
| 54 | 54 | /* Class to hold a single domain included in $text_domains. */ |
| 55 | 55 | class domain { |
| 56 | - var $l10n; |
|
| 57 | - var $path; |
|
| 58 | - var $codeset; |
|
| 56 | + var $l10n; |
|
| 57 | + var $path; |
|
| 58 | + var $codeset; |
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | // Utility functions |
@@ -64,63 +64,63 @@ discard block |
||
| 64 | 64 | * Return a list of locales to try for any POSIX-style locale specification. |
| 65 | 65 | */ |
| 66 | 66 | function get_list_of_locales($locale) { |
| 67 | - /* Figure out all possible locale names and start with the most |
|
| 67 | + /* Figure out all possible locale names and start with the most |
|
| 68 | 68 | * specific ones. I.e. for sr_CS.UTF-8@latin, look through all of |
| 69 | 69 | * sr_CS.UTF-8@latin, sr_CS@latin, sr@latin, sr_CS.UTF-8, sr_CS, sr. |
| 70 | 70 | */ |
| 71 | - $locale_names = array(); |
|
| 72 | - $lang = null; |
|
| 73 | - $country = null; |
|
| 74 | - $charset = null; |
|
| 75 | - $modifier = null; |
|
| 76 | - if ($locale) { |
|
| 71 | + $locale_names = array(); |
|
| 72 | + $lang = null; |
|
| 73 | + $country = null; |
|
| 74 | + $charset = null; |
|
| 75 | + $modifier = null; |
|
| 76 | + if ($locale) { |
|
| 77 | 77 | if (preg_match("/^(?P<lang>[a-z]{2,3})" // language code |
| 78 | - ."(?:_(?P<country>[A-Z]{2}))?" // country code |
|
| 79 | - ."(?:\.(?P<charset>[-A-Za-z0-9_]+))?" // charset |
|
| 80 | - ."(?:@(?P<modifier>[-A-Za-z0-9_]+))?$/", // @ modifier |
|
| 81 | - $locale, $matches)) { |
|
| 82 | - |
|
| 83 | - if (isset($matches["lang"])) { |
|
| 84 | - $lang = $matches["lang"]; |
|
| 85 | - } |
|
| 86 | - if (isset($matches["country"])) { |
|
| 87 | - $country = $matches["country"]; |
|
| 88 | - } |
|
| 89 | - if (isset($matches["charset"])) { |
|
| 90 | - $charset = $matches["charset"]; |
|
| 91 | - } |
|
| 92 | - if (isset($matches["modifier"])) { |
|
| 93 | - $modifier = $matches["modifier"]; |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - if ($modifier) { |
|
| 78 | + ."(?:_(?P<country>[A-Z]{2}))?" // country code |
|
| 79 | + ."(?:\.(?P<charset>[-A-Za-z0-9_]+))?" // charset |
|
| 80 | + ."(?:@(?P<modifier>[-A-Za-z0-9_]+))?$/", // @ modifier |
|
| 81 | + $locale, $matches)) { |
|
| 82 | + |
|
| 83 | + if (isset($matches["lang"])) { |
|
| 84 | + $lang = $matches["lang"]; |
|
| 85 | + } |
|
| 86 | + if (isset($matches["country"])) { |
|
| 87 | + $country = $matches["country"]; |
|
| 88 | + } |
|
| 89 | + if (isset($matches["charset"])) { |
|
| 90 | + $charset = $matches["charset"]; |
|
| 91 | + } |
|
| 92 | + if (isset($matches["modifier"])) { |
|
| 93 | + $modifier = $matches["modifier"]; |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + if ($modifier) { |
|
| 97 | 97 | if ($country) { |
| 98 | - if ($charset) { |
|
| 99 | - array_push($locale_names, "${lang}_$country.$charset@$modifier"); |
|
| 100 | - } |
|
| 101 | - array_push($locale_names, "${lang}_$country@$modifier"); |
|
| 98 | + if ($charset) { |
|
| 99 | + array_push($locale_names, "${lang}_$country.$charset@$modifier"); |
|
| 100 | + } |
|
| 101 | + array_push($locale_names, "${lang}_$country@$modifier"); |
|
| 102 | 102 | } elseif ($charset) { |
| 103 | 103 | array_push($locale_names, "${lang}.$charset@$modifier"); |
| 104 | 104 | } |
| 105 | 105 | array_push($locale_names, "$lang@$modifier"); |
| 106 | - } |
|
| 107 | - if ($country) { |
|
| 106 | + } |
|
| 107 | + if ($country) { |
|
| 108 | 108 | if ($charset) { |
| 109 | - array_push($locale_names, "${lang}_$country.$charset"); |
|
| 109 | + array_push($locale_names, "${lang}_$country.$charset"); |
|
| 110 | 110 | } |
| 111 | 111 | array_push($locale_names, "${lang}_$country"); |
| 112 | - } elseif ($charset) { |
|
| 112 | + } elseif ($charset) { |
|
| 113 | 113 | array_push($locale_names, "${lang}.$charset"); |
| 114 | - } |
|
| 115 | - array_push($locale_names, $lang); |
|
| 114 | + } |
|
| 115 | + array_push($locale_names, $lang); |
|
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | // If the locale name doesn't match POSIX style, just include it as-is. |
| 119 | 119 | if (!in_array($locale, $locale_names)) { |
| 120 | - array_push($locale_names, $locale); |
|
| 120 | + array_push($locale_names, $locale); |
|
| 121 | 121 | } |
| 122 | - } |
|
| 123 | - return $locale_names; |
|
| 122 | + } |
|
| 123 | + return $locale_names; |
|
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | /** |
@@ -141,19 +141,19 @@ discard block |
||
| 141 | 141 | $locale_names = get_list_of_locales($locale); |
| 142 | 142 | $input = null; |
| 143 | 143 | foreach ($locale_names as $locale) { |
| 144 | - $full_path = $bound_path.$locale."/".$subpath; |
|
| 145 | - if (file_exists($full_path)) { |
|
| 144 | + $full_path = $bound_path.$locale."/".$subpath; |
|
| 145 | + if (file_exists($full_path)) { |
|
| 146 | 146 | $input = new FileReader($full_path); |
| 147 | 147 | break; |
| 148 | - } |
|
| 148 | + } |
|
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | if (!array_key_exists($domain, $text_domains)) { |
| 152 | - // Initialize an empty domain object. |
|
| 153 | - $text_domains[$domain] = new domain(); |
|
| 152 | + // Initialize an empty domain object. |
|
| 153 | + $text_domains[$domain] = new domain(); |
|
| 154 | 154 | } |
| 155 | 155 | $text_domains[$domain]->l10n = new gettext_reader($input, |
| 156 | - $enable_cache); |
|
| 156 | + $enable_cache); |
|
| 157 | 157 | } |
| 158 | 158 | return $text_domains[$domain]->l10n; |
| 159 | 159 | } |
@@ -190,14 +190,14 @@ discard block |
||
| 190 | 190 | * Convert the given string to the encoding set by bind_textdomain_codeset. |
| 191 | 191 | */ |
| 192 | 192 | function _encode($text) { |
| 193 | - $target_encoding = _get_codeset(); |
|
| 194 | - if (function_exists("mb_detect_encoding")) { |
|
| 193 | + $target_encoding = _get_codeset(); |
|
| 194 | + if (function_exists("mb_detect_encoding")) { |
|
| 195 | 195 | $source_encoding = mb_detect_encoding($text); |
| 196 | 196 | if ($source_encoding != $target_encoding) { |
| 197 | - $text = mb_convert_encoding($text, $target_encoding, $source_encoding); |
|
| 197 | + $text = mb_convert_encoding($text, $target_encoding, $source_encoding); |
|
| 198 | + } |
|
| 198 | 199 | } |
| 199 | - } |
|
| 200 | - return $text; |
|
| 200 | + return $text; |
|
| 201 | 201 | } |
| 202 | 202 | |
| 203 | 203 | |
@@ -207,13 +207,13 @@ discard block |
||
| 207 | 207 | * Returns passed in $locale, or environment variable $LANG if $locale == ''. |
| 208 | 208 | */ |
| 209 | 209 | function _get_default_locale($locale) { |
| 210 | - if ($locale == '') { |
|
| 211 | - // emulate variable support |
|
| 210 | + if ($locale == '') { |
|
| 211 | + // emulate variable support |
|
| 212 | 212 | return getenv('LANG'); |
| 213 | - } else { |
|
| 214 | - return $locale; |
|
| 215 | - } |
|
| 216 | - } |
|
| 213 | + } else { |
|
| 214 | + return $locale; |
|
| 215 | + } |
|
| 216 | + } |
|
| 217 | 217 | |
| 218 | 218 | /** |
| 219 | 219 | * Sets a requested locale, if needed emulates it. |
@@ -230,20 +230,20 @@ discard block |
||
| 230 | 230 | } |
| 231 | 231 | } else { |
| 232 | 232 | if (function_exists('setlocale')) { |
| 233 | - $ret = setlocale($category, $locale); |
|
| 234 | - if (($locale == '' and !$ret) or // failed setting it by env |
|
| 233 | + $ret = setlocale($category, $locale); |
|
| 234 | + if (($locale == '' and !$ret) or // failed setting it by env |
|
| 235 | 235 | ($locale != '' and $ret != $locale)) { // failed setting it |
| 236 | 236 | // Failed setting it according to environment. |
| 237 | 237 | $CURRENTLOCALE = _get_default_locale($locale); |
| 238 | 238 | $EMULATEGETTEXT = 1; |
| 239 | - } else { |
|
| 239 | + } else { |
|
| 240 | 240 | $CURRENTLOCALE = $ret; |
| 241 | 241 | $EMULATEGETTEXT = 0; |
| 242 | - } |
|
| 242 | + } |
|
| 243 | 243 | } else { |
| 244 | - // No function setlocale(), emulate it all. |
|
| 245 | - $CURRENTLOCALE = _get_default_locale($locale); |
|
| 246 | - $EMULATEGETTEXT = 1; |
|
| 244 | + // No function setlocale(), emulate it all. |
|
| 245 | + $CURRENTLOCALE = _get_default_locale($locale); |
|
| 246 | + $EMULATEGETTEXT = 1; |
|
| 247 | 247 | } |
| 248 | 248 | // Allow locale to be changed on the go for one translation domain. |
| 249 | 249 | global $text_domains, $default_domain; |
@@ -261,15 +261,15 @@ discard block |
||
| 261 | 261 | global $text_domains; |
| 262 | 262 | // ensure $path ends with a slash ('/' should work for both, but lets still play nice) |
| 263 | 263 | if (substr(php_uname(), 0, 7) == "Windows") { |
| 264 | - if ($path[strlen($path) - 1] != '\\' and $path[strlen($path) - 1] != '/') |
|
| 264 | + if ($path[strlen($path) - 1] != '\\' and $path[strlen($path) - 1] != '/') |
|
| 265 | 265 | $path .= '\\'; |
| 266 | 266 | } else { |
| 267 | - if ($path[strlen($path) - 1] != '/') |
|
| 267 | + if ($path[strlen($path) - 1] != '/') |
|
| 268 | 268 | $path .= '/'; |
| 269 | 269 | } |
| 270 | 270 | if (!array_key_exists($domain, $text_domains)) { |
| 271 | - // Initialize an empty domain object. |
|
| 272 | - $text_domains[$domain] = new domain(); |
|
| 271 | + // Initialize an empty domain object. |
|
| 272 | + $text_domains[$domain] = new domain(); |
|
| 273 | 273 | } |
| 274 | 274 | $text_domains[$domain]->path = $path; |
| 275 | 275 | } |
@@ -468,35 +468,35 @@ discard block |
||
| 468 | 468 | } |
| 469 | 469 | function T_dcngettext($domain, $singular, $plural, $number, $category) { |
| 470 | 470 | if (_check_locale_and_function()) { |
| 471 | - return dcngettext($domain, $singular, $plural, $number, $category); |
|
| 471 | + return dcngettext($domain, $singular, $plural, $number, $category); |
|
| 472 | 472 | } else { |
| 473 | 473 | return _dcngettext($domain, $singular, $plural, $number, $category); |
| 474 | 474 | } |
| 475 | 475 | } |
| 476 | 476 | |
| 477 | 477 | function T_pgettext($context, $msgid) { |
| 478 | - if (_check_locale_and_function('pgettext')) { |
|
| 478 | + if (_check_locale_and_function('pgettext')) { |
|
| 479 | 479 | return pgettext($context, $msgid); |
| 480 | - } else { |
|
| 480 | + } else { |
|
| 481 | 481 | return _pgettext($context, $msgid); |
| 482 | - } |
|
| 483 | - } |
|
| 482 | + } |
|
| 483 | + } |
|
| 484 | 484 | |
| 485 | 485 | function T_dpgettext($domain, $context, $msgid) { |
| 486 | - if (_check_locale_and_function('dpgettext')) { |
|
| 486 | + if (_check_locale_and_function('dpgettext')) { |
|
| 487 | 487 | return dpgettext($domain, $context, $msgid); |
| 488 | - } else { |
|
| 488 | + } else { |
|
| 489 | 489 | return _dpgettext($domain, $context, $msgid); |
| 490 | - } |
|
| 491 | - } |
|
| 490 | + } |
|
| 491 | + } |
|
| 492 | 492 | |
| 493 | 493 | function T_dcpgettext($domain, $context, $msgid, $category) { |
| 494 | - if (_check_locale_and_function('dcpgettext')) { |
|
| 494 | + if (_check_locale_and_function('dcpgettext')) { |
|
| 495 | 495 | return dcpgettext($domain, $context, $msgid, $category); |
| 496 | - } else { |
|
| 496 | + } else { |
|
| 497 | 497 | return _dcpgettext($domain, $context, $msgid, $category); |
| 498 | - } |
|
| 499 | - } |
|
| 498 | + } |
|
| 499 | + } |
|
| 500 | 500 | |
| 501 | 501 | function T_npgettext($context, $singular, $plural, $number) { |
| 502 | 502 | if (_check_locale_and_function('npgettext')) { |
@@ -507,18 +507,18 @@ discard block |
||
| 507 | 507 | } |
| 508 | 508 | |
| 509 | 509 | function T_dnpgettext($domain, $context, $singular, $plural, $number) { |
| 510 | - if (_check_locale_and_function('dnpgettext')) { |
|
| 510 | + if (_check_locale_and_function('dnpgettext')) { |
|
| 511 | 511 | return dnpgettext($domain, $context, $singular, $plural, $number); |
| 512 | - } else { |
|
| 512 | + } else { |
|
| 513 | 513 | return _dnpgettext($domain, $context, $singular, $plural, $number); |
| 514 | - } |
|
| 515 | - } |
|
| 514 | + } |
|
| 515 | + } |
|
| 516 | 516 | |
| 517 | 517 | function T_dcnpgettext($domain, $context, $singular, $plural, |
| 518 | - $number, $category) { |
|
| 518 | + $number, $category) { |
|
| 519 | 519 | if (_check_locale_and_function('dcnpgettext')) { |
| 520 | 520 | return dcnpgettext($domain, $context, $singular, |
| 521 | - $plural, $number, $category); |
|
| 521 | + $plural, $number, $category); |
|
| 522 | 522 | } else { |
| 523 | 523 | return _dcnpgettext($domain, $context, $singular, |
| 524 | 524 | $plural, $number, $category); |
@@ -576,9 +576,9 @@ discard block |
||
| 576 | 576 | return _dcpgettext($domain, $context, $msgid, $category); |
| 577 | 577 | } |
| 578 | 578 | function dcnpgettext($domain, $context, $singular, $plural, |
| 579 | - $number, $category) { |
|
| 580 | - return _dcnpgettext($domain, $context, $singular, $plural, |
|
| 581 | - $number, $category); |
|
| 579 | + $number, $category) { |
|
| 580 | + return _dcnpgettext($domain, $context, $singular, $plural, |
|
| 581 | + $number, $category); |
|
| 582 | 582 | } |
| 583 | 583 | } |
| 584 | 584 | |
@@ -79,9 +79,9 @@ discard block |
||
| 79 | 79 | //---------------------------------------------------------------------- |
| 80 | 80 | public static function buildCache() |
| 81 | 81 | {
|
| 82 | - QRtools::markTime('before_build_cache');
|
|
| 82 | + QRtools::markTime('before_build_cache');
|
|
| 83 | 83 | |
| 84 | - $mask = new QRmask(); |
|
| 84 | + $mask = new QRmask(); |
|
| 85 | 85 | for ($a = 1; $a <= QRSPEC_VERSION_MAX; $a++) {
|
| 86 | 86 | $frame = QRspec::newFrame($a); |
| 87 | 87 | if (QR_IMAGE) {
|
@@ -89,13 +89,13 @@ discard block |
||
| 89 | 89 | QRimage::png(self::binarize($frame), $fileName, 1, 0); |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | - $width = count($frame); |
|
| 93 | - $bitMask = array_fill(0, $width, array_fill(0, $width, 0)); |
|
| 94 | - for ($maskNo = 0; $maskNo < 8; $maskNo++) |
|
| 95 | - $mask->makeMaskNo($maskNo, $width, $frame, $bitMask, true); |
|
| 92 | + $width = count($frame); |
|
| 93 | + $bitMask = array_fill(0, $width, array_fill(0, $width, 0)); |
|
| 94 | + for ($maskNo = 0; $maskNo < 8; $maskNo++) |
|
| 95 | + $mask->makeMaskNo($maskNo, $width, $frame, $bitMask, true); |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | - QRtools::markTime('after_build_cache');
|
|
| 98 | + QRtools::markTime('after_build_cache');
|
|
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | //---------------------------------------------------------------------- |
@@ -26,29 +26,29 @@ |
||
| 26 | 26 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 27 | 27 | */ |
| 28 | 28 | |
| 29 | - // Encoding modes |
|
| 29 | + // Encoding modes |
|
| 30 | 30 | |
| 31 | - define('QR_MODE_NUL', -1);
|
|
| 32 | - define('QR_MODE_NUM', 0);
|
|
| 33 | - define('QR_MODE_AN', 1);
|
|
| 34 | - define('QR_MODE_8', 2);
|
|
| 35 | - define('QR_MODE_KANJI', 3);
|
|
| 36 | - define('QR_MODE_STRUCTURE', 4);
|
|
| 31 | + define('QR_MODE_NUL', -1);
|
|
| 32 | + define('QR_MODE_NUM', 0);
|
|
| 33 | + define('QR_MODE_AN', 1);
|
|
| 34 | + define('QR_MODE_8', 2);
|
|
| 35 | + define('QR_MODE_KANJI', 3);
|
|
| 36 | + define('QR_MODE_STRUCTURE', 4);
|
|
| 37 | 37 | |
| 38 | - // Levels of error correction. |
|
| 38 | + // Levels of error correction. |
|
| 39 | 39 | |
| 40 | - define('QR_ECLEVEL_L', 0);
|
|
| 41 | - define('QR_ECLEVEL_M', 1);
|
|
| 42 | - define('QR_ECLEVEL_Q', 2);
|
|
| 43 | - define('QR_ECLEVEL_H', 3);
|
|
| 40 | + define('QR_ECLEVEL_L', 0);
|
|
| 41 | + define('QR_ECLEVEL_M', 1);
|
|
| 42 | + define('QR_ECLEVEL_Q', 2);
|
|
| 43 | + define('QR_ECLEVEL_H', 3);
|
|
| 44 | 44 | |
| 45 | - // Supported output formats |
|
| 45 | + // Supported output formats |
|
| 46 | 46 | |
| 47 | - define('QR_FORMAT_TEXT', 0);
|
|
| 48 | - define('QR_FORMAT_PNG', 1);
|
|
| 47 | + define('QR_FORMAT_TEXT', 0);
|
|
| 48 | + define('QR_FORMAT_PNG', 1);
|
|
| 49 | 49 | |
| 50 | - class qrstr {
|
|
| 51 | - public static function set(&$srctab, $x, $y, $repl, $replLen = false) {
|
|
| 52 | - $srctab[$y] = substr_replace($srctab[$y], ($replLen !== false) ?substr($repl, 0, $replLen) : $repl, $x, ($replLen !== false) ? $replLen : strlen($repl)); |
|
| 53 | - } |
|
| 54 | - } |
|
| 55 | 50 | \ No newline at end of file |
| 51 | + class qrstr {
|
|
| 52 | + public static function set(&$srctab, $x, $y, $repl, $replLen = false) {
|
|
| 53 | + $srctab[$y] = substr_replace($srctab[$y], ($replLen !== false) ?substr($repl, 0, $replLen) : $repl, $x, ($replLen !== false) ? $replLen : strlen($repl)); |
|
| 54 | + } |
|
| 55 | + } |
|
| 56 | 56 | \ No newline at end of file |
@@ -14,4 +14,4 @@ |
||
| 14 | 14 | define('QR_DEFAULT_MASK', 2); // when QR_FIND_BEST_MASK === false
|
| 15 | 15 | |
| 16 | 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 | 17 | \ No newline at end of file |
| 18 | + |
|
| 19 | 19 | \ No newline at end of file |