Changeset 981 in subversion


Ignore:
Timestamp:
Feb 1, 2008 8:59:23 AM (5 years ago)
Author:
tomekp
Message:

more merge

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/devel-vnext/program/include/rcube.php

    r957 r981  
    1818 $Id: main.inc 567 2007-05-17 18:41:24Z thomasb $ 
    1919 
    20 */ 
     20 */ 
    2121 
    2222 
     
    4141    const INPUT_POST = 0x0102; 
    4242    const INPUT_GPC  = 0x0103; 
    43      
    44      
     43 
    4544    /** 
    4645     * register session and connect to server 
     
    5150     * @return void 
    5251     */ 
    53     static function startup($task = 'mail') { 
     52    public static function startup($task = 'mail') { 
    5453        $registry = rcube_registry::get_instance(); 
    5554        $registry->set('task', $task, 'core'); 
     
    6362        } 
    6463 
    65         $DB = new rcube_db($CONFIG['db_dsnw'], $CONFIG['db_dsnr'], $CONFIG['db_persistent']); 
     64        $dbclass = 'rcube_' . (empty($CONFIG['db_backend']) ? 'db' : $CONFIG['db_backend']); 
     65        require_once 'include/'.$dbclass.'.inc'; 
     66 
     67        $DB = new $dbclass($CONFIG['db_dsnw'], $CONFIG['db_dsnr'], $CONFIG['db_persistent']); 
    6668        $DB->sqlite_initials = INSTALL_PATH . 'SQL/sqlite.initial.sql'; 
    6769        $DB->db_connect('w'); 
     
    7072 
    7173        // use database for storing session data 
    72         include_once 'include/session.inc'; 
     74        require_once 'include/session.inc'; 
    7375 
    7476        // init session 
     
    8789        $registry->set('user_lang', $user_lang, 'core'); 
    8890 
     91        // create user object 
     92        $USER = new rcube_user($_SESSION['user_id']); 
     93        $registry->set('USER', $USER, 'core'); 
     94 
    8995        // overwrite config with user preferences 
    9096        if (is_array($_SESSION['user_prefs'])) { 
    91             foreach ($_SESSION['user_prefs'] as $key => $prop) 
     97            foreach ($_SESSION['user_prefs'] as $key => $prop) { 
    9298                $registry->set($key, $prop, 'config'); 
    93              
     99            } 
    94100            $CONFIG = array_merge($CONFIG, $_SESSION['user_prefs']); 
    95101        } 
     
    111117        if ($CONFIG['locale_string']) { 
    112118            setlocale(LC_ALL, $CONFIG['locale_string']); 
    113         } 
    114         else if ($user_lang) { 
     119        } else if ($user_lang) { 
    115120            setlocale(LC_ALL, $user_lang); 
    116121        } 
    117          
     122 
    118123        register_shutdown_function(array('rcube', 'shutdown')); 
    119124    } 
    120125 
    121  
    122126    /** 
    123127     * Load roundcube configuration array 
     
    125129     * @return array Named configuration parameters 
    126130     */ 
    127     static function load_config() 
    128     { 
     131    private static function load_config() { 
    129132        // load config file (throw php error if fails) 
    130         include_once INSTALL_PATH . 'config/main.inc.php'; 
     133        require_once INSTALL_PATH . 'config/main.inc.php'; 
    131134        $conf = is_array($rcmail_config) ? $rcmail_config : array(); 
    132135 
     
    137140 
    138141        // load db conf 
    139         include_once INSTALL_PATH . 'config/db.inc.php'; 
     142        require_once INSTALL_PATH.'config/db.inc.php'; 
    140143        $conf = array_merge($conf, $rcmail_config); 
    141144 
    142145        if (empty($conf['log_dir'])) { 
    143             $conf['log_dir'] = INSTALL_PATH . 'logs'; 
    144         } 
    145         else { 
     146            $conf['log_dir'] = INSTALL_PATH.'logs'; 
     147        } else { 
    146148            $conf['log_dir'] = unslashify($conf['log_dir']); 
    147149        } 
     
    153155        if ($conf['debug_level'] & 4) { 
    154156            ini_set('display_errors', 1); 
    155         } 
    156         else { 
     157        } else { 
    157158            ini_set('display_errors', 0); 
    158159        } 
    159          
     160 
    160161        // copy all config parameters to registry 
    161162        $registry = rcube_registry::get_instance(); 
    162         foreach ($conf as $key => $prop) 
     163        foreach ($conf as $key => $prop) { 
    163164            $registry->set($key, $prop, 'config'); 
    164          
     165        } 
     166 
    165167        return $conf; 
    166168    } 
    167  
    168169 
    169170    /** 
     
    171172     * This will merge the host specific configuration with the given one 
    172173     * 
    173      * @param array Global configuration parameters 
    174      */ 
    175     static function load_host_config($config) 
    176     { 
     174     * @param array global configuration parameters 
     175     * @return array global configuration parameters 
     176     */ 
     177    private static function load_host_config($config = array()) { 
    177178        $fname = null; 
    178179 
    179180        if (is_array($config['include_host_config'])) { 
    180181            $fname = $config['include_host_config'][$_SERVER['HTTP_HOST']]; 
    181         } 
    182         else if (!empty($config['include_host_config'])) { 
     182        } else if (!empty($config['include_host_config'])) { 
    183183            $fname = preg_replace('/[^a-z0-9\.\-_]/i', '', $_SERVER['HTTP_HOST']) . '.inc.php'; 
    184184        } 
    185         if ($fname && is_file(INSTALL_PATH . 'config/' . $fname)) { 
    186             include(INSTALL_PATH . 'config/' . $fname); 
     185 
     186        if ($fname && is_file(INSTALL_PATH.'config/'.$fname)) { 
     187            require_once INSTALL_PATH.'config/' . $fname; 
    187188            $config = array_merge($config, $rcmail_config); 
    188189        } 
    189          
    190190        return $config; 
    191191    } 
    192  
    193192 
    194193    /** 
     
    199198     * @return string The generated auth hash 
    200199     */ 
    201     static function auth_hash($sess_id, $ts) 
    202     { 
     200    private static function auth_hash($sess_id = null, $ts = null) { 
    203201        $registry = rcube_registry::get_instance(); 
    204202        $CONFIG   = $registry->get_all('config'); 
     
    206204        $auth_string = sprintf( 
    207205                            'rcmail*sess%sR%s*Chk:%s;%s', 
    208                             $sess_id, 
    209                             $ts, 
    210                             $CONFIG['ip_check'] ? $_SERVER['REMOTE_ADDR'] : '***.***.***.***', 
    211                             $_SERVER['HTTP_USER_AGENT'] 
     206        $sess_id, 
     207        $ts, 
     208        $CONFIG['ip_check'] ? $_SERVER['REMOTE_ADDR'] : '***.***.***.***', 
     209        $_SERVER['HTTP_USER_AGENT'] 
    212210        ); 
    213211 
     
    218216    } 
    219217 
    220  
    221218    /** 
    222219     * Check the auth hash sent by the client against the local session credentials 
     
    224221     * @return boolean True if valid, False if not 
    225222     */ 
    226     static function authenticate_session() 
    227     { 
     223    public static function authenticate_session() { 
    228224        $registry       = rcube_registry::get_instance(); 
    229225        $CONFIG         = $registry->get_all('config'); 
     
    235231            $now = time(); 
    236232            $valid = ($_COOKIE['sessauth'] == self::auth_hash(session_id(), $_SESSION['auth_time']) || 
    237                   $_COOKIE['sessauth'] == self::auth_hash(session_id(), $_SESSION['last_auth'])); 
     233            $_COOKIE['sessauth'] == self::auth_hash(session_id(), $_SESSION['last_auth'])); 
    238234 
    239235            // renew auth cookie every 5 minutes (only for GET requests) 
     
    243239                setcookie('sessauth', self::auth_hash(session_id(), $now)); 
    244240            } 
    245         } 
    246         else { 
     241        } else { 
    247242            $valid = $CONFIG['ip_check'] ? $_SERVER['REMOTE_ADDR'] == $SESS_CLIENT_IP : true; 
    248243        } 
     
    262257     * @uses   rcube_registry::get_instance() 
    263258     */ 
    264     static function imap_init($connect=FALSE) 
    265     { 
     259    public static function imap_init($connect=FALSE) { 
    266260        $registry = rcube_registry::get_instance(); 
    267261        $CONFIG   = $registry->get_all('config'); 
     
    277271        if ($connect) { 
    278272            $conn = $IMAP->connect( 
    279                 $_SESSION['imap_host'], 
    280                 $_SESSION['username'], 
    281                 self::decrypt_passwd($_SESSION['password']), 
    282                 $_SESSION['imap_port'], 
    283                 $_SESSION['imap_ssl'] 
     273            $_SESSION['imap_host'], 
     274            $_SESSION['username'], 
     275            self::decrypt_passwd($_SESSION['password']), 
     276            $_SESSION['imap_port'], 
     277            $_SESSION['imap_ssl'] 
    284278            ); 
    285279            $registry->set('IMAP', $IMAP, 'core'); 
     
    298292            $IMAP->set_pagesize($CONFIG['pagesize']); 
    299293        } 
    300          
     294 
    301295        $registry->set('IMAP', $IMAP, 'core'); 
    302296    } 
     
    306300     * This must be done AFTER connecting to the server! 
    307301     */ 
    308     static function set_imap_prop() 
    309     { 
     302    public static function set_imap_prop() { 
    310303        $registry         = rcube_registry::get_instance(); 
    311304        $IMAP             = $registry->get('IMAP', 'core'); 
     
    331324    /** 
    332325     * Do these things on script shutdown 
    333      */ 
    334     static function shutdown() 
    335     { 
     326     * @return void 
     327     */ 
     328    //TODO check if this needs to be public 
     329    public static function shutdown() { 
    336330        $registry = rcube_registry::get_instance(); 
    337331        $IMAP     = $registry->get('IMAP', 'core'); 
     332        $CONTACTS = $registry->get('CONTACTS', 'core'); 
    338333 
    339334        if (is_object($IMAP)) { 
     
    342337        } 
    343338 
     339        if (is_object($CONTACTS)) { 
     340            $CONTACTS->close(); 
     341        } 
    344342        // before closing the database connection, write session data 
    345343        session_write_close(); 
     
    349347     * Destroy session data and remove cookie 
    350348     */ 
    351     static function kill_session() 
    352     { 
    353         // save user preferences 
    354         $a_user_prefs = $_SESSION['user_prefs']; 
    355         if (!is_array($a_user_prefs)) { 
    356             $a_user_prefs = array(); 
    357         } 
     349    public static function kill_session() { 
     350        $registry = rcube_registry::get_instance(); 
     351        $USER = $registry->get('USRE', 'core'); 
    358352        if ( 
    359             ( 
    360                 isset($_SESSION['sort_col']) 
    361                 && $_SESSION['sort_col'] != $a_user_prefs['message_sort_col'] 
    362             ) 
    363             || 
    364             ( 
    365                 isset($_SESSION['sort_order']) 
    366                 && $_SESSION['sort_order'] != $a_user_prefs['message_sort_order'] 
    367             ) 
     353        ( 
     354        isset($_SESSION['sort_col']) 
     355        && $_SESSION['sort_col'] != $a_user_prefs['message_sort_col'] 
     356        ) 
     357        || 
     358        ( 
     359        isset($_SESSION['sort_order']) 
     360        && $_SESSION['sort_order'] != $a_user_prefs['message_sort_order'] 
     361        ) 
    368362        ) { 
    369             $a_user_prefs['message_sort_col'] = $_SESSION['sort_col']; 
    370             $a_user_prefs['message_sort_order'] = $_SESSION['sort_order']; 
    371             self::save_user_prefs($a_user_prefs); 
     363            $a_user_prefs = array('message_sort_col' => $_SESSION['sort_col'], 'message_sort_order' => $_SESSION['sort_order']); 
     364            $USER->save_prefs($a_user_prefs); 
    372365        } 
    373366 
     
    378371        ); 
    379372        setcookie('sessauth', '-del-', time()-60); 
     373        $USER->reset(); 
    380374        session_destroy(); 
    381375    } 
    382  
    383376 
    384377    /** 
     
    389382     * @uses   rcube_registry::get_instance() 
    390383     */ 
    391     static function get_table_name($table) 
    392     { 
     384    public static function get_table_name($table) { 
    393385        $registry = rcube_registry::get_instance(); 
    394386        $CONFIG   = $registry->get_all('config'); 
     
    403395    } 
    404396 
    405  
    406397    /** 
    407398     * Return correct name for a specific database sequence 
     
    411402     * @return string Translated sequence name 
    412403     */ 
    413     static function get_sequence_name($sequence) 
    414     { 
     404    public static function get_sequence_name($sequence) { 
    415405        $registry = rcube_registry::get_instance(); 
    416406 
     
    418408            return $seq; 
    419409        } 
    420          
     410 
    421411        // return table name if not configured 
    422412        return $table; 
     
    429419     * environment vars according to the current session and configuration 
    430420     */ 
    431     static function load_gui() 
    432     { 
     421    public static function load_gui() { 
    433422        $registry  = rcube_registry::get_instance(); 
    434423        $config    = $registry->get_all('config'); 
     
    449438        // add some basic label to client 
    450439        $OUTPUT->add_label('loading', 'movingmessage'); 
    451          
     440 
    452441        $registry->set('OUTPUT', $OUTPUT, 'core'); 
    453          
     442 
    454443        // set locale setting 
    455444        self::set_locale($registry->get('user_lang', 'core')); 
    456445    } 
    457      
    458      
     446 
     447 
    459448    /** 
    460449     * Create an output object for JSON responses 
    461450     * and register it to the global registry 
    462451     */ 
    463     static function init_json() 
    464     { 
     452    public static function init_json() { 
    465453        $registry  = rcube_registry::get_instance(); 
    466          
     454 
    467455        $OUTPUT = new rcube_json_output(); 
    468456        $registry->set('OUTPUT', $OUTPUT, 'core'); 
    469          
     457 
    470458        // set locale setting 
    471459        self::set_locale($registry->get('user_lang', 'core')); 
     
    473461 
    474462 
    475     // set localization charset based on the given language 
    476     static function set_locale($lang) 
    477     { 
     463    /** 
     464     * Set localization charset based on the given language. 
     465     * This also creates a global property for mbstring usage. 
     466     */ 
     467    //TODO the variable $lang is not used 
     468    public static function set_locale($lang) { 
    478469        $registry        = rcube_registry::get_instance(); 
    479470        $charset         = $registry->get('charset', 'config', RCMAIL_CHARSET); 
     
    481472        $MBSTRING        = $registry->get('MBSTRING', 'core'); 
    482473        $mbstring_loaded = $registry->get('mbstring_loaded', 'core'); 
    483          
     474 
    484475        // settings for mbstring module (by Tadashi Jokagi) 
    485476        if (is_null($mbstring_loaded)) { 
    486             $MBSTRING = $mbstring_loaded = extension_loaded("mbstring"); 
    487         } 
    488         else { 
     477            $MBSTRING = $mbstring_loaded = extension_loaded('mbstring'); 
     478        } else { 
    489479            $MBSTRING = $mbstring_loaded = FALSE; 
    490480        } 
     
    493483            mb_internal_encoding($charset); 
    494484        } 
    495          
     485 
    496486        $registry->set('MBSTRING', $MBSTRING, 'core'); 
    497487        $registry->set('mbstring_loaded', $mbstring_loaded, 'core'); 
    498488        $registry->set('OUTPUT_CHARSET', $charset, 'core'); 
    499  
    500489        $OUTPUT->set_charset($charset); 
    501490    } 
     
    508497     * @todo   Remove reference to $_POST superglobal. 
    509498     */ 
    510     static function autoselect_host() 
    511     { 
     499    public static function autoselect_host() { 
    512500        $registry = rcube_registry::get_instance(); 
    513501        $default_host = $registry->get('default_host', 'config'); 
     
    516504        if (isset($_POST['_host']) && empty($_POST['_host']) === false) { 
    517505            $host .= rcube::get_input_value('_host', rcube::INPUT_POST); 
    518         } 
    519         else { 
     506        } else { 
    520507            $host .= $default_host; 
    521508        } 
     
    550537     * @return boolean True on success, False on failure 
    551538     */ 
    552     static function login($user, $pass, $host=null) 
    553     { 
     539    public static function login($user = null, $pass = null, $host = null) { 
    554540        $user_id = null; 
    555541 
     
    558544        $IMAP      = $registry->get('IMAP', 'core'); 
    559545        $DB        = $registry->get('DB', 'core'); 
     546        $USER        = $registry->get('USER', 'core'); 
    560547        $user_lang = $registry->get('user_lang', 'core'); 
    561548 
     
    578565                return false; 
    579566            } 
    580         } 
    581         else if (!empty($CONFIG['default_host']) && $host != $CONFIG['default_host']) { 
     567        } else if (!empty($CONFIG['default_host']) && $host != $CONFIG['default_host']) { 
    582568            return false; 
    583569        } 
     
    589575            $imap_ssl = (isset($a_host['scheme']) && in_array($a_host['scheme'], array('ssl','imaps','tls'))) ? true : false; 
    590576            $imap_port = isset($a_host['port']) ? $a_host['port'] : ($imap_ssl ? 993 : $CONFIG['default_port']); 
    591         } 
    592         else { 
     577        } else { 
    593578            $imap_port = $CONFIG['default_port']; 
    594579        } 
     
    613598        // try to resolve email address from virtuser table 
    614599        if (!empty($CONFIG['virtuser_file']) && strstr($user, '@')) { 
    615             $user = rcube::email2user($user); 
    616         } 
    617  
     600            $user = rcube_user::email2user($user); 
     601        } 
     602        // lowercase username if it's an e-mail address (#1484473) 
     603        if (strpos($user, '@')) { 
     604            $user = strtolower($user); 
     605        } 
    618606        // query if user already registered 
    619         $_query = "SELECT user_id, username, language, preferences"; 
    620         $_query.= " FROM " . self::get_table_name('users'); 
    621         $_query.= " WHERE mail_host=?"; 
    622         $_query.= " AND (username=? OR alias=?)"; 
    623  
    624         $sql_result = $DB->query( 
    625                             $_query, 
    626                             $host, 
    627                             $user, 
    628                             $user 
    629         ); 
    630         if ($DB->db_error === true) { 
    631             return FALSE; 
     607        if ($existing = rcube_user::query($user, $host)) { 
     608            $USER = $existing; 
    632609        } 
    633610        // user already registered -> overwrite username 
    634         if ($sql_arr = $DB->fetch_assoc($sql_result)) { 
    635             $user_id = $sql_arr['user_id']; 
    636             $user    = $sql_arr['username']; 
    637         } 
    638  
     611        if ($USER->ID) { 
     612            $user_id = $USER->ID; 
     613            $user = $USER->data['username']; 
     614        } 
    639615        // exit if IMAP login failed 
    640616        if (!($imap_login  = $IMAP->connect($host, $user, $pass, $imap_port, $imap_ssl))) { 
    641             return FALSE; 
     617            return false; 
    642618        } 
    643619        // user already registered 
    644         if ($user_id && !empty($sql_arr)) { 
     620        if ($USER->ID) { 
    645621            // get user prefs 
    646             if (strlen($sql_arr['preferences'])) { 
    647                 $user_prefs = unserialize($sql_arr['preferences']); 
    648                 $_SESSION['user_prefs'] = $user_prefs; 
    649                 array_merge($CONFIG, $user_prefs); 
    650             } 
    651  
    652  
     622            $_SESSION['user_prefs'] = $USER->get_prefs(); 
     623            array_merge($CONFIG, $_SESSION['user_prefs']); 
    653624            // set user specific language 
    654             if (strlen($sql_arr['language'])) { 
    655                 $user_lang = $_SESSION['user_lang'] = $sql_arr['language']; 
     625            if (!empty($USER->data['language'])) { 
     626                $sess_user_lang = $_SESSION['user_lang'] = $USER->data['language']; 
    656627            } 
    657628            // update user's record 
    658             $_query = "UPDATE " . self::get_table_name('users'); 
    659             $_query.= " SET last_login=" . $DB->now(); 
    660             $_query.= " WHERE user_id=?"; 
    661             $DB->query($_query, $user_id); 
    662         } 
    663         // create new system user 
    664         else if ($CONFIG['auto_create_user']) { 
    665             $user_id = self::create_user($user, $host); 
    666         } 
    667  
     629            $USER->touch(); 
     630        } else if ($CONFIG['auto_create_user']) { 
     631            // create new system user 
     632            if ($created = rcube_user::create($user, $host)) { 
     633                $USER = $created; 
     634                // get existing mailboxes 
     635                $a_mailboxes = $IMAP->list_mailboxes(); 
     636            } 
     637        } else { 
     638            rcube_error::raise(array( 
     639                                        'code' => 600, 
     640                                        'type' => 'php', 
     641                                        'file' => "config/main.inc.php", 
     642                                        'message' => "Acces denied for new user $user. 'auto_create_user' is disabled" 
     643                    ), 
     644                    true, 
     645                    false 
     646            ); 
     647        } 
    668648        //tfk_debug('User id: ' . $user_id); 
    669649 
    670         if (empty($user_id) === true) { 
     650        // login false if no user id 
     651        if (empty($USER->ID) === true) { 
    671652            return false; 
    672653        } 
    673         $_SESSION['user_id']    = $user_id; 
     654 
     655        $_SESSION['user_id']    = $USER->ID; 
     656        $_SESSION['username']   = $USER->data['username']; 
    674657        $_SESSION['imap_host']  = $host; 
    675658        $_SESSION['imap_port']  = $imap_port; 
    676659        $_SESSION['imap_ssl']   = $imap_ssl; 
    677         $_SESSION['username']   = $user; 
    678660        $_SESSION['user_lang']  = $user_lang; 
    679661        $_SESSION['password']   = self::encrypt_passwd($pass); 
     
    688670         * @author Till Klampaeckel <till@php.net> 
    689671         */ 
    690         if(is_array($CONFIG['smtp_server']) === true) { 
     672        if (is_array($CONFIG['smtp_server']) === true) { 
    691673            if (isset($CONFIG['smtp_server'][$host]) === true) { 
    692674                $_SESSION['smtp_server'] = $CONFIG['smtp_server'][$host]; 
    693             } 
    694             else { 
     675            } else { 
    695676                $_SESSION['smtp_server'] = 'phpMail'; 
    696677            } 
    697         } 
    698         else { 
     678        } else { 
    699679            if (empty($CONFIG['smtp_server']) === false) { 
    700680                $_SESSION['smtp_server'] = $CONFIG['smtp_server']; 
    701             } 
    702             else { 
     681            } else { 
    703682                $_SESSION['smtp_server'] = 'phpMail'; 
    704683            } 
     
    708687        self::set_imap_prop(); 
    709688        $IMAP->clear_cache('mailboxes'); 
    710         $IMAP->create_default_folders(); 
    711  
    712         return TRUE; 
    713     } 
    714  
     689 
     690        if ($CONFIG['create_default_folders']) { 
     691            $IMAP->create_default_folders(); 
     692        } 
     693        return true; 
     694    } 
    715695 
    716696    /** 
     
    721701     * @return mixed New user ID or False on failure 
    722702     */ 
     703    //TODO check this with rcube_user function 
    723704    static function create_user($user, $host) 
    724705    { 
     
    742723 
    743724        $_query = sprintf( 
    744                     $_query, 
    745                     $DB->quote(strip_newlines($user)), 
    746                     $DB->quote(strip_newlines($host)), 
    747                     $DB->quote(strip_newlines($user_email)), 
    748                     $DB->quote($_SESSION['user_lang']) 
     725        $_query, 
     726        $DB->quote(strip_newlines($user)), 
     727        $DB->quote(strip_newlines($host)), 
     728        $DB->quote(strip_newlines($user_email)), 
     729        $DB->quote($_SESSION['user_lang']) 
    749730        ); 
    750731        rcube::tfk_debug($_query); 
     
    763744            // try to resolve the e-mail address from the virtuser table 
    764745            if ( 
    765                 !empty($CONFIG['virtuser_query']) 
    766                 && ($sql_result = $DB->query(preg_replace('/%u/', $user, $CONFIG['virtuser_query']))) 
    767                 && ($DB->num_rows()>0) 
     746            !empty($CONFIG['virtuser_query']) 
     747            && ($sql_result = $DB->query(preg_replace('/%u/', $user, $CONFIG['virtuser_query']))) 
     748            && ($DB->num_rows()>0) 
    768749            ) { 
    769750                while ($sql_arr = $DB->fetch_array($sql_result)) { 
     
    772753                    $_query.= " VALUES (?, 0, 1, ?, ?)"; 
    773754                    $DB->query( 
    774                             $_query, 
    775                             $user_id, 
    776                             strip_newlines($user_name), 
    777                             preg_replace('/^@/', $user . '@', $sql_arr[0]) 
     755                    $_query, 
     756                    $user_id, 
     757                    strip_newlines($user_name), 
     758                    preg_replace('/^@/', $user . '@', $sql_arr[0]) 
    778759                    ); 
    779760                } 
     
    785766                $_query.= " VALUES (?, 0, 1, ?, ?)"; 
    786767                $DB->query( 
    787                         $_query, 
    788                         $user_id, 
    789                         strip_newlines($user_name), 
    790                         strip_newlines($user_email) 
     768                $_query, 
     769                $user_id, 
     770                strip_newlines($user_name), 
     771                strip_newlines($user_email) 
    791772                ); 
    792773            } 
     
    797778        else { 
    798779            rcube_error::raise( 
    799                 array( 
     780            array( 
    800781                    'code' => 500, 
    801782                    'type' => 'php', 
     
    803784                    'file' => __FILE__, 
    804785                    'message' => "Failed to create new user" 
    805                 ), 
    806                 TRUE, 
    807                 FALSE 
    808             ); 
     786                    ), 
     787                    TRUE, 
     788                    FALSE 
     789                    ); 
    809790        } 
    810791        return $user_id; 
    811792    } 
    812  
    813793 
    814794    /** 
     
    829809    } 
    830810 
    831  
    832811    /** 
    833812     * Find matches of the given pattern in virtuser table 
    834      *  
     813     * 
    835814     * @param string Regular expression to search for 
    836815     * @return array Matching entries 
     
    856835    } 
    857836 
    858  
    859837    /** 
    860838     * Resolve username using a virtuser table 
     
    863841     * @return string Resolved IMAP username 
    864842     */ 
     843    //TODO check this with rcube_user function 
    865844    static function email2user($email) 
    866845    { 
     
    879858    } 
    880859 
    881  
    882860    /** 
    883861     * Resolve e-mail address from virtuser table 
     
    886864     * @return string Resolved e-mail address 
    887865     */ 
     866    //TODO check this with rcube_user function 
    888867    static function user2email($user) 
    889868    { 
     
    902881    } 
    903882 
    904  
    905883    /** 
    906884     * Write the given user prefs to the user's record 
     
    909887     * @return boolean True on success, False on failure 
    910888     */ 
     889    //TODO check this with rcube_user function 
    911890    static function save_user_prefs($a_user_prefs) 
    912891    { 
     
    921900        $_query.= " WHERE user_id=?"; 
    922901        $DB->query( 
    923             $_query, 
    924             serialize($a_user_prefs), 
    925             $user_lang, 
    926             $_SESSION['user_id'] 
     902        $_query, 
     903        serialize($a_user_prefs), 
     904        $user_lang, 
     905        $_SESSION['user_id'] 
    927906        ); 
    928907 
     
    930909            $_SESSION['user_prefs'] = $a_user_prefs; 
    931910            foreach ($a_user_prefs as $key => $value) 
    932                 $registry->set($key, $value, 'config'); 
     911            $registry->set($key, $value, 'config'); 
    933912            return true; 
    934913        } 
     
    936915        return false; 
    937916    } 
    938  
    939917 
    940918    /** 
     
    950928        $OUTPUT->set_env('action', $action); 
    951929    } 
    952  
    953930 
    954931    /** 
     
    980957    } 
    981958 
    982  
    983959    /** 
    984960     * Encrypt IMAP password using DES encryption 
     
    1004980        return preg_replace('/\x00/', '', $pass); 
    1005981    } 
    1006  
    1007982 
    1008983    /** 
     
    10281003    } 
    10291004 
    1030  
    10311005    /** 
    10321006     * Garbage collector function for temp files. 
     
    10451019        while (($fname = readdir($dir)) !== false) { 
    10461020            if ($fname{0} == '.') 
    1047                 continue; 
     1021            continue; 
    10481022 
    10491023            if (filemtime($tmp.'/'.$fname) < $expire) 
    1050                 @unlink($tmp.'/'.$fname); 
     1024            @unlink($tmp.'/'.$fname); 
    10511025        } 
    10521026        closedir($dir); 
     
    11251099        // allow the following attributes to be added to the <table> tag 
    11261100        $attrib_str = rcube::create_attrib_string( 
    1127                         $attrib, 
    1128                         array( 
     1101        $attrib, 
     1102        array( 
    11291103                            'style', 
    11301104                            'class', 
     
    11341108                            'border', 
    11351109                            'summary' 
    1136                         ) 
    1137         ); 
    1138         $table = '<table' . $attrib_str . ">\n"; 
    1139  
    1140         // add table title 
    1141         $table .= "<thead><tr>\n"; 
    1142  
    1143         foreach ($a_show_cols as $col) { 
    1144             $table .= '<td class="'.$col.'">' . Q(rcube::gettext($col)) . "</td>\n"; 
    1145         } 
    1146         $table .= "</tr></thead>\n<tbody>\n"; 
    1147  
    1148         $c = 0; 
    1149         if (!is_array($table_data)) { 
    1150             while ($table_data && ($sql_arr = $DB->fetch_assoc($table_data))) { 
    1151                 $zebra_class = $c%2 ? 'even' : 'odd'; 
    1152  
    1153                 $table .= sprintf( 
     1110                            ) 
     1111                            ); 
     1112                            $table = '<table' . $attrib_str . ">\n"; 
     1113 
     1114                            // add table title 
     1115                            $table .= "<thead><tr>\n"; 
     1116 
     1117                            foreach ($a_show_cols as $col) { 
     1118                                $table .= '<td class="'.$col.'">' . Q(rcube::gettext($col)) . "</td>\n"; 
     1119                            } 
     1120                            $table .= "</tr></thead>\n<tbody>\n"; 
     1121 
     1122                            $c = 0; 
     1123                            if (!is_array($table_data)) { 
     1124                                while ($table_data && ($sql_arr = $DB->fetch_assoc($table_data))) { 
     1125                                    $zebra_class = $c%2 ? 'even' : 'odd'; 
     1126 
     1127                                    $table .= sprintf( 
    11541128                            '<tr id="rcmrow%d" class="contact '.$zebra_class.'">'."\n", 
    1155                             $sql_arr[$id_col] 
    1156                 ); 
    1157  
    1158                 // format each col 
    1159                 foreach ($a_show_cols as $col) { 
    1160                     $cont = Q($sql_arr[$col]); 
    1161                     $table .= '<td class="'.$col.'">' . $cont . "</td>\n"; 
    1162                 } 
    1163  
    1164                 $table .= "</tr>\n"; 
    1165                 $c++; 
    1166             } 
    1167         } 
    1168         else { 
    1169             foreach ($table_data as $row_data) { 
    1170                 $zebra_class = $c%2 ? 'even' : 'odd'; 
    1171  
    1172                 $table .= sprintf( 
     1129                                    $sql_arr[$id_col] 
     1130                                    ); 
     1131 
     1132                                    // format each col 
     1133                                    foreach ($a_show_cols as $col) { 
     1134                                        $cont = Q($sql_arr[$col]); 
     1135                                        $table .= '<td class="'.$col.'">' . $cont . "</td>\n"; 
     1136                                    } 
     1137 
     1138                                    $table .= "</tr>\n"; 
     1139                                    $c++; 
     1140                                } 
     1141                            } 
     1142                            else { 
     1143                                foreach ($table_data as $row_data) { 
     1144                                    $zebra_class = $c%2 ? 'even' : 'odd'; 
     1145 
     1146                                    $table .= sprintf( 
    11731147                            '<tr id="rcmrow%d" class="contact '.$zebra_class.'">'."\n", 
    1174                             $row_data[$id_col] 
    1175                 ); 
    1176  
    1177                 // format each col 
    1178                 foreach ($a_show_cols as $col) { 
    1179                     $cont = $row_data[$col]; 
    1180                     if (strstr($cont, '<roundcube')) { 
    1181                         if (is_null($OUTPUT) === true) { 
    1182                             $OUTPUT = $registry->get('OUTPUT','core'); 
    1183                         } 
    1184                         // parse tags/conditions 
    1185                         $cont = $OUTPUT->just_parse($cont); 
    1186                         //var_dump($cont); exit; 
    1187                     } 
    1188                     else { 
    1189                         $cont = Q($row_data[$col]); 
    1190                     } 
    1191                     $table .= '<td class="' . $col . '">' . $cont . "</td>\n"; 
    1192                 } 
    1193  
    1194                 $table .= "</tr>\n"; 
    1195                 $c++; 
    1196             } 
    1197         } 
    1198  
    1199         // complete message table 
    1200         $table .= "</tbody></table>\n"; 
    1201  
    1202         return $table; 
     1148                                    $row_data[$id_col] 
     1149                                    ); 
     1150 
     1151                                    // format each col 
     1152                                    foreach ($a_show_cols as $col) { 
     1153                                        $cont = $row_data[$col]; 
     1154                                        if (strstr($cont, '<roundcube')) { 
     1155                                            if (is_null($OUTPUT) === true) { 
     1156                                                $OUTPUT = $registry->get('OUTPUT','core'); 
     1157                                            } 
     1158                                            // parse tags/conditions 
     1159                                            $cont = $OUTPUT->just_parse($cont); 
     1160                                            //var_dump($cont); exit; 
     1161                                        } 
     1162                                        else { 
     1163                                            $cont = Q($row_data[$col]); 
     1164                                        } 
     1165                                        $table .= '<td class="' . $col . '">' . $cont . "</td>\n"; 
     1166                                    } 
     1167 
     1168                                    $table .= "</tr>\n"; 
     1169                                    $c++; 
     1170                                } 
     1171                            } 
     1172 
     1173                            // complete message table 
     1174                            $table .= "</tbody></table>\n"; 
     1175 
     1176                            return $table; 
    12031177    } 
    12041178 
     
    12061180    /** 
    12071181     * Create an edit field for inclusion on a form 
    1208      *  
     1182     * 
    12091183     * @param string col field name 
    12101184     * @param string value field value 
     
    13031277 
    13041278        $today_limit = mktime( 
    1305                         0, 0, 0, 
    1306                         $now_date['mon'], 
    1307                         $now_date['mday'], 
    1308                         $now_date['year'] 
     1279        0, 0, 0, 
     1280        $now_date['mon'], 
     1281        $now_date['mday'], 
     1282        $now_date['year'] 
    13091283        ); 
    13101284        $week_limit  = mktime( 
    1311                         0, 0, 0, 
    1312                         $now_date['mon'], 
    1313                         $now_date['mday']-6, 
    1314                         $now_date['year'] 
     1285        0, 0, 0, 
     1286        $now_date['mon'], 
     1287        $now_date['mday']-6, 
     1288        $now_date['year'] 
    13151289        ); 
    13161290 
    13171291        // define date format depending on current time 
    13181292        if ( 
    1319             $CONFIG['prettydate'] 
    1320             && !$format 
    1321             && $timestamp > $today_limit 
    1322             && $timestamp < $now 
     1293        $CONFIG['prettydate'] 
     1294        && !$format 
     1295        && $timestamp > $today_limit 
     1296        && $timestamp < $now 
    13231297        ) { 
    13241298            return sprintf( 
    13251299                    '%s %s', 
    1326                     rcube::gettext('today'), 
    1327                     date( 
    1328                         $CONFIG['date_today'] ? $CONFIG['date_today'] : 'H:i', 
    1329                         $timestamp 
    1330                     ) 
     1300            rcube::gettext('today'), 
     1301            date( 
     1302            $CONFIG['date_today'] ? $CONFIG['date_today'] : 'H:i', 
     1303            $timestamp 
     1304            ) 
    13311305            ); 
    13321306        } 
    13331307        elseif ( 
    1334             $CONFIG['prettydate'] 
    1335             && !$format 
    1336             && $timestamp > $week_limit 
    1337             && $timestamp < $now 
     1308        $CONFIG['prettydate'] 
     1309        && !$format 
     1310        && $timestamp > $week_limit 
     1311        && $timestamp < $now 
    13381312        ) { 
    13391313            $format = $CONFIG['date_short'] ? $CONFIG['date_short'] : 'D H:i'; 
     
    13531327            if ($format{$i}==' ' || $format{$i-1}=='\\') { 
    13541328                $out .= $format{$i}; 
    1355             // weekday (short) 
     1329                // weekday (short) 
    13561330            } 
    13571331            elseif ($format{$i}=='D') { 
    13581332                $out .= rcube::gettext(strtolower(date('D', $timestamp))); 
    1359             // weekday long 
     1333                // weekday long 
    13601334            } 
    13611335            elseif ($format{$i}=='l') { 
    13621336                $out .= rcube::gettext(strtolower(date('l', $timestamp))); 
    1363             // month name (short) 
     1337                // month name (short) 
    13641338            } 
    13651339            elseif ($format{$i}=='M') { 
    13661340                $out .= rcube::gettext(strtolower(date('M', $timestamp))); 
    1367             // month name (long) 
     1341                // month name (long) 
    13681342            } 
    13691343            elseif ($format{$i}=='F') { 
     
    13941368        } 
    13951369    } 
    1396      
    1397      
    1398      
     1370 
     1371 
     1372 
    13991373    /** 
    14001374     * Check the given string and returns language properties 
     
    14531427        return $lang; 
    14541428    } 
    1455      
    1456      
     1429 
     1430 
    14571431    /** 
    14581432     * Read directory program/localization and return a list of available languages 
     
    14721446                while (($name = readdir($dh)) !== false) { 
    14731447                    if ($name{0}=='.' || !is_dir(INSTALL_PATH . 'program/localization/' . $name)) 
    1474                         continue; 
     1448                    continue; 
    14751449 
    14761450                    if ($label = $rcube_languages[$name]) 
    1477                         $localizations[$name] = $label ? $label : $name; 
     1451                    $localizations[$name] = $label ? $label : $name; 
    14781452                } 
    14791453                closedir($dh); 
     
    14831457        return $localizations; 
    14841458    } 
    1485      
    1486      
     1459 
     1460 
    14871461    /** 
    14881462     * Get localized text in the desired language 
     
    14941468    { 
    14951469        static $sa_text_data, $s_language, $utf8_decode; 
    1496          
     1470 
    14971471        $registry = rcube_registry::get_instance(); 
    14981472        $lang     = $registry->get('user_lang', 'core'); 
     
    15251499            // include user language files 
    15261500            if ( 
    1527                 !empty($lang) 
    1528                 && $lang != 'en' 
    1529                 && is_dir(INSTALL_PATH . 'program/localization/'.$lang) 
     1501            !empty($lang) 
     1502            && $lang != 'en' 
     1503            && is_dir(INSTALL_PATH . 'program/localization/'.$lang) 
    15301504            ) { 
    15311505                include_once(INSTALL_PATH . 'program/localization/' . $lang . '/labels.inc'); 
     
    15451519        if (!($text_item = $sa_text_data[$alias])) { 
    15461520            /* 
    1547             rcube_error::raise( 
    1548                 array( 
    1549                     'code' => 500, 
    1550                     'type' => 'php', 
    1551                     'line' => __LINE__, 
    1552                     'file' => __FILE__, 
    1553                     'message' => "Missing localized text for '$alias' in '$lang'" 
    1554                 ), 
    1555                 TRUE, 
    1556                 FALSE 
    1557             ); 
    1558             */ 
     1521             rcube_error::raise( 
     1522             array( 
     1523             'code' => 500, 
     1524             'type' => 'php', 
     1525             'line' => __LINE__, 
     1526             'file' => __FILE__, 
     1527             'message' => "Missing localized text for '$alias' in '$lang'" 
     1528             ), 
     1529             TRUE, 
     1530             FALSE 
     1531             ); 
     1532             */ 
    15591533            /** 
    15601534             * We got as far - so let's see if $_SESSION contains what we are 
     
    15981572        // default text is single 
    15991573        if ($text=='') 
    1600             $text = $a_text_item['single']; 
     1574        $text = $a_text_item['single']; 
    16011575 
    16021576        // replace vars in text 
     
    16231597        return $text; 
    16241598    } 
    1625      
    1626      
     1599 
     1600 
    16271601    /** 
    16281602     * Read input value and convert it for internal use 
     
    16671641        // strip slashes if magic_quotes enabled 
    16681642        if ((bool)get_magic_quotes_gpc()) 
    1669             $value = stripslashes($value); 
     1643        $value = stripslashes($value); 
    16701644 
    16711645        // remove HTML tags if not allowed 
     
    16791653        return $value; 
    16801654    } 
    1681      
    1682      
     1655 
     1656 
    16831657    /** 
    16841658     * Read a specific HTTP request header 
     
    17031677        return null; 
    17041678    } 
    1705      
    1706      
     1679 
     1680 
    17071681    /** 
    17081682     * Convert a string from one charset to another. 
     
    17381712        // convert charset using iconv module 
    17391713        if (function_exists('iconv') && $from!='UTF-7' && $to!='UTF-7') 
    1740             return iconv($from, $to, $str); 
     1714        return iconv($from, $to, $str); 
    17411715 
    17421716        $conv = new utf8(); 
     
    17831757    { 
    17841758        static $html_encode_arr, $js_rep_table, $xml_rep_table; 
    1785          
     1759 
    17861760        $out_charset = rcube_registry::get_instance()->get('OUTPUT_CHARSET', 'core'); 
    17871761 
     
    17951769                "\r\n", 
    17961770                "\n", 
    1797                 $mode=='remove' ? strip_tags($str) : $str 
     1771            $mode=='remove' ? strip_tags($str) : $str 
    17981772            ); 
    17991773        } 
    1800          
     1774 
    18011775        // encode for HTML output 
    18021776        if ($enctype == 'html') { 
     
    18111785            // don't replace quotes and html tags 
    18121786            if ( 
    1813                 ($mode == 'show' || $mode == '') 
    1814                 && $ltpos!==false 
    1815                 && strpos($str, '>', $ltpos)!==false 
     1787            ($mode == 'show' || $mode == '') 
     1788            && $ltpos!==false 
     1789            && strpos($str, '>', $ltpos)!==false 
    18161790            ) { 
    18171791                unset($encode_arr['"']); 
     
    18271801                '/&amp;([a-z]{2,5}|#[0-9]{2,4});/', 
    18281802                '&\\1;', 
    1829                 strtr($str, $encode_arr) 
     1803            strtr($str, $encode_arr) 
    18301804            ); 
    18311805            return $newlines ? nl2br($out) : $out; 
     
    18351809            return rawurlencode($str); 
    18361810        } 
    1837          
     1811 
    18381812        // if the replace tables for XML and JS are not yet defined 
    18391813        if (empty($js_rep_table)) { 
     
    18561830            return strtr($str, $xml_rep_table); 
    18571831        } 
    1858          
     1832 
    18591833        // encode for javascript use 
    18601834        if ($enctype == 'js') { 
     
    18631837            } 
    18641838            return preg_replace( 
    1865                 array("/\r?\n/", "/\r/"), 
    1866                 array('\n', '\n'), 
    1867                 addslashes(strtr($str, $js_rep_table)) 
     1839            array("/\r?\n/", "/\r/"), 
     1840            array('\n', '\n'), 
     1841            addslashes(strtr($str, $js_rep_table)) 
    18681842            ); 
    18691843        } 
    1870          
     1844 
    18711845        // no encoding given -> return original string 
    18721846        return $str; 
    18731847    } 
    1874      
    1875      
     1848 
     1849 
    18761850    /** 
    18771851     * Compose a valid attribute string for HTML tags 
     
    19001874        preg_match_all( 
    19011875            '/\s*([-_a-z]+)=(["\'])([^"]+)\2/Ui', 
    1902             stripslashes($str), 
    1903             $regs, 
    1904             PREG_SET_ORDER 
     1876        stripslashes($str), 
     1877        $regs, 
     1878        PREG_SET_ORDER 
    19051879        ); 
    19061880 
     
    19131887        return $attrib; 
    19141888    } 
    1915      
    1916      
     1889 
     1890 
    19171891    /****** debugging functions ********/ 
    19181892 
     
    19361910        } 
    19371911    } 
    1938      
     1912 
    19391913 
    19401914    /** 
     
    19821956        $log_entry = sprintf( 
    19831957            "[%s]: %s\n", 
    1984             date("d-M-Y H:i:s O", mktime()), 
    1985             $line 
     1958        date("d-M-Y H:i:s O", mktime()), 
     1959        $line 
    19861960        ); 
    19871961 
     
    20161990        rcube::console(sprintf("%s: %0.4f sec", $label, $diff)); 
    20171991    } 
    2018      
    2019      
     1992 
     1993 
    20201994} 
    20211995 
Note: See TracChangeset for help on using the changeset viewer.