Esempio n. 1
1
 public function _settings_form_save($data)
 {
     fw_set_db_settings_option(null, array_merge((array) fw_get_db_settings_option(), fw_get_options_values_from_input(fw()->theme->get_settings_options())));
     FW_Flash_Messages::add('fw_settings_form_saved', __('Options successfuly saved', 'fw'), 'success');
     $data['redirect'] = fw_current_url();
     return $data;
 }
 /**
  * @internal
  *
  * @param array $option
  * @param array|null|string $input_value
  *
  * @return array|bool|int|string
  */
 protected function _get_value_from_input($option, $input_value)
 {
     if (is_array($input_value) && !empty($input_value)) {
         fw_ext('mailer')->set_db_settings_option(null, fw_get_options_values_from_input($this->get_inner_options(), $input_value));
     }
     return fw_ext('mailer')->get_db_settings_option();
 }
 public function enqueue_static()
 {
     wp_enqueue_style('fw-builder-' . $this->get_builder_type() . '-item-' . $this->get_type(), $this->get_uri('/static/css/styles.css'));
     wp_enqueue_script('fw-builder-' . $this->get_builder_type() . '-item-' . $this->get_type(), $this->get_uri('/static/js/scripts.js'), array('fw-events'), false, true);
     wp_localize_script('fw-builder-' . $this->get_builder_type() . '-item-' . $this->get_type(), 'fw_form_builder_item_type_' . $this->get_type(), array('options' => $this->get_options(), 'l10n' => array('item_title' => __('Recaptcha', 'fw'), 'label' => __('Label', 'fw'), 'edit_label' => __('Edit Label', 'fw'), 'edit' => __('Edit', 'fw'), 'delete' => __('Delete', 'fw'), 'site_key' => __('Set site key', 'fw'), 'secret_key' => __('Set secret key', 'fw')), 'defaults' => array('type' => $this->get_type(), 'options' => fw_get_options_values_from_input($this->get_options(), array()))));
     fw()->backend->enqueue_options_static($this->get_options());
 }
 /**
  * @internal
  */
 public function _form_save($data)
 {
     fw_set_db_extension_data($this->get_name(), 'options', fw_get_options_values_from_input($this->get_settings_options()));
     do_action('fw_' . $this->get_name() . '_form_save');
     $data['redirect'] = fw_current_url();
     return $data;
 }
 /**
  * @internal
  */
 public function _admin_action_wp_ajax_backup_settings_save()
 {
     if (!current_user_can('manage_options')) {
         wp_send_json_error();
     }
     $settings = $this->backup()->settings();
     $values = fw_get_options_values_from_input($settings->get_options(), FW_Request::POST('values'));
     $settings->save($values);
     wp_send_json_success();
 }
 protected function get_fixed_attributes($attributes)
 {
     // do not allow sub items
     unset($attributes['_items']);
     $default_attributes = array('type' => $this->get_type(), 'shortcode' => false, 'width' => '', 'options' => array());
     // remove unknown attributes
     $attributes = array_intersect_key($attributes, $default_attributes);
     $attributes = array_merge($default_attributes, $attributes);
     $attributes['options'] = fw_get_options_values_from_input($this->get_options(), $attributes['options']);
     return $attributes;
 }
 protected function get_fixed_attributes($attributes)
 {
     // do not allow sub items
     unset($attributes['_items']);
     $default_attributes = array('type' => $this->get_type(), 'shortcode' => false, 'width' => '', 'options' => array());
     // remove unknown attributes
     $attributes = array_intersect_key($attributes, $default_attributes);
     $attributes = array_merge($default_attributes, $attributes);
     $attributes['options'] = fw_get_options_values_from_input($this->get_options(), $attributes['options']);
     $constraints = $attributes['options']['constraints'];
     if (!empty($constraints['constraint'])) {
         $constraint = $constraints['constraint'];
         $constraint_data = $constraints[$constraint];
         switch ($constraint) {
             case 'digits':
                 if (!empty($constraint_data['min'])) {
                     $constraint_data['min'] = intval($constraint_data['min']);
                     if ($constraint_data['min'] < 0) {
                         $constraint_data['min'] = 0;
                     }
                 }
                 if (!empty($constraint_data['max'])) {
                     $constraint_data['max'] = intval($constraint_data['max']);
                     if ($constraint_data['max'] < 0 || $constraint_data['max'] < $constraint_data['min']) {
                         $constraint_data['max'] = null;
                     }
                 }
                 break;
             case 'value':
                 if ($constraint_data['min'] === '' || !preg_match($this->number_regex, $constraint_data['min'])) {
                     $constraint_data['min'] = null;
                 } else {
                     $constraint_data['min'] = doubleval($constraint_data['min']);
                 }
                 if ($constraint_data['max'] === '' || !preg_match($this->number_regex, $constraint_data['max'])) {
                     $constraint_data['max'] = null;
                 } else {
                     $constraint_data['max'] = doubleval($constraint_data['max']);
                 }
                 if (!is_null($constraint_data['max']) && !is_null($constraint_data['min'])) {
                     if ($constraint_data['max'] < $constraint_data['min']) {
                         $constraint_data['max'] = null;
                     }
                 }
                 break;
             default:
                 trigger_error('Invalid constraint: ' . $constraint, E_USER_WARNING);
                 $attributes['options']['constraints']['constraint'] = '';
         }
         $attributes['options']['constraints'][$constraint] = $constraint_data;
     }
     return $attributes;
 }
 public function setting_sanitize_callback($input)
 {
     $input = json_decode($input, true);
     if (is_null($input)) {
         return null;
     }
     $POST = array();
     foreach ($input as $var) {
         fw_aks(fw_html_attr_name_to_array_multi_key($var['name']), $var['value'], $POST);
     }
     $value = fw_get_options_values_from_input(array($this->id => $this->fw_option), fw_akg(FW_Option_Type::get_default_name_prefix(), $POST));
     $value = array_pop($value);
     return $value;
 }
 protected function get_fixed_attributes($attributes)
 {
     // do not allow sub items
     unset($attributes['_items']);
     $default_attributes = array('type' => $this->get_type(), 'shortcode' => false, 'width' => '', 'options' => array());
     // remove unknown attributes
     $attributes = array_intersect_key($attributes, $default_attributes);
     $attributes = array_merge($default_attributes, $attributes);
     $only_options = array();
     foreach (fw_extract_only_options($this->get_options()) as $option_id => $option) {
         if (array_key_exists($option_id, $attributes['options'])) {
             $option['value'] = $attributes['options'][$option_id];
         }
         $only_options[$option_id] = $option;
     }
     $attributes['options'] = fw_get_options_values_from_input($only_options, array());
     unset($only_options, $option_id, $option);
     $constraints = $attributes['options']['constraints'];
     if (!empty($constraints['constraint'])) {
         $constraint = $constraints['constraint'];
         $constraint_data = $constraints[$constraint];
         switch ($constraint) {
             case 'characters':
             case 'words':
                 if (!empty($constraint_data['min'])) {
                     $constraint_data['min'] = intval($constraint_data['min']);
                     if ($constraint_data['min'] < 0) {
                         $constraint_data['min'] = 0;
                     }
                 }
                 if (!empty($constraint_data['max'])) {
                     $constraint_data['max'] = intval($constraint_data['max']);
                     if ($constraint_data['max'] < 0 || $constraint_data['max'] < $constraint_data['min']) {
                         $constraint_data['max'] = null;
                     }
                 }
                 break;
             default:
                 trigger_error('Invalid constraint: ' . $constraint, E_USER_WARNING);
                 $attributes['options']['constraints']['constraint'] = '';
         }
         $attributes['options']['constraints'][$constraint] = $constraint_data;
     }
     return $attributes;
 }
 protected function get_fixed_attributes($attributes)
 {
     // do not allow sub items
     unset($attributes['_items']);
     $default_attributes = array('type' => $this->get_type(), 'shortcode' => 'form-header-title', 'width' => '', 'options' => array());
     // remove unknown attributes
     $attributes = array_intersect_key($attributes, $default_attributes);
     $attributes = array_merge($default_attributes, $attributes);
     $only_options = array();
     foreach (fw_extract_only_options($this->get_options()) as $option_id => $option) {
         if (array_key_exists($option_id, $attributes['options'])) {
             $option['value'] = $attributes['options'][$option_id];
         }
         $only_options[$option_id] = $option;
     }
     $attributes['options'] = fw_get_options_values_from_input($only_options, array());
     unset($only_options, $option_id, $option);
     return $attributes;
 }
 /**
  * @internal
  */
 public static function _action_ajax_cache_slide()
 {
     $output = '';
     $attr_data = json_decode(FW_Request::POST('option'), true);
     $option = $attr_data['option'];
     $id = $attr_data['id'];
     $data = $attr_data['data'];
     parse_str(FW_Request::POST('values'), $values);
     if (isset($values)) {
         $options_values_cache = $values['fw_options']['custom-slides'];
         $options_values = array_pop($options_values_cache);
         $valid_values = fw_get_options_values_from_input($option['slides_options'], $options_values);
         foreach ($values['fw_options']['custom-slides'] as $key => $value) {
             $output .= "<div class='fw-slide slide-" . $key . "'  data-order='" . $key . "'>";
             $output .= fw()->backend->render_options($option['slides_options'], $valid_values, array('id_prefix' => $data['id_prefix'] . $id . '-' . $key . '-', 'name_prefix' => $data['name_prefix'] . '[' . $id . '][' . $key . ']'));
             $output .= "</div>";
         }
     }
     wp_send_json($output);
 }
 /**
  * @internal
  */
 protected function _get_value_from_input($option, $input_value)
 {
     if (is_null($input_value)) {
         return $option['value'];
     } else {
         $value = fw_get_options_values_from_input($this->internal_options, $input_value);
         //remove time, if all_day selected
         $all_day = fw_akg('event_durability', $value);
         if ($all_day === 'yes') {
             foreach ($value['event_datetime'] as $key => &$row) {
                 if (isset($row['event_date_range']['from'])) {
                     $row['event_date_range']['from'] = date($this->only_date_format, strtotime($row['event_date_range']['from']));
                 }
                 if (isset($row['event_date_range']['to'])) {
                     $row['event_date_range']['to'] = date($this->only_date_format, strtotime($row['event_date_range']['to']));
                 }
             }
         }
         return $value;
     }
 }
 /**
  * @internal
  *
  * @param array $option
  * @param array|null|string $input_value
  *
  * @return array|bool|int|string
  */
 protected function _get_value_from_input($option, $input_value)
 {
     if (is_array($input_value) && !empty($input_value)) {
         /**
          * Doing a database save in get_value_from_input() is wrong
          * because this is not an actual save.
          * But this option type use is limited, it's used only in one place
          * and it works, so we decided to not create a new "deep save trigger" mechanism
          * just for one option.
          * When such mechanism will be needed for general use, then we will figure out something.
          */
         fw_ext('mailer')->set_db_settings_option(null, fw_get_options_values_from_input($this->get_inner_options(), $input_value));
     }
     /**
      * Return "nothing"
      * Prevent private smtp data to be saved/duplicated in post meta (somewhere else)
      */
     return array('time' => time());
 }
 /**
  * Extract correct value for $option['value'] from input array
  * If input value is empty, will be returned $option['value']
  *
  * @param array $option
  * @param array|string|null $input_value
  *
  * @return string|array|int|bool Correct value
  * @internal
  */
 protected function _get_value_from_input($option, $input_value)
 {
     if (empty($input_value)) {
         if (empty($option['popup-options'])) {
             return array();
         }
         /**
          * $option['value'] has DB format (not $input_value HTML format)
          * so it can't be used as second parameter in fw_get_options_values_from_input()
          * thus we need to move each option value in option array default values
          */
         $popup_options = array();
         foreach (fw_extract_only_options($option['popup-options']) as $popup_option_id => $popup_option) {
             if (isset($option['value'][$popup_option_id])) {
                 $popup_option['value'] = $option['value'][$popup_option_id];
             }
             $popup_options[$popup_option_id] = $popup_option;
         }
         $values = fw_get_options_values_from_input($popup_options, array());
     } else {
         if (is_array($input_value)) {
             /**
              * Don't decode if we have already an array
              */
             $values = fw_get_options_values_from_input($option['popup-options'], $input_value);
         } else {
             $values = fw_get_options_values_from_input($option['popup-options'], json_decode($input_value, true));
         }
     }
     return $values;
 }
