public static function get_all_elements($exclude_default_data = false) { $default_data = !$exclude_default_data ? self::get_default_data() : array(); //Set up the main array to be returned $elements = array(); //Get all of the design editor option groups by looking at the option groups catalog $option_groups = get_option('headway_option_groups'); //Pull out only the design editor groups. Since headway_option_groups uses true for every value //and the group is actually the key, we must pull the keys out using array_keys $design_editor_groups = array_filter(array_keys($option_groups), create_function('$group', 'return (strpos($group, \'design-editor-group-\') !== false);')); //Loop through all of the groups and get every element and its properties foreach ($design_editor_groups as $design_editor_group) { /* Have seen some support cases where a rogue design editor group with no name is somehow being put in... Possibly from skins, but this will prevent it from loading in the meantime */ if ($design_editor_group == 'design-editor-group-') { continue; } $group = get_option('headway_option_group_' . $design_editor_group . HeadwayOption::$group_suffix); //Merge the current group into the array to be returned $group = is_array($group) ? array_map('maybe_unserialize', $group) : false; if (is_array($group)) { $elements = array_merge($elements, $group); } } //Merge in the default element data if (is_array($default_data)) { $elements = headway_array_merge_recursive_simple($default_data, $elements); } //Move default elements to the top foreach ($elements as $element_id => $element_options) { $element = HeadwayElementAPI::get_element($element_id); if (!isset($element['default-element']) || $element['default-element'] === false) { continue; } $temp_id = $element_id; $temp_options = $element_options; unset($elements[$element_id]); $elements = array_merge(array($temp_id => $temp_options), $elements); } return $elements; }
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 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); }