]> git.mxchange.org Git - mailer.git/blobdiff - 0.2.1/inc/functions.php
Code rewritings, load base config improved and many minor fixes...
[mailer.git] / 0.2.1 / inc / functions.php
index 7ae88126bafa4fa7e8b006aec8ab610150fc99e9..6bc73d52d580545f67a7a42af3ae2634fdbff03a 100644 (file)
@@ -34,7 +34,7 @@
 // Some security stuff...\r
 if (ereg(basename(__FILE__), $_SERVER['PHP_SELF']))\r
 {\r
-       $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4)."/security.php";\r
+       $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";\r
        require($INC);\r
 }\r
 \r
@@ -61,6 +61,7 @@ function is_SQLWriteable($sql)
        $fp = @fopen(PATH.$sql.".sql", 'a');\r
        return @fclose($fp);\r
 }\r
+
 // Open a table (you may want to add some header stuff here)\r
 function OPEN_TABLE($PERCENT = "", $CLASS = "", $ALIGN="left", $VALIGN="", $td_only=false)\r
 {\r
@@ -98,6 +99,7 @@ function CLOSE_TABLE($ADD="")
        if (!empty($ADD)) OUTPUT_HTML ($ADD);\r
        OUTPUT_HTML ("</TABLE>");\r
 }\r
+
 // Output HTML code directly or "render" it. You addionally switch the new-line character off\r
 function OUTPUT_HTML ($HTML, $NEW_LINE = true) {\r
        // Some global variables\r
@@ -179,6 +181,7 @@ function OUTPUT_HTML ($HTML, $NEW_LINE = true) {
                flush();\r
        }\r
 }\r
+
 // Add a fatal error message to the queue array\r
 function ADD_FATAL ($message, $extra="")\r
 {\r
@@ -191,6 +194,7 @@ function ADD_FATAL ($message, $extra="")
                $FATAL[] = sprintf($message, $extra);\r
        }\r
 }\r
+
 // Load a template file and return it's content (only it's name; do not use ' or ")\r
 function LOAD_TEMPLATE($template, $return=false, $content="")\r
 {\r
@@ -347,7 +351,8 @@ function LOAD_TEMPLATE($template, $return=false, $content="")
                return "E:".$template."<BR>\n";\r
        }\r
 }\r
-//\r
+
+// Send mail out to an email address\r
 function SEND_EMAIL($TO, $SUBJECT, $MSG, $HTML="N", $FROM="")\r
 {\r
        // Compile subject line (for POINTS constant etc.)\r
@@ -417,9 +422,10 @@ function SEND_EMAIL($TO, $SUBJECT, $MSG, $HTML="N", $FROM="")
 function CHECK_PHPMAILER_USAGE() {\r
        return (((defined('SMTP_HOSTNAME')) && (defined('SMTP_USER')) && (defined('SMTP_PASSWORD'))) || ((SMTP_HOSTNAME != "") && (SMTP_USER != "")));\r
 }\r
-\r
-// Send a raw email\r
-// @private\r
+
+/*
+ * Send out a raw email with PHPMailer class or legacy mail() command
+ */\r
 function SEND_RAW_EMAIL ($to, $subject, $msg, $from) {\r
        // Shall we use PHPMailer class or legacy mode?\r
        if (CHECK_PHPMAILER_USAGE()) {\r
@@ -458,28 +464,31 @@ function SEND_RAW_EMAIL ($to, $subject, $msg, $from) {
        }\r
 }\r
 //\r
-function GEN_PASS($LEN="x")\r
-{\r
+
+// Generate a password in a specified length or use default password length
+function GEN_PASS($LEN = 0) {\r
        global $CONFIG;\r
-       if ($LEN == "x") $LEN = $CONFIG['pass_len'];\r
+       if ($LEN == 0) $LEN = $CONFIG['pass_len'];\r
+
        // Initialize array with all allowed chars\r
        $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,-,+,_,/");\r
+
        // Initialize randomizer\r
        mt_srand((double) microtime() * 1000000);\r
 \r
        // Start creating password\r
        $PASS = "";\r
-       for ($i = 0; $i < $LEN; $i++)\r
-       {\r
+       for ($i = 0; $i < $LEN; $i++) {\r
                $PASS .= $ABC[mt_rand(0, sizeof($ABC) -1)];\r
        }\r
 \r
        // When the size is below 40 we can also add additional security by scrambling it\r
-       if (strlen($PASS) <= 40)\r
-       {\r
+       if (strlen($PASS) <= 40) {\r
                // Also scramble the password\r
                $PASS = scrambleString($PASS);\r
-       }\r
+       }
+
+       // Return the password\r
        return $PASS;\r
 }\r
 //\r
@@ -964,27 +973,21 @@ function MAKE_TIME($H, $M, $S, $stamp)
        return mktime($H, $M, $S, $MONTH, $DAY, $YEAR);\r
 }\r
 //\r
-function LOAD_URL($URL)\r
-{\r
+function LOAD_URL($URL) {\r
        // Add some data to URL if cookies are not accepted\r
        if ((!defined('__COOKIES')) || (!__COOKIES)) $URL = ADD_URL_DATA($URL);\r
 \r
        // Probe for bot from search engine\r
-       if ((eregi("spider", getenv('HTTP_USER_AGENT'))) || (eregi("bot", getenv('HTTP_USER_AGENT'))) || (eregi("spider", getenv('HTTP_USER_AGENT'))))\r
-       {\r
+       if ((eregi("spider", getenv('HTTP_USER_AGENT'))) || (eregi("bot", getenv('HTTP_USER_AGENT'))) || (eregi("spider", getenv('HTTP_USER_AGENT')))) {\r
                // Search engine bot detected so let's rewrite many chars for the link\r
                $URL = htmlentities(strip_tags($URL), ENT_QUOTES);\r
 \r
                // Output new location link as anchor\r
                OUTPUT_HTML ("<A href=\"".$URL."\">".$URL."</A>\n");\r
-       }\r
-        elseif (!headers_sent())\r
-       {\r
+       } elseif (!headers_sent()) {\r
                // Load URL when headers are not sent\r
                @header ("Location: ".str_replace("&amp;", "&", $URL));\r
-       }\r
-        else\r
-       {\r
+       } else {\r
                // Output error message\r
                include(PATH."inc/header.php");\r
                OUTPUT_HTML (LOAD_URL_ERROR_1.$URL.LOAD_URL_ERROR_2);\r