Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

ezsys.php
Go to the documentation of this file.
1 <?php
33 class eZSys
34 {
40 public $LineSeparator;
41
47 public $FileSeparator;
48
54 public $EnvSeparator;
55
61 public $RootDir;
62
68 public $SiteDir;
69
80 protected $AccessPath;
81
87 public $WWWDir;
88
94 public $IndexFile;
95
101 public $RequestURI;
102
108 public $FileSystemType;
109
115 public $ShellEscapeCharacter;
116
122 public $OSType;
123
124 public $Attributes;
125 public $OS;
126 public $BackupFilename;
127
134 protected $Params;
135
141 protected static $instance = null;
142
149 protected $QueryString;
150
156 public function __construct( array $serverParams = array() )
157 {
158 $this->Params = $serverParams + array(
159 'PHP_OS' => PHP_OS,
160 'DIRECTORY_SEPARATOR' => DIRECTORY_SEPARATOR,
161 'PATH_SEPARATOR' => PATH_SEPARATOR,
162 '_SERVER' => $_SERVER,
163 );
164
165 if ( isset( $this->Params['_SERVER']['REQUEST_TIME'] ) )
166 {
167 // REQUEST_TIME is a float and includes microseconds in PHP > 5.4.0
168 // It should be casted to int in order to keep BC
169 $this->Params['_SERVER']['REQUEST_TIME'] = (int)$this->Params['_SERVER']['REQUEST_TIME'];
170 }
171
172 $this->Attributes = array( 'hostname' => true );
173 $this->FileSeparator = $this->Params['DIRECTORY_SEPARATOR'];
174 $this->EnvSeparator = $this->Params['PATH_SEPARATOR'];
175
176 // Determine OS specific settings
177 if ( $this->Params['PHP_OS'] === 'WINNT' )
178 {
179 $this->OSType = "win32";
180 $this->OS = "windows";
181 $this->FileSystemType = "win32";
182 $this->LineSeparator = "\r\n";
183 $this->ShellEscapeCharacter = '"';
184 $this->BackupFilename = '.bak';
185 }
186 else
187 {
188 $this->OSType = 'unix';
189 if ( $this->Params['PHP_OS'] === 'Linux' )
190 {
191 $this->OS = 'linux';
192 }
193 else if ( $this->Params['PHP_OS'] === 'FreeBSD' )
194 {
195 $this->OS = 'freebsd';
196 }
197 else if ( $this->Params['PHP_OS'] === 'Darwin' )
198 {
199 $this->OS = 'darwin';
200 }
201 else
202 {
203 $this->OS = false;
204 }
205 $this->FileSystemType = "unix";
206 $this->LineSeparator = "\n";
207 $this->ShellEscapeCharacter = "'";
208 $this->BackupFilename = '~';
209 }
210
211 $this->AccessPath = array( 'siteaccess' => array( 'name' => '', 'url' => array() ),
212 'path' => array( 'name' => '', 'url' => array() ) );
213 }
214
222 public static function osType()
223 {
224 return self::instance()->OSType;
225 }
226
234 public static function osName()
235 {
236 return self::instance()->OS;
237 }
238
246 public static function filesystemType()
247 {
248 return self::instance()->FileSystemType;
249 }
250
256 public static function fileSeparator()
257 {
258 return self::instance()->FileSeparator;
259 }
260
266 public static function isShellExecution()
267 {
268 $sapiType = php_sapi_name();
269
270 if ( $sapiType == 'cli' )
271 return true;
272
273 // For CGI we have to check, if the script has been executed over shell.
274 // Currently it looks like the HTTP_HOST variable is the most reasonable to check.
275 if ( substr( $sapiType, 0, 3 ) == 'cgi' )
276 {
277 if ( !self::serverVariable( 'HTTP_HOST', true ) )
278 return true;
279 else
280 return false;
281 }
282 return false;
283 }
284
291 public static function escapeShellArgument( $argument )
292 {
293 $escapeChar = self::instance()->ShellEscapeCharacter;
294 if ( $escapeChar == "'" )
295 {
296 $argument = str_replace( "'", "'\\''", $argument );
297 }
298 else
299 {
300 $argument = str_replace( $escapeChar, "\\" . $escapeChar, addcslashes( $argument, '\\' ) );
301 }
302 return $escapeChar . $argument . $escapeChar;
303 }
304
313 public static function createShellArgument( $argumentText, array $replaceList )
314 {
315 $instance = self::instance();
316 $elements = $instance->splitArgumentIntoElements( $argumentText );
317 $replacedElements = array();
318 foreach ( $elements as $element )
319 {
320 if ( is_string( $element ) )
321 {
322 $replacedElements[] = strtr( $element, $replaceList );
323 continue;
324 }
325 $replacedElements[] = $element;
326 }
327 $text = $instance->mergeArgumentElements( $replacedElements );
328 return $text;
329 }
330
350 public static function splitArgumentIntoElements( $argumentText )
351 {
352 $argumentElements = array();
353 $pos = 0;
354
355 while ( $pos < strlen( $argumentText ) )
356 {
357 if ( $argumentText[$pos] == '"' || $argumentText[$pos] == "'" )
358 {
359 $quoteStartPos = $pos + 1;
360 $quoteEndPos = $pos + 1;
361
362 while ( $quoteEndPos < strlen( $argumentText ) )
363 {
364 $tmpPos = strpos( $argumentText, $argumentText[$pos], $quoteEndPos );
365
366 if ( $tmpPos !== false && $argumentText[$tmpPos - 1] != "\\" )
367 {
368 $quoteEndPos = $tmpPos;
369 break;
370 }
371
372 if ( $tmpPos === false )
373 {
374 $quoteEndPos = strlen( $argumentText );
375 break;
376 }
377 $quoteEndPos = $tmpPos + 1;
378 }
379
380 $argumentElements[] = substr( $argumentText, $quoteStartPos, $quoteEndPos - $quoteStartPos );
381 $pos = $quoteEndPos + 1;
382 }
383 else if ( $argumentText[$pos] == ' ' )
384 {
385 $spacePos = $pos;
386 $spaceEndPos = $pos;
387 while ( $spaceEndPos < strlen( $argumentText ) )
388 {
389 if ( $argumentText[$spaceEndPos] != ' ' )
390 {
391 break;
392 }
393 ++$spaceEndPos;
394 }
395 $spaceText = substr( $argumentText, $spacePos, $spaceEndPos - $spacePos );
396 $spaceCount = strlen( $spaceText );
397 if ( $spaceCount > 0 )
398 {
399 $argumentElements[] = $spaceCount;
400 }
401
402 $pos = $spaceEndPos;
403 }
404 else
405 {
406 $spacePos = strpos( $argumentText, ' ', $pos );
407
408 if ( $spacePos !== false )
409 {
410 $argumentElements[] = substr( $argumentText, $pos, $spacePos - $pos );
411 $spaceEndPos = $spacePos + 1;
412
413 while ( $spaceEndPos < strlen( $argumentText ) )
414 {
415 if ( $argumentText[$spaceEndPos] != ' ' )
416 {
417 break;
418 }
419 ++$spaceEndPos;
420 }
421
422 $spaceText = substr( $argumentText, $spacePos, $spaceEndPos - $spacePos );
423 $spaceCount = strlen( $spaceText );
424
425 if ( $spaceCount > 0 )
426 {
427 $argumentElements[] = $spaceCount;
428 }
429 $pos = $spaceEndPos;
430 }
431 else
432 {
433 $argumentElements[] = substr( $argumentText, $pos );
434 $pos = strlen( $argumentText );
435 }
436 }
437 }
438
439 return $argumentElements;
440 }
441
449 public static function mergeArgumentElements( array $argumentElements )
450 {
451 $instance = self::instance();
452 $argumentText = '';
453 foreach ( $argumentElements as $element )
454 {
455 if ( is_int( $element ) )
456 {
457 $argumentText .= str_repeat( ' ', $element );
458 }
459 else if ( is_string( $element ) )
460 {
461 $argumentText .= $instance->escapeShellArgument( $element );
462 }
463 }
464 return $argumentText;
465 }
466
474 public static function backupFilename()
475 {
476 return self::instance()->BackupFilename;
477 }
478
484 public static function lineSeparator()
485 {
486 return self::instance()->LineSeparator;
487 }
488
494 public static function envSeparator()
495 {
496 return self::instance()->EnvSeparator;
497 }
498
504 public static function varDirectory()
505 {
506 $ini = eZINI::instance();
507 return eZDir::path( array( $ini->variable( 'FileSettings', 'VarDir' ) ) );
508 }
509
515 public static function storageDirectory()
516 {
517 $ini = eZINI::instance();
518 $varDir = self::varDirectory();
519 $storageDir = $ini->variable( 'FileSettings', 'StorageDir' );
520 return eZDir::path( array( $varDir, $storageDir ) );
521 }
522
528 public static function cacheDirectory()
529 {
530 $ini = eZINI::instance();
531 $cacheDir = $ini->variable( 'FileSettings', 'CacheDir' );
532
533 if ( $cacheDir[0] == "/" )
534 {
535 return eZDir::path( array( $cacheDir ) );
536 }
537 else
538 {
539 return eZDir::path( array( self::varDirectory(), $cacheDir ) );
540 }
541 }
542
548 public static function rootDir()
549 {
550 $instance = self::instance();
551 if ( !$instance->RootDir )
552 {
553 $cwd = getcwd();
554 $self = $instance->serverVariable( 'PHP_SELF' );
555 if ( file_exists( $cwd . $instance->FileSeparator . $self ) or
556 file_exists( $cwd . $instance->FileSeparator . $instance->IndexFile ) )
557 {
558 $instance->RootDir = $cwd;
559 }
560 else
561 {
562 $instance->RootDir = null;
563 }
564 }
565 return $instance->RootDir;
566 }
567
573 public static function siteDir()
574 {
575 return self::instance()->SiteDir;
576 }
577
583 public static function wwwDir()
584 {
585 return self::instance()->WWWDir;
586 }
587
594 public static function indexDir( $withAccessList = true )
595 {
596 return self::wwwDir() . self::indexFile( $withAccessList );
597 }
598
608 public static function queryString()
609 {
610 return self::instance()->QueryString;
611 }
612
619 public static function indexFile( $withAccessPath = true )
620 {
621 $sys = self::instance();
622 $text = $sys->IndexFile;
623
624 if ( $withAccessPath && ( isset( $sys->AccessPath['siteaccess']['url'][0] ) || isset( $sys->AccessPath['path']['url'][0] ) ) )
625 {
626 $ini = eZINI::instance();
627 if ( isset( $sys->AccessPath['siteaccess']['url'][0] ) &&
628 $ini->variable( 'SiteAccessSettings', 'RemoveSiteAccessIfDefaultAccess' ) === 'enabled' )
629 {
630 $defaultAccess = $ini->variable( 'SiteSettings', 'DefaultAccess' );
631 // 1st is proper match where code has used updated api as of 4.4, do not use siteaccess
632 if ( $sys->AccessPath['siteaccess']['name'] === $defaultAccess )
633 $accessPath = implode( '/', $sys->AccessPath['path']['url'] );
634 // 2nd is for compatability with older code that used eZSys api withouth defining scopes, shift default siteaccess path
635 elseif ( $sys->AccessPath['siteaccess']['name'] === 'undefined' && $sys->AccessPath['siteaccess']['url'][0] === $defaultAccess )
636 {
637 $accessPathArray = $sys->AccessPath;
638 array_shift( $accessPathArray['siteaccess']['url'] ); //remove default siteaccess
639 $accessPath = implode( '/', array_merge( $accessPathArray['siteaccess']['url'], $accessPathArray['path']['url'] ) );
640 }
641 // In case there is no default siteaccess match use full url
642 else
643 $accessPath = implode( '/', array_merge( $sys->AccessPath['siteaccess']['url'], $sys->AccessPath['path']['url'] ) );
644 }
645 else
646 {
647 $accessPath = implode( '/', array_merge( $sys->AccessPath['siteaccess']['url'], $sys->AccessPath['path']['url'] ) );
648 }
649
650 $text .= '/' . $accessPath;
651
652 // Make sure we never return just a single '/' in case where siteaccess was shifted
653 if ( $text === '/' )
654 $text = '';
655 }
656 return $text;
657 }
658
664 public static function indexFileName()
665 {
666 return self::instance()->IndexFile;
667 }
668
677 public static function hostname()
678 {
679 $hostName = null;
680 $forwardedHostsString = self::serverVariable( 'HTTP_X_FORWARDED_HOST', true );
681 if ( $forwardedHostsString )
682 {
683 $forwardedHosts = explode( ',', $forwardedHostsString );
684 $hostName = trim( $forwardedHosts[0] );
685 }
686
687 if ( !$hostName && self::serverVariable( 'HTTP_HOST', true ) )
688 {
689 $hostName = self::serverVariable( 'HTTP_HOST' );
690 }
691
692 if ( !$hostName )
693 {
694 $siteUrl = eZINI::instance()->variable( 'SiteSettings', 'SiteURL' );
695 $hostName = parse_url( "http://{$siteUrl}", PHP_URL_HOST );
696 }
697
698 return $hostName;
699 }
700
715 public static function clientIP()
716 {
717 $customHTTPHeader = eZINI::instance()->variable( 'HTTPHeaderSettings', 'ClientIpByCustomHTTPHeader' );
718 if( $customHTTPHeader && $customHTTPHeader != 'false' )
719 {
720 // Transforms for instance, X-Forwarded-For into X_FORWARDED_FOR
721 $phpHeader = 'HTTP_' . str_replace( '-', '_', strtoupper( $customHTTPHeader ) );
722 $forwardedClientsString = eZSys::serverVariable( $phpHeader, true );
723
724 if ( $forwardedClientsString )
725 {
726 // $forwardedClientsString (usually) contains a comma+space separated list of IPs
727 // where the left-most being the farthest downstream client. All the others are proxy servers.
728 // As X-Forwarded-For is not a standard header yet, we prefer to use a simple comma as the explode delimiter
729 $forwardedClients = explode( ',', $forwardedClientsString );
730 if( !empty( $forwardedClients ) )
731 {
732 return trim( $forwardedClients[0] );
733 }
734 }
735 }
736
737 return self::serverVariable( 'REMOTE_ADDR', true );
738 }
739
745 public static function isSSLNow()
746 {
747 $ini = eZINI::instance();
748 $sslPort = $ini->variable( 'SiteSettings', 'SSLPort' );
749 if ( !$sslPort )
750 $sslPort = eZSSLZone::DEFAULT_SSL_PORT;
751 // $nowSSl is true if current access mode is HTTPS.
752 $nowSSL = ( self::serverPort() == $sslPort );
753
754 if ( !$nowSSL )
755 {
756 // Check if this request might be driven through a ssl proxy
757 if ( isset( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) )
758 {
759 $nowSSL = ( $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' );
760 }
761 else if ( isset( $_SERVER['HTTP_X_FORWARDED_PORT'] ) )
762 {
763 $sslPort = $ini->variable( 'SiteSettings', 'SSLPort' );
764 $nowSSL = ( $_SERVER['HTTP_X_FORWARDED_PORT'] == $sslPort );
765 }
766 else if ( isset( $_SERVER['HTTP_X_FORWARDED_SERVER'] ) )
767 {
768 $sslProxyServerName = $ini->variable( 'SiteSettings', 'SSLProxyServerName' );
769 $nowSSL = ( $sslProxyServerName == $_SERVER['HTTP_X_FORWARDED_SERVER'] );
770 }
771 }
772 return $nowSSL;
773 }
774
780 public static function serverProtocol()
781 {
782 if ( self::isSSLNow() )
783 return 'https';
784 else
785 return 'http';
786 }
787
793 public static function serverURL()
794 {
795 $host = self::hostname();
796 $url = '';
797 if ( $host )
798 {
799 if ( self::isSSLNow() )
800 {
801 // https case
802 $host = preg_replace( '/:\d+$/', '', $host );
803
804 $ini = eZINI::instance();
805 $sslPort = $ini->variable( 'SiteSettings', 'SSLPort' );
806
807 $sslPortString = ( $sslPort == eZSSLZone::DEFAULT_SSL_PORT ) ? '' : ":$sslPort";
808 $url = "https://" . $host . $sslPortString;
809 }
810 else
811 {
812 $url = "http://" . $host;
813 }
814 }
815 return $url;
816 }
817
824 public static function serverPort()
825 {
826 if ( empty( $GLOBALS['eZSysServerPort'] ) )
827 {
828 $hostname = self::hostname();
829 if ( preg_match( "/.*:([0-9]+)/", $hostname, $regs ) )
830 {
831 $port = (int) $regs[1];
832 }
833 else
834 {
835 $port = (int) self::serverVariable( 'SERVER_PORT', true );
836 }
837
838 if ( !$port )
839 {
840 $port = 80;
841 }
842
843 $GLOBALS['eZSysServerPort'] = $port;
844 }
845 return $GLOBALS['eZSysServerPort'];
846 }
847
857 public static function serverVariable( $variableName, $quiet = false )
858 {
859 if ( !isset( $_SERVER[$variableName] ) )
860 {
861 if ( !$quiet )
862 {
863 eZDebug::writeError( "Server variable '$variableName' does not exist", __METHOD__ );
864 }
865
866 return null;
867 }
868 return $_SERVER[$variableName];
869 }
870
879 public static function setServerVariable( $variableName, $variableValue )
880 {
881 $_SERVER[$variableName] = $variableValue;
882 }
883
890 public static function path( $quiet = false )
891 {
892 return self::serverVariable( 'PATH', $quiet );
893 }
894
904 public static function environmentVariable( $variableName, $quiet = false )
905 {
906 if ( getenv($variableName) === false )
907 {
908 if ( !$quiet )
909 {
910 eZDebug::writeError( "Environment variable '$variableName' does not exist", __METHOD__ );
911 }
912 return null;
913 }
914 return getenv($variableName);
915 }
916
923 public static function hasEnvironmentVariable( $variableName )
924 {
925 return getenv($variableName) !== false;
926 }
927
935 public static function setEnvironmentVariable( $variableName, $variableValue )
936 {
937 putenv( "$variableName=$variableValue" );
938 }
939
945 function attributes()
946 {
947 return array_merge( array( 'wwwdir',
948 'sitedir',
949 'indexfile',
950 'indexdir',
951 'querystring' ),
952 array_keys( $this->Attributes ) );
953
954 }
955
962 function hasAttribute( $attr )
963 {
964 return in_array( $attr, $this->attributes() );
965 }
966
973 function attribute( $attr )
974 {
975 if ( isset( $this->Attributes[$attr] ) )
976 {
977 return $this->$attr();
978 }
979 else if ( $attr == 'wwwdir' )
980 {
981 return $this->wwwDir();
982 }
983 else if ( $attr == 'sitedir' )
984 {
985 return $this->siteDir();
986 }
987 else if ( $attr == 'indexfile' )
988 {
989 return $this->indexFile();
990 }
991 else if ( $attr == 'indexdir' )
992 {
993 return $this->indexDir();
994 }
995 else if ( $attr = 'querystring' )
996 {
997 return $this->queryString();
998 }
999
1000 eZDebug::writeError( "Attribute '$attr' does not exist", __METHOD__ );
1001 return null;
1002 }
1003
1014 static function addAccessPath( $path, $name = 'undefined', $siteaccess = true )
1015 {
1016 $instance = self::instance();
1017 if ( !is_array( $path ) )
1018 $path = array( $path );
1019
1020 if ( $siteaccess )
1021 {
1022 $instance->AccessPath['siteaccess']['name'] = $name;
1023 if ( isset($instance->AccessPath['siteaccess']['url'][0]) )
1024 $instance->AccessPath['siteaccess']['url'] = array_merge( $instance->AccessPath['siteaccess']['url'], $path );
1025 else
1026 $instance->AccessPath['siteaccess']['url'] = $path;
1027 }
1028 else
1029 {
1030 $instance->AccessPath['path']['name'] = $name;
1031 if ( isset($instance->AccessPath['path']['url'][0]) )
1032 $instance->AccessPath['path']['url'] = array_merge( $instance->AccessPath['path']['url'], $path );
1033 else
1034 $instance->AccessPath['path']['url'] = $path;
1035 }
1036 }
1037
1046 static function setAccessPath( array $path = array(), $name = 'undefined', $siteaccess = true )
1047 {
1048 if ( $siteaccess )
1049 self::instance()->AccessPath['siteaccess'] = array( 'name' => $name, 'url' => $path );
1050 else
1051 self::instance()->AccessPath['path'] = array( 'name' => $name, 'url' => $path );
1052 }
1053
1060 static function clearAccessPath( $siteaccess = true )
1061 {
1062 if ( $siteaccess )
1063 self::instance()->AccessPath['siteaccess'] = array( 'name' => '', 'url' => array() );
1064 else
1065 self::instance()->AccessPath['path'] = array( 'name' => '', 'url' => array() );
1066 }
1067
1075 public function __get( $propertyName )
1076 {
1077 if ( $propertyName === 'AccessPath' )
1078 return $this->AccessPath;
1079
1080 throw new ezcBasePropertyNotFoundException( $propertyName );
1081 }
1082
1090 public function __isset( $propertyName )
1091 {
1092 return $propertyName === 'AccessPath';
1093 }
1094
1104 public static function init( $index = 'index.php', $forceVirtualHost = null )
1105 {
1106 $instance = self::instance();
1107 $server = $instance->Params['_SERVER'];
1108 $phpSelf = $server['PHP_SELF'];
1109 $requestUri = isset( $server['REQUEST_URI'] ) ? $server['REQUEST_URI'] : '';
1110 $scriptFileName = $server['SCRIPT_FILENAME'];
1111 $siteDir = rtrim( str_replace( $index, '', $scriptFileName ), '\/' ) . '/';
1112 $wwwDir = '';
1113 $IndexFile = '';
1114 $queryString = '';
1115
1116 // see if we can use phpSelf to determin wwwdir
1117 $tempwwwDir = self::getValidwwwDir( $phpSelf, $scriptFileName, $index );
1118 if ( $tempwwwDir !== null && $tempwwwDir !== false )
1119 {
1120 // Force virual host or Auto detect IIS vh mode & Apache .htaccess mode
1121 if ( $forceVirtualHost
1122 || ( isset( $server['IIS_WasUrlRewritten'] ) && $server['IIS_WasUrlRewritten'] )
1123 || ( isset( $server['REDIRECT_URL'] ) && isset( $server['REDIRECT_STATUS'] ) && $server['REDIRECT_STATUS'] == '200' ) )
1124 {
1125 if ( $tempwwwDir )
1126 {
1127 $wwwDir = '/' . $tempwwwDir;
1128 $wwwDirPos = strpos( $requestUri, $wwwDir );
1129 if ( $wwwDirPos !== false )
1130 {
1131 $requestUri = substr( $requestUri, $wwwDirPos + strlen($wwwDir) );
1132 }
1133 }
1134 }
1135 else // Non virtual host mode, use $tempwwwDir to figgure out paths
1136 {
1137 $indexDir = $index;
1138 if ( $tempwwwDir )
1139 {
1140 $wwwDir = '/' . $tempwwwDir;
1141 $indexDir = $wwwDir . '/' . $indexDir;
1142 }
1143 $IndexFile = '/' . $index;
1144
1145 // remove sub path from requestUri
1146 $indexDirPos = strpos( $requestUri, $indexDir );
1147 if ( $indexDirPos !== false )
1148 {
1149 $requestUri = substr( $requestUri, $indexDirPos + strlen($indexDir) );
1150 }
1151 elseif ( $wwwDir )
1152 {
1153 $wwwDirPos = strpos( $requestUri, $wwwDir );
1154 if ( $wwwDirPos !== false )
1155 {
1156 $requestUri = substr( $requestUri, $wwwDirPos + strlen($wwwDir) );
1157 }
1158 }
1159 }
1160 }
1161
1162 // remove url and hash parameters
1163 if ( isset( $requestUri[1] ) && $requestUri !== '/' )
1164 {
1165 $uriGetPos = strpos( $requestUri, '?' );
1166 if ( $uriGetPos !== false )
1167 {
1168 $queryString = substr( $requestUri, $uriGetPos );
1169 if ( $uriGetPos === 0 )
1170 $requestUri = '';
1171 else
1172 $requestUri = substr( $requestUri, 0, $uriGetPos );
1173 }
1174
1175 $uriHashPos = strpos( $requestUri, '#' );
1176 if ( $uriHashPos === 0 )
1177 $requestUri = '';
1178 elseif ( $uriHashPos !== false )
1179 $requestUri = substr( $requestUri, 0, $uriHashPos );
1180 }
1181
1182 // normalize slash use and url decode url if needed
1183 if ( $requestUri === '/' || $requestUri === '' )
1184 {
1185 $requestUri = '';
1186 }
1187 else
1188 {
1189 $requestUri = '/' . urldecode( trim( $requestUri, '/ ' ) );
1190 }
1191
1192 $instance->AccessPath = array( 'siteaccess' => array( 'name' => '', 'url' => array() ),
1193 'path' => array( 'name' => '', 'url' => array() ) );
1194
1195 $instance->SiteDir = $siteDir;
1196 $instance->WWWDir = $wwwDir;
1197 $instance->IndexFile = $IndexFile;
1198 $instance->RequestURI = $requestUri;
1199 $instance->QueryString = $queryString;
1200 }
1201
1212 protected static function getValidwwwDir( $phpSelf, $scriptFileName, $index )
1213 {
1214 if ( !isset( $phpSelf[1] ) || empty($index) || strpos( $phpSelf, $index ) === false )
1215 return false;
1216
1217 // validate $index straight away
1218 if ( strpos( $scriptFileName, $index ) === false )
1219 return null;
1220
1221 // optimize '/index.php' pattern
1222 if ( $phpSelf === "/{$index}" )
1223 return '';
1224
1225 $phpSelfParts = explode( $index, $phpSelf );
1226 $validateDir = $phpSelfParts[0];
1227 // remove first path if home dir
1228 if ( $phpSelf[1] === '~' )
1229 {
1230 $uri = explode( '/', ltrim( $validateDir, '/' ) );
1231 $userName = ltrim( array_shift( $uri ), "~" );
1232
1233 // validating that we have user/ in path
1234 if ( !strpos( $scriptFileName, $userName ."/" ) )
1235 {
1236 return null;
1237 }
1238
1239 $validateDir = '/' . implode( '/', $uri );
1240 }
1241
1242 if ( !empty( $validateDir ) )
1243 {
1244 // validate directly with phpself part
1245 if ( strpos( $scriptFileName, $validateDir ) !== false )
1246 return trim( $phpSelfParts[0], '/' );
1247
1248 // validate with windows path
1249 if ( strpos( $scriptFileName, str_replace( '/', '\\', $validateDir ) ) !== false )
1250 return trim( $phpSelfParts[0], '/' );
1251 }
1252
1253 return null;
1254 }
1255
1263 public static function requestURI()
1264 {
1265 return self::instance()->RequestURI;
1266 }
1267
1273 public static function instance()
1274 {
1275 if ( !self::$instance instanceof eZSys )
1276 {
1277 self::$instance = new eZSys();
1278 }
1279 return self::$instance;
1280 }
1281
1287 public static function setInstance( eZSys|null $instance = null )
1288 {
1289 self::$instance = $instance;
1290 }
1291
1298 public static function ezcrc32( $string )
1299 {
1300 $ini = eZINI::instance();
1301
1302 if ( $ini->variable( 'SiteSettings', '64bitCompatibilityMode' ) === 'enabled' )
1303 $checksum = sprintf( '%u', crc32( $string ) );
1304 else
1305 $checksum = crc32( $string );
1306
1307 return $checksum;
1308 }
1309
1315 public static function protocolSchema()
1316 {
1317 $schema = '';
1318 if( preg_match( "#^([a-zA-Z]+)/.*$#", self::serverVariable( 'SERVER_PROTOCOL' ), $schemaMatches ) )
1319 {
1320 $schema = strtolower( $schemaMatches[1] ) . '://';
1321 }
1322
1323 return $schema;
1324 }
1325
1334 public static function globBrace( $pattern, $flags = 0 )
1335 {
1336 if ( defined( 'GLOB_BRACE' ) )
1337 {
1338 $flags = $flags | GLOB_BRACE;
1339 return glob( $pattern, $flags );
1340 }
1341 else
1342 {
1343 $result = array();
1344 $files = self::simulateGlobBrace( array( $pattern ) );
1345 foreach( $files as $file )
1346 {
1347 $globList = glob( $file, $flags );
1348 if ( is_array( $globList ) )
1349 {
1350 $result = array_merge( $result, $globList );
1351 }
1352 }
1353 return $result;
1354 }
1355 }
1356
1366 protected static function simulateGlobBrace( $filenames )
1367 {
1368 $result = array();
1369
1370 foreach ( $filenames as $filename )
1371 {
1372 if ( strpos( $filename, '{' ) === false )
1373 {
1374 $result[] = $filename;
1375 continue;
1376 }
1377
1378 if ( preg_match( '/^(.*)\{(.*?)(?<!\\\\)\}(.*)$/', $filename, $match ) )
1379 {
1380 $variants = preg_split( '/(?<!\\\\),/', $match[2] );
1381
1382 $newFilenames = array();
1383 foreach ( $variants as $variant )
1384 {
1385 $newFilenames[] = $match[1] . $variant . $match[3];
1386 }
1387
1388 $newFilenames = self::simulateGlobBrace( $newFilenames );
1389 $result = array_merge( $result, $newFilenames );
1390 }
1391 else
1392 {
1393 $result[] = $filename;
1394 }
1395 }
1396
1397 return $result;
1398 }
1399 }
1400
1401 ?>
$uri
$uri
Definition: activate.php:71
$files
$files
Definition: articlepreview.php:91
eZDebug\writeError
static writeError( $string, $label="", $backgroundClass="")
Definition: ezdebug.php:546
eZDir\path
static path( $names, $includeEndSeparator=false, $type=self::SEPARATOR_UNIX)
Definition: ezdir.php:238
eZSys
Definition: ezsys.php:34
eZSys\$RequestURI
$RequestURI
Definition: ezsys.php:101
eZSys\$FileSystemType
$FileSystemType
Definition: ezsys.php:108
eZSys\getValidwwwDir
static getValidwwwDir( $phpSelf, $scriptFileName, $index)
Definition: ezsys.php:1212
eZSys\filesystemType
static filesystemType()
Definition: ezsys.php:246
eZSys\$QueryString
$QueryString
Definition: ezsys.php:149
eZSys\storageDirectory
static storageDirectory()
Definition: ezsys.php:515
eZSys\rootDir
static rootDir()
Definition: ezsys.php:548
eZSys\createShellArgument
static createShellArgument( $argumentText, array $replaceList)
Definition: ezsys.php:313
eZSys\protocolSchema
static protocolSchema()
Definition: ezsys.php:1315
eZSys\indexDir
static indexDir( $withAccessList=true)
Definition: ezsys.php:594
eZSys\attributes
attributes()
Definition: ezsys.php:945
eZSys\envSeparator
static envSeparator()
Definition: ezsys.php:494
eZSys\setInstance
static setInstance(eZSys|null $instance=null)
Definition: ezsys.php:1287
eZSys\hasEnvironmentVariable
static hasEnvironmentVariable( $variableName)
Definition: ezsys.php:923
eZSys\osName
static osName()
Definition: ezsys.php:234
eZSys\isSSLNow
static isSSLNow()
Definition: ezsys.php:745
eZSys\serverVariable
static serverVariable( $variableName, $quiet=false)
Definition: ezsys.php:857
eZSys\$EnvSeparator
$EnvSeparator
Definition: ezsys.php:54
eZSys\$RootDir
$RootDir
Definition: ezsys.php:61
eZSys\environmentVariable
static environmentVariable( $variableName, $quiet=false)
Definition: ezsys.php:904
eZSys\isShellExecution
static isShellExecution()
Definition: ezsys.php:266
eZSys\$SiteDir
$SiteDir
Definition: ezsys.php:68
eZSys\serverProtocol
static serverProtocol()
Definition: ezsys.php:780
eZSys\escapeShellArgument
static escapeShellArgument( $argument)
Definition: ezsys.php:291
eZSys\serverURL
static serverURL()
Definition: ezsys.php:793
eZSys\$Attributes
$Attributes
Definition: ezsys.php:124
eZSys\attribute
attribute( $attr)
Definition: ezsys.php:973
eZSys\$AccessPath
$AccessPath
Definition: ezsys.php:80
eZSys\serverPort
static serverPort()
Definition: ezsys.php:824
eZSys\indexFileName
static indexFileName()
Definition: ezsys.php:664
eZSys\$BackupFilename
$BackupFilename
Definition: ezsys.php:126
eZSys\$FileSeparator
$FileSeparator
Definition: ezsys.php:47
eZSys\$Params
$Params
Definition: ezsys.php:134
eZSys\$instance
static $instance
Definition: ezsys.php:141
eZSys\clearAccessPath
static clearAccessPath( $siteaccess=true)
Definition: ezsys.php:1060
eZSys\globBrace
static globBrace( $pattern, $flags=0)
Definition: ezsys.php:1334
eZSys\lineSeparator
static lineSeparator()
Definition: ezsys.php:484
eZSys\__construct
__construct(array $serverParams=array())
Definition: ezsys.php:156
eZSys\addAccessPath
static addAccessPath( $path, $name='undefined', $siteaccess=true)
Definition: ezsys.php:1014
eZSys\$OSType
$OSType
Definition: ezsys.php:122
eZSys\$OS
$OS
Definition: ezsys.php:125
eZSys\$IndexFile
$IndexFile
Definition: ezsys.php:94
eZSys\osType
static osType()
Definition: ezsys.php:222
eZSys\setServerVariable
static setServerVariable( $variableName, $variableValue)
Definition: ezsys.php:879
eZSys\requestURI
static requestURI()
Definition: ezsys.php:1263
eZSys\mergeArgumentElements
static mergeArgumentElements(array $argumentElements)
Definition: ezsys.php:449
eZSys\__isset
__isset( $propertyName)
Definition: ezsys.php:1090
eZSys\fileSeparator
static fileSeparator()
Definition: ezsys.php:256
eZSys\hostname
static hostname()
Definition: ezsys.php:677
eZSys\$LineSeparator
$LineSeparator
Definition: ezsys.php:40
eZSys\wwwDir
static wwwDir()
Definition: ezsys.php:583
eZSys\clientIP
static clientIP()
Definition: ezsys.php:715
eZSys\setEnvironmentVariable
static setEnvironmentVariable( $variableName, $variableValue)
Definition: ezsys.php:935
eZSys\instance
static instance()
Definition: ezsys.php:1273
eZSys\path
static path( $quiet=false)
Definition: ezsys.php:890
eZSys\setAccessPath
static setAccessPath(array $path=array(), $name='undefined', $siteaccess=true)
Definition: ezsys.php:1046
eZSys\$ShellEscapeCharacter
$ShellEscapeCharacter
Definition: ezsys.php:115
eZSys\siteDir
static siteDir()
Definition: ezsys.php:573
eZSys\__get
__get( $propertyName)
Definition: ezsys.php:1075
eZSys\queryString
static queryString()
Definition: ezsys.php:608
eZSys\hasAttribute
hasAttribute( $attr)
Definition: ezsys.php:962
eZSys\backupFilename
static backupFilename()
Definition: ezsys.php:474
eZSys\ezcrc32
static ezcrc32( $string)
Definition: ezsys.php:1298
eZSys\splitArgumentIntoElements
static splitArgumentIntoElements( $argumentText)
Definition: ezsys.php:350
eZSys\init
static init( $index='index.php', $forceVirtualHost=null)
Definition: ezsys.php:1104
eZSys\indexFile
static indexFile( $withAccessPath=true)
Definition: ezsys.php:619
eZSys\varDirectory
static varDirectory()
Definition: ezsys.php:504
eZSys\simulateGlobBrace
static simulateGlobBrace( $filenames)
Definition: ezsys.php:1366
eZSys\$WWWDir
$WWWDir
Definition: ezsys.php:87
eZSys\cacheDirectory
static cacheDirectory()
Definition: ezsys.php:528
$ini
$ini
Definition: classes/admin/linklist.php:64
$result
$result
Definition: companysearch.php:94
$name
$name
Definition: companytypelist.php:194
$siteDir
else $siteDir
Definition: cron_alerts.php:43
file_exists
static file_exists( $inifilename)
Definition: eZPBINIFile.php:195
$cwd
if($_REQUEST['submitted']) else $cwd
Definition: ecommerce/jscalendar/test.php:62
$server
$server
Definition: ezarticle/xmlrpc/xmlrpcserver.php:63
$file
$file
Definition: ezfilemanager/user/filedownload.php:35
$index
$index
Definition: ezforum/user/messageedit.php:36
$element
if(! $parent) $element
Definition: folder.php:64
$elements
$elements
Definition: formedit.php:355
$sys
$sys
Definition: hwinfo.php:47
$url
$url
Definition: messagereviewlist.php:153
$instance
$instance
Definition: orderedit.php:667
$wwwDir
$wwwDir
Definition: singlelist.php:33
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.