18 * @subpackage UI |
18 * @subpackage UI |
19 */ |
19 */ |
20 |
20 |
21 abstract class Output_Base |
21 abstract class Output_Base |
22 { |
22 { |
23 /** |
23 /** |
24 * Page title |
24 * Page title |
25 * @var string |
25 * @var string |
26 */ |
26 */ |
27 |
27 |
28 public $title = 'Untitled'; |
28 public $title = 'Untitled'; |
29 |
29 |
30 /** |
30 /** |
31 * To allow scripts to determine whether we are outputting headers or not. |
31 * To allow scripts to determine whether we are outputting headers or not. |
32 * @var bool |
32 * @var bool |
33 */ |
33 */ |
34 |
34 |
35 public $naked = false; |
35 public $naked = false; |
36 |
36 |
37 /** |
37 /** |
38 * Added content |
38 * Added content |
39 * @var string |
39 * @var string |
40 * @var string |
40 * @var string |
41 * @var string |
41 * @var string |
42 * @var string |
42 * @var string |
43 */ |
43 */ |
44 |
44 |
45 public $before_header = '', $after_header = '', $before_footer = '', $after_footer = ''; |
45 public $before_header = '', $after_header = '', $before_footer = '', $after_footer = ''; |
46 |
46 |
47 /** |
47 /** |
48 * Call this to send content headers (e.g. the first third of the document if HTML) in place of $template->header(). |
48 * Call this to send content headers (e.g. the first third of the document if HTML) in place of $template->header(). |
49 * @access public |
49 * @access public |
50 */ |
50 */ |
51 |
51 |
52 abstract public function header(); |
52 abstract public function header(); |
53 |
53 |
54 /** |
54 /** |
55 * Call this to send extra stuff after the content (equivalent of $template->footer()). |
55 * Call this to send extra stuff after the content (equivalent of $template->footer()). |
56 * @access public |
56 * @access public |
57 */ |
57 */ |
58 |
58 |
59 abstract public function footer(); |
59 abstract public function footer(); |
60 |
60 |
61 /** |
61 /** |
62 * Add some code just before the header. |
62 * Add some code just before the header. |
63 * @access public |
63 * @access public |
64 */ |
64 */ |
65 |
65 |
66 public function add_before_header($code) |
66 public function add_before_header($code) |
67 { |
67 { |
68 $this->before_header .= $code; |
68 $this->before_header .= $code; |
69 } |
69 } |
70 |
70 |
71 /** |
71 /** |
72 * Add some code just after the header. |
72 * Add some code just after the header. |
73 * @access public |
73 * @access public |
74 */ |
74 */ |
75 |
75 |
76 public function add_after_header($code) |
76 public function add_after_header($code) |
77 { |
77 { |
78 $this->after_header .= $code; |
78 $this->after_header .= $code; |
79 } |
79 } |
80 |
80 |
81 /** |
81 /** |
82 * Add some code just before the footer. |
82 * Add some code just before the footer. |
83 * @access public |
83 * @access public |
84 */ |
84 */ |
85 |
85 |
86 public function add_before_footer($code) |
86 public function add_before_footer($code) |
87 { |
87 { |
88 $this->before_footer .= $code; |
88 $this->before_footer .= $code; |
89 } |
89 } |
90 |
90 |
91 /** |
91 /** |
92 * Add some code just after the footer. |
92 * Add some code just after the footer. |
93 * @access public |
93 * @access public |
94 */ |
94 */ |
95 |
95 |
96 public function add_after_footer($code) |
96 public function add_after_footer($code) |
97 { |
97 { |
98 $this->after_footer .= $code; |
98 $this->after_footer .= $code; |
99 } |
99 } |
100 |
100 |
101 /** |
101 /** |
102 * Send any required HTML headers through, e.g. Content-type. |
102 * Send any required HTML headers through, e.g. Content-type. |
103 * @access public |
103 * @access public |
104 */ |
104 */ |
105 |
105 |
106 public function http_headers() |
106 public function http_headers() |
107 { |
107 { |
108 header('Content-type: text/html'); |
108 header('Content-type: text/html'); |
109 } |
109 } |
110 |
110 |
111 /** |
111 /** |
112 * Set the title of the page being output. |
112 * Set the title of the page being output. |
113 * @param string Page name |
113 * @param string Page name |
114 */ |
114 */ |
115 |
115 |
116 public function set_title($title) |
116 public function set_title($title) |
117 { |
117 { |
118 $this->title = $title; |
118 $this->title = $title; |
119 } |
119 } |
120 |
120 |
121 /** |
121 /** |
122 * Avoid sending things out of order. |
122 * Avoid sending things out of order. |
123 * @var bool |
123 * @var bool |
124 * @var bool |
124 * @var bool |
125 */ |
125 */ |
126 |
126 |
127 public $headers_sent = false, $footers_sent = false; |
127 public $headers_sent = false, $footers_sent = false; |
128 } |
128 } |
129 |
129 |
130 /** |
130 /** |
131 * HTML outputter. |
131 * HTML outputter. |
132 */ |
132 */ |
133 |
133 |
134 class Output_HTML extends Output_Base |
134 class Output_HTML extends Output_Base |
135 { |
135 { |
136 public function header() |
136 public function header() |
137 { |
137 { |
138 if ( $this->headers_sent ) |
138 if ( $this->headers_sent ) |
139 return; |
139 return; |
140 |
140 |
141 $this->headers_sent = true; |
141 $this->headers_sent = true; |
142 |
142 |
143 ob_start(); |
143 ob_start(); |
144 } |
144 } |
145 |
145 |
146 public function footer() |
146 public function footer() |
147 { |
147 { |
148 global $template; |
148 global $template; |
149 if ( !$this->headers_sent ) |
149 if ( !$this->headers_sent ) |
150 return; |
150 return; |
151 |
151 |
152 $this->headers_sent = false; |
152 $this->headers_sent = false; |
153 $content = ob_get_contents(); |
153 $content = ob_get_contents(); |
154 ob_end_clean(); |
154 ob_end_clean(); |
155 |
155 |
156 ob_start(); |
156 ob_start(); |
157 echo $this->before_header; |
157 echo $this->before_header; |
158 echo $template->getHeader(); |
158 echo $template->getHeader(); |
159 echo $this->after_header; |
159 echo $this->after_header; |
160 echo $content; |
160 echo $content; |
161 echo $this->before_footer; |
161 echo $this->before_footer; |
162 echo $template->getFooter(); |
162 echo $template->getFooter(); |
163 echo $this->after_footer; |
163 echo $this->after_footer; |
164 |
164 |
165 global $aggressive_optimize_html; |
165 global $aggressive_optimize_html; |
166 if ( $aggressive_optimize_html ) |
166 if ( $aggressive_optimize_html ) |
167 { |
167 { |
168 $content = ob_get_contents(); |
168 $content = ob_get_contents(); |
169 ob_end_clean(); |
169 ob_end_clean(); |
170 |
170 |
171 ob_start(); |
171 ob_start(); |
172 echo aggressive_optimize_html($content); |
172 echo aggressive_optimize_html($content); |
173 } |
173 } |
174 else |
174 else |
175 { |
175 { |
176 $content = ob_get_contents(); |
176 $content = ob_get_contents(); |
177 ob_end_clean(); |
177 ob_end_clean(); |
178 |
178 |
179 ob_start(); |
179 ob_start(); |
180 echo preg_replace('~</?enano:no-opt>~', '', $content); |
180 echo preg_replace('~</?enano:no-opt>~', '', $content); |
181 } |
181 } |
182 |
182 |
183 } |
183 } |
184 |
184 |
185 public function set_title($title) |
185 public function set_title($title) |
186 { |
186 { |
187 global $template; |
187 global $template; |
188 $template->assign_vars(array( |
188 $template->assign_vars(array( |
189 'PAGE_NAME' => htmlspecialchars($title) |
189 'PAGE_NAME' => htmlspecialchars($title) |
190 )); |
190 )); |
191 } |
191 } |
192 } |
192 } |
193 |
193 |
194 /** |
194 /** |
195 * Same as HTML, except uses simple-header and simple-footer. |
195 * Same as HTML, except uses simple-header and simple-footer. |
196 */ |
196 */ |
197 |
197 |
198 class Output_HTML_Simple extends Output_HTML |
198 class Output_HTML_Simple extends Output_HTML |
199 { |
199 { |
200 public function footer() |
200 public function footer() |
201 { |
201 { |
202 global $template; |
202 global $template; |
203 if ( !$this->headers_sent ) |
203 if ( !$this->headers_sent ) |
204 return; |
204 return; |
205 |
205 |
206 $this->headers_sent = false; |
206 $this->headers_sent = false; |
207 $content = ob_get_contents(); |
207 $content = ob_get_contents(); |
208 ob_end_clean(); |
208 ob_end_clean(); |
209 |
209 |
210 ob_start(); |
210 ob_start(); |
211 echo $this->before_header; |
211 echo $this->before_header; |
212 echo $template->getHeader(true); |
212 echo $template->getHeader(true); |
213 echo $this->after_header; |
213 echo $this->after_header; |
214 echo $content; |
214 echo $content; |
215 echo $this->before_footer; |
215 echo $this->before_footer; |
216 echo $template->getFooter(true); |
216 echo $template->getFooter(true); |
217 echo $this->after_footer; |
217 echo $this->after_footer; |
218 |
218 |
219 global $aggressive_optimize_html; |
219 global $aggressive_optimize_html; |
220 if ( $aggressive_optimize_html ) |
220 if ( $aggressive_optimize_html ) |
221 { |
221 { |
222 $content = ob_get_contents(); |
222 $content = ob_get_contents(); |
223 ob_end_clean(); |
223 ob_end_clean(); |
224 |
224 |
225 ob_start(); |
225 ob_start(); |
226 echo aggressive_optimize_html($content); |
226 echo aggressive_optimize_html($content); |
227 } |
227 } |
228 else |
228 else |
229 { |
229 { |
230 $content = ob_get_contents(); |
230 $content = ob_get_contents(); |
231 ob_end_clean(); |
231 ob_end_clean(); |
232 |
232 |
233 ob_start(); |
233 ob_start(); |
234 echo preg_replace('~</?enano:no-opt>~', '', $content); |
234 echo preg_replace('~</?enano:no-opt>~', '', $content); |
235 } |
235 } |
236 } |
236 } |
237 } |
237 } |
238 |
238 |
239 /** |
239 /** |
240 * Outputter that bypasses $template->header() and $template->footer(), but still shows HTML added via {before,after}_{header,footer}. |
240 * Outputter that bypasses $template->header() and $template->footer(), but still shows HTML added via {before,after}_{header,footer}. |
241 */ |
241 */ |
242 |
242 |
243 class Output_Striptease extends Output_HTML |
243 class Output_Striptease extends Output_HTML |
244 { |
244 { |
245 public function header() |
245 public function header() |
246 { |
246 { |
247 echo $this->before_header; |
247 echo $this->before_header; |
248 echo $this->after_header; |
248 echo $this->after_header; |
249 } |
249 } |
250 |
250 |
251 public function footer() |
251 public function footer() |
252 { |
252 { |
253 echo $this->before_footer; |
253 echo $this->before_footer; |
254 echo $this->after_footer; |
254 echo $this->after_footer; |
255 } |
255 } |
256 } |
256 } |
257 |
257 |
258 /** |
258 /** |
259 * Outputter that bypasses $template->header() and $template->footer(). |
259 * Outputter that bypasses $template->header() and $template->footer(). |
260 */ |
260 */ |
261 |
261 |
262 class Output_Naked extends Output_HTML |
262 class Output_Naked extends Output_HTML |
263 { |
263 { |
264 public $naked = true; |
264 public $naked = true; |
265 |
265 |
266 public function header() |
266 public function header() |
267 { |
267 { |
268 } |
268 } |
269 |
269 |
270 public function footer() |
270 public function footer() |
271 { |
271 { |
272 } |
272 } |
273 } |
273 } |
274 |
274 |
275 /** |
275 /** |
276 * Safe template outputter |
276 * Safe template outputter |
277 */ |
277 */ |
278 |
278 |
279 class Output_Safe |
279 class Output_Safe |
280 { |
280 { |
281 protected $template; |
281 protected $template; |
282 protected $headers_sent = false; |
282 protected $headers_sent = false; |
283 public function __construct() |
283 public function __construct() |
284 { |
284 { |
285 $this->template = new template_nodb(); |
285 $this->template = new template_nodb(); |
286 $theme = ( defined('ENANO_CONFIG_FETCHED') ) ? getConfig('theme_default') : 'oxygen'; |
286 $theme = ( defined('ENANO_CONFIG_FETCHED') ) ? getConfig('theme_default') : 'oxygen'; |
287 $style = ( defined('ENANO_CONFIG_FETCHED') ) ? '__foo__' : 'bleu'; |
287 $style = ( defined('ENANO_CONFIG_FETCHED') ) ? '__foo__' : 'bleu'; |
288 |
288 |
289 $this->template->load_theme($theme, $style); |
289 $this->template->load_theme($theme, $style); |
290 $this->template->tpl_strings['SITE_NAME'] = getConfig('site_name'); |
290 $this->template->tpl_strings['SITE_NAME'] = getConfig('site_name'); |
291 $this->template->tpl_strings['SITE_DESC'] = getConfig('site_desc'); |
291 $this->template->tpl_strings['SITE_DESC'] = getConfig('site_desc'); |
292 $this->template->tpl_strings['COPYRIGHT'] = getConfig('copyright_notice'); |
292 $this->template->tpl_strings['COPYRIGHT'] = getConfig('copyright_notice'); |
293 $this->template->tpl_strings['PAGE_NAME'] = 'Untitled'; |
293 $this->template->tpl_strings['PAGE_NAME'] = 'Untitled'; |
294 } |
294 } |
295 public function header() |
295 public function header() |
296 { |
296 { |
297 if ( $this->headers_sent ) |
297 if ( $this->headers_sent ) |
298 return; |
298 return; |
299 |
299 |
300 $this->headers_sent = true; |
300 $this->headers_sent = true; |
301 |
301 |
302 $this->template->header(); |
302 $this->template->header(); |
303 } |
303 } |
304 |
304 |
305 public function footer() |
305 public function footer() |
306 { |
306 { |
307 global $template; |
307 global $template; |
308 if ( !$this->headers_sent ) |
308 if ( !$this->headers_sent ) |
309 { |
309 { |
310 $this->template->header(); |
310 $this->template->header(); |
311 } |
311 } |
312 |
312 |
313 $this->headers_sent = false; |
313 $this->headers_sent = false; |
314 $this->template->footer(); |
314 $this->template->footer(); |
315 |
315 |
316 } |
316 } |
317 |
317 |
318 public function set_title($title) |
318 public function set_title($title) |
319 { |
319 { |
320 $this->template->tpl_strings['PAGE_NAME'] = $title; |
320 $this->template->tpl_strings['PAGE_NAME'] = $title; |
321 } |
321 } |
322 } |
322 } |
323 |
323 |
324 ?> |
324 ?> |