Even more rewrites/fixes from EL branch (please report any broken part after you...
[mailer.git] / inc / functions.php
index 0a6f17f48fd9935c595e280ffd2f34aee62cb9b6..eec116f9c7cd0c52b9a87f25ef4dd13ff2a8f696 100644 (file)
@@ -45,7 +45,9 @@ if (!defined('__SECURITY')) {
 // Output HTML code directly or 'render' it. You addionally switch the new-line character off
 function outputHtml ($htmlCode, $newLine = true) {
        // Init output
-       if (!isset($GLOBALS['output'])) $GLOBALS['output'] = '';
+       if (!isset($GLOBALS['output'])) {
+               $GLOBALS['output'] = '';
+       } // END - if
 
        // Transfer username
        $username = getMessage('USERNAME_UNKNOWN');
@@ -134,7 +136,7 @@ function sendHttpHeaders () {
        $now = gmdate('D, d M Y H:i:s') . ' GMT';
 
        // Send HTTP header
-       sendHeader('HTTP/1.1 200');
+       sendHeader('HTTP/1.1 200 OK');
 
        // General headers for no caching
        sendHeader('Expires: ' . $now); // RFC2616 - Section 14.21
@@ -149,19 +151,21 @@ function sendHttpHeaders () {
 // Compiles the final output
 function compileFinalOutput () {
        // Init counter
-       $cnt = '0';
+       $cnt = 0;
 
        // Add page header and footer
        addPageHeaderFooter();
 
        // Compile all out
-       while (((strpos($GLOBALS['output'], '{--') > 0) || (strpos($GLOBALS['output'], '{!') > 0) || (strpos($GLOBALS['output'], '{?') > 0)) && ($cnt < 3)) {
+       while (((strpos($GLOBALS['output'], '{--') !== false) || (strpos($GLOBALS['output'], '{!') !== false) || (strpos($GLOBALS['output'], '{?') !== false) || (strpos($GLOBALS['output'], '{%') !== false)) && ($cnt < 3)) {
                // Init common variables
                $content = array();
                $newContent = '';
 
                // Compile it
-               $eval = "\$newContent = \"".compileCode(escapeQuotes($GLOBALS['output']))."\";";
+               //* DEBUG: */ print '<pre>'.htmlentities($GLOBALS['output']).'</pre>';
+               $eval = '$newContent = "' . compileCode(escapeQuotes($GLOBALS['output'])) . '";';
+               //* DEBUG: */ die('<pre>'.htmlentities($eval).'</pre>');
                eval($eval);
 
                // Was that eval okay?
@@ -169,6 +173,8 @@ function compileFinalOutput () {
                        // Something went wrong!
                        debug_report_bug('Evaluation error:<pre>' . linenumberCode($eval) . '</pre>', false);
                } // END - if
+
+               // Use it again
                $GLOBALS['output'] = $newContent;
 
                // Count round
@@ -785,6 +791,9 @@ function translatePoolType ($type) {
 
 // Translates the american decimal dot into a german comma
 function translateComma ($dotted, $cut = true, $max = '0') {
+       // First, cast all to double, due to PHP changes
+       $dotted = (double) $dotted;
+
        // Default is 3 you can change this in admin area "Misc -> Misc Options"
        if (!isConfigEntrySet('max_comma')) setConfigEntry('max_comma', 3);
 
@@ -1162,30 +1171,30 @@ function addSelectionBox ($type, $default, $prefix = '', $id = '0', $class = 're
 
        if ($type == 'yn') {
                // This is a yes/no selection only!
-               if ($id > 0) $prefix .= "[" . $id."]";
-               $OUT .= "    <select name=\"" . $prefix."\" class=\"" . $class . "\" size=\"1\">\n";
+               if ($id > 0) $prefix .= '[' . $id . ']';
+               $OUT .= '<select name="' . $prefix . '" class="' . $class . '" size="1">';
        } else {
                // Begin with regular selection box here
                if (!empty($prefix)) $prefix .= "_";
                $type2 = $type;
-               if ($id > 0) $type2 .= "[" . $id."]";
-               $OUT .= "    <select name=\"".strtolower($prefix . $type2)."\" class=\"" . $class . "\" size=\"1\">\n";
+               if ($id > 0) $type2 .= '[' . $id . ']';
+               $OUT .= '<select name="' . strtolower($prefix . $type2) . '" class="' . $class . '" size="1">';
        }
 
        switch ($type) {
                case 'day': // Day
                        for ($idx = 1; $idx < 32; $idx++) {
-                               $OUT .= "<option value=\"" . $idx."\"";
+                               $OUT .= '<option value="' . $idx . '"';
                                if ($default == $idx) $OUT .= ' selected="selected"';
-                               $OUT .= ">" . $idx."</option>\n";
+                               $OUT .= '>' . $idx . '</option>';
                        } // END - for
                        break;
 
                case 'month': // Month
-                       foreach ($GLOBALS['month_descr'] as $month => $descr) {
-                               $OUT .= "<option value=\"" . $month."\"";
-                               if ($default == $month) $OUT .= ' selected="selected"';
-                               $OUT .= ">" . $descr."</option>\n";
+                       foreach ($GLOBALS['month_descr'] as $idx => $descr) {
+                               $OUT .= '<option value="' . $idx . '"';
+                               if ($default == $idx) $OUT .= ' selected="selected"';
+                               $OUT .= '>' . $descr . '</option>';
                        } // END - for
                        break;
 
@@ -1194,7 +1203,7 @@ function addSelectionBox ($type, $default, $prefix = '', $id = '0', $class = 're
                        $year = date('Y', time());
 
                        // Use configured min age or fixed?
-                       if ((isExtensionActive('other')) && (getExtensionVersion('other') >= '0.2.1')) {
+                       if (isExtensionInstalledAndNewer('order', '0.2.1')) {
                                // Configured
                                $startYear = $year - getConfig('min_age');
                        } else {
@@ -1208,21 +1217,20 @@ function addSelectionBox ($type, $default, $prefix = '', $id = '0', $class = 're
                        // Check if the default value is larger than minimum and bigger than actual year
                        if (($default > $minYear) && ($default >= $year)) {
                                for ($idx = $year; $idx < ($year + 11); $idx++) {
-                                       $OUT .= "<option value=\"" . $idx."\"";
+                                       $OUT .= '<option value="' . $idx . '"';
                                        if ($default == $idx) $OUT .= ' selected="selected"';
-                                       $OUT .= ">" . $idx."</option>\n";
+                                       $OUT .= '>' . $idx . '</option>';
                                } // END - for
                        } elseif ($default == -1) {
                                // Current year minus 1
-                               for ($idx = $startYear; $idx <= ($year + 1); $idx++)
-                               {
-                                       $OUT .= "<option value=\"" . $idx."\">" . $idx."</option>\n";
-                               }
+                               for ($idx = $startYear; $idx <= ($year + 1); $idx++) {
+                                       $OUT .= '<option value="' . $idx . '">' . $idx . '</option>';
+                               } // END - for
                        } else {
                                // Get current year and subtract the configured minimum age
-                               $OUT .= "<option value=\"".($minYear - 1)."\">&lt;" . $minYear."</option>\n";
+                               $OUT .= '<option value="' . ($minYear - 1) . '">&lt;' . $minYear . '</option>';
                                // Calculate earliest year depending on extension version
-                               if ((isExtensionActive('other')) && (getExtensionVersion('other') >= '0.2.1')) {
+                               if (isExtensionInstalledAndNewer('order', '0.2.1')) {
                                        // Use configured minimum age
                                        $year = date('Y', time()) - getConfig('min_age');
                                } else {
@@ -1232,41 +1240,41 @@ function addSelectionBox ($type, $default, $prefix = '', $id = '0', $class = 're
 
                                // Construct year selection list
                                for ($idx = $minYear; $idx <= $year; $idx++) {
-                                       $OUT .= "<option value=\"" . $idx."\"";
+                                       $OUT .= '<option value="' . $idx . '"';
                                        if ($default == $idx) $OUT .= ' selected="selected"';
-                                       $OUT .= ">" . $idx."</option>\n";
+                                       $OUT .= '>' . $idx . '</option>';
                                } // END - for
                        }
                        break;
 
                case 'sec':
                case 'min':
-                       for ($idx = '0'; $idx < 60; $idx+=5) {
+                       for ($idx = 0; $idx < 60; $idx+=5) {
                                if (strlen($idx) == 1) $idx = '0' . $idx;
-                               $OUT .= "<option value=\"" . $idx."\"";
+                               $OUT .= '<option value="' . $idx . '"';
                                if ($default == $idx) $OUT .= ' selected="selected"';
-                               $OUT .= ">" . $idx."</option>\n";
+                               $OUT .= '>' . $idx . '</option>';
                        } // END - for
                        break;
 
                case 'hour':
-                       for ($idx = '0'; $idx < 24; $idx++) {
+                       for ($idx = 0; $idx < 24; $idx++) {
                                if (strlen($idx) == 1) $idx = '0' . $idx;
-                               $OUT .= "<option value=\"" . $idx."\"";
+                               $OUT .= '<option value="' . $idx . '"';
                                if ($default == $idx) $OUT .= ' selected="selected"';
-                               $OUT .= ">" . $idx."</option>\n";
+                               $OUT .= '>' . $idx . '</option>';
                        } // END - for
                        break;
 
                case 'yn':
-                       $OUT .= "<option value=\"Y\"";
+                       $OUT .= '<option value="Y"';
                        if ($default == 'Y') $OUT .= ' selected="selected"';
-                       $OUT .= ">{--YES--}</option>\n<option value=\"N\"";
+                       $OUT .= '>{--YES--}</option><option value="N"';
                        if ($default != 'Y') $OUT .= ' selected="selected"';
-                       $OUT .= ">{--NO--}</option>\n";
+                       $OUT .= '>{--NO--}</option>';
                        break;
        }
-       $OUT .= "    </select>\n";
+       $OUT .= '</select>';
        return $OUT;
 }
 
@@ -1352,7 +1360,7 @@ function generateImageOrCode ($img_code, $headerSent = true) {
                debug_report_bug('img_code ' . $img_code .' has invalid length. img_code()=' . strlen($img_code) . ' code_length=' . getConfig('code_length'));
        } elseif ($headerSent === false) {
                // Return an HTML code here
-               return "<img src=\"{%url=img.php?code=" . $img_code."%}\" alt=\"Image\" />\n";
+               return '<img src="{%url=img.php?code=' . $img_code . '%}" alt="Image" />';
        }
 
        // Load image
@@ -1365,8 +1373,7 @@ function generateImageOrCode ($img_code, $headerSent = true) {
        // Is it readable?
        if (isFileReadable($img)) {
                // Switch image type
-               switch (getConfig('img_type'))
-               {
+               switch (getConfig('img_type')) {
                        case 'jpg':
                                // Okay, load image and hide all errors
                                $image = imagecreatefromjpeg($img);
@@ -1376,7 +1383,7 @@ function generateImageOrCode ($img_code, $headerSent = true) {
                                // Okay, load image and hide all errors
                                $image = imagecreatefrompng($img);
                                break;
-               }
+               } // END - switch
        } else {
                // Exit function here
                logDebugMessage(__FUNCTION__, __LINE__, sprintf("File for image type %s not found.", getConfig('img_type')));
@@ -1396,7 +1403,7 @@ function generateImageOrCode ($img_code, $headerSent = true) {
        switch (getConfig('img_type')) {
                case 'jpg': imagejpeg($image); break;
                case 'png': imagepng($image);  break;
-       }
+       } // END - switch
 
        // Remove image from memory
        imagedestroy($image);
@@ -1470,137 +1477,137 @@ function createTimeSelections ($timestamp, $prefix = '', $display = '', $align =
                );
        } else {
                // Generate table
-               $OUT  = "<div align=\"" . $align."\">\n";
-               $OUT .= "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" class=\"timebox_table dashed\">\n";
-               $OUT .= "<tr>\n";
+               $OUT  = '<div align="' . $align . '">';
+               $OUT .= '<table border="0" cellspacing="0" cellpadding="0" class="timebox_table dashed">';
+               $OUT .= '<tr>';
 
                if (isInString('Y', $display) || (empty($display))) {
-                       $OUT .= "  <td align=\"center\" class=\"timebox_column bottom\"><div class=\"tiny\">{--_YEARS--}</strong></td>\n";
-               }
+                       $OUT .= '<td align="center" class="timebox_column bottom"><div class="tiny">{--_YEARS--}</strong></td>';
+               } // END - if
 
                if (isInString('M', $display) || (empty($display))) {
-                       $OUT .= "  <td align=\"center\" class=\"timebox_column bottom\"><div class=\"tiny\">{--_MONTHS--}</strong></td>\n";
-               }
+                       $OUT .= '<td align="center" class="timebox_column bottom"><div class="tiny">{--_MONTHS--}</strong></td>';
+               } // END - if
 
                if (isInString('W', $display) || (empty($display))) {
-                       $OUT .= "  <td align=\"center\" class=\"timebox_column bottom\"><div class=\"tiny\">{--_WEEKS--}</strong></td>\n";
-               }
+                       $OUT .= '<td align="center" class="timebox_column bottom"><div class="tiny">{--_WEEKS--}</strong></td>';
+               } // END - if
 
                if (isInString('D', $display) || (empty($display))) {
-                       $OUT .= "  <td align=\"center\" class=\"timebox_column bottom\"><div class=\"tiny\">{--_DAYS--}</strong></td>\n";
-               }
+                       $OUT .= '<td align="center" class="timebox_column bottom"><div class="tiny">{--_DAYS--}</strong></td>';
+               } // END - if
 
                if (isInString('h', $display) || (empty($display))) {
-                       $OUT .= "  <td align=\"center\" class=\"timebox_column bottom\"><div class=\"tiny\">{--_HOURS--}</strong></td>\n";
-               }
+                       $OUT .= '<td align="center" class="timebox_column bottom"><div class="tiny">{--_HOURS--}</strong></td>';
+               } // END - if
 
                if (isInString('m', $display) || (empty($display))) {
-                       $OUT .= "  <td align=\"center\" class=\"timebox_column bottom\"><div class=\"tiny\">{--_MINUTES--}</strong></td>\n";
-               }
+                       $OUT .= '<td align="center" class="timebox_column bottom"><div class="tiny">{--_MINUTES--}</strong></td>';
+               } // END - if
 
                if (isInString('s', $display) || (empty($display))) {
-                       $OUT .= "  <td align=\"center\" class=\"timebox_column bottom\"><div class=\"tiny\">{--_SECONDS--}</strong></td>\n";
-               }
+                       $OUT .= '<td align="center" class="timebox_column bottom"><div class="tiny">{--_SECONDS--}</strong></td>';
+               } // END - if
 
-               $OUT .= "</tr>\n";
-               $OUT .= "<tr>\n";
+               $OUT .= '</tr>';
+               $OUT .= '<tr>';
 
                if (isInString('Y', $display) || (empty($display))) {
                        // Generate year selection
-                       $OUT .= "  <td align=\"center\"><select class=\"mini_select\" name=\"" . $prefix . "_ye\" size=\"1\">\n";
-                       for ($idx = '0'; $idx <= 10; $idx++) {
-                               $OUT .= "    <option class=\"mini_select\" value=\"" . $idx."\"";
+                       $OUT .= '<td align="center"><select class="mini_select" name="' . $prefix . '_ye" size="1">';
+                       for ($idx = 0; $idx <= 10; $idx++) {
+                               $OUT .= '<option class="mini_select" value="' . $idx . '"';
                                if ($idx == $Y) $OUT .= ' selected="selected"';
-                               $OUT .= ">" . $idx."</option>\n";
-                       }
-                       $OUT .= "  </select></td>\n";
+                               $OUT .= '>' . $idx . '</option>';
+                       } // END - for
+                       $OUT .= '</select></td>';
                } else {
                        $OUT .= '<input type="hidden" name="' . $prefix . '_ye" value="0" />';
                }
 
                if (isInString('M', $display) || (empty($display))) {
                        // Generate month selection
-                       $OUT .= "  <td align=\"center\"><select class=\"mini_select\" name=\"" . $prefix . "_mo\" size=\"1\">\n";
-                       for ($idx = '0'; $idx <= 11; $idx++)
-                       {
-                               $OUT .= "  <option class=\"mini_select\" value=\"" . $idx."\"";
+                       $OUT .= '<td align="center"><select class="mini_select" name="' . $prefix . '_mo" size="1">';
+                       for ($idx = 0; $idx <= 11; $idx++) {
+                               $OUT .= '  <option class="mini_select" value="' . $idx . '"';
                                if ($idx == $M) $OUT .= ' selected="selected"';
-                               $OUT .= ">" . $idx."</option>\n";
-                       }
-                       $OUT .= "  </select></td>\n";
+                               $OUT .= '>' . $idx . '</option>';
+                       } // END - for
+                       $OUT .= '</select></td>';
                } else {
                        $OUT .= '<input type="hidden" name="' . $prefix . '_mo" value="0" />';
                }
 
                if (isInString('W', $display) || (empty($display))) {
                        // Generate week selection
-                       $OUT .= "  <td align=\"center\"><select class=\"mini_select\" name=\"" . $prefix . "_we\" size=\"1\">\n";
-                       for ($idx = '0'; $idx <= 4; $idx++) {
-                               $OUT .= "  <option class=\"mini_select\" value=\"" . $idx."\"";
+                       $OUT .= '<td align="center"><select class="mini_select" name="' . $prefix . '_we" size="1">';
+                       for ($idx = 0; $idx <= 4; $idx++) {
+                               $OUT .= '  <option class="mini_select" value="' . $idx . '"';
                                if ($idx == $W) $OUT .= ' selected="selected"';
-                               $OUT .= ">" . $idx."</option>\n";
-                       }
-                       $OUT .= "  </select></td>\n";
+                               $OUT .= '>' . $idx . '</option>';
+                       } // END - for
+                       $OUT .= '</select></td>';
                } else {
                        $OUT .= '<input type="hidden" name="' . $prefix . '_we" value="0" />';
                }
 
                if (isInString('D', $display) || (empty($display))) {
                        // Generate day selection
-                       $OUT .= "  <td align=\"center\"><select class=\"mini_select\" name=\"" . $prefix . "_da\" size=\"1\">\n";
-                       for ($idx = '0'; $idx <= 31; $idx++) {
-                               $OUT .= "  <option class=\"mini_select\" value=\"" . $idx."\"";
+                       $OUT .= '<td align="center"><select class="mini_select" name="' . $prefix . '_da" size="1">';
+                       for ($idx = 0; $idx <= 31; $idx++) {
+                               $OUT .= '  <option class="mini_select" value="' . $idx . '"';
                                if ($idx == $D) $OUT .= ' selected="selected"';
-                               $OUT .= ">" . $idx."</option>\n";
-                       }
-                       $OUT .= "  </select></td>\n";
+                               $OUT .= '>' . $idx . '</option>';
+                       } // END - for
+                       $OUT .= '</select></td>';
                } else {
                        $OUT .= '<input type="hidden" name="' . $prefix . '_da" value="0" />';
                }
 
                if (isInString('h', $display) || (empty($display))) {
                        // Generate hour selection
-                       $OUT .= "  <td align=\"center\"><select class=\"mini_select\" name=\"" . $prefix . "_ho\" size=\"1\">\n";
-                       for ($idx = '0'; $idx <= 23; $idx++)    {
-                               $OUT .= "  <option class=\"mini_select\" value=\"" . $idx."\"";
+                       $OUT .= '<td align="center"><select class="mini_select" name="' . $prefix . '_ho" size="1">';
+                       for ($idx = 0; $idx <= 23; $idx++) {
+                               $OUT .= '  <option class="mini_select" value="' . $idx . '"';
                                if ($idx == $h) $OUT .= ' selected="selected"';
-                               $OUT .= ">" . $idx."</option>\n";
-                       }
-                       $OUT .= "  </select></td>\n";
+                               $OUT .= '>' . $idx . '</option>';
+                       } // END - for
+                       $OUT .= '</select></td>';
                } else {
                        $OUT .= '<input type="hidden" name="' . $prefix . '_ho" value="0" />';
                }
 
                if (isInString('m', $display) || (empty($display))) {
                        // Generate minute selection
-                       $OUT .= "  <td align=\"center\"><select class=\"mini_select\" name=\"" . $prefix . "_mi\" size=\"1\">\n";
-                       for ($idx = '0'; $idx <= 59; $idx++) {
-                               $OUT .= "  <option class=\"mini_select\" value=\"" . $idx."\"";
+                       $OUT .= '<td align="center"><select class="mini_select" name="' . $prefix . '_mi" size="1">';
+                       for ($idx = 0; $idx <= 59; $idx++) {
+                               $OUT .= '  <option class="mini_select" value="' . $idx . '"';
                                if ($idx == $m) $OUT .= ' selected="selected"';
-                               $OUT .= ">" . $idx."</option>\n";
-                       }
-                       $OUT .= "  </select></td>\n";
+                               $OUT .= '>' . $idx . '</option>';
+                       } // END - for
+                       $OUT .= '</select></td>';
                } else {
                        $OUT .= '<input type="hidden" name="' . $prefix . '_mi" value="0" />';
                }
 
                if (isInString('s', $display) || (empty($display))) {
                        // Generate second selection
-                       $OUT .= "  <td align=\"center\"><select class=\"mini_select\" name=\"" . $prefix . "_se\" size=\"1\">\n";
-                       for ($idx = '0'; $idx <= 59; $idx++) {
-                               $OUT .= "  <option class=\"mini_select\" value=\"" . $idx."\"";
+                       $OUT .= '<td align="center"><select class="mini_select" name="' . $prefix . '_se" size="1">';
+                       for ($idx = 0; $idx <= 59; $idx++) {
+                               $OUT .= '  <option class="mini_select" value="' . $idx . '"';
                                if ($idx == $s) $OUT .= ' selected="selected"';
-                               $OUT .= ">" . $idx."</option>\n";
-                       }
-                       $OUT .= "  </select></td>\n";
+                               $OUT .= '>' . $idx . '</option>';
+                       } // END - for
+                       $OUT .= '</select></td>';
                } else {
                        $OUT .= '<input type="hidden" name="' . $prefix . '_se" value="0" />';
                }
-               $OUT .= "</tr>\n";
-               $OUT .= "</table>\n";
-               $OUT .= "</div>\n";
-               // Return generated HTML code
+               $OUT .= '</tr>';
+               $OUT .= '</table>';
+               $OUT .= '</div>';
        }
+
+       // Return generated HTML code
        return $OUT;
 }
 
@@ -1613,22 +1620,31 @@ function createTimestampFromSelections ($prefix, $postData) {
        $SWITCH = '0';
        $TEST = date('Y', time()) / 4;
        $M1   = date('m', time());
+
        // If so and if current time is before 02/29 and estimated time is after 02/29 then add 86400 seconds (one day)
        if ((floor($TEST) == $TEST) && ($M1 == '02') && ($postData[$prefix . '_mo'] > '02'))  $SWITCH = getConfig('ONE_DAY');
+
        // First add years...
        $ret += $postData[$prefix . '_ye'] * (31536000 + $SWITCH);
+
        // Next months...
        $ret += $postData[$prefix . '_mo'] * 2628000;
+
        // Next weeks
        $ret += $postData[$prefix . '_we'] * 604800;
+
        // Next days...
        $ret += $postData[$prefix . '_da'] * 86400;
+
        // Next hours...
        $ret += $postData[$prefix . '_ho'] * 3600;
+
        // Next minutes..
        $ret += $postData[$prefix . '_mi'] * 60;
+
        // And at last seconds...
        $ret += $postData[$prefix . '_se'];
+
        // Return calculated value
        return $ret;
 }
@@ -1641,7 +1657,7 @@ function createFancyTime ($stamp) {
        foreach($data as $k => $v) {
                if ($v > 0) {
                        // Value is greater than 0 "eval" data to return string
-                       eval("\$ret .= \", \".\$v.\" {--_".strtoupper($k)."--}\";");
+                       eval('$ret .= ", ".$v." {--_' . strtoupper($k) . '--}";');
                        break;
                } // END - if
        } // END - foreach
@@ -1652,7 +1668,7 @@ function createFancyTime ($stamp) {
                $ret = substr($ret, 2);
        } else {
                // Zero seconds
-               $ret = "0 {--_SECONDS--}";
+               $ret = '0 {--_SECONDS--}';
        }
 
        // Return fancy time string
@@ -1663,8 +1679,8 @@ function createFancyTime ($stamp) {
 function addEmailNavigation ($PAGES, $offset, $show_form, $colspan, $return=false) {
        $TOP = '';
        if ($show_form === false) {
-               $TOP = " top";
-       }
+               $TOP = ' top';
+       } // END - if
 
        $NAV = '';
        for ($page = 1; $page <= $PAGES; $page++) {
@@ -1731,7 +1747,7 @@ function extractHostnameFromUrl (&$script) {
        if (isInString('/', $host)) $host = substr($host, 0, strpos($host, '/'));
 
        // Generate relative URL
-       //* DEBUG: */ print("SCRIPT=" . $script.'<br />');
+       //* DEBUG: */ print('SCRIPT=' . $script.'<br />');
        if (substr(strtolower($script), 0, 7) == 'http://') {
                // But only if http:// is in front!
                $script = substr($script, (strlen($url) + 7));
@@ -1740,7 +1756,7 @@ function extractHostnameFromUrl (&$script) {
                $script = substr($script, (strlen($url) + 8));
        }
 
-       //* DEBUG: */ print("SCRIPT=" . $script.'<br />');
+       //* DEBUG: */ print('SCRIPT=' . $script.'<br />');
        if (substr($script, 0, 1) == '/') $script = substr($script, 1);
 
        // Return host name
@@ -1779,11 +1795,9 @@ function sendGetRequest ($script, $data = array()) {
        } else {
                $request .= 'User-Agent: ' . getConfig('TITLE') . '/' . getConfig('VERSION') . getConfig('HTTP_EOL');
        }
-       $request .= 'Accept: text/plain;q=0.8' . getConfig('HTTP_EOL');
+       $request .= 'Accept: image/png,image/*;q=0.8,text/plain,text/html,*/*;q=0.5' . getConfig('HTTP_EOL');
        $request .= 'Accept-Charset: UTF-8,*' . getConfig('HTTP_EOL');
-       $request .= 'Cache-Control: no-cache' . getConfig('HTTP_EOL');
-       $request .= 'Content-Type: text/plain' . getConfig('HTTP_EOL');
-       $request .= 'Content-Length: 0' . getConfig('HTTP_EOL');
+       $request .= 'Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0' . getConfig('HTTP_EOL');
        $request .= 'Connection: close' . getConfig('HTTP_EOL');
        $request .= getConfig('HTTP_EOL');
 
@@ -1810,7 +1824,7 @@ function sendPostRequest ($script, $postData) {
        $body = http_build_query($postData, '', '&');
 
        // Generate POST request header
-       $request  = 'POST /' . trim($script) . ' HTTP/1.1' . getConfig('HTTP_EOL');
+       $request  = 'POST /' . trim($script) . ' HTTP/1.0' . getConfig('HTTP_EOL');
        $request .= 'Host: ' . $host . getConfig('HTTP_EOL');
        $request .= 'Referer: ' . getConfig('URL') . '/admin.php' . getConfig('HTTP_EOL');
        $request .= 'User-Agent: ' . getConfig('TITLE') . '/' . getConfig('FULL_VERSION') . getConfig('HTTP_EOL');
@@ -1856,7 +1870,7 @@ function sendRawRequest ($host, $request) {
        $resolver = new HostnameResolver();
 
        // Open connection
-       //* DEBUG: */ die("SCRIPT=" . $script.'<br />');
+       //* DEBUG: */ die('SCRIPT=' . $script.'<br />');
        if ($useProxy === true) {
                // Resolve hostname into IP address
                $ip = $resolver->resolveHostname(compileRawCode(getConfig('proxy_host')));
@@ -1987,7 +2001,7 @@ function setupProxyTunnel ($host, $resource) {
        $response = array('', '', '');
 
        // Generate CONNECT request header
-       $proxyTunnel  = 'CONNECT ' . $host . ':80 HTTP/1.1' . getConfig('HTTP_EOL');
+       $proxyTunnel  = 'CONNECT ' . $host . ':80 HTTP/1.0' . getConfig('HTTP_EOL');
        $proxyTunnel .= 'Host: ' . $host . getConfig('HTTP_EOL');
 
        // Use login data to proxy? (username at least!)
@@ -2106,7 +2120,7 @@ function generateEmailLink ($email, $table = 'admins') {
        if ((isExtensionActive('admins')) && ($table == 'admins')) {
                // Create email link for contacting admin in guest area
                $EMAIL = generateAdminEmailLink($email);
-       } elseif ((isExtensionActive('user')) && (getExtensionVersion('user') >= '0.3.3') && ($table == 'user_data')) {
+       } elseif ((isExtensionInstalledAndNewer('user', '0.3.3')) && ($table == 'user_data')) {
                // Create email link for contacting a member within admin area (or later in other areas, too?)
                $EMAIL = generateUserEmailLink($email, 'admin');
        } elseif ((isExtensionActive('sponsor')) && ($table == 'sponsor_data')) {
@@ -2215,7 +2229,7 @@ function scrambleString($str) {
 
        // Scramble string here
        //* DEBUG: */ outputHtml('***Original=' . $str.'***<br />');
-       for ($idx = '0'; $idx < strlen($str); $idx++) {
+       for ($idx = 0; $idx < strlen($str); $idx++) {
                // Get char on scrambled position
                $char = substr($str, $scrambleNums[$idx], 1);
 
@@ -2242,7 +2256,7 @@ function descrambleString($str) {
        // Begin descrambling
        $orig = str_repeat(' ', 40);
        //* DEBUG: */ outputHtml('+++Scrambled=' . $str.'+++<br />');
-       for ($idx = '0'; $idx < 40; $idx++) {
+       for ($idx = 0; $idx < 40; $idx++) {
                $char = substr($str, $idx, 1);
                $orig = substr_replace($orig, $char, $scrambleNums[$idx], 1);
        } // END - for
@@ -2258,7 +2272,7 @@ function genScrambleString ($len) {
        $scrambleNumbers = array();
 
        // First we need to setup randomized numbers from 0 to 31
-       for ($idx = '0'; $idx < $len; $idx++) {
+       for ($idx = 0; $idx < $len; $idx++) {
                // Generate number
                $rand = mt_rand(0, ($len -1));
 
@@ -2383,9 +2397,10 @@ function displayParsingTime() {
        if ($runTime < 0) $runTime = '0';
 
        // Prepare output
+       // @TODO This can be easily moved out after the merge from EL branch to this is complete
        $content = array(
-               'runtime'  => translateComma($runTime),
-               'timeSQLs' => translateComma(getConfig('sql_time') * 1000),
+               'run_time' => translateComma($runTime),
+               'sql_time' => translateComma(getConfig('sql_time') * 1000),
        );
 
        // Load the template
@@ -2721,11 +2736,12 @@ function isUrlValidSimple ($url) {
        $pattern['d1g12']  = $http . $domain1 . $getstring1;
        $pattern['d2g12']  = $http . $domain2 . $getstring1;
        $pattern['ipg12']  = $http . $ip . $getstring1;
+
        // Test all patterns
        $reg = false;
        foreach ($pattern as $key => $pat) {
                // Debug regex?
-               if (isDebugRegExpressionEnabled()) {
+               if (isDebugRegularExpressionEnabled()) {
                        // @TODO Are these convertions still required?
                        $pat = str_replace('.', "&#92;&#46;", $pat);
                        $pat = str_replace('@', "&#92;&#64;", $pat);
@@ -2733,7 +2749,7 @@ function isUrlValidSimple ($url) {
                } // END - if
 
                // Check if expression matches
-               $reg = ($reg || preg_match(('^' . $pat.'^'), $url));
+               $reg = ($reg || preg_match(('^' . $pat . '^'), $url));
 
                // Does it match?
                if ($reg === true) break;
@@ -2940,14 +2956,14 @@ function handleLoginFailures ($accessLevel) {
        $OUT = '';
 
        // Is the session data set?
-       if ((isSessionVariableSet('mxchange_' . $accessLevel . '_failures')) && (isSessionVariableSet('mxchange_' . $accessLevel . '_last_failure'))) {
+       if ((isSessionVariableSet('mailer_' . $accessLevel . '_failures')) && (isSessionVariableSet('mailer_' . $accessLevel . '_last_failure'))) {
                // Ignore zero values
-               if (getSession('mxchange_' . $accessLevel . '_failures') > 0) {
+               if (getSession('mailer_' . $accessLevel . '_failures') > 0) {
                        // Non-guest has login failures found, get both data and prepare it for template
                        //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "accessLevel={$accessLevel}<br />");
                        $content = array(
-                               'login_failures' => getSession('mxchange_' . $accessLevel . '_failures'),
-                               'last_failure'   => generateDateTime(getSession('mxchange_' . $accessLevel . '_last_failure'), 2)
+                               'login_failures' => getSession('mailer_' . $accessLevel . '_failures'),
+                               'last_failure'   => generateDateTime(getSession('mailer_' . $accessLevel . '_last_failure'), 2)
                        );
 
                        // Load template
@@ -2955,8 +2971,8 @@ function handleLoginFailures ($accessLevel) {
                } // END - if
 
                // Reset session data
-               setSession('mxchange_' . $accessLevel . '_failures', '');
-               setSession('mxchange_' . $accessLevel . '_last_failure', '');
+               setSession('mailer_' . $accessLevel . '_failures', '');
+               setSession('mailer_' . $accessLevel . '_last_failure', '');
        } // END - if
 
        // Return rendered content
@@ -3079,7 +3095,7 @@ function determineReferalId () {
        } elseif ((isExtensionInstalledAndNewer('user', '0.3.4')) && (getConfig('select_user_zero_refid') == 'Y')) {
                // Select a random user which has confirmed enougth mails
                $GLOBALS['refid'] = determineRandomReferalId();
-       } elseif ((isExtensionInstalled('sql_patches')) && (getConfig('def_refid') > 0)) {
+       } elseif ((isExtensionInstalledAndNewer('sql_patches', '0.1.2')) && (getConfig('def_refid') > 0)) {
                // Set default refid as refid in URL
                $GLOBALS['refid'] = getConfig('def_refid');
        } else {
@@ -3869,10 +3885,10 @@ function addPageHeaderFooter () {
 
 // Generates meta description for current module and 'what' value
 function generateMetaDescriptionCode () {
-       // Only include from guest area
-       if (getModule() == 'index') {
+       // Only include from guest area and if sql_patches has correct version
+       if ((getModule() == 'index') && (isExtensionInstalledAndNewer('sql_patches', '0.1.6'))) {
                // Construct dynamic description
-               $DESCR = '{?MAIN_TITLE?} '.trim(getConfig('title_middle')) . ' ' . getTitleFromMenu('guest', getWhat());
+               $DESCR = '{?MAIN_TITLE?} ' . trim(getConfig('title_middle')) . ' ' . getTitleFromMenu('guest', getWhat());
 
                // Output it directly
                $GLOBALS['page_header'] .= '<meta name="description" content="' . $DESCR . '" />';
@@ -3946,6 +3962,28 @@ function fixNullEmptyToDashes ($str, $num) {
        return $return;
 }
 
+// Handles the braces [] of a field (e.g. value of 'name' attribute)
+function handleFieldWithBraces ($field) {
+       // Are there braces [] at the end?
+       if (substr($field, -2, 2) == '[]') {
+               // Try to find one and replace it. I do it this way to allow easy
+               // extending of this code.
+               foreach (array('admin_list_builder_id_value') as $key) {
+                       // Is the cache entry set?
+                       if (isset($GLOBALS[$key])) {
+                               // Insert it
+                               $field = str_replace('[]', '[' . $GLOBALS[$key] . ']', $field);
+
+                               // And abort
+                               break;
+                       } // END - if
+               } // END - foreach
+       } // END - if
+
+       // Return it
+       return $field;
+}
+
 //////////////////////////////////////////////////
 // AUTOMATICALLY RE-GENERATED MISSING FUNCTIONS //
 //////////////////////////////////////////////////