ab24e8fb3e4d0b3972af97ba10248ba35c93d52a
[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
44 // Initializer
45 function HTMLParser()
46 {
47 }
48
49 // Add HTML-Code to buffer
50 function add_html ($HTML, $NEW_LINE = true)
51 {
52         global $OUTPUT;
53 }
54 // Compiles HTML code
55 function compile_html($code, $simple=false)
56 {
57         global $SEC_CHARS;
58
59         // Compile constants
60         $code = str_replace('{--', '".', str_replace('--}', '."', $code));
61
62         // Compile QUOT and other non-HTML codes
63         foreach ($SEC_CHARS['to'] as $k=>$from)
64         {
65                 // Do the reversed thing as in inc/libs/security_functions.php
66                 $code = str_replace($from, $SEC_CHARS['from'][$k], $code);
67         }
68
69         // But keep simple quotes for later use
70         if ($simple) $code = str_replace("'", '{QUOT}', $code);
71
72         // Return compiled code
73         return $code;
74 }
75 // Load a template file and return it's content (only it's name; do not use ' or ")
76 function get_template ($template, $return=false, $content="")
77 {
78         // Add more variables which you want to use in your template files
79         global $DATA, $ACTION, $WHAT;
80         $REFID = bigintval(get_session('refid'));
81
82         if ($template == "member_support_form")
83         {
84                 // Support request of a member
85                 $ID = bigintval($GLOBALS['userid']);
86                 $result = SQL_QUERY_ESC("SELECT sex, surname, family FROM "._MYSQL_PREFIX."_user_data WHERE userid='%s' LIMIT 1", array($ID), __FILE__, __LINE__);
87                 list($sex, $surname, $family) = SQL_FETCHROW($result);
88                 SQL_FREERESULT($result);
89                 $salut = TRANSLATE_SEX($sex);
90         }
91
92         // Base directory
93         $BASE = PATH."templates/".GET_LANGUAGE()."/html/";
94         $MODE = "";
95
96         // Check for admin/guest/member templates
97         if (strpos($template, "admin_") > -1)
98         {
99                 // Admin template found
100                 $MODE = "admin/";
101         }
102          elseif (strpos($template, "guest_") > -1)
103         {
104                 // Guest template found
105                 $MODE = "guest/";
106         }
107          elseif (strpos($template, "member_") > -1)
108         {
109                 // Member template found
110                 $MODE = "member/";
111         }
112          elseif (strpos($template, "install_") > -1)
113         {
114                 // Installation template found
115                 $MODE = "install/";
116         }
117          elseif (strpos($template, "mailid_") > -1)
118         {
119                 // Mail confirmation template found
120                 $MODE = "mailid/";
121         }
122
123         // Generate file name
124         $file = $BASE.$MODE.$template.".tpl";
125         if ((!empty($HTTP_GET_VARS['what'])) && ((strpos($template, "_header") > 0) || (strpos($template, "_footer") > 0)) && (($MODE == "guest/") || ($MODE == "member/") || ($MODE == "admin/")))
126         {
127                 // Select what depended header/footer template file for admin/guest/member area
128                 $file2 = $BASE.$MODE.$template."_".$HTTP_GET_VARS['what'].".tpl";
129
130                 // Probe for it...
131                 if (file_exists($file2)) $file = $file2;
132
133                 // Remove variable from memory
134                 unset($file2);
135         }
136
137         // Does the special template exists?
138         if (!file_exists($file))
139         {
140                 // Reset to default template
141                 $file = PATH."templates/".GET_LANGUAGE()."/html/".$template.".tpl";
142         }
143
144         // Now does the final template exists?
145         if (file_exists($file))
146         {
147                 // The local file does exists so we load it. :)
148                 $tmpl_file = implode("", file($file));
149                 $tmpl_file = str_replace("'", '{QUOT}', $tmpl_file);
150
151                 // Compile and run code
152                 $ret = COMPILE_CODE(addslashes($tmpl_file), false, true);
153                 $ret = "<!-- Template ".$template." - Start -->\n".$ret."<!-- Template ".$template." - End -->\n";
154         }
155          elseif (IS_ADMIN())
156         {
157                 // Only admins shall see this warning
158                 $ret = "<br /><SPAN class=\"guest_failed\">".TEMPLATE_404."</SPAN><br />
159 (".basename($file).")
160 <br /><br />";
161         }
162         if ($return)
163         {
164                 // Return the HTML code
165                 return $ret;
166         }
167          else
168         {
169                 // Output directly
170                 $this->add_html ($ret);
171         }
172 }
173
174         // END OF CLASS
175 }
176 //
177 ?>