Example #1
1
function thb_import_theme_options()
{
    $file = get_template_directory_uri() . "/inc/democontent/theme-options.txt";
    $theme_options_txt = wp_remote_get($file);
    $options = unserialize(ot_decode($theme_options_txt['body']));
    /* get settings array */
    $settings = get_option(ot_settings_id());
    /* validate options */
    foreach ($settings['settings'] as $setting) {
        if (isset($options[$setting['id']])) {
            $content = ot_stripslashes($options[$setting['id']]);
            $options[$setting['id']] = ot_validate_setting($content, $setting['type'], $setting['id']);
        }
    }
    /* update the option tree array */
    update_option(ot_options_id(), $options);
    $message = 'success';
}
/**
 * Add HTML5 Boilerplate's .htaccess via WordPress
 */
function uncode_add_h5bp_htaccess()
{
    $options = get_option(ot_options_id());
    $theme_opt = $options['_uncode_htaccess'];
    $saved_opt = get_option("_uncode_htaccess_performace");
    if ($theme_opt === 'on' && $saved_opt !== 'on' || $theme_opt === 'off' && $saved_opt === 'on') {
        global $wp_rewrite;
        $home_path = function_exists('get_home_path') ? get_home_path() : ABSPATH;
        $htaccess_file = $home_path . '.htaccess';
        $mod_rewrite_enabled = function_exists('got_mod_rewrite') ? got_mod_rewrite() : false;
        if (!file_exists($htaccess_file) && is_writable($home_path) && $wp_rewrite->using_mod_rewrite_permalinks() || is_writable($htaccess_file)) {
            if ($mod_rewrite_enabled) {
                $h5bp_rules = extract_from_markers($htaccess_file, 'HTML5 Boilerplate');
                if ($h5bp_rules === array()) {
                    $filename = dirname(__FILE__) . '/h5bp-htaccess';
                    update_option("_uncode_htaccess_performace", $theme_opt);
                    return insert_with_markers($htaccess_file, 'HTML5 Boilerplate', extract_from_markers($filename, 'HTML5 Boilerplate'));
                } else {
                    if ($theme_opt === 'off') {
                        update_option("_uncode_htaccess_performace", $theme_opt);
                        return insert_with_markers($htaccess_file, 'HTML5 Boilerplate', '');
                    }
                }
            }
        }
    }
}
 function ot_get_option($option_id, $default = '')
 {
     /* get the saved options */
     $options = get_option(ot_options_id());
     /* look for the saved value */
     if (isset($options[$option_id]) && '' != $options[$option_id]) {
         return ot_wpml_filter($options, $option_id);
     }
     return $default;
 }
 /**
  * Export Data option type.
  */
 function ot_type_export_data()
 {
     /* format setting outer wrapper */
     echo '<div class="format-setting type-textarea simple">';
     /* get theme options data */
     $data = get_option(ot_options_id());
     $data = !empty($data) ? ot_encode(serialize($data)) : '';
     echo '<div class="format-setting-inner">' . PHP_EOL;
     echo '<textarea rows="10" cols="40" name="export_data" id="export_data" class="textarea">' . $data . '</textarea>' . PHP_EOL;
     echo '</div>' . PHP_EOL;
     echo '</div>' . PHP_EOL;
 }
 function get_option($option_id, $default = false)
 {
     if (class_exists('OT_Loader') and function_exists('ot_options_id')) {
         /* get the saved options */
         $options = get_option(ot_options_id());
         /* look for the saved value */
         if (isset($options[$option_id]) && '' != $options[$option_id]) {
             return $options[$option_id];
         }
         return $default;
     }
     return $default;
 }
Example #6
0
 function ot_get_option($option_id, $default = '')
 {
     //temporary hack
     if (!apply_filters('use_option_tree', true) && class_exists('HU_utils')) {
         return HU_utils::$inst->hu_opt($option_id);
     }
     /* get the saved options */
     $options = get_option(ot_options_id());
     /* look for the saved value */
     if (isset($options[$option_id]) && '' != $options[$option_id]) {
         return ot_wpml_filter($options, $option_id);
     }
     return $default;
 }
Example #7
0
 function ot_type_export_data()
 {
     /* format setting outer wrapper */
     echo '<div class="format-setting type-textarea simple has-desc">';
     /* description */
     echo '<div class="description">';
     echo '<p>' . __('Export your Theme Options data by highlighting this text and doing a copy/paste into a blank .txt file. Then save the file for importing into another install of WordPress later. Alternatively, you could just paste it into the <code>Import/export->Import</code> <strong>Theme Options</strong> textarea on another web site.', 'option-tree') . '</p>';
     echo '</div>';
     /* get theme options data */
     $data = get_option(ot_options_id());
     $data = !empty($data) ? ot_encode(serialize($data)) : '';
     echo '<div class="format-setting-inner">';
     echo '<textarea rows="10" cols="40" name="export_data" id="export_data" class="textarea">' . $data . '</textarea>';
     echo '</div>';
     echo '</div>';
 }
 function get_option_tree($item_id = '', $options = '', $echo = false, $is_array = false, $offset = -1)
 {
     /* load saved options */
     if (!$options) {
         $options = get_option(ot_options_id());
     }
     /* no value return */
     if (!isset($options[$item_id]) || empty($options[$item_id])) {
         return;
     }
     /* set content value & strip slashes */
     $content = option_tree_stripslashes($options[$item_id]);
     /* is an array */
     if ($is_array == true) {
         /* saved as a comma seperated lists of values, explode into an array */
         if (!is_array($content)) {
             $content = explode(',', $content);
         }
         /* get an array value using an offset */
         if (is_numeric($offset) && $offset >= 0) {
             $content = $content[$offset];
         } else {
             if (!is_numeric($offset) && isset($content[$offset])) {
                 $content = $content[$offset];
             }
         }
         /* not an array */
     } else {
         if ($is_array == false) {
             /* saved as array, implode and return a comma seperated lists of values */
             if (is_array($content)) {
                 $content = implode(',', $content);
             }
             /* This is f****d */
         }
     }
     /* echo content */
     if ($echo) {
         echo $content;
     }
     return $content;
 }
 static function _get_custom_css()
 {
     $html = false;
     /* grab a copy of the settings */
     $settings = get_option(ot_settings_id());
     $options = get_option(ot_options_id());
     /* has settings */
     if (isset($settings['settings'])) {
         /* loop through sections and insert CSS when needed */
         foreach ($settings['settings'] as $k => $setting) {
             $allows = self::_options_allow_output();
             if (!empty($allows) and in_array($setting['type'], $allows) and isset($setting['output']) and $setting['output']) {
                 if (isset($options[$setting['id']])) {
                     $html .= self::_get_output_item_css($setting, $options[$setting['id']]);
                 }
             }
         }
     }
     return $html;
 }
 function ot_maybe_migrate_options()
 {
     // Filter the ID to migrate from
     $options_id = apply_filters('ot_migrate_options_id', '');
     // Attempt to migrate Theme Options
     if (!empty($options_id) && get_option(ot_options_id()) === false && ot_options_id() !== $options_id) {
         // Old options
         $options = get_option($options_id);
         // Migrate to new ID
         update_option(ot_options_id(), $options);
     }
 }