Esempio n. 15
0
/**
 * Get extension's settings option value from the database
 *
 * @param string $extension_name
 * @param string|null $option_id
 * @param null|mixed $default_value If no option found in the database, this value will be returned
 * @param null|bool $get_original_value Original value is that with no translations and other changes
 *
 * @return mixed|null
 */
function fw_get_db_ext_settings_option($extension_name, $option_id = null, $default_value = null, $get_original_value = null)
{
    if (!($extension = fw()->extensions->get($extension_name))) {
        trigger_error('Invalid extension: ' . $extension_name, E_USER_WARNING);
        return null;
    }
    $value = FW_WP_Option::get('fw_ext_settings_options:' . $extension_name, $option_id, $default_value, $get_original_value);
    if (is_null($value)) {
        /**
         * Maybe the options was never saved or the given option id does not exists
         * Extract the default values from the options array and try to find there the option id
         */
        $cache_key = 'fw_default_options_values/ext_settings:' . $extension_name;
        try {
            $all_options_values = FW_Cache::get($cache_key);
        } catch (FW_Cache_Not_Found_Exception $e) {
            // extract the default values from options array
            $all_options_values = fw_get_options_values_from_input($extension->get_settings_options(), array());
            FW_Cache::set($cache_key, $all_options_values);
        }
        if (empty($option_id)) {
            // option id not specified, return all options values
            return $all_options_values;
        } else {
            return fw_akg($option_id, $all_options_values, $default_value);
        }
    } else {
        return $value;
    }
}
 public function _action_admin_save_shortcodes($post_id, $post)
 {
     if (wp_is_post_autosave($post_id)) {
         $original_id = wp_is_post_autosave($post_id);
         $original_post = get_post($original_id);
     } else {
         if (wp_is_post_revision($post_id)) {
             $original_id = wp_is_post_revision($post_id);
             $original_post = get_post($original_id);
         } else {
             $original_id = $post_id;
             $original_post = $post;
         }
     }
     if (!$this->is_supported_post($original_id) || !post_type_supports($original_post->post_type, $this->get_parent()->get_supports_feature_name())) {
         return false;
     }
     // todo: field 'content' smth changes ?
     $post_content = FW_Request::POST('content');
     // {"notification":{"1":{"message":"Message!","type":""}},"button":{"1":{},"2":{}},"text_block":{"1":{}}}
     $input_value = FW_Request::POST($this->meta_key);
     $tmp_val = json_decode($input_value, true);
     $new_val = array();
     // supported shortcodes
     $tags = implode('|', array_keys(fw_ext('shortcodes')->get_shortcodes()));
     $default_values = array();
     // only supported tags & integer\alphabetic string id
     if (preg_match_all('/\\[(' . $tags . ')(?:\\s+[^\\[\\]]*)fw_shortcode_id=[\\"\']([A-Za-z0-9]+)[\\"\'](?:\\s?[^\\[\\]]*)\\]/', $post_content, $output_array)) {
         foreach ($output_array[0] as $match_key => $match) {
             $tag = $output_array[1][$match_key];
             $id = $output_array[2][$match_key];
             if (!isset($tmp_val[$tag]) || !isset($tmp_val[$tag][$id]) || empty($tmp_val[$tag][$id])) {
                 $shortcode = fw_ext('shortcodes')->get_shortcode($tag);
                 if ($shortcode) {
                     $new_val[$tag][$id] = fw_get_options_values_from_input($shortcode->get_options(), array());
                 }
             } elseif (isset($tmp_val[$tag][$id]) and false === empty($tmp_val[$tag][$id])) {
                 $new_val[$tag][$id] = $tmp_val[$tag][$id];
             }
         }
     }
     // only supported tags match (defaults)
     if (preg_match_all('/\\[(' . $tags . ')(?:\\s+[^\\[\\]]*).*(?:\\s?[^\\[\\]]*)\\]/', $post_content, $output_array)) {
         foreach ($output_array[0] as $match_key => $match) {
             $tag = $output_array[1][$match_key];
             $shortcode = fw_ext('shortcodes')->get_shortcode($tag);
             if (!empty($shortcode) && is_array($shortcode->get_options())) {
                 $default_values[$tag] = fw_get_options_values_from_input($shortcode->get_options(), array());
             }
         }
     }
     update_post_meta($post_id, $this->meta_key_defaults, str_replace('\\', '\\\\', json_encode($default_values)));
     update_post_meta($post_id, $this->meta_key, str_replace('\\', '\\\\', json_encode($new_val)));
     return true;
 }
