X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;ds=sidebyside;f=inc%2Ffunctions.php;h=049a0c58178fb5061742363a671ba4b3a9ae1c54;hb=c3b3af29e6e80926519ade146ac657c036782bd3;hp=de2c08a4a07deeb568e4db45614a6c7dfda0a9a3;hpb=80e2def8ef2125fd4d7d1312ee3993ab613f0846;p=mailer.git
diff --git a/inc/functions.php b/inc/functions.php
index de2c08a4a0..049a0c5817 100644
--- a/inc/functions.php
+++ b/inc/functions.php
@@ -32,26 +32,36 @@
************************************************************************/
// Some security stuff...
-if (ereg(basename(__FILE__), $_SERVER['PHP_SELF'])) {
+if (!defined('__SECURITY')) {
$INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4)."/security.php";
require($INC);
}
// Check if our config file is writeable or not
-function is_INCWritable($inc) {
- $fp = @fopen(PATH."inc/".$inc.".php", 'a');
+function IS_INC_WRITEABLE($inc) {
+ // Generate FQFN
+ $fqfn = sprintf("%sinc/%s.php", PATH, $inc);
+
+ // Abort by simple test
+ 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(PATH."inc/dummy.php");
+ fclose($fp);
+ return unlink($fqfn);
} else {
// Close all other files
- return @fclose($fp);
+ return fclose($fp);
}
}
// Open a table (you may want to add some header stuff here)
-function OPEN_TABLE($PERCENT = "", $CLASS = "", $ALIGN="left", $VALIGN="", $td_only=false) {
+// @DEPRECATED
+function OPEN_TABLE ($PERCENT = "", $CLASS = "", $ALIGN="left", $VALIGN="", $td_only=false) {
global $table_cnt;
// Count tables so we can generate CSS classes for every table... :-)
@@ -79,14 +89,15 @@ function OPEN_TABLE($PERCENT = "", $CLASS = "", $ALIGN="left", $VALIGN="", $td_o
}
// Close a table (you may want to add some footer stuff here)
-function CLOSE_TABLE($ADD="") {
+// @DEPRECATED
+function CLOSE_TABLE( $ADD="") {
OUTPUT_HTML(" \n");
if (!empty($ADD)) OUTPUT_HTML($ADD);
OUTPUT_HTML("");
}
// Output HTML code directly or "render" it. You addionally switch the new-line character off
-function OUTPUT_HTML($HTML, $NEW_LINE = true) {
+function OUTPUT_HTML ($HTML, $NEW_LINE = true) {
// Some global variables
global $OUTPUT, $footer, $CSS;
@@ -123,19 +134,46 @@ function OUTPUT_HTML($HTML, $NEW_LINE = true) {
default:
// Huh, something goes wrong or maybe you have edited config.php ???
- die ("".FATAL_ERROR.": ".LANG_NO_RENDER_DIRECT);
+ DEBUG_LOG(__FUNCTION__, __LINE__, sprintf("Invalid renderer %s detected.", OUTPUT_MODE));
+ MXCHANGE_DIE("".FATAL_ERROR.": ".LANG_NO_RENDER_DIRECT);
break;
}
} elseif ((_OB_CACHING == "on") && ($footer == 1)) {
+ // Headers already sent?
+ if (headers_sent()) {
+ // Log this error
+ DEBUG_LOG(__FUNCTION__, __LINE__, "Headers already sent! We need debug backtrace here.");
+
+ // Output debug trace
+ print("Headers are already sent! \n");
+ print("Please report this error at bugs.mxchange.org:
");
+ debug_print_backtrace();
+ die("
Thank you for your help finding bugs.");
+ } // END - if
+
// Output cached HTML code
$OUTPUT = ob_get_contents();
// Clear output buffer for later output
ob_end_clean();
- if ((EXT_IS_ACTIVE("rewrite", true)) && (function_exists('REWRITE_LINKS')) && ($CSS != "1") && ($CSS != "-1")) {
+ // Send HTTP header
+ header("HTTP/1.1 200");
+
+ // Used later
+ $now = gmdate('D, d M Y H:i:s') . ' GMT';
+
+ // General headers for no caching
+ header("Expired: " . $now); // RFC2616 - Section 14.21
+ header("Last-Modified: " . $now);
+ header("Cache-Control: no-store, no-cache, must-revalidate, pre-check=0, post-check=0, max-age=0"); // HTTP/1.1
+ header("Pragma: no-cache"); // HTTP/1.0
+ header("Connection: Close");
+
+ // Extension "rewrite" installed?
+ if ((EXT_IS_ACTIVE("rewrite")) && (function_exists('REWRITE_LINKS')) && ($CSS != "1") && ($CSS != "-1")) {
$OUTPUT = REWRITE_LINKS($OUTPUT);
- }
+ } // END - if
// Compile and run finished rendered HTML code
while (strpos($OUTPUT, '{!') > 0) {
@@ -144,26 +182,27 @@ function OUTPUT_HTML($HTML, $NEW_LINE = true) {
$eval = "\$newContent = \"".COMPILE_CODE(addslashes($OUTPUT))."\";";
@eval($eval);
+ // Was that eval okay?
if (empty($newContent)) {
// Something went wrong!
die("Evaluation error:
".htmlentities($eval)."
");
- }
+ } // END - if
$OUTPUT = $newContent;
- }
+ } // END - while
// Output code here, DO NOT REMOVE! ;-)
OUTPUT_RAW($OUTPUT);
} elseif ((OUTPUT_MODE == "render") && (!empty($OUTPUT))) {
// Rewrite links when rewrite extension is active
- if ((EXT_IS_ACTIVE("rewrite", true)) && (function_exists('REWRITE_LINKS')) && ($CSS != "1") && ($CSS != "-1")) {
+ if ((EXT_IS_ACTIVE("rewrite")) && (function_exists('REWRITE_LINKS')) && ($CSS != "1") && ($CSS != "-1")) {
$OUTPUT = REWRITE_LINKS($OUTPUT);
- }
+ } // END - if
// Compile and run finished rendered HTML code
while (strpos($OUTPUT, '{!') > 0) {
$eval = "\$OUTPUT = \"".COMPILE_CODE(addslashes($OUTPUT))."\";";
eval($eval);
- }
+ } // END - while
// Output code here, DO NOT REMOVE! ;-)
OUTPUT_RAW($OUTPUT);
@@ -173,29 +212,34 @@ function OUTPUT_HTML($HTML, $NEW_LINE = true) {
// Output the raw HTML code
function OUTPUT_RAW ($HTML) {
// Output stripped HTML code to avoid broken JavaScript code, etc.
- echo stripslashes($HTML);
+ echo stripslashes(stripslashes($HTML));
// Flush the output if only _OB_CACHING is not "on"
if (_OB_CACHING != "on") {
// Flush it
flush();
- }
+ } // END - if
}
// Add a fatal error message to the queue array
function ADD_FATAL ($message, $extra="") {
global $FATAL;
+
if (empty($extra)) {
// Regular text message to add to $FATAL
$FATAL[] = $message;
} else {
// $message is text with a mask plus extras to insert into the text
- $FATAL[] = sprintf($message, $extra);
+ $message = sprintf($message, $extra);
+ $FATAL[] = $message;
}
+
+ // Log fatal messages away
+ DEBUG_LOG(__FUNCTION__, __LINE__, " message={$message}");
}
// Load a template file and return it's content (only it's name; do not use ' or ")
-function LOAD_TEMPLATE($template, $return=false, $content="") {
+function LOAD_TEMPLATE($template, $return=false, $content=array()) {
// Add more variables which you want to use in your template files
global $DATA, $_CONFIG, $username;
@@ -203,25 +247,42 @@ function LOAD_TEMPLATE($template, $return=false, $content="") {
$template = strtolower($template);
// Count the template load
- if (!isset($_CONFIG['num_templates'])) $_CONFIG['num_templates'] = 0;
- $_CONFIG['num_templates']++;
+ incrementConfigEntry('num_templates');
+
+ // Prepare IP number and User Agent
+ $REMOTE_ADDR = GET_REMOTE_ADDR();
+ if (!defined('REMOTE_ADDR')) define('REMOTE_ADDR', $REMOTE_ADDR);
+ $HTTP_USER_AGENT = GET_USER_AGENT();
// Init some data
- $ACTION = SQL_ESCAPE($GLOBALS['action']);
- $WHAT = SQL_ESCAPE($GLOBALS['what']);
$ret = "";
if (empty($GLOBALS['refid'])) $GLOBALS['refid'] = 0;
- $REFID = $GLOBALS['refid'];
- // DEPRECATED!!!
+ // @DEPRECATED Try to rewrite the if() condition
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=%s LIMIT 1",
- array($GLOBALS['userid']), __FILE__, __LINE__);
- list($sex, $surname, $family) = SQL_FETCHROW($result);
+ $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__);
+
+ // Is content an array?
+ if (is_array($content)) {
+ // Merge data
+ $content = merge_array($content, SQL_FETCHARRAY($result));
+
+ // Translate gender
+ $content['gender'] = TRANSLATE_GENDER($content['gender']);
+ } else {
+ // DEPRECATED: Load data in direct variables
+ list($gender, $surname, $family, $email) = SQL_FETCHROW($result);
+
+ // Translate gender
+ $gender = TRANSLATE_GENDER($gender);
+ DEBUG_LOG(__FUNCTION__, __LINE__, sprintf("DEPRECATION-WARNING: content is not array (%s).", gettype($content)));
+ }
+
+ // Free result
SQL_FREERESULT($result);
- $salut = TRANSLATE_SEX($sex);
- }
+ } // END - if
// Generate date/time string
$date_time = MAKE_DATETIME(time(), "1");
@@ -288,10 +349,10 @@ function LOAD_TEMPLATE($template, $return=false, $content="") {
// Now does the final template exists?
if (FILE_READABLE($file)) {
// The local file does exists so we load it. :)
- $tmpl_file = implode("", file($file));
+ $tmpl_file = READ_FILE($file);
// Replace ' to our own chars to preventing them being quoted
- while (strpos($tmpl_file, "\'") !== false) { $tmpl_file = str_replace("\'", '{QUOT}', $tmpl_file); }
+ while (strpos($tmpl_file, "'") !== false) { $tmpl_file = str_replace("'", '{QUOT}', $tmpl_file); }
// Do we have to compile the code?
$ret = "";
@@ -312,12 +373,16 @@ function LOAD_TEMPLATE($template, $return=false, $content="") {
(".basename($file).")
".TEMPLATE_CONTENT."
-
".print_r($content, true)."
+
".print_r($content, true)."
".TEMPLATE_DATA."
-
".print_r($DATA, true)."
+
".print_r($DATA, true)."
";
}
+ // Remove content and data
+ unset($content);
+ unset($DATA);
+
// Do we have some content to output or return?
if (!empty($ret)) {
// Not empty so let's put it out! ;)
@@ -335,30 +400,45 @@ function LOAD_TEMPLATE($template, $return=false, $content="") {
}
// Send mail out to an email address
-function SEND_EMAIL($TO, $SUBJECT, $MSG, $HTML='N', $FROM="") {
+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 = \"".COMPILE_CODE(addslashes($SUBJECT))."\";";
+ $eval = "\$SUBJECT = html_entity_decode(\"".COMPILE_CODE(addslashes($SUBJECT))."\");";
eval($eval);
- $SUBJECT = html_entity_decode($SUBJECT);
// Set from header
if ((!eregi("@", $TO)) && ($TO > 0)) {
- // Value detected, load email from database
+ // Value detected, is the message extension installed?
if (EXT_IS_ACTIVE("msg")) {
ADD_MESSAGE_TO_BOX($TO, $SUBJECT, $MSG, $HTML);
return;
} else {
- $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);
+ // 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__);
+ //* DEBUG: */ print __FUNCTION__."(".__LINE__."):numRows=".SQL_NUMROWS($result_email)." \n";
+
+ // Does the user exist?
+ if (SQL_NUMROWS($result_email)) {
+ // Load email address
+ list($TO) = SQL_FETCHROW($result_email);
+ } else {
+ // Set webmaster
+ $TO = WEBMASTER;
+ }
+
+ // Free result
SQL_FREERESULT($result_email);
}
- } elseif ($TO == 0) {
+ } elseif ("$TO" == "0") {
// Is the webmaster!
$TO = WEBMASTER;
}
+ //* DEBUG: */ print __FUNCTION__."(".__LINE__."):TO={$TO} \n";
- // Not in PHPMailer-Mode
+ // Check for PHPMailer or debug-mode
if (!CHECK_PHPMAILER_USAGE()) {
+ // Not in PHPMailer-Mode
if (empty($FROM)) {
// Load email header template
$FROM = LOAD_EMAIL_TEMPLATE("header");
@@ -376,28 +456,33 @@ function SEND_EMAIL($TO, $SUBJECT, $MSG, $HTML='N', $FROM="") {
}
}
+ // Compile "TO"
+ $eval = "\$TO = \"".COMPILE_CODE(addslashes($TO))."\";";
+ eval($eval);
+
+ // Compile "MSG"
+ $eval = "\$MSG = \"".COMPILE_CODE(addslashes($MSG))."\";";
+ eval($eval);
+
// Fix HTML parameter (default is no!)
if (empty($HTML)) $HTML = "N";
if (isBooleanConstantAndTrue('DEBUG_MODE')) {
// In debug mode we want to display the mail instead of sending it away so we can debug this part
- echo "