![]() |
Xataface 2.0
Xataface Application Framework
|
00001 <?php 00002 /*------------------------------------------------------------------------------- 00003 * Xataface Web Application Framework 00004 * Copyright (C) 2005-2008 Web Lite Solutions Corp (shannah@sfu.ca) 00005 * 00006 * This program is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU General Public License 00008 * as published by the Free Software Foundation; either version 2 00009 * of the License, or (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software 00018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00019 *------------------------------------------------------------------------------- 00020 */ 00030 if ( !defined('XATAFACE_INI_EXTENSION') ){ 00031 define('XATAFACE_INI_EXTENSION', ''); 00032 } 00033 //Prevent Magic Quotes from affecting scripts, regardless of server settings 00034 00035 //Make sure when reading file data, 00036 //PHP doesn't "magically" mangle backslashes! 00037 //set_magic_quotes_runtime(FALSE); 00038 ini_set('magic_quotes_runtime', false); 00039 if ( !function_exists('microtime_float') ){ 00040 function microtime_float() 00041 { 00042 list($usec, $sec) = explode(" ", microtime()); 00043 return ((float)$usec + (float)$sec); 00044 } 00045 } 00046 00047 function stripslashes_array($data) { 00048 if (is_array($data)){ 00049 foreach ($data as $key => $value){ 00050 $data[$key] = stripslashes_array($value); 00051 } 00052 return $data; 00053 }else{ 00054 return stripslashes($data); 00055 } 00056 } 00057 00058 if (get_magic_quotes_gpc()) { 00059 define('MAGIC_QUOTES_STRIPPED_SLASHES',1); 00060 /* 00061 All these global variables are slash-encoded by default, 00062 because magic_quotes_gpc is set by default! 00063 (And magic_quotes_gpc affects more than just $_GET, $_POST, and $_COOKIE) 00064 */ 00065 $_SERVER = stripslashes_array(@$_SERVER); 00066 $_GET = stripslashes_array(@$_GET); 00067 $_POST = stripslashes_array(@$_POST); 00068 $_COOKIE = stripslashes_array(@$_COOKIE); 00069 $_FILES = stripslashes_array(@$_FILES); 00070 $_ENV = stripslashes_array(@$_ENV); 00071 $_REQUEST = stripslashes_array(@$_REQUEST); 00072 $HTTP_SERVER_VARS = stripslashes_array(@$HTTP_SERVER_VARS); 00073 $HTTP_GET_VARS = stripslashes_array(@$HTTP_GET_VARS); 00074 $HTTP_POST_VARS = stripslashes_array(@$HTTP_POST_VARS); 00075 $HTTP_COOKIE_VARS = stripslashes_array(@$HTTP_COOKIE_VARS); 00076 $HTTP_POST_FILES = stripslashes_array(@$HTTP_POST_FILES); 00077 $HTTP_ENV_VARS = stripslashes_array(@$HTTP_ENV_VARS); 00078 if (isset($_SESSION)) { #These are unconfirmed (?) 00079 $_SESSION = stripslashes_array($_SESSION, ''); 00080 $HTTP_SESSION_VARS = stripslashes_array(@$HTTP_SESSION_VARS, ''); 00081 } 00082 /* 00083 The $GLOBALS array is also slash-encoded, but when all the above are 00084 changed, $GLOBALS is updated to reflect those changes. (Therefore 00085 $GLOBALS should never be modified directly). $GLOBALS also contains 00086 infinite recursion, so it's dangerous... 00087 */ 00088 } 00089 00090 00091 00092 00093 00094 00095 // first we resolve some differences between CGI and Module php 00096 if ( !isset( $_SERVER['QUERY_STRING'] ) ){ 00097 $_SERVER['QUERY_STRING'] = @$_ENV['QUERY_STRING']; 00098 } 00099 00100 // define a HOST_URI variable to contain the host portion of all urls 00101 $host = $_SERVER['HTTP_HOST']; 00102 $port = $_SERVER['SERVER_PORT']; 00103 $protocol = $_SERVER['SERVER_PROTOCOL']; 00104 if ( strtolower($protocol) == 'included' ){ 00105 $protocol = 'HTTP/1.0'; 00106 } 00107 $protocol = substr( $protocol, 0, strpos($protocol, '/')); 00108 $protocol = ((@$_SERVER['HTTPS'] == 'on' || $port == 443) ? $protocol.'s' : $protocol ); 00109 $protocol = strtolower($protocol); 00110 $_SERVER['HOST_URI'] = $protocol.'://'.$host;//.($port != 80 ? ':'.$port : ''); 00111 if ( (strpos($_SERVER['HTTP_HOST'], ':') === false) and !($protocol == 'https' and $port == 443 ) and !($protocol == 'http' and $port == 80) ){ 00112 $_SERVER['HOST_URI'] .= ':'.$port; 00113 } 00114 00115 if ( defined('DATAFACE_DEBUG') and DATAFACE_DEBUG){ 00116 /* 00117 * Debug with APD. 00118 */ 00119 apd_set_pprof_trace(); 00120 } 00121 00122 // Define a constant for use as quotes in INI files. 00123 // INI files can use quotes as follows: 00124 // key = "Quoted string: "_Q"I'm in quotes"_Q"." 00125 // I.e. just replace '"' with '"_Q"' (excluding single quotes). 00126 define('_Q', '"'); 00127 define('XATAFACEQ', _Q); 00128 00129 if ( !defined('DATAFACE_PATH') ){ 00130 // Path to the Dataface installation 00131 define('DATAFACE_PATH', str_replace('\\','/',dirname(__FILE__))); 00132 } 00133 if ( !defined('DATAFACE_URL') ){ 00134 // Webserver path to the Dataface installation 00135 define('DATAFACE_URL', str_replace('\\', '/', dirname($_SERVER['PHP_SELF']))); 00136 } 00137 if ( !defined('DATAFACE_FCKEDITOR_BASEPATH') ){ 00138 // Webserver path to the FCKEditor installation for use with Dataface 00139 define('DATAFACE_FCKEDITOR_BASEPATH', DATAFACE_URL.'/lib/FCKeditor/'); 00140 $GLOBALS['HTML_QuickForm_htmlarea']['FCKeditor_BasePath'] = DATAFACE_FCKEDITOR_BASEPATH; 00141 00142 00143 } 00144 $GLOBALS['HTML_QuickForm_htmlarea']['FCKeditor_BasePath'] = DATAFACE_FCKEDITOR_BASEPATH; 00145 00146 if ( !defined('DATAFACE_TINYMCE_BASEPATH') ){ 00147 define('DATAFACE_TINYMCE_BASEPATH', DATAFACE_URL.'/lib/tiny_mce'); 00148 00149 } 00150 $GLOBALS['HTML_QuickForm_htmlarea']['TinyMCE_BasePath'] = DATAFACE_TINYMCE_BASEPATH; 00151 00152 if ( !defined('DATAFACE_JSCALENDAR_BASEPATH') ){ 00153 define('DATAFACE_JSCALENDAR_BASEPATH', DATAFACE_URL.'/lib/jscalendar/'); 00154 } 00155 $GLOBALS['HTML_QuickForm_calendar']['jscalendar_BasePath'] = DATAFACE_JSCALENDAR_BASEPATH; 00156 00157 if ( !defined('DATAFACE_SITE_PATH') ){ 00158 // Path to the Site that is using Dataface. This may be different if than DATAFACE_PATH 00159 // if there are multiple sites being run on a single Dataface installation. 00160 define('DATAFACE_SITE_PATH', DATAFACE_PATH); 00161 } 00162 00163 00164 00165 if ( !defined('DATAFACE_SITE_URL') ){ 00166 // Webserver path to the current site. 00167 // This may be different than DATAFACE_URL if there are multiple sites being run on a single 00168 // dataface installation. 00169 define('DATAFACE_SITE_URL', DATAFACE_URL); 00170 define('DATAFACE_SITE_HREF', (DATAFACE_URL != '/' ? DATAFACE_URL.'/':'/').basename($_SERVER['PHP_SELF']) ); 00171 } 00172 00173 if ( !defined('DATAFACE_DEFAULT_CONFIG_STORAGE') ){ 00174 // The type of storage to use for application configuration by default. 00175 // Options include: ini or db. 00176 define('DATAFACE_DEFAULT_CONFIG_STORAGE', 'ini'); 00177 } 00178 00179 if ( !defined('DATAFACE_CACHE_PATH') ) { 00180 // Find teh cache directory to cache important stuff. 00181 if ( file_exists( DATAFACE_SITE_PATH.'/templates_c') ){ 00182 define('DATAFACE_CACHE_PATH', DATAFACE_SITE_PATH.'/templates_c/__cache'); 00183 } else { 00184 define('DATAFACE_CACHE_PATH', DATAFACE_PATH.'/Dataface/templates_c/__cache'); 00185 } 00186 } 00187 00188 if ( !defined('TRANSLATION_PAGE_TABLE') ){ 00189 // The name of the table that should be used to store temporary content that 00190 // is being translated by a machine translator in whole web page mode. 00191 define('TRANSLATION_PAGE_TABLE', '__pages_to_be_translated'); 00192 } 00193 00194 00195 //------------------------------------------------------------------------------------------ 00196 // Now we set the include path to include the necessary libraries in the lib directory. 00197 00198 $include_path = ini_get('include_path'); 00199 00200 00201 // If the current dir is currently first in the list, then it should remain that way 00202 if ( preg_match('/^\.'.PATH_SEPARATOR.'/', $include_path) ){ 00203 $include_path = preg_replace('/^\.'.PATH_SEPARATOR.'/','', $include_path); 00204 $curr_dir_first = true; 00205 } else { 00206 $curr_dir_first = false; 00207 } 00208 00209 $includePathArr = explode(PATH_SEPARATOR, $include_path); 00210 00211 if ( DATAFACE_SITE_PATH != DATAFACE_PATH and !in_array(DATAFACE_PATH,$includePathArr)){ 00212 $include_path = DATAFACE_PATH.PATH_SEPARATOR.DATAFACE_PATH.'/lib'.PATH_SEPARATOR.$include_path; 00213 } else if ( !in_array(DATAFACE_PATH.'/lib', $includePathArr)) { 00214 $include_path = DATAFACE_PATH.'/lib'.PATH_SEPARATOR.$include_path; 00215 } 00216 00217 if ( $curr_dir_first ){ 00218 $include_path = ".".PATH_SEPARATOR.$include_path; 00219 } 00220 00221 00222 ini_set('include_path', $include_path ); 00223 00224 //ini_set('display_errors', 'on'); 00225 00226 if ( !defined('DATAFACE_EXTENSION_LOADED_APC') ){ 00227 00228 define('DATAFACE_EXTENSION_LOADED_APC',extension_loaded('apc')); 00229 00230 } 00231 00232 if ( !defined('DATAFACE_EXTENSION_LOADED_MEMCACHE' ) ){ 00233 define('DATAFACE_EXTENSION_LOADED_MEMCACHE', extension_loaded('memcache')); 00234 } 00235 00236 00237 00238 00239 00240 function import($file){ 00241 00242 static $imports = 0; 00243 if ( !$imports ){ 00244 $imports = array(); 00245 } 00246 00247 //$class = str_replace('/','_', $file); 00248 //$class = substr($class, 0, strpos($class,'.')); 00249 if ( !isset($imports[$file]) ){ 00250 $imports[$file] = true; 00251 //error_log("importing ".$file); 00252 require_once $file; 00253 } 00254 } 00255 00256 00257 if ( !function_exists('sys_get_temp_dir') ) 00258 { 00259 // Based on http://www.phpit.net/ 00260 // article/creating-zip-tar-archives-dynamically-php/2/ 00261 function sys_get_temp_dir() 00262 { 00263 // Try to get from environment variable 00264 if ( !empty($_ENV['TMP']) ) 00265 { 00266 return realpath( $_ENV['TMP'] ); 00267 } 00268 else if ( !empty($_ENV['TMPDIR']) ) 00269 { 00270 return realpath( $_ENV['TMPDIR'] ); 00271 } 00272 else if ( !empty($_ENV['TEMP']) ) 00273 { 00274 return realpath( $_ENV['TEMP'] ); 00275 } 00276 00277 // Detect by creating a temporary file 00278 else 00279 { 00280 // Try to use system's temporary directory 00281 // as random name shouldn't exist 00282 $temp_file = tempnam( md5(uniqid(rand(), TRUE)), '' ); 00283 if ( $temp_file ) 00284 { 00285 $temp_dir = realpath( dirname($temp_file) ); 00286 unlink( $temp_file ); 00287 return $temp_dir; 00288 } 00289 else 00290 { 00291 return FALSE; 00292 } 00293 } 00294 } 00295 } 00296 00297 00298 require_once dirname(__FILE__).'/Dataface/Globals.php'; 00299