예제 #1
0
 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);
         }
     }
 }
예제 #2
0
 public static function is_seo_checkbox_enabled($option, $layout = false)
 {
     $seo_templates = self::get_seo_templates(self::current_seo_layout());
     if (HeadwayLayoutOption::get($layout, $option, 'seo', null) === null && !headway_get($option, $seo_templates)) {
         return false;
     }
     if (HeadwayLayoutOption::get($layout, $option, 'seo', null) === false) {
         return false;
     }
     return true;
 }
예제 #3
0
 /**
  * Assembles the classes for the posts.
  *
  * @global object $post
  * @global int $blog_post_alt
  * 
  * @param bool $print Determines whether or not to echo the post classes.
  * 
  * @return bool|string If $print is true, then echo the classes, otherwise just return them as a string. 
  **/
 function entry_class()
 {
     global $post, $blog_post_alt, $authordata;
     $c = get_post_class();
     if (!isset($blog_post_alt)) {
         $blog_post_alt = 1;
     }
     if (is_object($authordata)) {
         $c[] = 'author-' . sanitize_title_with_dashes(strtolower($authordata->user_login));
     }
     if (++$blog_post_alt % 2) {
         $c[] = 'alt';
     }
     //Add the custom classes from the meta box
     if ($custom_css_class = HeadwayLayoutOption::get(get_the_id(), 'css-class', null)) {
         $custom_css_classes = str_replace('  ', ' ', str_replace(',', ' ', htmlspecialchars(strip_tags($custom_css_class))));
         $c = array_merge($c, array_filter(explode(' ', $custom_css_classes)));
     }
     $c = join(' ', $c);
     return $c;
 }
예제 #4
0
 /**
  * If a post, page, or any other singular item has the 301 Redirect set, then do the redirect.
  **/
 public static function maybe_redirect_301()
 {
     global $post;
     //Don't try redirecting if the headers are already sent.  Otherwise, it'll result in an error and no redirect.
     if (headers_sent()) {
         return false;
     }
     //Make sure that it's a single post and that $post is a valid object.
     if (!is_object($post) || !is_singular()) {
         return false;
     }
     //Do not try redirecting if it's the visual editor or admin
     if (is_admin() || self::is_visual_editor() || self::is_visual_editor_iframe()) {
         return false;
     }
     //If the redirect URL isn't set, then don't try anything.
     if (!($redirect_url = HeadwayLayoutOption::get($post->ID, 'redirect-301', 'seo', false))) {
         return false;
     }
     //If there is no HTTP or HTTPS in the URL, add it.
     if (strpos($redirect_url, 'http://') !== 0 && strpos($redirect_url, 'https://') !== 0) {
         $redirect_url = 'http://' . $redirect_url;
     }
     wp_redirect($redirect_url, 301);
     die;
 }
예제 #5
0
 /**
  * Gets the status of the layout.  This will tell if it's customized, using a template, or none of the previous mentioned.
  * 
  * @return string
  **/
 public static function get_status($layout, $include_post_status = false)
 {
     $layout_parts = explode('-', $layout);
     $layout_end_part = end($layout_parts);
     $customized = HeadwayLayoutOption::get($layout, 'customized') === true ? true : false;
     $template = false;
     if ($possible_template = HeadwayLayoutOption::get($layout, 'template')) {
         if (self::template_exists($possible_template)) {
             $template = $possible_template;
         }
     }
     $status = array('customized' => $customized, 'template' => $template);
     /* If set to include post status and this is a single layout, fetch it */
     if ($include_post_status && $layout_parts[0] == 'single' && is_numeric($layout_end_part)) {
         /* Change status IDs to friendly statuses */
         $possible_statuses = array('publish', 'pending', 'draft', 'future', 'private');
         $friendly_status_names = array('Published', 'Pending Review', 'Draft', 'Scheduled', 'Private');
         $status['post_status'] = str_replace($possible_statuses, $friendly_status_names, get_post_status($layout_end_part));
     }
     return $status;
 }
