Problem with one URL not in reload lock fixed
[mailer.git] / inc / libs / output_functions.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    Start: 01/26/2005 *
4  * ===============                              Last change: 01/26/2005 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : output_functions.php                             *
8  * -------------------------------------------------------------------- *
9  * Short description : Class containing the HTML sub-system             *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Klasse fuer das HTML-Subsystem                   *
12  * -------------------------------------------------------------------- *
13  *                                                                      *
14  * -------------------------------------------------------------------- *
15  * Copyright (c) 2003, 2004, 2005, 2006, 2007 by Roland Haeder          *
16  * For more information visit: http://www.mxchange.org                  *
17  *                                                                      *
18  * This program is free software; you can redistribute it and/or modify *
19  * it under the terms of the GNU General Public License as published by *
20  * the Free Software Foundation; either version 2 of the License, or    *
21  * (at your option) any later version.                                  *
22  *                                                                      *
23  * This program is distributed in the hope that it will be useful,      *
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
26  * GNU General Public License for more details.                         *
27  *                                                                      *
28  * You should have received a copy of the GNU General Public License    *
29  * along with this program; if not, write to the Free Software          *
30  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
31  * MA  02110-1301  USA                                                  *
32  ************************************************************************/
33
34 // Some security stuff...
35 if (ereg(basename(__FILE__), $_SERVER['PHP_SELF']))
36 {
37         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
38         require($INC);
39 }
40 // Add HTML to the output stream
41 class HTMLParser {
42
43 // Initializer
44 function HTMLParser() {
45 }
46
47 // Add HTML-Code to buffer
48 function add_html ($HTML, $NEW_LINE = true) {
49         global $OUTPUT;
50 }
51
52 // Compiles HTML code
53 function compile_html($code, $simple=false) {
54         global $SEC_CHARS;
55
56         // Compile constants
57         $code = str_replace('{--', '".', str_replace('--}', '."', $code));
58
59         // Compile QUOT and other non-HTML codes
60         foreach ($SEC_CHARS['to'] as $k=>$from) {
61                 // Do the reversed thing as in inc/libs/security_functions.php
62                 $code = str_replace($from, $SEC_CHARS['from'][$k], $code);
63         }
64
65         // But keep simple quotes for later use
66         if ($simple) $code = str_replace("'", '{QUOT}', $code);
67
68         // Return compiled code
69         return $code;
70 }
71
72 // Load a template file and return it's content (only it's name; do not use ' or ")
73 function get_template ($template, $return=false, $content="")
74 {
75         // Add more variables which you want to use in your template files
76         global $DATA, $ACTION, $WHAT;
77         $REFID = bigintval(get_session('refid'));
78
79         if ($template == "member_support_form") {
80                 // Support request of a member
81                 $result = SQL_QUERY_ESC("SELECT sex, surname, family FROM "._MYSQL_PREFIX."_user_data WHERE userid='%s' LIMIT 1", array($GLOBALS['userid']), __FILE__, __LINE__);
82                 list($sex, $surname, $family) = SQL_FETCHROW($result);
83                 SQL_FREERESULT($result);
84                 $salut = TRANSLATE_SEX($sex);
85         }
86
87         // Base directory
88         $BASE = sprintf("%stemplates/%s/html/", PATH, GET_LANGUAGE());
89         $MODE = "";
90
91         // Check for admin/guest/member templates
92         if (strpos($template, "admin_") > -1) {
93                 // Admin template found
94                 $MODE = "admin/";
95         } elseif (strpos($template, "guest_") > -1) {
96                 // Guest template found
97                 $MODE = "guest/";
98         } elseif (strpos($template, "member_") > -1) {
99                 // Member template found
100                 $MODE = "member/";
101         } elseif (strpos($template, "install_") > -1) {
102                 // Installation template found
103                 $MODE = "install/";
104         } elseif (strpos($template, "mailid_") > -1) {
105                 // Mail confirmation template found
106                 $MODE = "mailid/";
107         }
108
109         // Generate file name
110         $file = $BASE.$MODE.$template.".tpl";
111         if ((!empty($_GET['what'])) && ((strpos($template, "_header") > 0) || (strpos($template, "_footer") > 0)) && (($MODE == "guest/") || ($MODE == "member/") || ($MODE == "admin/"))) {
112                 // Select what depended header/footer template file for admin/guest/member area
113                 $file2 = sprintf("%s%s%s_%s.tpl", $BASE, $MODE, $template, SQL_ESCAPE($_GET['what']));
114
115                 // Probe for it...
116                 if ((file_exists($file2)) && (is_readable($file2))) $file = $file2;
117
118                 // Remove variable from memory
119                 unset($file2);
120         } // END - if
121
122         // Does the special template exists?
123         if ((!file_exists($file)) || (!is_readable($file))) {
124                 // Reset to default template
125                 $file = sprintf("%stemplates/%s/html/%s.tpl", PATH, GET_LANGUAGE(), $template);
126         } // END - if
127
128         // Now does the final template exists?
129         if ((file_exists($file)) && (is_readable($file))) {
130                 // The local file does exists so we load it. :)
131                 $tmpl_file = implode("", file($file));
132                 $tmpl_file = str_replace("'", '{QUOT}', $tmpl_file);
133
134                 // Compile and run code
135                 $ret = COMPILE_CODE(addslashes($tmpl_file), false, true);
136                 $ret = "<!-- Template ".$template." - Start -->\n".$ret."<!-- Template ".$template." - End -->\n";
137         } elseif (IS_ADMIN()) {
138                 // Only admins shall see this warning
139                 $ret = "<br /><SPAN class=\"guest_failed\">".TEMPLATE_404."</SPAN><br />
140 (".basename($file).")
141 <br /><br />";
142         }
143
144         if ($return) {
145                 // Return the HTML code
146                 return $ret;
147         } else {
148                 // Output directly
149                 $this->add_html ($ret);
150         }
151 }
152
153         // END OF CLASS
154 }
155
156 //
157 ?>