/**
 * The Header for our theme.
 *
 * Displays all of the <head> section and everything up till <div id="content">
 *
 * @package Wall Street
 */
?>
<!DOCTYPE html>
<html <?php 
language_attributes();
?>
>
<?php 
global $theme_options;
$theme_options = get_option(gpp_get_current_theme_id() . '_options');
$header_image = get_header_image();
?>
<head>
<meta charset="<?php 
bloginfo('charset');
?>
">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title><?php 
wp_title('|', true, 'right');
?>
</title>
<?php 
if (isset($theme_options['wallstreet_custom_favicon']) && '' != $theme_options['wallstreet_custom_favicon']) {
/**
 * Sorting script
 */
function gpp_section_sortable()
{
    $screen = get_current_screen();
    if ($screen->id == 'appearance_page_gpp-settings') {
        $theme_options = get_option(gpp_get_current_theme_id() . '_options');
        if (!empty($theme_options['section_order'])) {
            $section_order = $theme_options['section_order'];
            $doc_ready_script = '
                <script type="text/javascript">
                    jQuery(document).ready(function(){
                        jQuery(".tab_section").append("<span class=\\"section_toggle\\"></span>");
                        var i = 0;
                        var stored_order = "' . $section_order . '";
                        var section_order = stored_order.split(",");
                        jQuery("#wpbody-content .form-table .section_order").parents(".form-table").hide().nextUntil(".button").wrapAll( "<div class=\\"sortable-options\\"></div>" );

                        // Wrap each sections into sortable blocks
                        jQuery(".sortable-options .tab_section").each(function(){
                            jQuery(this).parent().nextUntil("h3").addBack()
                            .wrapAll( "<div id=\\""+section_order[i]+"\\" class=\\"sortable-block\\"></div>" );
                            i++;
                        });

                        // Call the sorting function
                        jQuery( ".sortable-options" ).sortable({
                                placeholder: "sortable-placeholder",
                                handle: "h3",
                                forcePlaceholderSize: true,
                                start: function( event, ui ) {
                                        ui.placeholder.height("45px");
                                        ui.item.css({"height":"45px"}).find(".form-table").hide();
                                },
                                stop: function( event, ui ) {
                                    var newOrder = jQuery(this).sortable("toArray").toString();
                                    jQuery(".section_order").val(newOrder);
                                }
                            });

                        // Hide all settings at first
                        jQuery(".sortable-block").each(function(){
                            jQuery(this).find(".form-table").hide();
                        });

                        // Toggle content on click
                        jQuery("#wpbody-content").on("click", ".sortable-block h3", function(){
                            jQuery(this).parent().find(".form-table").toggle();
                        });
                    ';
            $doc_ready_script .= '
                    });
                </script>';
            echo $doc_ready_script;
        }
    }
}
/**
 * Bind JS handlers to make Theme Customizer preview reload changes asynchronously.
 * Used with fonts
 *
 * @since GPP Theme Options 1.0
 */
function gpp_customize_preview_js()
{
    $doc_ready_script = '
		<script type="text/javascript">
			(function($){
				wp.customize( "blogname", function( value ) {
					value.bind( function( to ) {
						$( ".site-title a" ).html( to );
					});
				});

				wp.customize( "blogdescription", function( value ) {
					value.bind( function( to ) {
						$( ".site-description" ).html( to );
					});
				});

				wp.customize( "header_textcolor", function( value ) {
					value.bind( function( to ) {
						$( ".site-title a, .site-description" ).css( "cssText", "color: " + to + " !important;" );
					});
				});

				wp.customize( "' . gpp_get_current_theme_id() . '_options[logo]", function( value ) {
					value.bind( function( to ) {
						$( ".site-title a" ).html( "<img class=\\"sitetitle\\" alt=\\"' . get_bloginfo('name') . '\\" src=\\"" + to + "\\">" );
					});
				});

				wp.customize("' . gpp_get_current_theme_id() . '_options[font]",function(value) {
					value.bind(function(to) {
						$("#fontdiv").remove();
						var googlefont = to.split(",");
						var n = googlefont[0].indexOf(":");
						googlefontfamily = googlefont[0].substring(0, n != -1 ? n : googlefont[0].length);
						$("body").append("<div id=\\"fontdiv\\"><link href=\\"http://fonts.googleapis.com/css?family="+googlefont[0]+"\\" rel=\\"stylesheet\\" type=\\"text/css\\" /><style type=\\"text/css\\">	h1, h2, h3, h4, h5, h6, ul.menu li a {font-family: \\""+googlefontfamily+"\\";}</style></div>");
					});
				});

				wp.customize("' . gpp_get_current_theme_id() . '_options[font_alt]",function(value) {
					value.bind(function(to) {
						$("#fontaltdiv").remove();
						var googlefont = to.split(",");
						var n = googlefont[0].indexOf(":");
						googlefontfamily = googlefont[0].substring(0, n != -1 ? n : googlefont[0].length);
						$("body").append("<div id=\\"fontaltdiv\\"><link href=\\"http://fonts.googleapis.com/css?family="+googlefont[0]+"\\" rel=\\"stylesheet\\" type=\\"text/css\\" /><style type=\\"text/css\\">	body, p, h2.site-description {font-family: \\""+googlefontfamily+"\\";}</style></div>");
					});
				});

				wp.customize( "' . gpp_get_current_theme_id() . '_options[color]", function( value ) {
					value.bind( function( to ) {
						$( "#gpp-alt-style-css" ).attr( "href", "' . get_stylesheet_directory_uri() . '/css/" + to + ".css" );
					});
				});

				wp.customize( "' . gpp_get_current_theme_id() . '_options[css]", function( value ) {
					value.bind( function( to ) {
						$( "#tempcss" ).remove();
						var googlefont = to.split( "," );
						$( "body" ).append( "<div id=\\"tempcss\\"><style type=\\"text/css\\">" + to + "</style></div>" );
					});
				});

			})( jQuery );
		</script>';
    echo $doc_ready_script;
}
<?php

/**
 * Register Theme Settings
 *
 * Register theme options array to hold all theme options.
 *
 * @link	http://codex.wordpress.org/Function_Reference/register_setting	Codex Reference: register_setting()
 *
 * @param	string		$option_group		Unique Settings API identifier; passed to settings_fields() call
 * @param	string		$option_name		Name of the wp_options database table entry
 * @param	callback	$sanitize_callback	Name of the callback function in which user input data are sanitized
 */
register_setting(gpp_get_current_theme_id() . '_options', gpp_get_current_theme_id() . '_options', 'gpp_options_validate');
/**
 * Register Global Admin Javascript Variables
 *
 * Register JS variables used by theme options admin Javascript.
 *
 * @global	array	Settings Page Tab definitions
 *
 */
function gpp_register_admin_js_globals()
{
    global $gpp_tabs;
    $tab = '';
    $selected_tab = '';
    $selected_tab = $selected_tab ? $gpp_tabs[0]['name'] : $tab;
    $themedata = wp_get_theme();
    $theme_title = $themedata->title;
    $theme_name = strtolower($theme_title);
/**
 * Check theme options for thumbnail orientation
 *
 * @since 1.0
 */
function wallstreet_image_orientation()
{
    if (get_option(gpp_get_current_theme_id() . '_options')) {
        $options = get_option(gpp_get_current_theme_id() . '_options');
        if (!empty($options['wallstreet_orientation']) && $options['wallstreet_orientation'] == 'vertical') {
            return 'vertical';
        } elseif (!empty($options['wallstreet_orientation']) && $options['wallstreet_orientation'] == 'horizontal') {
            return 'horizontal';
        } else {
            return 'square';
        }
    } else {
        return 'vertical';
    }
}
function gpp_field_gallery($value, $attr)
{
    $images = explode(',', $value);
    $imgarray = '';
    foreach ($images as $imageID) {
        $image = wp_get_attachment_image_src($imageID);
        $imgarray .= '<img class="eachthumbs" src="' . $image[0] . '" style="cursor:pointer;height:60px;width:auto;margin:5px 5px 0 0;"/>';
    }
    ?>

    <script language="javascript">
    jQuery(document).ready(function() {

        $container = jQuery("#<?php 
    echo $attr['name'];
    ?>
_container");
        $image_field = $container.find('.upload_gallery_field');
        $image_button = $container.find('.upload_gallery_button');
        $remove_button = $container.find('.gpp_gallery_remove');

        $image_button.click(function() {

            // WordPress 3.5 Media Pop Up

            var file_frame;

            // Create the media frame.
            file_frame = wp.media.frames.file_frame = wp.media({
                title: 'Select Images',
                button: {
                    text: 'Use Selected Images',
                },
                multiple: 'add'
            });

            // When an image is selected, run a callback.
            file_frame.on( 'select', function() {
                hiddenids = '';
                jQuery( '.upload_gallery_preview' ).html('');
                var selection = file_frame.state().get( 'selection' );
                selection.map( function( attachment ) {
                    attachment = attachment.toJSON();
                    hiddenids += attachment.id + ',';
                    $container.find( '.upload_gallery_preview' ).show();
                    jQuery( '.upload_gallery_preview' ).append( '<img style=\"cursor:pointer;height:60px;width:auto;margin:5px 5px 0 0;\" class=\'eachthumbs\' src=\"' + attachment.url + '\"/>' );
                });
                jQuery( '.upload_gallery_preview' ).append( '<br /><a href="javascript:void(0);" class="upload_gallery_remove">Remove</a>' );
                $container.find( '.upload_gallery_field' ).val( hiddenids.substring( 0, hiddenids.length - 1 ) ).show();
            });

            // open the modal
            file_frame.open();
            return false;
        });

        jQuery( '.upload_gallery_preview' ).on( 'click', '.eachthumbs', function() { // edit gallery
            var file_frame, selection;
            var hiddenids = '';

            var hiddenids = jQuery( '.upload_gallery_field' ).val();
            var gallerysc = '[gallery ids=' + hiddenids + ']';
            file_frame = wp.media.gallery.edit( gallerysc ); // need to replace [gallery] with actual shortcode
            file_frame.on( 'update', function( selection ) {
                jQuery( '.upload_gallery_preview' ).html( '<img src=\"" . site_url() . "/wp-includes/images/wpspin.gif" . "\" />' );
                var addedgallery = wp.media.gallery.shortcode( selection ).string();
                var idarray = addedgallery.split( '=\"' );
                datanew = idarray[1].substring( 0, idarray[1].length - 2 );

                jQuery.post( ajaxurl, { action: 'gpp_imageurl', ids: datanew, pid: jQuery( '.upload_gallery_field' ).val() }, function( response ) {
                    jQuery( '.upload_gallery_field' ).val( datanew );
                    jQuery( '.upload_gallery_preview' ).html( response );
                });

            });

            return false;
        });

        // remove image
        jQuery( '.upload_gallery_preview' ).on( 'click', '.upload_gallery_remove', function() {
            jQuery( '.upload_gallery_field' ).val( '' );
            jQuery( '.upload_gallery_preview' ).hide();
        });
        if ( jQuery( '.upload_gallery_field' ).val().length > 0 ) {
            jQuery( '.upload_gallery_preview' ).show();
        }
    });
    </script>

    <div id="<?php 
    echo $attr['name'];
    ?>
_container">
        <input type="hidden" class="upload_gallery_field" id="<?php 
    echo $attr['name'];
    ?>
" name="<?php 
    echo gpp_get_current_theme_id();
    ?>
_options[<?php 
    echo $attr['name'];
    ?>
]" value="<?php 
    echo $value;
    ?>
">
        <input class="upload_gallery_button button" type="button" value="<?php 
    _e('Upload or Select Images', 'gpp');
    ?>
" />
        <div class="upload_gallery_preview"><?php 
    if ('' != $value) {
        echo $imgarray;
        ?>
<br /><a href="javascript:void(0);" class="upload_gallery_remove"><?php 
        _e('Remove', 'gpp');
        ?>
</a><?php 
    }
    ?>
</div>
    </div>

<?php 
}
 * Define the Tabs appearing on the Theme Options page
 * Tabs contains sections
 * Options are assigned to both Tabs and Sections
 * See README.md for a full list of option types
 */
$general_settings_tab = array("name" => "general_tab", "title" => __("General", "gpp"), "sections" => array("general_section_1" => array("name" => "general_section_1", "title" => __("General", "gpp"), "description" => "")));
gpp_register_theme_option_tab($general_settings_tab);
$colors_tab = array("name" => "colors_tab", "title" => __("Colors", "gpp"), "sections" => array("colors_section_1" => array("name" => "colors_section_1", "title" => __("Colors", "gpp"), "description" => "")));
gpp_register_theme_option_tab($colors_tab);
$slideshow_tab = array("name" => "slideshow_tab", "title" => __("Slideshow", "gpp"), "sections" => array("slideshow_section_1" => array("name" => "slideshow_section_1", "title" => __("Slideshow", "gpp"), "description" => "")));
gpp_register_theme_option_tab($slideshow_tab);
// Default order of the sections in the particular tab
$block_order = explode(",", '1,2,3,4,5');
$block_array = array(1 => array("order" => "1", "title" => "Work", "icon" => "grid"), 2 => array("order" => "2", "title" => "Services", "icon" => "grid"), 3 => array("order" => "3", "title" => "Clients", "icon" => "gridh"), 4 => array("order" => "4", "title" => "Testimonials", "icon" => "staggered"), 5 => array("order" => "5", "title" => "News", "icon" => "text"));
// Get the order from the database
$theme_options = get_option(gpp_get_current_theme_id() . "_options");
if (!empty($theme_options['section_order'])) {
    $block_order = explode(",", $theme_options['section_order']);
}
/**
 * Home page tab
 */
$section_array = array("homepage_section_0" => array("name" => "homepage_section_0", "title" => __("Sortable Sections", "gpp"), "description" => ""));
// Arrange the sections according to saved order
foreach ($block_order as $value) {
    $section_array["homepage_section_" . $value] = array("name" => "homepage_section_" . $block_array[$value]['order'], "title" => $block_array[$value]['title'], "description" => "", "icon" => $block_array[$value]['icon']);
}
$homepage_tab = array("name" => "homepage_tab", "title" => __("Homepage", "gpp"), "sections" => $section_array);
gpp_register_theme_option_tab($homepage_tab);
/**
 * The following example shows you how to register theme options and assign them to tabs and sections: