| | |
| | | */ |
| | | |
| | | require_once('lib/utf7.inc'); |
| | | require_once('include/rcube_user.inc'); |
| | | require_once('include/rcube_shared.inc'); |
| | | require_once('include/rcmail_template.inc'); |
| | | |
| | | // fallback if not PHP modules are available |
| | | @include_once('lib/des.inc'); |
| | |
| | | function rcmail_startup($task='mail') |
| | | { |
| | | global $sess_id, $sess_user_lang; |
| | | global $CONFIG, $INSTALL_PATH, $BROWSER, $OUTPUT, $_SESSION, $IMAP, $DB, $USER; |
| | | global $CONFIG, $OUTPUT, $IMAP, $DB, $USER; |
| | | |
| | | // check client |
| | | $BROWSER = rcube_browser(); |
| | | // start output buffering, we don't need any output yet, |
| | | // it'll be cleared after reading of config files, etc. |
| | | ob_start(); |
| | | |
| | | // load configuration |
| | | $CONFIG = rcmail_load_config(); |
| | |
| | | // prepare DB connection |
| | | $dbwrapper = empty($CONFIG['db_backend']) ? 'db' : $CONFIG['db_backend']; |
| | | $dbclass = "rcube_" . $dbwrapper; |
| | | require_once("include/$dbclass.inc"); |
| | | |
| | | $DB = new $dbclass($CONFIG['db_dsnw'], $CONFIG['db_dsnr'], $CONFIG['db_persistent']); |
| | | $DB->sqlite_initials = $INSTALL_PATH.'SQL/sqlite.initial.sql'; |
| | | $DB->sqlite_initials = INSTALL_PATH.'SQL/sqlite.initial.sql'; |
| | | $DB->set_debug((bool)$CONFIG['sql_debug']); |
| | | $DB->db_connect('w'); |
| | | |
| | | // use database for storing session data |
| | | include_once('include/session.inc'); |
| | | |
| | | // clear output buffer |
| | | ob_end_clean(); |
| | | |
| | | // init session |
| | | session_start(); |
| | |
| | | // overwrite config with user preferences |
| | | $CONFIG = array_merge($CONFIG, (array)$USER->get_prefs()); |
| | | |
| | | |
| | | // reset some session parameters when changing task |
| | | if ($_SESSION['task'] != $task) |
| | | unset($_SESSION['page']); |
| | |
| | | if ($task=='mail') |
| | | rcmail_imap_init(); |
| | | |
| | | |
| | | // set localization |
| | | if ($CONFIG['locale_string']) |
| | | setlocale(LC_ALL, $CONFIG['locale_string']); |
| | | else if ($sess_user_lang) |
| | | setlocale(LC_ALL, $sess_user_lang); |
| | | |
| | | |
| | | register_shutdown_function('rcmail_shutdown'); |
| | | } |
| | |
| | | */ |
| | | function rcmail_load_config() |
| | | { |
| | | global $INSTALL_PATH; |
| | | |
| | | // load config file |
| | | include_once('config/main.inc.php'); |
| | | $conf = is_array($rcmail_config) ? $rcmail_config : array(); |
| | |
| | | $conf = array_merge($conf, $rcmail_config); |
| | | |
| | | if (empty($conf['log_dir'])) |
| | | $conf['log_dir'] = $INSTALL_PATH.'logs'; |
| | | $conf['log_dir'] = INSTALL_PATH.'logs'; |
| | | else |
| | | $conf['log_dir'] = unslashify($conf['log_dir']); |
| | | |
| | |
| | | $USER->reset(); |
| | | } |
| | | |
| | | /** |
| | | * Do server side actions on logout |
| | | */ |
| | | function rcmail_logout_actions() |
| | | { |
| | | global $CONFIG, $IMAP; |
| | | |
| | | // on logout action we're not connected to imap server |
| | | if (($CONFIG['logout_purge'] && !empty($CONFIG['trash_mbox'])) |
| | | || $CONFIG['logout_expunge']) |
| | | { |
| | | if (!rcmail_authenticate_session()) |
| | | return; |
| | | |
| | | rcmail_imap_init(true); |
| | | } |
| | | |
| | | if ($CONFIG['logout_purge'] && !empty($CONFIG['trash_mbox'])) |
| | | $IMAP->clear_mailbox($CONFIG['trash_mbox']); |
| | | |
| | | if ($CONFIG['logout_expunge']) |
| | | $IMAP->expunge('INBOX'); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Return correct name for a specific database table |
| | |
| | | function get_table_name($table) |
| | | { |
| | | global $CONFIG; |
| | | |
| | | |
| | | // return table name if configured |
| | | $config_key = 'db_table_'.$table; |
| | | |
| | | if (strlen($CONFIG[$config_key])) |
| | | return $CONFIG[$config_key]; |
| | | |
| | | |
| | | return $table; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Return correct name for a specific database sequence |
| | | * (used for Postres only) |
| | | * (used for Postgres only) |
| | | * |
| | | * @param string Secuence name |
| | | * @return string Translated sequence name |
| | |
| | | function get_sequence_name($sequence) |
| | | { |
| | | global $CONFIG; |
| | | |
| | | |
| | | // return table name if configured |
| | | $config_key = 'db_sequence_'.$sequence; |
| | | |
| | | if (strlen($CONFIG[$config_key])) |
| | | return $CONFIG[$config_key]; |
| | | |
| | | |
| | | return $sequence; |
| | | } |
| | | |
| | |
| | | */ |
| | | function rcube_language_prop($lang, $prop='lang') |
| | | { |
| | | global $INSTALL_PATH; |
| | | static $rcube_languages, $rcube_language_aliases, $rcube_charsets; |
| | | |
| | | if (empty($rcube_languages)) |
| | | @include($INSTALL_PATH.'program/localization/index.inc'); |
| | | @include(INSTALL_PATH.'program/localization/index.inc'); |
| | | |
| | | // check if we have an alias for that language |
| | | if (!isset($rcube_languages[$lang]) && isset($rcube_language_aliases[$lang])) |
| | |
| | | if (isset($rcube_charsets[$lang])) |
| | | $charset = $rcube_charsets[$lang]; |
| | | else |
| | | $charset = 'UTF-8'; |
| | | $charset = 'UTF-8'; |
| | | |
| | | |
| | | if ($prop=='charset') |
| | |
| | | * environment vars according to the current session and configuration |
| | | */ |
| | | function rcmail_load_gui() |
| | | { |
| | | { |
| | | global $CONFIG, $OUTPUT, $sess_user_lang; |
| | | |
| | | // init output page |
| | | $OUTPUT = new rcmail_template($CONFIG, $GLOBALS['_task']); |
| | | $OUTPUT = new rcube_template($CONFIG, $GLOBALS['_task']); |
| | | $OUTPUT->set_env('comm_path', $GLOBALS['COMM_PATH']); |
| | | |
| | | if (is_array($CONFIG['javascript_config'])) |
| | | { |
| | | foreach ($CONFIG['javascript_config'] as $js_config_var) |
| | | $OUTPUT->set_env($js_config_var, $CONFIG[$js_config_var]); |
| | | } |
| | | foreach (array('flag_for_deletion') as $js_config_var) |
| | | $OUTPUT->set_env($js_config_var, $CONFIG[$js_config_var]); |
| | | |
| | | if (!empty($GLOBALS['_framed'])) |
| | | $OUTPUT->set_env('framed', true); |
| | |
| | | if (!empty($CONFIG['charset'])) |
| | | $OUTPUT->set_charset($CONFIG['charset']); |
| | | |
| | | // register common UI objects |
| | | $OUTPUT->add_handlers(array( |
| | | 'loginform' => 'rcmail_login_form', |
| | | 'username' => 'rcmail_current_username', |
| | | 'message' => 'rcmail_message_container', |
| | | 'charsetselector' => 'rcmail_charset_selector', |
| | | )); |
| | | |
| | | // add some basic label to client |
| | | if (!$OUTPUT->ajax_call) |
| | | rcube_add_label('loading', 'movingmessage'); |
| | | } |
| | | $OUTPUT->add_label('loading', 'movingmessage'); |
| | | } |
| | | |
| | | /** |
| | | * Create an output object for JSON responses |
| | | */ |
| | | function rcmail_init_json() |
| | | { |
| | | global $CONFIG, $OUTPUT; |
| | | |
| | | // init output object |
| | | $OUTPUT = new rcube_json_output($CONFIG, $GLOBALS['_task']); |
| | | |
| | | // set locale setting |
| | | rcmail_set_locale($sess_user_lang); |
| | | } |
| | | |
| | | /** |
| | | * Set localization charset based on the given language. |
| | |
| | | */ |
| | | function rcube_list_languages() |
| | | { |
| | | global $CONFIG, $INSTALL_PATH; |
| | | global $CONFIG; |
| | | static $sa_languages = array(); |
| | | |
| | | if (!sizeof($sa_languages)) |
| | | { |
| | | @include($INSTALL_PATH.'program/localization/index.inc'); |
| | | @include(INSTALL_PATH.'program/localization/index.inc'); |
| | | |
| | | if ($dh = @opendir($INSTALL_PATH.'program/localization')) |
| | | if ($dh = @opendir(INSTALL_PATH.'program/localization')) |
| | | { |
| | | while (($name = readdir($dh)) !== false) |
| | | { |
| | | if ($name{0}=='.' || !is_dir($INSTALL_PATH.'program/localization/'.$name)) |
| | | if ($name{0}=='.' || !is_dir(INSTALL_PATH.'program/localization/'.$name)) |
| | | continue; |
| | | |
| | | if ($label = $rcube_languages[$name]) |
| | |
| | | |
| | | /** |
| | | * Add a localized label to the client environment |
| | | * @deprecated |
| | | */ |
| | | function rcube_add_label() |
| | | { |
| | |
| | | |
| | | $arg_list = func_get_args(); |
| | | foreach ($arg_list as $i => $name) |
| | | $OUTPUT->command('add_label', $name, rcube_label($name)); |
| | | $OUTPUT->add_label($name); |
| | | } |
| | | |
| | | |
| | |
| | | if ($OUTPUT->get_charset()!='UTF-8') |
| | | $str = rcube_charset_convert($str, RCMAIL_CHARSET, $OUTPUT->get_charset()); |
| | | |
| | | return preg_replace(array("/\r?\n/", "/\r/"), array('\n', '\n'), addslashes(strtr($str, $js_rep_table))); |
| | | return preg_replace(array("/\r?\n/", "/\r/", '/<\\//'), array('\n', '\n', '<\\/'), addslashes(strtr($str, $js_rep_table))); |
| | | } |
| | | |
| | | // no encoding given -> return original string |
| | |
| | | |
| | | |
| | | /** |
| | | * Wrapper for rcmail_template::parse() |
| | | * @deprecated |
| | | */ |
| | | function parse_template($name='main', $exit=true) |
| | | { |
| | | $GLOBALS['OUTPUT']->parse($name, $exit); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Create a HTML table based on the given data |
| | | * |
| | | * @param array Named table attributes |
| | |
| | | if ($type=='checkbox') |
| | | { |
| | | $attrib['value'] = '1'; |
| | | $input = new checkbox($attrib); |
| | | $input = new html_checkbox($attrib); |
| | | } |
| | | else if ($type=='textarea') |
| | | { |
| | | $attrib['cols'] = $attrib['size']; |
| | | $input = new textarea($attrib); |
| | | $input = new html_textarea($attrib); |
| | | } |
| | | else |
| | | $input = new textfield($attrib); |
| | | $input = new html_inputfield($attrib); |
| | | |
| | | // use value from post |
| | | if (!empty($_POST[$fname])) |
| | |
| | | |
| | | /** |
| | | * Replace all css definitions with #container [def] |
| | | * and remove css-inlined scripting |
| | | * |
| | | * @param string CSS source code |
| | | * @param string Container ID to use as prefix |
| | |
| | | { |
| | | $a_css_values = array(); |
| | | $last_pos = 0; |
| | | |
| | | // ignore the whole block if evil styles are detected |
| | | if (stristr($source, 'expression') || stristr($source, 'behavior')) |
| | | return ''; |
| | | |
| | | // cut out all contents between { and } |
| | | while (($pos = strpos($source, '{', $last_pos)) && ($pos2 = strpos($source, '}', $pos))) |
| | |
| | | $last_pos = $pos+2; |
| | | } |
| | | |
| | | // remove html commends and add #container to each tag selector. |
| | | // remove html comments and add #container to each tag selector. |
| | | // also replace body definition because we also stripped off the <body> tag |
| | | $styles = preg_replace( |
| | | array( |
| | |
| | | function parse_attrib_string($str) |
| | | { |
| | | $attrib = array(); |
| | | preg_match_all('/\s*([-_a-z]+)=(["\'])([^"]+)\2/Ui', stripslashes($str), $regs, PREG_SET_ORDER); |
| | | preg_match_all('/\s*([-_a-z]+)=(["\'])??(?(2)([^\2]+)\2|(\S+?))/Ui', stripslashes($str), $regs, PREG_SET_ORDER); |
| | | |
| | | // convert attributes to an associative array (name => value) |
| | | if ($regs) |
| | | foreach ($regs as $attr) |
| | | $attrib[strtolower($attr[1])] = $attr[3]; |
| | | { |
| | | $attrib[strtolower($attr[1])] = $attr[3] . $attr[4]; |
| | | } |
| | | |
| | | return $attrib; |
| | | } |
| | |
| | | global $CONFIG, $sess_user_lang; |
| | | |
| | | $ts = NULL; |
| | | |
| | | |
| | | if (is_numeric($date)) |
| | | $ts = $date; |
| | | else if (!empty($date)) |
| | | $ts = @strtotime($date); |
| | | |
| | | { |
| | | while (($ts = @strtotime($date))===false) |
| | | { |
| | | // if we have a date in non-rfc format |
| | | // remove token from the end and try again |
| | | $d = explode(' ', $date); |
| | | array_pop($d); |
| | | if (!$d) break; |
| | | $date = implode(' ', $d); |
| | | } |
| | | } |
| | | |
| | | if (empty($ts)) |
| | | return ''; |
| | | |
| | |
| | | $out .= rcube_label(strtolower(date('M', $timestamp))); |
| | | // month name (long) |
| | | else if ($format{$i}=='F') |
| | | $out .= rcube_label(strtolower(date('F', $timestamp))); |
| | | $out .= rcube_label('long'.strtolower(date('M', $timestamp))); |
| | | else |
| | | $out .= date($format{$i}, $timestamp); |
| | | } |
| | |
| | | * Append a line to a logfile in the logs directory. |
| | | * Date will be added automatically to the line. |
| | | * |
| | | * @param $name Name of logfile |
| | | * @param $line Line to append |
| | | * @param $name name of log file |
| | | * @param line Line to append |
| | | */ |
| | | function write_log($name, $line) |
| | | { |
| | | global $CONFIG, $INSTALL_PATH; |
| | | global $CONFIG; |
| | | |
| | | if (!is_string($line)) |
| | | $line = var_export($line, true); |
| | |
| | | $line); |
| | | |
| | | if (empty($CONFIG['log_dir'])) |
| | | $CONFIG['log_dir'] = $INSTALL_PATH.'logs'; |
| | | $CONFIG['log_dir'] = INSTALL_PATH.'logs'; |
| | | |
| | | // try to open specific log file for writing |
| | | if ($fp = @fopen($CONFIG['log_dir'].'/'.$name, 'a')) |
| | |
| | | $foldername = $fname; |
| | | } |
| | | } |
| | | |
| | | // add unread message count display |
| | | if ($unread_count = $IMAP->messagecount($folder['id'], 'RECENT', ($folder['id']==$mbox_name))) |
| | | $foldername .= sprintf(' (%d)', $unread_count); |
| | | |
| | | // make folder name safe for ids and class names |
| | | $folder_id = preg_replace('/[^A-Za-z0-9\-_]/', '', $folder['id']); |