oxsysrequirements.php

Go to the documentation of this file.
00001 <?php
00002 
00006 class oxSysRequirements
00007 {
00013     protected $_aRequiredModules = null;
00014 
00020     protected $_blSysReqStatus = null;
00021 
00027     protected $_aException = array( 'OXDELIVERY'   => 'OXDELTYPE',
00028                                     'OXSELECTLIST' => 'OXIDENT');
00029 
00035     protected $_aColumns = array( 'OXID',
00036                                   'OXOBJECTID',
00037                                   'OXARTICLENID',
00038                                   'OXACTIONID',
00039                                   'OXARTID',
00040                                   'OXUSERID',
00041                                   'OXADDRESSUSERID',
00042                                   'OXCOUNTRYID',
00043                                   'OXSESSID',
00044                                   'OXITMID',
00045                                   'OXPARENTID',
00046                                   'OXAMITEMID',
00047                                   'OXAMTASKID',
00048                                   'OXVENDORID',
00049                                   'OXMANUFACTURERID',
00050                                   'OXROOTID',
00051                                   'OXATTRID',
00052                                   'OXCATID',
00053                                   'OXDELID',
00054                                   'OXDELSETID',
00055                                   'OXITMARTID',
00056                                   'OXFIELDID',
00057                                   'OXROLEID',
00058                                   'OXCNID',
00059                                   'OXANID',
00060                                   'OXARTICLENID',
00061                                   'OXCATNID',
00062                                   'OXDELIVERYID',
00063                                   'OXDISCOUNTID',
00064                                   'OXGROUPSID',
00065                                   'OXLISTID',
00066                                   'OXPAYMENTID',
00067                                   'OXDELTYPE',
00068                                   'OXROLEID',
00069                                   'OXSELNID',
00070                                   'OXBILLCOUNTRYID',
00071                                   'OXDELCOUNTRYID',
00072                                   'OXPAYMENTID',
00073                                   'OXCARDID',
00074                                   'OXPAYID',
00075                                   'OXIDENT',
00076                                   'OXDEFCAT',
00077                                   'OXBASKETID',
00078                                   'OXPAYMENTSID',
00079                                   'OXORDERID',
00080                                   'OXVOUCHERSERIEID');
00081 
00087     public function getRequiredModules()
00088     {
00089         if ( $this->_aRequiredModules == null ) {
00090             $aRequiredPHPExtensions = array(
00091                                           'phpversion',
00092                                           'libxml2',
00093                                           'php-xml',
00094                                           'json',
00095                                           'iconv',
00096                                           'tokenizer',
00097                                           'mysql_connect',
00098                                           'gd_info',
00099                                           'mb_string',
00100                                       );
00101 
00102                 $aRequiredPHPExtensions[] = 'bcmath';
00103 
00104             $aRequiredPHPConfigs = array(
00105                                        'allow_url_fopen',
00106                                        'php4_compat',
00107                                        'request_uri',
00108                                        'ini_set',
00109                                        'register_globals',
00110                                        'memory_limit',
00111                                        'unicode_support'
00112                                    );
00113 
00114             $aRequiredServerConfigs = array(
00115                                           'mod_rewrite'
00116                                       );
00117 
00118 
00119             $this->_aRequiredModules = array_fill_keys( $aRequiredPHPExtensions, 'php_extennsions' ) +
00120                                        array_fill_keys( $aRequiredPHPConfigs, 'php_config' ) +
00121                                        array_fill_keys( $aRequiredServerConfigs, 'server_config' );
00122         }
00123         return $this->_aRequiredModules;
00124     }
00125 
00131     public function checkMbString()
00132     {
00133         return extension_loaded( 'mbstring' ) ? 2 : 1;
00134     }
00135 
00141     public function checkModRewrite()
00142     {
00143         $iModStat = null;
00144         $sHost   = $_SERVER['HTTP_HOST'];
00145         $sScript = $_SERVER['SCRIPT_NAME'];
00146         if ( $sScript && $rFp = @fsockopen( $sHost, 80, $iErrNo, $sErrStr, 10 ) ) {
00147             $sScript = str_replace( basename($sScript), '../admin/test.php', $sScript );
00148 
00149             $sReq  = "POST $sScript HTTP/1.1\r\n";
00150             $sReq .= "Host: $sHost\r\n";
00151             $sReq .= "User-Agent: oxid setup\r\n";
00152             $sReq .= "Content-Type: application/x-www-form-urlencoded\r\n";
00153             $sReq .= "Content-Length: 0\r\n"; // empty post
00154             $sReq .= "Connection: close\r\n\r\n";
00155 
00156             $sOut = '';
00157             fwrite( $rFp, $sReq );
00158             while ( !feof( $rFp ) ) {
00159                 $sOut .= fgets( $rFp, 100 );
00160             }
00161             fclose( $rFp );
00162 
00163             $iModStat = ( strpos( $sOut, 'mod_rewrite_on' ) !== false ) ? 2 : 0;
00164         } else {
00165             if ( function_exists( 'apache_get_modules' ) ) {
00166                 // it does not assure that mod_rewrite is enabled on current host, so setting 1
00167                 $iModStat = in_array( 'mod_rewrite', apache_get_modules() ) ? 1 : 0;
00168             } else {
00169                 $iModStat = -1;
00170             }
00171         }
00172         return $iModStat;
00173     }
00174 
00180     public function checkAllowUrlFopen()
00181     {
00182         $iModStat = @ini_get('allow_url_fopen');
00183         $iModStat = ( $iModStat && strcasecmp( '1', $iModStat ) ) ? 2 : 1;
00184         if ( $iModStat == 1 ) {
00185             $iErrNo  = 0;
00186             $sErrStr = '';
00187             if ( $oRes = @fsockopen( 'www.oxid-esales.com', 80, $iErrNo, $sErrStr, 10 ) ) {
00188                 $iModStat = 2;
00189                 fclose( $oRes );
00190             }
00191         }
00192         $iModStat = ( !$iModStat ) ? 1 : $iModStat;
00193         return $iModStat;
00194     }
00195 
00202     public function checkPhp4Compat()
00203     {
00204         $sZendStatus = ( strtolower( (string) @ini_get( 'zend.ze1_compatibility_mode' ) ) );
00205         return in_array( $sZendStatus, array( 'on', '1' ) ) ? 0 : 2;
00206     }
00207 
00214     public function checkPhpVersion()
00215     {
00216         $iModStat = ( version_compare( PHP_VERSION, '5.1', '>' ) ) ? 1 : 0;
00217         $iModStat = ( $iModStat == 0 ) ? $iModStat : ( version_compare( PHP_VERSION, '5.2', '>=' ) ? 2 : 1 );
00218         return $iModStat;
00219     }
00220 
00226     public function checkRequestUri()
00227     {
00228         return ( isset( $_SERVER['REQUEST_URI'] ) || isset( $_SERVER['SCRIPT_URI'] ) ) ? 2 : 0;
00229     }
00230 
00236     public function checkLibXml2()
00237     {
00238         return class_exists( 'DOMDocument' ) ? 2 : 0;
00239     }
00240 
00246     public function checkPhpXml()
00247     {
00248         return class_exists( 'DOMDocument' ) ? 2 : 0;
00249     }
00250 
00256     public function checkJSon()
00257     {
00258         return extension_loaded( 'json' ) ? 2 : 0;
00259     }
00260 
00266     public function checkIConv()
00267     {
00268         return extension_loaded( 'iconv' ) ? 2 : 0;
00269     }
00270 
00276     public function checkTokenizer()
00277     {
00278         return extension_loaded( 'tokenizer' ) ? 2 : 0;
00279     }
00280 
00286     public function checkBcMath()
00287     {
00288         return extension_loaded( 'bcmath' ) ? 2 : 1;
00289     }
00290 
00296     public function checkMysqlConnect()
00297     {
00298         // MySQL module for MySQL5
00299         $iModStat = extension_loaded( 'mysql' ) ? 2 : 0;
00300         // client version must be >=5
00301         if ( $iModStat ) {
00302             $sClientVersion = mysql_get_client_info();
00303             $iModStat = version_compare( mysql_get_client_info(), '5', '>=' ) ? $iModStat : 1;
00304             // notice if client version < 5
00305             if ( $iModStat == 1) {
00306                 $iModStat = version_compare( mysql_get_client_info(), '4', '>=' ) ? $iModStat : 0;
00307             }
00308         }
00309         return $iModStat;
00310     }
00311 
00317     public function checkGdInfo()
00318     {
00319         $iModStat = extension_loaded( 'gd' ) ? 1 : 0;
00320         $iModStat = function_exists( 'imagecreatetruecolor' ) ? 2 : $iModStat;
00321         $iModStat = function_exists( 'imagecreatefromjpeg' ) ? $iModStat : 0;
00322         return $iModStat;
00323     }
00324 
00330     public function checkIniSet()
00331     {
00332         return ( @ini_set('session.name', 'sid' ) !== false ) ? 2 : 0;
00333     }
00334 
00340     public function checkRegisterGlobals()
00341     {
00342         $sGlobStatus = ( strtolower( (string) @ini_get( 'register_globals' ) ) );
00343         return in_array( $sGlobStatus, array( 'on', '1' ) ) ? 0 : 2;
00344     }
00345 
00351     public function checkMemoryLimit()
00352     {
00353         if ( $sMemLimit = @ini_get('memory_limit') ) {
00354                 // CE - PE at least to 14 MB. We recomend a memory_limit of 30MB.
00355                 $sDefLimit = '14M';
00356                 $sRecLimit = '30M';
00357 
00358 
00359             $iMemLimit = $this->_getBytes( $sMemLimit );
00360             $iModStat = ( $iMemLimit >= $this->_getBytes( $sDefLimit ) ) ? 1 : 0;
00361             $iModStat = $iModStat ? ( ( $iMemLimit >= $this->_getBytes( $sRecLimit ) ) ? 2 : $iModStat ) : $iModStat;
00362 
00363         } else {
00364             $iModStat = -1;
00365         }
00366         return $iModStat;
00367     }
00368 
00374     public function checkZendOptimizer()
00375     {
00376         $iModStat = extension_loaded( 'Zend Optimizer' ) ? 2 : 0;
00377         $sHost   = $_SERVER['HTTP_HOST'];
00378         $sScript = $_SERVER['SCRIPT_NAME'];
00379         if ( $iModStat > 0 && $sScript && $rFp = @fsockopen( $sHost, 80, $iErrNo, $sErrStr, 10 ) ) {
00380             $sScript = str_replace( basename($sScript), '../admin/index.php', $sScript );
00381 
00382             $sReq  = "POST $sScript HTTP/1.1\r\n";
00383             $sReq .= "Host: $sHost\r\n";
00384             $sReq .= "User-Agent: oxid setup\r\n";
00385             $sReq .= "Content-Type: application/x-www-form-urlencoded\r\n";
00386             $sReq .= "Content-Length: 0\r\n"; // empty post
00387             $sReq .= "Connection: close\r\n\r\n";
00388 
00389             $sOut = '';
00390             fwrite( $rFp, $sReq );
00391             while ( !feof( $rFp ) ) {
00392                 $sOut .= fgets( $rFp, 100 );
00393             }
00394 
00395             $iModStat = ( strpos( $sOut, 'Zend Optimizer not installed' ) !== false ) ? 0 : 2;
00396             fclose( $rFp );
00397         }
00398         if ( $iModStat > 0 && $sScript && $rFp = @fsockopen( $sHost, 80, $iErrNo, $sErrStr, 10 ) ) {
00399             $sScript = str_replace( basename($sScript), '../index.php', $sScript );
00400 
00401             $sReq  = "POST $sScript HTTP/1.1\r\n";
00402             $sReq .= "Host: $sHost\r\n";
00403             $sReq .= "User-Agent: oxid setup\r\n";
00404             $sReq .= "Content-Type: application/x-www-form-urlencoded\r\n";
00405             $sReq .= "Content-Length: 0\r\n"; // empty post
00406             $sReq .= "Connection: close\r\n\r\n";
00407 
00408             $sOut = '';
00409             fwrite( $rFp, $sReq );
00410             while ( !feof( $rFp ) ) {
00411                 $sOut .= fgets( $rFp, 100 );
00412             }
00413             $iModStat = ( strpos( $sOut, 'Zend Optimizer not installed' ) !== false ) ? 0 : 2;
00414             fclose( $rFp );
00415         }
00416         return $iModStat;
00417     }
00418 
00424     public function checkZendPlatform()
00425     {
00426         return function_exists( 'output_cache_get' ) ? 2 : 1;
00427     }
00428 
00434     protected function _getAdditionalCheck()
00435     {
00436         $sSelect = '';
00437         foreach ( $this->_aException as $sTable => $sColumn ) {
00438             $sSelect .= 'and ( t.TABLE_NAME != "'.$sTable.'" and c.COLUMN_NAME != "'.$sColumn.'" ) ';
00439         }
00440         return $sSelect;
00441     }
00442 
00448     public function checkCollation()
00449     {
00450         $myConfig = oxConfig::getInstance();
00451 
00452         $aCollations = array();
00453         $sCollation = '';
00454 
00455         $sSelect = 'select t.TABLE_NAME, c.COLUMN_NAME, c.COLLATION_NAME from INFORMATION_SCHEMA.tables t ' .
00456                    'LEFT JOIN INFORMATION_SCHEMA.columns c ON t.TABLE_NAME = c.TABLE_NAME  ' .
00457                    'where t.TABLE_SCHEMA = "'.$myConfig->getConfigParam( 'dbName' ).'" ' .
00458                    'and c.TABLE_SCHEMA = "'.$myConfig->getConfigParam( 'dbName' ).'" ' .
00459                    'and c.COLUMN_NAME in ("'.implode('", "', $this->_aColumns).'") ' . $this->_getAdditionalCheck() . 
00460                    ' ORDER BY (t.TABLE_NAME = "oxarticles") DESC';
00461         $aRez = oxDb::getDb()->getAll($sSelect);
00462         foreach ( $aRez as $aRetTable ) {
00463             if ( !$sCollation ) {
00464                 $sCollation = $aRetTable[2];
00465             } else {
00466                 if ( $aRetTable[2] && $sCollation != $aRetTable[2]) {
00467                     $aCollations[$aRetTable[0]][$aRetTable[1]] = $aRetTable[2];
00468                 }
00469             }
00470         }
00471 
00472         $this->_blSysReqStatus = true;
00473         if ( count($aCollations) > 0 ) {
00474             $this->_blSysReqStatus = false;
00475         }
00476         return $aCollations;
00477     }
00478 
00484     public function checkDatabaseCluster()
00485     {
00486         return 2;
00487     }
00488 
00494     public function checkUnicodeSupport()
00495     {
00496         return (@preg_match('/\pL/u', 'a') == 1) ? 2 : 1;
00497     }
00498 
00504     public function getSysReqStatus()
00505     {
00506         if ( $this->_blSysReqStatus == null ) {
00507             $this->getSystemInfo();
00508             $this->checkCollation();
00509         }
00510         return $this->_blSysReqStatus;
00511     }
00512 
00527     public function getSystemInfo()
00528     {
00529         $aSysInfo = array();
00530         $aRequiredModules = $this->getRequiredModules();
00531         $this->_blSysReqStatus = true;
00532         foreach ( $aRequiredModules as $sModule => $sGroup ) {
00533             if ( !$aSysInfo[$sGroup] ) {
00534                 $aSysInfo[$sGroup] = array();
00535             }
00536             $iModuleState = $this->getModuleInfo( $sModule );
00537             $aSysInfo[$sGroup][$sModule] = $iModuleState;
00538             $this->_blSysReqStatus = $this->_blSysReqStatus && ( bool ) abs( $iModuleState );
00539         }
00540         return $aSysInfo;
00541     }
00542 
00550     public function getModuleInfo( $sModule = null )
00551     {
00552         if ( $sModule ) {
00553             $iModStat = null;
00554             switch ( $sModule ) {
00555                 case 'mb_string':
00556                     $iModStat = $this->checkMbString();
00557                     break;
00558                 case 'mod_rewrite':
00559                     $iModStat = $this->checkModRewrite();
00560                     break;
00561                 case 'allow_url_fopen':
00562                     $iModStat = $this->checkAllowUrlFopen();
00563                     break;
00564                 case 'php4_compat':
00565                     $iModStat = $this->checkPhp4Compat();
00566                     break;
00567                 case 'phpversion':
00568                     $iModStat = $this->checkPhp4Compat();
00569                     break;
00570                 case 'request_uri':
00571                     $iModStat = $this->checkRequestUri();
00572                     break;
00573                 case 'libxml2':
00574                     $iModStat = $this->checkLibXml2();
00575                     break;
00576                 case 'php-xml':
00577                     $iModStat = $this->checkPhpXml();
00578                     break;
00579                 case 'json':
00580                     $iModStat = $this->checkJSon();
00581                     break;
00582                 case 'iconv':
00583                     $iModStat = $this->checkIConv();
00584                     break;
00585                 case 'tokenizer':
00586                     $iModStat = $this->checkTokenizer();
00587                     break;
00588                 case 'bcmath':
00589                     $iModStat = $this->checkBcMath();
00590                     break;
00591                 case 'mysql_connect':
00592                     $iModStat = $this->checkMysqlConnect();
00593                     break;
00594                 case 'gd_info':
00595                     $iModStat = $this->checkGdInfo();
00596                     break;
00597                 case 'ini_set':
00598                     $iModStat = $this->checkIniSet();
00599                     break;
00600                 case 'register_globals':
00601                     $iModStat = $this->checkRegisterGlobals();
00602                     break;
00603                 case 'memory_limit':
00604                     $iModStat = $this->checkMemoryLimit();
00605                     break;
00606                 case 'unicode_support':
00607                     $iModStat = $this->checkUnicodeSupport();
00608                     break;
00609             }
00610 
00611 
00612             return $iModStat;
00613         }
00614     }
00615 
00623     protected function _getBytes( $sBytes )
00624     {
00625         $sBytes = trim( $sBytes );
00626         $sLast = strtolower($sBytes[strlen($sBytes)-1]);
00627         switch( $sLast ) {
00628             // The 'G' modifier is available since PHP 5.1.0
00629             case 'g':
00630                 $sBytes *= 1024;
00631             case 'm':
00632                 $sBytes *= 1024;
00633             case 'k':
00634                 $sBytes *= 1024;
00635                 break;
00636         }
00637 
00638         return $sBytes;
00639     }
00640 
00641 }

Generated on Wed May 13 13:25:51 2009 for OXID eShop CE by  doxygen 1.5.5