示例#1
0
 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;
 }
 public static function method_load_block_content()
 {
     /* Check for grid safe mode */
     if (HeadwayOption::get('grid-safe-mode', false, false)) {
         echo '<div class="alert alert-red block-safe-mode"><p>Grid Safe mode enabled.  Block content not outputted.</p></div>';
         return;
     }
     /* Go */
     $layout = headway_post('layout');
     $block_origin = headway_post('block_origin');
     $block_default = headway_post('block_default', false);
     $unsaved_block_settings = headway_post('unsaved_block_settings', false);
     /* If the block origin is a string or ID, then get the object from DB. */
     if (is_numeric($block_origin) || is_string($block_origin)) {
         $block = HeadwayBlocksData::get_block($block_origin);
     } else {
         $block = $block_origin;
     }
     /* If the block doesn't exist, then use the default as the origin.  If the default doesn't exist... We're screwed. */
     if (!$block && $block_default) {
         $block = $block_default;
     }
     /* If the block settings is an array, merge that into the origin.  But first, make sure the settings exists for the origin. */
     if (!isset($block['settings'])) {
         $block['settings'] = array();
     }
     if (is_array($unsaved_block_settings) && count($unsaved_block_settings) && isset($unsaved_block_settings['settings'])) {
         $block = headway_array_merge_recursive_simple($block, $unsaved_block_settings);
     }
     /* If the block is set to mirror, then get that block. */
     if ($mirrored_block = HeadwayBlocksData::is_block_mirrored($block)) {
         $original_block = $block;
         $block = $mirrored_block;
         $block['original'] = $original_block;
     }
     /* Add a flag into the block so we can check if this is coming from the visual editor. */
     $block['ve-live-content-query'] = true;
     /* Show the content */
     do_action('headway_block_content_' . $block['type'], $block);
     /* Output dynamic JS and CSS */
     if (headway_post('mode') != 'grid') {
         $block_types = HeadwayBlocks::get_block_types();
         /* Dynamic CSS */
         if (method_exists($block_types[$block['type']]['class'], 'dynamic_css')) {
             echo '<style type="text/css">';
             echo call_user_func(array($block_types[$block['type']]['class'], 'dynamic_css'), $block['id'], $block);
             echo '</style><!-- AJAX Block Content Dynamic CSS -->';
         }
         /* Run enqueue action and print right away */
         if (method_exists($block_types[$block['type']]['class'], 'enqueue_action')) {
             /* Remove all other enqueued scripts to reduce conflicts */
             global $wp_scripts;
             $wp_scripts = null;
             remove_all_actions('wp_print_scripts');
             /* Remove all other enqueued styles to reduce conflicts */
             global $wp_styles;
             $wp_styles = null;
             remove_all_actions('wp_print_styles');
             echo call_user_func(array($block_types[$block['type']]['class'], 'enqueue_action'), $block['id'], $block);
             wp_print_scripts();
             wp_print_footer_scripts();
             /* This isn't really needed, but it's here for juju power */
         }
         /* Output dynamic JS */
         if (method_exists($block_types[$block['type']]['class'], 'dynamic_js')) {
             echo '<script type="text/javascript">';
             echo call_user_func(array($block_types[$block['type']]['class'], 'dynamic_js'), $block['id'], $block);
             echo '</script><!-- AJAX Block Content Dynamic JS -->';
         }
     }
     /* End outputting dynamic JS and CSS */
 }