r1412: Using the new database caching feature of ISSO's template system
[bugdar.git] / global.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar [#]version[#]
5 || # Copyright ©2002-[#]year[#] Blue Static
6 || #
7 || # This program is free software; you can redistribute it and/or modify
8 || # it under the terms of the GNU General Public License as published by
9 || # the Free Software Foundation; version [#]gpl[#] of the License.
10 || #
11 || # This program is distributed in the hope that it will be useful, but
12 || # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 || # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 || # more details.
15 || #
16 || # You should have received a copy of the GNU General Public License along
17 || # with this program; if not, write to the Free Software Foundation, Inc.,
18 || # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 || ###################################################################
20 \*=====================================================================*/
21
22 require_once('./includes/init.php');
23
24 define('HTML_CHECKED', ' checked="checked"');
25
26 // ###################################################################
27 // initialize template system
28 $bugsys->load('template_fs', 'template', true);
29 $template->setExtension('tpl');
30 $template->setPreParseHook('isso_pre_parse_hook');
31 $template->setTemplateDir('templates/');
32 $template->setDatabaseCache(TABLE_PREFIX . 'template');
33
34 // ###################################################################
35 // global template variables
36 $datetime = $datef->format('l, F j, Y g:i A');
37 $year = $datef->format('Y');
38 $version = $bugsys->options['trackerversion'];
39
40 $show['admin'] = (bool)can_perform('canadminpanel');
41 $show['newreport'] = (bool)can_perform('cansubmitbugs');
42 $show['search'] = (bool)can_perform('cansearch');
43
44 if (!defined('NO_TEMPLATES') OR (defined('NO_TEMPLATES') AND constant('NO_TEMPLATES') == true))
45 {
46 // ###################################################################
47 // do style vars
48 if (($raw = @file_get_contents('./templates/stylevars.txt')) !== false)
49 {
50 // remove comments
51 $raw = preg_replace('#/\*(.*?)\*/#s', '', $raw);
52 $raw = trim($raw);
53
54 // create individual vars
55 $varsraw = explode(';', $raw);
56 foreach ($varsraw AS $var)
57 {
58 if (($var = trim($var)) == '')
59 {
60 continue;
61 }
62
63 // split into varname - value pair
64 $temp = explode(':', $var);
65
66 // clean up varnames
67 $varname = trim($temp[0]);
68 $varname = preg_replace('#[^a-z0-9]#i', '_', $varname);
69
70 // clean up values
71 $value = trim($temp[1]);
72 $value = preg_replace('#[^a-z0-9%\-\.\#]#i', '', $value);
73
74 // put it in the array
75 $stylevar["$varname"] = $value;
76 }
77 }
78 else
79 {
80 trigger_error('StyleVars file (./templates/stylevars.txt) could not be loaded', E_USER_WARNING);
81 }
82
83 // ###################################################################
84 // cache templates
85 $globaltemplates = array(
86 'doctype',
87 'header',
88 'headinclude',
89 'footer',
90 'selectoption',
91 'selectoptgroup',
92 'std_error',
93 'std_redirect',
94 'std_message',
95 'bugfield_input_text',
96 'bugfield_input_checkbox',
97 'bugfield_select_single_option',
98 'bugfield_select_single',
99 'username_display',
100 'help_link'
101 );
102
103 $start = microtime();
104
105 $template->cache(array_merge($globaltemplates, (array)$fetchtemplates));
106
107 $bugsys->debug('time for tpl cache: ' . $funct->fetch_microtime_diff($start));
108
109 eval('$header = "' . $template->fetch('header') . '";');
110 eval('$doctype = "' . $template->fetch('doctype') . '";');
111 eval('$headinclude = "' . $template->fetch('headinclude') . '";');
112 eval('$footer = "' . $template->fetch('footer') . '";');
113 }
114
115 // ###################################################################
116
117 // ###################################################################
118 // initialize template variables
119 $show = array();
120
121 // ###################################################################
122 // create error reporter
123 require_once('./includes/class_message_reporter.php');
124 $message = new Message_Reporter();
125 $bugsys->message =& $message;
126
127 /*=====================================================================*\
128 || ###################################################################
129 || # $HeadURL$
130 || # $Id$
131 || ###################################################################
132 \*=====================================================================*/
133 ?>