Exemplo n.º 1
0
 /**
  * Over time, there may be issues to be corrected between updates or naming conventions to be changed between updates.
  * All of that will be processed here.
  **/
 public static function db_upgrade($db_version)
 {
     /* Pre-3.0.3 */
     if (version_compare($db_version, '3.0.3', '<')) {
         self::fix_serialization_in_db();
         self::repair_blocks();
     }
     /**
      * Pre-3.2.3
      * 
      * Change the old wrapper-horizontal-padding and wrapper-vertical-padding to design editor values
      **/
     if (version_compare($db_version, '3.2.3', '<')) {
         $horizontal_padding = HeadwayOption::get('wrapper-horizontal-padding', 'general', 15);
         $vertical_padding = HeadwayOption::get('wrapper-vertical-padding', 'general', 15);
         HeadwayElementsData::set_property('structure', 'wrapper', 'padding-top', $vertical_padding);
         HeadwayElementsData::set_property('structure', 'wrapper', 'padding-bottom', $vertical_padding);
         HeadwayElementsData::set_property('structure', 'wrapper', 'padding-left', $horizontal_padding);
         HeadwayElementsData::set_property('structure', 'wrapper', 'padding-right', $horizontal_padding);
     }
     /**
      * Pre-3.4
      * 
      * - Change block and wrapper margins to Design Editor values
      * - Convert Media blocks to Slider or Embed blocks
      **/
     if (version_compare($db_version, '3.4', '<')) {
         /* Change block and wrapper margins to Design Editor values */
         HeadwayElementsData::set_property('structure', 'wrapper', 'margin-top', HeadwayOption::get('wrapper-top-margin', 'general', 30));
         HeadwayElementsData::set_property('structure', 'wrapper', 'margin-bottom', HeadwayOption::get('wrapper-bottom-margin', 'general', 30));
         HeadwayElementsData::set_property('default-elements', 'default-block', 'margin-bottom', HeadwayOption::get('block-bottom-margin', 'general', 10));
         /* Convert Media blocks to Slider or Embed blocks */
         $media_blocks = HeadwayBlocksData::get_blocks_by_type('media');
         if (is_array($media_blocks) && count($media_blocks)) {
             foreach ($media_blocks as $media_block_id => $media_block_layout_id) {
                 $media_block = HeadwayBlocksData::get_block($media_block_id);
                 $media_block_mode = headway_get('mode', $media_block['settings'], 'embed');
                 switch ($media_block_mode) {
                     case 'embed':
                         HeadwayBlocksData::update_block($media_block['layout'], $media_block['id'], array('type' => 'embed'));
                         break;
                     case 'image-rotator':
                         $slider_images = array();
                         foreach (headway_get('images', $media_block['settings'], array()) as $media_block_image) {
                             $slider_images[] = array('image' => $media_block_image, 'image-description' => null, 'image-hyperlink' => null);
                         }
                         HeadwayBlocksData::update_block($media_block['layout'], $media_block['id'], array('type' => 'slider', 'settings' => array('images' => $slider_images)));
                         break;
                 }
             }
         }
     }
     /* Add action to flush caches */
     do_action('headway_db_upgrade');
     /* Update the version here. */
     $headway_settings = get_option('headway', array('version' => 0));
     $headway_settings['version'] = HEADWAY_VERSION;
     update_option('headway', $headway_settings);
     return true;
 }
Exemplo n.º 2
0
 public static function init_action($block_id, $block = false)
 {
     if (!$block) {
         $block = HeadwayBlocksData::get_block($block_id);
     }
     $name = HeadwayBlocksData::get_block_name($block) . ' &mdash; ' . 'Layout: ' . HeadwayLayout::get_name($block['layout']);
     register_nav_menu('navigation_block_' . $block_id, $name);
     wp_register_script('jquery-hoverintent', headway_url() . '/library/media/js/jquery.hoverintent.js', array('jquery'));
 }
Exemplo n.º 3
0
 public function get_blocks_select_options_for_mirroring()
 {
     $block_type = $this->block['type'];
     $blocks = HeadwayBlocksData::get_blocks_by_type($block_type);
     $options = array('' => '&ndash; Do Not Mirror &ndash;');
     //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) . ' &ndash; ' . $layout_name . $current_layout_suffix;
     }
     //Remove the current block from the list
     unset($options[$this->block['id']]);
     return $options;
 }
