Esempio n. 1
0
function wppb_inline_scripts()
{
    $wppb_design_settings = get_option(WPPB_DESIGNER_SETTINGS);
    // Setting potentially empty variable
    if (empty($wppb_design_settings['design'])) {
        $wppb_design_settings['design'] = '';
    } else {
        $wppb_design_settings['design'] = sanitize_title($wppb_design_settings['design']);
    }
    // Bug fix for existing poorly labelled designs
    ?>
<script type="text/javascript">
<?php 
    do_action('wppb_inline_scripts_hook');
    ?>

// Setting WP Paintbrush JS variables
var storage_folder = '<?php 
    echo wppb_storage_folder('images', 'url');
    ?>
';
var design_folder = '<?php 
    echo get_template_directory_uri();
    ?>
/designs/<?php 
    echo $wppb_design_settings['design'];
    ?>
/images/';
var design_name = '<?php 
    echo $wppb_design_settings['design'];
    ?>
';
var nonce_link = '<?php 
    echo wp_nonce_url(home_url(), 'wppb_editor');
    ?>
';
var admin_url = '<?php 
    echo home_url();
    ?>
/wp-admin/';
var home_url = '<?php 
    echo home_url();
    ?>
';

jQuery(function($){
	// AJAX form submission
	function change_design(button) {
		$.ajax({
			type: 'POST',
			url: home_url+'/?change_theme='+button,
			data: {
				'wppb_nonce' : $("#wppb_nonce").val(),
			},
			success: function(data, textStatus) {
				$( "#wppb-page-reload" ).dialog({width:250,minWidth:250,maxWidth:250,modal:true,autoOpen:true,});
				$(location).attr('href',home_url);
			},
			error: function(jqXHR, textStatus, errorThrown) {
				$( "#wppb-external-connection-failure" ).dialog({width:250,minWidth:250,maxWidth:250,modal:true,autoOpen:true,});
			},
			dataType: 'html'
		});

	}<?php 
    // Output list of available designs
    foreach (wppb_available_themes() as $count => $design) {
        echo "\$('#myform" . $design['Folder'] . "').click(function() {change_design( '" . $design['Folder'] . "' );});\n";
    }
    ?>
	// AJAX form submission
	function option_get(button) {
		$("#wppb-css2").html('<div style="text-indent:0;"><img style="" src="'+admin_url+'images/wpspin_light.gif" /></div>');
		$.ajax({
			type: 'POST',
			url: home_url+'/?generator-css='+button,
			data: {
				'wppb_nonce':$("#wppb_nonce").val(),<?php 
    // Set all AJAX options
    foreach (wppb_ajax_option_get() as $option) {
        echo '\'' . $option . '\':$("#' . $option . '").val(),' . "\n";
    }
    ?>
			},
			success: function(data, textStatus) {
				switch(data) {
					case "Error: Couldn't connect to server":
					$( "#wppb-external-connection-failure" ).dialog({width:250,minWidth:250,maxWidth:250,modal:true,autoOpen:true,});
					$('#wppb-css3').html("Error: Couldn't connect to server");
					break;
					default:
					$('#wppb-css').html(data);
					$('#wppb-css3').html(data);
					break;
				}
				$('#wppb-css2').html('');
			},
			error: function(jqXHR, textStatus, errorThrown) {
				$( "#wppb-external-connection-failure" ).dialog({width:250,minWidth:250,maxWidth:250,modal:true,autoOpen:true,});
			},
			dataType: 'html'
		});
	}
	$('#myformButton').click(function() {option_get( 'process' );});
	$('.myformSaver').click(function() {option_get( 'save' );});
	$('#myformPublish').click(function() {option_get( 'publish' );});
	$('#myformExport').click(function() {option_get( 'export' );});
	$('#ChangeHomeLayoutMagazine').click(function() {option_get( 'Magazine' );});
	$('#ChangeHomeLayoutNormal').click(function() {option_get( 'Normal' );});

	$("#sidebar-layout-sortable, #sidebar-blocks-sortable").sortable({
		connectWith: ".sidebar-sortable-connect",
		update: function(){
			var pos = [];
			$('#sidebar-layout-sortable > li').each(function(i){
				pos[i] = $(this).attr('id');
			});
			$('#sidebar_positions').val(pos.toString());
			option_get( 'process' );
		}
	});

	// Image picker
	var $button,
	$ele = $('#wppb-image-uploads').dialog({
		width: 530,
		minWidth: 530,
		maxWidth: 530,
		title: 'Image picker',
		modal: false,
		autoOpen: false,
		open : function(event, ui){
			$('img.uploaded-image',ui.dialog).each(function(){
				var image = $(this);
				image.click(function(){
					$button.parent().find('.image-picker').val(image.attr('alt'));
					$button.removeClass('ICopen').val('pick');
<?php 
    $images = array('sidebar_background_image' => '.wrapper', 'footer_background_image' => 'footer div.footer', 'background_image' => 'body', 'maincontent_background_image' => '.wrapper #content', 'header_background_image' => 'header div.header', 'header_fullwidth_background_image' => 'header', 'header_searchbox_background_image' => 'header #search', 'header_logo_background_image' => 'header #logo', 'banner_image' => '#banner div.banner-image', 'menu1_hover_background_image' => 'nav#nav li:hover a', 'menu1_background_image' => 'nav#nav ul', 'menu1_fullwidth_background_image' => 'nav#nav', 'menu1_items_background_image' => 'nav#nav li', 'header_searchbox_text_background_image' => 'header #search input[type=text]', 'header_searchsubmit_text_background_image' => 'header #search input[type=submit]', 'footer_fullwidth_background_image' => 'footer');
    foreach ($images as $theid => $selector) {
        echo "\n\t\t\t\t\tvar filename=\$('#" . $theid, "').val().split('/');\n\t\t\t\t\tif('stored'==filename[0]){\n\t\t\t\t\t\t\$('" . $selector . "').css({'background-image':'url('+storage_folder+'/'+filename[1]+')'});\n\t\t\t\t\t}\n\t\t\t\t\tif(design_name==filename[0]){\n\t\t\t\t\t\t\$('" . $selector . "').css({'background-image':'url('+design_folder+'/'+filename[1]+')'});\n\t\t\t\t\t}";
    }
    ?>
					$ele.dialog('close');
				});
			});
		},
		beforeClose: function(event,ui){
			$('img',ui.dialog).unbind();
		}
	});
	$('.imagepickerbutton').click(function(){$button = $(this);$ele.dialog('open');});
});
</script><?php 
}
Esempio n. 2
0
function wppb_sanitize_inputs($input = '')
{
    // Grab from POST
    if ('' == $input) {
        $input = $_POST;
    }
    // If no data loaded, then grab from database (presumably because on initial page load instead of loading via AJAX)
    if ('' == $input) {
        $input = get_option(WPPB_DESIGNER_SETTINGS);
    }
    // Processing entire POST to array with errors (replaced later with correct values - used for debugging purposes)
    foreach (wppb_ajax_option_get() as $option) {
        if (isset($input[$option])) {
            $wppb_design_settings[$option] = 'Sanitization error!';
        }
    }
    // Sanitizing CSS
    if (isset($input['add_custom_css'])) {
        $wppb_design_settings['add_custom_css'] = pixopoint_validate_css($input['add_custom_css']);
    }
    // Sanitizing CSS
    // Sanitizing the added custom CSS (only one option for this so need for accessing from array)
    if (empty($wppb_design_settings['add_custom_css'])) {
        $wppb_design_settings['add_custom_css'] = '';
    }
    if (isset($input['add_custom_css'])) {
        $wppb_design_settings['add_custom_css'] = pixopoint_validate_css($input['add_custom_css']);
    }
    // Sanitizing font size options
    foreach (wppb_fontsize_options() as $stuff => $opt) {
        if (!isset($input[$opt])) {
            $input[$opt] = '';
        }
        if (is_numeric($input[$opt])) {
            if ($input[$opt] > 4 && $input[$opt] < 120) {
                $wppb_design_settings[$opt] = $input[$opt];
            } else {
                $wppb_design_settings[$opt] = '12';
            }
        }
    }
    // Sanitizing Font family options
    foreach (wppb_fontfamily_options() as $stuff => $opt) {
        // Loop through all variations
        foreach (wppb_font_family() as $variation) {
            if (!isset($input[$opt])) {
                $input[$opt] = '';
            }
            // Correcting escaped characters
            $input[$opt] = str_replace("\\'", "'", $input[$opt]);
            // Setting option if matches possible variation
            if ($input[$opt] == $variation) {
                $wppb_design_settings[$opt] = $input[$opt];
            }
        }
        // If no variation selected, then default to helvetica
        if ('' == $input[$opt]) {
            $wppb_design_settings[$opt] = "'Helvetica Neue', Arial, Helvetica, 'Nimbus Sans L', sans-serif";
        }
    }
    // Sanitizing colour options
    foreach (wppb_colour_options() as $stuff => $opt) {
        if (!isset($input[$opt])) {
            $input[$opt] = '';
        }
        $wppb_design_settings[$opt] = wppb_sanitize_hex_colour($input[$opt]);
    }
    // Sanitizing image options
    foreach (wppb_image_options() as $stuff => $opt) {
        if (!isset($input[$opt])) {
            $input[$opt] = '';
        }
        $image_location_initial = explode('/', $input[$opt]);
        $image_location_final[0] = sanitize_file_name($image_location_initial[0]);
        if (isset($image_location_initial[1])) {
            $image_location_final[1] = sanitize_file_name($image_location_initial[1]);
        }
        $wppb_design_settings[$opt] = implode('/', $image_location_final);
        if ('/' == $wppb_design_settings[$opt]) {
            $wppb_design_settings[$opt] = '';
        }
    }
    // Sanitizing image tiling options
    foreach (wppb_imagetiling_options() as $stuff => $opt) {
        if (!isset($input[$opt])) {
            $input[$opt] = '';
        }
        // Loop through all variations
        foreach (wppb_imagetiling_variations() as $variation => $text) {
            if ($input[$opt] == $variation) {
                $wppb_design_settings[$opt] = $input[$opt];
            }
        }
        // If no variation selected, then default to "repeat"
        if (!isset($wppb_design_settings[$opt])) {
            $wppb_design_settings[$opt] = '';
        }
        if ('' == $wppb_design_settings[$opt]) {
            $wppb_design_settings[$opt] = 'repeat';
        }
    }
    // Sanitizing Small-caps options
    foreach (wppb_smallcaps_options() as $stuff => $opt) {
        if (!isset($input[$opt])) {
            $input[$opt] = '';
        }
        // Loop through all variations
        foreach (wppb_smallcaps_variations() as $variation => $text) {
            if ($input[$opt] == $variation) {
                $wppb_design_settings[$opt] = $input[$opt];
            }
        }
        if (!isset($wppb_design_settings[$opt])) {
            $wppb_design_settings[$opt] = '';
        }
        // If no variation selected, then default to "repeat"
        if ('' == $wppb_design_settings[$opt]) {
            $wppb_design_settings[$opt] = 'normal';
        }
    }
    // Sanitizing font weight options
    foreach (wppb_fontweight_options() as $stuff => $opt) {
        if (!isset($input[$opt])) {
            $input[$opt] = '';
        }
        if ('bold' == $input[$opt]) {
            $wppb_design_settings[$opt] = 'bold';
        } elseif ('inherit' == $input[$opt]) {
            $wppb_design_settings[$opt] = 'inherit';
        } else {
            $wppb_design_settings[$opt] = 'normal';
        }
    }
    // Sanitizing text decoration options
    foreach (wppb_textdecoration_options() as $stuff => $opt) {
        // Loop through all variations
        foreach (wppb_textdecoration_variations() as $variation) {
            if (!isset($input[$opt])) {
                $input[$opt] = '';
            }
            if ($input[$opt] == $variation) {
                $wppb_design_settings[$opt] = $input[$opt];
            }
        }
        // Inherit variation is only present for some options
        if ($input[$opt] == 'inherit') {
            $wppb_design_settings[$opt] = $input[$opt];
        }
        // If no variation selected, then default to "repeat"
        if (!isset($wppb_design_settings[$opt])) {
            $wppb_design_settings[$opt] = '';
        }
        if ('' == $wppb_design_settings[$opt]) {
            $wppb_design_settings[$opt] = 'none';
        }
    }
    // Sanitizing big numbers options
    foreach (wppb_bignumbers_options() as $stuff => $opt) {
        if (!isset($input[$opt])) {
            $input[$opt] = '';
        }
        if (is_numeric($input[$opt])) {
            if ($input[$opt] > -0.001 and $input[$opt] < 1600) {
                $wppb_design_settings[$opt] = $input[$opt];
            } else {
                $wppb_design_settings[$opt] = '600';
            }
        }
    }
    // Sanitizing little numbers options
    foreach (wppb_littlenumbers_options() as $stuff => $opt) {
        if (!isset($input[$opt])) {
            $input[$opt] = '';
        }
        if (is_numeric($input[$opt])) {
            if ($input[$opt] > 0 and $input[$opt] < 100) {
                $wppb_design_settings[$opt] = $input[$opt];
            } else {
                $wppb_design_settings[$opt] = '0';
            }
        }
    }
    // Sanitizing shadow coordinate options
    foreach (wppb_shadow_coordinates_options() as $stuff => $opt) {
        if (!isset($input[$opt])) {
            $input[$opt] = '';
        }
        if (is_numeric($input[$opt])) {
            if ($input[$opt] > -0.001 and $input[$opt] < 40) {
                $wppb_design_settings[$opt] = $input[$opt];
            } else {
                $wppb_design_settings[$opt] = '0';
            }
        }
    }
    // Sanitizing opacity options
    foreach (wppb_opacity_options() as $stuff => $opt) {
        if (!isset($input[$opt])) {
            $input[$opt] = '';
        }
        if (is_numeric($input[$opt])) {
            if ($input[$opt] > 0 and $input[$opt] < 1.00001) {
                $wppb_design_settings[$opt] = $input[$opt];
            } else {
                $wppb_design_settings[$opt] = '1';
            }
        }
    }
    // Sanitizing display options
    foreach (wppb_display_options() as $stuff => $opt) {
        if (!isset($input[$opt])) {
            $input[$opt] = 'none';
        }
        if ($input[$opt] == 'on' || $input[$opt] == 'block') {
            $wppb_design_settings[$opt] = 'block';
        } else {
            $wppb_design_settings[$opt] = 'none';
        }
    }
    // Sanitizing centered options
    foreach (wppb_centered_options() as $stuff => $opt) {
        if (!isset($input[$opt])) {
            $input[$opt] = '';
        }
        // Loop through all variations
        foreach (wppb_alignment_variations() as $variation) {
            if ($input[$opt] == $variation) {
                $wppb_design_settings[$opt] = $input[$opt];
            }
        }
        // If no variation selected, then default to "repeat"
        if (!isset($wppb_design_settings[$opt])) {
            $wppb_design_settings[$opt] = '';
        }
        if ('' == $wppb_design_settings[$opt]) {
            $wppb_design_settings[$opt] = 'none';
        }
    }
    // Sanitizing alignment options
    foreach (wppb_alignment_options() as $stuff => $opt) {
        if (!isset($input[$opt])) {
            $input[$opt] = '';
        }
        // Loop through all variations
        foreach (wppb_alignment_variations() as $variation) {
            if ($input[$opt] == $variation) {
                $wppb_design_settings[$opt] = $input[$opt];
            }
        }
        // If no variation selected, then default to "none"
        if (!isset($wppb_design_settings[$opt])) {
            $wppb_design_settings[$opt] = '';
        }
        if ('' == $wppb_design_settings[$opt]) {
            $wppb_design_settings[$opt] = 'none';
        }
    }
    // Sanitizing Text transform options
    foreach (wppb_texttransform_options() as $stuff => $opt) {
        if (!isset($input[$opt])) {
            $input[$opt] = '';
        }
        // Loop through all variations
        foreach (wppb_texttransform_variations() as $variation) {
            if ($input[$opt] == $variation) {
                $wppb_design_settings[$opt] = $input[$opt];
            }
        }
        // If no variation selected, then default to "none"
        if (!isset($wppb_design_settings[$opt])) {
            $wppb_design_settings[$opt] = '';
        }
        if ('' == $wppb_design_settings[$opt]) {
            $wppb_design_settings[$opt] = 'none';
        }
    }
    // Sanitizing border type options
    foreach (wppb_bordertype_options() as $stuff => $opt) {
        if (!isset($input[$opt])) {
            $input[$opt] = '';
        }
        // Loop through all variations
        foreach (wppb_bordertype_variations() as $variation) {
            if ($input[$opt] == $variation) {
                $wppb_design_settings[$opt] = $input[$opt];
            }
        }
        // If no variation selected, then default to "solid"
        if (!isset($wppb_design_settings[$opt])) {
            $wppb_design_settings[$opt] = '';
        }
        if ('' == $wppb_design_settings[$opt]) {
            $wppb_design_settings[$opt] = 'solid';
        }
    }
    // Sanitizing font style options
    foreach (wppb_fontstyle_options() as $stuff => $opt) {
        if (!isset($input[$opt])) {
            $input[$opt] = '';
        }
        if ('normal' == $input[$opt] || 'italic' == $input[$opt] || 'inherit' == $input[$opt]) {
            $wppb_design_settings[$opt] = $input[$opt];
        } else {
            $wppb_design_settings[$opt] = 'normal';
        }
    }
    // Sanitizing raw text options
    foreach (wppb_rawtext_options() as $stuff => $opt) {
        if (!isset($input[$opt])) {
            $input[$opt] = '';
        }
        // Allows some HTML, and converts quote marks to ensure they don't screw up quote marks in input fields
        $wppb_design_settings[$opt] = str_replace("'", '"', wp_kses($input[$opt], pixopoint_limited_html(), ''));
    }
    // Sanitizing raw text options
    foreach (wppb_rawhtml_options() as $stuff => $opt) {
        if (!isset($input[$opt])) {
            $input[$opt] = '';
        }
        // Allows some HTML, and converts quote marks to ensure they don't screw up quote marks in input fields
        $wppb_design_settings[$opt] = wp_kses($input[$opt], pixopoint_allowed_html(), '');
    }
    return $wppb_design_settings;
}