ezpublish /lib/eztemplate/classes/eztemplate.php

Language PHP Lines 2703
MD5 Hash c66ecac8902c70f99ed364aa4b2d2e3e
Repository https://github.com/aurelienRT1/ezpublish.git View Raw File View Project SPDX
   1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
<?php
//
// Definition of eZTemplate class
//
// Created on: <01-Mar-2002 13:49:57 amos>
//
// ## BEGIN COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
// SOFTWARE NAME: eZ Publish
// SOFTWARE RELEASE: 4.1.x
// COPYRIGHT NOTICE: Copyright (C) 1999-2010 eZ Systems AS
// SOFTWARE LICENSE: GNU General Public License v2.0
// NOTICE: >
//   This program is free software; you can redistribute it and/or
//   modify it under the terms of version 2.0  of the GNU General
//   Public License as published by the Free Software Foundation.
//
//   This program is distributed in the hope that it will be useful,
//   but WITHOUT ANY WARRANTY; without even the implied warranty of
//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//   GNU General Public License for more details.
//
//   You should have received a copy of version 2.0 of the GNU General
//   Public License along with this program; if not, write to the Free
//   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
//   MA 02110-1301, USA.
//
//
// ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
//

/*! \file
 Template system manager.
*/

/*! \defgroup eZTemplate Template system */

/*!
  \class eZTemplate eztemplate.php
  \ingroup eZTemplate
  \brief The main manager for templates

  The template systems allows for separation of code and
  layout by moving the layout part into template files. These
  template files are parsed and processed with template variables set
  by the PHP code.

  The template system in itself is does not do much, it parses template files
  according to a rule set sets up a tree hierarchy and process the data
  using functions and operators. The standard template system comes with only
  a few functions and no operators, it is meant for these functions and operators
  to be specified by the users of the template system. But for simplicity a few
  help classes is available which can be easily enabled.

  The classes are:
  - eZTemplateDelimitFunction - Inserts the left and right delimiter which are normally parsed.
  - eZTemplateSectionFunction - Allows for conditional blocks and loops.
  - eZTemplateIncludeFunction - Includes external templates
  - eZTemplateSequenceFunction - Creates sequences arrays
  - eZTemplateSwitchFunction - Conditional output of template

  - eZTemplatePHPOperator - Allows for easy redirection of operator names to PHP functions.
  - eZTemplateLocaleOperator - Allows for locale conversions.
  - eZTemplateArrayOperator - Creates arrays
  - eZTemplateAttributeOperator - Displays contents of template variables, useful for debugging
  - eZTemplateImageOperator - Converts text to image
  - eZTemplateLogicOperator - Various logical operators for boolean handling
  - eZTemplateUnitOperator - Unit conversion and display

  To enable these functions and operator use registerFunction and registerOperator.

  In keeping with the spirit of being simple the template system does not know how
  to get the template files itself. Instead it relies on resource handlers, these
  handlers fetches the template files using different kind of transport mechanism.
  For simplicity a default resource class is available, eZTemplateFileResource fetches
  templates from the filesystem.

  The parser process consists of three passes, each pass adds a new level of complexity.
  The first pass strips text from template blocks which starts with a left delimiter and
  ends with a right delimiter (default is { and } ), and places them in an array.
  The second pass iterates the text and block elements and removes newlines from
  text before function blocks and text after function blocks.
  The third pass builds the tree according the function rules.

  Processing is done by iterating over the root of the tree, if a text block is found
  the text is appended to the result text. If a variable or contant is it's data is extracted
  and any operators found are run on it before fetching the result and appending it to
  the result text. If a function is found the function is called with the parameters
  and it's up to the function handle children if any.

  Constants and template variables will usually be called variables since there's little
  difference. A template variable expression will start with a $ and consists of a
  namespace (optional) a name and attribues(optional). The variable expression
  \verbatim $root:var.attr1 \endverbatim exists in the "root" namespace, has the name "var" and uses the
  attribute "attr1". Some functions will create variables on demand, to avoid name conflicts
  namespaces were introduced, each function will place the new variables in a namespace
  specified in the template file. Attribues are used for fetching parts of the variable,
  for instance an element in an array or data in an object. Since the syntax is the
  same for arrays and objects the PHP code can use simple arrays when speed is required,
  the template code will not care.
  A different syntax is also available when you want to access an attribute using a variable.
  For instance \verbatim $root:var[$attr_var] \endverbatim, if the variable $attr_var contains "attr1" it would
  access the same attribute as in the first example.

  The syntax for operators is a | and a name, optionally parameters can be specified with
  ( and ) delimited with ,. Valid operators are \verbatim |upcase, |l10n(date) \endverbatim.

  Functions look a lot like HTML/XML tags. The function consists of a name and parameters
  which are assigned using the param=value syntax. Some parameters may be required while
  others may be optionally, the exact behaviour is specified by each function.
  Valid functions are \verbatim "section name=abc loop=4" \endverbatim

  Example of usage:
\code
// Init template
$tpl = eZTemplate::instance();

$tpl->registerOperators( new eZTemplatePHPOperator( array( "upcase" => "strtoupper",
                                                           "reverse" => "strrev" ) ) );
$tpl->registerOperators( new eZTemplateLocaleOperator() );
$tpl->registerFunction( "section", new eZTemplateSectionFunction( "section" ) );
$tpl->registerFunctions( new eZTemplateDelimitFunction() );

$tpl->setVariable( "my_var", "{this value set by variable}", "test" );
$tpl->setVariable( "my_arr", array( "1st", "2nd", "third", "fjerde" ) );
$tpl->setVariable( "multidim", array( array( "a", "b" ),
                                      array( "c", "d" ),
                                      array( "e", "f" ),
                                      array( "g", "h" ) ) );

class mytest
{
    function mytest( $n, $s )
    {
        $this->n = $n;
        $this->s = $s;
    }

    function hasAttribute( $attr )
    {
        return ( $attr == "name" || $attr == "size" );
    }

    function attribute( $attr )
    {
        switch ( $attr )
        {
            case "name";
                return $this->n;
            case "size";
                return $this->s;
            default:
                $retAttr = null;
                return $retAttr;
        }
    }

};

$tpl->setVariable( "multidim_obj", array( new mytest( "jan", 200 ),
                                          new mytest( "feb", 200 ),
                                          new mytest( "john", 200 ),
                                          new mytest( "doe", 50 ) ) );
$tpl->setVariable( "curdate", time() );

$tpl->display( "lib/eztemplate/example/test.tpl" );

// test.tpl

{section name=outer loop=4}
123
{delimit}::{/delimit}
{/section}

{literal test=1} This is some {blah arg1="" arg2="abc" /} {/literal}

<title>This is a test</title>
<table border="1">
<tr><th>{$test:my_var}
{"some text!!!"|upcase|reverse}</th></tr>
{section name=abc loop=$my_arr}
<tr><td>{$abc:item}</td></tr>
{/section}
</table>

<table border="1">
{section name=outer loop=$multidim}
<tr>
{section name=inner loop=$outer:item}
<td>{$inner:item}</td>
{/section}
</tr>
{/section}
</table>

<table border="1">
{section name=outer loop=$multidim_obj}
<tr>
<td>{$outer:item.name}</td>
<td>{$outer:item.size}</td>
</tr>
{/section}
</table>

{section name=outer loop=$nonexistingvar}
<b><i>Dette skal ikke vises</b></i>
{section-else}
<b><i>This is shown when the {ldelim}$loop{rdelim} variable is non-existant</b></i>
{/section}


Denne koster {1.4|l10n(currency)}<br>
{-123456789|l10n(number)}<br>
{$curdate|l10n(date)}<br>
{$curdate|l10n(shortdate)}<br>
{$curdate|l10n(time)}<br>
{$curdate|l10n(shorttime)}<br>
{include file="test2.tpl"/}

\endcode
*/

class eZTemplate
{
    const RESOURCE_FETCH = 1;
    const RESOURCE_QUERY = 2;

    const ELEMENT_TEXT = 1;
    const ELEMENT_SINGLE_TAG = 2;
    const ELEMENT_NORMAL_TAG = 3;
    const ELEMENT_END_TAG = 4;
    const ELEMENT_VARIABLE = 5;
    const ELEMENT_COMMENT = 6;

    const NODE_ROOT = 1;
    const NODE_TEXT = 2;
    const NODE_VARIABLE = 3;
    const NODE_FUNCTION = 4;
    const NODE_OPERATOR = 5;


    const NODE_INTERNAL = 100;
    const NODE_INTERNAL_CODE_PIECE = 101;

    const NODE_INTERNAL_VARIABLE_SET = 105;
    const NODE_INTERNAL_VARIABLE_UNSET = 102;

    const NODE_INTERNAL_NAMESPACE_CHANGE = 103;
    const NODE_INTERNAL_NAMESPACE_RESTORE = 104;

    const NODE_INTERNAL_WARNING = 120;
    const NODE_INTERNAL_ERROR = 121;

    const NODE_INTERNAL_RESOURCE_ACQUISITION = 140;
    const NODE_OPTIMIZED_RESOURCE_ACQUISITION = 141;

    const NODE_INTERNAL_OUTPUT_ASSIGN = 150;
    const NODE_INTERNAL_OUTPUT_READ = 151;
    const NODE_INTERNAL_OUTPUT_INCREASE = 152;
    const NODE_INTERNAL_OUTPUT_DECREASE = 153;

    const NODE_INTERNAL_OUTPUT_SPACING_INCREASE = 160;
    const NODE_INTERNAL_SPACING_DECREASE = 161;

    const NODE_OPTIMIZED_INIT = 201;


    const NODE_USER_CUSTOM = 1000;


    const TYPE_VOID = 0;
    const TYPE_STRING = 1;
    const TYPE_NUMERIC = 2;
    const TYPE_IDENTIFIER = 3;
    const TYPE_VARIABLE = 4;
    const TYPE_ATTRIBUTE = 5;
    const TYPE_OPERATOR = 6;
    const TYPE_BOOLEAN = 7;
    const TYPE_ARRAY = 8;
    const TYPE_DYNAMIC_ARRAY = 9;

    const TYPE_INTERNAL = 100;
    const TYPE_INTERNAL_CODE_PIECE = 101;
    const TYPE_PHP_VARIABLE = 102;

