public static function display_grid_blocks($blocks, $wrapper) { echo '<div class="grid-container">'; if (is_array($blocks)) { foreach ($blocks as $block_id => $block) { HeadwayBlocks::display_block($block, 'grid'); } } /* Mirrored wrapper notice */ $mirror_wrapper_id = HeadwayWrappers::format_wrapper_id(headway_get('mirror-wrapper', $wrapper)); $mirror_wrapper = $mirror_wrapper_id ? HeadwayWrappers::get_wrapper($mirror_wrapper_id) : null; $mirror_wrapper_layout = $mirror_wrapper ? HeadwayLayout::get_name(headway_get('layout', $mirror_wrapper)) : null; $mirror_wrapper_alias = headway_get('alias', $mirror_wrapper) ? '(' . headway_get('alias', $mirror_wrapper) . ')' : null; echo '<div class="wrapper-mirror-notice"> <div> <h2>Wrapper Mirrored</h2> <p>This wrapper is mirroring the blocks from Wrapper #<span class="wrapper-mirror-notice-id">' . $mirror_wrapper_id . '</span> <span class="wrapper-mirror-notice-alias">' . $mirror_wrapper_alias . '</span> <span class="wrapper-mirror-notice-layout">from "' . $mirror_wrapper_layout . '" layout</span></p> <small>Mirroring can be disabled via Wrapper Options in the right-click menu</small> </div> </div><!-- .wrapper-mirror-notice -->'; /* End mirrored wrapper notice */ echo '</div><!-- .grid-container -->'; }
public function get_blocks_select_options_for_mirroring() { $block_type = $this->block['type']; $blocks = HeadwayBlocksData::get_blocks_by_type($block_type); $options = array('' => '– Do Not Mirror –'); //If there are no blocks, then just return the Do Not Mirror option. if (!isset($blocks) || !is_array($blocks)) { return $options; } foreach ($blocks as $block_id => $layout_id) { //Get the block instance $block = HeadwayBlocksData::get_block($block_id); //If the block is mirrored, skip it if (HeadwayBlocksData::is_block_mirrored($block)) { continue; } /* Do not show block that's in a mirrored wrapper */ if (HeadwayWrappers::get_wrapper_mirror(HeadwayWrappers::get_wrapper(headway_get('wrapper', $block)))) { continue; } //Create the default name by using the block type and ID $default_name = HeadwayBlocks::block_type_nice($block['type']) . ' #' . $block['id']; //If we can't get a name for the layout, then things probably aren't looking good. Just skip this block. if (!($layout_name = HeadwayLayout::get_name($layout_id))) { continue; } //Make sure the block exists if (!HeadwayBlocksData::block_exists($block['id'])) { continue; } $current_layout_suffix = $this->block['layout'] == $layout_id ? ' (Warning: Same Layout)' : null; //Get alias if it exists, otherwise use the default name $options[$block['id']] = headway_get('alias', $block['settings'], $default_name) . ' – ' . $layout_name . $current_layout_suffix; } //Remove the current block from the list unset($options[$this->block['id']]); return $options; }
static function get_blocks_select_options_for_mirroring($block_type) { $return = ''; $blocks = HeadwayBlocksData::get_blocks_by_type($block_type); //If there are no blocks, then just return the Do Not Mirror option. if (!isset($blocks) || !is_array($blocks)) { return $return; } foreach ($blocks as $block_id => $layout_id) { //Get the block instance $block = HeadwayBlocksData::get_block($block_id); //If the block is mirrored, skip it if (headway_get('mirror-block', $block['settings'], false)) { continue; } //If the block is in the same layout as the current block, then do not allow it to be used as a block to mirror. if ($layout_id == headway_post('layout')) { continue; } //Create the default name by using the block type and ID $default_name = HeadwayBlocks::block_type_nice($block['type']) . ' #' . $block['id']; //If we can't get a name for the layout, then things probably aren't looking good. Just skip this block. if (!($layout_name = HeadwayLayout::get_name($layout_id))) { continue; } //Get alias if it exists, otherwise use the default name $return .= '<option value="' . $block['id'] . '">' . headway_get('alias', $block['settings'], $default_name) . ' – ' . $layout_name . '</option>'; } return $return; }
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 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 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 function render_grid() { $this->process(); echo '<div class="grid-container clearfix">' . "\n"; do_action('headway_grid_container_open', $this->wrapper); foreach ($this->finalized_layout as $row_index => $row) { echo '<section class="' . implode(' ', array_unique(array_filter($row['classes']))) . '">' . "\n"; do_action('headway_block_row_open', $this->wrapper); foreach ($row['columns'] as $column_index => $column) { echo '<section class="' . implode(' ', array_unique(array_filter($column['classes']))) . '">' . "\n"; do_action('headway_block_column_open', $this->wrapper); foreach ($column['contents'] as $index => $block_or_sub_column) { if (headway_get('type', $block_or_sub_column) == 'block') { HeadwayBlocks::display_block(headway_get('block', $block_or_sub_column), 'grid-renderer'); } elseif (headway_get('type', $block_or_sub_column) == 'sub-column') { echo '<section class="' . implode(' ', array_unique(array_filter($block_or_sub_column['classes']))) . '">'; do_action('headway_block_sub_column_open', $this->wrapper); foreach ($block_or_sub_column['blocks'] as $sub_block) { HeadwayBlocks::display_block($sub_block, 'grid-renderer'); } do_action('headway_block_sub_column_column', $this->wrapper); echo '</section><!-- .sub-column -->'; } } do_action('headway_block_column_close', $this->wrapper); echo '</section><!-- .column -->'; } do_action('headway_block_row_close', $this->wrapper); echo '</section><!-- .row -->' . "\n\n"; } do_action('headway_grid_container_close', $this->wrapper); echo '</div><!-- .grid-container -->' . "\n\n"; }
public static function method_clear_cache() { if (HeadwayCompiler::flush_cache(true) && HeadwayBlocks::clear_block_actions_cache()) { echo 'success'; } else { echo 'failure'; } }