/** * Prepares the navbar view so that it can be fetched and rendered. * Note: Forcing the cache to be ignored is useful if the subnav has just been * updated. * * @param vBCms_Item_Content $node - The current node * @param bool $refresh - Forces the cache to be ignored and the view to be rebuilt. */ public static function prepareNavBar($node = false, $refresh = false) { // Normalize node $node = ($node ? $node : 1); if (!$node instanceof vBCms_Item_Content) { $node = new vBCms_Item_Content($node, vBCms_Item_Content::INFO_NAVIGATION); } $cache_key = self::getHash($node); if ($refresh OR !$navnodes = vB_Cache::instance()->read($cache_key, false, true)) { //The query to pull the navigation requires that the //parent information be available $node->requireInfo(vBCms_Item_Content::INFO_PARENTS); $node->isValid(); $node->requireInfo(vBCms_Item_Content::INFO_NAVIGATION); if ($navnodes = $node->getNavigationNodes()) { // get collection $collection = new vBCms_Collection_Content($navnodes, vBCms_Item_Content::INFO_NODE | vBCms_Item_Content::INFO_PARENTS); $collection->filterVisible(false); // check count if (!$collection->isValid()) { return false; } // set original ids as keys $navnodes = array_flip($navnodes); // remap order foreach ($collection AS $navnode) { $navnodes[$navnode->getNodeId()] = $navnode; } unset($collection); // remove unfound entries foreach ($navnodes AS $id => $navnode) { if (!$navnode instanceof vBCms_Item_Content) { unset($navnodes[$id]); } } // write cache vB_Cache::instance()->write( $cache_key, $navnodes, self::$cache_ttl, array( self::getCacheEventId($node->getNavigationNode()), self::GLOBAL_CACHE_EVENT, self::GLOBAL_SECTION_CACHE_EVENT ) ); } } if (is_array($navnodes) AND !empty($navnodes)) { $perms_load = array(); foreach($navnodes as $navnode) { $perms_load[] = $navnode->getNodeId(); } vBCMS_Permissions::loadPermissionsfrom(array_keys($perms_load)); } // create navlinks for published nodes $links = array(); $route = new vBCms_Route_Content(); foreach ((array)$navnodes AS $navnode) { if ($navnode->isPublished() AND $navnode->canView()) { $route->node = $navnode->getUrlSegment(); $links[] = array( 'title' => $navnode->getTitle(), 'url' => $route->getCurrentUrl() ); } } if (!self::$view OR $refresh) { self::$view = new vB_View('vbcms_navbar_link'); self::$view->links = $links; } }