-//
-function LOAD_EMAIL_TEMPLATE($template, $content=array(), $UID="0") {
- global $DATA, $REPLACER, $_CONFIG;
-
- // Make sure all template names are lowercase!
- $template = strtolower($template);
-
- // Default "nickname" if extension is not installed
- $nick = "---";
-
- // Keept for backward-compatiblity (please replace these variables against our new {!CONST!} syntax!)
- // No longer used: $MAIN_TITLE = MAIN_TITLE; $URL = constant('URL'); $WEBMASTER = constant('WEBMASTER');
-
- // Prepare IP number and User Agent
- $REMOTE_ADDR = GET_REMOTE_ADDR();
- $HTTP_USER_AGENT = GET_USER_AGENT();
-
- // Default admin
- $ADMIN = 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 = 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__."(<font color=\"#0000aa\">".__LINE__."</font>):UID={$UID},template={$template},content[]=".gettype($content)."<br />\n";
- if (($UID > 0) && (is_array($content))) {
- // If nickname extension is installed, fetch nickname as well
- if (EXT_IS_ACTIVE("nickname")) {
- //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):NICKNAME!<br />\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__);
- } else {
- //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):NO-NICK!<br />\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__);
- }
-
- // Fetch and merge data
- //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):content()=".count($content)." - PRE<br />\n";
- $content = merge_array($content, SQL_FETCHARRAY($result));
- //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):content()=".count($content)." - AFTER<br />\n";
-
- // Free result
- SQL_FREERESULT($result);
- } // END - if
-
- // Translate M to male or F to female if present
- if (isset($content['gender'])) $content['gender'] = TRANSLATE_GENDER($content['gender']);
-
- // Overwrite email from data if present
- if (isset($content['email'])) $email = $content['email'];
-
- // Store email for some functions in global data array
- $DATA['email'] = $email;
-
- // Base directory
- $BASE = sprintf("%stemplates/%s/emails/", constant('PATH'), GET_LANGUAGE());
-
- // Check for admin/guest/member templates
- if (strpos($template, "admin_") > -1) {
- // Admin template found
- $file = $BASE."admin/".$template.".tpl";
- } elseif (strpos($template, "guest_") > -1) {
- // Guest template found
- $file = $BASE."guest/".$template.".tpl";
- } elseif (strpos($template, "member_") > -1) {
- // Member template found
- $file = $BASE."member/".$template.".tpl";
- } else {
- // Test for extension
- $test = substr($template, 0, strpos($template, "_"));
- if (EXT_IS_ACTIVE($test)) {
- // Set extra path to extension's name
- $file = $BASE.$test."/".$template.".tpl";
- } else {
- // No special filename
- $file = $BASE.$template.".tpl";
- }
- }
-
- // Does the special template exists?
- if (!FILE_READABLE($file)) {
- // Reset to default template
- $file = $BASE.$template.".tpl";
- } // END - if
-
- // Now does the final template exists?
- $newContent = "";
- if (FILE_READABLE($file)) {
- // The local file does exists so we load it. :)
- $tmpl_file = READ_FILE($file);
- $tmpl_file = addslashes($tmpl_file);
-
- // Run code
- $tmpl_file = "\$newContent=html_entity_decode(\"".COMPILE_CODE($tmpl_file)."\");";
- @eval($tmpl_file);
- } elseif (!empty($template)) {
- // Template file not found!
- $newContent = TEMPLATE_404.": ".$template."<br />
-".TEMPLATE_CONTENT."
-<pre>".print_r($content, true)."</pre>
-".TEMPLATE_DATA."
-<pre>".print_r($DATA, true)."</pre>
-<br /><br />";
-
- // Debug mode not active? Then remove the HTML tags
- if (!DEBUG_MODE) $newContent = strip_tags($newContent);
- } else {
- // No template name supplied!
- $newContent = NO_TEMPLATE_SUPPLIED;
- }
-
- // Is there some content?
- if (empty($newContent)) {
- // Compiling failed
- $newContent = "Compiler error for template {$template}!\nUncompiled content:\n".$tmpl_file;
- // Add last error if the required function exists
- if (function_exists('error_get_last')) $newContent .= "\n--------------------------------------\nDebug:\n".print_r(error_get_last(), true)."--------------------------------------\nPlease don't alter these informations!\nThanx.";
- } // END - if