+function loadTemplate ($template, $return=false, $content=array()) {
+ // @TODO Remove this sanity-check if all is fine
+ if (!is_bool($return)) debug_report_bug('return is not bool (' . gettype($return) . ')');
+
+ // @TODO Try to rewrite all $DATA to $content
+ global $DATA;
+
+ // Do we have cache?
+ if (!isset($GLOBALS['template_eval'][$template])) {
+ // Add more variables which you want to use in your template files
+ $username = getUsername();
+
+ // Make all template names lowercase
+ $template = strtolower($template);
+
+ // Count the template load
+ incrementConfigEntry('num_templates');
+
+ // Init some data
+ $ret = '';
+ if (empty($GLOBALS['refid'])) $GLOBALS['refid'] = 0;
+
+ // Generate date/time string
+ $date_time = generateDateTime(time(), '1');
+
+ // Is content an array
+ if (is_array($content)) $content['date_time'] = $date_time;
+
+ // @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'] = translateGender($content['gender']);
+ } else {
+ // @DEPRECATED
+ // @TODO Find 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 = translateGender($gender);
+ logDebugMessage(__FUNCTION__, __LINE__, sprintf("DEPRECATION-WARNING: content is not array [%s], template=%s.", gettype($content), $template));
+ }
+
+ // Free result
+ SQL_FREERESULT($result);
+ } // END - if
+
+ // Base directory
+ $basePath = sprintf("%stemplates/%s/html/", getConfig('PATH'), getLanguage());
+ $mode = '';
+
+ // Check for admin/guest/member templates
+ if (substr($template, 0, 6) == 'admin_') {
+ // Admin template found
+ $mode = 'admin/';
+ } elseif (substr($template, 0, 6) == 'guest_') {
+ // Guest template found
+ $mode = 'guest/';
+ } elseif (substr($template, 0, 7) == 'member_') {
+ // Member template found
+ $mode = 'member/';
+ } elseif (substr($template, 0, 8) == 'install_') {
+ // Installation template found
+ $mode = 'install/';
+ } elseif (substr($template, 0, 4) == 'ext_') {
+ // Extension template found
+ $mode = 'ext/';
+ } elseif (substr($template, 0, 3) == 'la_') {
+ // 'Logical-area' template found
+ $mode = 'la/';
+ } elseif (substr($template, 0, 3) == 'js_') {
+ // JavaScript template found
+ $mode = 'js/';
+ } elseif (substr($template, 0, 5) == 'menu_') {
+ // Menu template found
+ $mode = 'menu/';
+ } else {
+ // Test for extension
+ $test = substr($template, 0, strpos($template, '_'));
+
+ // Probe for valid extension name
+ if (isExtensionNameValid($test)) {
+ // Set extra path to extension's name
+ $mode = $test . '/';
+ } // END - if
+ }
+
+ ////////////////////////
+ // Generate file name //
+ ////////////////////////
+ $FQFN = $basePath . $mode . $template . '.tpl';
+
+ if ((isWhatSet()) && ((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",
+ $basePath,
+ $mode,
+ $template,
+ getWhat()
+ );