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