00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053 define( "EZ_SYS_DEBUG_INTERNALS", false );
00054
00055 define( 'EZSSLZONE_DEFAULT_SSL_PORT', 443 );
00056
00057 class eZSys
00058 {
00059
00060
00061
00062 function eZSys()
00063 {
00064 $this->Attributes = array( "magickQuotes" => true,
00065 "hostname" => true );
00066
00067 $uname = php_uname();
00068 if ( substr( $uname, 0, 7 ) == "Windows" )
00069 {
00070 $this->OSType = "win32";
00071 $this->OS = "windows";
00072 $this->FileSystemType = "win32";
00073 $this->FileSeparator = "\\";
00074 $this->LineSeparator= "\r\n";
00075 $this->EnvSeparator = ";";
00076 $this->ShellEscapeCharacter = '"';
00077 $this->BackupFilename = '.bak';
00078 }
00079 else if ( substr( $uname, 0, 3 ) == "Mac" )
00080 {
00081 $this->OSType = "mac";
00082 $this->OS = "mac";
00083 $this->FileSystemType = "unix";
00084 $this->FileSeparator = "/";
00085 $this->LineSeparator= "\r";
00086 $this->EnvSeparator = ":";
00087 $this->ShellEscapeCharacter = "'";
00088 $this->BackupFilename = '~';
00089 }
00090 else
00091 {
00092 $this->OSType = "unix";
00093 if ( strtolower( substr( $uname, 0, 5 ) ) == 'linux' )
00094 {
00095 $this->OS = 'linux';
00096 }
00097 else if ( strtolower( substr( $uname, 0, 0 ) ) == 'freebsd' )
00098 {
00099 $this->OS = 'freebsd';
00100 }
00101 else
00102 {
00103 $this->OS = false;
00104 }
00105 $this->FileSystemType = "unix";
00106 $this->FileSeparator = "/";
00107 $this->LineSeparator= "\n";
00108 $this->EnvSeparator = ":";
00109 $this->ShellEscapeCharacter = "'";
00110 $this->BackupFilename = '~';
00111 }
00112
00113 $magicQuote = get_magic_quotes_gpc();
00114
00115 if ( $magicQuote == 1 )
00116 {
00117 eZSys::removeMagicQuotes();
00118 }
00119 }
00120
00121 function removeMagicQuotes()
00122 {
00123 $globalVariables = array( '_SERVER', '_ENV' );
00124 foreach ( $globalVariables as $globalVariable )
00125 {
00126 foreach ( array_keys( $GLOBALS[$globalVariable] ) as $key )
00127 {
00128 if ( !is_array( $GLOBALS[$globalVariable][$key] ) )
00129 {
00130 $GLOBALS[$globalVariable][$key] = stripslashes( $GLOBALS[$globalVariable][$key] );
00131 }
00132 }
00133 }
00134 }
00135
00136
00137
00138
00139
00140 function osType()
00141 {
00142 if ( isset( $this ) and get_class( $this ) == "ezsys" )
00143 $instance =& $this;
00144 else
00145 $instance =& eZSys::instance();
00146 return $instance->OSType;
00147 }
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158 function osName()
00159 {
00160 if ( isset( $this ) and get_class( $this ) == "ezsys" )
00161 $instance =& $this;
00162 else
00163 $instance =& eZSys::instance();
00164 return $instance->OS;
00165 }
00166
00167
00168
00169
00170
00171 function filesystemType()
00172 {
00173 if ( isset( $this ) and get_class( $this ) == "ezsys" )
00174 $instance =& $this;
00175 else
00176 $instance =& eZSys::instance();
00177 return $instance->FileSystemType;
00178 }
00179
00180
00181
00182
00183
00184 function fileSeparator()
00185 {
00186 if ( isset( $this ) and get_class( $this ) == "ezsys" )
00187 $instance =& $this;
00188 else
00189 $instance =& eZSys::instance();
00190 return $instance->FileSeparator;
00191 }
00192
00193
00194
00195
00196
00197
00198 function phpVersionText()
00199 {
00200 return phpversion();
00201 }
00202
00203
00204
00205
00206
00207
00208
00209
00210 function phpVersion()
00211 {
00212 $text = eZSys::phpVersionText();
00213 $elements = explode( '.', $text );
00214 return $elements;
00215 }
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225 function isPHPVersionSufficient( $requiredVersion )
00226 {
00227 if ( !is_array( $requiredVersion ) )
00228 return false;
00229 $phpVersion = eZSys::phpVersion();
00230 $len = min( count( $phpVersion ), count( $requiredVersion ) );
00231 for ( $i = 0; $i < $len; ++$i )
00232 {
00233 if ( $phpVersion[$i] > $requiredVersion[$i] )
00234 return true;
00235 if ( $phpVersion[$i] < $requiredVersion[$i] )
00236 return false;
00237 }
00238 return true;
00239 }
00240
00241
00242
00243
00244
00245 function isShellExecution()
00246 {
00247 $sapiType = php_sapi_name();
00248
00249 if ( $sapiType == 'cli' )
00250 return true;
00251
00252
00253
00254 if ( substr( $sapiType, 0, 3 ) == 'cgi' )
00255 {
00256 if ( !eZSys::serverVariable( 'HTTP_HOST', true ) )
00257 return true;
00258 else
00259 return false;
00260 }
00261 return false;
00262 }
00263
00264
00265
00266
00267
00268 function escapeShellArgument( $argument )
00269 {
00270 if ( isset( $this ) and get_class( $this ) == "ezsys" )
00271 $instance =& $this;
00272 else
00273 $instance =& eZSys::instance();
00274 $escapeChar = $instance->ShellEscapeCharacter;
00275 $argument = str_replace( "\\", "\\\\", $argument );
00276 $argument = str_replace( $escapeChar, "\\" . $escapeChar, $argument );
00277 $argument = $escapeChar . $argument . $escapeChar;
00278 return $argument;
00279 }
00280
00281
00282
00283
00284
00285
00286
00287 function createShellArgument( $argumentText, $replaceList )
00288 {
00289 if ( isset( $this ) and get_class( $this ) == "ezsys" )
00290 $instance =& $this;
00291 else
00292 $instance =& eZSys::instance();
00293 $elements = $instance->splitArgumentIntoElements( $argumentText );
00294 $replacedElements = array();
00295 foreach ( $elements as $element )
00296 {
00297 if ( is_string( $element ) )
00298 {
00299 $replacedElements[] = strtr( $element, $replaceList );
00300 continue;
00301 }
00302 $replacedElements[] = $element;
00303 }
00304 $text = $instance->mergeArgumentElements( $replacedElements );
00305 return $text;
00306 }
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322 function splitArgumentIntoElements( $argumentText )
00323 {
00324 if ( isset( $this ) and get_class( $this ) == "ezsys" )
00325 $instance =& $this;
00326 else
00327 $instance =& eZSys::instance();
00328 $argumentElements = array();
00329 $pos = 0;
00330
00331 while ( $pos < strlen( $argumentText ) )
00332 {
00333 if ( $argumentText[$pos] == '"' || $argumentText[$pos] == "'" )
00334 {
00335 $quoteStartPos = $pos + 1;
00336 $quoteEndPos = $pos + 1;
00337 while ( $quoteEndPos < strlen( $argumentText ) )
00338 {
00339 $tmpPos = strpos( $argumentText, $argumentText[$pos], $quoteEndPos );
00340 if ( $tmpPos !== false and
00341 $argumentText[$tmpPos - 1] != "\\" );
00342 {
00343 $quoteEndPos = $tmpPos;
00344 break;
00345 }
00346 if ( $tmpPos === false )
00347 {
00348 $quoteEndPos = strlen( $argumentText );
00349 break;
00350 }
00351 $quoteEndPos = $tmpPos + 1;
00352 }
00353 $argumentElements[] = substr( $argumentText, $quoteStartPos, $quoteEndPos - $quoteStartPos );
00354 $pos = $quoteEndPos + 1;
00355 }
00356 else if ( $argumentText[$pos] == ' ' )
00357 {
00358 $spacePos = $pos;
00359 $spaceEndPos = $pos;
00360 while ( $spaceEndPos < strlen( $argumentText ) )
00361 {
00362 if ( $argumentText[$spaceEndPos] != ' ' )
00363 break;
00364 ++$spaceEndPos;
00365 }
00366 $spaceText = substr( $argumentText, $spacePos, $spaceEndPos - $spacePos );
00367 $spaceCount = strlen( $spaceText );
00368 if ( $spaceCount > 0 )
00369 $argumentElements[] = $spaceCount;
00370 $pos = $spaceEndPos;
00371 }
00372 else
00373 {
00374 $spacePos = strpos( $argumentText, ' ', $pos );
00375 if ( $spacePos !== false )
00376 {
00377 $argumentElements[] = substr( $argumentText, $pos, $spacePos - $pos );
00378 $spaceEndPos = $spacePos + 1;
00379 while ( $spaceEndPos < strlen( $argumentText ) )
00380 {
00381 if ( $argumentText[$spaceEndPos] != ' ' )
00382 break;
00383 ++$spaceEndPos;
00384 }
00385 $spaceText = substr( $argumentText, $spacePos, $spaceEndPos - $spacePos );
00386 $spaceCount = strlen( $spaceText );
00387 if ( $spaceCount > 0 )
00388 $argumentElements[] = $spaceCount;
00389 $pos = $spaceEndPos;
00390 }
00391 else
00392 {
00393 $argumentElements[] = substr( $argumentText, $pos );
00394 $pos = strlen( $argumentText );
00395 }
00396 }
00397 }
00398 return $argumentElements;
00399 }
00400
00401
00402
00403
00404
00405
00406 function mergeArgumentElements( $argumentElements )
00407 {
00408 if ( isset( $this ) and get_class( $this ) == "ezsys" )
00409 $instance =& $this;
00410 else
00411 $instance =& eZSys::instance();
00412 $argumentText = '';
00413 foreach ( $argumentElements as $element )
00414 {
00415 if ( is_int( $element ) )
00416 {
00417 $argumentText .= str_repeat( ' ', $element );
00418 }
00419 else if ( is_string( $element ) )
00420 {
00421 $argumentText .= $instance->escapeShellArgument( $element );
00422 }
00423 }
00424 return $argumentText;
00425 }
00426
00427
00428
00429
00430
00431 function backupFilename()
00432 {
00433 if ( isset( $this ) and get_class( $this ) == "ezsys" )
00434 $instance =& $this;
00435 else
00436 $instance =& eZSys::instance();
00437 return $instance->BackupFilename;
00438 }
00439
00440
00441
00442
00443
00444 function lineSeparator()
00445 {
00446 if ( isset( $this ) and get_class( $this ) == "ezsys" )
00447 $instance =& $this;
00448 else
00449 $instance =& eZSys::instance();
00450 return $instance->LineSeparator;
00451 }
00452
00453
00454
00455
00456
00457 function envSeparator()
00458 {
00459 if ( isset( $this ) and get_class( $this ) == "ezsys" )
00460 $instance =& $this;
00461 else
00462 $instance =& eZSys::instance();
00463 return $instance->EnvSeparator;
00464 }
00465
00466
00467
00468
00469
00470 function varDirectory()
00471 {
00472 include_once( 'lib/ezutils/classes/ezini.php' );
00473 $ini =& eZINI::instance();
00474 include_once( 'lib/ezfile/classes/ezdir.php' );
00475 return eZDir::path( array( $ini->variable( 'FileSettings', 'VarDir' ) ) );
00476 }
00477
00478
00479
00480
00481
00482
00483 function storageDirectory()
00484 {
00485 include_once( 'lib/ezutils/classes/ezini.php' );
00486 include_once( 'lib/ezfile/classes/ezdir.php' );
00487 $ini =& eZINI::instance();
00488 $varDir = eZSys::varDirectory();
00489 $storageDir = $ini->variable( 'FileSettings', 'StorageDir' );
00490 return eZDir::path( array( $varDir, $storageDir ) );
00491 }
00492
00493
00494
00495
00496
00497
00498 function cacheDirectory()
00499 {
00500 include_once( 'lib/ezutils/classes/ezini.php' );
00501 $ini =& eZINI::instance();
00502 $cacheDir = $ini->variable( 'FileSettings', 'CacheDir' );
00503
00504 include_once( 'lib/ezfile/classes/ezdir.php' );
00505 if ( $cacheDir[0] == "/" )
00506 {
00507 return eZDir::path( array( $cacheDir ) );
00508 }
00509 else
00510 {
00511 return eZDir::path( array( eZSys::varDirectory(), $cacheDir ) );
00512 }
00513 }
00514
00515
00516
00517
00518
00519 function rootDir()
00520 {
00521 if ( isset( $this ) and get_class( $this ) == "ezsys" )
00522 $instance =& $this;
00523 else
00524 $instance =& eZSys::instance();
00525 if ( !$instance->RootDir )
00526 {
00527 $cwd = getcwd();
00528 $self = $instance->serverVariable( 'PHP_SELF' );
00529 if ( file_exists( $cwd . $instance->FileSeparator . $self ) or
00530 file_exists( $cwd . $instance->FileSeparator . $instance->IndexFile ) )
00531 {
00532 $instance->RootDir = $cwd;
00533 }
00534 else
00535 {
00536 $instance->RootDir = null;
00537 }
00538 }
00539 return $instance->RootDir;
00540 }
00541
00542
00543
00544
00545
00546 function &siteDir()
00547 {
00548 if ( isset( $this ) and get_class( $this ) == "ezsys" )
00549 $instance =& $this;
00550 else
00551 $instance =& eZSys::instance();
00552 return $instance->SiteDir;
00553 }
00554
00555
00556
00557
00558
00559 function &wwwDir()
00560 {
00561 if ( isset( $this ) and get_class( $this ) == "ezsys" )
00562 $instance =& $this;
00563 else
00564 $instance =& eZSys::instance();
00565 return $instance->WWWDir;
00566 }
00567
00568
00569
00570
00571
00572 function &indexDir( $withAccessList = true )
00573 {
00574 if ( isset( $this ) and get_class( $this ) == "ezsys" )
00575 $instance =& $this;
00576 else
00577 $instance =& eZSys::instance();
00578
00579 $indexDir = $instance->wwwDir() . $instance->indexFile( $withAccessList );
00580 return $indexDir;
00581 }
00582
00583
00584
00585
00586
00587
00588 function &indexFile( $withAccessList = true )
00589 {
00590 if ( isset( $this ) and get_class( $this ) == "ezsys" )
00591 $instance =& $this;
00592 else
00593 $instance =& eZSys::instance();
00594 $text = $instance->IndexFile;
00595
00596 $ini =& eZINI::instance();
00597 if ( $ini->variable( 'SiteAccessSettings', 'RemoveSiteAccessIfDefaultAccess' ) == 'enabled' )
00598 {
00599 $defaultAccess = $ini->variable( 'SiteSettings', 'DefaultAccess' );
00600 if ( count( $instance->AccessPath ) > 0 and $instance->AccessPath[0] == $defaultAccess )
00601 {
00602 $accessPathArray = $instance->AccessPath;
00603 array_shift( $accessPathArray );
00604 $accessPath = implode( '/', $accessPathArray );
00605 $text .= '/' . $accessPath;
00606
00607
00608 if ( $text == "/" )
00609 $text = "";
00610
00611 return $text;
00612 }
00613 }
00614
00615 if ( $withAccessList and count( $instance->AccessPath ) > 0 )
00616 {
00617 $accessPath = implode( '/', $instance->AccessPath );
00618
00619 include_once( 'access.php' );
00620 if ( isset( $GLOBALS['eZCurrentAccess'] ) &&
00621 isset( $GLOBALS['eZCurrentAccess']['type'] ) &&
00622 $GLOBALS['eZCurrentAccess']['type'] == EZ_ACCESS_TYPE_URI &&
00623 isset( $GLOBALS['eZCurrentAccess']['access_alias'] ) )
00624 {
00625 $accessPathArray = $instance->AccessPath;
00626 $accessPathArray[0] = $GLOBALS['eZCurrentAccess']['access_alias'];
00627 $accessPath = implode( '/', $accessPathArray );
00628 }
00629 $text .= '/' . $accessPath;
00630 }
00631 return $text;
00632 }
00633
00634
00635
00636
00637
00638 function indexFileName()
00639 {
00640 if ( isset( $this ) and get_class( $this ) == "ezsys" )
00641 $instance =& $this;
00642 else
00643 $instance =& eZSys::instance();
00644 return $instance->IndexFile;
00645 }
00646
00647
00648
00649
00650
00651 function &hostname()
00652 {
00653 $retVal = eZSys::serverVariable( 'HTTP_HOST' );
00654 return $retVal;
00655 }
00656
00657
00658
00659
00660
00661
00662 function isSSLNow()
00663 {
00664 $ini =& eZINI::instance();
00665 $sslPort = $ini->variable( 'SiteSettings', 'SSLPort' );
00666 if ( !$sslPort )
00667 $sslPort = EZSSLZONE_DEFAULT_SSL_PORT;
00668
00669 $nowSSL = ( eZSys::serverPort() == $sslPort );
00670 return $nowSSL;
00671 }
00672
00673
00674
00675
00676 function serverProtocol()
00677 {
00678 if ( eZSys::isSSLNow() )
00679 return 'https';
00680 else
00681 return 'http';
00682 }
00683
00684
00685
00686
00687
00688 function serverURL()
00689 {
00690 $host = eZSys::hostname();
00691 $url = '';
00692 if ( $host )
00693 {
00694 if ( eZSys::isSSLNow() )
00695 {
00696
00697 $host = preg_replace( '/:\d+$/', '', $host );
00698
00699 $ini =& eZINI::instance();
00700 $sslPort = $ini->variable( 'SiteSettings', 'SSLPort' );
00701
00702 $sslPortString = ( $sslPort == EZSSLZONE_DEFAULT_SSL_PORT ) ? '' : ":$sslPort";
00703 $url = "https://" . $host . $sslPortString;
00704 }
00705 else
00706 {
00707 $url = "http://" . $host;
00708 }
00709 }
00710 return $url;
00711 }
00712
00713
00714
00715
00716 function serverPort()
00717 {
00718 $port =& $GLOBALS['eZSysServerPort'];
00719 if ( !isset( $port ) )
00720 {
00721 $hostname = eZSys::hostname();
00722 if ( preg_match( "/.*:([0-9]+)/", $hostname, $regs ) )
00723 {
00724 $port = $regs[1];
00725 }
00726 else
00727 {
00728 $port = eZSys::serverVariable( 'SERVER_PORT' );
00729 }
00730 }
00731 return $port;
00732 }
00733
00734
00735
00736
00737
00738 function &magickQuotes()
00739 {
00740 $retValue = null;
00741 return $retValue;
00742 }
00743
00744
00745
00746
00747
00748 function &serverVariable( $variableName, $quiet = false )
00749 {
00750 if ( !isset( $_SERVER[$variableName] ) )
00751 {
00752 if ( !$quiet )
00753 eZDebug::writeError( "Server variable '$variableName' does not exist", 'eZSys::serverVariable' );
00754 $retVal = null;
00755 return $retVal;
00756 }
00757 return $_SERVER[$variableName];
00758 }
00759
00760
00761
00762
00763
00764 function setServerVariable( $variableName, $variableValue )
00765 {
00766 $_SERVER;
00767 $_SERVER[$variableName] = $variableValue;
00768 }
00769
00770
00771
00772
00773 function path( $quiet = false )
00774 {
00775 return eZSys::serverVariable( 'PATH', $quiet );
00776 }
00777
00778
00779
00780
00781
00782 function &environmentVariable( $variableName, $quiet = false )
00783 {
00784 $_ENV;
00785 if ( !isset( $_ENV[$variableName] ) )
00786 {
00787 if ( !$quiet )
00788 eZDebug::writeError( "Environment variable '$variableName' does not exist", 'eZSys::environmentVariable' );
00789 $retValue = null;
00790 return $retValue;
00791 }
00792 return $_ENV[$variableName];
00793 }
00794
00795
00796
00797
00798
00799 function setEnvironmentVariable( $variableName, $variableValue )
00800 {
00801 $_ENV;
00802 $_ENV[$variableName] = $variableValue;
00803 }
00804
00805 function attributes()
00806 {
00807 return array_merge( array( 'wwwdir',
00808 'sitedir',
00809 'indexfile',
00810 'indexdir' ),
00811 array_keys( $this->Attributes ) );
00812
00813 }
00814
00815
00816
00817
00818
00819 function hasAttribute( $attr )
00820 {
00821 return in_array( $attr, $this->attributes() );
00822 }
00823
00824
00825
00826
00827 function &attribute( $attr )
00828 {
00829 if ( isset( $this->Attributes[$attr] ) )
00830 {
00831 $mname = $attr;
00832 return $this->$mname();
00833 }
00834 else if ( $attr == 'wwwdir' )
00835 {
00836 return $this->wwwDir();
00837 }
00838 else if ( $attr == 'sitedir' )
00839 {
00840 return $this->siteDir();
00841 }
00842 else if ( $attr == 'indexfile' )
00843 {
00844 return $this->indexFile();
00845 }
00846 else if ( $attr == 'indexdir' )
00847 {
00848 $retVal = $this->indexDir();
00849 return $retVal;
00850 }
00851 else
00852 {
00853 eZDebug::writeError( "Attribute '$attr' does not exist", 'eZSys::attribute' );
00854 $retValue = null;
00855 return $retValue;
00856 }
00857 }
00858
00859
00860
00861
00862
00863
00864 function addAccessPath( $path )
00865 {
00866 if ( isset( $this ) and get_class( $this ) == "ezsys" )
00867 $instance =& $this;
00868 else
00869 $instance =& eZSys::instance();
00870 if ( !is_array( $path ) )
00871 $path = array( $path );
00872 $instance->AccessPath = array_merge( $instance->AccessPath, $path );
00873 }
00874
00875
00876
00877
00878
00879 function clearAccessPath()
00880 {
00881 if ( isset( $this ) and get_class( $this ) == "ezsys" )
00882 $instance =& $this;
00883 else
00884 $instance =& eZSys::instance();
00885 $instance->AccessPath = array();
00886 }
00887
00888
00889
00890
00891
00892
00893
00894 function isDebugEnabled()
00895 {
00896 if ( !isset( $GLOBALS['eZSysDebugInternalsEnabled'] ) )
00897 $GLOBALS['eZSysDebugInternalsEnabled'] = EZ_SYS_DEBUG_INTERNALS;
00898 return $GLOBALS['eZSysDebugInternalsEnabled'];
00899 }
00900
00901
00902
00903
00904
00905 function setIsDebugEnabled( $debug )
00906 {
00907 $GLOBALS['eZSysDebugInternalsEnabled'] = $debug;
00908 }
00909
00910
00911
00912
00913
00914
00915
00916 function init( $def_index = "index.php", $force_VirtualHost = false )
00917 {
00918 $isCGI = ( substr( php_sapi_name(), 0, 3 ) == 'cgi' );
00919
00920 if ( isset( $this ) and get_class( $this ) == "ezsys" )
00921 $instance =& $this;
00922 else
00923 $instance =& eZSys::instance();
00924
00925 if ( eZSys::isDebugEnabled() )
00926 {
00927 eZDebug::writeNotice( eZSys::serverVariable( 'PHP_SELF' ), 'PHP_SELF' );
00928 eZDebug::writeNotice( eZSys::serverVariable( 'SCRIPT_FILENAME' ), 'SCRIPT_FILENAME' );
00929 eZDebug::writeNotice( eZSys::serverVariable( 'DOCUMENT_ROOT' ), 'DOCUMENT_ROOT' );
00930 eZDebug::writeNotice( eZSys::serverVariable( 'REQUEST_URI' ), 'REQUEST_URI' );
00931 eZDebug::writeNotice( eZSys::serverVariable( 'QUERY_STRING' ), 'QUERY_STRING' );
00932 eZDebug::writeNotice( ini_get( 'include_path' ), 'include_path' );
00933 }
00934
00935 $phpSelf = eZSys::serverVariable( 'PHP_SELF' );
00936
00937
00938 if ( ereg( "(.*/)([^\/]+\.php)$", eZSys::serverVariable( 'SCRIPT_FILENAME' ), $regs ) )
00939 {
00940 $siteDir = $regs[1];
00941 $index = "/" . $regs[2];
00942 }
00943 elseif ( ereg( "(.*/)([^\/]+\.php)/?", $phpSelf, $regs ) )
00944 {
00945
00946 $siteDir = eZSys::serverVariable( 'DOCUMENT_ROOT' ) . $regs[1];
00947 $index = "/" . $regs[2];
00948 }
00949 else
00950 {
00951
00952 $siteDir = "./";
00953 $index = "/$def_index";
00954 }
00955 if ( $isCGI and !$force_VirtualHost )
00956 {
00957 $index .= '?';
00958 }
00959
00960
00961 $includePath = ini_get( "include_path" );
00962 if ( trim( $includePath ) != "" )
00963 {
00964 $includePath = $includePath . $instance->envSeparator() . $siteDir;
00965 }
00966 else
00967 {
00968 $includePath = $siteDir;
00969 }
00970 ini_set( "include_path", $includePath );
00971
00972 $scriptName = eZSys::serverVariable( 'SCRIPT_NAME' );
00973
00974
00975 $wwwDir = "";
00976
00977 if ( $force_VirtualHost )
00978 {
00979 $wwwDir = "";
00980 }
00981 else
00982 {
00983 if ( ereg( "(.*)/([^\/]+\.php)$", $scriptName, $regs ) )
00984 $wwwDir = $regs[1];
00985 else if ( ereg( "(.*)/([^\/]+\.php)$", $phpSelf, $regs ) )
00986 $wwwDir = $regs[1];
00987 }
00988
00989 if ( ! $isCGI || $force_VirtualHost )
00990 {
00991 $requestURI = eZSys::serverVariable( 'REQUEST_URI' );
00992 }
00993 else
00994 {
00995 $requestURI = eZSys::serverVariable( 'QUERY_STRING' );
00996
00997
00998 if ( preg_match( "/(.*)&PHPSESSID=[^&]+(.*)/", $requestURI, $matches ) )
00999 {
01000 $requestURI = $matches[1].$matches[2];
01001 }
01002 }
01003
01004
01005 if ( $siteDir == "./" )
01006 $phpSelf = $requestURI;
01007
01008 if ( ! $isCGI )
01009 {
01010 $def_index_reg = str_replace( ".", "\\.", $def_index );
01011
01012 if ( ! ereg( ".*$def_index_reg.*", $phpSelf ) || $force_VirtualHost )
01013 {
01014 $index = "";
01015 }
01016 else
01017 {
01018 if ( eZSys::isDebugEnabled() )
01019 eZDebug::writeNotice( "$wwwDir$index", '$wwwDir$index' );
01020
01021 if ( ereg( "^$wwwDir$index(.*)", $phpSelf, $req ) )
01022 {
01023 if (! $req[1] )
01024 {
01025 if ( $phpSelf != "$wwwDir$index" and ereg( "^$wwwDir(.*)", $requestURI, $req ) )
01026 {
01027 $requestURI = $req[1];
01028 $index = '';
01029 }
01030 elseif ( $phpSelf == "$wwwDir$index" and ereg( "^$wwwDir$index(.*)", $requestURI, $req ) or
01031 ereg( "^$wwwDir(.*)", $requestURI, $req ) )
01032 {
01033 $requestURI = $req[1];
01034 }
01035 }
01036 else
01037 {
01038 $requestURI = $req[1];
01039 }
01040 }
01041 }
01042 }
01043 if ( $isCGI and $force_VirtualHost )
01044 $index = '';
01045
01046 if ( $isCGI and !$force_VirtualHost )
01047 {
01048 $pattern = "(\/[^&]+)";
01049 }
01050 else
01051 {
01052 $pattern = "([^?]+)";
01053 }
01054 if ( ereg( $pattern, $requestURI, $regs ) )
01055 {
01056 $requestURI = $regs[1];
01057 }
01058
01059
01060 if ( ereg( "([^#]+)", $requestURI, $regs ) )
01061 {
01062 $requestURI = $regs[1];
01063 }
01064
01065 if ( !$isCGI )
01066 {
01067 $currentPath = substr( eZSys::serverVariable( 'SCRIPT_FILENAME' ), 0, -strlen( 'index.php' ) );
01068 if ( strpos( $currentPath, eZSys::serverVariable( 'DOCUMENT_ROOT' ) ) === 0 )
01069 {
01070 $prependRequest = substr( $currentPath, strlen( eZSys::serverVariable( 'DOCUMENT_ROOT' ) ) );
01071
01072 if ( strpos( $requestURI, $prependRequest ) === 0 )
01073 {
01074 $requestURI = substr( $requestURI, strlen( $prependRequest ) - 1 );
01075 $wwwDir = substr( $prependRequest, 0, -1 );
01076 }
01077 }
01078 }
01079
01080 $instance->AccessPath = array();
01081 $instance->SiteDir =& $siteDir;
01082 $instance->WWWDir =& $wwwDir;
01083 $instance->IndexFile =& $index;
01084 $instance->RequestURI = $requestURI;
01085
01086 if ( eZSys::isDebugEnabled() )
01087 {
01088 eZDebug::writeNotice( $instance->SiteDir, 'SiteDir' );
01089 eZDebug::writeNotice( $instance->WWWDir, 'WWWDir' );
01090 eZDebug::writeNotice( $instance->IndexFile, 'IndexFile' );
01091 eZDebug::writeNotice( eZSys::requestURI(), 'eZSys::requestURI()' );
01092 }
01093
01094 }
01095
01096
01097
01098
01099 function requestURI()
01100 {
01101 if ( isset( $this ) and get_class( $this ) == "ezsys" )
01102 $instance =& $this;
01103 else
01104 $instance =& eZSys::instance();
01105 return $instance->RequestURI;
01106 }
01107
01108
01109
01110
01111
01112 function initIni( &$ini )
01113 {
01114 }
01115
01116
01117
01118
01119
01120 function &instance()
01121 {
01122 $instance =& $GLOBALS["eZSysInstance"];
01123 if ( get_class( $instance ) != "ezsys" )
01124 {
01125 $instance = new eZSys();
01126 }
01127 return $instance;
01128 }
01129
01130
01131
01132
01133
01134 function ezcrc32( $string )
01135 {
01136 include_once( 'lib/ezutils/classes/ezini.php' );
01137 $ini =& eZINI::instance();
01138
01139 if ( $ini->variable( 'SiteSettings', '64bitCompatibilityMode' ) === 'enabled' )
01140 $checksum = sprintf( '%u', crc32( $string ) );
01141 else
01142 $checksum = crc32( $string );
01143
01144 return $checksum;
01145 }
01146
01147
01148
01149
01150
01151
01152
01153 function globBrace( $pattern, $flags = 0 )
01154 {
01155 if ( defined( 'GLOB_BRACE' ) )
01156 {
01157 $flags = $flags | GLOB_BRACE;
01158 return glob( $pattern, $flags );
01159 }
01160 else
01161 {
01162 $result = array();
01163 $files = eZSys::simulateGlobBrace( array( $pattern ) );
01164 foreach( $files as $file )
01165 {
01166 $result = array_merge( $result, glob( $file, $flags ) );
01167 }
01168 return $result;
01169 }
01170 }
01171
01172
01173
01174
01175
01176
01177
01178
01179
01180
01181 function simulateGlobBrace( $filenames )
01182 {
01183 $result = array();
01184
01185 foreach ( $filenames as $filename )
01186 {
01187 if ( strpos( $filename, '{' ) === false )
01188 {
01189 $result[] = $filename;
01190 continue;
01191 }
01192
01193 if ( preg_match( '/^(.*)\{(.*?)(?<!\\\\)\}(.*)$/', $filename, $match ) )
01194 {
01195 $variants = preg_split( '/(?<!\\\\),/', $match[2] );
01196
01197 $newFilenames = array();
01198 foreach ( $variants as $variant )
01199 {
01200 $newFilenames[] = $match[1] . $variant . $match[3];
01201 }
01202
01203 $newFilenames = eZSys::simulateGlobBrace( $newFilenames );
01204 $result = array_merge( $result, $newFilenames );
01205 }
01206 else
01207 {
01208 $result[] = $filename;
01209 }
01210 }
01211
01212 return $result;
01213 }
01214
01215
01216
01217 var $LineSeparator;
01218
01219 var $FileSeparator;
01220
01221 var $EnvSeparator;
01222
01223 var $RootDir;
01224
01225 var $SiteDir;
01226
01227 var $AccessPath;
01228
01229 var $WWWDir;
01230
01231 var $IndexFile;
01232
01233 var $RequestURI;
01234
01235 var $FileSystemType;
01236
01237 var $ShellEscapeCharacter;
01238 var $OSType;
01239 }
01240
01241 ?>