PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 2.05.09
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v2.05.09
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
formidable / classes / models / FrmFieldValue.php

FrmFieldValue.php in Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More 2.05.09, at classes/models/FrmFieldValue.php

211 lines 3.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * @since 2.04
5 */
6 class FrmFieldValue {
7
8 /**
9 * @since 2.04
10 *
11 * @var stdClass
12 */
13 protected $field = null;
14
15 /**
16 * @since 2.04
17 *
18 * @var stdClass
19 */
20 protected $entry = null;
21
22 /**
23 * @since 2.04
24 *
25 * @var string
26 */
27 protected $source = '';
28
29 /**
30 * @since 2.04
31 *
32 * @var mixed
33 */
34 protected $saved_value = '';
35
36 /**
37 * @since 2.04
38 *
39 * @var mixed
40 */
41 protected $displayed_value = '';
42
43 /**
44 * FrmFieldValue constructor.
45 *
46 * @param stdClass $field
47 * @param stdClass $entry
48 * @param array $atts
49 */
50 public function __construct( $field, $entry, $atts = array() ) {
51 if ( ! is_object( $field ) || ! is_object( $entry ) || ! isset( $entry->metas ) ) {
52 return;
53 }
54
55 $this->field = $field;
56 $this->entry = $entry;
57 $this->init_source( $atts );
58 $this->init_saved_value();
59 $this->init_displayed_value();
60 }
61
62 /**
63 * Initialize the source property
64 *
65 * @since 2.04
66 *
67 * @param array $atts
68 */
69 protected function init_source( $atts ) {
70 if ( isset( $atts['source'] ) && is_string( $atts['source'] ) && $atts['source'] !== '' ) {
71 $this->source = (string) $atts['source'];
72 } else {
73 $this->source = 'general';
74 }
75 }
76
77 /**
78 * Initialize the saved_value property
79 *
80 * @since 2.04
81 */
82 protected function init_saved_value() {
83 if ( isset( $this->entry->metas[ $this->field->id ] ) ) {
84 $this->saved_value = $this->entry->metas[ $this->field->id ];
85 } else {
86 $this->saved_value = '';
87 }
88
89 $this->clean_saved_value();
90 }
91
92 /**
93 * Initialize a field's displayed value
94 *
95 * @since 2.04
96 */
97 protected function init_displayed_value() {
98 $this->displayed_value = $this->saved_value;
99
100 $this->filter_displayed_value();
101 }
102
103 /**
104 * Get the saved_value property
105 *
106 * @since 2.04
107 */
108 public function get_saved_value() {
109 return $this->saved_value;
110 }
111
112 /**
113 * Get a value from the field settings
114 * @since 2.05.06
115 */
116 public function get_field_option( $value ) {
117 return FrmField::get_option( $this->field, $value );
118 }
119
120 /**
121 * Get the field property's label
122 *
123 * @since 2.04
124 */
125 public function get_field_label() {
126 return $this->field->name;
127 }
128
129 /**
130 * Get the field property's id
131 *
132 * @since 2.05
133 */
134 public function get_field_id() {
135 return $this->field->id;
136 }
137
138 /**
139 * Get the field property's key
140 *
141 * @since 2.04
142 */
143 public function get_field_key() {
144 return $this->field->field_key;
145 }
146
147 /**
148 * Get the field property's type
149 *
150 * @since 2.04
151 */
152 public function get_field_type() {
153 return $this->field->type;
154 }
155
156 /**
157 * Get the displayed_value property
158 *
159 * @since 2.04
160 */
161 public function get_displayed_value() {
162 return $this->displayed_value;
163 }
164
165 /**
166 * Filter the displayed_value property
167 *
168 * @since 2.04
169 */
170 protected function filter_displayed_value() {
171
172 if ( $this->source === 'entry_formatter' ) {
173 // Deprecated frm_email_value hook
174 $meta = array(
175 'item_id' => $this->entry->id,
176 'field_id' => $this->field->id,
177 'meta_value' => $this->saved_value,
178 'field_type' => $this->field->type,
179 );
180 $this->displayed_value = apply_filters( 'frm_email_value', $this->displayed_value, (object) $meta, $this->entry, array(
181 'field' => $this->field,
182 ) );
183 if ( has_filter( 'frm_email_value' ) ) {
184 _deprecated_function( 'The frm_email_value filter', '2.04', 'the frm_display_{fieldtype}_value_custom filter' );
185 }
186 }
187
188 // frm_display_{fieldtype}_value_custom hook
189 $this->displayed_value = apply_filters( 'frm_display_' . $this->field->type . '_value_custom', $this->displayed_value, array(
190 'field' => $this->field,
191 'entry' => $this->entry,
192 ) );
193 }
194
195 /**
196 * Clean a field's saved value
197 *
198 * @since 2.04
199 */
200 protected function clean_saved_value() {
201 if ( $this->saved_value !== '' ) {
202
203 $this->saved_value = maybe_unserialize( $this->saved_value );
204
205 if ( is_array( $this->saved_value ) && empty( $this->saved_value ) ) {
206 $this->saved_value = '';
207 }
208 }
209 }
210 }
211