    const TYPE_OPTIMIZED_NODE = 201;
    const TYPE_OPTIMIZED_ARRAY_LOOKUP = 202;
    const TYPE_OPTIMIZED_CONTENT_CALL = 203;
    const TYPE_OPTIMIZED_ATTRIBUTE_LOOKUP = 204;

    const TYPE_INTERNAL_STOP = 999;


    const TYPE_STRING_BIT = 1;
    const TYPE_NUMERIC_BIT = 2;
    const TYPE_IDENTIFIER_BIT = 4;
    const TYPE_VARIABLE_BIT = 8;
    const TYPE_ATTRIBUTE_BIT = 16;
    const TYPE_OPERATOR_BIT = 32;

    const TYPE_NONE = 0;

    const TYPE_ALL = 63;

    const TYPE_BASIC = 47;

    const TYPE_MODIFIER_MASK = 48;

    const NAMESPACE_SCOPE_GLOBAL = 1;
    const NAMESPACE_SCOPE_LOCAL = 2;
    const NAMESPACE_SCOPE_RELATIVE = 3;

    const DEBUG_INTERNALS = false;

    const FILE_ERRORS = 1;

    /*!
     Intializes the template with left and right delimiters being { and },
     and a file resource. The literal tag "literal" is also registered.
    */
    function eZTemplate()
    {
        $this->Tree = array( eZTemplate::NODE_ROOT, false );
        $this->LDelim = "{";
        $this->RDelim = "}";

        $this->IncludeText = array();
        $this->IncludeOutput = array();

        $this->registerLiteral( "literal" );

        $res = new eZTemplateFileResource();
        $this->DefaultResource = $res;
        $this->registerResource( $res );

        $this->Resources = array();
        $this->Text = null;

        $this->IsCachingAllowed = true;

        $this->resetErrorLog();

        $this->AutoloadPathList = array( 'lib/eztemplate/classes/' );
        $this->Variables = array();
        $this->LocalVariablesNamesStack = array();
        $this->CurrentLocalVariablesNames = null;
        $this->Functions = array();
        $this->FunctionAttributes = array();

        $this->TestCompile = false;

        $ini = eZINI::instance( 'template.ini' );
        if ( $ini->hasVariable( 'ControlSettings', 'MaxLevel' ) )
             $this->MaxLevel = $ini->variable( 'ControlSettings', 'MaxLevel' );

        $this->MaxLevelWarning = ezpI18n::tr( 'lib/template',
                                         'The maximum nesting level of %max has been reached. The execution is stopped to avoid infinite recursion.',
                                         '',
                                         array( '%max' => $this->MaxLevel ) );
        eZDebug::createAccumulatorGroup( 'template_total', 'Template Total' );

        $this->TemplatesUsageStatistics = array();
        // Array of templates which are used in a single fetch()
        $this->TemplateFetchList = array();

        $this->ForeachCounter = 0;
        $this->ForCounter     = 0;
        $this->WhileCounter   = 0;
        $this->DoCounter      = 0;
        $this->ElseifCounter  = 0;
    }

    /*!
     Returns the left delimiter being used.
    */
    function leftDelimiter()
    {
        return $this->LDelim;
    }

    /*!
     Returns the right delimiter being used.
    */
    function rightDelimiter()
    {
        return $this->RDelim;
    }

    /*!
     Sets the left delimiter.
    */
    function setLeftDelimiter( $delim )
    {
        $this->LDelim = $delim;
    }

    /*!
     Sets the right delimiter.
    */
    function setRightDelimiter( $delim )
    {
        $this->RDelim = $delim;
    }

    /*!
     Fetches the result of the template file and displays it.
     If $template is supplied it will load this template file first.
    */
    function display( $template = false, $extraParameters = false )
    {
        $output = $this->fetch( $template, $extraParameters );
        if ( $this->ShowDetails )
        {
            echo '<h1>Result:</h1>' . "\n";
            echo '<hr/>' . "\n";
        }
        echo "$output";
        if ( $this->ShowDetails )
        {
            echo '<hr/>' . "\n";
        }
        if ( $this->ShowDetails )
        {
            echo "<h1>Template data:</h1>";
            echo "<p class=\"filename\">" . $template . "</p>";
            echo "<pre class=\"example\">" . htmlspecialchars( $this->Text ) . "</pre>";
            reset( $this->IncludeText );
            while ( ( $key = key( $this->IncludeText ) ) !== null )
            {
                $item = $this->IncludeText[$key];
                echo "<p class=\"filename\">" . $key . "</p>";
                echo "<pre class=\"example\">" . htmlspecialchars( $item ) . "</pre>";
                next( $this->IncludeText );
            }
            echo "<h1>Result text:</h1>";
            echo "<p class=\"filename\">" . $template . "</p>";
            echo "<pre class=\"example\">" . htmlspecialchars( $output ) . "</pre>";
            reset( $this->IncludeOutput );
            while ( ( $key = key( $this->IncludeOutput ) ) !== null )
            {
                $item = $this->IncludeOutput[$key];
                echo "<p class=\"filename\">" . $key . "</p>";
                echo "<pre class=\"example\">" . htmlspecialchars( $item ) . "</pre>";
                next( $this->IncludeOutput );
            }
        }
    }

    /*!
     * Initialize list of local variables for the current template.
     * The list contains only names of variables.
     */
    function createLocalVariablesList()
    {
        $this->LocalVariablesNamesStack[] = array();
        $this->CurrentLocalVariablesNames =& $this->LocalVariablesNamesStack[ count( $this->LocalVariablesNamesStack ) - 1];
    }

    /*!
     * Check if the given local variable exists.
     */
    function hasLocalVariable( $varName, $rootNamespace )
    {
        return ( array_key_exists( $rootNamespace, $this->CurrentLocalVariablesNames ) &&
                 array_key_exists( $varName, $this->CurrentLocalVariablesNames[$rootNamespace] ) );
    }

    /*!
     * Create a local variable.
     */
    function setLocalVariable( $varName, $varValue, $rootNamespace )
    {
        $this->CurrentLocalVariablesNames[$rootNamespace][$varName] = 1;
        $this->setVariable( $varName, $varValue, $rootNamespace );
    }

    /*!
     * Destroy a local variable.
     */
    function unsetLocalVariable( $varName, $rootNamespace )
    {
        if ( !$this->hasLocalVariable( $varName, $rootNamespace ) )
            return;

        $this->unsetVariable( $varName, $rootNamespace );
        unset( $this->CurrentLocalVariablesNames[$rootNamespace][$varName] );
    }

    /*!
     * Destroy all local variables defined in the current template.
     */
    function unsetLocalVariables()
    {
        foreach ( $this->CurrentLocalVariablesNames as $ns => $vars )
        {
            foreach ( $vars as $var => $val )
                $this->unsetLocalVariable( $var, $ns );
        }
    }

    /*!
     * Destroy list of local variables defined in the current (innermost) template.
     */
    function destroyLocalVariablesList()
    {
        array_pop( $this->LocalVariablesNamesStack );

        if ( $this->LocalVariablesNamesStack )
            $this->CurrentLocalVariablesNames =& $this->LocalVariablesNamesStack[ count( $this->LocalVariablesNamesStack ) - 1];
        else
            unset( $this->CurrentLocalVariablesNames );
    }

    /*!
     Tries to fetch the result of the template file and returns it.
     If $template is supplied it will load this template file first.
    */
    function fetch( $template = false, $extraParameters = false, $returnResourceData = false )
    {
        $this->resetErrorLog();
        // Reset fetch list when a new fetch is started
        $this->TemplateFetchList = array();

        eZDebug::accumulatorStart( 'template_total' );
        eZDebug::accumulatorStart( 'template_load', 'template_total', 'Template load' );
        $root = null;
        if ( is_string( $template ) )
        {
            $resourceData = $this->loadURIRoot( $template, true, $extraParameters );
            if ( $resourceData and
                 $resourceData['root-node'] !== null )
                $root =& $resourceData['root-node'];
        }
        eZDebug::accumulatorStop( 'template_load' );
        if ( $resourceData['locales'] && !empty( $resourceData['locales'] ) )
        {
            $savedLocale = setlocale( LC_CTYPE, null );
            setlocale( LC_CTYPE, $resourceData['locales'] );
        }

        $text = "";

        if ( $root !== null or
             $resourceData['compiled-template'] )
        {
            if ( $this->ShowDetails )
                eZDebug::addTimingPoint( "Process" );
            eZDebug::accumulatorStart( 'template_processing', 'template_total', 'Template processing' );

            $templateCompilationUsed = false;
            if ( $resourceData['compiled-template'] )
            {
                $textElements = array();
                if ( $this->executeCompiledTemplate( $resourceData, $textElements, "", "", $extraParameters ) )
                {
                    $text = implode( '', $textElements );
                    $templateCompilationUsed = true;
                }
            }
            if ( !$templateCompilationUsed )
            {
                if ( eZTemplate::isDebugEnabled() )
                {
                    $fname = $resourceData['template-filename'];
                    eZDebug::writeDebug( "FETCH START URI: $template, $fname" );
                }
                $this->process( $root, $text, "", "" );
                if ( eZTemplate::isDebugEnabled() )
                    eZDebug::writeDebug( "FETCH END URI: $template, $fname" );
            }

            eZDebug::accumulatorStop( 'template_processing' );
            if ( $this->ShowDetails )
                eZDebug::addTimingPoint( "Process done" );
        }

        eZDebug::accumulatorStop( 'template_total' );

        if ( $resourceData['locales'] && !empty( $resourceData['locales'] ) )
        {
            setlocale( LC_CTYPE, $savedLocale );
        }

        if ( $returnResourceData )
        {
            $resourceData['result_text'] = $text;
            return $resourceData;
        }
        return $text;
    }

    function process( $root, &$text, $rootNamespace, $currentNamespace )
    {
        $this->createLocalVariablesList();

        $textElements = array();
        $this->processNode( $root, $textElements, $rootNamespace, $currentNamespace );
        if ( is_array( $textElements ) )
            $text = implode( '', $textElements );
        else
            $text = $textElements;

        $this->unsetLocalVariables();
        $this->destroyLocalVariablesList();
    }

