コード例 #1
0
 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);
 }
コード例 #2
0
ファイル: admin.php プロジェクト: danaiser/hollandLawns
 public static function form_action_save()
 {
     //Form action for all Headway configuration panels.  Not in function/hook so it can load before everything else.
     if (!headway_post('headway-submit', false)) {
         return false;
     }
     if (!wp_verify_nonce(headway_post('headway-admin-nonce', false), 'headway-admin-nonce')) {
         global $headway_admin_save_message;
         $headway_admin_save_message = 'Security nonce did not match.';
         return false;
     }
     foreach (headway_post('headway-admin-input', array()) as $option => $value) {
         HeadwayOption::set($option, $value);
     }
     global $headway_admin_save_message;
     $headway_admin_save_message = 'Settings saved.';
     return true;
 }
コード例 #3
0
ファイル: compiler.php プロジェクト: danaiser/hollandLawns
 /**
  * @return bool
  **/
 public static function flush_cache($hard = false)
 {
     //Flush Headway cache if it is active.
     if (self::can_cache()) {
         //Delete the Headway cache option if hard flush otherwise delete the ones that aren't set to stay with soft flush
         if ($hard) {
             HeadwayOption::delete('cache');
         } else {
             $cache = HeadwayOption::get('cache');
             foreach ($cache as $cached_file_id => $cached_file) {
                 if (!headway_get('require-hard-flush', $cached_file, false)) {
                     unset($cache[$cached_file_id]);
                 }
             }
             HeadwayOption::set('cache', $cache);
         }
         //Set do not delete list
         $no_delete = array('..', '.');
         if ($handle = opendir(HEADWAY_CACHE_DIR)) {
             while (false !== ($file = readdir($handle))) {
                 if (in_array($file, $no_delete) || strpos($file, 'hard-cache') !== false && !$hard) {
                     continue;
                 }
                 @unlink(HEADWAY_CACHE_DIR . '/' . $file);
             }
             closedir($handle);
         }
     }
     //Flush plugin caches
     self::flush_plugin_caches();
     return true;
 }
コード例 #4
0
ファイル: layout.php プロジェクト: danaiser/hollandLawns
 public static function add_template($template_name = null, $blocks = null, $wrappers = null)
 {
     $templates = HeadwayOption::get('list', 'templates', array());
     $last_template_id = HeadwayOption::get('last-id', 'templates', 0);
     /* These  two variables be used for when a blocks/wrappers imported ID is different than the one that it ends up with... i.g. skin importing to line up instances */
     $block_id_translations = array();
     $wrapper_id_translations = array();
     /* Build name */
     $id = $last_template_id + 1;
     $template_name = $template_name ? $template_name : 'Template ' . $id;
     /* Add template to templates array so it can be sent to DB */
     $templates[$id] = $template_name;
     /* Send array to DB */
     HeadwayOption::set('list', $templates, 'templates');
     HeadwayOption::set('last-id', $id, 'templates');
     /* Add blocks and wrappers */
     if ($blocks && $wrappers) {
         /* Format wrappers */
         foreach ($wrappers as $wrapper_id => $wrapper_settings) {
             $old_wrapper_id = $wrapper_id;
             $new_wrapper = HeadwayWrappers::add_wrapper('template-' . $id, $wrapper_settings);
             $wrapper_id_translations[str_replace('wrapper-', '', $old_wrapper_id)] = array('id' => $new_wrapper['id'], 'layout' => 'template-' . $id);
         }
         /* Add blocks */
         foreach ($blocks as $block) {
             $old_block_id = $block['id'];
             unset($block['id']);
             unset($block['layout']);
             /* Update block's wrapper ID to match the real ID of the imported wrapper because if you link to the old ID from the export file then it won't match up */
             $block['wrapper'] = 'wrapper-' . $wrapper_id_translations[str_replace('wrapper-', '', $block['wrapper'])]['id'];
             $new_block_id = HeadwayBlocksData::add_block('template-' . $id, $block);
             $block_id_translations[$old_block_id] = $new_block_id;
         }
     }
     /* End adding wrappers and blocks */
     return array('id' => $id, 'name' => $template_name, 'block-id-translations' => $block_id_translations, 'wrapper-id-translations' => $wrapper_id_translations);
 }
コード例 #5
0
ファイル: maintenance.php プロジェクト: danaiser/hollandLawns
 /**
  * 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;
 }
コード例 #6
0
ファイル: blocks.php プロジェクト: danaiser/hollandLawns
 public static function clear_block_actions_cache()
 {
     HeadwayOption::set('init', array(), 'block-actions-cache');
     HeadwayOption::set('enqueue', array(), 'block-actions-cache');
     HeadwayOption::set('dynamic-js', array(), 'block-actions-cache');
     HeadwayOption::set('dynamic-css', array(), 'block-actions-cache');
     HeadwayOption::set('block-objects', array(), 'block-actions-cache');
     return HeadwayOption::set('cached', false, 'block-actions-cache');
 }
コード例 #7
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;
 }
コード例 #8
0
 public static function delete_special_element_properties($element_group, $element_id, $special_element_type, $special_element_meta)
 {
     $element = HeadwayOption::get($element_id, 'design-editor-group-' . $element_group);
     /* Delete all special elements matching the meta and type */
     if (isset($element['special-element-' . $special_element_type][$special_element_meta])) {
         unset($element['special-element-' . $special_element_type][$special_element_meta]);
     }
     /* Send it back to DB */
     return HeadwayOption::set($element_id, $element, 'design-editor-group-' . $element_group);
 }
コード例 #9
0
ファイル: wrappers.php プロジェクト: danaiser/hollandLawns
 public static function add_wrapper($layout_id, $wrapper_settings)
 {
     $existing_wrappers = self::get_layout_wrappers($layout_id);
     /* Delete the default wrapper */
     if (isset($existing_wrappers['wrapper-default'])) {
         unset($existing_wrappers['wrapper-default']);
     }
     $last_wrapper_id = HeadwayOption::get('last-id', 'wrappers');
     $new_wrapper_id = $last_wrapper_id + 1;
     /* Prepare wrapper settings for new ID and clear out mirroring */
     if (isset($wrapper_settings['layout'])) {
         unset($wrapper_settings['layout']);
     }
     if (isset($wrapper_settings['id'])) {
         unset($wrapper_settings['id']);
     }
     if (isset($wrapper_settings['mirror-wrapper'])) {
         unset($wrapper_settings['mirror-wrapper']);
     }
     /* Add wrapper */
     $existing_wrappers['wrapper-' . $new_wrapper_id] = $wrapper_settings;
     /* Save wrappers array with new wrapper to layout */
     HeadwayOption::set($layout_id, $existing_wrappers, 'wrappers');
     /* Save last wrapper ID back to DB */
     HeadwayOption::set('last-id', $new_wrapper_id, 'wrappers');
     return array('id' => $new_wrapper_id, 'wrapper' => $wrapper_settings);
 }
コード例 #10
0
 public static function method_change_grid_height()
 {
     $grid_height = headway_post('grid_height');
     //Make sure the grid height is numeric and at least 800px
     if (!is_numeric($grid_height) || $grid_height < 800) {
         return false;
     }
     HeadwayOption::set('grid-height', $grid_height);
 }