| @@ -52,14 +52,14 @@ | ||
| 52 | 52 | |
| 53 | 53 | $macroname = strtr($this->expression, '-', '_'); | 
| 54 | 54 | |
| 55 | - // throw error if attempting to define and use macro at same time | |
| 56 | - // [should perhaps be a TemplateException? but I don't know how to set that up...] | |
| 57 | - if ($defineAttr = $this->phpelement->getAttributeNodeNS( | |
| 58 | -		'http://xml.zope.org/namespaces/metal', 'define-macro')) { | |
| 59 | - if ($defineAttr->getValue() == $macroname) | |
| 60 | -            		throw new PHPTAL_TemplateException("Cannot simultaneously define and use macro '$macroname'", | |
| 61 | - $this->phpelement->getSourceFile(), $this->phpelement->getSourceLine()); | |
| 62 | - } | |
| 55 | + // throw error if attempting to define and use macro at same time | |
| 56 | + // [should perhaps be a TemplateException? but I don't know how to set that up...] | |
| 57 | + if ($defineAttr = $this->phpelement->getAttributeNodeNS( | |
| 58 | +        'http://xml.zope.org/namespaces/metal', 'define-macro')) { | |
| 59 | + if ($defineAttr->getValue() == $macroname) | |
| 60 | +                    throw new PHPTAL_TemplateException("Cannot simultaneously define and use macro '$macroname'", | |
| 61 | + $this->phpelement->getSourceFile(), $this->phpelement->getSourceLine()); | |
| 62 | + } | |
| 63 | 63 | |
| 64 | 64 | // local macro (no filename specified) and non dynamic macro name | 
| 65 | 65 | // can be called directly if it's a known function (just generated or seen in previous compilation) | 
| @@ -67,12 +67,12 @@ | ||
| 67 | 67 |          } elseif ($cache_per_expression == 'nothing') { | 
| 68 | 68 | /* do nothing */ | 
| 69 | 69 |          } elseif ($cache_per_expression) { | 
| 70 | - $code = $codewriter->evaluateExpression($cache_per_expression); | |
| 70 | + $code = $codewriter->evaluateExpression($cache_per_expression); | |
| 71 | 71 | |
| 72 | -             if (is_array($code)) throw new PHPTAL_ParserException("Chained expressions in per-cache directive are not supported", | |
| 72 | +                if (is_array($code)) throw new PHPTAL_ParserException("Chained expressions in per-cache directive are not supported", | |
| 73 | 73 | $this->phpelement->getSourceFile(), $this->phpelement->getSourceLine()); | 
| 74 | 74 | |
| 75 | -             $cache_tag = '('.$code.')."@".' . $cache_tag; | |
| 75 | +                $cache_tag = '('.$code.')."@".' . $cache_tag; | |
| 76 | 76 | } | 
| 77 | 77 | |
| 78 | 78 | $this->cache_filename_var = $codewriter->createTempVariable(); | 
| @@ -466,10 +466,10 @@ | ||
| 466 | 466 | $nsattr = PHPTAL_Dom_Defs::getInstance()->getNamespaceAttribute($domattr->getNamespaceURI(), $domattr->getLocalName()); | 
| 467 | 467 |              if (array_key_exists($nsattr->getPriority(), $temp)) { | 
| 468 | 468 |                  throw new PHPTAL_TemplateException(sprintf("Attribute conflict in < %s > '%s' cannot appear with '%s'", | 
| 469 | - $this->qualifiedName, | |
| 470 | - $key, | |
| 471 | - $temp[$nsattr->getPriority()][0]->getNamespace()->getPrefix() . ':' . $temp[$nsattr->getPriority()][0]->getLocalName() | |
| 472 | - ), $this->getSourceFile(), $this->getSourceLine()); | |
| 469 | + $this->qualifiedName, | |
| 470 | + $key, | |
| 471 | + $temp[$nsattr->getPriority()][0]->getNamespace()->getPrefix() . ':' . $temp[$nsattr->getPriority()][0]->getLocalName() | |
| 472 | + ), $this->getSourceFile(), $this->getSourceLine()); | |
| 473 | 473 | } | 
| 474 | 474 | $temp[$nsattr->getPriority()] = array($nsattr, $domattr); | 
| 475 | 475 | } | 
| @@ -153,7 +153,7 @@ discard block | ||
| 153 | 153 | public function interpolateTalesVarsInHTML($src) | 
| 154 | 154 |      { | 
| 155 | 155 |          return preg_replace_callback('/((?:\$\$)*)\$\{(structure |text )?(.*?)\}|((?:\$\$)+)\{/isS', | 
| 156 | - array($this,'_interpolateTalesVarsInHTMLCallback'), $src); | |
| 156 | + array($this,'_interpolateTalesVarsInHTMLCallback'), $src); | |
| 157 | 157 | } | 
| 158 | 158 | |
| 159 | 159 | /** | 
| @@ -172,7 +172,7 @@ discard block | ||
| 172 | 172 | public function interpolateTalesVarsInCDATA($src) | 
| 173 | 173 |      { | 
| 174 | 174 |          return preg_replace_callback('/((?:\$\$)*)\$\{(structure |text )?(.*?)\}|((?:\$\$)+)\{/isS', | 
| 175 | - array($this,'_interpolateTalesVarsInCDATACallback'), $src); | |
| 175 | + array($this,'_interpolateTalesVarsInCDATACallback'), $src); | |
| 176 | 176 | } | 
| 177 | 177 | |
| 178 | 178 | /** | 
| @@ -172,8 +172,8 @@ discard block | ||
| 172 | 172 | } | 
| 173 | 173 | |
| 174 | 174 | if ($element->getNamespaceURI() !== 'http://www.w3.org/1999/xhtml' | 
| 175 | -	        && $element->getNamespaceURI() !== '') { | |
| 176 | - return false; | |
| 175 | +            && $element->getNamespaceURI() !== '') { | |
| 176 | + return false; | |
| 177 | 177 | } | 
| 178 | 178 | |
| 179 | 179 | return in_array($element->getLocalName(), self::$breaks_line); | 
| @@ -189,8 +189,8 @@ discard block | ||
| 189 | 189 | private function isInlineBlock(PHPTAL_Dom_Element $element) | 
| 190 | 190 |      { | 
| 191 | 191 | if ($element->getNamespaceURI() !== 'http://www.w3.org/1999/xhtml' | 
| 192 | -	        && $element->getNamespaceURI() !== '') { | |
| 193 | - return false; | |
| 192 | +            && $element->getNamespaceURI() !== '') { | |
| 193 | + return false; | |
| 194 | 194 | } | 
| 195 | 195 | |
| 196 | 196 | return in_array($element->getLocalName(), self::$inline_blocks); | 
| @@ -209,45 +209,45 @@ discard block | ||
| 209 | 209 | $attrs_by_qname[$attrnode->getQualifiedName()] = $attrnode; | 
| 210 | 210 | } | 
| 211 | 211 | |
| 212 | -	if (count($attrs_by_qname) > 1) { | |
| 213 | - uksort($attrs_by_qname, array($this, 'compareQNames')); | |
| 214 | - $element->setAttributeNodes(array_values($attrs_by_qname)); | |
| 215 | - } | |
| 212 | +    if (count($attrs_by_qname) > 1) { | |
| 213 | + uksort($attrs_by_qname, array($this, 'compareQNames')); | |
| 214 | + $element->setAttributeNodes(array_values($attrs_by_qname)); | |
| 215 | + } | |
| 216 | 216 | } | 
| 217 | 217 | |
| 218 | 218 | /** | 
| 219 | - * pre-defined order of attributes roughly by popularity | |
| 220 | - */ | |
| 221 | - private static $attributes_order = array( | |
| 219 | + * pre-defined order of attributes roughly by popularity | |
| 220 | + */ | |
| 221 | + private static $attributes_order = array( | |
| 222 | 222 | 'href','src','class','rel','type','title','width','height','alt','content','name','style','lang','id', | 
| 223 | 223 | ); | 
| 224 | 224 | |
| 225 | - /** | |
| 226 | - * compare names according to $attributes_order array. | |
| 227 | - * Elements that are not in array, are considered greater than all elements in array, | |
| 228 | - * and are sorted alphabetically. | |
| 229 | - */ | |
| 230 | -	private static function compareQNames($a, $b) { | |
| 231 | - $a_index = array_search($a, self::$attributes_order); | |
| 232 | - $b_index = array_search($b, self::$attributes_order); | |
| 233 | - | |
| 234 | -		if ($a_index !== false && $b_index !== false) { | |
| 235 | - return $a_index - $b_index; | |
| 236 | - } | |
| 237 | -		if ($a_index === false && $b_index === false) { | |
| 238 | - return strcmp($a, $b); | |
| 239 | - } | |
| 240 | - return ($a_index === false) ? 1 : -1; | |
| 241 | - } | |
| 225 | + /** | |
| 226 | + * compare names according to $attributes_order array. | |
| 227 | + * Elements that are not in array, are considered greater than all elements in array, | |
| 228 | + * and are sorted alphabetically. | |
| 229 | + */ | |
| 230 | +    private static function compareQNames($a, $b) { | |
| 231 | + $a_index = array_search($a, self::$attributes_order); | |
| 232 | + $b_index = array_search($b, self::$attributes_order); | |
| 233 | + | |
| 234 | +        if ($a_index !== false && $b_index !== false) { | |
| 235 | + return $a_index - $b_index; | |
| 236 | + } | |
| 237 | +        if ($a_index === false && $b_index === false) { | |
| 238 | + return strcmp($a, $b); | |
| 239 | + } | |
| 240 | + return ($a_index === false) ? 1 : -1; | |
| 241 | + } | |
| 242 | 242 | |
| 243 | 243 | /** | 
| 244 | 244 | * HTML5 doesn't care about boilerplate | 
| 245 | 245 | */ | 
| 246 | - private function elementSpecificOptimizations(PHPTAL_Dom_Element $element) | |
| 247 | -	{ | |
| 248 | - if ($element->getNamespaceURI() !== 'http://www.w3.org/1999/xhtml' | |
| 249 | -	     && $element->getNamespaceURI() !== '') { | |
| 250 | - return; | |
| 246 | + private function elementSpecificOptimizations(PHPTAL_Dom_Element $element) | |
| 247 | +    { | |
| 248 | + if ($element->getNamespaceURI() !== 'http://www.w3.org/1999/xhtml' | |
| 249 | +         && $element->getNamespaceURI() !== '') { | |
| 250 | + return; | |
| 251 | 251 | } | 
| 252 | 252 | |
| 253 | 253 |          if ($this->getPHPTAL()->getOutputMode() !== PHPTAL::HTML5) { | 
| @@ -255,11 +255,11 @@ discard block | ||
| 255 | 255 | } | 
| 256 | 256 | |
| 257 | 257 | // <meta charset> | 
| 258 | -	    if ('meta' === $element->getLocalName() && | |
| 259 | -	        $element->getAttributeNS('','http-equiv') === 'Content-Type') { | |
| 260 | -	            $element->removeAttributeNS('','http-equiv'); | |
| 261 | -	            $element->removeAttributeNS('','content'); | |
| 262 | -	            $element->setAttributeNS('','charset',strtolower($this->getPHPTAL()->getEncoding())); | |
| 258 | +        if ('meta' === $element->getLocalName() && | |
| 259 | +            $element->getAttributeNS('','http-equiv') === 'Content-Type') { | |
| 260 | +                $element->removeAttributeNS('','http-equiv'); | |
| 261 | +                $element->removeAttributeNS('','content'); | |
| 262 | +                $element->setAttributeNS('','charset',strtolower($this->getPHPTAL()->getEncoding())); | |
| 263 | 263 | } | 
| 264 | 264 |          elseif (('link' === $element->getLocalName() && $element->getAttributeNS('','rel') === 'stylesheet') || | 
| 265 | 265 |              ('style' === $element->getLocalName())) { | 
| @@ -975,10 +975,10 @@ discard block | ||
| 975 | 975 | */ | 
| 976 | 976 | public function getFunctionName() | 
| 977 | 977 |      { | 
| 978 | - // function name is used as base for caching, so it must be unique for | |
| 979 | - // every combination of settings that changes code in compiled template | |
| 978 | + // function name is used as base for caching, so it must be unique for | |
| 979 | + // every combination of settings that changes code in compiled template | |
| 980 | 980 | |
| 981 | -       if (!$this->_functionName) { | |
| 981 | +        if (!$this->_functionName) { | |
| 982 | 982 | |
| 983 | 983 | // just to make tempalte name recognizable | 
| 984 | 984 |              $basename = preg_replace('/\.[a-z]{3,5}$/', '', basename($this->_source->getRealPath() ?? '')); | 
| @@ -998,7 +998,7 @@ discard block | ||
| 998 | 998 | $hash = strtr(rtrim(base64_encode($hash),"="),"+/=","_A_"); | 
| 999 | 999 | |
| 1000 | 1000 | $this->_functionName = $this->getFunctionNamePrefix($this->_source->getLastModifiedTime()) . | 
| 1001 | - $basename . '__' . $hash; | |
| 1001 | + $basename . '__' . $hash; | |
| 1002 | 1002 | } | 
| 1003 | 1003 | return $this->_functionName; | 
| 1004 | 1004 | } | 
| @@ -60,23 +60,23 @@ discard block | ||
| 60 | 60 | |
| 61 | 61 | |
| 62 | 62 | static $state_names = array( | 
| 63 | - self::ST_ROOT => 'root node', | |
| 64 | - self::ST_TEXT => 'text', | |
| 65 | - self::ST_LT => 'start of tag', | |
| 66 | - self::ST_TAG_NAME => 'tag name', | |
| 67 | - self::ST_TAG_CLOSE => 'closing tag', | |
| 68 | - self::ST_TAG_SINGLE => 'self-closing tag', | |
| 69 | - self::ST_TAG_ATTRIBUTES => 'tag', | |
| 70 | - self::ST_TAG_BETWEEN_ATTRIBUTE => 'tag attributes', | |
| 71 | - self::ST_CDATA => 'CDATA', | |
| 72 | - self::ST_COMMENT => 'comment', | |
| 73 | - self::ST_DOCTYPE => 'doctype', | |
| 74 | - self::ST_XMLDEC => 'XML declaration', | |
| 75 | - self::ST_PREPROC => 'preprocessor directive', | |
| 76 | - self::ST_ATTR_KEY => 'attribute name', | |
| 77 | - self::ST_ATTR_EQ => 'attribute value', | |
| 78 | - self::ST_ATTR_QUOTE => 'quoted attribute value', | |
| 79 | - self::ST_ATTR_VALUE => 'unquoted attribute value', | |
| 63 | + self::ST_ROOT => 'root node', | |
| 64 | + self::ST_TEXT => 'text', | |
| 65 | + self::ST_LT => 'start of tag', | |
| 66 | + self::ST_TAG_NAME => 'tag name', | |
| 67 | + self::ST_TAG_CLOSE => 'closing tag', | |
| 68 | + self::ST_TAG_SINGLE => 'self-closing tag', | |
| 69 | + self::ST_TAG_ATTRIBUTES => 'tag', | |
| 70 | + self::ST_TAG_BETWEEN_ATTRIBUTE => 'tag attributes', | |
| 71 | + self::ST_CDATA => 'CDATA', | |
| 72 | + self::ST_COMMENT => 'comment', | |
| 73 | + self::ST_DOCTYPE => 'doctype', | |
| 74 | + self::ST_XMLDEC => 'XML declaration', | |
| 75 | + self::ST_PREPROC => 'preprocessor directive', | |
| 76 | + self::ST_ATTR_KEY => 'attribute name', | |
| 77 | + self::ST_ATTR_EQ => 'attribute value', | |
| 78 | + self::ST_ATTR_QUOTE => 'quoted attribute value', | |
| 79 | + self::ST_ATTR_VALUE => 'unquoted attribute value', | |
| 80 | 80 | ); | 
| 81 | 81 | |
| 82 | 82 | private $input_encoding; | 
| @@ -381,15 +381,15 @@ discard block | ||
| 381 | 381 | |
| 382 | 382 | // http://www.w3.org/International/questions/qa-forms-utf-8 | 
| 383 | 383 | $match = '[\x09\x0A\x0D\x20-\x7F]' // ASCII | 
| 384 | - . '|[\xC2-\xDF][\x80-\xBF]' // non-overlong 2-byte | |
| 385 | - . '|\xE0[\xA0-\xBF][\x80-\xBF]' // excluding overlongs | |
| 386 | -               . '|[\xE1-\xEC\xEE\xEE][\x80-\xBF]{2}' // straight 3-byte (exclude FFFE and FFFF) | |
| 387 | - . '|\xEF[\x80-\xBE][\x80-\xBF]' // straight 3-byte | |
| 388 | - . '|\xEF\xBF[\x80-\xBD]' // straight 3-byte | |
| 389 | - . '|\xED[\x80-\x9F][\x80-\xBF]' // excluding surrogates | |
| 390 | -               . '|\xF0[\x90-\xBF][\x80-\xBF]{2}'     // planes 1-3 | |
| 391 | -               . '|[\xF1-\xF3][\x80-\xBF]{3}'         // planes 4-15 | |
| 392 | -               . '|\xF4[\x80-\x8F][\x80-\xBF]{2}';    // plane 16 | |
| 384 | + . '|[\xC2-\xDF][\x80-\xBF]' // non-overlong 2-byte | |
| 385 | + . '|\xE0[\xA0-\xBF][\x80-\xBF]' // excluding overlongs | |
| 386 | +                . '|[\xE1-\xEC\xEE\xEE][\x80-\xBF]{2}' // straight 3-byte (exclude FFFE and FFFF) | |
| 387 | + . '|\xEF[\x80-\xBE][\x80-\xBF]' // straight 3-byte | |
| 388 | + . '|\xEF\xBF[\x80-\xBD]' // straight 3-byte | |
| 389 | + . '|\xED[\x80-\x9F][\x80-\xBF]' // excluding surrogates | |
| 390 | +                . '|\xF0[\x90-\xBF][\x80-\xBF]{2}'     // planes 1-3 | |
| 391 | +                . '|[\xF1-\xF3][\x80-\xBF]{3}'         // planes 4-15 | |
| 392 | +                . '|\xF4[\x80-\x8F][\x80-\xBF]{2}';    // plane 16 | |
| 393 | 393 | |
| 394 | 394 |              if (!preg_match('/^(?:(?>'.$match.'))+$/s',$str)) { | 
| 395 | 395 |                  $res = preg_split('/((?>'.$match.')+)/s',$str,0,PREG_SPLIT_DELIM_CAPTURE); |