Changeset 666 in subversion for trunk/roundcubemail/program/include/main.inc
- Timestamp:
- Aug 7, 2007 5:02:12 PM (6 years ago)
- File:
-
- 1 edited
-
trunk/roundcubemail/program/include/main.inc (modified) (51 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/roundcubemail/program/include/main.inc
r652 r666 20 20 */ 21 21 22 /** 23 * RoundCube Webmail common functions 24 * 25 * @package Core 26 * @author Thomas Bruederli <roundcube@gmail.com> 27 */ 28 22 29 require_once('lib/des.inc'); 23 30 require_once('lib/utf7.inc'); … … 32 39 33 40 34 // register session and connect to server 41 /** 42 * Initial startup function 43 * to register session, create database and imap connections 44 * 45 * @param string Current task 46 */ 35 47 function rcmail_startup($task='mail') 36 48 { … … 49 61 50 62 // prepare DB connection 51 require_once('include/rcube_'.(empty($CONFIG['db_backend']) ? 'db' : $CONFIG['db_backend']).'.inc'); 52 53 $DB = new rcube_db($CONFIG['db_dsnw'], $CONFIG['db_dsnr'], $CONFIG['db_persistent']); 63 $dbwrapper = empty($CONFIG['db_backend']) ? 'db' : $CONFIG['db_backend']; 64 $dbclass = "rcube_" . $dbwrapper; 65 require_once("include/$dbclass.inc"); 66 67 $DB = new $dbclass($CONFIG['db_dsnw'], $CONFIG['db_dsnr'], $CONFIG['db_persistent']); 54 68 $DB->sqlite_initials = $INSTALL_PATH.'SQL/sqlite.initial.sql'; 55 69 $DB->db_connect('w'); … … 102 116 103 117 104 // load roundcube configuration into global var 118 /** 119 * Load roundcube configuration array 120 * 121 * @return array Named configuration parameters 122 */ 105 123 function rcmail_load_config() 106 124 { … … 140 158 141 159 142 // load a host-specific config file if configured 160 /** 161 * Load a host-specific config file if configured 162 * This will merge the host specific configuration with the given one 163 * 164 * @param array Global configuration parameters 165 */ 143 166 function rcmail_load_host_config(&$config) 144 167 { … … 158 181 159 182 160 // create authorization hash 183 /** 184 * Create unique authorization hash 185 * 186 * @param string Session ID 187 * @param int Timestamp 188 * @return string The generated auth hash 189 */ 161 190 function rcmail_auth_hash($sess_id, $ts) 162 191 { … … 176 205 177 206 178 // compare the auth hash sent by the client with the local session credentials 207 /** 208 * Check the auth hash sent by the client against the local session credentials 209 * 210 * @return boolean True if valid, False if not 211 */ 179 212 function rcmail_authenticate_session() 180 213 { … … 207 240 208 241 209 // create IMAP object and connect to server 242 /** 243 * Create global IMAP object and connect to server 244 * 245 * @param boolean True if connection should be established 246 */ 210 247 function rcmail_imap_init($connect=FALSE) 211 248 { … … 236 273 237 274 238 // set root dir and last stored mailbox 239 // this must be done AFTER connecting to the server 275 /** 276 * Set root dir and last stored mailbox 277 * This must be done AFTER connecting to the server! 278 */ 240 279 function rcmail_set_imap_prop() 241 280 { … … 256 295 257 296 258 // do these things on script shutdown 297 /** 298 * Do these things on script shutdown 299 */ 259 300 function rcmail_shutdown() 260 301 { … … 272 313 273 314 274 // destroy session data and remove cookie 315 /** 316 * Destroy session data and remove cookie 317 */ 275 318 function rcmail_kill_session() 276 319 { … … 293 336 294 337 295 // return correct name for a specific database table 338 /** 339 * Return correct name for a specific database table 340 * 341 * @param string Table name 342 * @return string Translated table name 343 */ 296 344 function get_table_name($table) 297 345 { … … 308 356 309 357 310 // return correct name for a specific database sequence 311 // (used for Postres only) 358 /** 359 * Return correct name for a specific database sequence 360 * (used for Postres only) 361 * 362 * @param string Secuence name 363 * @return string Translated sequence name 364 */ 312 365 function get_sequence_name($sequence) 313 366 { … … 324 377 325 378 326 // check the given string and returns language properties 379 /** 380 * Check the given string and returns language properties 381 * 382 * @param string Language code 383 * @param string Peropert name 384 * @return string Property value 385 */ 327 386 function rcube_language_prop($lang, $prop='lang') 328 387 { … … 361 420 362 421 363 // init output object for GUI and add common scripts 422 /** 423 * Init output object for GUI and add common scripts. 424 * This will instantiate a rcmail_template object and set 425 * environment vars according to the current session and configuration 426 */ 364 427 function rcmail_load_gui() 365 428 { … … 400 463 401 464 402 // set localization charset based on the given language 465 /** 466 * Set localization charset based on the given language. 467 * This also creates a global property for mbstring usage. 468 */ 403 469 function rcmail_set_locale($lang) 404 470 { … … 419 485 420 486 421 // auto-select IMAP host based on the posted login information 487 /** 488 * Auto-select IMAP host based on the posted login information 489 * 490 * @return string Selected IMAP host 491 */ 422 492 function rcmail_autoselect_host() 423 493 { … … 447 517 448 518 449 // perfom login to the IMAP server and to the webmail service 519 /** 520 * Perfom login to the IMAP server and to the webmail service. 521 * This will also create a new user entry if auto_create_user is configured. 522 * 523 * @param string IMAP user name 524 * @param string IMAP password 525 * @param string IMAP host 526 * @return boolean True on success, False on failure 527 */ 450 528 function rcmail_login($user, $pass, $host=NULL) 451 529 { … … 576 654 577 655 578 // create new entry in users and identities table 656 /** 657 * Create new entry in users and identities table 658 * 659 * @param string User name 660 * @param string IMAP host 661 * @return mixed New user ID or False on failure 662 */ 579 663 function rcmail_create_user($user, $host) 580 664 { … … 647 731 648 732 649 // load virtuser table in array 733 /** 734 * Load virtuser table in array 735 * 736 * @return array Virtuser table entries 737 */ 650 738 function rcmail_getvirtualfile() 651 739 { … … 660 748 661 749 662 // find matches of the given pattern in virtuser table 750 /** 751 * Find matches of the given pattern in virtuser table 752 * 753 * @param string Regular expression to search for 754 * @return array Matching entries 755 */ 663 756 function rcmail_findinvirtual($pattern) 664 757 { … … 683 776 684 777 685 // resolve username with virtuser table 778 /** 779 * Resolve username using a virtuser table 780 * 781 * @param string E-mail address to resolve 782 * @return string Resolved IMAP username 783 */ 686 784 function rcmail_email2user($email) 687 785 { … … 704 802 705 803 706 // resolve e-mail address with virtuser table 804 /** 805 * Resolve e-mail address from virtuser table 806 * 807 * @param string User name 808 * @return string Resolved e-mail address 809 */ 707 810 function rcmail_user2email($user) 708 811 { … … 725 828 726 829 830 /** 831 * Write the given user prefs to the user's record 832 * 833 * @param mixed User prefs to save 834 * @return boolean True on success, False on failure 835 */ 727 836 function rcmail_save_user_prefs($a_user_prefs) 728 837 { … … 748 857 749 858 750 // overwrite action variable 859 /** 860 * Overwrite action variable 861 * 862 * @param string New action value 863 */ 751 864 function rcmail_overwrite_action($action) 752 865 { … … 790 903 791 904 792 // encrypt IMAP password using DES encryption 905 /** 906 * Encrypt IMAP password using DES encryption 907 * 908 * @param string Password to encrypt 909 * @return string Encryprted string 910 */ 793 911 function encrypt_passwd($pass) 794 912 { … … 798 916 799 917 800 // decrypt IMAP password using DES encryption 918 /** 919 * Decrypt IMAP password using DES encryption 920 * 921 * @param string Encrypted password 922 * @return string Plain password 923 */ 801 924 function decrypt_passwd($cypher) 802 925 { … … 806 929 807 930 808 // return a 24 byte key for the DES encryption 931 /** 932 * Return a 24 byte key for the DES encryption 933 * 934 * @return string DES encryption key 935 */ 809 936 function get_des_key() 810 937 { … … 822 949 823 950 824 // read directory program/localization/ and return a list of available languages 951 /** 952 * Read directory program/localization and return a list of available languages 953 * 954 * @return array List of available localizations 955 */ 825 956 function rcube_list_languages() 826 957 { … … 849 980 850 981 851 // add a localized label to the client environment 982 /** 983 * Add a localized label to the client environment 984 */ 852 985 function rcube_add_label() 853 986 { … … 860 993 861 994 862 // remove temp files older than two day 995 /** 996 * Garbage collector function for temp files. 997 * Remove temp files older than two days 998 */ 863 999 function rcmail_temp_gc() 864 1000 { … … 882 1018 883 1019 884 // remove all expired message cache records 1020 /** 1021 * Garbage collector for cache entries. 1022 * Remove all expired message cache records 1023 */ 885 1024 function rcmail_message_cache_gc() 886 1025 { … … 1055 1194 1056 1195 /** 1057 * Quote a given string. Alias function for rep_specialchars_output 1058 * @see rep_specialchars_output 1196 * Quote a given string. 1197 * Shortcut function for rep_specialchars_output 1198 * 1199 * @return string HTML-quoted string 1200 * @see rep_specialchars_output() 1059 1201 */ 1060 1202 function Q($str, $mode='strict', $newlines=TRUE) … … 1064 1206 1065 1207 /** 1066 * Quote a given string. Alias function for rep_specialchars_output 1067 * @see rep_specialchars_output 1208 * Quote a given string for javascript output. 1209 * Shortcut function for rep_specialchars_output 1210 * 1211 * @return string JS-quoted string 1212 * @see rep_specialchars_output() 1068 1213 */ 1069 1214 function JQ($str) … … 1117 1262 } 1118 1263 1264 1119 1265 /** 1120 1266 * Remove single and double quotes from given string 1267 * 1268 * @param string Input value 1269 * @return string Dequoted string 1121 1270 */ 1122 1271 function strip_quotes($str) … … 1125 1274 } 1126 1275 1276 1127 1277 /** 1128 1278 * Remove new lines characters from given string 1279 * 1280 * @param string Input value 1281 * @return string Stripped string 1129 1282 */ 1130 1283 function strip_newlines($str) … … 1134 1287 1135 1288 1136 // return boolean if a specific template exists 1289 /** 1290 * Check if a specific template exists 1291 * 1292 * @param string Template name 1293 * @return boolean True if template exists 1294 */ 1137 1295 function template_exists($name) 1138 1296 { … … 1145 1303 1146 1304 1147 // Wrapper for rcmail_template::parse() 1148 // @deprecated 1305 /** 1306 * Wrapper for rcmail_template::parse() 1307 * @deprecated 1308 */ 1149 1309 function parse_template($name='main', $exit=true) 1150 1310 { … … 1153 1313 1154 1314 1155 1315 /** 1316 * Create a HTML table based on the given data 1317 * 1318 * @param array Named table attributes 1319 * @param mixed Table row data. Either a two-dimensional array or a valid SQL result set 1320 * @param array List of cols to show 1321 * @param string Name of the identifier col 1322 * @return string HTML table code 1323 */ 1156 1324 function rcube_table_output($attrib, $table_data, $a_show_cols, $id_col) 1157 1325 { … … 1255 1423 1256 1424 1257 // return the mail domain configured for the given host 1425 /** 1426 * Return the mail domain configured for the given host 1427 * 1428 * @param string IMAP host 1429 * @return string Resolved SMTP host 1430 */ 1258 1431 function rcmail_mail_domain($host) 1259 1432 { … … 1273 1446 1274 1447 1275 // compose a valid attribute string for HTML tags 1448 /** 1449 * Compose a valid attribute string for HTML tags 1450 * 1451 * @param array Named tag attributes 1452 * @param array List of allowed attributes 1453 * @return string HTML formatted attribute string 1454 */ 1276 1455 function create_attrib_string($attrib, $allowed_attribs=array('id', 'class', 'style')) 1277 1456 { … … 1286 1465 1287 1466 1288 // convert a HTML attribute string attributes to an associative array (name => value) 1467 /** 1468 * Convert a HTML attribute string attributes to an associative array (name => value) 1469 * 1470 * @param string Input string 1471 * @return array Key-value pairs of parsed attributes 1472 */ 1289 1473 function parse_attrib_string($str) 1290 1474 { … … 1301 1485 1302 1486 1487 /** 1488 * Convert the given date to a human readable form 1489 * This uses the date formatting properties from config 1490 * 1491 * @param mixed Date representation (string or timestamp) 1492 * @param string Date format to use 1493 * @return string Formatted date string 1494 */ 1303 1495 function format_date($date, $format=NULL) 1304 1496 { … … 1372 1564 1373 1565 1566 /** 1567 * Compose a valid representaion of name and e-mail address 1568 * 1569 * @param string E-mail address 1570 * @param string Person name 1571 * @return string Formatted string 1572 */ 1374 1573 function format_email_recipient($email, $name='') 1375 1574 { … … 1380 1579 } 1381 1580 1382 1383 1384 // ************** functions delivering gui objects **************1385 1386 1387 1388 function rcmail_message_container($attrib)1389 {1390 global $OUTPUT;1391 1392 if (!$attrib['id'])1393 $attrib['id'] = 'rcmMessageContainer';1394 1395 // allow the following attributes to be added to the <table> tag1396 $attrib_str = create_attrib_string($attrib, array('style', 'class', 'id'));1397 $out = '<div' . $attrib_str . "></div>";1398 1399 $OUTPUT->add_gui_object('message', $attrib['id']);1400 1401 return $out;1402 }1403 1404 1405 // return the IMAP username of the current session1406 function rcmail_current_username($attrib)1407 {1408 global $DB;1409 static $s_username;1410 1411 // alread fetched1412 if (!empty($s_username))1413 return $s_username;1414 1415 // get e-mail address form default identity1416 $sql_result = $DB->query("SELECT email AS mailto1417 FROM ".get_table_name('identities')."1418 WHERE user_id=?1419 AND standard=11420 AND del<>1",1421 $_SESSION['user_id']);1422 1423 if ($DB->num_rows($sql_result))1424 {1425 $sql_arr = $DB->fetch_assoc($sql_result);1426 $s_username = $sql_arr['mailto'];1427 }1428 else if (strstr($_SESSION['username'], '@'))1429 $s_username = $_SESSION['username'];1430 else1431 $s_username = $_SESSION['username'].'@'.$_SESSION['imap_host'];1432 1433 return $s_username;1434 }1435 1436 1437 // return code for the webmail login form1438 function rcmail_login_form($attrib)1439 {1440 global $CONFIG, $OUTPUT, $SESS_HIDDEN_FIELD;1441 1442 $labels = array();1443 $labels['user'] = rcube_label('username');1444 $labels['pass'] = rcube_label('password');1445 $labels['host'] = rcube_label('server');1446 1447 $input_user = new textfield(array('name' => '_user', 'id' => 'rcmloginuser', 'size' => 30, 'autocomplete' => 'off'));1448 $input_pass = new passwordfield(array('name' => '_pass', 'id' => 'rcmloginpwd', 'size' => 30));1449 $input_action = new hiddenfield(array('name' => '_action', 'value' => 'login'));1450 1451 $fields = array();1452 $fields['user'] = $input_user->show(get_input_value('_user', RCUBE_INPUT_POST));1453 $fields['pass'] = $input_pass->show();1454 $fields['action'] = $input_action->show();1455 1456 if (is_array($CONFIG['default_host']))1457 {1458 $select_host = new select(array('name' => '_host', 'id' => 'rcmloginhost'));1459 1460 foreach ($CONFIG['default_host'] as $key => $value)1461 {1462 if (!is_array($value))1463 $select_host->add($value, (is_numeric($key) ? $value : $key));1464 else1465 {1466 unset($select_host);1467 break;1468 }1469 }1470 1471 $fields['host'] = isset($select_host) ? $select_host->show($_POST['_host']) : null;1472 }1473 else if (!strlen($CONFIG['default_host']))1474 {1475 $input_host = new textfield(array('name' => '_host', 'id' => 'rcmloginhost', 'size' => 30));1476 $fields['host'] = $input_host->show($_POST['_host']);1477 }1478 1479 $form_name = strlen($attrib['form']) ? $attrib['form'] : 'form';1480 $form_start = !strlen($attrib['form']) ? '<form name="form" action="./" method="post">' : '';1481 $form_end = !strlen($attrib['form']) ? '</form>' : '';1482 1483 if ($fields['host'])1484 $form_host = <<<EOF1485 1486 </tr><tr>1487 1488 <td class="title"><label for="rcmloginhost">$labels[host]</label></td>1489 <td>$fields[host]</td>1490 1491 EOF;1492 1493 $OUTPUT->add_gui_object('loginform', $form_name);1494 1495 $out = <<<EOF1496 $form_start1497 $SESS_HIDDEN_FIELD1498 $fields[action]1499 <table><tr>1500 1501 <td class="title"><label for="rcmloginuser">$labels[user]</label></td>1502 <td>$fields[user]</td>1503 1504 </tr><tr>1505 1506 <td class="title"><label for="rcmloginpwd">$labels[pass]</label></td>1507 <td>$fields[pass]</td>1508 $form_host1509 </tr></table>1510 $form_end1511 EOF;1512 1513 return $out;1514 }1515 1516 1517 function rcmail_charset_selector($attrib)1518 {1519 global $OUTPUT;1520 1521 // pass the following attributes to the form class1522 $field_attrib = array('name' => '_charset');1523 foreach ($attrib as $attr => $value)1524 if (in_array($attr, array('id', 'class', 'style', 'size', 'tabindex')))1525 $field_attrib[$attr] = $value;1526 1527 $charsets = array(1528 'US-ASCII' => 'ASCII (English)',1529 'EUC-JP' => 'EUC-JP (Japanese)',1530 'EUC-KR' => 'EUC-KR (Korean)',1531 'BIG5' => 'BIG5 (Chinese)',1532 'GB2312' => 'GB2312 (Chinese)',1533 'ISO-2022-JP' => 'ISO-2022-JP (Japanese)',1534 'ISO-8859-1' => 'ISO-8859-1 (Latin-1)',1535 'ISO-8859-2' => 'ISO-8895-2 (Central European)',1536 'ISO-8859-7' => 'ISO-8859-7 (Greek)',1537 'ISO-8859-9' => 'ISO-8859-9 (Turkish)',1538 'Windows-1251' => 'Windows-1251 (Cyrillic)',1539 'Windows-1252' => 'Windows-1252 (Western)',1540 'Windows-1255' => 'Windows-1255 (Hebrew)',1541 'Windows-1256' => 'Windows-1256 (Arabic)',1542 'Windows-1257' => 'Windows-1257 (Baltic)',1543 'UTF-8' => 'UTF-8'1544 );1545 1546 $select = new select($field_attrib);1547 $select->add(array_values($charsets), array_keys($charsets));1548 1549 $set = $_POST['_charset'] ? $_POST['_charset'] : $OUTPUT->get_charset();1550 return $select->show($set);1551 }1552 1553 1554 // return code for search function1555 function rcmail_search_form($attrib)1556 {1557 global $OUTPUT;1558 1559 // add some labels to client1560 rcube_add_label('searching');1561 1562 $attrib['name'] = '_q';1563 1564 if (empty($attrib['id']))1565 $attrib['id'] = 'rcmqsearchbox';1566 1567 $input_q = new textfield($attrib);1568 $out = $input_q->show();1569 1570 $OUTPUT->add_gui_object('qsearchbox', $attrib['id']);1571 1572 // add form tag around text field1573 if (empty($attrib['form']))1574 $out = sprintf(1575 '<form name="rcmqsearchform" action="./" '.1576 'onsubmit="%s.command(\'search\');return false" style="display:inline;">%s</form>',1577 JS_OBJECT_NAME,1578 $out);1579 1580 return $out;1581 }1582 1581 1583 1582 … … 1638 1637 1639 1638 1639 /** 1640 * @access private 1641 */ 1640 1642 function rcube_timer() 1641 1643 { … … 1645 1647 1646 1648 1649 /** 1650 * @access private 1651 */ 1647 1652 function rcube_print_time($timer, $label='Timer') 1648 1653 { … … 1660 1665 1661 1666 1662 // return the mailboxlist in HTML 1667 /** 1668 * Return the mailboxlist in HTML 1669 * 1670 * @param array Named parameters 1671 * @return string HTML code for the gui object 1672 */ 1663 1673 function rcmail_mailbox_list($attrib) 1664 1674 { … … 1730 1740 1731 1741 1732 // create a hierarchical array of the mailbox list 1742 /** 1743 * Create a hierarchical array of the mailbox list 1744 * @access private 1745 */ 1733 1746 function rcmail_build_folder_tree(&$arrFolders, $folder, $delm='/', $path='') 1734 1747 { … … 1759 1772 1760 1773 1761 // return html for a structured list <ul> for the mailbox tree 1774 /** 1775 * Return html for a structured list <ul> for the mailbox tree 1776 * @access private 1777 */ 1762 1778 function rcmail_render_folder_tree_html(&$arrFolders, &$special, &$mbox_name, $maxlength, $nestLevel=0) 1763 1779 { … … 1840 1856 1841 1857 1842 // return html for a flat list <select> for the mailbox tree 1858 /** 1859 * Return html for a flat list <select> for the mailbox tree 1860 * @access private 1861 */ 1843 1862 function rcmail_render_folder_tree_select(&$arrFolders, &$special, &$mbox_name, $maxlength, $nestLevel=0) 1844 1863 {
Note: See TracChangeset
for help on using the changeset viewer.
