/** * Renders the sidebar commander on post/page editor. * * @since 0.1.0 */ public function theme_meta_box_widget_areas($post, $args) { // Retrieve our custom meta box values $pc_primary_widget_areas = get_post_meta($post->ID, '_' . PC_THEME_NAME_SLUG . '_primary_sort', true); $pc_secondary_widget_areas = get_post_meta($post->ID, '_' . PC_THEME_NAME_SLUG . '_secondary_sort', true); $pc_main_content_widget_areas = get_post_meta($post->ID, '_' . PC_THEME_NAME_SLUG . '_main_content_sort', true); $pc_theme_widget_areas_save = get_post_meta($post->ID, '_' . PC_THEME_NAME_SLUG . '_widget_areas_save', true); ?> <script type="text/javascript"> jQuery(document).ready(function($) { // Enable jQuery UI tabs jQuery(document).ready(function($) { $(".tabs").tabs(); }); // Set-up sortable and placeholders for sidebar commander $( "#primary_widget_areas, #secondary_widget_areas, #main_content_widget_areas" ).sortable({ placeholder: "ui-state-highlight" }); // Make sure the link text can' be selected whilst dragging $( "#primary_widget_areas, #secondary_widget_areas, #main_content_widget_areas" ).disableSelection(); // When page loads set the initial opacity of checked checkboxes to 100% $("input:checkbox:checked").parent( 'li' ).each(function (i) { if(jQuery.support.opacity) { $(this).css("opacity", "1"); } else { this.style.filter = "alpha(opacity=100)"; // IE fix } }); // When page loads set the initial opacity of unchecked checkboxes to 30% $("input:checkbox:not(:checked)").parent( 'li' ).each(function (i) { if(jQuery.support.opacity) { $(this).css("opacity", "0.30"); } else { this.style.filter = "alpha(opacity=30)"; // IE fix } }); // When a checkbox is clicked, toggle the opacity $("input:checkbox").click(function () { if( this.checked ) { $(this).parent( 'li' ).css("opacity", "1"); } else { $(this).parent( 'li' ).css("opacity", "0.30"); } }); }); </script> <?php // Get column layout for this post/page $pc_column_layout = get_post_meta($post->ID, '_' . PC_THEME_NAME_SLUG . '_column_layout', true); // Get the page template used by this page (if a page) if ($args['args']['type'] == "page") { $pc_page_template = get_post_meta(get_the_ID(), '_wp_page_template', true); } $options = get_option(PC_OPTIONS_DB_NAME); if (empty($pc_column_layout) || $pc_column_layout == 'default') { $layout = $options[PC_DEFAULT_LAYOUT_THEME_OPTION]; } else { $layout = $pc_column_layout; } $layout_text_after = ""; //$layout_text_after = " is indicated by the icon to the left.<br /><br />"; if ($layout == "1-col") { // Define the layout icons to show on each visible tab $main_content_layout_icon = PC_THEME_ROOT_URI . '/api/images/layout-icons/full.png'; // Define the layout text $main_content_layout_text = ""; //$main_content_layout_text = "The <span class=\"underline\">main content</span> location for this ".$args['args']['type']." with the current layout (1-col, full width) "; } elseif ($layout == "2-col-l") { // Define the layout icons to show on each visible tab $primary_layout_icon = PC_THEME_ROOT_URI . '/api/images/layout-icons/primary-left.png'; $main_content_layout_icon = PC_THEME_ROOT_URI . '/api/images/layout-icons/main-right.png'; // Define the layout text $primary_layout_text = ""; $main_content_layout_text = ""; //$primary_layout_text = "The <span class=\"underline\">primary</span> sidebar location for this ".$args['args']['type']." with the current layout (2-col, sidebar left) "; //$main_content_layout_text = "The <span class=\"underline\">main content</span> location for this ".$args['args']['type']." with the current layout (2-col, sidebar left) "; } elseif ($layout == "2-col-r") { // Define the layout icons to show on each visible tab $primary_layout_icon = PC_THEME_ROOT_URI . '/api/images/layout-icons/primary-right.png'; $main_content_layout_icon = PC_THEME_ROOT_URI . '/api/images/layout-icons/main-left.png'; // Define the layout text $primary_layout_text = ""; $main_content_layout_text = ""; //$primary_layout_text = "The <span class=\"underline\">primary</span> sidebar location for this ".$args['args']['type']." with the current layout (2-col, sidebar right) "; //$main_content_layout_text = "The <span class=\"underline\">main content</span> location for this ".$args['args']['type']." with the current layout (2-col, sidebar right) "; } elseif ($layout == "3-col-l") { // Define the layout icons to show on each visible tab $primary_layout_icon = PC_THEME_ROOT_URI . '/api/images/layout-icons/3col-left.png'; $secondary_layout_icon = PC_THEME_ROOT_URI . '/api/images/layout-icons/3col-left1.png'; $main_content_layout_icon = PC_THEME_ROOT_URI . '/api/images/layout-icons/3col-main-right.png'; // Define the layout text $primary_layout_text = ""; $secondary_layout_text = ""; $main_content_layout_text = ""; //$primary_layout_text = "The <span class=\"underline\">primary</span> sidebar location for this ".$args['args']['type']." with the current layout (3-col, sidebars left) "; //$secondary_layout_text = "The <span class=\"underline\">secondary</span> sidebar location for this ".$args['args']['type']." with the current layout (3-col, sidebars left) "; //$main_content_layout_text = "The <span class=\"underline\">main content</span> location for this ".$args['args']['type']." with the current layout (3-col, sidebars left) "; } elseif ($layout == "3-col-r") { // Define the layout icons to show on each visible tab $primary_layout_icon = PC_THEME_ROOT_URI . '/api/images/layout-icons/3col-middle1.png'; $secondary_layout_icon = PC_THEME_ROOT_URI . '/api/images/layout-icons/3col-right.png'; $main_content_layout_icon = PC_THEME_ROOT_URI . '/api/images/layout-icons/3col-main-left.png'; // Define the layout text $primary_layout_text = ""; $secondary_layout_text = ""; $main_content_layout_text = ""; //$primary_layout_text = "The <span class=\"underline\">primary</span> sidebar location for this ".$args['args']['type']." with the current layout (3-col, sidebars right) "; //$secondary_layout_text = "The <span class=\"underline\">secondary</span> sidebar location for this ".$args['args']['type']." with the current layout (3-col, sidebars right) "; //$main_content_layout_text = "The <span class=\"underline\">main content</span> location for this ".$args['args']['type']." with the current layout (3-col, sidebars right) "; } else { // Layout must be 3-col-c // Define the layout icons to show on each visible tab $primary_layout_icon = PC_THEME_ROOT_URI . '/api/images/layout-icons/3col-left-2.png'; $secondary_layout_icon = PC_THEME_ROOT_URI . '/api/images/layout-icons/3col-right-2.png'; $main_content_layout_icon = PC_THEME_ROOT_URI . '/api/images/layout-icons/3col-main-middle.png'; // Define the layout text $primary_layout_text = ""; $secondary_layout_text = ""; $main_content_layout_text = ""; //$primary_layout_text = "The <span class=\"underline\">primary</span> sidebar location for this ".$args['args']['type']." with the current layout (3-col, content center) "; //$secondary_layout_text = "The <span class=\"underline\">secondary</span> sidebar location for this ".$args['args']['type']." with the current layout (3-col, content center) "; //$main_content_layout_text = "The <span class=\"underline\">main content</span> location for this ".$args['args']['type']." with the current layout (3-col, content center) "; } // Reference the global widget area variable here so we can access it global $wp_registered_sidebars; $tmp_primary_wp_registered_sidebars = $wp_registered_sidebars; // store a primary copy $tmp_secondary_wp_registered_sidebars = $wp_registered_sidebars; // store a secondary copy $tmp_main_content_wp_registered_sidebars = $wp_registered_sidebars; // store a main content copy ?> <div id="page-sidebar-commander"> <div class="tabs"> <?php // Set this to null if not defined to suppress 'not defined' error notices if (!isset($pc_page_template)) { $pc_page_template = null; } // Display message if there are no sidebars or main content areas available if ($layout == "1-col" && $pc_page_template != "widgetized-page.php") { echo "This " . $args['args']['type'] . " has no sidebars, so no unique widget areas can be defined here. Select a two or three column layout to be able to edit sidebar widget areas."; } else { // Show the tabs ?> <!-- the tabs --> <ul> <?php if ($layout != "1-col") { ?> <li><a href="#tabs-primary"><?php _e('Primary Sidebar', 'presscoders'); ?> </a></li> <?php } ?> <?php if ($pc_page_template == "widgetized-page.php") { ?> <li><a href="#tabs-maincontent"><?php _e('Main Content Area', 'presscoders'); ?> </a></li> <?php } ?> <?php if ($layout == "3-col-l" || $layout == "3-col-r" || $layout == "3-col-c") { ?> <li><a href="#tabs-secondary"><?php _e('Secondary Sidebar', 'presscoders'); ?> </a></li> <?php } ?> </ul> <?php } ?> <?php // ** PRIMARY SIDEBAR WIDGET AREAS ** ?> <?php if ($layout != "1-col") { // %1$s $msg = sprintf(__('%1$s%2$sAdd any widget area to the %3$sprimary%4$s sidebar of this %5$s by clicking the checkboxes. Drag and drop to dynamically reorder them. %6$sThe content for each widget area is controlled on the %7$sWidgets%8$s page.', 'presscoders'), $primary_layout_text, $layout_text_after, '<span class="underline">', '</span>', $args['args']['type'], '<br/><br/>', '<a href="' . get_admin_url(null, 'widgets.php') . '">', '</a>'); ?> <div id="tabs-primary"> <ul id="primary_widget_areas"> <?php // Create array with some entries to exclude from widget areas list $exclude_from_primary = array('secondary-post-widget-area', 'secondary-page-widget-area', 'header-widget-area', 'footer-widget-area'); // To avoid confusion, remove secondary sidebars on the primary sidebar list foreach ($exclude_from_primary as $exclude) { if (isset($tmp_primary_wp_registered_sidebars[$exclude])) { unset($tmp_primary_wp_registered_sidebars[$exclude]); } } // Now sort array before printing it if (!empty($pc_primary_widget_areas)) { $tmp_primary_wp_registered_sidebars = PC_Utility::sortMultiArrayByArray($tmp_primary_wp_registered_sidebars, $pc_primary_widget_areas); } if (is_array($tmp_primary_wp_registered_sidebars)) { foreach ($tmp_primary_wp_registered_sidebars as $tmp_primary_wp_registered_sidebar) { // Only show widget areas with a width of 'normal' if ($tmp_primary_wp_registered_sidebar['width'] != "normal") { continue; } if (isset($pc_primary_widget_areas[$tmp_primary_wp_registered_sidebar['id']])) { $chk = checked('1', esc_attr($pc_primary_widget_areas[$tmp_primary_wp_registered_sidebar['id']]), false); } else { $chk = ''; } echo '<li class="ui-state-default"><input type="checkbox" name="' . PC_THEME_NAME_SLUG . '_primary_sort[' . $tmp_primary_wp_registered_sidebar['id'] . ']" id="' . PC_THEME_NAME_SLUG . '_primary_sort[' . $tmp_primary_wp_registered_sidebar['id'] . ']" value="1" ' . $chk . '><label for="' . PC_THEME_NAME_SLUG . '_primary_sort[' . $tmp_primary_wp_registered_sidebar['id'] . ']">' . $tmp_primary_wp_registered_sidebar['name'] . '</label></li>'; } } ?> </ul> <p class="column_message"><img class="layouticon" src="<?php echo $primary_layout_icon; ?> " /><?php echo $msg; ?> </p> </div><!-- #tabs-primary --> <?php } ?> <?php // ** MAIN CONTENT SIDEBAR WIDGET AREAS ** ?> <?php if ($pc_page_template == "widgetized-page.php") { $msg = sprintf(__('%1$s%2$sAdd any widget area to the %3$smain content%4$s area of this %5$s by clicking the checkboxes. Drag and drop to dynamically reorder them. %6$sThe content for each widget area is controlled on the %7$sWidgets%8$s page.', 'presscoders'), $main_content_layout_text, $layout_text_after, '<span class="underline">', '</span>', $args['args']['type'], '<br/><br/>', '<a href="' . get_admin_url(null, 'widgets.php') . '">', '</a>'); ?> <div id="tabs-maincontent"> <ul id="main_content_widget_areas"> <?php // Create array with some entries to exclude from widget areas list //$exclude_from_main_content = array('primary-post-widget-area', 'primary-page-widget-area', 'secondary-post-widget-area', 'secondary-page-widget-area'); // To avoid confusion, remove secondary sidebars on the primary sidebar list /*foreach($exclude_from_main_content as $exclude) { if( isset($tmp_main_content_wp_registered_sidebars[$exclude]) ) { unset($tmp_main_content_wp_registered_sidebars[$exclude]); } }*/ // Now sort array before printing it if (!empty($pc_main_content_widget_areas)) { $tmp_main_content_wp_registered_sidebars = PC_Utility::sortMultiArrayByArray($tmp_main_content_wp_registered_sidebars, $pc_main_content_widget_areas); } if (is_array($tmp_main_content_wp_registered_sidebars)) { foreach ($tmp_main_content_wp_registered_sidebars as $tmp_main_content_wp_registered_sidebar) { // Only show widget areas with a width of 'wide' if ($tmp_main_content_wp_registered_sidebar['width'] != "wide") { continue; } if (isset($pc_main_content_widget_areas[$tmp_main_content_wp_registered_sidebar['id']])) { $chk = checked('1', esc_attr($pc_main_content_widget_areas[$tmp_main_content_wp_registered_sidebar['id']]), false); } else { $chk = ''; } echo '<li class="ui-state-default"><input type="checkbox" name="' . PC_THEME_NAME_SLUG . '_main_content_sort[' . $tmp_main_content_wp_registered_sidebar['id'] . ']" id="' . PC_THEME_NAME_SLUG . '_main_content_sort[' . $tmp_main_content_wp_registered_sidebar['id'] . ']" value="1" ' . $chk . '><label for="' . PC_THEME_NAME_SLUG . '_main_content_sort[' . $tmp_main_content_wp_registered_sidebar['id'] . ']">' . $tmp_main_content_wp_registered_sidebar['name'] . '</label></li>'; } } ?> </ul> <p class="column_message"><img class="layouticon" src="<?php echo $main_content_layout_icon; ?> " /><?php echo $msg; ?> </p> </div><!-- #tabs-maincontent --> <?php } // endif ?> <?php // ** SECONDARY SIDEBAR WIDGET AREAS ** ?> <?php if ($layout == "3-col-l" || $layout == "3-col-r" || $layout == "3-col-c") { $msg = sprintf(__('%1$s%2$sAdd any widget area to the %3$ssecondary%4$s sidebar of this %5$s by clicking the checkboxes. Drag and drop to dynamically reorder them. %6$sThe content for each widget area is controlled on the %7$sWidgets%8$s page.', 'presscoders'), $secondary_layout_text, $layout_text_after, '<span class="underline">', '</span>', $args['args']['type'], '<br/><br/>', '<a href="' . get_admin_url(null, 'widgets.php') . '">', '</a>'); ?> <div id="tabs-secondary"> <ul id="secondary_widget_areas"> <?php // Create array with some entries to exclude from widget areas list $exclude_from_secondary = array('primary-post-widget-area', 'primary-page-widget-area', 'header-widget-area', 'footer-widget-area'); // To avoid confusion, remove secondary sidebars on the secondary sidebar list foreach ($exclude_from_secondary as $exclude) { if (isset($tmp_secondary_wp_registered_sidebars[$exclude])) { unset($tmp_secondary_wp_registered_sidebars[$exclude]); } } // Now sort array before printing it if (!empty($pc_secondary_widget_areas)) { $tmp_secondary_wp_registered_sidebars = PC_Utility::sortMultiArrayByArray($tmp_secondary_wp_registered_sidebars, $pc_secondary_widget_areas); } if (is_array($tmp_secondary_wp_registered_sidebars)) { foreach ($tmp_secondary_wp_registered_sidebars as $tmp_secondary_wp_registered_sidebar) { // Only show widget areas with a width of 'normal' if ($tmp_secondary_wp_registered_sidebar['width'] != "normal") { continue; } if (isset($pc_secondary_widget_areas[$tmp_secondary_wp_registered_sidebar['id']])) { $chk = checked('1', esc_attr($pc_secondary_widget_areas[$tmp_secondary_wp_registered_sidebar['id']]), false); } else { $chk = ''; } echo '<li class="ui-state-default"><input type="checkbox" name="' . PC_THEME_NAME_SLUG . '_secondary_sort[' . $tmp_secondary_wp_registered_sidebar['id'] . ']" id="' . PC_THEME_NAME_SLUG . '_secondary_sort[' . $tmp_secondary_wp_registered_sidebar['id'] . ']" value="1" ' . $chk . '><label for="' . PC_THEME_NAME_SLUG . '_secondary_sort[' . $tmp_secondary_wp_registered_sidebar['id'] . ']">' . $tmp_secondary_wp_registered_sidebar['name'] . '</label></li>'; } } ?> </ul> <p class="column_message"><img class="layouticon" src="<?php echo $secondary_layout_icon; ?> " /><?php echo $msg; ?> </p> </div><!-- #tabs-secondary --> <?php } ?> </div><!-- .tabs --> <input type="hidden" name="<?php echo PC_THEME_NAME_SLUG; ?> _widget_areas_save" id="<?php echo PC_THEME_NAME_SLUG; ?> _widget_areas_save" value="<?php echo esc_attr($pc_theme_widget_areas_save); ?> "> </div><!-- #page-sidebar-commander --> <?php }