@@ -59,7 +59,7 @@ class Vtpl {
59
59
60
60
private $ removeVattrs = false ;
61
61
62
- private $ isHTML = true ;
62
+ private $ documentType = ' html ' ;
63
63
64
64
private $ checkSyntax = true ;
65
65
@@ -157,6 +157,10 @@ function removeVattrs($flag = true) {
157
157
$ this ->removeVattrs = $ flag ;
158
158
}
159
159
160
+ function getDocumentType () {
161
+ return $ this ->documentType ;
162
+ }
163
+
160
164
function addCommand ($ selector , $ command = false ) {
161
165
if ($ selector ) {
162
166
$ this ->template .= "\n $ selector " ;
@@ -1099,7 +1103,7 @@ function ($matches) use ($node) {
1099
1103
$ value = $ node ->getAttribute ($ matches [1 ]);
1100
1104
$ this ->debug ->log ('VTPL_ATTRIBUTE ' , '<b>ATTRIB NAME</b> ' . $ matches [1 ]);
1101
1105
//expand shorthand expression (*) to regex ([a-zA-Z_0-9-]+)
1102
- $ regex = str_replace ('(*) ' , '([a-zA-Z_0-9-]+) ' , $ matches [1 ]);
1106
+ $ regex = str_replace ('(*) ' , '([a-zA-Z_0-9-\. ]+) ' , $ matches [1 ]);
1103
1107
1104
1108
foreach ($ node ->attributes as $ name => $ attrNode ) {
1105
1109
if (preg_match ("@ $ regex@ " , $ name , $ _match )) {
@@ -1187,7 +1191,7 @@ private function innerHTML($nodeList, $html = false) {
1187
1191
$ doc ->appendChild ($ doc ->importNode ($ child , true ));
1188
1192
}
1189
1193
1190
- if ($ this ->isHTML ) {
1194
+ if ($ this ->documentType == ' html ' ) {
1191
1195
return $ doc ->saveHTML ();
1192
1196
} else {
1193
1197
return $ doc ->saveXML ();
@@ -1257,7 +1261,7 @@ private function outerHTML(&$nodeList, $html = false) {
1257
1261
$ node ->parentNode ->replaceChild ($ doc ->importNode ($ child , true ), $ node );
1258
1262
}
1259
1263
1260
- if ($ this ->isHTML ) {
1264
+ if ($ this ->documentType == ' html ' ) {
1261
1265
return $ doc ->saveHTML ();
1262
1266
} else {
1263
1267
return $ doc ->saveXML ();
@@ -1758,7 +1762,7 @@ private function loadFromExternalHtml($val, $node) {
1758
1762
1759
1763
$ document = new DomDocument ();
1760
1764
1761
- if ($ this ->isHTML ) {
1765
+ if ($ this ->documentType == ' html ' ) {
1762
1766
@$ document ->loadHTML ($ html );
1763
1767
} else {
1764
1768
@$ document ->loadXML ($ html );
@@ -1772,7 +1776,8 @@ private function loadFromExternalHtml($val, $node) {
1772
1776
}
1773
1777
1774
1778
function loadHtmlTemplate ($ filename ) {
1775
- $ this ->isHTML = (substr ($ filename , -3 ) != 'xml ' );
1779
+ $ extension = strtolower (trim (substr ($ filename , -4 ), '. ' ));
1780
+ $ this ->documentType = $ extension ;
1776
1781
1777
1782
if (strpos ($ filename , DS ) === false ) {
1778
1783
$ filename = $ this ->htmlPath . $ filename ;
@@ -1819,9 +1824,16 @@ function loadHtmlTemplate($filename) {
1819
1824
$ html = str_replace (array_keys ($ this ->replaceConstants ),array_values ($ this ->replaceConstants ),$ html );
1820
1825
}
1821
1826
1822
- if ($ this ->isHTML ) {
1827
+ if ($ this ->documentType == ' html ' ) {
1823
1828
@$ this ->document ->loadHTML ($ html , LIBXML_NOERROR );
1824
1829
} else {
1830
+ //convert json
1831
+ if ($ extension == 'json ' ) {
1832
+ $ json = json_decode ($ html , true );
1833
+ $ json = Vvveb \prepareJson ($ json );
1834
+ $ xml = Vvveb \array2xml ($ json );
1835
+ $ html = $ xml ;
1836
+ }
1825
1837
@$ this ->document ->loadXML ($ html , LIBXML_NOERROR );
1826
1838
}
1827
1839
@@ -1844,7 +1856,7 @@ function loadHtmlTemplate($filename) {
1844
1856
1845
1857
$ tmpDom = new DomDocument ();
1846
1858
1847
- if ($ this ->isHTML ) {
1859
+ if ($ this ->documentType == ' html ' ) {
1848
1860
@$ tmpDom ->loadHTML ($ this ->componentContent );
1849
1861
} else {
1850
1862
@$ tmpDom ->loadXML ($ this ->componentContent );
@@ -1946,7 +1958,11 @@ function ($matches) {
1946
1958
$ text = \Vvveb \stripExtraSpaces ($ text );
1947
1959
$ trimmed = trim ($ text );
1948
1960
1949
- if (strlen ($ trimmed ) < 2 ) {
1961
+ if (strlen ($ trimmed ) < 2 ||
1962
+ (substr_compare ($ trimmed , '{$ ' , 0 , 2 ) == 0 ) ||
1963
+ (substr_compare ($ trimmed , 'http ' , 0 , 4 ) == 0 ) ||
1964
+ (is_numeric ($ trimmed [0 ]))
1965
+ ) {
1950
1966
continue ;
1951
1967
}
1952
1968
@@ -1966,7 +1982,7 @@ function ($matches) {
1966
1982
$ c = $ this ->document ->createCDATASection ('echo ' . $ this ->translationFunction . '( \'' . $ trimmed . '\'); ' );
1967
1983
$ f = $ this ->document ->createElement ('_script ' );
1968
1984
$ f ->setAttribute ('language ' , 'php ' );
1969
- $ f ->append ($ c );
1985
+ $ f ->appendChild ($ c );
1970
1986
$ node = $ node ->parentNode ->replaceChild ($ f , $ node );
1971
1987
}
1972
1988
//$node->parentNode->replaceChild($f, $node);
@@ -2122,22 +2138,22 @@ function saveCompiledTemplate($compiledFile) {
2122
2138
$ tmpDom = new DOMDocument ();
2123
2139
$ tmpDom ->appendChild ($ tmpDom ->importNode ($ componentNode , true ));
2124
2140
2125
- if ($ this ->isHTML ) {
2141
+ if ($ this ->documentType == ' html ' ) {
2126
2142
$ html = $ tmpDom ->saveHTML ();
2127
2143
} else {
2128
2144
$ html = $ tmpDom ->saveXML ();
2129
2145
}
2130
2146
2131
2147
$ html = trim ($ html );
2132
2148
} else {
2133
- if ($ this ->isHTML ) {
2149
+ if ($ this ->documentType == ' html ' ) {
2134
2150
$ html = $ this ->document ->saveHTML ();
2135
2151
} else {
2136
2152
$ html = $ this ->document ->saveXML ();
2137
2153
}
2138
2154
}
2139
2155
} else {
2140
- if ($ this ->isHTML ) {
2156
+ if ($ this ->documentType == ' html ' ) {
2141
2157
$ html = $ this ->document ->saveHTML ();
2142
2158
} else {
2143
2159
$ html = $ this ->document ->saveXML ();
0 commit comments