Esempio n. 1
0
    print_table_header('Time');
    print_column_style_code(array('width:30%'));
    print_label_row('System Time', $systemdate = date('r T'));
    print_label_row('Your Time', $userdate = vbdate('r T'));
    print_table_footer();
} else {
    if ($_REQUEST['do'] == 'xml') {
        switch ($vbulletin->GPC['type']) {
            case 'style':
                require_once './includes/adminfunctions_template.php';
                if (!($xml = file_read('./install/vbulletin-style.xml'))) {
                    echo '<p>Uh oh, ./install/vbulletin-style.xml doesn\'t appear to exist! Upload it and refresh the page.</p>';
                    break;
                }
                echo '<p>Importing vbulletin-style.xml</p>';
                xml_import_style($xml);
                // define those phrases that are used for the import
                $vbphrase['style'] = 'Style';
                $vbphrase['please_wait'] = 'Please Wait';
                build_all_styles(0, 1);
                break;
            case 'settings':
                require_once './includes/adminfunctions_options.php';
                if (!($xml = file_read('./install/vbulletin-settings.xml'))) {
                    echo '<p>Uh oh, ./install/vbulletin-settings.xml doesn\'t appear to exist! Upload it and refresh the page.</p>';
                    print_cp_footer();
                }
                echo '<p>Importing vbulletin-settings.xml';
                xml_import_settings($xml);
                echo '<br /><span class="smallfont"><b>Okay</b></span></p>';
                break;
/**
* 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;
	// 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_message('incorrect_color_mapping');
	}

	if ($type == 'lps') // Color : Primary and Secondary (except S3 and S4)
	{
		$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') // 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]);
	}
	else if ($type == '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]);
	}
	else if ($type == '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]);
	}
	else // Dark : Default to Dark
	{
		$sample_file = "style_generator_sample_dark.xml";
		$from = array('#A60000', '#FF4040');
		$to = array($hex[1], $hex[4]);
	}

	$style = file(DIR . '/includes/xml/' . $sample_file);

	$decode = $match = array();
	foreach($style AS $name => $value) // read in and decode the sample_*.xml file
	{
		if (preg_match("/name=\"(.*)\" value=\"(.*)\"/", $value, $match) == 1)
		{
			$decode[$match[1]] = base64_decode($match[2]);
		}
	}

	$match = array();
	$output = '';
	foreach ($decode AS $name => $value) // replace the RRGGBB in the sample_*.xml file with chosen colors and re-encode
	{
		if (preg_match("/\"(#[a-zA-Z0-9]{6})\"/", $value, $match) == 1)
		{
			$upper = '"' . strtoupper($match[1]) . '"';
			$value = base64_encode(str_replace($from, $to, preg_replace("/\"(#[a-zA-Z0-9]{6})\"/", $upper, $value)));
			$output .= '		<stylevar name="' . $name . '" value="' . $value . '" />
	';
		}
	}
	if($title===''){$title = 'Style ' . time();}
	$output = '<?xml version="1.0" encoding="ISO-8859-1"?>

	<style name="' . $title . '" vbversion="' . $version . '" product="vbulletin" type="custom">
		<stylevardfns>
		</stylevardfns>
		<stylevars>
	' . $output . '	</stylevars>
	</style>
	';

	xml_import_style($output,
		-1, $parentid, $title,
		$anyversion, $displayorder, $userselect
	);

	print_cp_redirect("template.php?" . $vbulletin->session->vars['sessionurl'] . "do=rebuild&amp;goto=template.php?" . $vbulletin->session->vars['sessionurl']);

}
Esempio n. 3
0
// #############################################################################
// upload style
if ($_POST['do'] == 'upload') {
    $vbulletin->input->clean_array_gpc('p', array('overwritestyleid' => TYPE_INT, 'serverfile' => TYPE_STR, 'parentid' => TYPE_INT, 'title' => TYPE_STR, 'anyversion' => TYPE_BOOL, 'displayorder' => TYPE_INT, 'userselect' => TYPE_BOOL));
    $vbulletin->input->clean_array_gpc('f', array('stylefile' => TYPE_FILE));
    // got an uploaded file?
    if (file_exists($vbulletin->GPC['stylefile']['tmp_name'])) {
        $xml = file_read($vbulletin->GPC['stylefile']['tmp_name']);
    } else {
        if (file_exists($vbulletin->GPC['serverfile'])) {
            $xml = file_read($vbulletin->GPC['serverfile']);
        } else {
            print_stop_message('no_file_uploaded_and_no_local_file_found');
        }
    }
    xml_import_style($xml, $vbulletin->GPC['overwritestyleid'], $vbulletin->GPC['parentid'], $vbulletin->GPC['title'], $vbulletin->GPC['anyversion'], $vbulletin->GPC['displayorder'], $vbulletin->GPC['userselect']);
    print_cp_redirect("template.php?" . $vbulletin->session->vars['sessionurl'] . "do=rebuild", 0);
}
// #############################################################################
// file manager
if ($_REQUEST['do'] == 'files') {
    cache_styles();
    ?>
	<script type="text/javascript">
	<!--
	function js_confirm_upload(tform, filefield)
	{
		if (filefield.value == "")
		{
			return confirm("<?php 
    echo construct_phrase($vbphrase['you_did_not_specify_a_file_to_upload'], '" + tform.serverfile.value + "');
Esempio n. 4
0
 /**
  * Import style from XML Data
  *
  * @param string $xmldata XML Data to be imported as style.
  * @param string $title Style title.
  * @param integer $parentid Parent style ID.
  * @param integer $overwritestyleid Style ID to be overwritten.
  * @param boolean $anyversion Whether to ignore style version.
  * @param integer $displayorder Style display order.
  * @param boolean $userselect Whether the style allows user selection.
  */
 public function importStyleFromXML($xmldata, $title, $parentid, $overwritestyleid, $anyversion, $displayorder, $userselect, $scilent = false)
 {
     require_once DIR . '/includes/adminfunctions_template.php';
     $imported = xml_import_style($xmldata, $overwritestyleid, $parentid, $title, $anyversion, $displayorder, $userselect, null, null, $scilent);
     return $imported;
 }
Esempio n. 5
0
	require_once(DIR . '/includes/functions_databuild.php');
	build_bbcode_video();

	require_once(DIR . '/includes/adminfunctions_template.php');

	//needed for next_page processing.
	$vbulletin->GPC['perpage'] = 10;
	if (!($xml = file_read(DIR . '/install/vbulletin-style.xml')))
	{
		echo '<p>' . sprintf($vbphrase['file_not_found'], 'vbulletin-style.xml') . '</p>';
		print_cp_footer();
	}

	echo '<p>' . sprintf($vbphrase['importing_file'], 'vbulletin-style.xml');

	$info = xml_import_style($xml, -1, -1, '', false, 1, false,
		$vbulletin->GPC['startat'], $vbulletin->GPC['perpage']);
	if ($info['done'])
	{
		build_all_styles(0, 1);
	}
	else
	{
		print_next_page();
	}

	echo "<br /><span class=\"smallfont\"><b>$vbphrase[ok]</b></span></p>";
}

if ($vbulletin->GPC['step'] == 8)
{
	require_once(DIR . '/includes/adminfunctions_help.php');
Esempio n. 6
0
 protected function import($startat = 0, $perpage = 1, $overwrite = false, $styleid = -1, $anyversion = false, $extra = array())
 {
     require_once DIR . '/includes/adminfunctions_template.php';
     require_once DIR . '/includes/adminfunctions.php';
     $xml = $this->parsedXML['theme'];
     $themeName = $xml['name'];
     unset($this->parsedXML['theme']);
     $phrases = vB_Api::instanceInternal('phrase')->fetch(array('theme_x_exists_skipped', 'theme_x_invalid_data_skiped', 'theme_x_imported'));
     // At the very least we need guid (icon is optional) for a theme
     if (empty($xml['guid'])) {
         return array('done' => true, 'output' => construct_phrase($phrases['theme_x_invalid_data_skiped'], $xml['name']), "error" => "GUID and icon must be specified for a theme!");
     }
     /*
     	On import the theme import should fail if the theme is already installed (per the guid value)
     	unless an overwrite is requested. If an overwrite is requested than any parent/title information
     	for the import is ignored and the existing theme is overwritten by the import.
     */
     // we don't add the GUID until we're done, so this check works even when we're in the middle of
     // importing a theme in partitions
     $existingTheme = $this->db->getRow('style', array('guid' => $xml['guid']));
     if (!empty($existingTheme)) {
         // TODO: need to test that overwrite works correctly
         if ($overwrite) {
             // ignore parent & title info, overwrite existing theme.
             unset($xml['name']);
             $title = $existingTheme['title'];
             // If styleid is not -1, xml_import_style will ignore the parentid, so it's only used for the style record creation.
             // This works with overwrite (ignore parent relation).
             $parentid = $existingTheme['parentid'];
             $styleid = $existingTheme['styleid'];
             $product = empty($xml['product']) ? 'vbulletin' : $xml['product'];
             // grab rest form user input if set. Otherwise, use defaults.
             $userselect = empty($extra['userselect']) ? false : $extra['userselect'];
             $displayorder = empty($extra['displayorder']) ? 1 : $extra['displayorder'];
         } else {
             /*
             					TODO: The admincp should be updated to attempt the import without overwrite and request
             						confirmation for overwrite if the install fails due to the theme already existing.
             */
             return array('done' => true, 'output' => construct_phrase($phrases['theme_x_exists_skipped'], $xml['name']), "warning" => "The theme exists, and overwrite was not specified. Skipping import.");
             // we're not in overwrite mode, and theme already exists. Let's just return.
         }
     } elseif ($startat == 0) {
         /*
          *	We need to add this new theme. Setting styleid to -1 should allow the existing import code
          *	to take care of it for us.
          */
         $styleid = -1;
         $product = empty($xml['product']) ? 'vbulletin' : $xml['product'];
         /*
          *	For a new import, use user selected data for title, parentid and userselect. If no user provided
          *	input is available, use xml provided info or defaults.
          *	User input will only be available for adminCP imports, not install/upgrades
          */
         $title = empty($extra['title']) ? !empty($xml['name']) ? $xml['name'] : '' : $extra['title'];
         $parentid = empty($extra['parentid']) ? self::$themeParent['styleid'] : $extra['parentid'];
         $userselect = empty($extra['userselect']) ? false : $extra['userselect'];
         $displayorder = empty($extra['displayorder']) ? 1 : $extra['displayorder'];
     }
     // If styleid is not -1, xml_import_style will ignore the parentid, so it's only used for the style record creation.
     // This works with overwrite (ignore parent relation).
     $info = xml_import_style(false, $styleid, $parentid, $title, $anyversion, $displayorder, $userselect, $startat, $perpage, false, $xml);
     // If we're done importing all the templates 1 by 1, the stylevar definitions & style vars. Let's
     // add the theme-specific data.
     if ($info['done']) {
         // If import finished on 1 iteration (which it does if the theme/style has no template groups to import),
         // we need to grab the styleid of the new style record that was created because $styleid is still -1 at
         // this point.
         if ($info['overwritestyleid'] > -1) {
             $styleid = $info['overwritestyleid'];
         }
         $updateParams = array('guid' => $xml['guid']);
         if (!empty($xml['icon'])) {
             try {
                 $filedataid = $this->uploadThemeImage($xml['icon']);
                 if ($filedataid) {
                     $updateParams['filedataid'] = $filedataid;
                 }
             } catch (Exception $e) {
                 // ATM we just ignore errors in icon/preview image uploads and just import the theme without it
                 // since icons & preview images are optional
                 // A neat TODO would be to add a warning here instead, and have the upgrader or adminCP
                 // pull all warnings out and display them after each theme's import is finished.
             }
         }
         if (!empty($xml['previewimage'])) {
             try {
                 $filedataid = $this->uploadThemeImage($xml['previewimage']);
                 if ($filedataid) {
                     $updateParams['previewfiledataid'] = $filedataid;
                 }
             } catch (Exception $e) {
                 // ATM we just ignore errors in icon/preview image uploads and just import the theme without it
                 // since icons & preview images are optional
                 // A neat TODO would be to add a warning here instead, and have the upgrader or adminCP
                 // pull all warnings out and display them after each theme's import is finished.
             }
         }
         // In addition to the filedataid and previewdataid, handle any other theme-specific style table fields here
         $this->db->update('style', $updateParams, array('styleid' => $styleid));
         // TODO: Figure out what this is used for
         vB_Xml_Import::setImportedId(vB_Xml_Import::TYPE_THEME, $xml['guid'], $styleid);
         if (empty($info['output'])) {
             $info['output'] = construct_phrase($phrases['theme_x_imported'], $themeName);
         }
     }
     /*
     			xml_import_style returns:
     			return array(
     				'version' => $version,
     				'master'  => $master,
     				'title'   => $title,
     				'product' => $product,
     				'done'    => $done,
     				'overwritestyleid' => $styleid,
     				'output'  => $outputtext,
     				);
     */
     return $info;
 }
Esempio n. 7
0
 protected function import_product_mobile($data, $product)
 {
     switch ($product) {
         case 'vbblog':
             $file = 'vbulletin-mobile-style-blog.xml';
             break;
         case 'vbcms':
             $file = 'vbulletin-mobile-style-cms.xml';
             break;
         default:
             $this->skip_message();
             return;
     }
     $perpage = 1;
     $startat = intval($data['startat']);
     require_once DIR . '/includes/adminfunctions_template.php';
     $importfile = '';
     if (!($xml = file_read(DIR . '/install/' . $file))) {
         // output a mobile style not found error
         $this->add_error(sprintf($this->phrase['vbphrase']['file_not_found'], $file), self::PHP_TRIGGER_ERROR, true);
         return;
     }
     if ($startat == 0) {
         $this->show_message(sprintf($this->phrase['vbphrase']['importing_file'], $file));
     }
     $info = xml_import_style($xml, -2, -2, '', false, 1, false, $startat, $perpage, 0, $file);
     if (!$info['done']) {
         $this->show_message($info['output']);
         return array('startat' => $startat + $perpage);
     } else {
         $this->show_message($this->phrase['core']['import_done']);
     }
 }
Esempio n. 8
0
/**
* 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&amp;goto=template.php?" . $vbulletin->session->vars['sessionurl']);
}
Esempio n. 9
0
 /**
  * Step #5 - Import Mobile Style
  *
  * @param	array	contains id to startat processing at
  *
  */
 function step_5($data = null)
 {
     $perpage = 1;
     $startat = intval($data['startat']);
     require_once DIR . '/includes/adminfunctions_template.php';
     $importfile = '';
     if ($xml = file_read(DIR . '/install/vbulletin-mobile-style.xml')) {
         $importfile = 'vbulletin-mobile-style.xml';
     } else {
         // output a mobile style not found error
         $this->add_error(sprintf($this->phrase['vbphrase']['file_not_found'], 'vbulletin-mobile-style.xml'), self::PHP_TRIGGER_ERROR, true);
         return;
     }
     if ($startat == 0) {
         $this->show_message(sprintf($this->phrase['vbphrase']['importing_file'], $importfile));
     }
     $info = xml_import_style($xml, -2, -2, '', false, 1, false, $startat, $perpage, 0, $importfile);
     if (!$info['done']) {
         $this->show_message($info['output']);
         return array('startat' => $startat + $perpage);
     } else {
         $this->show_message($this->phrase['core']['import_done']);
     }
 }
/**
* 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);
}