0
|
1 <?php
|
|
2
|
|
3 /**
|
|
4 +-----------------------------------------------------------------------+
|
|
5 | program/include/rcmail_output_html.php |
|
|
6 | |
|
|
7 | This file is part of the Roundcube Webmail client |
|
|
8 | Copyright (C) 2006-2014, 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 | |
|
|
14 | PURPOSE: |
|
|
15 | Class to handle HTML page output using a skin template. |
|
|
16 | |
|
|
17 +-----------------------------------------------------------------------+
|
|
18 | Author: Thomas Bruederli <roundcube@gmail.com> |
|
|
19 +-----------------------------------------------------------------------+
|
|
20 */
|
|
21
|
|
22 /**
|
|
23 * Class to create HTML page output using a skin template
|
|
24 *
|
|
25 * @package Webmail
|
|
26 * @subpackage View
|
|
27 */
|
|
28 class rcmail_output_html extends rcmail_output
|
|
29 {
|
|
30 public $type = 'html';
|
|
31
|
|
32 protected $message;
|
|
33 protected $template_name;
|
|
34 protected $objects = array();
|
|
35 protected $js_env = array();
|
|
36 protected $js_labels = array();
|
|
37 protected $js_commands = array();
|
|
38 protected $skin_paths = array();
|
|
39 protected $scripts_path = '';
|
|
40 protected $script_files = array();
|
|
41 protected $css_files = array();
|
|
42 protected $scripts = array();
|
|
43 protected $default_template = "<html>\n<head><title></title></head>\n<body></body>\n</html>";
|
|
44 protected $header = '';
|
|
45 protected $footer = '';
|
|
46 protected $body = '';
|
|
47 protected $base_path = '';
|
|
48 protected $assets_path;
|
|
49 protected $assets_dir = RCUBE_INSTALL_PATH;
|
|
50 protected $devel_mode = false;
|
|
51
|
|
52 // deprecated names of templates used before 0.5
|
|
53 protected $deprecated_templates = array(
|
|
54 'contact' => 'showcontact',
|
|
55 'contactadd' => 'addcontact',
|
|
56 'contactedit' => 'editcontact',
|
|
57 'identityedit' => 'editidentity',
|
|
58 'messageprint' => 'printmessage',
|
|
59 );
|
|
60
|
|
61 /**
|
|
62 * Constructor
|
|
63 */
|
|
64 public function __construct($task = null, $framed = false)
|
|
65 {
|
|
66 parent::__construct();
|
|
67
|
|
68 $this->devel_mode = $this->config->get('devel_mode');
|
|
69
|
|
70 $this->set_env('task', $task);
|
|
71 $this->set_env('x_frame_options', $this->config->get('x_frame_options', 'sameorigin'));
|
|
72 $this->set_env('standard_windows', (bool) $this->config->get('standard_windows'));
|
|
73 $this->set_env('locale', $_SESSION['language']);
|
|
74 $this->set_env('devel_mode', $this->devel_mode);
|
|
75
|
|
76 // add cookie info
|
|
77 $this->set_env('cookie_domain', ini_get('session.cookie_domain'));
|
|
78 $this->set_env('cookie_path', ini_get('session.cookie_path'));
|
|
79 $this->set_env('cookie_secure', filter_var(ini_get('session.cookie_secure'), FILTER_VALIDATE_BOOLEAN));
|
|
80
|
|
81 // load the correct skin (in case user-defined)
|
|
82 $skin = $this->config->get('skin');
|
|
83 $this->set_skin($skin);
|
|
84 $this->set_env('skin', $skin);
|
|
85
|
|
86 $this->set_assets_path($this->config->get('assets_path'), $this->config->get('assets_dir'));
|
|
87
|
|
88 if (!empty($_REQUEST['_extwin']))
|
|
89 $this->set_env('extwin', 1);
|
|
90 if ($this->framed || $framed)
|
|
91 $this->set_env('framed', 1);
|
|
92
|
|
93 $lic = <<<EOF
|
|
94 /*
|
|
95 @licstart The following is the entire license notice for the
|
|
96 JavaScript code in this page.
|
|
97
|
|
98 Copyright (C) 2005-2014 The Roundcube Dev Team
|
|
99
|
|
100 The JavaScript code in this page is free software: you can redistribute
|
|
101 it and/or modify it under the terms of the GNU General Public License
|
|
102 as published by the Free Software Foundation, either version 3 of
|
|
103 the License, or (at your option) any later version.
|
|
104
|
|
105 The code is distributed WITHOUT ANY WARRANTY; without even the implied
|
|
106 warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
107 See the GNU GPL for more details.
|
|
108
|
|
109 @licend The above is the entire license notice
|
|
110 for the JavaScript code in this page.
|
|
111 */
|
|
112 EOF;
|
|
113 // add common javascripts
|
|
114 $this->add_script($lic, 'head_top');
|
|
115 $this->add_script('var '.self::JS_OBJECT_NAME.' = new rcube_webmail();', 'head_top');
|
|
116
|
|
117 // don't wait for page onload. Call init at the bottom of the page (delayed)
|
|
118 $this->add_script(self::JS_OBJECT_NAME.'.init();', 'docready');
|
|
119
|
|
120 $this->scripts_path = 'program/js/';
|
|
121 $this->include_script('jquery.min.js');
|
|
122 $this->include_script('common.js');
|
|
123 $this->include_script('app.js');
|
|
124
|
|
125 // register common UI objects
|
|
126 $this->add_handlers(array(
|
|
127 'loginform' => array($this, 'login_form'),
|
|
128 'preloader' => array($this, 'preloader'),
|
|
129 'username' => array($this, 'current_username'),
|
|
130 'message' => array($this, 'message_container'),
|
|
131 'charsetselector' => array($this, 'charset_selector'),
|
|
132 'aboutcontent' => array($this, 'about_content'),
|
|
133 ));
|
|
134 }
|
|
135
|
|
136 /**
|
|
137 * Set environment variable
|
|
138 *
|
|
139 * @param string $name Property name
|
|
140 * @param mixed $value Property value
|
|
141 * @param boolean $addtojs True if this property should be added
|
|
142 * to client environment
|
|
143 */
|
|
144 public function set_env($name, $value, $addtojs = true)
|
|
145 {
|
|
146 $this->env[$name] = $value;
|
|
147
|
|
148 if ($addtojs || isset($this->js_env[$name])) {
|
|
149 $this->js_env[$name] = $value;
|
|
150 }
|
|
151 }
|
|
152
|
|
153 /**
|
|
154 * Parse and set assets path
|
|
155 *
|
|
156 * @param string $path Assets path URL (relative or absolute)
|
|
157 * @param string $fs_dif Assets path in filesystem
|
|
158 */
|
|
159 public function set_assets_path($path, $fs_dir = null)
|
|
160 {
|
|
161 if (empty($path)) {
|
|
162 return;
|
|
163 }
|
|
164
|
|
165 $path = rtrim($path, '/') . '/';
|
|
166
|
|
167 // handle relative assets path
|
|
168 if (!preg_match('|^https?://|', $path) && $path[0] != '/') {
|
|
169 // save the path to search for asset files later
|
|
170 $this->assets_dir = $path;
|
|
171
|
|
172 $base = preg_replace('/[?#&].*$/', '', $_SERVER['REQUEST_URI']);
|
|
173 $base = rtrim($base, '/');
|
|
174
|
|
175 // remove url token if exists
|
|
176 if ($len = intval($this->config->get('use_secure_urls'))) {
|
|
177 $_base = explode('/', $base);
|
|
178 $last = count($_base) - 1;
|
|
179 $length = $len > 1 ? $len : 16; // as in rcube::get_secure_url_token()
|
|
180
|
|
181 // we can't use real token here because it
|
|
182 // does not exists in unauthenticated state,
|
|
183 // hope this will not produce false-positive matches
|
|
184 if ($last > -1 && preg_match('/^[a-f0-9]{' . $length . '}$/', $_base[$last])) {
|
|
185 $path = '../' . $path;
|
|
186 }
|
|
187 }
|
|
188 }
|
|
189
|
|
190 // set filesystem path for assets
|
|
191 if ($fs_dir) {
|
|
192 if ($fs_dir[0] != '/') {
|
|
193 $fs_dir = realpath(RCUBE_INSTALL_PATH . $fs_dir);
|
|
194 }
|
|
195 // ensure the path ends with a slash
|
|
196 $this->assets_dir = rtrim($fs_dir, '/') . '/';
|
|
197 }
|
|
198
|
|
199 $this->assets_path = $path;
|
|
200 $this->set_env('assets_path', $path);
|
|
201 }
|
|
202
|
|
203 /**
|
|
204 * Getter for the current page title
|
|
205 *
|
|
206 * @return string The page title
|
|
207 */
|
|
208 protected function get_pagetitle()
|
|
209 {
|
|
210 if (!empty($this->pagetitle)) {
|
|
211 $title = $this->pagetitle;
|
|
212 }
|
|
213 else if ($this->env['task'] == 'login') {
|
|
214 $title = $this->app->gettext(array(
|
|
215 'name' => 'welcome',
|
|
216 'vars' => array('product' => $this->config->get('product_name')
|
|
217 )));
|
|
218 }
|
|
219 else {
|
|
220 $title = ucfirst($this->env['task']);
|
|
221 }
|
|
222
|
|
223 return $title;
|
|
224 }
|
|
225
|
|
226 /**
|
|
227 * Set skin
|
|
228 *
|
|
229 * @param string $skin Skin name
|
|
230 *
|
|
231 * @return bool True if the skin exist and is readable, False otherwise
|
|
232 */
|
|
233 public function set_skin($skin)
|
|
234 {
|
|
235 // Sanity check to prevent from path traversal vulnerability (#1490620)
|
|
236 if (strpos($skin, '/') !== false || strpos($skin, "\\") !== false) {
|
|
237 rcube::raise_error(array(
|
|
238 'file' => __FILE__,
|
|
239 'line' => __LINE__,
|
|
240 'message' => 'Invalid skin name'
|
|
241 ), true, false);
|
|
242
|
|
243 return false;
|
|
244 }
|
|
245
|
|
246 $valid = false;
|
|
247 $path = RCUBE_INSTALL_PATH . 'skins/';
|
|
248
|
|
249 if (!empty($skin) && is_dir($path . $skin) && is_readable($path . $skin)) {
|
|
250 $skin_path = 'skins/' . $skin;
|
|
251 $valid = true;
|
|
252 }
|
|
253 else {
|
|
254 $skin_path = $this->config->get('skin_path');
|
|
255 if (!$skin_path) {
|
|
256 $skin_path = 'skins/' . rcube_config::DEFAULT_SKIN;
|
|
257 }
|
|
258 $valid = !$skin;
|
|
259 }
|
|
260
|
|
261 $skin_path = rtrim($skin_path, '/');
|
|
262
|
|
263 $this->config->set('skin_path', $skin_path);
|
|
264 $this->base_path = $skin_path;
|
|
265
|
|
266 // register skin path(s)
|
|
267 $this->skin_paths = array();
|
|
268 $this->load_skin($skin_path);
|
|
269
|
|
270 return $valid;
|
|
271 }
|
|
272
|
|
273 /**
|
|
274 * Helper method to recursively read skin meta files and register search paths
|
|
275 */
|
|
276 private function load_skin($skin_path)
|
|
277 {
|
|
278 $this->skin_paths[] = $skin_path;
|
|
279
|
|
280 // read meta file and check for dependencies
|
|
281 $meta = @file_get_contents(RCUBE_INSTALL_PATH . $skin_path . '/meta.json');
|
|
282 $meta = @json_decode($meta, true);
|
|
283
|
|
284 $meta['path'] = $skin_path;
|
|
285 $path_elements = explode('/', $skin_path);
|
|
286 $skin_id = end($path_elements);
|
|
287
|
|
288 if (!$meta['name']) {
|
|
289 $meta['name'] = $skin_id;
|
|
290 }
|
|
291
|
|
292 $this->skins[$skin_id] = $meta;
|
|
293
|
|
294 if ($meta['extends']) {
|
|
295 $path = RCUBE_INSTALL_PATH . 'skins/';
|
|
296 if (is_dir($path . $meta['extends']) && is_readable($path . $meta['extends'])) {
|
|
297 $this->load_skin('skins/' . $meta['extends']);
|
|
298 }
|
|
299 }
|
|
300 }
|
|
301
|
|
302 /**
|
|
303 * Check if a specific template exists
|
|
304 *
|
|
305 * @param string $name Template name
|
|
306 *
|
|
307 * @return boolean True if template exists
|
|
308 */
|
|
309 public function template_exists($name)
|
|
310 {
|
|
311 foreach ($this->skin_paths as $skin_path) {
|
|
312 $filename = RCUBE_INSTALL_PATH . $skin_path . '/templates/' . $name . '.html';
|
|
313 if ((is_file($filename) && is_readable($filename))
|
|
314 || ($this->deprecated_templates[$name] && $this->template_exists($this->deprecated_templates[$name]))
|
|
315 ) {
|
|
316 return true;
|
|
317 }
|
|
318 }
|
|
319
|
|
320 return false;
|
|
321 }
|
|
322
|
|
323 /**
|
|
324 * Find the given file in the current skin path stack
|
|
325 *
|
|
326 * @param string $file File name/path to resolve (starting with /)
|
|
327 * @param string &$skin_path Reference to the base path of the matching skin
|
|
328 * @param string $add_path Additional path to search in
|
|
329 *
|
|
330 * @return mixed Relative path to the requested file or False if not found
|
|
331 */
|
|
332 public function get_skin_file($file, &$skin_path = null, $add_path = null)
|
|
333 {
|
|
334 $skin_paths = $this->skin_paths;
|
|
335 if ($add_path) {
|
|
336 array_unshift($skin_paths, $add_path);
|
|
337 }
|
|
338
|
|
339 foreach ($skin_paths as $skin_path) {
|
|
340 $path = realpath(RCUBE_INSTALL_PATH . $skin_path . $file);
|
|
341
|
|
342 if ($path && is_file($path)) {
|
|
343 return $skin_path . $file;
|
|
344 }
|
|
345
|
|
346 if ($this->assets_dir != RCUBE_INSTALL_PATH) {
|
|
347 $path = realpath($this->assets_dir . $skin_path . $file);
|
|
348
|
|
349 if ($path && is_file($path)) {
|
|
350 return $skin_path . $file;
|
|
351 }
|
|
352 }
|
|
353 }
|
|
354
|
|
355 return false;
|
|
356 }
|
|
357
|
|
358 /**
|
|
359 * Register a GUI object to the client script
|
|
360 *
|
|
361 * @param string $obj Object name
|
|
362 * @param string $id Object ID
|
|
363 */
|
|
364 public function add_gui_object($obj, $id)
|
|
365 {
|
|
366 $this->add_script(self::JS_OBJECT_NAME.".gui_object('$obj', '$id');");
|
|
367 }
|
|
368
|
|
369 /**
|
|
370 * Call a client method
|
|
371 *
|
|
372 * @param string Method to call
|
|
373 * @param ... Additional arguments
|
|
374 */
|
|
375 public function command()
|
|
376 {
|
|
377 $cmd = func_get_args();
|
|
378 if (strpos($cmd[0], 'plugin.') !== false)
|
|
379 $this->js_commands[] = array('triggerEvent', $cmd[0], $cmd[1]);
|
|
380 else
|
|
381 $this->js_commands[] = $cmd;
|
|
382 }
|
|
383
|
|
384 /**
|
|
385 * Add a localized label to the client environment
|
|
386 */
|
|
387 public function add_label()
|
|
388 {
|
|
389 $args = func_get_args();
|
|
390
|
|
391 if (count($args) == 1 && is_array($args[0])) {
|
|
392 $args = $args[0];
|
|
393 }
|
|
394
|
|
395 foreach ($args as $name) {
|
|
396 $this->js_labels[$name] = $this->app->gettext($name);
|
|
397 }
|
|
398 }
|
|
399
|
|
400 /**
|
|
401 * Invoke display_message command
|
|
402 *
|
|
403 * @param string $message Message to display
|
|
404 * @param string $type Message type [notice|confirm|error]
|
|
405 * @param array $vars Key-value pairs to be replaced in localized text
|
|
406 * @param boolean $override Override last set message
|
|
407 * @param int $timeout Message display time in seconds
|
|
408 *
|
|
409 * @uses self::command()
|
|
410 */
|
|
411 public function show_message($message, $type='notice', $vars=null, $override=true, $timeout=0)
|
|
412 {
|
|
413 if ($override || !$this->message) {
|
|
414 if ($this->app->text_exists($message)) {
|
|
415 if (!empty($vars))
|
|
416 $vars = array_map(array('rcube','Q'), $vars);
|
|
417 $msgtext = $this->app->gettext(array('name' => $message, 'vars' => $vars));
|
|
418 }
|
|
419 else
|
|
420 $msgtext = $message;
|
|
421
|
|
422 $this->message = $message;
|
|
423 $this->command('display_message', $msgtext, $type, $timeout * 1000);
|
|
424 }
|
|
425 }
|
|
426
|
|
427 /**
|
|
428 * Delete all stored env variables and commands
|
|
429 *
|
|
430 * @param bool $all Reset all env variables (including internal)
|
|
431 */
|
|
432 public function reset($all = false)
|
|
433 {
|
|
434 $framed = $this->framed;
|
|
435 $env = $all ? null : array_intersect_key($this->env, array('extwin'=>1, 'framed'=>1));
|
|
436
|
|
437 parent::reset();
|
|
438
|
|
439 // let some env variables survive
|
|
440 $this->env = $this->js_env = $env;
|
|
441 $this->framed = $framed || $this->env['framed'];
|
|
442 $this->js_labels = array();
|
|
443 $this->js_commands = array();
|
|
444 $this->script_files = array();
|
|
445 $this->scripts = array();
|
|
446 $this->header = '';
|
|
447 $this->footer = '';
|
|
448 $this->body = '';
|
|
449
|
|
450 // load defaults
|
|
451 if (!$all) {
|
|
452 $this->__construct();
|
|
453 }
|
|
454 }
|
|
455
|
|
456 /**
|
|
457 * Redirect to a certain url
|
|
458 *
|
|
459 * @param mixed $p Either a string with the action or url parameters as key-value pairs
|
|
460 * @param int $delay Delay in seconds
|
|
461 * @param bool $secure Redirect to secure location (see rcmail::url())
|
|
462 */
|
|
463 public function redirect($p = array(), $delay = 1, $secure = false)
|
|
464 {
|
|
465 if ($this->env['extwin'])
|
|
466 $p['extwin'] = 1;
|
|
467 $location = $this->app->url($p, false, false, $secure);
|
|
468 header('Location: ' . $location);
|
|
469 exit;
|
|
470 }
|
|
471
|
|
472 /**
|
|
473 * Send the request output to the client.
|
|
474 * This will either parse a skin tempalte or send an AJAX response
|
|
475 *
|
|
476 * @param string $templ Template name
|
|
477 * @param boolean $exit True if script should terminate (default)
|
|
478 */
|
|
479 public function send($templ = null, $exit = true)
|
|
480 {
|
|
481 if ($templ != 'iframe') {
|
|
482 // prevent from endless loops
|
|
483 if ($exit != 'recur' && $this->app->plugins->is_processing('render_page')) {
|
|
484 rcube::raise_error(array('code' => 505, 'type' => 'php',
|
|
485 'file' => __FILE__, 'line' => __LINE__,
|
|
486 'message' => 'Recursion alert: ignoring output->send()'), true, false);
|
|
487 return;
|
|
488 }
|
|
489 $this->parse($templ, false);
|
|
490 }
|
|
491 else {
|
|
492 $this->framed = true;
|
|
493 $this->write();
|
|
494 }
|
|
495
|
|
496 // set output asap
|
|
497 ob_flush();
|
|
498 flush();
|
|
499
|
|
500 if ($exit) {
|
|
501 exit;
|
|
502 }
|
|
503 }
|
|
504
|
|
505 /**
|
|
506 * Process template and write to stdOut
|
|
507 *
|
|
508 * @param string $template HTML template content
|
|
509 */
|
|
510 public function write($template = '')
|
|
511 {
|
|
512 if (!empty($this->script_files)) {
|
|
513 $this->set_env('request_token', $this->app->get_request_token());
|
|
514 }
|
|
515
|
|
516 $commands = $this->get_js_commands($framed);
|
|
517
|
|
518 // if all js commands go to parent window we can ignore all
|
|
519 // script files and skip rcube_webmail initialization (#1489792)
|
|
520 if ($framed) {
|
|
521 $this->scripts = array();
|
|
522 $this->script_files = array();
|
|
523 $this->header = '';
|
|
524 $this->footer = '';
|
|
525 }
|
|
526
|
|
527 // write all javascript commands
|
|
528 $this->add_script($commands, 'head_top');
|
|
529
|
|
530 // allow (legal) iframe content to be loaded
|
|
531 $iframe = $this->framed || $this->env['framed'];
|
|
532 if (!headers_sent() && $iframe && ($xopt = $this->app->config->get('x_frame_options', 'sameorigin'))) {
|
|
533 if (strtolower($xopt) != 'sameorigin') {
|
|
534 header('X-Frame-Options: sameorigin', true);
|
|
535 }
|
|
536 }
|
|
537
|
|
538 // call super method
|
|
539 $this->_write($template, $this->config->get('skin_path'));
|
|
540 }
|
|
541
|
|
542 /**
|
|
543 * Parse a specific skin template and deliver to stdout (or return)
|
|
544 *
|
|
545 * @param string $name Template name
|
|
546 * @param boolean $exit Exit script
|
|
547 * @param boolean $write Don't write to stdout, return parsed content instead
|
|
548 *
|
|
549 * @link http://php.net/manual/en/function.exit.php
|
|
550 */
|
|
551 function parse($name = 'main', $exit = true, $write = true)
|
|
552 {
|
|
553 $plugin = false;
|
|
554 $realname = $name;
|
|
555 $plugin_skin_paths = array();
|
|
556
|
|
557 $this->template_name = $realname;
|
|
558
|
|
559 $temp = explode('.', $name, 2);
|
|
560 if (count($temp) > 1) {
|
|
561 $plugin = $temp[0];
|
|
562 $name = $temp[1];
|
|
563 $skin_dir = $plugin . '/skins/' . $this->config->get('skin');
|
|
564
|
|
565 // apply skin search escalation list to plugin directory
|
|
566 foreach ($this->skin_paths as $skin_path) {
|
|
567 $plugin_skin_paths[] = $this->app->plugins->url . $plugin . '/' . $skin_path;
|
|
568 }
|
|
569
|
|
570 // add fallback to default skin
|
|
571 if (is_dir($this->app->plugins->dir . $plugin . '/skins/default')) {
|
|
572 $skin_dir = $plugin . '/skins/default';
|
|
573 $plugin_skin_paths[] = $this->app->plugins->url . $skin_dir;
|
|
574 }
|
|
575
|
|
576 // prepend plugin skin paths to search list
|
|
577 $this->skin_paths = array_merge($plugin_skin_paths, $this->skin_paths);
|
|
578 }
|
|
579
|
|
580 // find skin template
|
|
581 $path = false;
|
|
582 foreach ($this->skin_paths as $skin_path) {
|
|
583 $path = RCUBE_INSTALL_PATH . "$skin_path/templates/$name.html";
|
|
584
|
|
585 // fallback to deprecated template names
|
|
586 if (!is_readable($path) && ($dname = $this->deprecated_templates[$realname])) {
|
|
587 $path = RCUBE_INSTALL_PATH . "$skin_path/templates/$dname.html";
|
|
588
|
|
589 if (is_readable($path)) {
|
|
590 rcube::raise_error(array(
|
|
591 'code' => 502, 'file' => __FILE__, 'line' => __LINE__,
|
|
592 'message' => "Using deprecated template '$dname' in $skin_path/templates. Please rename to '$realname'"
|
|
593 ), true, false);
|
|
594 }
|
|
595 }
|
|
596
|
|
597 if (is_readable($path)) {
|
|
598 $this->config->set('skin_path', $skin_path);
|
|
599 // set base_path to core skin directory (not plugin's skin)
|
|
600 $this->base_path = preg_replace('!plugins/\w+/!', '', $skin_path);
|
|
601 $skin_dir = preg_replace('!^plugins/!', '', $skin_path);
|
|
602 break;
|
|
603 }
|
|
604 else {
|
|
605 $path = false;
|
|
606 }
|
|
607 }
|
5
|
608 #rcube::write_log('mail',"skin: $skin_path $realname $path");
|
0
|
609
|
|
610 // read template file
|
|
611 if (!$path || ($templ = @file_get_contents($path)) === false) {
|
|
612 rcube::raise_error(array(
|
|
613 'code' => 404,
|
|
614 'type' => 'php',
|
|
615 'line' => __LINE__,
|
|
616 'file' => __FILE__,
|
|
617 'message' => 'Error loading template for '.$realname
|
|
618 ), true, $write);
|
|
619
|
|
620 $this->skin_paths = array_slice($this->skin_paths, count($plugin_skin_paths));
|
|
621 return false;
|
|
622 }
|
|
623
|
|
624 // replace all path references to plugins/... with the configured plugins dir
|
|
625 // and /this/ to the current plugin skin directory
|
|
626 if ($plugin) {
|
|
627 $templ = preg_replace(
|
|
628 array('/\bplugins\//', '/(["\']?)\/this\//'),
|
|
629 array($this->app->plugins->url, '\\1'.$this->app->plugins->url.$skin_dir.'/'),
|
|
630 $templ
|
|
631 );
|
|
632 }
|
|
633
|
|
634 // parse for specialtags
|
|
635 $output = $this->parse_conditions($templ);
|
|
636 $output = $this->parse_xml($output);
|
5
|
637 #rcube::write_log('mail',"px: ".strlen($output));
|
0
|
638
|
|
639 // trigger generic hook where plugins can put additional content to the page
|
|
640 $hook = $this->app->plugins->exec_hook("render_page", array('template' => $realname, 'content' => $output));
|
|
641
|
|
642 // save some memory
|
|
643 $output = $hook['content'];
|
|
644 unset($hook['content']);
|
|
645
|
|
646 // remove plugin skin paths from current context
|
|
647 $this->skin_paths = array_slice($this->skin_paths, count($plugin_skin_paths));
|
|
648
|
|
649 if (!$write) {
|
|
650 return $this->postrender($output);
|
|
651 }
|
|
652
|
|
653 $this->write(trim($output));
|
|
654
|
|
655 if ($exit) {
|
|
656 exit;
|
|
657 }
|
|
658 }
|
|
659
|
|
660 /**
|
|
661 * Return executable javascript code for all registered commands
|
|
662 */
|
|
663 protected function get_js_commands(&$framed = null)
|
|
664 {
|
|
665 $out = '';
|
|
666 $parent_commands = 0;
|
|
667 $top_commands = array();
|
|
668
|
|
669 // these should be always on top,
|
|
670 // e.g. hide_message() below depends on env.framed
|
|
671 if (!$this->framed && !empty($this->js_env)) {
|
|
672 $top_commands[] = array('set_env', $this->js_env);
|
|
673 }
|
|
674 if (!empty($this->js_labels)) {
|
|
675 $top_commands[] = array('add_label', $this->js_labels);
|
|
676 }
|
|
677
|
|
678 // unlock interface after iframe load
|
|
679 $unlock = preg_replace('/[^a-z0-9]/i', '', $_REQUEST['_unlock']);
|
|
680 if ($this->framed) {
|
|
681 $top_commands[] = array('iframe_loaded', $unlock);
|
|
682 }
|
|
683 else if ($unlock) {
|
|
684 $top_commands[] = array('hide_message', $unlock);
|
|
685 }
|
|
686
|
|
687 $commands = array_merge($top_commands, $this->js_commands);
|
|
688
|
|
689 foreach ($commands as $i => $args) {
|
|
690 $method = array_shift($args);
|
|
691 $parent = $this->framed || preg_match('/^parent\./', $method);
|
|
692
|
|
693 foreach ($args as $i => $arg) {
|
|
694 $args[$i] = self::json_serialize($arg, $this->devel_mode);
|
|
695 }
|
|
696
|
|
697 if ($parent) {
|
|
698 $parent_commands++;
|
|
699 $method = preg_replace('/^parent\./', '', $method);
|
|
700 $parent_prefix = 'if (window.parent && parent.' . self::JS_OBJECT_NAME . ') parent.';
|
|
701 $method = $parent_prefix . self::JS_OBJECT_NAME . '.' . $method;
|
|
702 }
|
|
703 else {
|
|
704 $method = self::JS_OBJECT_NAME . '.' . $method;
|
|
705 }
|
|
706
|
|
707 $out .= sprintf("%s(%s);\n", $method, implode(',', $args));
|
|
708 }
|
|
709
|
|
710 $framed = $parent_prefix && $parent_commands == count($commands);
|
|
711
|
|
712 // make the output more compact if all commands go to parent window
|
|
713 if ($framed) {
|
|
714 $out = "if (window.parent && parent." . self::JS_OBJECT_NAME . ") {\n"
|
|
715 . str_replace($parent_prefix, "\tparent.", $out)
|
|
716 . "}\n";
|
|
717 }
|
|
718
|
|
719 return $out;
|
|
720 }
|
|
721
|
|
722 /**
|
|
723 * Make URLs starting with a slash point to skin directory
|
|
724 *
|
|
725 * @param string $str Input string
|
|
726 * @param bool $search_path True if URL should be resolved using the current skin path stack
|
|
727 *
|
|
728 * @return string URL
|
|
729 */
|
|
730 public function abs_url($str, $search_path = false)
|
|
731 {
|
|
732 if ($str[0] == '/') {
|
|
733 if ($search_path && ($file_url = $this->get_skin_file($str, $skin_path))) {
|
|
734 return $file_url;
|
|
735 }
|
|
736
|
|
737 return $this->base_path . $str;
|
|
738 }
|
|
739
|
|
740 return $str;
|
|
741 }
|
|
742
|
|
743 /**
|
|
744 * Show error page and terminate script execution
|
|
745 *
|
|
746 * @param int $code Error code
|
|
747 * @param string $message Error message
|
|
748 */
|
|
749 public function raise_error($code, $message)
|
|
750 {
|
|
751 global $__page_content, $ERROR_CODE, $ERROR_MESSAGE;
|
|
752
|
|
753 $ERROR_CODE = $code;
|
|
754 $ERROR_MESSAGE = $message;
|
|
755
|
|
756 include RCUBE_INSTALL_PATH . 'program/steps/utils/error.inc';
|
|
757 exit;
|
|
758 }
|
|
759
|
|
760 /**
|
|
761 * Modify path by adding URL prefix if configured
|
|
762 */
|
|
763 public function asset_url($path)
|
|
764 {
|
|
765 // iframe content can't be in a different domain
|
|
766 // @TODO: check if assests are on a different domain
|
|
767
|
|
768 if (!$this->assets_path || in_array($path[0], array('?', '/', '.')) || strpos($path, '://')) {
|
|
769 return $path;
|
|
770 }
|
|
771
|
|
772 return $this->assets_path . $path;
|
|
773 }
|
|
774
|
|
775
|
|
776 /***** Template parsing methods *****/
|
|
777
|
|
778 /**
|
|
779 * Replace all strings ($varname)
|
|
780 * with the content of the according global variable.
|
|
781 */
|
|
782 protected function parse_with_globals($input)
|
|
783 {
|
|
784 $GLOBALS['__version'] = html::quote(RCMAIL_VERSION);
|
|
785 $GLOBALS['__comm_path'] = html::quote($this->app->comm_path);
|
|
786 $GLOBALS['__skin_path'] = html::quote($this->base_path);
|
|
787
|
|
788 return preg_replace_callback('/\$(__[a-z0-9_\-]+)/',
|
|
789 array($this, 'globals_callback'), $input);
|
|
790 }
|
|
791
|
|
792 /**
|
|
793 * Callback function for preg_replace_callback() in parse_with_globals()
|
|
794 */
|
|
795 protected function globals_callback($matches)
|
|
796 {
|
|
797 return $GLOBALS[$matches[1]];
|
|
798 }
|
|
799
|
|
800 /**
|
|
801 * Correct absolute paths in images and other tags
|
|
802 * add timestamp to .js and .css filename
|
|
803 */
|
|
804 protected function fix_paths($output)
|
|
805 {
|
|
806 return preg_replace_callback(
|
|
807 '!(src|href|background)=(["\']?)([a-z0-9/_.-]+)(["\'\s>])!i',
|
|
808 array($this, 'file_callback'), $output);
|
|
809 }
|
|
810
|
|
811 /**
|
|
812 * Callback function for preg_replace_callback in fix_paths()
|
|
813 *
|
|
814 * @return string Parsed string
|
|
815 */
|
|
816 protected function file_callback($matches)
|
|
817 {
|
|
818 $file = $matches[3];
|
|
819 $file = preg_replace('!^/this/!', '/', $file);
|
|
820
|
|
821 // correct absolute paths
|
|
822 if ($file[0] == '/') {
|
|
823 $file = $this->base_path . $file;
|
|
824 }
|
|
825
|
|
826 // add file modification timestamp
|
|
827 if (preg_match('/\.(js|css)$/', $file, $m)) {
|
|
828 $file = $this->file_mod($file);
|
|
829 }
|
|
830
|
|
831 return $matches[1] . '=' . $matches[2] . $file . $matches[4];
|
|
832 }
|
|
833
|
|
834 /**
|
|
835 * Correct paths of asset files according to assets_path
|
|
836 */
|
|
837 protected function fix_assets_paths($output)
|
|
838 {
|
|
839 return preg_replace_callback(
|
|
840 '!(src|href|background)=(["\']?)([a-z0-9/_.?=-]+)(["\'\s>])!i',
|
|
841 array($this, 'assets_callback'), $output);
|
|
842 }
|
|
843
|
|
844 /**
|
|
845 * Callback function for preg_replace_callback in fix_assets_paths()
|
|
846 *
|
|
847 * @return string Parsed string
|
|
848 */
|
|
849 protected function assets_callback($matches)
|
|
850 {
|
|
851 $file = $this->asset_url($matches[3]);
|
|
852
|
|
853 return $matches[1] . '=' . $matches[2] . $file . $matches[4];
|
|
854 }
|
|
855
|
|
856 /**
|
|
857 * Modify file by adding mtime indicator
|
|
858 */
|
|
859 protected function file_mod($file)
|
|
860 {
|
|
861 $fs = false;
|
|
862 $ext = substr($file, strrpos($file, '.') + 1);
|
|
863
|
|
864 // use minified file if exists (not in development mode)
|
|
865 if (!$this->devel_mode && !preg_match('/\.min\.' . $ext . '$/', $file)) {
|
|
866 $minified_file = substr($file, 0, strlen($ext) * -1) . 'min.' . $ext;
|
|
867 if ($fs = @filemtime($this->assets_dir . $minified_file)) {
|
|
868 return $minified_file . '?s=' . $fs;
|
|
869 }
|
|
870 }
|
|
871
|
|
872 if ($fs = @filemtime($this->assets_dir . $file)) {
|
|
873 $file .= '?s=' . $fs;
|
|
874 }
|
|
875
|
|
876 return $file;
|
|
877 }
|
|
878
|
|
879 /**
|
|
880 * Public wrapper to dipp into template parsing.
|
|
881 *
|
|
882 * @param string $input Template content
|
|
883 *
|
|
884 * @return string
|
|
885 * @uses rcmail_output_html::parse_xml()
|
|
886 * @since 0.1-rc1
|
|
887 */
|
|
888 public function just_parse($input)
|
|
889 {
|
|
890 $input = $this->parse_conditions($input);
|
|
891 $input = $this->parse_xml($input);
|
|
892 $input = $this->postrender($input);
|
|
893
|
|
894 return $input;
|
|
895 }
|
|
896
|
|
897 /**
|
|
898 * Parse for conditional tags
|
|
899 */
|
|
900 protected function parse_conditions($input)
|
|
901 {
|
|
902 $matches = preg_split('/<roundcube:(if|elseif|else|endif)\s+([^>]+)>\n?/is', $input, 2, PREG_SPLIT_DELIM_CAPTURE);
|
|
903 if ($matches && count($matches) == 4) {
|
|
904 if (preg_match('/^(else|endif)$/i', $matches[1])) {
|
|
905 return $matches[0] . $this->parse_conditions($matches[3]);
|
|
906 }
|
|
907
|
|
908 $attrib = html::parse_attrib_string($matches[2]);
|
|
909
|
|
910 if (isset($attrib['condition'])) {
|
|
911 $condmet = $this->check_condition($attrib['condition']);
|
|
912 $submatches = preg_split('/<roundcube:(elseif|else|endif)\s+([^>]+)>\n?/is', $matches[3], 2, PREG_SPLIT_DELIM_CAPTURE);
|
|
913
|
|
914 if ($condmet) {
|
|
915 $result = $submatches[0];
|
|
916 if ($submatches[1] != 'endif') {
|
|
917 $result .= preg_replace('/.*<roundcube:endif\s+[^>]+>\n?/Uis', '', $submatches[3], 1);
|
|
918 }
|
|
919 else {
|
|
920 $result .= $submatches[3];
|
|
921 }
|
|
922 }
|
|
923 else {
|
|
924 $result = "<roundcube:$submatches[1] $submatches[2]>" . $submatches[3];
|
|
925 }
|
|
926
|
|
927 return $matches[0] . $this->parse_conditions($result);
|
|
928 }
|
|
929
|
|
930 rcube::raise_error(array(
|
|
931 'code' => 500, 'line' => __LINE__, 'file' => __FILE__,
|
|
932 'message' => "Unable to parse conditional tag " . $matches[2]
|
|
933 ), true, false);
|
|
934 }
|
|
935
|
|
936 return $input;
|
|
937 }
|
|
938
|
|
939 /**
|
|
940 * Determines if a given condition is met
|
|
941 *
|
|
942 * @param string $condition Condition statement
|
|
943 *
|
|
944 * @return boolean True if condition is met, False if not
|
|
945 * @todo Extend this to allow real conditions, not just "set"
|
|
946 */
|
|
947 protected function check_condition($condition)
|
|
948 {
|
|
949 return $this->eval_expression($condition);
|
|
950 }
|
|
951
|
|
952 /**
|
|
953 * Inserts hidden field with CSRF-prevention-token into POST forms
|
|
954 */
|
|
955 protected function alter_form_tag($matches)
|
|
956 {
|
|
957 $out = $matches[0];
|
|
958 $attrib = html::parse_attrib_string($matches[1]);
|
|
959
|
|
960 if (strtolower($attrib['method']) == 'post') {
|
|
961 $hidden = new html_hiddenfield(array('name' => '_token', 'value' => $this->app->get_request_token()));
|
|
962 $out .= "\n" . $hidden->show();
|
|
963 }
|
|
964
|
|
965 return $out;
|
|
966 }
|
|
967
|
|
968 /**
|
|
969 * Parse & evaluate a given expression and return its result.
|
|
970 *
|
|
971 * @param string $expression Expression statement
|
|
972 *
|
|
973 * @return mixed Expression result
|
|
974 */
|
|
975 protected function eval_expression($expression)
|
|
976 {
|
|
977 $expression = preg_replace(
|
|
978 array(
|
|
979 '/session:([a-z0-9_]+)/i',
|
|
980 '/config:([a-z0-9_]+)(:([a-z0-9_]+))?/i',
|
|
981 '/env:([a-z0-9_]+)/i',
|
|
982 '/request:([a-z0-9_]+)/i',
|
|
983 '/cookie:([a-z0-9_]+)/i',
|
|
984 '/browser:([a-z0-9_]+)/i',
|
|
985 '/template:name/i',
|
|
986 ),
|
|
987 array(
|
|
988 "\$_SESSION['\\1']",
|
|
989 "\$this->app->config->get('\\1',rcube_utils::get_boolean('\\3'))",
|
|
990 "\$this->env['\\1']",
|
|
991 "rcube_utils::get_input_value('\\1', rcube_utils::INPUT_GPC)",
|
|
992 "\$_COOKIE['\\1']",
|
|
993 "\$this->browser->{'\\1'}",
|
|
994 "'{$this->template_name}'",
|
|
995 ),
|
|
996 $expression
|
|
997 );
|
|
998
|
|
999 // Note: We used create_function() before but it's deprecated in PHP 7.2
|
|
1000 // and really it was just a wrapper on eval().
|
|
1001 return eval("return ($expression);");
|
|
1002 }
|
|
1003
|
|
1004 /**
|
|
1005 * Search for special tags in input and replace them
|
|
1006 * with the appropriate content
|
|
1007 *
|
|
1008 * @param string $input Input string to parse
|
|
1009 *
|
|
1010 * @return string Altered input string
|
|
1011 * @todo Use DOM-parser to traverse template HTML
|
|
1012 * @todo Maybe a cache.
|
|
1013 */
|
|
1014 protected function parse_xml($input)
|
|
1015 {
|
|
1016 return preg_replace_callback('/<roundcube:([-_a-z]+)\s+((?:[^>]|\\\\>)+)(?<!\\\\)>/Ui', array($this, 'xml_command'), $input);
|
|
1017 }
|
|
1018
|
|
1019 /**
|
|
1020 * Callback function for parsing an xml command tag
|
|
1021 * and turn it into real html content
|
|
1022 *
|
|
1023 * @param array $matches Matches array of preg_replace_callback
|
|
1024 *
|
|
1025 * @return string Tag/Object content
|
|
1026 */
|
|
1027 protected function xml_command($matches)
|
|
1028 {
|
|
1029 $command = strtolower($matches[1]);
|
|
1030 $attrib = html::parse_attrib_string($matches[2]);
|
|
1031
|
|
1032 // empty output if required condition is not met
|
|
1033 if (!empty($attrib['condition']) && !$this->check_condition($attrib['condition'])) {
|
|
1034 return '';
|
|
1035 }
|
|
1036
|
|
1037 // localize title and summary attributes
|
|
1038 if ($command != 'button' && !empty($attrib['title']) && $this->app->text_exists($attrib['title'])) {
|
|
1039 $attrib['title'] = $this->app->gettext($attrib['title']);
|
|
1040 }
|
|
1041 if ($command != 'button' && !empty($attrib['summary']) && $this->app->text_exists($attrib['summary'])) {
|
|
1042 $attrib['summary'] = $this->app->gettext($attrib['summary']);
|
|
1043 }
|
|
1044
|
|
1045 // execute command
|
|
1046 switch ($command) {
|
|
1047 // return a button
|
|
1048 case 'button':
|
|
1049 if ($attrib['name'] || $attrib['command']) {
|
5
|
1050 #rcube::write_log('lab',"button in: ".print_r($attrib,true));
|
|
1051 $but = $this->button($attrib);
|
|
1052 #rcube::write_log('lab',"button out:\n$but");
|
|
1053 return $but;
|
|
1054
|
0
|
1055 }
|
|
1056 break;
|
|
1057
|
|
1058 // frame
|
|
1059 case 'frame':
|
|
1060 return $this->frame($attrib);
|
|
1061 break;
|
|
1062
|
|
1063 // show a label
|
|
1064 case 'label':
|
|
1065 if ($attrib['expression'])
|
|
1066 $attrib['name'] = $this->eval_expression($attrib['expression']);
|
|
1067
|
|
1068 if ($attrib['name'] || $attrib['command']) {
|
|
1069 $vars = $attrib + array('product' => $this->config->get('product_name'));
|
|
1070 unset($vars['name'], $vars['command']);
|
|
1071
|
|
1072 $label = $this->app->gettext($attrib + array('vars' => $vars));
|
|
1073 $quoting = !empty($attrib['quoting']) ? strtolower($attrib['quoting']) : (rcube_utils::get_boolean((string)$attrib['html']) ? 'no' : '');
|
|
1074
|
|
1075 // 'noshow' can be used in skins to define new labels
|
|
1076 if ($attrib['noshow']) {
|
|
1077 return '';
|
|
1078 }
|
|
1079
|
|
1080 switch ($quoting) {
|
|
1081 case 'no':
|
|
1082 case 'raw':
|
|
1083 break;
|
|
1084 case 'javascript':
|
|
1085 case 'js':
|
|
1086 $label = rcube::JQ($label);
|
|
1087 break;
|
|
1088 default:
|
|
1089 $label = html::quote($label);
|
|
1090 break;
|
|
1091 }
|
|
1092
|
|
1093 return $label;
|
|
1094 }
|
|
1095 break;
|
|
1096
|
|
1097 case 'add_label':
|
|
1098 $this->add_label($attrib['name']);
|
|
1099 break;
|
|
1100
|
|
1101 // include a file
|
|
1102 case 'include':
|
|
1103 $old_base_path = $this->base_path;
|
|
1104 if (!empty($attrib['skin_path'])) $attrib['skinpath'] = $attrib['skin_path'];
|
|
1105 if ($path = $this->get_skin_file($attrib['file'], $skin_path, $attrib['skinpath'])) {
|
|
1106 // set base_path to core skin directory (not plugin's skin)
|
|
1107 $this->base_path = preg_replace('!plugins/\w+/!', '', $skin_path);
|
|
1108 $path = realpath(RCUBE_INSTALL_PATH . $path);
|
|
1109 }
|
|
1110
|
|
1111 if (is_readable($path)) {
|
|
1112 if ($this->config->get('skin_include_php')) {
|
|
1113 $incl = $this->include_php($path);
|
|
1114 }
|
|
1115 else {
|
|
1116 $incl = file_get_contents($path);
|
|
1117 }
|
|
1118 $incl = $this->parse_conditions($incl);
|
|
1119 $incl = $this->parse_xml($incl);
|
|
1120 $incl = $this->fix_paths($incl);
|
|
1121 $this->base_path = $old_base_path;
|
|
1122 return $incl;
|
|
1123 }
|
|
1124 break;
|
|
1125
|
|
1126 case 'plugin.include':
|
|
1127 $hook = $this->app->plugins->exec_hook("template_plugin_include", $attrib);
|
|
1128 return $hook['content'];
|
|
1129
|
|
1130 // define a container block
|
|
1131 case 'container':
|
|
1132 if ($attrib['name'] && $attrib['id']) {
|
|
1133 $this->command('gui_container', $attrib['name'], $attrib['id']);
|
|
1134 // let plugins insert some content here
|
|
1135 $hook = $this->app->plugins->exec_hook("template_container", $attrib);
|
|
1136 return $hook['content'];
|
|
1137 }
|
|
1138 break;
|
|
1139
|
|
1140 // return code for a specific application object
|
|
1141 case 'object':
|
|
1142 $object = strtolower($attrib['name']);
|
|
1143 $content = '';
|
|
1144
|
|
1145 // we are calling a class/method
|
|
1146 if (($handler = $this->object_handlers[$object]) && is_array($handler)) {
|
|
1147 if (is_callable($handler)) {
|
|
1148 // We assume that objects with src attribute are internal (in most
|
|
1149 // cases this is a watermark frame). We need this to make sure assets_path
|
|
1150 // is added to the internal assets paths
|
|
1151 $external = empty($attrib['src']);
|
|
1152 $content = call_user_func($handler, $attrib);
|
|
1153 }
|
|
1154 }
|
|
1155 // execute object handler function
|
|
1156 else if (function_exists($handler)) {
|
|
1157 $content = call_user_func($handler, $attrib);
|
|
1158 }
|
|
1159 else if ($object == 'doctype') {
|
|
1160 $content = html::doctype($attrib['value']);
|
|
1161 }
|
|
1162 else if ($object == 'logo') {
|
|
1163 $attrib += array('alt' => $this->xml_command(array('', 'object', 'name="productname"')));
|
|
1164
|
|
1165 if ($logo = $this->config->get('skin_logo')) {
|
|
1166 if (is_array($logo)) {
|
|
1167 if ($template_logo = $logo[$this->template_name]) {
|
|
1168 $attrib['src'] = $template_logo;
|
|
1169 }
|
|
1170 elseif ($template_logo = $logo['*']) {
|
|
1171 $attrib['src'] = $template_logo;
|
|
1172 }
|
|
1173 }
|
|
1174 else {
|
|
1175 $attrib['src'] = $logo;
|
|
1176 }
|
|
1177 }
|
|
1178
|
|
1179 $content = html::img($attrib);
|
|
1180 }
|
|
1181 else if ($object == 'productname') {
|
|
1182 $name = $this->config->get('product_name', 'Roundcube Webmail');
|
|
1183 $content = html::quote($name);
|
|
1184 }
|
|
1185 else if ($object == 'version') {
|
|
1186 $ver = (string)RCMAIL_VERSION;
|
|
1187 if (is_file(RCUBE_INSTALL_PATH . '.svn/entries')) {
|
|
1188 if (preg_match('/Revision:\s(\d+)/', @shell_exec('svn info'), $regs))
|
|
1189 $ver .= ' [SVN r'.$regs[1].']';
|
|
1190 }
|
|
1191 else if (is_file(RCUBE_INSTALL_PATH . '.git/index')) {
|
|
1192 if (preg_match('/Date:\s+([^\n]+)/', @shell_exec('git log -1'), $regs)) {
|
|
1193 if ($date = date('Ymd.Hi', strtotime($regs[1]))) {
|
|
1194 $ver .= ' [GIT '.$date.']';
|
|
1195 }
|
|
1196 }
|
|
1197 }
|
|
1198 $content = html::quote($ver);
|
|
1199 }
|
|
1200 else if ($object == 'steptitle') {
|
|
1201 $content = html::quote($this->get_pagetitle());
|
|
1202 }
|
|
1203 else if ($object == 'pagetitle') {
|
|
1204 if ($this->devel_mode && !empty($_SESSION['username']))
|
|
1205 $title = $_SESSION['username'].' :: ';
|
|
1206 else if ($prod_name = $this->config->get('product_name'))
|
|
1207 $title = $prod_name . ' :: ';
|
|
1208 else
|
|
1209 $title = '';
|
|
1210 $title .= $this->get_pagetitle();
|
|
1211 $content = html::quote($title);
|
|
1212 }
|
|
1213
|
|
1214 // exec plugin hooks for this template object
|
|
1215 $hook = $this->app->plugins->exec_hook("template_object_$object", $attrib + array('content' => $content));
|
|
1216
|
|
1217 if (strlen($hook['content']) && !empty($external)) {
|
|
1218 $object_id = uniqid('TEMPLOBJECT:', true);
|
|
1219 $this->objects[$object_id] = $hook['content'];
|
|
1220 $hook['content'] = $object_id;
|
|
1221 }
|
|
1222
|
|
1223 return $hook['content'];
|
|
1224
|
|
1225 // return code for a specified eval expression
|
|
1226 case 'exp':
|
|
1227 return html::quote($this->eval_expression($attrib['expression']));
|
|
1228
|
|
1229 // return variable
|
|
1230 case 'var':
|
|
1231 $var = explode(':', $attrib['name']);
|
|
1232 $name = $var[1];
|
|
1233 $value = '';
|
|
1234
|
|
1235 switch ($var[0]) {
|
|
1236 case 'env':
|
|
1237 $value = $this->env[$name];
|
|
1238 break;
|
|
1239 case 'config':
|
|
1240 $value = $this->config->get($name);
|
|
1241 if (is_array($value) && $value[$_SESSION['storage_host']]) {
|
|
1242 $value = $value[$_SESSION['storage_host']];
|
|
1243 }
|
|
1244 break;
|
|
1245 case 'request':
|
|
1246 $value = rcube_utils::get_input_value($name, rcube_utils::INPUT_GPC);
|
|
1247 break;
|
|
1248 case 'session':
|
|
1249 $value = $_SESSION[$name];
|
|
1250 break;
|
|
1251 case 'cookie':
|
|
1252 $value = htmlspecialchars($_COOKIE[$name]);
|
|
1253 break;
|
|
1254 case 'browser':
|
|
1255 $value = $this->browser->{$name};
|
|
1256 break;
|
|
1257 }
|
|
1258
|
|
1259 if (is_array($value)) {
|
|
1260 $value = implode(', ', $value);
|
|
1261 }
|
|
1262
|
|
1263 return html::quote($value);
|
|
1264
|
|
1265 case 'form':
|
|
1266 return $this->form_tag($attrib);
|
|
1267 }
|
|
1268 return '';
|
|
1269 }
|
|
1270
|
|
1271 /**
|
|
1272 * Include a specific file and return it's contents
|
|
1273 *
|
|
1274 * @param string $file File path
|
|
1275 *
|
|
1276 * @return string Contents of the processed file
|
|
1277 */
|
|
1278 protected function include_php($file)
|
|
1279 {
|
|
1280 ob_start();
|
|
1281 include $file;
|
|
1282 $out = ob_get_contents();
|
|
1283 ob_end_clean();
|
|
1284
|
|
1285 return $out;
|
|
1286 }
|
|
1287
|
|
1288 /**
|
|
1289 * Put objects' content back into template output
|
|
1290 */
|
|
1291 protected function postrender($output)
|
|
1292 {
|
|
1293 // insert objects' contents
|
|
1294 foreach ($this->objects as $key => $val) {
|
|
1295 $output = str_replace($key, $val, $output, $count);
|
|
1296 if ($count) {
|
|
1297 $this->objects[$key] = null;
|
|
1298 }
|
|
1299 }
|
|
1300
|
|
1301 // make sure all <form> tags have a valid request token
|
|
1302 $output = preg_replace_callback('/<form\s+([^>]+)>/Ui', array($this, 'alter_form_tag'), $output);
|
|
1303
|
|
1304 return $output;
|
|
1305 }
|
|
1306
|
|
1307 /**
|
|
1308 * Create and register a button
|
|
1309 *
|
|
1310 * @param array $attrib Named button attributes
|
|
1311 *
|
|
1312 * @return string HTML button
|
|
1313 * @todo Remove all inline JS calls and use jQuery instead.
|
|
1314 * @todo Remove all sprintf()'s - they are pretty, but also slow.
|
|
1315 */
|
|
1316 public function button($attrib)
|
|
1317 {
|
|
1318 static $s_button_count = 100;
|
|
1319 static $disabled_actions = null;
|
|
1320
|
|
1321 // these commands can be called directly via url
|
|
1322 $a_static_commands = array('compose', 'list', 'preferences', 'folders', 'identities');
|
|
1323
|
|
1324 if (!($attrib['command'] || $attrib['name'] || $attrib['href'])) {
|
|
1325 return '';
|
|
1326 }
|
|
1327
|
|
1328 // try to find out the button type
|
|
1329 if ($attrib['type']) {
|
|
1330 $attrib['type'] = strtolower($attrib['type']);
|
|
1331 if ($pos = strpos($attrib['type'], '-menuitem')) {
|
|
1332 $attrib['type'] = substr($attrib['type'], 0, -9);
|
|
1333 $menuitem = true;
|
|
1334 }
|
|
1335 }
|
|
1336 else {
|
|
1337 $attrib['type'] = ($attrib['image'] || $attrib['imagepas'] || $attrib['imageact']) ? 'image' : 'link';
|
|
1338 }
|
|
1339
|
|
1340 $command = $attrib['command'];
|
|
1341
|
|
1342 if ($attrib['task']) {
|
|
1343 $element = $command = $attrib['task'] . '.' . $command;
|
|
1344 }
|
|
1345 else {
|
|
1346 $element = ($this->env['task'] ? $this->env['task'] . '.' : '') . $command;
|
|
1347 }
|
|
1348
|
|
1349 if ($disabled_actions === null) {
|
|
1350 $disabled_actions = (array) $this->config->get('disabled_actions');
|
|
1351 }
|
|
1352
|
|
1353 // remove buttons for disabled actions
|
|
1354 if (in_array($element, $disabled_actions)) {
|
|
1355 return '';
|
|
1356 }
|
|
1357
|
|
1358 if (!$attrib['image']) {
|
|
1359 $attrib['image'] = $attrib['imagepas'] ? $attrib['imagepas'] : $attrib['imageact'];
|
|
1360 }
|
|
1361
|
|
1362 if (!$attrib['id']) {
|
|
1363 $attrib['id'] = sprintf('rcmbtn%d', $s_button_count++);
|
|
1364 }
|
|
1365 // get localized text for labels and titles
|
|
1366 if ($attrib['title']) {
|
|
1367 $attrib['title'] = html::quote($this->app->gettext($attrib['title'], $attrib['domain']));
|
|
1368 }
|
|
1369 if ($attrib['label']) {
|
|
1370 $attrib['label'] = html::quote($this->app->gettext($attrib['label'], $attrib['domain']));
|
|
1371 }
|
|
1372 if ($attrib['alt']) {
|
|
1373 $attrib['alt'] = html::quote($this->app->gettext($attrib['alt'], $attrib['domain']));
|
|
1374 }
|
|
1375
|
|
1376 // set accessibility attributes
|
|
1377 if (!$attrib['role']) {
|
|
1378 $attrib['role'] = 'button';
|
|
1379 }
|
|
1380 if (!empty($attrib['class']) && !empty($attrib['classact']) || !empty($attrib['imagepas']) && !empty($attrib['imageact'])) {
|
|
1381 if (array_key_exists('tabindex', $attrib))
|
|
1382 $attrib['data-tabindex'] = $attrib['tabindex'];
|
|
1383 $attrib['tabindex'] = '-1'; // disable button by default
|
|
1384 $attrib['aria-disabled'] = 'true';
|
|
1385 }
|
|
1386
|
|
1387 // set title to alt attribute for IE browsers
|
|
1388 if ($this->browser->ie && !$attrib['title'] && $attrib['alt']) {
|
|
1389 $attrib['title'] = $attrib['alt'];
|
|
1390 }
|
|
1391
|
|
1392 // add empty alt attribute for XHTML compatibility
|
|
1393 if (!isset($attrib['alt'])) {
|
|
1394 $attrib['alt'] = '';
|
|
1395 }
|
|
1396
|
|
1397 // register button in the system
|
|
1398 if ($attrib['command']) {
|
|
1399 $this->add_script(sprintf(
|
|
1400 "%s.register_button('%s', '%s', '%s', '%s', '%s', '%s');",
|
|
1401 self::JS_OBJECT_NAME,
|
|
1402 $command,
|
|
1403 $attrib['id'],
|
|
1404 $attrib['type'],
|
|
1405 $attrib['imageact'] ? $this->abs_url($attrib['imageact']) : $attrib['classact'],
|
|
1406 $attrib['imagesel'] ? $this->abs_url($attrib['imagesel']) : $attrib['classsel'],
|
|
1407 $attrib['imageover'] ? $this->abs_url($attrib['imageover']) : ''
|
|
1408 ));
|
|
1409
|
|
1410 // make valid href to specific buttons
|
|
1411 if (in_array($attrib['command'], rcmail::$main_tasks)) {
|
|
1412 $attrib['href'] = $this->app->url(array('task' => $attrib['command']));
|
|
1413 $attrib['onclick'] = sprintf("return %s.command('switch-task','%s',this,event)", self::JS_OBJECT_NAME, $attrib['command']);
|
|
1414 }
|
|
1415 else if ($attrib['task'] && in_array($attrib['task'], rcmail::$main_tasks)) {
|
|
1416 $attrib['href'] = $this->app->url(array('action' => $attrib['command'], 'task' => $attrib['task']));
|
|
1417 }
|
|
1418 else if (in_array($attrib['command'], $a_static_commands)) {
|
|
1419 $attrib['href'] = $this->app->url(array('action' => $attrib['command']));
|
|
1420 }
|
|
1421 else if (($attrib['command'] == 'permaurl' || $attrib['command'] == 'extwin') && !empty($this->env['permaurl'])) {
|
|
1422 $attrib['href'] = $this->env['permaurl'];
|
|
1423 }
|
|
1424 }
|
|
1425
|
|
1426 // overwrite attributes
|
|
1427 if (!$attrib['href']) {
|
|
1428 $attrib['href'] = '#';
|
|
1429 }
|
|
1430 if ($attrib['task']) {
|
|
1431 if ($attrib['classact'])
|
|
1432 $attrib['class'] = $attrib['classact'];
|
|
1433 }
|
|
1434 else if ($command && !$attrib['onclick']) {
|
|
1435 $attrib['onclick'] = sprintf(
|
|
1436 "return %s.command('%s','%s',this,event)",
|
|
1437 self::JS_OBJECT_NAME,
|
|
1438 $command,
|
|
1439 $attrib['prop']
|
|
1440 );
|
|
1441 }
|
|
1442
|
|
1443 $out = '';
|
|
1444
|
|
1445 // generate image tag
|
|
1446 if ($attrib['type'] == 'image') {
|
|
1447 $attrib_str = html::attrib_string(
|
|
1448 $attrib,
|
|
1449 array(
|
|
1450 'style', 'class', 'id', 'width', 'height', 'border', 'hspace',
|
|
1451 'vspace', 'align', 'alt', 'tabindex', 'title'
|
|
1452 )
|
|
1453 );
|
|
1454 $btn_content = sprintf('<img src="%s"%s />', $this->abs_url($attrib['image']), $attrib_str);
|
|
1455 if ($attrib['label']) {
|
|
1456 $btn_content .= ' '.$attrib['label'];
|
|
1457 }
|
|
1458 $link_attrib = array('href', 'onclick', 'onmouseover', 'onmouseout', 'onmousedown', 'onmouseup', 'target');
|
|
1459 }
|
|
1460 else if ($attrib['type'] == 'link') {
|
|
1461 $btn_content = isset($attrib['content']) ? $attrib['content'] : ($attrib['label'] ? $attrib['label'] : $attrib['command']);
|
|
1462 $link_attrib = array_merge(html::$common_attrib, array('href', 'onclick', 'tabindex', 'target'));
|
|
1463 if ($attrib['innerclass'])
|
|
1464 $btn_content = html::span($attrib['innerclass'], $btn_content);
|
|
1465 }
|
|
1466 else if ($attrib['type'] == 'input') {
|
|
1467 $attrib['type'] = 'button';
|
|
1468
|
|
1469 if ($attrib['label']) {
|
|
1470 $attrib['value'] = $attrib['label'];
|
|
1471 }
|
|
1472 if ($attrib['command']) {
|
|
1473 $attrib['disabled'] = 'disabled';
|
|
1474 }
|
|
1475
|
|
1476 $out = html::tag('input', $attrib, null, array('type', 'value', 'onclick', 'id', 'class', 'style', 'tabindex', 'disabled'));
|
|
1477 }
|
|
1478
|
|
1479 // generate html code for button
|
|
1480 if ($btn_content) {
|
|
1481 $attrib_str = html::attrib_string($attrib, $link_attrib);
|
|
1482 $out = sprintf('<a%s>%s</a>', $attrib_str, $btn_content);
|
|
1483 }
|
|
1484
|
|
1485 if ($attrib['wrapper']) {
|
|
1486 $out = html::tag($attrib['wrapper'], null, $out);
|
|
1487 }
|
|
1488
|
|
1489 if ($menuitem) {
|
|
1490 $class = $attrib['menuitem-class'] ? ' class="' . $attrib['menuitem-class'] . '"' : '';
|
|
1491 $out = '<li role="menuitem"' . $class . '>' . $out . '</li>';
|
|
1492 }
|
|
1493
|
|
1494 return $out;
|
|
1495 }
|
|
1496
|
|
1497 /**
|
|
1498 * Link an external script file
|
|
1499 *
|
|
1500 * @param string $file File URL
|
|
1501 * @param string $position Target position [head|foot]
|
|
1502 */
|
|
1503 public function include_script($file, $position='head')
|
|
1504 {
|
|
1505 if (!preg_match('|^https?://|i', $file) && $file[0] != '/') {
|
|
1506 $file = $this->file_mod($this->scripts_path . $file);
|
|
1507 }
|
|
1508
|
|
1509 if (!is_array($this->script_files[$position])) {
|
|
1510 $this->script_files[$position] = array();
|
|
1511 }
|
|
1512
|
|
1513 if (!in_array($file, $this->script_files[$position])) {
|
|
1514 $this->script_files[$position][] = $file;
|
|
1515 }
|
|
1516 }
|
|
1517
|
|
1518 /**
|
|
1519 * Add inline javascript code
|
|
1520 *
|
|
1521 * @param string $script JS code snippet
|
|
1522 * @param string $position Target position [head|head_top|foot]
|
|
1523 */
|
|
1524 public function add_script($script, $position='head')
|
|
1525 {
|
|
1526 if (!isset($this->scripts[$position])) {
|
|
1527 $this->scripts[$position] = "\n" . rtrim($script);
|
|
1528 }
|
|
1529 else {
|
|
1530 $this->scripts[$position] .= "\n" . rtrim($script);
|
|
1531 }
|
|
1532 }
|
|
1533
|
|
1534 /**
|
|
1535 * Link an external css file
|
|
1536 *
|
|
1537 * @param string $file File URL
|
|
1538 */
|
|
1539 public function include_css($file)
|
|
1540 {
|
|
1541 $this->css_files[] = $file;
|
|
1542 }
|
|
1543
|
|
1544 /**
|
|
1545 * Add HTML code to the page header
|
|
1546 *
|
|
1547 * @param string $str HTML code
|
|
1548 */
|
|
1549 public function add_header($str)
|
|
1550 {
|
|
1551 $this->header .= "\n" . $str;
|
|
1552 }
|
|
1553
|
|
1554 /**
|
|
1555 * Add HTML code to the page footer
|
|
1556 * To be added right befor </body>
|
|
1557 *
|
|
1558 * @param string $str HTML code
|
|
1559 */
|
|
1560 public function add_footer($str)
|
|
1561 {
|
|
1562 $this->footer .= "\n" . $str;
|
|
1563 }
|
|
1564
|
|
1565 /**
|
|
1566 * Process template and write to stdOut
|
|
1567 *
|
|
1568 * @param string $templ HTML template
|
|
1569 * @param string $base_path Base for absolute paths
|
|
1570 */
|
|
1571 protected function _write($templ = '', $base_path = '')
|
|
1572 {
|
|
1573 $output = trim($templ);
|
|
1574
|
|
1575 if (empty($output)) {
|
|
1576 $output = html::doctype('html5') . "\n" . $this->default_template;
|
|
1577 $is_empty = true;
|
|
1578 }
|
|
1579
|
|
1580 // set default page title
|
|
1581 if (empty($this->pagetitle)) {
|
|
1582 $this->pagetitle = 'Roundcube Mail';
|
|
1583 }
|
|
1584
|
|
1585 // declare page language
|
|
1586 if (!empty($_SESSION['language'])) {
|
|
1587 $lang = substr($_SESSION['language'], 0, 2);
|
|
1588 $output = preg_replace('/<html/', '<html lang="' . html::quote($lang) . '"', $output, 1);
|
|
1589 if (!headers_sent()) {
|
|
1590 header('Content-Language: ' . $lang);
|
|
1591 }
|
|
1592 }
|
|
1593
|
|
1594 // replace specialchars in content
|
|
1595 $page_title = html::quote($this->pagetitle);
|
|
1596 $page_header = '';
|
|
1597 $page_footer = '';
|
|
1598
|
|
1599 // include meta tag with charset
|
|
1600 if (!empty($this->charset)) {
|
|
1601 if (!headers_sent()) {
|
|
1602 header('Content-Type: text/html; charset=' . $this->charset);
|
|
1603 }
|
|
1604 $page_header = '<meta http-equiv="content-type"';
|
|
1605 $page_header.= ' content="text/html; charset=';
|
|
1606 $page_header.= $this->charset . '" />'."\n";
|
|
1607 }
|
|
1608
|
|
1609 // definition of the code to be placed in the document header and footer
|
|
1610 if (is_array($this->script_files['head'])) {
|
|
1611 foreach ($this->script_files['head'] as $file) {
|
|
1612 $page_header .= html::script($file);
|
|
1613 }
|
|
1614 }
|
|
1615
|
|
1616 $head_script = $this->scripts['head_top'] . $this->scripts['head'];
|
|
1617 if (!empty($head_script)) {
|
|
1618 $page_header .= html::script(array(), $head_script);
|
|
1619 }
|
|
1620
|
|
1621 if (!empty($this->header)) {
|
|
1622 $page_header .= $this->header;
|
|
1623 }
|
|
1624
|
|
1625 // put docready commands into page footer
|
|
1626 if (!empty($this->scripts['docready'])) {
|
|
1627 $this->add_script('$(document).ready(function(){ ' . $this->scripts['docready'] . "\n});", 'foot');
|
|
1628 }
|
|
1629
|
|
1630 if (is_array($this->script_files['foot'])) {
|
|
1631 foreach ($this->script_files['foot'] as $file) {
|
|
1632 $page_footer .= html::script($file);
|
|
1633 }
|
|
1634 }
|
|
1635
|
|
1636 if (!empty($this->footer)) {
|
|
1637 $page_footer .= $this->footer . "\n";
|
|
1638 }
|
|
1639
|
|
1640 if (!empty($this->scripts['foot'])) {
|
|
1641 $page_footer .= html::script(array(), $this->scripts['foot']);
|
|
1642 }
|
|
1643
|
|
1644 // find page header
|
|
1645 if ($hpos = stripos($output, '</head>')) {
|
|
1646 $page_header .= "\n";
|
|
1647 }
|
|
1648 else {
|
|
1649 if (!is_numeric($hpos)) {
|
|
1650 $hpos = stripos($output, '<body');
|
|
1651 }
|
|
1652 if (!is_numeric($hpos) && ($hpos = stripos($output, '<html'))) {
|
|
1653 while ($output[$hpos] != '>') {
|
|
1654 $hpos++;
|
|
1655 }
|
|
1656 $hpos++;
|
|
1657 }
|
|
1658 $page_header = "<head>\n<title>$page_title</title>\n$page_header\n</head>\n";
|
|
1659 }
|
|
1660
|
|
1661 // add page hader
|
|
1662 if ($hpos) {
|
|
1663 $output = substr_replace($output, $page_header, $hpos, 0);
|
|
1664 }
|
|
1665 else {
|
|
1666 $output = $page_header . $output;
|
|
1667 }
|
|
1668
|
|
1669 // add page footer
|
|
1670 if (($fpos = strripos($output, '</body>')) || ($fpos = strripos($output, '</html>'))) {
|
|
1671 $output = substr_replace($output, $page_footer."\n", $fpos, 0);
|
|
1672 }
|
|
1673 else {
|
|
1674 $output .= "\n".$page_footer;
|
|
1675 }
|
|
1676
|
|
1677 // add css files in head, before scripts, for speed up with parallel downloads
|
|
1678 if (!empty($this->css_files) && !$is_empty
|
|
1679 && (($pos = stripos($output, '<script ')) || ($pos = stripos($output, '</head>')))
|
|
1680 ) {
|
|
1681 $css = '';
|
|
1682 foreach ($this->css_files as $file) {
|
|
1683 $css .= html::tag('link', array('rel' => 'stylesheet',
|
|
1684 'type' => 'text/css', 'href' => $file, 'nl' => true));
|
|
1685 }
|
|
1686 $output = substr_replace($output, $css, $pos, 0);
|
|
1687 }
|
|
1688
|
|
1689 $output = $this->parse_with_globals($this->fix_paths($output));
|
|
1690
|
|
1691 if ($this->assets_path) {
|
|
1692 $output = $this->fix_assets_paths($output);
|
|
1693 }
|
|
1694
|
|
1695 $output = $this->postrender($output);
|
|
1696
|
|
1697 // trigger hook with final HTML content to be sent
|
|
1698 $hook = $this->app->plugins->exec_hook("send_page", array('content' => $output));
|
|
1699 if (!$hook['abort']) {
|
|
1700 if ($this->charset != RCUBE_CHARSET) {
|
|
1701 echo rcube_charset::convert($hook['content'], RCUBE_CHARSET, $this->charset);
|
|
1702 }
|
|
1703 else {
|
|
1704 echo $hook['content'];
|
|
1705 }
|
|
1706 }
|
|
1707 }
|
|
1708
|
|
1709 /**
|
|
1710 * Returns iframe object, registers some related env variables
|
|
1711 *
|
|
1712 * @param array $attrib HTML attributes
|
|
1713 * @param boolean $is_contentframe Register this iframe as the 'contentframe' gui object
|
|
1714 *
|
|
1715 * @return string IFRAME element
|
|
1716 */
|
|
1717 public function frame($attrib, $is_contentframe = false)
|
|
1718 {
|
|
1719 static $idcount = 0;
|
|
1720
|
|
1721 if (!$attrib['id']) {
|
|
1722 $attrib['id'] = 'rcmframe' . ++$idcount;
|
|
1723 }
|
|
1724
|
|
1725 $attrib['name'] = $attrib['id'];
|
|
1726 $attrib['src'] = $attrib['src'] ? $this->abs_url($attrib['src'], true) : 'program/resources/blank.gif';
|
|
1727
|
|
1728 // register as 'contentframe' object
|
|
1729 if ($is_contentframe || $attrib['contentframe']) {
|
|
1730 $this->set_env('contentframe', $attrib['contentframe'] ? $attrib['contentframe'] : $attrib['name']);
|
|
1731 $this->set_env('blankpage', $this->asset_url($attrib['src']));
|
|
1732 }
|
|
1733
|
|
1734 return html::iframe($attrib);
|
|
1735 }
|
|
1736
|
|
1737
|
|
1738 /* ************* common functions delivering gui objects ************** */
|
|
1739
|
|
1740 /**
|
|
1741 * Create a form tag with the necessary hidden fields
|
|
1742 *
|
|
1743 * @param array $attrib Named tag parameters
|
|
1744 * @param string $content HTML content of the form
|
|
1745 *
|
|
1746 * @return string HTML code for the form
|
|
1747 */
|
|
1748 public function form_tag($attrib, $content = null)
|
|
1749 {
|
|
1750 if ($this->env['extwin']) {
|
|
1751 $hiddenfield = new html_hiddenfield(array('name' => '_extwin', 'value' => '1'));
|
|
1752 $hidden = $hiddenfield->show();
|
|
1753 }
|
|
1754 else if ($this->framed || $this->env['framed']) {
|
|
1755 $hiddenfield = new html_hiddenfield(array('name' => '_framed', 'value' => '1'));
|
|
1756 $hidden = $hiddenfield->show();
|
|
1757 }
|
|
1758
|
|
1759 if (!$content) {
|
|
1760 $attrib['noclose'] = true;
|
|
1761 }
|
|
1762
|
|
1763 return html::tag('form',
|
|
1764 $attrib + array('action' => $this->app->comm_path, 'method' => "get"),
|
|
1765 $hidden . $content,
|
|
1766 array('id','class','style','name','method','action','enctype','onsubmit')
|
|
1767 );
|
|
1768 }
|
|
1769
|
|
1770 /**
|
|
1771 * Build a form tag with a unique request token
|
|
1772 *
|
|
1773 * @param array $attrib Named tag parameters including 'action' and 'task' values
|
|
1774 * which will be put into hidden fields
|
|
1775 * @param string $content Form content
|
|
1776 *
|
|
1777 * @return string HTML code for the form
|
|
1778 */
|
|
1779 public function request_form($attrib, $content = '')
|
|
1780 {
|
|
1781 $hidden = new html_hiddenfield();
|
|
1782 if ($attrib['task']) {
|
|
1783 $hidden->add(array('name' => '_task', 'value' => $attrib['task']));
|
|
1784 }
|
|
1785 if ($attrib['action']) {
|
|
1786 $hidden->add(array('name' => '_action', 'value' => $attrib['action']));
|
|
1787 }
|
|
1788
|
|
1789 // we already have a <form> tag
|
|
1790 if ($attrib['form']) {
|
|
1791 if ($this->framed || $this->env['framed']) {
|
|
1792 $hidden->add(array('name' => '_framed', 'value' => '1'));
|
|
1793 }
|
|
1794
|
|
1795 return $hidden->show() . $content;
|
|
1796 }
|
|
1797
|
|
1798 unset($attrib['task'], $attrib['request']);
|
|
1799 $attrib['action'] = './';
|
|
1800
|
|
1801 return $this->form_tag($attrib, $hidden->show() . $content);
|
|
1802 }
|
|
1803
|
|
1804 /**
|
|
1805 * GUI object 'username'
|
|
1806 * Showing IMAP username of the current session
|
|
1807 *
|
|
1808 * @param array $attrib Named tag parameters (currently not used)
|
|
1809 *
|
|
1810 * @return string HTML code for the gui object
|
|
1811 */
|
|
1812 public function current_username($attrib)
|
|
1813 {
|
|
1814 static $username;
|
|
1815
|
|
1816 // alread fetched
|
|
1817 if (!empty($username)) {
|
|
1818 return $username;
|
|
1819 }
|
|
1820
|
|
1821 // Current username is an e-mail address
|
|
1822 if (strpos($_SESSION['username'], '@')) {
|
|
1823 $username = $_SESSION['username'];
|
|
1824 }
|
|
1825 // get e-mail address from default identity
|
|
1826 else if ($sql_arr = $this->app->user->get_identity()) {
|
|
1827 $username = $sql_arr['email'];
|
|
1828 }
|
|
1829 else {
|
|
1830 $username = $this->app->user->get_username();
|
|
1831 }
|
|
1832
|
|
1833 return rcube_utils::idn_to_utf8($username);
|
|
1834 }
|
|
1835
|
|
1836 /**
|
|
1837 * GUI object 'loginform'
|
|
1838 * Returns code for the webmail login form
|
|
1839 *
|
|
1840 * @param array $attrib Named parameters
|
|
1841 *
|
|
1842 * @return string HTML code for the gui object
|
|
1843 */
|
|
1844 protected function login_form($attrib)
|
|
1845 {
|
|
1846 $default_host = $this->config->get('default_host');
|
|
1847 $autocomplete = (int) $this->config->get('login_autocomplete');
|
|
1848
|
|
1849 $_SESSION['temp'] = true;
|
|
1850
|
|
1851 // save original url
|
|
1852 $url = rcube_utils::get_input_value('_url', rcube_utils::INPUT_POST);
|
|
1853 if (empty($url) && !preg_match('/_(task|action)=logout/', $_SERVER['QUERY_STRING']))
|
|
1854 $url = $_SERVER['QUERY_STRING'];
|
|
1855
|
|
1856 // Disable autocapitalization on iPad/iPhone (#1488609)
|
|
1857 $attrib['autocapitalize'] = 'off';
|
|
1858
|
|
1859 $form_name = !empty($attrib['form']) ? $attrib['form'] : 'form';
|
|
1860
|
|
1861 // set atocomplete attribute
|
|
1862 $user_attrib = $autocomplete > 0 ? array() : array('autocomplete' => 'off');
|
|
1863 $host_attrib = $autocomplete > 0 ? array() : array('autocomplete' => 'off');
|
|
1864 $pass_attrib = $autocomplete > 1 ? array() : array('autocomplete' => 'off');
|
|
1865
|
|
1866 $input_task = new html_hiddenfield(array('name' => '_task', 'value' => 'login'));
|
|
1867 $input_action = new html_hiddenfield(array('name' => '_action', 'value' => 'login'));
|
|
1868 $input_tzone = new html_hiddenfield(array('name' => '_timezone', 'id' => 'rcmlogintz', 'value' => '_default_'));
|
|
1869 $input_url = new html_hiddenfield(array('name' => '_url', 'id' => 'rcmloginurl', 'value' => $url));
|
|
1870 $input_user = new html_inputfield(array('name' => '_user', 'id' => 'rcmloginuser', 'required' => 'required')
|
|
1871 + $attrib + $user_attrib);
|
|
1872 $input_pass = new html_passwordfield(array('name' => '_pass', 'id' => 'rcmloginpwd', 'required' => 'required')
|
|
1873 + $attrib + $pass_attrib);
|
|
1874 $input_host = null;
|
|
1875
|
|
1876 if (is_array($default_host) && count($default_host) > 1) {
|
|
1877 $input_host = new html_select(array('name' => '_host', 'id' => 'rcmloginhost'));
|
|
1878
|
|
1879 foreach ($default_host as $key => $value) {
|
|
1880 if (!is_array($value)) {
|
|
1881 $input_host->add($value, (is_numeric($key) ? $value : $key));
|
|
1882 }
|
|
1883 else {
|
|
1884 $input_host = null;
|
|
1885 break;
|
|
1886 }
|
|
1887 }
|
|
1888 }
|
|
1889 else if (is_array($default_host) && ($host = key($default_host)) !== null) {
|
|
1890 $hide_host = true;
|
|
1891 $input_host = new html_hiddenfield(array(
|
|
1892 'name' => '_host', 'id' => 'rcmloginhost', 'value' => is_numeric($host) ? $default_host[$host] : $host) + $attrib);
|
|
1893 }
|
|
1894 else if (empty($default_host)) {
|
|
1895 $input_host = new html_inputfield(array('name' => '_host', 'id' => 'rcmloginhost')
|
|
1896 + $attrib + $host_attrib);
|
|
1897 }
|
|
1898
|
|
1899 $this->add_gui_object('loginform', $form_name);
|
|
1900
|
|
1901 // create HTML table with two cols
|
|
1902 $table = new html_table(array('cols' => 2));
|
|
1903
|
|
1904 $table->add('title', html::label('rcmloginuser', html::quote($this->app->gettext('username'))));
|
|
1905 $table->add('input', $input_user->show(rcube_utils::get_input_value('_user', rcube_utils::INPUT_GPC)));
|
|
1906
|
|
1907 $table->add('title', html::label('rcmloginpwd', html::quote($this->app->gettext('password'))));
|
|
1908 $table->add('input', $input_pass->show());
|
|
1909
|
|
1910 // add host selection row
|
|
1911 if (is_object($input_host) && !$hide_host) {
|
|
1912 $table->add('title', html::label('rcmloginhost', html::quote($this->app->gettext('server'))));
|
|
1913 $table->add('input', $input_host->show(rcube_utils::get_input_value('_host', rcube_utils::INPUT_GPC)));
|
|
1914 }
|
|
1915
|
|
1916 $out = $input_task->show();
|
|
1917 $out .= $input_action->show();
|
|
1918 $out .= $input_tzone->show();
|
|
1919 $out .= $input_url->show();
|
|
1920 $out .= $table->show();
|
|
1921
|
|
1922 if ($hide_host) {
|
|
1923 $out .= $input_host->show();
|
|
1924 }
|
|
1925
|
|
1926 if (rcube_utils::get_boolean($attrib['submit'])) {
|
|
1927 $submit = new html_inputfield(array('type' => 'submit', 'id' => 'rcmloginsubmit',
|
|
1928 'class' => 'button mainaction', 'value' => $this->app->gettext('login')));
|
|
1929 $out .= html::p('formbuttons', $submit->show());
|
|
1930 }
|
|
1931
|
|
1932 // surround html output with a form tag
|
|
1933 if (empty($attrib['form'])) {
|
|
1934 $out = $this->form_tag(array('name' => $form_name, 'method' => 'post'), $out);
|
|
1935 }
|
|
1936
|
|
1937 // include script for timezone detection
|
|
1938 $this->include_script('jstz.min.js');
|
|
1939
|
|
1940 return $out;
|
|
1941 }
|
|
1942
|
|
1943 /**
|
|
1944 * GUI object 'preloader'
|
|
1945 * Loads javascript code for images preloading
|
|
1946 *
|
|
1947 * @param array $attrib Named parameters
|
|
1948 * @return void
|
|
1949 */
|
|
1950 protected function preloader($attrib)
|
|
1951 {
|
|
1952 $images = preg_split('/[\s\t\n,]+/', $attrib['images'], -1, PREG_SPLIT_NO_EMPTY);
|
|
1953 $images = array_map(array($this, 'abs_url'), $images);
|
|
1954 $images = array_map(array($this, 'asset_url'), $images);
|
|
1955
|
|
1956 if (empty($images) || $_REQUEST['_task'] == 'logout') {
|
|
1957 return;
|
|
1958 }
|
|
1959
|
|
1960 $this->add_script('var images = ' . self::json_serialize($images, $this->devel_mode) .';
|
|
1961 for (var i=0; i<images.length; i++) {
|
|
1962 img = new Image();
|
|
1963 img.src = images[i];
|
|
1964 }', 'docready');
|
|
1965 }
|
|
1966
|
|
1967 /**
|
|
1968 * GUI object 'searchform'
|
|
1969 * Returns code for search function
|
|
1970 *
|
|
1971 * @param array $attrib Named parameters
|
|
1972 *
|
|
1973 * @return string HTML code for the gui object
|
|
1974 */
|
|
1975 protected function search_form($attrib)
|
|
1976 {
|
|
1977 // add some labels to client
|
|
1978 $this->add_label('searching');
|
|
1979
|
|
1980 $attrib['name'] = '_q';
|
|
1981
|
|
1982 if (empty($attrib['id'])) {
|
|
1983 $attrib['id'] = 'rcmqsearchbox';
|
|
1984 }
|
|
1985 if ($attrib['type'] == 'search' && !$this->browser->khtml) {
|
|
1986 unset($attrib['type'], $attrib['results']);
|
|
1987 }
|
|
1988
|
|
1989 $input_q = new html_inputfield($attrib);
|
|
1990 $out = $input_q->show();
|
|
1991
|
|
1992 $this->add_gui_object('qsearchbox', $attrib['id']);
|
|
1993
|
|
1994 // add form tag around text field
|
|
1995 if (empty($attrib['form'])) {
|
|
1996 $out = $this->form_tag(array(
|
|
1997 'name' => "rcmqsearchform",
|
|
1998 'onsubmit' => self::JS_OBJECT_NAME . ".command('search'); return false",
|
|
1999 'style' => "display:inline"
|
|
2000 ), $out);
|
|
2001 }
|
|
2002
|
|
2003 return $out;
|
|
2004 }
|
|
2005
|
|
2006 /**
|
|
2007 * Builder for GUI object 'message'
|
|
2008 *
|
|
2009 * @param array Named tag parameters
|
|
2010 * @return string HTML code for the gui object
|
|
2011 */
|
|
2012 protected function message_container($attrib)
|
|
2013 {
|
|
2014 if (isset($attrib['id']) === false) {
|
|
2015 $attrib['id'] = 'rcmMessageContainer';
|
|
2016 }
|
|
2017
|
|
2018 $this->add_gui_object('message', $attrib['id']);
|
|
2019
|
|
2020 return html::div($attrib, '');
|
|
2021 }
|
|
2022
|
|
2023 /**
|
|
2024 * GUI object 'charsetselector'
|
|
2025 *
|
|
2026 * @param array $attrib Named parameters for the select tag
|
|
2027 *
|
|
2028 * @return string HTML code for the gui object
|
|
2029 */
|
|
2030 public function charset_selector($attrib)
|
|
2031 {
|
|
2032 // pass the following attributes to the form class
|
|
2033 $field_attrib = array('name' => '_charset');
|
|
2034 foreach ($attrib as $attr => $value) {
|
|
2035 if (in_array($attr, array('id', 'name', 'class', 'style', 'size', 'tabindex'))) {
|
|
2036 $field_attrib[$attr] = $value;
|
|
2037 }
|
|
2038 }
|
|
2039
|
|
2040 $charsets = array(
|
|
2041 'UTF-8' => 'UTF-8 ('.$this->app->gettext('unicode').')',
|
|
2042 'US-ASCII' => 'ASCII ('.$this->app->gettext('english').')',
|
|
2043 'ISO-8859-1' => 'ISO-8859-1 ('.$this->app->gettext('westerneuropean').')',
|
|
2044 'ISO-8859-2' => 'ISO-8859-2 ('.$this->app->gettext('easterneuropean').')',
|
|
2045 'ISO-8859-4' => 'ISO-8859-4 ('.$this->app->gettext('baltic').')',
|
|
2046 'ISO-8859-5' => 'ISO-8859-5 ('.$this->app->gettext('cyrillic').')',
|
|
2047 'ISO-8859-6' => 'ISO-8859-6 ('.$this->app->gettext('arabic').')',
|
|
2048 'ISO-8859-7' => 'ISO-8859-7 ('.$this->app->gettext('greek').')',
|
|
2049 'ISO-8859-8' => 'ISO-8859-8 ('.$this->app->gettext('hebrew').')',
|
|
2050 'ISO-8859-9' => 'ISO-8859-9 ('.$this->app->gettext('turkish').')',
|
|
2051 'ISO-8859-10' => 'ISO-8859-10 ('.$this->app->gettext('nordic').')',
|
|
2052 'ISO-8859-11' => 'ISO-8859-11 ('.$this->app->gettext('thai').')',
|
|
2053 'ISO-8859-13' => 'ISO-8859-13 ('.$this->app->gettext('baltic').')',
|
|
2054 'ISO-8859-14' => 'ISO-8859-14 ('.$this->app->gettext('celtic').')',
|
|
2055 'ISO-8859-15' => 'ISO-8859-15 ('.$this->app->gettext('westerneuropean').')',
|
|
2056 'ISO-8859-16' => 'ISO-8859-16 ('.$this->app->gettext('southeasterneuropean').')',
|
|
2057 'WINDOWS-1250' => 'Windows-1250 ('.$this->app->gettext('easterneuropean').')',
|
|
2058 'WINDOWS-1251' => 'Windows-1251 ('.$this->app->gettext('cyrillic').')',
|
|
2059 'WINDOWS-1252' => 'Windows-1252 ('.$this->app->gettext('westerneuropean').')',
|
|
2060 'WINDOWS-1253' => 'Windows-1253 ('.$this->app->gettext('greek').')',
|
|
2061 'WINDOWS-1254' => 'Windows-1254 ('.$this->app->gettext('turkish').')',
|
|
2062 'WINDOWS-1255' => 'Windows-1255 ('.$this->app->gettext('hebrew').')',
|
|
2063 'WINDOWS-1256' => 'Windows-1256 ('.$this->app->gettext('arabic').')',
|
|
2064 'WINDOWS-1257' => 'Windows-1257 ('.$this->app->gettext('baltic').')',
|
|
2065 'WINDOWS-1258' => 'Windows-1258 ('.$this->app->gettext('vietnamese').')',
|
|
2066 'ISO-2022-JP' => 'ISO-2022-JP ('.$this->app->gettext('japanese').')',
|
|
2067 'ISO-2022-KR' => 'ISO-2022-KR ('.$this->app->gettext('korean').')',
|
|
2068 'ISO-2022-CN' => 'ISO-2022-CN ('.$this->app->gettext('chinese').')',
|
|
2069 'EUC-JP' => 'EUC-JP ('.$this->app->gettext('japanese').')',
|
|
2070 'EUC-KR' => 'EUC-KR ('.$this->app->gettext('korean').')',
|
|
2071 'EUC-CN' => 'EUC-CN ('.$this->app->gettext('chinese').')',
|
|
2072 'BIG5' => 'BIG5 ('.$this->app->gettext('chinese').')',
|
|
2073 'GB2312' => 'GB2312 ('.$this->app->gettext('chinese').')',
|
|
2074 );
|
|
2075
|
|
2076 if ($post = rcube_utils::get_input_value('_charset', rcube_utils::INPUT_POST)) {
|
|
2077 $set = $post;
|
|
2078 }
|
|
2079 else if (!empty($attrib['selected'])) {
|
|
2080 $set = $attrib['selected'];
|
|
2081 }
|
|
2082 else {
|
|
2083 $set = $this->get_charset();
|
|
2084 }
|
|
2085
|
|
2086 $set = strtoupper($set);
|
|
2087 if (!isset($charsets[$set]) && preg_match('/^[A-Z0-9-]+$/', $set)) {
|
|
2088 $charsets[$set] = $set;
|
|
2089 }
|
|
2090
|
|
2091 $select = new html_select($field_attrib);
|
|
2092 $select->add(array_values($charsets), array_keys($charsets));
|
|
2093
|
|
2094 return $select->show($set);
|
|
2095 }
|
|
2096
|
|
2097 /**
|
|
2098 * Include content from config/about.<LANG>.html if available
|
|
2099 */
|
|
2100 protected function about_content($attrib)
|
|
2101 {
|
|
2102 $content = '';
|
|
2103 $filenames = array(
|
|
2104 'about.' . $_SESSION['language'] . '.html',
|
|
2105 'about.' . substr($_SESSION['language'], 0, 2) . '.html',
|
|
2106 'about.html',
|
|
2107 );
|
|
2108 foreach ($filenames as $file) {
|
|
2109 $fn = RCUBE_CONFIG_DIR . $file;
|
|
2110 if (is_readable($fn)) {
|
|
2111 $content = file_get_contents($fn);
|
|
2112 $content = $this->parse_conditions($content);
|
|
2113 $content = $this->parse_xml($content);
|
|
2114 break;
|
|
2115 }
|
|
2116 }
|
|
2117
|
|
2118 return $content;
|
|
2119 }
|
|
2120 }
|