Thomas Bruederli
2013-10-21 f06aa8058b7e32ba32d4551074b6e0b8a300f751
commit | author | age
47124c 1 <?php
T 2
3 /*
4  +-----------------------------------------------------------------------+
197601 5  | program/include/iniset.php                                            |
47124c 6  |                                                                       |
e019f2 7  | This file is part of the Roundcube Webmail client                     |
7fe381 8  | Copyright (C) 2008-2012, The Roundcube Dev Team                       |
T 9  |                                                                       |
10  | Licensed under the GNU General Public License version 3 or            |
11  | any later version with exceptions for skins & plugins.                |
12  | See the README file for a full license statement.                     |
47124c 13  |                                                                       |
T 14  | PURPOSE:                                                              |
15  |   Setup the application envoronment required to process               |
16  |   any request.                                                        |
17  +-----------------------------------------------------------------------+
18  | Author: Till Klampaeckel <till@php.net>                               |
19  |         Thomas Bruederli <roundcube@gmail.com>                        |
20  +-----------------------------------------------------------------------+
21
af58c3 22  $Id$
47124c 23
T 24 */
25
7a259c 26 $config = array(
AM 27     'error_reporting'         => E_ALL &~ (E_NOTICE | E_STRICT),
28     // Some users are not using Installer, so we'll check some
29     // critical PHP settings here. Only these, which doesn't provide
30     // an error/warning in the logs later. See (#1486307).
31     'mbstring.func_overload'  => 0,
cd96fd 32     'suhosin.session.encrypt' => 0,
7a259c 33     'session.auto_start'      => 0,
AM 34     'file_uploads'            => 1,
35     'magic_quotes_runtime'    => 0,
36     'magic_quotes_sybase'     => 0, // #1488506
cd96fd 37 );
7a259c 38 foreach ($config as $optname => $optval) {
AM 39     if ($optval != ini_get($optname) && @ini_set($optname, $optval) === false) {
cd96fd 40         die("ERROR: Wrong '$optname' option value. Read REQUIREMENTS section in INSTALL file or use Roundcube Installer, please!");
A 41     }
42 }
47124c 43
T 44 // application constants
f06aa8 45 define('RCMAIL_VERSION', '0.8.7');
47124c 46 define('RCMAIL_CHARSET', 'UTF-8');
T 47 define('JS_OBJECT_NAME', 'rcmail');
2b35c5 48 define('RCMAIL_START', microtime(true));
47124c 49
T 50 if (!defined('INSTALL_PATH')) {
2eb794 51     define('INSTALL_PATH', dirname($_SERVER['SCRIPT_FILENAME']).'/');
47124c 52 }
T 53
4859fe 54 if (!defined('RCMAIL_CONFIG_DIR')) {
T 55     define('RCMAIL_CONFIG_DIR', INSTALL_PATH . 'config');
56 }
bba657 57
47124c 58 // make sure path_separator is defined
T 59 if (!defined('PATH_SEPARATOR')) {
2eb794 60     define('PATH_SEPARATOR', (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') ? ';' : ':');
47124c 61 }
T 62
63 // RC include folders MUST be included FIRST to avoid other
64 // possible not compatible libraries (i.e PEAR) to be included
65 // instead the ones provided by RC
926948 66 $include_path = INSTALL_PATH . 'program/lib' . PATH_SEPARATOR;
47124c 67 $include_path.= ini_get('include_path');
T 68
69 if (set_include_path($include_path) === false) {
e93c72 70     die("Fatal error: ini_set/set_include_path does not work.");
47124c 71 }
T 72
73 // increase maximum execution time for php scripts
74 // (does not work in safe mode)
6d479a 75 @set_time_limit(120);
47124c 76
d99b93 77 // set internal encoding for mbstring extension
5c4c06 78 if (extension_loaded('mbstring')) {
2eb794 79     mb_internal_encoding(RCMAIL_CHARSET);
5c4c06 80     @mb_regex_encoding(RCMAIL_CHARSET);
A 81 }
d99b93 82
47124c 83 /**
T 84  * Use PHP5 autoload for dynamic class loading
85  * 
86  * @todo Make Zend, PEAR etc play with this
b99bf4 87  * @todo Make our classes conform to a more straight forward CS.
47124c 88  */
588135 89 function rcube_autoload($classname)
47124c 90 {
2eb794 91     $filename = preg_replace(
A 92         array(
93             '/MDB2_(.+)/',
94             '/Mail_(.+)/',
95             '/Net_(.+)/',
e31afb 96             '/Auth_(.+)/',
2eb794 97             '/^html_.+/',
A 98             '/^utf8$/',
99         ),
100         array(
101             'MDB2/\\1',
102             'Mail/\\1',
103             'Net/\\1',
e31afb 104             'Auth/\\1',
2eb794 105             'html',
A 106             'utf8.class',
107         ),
108         $classname
109     );
965ed0 110
T 111     if ($fp = @fopen("$filename.php", 'r', true)) {
112         fclose($fp);
113         include_once("$filename.php");
114         return true;
115     }
116
117     return false;
47124c 118 }
T 119
588135 120 spl_autoload_register('rcube_autoload');
T 121
47124c 122 /**
T 123  * Local callback function for PEAR errors
124  */
125 function rcube_pear_error($err)
126 {
2eb794 127     error_log(sprintf("%s (%s): %s",
A 128         $err->getMessage(),
129         $err->getCode(),
130         $err->getUserinfo()), 0);
47124c 131 }
2eb794 132
A 133 // set PEAR error handling (will also load the PEAR main class)
134 PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, 'rcube_pear_error');
47124c 135
T 136 // include global functions
4351f7 137 require_once INSTALL_PATH . 'program/include/main.inc';
A 138 require_once INSTALL_PATH . 'program/include/rcube_shared.inc';