/**
 * Get a customizer framework option value from the database
 *
 * @param string|null $option_id Specific option id (accepts multikey). null - all options
 * @param null|mixed $default_value If no option found in the database, this value will be returned
 * // fixme: Maybe add this parameter? @ param null|bool $get_original_value Original value is that with no translations and other changes
 *
 * @return mixed|null
 */
function fw_get_db_customizer_option($option_id = null, $default_value = null)
{
    // note: this contains only changed controls/options
    $all_db_values = get_theme_mod(FW_Option_Type::get_default_name_prefix(), array());
    $cache_key = 'fw_default_options_values/customizer';
    try {
        $all_default_values = FW_Cache::get($cache_key);
    } catch (FW_Cache_Not_Found_Exception $e) {
        // extract the default values from options array
        $all_default_values = fw_get_options_values_from_input(fw()->theme->get_customizer_options(), array());
        FW_Cache::set($cache_key, $all_default_values);
    }
    if (is_null($option_id)) {
        return array_merge($all_default_values, $all_db_values);
    } else {
        $base_key = explode('/', $option_id);
        // note: option_id can be a multi-key 'a/b/c'
        $base_key = array_shift($base_key);
        $all_db_values = array_key_exists($base_key, $all_db_values) ? $all_db_values : $all_default_values;
        return fw_akg($option_id, $all_db_values, $default_value);
    }
}
 /**
  * @param array $data
  * @return array
  * @internal
  */
 public function _extension_settings_form_save($data)
 {
     $extension = fw()->extensions->get(FW_Request::POST('fw_extension_name'));
     $options_before_save = (array) fw_get_db_ext_settings_option($extension->get_name());
     fw_set_db_ext_settings_option($extension->get_name(), null, array_merge($options_before_save, fw_get_options_values_from_input($extension->get_settings_options())));
     FW_Flash_Messages::add('fw_extension_settings_saved', __('Extensions settings successfully saved.', 'fw'), 'success');
     $data['redirect'] = fw_current_url();
     do_action('fw_extension_settings_form_saved:' . $extension->get_name(), $options_before_save);
     return $data;
 }
 /**
  * @param null|int|string $item_id
  * @param null|string $option_id
  * @param mixed $default_value
  * @param array $extra_data
  * @return mixed
  */
 public final function get($item_id = null, $option_id = null, $default_value = null, array $extra_data = array())
 {
     if (empty($option_id)) {
         $sub_keys = null;
     } else {
         $option_id = explode('/', $option_id);
         // 'option_id/sub/keys'
         $_option_id = array_shift($option_id);
         // 'option_id'
         $sub_keys = empty($option_id) ? null : implode('/', $option_id);
         // 'sub/keys'
         $option_id = $_option_id;
         unset($_option_id);
     }
     try {
         // Cached because values are merged with extracted default values
         $values = FW_Cache::get($cache_key_values = $this->get_cache_key('values', $item_id, $extra_data));
     } catch (FW_Cache_Not_Found_Exception $e) {
         FW_Cache::set($cache_key_values, $values = is_array($values = $this->get_values($item_id, $extra_data)) ? $values : array());
     }
     /**
      * If db value is not found and default value is provided
      * return default value before the options file is loaded
      */
     if (!is_null($default_value)) {
         if (empty($option_id)) {
             if (empty($values) && is_array($default_value)) {
                 return $default_value;
             }
         } else {
             if (is_null($sub_keys)) {
                 if (!isset($values[$option_id])) {
                     return $default_value;
                 }
             } else {
                 if (is_null(fw_akg($sub_keys, $values[$option_id]))) {
                     return $default_value;
                 }
             }
         }
     }
     try {
         $options = FW_Cache::get($cache_key = $this->get_cache_key('options', $item_id, $extra_data));
     } catch (FW_Cache_Not_Found_Exception $e) {
         FW_Cache::set($cache_key, array());
         // prevent recursion
         FW_Cache::set($cache_key, $options = fw_extract_only_options($this->get_options($item_id, $extra_data)));
     }
     if ($options) {
         try {
             FW_Cache::get($cache_key_values_processed = $this->get_cache_key('values:processed', $item_id, $extra_data));
         } catch (FW_Cache_Not_Found_Exception $e) {
             /**
              * Set cache value before processing options
              * Fixes https://github.com/ThemeFuse/Unyson/issues/2034#issuecomment-248571149
              */
             FW_Cache::set($cache_key_values_processed, true);
             // Complete missing db values with default values from options array
             $values = array_merge(fw_get_options_values_from_input($options, array()), $values);
             foreach ($options as $id => $option) {
                 $values[$id] = fw()->backend->option_type($option['type'])->storage_load($id, $option, isset($values[$id]) ? $values[$id] : null, $this->get_fw_storage_params($item_id, $extra_data));
             }
             FW_Cache::set($cache_key_values, $values);
         }
     }
     if (empty($option_id)) {
         return empty($values) && is_array($default_value) ? $default_value : $values;
     } else {
         if (is_null($sub_keys)) {
             return isset($values[$option_id]) ? $values[$option_id] : $default_value;
         } else {
             return fw_akg($sub_keys, $values[$option_id], $default_value);
         }
     }
 }
 /**
  * Extract correct value for $option['value'] from input array
  * If input value is empty, will be returned $option['value']
  *
  * @param array $option
  * @param array|string|null $input_value
  *
  * @return string|array|int|bool Correct value
  * @internal
  */
 protected function _get_value_from_input($option, $input_value)
 {
     if (empty($input_value)) {
         if (empty($option['popup-options'])) {
             return array();
         }
         $popup_options = array();
         foreach (fw_extract_only_options($option['popup-options']) as $popup_option_id => $popup_option) {
             if (isset($option['value'][$popup_option_id])) {
                 $popup_option['value'] = $option['value'][$popup_option_id];
             }
             $popup_options[$popup_option_id] = $popup_option;
         }
         $values = fw_get_options_values_from_input($popup_options, array());
     } else {
         if (is_array($input_value)) {
             /**
              * Don't decode if we have already an array
              */
             $values = $input_value;
         } else {
             $values = json_decode($input_value, true);
         }
     }
     return $values;
 }
 public function get_value_from_attributes($attributes)
 {
     // simple items do not contain other items
     unset($attributes['_items']);
     $builder_data = $this->get_builder_data();
     $shortcode_data = $builder_data[$attributes['shortcode']];
     if (isset($shortcode_data['options'])) {
         if (empty($attributes['atts'])) {
             /**
              * The options popup was never opened and there are no attributes.
              * Extract options default values.
              */
             $attributes['atts'] = fw_get_options_values_from_input($shortcode_data['options'], array());
         } else {
             /**
              * There are saved attributes.
              * But we need to execute the _get_value_from_input() method for all options,
              * because some of them may be (need to be) changed (auto-generated) https://github.com/ThemeFuse/Unyson/issues/275
              * Add the values to $option['value']
              */
             $options = fw_extract_only_options($shortcode_data['options']);
             foreach ($attributes['atts'] as $option_id => $option_value) {
                 if (isset($options[$option_id])) {
                     $options[$option_id]['value'] = $option_value;
                 }
             }
             $attributes['atts'] = fw_get_options_values_from_input($options, array());
         }
     }
     return $attributes;
 }
