PluginProbe
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder / 6.2.15
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder v6.2.15
6.2.15 6.2.14 6.2.13 6.2.12 6.2.10 6.2.11 6.2.9 6.2.8 6.2.7 6.2.6 6.2.5 6.2.4 6.2.3 6.2.2 3.6.22 3.6.31 3.6.40 3.6.41 3.6.42 3.6.50 3.6.51 3.6.60 3.6.61 3.6.62 3.6.64 All 197 releases
← All changes | app/Services/FormBuilder/Components/SelectCountry.php +64 -26 3.6.62 → 6.2.15 View file →
@@ -1,9 +1,8 @@
1 1 <?php
2 2
3 3 namespace FluentForm\App\Services\FormBuilder\Components;
4 4
5 -use FluentForm\App;
6 5 use FluentForm\App\Helpers\Helper;
7 6 use FluentForm\Framework\Helpers\ArrayHelper;
8 7
9 8 class SelectCountry extends BaseComponent
@@ -9,23 +8,41 @@
9 8 class SelectCountry extends BaseComponent
10 9 {
11 10 /**
12 11 * Compile and echo the html element
13 - * @param array $data [element data]
14 - * @param stdClass $form [Form Object]
15 - * @return viod
12 + *
13 + * @param array $data [element data]
14 + * @param \stdClass $form [Form Object]
15 + *
16 + * @return void
16 17 */
17 18 public function compile($data, $form)
18 19 {
19 20 $elementName = $data['element'];
20 - $data = apply_filters('fluenform_rendering_field_data_' . $elementName, $data, $form);
21 + $data = apply_filters_deprecated(
22 + 'fluentform_rendering_field_data_' . $elementName,
23 + [
24 + $data,
25 + $form
26 + ],
27 + FLUENTFORM_FRAMEWORK_UPGRADE,
28 + 'fluentform/rendering_field_data_' . $elementName,
29 + 'Use fluentform/rendering_field_data_' . $elementName . ' instead of fluentform_rendering_field_data_' . $elementName
30 + );
31 + $data = apply_filters('fluentform/rendering_field_data_' . $elementName, $data, $form);
21 32
22 33 $data = $this->loadCountries($data);
23 - $defaultValues = (array)$this->extractValueFromAttributes($data);
24 - $data['attributes']['class'] = trim('ff-el-form-control ' . $data['attributes']['class']);
34 + $defaultValues = (array) $this->extractValueFromAttributes($data);
35 + $data['attributes']['class'] = trim('ff-el-form-control ' . ArrayHelper::get($data, 'attributes.class', ''));
25 36 $data['attributes']['id'] = $this->makeElementId($data, $form);
37 + $isSearchable = ArrayHelper::get($data, 'settings.enable_select_2');
38 + if ('yes' == $isSearchable) {
39 + wp_enqueue_script('choices');
40 + wp_enqueue_style('ff_choices');
41 + $data['attributes']['class'] .= ' ff_has_multi_select';
42 + }
26 43
27 - if ($tabIndex = \FluentForm\App\Helpers\Helper::getNextTabIndex()) {
44 + if ($tabIndex = Helper::getNextTabIndex()) {
28 45 $data['attributes']['tabindex'] = $tabIndex;
29 46 }
30 47
31 48 $placeholder = ArrayHelper::get($data, 'attributes.placeholder');
@@ -31,18 +48,25 @@
31 48 $placeholder = ArrayHelper::get($data, 'attributes.placeholder');
32 49
33 50 $activeList = ArrayHelper::get($data, 'settings.country_list.active_list');
34 51
35 - $elMarkup = "<select " . $this->buildAttributes($data['attributes']) . "><option value=''>" . $placeholder . "</option>";
52 + $ariaRequired = 'false';
53 + if (ArrayHelper::get($data, 'settings.validation_rules.required.value')) {
54 + $ariaRequired = 'true';
55 + }
36 56
37 - if ($activeList == 'priority_based') {
57 + $elMarkup = '<select ' . $this->buildAttributes($data['attributes']) . "aria-invalid='false' aria-required=$ariaRequired><option value=''>" . wp_strip_all_tags($placeholder) . '</option>';
58 +
59 + if ('priority_based' == $activeList) {
38 60 $selectCountries = ArrayHelper::get($data, 'settings.country_list.priority_based', []);
39 61 $priorityCountries = $this->getSelectedCountries($selectCountries);
40 62 $primaryListLabel = ArrayHelper::get($data, 'settings.primary_label');
41 63 $otherListLabel = ArrayHelper::get($data, 'settings.other_label');
42 - $elMarkup .= '<optgroup label="' . $primaryListLabel . '">';
64 + // SECURITY (FINDING-12): esc_attr (not just strip_all_tags, which leaves quotes) the
65 + // optgroup labels before interpolating them into the double-quoted label attribute.
66 + $elMarkup .= '<optgroup label="' . esc_attr($primaryListLabel) . '">';
43 67 $elMarkup .= $this->buildOptions($priorityCountries, $defaultValues);
44 - $elMarkup .= '</optgroup><optgroup label="' . $otherListLabel . '">';
68 + $elMarkup .= '</optgroup><optgroup label="' . esc_attr($otherListLabel) . '">';
45 69 $elMarkup .= $this->buildOptions($data['options'], $defaultValues);
46 70 $elMarkup .= '</optgroup>';
47 71 } else {
48 72 $elMarkup .= $this->buildOptions($data['options'], $defaultValues);
@@ -47,32 +71,46 @@
47 71 } else {
48 72 $elMarkup .= $this->buildOptions($data['options'], $defaultValues);
49 73 }
50 74
51 - $elMarkup .= "</select>";
75 + $elMarkup .= '</select>';
52 76
53 77 $html = $this->buildElementMarkup($elMarkup, $data, $form);
54 - echo apply_filters('fluenform_rendering_field_html_' . $elementName, $html, $data, $form);
78 +
79 + $html = apply_filters_deprecated(
80 + 'fluentform_rendering_field_html_' . $elementName,
81 + [
82 + $html,
83 + $data,
84 + $form
85 + ],
86 + FLUENTFORM_FRAMEWORK_UPGRADE,
87 + 'fluentform/rendering_field_html_' . $elementName,
88 + 'Use fluentform/rendering_field_html_' . $elementName . ' instead of fluentform_rendering_field_html_' . $elementName
89 + );
90 +
91 + $this->printContent('fluentform/rendering_field_html_' . $elementName, $html, $data, $form);
55 92 }
56 -
57 93 /**
58 94 * Load countt list from file
95 + *
59 96 * @param array $data
97 + *
60 98 * @return array
61 99 */
62 - protected function loadCountries($data)
100 + public function loadCountries($data)
63 101 {
64 - $app = App::make();
65 - $data['options'] = array();
102 + $app = wpFluentForm();
103 + $data['options'] = [];
66 104 $activeList = ArrayHelper::get($data, 'settings.country_list.active_list');
67 - $countries = $app->load($app->appPath('Services/FormBuilder/CountryNames.php'));
105 + $countries = getFluentFormCountryList();
68 106
69 - if ($activeList == 'visible_list') {
107 + if ('visible_list' == $activeList) {
70 108 $selectCountries = ArrayHelper::get($data, 'settings.country_list.' . $activeList, []);
71 109 foreach ($selectCountries as $value) {
72 110 $data['options'][$value] = $countries[$value];
73 111 }
74 - } elseif ($activeList == 'hidden_list' || $activeList == 'priority_based') {
112 + } elseif ('hidden_list' == $activeList || 'priority_based' == $activeList) {
75 113 $data['options'] = $countries;
76 114 $selectCountries = ArrayHelper::get($data, 'settings.country_list.' . $activeList, []);
77 115 foreach ($selectCountries as $value) {
78 116 unset($data['options'][$value]);
@@ -91,9 +129,11 @@
91 129 }
92 130
93 131 /**
94 132 * Build options for country list/select
133 + *
95 134 * @param array $options
135 + *
96 136 * @return string/html [compiled options]
97 137 */
98 138 protected function buildOptions($options, $defaultValues = [])
99 139 {
@@ -103,18 +143,17 @@
103 143 $selected = 'selected';
104 144 } else {
105 145 $selected = '';
106 146 }
107 - $opts .= "<option value='{$value}' {$selected}>{$label}</option>";
147 + $opts .= "<option value='" . esc_attr($value) . "' {$selected}>" . esc_attr($label) . '</option>';
108 148 }
109 149 return $opts;
110 150 }
111 151
112 - protected function getSelectedCountries($keys = [])
152 + public function getSelectedCountries($keys = [])
113 153 {
114 - $app = App::make();
115 154 $options = [];
116 - $countries = $app->load($app->appPath('Services/FormBuilder/CountryNames.php'));
155 + $countries = getFluentFormCountryList();
117 156 foreach ($keys as $value) {
118 157 $options[$value] = $countries[$value];
119 158 }
120 159
@@ -121,6 +160,5 @@
121 160 $options = array_flip($options);
122 161 ksort($options);
123 162 return array_flip($options);
124 163 }
125 -
126 164 }