예제 #6
0
 /**
  * For some reason, the 'blocks-by-id', 'blocks-by-type', and 'blocks-by-layout' options become blank.  This will restore them.
  **/
 public static function repair_blocks()
 {
     global $wpdb;
     /* Build layout options catalog */
     $catalog = array();
     foreach (wp_load_alloptions() as $option => $option_value) {
         if (strpos($option, 'headway_layout_options_') !== 0 || $option == 'headway_layout_options_catalog' || strpos($option, 'headway_layout_options_') === 0 && substr($option, -8) == '_preview') {
             continue;
         }
         $catalog[] = str_replace('headway_layout_options_', '', $option);
     }
     /* Set up blank arrays */
     $blocks_by_id = array();
     $blocks_by_type = array();
     $blocks_by_layout = array();
     foreach ($catalog as $layout) {
         /* If the layout is numeric, then check if the post even exists and isn't a revision.  If it does not exist or is a revision, delete it! */
         if (is_numeric($layout)) {
             $post_row = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->posts} WHERE ID = %d LIMIT 1", $layout));
             if ($post_row) {
                 $post_status = get_post_status($layout);
             }
             /* If the post row is false (doesn't exist) or post status is revision (AKA inherit) then delete the whole layout option group */
             if (!$post_row || $post_status == 'inherit') {
                 delete_option('headway_layout_options_' . $layout);
                 continue;
             }
         }
         $layout_options = get_option('headway_layout_options_' . $layout);
         //If there are no blocks, then skip the layout
         if (!isset($layout_options['general']['blocks']) || !is_array($layout_options['general']['blocks'])) {
             continue;
         }
         /* If the layout ID is template then change the underscore to a hyphen */
         if (strpos($layout, 'template_') === 0) {
             $layout = str_replace('template_', 'template-', $layout);
         }
         $layout_blocks = $layout_options['general']['blocks'];
         //If the layout is a template, then skip these two conditionals
         if (strpos($layout, 'template') !== 0) {
             //If the layout doesn't have any blocks, then remove the customized flag if it exists.
             if (!isset($layout_blocks) || !is_array($layout_blocks) || count($layout_blocks) === 0) {
                 HeadwayLayoutOption::delete($layout, 'customized');
                 continue;
             }
             //If the layout isn't customized and doesn't have a template assigned,
             //then nuke those blocks from the layout options and do not include them in the main block options
             if ((!isset($layout_options['general']['customized']) || $layout_options['general']['customized'] !== 'true') && (!isset($layout_options['general']['template']) || $layout_options['general']['template'] === 'false')) {
                 HeadwayLayoutOption::delete($layout, 'blocks');
                 continue;
             }
         }
         foreach ($layout_blocks as $block_id => $block) {
             /* Blocks by ID */
             $blocks_by_id[$block['id']] = array('layout' => $layout, 'type' => $block['type']);
             /* Blocks by type */
             if (!isset($blocks_by_type[$block['type']])) {
                 $blocks_by_type[$block['type']] = array();
             }
             $blocks_by_type[$block['type']][$block['id']] = $layout;
             /* Blocks by layout */
             if (!isset($blocks_by_layout[$layout])) {
                 $blocks_by_layout[$layout] = array();
             }
             $blocks_by_layout[$layout][$block['id']] = true;
         }
     }
     HeadwayOption::set('blocks-by-type', $blocks_by_type, 'blocks');
     HeadwayOption::set('blocks-by-id', $blocks_by_id, 'blocks');
     HeadwayOption::set('blocks-by-layout', $blocks_by_layout, 'blocks');
     return true;
 }
예제 #7
0
 /**
  * Assembles the classes for the body element.
  **/
 public static function body_class($c)
 {
     global $wp_query, $authordata;
     $c[] = 'custom';
     /* User Agents */
     if (!HeadwayCompiler::is_plugin_caching()) {
         $user_agent = $_SERVER['HTTP_USER_AGENT'];
         /* IE */
         if ($ie_version = headway_is_ie()) {
             $c[] = 'ie';
             $c[] = 'ie' . $ie_version;
         }
         /* Modern Browsers */
         if (stripos($user_agent, 'Safari') !== false) {
             $c[] = 'safari';
         } elseif (stripos($user_agent, 'Firefox') !== false) {
             $c[] = 'firefox';
         } elseif (stripos($user_agent, 'Chrome') !== false) {
             $c[] = 'chrome';
         } elseif (stripos($user_agent, 'Opera') !== false) {
             $c[] = 'opera';
         }
         /* Rendering Engines */
         if (stripos($user_agent, 'WebKit') !== false) {
             $c[] = 'webkit';
         } elseif (stripos($user_agent, 'Gecko') !== false) {
             $c[] = 'gecko';
         }
         /* Mobile */
         if (stripos($user_agent, 'iPhone') !== false) {
             $c[] = 'iphone';
         } elseif (stripos($user_agent, 'iPod') !== false) {
             $c[] = 'ipod';
         } elseif (stripos($user_agent, 'iPad') !== false) {
             $c[] = 'ipad';
         } elseif (stripos($user_agent, 'Android') !== false) {
             $c[] = 'android';
         }
     }
     /* End User Agents */
     /* Responsive Grid */
     if (HeadwayResponsiveGrid::is_enabled()) {
         $c[] = 'responsive-grid-enabled';
     }
     if (HeadwayResponsiveGrid::is_active()) {
         $c[] = 'responsive-grid-active';
     }
     /* Pages */
     if (is_page() && isset($wp_query->post) && isset($wp_query->post->ID)) {
         $c[] = 'pageid-' . $wp_query->post->ID;
         $c[] = 'page-slug-' . $wp_query->post->post_name;
     }
     /* Posts & Pages */
     if (is_singular() && isset($wp_query->post) && isset($wp_query->post->ID)) {
         //Add the custom classes from the meta box
         if ($custom_css_class = HeadwayLayoutOption::get($wp_query->post->ID, 'css-class', null)) {
             $custom_css_classes = str_replace('  ', ' ', str_replace(',', ' ', htmlspecialchars(strip_tags($custom_css_class))));
             $c = array_merge($c, array_filter(explode(' ', $custom_css_classes)));
         }
     }
     /* Layout IDs, etc */
     $c[] = 'layout-' . HeadwayLayout::get_current();
     $c[] = 'layout-using-' . HeadwayLayout::get_current_in_use();
     if (HeadwayRoute::is_visual_editor_iframe()) {
         $c[] = 've-iframe';
     }
     if (headway_get('ve-iframe-mode') && HeadwayRoute::is_visual_editor_iframe()) {
         $c[] = 'visual-editor-mode-' . headway_get('ve-iframe-mode');
     }
     if (!current_theme_supports('headway-design-editor')) {
         $c[] = 'design-editor-disabled';
     }
     $c = array_unique(array_filter($c));
     return $c;
 }
예제 #8
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;
 }
예제 #9
0
 public static function secure_method_remove_template_from_layout()
 {
     $layout = headway_post('layout');
     //Remove the template flag
     if (!HeadwayLayoutOption::set($layout, 'template', false)) {
         echo 'failure';
         return;
     }
     if (HeadwayLayoutOption::get($layout, 'customized', false) === true) {
         echo 'customized';
         return;
     }
     do_action('headway_visual_editor_unassign_template');
     echo 'success';
 }