@@ -1778,29 +1778,10 @@ private function loadFromExternalHtml($val, $node) {
1778
1778
return $ elements ;
1779
1779
}
1780
1780
1781
- function loadHtmlTemplate ($ filename ) {
1782
- $ extension = strtolower (trim (substr ($ filename , -4 ), '. ' ));
1783
- $ this ->documentType = $ extension ;
1784
-
1785
- if (strpos ($ filename , DS ) === false ) {
1786
- $ filename = $ this ->htmlPath . $ filename ;
1787
- }
1788
-
1789
- if (! ($ html = @file_get_contents ($ filename ))) {
1790
- Vvveb \logError ("can't load template $ filename " );
1791
- $ this ->debug ->log ('LOAD ' , '<b>ERROR</b> ' . $ filename );
1792
-
1793
- return false ;
1794
- }
1795
-
1796
- $ this ->htmlSourceFile = $ filename ;
1797
-
1798
- $ this ->debug ->log ('LOAD ' , $ filename );
1799
-
1781
+ function loadHtml ($ html ) {
1800
1782
if (VTPL_DONT_ALLOW_PHP ) {
1801
1783
$ html = $ this ->removePhp ($ html );
1802
1784
}
1803
-
1804
1785
//replace script tags with placeholders to preserve formatting.
1805
1786
1806
1787
//preg_match_all("@<script[^>]*>.*?script>@s", $html, $this->_scripts);
@@ -1832,7 +1813,7 @@ function loadHtmlTemplate($filename) {
1832
1813
@$ this ->document ->loadHTML ($ html , LIBXML_NOERROR );
1833
1814
} else {
1834
1815
//convert json
1835
- if ($ extension == 'json ' ) {
1816
+ if ($ this -> documentType == 'json ' ) {
1836
1817
//remove json comments from line start
1837
1818
$ html = Vvveb \removeJsonComments ($ html );
1838
1819
$ json = json_decode ($ html , true );
@@ -1895,6 +1876,27 @@ function loadHtmlTemplate($filename) {
1895
1876
return $ errors ;
1896
1877
}
1897
1878
1879
+ function loadHtmlTemplate ($ filename ) {
1880
+ $ extension = strtolower (trim (substr ($ filename , -4 ), '. ' ));
1881
+ $ this ->documentType = $ extension ;
1882
+
1883
+ if (strpos ($ filename , DS ) === false ) {
1884
+ $ filename = $ this ->htmlPath . $ filename ;
1885
+ }
1886
+
1887
+ if (! ($ html = @file_get_contents ($ filename ))) {
1888
+ Vvveb \logError ("can't load template $ filename " );
1889
+ $ this ->debug ->log ('LOAD ' , '<b>ERROR</b> ' . $ filename );
1890
+
1891
+ return false ;
1892
+ }
1893
+
1894
+ $ this ->htmlSourceFile = $ filename ;
1895
+ $ this ->debug ->log ('LOAD ' , $ filename );
1896
+
1897
+ $ this ->loadHtml ($ html );
1898
+ }
1899
+
1898
1900
private function setMultiLanguageText ($ currentNode ) {
1899
1901
if (! $ currentNode || ! $ currentNode ->childNodes || $ currentNode ->childNodes ->length == 0 ) {
1900
1902
return ;
@@ -1978,8 +1980,6 @@ function ($matches) {
1978
1980
$ before = $ currentNode ->childNodes ->length ;
1979
1981
1980
1982
if ($ trimmed != '' ) {
1981
- $ trimmed = addcslashes ($ trimmed , "' " );
1982
-
1983
1983
if (strlen ($ trimmed ) < 1024 ) {
1984
1984
/*
1985
1985
$php = '<_script language="php"><![CDATA[ echo ' . $this->translationFunction . '(\'' . $trimmed . '\');]]></_script>';
@@ -1988,7 +1988,7 @@ function ($matches) {
1988
1988
$f = $this->document->createDocumentFragment();
1989
1989
$f->appendXML($php);
1990
1990
*/
1991
- $ c = $ this ->document ->createCDATASection ('echo ' . $ this ->translationFunction . '( \'' . $ trimmed . '\'); ' );
1991
+ $ c = $ this ->document ->createCDATASection ('echo ' . $ this ->translationFunction . '( \'' . addcslashes ( $ trimmed, " ' " ) . '\'); ' );
1992
1992
$ f = $ this ->document ->createElement ('_script ' );
1993
1993
$ f ->setAttribute ('language ' , 'php ' );
1994
1994
$ f ->appendChild ($ c );
@@ -2134,7 +2134,8 @@ function ($matches) use ($self) {
2134
2134
if (isset ($ matches [2 ])) {
2135
2135
$ modifier = $ matches [2 ];
2136
2136
}
2137
- $ variable = Vvveb \dotToArrayKey ($ matches [1 ]);
2137
+ $ variable = str_replace ('$this. ' , '$this-> ' , $ matches [1 ]);
2138
+ $ variable = Vvveb \dotToArrayKey ($ variable );
2138
2139
$ template =
2139
2140
"<?php if (isset( $ variable)) {
2140
2141
if (is_array( $ variable)) {
@@ -2171,8 +2172,23 @@ function saveCompiledTemplate($compiledFile) {
2171
2172
2172
2173
if ($ componentNode ) {
2173
2174
$ tmpDom = new DOMDocument ();
2175
+
2176
+ //add before php code if available
2177
+ $ currentNode = $ componentNode ;
2178
+
2179
+ while (($ currentNode = $ currentNode ->previousSibling ) && $ currentNode ->nodeName === '_script ' ) {
2180
+ $ tmpDom ->appendChild ($ tmpDom ->importNode ($ currentNode , true ));
2181
+ }
2182
+
2174
2183
$ tmpDom ->appendChild ($ tmpDom ->importNode ($ componentNode , true ));
2175
2184
2185
+ //add after php code if available
2186
+ $ currentNode = $ componentNode ;
2187
+
2188
+ while (($ currentNode = $ currentNode ->nextSibling ) && $ currentNode ->nodeName === '_script ' ) {
2189
+ $ tmpDom ->appendChild ($ tmpDom ->importNode ($ currentNode , true ));
2190
+ }
2191
+
2176
2192
if ($ this ->documentType == 'html ' ) {
2177
2193
$ html = $ tmpDom ->saveHTML ();
2178
2194
} else {
0 commit comments