Example #11
0
 function compat_ot_import_from_files()
 {
     /* file path & name without extention */
     $ot_xml = '/option-tree/theme-options.xml';
     $ot_data = '/option-tree/theme-options.txt';
     $ot_layout = '/option-tree/layouts.txt';
     /* XML file path - child theme first then parent */
     if (is_readable(get_stylesheet_directory() . $ot_xml)) {
         $xml_file = get_stylesheet_directory_uri() . $ot_xml;
     } else {
         if (is_readable(get_template_directory() . $ot_xml)) {
             $xml_file = get_template_directory_uri() . $ot_xml;
         }
     }
     /* Data file path - child theme first then parent */
     if (is_readable(get_stylesheet_directory() . $ot_data)) {
         $data_file = get_stylesheet_directory_uri() . $ot_data;
     } else {
         if (is_readable(get_template_directory() . $ot_data)) {
             $data_file = get_template_directory_uri() . $ot_data;
         }
     }
     /* Layout file path - child theme first then parent */
     if (is_readable(get_stylesheet_directory() . $ot_layout)) {
         $layout_file = get_stylesheet_directory_uri() . $ot_layout;
     } else {
         if (is_readable(get_template_directory() . $ot_layout)) {
             $layout_file = get_template_directory_uri() . $ot_layout;
         }
     }
     /* check for files */
     $has_xml = isset($xml_file) ? true : false;
     $has_data = isset($data_file) ? true : false;
     $has_layout = isset($layout_file) ? true : false;
     /* auto import XML file */
     if ($has_xml == true && !get_option(ot_settings_id()) && class_exists('SimpleXMLElement')) {
         $settings = ot_import_xml($xml_file);
         if (isset($settings) && !empty($settings)) {
             update_option(ot_settings_id(), $settings);
         }
     }
     /* auto import Data file */
     if ($has_data == true && !get_option(ot_options_id())) {
         $get_data = wp_remote_get($data_file);
         if (is_wp_error($get_data)) {
             return false;
         }
         $rawdata = isset($get_data['body']) ? $get_data['body'] : '';
         $options = unserialize(ot_decode($rawdata));
         /* get settings array */
         $settings = get_option(ot_settings_id());
         /* has options */
         if (is_array($options)) {
             /* validate options */
             if (is_array($settings)) {
                 foreach ($settings['settings'] as $setting) {
                     if (isset($options[$setting['id']])) {
                         $content = ot_stripslashes($options[$setting['id']]);
                         $options[$setting['id']] = ot_validate_setting($content, $setting['type'], $setting['id']);
                     }
                 }
             }
             /* update the option tree array */
             update_option(ot_options_id(), $options);
         }
     }
     /* auto import Layout file */
     if ($has_layout == true && !get_option(ot_layouts_id())) {
         $get_data = wp_remote_get($layout_file);
         if (is_wp_error($get_data)) {
             return false;
         }
         $rawdata = isset($get_data['body']) ? $get_data['body'] : '';
         $layouts = unserialize(ot_decode($rawdata));
         /* get settings array */
         $settings = get_option(ot_settings_id());
         /* has layouts */
         if (is_array($layouts)) {
             /* validate options */
             if (is_array($settings)) {
                 foreach ($layouts as $key => $value) {
                     if ($key == 'active_layout') {
                         continue;
                     }
                     $options = unserialize(ot_decode($value));
                     foreach ($settings['settings'] as $setting) {
                         if (isset($options[$setting['id']])) {
                             $content = ot_stripslashes($options[$setting['id']]);
                             $options[$setting['id']] = ot_validate_setting($content, $setting['type'], $setting['id']);
                         }
                     }
                     $layouts[$key] = ot_encode(serialize($options));
                 }
             }
             /* update the option tree array */
             if (isset($layouts['active_layout'])) {
                 update_option(ot_options_id(), unserialize(ot_decode($layouts[$layouts['active_layout']])));
             }
             /* update the option tree layouts array */
             update_option(ot_layouts_id(), $layouts);
         }
     }
 }
Example #12
0
<?php

/* =============================================================================
	Include the Option-Tree Google Fonts Plugin
	========================================================================== */
