X-Git-Url: https://git.mxchange.org/?p=mailer.git;a=blobdiff_plain;f=inc%2Ffunctions.php;h=af966907f678950999a0501f479ee3d47b96c567;hp=61aeeddf3813c7f85871d60e80c68efaee69a869;hb=d22205247313f4b67db5c9aa3aac07cd9d073bce;hpb=990143bc76b43047c3fa20b33580d345de3e7b75 diff --git a/inc/functions.php b/inc/functions.php index 61aeeddf38..af966907f6 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -48,7 +48,7 @@ function IS_INC_WRITEABLE($inc) { } // END - if // Test if we can append data - $fp = @fopen($fqfn, 'a'); + $fp = fopen($fqfn, 'a'); if ($inc == "dummy") { // Remove dummy file fclose($fp); @@ -114,8 +114,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 +141,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 +162,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 +194,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 +207,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 +249,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($GLOBALS['userid']), __FUNCTION__, __LINE__); // Is content an array? if (is_array($content)) { @@ -345,7 +347,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 +356,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).")
@@ -391,7 +393,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 +404,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? @@ -444,11 +446,11 @@ 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!) @@ -802,12 +804,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 +870,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."
@@ -901,7 +903,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 +913,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 +924,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 +934,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()))) { @@ -1218,12 +1221,12 @@ function ADD_SELECTION ($type, $DEFAULT, $prefix="", $id="0") { } // -function TRANSLATE_YESNO($yn) { +function TRANSLATE_YESNO ($yn) { // Default - $yn = "??? (".$yn.")"; + $translated = "??? (".$yn.")"; switch ($yn) { - case "Y": $yn = getMessage('YES'); break; - case "N": $yn = getMessage('NO'); break; + case "Y": $translated = getMessage('YES'); break; + case "N": $translated = getMessage('NO'); break; default: // Log unknown value DEBUG_LOG(__FUNCTION__, __LINE__, sprintf("Unknown value %s. Expected Y/N!", $yn)); @@ -1231,7 +1234,7 @@ function TRANSLATE_YESNO($yn) { } // Return it - return $yn; + return $translated; } // @@ -1598,11 +1601,11 @@ function SEND_ADMIN_EMAILS_PRO ($subj, $template, $content, $UID) { // Check which admin shall receive this mail $result = SQL_QUERY_ESC("SELECT DISTINCT admin_id FROM `{!_MYSQL_PREFIX!}_admins_mails` WHERE mail_template='%s' ORDER BY admin_id", - array($template), __FILE__, __LINE__); + array($template), __FUNCTION__, __LINE__); if (SQL_NUMROWS($result) == 0) { // Create new entry (to all admins) SQL_QUERY_ESC("INSERT INTO `{!_MYSQL_PREFIX!}_admins_mails` (admin_id, mail_template) VALUES (0, '%s')", - array($template), __FILE__, __LINE__); + array($template), __FUNCTION__, __LINE__); } else { // Load admin IDs... $aids = array(); @@ -1632,10 +1635,10 @@ function SEND_ADMIN_EMAILS_PRO ($subj, $template, $content, $UID) { } } elseif ($aid == "0") { // Select all email adresses - $result = SQL_QUERY("SELECT email FROM `{!_MYSQL_PREFIX!}_admins` ORDER BY `id`", __FILE__, __LINE__); + $result = SQL_QUERY("SELECT email FROM `{!_MYSQL_PREFIX!}_admins` ORDER BY `id`", __FUNCTION__, __LINE__); } else { // If Admin-ID is not "to-all" select - $result = SQL_QUERY_ESC("SELECT email FROM `{!_MYSQL_PREFIX!}_admins` WHERE id IN (%s) ORDER BY `id`", array($aid), __FILE__, __LINE__); + $result = SQL_QUERY_ESC("SELECT email FROM `{!_MYSQL_PREFIX!}_admins` WHERE id IN (%s) ORDER BY `id`", array($aid), __FUNCTION__, __LINE__); } } @@ -2294,7 +2297,7 @@ function DISPLAY_PARSING_TIME_FOOTER() { // Check wether a boolean constant is set // Taken from user comments in PHP documentation for function constant() -function isBooleanConstantAndTrue($constName) { // : Boolean +function isBooleanConstantAndTrue ($constName) { // : Boolean // Failed by default $res = false; @@ -2302,11 +2305,15 @@ function isBooleanConstantAndTrue($constName) { // : Boolean if (isset($GLOBALS['cache_array']['const'][$constName])) { // Use cache //* DEBUG: */ print __FUNCTION__."(".__LINE__."): ".$constName."-CACHE!
\n"; - $res = $GLOBALS['cache_array']['const'][$constName]; + $res = ($GLOBALS['cache_array']['const'][$constName] === true); } else { // Check constant //* DEBUG: */ print __FUNCTION__."(".__LINE__."): ".$constName."-RESOLVE!
\n"; - if (defined($constName)) $res = (constant($constName) === true); + if (defined($constName)) { + // Found! + //* DEBUG: */ print __FUNCTION__."(".__LINE__."): ".$constName."-FOUND!
\n"; + $res = (constant($constName) === true); + } // END - if // Set cache $GLOBALS['cache_array']['const'][$constName] = $res; @@ -2371,14 +2378,14 @@ function GET_CURR_THEME() { // Fix it to default $ret = "default"; } // END - if - } elseif ((!isBooleanConstantAndTrue('mxchange_installed')) && ((isBooleanConstantAndTrue('mxchange_installing')) || ($GLOBALS['output_mode'] == true)) && ((REQUEST_ISSET_GET(('theme'))) || (REQUEST_ISSET_POST(('theme'))))) { + } elseif ((!isInstalled()) && ((isInstalling()) || ($GLOBALS['output_mode'] == true)) && ((REQUEST_ISSET_GET(('theme'))) || (REQUEST_ISSET_POST(('theme'))))) { // Prepare FQFN for checking - $theme = sprintf("%stheme/%s/theme.php", constant('PATH'), SQL_ESCAPE(REQUEST_GET('theme'))); + $theme = sprintf("%stheme/%s/theme.php", constant('PATH'), REQUEST_GET(('theme'))); // Installation mode active if ((REQUEST_ISSET_GET(('theme'))) && (FILE_READABLE($theme))) { // Set cookie from URL data - set_session('mxchange_theme', SQL_ESCAPE(REQUEST_GET('theme'))); + set_session('mxchange_theme', REQUEST_GET(('theme'))); } elseif (FILE_READABLE(sprintf("%stheme/%s/theme.php", constant('PATH'), SQL_ESCAPE(REQUEST_POST('theme'))))) { // Set cookie from posted data set_session('mxchange_theme', SQL_ESCAPE(REQUEST_POST('theme'))); @@ -2422,7 +2429,7 @@ function THEME_GET_ID ($name) { } elseif (GET_EXT_VERSION("cache") != "0.1.8") { // Check if current theme is already imported or not $result = SQL_QUERY_ESC("SELECT id FROM `{!_MYSQL_PREFIX!}_themes` WHERE theme_path='%s' LIMIT 1", - array($name), __FILE__, __LINE__); + array($name), __FUNCTION__, __LINE__); // Entry found? if (SQL_NUMROWS($result) == 1) { @@ -2568,19 +2575,8 @@ function getActualVersion ($type = 0) { // Loads an include file and logs any missing files for debug purposes function LOAD_INC ($INC) { - // Get constant path - $PATH = constant('PATH'); - - // Use the include file name directly - // @TODO Try to find all locations where an FQFN is given to these two - // @TODO functions and avoid it. - $FQFN = $INC; - - // Check if PATH is in $INC - if (substr($INC, 0, $PATH) != $PATH) { - // Add it. This is why we need a trailing slash in config.php - $FQFN = $PATH . $INC; - } // END - if + // Add the path. This is why we need a trailing slash in config.php + $FQFN = constant('PATH') . $INC; // Is the include file there? if (!FILE_READABLE($FQFN)) { @@ -2596,12 +2592,12 @@ function LOAD_INC ($INC) { // Loads an include file once function LOAD_INC_ONCE ($INC) { // Is it not loaded? - if (!isset($GLOBALS['cache_array']['load_once'][$INC])) { + if (!isset($GLOBALS['load_once'][$INC])) { // Then try to load it LOAD_INC($INC); // And mark it as loaded - $GLOBALS['cache_array']['load_once'][$INC] = "loaded"; + $GLOBALS['load_once'][$INC] = "loaded"; } // END - if } @@ -2613,7 +2609,7 @@ function debug_get_printable_backtrace () { // Get and prepare backtrace for output $backtraceArray = debug_backtrace(); foreach ($backtraceArray as $key => $trace) { - if (!isset($trace['file'])) $trace['file'] = __FILE__; + if (!isset($trace['file'])) $trace['file'] = __FUNCTION__; if (!isset($trace['line'])) $trace['line'] = __LINE__; if (!isset($trace['args'])) $trace['args'] = array(); $backtrace .= "
  • ".basename($trace['file']).":".$trace['line'].", ".$trace['function']."(".count($trace['args']).")
  • \n"; @@ -2679,7 +2675,7 @@ function convertCodeToMessage ($code) { case constant('CODE_EXTENSION_PROBLEM'): if (REQUEST_ISSET_GET(('ext'))) { - $msg = sprintf(getMessage('EXTENSION_PROBLEM_EXT_INACTIVE'), SQL_ESCAPE(REQUEST_GET('ext'))); + $msg = sprintf(getMessage('EXTENSION_PROBLEM_EXT_INACTIVE'), REQUEST_GET(('ext'))); } else { $msg = getMessage('EXTENSION_PROBLEM_UNSET_EXT'); } @@ -2708,7 +2704,7 @@ function REDIRCT_ON_UNINSTALLED_EXTENSION ($ext_name) { // Generate a "link" for the given admin id (aid) function GENERATE_AID_LINK ($aid) { // No assigned admin is default - $admin = "
    {--ADMIN_NO_ADMIN_ASSIGNED--}
    "; + $admin = "{--ADMIN_NO_ADMIN_ASSIGNED--}"; // Zero? = Not assigned if ($aid == "0") { @@ -2875,12 +2871,12 @@ function changeDataInFile ($FQFN, $comment, $prefix, $suffix, $DATA, $seek=0) { $tmp = $FQFN.".tmp"; // Open the source file - $fp = @fopen($FQFN, 'r') or OUTPUT_HTML("READ: ".$FQFN."
    "); + $fp = fopen($FQFN, 'r') or OUTPUT_HTML("READ: ".$FQFN."
    "); // Is the resource valid? if (is_resource($fp)) { // Open temporary file - $fp_tmp = @fopen($tmp, 'w') or OUTPUT_HTML("WRITE: ".$tmp."
    "); + $fp_tmp = fopen($tmp, 'w') or OUTPUT_HTML("WRITE: ".$tmp."
    "); // Is the resource again valid? if (is_resource($fp_tmp)) { @@ -2915,21 +2911,21 @@ function changeDataInFile ($FQFN, $comment, $prefix, $suffix, $DATA, $seek=0) { if (($done) && ($found)) { // Copy back tmp file and delete tmp :-) - @copy($tmp, $FQFN); - @unlink($tmp); - define('_FATAL', false); + copy($tmp, $FQFN); + return unlink($tmp); } elseif (!$found) { OUTPUT_HTML("CHANGE: 404!"); - define('_FATAL', true); } else { OUTPUT_HTML("TMP: UNDONE!"); - define('_FATAL', true); } } } else { // File not found, not readable or writeable OUTPUT_HTML("404: ".$FQFN."
    "); } + + // An error was detected! + return false; } // Send notification to admin function SEND_ADMIN_NOTIFICATION($subject, $templateName, $content=array(), $uid="0") { @@ -2979,13 +2975,13 @@ function GET_DIR_AS_ARRAY ($baseDir, $prefix) { $INCs = array(); // Open directory - $dirPointer = opendir($baseDir) or mxchange_die("Cannot read ".basename($baseDir)." path!"); + $dirPointer = opendir(constant('PATH') . $baseDir) or mxchange_die("Cannot read ".basename($baseDir)." path!"); // Read all entries while ($baseFile = readdir($dirPointer)) { // Load file only if extension is active - // Make full path - $FQFN = $baseDir.$baseFile; + $INC = $baseDir.$baseFile; + $FQFN = constant('PATH') . $INC; // Is this a valid reset file? //* DEBUG: */ print __FUNCTION__."(".__LINE__."):baseDir={$baseDir},prefix={$prefix},baseFile={$baseFile}
    \n"; @@ -2999,10 +2995,10 @@ function GET_DIR_AS_ARRAY ($baseDir, $prefix) { // Is the extension valid and active? if (($extId > 0) && (EXT_IS_ACTIVE($extName))) { // Then add this file - $INCs[] = $FQFN; + $INCs[] = $INC; } elseif ($extId == 0) { // Add non-extension files as well - $INCs[] = $FQFN; + $INCs[] = $INC; } } // END - if } // END - while @@ -3026,7 +3022,7 @@ function RESET_ADD_INCLUDES () { } // END - if // Get more daily reset scripts - $INC_POOL = GET_DIR_AS_ARRAY(constant('PATH')."inc/reset/", "reset_"); + $INC_POOL = GET_DIR_AS_ARRAY("inc/reset/", "reset_"); // Update database if (!defined('DEBUG_RESET')) UPDATE_CONFIG("last_update", time()); @@ -3037,7 +3033,7 @@ function RESET_ADD_INCLUDES () { // Has it changed? if (getConfig('last_week') != $currWeek) { // Include weekly reset scripts - $INC_POOL = merge_array($INC_POOL, GET_DIR_AS_ARRAY(constant('PATH')."inc/weekly/", "weekly_")); + $INC_POOL = merge_array($INC_POOL, GET_DIR_AS_ARRAY("inc/weekly/", "weekly_")); // Update config if (!defined('DEBUG_WEEKLY')) UPDATE_CONFIG("last_week", $currWeek); @@ -3049,7 +3045,7 @@ function RESET_ADD_INCLUDES () { // Has it changed? if (getConfig('last_month') != $currMonth) { // Include monthly reset scripts - $INC_POOL = merge_array($INC_POOL, GET_DIR_AS_ARRAY(constant('PATH')."inc/monthly/", "monthly_")); + $INC_POOL = merge_array($INC_POOL, GET_DIR_AS_ARRAY("inc/monthly/", "monthly_")); // Update config if (!defined('DEBUG_MONTHLY')) UPDATE_CONFIG("last_month", $currMonth); @@ -3384,6 +3380,21 @@ function DETERMINE_REFID () { return $GLOBALS['refid']; } +// Check wether we are installing +function isInstalling () { + return (isset($GLOBALS['mxchange_installing'])); +} + +// Check wether this script is installed +function isInstalled () { + return isBooleanConstantAndTrue('mxchange_installed'); +} + +// Check wether an admin is registered +function isAdminRegistered () { + return isBooleanConstantAndTrue('admin_registered'); +} + ////////////////////////////////////////////////// // AUTOMATICALLY RE-GENERATED MISSING FUNCTIONS // //////////////////////////////////////////////////