} $Result['content'] = $resultContent; } } break; case eZModuleOperationInfo::STATUS_CANCELLED: $Result = array(); $Result['content'] = "Content view cancelled<br/>"; break; } return $Result; } else { $localVars = array("cacheFileArray", "NodeID", "Module", "tpl", "LanguageCode", "ViewMode", "Offset", "ini", "cacheFileArray", "viewParameters", "collectionAttributes", "validation"); if ($viewCacheEnabled) { $user = eZUser::currentUser(); $cacheFileArray = eZNodeviewfunctions::generateViewCacheFile($user, $NodeID, $Offset, $layout, $LanguageCode, $ViewMode, $viewParameters, false); $cacheFilePath = $cacheFileArray['cache_path']; $cacheFile = eZClusterFileHandler::instance($cacheFilePath); $args = compact($localVars); $Result = $cacheFile->processCache(array('eZNodeviewfunctions', 'contentViewRetrieve'), array('eZNodeviewfunctions', 'contentViewGenerate'), null, null, $args); return $Result; } else { $cacheFileArray = array('cache_dir' => false, 'cache_path' => false); $args = compact($localVars); $data = eZNodeviewfunctions::contentViewGenerate(false, $args); // the false parameter will disable generation of the 'binarydata' entry return $data['content']; // Return the $Result array } } // Looking for some view-cache code?
static function generateObjectViewCache($objectID) { // Generate the view cache $ini = eZINI::instance(); $object = eZContentObject::fetch($objectID); $user = eZUser::currentUser(); eZDebug::accumulatorStart('generate_cache', '', 'Generating view cache'); if ($ini->variable('ContentSettings', 'PreViewCache') == 'enabled') { $preCacheSiteaccessArray = $ini->variable('ContentSettings', 'PreCacheSiteaccessArray'); $currentSiteAccess = $GLOBALS['eZCurrentAccess']; // This is the default view parameters for content/view $viewParameters = array('offset' => false, 'year' => false, 'month' => false, 'day' => false, 'namefilter' => false); if (is_array($preCacheSiteaccessArray) && count($preCacheSiteaccessArray) > 0) { foreach ($preCacheSiteaccessArray as $changeToSiteAccess) { $newSiteAccess = $currentSiteAccess; $newSiteAccess['name'] = $changeToSiteAccess; unset($newSiteAccess['uri_part']); //eZSiteAccess::load() will take care of setting correct one eZSiteAccess::load($newSiteAccess); $tpl = eZTemplate::factory(); // Get the sitedesign and cached view preferences for this siteaccess $siteini = eZINI::instance('site.ini'); $cachedViewPreferences = $siteini->variable('ContentSettings', 'CachedViewPreferences'); $language = false; // Needs to be specified if you want to generate the cache for a specific language $viewMode = 'full'; $assignedNodes = $object->assignedNodes(); foreach ($assignedNodes as $node) { // We want to generate the cache for the specified user $previewCacheUsers = $ini->variable('ContentSettings', 'PreviewCacheUsers'); foreach ($previewCacheUsers as $previewCacheUserID) { // If the text is 'anon' we need to fetch the Anonymous user ID. if ($previewCacheUserID === 'anonymous') { $previewCacheUserID = $siteini->variable("UserSettings", "AnonymousUserID"); $previewCacheUser = eZUser::fetch($previewCacheUserID); } else { if ($previewCacheUserID === 'current') { $previewCacheUser = $user; } else { $previewCacheUser = eZUser::fetch($previewCacheUserID); } } if (!$previewCacheUser) { continue; } // Before we generate the view cache we must change the currently logged in user to $previewCacheUser // If not the templates might read in wrong personalized data (preferences etc.) eZUser::setCurrentlyLoggedInUser($previewCacheUser, $previewCacheUser->attribute('contentobject_id'), eZUser::NO_SESSION_REGENERATE); // Cache the current node $cacheFileArray = eZNodeviewfunctions::generateViewCacheFile($previewCacheUser, $node->attribute('node_id'), false, false, $language, $viewMode, $viewParameters, $cachedViewPreferences); $tmpRes = eZNodeviewfunctions::generateNodeView($tpl, $node, $node->attribute('object'), $language, $viewMode, false, $cacheFileArray['cache_dir'], $cacheFileArray['cache_path'], true, $viewParameters); // Cache the parent node $parentNode = $node->attribute('parent'); $objectID = $parentNode->attribute('contentobject_id'); // if parent objectID is null or is 0 we should not create cache. if ($objectID) { $cacheFileArray = eZNodeviewfunctions::generateViewCacheFile($previewCacheUser, $parentNode->attribute('node_id'), 0, false, $language, $viewMode, $viewParameters, $cachedViewPreferences); $tmpRes = eZNodeviewfunctions::generateNodeView($tpl, $parentNode, $parentNode->attribute('object'), $language, $viewMode, 0, $cacheFileArray['cache_dir'], $cacheFileArray['cache_path'], true, $viewParameters); } } } } // Restore the old user as the current one eZUser::setCurrentlyLoggedInUser($user, $user->attribute('contentobject_id'), eZUser::NO_SESSION_REGENERATE); // restore siteaccess eZSiteAccess::load($currentSiteAccess); } } if ($ini->variable('ContentSettings', 'StaticCache') == 'enabled') { $nodes = array(); $ini = eZINI::instance(); $useURLAlias =& $GLOBALS['eZContentObjectTreeNodeUseURLAlias']; $pathPrefix = $ini->variable('SiteAccessSettings', 'PathPrefix'); // get staticCacheHandler instance $optionArray = array('iniFile' => 'site.ini', 'iniSection' => 'ContentSettings', 'iniVariable' => 'StaticCacheHandler'); $options = new ezpExtensionOptions($optionArray); $staticCacheHandler = eZExtension::getHandlerClass($options); if (!isset($useURLAlias)) { $useURLAlias = $ini->variable('URLTranslator', 'Translation') == 'enabled'; } eZContentCacheManager::nodeListForObject($object, true, self::CLEAR_DEFAULT, $nodes, $handledObjectList); // If no nodes returns it means that ClearCacheMethod = self::CLEAR_NO_CACHE if (count($nodes)) { foreach ($nodes as $nodeID) { if ($useURLAlias) { $oNode = eZContentObjectTreeNode::fetch($nodeID, false, true); if (!isset($oNode)) { continue; } $urlAlias = $oNode->urlAlias(); if ($pathPrefix != '') { $tempAlias = substr($pathPrefix, strlen($pathPrefix) - 1) == '/' ? $urlAlias . '/' : $urlAlias; if (strncmp($tempAlias, $pathPrefix, strlen($tempAlias)) == 0) { $urlAlias = substr($tempAlias, strlen($pathPrefix)); } } } else { $urlAlias = 'content/view/full/' . $nodeID; } $staticCacheHandler->cacheURL('/' . $urlAlias, $nodeID); } $staticCacheHandler->generateAlwaysUpdatedCache(); } } eZDebug::accumulatorStop('generate_cache'); }