commit | author | age
|
0c2596
|
1 |
<?php |
A |
2 |
|
|
3 |
/* |
|
4 |
+-----------------------------------------------------------------------+ |
|
5 |
| program/include/rcube_output.php | |
|
6 |
| | |
|
7 |
| This file is part of the Roundcube PHP suite | |
|
8 |
| Copyright (C) 2005-2012 The Roundcube Dev Team | |
|
9 |
| | |
|
10 |
| Licensed under the GNU General Public License version 3 or | |
|
11 |
| any later version with exceptions for skins & plugins. | |
|
12 |
| See the README file for a full license statement. | |
|
13 |
| CONTENTS: | |
|
14 |
| Abstract class for output generation | |
|
15 |
| | |
|
16 |
+-----------------------------------------------------------------------+ |
|
17 |
| Author: Thomas Bruederli <roundcube@gmail.com> | |
|
18 |
| Author: Aleksander Machniak <alec@alec.pl> | |
|
19 |
+-----------------------------------------------------------------------+ |
|
20 |
*/ |
|
21 |
|
|
22 |
/** |
|
23 |
* Class for output generation |
|
24 |
* |
|
25 |
* @package HTML |
|
26 |
*/ |
|
27 |
abstract class rcube_output |
|
28 |
{ |
|
29 |
public $browser; |
|
30 |
public $type = 'html'; |
|
31 |
public $ajax_call = false; |
|
32 |
public $framed = false; |
|
33 |
|
|
34 |
protected $app; |
|
35 |
protected $config; |
|
36 |
protected $charset = RCMAIL_CHARSET; |
|
37 |
protected $env = array(); |
|
38 |
protected $pagetitle = ''; |
|
39 |
protected $object_handlers = array(); |
|
40 |
|
|
41 |
|
|
42 |
/** |
|
43 |
* Object constructor |
|
44 |
*/ |
|
45 |
public function __construct($task = null, $framed = false) |
|
46 |
{ |
|
47 |
$this->app = rcmail::get_instance(); |
|
48 |
$this->config = $this->app->config; |
|
49 |
$this->browser = new rcube_browser(); |
|
50 |
} |
|
51 |
|
|
52 |
|
|
53 |
/** |
69baee
|
54 |
* Magic getter |
T |
55 |
*/ |
|
56 |
public function __get($var) |
|
57 |
{ |
|
58 |
// allow read-only access to $env |
|
59 |
if ($var == 'env') |
|
60 |
return $this->env; |
|
61 |
|
|
62 |
return null; |
|
63 |
} |
|
64 |
|
|
65 |
/** |
0c2596
|
66 |
* Setter for page title |
A |
67 |
* |
|
68 |
* @param string $title Page title |
|
69 |
*/ |
|
70 |
public function set_pagetitle($title) |
|
71 |
{ |
|
72 |
$this->pagetitle = $title; |
|
73 |
} |
|
74 |
|
|
75 |
|
|
76 |
/** |
|
77 |
* Setter for output charset. |
|
78 |
* To be specified in a meta tag and sent as http-header |
|
79 |
* |
|
80 |
* @param string $charset Charset name |
|
81 |
*/ |
|
82 |
public function set_charset($charset) |
|
83 |
{ |
|
84 |
$this->charset = $charset; |
|
85 |
} |
|
86 |
|
|
87 |
|
|
88 |
/** |
|
89 |
* Getter for output charset |
|
90 |
* |
|
91 |
* @return string Output charset name |
|
92 |
*/ |
|
93 |
public function get_charset() |
|
94 |
{ |
|
95 |
return $this->charset; |
|
96 |
} |
|
97 |
|
|
98 |
|
|
99 |
/** |
|
100 |
* Getter for the current skin path property |
|
101 |
*/ |
|
102 |
public function get_skin_path() |
|
103 |
{ |
|
104 |
return $this->config->get('skin_path'); |
|
105 |
} |
|
106 |
|
|
107 |
|
|
108 |
/** |
|
109 |
* Set environment variable |
|
110 |
* |
|
111 |
* @param string $name Property name |
|
112 |
* @param mixed $value Property value |
|
113 |
*/ |
|
114 |
public function set_env($name, $value) |
|
115 |
{ |
|
116 |
$this->env[$name] = $value; |
|
117 |
} |
|
118 |
|
|
119 |
|
|
120 |
/** |
|
121 |
* Environment variable getter. |
|
122 |
* |
|
123 |
* @param string $name Property name |
|
124 |
* |
|
125 |
* @return mixed Property value |
|
126 |
*/ |
|
127 |
public function get_env($name) |
|
128 |
{ |
|
129 |
return $this->env[$name]; |
|
130 |
} |
|
131 |
|
|
132 |
|
|
133 |
/** |
|
134 |
* Delete all stored env variables and commands |
|
135 |
*/ |
|
136 |
public function reset() |
|
137 |
{ |
|
138 |
$this->env = array(); |
|
139 |
$this->object_handlers = array(); |
|
140 |
$this->pagetitle = ''; |
|
141 |
} |
|
142 |
|
|
143 |
|
|
144 |
/** |
|
145 |
* Call a client method |
|
146 |
* |
|
147 |
* @param string Method to call |
|
148 |
* @param ... Additional arguments |
|
149 |
*/ |
|
150 |
abstract function command(); |
|
151 |
|
|
152 |
|
|
153 |
/** |
|
154 |
* Add a localized label to the client environment |
|
155 |
*/ |
|
156 |
abstract function add_label(); |
|
157 |
|
|
158 |
|
|
159 |
/** |
|
160 |
* Invoke display_message command |
|
161 |
* |
|
162 |
* @param string $message Message to display |
|
163 |
* @param string $type Message type [notice|confirm|error] |
|
164 |
* @param array $vars Key-value pairs to be replaced in localized text |
|
165 |
* @param boolean $override Override last set message |
|
166 |
* @param int $timeout Message displaying time in seconds |
|
167 |
*/ |
|
168 |
abstract function show_message($message, $type = 'notice', $vars = null, $override = true, $timeout = 0); |
|
169 |
|
|
170 |
|
|
171 |
/** |
|
172 |
* Redirect to a certain url. |
|
173 |
* |
|
174 |
* @param mixed $p Either a string with the action or url parameters as key-value pairs |
|
175 |
* @param int $delay Delay in seconds |
|
176 |
*/ |
|
177 |
abstract function redirect($p = array(), $delay = 1); |
|
178 |
|
|
179 |
|
|
180 |
/** |
|
181 |
* Send output to the client. |
|
182 |
*/ |
|
183 |
abstract function send(); |
|
184 |
|
|
185 |
|
|
186 |
/** |
|
187 |
* Register a template object handler |
|
188 |
* |
|
189 |
* @param string Object name |
|
190 |
* @param string Function name to call |
|
191 |
* @return void |
|
192 |
*/ |
|
193 |
public function add_handler($obj, $func) |
|
194 |
{ |
|
195 |
$this->object_handlers[$obj] = $func; |
|
196 |
} |
|
197 |
|
|
198 |
|
|
199 |
/** |
|
200 |
* Register a list of template object handlers |
|
201 |
* |
|
202 |
* @param array Hash array with object=>handler pairs |
|
203 |
* @return void |
|
204 |
*/ |
|
205 |
public function add_handlers($arr) |
|
206 |
{ |
|
207 |
$this->object_handlers = array_merge($this->object_handlers, $arr); |
|
208 |
} |
|
209 |
|
|
210 |
|
|
211 |
/** |
|
212 |
* Send HTTP headers to prevent caching a page |
|
213 |
*/ |
|
214 |
public function nocacheing_headers() |
|
215 |
{ |
|
216 |
if (headers_sent()) { |
|
217 |
return; |
|
218 |
} |
|
219 |
|
|
220 |
header("Expires: ".gmdate("D, d M Y H:i:s")." GMT"); |
|
221 |
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); |
|
222 |
|
|
223 |
// Request browser to disable DNS prefetching (CVE-2010-0464) |
|
224 |
header("X-DNS-Prefetch-Control: off"); |
|
225 |
|
|
226 |
// We need to set the following headers to make downloads work using IE in HTTPS mode. |
1aceb9
|
227 |
if ($this->browser->ie && rcube_utils::https_check()) { |
0c2596
|
228 |
header('Pragma: private'); |
A |
229 |
header("Cache-Control: private, must-revalidate"); |
|
230 |
} |
|
231 |
else { |
|
232 |
header("Cache-Control: private, no-cache, must-revalidate, post-check=0, pre-check=0"); |
|
233 |
header("Pragma: no-cache"); |
|
234 |
} |
|
235 |
} |
|
236 |
|
988a80
|
237 |
/** |
T |
238 |
* Send header with expire date 30 days in future |
|
239 |
* |
|
240 |
* @param int Expiration time in seconds |
|
241 |
*/ |
|
242 |
public function future_expire_header($offset = 2600000) |
|
243 |
{ |
|
244 |
if (headers_sent()) |
|
245 |
return; |
|
246 |
|
|
247 |
header("Expires: " . gmdate("D, d M Y H:i:s", time()+$offset) . " GMT"); |
|
248 |
header("Cache-Control: max-age=$offset"); |
|
249 |
header("Pragma: "); |
|
250 |
} |
|
251 |
|
0c2596
|
252 |
|
A |
253 |
/** |
|
254 |
* Show error page and terminate script execution |
|
255 |
* |
|
256 |
* @param int $code Error code |
|
257 |
* @param string $message Error message |
|
258 |
*/ |
|
259 |
public function raise_error($code, $message) |
|
260 |
{ |
|
261 |
// STUB: to be overloaded by specific output classes |
|
262 |
fputs(STDERR, "Error $code: $message\n"); |
|
263 |
exit(-1); |
|
264 |
} |
|
265 |
|
|
266 |
|
|
267 |
/** |
|
268 |
* Convert a variable into a javascript object notation |
|
269 |
* |
|
270 |
* @param mixed Input value |
|
271 |
* |
|
272 |
* @return string Serialized JSON string |
|
273 |
*/ |
|
274 |
public static function json_serialize($input) |
|
275 |
{ |
|
276 |
$input = rcube_charset::clean($input); |
|
277 |
|
|
278 |
// sometimes even using rcube_charset::clean() the input contains invalid UTF-8 sequences |
|
279 |
// that's why we have @ here |
|
280 |
return @json_encode($input); |
|
281 |
} |
|
282 |
|
|
283 |
} |