00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 define( 'eZNodeViewFunctions_FileGenerateTimeout', 3 );
00038
00039 class eZNodeviewfunctions
00040 {
00041 function &generateNodeView( &$tpl, &$node, &$object, $languageCode, $viewMode, $offset,
00042 $cacheDir, $cachePath, $viewCacheEnabled,
00043 $viewParameters = array( 'offset' => 0, 'year' => false, 'month' => false, 'day' => false ),
00044 $collectionAttributes = false, $validation = false )
00045 {
00046 include_once( 'kernel/classes/ezsection.php' );
00047 eZSection::setGlobalID( $object->attribute( 'section_id' ) );
00048
00049 $section = eZSection::fetch( $object->attribute( 'section_id' ) );
00050 if ( $section )
00051 $navigationPartIdentifier = $section->attribute( 'navigation_part_identifier' );
00052 else
00053 $navigationPartIdentifier = null;
00054
00055 $keyArray = array( array( 'object', $object->attribute( 'id' ) ),
00056 array( 'node', $node->attribute( 'node_id' ) ),
00057 array( 'parent_node', $node->attribute( 'parent_node_id' ) ),
00058 array( 'class', $object->attribute( 'contentclass_id' ) ),
00059 array( 'class_identifier', $node->attribute( 'class_identifier' ) ),
00060 array( 'view_offset', $offset ),
00061 array( 'viewmode', $viewMode ),
00062 array( 'navigation_part_identifier', $navigationPartIdentifier ),
00063 array( 'depth', $node->attribute( 'depth' ) ),
00064 array( 'url_alias', $node->attribute( 'url_alias' ) ),
00065 array( 'class_group', $object->attribute( 'match_ingroup_id_list' ) ) );
00066
00067 $parentClassID = false;
00068 $parentClassIdentifier = false;
00069 $parentNode = $node->attribute( 'parent' );
00070 if ( is_object( $parentNode ) )
00071 {
00072 $parentObject = $parentNode->attribute( 'object' );
00073 if ( is_object( $parentObject ) )
00074 {
00075 $parentClass = $parentObject->contentClass();
00076 if ( is_object( $parentClass ) )
00077 {
00078 $parentClassID = $parentClass->attribute( 'id' );
00079 $parentClassIdentifier = $parentClass->attribute( 'identifier' );
00080
00081 $keyArray[] = array( 'parent_class', $parentClassID );
00082 $keyArray[] = array( 'parent_class_identifier', $parentClassIdentifier );
00083 }
00084 }
00085 }
00086
00087 $res =& eZTemplateDesignResource::instance();
00088 $res->setKeys( $keyArray );
00089
00090 if ( $languageCode )
00091 {
00092 $oldLanguageCode = $node->currentLanguage();
00093 $node->setCurrentLanguage( $languageCode );
00094 }
00095
00096 $tpl->setVariable( 'node', $node );
00097 $tpl->setVariable( 'viewmode', $viewMode );
00098 $tpl->setVariable( 'language_code', $languageCode );
00099 $tpl->setVariable( 'view_parameters', $viewParameters );
00100 $tpl->setVariable( 'collection_attributes', $collectionAttributes );
00101 $tpl->setVariable( 'validation', $validation );
00102 $tpl->setVariable( 'persistent_variable', false );
00103
00104 $parents =& $node->attribute( 'path' );
00105
00106 $path = array();
00107 $titlePath = array();
00108 foreach ( $parents as $parent )
00109 {
00110 $path[] = array( 'text' => $parent->attribute( 'name' ),
00111 'url' => '/content/view/full/' . $parent->attribute( 'node_id' ),
00112 'url_alias' => $parent->attribute( 'url_alias' ),
00113 'node_id' => $parent->attribute( 'node_id' ) );
00114 }
00115
00116 $titlePath = $path;
00117 $path[] = array( 'text' => $object->attribute( 'name' ),
00118 'url' => false,
00119 'url_alias' => false,
00120 'node_id' => $node->attribute( 'node_id' ) );
00121
00122 $titlePath[] = array( 'text' => $object->attribute( 'name' ),
00123 'url' => false,
00124 'url_alias' => false );
00125
00126 $tpl->setVariable( 'node_path', $path );
00127
00128 $Result = array();
00129 $Result['content'] =& $tpl->fetch( 'design:node/view/' . $viewMode . '.tpl' );
00130 $Result['view_parameters'] =& $viewParameters;
00131 $Result['path'] =& $path;
00132 $Result['title_path'] =& $titlePath;
00133 $Result['section_id'] =& $object->attribute( 'section_id' );
00134 $Result['node_id'] =& $node->attribute( 'node_id' );
00135 $Result['navigation_part'] = $navigationPartIdentifier;
00136
00137 $contentInfoArray = array();
00138 $contentInfoArray['object_id'] = $object->attribute( 'id' );
00139 $contentInfoArray['node_id'] = $node->attribute( 'node_id' );
00140 $contentInfoArray['parent_node_id'] = $node->attribute( 'parent_node_id' );
00141 $contentInfoArray['class_id'] = $object->attribute( 'contentclass_id' );
00142 $contentInfoArray['class_identifier'] = $node->attribute( 'class_identifier' );
00143 $contentInfoArray['offset'] = $offset;
00144 $contentInfoArray['viewmode'] = $viewMode;
00145 $contentInfoArray['navigation_part_identifier'] = $navigationPartIdentifier;
00146 $contentInfoArray['node_depth'] = $node->attribute( 'depth' );
00147 $contentInfoArray['url_alias'] = $node->attribute( 'url_alias' );
00148 $contentInfoArray['persistent_variable'] = false;
00149 if ( $tpl->variable( 'persistent_variable' ) !== false )
00150 {
00151 $contentInfoArray['persistent_variable'] = $tpl->variable( 'persistent_variable' );
00152 $keyArray[] = array( 'persistent_variable', $contentInfoArray['persistent_variable'] );
00153 $res->setKeys( $keyArray );
00154 }
00155 $contentInfoArray['class_group'] = $object->attribute( 'match_ingroup_id_list' );
00156 $contentInfoArray['parent_class_id'] = $parentClassID;
00157 $contentInfoArray['parent_class_identifier'] = $parentClassIdentifier;
00158
00159 $Result['content_info'] = $contentInfoArray;
00160
00161
00162 $Result['template_list'] = $tpl->templateFetchList();
00163
00164
00165 if ( $tpl->hasVariable( 'cache_ttl' ) )
00166 {
00167 $cacheTTL =& $tpl->variable( 'cache_ttl' );
00168 }
00169
00170 if ( !isset( $cacheTTL ) )
00171 {
00172 $cacheTTL = -1;
00173 }
00174
00175
00176 if ( $cacheTTL == 0 )
00177 {
00178 $viewCacheEnabled = false;
00179 }
00180
00181 $Result['cache_ttl'] = $cacheTTL;
00182
00183
00184 if ( $viewCacheEnabled )
00185 {
00186 $serializeString = serialize( $Result );
00187
00188 if ( !file_exists( $cacheDir ) )
00189 {
00190 include_once( 'lib/ezfile/classes/ezdir.php' );
00191 $ini =& eZINI::instance();
00192 $perm = octdec( $ini->variable( 'FileSettings', 'StorageDirPermissions' ) );
00193 eZDir::mkdir( $cacheDir, $perm, true );
00194 }
00195 $oldumask = umask( 0 );
00196 $pathExisted = file_exists( $cachePath );
00197 $ini =& eZINI::instance();
00198 $perm = octdec( $ini->variable( 'FileSettings', 'StorageFilePermissions' ) );
00199 $fp = @fopen( $cachePath, "w" );
00200 if ( !$fp )
00201 eZDebug::writeError( "Could not open file '$cachePath' for writing, perhaps wrong permissions" );
00202 if ( $fp and
00203 !$pathExisted )
00204 chmod( $cachePath, $perm );
00205 umask( $oldumask );
00206
00207 if ( $fp )
00208 {
00209 fwrite( $fp, $serializeString );
00210 fclose( $fp );
00211 }
00212
00213
00214
00215 require_once( 'kernel/classes/ezclusterfilehandler.php' );
00216 $fileHandler = eZClusterFileHandler::instance();
00217 $fileHandler->fileStore( $cachePath, 'viewcache', true );
00218 }
00219
00220 if ( $languageCode )
00221 {
00222 $node->setCurrentLanguage( $oldLanguageCode );
00223 }
00224
00225 return $Result;
00226 }
00227
00228 function generateViewCacheFile( $user, $nodeID, $offset, $layout, $language, $viewMode, $viewParameters = false, $cachedViewPreferences = false )
00229 {
00230 include_once( 'kernel/classes/ezuserdiscountrule.php' );
00231 include_once( 'kernel/classes/ezpreferences.php' );
00232
00233 $limitedAssignmentValueList = $user->limitValueList();
00234 $roleList = $user->roleIDList();
00235 $discountList = eZUserDiscountRule::fetchIDListByUserID( $user->attribute( 'contentobject_id' ) );
00236
00237 if ( !$language )
00238 {
00239 $language = false;
00240 }
00241 $currentSiteAccess = $GLOBALS['eZCurrentAccess']['name'];
00242
00243 $cacheHashArray = array( $nodeID,
00244 $viewMode,
00245 $language,
00246 $offset,
00247 $layout,
00248 implode( '.', $roleList ),
00249 implode( '.', $limitedAssignmentValueList),
00250 implode( '.', $discountList ),
00251 eZSys::indexFile() );
00252
00253
00254 if ( $viewParameters )
00255 {
00256 $vpString = "";
00257 ksort( $viewParameters );
00258 foreach ( $viewParameters as $key => $value )
00259 {
00260 if ( !$key )
00261 continue;
00262 $vpString .= 'vp:' . $key . '=' . $value;
00263 }
00264 $cacheHashArray[] = $vpString;
00265 }
00266
00267
00268 if ( $cachedViewPreferences === false )
00269 {
00270 $siteIni =& eZINI::instance( );
00271 $depPreferences = $siteIni->variable( 'ContentSettings', 'CachedViewPreferences' );
00272 }
00273 else
00274 {
00275 $depPreferences = $cachedViewPreferences;
00276 }
00277 if ( isset ( $depPreferences[$viewMode] ) )
00278 {
00279 $depPreferences = explode( ';', $depPreferences[$viewMode] );
00280 $pString = "";
00281
00282 $preferences = eZPreferences::values( $user );
00283 foreach( $depPreferences as $pref )
00284 {
00285 $pref = explode( '=', $pref );
00286 if ( isset( $pref[0] ) )
00287 {
00288 if ( isset( $preferences[$pref[0]] ) )
00289 $pString .= 'p:' . $pref[0] . '='. $preferences[$pref[0]]. ';';
00290 else if ( isset( $pref[1] ) )
00291 $pString .= 'p:' . $pref[0] . '='. $pref[1]. ';';
00292 }
00293 }
00294 $cacheHashArray[] = $pString;
00295 }
00296
00297 $ini =& eZINI::instance();
00298
00299 $cacheFile = $nodeID . '-' . md5( implode( '-', $cacheHashArray ) ) . '.cache';
00300 $extraPath = eZDir::filenamePath( $nodeID );
00301 $cacheDir = eZDir::path( array( eZSys::cacheDirectory(), $ini->variable( 'ContentSettings', 'CacheDir' ), $currentSiteAccess, $extraPath ) );
00302 $cachePath = eZDir::path( array( $cacheDir, $cacheFile ) );
00303
00304 return array( 'cache_path' => $cachePath,
00305 'cache_dir' => $cacheDir,
00306 'cache_file' => $cacheFile );
00307 }
00308
00309 }
00310
00311 ?>