    function processNode( $node, &$textElements, $rootNamespace, $currentNamespace )
    {
        $rslt = null;
        $nodeType = $node[0];
        if ( $nodeType == eZTemplate::NODE_ROOT )
        {
            $children = $node[1];
            if ( $children )
            {
                foreach ( $children as $child )
                {
                    $this->processNode( $child, $textElements, $rootNamespace, $currentNamespace );
                    if ( !is_array( $textElements ) )
                        eZDebug::writeError( "Textelements is no longer array: '$textElements'",
                                             'eztemplate::processNode::root' );
                }
            }
        }
        else if ( $nodeType == eZTemplate::NODE_TEXT )
        {
            $textElements[] = $node[2];
        }
        else if ( $nodeType == eZTemplate::NODE_VARIABLE )
        {
            $variableData = $node[2];
            $variablePlacement = $node[3];
            $rslt = $this->processVariable( $textElements, $variableData, $variablePlacement, $rootNamespace, $currentNamespace );
            if ( !is_array( $textElements ) )
                eZDebug::writeError( "Textelements is no longer array: '$textElements'",
                                     'eztemplate::processNode::variable' );
        }
        else if ( $nodeType == eZTemplate::NODE_FUNCTION )
        {
            $functionChildren = $node[1];
            $functionName = $node[2];
            $functionParameters = $node[3];
            $functionPlacement = $node[4];
            $rslt = $this->processFunction( $functionName, $textElements, $functionChildren, $functionParameters, $functionPlacement, $rootNamespace, $currentNamespace );
            if ( !is_array( $textElements ) )
                eZDebug::writeError( "Textelements is no longer array: '$textElements'",
                                     "eztemplate::processNode::function( '$functionName' )" );
        }

        return $rslt;
    }

    function processVariable( &$textElements, $variableData, $variablePlacement, $rootNamespace, $currentNamespace )
    {
        $value = $this->elementValue( $variableData, $rootNamespace, $currentNamespace, $variablePlacement );
        $this->appendElementText( $textElements, $value, $rootNamespace, $currentNamespace );
    }

    function processFunction( $functionName, &$textElements, $functionChildren, $functionParameters, $functionPlacement, $rootNamespace, $currentNamespace )
    {
        // Note: This code piece is replicated in the eZTemplateCompiler,
        //       if this code is changed the replicated code must be updated as well.
        $func = $this->Functions[$functionName];
        if ( is_array( $func ) )
        {
            $this->loadAndRegisterFunctions( $this->Functions[$functionName] );
            $func = $this->Functions[$functionName];
        }
        if ( isset( $func ) and
             is_object( $func ) )
        {
            if ( eZTemplate::isMethodDebugEnabled() )
                eZDebug::writeDebug( "START FUNCTION: $functionName" );
            $value = $func->process( $this, $textElements, $functionName, $functionChildren, $functionParameters, $functionPlacement, $rootNamespace, $currentNamespace );
            if ( eZTemplate::isMethodDebugEnabled() )
                eZDebug::writeDebug( "END FUNCTION: $functionName" );
            return $value;
        }
        else
        {
            $this->warning( "", "Function \"$functionName\" is not registered" );
        }
    }

    function fetchFunctionObject( $functionName )
    {
        $func = $this->Functions[$functionName];
        if ( is_array( $func ) )
        {
            $this->loadAndRegisterFunctions( $this->Functions[$functionName] );
            $func = $this->Functions[$functionName];
        }
        return $func;
    }

    /*!
     Loads the template using the URI $uri and parses it.
     \return The root node of the tree if \a $returnResourceData is false,
             if \c true the entire resource data structure.
    */
    function load( $uri, $extraParameters = false, $returnResourceData = false )
    {
        $resourceData = $this->loadURIRoot( $uri, true, $extraParameters );
        if ( !$resourceData or
             $resourceData['root-node'] === null )
        {
            $retValue = null;
            return $retValue;
        }
        else
            return $resourceData['root-node'];
    }

    function parse( $sourceText, &$rootElement, $rootNamespace, &$resourceData )
    {
        $parser = eZTemplateMultiPassParser::instance();
        $parser->parse( $this, $sourceText, $rootElement, $rootNamespace, $resourceData );
    }

    function loadURIData( $resourceObject, $uri, $resourceName, $template, &$extraParameters, $displayErrors = true )
    {
        $resourceData = $this->resourceData( $resourceObject, $uri, $resourceName, $template );

        $resourceData['text'] = null;
        $resourceData['root-node'] = null;
        $resourceData['compiled-template'] = false;
        $resourceData['time-stamp'] = null;
        $resourceData['key-data'] = null;
        $resourceData['locales'] = null;

        if ( !$resourceObject->handleResource( $this, $resourceData, eZTemplate::RESOURCE_FETCH, $extraParameters ) )
        {
            $resourceData = null;
            if ( $displayErrors )
                $this->warning( "", "No template could be loaded for \"$template\" using resource \"$resourceName\"" );
        }
        return $resourceData;
    }

    /*!
     \static
     Creates a resource data structure of the parameters and returns it.
     This structure is passed to various parts of the template system.

     \note If you only have the URI you should call resourceFor() first to
           figure out the resource handler.
    */
    function resourceData( $resourceObject, $uri, $resourceName, $templateName )
    {
        $resourceData = array();
        $resourceData['uri'] = $uri;
        $resourceData['resource'] = $resourceName;
        $resourceData['template-name'] = $templateName;
        $resourceData['template-filename'] = $templateName;
        $resourceData['handler'] = $resourceObject;
        $resourceData['test-compile'] = $this->TestCompile;
        return $resourceData;
    }

    /*!
     Loads the template using the URI $uri and returns a structure with the text and timestamp,
     false otherwise.
     The structure keys are:
     - "text", the text.
     - "time-stamp", the timestamp.
    */
    function loadURIRoot( $uri, $displayErrors = true, &$extraParameters )
    {
        $res = "";
        $template = "";
        $resobj = $this->resourceFor( $uri, $res, $template );

        if ( !is_object( $resobj ) )
        {
            if ( $displayErrors )
                $this->warning( "", "No resource handler for \"$res\" and no default resource handler, aborting." );
            return null;
        }

        $canCache = true;
        if ( !$resobj->servesStaticData() )
            $canCache = false;
        if ( !$this->isCachingAllowed() )
            $canCache = false;

        $resourceData = $this->loadURIData( $resobj, $uri, $res, $template, $extraParameters, $displayErrors );

        if ( $resourceData )
        {
            $root = null;
            eZTemplate::appendTemplateToStatisticsIfNeeded( $resourceData['template-name'], $resourceData['template-filename'] );
            $this->appendTemplateFetch( $resourceData['template-filename'] );

            if ( !$resourceData['compiled-template'] and
                 $resourceData['root-node'] === null )
            {
                $resourceData['root-node'] = array( eZTemplate::NODE_ROOT, false );
                $templateText = $resourceData["text"];
                $keyData = $resourceData['key-data'];
                $this->setIncludeText( $uri, $templateText );
                $rootNamespace = '';
                $this->parse( $templateText, $resourceData['root-node'], $rootNamespace, $resourceData );

                if ( eZTemplate::isDebugEnabled() )
                {
                    $this->appendDebugNodes( $resourceData['root-node'], $resourceData );
                }

                if ( $canCache )
                    $resobj->setCachedTemplateTree( $keyData, $uri, $res, $template, $extraParameters, $resourceData['root-node'] );
            }
            if ( !$resourceData['compiled-template'] and
                 $canCache and
                 $this->canCompileTemplate( $resourceData, $extraParameters ) )
            {
                $generateStatus = $this->compileTemplate( $resourceData, $extraParameters );
                if ( $generateStatus )
                    $resourceData['compiled-template'] = true;
            }
        }

        return $resourceData;
    }

    function processURI( $uri, $displayErrors = true, &$extraParameters,
                         &$textElements, $rootNamespace, $currentNamespace )
    {
        $this->Level++;
        if ( $this->Level > $this->MaxLevel )
        {
            eZDebug::writeError( $this->MaxLevelWarning,  "eZTemplate:processURI Level: $this->Level @ $uri" );
            $textElements[] = $this->MaxLevelWarning;
            $this->Level--;
            return;
        }
        $resourceData = $this->loadURIRoot( $uri, $displayErrors, $extraParameters );
        if ( !$resourceData or
             ( !$resourceData['compiled-template'] and
               $resourceData['root-node'] === null ) )
        {
            $this->Level--;
            return;
        }

        $templateCompilationUsed = false;

        if ( $resourceData['locales'] && !empty( $resourceData['locales'] ) )
        {
            $savedLocale = setlocale( LC_CTYPE, null );
            setlocale( LC_CTYPE, $resourceData['locales'] );
        }

        if ( $resourceData['compiled-template'] )
        {
            if ( $this->executeCompiledTemplate( $resourceData, $textElements, $rootNamespace, $currentNamespace, $extraParameters ) )
                $templateCompilationUsed = true;
        }
        if ( !$templateCompilationUsed )
        {
            $text = null;
            if ( eZTemplate::isDebugEnabled() )
            {
                $fname = $resourceData['template-filename'];
                eZDebug::writeDebug( "START URI: $uri, $fname" );
            }
            $this->process( $resourceData['root-node'], $text, $rootNamespace, $currentNamespace );
            if ( eZTemplate::isDebugEnabled() )
                eZDebug::writeDebug( "END URI: $uri, $fname" );
            $this->setIncludeOutput( $uri, $text );
            $textElements[] = $text;
        }

        if ( $resourceData['locales'] && !empty( $resourceData['locales'] ) )
        {
            setlocale( LC_CTYPE, $savedLocale );
        }
        $this->Level--;

    }

    function canCompileTemplate( $resourceData, &$extraParameters )
    {
        $resourceObject = $resourceData['handler'];
        if ( !$resourceObject )
            return false;
        $canGenerate = $resourceObject->canCompileTemplate( $this, $resourceData, $extraParameters );
        return $canGenerate;
    }