// load the ot-google-fonts plugin if the loader class is available
if (class_exists('OT_Loader')) {
    global $ot_options;
    $ot_options_id = ot_options_id();
    $ot_options = get_option($ot_options_id);
    // default fonts used in this theme, even though there are no google fonts
    $default_theme_fonts = array('arial' => 'Arial, Helvetica, sans-serif', 'helvetica' => 'Helvetica, Arial, sans-serif', 'georgia' => 'Georgia, "Times New Roman", Times, serif', 'tahoma' => 'Tahoma, Geneva, sans-serif', 'times' => '"Times New Roman", Times, serif', 'trebuchet' => '"Trebuchet MS", Arial, Helvetica, sans-serif', 'verdana' => 'Verdana, Geneva, sans-serif');
    defined('OT_FONT_DEFAULTS') or define('OT_FONT_DEFAULTS', serialize($default_theme_fonts));
    defined('OT_FONT_API_KEY') or define('OT_FONT_API_KEY', 'AIzaSyBmzfJsfXkXP9PUvwfq53jA1l1YJNxBT4g');
    // enter your own Google Font API key here
    defined('OT_FONT_CACHE_INTERVAL') or define('OT_FONT_CACHE_INTERVAL', 0);
    // Checking once a week for new Fonts. The time interval for the remote XML cache in the database (21600 seconds = 6 hours)
    // get the OT-Google-Font plugin file
    include_once get_template_directory() . '/option-tree-google-fonts/ot-google-fonts.php';
    // get the google font array - build in ot-google-fonts.php
    $google_font_array = ot_get_google_font(OT_FONT_API_KEY, OT_FONT_CACHE_INTERVAL);
    // Now apply the fonts to the font dropdowns in theme options with the build in OptionTree hook
    function ot_filter_recognized_font_families($array, $field_id)
    {
        global $google_font_array;
        // loop through the cached google font array if available and append to default fonts
        $font_array = array();
        if ($google_font_array) {
            foreach ($google_font_array as $index => $value) {
                $font_array[$index] = $value['family'];
            }
 public function set_demo_theme_options($file)
 {
     $response = wp_remote_get(esc_url_raw($file));
     /* Will result in $api_response being an array of data,
     		parsed from the JSON response of the API listed above */
     $data = wp_remote_retrieve_body($response);
     // Have valid data?
     // If no data or could not decode
     if (empty($data)) {
         wp_die(esc_html__('Theme options import data could not be read. Please try a different file.', 'radium'), '', array('back_link' => true));
     }
     /* textarea value */
     $options = unserialize(base64_decode($data));
     /* get settings array */
     $settings = get_option(ot_settings_id());
     /* has options */
     if (is_array($options)) {
         /* validate options */
         if (is_array($settings)) {
             foreach ($settings['settings'] as $setting) {
                 if (isset($options[$setting['id']])) {
                     $content = ot_stripslashes($options[$setting['id']]);
                     $options[$setting['id']] = ot_validate_setting($content, $setting['type'], $setting['id']);
                 }
             }
         }
         /* update the option tree array */
         update_option(ot_options_id(), $options);
         /* execute the action hook and pass the theme options to it */
         do_action('ot_after_theme_options_save', $options);
     }
 }
/**
 * Update terms when a term gets split.
 *
 * @param     int     $term_id ID of the formerly shared term.
 * @param     int     $new_term_id ID of the new term created for the $term_taxonomy_id.
 * @param     int     $term_taxonomy_id ID for the term_taxonomy row affected by the split.
 * @param     string  $taxonomy Taxonomy for the split term.
 * @return    void
 *
 * @access    public
 * @since     2.5.4
 */
function ot_split_shared_term($term_id, $new_term_id, $term_taxonomy_id, $taxonomy)
{
    // Process the Theme Options
    $settings = _ot_settings_potential_shared_terms();
    $old_options = get_option(ot_options_id(), array());
    $new_options = $old_options;
    // Process the saved settings
    if (!empty($settings) && !empty($old_options)) {
        // Loop over the Theme Options
        foreach ($settings as $option) {
            if (!is_array($option['taxonomy'])) {
                $option['taxonomy'] = explode(',', $option['taxonomy']);
            }
            if (!in_array($taxonomy, $option['taxonomy'])) {
                continue;
            }
            // The option ID was found
            if (array_key_exists($option['id'], $old_options) || isset($option['parent']) && array_key_exists($option['parent'], $old_options)) {
                // This is a list item, we have to go deeper
                if (isset($option['parent'])) {
                    // Loop over the array
                    foreach ($option['value'] as $key => $value) {
                        // The value is an array of IDs
                        if (is_array($value)) {
                            // Loop over the sub array
                            foreach ($value as $sub_key => $sub_value) {
                                if ($sub_value == $term_id) {
                                    unset($new_options[$option['parent']][$key][$option['id']][$sub_key]);
                                    $new_options[$option['parent']][$key][$option['id']][$new_term_id] = $new_term_id;
                                }
                            }
                        } else {
                            if ($value == $term_id) {
                                unset($new_options[$option['parent']][$key][$option['id']]);
                                $new_options[$option['parent']][$key][$option['id']] = $new_term_id;
                            }
                        }
                    }
                } else {
                    // The value is an array of IDs
                    if (is_array($option['value'])) {
                        // Loop over the array
                        foreach ($option['value'] as $key => $value) {
                            // It's a single value, just replace it
                            if ($value == $term_id) {
                                unset($new_options[$option['id']][$key]);
                                $new_options[$option['id']][$new_term_id] = $new_term_id;
                            }
                        }
                        // It's a single value, just replace it
                    } else {
                        if ($option['value'] == $term_id) {
                            $new_options[$option['id']] = $new_term_id;
                        }
                    }
                }
            }
        }
    }
    // Options need to be updated
    if ($old_options !== $new_options) {
        update_option(ot_options_id(), $new_options);
    }
    // Process the Meta Boxes
    $meta_settings = _ot_meta_box_potential_shared_terms();
    $option_types = array('category-checkbox', 'category-select', 'tag-checkbox', 'tag-select', 'taxonomy-checkbox', 'taxonomy-select');
    if (!empty($meta_settings)) {
        $old_meta = array();
        foreach ($meta_settings as $option) {
            if (!is_array($option['taxonomy'])) {
                $option['taxonomy'] = explode(',', $option['taxonomy']);
            }
            if (!in_array($taxonomy, $option['taxonomy'])) {
                continue;
            }
            if (isset($option['children'])) {
                $post_ids = get_posts(array('fields' => 'ids', 'meta_key' => $option['id']));
                if ($post_ids) {
                    foreach ($post_ids as $post_id) {
                        // Get the meta
                        $old_meta = get_post_meta($post_id, $option['id'], true);
                        $new_meta = $old_meta;
                        // Has a saved value
                        if (!empty($old_meta) && is_array($old_meta)) {
                            // Loop over the array
                            foreach ($old_meta as $key => $value) {
                                foreach ($value as $sub_key => $sub_value) {
                                    if (in_array($sub_key, $option['children'])) {
                                        // The value is an array of IDs
                                        if (is_array($sub_value)) {
                                            // Loop over the array
                                            foreach ($sub_value as $sub_sub_key => $sub_sub_value) {
                                                // It's a single value, just replace it
                                                if ($sub_sub_value == $term_id) {
                                                    unset($new_meta[$key][$sub_key][$sub_sub_key]);
                                                    $new_meta[$key][$sub_key][$new_term_id] = $new_term_id;
                                                }
                                            }
                                            // It's a single value, just replace it
                                        } else {
                                            if ($sub_value == $term_id) {
                                                $new_meta[$key][$sub_key] = $new_term_id;
                                            }
                                        }
                                    }
                                }
                            }
                            // Update
                            if ($old_meta !== $new_meta) {
                                update_post_meta($post_id, $option['id'], $new_meta, $old_meta);
                            }
                        }
                    }
                }
            } else {
                $post_ids = get_posts(array('fields' => 'ids', 'meta_query' => array('key' => $option['id'], 'value' => $term_id, 'compare' => 'IN')));
                if ($post_ids) {
                    foreach ($post_ids as $post_id) {
                        // Get the meta
                        $old_meta = get_post_meta($post_id, $option['id'], true);
                        $new_meta = $old_meta;
                        // Has a saved value
                        if (!empty($old_meta)) {
                            // The value is an array of IDs
                            if (is_array($old_meta)) {
                                // Loop over the array
                                foreach ($old_meta as $key => $value) {
                                    // It's a single value, just replace it
                                    if ($value == $term_id) {
                                        unset($new_meta[$key]);
                                        $new_meta[$new_term_id] = $new_term_id;
                                    }
                                }
                                // It's a single value, just replace it
                            } else {
                                if ($old_meta == $term_id) {
                                    $new_meta = $new_term_id;
                                }
                            }
                            // Update
                            if ($old_meta !== $new_meta) {
                                update_post_meta($post_id, $option['id'], $new_meta, $old_meta);
                            }
                        }
                    }
                }
            }
        }
    }
}
 /**
  * Constructor. Hooks all interactions to initialize the class.
  *
  * @since 0.0.2
  */
 public function __construct()
 {
     self::$instance = $this;
     $this->demo_files_path = apply_filters('radium_theme_importer_demo_files_path', $this->demo_files_path);
     $this->theme_options_file = apply_filters('radium_theme_importer_theme_options_file', $this->demo_files_path . $this->theme_options_file_name);
     $this->widgets = apply_filters('radium_theme_importer_widgets_file', $this->demo_files_path . $this->widgets_file_name);
     $this->content_demo = apply_filters('radium_theme_importer_content_demo_file', $this->demo_files_path . $this->content_demo_file_name);
     $this->imported_demos = get_option('radium_imported_demo');
     if ($this->theme_options_framework == 'optiontree') {
         $this->theme_option_name = ot_options_id();
     }
     if ($this->add_admin_menu) {
         add_action('admin_menu', array($this, 'add_admin'));
     }
     add_filter('add_post_metadata', array($this, 'check_previous_meta'), 10, 5);
     add_action('radium_import_end', array($this, 'after_wp_importer'));
 }
 function ot_insert_css_with_markers($field_id = '', $insertion = '', $meta = false)
 {
     /* missing $field_id or $insertion exit early */
     if ('' == $field_id || '' == $insertion) {
         return;
     }
     /* path to the dynamic.css file */
     $filepath = get_stylesheet_directory() . '/dynamic.css';
     /* allow filter on path */
     $filepath = apply_filters('css_option_file_path', $filepath, $field_id);
     /* grab a copy of the paths array */
     $ot_css_file_paths = get_option('ot_css_file_paths', array());
     /* set the path for this field */
     $ot_css_file_paths[$field_id] = $filepath;
     /* update the paths */
     update_option('ot_css_file_paths', $ot_css_file_paths);
     /* insert CSS into file */
     if (file_exists($filepath)) {
         $insertion = ot_normalize_css($insertion);
         $regex = "/{{([a-zA-Z0-9\\_\\-\\#\\|\\=]+)}}/";
         $marker = $field_id;
         /* Match custom CSS */
         preg_match_all($regex, $insertion, $matches);
         /* Loop through CSS */
         foreach ($matches[0] as $option) {
             $value = '';
             $option_id = str_replace(array('{{', '}}'), '', $option);
             $option_array = explode('|', $option_id);
             /* get the array value */
             if ($meta) {
                 global $post;
                 $value = get_post_meta($post->ID, $option_array[0], true);
             } else {
                 $options = get_option(ot_options_id());
                 if (isset($options[$option_array[0]])) {
                     $value = $options[$option_array[0]];
                 }
             }
             if (is_array($value)) {
                 if (!isset($option_array[1])) {
                     /* Measurement */
                     if (isset($value[0]) && isset($value[1])) {
                         /* set $value with measurement properties */
                         $value = $value[0] . $value[1];
                         /* typography */
                     } else {
                         if (ot_array_keys_exists($value, array('font-color', 'font-family', 'font-size', 'font-style', 'font-variant', 'font-weight', 'letter-spacing', 'line-height', 'text-decoration', 'text-transform'))) {
                             $font = array();
                             if (!empty($value['font-color'])) {
                                 $font[] = "color: " . $value['font-color'] . ";";
                             }
                             if (!empty($value['font-family'])) {
                                 foreach (ot_recognized_font_families($marker) as $key => $v) {
                                     if ($key == $value['font-family']) {
                                         $font[] = "font-family: " . $v . ";";
                                     }
                                 }
                             }
                             if (!empty($value['font-size'])) {
                                 $font[] = "font-size: " . $value['font-size'] . ";";
                             }
                             if (!empty($value['font-style'])) {
                                 $font[] = "font-style: " . $value['font-style'] . ";";
                             }
                             if (!empty($value['font-variant'])) {
                                 $font[] = "font-variant: " . $value['font-variant'] . ";";
                             }
                             if (!empty($value['font-weight'])) {
                                 $font[] = "font-weight: " . $value['font-weight'] . ";";
                             }
                             if (!empty($value['letter-spacing'])) {
                                 $font[] = "letter-spacing: " . $value['letter-spacing'] . ";";
                             }
                             if (!empty($value['line-height'])) {
                                 $font[] = "line-height: " . $value['line-height'] . ";";
                             }
                             if (!empty($value['text-decoration'])) {
                                 $font[] = "text-decoration: " . $value['text-decoration'] . ";";
                             }
                             if (!empty($value['text-transform'])) {
                                 $font[] = "text-transform: " . $value['text-transform'] . ";";
                             }
                             /* set $value with font properties or empty string */
                             $value = !empty($font) ? implode("\n", $font) : '';
                             /* background */
                         } else {
                             if (ot_array_keys_exists($value, array('background-color', 'background-image', 'background-repeat', 'background-attachment', 'background-position', 'background-size'))) {
                                 $bg = array();
                                 if (!empty($value['background-color'])) {
                                     $bg[] = $value['background-color'];
                                 }
                                 if (!empty($value['background-image'])) {
                                     $bg[] = 'url("' . $value['background-image'] . '")';
                                 }
                                 if (!empty($value['background-repeat'])) {
                                     $bg[] = $value['background-repeat'];
                                 }
                                 if (!empty($value['background-attachment'])) {
                                     $bg[] = $value['background-attachment'];
                                 }
                                 if (!empty($value['background-position'])) {
                                     $bg[] = $value['background-position'];
                                 }
                                 if (!empty($value['background-size'])) {
                                     $size = $value['background-size'];
                                 }
                                 /* set $value with background properties or empty string */
                                 $value = !empty($bg) ? 'background: ' . implode(" ", $bg) . ';' : '';
                                 if (isset($size)) {
                                     if (!empty($bg)) {
                                         $value .= apply_filters('ot_insert_css_with_markers_bg_size_white_space', "\n  ", $option_id);
                                     }
                                     $value .= "background-size: {$size};";
                                 }
                             }
                         }
                     }
                 } else {
                     $value = $value[$option_array[1]];
                 }
             }
             // Filter the CSS
             $value = apply_filters('ot_insert_css_with_markers_value', $value, $option_id);
             /* insert CSS, even if the value is empty */
             $insertion = stripslashes(str_replace($option, $value, $insertion));
         }
         /* create array from the lines of code */
         $markerdata = explode("\n", implode('', file($filepath)));
         /* can't write to the file return false */
         if (!($f = ot_file_open($filepath, 'w'))) {
             return false;
         }
         $searching = true;
         $foundit = false;
         /* has array of lines */
         if (!empty($markerdata)) {
             /* foreach line of code */
             foreach ($markerdata as $n => $markerline) {
                 /* found begining of marker, set $searching to false  */
                 if ($markerline == "/* BEGIN {$marker} */") {
                     $searching = false;
                 }
                 /* keep rewrite each line of CSS  */
                 if ($searching == true) {
                     if ($n + 1 < count($markerdata)) {
                         ot_file_write($f, "{$markerline}\n");
                     } else {
                         ot_file_write($f, "{$markerline}");
                     }
                 }
                 /* found end marker write code */
                 if ($markerline == "/* END {$marker} */") {
                     ot_file_write($f, "/* BEGIN {$marker} */\n");
                     ot_file_write($f, "{$insertion}\n");
                     ot_file_write($f, "/* END {$marker} */\n");
                     $searching = true;
                     $foundit = true;
                 }
             }
         }
         /* nothing inserted, write code. DO IT, DO IT! */
         if (!$foundit) {
             ot_file_write($f, "/* BEGIN {$marker} */\n");
             ot_file_write($f, "{$insertion}\n");
             ot_file_write($f, "/* END {$marker} */\n");
         }
         /* close file */
         ot_file_close($f);
         return true;
     }
     return false;
 }
function rj_taxonomy_ot_save_settings()
{
    if (isset($_REQUEST['page']) && $_REQUEST['page'] == 'rj-ot-taxonomy_metabox') {
        rj_ot_admin_scriptss();
        rj_ot_admin_styless();
        wp_enqueue_script('rj_ot_taxonomy_script', plugin_dir_url(dirname(__FILE__)) . 'js/taxonomy-ot-metabox-ui-settings.js');
    }
    /* check and verify import settings nonce */
    if (isset($_POST['option_tree_settings_nonce']) && wp_verify_nonce($_POST['option_tree_settings_nonce'], 'rj_option_tree_settings_form') && isset($_GET['page']) && $_GET['page'] == 'rj-ot-taxonomy_metabox') {
        /* settings value */
        $settings = isset($_POST[ot_settings_id()]) ? $_POST[ot_settings_id()] : '';
        /* validate sections */
        if (isset($settings['sections'])) {
            /* fix numeric keys since drag & drop will change them */
            $settings['sections'] = array_values($settings['sections']);
            /* loop through sections */
            foreach ($settings['sections'] as $k => $section) {
                /* remove from array if missing values */
                if (!isset($section['title']) && !isset($section['id']) || '' == $section['title'] && '' == $section['id']) {
                    unset($settings['sections'][$k]);
                } else {
                    /* validate label */
                    if ('' != $section['title']) {
                        $settings['sections'][$k]['title'] = wp_kses_post($section['title']);
                    }
                    /* missing title set to unfiltered ID */
                    if (!isset($section['title']) || '' == $section['title']) {
                        $settings['sections'][$k]['title'] = wp_kses_post($section['id']);
                        /* missing ID set to title */
                    } else {
                        if (!isset($section['id']) || '' == $section['id']) {
                            $section['id'] = wp_kses_post($section['title']);
                        }
                    }
                    /* sanitize ID once everything has been checked first */
                    $settings['sections'][$k]['id'] = ot_sanitize_option_id(wp_kses_post($section['id']));
                }
            }
            $settings['sections'] = ot_stripslashes($settings['sections']);
        }
        /* validate settings by looping over array as many times as it takes */
        if (isset($settings['settings'])) {
            $settings['settings'] = ot_validate_settings_array($settings['settings']);
        }
        /* validate contextual_help */
        if (isset($settings['contextual_help']['content'])) {
            /* fix numeric keys since drag & drop will change them */
            $settings['contextual_help']['content'] = array_values($settings['contextual_help']['content']);
            /* loop through content */
            foreach ($settings['contextual_help']['content'] as $k => $content) {
                /* remove from array if missing values */
                if (!isset($content['title']) && !isset($content['id']) || '' == $content['title'] && '' == $content['id']) {
                    unset($settings['contextual_help']['content'][$k]);
                } else {
                    /* validate label */
                    if ('' != $content['title']) {
                        $settings['contextual_help']['content'][$k]['title'] = wp_kses_post($content['title']);
                    }
                    /* missing title set to unfiltered ID */
                    if (!isset($content['title']) || '' == $content['title']) {
                        $settings['contextual_help']['content'][$k]['title'] = wp_kses_post($content['id']);
                        /* missing ID set to title */
                    } else {
                        if (!isset($content['id']) || '' == $content['id']) {
                            $content['id'] = wp_kses_post($content['title']);
                        }
                    }
                    /* sanitize ID once everything has been checked first */
                    $settings['contextual_help']['content'][$k]['id'] = ot_sanitize_option_id(wp_kses_post($content['id']));
                }
                /* validate textarea description */
                if (isset($content['content'])) {
                    $settings['contextual_help']['content'][$k]['content'] = wp_kses_post($content['content']);
                }
            }
        }
        /* validate contextual_help sidebar */
        if (isset($settings['contextual_help']['sidebar'])) {
            $settings['contextual_help']['sidebar'] = wp_kses_post($settings['contextual_help']['sidebar']);
        }
        $settings['contextual_help'] = ot_stripslashes($settings['contextual_help']);
        /* default message */
        $message = 'failed';
        /* is array: save & show success message */
        if (is_array($settings)) {
            /* WPML unregister ID's that have been removed */
            if (function_exists('icl_unregister_string')) {
                $current = get_option(ot_settings_id());
                $options = get_option(ot_options_id());
                if (isset($current['settings'])) {
                    /* Empty ID array */
                    $new_ids = array();
                    /* Build the WPML IDs array */
                    foreach ($settings['settings'] as $setting) {
                        if ($setting['id']) {
                            $new_ids[] = $setting['id'];
                        }
                    }
                    /* Remove missing IDs from WPML */
                    foreach ($current['settings'] as $current_setting) {
                        if (!in_array($current_setting['id'], $new_ids)) {
                            if (!empty($options[$current_setting['id']]) && in_array($current_setting['type'], array('list-item', 'slider'))) {
                                foreach ($options[$current_setting['id']] as $key => $value) {
                                    foreach ($value as $ckey => $cvalue) {
                                        ot_wpml_unregister_string($current_setting['id'] . '_' . $ckey . '_' . $key);
                                    }
                                }
                            } else {
                                if (!empty($options[$current_setting['id']]) && $current_setting['type'] == 'social-icons') {
                                    foreach ($options[$current_setting['id']] as $key => $value) {
                                        foreach ($value as $ckey => $cvalue) {
                                            ot_wpml_unregister_string($current_setting['id'] . '_' . $ckey . '_' . $key);
                                        }
                                    }
                                } else {
                                    ot_wpml_unregister_string($current_setting['id']);
                                }
                            }
                        }
                    }
                }
            }
            update_option('rj_taxonomy_' . ot_settings_id(), $settings);
            $message = 'success';
        }
        /* redirect */
        wp_redirect(add_query_arg(array('action' => 'save-settings', 'message' => $message), $_POST['_wp_http_referer']));
        exit;
    }
    return false;
}
 function st_check_service_available($post_type = false)
 {
     if ($post_type) {
         if (function_exists('ot_options_id')) {
             $option = get_option(ot_options_id());
             $disable_list = isset($option['list_disabled_feature']) ? $option['list_disabled_feature'] : array();
             if (!empty($disable_list)) {
                 foreach ($disable_list as $key) {
                     if ($key == $post_type) {
                         return false;
                     }
                 }
             }
         }
         return true;
     }
     return false;
 }
Example #19
0
 public function set_demo_theme_options($file)
 {
     // Does the File exist?
     if (file_exists($file)) {
         // Get file contents and decode
         $data = file_get_contents($file);
         if ($this->theme_options_framework == 'radium') {
             //radium framework
             $data = unserialize(trim($data, '###'));
         } elseif ($this->theme_options_framework == 'optiontree') {
             //option tree import
             $data = $this->optiontree_decode($data);
             update_option(ot_options_id(), $data);
             $this->flag_as_imported['options'] = true;
         } else {
             //other frameworks
             //$data = json_decode( $data, true );
             $data = maybe_unserialize($data);
         }
         // Only if there is data
         if (!empty($data) || is_array($data)) {
             // Hook before import
             $data = apply_filters('radium_theme_import_theme_options', $data);
             update_option($this->theme_option_name, $data);
             $this->flag_as_imported['options'] = true;
         }
         do_action('radium_importer_after_theme_options_import', $this->active_import, $this->demo_files_path);
     } else {
         wp_die(__('Theme options Import file could not be found. Please try again.', 'radium'), '', array('back_link' => true));
     }
 }
Example #20
0
/**
 * Helper function to parse and return properly formated CSS.
 *
 * @param     string    $field_id ID of the option to retrieve.
 * @param     string    $insertion The string to parse into CSS.
 * @param     boolean   $meta Whether the ID is of a meta option or regular theme option.
 * @return    string
 *
 * @since     2.3.0
 */
function demo_parse_css($field_id = '', $insertion = '', $meta = false)
{
    /* missing $field_id or $insertion exit early */
    if ('' == $field_id || '' == $insertion) {
        return;
    }
    $insertion = demo_normalize_css($insertion);
    $regex = "/{{([a-zA-Z0-9\\_\\-\\#\\|\\=]+)}}/";
    /* Match custom CSS */
    preg_match_all($regex, $insertion, $matches);
    /* Loop through CSS */
    foreach ($matches[0] as $option) {
        $value = '';
        $option_array = explode('|', str_replace(array('{{', '}}'), '', $option));
        $option_id = isset($option_array[0]) ? $option_array[0] : '';
        $option_key = isset($option_array[1]) ? $option_array[1] : '';
        $option_type = demo_get_option_type_by_id($option_id);
        $fallback = '';
        // Get the meta array value
        if ($meta) {
            global $post;
            $value = get_post_meta($post->ID, $option_id, true);
            // Get the options array value
        } else {
            $options = get_option(ot_options_id());
            if (isset($options[$option_id])) {
                $value = $options[$option_id];
            }
        }
        // This in an array of values
        if (is_array($value)) {
            if (empty($option_key)) {
                // Measurement
                if ($option_type == 'measurement') {
                    // Set $value with measurement properties
                    if (isset($value[0]) && isset($value[1])) {
                        $value = $value[0] . $value[1];
                    }
                    // Border
                } else {
                    if ($option_type == 'border') {
                        $border = array();
                        $unit = !empty($value['unit']) ? $value['unit'] : 'px';
                        if (!empty($value['width'])) {
                            $border[] = $value['width'] . $unit;
                        }
                        if (!empty($value['style'])) {
                            $border[] = $value['style'];
                        }
                        if (!empty($value['color'])) {
                            $border[] = $value['color'];
                        }
                        /* set $value with border properties or empty string */
                        $value = !empty($border) ? implode(' ', $border) : '';
                        // Box Shadow
                    } else {
                        if ($option_type == 'box-shadow') {
                            /* set $value with box-shadow properties or empty string */
                            $value = !empty($value) ? implode(' ', $value) : '';
                            // Dimension
                        } else {
                            if ($option_type == 'dimension') {
                                $dimension = array();
                                $unit = !empty($value['unit']) ? $value['unit'] : 'px';
                                if (!empty($value['width'])) {
                                    $dimension[] = $value['width'] . $unit;
                                }
                                if (!empty($value['height'])) {
                                    $dimension[] = $value['height'] . $unit;
                                }
                                // Set $value with dimension properties or empty string
                                $value = !empty($dimension) ? implode(' ', $dimension) : '';
                                // Spacing
                            } else {
                                if ($option_type == 'spacing') {
                                    $spacing = array();
                                    $unit = !empty($value['unit']) ? $value['unit'] : 'px';
                                    if (!empty($value['top'])) {
                                        $spacing[] = $value['top'] . $unit;
                                    }
                                    if (!empty($value['right'])) {
                                        $spacing[] = $value['right'] . $unit;
                                    }
                                    if (!empty($value['bottom'])) {
                                        $spacing[] = $value['bottom'] . $unit;
                                    }
                                    if (!empty($value['left'])) {
                                        $spacing[] = $value['left'] . $unit;
                                    }
                                    // Set $value with spacing properties or empty string
                                    $value = !empty($spacing) ? implode(' ', $spacing) : '';
                                    // Typography
                                } else {
                                    if ($option_type == 'typography') {
                                        $font = array();
                                        if (!empty($value['font-color'])) {
                                            $font[] = "color: " . $value['font-color'] . ";";
                                        }
                                        if (!empty($value['font-family'])) {
                                            foreach (demo_recognized_font_families($field_id) as $key => $v) {
                                                if ($key == $value['font-family']) {
                                                    $font[] = "font-family: " . $v . ";";
                                                }
                                            }
                                        }
                                        if (!empty($value['font-size'])) {
                                            $font[] = "font-size: " . $value['font-size'] . ";";
                                        }
                                        if (!empty($value['font-style'])) {
                                            $font[] = "font-style: " . $value['font-style'] . ";";
                                        }
                                        if (!empty($value['font-variant'])) {
                                            $font[] = "font-variant: " . $value['font-variant'] . ";";
                                        }
                                        if (!empty($value['font-weight'])) {
                                            $font[] = "font-weight: " . $value['font-weight'] . ";";
                                        }
                                        if (!empty($value['letter-spacing'])) {
                                            $font[] = "letter-spacing: " . $value['letter-spacing'] . ";";
                                        }
                                        if (!empty($value['line-height'])) {
                                            $font[] = "line-height: " . $value['line-height'] . ";";
                                        }
                                        if (!empty($value['text-decoration'])) {
                                            $font[] = "text-decoration: " . $value['text-decoration'] . ";";
                                        }
                                        if (!empty($value['text-transform'])) {
                                            $font[] = "text-transform: " . $value['text-transform'] . ";";
                                        }
                                        // Set $value with font properties or empty string
                                        $value = !empty($font) ? implode("\n", $font) : '';
                                        // Background
                                    } else {
                                        if ($option_type == 'background') {
                                            $bg = array();
                                            if (!empty($value['background-color'])) {
                                                $bg[] = $value['background-color'];
                                            }
                                            if (!empty($value['background-image'])) {
                                                // If an attachment ID is stored here fetch its URL and replace the value
                                                if (wp_attachment_is_image($value['background-image'])) {
                                                    $attachment_data = wp_get_attachment_image_src($value['background-image'], 'original');
                                                    // Check for attachment data
                                                    if ($attachment_data) {
                                                        $value['background-image'] = $attachment_data[0];
                                                    }
                                                }
                                                $bg[] = 'url("' . $value['background-image'] . '")';
                                            }
                                            if (!empty($value['background-repeat'])) {
                                                $bg[] = $value['background-repeat'];
                                            }
                                            if (!empty($value['background-attachment'])) {
                                                $bg[] = $value['background-attachment'];
                                            }
                                            if (!empty($value['background-position'])) {
                                                $bg[] = $value['background-position'];
                                            }
                                            if (!empty($value['background-size'])) {
                                                $size = $value['background-size'];
                                            }
                                            // Set $value with background properties or empty string
                                            $value = !empty($bg) ? 'background: ' . implode(" ", $bg) . ';' : '';
                                            if (isset($size)) {
                                                if (!empty($bg)) {
                                                    $value .= apply_filters('ot_demo_insert_css_with_markers_bg_size_white_space', "\n  ", $option_id);
                                                }
                                                $value .= "background-size: {$size};";
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            } else {
                $value = $value[$option_key];
            }
        }
        // If an attachment ID is stored here fetch its URL and replace the value
        if ($option_type == 'upload' && wp_attachment_is_image($value)) {
            $attachment_data = wp_get_attachment_image_src($value, 'original');
            // Check for attachment data
            if ($attachment_data) {
                $value = $attachment_data[0];
            }
        }
        // Attempt to fallback when `$value` is empty
        if (empty($value)) {
            // We're trying to access a single array key
            if (!empty($option_key)) {
                // Link Color `inherit`
                if ($option_type == 'link-color') {
                    $fallback = 'inherit';
                }
            } else {
                // Border
                if ($option_type == 'border') {
                    $fallback = 'inherit';
                }
                // Box Shadow
                if ($option_type == 'box-shadow') {
                    $fallback = 'none';
                }
                // Colorpicker
                if ($option_type == 'colorpicker') {
                    $fallback = 'inherit';
                }
                // Colorpicker Opacity
                if ($option_type == 'colorpicker-opacity') {
                    $fallback = 'inherit';
                }
            }
            /**
             * Filter the `dynamic.css` fallback value.
             *
             * @since 2.5.3
             *
             * @param string $fallback The default CSS fallback value.
             * @param string $option_id The option ID.
             * @param string $option_type The option type.
             * @param string $option_key The option array key.
             */
            $fallback = apply_filters('ot_demo_insert_css_with_markers_fallback', $fallback, $option_id, $option_type, $option_key);
        }
        // Let's fallback!
        if (!empty($fallback)) {
            $value = $fallback;
        }
        // Filter the CSS
        $value = apply_filters('ot_demo_insert_css_with_markers_value', $value, $option_id);
        // Insert CSS, even if the value is empty
        $insertion = stripslashes(str_replace($option, $value, $insertion));
    }
    return $insertion;
}
Example #21
0
function handle_ot_import($data)
{
    if (!class_exists('OT_Loader')) {
        return new WP_Error('theme_options_ot_not_found', esc_html__('Option Tree is not installed, theme options not imported.', 'youxi'));
    }
    try {
        /* decode the theme options data */
        $options = unserialize(ot_decode($data));
        /* has options */
        if (is_array($options)) {
            /* update the option tree options */
            update_option(ot_options_id(), $options);
        } else {
            return new WP_Error('theme_options_invalid_data', esc_html__('The supplied theme options data is invalid.', 'youxi'));
        }
    } catch (Exception $e) {
        return new WP_Error('theme_options_unknown_error', $e->getMessage());
    }
    return esc_html__('Theme options successfully imported.', 'youxi');
}