Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

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