public function get_wrappers_select_options_for_mirroring() { $wrappers = HeadwayWrappers::get_all_wrappers(); $options = array('' => '– Do Not Mirror –'); //If there are no blocks, then just return the Do Not Mirror option. if (empty($wrappers) || !is_array($wrappers)) { return $options; } foreach ($wrappers as $wrapper_id => $wrapper_settings) { /* If we can't get a name for the layout, then things probably aren't looking good. Just skip this wrapper. */ if (!($layout_name = HeadwayLayout::get_name($wrapper_settings['layout']))) { continue; } /* Check for mirroring here */ if (HeadwayWrappers::get_wrapper_mirror($wrapper_settings)) { continue; } $current_layout_suffix = $this->wrapper['layout'] == $wrapper_settings['layout'] ? ' (Warning: Same Layout)' : null; $wrapper_alias = headway_get('alias', $wrapper_settings) ? ' – ' . headway_get('alias', $wrapper_settings) : null; //Get alias if it exists, otherwise use the default name $options[$wrapper_id] = 'Wrapper #' . HeadwayWrappers::format_wrapper_id($wrapper_id) . $wrapper_alias . ' – ' . $layout_name . $current_layout_suffix; } //Remove the current wrapper from the list unset($options[$this->wrapper['id']]); return $options; }
public static function init_action($block_id, $block = false) { if (!$block) { $block = HeadwayBlocksData::get_block($block_id); } $name = HeadwayBlocksData::get_block_name($block) . ' — ' . 'Layout: ' . HeadwayLayout::get_name($block['layout']); register_nav_menu('navigation_block_' . $block_id, $name); wp_register_script('jquery-hoverintent', headway_url() . '/library/media/js/jquery.hoverintent.js', array('jquery')); }
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 clone_pages_select_walker($pages, $depth = 0) { $return = ''; foreach ($pages as $id => $children) { $layout_id_fragments = explode('-', $id); $status = HeadwayLayout::get_status($id); /* Take care of layouts that are the front page or blog index */ if (get_option('show_on_front') === 'page' && (isset($layout_id_fragments[1]) && $layout_id_fragments[1] == 'page')) { /* If the page is set as the static homepage or blog page, hide it if they don't have children. */ if (end($layout_id_fragments) == get_option('page_on_front') || end($layout_id_fragments) == get_option('page_for_posts')) { /* Layout has children--add the no edit class and has children class. */ if (is_array($children) && count($children) !== 0) { $disabled = true; } else { continue; } } } /* Handle layouts that aren't customized or have a template */ if (headway_get('customized', $status, false) === false || headway_get('template', $status, false) !== false) { /* If there ARE customized children, add the no-edit class */ if (is_array($children) && count($children) !== 0) { /* Check if the children are customized. */ if (HeadwayVisualEditorDisplay::is_any_layout_child_customized($children)) { $disabled = true; } else { continue; } /* If there aren't any children, do not display the node at all */ } else { continue; } } /* If the current layout is selected, then make it disabled. */ if (headway_post('layout') == $id) { $disabled = true; } /* Output Stuff */ $depth_display = str_repeat(' ', $depth); $disabled = isset($disabled) && $disabled === true ? ' disabled="disabled"' : null; $return .= '<option value="' . $id . '"' . $disabled . '>' . $depth_display . HeadwayLayout::get_name($id) . '</option>'; if (is_array($children) && count($children) !== 0) { $return .= self::clone_pages_select_walker($children, $depth + 1); } } return $return; }
public static function register_element_instance($args) { if (!is_array($args)) { return new WP_Error('hw_elements_register_element_instance_args_not_array', __('Error: Arguments must be an array for this element instance.', 'headway'), $args); } $defaults = array('group' => null, 'grandparent' => null, 'element' => null, 'id' => null, 'name' => null, 'selector' => null, 'layout' => null, 'state-of' => null); $item = array_merge($defaults, $args); //If requirements are not met, throw errors if (!$item['id']) { return new WP_Error('hw_elements_register_element_instance_no_id', __('Error: An ID is required for this element instance.', 'headway'), $item); } if (!$item['name']) { return new WP_Error('hw_elements_register_element_instance_no_name', __('Error: A name is required for this element instance.', 'headway'), $item); } if ($item['group'] === null) { return new WP_Error('hw_elements_register_element_instance_no_group', __('Error: A group is required for this element instance.', 'headway'), $item); } if ($item['element'] === null) { return new WP_Error('hw_elements_register_element_instance_no_parent', __('Error: A parent element is required for this element instance.', 'headway'), $item); } if ($item['selector'] === null) { return new WP_Error('hw_elements_register_element_instance_no_selector', __('Error: A CSS selector is required for this element instance.', 'headway'), $item); } //If layout is set, then set layout-name as well if ($item['layout']) { $item['layout-name'] = HeadwayLayout::get_name($item['layout']); } //Figure out where the element will go in the elements array if ($item['grandparent'] !== null && isset(self::$elements[$item['group']][$item['grandparent']]['children'][$item['element']])) { $destination =& self::$elements[$item['group']][$item['grandparent']]['children'][$item['element']]; } else { if (isset(self::$elements[$item['group']][$item['element']])) { $destination =& self::$elements[$item['group']][$item['element']]; } else { return false; } } //Make sure that the element supports instances if (!headway_get('supports-instances', $destination)) { return false; } $destination =& $destination['instances'][$item['id']]; //Add the guts $destination = $item; //Add the instance to element paths so we can look the parent, grandparent and group up self::$element_paths[$item['id']] = array('group' => $item['group'], 'parent' => $item['element'], 'grandparent' => $item['grandparent']); //Remove the extra options unset($destination['element']); unset($destination['grandparent']); unset($destination['group']); //The element instance is now registered! return $destination; }
public static function init_action($block_id, $block) { $widget_area_name = HeadwayBlocksData::get_block_name($block) . ' — ' . 'Layout: ' . HeadwayLayout::get_name($block['layout']); $widget_area = array('name' => $widget_area_name, 'id' => 'widget-area-' . $block['id'], 'before_widget' => '<li id="%1$s" class="widget %2$s">' . "\n", 'after_widget' => '</li><!-- .widget -->' . "\n", 'before_title' => '<span class="widget-title">', 'after_title' => '</span>' . "\n"); register_sidebar($widget_area); }
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 export_layout($layout_id) { /* Set up variables */ if (!($layout_name = HeadwayLayout::get_name($layout_id))) { die('Error: Invalid layout.'); } $layout = array('name' => $layout_name, 'blocks' => HeadwayBlocksData::get_blocks_by_layout($layout_id)); /* Convert all mirrored blocks into original blocks by pulling their mirror target's settings */ /* Loop through each block in the template and check if it's mirrored. If it is, replace it with the block that it's mirroring */ foreach ($layout['blocks'] as $layout_block_index => $layout_block) { if (!($mirrored_block = HeadwayBlocksData::is_block_mirrored($layout_block))) { continue; } $layout['blocks'][$layout_block_index] = $mirrored_block; } /* Spit the file out */ return self::to_json('Headway Layout - ' . $layout_name, 'layout', $layout); }
public static function list_templates() { $templates = HeadwayLayout::get_templates(); $return = ''; $return .= '<ul>' . "\n"; $no_templates_display = count($templates) === 0 ? null : ' style="display:none;"'; $return .= '<li class="layout-item info-layout-item" id="no-templates"' . $no_templates_display . '><span class="layout"><strong>There are no templates to display, add one!</strong></span></li>'; foreach ($templates as $id => $name) { $class = array('layout-item'); $class[] = $id === headway_post('currentLayout') ? 'layout-selected' : null; //Output stuff $return .= "\n" . '<li class="' . implode(' ', array_filter($class)) . '">' . "\n"; $return .= "\n" . ' <span data-layout-id="template-' . $id . '" class="layout layout-template"> <strong class="template-name">' . HeadwayLayout::get_name('template-' . $id) . '</strong> <span class="delete-template" title="Delete Template">Delete</span> <span class="status status-currently-editing">Currently Editing</span> <span class="assign-template layout-selector-button">Use Template</span> <span class="edit layout-selector-button">Edit</span> </span>' . "\n"; $return .= '</li>' . "\n"; } $return .= '</ul>' . "\n"; return $return; }
public static function secure_method_assign_template() { $layout = headway_post('layout'); $template = str_replace('template-', '', headway_post('template')); //Add the template flag HeadwayLayoutOption::set($layout, 'template', $template); do_action('headway_visual_editor_assign_template'); echo HeadwayLayout::get_name('template-' . $template); }