Changeset 438 for trunk/patTemplate
- Timestamp:
- 08/08/06 22:50:46 (2 years ago)
- Files:
-
- trunk/patTemplate/Reader.php (modified) (65 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/patTemplate/Reader.php
r437 r438 31 31 */ 32 32 define( 'PATTEMPLATE_READER_ERROR_NO_CLOSING_TAG', 6003 ); 33 33 34 34 /** 35 35 * Invalid closing tag … … 112 112 */ 113 113 var $_templates = array(); 114 114 115 115 /** 116 116 * path to the template … … 119 119 */ 120 120 var $_path = array(); 121 121 122 122 /** 123 123 * start tag for variables … … 126 126 */ 127 127 var $_startTag; 128 128 129 129 /** 130 130 * end tag for variables … … 133 133 */ 134 134 var $_endTag; 135 135 136 136 /** 137 137 * default attributes … … 200 200 */ 201 201 var $_funcAliases = array(); 202 202 203 203 /** 204 204 * options … … 208 208 */ 209 209 var $_options = array(); 210 210 211 211 /** 212 212 * reader is in use … … 216 216 */ 217 217 var $_inUse = false; 218 218 219 219 /** 220 220 * set a reference to the patTemplate object that instantiated the reader … … 229 229 230 230 /** 231 * read templates from any input 231 * read templates from any input 232 232 * 233 233 * @abstract must be implemented in the template readers … … 243 243 244 244 /** 245 * load template from any input 245 * load template from any input 246 246 * 247 247 * If the a template is loaded, the content will not get … … 271 271 272 272 $this->_options = $options; 273 273 274 274 if (isset($options['functionAliases'])) { 275 275 $this->_funcAliases = $options['functionAliases']; … … 289 289 $this->_funcAliases[strtolower($alias)] = $function; 290 290 } 291 291 292 292 /** 293 293 * set the root attributes … … 316 316 */ 317 317 $string = $this->_tmpl->applyInputFilters( $string ); 318 318 319 319 $this->_inheritAtts = array(); 320 320 $this->_elStack = array(); … … 325 325 $this->_path = array(); 326 326 $this->_processedData = ''; 327 327 328 328 $this->_defaultAtts = $this->_tmpl->getDefaultAttributes(); 329 329 330 330 if( !isset( $this->_defaultAtts['autoload'] ) ) { 331 331 $this->_defaultAtts['autoload'] = 'on'; … … 337 337 $attributes = $this->_rootAtts; 338 338 $attributes['name'] = '__ptroot'; 339 339 340 340 $rootTemplate = $this->_initTemplate( $attributes ); 341 341 $this->_root = null; … … 429 429 430 430 $this->_closeTemplate( $rootTemplate, $this->_data[0] ); 431 431 432 432 /** 433 433 * check for tags that are still open … … 442 442 443 443 $this->_inUse = false; 444 444 445 445 return $this->_templates; 446 446 } 447 447 448 448 /** 449 449 * parse an attribute string and build an array … … 509 509 case 'sub': 510 510 $result = $this->_initSubTemplate( $attributes ); 511 break; 511 break; 512 512 513 513 /** … … 516 516 case 'link': 517 517 $result = $this->_initLink( $attributes ); 518 break; 518 break; 519 519 520 520 /** … … 523 523 case 'var': 524 524 $result = false; 525 break; 525 break; 526 526 527 527 /** … … 531 531 case 'comment': 532 532 $result = false; 533 break; 533 break; 534 534 535 535 /** … … 541 541 } 542 542 $name = ucfirst( $name ); 543 543 544 544 if( !$this->_tmpl->moduleExists( 'Function', $name ) ) { 545 545 … … 565 565 return $result; 566 566 } 567 567 568 568 array_push( $this->_tmplStack, $result ); 569 569 return true; 570 570 } 571 571 572 572 /** 573 573 * handle end element … … 588 588 ); 589 589 } 590 590 591 591 $tmpl = array_pop( $this->_tmplStack ); 592 592 … … 635 635 case 'comment': 636 636 $this->_handleComment( $el['attributes'], $data ); 637 break; 637 break; 638 638 639 639 /** … … 642 642 default: 643 643 $name = ucfirst( $tmpl['function'] ); 644 644 645 645 if( !isset( $this->_functions[$name] ) ) { 646 646 $this->_functions[$name] = $this->_tmpl->loadModule( 'Function', $name ); 647 647 $this->_functions[$name]->setReader( $this ); 648 648 } 649 649 650 650 $result = $this->_functions[$name]->call( $tmpl['attributes'], $data ); 651 651 … … 653 653 return $result; 654 654 } 655 655 656 656 if( is_string( $result ) ) { 657 657 $this->_characterData( $result, false ); … … 678 678 return true; 679 679 } 680 680 681 681 /** 682 682 * handle a Link … … 697 697 ); 698 698 } 699 699 700 700 /** 701 701 * create a new template … … 727 727 } 728 728 729 return true; 730 } 731 729 return true; 730 } 731 732 732 /** 733 733 * create a new template … … 748 748 unset( $attributes['name'] ); 749 749 } 750 750 751 751 /** 752 752 * name must be unique … … 779 779 ) 780 780 ); 781 781 782 782 /** 783 783 * create a new template … … 831 831 return $attributes; 832 832 } 833 833 834 834 $attributes = $this->_inheritAttributes( $attributes ); 835 835 … … 844 844 $attributes['rowoffset'] = 1; 845 845 } 846 846 847 847 if( !isset( $attributes['addsystemvars'] ) ) { 848 848 $attributes['addsystemvars'] = false; … … 862 862 } 863 863 } 864 864 865 865 /** 866 866 * external template … … 891 891 $attributes['varscope'] = $this->_getFromParentTemplate('name'); 892 892 } 893 893 894 894 $attributes['varscope'] = strtolower( $attributes['varscope'] ); 895 895 if (strstr($attributes['varscope'], ',')) { … … 936 936 $attributes['requiredvars'] = array(); 937 937 foreach( $tmp as $var ) { 938 938 939 939 $pos = strpos( $var, '=' ); 940 940 if ($pos !== false) { … … 957 957 ); 958 958 } 959 959 960 960 } 961 961 $attributes['autoclear'] = 'yes'; 962 962 break; 963 963 964 964 /** 965 965 * oddeven => switch to new modulo syntax … … 970 970 $attributes['autoclear'] = 'yes'; 971 971 break; 972 972 973 973 /** 974 974 * modulo => requires a module attribute … … 1002 1002 1003 1003 $attributes['__prepared'] = true; 1004 1004 1005 1005 return $attributes; 1006 1006 } 1007 1007 1008 1008 /** 1009 1009 * build a template name … … 1011 1011 * @access private 1012 1012 * @return string new template name 1013 */ 1013 */ 1014 1014 function _buildTemplateName() 1015 1015 { … … 1030 1030 1031 1031 array_pop( $this->_inheritAtts ); 1032 1032 1033 1033 /** 1034 1034 * check for special templates … … 1051 1051 break; 1052 1052 } 1053 1053 1054 1054 /** 1055 1055 * store the content 1056 1056 */ 1057 1057 $tmpl['content'] = $data; 1058 1058 1059 1059 /** 1060 1060 * No external template … … 1069 1069 if( !empty( $this->_tmplStack ) ) { 1070 1070 $this->_addToParentTag( 'dependencies', $name ); 1071 1071 1072 1072 if( isset( $tmpl['attributes']['placeholder'] ) ) { 1073 1073 // maintain BC … … 1075 1075 $tmpl['attributes']['placeholder'] = '__none'; 1076 1076 } 1077 1077 1078 1078 if( $tmpl['attributes']['placeholder'] !== '__none' ) { 1079 1079 $this->_characterData( $this->_startTag.(strtoupper( $tmpl['attributes']['placeholder'] ) ).$this->_endTag ); … … 1086 1086 unset( $tmpl['name'] ); 1087 1087 unset( $tmpl['tag'] ); 1088 1088 1089 1089 $this->_templates[$name] = $tmpl; 1090 1090 1091 1091 return true; 1092 1092 } … … 1142 1142 array_push( $this->_tmplStack, $parent ); 1143 1143 if ($parent['attributes']['type'] == 'modulo') { 1144 1144 1145 1145 if( preg_match( '/^\d$/', $attributes['condition'] ) ) { 1146 1146 if( (integer)$attributes['condition'] >= $parent['attributes']['modulo'] ) { … … 1180 1180 { 1181 1181 $data = $this->_adjustWhitespace( $data, $subTmpl['attributes']['whitespace'] ); 1182 1182 1183 1183 $subTmpl['data'] = $data; 1184 1184 $condition = $subTmpl['condition']; … … 1191 1191 return true; 1192 1192 } 1193 1193 1194 1194 /** 1195 1195 * handle a variable … … 1209 1209 } 1210 1210 1211 $specs = array(); 1212 1211 $specs = array(); 1212 1213 1213 /** 1214 1214 * get name … … 1228 1228 $specs['default'] = $data; 1229 1229 } 1230 1230 1231 1231 /** 1232 1232 * add it to template, if it's not hidden … … 1235 1235 $this->_characterData( $this->_startTag . strtoupper( $name ) . $this->_endTag ); 1236 1236 } 1237 1237 1238 1238 if( isset( $attributes['hidden'] ) ) { 1239 1239 unset( $attributes['hidden'] ); … … 1242 1242 /** 1243 1243 * copy value from any other variable 1244 */ 1244 */ 1245 1245 if (isset( $attributes['copyfrom'] )) { 1246 1246 $specs['copyfrom'] = strtoupper( $attributes['copyfrom'] ); 1247 1247 1248 1248 if (strstr( $specs['copyfrom'], '.' )) { 1249 1249 $specs['copyfrom'] = explode( '.', $specs['copyfrom'] ); … … 1255 1255 } 1256 1256 } 1257 1257 1258 1258 unset( $attributes['copyfrom'] ); 1259 1259 } 1260 1260 1261 1261 if( isset( $attributes['modifier'] ) ) { 1262 1262 $modifier = $attributes['modifier']; … … 1270 1270 $specs['modifier'] = array( 'mod' => $modifier, 'type' => $type, 'params' => $attributes ); 1271 1271 } 1272 1272 1273 1273 if (!empty( $specs )) { 1274 1274 $this->_addToParentTemplate( … … 1320 1320 { 1321 1321 $cnt = count( $this->_tmplStack ); 1322 1322 1323 1323 if ($cnt === 0) { 1324 1324 return false; … … 1331 1331 continue; 1332 1332 } 1333 1333 1334 1334 if ($key === null) { 1335 1335 1336 1336 if (!in_array( $value, $this->_tmplStack[$pos][$property] )) { 1337 1337 array_push( $this->_tmplStack[$pos][$property], $value ); … … 1343 1343 return true; 1344 1344 } 1345 1345 1346 1346 return false; 1347 1347 } … … 1358 1358 { 1359 1359 $cnt = count( $this->_tmplStack ); 1360 1360 1361 1361 if ($cnt === 0) { 1362 1362 return false; … … 1391 1391 { 1392 1392 $cnt = count( $this->_tmplStack ); 1393 1393 1394 1394 if ($cnt === 0) { 1395 1395 return false; … … 1397 1397 1398 1398 $pos = $cnt - 1; 1399 1399 1400 1400 if ($key === null) { 1401 1401 1402 1402 if (!in_array( $value, $this->_tmplStack[$pos][$property] )) { 1403 1403 array_push( $this->_tmplStack[$pos][$property], $value ); … … 1455 1455 1456 1456 $attributes = array_merge( $parent, $attributes ); 1457 1457 1458 1458 return $attributes; 1459 1459 } … … 1476 1476 } 1477 1477 array_push( $this->_tmplStack, $parent ); 1478 1478 1479 1479 if( $parent['type'] == $type ) { 1480 1480 return true; 1481 1481 } 1482 1482 1483 1483 return false; 1484 1484 } … … 1522 1522 return $this->_currentInput; 1523 1523 } 1524 1524 1525 1525 /** 1526 1526 * tests whether the reader should maintain backwards compatibility … … 1552 1552 return $this->_inUse; 1553 1553 } 1554 1554 1555 1555 /** 1556 1556 * get the template root for this reader
