/kernel/content/view.php

https://github.com/brookinsconsulting/ezpublish · PHP · 209 lines · 167 code · 29 blank · 13 comment · 30 complexity · b15724228c5480736618f8f680159a5b MD5 · raw file

  1. <?php
  2. /**
  3. * @copyright Copyright (C) eZ Systems AS. All rights reserved.
  4. * @license For full copyright and license information view LICENSE file distributed with this source code.
  5. * @version //autogentag//
  6. * @package kernel
  7. */
  8. $tpl = eZTemplate::factory();
  9. $ViewMode = $Params['ViewMode'];
  10. $NodeID = $Params['NodeID'];
  11. $Module = $Params['Module'];
  12. $LanguageCode = $Params['Language'];
  13. $Offset = $Params['Offset'];
  14. $Year = $Params['Year'];
  15. $Month = $Params['Month'];
  16. $Day = $Params['Day'];
  17. // Check if we should switch access mode (http/https) for this node.
  18. eZSSLZone::checkNodeID( 'content', 'view', $NodeID );
  19. if ( isset( $Params['UserParameters'] ) )
  20. {
  21. $UserParameters = $Params['UserParameters'];
  22. }
  23. else
  24. {
  25. $UserParameters = array();
  26. }
  27. if ( $Offset )
  28. $Offset = (int) $Offset;
  29. if ( $Year )
  30. $Year = (int) $Year;
  31. if ( $Month )
  32. $Month = (int) $Month;
  33. if ( $Day )
  34. $Day = (int) $Day;
  35. $NodeID = (int) $NodeID;
  36. if ( $NodeID < 2 )
  37. {
  38. return $Module->handleError( eZError::KERNEL_NOT_FOUND, 'kernel' );
  39. }
  40. $ini = eZINI::instance();
  41. // Be able to filter node id for general use
  42. $NodeID = ezpEvent::getInstance()->filter( 'content/view', $NodeID, $ini );
  43. $testingHandler = new ezpMultivariateTest( ezpMultivariateTest::getHandler() );
  44. if ( $testingHandler->isEnabled() )
  45. $NodeID = $testingHandler->execute( $NodeID );
  46. $viewCacheEnabled = ( $ini->variable( 'ContentSettings', 'ViewCaching' ) == 'enabled' );
  47. if ( isset( $Params['ViewCache'] ) )
  48. {
  49. $viewCacheEnabled = $Params['ViewCache'];
  50. }
  51. elseif ( $viewCacheEnabled && !in_array( $ViewMode, $ini->variableArray( 'ContentSettings', 'CachedViewModes' ) ) )
  52. {
  53. $viewCacheEnabled = false;
  54. }
  55. if ( $viewCacheEnabled && $ini->hasVariable( 'ContentSettings', 'ViewCacheTweaks' ) )
  56. {
  57. $viewCacheTweaks = $ini->variable( 'ContentSettings', 'ViewCacheTweaks' );
  58. if ( isset( $viewCacheTweaks[$NodeID] ) && strpos( $viewCacheTweaks[$NodeID], 'disabled' ) !== false )
  59. {
  60. $viewCacheEnabled = false;
  61. }
  62. }
  63. $collectionAttributes = false;
  64. if ( isset( $Params['CollectionAttributes'] ) )
  65. $collectionAttributes = $Params['CollectionAttributes'];
  66. $validation = array( 'processed' => false,
  67. 'attributes' => array() );
  68. if ( isset( $Params['AttributeValidation'] ) )
  69. $validation = $Params['AttributeValidation'];
  70. $res = eZTemplateDesignResource::instance();
  71. $keys = $res->keys();
  72. if ( isset( $keys['layout'] ) )
  73. $layout = $keys['layout'];
  74. else
  75. $layout = false;
  76. $viewParameters = array(
  77. 'offset' => $Offset,
  78. 'year' => $Year,
  79. 'month' => $Month,
  80. 'day' => $Day,
  81. 'namefilter' => false,
  82. '_custom' => $UserParameters
  83. );
  84. // Keep the following array_merge for BC
  85. // All user parameters will be exposed as direct variables in template.
  86. $viewParameters = array_merge( $viewParameters, $UserParameters );
  87. $user = eZUser::currentUser();
  88. eZDebugSetting::addTimingPoint( 'kernel-content-view', 'Operation start' );
  89. $operationResult = array();
  90. if ( eZOperationHandler::operationIsAvailable( 'content_read' ) )
  91. {
  92. $operationResult = eZOperationHandler::execute( 'content', 'read', array( 'node_id' => $NodeID,
  93. 'user_id' => $user->id(),
  94. 'language_code' => $LanguageCode ), null, true );
  95. }
  96. if ( ( isset( $operationResult['status'] ) && $operationResult['status'] != eZModuleOperationInfo::STATUS_CONTINUE ) )
  97. {
  98. switch( $operationResult['status'] )
  99. {
  100. case eZModuleOperationInfo::STATUS_HALTED:
  101. case eZModuleOperationInfo::STATUS_REPEAT:
  102. {
  103. if ( isset( $operationResult['redirect_url'] ) )
  104. {
  105. $Module->redirectTo( $operationResult['redirect_url'] );
  106. return;
  107. }
  108. else if ( isset( $operationResult['result'] ) )
  109. {
  110. $result = $operationResult['result'];
  111. $resultContent = false;
  112. if ( is_array( $result ) )
  113. {
  114. if ( isset( $result['content'] ) )
  115. {
  116. $resultContent = $result['content'];
  117. }
  118. if ( isset( $result['path'] ) )
  119. {
  120. $Result['path'] = $result['path'];
  121. }
  122. }
  123. else
  124. {
  125. $resultContent = $result;
  126. }
  127. $Result['content'] = $resultContent;
  128. }
  129. } break;
  130. case eZModuleOperationInfo::STATUS_CANCELLED:
  131. {
  132. $Result = array();
  133. $Result['content'] = "Content view cancelled<br/>";
  134. } break;
  135. }
  136. return $Result;
  137. }
  138. else
  139. {
  140. $args = compact(
  141. array(
  142. "NodeID", "Module", "tpl", "LanguageCode", "ViewMode", "Offset", "ini", "viewParameters", "collectionAttributes", "validation"
  143. )
  144. );
  145. if ( $viewCacheEnabled )
  146. {
  147. $cacheFileArray = eZNodeviewfunctions::generateViewCacheFile(
  148. eZUser::currentUser(),
  149. $NodeID,
  150. $Offset,
  151. $layout,
  152. $LanguageCode,
  153. $ViewMode,
  154. $viewParameters,
  155. false
  156. );
  157. $result = eZClusterFileHandler::instance( $cacheFileArray['cache_path'] )
  158. ->processCache(
  159. array( 'eZNodeviewfunctions', 'contentViewRetrieve' ),
  160. array( 'eZNodeviewfunctions', 'contentViewGenerate' ),
  161. null,
  162. null,
  163. $args
  164. );
  165. // check if $result is an array (could also be eZClusterFileFailure) and contains responseHeaders
  166. if ( is_array( $result ) && !empty( $result['responseHeaders'] ) )
  167. {
  168. foreach ( $result['responseHeaders'] as $header )
  169. {
  170. header( $header );
  171. }
  172. }
  173. return $result;
  174. }
  175. $data = eZNodeviewfunctions::contentViewGenerate( false, $args ); // the false parameter will disable generation of the 'binarydata' entry
  176. return $data['content']; // Return the $Result array
  177. }
  178. // Looking for some view-cache code?
  179. // Try the eZNodeviewfunctions class for enlightenment.
  180. ?>