source: subversion/trunk/roundcubemail/program/include/rcube_output.php @ 6091

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