function build_navigation_array($bypass = false, $forced = false) { global $db, $vbphrase, $vbulletin; static $result = array(); if ($result and !$forced) { return $result; } $list = array(); $navdata = array(); $tablist = array(); if (is_array($vbulletin->navdata)) { $data = $vbulletin->navdata; } else { $data = build_navigation_datastore(); } foreach ($data as $row) { $count = 10; if ($row['parent']) { do { $count++; if ($count > 99) { /* Something is very wrong */ print_stop_message('internal_error', '10'); } /* Try and prevent key clashes. */ $subkey = $row['displayorder'] . $count; } while (isset($list[$row['parent']][$subkey])); $list[$row['parent']][$subkey] = $row['name']; } else { // Dummy element, to create and order the tabs. $list[$row['name']][$row['displayorder'] . $count] = '#'; } expand_navigation_state($row); $phrasename = 'vb_navigation_' . $row['navtype'] . '_' . $row['name'] . '_text'; $row['text'] = $vbphrase[$phrasename] ? $vbphrase[$phrasename] : '#' . $row['name'] . '#'; unset($row['username'], $row['version'], $row['dateline']); // Not needed. $navdata[$row['name']] = $row; } ($hook = vBulletinHook::fetch_hook('build_navigation_data')) ? eval($hook) : false; foreach ($list as $tabname => $tab) { ksort($tab); foreach ($tab as $key => $element) { if (!is_array($element)) { unset($tab[$key]); if ($list[$element]) { $tab[$element] = $navdata[$element]; foreach ($list[$element] as $subkey => $subelement) { unset($list[$element][$subkey]); $list[$element][$subelement] = $navdata[$subelement]; } $tab[$element]['links'] = $list[$element]; unset($list[$element]); } else { if ($element != '#') { $tab[$element] = $navdata[$element]; } } } $list[$tabname] = $tab; } $tablist[$tabname] = $navdata[$tabname]; $tablist[$tabname]['links'] = $list[$tabname]; } $result = $tablist; ($hook = vBulletinHook::fetch_hook('build_navigation_array')) ? eval($hook) : false; unset($navdata, $tablist, $list); return $result; }
if ($proposed['navid'] != $vbulletin->GPC['newid']) { print_stop_message('invalid_new_default'); } $sqlset1 = $sqlset2 = ''; $current['edited'] = 1; $proposed['edited'] = 1; $current['default'] = 0; $proposed['default'] = 1; ($hook = vBulletinHook::fetch_hook('navigation_admin_dodefault')) ? eval($hook) : false; collapse_navigation_state($current); collapse_navigation_state($proposed); if ($current['navid']) { $sql = "\n\t\t\t\tUPDATE " . TABLE_PREFIX . "navigation\n\t\t\t\tSET state = " . $current['state'] . "\n\t\t\t\t{$sqlset1}\n\t\t\t\tWHERE navid = " . $current['navid'] . "\n\t\t\t"; $db->query_write($sql); } $sql = "\n\t\t\tUPDATE " . TABLE_PREFIX . "navigation\n\t\t\tSET state = " . $proposed['state'] . "\n\t\t\t{$sqlset2}\n\t\t\tWHERE navid = " . $proposed['navid'] . "\n\t\t"; $db->query_write($sql); } $parent = $roots[$proposed['name']]; build_navigation_datastore(); $taburl = $parent ? '&tabid=' . $parent : ''; define('CP_REDIRECT', 'navigation.php?do=list' . $taburl); print_stop_message('saved_settings_successfully'); } print_cp_footer(); /*======================================================================*\ || #################################################################### || # Downloaded: 03:13, Sat Sep 7th 2013 || # CVS: $RCSfile$ - $Revision: 58699 $ || #################################################################### \*======================================================================*/
function import_navigation($arr, $info) { global $db, $vbulletin; $default = ''; $data = array(); $result = array(); $master = array(); $edited = array(); $zaplist = array(); $product =& $info['productid']; $navarray =& $arr['navigation']; $protected = substr($product, 0, 2) == 'vb' ? 1 : 0; $install = $info['process'] == 'Install' ? true : false; if (empty($navarray) or !is_array($navarray)) { /* Nothing to add, just delete anything that exists. This probably needs changing at some point in the future to use a volatile type flag and only delete items where volatile is set */ if ($product != 'vbulletin') { $db->query_write("\n\t\t\t\tDELETE FROM " . TABLE_PREFIX . "navigation\n\t\t\t\tWHERE productid = '" . $db->escape_string($product) . "'\n\t\t\t"); } return; } /* The XML class doesnt create an array if there is only one entry, so we have to */ foreach ($navarray as $type => $data) { if (!isset($data[0])) { $navarray[$type] = array($navarray[$type]); } } $common = array('install' => $install, 'dateline' => TIMENOW, 'productid' => $product, 'version' => $info['version'], 'username' => $info['username']); // Get current elements $edit = $db->query_read_slave("\n\t\tSELECT name, state\n\t\tFROM " . TABLE_PREFIX . "navigation\n\t\tWHERE productid = '" . $db->escape_string($product) . "'\n\t"); while ($data = $db->fetch_array($edit)) { $edited[$data['name']] = $data['state'] & $vbulletin->bf_misc_navstate['edited'] ? true : false; } // ### Import Tabs ### if (is_array($navarray['tab'])) { foreach ($navarray['tab'] as $tab) { $name = $tab['name']; if ($install or !$edited[$name]) { $data[$name]['type'] = 'tab'; $data[$name]['url'] = $tab['url']; $data[$name]['showperm'] = $tab['show']; $data[$name]['displayorder'] = $tab['displayorder']; $data[$name]['parent'] = ''; // Tabs have no parent $data[$name]['productid'] = $product; $data[$name]['scripts'] = $tab['scripts']; $data[$name]['active'] = $tab['active']; $data[$name]['protected'] = $protected; $data[$name]['menuid'] = $tab['menuid']; $data[$name]['newpage'] = $tab['newpage']; if ($tab['default'] and !$default) { $default = $name; } $zaplist[] = "'" . $db->escape_string($name) . "'"; } $master[] = "'" . $db->escape_string($name) . "'"; } } // ### Import Menus ### if (is_array($navarray['menu'])) { foreach ($navarray['menu'] as $menu) { $name = $menu['name']; if ($install or !$edited[$name]) { $data[$name]['type'] = 'menu'; $data[$name]['url'] = ''; // Menus have no url $data[$name]['showperm'] = $menu['show']; $data[$name]['displayorder'] = $menu['displayorder']; $data[$name]['parent'] = $menu['parent']; $data[$name]['productid'] = $product; $data[$name]['scripts'] = ''; // Only tabs have this $data[$name]['active'] = $menu['active']; $data[$name]['protected'] = $protected; if ($menu['default'] and !$default) { $default = $name; } $zaplist[] = "'" . $db->escape_string($name) . "'"; } $master[] = "'" . $db->escape_string($name) . "'"; } } // ### Import Links ### if (is_array($navarray['link'])) { foreach ($navarray['link'] as $link) { $name = $link['name']; if ($install or !$edited[$name]) { $data[$name]['type'] = 'link'; $data[$name]['url'] = $link['url']; $data[$name]['showperm'] = $link['show']; $data[$name]['displayorder'] = $link['displayorder']; $data[$name]['parent'] = $link['parent']; $data[$name]['productid'] = $product; $data[$name]['scripts'] = ''; // Only tabs have this $data[$name]['active'] = $link['active']; $data[$name]['protected'] = $protected; $data[$name]['newpage'] = $tab['newpage']; if ($link['default'] and !$default) { $default = $name; } $zaplist[] = "'" . $db->escape_string($name) . "'"; } $master[] = "'" . $db->escape_string($name) . "'"; } } /* Delete anything assigned to the product if it hasnt just been imported above. Exclude 'vbulletin' from this as it will have the normal custom elements. */ $condition = $master ? 'AND name NOT IN (' . implode(',', $master) . ')' : ''; if ($product != 'vbulletin') { $db->query_write("\n\t\t\tDELETE FROM " . TABLE_PREFIX . "navigation\n\t\t\tWHERE productid = '" . $db->escape_string($product) . "'\n\t\t\t{$condition}\n\t\t"); } /* Delete any unprotected elements that already exist, whatever product they are currently assigned to */ if ($zaplist) { $db->query_write("\n\t\t\tDELETE FROM " . TABLE_PREFIX . "navigation\n\t\t\tWHERE name IN (" . implode(',', $zaplist) . ")\n\t\t\tAND ((state & " . $vbulletin->bf_misc_navstate['protected'] . ") = 0 OR {$protected} = 1);\n\t\t"); } if ($install and $default) { $data[$default]['default'] = 1; } else { if ($protected) { set_navigation_default($data, $default); } } if ($insert = get_navigation_sql($common, $data)) { $db->query_write($insert); } build_navigation_datastore(); }