bigintval() made to much trouble, uberwach wont be displayed in frames anymore
[mailer.git] / inc / functions.php
index 16a7194b80aedc83954c4b70732b2e423fda8573..342ab2e3fcf36b64cbc907c6fd2cb2dd189f5def 100644 (file)
@@ -120,6 +120,9 @@ function OUTPUT_HTML ($HTML, $newLine = true) {
 
                // Compile and run finished rendered HTML code
                while (strpos($OUTPUT, '{!') > 0) {
+                       // Replace _MYSQL_PREFIX
+                       $OUTPUT = str_replace("{!_MYSQL_PREFIX!}", getConfig('_MYSQL_PREFIX'), $OUTPUT);
+
                        // Prepare the content and eval() it...
                        $newContent = '';
                        $eval = "\$newContent = \"".COMPILE_CODE(smartAddSlashes($OUTPUT))."\";";
@@ -128,7 +131,7 @@ function OUTPUT_HTML ($HTML, $newLine = true) {
                        // Was that eval okay?
                        if (empty($newContent)) {
                                // Something went wrong!
-                               app_die(__FUNCTION__, __LINE__, "Evaluation error:<pre>".htmlentities($eval)."</pre>");
+                               app_die(__FUNCTION__, __LINE__, 'Evaluation error:<pre>' . htmlentities($eval) . '</pre>');
                        } // END - if
                        $OUTPUT = $newContent;
                } // END - while
@@ -286,13 +289,16 @@ function LOAD_TEMPLATE ($template, $return=false, $content=array()) {
        } elseif (strpos($template, 'la_') > -1) {
                // 'Logical-area' template found
                $mode = 'la/';
+       } elseif (strpos($template, 'js_') > -1) {
+               // JavaScript template found
+               $mode = 'js/';
        } else {
                // Test for extension
                $test = substr($template, 0, strpos($template, '_'));
                if (EXT_IS_ACTIVE($test)) {
                        // Set extra path to extension's name
-                       $mode = $test.'/';
-               }
+                       $mode = $test . '/';
+               } // END - if
        }
 
        ////////////////////////
@@ -514,16 +520,16 @@ function sendRawEmail ($toEmail, $subject, $message, $from) {
 }
 
 // Generate a password in a specified length or use default password length
-function generatePassword ($LEN = 0) {
+function generatePassword ($length = 0) {
        // Auto-fix invalid length of zero
-       if ($LEN == 0) $LEN = getConfig('pass_len');
+       if ($length == 0) $length = getConfig('pass_len');
 
        // Initialize array with all allowed chars
-       $ABC = explode(',', 'a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,0,1,2,3,4,5,6,7,8,9,-,+,_,/');
+       $ABC = explode(',', 'a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,0,1,2,3,4,5,6,7,8,9,-,+,_,/,.');
 
        // Start creating password
        $PASS = '';
-       for ($i = 0; $i < $LEN; $i++) {
+       for ($i = 0; $i < $length; $i++) {
                $PASS .= $ABC[mt_rand(0, count($ABC) -1)];
        } // END - for
 
@@ -735,7 +741,10 @@ function generateCaptchaCode ($code, $type, $DATA, $uid) {
 
 // Loads an email template and compiles it
 function LOAD_EMAIL_TEMPLATE ($template, $content = array(), $UID = '0') {
-       global $DATA, $_CONFIG;
+       global $DATA;
+
+       // Our configuration is kept non-global here
+       $_CONFIG = getConfigArray();
 
        // Make sure all template names are lowercase!
        $template = strtolower($template);
@@ -1283,9 +1292,9 @@ function bigintval ($num, $castValue = true) {
 
        // Has the whole value changed?
        // @TODO Remove this if() block if all is working fine
-       if ("" . $ret."" != '' . $num."") {
+       if ('' . $ret . '' != '' . $num . '') {
                // Log the values
-               debug_report_bug("{$ret}<>{$num}");
+               //debug_report_bug("{$ret}<>{$num}");
        } // END - if
 
        // Return result
@@ -2218,9 +2227,12 @@ function app_die ($F, $L, $message) {
                // Load header
                loadIncludeOnce('inc/header.php');
 
-               // Prepare message for output
+               // Rewrite message for output
                $message = sprintf(getMessage('MXCHANGE_HAS_DIED'), basename($F), $L, $message);
 
+               // Better log this message away
+               DEBUG_LOG($F, $L, $message);
+
                // Load the message template
                LOAD_TEMPLATE('admin_settings_saved', false, $message);
 
@@ -2455,25 +2467,37 @@ function getActualVersion ($type = 'Revision') {
 
        if (EXT_IS_ACTIVE('cache')) {
                // Check if REQUEST_GET('check_revision_data') is setted (switch for manually rewrite the .revision-File)
-               if (REQUEST_ISSET_GET('check_revision_data') && REQUEST_GET('check_revision_data') == 'yes') $new = true;
-               if (!isset($GLOBALS['cache_array']['revision'][$type])
-               || count($GLOBALS['cache_array']['revision']) < 3
-               || !$GLOBALS['cache_instance']->loadCacheFile('revision')) $new = true;
+               if (REQUEST_ISSET_GET('check_revision_data') && REQUEST_GET('check_revision_data') == 'yes') {
+                       // Force rebuild by URL parameter
+                       $new = true;
+               } elseif ((
+                       !isset($GLOBALS['cache_array']['revision'][$type])
+               ) || (
+                       count($GLOBALS['cache_array']['revision']) < 3
+               ) || (
+                       !$GLOBALS['cache_instance']->loadCacheFile('revision')
+               )) {
+                       // Out-dated cache
+                       $new = true;
+               } // END - if
 
                // Is the cache file outdated/invalid?
                if ($new === true){
-                       $GLOBALS['cache_instance']->destroyCacheFile(); // @TODO isn't it better to do $GLOBALS['cache_instance']->destroyCacheFile('revision')?
+                       // Destroy cache file
+                       $GLOBALS['cache_instance']->destroyCacheFile();
 
                        // @TODO shouldn't do the unset and the reloading $GLOBALS['cache_instance']->destroyCacheFile() Or a new methode like forceCacheReload('revision')?
                        unset($GLOBALS['cache_array']['revision']);
 
                        // Reload load_cach-revison.php
                        loadInclude('inc/loader/load_cache-revision.php');
+
+                       // Abort here
+                       return;
                } // END - if
 
                // Return found value
                return $GLOBALS['cache_array']['revision'][$type][0];
-
        } else {
                // Old Version without ext-cache active (deprecated ?)
 
@@ -2482,7 +2506,7 @@ function getActualVersion ($type = 'Revision') {
 
                // Check if REQUEST_GET('check_revision_data') is setted (switch for manually rewrite the .revision-File)
                if ((REQUEST_ISSET_GET('check_revision_data')) && (REQUEST_GET('check_revision_data') == 'yes')) {
-                       // Has changed!
+                       // Forced rebuild of .revision file
                        $new = true;
                } else {
                        // Check for revision file
@@ -2625,7 +2649,7 @@ function debug_report_bug ($message = '') {
        } // END - if
 
        // Add output
-       $debug .= "Please report this bug at <a title=\"Direct link to the bug-tracker\" href=\"http://bugs.mxchange.org\" rel=\"external\" target=\"_blank\">bugs.mxchange.org</a> and include the logfile from <strong>inc/cache/debug.log</strong> in your report (you cannot attach files!):<pre>";
+       $debug .= "Please report this bug at <a title=\"Direct link to the bug-tracker\" href=\"http://bugs.mxchange.org\" rel=\"external\" target=\"_blank\">bugs.mxchange.org</a> and include the logfile from <strong>inc/cache/debug.log</strong> in your report (you can now attach files):<pre>";
        $debug .= debug_get_printable_backtrace();
        $debug .= "</pre>\nRequest-URI: " . $_SERVER['REQUEST_URI']."<br />\n";
        $debug .= "Thank you for finding bugs.";
@@ -2637,8 +2661,9 @@ function debug_report_bug ($message = '') {
 
 // Generates a ***weak*** seed (taken from de.php.net/mt_srand)
 function generateSeed () {
-       list($usec, $sec) = explode(" ", microtime());
-       return ((float)$sec + (float)$usec);
+       list($usec, $sec) = explode(' ', microtime());
+       $microTime = (((float)$sec + (float)$usec)) * 100000;
+       return $microTime;
 }
 
 // Converts a message code to a human-readable message
@@ -3266,7 +3291,7 @@ function isUserIdSet () {
 // Handle message codes from URL
 function handleCodeMessage () {
        if (REQUEST_ISSET_GET('msg')) {
-               // Default extension is "unknown"
+               // Default extension is 'unknown'
                $ext = 'unknown';
 
                // Is extension given?