@@ -167,7 +167,7 @@ function getCurrentTemplate() {
167
167
return System \Core \View :: getInstance ()->template ();
168
168
}
169
169
170
- function getUrlTemplate ($ url ) {
170
+ function getUrlRoute ($ url ) {
171
171
$ urlData = \Vvveb \System \Routes::getUrlData ($ url );
172
172
173
173
return $ urlData ;
@@ -957,7 +957,7 @@ function getTemplateList($theme = null, $skip = []) {
957
957
}
958
958
$ name = $ title = str_replace ('.html ' , '' , $ filename );
959
959
$ description = '' ;
960
- $ name = ! empty ($ folder ) ? "$ folder- $ name " : $ name ;
960
+ $ name = ( ! empty ($ folder) && $ folder != ' / ' ) ? "$ folder- $ name " : $ name ;
961
961
962
962
if (isset ($ friendlyNames [$ name ])) {
963
963
if (isset ($ friendlyNames [$ name ]['description ' ])) {
@@ -1024,7 +1024,7 @@ function dd(...$variables) {
1024
1024
echo highlight_string ("<?php \n" . var_export ($ variable , true ), true );
1025
1025
}
1026
1026
1027
- die ();
1027
+ die (0 );
1028
1028
}
1029
1029
1030
1030
function encrypt ($ key , $ value , $ cipher = 'aes-256-gcm ' , $ digest = 'sha256 ' ) {
@@ -1779,45 +1779,47 @@ function array2xml($array, $xml = false) {
1779
1779
$ i = 0 ;
1780
1780
$ start = 0 ;
1781
1781
1782
- while (($ start = strpos ($ key , '@@ ' , $ start ))) {
1783
- $ i ++;
1784
- $ start += 2 ;
1785
- $ end = (int )strpos ($ key ,' ' , $ start );
1786
- $ name = substr ($ key , $ start , $ end ? $ end - $ start : null );
1782
+ if ($ key ) {
1783
+ while (($ start = strpos ($ key , '@@ ' , $ start ))) {
1784
+ $ i ++;
1785
+ $ start += 2 ;
1786
+ $ end = (int )strpos ($ key ,' ' , $ start );
1787
+ $ name = substr ($ key , $ start , $ end ? $ end - $ start : null );
1788
+
1789
+ if ($ end == 0 ) {
1790
+ $ start += strlen ($ name );
1791
+ } else {
1792
+ $ start = (int )$ end ;
1793
+ }
1787
1794
1788
- if ($ end == 0 ) {
1789
- $ start += strlen ( $ name );
1790
- } else {
1791
- $ start = ( int ) $ end ;
1795
+ if ($ name ) {
1796
+ $ name = explode ( ' = ' , $ name );
1797
+ $ attributes [ $ name [ 0 ]] = trim ( $ name [ 1 ] ?? '' , '\' " ' );
1798
+ }
1792
1799
}
1793
1800
1794
- if ($ name ) {
1795
- $ name = explode ('= ' , $ name );
1796
- $ attributes [$ name [0 ]] = trim ($ name [1 ] ?? '' , '\'" ' );
1797
- }
1801
+ $ key = strstr ($ key , ' @@ ' , true ) ?: $ key ;
1798
1802
}
1799
-
1800
- $ key = strstr ($ key , ' @@ ' , true ) ?: $ key ;
1801
1803
};
1802
1804
1803
1805
$ processAttr ($ key );
1804
1806
1805
- if (is_array ($ value )) {
1807
+ if (is_array ($ value ) || is_object ( $ value ) ) {
1806
1808
$ node = $ xml ->addChild ($ key );
1807
1809
1808
1810
if ($ attributes ) {
1809
1811
foreach ($ attributes as $ key => $ val ) {
1810
- $ node ->addAttribute ($ key , $ val );
1812
+ $ node ->addAttribute ($ key , htmlentities ( $ val) );
1811
1813
}
1812
1814
}
1813
1815
array2xml ($ value , $ node );
1814
1816
} else {
1815
1817
if (substr_compare ($ key , '--xmlattr ' , -9 , 9 ) === 0 ) {
1816
1818
$ key = substr ($ key , 0 , -9 );
1817
- $ xml ->addAttribute ($ key , $ value );
1819
+ $ xml ->addAttribute ($ key , htmlentities ( $ value) );
1818
1820
} else {
1819
1821
$ processAttr ($ value );
1820
- $ node = $ xml ->addChild ($ key , $ value );
1822
+ $ node = $ xml ->addChild ($ key , htmlentities ( $ value) );
1821
1823
1822
1824
if ($ attributes ) {
1823
1825
foreach ($ attributes as $ key => $ val ) {
@@ -1837,9 +1839,34 @@ function removeJsonComments($json) {
1837
1839
return $ json ;
1838
1840
}
1839
1841
1842
+ function encodeXmlName ($ name ) {
1843
+ $ len = strlen ($ name );
1844
+ $ newName = '' ;
1845
+
1846
+ for ($ i = 0 ; $ i < $ len ; $ i ++) {
1847
+ $ char = $ name [$ i ];
1848
+ $ code = ord ($ char );
1849
+
1850
+ // = @ _ - . A-Z a-z 0-9
1851
+ if (! ($ code == 32 || $ code == 34 || $ code == 61 || $ code == 64 || $ code == 95 || $ code == 45 || $ code == 46 || ($ code <= 90 && $ code >= 65 ) || ($ code <= 122 && $ code >= 97 ) || ($ code <= 57 && $ code >= 48 ))) {
1852
+ $ char = '_x ' . sprintf ('%03d ' , $ code ) . '_ ' ;
1853
+ }
1854
+
1855
+ $ newName .= $ char ;
1856
+ }
1857
+
1858
+ return $ newName ;
1859
+ }
1860
+
1861
+ function decodeXmlName ($ name ) {
1862
+ return preg_replace_callback ('/_x(\d+)_/ ' ,function ($ matches ) {
1863
+ return chr (ltrim ($ matches [1 ], '0 ' ));
1864
+ }, $ name );
1865
+ }
1866
+
1840
1867
function prepareJson ($ array ) {
1841
1868
if (! is_array ($ array )) {
1842
- return ;
1869
+ // return;
1843
1870
}
1844
1871
$ helper = [];
1845
1872
@@ -1859,6 +1886,32 @@ function prepareJson($array) {
1859
1886
if (strpos ($ key , '@ ' )) {
1860
1887
}
1861
1888
1889
+ //keep empty arrays as array type
1890
+ if (is_object ($ value ) && ! $ value ) {
1891
+ $ key .= '--object ' ;
1892
+ } else {
1893
+ if (is_array ($ value ) && ! $ value ) {
1894
+ $ key .= '--array ' ;
1895
+ }
1896
+ }
1897
+
1898
+ //keep boolean type
1899
+ if (is_bool ($ value )) {
1900
+ $ key .= '--boolean ' ;
1901
+ }
1902
+
1903
+ //keep int type
1904
+ if (is_int ($ value )) {
1905
+ $ key .= '--int ' ;
1906
+ }
1907
+
1908
+ //keep null type
1909
+ if ($ value === null ) {
1910
+ $ key .= '--null ' ;
1911
+ }
1912
+
1913
+ $ key = encodeXmlName (trim ($ key ));
1914
+
1862
1915
$ helper [$ key ] = is_array ($ value ) ? prepareJson ($ value ) : $ value ;
1863
1916
}
1864
1917
@@ -1877,6 +1930,37 @@ function reconstructJson(&$array, $removeAttrs = false) {
1877
1930
continue ;
1878
1931
}
1879
1932
1933
+ $ key = decodeXmlName ($ key );
1934
+
1935
+ if (substr_compare ($ key , '--array ' , -7 , 7 ) === 0 ) {
1936
+ $ key = substr ($ key , 0 , -7 );
1937
+ $ value = (array )$ value ;
1938
+ } else {
1939
+ if (! $ value ) {
1940
+ $ value = '' ;
1941
+ }
1942
+ }
1943
+
1944
+ if (substr_compare ($ key , '--boolean ' , -9 , 9 ) === 0 ) {
1945
+ $ key = substr ($ key , 0 , -9 );
1946
+ $ value = (boolean )$ value ;
1947
+ }
1948
+
1949
+ if (substr_compare ($ key , '--null ' , -6 , 6 ) === 0 ) {
1950
+ $ key = substr ($ key , 0 , -6 );
1951
+ $ value = null ;
1952
+ }
1953
+
1954
+ if (substr_compare ($ key , '--int ' , -5 , 5 ) === 0 ) {
1955
+ $ key = substr ($ key , 0 , -5 );
1956
+ $ value = (int )$ value ;
1957
+ }
1958
+
1959
+ if (substr_compare ($ key , '--object ' , -8 , 8 ) === 0 ) {
1960
+ $ key = substr ($ key , 0 , -8 );
1961
+ $ value = (object )$ value ;
1962
+ }
1963
+
1880
1964
if (substr_compare ($ key , 'n-- ' , 0 , 3 ) === 0 ) {
1881
1965
$ newkey = substr ($ key , 3 );
1882
1966
0 commit comments