{--FATAL_ERROR--}: {--LANG_NO_RENDER_DIRECT--}"); break; } } elseif ((constant('_OB_CACHING') == "on") && (isset($GLOBALS['footer_sent'])) && ($GLOBALS['footer_sent'] == 1)) { // Headers already sent? if (headers_sent()) { // Log this error DEBUG_LOG(__FUNCTION__, __LINE__, "Headers already sent! We need debug backtrace here."); // Trigger an user error debug_report_bug("Headers are already sent!"); } // END - if // Output cached HTML code $OUTPUT = ob_get_contents(); // Clear output buffer for later output if output is found if (!empty($OUTPUT)) { clearOutputBuffer(); } // END - if // 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")) && ($GLOBALS['output_mode'] != "1") && ($GLOBALS['output_mode'] != "-1")) { $OUTPUT = REWRITE_LINKS($OUTPUT); } // END - if // Compile and run finished rendered HTML code while (strpos($OUTPUT, '{!') > 0) { // Prepare the content and eval() it... $newContent = ""; $eval = "\$newContent = \"".COMPILE_CODE(smartAddSlashes($OUTPUT))."\";"; eval($eval); // Was that eval okay? if (empty($newContent)) { // Something went wrong! mxchange_die("Evaluation error:
".htmlentities($eval).""); } // END - if $OUTPUT = $newContent; } // END - while // Output code here, DO NOT REMOVE! ;-) OUTPUT_RAW($OUTPUT); } elseif ((constant('OUTPUT_MODE') == "render") && (!empty($OUTPUT))) { // Rewrite links when rewrite extension is active if ((EXT_IS_ACTIVE("rewrite")) && ($GLOBALS['output_mode'] != "1") && ($GLOBALS['output_mode'] != "-1")) { $OUTPUT = REWRITE_LINKS($OUTPUT); } // END - if // Compile and run finished rendered HTML code while (strpos($OUTPUT, '{!') > 0) { $eval = "\$OUTPUT = \"".COMPILE_CODE(smartAddSlashes($OUTPUT))."\";"; eval($eval); } // END - while // Output code here, DO NOT REMOVE! ;-) OUTPUT_RAW($OUTPUT); } } // Output the raw HTML code function OUTPUT_RAW ($HTML) { // Output stripped HTML code to avoid broken JavaScript code, etc. echo stripslashes(stripslashes($HTML)); // Flush the output if only constant('_OB_CACHING') is not "on" if (constant('_OB_CACHING') != "on") { // Flush it flush(); } // END - if } // Init fatal message array function initFatalMessages () { $GLOBALS['fatal_messages'] = array(); } // Getter for whole fatal error messages function getFatalArray () { return $GLOBALS['fatal_messages']; } // Add a fatal error message to the queue array function addFatalMessage ($F, $L, $message, $extra="") { if (is_array($extra)) { // Multiple extras for a message with masks $message = call_user_func_array('sprintf', $extra); } elseif (!empty($extra)) { // $message is text with a mask plus extras to insert into the text $message = sprintf($message, $extra); } // Add message to $GLOBALS['fatal_messages'] $GLOBALS['fatal_messages'][] = $message; // Log fatal messages away DEBUG_LOG($F, $L, " message={$message}"); } // Getter for total fatal message count function getTotalFatalErrors () { // Init coun $count = 0; // Do we have at least the first entry? if (!empty($GLOBALS['fatal_messages'][0])) { // Get total count $count = count($GLOBALS['fatal_messages']); } // END - if // Return value return $count; } // Load a template file and return it's content (only it's name; do not use ' or ") function LOAD_TEMPLATE ($template, $return=false, $content=array()) { // Add more variables which you want to use in your template files global $DATA, $_CONFIG, $username; // Make all template names lowercase $template = strtolower($template); // Count the template load 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 $ret = ""; if (empty($GLOBALS['refid'])) $GLOBALS['refid'] = 0; // @DEPRECATED Try to rewrite the if() condition 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(getUserId()), __FUNCTION__, __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 // @TODO Fine all templates which are using these direct variables and rewrite them. // @TODO After this step is done, this else-block is history 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); } // END - if // Generate date/time string $date_time = MAKE_DATETIME(time(), "1"); // Base directory $BASE = sprintf("%stemplates/%s/html/", constant('PATH'), GET_LANGUAGE()); $MODE = ""; // Check for admin/guest/member templates if (strpos($template, "admin_") > -1) { // Admin template found $MODE = "admin/"; } elseif (strpos($template, "guest_") > -1) { // Guest template found $MODE = "guest/"; } elseif (strpos($template, "member_") > -1) { // Member template found $MODE = "member/"; } elseif (strpos($template, "install_") > -1) { // Installation template found $MODE = "install/"; } elseif (strpos($template, "ext_") > -1) { // Extension template found $MODE = "ext/"; } elseif (strpos($template, "la_") > -1) { // "Logical-area" template found $MODE = "la/"; } else { // Test for extension $test = substr($template, 0, strpos($template, "_")); if (EXT_IS_ACTIVE($test)) { // Set extra path to extension's name $MODE = $test."/"; } } //////////////////////// // Generate file name // //////////////////////// $FQFN = $BASE.$MODE.$template.".tpl"; if ((!empty($GLOBALS['what'])) && ((strpos($template, "_header") > 0) || (strpos($template, "_footer") > 0)) && (($MODE == "guest/") || ($MODE == "member/") || ($MODE == "admin/"))) { // Select what depended header/footer template file for admin/guest/member area $file2 = sprintf("%s%s%s_%s.tpl", $BASE, $MODE, $template, SQL_ESCAPE($GLOBALS['what']) ); // Probe for it... if (FILE_READABLE($file2)) $FQFN = $file2; // Remove variable from memory unset($file2); } // Does the special template exists? if (!FILE_READABLE($FQFN)) { // Reset to default template $FQFN = $BASE.$template.".tpl"; } // END - if // Now does the final template exists? if (FILE_READABLE($FQFN)) { // The local file does exists so we load it. :) $tmpl_file = READ_FILE($FQFN); // Replace ' to our own chars to preventing them being quoted while (strpos($tmpl_file, "'") !== false) { $tmpl_file = str_replace("'", '{QUOT}', $tmpl_file); } // Do we have to compile the code? $ret = ""; if ((strpos($tmpl_file, "\$") !== false) || (strpos($tmpl_file, '{--') !== false) || (strpos($tmpl_file, '--}') > 0)) { // Okay, compile it! $tmpl_file = "\$ret=\"".COMPILE_CODE(smartAddSlashes($tmpl_file))."\";"; eval($tmpl_file); } else { // Simply return loaded code $ret = $tmpl_file; } // Add surrounding HTML comments to help finding bugs faster $ret = "\n".$ret."\n"; } elseif ((IS_ADMIN()) || ((isInstalling()) && (!isInstalled()))) { // Only admins shall see this warning or when installation mode is active $ret = "
".print_r($content, true)."".TEMPLATE_DATA."
".print_r($DATA, true)."
".htmlentities(trim($FROM))." To : ".$TO." Subject : ".$SUBJECT." Message : ".$MSG."\n"); } elseif (($HTML == "Y") && (EXT_IS_ACTIVE("html_mail"))) { // Send mail as HTML away SEND_HTML_EMAIL($TO, $SUBJECT, $MSG, $FROM); } elseif (!empty($TO)) { // Send Mail away SEND_RAW_EMAIL($TO, $SUBJECT, $MSG, $FROM); } elseif ($HTML == "N") { // Problem found! SEND_RAW_EMAIL(constant('WEBMASTER'), "[PROBLEM:]".$SUBJECT, $MSG, $FROM); } } // 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')) && (constant('SMTP_HOSTNAME') != "") && (constant('SMTP_USER') != "")); } /* * Send out a raw email with PHPMailer class or legacy mail() command */ function SEND_RAW_EMAIL ($to, $subject, $msg, $from) { // Shall we use PHPMailer class or legacy mode? if (CHECK_PHPMAILER_USAGE()) { // Use PHPMailer class with SMTP enabled LOAD_INC_ONCE("inc/phpmailer/class.phpmailer.php"); LOAD_INC_ONCE("inc/phpmailer/class.smtp.php"); // get new instance $mail = new PHPMailer(); $mail->PluginDir = sprintf("%sinc/phpmailer/", constant('PATH')); $mail->IsSMTP(); $mail->SMTPAuth = true; $mail->Host = constant('SMTP_HOSTNAME'); $mail->Port = 25; $mail->Username = constant('SMTP_USER'); $mail->Password = constant('SMTP_PASSWORD'); if (empty($from)) { $mail->From = constant('WEBMASTER'); } else { $mail->From = $from; } $mail->FromName = constant('MAIN_TITLE'); $mail->Subject = $subject; if ((EXT_IS_ACTIVE("html_mail")) && (strip_tags($msg) != $msg)) { $mail->Body = $msg; $mail->AltBody = "Your mail program required HTML support to read this mail!"; $mail->WordWrap = 70; $mail->IsHTML(true); } else { $mail->Body = decodeEntities($msg); } $mail->AddAddress($to, ""); $mail->AddReplyTo(constant('WEBMASTER'), constant('MAIN_TITLE')); $mail->AddCustomHeader("Errors-To:".constant('WEBMASTER')); $mail->AddCustomHeader("X-Loop:".constant('WEBMASTER')); $mail->Send(); } else { // Use legacy mail() command @mail($to, $subject, decodeEntities($msg), $from); } } // // Generate a password in a specified length or use default password length function GEN_PASS ($LEN = 0) { // Auto-fix invalid length of zero if ($LEN == 0) $LEN = getConfig('pass_len'); // Initialize array with all allowed chars $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,-,+,_,/"); // Start creating password $PASS = ""; for ($i = 0; $i < $LEN; $i++) { $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 if (strlen($PASS) <= 40) { // Also scramble the password $PASS = scrambleString($PASS); } // END - if // Return the password return $PASS; } // function MAKE_DATETIME ($time, $mode="0") { if ($time == 0) { // Never happend return NEVER_HAPPENED; } else { // Filter out numbers $time = bigintval($time); } switch (GET_LANGUAGE()) { case "de": // German date / time format switch ($mode) { case "0": $ret = date("d.m.Y \u\m H:i \U\h\\r", $time); break; case "1": $ret = strtolower(date("d.m.Y - H:i", $time)); break; case "2": $ret = date("d.m.Y|H:i", $time); break; case "3": $ret = date("d.m.Y", $time); break; default: DEBUG_LOG(__FUNCTION__, __LINE__, sprintf("Invalid date mode %s detected.", $mode)); break; } break; default: // Default is the US date / time format! switch ($mode) { case "0": $ret = date("r", $time); break; case "1": $ret = date("Y-m-d - g:i A", $time); break; case "2": $ret = date("y-m-d|H:i", $time); break; case "3": $ret = date("y-m-d", $time); break; default: DEBUG_LOG(__FUNCTION__, __LINE__, sprintf("Invalid date mode %s detected.", $mode)); break; } } return $ret; } // Translates the american decimal dot into a german comma function TRANSLATE_COMMA ($dotted, $cut=true, $max=0) { // Default is 3 you can change this in admin area "Misc -> Misc Options" if (!isConfigEntrySet('max_comma')) setConfigEntry('max_comma', "3"); // Use from config is default $maxComma = getConfig('max_comma'); // Use from parameter? if ($max > 0) $maxComma = $max; // Cut zeros off? if (($cut) && ($max == 0)) { // Test for commata if in cut-mode $com = explode(".", $dotted); if (count($com) < 2) { // Don't display commatas even if there are none... ;-) $maxComma = 0; } } // END - if // Debug log //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "dotted={$dotted},maxComma={$maxComma}"); // Translate it now switch (GET_LANGUAGE()) { case "de": $dotted = number_format($dotted, $maxComma, ",", "."); break; default: $dotted = number_format($dotted, $maxComma, ".", ","); break; } // Return translated value return $dotted; } // function DEREFERER ($URL) { // Don't de-refer our own links! if (substr($URL, 0, strlen(URL)) != URL) { // De-refer this link $URL = "modules.php?module=loader&url=".encodeString(compileUriCode($URL)); } // END - if // Return link return $URL; } // Translate Uni*-like gender to human-readable function TRANSLATE_GENDER ($gender) { // Default $ret = "!{$gender}!"; // Male/female or company? switch ($gender) { case "M": $ret = getMessage('GENDER_M'); break; case "F": $ret = getMessage('GENDER_F'); break; case "C": $ret = getMessage('GENDER_C'); break; default: // Log unknown gender DEBUG_LOG(__FUNCTION__, __LINE__, sprintf("Unknown gender %s detected.", $gender)); break; } // Return translated gender return $ret; } // function FRAMETESTER ($URL) { // Prepare frametester URL $frametesterUrl = sprintf("%s/modules.php?module=frametester&url=%s", URL, encodeString(compileUriCode($URL)) ); return $frametesterUrl; } // function SELECTION_COUNT ($array) { $ret = 0; if (is_array($array)) { foreach ($array as $key => $selected) { if (!empty($selected)) $ret++; } } return $ret; } // function IMG_CODE ($code, $type, $DATA, $uid) { return ""; } // function TRANSLATE_STATUS ($status) { switch ($status) { case "UNCONFIRMED": case "CONFIRMED": case "LOCKED": $ret = getMessage(sprintf("ACCOUNT_%s", $status)); break; case "": case null: $ret = getMessage('ACCOUNT_DELETED'); break; default: DEBUG_LOG(__FUNCTION__, __LINE__, sprintf("Unknown status %s detected.", $status)); $ret = sprintf(getMessage('UNKNOWN_STATUS"'), $status); break; } // Return it return $ret; } // function GET_LANGUAGE() { // Set default return value to default language from config $ret = constant('DEFAULT_LANG'); // Init variable $lang = ""; // Is the variable set if (REQUEST_ISSET_GET(('mx_lang'))) { // Accept only first 2 chars $lang = substr(REQUEST_GET('mx_lang'), 0, 2); } elseif (isset($GLOBALS['cache_array']['language'])) { // Use cached $ret = $GLOBALS['cache_array']['language']; } elseif (!empty($lang)) { // Check if main language file does exist if (FILE_READABLE(constant('PATH')."inc/language/".$lang.".php")) { // Okay found, so let's update cookies SET_LANGUAGE($lang); } } elseif (!isSessionVariableSet('mx_lang')) { // Return stored value from cookie $ret = get_session('mx_lang'); // Fixes a warning before the session has the mx_lang constant if (empty($ret)) $ret = constant('DEFAULT_LANG'); } // Cache entry $GLOBALS['cache_array']['language'] = $ret; // Return value return $ret; } // function SET_LANGUAGE ($lang) { // Accept only first 2 chars! $lang = substr(SQL_ESCAPE(strip_tags($lang)), 0, 2); // Set cookie set_session('mx_lang', $lang); } // function LOAD_EMAIL_TEMPLATE($template, $content=array(), $UID="0") { global $DATA, $_CONFIG; // Make sure all template names are lowercase! $template = strtolower($template); // Default "nickname" if extension is not installed $nick = "---"; // Prepare IP number and User Agent $REMOTE_ADDR = GET_REMOTE_ADDR(); $HTTP_USER_AGENT = GET_USER_AGENT(); // Default admin $ADMIN = constant('MAIN_TITLE'); // Is the admin logged in? if (IS_ADMIN()) { // Get admin id $aid = GET_CURRENT_ADMIN_ID(); // Load Admin data $ADMIN = GET_ADMIN_EMAIL($aid); } // END - if // Neutral email address is default $email = constant('WEBMASTER'); // Expiration in a nice output format if (getConfig('auto_purge') == 0) { // Will never expire! $EXPIRATION = getMessage('MAIL_WILL_NEVER_EXPIRE'); } else { // Create nice date string $EXPIRATION = CREATE_FANCY_TIME(getConfig('auto_purge')); } // Is content an array? if (is_array($content)) { // Add expiration to array, $EXPIRATION is now deprecated! $content['expiration'] = $EXPIRATION; } // END - if // Load user's data //* DEBUG: */ print __FUNCTION__."(".__LINE__."):UID={$UID},template={$template},content[]=".gettype($content)."
".print_r($content, true)."{--TEMPLATE_DATA--}
".print_r($DATA, true)."