[ Index ] |
|
Code source de eZ Publish 3.9.0 |
1 <?php 2 // 3 // Definition of eZNodeviewfunctions class 4 // 5 // Created on: <20-Apr-2004 11:57:36 bf> 6 // 7 // SOFTWARE NAME: eZ publish 8 // SOFTWARE RELEASE: 3.9.0 9 // BUILD VERSION: 17785 10 // COPYRIGHT NOTICE: Copyright (C) 1999-2006 eZ systems AS 11 // SOFTWARE LICENSE: GNU General Public License v2.0 12 // NOTICE: > 13 // This program is free software; you can redistribute it and/or 14 // modify it under the terms of version 2.0 of the GNU General 15 // Public License as published by the Free Software Foundation. 16 // 17 // This program is distributed in the hope that it will be useful, 18 // but WITHOUT ANY WARRANTY; without even the implied warranty of 19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 // GNU General Public License for more details. 21 // 22 // You should have received a copy of version 2.0 of the GNU General 23 // Public License along with this program; if not, write to the Free 24 // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 25 // MA 02110-1301, USA. 26 // 27 // 28 29 /*! 30 \class eZNodeviewfunctions eznodeviewfunctions.php 31 \brief The class eZNodeviewfunctions does 32 33 */ 34 35 class eZNodeviewfunctions 36 { 37 function &generateNodeView( &$tpl, &$node, &$object, $languageCode, $viewMode, $offset, 38 $cacheDir, $cachePath, $viewCacheEnabled, 39 $viewParameters = array( 'offset' => 0, 'year' => false, 'month' => false, 'day' => false ), 40 $collectionAttributes = false, $validation = false ) 41 { 42 include_once ( 'kernel/classes/ezsection.php' ); 43 eZSection::setGlobalID( $object->attribute( 'section_id' ) ); 44 45 $section = eZSection::fetch( $object->attribute( 'section_id' ) ); 46 if ( $section ) 47 $navigationPartIdentifier = $section->attribute( 'navigation_part_identifier' ); 48 else 49 $navigationPartIdentifier = null; 50 51 $keyArray = array( array( 'object', $object->attribute( 'id' ) ), 52 array( 'node', $node->attribute( 'node_id' ) ), 53 array( 'parent_node', $node->attribute( 'parent_node_id' ) ), 54 array( 'class', $object->attribute( 'contentclass_id' ) ), 55 array( 'class_identifier', $node->attribute( 'class_identifier' ) ), 56 array( 'view_offset', $offset ), 57 array( 'viewmode', $viewMode ), 58 array( 'navigation_part_identifier', $navigationPartIdentifier ), 59 array( 'depth', $node->attribute( 'depth' ) ), 60 array( 'url_alias', $node->attribute( 'url_alias' ) ), 61 array( 'class_group', $object->attribute( 'match_ingroup_id_list' ) ) ); 62 63 $parentClassID = false; 64 $parentClassIdentifier = false; 65 $parentNode = $node->attribute( 'parent' ); 66 if ( is_object( $parentNode ) ) 67 { 68 $parentObject = $parentNode->attribute( 'object' ); 69 if ( is_object( $parentObject ) ) 70 { 71 $parentClass = $parentObject->contentClass(); 72 if ( is_object( $parentClass ) ) 73 { 74 $parentClassID = $parentClass->attribute( 'id' ); 75 $parentClassIdentifier = $parentClass->attribute( 'identifier' ); 76 77 $keyArray[] = array( 'parent_class', $parentClassID ); 78 $keyArray[] = array( 'parent_class_identifier', $parentClassIdentifier ); 79 } 80 } 81 } 82 83 $res =& eZTemplateDesignResource::instance(); 84 $res->setKeys( $keyArray ); 85 86 if ( $languageCode ) 87 { 88 $oldLanguageCode = $node->currentLanguage(); 89 $node->setCurrentLanguage( $languageCode ); 90 } 91 92 $tpl->setVariable( 'node', $node ); 93 $tpl->setVariable( 'viewmode', $viewMode ); 94 $tpl->setVariable( 'language_code', $languageCode ); 95 $tpl->setVariable( 'view_parameters', $viewParameters ); 96 $tpl->setVariable( 'collection_attributes', $collectionAttributes ); 97 $tpl->setVariable( 'validation', $validation ); 98 $tpl->setVariable( 'persistent_variable', false ); 99 100 $parents =& $node->attribute( 'path' ); 101 102 $path = array(); 103 $titlePath = array(); 104 foreach ( $parents as $parent ) 105 { 106 $path[] = array( 'text' => $parent->attribute( 'name' ), 107 'url' => '/content/view/full/' . $parent->attribute( 'node_id' ), 108 'url_alias' => $parent->attribute( 'url_alias' ), 109 'node_id' => $parent->attribute( 'node_id' ) 110 ); 111 } 112 113 $titlePath = $path; 114 $path[] = array( 'text' => $object->attribute( 'name' ), 115 'url' => false, 116 'url_alias' => false, 117 'node_id' => $node->attribute( 'node_id' ) ); 118 119 $titlePath[] = array( 'text' => $object->attribute( 'name' ), 120 'url' => false, 121 'url_alias' => false ); 122 123 $tpl->setVariable( 'node_path', $path ); 124 125 $Result = array(); 126 $Result['content'] =& $tpl->fetch( 'design:node/view/' . $viewMode . '.tpl' ); 127 $Result['view_parameters'] =& $viewParameters; 128 $Result['path'] =& $path; 129 $Result['title_path'] =& $titlePath; 130 $Result['section_id'] =& $object->attribute( 'section_id' ); 131 $Result['node_id'] =& $node->attribute( 'node_id' ); 132 $Result['navigation_part'] = $navigationPartIdentifier; 133 134 $contentInfoArray = array(); 135 $contentInfoArray['object_id'] = $object->attribute( 'id' ); 136 $contentInfoArray['node_id'] = $node->attribute( 'node_id' ); 137 $contentInfoArray['parent_node_id'] = $node->attribute( 'parent_node_id' ); 138 $contentInfoArray['class_id'] = $object->attribute( 'contentclass_id' ); 139 $contentInfoArray['class_identifier'] = $node->attribute( 'class_identifier' ); 140 $contentInfoArray['offset'] = $offset; 141 $contentInfoArray['viewmode'] = $viewMode; 142 $contentInfoArray['navigation_part_identifier'] = $navigationPartIdentifier; 143 $contentInfoArray['node_depth'] = $node->attribute( 'depth' ); 144 $contentInfoArray['url_alias'] = $node->attribute( 'url_alias' ); 145 $contentInfoArray['persistent_variable'] = false; 146 if ( $tpl->variable( 'persistent_variable' ) !== false ) 147 { 148 $contentInfoArray['persistent_variable'] = $tpl->variable( 'persistent_variable' ); 149 } 150 $contentInfoArray['class_group'] = $object->attribute( 'match_ingroup_id_list' ); 151 $contentInfoArray['parent_class_id'] = $parentClassID; 152 $contentInfoArray['parent_class_identifier'] = $parentClassIdentifier; 153 154 $Result['content_info'] = $contentInfoArray; 155 156 // Store which templates were used to make this cache. 157 $Result['template_list'] = $tpl->templateFetchList(); 158 159 // Check if time to live is set in template 160 if ( $tpl->hasVariable( 'cache_ttl' ) ) 161 { 162 $cacheTTL =& $tpl->variable( 'cache_ttl' ); 163 } 164 165 if ( !isset( $cacheTTL ) ) 166 { 167 $cacheTTL = -1; 168 } 169 170 // Check if cache time = 0 (disabled) 171 if ( $cacheTTL == 0 ) 172 { 173 $viewCacheEnabled = false; 174 } 175 176 $Result['cache_ttl'] = $cacheTTL; 177 178 // Store view cache 179 if ( $viewCacheEnabled ) 180 { 181 $serializeString = serialize( $Result ); 182 183 if ( !file_exists( $cacheDir ) ) 184 { 185 include_once ( 'lib/ezfile/classes/ezdir.php' ); 186 $ini =& eZINI::instance(); 187 $perm = octdec( $ini->variable( 'FileSettings', 'StorageDirPermissions' ) ); 188 eZDir::mkdir( $cacheDir, $perm, true ); 189 } 190 $oldumask = umask( 0 ); 191 $pathExisted = file_exists( $cachePath ); 192 $ini =& eZINI::instance(); 193 $perm = octdec( $ini->variable( 'FileSettings', 'StorageFilePermissions' ) ); 194 $fp = @fopen( $cachePath, "w" ); 195 if ( !$fp ) 196 eZDebug::writeError( "Could not open file '$cachePath' for writing, perhaps wrong permissions" ); 197 if ( $fp and 198 !$pathExisted ) 199 chmod( $cachePath, $perm ); 200 umask( $oldumask ); 201 202 if ( $fp ) 203 { 204 fwrite( $fp, $serializeString ); 205 fclose( $fp ); 206 } 207 208 // VS-DBFILE 209 210 require_once ( 'kernel/classes/ezclusterfilehandler.php' ); 211 $fileHandler = eZClusterFileHandler::instance(); 212 $fileHandler->fileStore( $cachePath, 'viewcache', true ); 213 } 214 215 if ( $languageCode ) 216 { 217 $node->setCurrentLanguage( $oldLanguageCode ); 218 } 219 220 return $Result; 221 } 222 223 function generateViewCacheFile( $user, $nodeID, $offset, $layout, $language, $viewMode, $viewParameters = false, $cachedViewPreferences = false ) 224 { 225 include_once ( 'kernel/classes/ezuserdiscountrule.php' ); 226 include_once ( 'kernel/classes/ezpreferences.php' ); 227 228 $limitedAssignmentValueList = $user->limitValueList(); 229 $roleList = $user->roleIDList(); 230 $discountList = eZUserDiscountRule::fetchIDListByUserID( $user->attribute( 'contentobject_id' ) ); 231 232 if ( !$language ) 233 { 234 $language = false; 235 } 236 $currentSiteAccess = $GLOBALS['eZCurrentAccess']['name']; 237 238 $cacheHashArray = array( $nodeID, 239 $viewMode, 240 $language, 241 $offset, 242 $layout, 243 implode( '.', $roleList ), 244 implode( '.', $limitedAssignmentValueList), 245 implode( '.', $discountList ), 246 eZSys::indexFile() ); 247 248 // Make the cache unique for every case of view parameters 249 if ( $viewParameters ) 250 { 251 $vpString = ""; 252 ksort( $viewParameters ); 253 foreach ( $viewParameters as $key => $value ) 254 { 255 if ( !$key ) 256 continue; 257 $vpString .= 'vp:' . $key . '=' . $value; 258 } 259 $cacheHashArray[] = $vpString; 260 } 261 262 // Make the cache unique for every case of the preferences 263 if ( $cachedViewPreferences === false ) 264 { 265 $siteIni =& eZINI::instance( ); 266 $depPreferences = $siteIni->variable( 'ContentSettings', 'CachedViewPreferences' ); 267 } 268 else 269 { 270 $depPreferences = $cachedViewPreferences; 271 } 272 if ( isset ( $depPreferences[$viewMode] ) ) 273 { 274 $depPreferences = explode( ';', $depPreferences[$viewMode] ); 275 $pString = ""; 276 // Fetch preferences for the specified user 277 $preferences = eZPreferences::values( $user ); 278 foreach( $depPreferences as $pref ) 279 { 280 $pref = explode( '=', $pref ); 281 if ( isset( $pref[0] ) ) 282 { 283 if ( isset( $preferences[$pref[0]] ) ) 284 $pString .= 'p:' . $pref[0] . '='. $preferences[$pref[0]]. ';'; 285 else if ( isset( $pref[1] ) ) 286 $pString .= 'p:' . $pref[0] . '='. $pref[1]. ';'; 287 } 288 } 289 $cacheHashArray[] = $pString; 290 } 291 292 $ini =& eZINI::instance(); 293 294 $cacheFile = $nodeID . '-' . md5( implode( '-', $cacheHashArray ) ) . '.cache'; 295 $extraPath = eZDir::filenamePath( $nodeID ); 296 $cacheDir = eZDir::path( array( eZSys::cacheDirectory(), $ini->variable( 'ContentSettings', 'CacheDir' ), $currentSiteAccess, $extraPath ) ); 297 $cachePath = eZDir::path( array( $cacheDir, $cacheFile ) ); 298 299 return array( 'cache_path' => $cachePath, 300 'cache_dir' => $cacheDir, 301 'cache_file' => $cacheFile ); 302 } 303 304 } 305 306 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sat Feb 24 10:30:04 2007 | par Balluche grâce à PHPXref 0.7 |