|
1 <?php |
|
2 |
|
3 /* |
|
4 * Enano - an open-source CMS capable of wiki functions, Drupal-like sidebar blocks, and everything in between |
|
5 * Version 1.1.5 (Caoineag alpha 5) |
|
6 * output.php - Controls output format, messages of death, that kind of stuff |
|
7 * Copyright (C) 2006-2008 Dan Fuhry |
|
8 * |
|
9 * This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License |
|
10 * as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. |
|
11 * |
|
12 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied |
|
13 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details. |
|
14 */ |
|
15 |
|
16 /** |
|
17 * Abstract class to define how output handlers should act. |
|
18 * @package Enano |
|
19 * @subpackage UI |
|
20 */ |
|
21 |
|
22 abstract class Output_Base |
|
23 { |
|
24 /** |
|
25 * Page title |
|
26 * @var string |
|
27 */ |
|
28 |
|
29 public $title = 'Untitled'; |
|
30 |
|
31 /** |
|
32 * To allow scripts to determine whether we are outputting headers or not. |
|
33 * @var bool |
|
34 */ |
|
35 |
|
36 public $naked = false; |
|
37 |
|
38 /** |
|
39 * Added content |
|
40 * @var string |
|
41 * @var string |
|
42 * @var string |
|
43 * @var string |
|
44 */ |
|
45 |
|
46 public $before_header = '', $after_header = '', $before_footer = '', $after_footer = ''; |
|
47 |
|
48 /** |
|
49 * Call this to send content headers (e.g. the first third of the document if HTML) in place of $template->header(). |
|
50 * @access public |
|
51 */ |
|
52 |
|
53 abstract public function header(); |
|
54 |
|
55 /** |
|
56 * Call this to send extra stuff after the content (equivalent of $template->footer()). |
|
57 * @access public |
|
58 */ |
|
59 |
|
60 abstract public function footer(); |
|
61 |
|
62 /** |
|
63 * Add some code just before the header. |
|
64 * @access public |
|
65 */ |
|
66 |
|
67 public function add_before_header($code) |
|
68 { |
|
69 $this->before_header .= $code; |
|
70 } |
|
71 |
|
72 /** |
|
73 * Add some code just after the header. |
|
74 * @access public |
|
75 */ |
|
76 |
|
77 public function add_after_header($code) |
|
78 { |
|
79 $this->after_header .= $code; |
|
80 } |
|
81 |
|
82 /** |
|
83 * Add some code just before the footer. |
|
84 * @access public |
|
85 */ |
|
86 |
|
87 public function add_before_footer($code) |
|
88 { |
|
89 $this->before_footer .= $code; |
|
90 } |
|
91 |
|
92 /** |
|
93 * Add some code just after the footer. |
|
94 * @access public |
|
95 */ |
|
96 |
|
97 public function add_after_footer($code) |
|
98 { |
|
99 $this->after_footer .= $code; |
|
100 } |
|
101 |
|
102 /** |
|
103 * Send any required HTML headers through, e.g. Content-type. |
|
104 * @access public |
|
105 */ |
|
106 |
|
107 public function http_headers() |
|
108 { |
|
109 header('Content-type: text/html'); |
|
110 } |
|
111 |
|
112 /** |
|
113 * Set the title of the page being output. |
|
114 * @param string Page name |
|
115 */ |
|
116 |
|
117 public function set_title($title) |
|
118 { |
|
119 $this->title = $title; |
|
120 } |
|
121 |
|
122 /** |
|
123 * Avoid sending things out of order. |
|
124 * @var bool |
|
125 * @var bool |
|
126 */ |
|
127 |
|
128 public $headers_sent = false, $footers_sent = false; |
|
129 } |
|
130 |
|
131 /** |
|
132 * HTML outputter. |
|
133 */ |
|
134 |
|
135 class Output_HTML extends Output_Base |
|
136 { |
|
137 public function header() |
|
138 { |
|
139 if ( $this->headers_sent ) |
|
140 return; |
|
141 |
|
142 $this->headers_sent = true; |
|
143 |
|
144 ob_start(); |
|
145 } |
|
146 |
|
147 public function footer() |
|
148 { |
|
149 global $template; |
|
150 if ( !$this->headers_sent ) |
|
151 return; |
|
152 |
|
153 $this->headers_sent = false; |
|
154 $content = ob_get_contents(); |
|
155 ob_end_clean(); |
|
156 |
|
157 ob_start(); |
|
158 echo $this->before_header; |
|
159 echo $template->getHeader(); |
|
160 echo $this->after_header; |
|
161 echo $content; |
|
162 echo $this->before_footer; |
|
163 echo $template->getFooter(); |
|
164 echo $this->after_footer; |
|
165 |
|
166 } |
|
167 |
|
168 public function set_title($title) |
|
169 { |
|
170 global $template; |
|
171 $template->assign_vars(array( |
|
172 'PAGE_NAME' => $title |
|
173 )); |
|
174 } |
|
175 } |
|
176 |
|
177 /** |
|
178 * Outputter that bypasses $template->header() and $template->footer(), but still shows HTML added via {before,after}_{header,footer}. |
|
179 */ |
|
180 |
|
181 class Output_Striptease extends Output_HTML |
|
182 { |
|
183 public function header() |
|
184 { |
|
185 echo $this->before_header; |
|
186 echo $this->after_header; |
|
187 } |
|
188 |
|
189 public function footer() |
|
190 { |
|
191 echo $this->before_footer; |
|
192 echo $this->after_footer; |
|
193 } |
|
194 } |
|
195 |
|
196 /** |
|
197 * Outputter that bypasses $template->header() and $template->footer(). |
|
198 */ |
|
199 |
|
200 class Output_Naked extends Output_HTML |
|
201 { |
|
202 public $naked = true; |
|
203 |
|
204 public function header() |
|
205 { |
|
206 } |
|
207 |
|
208 public function footer() |
|
209 { |
|
210 } |
|
211 } |
|
212 |
|
213 /** |
|
214 * Safe template outputter |
|
215 */ |
|
216 |
|
217 class Output_Safe |
|
218 { |
|
219 protected $template; |
|
220 protected $headers_sent = false; |
|
221 public function __construct() |
|
222 { |
|
223 $this->template = new template_nodb(); |
|
224 $theme = ( defined('ENANO_CONFIG_FETCHED') ) ? getConfig('theme_default') : 'oxygen'; |
|
225 $style = ( defined('ENANO_CONFIG_FETCHED') ) ? '__foo__' : 'bleu'; |
|
226 |
|
227 $this->template->load_theme($theme, $style); |
|
228 $this->template->tpl_strings['SITE_NAME'] = getConfig('site_name'); |
|
229 $this->template->tpl_strings['SITE_DESC'] = getConfig('site_desc'); |
|
230 $this->template->tpl_strings['COPYRIGHT'] = getConfig('copyright_notice'); |
|
231 $this->template->tpl_strings['PAGE_NAME'] = 'Untitled'; |
|
232 } |
|
233 public function header() |
|
234 { |
|
235 if ( $this->headers_sent ) |
|
236 return; |
|
237 |
|
238 $this->headers_sent = true; |
|
239 |
|
240 $this->template->header(); |
|
241 } |
|
242 |
|
243 public function footer() |
|
244 { |
|
245 global $template; |
|
246 if ( !$this->headers_sent ) |
|
247 { |
|
248 $this->template->header(); |
|
249 } |
|
250 |
|
251 $this->headers_sent = false; |
|
252 $this->template->footer(); |
|
253 |
|
254 } |
|
255 |
|
256 public function set_title($title) |
|
257 { |
|
258 $this->template->tpl_strings['PAGE_NAME'] = $title; |
|
259 } |
|
260 } |
|
261 |
|
262 ?> |