public static function form_action_maintenance() { //Form action for all Headway configuration panels. Not in function/hook so it can load before everything else. if (!headway_post('headway-maintenance-nonce', false)) { return false; } //Check the nonce for security if (!wp_verify_nonce(headway_post('headway-maintenance-nonce', false), 'headway-maintenance-nonce')) { $GLOBALS['headway_admin_save_message'] = 'Security nonce did not match.'; return false; } //Load the maintenance class Headway::load('common/maintenance'); //Handle block repair if (headway_post('repair-blocks', false)) { HeadwayMaintenance::repair_blocks(); $GLOBALS['headway_admin_save_message'] = 'Blocks have successfully been repaired.'; } return true; }
static function clone_pages_select_walker($pages, $depth = 0) { $return = ''; foreach ($pages as $id => $children) { $layout_id_fragments = explode('-', $id); $status = HeadwayLayout::get_status($id); /* Take care of layouts that are the front page or blog index */ if (get_option('show_on_front') === 'page' && (isset($layout_id_fragments[1]) && $layout_id_fragments[1] == 'page')) { /* If the page is set as the static homepage or blog page, hide it if they don't have children. */ if (end($layout_id_fragments) == get_option('page_on_front') || end($layout_id_fragments) == get_option('page_for_posts')) { /* Layout has children--add the no edit class and has children class. */ if (is_array($children) && count($children) !== 0) { $disabled = true; } else { continue; } } } /* Handle layouts that aren't customized or have a template */ if (headway_get('customized', $status, false) === false || headway_get('template', $status, false) !== false) { /* If there ARE customized children, add the no-edit class */ if (is_array($children) && count($children) !== 0) { /* Check if the children are customized. */ if (HeadwayVisualEditorDisplay::is_any_layout_child_customized($children)) { $disabled = true; } else { continue; } /* If there aren't any children, do not display the node at all */ } else { continue; } } /* If the current layout is selected, then make it disabled. */ if (headway_post('layout') == $id) { $disabled = true; } /* Output Stuff */ $depth_display = str_repeat(' ', $depth); $disabled = isset($disabled) && $disabled === true ? ' disabled="disabled"' : null; $return .= '<option value="' . $id . '"' . $disabled . '>' . $depth_display . HeadwayLayout::get_name($id) . '</option>'; if (is_array($children) && count($children) !== 0) { $return .= self::clone_pages_select_walker($children, $depth + 1); } } return $return; }
public function save($post_ID, $post) { //If it is our form has not been submitted, so we dont want to do anything if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return; } //Ruh-roh, bad nonce if (!wp_verify_nonce(headway_post($this->id . '_nonce'), md5($this->id))) { return false; } $post_ID = $post->ID; //Check for capabilities if ($_POST['post_type'] === 'page' && !current_user_can('edit_page', $post_ID)) { return false; } if (!current_user_can('edit_post', $post_ID)) { return false; } //If there are no options, then there's nothing to save if (!isset($_POST[$this->id]) || !is_array($_POST[$this->id])) { return false; } //Loop through and set the options foreach ($_POST[$this->id] as $group => $inputs) { foreach ($inputs as $input => $value) { HeadwayLayoutOption::set($post_ID, $input, $value, $group); } } }
public function list_fonts($sortby = false) { if (headway_post('sortby')) { $sortby = headway_post('sortby'); } if (!($fonts = $this->retrieve_fonts($sortby))) { echo '<p class="error">Unable to retrieve fonts at this time.</p>'; return; } /* Display possible error */ if (isset($fonts['error'])) { echo '<p class="error">' . $fonts['error'] . '</p>'; return; } /* Output the fonts */ foreach ($fonts as $font) { echo ' <li data-value="' . $font['id'] . '" style="font-family:' . $font['stack'] . ';" data-variants="' . htmlspecialchars(json_encode(headway_get('variants', $font, array()))) . '"> <span class="font-family">' . $font['name'] . '</span> <span class="font-preview-text">The quick brown fox jumps over the lazy dog.</span> <span title="Use Font" class="use-font action"></span> <span title="Preview Font" class="preview-font action"></span> </li> '; } return true; }
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 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; }
public static function list_templates() { $templates = HeadwayLayout::get_templates(); $return = ''; $return .= '<ul>' . "\n"; $no_templates_display = count($templates) === 0 ? null : ' style="display:none;"'; $return .= '<li class="layout-item info-layout-item" id="no-templates"' . $no_templates_display . '><span class="layout"><strong>There are no templates to display, add one!</strong></span></li>'; foreach ($templates as $id => $name) { $class = array('layout-item'); $class[] = $id === headway_post('currentLayout') ? 'layout-selected' : null; //Output stuff $return .= "\n" . '<li class="' . implode(' ', array_filter($class)) . '">' . "\n"; $return .= "\n" . ' <span data-layout-id="template-' . $id . '" class="layout layout-template"> <strong class="template-name">' . HeadwayLayout::get_name('template-' . $id) . '</strong> <span class="delete-template" title="Delete Template">Delete</span> <span class="status status-currently-editing">Currently Editing</span> <span class="assign-template layout-selector-button">Use Template</span> <span class="edit layout-selector-button">Edit</span> </span>' . "\n"; $return .= '</li>' . "\n"; } $return .= '</ul>' . "\n"; return $return; }
public static function method_import_images() { Headway::load('data/data-portability'); /* Set up variables */ $import_file = headway_post('importFile'); $image_definitions = headway_get('image-definitions', $import_file, array()); $imported_images = array(); /* Loop through base64'd images and move them to uploads directory */ foreach ($image_definitions as $image_id => $image) { $imported_images[$image_id] = HeadwayDataPortability::decode_image_to_uploads($image['base64_contents']); } /* Replace image variables in the import file */ foreach ($imported_images as $imported_image_id => $imported_image) { /* Handle sideloading errors */ if (headway_get('error', $imported_image)) { /* Replace entire array with error to stop import of settings */ $import_file = array('error' => headway_get('error', $imported_image)); } else { if (headway_get('url', $imported_image)) { $import_file = self::import_images_recursive_replace($imported_image_id, $imported_image['url'], $import_file); } } } /* Remove giant image definitions from import file */ unset($import_file['image-definitions']); /* Send import file with images replaced back to Visual Editor */ self::json_encode($import_file); }