Changeset 1344 in subversion


Ignore:
Timestamp:
Apr 30, 2008 4:21:42 AM (5 years ago)
Author:
thomasb
Message:

Next step: introduce the application class 'rcmail' and get rid of some global vars

Location:
trunk/roundcubemail
Files:
2 added
23 edited

Legend:

Unmodified
Added
Removed
  • trunk/roundcubemail/CHANGELOG

    r1341 r1344  
    11CHANGELOG RoundCube Webmail 
    22--------------------------- 
     3 
     42008/04/30 (thomasb) 
     5---------- 
     6- Introduce new application class 'rcmail' and get rid of some global vars 
    37 
    482008/04/29 (alec) 
  • trunk/roundcubemail/config/main.inc.php.dist

    r1291 r1344  
    119119 
    120120// the default locale setting 
    121 $rcmail_config['locale_string'] = 'en'; 
     121$rcmail_config['language'] = 'en'; 
    122122 
    123123// use this format for short date display 
  • trunk/roundcubemail/index.php

    r1291 r1344  
    33 +-----------------------------------------------------------------------+ 
    44 | RoundCube Webmail IMAP Client                                         | 
    5  | Version 0.1-20080328                                                  | 
     5 | Version 0.1-20080430                                                  | 
    66 |                                                                       | 
    77 | Copyright (C) 2005-2008, RoundCube Dev. - Switzerland                 | 
     
    4646// define global vars 
    4747$OUTPUT_TYPE = 'html'; 
    48 $MAIN_TASKS = array('mail','settings','addressbook','logout'); 
    49  
    50 // catch some url/post parameters 
    51 $_task = strip_quotes(get_input_value('_task', RCUBE_INPUT_GPC)); 
    52 $_action = strip_quotes(get_input_value('_action', RCUBE_INPUT_GPC)); 
    53 $_framed = (!empty($_GET['_framed']) || !empty($_POST['_framed'])); 
    54  
    55 // use main task if empty or invalid value 
    56 if (empty($_task) || !in_array($_task, $MAIN_TASKS)) 
    57   $_task = 'mail'; 
    58  
    5948 
    6049// set output buffering 
    61 if ($_action != 'get' && $_action != 'viewsource') { 
     50if ($RCMAIL->action != 'get' && $RCMAIL->action != 'viewsource') { 
    6251  // use gzip compression if supported 
    6352  if (function_exists('ob_gzhandler') 
     
    7261 
    7362 
    74 // start session with requested task 
    75 rcmail_startup($_task); 
    76  
    77 // set session related variables 
    78 $COMM_PATH = sprintf('./?_task=%s', $_task); 
    79 $SESS_HIDDEN_FIELD = ''; 
    80  
    81  
    82 // add framed parameter 
    83 if ($_framed) { 
    84   $COMM_PATH .= '&_framed=1'; 
    85   $SESS_HIDDEN_FIELD .= "\n".'<input type="hidden" name="_framed" value="1" />'; 
    86 } 
    87  
     63// init application and start session with requested task 
     64$RCMAIL = rcmail::get_instance(); 
    8865 
    8966// init output class 
    90 if (!empty($_GET['_remote']) || !empty($_POST['_remote'])) { 
    91   rcmail_init_json(); 
    92 } 
    93 else { 
    94   rcmail_load_gui(); 
    95 } 
     67$OUTPUT = (!empty($_GET['_remote']) || !empty($_POST['_remote'])) ? $RCMAIL->init_json() : $RCMAIL->load_gui((!empty($_GET['_framed']) || !empty($_POST['_framed']))); 
    9668 
    9769 
     
    10678 
    10779// error steps 
    108 if ($_action=='error' && !empty($_GET['_code'])) { 
     80if ($RCMAIL->action=='error' && !empty($_GET['_code'])) { 
    10981  raise_error(array('code' => hexdec($_GET['_code'])), FALSE, TRUE); 
    11082} 
    11183 
    11284// try to log in 
    113 if ($_action=='login' && $_task=='mail') { 
     85if ($RCMAIL->action=='login' && $RCMAIL->task=='mail') { 
    11486  $host = rcmail_autoselect_host(); 
    11587   
     
    11991  } 
    12092  else if ($_SESSION['temp'] && !empty($_POST['_user']) && isset($_POST['_pass']) && 
    121            rcmail_login(trim(get_input_value('_user', RCUBE_INPUT_POST), ' '), 
     93           $RCMAIL->login(trim(get_input_value('_user', RCUBE_INPUT_POST), ' '), 
    12294              get_input_value('_pass', RCUBE_INPUT_POST, true, 'ISO-8859-1'), $host)) { 
    12395    // create new session ID 
     
    129101 
    130102    // send redirect 
    131     header("Location: $COMM_PATH"); 
     103    header("Location: {$RCMAIL->comm_path}"); 
    132104    exit; 
    133105  } 
     
    139111 
    140112// end session 
    141 else if (($_task=='logout' || $_action=='logout') && isset($_SESSION['user_id'])) { 
     113else if (($RCMAIL->task=='logout' || $RCMAIL->action=='logout') && isset($_SESSION['user_id'])) { 
    142114  $OUTPUT->show_message('loggedout'); 
    143115  rcmail_logout_actions(); 
     
    146118 
    147119// check session and auth cookie 
    148 else if ($_action != 'login' && $_SESSION['user_id'] && $_action != 'send') { 
     120else if ($RCMAIL->action != 'login' && $_SESSION['user_id'] && $RCMAIL->action != 'send') { 
    149121  if (!rcmail_authenticate_session()) { 
    150122    $OUTPUT->show_message('sessionerror', 'error'); 
     
    155127 
    156128// log in to imap server 
    157 if (!empty($USER->ID) && $_task=='mail') { 
     129if (!empty($RCMAIL->user->ID) && $RCMAIL->task == 'mail') { 
    158130  $conn = $IMAP->connect($_SESSION['imap_host'], $_SESSION['username'], decrypt_passwd($_SESSION['password']), $_SESSION['imap_port'], $_SESSION['imap_ssl']); 
    159131  if (!$conn) { 
     
    162134  } 
    163135  else { 
    164     rcmail_set_imap_prop(); 
     136    $RCMAIL->set_imap_prop(); 
    165137  } 
    166138} 
     
    168140 
    169141// not logged in -> set task to 'login 
    170 if (empty($USER->ID)) { 
     142if (empty($RCMAIL->user->ID)) { 
    171143  if ($OUTPUT->ajax_call) 
    172144    $OUTPUT->remote_response("setTimeout(\"location.href='\"+this.env.comm_path+\"'\", 2000);"); 
    173145   
    174   $_task = 'login'; 
     146  $RCMAIL->task = 'login'; 
    175147} 
    176148 
     
    185157 
    186158 
    187 // set task and action to client 
    188 $OUTPUT->set_env('task', $_task); 
    189 if (!empty($_action)) { 
    190   $OUTPUT->set_env('action', $_action); 
    191 } 
    192  
    193  
    194  
    195159// not logged in -> show login page 
    196 if (empty($USER->ID)) { 
     160if (empty($RCMAIL->user->ID)) { 
    197161  // check if installer is still active 
    198162  if ($CONFIG['enable_installer'] && is_readable('./installer/index.php')) { 
     
    214178 
    215179// handle keep-alive signal 
    216 if ($_action=='keep-alive') { 
     180if ($RCMAIL->action=='keep-alive') { 
    217181  $OUTPUT->reset(); 
    218182  $OUTPUT->send(''); 
     
    221185 
    222186// include task specific files 
    223 if ($_task=='mail') { 
     187if ($RCMAIL->task=='mail') { 
    224188  include_once('program/steps/mail/func.inc'); 
    225189   
    226   if ($_action=='show' || $_action=='preview' || $_action=='print') 
     190  if ($RCMAIL->action=='show' || $RCMAIL->action=='preview' || $RCMAIL->action=='print') 
    227191    include('program/steps/mail/show.inc'); 
    228192 
    229   if ($_action=='get') 
     193  if ($RCMAIL->action=='get') 
    230194    include('program/steps/mail/get.inc'); 
    231195 
    232   if ($_action=='moveto' || $_action=='delete') 
     196  if ($RCMAIL->action=='moveto' || $RCMAIL->action=='delete') 
    233197    include('program/steps/mail/move_del.inc'); 
    234198 
    235   if ($_action=='mark') 
     199  if ($RCMAIL->action=='mark') 
    236200    include('program/steps/mail/mark.inc'); 
    237201 
    238   if ($_action=='viewsource') 
     202  if ($RCMAIL->action=='viewsource') 
    239203    include('program/steps/mail/viewsource.inc'); 
    240204 
    241   if ($_action=='sendmdn') 
     205  if ($RCMAIL->action=='sendmdn') 
    242206    include('program/steps/mail/sendmdn.inc'); 
    243207 
    244   if ($_action=='send') 
     208  if ($RCMAIL->action=='send') 
    245209    include('program/steps/mail/sendmail.inc'); 
    246210 
    247   if ($_action=='upload') 
     211  if ($RCMAIL->action=='upload') 
    248212    include('program/steps/mail/upload.inc'); 
    249213 
    250   if ($_action=='compose' || $_action=='remove-attachment' || $_action=='display-attachment') 
     214  if ($RCMAIL->action=='compose' || $RCMAIL->action=='remove-attachment' || $RCMAIL->action=='display-attachment') 
    251215    include('program/steps/mail/compose.inc'); 
    252216 
    253   if ($_action=='addcontact') 
     217  if ($RCMAIL->action=='addcontact') 
    254218    include('program/steps/mail/addcontact.inc'); 
    255219 
    256   if ($_action=='expunge' || $_action=='purge') 
     220  if ($RCMAIL->action=='expunge' || $RCMAIL->action=='purge') 
    257221    include('program/steps/mail/folders.inc'); 
    258222 
    259   if ($_action=='check-recent') 
     223  if ($RCMAIL->action=='check-recent') 
    260224    include('program/steps/mail/check_recent.inc'); 
    261225 
    262   if ($_action=='getunread') 
     226  if ($RCMAIL->action=='getunread') 
    263227    include('program/steps/mail/getunread.inc'); 
    264228     
    265   if ($_action=='list' && isset($_REQUEST['_remote'])) 
     229  if ($RCMAIL->action=='list' && isset($_REQUEST['_remote'])) 
    266230    include('program/steps/mail/list.inc'); 
    267231 
    268    if ($_action=='search') 
     232   if ($RCMAIL->action=='search') 
    269233     include('program/steps/mail/search.inc'); 
    270234      
    271   if ($_action=='spell') 
     235  if ($RCMAIL->action=='spell') 
    272236    include('program/steps/mail/spell.inc'); 
    273237 
    274   if ($_action=='rss') 
     238  if ($RCMAIL->action=='rss') 
    275239    include('program/steps/mail/rss.inc'); 
    276240     
     
    281245 
    282246// include task specific files 
    283 if ($_task=='addressbook') { 
     247if ($RCMAIL->task=='addressbook') { 
    284248  include_once('program/steps/addressbook/func.inc'); 
    285249 
    286   if ($_action=='save') 
     250  if ($RCMAIL->action=='save') 
    287251    include('program/steps/addressbook/save.inc'); 
    288252   
    289   if ($_action=='edit' || $_action=='add') 
     253  if ($RCMAIL->action=='edit' || $RCMAIL->action=='add') 
    290254    include('program/steps/addressbook/edit.inc'); 
    291255   
    292   if ($_action=='delete') 
     256  if ($RCMAIL->action=='delete') 
    293257    include('program/steps/addressbook/delete.inc'); 
    294258 
    295   if ($_action=='show') 
     259  if ($RCMAIL->action=='show') 
    296260    include('program/steps/addressbook/show.inc');   
    297261 
    298   if ($_action=='list' && $_REQUEST['_remote']) 
     262  if ($RCMAIL->action=='list' && $_REQUEST['_remote']) 
    299263    include('program/steps/addressbook/list.inc'); 
    300264 
    301   if ($_action=='search') 
     265  if ($RCMAIL->action=='search') 
    302266    include('program/steps/addressbook/search.inc'); 
    303267 
    304   if ($_action=='copy') 
     268  if ($RCMAIL->action=='copy') 
    305269    include('program/steps/addressbook/copy.inc'); 
    306270 
    307   if ($_action=='mailto') 
     271  if ($RCMAIL->action=='mailto') 
    308272    include('program/steps/addressbook/mailto.inc'); 
    309273} 
     
    311275 
    312276// include task specific files 
    313 if ($_task=='settings') { 
     277if ($RCMAIL->task=='settings') { 
    314278  include_once('program/steps/settings/func.inc'); 
    315279 
    316   if ($_action=='save-identity') 
     280  if ($RCMAIL->action=='save-identity') 
    317281    include('program/steps/settings/save_identity.inc'); 
    318282 
    319   if ($_action=='add-identity' || $_action=='edit-identity') 
     283  if ($RCMAIL->action=='add-identity' || $RCMAIL->action=='edit-identity') 
    320284    include('program/steps/settings/edit_identity.inc'); 
    321285 
    322   if ($_action=='delete-identity') 
     286  if ($RCMAIL->action=='delete-identity') 
    323287    include('program/steps/settings/delete_identity.inc'); 
    324288   
    325   if ($_action=='identities') 
     289  if ($RCMAIL->action=='identities') 
    326290    include('program/steps/settings/identities.inc');   
    327291 
    328   if ($_action=='save-prefs') 
     292  if ($RCMAIL->action=='save-prefs') 
    329293    include('program/steps/settings/save_prefs.inc');   
    330294 
    331   if ($_action=='folders' || $_action=='subscribe' || $_action=='unsubscribe' || 
    332       $_action=='create-folder' || $_action=='rename-folder' || $_action=='delete-folder') 
     295  if ($RCMAIL->action=='folders' || $RCMAIL->action=='subscribe' || $RCMAIL->action=='unsubscribe' || 
     296      $RCMAIL->action=='create-folder' || $RCMAIL->action=='rename-folder' || $RCMAIL->action=='delete-folder') 
    333297    include('program/steps/settings/manage_folders.inc'); 
    334298} 
     
    336300 
    337301// parse main template 
    338 $OUTPUT->send($_task); 
     302$OUTPUT->send($RCMAIL->task); 
    339303 
    340304 
  • trunk/roundcubemail/program/include/iniset.php

    r1291 r1344  
    33/* 
    44 +-----------------------------------------------------------------------+ 
    5  | program/include/iniset.inc                                            | 
     5 | program/include/iniset.php                                            | 
    66 |                                                                       | 
    77 | This file is part of the RoundCube Webmail client                     | 
  • trunk/roundcubemail/program/include/main.inc

    r1341 r1344  
    4141 
    4242/** 
    43  * Initial startup function 
    44  * to register session, create database and imap connections 
    45  * 
    46  * @param string Current task 
    47  */ 
    48 function rcmail_startup($task='mail') 
    49   { 
    50   global $sess_id, $sess_user_lang; 
    51   global $CONFIG, $OUTPUT, $IMAP, $DB, $USER; 
    52  
    53   // start output buffering, we don't need any output yet,  
    54   // it'll be cleared after reading of config files, etc. 
    55   ob_start(); 
    56  
    57   // load configuration 
    58   $CONFIG = rcmail_load_config(); 
    59  
    60   // set session domain 
    61   if (isset($CONFIG['session_domain']) && !empty($CONFIG['session_domain'])) { 
    62     ini_set('session.cookie_domain', $CONFIG['session_domain']); 
    63   } 
    64  
    65   // set session garbage collecting time according to session_lifetime 
    66   if (!empty($CONFIG['session_lifetime'])) 
    67     ini_set('session.gc_maxlifetime', ($CONFIG['session_lifetime']) * 120); 
    68  
    69   // prepare DB connection 
    70   $dbwrapper = empty($CONFIG['db_backend']) ? 'db' : $CONFIG['db_backend']; 
    71   $dbclass = "rcube_" . $dbwrapper; 
    72    
    73   $DB = new $dbclass($CONFIG['db_dsnw'], $CONFIG['db_dsnr'], $CONFIG['db_persistent']); 
    74   $DB->sqlite_initials = INSTALL_PATH.'SQL/sqlite.initial.sql'; 
    75   $DB->set_debug((bool)$CONFIG['sql_debug']); 
    76   $DB->db_connect('w'); 
    77  
    78   // use database for storing session data 
    79   include_once('include/session.inc'); 
    80  
    81   // clear output buffer 
    82   ob_end_clean(); 
    83  
    84   // init session 
    85   session_start(); 
    86   $sess_id = session_id(); 
    87  
    88   // create session and set session vars 
    89   if (!isset($_SESSION['auth_time'])) 
    90     { 
    91     $_SESSION['user_lang'] = rcube_language_prop($CONFIG['locale_string']); 
    92     $_SESSION['auth_time'] = time(); 
    93     $_SESSION['temp'] = true; 
    94     } 
    95  
    96   // set session vars global 
    97   $sess_user_lang = rcube_language_prop($_SESSION['user_lang']); 
    98  
    99   // create user object 
    100   $USER = new rcube_user($_SESSION['user_id']); 
    101  
    102   // overwrite config with user preferences 
    103   $CONFIG = array_merge($CONFIG, (array)$USER->get_prefs()); 
    104  
    105   // reset some session parameters when changing task 
    106   if ($_SESSION['task'] != $task) 
    107     unset($_SESSION['page']); 
    108  
    109   // set current task to session 
    110   $_SESSION['task'] = $task; 
    111  
    112   // create IMAP object 
    113   if ($task=='mail') 
    114     rcmail_imap_init(); 
    115  
    116   // set localization 
    117   if ($CONFIG['locale_string']) 
    118     setlocale(LC_ALL, $CONFIG['locale_string']); 
    119   else if ($sess_user_lang) 
    120     setlocale(LC_ALL, $sess_user_lang); 
    121  
    122   register_shutdown_function('rcmail_shutdown'); 
    123   } 
    124  
    125  
    126 /** 
    127  * Load roundcube configuration array 
    128  * 
    129  * @return array Named configuration parameters 
    130  */ 
    131 function rcmail_load_config() 
    132   { 
    133   // load config file 
    134   include_once('config/main.inc.php'); 
    135   $conf = is_array($rcmail_config) ? $rcmail_config : array(); 
    136  
    137   // load host-specific configuration 
    138   rcmail_load_host_config($conf); 
    139  
    140   $conf['skin_path'] = $conf['skin_path'] ? unslashify($conf['skin_path']) : 'skins/default'; 
    141  
    142   // load db conf 
    143   include_once('config/db.inc.php'); 
    144   $conf = array_merge($conf, $rcmail_config); 
    145  
    146   if (empty($conf['log_dir'])) 
    147     $conf['log_dir'] = INSTALL_PATH.'logs'; 
    148   else 
    149     $conf['log_dir'] = unslashify($conf['log_dir']); 
    150  
    151   // set PHP error logging according to config 
    152   if ($conf['debug_level'] & 1) 
    153     { 
    154     ini_set('log_errors', 1); 
    155     ini_set('error_log', $conf['log_dir'].'/errors'); 
    156     } 
    157   if ($conf['debug_level'] & 4) 
    158     ini_set('display_errors', 1); 
    159   else 
    160     ini_set('display_errors', 0); 
    161  
    162   return $conf; 
    163   } 
    164  
    165  
    166 /** 
    167  * Load a host-specific config file if configured 
    168  * This will merge the host specific configuration with the given one 
    169  * 
    170  * @param array Global configuration parameters 
    171  */ 
    172 function rcmail_load_host_config(&$config) 
    173   { 
    174   $fname = NULL; 
    175    
    176   if (is_array($config['include_host_config'])) 
    177     $fname = $config['include_host_config'][$_SERVER['HTTP_HOST']]; 
    178   else if (!empty($config['include_host_config'])) 
    179     $fname = preg_replace('/[^a-z0-9\.\-_]/i', '', $_SERVER['HTTP_HOST']) . '.inc.php'; 
    180  
    181    if ($fname && is_file('config/'.$fname)) 
    182      { 
    183      include('config/'.$fname); 
    184      $config = array_merge($config, $rcmail_config); 
    185      } 
    186   } 
    187  
    188  
    189 /** 
    19043 * Create unique authorization hash 
    19144 * 
     
    247100 
    248101 
    249 /** 
    250  * Create global IMAP object and connect to server 
    251  * 
    252  * @param boolean True if connection should be established 
    253  */ 
    254 function rcmail_imap_init($connect=FALSE) 
    255   { 
    256   global $CONFIG, $DB, $IMAP, $OUTPUT; 
    257  
    258   $IMAP = new rcube_imap($DB); 
    259   $IMAP->debug_level = $CONFIG['debug_level']; 
    260   $IMAP->skip_deleted = $CONFIG['skip_deleted']; 
    261  
    262  
    263   // connect with stored session data 
    264   if ($connect) 
    265     { 
    266     if (!($conn = $IMAP->connect($_SESSION['imap_host'], $_SESSION['username'], decrypt_passwd($_SESSION['password']), $_SESSION['imap_port'], $_SESSION['imap_ssl']))) 
    267       $OUTPUT->show_message('imaperror', 'error'); 
    268        
    269     rcmail_set_imap_prop(); 
    270     } 
    271  
    272   // enable caching of imap data 
    273   if ($CONFIG['enable_caching']===TRUE) 
    274     $IMAP->set_caching(TRUE); 
    275  
    276   // set pagesize from config 
    277   if (isset($CONFIG['pagesize'])) 
    278     $IMAP->set_pagesize($CONFIG['pagesize']); 
    279   } 
    280  
    281  
    282 /** 
    283  * Set root dir and last stored mailbox 
    284  * This must be done AFTER connecting to the server! 
    285  */ 
    286 function rcmail_set_imap_prop() 
    287   { 
    288   global $CONFIG, $IMAP; 
    289    
    290   if (!empty($CONFIG['default_charset'])) 
    291     $IMAP->set_charset($CONFIG['default_charset']); 
    292  
    293   // set root dir from config 
    294   if (!empty($CONFIG['imap_root'])) 
    295     $IMAP->set_rootdir($CONFIG['imap_root']); 
    296  
    297   if (is_array($CONFIG['default_imap_folders'])) 
    298     $IMAP->set_default_mailboxes($CONFIG['default_imap_folders']); 
    299  
    300   if (!empty($_SESSION['mbox'])) 
    301     $IMAP->set_mailbox($_SESSION['mbox']); 
    302   if (isset($_SESSION['page'])) 
    303     $IMAP->set_page($_SESSION['page']); 
    304   } 
    305  
    306  
    307 /** 
    308  * Do these things on script shutdown 
    309  */ 
    310 function rcmail_shutdown() 
    311   { 
    312   global $IMAP, $CONTACTS; 
    313    
    314   if (is_object($IMAP)) 
    315     { 
    316     $IMAP->close(); 
    317     $IMAP->write_cache(); 
    318     } 
    319      
    320   if (is_object($CONTACTS)) 
    321     $CONTACTS->close(); 
    322      
    323   // before closing the database connection, write session data 
    324   session_write_close(); 
    325   } 
    326  
    327102 
    328103/** 
     
    340115    } 
    341116 
    342   $_SESSION = array('user_lang' => $GLOBALS['sess_user_lang'], 'auth_time' => time(), 'temp' => true); 
     117  $_SESSION = array('language' => $USER->language, 'auth_time' => time(), 'temp' => true); 
    343118  setcookie('sessauth', '-del-', time()-60); 
    344119  $USER->reset(); 
    345120  } 
    346121 
     122 
    347123/** 
    348124 * Do server side actions on logout 
     
    350126function rcmail_logout_actions() 
    351127  { 
    352   global $CONFIG, $IMAP; 
     128  global $CONFIG, $IMAP, $RCMAIL; 
    353129 
    354130  // on logout action we're not connected to imap server   
     
    359135        return; 
    360136 
    361       rcmail_imap_init(true); 
     137      $RCMAIL->imap_init(true); 
    362138    } 
    363139 
     
    408184 
    409185  return $sequence; 
    410   } 
    411  
    412  
    413 /** 
    414  * Check the given string and returns language properties 
    415  * 
    416  * @param string Language code 
    417  * @param string Peropert name 
    418  * @return string Property value 
    419  */ 
    420 function rcube_language_prop($lang, $prop='lang') 
    421   { 
    422   static $rcube_languages, $rcube_language_aliases, $rcube_charsets; 
    423  
    424   if (empty($rcube_languages)) 
    425     @include(INSTALL_PATH.'program/localization/index.inc'); 
    426      
    427   // check if we have an alias for that language 
    428   if (!isset($rcube_languages[$lang]) && isset($rcube_language_aliases[$lang])) 
    429     $lang = $rcube_language_aliases[$lang]; 
    430      
    431   // try the first two chars 
    432   if (!isset($rcube_languages[$lang]) && strlen($lang)>2) 
    433     { 
    434     $lang = substr($lang, 0, 2); 
    435     $lang = rcube_language_prop($lang); 
    436     } 
    437  
    438   if (!isset($rcube_languages[$lang])) 
    439     $lang = 'en_US'; 
    440  
    441   // language has special charset configured 
    442   if (isset($rcube_charsets[$lang])) 
    443     $charset = $rcube_charsets[$lang]; 
    444   else 
    445     $charset = 'UTF-8'; 
    446  
    447  
    448   if ($prop=='charset') 
    449     return $charset; 
    450   else 
    451     return $lang; 
    452   } 
    453    
    454  
    455 /** 
    456  * Init output object for GUI and add common scripts. 
    457  * This will instantiate a rcmail_template object and set 
    458  * environment vars according to the current session and configuration 
    459  */ 
    460 function rcmail_load_gui() 
    461 { 
    462   global $CONFIG, $OUTPUT, $sess_user_lang; 
    463  
    464   // init output page 
    465   $OUTPUT = new rcube_template($CONFIG, $GLOBALS['_task']); 
    466   $OUTPUT->set_env('comm_path', $GLOBALS['COMM_PATH']); 
    467  
    468   foreach (array('flag_for_deletion') as $js_config_var) 
    469     $OUTPUT->set_env($js_config_var, $CONFIG[$js_config_var]); 
    470  
    471   if (!empty($GLOBALS['_framed'])) 
    472     $OUTPUT->set_env('framed', true); 
    473  
    474   // set locale setting 
    475   rcmail_set_locale($sess_user_lang); 
    476  
    477   // set user-selected charset 
    478   if (!empty($CONFIG['charset'])) 
    479     $OUTPUT->set_charset($CONFIG['charset']); 
    480      
    481   // add some basic label to client 
    482   $OUTPUT->add_label('loading'); 
    483 } 
    484  
    485 /** 
    486  * Create an output object for JSON responses 
    487  */ 
    488 function rcmail_init_json() 
    489 { 
    490   global $CONFIG, $OUTPUT; 
    491    
    492   // init output object 
    493   $OUTPUT = new rcube_json_output($CONFIG, $GLOBALS['_task']); 
    494  
    495   // set locale setting 
    496   rcmail_set_locale($sess_user_lang); 
    497 } 
    498  
    499 /** 
    500  * Set localization charset based on the given language. 
    501  * This also creates a global property for mbstring usage. 
    502  */ 
    503 function rcmail_set_locale($lang) 
    504   { 
    505   global $OUTPUT, $MBSTRING; 
    506   static $s_mbstring_loaded = NULL; 
    507    
    508   // settings for mbstring module (by Tadashi Jokagi) 
    509   if (is_null($s_mbstring_loaded))  
    510     $MBSTRING = $s_mbstring_loaded = extension_loaded("mbstring");  
    511   else 
    512     $MBSTRING = $s_mbstring_loaded = FALSE; 
    513    
    514   if ($MBSTRING) 
    515     mb_internal_encoding(RCMAIL_CHARSET); 
    516  
    517   $OUTPUT->set_charset(rcube_language_prop($lang, 'charset')); 
    518186  } 
    519187 
     
    552220 
    553221/** 
    554  * Perfom login to the IMAP server and to the webmail service. 
    555  * This will also create a new user entry if auto_create_user is configured. 
    556  * 
    557  * @param string IMAP user name 
    558  * @param string IMAP password 
    559  * @param string IMAP host 
    560  * @return boolean True on success, False on failure 
    561  */ 
    562 function rcmail_login($user, $pass, $host=NULL) 
    563   { 
    564   global $CONFIG, $IMAP, $DB, $USER, $sess_user_lang; 
    565   $user_id = NULL; 
    566    
    567   if (!$host) 
    568     $host = $CONFIG['default_host']; 
    569  
    570   // Validate that selected host is in the list of configured hosts 
    571   if (is_array($CONFIG['default_host'])) 
    572     { 
    573     $allowed = FALSE; 
    574     foreach ($CONFIG['default_host'] as $key => $host_allowed) 
    575       { 
    576       if (!is_numeric($key)) 
    577         $host_allowed = $key; 
    578       if ($host == $host_allowed) 
    579         { 
    580         $allowed = TRUE; 
    581         break; 
    582         } 
    583       } 
    584     if (!$allowed) 
    585       return FALSE; 
    586     } 
    587   else if (!empty($CONFIG['default_host']) && $host != $CONFIG['default_host']) 
    588     return FALSE; 
    589  
    590   // parse $host URL 
    591   $a_host = parse_url($host); 
    592   if ($a_host['host']) 
    593     { 
    594     $host = $a_host['host']; 
    595     $imap_ssl = (isset($a_host['scheme']) && in_array($a_host['scheme'], array('ssl','imaps','tls'))) ? $a_host['scheme'] : null; 
    596     $imap_port = isset($a_host['port']) ? $a_host['port'] : ($imap_ssl ? 993 : $CONFIG['default_port']); 
    597     } 
    598   else 
    599     $imap_port = $CONFIG['default_port']; 
    600  
    601  
    602   /* Modify username with domain if required   
    603      Inspired by Marco <P0L0_notspam_binware.org> 
    604   */ 
    605   // Check if we need to add domain 
    606   if (!empty($CONFIG['username_domain']) && !strpos($user, '@')) 
    607     { 
    608     if (is_array($CONFIG['username_domain']) && isset($CONFIG['username_domain'][$host])) 
    609       $user .= '@'.$CONFIG['username_domain'][$host]; 
    610     else if (is_string($CONFIG['username_domain'])) 
    611       $user .= '@'.$CONFIG['username_domain']; 
    612     } 
    613  
    614   // try to resolve email address from virtuser table     
    615   if (!empty($CONFIG['virtuser_file']) && strpos($user, '@')) 
    616     $user = rcube_user::email2user($user); 
    617  
    618   // lowercase username if it's an e-mail address (#1484473) 
    619   if (strpos($user, '@')) 
    620     $user = strtolower($user); 
    621  
    622   // query if user already registered 
    623   if ($existing = rcube_user::query($user, $host)) 
    624     $USER = $existing; 
    625  
    626   // user already registered -> overwrite username 
    627   if ($USER->ID) 
    628     { 
    629     $user_id = $USER->ID; 
    630     $user = $USER->data['username']; 
    631     } 
    632  
    633   // exit if IMAP login failed 
    634   if (!($imap_login  = $IMAP->connect($host, $user, $pass, $imap_port, $imap_ssl))) 
    635     return false; 
    636  
    637   // user already registered 
    638   if ($USER->ID) 
    639     { 
    640     // get user prefs 
    641     $CONFIG = array_merge($CONFIG, (array)$USER->get_prefs()); 
    642  
    643     // set user specific language 
    644     if (!empty($USER->data['language'])) 
    645       $sess_user_lang = $_SESSION['user_lang'] = $USER->data['language']; 
    646        
    647     // update user's record 
    648     $USER->touch(); 
    649     } 
    650   // create new system user 
    651   else if ($CONFIG['auto_create_user']) 
    652     { 
    653     if ($created = rcube_user::create($user, $host)) 
    654     { 
    655       $USER = $created; 
    656        
    657       // get existing mailboxes 
    658       $a_mailboxes = $IMAP->list_mailboxes(); 
    659     } 
    660     } 
    661   else 
    662     { 
    663     raise_error(array( 
    664       'code' => 600, 
    665       'type' => 'php', 
    666       'file' => "config/main.inc.php", 
    667       'message' => "Acces denied for new user $user. 'auto_create_user' is disabled" 
    668       ), true, false); 
    669     } 
    670  
    671   if ($USER->ID) 
    672     { 
    673     $_SESSION['user_id']   = $USER->ID; 
    674     $_SESSION['username']  = $USER->data['username']; 
    675     $_SESSION['imap_host'] = $host; 
    676     $_SESSION['imap_port'] = $imap_port; 
    677     $_SESSION['imap_ssl']  = $imap_ssl; 
    678     $_SESSION['user_lang'] = $sess_user_lang; 
    679     $_SESSION['password']  = encrypt_passwd($pass); 
    680     $_SESSION['login_time'] = mktime(); 
    681  
    682     // force reloading complete list of subscribed mailboxes 
    683     rcmail_set_imap_prop(); 
    684     $IMAP->clear_cache('mailboxes'); 
    685  
    686     if ($CONFIG['create_default_folders']) 
    687         $IMAP->create_default_folders(); 
    688  
    689     return TRUE; 
    690     } 
    691  
    692   return FALSE; 
    693   } 
    694  
    695  
    696 /** 
    697222 * Load virtuser table in array 
    698223 * 
     
    746271function rcmail_overwrite_action($action) 
    747272  { 
    748   global $OUTPUT; 
    749   $GLOBALS['_action'] = $action; 
    750   $OUTPUT->set_env('action', $action); 
     273  $app = rcmail::get_instance(); 
     274  $app->action = $action; 
     275  $app->output->set_env('action', $action); 
    751276  } 
    752277 
     
    762287function rcmail_url($action, $p=array(), $task=null) 
    763288{ 
    764   global $MAIN_TASKS, $COMM_PATH; 
     289  $app = rcmail::get_instance(); 
     290   
    765291  $qstring = ''; 
    766   $base = $COMM_PATH; 
    767    
    768   if ($task && in_array($task, $MAIN_TASKS)) 
    769     $base = ereg_replace('_task=[a-z]+', '_task='.$task, $COMM_PATH); 
     292  $base = $app->comm_path; 
     293   
     294  if ($task && in_array($task, rcmail::$main_tasks)) 
     295    $base = ereg_replace('_task=[a-z]+', '_task='.$task, $app->comm_path); 
    770296   
    771297  if (is_array($p)) 
     
    965491function rcube_charset_convert($str, $from, $to=NULL) 
    966492  { 
    967   global $MBSTRING; 
    968   static $convert_warning = false; 
     493  static $mbstring_loaded = null, $convert_warning = false; 
    969494 
    970495  $from = strtoupper($from); 
     
    990515    } 
    991516 
    992   // convert charset using mbstring module   
    993   if ($MBSTRING) 
     517  // settings for mbstring module (by Tadashi Jokagi) 
     518  if (is_null($mbstring_loaded)) { 
     519    if ($mbstring_loaded = extension_loaded("mbstring")) 
     520      mb_internal_encoding(RCMAIL_CHARSET); 
     521  } 
     522 
     523  // convert charset using mbstring module 
     524  if ($mbstring_loaded) 
    994525    { 
    995526    $aliases['UTF-7'] = 'UTF7-IMAP'; 
     
    1060591function rep_specialchars_output($str, $enctype='', $mode='', $newlines=TRUE) 
    1061592  { 
    1062   global $OUTPUT_TYPE, $OUTPUT; 
     593  global $OUTPUT; 
    1063594  static $html_encode_arr = false; 
    1064595  static $js_rep_table = false; 
     
    15141045function format_date($date, $format=NULL) 
    15151046  { 
    1516   global $CONFIG, $sess_user_lang; 
     1047  global $CONFIG; 
    15171048   
    15181049  $ts = NULL; 
     
    15251056      { 
    15261057        // if we have a date in non-rfc format 
    1527         // remove token from the end and try again 
     1058        // remove token from the end and try again 
    15281059        $d = explode(' ', $date); 
    1529         array_pop($d); 
    1530         if (!$d) break; 
    1531         $date = implode(' ', $d); 
     1060        array_pop($d); 
     1061        if (!$d) break; 
     1062        $date = implode(' ', $d); 
    15321063      } 
    15331064    } 
     
    16281159  if (!($GLOBALS['CONFIG']['debug_level'] & 4)) 
    16291160    write_log('console', $msg); 
    1630   else if ($GLOBALS['REMOTE_REQUEST']) 
     1161  else if ($GLOBALS['OUTPUT']->ajax_call) 
    16311162    print "/*\n $msg \n*/\n"; 
    16321163  else 
  • trunk/roundcubemail/program/include/rcube_imap.php

    r1341 r1344  
    466466      return $a_mailbox_cache[$mailbox][$mode]; 
    467467 
    468     // RECENT count is fetched abit different       
     468    // RECENT count is fetched a bit different 
    469469    if ($mode == 'RECENT') 
    470470       $count = iil_C_CheckForRecent($this->conn, $mailbox); 
  • trunk/roundcubemail/program/include/rcube_json_output.php

    r1305 r1344  
    4242     * Constructor 
    4343     */ 
    44     public function __construct(&$config, $task) 
     44    public function __construct($task) 
    4545    { 
    4646        $this->task   = $task; 
    47         $this->config = $config; 
     47        $this->config = rcmail::get_instance()->config; 
    4848    } 
    4949     
  • trunk/roundcubemail/program/include/rcube_shared.inc

    r1341 r1344  
    9292function rcube_label($attrib) 
    9393{ 
    94   global $sess_user_lang, $OUTPUT; 
     94  global $OUTPUT; 
    9595  static $sa_text_data = false; 
    9696  static $s_language, $utf8_decode; 
     97   
     98  $sess_user_lang = $_SESSION['language']; 
    9799 
    98100  // extract attributes 
  • trunk/roundcubemail/program/include/rcube_template.php

    r1330 r1344  
    3131class rcube_template extends rcube_html_page 
    3232{ 
     33    var $app; 
    3334    var $config; 
    3435    var $task = ''; 
     
    4647     * 
    4748     * @todo   Use jQuery's $(document).ready() here. 
    48      */ 
    49     public function __construct(&$config, $task) 
     49     * @todo   Replace $this->config with the real rcube_config object 
     50     */ 
     51    public function __construct($task, $framed = false) 
    5052    { 
    5153        parent::__construct(); 
    5254 
     55        $this->app = rcmail::get_instance(); 
     56        $this->config = $this->app->config->all(); 
     57         
     58        //$this->framed = $framed; 
    5359        $this->task = $task; 
    54         $this->config = $config; 
    5560 
    5661        // add common javascripts 
     
    349354    private function parse_with_globals($input) 
    350355    { 
    351         $GLOBALS['__comm_path'] = Q($GLOBALS['COMM_PATH']); 
     356        $GLOBALS['__comm_path'] = Q($this->app->comm_path); 
    352357        return preg_replace('/\$(__[a-z0-9_\-]+)/e', '$GLOBALS["\\1"]', $input); 
    353358    } 
     
    610615    private function button($attrib) 
    611616    { 
    612         global $CONFIG, $OUTPUT, $MAIN_TASKS; 
    613617        static $sa_buttons = array(); 
    614618        static $s_button_count = 100; 
     
    693697 
    694698            // make valid href to specific buttons 
    695             if (in_array($attrib['command'], $MAIN_TASKS)) { 
     699            if (in_array($attrib['command'], rcmail::$main_tasks)) { 
    696700                $attrib['href'] = Q(rcmail_url(null, null, $attrib['command'])); 
    697701            } 
     
    796800 
    797801    /** 
     802     * Create a form tag with the necessary hidden fields 
     803     * 
     804     * @param array Named tag parameters 
     805     * @return string HTML code for the form 
     806     */ 
     807    public function form_tag($attrib, $content = null) 
     808    { 
     809      if ($this->framed) { 
     810        $hiddenfield = new html_hiddenfield(array('name' => '_framed', 'value' => '1')); 
     811        $hidden = $hiddenfield->show(); 
     812      } 
     813       
     814      if (!$content) 
     815        $attrib['noclose'] = true; 
     816       
     817      return html::tag('form', 
     818        $attrib + array('action' => "./", 'method' => "get"), 
     819        $hidden . $content); 
     820    } 
     821 
     822 
     823    /** 
    798824     * GUI object 'username' 
    799825     * Showing IMAP username of the current session 
     
    802828     * @return string HTML code for the gui object 
    803829     */ 
    804     static function current_username($attrib) 
     830    public function current_username($attrib) 
    805831    { 
    806832        global $USER; 
     
    836862    private function login_form($attrib) 
    837863    { 
    838         global $CONFIG, $SESS_HIDDEN_FIELD; 
    839         $default_host = $CONFIG['default_host']; 
     864        $default_host = $this->config['default_host']; 
    840865 
    841866        $_SESSION['temp'] = true; 
     
    881906        } 
    882907 
    883         $out = $SESS_HIDDEN_FIELD; 
    884         $out .= $input_action->show(); 
     908        $out = $input_action->show(); 
    885909        $out .= $table->show(); 
    886910 
    887911        // surround html output with a form tag 
    888912        if (empty($attrib['form'])) { 
    889             $out = html::tag( 
    890                 'form', 
    891                 array( 
    892                     'name' => $form_name, 
    893                     'action' => "./", 
    894                     'method' => "post" 
    895                 ), 
    896             $out); 
     913            $out = $this->form_tag(array('name' => $form_name, 'method' => "post"), $out); 
    897914        } 
    898915 
     
    925942        // add form tag around text field 
    926943        if (empty($attrib['form'])) { 
    927             $out = html::tag( 
    928                 'form', 
    929                 array( 
    930                     'name' => "rcmqsearchform", 
    931                     'action' => "./", 
    932                     'onsubmit' => JS_OBJECT_NAME . ".command('search');return false;", 
    933                     'style' => "display:inline", 
    934                 ), 
    935             $out); 
     944            $out = $this->form_tag(array( 
     945                'name' => "rcmqsearchform", 
     946                'onsubmit' => JS_OBJECT_NAME . ".command('search');return false;", 
     947                'style' => "display:inline"), 
     948              $out); 
    936949        } 
    937950 
  • trunk/roundcubemail/program/include/rcube_user.php

    r1291 r1344  
    3030class rcube_user 
    3131{ 
    32   var $ID = null; 
    33   var $data = null; 
     32  public $ID = null; 
     33  public $data = null; 
     34  public $language = 'en_US'; 
     35   
     36  private $db = null; 
    3437   
    3538   
     
    4144  function __construct($id = null, $sql_arr = null) 
    4245  { 
    43     global $DB; 
     46    $this->db = rcmail::get_instance()->get_dbh(); 
    4447     
    4548    if ($id && !$sql_arr) 
    4649    { 
    47       $sql_result = $DB->query("SELECT * FROM ".get_table_name('users')." WHERE  user_id=?", $id); 
    48       $sql_arr = $DB->fetch_assoc($sql_result); 
     50      $sql_result = $this->db->query("SELECT * FROM ".get_table_name('users')." WHERE  user_id=?", $id); 
     51      $sql_arr = $this->db->fetch_assoc($sql_result); 
    4952    } 
    5053     
     
    5356      $this->ID = $sql_arr['user_id']; 
    5457      $this->data = $sql_arr; 
     58      $this->language = $sql_arr['language']; 
    5559    } 
    5660  } 
     
    8690  { 
    8791    if ($this->ID && $this->data['preferences']) 
    88       return unserialize($this->data['preferences']); 
     92      return array('language' => $this->language) + unserialize($this->data['preferences']); 
    8993    else 
    9094      return array(); 
     
    100104  function save_prefs($a_user_prefs) 
    101105  { 
    102     global $DB, $CONFIG, $sess_user_lang; 
    103      
    104106    if (!$this->ID) 
    105107      return false; 
     
    107109    // merge (partial) prefs array with existing settings 
    108110    $a_user_prefs += (array)$this->get_prefs(); 
    109  
    110     $DB->query( 
     111    unset($a_user_prefs['language']); 
     112 
     113    $this->db->query( 
    111114      "UPDATE ".get_table_name('users')." 
    112115       SET    preferences=?, 
     
    114117       WHERE  user_id=?", 
    115118      serialize($a_user_prefs), 
    116       $sess_user_lang, 
     119      $_SESSION['language'], 
    117120      $this->ID); 
    118121 
    119     if ($DB->affected_rows()) 
    120     { 
    121       $CONFIG = array_merge($CONFIG, $a_user_prefs); 
     122    $this->language = $_SESSION['language']; 
     123    if ($this->db->affected_rows()) 
     124    { 
     125      rcmail::get_instance()->config->merge($a_user_prefs); 
    122126      return true; 
    123127    } 
     
    135139  function get_identity($id = null) 
    136140  { 
    137     global $DB; 
    138      
    139141    $sql_result = $this->list_identities($id ? sprintf('AND identity_id=%d', $id) : ''); 
    140     return $DB->fetch_assoc($sql_result); 
     142    return $this->db->fetch_assoc($sql_result); 
    141143  } 
    142144   
     
    149151  function list_identities($sql_add = '') 
    150152  { 
    151     global $DB; 
    152      
    153153    // get contacts from DB 
    154     $sql_result = $DB->query( 
     154    $sql_result = $this->db->query( 
    155155      "SELECT * FROM ".get_table_name('identities')." 
    156156       WHERE  del<>1 
    157157       AND    user_id=? 
    158158       $sql_add 
    159        ORDER BY ".$DB->quoteIdentifier('standard')." DESC, name ASC", 
     159       ORDER BY ".$this->db->quoteIdentifier('standard')." DESC, name ASC", 
    160160      $this->ID); 
    161161     
     
    173173  function update_identity($iid, $data) 
    174174  { 
    175     global $DB; 
    176      
    177175    if (!$this->ID) 
    178176      return false; 
     
    183181    { 
    184182      $write_sql[] = sprintf("%s=%s", 
    185         $DB->quoteIdentifier($col), 
    186         $DB->quote($value)); 
    187     } 
    188      
    189     $DB->query( 
     183        $this->db->quoteIdentifier($col), 
     184        $this->db->quote($value)); 
     185    } 
     186     
     187    $this->db->query( 
    190188      "UPDATE ".get_table_name('identities')." 
    191189       SET ".join(', ', $write_sql)." 
     
    196194      $this->ID); 
    197195     
    198     return $DB->affected_rows(); 
     196    return $this->db->affected_rows(); 
    199197  } 
    200198   
     
    208206  function insert_identity($data) 
    209207  { 
    210     global $DB; 
    211      
    212208    if (!$this->ID) 
    213209      return false; 
     
    216212    foreach ((array)$data as $col => $value) 
    217213    { 
    218       $insert_cols[] = $DB->quoteIdentifier($col); 
    219       $insert_values[] = $DB->quote($value); 
    220     } 
    221  
    222     $DB->query( 
     214      $insert_cols[] = $this->db->quoteIdentifier($col); 
     215      $insert_values[] = $this->db->quote($value); 
     216    } 
     217 
     218    $this->db->query( 
    223219      "INSERT INTO ".get_table_name('identities')." 
    224220        (user_id, ".join(', ', $insert_cols).") 
     
    226222      $this->ID); 
    227223 
    228     return $DB->insert_id(get_sequence_name('identities')); 
     224    return $this->db->insert_id(get_sequence_name('identities')); 
    229225  } 
    230226   
     
    238234  function delete_identity($iid) 
    239235  { 
    240     global $DB; 
    241      
    242236    if (!$this->ID) 
    243237      return false; 
     
    246240      return false; 
    247241 
    248     $sql_result = $DB->query("SELECT count(*) AS ident_count FROM " . 
     242    $sql_result = $this->db->query("SELECT count(*) AS ident_count FROM " . 
    249243      get_table_name('identities') . 
    250244      " WHERE user_id = ? AND del <> 1", 
    251245      $this->ID); 
    252246 
    253     $sql_arr = $DB->fetch_assoc($sql_result); 
     247    $sql_arr = $this->db->fetch_assoc($sql_result); 
    254248    if ($sql_arr['ident_count'] <= 1) 
    255249      return false; 
    256250     
    257     $DB->query( 
     251    $this->db->query( 
    258252      "UPDATE ".get_table_name('identities')." 
    259253       SET    del=1 
     
    263257      $iid); 
    264258 
    265     return $DB->affected_rows(); 
     259    return $this->db->affected_rows(); 
    266260  } 
    267261   
     
    274268  function set_default($iid) 
    275269  { 
    276     global $DB; 
    277      
    278270    if ($this->ID && $iid) 
    279271    { 
    280       $DB->query( 
     272      $this->db->query( 
    281273        "UPDATE ".get_table_name('identities')." 
    282          SET ".$DB->quoteIdentifier('standard')."='0' 
     274         SET ".$this->db->quoteIdentifier('standard')."='0' 
    283275         WHERE  user_id=? 
    284276         AND    identity_id<>? 
     
    295287  function touch() 
    296288  { 
    297     global $DB; 
    298      
    299289    if ($this->ID) 
    300290    { 
    301       $DB->query( 
     291      $this->db->query( 
    302292        "UPDATE ".get_table_name('users')." 
    303          SET    last_login=".$DB->now()." 
     293         SET    last_login=".$this->db->now()." 
    304294         WHERE  user_id=?", 
    305295        $this->ID); 
     
    324314   * @param string IMAP host name 
    325315   * @return object rcube_user New user instance 
    326    * @static 
    327    */ 
    328   function query($user, $host) 
    329   { 
    330     global $DB; 
     316   */ 
     317  static function query($user, $host) 
     318  { 
     319    $dbh = rcmail::get_instance()->get_dbh(); 
    331320     
    332321    // query if user already registered 
    333     $sql_result = $DB->query( 
     322    $sql_result = $dbh->query( 
    334323      "SELECT * FROM ".get_table_name('users')." 
    335324       WHERE  mail_host=? AND (username=? OR alias=?)", 
     
    339328       
    340329    // user already registered -> overwrite username 
    341     if ($sql_arr = $DB->fetch_assoc($sql_result)) 
     330    if ($sql_arr = $dbh->fetch_assoc($sql_result)) 
    342331      return new rcube_user($sql_arr['user_id'], $sql_arr); 
    343332    else 
     
    352341   * @param string IMAP host 
    353342   * @return object rcube_user New user instance 
    354    * @static 
    355    */ 
    356   function create($user, $host) 
    357   { 
    358     global $DB, $CONFIG; 
    359      
     343   */ 
     344  static function create($user, $host) 
     345  { 
    360346    $user_email = ''; 
     347    $rcmail = rcmail::get_instance(); 
     348    $dbh = $rcmail->get_dbh(); 
    361349 
    362350    // try to resolve user in virtusertable 
    363     if (!empty($CONFIG['virtuser_file']) && !strpos($user, '@')) 
     351    if ($rcmail->config->get('virtuser_file') && !strpos($user, '@')) 
    364352      $user_email = rcube_user::user2email($user); 
    365353 
    366     $DB->query( 
     354    $dbh->query( 
    367355      "INSERT INTO ".get_table_name('users')." 
    368356        (created, last_login, username, mail_host, alias, language) 
    369        VALUES (".$DB->now().", ".$DB->now().", ?, ?, ?, ?)", 
     357       VALUES (".$dbh->now().", ".$dbh->now().", ?, ?, ?, ?)", 
    370358      strip_newlines($user), 
    371359      strip_newlines($host), 
    372360      strip_newlines($user_email), 
    373       $_SESSION['user_lang']); 
    374  
    375     if ($user_id = $DB->insert_id(get_sequence_name('users'))) 
     361      $_SESSION['language']); 
     362 
     363    if ($user_id = $dbh->insert_id(get_sequence_name('users'))) 
    376364    { 
    377365      $mail_domain = rcmail_mail_domain($host); 
     
    383371 
    384372      // try to resolve the e-mail address from the virtuser table 
    385       if (!empty($CONFIG['virtuser_query']) && 
    386           ($sql_result = $DB->query(preg_replace('/%u/', $DB->escapeSimple($user), $CONFIG['virtuser_query']))) && 
    387           ($DB->num_rows()>0)) 
     373      if ($virtuser_query = $rcmail->config->get('virtuser_query') && 
     374          ($sql_result = $dbh->query(preg_replace('/%u/', $dbh->escapeSimple($user), $virtuser_query))) && 
     375          ($dbh->num_rows() > 0)) 
    388376      { 
    389         while ($sql_arr = $DB->fetch_array($sql_result)) 
     377        while ($sql_arr = $dbh->fetch_array($sql_result)) 
    390378        { 
    391           $DB->query( 
     379          $dbh->query( 
    392380            "INSERT INTO ".get_table_name('identities')." 
    393381              (user_id, del, standard, name, email) 
     
    401389      { 
    402390        // also create new identity records 
    403         $DB->query( 
     391        $dbh->query( 
    404392          "INSERT INTO ".get_table_name('identities')." 
    405393            (user_id, del, standard, name, email) 
     
    429417   * @param string E-mail address to resolve 
    430418   * @return string Resolved IMAP username 
    431    * @static 
    432    */ 
    433   function email2user($email) 
     419   */ 
     420  static function email2user($email) 
    434421  { 
    435422    $user = $email; 
     
    456443   * @param string User name 
    457444   * @return string Resolved e-mail address 
    458    * @static 
    459    */ 
    460   function user2email($user) 
     445   */ 
     446  static function user2email($user) 
    461447  { 
    462448    $email = ""; 
     
    480466 
    481467 
    482 ?> 
  • trunk/roundcubemail/program/steps/addressbook/edit.inc

    r1291 r1344  
    3434function rcmail_contact_editform($attrib) 
    3535{ 
    36   global $CONTACTS, $OUTPUT; 
     36  global $RCMAIL, $CONTACTS, $OUTPUT; 
    3737 
    3838  // check if we have a valid result 
    39   if ($GLOBALS['_action'] != 'add' && !(($result = $CONTACTS->get_result()) && ($record = $result->first()))) 
     39  if ($RCMAIL->action != 'add' && !(($result = $CONTACTS->get_result()) && ($record = $result->first()))) 
    4040  { 
    4141    $OUTPUT->show_message('contactnotfound'); 
     
    8484function get_form_tags($attrib) 
    8585  { 
    86   global $CONTACTS, $OUTPUT, $EDIT_FORM, $SESS_HIDDEN_FIELD;   
     86  global $CONTACTS, $EDIT_FORM, $RCMAIL; 
    8787 
    8888  $result = $CONTACTS->get_result(); 
     
    9090  if (!strlen($EDIT_FORM)) 
    9191    { 
    92     $hiddenfields = new html_hiddenfield(array('name' => '_task', 'value' => $GLOBALS['_task'])); 
     92    $hiddenfields = new html_hiddenfield(array('name' => '_task', 'value' => $RCMAIL->task)); 
    9393    $hiddenfields->add(array('name' => '_action', 'value' => 'save', 'source' => get_input_value('_source', RCUBE_INPUT_GPC))); 
    9494     
     
    9696      $hiddenfields->add(array('name' => '_cid', 'value' => $record['ID'])); 
    9797     
    98     $form_start = !strlen($attrib['form']) ? '<form name="form" action="./" method="post">' : ''; 
    99     $form_start .= "\n$SESS_HIDDEN_FIELD\n"; 
     98    $form_start = !strlen($attrib['form']) ? $RCMAIL->output->form_tag(array('name' => "form", 'method' => "post")) : ''; 
    10099    $form_start .= $hiddenfields->show(); 
    101100    } 
     
    105104   
    106105  if (!strlen($EDIT_FORM)) 
    107     $OUTPUT->add_gui_object('editform', $form_name); 
     106    $RCMAIL->output->add_gui_object('editform', $form_name); 
    108107   
    109108  $EDIT_FORM = $form_name; 
    110109 
    111   return array($form_start, $form_end);   
     110  return array($form_start, $form_end);  
    112111  } 
    113112 
  • trunk/roundcubemail/program/steps/addressbook/save.inc

    r638 r1344  
    2929 
    3030// check input 
    31 if ((!get_input_value('_name', RCUBE_INPUT_POST) || !get_input_value('_email', RCUBE_INPUT_POST)) && $_framed) 
     31if ((!get_input_value('_name', RCUBE_INPUT_POST) || !get_input_value('_email', RCUBE_INPUT_POST)) && $OUTPUT->action) 
    3232{ 
    3333  $OUTPUT->show_message('formincomplete', 'warning'); 
     
    5555  if ($CONTACTS->update($cid, $a_record)) 
    5656  { 
    57     if ($_framed) 
     57    if ($OUTPUT->action) 
    5858    { 
    5959      // define list of cols to be displayed 
     
    9797  if ($insert_id = $CONTACTS->insert($a_record)) 
    9898  { 
    99     if ($_framed) 
     99    if ($OUTPUT->action) 
    100100    { 
    101101      // add contact row or jump to the page where it should appear 
  • trunk/roundcubemail/program/steps/mail/compose.inc

    r1315 r1344  
    2727 
    2828// remove an attachment 
    29 if ($_action=='remove-attachment' && preg_match('/^rcmfile([0-9]+)$/', $_POST['_file'], $regs)) 
     29if ($RCMAIL->action=='remove-attachment' && preg_match('/^rcmfile([0-9]+)$/', $_POST['_file'], $regs)) 
    3030{ 
    3131  $id = $regs[1]; 
     
    4040} 
    4141 
    42 if ($_action=='display-attachment' && preg_match('/^rcmfile([0-9]+)$/', $_GET['_file'], $regs)) 
     42if ($RCMAIL->action=='display-attachment' && preg_match('/^rcmfile([0-9]+)$/', $_GET['_file'], $regs)) 
    4343{ 
    4444  $id = $regs[1]; 
     
    338338function rcmail_compose_body($attrib) 
    339339{ 
    340   global $CONFIG, $OUTPUT, $MESSAGE, $compose_mode; 
     340  global $RCMAIL, $CONFIG, $OUTPUT, $MESSAGE, $compose_mode; 
    341341   
    342342  list($form_start, $form_end) = get_form_tags($attrib); 
     
    411411    } 
    412412 
    413   $tinylang = substr($_SESSION['user_lang'], 0, 2);  
     413  $tinylang = substr($_SESSION['language'], 0, 2); 
    414414  if (!file_exists('program/js/tiny_mce/langs/'.$tinylang.'.js')) 
    415415    {  
     
    456456      "googie.decorateTextarea('%s');\n". 
    457457      "%s.set_env('spellcheck', googie);", 
    458       $GLOBALS['COMM_PATH'], 
     458      $RCMAIL->comm_path, 
    459459      JQ(Q(rcube_label('checkspelling'))), 
    460460      JQ(Q(rcube_label('resumeediting'))), 
     
    463463      JQ(Q(rcube_label('nospellerrors'))), 
    464464      $lang_set, 
    465       substr($_SESSION['user_lang'], 0, 2), 
     465      substr($_SESSION['language'], 0, 2), 
    466466      $attrib['id'], 
    467467      JS_OBJECT_NAME), 'foot'); 
     
    705705function rcmail_compose_attachment_form($attrib) 
    706706{ 
    707   global $OUTPUT, $SESS_HIDDEN_FIELD; 
     707  global $OUTPUT; 
    708708 
    709709  // add ID if not given 
     
    711711    $attrib['id'] = 'rcmUploadbox'; 
    712712   
    713   // allow the following attributes to be added to the <div> tag 
    714   $attrib_str = create_attrib_string($attrib, array('id', 'class', 'style')); 
    715   $input_field = rcmail_compose_attachment_field(array()); 
    716   $label_send = rcube_label('upload'); 
    717   $label_close = rcube_label('close'); 
    718   $js_instance = JS_OBJECT_NAME; 
    719    
    720   $out = <<<EOF 
    721 <div$attrib_str> 
    722 <form action="./" method="post" enctype="multipart/form-data"> 
    723 $SESS_HIDDEN_FIELD 
    724 $input_field<br /> 
    725 <input type="button" value="$label_close" class="button" onclick="document.getElementById('$attrib[id]').style.visibility='hidden'" /> 
    726 <input type="button" value="$label_send" class="button" onclick="$js_instance.command('send-attachment', this.form)" /> 
    727 </form> 
    728 </div> 
    729 EOF; 
    730  
     713  $button = new html_inputfield(array('type' => "button", 'class' => "button")); 
     714   
     715  $out = html::div($attrib, 
     716    $OUTPUT->form_tag(array('name' => "form", 'method' => "post")) . 
     717    rcmail_compose_attachment_field(array()) . html::br() . 
     718    $button->show(rcube_label('close'), array('onclick' => "document.getElementById('$attrib[id]').style.visibility='hidden'")) . 
     719    $button->show(rcube_label('upload'), array('onclick' => JS_OBJECT_NAME . ".command('send-attachment', this.form)")) 
     720  ); 
     721   
    731722   
    732723  $OUTPUT->add_gui_object('uploadbox', $attrib['id']); 
     
    844835function get_form_tags($attrib) 
    845836{ 
    846   global $CONFIG, $OUTPUT, $MESSAGE_FORM, $SESS_HIDDEN_FIELD;   
     837  global $RCMAIL, $MESSAGE_FORM; 
    847838 
    848839  $form_start = ''; 
    849840  if (!strlen($MESSAGE_FORM)) 
    850841  { 
    851     $hiddenfields = new html_hiddenfield(array('name' => '_task', 'value' => $GLOBALS['_task'])); 
     842    $hiddenfields = new html_hiddenfield(array('name' => '_task', 'value' => $RCMAIL->task)); 
    852843    $hiddenfields->add(array('name' => '_action', 'value' => 'send')); 
    853844 
    854     $form_start = empty($attrib['form']) ? '<form name="form" action="./" method="post">' : ''; 
    855     $form_start .= "\n$SESS_HIDDEN_FIELD\n"; 
     845    $form_start = empty($attrib['form']) ? $RCMAIL->output->form_tag(array('name' => "form", 'method' => "post")) : ''; 
    856846    $form_start .= $hiddenfields->show(); 
    857847  } 
     
    861851   
    862852  if (!strlen($MESSAGE_FORM)) 
    863     $OUTPUT->add_gui_object('messageform', $form_name); 
     853    $RCMAIL->output->add_gui_object('messageform', $form_name); 
    864854   
    865855  $MESSAGE_FORM = $form_name; 
  • trunk/roundcubemail/program/steps/mail/folders.inc

    r1020 r1344  
    2222 
    2323// send EXPUNGE command 
    24 if ($_action=='expunge' && ($mbox = get_input_value('_mbox', RCUBE_INPUT_POST))) 
     24if ($RCMAIL->action=='expunge' && ($mbox = get_input_value('_mbox', RCUBE_INPUT_POST))) 
    2525{ 
    2626  $success = $IMAP->expunge($mbox); 
     
    3030  { 
    3131    $OUTPUT->command('message_list.clear'); 
    32     $_action = 'list'; 
     32    $RCMAIL->action = 'list'; 
    3333    return; 
    3434  } 
     
    3838 
    3939// clear mailbox 
    40 else if ($_action=='purge' && ($mbox = get_input_value('_mbox', RCUBE_INPUT_POST))) 
     40else if ($RCMAIL->action=='purge' && ($mbox = get_input_value('_mbox', RCUBE_INPUT_POST))) 
    4141{ 
    4242  // we should only be purging trash and junk 
  • trunk/roundcubemail/program/steps/mail/func.inc

    r1332 r1344  
    7575 
    7676// set page title 
    77 if (empty($_action) || $_action == 'list') 
     77if (empty($RCMAIL->action) || $RCMAIL->action == 'list') 
    7878  $OUTPUT->set_pagetitle(rcmail_localize_foldername($IMAP->get_mailbox_name())); 
    7979 
  • trunk/roundcubemail/program/steps/mail/move_del.inc

    r1285 r1344  
    2525 
    2626// move messages 
    27 if ($_action=='moveto' && !empty($_POST['_uid']) && !empty($_POST['_target_mbox'])) 
     27if ($RCMAIL->action=='moveto' && !empty($_POST['_uid']) && !empty($_POST['_target_mbox'])) 
    2828{ 
    2929  $count = sizeof(explode(',', ($uids = get_input_value('_uid', RCUBE_INPUT_POST)))); 
     
    4242 
    4343// delete messages  
    44 else if ($_action=='delete' && !empty($_POST['_uid'])) 
     44else if ($RCMAIL->action=='delete' && !empty($_POST['_uid'])) 
    4545{ 
    4646  $count = sizeof(explode(',', ($uids = get_input_value('_uid', RCUBE_INPUT_POST)))); 
     
    9090$OUTPUT->command('set_unread_count', $mbox, $IMAP->messagecount($mbox, 'UNSEEN'), ($mbox == 'INBOX')); 
    9191 
    92 if ($_action=='moveto' && $target) 
     92if ($RCMAIL->action=='moveto' && $target) 
    9393  $OUTPUT->command('set_unread_count', $target, $IMAP->messagecount($target, 'UNSEEN')); 
    9494 
  • trunk/roundcubemail/program/steps/mail/sendmail.inc

    r1291 r1344  
    314314 
    315315// encoding subject header with mb_encode provides better results with asian characters 
    316 if ($MBSTRING && function_exists("mb_encode_mimeheader")) 
     316if (function_exists("mb_encode_mimeheader")) 
    317317{ 
    318318  mb_internal_encoding($message_charset); 
  • trunk/roundcubemail/program/steps/mail/show.inc

    r1296 r1344  
    2020*/ 
    2121 
    22 $PRINT_MODE = $_action=='print' ? TRUE : FALSE; 
     22$PRINT_MODE = $RCMAIL->action=='print' ? TRUE : FALSE; 
    2323 
    2424// similar code as in program/steps/mail/get.inc 
     
    3636    { 
    3737    $OUTPUT->show_message('messageopenerror', 'error'); 
    38     if ($_action=='preview' && template_exists('messagepreview')) 
     38    if ($RCMAIL->action=='preview' && template_exists('messagepreview')) 
    3939        $OUTPUT->send('messagepreview'); 
    4040    else 
    4141      { 
    42       $_action = 'list'; 
     42      $RCMAIL->action = 'list'; 
    4343      return; 
    4444      } 
     
    7979  { 
    8080    $marked = $IMAP->set_flag($MESSAGE['UID'], 'SEEN'); 
    81     if($_action == 'preview' && $marked != -1) 
     81    if($RCMAIL->action == 'preview' && $marked != -1) 
    8282    { 
    8383      $OUTPUT->command('set_unread_count_from_preview', $mbox_name, $IMAP->messagecount($mbox_name, 'UNSEEN'), ($mbox_name == 'INBOX')); 
     
    204204 
    205205 
    206 if ($_action=='print' && template_exists('printmessage')) 
     206if ($RCMAIL->action=='print' && template_exists('printmessage')) 
    207207  $OUTPUT->send('printmessage'); 
    208 else if ($_action=='preview' && template_exists('messagepreview')) 
     208else if ($RCMAIL->action=='preview' && template_exists('messagepreview')) 
    209209    $OUTPUT->send('messagepreview'); 
    210210else 
  • trunk/roundcubemail/program/steps/settings/edit_identity.inc

    r1320 r1344  
    2020*/ 
    2121 
    22 if (($_GET['_iid'] || $_POST['_iid']) && $_action=='edit-identity') 
     22if (($_GET['_iid'] || $_POST['_iid']) && $RCMAIL->action=='edit-identity') 
    2323  { 
    2424  $IDENTITY_RECORD = $USER->get_identity(get_input_value('_iid', RCUBE_INPUT_GPC)); 
     
    3838function rcube_identity_form($attrib) 
    3939  { 
    40   global $IDENTITY_RECORD, $OUTPUT; 
     40  global $IDENTITY_RECORD, $RCMAIL, $OUTPUT; 
    4141 
    42   $tinylang = substr($_SESSION['user_lang'], 0, 2); 
     42  $tinylang = substr($_SESSION['language'], 0, 2); 
    4343  if (!file_exists('program/js/tiny_mce/langs/'.$tinylang.'.js')) 
    4444    { 
     
    5959                                    "theme_advanced_buttons3 : '' });"); 
    6060 
    61   if (!$IDENTITY_RECORD && $GLOBALS['_action']!='add-identity') 
     61  if (!$IDENTITY_RECORD && $RCMAIL->action != 'add-identity') 
    6262    return rcube_label('notfound'); 
    6363 
     
    139139$OUTPUT->add_handler('identityform', 'rcube_identity_form'); 
    140140 
    141 if ($_action=='add-identity' && template_exists('addidentity')) 
     141if ($RCMAIL->action=='add-identity' && template_exists('addidentity')) 
    142142  $OUTPUT->send('addidentity'); 
    143143 
  • trunk/roundcubemail/program/steps/settings/func.inc

    r1334 r1344  
    2828function rcmail_user_prefs_form($attrib) 
    2929  { 
    30   global $DB, $CONFIG, $sess_user_lang; 
     30  global $DB, $CONFIG; 
    3131 
    3232  $no_override = is_array($CONFIG['dont_override']) ? array_flip($CONFIG['dont_override']) : array(); 
     
    5757                    $field_id, 
    5858                    Q(rcube_label('language')), 
    59                     $select_lang->show($sess_user_lang)); 
     59                    $select_lang->show($_SESSION['language'])); 
    6060    } 
    6161 
     
    252252function get_form_tags($attrib, $action, $add_hidden=array()) 
    253253  { 
    254   global $OUTPUT, $EDIT_FORM, $SESS_HIDDEN_FIELD;   
     254  global $EDIT_FORM, $RCMAIL; 
    255255 
    256256  $form_start = ''; 
    257257  if (!strlen($EDIT_FORM)) 
    258258    { 
    259     $hiddenfields = new html_hiddenfield(array('name' => '_task', 'value' => $GLOBALS['_task'])); 
     259    $hiddenfields = new html_hiddenfield(array('name' => '_task', 'value' => $RCMAIL->task)); 
    260260    $hiddenfields->add(array('name' => '_action', 'value' => $action)); 
    261261     
     
    263263      $hiddenfields->add($add_hidden); 
    264264     
    265     $form_start = !strlen($attrib['form']) ? '<form name="form" action="./" method="post">' : ''; 
    266     $form_start .= "\n$SESS_HIDDEN_FIELD\n"; 
     265    $form_start = !strlen($attrib['form']) ? $RCMAIL->output->form_tag(array('name' => "form", 'method' => "post")) : ''; 
    267266    $form_start .= $hiddenfields->show(); 
    268267    } 
     
    272271 
    273272  if (!strlen($EDIT_FORM)) 
    274     $OUTPUT->add_gui_object('editform', $form_name); 
     273    $RCMAIL->output->add_gui_object('editform', $form_name); 
    275274   
    276275  $EDIT_FORM = $form_name; 
    277276 
    278   return array($form_start, $form_end);   
     277  return array($form_start, $form_end); 
    279278  } 
    280279 
  • trunk/roundcubemail/program/steps/settings/manage_folders.inc

    r1319 r1344  
    2121 
    2222// init IMAP connection 
    23 rcmail_imap_init(TRUE); 
     23$RCMAIL->imap_init(true); 
    2424 
    2525// subscribe to one or more mailboxes 
    26 if ($_action=='subscribe') 
     26if ($RCMAIL->action=='subscribe') 
    2727  { 
    2828  if ($mbox = get_input_value('_mbox', RCUBE_INPUT_POST)) 
     
    3434 
    3535// unsubscribe one or more mailboxes 
    36 else if ($_action=='unsubscribe') 
     36else if ($RCMAIL->action=='unsubscribe') 
    3737  { 
    3838  if ($mbox = get_input_value('_mbox', RCUBE_INPUT_POST)) 
     
    4444 
    4545// create a new mailbox 
    46 else if ($_action=='create-folder') 
     46else if ($RCMAIL->action=='create-folder') 
    4747  { 
    4848  if (!empty($_POST['_name'])) 
     
    6363 
    6464// rename a mailbox 
    65 else if ($_action=='rename-folder') 
     65else if ($RCMAIL->action=='rename-folder') 
    6666  { 
    6767  if (!empty($_POST['_folder_oldname']) && !empty($_POST['_folder_newname'])) 
     
    9898 
    9999// delete an existing IMAP mailbox 
    100 else if ($_action=='delete-folder') 
     100else if ($RCMAIL->action=='delete-folder') 
    101101  { 
    102102  $a_mboxes = array_merge($IMAP->list_mailboxes(), $IMAP->list_unsubscribed()); 
  • trunk/roundcubemail/program/steps/settings/save_identity.inc

    r938 r1344  
    108108 
    109109// go to next step 
    110 rcmail_overwrite_action($_framed ? 'edit-identity' : 'identities'); 
     110rcmail_overwrite_action($OUTPUT->action ? 'edit-identity' : 'identities'); 
    111111 
    112112?> 
  • trunk/roundcubemail/program/steps/settings/save_prefs.inc

    r1317 r1344  
    4040// switch UI language 
    4141if (isset($_POST['_language'])) 
    42   { 
    43   $sess_user_lang = $_SESSION['user_lang'] = get_input_value('_language', RCUBE_INPUT_POST); 
    44   rcmail_set_locale($sess_user_lang); 
    45   } 
     42  $_SESSION['language'] = get_input_value('_language', RCUBE_INPUT_POST); 
    4643 
    4744// force min size 
Note: See TracChangeset for help on using the changeset viewer.