Esempio n. 22
0
 public function _settings_form_save($data)
 {
     $flash_id = 'fw_settings_form_save';
     $old_values = (array) fw_get_db_settings_option();
     if (!empty($_POST['_fw_reset_options'])) {
         // The "Reset" button was pressed
         fw_set_db_settings_option(null, array());
         FW_Flash_Messages::add($flash_id, __('The options were successfully reset', 'fw'), 'success');
         do_action('fw_settings_form_reset', $old_values);
     } else {
         // The "Save" button was pressed
         fw_set_db_settings_option(null, fw_get_options_values_from_input(fw()->theme->get_settings_options()));
         FW_Flash_Messages::add($flash_id, __('The options were successfully saved', 'fw'), 'success');
         do_action('fw_settings_form_saved', $old_values);
     }
     $redirect_url = fw_current_url();
     $data['redirect'] = $redirect_url;
     return $data;
 }
 public function get_value_from_attributes($attributes)
 {
     // simple items do not contain other items
     unset($attributes['_items']);
     /*
      * when saving the modal, the values go into the
      * 'optionValues' key, if it is not present it could be
      * because of two things:
      * either the shortcode does not have options
      * or the user did not open or save the modal (which will be more likely the case)
      */
     if (!isset($attributes['optionValues'])) {
         $builder_data = $this->get_builder_data();
         $item = $builder_data[$attributes['subtype']];
         if (isset($item['options'])) {
             $attributes['optionValues'] = fw_get_options_values_from_input($item['options'], array());
         }
     }
     return $attributes;
 }
 private function get_option($service_id, $key)
 {
     static $is_getting_option = false;
     if ($is_getting_option) {
         // prevent recursion
         return false;
     }
     $is_getting_option = true;
     $values = fw_get_db_extension_data($this->get_name(), 'settings');
     if (empty($values)) {
         /**
          * Settings options was never saved to database.
          * Emulate save with default values.
          *
          * So on next refresh we will not need to call again
          *  fw_get_options_values_from_input( $this->get_backup_settings_options(), array() )
          *  I think it's resource consuming to call that on every refresh
          */
         $options = $this->get_backup_settings_options();
         $values = fw_get_options_values_from_input($options, array());
         fw_set_db_extension_data($this->get_name(), 'settings', $values);
     }
     $option_name = $this->get_option_name($service_id, $key);
     $is_getting_option = false;
     if (isset($values[$option_name])) {
         return $values[$option_name];
     } else {
         return false;
     }
 }
 public function get_value_from_attributes($attributes)
 {
     $attributes['type'] = $this->get_type();
     if (!isset($attributes['width'])) {
         $attributes['width'] = fw_ext_builder_get_item_width($this->get_builder_type());
         end($attributes['width']);
         // move to the last width (usually it's the biggest)
         $attributes['width'] = key($attributes['width']);
     }
     $options = $this->get_shortcode_options();
     if (!empty($options)) {
         if (empty($attributes['atts'])) {
             /**
              * The options popup was never opened and there are no attributes.
              * Extract options default values.
              */
             $attributes['atts'] = fw_get_options_values_from_input($options, array());
         } else {
             /**
              * There are saved attributes.
              * But we need to execute the _get_value_from_input() method for all options,
              * because some of them may be (need to be) changed (auto-generated) https://github.com/ThemeFuse/Unyson/issues/275
              * Add the values to $option['value']
              */
             $options = fw_extract_only_options($options);
             foreach ($attributes['atts'] as $option_id => $option_value) {
                 if (isset($options[$option_id])) {
                     $options[$option_id]['value'] = $option_value;
                 }
             }
             $attributes['atts'] = fw_get_options_values_from_input($options, array());
         }
     }
     return $attributes;
 }
