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 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 responsive_grid(array $wrapper_settings) { global $wrapper_css_flags; /* If wrapper is mirrored then use settings from it for the grid */ if ($potential_wrapper_mirror = HeadwayWrappers::get_wrapper_mirror($wrapper_settings)) { $wrapper_settings = $potential_wrapper_mirror; } $round_precision = 9; $return = ''; $grid_number = headway_get('columns', $wrapper_settings); $column_width = headway_get('use-independent-grid', $wrapper_settings) ? headway_get('column-width', $wrapper_settings) : HeadwayOption::get('column-width', false, HeadwayWrappers::$default_column_width); $gutter_width = headway_get('use-independent-grid', $wrapper_settings) ? headway_get('gutter-width', $wrapper_settings) : HeadwayOption::get('gutter-width', false, HeadwayWrappers::$default_gutter_width); /* Render the Grid into arrays to see if sub column CSS will be needed */ $wrapper_blocks = HeadwayBlocksData::get_blocks_by_wrapper(headway_get('layout-in-use'), $wrapper_settings['id']); $wrapper_rendered = new HeadwayGridRenderer($wrapper_blocks, $wrapper_settings); /* Process the blocks into arrays */ $wrapper_rendered->process(); $blocks_in_sub_columns = !empty($wrapper_rendered->blocks_in_sub_columns) ? true : false; /* Keep extraneous CSS from be created by wrappers that have the same settings */ $grid_class = 'grid-fluid-' . $grid_number . '-' . $column_width . '-' . $gutter_width; /* If there are no sub columns and the main CSS has already been outputted, just stop here */ if (isset($wrapper_css_flags[$grid_class]) && !$blocks_in_sub_columns) { return; } /* End extraneous CSS check */ /* Make calculations for the percentages */ $grid_wrapper_width = $column_width * $grid_number + ($grid_number - 1) * $gutter_width; $resp_width_ratio = $column_width * $grid_number / $grid_wrapper_width; $resp_gutter_ratio = $gutter_width * $grid_number / $grid_wrapper_width; $resp_single_column_width = 100 / $grid_number * $resp_width_ratio; $resp_single_column_margin = 100 / $grid_number * $resp_gutter_ratio; /* Add CSS prefix */ $prefix = 'div.' . $grid_class . ' '; /* Generate the main Grid CSS */ if (!isset($wrapper_css_flags[$grid_class])) { $return .= $prefix . '.column { margin-left: ' . round($resp_single_column_margin, $round_precision) . '%; }' . "\n"; for ($i = 1; $i <= $grid_number; $i++) { /* Vars */ $resp_grid_width = $resp_single_column_width * $i + $i * $resp_single_column_margin; $resp_grid_left_margin = ($resp_single_column_width + $resp_single_column_margin) * $i + $resp_single_column_margin; /* Output */ $return .= $prefix . '.grid-width-' . $i . ' { width: ' . round($resp_grid_width - $resp_single_column_margin, $round_precision) . '%; }' . "\n"; if ($i < $grid_number) { $return .= $prefix . '.grid-left-' . $i . ' { margin-left: ' . round($resp_grid_left_margin, $round_precision) . '%; }' . "\n"; } } /* Create a flag keeping this same Grid CSS from being outputted */ $wrapper_css_flags['grid-fluid-' . $grid_number . '-' . $column_width . '-' . $gutter_width] = true; } /* End main grid CSS */ /* Responsive Sub Column CSS */ if ($blocks_in_sub_columns) { /* Get the columns required for sub columns */ $required_columns_for_sub_columns = array(); foreach ($wrapper_rendered->blocks_in_sub_columns as $block_in_sub_column_id) { if (isset($wrapper_rendered->blocks[$block_in_sub_column_id]['parent-column-width'])) { $required_columns_for_sub_columns[] = $wrapper_rendered->blocks[$block_in_sub_column_id]['parent-column-width']; } } $required_columns_for_sub_columns = array_filter(array_unique($required_columns_for_sub_columns)); /* End getting columns required for sub columns */ for ($i = 1; $i <= $grid_number; $i++) { /* Don't output the sub column CSS if there's no column of this number with sub columns and don't output it if has already by a previous wrapper. */ if (!in_array($i, $required_columns_for_sub_columns) || isset($wrapper_css_flags['grid-fluid-' . $grid_number . '-' . $column_width . '-' . $gutter_width . '-sub-columns-column-' . $i])) { continue; } /* Vars */ $resp_grid_width = $resp_single_column_width * $i + $i * $resp_single_column_margin; $resp_grid_left_margin = ($resp_single_column_width + $resp_single_column_margin) * $i + $resp_single_column_margin; $sub_column_single_width = $resp_single_column_width / $resp_grid_width * 100; $sub_column_single_margin = $resp_single_column_margin / $resp_grid_width * 100; $return .= $prefix . '.grid-width-' . $i . ' .sub-column { margin-left: ' . round($sub_column_single_margin, $round_precision) . '%; }' . "\n"; for ($sub_column_i = 1; $sub_column_i < $i; $sub_column_i++) { /* Sub column vars */ $sub_column_width = $sub_column_single_width * $sub_column_i + $sub_column_i * $sub_column_single_margin; $sub_column_margin = ($sub_column_single_width + $sub_column_single_margin) * $sub_column_i + $sub_column_single_margin; $return .= $prefix . '.grid-width-' . $i . ' .sub-column.grid-width-' . $sub_column_i . ' { width: ' . round($sub_column_width - $sub_column_single_margin, $round_precision) . '%; }' . "\n"; $return .= $prefix . '.grid-width-' . $i . ' .sub-column.grid-width-' . $sub_column_i . '.column-1 { width: ' . round($sub_column_width, $round_precision) . '%; }' . "\n"; $return .= $prefix . '.grid-width-' . $i . ' .sub-column.grid-left-' . $sub_column_i . ' { margin-left: ' . round($sub_column_margin, $round_precision) . '%; }' . "\n"; $return .= $prefix . '.grid-width-' . $i . ' .sub-column.grid-left-' . $sub_column_i . '.column-1 { margin-left: ' . round($sub_column_margin - $sub_column_single_margin, $round_precision) . '%; }' . "\n"; } /* Create a flag keeping this same sub column CSS from being outputted */ $wrapper_css_flags['grid-fluid-' . $grid_number . '-' . $column_width . '-' . $gutter_width . '-sub-columns-column-' . $i] = true; } } /* End responsive sub column CSS */ return $return; }
public function display() { if (!$this->blocks) { return $this->display_no_blocks_message(); } foreach ($this->wrappers as $wrapper_id => $wrapper_settings) { $wrapper_id_for_blocks = $wrapper_id; /* Check if mirroring. If mirroring, change wrapper ID to the wrapper being mirrored and preserve original ID for a later class */ if ($wrapper_being_mirrored = HeadwayWrappers::get_wrapper_mirror($wrapper_settings)) { $mirrored_wrapper_id = $wrapper_being_mirrored['id']; $wrapper_id_for_blocks = $mirrored_wrapper_id; foreach (HeadwayBlocksData::get_blocks_by_wrapper($wrapper_being_mirrored['layout'], $mirrored_wrapper_id) as $block_from_mirrored_wrapper) { $this->blocks[$block_from_mirrored_wrapper['id']] = $block_from_mirrored_wrapper; } } /* Grab blocks belonging to this wrapper */ $wrapper_blocks = array(); foreach ($this->blocks as $block_id => $block) { if (headway_get('wrapper', $block, HeadwayWrappers::$default_wrapper_id) === $wrapper_id_for_blocks) { $wrapper_blocks[$block_id] = $block; } /* If there's only one wrapper and the block does not have a proper ID or is default, move it to that wrapper */ if (count($this->wrappers) === 1 && (headway_get('wrapper', $block) === null || headway_get('wrapper', $block) == 'wrapper-default' || !isset($this->wrappers[headway_get('wrapper', $block)]))) { $wrapper_blocks[$block_id] = $block; } } /* Setup wrapper classes */ $wrapper_column_width = headway_get('use-independent-grid', $wrapper_settings) ? headway_get('column-width', $wrapper_settings) : HeadwayOption::get('column-width', false, HeadwayWrappers::$default_column_width); $wrapper_gutter_width = headway_get('use-independent-grid', $wrapper_settings) ? headway_get('gutter-width', $wrapper_settings) : HeadwayOption::get('gutter-width', false, HeadwayWrappers::$default_gutter_width); $wrapper_classes = array('wrapper'); $wrapper_classes[] = $wrapper_settings['fluid'] ? 'wrapper-fluid' : 'wrapper-fixed'; $wrapper_classes[] = HeadwayResponsiveGrid::is_active() ? 'responsive-grid' : null; $wrapper_classes[] = headway_get('use-independent-grid', $wrapper_settings) ? 'independent-grid' : null; $wrapper_classes[] = 'grid-' . ($wrapper_settings['fluid-grid'] || HeadwayResponsiveGrid::is_enabled() ? 'fluid' : 'fixed') . '-' . $wrapper_settings['columns'] . '-' . $wrapper_column_width . '-' . $wrapper_gutter_width; $wrapper_classes[] = $wrapper_being_mirrored ? 'wrapper-mirroring-' . HeadwayWrappers::format_wrapper_id($mirrored_wrapper_id) : null; $last_wrapper_id = array_slice(array_keys($this->wrappers), -1, 1); $last_wrapper_id = $last_wrapper_id[0]; $first_wrapper_id = array_keys($this->wrappers); $first_wrapper_id = $first_wrapper_id[0]; if ($last_wrapper_id == $wrapper_id) { $wrapper_classes[] = 'wrapper-last'; } else { if ($first_wrapper_id == $wrapper_id) { $wrapper_classes[] = 'wrapper-first'; } } /* Custom wrapper classes */ $custom_css_classes = explode(' ', str_replace(' ', ' ', str_replace(',', ' ', htmlspecialchars(strip_tags(headway_get('css-classes', $wrapper_settings, '')))))); $wrapper_classes = array_merge($wrapper_classes, $custom_css_classes); /* Display the wrapper */ do_action('headway_before_wrapper'); echo '<div id="' . $wrapper_id . '" class="' . implode(' ', array_unique(array_filter($wrapper_classes))) . '">' . "\n\n"; do_action('headway_wrapper_open'); $wrapper = new HeadwayGridRenderer($wrapper_blocks, $wrapper_settings); $wrapper->render_grid(); do_action('headway_wrapper_close'); echo '</div><!-- .wrapper -->' . "\n\n"; do_action('headway_after_wrapper'); /* End displaying wrapper */ } }
public static function add_template($template_name = null, $blocks = null, $wrappers = null) { $templates = HeadwayOption::get('list', 'templates', array()); $last_template_id = HeadwayOption::get('last-id', 'templates', 0); /* These two variables be used for when a blocks/wrappers imported ID is different than the one that it ends up with... i.g. skin importing to line up instances */ $block_id_translations = array(); $wrapper_id_translations = array(); /* Build name */ $id = $last_template_id + 1; $template_name = $template_name ? $template_name : 'Template ' . $id; /* Add template to templates array so it can be sent to DB */ $templates[$id] = $template_name; /* Send array to DB */ HeadwayOption::set('list', $templates, 'templates'); HeadwayOption::set('last-id', $id, 'templates'); /* Add blocks and wrappers */ if ($blocks && $wrappers) { /* Format wrappers */ foreach ($wrappers as $wrapper_id => $wrapper_settings) { $old_wrapper_id = $wrapper_id; $new_wrapper = HeadwayWrappers::add_wrapper('template-' . $id, $wrapper_settings); $wrapper_id_translations[str_replace('wrapper-', '', $old_wrapper_id)] = array('id' => $new_wrapper['id'], 'layout' => 'template-' . $id); } /* Add blocks */ foreach ($blocks as $block) { $old_block_id = $block['id']; unset($block['id']); unset($block['layout']); /* Update block's wrapper ID to match the real ID of the imported wrapper because if you link to the old ID from the export file then it won't match up */ $block['wrapper'] = 'wrapper-' . $wrapper_id_translations[str_replace('wrapper-', '', $block['wrapper'])]['id']; $new_block_id = HeadwayBlocksData::add_block('template-' . $id, $block); $block_id_translations[$old_block_id] = $new_block_id; } } /* End adding wrappers and blocks */ return array('id' => $id, 'name' => $template_name, 'block-id-translations' => $block_id_translations, 'wrapper-id-translations' => $wrapper_id_translations); }
public static function register_block_element_instances() { if ((headway_get('layout-in-use') || headway_post('layout')) && !headway_get('compiler-cache')) { $layout_id = headway_get('layout-in-use') ? headway_get('layout-in-use') : headway_post('layout'); $register_block_mirrors = true; if (!($blocks = HeadwayBlocksData::get_blocks_by_layout($layout_id))) { return false; } } else { $register_block_mirrors = false; if (!($blocks = HeadwayBlocksData::get_all_blocks())) { return false; } } foreach ($blocks as $block) { /* Do not register instance for block that's in a mirrored wrapper */ if (HeadwayWrappers::get_wrapper_mirror(HeadwayWrappers::get_wrapper(headway_get('wrapper', $block)))) { continue; } /* If it's a mirrored block then we'll register it as long as $register_block_mirrors is true */ if ($block_mirror = HeadwayBlocksData::is_block_mirrored($block)) { if (!$register_block_mirrors) { continue; } $block = $block_mirror; } $default_name = self::block_type_nice($block['type']) . ' #' . $block['id']; $name = headway_get('alias', $block['settings'], $default_name); HeadwayElementAPI::register_element_instance(array('group' => 'blocks', 'element' => 'block-' . $block['type'], 'id' => $block['type'] . '-block-' . $block['id'], 'name' => $name, 'selector' => '#block-' . $block['id'], 'layout' => $block['layout'])); /* Register sub elements */ $block_element = HeadwayElementAPI::get_element('block-' . $block['type']); foreach (headway_get('children', $block_element, array()) as $block_element_sub_element) { /* Make sure that the element supports instances */ if (!headway_get('supports-instances', $block_element_sub_element)) { continue; } /* Register instance */ $instance_selector = str_replace('.block-type-' . $block['type'], '#block-' . $block['id'], $block_element_sub_element['selector']); HeadwayElementAPI::register_element_instance(array('group' => 'blocks', 'grandparent' => 'block-' . $block['type'], 'element' => $block_element_sub_element['id'], 'id' => $block_element_sub_element['id'] . '-block-' . $block['id'], 'name' => $name . ' - ' . $block_element_sub_element['name'], 'selector' => $instance_selector, 'layout' => $block['layout'])); /* Register instance states as instances */ if (!empty($block_element_sub_element['states']) && is_array($block_element_sub_element['states'])) { foreach ($block_element_sub_element['states'] as $instance_state_id => $instance_state_info) { HeadwayElementAPI::register_element_instance(array('group' => 'blocks', 'grandparent' => 'block-' . $block['type'], 'element' => $block_element_sub_element['id'], 'id' => $block_element_sub_element['id'] . '-block-' . $block['id'] . '-state-' . $instance_state_id, 'name' => $name . ' - ' . $block_element_sub_element['name'] . ' (State: ' . $instance_state_info['name'] . ')', 'selector' => str_replace('.block-type-' . $block['type'], '#block-' . $block['id'], $instance_state_info['selector']), 'layout' => $block['layout'], 'state-of' => $block_element_sub_element['id'] . '-block-' . $block['id'], 'state-name' => $instance_state_info['name'])); } } } /* /foreach */ } }
public static function export_skin($skin_name = 'Unnamed', $include_live_css = false, $included_templates = false) { do_action('headway_before_export_skin'); /* Set up variables */ $element_data = HeadwayElementsData::get_all_elements(); $skin = array('name' => $skin_name, 'element-data' => $element_data); if ($include_live_css) { $skin['live-css'] = HeadwayOption::get('live-css'); } /* If templates are to be included then query for them and convert all mirrored blocks into original blocks by pulling their mirror target's settings */ if (is_array($included_templates)) { $skin['templates'] = array(); $white_listed_block_instances = array(); $white_listed_wrapper_instances = array(); foreach ($included_templates as $template_id) { $template_name = HeadwayLayout::get_name('template-' . $template_id); $template_blocks = HeadwayBlocksData::get_blocks_by_layout('template-' . $template_id); $template_wrappers = HeadwayWrappers::get_layout_wrappers('template-' . $template_id); /* 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 ($template_blocks as $template_block_index => $template_block) { if (!($mirrored_block = HeadwayBlocksData::is_block_mirrored($template_block))) { /* Allow this block's instances to be in the skin */ $white_listed_block_instances[] = $template_block['id']; /* Delete mirror option in case it's present */ if (isset($template_blocks[$template_block_index]['settings']['mirror-block'])) { unset($template_blocks[$template_block_index]['settings']['mirror-block']); } continue; } $template_blocks[$template_block_index]['id'] = $mirrored_block['id']; $template_blocks[$template_block_index]['settings'] = $mirrored_block['settings']; /* Allow this block's instances to be in the skin */ $white_listed_block_instances[] = $mirrored_block['id']; } /* Whitelist wrapper instances */ foreach ($template_wrappers as $template_wrapper_id => $template_wrapper_settings) { $white_listed_wrapper_instances[] = $template_wrapper_id; } $skin['templates'][$template_name] = $template_blocks; $skin['templates'][$template_name]['wrappers'] = $template_wrappers; } } /* Need to remove instances that aren't in the included templates and layout specific customizations from $element_data here */ foreach ($skin['element-data'] as $element_id => $element) { /* Add in the element group that way it can be saved @since 3.4.8 */ $element_registration = HeadwayElementAPI::get_element($element_id); $skin['element-data'][$element_id]['group'] = $element_registration['group']; /* Remove instances that aren't in this skin's templates */ if (isset($element['special-element-instance'])) { /* White list doesn't exist, just remove all instances */ if (!isset($white_listed_block_instances)) { unset($skin['element-data'][$element_id]['special-element-instance']); /* White List Exists, loop through each instance and check its ID */ } else { foreach ($skin['element-data'][$element_id]['special-element-instance'] as $instance_id => $properties) { $instance_id_fragments = explode('-', $instance_id); $instance_potential_block_id_search = preg_match('/\\bblock\\b\\-[0-9]+/', $instance_id, $instance_potential_block_id_search_results); $instance_potential_block_id = str_replace('block-', '', end($instance_potential_block_id_search_results)); $instance_potential_wrapper_id = $instance_id_fragments[0] . '-' . $instance_id_fragments[1]; /* Wrapper instance conditional. If a positive match, CONTINUE that way the unset doesn't happen */ if (strpos($instance_id, 'wrapper-') === 0 && in_array($instance_potential_wrapper_id, $white_listed_wrapper_instances)) { continue; } else { if (strpos($instance_id, 'block-') !== false && is_numeric($instance_potential_block_id) && in_array($instance_potential_block_id, $white_listed_block_instances)) { continue; } } /* Delete the instance if it doesn't match the block OR wrapper whitelist */ unset($skin['element-data'][$element_id]['special-element-instance'][$instance_id]); } } } /* Remove layout-specific customizations from the skin */ if (isset($element['special-element-layout'])) { unset($skin['element-data'][$element_id]['special-element-layout']); } } /* Spit the file out */ return self::to_json('Headway Skin - ' . $skin_name, 'skin', $skin); }
public function render_input($input) { //Fill defaults $defaults = array('tooltip' => false, 'default' => false, 'callback' => null); //Merge defaults $input = array_merge($defaults, $input); //Fix up inputs $input = $this->parse_function_args($input); if (!isset($input['name']) || !isset($input['type'])) { return; } /* Set up main input variables */ $input['name'] = strtolower($input['name']); $input['group'] = isset($input['group']) ? $input['group'] : $this->options_group; $input['tooltip'] = isset($input['tooltip']) && $input['tooltip'] != false ? $input['tooltip'] : false; /* Populate the value */ $input['default'] = isset($input['default']) ? $input['default'] : null; if (isset($this->wrapper) && $this->wrapper && !isset($input['value'])) { $input['value'] = HeadwayWrappers::get_wrapper_setting($this->wrapper, $input['name'], $input['default']); } else { if (isset($this->block) && $this->block && !isset($input['value'])) { $input['value'] = HeadwayBlocksData::get_block_setting($this->block, $input['name'], $input['default']); } else { if (!isset($input['value'])) { $input['value'] = HeadwayOption::get($input['name'], $input['group'], $input['default']); } } } /* Setup Attributes */ $attributes_array = array('id' => isset($this->block) && $this->block ? 'input-' . $this->block['id'] . '-' . $input['name'] : 'input-' . $input['group'] . '-' . $input['name'], 'name' => $input['name'], 'data-group' => $input['group']); /* Set up the callback attribute */ $attributes_array['data-callback'] = htmlspecialchars('(function(args){var input=args.input;var value=args.value;var block=args.block || null;' . $input['callback'] . '})'); /* Set up data handler override if it's used */ if (headway_get('data-handler-callback', $input)) { $attributes_array['data-data-handler-callback'] = htmlspecialchars('(function(args){' . $input['data-handler-callback'] . '})'); } /* Set up toggle attribute */ if (headway_get('toggle', $input)) { $attributes_array['data-toggle'] = htmlspecialchars(json_encode($input['toggle'])); } /* No save attribute */ if (headway_get('no-save', $input, false)) { $attributes_array['data-no-save'] = 'true'; } /* Turn attributes array into a string for HTML */ $input['attributes'] = ''; foreach ($attributes_array as $attribute => $attribute_value) { $input['attributes'] .= $attribute . '="' . $attribute_value . '" '; } $input['attributes'] = trim($input['attributes']); /* If it's a repeater then handle it before it's handled as an input */ if ($input['type'] == 'repeater') { return $this->repeater($input); } /* Handle regular input */ if (method_exists($this, 'input_' . str_replace('-', '_', $input['type']))) { /* Handle all types except for raw HTML input */ if ($input['type'] != 'raw-html') { echo '<div class="input input-' . $input['type'] . '" id="input-' . $input['name'] . '">'; if ($input['tooltip']) { echo '<div class="tooltip-button" title="' . htmlspecialchars($input['tooltip']) . '"></div>'; } call_user_func(array($this, 'input_' . str_replace('-', '_', $input['type'])), $input); echo '</div><!-- #input-' . $input['name'] . ' -->'; } else { call_user_func(array($this, 'input_' . str_replace('-', '_', $input['type'])), $input); } } /* End regular input handling */ }
public static function add_visual_editor_js_vars() { //Gather the URLs for the block types $block_types = HeadwayBlocks::get_block_types(); $block_type_urls = array(); foreach ($block_types as $block_type => $block_type_options) { $block_type_urls[$block_type] = $block_type_options['url']; } $block_styles = class_exists('HeadwayChildThemeAPI') ? HeadwayChildThemeAPI::get_block_style_classes() : array(); $current_layout_status = HeadwayLayout::get_status(HeadwayLayout::get_current()); $script_name = is_ssl() ? 'headway-ve-js-https' : 'headway-ve-js'; wp_localize_script($script_name, 'Headway', array('ajaxURL' => admin_url('admin-ajax.php'), 'currentLayout' => HeadwayLayout::get_current(), 'currentLayoutName' => HeadwayLayout::get_name(HeadwayLayout::get_current()), 'currentLayoutCustomized' => $current_layout_status['customized'], 'currentLayoutTemplate' => $current_layout_status['template'], 'availableBlockID' => HeadwayBlocksData::get_available_block_id(), 'availableWrapperID' => HeadwayWrappers::get_available_wrapper_id(), 'headwayURL' => get_template_directory_uri(), 'siteURL' => site_url(), 'homeURL' => home_url(), 'adminURL' => admin_url(), 'mode' => HeadwayVisualEditor::get_current_mode(), 'designEditorSupport' => current_theme_supports('headway-design-editor'), 'siteName' => get_bloginfo('name'), 'siteDescription' => get_bloginfo('description'), 'security' => wp_create_nonce('headway-visual-editor-ajax'), 'ranTour' => json_encode(array('legacy' => HeadwayOption::get('ran-tour', false, false), 'grid' => HeadwayOption::get('ran-tour-grid', false, false), 'design' => HeadwayOption::get('ran-tour-design', false, false))), 'blockTypeURLs' => json_encode($block_type_urls), 'allBlockTypes' => json_encode($block_types), 'disableCodeMirror' => HeadwayOption::get('disable-codemirror', false, false), 'frontPage' => get_option('show_on_front', 'posts'), 'gridSupported' => current_theme_supports('headway-grid'), 'disableTooltips' => HeadwayOption::get('disable-visual-editor-tooltips', false, false), 'blockStyles' => $block_styles, 'responsiveGrid' => HeadwayResponsiveGrid::is_enabled(), 'designEditorProperties' => HeadwayVisualEditor::is_mode('design') ? json_encode(HeadwayElementProperties::get_properties()) : json_encode(array()), 'colorpickerSwatches' => HeadwayOption::get('colorpicker-swatches', false, array()), 'gridSafeMode' => HeadwayOption::get('grid-safe-mode', false, false), 'defaultGridColumnCount' => HeadwayWrappers::$default_columns, 'globalGridColumnWidth' => HeadwayWrappers::$global_grid_column_width, 'globalGridGutterWidth' => HeadwayWrappers::$global_grid_gutter_width, 'touch' => stripos($_SERVER['HTTP_USER_AGENT'], 'iPad') !== false ? true : false)); }
public static function get_grid_width($wrapper) { if (!is_array($wrapper)) { return false; } /* If wrapper is mirrored then use settings from it for the grid */ if ($potential_wrapper_mirror = HeadwayWrappers::get_wrapper_mirror($wrapper)) { $wrapper = $potential_wrapper_mirror; } $column_width = headway_get('use-independent-grid', $wrapper) ? headway_get('column-width', $wrapper) : HeadwayOption::get('column-width', false, HeadwayWrappers::$default_column_width); $gutter_width = headway_get('use-independent-grid', $wrapper) ? headway_get('gutter-width', $wrapper) : HeadwayOption::get('gutter-width', false, HeadwayWrappers::$default_gutter_width); return $column_width * headway_get('columns', $wrapper) + (headway_get('columns', $wrapper) - 1) * $gutter_width; }
public static function display_canvas() { echo '<!DOCTYPE HTML> <html lang="en"> <head> <meta charset="' . get_bloginfo('charset') . '" /> <link rel="profile" href="http://gmpg.org/xfn/11" /> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" /> <meta http-equiv="cache-control" content="no-cache" /> <title>Visual Editor Grid: ' . wp_title(false, false) . '</title>'; do_action('headway_grid_iframe_head'); echo '</head><!-- /head --> <body class="visual-editor-iframe-grid ' . join(' ', get_body_class()) . '">'; $wrappers = HeadwayWrappers::get_layout_wrappers(HeadwayLayout::get_current_in_use()); $blocks = HeadwayBlocksData::get_blocks_by_layout(HeadwayLayout::get_current_in_use()); echo '<div id="whitewrap" data-wrappers="' . htmlspecialchars(json_encode($wrappers)) . '">'; foreach ($wrappers as $wrapper_id => $wrapper_settings) { /* Setup wrapper classes */ $wrapper_classes = array('wrapper'); $wrapper_classes[] = headway_get('use-independent-grid', $wrapper_settings) ? 'independent-grid' : null; $wrapper_classes[] = $wrapper_settings['fluid'] ? 'wrapper-fluid' : 'wrapper-fixed'; $wrapper_classes[] = $wrapper_settings['fluid'] && $wrapper_settings['fluid-grid'] ? 'wrapper-fluid-grid' : 'wrapper-fixed-grid'; if (HeadwayWrappers::get_wrapper_mirror($wrapper_settings)) { $wrapper_classes[] = 'wrapper-mirrored'; } /* Populate wrapper with its blocks */ $wrapper_blocks = array(); foreach ($blocks as $block_id => $block) { /* Grab blocks belonging to this wrapper */ if (headway_get('wrapper', $block, HeadwayWrappers::$default_wrapper_id) === $wrapper_id) { $wrapper_blocks[$block_id] = $block; } /* If last wrapper, grab all blocks on this layout with invalid wrapper IDs to make sure they're editable somewhere */ $last_wrapper_id = array_slice(array_keys($wrappers), -1, 1); $last_wrapper_id = $last_wrapper_id[0]; if ($last_wrapper_id == $wrapper_id && !headway_get(headway_get('wrapper', $block, HeadwayWrappers::$default_wrapper_id), $wrappers)) { $wrapper_blocks[$block_id] = $block; } } /* Output the wrapper */ echo '<div id="' . $wrapper_id . '" class="' . implode(' ', array_filter($wrapper_classes)) . '">'; echo '<div class="wrapper-mirror-overlay"></div><!-- .wrapper-mirror-overlay -->'; self::display_grid_blocks($wrapper_blocks, $wrapper_settings); echo '</div><!-- #wrapper-' . $wrapper_id . ' -->'; } echo '<div id="wrapper-buttons-template">'; echo '<div class="wrapper-top-margin-handle wrapper-handle wrapper-margin-handle" title="Drag to change wrapper top margin"><span></span><span></span><span></span></div>'; echo '<div class="wrapper-drag-handle wrapper-handle tooltip tooltip-right" title="Drag to change wrapper order"><span></span><span></span><span></span></div>'; echo '<div class="wrapper-bottom-margin-handle wrapper-handle wrapper-margin-handle" title="Drag to change wrapper bottom margin"><span></span><span></span><span></span></div>'; echo '<div class="wrapper-options tooltip tooltip-right" title="Click to open wrapper options"><span></span></div>'; echo '</div><!-- .wrapper-buttons -->'; do_action('headway_grid_iframe_footer'); echo '</div><!-- #whitewrap --> </body> </html>'; }
public static function method_load_wrapper_options() { $layout_id = headway_post('layout'); $wrapper_id = headway_post('wrapper_id'); $unsaved_options = headway_post('unsaved_wrapper_options', array()); $wrapper = HeadwayWrappers::get_wrapper($wrapper_id, $layout_id); /* Merge unsaved options in */ if (is_array($unsaved_options)) { $wrapper = array_merge($wrapper, $unsaved_options); } do_action('headway_wrapper_options', $wrapper, $layout_id); }