static function block_heights() { if (!($blocks = HeadwayBlocksData::get_all_blocks())) { return false; } $return = ''; //Retrieve the blocks so we can check if the block type is fixed or fluid height $block_types = HeadwayBlocks::get_block_types(); foreach ($blocks as $block) { $selector = '#block-' . $block['id']; /* If the block is mirrored then change the selector */ if ($mirrored_block_id = HeadwayBlocksData::is_block_mirrored($block, true)) { $selector = '#block-' . $mirrored_block_id . '.block-original-' . $block['id']; } //If it's a fluid block (which blocks ARE by default), then we need to use min-height. Otherwise, if it's fixed, we use height. if (headway_get('fixed-height', headway_get($block['type'], $block_types), false) !== true) { $return .= $selector . ' { min-height: ' . $block['dimensions']['height'] . 'px; }'; } else { $return .= $selector . ' { height: ' . $block['dimensions']['height'] . 'px; }'; } } return $return; }
public static function block_type_selector() { $block_types = HeadwayBlocks::get_block_types(); echo "\n" . '<div class="block-type-selector block-type-selector-original" style="display: none;">' . "\n"; foreach ($block_types as $block_type_id => $block_type) { echo ' <div id="block-type-' . $block_type_id . '" class="block-type" title="' . $block_type['description'] . '"> <h4 style="background-image: url(' . $block_type['url'] . '/icon.png);">' . $block_type['name'] . '</h4> <div class="block-type-description"> <p>' . $block_type['description'] . '</p> </div> </div> '; } echo '</div><!-- div.block-type-selector -->' . "\n\n"; }
public static function display_block($block, $where = null) { //We'll allow this function to take either an integer argument to look up the block or to use the existing if (!is_array($block)) { $block = HeadwayBlocksData::get_block($block); } //Check that the block exists if (!is_array($block) || !$block) { return false; } $block_types = HeadwayBlocks::get_block_types(); //Set the original block for future use $original_block = $block; $original_block_id = $block['id']; //Set the block style to null so we don't get an ugly notice down the road if it's not used. $block_style_attr = null; //Check if the block type exists if (!($block_type_settings = headway_get($block['type'], $block_types, array()))) { $block['requested-type'] = $block['type']; $block['type'] = 'unknown'; } //Get the custom CSS classes and change commas to spaces and remove double spaces and remove HTML $custom_css_classes = str_replace(' ', ' ', str_replace(',', ' ', htmlspecialchars(strip_tags(headway_get('css-classes', $block['settings'], ''))))); $block_classes = array_unique(array_filter(explode(' ', $custom_css_classes))); $block_classes[] = 'block'; $block_classes[] = 'block-type-' . $block['type']; $block_classes[] = headway_get('fixed-height', $block_type_settings, false) !== true ? 'block-fluid-height' : 'block-fixed-height'; //Block Styles if (HEADWAY_CHILD_THEME_ACTIVE && ($block_style = headway_get(HEADWAY_CHILD_THEME_ID . '-block-style', $block['settings']))) { $block_style_classes = explode(' ', headway_get('class', headway_get($block_style, HeadwayChildThemeAPI::$block_styles))); foreach ($block_style_classes as $block_style_class) { $block_classes[] = $block_style_class; } } //If the block is being displayed in the Grid, then we need to make it work with absolute positioning. if ($where == 'grid') { $block_classes[] = 'grid-width-' . $original_block['dimensions']['width']; $block_classes[] = 'grid-left-' . $original_block['position']['left']; $block_style_attr = ' style="height: ' . $original_block['dimensions']['height'] . 'px; top: ' . $original_block['position']['top'] . 'px;"'; } //If the responsive grid is active, then add the responsive block hiding classes if (HeadwayResponsiveGrid::is_enabled()) { $responsive_block_hiding = headway_get('responsive-block-hiding', $block['settings'], array()); if (is_array($responsive_block_hiding) && count($responsive_block_hiding) > 0) { foreach ($responsive_block_hiding as $device) { $block_classes[] = 'responsive-block-hiding-device-' . $device; } } } //If it's a mirrored block, change $block to the mirrored block if ($mirrored_block = HeadwayBlocksData::is_block_mirrored($block)) { $block = $mirrored_block; $block['original'] = $original_block; //Add Classes for the mirroring $block_classes[] = 'block-mirrored'; if ($where != 'grid') { $block_classes[] = 'block-mirroring-' . $mirrored_block['id']; $block_classes[] = 'block-original-' . $original_block_id; } } //Fetch the HTML tag for the block $block_tag = ($html_tag = headway_get('html-tag', $block_type_settings)) ? $html_tag : 'div'; //The ID attribute for the block. This will change if mirrored. $block_id_for_id_attr = $block['id']; //Original block ID to be used in the Visual Editor if (HeadwayRoute::is_visual_editor_iframe()) { $block_data_attrs = implode(' ', array('data-id="' . str_replace('block-', '', $original_block_id) . '"', 'data-block-mirror="' . (isset($mirrored_block) ? $mirrored_block['id'] : '') . '"', 'data-block-mirror-layout-name="' . (isset($mirrored_block) ? HeadwayLayout::get_name($mirrored_block['layout']) : '') . '"', 'data-grid-left="' . $original_block['position']['left'] . '"', 'data-grid-top="' . $original_block['position']['top'] . '"', 'data-width="' . $original_block['dimensions']['width'] . '"', 'data-height="' . $original_block['dimensions']['height'] . '"', 'data-alias="' . headway_get('alias', headway_get('settings', $original_block, array())) . '"')); } else { $block_data_attrs = null; } //The grid will display blocks entirely differently and not use hooks. if ($where != 'grid') { do_action('headway_before_block', $block); do_action('headway_before_block_' . $block['id'], $block); echo '<' . $block_tag . ' id="block-' . $block_id_for_id_attr . '" class="' . implode(' ', array_filter(apply_filters('headway_block_class', $block_classes, $block))) . '"' . $block_style_attr . $block_data_attrs . '>'; do_action('headway_block_open', $block); do_action('headway_block_open_' . $block['id'], $block); echo '<div class="block-content">'; do_action('headway_block_content_open', $block); do_action('headway_block_content_open_' . $block['id'], $block); do_action('headway_block_content_' . $block['type'], $block); do_action('headway_block_content_close', $block); do_action('headway_block_content_close_' . $block['id'], $block); echo '</div><!-- .block-content -->' . "\n"; do_action('headway_block_close', $block); do_action('headway_block_close_' . $block['id'], $block); echo '</' . $block_tag . '><!-- #block-' . $block_id_for_id_attr . ' -->' . "\n"; do_action('headway_after_block', $block); do_action('headway_after_block_' . $block['id'], $block); //Show the block in the grid } else { $show_content_in_grid = self::block_type_exists($block['type']) ? headway_get('show-content-in-grid', $block_type_settings, false) : false; if (!$show_content_in_grid) { $block_classes[] = 'hide-content-in-grid'; } if (!self::block_type_exists($block['type'])) { $block_classes[] = 'block-error'; } echo '<' . $block_tag . ' id="block-' . $block_id_for_id_attr . '" class="' . implode(' ', array_filter($block_classes)) . '"' . $block_style_attr . $block_data_attrs . '>'; echo '<div class="block-content-fade block-content">'; if (!self::block_type_exists($block['type'])) { self::unknown_block_content($block); } else { if (!$show_content_in_grid) { echo '<p class="hide-content-in-grid-notice"><strong>Notice:</strong> <em>' . self::block_type_nice($block['type']) . '</em> blocks do not display in the Grid Mode. Please switch to the Design mode to see the content in this block.</p>'; } } echo '</div><!-- .block-content-fade -->' . "\n"; echo '</' . $block_tag . '><!-- #block-' . $block_id_for_id_attr . ' -->' . "\n"; } //Spit the ID back out return $block['id']; }
public static function method_load_block_content() { /* Check for grid safe mode */ if (HeadwayOption::get('grid-safe-mode', false, false)) { echo '<div class="alert alert-red block-safe-mode"><p>Grid Safe mode enabled. Block content not outputted.</p></div>'; return; } /* Go */ $layout = headway_post('layout'); $block_origin = headway_post('block_origin'); $block_default = headway_post('block_default', false); $unsaved_block_settings = headway_post('unsaved_block_settings', false); /* If the block origin is a string or ID, then get the object from DB. */ if (is_numeric($block_origin) || is_string($block_origin)) { $block = HeadwayBlocksData::get_block($block_origin); } else { $block = $block_origin; } /* If the block doesn't exist, then use the default as the origin. If the default doesn't exist... We're screwed. */ if (!$block && $block_default) { $block = $block_default; } /* If the block settings is an array, merge that into the origin. But first, make sure the settings exists for the origin. */ if (!isset($block['settings'])) { $block['settings'] = array(); } if (is_array($unsaved_block_settings) && count($unsaved_block_settings) && isset($unsaved_block_settings['settings'])) { $block = headway_array_merge_recursive_simple($block, $unsaved_block_settings); } /* If the block is set to mirror, then get that block. */ if ($mirrored_block = HeadwayBlocksData::is_block_mirrored($block)) { $original_block = $block; $block = $mirrored_block; $block['original'] = $original_block; } /* Add a flag into the block so we can check if this is coming from the visual editor. */ $block['ve-live-content-query'] = true; /* Show the content */ do_action('headway_block_content_' . $block['type'], $block); /* Output dynamic JS and CSS */ if (headway_post('mode') != 'grid') { $block_types = HeadwayBlocks::get_block_types(); /* Dynamic CSS */ if (method_exists($block_types[$block['type']]['class'], 'dynamic_css')) { echo '<style type="text/css">'; echo call_user_func(array($block_types[$block['type']]['class'], 'dynamic_css'), $block['id'], $block); echo '</style><!-- AJAX Block Content Dynamic CSS -->'; } /* Run enqueue action and print right away */ if (method_exists($block_types[$block['type']]['class'], 'enqueue_action')) { /* Remove all other enqueued scripts to reduce conflicts */ global $wp_scripts; $wp_scripts = null; remove_all_actions('wp_print_scripts'); /* Remove all other enqueued styles to reduce conflicts */ global $wp_styles; $wp_styles = null; remove_all_actions('wp_print_styles'); echo call_user_func(array($block_types[$block['type']]['class'], 'enqueue_action'), $block['id'], $block); wp_print_scripts(); wp_print_footer_scripts(); /* This isn't really needed, but it's here for juju power */ } /* Output dynamic JS */ if (method_exists($block_types[$block['type']]['class'], 'dynamic_js')) { echo '<script type="text/javascript">'; echo call_user_func(array($block_types[$block['type']]['class'], 'dynamic_js'), $block['id'], $block); echo '</script><!-- AJAX Block Content Dynamic JS -->'; } } /* End outputting dynamic JS and CSS */ }