]> git.donarmstrong.com Git - roundcube.git/blob - program/include/iniset.php
Imported Upstream version 0.3
[roundcube.git] / program / include / iniset.php
1 <?php
2
3 /*
4  +-----------------------------------------------------------------------+
5  | program/include/iniset.php                                            |
6  |                                                                       |
7  | This file is part of the RoundCube Webmail client                     |
8  | Copyright (C) 2008-2009, RoundCube Dev, - Switzerland                 |
9  | Licensed under the GNU GPL                                            |
10  |                                                                       |
11  | PURPOSE:                                                              |
12  |   Setup the application envoronment required to process               |
13  |   any request.                                                        |
14  +-----------------------------------------------------------------------+
15  | Author: Till Klampaeckel <till@php.net>                               |
16  |         Thomas Bruederli <roundcube@gmail.com>                        |
17  +-----------------------------------------------------------------------+
18
19  $Id: iniset.php 2916 2009-09-04 10:58:29Z thomasb $
20
21 */
22
23
24 // application constants
25 define('RCMAIL_VERSION', '0.3-stable');
26 define('RCMAIL_CHARSET', 'UTF-8');
27 define('JS_OBJECT_NAME', 'rcmail');
28
29 if (!defined('INSTALL_PATH')) {
30   define('INSTALL_PATH', dirname($_SERVER['SCRIPT_FILENAME']).'/');
31 }
32
33 define('RCMAIL_CONFIG_DIR', INSTALL_PATH . 'config');
34
35 // make sure path_separator is defined
36 if (!defined('PATH_SEPARATOR')) {
37   define('PATH_SEPARATOR', (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') ? ';' : ':');
38 }
39
40 // RC include folders MUST be included FIRST to avoid other
41 // possible not compatible libraries (i.e PEAR) to be included
42 // instead the ones provided by RC
43 $include_path = INSTALL_PATH . PATH_SEPARATOR;
44 $include_path.= INSTALL_PATH . 'program' . PATH_SEPARATOR;
45 $include_path.= INSTALL_PATH . 'program/lib' . PATH_SEPARATOR;
46 $include_path.= INSTALL_PATH . 'program/include' . PATH_SEPARATOR;
47 $include_path.= ini_get('include_path');
48
49 if (set_include_path($include_path) === false) {
50   die('Fatal error: ini_set/set_include_path does not work.');
51 }
52
53 ini_set('error_reporting', E_ALL&~E_NOTICE);
54 if  (isset($_SERVER['HTTPS'])) {
55    ini_set('session.cookie_secure', ($_SERVER['HTTPS'] && ($_SERVER['HTTPS'] != 'off'))?1:0);
56 } else {
57    ini_set('session.cookie_secure', 0);
58 }
59 ini_set('session.name', 'roundcube_sessid');
60 ini_set('session.use_cookies', 1);
61 ini_set('session.use_only_cookies', 1);
62 if (function_exists('set_magic_quotes_runtime')) {
63   set_magic_quotes_runtime(0);
64 }
65
66 // increase maximum execution time for php scripts
67 // (does not work in safe mode)
68 if (!ini_get('safe_mode')) {
69   set_time_limit(120);
70 }
71
72 // set internal encoding for mbstring extension
73 if(extension_loaded('mbstring'))
74   mb_internal_encoding(RCMAIL_CHARSET);
75               
76
77 /**
78  * Use PHP5 autoload for dynamic class loading
79  * 
80  * @todo Make Zend, PEAR etc play with this
81  * @todo Make our classes conform to a more straight forward CS.
82  */
83 function rcube_autoload($classname)
84 {
85   $filename = preg_replace(
86       array(
87         '/MDB2_(.+)/',
88         '/Mail_(.+)/',
89         '/Net_(.+)/',
90         '/^html_.+/',
91         '/^utf8$/',
92         '/html2text/'
93       ),
94       array(
95         'MDB2/\\1',
96         'Mail/\\1',
97         'Net/\\1',
98         'html',
99         'utf8.class',
100         'lib/html2text'  // see #1485505
101       ),
102       $classname
103   );
104   include $filename. '.php';
105 }
106
107 spl_autoload_register('rcube_autoload');
108
109 /**
110  * Local callback function for PEAR errors
111  */
112 function rcube_pear_error($err)
113 {
114   error_log(sprintf("%s (%s): %s",
115     $err->getMessage(),
116     $err->getCode(),
117     $err->getUserinfo()), 0);
118 }
119
120 // include global functions
121 require_once 'include/bugs.inc';
122 require_once 'include/main.inc';
123 require_once 'include/rcube_shared.inc';
124
125
126 // set PEAR error handling (will also load the PEAR main class)
127 PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, 'rcube_pear_error');