Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 237 lines (173 sloc) 6.265 kb
bfc4c5f @dietrichm Initial Commit.
dietrichm authored
1 <?php
2
3 /*
f362a03 @dietrichm copyright update
dietrichm authored
4 Copyright (C) 2003-2005 UseBB Team
98e8605 @dietrichm Changed project web site URL to http://www.usebb.net.
dietrichm authored
5 http://www.usebb.net
3f54de4 @dietrichm Added Header keyword to php files.
dietrichm authored
6
7 $Header$
1933850 @dietrichm Fixed bug 906106 with undefined arrays.
dietrichm authored
8
bfc4c5f @dietrichm Initial Commit.
dietrichm authored
9 This file is part of UseBB.
7e4335d @dietrichm Cosmetic changes with spaces and tabs in header of PHP files.
dietrichm authored
10
1933850 @dietrichm Fixed bug 906106 with undefined arrays.
dietrichm authored
11 UseBB is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
7e4335d @dietrichm Cosmetic changes with spaces and tabs in header of PHP files.
dietrichm authored
15
1933850 @dietrichm Fixed bug 906106 with undefined arrays.
dietrichm authored
16 UseBB is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with UseBB; if not, write to the Free Software
23 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
bfc4c5f @dietrichm Initial Commit.
dietrichm authored
24 */
25
26 //
27 // Die when called directly in browser
28 //
29 if ( !defined('INCLUDED') )
30 exit();
31
32 //
33 // Create the template handlers
34 //
35 class template {
36
37 //
38 // Variables
39 //
c9b5378 @dietrichm OMG HUGE update. Check Changelog.txt. ;)
dietrichm authored
40 var $loaded_sections;
bfc4c5f @dietrichm Initial Commit.
dietrichm authored
41 var $templates;
e4e3929 @dietrichm better template parser - nicer debug info
dietrichm authored
42 var $requests;
c9b5378 @dietrichm OMG HUGE update. Check Changelog.txt. ;)
dietrichm authored
43 var $body;
44
91d048d @dietrichm removed duplicate template section loading code with new function
dietrichm authored
45 //
46 // Define arrays
47 //
c9b5378 @dietrichm OMG HUGE update. Check Changelog.txt. ;)
dietrichm authored
48 function template() {
49
50 $this->loaded_sections = array();
51 $this->templates = array();
e4e3929 @dietrichm better template parser - nicer debug info
dietrichm authored
52 $this->requests = array();
c9b5378 @dietrichm OMG HUGE update. Check Changelog.txt. ;)
dietrichm authored
53 $this->body = '';
54
55 }
bfc4c5f @dietrichm Initial Commit.
dietrichm authored
56
91d048d @dietrichm removed duplicate template section loading code with new function
dietrichm authored
57 //
58 // Load a given template section in the template array
59 //
60 function load_section($section) {
fa92bb3 @dietrichm New template_config table + implementation of get_config() in templat…
dietrichm authored
61
c9b5378 @dietrichm OMG HUGE update. Check Changelog.txt. ;)
dietrichm authored
62 global $functions;
fa92bb3 @dietrichm New template_config table + implementation of get_config() in templat…
dietrichm authored
63
91d048d @dietrichm removed duplicate template section loading code with new function
dietrichm authored
64 if ( !in_array($section, $this->loaded_sections) ) {
fa92bb3 @dietrichm New template_config table + implementation of get_config() in templat…
dietrichm authored
65
91d048d @dietrichm removed duplicate template section loading code with new function
dietrichm authored
66 $templates_file = ROOT_PATH.'templates/'.$functions->get_config('template').'/'.$section.'.tpl.php';
c9b5378 @dietrichm OMG HUGE update. Check Changelog.txt. ;)
dietrichm authored
67 if ( !file_exists($templates_file) || !is_readable($templates_file) )
91d048d @dietrichm removed duplicate template section loading code with new function
dietrichm authored
68 $functions->usebb_die('Template', 'Unable to load '.$section.' templates file for set "'.$functions->get_config('template').'"!', __FILE__, __LINE__);
c9b5378 @dietrichm OMG HUGE update. Check Changelog.txt. ;)
dietrichm authored
69 else
70 require($templates_file);
fa92bb3 @dietrichm New template_config table + implementation of get_config() in templat…
dietrichm authored
71
403060e @dietrichm really split template sections
dietrichm authored
72 $this->templates[$section] = $templates;
c9b5378 @dietrichm OMG HUGE update. Check Changelog.txt. ;)
dietrichm authored
73 $this->loaded_sections[] = $section;
74 unset($templates);
fa92bb3 @dietrichm New template_config table + implementation of get_config() in templat…
dietrichm authored
75
76 }
77
91d048d @dietrichm removed duplicate template section loading code with new function
dietrichm authored
78 }
79
80 //
81 // Get the template config
82 //
83 function get_config($setting) {
84
85 global $functions;
86
87 //
88 // Load the template set
89 //
90 $this->load_section('global');
91
403060e @dietrichm really split template sections
dietrichm authored
92 if ( isset($this->templates['global']['config'][$setting]) )
93 return $this->templates['global']['config'][$setting];
fa92bb3 @dietrichm New template_config table + implementation of get_config() in templat…
dietrichm authored
94 else
4ea0672 @dietrichm Added feature 973978: Show server load.
dietrichm authored
95 $functions->usebb_die('Template', 'The template configuration variable "'.$setting.'" does not exist!', __FILE__, __LINE__);
fa92bb3 @dietrichm New template_config table + implementation of get_config() in templat…
dietrichm authored
96
97 }
98
91d048d @dietrichm removed duplicate template section loading code with new function
dietrichm authored
99 //
100 // Parse a template
101 //
e4e3929 @dietrichm better template parser - nicer debug info
dietrichm authored
102 function parse($name='', $section, $variables=array()) {
bfc4c5f @dietrichm Initial Commit.
dietrichm authored
103
c9b5378 @dietrichm OMG HUGE update. Check Changelog.txt. ;)
dietrichm authored
104 global $functions;
bfc4c5f @dietrichm Initial Commit.
dietrichm authored
105
91d048d @dietrichm removed duplicate template section loading code with new function
dietrichm authored
106 //
107 // Load the template set
108 //
109 $this->load_section($section);
bfc4c5f @dietrichm Initial Commit.
dietrichm authored
110
403060e @dietrichm really split template sections
dietrichm authored
111 if ( !array_key_exists($name, $this->templates[$section]) )
6017b65 @dietrichm Check if template variable is not an array.
dietrichm authored
112 $functions->usebb_die('Template', 'Unable to load "'.$name.'" template in '.$section.' templates file for set "'.$functions->get_config('template').'"!', __FILE__, __LINE__);
c9b5378 @dietrichm OMG HUGE update. Check Changelog.txt. ;)
dietrichm authored
113
e4e3929 @dietrichm better template parser - nicer debug info
dietrichm authored
114 $this->requests[] = array(
403060e @dietrichm really split template sections
dietrichm authored
115 'section' => $section,
e4e3929 @dietrichm better template parser - nicer debug info
dietrichm authored
116 'template_name' => $name,
117 'variables' => ( is_array($variables) && count($variables) ) ? $variables : array()
118 );
119
120 }
121
122 //
123 // Add global template variables
124 // You can overwite existing variables with this function
125 //
126 function add_global_vars($variables) {
127
128 foreach ( $this->requests as $request_key => $null ) {
6017b65 @dietrichm Check if template variable is not an array.
dietrichm authored
129
e4e3929 @dietrichm better template parser - nicer debug info
dietrichm authored
130 $this->requests[$request_key]['variables'] = array_merge($this->requests[$request_key]['variables'], $variables);
6017b65 @dietrichm Check if template variable is not an array.
dietrichm authored
131
132 }
bfc4c5f @dietrichm Initial Commit.
dietrichm authored
133
134 }
135
91d048d @dietrichm removed duplicate template section loading code with new function
dietrichm authored
136 //
137 // Set the page title
138 //
e4e3929 @dietrichm better template parser - nicer debug info
dietrichm authored
139 function set_page_title($page_title) {
bfc4c5f @dietrichm Initial Commit.
dietrichm authored
140
e4e3929 @dietrichm better template parser - nicer debug info
dietrichm authored
141 $this->add_global_vars(array('page_title' => $page_title));
bfc4c5f @dietrichm Initial Commit.
dietrichm authored
142
143 }
144
91d048d @dietrichm removed duplicate template section loading code with new function
dietrichm authored
145 //
146 // Output the page body
147 //
2451ad1 @dietrichm Fixed bug #73: CSS doesn't load directly in IE when gzip enabled.
dietrichm authored
148 function body($enable_debugmessages=true) {
bfc4c5f @dietrichm Initial Commit.
dietrichm authored
149
f06c385 @dietrichm better debug messages
dietrichm authored
150 global $db, $functions, $timer, $lang;
bfc4c5f @dietrichm Initial Commit.
dietrichm authored
151
152 //
153 // Debug features
154 //
4c8972c @dietrichm Fixed bug 990425: Debug messages are passed to CSS as well.
dietrichm authored
155 if ( $functions->get_config('debug') && $enable_debugmessages ) {
bfc4c5f @dietrichm Initial Commit.
dietrichm authored
156
157 //
158 // Timer for checking parsetime
159 //
160 $timer['end'] = explode(' ', microtime());
161 $timer['end'] = (float)$timer['end'][1] + (float)$timer['end'][0];
4ea0672 @dietrichm Added feature 973978: Show server load.
dietrichm authored
162 $parsetime = round($timer['end'] - $timer['begin'], 2);
bfc4c5f @dietrichm Initial Commit.
dietrichm authored
163
9c782ba @dietrichm Cleaned up debug message creation and hide server load on Windows etc.
dietrichm authored
164 $debug_info = array();
165 $debug_info[] = $lang['ParseTime'].': '.$parsetime.' s';
166 if ( $serverload = $functions->get_server_load() )
167 $debug_info[] = $lang['ServerLoad'].': '.$serverload;
168 $debug_info[] = $lang['TemplateSections'].': '.count($this->loaded_sections);
169 $debug_info[] = $lang['SQLQueries'].': '.count($db->get_used_queries());
76731fc @dietrichm Server load in template parser moved to function class.
dietrichm authored
170
7ceccd6 @dietrichm Added feature 1055684: Hide avatars/signatures setting.
dietrichm authored
171 if ( $functions->get_config('debug') === 1 ) {
378f930 @dietrichm Debug now has short (1) and full (2) level.
dietrichm authored
172
173 //
174 // List parsetime and queries in short
175 //
9c782ba @dietrichm Cleaned up debug message creation and hide server load on Windows etc.
dietrichm authored
176 $debug_info_small = sprintf($this->get_config('debug_info_small'), join(' '.$this->get_config('item_delimiter').' ', $debug_info));
cfd5c20 @dietrichm debug - stupid bugs :p
dietrichm authored
177 $debug_info_large = '';
ea42fc9 @dietrichm Implemented timezone and DST handling.
dietrichm authored
178
7ceccd6 @dietrichm Added feature 1055684: Hide avatars/signatures setting.
dietrichm authored
179 } elseif ( $functions->get_config('debug') === 2 ) {
378f930 @dietrichm Debug now has short (1) and full (2) level.
dietrichm authored
180
181 //
182 // Lists parsetime and queries fully
183 //
cfd5c20 @dietrichm debug - stupid bugs :p
dietrichm authored
184 $debug_info_small = '';
9c782ba @dietrichm Cleaned up debug message creation and hide server load on Windows etc.
dietrichm authored
185 $debug_info_large = sprintf($this->get_config('debug_info_large'), '<div><strong>'.$lang['DebugMode'].'</strong> '.$this->get_config('item_delimiter').' '.join(' '.$this->get_config('item_delimiter').' ', $debug_info).':</div><textarea rows="10" cols="50" readonly="readonly">'.htmlspecialchars(join("\n\n", $db->get_used_queries())).'</textarea>');
ea42fc9 @dietrichm Implemented timezone and DST handling.
dietrichm authored
186
378f930 @dietrichm Debug now has short (1) and full (2) level.
dietrichm authored
187 }
bfc4c5f @dietrichm Initial Commit.
dietrichm authored
188
cfd5c20 @dietrichm debug - stupid bugs :p
dietrichm authored
189 } else {
190
191 $debug_info_small = '';
192 $debug_info_large = '';
193
e4e3929 @dietrichm better template parser - nicer debug info
dietrichm authored
194 }
cfd5c20 @dietrichm debug - stupid bugs :p
dietrichm authored
195 $this->add_global_vars(array(
196 'debug_info_small' => $debug_info_small,
197 'debug_info_large' => $debug_info_large
198 ));
e4e3929 @dietrichm better template parser - nicer debug info
dietrichm authored
199
200 //
201 // Parse all templates
202 //
203 foreach ( $this->requests as $request ) {
204
205 $request['variables']['img_dir'] = ROOT_PATH.'templates/'.$functions->get_config('template').'/gfx/';
403060e @dietrichm really split template sections
dietrichm authored
206 $current_template = $this->templates[$request['section']][$request['template_name']];
e692af1 @dietrichm language vars prior to system vars
dietrichm authored
207 if ( preg_match('#\{l_[a-zA-Z]+\}#', $current_template) ) {
208
209 foreach ( $lang as $key => $val )
210 $current_template = str_replace('{l_'.$key.'}', $val, $current_template);
211
212 }
e4e3929 @dietrichm better template parser - nicer debug info
dietrichm authored
213 foreach ( $request['variables'] as $key => $val ) {
214
215 if ( is_array($val) )
216 $functions->usebb_die('Template', 'Unable to translate "{'.$key.'}" to an array!', __FILE__, __LINE__);
217 $current_template = str_replace('{'.$key.'}', $val, $current_template);
218
219 }
220 $this->body .= $current_template;
51d90fa @dietrichm Optimalizations in template.php, debug also works without </body> tag…
dietrichm authored
221
bfc4c5f @dietrichm Initial Commit.
dietrichm authored
222 }
223
224 //
a82bd90 @dietrichm Multiple levels of output compression: none, compress whitespace, gzi…
dietrichm authored
225 // Compression and output
bfc4c5f @dietrichm Initial Commit.
dietrichm authored
226 //
7ceccd6 @dietrichm Added feature 1055684: Hide avatars/signatures setting.
dietrichm authored
227 if ( $functions->get_config('output_compression') === 1 || $functions->get_config('output_compression') === 3 )
c9b5378 @dietrichm OMG HUGE update. Check Changelog.txt. ;)
dietrichm authored
228 $this->body = $functions->compress_sourcecode($this->body);
bfc4c5f @dietrichm Initial Commit.
dietrichm authored
229
c9b5378 @dietrichm OMG HUGE update. Check Changelog.txt. ;)
dietrichm authored
230 echo $this->body;
d95e270 @dietrichm Fixed bug 997622: Source code compression strips newlines out of text…
dietrichm authored
231
bfc4c5f @dietrichm Initial Commit.
dietrichm authored
232 }
233
234 }
235
378f930 @dietrichm Debug now has short (1) and full (2) level.
dietrichm authored
236 ?>
Something went wrong with that request. Please try again.