]> git.mxchange.org Git - mailer.git/blobdiff - inc/functions.php
Tons of rewrites (SQL queries), surfbar nearly finished (working: surfing with static...
[mailer.git] / inc / functions.php
index 7a08291573bbb32e871b2b29e23365e7dc3661e8..aae3aae26a9139227769be974d76e7c08af2fdd2 100644 (file)
@@ -209,9 +209,10 @@ function LOAD_TEMPLATE($template, $return=false, $content="") {
        if (empty($GLOBALS['refid'])) $GLOBALS['refid'] = 0;
        $REFID = $GLOBALS['refid'];
 
+       // DEPRECATED!!!
        if ($template == "member_support_form") {
                // Support request of a member
-               $result = SQL_QUERY_ESC("SELECT sex, surname, family FROM "._MYSQL_PREFIX."_user_data WHERE userid=%d LIMIT 1",
+               $result = SQL_QUERY_ESC("SELECT sex, surname, family FROM "._MYSQL_PREFIX."_user_data WHERE userid=%s LIMIT 1",
                 array($GLOBALS['userid']), __FILE__, __LINE__);
                list($sex, $surname, $family) = SQL_FETCHROW($result);
                SQL_FREERESULT($result);
@@ -222,7 +223,7 @@ function LOAD_TEMPLATE($template, $return=false, $content="") {
        $date_time = MAKE_DATETIME(time(), "1");
 
        // Base directory
-       $BASE = PATH."templates/".GET_LANGUAGE()."/html/";
+       $BASE = sprintf("%stemplates/%s/html/", PATH, GET_LANGUAGE());
        $MODE = "";
 
        // Check for admin/guest/member templates
@@ -342,7 +343,7 @@ function SEND_EMAIL($TO, $SUBJECT, $MSG, $HTML='N', $FROM="") {
                        ADD_MESSAGE_TO_BOX($TO, $SUBJECT, $MSG, $HTML);
                        return;
                } else {
-                       $result_email = SQL_QUERY_ESC("SELECT email FROM "._MYSQL_PREFIX."_user_data WHERE userid=%d LIMIT 1", array(bigintval($TO)), __FILE__, __LINE__);
+                       $result_email = SQL_QUERY_ESC("SELECT email FROM "._MYSQL_PREFIX."_user_data WHERE userid=%s LIMIT 1", array(bigintval($TO)), __FILE__, __LINE__);
                        list($TO) = SQL_FETCHROW($result_email);
                        SQL_FREERESULT($result_email);
                }
@@ -410,7 +411,7 @@ function SEND_RAW_EMAIL ($to, $subject, $msg, $from) {
 
                // get new instance
                $mail = new PHPMailer();
-               $mail->PluginDir  = PATH."inc/phpmailer/";
+               $mail->PluginDir  = sprintf("%sinc/phpmailer/", PATH);
 
                $mail->IsSMTP();
                $mail->SMTPAuth   = true;
@@ -710,6 +711,7 @@ function LOAD_EMAIL_TEMPLATE($template, $content="", $UID="0") {
                $EXPIRATION = round($_CONFIG['auto_purge']/60/60/24)." "._DAYS;
        }
 
+       // DEPRECATED switch!
        switch ($template)
        {
        case "bonus-mail": // Load data for the bonus mail
@@ -807,13 +809,13 @@ function LOAD_EMAIL_TEMPLATE($template, $content="", $UID="0") {
        if ($UID > 0) {
                if (EXT_IS_ACTIVE("nickname")) {
                        // Load nickname
-                       $result = SQL_QUERY_ESC("SELECT surname, family, sex, email, nickname FROM "._MYSQL_PREFIX."_user_data WHERE userid=%d LIMIT 1",
+                       $result = SQL_QUERY_ESC("SELECT surname, family, sex, email, nickname FROM "._MYSQL_PREFIX."_user_data WHERE userid=%s LIMIT 1",
                         array(bigintval($UID)), __FILE__, __LINE__);
                        list($surname, $family, $sex, $email, $nick) = SQL_FETCHROW($result);
                        SQL_FREERESULT($result);
                } else {
                        // Load normal data
-                       $result = SQL_QUERY_ESC("SELECT surname, family, sex, email FROM "._MYSQL_PREFIX."_user_data WHERE userid=%d LIMIT 1",
+                       $result = SQL_QUERY_ESC("SELECT surname, family, sex, email FROM "._MYSQL_PREFIX."_user_data WHERE userid=%s LIMIT 1",
                         array(bigintval($UID)), __FILE__, __LINE__);
                        list($surname, $family, $sex, $email) = SQL_FETCHROW($result);
                        SQL_FREERESULT($result);
@@ -832,7 +834,7 @@ function LOAD_EMAIL_TEMPLATE($template, $content="", $UID="0") {
        $DATA['email'] = $email;
 
        // Base directory
-       $BASE = PATH."templates/".GET_LANGUAGE()."/emails/";
+       $BASE = sprintf("%stemplates/%s/emails/", PATH, GET_LANGUAGE());
 
        // Check for admin/guest/member templates
        if (strpos($template, "admin_") > -1) {
@@ -860,11 +862,10 @@ function LOAD_EMAIL_TEMPLATE($template, $content="", $UID="0") {
        if ((!@file_exists($file)) || (!is_readable($file))) {
                // Reset to default template
                $file = $BASE.$template.".tpl";
-       }
+       } // END - if
 
        // Now does the final template exists?
-       if ((@file_exists($file)) && (is_readable($file)))
-       {
+       if ((@file_exists($file)) && (is_readable($file))) {
                // The local file does exists so we load it. :)
                $tmpl_file = @implode("", @file($file));
                $tmpl_file = addslashes($tmpl_file);
@@ -878,9 +879,7 @@ function LOAD_EMAIL_TEMPLATE($template, $content="", $UID="0") {
 
                // Replace HTML confirm chars
                $content = html_entity_decode($content);
-       }
-        elseif (!empty($template))
-       {
+       } elseif (!empty($template)) {
                // Template file not found!
                $content = TEMPLATE_404.": ".$template."<br />
 ".TEMPLATE_CONTENT."
@@ -891,17 +890,16 @@ function LOAD_EMAIL_TEMPLATE($template, $content="", $UID="0") {
 
                // Debug mode not active? Then remove the HTML tags
                if (!DEBUG_MODE) $content = strip_tags($content);
-       }
-        else
-       {
+       } else {
                // No template name supplied!
                $content = NO_TEMPLATE_SUPPLIED;
        }
+
+       // Return compiled content
        return COMPILE_CODE($content);
 }
 //
-function MAKE_TIME($H, $M, $S, $stamp)
-{
+function MAKE_TIME($H, $M, $S, $stamp) {
        // Extract day, month and year from given timestamp
        $DAY   = date("d", $stamp);
        $MONTH = date("m", $stamp);
@@ -1241,20 +1239,15 @@ function GEN_RANDOM_CODE($length, $code, $uid, $DATA="") {
        return $return;
 }
 // Does only allow numbers
-function bigintval($num, $castValue = true)
-{
+function bigintval($num, $castValue = true) {
        // Filter all numbers out
        $ret = preg_replace("/[^0123456789]/", "", $num);
 
-       // Cast the value?
-       if ($castValue) $ret = (int) $ret;
-
        // Return result
        return $ret;
 }
 // Insert the code in $img_code into jpeg or PNG image
-function GENERATE_IMAGE($img_code, $header=true)
-{
+function GENERATE_IMAGE($img_code, $header=true) {
        global $_CONFIG;
        if ((strlen($img_code) > 6) || (empty($img_code)) || ($_CONFIG['code_length'] == 0))
        {
@@ -1271,14 +1264,11 @@ function GENERATE_IMAGE($img_code, $header=true)
        {
        case "jpg":
                // Loads JPEG image
-               $img = PATH."/theme/".GET_CURR_THEME()."/images/code_bg.jpg";
-               if ((file_exists($img)) && (is_readable($img)))
-               {
+               $img = sprintf("%s/theme/%s/images/code_bg.jpg", PATH, GET_CURR_THEME());
+               if ((file_exists($img)) && (is_readable($img))) {
                        // Okay, load image and hide all errors
                        $image = @imagecreatefromjpeg($img);
-               }
-                else
-               {
+               } else  {
                        // Exit function here
                        return;
                }
@@ -1286,14 +1276,11 @@ function GENERATE_IMAGE($img_code, $header=true)
 
        case "png":
                // Loads PNG image
-               $img = PATH."/theme/".GET_CURR_THEME()."/images/code_bg.png";
-               if ((file_exists($img)) && (is_readable($img)))
-               {
+               $img = sprintf("%s/theme/%s/images/code_bg.png", PATH, GET_CURR_THEME());
+               if ((file_exists($img)) && (is_readable($img))) {
                        // Okay, load image and hide all errors
                        $image = @imagecreatefrompng($img);
-               }
-                else
-               {
+               } else {
                        // Exit function here
                        return;
                }
@@ -1310,8 +1297,7 @@ function GENERATE_IMAGE($img_code, $header=true)
        header ("Content-Type: image/".$_CONFIG['img_type']);
 
        // Output image with matching image factory
-       switch ($_CONFIG['img_type'])
-       {
+       switch ($_CONFIG['img_type']) {
                case "jpg": imagejpeg($image); break;
                case "png": imagepng($image);  break;
        }
@@ -1916,6 +1902,14 @@ function generateHash ($plainText, $salt = "") {
                return $plainText;
        } // END - if
 
+       // Do we miss an arry element here?
+       if (!isset($_CONFIG['file_hash'])) {
+               // Stop here
+               print(__FUNCTION__.":<pre>");
+               debug_print_backtrace();
+               die("</pre>");
+       } // END - if
+
        // When the salt is empty build a new one, else use the first x configured characters as the salt
        if ($salt == "") {
                // Build server string
@@ -1941,10 +1935,10 @@ function generateHash ($plainText, $salt = "") {
                // Generate the password salt string
                $salt = substr($sha1, 0, $_CONFIG['salt_length']);
                //* DEBUG: */ echo $salt." (".strlen($salt).")<br />";
-       }
-        else
-       {
+       } else {
+               // Use given salt
                $salt = substr($salt, 0, $_CONFIG['salt_length']);
+               //* DEBUG: */ echo "GIVEN={$salt}<br />\n";
        }
 
        // Return hash
@@ -2070,7 +2064,7 @@ function ADD_URL_DATA($URL)
        // Add all together and return it
        return $URL.$ADD;
 }
-//
+// Generate an PGP-like encrypted hash of given hash for e.g. cookies
 function generatePassString($passHash) {
        global $_CONFIG;
 
@@ -2095,10 +2089,11 @@ function generatePassString($passHash) {
                        //* DEBUG: */ echo "*".$start."=".$mod."*<br>";
                        $start += 4;
                        $newHash .= $mod;
-               }
+               } // END - for
 
-               //* DEBUG: */ die($passHash."<br>".$newHash." (".strlen($newHash).")");
+               //* DEBUG: */ print($passHash."<br>".$newHash." (".strlen($newHash).")");
                $ret = generateHash($newHash, $_CONFIG['master_salt']);
+               //* DEBUG: */ print($ret."<br />\n");
        } else {
                // Hash it simple
                //* DEBUG: */ echo "--".$passHash."--<br />\n";
@@ -2191,6 +2186,9 @@ function set_session ($var, $value) {
        } elseif (!empty($value)) {
                // Update session
                $_SESSION[$var] = $value;
+       } else {
+               // Something bad happens!
+               return false; // Hope this doesn't make so much trouble???
        }
 
        // Return always true if the session variable is already set.
@@ -2236,7 +2234,27 @@ function SEND_ADMIN_NOTIFICATION($subject, $templateName, $content="", $uid="0")
                SEND_ADMIN_EMAILS($subject, $msg);
        }
 }
-
+// Destroy user session
+function destroy_user_session () {
+       // Remove all user data from session
+       return ((set_session("userid", "")) && (set_session("u_hash", "")) && (set_session("lifetime", "")));
+}
+// Merges an array together but only if both are arrays
+function merge_array ($array1, $array2) {
+       // Are both an array?
+       if ((is_array($array1)) && (is_array($array2))) {
+               // Merge all together
+               return array_merge($array1, $array2);
+       } elseif (is_array($array1)) {
+               // Return left array
+               return $array1;
+       }
+
+       // Something wired happened here...
+       print(__FUNCTION__.":<pre>");
+       debug_print_backtrace();
+       die("</pre>");
+}
 //
 //////////////////////////////////////////////////
 //                                              //