/** * Imports a structure from liberty_structures to nexus including hierarchy * @return number of errors encountered */ function importStructure($pStructureId = NULL) { if ($pStructureId || !is_numeric($pStructureId)) { include_once LIBERTY_PKG_PATH . 'LibertyStructure.php'; $structure = new LibertyStructure($pStructureId); $structure->load(); // order matters for these conditionals if (empty($structure) || !$structure->isValid()) { $this->mErrors['structure'] = tra('Invalid structure'); } if ($structure->mInfo['root_structure_id'] == $structure->mInfo['structure_id']) { $rootStructure =& $structure; } else { $rootStructure = new LibertyStructure($structure->mInfo['root_structure_id']); $rootStructure->load(); } $structureList = $rootStructure->getSubTree($rootStructure->mInfo['structure_id']); $menuHash['title'] = $rootStructure->mInfo['title']; if ($menu_id = $this->storeMenu($menuHash)) { // we need to insert the structure title manually, as this is not part of the structure $itemHash = array('menu_id' => $menu_id, 'title' => $rootStructure->mInfo['title'], 'pos' => 1, 'parent_id' => 0, 'rsrc' => $rootStructure->mInfo['structure_id'], 'rsrc_type' => 'structure_id'); $storedItem = $this->storeItem($itemHash); // insert all nodes in structure as menu items foreach ($structureList as $structureItem) { if ($structureItem['first']) { // get id of the current item $query = "SELECT MAX(`item_id`) FROM `" . BIT_DB_PREFIX . "nexus_menu_items`"; $parentPath[] = $this->mDb->getOne($query, array()); $parent_id = end($parentPath); } if ($structureItem['last']) { // move up one step in the structure parentPath array_pop($parentPath); $parent_id = end($parentPath); } else { // save the item in the menu $tmpItem = $rootStructure->getNode($structureItem['structure_id']); $itemHash = array('menu_id' => $menu_id, 'title' => $structureItem['title'], 'pos' => $tmpItem['pos'], 'parent_id' => $parent_id, 'rsrc' => isset($structureItem['structure_id']) ? $structureItem['structure_id'] : NULL, 'rsrc_type' => 'structure_id'); $storedItem = $this->storeItem($itemHash); } } } else { $this->mErrors['store_menu'] = tra('The menu could not be stored.'); } } else { $this->mErrors['structure_id'] = tra('No valid structure id was given.'); } return count($this->mErrors) == 0; }
/** * Get all child pigeonholes starting from any parent * * @param array $pContentId of the pigoenhole * @param array $pStructureId of the pigeonhole * @access public * @return array of child pigeonholes on success, empty array on failure */ function getSubPigeonholes($pContentId = NULL, $pStructureId = NULL) { global $gStructure; $ret = array(); if (empty($gStructure)) { $struct = new LibertyStructure(); } else { $struct =& $gStructure; } if (@BitBase::verifyId($pContentId) && !@BitBase::verifyId($pStructureId)) { $pigeon = $struct->getNode(NULL, $pContentId); $pStructureId = $pigeon['structure_id']; } if (@BitBase::verifyId($pStructureId)) { $tree = $struct->getSubTree($pStructureId); // weed out duplicates foreach ($tree as $pigeon) { if (!in_array($pigeon['content_id'], array_keys($ret))) { $ret[$pigeon['content_id']] = $pigeon; } } } return $ret; }
global $gStructure; /** * first pass at trying to bring books up to speed with modern perm checking * we initialize an object here since books dont have an include **/ // get a book instance global $gContent; if (@BitBase::verifyId($_REQUEST["structure_id"]) || @BitBase::verifyId($_REQUEST["content_id"])) { include_once LIBERTY_PKG_PATH . 'lookup_content_inc.php'; if (empty($gContent)) { $gBitSystem->fatalError('Error: Invalid structure id, the book you requested could not be found.'); } elseif (empty($_REQUEST["structure_id"])) { // we were passed a valid content_id. Make sure the root node exists, and if not, create it. $newStructure = new LibertyStructure(); // alias => '' is a temporary setting until alias stuff has been removed if (!($node = $newStructure->getNode(NULL, $gContent->mContentId))) { $structureHash = array('content_id' => $gContent->mContentId, 'alias' => ''); $_REQUEST["structure_id"] = $newStructure->storeNode($structureHash); } else { $_REQUEST["structure_id"] = $node['structure_id']; } } } else { $gContent = new BitBook(); if (!empty($_REQUEST['name'])) { if ($pageId = $gContent->findByPageName($_REQUEST['name'])) { $gContent->mPageId = $pageId; $gContent->load(); } elseif (empty($_REQUEST["createstructure"])) { $gBitSystem->fatalError('Error: Invalid name, the book you requested could not be found.'); }