    /*!
     Validates the template file \a $file and returns \c true if the file has correct syntax.
     \param $returnResourceData If \c true then the returned value will be the resourcedata structure
     \sa compileTemplateFile(), fetch()
    */
    function validateTemplateFile( $file, $returnResourceData = false )
    {
        $this->resetErrorLog();

        if ( !file_exists( $file ) )
            return false;
        $resourceHandler = $this->resourceFor( $file, $resourceName, $templateName );
        if ( !$resourceHandler )
            return false;
        $resourceData = $this->resourceData( $resourceHandler, $file, $resourceName, $templateName );
        $resourceData['key-data'] = "file:" . $file;
        $key = md5( $resourceData['key-data'] );
        $extraParameters = array();

        // Disable caching/compiling while fetchin the resource
        // It will be restored afterwards
        $isCachingAllowed = $this->IsCachingAllowed;
        $this->IsCachingAllowed = false;

        $resourceHandler->handleResource( $this, $resourceData, eZTemplate::RESOURCE_FETCH, $extraParameters );

        // Restore previous caching flag
        $this->IsCachingAllowed = $isCachingAllowed;

        $root =& $resourceData['root-node'];
        $root = array( eZTemplate::NODE_ROOT, false );
        $templateText = $resourceData["text"];
        $rootNamespace = '';
        $this->parse( $templateText, $root, $rootNamespace, $resourceData );
        if ( eZTemplate::isDebugEnabled() )
        {
            $this->appendDebugNodes( $root, $resourceData );
        }

        $result = !$this->hasErrors() and !$this->hasWarnings();
        if ( $returnResourceData )
        {
            $resourceData['result'] = $result;
            return $resourceData;
        }
        return $result;
    }

    /*!
     Compiles the template file \a $file and returns \c true if the compilation was OK.
     \param $returnResourceData If \c true then the returned value will be the resourcedata structure
     \sa validateTemplateFile(), fetch()
    */
    function compileTemplateFile( $file, $returnResourceData = false )
    {
        $this->resetErrorLog();

        if ( !file_exists( $file ) )
            return false;
        $resourceHandler = $this->resourceFor( $file, $resourceName, $templateName );
        if ( !$resourceHandler )
            return false;
        $resourceData = $this->resourceData( $resourceHandler, $file, $resourceName, $templateName );
        $resourceData['key-data'] = "file:" . $file;
        $key = md5( $resourceData['key-data'] );
        $extraParameters = array();
        $resourceHandler->handleResource( $this, $resourceData, eZTemplate::RESOURCE_FETCH, $extraParameters );

        $isCompiled = false;
        if ( isset( $resourceData['compiled-template'] ) )
            $isCompiled = $resourceData['compiled-template'];

        if ( !$isCompiled )
        {
            $root =& $resourceData['root-node'];
            $root = array( eZTemplate::NODE_ROOT, false );
            $templateText = $resourceData["text"];
            $rootNamespace = '';
            $this->parse( $templateText, $root, $rootNamespace, $resourceData );
            if ( eZTemplate::isDebugEnabled() )
            {
                $this->appendDebugNodes( $root, $resourceData );
            }

            $result = eZTemplateCompiler::compileTemplate( $this, $key, $resourceData );
        }
        else
        {
            $result = true;
        }

        if ( $returnResourceData )
        {
            $resourceData['result'] = $result;
            return $resourceData;
        }
        return $result;
    }

    function compileTemplate( &$resourceData, &$extraParameters )
    {
        $resourceObject = $resourceData['handler'];
        if ( !$resourceObject )
            return false;
        $keyData = $resourceData['key-data'];
        $uri = $resourceData['uri'];
        $resourceName = $resourceData['resource'];
        $templatePath = $resourceData['template-name'];
        return $resourceObject->compileTemplate( $this, $keyData, $uri, $resourceName, $templatePath, $extraParameters, $resourceData );
    }

    function executeCompiledTemplate( &$resourceData, &$textElements, $rootNamespace, $currentNamespace, &$extraParameters )
    {
        $resourceObject = $resourceData['handler'];
        if ( !$resourceObject )
            return false;
        $keyData = $resourceData['key-data'];
        $uri = $resourceData['uri'];
        $resourceName = $resourceData['resource'];
        $templatePath = $resourceData['template-name'];
        $timestamp = $resourceData['time-stamp'];
        return $resourceObject->executeCompiledTemplate( $this, $textElements,
                                                         $keyData, $uri, $resourceData, $templatePath,
                                                         $extraParameters, $timestamp,
                                                         $rootNamespace, $currentNamespace );
    }

    /*!
     Returns the resource object for URI $uri. If a resource type is specified
     in the URI it is extracted and set in $res. The template name is set in $template
     without any resource specifier. To specify a resource the name and a ":" is
     prepended to the URI, for instance file:my.tpl.
     If no resource type is found the URI the default resource handler is used.
    */
    function resourceFor( $uri, &$res, &$template )
    {
        $args = explode( ":", $uri );
        if ( isset( $args[1] ) )
        {
            $res = $args[0];
            $template = $args[1];
        }
        else
            $template = $uri;
        if ( eZTemplate::isDebugEnabled() )
        {
            eZDebug::writeNotice( "eZTemplate: Loading template \"$template\" with resource \"$res\"" );
        }
        if ( isset( $this->Resources[$res] ) and is_object( $this->Resources[$res] ) )
        {
            return $this->Resources[$res];
        }
        return $this->DefaultResource;
    }

    /*!
     \return The resource handler object for resource name \a $resourceName.
     \sa resourceFor
    */
    function resourceHandler( $resourceName )
    {
        if ( isset( $this->Resources[$resourceName] ) &&
             is_object( $this->Resources[$resourceName] ) )
        {
            return $this->Resources[$resourceName];
        }
        return $this->DefaultResource;
    }

    function hasChildren( &$function, $functionName )
    {
        $hasChildren = $function->hasChildren();
        if ( is_array( $hasChildren ) )
            return $hasChildren[$functionName];
        else
            return $hasChildren;
     }

    /*!
     Returns the empty variable type.
    */
    function emptyVariable()
    {
        return array( "type" => "null" );
    }

    /*!
     \static
    */
    function mergeNamespace( $rootNamespace, $additionalNamespace )
    {
        $namespace = $rootNamespace;
        if ( $namespace == '' )
            $namespace = $additionalNamespace;
        else if ( $additionalNamespace != '' )
            $namespace = "$namespace:$additionalNamespace";
        return $namespace;
    }

    /*!
     Returns the actual value of a template type or null if an unknown type.
    */
    function elementValue( &$dataElements, $rootNamespace, $currentNamespace, $placement = false,
                           $checkExistance = false, $checkForProxy = false )
    {
        /*
         * We use a small dirty hack in this function...
         * To help the caller to determine if the value was a proxy object,
         * we store boolean true to $dataElements['proxy-object-found'] in this case.
         * (it's up to caller to remove this garbage from $dataElements...)
         * This behaviour is enabled by $checkForProxy parameter.
         */

        $value = null;
        if ( !is_array( $dataElements ) )
        {
            $this->error( "elementValue",
                          "Missing array data structure, got " . gettype( $dataElements ) );
            return null;
        }
        foreach ( $dataElements as $dataElement )
        {
            if ( $dataElement === null )
            {
                return null;
            }
            $dataType = $dataElement[0];
            switch ( $dataType )
            {
                case eZTemplate::TYPE_VOID:
                {
                    if ( !$checkExistance )
                        $this->warning( 'elementValue',
                                        'Found void datatype, should not be used' );
                    else
                    {
                        return null;
                    }
                } break;
                case eZTemplate::TYPE_STRING:
                case eZTemplate::TYPE_NUMERIC:
                case eZTemplate::TYPE_IDENTIFIER:
                case eZTemplate::TYPE_BOOLEAN:
                case eZTemplate::TYPE_ARRAY:
                {
                    $value = $dataElement[1];
                } break;
                case eZTemplate::TYPE_VARIABLE:
                {
                    $variableData = $dataElement[1];
                    $variableNamespace = $variableData[0];
                    $variableNamespaceScope = $variableData[1];
                    $variableName = $variableData[2];
                    if ( $variableNamespaceScope == eZTemplate::NAMESPACE_SCOPE_GLOBAL )
                        $namespace = $variableNamespace;
                    else if ( $variableNamespaceScope == eZTemplate::NAMESPACE_SCOPE_LOCAL )
                        $namespace = $this->mergeNamespace( $rootNamespace, $variableNamespace );
                    else if ( $variableNamespaceScope == eZTemplate::NAMESPACE_SCOPE_RELATIVE )
                        $namespace = $this->mergeNamespace( $currentNamespace, $variableNamespace );
                    else
                        $namespace = false;
                    if ( $this->hasVariable( $variableName, $namespace ) )
                    {
                        $value = $this->variable( $variableName, $namespace );
                    }
                    else
                    {
                        if ( !$checkExistance )
                            $this->error( '', "Unknown template variable '$variableName' in namespace '$namespace'", $placement );
                        {
                            return null;
                        }
                    }
                } break;
                case eZTemplate::TYPE_ATTRIBUTE:
                {
                    $attributeData = $dataElement[1];
                    $attributeValue = $this->elementValue( $attributeData, $rootNamespace, $currentNamespace, false, $checkExistance );

                    if ( $attributeValue !== null )
                    {
                        if ( !is_numeric( $attributeValue ) and
                             !is_string( $attributeValue ) and
                             !is_bool( $attributeValue ) )
                        {
                            if ( !$checkExistance )
                                $this->error( "",
                                              "Cannot use type " . gettype( $attributeValue ) . " for attribute lookup", $placement );
                            {
                                return null;
                            }
                        }
                        if ( is_array( $value ) )
                        {
                            if ( array_key_exists( $attributeValue, $value ) )
                            {
                                $value = $value[$attributeValue];
                            }
                            else
                            {
                                if ( !$checkExistance )
                                {
                                    $arrayAttributeList = array_keys( $value );
                                    $arrayCount = count( $arrayAttributeList );
                                    $errorMessage = "No such attribute for array($arrayCount): $attributeValue";
                                    $chooseText = "Choose one of following: ";
                                    $errorMessage .= "\n$chooseText";
                                    $errorMessage .= $this->expandAttributes( $arrayAttributeList, $chooseText, 25 );
                                    $this->error( "",
                                                  $errorMessage, $placement );
                                }
                                return null;
                            }
                        }
                        else if ( is_object( $value ) )
                        {
                            if ( method_exists( $value, "attribute" ) and
                                 method_exists( $value, "hasattribute" ) )
                            {
                                if ( $value->hasAttribute( $attributeValue ) )
                                {
                                    $value = $value->attribute( $attributeValue );
                                }
                                else
                                {
                                    if ( !$checkExistance )
                                    {
                                        $objectAttributeList = array();
                                        if ( method_exists( $value, 'attributes' ) )
                                            $objectAttributeList = $value->attributes();
                                        $objectClass= get_class( $value );
                                        $errorMessage = "No such attribute for object($objectClass): $attributeValue";
                                        $chooseText = "Choose one of following: ";
                                        $errorMessage .= "\n$chooseText";
                                        $errorMessage .= $this->expandAttributes( $objectAttributeList, $chooseText, 25 );
                                        $this->error( "",
                                                      $errorMessage, $placement );
                                    }
                                    return null;
                                }
                            }
                            else
                            {
                                if ( !$checkExistance )
                                    $this->error( "",
                                                  "Cannot retrieve attribute of object(" . get_class( $value ) .
                                                  "), no attribute functions available",
                                                  $placement );
                                return null;
                            }
                        }
                        else
                        {
                            if ( !$checkExistance )
                                $this->error( "",
                                              "Cannot retrieve attribute of a " . gettype( $value ),
                                              $placement );
                            return null;
                        }
                    }
                    else
                    {
                        if ( !$checkExistance )
                            $this->error( '',
                                          'Attribute value was null, cannot get attribute',
                                          $placement );
                        return null;
                    }
                } break;
                case eZTemplate::TYPE_OPERATOR:
                {
                    $operatorParameters = $dataElement[1];
                    $operatorName = $operatorParameters[0];
                    $operatorParameters = array_splice( $operatorParameters, 1 );
                    if ( is_object( $value ) and
                         method_exists( $value, 'templateValue' ) )
                    {
                        if ( $checkForProxy )
                            $dataElements['proxy-object-found'] = true;
                        $value = $value->templateValue();
                    }
                    $valueData = array( 'value' => $value );
                    $this->processOperator( $operatorName, $operatorParameters, $rootNamespace, $currentNamespace,
                                            $valueData, $placement, $checkExistance );
                    $value = $valueData['value'];
                } break;
                default:
                {
                    if ( !$checkExistance )
                        $this->error( "elementValue",
                                      "Unknown data type: '$dataType'" );
                    return null;
                }
            }
        }
        if ( is_object( $value ) and
             method_exists( $value, 'templateValue' ) )
        {
            if ( $checkForProxy )
                $dataElements['proxy-object-found'] = true;
            return $value->templateValue();
        }
        return $value;
    }

