$parentlist = $style['parentlist']; } // ############## templates $gettemplates = $db->query_read("\r\n\t\tSELECT title, templatetype, username, dateline, version, product,\r\n\t\t\tIF(templatetype = 'template', template_un, template) AS template\r\n\t\tFROM " . TABLE_PREFIX . "template\r\n\t\tWHERE product = '" . $db->escape_string($vbulletin->GPC['productid']) . "'\r\n\t\t\tAND {$sqlcondition}\r\n\t\tORDER BY title\r\n\t"); $xml->add_group('templates'); while ($template = $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']; } $xml->add_tag('template', $template['template'], array('name' => htmlspecialchars($template['title']), 'templatetype' => $template['templatetype'], 'date' => $template['dateline'], 'username' => $template['username'], 'version' => htmlspecialchars_uni($template['version'])), true); } $xml->close_group(); // ############## Stylevars $stylevarinfo = get_stylevars_for_export($vbulletin->GPC['productid'], $parentlist, true); $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($stylevar['stylevarid']), 'datatype' => $stylevar['datatype'], 'validation' => base64_encode($stylevar['validation']), 'failsafe' => base64_encode($stylevar['failsafe']))); } $xml->close_group(); } $xml->close_group(); unset($stylevar_dfn_cache); $xml->add_group('stylevars'); foreach ($stylevar_cache as $stylevarid => $stylevar) { $xml->add_tag('stylevar', '', array('name' => htmlspecialchars($stylevar['stylevarid']), 'value' => base64_encode($stylevar['value'])));
function get_style_export_xml ( $styleid, $product, $product_version, $title, $mode ) { //only is the (badly named) list of template groups global $vbulletin, $vbphrase, $only; if ($styleid == -1) { // set the style title as 'master style' $style = array('title' => $vbphrase['master_style']); $sqlcondition = "styleid = -1"; $parentlist = "-1"; $is_master = true; } else { // query everything from the specified style $style = $vbulletin->db->query_first(" SELECT * FROM " . TABLE_PREFIX . "style WHERE styleid = " . $styleid ); //export as master -- export a style with all changes as a new master style. if ($mode == 2) { //only allowed in debug mode. if (!$vbulletin->debug) { print_cp_no_permission(); } // get all items from this style and all parent styles $sqlcondition = "templateid IN(" . implode(',', unserialize($style['templatelist'])) . ")"; $sqlcondition .= " AND title NOT LIKE 'vbcms_grid_%'"; $parentlist = $style['parentlist']; $is_master = true; $title = $vbphrase['master_style']; } //export with parent styles else if ($mode == 1) { // get all items from this style and all parent styles (except master) $sqlcondition = "styleid <> -1 AND templateid IN(" . implode(',', unserialize($style['templatelist'])) . ")"; //remove the master style id off the end of the list $parentlist = substr(trim($style['parentlist']), 0, -3); $is_master = false; } //this style only else { // get only items customized in THIS style $sqlcondition = "styleid = " . $styleid; $parentlist = $styleid; $is_master = false; } } if ($product == 'vbulletin') { $sqlcondition .= " AND (product = '" . $vbulletin->db->escape_string($product) . "' OR product = '')"; } else { $sqlcondition .= " AND product = '" . $vbulletin->db->escape_string($product) . "'"; } // set a default title if ($title == '' OR $styleid == -1) { $title = $style['title']; } // -------------------------------------------- // query the templates and put them in an array $templates = array(); $gettemplates = $vbulletin->db->query_read(" SELECT title, templatetype, username, dateline, version, IF(templatetype = 'template', template_un, template) AS template FROM " . TABLE_PREFIX . "template WHERE $sqlcondition ORDER BY title "); while ($gettemplate = $vbulletin->db->fetch_array($gettemplates)) { switch($gettemplate['templatetype']) { case 'template': // regular template // if we have ad template, and we are exporting as master, make sure we do not export the add data if (substr($gettemplate['title'], 0, 3) == 'ad_' AND $mode == 2) { $gettemplate['template'] = ''; } $isgrouped = false; foreach(array_keys($only) AS $group) { if (strpos(strtolower(" $gettemplate[title]"), $group) == 1) { $templates["$group"][] = $gettemplate; $isgrouped = true; } } if (!$isgrouped) { $templates['zzz'][] = $gettemplate; } break; case 'stylevar': // stylevar $templates['StyleVar Special Templates'][] = $gettemplate; break; case 'css': // css $templates['CSS Special Templates'][] = $gettemplate; break; case 'replacement': // replacement $templates['Replacement Var Special Templates'][] = $gettemplate; break; } } unset($template); $vbulletin->db->free_result($gettemplates); if (!empty($templates)) { ksort($templates); $only['zzz'] = 'Ungrouped Templates'; } // -------------------------------------------- // fetch stylevar-dfns $stylevarinfo = get_stylevars_for_export($product, $parentlist, $is_master); $stylevar_cache = $stylevarinfo['stylevars']; $stylevar_dfn_cache = $stylevarinfo['stylevardfns']; if (empty($templates) AND empty($stylevar_cache) AND empty($stylevar_dfn_cache)) { print_stop_message('download_contains_no_customizations'); } // -------------------------------------------- // now output the XML require_once(DIR . '/includes/class_xml.php'); $xml = new vB_XML_Builder($vbulletin); $xml->add_group('style', array( 'name' => $title, 'vbversion' => $product_version, 'product' => $product, 'type' => $is_master ? 'master' : 'custom' ) ); foreach($templates AS $group => $grouptemplates) { $xml->add_group('templategroup', array('name' => iif(isset($only["$group"]), $only["$group"], $group))); foreach($grouptemplates AS $template) { $xml->add_tag('template', $template['template'], array( 'name' => htmlspecialchars($template['title']), 'templatetype' => $template['templatetype'], 'date' => $template['dateline'], 'username' => $template['username'], 'version' => htmlspecialchars_uni($template['version'])), true ); } $xml->close_group(); } $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($stylevar['stylevarid']), 'datatype' => $stylevar['datatype'], 'validation' => base64_encode($stylevar['validation']), 'failsafe' => base64_encode($stylevar['failsafe']) ) ); } $xml->close_group(); } $xml->close_group(); $xml->add_group('stylevars'); foreach ($stylevar_cache AS $stylevarid => $stylevar) { $xml->add_tag('stylevar', '', array( 'name' => htmlspecialchars($stylevar['stylevarid']), 'value' => base64_encode($stylevar['value']) ) ); } $xml->close_group(); $xml->close_group(); $doc = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\r\n\r\n"; $doc .= $xml->output(); $xml = null; return $doc; }
function get_product_export_xml($productid) { global $vbulletin; // Set up the parent tag $product_details = $vbulletin->db->query_first(" SELECT * FROM " . TABLE_PREFIX . "product WHERE productid = '" . $vbulletin->db->escape_string($productid) . "' "); if (!$product_details) { throw new vB_Exception_AdminStopMessage('invalid_product_specified'); } require_once(DIR . '/includes/class_xml.php'); $xml = new vB_XML_Builder($vbulletin); $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(" SELECT * FROM " . TABLE_PREFIX . "productdependency WHERE productid = '" . $vbulletin->db->escape_string($productid) . "' ORDER BY dependencytype, parentproductid, minversion "); $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(" SELECT * FROM " . TABLE_PREFIX . "productcode WHERE productid = '" . $vbulletin->db->escape_string($productid) . "' "); $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) { $sqlcondition = "styleid = -1"; $parentlist = "-1"; } else { // query everything from the specified style $style = $vbulletin->db->query_first(" SELECT * FROM " . TABLE_PREFIX . "style WHERE styleid = " . $export_styleid ); $sqlcondition = "templateid IN(" . implode(',', unserialize($style['templatelist'])) . ")"; $parentlist = $style['parentlist']; } // ############## templates $gettemplates = $vbulletin->db->query_read(" SELECT title, templatetype, username, dateline, version, product, IF(templatetype = 'template', template_un, template) AS template FROM " . TABLE_PREFIX . "template WHERE product = '" . $vbulletin->db->escape_string($productid) . "' AND $sqlcondition ORDER BY title "); $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']; } $xml->add_tag('template', $template['template'], array( 'name' => htmlspecialchars($template['title']), 'templatetype' => $template['templatetype'], 'date' => $template['dateline'], 'username' => $template['username'], 'version' => htmlspecialchars_uni($template['version']) ), true); } $xml->close_group(); // ############## Stylevars $stylevarinfo = get_stylevars_for_export($productid, $parentlist, true); $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($stylevar['stylevarid']), 'datatype' => $stylevar['datatype'], 'validation' => base64_encode($stylevar['validation']), 'failsafe' => base64_encode($stylevar['failsafe']) ) ); } $xml->close_group(); } $xml->close_group(); unset($stylevar_dfn_cache); $xml->add_group('stylevars'); foreach ($stylevar_cache AS $stylevarid => $stylevar) { $xml->add_tag('stylevar', '', array( 'name' => htmlspecialchars($stylevar['stylevarid']), 'value' => base64_encode($stylevar['value']) ) ); } $xml->close_group(); unset($stylevar_dfn_cache); // ############## plugins $xml->add_group('plugins'); $plugins = $vbulletin->db->query_read(" SELECT * FROM " . TABLE_PREFIX . "plugin WHERE product = '" . $vbulletin->db->escape_string($productid) . "' ORDER BY hookname "); 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(" SELECT * FROM " . TABLE_PREFIX . "phrase WHERE languageid IN (" . implode(',', $export_languageids) . ") AND product = '" . $vbulletin->db->escape_string($productid) . "' ORDER BY languageid, fieldname, varname "); 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(" SELECT * FROM " . TABLE_PREFIX . "settinggroup WHERE volatile = 1 ORDER BY displayorder, grouptitle "); while ($group = $vbulletin->db->fetch_array($groups)) { $settinggroup["$group[grouptitle]"] = $group; } ksort($settinggroup); $options = $vbulletin->db->query_read(" SELECT * FROM " . TABLE_PREFIX . "setting WHERE product = '" . $vbulletin->db->escape_string($productid) . "' AND volatile = 1 ORDER BY displayorder, varname "); 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($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(" SELECT * FROM " . TABLE_PREFIX . "adminhelp WHERE product = '" . $vbulletin->db->escape_string($productid) . "' AND volatile = 1 ORDER BY script, action, displayorder, optionname "); $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(" SELECT * FROM " . TABLE_PREFIX . "cron WHERE product = '" . $vbulletin->db->escape_string($productid) . "' AND volatile = 1 AND varname <> '' ORDER BY varname "); $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(" SELECT * FROM " . TABLE_PREFIX . "faq WHERE product = '" . $vbulletin->db->escape_string($productid) . "' AND volatile = 1 ORDER BY faqname "); $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); // ############## Finish up $xml->close_group(); $doc = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\r\n\r\n" . $xml->output(); unset($xml); return $doc; }
function get_product_export_xml($productid) { $assertor = vB::getDbAssertor(); // Set up the parent tag $product_details = $assertor->getRow('product', array('productid' => $productid)); if (!$product_details) { throw new vB_Exception_AdminStopMessage('invalid_product_specified'); } $xml = new vB_XML_Builder(); // ############## 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']); // ############## dependencies $product_dependencies = $assertor->assertQuery('productdependency', array('productid' => $productid), array('field' => array('dependencytype', 'parentproductid', 'minversion'), 'direction' => array(vB_dB_Query::SORT_ASC, vB_dB_Query::SORT_ASC, vB_dB_Query::SORT_ASC))); $xml->add_group('dependencies'); while ($product_dependencies and $product_dependencies->valid()) { $product_dependency = $product_dependencies->current(); $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); $product_dependencies->next(); } unset($product_dependency); $xml->close_group(); // ############## install / uninstall codes $productcodes = $assertor->getRows('productcode', array('productid' => $productid)); $xml->add_group('codes'); $productcodes_grouped = array(); $productcodes_versions = array(); foreach ($productcodes as $productcode) { // 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(); // ############## templates $gettemplates = $assertor->assertQuery('template', array('product' => $productid, 'styleid' => -1), 'title'); $xml->add_group('templates'); while ($gettemplates and $gettemplates->valid()) { $template = $gettemplates->current(); 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']; } $xml->add_tag('template', $template['templatetype'] == 'template' ? $template['template_un'] : $template['template'], array('name' => htmlspecialchars($template['title']), 'templatetype' => $template['templatetype'], 'date' => $template['dateline'], 'username' => $template['username'], 'version' => htmlspecialchars_uni($template['version'])), true); $gettemplates->next(); } $xml->close_group(); // ############## Stylevars $stylevarinfo = get_stylevars_for_export($productid, -1); $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($stylevar['stylevarid']), 'datatype' => $stylevar['datatype'], 'validation' => base64_encode($stylevar['validation']), 'failsafe' => base64_encode($stylevar['failsafe']))); } $xml->close_group(); } $xml->close_group(); $xml->add_group('stylevars'); foreach ($stylevar_cache as $stylevarid => $stylevar) { $xml->add_tag('stylevar', '', array('name' => htmlspecialchars($stylevar['stylevarid']), 'value' => base64_encode($stylevar['value']))); } $xml->close_group(); // ############## hooks $xml->add_group('hooks'); $hooks = vB_Api::instanceInternal("Hook")->getHookList(array('hookname'), array('product' => $productid)); foreach ($hooks as $hook) { $xml->add_group('hook'); $xml->add_tag('hookname', $hook['hookname']); $xml->add_tag('title', $hook['title']); $xml->add_tag('active', $hook['active']); $xml->add_tag('hookorder', $hook['hookorder']); $xml->add_tag('template', $hook['template']); $xml->add_tag('arguments', $hook['arguments']); $xml->close_group(); } $xml->close_group(); // ############## phrases $phrasetypes = vB_Api::instanceInternal('phrase')->fetch_phrasetypes(false); $phrases = array(); $getphrases = $assertor->getRows('vBForum:phrase', array('languageid' => array(-1, 0), 'product' => $productid), array('languageid', 'fieldname', 'varname')); foreach ($getphrases as $getphrase) { $phrases["{$getphrase['fieldname']}"]["{$getphrase['varname']}"] = $getphrase; } $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 = $assertor->getRows('settinggroup', array('volatile' => 1), array('displayorder', 'grouptitle')); foreach ($groups as $group) { $settinggroup["{$group['grouptitle']}"] = $group; } ksort($settinggroup); $options = $assertor->getRows('setting', array('product' => $productid, 'volatile' => 1), array('displayorder', 'varname')); foreach ($options as $row) { $setting["{$row['grouptitle']}"][] = $row; } $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 $newGroup = array('name' => htmlspecialchars($group['grouptitle']), 'displayorder' => $group['displayorder']); if (!empty($group['adminperm'])) { $newGroup['adminperm'] = $group['adminperm']; } $xml->add_group('settinggroup', $newGroup); 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); } if ($set['ispublic']) { $xml->add_tag('public', 1); } if ($set['adminperm']) { $xml->add_tag('adminperm', $set['adminperm']); } $xml->close_group(); } $xml->close_group(); } $xml->close_group(); // ############## admin help $help_topics_results = $assertor->getRows('vBForum:adminhelp', array('product' => $productid, 'volatile' => 1), array('script', 'action', 'displayorder', 'optionname')); $help_topics = array(); foreach ($help_topics_results as $help_topic) { $help_topics["{$help_topic['script']}"][] = $help_topic; } 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 = $assertor->getRows('cron', array(vB_dB_Query::CONDITIONS_KEY => array(array('field' => 'product', 'value' => $productid, vB_dB_Query::OPERATOR_KEY => vB_dB_Query::OPERATOR_EQ), array('field' => 'volatile', 'value' => 1, vB_dB_Query::OPERATOR_KEY => vB_dB_Query::OPERATOR_EQ), array('field' => 'varname', 'value' => '', vB_dB_Query::OPERATOR_KEY => vB_dB_Query::OPERATOR_NE)))); $xml->add_group('cronentries'); foreach ($cron_results as $cron) { $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(); $faq_results = $assertor->getRows('vBForum:faq', array('product' => $productid, 'volatile' => 1), 'faqname'); $xml->add_group('faqentries'); foreach ($faq_results as $faq) { $xml->add_tag('faq', '', array('faqname' => $faq['faqname'], 'faqparent' => $faq['faqparent'], 'displayorder' => $faq['displayorder'])); } $xml->close_group(); // ############## widgets $widgetExporter = new vB_Xml_Export_Widget($productid); $widgetExporter->getXml($xml); // ############## pagetemplates $pageTemplateExporter = new vB_Xml_Export_PageTemplate($productid); $pageTemplateExporter->getXml($xml); // ############## pages $pageExporter = new vB_Xml_Export_Page($productid); $pageExporter->getXml($xml); // ############## channels $channelExporter = new vB_Xml_Export_Channel($productid); $channelExporter->getXml($xml); // ############## routes $routeExporter = new vB_Xml_Export_Route($productid); $routeExporter->getXml($xml); // ############## Finish up $xml->close_group(); $doc = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\r\n\r\n" . $xml->output(); unset($xml); return $doc; }
function get_style_export_xml($styleid, $product, $product_version, $title, $mode) { // $only is the (badly named) list of template groups global $vbulletin, $vbphrase, $only; /* Load the master 'style' phrases for use in the export, and then rebuild the $only array */ load_phrases(array('style'), -1); build_template_groups($only); if ($styleid == -1 or $styleid == -2) { // set the style title as 'master style' $style = array('title' => $styleid == -1 ? $vbphrase['master_style'] : $vbphrase['mobile_master_style']); $sqlcondition = "styleid = {$styleid}"; $parentlist = $styleid; $styletype = $styleid == -1 ? 'master' : 'mobilemaster'; } 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 = " . $styleid); //export as master -- export a style with all changes as a new master style. if ($mode == 2) { //only allowed in debug mode. if (!$vbulletin->debug) { print_cp_no_permission(); } // get all items from this style and all parent styles $sqlcondition = "templateid IN(" . implode(',', unserialize($style['templatelist'])) . ")"; $sqlcondition .= " AND title NOT LIKE 'vbcms_grid_%'"; $parentlist = $style['parentlist']; $styletype = $style['type'] == 'standard' ? 'master' : 'mobilemaster'; $title = $vbphrase['master_style']; } else { if ($mode == 1) { // get all items from this style and all parent styles (except master) $sqlcondition = "styleid <> -1 AND styleid <> -2 AND templateid IN(" . implode(',', unserialize($style['templatelist'])) . ")"; //remove the master style id off the end of the list $parentlist = substr(trim($style['parentlist']), 0, -3); $styletype = 'custom'; } else { // get only items customized in THIS style $sqlcondition = "styleid = " . $styleid; $parentlist = $styleid; $styletype = 'custom'; } } } if ($product == 'vbulletin') { $sqlcondition .= " AND (product = '" . $vbulletin->db->escape_string($product) . "' OR product = '')"; } else { $sqlcondition .= " AND product = '" . $vbulletin->db->escape_string($product) . "'"; } // set a default title if ($title == '' or $styleid == -1 or $styleid == -2) { $title = $style['title']; } // -------------------------------------------- // query the templates and put them in an array $templates = array(); $gettemplates = $vbulletin->db->query_read("\n\t\tSELECT title, templatetype, username, dateline, version,\n\t\tIF(templatetype = 'template', template_un, template) AS template\n\t\tFROM " . TABLE_PREFIX . "template\n\t\tWHERE {$sqlcondition}\n\t\tORDER BY title\n\t"); $ugcount = $ugtemplates = 0; while ($gettemplate = $vbulletin->db->fetch_array($gettemplates)) { switch ($gettemplate['templatetype']) { case 'template': // regular template // if we have ad template, and we are exporting as master, make sure we do not export the add data if (substr($gettemplate['title'], 0, 3) == 'ad_' and $mode == 2) { $gettemplate['template'] = ''; } $isgrouped = false; foreach (array_keys($only) as $group) { if (strpos(strtolower(" {$gettemplate['title']}"), $group) == 1) { $templates["{$group}"][] = $gettemplate; $isgrouped = true; } } if (!$isgrouped) { if ($ugtemplates % 10 == 0) { $ugcount++; } $ugtemplates++; //sort ungrouped templates last. $ugcount_key = 'zzz' . str_pad($ugcount, 5, '0', STR_PAD_LEFT); $templates[$ugcount_key][] = $gettemplate; $only[$ugcount_key] = construct_phrase($vbphrase['ungrouped_templates_x'], $ugcount); } break; case 'stylevar': // stylevar $templates[$vbphrase['stylevar_special_templates']][] = $gettemplate; break; case 'css': // css $templates[$vbphrase['css_special_templates']][] = $gettemplate; break; case 'replacement': // replacement $templates[$vbphrase['replacement_var_special_templates']][] = $gettemplate; break; } } unset($template); $vbulletin->db->free_result($gettemplates); if (!empty($templates)) { ksort($templates); } // -------------------------------------------- // fetch stylevar-dfns $stylevarinfo = get_stylevars_for_export($product, $parentlist); $stylevar_cache = $stylevarinfo['stylevars']; $stylevar_dfn_cache = $stylevarinfo['stylevardfns']; if (empty($templates) and empty($stylevar_cache) and empty($stylevar_dfn_cache)) { throw new vB_Exception_AdminStopMessage('download_contains_no_customizations'); } // -------------------------------------------- // now output the XML require_once DIR . '/includes/class_xml.php'; $xml = new vB_XML_Builder($vbulletin); $xml->add_group('style', array('name' => $title, 'vbversion' => $product_version, 'product' => $product, 'type' => $styletype)); foreach ($templates as $group => $grouptemplates) { $xml->add_group('templategroup', array('name' => iif(isset($only["{$group}"]), $only["{$group}"], $group))); foreach ($grouptemplates 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(); } $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(); } $xml->close_group(); $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(); $xml->close_group(); $doc = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\r\n\r\n"; $doc .= $xml->output(); $xml = null; return $doc; }
break; case 'replacement': // replacement $templates['Replacement Var Special Templates'][] = $gettemplate; break; } } unset($template); $db->free_result($gettemplates); if (!empty($templates)) { ksort($templates); $only['zzz'] = 'Ungrouped Templates'; } // -------------------------------------------- // fetch stylevar-dfns $stylevarinfo = get_stylevars_for_export($vbulletin->GPC['product'], $parentlist, $is_master); $stylevar_cache = $stylevarinfo['stylevars']; $stylevar_dfn_cache = $stylevarinfo['stylevardfns']; if (empty($templates) and empty($stylevar_cache) and empty($stylevar_dfn_cache)) { print_stop_message('download_contains_no_customizations'); } // -------------------------------------------- // now output the XML require_once DIR . '/includes/class_xml.php'; $xml = new vB_XML_Builder($vbulletin); $xml->add_group('style', array('name' => $vbulletin->GPC['title'], 'vbversion' => $full_product_info[$vbulletin->GPC['product']]['version'], 'product' => $vbulletin->GPC['product'], 'type' => $is_master ? 'master' : 'custom')); foreach ($templates as $group => $grouptemplates) { $xml->add_group('templategroup', array('name' => iif(isset($only["{$group}"]), $only["{$group}"], $group))); foreach ($grouptemplates as $template) { $xml->add_tag('template', $template['template'], array('name' => htmlspecialchars($template['title']), 'templatetype' => $template['templatetype'], 'date' => $template['dateline'], 'username' => $template['username'], 'version' => htmlspecialchars_uni($template['version'])), true); }