- // 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)), __FUNCTION__, __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)), __FUNCTION__, __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'] = translateGender($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
- $basePath = sprintf("%stemplates/%s/emails/", constant('PATH'), getLanguage());
-
- // Check for admin/guest/member templates
- if (strpos($template, 'admin_') > -1) {
- // Admin template found
- $FQFN = $basePath.'admin/' . $template.'.tpl';
- } elseif (strpos($template, 'guest_') > -1) {
- // Guest template found
- $FQFN = $basePath.'guest/' . $template.'.tpl';
- } elseif (strpos($template, 'member_') > -1) {
- // Member template found
- $FQFN = $basePath.'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
- $FQFN = $basePath . $test.'/' . $template.'.tpl';
- } else {
- // No special filename
- $FQFN = $basePath . $template.'.tpl';
- }
- }
-
- // Does the special template exists?
- if (!isFileReadable($FQFN)) {
- // Reset to default template
- $FQFN = $basePath . $template.'.tpl';
- } // END - if
-
- // Now does the final template exists?
- $newContent = '';
- if (isFileReadable($FQFN)) {
- // The local file does exists so we load it. :)
- $tmpl_file = readFromFile($FQFN);
- $tmpl_file = SQL_ESCAPE($tmpl_file);
-
- // Run code
- $tmpl_file = "\$newContent = decodeEntities(\"".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 (!isDebugModeEnabled()) $newContent = strip_tags($newContent);
- } else {
- // No template name supplied!
- $newContent = getMessage('NO_TEMPLATE_SUPPLIED');
- }