X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;ds=sidebyside;f=inc%2Ffunctions.php;h=e9eb6681020ff46b822479f1b51822ea084c3321;hb=a4fc56f660a422a080ff241bd86b772a5b5d0c53;hp=0f4f995d6d2124d2ba368fc2164604d3d6b702fd;hpb=d997f1621c6e6e0427166bd96690e0825387dadd;p=mailer.git
diff --git a/inc/functions.php b/inc/functions.php
index 0f4f995d6d..e9eb668102 100644
--- a/inc/functions.php
+++ b/inc/functions.php
@@ -32,18 +32,27 @@
************************************************************************/
// 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');
+ // 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");
+ return @unlink($fqfn);
} else {
// Close all other files
return @fclose($fp);
@@ -53,6 +62,7 @@ function is_INCWritable($inc) {
// Open a table (you may want to add some header stuff here)
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... :-)
if (empty($CLASS)) {
// Class is empty so count one up and create a class
@@ -132,9 +142,10 @@ function OUTPUT_HTML($HTML, $NEW_LINE = true) {
// Clear output buffer for later output
ob_end_clean();
- if ((EXT_IS_ACTIVE("rewrite", true)) && (function_exists('REWRITE_LINKS')) && ($CSS != "1") && ($CSS != "-1")) {
+ // 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) {
@@ -143,26 +154,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);
@@ -172,29 +184,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;
@@ -206,21 +223,33 @@ function LOAD_TEMPLATE($template, $return=false, $content="") {
$_CONFIG['num_templates']++;
// 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 remove this if() block
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",
+ $result = SQL_QUERY_ESC("SELECT gender, surname, family, email FROM "._MYSQL_PREFIX."_user_data WHERE userid=%s LIMIT 1",
array($GLOBALS['userid']), __FILE__, __LINE__);
- list($sex, $surname, $family) = SQL_FETCHROW($result);
+
+ // Is content an array?
+ if (is_array($content)) {
+ // Merge data
+ $content = array_merge($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);
+ }
+
+ // Free result
SQL_FREERESULT($result);
- $salut = TRANSLATE_SEX($sex);
- }
+ } // END - if
// Generate date/time string
$date_time = MAKE_DATETIME(time(), "1");
@@ -272,20 +301,20 @@ function LOAD_TEMPLATE($template, $return=false, $content="") {
);
// Probe for it...
- if (file_exists($file2)) $file = $file2;
+ if (FILE_READABLE($file2)) $file = $file2;
// Remove variable from memory
unset($file2);
}
// Does the special template exists?
- if ((!file_exists($file)) || (!is_readable($file))) {
+ if (!FILE_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_READABLE($file)) {
// The local file does exists so we load it. :)
$tmpl_file = implode("", file($file));
@@ -311,12 +340,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! ;)
@@ -334,27 +367,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)) {
- // Value detected, load email from database
+ if ((!eregi("@", $TO)) && ($TO > 0)) {
+ // Value detected, is the message extension installed?
if (EXT_IS_ACTIVE("msg")) {
ADD_MESSAGE_TO_BOX($TO, $SUBJECT, $MSG, $HTML);
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__);
- list($TO) = SQL_FETCHROW($result_email);
+ //* 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") {
+ // 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");
@@ -372,28 +423,36 @@ 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 "