Esempio n. 26
0
/**
 * Get a customizer framework option value from the database
 *
 * @param string|null $option_id Specific option id (accepts multikey). null - all options
 * @param null|mixed $default_value If no option found in the database, this value will be returned
 * // fixme: Maybe add this parameter? @ param null|bool $get_original_value Original value is that with no translations and other changes
 *
 * @return mixed|null
 */
function fw_get_db_customizer_option($option_id = null, $default_value = null)
{
    // note: this contains only changed controls/options
    $db_values = get_theme_mod(FW_Option_Type::get_default_name_prefix(), null);
    if (!is_null($default_value) && is_null($option_id ? fw_akg($option_id, $db_values) : $db_values)) {
        /**
         * Default value was provided in case db value is empty.
         *
         * Do not extract default values from options files (below)
         * maybe this function was called from options files and it will cause infinite loop,
         * that's why the developer provided a default value to prevent that.
         */
        return $default_value;
    }
    if (is_null($db_values)) {
        $db_values = array();
    }
    if (is_null($option_id) || ($base_key = explode('/', $option_id)) && ($base_key = array_shift($base_key)) && !array_key_exists($base_key, $db_values)) {
        $cache_key = 'fw_default_options_values/customizer';
        try {
            $default_values = FW_Cache::get($cache_key);
        } catch (FW_Cache_Not_Found_Exception $e) {
            // extract the default values from options array
            $default_values = fw_get_options_values_from_input(fw()->theme->get_customizer_options(), array());
            FW_Cache::set($cache_key, $default_values);
        }
        $db_values = array_merge($default_values, $db_values);
    }
    return is_null($option_id) ? $db_values : fw_akg($option_id, $db_values, $default_value);
}
 /**
  * @internal
  */
 protected function _get_value_from_input($option, $input_value)
 {
     if (!is_array($input_value)) {
         $input_value = $option['value'];
     }
     $saved = array();
     $saved['predefined'] = !empty($input_value['predefined']) ? $input_value['predefined'] : '';
     $option = $this->prepare_options($option);
     foreach ($input_value as $block_id => $block_settings) {
         if (!is_array($block_settings)) {
             unset($input_value[$block_id]);
             continue;
         }
         foreach ($block_settings as $tag => $tag_settings) {
             if (in_array($tag, array_keys(self::$settings['typography_tags']))) {
                 //Typography
                 $tag_settings = fw()->backend->option_type('typography')->get_value_from_input(array('value' => $option['value'][$block_id][$tag]), $tag_settings);
             } elseif (in_array($tag, array_keys(self::$settings['links']))) {
                 //Links
                 $tag_settings = fw()->backend->option_type('color-picker')->get_value_from_input(array('value' => $option['value'][$block_id][$tag]), $tag_settings);
             } elseif ($tag === 'background' && !empty($tag_settings)) {
                 //Background
                 $tag_settings['background-color']['primary'] = fw()->backend->option_type('color-picker')->get_value_from_input(array('value' => $option['value'][$block_id]['background']['background-color']['primary']), $tag_settings['background-color']['primary']);
                 $tag_settings['background-image'] = fw()->backend->option_type('background-image')->get_value_from_input(json_decode($tag_settings['background-image']['data'], true), $tag_settings['background-image']);
                 $block_settings[$tag] = $tag_settings;
             } elseif (($tag === 'before' || $tag === 'after') && !empty($option['blocks'][$block_id][$tag])) {
                 $tag_settings = fw_get_options_values_from_input($option['blocks'][$block_id][$tag], $input_value[$block_id][$tag]);
             }
             $block_settings[$tag] = $tag_settings;
         }
         $input_value[$block_id] = $block_settings;
     }
     $saved['blocks'] = $input_value;
     return $saved;
 }
Esempio n. 28
-5
 public function _settings_form_save($data)
 {
     $flash_id = 'fw_settings_form_save';
     $old_values = (array) fw_get_db_settings_option();
     if (!empty($_POST['_fw_reset_options'])) {
         // The "Reset" button was pressed
         fw_set_db_settings_option(null, array());
         FW_Flash_Messages::add($flash_id, __('The options were successfully reset', 'fw'), 'success');
         do_action('fw_settings_form_reset', $old_values);
     } else {
         // The "Save" button was pressed
         fw_set_db_settings_option(null, array_merge($old_values, fw_get_options_values_from_input(fw()->theme->get_settings_options())));
         FW_Flash_Messages::add($flash_id, __('The options were successfully saved', 'fw'), 'success');
         do_action('fw_settings_form_saved', $old_values);
     }
     $redirect_url = fw_current_url();
     $focus_tab_input_name = '_focus_tab';
     $focus_tab_id = trim(FW_Request::POST($focus_tab_input_name));
     if (!empty($focus_tab_id)) {
         $redirect_url = add_query_arg($focus_tab_input_name, $focus_tab_id, remove_query_arg($focus_tab_input_name, $redirect_url));
     }
     $data['redirect'] = $redirect_url;
     return $data;
 }