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         $iModStat = extension_loaded( 'Zend Optimizer' ) ? 2 : 0;
00390         $sHost   = $_SERVER['HTTP_HOST'];
00391         $sScript = $_SERVER['SCRIPT_NAME'];
00392         if ( $iModStat > 0 && $sScript && $rFp = @fsockopen( $sHost, 80, $iErrNo, $sErrStr, 10 ) ) {
00393             $sScript = str_replace( basename($sScript), '../admin/index.php', $sScript );
00394 
00395             $sReq  = "POST $sScript HTTP/1.1\r\n";
00396             $sReq .= "Host: $sHost\r\n";
00397             $sReq .= "User-Agent: oxid setup\r\n";
00398             $sReq .= "Content-Type: application/x-www-form-urlencoded\r\n";
00399             $sReq .= "Content-Length: 0\r\n"; // empty post
00400             $sReq .= "Connection: close\r\n\r\n";
00401 
00402             $sOut = '';
00403             fwrite( $rFp, $sReq );
00404             while ( !feof( $rFp ) ) {
00405                 $sOut .= fgets( $rFp, 100 );
00406             }
00407 
00408             $iModStat = ( strpos( $sOut, 'Zend Optimizer not installed' ) !== false ) ? 0 : 2;
00409             fclose( $rFp );
00410         }
00411         if ( $iModStat > 0 && $sScript && $rFp = @fsockopen( $sHost, 80, $iErrNo, $sErrStr, 10 ) ) {
00412             $sScript = str_replace( basename($sScript), '../index.php', $sScript );
00413 
00414             $sReq  = "POST $sScript HTTP/1.1\r\n";
00415             $sReq .= "Host: $sHost\r\n";
00416             $sReq .= "User-Agent: oxid setup\r\n";
00417             $sReq .= "Content-Type: application/x-www-form-urlencoded\r\n";
00418             $sReq .= "Content-Length: 0\r\n"; // empty post
00419             $sReq .= "Connection: close\r\n\r\n";
00420 
00421             $sOut = '';
00422             fwrite( $rFp, $sReq );
00423             while ( !feof( $rFp ) ) {
00424                 $sOut .= fgets( $rFp, 100 );
00425             }
00426             $iModStat = ( strpos( $sOut, 'Zend Optimizer not installed' ) !== false ) ? 0 : 2;
00427             fclose( $rFp );
00428         }
00429         return $iModStat;
00430     }
00431 
00437     public function checkZendPlatform()
00438     {
00439         return function_exists( 'output_cache_get' ) ? 2 : 1;
00440     }
00441 
00447     protected function _getAdditionalCheck()
00448     {
00449         $sSelect = '';
00450         foreach ( $this->_aException as $sTable => $sColumn ) {
00451             $sSelect .= 'and ( t.TABLE_NAME != "'.$sTable.'" and c.COLUMN_NAME != "'.$sColumn.'" ) ';
00452         }
00453         return $sSelect;
00454     }
00455 
00461     public function checkCollation()
00462     {
00463         $myConfig = oxConfig::getInstance();
00464 
00465         $aCollations = array();
00466         $sCollation = '';
00467 
00468         $sSelect = 'select t.TABLE_NAME, c.COLUMN_NAME, c.COLLATION_NAME from INFORMATION_SCHEMA.tables t ' .
00469                    'LEFT JOIN INFORMATION_SCHEMA.columns c ON t.TABLE_NAME = c.TABLE_NAME  ' .
00470                    'where t.TABLE_SCHEMA = "'.$myConfig->getConfigParam( 'dbName' ).'" ' .
00471                    'and c.TABLE_SCHEMA = "'.$myConfig->getConfigParam( 'dbName' ).'" ' .
00472                    'and c.COLUMN_NAME in ("'.implode('", "', $this->_aColumns).'") ' . $this->_getAdditionalCheck() .
00473                    ' ORDER BY (t.TABLE_NAME = "oxarticles") DESC';
00474         $aRez = oxDb::getDb()->getAll($sSelect);
00475         foreach ( $aRez as $aRetTable ) {
00476             if ( !$sCollation ) {
00477                 $sCollation = $aRetTable[2];
00478             } else {
00479                 if ( $aRetTable[2] && $sCollation != $aRetTable[2]) {
00480                     $aCollations[$aRetTable[0]][$aRetTable[1]] = $aRetTable[2];
00481                 }
00482             }
00483         }
00484 
00485         if ( $this->_blSysReqStatus === null ) {
00486             $this->_blSysReqStatus = true;
00487         }
00488         if ( count($aCollations) > 0 ) {
00489             $this->_blSysReqStatus = false;
00490         }
00491         return $aCollations;
00492     }
00493 
00499     public function checkDatabaseCluster()
00500     {
00501         return 2;
00502     }
00503 
00509     public function checkUnicodeSupport()
00510     {
00511         return (@preg_match('/\pL/u', 'a') == 1) ? 2 : 1;
00512     }
00513 
00519     public function getSysReqStatus()
00520     {
00521         if ( $this->_blSysReqStatus == null ) {
00522             $this->_blSysReqStatus = true;
00523             $this->getSystemInfo();
00524             $this->checkCollation();
00525         }
00526         return $this->_blSysReqStatus;
00527     }
00528 
00543     public function getSystemInfo()
00544     {
00545         $aSysInfo = array();
00546         $aRequiredModules = $this->getRequiredModules();
00547         $this->_blSysReqStatus = true;
00548         foreach ( $aRequiredModules as $sModule => $sGroup ) {
00549             if ( isset($aSysInfo[$sGroup]) && !$aSysInfo[$sGroup] ) {
00550                 $aSysInfo[$sGroup] = array();
00551             }
00552             $iModuleState = $this->getModuleInfo( $sModule );
00553             $aSysInfo[$sGroup][$sModule] = $iModuleState;
00554             $this->_blSysReqStatus = $this->_blSysReqStatus && ( bool ) abs( $iModuleState );
00555         }
00556         return $aSysInfo;
00557     }
00558 
00566     public function getModuleInfo( $sModule = null )
00567     {
00568         if ( $sModule ) {
00569             $iModStat = null;
00570             $sCheckFunction = "check".str_replace(" ","",ucwords(str_replace("_"," ",$sModule)));
00571             $iModStat = $this->$sCheckFunction();
00572 
00573             return $iModStat;
00574         }
00575     }
00576 
00584     protected function _getBytes( $sBytes )
00585     {
00586         $sBytes = trim( $sBytes );
00587         $sLast = strtolower($sBytes[strlen($sBytes)-1]);
00588         switch( $sLast ) {
00589             // The 'G' modifier is available since PHP 5.1.0
00590             case 'g':
00591                 $sBytes *= 1024;
00592             case 'm':
00593                 $sBytes *= 1024;
00594             case 'k':
00595                 $sBytes *= 1024;
00596                 break;
00597         }
00598 
00599         return $sBytes;
00600     }
00601 
00602 }

Generated on Tue Aug 18 09:21:06 2009 for OXID eShop CE by  doxygen 1.5.5