@@ -515,6 +515,7 @@ protected function compileChild($child, $out) {
515515 break ;
516516 case "assign " :
517517 list (,$ name , $ value ) = $ child ;
518+
518519 if ($ name [0 ] == "var " ) {
519520 $ isDefault = !empty ($ child [3 ]);
520521 if (!$ isDefault || $ this ->get ($ name [1 ], true ) === true ) {
@@ -533,6 +534,7 @@ protected function compileChild($child, $out) {
533534 }
534535
535536 $ compiledValue = $ this ->compileValue ($ value );
537+
536538 $ out ->lines [] = $ this ->formatter ->property (
537539 $ this ->compileValue ($ name ),
538540 $ compiledValue );
@@ -1100,6 +1102,10 @@ protected function compileValue($value) {
11001102 case "number " :
11011103 return round ($ value [1 ], self ::$ numberPrecision ) . $ value [2 ];
11021104 case "string " :
1105+ // Check if the string contains a dollar
1106+ if (is_array ($ value [2 ]) && $ value [2 ][0 ] && strpos ($ value [2 ][0 ], '$ ' ) !== FALSE ) {
1107+ $ value [2 ][0 ] = $ this ->replaceVariableInString ($ value [2 ][0 ]);
1108+ }
11031109 return $ value [1 ] . $ this ->compileStringContent ($ value ) . $ value [1 ];
11041110 case "function " :
11051111 $ args = !empty ($ value [2 ]) ? $ this ->compileValue ($ value [2 ]) : "" ;
@@ -1110,6 +1116,13 @@ protected function compileValue($value) {
11101116
11111117 list (, $ delim , $ items ) = $ value ;
11121118
1119+ if (is_array ($ items [0 ])
1120+ && $ items [0 ][0 ] === 'string '
1121+ && is_array ($ items [0 ][0 ][2 ])
1122+ && $ items [0 ][0 ][2 ][0 ][2 ] == 'opacity=$opacity ' ) {
1123+ die;
1124+ }
1125+
11131126 $ filtered = array ();
11141127 foreach ($ items as $ item ) {
11151128 if ($ item [0 ] == "null " ) continue ;
@@ -1151,6 +1164,50 @@ protected function compileValue($value) {
11511164 }
11521165 }
11531166
1167+ /**
1168+ * Find and replace variables in the given input string
1169+ * @param string $input
1170+ * @return string Returns the input string with the variable replaced
1171+ */
1172+ protected function replaceVariableInString ($ input ) {
1173+ if (!is_string ($ input ) || strpos ($ input , '$ ' ) === FALSE ) {
1174+ return $ input ;
1175+ }
1176+ $ matches = array ();
1177+ if (!preg_match_all ('!\$[a-zA-Z0-9]+! ' , $ input , $ matches )) {
1178+ return $ input ;
1179+ }
1180+
1181+ $ output = $ input ;
1182+ $ matches = $ matches [0 ];
1183+ $ matches = array_unique ($ matches );
1184+ foreach ($ matches as $ variable ) {
1185+ $ variable = trim ($ variable );
1186+ if (!$ variable || $ variable === '$ ' ) {
1187+ continue ;
1188+ }
1189+ // Strip the leading $
1190+ $ variableIdentifier = substr ($ variable , 1 );
1191+
1192+ $ value = $ this ->get ($ variableIdentifier );
1193+ if (is_array ($ value )) {
1194+ // Output numbers correctly
1195+ if ('number ' === $ value [0 ]) {
1196+ $ value = $ this ->normalizeNumber ($ value );
1197+ }
1198+ $ value = $ value [1 ];
1199+ }
1200+ #$this->pd($value, '!\\' . $variable . '\\b!');
1201+
1202+ // Stricter
1203+ // $output = preg_replace('!\\' . $variable . '\\b!', $value, $output);
1204+
1205+ // Faster
1206+ $ output = str_replace ($ variable , $ value , $ output );
1207+ }
1208+ return $ output ;
1209+ }
1210+
11541211 protected function compileStringContent ($ string ) {
11551212 $ parts = array ();
11561213 foreach ($ string [2 ] as $ part ) {
@@ -2287,6 +2344,17 @@ protected function lib_comparable($args) {
22872344 return $ number1 [2 ] == $ number2 [2 ] || $ number1 [2 ] == "" || $ number2 [2 ] == "" ;
22882345 }
22892346
2347+ /**
2348+ * Dumps a given variable (or the given variables) wrapped into a 'pre' tag.
2349+ * @var mixed $var1
2350+ */
2351+ public function pd ($ var1 = '__iresults_pd_noValue ' ) {
2352+ $ args = func_get_args ();
2353+ if (class_exists ('Tx_Iresults ' )) {
2354+ call_user_func_array (array ('Tx_Iresults ' , 'pd ' ), $ args );
2355+ }
2356+ }
2357+
22902358 static protected $ cssColors = array (
22912359 'aliceblue ' => '240,248,255 ' ,
22922360 'antiquewhite ' => '250,235,215 ' ,
@@ -3808,6 +3876,17 @@ protected function flattenList($value) {
38083876 }
38093877 return $ value ;
38103878 }
3879+
3880+ /**
3881+ * Dumps a given variable (or the given variables) wrapped into a 'pre' tag.
3882+ * @var mixed $var1
3883+ */
3884+ public function pd ($ var1 = '__iresults_pd_noValue ' ) {
3885+ $ args = func_get_args ();
3886+ if (class_exists ('Tx_Iresults ' )) {
3887+ call_user_func_array (array ('Tx_Iresults ' , 'pd ' ), $ args );
3888+ }
3889+ }
38113890}
38123891
38133892/**
0 commit comments