/** * 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; }
// Copyright (c) 2004, Christian Fowler, et. al. // All Rights Reserved. See below for details and a complete list of authors. // Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See http://www.gnu.org/copyleft/lesser.html for details. /** * required setup */ require_once '../kernel/setup_inc.php'; include_once LIBERTY_PKG_PATH . 'LibertyStructure.php'; if (!@BitBase::verifyId($_REQUEST["structure_id"])) { $gBitSystem->fatalError(tra("No structure indicated")); } else { global $gStructure; $gStructure = new LibertyStructure($_REQUEST["structure_id"]); $gStructure->load(); // order matters for these conditionals if (empty($gStructure) || !$gStructure->isValid()) { $gBitSystem->fatalError(tra('Invalid structure')); } if ($gStructure->mInfo['root_structure_id'] == $gStructure->mInfo['structure_id']) { $rootStructure =& $gStructure; } else { $rootStructure = new LibertyStructure($gStructure->mInfo['root_structure_id']); $rootStructure->load(); $rootStructure->loadNavigation(); $rootStructure->loadPath(); } if (empty($gContent)) { $gContent = LibertyContent::getLibertyObject($gStructure->getField('content_id')); $gContent->verifyUpdatePermission(); } $gBitSmarty->assign_by_ref('gStructure', $gStructure);
} $nodeHash['content_id'] = $nodePage->mContentId; $nodeHash['after_ref_id'] = $gStructure->storeNode($nodeHash); } } header("location: " . WIKI_PKG_URL . "edit_book.php?structure_id=" . $structure_id); } else { $gBitSmarty->assignByRef('errors', $gContent->mErrors); $gBitSmarty->assign('name', $_REQUEST['name']); $gBitSmarty->assign('chapters', $_REQUEST['chapters']); $mid = 'bitpackage:wiki/create_book.tpl'; } } elseif ($gContent->isValid()) { // Get all wiki pages for the select box $_REQUEST['content_type_guid'] = !isset($_REQUEST['content_type_guid']) ? 'bitpage' : $_REQUEST['content_type_guid']; // verify the book permission on structure load $verifyStructurePermission = 'p_wiki_admin_book'; // set the correct display template $mid = 'bitpackage:wiki/edit_book.tpl'; include_once LIBERTY_PKG_PATH . 'edit_structure_inc.php'; if ($gBitThemes->isAjaxRequest()) { $gBitSmarty->display('bitpackage:kernel/feedback_inc.tpl'); } } else { // user is just trying to create a new book - give them the form $gBitSystem->setBrowserTitle('Create Wiki Book'); $mid = 'bitpackage:wiki/create_book.tpl'; } $gBitSystem->setBrowserTitle(!empty($gStructure) && $gStructure->isValid() ? 'Edit Wiki Book:' . $gStructure->getField('title') : NULL); // Display the template $gBitSystem->display($mid, NULL, array('display_mode' => 'edit'));