]> git.mxchange.org Git - mailer.git/blobdiff - inc/functions.php
Bonus ranking list now contains nicknames, if set
[mailer.git] / inc / functions.php
index 4c5ca96fa50f0e41fc16d68381efe35fccb8dd1d..0048109565812153f65ca8df08c1c64097237ab6 100644 (file)
@@ -44,7 +44,8 @@ if (!defined('__SECURITY')) {
 // Output HTML code directly or 'render' it. You addionally switch the new-line character off
 function outputHtml ($htmlCode, $newLine = true) {
        // Transfer username
-       $username = getUsername();
+       $username = getMessage('USERNAME_UNKNOWN');
+       if (isset($GLOBALS['username'])) $username = getUsername();
 
        // Do we have HTML-Code here?
        if (!empty($htmlCode)) {
@@ -123,7 +124,7 @@ function outputHtml ($htmlCode, $newLine = true) {
                $cnt = 0;
 
                // Compile and run finished rendered HTML code
-               while (((strpos($GLOBALS['output'], '{!') > 0) || (strpos($GLOBALS['output'], '{?') > 0)) && ($cnt < 3)) {
+               while (((strpos($GLOBALS['output'], '{--') > 0) || (strpos($GLOBALS['output'], '{!') > 0) || (strpos($GLOBALS['output'], '{?') > 0)) && ($cnt < 3)) {
                        // Prepare the content and eval() it...
                        $content = array();
                        $newContent = '';
@@ -135,7 +136,7 @@ function outputHtml ($htmlCode, $newLine = true) {
                        // Was that eval okay?
                        if (empty($newContent)) {
                                // Something went wrong!
-                               debug_report_bug('Evaluation error:<pre>' . htmlentities($eval) . '</pre>');
+                               debug_report_bug('Evaluation error:<pre>' . linenumberCode($eval) . '</pre>');
                        } // END - if
                        $GLOBALS['output'] = $newContent;
 
@@ -363,8 +364,9 @@ function loadTemplate ($template, $return=false, $content=array()) {
                                        $eval = '$ret = "' . compileCode(smartAddSlashes($GLOBALS['tpl_content'])) . '";';
                                }
                        } else {
-                               // Simply return loaded code
-                               $eval = '$ret = $GLOBALS[\'tpl_content\'];';
+                               // Add surrounding HTML comments to help finding bugs faster
+                               $ret = "<!-- Template " . $template . " - Start -->\n" . $GLOBALS['tpl_content'] . "<!-- Template " . $template . " - End -->\n";
+                               $eval = '$ret = "' . smartAddSlashes($ret) . '";';
                        } // END - if
 
                        // Cache the eval() command here
@@ -558,8 +560,12 @@ function loadEmailTemplate ($template, $content = array(), $UID = '0') {
        unset($content);
        unset($DATA);
 
-       // Return compiled content
-       return compileCode($newContent);
+       // Compile the code and eval it
+       $eval = '$newContent = "' . compileCode(smartAddSlashes($newContent)) . '";';
+       eval($eval);
+
+       // Return content
+       return $newContent;
 }
 
 // Send mail out to an email address
@@ -888,7 +894,7 @@ function generateDerefererUrl ($URL) {
        // Don't de-refer our own links!
        if (substr($URL, 0, strlen(getConfig('URL'))) != getConfig('URL')) {
                // De-refer this link
-               $URL = 'modules.php?module=loader&amp;url=' . encodeString(compileUriCode($URL));
+               $URL = '{?URL?}/modules.php?module=loader&amp;url=' . encodeString(compileUriCode($URL));
        } // END - if
 
        // Return link
@@ -929,18 +935,25 @@ function countSelection ($array) {
 
 // Generate XHTML code for the CAPTCHA
 function generateCaptchaCode ($code, $type, $DATA, $userid) {
-       return '<IMG border="0" alt="Code" src="{?URL?}/mailid_top.php?userid=' . $userid . '&amp;' . $type . '=' . $DATA . '&amp;mode=img&amp;code=' . $code . '" />';
+       return '<img border="0" alt="Code ' . $code . '" src="{?URL?}/mailid_top.php?userid=' . $userid . '&amp;' . $type . '=' . $DATA . '&amp;mode=img&amp;code=' . $code . '" />';
 }
 
 // Generates a timestamp (some wrapper for mktime())
-function makeTime ($H, $M, $S, $stamp) {
+function makeTime ($hours, $minutes, $seconds, $stamp) {
        // Extract day, month and year from given timestamp
-       $day   = date('d', $stamp);
-       $month = date('m', $stamp);
-       $year  = date('Y', $stamp);
+       $days   = date('d', $stamp);
+       $months = date('m', $stamp);
+       $years  = date('Y', $stamp);
 
        // Create timestamp for wished time which depends on extracted date
-       return mktime($H, $M, $S, $month, $day, $year);
+       return mktime(
+               $hours,
+               $minutes,
+               $seconds,
+               $months,
+               $days,
+               $years
+       );
 }
 
 // Redirects to an URL and if neccessarry extends it with own base URL
@@ -1324,7 +1337,7 @@ function generateRandomCode ($length, $code, $userid, $DATA = '') {
 // Does only allow numbers
 function bigintval ($num, $castValue = true) {
        // Filter all numbers out
-       $ret = preg_replace("/[^0123456789]/", '', $num);
+       $ret = preg_replace('/[^0123456789]/', '', $num);
 
        // Shall we cast?
        if ($castValue) $ret = (double)$ret;
@@ -3060,7 +3073,7 @@ function rebuildCacheFile ($cache, $inc = '', $force = false) {
                // Rebuild cache
                if ($GLOBALS['cache_instance']->loadCacheFile($cache)) {
                        // Destroy it
-                       $GLOBALS['cache_instance']->removeCacheFile(false, $force);
+                       $GLOBALS['cache_instance']->removeCacheFile($force);
                } // END - if
 
                // Include file given?
@@ -3593,6 +3606,28 @@ function handleFatalErrors () {
        shutdown();
 }
 
+// Print code with line numbers
+function linenumberCode ($code)    {
+       if (!is_array($code)) $codeE = explode("\n", $code); else $codeE = $code;
+       $count_lines = count($codeE);
+
+       $r = "Line | Code:<br />";
+       foreach($codeE as $line => $c) {
+               $r .= "<div class=\"line\"><span class=\"linenum\">";
+               if ($count_lines == 1) {
+                       $r .= '1';
+               } else {
+                       $r .= ($line == ($count_lines - 1)) ? '' :  ($line+1);
+               }
+               $r .= "</span>|";
+
+               // Add code
+               $r .= "<span class=\"linetext\">" . htmlentities($c) . "</span></div>";
+       }
+
+       return "<div class=\"code\">" . $r . "</div>\n";
+}
+
 //////////////////////////////////////////////////
 // AUTOMATICALLY RE-GENERATED MISSING FUNCTIONS //
 //////////////////////////////////////////////////