X-Git-Url: https://git.mxchange.org/?p=mailer.git;a=blobdiff_plain;f=inc%2Ffunctions.php;h=96ed81d53fce6b42cc5d3125751ec6d31882fc60;hp=e04576056a34b1076468db2d895d1955ff75b1f5;hb=64d07c28338c2b08687ff394235101c79cd3077f;hpb=65ba529135f31dfd36b4471588f45f8687cc1aca diff --git a/inc/functions.php b/inc/functions.php index e04576056a..96ed81d53f 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -10,7 +10,12 @@ * -------------------------------------------------------------------- * * Kurzbeschreibung : Viele Nicht-MySQL-Funktionen (auch Dateizugriff) * * -------------------------------------------------------------------- * - * * + * $Revision:: 856 $ * + * $Date:: $ * + * $Tag:: 0.2.1-FINAL $ * + * $Author:: $ * + * Needs to be in all Files and every File needs "svn propset * + * svn:keywords Date Revision" (autoprobset!) at least!!!!!! * * -------------------------------------------------------------------- * * Copyright (c) 2003 - 2008 by Roland Haeder * * For more information visit: http://www.mxchange.org * @@ -30,7 +35,6 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, * * MA 02110-1301 USA * ************************************************************************/ - // Some security stuff... if (!defined('__SECURITY')) { $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4)."/security.php"; @@ -38,25 +42,17 @@ if (!defined('__SECURITY')) { } // Check if our config file is writeable or not -function IS_INC_WRITEABLE($inc) { +function IS_INC_WRITEABLE ($inc) { // Generate FQFN - $fqfn = sprintf("%sinc/%s.php", constant('PATH'), $inc); + $FQFN = sprintf("%sinc/%s.php", constant('PATH'), $inc); // Abort by simple test - if ((FILE_READABLE($fqfn)) && (!is_writeable($fqfn))) { + if ((FILE_READABLE($FQFN)) && (!is_writeable($FQFN))) { return false; } // END - if - // Test if we can append data - $fp = @fopen($fqfn, 'a'); - if ($inc == "dummy") { - // Remove dummy file - fclose($fp); - return unlink($fqfn); - } else { - // Close all other files - return fclose($fp); - } + // Test write-access on directory + return is_writeable(dirname($FQFN)); } // Output HTML code directly or "render" it. You addionally switch the new-line character off @@ -101,7 +97,7 @@ function OUTPUT_HTML ($HTML, $newLine = true) { mxchange_die("{--FATAL_ERROR--}: {--LANG_NO_RENDER_DIRECT--}"); break; } - } elseif ((constant('_OB_CACHING') == "on") && ($GLOBALS['footer_sent'] == 1)) { + } elseif ((constant('_OB_CACHING') == "on") && (isset($GLOBALS['footer_sent'])) && ($GLOBALS['footer_sent'] == 1)) { // Headers already sent? if (headers_sent()) { // Log this error @@ -114,8 +110,10 @@ function OUTPUT_HTML ($HTML, $newLine = true) { // Output cached HTML code $OUTPUT = ob_get_contents(); - // Clear output buffer for later output - clearOutputBuffer(); + // Clear output buffer for later output if output is found + if (!empty($OUTPUT)) { + clearOutputBuffer(); + } // END - if // Send HTTP header header("HTTP/1.1 200"); @@ -139,8 +137,8 @@ function OUTPUT_HTML ($HTML, $newLine = true) { while (strpos($OUTPUT, '{!') > 0) { // Prepare the content and eval() it... $newContent = ""; - $eval = "\$newContent = \"".COMPILE_CODE(SQL_ESCAPE($OUTPUT))."\";"; - @eval($eval); + $eval = "\$newContent = \"".COMPILE_CODE(smartAddSlashes($OUTPUT))."\";"; + eval($eval); // Was that eval okay? if (empty($newContent)) { @@ -160,7 +158,7 @@ function OUTPUT_HTML ($HTML, $newLine = true) { // Compile and run finished rendered HTML code while (strpos($OUTPUT, '{!') > 0) { - $eval = "\$OUTPUT = \"".COMPILE_CODE(SQL_ESCAPE($OUTPUT))."\";"; + $eval = "\$OUTPUT = \"".COMPILE_CODE(smartAddSlashes($OUTPUT))."\";"; eval($eval); } // END - while @@ -192,7 +190,7 @@ function getFatalArray () { } // Add a fatal error message to the queue array -function addFatalMessage ($message, $extra="") { +function addFatalMessage ($F, $L, $message, $extra="") { if (is_array($extra)) { // Multiple extras for a message with masks $message = call_user_func_array('sprintf', $extra); @@ -205,7 +203,7 @@ function addFatalMessage ($message, $extra="") { $GLOBALS['fatal_messages'][] = $message; // Log fatal messages away - DEBUG_LOG(__FUNCTION__, __LINE__, " message={$message}"); + DEBUG_LOG($F, $L, " message={$message}"); } // Getter for total fatal message count @@ -247,7 +245,7 @@ function LOAD_TEMPLATE ($template, $return=false, $content=array()) { if ($template == "member_support_form") { // Support request of a member $result = SQL_QUERY_ESC("SELECT userid, gender, surname, family, email FROM `{!_MYSQL_PREFIX!}_user_data` WHERE userid=%s LIMIT 1", - array($GLOBALS['userid']), __FILE__, __LINE__); + array(getUserId()), __FUNCTION__, __LINE__); // Is content an array? if (is_array($content)) { @@ -345,7 +343,7 @@ function LOAD_TEMPLATE ($template, $return=false, $content=array()) { $ret = ""; if ((strpos($tmpl_file, "\$") !== false) || (strpos($tmpl_file, '{--') !== false) || (strpos($tmpl_file, '--}') > 0)) { // Okay, compile it! - $tmpl_file = "\$ret=\"".COMPILE_CODE(SQL_ESCAPE($tmpl_file))."\";"; + $tmpl_file = "\$ret=\"".COMPILE_CODE(smartAddSlashes($tmpl_file))."\";"; eval($tmpl_file); } else { // Simply return loaded code @@ -354,7 +352,7 @@ function LOAD_TEMPLATE ($template, $return=false, $content=array()) { // Add surrounding HTML comments to help finding bugs faster $ret = "\n".$ret."\n"; - } elseif ((IS_ADMIN()) || ((isBooleanConstantAndTrue('mxchange_installing')) && (!isBooleanConstantAndTrue('mxchange_installed')))) { + } elseif ((IS_ADMIN()) || ((isInstalling()) && (!isInstalled()))) { // Only admins shall see this warning or when installation mode is active $ret = "
".TEMPLATE_404."
(".basename($FQFN).")
@@ -373,14 +371,14 @@ function LOAD_TEMPLATE ($template, $return=false, $content=array()) { // Do we have some content to output or return? if (!empty($ret)) { // Not empty so let's put it out! ;) - if ($return) { + if ($return === true) { // Return the HTML code return $ret; } else { // Output direct OUTPUT_HTML($ret); } - } elseif (isBooleanConstantAndTrue('DEBUG_MODE')) { + } elseif (isDebugModeEnabled()) { // Warning, empty output! return "E:".$template."
\n"; } @@ -391,7 +389,7 @@ function SEND_EMAIL($TO, $SUBJECT, $MSG, $HTML = "N", $FROM = "") { //* DEBUG: */ print __FUNCTION__."(".__LINE__."):TO={$TO},SUBJECT={$SUBJECT}
\n"; // Compile subject line (for POINTS constant etc.) - $eval = "\$SUBJECT = decodeEntities(\"".COMPILE_CODE(SQL_ESCAPE($SUBJECT))."\");"; + $eval = "\$SUBJECT = decodeEntities(\"".COMPILE_CODE(smartAddSlashes($SUBJECT))."\");"; eval($eval); // Set from header @@ -402,7 +400,7 @@ function SEND_EMAIL($TO, $SUBJECT, $MSG, $HTML = "N", $FROM = "") { return; } else { // Load email address - $result_email = SQL_QUERY_ESC("SELECT email FROM `{!_MYSQL_PREFIX!}_user_data` WHERE userid=%s 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)), __FUNCTION__, __LINE__); //* DEBUG: */ print __FUNCTION__."(".__LINE__."):numRows=".SQL_NUMROWS($result_email)."
\n"; // Does the user exist? @@ -433,7 +431,7 @@ function SEND_EMAIL($TO, $SUBJECT, $MSG, $HTML = "N", $FROM = "") { // Append header $FROM .= LOAD_EMAIL_TEMPLATE("header"); } - } elseif (isBooleanConstantAndTrue('DEBUG_MODE')) { + } elseif (isDebugModeEnabled()) { if (empty($FROM)) { // Load email header template $FROM = LOAD_EMAIL_TEMPLATE("header"); @@ -444,16 +442,16 @@ function SEND_EMAIL($TO, $SUBJECT, $MSG, $HTML = "N", $FROM = "") { } // Compile "TO" - $eval = "\$TO = \"".COMPILE_CODE(SQL_ESCAPE($TO))."\";"; + $eval = "\$TO = \"".COMPILE_CODE(smartAddSlashes($TO))."\";"; eval($eval); // Compile "MSG" - $eval = "\$MSG = \"".COMPILE_CODE(SQL_ESCAPE($MSG))."\";"; + $eval = "\$MSG = \"".COMPILE_CODE(smartAddSlashes($MSG))."\";"; eval($eval); // Fix HTML parameter (default is no!) if (empty($HTML)) $HTML = "N"; - if (isBooleanConstantAndTrue('DEBUG_MODE')) { + if (isDebugModeEnabled()) { // In debug mode we want to display the mail instead of sending it away so we can debug this part print("
 ".htmlentities(trim($FROM))."
@@ -474,9 +472,10 @@ Message : ".$MSG."
 }
 
 // Check if legacy or PHPMailer command
+// @TODO Rewrite this to an extension 'smtp'
 // @private
 function CHECK_PHPMAILER_USAGE() {
-	return ((defined('SMTP_HOSTNAME')) && (defined('SMTP_USER')) && (defined('SMTP_PASSWORD')) && (SMTP_HOSTNAME != "") && (SMTP_USER != ""));
+	return ((defined('SMTP_HOSTNAME')) && (defined('SMTP_USER')) && (defined('SMTP_PASSWORD')) && (constant('SMTP_HOSTNAME') != "") && (constant('SMTP_USER') != ""));
 }
 
 /*
@@ -537,7 +536,7 @@ function GEN_PASS ($LEN = 0) {
 	// Start creating password
 	$PASS = "";
 	for ($i = 0; $i < $LEN; $i++) {
-		$PASS .= $ABC[mt_rand(0, sizeof($ABC) -1)];
+		$PASS .= $ABC[mt_rand(0, count($ABC) -1)];
 	} // END - for
 
 	// When the size is below 40 we can also add additional security by scrambling it
@@ -673,8 +672,8 @@ function FRAMETESTER ($URL) {
 function SELECTION_COUNT ($array) {
 	$ret = 0;
 	if (is_array($array)) {
-		foreach ($array as $key => $sel) {
-			if (!empty($sel)) $ret++;
+		foreach ($array as $key => $selected) {
+			if (!empty($selected)) $ret++;
 		}
 	}
 	return $ret;
@@ -802,12 +801,12 @@ function LOAD_EMAIL_TEMPLATE($template, $content=array(), $UID="0") {
 			//* DEBUG: */ print __FUNCTION__."(".__LINE__."):NICKNAME!
\n"; // Load nickname $result = SQL_QUERY_ESC("SELECT surname, family, gender, email, nickname FROM `{!_MYSQL_PREFIX!}_user_data` WHERE userid=%s LIMIT 1", - array(bigintval($UID)), __FILE__, __LINE__); + array(bigintval($UID)), __FUNCTION__, __LINE__); } else { //* DEBUG: */ print __FUNCTION__."(".__LINE__."):NO-NICK!
\n"; /// Load normal data $result = SQL_QUERY_ESC("SELECT surname, family, gender, email FROM `{!_MYSQL_PREFIX!}_user_data` WHERE userid=%s LIMIT 1", - array(bigintval($UID)), __FILE__, __LINE__); + array(bigintval($UID)), __FUNCTION__, __LINE__); } // Fetch and merge data @@ -868,7 +867,7 @@ function LOAD_EMAIL_TEMPLATE($template, $content=array(), $UID="0") { // Run code $tmpl_file = "\$newContent = decodeEntities(\"".COMPILE_CODE($tmpl_file)."\");"; - @eval($tmpl_file); + eval($tmpl_file); } elseif (!empty($template)) { // Template file not found! $newContent = "{--TEMPLATE_404--}: ".$template."
@@ -879,7 +878,7 @@ function LOAD_EMAIL_TEMPLATE($template, $content=array(), $UID="0") {

"; // Debug mode not active? Then remove the HTML tags - if (!isBooleanConstantAndTrue('DEBUG_MODE')) $newContent = strip_tags($newContent); + if (!isDebugModeEnabled()) $newContent = strip_tags($newContent); } else { // No template name supplied! $newContent = getMessage('NO_TEMPLATE_SUPPLIED'); @@ -901,7 +900,7 @@ function LOAD_EMAIL_TEMPLATE($template, $content=array(), $UID="0") { return COMPILE_CODE($newContent); } // -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); @@ -911,7 +910,7 @@ function MAKE_TIME($H, $M, $S, $stamp) { return mktime($H, $M, $S, $MONTH, $DAY, $YEAR); } // -function LOAD_URL($URL, $addUrlData=true) { +function LOAD_URL ($URL, $addUrlData=true) { // Compile out URI codes $URL = compileUriCode($URL); @@ -922,7 +921,8 @@ function LOAD_URL($URL, $addUrlData=true) { } // Get output buffer - //* DEBUG: */ debug_report_bug(); + //* DEBUG: */ debug_report_bug(sprintf("%s[%s:] URL=%s", __FUNCTION__, __LINE__, $URL)); + //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, $URL); $OUTPUT = ob_get_contents(); // Clear it only if there is content @@ -931,7 +931,7 @@ function LOAD_URL($URL, $addUrlData=true) { } // END - if // Add some data to URL if cookies are not accepted - if (((!defined('__COOKIES')) || (!__COOKIES)) && ($addUrlData)) $URL = ADD_URL_DATA($URL); + if (((!defined('__COOKIES')) || (!constant('__COOKIES'))) && ($addUrlData)) $URL = ADD_URL_DATA($URL); // Probe for bot from search engine if ((eregi("spider", GET_USER_AGENT())) || (eregi("bot", GET_USER_AGENT()))) { @@ -950,7 +950,7 @@ function LOAD_URL($URL, $addUrlData=true) { LOAD_TEMPLATE("redirect_url", false, str_replace("&", "&", $URL)); LOAD_INC("inc/footer.php"); } - exit(); + shutdown(); } // Wrapper for LOAD_URL but URL comes from a configuration entry @@ -1104,7 +1104,6 @@ function array_pk_sort (&$array, $a_sort, $primary_key = 0, $order = -1, $nums = // function ADD_SELECTION ($type, $DEFAULT, $prefix="", $id="0") { - global $MONTH_DESCR; $OUT = ""; if ($type == "yn") { @@ -1129,7 +1128,7 @@ function ADD_SELECTION ($type, $DEFAULT, $prefix="", $id="0") { break; case "month": // Month - foreach ($MONTH_DESCR as $month => $descr) { + foreach ($GLOBALS['month_descr'] as $month => $descr) { $OUT .= "