| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | |
|---|
| 25 | |
|---|
| 26 | |
|---|
| 27 | |
|---|
| 28 | |
|---|
| 29 | |
|---|
| 30 | |
|---|
| 31 | |
|---|
| 32 | |
|---|
| 33 | |
|---|
| 34 | |
|---|
| 35 | |
|---|
| 36 | |
|---|
| 37 | |
|---|
| 38 | |
|---|
| 39 | |
|---|
| 40 | |
|---|
| 41 | |
|---|
| 42 | |
|---|
| 43 | |
|---|
| 44 | |
|---|
| 45 | |
|---|
| 46 | |
|---|
| 47 | |
|---|
| 48 | |
|---|
| 49 | |
|---|
| 50 | |
|---|
| 51 | |
|---|
| 52 | function __cfthrow($_cfcatch){ |
|---|
| 53 | global $cfcatch; |
|---|
| 54 | $_cfcatch["detail"] = htmlspecialchars($_cfcatch["detail"]); |
|---|
| 55 | $cfcatch = $_cfcatch; |
|---|
| 56 | if ( isset($GLOBALS['_fba']->debug) && $GLOBALS['_fba']->debug && isset($GLOBALS['myFusebox']) ) { |
|---|
| 57 | $GLOBALS['myFusebox']->trace("Fusebox","Caught Fusebox exception '{$cfcatch['type']}'"); |
|---|
| 58 | } |
|---|
| 59 | die( (!@include($GLOBALS["FUSEBOX_APPLICATION_PATH"]."errortemplates/".$_cfcatch["type"].".php") ) ? $_cfcatch["detail"] : null ); |
|---|
| 60 | } |
|---|
| 61 | |
|---|
| 62 | function Location($URL, $addToken = 1) { |
|---|
| 63 | $questionORamp = (strstr($URL, "?"))?"&":"?"; |
|---|
| 64 | $location = ( $addToken && substr($URL, 0, 7) != "http://" && defined('SID') ) ? $URL.$questionORamp.SID : $URL; |
|---|
| 65 | |
|---|
| 66 | if(headers_sent()) { |
|---|
| 67 | print('<script type="text/javascript">( document.location.replace ) ? document.location.replace("'.$location.'") : document.location.href = "'.$location.'";</script>'."\n".'<noscript><meta http-equiv="Refresh" content="0;URL='.$location.'" /></noscript>'); |
|---|
| 68 | } else { |
|---|
| 69 | header('Location: '.$location); |
|---|
| 70 | exit; |
|---|
| 71 | } |
|---|
| 72 | } |
|---|
| 73 | function isPHP5() { |
|---|
| 74 | $thisversion = phpversion(); |
|---|
| 75 | return ( $thisversion{0} >= 5 ); |
|---|
| 76 | } |
|---|
| 77 | |
|---|
| 78 | if ( !isset($FUSEBOX_APPLICATION_PATH) ) $FUSEBOX_APPLICATION_PATH = ""; |
|---|
| 79 | if ( strlen($FUSEBOX_APPLICATION_PATH) > 0 && substr($FUSEBOX_APPLICATION_PATH, -1) != "/" ) { |
|---|
| 80 | $FUSEBOX_APPLICATION_PATH .= '/'; |
|---|
| 81 | } |
|---|
| 82 | |
|---|
| 83 | if ( !isset($FUSEBOX_APPLICATION_KEY) ) $FUSEBOX_APPLICATION_KEY = "fusebox"; |
|---|
| 84 | |
|---|
| 85 | |
|---|
| 86 | if ( !isset($FUSEBOX_APPLICATION_NAME) ) $FUSEBOX_APPLICATION_NAME = "cacheddata"; |
|---|
| 87 | |
|---|
| 88 | if( !isset($attributes) || !is_array($attributes) ) { |
|---|
| 89 | $attributes = array(); |
|---|
| 90 | $attributes = array_merge($_GET,$_POST); |
|---|
| 91 | } |
|---|
| 92 | |
|---|
| 93 | if ( isset( $_SERVER['QUERY_STRING']) and strlen($_SERVER['QUERY_STRING']) > 0 ) { |
|---|
| 94 | |
|---|
| 95 | $qs_array = split("[\&;]",$_SERVER['QUERY_STRING']); |
|---|
| 96 | for ( $i = 0 ; $i < count( $qs_array ) ; $i++ ) { |
|---|
| 97 | @list($thisname,$thisvalue) = explode("=",$qs_array[$i]); |
|---|
| 98 | if ( !isset($attributes[$thisname]) ) $attributes[$thisname] = $thisvalue; |
|---|
| 99 | } |
|---|
| 100 | } |
|---|
| 101 | |
|---|
| 102 | require_once("myFusebox.php"); |
|---|
| 103 | if ( !isPHP5() ) { eval('$myFusebox =& new MyFusebox($FUSEBOX_APPLICATION_KEY,$attributes);'); } else { $myFusebox = new MyFusebox($FUSEBOX_APPLICATION_KEY,$attributes); } |
|---|
| 104 | |
|---|
| 105 | if ( isset($FUSEBOX_APPLICATION_STARTUPTIME) ) $myFusebox->trace('Fusebox','Deserialized app_ datafile',$FUSEBOX_APPLICATION_STARTUPTIME); |
|---|
| 106 | |
|---|
| 107 | $myFusebox->applicationStart = false; |
|---|
| 108 | |
|---|
| 109 | $_REQUEST['__fusebox'] = array(); |
|---|
| 110 | |
|---|
| 111 | |
|---|
| 112 | |
|---|
| 113 | |
|---|
| 114 | |
|---|
| 115 | if ( !isset($application[$FUSEBOX_APPLICATION_KEY]) || $myFusebox->parameters['load'] ) { |
|---|
| 116 | $fa = @fopen($FUSEBOX_APPLICATION_PATH."parsed/_app_".$FUSEBOX_APPLICATION_NAME.".php","r") or |
|---|
| 117 | $fa = fopen($FUSEBOX_APPLICATION_PATH."parsed/_app_".$FUSEBOX_APPLICATION_NAME.".php","w"); |
|---|
| 118 | if(!flock($fa,LOCK_EX)){ |
|---|
| 119 | $myFusebox->trace("FuseboxError","Could not get exclusive lock to application data file"); |
|---|
| 120 | } |
|---|
| 121 | |
|---|
| 122 | if ( !isset($application[$FUSEBOX_APPLICATION_KEY]) || $myFusebox->parameters['load'] ) { |
|---|
| 123 | |
|---|
| 124 | if ( !isset($application[$FUSEBOX_APPLICATION_KEY]) || $myFusebox->parameters['userProvidedLoadParameter'] ) { |
|---|
| 125 | |
|---|
| 126 | $myFusebox->trace("Fusebox","Creating Fusebox application object"); |
|---|
| 127 | require_once("fuseboxApplication.php"); |
|---|
| 128 | if ( !isPHP5() ) { eval('$_fba =& new FuseboxApplication();'); } else { $_fba = new FuseboxApplication(); } |
|---|
| 129 | $application[$FUSEBOX_APPLICATION_KEY] = $_fba->init($FUSEBOX_APPLICATION_KEY,$FUSEBOX_APPLICATION_PATH,$FUSEBOX_APPLICATION_NAME,$myFusebox); |
|---|
| 130 | |
|---|
| 131 | } else { |
|---|
| 132 | |
|---|
| 133 | $myFusebox->trace("Fusebox","Reloading Fusebox application object"); |
|---|
| 134 | @include($FUSEBOX_APPLICATION_PATH."parsed/_app_".$FUSEBOX_APPLICATION_NAME.".php"); |
|---|
| 135 | $_fba =& $application[$FUSEBOX_APPLICATION_KEY]; |
|---|
| 136 | |
|---|
| 137 | $_fba->reload($FUSEBOX_APPLICATION_KEY,$FUSEBOX_APPLICATION_PATH,$myFusebox); |
|---|
| 138 | } |
|---|
| 139 | |
|---|
| 140 | if ( $_fba->precedenceFormOrURL == "URL" ) { |
|---|
| 141 | $attributes = array_merge($_POST,$_GET); |
|---|
| 142 | } |
|---|
| 143 | |
|---|
| 144 | if ( !array_key_exists($_fba->fuseactionVariable,$attributes) || $attributes[$_fba->fuseactionVariable] == "" ) { |
|---|
| 145 | $attributes[$_fba->fuseactionVariable] = $_fba->defaultFuseaction; |
|---|
| 146 | } |
|---|
| 147 | |
|---|
| 148 | $attributes['fuseaction'] = $attributes[$_fba->fuseactionVariable]; |
|---|
| 149 | |
|---|
| 150 | $myFusebox->applicationStart = true; |
|---|
| 151 | |
|---|
| 152 | if ( $_fba->mode != "production" || $myFusebox->parameters['userProvidedLoadParameter'] ) { |
|---|
| 153 | $myFusebox->parameters['parse'] = true; |
|---|
| 154 | } |
|---|
| 155 | |
|---|
| 156 | |
|---|
| 157 | if ( $myFusebox->parameters['parseall'] ) { |
|---|
| 158 | $_fba->compileAll($myFusebox); |
|---|
| 159 | } |
|---|
| 160 | |
|---|
| 161 | if ( $_fba->debug ) { |
|---|
| 162 | $myFusebox->trace("Fusebox","Including fusebox.appinit.php"); |
|---|
| 163 | } |
|---|
| 164 | if ( file_exists($_fba->getWebRootPathToappRoot()."fusebox.appinit.php") ) { |
|---|
| 165 | include($_fba->getWebRootPathToappRoot()."fusebox.appinit.php"); |
|---|
| 166 | } |
|---|
| 167 | } else { |
|---|
| 168 | $_fba =& $application[$FUSEBOX_APPLICATION_KEY]; |
|---|
| 169 | |
|---|
| 170 | if ( $_fba->precedenceFormOrURL == "URL" ) { |
|---|
| 171 | $attributes = array_merge($_POST,$_GET); |
|---|
| 172 | } |
|---|
| 173 | |
|---|
| 174 | if ( !array_key_exists($_fba->fuseactionVariable,$attributes) || $attributes[$_fba->fuseactionVariable] == "" ) { |
|---|
| 175 | $attributes[$_fba->fuseactionVariable] = $_fba->defaultFuseaction; |
|---|
| 176 | } |
|---|
| 177 | $attributes['fuseaction'] = $attributes[$_fba->fuseactionVariable]; |
|---|
| 178 | } |
|---|
| 179 | @flock($fa,LOCK_UN); |
|---|
| 180 | fclose($fa); |
|---|
| 181 | } else { |
|---|
| 182 | $_fba =& $application[$FUSEBOX_APPLICATION_KEY]; |
|---|
| 183 | |
|---|
| 184 | if ( $_fba->precedenceFormOrURL == "URL" ) { |
|---|
| 185 | $attributes = array_merge($_POST,$_GET); |
|---|
| 186 | } |
|---|
| 187 | |
|---|
| 188 | if ( !array_key_exists($_fba->fuseactionVariable,$attributes) || $attributes[$_fba->fuseactionVariable] == "" ) { |
|---|
| 189 | $attributes[$_fba->fuseactionVariable] = $_fba->defaultFuseaction; |
|---|
| 190 | } |
|---|
| 191 | $attributes['fuseaction'] = $attributes[$_fba->fuseactionVariable]; |
|---|
| 192 | } |
|---|
| 193 | |
|---|
| 194 | |
|---|
| 195 | |
|---|
| 196 | |
|---|
| 197 | |
|---|
| 198 | |
|---|
| 199 | |
|---|
| 200 | |
|---|
| 201 | |
|---|
| 202 | |
|---|
| 203 | |
|---|
| 204 | |
|---|
| 205 | if ( $_fba->debug ) { |
|---|
| 206 | $myFusebox->trace("Fusebox","Including fusebox.init.php"); |
|---|
| 207 | } |
|---|
| 208 | if ( file_exists($_fba->getWebRootPathToappRoot()."fusebox.init.php") ) { |
|---|
| 209 | $_fba_attr_fav = $attributes[$_fba->fuseactionVariable]; |
|---|
| 210 | $_fba_attr_fa = $attributes['fuseaction']; |
|---|
| 211 | include($_fba->getWebRootPathToappRoot()."fusebox.init.php"); |
|---|
| 212 | if ( $attributes['fuseaction'] != $_fba_attr_fa ) { |
|---|
| 213 | if ( $attributes['fuseaction'] != $attributes[$_fba->fuseactionVariable] ) { |
|---|
| 214 | if ( $attributes[$_fba->fuseactionVariable] != $_fba_attr_fav ) { |
|---|
| 215 | |
|---|
| 216 | __cfthrow(array( 'type'=>"fusebox.inconsistentFuseaction", |
|---|
| 217 | 'message'=>"Inconsistent fuseaction variables", |
|---|
| 218 | 'detail'=>"Both attributes.fuseaction and attributes[{fusebox}.fuseactionVariable] changed in fusebox.init.php so Fusebox doesn't know what to do with the values!" |
|---|
| 219 | )); |
|---|
| 220 | } else { |
|---|
| 221 | |
|---|
| 222 | $attributes[$_fba->fuseactionVariable] = $attributes['fuseaction']; |
|---|
| 223 | } |
|---|
| 224 | } else { |
|---|
| 225 | |
|---|
| 226 | } |
|---|
| 227 | } else { |
|---|
| 228 | |
|---|
| 229 | if ( $attributes[$_fba->fuseactionVariable] != $_fba_attr_fav ) { |
|---|
| 230 | |
|---|
| 231 | $attributes['fuseaction'] = $attributes[$_fba->fuseactionVariable]; |
|---|
| 232 | } else { |
|---|
| 233 | |
|---|
| 234 | } |
|---|
| 235 | } |
|---|
| 236 | } |
|---|
| 237 | |
|---|
| 238 | |
|---|
| 239 | |
|---|
| 240 | |
|---|
| 241 | |
|---|
| 242 | |
|---|
| 243 | if ( !$myFusebox->parameters['load'] && ( $myFusebox->parameters['parse'] || !file_exists($_fba->approotdirectory."parsed/".strtolower($attributes['fuseaction']).".php" ) ) ) { |
|---|
| 244 | if ( $_fba->debug ) $myFusebox->trace("Fusebox","Replacing slim AFB object with full copy"); |
|---|
| 245 | include($FUSEBOX_APPLICATION_PATH."parsed/_app_".$FUSEBOX_APPLICATION_NAME.".php"); |
|---|
| 246 | unset($_fba); |
|---|
| 247 | $_fba =& $application[$FUSEBOX_APPLICATION_KEY]; |
|---|
| 248 | } |
|---|
| 249 | |
|---|
| 250 | |
|---|
| 251 | |
|---|
| 252 | |
|---|
| 253 | |
|---|
| 254 | if ( $_fba->debug ) { |
|---|
| 255 | $myFusebox->trace("Fusebox","Compiling requested fuseaction '{$attributes['fuseaction']}'"); |
|---|
| 256 | } |
|---|
| 257 | if ( $_fba->mode == "development-circuit-load" ) { |
|---|
| 258 | $fa = fopen($FUSEBOX_APPLICATION_PATH."parsed/_app_".$FUSEBOX_APPLICATION_NAME.".php","r"); |
|---|
| 259 | if(!flock($fa,LOCK_EX)){ |
|---|
| 260 | $myFusebox->trace("FuseboxError","Could not get exclusive lock to application data file"); |
|---|
| 261 | } |
|---|
| 262 | $_parsedFileData = $_fba->compileRequest($attributes['fuseaction'],$myFusebox); |
|---|
| 263 | @flock($fa,LOCK_UN); |
|---|
| 264 | fclose($fa); |
|---|
| 265 | } else { |
|---|
| 266 | $fa = fopen($FUSEBOX_APPLICATION_PATH."parsed/_app_".$FUSEBOX_APPLICATION_NAME.".php","r"); |
|---|
| 267 | if ( !flock($fa,LOCK_SH) ) { |
|---|
| 268 | $myFusebox->trace("FuseboxError","Could not get exclusive lock to application data file"); |
|---|
| 269 | } |
|---|
| 270 | $_parsedFileData = $_fba->compileRequest($attributes['fuseaction'],$myFusebox); |
|---|
| 271 | @flock($fa,LOCK_UN); |
|---|
| 272 | fclose($fa); |
|---|
| 273 | |
|---|
| 274 | } |
|---|
| 275 | |
|---|
| 276 | |
|---|
| 277 | |
|---|
| 278 | |
|---|
| 279 | if ( $myFusebox->parameters['execute'] ) { |
|---|
| 280 | if ( $_fba->debug ) { |
|---|
| 281 | $myFusebox->trace("Fusebox","Including parsed file for '{$attributes['fuseaction']}'"); |
|---|
| 282 | } |
|---|
| 283 | if ( file_exists($_parsedFileData['lockName']) ) { |
|---|
| 284 | $fp = fopen($_parsedFileData['lockName'],'r'); |
|---|
| 285 | if ( !flock($fp,LOCK_SH) ) { |
|---|
| 286 | $myFusebox->trace("FuseboxError","Could not get exclusive lock to parsed fuseaction file"); |
|---|
| 287 | } |
|---|
| 288 | include($_parsedFileData['parsedFile']); |
|---|
| 289 | @flock($fp,LOCK_UN); |
|---|
| 290 | fclose($fp); |
|---|
| 291 | } else { |
|---|
| 292 | __cfthrow(array( 'type'=>"fusebox.missingParsedFile", |
|---|
| 293 | 'message'=>"Parsed File or Directory not found.", |
|---|
| 294 | 'detail'=>"fusebox5.php line 269: Attempting to execute the parsed file '{$_parsedFileData['parsedName']}' threw an error. This can occur if the parsed file does not exist in the parsed directory or if the parsed directory itself is missing." |
|---|
| 295 | )); |
|---|
| 296 | } |
|---|
| 297 | } |
|---|
| 298 | |
|---|
| 299 | |
|---|
| 300 | if ( $myFusebox->parameters['load'] ) { |
|---|
| 301 | if ( $_fba->debug ) $myFusebox->trace("Fusebox","Saving app data file..."); |
|---|
| 302 | $_fba->writeFullObjectToDisk(); |
|---|
| 303 | $_fba->writeSlimObjectToDisk(); |
|---|
| 304 | } |
|---|
| 305 | |
|---|
| 306 | $myFusebox->trace("Fusebox","Request completed"); |
|---|
| 307 | if ( isset($_fba->debug) && $_fba->debug == "true" && isset($myFusebox) ) { |
|---|
| 308 | echo $myFusebox->renderTrace(); |
|---|
| 309 | } |
|---|
| 310 | ?> |
|---|