Exemplo n.º 4
0
 /**
  * Use this to enqueue styles or scripts for your block.  This method will be execute when the block type is on 
  * the current page you are viewing.  Also, not only is it page-specific, the method will execute for every instance
  * of that block type on the current page.
  * 
  * This method will be executed at the WordPress 'wp' hook
  *
  * REMOVE THIS METHOD IF NOT USING IT
  **/
 function enqueue_action($block_id)
 {
     $block = HeadwayBlocksData::get_block($block_id);
     return;
 }
Exemplo n.º 5
0
 static function get_blocks_select_options_for_mirroring($block_type)
 {
     $return = '';
     $blocks = HeadwayBlocksData::get_blocks_by_type($block_type);
     //If there are no blocks, then just return the Do Not Mirror option.
     if (!isset($blocks) || !is_array($blocks)) {
         return $return;
     }
     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 (headway_get('mirror-block', $block['settings'], false)) {
             continue;
         }
         //If the block is in the same layout as the current block, then do not allow it to be used as a block to mirror.
         if ($layout_id == headway_post('layout')) {
             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;
         }
         //Get alias if it exists, otherwise use the default name
         $return .= '<option value="' . $block['id'] . '">' . headway_get('alias', $block['settings'], $default_name) . ' &ndash; ' . $layout_name . '</option>';
     }
     return $return;
 }
Exemplo n.º 6
0
 public static function enqueue_action($block_id)
 {
     $block = HeadwayBlocksData::get_block($block_id);
     return gravity_form_enqueue_scripts(parent::get_setting($block, 'form-id', null), parent::get_setting($block, 'use-ajax', false));
 }
