|
eZ Publish
[trunk]
|
00001 <?php 00002 /** 00003 * File containing pre check functions as used to validate request 00004 * 00005 * @copyright Copyright (C) 1999-2012 eZ Systems AS. All rights reserved. 00006 * @license http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2 00007 * @version //autogentag// 00008 * @package index 00009 */ 00010 00011 /** 00012 * Checks if the installation is valid and returns a module redirect if required. 00013 * If CheckValidity in SiteAccessSettings is false then no check is done. 00014 * 00015 * @deprecated As of 4.4, moved to index.php for now 00016 * @param array $siteBasics 00017 * @param eZURI $uri 00018 */ 00019 function eZCheckValidity( array &$siteBasics, eZURI $uri ) 00020 { 00021 eZDebug::writeStrict( 'Function eZCheckValidity() has been deprecated in 4.4', 'Deprecation' ); 00022 $ini = eZINI::instance(); 00023 $checkValidity = ( $ini->variable( "SiteAccessSettings", "CheckValidity" ) == "true" ); 00024 $check = null; 00025 if ( $checkValidity ) 00026 { 00027 $check = array( "module" => "setup", 00028 'function' => 'init' ); 00029 // Turn off some features that won't bee needed yet 00030 // $siteBasics['policy-check-required'] = false; 00031 $siteBasics['policy-check-omit-list'][] = 'setup'; 00032 $siteBasics['url-translator-allowed'] = false; 00033 $siteBasics['show-page-layout'] = $ini->variable( 'SetupSettings', 'PageLayout' ); 00034 $siteBasics['validity-check-required'] = true; 00035 $siteBasics['user-object-required'] = false; 00036 $siteBasics['session-required'] = false; 00037 $siteBasics['db-required'] = false; 00038 $siteBasics['no-cache-adviced'] = false; 00039 $siteBasics['site-design-override'] = $ini->variable( 'SetupSettings', 'OverrideSiteDesign' ); 00040 $access = array( 'name' => 'setup', 00041 'type' => eZSiteAccess::TYPE_URI ); 00042 $access = eZSiteAccess::change( $access ); 00043 00044 eZTranslatorManager::enableDynamicTranslations(); 00045 } 00046 return $check; 00047 } 00048 00049 /** 00050 * List of functions that should be checked by key identifier 00051 * 00052 * @deprecated As of 4.4, since SitePrecheckRules setting is not used or documented anywhere 00053 * (documentation above was added when it was deprecated) 00054 * Also validity checks needs to be done before session init and user check after.. 00055 * @return array An associative array with items to run a check on, each items 00056 * is an associative array. The item must contain: function -> name of the function 00057 */ 00058 function eZCheckList() 00059 { 00060 $checks = array(); 00061 $checks['validity'] = array( 'function' => 'eZCheckValidity' ); 00062 $checks['user'] = array( 'function' => 'eZCheckUser' ); 00063 return $checks; 00064 } 00065 00066 /** 00067 * Check if user login is required. If so, use login handler to redirect user. 00068 * 00069 * @deprecated As of 4.4, moved to {@link eZUserLoginHandler::preCheck()} 00070 * @param array $siteBasics 00071 * @param eZURI $uri 00072 * @return array|true|false|null An associative array on redirect with 'module' and 'function' keys, true on successful 00073 * and false/null on #fail. 00074 */ 00075 function eZCheckUser( array &$siteBasics, eZURI $uri ) 00076 { 00077 eZDebug::writeStrict( 'Function eZCheckUser() has been deprecated in 4.4 in favor of eZUserLoginHandler::preCheck()', 'Deprecation' ); 00078 if ( !$siteBasics['user-object-required'] ) 00079 { 00080 return null; 00081 } 00082 00083 $ini = eZINI::instance(); 00084 $requireUserLogin = ( $ini->variable( 'SiteAccessSettings', 'RequireUserLogin' ) == 'true' ); 00085 $forceLogin = false; 00086 if ( eZSession::hasStarted() ) 00087 { 00088 $http = eZHTTPTool::instance(); 00089 $forceLogin = $http->hasSessionVariable( eZUserLoginHandler::FORCE_LOGIN ); 00090 } 00091 if ( !$requireUserLogin && !$forceLogin ) 00092 { 00093 return null; 00094 } 00095 00096 return eZUserLoginHandler::checkUser( $siteBasics, $uri ); 00097 } 00098 00099 /** 00100 * Return the order that prechecks should be checked 00101 * 00102 * @deprecated As of 4.4, since SitePrecheckRules setting is not used or documented anywhere 00103 * (documentation above was added when it was deprecated) 00104 * Also validity checks needs to be done before session init and user check after.. 00105 * @return array 00106 */ 00107 function eZCheckOrder() 00108 { 00109 return array( 'validity', 'user' ); 00110 } 00111 00112 /** 00113 * Executes pre checks 00114 * 00115 * @deprecated As of 4.4, since SitePrecheckRules setting is not used or documented anywhere 00116 * (documentation above was added when it was deprecated) 00117 * Also validity checks needs to be done before session init and user check after.. 00118 * @param array $siteBasics 00119 * @param eZURI $uri 00120 * @return array|null A structure with redirection information or null if nothing should be done. 00121 */ 00122 function eZHandlePreChecks( array &$siteBasics, eZURI $uri ) 00123 { 00124 $checks = eZCheckList(); 00125 $checks = precheckAllowed( $checks ); 00126 $checkOrder = eZCheckOrder(); 00127 foreach( $checkOrder as $checkItem ) 00128 { 00129 if ( !isset( $checks[$checkItem] ) ) 00130 continue; 00131 $check = $checks[$checkItem]; 00132 if ( !isset( $check['allow'] ) || $check['allow'] ) 00133 { 00134 $func = $check['function']; 00135 $check = $func( $siteBasics, $uri ); 00136 if ( $check !== null ) 00137 return $check; 00138 } 00139 } 00140 return null; 00141 } 00142 00143 /** 00144 * Uses [SitePrecheckRules] to check if a precheck is allowed or not. 00145 * Setting seems to be able to be defined like this (site.ini): 00146 * [SitePrecheckRules] 00147 * Rules[] 00148 * # access can be enabled or disabled, and will affect the later 00149 * Rules[]=access;enabled 00150 * # precheckall can be true (makes prior access rule affect all prechecks) 00151 * Rules[]=precheckall;true 00152 * # precheck needs to be set to the same key as the precheck you want to allow / disallow 00153 * Rules[]=precheck;validity 00154 * 00155 * @deprecated As of 4.4, since SitePrecheckRules setting is not used or documented anywhere 00156 * (documentation above was added when it was deprecated) 00157 * @param array $prechecks 00158 * @return array The same $prechecks array but adjusted according to the SitePrecheckRules rules 00159 */ 00160 function precheckAllowed( array $prechecks ) 00161 { 00162 $ini = eZINI::instance(); 00163 00164 if ( !$ini->hasGroup( 'SitePrecheckRules' ) ) 00165 return $prechecks; 00166 00167 $tmp_allow = true; 00168 $items = $ini->variableArray( 'SitePrecheckRules', 'Rules' ); 00169 foreach( $items as $item ) 00170 { 00171 $name = strtolower( $item[0] ); 00172 $value = $item[1]; 00173 switch( $name ) 00174 { 00175 case 'access': 00176 { 00177 $tmp_allow = ($value === 'enable'); 00178 } break; 00179 case 'precheckall': 00180 { 00181 if ( $value === 'true' ) 00182 { 00183 foreach( $prechecks as $key => $value ) 00184 { 00185 $prechecks[$key]['allow'] = $tmp_allow; 00186 } 00187 } 00188 } break; 00189 case 'precheck': 00190 { 00191 if ( isset( $prechecks[$value] ) ) 00192 $prechecks[$value]['allow'] = $tmp_allow; 00193 } break; 00194 default: 00195 { 00196 eZDebug::writeError( "Unknown precheck rule: $name=$value", 'Access' ); 00197 } break; 00198 } 00199 } 00200 return $prechecks; 00201 } 00202 00203 ?>