    function expandAttributes( $attributeList, $chooseText, $maxThreshold, $minThreshold = 1 )
    {
        $errorMessage = '';
        $attributeCount = count( $attributeList );
        if ( $attributeCount < $minThreshold )
            return $errorMessage;
        if ( $attributeCount < $maxThreshold )
        {
            $chooseLength = strlen( $chooseText );
            $attributeText = '';
            $i = 0;
            foreach ( $attributeList as $attributeName )
            {
                if ( $i > 0 )
                    $attributeText .= ",";
                if ( strlen( $attributeText ) > 40 )
                {
                    $attributeText .= "\n";
                    $errorMessage .= $attributeText;
                    $errorMessage .= str_repeat( ' ', $chooseLength );
                    $attributeText = '';
                }
                else if ( $i > 0 )
                    $attributeText .= " ";
                $attributeText .= $attributeName;
                ++$i;
            }
            $errorMessage .= $attributeText;
        }
        return $errorMessage;
    }

    function processOperator( $operatorName, $operatorParameters, $rootNamespace, $currentNamespace,
                              &$valueData, $placement = false, $checkExistance = false )
    {
        $namedParameters = array();
        $operatorParameterDefinition = $this->operatorParameterList( $operatorName );
        $i = 0;
        foreach ( $operatorParameterDefinition as $parameterName => $parameterType )
        {
            if ( !isset( $operatorParameters[$i] ) or
                 !isset( $operatorParameters[$i][0] ) or
                 $operatorParameters[$i][0] == eZTemplate::TYPE_VOID )
            {
                if ( $parameterType["required"] )
                {
                    if ( !$checkExistance )
                        $this->warning( "eZTemplateOperatorElement", "Parameter '$parameterName' ($i) missing",
                                        $placement );
                    $namedParameters[$parameterName] = $parameterType["default"];
                }
                else
                {
                    $namedParameters[$parameterName] = $parameterType["default"];
                }
            }
            else
            {
                $parameterData = $operatorParameters[$i];
                $namedParameters[$parameterName] = $this->elementValue( $parameterData, $rootNamespace, $currentNamespace, false, $checkExistance );
            }
            ++$i;
        }

        if ( isset( $this->Operators[$operatorName] ) )
        {
            if ( is_array( $this->Operators[$operatorName] ) )
            {
                $this->loadAndRegisterOperators( $this->Operators[$operatorName] );
            }

            $op = $this->Operators[$operatorName];

            if ( is_object( $op ) and method_exists( $op, 'modify' ) )
            {
                $value = $valueData['value'];
                if ( eZTemplate::isMethodDebugEnabled() )
                    eZDebug::writeDebug( "START OPERATOR: $operatorName" );
                $op->modify( $this, $operatorName, $operatorParameters, $rootNamespace, $currentNamespace, $value, $namedParameters,
                             $placement );
                if ( eZTemplate::isMethodDebugEnabled() )
                    eZDebug::writeDebug( "END OPERATOR: $operatorName" );
                $valueData['value'] = $value;
            }
            else
                $this->error( '', "Object problem with operator '$operatorName' ",
                              $placement );
        }
        else if ( !$checkExistance )
            $this->warning( "", "Operator '$operatorName' is not registered",
                            $placement );
    }

    /*!
     Return the identifier used for attribute lookup.
    */
    function attributeValue( &$data, $nspace )
    {
        switch ( $data["type"] )
        {
            case "map":
            {
                return $data["content"];
            } break;
            case "index":
            {
                return $data["content"];
            } break;
            case "variable":
            {
                return $this->elementValue( $data["content"], $nspace );
            } break;
            default:
            {
                $this->error( "attributeValue()", "Unknown attribute type: " . $data["type"] );
                return null;
            }
        }
    }

    /*!
     Helper function for creating a displayable text for a variable.
    */
    function variableText( $var, $namespace = "", $attrs = array() )
    {
        $txt = "$";
        if ( $namespace != "" )
            $txt .= "$namespace:";
        $txt .= $var;
        if ( !empty( $attrs ) )
            $txt .= "." . implode( ".", $attrs );
        return $txt;
    }

    /*!
     Returns the named parameter list for the operator $name.
    */
    function operatorParameterList( $name )
    {
        $param_list = array();
        if ( !isset( $this->Operators[$name] ) )
        {
            return $param_list;
        }

        if ( is_array( $this->Operators[$name] ) )
        {
            $this->loadAndRegisterOperators( $this->Operators[$name] );
        }

        $op = $this->Operators[$name];
        if ( isset( $op ) and
             method_exists( $op, "namedparameterlist" ) )
        {
            $param_list = $op->namedParameterList();
            if ( method_exists( $op, "namedparameterperoperator" ) and
                 $op->namedParameterPerOperator() )
            {
                if ( !isset( $param_list[$name] ) )
                    return array();
                $param_list = $param_list[$name];
            }
        }
        return $param_list;
    }

    /*!
     Tries to run the operator $operatorName with parameters $operatorParameters
     on the value $value.
    */
    function doOperator( $element, &$namespace, &$current_nspace, &$value, $operatorName, $operatorParameters, &$named_params )
    {
        if ( is_array( $this->Operators[$operatorName] ) )
        {
            $this->loadAndRegisterOperators( $this->Operators[$operatorName] );
        }
        $op = $this->Operators[$operatorName];
        if ( isset( $op ) )
        {
            $op->modify( $element, $this, $operatorName, $operatorParameters, $namespace, $current_nspace, $value, $named_params );
        }
        else
            $this->warning( "", "Operator \"$operatorName\" is not registered" );
    }

    /*!
     Tries to run the function object $func_obj
    */
    function doFunction( $name, $func_obj, $nspace, $current_nspace )
    {
        $func = $this->Functions[$name];
        if ( is_array( $func ) )
        {
            $this->loadAndRegisterFunctions( $this->Functions[$name] );
            $func = $this->Functions[$name];
        }
        if ( isset( $func ) and
             is_object( $func ) )
        {
            return $func->process( $this, $name, $func_obj, $nspace, $current_nspace );
        }
        else
        {
            $this->warning( "", "Function \"$name\" is not registered" );
            return false;
        }
    }

    /**
     * Sets the template variable $var to the value $val.
     *
     * @param string $var
     * @param string $val
     * @param string $namespace (optional)
     */
    function setVariable( $var, $val, $namespace = '' )
    {
        $this->Variables[$namespace][$var] = $val;
    }

    /**
     * Sets the template variable $var to the value $val by ref
     *
     * @deprecated Since 4.4, have not used references since 3.10
     * @uses eZTemplate::setVariable()
     *
     * @param string $var
     * @param string $val
     * @param string $namespace (optional)
     */
    function setVariableRef( $var, $val, $namespace = '' )
    {
        $this->setVariable( $var, $val, $namespace );
    }

    /**
     * Unsets the template variable $var.
     *
     * @param string $var
     * @param string $namespace (optional)
     */
    function unsetVariable( $var, $namespace = '' )
    {
        if ( isset( $this->Variables[$namespace] ) &&
             array_key_exists( $var, $this->Variables[$namespace] ) )
            unset( $this->Variables[$namespace][$var] );
        else
            $this->warning( "unsetVariable()", "Undefined Variable: \$$namespace:$var, cannot unset" );
    }

    /**
     * Returns true if the variable $var is set in namespace $namespace,
     * if $attrs is supplied all attributes must exist for the function to return true.
     *
     * @param string $var
     * @param string $namespace (optional)
     * @param array $attrs (optional) Deprecated as of 4.4.
     * @return bool
     */
    function hasVariable( $var, $namespace = '', $attrs = null )
    {
        $exists = ( isset( $this->Variables[$namespace] ) &&
                    array_key_exists( $var, $this->Variables[$namespace] ) );
        if ( $exists && $attrs !== null && !empty( $attrs ) )
        {
            eZDebug::writeStrict( '$attrs parameter is deprecated as of 4.4', __METHOD__ );
            $ptr =& $this->Variables[$namespace][$var];
            foreach( $attrs as $attr )
            {
                unset( $tmp );
                if ( is_object( $ptr ) )
                {
                    if ( $ptr->hasAttribute( $attr ) )
                        $tmp = $ptr->attribute( $attr );
                    else
                        return false;
                }
                else if ( is_array( $ptr ) )
                {
                    if ( array_key_exists( $attr, $ptr ) )
                        $tmp =& $ptr[$attr];
                    else
                        return false;
                }
                else
                {
                    return false;
                }
                unset( $ptr );
                $ptr =& $tmp;
            }
        }
        return $exists;
    }

