/**
  * Validates the inputs provided by users. For now:
  *  1. All text type of options including slider, color-picture etc. are simply checked for special characters
  *  2. Radio buttons/select items are checked for presence in a master list defined by the 'options' key in the inbuilt options array
  *  3. Each item in Multi-select and sortable-list fields is checked against a master list defined by the 'options' key in the options array
  *
  * @param $options
  * @return array|void
  */
 function validate_options($options)
 {
     foreach ($options as $option => $option_value) {
         if (isset($this->reverse_options[$option])) {
             //Sanitize options
             switch ($this->reverse_options[$option]) {
                 // For all text type of options make sure that the eventual text is properly escaped.
                 case "text":
                 case "textarea":
                 case "slider":
                 case "color-picker":
                 case "background":
                 case "border":
                 case "font":
                 case "upload":
                 case "template":
                 case "associative-array":
                     $options[$option] = esc_attr($option_value);
                     break;
                 case "select":
                 case "radio":
                     if (isset($this->allowed_values[$option])) {
                         if (!array_key_exists($option_value, $this->allowed_values[$option])) {
                             $options[$option] = $this->option_defaults[$option];
                         }
                     }
                     break;
                 case "multi-select":
                     if (is_array($option_value)) {
                         $selections = $option_value;
                     } else {
                         $selections = explode(',', $option_value);
                     }
                     $final_selections = array();
                     foreach ($selections as $selection) {
                         if (array_key_exists($selection, $this->allowed_values[$option])) {
                             $final_selections[] = $selection;
                         }
                     }
                     $options[$option] = implode(',', $final_selections);
                     break;
                 case "sortable-list":
                     if (is_array($option_value)) {
                         $selections = $option_value;
                     } else {
                         $selections = explode(',', $option_value);
                     }
                     $final_selections = array();
                     $master_list = $this->option_defaults[$option];
                     // Sortable lists don't have their values in ['options']
                     foreach ($selections as $selection) {
                         if (array_key_exists($selection, $master_list)) {
                             $final_selections[] = $selection;
                         }
                     }
                     $options[$option] = implode(',', $final_selections);
                     break;
                 case "checkbox":
                     if (!in_array($option_value, array('on', 'off', 'true', 'false')) && isset($this->option_defaults[$option])) {
                         $options[$option] = $this->option_defaults[$option];
                     }
                     break;
             }
         }
     }
     /* The Settings API does an update_option($option, $value), overwriting the $suffusion_options array with the values on THIS page
      * This is problematic because all options are stored in a single array, but are displayed on different options pages.
      * Hence the overwrite kills the options from the other pages.
      * So this is a workaround to include the options from other pages as hidden fields on this page, so that the array gets properly updated.
      * The alternative would be to separate options for each page, but that would cause a migration headache for current users.
      */
     if (isset($this->hidden_options) && is_array($this->hidden_options)) {
         foreach ($this->hidden_options as $hidden_option => $hidden_value) {
             if (strlen($hidden_option) >= 7 && (substr($hidden_option, 0, 7) == 'submit-' || substr($hidden_option, 0, 6) == 'reset-')) {
                 continue;
             }
             $options[$hidden_option] = esc_attr($hidden_value);
         }
     }
     $options['pre-navt'] = $options['suf_navt_entity_order'];
     foreach ($this->nested_options as $section => $children) {
         if (isset($options['submit-' . $section])) {
             $options['last-set-section'] = $section;
             if (substr($options['submit-' . $section], 0, 9) == 'Save page' || substr($options['submit-' . $section], 0, 10) == 'Reset page') {
                 global $suffusion_options;
                 foreach ($this->nested_options as $inner_section => $inner_children) {
                     if ($inner_section != $section) {
                         foreach ($inner_children as $inner_child) {
                             if (isset($suffusion_options[$inner_child])) {
                                 $options[$inner_child] = $suffusion_options[$inner_child];
                             }
                         }
                     }
                 }
                 if (substr($options['submit-' . $section], 0, 10) == 'Reset page') {
                     unset($options['submit-' . $section]);
                     // This is a reset for an individual section. So we will unset the child fields.
                     foreach ($children as $child) {
                         unset($options[$child]);
                     }
                 }
                 unset($options['submit-' . $section]);
             } else {
                 if (substr($options['submit-' . $section], 0, 12) == 'Save changes') {
                     unset($options['submit-' . $section]);
                 } else {
                     if (substr($options['submit-' . $section], 0, 13) == 'Reset changes') {
                         unset($options['submit-' . $section]);
                         // This is a reset for all options in the sub-menu. So we will unset all child fields.
                         foreach ($this->nested_options as $section => $children) {
                             foreach ($children as $child) {
                                 unset($options[$child]);
                             }
                         }
                     } else {
                         if (substr($options['submit-' . $section], 0, 6) == 'Delete') {
                             return;
                         } else {
                             if ($options['submit-' . $section] == 'Migrate from 3.0.2 or lower') {
                                 unset($options['submit-' . $section]);
                                 $options = $this->migrate_from_v302($options);
                             } else {
                                 if ($options['submit-' . $section] == 'Migrate from 3.4.3 or lower') {
                                     unset($options['submit-' . $section]);
                                     $options = $this->migrate_from_v343($options);
                                 } else {
                                     if ($options['submit-' . $section] == 'Export core options to a file') {
                                         $this->export_settings('core');
                                     } else {
                                         if ($options['submit-' . $section] == 'Export all options to a file') {
                                             $this->export_settings('all');
                                         } else {
                                             if ($options['submit-' . $section] == 'Import options') {
                                                 $options = $this->import_settings($options);
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             break;
         }
     }
     $options['theme-version'] = SUFFUSION_THEME_VERSION;
     $options['option-date'] = date(get_option('date_format') . ' ' . get_option('time_format'));
     $options = array_merge(suffusion_default_options(), $options);
     return $options;
 }
Esempio n. 2
0
function suffusion_get_unified_options()
{
    global $suffusion_unified_options, $suffusion_default_theme_name;
    $suffusion_unified_options = get_option('suffusion_options');
    if (!isset($suffusion_unified_options) || !is_array($suffusion_unified_options)) {
        // Regenerate the options
        $suffusion_unified_options = suffusion_default_options();
        $suffusion_unified_options['theme-version'] = SUFFUSION_THEME_VERSION;
        $suffusion_unified_options['option-date'] = date(get_option('date_format') . ' ' . get_option('time_format'));
        $save = true;
    } else {
        if (!isset($suffusion_unified_options['theme-version']) || isset($suffusion_unified_options['theme-version']) && $suffusion_unified_options['theme-version'] != SUFFUSION_THEME_VERSION || !isset($suffusion_unified_options['option-date'])) {
            $default_options = suffusion_default_options();
            $suffusion_unified_options = array_merge($default_options, $suffusion_unified_options);
            $suffusion_unified_options['theme-version'] = SUFFUSION_THEME_VERSION;
            $suffusion_unified_options['option-date'] = date(get_option('date_format') . ' ' . get_option('time_format'));
            $save = true;
        }
    }
    $template_path = get_template_directory();
    $stylesheet_path = get_stylesheet_directory();
    $suffusion_theme_name = suffusion_get_theme_name();
    if ($suffusion_theme_name == 'root') {
        $skin = $suffusion_default_theme_name;
    } else {
        $skin = $suffusion_theme_name;
    }
    if (file_exists($stylesheet_path . "/skins/{$skin}/settings.php")) {
        include_once $stylesheet_path . "/skins/{$skin}/settings.php";
    } else {
        if (file_exists($template_path . "/skins/{$skin}/settings.php")) {
            include_once $template_path . "/skins/{$skin}/settings.php";
        }
    }
    if (isset($skin_settings) && is_array($skin_settings)) {
        foreach ($skin_settings as $key => $value) {
            if (!isset($suffusion_unified_options[$key]) || isset($suffusion_unified_options[$key]) && $suffusion_unified_options[$key] == 'theme') {
                $suffusion_unified_options[$key] = $skin_settings[$key];
            }
        }
    }
    if (isset($save)) {
        update_option('suffusion_options', $suffusion_unified_options);
    }
    return $suffusion_unified_options;
}