public static function cache()
 {
     $raw_webfonts = self::pluck_webfonts(HeadwayElementsData::get_all_elements());
     $sorted_webfonts = array();
     foreach ($raw_webfonts as $webfont) {
         $fragments = explode('|', $webfont);
         $sorted_webfonts[$fragments[0]][] = !empty($fragments[2]) ? $fragments[1] . ':' . $fragments[2] : $fragments[1];
         /* $fragments[2] are the variants */
         $sorted_webfonts[$fragments[0]] = array_unique($sorted_webfonts[$fragments[0]]);
     }
     return HeadwayOption::set('webfont-cache', $sorted_webfonts);
 }
Example #2
0
 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 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);
 }