Exemplo n.º 7
0
 public static function display_block($block, $where = null)
 {
     //We'll allow this function to take either an integer argument to look up the block or to use the existing
     if (!is_array($block)) {
         $block = HeadwayBlocksData::get_block($block);
     }
     //Check that the block exists
     if (!is_array($block) || !$block) {
         return false;
     }
     $block_types = HeadwayBlocks::get_block_types();
     //Set the original block for future use
     $original_block = $block;
     $original_block_id = $block['id'];
     //Set the block style to null so we don't get an ugly notice down the road if it's not used.
     $block_style_attr = null;
     //Check if the block type exists
     if (!($block_type_settings = headway_get($block['type'], $block_types, array()))) {
         $block['requested-type'] = $block['type'];
         $block['type'] = 'unknown';
     }
     //Get the custom CSS classes and change commas to spaces and remove double spaces and remove HTML
     $custom_css_classes = str_replace('  ', ' ', str_replace(',', ' ', htmlspecialchars(strip_tags(headway_get('css-classes', $block['settings'], '')))));
     $block_classes = array_unique(array_filter(explode(' ', $custom_css_classes)));
     $block_classes[] = 'block';
     $block_classes[] = 'block-type-' . $block['type'];
     $block_classes[] = headway_get('fixed-height', $block_type_settings, false) !== true ? 'block-fluid-height' : 'block-fixed-height';
     //Block Styles
     if (HEADWAY_CHILD_THEME_ACTIVE && ($block_style = headway_get(HEADWAY_CHILD_THEME_ID . '-block-style', $block['settings']))) {
         $block_style_classes = explode(' ', headway_get('class', headway_get($block_style, HeadwayChildThemeAPI::$block_styles)));
         foreach ($block_style_classes as $block_style_class) {
             $block_classes[] = $block_style_class;
         }
     }
     //If the block is being displayed in the Grid, then we need to make it work with absolute positioning.
     if ($where == 'grid') {
         $block_classes[] = 'grid-width-' . $original_block['dimensions']['width'];
         $block_classes[] = 'grid-left-' . $original_block['position']['left'];
         $block_style_attr = ' style="height: ' . $original_block['dimensions']['height'] . 'px; top: ' . $original_block['position']['top'] . 'px;"';
     }
     //If the responsive grid is active, then add the responsive block hiding classes
     if (HeadwayResponsiveGrid::is_enabled()) {
         $responsive_block_hiding = headway_get('responsive-block-hiding', $block['settings'], array());
         if (is_array($responsive_block_hiding) && count($responsive_block_hiding) > 0) {
             foreach ($responsive_block_hiding as $device) {
                 $block_classes[] = 'responsive-block-hiding-device-' . $device;
             }
         }
     }
     //If it's a mirrored block, change $block to the mirrored block
     if ($mirrored_block = HeadwayBlocksData::is_block_mirrored($block)) {
         $block = $mirrored_block;
         $block['original'] = $original_block;
         //Add Classes for the mirroring
         $block_classes[] = 'block-mirrored';
         if ($where != 'grid') {
             $block_classes[] = 'block-mirroring-' . $mirrored_block['id'];
             $block_classes[] = 'block-original-' . $original_block_id;
         }
     }
     //Fetch the HTML tag for the block
     $block_tag = ($html_tag = headway_get('html-tag', $block_type_settings)) ? $html_tag : 'div';
     //The ID attribute for the block.  This will change if mirrored.
     $block_id_for_id_attr = $block['id'];
     //Original block ID to be used in the Visual Editor
     if (HeadwayRoute::is_visual_editor_iframe()) {
         $block_data_attrs = implode(' ', array('data-id="' . str_replace('block-', '', $original_block_id) . '"', 'data-block-mirror="' . (isset($mirrored_block) ? $mirrored_block['id'] : '') . '"', 'data-block-mirror-layout-name="' . (isset($mirrored_block) ? HeadwayLayout::get_name($mirrored_block['layout']) : '') . '"', 'data-grid-left="' . $original_block['position']['left'] . '"', 'data-grid-top="' . $original_block['position']['top'] . '"', 'data-width="' . $original_block['dimensions']['width'] . '"', 'data-height="' . $original_block['dimensions']['height'] . '"', 'data-alias="' . headway_get('alias', headway_get('settings', $original_block, array())) . '"'));
     } else {
         $block_data_attrs = null;
     }
     //The grid will display blocks entirely differently and not use hooks.
     if ($where != 'grid') {
         do_action('headway_before_block', $block);
         do_action('headway_before_block_' . $block['id'], $block);
         echo '<' . $block_tag . ' id="block-' . $block_id_for_id_attr . '" class="' . implode(' ', array_filter(apply_filters('headway_block_class', $block_classes, $block))) . '"' . $block_style_attr . $block_data_attrs . '>';
         do_action('headway_block_open', $block);
         do_action('headway_block_open_' . $block['id'], $block);
         echo '<div class="block-content">';
         do_action('headway_block_content_open', $block);
         do_action('headway_block_content_open_' . $block['id'], $block);
         do_action('headway_block_content_' . $block['type'], $block);
         do_action('headway_block_content_close', $block);
         do_action('headway_block_content_close_' . $block['id'], $block);
         echo '</div><!-- .block-content -->' . "\n";
         do_action('headway_block_close', $block);
         do_action('headway_block_close_' . $block['id'], $block);
         echo '</' . $block_tag . '><!-- #block-' . $block_id_for_id_attr . ' -->' . "\n";
         do_action('headway_after_block', $block);
         do_action('headway_after_block_' . $block['id'], $block);
         //Show the block in the grid
     } else {
         $show_content_in_grid = self::block_type_exists($block['type']) ? headway_get('show-content-in-grid', $block_type_settings, false) : false;
         if (!$show_content_in_grid) {
             $block_classes[] = 'hide-content-in-grid';
         }
         if (!self::block_type_exists($block['type'])) {
             $block_classes[] = 'block-error';
         }
         echo '<' . $block_tag . ' id="block-' . $block_id_for_id_attr . '" class="' . implode(' ', array_filter($block_classes)) . '"' . $block_style_attr . $block_data_attrs . '>';
         echo '<div class="block-content-fade block-content">';
         if (!self::block_type_exists($block['type'])) {
             self::unknown_block_content($block);
         } else {
             if (!$show_content_in_grid) {
                 echo '<p class="hide-content-in-grid-notice"><strong>Notice:</strong> <em>' . self::block_type_nice($block['type']) . '</em> blocks do not display in the Grid Mode.  Please switch to the Design mode to see the content in this block.</p>';
             }
         }
         echo '</div><!-- .block-content-fade -->' . "\n";
         echo '</' . $block_tag . '><!-- #block-' . $block_id_for_id_attr . ' -->' . "\n";
     }
     //Spit the ID back out
     return $block['id'];
 }
Exemplo n.º 8
0
 public static function export_block_settings($block_id)
 {
     /* Set up variables */
     $block = HeadwayBlocksData::get_block($block_id);
     /* Check if block exists */
     if (!$block) {
         die('Error: Could not export block settings.');
     }
     /* Spit the file out */
     return self::to_json('Block Settings - ' . HeadwayBlocksData::get_block_name($block), 'block-settings', array('id' => $block_id, 'type' => $block['type'], 'settings' => $block['settings'], 'styling' => HeadwayBlocksData::get_block_styling($block)));
 }
