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 __construct()
00088     {
00089     }
00090 
00096     public function getRequiredModules()
00097     {
00098         if ( $this->_aRequiredModules == null ) {
00099             $aRequiredPHPExtensions = array(
00100                                           'php_version',
00101                                           'lib_xml2',
00102                                           'php_xml',
00103                                           'j_son',
00104                                           'i_conv',
00105                                           'tokenizer',
00106                                           'mysql_connect',
00107                                           'gd_info',
00108                                           'mb_string',
00109                                       );
00110 
00111                 $aRequiredPHPExtensions[] = 'bc_math';
00112 
00113             $aRequiredPHPConfigs = array(
00114                                        'allow_url_fopen',
00115                                        'php4_compat',
00116                                        'request_uri',
00117                                        'ini_set',
00118                                        'register_globals',
00119                                        'memory_limit',
00120                                        'unicode_support'
00121                                    );
00122 
00123             $aRequiredServerConfigs = array(
00124                                           'mod_rewrite'
00125                                       );
00126 
00127 
00128             $this->_aRequiredModules = array_fill_keys( $aRequiredPHPExtensions, 'php_extennsions' ) +
00129                                        array_fill_keys( $aRequiredPHPConfigs, 'php_config' ) +
00130                                        array_fill_keys( $aRequiredServerConfigs, 'server_config' );
00131         }
00132         return $this->_aRequiredModules;
00133     }
00134 
00140     public function checkMbString()
00141     {
00142         return extension_loaded( 'mbstring' ) ? 2 : 1;
00143     }
00144 
00150     public function checkModRewrite()
00151     {
00152         $iModStat = null;
00153         $sHost   = $_SERVER['HTTP_HOST'];
00154         $sScript = $_SERVER['SCRIPT_NAME'];
00155         if ( $sScript && $rFp = @fsockopen( $sHost, 80, $iErrNo, $sErrStr, 10 ) ) {
00156             $sScript = str_replace( basename($sScript), '../admin/test.php', $sScript );
00157 
00158             $sReq  = "POST $sScript HTTP/1.1\r\n";
00159             $sReq .= "Host: $sHost\r\n";
00160             $sReq .= "User-Agent: oxid setup\r\n";
00161             $sReq .= "Content-Type: application/x-www-form-urlencoded\r\n";
00162             $sReq .= "Content-Length: 0\r\n"; // empty post
00163             $sReq .= "Connection: close\r\n\r\n";
00164 
00165             $sOut = '';
00166             fwrite( $rFp, $sReq );
00167             while ( !feof( $rFp ) ) {
00168                 $sOut .= fgets( $rFp, 100 );
00169             }
00170             fclose( $rFp );
00171 
00172             $iModStat = ( strpos( $sOut, 'mod_rewrite_on' ) !== false ) ? 2 : 0;
00173         } else {
00174             if ( function_exists( 'apache_get_modules' ) ) {
00175                 // it does not assure that mod_rewrite is enabled on current host, so setting 1
00176                 $iModStat = in_array( 'mod_rewrite', apache_get_modules() ) ? 1 : 0;
00177             } else {
00178                 $iModStat = -1;
00179             }
00180         }
00181         return $iModStat;
00182     }
00183 
00189     public function checkAllowUrlFopen()
00190     {
00191         $iModStat = @ini_get('allow_url_fopen');
00192         $iModStat = ( $iModStat && strcasecmp( '1', $iModStat ) ) ? 2 : 1;
00193         if ( $iModStat == 1 ) {
00194             $iErrNo  = 0;
00195             $sErrStr = '';
00196             if ( $oRes = @fsockopen( 'www.example.com', 80, $iErrNo, $sErrStr, 10 ) ) {
00197                 $iModStat = 2;
00198                 fclose( $oRes );
00199             }
00200         }
00201         $iModStat = ( !$iModStat ) ? 1 : $iModStat;
00202         return $iModStat;
00203     }
00204 
00211     public function checkPhp4Compat()
00212     {
00213         $sZendStatus = ( strtolower( (string) @ini_get( 'zend.ze1_compatibility_mode' ) ) );
00214         return in_array( $sZendStatus, array( 'on', '1' ) ) ? 0 : 2;
00215     }
00216 
00223     public function checkPhpVersion()
00224     {
00225         $iModStat = ( version_compare( PHP_VERSION, '5.1', '>' ) ) ? 1 : 0;
00226         $iModStat = ( $iModStat == 0 ) ? $iModStat : ( version_compare( PHP_VERSION, '5.2', '>=' ) ? 2 : 1 );
00227         return $iModStat;
00228     }
00229 
00235     public function checkRequestUri()
00236     {
00237         return ( isset( $_SERVER['REQUEST_URI'] ) || isset( $_SERVER['SCRIPT_URI'] ) ) ? 2 : 0;
00238     }
00239 
00245     public function checkLibXml2()
00246     {
00247         return class_exists( 'DOMDocument' ) ? 2 : 0;
00248     }
00249 
00255     public function checkPhpXml()
00256     {
00257         return class_exists( 'DOMDocument' ) ? 2 : 0;
00258     }
00259 
00265     public function checkJSon()
00266     {
00267         return extension_loaded( 'json' ) ? 2 : 0;
00268     }
00269 
00275     public function checkIConv()
00276     {
00277         return extension_loaded( 'iconv' ) ? 2 : 0;
00278     }
00279 
00285     public function checkTokenizer()
00286     {
00287         return extension_loaded( 'tokenizer' ) ? 2 : 0;
00288     }
00289 
00295     public function checkBcMath()
00296     {
00297         return extension_loaded( 'bcmath' ) ? 2 : 1;
00298     }
00299 
00305     public function checkMysqlConnect()
00306     {
00307         // MySQL module for MySQL5
00308         $iModStat = extension_loaded( 'mysql' ) ? 2 : 0;
00309         // client version must be >=5
00310         if ( $iModStat ) {
00311             $sClientVersion = mysql_get_client_info();
00312             if (version_compare( $sClientVersion, '5', '<' )) {
00313                 $iModStat = 1;
00314                 if (version_compare( $sClientVersion, '4', '<' )) {
00315                     $iModStat = 0;
00316                 }
00317             } elseif (version_compare($sClientVersion, '5.0.36', '>=') && version_compare($sClientVersion, '5.0.38', '<')) {
00318                 // mantis#0001003: Problems with MySQL version 5.0.37
00319                 $iModStat = 0;
00320             }
00321         }
00322         return $iModStat;
00323     }
00324 
00330     public function checkGdInfo()
00331     {
00332         $iModStat = extension_loaded( 'gd' ) ? 1 : 0;
00333         $iModStat = function_exists( 'imagecreatetruecolor' ) ? 2 : $iModStat;
00334         $iModStat = function_exists( 'imagecreatefromjpeg' ) ? $iModStat : 0;
00335         return $iModStat;
00336     }
00337 
00343     public function checkIniSet()
00344     {
00345         return ( @ini_set('session.name', 'sid' ) !== false ) ? 2 : 0;
00346     }
00347 
00353     public function checkRegisterGlobals()
00354     {
00355         $sGlobStatus = ( strtolower( (string) @ini_get( 'register_globals' ) ) );
00356         return in_array( $sGlobStatus, array( 'on', '1' ) ) ? 0 : 2;
00357     }
00358 
00364     public function checkMemoryLimit()
00365     {
00366         if ( $sMemLimit = @ini_get('memory_limit') ) {
00367                 // CE - PE at least to 14 MB. We recomend a memory_limit of 30MB.
00368                 $sDefLimit = '14M';
00369                 $sRecLimit = '30M';
00370 
00371 
00372             $iMemLimit = $this->_getBytes( $sMemLimit );
00373             $iModStat = ( $iMemLimit >= $this->_getBytes( $sDefLimit ) ) ? 1 : 0;
00374             $iModStat = $iModStat ? ( ( $iMemLimit >= $this->_getBytes( $sRecLimit ) ) ? 2 : $iModStat ) : $iModStat;
00375 
00376         } else {
00377             $iModStat = -1;
00378         }
00379         return $iModStat;
00380     }
00381 
00387     public function checkZendOptimizer()
00388     {
00389         $iMinStat = 0;
00390         $iModStat = extension_loaded( 'Zend Optimizer' ) ? 2 : $iMinStat;
00391         $sHost   = $_SERVER['HTTP_HOST'];
00392         $sScript = $_SERVER['SCRIPT_NAME'];
00393         if ( $iModStat > $iMinStat && $sScript && $rFp = @fsockopen( $sHost, 80, $iErrNo, $sErrStr, 10 ) ) {
00394             $sScript = str_replace( basename($sScript), '../admin/index.php', $sScript );
00395 
00396             $sReq  = "POST $sScript HTTP/1.1\r\n";
00397             $sReq .= "Host: $sHost\r\n";
00398             $sReq .= "User-Agent: oxid setup\r\n";
00399             $sReq .= "Content-Type: application/x-www-form-urlencoded\r\n";
00400             $sReq .= "Content-Length: 0\r\n"; // empty post
00401             $sReq .= "Connection: close\r\n\r\n";
00402 
00403             $sOut = '';
00404             fwrite( $rFp, $sReq );
00405             while ( !feof( $rFp ) ) {
00406                 $sOut .= fgets( $rFp, 100 );
00407             }
00408 
00409             $iModStat = ( strpos( $sOut, 'Zend Optimizer not installed' ) !== false ) ? $iMinStat : 2;
00410             fclose( $rFp );
00411         }
00412         if ( $iModStat > $iMinStat && $sScript && $rFp = @fsockopen( $sHost, 80, $iErrNo, $sErrStr, 10 ) ) {
00413             $sScript = str_replace( basename($sScript), '../index.php', $sScript );
00414 
00415             $sReq  = "POST $sScript HTTP/1.1\r\n";
00416             $sReq .= "Host: $sHost\r\n";
00417             $sReq .= "User-Agent: oxid setup\r\n";
00418             $sReq .= "Content-Type: application/x-www-form-urlencoded\r\n";
00419             $sReq .= "Content-Length: 0\r\n"; // empty post
00420             $sReq .= "Connection: close\r\n\r\n";
00421 
00422             $sOut = '';
00423             fwrite( $rFp, $sReq );
00424             while ( !feof( $rFp ) ) {
00425                 $sOut .= fgets( $rFp, 100 );
00426             }
00427             $iModStat = ( strpos( $sOut, 'Zend Optimizer not installed' ) !== false ) ? $iMinStat : 2;
00428             fclose( $rFp );
00429         }
00430         return $iModStat;
00431     }
00432 
00438     public function checkZendPlatform()
00439     {
00440         return function_exists( 'output_cache_get' ) ? 2 : 1;
00441     }
00442 
00448     protected function _getAdditionalCheck()
00449     {
00450         $sSelect = '';
00451         foreach ( $this->_aException as $sTable => $sColumn ) {
00452             $sSelect .= 'and ( t.TABLE_NAME != "'.$sTable.'" and c.COLUMN_NAME != "'.$sColumn.'" ) ';
00453         }
00454         return $sSelect;
00455     }
00456 
00462     public function checkCollation()
00463     {
00464         $myConfig = oxConfig::getInstance();
00465 
00466         $aCollations = array();
00467         $sCollation = '';
00468 
00469         $sSelect = 'select t.TABLE_NAME, c.COLUMN_NAME, c.COLLATION_NAME from INFORMATION_SCHEMA.tables t ' .
00470                    'LEFT JOIN INFORMATION_SCHEMA.columns c ON t.TABLE_NAME = c.TABLE_NAME  ' .
00471                    'where t.TABLE_SCHEMA = "'.$myConfig->getConfigParam( 'dbName' ).'" ' .
00472                    'and c.TABLE_SCHEMA = "'.$myConfig->getConfigParam( 'dbName' ).'" ' .
00473                    'and c.COLUMN_NAME in ("'.implode('", "', $this->_aColumns).'") ' . $this->_getAdditionalCheck() .
00474                    ' ORDER BY (t.TABLE_NAME = "oxarticles") DESC';
00475         $aRez = oxDb::getDb()->getAll($sSelect);
00476         foreach ( $aRez as $aRetTable ) {
00477             if ( !$sCollation ) {
00478                 $sCollation = $aRetTable[2];
00479             } else {
00480                 if ( $aRetTable[2] && $sCollation != $aRetTable[2]) {
00481                     $aCollations[$aRetTable[0]][$aRetTable[1]] = $aRetTable[2];
00482                 }
00483             }
00484         }
00485 
00486         if ( $this->_blSysReqStatus === null ) {
00487             $this->_blSysReqStatus = true;
00488         }
00489         if ( count($aCollations) > 0 ) {
00490             $this->_blSysReqStatus = false;
00491         }
00492         return $aCollations;
00493     }
00494 
00500     public function checkDatabaseCluster()
00501     {
00502         return 2;
00503     }
00504 
00510     public function checkUnicodeSupport()
00511     {
00512         return (@preg_match('/\pL/u', 'a') == 1) ? 2 : 1;
00513     }
00514 
00520     public function getSysReqStatus()
00521     {
00522         if ( $this->_blSysReqStatus == null ) {
00523             $this->_blSysReqStatus = true;
00524             $this->getSystemInfo();
00525             $this->checkCollation();
00526         }
00527         return $this->_blSysReqStatus;
00528     }
00529 
00544     public function getSystemInfo()
00545     {
00546         $aSysInfo = array();
00547         $aRequiredModules = $this->getRequiredModules();
00548         $this->_blSysReqStatus = true;
00549         foreach ( $aRequiredModules as $sModule => $sGroup ) {
00550             if ( isset($aSysInfo[$sGroup]) && !$aSysInfo[$sGroup] ) {
00551                 $aSysInfo[$sGroup] = array();
00552             }
00553             $iModuleState = $this->getModuleInfo( $sModule );
00554             $aSysInfo[$sGroup][$sModule] = $iModuleState;
00555             $this->_blSysReqStatus = $this->_blSysReqStatus && ( bool ) abs( $iModuleState );
00556         }
00557         return $aSysInfo;
00558     }
00559 
00567     public function getModuleInfo( $sModule = null )
00568     {
00569         if ( $sModule ) {
00570             $iModStat = null;
00571             $sCheckFunction = "check".str_replace(" ", "", ucwords(str_replace("_", " ", $sModule)));
00572             $iModStat = $this->$sCheckFunction();
00573 
00574             return $iModStat;
00575         }
00576     }
00577 
00585     protected function _getBytes( $sBytes )
00586     {
00587         $sBytes = trim( $sBytes );
00588         $sLast = strtolower($sBytes[strlen($sBytes)-1]);
00589         switch( $sLast ) {
00590             // The 'G' modifier is available since PHP 5.1.0
00591             case 'g':
00592                 $sBytes *= 1024;
00593             case 'm':
00594                 $sBytes *= 1024;
00595             case 'k':
00596                 $sBytes *= 1024;
00597                 break;
00598         }
00599 
00600         return $sBytes;
00601     }
00602 
00603 }

Generated on Tue Sep 29 16:45:13 2009 for OXID eShop CE by  doxygen 1.5.5