PageRenderTime 60ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/index_treemenu_tags.php

https://bitbucket.org/netgen/eztags
PHP | 172 lines | 136 code | 25 blank | 11 comment | 20 complexity | 8ba49a8c3b196ce23dd70bdd7a035871 MD5 | raw file
  1. <?php
  2. // Set a default time zone if none is given. The time zone can be overriden
  3. // in config.php or php.ini.
  4. if ( !ini_get( 'date.timezone' ) )
  5. {
  6. date_default_timezone_set( 'UTC' );
  7. }
  8. define( 'MAX_AGE', 86400 );
  9. header( 'X-Powered-By: eZ Publish (index_treemenu_tags)' );
  10. if ( isset( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) )
  11. {
  12. header( $_SERVER['SERVER_PROTOCOL'] . ' 304 Not Modified' );
  13. header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', time() + MAX_AGE ) . ' GMT' );
  14. header( 'Cache-Control: max-age=' . MAX_AGE );
  15. header( 'Last-Modified: ' . gmdate( 'D, d M Y H:i:s', strtotime( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ) . ' GMT' );
  16. header( 'Pragma: ' );
  17. exit();
  18. }
  19. require 'autoload.php';
  20. // Tweaks ini filetime checks if not defined!
  21. // This makes ini system not check modified time so
  22. // that index_treemenu_tags.php can assume that index.php does
  23. // this regular enough, set in config.php to override.
  24. if ( !defined('EZP_INI_FILEMTIME_CHECK') )
  25. {
  26. define( 'EZP_INI_FILEMTIME_CHECK', false );
  27. }
  28. function ezupdatedebugsettings()
  29. {
  30. }
  31. function eZFatalError()
  32. {
  33. header( $_SERVER['SERVER_PROTOCOL'] . ' 500 Internal Server Error' );
  34. }
  35. function exitWithInternalError()
  36. {
  37. header( $_SERVER['SERVER_PROTOCOL'] . ' 500 Internal Server Error' );
  38. eZExecution::cleanup();
  39. eZExecution::setCleanExit();
  40. }
  41. ignore_user_abort( true );
  42. ob_start();
  43. error_reporting ( E_ALL );
  44. eZExecution::addFatalErrorHandler( 'eZFatalError' );
  45. eZDebug::setHandleType( eZDebug::HANDLE_FROM_PHP );
  46. // Trick to get eZSys working with a script other than index.php (while index.php still used in generated URLs):
  47. $_SERVER['SCRIPT_FILENAME'] = str_replace( '/index_treemenu_tags.php', '/index.php', $_SERVER['SCRIPT_FILENAME'] );
  48. $_SERVER['PHP_SELF'] = str_replace( '/index_treemenu_tags.php', '/index.php', $_SERVER['PHP_SELF'] );
  49. $ini = eZINI::instance();
  50. $timezone = $ini->variable( 'TimeZoneSettings', 'TimeZone' );
  51. if ( $timezone )
  52. {
  53. putenv( "TZ=$timezone" );
  54. }
  55. // init uri code
  56. $GLOBALS['eZGlobalRequestURI'] = eZSys::serverVariable( 'REQUEST_URI' );
  57. eZSys::init( 'index.php', $ini->variable( 'SiteAccessSettings', 'ForceVirtualHost' ) === 'true' );
  58. $uri = eZURI::instance( eZSys::requestURI() );
  59. $GLOBALS['eZRequestedURI'] = $uri;
  60. // Check for extension
  61. eZExtension::activateExtensions( 'default' );
  62. // load siteaccess
  63. if( method_exists( 'eZSiteAccess', 'match' ) && method_exists( 'eZSiteAccess', 'change' ) )
  64. {
  65. $access = eZSiteAccess::match( $uri,
  66. eZSys::hostname(),
  67. eZSys::serverPort(),
  68. eZSys::indexFile() );
  69. $access = eZSiteAccess::change( $access );
  70. }
  71. else
  72. {
  73. include_once( 'access.php' );
  74. $access = accessType( $uri,
  75. eZSys::hostname(),
  76. eZSys::serverPort(),
  77. eZSys::indexFile() );
  78. $access = changeAccess( $access );
  79. }
  80. $GLOBALS['eZCurrentAccess'] = $access;
  81. // Check for new extension loaded by siteaccess
  82. eZExtension::activateExtensions( 'access' );
  83. $db = eZDB::instance();
  84. if ( $db->isConnected() )
  85. {
  86. eZSession::start();
  87. }
  88. else
  89. {
  90. exitWithInternalError();
  91. return;
  92. }
  93. $moduleINI = eZINI::instance( 'module.ini' );
  94. $globalModuleRepositories = $moduleINI->variable( 'ModuleSettings', 'ModuleRepositories' );
  95. $globalModuleRepositories[] = 'extension/eztags/modules';
  96. eZModule::setGlobalPathList( $globalModuleRepositories );
  97. $module = eZModule::exists( 'tags' );
  98. if ( !$module )
  99. {
  100. exitWithInternalError();
  101. return;
  102. }
  103. $function_name = 'treemenu';
  104. $uri->increase();
  105. $uri->increase();
  106. $currentUser = eZUser::currentUser();
  107. $siteAccessResult = $currentUser->hasAccessTo( 'user', 'login' );
  108. $tagsReadResult = $currentUser->hasAccessTo( 'tags', 'read' );
  109. $hasAccessToSite = false;
  110. if ( $siteAccessResult[ 'accessWord' ] == 'limited' )
  111. {
  112. $policyChecked = false;
  113. foreach ( $siteAccessResult['policies'] as $policy )
  114. {
  115. if ( isset( $policy['SiteAccess'] ) )
  116. {
  117. $policyChecked = true;
  118. $crc32AccessName = eZSys::ezcrc32( $access[ 'name' ] );
  119. if ( in_array( $crc32AccessName, $policy['SiteAccess'] ) )
  120. {
  121. $hasAccessToSite = true;
  122. break;
  123. }
  124. }
  125. if ( $hasAccessToSite )
  126. {
  127. break;
  128. }
  129. }
  130. if ( !$policyChecked )
  131. {
  132. $hasAccessToSite = true;
  133. }
  134. }
  135. else if ( $siteAccessResult[ 'accessWord' ] == 'yes' )
  136. {
  137. $hasAccessToSite = true;
  138. }
  139. if ( !$hasAccessToSite || $tagsReadResult['accessWord'] == 'no' )
  140. {
  141. exitWithInternalError();
  142. return;
  143. }
  144. $GLOBALS['eZRequestedModule'] = $module;
  145. $moduleResult = $module->run( $function_name, $uri->elements( false ) );
  146. eZExecution::cleanup();
  147. eZExecution::setCleanExit();