| | |
| | | | program/include/rcmail_output_html.php | |
| | | | | |
| | | | This file is part of the Roundcube Webmail client | |
| | | | Copyright (C) 2006-2012, The Roundcube Dev Team | |
| | | | Copyright (C) 2006-2013, The Roundcube Dev Team | |
| | | | | |
| | | | Licensed under the GNU General Public License version 3 or | |
| | | | any later version with exceptions for skins & plugins. | |
| | |
| | | /** |
| | | * Class to create HTML page output using a skin template |
| | | * |
| | | * @package Core |
| | | * @package Webmail |
| | | * @subpackage View |
| | | */ |
| | | class rcmail_output_html extends rcmail_output |
| | |
| | | protected $footer = ''; |
| | | protected $body = ''; |
| | | protected $base_path = ''; |
| | | protected $devel_mode = false; |
| | | |
| | | // deprecated names of templates used before 0.5 |
| | | protected $deprecated_templates = array( |
| | |
| | | { |
| | | parent::__construct(); |
| | | |
| | | $this->devel_mode = $this->config->get('devel_mode'); |
| | | |
| | | //$this->framed = $framed; |
| | | $this->set_env('task', $task); |
| | | $this->set_env('x_frame_options', $this->config->get('x_frame_options', 'sameorigin')); |
| | |
| | | $this->set_env('skin', $skin); |
| | | |
| | | if (!empty($_REQUEST['_extwin'])) |
| | | $this->set_env('extwin', 1); |
| | | $this->set_env('extwin', 1); |
| | | if ($this->framed || !empty($_REQUEST['_framed'])) |
| | | $this->set_env('framed', 1); |
| | | $this->set_env('framed', 1); |
| | | |
| | | $lic = <<<EOF |
| | | /* |
| | | @licstart The following is the entire license notice for the |
| | | JavaScript code in this page. |
| | | |
| | | Copyright (C) 2005-2014 The Roundcube Dev Team |
| | | |
| | | The JavaScript code in this page is free software: you can redistribute |
| | | it and/or modify it under the terms of the GNU General Public License |
| | | as published by the Free Software Foundation, either version 3 of |
| | | the License, or (at your option) any later version. |
| | | |
| | | The code is distributed WITHOUT ANY WARRANTY; without even the implied |
| | | warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| | | See the GNU GPL for more details. |
| | | |
| | | @licend The above is the entire license notice |
| | | for the JavaScript code in this page. |
| | | */ |
| | | EOF; |
| | | // add common javascripts |
| | | $this->add_script($lic, 'head_top'); |
| | | $this->add_script('var '.self::JS_OBJECT_NAME.' = new rcube_webmail();', 'head_top'); |
| | | |
| | | // don't wait for page onload. Call init at the bottom of the page (delayed) |
| | |
| | | public function set_env($name, $value, $addtojs = true) |
| | | { |
| | | $this->env[$name] = $value; |
| | | |
| | | if ($addtojs || isset($this->js_env[$name])) { |
| | | $this->js_env[$name] = $value; |
| | | } |
| | |
| | | */ |
| | | public function reset($all = false) |
| | | { |
| | | $framed = $this->framed; |
| | | $env = $all ? null : array_intersect_key($this->env, array('extwin'=>1, 'framed'=>1)); |
| | | |
| | | parent::reset(); |
| | | |
| | | // let some env variables survive |
| | | $this->env = $this->js_env = $env; |
| | | $this->framed = $framed || $this->env['framed']; |
| | | $this->js_labels = array(); |
| | | $this->js_commands = array(); |
| | | $this->script_files = array(); |
| | |
| | | $this->header = ''; |
| | | $this->footer = ''; |
| | | $this->body = ''; |
| | | |
| | | // load defaults |
| | | if (!$all) { |
| | | $this->__construct(); |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | $output = preg_replace_callback('/<form\s+([^>]+)>/Ui', array($this, 'alter_form_tag'), $output); |
| | | $this->footer = preg_replace_callback('/<form\s+([^>]+)>/Ui', array($this, 'alter_form_tag'), $this->footer); |
| | | |
| | | if ($write) { |
| | | // add debug console |
| | | if ($realname != 'error' && ($this->config->get('debug_level') & 8)) { |
| | | $this->add_footer('<div id="console" style="position:absolute;top:5px;left:5px;width:405px;padding:2px;background:white;z-index:9000;display:none"> |
| | | <a href="#toggle" onclick="con=$(\'#dbgconsole\');con[con.is(\':visible\')?\'hide\':\'show\']();return false">console</a> |
| | | <textarea name="console" id="dbgconsole" rows="20" cols="40" style="display:none;width:400px;border:none;font-size:10px" spellcheck="false"></textarea></div>' |
| | | ); |
| | | $this->add_script( |
| | | "if (!window.console || !window.console.log) {\n". |
| | | " window.console = new rcube_console();\n". |
| | | " $('#console').show();\n". |
| | | "}", 'foot'); |
| | | } |
| | | $this->write(trim($output)); |
| | | } |
| | | else { |
| | | if (!$write) { |
| | | return $output; |
| | | } |
| | | |
| | | $this->write(trim($output)); |
| | | |
| | | if ($exit) { |
| | | exit; |
| | |
| | | } |
| | | |
| | | // add file modification timestamp |
| | | if (preg_match('/\.(js|css)$/', $file)) { |
| | | if ($fs = @filemtime($file)) { |
| | | $file .= '?s=' . $fs; |
| | | } |
| | | if (preg_match('/\.(js|css)$/', $file, $m)) { |
| | | $file = $this->file_mod($file); |
| | | } |
| | | |
| | | return $matches[1] . '=' . $matches[2] . $file . $matches[4]; |
| | | } |
| | | |
| | | /** |
| | | * Modify file by adding mtime indicator |
| | | */ |
| | | protected function file_mod($file) |
| | | { |
| | | $fs = false; |
| | | $ext = substr($file, strrpos($file, '.') + 1); |
| | | |
| | | // use minified file if exists (not in development mode) |
| | | if (!$this->devel_mode && !preg_match('/\.min\.' . $ext . '$/', $file)) { |
| | | $minified_file = substr($file, 0, strlen($ext) * -1) . 'min.' . $ext; |
| | | if ($fs = @filemtime($minified_file)) { |
| | | return $minified_file . '?s=' . $fs; |
| | | } |
| | | } |
| | | |
| | | if ($fs = @filemtime($file)) { |
| | | $file .= '?s=' . $fs; |
| | | } |
| | | |
| | | return $file; |
| | | } |
| | | |
| | | /** |
| | |
| | | return ''; |
| | | } |
| | | |
| | | // localize title and summary attributes |
| | | if ($command != 'button' && !empty($attrib['title']) && $this->app->text_exists($attrib['title'])) { |
| | | $attrib['title'] = $this->app->gettext($attrib['title']); |
| | | } |
| | | if ($command != 'button' && !empty($attrib['summary']) && $this->app->text_exists($attrib['summary'])) { |
| | | $attrib['summary'] = $this->app->gettext($attrib['summary']); |
| | | } |
| | | |
| | | // execute command |
| | | switch ($command) { |
| | | // return a button |
| | |
| | | $content = html::quote($this->get_pagetitle()); |
| | | } |
| | | else if ($object == 'pagetitle') { |
| | | if ($this->config->get('devel_mode') && !empty($_SESSION['username'])) |
| | | if ($this->devel_mode && !empty($_SESSION['username'])) |
| | | $title = $_SESSION['username'].' :: '; |
| | | else if ($prod_name = $this->config->get('product_name')) |
| | | $title = $prod_name . ' :: '; |
| | |
| | | $attrib['alt'] = html::quote($this->app->gettext($attrib['alt'], $attrib['domain'])); |
| | | } |
| | | |
| | | // set accessibility attributes |
| | | if (!$attrib['role']) { |
| | | $attrib['role'] = 'button'; |
| | | } |
| | | if (!empty($attrib['class']) && !empty($attrib['classact']) || !empty($attrib['imagepas']) && !empty($attrib['imageact'])) { |
| | | if (array_key_exists('tabindex', $attrib)) |
| | | $attrib['data-tabindex'] = $attrib['tabindex']; |
| | | $attrib['tabindex'] = '-1'; // disable button by default |
| | | $attrib['aria-disabled'] = 'true'; |
| | | } |
| | | |
| | | // set title to alt attribute for IE browsers |
| | | if ($this->browser->ie && !$attrib['title'] && $attrib['alt']) { |
| | | $attrib['title'] = $attrib['alt']; |
| | |
| | | } |
| | | else if ($attrib['type'] == 'link') { |
| | | $btn_content = isset($attrib['content']) ? $attrib['content'] : ($attrib['label'] ? $attrib['label'] : $attrib['command']); |
| | | $link_attrib = array('href', 'onclick', 'title', 'id', 'class', 'style', 'tabindex', 'target'); |
| | | $link_attrib = array_merge(html::$common_attrib, array('href', 'onclick', 'tabindex', 'target')); |
| | | if ($attrib['innerclass']) |
| | | $btn_content = html::span($attrib['innerclass'], $btn_content); |
| | | } |
| | |
| | | |
| | | // generate html code for button |
| | | if ($btn_content) { |
| | | $attrib_str = html::attrib_string($attrib, array_merge(html::$common_attrib, $link_attrib)); |
| | | $attrib_str = html::attrib_string($attrib, array_merge($link_attrib, array('data-*'))); |
| | | $out = sprintf('<a%s>%s</a>', $attrib_str, $btn_content); |
| | | } |
| | | |
| | |
| | | */ |
| | | public function include_script($file, $position='head') |
| | | { |
| | | static $sa_files = array(); |
| | | |
| | | if (!preg_match('|^https?://|i', $file) && $file[0] != '/') { |
| | | $file = $this->scripts_path . $file; |
| | | if ($fs = @filemtime($file)) { |
| | | $file .= '?s=' . $fs; |
| | | } |
| | | $file = $this->file_mod($this->scripts_path . $file); |
| | | } |
| | | |
| | | if (in_array($file, $sa_files)) { |
| | | return; |
| | | } |
| | | |
| | | $sa_files[] = $file; |
| | | |
| | | if (!is_array($this->script_files[$position])) { |
| | | $this->script_files[$position] = array(); |
| | | } |
| | | |
| | | $this->script_files[$position][] = $file; |
| | | if (!in_array($file, $this->script_files[$position])) { |
| | | $this->script_files[$position][] = $file; |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | // set default page title |
| | | if (empty($this->pagetitle)) { |
| | | $this->pagetitle = 'Roundcube Mail'; |
| | | } |
| | | |
| | | // declare page language |
| | | if (!empty($_SESSION['language'])) { |
| | | $lang = substr($_SESSION['language'], 0, 2); |
| | | $output = preg_replace('/<html/', '<html lang="' . html::quote($lang) . '"', $output, 1); |
| | | if (!headers_sent()) { |
| | | header('Content-Language: ' . $lang); |
| | | } |
| | | } |
| | | |
| | | // replace specialchars in content |
| | |
| | | $out .= $input_host->show(); |
| | | } |
| | | |
| | | if (rcube_utils::get_boolean($attrib['submit'])) { |
| | | $submit = new html_inputfield(array('type' => 'submit', 'id' => 'rcmloginsubmit', |
| | | 'class' => 'button mainaction', 'value' => $this->app->gettext('login'))); |
| | | $out .= html::p('formbuttons', $submit->show()); |
| | | } |
| | | |
| | | // surround html output with a form tag |
| | | if (empty($attrib['form'])) { |
| | | $out = $this->form_tag(array('name' => $form_name, 'method' => 'post'), $out); |
| | |
| | | // add form tag around text field |
| | | if (empty($attrib['form'])) { |
| | | $out = $this->form_tag(array( |
| | | 'name' => "rcmqsearchform", |
| | | 'name' => "rcmqsearchform", |
| | | 'onsubmit' => self::JS_OBJECT_NAME . ".command('search'); return false", |
| | | 'style' => "display:inline"), |
| | | 'style' => "display:inline"), |
| | | $out); |
| | | } |
| | | |