Response from server parsed through trim() to avoid trailing/leading whitespaces
[mailer.git] / inc / functions.php
index 25aa0e93360b1355be31ad0aba7a695c05452ee2..5692191704452f620a42d03ab5294cd50a9d96df 100644 (file)
@@ -71,18 +71,15 @@ function OPEN_TABLE($PERCENT = "", $CLASS = "", $ALIGN="left", $VALIGN="", $td_o
 
        // Vertical align is given
        if (!empty($VALIGN))  $OUT .= " valign=\"".$VALIGN."\"";
-       $OUT .= ">
-<TR>
-  <TD";
+       $OUT .= ">\n<TR>\n<TD";
        if (!empty($ALIGN)) $OUT .=" align=\"".$ALIGN."\"";
        $OUT .= " class=\"".$CLASS."\">";
-       OUTPUT_HTML($OUT);
+       OUTPUT_HTML($OUT);
 }
 
 // Close a table (you may want to add some footer stuff here)
 function CLOSE_TABLE($ADD="") {
-       OUTPUT_HTML("  </TD>
-</TR>");
+       OUTPUT_HTML("  </TD>\n</TR>");
        if (!empty($ADD)) OUTPUT_HTML($ADD);
        OUTPUT_HTML("</TABLE>");
 }
@@ -140,9 +137,9 @@ function OUTPUT_HTML($HTML, $NEW_LINE = true) {
                }
 
                // Compile and run finished rendered HTML code
-               while (strpos($OUTPUT, "{!") > 0) {
+               while (strpos($OUTPUT, '{!') > 0) {
                        $eval = "\$OUTPUT = \"" . COMPILE_CODE(addslashes($OUTPUT)) . "\";";
-                       @eval($eval);
+                       eval($eval);
                }
 
                // Output code here, DO NOT REMOVE! ;-)
@@ -154,9 +151,9 @@ function OUTPUT_HTML($HTML, $NEW_LINE = true) {
                }
 
                // Compile and run finished rendered HTML code
-               while (strpos($OUTPUT, "{!") > 0) {
+               while (strpos($OUTPUT, '{!') > 0) {
                        $eval = "\$OUTPUT = \"" . COMPILE_CODE(addslashes($OUTPUT)) . "\";";
-                       @eval($eval);
+                       eval($eval);
                }
 
                // Output code here, DO NOT REMOVE! ;-)
@@ -179,8 +176,7 @@ function OUTPUT_RAW ($HTML) {
 }
 
 // Add a fatal error message to the queue array
-function ADD_FATAL ($message, $extra="")
-{
+function ADD_FATAL ($message, $extra="") {
        global $FATAL;
        if (empty($extra)) {
                // Regular text message to add to $FATAL
@@ -284,12 +280,12 @@ function LOAD_TEMPLATE($template, $return=false, $content="") {
                $tmpl_file = implode("", file($file));
 
                // Replace ' to our own chars to preventing them being quoted
-               while (strpos($tmpl_file, "\'") !== false) { $tmpl_file = str_replace("\'", "{QUOT}", $tmpl_file); }
+               while (strpos($tmpl_file, "\'") !== false) { $tmpl_file = str_replace("\'", '{QUOT}', $tmpl_file); }
 
                // Do we have to compile the code?
                if ((strpos($tmpl_file, "\$") !== false) || (strpos($tmpl_file, '{--') !== false) || (strpos($tmpl_file, '--}') > 0)) {
                        // Okay, compile it!
-                       $tmpl_file = "\$ret=\"".COMPILE_CODE(addslashes($tmpl_file))."\";";
+                       $tmpl_file = "\$ret=\"" . COMPILE_CODE(addslashes($tmpl_file)) . "\";";
                        eval($tmpl_file);
                } else {
                        // Simply return loaded code
@@ -329,7 +325,7 @@ function LOAD_TEMPLATE($template, $return=false, $content="") {
 // Send mail out to an email address
 function SEND_EMAIL($TO, $SUBJECT, $MSG, $HTML='N', $FROM="") {
        // Compile subject line (for POINTS constant etc.)
-       $eval = "\$SUBJECT = \"".COMPILE_CODE(addslashes($SUBJECT))."\";";
+       $eval = "\$SUBJECT = \"" . COMPILE_CODE(addslashes($SUBJECT)) . "\";";
        eval($eval);
        $SUBJECT = html_entity_decode($SUBJECT);
 
@@ -951,11 +947,11 @@ function COMPILE_CODE($code, $simple = false, $constants = true, $full = true) {
        if ($constants) {
                // BEFORE 0.2.1 : Language and data constants
                // WITH 0.2.1+  : Only language constants
-               $code = str_replace("{--", '".', str_replace("--}", '."', $code));
+               $code = str_replace('{--', '".', str_replace('--}', '."', $code));
 
                // BEFORE 0.2.1 : Not used
                // WITH 0.2.1+  : Data constants
-               $code = str_replace("{!", '".', str_replace("!}", '."', $code));
+               $code = str_replace('{!', '".', str_replace("!}", '."', $code));
        }
 
        // Compile QUOT and other non-HTML codes
@@ -965,7 +961,7 @@ function COMPILE_CODE($code, $simple = false, $constants = true, $full = true) {
        }
 
        // But shall I keep simple quotes for later use?
-       if ($simple) $code = str_replace("\'", "{QUOT}", $code);
+       if ($simple) $code = str_replace("\'", '{QUOT}', $code);
 
        // Find $content[bla][blub] entries
        @preg_match_all('/\$(content|DATA)((\[([a-zA-Z0-9-_]+)\])*)/', $code, $matches);
@@ -1152,7 +1148,7 @@ function ADD_SELECTION($type, $DEFAULT, $prefix="", $id="0")
                $OUT .= "      <OPTION value=\"Y\"";
                if ($DEFAULT == 'Y') $OUT .= " selected=\"selected\"";
                $OUT .= ">".YES."</OPTION>
-      <OPTION value=\"N\"";
+                       <OPTION value=\"N\"";
                if ($DEFAULT == 'N') $OUT .= " selected=\"selected\"";
                $OUT .= ">".NO."</OPTION>\n";
                break;
@@ -1210,7 +1206,7 @@ function GEN_RANDOM_CODE($length, $code, $uid, $DATA="")
        if ($len == 0) $len = 10;
 
        // Cut off requested counts of number
-       $return = substr(str_replace('.', '', $rcode), 0, $len);
+       $return = substr(str_replace('.', "", $rcode), 0, $len);
 
        // Done building code
        return $return;
@@ -1683,7 +1679,7 @@ function MXCHANGE_OPEN($script) {
 
        // Read response
        while(!feof($fp)) {
-               $response[] = fgets($fp, 1024);
+               $response[] = trim(fgets($fp, 1024));
        }
 
        // Close socket
@@ -1942,7 +1938,7 @@ function ADD_URL_DATA($URL)
                if ((!empty($_GET['refid'])) && (strpos($URL, "refid=") == 0)) {
                        // Cookie found in URL
                        $ADD .= $BIND."refid=".bigintval($_GET['refid']);
-               } elseif ((GET_EXT_VERSION("sql_patches") != "") && ($_CONFIG['def_refid'] > 0)) {
+               } elseif ((GET_EXT_VERSION("sql_patches") != '') && ($_CONFIG['def_refid'] > 0)) {
                        // Not found! So let's set default here
                        $ADD .= $BIND."refid=".$_CONFIG['def_refid'];
                }
@@ -2050,7 +2046,7 @@ function DISPLAY_PARSING_TIME_FOOTER() {
        );
 
        // Load the template
-       LOAD_TEMPLATE("footer_stats", false, $content);
+       LOAD_TEMPLATE("show_timings", false, $content);
 }
 
 // Unset/set session variables
@@ -2068,7 +2064,7 @@ function set_session ($var, $value) {
                //* DEBUG: */ echo "UNSET:".$var."=".get_session($var)."<br />\n";
                unset($_SESSION[$var]);
                return session_unregister($var);
-       } elseif (("".$value."" != "") && (!isSessionVariableSet($var))) {
+       } elseif (("".$value."" != '') && (!isSessionVariableSet($var))) {
                // Set session
                //* DEBUG: */ echo "SET:".$var."=".$value."<br />\n";
                $_SESSION[$var] =  $value;