Xataface  2.0alpha2
Xataface Application Framework
 All Data Structures Namespaces Files Functions Variables Groups Pages
config.inc.php
Go to the documentation of this file.
1 <?php
2 /*-------------------------------------------------------------------------------
3  * Xataface Web Application Framework
4  * Copyright (C) 2005-2008 Web Lite Solutions Corp (shannah@sfu.ca)
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  *-------------------------------------------------------------------------------
20  */
30 if ( !defined('XATAFACE_INI_EXTENSION') ){
31  define('XATAFACE_INI_EXTENSION', '');
32 }
33 //Prevent Magic Quotes from affecting scripts, regardless of server settings
34 
35 //Make sure when reading file data,
36 //PHP doesn't "magically" mangle backslashes!
37 //set_magic_quotes_runtime(FALSE);
38 ini_set('magic_quotes_runtime', false);
39 if ( !function_exists('microtime_float') ){
40  function microtime_float()
41  {
42  list($usec, $sec) = explode(" ", microtime());
43  return ((float)$usec + (float)$sec);
44  }
45 }
46 
47 function stripslashes_array($data) {
48  if (is_array($data)){
49  foreach ($data as $key => $value){
50  $data[$key] = stripslashes_array($value);
51  }
52  return $data;
53  }else{
54  return stripslashes($data);
55  }
56 }
57 
58 if (get_magic_quotes_gpc()) {
59  define('MAGIC_QUOTES_STRIPPED_SLASHES',1);
60  /*
61  All these global variables are slash-encoded by default,
62  because magic_quotes_gpc is set by default!
63  (And magic_quotes_gpc affects more than just $_GET, $_POST, and $_COOKIE)
64  */
66  $_GET = stripslashes_array(@$_GET);
67  $_POST = stripslashes_array(@$_POST);
68  $_COOKIE = stripslashes_array(@$_COOKIE);
69  $_FILES = stripslashes_array(@$_FILES);
70  $_ENV = stripslashes_array(@$_ENV);
71  $_REQUEST = stripslashes_array(@$_REQUEST);
72  $HTTP_SERVER_VARS = stripslashes_array(@$HTTP_SERVER_VARS);
73  $HTTP_GET_VARS = stripslashes_array(@$HTTP_GET_VARS);
74  $HTTP_POST_VARS = stripslashes_array(@$HTTP_POST_VARS);
75  $HTTP_COOKIE_VARS = stripslashes_array(@$HTTP_COOKIE_VARS);
76  $HTTP_POST_FILES = stripslashes_array(@$HTTP_POST_FILES);
77  $HTTP_ENV_VARS = stripslashes_array(@$HTTP_ENV_VARS);
78  if (isset($_SESSION)) { #These are unconfirmed (?)
79  $_SESSION = stripslashes_array($_SESSION, '');
80  $HTTP_SESSION_VARS = stripslashes_array(@$HTTP_SESSION_VARS, '');
81  }
82  /*
83  The $GLOBALS array is also slash-encoded, but when all the above are
84  changed, $GLOBALS is updated to reflect those changes. (Therefore
85  $GLOBALS should never be modified directly). $GLOBALS also contains
86  infinite recursion, so it's dangerous...
87  */
88 }
89 
90 
91 
92 
93 
94 
95 // first we resolve some differences between CGI and Module php
96 if ( !isset( $_SERVER['QUERY_STRING'] ) ){
97  $_SERVER['QUERY_STRING'] = @$_ENV['QUERY_STRING'];
98 }
99 
100 // define a HOST_URI variable to contain the host portion of all urls
101 $host = $_SERVER['HTTP_HOST'];
102 $port = $_SERVER['SERVER_PORT'];
103 $protocol = $_SERVER['SERVER_PROTOCOL'];
104 if ( strtolower($protocol) == 'included' ){
105  $protocol = 'HTTP/1.0';
106 }
107 $protocol = substr( $protocol, 0, strpos($protocol, '/'));
108 $protocol = ((@$_SERVER['HTTPS'] == 'on' || $port == 443) ? $protocol.'s' : $protocol );
109 $protocol = strtolower($protocol);
110 $_SERVER['HOST_URI'] = $protocol.'://'.$host;//.($port != 80 ? ':'.$port : '');
111 if ( (strpos($_SERVER['HTTP_HOST'], ':') === false) and !($protocol == 'https' and $port == 443 ) and !($protocol == 'http' and $port == 80) ){
112  $_SERVER['HOST_URI'] .= ':'.$port;
113 }
114 
115 if ( defined('DATAFACE_DEBUG') and DATAFACE_DEBUG){
116  /*
117  * Debug with APD.
118  */
119  apd_set_pprof_trace();
120 }
121 
122 // Define a constant for use as quotes in INI files.
123 // INI files can use quotes as follows:
124 // key = "Quoted string: "_Q"I'm in quotes"_Q"."
125 // I.e. just replace '"' with '"_Q"' (excluding single quotes).
126 define('_Q', '"');
127 define('XATAFACEQ', _Q);
128 
129 if ( !defined('DATAFACE_PATH') ){
130  // Path to the Dataface installation
131  define('DATAFACE_PATH', str_replace('\\','/',dirname(__FILE__)));
132 }
133 if ( !defined('DATAFACE_URL') ){
134  // Webserver path to the Dataface installation
135  define('DATAFACE_URL', str_replace('\\', '/', dirname($_SERVER['PHP_SELF'])));
136 }
137 if ( !defined('DATAFACE_FCKEDITOR_BASEPATH') ){
138  // Webserver path to the FCKEditor installation for use with Dataface
139  define('DATAFACE_FCKEDITOR_BASEPATH', DATAFACE_URL.'/lib/FCKeditor/');
140  $GLOBALS['HTML_QuickForm_htmlarea']['FCKeditor_BasePath'] = DATAFACE_FCKEDITOR_BASEPATH;
141 
142 
143 }
144 $GLOBALS['HTML_QuickForm_htmlarea']['FCKeditor_BasePath'] = DATAFACE_FCKEDITOR_BASEPATH;
145 
146 if ( !defined('DATAFACE_TINYMCE_BASEPATH') ){
147  define('DATAFACE_TINYMCE_BASEPATH', DATAFACE_URL.'/lib/tiny_mce');
148 
149 }
150 $GLOBALS['HTML_QuickForm_htmlarea']['TinyMCE_BasePath'] = DATAFACE_TINYMCE_BASEPATH;
151 
152 if ( !defined('DATAFACE_JSCALENDAR_BASEPATH') ){
153  define('DATAFACE_JSCALENDAR_BASEPATH', DATAFACE_URL.'/lib/jscalendar/');
154 }
155 $GLOBALS['HTML_QuickForm_calendar']['jscalendar_BasePath'] = DATAFACE_JSCALENDAR_BASEPATH;
156 
157 if ( !defined('DATAFACE_SITE_PATH') ){
158  // Path to the Site that is using Dataface. This may be different if than DATAFACE_PATH
159  // if there are multiple sites being run on a single Dataface installation.
160  define('DATAFACE_SITE_PATH', DATAFACE_PATH);
161 }
162 
163 
164 
165 if ( !defined('DATAFACE_SITE_URL') ){
166  // Webserver path to the current site.
167  // This may be different than DATAFACE_URL if there are multiple sites being run on a single
168  // dataface installation.
169  define('DATAFACE_SITE_URL', DATAFACE_URL);
170  define('DATAFACE_SITE_HREF', (DATAFACE_URL != '/' ? DATAFACE_URL.'/':'/').basename($_SERVER['PHP_SELF']) );
171 }
172 
173 if ( !defined('DATAFACE_DEFAULT_CONFIG_STORAGE') ){
174  // The type of storage to use for application configuration by default.
175  // Options include: ini or db.
176  define('DATAFACE_DEFAULT_CONFIG_STORAGE', 'ini');
177 }
178 
179 if ( !defined('DATAFACE_CACHE_PATH') ) {
180  // Find teh cache directory to cache important stuff.
181  if ( file_exists( DATAFACE_SITE_PATH.'/templates_c') ){
182  define('DATAFACE_CACHE_PATH', DATAFACE_SITE_PATH.'/templates_c/__cache');
183  } else {
184  define('DATAFACE_CACHE_PATH', DATAFACE_PATH.'/Dataface/templates_c/__cache');
185  }
186 }
187 
188 if ( !defined('TRANSLATION_PAGE_TABLE') ){
189  // The name of the table that should be used to store temporary content that
190  // is being translated by a machine translator in whole web page mode.
191  define('TRANSLATION_PAGE_TABLE', '__pages_to_be_translated');
192 }
193 
194 
195 //------------------------------------------------------------------------------------------
196 // Now we set the include path to include the necessary libraries in the lib directory.
197 
198 $include_path = ini_get('include_path');
199 
200 
201 // If the current dir is currently first in the list, then it should remain that way
202 if ( preg_match('/^\.'.PATH_SEPARATOR.'/', $include_path) ){
203  $include_path = preg_replace('/^\.'.PATH_SEPARATOR.'/','', $include_path);
204  $curr_dir_first = true;
205 } else {
206  $curr_dir_first = false;
207 }
208 
209 $includePathArr = explode(PATH_SEPARATOR, $include_path);
210 
211 if ( DATAFACE_SITE_PATH != DATAFACE_PATH and !in_array(DATAFACE_PATH,$includePathArr)){
212  $include_path = DATAFACE_PATH.PATH_SEPARATOR.DATAFACE_PATH.'/lib'.PATH_SEPARATOR.$include_path;
213 } else if ( !in_array(DATAFACE_PATH.'/lib', $includePathArr)) {
214  $include_path = DATAFACE_PATH.'/lib'.PATH_SEPARATOR.$include_path;
215 }
216 
217 if ( $curr_dir_first ){
218  $include_path = ".".PATH_SEPARATOR.$include_path;
219 }
220 
221 
222 set_include_path($include_path );
223 
224 //ini_set('display_errors', 'on');
225 
226 if ( !defined('DATAFACE_EXTENSION_LOADED_APC') ){
227 
228  define('DATAFACE_EXTENSION_LOADED_APC',extension_loaded('apc'));
229 
230 }
231 
232 if ( !defined('DATAFACE_EXTENSION_LOADED_MEMCACHE' ) ){
233  define('DATAFACE_EXTENSION_LOADED_MEMCACHE', extension_loaded('memcache'));
234 }
235 
236 
237 
238 
239 
240 function import($file){
241 
242  static $imports = 0;
243  if ( !$imports ){
244  $imports = array();
245  }
246 
247  //$class = str_replace('/','_', $file);
248  //$class = substr($class, 0, strpos($class,'.'));
249  if ( !isset($imports[$file]) ){
250  $imports[$file] = true;
251  //error_log("importing ".$file);
252  require_once $file;
253  }
254 }
255 
256 
257 if ( !function_exists('sys_get_temp_dir') )
258 {
259  // Based on http://www.phpit.net/
260  // article/creating-zip-tar-archives-dynamically-php/2/
261  function sys_get_temp_dir()
262  {
263  // Try to get from environment variable
264  if ( !empty($_ENV['TMP']) )
265  {
266  return realpath( $_ENV['TMP'] );
267  }
268  else if ( !empty($_ENV['TMPDIR']) )
269  {
270  return realpath( $_ENV['TMPDIR'] );
271  }
272  else if ( !empty($_ENV['TEMP']) )
273  {
274  return realpath( $_ENV['TEMP'] );
275  }
276 
277  // Detect by creating a temporary file
278  else
279  {
280  // Try to use system's temporary directory
281  // as random name shouldn't exist
282  $temp_file = tempnam( md5(uniqid(rand(), TRUE)), '' );
283  if ( $temp_file )
284  {
285  $temp_dir = realpath( dirname($temp_file) );
286  unlink( $temp_file );
287  return $temp_dir;
288  }
289  else
290  {
291  return FALSE;
292  }
293  }
294  }
295 }
296 
297 
298 require_once dirname(__FILE__).'/Dataface/Globals.php';
299