/** * @internal */ public function _form_render($data) { $this->add_admin_static(); $options = array(array('custom_css' => array('title' => false, 'type' => 'box', 'options' => self::$user_options))); $values = FW_Request::POST(FW_Option_Type::get_default_name_prefix(), fw_get_db_extension_data($this->get_name(), 'options')); echo fw()->backend->render_options($options, $values); $data['submit']['html'] = '<button class="button-primary button-large">' . __('Save', 'fw') . '</button>'; unset($options); return $data; }
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; }
* @internal */ protected function _render($id, $option, $data) { $css_uri = fw()->extensions->get('seo')->get_declared_URI('/includes/option-types/' . $this->get_type() . '/static/css/style.css'); $js_uri = fw()->extensions->get('seo')->get_declared_URI('/includes/option-types/' . $this->get_type() . '/static/js/scripts.js'); $seo_tags = fw()->extensions->get('seo')->get_seo_tags(); $tags_names = array(); foreach ($seo_tags as $tag_id => $tag) { array_push($tags_names, '%%' . $tag_id . '%%'); } $version = fw()->extensions->get('seo')->manifest->get_version(); wp_enqueue_style('fw-option-' . $this->get_type(), $css_uri, array(), $version); wp_enqueue_script('fw-option-' . $this->get_type(), $js_uri, array('jquery', 'jquery-ui', 'jquery-ui-autocomplete'), $version, true); wp_localize_script('fw-option-' . $this->get_type(), 'fw_ext_seo_tags', $tags_names); return fw()->backend->option_type('text')->render($id, $option, $data); } public function get_type() { return 'seo-tags'; } /** * @internal */ protected function _get_value_from_input($option, $input_value) { return fw()->backend->option_type('text')->get_value_from_input($this->internal_options, $input_value); } } FW_Option_Type::register('FW_Option_Type_SEO_Tags');
* @internal */ protected function _get_value_from_input($option, $input_value) { if (is_array($input_value) || empty($option['value'])) { $value = array(); } else { $value = $option['value']; } foreach (fw_extract_only_options($option['inner-options']) as $inner_id => $inner_option) { $value[$inner_id] = fw()->backend->option_type($inner_option['type'])->get_value_from_input(isset($value[$inner_id]) ? array_merge($inner_option, array('value' => $value[$inner_id])) : $inner_option, isset($input_value[$inner_id]) ? $input_value[$inner_id] : null); } return $value; } /** * @internal */ public function _get_backend_width_type() { return 'full'; } /** * @internal */ protected function _get_defaults() { return array('inner-options' => array(), 'value' => array()); } } FW_Option_Type::register('FW_Option_Type_Multi');
/** * @param WP_Customize_Manager $wp_customize * @param array $options * @param array $parent_data {'type':'...','id':'...'} */ private function customizer_register_options($wp_customize, $options, $parent_data = array()) { $collected = array(); fw_collect_options($collected, $options, array('limit_option_types' => false, 'limit_container_types' => false, 'limit_level' => 1, 'info_wrapper' => true)); if (empty($collected)) { return; } foreach ($collected as &$opt) { switch ($opt['group']) { case 'container': $_collected = array(); fw_collect_options($_collected, $opt['option']['options'], array('limit_option_types' => array(), 'limit_container_types' => false, 'limit_level' => 1, 'limit' => 1, 'info_wrapper' => false)); $has_containers = !empty($_collected); unset($_collected); $children_data = array('group' => 'container', 'id' => $opt['id']); $args = array('title' => empty($opt['option']['title']) ? fw_id_to_title($opt['id']) : $opt['option']['title'], 'description' => empty($opt['option']['desc']) ? '' : $opt['option']['desc']); if (isset($opt['option']['wp-customizer-args']) && is_array($opt['option']['wp-customizer-args'])) { $args = array_merge($opt['option']['wp-customizer-args'], $args); } if ($has_containers) { if ($parent_data) { trigger_error($opt['id'] . ' panel can\'t have a parent (' . $parent_data['id'] . ')', E_USER_WARNING); break; } $wp_customize->add_panel($opt['id'], $args); $children_data['customizer_type'] = 'panel'; } else { if ($parent_data) { if ($parent_data['customizer_type'] === 'panel') { $args['panel'] = $parent_data['id']; } else { trigger_error($opt['id'] . ' section can have only panel parent (' . $parent_data['id'] . ')', E_USER_WARNING); break; } } $wp_customize->add_section($opt['id'], $args); $children_data['customizer_type'] = 'section'; } $this->customizer_register_options($wp_customize, $opt['option']['options'], $children_data); unset($children_data); break; case 'option': $setting_id = FW_Option_Type::get_default_name_prefix() . '[' . $opt['id'] . ']'; $args = array('label' => empty($opt['option']['label']) ? fw_id_to_title($opt['id']) : $opt['option']['label'], 'description' => empty($opt['option']['desc']) ? '' : $opt['option']['desc'], 'settings' => $setting_id); if (isset($opt['option']['wp-customizer-args']) && is_array($opt['option']['wp-customizer-args'])) { $args = array_merge($opt['option']['wp-customizer-args'], $args); } if ($parent_data) { if ($parent_data['customizer_type'] === 'section') { $args['section'] = $parent_data['id']; } else { trigger_error('Invalid control parent: ' . $parent_data['customizer_type'], E_USER_WARNING); break; } } else { // the option is not placed in a section, create a section automatically $args['section'] = 'fw_option_auto_section_' . $opt['id']; $wp_customize->add_section($args['section'], array('title' => empty($opt['option']['label']) ? fw_id_to_title($opt['id']) : $opt['option']['label'])); } if (!class_exists('_FW_Customizer_Setting_Option')) { require_once fw_get_framework_directory('/includes/customizer/class--fw-customizer-setting-option.php'); } if (!class_exists('_FW_Customizer_Control_Option_Wrapper')) { require_once fw_get_framework_directory('/includes/customizer/class--fw-customizer-control-option-wrapper.php'); } $wp_customize->add_setting(new _FW_Customizer_Setting_Option($wp_customize, $setting_id, array('default' => fw()->backend->option_type($opt['option']['type'])->get_value_from_input($opt['option'], null), 'fw_option' => $opt['option']))); $wp_customize->add_control(new _FW_Customizer_Control_Option_Wrapper($wp_customize, $opt['id'], $args)); break; default: trigger_error('Unknown group: ' . $opt['group'], E_USER_WARNING); } } }
self::$googleFontsPrinted = true; } return fw_render_view(fw_get_framework_directory('/includes/option-types/' . $this->get_type() . '/view.php'), array('id' => $id, 'option' => $option, 'data' => $data, 'fonts' => self::$fonts)); } public function get_type() { return 'typography'; } /** * @internal */ protected function _get_value_from_input($option, $input_value) { if (!is_array($input_value)) { return $option['value']; } $components = isset($option['components']) && is_array($option['components']) ? $option['components'] : array(); $components = array_merge(array('size' => true, 'family' => true, 'color' => true), $components); $values = array('size' => $components['size'] ? isset($input_value['size']) ? intval($input_value['size']) : intval($option['value']['size']) : false, 'family' => $components['family'] ? isset($input_value['family']) ? $input_value['family'] : $option['value']['family'] : false, 'style' => $components['family'] ? isset($input_value['style']) ? $input_value['style'] : $option['value']['style'] : false, 'color' => $components['color'] ? isset($input_value['color']) && preg_match('/^#[a-f0-9]{6}$/i', $input_value['color']) ? $input_value['color'] : $option['value']['color'] : false); return $values; } /** * @internal */ protected function _get_defaults() { return array('value' => array('size' => 12, 'family' => 'Arial', 'style' => '400', 'color' => '#000000')); } } FW_Option_Type::register('FW_Option_Type_Typography');
/** * Get correct values from input (POST) for given options * This values can be saved in db then replaced with $option['value'] for each option * @param array $options * @param array $input_array * @return array Values */ function fw_get_options_values_from_input(array $options, $input_array = null) { if (!is_array($input_array)) { $input_array = FW_Request::POST(FW_Option_Type::get_default_name_prefix()); } $values = array(); foreach (fw_extract_only_options($options) as $id => $option) { $values[$id] = fw()->backend->option_type($option['type'])->get_value_from_input($option, isset($input_array[$id]) ? $input_array[$id] : null); if (is_null($values[$id])) { // do not save null values unset($values[$id]); } } return $values; }
protected function _get_value_from_input($option, $input_value) { if (is_null($input_value)) { return $option['value']; } else { $input_values = isset($option['properties']['values']) && is_array($option['properties']['values']) ? explode(';', $input_value) : array_map('intval', explode(';', $input_value)); return array('from' => $input_values[0], 'to' => $input_values[1]); } } /** * Used to update option from and to value to be equal to max and min in case they are not defined * * @param array $option * * @return array */ private function update_option($option) { if ($option['value']['from'] < $option['properties']['min'] || $option['value']['from'] > $option['properties']['max']) { $option['value']['from'] = $option['properties']['min']; $option['properties']['from'] = $option['properties']['min']; } if ($option['value']['to'] > $option['properties']['max'] || $option['value']['to'] < $option['properties']['min']) { $option['value']['to'] = $option['properties']['max']; $option['properties']['to'] = $option['properties']['max']; } return $option; } } FW_Option_Type::register('FW_Option_Type_Range_Slider');
$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; } } FW_Option_Type::register('FW_Option_Type_Style');
wp_enqueue_style($this->get_type() . '-scripts', fw_ext('mailer')->get_uri() . '/includes/option-type-mailer/static/css/style.css'); wp_enqueue_script($this->get_type() . '-scripts', fw_ext('mailer')->get_uri() . '/includes/option-type-mailer/static/js/scripts.js', array('fw-events'), fw()->manifest->get_version(), true); } /** * @internal */ protected function _render($id, $option, $data) { $data['value'] = fw_ext('mailer')->get_db_settings_option(); $wrapper_attr = $option['attr']; unset($wrapper_attr['name'], $wrapper_attr['value']); return '<div ' . fw_attr_to_html($wrapper_attr) . '>' . fw()->backend->option_type('multi')->render($id, array('inner-options' => $this->get_inner_options()), $data) . '</div>'; } /** * @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(); } } FW_Option_Type::register('FW_Option_Type_Mailer');
} if ($input['type'] === 'custom-upload') { $result['attachment-id'] = $input['attachment-id']; $result['url'] = $input['url']; } return $result; } protected function _get_json_value_to_insert_in_html($data) { $result = array(); $result['type'] = $data['value']['type']; if ($data['value']['type'] === 'icon-font') { $result['icon-class'] = $data['value']['icon-class']; } if ($data['value']['type'] === 'custom-upload') { $result['attachment-id'] = $data['value']['attachment-id']; $result['url'] = $data['value']['url']; } return json_encode($result); } protected function _get_defaults() { return array('value' => array('type' => 'icon-font', 'icon-class' => '', 'icon-class-without-root' => false, 'pack-name' => false, 'pack-css-uri' => false), 'preview-size' => 'medium'); } public function _get_backend_width_type() { return 'full'; } } FW_Option_Type::register('FW_Option_Type_Icon_v2');
public function _init() { if (is_null(self::$original_value)) { self::$original_value = self::get_key(); } } public function get_type() { return 'gmap-key'; } /** * @internal */ protected function _get_defaults() { return array('value' => self::get_key(), 'fw-storage' => array('type' => 'wp-option', 'wp-option' => self::get_key_option_id())); } /** * Restrict option save if the option value is same as the one in the database * @inheritdoc */ protected function _storage_save($id, array $option, $value, array $params) { if ($value == self::$original_value) { return $value; } return parent::_storage_save($id, $option, $value, $params); } } FW_Option_Type::register('FW_Option_Type_GMap_Key');
switch ($picker_type) { case 'switch': $choices = array_intersect_key($option['choices'], array($picker['left-choice']['value'] => array(), $picker['right-choice']['value'] => array())); break; case 'select': case 'short-select': // we need to treat the case with optgroups $collected_choices = array(); foreach ($picker['choices'] as $key => $choice_value) { if (is_array($choice_value) && isset($choice_value['choices'])) { // we have an optgroup $collected_choices = array_merge($collected_choices, $choice_value['choices']); } else { $collected_choices[$key] = $choice_value; } } $choices = array_intersect_key($option['choices'], $collected_choices); break; default: $choices = array_intersect_key($option['choices'], $picker['choices']); } foreach ($choices as $choice_id => $options) { foreach ($options as $option_id => $option) { $value[$choice_id][$option_id] = fw()->backend->option_type($option['type'])->get_value_from_input($option, isset($input_value[$choice_id][$option_id]) ? $input_value[$choice_id][$option_id] : null); } } return $value; } } FW_Option_Type::register('FW_Option_Type_Multi_Picker');
/** * @param WP_Customize_Manager $wp_customize * @param array $options * @param array $parent_data {'type':'...','id':'...'} */ private function customizer_register_options($wp_customize, $options, $parent_data = array()) { $collected = array(); fw_collect_first_level_options($collected, $options); if (empty($collected['all'])) { return; } foreach ($collected['all'] as &$opt) { switch ($opt['type']) { case 'tab': $args = array('title' => $opt['option']['title'], 'description' => empty($opt['option']['desc']) ? '' : $opt['option']['desc']); if ($parent_data) { trigger_error('Not supported panel parent, type: ' . $parent_data['type'], E_USER_WARNING); break; } $wp_customize->add_panel($opt['id'], $args); $this->customizer_register_options($wp_customize, $opt['option']['options'], array('type' => 'panel', 'id' => $opt['id'])); break; case 'box': $args = array('title' => $opt['option']['title']); if ($parent_data) { if ($parent_data['type'] === 'panel') { $args['panel'] = $parent_data['id']; } else { trigger_error('Not supported section parent, type: ' . $parent_data['type'], E_USER_WARNING); break; } } $wp_customize->add_section($opt['id'], $args); $this->customizer_register_options($wp_customize, $opt['option']['options'], array('type' => 'section', 'id' => $opt['id'])); break; case 'option': $setting_id = FW_Option_Type::get_default_name_prefix() . '[' . $opt['id'] . ']'; $args = array('label' => empty($opt['option']['label']) ? '' : $opt['option']['label'], 'description' => empty($opt['option']['desc']) ? '' : $opt['option']['desc'], 'settings' => $setting_id, 'type' => 'radio', 'choices' => array('a' => 'Demo A', 'b' => 'Demo B')); if ($parent_data) { if ($parent_data['type'] === 'section') { $args['section'] = $parent_data['id']; } else { trigger_error('Not supported control parent, type: ' . $parent_data['type'], E_USER_WARNING); break; } } else { // the option is not placed in a section, create a section automatically $args['section'] = 'fw_option_auto_section_' . $opt['id']; $wp_customize->add_section($args['section'], array('title' => empty($opt['option']['label']) ? fw_id_to_title($opt['id']) : $opt['option']['label'])); } if (!class_exists('_FW_Customizer_Control_Option_Wrapper')) { require_once fw_get_framework_directory('/includes/customizer/class--fw-customizer-control-option-wrapper.php'); } $wp_customize->add_setting($setting_id, array('default' => fw()->backend->option_type($opt['option']['type'])->get_value_from_input($opt['option'], null))); $control = new _FW_Customizer_Control_Option_Wrapper($wp_customize, $opt['id'], $args, array('fw_option' => $opt['option'])); add_filter("customize_sanitize_{$setting_id}", array($control, 'setting_sanitize_callback'), 10, 2); $wp_customize->add_control($control); break; default: trigger_error('Not supported option in customizer, type: ' . $opt['type'], E_USER_WARNING); // todo: uncomment } } }
return $input_value; } private function set_default_values(&$input_value, &$option) { if (!isset($input_value['textarea']) || empty($input_value['textarea'])) { $input_value['textarea'] = $option['value']['textarea']; } if (!isset($input_value['rows']) || empty($input_value['rows'])) { $input_value['rows'] = $option['value']['rows']; } if (!isset($input_value['cols']) || empty($input_value['cols'])) { $input_value['cols'] = $option['value']['cols']; } } /** * @internal */ protected function _get_defaults() { return array('row_options' => array('choices' => array('' => __('Default row', 'fw'), 'heading-row' => __('Heading row', 'fw'), 'pricing-row' => __('Pricing row', 'fw'))), 'columns_options' => array('choices' => array('' => __('Default column', 'fw'), 'highlight-col' => __('Highlight column', 'fw'), 'desc-col' => __('Description column', 'fw'), 'center-col' => __('Center text column', 'fw'))), 'value' => array('cols' => array('', '', ''), 'rows' => array('', '', ''), 'textarea' => array(array('', '', ''), array('', '', ''), array('', '', '')))); } /** * @internal */ public function _get_backend_width_type() { return 'full'; } } FW_Option_Type::register('FW_Option_Type_Table_Builder');
} else { // simple choice $html .= '<option value="' . esc_attr($c_value) . '" ' . (in_array($c_value, $value) ? 'selected="selected" ' : '') . '>' . htmlspecialchars($choice, ENT_COMPAT, 'UTF-8') . '</option>'; } } return $html; } /** * @internal */ protected function _get_defaults() { return array('value' => array(), 'choices' => array()); } } FW_Option_Type::register('FW_Option_Type_Select_Multiple'); $dir = dirname(__FILE__); require $dir . '/option-types/icon/class-fw-option-type-icon.php'; require $dir . '/option-types/image-picker/class-fw-option-type-image-picker.php'; require $dir . '/option-types/upload/class-fw-option-type-upload.php'; require $dir . '/option-types/color-picker/class-fw-option-type-color-picker.php'; require $dir . '/option-types/gradient/class-fw-option-type-gradient.php'; require $dir . '/option-types/background-image/class-fw-option-type-background-image.php'; require $dir . '/option-types/multi/class-fw-option-type-multi.php'; require $dir . '/option-types/switch/class-fw-option-type-switch.php'; require $dir . '/option-types/typography/class-fw-option-type-typography.php'; require $dir . '/option-types/multi-upload/class-fw-option-type-multi-upload.php'; require $dir . '/option-types/multi-picker/class-fw-option-type-multi-picker.php'; require $dir . '/option-types/wp-editor/class-fw-option-type-wp-editor.php'; require $dir . '/option-types/date-picker/class-fw-option-type-wp-date-picker.php'; require $dir . '/option-types/addable-option/class-fw-option-type-addable-option.php';
protected function _get_value_from_input($option, $input_value) { if (is_null($input_value)) { return $option['value']; } else { if ($input_value) { // checked return $option['right-choice']['value']; } else { // unchecked return $option['left-choice']['value']; } } } /** * @internal */ public function _get_backend_width_type() { return 'auto'; } /** * @internal */ protected function _get_defaults() { return array('value' => false, 'left-choice' => array('value' => false, 'label' => __('No', 'fw')), 'right-choice' => array('value' => true, 'label' => __('Yes', 'fw'))); } } FW_Option_Type::register('FW_Option_Type_Switch');
* * array( * 'value' => '', * ... * ) * @internal */ protected function _get_defaults() { return array('value' => '', 'attr' => array('placeholder' => 'https://www.youtube.com'), 'preview' => array('width' => 428, 'height' => 320, 'keep_ratio' => true)); } protected function _enqueue_static($id, $option, $data) { wp_enqueue_style('fw-option-' . $this->get_type(), fw_get_framework_directory_uri('/includes/option-types/' . $this->get_type() . '/static/css/styles.css'), array('fw')); wp_enqueue_script('fw-option-' . $this->get_type(), fw_get_framework_directory_uri('/includes/option-types/' . $this->get_type() . '/static/js/' . $this->get_type() . '.js'), array('underscore', 'fw-events', 'fw', 'wp-util'), false, true); } public static function _action_get_oembed_response() { if (wp_verify_nonce(FW_Request::POST('_nonce'), '_action_get_oembed_response')) { $url = FW_Request::POST('url'); $width = FW_Request::POST('preview/width'); $height = FW_Request::POST('preview/height'); $keep_ratio = FW_Request::POST('preview/keep_ratio') === 'true'; $iframe = empty($keep_ratio) ? fw_oembed_get($url, compact('width', 'height')) : wp_oembed_get($url, compact('width', 'height')); wp_send_json_success(array('response' => $iframe)); } wp_send_json_error(array('message' => 'Invalid nonce')); } } FW_Option_Type::register('FW_Option_Type_Oembed'); add_action('wp_ajax_get_oembed_response', array("FW_Option_Type_Oembed", '_action_get_oembed_response'));
if (isset($option['datetime-picker']['minDate']) and !empty($option['datetime-picker']['minDate'])) { $min_timestamp_value = strtotime($option['datetime-picker']['minDate']); if ($min_timestamp_value > $input_timestamp_value) { return $option['value']; } } if (isset($option['datetime-picker']['maxDate']) and !empty($option['datetime-picker']['maxDate'])) { $max_timestamp_value = strtotime($option['datetime-picker']['maxDate']); if ($max_timestamp_value < $input_timestamp_value) { return $option['value']; } } } catch (Exception $e) { return $option['value']; } return (string) $input_value; } private function _fw_validate_date_format($date, $format = 'Y/m/d H:i', $extra_formats = array()) { $extra_formats = array_merge($extra_formats, array($format)); foreach ($extra_formats as $format) { $d = DateTime::createFromFormat($format, $date); if ($d && $d->format($format) == $date) { return true; } } return false; } } FW_Option_Type::register('FW_Option_Type_Datetime_Picker');
} /** * @internal */ protected function _get_value_from_input($option, $input_value) { if (empty($input_value)) { return $option['value']; } else { return $this->get_attachments_info($input_value); } } private function get_attachments_info($attachment_ids) { $decoded_ids = json_decode($attachment_ids, true); if (!is_array($decoded_ids) || empty($decoded_ids)) { $defaults = $this->get_defaults(); return $defaults['value']; } $return_arr = array(); foreach ($decoded_ids as $id) { $url = wp_get_attachment_url($id); if ($url) { $return_arr[] = array('attachment_id' => $id, 'url' => preg_replace('/^https?:\\/\\//', '//', $url)); } } return $return_arr; } } FW_Option_Type::register('FW_Option_Type_Multi_Upload');
/** * Set a theme customizer option value in database * * @param null $option_id Specific option id (accepts multikey). null - all options * @param mixed $value */ function fw_set_db_customizer_option($option_id = null, $value) { $db_value = get_theme_mod(FW_Option_Type::get_default_name_prefix(), array()); if (is_null($option_id)) { $db_value = $value; } else { fw_aks($option_id, $value, $db_value); } set_theme_mod(FW_Option_Type::get_default_name_prefix(), $db_value); }
return 'rgba-color-picker'; } /** * @internal */ protected function _render($id, $option, $data) { $option['attr']['value'] = empty($data['value']) ? $option['value'] : $data['value']; return '<input type="text" ' . fw_attr_to_html($option['attr']) . '>'; } /** * @internal */ protected function _get_value_from_input($option, $input_value) { if (!empty($input_value)) { $input_value = trim($input_value); $input_value = preg_match('/^#[a-f0-9]{3}([a-f0-9]{3})?$/i', $input_value) || preg_match('/^rgba\\( *([01]?\\d\\d?|2[0-4]\\d|25[0-5]) *\\, *([01]?\\d\\d?|2[0-4]\\d|25[0-5]) *\\, *([01]?\\d\\d?|2[0-4]\\d|25[0-5]) *\\, *(1|0|0?.\\d+) *\\)$/', $input_value) ? $input_value : $option['value']; } return (string) $input_value; } /** * @internal */ protected function _get_defaults() { return array('value' => ''); } } FW_Option_Type::register('FW_Option_Type_Rgba_Color_Picker');
} } else { $values = $option['value']; } /** * For e.g. option type 'unique' needs to execute _get_value_from_input() for each option to prevent duplicate values */ $values = apply_filters('fw:option-type:addable-popup:value-from-input', $values, $option); return $values; } /** * Default option array * * This makes possible an option array to have required only one parameter: array('type' => '...') * Other parameters are merged with array returned from this method * * @return array * * array( * 'value' => '', * ... * ) * @internal */ protected function _get_defaults() { return array('value' => array(), 'popup-options' => array('default' => array('type' => 'text')), 'template' => '', 'popup-title' => null, 'limit' => 0, 'size' => 'small', 'add-button-text' => __('Add', 'fw'), 'sortable' => true); } } FW_Option_Type::register('FW_Option_Type_Addable_Popup');
* {@inheritdoc} */ protected function _enqueue_static($id, $option, $data) { wp_enqueue_style('fw-option-' . $this->get_type(), $this->css_uri . '/styles.css', array(), fw()->manifest->get_version()); wp_enqueue_script('fw-option-' . $this->get_type(), $this->js_uri . '/scripts.js', array('jquery', 'fw-events'), fw()->manifest->get_version(), true); } /** * @internal */ protected function _render($id, $option, $data) { $option['choices'][$this->custom_choice_key] = ''; return fw_render_view(dirname(__FILE__) . '/view.php', array('id' => $id, 'option' => $option, 'data' => $data, 'custom_choice_key' => $this->custom_choice_key)); } /** * @internal */ protected function _get_value_from_input($option, $input_value) { $option['choices'][$this->custom_choice_key] = ''; $selected = fw()->backend->option_type('radio')->get_value_from_input(array('value' => $option['value'], 'choices' => $option['choices']), $input_value['predefined']); if ($selected === $this->custom_choice_key) { return (string) $input_value['custom']; } else { return $selected; } } } FW_Option_Type::register('FW_Option_Type_Radio_Text');
fw()->backend->option_type('text')->enqueue_static(); } /** * @internal */ private function convert_array($array = array()) { if (!is_array($array) || empty($array)) { return array(); } $return = array(); foreach ($array as $key => $item) { $return[] = array('val' => $key, 'title' => $item ? $item : $key . ' (' . __('No title', 'fw') . ')'); } return $return; } /** * @internal */ protected function _get_value_from_input($option, $input_value) { if (is_null($input_value)) { return $option['value']; } $value = explode('/*/', $input_value); return empty($input_value) ? array() : $value; } } FW_Option_Type::register('FW_Option_Type_Multi_Select'); add_action('wp_ajax_admin_action_get_ajax_response', array("FW_Option_Type_Multi_Select", '_admin_action_get_ajax_response')); }
/** * Render option enclosed in backend design */ public function render_option($id, $option, $data = array(), $design = 'default') { /** * register scripts and styles * in case if this method is called before enqueue_scripts action * and option types has some of these in their dependencies */ $this->register_static(); if (!in_array($design, $this->available_render_designs)) { trigger_error('Invalid render design specified: ' . $design, E_USER_WARNING); $design = 'post'; } if (!isset($data['id_prefix'])) { $data['id_prefix'] = FW_Option_Type::get_default_id_prefix(); } return fw_render_view(FW_DIR . '/views/backend-option-design-' . $design . '.php', array('id' => $id, 'option' => $option, 'data' => $data)); }
foreach ($editor_styles as $key => $file) { if ($file && file_exists("{$template_dir}/{$file}")) { $mce_css[] = "{$template_uri}/{$file}"; } } } foreach ($editor_styles as $file) { if ($file && file_exists("{$style_dir}/{$file}")) { $mce_css[] = "{$style_uri}/{$file}"; } } } return $mce_css_urls = trim(implode(',', $mce_css)); } /** * @internal */ protected function _get_value_from_input($option, $input_value) { if (is_null($input_value)) { return $option['value']; } $value = (string) $input_value; if ($option['wpautop'] === true) { $value = wpautop($value); } return $value; } } FW_Option_Type::register('FW_Option_Type_Wp_Editor');
self::$ids[$post_id][$id] = true; return $id; } /** * Make sure there are no duplicate ids * * @param array $value * @param array $option * * @return array */ public function _filter_addable_popup_value_from_input($value, $option) { $update_options = array(); fw_collect_options($update_options, $option['popup-options'], array('limit_option_types' => array($this->get_type()))); if (empty($update_options)) { return $value; } foreach ($value as &$row) { foreach ($update_options as $opt_id => $opt) { if (isset($row[$opt_id])) { // should not happen, but just in case, prevent notice $row[$opt_id] = fw()->backend->option_type($opt['type'])->get_value_from_input(array_merge($opt, array('value' => $row[$opt_id])), null); } } } return $value; } } FW_Option_Type::register('FW_Option_Type_Unique');
*/ protected function _get_value_from_input($option, $input_value) { if (!is_array($input_value)) { return $option['value']; } $option['limit'] = intval($option['limit']); $value = array(); $box_options = fw_extract_only_options($option['box-options']); foreach ($input_value as &$list_item_value) { $current_value = array(); foreach ($box_options as $id => $input_option) { $current_value[$id] = fw()->backend->option_type($input_option['type'])->get_value_from_input($input_option, isset($list_item_value[$id]) ? $list_item_value[$id] : null); } $value[] = $current_value; if ($option['limit'] && count($value) === $option['limit']) { break; } } return $value; } /** * @internal */ protected function _get_defaults() { return array('value' => array(), 'box-controls' => array(), 'box-options' => array(), 'limit' => 0, 'template' => ''); } } FW_Option_Type::register('FW_Option_Type_Addable_Box');
/** * 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 (!is_array($input_value)) { return $option['value']; } // unset the last slide that is default for add array_pop($input_value); $value = array(); $slides_options = fw_extract_only_options($option['slides_options']); foreach ($input_value as &$list_item_value) { $current_value = array(); foreach ($slides_options as $id => $input_option) { $current_value[$id] = fw()->backend->option_type($input_option['type'])->get_value_from_input($input_option, isset($list_item_value[$id]) ? $list_item_value[$id] : null); $current_value['thumb'] = isset($list_item_value['thumb']) ? $list_item_value['thumb'] : null; } $value[] = $current_value; } return $value; } } FW_Option_Type::register('FW_Option_Type_Slides'); add_action('wp_ajax_cache_slide', array('FW_Option_Type_Slides', '_action_ajax_cache_slide')); add_action('wp_ajax_resize_slide', array('FW_Option_Type_Slides', '_action_ajax_resize_slide'));