unset($pm['folder']); ($hook = vBulletinHook::fetch_hook('private_downloadpm_bit')) ? eval($hook) : false; $xml->add_group('privatemessage'); foreach ($pm as $key => $val) { $xml->add_tag($key, $val); } $xml->close_group(); } $xml->close_group(); } $xml->close_group(); $doc = "<?xml version=\"1.0\" encoding=\"{$stylevar['charset']}\"?>\r\n\r\n"; $doc .= "<!-- " . $vbulletin->options['bbtitle'] . ';' . $vbulletin->options['bburl'] . " -->\r\n"; // replace --/---/... with underscores for valid XML comments $doc .= '<!-- ' . construct_phrase($vbphrase['private_message_dump_for_user_x_y'], preg_replace('#(-(?=-)|(?<=-)-)#', '_', $vbulletin->userinfo['username']), vbdate($vbulletin->options['dateformat'] . ' ' . $vbulletin->options['timeformat'], TIMENOW)) . " -->\r\n\r\n"; $doc .= $xml->output(); $xml = null; // download the file file_download($doc, str_replace(array('\\', '/'), '-', "{$vbphrase['dump_privatemessages']}-" . $vbulletin->userinfo['username'] . "-" . vbdate($vbulletin->options['dateformat'], TIMENOW) . '.xml'), 'text/xml'); break; // ***************************** // download as CSV // ***************************** // download as CSV case 'csv': // column headers $csv = "{$vbphrase['date']},{$vbphrase['folder']},{$vbphrase['title']},{$vbphrase['dump_from']},{$vbphrase['dump_to']},{$vbphrase['message']}\r\n"; while ($pm = $db->fetch_array($pms)) { $csvpm = array(); $csvpm['datestamp'] = vbdate('Y-m-d H:i', $pm['datestamp'], false, false); $csvpm['folder'] = $foldernames["{$pm['folder']}"];
function get_help_export_xml($product) { global $vbulletin; if ($product == 'vbulletin') { $product_sql = "product IN ('vbulletin', '')"; } else { $product_sql = "product = '" . $vbulletin->db->escape_string($product) . "'"; } // query topics $helptopics = array(); $phrase_names = array(); $topics = $vbulletin->db->query_read("\n\t\tSELECT adminhelp.*\n\t\tFROM " . TABLE_PREFIX . "adminhelp AS adminhelp\n\t\tWHERE adminhelp.volatile = 1\n\t\t\tAND adminhelp.{$product_sql}\n\t\tORDER BY adminhelp.script, adminhelp.action, adminhelp.displayorder, adminhelp.optionname\n\t"); while ($topic = $vbulletin->db->fetch_array($topics)) { $topic['phrase_name'] = fetch_help_phrase_short_name($topic); $phrase_names[] = $vbulletin->db->escape_string($topic['phrase_name'] . '_title'); $phrase_names[] = $vbulletin->db->escape_string($topic['phrase_name'] . '_text'); $helptopics["{$topic['script']}"][] = $topic; } unset($topic); $vbulletin->db->free_result($topics); $phrases = array(); $phrase_results = $vbulletin->db->query_read("\n\t\tSELECT *\n\t\tFROM " . TABLE_PREFIX . "phrase\n\t\tWHERE languageid = -1\n\t\t\tAND varname IN ('" . implode("', '", $phrase_names) . "')\n\t"); while ($phrase = $vbulletin->db->fetch_array($phrase_results)) { $phrases["{$phrase['varname']}"] = $phrase; } require_once DIR . '/includes/class_xml.php'; $xml = new vB_XML_Builder($vbulletin); $version = str_replace('"', '\\"', $vbulletin->options['templateversion']); $xml->add_group('helptopics', array('vbversion' => $version, 'product' => $product, 'hasphrases' => 1)); ksort($helptopics); foreach ($helptopics as $script => $scripttopics) { $xml->add_group('helpscript', array('name' => $script)); foreach ($scripttopics as $topic) { $attr = array('disp' => $topic['displayorder']); if ($topic['action']) { $attr['act'] = $topic['action']; } if ($topic['optionname']) { $attr['opt'] = $topic['optionname']; } $title =& $phrases[$topic['phrase_name'] . '_title']; $text =& $phrases[$topic['phrase_name'] . '_text']; if (!empty($title) or !empty($text)) { $xml->add_group('helptopic', $attr); $title_attributes = array('date' => $title['dateline'], 'username' => $title['username'], 'version' => htmlspecialchars_uni($title['version'])); $xml->add_tag('title', $title['text'], $title_attributes); $text_attributes = array('date' => $text['dateline'], 'username' => $text['username'], 'version' => htmlspecialchars_uni($text['version'])); $xml->add_tag('text', $text['text'], $text_attributes); $xml->close_group(); } else { $xml->add_tag('helptopic', '', $attr); } } $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_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; }
$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(); $db->free_result($cron_results); // ############## FAQ entries $faq_results = $db->query_read("\r\n\t\tSELECT *\r\n\t\tFROM " . TABLE_PREFIX . "faq\r\n\t\tWHERE product = '" . $db->escape_string($vbulletin->GPC['productid']) . "'\r\n\t\t\tAND volatile = 1\r\n\t\tORDER BY faqname\r\n\t"); $xml->add_group('faqentries'); while ($faq = $db->fetch_array($faq_results)) { $xml->add_tag('faq', '', array('faqname' => $faq['faqname'], 'faqparent' => $faq['faqparent'], 'displayorder' => $faq['displayorder'])); } $xml->close_group(); $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); require_once DIR . '/includes/functions_file.php'; file_download($doc, "product-" . $vbulletin->GPC['productid'] . '.xml', 'text/xml'); } print_cp_footer(); /*======================================================================*\ || #################################################################### || # Downloaded: 23:48, Wed Mar 24th 2010 || # CVS: $RCSfile$ - $Revision: 34205 $ || #################################################################### \*======================================================================*/
$xml->close_group(); // close #bd if ($vbulletin->GPC['auxfooter']) { $xml->add_group('div', array('id' => 'ft')); $xml->add_group('div', array('class' => 'yui-u yui-footer')); $xml->add_tag('ul', '$' . 'column[' . $columnid . ']', array('class' => 'list_no_decoration widget_list', 'id' => 'widgetlist_column' . $columnid)); $xml->close_group(); $xml->close_group(); $columnid++; } $xml->close_group(); // close #doc // get the xml, well, html segment, and store into db // replace "<![CDATA[" and "]]>" with "", as we don't need them in HTML. $replace = array("<![CDATA[", "]]>"); $gridhtml = str_replace($replace, '', $xml->output()); $db->query_write(" REPLACE INTO " . TABLE_PREFIX . "cms_grid (gridid, title, gridhtml, auxheader, auxfooter, addcolumn, addcolumnsnap, addcolumnsize, gridcolumns) VALUES ( " . intval($gridinfo['gridid']) . ", '" . $db->escape_string($vbulletin->GPC['title']) . "', '" . $db->escape_string($gridhtml) . "', " . intval($vbulletin->GPC['auxheader']) . ", " . intval($vbulletin->GPC['auxfooter']) . ", " . intval($vbulletin->GPC['addcolumn']) . ", " . intval($vbulletin->GPC['addcolumnsnap']) . ", " . intval($vbulletin->GPC['addcolumnsize']) . ", " . intval($vbulletin->GPC['columns']) . "
} $xml->close_group('item'); break; } } } switch($vbulletin->GPC['type']) { case 'XML': case 'JS': break; case 'RSS1': $xml->close_group('rdf:RDF'); $output .= $xml->output(); unset($xml); break; case 'RSS': $output .= '<!DOCTYPE rss PUBLIC "-//Netscape Communications//DTD RSS 0.91//EN" "http://my.netscape.com/publish/formats/rss-0.91.dtd">' . "\r\n"; $xml->close_group('channel'); $xml->close_group('rss'); $output .= $xml->output(); unset($xml); break; case 'RSS2': $xml->close_group('channel'); $xml->close_group('rss'); $output .= $xml->output(); unset($xml); }
function get_language_export_xml($languageid, $product, $custom, $just_phrases, $charset = 'ISO-8859-1') { global $vbulletin; //moved here from the top of language.php $default_skipped_groups = array('cphelptext'); if ($languageid == -1) { // $language['title'] = $vbphrase['master_language']; $language['title'] = new vB_Phrase('language', 'master_language'); } else { $language = $vbulletin->db->query_first("\n\t\t\tSELECT *\n\t\t\tFROM " . TABLE_PREFIX . "language\n\t\t\tWHERE languageid = " . $languageid); } $title = str_replace('"', '\\"', $language['title']); $version = str_replace('"', '\\"', $vbulletin->options['templateversion']); $phrasetypes = fetch_phrasetypes_array(false); $phrases = array(); $getphrases = $vbulletin->db->query_read("\n\t\tSELECT phrase.varname, phrase.text, phrase.fieldname, phrase.languageid,\n\t\t\tphrase.username, phrase.dateline, phrase.version\n\t\t\t" . ($languageid != -1 ? ", IF(ISNULL(phrase2.phraseid), 1, 0) AS iscustom" : "") . "\n\t\tFROM " . TABLE_PREFIX . "phrase AS phrase\n\t\t" . ($languageid != -1 ? "LEFT JOIN " . TABLE_PREFIX . "phrase AS phrase2 ON (phrase.varname = phrase2.varname AND phrase2.languageid = -1 AND phrase.fieldname = phrase2.fieldname)" : "") . "\n\t\tWHERE phrase.languageid IN (" . $languageid . ($custom ? ", 0" : "") . ")\n\t\t\tAND (phrase.product = '" . $vbulletin->db->escape_string($product) . "'" . iif($product == 'vbulletin', " OR phrase.product = ''") . ")\n\t\t\t" . (($languageid == -1 and !empty($default_skipped_groups)) ? "AND fieldname NOT IN ('" . implode("', '", $default_skipped_groups) . "')" : '') . "\n\t\tORDER BY phrase.languageid, phrase.fieldname, phrase.varname\n\t"); while ($getphrase = $vbulletin->db->fetch_array($getphrases)) { if (!$custom and $getphrase['iscustom']) { continue; } $phrases["{$getphrase['fieldname']}"]["{$getphrase['varname']}"] = $getphrase; } unset($getphrase); $vbulletin->db->free_result($getphrases); if (empty($phrases) and $just_phrases) { throw new vB_Exception_AdminStopMessage('download_contains_no_customizations'); } require_once DIR . '/includes/class_xml.php'; $xml = new vB_XML_Builder($vbulletin, null, $charset); $xml->add_group('language', array('name' => $title, 'vbversion' => $version, 'product' => $product, 'type' => iif($languageid == -1, 'master', iif($just_phrases, 'phrases', 'custom')))); if ($languageid != -1 and !$just_phrases) { $xml->add_group('settings'); $ignorefields = array('languageid', 'title', 'userselect'); foreach ($language as $fieldname => $value) { if (substr($fieldname, 0, 12) != 'phrasegroup_' and !in_array($fieldname, $ignorefields)) { $xml->add_tag($fieldname, $value, array(), true); } } $xml->close_group(); } if ($languageid == -1 and !empty($default_skipped_groups)) { $xml->add_group('skippedgroups'); foreach ($default_skipped_groups as $skipped_group) { $xml->add_tag('skippedgroup', $skipped_group); } $xml->close_group(); } foreach ($phrases as $_fieldname => $typephrases) { $xml->add_group('phrasetype', array('name' => $phrasetypes["{$_fieldname}"]['title'], 'fieldname' => $_fieldname)); foreach ($typephrases as $phrase) { $attributes = array('name' => $phrase['varname']); if ($phrase['dateline']) { $attributes['date'] = $phrase['dateline']; } if ($phrase['username']) { $attributes['username'] = $phrase['username']; } if ($phrase['version']) { $attributes['version'] = htmlspecialchars_uni($phrase['version']); } if ($custom and $phrase['languageid'] == 0) { $attributes['custom'] = 1; } $xml->add_tag('phrase', $phrase['text'], $attributes, true); } $xml->close_group(); } $xml->close_group(); $doc = "<?xml version=\"1.0\" encoding=\"{$charset}\"?>\r\n\r\n"; $doc .= $xml->output(); $xml = null; return $doc; }
public function generateStyle($scheme, $type, $parentid, $title, $displayorder = 1, $userselect = false) { if (!vB::getUserContext()->hasAdminPermission('canadminstyles')) { throw new vB_Exception_Api('no_permission'); } define('NO_IMPORT_DOTS', true); $merge = $scheme['primary']; if (!empty($scheme['secondary'])) { $merge = array_merge($merge, $scheme['secondary']); } if (!empty($scheme['complement'])) { $merge = array_merge($merge, $scheme['complement']); } foreach ($merge as $val) { $hex[] = $val['hex']; } switch ($type) { case 'lps': // Color : Primary and Secondary $sample_file = "style_generator_sample_light.xml"; break; case 'lpt': // White : Similar to the current style $sample_file = "style_generator_sample_white.xml"; break; case 'gry': // Grey :: Primary 3 and Primary 4 only $sample_file = "style_generator_sample_gray.xml"; break; case 'drk': // Dark : Primary 3 and Primary 4 only // Dark : Primary 3 and Primary 4 only default: // Dark : Default to Dark $sample_file = "style_generator_sample_dark.xml"; break; } $xmlobj = new vB_XML_Parser(false, DIR . '/includes/xml/' . $sample_file); $styledata = $xmlobj->parse(); if ($title === '') { $title = 'Style ' . time(); } $xml = new vB_XML_Builder(); $xml->add_group('style', array('name' => $title, 'vbversion' => vB::getDatastore()->getOption('templateversion'), 'product' => 'vbulletin', 'type' => 'custom')); $xml->add_group('stylevars'); foreach ($styledata['stylevars']['stylevar'] as $stylevars) { // The XML Parser outputs 2 values for the value field when one is set as an attribute. // The work around for now is to specify the first value (the attribute). In reality // the parser shouldn't add a blank 'value' if it exists as an attribute. if (!empty($stylevars['colCat'])) { list($group, $nr) = explode('-', $stylevars['colCat']); $group = $group == 'sec' ? 'secondary' : 'primary'; $stylevars['value'] = '{"color":"#' . $scheme[$group][$nr]['hex'] . '"}'; } $thisValue = json_decode($stylevars['value'], true); if (strpos($stylevars['name'], '_border') !== false) { // @todo, make this inherit the border style & width from the default style? $thisValue['width'] = 1; $thisValue['units'] = 'px'; $thisValue['style'] = 'solid'; } $xml->add_tag('stylevar', '', array('name' => htmlspecialchars($stylevars['name']), 'value' => base64_encode(serialize($thisValue)))); } // Close stylevar group $xml->close_group(); // Close style group $xml->close_group(); $doc = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\r\n\r\n"; $doc .= $xml->output(); $xml = null; $imported = $this->library->importStyleFromXML($doc, $title, $parentid, -1, true, $displayorder, $userselect, true); $this->buildAllStyles(); //xml_import_style($doc, -1, $parentid, $title, $anyversion, $displayorder, $userselect, null, null, true); return $imported; }
function get_language_export_xml($languageid, $product, $custom, $just_phrases, $charset = 'ISO-8859-1') { global $vbulletin; //moved here from the top of language.php $default_skipped_groups = array('cphelptext', 'pagemeta'); if ($languageid == -1) { // $language['title'] = $vbphrase['master_language']; $language['title'] = new vB_Phrase('language', 'master_language'); } else { $language = vB::getDbAssertor()->getRow('language', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_SELECT, 'languageid' => $languageid)); } $title = str_replace('"', '\\"', $language['title']); $version = str_replace('"', '\\"', $vbulletin->options['templateversion']); $vblangcode = str_replace('"', '\\"', $language['vblangcode']); $revision = str_replace('"', '\\"', $language['revision']); $phrasetypes = fetch_phrasetypes_array(false); $phrases = array(); $getphrases = vB::getDbAssertor()->assertQuery('fetchPhrasesForExport', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_METHOD, 'languageid' => $languageid, 'custom' => $custom, 'product' => $product, 'default_skipped_groups' => $default_skipped_groups)); foreach ($getphrases as $getphrase) { if (!$custom and $getphrase['iscustom']) { continue; } $phrases["{$getphrase['fieldname']}"]["{$getphrase['varname']}"] = $getphrase; } unset($getphrase); if (empty($phrases) and $just_phrases) { throw new vB_Exception_AdminStopMessage('download_contains_no_customizations'); } require_once DIR . '/includes/class_xml.php'; $xml = new vB_XML_Builder(null, $charset); $languagegroup = array('name' => $title, 'vbversion' => $version, 'product' => $product, 'type' => $languageid == -1 ? 'master' : ($just_phrases ? 'phrases' : 'custom')); $vb5_config =& vB::getConfig(); if (!empty($vblangcode) and !empty($revision)) { $languagegroup += array('vblangcode' => $vblangcode, 'revision' => $revision); } $xml->add_group('language', $languagegroup); if ($languageid != -1 and !$just_phrases) { $xml->add_group('settings'); $ignorefields = array('languageid', 'title', 'userselect', 'vblangcode', 'revision'); foreach ($language as $fieldname => $value) { if (substr($fieldname, 0, 12) != 'phrasegroup_' and !in_array($fieldname, $ignorefields)) { $xml->add_tag($fieldname, $value, array(), true); } } $xml->close_group(); } if ($languageid == -1 and !empty($default_skipped_groups)) { $xml->add_group('skippedgroups'); foreach ($default_skipped_groups as $skipped_group) { $xml->add_tag('skippedgroup', $skipped_group); } $xml->close_group(); } foreach ($phrases as $_fieldname => $typephrases) { $xml->add_group('phrasetype', array('name' => $phrasetypes["{$_fieldname}"]['title'], 'fieldname' => $_fieldname)); foreach ($typephrases as $phrase) { $attributes = array('name' => $phrase['varname']); if ($phrase['dateline']) { $attributes['date'] = $phrase['dateline']; } if ($phrase['username']) { $attributes['username'] = $phrase['username']; } if ($phrase['version']) { $attributes['version'] = htmlspecialchars_uni($phrase['version']); } if ($custom and $phrase['languageid'] == 0) { $attributes['custom'] = 1; } $xml->add_tag('phrase', $phrase['text'], $attributes, true); } $xml->close_group(); } $xml->close_group(); $doc = "<?xml version=\"1.0\" encoding=\"{$charset}\"?>\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_settings_export_xml($product) { global $vbulletin; $setting = array(); $settinggroup = array(); $groups = $vbulletin->db->query_read("\n\t\tSELECT * FROM " . 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; } $sets = $vbulletin->db->query_read("\n\t\tSELECT * FROM " . TABLE_PREFIX . "setting\n\t\tWHERE volatile = 1\n\t\tAND (product = '" . $vbulletin->db->escape_string($product) . "'" . iif($product == 'vbulletin', " OR product = ''") . ")\n\t\tORDER BY displayorder, varname\n\t"); while ($set = $vbulletin->db->fetch_array($sets)) { $setting["{$set['grouptitle']}"][] = $set; } unset($set); $vbulletin->db->free_result($sets); require_once DIR . '/includes/class_xml.php'; $xml = new vB_XML_Builder($vbulletin); $xml->add_group('settinggroups', array('product' => $product)); foreach ($settinggroup as $grouptitle => $group) { if (!empty($setting["{$grouptitle}"])) { $group = $settinggroup["{$grouptitle}"]; $xml->add_group('settinggroup', array('name' => htmlspecialchars_uni($group['grouptitle']), 'displayorder' => $group['displayorder'], 'product' => $group['product'])); 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', iif($set['varname'] == 'templateversion', $vbulletin->options['templateversion'], $set['defaultvalue'])); } if ($set['blacklist']) { $xml->add_tag('blacklist', 1); } $xml->close_group(); } $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_settings_export_xml($product) { $setting = array(); $settinggroup = array(); $groups = vB::getDbAssertor()->assertQuery('settinggroup', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_SELECT, 'volatile' => 1), array('field' => array('displayorder', 'grouptitle'), 'direction' => array(vB_dB_Query::SORT_ASC, vB_dB_Query::SORT_ASC))); if ($groups and $groups->valid()) { foreach ($groups as $group) { $settinggroup["{$group['grouptitle']}"] = $group; } } $sets = vB::getDbAssertor()->assertQuery('vBForum:fetchSettingsByProduct', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_METHOD, 'product' => $product)); if ($sets and $sets->valid()) { foreach ($sets as $set) { $setting["{$set['grouptitle']}"][] = $set; } } unset($set); require_once DIR . '/includes/class_xml.php'; $xml = new vB_XML_Builder(); $xml->add_group('settinggroups', array('product' => $product)); foreach ($settinggroup as $grouptitle => $group) { if (!empty($setting["{$grouptitle}"])) { $group = $settinggroup["{$grouptitle}"]; if (empty($group['adminperm'])) { $xml->add_group('settinggroup', array('name' => htmlspecialchars($group['grouptitle']), 'displayorder' => $group['displayorder'], 'product' => $group['product'])); } else { $xml->add_group('settinggroup', array('name' => htmlspecialchars($group['grouptitle']), 'displayorder' => $group['displayorder'], 'product' => $group['product'], 'adminperm' => $group['adminperm'])); } 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', iif($set['varname'] == 'templateversion', vB::getDatastore()->getOption('templateversion'), $set['defaultvalue'])); } if ($set['blacklist']) { $xml->add_tag('blacklist', 1); } if ($set['ispublic']) { $xml->add_tag('ispublic', 1); } if (!empty($set['adminperm'])) { $xml->add_tag('adminperm', $set['adminperm']); } $xml->close_group(); } $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; }
/** * Generates the style for the style generator * * @param array contains all color data * @param int Number for the parent id * @param string Title for the genrated style * @param boolean Override version check * @param int Display order for the style * @param boolean True / False whether it will be user selectable * @param int Version * */ function generate_style($data, $parentid, $title, $anyversion = false, $displayorder, $userselect, $version) { global $vbulletin; require_once DIR . '/includes/class_xml.php'; // Need to check variable for values - Check to make sure we have a name etc $arr = explode('{', stripslashes($data)); // checked below $hex = array(0 => ''); // start at one $match = $match2 = array(); // initialize $type = 'lps'; // checked below // Get master stylevar data $svdata = $vbulletin->db->query_read("\n\t\tSELECT stylevarid\n\t\tFROM " . TABLE_PREFIX . "stylevar\n\t\tWHERE styleid = -1\n\t"); // Generate list $masterlist = array(); while ($svlist = $vbulletin->db->fetch_array($svdata)) { $masterlist[$svlist['stylevarid']] = true; } foreach ($arr as $key => $value) { if (preg_match("/\"hex\":\"([0-9A-F]{6})\"/", $value, $match) == 1) { $hex[] = '#' . $match[1]; } if (preg_match("/\"type\":\"([a-z0-9]{3})\"/", $value, $match2) == 1) { $type = $match2[1]; } } switch (count($hex)) { case '11': break; default: print_stop_message('incorrect_color_mapping'); } switch ($type) { case 'lpt': // White : Similar to the current style $sample_file = "style_generator_sample_white.xml"; $from = array('#A60000', '#BF3030', '#FF4040', '#FF7373'); $to = array($hex[3], $hex[2], $hex[1], $hex[1]); break; case 'gry': // Grey :: Primary 3 and Primary 4 only $sample_file = "style_generator_sample_gray.xml"; $from = array('#A60000', '#FF4040'); $to = array($hex[1], $hex[4]); break; case 'drk': // Dark : Primary 3 and Primary 4 only $sample_file = "style_generator_sample_dark.xml"; $from = array('#A60000', '#FF4040'); $to = array($hex[1], $hex[4]); break; case 'lps': // Light : Primary and Secondary // Light : Primary and Secondary default: // Default to lps (as previously set at start of function, not dark). $sample_file = "style_generator_sample_light.xml"; $from = array('#FF0000', '#BF3030', '#A60000', '#FF4040', '#FF7373', '#009999', '#1D7373', '#5CCCCC'); $to = array($hex[1], $hex[2], $hex[3], $hex[4], $hex[5], $hex[6], $hex[7], $hex[10]); break; } $decode = $match = array(); $xmlobj = new vB_XML_Parser(false, DIR . '/includes/xml/' . $sample_file); $styledata = $xmlobj->parse(); foreach ($styledata['stylevars']['stylevar'] as $stylevars) { // The XML Parser outputs 2 values for the value field when one is set as an attribute. // The work around for now is to specify the first value (the attribute). In reality // the parser shouldn't add a blank 'value' if it exists as an attribute. $decode[$stylevars['name']] = vb_base64_decode($stylevars['value'][0]); } // Preg match and then replace. Shutter, a better method is on the way. $match = array(); foreach ($decode as $name => $value) { if (preg_match("/\"(#[a-zA-Z0-9]{6})\"/", $value, $match) == 1) { $upper = '"' . strtoupper($match[1]) . '"'; $stylevarparts[$name] = str_replace($from, $to, preg_replace("/\"(#[a-zA-Z0-9]{6})\"/", $upper, $value)); } } if ($title === '') { $title = 'Style ' . time(); } $xml = new vB_XML_Builder($vbulletin); $xml->add_group('style', array('name' => $title, 'vbversion' => $version, 'product' => 'vbulletin', 'type' => 'custom')); $xml->add_group('stylevars'); foreach ($stylevarparts as $stylevarid => $stylevar) { // Add if exists if ($masterlist[$stylevarid]) { $xml->add_tag('stylevar', '', array('name' => htmlspecialchars_uni($stylevarid), 'value' => vb_base64_encode($stylevar))); } } // Close stylevar group $xml->close_group(); // Close style group $xml->close_group(); $doc = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\r\n\r\n"; $doc .= $xml->output(); $xml = null; if ($parentid == -1 or $parentid == -2) { $masterstyleid = $parentid; } else { $style = $vbulletin->db->query_first("\n\t\t\tSELECT IF(type = 'standard', '-1', '-2') AS masterstyleid\n\t\t\tFROM " . TABLE_PREFIX . "style\n\t\t\tWHERE styleid = {$parentid}\n\t\t"); $masterstyleid = $style['masterstyleid']; } xml_import_style($doc, $masterstyleid, $parentid, $title, $anyversion, $displayorder, $userselect, null, null, 1); print_cp_redirect("template.php?" . $vbulletin->session->vars['sessionurl'] . "do=rebuild&goto=template.php?" . $vbulletin->session->vars['sessionurl']); }
/** * This function gets a product or set vbulletin as default and prints * the XML file for it's options.. * @param boolean $blacklist * @param string $product * @return array response */ public function getGroupSettingsXML($blacklist, $product = 'vbulletin') { $this->checkHasAdminPermission('canadminsettingsall'); require_once DIR . '/includes/class_xml.php'; require_once DIR . '/includes/functions_file.php'; require_once DIR . '/includes/adminfunctions_options.php'; $response = array(); //Evaluate if product is valid if (array_key_exists($product, vB::getDatastore()->getValue('products'))) { $xml = new vB_XML_Builder(); $xml->add_group('settings', array('product' => $product)); $sets = vB::getDbAssertor()->assertQuery('vBForum:fetchSettingsByProduct', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_METHOD, 'product' => $product, 'blacklist' => $blacklist)); if ($sets and $sets->valid()) { foreach ($sets as $set) { $arr = array('varname' => $set['varname']); $xml->add_group('setting', $arr); if ($set['value'] != '') { $xml->add_tag('value', $set['value']); } $xml->close_group(); } } $xml->close_group(); $response['settings'] = $xml->output(); $xml = null; } else { throw new vB_Exception_Api('invalid_product_specified'); } return $response; }
/** * Generates the style for the style generator * * @param array contains all color data * @param int Number for the parent id * @param string Title for the genrated style * @param boolean Override version check * @param int Display order for the style * @param boolean True / False whether it will be user selectable * @param int Version * */ function generate_style($data, $parentid, $title, $anyversion = false, $displayorder, $userselect, $version) { global $vbulletin; require_once DIR . '/includes/class_xml.php'; // Need to check variable for values - Check to make sure we have a name etc $arr = explode('{', stripslashes($data)); // checked below $hex = array(0 => ''); // start at one $match = $match2 = array(); // initialize $type = 'lps'; // checked below foreach ($arr as $key => $value) { if (preg_match("/\"hex\":\"([0-9A-F]{6})\"/", $value, $match) == 1) { $hex[] = '#' . $match[1]; } if (preg_match("/\"type\":\"([a-z0-9]{3})\"/", $value, $match2) == 1) { $type = $match2[1]; } } switch (count($hex)) { case '11': break; default: print_stop_message2('incorrect_color_mapping'); } if ($type == 'lps') { $sample_file = "style_generator_sample_light.xml"; $from = array('#FF0000', '#BF3030', '#A60000', '#FF4040', '#FF7373', '#009999', '#1D7373', '#5CCCCC'); $to = array($hex[1], $hex[2], $hex[3], $hex[4], $hex[5], $hex[6], $hex[7], $hex[10]); } else { if ($type == 'lpt') { $sample_file = "style_generator_sample_white.xml"; $from = array('#A60000', '#BF3030', '#FF4040', '#FF7373'); $to = array($hex[3], $hex[2], $hex[1], $hex[1]); } else { if ($type == 'gry') { $sample_file = "style_generator_sample_gray.xml"; $from = array('#A60000', '#FF4040'); $to = array($hex[1], $hex[4]); } else { if ($type == 'drk') { $sample_file = "style_generator_sample_dark.xml"; $from = array('#A60000', '#FF4040'); $to = array($hex[1], $hex[4]); } else { $sample_file = "style_generator_sample_dark.xml"; $from = array('#A60000', '#FF4040'); $to = array($hex[1], $hex[4]); } } } } $decode = $match = array(); $xmlobj = new vB_XML_Parser(false, DIR . '/includes/xml/' . $sample_file); $styledata = $xmlobj->parse(); foreach ($styledata['stylevars']['stylevar'] as $stylevars) { // The XML Parser outputs 2 values for the value field when one is set as an attribute. // The work around for now is to specify the first value (the attribute). In reality // the parser shouldn't add a blank 'value' if it exists as an attribute. $decode[$stylevars['name']] = base64_decode($stylevars['value'][0]); } // Preg match and then replace. Shutter, a better method is on the way. $match = array(); foreach ($decode as $name => $value) { if (preg_match("/\"(#[a-zA-Z0-9]{6})\"/", $value, $match) == 1) { $upper = '"' . strtoupper($match[1]) . '"'; $stylevarparts[$name] = str_replace($from, $to, preg_replace("/\"(#[a-zA-Z0-9]{6})\"/", $upper, $value)); } } if ($title === '') { $title = 'Style ' . time(); } $xml = new vB_XML_Builder(); $xml->add_group('style', array('name' => $title, 'vbversion' => $version, 'product' => 'vbulletin', 'type' => 'custom')); $xml->add_group('stylevars'); foreach ($stylevarparts as $stylevarid => $stylevar) { $xml->add_tag('stylevar', '', array('name' => htmlspecialchars($stylevarid), 'value' => base64_encode(serialize(json_decode($stylevar))))); } // Close stylevar group $xml->close_group(); // Close style group $xml->close_group(); $doc = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\r\n\r\n"; $doc .= $xml->output(); $xml = null; xml_import_style($doc, -1, $parentid, $title, $anyversion, $displayorder, $userselect); $args['do'] = 'rebuild'; $args['goto'] = "template?" . vB::getCurrentSession()->get('sessionurl'); print_cp_redirect_with_session('template', $args); }