    /**
     * Returns the content of the variable $var using namespace $namespace,
     * if $attrs is supplied the result of the attributes is returned.
     *
     * @param string $var
     * @param string $namespace (optional)
     * @param array $attrs (optional) Deprecated as of 4.4
     * @return string|array
     */
    function variable( $var, $namespace = '', $attrs = null )
    {
        $val = null;
        $exists = ( isset( $this->Variables[$namespace] ) &&
                    array_key_exists( $var, $this->Variables[$namespace] ) );
        if ( $exists )
        {
            if ( $attrs !== null && !empty( $attrs ) )
            {
                eZDebug::writeStrict( '$attrs parameter is deprecated as of 4.4', __METHOD__ );
                $element = $this->Variables[$namespace][$var];
                foreach( $attrs as $attr )
                {
                    if ( is_object( $element ) )
                    {
                        if ( $element->hasAttribute( $attr ) )
                        {
                            $element = $element->attribute( $attr );
                        }
                        else
                        {
                            return $val;
                        }
                    }
                    else if ( is_array( $element ) )
                    {
                        if ( array_key_exists( $attr, $element ) )
                        {
                            $val = $element[$attr];
                        }
                        else
                        {
                            return $val;
                        }
                    }
                    else
                    {
                        return $val;
                    }
                    $val = $element;
                }
            }
            else
            {
                $val = $this->Variables[$namespace][$var];
            }
        }
        return $val;
    }

    /*!
     Returns the attribute(s) of the template variable $var,
     $attrs is an array of attribute names to use iteratively for each new variable returned.
    */
    function variableAttribute( $var, $attrs )
    {
        foreach( $attrs as $attr )
        {
            if ( is_object( $var ) )
            {
                if ( $var->hasAttribute( $attr ) )
                {
                    $var = $var->attribute( $attr );
                }
                else
                {
                    return null;
                }
            }
            else if ( is_array( $var ) )
            {
                if ( isset( $var[$attr] ) )
                {
                    $var = $var[$attr];
                }
                else
                {
                    return null;
                }
            }
            else
            {
                return null;
            }
        }
        if ( isset( $var ) )
        {
            return $var;
        }

        return null;
    }

    function appendElement( &$text, $item, $nspace, $name )
    {
        $this->appendElementText( $textElements, $item, $nspace, $name );
        $text .= implode( '', $textElements );
    }

    function appendElementText( &$textElements, $item, $nspace, $name )
    {
        if ( !is_array( $textElements ) )
            $textElements = array();
        if ( is_object( $item ) and
             method_exists( $item, 'templateValue' ) )
        {
            $item = $item->templateValue();
            $textElements[] = "$item";
        }
        else if ( is_object( $item ) )
        {
            $hasTemplateData = false;
            if ( method_exists( $item, 'templateData' ) )
            {
                $templateData = $item->templateData();
                if ( is_array( $templateData ) and
                     isset( $templateData['type'] ) )
                {
                    if ( $templateData['type'] == 'template' and
                         isset( $templateData['uri'] ) and
                         isset( $templateData['template_variable_name'] ) )
                    {
                        $templateURI =& $templateData['uri'];
                        $templateVariableName =& $templateData['template_variable_name'];
                        $templateText = '';
                        $this->setVariable( $templateVariableName, $item, $name );
                        eZTemplateIncludeFunction::handleInclude( $textElements, $templateURI, $this, $nspace, $name );
                        $hasTemplateData = true;
                    }
                }
            }
            if ( !$hasTemplateData )
                $textElements[] = method_exists( $item, '__toString' ) ? (string)$item : 'Object(' . get_class( $item ) . ')';
        }
        else
            $textElements[] = "$item";
        return $textElements;
    }

    /*!
     Creates some text nodes before and after the children of \a $root.
     It will extract the current filename and uri and create some XHTML
     comments and inline text.
     \sa isXHTMLCodeIncluded
    */
    function appendDebugNodes( &$root, &$resourceData )
    {
        $path = $resourceData['template-filename'];
        $uri = $resourceData['uri'];
        $preText = "\n<!-- START: including template: $path ($uri) -->\n";
        if ( eZTemplate::isXHTMLCodeIncluded() )
            $preText .= "<p class=\"small\">$path</p><br/>\n";
        $postText = "\n<!-- STOP: including template: $path ($uri) -->\n";
        $root[1] = array_merge( array( eZTemplateNodeTool::createTextNode( $preText ) ), $root[1] );
        $root[1][] = eZTemplateNodeTool::createTextNode( $postText );
    }

    /*!
     Registers the functions supplied by the object $functionObject.
     The object must have a function called functionList()
     which returns an array of functions this object handles.
     If the object has a function called attributeList()
     it is used for registering function attributes.
     The function returns an associative array with each key being
     the name of the function and the value being a boolean.
     If the boolean is true the function will have children.
    */
    function registerFunctions( &$functionObject )
    {
        $this->registerFunctionsInternal( $functionObject );
    }

    function registerAutoloadFunctions( $functionDefinition )
    {
        if ( ( ( isset( $functionDefinition['function'] ) ||
                 isset( $functionDefinition['class'] ) ) &&
               ( isset( $functionDefinition['function_names_function'] ) ||
                 isset( $functionDefinition['function_names'] ) ) ) )
        {
            if ( isset( $functionDefinition['function_names_function'] ) )
            {
                $functionNamesFunction = $functionDefinition['function_names_function'];
                if ( !function_exists( $functionNamesFunction ) )
                {
                    $this->error( 'registerFunctions', "Cannot register function definition, missing function names function '$functionNamesFunction'" );
                    return;
                }
                $functionNames = $functionNamesFunction();
            }
            else
                $functionNames = $functionDefinition['function_names'];
            foreach ( $functionNames as $functionName )
            {
                $this->Functions[$functionName] = $functionDefinition;
            }
            if ( isset( $functionDefinition['function_attributes'] ) )
            {
                foreach ( $functionDefinition['function_attributes'] as $functionAttributeName )
                {
                    $this->FunctionAttributes[$functionAttributeName] = $functionDefinition;
                }
            }
        }
        else
            $this->error( 'registerFunctions', 'Cannot register function definition, missing data' );
    }

    function loadAndRegisterFunctions( $functionDefinition )
    {
        eZDebug::accumulatorStart( 'template_register_function', 'template_total', 'Template load and register function' );
        $functionObject = null;
        if ( isset( $functionDefinition['function'] ) )
        {
            $function = $functionDefinition['function'];
            if ( function_exists( $function ) )
                $functionObject = $function();
        }
        else
        {
            if ( !class_exists( $functionDefinition['class'], false )
                    && isset( $functionDefinition['script'] ) )
            {
                include_once( $functionDefinition['script'] );
            }
            $class = $functionDefinition['class'];
            if ( class_exists( $class ) )
                $functionObject = new $class();
        }
        eZDebug::accumulatorStop( 'template_register_function' );
        if ( is_object( $functionObject ) )
        {
            $this->registerFunctionsInternal( $functionObject, true );
            return true;
        }
        return false;
    }

    /*!
     \private
    */
    function registerFunctionsInternal( $functionObject, $debug = false )
    {
        if ( !is_object( $functionObject ) or
             !method_exists( $functionObject, 'functionList' ) )
            return false;
        foreach ( $functionObject->functionList() as $functionName )
        {
            $this->Functions[$functionName] = $functionObject;
        }
        if ( method_exists( $functionObject, "attributeList" ) )
        {
            $functionAttributes = $functionObject->attributeList();
            foreach ( $functionAttributes as $attributeName => $hasChildren )
            {
                $this->FunctionAttributes[$attributeName] = $hasChildren;
            }
        }
        return true;
    }

    /*!
     Registers the function $func_name to be bound to object $func_obj.
     If the object has a function called attributeList()
     it is used for registering function attributes.
     The function returns an associative array with each key being
     the name of the function and the value being a boolean.
     If the boolean is true the function will have children.
    */
    function registerFunction( $func_name, $func_obj )
    {
        $this->Functions[$func_name] = $func_obj;
        if ( method_exists( $func_obj, "attributeList" ) )
        {
            $attrs = $func_obj->attributeList();
            while ( list( $attr_name, $has_children ) = each( $attrs ) )
            {
                $this->FunctionAttributes[$attr_name] = $has_children;
            }
        }
    }

    /*!
     Registers a new literal tag in which the tag will be transformed into
     a text element.
    */
    function registerLiteral( $func_name )
    {
        $this->Literals[$func_name] = true;
    }

    /*!
     Removes the literal tag $func_name.
    */
    function unregisterLiteral( $func_name )
    {
        unset( $this->Literals[$func_name] );
    }

    function registerAutoloadOperators( $operatorDefinition )
    {
        if ( ( ( isset( $operatorDefinition['function'] ) ||
                 isset( $operatorDefinition['class'] ) ) &&
               ( isset( $operatorDefinition['operator_names_function'] ) ||
                 isset( $operatorDefinition['operator_names'] ) ) ) )
        {
            if ( isset( $operatorDefinition['operator_names_function'] ) )
            {
                $operatorNamesFunction = $operatorDefinition['operator_names_function'];
                if ( !function_exists( $operatorNamesFunction ) )
                {
                    $this->error( 'registerOperators', "Cannot register operator definition, missing operator names function '$operatorNamesFunction'" );
                    return;
                }
                $operatorNames = $operatorNamesFunction();
            }
            else
                $operatorNames = $operatorDefinition['operator_names'];
            foreach ( $operatorNames as $operatorName )
            {
                $this->Operators[$operatorName] = $operatorDefinition;
            }
        }
        else
            $this->error( 'registerOperators', 'Cannot register operator definition, missing data' );
    }

