pwet

Sign in or create your account | Project List | Help | pwet.fr | Planet eZ Publish.fr | Bioutifoul Photos

pwet Svn Source Tree

Root/trunk/www/pre_check.php

1<?php
2/**
3 * File containing pre check functions as used to validate request
4 *
5 * @copyright Copyright (C) 1999-2011 eZ Systems AS. All rights reserved.
6 * @license http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2
7 * @version 2011.7
8 * @package index
9 */
10
11/**
12 * Checks if the installation is valid and returns a module redirect if required.
13 * If CheckValidity in SiteAccessSettings is false then no check is done.
14 *
15 * @deprecated As of 4.4, moved to index.php for now
16 * @param array $siteBasics
17 * @param eZURI $uri
18 */
19function eZCheckValidity( array &$siteBasics, eZURI $uri )
20{
21    eZDebug::writeStrict( 'Function eZCheckValidity() has been deprecated in 4.4', 'Deprecation' );
22    $ini = eZINI::instance();
23    $checkValidity = ( $ini->variable( "SiteAccessSettings", "CheckValidity" ) == "true" );
24    $check = null;
25    if ( $checkValidity )
26    {
27        $check = array( "module" => "setup",
28                        'function' => 'init' );
29        // Turn off some features that won't bee needed yet
30// $siteBasics['policy-check-required'] = false;
31        $siteBasics['policy-check-omit-list'][] = 'setup';
32        $siteBasics['url-translator-allowed'] = false;
33        $siteBasics['show-page-layout'] = $ini->variable( 'SetupSettings', 'PageLayout' );
34        $siteBasics['validity-check-required'] = true;
35        $siteBasics['user-object-required'] = false;
36        $siteBasics['session-required'] = false;
37        $siteBasics['db-required'] = false;
38        $siteBasics['no-cache-adviced'] = false;
39        $siteBasics['site-design-override'] = $ini->variable( 'SetupSettings', 'OverrideSiteDesign' );
40        $access = array( 'name' => 'setup',
41                         'type' => eZSiteAccess::TYPE_URI );
42        $access = eZSiteAccess::change( $access );
43
44        eZTranslatorManager::enableDynamicTranslations();
45    }
46    return $check;
47}
48
49/**
50 * List of functions that should be checked by key identifier
51 *
52 * @deprecated As of 4.4, since SitePrecheckRules setting is not used or documented anywhere
53 * (documentation above was added when it was deprecated)
54 * Also validity checks needs to be done before session init and user check after..
55 * @return array An associative array with items to run a check on, each items
56 * is an associative array. The item must contain: function -> name of the function
57 */
58function eZCheckList()
59{
60    $checks = array();
61    $checks['validity'] = array( 'function' => 'eZCheckValidity' );
62    $checks['user'] = array( 'function' => 'eZCheckUser' );
63    return $checks;
64}
65
66/**
67 * Check if user login is required. If so, use login handler to redirect user.
68 *
69 * @deprecated As of 4.4, moved to {@link eZUserLoginHandler::preCheck()}
70 * @param array $siteBasics
71 * @param eZURI $uri
72 * @return array|true|false|null An associative array on redirect with 'module' and 'function' keys, true on successful
73 * and false/null on #fail.
74 */
75function eZCheckUser( array &$siteBasics, eZURI $uri )
76{
77    eZDebug::writeStrict( 'Function eZCheckUser() has been deprecated in 4.4 in favor of eZUserLoginHandler::preCheck()', 'Deprecation' );
78    if ( !$siteBasics['user-object-required'] )
79    {
80        return null;
81    }
82
83    $ini = eZINI::instance();
84    $requireUserLogin = ( $ini->variable( 'SiteAccessSettings', 'RequireUserLogin' ) == 'true' );
85    $forceLogin = false;
86    if ( eZSession::hasStarted() )
87    {
88        $http = eZHTTPTool::instance();
89        $forceLogin = $http->hasSessionVariable( eZUserLoginHandler::FORCE_LOGIN );
90    }
91    if ( !$requireUserLogin && !$forceLogin )
92    {
93        return null;
94    }
95
96    return eZUserLoginHandler::checkUser( $siteBasics, $uri );
97}
98
99/**
100 * Return the order that prechecks should be checked
101 *
102 * @deprecated As of 4.4, since SitePrecheckRules setting is not used or documented anywhere
103 * (documentation above was added when it was deprecated)
104 * Also validity checks needs to be done before session init and user check after..
105 * @return array
106 */
107function eZCheckOrder()
108{
109    return array( 'validity', 'user' );
110}
111
112/**
113 * Executes pre checks
114 *
115 * @deprecated As of 4.4, since SitePrecheckRules setting is not used or documented anywhere
116 * (documentation above was added when it was deprecated)
117 * Also validity checks needs to be done before session init and user check after..
118 * @param array $siteBasics
119 * @param eZURI $uri
120 * @return array|null A structure with redirection information or null if nothing should be done.
121 */
122function eZHandlePreChecks( array &$siteBasics, eZURI $uri )
123{
124    $checks = eZCheckList();
125    $checks = precheckAllowed( $checks );
126    $checkOrder = eZCheckOrder();
127    foreach( $checkOrder as $checkItem )
128    {
129        if ( !isset( $checks[$checkItem] ) )
130            continue;
131        $check = $checks[$checkItem];
132        if ( !isset( $check['allow'] ) || $check['allow'] )
133        {
134            $func = $check['function'];
135            $check = $func( $siteBasics, $uri );
136            if ( $check !== null )
137                return $check;
138        }
139    }
140    return null;
141}
142
143/**
144 * Uses [SitePrecheckRules] to check if a precheck is allowed or not.
145 * Setting seems to be able to be defined like this (site.ini):
146 * [SitePrecheckRules]
147 * Rules[]
148 * # access can be enabled or disabled, and will affect the later
149 * Rules[]=access;enabled
150 * # precheckall can be true (makes prior access rule affect all prechecks)
151 * Rules[]=precheckall;true
152 * # precheck needs to be set to the same key as the precheck you want to allow / disallow
153 * Rules[]=precheck;validity
154 *
155 * @deprecated As of 4.4, since SitePrecheckRules setting is not used or documented anywhere
156 * (documentation above was added when it was deprecated)
157 * @param array $prechecks
158 * @return array The same $prechecks array but adjusted according to the SitePrecheckRules rules
159 */
160function precheckAllowed( array $prechecks )
161{
162    $ini = eZINI::instance();
163
164    if ( !$ini->hasGroup( 'SitePrecheckRules' ) )
165        return $prechecks;
166
167    $tmp_allow = true;
168    $items = $ini->variableArray( 'SitePrecheckRules', 'Rules' );
169    foreach( $items as $item )
170    {
171        $name = strtolower( $item[0] );
172        $value = $item[1];
173        switch( $name )
174        {
175            case 'access':
176            {
177                $tmp_allow = ($value === 'enable');
178            } break;
179            case 'precheckall':
180            {
181                if ( $value === 'true' )
182                {
183                    foreach( $prechecks as $key => $value )
184                    {
185                        $prechecks[$key]['allow'] = $tmp_allow;
186                    }
187                }
188            } break;
189            case 'precheck':
190            {
191                if ( isset( $prechecks[$value] ) )
192                    $prechecks[$value]['allow'] = $tmp_allow;
193            } break;
194            default:
195            {
196                eZDebug::writeError( "Unknown precheck rule: $name=$value", 'Access' );
197            } break;
198        }
199    }
200    return $prechecks;
201}
202
203?>
204

Archive Download this file

Revision: HEAD