Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 155 lines (117 sloc) 3.671 kb
bfc4c5f @dietrichm Initial Commit.
dietrichm authored
1 <?php
2
3 /*
4 Copyright (C) 2003-2004 UseBB Team
5 http://usebb.sourceforge.net
3f54de4 @dietrichm Added Header keyword to php files.
dietrichm authored
6
7 $Header$
bfc4c5f @dietrichm Initial Commit.
dietrichm authored
8
9 This file is part of UseBB.
10
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.
15
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
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 //
40 var $needed;
41 var $requests;
42 var $templates;
43
44 //
45 // Add a template request and variables to the $requests var
46 //
47 function parse($name, $vars='') {
48
49 global $config;
50
51 if ( !is_array($this->needed) || !in_array($name, $this->needed) )
52 $this->needed[] = $name;
53
54 $vars['img_dir'] = 'gfx/'.$config['template'].'/';
55 $vars['lang'] = $config['language'];
56
57 $this->requests[] = array(
58 'name' => $name,
59 'vars' => $vars
60 );
61
62 }
63
64 function set_page_title($title) {
65
66 $this->requests[0]['vars']['page_title'] = $title;
67
68 }
69
70 //
71 // Build and echo the page body
72 //
73 function body() {
74
75 global $config, $db, $timer;
76
77 //
78 // Get all the templates we need
79 //
80 foreach ( $this->needed as $val )
81 $query_where_part[] = "'".$val."'";
82 $query_where_part = '( '.join(', ', $query_where_part).' )';
83 if ( !($result = $db->query("SELECT name, content FROM ".TABLE_PREFIX."templates WHERE template = '".$config['template']."' AND name IN ".$query_where_part)) )
84 usebb_die('SQL', 'Unable to get contents of template "'.$config['template'].'"!', __FILE__, __LINE__);
85 while ( $templates = $db->fetch_result($result) )
86 $this->templates[$templates['name']] = stripslashes($templates['content']);
87
88 $body = '';
89
90 //
91 // Build each template
92 //
93 foreach ( $this->requests as $request ) {
94
95 //
96 // When variables has been passed
97 //
98 if ( !empty($request['vars']) ) {
99
100 //
101 // Parse the variables and add it to the body
102 //
103 if ( !isset($this->templates[$request['name']]) )
104 usebb_die('Template', 'Missing template "'.$request['name'].'"!', __FILE__, __LINE__);
105 $current_template = $this->templates[$request['name']];
106 foreach ( $request['vars'] as $key => $val )
107 $current_template = str_replace('{'.$key.'}', $val, $current_template);
108 $body .= $current_template."\n";
109
110 } else {
111
112 //
113 // Just add the template to the body
114 //
115 $body .= $this->templates[$request['name']];
116
117 }
118
119 }
120
121 //
122 // Debug features
123 //
124 if ( $config['debug'] ) {
125
126 //
127 // Timer for checking parsetime
128 //
129 $timer['end'] = explode(' ', microtime());
130 $timer['end'] = (float)$timer['end'][1] + (float)$timer['end'][0];
131 $parsetime = round($timer['end'] - $timer['begin'], 5).'s';
132
133 //
134 // Lists parsetime and queries
135 //
136 $body .= '<hr /><code>Parse Time: '.$parsetime.'</code><ol><code>';
137 foreach ( $db->queries as $query )
138 $body .= '<li>'.$query.'</li>';
139 $body .= '</code></ol>';
140
141 }
142
143 //
144 // Output compression
145 //
146 if ( $config['output_compression'] )
147 $body = preg_replace("/>\s+</", '><', $body);
148
149 echo $body;
150
151 }
152
153 }
154
155 ?>
Something went wrong with that request. Please try again.