    function loadAndRegisterOperators( $operatorDefinition )
    {
        $operatorObject = null;
        if ( isset( $operatorDefinition['function'] ) )
        {
            $function = $operatorDefinition['function'];
            if ( function_exists( $function ) )
                $operatorObject = $function();
        }
        else
        {
            $class = $operatorDefinition['class'];
            if ( !class_exists( $class, false ) && isset( $operatorDefinition['script'] ) )
            {
                include_once( $operatorDefinition['script'] );
            }
            if ( class_exists( $class ) )
            {
                if ( isset( $operatorDefinition['class_parameter'] ) )
                    $operatorObject = new $class( $operatorDefinition['class_parameter'] );
                else
                    $operatorObject = new $class();
            }
        }
        if ( is_object( $operatorObject ) )
        {
            $this->registerOperatorsInternal( $operatorObject, true );
            return true;
        }
        return false;
    }

    /*!
     Registers the operators supplied by the object $operatorObject.
     The function operatorList() must return an array of operator names.
    */
    function registerOperators( &$operatorObject )
    {
        $this->registerOperatorsInternal( $operatorObject );
    }

    function registerOperatorsInternal( $operatorObject, $debug = false )
    {
        if ( !is_object( $operatorObject ) or
             !method_exists( $operatorObject, 'operatorList' ) )
            return false;
        foreach( $operatorObject->operatorList() as $operatorName )
        {
            $this->Operators[$operatorName] = $operatorObject;
        }
    }

    /*!
     Registers the operator $op_name to use the object $op_obj.
    */
    function registerOperator( $op_name, $op_obj )
    {
        $this->Operators[$op_name] = $op_obj;
    }

    /*!
     Unregisters the operator $op_name.
    */
    function unregisterOperator( $op_name )
    {
        if ( is_array( $op_name ) )
        {
            foreach ( $op_name as $op )
            {
                $this->unregisterOperator( $op_name );
            }
        }
        else if ( isset( $this->Operators ) )
            unset( $this->Operators[$op_name] );
        else
            $this->warning( "unregisterOpearator()", "Operator $op_name is not registered, cannot unregister" );
    }

    /*!
     Not implemented yet.
    */
    function registerFilter()
    {
    }

    /*!
     Registers a new resource object $res.
     The resource object take care of fetching templates using an URI.
    */
    function registerResource( $res )
    {
        if ( is_object( $res ) )
            $this->Resources[$res->resourceName()] =& $res;
        else
            $this->warning( "registerResource()", "Supplied argument is not a resource object" );
    }

    /*!
     Unregisters the resource $res_name.
    */
    function unregisterResource( $res_name )
    {
        if ( is_array( $res_name ) )
        {
            foreach ( $res_name as $res )
            {
                $this->unregisterResource( $res );
            }
        }
        else if ( isset( $this->Resources[$res_name] ) )
            unset( $this->Resources[$res_name] );
        else
            $this->warning( "unregisterResource()", "Resource $res_name is not registered, cannot unregister" );
    }

    /*!
     Sets whether detail output is used or not.
     Detail output is useful for debug output where you want to examine the template
     and the output text.
    */
    function setShowDetails( $show )
    {
        $this->ShowDetails = $show;
    }

    /*!
     Outputs a warning about the parameter $param missing for function/operator $name.
    */
    function missingParameter( $name, $param )
    {
        $this->warning( $name, "Missing parameter $param" );
    }

    /*!
     Outputs a warning about the parameter count being to high for function/operator $name.
    */
    function extraParameters( $name, $count, $maxCount )
    {
        $this->warning( $name, "Passed $count parameters but correct count is $maxCount" );
    }

    /*!
     Outputs a warning about the variable $var being undefined.
    */
    function undefinedVariable( $name, $var )
    {
        $this->warning( $name, "Undefined variable: $var" );
    }

    /*!
     Outputs an error about the template function $func_name being undefined.
    */
    function undefinedFunction( $func_name )
    {
        $this->error( "", "Undefined function: $func_name" );
    }

    /*!
     Creates a string for the placement information and returns it.
     \note The placement information can either be in indexed or associative
    */
    function placementText( $placement = false )
    {
        $placementText = false;
        if ( $placement !== false )
        {
            if ( isset( $placement['start'] ) and
                 isset( $placement['stop'] ) and
                 isset( $placement['templatefile'] ) )
            {
                $line = $placement['start']['line'];
                $column = $placement['start']['column'];
                $templateFile = $placement['templatefile'];
            }
            else
            {
                $line = $placement[0][0];
                $column = $placement[0][1];
                $templateFile = $placement[2];
            }

            $placementText = " @ $templateFile:$line" . "[$column]";
        }
        return $placementText;
    }

    /*!
     Displays a warning for the function/operator $name and text $txt.
    */
    function warning( $name, $txt, $placement = false )
    {
        $this->WarningLog[] = array( 'name' => $name,
                                     'text' => $txt,
                                     'placement' => $placement );

        if ( !is_string( $placement ) )
            $placementText = $this->placementText( $placement );
        else
            $placementText = $placement;
        $placementText = $this->placementText( $placement );
        if ( $name != "" )
            eZDebug::writeWarning( $txt, "eZTemplate:$name" . $placementText );
        else
            eZDebug::writeWarning( $txt, "eZTemplate" . $placementText );
    }

    /*!
     Displays an error for the function/operator $name and text $txt.
    */
    function error( $name, $txt, $placement = false )
    {
        $this->ErrorLog[] = array( 'name' => $name,
                                   'text' => $txt,
                                   'placement' => $placement );

        if ( !is_string( $placement ) )
            $placementText = $this->placementText( $placement );
        else
            $placementText = $placement;
        if ( $name != "" )
            $nameText = "eZTemplate:$name";
        else
            $nameText = "eZTemplate";
        eZDebug::writeError( $txt, $nameText . $placementText );
        $hasAppendWarning =& $GLOBALS['eZTemplateHasAppendWarning'];
        $ini = $this->ini();
        if ( $ini->variable( 'ControlSettings', 'DisplayWarnings' ) == 'enabled' )
        {
            if ( !isset( $hasAppendWarning ) or
                 !$hasAppendWarning )
            {
                if ( function_exists( 'eZAppendWarningItem' ) )
                {
                    eZAppendWarningItem( array( 'error' => array( 'type' => 'template',
                                                                  'number' => eZTemplate::FILE_ERRORS ),
                                                'text' => ezpI18n::tr( 'lib/eztemplate', 'Some template errors occurred, see debug for more information.' ) ) );
                    $hasAppendWarning = true;
                }
            }
        }
    }


    function operatorInputSupported( $operatorName )
    {
    }

    /*!
     Sets the original text for uri $uri to $text.
    */
    function setIncludeText( $uri, $text )
    {
        $this->IncludeText[$uri] = $text;
    }

    /*!
     Sets the output for uri $uri to $output.
    */
    function setIncludeOutput( $uri, $output )
    {
        $this->IncludeOutput[$uri] = $output;
    }

    /*!
     \return the path list which is used for autoloading functions and operators.
    */
    function autoloadPathList()
    {
        return $this->AutoloadPathList;
    }

    /*!
     Sets the path list for autoloading.
    */
    function setAutoloadPathList( $pathList )
    {
        $this->AutoloadPathList = $pathList;
    }

    /*!
     Looks trough the pathes specified in autoloadPathList() and fetches autoload
     definition files used for autoloading functions and operators.
    */
    function autoload()
    {
        $pathList = $this->autoloadPathList();
        foreach ( $pathList as $path )
        {
            $autoloadFile = $path . '/eztemplateautoload.php';
            if ( file_exists( $autoloadFile ) )
            {
                unset( $eZTemplateOperatorArray );
                unset( $eZTemplateFunctionArray );
                include( $autoloadFile );
                if ( isset( $eZTemplateOperatorArray ) and
                     is_array( $eZTemplateOperatorArray ) )
                {
                    foreach ( $eZTemplateOperatorArray as $operatorDefinition )
                    {
                        $this->registerAutoloadOperators( $operatorDefinition );
                    }
                }
                if ( isset( $eZTemplateFunctionArray ) and
                     is_array( $eZTemplateFunctionArray ) )
                {
                    foreach ( $eZTemplateFunctionArray as $functionDefinition )
                    {
                        $this->registerAutoloadFunctions( $functionDefinition );
                    }
                }
            }
        }
    }

    /*!
     Resets all template variables.
    */
    function resetVariables()
    {
        $this->Variables = array();
    }

    /*!
     Resets all template functions and operators by calling the resetFunction and resetOperator
     on all elements that supports it.
    */
    function resetElements()
    {
        foreach ( $this->Functions as $functionName => $functionObject )
        {
            if ( is_object( $functionObject ) and
                 method_exists( $functionObject, 'resetFunction' ) )
            {
                $functionObject->resetFunction( $functionName );
            }
        }

        foreach ( $this->Operators as  $operatorName => $operatorObject )
        {
            if ( is_object( $operatorObject ) and
                 method_exists( $operatorObject, 'resetOperator' ) )
            {
                $operatorObject->resetOperator( $operatorName );
            }
        }
    }

    /*!
     Resets all template variables, functions, operators and error counts.
    */
    function reset()
    {
        $this->resetVariables();
        $this->resetElements();
        $this->IsCachingAllowed = true;

        $this->resetErrorLog();

        $this->TemplatesUsageStatistics = array();
        $this->TemplateFetchList = array();
    }

    /*!
      \return The number of errors that occured with the last fetch
      \sa hasErrors()
    */
    function errorCount()
    {
        return count( $this->ErrorLog );
    }

    /*!
      \return \ true if errors occured with the last fetch.
      \sa errorCount()
    */
    function hasErrors()
    {
        return $this->errorCount() > 0;
    }

    /*!
     \return error log.
     \sa errorCount()
    */
    function errorLog()
    {
        return $this->ErrorLog;
    }

    /*!
      \return The number of warnings that occured with the last fetch
      \sa hasWarnings()
    */
    function warningCount()
    {
        return count( $this->WarningLog );
    }

    /*!
      \return \ true if warnings occured with the last fetch.
      \sa warningCount()
    */
    function hasWarnings()
    {
        return $this->warningCount() > 0;
    }

    /*!
     \return waring log.
     \sa warningCount()
    */
    function warningLog()
    {
        return $this->WarningLog;
    }

    /**
     * Returns a shared instance of the eZTemplate class.
     *
     * @return eZTemplate
     */
    public static function instance()
    {
        if ( self::$instance === null )
        {
            self::$instance = new eZTemplate();
        }
        return self::$instance;
    }

