Changeset 981 in subversion
- Timestamp:
- Feb 1, 2008 8:59:23 AM (5 years ago)
- File:
-
- 1 edited
-
branches/devel-vnext/program/include/rcube.php (modified) (95 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/devel-vnext/program/include/rcube.php
r957 r981 18 18 $Id: main.inc 567 2007-05-17 18:41:24Z thomasb $ 19 19 20 */20 */ 21 21 22 22 … … 41 41 const INPUT_POST = 0x0102; 42 42 const INPUT_GPC = 0x0103; 43 44 43 45 44 /** 46 45 * register session and connect to server … … 51 50 * @return void 52 51 */ 53 static function startup($task = 'mail') {52 public static function startup($task = 'mail') { 54 53 $registry = rcube_registry::get_instance(); 55 54 $registry->set('task', $task, 'core'); … … 63 62 } 64 63 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']); 66 68 $DB->sqlite_initials = INSTALL_PATH . 'SQL/sqlite.initial.sql'; 67 69 $DB->db_connect('w'); … … 70 72 71 73 // use database for storing session data 72 include_once 'include/session.inc';74 require_once 'include/session.inc'; 73 75 74 76 // init session … … 87 89 $registry->set('user_lang', $user_lang, 'core'); 88 90 91 // create user object 92 $USER = new rcube_user($_SESSION['user_id']); 93 $registry->set('USER', $USER, 'core'); 94 89 95 // overwrite config with user preferences 90 96 if (is_array($_SESSION['user_prefs'])) { 91 foreach ($_SESSION['user_prefs'] as $key => $prop) 97 foreach ($_SESSION['user_prefs'] as $key => $prop) { 92 98 $registry->set($key, $prop, 'config'); 93 99 } 94 100 $CONFIG = array_merge($CONFIG, $_SESSION['user_prefs']); 95 101 } … … 111 117 if ($CONFIG['locale_string']) { 112 118 setlocale(LC_ALL, $CONFIG['locale_string']); 113 } 114 else if ($user_lang) { 119 } else if ($user_lang) { 115 120 setlocale(LC_ALL, $user_lang); 116 121 } 117 122 118 123 register_shutdown_function(array('rcube', 'shutdown')); 119 124 } 120 125 121 122 126 /** 123 127 * Load roundcube configuration array … … 125 129 * @return array Named configuration parameters 126 130 */ 127 static function load_config() 128 { 131 private static function load_config() { 129 132 // 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'; 131 134 $conf = is_array($rcmail_config) ? $rcmail_config : array(); 132 135 … … 137 140 138 141 // load db conf 139 include_once INSTALL_PATH .'config/db.inc.php';142 require_once INSTALL_PATH.'config/db.inc.php'; 140 143 $conf = array_merge($conf, $rcmail_config); 141 144 142 145 if (empty($conf['log_dir'])) { 143 $conf['log_dir'] = INSTALL_PATH . 'logs'; 144 } 145 else { 146 $conf['log_dir'] = INSTALL_PATH.'logs'; 147 } else { 146 148 $conf['log_dir'] = unslashify($conf['log_dir']); 147 149 } … … 153 155 if ($conf['debug_level'] & 4) { 154 156 ini_set('display_errors', 1); 155 } 156 else { 157 } else { 157 158 ini_set('display_errors', 0); 158 159 } 159 160 160 161 // copy all config parameters to registry 161 162 $registry = rcube_registry::get_instance(); 162 foreach ($conf as $key => $prop) 163 foreach ($conf as $key => $prop) { 163 164 $registry->set($key, $prop, 'config'); 164 165 } 166 165 167 return $conf; 166 168 } 167 168 169 169 170 /** … … 171 172 * This will merge the host specific configuration with the given one 172 173 * 173 * @param array Global configuration parameters174 * /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()) { 177 178 $fname = null; 178 179 179 180 if (is_array($config['include_host_config'])) { 180 181 $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'])) { 183 183 $fname = preg_replace('/[^a-z0-9\.\-_]/i', '', $_SERVER['HTTP_HOST']) . '.inc.php'; 184 184 } 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; 187 188 $config = array_merge($config, $rcmail_config); 188 189 } 189 190 190 return $config; 191 191 } 192 193 192 194 193 /** … … 199 198 * @return string The generated auth hash 200 199 */ 201 static function auth_hash($sess_id, $ts) 202 { 200 private static function auth_hash($sess_id = null, $ts = null) { 203 201 $registry = rcube_registry::get_instance(); 204 202 $CONFIG = $registry->get_all('config'); … … 206 204 $auth_string = sprintf( 207 205 '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'] 212 210 ); 213 211 … … 218 216 } 219 217 220 221 218 /** 222 219 * Check the auth hash sent by the client against the local session credentials … … 224 221 * @return boolean True if valid, False if not 225 222 */ 226 static function authenticate_session() 227 { 223 public static function authenticate_session() { 228 224 $registry = rcube_registry::get_instance(); 229 225 $CONFIG = $registry->get_all('config'); … … 235 231 $now = time(); 236 232 $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'])); 238 234 239 235 // renew auth cookie every 5 minutes (only for GET requests) … … 243 239 setcookie('sessauth', self::auth_hash(session_id(), $now)); 244 240 } 245 } 246 else { 241 } else { 247 242 $valid = $CONFIG['ip_check'] ? $_SERVER['REMOTE_ADDR'] == $SESS_CLIENT_IP : true; 248 243 } … … 262 257 * @uses rcube_registry::get_instance() 263 258 */ 264 static function imap_init($connect=FALSE) 265 { 259 public static function imap_init($connect=FALSE) { 266 260 $registry = rcube_registry::get_instance(); 267 261 $CONFIG = $registry->get_all('config'); … … 277 271 if ($connect) { 278 272 $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'] 284 278 ); 285 279 $registry->set('IMAP', $IMAP, 'core'); … … 298 292 $IMAP->set_pagesize($CONFIG['pagesize']); 299 293 } 300 294 301 295 $registry->set('IMAP', $IMAP, 'core'); 302 296 } … … 306 300 * This must be done AFTER connecting to the server! 307 301 */ 308 static function set_imap_prop() 309 { 302 public static function set_imap_prop() { 310 303 $registry = rcube_registry::get_instance(); 311 304 $IMAP = $registry->get('IMAP', 'core'); … … 331 324 /** 332 325 * 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() { 336 330 $registry = rcube_registry::get_instance(); 337 331 $IMAP = $registry->get('IMAP', 'core'); 332 $CONTACTS = $registry->get('CONTACTS', 'core'); 338 333 339 334 if (is_object($IMAP)) { … … 342 337 } 343 338 339 if (is_object($CONTACTS)) { 340 $CONTACTS->close(); 341 } 344 342 // before closing the database connection, write session data 345 343 session_write_close(); … … 349 347 * Destroy session data and remove cookie 350 348 */ 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'); 358 352 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 ) 368 362 ) { 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); 372 365 } 373 366 … … 378 371 ); 379 372 setcookie('sessauth', '-del-', time()-60); 373 $USER->reset(); 380 374 session_destroy(); 381 375 } 382 383 376 384 377 /** … … 389 382 * @uses rcube_registry::get_instance() 390 383 */ 391 static function get_table_name($table) 392 { 384 public static function get_table_name($table) { 393 385 $registry = rcube_registry::get_instance(); 394 386 $CONFIG = $registry->get_all('config'); … … 403 395 } 404 396 405 406 397 /** 407 398 * Return correct name for a specific database sequence … … 411 402 * @return string Translated sequence name 412 403 */ 413 static function get_sequence_name($sequence) 414 { 404 public static function get_sequence_name($sequence) { 415 405 $registry = rcube_registry::get_instance(); 416 406 … … 418 408 return $seq; 419 409 } 420 410 421 411 // return table name if not configured 422 412 return $table; … … 429 419 * environment vars according to the current session and configuration 430 420 */ 431 static function load_gui() 432 { 421 public static function load_gui() { 433 422 $registry = rcube_registry::get_instance(); 434 423 $config = $registry->get_all('config'); … … 449 438 // add some basic label to client 450 439 $OUTPUT->add_label('loading', 'movingmessage'); 451 440 452 441 $registry->set('OUTPUT', $OUTPUT, 'core'); 453 442 454 443 // set locale setting 455 444 self::set_locale($registry->get('user_lang', 'core')); 456 445 } 457 458 446 447 459 448 /** 460 449 * Create an output object for JSON responses 461 450 * and register it to the global registry 462 451 */ 463 static function init_json() 464 { 452 public static function init_json() { 465 453 $registry = rcube_registry::get_instance(); 466 454 467 455 $OUTPUT = new rcube_json_output(); 468 456 $registry->set('OUTPUT', $OUTPUT, 'core'); 469 457 470 458 // set locale setting 471 459 self::set_locale($registry->get('user_lang', 'core')); … … 473 461 474 462 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) { 478 469 $registry = rcube_registry::get_instance(); 479 470 $charset = $registry->get('charset', 'config', RCMAIL_CHARSET); … … 481 472 $MBSTRING = $registry->get('MBSTRING', 'core'); 482 473 $mbstring_loaded = $registry->get('mbstring_loaded', 'core'); 483 474 484 475 // settings for mbstring module (by Tadashi Jokagi) 485 476 if (is_null($mbstring_loaded)) { 486 $MBSTRING = $mbstring_loaded = extension_loaded("mbstring"); 487 } 488 else { 477 $MBSTRING = $mbstring_loaded = extension_loaded('mbstring'); 478 } else { 489 479 $MBSTRING = $mbstring_loaded = FALSE; 490 480 } … … 493 483 mb_internal_encoding($charset); 494 484 } 495 485 496 486 $registry->set('MBSTRING', $MBSTRING, 'core'); 497 487 $registry->set('mbstring_loaded', $mbstring_loaded, 'core'); 498 488 $registry->set('OUTPUT_CHARSET', $charset, 'core'); 499 500 489 $OUTPUT->set_charset($charset); 501 490 } … … 508 497 * @todo Remove reference to $_POST superglobal. 509 498 */ 510 static function autoselect_host() 511 { 499 public static function autoselect_host() { 512 500 $registry = rcube_registry::get_instance(); 513 501 $default_host = $registry->get('default_host', 'config'); … … 516 504 if (isset($_POST['_host']) && empty($_POST['_host']) === false) { 517 505 $host .= rcube::get_input_value('_host', rcube::INPUT_POST); 518 } 519 else { 506 } else { 520 507 $host .= $default_host; 521 508 } … … 550 537 * @return boolean True on success, False on failure 551 538 */ 552 static function login($user, $pass, $host=null) 553 { 539 public static function login($user = null, $pass = null, $host = null) { 554 540 $user_id = null; 555 541 … … 558 544 $IMAP = $registry->get('IMAP', 'core'); 559 545 $DB = $registry->get('DB', 'core'); 546 $USER = $registry->get('USER', 'core'); 560 547 $user_lang = $registry->get('user_lang', 'core'); 561 548 … … 578 565 return false; 579 566 } 580 } 581 else if (!empty($CONFIG['default_host']) && $host != $CONFIG['default_host']) { 567 } else if (!empty($CONFIG['default_host']) && $host != $CONFIG['default_host']) { 582 568 return false; 583 569 } … … 589 575 $imap_ssl = (isset($a_host['scheme']) && in_array($a_host['scheme'], array('ssl','imaps','tls'))) ? true : false; 590 576 $imap_port = isset($a_host['port']) ? $a_host['port'] : ($imap_ssl ? 993 : $CONFIG['default_port']); 591 } 592 else { 577 } else { 593 578 $imap_port = $CONFIG['default_port']; 594 579 } … … 613 598 // try to resolve email address from virtuser table 614 599 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 } 618 606 // 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; 632 609 } 633 610 // 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 } 639 615 // exit if IMAP login failed 640 616 if (!($imap_login = $IMAP->connect($host, $user, $pass, $imap_port, $imap_ssl))) { 641 return FALSE;617 return false; 642 618 } 643 619 // user already registered 644 if ($ user_id && !empty($sql_arr)) {620 if ($USER->ID) { 645 621 // 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']); 653 624 // 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']; 656 627 } 657 628 // 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 } 668 648 //tfk_debug('User id: ' . $user_id); 669 649 670 if (empty($user_id) === true) { 650 // login false if no user id 651 if (empty($USER->ID) === true) { 671 652 return false; 672 653 } 673 $_SESSION['user_id'] = $user_id; 654 655 $_SESSION['user_id'] = $USER->ID; 656 $_SESSION['username'] = $USER->data['username']; 674 657 $_SESSION['imap_host'] = $host; 675 658 $_SESSION['imap_port'] = $imap_port; 676 659 $_SESSION['imap_ssl'] = $imap_ssl; 677 $_SESSION['username'] = $user;678 660 $_SESSION['user_lang'] = $user_lang; 679 661 $_SESSION['password'] = self::encrypt_passwd($pass); … … 688 670 * @author Till Klampaeckel <till@php.net> 689 671 */ 690 if (is_array($CONFIG['smtp_server']) === true) {672 if (is_array($CONFIG['smtp_server']) === true) { 691 673 if (isset($CONFIG['smtp_server'][$host]) === true) { 692 674 $_SESSION['smtp_server'] = $CONFIG['smtp_server'][$host]; 693 } 694 else { 675 } else { 695 676 $_SESSION['smtp_server'] = 'phpMail'; 696 677 } 697 } 698 else { 678 } else { 699 679 if (empty($CONFIG['smtp_server']) === false) { 700 680 $_SESSION['smtp_server'] = $CONFIG['smtp_server']; 701 } 702 else { 681 } else { 703 682 $_SESSION['smtp_server'] = 'phpMail'; 704 683 } … … 708 687 self::set_imap_prop(); 709 688 $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 } 715 695 716 696 /** … … 721 701 * @return mixed New user ID or False on failure 722 702 */ 703 //TODO check this with rcube_user function 723 704 static function create_user($user, $host) 724 705 { … … 742 723 743 724 $_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']) 749 730 ); 750 731 rcube::tfk_debug($_query); … … 763 744 // try to resolve the e-mail address from the virtuser table 764 745 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) 768 749 ) { 769 750 while ($sql_arr = $DB->fetch_array($sql_result)) { … … 772 753 $_query.= " VALUES (?, 0, 1, ?, ?)"; 773 754 $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]) 778 759 ); 779 760 } … … 785 766 $_query.= " VALUES (?, 0, 1, ?, ?)"; 786 767 $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) 791 772 ); 792 773 } … … 797 778 else { 798 779 rcube_error::raise( 799 array(780 array( 800 781 'code' => 500, 801 782 'type' => 'php', … … 803 784 'file' => __FILE__, 804 785 'message' => "Failed to create new user" 805 ),806 TRUE,807 FALSE808 );786 ), 787 TRUE, 788 FALSE 789 ); 809 790 } 810 791 return $user_id; 811 792 } 812 813 793 814 794 /** … … 829 809 } 830 810 831 832 811 /** 833 812 * Find matches of the given pattern in virtuser table 834 * 813 * 835 814 * @param string Regular expression to search for 836 815 * @return array Matching entries … … 856 835 } 857 836 858 859 837 /** 860 838 * Resolve username using a virtuser table … … 863 841 * @return string Resolved IMAP username 864 842 */ 843 //TODO check this with rcube_user function 865 844 static function email2user($email) 866 845 { … … 879 858 } 880 859 881 882 860 /** 883 861 * Resolve e-mail address from virtuser table … … 886 864 * @return string Resolved e-mail address 887 865 */ 866 //TODO check this with rcube_user function 888 867 static function user2email($user) 889 868 { … … 902 881 } 903 882 904 905 883 /** 906 884 * Write the given user prefs to the user's record … … 909 887 * @return boolean True on success, False on failure 910 888 */ 889 //TODO check this with rcube_user function 911 890 static function save_user_prefs($a_user_prefs) 912 891 { … … 921 900 $_query.= " WHERE user_id=?"; 922 901 $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'] 927 906 ); 928 907 … … 930 909 $_SESSION['user_prefs'] = $a_user_prefs; 931 910 foreach ($a_user_prefs as $key => $value) 932 $registry->set($key, $value, 'config');911 $registry->set($key, $value, 'config'); 933 912 return true; 934 913 } … … 936 915 return false; 937 916 } 938 939 917 940 918 /** … … 950 928 $OUTPUT->set_env('action', $action); 951 929 } 952 953 930 954 931 /** … … 980 957 } 981 958 982 983 959 /** 984 960 * Encrypt IMAP password using DES encryption … … 1004 980 return preg_replace('/\x00/', '', $pass); 1005 981 } 1006 1007 982 1008 983 /** … … 1028 1003 } 1029 1004 1030 1031 1005 /** 1032 1006 * Garbage collector function for temp files. … … 1045 1019 while (($fname = readdir($dir)) !== false) { 1046 1020 if ($fname{0} == '.') 1047 continue;1021 continue; 1048 1022 1049 1023 if (filemtime($tmp.'/'.$fname) < $expire) 1050 @unlink($tmp.'/'.$fname);1024 @unlink($tmp.'/'.$fname); 1051 1025 } 1052 1026 closedir($dir); … … 1125 1099 // allow the following attributes to be added to the <table> tag 1126 1100 $attrib_str = rcube::create_attrib_string( 1127 $attrib,1128 array(1101 $attrib, 1102 array( 1129 1103 'style', 1130 1104 'class', … … 1134 1108 'border', 1135 1109 'summary' 1136 )1137 );1138 $table = '<table' . $attrib_str . ">\n";1139 1140 // add table title1141 $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( 1154 1128 '<tr id="rcmrow%d" class="contact '.$zebra_class.'">'."\n", 1155 $sql_arr[$id_col]1156 );1157 1158 // format each col1159 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( 1173 1147 '<tr id="rcmrow%d" class="contact '.$zebra_class.'">'."\n", 1174 $row_data[$id_col]1175 );1176 1177 // format each col1178 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/conditions1185 $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 table1200 $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; 1203 1177 } 1204 1178 … … 1206 1180 /** 1207 1181 * Create an edit field for inclusion on a form 1208 * 1182 * 1209 1183 * @param string col field name 1210 1184 * @param string value field value … … 1303 1277 1304 1278 $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'] 1309 1283 ); 1310 1284 $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'] 1315 1289 ); 1316 1290 1317 1291 // define date format depending on current time 1318 1292 if ( 1319 $CONFIG['prettydate']1320 && !$format1321 && $timestamp > $today_limit1322 && $timestamp < $now1293 $CONFIG['prettydate'] 1294 && !$format 1295 && $timestamp > $today_limit 1296 && $timestamp < $now 1323 1297 ) { 1324 1298 return sprintf( 1325 1299 '%s %s', 1326 rcube::gettext('today'),1327 date(1328 $CONFIG['date_today'] ? $CONFIG['date_today'] : 'H:i',1329 $timestamp1330 )1300 rcube::gettext('today'), 1301 date( 1302 $CONFIG['date_today'] ? $CONFIG['date_today'] : 'H:i', 1303 $timestamp 1304 ) 1331 1305 ); 1332 1306 } 1333 1307 elseif ( 1334 $CONFIG['prettydate']1335 && !$format1336 && $timestamp > $week_limit1337 && $timestamp < $now1308 $CONFIG['prettydate'] 1309 && !$format 1310 && $timestamp > $week_limit 1311 && $timestamp < $now 1338 1312 ) { 1339 1313 $format = $CONFIG['date_short'] ? $CONFIG['date_short'] : 'D H:i'; … … 1353 1327 if ($format{$i}==' ' || $format{$i-1}=='\\') { 1354 1328 $out .= $format{$i}; 1355 // weekday (short)1329 // weekday (short) 1356 1330 } 1357 1331 elseif ($format{$i}=='D') { 1358 1332 $out .= rcube::gettext(strtolower(date('D', $timestamp))); 1359 // weekday long1333 // weekday long 1360 1334 } 1361 1335 elseif ($format{$i}=='l') { 1362 1336 $out .= rcube::gettext(strtolower(date('l', $timestamp))); 1363 // month name (short)1337 // month name (short) 1364 1338 } 1365 1339 elseif ($format{$i}=='M') { 1366 1340 $out .= rcube::gettext(strtolower(date('M', $timestamp))); 1367 // month name (long)1341 // month name (long) 1368 1342 } 1369 1343 elseif ($format{$i}=='F') { … … 1394 1368 } 1395 1369 } 1396 1397 1398 1370 1371 1372 1399 1373 /** 1400 1374 * Check the given string and returns language properties … … 1453 1427 return $lang; 1454 1428 } 1455 1456 1429 1430 1457 1431 /** 1458 1432 * Read directory program/localization and return a list of available languages … … 1472 1446 while (($name = readdir($dh)) !== false) { 1473 1447 if ($name{0}=='.' || !is_dir(INSTALL_PATH . 'program/localization/' . $name)) 1474 continue;1448 continue; 1475 1449 1476 1450 if ($label = $rcube_languages[$name]) 1477 $localizations[$name] = $label ? $label : $name;1451 $localizations[$name] = $label ? $label : $name; 1478 1452 } 1479 1453 closedir($dh); … … 1483 1457 return $localizations; 1484 1458 } 1485 1486 1459 1460 1487 1461 /** 1488 1462 * Get localized text in the desired language … … 1494 1468 { 1495 1469 static $sa_text_data, $s_language, $utf8_decode; 1496 1470 1497 1471 $registry = rcube_registry::get_instance(); 1498 1472 $lang = $registry->get('user_lang', 'core'); … … 1525 1499 // include user language files 1526 1500 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) 1530 1504 ) { 1531 1505 include_once(INSTALL_PATH . 'program/localization/' . $lang . '/labels.inc'); … … 1545 1519 if (!($text_item = $sa_text_data[$alias])) { 1546 1520 /* 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 FALSE1557 );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 */ 1559 1533 /** 1560 1534 * We got as far - so let's see if $_SESSION contains what we are … … 1598 1572 // default text is single 1599 1573 if ($text=='') 1600 $text = $a_text_item['single'];1574 $text = $a_text_item['single']; 1601 1575 1602 1576 // replace vars in text … … 1623 1597 return $text; 1624 1598 } 1625 1626 1599 1600 1627 1601 /** 1628 1602 * Read input value and convert it for internal use … … 1667 1641 // strip slashes if magic_quotes enabled 1668 1642 if ((bool)get_magic_quotes_gpc()) 1669 $value = stripslashes($value);1643 $value = stripslashes($value); 1670 1644 1671 1645 // remove HTML tags if not allowed … … 1679 1653 return $value; 1680 1654 } 1681 1682 1655 1656 1683 1657 /** 1684 1658 * Read a specific HTTP request header … … 1703 1677 return null; 1704 1678 } 1705 1706 1679 1680 1707 1681 /** 1708 1682 * Convert a string from one charset to another. … … 1738 1712 // convert charset using iconv module 1739 1713 if (function_exists('iconv') && $from!='UTF-7' && $to!='UTF-7') 1740 return iconv($from, $to, $str);1714 return iconv($from, $to, $str); 1741 1715 1742 1716 $conv = new utf8(); … … 1783 1757 { 1784 1758 static $html_encode_arr, $js_rep_table, $xml_rep_table; 1785 1759 1786 1760 $out_charset = rcube_registry::get_instance()->get('OUTPUT_CHARSET', 'core'); 1787 1761 … … 1795 1769 "\r\n", 1796 1770 "\n", 1797 $mode=='remove' ? strip_tags($str) : $str1771 $mode=='remove' ? strip_tags($str) : $str 1798 1772 ); 1799 1773 } 1800 1774 1801 1775 // encode for HTML output 1802 1776 if ($enctype == 'html') { … … 1811 1785 // don't replace quotes and html tags 1812 1786 if ( 1813 ($mode == 'show' || $mode == '')1814 && $ltpos!==false1815 && strpos($str, '>', $ltpos)!==false1787 ($mode == 'show' || $mode == '') 1788 && $ltpos!==false 1789 && strpos($str, '>', $ltpos)!==false 1816 1790 ) { 1817 1791 unset($encode_arr['"']); … … 1827 1801 '/&([a-z]{2,5}|#[0-9]{2,4});/', 1828 1802 '&\\1;', 1829 strtr($str, $encode_arr)1803 strtr($str, $encode_arr) 1830 1804 ); 1831 1805 return $newlines ? nl2br($out) : $out; … … 1835 1809 return rawurlencode($str); 1836 1810 } 1837 1811 1838 1812 // if the replace tables for XML and JS are not yet defined 1839 1813 if (empty($js_rep_table)) { … … 1856 1830 return strtr($str, $xml_rep_table); 1857 1831 } 1858 1832 1859 1833 // encode for javascript use 1860 1834 if ($enctype == 'js') { … … 1863 1837 } 1864 1838 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)) 1868 1842 ); 1869 1843 } 1870 1844 1871 1845 // no encoding given -> return original string 1872 1846 return $str; 1873 1847 } 1874 1875 1848 1849 1876 1850 /** 1877 1851 * Compose a valid attribute string for HTML tags … … 1900 1874 preg_match_all( 1901 1875 '/\s*([-_a-z]+)=(["\'])([^"]+)\2/Ui', 1902 stripslashes($str),1903 $regs,1904 PREG_SET_ORDER1876 stripslashes($str), 1877 $regs, 1878 PREG_SET_ORDER 1905 1879 ); 1906 1880 … … 1913 1887 return $attrib; 1914 1888 } 1915 1916 1889 1890 1917 1891 /****** debugging functions ********/ 1918 1892 … … 1936 1910 } 1937 1911 } 1938 1912 1939 1913 1940 1914 /** … … 1982 1956 $log_entry = sprintf( 1983 1957 "[%s]: %s\n", 1984 date("d-M-Y H:i:s O", mktime()),1985 $line1958 date("d-M-Y H:i:s O", mktime()), 1959 $line 1986 1960 ); 1987 1961 … … 2016 1990 rcube::console(sprintf("%s: %0.4f sec", $label, $diff)); 2017 1991 } 2018 2019 1992 1993 2020 1994 } 2021 1995
Note: See TracChangeset
for help on using the changeset viewer.
