function headway_register_default_elements() { HeadwayElementAPI::register_element(array('id' => 'default-text', 'name' => 'Paragraph Text', 'properties' => array('fonts'), 'default-element' => true, 'selector' => 'body')); HeadwayElementAPI::register_element(array('id' => 'default-hyperlink', 'name' => 'Hyperlink', 'properties' => array('fonts' => array('color', 'font-styling', 'capitalization'), 'text-shadow', 'borders', 'box-shadow', 'rounded-corners'), 'default-element' => true, 'selector' => 'a')); HeadwayElementAPI::register_element(array('id' => 'default-block', 'name' => 'Block', 'properties' => array('background', 'borders', 'fonts', 'padding', 'rounded-corners', 'box-shadow', 'overflow'), 'default-element' => true, 'selector' => '.block')); HeadwayElementAPI::register_element(array('id' => 'block-title', 'name' => 'Block Title', 'selector' => '.block-title', 'default-element' => true)); HeadwayElementAPI::register_element(array('id' => 'block-subtitle', 'name' => 'Block Subtitle', 'selector' => '.block-subtitle', 'default-element' => true)); }
function headway_register_structural_elements() { //Structure HeadwayElementAPI::register_group('structure', 'Structure'); HeadwayElementAPI::register_element(array('group' => 'structure', 'id' => 'body', 'name' => 'Body', 'selector' => 'body', 'properties' => array('background', 'borders'), 'disallow-nudging' => true)); HeadwayElementAPI::register_element(array('group' => 'structure', 'id' => 'wrapper', 'name' => 'Wrapper', 'selector' => 'div.wrapper', 'properties' => array('background', 'borders', 'padding', 'rounded-corners', 'box-shadow'))); //Blocks HeadwayElementAPI::register_group('blocks', 'Blocks'); }
public function register_block_element($args) { /* Add the selector prefix to the selector and even handle commas */ $selector_prefix = '.block-type-' . $this->id . ' '; $selector_array = explode(',', $args['selector']); foreach ($selector_array as $selector_index => $selector) { if (strpos(trim($selector_array[$selector_index]), '.block-type-') === 0) { continue; } $selector_array[$selector_index] = $selector_prefix . trim($selector); } $modified_selector = implode(',', $selector_array); /* End Selector Modification */ $defaults = array('group' => 'blocks', 'parent' => 'block-' . $this->id, 'id' => 'block-' . $this->id . '-' . $args['id'], 'name' => $args['name'], 'selector' => $modified_selector); //Unset the following so they don't overwrite the defaults unset($args['id']); unset($args['name']); unset($args['selector']); $element = array_merge($defaults, $args); //Go through states and add the selector prefix to each state if (isset($element['states']) && is_array($element['states'])) { foreach ($element['states'] as $state_name => $state_selector) { $state_selector_array = explode(',', $state_selector); foreach ($state_selector_array as $selector_index => $selector) { if (strpos(trim($state_selector_array[$selector_index]), '.block-type-') === 0) { continue; } $state_selector_array[$selector_index] = $selector_prefix . trim($selector); } $element['states'][$state_name] = trim(implode(',', $state_selector_array)); } } return HeadwayElementAPI::register_element($element); }
static function design_editor() { /* Action used for registering elements */ do_action('headway_dynamic_style_design_editor_init'); $elements = HeadwayElementsData::get_all_elements(); $return = "/* DESIGN EDITOR STYLING */\n"; foreach ($elements as $element_id => $element_options) { $element = HeadwayElementAPI::get_element($element_id); $selector = $element['selector']; $nudging_properties = array('top', 'left', 'position', 'z-index'); //Continue to next element if the element/selector does not exist if (!isset($selector) || $selector == false) { continue; } /* Regular Element */ if (isset($element_options['properties'])) { $return .= HeadwayElementProperties::output_css($selector, self::filter_nudging_properties($element_options['properties'], $element)); } /* Layout-specific elements */ if (isset($element_options['special-element-layout']) && is_array($element_options['special-element-layout'])) { //Handle every layout foreach ($element_options['special-element-layout'] as $layout => $layout_properties) { //Get the selector for the layout $layout_element_selector = 'body.layout-using-' . $layout . ' ' . $selector; //Since the layout selectors are targeted by the body element, we can't do anything body to style the actual body element. Let's fix that. if ($selector == 'body') { $layout_element_selector = str_replace(' body', '', $layout_element_selector); } //The space inside str_replace is completely intentional. $return .= HeadwayElementProperties::output_css($layout_element_selector, self::filter_nudging_properties($layout_properties, $element)); } } /* Instances */ if (isset($element_options['special-element-instance']) && is_array($element_options['special-element-instance'])) { //Handle every instance foreach ($element_options['special-element-instance'] as $instance => $instance_properties) { //Make sure the instance exists if (!isset($element['instances'][$instance])) { continue; } //Get the selector for the instance $instance_selector = $element['instances'][$instance]['selector']; $return .= HeadwayElementProperties::output_css($instance_selector, self::filter_nudging_properties($instance_properties, $element)); } } /* States */ if (isset($element_options['special-element-state']) && is_array($element_options['special-element-state'])) { //Handle every instance foreach ($element_options['special-element-state'] as $state => $state_properties) { //Make sure the state exists if (!isset($element['states'][$state])) { continue; } //Get the selector for the layout $state_info = $element['states'][$state]; $return .= HeadwayElementProperties::output_css($state_info['selector'], self::filter_nudging_properties($state_properties, $element)); } } } //End main $elements foreach return $return; }
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 static function get_inherited_property($element_id, $property_id, $default = null) { //Check for normal property first. Need this for recursion and for instances/states. if ($normal_property = self::get_property($element_id, $property_id)) { return $normal_property; } //Check for inherit location right away. $inherit_location = HeadwayElementAPI::get_inherit_location($element_id); //If inherit location does not exist, go straight to default. if (!$inherit_location) { return $default; } else { return self::get_inherited_property($inherit_location, $property_id, $default); } }
public static function register_wrapper_instances() { $all_wrappers = HeadwayOption::get_group('wrappers'); if (!$all_wrappers) { return false; } foreach ($all_wrappers as $layout_id => $layout_wrappers) { /* Skip over the last-id option */ if ($layout_id == 'last-id') { continue; } foreach ($layout_wrappers as $layout_wrapper_id => $layout_wrapper_settings) { /* Do NOT register the default wrapper instance */ if ($layout_wrapper_id == 'wrapper-default') { continue; } /* Format the wrapper settings array */ $layout_wrapper_settings['id'] = $layout_wrapper_id; /* Do not register instance for mirrored wrapper */ if (HeadwayWrappers::get_wrapper_mirror($layout_wrapper_settings)) { continue; } $wrapper_alias = headway_get('alias', $layout_wrapper_settings) ? ' – ' . headway_get('alias', $layout_wrapper_settings) : null; HeadwayElementAPI::register_element_instance(array('group' => 'structure', 'element' => 'wrapper', 'id' => $layout_wrapper_id . '-layout-' . $layout_id, 'name' => 'Wrapper #' . HeadwayWrappers::format_wrapper_id($layout_wrapper_id) . $wrapper_alias, 'selector' => '#' . $layout_wrapper_id . ', div.wrapper-mirroring-' . HeadwayWrappers::format_wrapper_id($layout_wrapper_id), 'layout' => $layout_id)); } } }
public static function method_get_design_editor_elements() { $current_layout = headway_post('layout'); $all_elements = HeadwayElementAPI::get_all_elements(); $groups = HeadwayElementAPI::get_groups(); $customized_element_data = HeadwayElementsData::get_all_elements(true); $elements = array(); /* Assemble the arrays */ foreach ($all_elements as $group_id => $main_elements) { $elements[$group_id] = array(); /* Loop through main elements */ foreach ($main_elements as $main_element_id => $main_element_settings) { /* Handle main element */ $inherit_location = HeadwayElementAPI::get_element(HeadwayElementAPI::get_inherit_location($main_element_id)); $elements[$group_id][$main_element_id] = array('selector' => $main_element_settings['selector'], 'id' => $main_element_settings['id'], 'name' => $main_element_settings['name'], 'description' => headway_get('description', $main_element_settings), 'properties' => $main_element_settings['properties'], 'group' => $group_id, 'groupName' => headway_get($group_id, $groups), 'states' => headway_get('states', $main_element_settings, array()), 'instances' => headway_get('instances', $main_element_settings, array()), 'inherit-location' => headway_get('id', $inherit_location), 'inherit-location-name' => headway_get('name', $inherit_location), 'disallow-nudging' => headway_get('disallow-nudging', $main_element_settings, false), 'indent-in-selector' => headway_get('indent-in-selector', $main_element_settings, false), 'customized' => isset($customized_element_data[$main_element_settings['id']]) ? true : false, 'children' => array()); /* Loop through main element instances and add customized flag if necessary */ foreach ($elements[$group_id][$main_element_id]['instances'] as $main_element_instance_id => $main_element_instance_settings) { if (isset($customized_element_data[$main_element_settings['id']]['special-element-instance'][$main_element_instance_id])) { $elements[$group_id][$main_element_id]['instances'][$main_element_instance_id]['customized'] = true; } } /* Loop through element children */ foreach (headway_get('children', $main_element_settings, array()) as $child_element_id => $child_element_settings) { /* Handle child element */ $inherit_location = HeadwayElementAPI::get_element(HeadwayElementAPI::get_inherit_location($child_element_id)); $elements[$group_id][$main_element_id]['children'][$child_element_id] = array('selector' => $child_element_settings['selector'], 'id' => $child_element_settings['id'], 'name' => $child_element_settings['name'], 'description' => headway_get('description', $child_element_settings), 'properties' => $child_element_settings['properties'], 'group' => $group_id, 'groupName' => headway_get($group_id, $groups), 'parent' => $main_element_id, 'parentName' => headway_get('name', $main_element_settings), 'states' => headway_get('states', $child_element_settings, array()), 'instances' => headway_get('instances', $child_element_settings, array()), 'indent-in-selector' => headway_get('indent-in-selector', $child_element_settings, false), 'inherit-location' => headway_get('id', $inherit_location), 'inherit-location-name' => headway_get('name', $inherit_location), 'disallow-nudging' => headway_get('disallow-nudging', $child_element_settings, false), 'customized' => isset($customized_element_data[$child_element_settings['id']]) ? true : false); /* Loop through sub element instances and add customized flag if necessary */ foreach ($elements[$group_id][$main_element_id]['children'][$child_element_id]['instances'] as $sub_element_instance_id => $sub_element_instance_settings) { if (isset($customized_element_data[$child_element_settings['id']]['special-element-instance'][$sub_element_instance_id])) { $elements[$group_id][$main_element_id]['children'][$child_element_id]['instances'][$sub_element_instance_id]['customized'] = true; } } } } } /* Spit it all out */ self::json_encode($elements); }