/** * Prepares the contents of the export file. * * @author Gary Jones * @since 0.9.6 * @return array $output multi-dimensional array holding CSS data * @uses premise_get_mapping() * @version 1.0 */ function premise_prepare_export($key) { $mapping = premise_get_mapping(); foreach ($mapping as $selector => $declaration) { if (!is_array($declaration)) { $output[$selector] = premise_get_design_option($declaration, $key); } else { foreach ($declaration as $property => $value) { if (!is_array($value)) { $output[$selector][$property] = premise_get_design_option($value, $key); } else { foreach ($value as $index => $composite_value) { $val = $composite_value[0]; $type = $composite_value[1]; if ('fixed_string' == $type) { $output[$selector][$property][$index]['value'] = $val; } else { $output[$selector][$property][$index]['value'] = premise_get_design_option($val, $key); } $output[$selector][$property][$index]['type'] = $type; } } } } } // Add in contents of custom stylesheet $css = file_get_contents(premise_get_custom_stylesheet_path()); $output['custom_css'] = $css; return apply_filters('premise_prepare_export', $output); }
/** * If a file has been uploaded to import options, it parses the file, formats into a nice array * via the $mapping, then updates the setting in the DB. * * @author Gary Jones * @since 0.9.6 * @uses premise_get_mapping */ function premise_process_import() { if (isset($_POST['premise'])) { if ('import' == $_POST['premise']) { check_admin_referer('premise-import', '_wpnonce-premise-import'); if (strpos($_FILES['file']['name'], premise_get_export_filename_prefix()) === false) { wp_redirect(admin_url('admin.php?page=premise-design&premise=wrongfile')); } elseif ($_FILES['file']['error'] > 0) { wp_redirect(admin_url('admin.php?page=premise-design&premise=file')); } else { $raw_options = file_get_contents($_FILES['file']['tmp_name']); $raw_options = trim($raw_options); $options = maybe_unserialize($raw_options); $mapping = premise_get_mapping(); foreach ($options as $selector => $declaration) { if (!isset($mapping[$selector])) { continue; } if (!is_array($declaration)) { // custom_css or minify_css if ('custom_css' == $selector) { premise_create_custom_stylesheet($declaration); } else { $opt = $selector; $newvalue = $declaration; $newarray[$opt] = $newvalue; } } else { foreach ($declaration as $property => $value) { if (!is_array($value)) { // color, font-style, text-decoration etc $opt = $mapping[$selector][$property]; $newvalue = $value; $newarray[$opt] = $newvalue; } else { // multi-value properties: margin, padding, etc foreach ($value as $index => $composite_value) { $type = $mapping[$selector][$property][$index][1]; if ('fixed_string' != $type) { $opt = $mapping[$selector][$property][$index][0]; $newvalue = $composite_value['value']; $newarray[$opt] = $newvalue; } } } } } } $title = empty($_POST['premise_style_title']) ? __('Imported Style', 'premise') : $_POST['premise_style_title']; $newarray['premise_style_title'] = __('Imported Styles', 'premise'); global $Premise; $key = $Premise->saveDesignSettings($newarray, $_POST['premise-design-key']); wp_redirect(admin_url('admin.php?page=premise-style-settings&updated=true&premise-design-key=' . $key)); } } } }
/** * Loops through the mapping to prepare the CSS output. * * @author Gary Jones * @since 0.9.6 * @return string $output Beautified CSS * @uses premise_get_mapping() * @version 1.0 */ function premise_prepare_settings_stylesheet($key) { $mapping = premise_get_mapping(); $output = array(); foreach ($mapping as $selector => $declaration) { if ('premise_custom_css' != $selector && 'minify_css' != $selector) { $output[] = $selector . ' {'; foreach ($declaration as $property => $value) { if (strpos($property, '_select')) { if (premise_get_fresh_design_option($value, $key) == 'hex') { continue; } array_pop($output); $property = substr($property, 0, strlen($property) - 7); } if ('background-image' == $property) { $imagekey = $value[1][0]; $image = trim(premise_get_fresh_design_option($imagekey, $key)); if ('' == $image) { continue; } } $line = "\t" . $property . ':'; if (is_array($value)) { foreach ($value as $composite_value) { $line .= ' '; $val = $composite_value[0]; $type = $composite_value[1]; if ('fixed_string' == $type) { $line .= $val; } elseif ('string' == $type) { $line .= premise_get_fresh_design_option($val, $key); } else { $cache_val = premise_get_fresh_design_option($val, $key); $line .= $cache_val; $line .= (int) $cache_val > 0 ? $type : null; } } } else { $line .= ' ' . premise_get_fresh_design_option($value, $key); } $output[] = $line . ";"; } $output[] = "}"; } elseif ('premise_custom_css' == $selector) { $output[] = premise_get_fresh_design_option($declaration, $key); } } return apply_filters('premise_prepare_stylesheet', implode("\n", $output), $key); }