From 0ada4f129c9ae6ad6db5965421f9b358cbbcf642 Mon Sep 17 00:00:00 2001 From: f0o Date: Mon, 26 Jan 2015 08:11:28 +0000 Subject: [PATCH] Fix variable declaration --- alerts.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/alerts.php b/alerts.php index 28840bca1..9a4e4db48 100755 --- a/alerts.php +++ b/alerts.php @@ -217,7 +217,7 @@ function FormatAlertTpl($tpl,$obj) { } else { continue; } - $cond = preg_replace('/%(\w+)/i','\$obj["$1"]', substr($orig,$o,-1)); + $cond = trim(populate(substr($orig,$o,-1),false)); $native = $native[0].$cond.$native[1]; $parsed = str_replace($orig,$native,$parsed); unset($cond, $o, $orig, $native); @@ -317,10 +317,11 @@ function RunJail($code,$obj) { /** * Populate variables - * @param string Text with variables + * @param string $txt Text with variables + * @param bool $wrap Wrap variable for text-usage (default: true) * @return string */ -function populate($txt) { +function populate($txt,$wrap=true) { preg_match_all('/%([\w\.]+)/', $txt, $m); foreach( $m[1] as $tmp ) { $orig = $tmp; @@ -335,7 +336,10 @@ function populate($txt) { } else { $pre = '$obj'; } - $rep = "{".$pre."['".str_replace('.',"']['",$tmp)."']}"; + $rep = $pre."['".str_replace('.',"']['",$tmp)."']"; + if( $wrap ) { + $rep = "{".$rep."}"; + } } $txt = str_replace("%".$orig,$rep,$txt); }