    /**
     * Returns a shared instance of the eZTemplate class with
     * default settings applied, like:
     * - Autoload operators loaded
     * - Debug mode set
     * - eZTemplateDesignResource::instance registered
     *
     * @since 4.3
     * @return eZTemplate
     */
    public static function factory()
    {
        if ( self::$factory === false )
        {
            $instance = self::instance();

            $ini = eZINI::instance();
            if ( $ini->variable( 'TemplateSettings', 'Debug' ) == 'enabled' )
                eZTemplate::setIsDebugEnabled( true );

            $compatAutoLoadPath = $ini->variableArray( 'TemplateSettings', 'AutoloadPath' );
            $autoLoadPathList   = $ini->variable( 'TemplateSettings', 'AutoloadPathList' );

            $extensionAutoloadPath = $ini->variable( 'TemplateSettings', 'ExtensionAutoloadPath' );
            $extensionPathList     = eZExtension::expandedPathList( $extensionAutoloadPath, 'autoloads' );

            $autoLoadPathList = array_unique( array_merge( $compatAutoLoadPath, $autoLoadPathList, $extensionPathList ) );

            $instance->setAutoloadPathList( $autoLoadPathList );
            $instance->autoload();

            $instance->registerResource( eZTemplateDesignResource::instance() );
            self::$factory = true;
        }
        return self::instance();
    }

    /**
     * Reset shared instance of the eZTemplate class and factory flag
     * as used by {@see eZTemplate::instance()} and {@see eZTemplate::factory()}
     *
     * @since 4.3
     */
    public static function resetInstance()
    {
        self::$instance = null;
        self::$factory  = false;
    }

    /**
     * Returns the eZINI object instance for the template.ini file.
     *
     * @return eZINI
     */
    public function ini()
    {
        return eZINI::instance( "template.ini" );
    }

    /*!
     \static
     \return true if special XHTML code should be included before the included template file.
             This code will display the template filename in the browser but will eventually
             break the design.
    */
    static function isXHTMLCodeIncluded()
    {
        if ( !isset( $GLOBALS['eZTemplateDebugXHTMLCodeEnabled'] ) )
        {
            $ini = eZINI::instance();
            $GLOBALS['eZTemplateDebugXHTMLCodeEnabled'] = $ini->variable( 'TemplateSettings', 'ShowXHTMLCode' ) == 'enabled';
        }
        return $GLOBALS['eZTemplateDebugXHTMLCodeEnabled'];
    }

    /*!
     \static
     \return \c true if debug output of template functions and operators should be enabled.
    */
    static function isMethodDebugEnabled()
    {
        if ( !isset( $GLOBALS['eZTemplateDebugMethodEnabled'] ) )
        {
            $ini = eZINI::instance();
            $GLOBALS['eZTemplateDebugMethodEnabled'] = $ini->variable( 'TemplateSettings', 'ShowMethodDebug' ) == 'enabled';
        }
        return $GLOBALS['eZTemplateDebugMethodEnabled'];
    }

    /*!
     \static
     \return true if debugging of internals is enabled, this will display
     which files are loaded and when cache files are created.
      Set the option with setIsDebugEnabled().
    */
    static function isDebugEnabled()
    {
        if ( !isset( $GLOBALS['eZTemplateDebugInternalsEnabled'] ) )
             $GLOBALS['eZTemplateDebugInternalsEnabled'] = eZTemplate::DEBUG_INTERNALS;
        return $GLOBALS['eZTemplateDebugInternalsEnabled'];
    }

    /*!
     \static
     Sets whether internal debugging is enabled or not.
    */
    static function setIsDebugEnabled( $debug )
    {
        $GLOBALS['eZTemplateDebugInternalsEnabled'] = $debug;
    }

    /*!
      \return \c true if caching is allowed (default) or \c false otherwise.
              This also affects template compiling.
      \sa setIsCachingAllowed
    */
    function isCachingAllowed()
    {
        return $this->IsCachingAllowed;
    }

    /*!
      Sets whether caching/compiling is allowed or not. This is useful
      if you need to make sure templates are parsed and processed
      without any caching mechanisms.
      \note The default is to allow caching.
      \sa isCachingAllowed
    */
    function setIsCachingAllowed( $allowed )
    {
        $this->IsCachingAllowed = $allowed;
    }

    /*!
     \static
     \return \c true if templates usage statistics should be enabled.
    */
    static function isTemplatesUsageStatisticsEnabled()
    {
        if ( !isset( $GLOBALS['eZTemplateDebugTemplatesUsageStatisticsEnabled'] ) )
        {
            $ini = eZINI::instance();
            $GLOBALS['eZTemplateDebugTemplatesUsageStatisticsEnabled'] = $ini->variable( 'TemplateSettings', 'ShowUsedTemplates' ) == 'enabled';
        }
        return ( $GLOBALS['eZTemplateDebugTemplatesUsageStatisticsEnabled'] );
    }

    /*!
     \static
     Sets whether templates usage statistics enabled or not.
     \return \c true if templates usage statistics was enabled, otherwise \c false.
    */
    function setIsTemplatesUsageStatisticsEnabled( $enabled )
    {
        $wasEnabled = false;
        if( isset( $GLOBALS['eZTemplateDebugTemplatesUsageStatisticsEnabled'] ) )
            $wasEnabled = $GLOBALS['eZTemplateDebugTemplatesUsageStatisticsEnabled'];

        $GLOBALS['eZTemplateDebugTemplatesUsageStatisticsEnabled'] = $enabled;
        return $wasEnabled;
    }

    /*!
     \static
     Checks settings and if 'ShowUsedTemplates' is enabled appends template info to stats.
    */
    function appendTemplateToStatisticsIfNeeded( &$templateName, &$templateFileName )
    {
        if ( eZTemplate::isTemplatesUsageStatisticsEnabled() )
            eZTemplate::appendTemplateToStatistics( $templateName, $templateFileName );
    }

    /*!
     \static
     Appends template info to stats.
    */
    function appendTemplateToStatistics( $templateName, $templateFileName )
    {
        $actualTemplateName = preg_replace( "#^[\w/]+templates/#", '', $templateFileName );
        $requestedTemplateName = preg_replace( "#^[\w/]+templates/#", '', $templateName );

        $tpl = eZTemplate::instance();
        $needToAppend = true;

        // don't add template info if it is a duplicate of previous.
        $statsSize = count( $tpl->TemplatesUsageStatistics );
        if ( $statsSize > 0 )
        {
            $lastTemplateInfo = $tpl->TemplatesUsageStatistics[$statsSize-1];
            if ( $lastTemplateInfo['actual-template-name'] === $actualTemplateName &&
                 $lastTemplateInfo['requested-template-name'] === $requestedTemplateName &&
                 $lastTemplateInfo['template-filename'] === $templateFileName )
            {
                $needToAppend = false;
            }
        }

        if ( $needToAppend )
        {
            $templateInfo = array( 'actual-template-name' => $actualTemplateName,
                                   'requested-template-name' => $requestedTemplateName,
                                   'template-filename' => $templateFileName );

            $tpl->TemplatesUsageStatistics[] = $templateInfo;
        }
    }

    /*!
     Appends template info for current fetch.
    */
    function appendTemplateFetch( $actualTemplateName )
    {
        $this->TemplateFetchList[] = $actualTemplateName;
        $this->TemplateFetchList = array_unique( $this->TemplateFetchList );
    }

    /*!
     Reset error and warning logs
    */
    function resetErrorLog()
    {
        $this->ErrorLog = array();
        $this->WarningLog = array();
    }

    /*!
     \static
     Returns template usage statistics
    */
    static function templatesUsageStatistics()
    {
        $tpl = eZTemplate::instance();
        return $tpl->TemplatesUsageStatistics;
    }

    /*!
     Returns template list for the last fetch.
    */
    function templateFetchList()
    {
        return $this->TemplateFetchList;
    }

    /*!
     Set template compilation test mode.

     \param true, will set template compilation in test mode ( no disc writes ).
            false, will compile templates to disc
    */
    function setCompileTest( $val )
    {
        $this->TestCompile = $val;
    }

    /*!
     Get if template session is test compile
    */
    function testCompile()
    {
        return $this->TestCompile;
    }

    /// \privatesection
    /// Associative array of resource objects
    public $Resources;
    /// Reference to the default resource object
    public $DefaultResource;
    /// The original template text
    public $Text;
    /// Included texts, usually performed by custom functions
    public $IncludeText;
    /// Included outputs, usually performed by custom functions
    public $IncludeOutput;
    /// The timestamp of the template when it was last modified
    public $TimeStamp;
    /// The left delimiter used for parsing
    public $LDelim;
    /// The right delimiter used for parsing
    public $RDelim;

    /// The resulting object tree of the template
    public $Tree;
    /// An associative array of template variables
    public $Variables;
    /*!
     Last element of this stack contains names of
     all variables created in the innermost template, for them
     to be destroyed after the template execution finishes.
     */
    public $LocalVariablesNamesStack;
    // Reference to the last element of $LocalVariablesNamesStack.
    public $CurrentLocalVariablesNames;
    /// An associative array of operators
    public $Operators;
    /// An associative array of functions
    public $Functions;
    /// An associative array of function attributes
    public $FunctionAttributes;
    /// An associative array of literal tags
    public $Literals;
    /// True if output details is to be shown
    public $ShowDetails = false;
    /// \c true if caching is allowed
    public $IsCachingAllowed;

    /// Array containing all errors occured during a fetch
    public $ErrorLog;
    /// Array containing all warnings occured during a fetch
    public $WarningLog;

    public $AutoloadPathList;
    /// include level
    public $Level = 0;
    public $MaxLevel = 40;

    /// A list of templates used by a rendered page
    public $TemplatesUsageStatistics;

    // counter to make unique names for {foreach} loop variables in com
    public $ForeachCounter;
    public $ForCounter;
    public $WhileCounter;
    public $DoCounter;
    public $ElseifCounter;

    // Flag for setting compilation in test mode
    public $TestCompile;

    /**
     * Singelton instance of eZTemplate used by {@see eZTemplate::instance()}
     * Reset with {@see eZTemplate::resetInstance()}
     *
     * @var null|eZTemplate
     */
    protected static $instance;

    /**
     * Factory flag as used by {@see eZTemplate::factory()}
     * Reset with {@see eZTemplate::resetInstance()}
     *
     * @var bool
     */
    protected static $factory = false;

//     public $CurrentRelatedResource;
//     public $CurrentRelatedTemplateName;
}

?>
Back to Top