summaryrefslogtreecommitdiff
path: root/program/include
diff options
context:
space:
mode:
Diffstat (limited to 'program/include')
-rw-r--r--program/include/bc.php2
-rw-r--r--program/include/iniset.php6
-rw-r--r--program/include/rcmail.php258
-rw-r--r--program/include/rcmail_html_page.php2
-rw-r--r--program/include/rcmail_install.php776
-rw-r--r--program/include/rcmail_output.php2
-rw-r--r--program/include/rcmail_output_html.php190
-rw-r--r--program/include/rcmail_output_json.php2
-rw-r--r--program/include/rcmail_string_replacer.php2
9 files changed, 1069 insertions, 171 deletions
diff --git a/program/include/bc.php b/program/include/bc.php
index a7d7b5ac1..2cb151798 100644
--- a/program/include/bc.php
+++ b/program/include/bc.php
@@ -22,7 +22,7 @@
/**
* Roundcube Webmail deprecated functions
*
- * @package Core
+ * @package Webmail
* @subpackage Legacy
* @author Thomas Bruederli <roundcube@gmail.com>
*/
diff --git a/program/include/iniset.php b/program/include/iniset.php
index f6ad466da..5c3065489 100644
--- a/program/include/iniset.php
+++ b/program/include/iniset.php
@@ -5,7 +5,7 @@
| program/include/iniset.php |
| |
| This file is part of the Roundcube Webmail client |
- | Copyright (C) 2008-2013, The Roundcube Dev Team |
+ | Copyright (C) 2008-2014, The Roundcube Dev Team |
| |
| Licensed under the GNU General Public License version 3 or |
| any later version with exceptions for skins & plugins. |
@@ -21,7 +21,7 @@
*/
// application constants
-define('RCMAIL_VERSION', '1.0-git');
+define('RCMAIL_VERSION', '1.1-git');
define('RCMAIL_START', microtime(true));
if (!defined('INSTALL_PATH')) {
@@ -61,7 +61,7 @@ require_once 'Roundcube/bootstrap.php';
spl_autoload_register('rcmail_autoload');
// include composer autoloader (if available)
-if (file_exists('vendor/autoload.php')) {
+if (@file_exists('vendor/autoload.php')) {
require 'vendor/autoload.php';
}
diff --git a/program/include/rcmail.php b/program/include/rcmail.php
index ef63db9da..7a952cfe3 100644
--- a/program/include/rcmail.php
+++ b/program/include/rcmail.php
@@ -5,8 +5,8 @@
| program/include/rcmail.php |
| |
| This file is part of the Roundcube Webmail client |
- | Copyright (C) 2008-2013, The Roundcube Dev Team |
- | Copyright (C) 2011-2013, Kolab Systems AG |
+ | Copyright (C) 2008-2014, The Roundcube Dev Team |
+ | Copyright (C) 2011-2014, Kolab Systems AG |
| |
| Licensed under the GNU General Public License version 3 or |
| any later version with exceptions for skins & plugins. |
@@ -25,7 +25,7 @@
* Application class of Roundcube Webmail
* implemented as singleton
*
- * @package Core
+ * @package Webmail
*/
class rcmail extends rcube
{
@@ -139,6 +139,8 @@ class rcmail extends rcube
if ($this->user && $this->user->ID)
$task = !$task ? 'mail' : $task;
+ else if (php_sapi_name() == 'cli')
+ $task = 'cli';
else
$task = 'login';
@@ -157,12 +159,7 @@ class rcmail extends rcube
*/
public function set_user($user)
{
- if (is_object($user)) {
- $this->user = $user;
-
- // overwrite config with user preferences
- $this->config->set_user_prefs((array)$this->user->get_prefs());
- }
+ parent::set_user($user);
$lang = $this->language_prop($this->config->get('language', $_SESSION['language']));
$_SESSION['language'] = $this->user->language = $lang;
@@ -431,7 +428,7 @@ class rcmail extends rcube
}
// add some basic labels to client
- $this->output->add_label('loading', 'servererror', 'requesttimedout', 'refreshing');
+ $this->output->add_label('loading', 'servererror', 'connerror', 'requesttimedout', 'refreshing');
return $this->output;
}
@@ -492,32 +489,23 @@ class rcmail extends rcube
return false;
}
- $config = $this->config->all();
-
- if (!$host) {
- $host = $config['default_host'];
- }
-
- // Validate that selected host is in the list of configured hosts
- if (is_array($config['default_host'])) {
- $allowed = false;
+ $default_host = $this->config->get('default_host');
+ $default_port = $this->config->get('default_port');
+ $username_domain = $this->config->get('username_domain');
+ $login_lc = $this->config->get('login_lc', 2);
- foreach ($config['default_host'] as $key => $host_allowed) {
- if (!is_numeric($key)) {
- $host_allowed = $key;
- }
- if ($host == $host_allowed) {
- $allowed = true;
- break;
- }
+ // host is validated in rcmail::autoselect_host(), so here
+ // we'll only handle unset host (if possible)
+ if (!$host && !empty($default_host)) {
+ if (is_array($default_host)) {
+ list($key, $val) = each($default_host);
+ $host = is_numeric($key) ? $val : $key;
}
-
- if (!$allowed) {
- $host = null;
+ else {
+ $host = $default_host;
}
- }
- else if (!empty($config['default_host']) && $host != rcube_utils::parse_host($config['default_host'])) {
- $host = null;
+
+ $host = rcube_utils::parse_host($host);
}
if (!$host) {
@@ -533,23 +521,23 @@ class rcmail extends rcube
if (!empty($a_host['port']))
$port = $a_host['port'];
- else if ($ssl && $ssl != 'tls' && (!$config['default_port'] || $config['default_port'] == 143))
+ else if ($ssl && $ssl != 'tls' && (!$default_port || $default_port == 143))
$port = 993;
}
if (!$port) {
- $port = $config['default_port'];
+ $port = $default_port;
}
// Check if we need to add/force domain to username
- if (!empty($config['username_domain'])) {
- $domain = is_array($config['username_domain']) ? $config['username_domain'][$host] : $config['username_domain'];
+ if (!empty($username_domain)) {
+ $domain = is_array($username_domain) ? $username_domain[$host] : $username_domain;
if ($domain = rcube_utils::parse_host((string)$domain, $host)) {
$pos = strpos($username, '@');
// force configured domains
- if (!empty($config['username_domain_forced']) && $pos !== false) {
+ if ($pos !== false && $this->config->get('username_domain_forced')) {
$username = substr($username, 0, $pos) . '@' . $domain;
}
// just add domain if not specified
@@ -559,14 +547,10 @@ class rcmail extends rcube
}
}
- if (!isset($config['login_lc'])) {
- $config['login_lc'] = 2; // default
- }
-
// Convert username to lowercase. If storage backend
// is case-insensitive we need to store always the same username (#1487113)
- if ($config['login_lc']) {
- if ($config['login_lc'] == 2 || $config['login_lc'] === true) {
+ if ($login_lc) {
+ if ($login_lc == 2 || $login_lc === true) {
$username = mb_strtolower($username);
}
else if (strpos($username, '@')) {
@@ -604,7 +588,7 @@ class rcmail extends rcube
$user->touch();
}
// create new system user
- else if ($config['auto_create_user']) {
+ else if ($this->config->get('auto_create_user')) {
if ($created = rcube_user::create($username, $host)) {
$user = $created;
}
@@ -634,14 +618,6 @@ class rcmail extends rcube
$this->set_user($user);
$this->set_storage_prop();
- // fix some old settings according to namespace prefix
- $this->fix_namespace_settings($user);
-
- // create default folders on first login
- if ($config['create_default_folders'] && (!empty($created) || empty($user->data['last_login']))) {
- $storage->create_default_folders();
- }
-
// set session vars
$_SESSION['user_id'] = $user->ID;
$_SESSION['username'] = $user->data['username'];
@@ -655,7 +631,13 @@ class rcmail extends rcube
$_SESSION['timezone'] = rcube_utils::get_input_value('_timezone', rcube_utils::INPUT_GPC);
}
- // force reloading complete list of subscribed mailboxes
+ // fix some old settings according to namespace prefix
+ $this->fix_namespace_settings($user);
+
+ // set/create special folders
+ $this->set_special_folders();
+
+ // clear all mailboxes related cache(s)
$storage->clear_cache('mailboxes', true);
return true;
@@ -846,7 +828,10 @@ class rcmail extends rcube
}
// write performance stats to logs/console
- if ($this->config->get('devel_mode')) {
+ if ($this->config->get('devel_mode') || $this->config->get('performance_stats')) {
+ // make sure logged numbers use unified format
+ setlocale(LC_NUMERIC, 'en_US.utf8', 'en_US.UTF-8', 'en_US', 'C');
+
if (function_exists('memory_get_usage'))
$mem = $this->show_bytes(memory_get_usage());
if (function_exists('memory_get_peak_usage'))
@@ -933,14 +918,6 @@ class rcmail extends rcube
}
}
- if (!empty($prefs['default_folders'])) {
- foreach ($prefs['default_folders'] as $idx => $name) {
- if ($name != 'INBOX' && !preg_match($regexp, $name)) {
- $prefs['default_folders'][$idx] = $prefix.$name;
- }
- }
- }
-
if (!empty($prefs['search_mods'])) {
$folders = array();
foreach ($prefs['search_mods'] as $idx => $value) {
@@ -1168,11 +1145,11 @@ class rcmail extends rcube
$week_limit = mktime(0, 0, 0, $now_date['mon'], $now_date['mday']-6, $now_date['year']);
$pretty_date = $this->config->get('prettydate');
- if ($pretty_date && $timestamp > $today_limit && $timestamp < $now) {
+ if ($pretty_date && $timestamp > $today_limit && $timestamp <= $now) {
$format = $this->config->get('date_today', $this->config->get('time_format', 'H:i'));
$today = true;
}
- else if ($pretty_date && $timestamp > $week_limit && $timestamp < $now) {
+ else if ($pretty_date && $timestamp > $week_limit && $timestamp <= $now) {
$format = $this->config->get('date_short', 'D H:i');
}
else {
@@ -1361,12 +1338,31 @@ class rcmail extends rcube
$delimiter = $storage->get_hierarchy_delimiter();
- foreach ($list as $folder) {
- if (empty($p['exceptions']) || !in_array($folder, $p['exceptions'])) {
- $this->build_folder_tree($a_mailboxes, $folder, $delimiter);
+ if (!empty($p['exceptions'])) {
+ $list = array_diff($list, (array) $p['exceptions']);
+ }
+
+ if (!empty($p['additional'])) {
+ foreach ($p['additional'] as $add_folder) {
+ $add_items = explode($delimiter, $add_folder);
+ $folder = '';
+ while (count($add_items)) {
+ $folder .= array_shift($add_items);
+
+ // @TODO: sorting
+ if (!in_array($folder, $list)) {
+ $list[] = $folder;
+ }
+
+ $folder .= $delimiter;
+ }
}
}
+ foreach ($list as $folder) {
+ $this->build_folder_tree($a_mailboxes, $folder, $delimiter);
+ }
+
$select = new html_select($p);
if ($p['noselection']) {
@@ -1600,10 +1596,14 @@ class rcmail extends rcube
*
* @return string Localized folder name in UTF-8 encoding
*/
- public function localize_foldername($name, $with_path = true)
+ public function localize_foldername($name, $with_path = false)
{
$realnames = $this->config->get('show_real_foldernames');
+ if (!$realnames && ($folder_class = $this->folder_classname($name))) {
+ return $this->gettext($folder_class);
+ }
+
// try to localize path of the folder
if ($with_path && !$realnames) {
$storage = $this->get_storage();
@@ -1612,7 +1612,7 @@ class rcmail extends rcube
$count = count($path);
if ($count > 1) {
- for ($i = 0; $i < $count; $i++) {
+ for ($i = 1; $i < $count; $i++) {
$folder = implode($delimiter, array_slice($path, 0, -$i));
if ($folder_class = $this->folder_classname($folder)) {
$name = implode($delimiter, array_slice($path, $count - $i));
@@ -1622,10 +1622,6 @@ class rcmail extends rcube
}
}
- if (!$realnames && ($folder_class = $this->folder_classname($name))) {
- return $this->gettext($folder_class);
- }
-
return rcube_charset::convert($name, 'UTF7-IMAP');
}
@@ -1633,14 +1629,13 @@ class rcmail extends rcube
public function localize_folderpath($path)
{
$protect_folders = $this->config->get('protect_default_folders');
- $default_folders = (array) $this->config->get('default_folders');
$delimiter = $this->storage->get_hierarchy_delimiter();
$path = explode($delimiter, $path);
$result = array();
foreach ($path as $idx => $dir) {
$directory = implode($delimiter, array_slice($path, 0, $idx+1));
- if ($protect_folders && in_array($directory, $default_folders)) {
+ if ($protect_folders && $this->storage->is_special_folder($directory)) {
unset($result);
$result[] = $this->localize_foldername($directory);
}
@@ -1847,27 +1842,52 @@ class rcmail extends rcube
*/
public function upload_progress()
{
- $prefix = ini_get('apc.rfc1867_prefix');
$params = array(
'action' => $this->action,
- 'name' => rcube_utils::get_input_value('_progress', rcube_utils::INPUT_GET),
+ 'name' => rcube_utils::get_input_value('_progress', rcube_utils::INPUT_GET),
);
- if (function_exists('apc_fetch')) {
+ if (function_exists('uploadprogress_get_info')) {
+ $status = uploadprogress_get_info($params['name']);
+
+ if (!empty($status)) {
+ $params['current'] = $status['bytes_uploaded'];
+ $params['total'] = $status['bytes_total'];
+ }
+ }
+
+ if (!isset($status) && filter_var(ini_get('apc.rfc1867'), FILTER_VALIDATE_BOOLEAN)
+ && ini_get('apc.rfc1867_name')
+ ) {
+ $prefix = ini_get('apc.rfc1867_prefix');
$status = apc_fetch($prefix . $params['name']);
if (!empty($status)) {
- $status['percent'] = round($status['current']/$status['total']*100);
- $params = array_merge($status, $params);
+ $params['current'] = $status['current'];
+ $params['total'] = $status['total'];
}
}
- if (isset($params['percent']))
- $params['text'] = $this->gettext(array('name' => 'uploadprogress', 'vars' => array(
- 'percent' => $params['percent'] . '%',
- 'current' => $this->show_bytes($params['current']),
- 'total' => $this->show_bytes($params['total'])
- )));
+ if (!isset($status) && filter_var(ini_get('session.upload_progress.enabled'), FILTER_VALIDATE_BOOLEAN)
+ && ini_get('session.upload_progress.name')
+ ) {
+ $key = ini_get('session.upload_progress.prefix') . $params['name'];
+
+ $params['total'] = $_SESSION[$key]['content_length'];
+ $params['current'] = $_SESSION[$key]['bytes_processed'];
+ }
+
+ if (!empty($params['total'])) {
+ $params['percent'] = round($status['current']/$status['total']*100);
+ $params['text'] = $this->gettext(array(
+ 'name' => 'uploadprogress',
+ 'vars' => array(
+ 'percent' => $params['percent'] . '%',
+ 'current' => $this->show_bytes($params['current']),
+ 'total' => $this->show_bytes($params['total'])
+ )
+ ));
+ }
$this->output->command('upload_progress_update', $params);
$this->output->send();
@@ -1879,9 +1899,18 @@ class rcmail extends rcube
public function upload_init()
{
// Enable upload progress bar
- $rfc1867 = filter_var(ini_get('apc.rfc1867'), FILTER_VALIDATE_BOOLEAN);
- if ($rfc1867 && ($seconds = $this->config->get('upload_progress'))) {
- if ($field_name = ini_get('apc.rfc1867_name')) {
+ if ($seconds = $this->config->get('upload_progress')) {
+ if (function_exists('uploadprogress_get_info')) {
+ $field_name = 'UPLOAD_IDENTIFIER';
+ }
+ if (!$field_name && filter_var(ini_get('apc.rfc1867'), FILTER_VALIDATE_BOOLEAN)) {
+ $field_name = ini_get('apc.rfc1867_name');
+ }
+ if (!$field_name && filter_var(ini_get('session.upload_progress.enabled'), FILTER_VALIDATE_BOOLEAN)) {
+ $field_name = ini_get('session.upload_progress.name');
+ }
+
+ if ($field_name) {
$this->output->set_env('upload_progress_name', $field_name);
$this->output->set_env('upload_progress_time', (int) $seconds);
}
@@ -2012,6 +2041,55 @@ class rcmail extends rcube
return $size;
}
+ /**
+ * Returns message UID(s) and IMAP folder(s) from GET/POST data
+ *
+ * @param string UID value to decode
+ * @param string Default mailbox value (if not encoded in UIDs)
+ * @return array List of message UIDs per folder
+ */
+ public static function get_uids($uids = null, $mbox = null)
+ {
+ // message UID (or comma-separated list of IDs) is provided in
+ // the form of <ID>-<MBOX>[,<ID>-<MBOX>]*
+
+ $_uid = $uids ?: rcube_utils::get_input_value('_uid', RCUBE_INPUT_GPC);
+ $_mbox = $mbox ?: (string)rcube_utils::get_input_value('_mbox', RCUBE_INPUT_GPC);
+
+ // already a hash array
+ if (is_array($_uid) && !isset($_uid[0])) {
+ return $_uid;
+ }
+
+ $result = array();
+
+ // special case: *
+ if ($_uid == '*' && is_object($_SESSION['search'][1]) && $_SESSION['search'][1]->multi) {
+ // extract the full list of UIDs per folder from the search set
+ foreach ($_SESSION['search'][1]->sets as $subset) {
+ $mbox = $subset->get_parameters('MAILBOX');
+ $result[$mbox] = $subset->get();
+ }
+ }
+ else {
+ if (is_string($_uid))
+ $_uid = explode(',', $_uid);
+
+ // create a per-folder UIDs array
+ foreach ((array)$_uid as $uid) {
+ list($uid, $mbox) = explode('-', $uid, 2);
+ if (!strlen($mbox))
+ $mbox = $_mbox;
+ if ($uid == '*')
+ $result[$mbox] = $uid;
+ else
+ $result[$mbox][] = $uid;
+ }
+ }
+
+ return $result;
+ }
+
/************************************************************************
********* Deprecated methods (to be removed) *********
diff --git a/program/include/rcmail_html_page.php b/program/include/rcmail_html_page.php
index d5610ab47..604d756e7 100644
--- a/program/include/rcmail_html_page.php
+++ b/program/include/rcmail_html_page.php
@@ -23,7 +23,7 @@
/**
* Class to create an empty HTML page with some default styles
*
- * @package Core
+ * @package Webmail
* @subpackage View
*/
class rcmail_html_page extends rcmail_output_html
diff --git a/program/include/rcmail_install.php b/program/include/rcmail_install.php
new file mode 100644
index 000000000..eec21ec7e
--- /dev/null
+++ b/program/include/rcmail_install.php
@@ -0,0 +1,776 @@
+<?php
+
+/*
+ +-----------------------------------------------------------------------+
+ | rcmail_install.php |
+ | |
+ | This file is part of the Roundcube Webmail package |
+ | Copyright (C) 2008-2014, The Roundcube Dev Team |
+ | |
+ | Licensed under the GNU General Public License version 3 or |
+ | any later version with exceptions for skins & plugins. |
+ | See the README file for a full license statement. |
+ +-----------------------------------------------------------------------+
+*/
+
+
+/**
+ * Class to control the installation process of the Roundcube Webmail package
+ *
+ * @category Install
+ * @package Roundcube
+ * @author Thomas Bruederli
+ */
+class rcmail_install
+{
+ var $step;
+ var $is_post = false;
+ var $failures = 0;
+ var $config = array();
+ var $configured = false;
+ var $legacy_config = false;
+ var $last_error = null;
+ var $email_pattern = '([a-z0-9][a-z0-9\-\.\+\_]*@[a-z0-9]([a-z0-9\-][.]?)*[a-z0-9])';
+ var $bool_config_props = array();
+
+ var $local_config = array('db_dsnw', 'default_host', 'support_url', 'des_key', 'plugins');
+ var $obsolete_config = array('db_backend', 'db_max_length', 'double_auth');
+ var $replaced_config = array(
+ 'skin_path' => 'skin',
+ 'locale_string' => 'language',
+ 'multiple_identities' => 'identities_level',
+ 'addrbook_show_images' => 'show_images',
+ 'imap_root' => 'imap_ns_personal',
+ 'pagesize' => 'mail_pagesize',
+ 'top_posting' => 'reply_mode',
+ 'keep_alive' => 'refresh_interval',
+ 'min_keep_alive' => 'min_refresh_interval',
+ );
+
+ // list of supported database drivers
+ var $supported_dbs = array(
+ 'MySQL' => 'pdo_mysql',
+ 'PostgreSQL' => 'pdo_pgsql',
+ 'SQLite' => 'pdo_sqlite',
+ 'SQLite (v2)' => 'pdo_sqlite2',
+ 'SQL Server (SQLSRV)' => 'pdo_sqlsrv',
+ 'SQL Server (DBLIB)' => 'pdo_dblib',
+ );
+
+
+ /**
+ * Constructor
+ */
+ function __construct()
+ {
+ $this->step = intval($_REQUEST['_step']);
+ $this->is_post = $_SERVER['REQUEST_METHOD'] == 'POST';
+ }
+
+ /**
+ * Singleton getter
+ */
+ static function get_instance()
+ {
+ static $inst;
+
+ if (!$inst)
+ $inst = new rcmail_install();
+
+ return $inst;
+ }
+
+ /**
+ * Read the local config files and store properties
+ */
+ function load_config()
+ {
+ // defaults
+ if ($config = $this->load_config_file(RCUBE_CONFIG_DIR . 'defaults.inc.php')) {
+ $this->config = (array) $config;
+ $this->defaults = $this->config;
+ }
+
+ $config = null;
+
+ // config
+ if ($config = $this->load_config_file(RCUBE_CONFIG_DIR . 'config.inc.php')) {
+ $this->config = array_merge($this->config, $config);
+ }
+ else {
+ if ($config = $this->load_config_file(RCUBE_CONFIG_DIR . 'main.inc.php')) {
+ $this->config = array_merge($this->config, $config);
+ $this->legacy_config = true;
+ }
+ if ($config = $this->load_config_file(RCUBE_CONFIG_DIR . 'db.inc.php')) {
+ $this->config = array_merge($this->config, $config);
+ $this->legacy_config = true;
+ }
+ }
+
+ $this->configured = !empty($config);
+ }
+
+ /**
+ * Read the default config file and store properties
+ */
+ public function load_config_file($file)
+ {
+ if (is_readable($file)) {
+ include $file;
+
+ // read comments from config file
+ if (function_exists('token_get_all')) {
+ $tokens = token_get_all(file_get_contents($file));
+ $in_config = false;
+ $buffer = '';
+ for ($i=0; $i < count($tokens); $i++) {
+ $token = $tokens[$i];
+ if ($token[0] == T_VARIABLE && $token[1] == '$config' || $token[1] == '$rcmail_config') {
+ $in_config = true;
+ if ($buffer && $tokens[$i+1] == '[' && $tokens[$i+2][0] == T_CONSTANT_ENCAPSED_STRING) {
+ $propname = trim($tokens[$i+2][1], "'\"");
+ $this->comments[$propname] = $buffer;
+ $buffer = '';
+ $i += 3;
+ }
+ }
+ else if ($in_config && $token[0] == T_COMMENT) {
+ $buffer .= strtr($token[1], array('\n' => "\n"));
+ }
+ }
+ }
+
+ // deprecated name of config variable
+ if (is_array($rcmail_config)) {
+ return $rcmail_config;
+ }
+
+ return $config;
+ }
+ }
+
+ /**
+ * Getter for a certain config property
+ *
+ * @param string Property name
+ * @param string Default value
+ * @return string The property value
+ */
+ function getprop($name, $default = '')
+ {
+ $value = $this->config[$name];
+
+ if ($name == 'des_key' && !$this->configured && !isset($_REQUEST["_$name"]))
+ $value = self::random_key(24);
+
+ return $value !== null && $value !== '' ? $value : $default;
+ }
+
+
+ /**
+ * Create configuration file that contains parameters
+ * that differ from default values.
+ *
+ * @return string The complete config file content
+ */
+ function create_config()
+ {
+ $config = array();
+
+ foreach ($this->config as $prop => $default) {
+ $is_default = !isset($_POST["_$prop"]);
+ $value = !$is_default || $this->bool_config_props[$prop] ? $_POST["_$prop"] : $default;
+
+ // always disable installer
+ if ($prop == 'enable_installer')
+ $value = false;
+
+ // reset useragent to default (keeps version up-to-date)
+ if ($prop == 'useragent' && stripos($value, 'Roundcube Webmail/') !== false)
+ $value = $this->defaults[$prop];
+
+ // generate new encryption key, never use the default value
+ if ($prop == 'des_key' && $value == $this->defaults[$prop])
+ $value = $this->random_key(24);
+
+ // convert some form data
+ if ($prop == 'debug_level' && !$is_default) {
+ if (is_array($value)) {
+ $val = 0;
+ foreach ($value as $dbgval)
+ $val += intval($dbgval);
+ $value = $val;
+ }
+ }
+ else if ($prop == 'db_dsnw' && !empty($_POST['_dbtype'])) {
+ if ($_POST['_dbtype'] == 'sqlite')
+ $value = sprintf('%s://%s?mode=0646', $_POST['_dbtype'], $_POST['_dbname']{0} == '/' ? '/' . $_POST['_dbname'] : $_POST['_dbname']);
+ else if ($_POST['_dbtype'])
+ $value = sprintf('%s://%s:%s@%s/%s', $_POST['_dbtype'],
+ rawurlencode($_POST['_dbuser']), rawurlencode($_POST['_dbpass']), $_POST['_dbhost'], $_POST['_dbname']);
+ }
+ else if ($prop == 'smtp_auth_type' && $value == '0') {
+ $value = '';
+ }
+ else if ($prop == 'default_host' && is_array($value)) {
+ $value = self::_clean_array($value);
+ if (count($value) <= 1)
+ $value = $value[0];
+ }
+ else if ($prop == 'mail_pagesize' || $prop == 'addressbook_pagesize') {
+ $value = max(2, intval($value));
+ }
+ else if ($prop == 'smtp_user' && !empty($_POST['_smtp_user_u'])) {
+ $value = '%u';
+ }
+ else if ($prop == 'smtp_pass' && !empty($_POST['_smtp_user_u'])) {
+ $value = '%p';
+ }
+ else if (is_bool($default)) {
+ $value = (bool)$value;
+ }
+ else if (is_numeric($value)) {
+ $value = intval($value);
+ }
+
+ // skip this property
+ if (($value == $this->defaults[$prop]) && !in_array($prop, $this->local_config)
+ || in_array($prop, array_merge($this->obsolete_config, array_keys($this->replaced_config)))
+ || preg_match('/^db_(table|sequence)_/', $prop)) {
+ continue;
+ }
+
+ // save change
+ $this->config[$prop] = $value;
+ $config[$prop] = $value;
+ }
+
+ $out = "<?php\n\n";
+ $out .= "/* Local configuration for Roundcube Webmail */\n\n";
+ foreach ($config as $prop => $value) {
+ // copy option descriptions from existing config or defaults.inc.php
+ $out .= $this->comments[$prop];
+ $out .= "\$config['$prop'] = " . self::_dump_var($value, $prop) . ";\n\n";
+ }
+
+ return $out;
+ }
+
+
+ /**
+ * save generated config file in RCUBE_CONFIG_DIR
+ *
+ * @return boolean True if the file was saved successfully, false if not
+ */
+ function save_configfile($config)
+ {
+ if (is_writable(RCUBE_CONFIG_DIR)) {
+ return file_put_contents(RCUBE_CONFIG_DIR . 'config.inc.php', $config);
+ }
+
+ return false;
+ }
+
+ /**
+ * Check the current configuration for missing properties
+ * and deprecated or obsolete settings
+ *
+ * @return array List with problems detected
+ */
+ function check_config()
+ {
+ $this->load_config();
+
+ if (!$this->configured) {
+ return null;
+ }
+
+ $out = $seen = array();
+
+ // iterate over the current configuration
+ foreach ($this->config as $prop => $value) {
+ if ($replacement = $this->replaced_config[$prop]) {
+ $out['replaced'][] = array('prop' => $prop, 'replacement' => $replacement);
+ $seen[$replacement] = true;
+ }
+ else if (!$seen[$prop] && in_array($prop, $this->obsolete_config)) {
+ $out['obsolete'][] = array('prop' => $prop);
+ $seen[$prop] = true;
+ }
+ }
+
+ // the old default mime_magic reference is obsolete
+ if ($this->config['mime_magic'] == '/usr/share/misc/magic') {
+ $out['obsolete'][] = array('prop' => 'mime_magic', 'explain' => "Set value to null in order to use system default");
+ }
+
+ // check config dependencies and contradictions
+ if ($this->config['enable_spellcheck'] && $this->config['spellcheck_engine'] == 'pspell') {
+ if (!extension_loaded('pspell')) {
+ $out['dependencies'][] = array('prop' => 'spellcheck_engine',
+ 'explain' => 'This requires the <tt>pspell</tt> extension which could not be loaded.');
+ }
+ else if (!empty($this->config['spellcheck_languages'])) {
+ foreach ($this->config['spellcheck_languages'] as $lang => $descr)
+ if (!@pspell_new($lang))
+ $out['dependencies'][] = array('prop' => 'spellcheck_languages',
+ 'explain' => "You are missing pspell support for language $lang ($descr)");
+ }
+ }
+
+ if ($this->config['log_driver'] == 'syslog') {
+ if (!function_exists('openlog')) {
+ $out['dependencies'][] = array('prop' => 'log_driver',
+ 'explain' => 'This requires the <tt>syslog</tt> extension which could not be loaded.');
+ }
+ if (empty($this->config['syslog_id'])) {
+ $out['dependencies'][] = array('prop' => 'syslog_id',
+ 'explain' => 'Using <tt>syslog</tt> for logging requires a syslog ID to be configured');
+ }
+ }
+
+ // check ldap_public sources having global_search enabled
+ if (is_array($this->config['ldap_public']) && !is_array($this->config['autocomplete_addressbooks'])) {
+ foreach ($this->config['ldap_public'] as $ldap_public) {
+ if ($ldap_public['global_search']) {
+ $out['replaced'][] = array('prop' => 'ldap_public::global_search', 'replacement' => 'autocomplete_addressbooks');
+ break;
+ }
+ }
+ }
+
+ return $out;
+ }
+
+
+ /**
+ * Merge the current configuration with the defaults
+ * and copy replaced values to the new options.
+ */
+ function merge_config()
+ {
+ $current = $this->config;
+ $this->config = array();
+
+ foreach ($this->replaced_config as $prop => $replacement) {
+ if (isset($current[$prop])) {
+ if ($prop == 'skin_path')
+ $this->config[$replacement] = preg_replace('#skins/(\w+)/?$#', '\\1', $current[$prop]);
+ else if ($prop == 'multiple_identities')
+ $this->config[$replacement] = $current[$prop] ? 2 : 0;
+ else
+ $this->config[$replacement] = $current[$prop];
+ }
+ unset($current[$prop]);
+ }
+
+ foreach ($this->obsolete_config as $prop) {
+ unset($current[$prop]);
+ }
+
+ // add all ldap_public sources having global_search enabled to autocomplete_addressbooks
+ if (is_array($current['ldap_public'])) {
+ foreach ($current['ldap_public'] as $key => $ldap_public) {
+ if ($ldap_public['global_search']) {
+ $this->config['autocomplete_addressbooks'][] = $key;
+ unset($current['ldap_public'][$key]['global_search']);
+ }
+ }
+ }
+
+ $this->config = array_merge($this->config, $current);
+
+ foreach (array_keys((array)$current['ldap_public']) as $key) {
+ $this->config['ldap_public'][$key] = $current['ldap_public'][$key];
+ }
+ }
+
+ /**
+ * Compare the local database schema with the reference schema
+ * required for this version of Roundcube
+ *
+ * @param rcube_db Database object
+ *
+ * @return boolean True if the schema is up-to-date, false if not or an error occurred
+ */
+ function db_schema_check($DB)
+ {
+ if (!$this->configured)
+ return false;
+
+ // read reference schema from mysql.initial.sql
+ $db_schema = $this->db_read_schema(INSTALL_PATH . 'SQL/mysql.initial.sql');
+ $errors = array();
+
+ // check list of tables
+ $existing_tables = $DB->list_tables();
+
+ foreach ($db_schema as $table => $cols) {
+ $table = $this->config['db_prefix'] . $table;
+ if (!in_array($table, $existing_tables)) {
+ $errors[] = "Missing table '".$table."'";
+ }
+ else { // compare cols
+ $db_cols = $DB->list_cols($table);
+ $diff = array_diff(array_keys($cols), $db_cols);
+ if (!empty($diff))
+ $errors[] = "Missing columns in table '$table': " . join(',', $diff);
+ }
+ }
+
+ return !empty($errors) ? $errors : false;
+ }
+
+ /**
+ * Utility function to read database schema from an .sql file
+ */
+ private function db_read_schema($schemafile)
+ {
+ $lines = file($schemafile);
+ $table_block = false;
+ $schema = array();
+ foreach ($lines as $line) {
+ if (preg_match('/^\s*create table `?([a-z0-9_]+)`?/i', $line, $m)) {
+ $table_block = $m[1];
+ }
+ else if ($table_block && preg_match('/^\s*`?([a-z0-9_-]+)`?\s+([a-z]+)/', $line, $m)) {
+ $col = $m[1];
+ if (!in_array(strtoupper($col), array('PRIMARY','KEY','INDEX','UNIQUE','CONSTRAINT','REFERENCES','FOREIGN'))) {
+ $schema[$table_block][$col] = $m[2];
+ }
+ }
+ }
+
+ return $schema;
+ }
+
+ /**
+ * Try to detect some file's mimetypes to test the correct behavior of fileinfo
+ */
+ function check_mime_detection()
+ {
+ $files = array(
+ 'skins/larry/images/roundcube_logo.png' => 'image/png',
+ 'program/resources/blank.tif' => 'image/tiff',
+ 'program/resources/blocked.gif' => 'image/gif',
+ 'skins/larry/README' => 'text/plain',
+ );
+
+ $errors = array();
+ foreach ($files as $path => $expected) {
+ $mimetype = rcube_mime::file_content_type(INSTALL_PATH . $path, basename($path));
+ if ($mimetype != $expected) {
+ $errors[] = array($path, $mimetype, $expected);
+ }
+ }
+
+ return $errors;
+ }
+
+ /**
+ * Check the correct configuration of the 'mime_types' mapping option
+ */
+ function check_mime_extensions()
+ {
+ $types = array(
+ 'application/zip' => 'zip',
+ 'application/x-tar' => 'tar',
+ 'application/java-archive' => 'jar',
+ 'image/gif' => 'gif',
+ 'image/svg+xml' => 'svg',
+ );
+
+ $errors = array();
+ foreach ($types as $mimetype => $expected) {
+ $ext = rcube_mime::get_mime_extensions($mimetype);
+ if ($ext[0] != $expected) {
+ $errors[] = array($mimetype, $ext, $expected);
+ }
+ }
+
+ return $errors;
+ }
+
+ /**
+ * Getter for the last error message
+ *
+ * @return string Error message or null if none exists
+ */
+ function get_error()
+ {
+ return $this->last_error['message'];
+ }
+
+
+ /**
+ * Return a list with all imap hosts configured
+ *
+ * @return array Clean list with imap hosts
+ */
+ function get_hostlist()
+ {
+ $default_hosts = (array)$this->getprop('default_host');
+ $out = array();
+
+ foreach ($default_hosts as $key => $name) {
+ if (!empty($name))
+ $out[] = rcube_parse_host(is_numeric($key) ? $name : $key);
+ }
+
+ return $out;
+ }
+
+ /**
+ * Create a HTML dropdown to select a previous version of Roundcube
+ */
+ function versions_select($attrib = array())
+ {
+ $select = new html_select($attrib);
+ $select->add(array(
+ '0.1-stable', '0.1.1',
+ '0.2-alpha', '0.2-beta', '0.2-stable',
+ '0.3-stable', '0.3.1',
+ '0.4-beta', '0.4.2',
+ '0.5-beta', '0.5', '0.5.1', '0.5.2', '0.5.3', '0.5.4',
+ '0.6-beta', '0.6',
+ '0.7-beta', '0.7', '0.7.1', '0.7.2', '0.7.3', '0.7.4',
+ '0.8-beta', '0.8-rc', '0.8.0', '0.8.1', '0.8.2', '0.8.3', '0.8.4', '0.8.5', '0.8.6',
+ '0.9-beta', '0.9-rc', '0.9-rc2',
+ // Note: Do not add newer versions here
+ ));
+ return $select;
+ }
+
+ /**
+ * Return a list with available subfolders of the skin directory
+ */
+ function list_skins()
+ {
+ $skins = array();
+ $skindir = INSTALL_PATH . 'skins/';
+ foreach (glob($skindir . '*') as $path) {
+ if (is_dir($path) && is_readable($path)) {
+ $skins[] = substr($path, strlen($skindir));
+ }
+ }
+ return $skins;
+ }
+
+ /**
+ * Display OK status
+ *
+ * @param string Test name
+ * @param string Confirm message
+ */
+ function pass($name, $message = '')
+ {
+ echo Q($name) . ':&nbsp; <span class="success">OK</span>';
+ $this->_showhint($message);
+ }
+
+
+ /**
+ * Display an error status and increase failure count
+ *
+ * @param string Test name
+ * @param string Error message
+ * @param string URL for details
+ * @param bool Do not count this failure
+ */
+ function fail($name, $message = '', $url = '', $optional=false)
+ {
+ if (!$optional) {
+ $this->failures++;
+ }
+
+ echo Q($name) . ':&nbsp; <span class="fail">NOT OK</span>';
+ $this->_showhint($message, $url);
+ }
+
+
+ /**
+ * Display an error status for optional settings/features
+ *
+ * @param string Test name
+ * @param string Error message
+ * @param string URL for details
+ */
+ function optfail($name, $message = '', $url = '')
+ {
+ echo Q($name) . ':&nbsp; <span class="na">NOT OK</span>';
+ $this->_showhint($message, $url);
+ }
+
+
+ /**
+ * Display warning status
+ *
+ * @param string Test name
+ * @param string Warning message
+ * @param string URL for details
+ */
+ function na($name, $message = '', $url = '')
+ {
+ echo Q($name) . ':&nbsp; <span class="na">NOT AVAILABLE</span>';
+ $this->_showhint($message, $url);
+ }
+
+
+ function _showhint($message, $url = '')
+ {
+ $hint = Q($message);
+
+ if ($url)
+ $hint .= ($hint ? '; ' : '') . 'See <a href="' . Q($url) . '" target="_blank">' . Q($url) . '</a>';
+
+ if ($hint)
+ echo '<span class="indent">(' . $hint . ')</span>';
+ }
+
+
+ static function _clean_array($arr)
+ {
+ $out = array();
+
+ foreach (array_unique($arr) as $k => $val) {
+ if (!empty($val)) {
+ if (is_numeric($k))
+ $out[] = $val;
+ else
+ $out[$k] = $val;
+ }
+ }
+
+ return $out;
+ }
+
+
+ static function _dump_var($var, $name=null)
+ {
+ // special values
+ switch ($name) {
+ case 'syslog_facility':
+ $list = array(32 => 'LOG_AUTH', 80 => 'LOG_AUTHPRIV', 72 => ' LOG_CRON',
+ 24 => 'LOG_DAEMON', 0 => 'LOG_KERN', 128 => 'LOG_LOCAL0',
+ 136 => 'LOG_LOCAL1', 144 => 'LOG_LOCAL2', 152 => 'LOG_LOCAL3',
+ 160 => 'LOG_LOCAL4', 168 => 'LOG_LOCAL5', 176 => 'LOG_LOCAL6',
+ 184 => 'LOG_LOCAL7', 48 => 'LOG_LPR', 16 => 'LOG_MAIL',
+ 56 => 'LOG_NEWS', 40 => 'LOG_SYSLOG', 8 => 'LOG_USER', 64 => 'LOG_UUCP');
+ if ($val = $list[$var])
+ return $val;
+ break;
+
+ case 'mail_header_delimiter':
+ $var = str_replace(array("\r", "\n"), array('\r', '\n'), $var);
+ return '"' . $var. '"';
+ break;
+/*
+ // RCMAIL_VERSION is undefined here
+ case 'useragent':
+ if (preg_match('|^(.*)/('.preg_quote(RCMAIL_VERSION, '|').')$|i', $var, $m)) {
+ return '"' . addcslashes($var, '"') . '/" . RCMAIL_VERSION';
+ }
+ break;
+*/
+ }
+
+ if (is_array($var)) {
+ if (empty($var)) {
+ return 'array()';
+ }
+ else { // check if all keys are numeric
+ $isnum = true;
+ foreach (array_keys($var) as $key) {
+ if (!is_numeric($key)) {
+ $isnum = false;
+ break;
+ }
+ }
+
+ if ($isnum)
+ return 'array(' . join(', ', array_map(array('rcmail_install', '_dump_var'), $var)) . ')';
+ }
+ }
+
+ return var_export($var, true);
+ }
+
+
+ /**
+ * Initialize the database with the according schema
+ *
+ * @param object rcube_db Database connection
+ * @return boolen True on success, False on error
+ */
+ function init_db($DB)
+ {
+ $engine = $DB->db_provider;
+
+ // read schema file from /SQL/*
+ $fname = INSTALL_PATH . "SQL/$engine.initial.sql";
+ if ($sql = @file_get_contents($fname)) {
+ $DB->set_option('table_prefix', $this->config['db_prefix']);
+ $DB->exec_script($sql);
+ }
+ else {
+ $this->fail('DB Schema', "Cannot read the schema file: $fname");
+ return false;
+ }
+
+ if ($err = $this->get_error()) {
+ $this->fail('DB Schema', "Error creating database schema: $err");
+ return false;
+ }
+
+ return true;
+ }
+
+
+ /**
+ * Update database schema
+ *
+ * @param string Version to update from
+ *
+ * @return boolen True on success, False on error
+ */
+ function update_db($version)
+ {
+ system(INSTALL_PATH . "bin/updatedb.sh --package=roundcube"
+ . " --version=" . escapeshellarg($version)
+ . " --dir=" . INSTALL_PATH . "SQL"
+ . " 2>&1", $result);
+
+ return !$result;
+ }
+
+
+ /**
+ * Handler for Roundcube errors
+ */
+ function raise_error($p)
+ {
+ $this->last_error = $p;
+ }
+
+
+ /**
+ * Generarte a ramdom string to be used as encryption key
+ *
+ * @param int Key length
+ * @return string The generated random string
+ * @static
+ */
+ function random_key($length)
+ {
+ $alpha = 'ABCDEFGHIJKLMNOPQERSTUVXYZabcdefghijklmnopqrtsuvwxyz0123456789+*%&?!$-_=';
+ $out = '';
+
+ for ($i=0; $i < $length; $i++)
+ $out .= $alpha{rand(0, strlen($alpha)-1)};
+
+ return $out;
+ }
+
+}
+
diff --git a/program/include/rcmail_output.php b/program/include/rcmail_output.php
index 36512ad48..0f7aaf966 100644
--- a/program/include/rcmail_output.php
+++ b/program/include/rcmail_output.php
@@ -22,7 +22,7 @@
/**
* Class for output generation
*
- * @package Core
+ * @package Webmail
* @subpackage View
*/
abstract class rcmail_output extends rcube_output
diff --git a/program/include/rcmail_output_html.php b/program/include/rcmail_output_html.php
index 4df755985..43d73a6b4 100644
--- a/program/include/rcmail_output_html.php
+++ b/program/include/rcmail_output_html.php
@@ -5,7 +5,7 @@
| program/include/rcmail_output_html.php |
| |
| This file is part of the Roundcube Webmail client |
- | Copyright (C) 2006-2013, The Roundcube Dev Team |
+ | Copyright (C) 2006-2014, The Roundcube Dev Team |
| |
| Licensed under the GNU General Public License version 3 or |
| any later version with exceptions for skins & plugins. |
@@ -23,23 +23,23 @@
/**
* Class to create HTML page output using a skin template
*
- * @package Core
+ * @package Webmail
* @subpackage View
*/
class rcmail_output_html extends rcmail_output
{
public $type = 'html';
- protected $message = null;
- protected $js_env = array();
- protected $js_labels = array();
- protected $js_commands = array();
- protected $skin_paths = array();
+ protected $message;
protected $template_name;
+ protected $js_env = array();
+ protected $js_labels = array();
+ protected $js_commands = array();
+ protected $skin_paths = array();
protected $scripts_path = '';
protected $script_files = array();
- protected $css_files = array();
- protected $scripts = array();
+ protected $css_files = array();
+ protected $scripts = array();
protected $default_template = "<html>\n<head><title></title></head>\n<body></body>\n</html>";
protected $header = '';
protected $footer = '';
@@ -58,8 +58,6 @@ class rcmail_output_html extends rcmail_output
/**
* Constructor
- *
- * @todo Replace $this->config with the real rcube_config object
*/
public function __construct($task = null, $framed = false)
{
@@ -67,10 +65,10 @@ class rcmail_output_html extends rcmail_output
$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('standard_windows', (bool) $this->config->get('standard_windows'));
+ $this->set_env('locale', $_SESSION['language']);
// add cookie info
$this->set_env('cookie_domain', ini_get('session.cookie_domain'));
@@ -84,10 +82,31 @@ class rcmail_output_html extends rcmail_output
if (!empty($_REQUEST['_extwin']))
$this->set_env('extwin', 1);
- if ($this->framed || !empty($_REQUEST['_framed']))
+ if ($this->framed || $framed)
$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)
@@ -188,6 +207,14 @@ class rcmail_output_html extends rcmail_output
// read meta file and check for dependecies
$meta = @file_get_contents(RCUBE_INSTALL_PATH . $skin_path . '/meta.json');
$meta = @json_decode($meta, true);
+
+ $meta['path'] = $skin_path;
+ $skin_id = end(explode('/', $skin_path));
+ if (!$meta['name']) {
+ $meta['name'] = $skin_id;
+ }
+ $this->skins[$skin_id] = $meta;
+
if ($meta['extends']) {
$path = RCUBE_INSTALL_PATH . 'skins/';
if (is_dir($path . $meta['extends']) && is_readable($path . $meta['extends'])) {
@@ -227,8 +254,9 @@ class rcmail_output_html extends rcmail_output
public function get_skin_file($file, &$skin_path = null, $add_path = null)
{
$skin_paths = $this->skin_paths;
- if ($add_path)
+ if ($add_path) {
array_unshift($skin_paths, $add_path);
+ }
foreach ($skin_paths as $skin_path) {
$path = realpath($skin_path . $file);
@@ -262,9 +290,9 @@ class rcmail_output_html extends rcmail_output
{
$cmd = func_get_args();
if (strpos($cmd[0], 'plugin.') !== false)
- $this->js_commands[] = array('triggerEvent', $cmd[0], $cmd[1]);
+ $this->js_commands[] = array('triggerEvent', $cmd[0], $cmd[1]);
else
- $this->js_commands[] = $cmd;
+ $this->js_commands[] = $cmd;
}
/**
@@ -274,7 +302,7 @@ class rcmail_output_html extends rcmail_output
{
$args = func_get_args();
if (count($args) == 1 && is_array($args[0]))
- $args = $args[0];
+ $args = $args[0];
foreach ($args as $name) {
$this->js_labels[$name] = $this->app->gettext($name);
@@ -315,13 +343,13 @@ class rcmail_output_html extends rcmail_output
public function reset($all = false)
{
$framed = $this->framed;
- $env = $all ? null : array_intersect_key($this->env, array('extwin'=>1, 'framed'=>1));
+ $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->env = $this->js_env = $env;
+ $this->framed = $framed || $this->env['framed'];
$this->js_labels = array();
$this->js_commands = array();
$this->script_files = array();
@@ -400,20 +428,27 @@ class rcmail_output_html extends rcmail_output
array_unshift($this->js_commands, array('hide_message', $unlock));
}
- if (!empty($this->script_files))
- $this->set_env('request_token', $this->app->get_request_token());
+ if (!empty($this->script_files)) {
+ $this->set_env('request_token', $this->app->get_request_token());
+ }
+
+ $commands = $this->get_js_commands($framed);
- // write all env variables to client
- if ($commands = $this->get_js_commands()) {
- $js = $this->framed ? "if (window.parent) {\n" : '';
- $js .= $commands . ($this->framed ? ' }' : '');
- $this->add_script($js, 'head_top');
+ // if all js commands go to parent window we can ignore all
+ // script files and skip rcube_webmail initialization (#1489792)
+ if ($framed) {
+ $this->scripts = array();
+ $this->script_files = array();
}
+ // write all javascript commands
+ $this->add_script($commands, 'head_top');
+
// send clickjacking protection headers
- $iframe = $this->framed || !empty($_REQUEST['_framed']);
- if (!headers_sent() && ($xframe = $this->app->config->get('x_frame_options', 'sameorigin')))
+ $iframe = $this->framed || $this->env['framed'];
+ if (!headers_sent() && ($xframe = $this->app->config->get('x_frame_options', 'sameorigin'))) {
header('X-Frame-Options: ' . ($iframe && $xframe == 'deny' ? 'sameorigin' : $xframe));
+ }
// call super method
$this->_write($template, $this->config->get('skin_path'));
@@ -430,15 +465,15 @@ class rcmail_output_html extends rcmail_output
*/
function parse($name = 'main', $exit = true, $write = true)
{
- $plugin = false;
- $realname = $name;
+ $plugin = false;
+ $realname = $name;
$this->template_name = $realname;
$temp = explode('.', $name, 2);
if (count($temp) > 1) {
- $plugin = $temp[0];
- $name = $temp[1];
- $skin_dir = $plugin . '/skins/' . $this->config->get('skin');
+ $plugin = $temp[0];
+ $name = $temp[1];
+ $skin_dir = $plugin . '/skins/' . $this->config->get('skin');
// apply skin search escalation list to plugin directory
$plugin_skin_paths = array();
@@ -519,25 +554,12 @@ class rcmail_output_html extends rcmail_output
$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;
}
@@ -548,27 +570,47 @@ class rcmail_output_html extends rcmail_output
*
* @return string $out
*/
- protected function get_js_commands()
+ protected function get_js_commands(&$framed = null)
{
- $out = '';
if (!$this->framed && !empty($this->js_env)) {
- $out .= self::JS_OBJECT_NAME . '.set_env('.self::json_serialize($this->js_env).");\n";
+ $this->command('set_env', $this->js_env);
}
+
if (!empty($this->js_labels)) {
$this->command('add_label', $this->js_labels);
}
+
+ $out = '';
+ $parent_commands = 0;
+
foreach ($this->js_commands as $i => $args) {
$method = array_shift($args);
+ $parent = $this->framed || preg_match('/^parent\./', $method);
+
foreach ($args as $i => $arg) {
$args[$i] = self::json_serialize($arg);
}
- $parent = $this->framed || preg_match('/^parent\./', $method);
- $out .= sprintf(
- "%s.%s(%s);\n",
- ($parent ? 'if(window.parent && parent.'.self::JS_OBJECT_NAME.') parent.' : '') . self::JS_OBJECT_NAME,
- preg_replace('/^parent\./', '', $method),
- implode(',', $args)
- );
+
+ if ($parent) {
+ $parent_commands++;
+ $method = preg_replace('/^parent\./', '', $method);
+ $parent_prefix = 'if (window.parent && parent.' . self::JS_OBJECT_NAME . ') parent.';
+ $method = $parent_prefix . self::JS_OBJECT_NAME . '.' . $method;
+ }
+ else {
+ $method = self::JS_OBJECT_NAME . '.' . $method;
+ }
+
+ $out .= sprintf("%s(%s);\n", $method, implode(',', $args));
+ }
+
+ $framed = $parent_prefix && $parent_commands == count($this->js_commands);
+
+ // make the output more compact if all commands go to parent window
+ if ($framed) {
+ $out = "if (window.parent && parent." . self::JS_OBJECT_NAME . ") {\n"
+ . str_replace($parent_prefix, "\tparent.", $out)
+ . "}\n";
}
return $out;
@@ -584,13 +626,14 @@ class rcmail_output_html extends rcmail_output
public function abs_url($str, $search_path = false)
{
if ($str[0] == '/') {
- if ($search_path && ($file_url = $this->get_skin_file($str, $skin_path)))
+ if ($search_path && ($file_url = $this->get_skin_file($str, $skin_path))) {
return $file_url;
+ }
return $this->base_path . $str;
}
- else
- return $str;
+
+ return $str;
}
/**
@@ -1306,15 +1349,10 @@ class rcmail_output_html extends rcmail_output
$output = trim($templ);
if (empty($output)) {
- $output = $this->default_template;
+ $output = html::doctype('html5') . "\n" . $this->default_template;
$is_empty = true;
}
- // set default page title
- if (empty($this->pagetitle)) {
- $this->pagetitle = 'Roundcube Mail';
- }
-
// replace specialchars in content
$page_title = html::quote($this->pagetitle);
$page_header = '';
@@ -1462,7 +1500,7 @@ class rcmail_output_html extends rcmail_output
*/
public function form_tag($attrib, $content = null)
{
- if ($this->framed || !empty($_REQUEST['_framed'])) {
+ if ($this->framed || $this->env['framed']) {
$hiddenfield = new html_hiddenfield(array('name' => '_framed', 'value' => '1'));
$hidden = $hiddenfield->show();
}
@@ -1502,7 +1540,7 @@ class rcmail_output_html extends rcmail_output
// we already have a <form> tag
if ($attrib['form']) {
- if ($this->framed || !empty($_REQUEST['_framed']))
+ if ($this->framed || $this->env['framed'])
$hidden->add(array('name' => '_framed', 'value' => '1'));
return $hidden->show() . $content;
}
@@ -1629,6 +1667,12 @@ class rcmail_output_html extends rcmail_output
$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);
@@ -1691,9 +1735,9 @@ class rcmail_output_html extends rcmail_output
// 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);
}
diff --git a/program/include/rcmail_output_json.php b/program/include/rcmail_output_json.php
index d0e1eec64..fa35824db 100644
--- a/program/include/rcmail_output_json.php
+++ b/program/include/rcmail_output_json.php
@@ -23,7 +23,7 @@
/**
* View class to produce JSON responses
*
- * @package Core
+ * @package Webmail
* @subpackage View
*/
class rcmail_output_json extends rcmail_output
diff --git a/program/include/rcmail_string_replacer.php b/program/include/rcmail_string_replacer.php
index 6771375e1..d3fdc3e7f 100644
--- a/program/include/rcmail_string_replacer.php
+++ b/program/include/rcmail_string_replacer.php
@@ -23,7 +23,7 @@
* Helper class for turning URLs and email addresses in plaintext content
* into clickable links.
*
- * @package Core
+ * @package Webmail
* @subpackage Utils
*/
class rcmail_string_replacer extends rcube_string_replacer