public function checkSaveData($view) { require_once DIR . '/includes/functions_databuild.php'; require_once DIR . '/includes/functions.php'; fetch_phrase_group('cpcms'); ($hook = vBulletinHook::fetch_hook('vbcms_section_save_start')) ? eval($hook) : false; // Check if inline form was submitted vB::$vbulletin->input->clean_array_gpc('r', array( 'do' => vB_Input::TYPE_STR )); //let's make sure we use the Post value of do vB::$vbulletin->input->clean_array_gpc('p', array( 'do' => vB_Input::TYPE_STR, 'per_page' => TYPE_INT, 'new_parentid' => TYPE_INT, 'html_title' => TYPE_STR, 'title' => TYPE_STR, 'displayorder' => TYPE_INT, 'content_layout' => TYPE_INT, 'pagination_links' => TYPE_INT, 'contentfrom' => TYPE_INT, 'new_parentid' => TYPE_INT, 'simple_paging' => TYPE_INT, 'perpage' => TYPE_INT, )); if (vB::$vbulletin->GPC_exists['new_parentid'] AND intval(vB::$vbulletin->GPC['new_parentid']) AND (intval(vB::$vbulletin->GPC['new_parentid'] != $this->content->getParentId())) ) { vBCms_ContentManager::moveSection(array($this->content->getNodeId()), vB::$vbulletin->GPC['new_parentid']); } if ($_REQUEST['do'] == 'apply' OR $_REQUEST['do'] == 'update' ) { // collect error messages $errors = array(); // create dm $dm = $this->content->getDM(); $this->config = array(); if (vB::$vbulletin->GPC_exists['perpage']) //This is the number displayed on the edit page { $current_user = new vB_Legacy_CurrentUser(); if (!$stored_prefs = $current_user->getSearchPrefs()) { $stored_prefs = array(); } if (vB::$vbulletin->GPC_exists['perpage'] AND intval(vB::$vbulletin->GPC['perpage'])) { $stored_prefs['cmsadmin_showperpage'] = intval(vB::$vbulletin->GPC['perpage']); $current_user->saveSearchPrefs($stored_prefs); } } if (vB::$vbulletin->GPC_exists['per_page']) //This is the number of items displayed to the end user in the view { $this->config['items_perhomepage'] = vB::$vbulletin->GPC['per_page']; } if (vB::$vbulletin->GPC_exists['displayorder']) { $this->config['section_priority'] = vB::$vbulletin->GPC['displayorder']; } if (vB::$vbulletin->GPC_exists['content_layout']) { $this->config['content_layout'] = vB::$vbulletin->GPC['content_layout']; } if (vB::$vbulletin->GPC_exists['title']) { $this->config['title'] = vB::$vbulletin->GPC['title']; } if (vB::$vbulletin->GPC_exists['pagination_links']) { $this->config['pagination_links'] = vB::$vbulletin->GPC['pagination_links']; } if (vB::$vbulletin->GPC_exists['simple_paging']) { $this->config['simple_paging'] = 1; } $this->config['contentfrom'] = (vB::$vbulletin->GPC_exists['contentfrom'] AND (vB::$vbulletin->GPC['contentfrom'] == 1)) ? 1 : 2; if (count($this->config)) { $dm->set('config', $this->config); $this->content->setConfig($this->config); } $dm->saveFromForm($this->content->getNodeId()); if ($dm->hasErrors()) { $fieldnames = array( 'title' => new vB_Phrase('global', 'title') ); $view->errors = $dm->getErrors(array_keys($fieldnames)); $view->error_summary = self::getErrorSummary($dm->getErrors(array_keys($fieldnames)), $fieldnames); $view->status = $view->error_view->title; } else { $view->status = new vB_Phrase('vbcms', 'content_saved'); // reroute to the section $route = new vBCms_Route_Content(); $route->node = $this->content->getUrlSegment(); $url = $route->getCurrentUrl(); ($hook = vBulletinHook::fetch_hook('vbcms_section_save_end')) ? eval($hook) : false; } } $this->changed = true; ($hook = vBulletinHook::fetch_hook('vbcms_section_save_end')) ? eval($hook) : false; //invalidate the navigation cache. vB_Cache::instance()->event('sections_updated'); vB_Cache::instance()->event('articles_updated'); vB_Cache::instance()->event($this->content->getCacheEvents()); vB_Cache::instance()->event($this->getCleanCacheEvents()); vB_Cache::instance()->cleanNow(); $this->content->reset(); }
/** * Fetches the standard page view for a widget. * * @param bool $skip_errors - If using a collection, omit widgets that throw errors * @return vBCms_View_Widget - The resolved view, or array of views */ public function getPageView() { $this->assertWidget(); if (! isset($vbulletin->userinfo['permissions']['cms'])) { vBCMS_Permissions::getUserPerms(); } // Create view $config = $this->widget->getConfig(); if (!isset($config['template_name']) OR ($config['template_name'] == '') ) { $config['template_name'] = 'vbcms_widget_sectionnav_page'; } $canviewlist = implode(', ', vB::$vbulletin->userinfo['permissions']['cms']['viewonly']); $caneditlist = implode(', ', vB::$vbulletin->userinfo['permissions']['cms']['canedit']); $for_node = intval($this->content->getContentTypeId()) == intval(vb_Types::instance()->getContentTypeID("vBCms_Section")) ? $this->content->getNodeId() : $this->content->getParentId(); // Create view $view = new vBCms_View_Widget($config['template_name']); if ( $link_nodes = vB_Cache::instance()->read($cache_key = $this->getHash($this->widget->getId(), $for_node), false, true)) { $links_before = $link_nodes['links_before']; $links_above = $link_nodes['links_above']; $links_sibling = $link_nodes['links_sibling']; $links_children = $link_nodes['links_children']; $links_after = $link_nodes['links_after']; $myself = $link_nodes['myself']; } else { //If we're on a section, we show for this nodeid. If we're on // on a leaf-type node we show for the parent $section_possibles = vBCms_ContentManager::getSections(); $my_left = $this->content->getNodeLeft(); $my_right = $this->content->getNodeRight(); $my_parent = $this->content->getParentId(); $my_nodeid = $this->content->getNodeId(); $my_title = ''; $links_above = array(); $links_before = array(); $links_above = array(); $links_sibling = array(); $links_after = array(); $links_children = array(); $top_level = array(); if (! isset(vB::$vbulletin->userinfo['permissions']['cms']) ) { vBCMS_Permissions::getUserPerms(); } $route = new vBCms_Route_Content(); $route->setParameter('action', 'view'); $homeid = $sections[0]['nodeid']; //Now let's scan the array; $indent = 0; $i = 1; $noderight = 0; //Let's remove items we're not supposed to see. $sections= array(); foreach ($section_possibles as $key => $section) { if (/** This user has permissions to view this record **/ ( in_array($section['permissionsfrom'], vB::$vbulletin->userinfo['permissions']['cms']['canedit']) OR (in_array($section['permissionsfrom'],vB::$vbulletin->userinfo['permissions']['cms']['canview'] ) AND $section['setpublish'] == '1' AND $section['publishdate'] < TIMENOW )) AND /** This user also has rights to the parents **/ ($section['noderight'] > $noderight)) { $sections[] = $section; } else { //So the children will be skipped $noderight = $section['noderight']; } } //First the sections ahead of us while($i < count($sections) AND $my_left > $sections[$i]['nodeleft']) { $route->node = $sections[$i]['nodeid'] . (strlen($sections[$i]['url']) ? '-' . $sections[$i]['url'] : '' ); //see if it's a top-level if ($sections[$i]['parentnode'] == $homeid) { $links_before[] = array('title' => $sections[$i]['title'], 'sectionurl' => $route->getCurrentUrl(array('node' =>$route->node, 'action' => 'view')), 'indent' => 0); }//is it a sibling? else if ($my_parent == $sections[$i]['parentnode']) { $links_sibling[] = array('title' => $sections[$i]['title'], 'sectionurl' => $route->getCurrentUrl(array('node' =>$route->node, 'action' => 'view')), 'indent' => 0); } $i++; } //Now our parentage and children while($i < count($sections) AND $my_right > $sections[$i]['nodeleft']) { $route->node = $sections[$i]['nodeid'] . (strlen($sections[$i]['url']) ? '-' . $sections[$i]['url'] : '' ); if ($my_nodeid == $sections[$i]['parentnode']) { $links_children[] = array('title' => $sections[$i]['title'], 'sectionurl' => $route->getCurrentUrl(array('node' =>$route->node, 'action' => 'view')), 'indent' => ($indent) * 10); } else if ($my_nodeid == $sections[$i]['nodeid']) { $myself = array('title' => $sections[$i]['title'], 'sectionurl' => $route->getCurrentUrl(array('node' =>$route->node, 'action' => 'view')), 'indent' => $indent * 10); } else { $links_above[] = array('title' => $sections[$i]['title'], 'sectionurl' => $route->getCurrentUrl(array('node' =>$route->node, 'action' => 'view')), 'indent' => $indent * 10); $my_title = $sections[$i]['title']; $indent++; } $i++; } //Now the afters while ($i < count($sections)) { $route->node = $sections[$i]['nodeid'] . (strlen($sections[$i]['url']) ? '-' . $sections[$i]['url'] : '' ); if ($sections[$i]['parentnode'] == $homeid) { $links_after[] = array('title' => $sections[$i]['title'], 'sectionurl' => $route->getCurrentUrl(array('node' =>$route->node, 'action' => 'view')), 'indent' => 0); } else if ($my_parent == $sections[$i]['parentnode']) { $links_sibling[] = array('title' => $sections[$i]['title'], 'sectionurl' => $route->getCurrentUrl(array('node' =>$route->node, 'action' => 'view')), 'indent' => 0); } $i++; } foreach($links_sibling as $key => $value) { $links_sibling[$key]['indent'] = $indent * 10; } $route->node = $sections[1]['nodeid'] . (strlen($sections[1]['url']) ? '-' . $sections[1]['url'] : '' ); //We have the pieces, now let's string them together; //Top level first $links_before = array_merge(array(array('title' => $sections[0]['title'], 'sectionurl' => $route->getCurrentUrl(array('node' =>$route->node, 'action' => 'view')), 'indent' => 0)), $links_before); //Now write to the cache vB_Cache::instance()->write($cache_key, array('links_before' => $links_before, 'links_above' => $links_above, 'links_sibling' => $links_sibling , 'links_after' => $links_after, 'links_children' => $links_children, 'myself' => $myself ), $this->cache_ttl, array('section_nav_' . $for_node, 'sections_updated')); } //The first record is the root $view->links_before = $links_before; $view->links_above = $links_above; $view->links_sibling = $links_sibling; $view->links_children = $links_children; $view->links_after = $links_after; $view->myself = $myself; $view->widget_title = $this->widget->getTitle(); return $view; }
/** * 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; } }