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; }
} else { construct_hidden_code('newid', $navelement['navid']); print_label_row($vbphrase['nav_default_new'], $navelement['text'], '', 'top', null, 40); } print_yes_no_row($vbphrase['nav_default_set'], 'confirm', 1); ($hook = vBulletinHook::fetch_hook('navigation_admin_default')) ? eval($hook) : false; print_submit_row($vbphrase['save']); } if ($_REQUEST['do'] == 'dodefault') { $roots = get_navigation_roots($navlist); $vbulletin->input->clean_array_gpc('r', array('oldid' => TYPE_INT, 'newid' => TYPE_INT, 'confirm' => TYPE_INT)); $existing = get_navigation_default($navlist, false); $current = $navlist[$vbulletin->GPC['oldid']]; $proposed = $navlist[$vbulletin->GPC['newid']]; expand_navigation_state($current); expand_navigation_state($proposed); if ($vbulletin->GPC['confirm']) { if ($current['navid'] != $existing) { print_stop_message('invalid_current_default'); } if ($current['navid'] != $vbulletin->GPC['oldid']) { print_stop_message('invalid_current_default'); } 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;
function get_product_export_xml($productid) { global $vbulletin; // Set up the parent tag $product_details = $vbulletin->db->query_first("\n\t\tSELECT *\n\t\tFROM " . TABLE_PREFIX . "product\n\t\tWHERE productid = '" . $vbulletin->db->escape_string($productid) . "'\n\t"); if (!$product_details) { throw new vB_Exception_AdminStopMessage('invalid_product_specified'); } require_once DIR . '/includes/class_xml.php'; $xml = new vB_XML_Builder($vbulletin); // -1 means also export -2 $export_styleid = -1; $export_languageids = array(-1, 0); // ############## main product info $xml->add_group('product', array('productid' => strtolower($product_details['productid']), 'active' => $product_details['active'])); // Parent for product $xml->add_tag('title', $product_details['title']); $xml->add_tag('description', $product_details['description']); $xml->add_tag('version', $product_details['version']); $xml->add_tag('url', $product_details['url']); $xml->add_tag('versioncheckurl', $product_details['versioncheckurl']); ($hook = vBulletinHook::fetch_hook('admin_product_export')) ? eval($hook) : false; // ############## dependencies $product_dependencies = $vbulletin->db->query_read("\n\t\tSELECT *\n\t\tFROM " . TABLE_PREFIX . "productdependency\n\t\tWHERE productid = '" . $vbulletin->db->escape_string($productid) . "'\n\t\tORDER BY dependencytype, parentproductid, minversion\n\t"); $xml->add_group('dependencies'); while ($product_dependency = $vbulletin->db->fetch_array($product_dependencies)) { $deps = array('dependencytype' => $product_dependency['dependencytype']); if ($product_dependency['dependencytype'] == 'product') { $deps['parentproductid'] = $product_dependency['parentproductid']; } $deps['minversion'] = $product_dependency['minversion']; $deps['maxversion'] = $product_dependency['maxversion']; $xml->add_tag('dependency', '', $deps); } $xml->close_group(); // ############## install / uninstall codes $productcodes = $vbulletin->db->query_read("\n\t\tSELECT *\n\t\tFROM " . TABLE_PREFIX . "productcode\n\t\tWHERE productid = '" . $vbulletin->db->escape_string($productid) . "'\n\t"); $xml->add_group('codes'); $productcodes_grouped = array(); $productcodes_versions = array(); while ($productcode = $vbulletin->db->fetch_array($productcodes)) { // have to be careful here, as version numbers are not necessarily unique $productcodes_versions["{$productcode['version']}"] = 1; $productcodes_grouped["{$productcode['version']}"][] = $productcode; } $productcodes_versions = array_keys($productcodes_versions); usort($productcodes_versions, 'version_sort'); foreach ($productcodes_versions as $version) { foreach ($productcodes_grouped["{$version}"] as $productcode) { $xml->add_group('code', array('version' => $productcode['version'])); $xml->add_tag('installcode', $productcode['installcode']); $xml->add_tag('uninstallcode', $productcode['uninstallcode']); $xml->close_group(); } } $xml->close_group(); //hack in the ability to handle styles other than the master in a sane fashion. //We can set it via a hook for the moment, it should be a fairly temporary need. //There was some logic that look like you might be able to export more than one //style, but it didn't make much sense -- if you selected multiple styles then //you'd end up with templates from multiple styles with no attempt to handle duplicates //and no requirement that the styles in question were parents/children of each other. if ($export_styleid == -1) { // -1 means also export -2 $sqlcondition = "styleid IN (-1, -2)"; $parentlist = "-1,-2"; } else { // query everything from the specified style $style = $vbulletin->db->query_first("\n\t\t\tSELECT *\n\t\t\tFROM " . TABLE_PREFIX . "style\n\t\t\tWHERE styleid = " . $export_styleid); $sqlcondition = "templateid IN(" . implode(',', unserialize($style['templatelist'])) . ")"; $parentlist = $style['parentlist']; } // ############## templates $gettemplates = $vbulletin->db->query_read("\n\t\tSELECT\n\t\t\ttitle, templatetype, username, dateline, version, product, styleid,\n\t\t\tIF(templatetype = 'template', template_un, template) AS template\n\t\tFROM " . TABLE_PREFIX . "template\n\t\tWHERE\n\t\t\tproduct = '" . $vbulletin->db->escape_string($productid) . "'\n\t\t\t\tAND\n\t\t\t{$sqlcondition}\n\t\tORDER BY\n\t\t\ttitle\n\t"); $mobile_templates = array(); $xml->add_group('templates'); while ($template = $vbulletin->db->fetch_array($gettemplates)) { if (is_newer_version($template['version'], $product_details['version'])) { // version in the template is newer than the version of the product, // which probably means it's using the vB version $template['version'] = $product_details['version']; } if ($template['styleid'] == -2) { $mobile_templates[] = $template; continue; } $xml->add_tag('template', $template['template'], array('name' => htmlspecialchars_uni($template['title']), 'templatetype' => $template['templatetype'], 'date' => $template['dateline'], 'username' => $template['username'], 'version' => htmlspecialchars_uni($template['version'])), true); } $xml->close_group('templates'); if ($mobile_templates) { $xml->add_group('templates_mobile'); foreach ($mobile_templates as $template) { $xml->add_tag('template', $template['template'], array('name' => htmlspecialchars_uni($template['title']), 'templatetype' => $template['templatetype'], 'date' => $template['dateline'], 'username' => $template['username'], 'version' => htmlspecialchars_uni($template['version'])), true); } $xml->close_group('templates_mobile'); unset($mobile_templates); } // ############## Stylevars require_once DIR . '/includes/adminfunctions_template.php'; if ($export_styleid == -1) { $stylevarinfo = get_stylevars_for_export($productid, -1); $stylevarinfo_mobile = get_stylevars_for_export($productid, -2); $stylevar_cache_mobile = $stylevarinfo_mobile['stylevars']; $stylevar_dfn_cache_mobile = $stylevarinfo_mobile['stylevardfns']; } else { $stylevarinfo = get_stylevars_for_export($productid, $parentlist); } $stylevar_cache = $stylevarinfo['stylevars']; $stylevar_dfn_cache = $stylevarinfo['stylevardfns']; $xml->add_group('stylevardfns'); foreach ($stylevar_dfn_cache as $stylevargroupname => $stylevargroup) { $xml->add_group('stylevargroup', array('name' => $stylevargroupname)); foreach ($stylevargroup as $stylevar) { $xml->add_tag('stylevar', '', array('name' => htmlspecialchars_uni($stylevar['stylevarid']), 'datatype' => $stylevar['datatype'], 'validation' => vb_base64_encode($stylevar['validation']), 'failsafe' => vb_base64_encode($stylevar['failsafe']))); } $xml->close_group('stylevargroup'); } $xml->close_group('stylevardfns'); unset($stylevar_dfn_cache); $xml->add_group('stylevars'); foreach ($stylevar_cache as $stylevarid => $stylevar) { $xml->add_tag('stylevar', '', array('name' => htmlspecialchars_uni($stylevar['stylevarid']), 'value' => vb_base64_encode($stylevar['value']))); } $xml->close_group('stylevars'); unset($stylevar_cache); if ($stylevar_dfn_cache_mobile) { $xml->add_group('stylevardfns_mobile'); foreach ($stylevar_dfn_cache_mobile as $stylevargroupname => $stylevargroup) { $xml->add_group('stylevargroup', array('name' => $stylevargroupname)); foreach ($stylevargroup as $stylevar) { $xml->add_tag('stylevar', '', array('name' => htmlspecialchars_uni($stylevar['stylevarid']), 'datatype' => $stylevar['datatype'], 'validation' => vb_base64_encode($stylevar['validation']), 'failsafe' => vb_base64_encode($stylevar['failsafe']))); } $xml->close_group('stylegroup'); } $xml->close_group('stylevardfns_mobile'); unset($stylevar_dfn_cache_mobile); $xml->add_group('stylevars_mobile'); foreach ($stylevar_cache_mobile as $stylevarid => $stylevar) { $xml->add_tag('stylevar', '', array('name' => htmlspecialchars_uni($stylevar['stylevarid']), 'value' => vb_base64_encode($stylevar['value']))); } $xml->close_group('stylevars_mobile'); unset($stylevar_cache_mobile); } // ############## plugins $xml->add_group('plugins'); $plugins = $vbulletin->db->query_read("\n\t\tSELECT *\n\t\tFROM " . TABLE_PREFIX . "plugin\n\t\tWHERE product = '" . $vbulletin->db->escape_string($productid) . "'\n\t\tORDER BY hookname\n\t"); while ($plugin = $vbulletin->db->fetch_array($plugins)) { $params = array('active' => $plugin['active'], 'executionorder' => $plugin['executionorder']); $xml->add_group('plugin', $params); $xml->add_tag('title', $plugin['title']); $xml->add_tag('hookname', $plugin['hookname']); $xml->add_tag('phpcode', $plugin['phpcode']); $xml->close_group(); } unset($plugin); $vbulletin->db->free_result($plugins); $xml->close_group(); // ############## phrases require_once DIR . '/includes/adminfunctions_language.php'; $phrasetypes = fetch_phrasetypes_array(false); $phrases = array(); $getphrases = $vbulletin->db->query_read("\n\t\tSELECT *\n\t\tFROM " . TABLE_PREFIX . "phrase\n\t\tWHERE languageid IN (" . implode(',', $export_languageids) . ")\n\t\t\tAND product = '" . $vbulletin->db->escape_string($productid) . "'\n\t\tORDER BY languageid, fieldname, varname\n\t"); while ($getphrase = $vbulletin->db->fetch_array($getphrases)) { $phrases["{$getphrase['fieldname']}"]["{$getphrase['varname']}"] = $getphrase; } unset($getphrase); $vbulletin->db->free_result($getphrases); $xml->add_group('phrases'); // make sure the phrasegroups are in a reliable order ksort($phrases); foreach ($phrases as $_fieldname => $typephrases) { // create a group for each phrase type that we have phrases for // then insert the phrases $xml->add_group('phrasetype', array('name' => $phrasetypes["{$_fieldname}"]['title'], 'fieldname' => $_fieldname)); // make sure the phrases are in a reliable order ksort($typephrases); foreach ($typephrases as $phrase) { $xml->add_tag('phrase', $phrase['text'], array('name' => $phrase['varname'], 'date' => $phrase['dateline'], 'username' => $phrase['username'], 'version' => htmlspecialchars_uni($phrase['version'])), true); } $xml->close_group(); } $xml->close_group(); // ############## options $setting = array(); $settinggroup = array(); $groups = $vbulletin->db->query_read("\n\t\tSELECT *\n\t\tFROM " . TABLE_PREFIX . "settinggroup\n\t\tWHERE volatile = 1\n\t\tORDER BY displayorder, grouptitle\n\t"); while ($group = $vbulletin->db->fetch_array($groups)) { $settinggroup["{$group['grouptitle']}"] = $group; } ksort($settinggroup); $options = $vbulletin->db->query_read("\n\t\tSELECT *\n\t\tFROM " . TABLE_PREFIX . "setting\n\t\tWHERE product = '" . $vbulletin->db->escape_string($productid) . "'\n\t\t\tAND volatile = 1\n\t\tORDER BY displayorder, varname\n\t"); while ($row = $vbulletin->db->fetch_array($options)) { $setting["{$row['grouptitle']}"][] = $row; } unset($row); $vbulletin->db->free_result($options); $xml->add_group('options'); foreach ($settinggroup as $grouptitle => $group) { if (empty($setting["{$grouptitle}"])) { continue; } // add a group for each setting group we have settings for $xml->add_group('settinggroup', array('name' => htmlspecialchars_uni($group['grouptitle']), 'displayorder' => $group['displayorder'])); ksort($setting["{$grouptitle}"]); foreach ($setting["{$grouptitle}"] as $set) { $arr = array('varname' => $set['varname'], 'displayorder' => $set['displayorder']); if ($set['advanced']) { $arr['advanced'] = 1; } $xml->add_group('setting', $arr); if ($set['datatype']) { $xml->add_tag('datatype', $set['datatype']); } if ($set['optioncode'] != '') { $xml->add_tag('optioncode', $set['optioncode']); } if ($set['validationcode']) { $xml->add_tag('validationcode', $set['validationcode']); } if ($set['defaultvalue'] !== '') { $xml->add_tag('defaultvalue', $set['defaultvalue']); } if ($set['blacklist']) { $xml->add_tag('blacklist', 1); } $xml->close_group(); } $xml->close_group(); } $xml->close_group(); // ############## admin help $help_topics_results = $vbulletin->db->query_read("\n\t\tSELECT *\n\t\tFROM " . TABLE_PREFIX . "adminhelp\n\t\tWHERE product = '" . $vbulletin->db->escape_string($productid) . "'\n\t\t\tAND volatile = 1\n\t\tORDER BY script, action, displayorder, optionname\n\t"); $help_topics = array(); while ($help_topic = $vbulletin->db->fetch_array($help_topics_results)) { $help_topics["{$help_topic['script']}"][] = $help_topic; } $vbulletin->db->free_result($help_topics_results); ksort($help_topics); $xml->add_group('helptopics'); foreach ($help_topics as $script => $script_topics) { $xml->add_group('helpscript', array('name' => $script)); foreach ($script_topics as $topic) { $attr = array('disp' => $topic['displayorder']); if ($topic['action']) { $attr['act'] = $topic['action']; } if ($topic['optionname']) { $attr['opt'] = $topic['optionname']; } $xml->add_tag('helptopic', '', $attr); } $xml->close_group(); } $xml->close_group(); // ############## Cron entries $cron_results = $vbulletin->db->query_read("\n\t\tSELECT *\n\t\tFROM " . TABLE_PREFIX . "cron\n\t\tWHERE product = '" . $vbulletin->db->escape_string($productid) . "'\n\t\t\tAND volatile = 1\n\t\t\tAND varname <> ''\n\t\tORDER BY varname\n\t"); $xml->add_group('cronentries'); while ($cron = $vbulletin->db->fetch_array($cron_results)) { $minutes = unserialize($cron['minute']); if (!is_array($minutes)) { $minutes = array(); } $xml->add_group('cron', array('varname' => $cron['varname'], 'active' => $cron['active'], 'loglevel' => $cron['loglevel'])); $xml->add_tag('filename', $cron['filename']); $xml->add_tag('scheduling', '', array('weekday' => $cron['weekday'], 'day' => $cron['day'], 'hour' => $cron['hour'], 'minute' => implode(',', $minutes))); $xml->close_group(); } $xml->close_group(); $vbulletin->db->free_result($cron_results); // ############## FAQ entries $faq_results = $vbulletin->db->query_read("\n\t\tSELECT *\n\t\tFROM " . TABLE_PREFIX . "faq\n\t\tWHERE product = '" . $vbulletin->db->escape_string($productid) . "'\n\t\t\tAND volatile = 1\n\t\tORDER BY faqname\n\t"); $xml->add_group('faqentries'); while ($faq = $vbulletin->db->fetch_array($faq_results)) { $xml->add_tag('faq', '', array('faqname' => $faq['faqname'], 'faqparent' => $faq['faqparent'], 'displayorder' => $faq['displayorder'])); } $xml->close_group(); $vbulletin->db->free_result($faq_results); // Navigation Data // $xml->add_group('navigation'); $navdata = $vbulletin->db->query_read_slave("\n\t\tSELECT *\n\t\tFROM " . TABLE_PREFIX . "navigation\n\t\tWHERE\n\t\t\tproductid = '" . $vbulletin->db->escape_string($productid) . "'\n\t\t\t\tAND\n\t\t\tstate & " . $vbulletin->bf_misc_navstate['deleted'] . " = 0\n\t\tORDER BY\n\t\t\tnavtype, parent, displayorder\n\t"); while ($nav = $vbulletin->db->fetch_array($navdata)) { $row = array('name' => $nav['name'], 'date' => $nav['dateline'], 'username' => $nav['username'], 'version' => $nav['version']); $taglist = array(); expand_navigation_state($nav); switch ($nav['navtype']) { case 'tab': $taglist = array('active' => $nav['active'], 'show' => $nav['showperm'], 'scripts' => $nav['scripts'], 'displayorder' => $nav['displayorder'], 'url' => $nav['url'], 'menuid' => $nav['menuid'], 'newpage' => $nav['newpage']); break; case 'menu': $taglist = array('active' => $nav['active'], 'show' => $nav['showperm'], 'parent' => $nav['parent'], 'displayorder' => $nav['displayorder']); break; case 'link': $taglist = array('active' => $nav['active'], 'show' => $nav['showperm'], 'parent' => $nav['parent'], 'displayorder' => $nav['displayorder'], 'url' => $nav['url'], 'newpage' => $nav['newpage']); break; } if ($nav['protected']) { if ($nav['default']) { $taglist['default'] = 1; } } else { if (substr($nav['product'], 0, 2) == 'vb') { continue; } } $xml->add_group($nav['navtype'], $row); foreach ($taglist as $key => $value) { $xml->add_tag($key, $value); } $xml->close_group($nav['navtype']); } $xml->close_group('navigation'); // ############## Finish up $xml->close_group(); $doc = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\r\n\r\n" . $xml->output(); unset($xml); return $doc; }