Aleksander Machniak
2014-01-01 0301d9347f8c59882cdd7b6ed59686b286a77876
program/lib/Roundcube/rcube.php
@@ -105,13 +105,14 @@
     * This implements the 'singleton' design pattern
     *
     * @param integer Options to initialize with this instance. See rcube::INIT_WITH_* constants
     * @param string Environment name to run (e.g. live, dev, test)
     *
     * @return rcube The one and only instance
     */
    static function get_instance($mode = 0)
    static function get_instance($mode = 0, $env = '')
    {
        if (!self::$instance) {
            self::$instance = new rcube();
            self::$instance = new rcube($env);
            self::$instance->init($mode);
        }
@@ -122,10 +123,10 @@
    /**
     * Private constructor
     */
    protected function __construct()
    protected function __construct($env = '')
    {
        // load configuration
        $this->config  = new rcube_config;
        $this->config  = new rcube_config($env);
        $this->plugins = new rcube_dummy_plugin_api;
        register_shutdown_function(array($this, 'shutdown'));
@@ -466,6 +467,10 @@
        $this->session->set_secret($this->config->get('des_key') . dirname($_SERVER['SCRIPT_NAME']));
        $this->session->set_ip_check($this->config->get('ip_check'));
        if ($this->config->get('session_auth_name')) {
            $this->session->set_cookiename($this->config->get('session_auth_name'));
        }
        // start PHP session (if not in CLI mode)
        if ($_SERVER['REMOTE_ADDR']) {
            $this->session->start();
@@ -493,15 +498,22 @@
    public function gc_temp()
    {
        $tmp = unslashify($this->config->get('temp_dir'));
        $expire = time() - 172800;  // expire in 48 hours
        // expire in 48 hours by default
        $temp_dir_ttl = $this->config->get('temp_dir_ttl', '48h');
        $temp_dir_ttl = get_offset_sec($temp_dir_ttl);
        if ($temp_dir_ttl < 6*3600)
            $temp_dir_ttl = 6*3600;   // 6 hours sensible lower bound.
        $expire = time() - $temp_dir_ttl;
        if ($tmp && ($dir = opendir($tmp))) {
            while (($fname = readdir($dir)) !== false) {
                if ($fname{0} == '.') {
                if ($fname[0] == '.') {
                    continue;
                }
                if (filemtime($tmp.'/'.$fname) < $expire) {
                if (@filemtime($tmp.'/'.$fname) < $expire) {
                    @unlink($tmp.'/'.$fname);
                }
            }
@@ -630,10 +642,11 @@
    /**
     * Load a localization package
     *
     * @param string Language ID
     * @param array  Additional text labels/messages
     * @param string $lang  Language ID
     * @param array  $add   Additional text labels/messages
     * @param array  $merge Additional text labels/messages to merge
     */
    public function load_language($lang = null, $add = array())
    public function load_language($lang = null, $add = array(), $merge = array())
    {
        $lang = $this->language_prop(($lang ? $lang : $_SESSION['language']));
@@ -673,6 +686,11 @@
        if (is_array($add) && !empty($add)) {
            $this->texts += $add;
        }
        // merge additional texts (from plugin)
        if (is_array($merge) && !empty($merge)) {
            $this->texts = array_merge($this->texts, $merge);
        }
    }
@@ -690,7 +708,11 @@
        // user HTTP_ACCEPT_LANGUAGE if no language is specified
        if (empty($lang) || $lang == 'auto') {
            $accept_langs = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
            $lang         = str_replace('-', '_', $accept_langs[0]);
            $lang         = $accept_langs[0];
            if (preg_match('/^([a-z]+)[_-]([a-z]+)$/i', $lang, $m)) {
                $lang = $m[1] . '_' . strtoupper($m[2]);
            }
        }
        if (empty($rcube_languages)) {
@@ -1120,8 +1142,8 @@
     *      - code:    Error code (required)
     *      - type:    Error type [php|db|imap|javascript] (required)
     *      - message: Error message
     *      - file:    File where error occured
     *      - line:    Line where error occured
     *      - file:    File where error occurred
     *      - line:    Line where error occurred
     * @param boolean True to log the error
     * @param boolean Terminate script execution
     */
@@ -1130,7 +1152,6 @@
        // handle PHP exceptions
        if (is_object($arg) && is_a($arg, 'Exception')) {
            $arg = array(
                'type' => 'php',
                'code' => $arg->getCode(),
                'line' => $arg->getLine(),
                'file' => $arg->getFile(),
@@ -1138,7 +1159,7 @@
            );
        }
        else if (is_string($arg)) {
            $arg = array('message' => $arg, 'type' => 'php');
            $arg = array('message' => $arg);
        }
        if (empty($arg['code'])) {
@@ -1154,7 +1175,7 @@
        $cli = php_sapi_name() == 'cli';
        if (($log || $terminate) && !$cli && $arg['type'] && $arg['message']) {
        if (($log || $terminate) && !$cli && $arg['message']) {
            $arg['fatal'] = $terminate;
            self::log_bug($arg);
        }
@@ -1182,7 +1203,7 @@
     */
    public static function log_bug($arg_arr)
    {
        $program = strtoupper($arg_arr['type']);
        $program = strtoupper(!empty($arg_arr['type']) ? $arg_arr['type'] : 'php');
        $level   = self::get_instance()->config->get('debug_level');
        // disable errors for ajax requests, write to log instead (#1487831)
@@ -1392,6 +1413,10 @@
            'options' => $options,
        ));
        if ($plugin['abort']) {
            return isset($plugin['result']) ? $plugin['result'] : false;
        }
        $from    = $plugin['from'];
        $mailto  = $plugin['mailto'];
        $options = $plugin['options'];
@@ -1517,6 +1542,10 @@
                    !empty($response) ? join('; ', $response) : ''));
            }
        }
        else {
            // allow plugins to catch sending errors with the same parameters as in 'message_before_send'
            $this->plugins->exec_hook('message_send_error', $plugin + array('error' => $error));
        }
        if (is_resource($msg_body)) {
            fclose($msg_body);