Exemplo n.º 9
0
 public static function save($options, $current_layout = false, $mode = false)
 {
     if (!$current_layout) {
         $current_layout = headway_post('layout');
     }
     if (!$mode) {
         $mode = headway_post('mode');
     }
     //Handle triple slash bullshit
     if (get_magic_quotes_gpc() === 1) {
         $options = array_map('stripslashes_deep', $options);
     }
     $blocks = isset($options['blocks']) ? $options['blocks'] : null;
     $wrappers = isset($options['wrappers']) ? $options['wrappers'] : null;
     $layout_options = isset($options['layout-options']) ? $options['layout-options'] : null;
     $options_inputs = isset($options['options']) ? $options['options'] : null;
     $design_editor_inputs = isset($options['design-editor']) ? $options['design-editor'] : null;
     //Set the current layout to customized if it's the grid mode
     if ($mode == 'grid') {
         HeadwayLayoutOption::set($current_layout, 'customized', true);
     }
     /* Blocks */
     if ($blocks) {
         foreach ($blocks as $id => $methods) {
             foreach ($methods as $method => $value) {
                 switch ($method) {
                     case 'new':
                         if (HeadwayBlocksData::get_block($id)) {
                             continue;
                         }
                         $dimensions = explode(',', $blocks[$id]['dimensions']);
                         $position = explode(',', $blocks[$id]['position']);
                         $settings = isset($blocks[$id]['settings']) ? $blocks[$id]['settings'] : array();
                         $args = array('id' => $id, 'type' => $value, 'position' => array('left' => $position[0], 'top' => $position[1]), 'dimensions' => array('width' => $dimensions[0], 'height' => $dimensions[1]), 'settings' => $settings);
                         HeadwayBlocksData::add_block($current_layout, $args);
                         break;
                     case 'delete':
                         HeadwayBlocksData::delete_block($current_layout, $id);
                         break;
                     case 'dimensions':
                         $dimensions = explode(',', $value);
                         $args = array('dimensions' => array('width' => $dimensions[0], 'height' => $dimensions[1]));
                         HeadwayBlocksData::update_block($current_layout, $id, $args);
                         break;
                     case 'position':
                         $position = explode(',', $value);
                         $args = array('position' => array('left' => $position[0], 'top' => $position[1]));
                         HeadwayBlocksData::update_block($current_layout, $id, $args);
                         break;
                     case 'wrapper':
                         $args = array('wrapper' => $value);
                         HeadwayBlocksData::update_block($current_layout, $id, $args);
                         break;
                     case 'settings':
                         //Retrieve all blocks from layout
                         $layout_blocks = HeadwayBlocksData::get_blocks_by_layout($current_layout);
                         //Get the block from the layout
                         $block = headway_get($id, $layout_blocks);
                         //If block doesn't exist, we can't do anything.
                         if (!$block) {
                             continue;
                         }
                         //If there aren't any options, then don't do anything either
                         if (!is_array($value) || count($value) === 0) {
                             continue;
                         }
                         $block['settings'] = array_merge($block['settings'], $value);
                         HeadwayBlocksData::update_block($current_layout, $id, $block);
                         break;
                 }
             }
         }
     }
     /* End Blocks */
     /* Wrappers */
     if ($wrappers) {
         /* Pluck last-id out of wrappers and send it to DB */
         if (headway_get('last-id', $wrappers)) {
             $last_id = $wrappers['last-id'];
             unset($wrappers['last-id']);
             HeadwayOption::set('last-id', $last_id, 'wrappers');
         }
         /* Save layout wrappers to dB */
         HeadwayOption::set($current_layout, $wrappers, 'wrappers');
     }
     /* End Wrappers */
     /* Layout Options */
     if ($layout_options) {
         foreach ($layout_options as $group => $options) {
             foreach ($options as $option => $value) {
                 HeadwayLayoutOption::set($current_layout, $option, $value, $group);
             }
         }
     }
     /* End Layout Options */
     /* Options */
     if ($options_inputs) {
         foreach ($options_inputs as $group => $options) {
             foreach ($options as $option => $value) {
                 HeadwayOption::set($option, $value, $group);
             }
         }
     }
     /* End Options */
     /* Design Editor Inputs */
     if ($design_editor_inputs) {
         /* If skin import is set to true then nuke all design settings to prevent overlapping settings */
         if (headway_get('skin-import', $design_editor_inputs)) {
             HeadwayElementsData::delete_all();
         }
         /* End skin import nuke */
         /* Handle skin templates */
         $skin_templates = headway_get('skin-import-templates', $design_editor_inputs);
         if (is_array($skin_templates) && count($skin_templates)) {
             $skin_template_block_id_translations = array();
             $skin_template_wrapper_id_translations = array();
             foreach ($skin_templates as $skin_template_name => $skin_template_blocks) {
                 /* Pluck wrappers array out of blocks array */
                 $skin_template_wrappers = $skin_template_blocks['wrappers'];
                 unset($skin_template_blocks['wrappers']);
                 $template = HeadwayLayout::add_template($skin_template_name, $skin_template_blocks, $skin_template_wrappers);
                 /* Use + rather than array_merge because + preserves numeric keys */
                 $skin_template_block_id_translations = $skin_template_block_id_translations + $template['block-id-translations'];
                 $skin_template_wrapper_id_translations = $skin_template_wrapper_id_translations + $template['wrapper-id-translations'];
             }
             /* Re-map block IDs in instances according to block ID translations */
             foreach ($design_editor_inputs as $element_id => $element_data) {
                 if (!is_array($element_data) || !isset($element_data['special-element-instance'])) {
                     continue;
                 }
                 foreach ($element_data['special-element-instance'] as $instance_id => $instance_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[1];
                     /* Wrapper instance conditional. Modify new instance ID accordingly */
                     if (strpos($instance_id, 'wrapper-') === 0 && isset($skin_template_wrapper_id_translations[intval($instance_potential_wrapper_id)])) {
                         $new_wrapper_id = $skin_template_wrapper_id_translations[intval($instance_potential_wrapper_id)]['id'];
                         $new_wrapper_layout = $skin_template_wrapper_id_translations[intval($instance_potential_wrapper_id)]['layout'];
                         $new_instance_id = 'wrapper-' . $new_wrapper_id . '-layout-' . $new_wrapper_layout;
                         /* Block instance conditional.  Modify new instance ID accordingly */
                     } else {
                         if (strpos($instance_id, 'block-') !== false && is_numeric($instance_potential_block_id) && isset($skin_template_block_id_translations[intval($instance_potential_block_id)])) {
                             $new_block_id = $skin_template_block_id_translations[intval($instance_potential_block_id)];
                             $new_instance_id = str_replace('block-' . $instance_potential_block_id, 'block-' . $new_block_id, $instance_id);
                             /* Not a proper block or wrapper instance, just skip it */
                         } else {
                             continue;
                         }
                     }
                     /* Remove existing instance key/value pair */
                     unset($design_editor_inputs[$element_id]['special-element-instance'][$instance_id]);
                     /* Add new instance key/value pair with new instance ID */
                     $design_editor_inputs[$element_id]['special-element-instance'][$new_instance_id] = $instance_properties;
                 }
             }
         }
         /* End skin template handling */
         /* Loop through to get every element and its properties */
         foreach ($design_editor_inputs as $element_id => $element_data) {
             if (!is_array($element_data) || !isset($element_data['group'])) {
                 continue;
             }
             $element_group = $element_data['group'];
             //Dispatch depending on type of element data
             foreach ($element_data as $element_data_node => $element_data_node_data) {
                 //Handle different nodes depending on what they are
                 if ($element_data_node == 'properties') {
                     //Set each property for the regular element
                     foreach ($element_data_node_data as $property_id => $property_value) {
                         HeadwayElementsData::set_property($element_group, $element_id, $property_id, $property_value);
                     }
                     //Handle instances, states, etc.
                 } else {
                     if (strpos($element_data_node, 'special-element-') === 0) {
                         $special_element_type = str_replace('special-element-', '', $element_data_node);
                         //Loop through the special elements
                         foreach ($element_data_node_data as $special_element => $special_element_properties) {
                             //Set the special element properties now
                             foreach ($special_element_properties as $special_element_property => $special_element_property_value) {
                                 HeadwayElementsData::set_special_element_property($element_group, $element_id, $special_element_type, $special_element, $special_element_property, $special_element_property_value);
                             }
                         }
                     }
                 }
             }
         }
         /* End loop */
     }
     /* End Design Editor Inputs */
     //This hook is used by cache flushing, plugins, etc.  Do not fire on preview save because it'll flush preview options
     if (!headway_get('ve-preview')) {
         do_action('headway_visual_editor_save');
     }
     return true;
 }
Exemplo n.º 10
0
 public static function method_load_block_options()
 {
     $layout = headway_post('layout');
     $block_id = headway_post('block_id');
     $unsaved_options = headway_post('unsaved_block_options', array());
     $block = HeadwayBlocksData::get_block($block_id);
     //If block is new, set the bare basics up
     if (!$block) {
         $block = array('type' => headway_post('block_type'), 'new' => true, 'id' => $block_id, 'layout' => $layout);
     }
     /* Merge unsaved options in */
     if (is_array($unsaved_options)) {
         $block['settings'] = is_array(headway_get('settings', $block)) ? array_merge($block['settings'], $unsaved_options) : $unsaved_options;
     }
     do_action('headway_block_options_' . $block['type'], $block, $layout);
 }