Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

ezpkerneltreemenu.php
Go to the documentation of this file.
1 <?php
11 class ezpKernelTreeMenu implements ezpKernelHandler
12 {
16 public $siteBasics;
22 protected $isInitialized = false;
23
29 protected $settings;
30
36 protected $access;
37
41 protected $uri;
42
43 public function __construct( array $settings = array() )
44 {
45 if ( isset( $settings['injected-settings'] ) )
46 {
47 $injectedSettings = array();
48 foreach ( $settings['injected-settings'] as $keySetting => $injectedSetting )
49 {
50 list( $file, $section, $setting ) = explode( '/', $keySetting );
51 $injectedSettings[$file][$section][$setting] = $injectedSetting;
52 }
53 // Those settings override anything else in local .ini files and their overrides
54 eZINI::injectSettings( $injectedSettings );
55 }
56 if ( isset( $settings['injected-merge-settings'] ) )
57 {
58 $injectedSettings = array();
59 foreach ( $settings['injected-merge-settings'] as $keySetting => $injectedSetting )
60 {
61 list( $file, $section, $setting ) = explode( '/', $keySetting );
62 $injectedSettings[$file][$section][$setting] = $injectedSetting;
63 }
64 // Those settings override anything else in local .ini files and their overrides
65 eZINI::injectMergeSettings( $injectedSettings );
66 }
67 $this->settings = $settings + array(
68 'use-cache-headers' => true,
69 'max-age' => 86400,
70 'siteaccess' => null,
71 'use-exceptions' => false,
72 'service-container' => null,
73 );
74 unset( $settings, $injectedSettings, $file, $section, $setting, $keySetting, $injectedSetting );
75
76 require_once __DIR__ . '/treemenu_functions.php';
77 $this->setUseExceptions( $this->settings['use-exceptions'] );
78
79 header( 'X-Powered-By: ' . eZPublishSDK::EDITION . ' (index_treemenu)' );
80 if ( $this->settings['use-cache-headers'] === true )
81 {
82 define( 'MAX_AGE', $this->settings['max-age'] );
83 if ( isset( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) )
84 {
85 header( $_SERVER['SERVER_PROTOCOL'] . ' 304 Not Modified' );
86 header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', time() + MAX_AGE ) . ' GMT' );
87 header( 'Cache-Control: max-age=' . MAX_AGE );
88 header( 'Last-Modified: ' . gmdate( 'D, d M Y H:i:s', strtotime( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ) . ' GMT' );
89 header( 'Pragma: ' );
90 exit();
91 }
92 }
93
94 // Tweaks ini filetime checks if not defined!
95 // This makes ini system not check modified time so
96 // that index_treemenu.php can assume that index.php does
97 // this regular enough, set in config.php to override.
98 if ( !defined( 'EZP_INI_FILEMTIME_CHECK' ) )
99 {
100 define( 'EZP_INI_FILEMTIME_CHECK', false );
101 }
102
103 eZExecution::addFatalErrorHandler(
104 function ()
105 {
106 if ( !headers_sent() )
107 {
108 header( $_SERVER['SERVER_PROTOCOL'] . ' 500 Internal Server Error' );
109 }
110 }
111 );
112 eZDebug::setHandleType( eZDebug::HANDLE_FROM_PHP );
113
114 // Trick to get eZSys working with a script other than index.php (while index.php still used in generated URLs):
115 $_SERVER['SCRIPT_FILENAME'] = str_replace( '/index_treemenu.php', '/index.php', $_SERVER['SCRIPT_FILENAME'] );
116 $_SERVER['PHP_SELF'] = str_replace( '/index_treemenu.php', '/index.php', $_SERVER['PHP_SELF'] );
117
118 $ini = eZINI::instance();
119 $timezone = $ini->variable( 'TimeZoneSettings', 'TimeZone' );
120 if ( $timezone )
121 {
122 putenv( "TZ=$timezone" );
123 }
124
125 // init uri code
126 $GLOBALS['eZGlobalRequestURI'] = eZSys::serverVariable( 'REQUEST_URI' );
127 if ( $this->hasServiceContainer() && $this->getServiceContainer()->has( 'request' ) )
128 {
129 eZSys::init(
130 basename( $this->getServiceContainer()->get( 'request' )->server->get( 'SCRIPT_FILENAME' ) ),
131 $ini->variable( 'SiteAccessSettings', 'ForceVirtualHost' ) === 'true'
132 );
133 }
134 else
135 {
136 eZSys::init(
137 'index.php',
138 $ini->variable( 'SiteAccessSettings', 'ForceVirtualHost' ) === 'true'
139 );
140 }
141 $this->uri = eZURI::instance( eZSys::requestURI() );
142
143 $GLOBALS['eZRequestedURI'] = $this->uri;
144
145 // Check for extension
146 eZExtension::activateExtensions( 'default' );
147
148 // load siteaccess
149 // Use injected siteaccess if available or match it internally.
150 $this->access = isset( $this->settings['siteaccess'] ) ?
151 $this->settings['siteaccess'] :
152 eZSiteAccess::match(
153 $this->uri,
154 eZSys::hostname(),
155 eZSys::serverPort(),
156 eZSys::indexFile()
157 );
158 eZSiteAccess::change( $this->access );
159
160 // Check for new extension loaded by siteaccess
161 eZExtension::activateExtensions( 'access' );
162 }
163
168 protected function sessionInit()
169 {
170 if ( !isset( $this->settings['session'] ) || !$this->settings['session']['configured'] )
171 {
172 // running without Symfony2 or session is not configured
173 // we keep the historic behaviour
174 $ini = eZINI::instance();
175 if ( $ini->variable( 'Session', 'ForceStart' ) === 'enabled' )
176 eZSession::start();
177 else
178 eZSession::lazyStart();
179 }
180 else
181 {
182 $sfHandler = new ezpSessionHandlerSymfony(
183 $this->settings['session']['has_previous']
184 || $this->settings['session']['started']
185 );
186 $sfHandler->setStorage( $this->settings['session']['storage'] );
187 eZSession::init(
188 $this->settings['session']['name'],
189 $this->settings['session']['started'],
190 $this->settings['session']['namespace'],
191 $sfHandler
192 );
193 }
194
195 // let session specify if db is required
196 $this->siteBasics['db-required'] = eZSession::getHandlerInstance()->dbRequired();
197 }
198
205 public function run()
206 {
207 $db = eZDB::instance();
208 if ( $db->isConnected() )
209 {
210 $this->sessionInit();
211 }
212 else
213 {
214 return $this->exitWithInternalError(
215 ezpI18n::tr( 'kernel/content/treemenu', 'Database is not connected' )
216 );
217 }
218
219 $moduleINI = eZINI::instance( 'module.ini' );
220 $globalModuleRepositories = $moduleINI->variable( 'ModuleSettings', 'ModuleRepositories' );
221 eZModule::setGlobalPathList( $globalModuleRepositories );
222
223 $module = eZModule::exists( 'content' );
224 if ( !$module )
225 {
226 return $this->exitWithInternalError(
227 ezpI18n::tr( 'kernel/content/treemenu', '"content" module could not be found.' )
228 );
229 }
230
231 $function_name = 'treemenu';
232 $this->uri->increase();
233 $this->uri->increase();
234
235 $currentUser = eZUser::currentUser();
236 $siteAccessResult = $currentUser->hasAccessTo( 'user', 'login' );
237 $hasAccessToSite = false;
238 if ( $siteAccessResult[ 'accessWord' ] == 'limited' )
239 {
240 $policyChecked = false;
241 foreach ( $siteAccessResult['policies'] as $policy )
242 {
243 if ( isset( $policy['SiteAccess'] ) )
244 {
245 $policyChecked = true;
246 $crc32AccessName = eZSys::ezcrc32( $this->access[ 'name' ] );
247 if ( in_array( $crc32AccessName, $policy['SiteAccess'] ) )
248 {
249 $hasAccessToSite = true;
250 break;
251 }
252 }
253 if ( $hasAccessToSite )
254 {
255 break;
256 }
257 }
258 if ( !$policyChecked )
259 {
260 $hasAccessToSite = true;
261 }
262 }
263 else if ( $siteAccessResult[ 'accessWord' ] == 'yes' )
264 {
265 $hasAccessToSite = true;
266 }
267
268 if ( !$hasAccessToSite )
269 {
270 return $this->exitWithInternalError(
271 ezpI18n::tr( 'kernel/content/treemenu', 'Insufficient permissions to display the treemenu.' ),
272 403
273 );
274 }
275
276 $GLOBALS['eZRequestedModule'] = $module;
277
278 $content = $module->run(
279 $function_name,
280 $this->uri->elements( false ),
281 false,
282 array(
283 'use-cache-headers' => $this->settings['use-cache-headers']
284 )
285 );
286 $attributes = isset( $content['lastModified'] ) ? array( 'lastModified' => $content['lastModified'] ) : array();
287 $this->shutdown();
288 return new ezpKernelResult( $content['content'], $attributes );
289 }
290
296 public function runCallback( \Closure $callback, $postReinitialize = true )
297 {
298 throw new \RuntimeException( 'runCallback() method is not supported by ezpKernelTreeMenu' );
299 }
300
306 public function setUseExceptions( $useExceptions )
307 {
308 eZModule::$useExceptions = (bool)$useExceptions;
309 }
310
316 public function reInitialize()
317 {
318 $this->isInitialized = false;
319 }
320
324 protected function shutdown( $reInitialize = true )
325 {
326 eZExecution::cleanup();
327 eZExecution::setCleanExit();
328 eZExpiryHandler::shutdown();
329 if ( $reInitialize )
330 $this->isInitialized = false;
331 }
332
346 protected function exitWithInternalError( $errorMessage, $errorCode = 500 )
347 {
348 if ( eZModule::$useExceptions )
349 {
350 switch ( $errorCode )
351 {
352 case 403:
353 throw new ezpAccessDenied( $errorMessage );
354
355 case 500:
356 default:
357 throw new RuntimeException( $errorMessage, $errorCode );
358 }
359 }
360 else
361 {
362 header( $_SERVER['SERVER_PROTOCOL'] . ' 500 Internal Server Error' );
363 eZExecution::cleanup();
364 eZExecution::setCleanExit();
365
366 return new ezpKernelResult(
367 json_encode(
368 array(
369 'error' => $errorMessage,
370 'code' => $errorCode
371 )
372 )
373 );
374 }
375 }
376
383 public function hasServiceContainer()
384 {
385 return isset( $this->settings['service-container'] );
386 }
387
394 public function getServiceContainer()
395 {
396 return $this->settings['service-container'];
397 }
398 }
eZDebug\HANDLE_FROM_PHP
const HANDLE_FROM_PHP
Definition: ezdebug.php:76
eZDebug\setHandleType
static setHandleType( $type)
Definition: ezdebug.php:248
eZExecution\setCleanExit
static setCleanExit( $hasCleanExit=true)
Definition: ezexecution.php:29
eZExecution\cleanup
static cleanup()
Definition: ezexecution.php:37
eZExecution\addFatalErrorHandler
static addFatalErrorHandler( $handler)
Definition: ezexecution.php:75
eZExtension\activateExtensions
static activateExtensions( $extensionType='default', eZINI $siteINI=null)
Definition: ezextension.php:188
eZModule\$useExceptions
static $useExceptions
Definition: ezmodule.php:258
eZModule\exists
exists( $name)
Definition: ezmodule.php:214
eZPublishSDK\EDITION
const EDITION
Definition: version.php:24
eZSession\start
static start( $cookieTimeout=false)
Definition: lib/ezsession/classes/ezsession.php:384
eZSession\init
static init( $name, $started, $ns, ezpSessionHandler $handler)
Definition: lib/ezsession/classes/ezsession.php:428
eZSession\lazyStart
static lazyStart( $startIfUserHasCookie=true)
Definition: lib/ezsession/classes/ezsession.php:401
eZSession\getHandlerInstance
static getHandlerInstance(ezpSessionHandler|null $handler=null)
Definition: lib/ezsession/classes/ezsession.php:580
eZSiteAccess\match
static match(eZURI $uri, $host, $port=80, $file='/index.php')
Definition: ezsiteaccess.php:104
eZSiteAccess\change
static change(array $access, eZINI $siteINI=null)
Definition: ezsiteaccess.php:504
eZSys\serverVariable
static serverVariable( $variableName, $quiet=false)
Definition: ezsys.php:857
eZSys\serverPort
static serverPort()
Definition: ezsys.php:824
eZSys\requestURI
static requestURI()
Definition: ezsys.php:1263
eZSys\hostname
static hostname()
Definition: ezsys.php:677
eZSys\ezcrc32
static ezcrc32( $string)
Definition: ezsys.php:1298
eZSys\init
static init( $index='index.php', $forceVirtualHost=null)
Definition: ezsys.php:1104
eZSys\indexFile
static indexFile( $withAccessPath=true)
Definition: ezsys.php:619
eZURI\instance
static instance( $uri=false)
Definition: ezuri.php:575
eZUser\currentUser
static & currentUser()
Definition: ezuser.php:896
$ini
$ini
Definition: classes/admin/linklist.php:64
$module
$module
Definition: classes/admin/linkselect.php:219
ezpAccessDenied
Definition: accessdenied.php:18
ezpKernelResult
Definition: ezpkernelresult.php:15
ezpKernelTreeMenu
Definition: ezpkerneltreemenu.php:12
ezpKernelTreeMenu\reInitialize
reInitialize()
Definition: ezpkerneltreemenu.php:316
ezpKernelTreeMenu\$isInitialized
$isInitialized
Definition: ezpkerneltreemenu.php:22
ezpKernelTreeMenu\hasServiceContainer
hasServiceContainer()
Definition: ezpkerneltreemenu.php:383
ezpKernelTreeMenu\run
run()
Definition: ezpkerneltreemenu.php:205
ezpKernelTreeMenu\sessionInit
sessionInit()
Definition: ezpkerneltreemenu.php:168
ezpKernelTreeMenu\$uri
$uri
Definition: ezpkerneltreemenu.php:41
ezpKernelTreeMenu\__construct
__construct(array $settings=array())
Definition: ezpkerneltreemenu.php:43
ezpKernelTreeMenu\$settings
$settings
Definition: ezpkerneltreemenu.php:29
ezpKernelTreeMenu\$access
$access
Definition: ezpkerneltreemenu.php:36
ezpKernelTreeMenu\getServiceContainer
getServiceContainer()
Definition: ezpkerneltreemenu.php:394
ezpKernelTreeMenu\runCallback
runCallback(\Closure $callback, $postReinitialize=true)
Definition: ezpkerneltreemenu.php:296
ezpKernelTreeMenu\shutdown
shutdown( $reInitialize=true)
Definition: ezpkerneltreemenu.php:324
ezpKernelTreeMenu\$siteBasics
$siteBasics
Definition: ezpkerneltreemenu.php:16
ezpKernelTreeMenu\exitWithInternalError
exitWithInternalError( $errorMessage, $errorCode=500)
Definition: ezpkerneltreemenu.php:346
ezpKernelTreeMenu\setUseExceptions
setUseExceptions( $useExceptions)
Definition: ezpkerneltreemenu.php:306
ezpSessionHandlerSymfony
Definition: ezpsessionhandlersymfony.php:21
$db
$db
Definition: ezarticle/user/authorlist.php:53
$file
$file
Definition: ezfilemanager/user/filedownload.php:35
$content
$content
Definition: ezimagecatalogue/admin/filedownload.php:53
$section
$section
Definition: ezimagecatalogue/user/categoryedit.php:393
exit
exit
Definition: folder.php:81
ezpKernelHandler
Definition: ezpkernelhandler.php:15
$currentUser
$currentUser
Definition: surveyedit.php:54
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.