function show($view, $loc = null, $title = '') { if (empty($view)) { $view = "Default"; } $source_select = array(); $clickable_mods = null; // Show all $dest = null; $singleview = '_container'; $singlemodule = 'containermodule'; if (expSession::is_set('source_select') && defined('SELECTOR')) { $source_select = expSession::get('source_select'); $singleview = $source_select['view']; $singlemodule = $source_select['module']; $clickable_mods = $source_select['showmodules']; if (!is_array($clickable_mods)) { $clickable_mods = null; } $dest = $source_select['dest']; } global $db, $user; $container = null; $container_key = serialize($loc); $cache = expSession::getCacheValue('containermodule'); if (!isset($this) || !isset($this->_hasParent) || $this->_hasParent == 0) { // Top level container. if (!isset($cache['top'][$container_key])) { $container = $db->selectObject('container', "external='" . serialize(null) . "' AND internal='" . $container_key . "'"); //if container isn't here already, then create it. if ($container == null) { $container->external = serialize(null); $container->internal = serialize($loc); $container->view = $view; $container->title = $title; $container->id = $db->insertObject($container, 'container'); } $cache['top'][$container_key] = $container; expSession::setCacheValue('containermodule', $cache); } else { $container = $cache['top'][$container_key]; } if (!defined('PREVIEW_READONLY') || defined('SELECTOR')) { $view = empty($container->view) ? $view : $container->view; } $title = $container->title; } $template = new template('containermodule', $view, $loc, $cache); if ($dest) { $template->assign('dest', $dest); } $template->assign('singleview', $singleview); $template->assign('singlemodule', $singlemodule); $template->assign('top', $container); $containers = array(); if (!isset($cache[$container_key])) { foreach ($db->selectObjects('container', "external='" . $container_key . "'") as $c) { if ($c->is_private == 0 || expPermissions::check('view', expCore::makeLocation($loc->mod, $loc->src, $c->id))) { $containers[$c->rank] = $c; } } $cache[$container_key] = $containers; expSession::setCacheValue('containermodule', $cache); } else { $containers = $cache[$container_key]; } ksort($containers); foreach (array_keys($containers) as $i) { $location = unserialize($containers[$i]->internal); // check to see if this is a controller or module $iscontroller = expModules::controllerExists($location->mod); $modclass = $iscontroller ? expModules::getControllerClassName($location->mod) : $location->mod; if (class_exists($modclass)) { $mod = new $modclass(); ob_start(); $mod->_hasParent = 1; if ($iscontroller) { renderAction(array('controller' => $location->mod, 'action' => $containers[$i]->action, 'src' => $location->src, 'view' => $containers[$i]->view, 'moduletitle' => $containers[$i]->title)); } else { $mod->show($containers[$i]->view, $location, $containers[$i]->title); } $containers[$i]->output = trim(ob_get_contents()); ob_end_clean(); $containers[$i]->info = array('module' => $mod->name(), 'source' => $location->src, 'hasContent' => $mod->hasContent(), 'hasSources' => $mod->hasSources(), 'hasViews' => $mod->hasViews(), 'class' => $modclass, 'supportsWorkflow' => $mod->supportsWorkflow() ? 1 : 0, 'workflowPolicy' => '', 'workflowUsesDefault' => 0, 'clickable' => $clickable_mods == null || in_array($modclass, $clickable_mods), 'hasConfig' => $db->tableExists($modclass . "_config")); } else { $containers[$i]->output = sprintf(gt('The module "%s" was not found in the system'), $location->mod); $containers[$i]->info = array('module' => sprintf(gt('Unknown: %s'), $location->mod), 'source' => $location->src, 'hasContent' => 0, 'hasSources' => 0, 'hasViews' => 0, 'class' => $modclass, 'supportsWorkflow' => 0, 'workflowPolicy' => '', 'workflowUsesDefault' => 0, 'hasConfig' => $db->tableExists($modclass . "_config"), 'clickable' => 0); } $containers[$i]->moduleLocation = $location; $cloc = null; $cloc->mod = $loc->mod; $cloc->src = $loc->src; $cloc->int = $containers[$i]->id; $location->mod = str_replace('Controller', '', $location->mod); $containers[$i]->permissions = array('administrate' => expPermissions::check('administrate', $location) ? 1 : 0, 'configure' => expPermissions::check('configure', $location) ? 1 : 0); } $template->assign('user', $user); $template->assign('containers', $containers); $template->assign('hasParent', isset($this) && isset($this->_hasParent) ? 1 : 0); $template->register_permissions(array('administrate', 'add_module', 'edit_module', 'delete_module', 'order_modules'), $loc); $template->output(); }
/** * returns all the section's children * * @static * @param $parent top level parent id * @param int $depth variable to hold level of recursion * @param array $parents * * @return array */ static function levelTemplate($parent, $depth = 0, $parents = array()) { if ($parent != 0) { $parents[] = $parent; } global $db, $user; $nodes = array(); $cache = expSession::getCacheValue('navigationmodule'); if (!isset($cache['kids'][$parent])) { $kids = $db->selectObjects('section', 'parent=' . $parent); $cache['kids'][$parent] = $kids; expSession::setCacheValue('navigationmodule', $cache); } else { $kids = $cache['kids'][$parent]; } $kids = expSorter::sort(array('array' => $kids, 'sortby' => 'rank', 'order' => 'ASC')); for ($i = 0; $i < count($kids); $i++) { $child = $kids[$i]; //foreach ($kids as $child) { if ($child->public == 1 || expPermissions::check('view', expCore::makeLocation('navigationmodule', '', $child->id))) { $child->numParents = count($parents); $child->depth = $depth; $child->first = $i == 0 ? 1 : 0; $child->last = $i == count($kids) - 1 ? 1 : 0; $child->parents = $parents; $child->canManage = isset($user->is_acting_admin) && $user->is_acting_admin == 1 ? 1 : 0; $child->canManageRank = $child->canManage; if (!isset($child->sef_name)) { $child->sef_name = ''; } // Generate the link attribute base on alias type. if ($child->alias_type == 1) { // External link. Set the link to the configured website URL. // This is guaranteed to be a full URL because of the // section::updateExternalAlias() method in datatypes/section.php $child->link = $child->external_link; } else { if ($child->alias_type == 2) { // Internal link. // Need to check and see if the internal_id is pointing at an external link. $dest = $db->selectObject('section', 'id=' . $child->internal_id); if ($dest->alias_type == 1) { // This internal alias is pointing at an external alias. // Use the external_link of the destination section for the link $child->link = $dest->external_link; } else { // Pointing at a regular section. This is guaranteed to be // a regular section because aliases cannot be turned into sections, // (and vice-versa) and because the section::updateInternalLink // does 'alias to alias' dereferencing before the section is saved // (see datatypes/section.php) //added by Tyler to pull the descriptions through for the children view $child->description = $dest->description; $child->link = expCore::makeLink(array('section' => $child->internal_id)); } } else { // Normal link. Just create the URL from the section's id. $child->link = expCore::makeLink(array('section' => $child->id), '', $child->sef_name); } } //$child->numChildren = $db->countObjects('section','parent='.$child->id); $nodes[] = $child; $nodes = array_merge($nodes, navigationmodule::levelTemplate($child->id, $depth + 1, $parents)); } } return $nodes; }