@@ -21,15 +21,15 @@ |
||
21 | 21 | </div> |
22 | 22 | <div class="widget-inside frm_hidden"> |
23 | 23 | <?php |
24 | - if ( defined('DOING_AJAX') || ! $action_control->action_options['ajax_load'] ) { |
|
25 | - // only load settings if they are just added or are open |
|
24 | + if ( defined('DOING_AJAX') || ! $action_control->action_options['ajax_load'] ) { |
|
25 | + // only load settings if they are just added or are open |
|
26 | 26 | include( dirname( __FILE__ ) . '/_action_inside.php' ); |
27 | - } else { |
|
28 | - // include hidden settings so action won't get lost on update ?> |
|
27 | + } else { |
|
28 | + // include hidden settings so action won't get lost on update ?> |
|
29 | 29 | <input type="hidden" name="<?php echo esc_attr( $action_control->get_field_name('post_excerpt', '') ) ?>" class="frm_action_name" value="<?php echo esc_attr( $form_action->post_excerpt ); ?>" /> |
30 | 30 | <input type="hidden" name="<?php echo esc_attr( $action_control->get_field_name('ID', '') ) ?>" value="<?php echo esc_attr( $form_action->ID ); ?>" /> |
31 | 31 | <?php |
32 | - } ?> |
|
32 | + } ?> |
|
33 | 33 | </div> |
34 | 34 | <style type="text/css"> |
35 | 35 | .frm_no_actions{ |
@@ -21,13 +21,13 @@ |
||
21 | 21 | </div> |
22 | 22 | <div class="widget-inside frm_hidden"> |
23 | 23 | <?php |
24 | - if ( defined('DOING_AJAX') || ! $action_control->action_options['ajax_load'] ) { |
|
24 | + if ( defined( 'DOING_AJAX' ) || ! $action_control->action_options['ajax_load'] ) { |
|
25 | 25 | // only load settings if they are just added or are open |
26 | 26 | include( dirname( __FILE__ ) . '/_action_inside.php' ); |
27 | 27 | } else { |
28 | 28 | // include hidden settings so action won't get lost on update ?> |
29 | - <input type="hidden" name="<?php echo esc_attr( $action_control->get_field_name('post_excerpt', '') ) ?>" class="frm_action_name" value="<?php echo esc_attr( $form_action->post_excerpt ); ?>" /> |
|
30 | - <input type="hidden" name="<?php echo esc_attr( $action_control->get_field_name('ID', '') ) ?>" value="<?php echo esc_attr( $form_action->ID ); ?>" /> |
|
29 | + <input type="hidden" name="<?php echo esc_attr( $action_control->get_field_name( 'post_excerpt', '' ) ) ?>" class="frm_action_name" value="<?php echo esc_attr( $form_action->post_excerpt ); ?>" /> |
|
30 | + <input type="hidden" name="<?php echo esc_attr( $action_control->get_field_name( 'ID', '' ) ) ?>" value="<?php echo esc_attr( $form_action->ID ); ?>" /> |
|
31 | 31 | <?php |
32 | 32 | } ?> |
33 | 33 | </div> |
@@ -4,12 +4,12 @@ discard block |
||
4 | 4 | |
5 | 5 | public function __construct() { |
6 | 6 | $action_ops = array( |
7 | - 'classes' => 'frm_email_icon frm_icon_font', |
|
8 | - 'active' => true, |
|
7 | + 'classes' => 'frm_email_icon frm_icon_font', |
|
8 | + 'active' => true, |
|
9 | 9 | 'event' => array( 'create' ), |
10 | - 'limit' => 99, |
|
11 | - 'priority' => 10, |
|
12 | - 'ajax_load' => false, |
|
10 | + 'limit' => 99, |
|
11 | + 'priority' => 10, |
|
12 | + 'ajax_load' => false, |
|
13 | 13 | ); |
14 | 14 | $action_ops = apply_filters('frm_email_control_settings', $action_ops); |
15 | 15 | |
@@ -17,23 +17,23 @@ discard block |
||
17 | 17 | } |
18 | 18 | |
19 | 19 | public function form( $form_action, $args = array() ) { |
20 | - extract($args); |
|
20 | + extract($args); |
|
21 | 21 | |
22 | 22 | include( FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/_email_settings.php' ); |
23 | 23 | } |
24 | 24 | |
25 | 25 | public function get_defaults() { |
26 | - return array( |
|
27 | - 'email_to' => '[admin_email]', |
|
28 | - 'cc' => '', |
|
29 | - 'bcc' => '', |
|
30 | - 'from' => '[sitename] <[admin_email]>', |
|
31 | - 'reply_to' => '', |
|
32 | - 'email_subject' => '', |
|
33 | - 'email_message' => '[default-message]', |
|
34 | - 'inc_user_info' => 0, |
|
35 | - 'plain_text' => 0, |
|
26 | + return array( |
|
27 | + 'email_to' => '[admin_email]', |
|
28 | + 'cc' => '', |
|
29 | + 'bcc' => '', |
|
30 | + 'from' => '[sitename] <[admin_email]>', |
|
31 | + 'reply_to' => '', |
|
32 | + 'email_subject' => '', |
|
33 | + 'email_message' => '[default-message]', |
|
34 | + 'inc_user_info' => 0, |
|
35 | + 'plain_text' => 0, |
|
36 | 36 | 'event' => array( 'create' ), |
37 | - ); |
|
37 | + ); |
|
38 | 38 | } |
39 | 39 | } |
@@ -11,13 +11,13 @@ |
||
11 | 11 | 'priority' => 10, |
12 | 12 | 'ajax_load' => false, |
13 | 13 | ); |
14 | - $action_ops = apply_filters('frm_email_control_settings', $action_ops); |
|
14 | + $action_ops = apply_filters( 'frm_email_control_settings', $action_ops ); |
|
15 | 15 | |
16 | - parent::__construct('email', __( 'Email Notification', 'formidable' ), $action_ops); |
|
16 | + parent::__construct( 'email', __( 'Email Notification', 'formidable' ), $action_ops ); |
|
17 | 17 | } |
18 | 18 | |
19 | 19 | public function form( $form_action, $args = array() ) { |
20 | - extract($args); |
|
20 | + extract( $args ); |
|
21 | 21 | |
22 | 22 | include( FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/_email_settings.php' ); |
23 | 23 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | } |
5 | 5 | |
6 | 6 | class FrmField { |
7 | - static $use_cache = true; |
|
7 | + static $use_cache = true; |
|
8 | 8 | static $transient_size = 200; |
9 | 9 | |
10 | 10 | public static function field_selection() { |
@@ -50,39 +50,39 @@ discard block |
||
50 | 50 | )); |
51 | 51 | } |
52 | 52 | |
53 | - public static function create( $values, $return = true ) { |
|
54 | - global $wpdb, $frm_duplicate_ids; |
|
53 | + public static function create( $values, $return = true ) { |
|
54 | + global $wpdb, $frm_duplicate_ids; |
|
55 | 55 | |
56 | - $new_values = array(); |
|
57 | - $key = isset($values['field_key']) ? $values['field_key'] : $values['name']; |
|
56 | + $new_values = array(); |
|
57 | + $key = isset($values['field_key']) ? $values['field_key'] : $values['name']; |
|
58 | 58 | $new_values['field_key'] = FrmAppHelper::get_unique_key( $key, $wpdb->prefix . 'frm_fields', 'field_key' ); |
59 | 59 | |
60 | 60 | foreach ( array( 'name', 'description', 'type', 'default_value' ) as $col ) { |
61 | 61 | $new_values[ $col ] = $values[ $col ]; |
62 | - } |
|
62 | + } |
|
63 | 63 | |
64 | - $new_values['options'] = $values['options']; |
|
64 | + $new_values['options'] = $values['options']; |
|
65 | 65 | |
66 | - $new_values['field_order'] = isset($values['field_order']) ? (int) $values['field_order'] : null; |
|
67 | - $new_values['required'] = isset($values['required']) ? (int) $values['required'] : 0; |
|
68 | - $new_values['form_id'] = isset($values['form_id']) ? (int) $values['form_id'] : null; |
|
69 | - $new_values['field_options'] = $values['field_options']; |
|
70 | - $new_values['created_at'] = current_time('mysql', 1); |
|
66 | + $new_values['field_order'] = isset($values['field_order']) ? (int) $values['field_order'] : null; |
|
67 | + $new_values['required'] = isset($values['required']) ? (int) $values['required'] : 0; |
|
68 | + $new_values['form_id'] = isset($values['form_id']) ? (int) $values['form_id'] : null; |
|
69 | + $new_values['field_options'] = $values['field_options']; |
|
70 | + $new_values['created_at'] = current_time('mysql', 1); |
|
71 | 71 | |
72 | 72 | if ( isset( $values['id'] ) ) { |
73 | 73 | $frm_duplicate_ids[ $values['field_key'] ] = $new_values['field_key']; |
74 | - $new_values = apply_filters('frm_duplicated_field', $new_values); |
|
75 | - } |
|
74 | + $new_values = apply_filters('frm_duplicated_field', $new_values); |
|
75 | + } |
|
76 | 76 | |
77 | 77 | foreach ( $new_values as $k => $v ) { |
78 | - if ( is_array( $v ) ) { |
|
78 | + if ( is_array( $v ) ) { |
|
79 | 79 | $new_values[ $k ] = serialize( $v ); |
80 | 80 | } |
81 | - unset( $k, $v ); |
|
82 | - } |
|
81 | + unset( $k, $v ); |
|
82 | + } |
|
83 | 83 | |
84 | - //if(isset($values['id']) and is_numeric($values['id'])) |
|
85 | - // $new_values['id'] = $values['id']; |
|
84 | + //if(isset($values['id']) and is_numeric($values['id'])) |
|
85 | + // $new_values['id'] = $values['id']; |
|
86 | 86 | |
87 | 87 | $query_results = $wpdb->insert( $wpdb->prefix . 'frm_fields', $new_values ); |
88 | 88 | $new_id = 0; |
@@ -103,22 +103,22 @@ discard block |
||
103 | 103 | } else { |
104 | 104 | return false; |
105 | 105 | } |
106 | - } |
|
106 | + } |
|
107 | 107 | |
108 | - public static function duplicate( $old_form_id, $form_id, $copy_keys = false, $blog_id = false ) { |
|
109 | - global $frm_duplicate_ids; |
|
108 | + public static function duplicate( $old_form_id, $form_id, $copy_keys = false, $blog_id = false ) { |
|
109 | + global $frm_duplicate_ids; |
|
110 | 110 | |
111 | 111 | $where = array( array( 'or' => 1, 'fi.form_id' => $old_form_id, 'fr.parent_form_id' => $old_form_id ) ); |
112 | 112 | $fields = self::getAll( $where, 'field_order', '', $blog_id ); |
113 | 113 | |
114 | - foreach ( (array) $fields as $field ) { |
|
115 | - $new_key = ($copy_keys) ? $field->field_key : ''; |
|
116 | - if ( $copy_keys && substr($field->field_key, -1) == 2 ) { |
|
117 | - $new_key = rtrim($new_key, 2); |
|
118 | - } |
|
114 | + foreach ( (array) $fields as $field ) { |
|
115 | + $new_key = ($copy_keys) ? $field->field_key : ''; |
|
116 | + if ( $copy_keys && substr($field->field_key, -1) == 2 ) { |
|
117 | + $new_key = rtrim($new_key, 2); |
|
118 | + } |
|
119 | 119 | |
120 | - $values = array(); |
|
121 | - FrmFieldsHelper::fill_field( $values, $field, $form_id, $new_key ); |
|
120 | + $values = array(); |
|
121 | + FrmFieldsHelper::fill_field( $values, $field, $form_id, $new_key ); |
|
122 | 122 | |
123 | 123 | // If this is a repeating section, create new form |
124 | 124 | if ( self::is_repeating_field( $field ) ) { |
@@ -137,16 +137,16 @@ discard block |
||
137 | 137 | $values['form_id'] = $new_repeat_form_id; |
138 | 138 | } |
139 | 139 | |
140 | - $values = apply_filters('frm_duplicated_field', $values); |
|
141 | - $new_id = self::create($values); |
|
142 | - $frm_duplicate_ids[ $field->id ] = $new_id; |
|
143 | - $frm_duplicate_ids[ $field->field_key ] = $new_id; |
|
144 | - unset($field); |
|
145 | - } |
|
146 | - } |
|
140 | + $values = apply_filters('frm_duplicated_field', $values); |
|
141 | + $new_id = self::create($values); |
|
142 | + $frm_duplicate_ids[ $field->id ] = $new_id; |
|
143 | + $frm_duplicate_ids[ $field->field_key ] = $new_id; |
|
144 | + unset($field); |
|
145 | + } |
|
146 | + } |
|
147 | 147 | |
148 | 148 | public static function update( $id, $values ) { |
149 | - global $wpdb; |
|
149 | + global $wpdb; |
|
150 | 150 | |
151 | 151 | $id = absint( $id ); |
152 | 152 | |
@@ -154,9 +154,9 @@ discard block |
||
154 | 154 | $values['field_key'] = FrmAppHelper::get_unique_key( $values['field_key'], $wpdb->prefix . 'frm_fields', 'field_key', $id ); |
155 | 155 | } |
156 | 156 | |
157 | - if ( isset($values['required']) ) { |
|
158 | - $values['required'] = (int) $values['required']; |
|
159 | - } |
|
157 | + if ( isset($values['required']) ) { |
|
158 | + $values['required'] = (int) $values['required']; |
|
159 | + } |
|
160 | 160 | |
161 | 161 | self::preserve_phone_format_backslashes( $values ); |
162 | 162 | |
@@ -169,41 +169,41 @@ discard block |
||
169 | 169 | |
170 | 170 | $query_results = $wpdb->update( $wpdb->prefix . 'frm_fields', $values, array( 'id' => $id ) ); |
171 | 171 | |
172 | - $form_id = 0; |
|
172 | + $form_id = 0; |
|
173 | 173 | if ( isset( $values['form_id'] ) ) { |
174 | - $form_id = absint( $values['form_id'] ); |
|
174 | + $form_id = absint( $values['form_id'] ); |
|
175 | 175 | } else { |
176 | - $field = self::getOne($id); |
|
177 | - if ( $field ) { |
|
178 | - $form_id = $field->form_id; |
|
179 | - } |
|
180 | - unset($field); |
|
181 | - } |
|
182 | - unset($values); |
|
176 | + $field = self::getOne($id); |
|
177 | + if ( $field ) { |
|
178 | + $form_id = $field->form_id; |
|
179 | + } |
|
180 | + unset($field); |
|
181 | + } |
|
182 | + unset($values); |
|
183 | 183 | |
184 | 184 | if ( $query_results ) { |
185 | - wp_cache_delete( $id, 'frm_field' ); |
|
186 | - if ( $form_id ) { |
|
187 | - self::delete_form_transient($form_id); |
|
188 | - } |
|
189 | - } |
|
185 | + wp_cache_delete( $id, 'frm_field' ); |
|
186 | + if ( $form_id ) { |
|
187 | + self::delete_form_transient($form_id); |
|
188 | + } |
|
189 | + } |
|
190 | 190 | |
191 | - return $query_results; |
|
192 | - } |
|
191 | + return $query_results; |
|
192 | + } |
|
193 | 193 | |
194 | 194 | /** |
195 | - * Keep backslashes in the phone format option |
|
196 | - * |
|
197 | - * @since 2.0.8 |
|
198 | - * @param $values array - pass by reference |
|
199 | - */ |
|
195 | + * Keep backslashes in the phone format option |
|
196 | + * |
|
197 | + * @since 2.0.8 |
|
198 | + * @param $values array - pass by reference |
|
199 | + */ |
|
200 | 200 | private static function preserve_phone_format_backslashes( &$values ) { |
201 | 201 | if ( isset( $values['field_options']['format'] ) ) { |
202 | 202 | $values['field_options']['format'] = FrmAppHelper::preserve_backslashes( $values['field_options']['format'] ); |
203 | 203 | } |
204 | 204 | } |
205 | 205 | |
206 | - public static function destroy( $id ) { |
|
206 | + public static function destroy( $id ) { |
|
207 | 207 | global $wpdb; |
208 | 208 | |
209 | 209 | do_action( 'frm_before_destroy_field', $id ); |
@@ -218,7 +218,7 @@ discard block |
||
218 | 218 | |
219 | 219 | $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_item_metas WHERE field_id=%d', $id ) ); |
220 | 220 | return $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_fields WHERE id=%d', $id ) ); |
221 | - } |
|
221 | + } |
|
222 | 222 | |
223 | 223 | public static function delete_form_transient( $form_id ) { |
224 | 224 | $form_id = absint( $form_id ); |
@@ -231,16 +231,16 @@ discard block |
||
231 | 231 | $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->options . ' WHERE option_name LIKE %s OR option_name LIKE %s OR option_name LIKE %s OR option_name LIKE %s', '_transient_timeout_frm_form_fields_' . $form_id . 'ex%', '_transient_frm_form_fields_' . $form_id . 'ex%', '_transient_timeout_frm_form_fields_' . $form_id . 'in%', '_transient_frm_form_fields_' . $form_id . 'in%' ) ); |
232 | 232 | |
233 | 233 | $cache_key = serialize( array( 'fi.form_id' => $form_id ) ) . 'field_orderlb'; |
234 | - wp_cache_delete($cache_key, 'frm_field'); |
|
234 | + wp_cache_delete($cache_key, 'frm_field'); |
|
235 | 235 | |
236 | 236 | // this cache key is autogenerated in FrmDb::get_var |
237 | 237 | wp_cache_delete( '(__fi.form_id=%d_OR_fr.parent_form_id=%d_)__' . $form_id . '_' . $form_id . '_ORDER_BY_field_orderfi.*__fr.name_as_form_name_results', 'frm_field' ); |
238 | 238 | |
239 | - $form = FrmForm::getOne($form_id); |
|
240 | - if ( $form && $form->parent_form_id ) { |
|
241 | - self::delete_form_transient( $form->parent_form_id ); |
|
242 | - } |
|
243 | - } |
|
239 | + $form = FrmForm::getOne($form_id); |
|
240 | + if ( $form && $form->parent_form_id ) { |
|
241 | + self::delete_form_transient( $form->parent_form_id ); |
|
242 | + } |
|
243 | + } |
|
244 | 244 | |
245 | 245 | /** |
246 | 246 | * If $field is numeric, get the field object |
@@ -256,131 +256,131 @@ discard block |
||
256 | 256 | return; |
257 | 257 | } |
258 | 258 | |
259 | - global $wpdb; |
|
259 | + global $wpdb; |
|
260 | 260 | |
261 | - $where = is_numeric($id) ? 'id=%d' : 'field_key=%s'; |
|
261 | + $where = is_numeric($id) ? 'id=%d' : 'field_key=%s'; |
|
262 | 262 | $query = $wpdb->prepare( 'SELECT * FROM ' . $wpdb->prefix . 'frm_fields WHERE ' . $where, $id ); |
263 | 263 | |
264 | - $results = FrmAppHelper::check_cache( $id, 'frm_field', $query, 'get_row', 0 ); |
|
264 | + $results = FrmAppHelper::check_cache( $id, 'frm_field', $query, 'get_row', 0 ); |
|
265 | 265 | |
266 | - if ( empty($results) ) { |
|
267 | - return $results; |
|
268 | - } |
|
266 | + if ( empty($results) ) { |
|
267 | + return $results; |
|
268 | + } |
|
269 | 269 | |
270 | - if ( is_numeric($id) ) { |
|
271 | - wp_cache_set( $results->field_key, $results, 'frm_field' ); |
|
272 | - } else if ( $results ) { |
|
273 | - wp_cache_set( $results->id, $results, 'frm_field' ); |
|
274 | - } |
|
270 | + if ( is_numeric($id) ) { |
|
271 | + wp_cache_set( $results->field_key, $results, 'frm_field' ); |
|
272 | + } else if ( $results ) { |
|
273 | + wp_cache_set( $results->id, $results, 'frm_field' ); |
|
274 | + } |
|
275 | 275 | |
276 | 276 | self::prepare_options( $results ); |
277 | 277 | |
278 | - return stripslashes_deep($results); |
|
279 | - } |
|
278 | + return stripslashes_deep($results); |
|
279 | + } |
|
280 | 280 | |
281 | - /** |
|
282 | - * Get the field type by key or id |
|
283 | - * @param int|string The field id or key |
|
281 | + /** |
|
282 | + * Get the field type by key or id |
|
283 | + * @param int|string The field id or key |
|
284 | 284 | * @param mixed $col The name of the column in the fields database table |
285 | - */ |
|
286 | - public static function &get_type( $id, $col = 'type' ) { |
|
287 | - $field = FrmAppHelper::check_cache( $id, 'frm_field' ); |
|
288 | - if ( $field ) { |
|
289 | - $type = $field->{$col}; |
|
290 | - } else { |
|
291 | - $type = FrmDb::get_var( 'frm_fields', array( 'or' => 1, 'id' => $id, 'field_key' => $id ), $col ); |
|
292 | - } |
|
293 | - |
|
294 | - return $type; |
|
295 | - } |
|
285 | + */ |
|
286 | + public static function &get_type( $id, $col = 'type' ) { |
|
287 | + $field = FrmAppHelper::check_cache( $id, 'frm_field' ); |
|
288 | + if ( $field ) { |
|
289 | + $type = $field->{$col}; |
|
290 | + } else { |
|
291 | + $type = FrmDb::get_var( 'frm_fields', array( 'or' => 1, 'id' => $id, 'field_key' => $id ), $col ); |
|
292 | + } |
|
293 | + |
|
294 | + return $type; |
|
295 | + } |
|
296 | 296 | |
297 | 297 | public static function get_all_types_in_form( $form_id, $type, $limit = '', $inc_sub = 'exclude' ) { |
298 | - if ( ! $form_id ) { |
|
299 | - return array(); |
|
300 | - } |
|
298 | + if ( ! $form_id ) { |
|
299 | + return array(); |
|
300 | + } |
|
301 | 301 | |
302 | 302 | $results = self::get_fields_from_transients( $form_id, array( 'inc_embed' => $inc_sub, 'inc_repeat' => $inc_sub ) ); |
303 | 303 | if ( ! empty( $results ) ) { |
304 | - $fields = array(); |
|
305 | - $count = 0; |
|
306 | - foreach ( $results as $result ) { |
|
307 | - if ( $type != $result->type ) { |
|
308 | - continue; |
|
309 | - } |
|
304 | + $fields = array(); |
|
305 | + $count = 0; |
|
306 | + foreach ( $results as $result ) { |
|
307 | + if ( $type != $result->type ) { |
|
308 | + continue; |
|
309 | + } |
|
310 | 310 | |
311 | 311 | $fields[ $result->id ] = $result; |
312 | - $count++; |
|
313 | - if ( $limit == 1 ) { |
|
314 | - $fields = $result; |
|
315 | - break; |
|
316 | - } |
|
312 | + $count++; |
|
313 | + if ( $limit == 1 ) { |
|
314 | + $fields = $result; |
|
315 | + break; |
|
316 | + } |
|
317 | 317 | |
318 | - if ( ! empty($limit) && $count >= $limit ) { |
|
319 | - break; |
|
320 | - } |
|
318 | + if ( ! empty($limit) && $count >= $limit ) { |
|
319 | + break; |
|
320 | + } |
|
321 | 321 | |
322 | - unset($result); |
|
323 | - } |
|
324 | - return stripslashes_deep($fields); |
|
325 | - } |
|
322 | + unset($result); |
|
323 | + } |
|
324 | + return stripslashes_deep($fields); |
|
325 | + } |
|
326 | 326 | |
327 | - self::$use_cache = false; |
|
327 | + self::$use_cache = false; |
|
328 | 328 | |
329 | 329 | $where = array( 'fi.form_id' => (int) $form_id, 'fi.type' => $type ); |
330 | 330 | self::maybe_include_repeating_fields( $inc_sub, $where ); |
331 | 331 | $results = self::getAll( $where, 'field_order', $limit ); |
332 | - self::$use_cache = true; |
|
333 | - self::include_sub_fields($results, $inc_sub, $type); |
|
332 | + self::$use_cache = true; |
|
333 | + self::include_sub_fields($results, $inc_sub, $type); |
|
334 | 334 | |
335 | - return $results; |
|
336 | - } |
|
335 | + return $results; |
|
336 | + } |
|
337 | 337 | |
338 | 338 | public static function get_all_for_form( $form_id, $limit = '', $inc_embed = 'exclude', $inc_repeat = 'include' ) { |
339 | - if ( ! (int) $form_id ) { |
|
340 | - return array(); |
|
341 | - } |
|
339 | + if ( ! (int) $form_id ) { |
|
340 | + return array(); |
|
341 | + } |
|
342 | 342 | |
343 | 343 | $results = self::get_fields_from_transients( $form_id, array( 'inc_embed' => $inc_embed, 'inc_repeat' => $inc_repeat ) ); |
344 | 344 | if ( ! empty( $results ) ) { |
345 | - if ( empty($limit) ) { |
|
345 | + if ( empty($limit) ) { |
|
346 | 346 | return $results; |
347 | - } |
|
347 | + } |
|
348 | 348 | |
349 | - $fields = array(); |
|
350 | - $count = 0; |
|
351 | - foreach ( $results as $result ) { |
|
349 | + $fields = array(); |
|
350 | + $count = 0; |
|
351 | + foreach ( $results as $result ) { |
|
352 | 352 | $fields[ $result->id ] = $result; |
353 | - if ( ! empty($limit) && $count >= $limit ) { |
|
354 | - break; |
|
355 | - } |
|
356 | - } |
|
353 | + if ( ! empty($limit) && $count >= $limit ) { |
|
354 | + break; |
|
355 | + } |
|
356 | + } |
|
357 | 357 | |
358 | 358 | return $fields; |
359 | - } |
|
359 | + } |
|
360 | 360 | |
361 | - self::$use_cache = false; |
|
361 | + self::$use_cache = false; |
|
362 | 362 | |
363 | 363 | $where = array( 'fi.form_id' => absint( $form_id ) ); |
364 | 364 | self::maybe_include_repeating_fields( $inc_repeat, $where ); |
365 | 365 | $results = self::getAll( $where, 'field_order', $limit ); |
366 | 366 | |
367 | - self::$use_cache = true; |
|
367 | + self::$use_cache = true; |
|
368 | 368 | |
369 | 369 | self::include_sub_fields( $results, $inc_embed, 'all' ); |
370 | 370 | |
371 | - if ( empty($limit) ) { |
|
371 | + if ( empty($limit) ) { |
|
372 | 372 | self::set_field_transient( $results, $form_id, 0, array( 'inc_embed' => $inc_embed, 'inc_repeat' => $inc_repeat ) ); |
373 | - } |
|
373 | + } |
|
374 | 374 | |
375 | 375 | return $results; |
376 | - } |
|
376 | + } |
|
377 | 377 | |
378 | 378 | /** |
379 | - * If repeating fields should be included, adjust $where accordingly |
|
380 | - * |
|
381 | - * @param string $inc_repeat |
|
382 | - * @param array $where - pass by reference |
|
383 | - */ |
|
379 | + * If repeating fields should be included, adjust $where accordingly |
|
380 | + * |
|
381 | + * @param string $inc_repeat |
|
382 | + * @param array $where - pass by reference |
|
383 | + */ |
|
384 | 384 | private static function maybe_include_repeating_fields( $inc_repeat, &$where ) { |
385 | 385 | if ( $inc_repeat == 'include' ) { |
386 | 386 | $form_id = $where['fi.form_id']; |
@@ -391,77 +391,77 @@ discard block |
||
391 | 391 | |
392 | 392 | public static function include_sub_fields( &$results, $inc_embed, $type = 'all' ) { |
393 | 393 | if ( 'include' != $inc_embed ) { |
394 | - return; |
|
395 | - } |
|
394 | + return; |
|
395 | + } |
|
396 | 396 | |
397 | - $form_fields = $results; |
|
397 | + $form_fields = $results; |
|
398 | 398 | $index_offset = 1; |
399 | - foreach ( $form_fields as $k => $field ) { |
|
400 | - if ( 'form' != $field->type || ! isset($field->field_options['form_select']) ) { |
|
401 | - continue; |
|
402 | - } |
|
403 | - |
|
404 | - if ( $type == 'all' ) { |
|
405 | - $sub_fields = self::get_all_for_form( $field->field_options['form_select'] ); |
|
406 | - } else { |
|
407 | - $sub_fields = self::get_all_types_in_form($field->form_id, $type); |
|
408 | - } |
|
409 | - |
|
410 | - if ( ! empty($sub_fields) ) { |
|
399 | + foreach ( $form_fields as $k => $field ) { |
|
400 | + if ( 'form' != $field->type || ! isset($field->field_options['form_select']) ) { |
|
401 | + continue; |
|
402 | + } |
|
403 | + |
|
404 | + if ( $type == 'all' ) { |
|
405 | + $sub_fields = self::get_all_for_form( $field->field_options['form_select'] ); |
|
406 | + } else { |
|
407 | + $sub_fields = self::get_all_types_in_form($field->form_id, $type); |
|
408 | + } |
|
409 | + |
|
410 | + if ( ! empty($sub_fields) ) { |
|
411 | 411 | $index = $k + $index_offset; |
412 | 412 | $index_offset += count( $sub_fields ); |
413 | 413 | array_splice($results, $index, 0, $sub_fields); |
414 | - } |
|
415 | - unset($field, $sub_fields); |
|
416 | - } |
|
417 | - } |
|
414 | + } |
|
415 | + unset($field, $sub_fields); |
|
416 | + } |
|
417 | + } |
|
418 | 418 | |
419 | 419 | public static function getAll( $where = array(), $order_by = '', $limit = '', $blog_id = false ) { |
420 | 420 | $cache_key = maybe_serialize( $where ) . $order_by . 'l' . $limit . 'b' . $blog_id; |
421 | - if ( self::$use_cache ) { |
|
422 | - // make sure old cache doesn't get saved as a transient |
|
423 | - $results = wp_cache_get($cache_key, 'frm_field'); |
|
424 | - if ( false !== $results ) { |
|
425 | - return stripslashes_deep($results); |
|
426 | - } |
|
427 | - } |
|
428 | - |
|
429 | - global $wpdb; |
|
430 | - |
|
431 | - if ( $blog_id && is_multisite() ) { |
|
432 | - global $wpmuBaseTablePrefix; |
|
433 | - if ( $wpmuBaseTablePrefix ) { |
|
421 | + if ( self::$use_cache ) { |
|
422 | + // make sure old cache doesn't get saved as a transient |
|
423 | + $results = wp_cache_get($cache_key, 'frm_field'); |
|
424 | + if ( false !== $results ) { |
|
425 | + return stripslashes_deep($results); |
|
426 | + } |
|
427 | + } |
|
428 | + |
|
429 | + global $wpdb; |
|
430 | + |
|
431 | + if ( $blog_id && is_multisite() ) { |
|
432 | + global $wpmuBaseTablePrefix; |
|
433 | + if ( $wpmuBaseTablePrefix ) { |
|
434 | 434 | $prefix = $wpmuBaseTablePrefix . $blog_id . '_'; |
435 | - } else { |
|
436 | - $prefix = $wpdb->get_blog_prefix( $blog_id ); |
|
437 | - } |
|
435 | + } else { |
|
436 | + $prefix = $wpdb->get_blog_prefix( $blog_id ); |
|
437 | + } |
|
438 | 438 | |
439 | 439 | $table_name = $prefix . 'frm_fields'; |
440 | 440 | $form_table_name = $prefix . 'frm_forms'; |
441 | 441 | } else { |
442 | 442 | $table_name = $wpdb->prefix . 'frm_fields'; |
443 | 443 | $form_table_name = $wpdb->prefix . 'frm_forms'; |
444 | - } |
|
444 | + } |
|
445 | 445 | |
446 | 446 | if ( ! empty( $order_by ) && strpos( $order_by, 'ORDER BY' ) === false ) { |
447 | 447 | $order_by = ' ORDER BY ' . $order_by; |
448 | 448 | } |
449 | 449 | |
450 | - $limit = FrmAppHelper::esc_limit($limit); |
|
450 | + $limit = FrmAppHelper::esc_limit($limit); |
|
451 | 451 | |
452 | - $query = "SELECT fi.*, fr.name as form_name FROM {$table_name} fi LEFT OUTER JOIN {$form_table_name} fr ON fi.form_id=fr.id"; |
|
453 | - $query_type = ( $limit == ' LIMIT 1' || $limit == 1 ) ? 'row' : 'results'; |
|
452 | + $query = "SELECT fi.*, fr.name as form_name FROM {$table_name} fi LEFT OUTER JOIN {$form_table_name} fr ON fi.form_id=fr.id"; |
|
453 | + $query_type = ( $limit == ' LIMIT 1' || $limit == 1 ) ? 'row' : 'results'; |
|
454 | 454 | |
455 | - if ( is_array($where) ) { |
|
456 | - $results = FrmDb::get_var( $table_name . ' fi LEFT OUTER JOIN ' . $form_table_name . ' fr ON fi.form_id=fr.id', $where, 'fi.*, fr.name as form_name', array( 'order_by' => $order_by, 'limit' => $limit ), '', $query_type ); |
|
455 | + if ( is_array($where) ) { |
|
456 | + $results = FrmDb::get_var( $table_name . ' fi LEFT OUTER JOIN ' . $form_table_name . ' fr ON fi.form_id=fr.id', $where, 'fi.*, fr.name as form_name', array( 'order_by' => $order_by, 'limit' => $limit ), '', $query_type ); |
|
457 | 457 | } else { |
458 | 458 | // if the query is not an array, then it has already been prepared |
459 | - $query .= FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit; |
|
459 | + $query .= FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit; |
|
460 | 460 | |
461 | 461 | $function_name = ( $query_type == 'row' ) ? 'get_row' : 'get_results'; |
462 | 462 | $results = $wpdb->$function_name( $query ); |
463 | - } |
|
464 | - unset( $where ); |
|
463 | + } |
|
464 | + unset( $where ); |
|
465 | 465 | |
466 | 466 | self::format_field_results( $results ); |
467 | 467 | |
@@ -560,21 +560,21 @@ discard block |
||
560 | 560 | |
561 | 561 | public static function getIds( $where = '', $order_by = '', $limit = '' ) { |
562 | 562 | _deprecated_function( __FUNCTION__, '2.0' ); |
563 | - global $wpdb; |
|
564 | - if ( ! empty($order_by) && ! strpos($order_by, 'ORDER BY') !== false ) { |
|
563 | + global $wpdb; |
|
564 | + if ( ! empty($order_by) && ! strpos($order_by, 'ORDER BY') !== false ) { |
|
565 | 565 | $order_by = ' ORDER BY ' . $order_by; |
566 | - } |
|
566 | + } |
|
567 | 567 | |
568 | 568 | $query = 'SELECT fi.id FROM ' . $wpdb->prefix . 'frm_fields fi ' . |
569 | 569 | 'LEFT OUTER JOIN '. $wpdb->prefix . 'frm_forms fr ON fi.form_id=fr.id' . |
570 | 570 | FrmAppHelper::prepend_and_or_where( ' WHERE ', $where ) . $order_by . $limit; |
571 | 571 | |
572 | - $method = ( $limit == ' LIMIT 1' || $limit == 1 ) ? 'get_var' : 'get_col'; |
|
572 | + $method = ( $limit == ' LIMIT 1' || $limit == 1 ) ? 'get_var' : 'get_col'; |
|
573 | 573 | $cache_key = 'getIds_' . maybe_serialize( $where ) . $order_by . $limit; |
574 | - $results = FrmAppHelper::check_cache($cache_key, 'frm_field', $query, $method); |
|
574 | + $results = FrmAppHelper::check_cache($cache_key, 'frm_field', $query, $method); |
|
575 | 575 | |
576 | - return $results; |
|
577 | - } |
|
576 | + return $results; |
|
577 | + } |
|
578 | 578 | |
579 | 579 | public static function is_no_save_field( $type ) { |
580 | 580 | return in_array( $type, self::no_save_fields() ); |
@@ -701,8 +701,8 @@ discard block |
||
701 | 701 | } |
702 | 702 | |
703 | 703 | /** |
704 | - * @since 2.0.09 |
|
705 | - */ |
|
704 | + * @since 2.0.09 |
|
705 | + */ |
|
706 | 706 | public static function is_repeating_field( $field ) { |
707 | 707 | if ( is_array( $field ) ) { |
708 | 708 | $is_repeating_field = ( 'divider' == $field['type'] ); |
@@ -712,12 +712,12 @@ discard block |
||
712 | 712 | return ( $is_repeating_field && self::is_option_true( $field, 'repeat' ) ); |
713 | 713 | } |
714 | 714 | |
715 | - /** |
|
716 | - * @param string $key |
|
717 | - * @return int field id |
|
718 | - */ |
|
715 | + /** |
|
716 | + * @param string $key |
|
717 | + * @return int field id |
|
718 | + */ |
|
719 | 719 | public static function get_id_by_key( $key ) { |
720 | - $id = FrmDb::get_var( 'frm_fields', array( 'field_key' => sanitize_title( $key ) ) ); |
|
721 | - return $id; |
|
722 | - } |
|
720 | + $id = FrmDb::get_var( 'frm_fields', array( 'field_key' => sanitize_title( $key ) ) ); |
|
721 | + return $id; |
|
722 | + } |
|
723 | 723 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined('ABSPATH') ) { |
|
2 | +if ( ! defined( 'ABSPATH' ) ) { |
|
3 | 3 | die( 'You are not allowed to call this page directly.' ); |
4 | 4 | } |
5 | 5 | |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | static $transient_size = 200; |
9 | 9 | |
10 | 10 | public static function field_selection() { |
11 | - $fields = apply_filters('frm_available_fields', array( |
|
11 | + $fields = apply_filters( 'frm_available_fields', array( |
|
12 | 12 | 'text' => __( 'Single Line Text', 'formidable' ), |
13 | 13 | 'textarea' => __( 'Paragraph Text', 'formidable' ), |
14 | 14 | 'checkbox' => __( 'Checkboxes', 'formidable' ), |
@@ -17,13 +17,13 @@ discard block |
||
17 | 17 | 'email' => __( 'Email Address', 'formidable' ), |
18 | 18 | 'url' => __( 'Website/URL', 'formidable' ), |
19 | 19 | 'captcha' => __( 'reCAPTCHA', 'formidable' ), |
20 | - )); |
|
20 | + ) ); |
|
21 | 21 | |
22 | 22 | return $fields; |
23 | 23 | } |
24 | 24 | |
25 | 25 | public static function pro_field_selection() { |
26 | - return apply_filters('frm_pro_available_fields', array( |
|
26 | + return apply_filters( 'frm_pro_available_fields', array( |
|
27 | 27 | 'end_divider' => array( |
28 | 28 | 'name' => __( 'End Section', 'formidable' ), |
29 | 29 | 'switch_from' => 'divider', |
@@ -47,36 +47,36 @@ discard block |
||
47 | 47 | 'tag' => __( 'Tags', 'formidable' ), |
48 | 48 | 'credit_card' => __( 'Credit Card', 'formidable' ), |
49 | 49 | 'address' => __( 'Address', 'formidable' ), |
50 | - )); |
|
50 | + ) ); |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | public static function create( $values, $return = true ) { |
54 | 54 | global $wpdb, $frm_duplicate_ids; |
55 | 55 | |
56 | 56 | $new_values = array(); |
57 | - $key = isset($values['field_key']) ? $values['field_key'] : $values['name']; |
|
57 | + $key = isset( $values['field_key'] ) ? $values['field_key'] : $values['name']; |
|
58 | 58 | $new_values['field_key'] = FrmAppHelper::get_unique_key( $key, $wpdb->prefix . 'frm_fields', 'field_key' ); |
59 | 59 | |
60 | 60 | foreach ( array( 'name', 'description', 'type', 'default_value' ) as $col ) { |
61 | - $new_values[ $col ] = $values[ $col ]; |
|
61 | + $new_values[$col] = $values[$col]; |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | $new_values['options'] = $values['options']; |
65 | 65 | |
66 | - $new_values['field_order'] = isset($values['field_order']) ? (int) $values['field_order'] : null; |
|
67 | - $new_values['required'] = isset($values['required']) ? (int) $values['required'] : 0; |
|
68 | - $new_values['form_id'] = isset($values['form_id']) ? (int) $values['form_id'] : null; |
|
66 | + $new_values['field_order'] = isset( $values['field_order'] ) ? (int) $values['field_order'] : null; |
|
67 | + $new_values['required'] = isset( $values['required'] ) ? (int) $values['required'] : 0; |
|
68 | + $new_values['form_id'] = isset( $values['form_id'] ) ? (int) $values['form_id'] : null; |
|
69 | 69 | $new_values['field_options'] = $values['field_options']; |
70 | - $new_values['created_at'] = current_time('mysql', 1); |
|
70 | + $new_values['created_at'] = current_time( 'mysql', 1 ); |
|
71 | 71 | |
72 | 72 | if ( isset( $values['id'] ) ) { |
73 | - $frm_duplicate_ids[ $values['field_key'] ] = $new_values['field_key']; |
|
74 | - $new_values = apply_filters('frm_duplicated_field', $new_values); |
|
73 | + $frm_duplicate_ids[$values['field_key']] = $new_values['field_key']; |
|
74 | + $new_values = apply_filters( 'frm_duplicated_field', $new_values ); |
|
75 | 75 | } |
76 | 76 | |
77 | 77 | foreach ( $new_values as $k => $v ) { |
78 | 78 | if ( is_array( $v ) ) { |
79 | - $new_values[ $k ] = serialize( $v ); |
|
79 | + $new_values[$k] = serialize( $v ); |
|
80 | 80 | } |
81 | 81 | unset( $k, $v ); |
82 | 82 | } |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | |
98 | 98 | if ( $query_results ) { |
99 | 99 | if ( isset( $values['id'] ) ) { |
100 | - $frm_duplicate_ids[ $values['id'] ] = $new_id; |
|
100 | + $frm_duplicate_ids[$values['id']] = $new_id; |
|
101 | 101 | } |
102 | 102 | return $new_id; |
103 | 103 | } else { |
@@ -112,9 +112,9 @@ discard block |
||
112 | 112 | $fields = self::getAll( $where, 'field_order', '', $blog_id ); |
113 | 113 | |
114 | 114 | foreach ( (array) $fields as $field ) { |
115 | - $new_key = ($copy_keys) ? $field->field_key : ''; |
|
116 | - if ( $copy_keys && substr($field->field_key, -1) == 2 ) { |
|
117 | - $new_key = rtrim($new_key, 2); |
|
115 | + $new_key = ( $copy_keys ) ? $field->field_key : ''; |
|
116 | + if ( $copy_keys && substr( $field->field_key, -1 ) == 2 ) { |
|
117 | + $new_key = rtrim( $new_key, 2 ); |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | $values = array(); |
@@ -137,11 +137,11 @@ discard block |
||
137 | 137 | $values['form_id'] = $new_repeat_form_id; |
138 | 138 | } |
139 | 139 | |
140 | - $values = apply_filters('frm_duplicated_field', $values); |
|
141 | - $new_id = self::create($values); |
|
142 | - $frm_duplicate_ids[ $field->id ] = $new_id; |
|
143 | - $frm_duplicate_ids[ $field->field_key ] = $new_id; |
|
144 | - unset($field); |
|
140 | + $values = apply_filters( 'frm_duplicated_field', $values ); |
|
141 | + $new_id = self::create( $values ); |
|
142 | + $frm_duplicate_ids[$field->id] = $new_id; |
|
143 | + $frm_duplicate_ids[$field->field_key] = $new_id; |
|
144 | + unset( $field ); |
|
145 | 145 | } |
146 | 146 | } |
147 | 147 | |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | $values['field_key'] = FrmAppHelper::get_unique_key( $values['field_key'], $wpdb->prefix . 'frm_fields', 'field_key', $id ); |
155 | 155 | } |
156 | 156 | |
157 | - if ( isset($values['required']) ) { |
|
157 | + if ( isset( $values['required'] ) ) { |
|
158 | 158 | $values['required'] = (int) $values['required']; |
159 | 159 | } |
160 | 160 | |
@@ -162,8 +162,8 @@ discard block |
||
162 | 162 | |
163 | 163 | // serialize array values |
164 | 164 | foreach ( array( 'default_value', 'field_options', 'options' ) as $opt ) { |
165 | - if ( isset( $values[ $opt ] ) && is_array( $values[ $opt ] ) ) { |
|
166 | - $values[ $opt ] = serialize( $values[ $opt ] ); |
|
165 | + if ( isset( $values[$opt] ) && is_array( $values[$opt] ) ) { |
|
166 | + $values[$opt] = serialize( $values[$opt] ); |
|
167 | 167 | } |
168 | 168 | } |
169 | 169 | |
@@ -173,18 +173,18 @@ discard block |
||
173 | 173 | if ( isset( $values['form_id'] ) ) { |
174 | 174 | $form_id = absint( $values['form_id'] ); |
175 | 175 | } else { |
176 | - $field = self::getOne($id); |
|
176 | + $field = self::getOne( $id ); |
|
177 | 177 | if ( $field ) { |
178 | 178 | $form_id = $field->form_id; |
179 | 179 | } |
180 | - unset($field); |
|
180 | + unset( $field ); |
|
181 | 181 | } |
182 | - unset($values); |
|
182 | + unset( $values ); |
|
183 | 183 | |
184 | 184 | if ( $query_results ) { |
185 | 185 | wp_cache_delete( $id, 'frm_field' ); |
186 | 186 | if ( $form_id ) { |
187 | - self::delete_form_transient($form_id); |
|
187 | + self::delete_form_transient( $form_id ); |
|
188 | 188 | } |
189 | 189 | } |
190 | 190 | |
@@ -231,12 +231,12 @@ discard block |
||
231 | 231 | $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->options . ' WHERE option_name LIKE %s OR option_name LIKE %s OR option_name LIKE %s OR option_name LIKE %s', '_transient_timeout_frm_form_fields_' . $form_id . 'ex%', '_transient_frm_form_fields_' . $form_id . 'ex%', '_transient_timeout_frm_form_fields_' . $form_id . 'in%', '_transient_frm_form_fields_' . $form_id . 'in%' ) ); |
232 | 232 | |
233 | 233 | $cache_key = serialize( array( 'fi.form_id' => $form_id ) ) . 'field_orderlb'; |
234 | - wp_cache_delete($cache_key, 'frm_field'); |
|
234 | + wp_cache_delete( $cache_key, 'frm_field' ); |
|
235 | 235 | |
236 | 236 | // this cache key is autogenerated in FrmDb::get_var |
237 | 237 | wp_cache_delete( '(__fi.form_id=%d_OR_fr.parent_form_id=%d_)__' . $form_id . '_' . $form_id . '_ORDER_BY_field_orderfi.*__fr.name_as_form_name_results', 'frm_field' ); |
238 | 238 | |
239 | - $form = FrmForm::getOne($form_id); |
|
239 | + $form = FrmForm::getOne( $form_id ); |
|
240 | 240 | if ( $form && $form->parent_form_id ) { |
241 | 241 | self::delete_form_transient( $form->parent_form_id ); |
242 | 242 | } |
@@ -258,16 +258,16 @@ discard block |
||
258 | 258 | |
259 | 259 | global $wpdb; |
260 | 260 | |
261 | - $where = is_numeric($id) ? 'id=%d' : 'field_key=%s'; |
|
261 | + $where = is_numeric( $id ) ? 'id=%d' : 'field_key=%s'; |
|
262 | 262 | $query = $wpdb->prepare( 'SELECT * FROM ' . $wpdb->prefix . 'frm_fields WHERE ' . $where, $id ); |
263 | 263 | |
264 | 264 | $results = FrmAppHelper::check_cache( $id, 'frm_field', $query, 'get_row', 0 ); |
265 | 265 | |
266 | - if ( empty($results) ) { |
|
266 | + if ( empty( $results ) ) { |
|
267 | 267 | return $results; |
268 | 268 | } |
269 | 269 | |
270 | - if ( is_numeric($id) ) { |
|
270 | + if ( is_numeric( $id ) ) { |
|
271 | 271 | wp_cache_set( $results->field_key, $results, 'frm_field' ); |
272 | 272 | } else if ( $results ) { |
273 | 273 | wp_cache_set( $results->id, $results, 'frm_field' ); |
@@ -275,7 +275,7 @@ discard block |
||
275 | 275 | |
276 | 276 | self::prepare_options( $results ); |
277 | 277 | |
278 | - return stripslashes_deep($results); |
|
278 | + return stripslashes_deep( $results ); |
|
279 | 279 | } |
280 | 280 | |
281 | 281 | /** |
@@ -308,20 +308,20 @@ discard block |
||
308 | 308 | continue; |
309 | 309 | } |
310 | 310 | |
311 | - $fields[ $result->id ] = $result; |
|
312 | - $count++; |
|
311 | + $fields[$result->id] = $result; |
|
312 | + $count ++; |
|
313 | 313 | if ( $limit == 1 ) { |
314 | 314 | $fields = $result; |
315 | 315 | break; |
316 | 316 | } |
317 | 317 | |
318 | - if ( ! empty($limit) && $count >= $limit ) { |
|
318 | + if ( ! empty( $limit ) && $count >= $limit ) { |
|
319 | 319 | break; |
320 | 320 | } |
321 | 321 | |
322 | - unset($result); |
|
322 | + unset( $result ); |
|
323 | 323 | } |
324 | - return stripslashes_deep($fields); |
|
324 | + return stripslashes_deep( $fields ); |
|
325 | 325 | } |
326 | 326 | |
327 | 327 | self::$use_cache = false; |
@@ -330,7 +330,7 @@ discard block |
||
330 | 330 | self::maybe_include_repeating_fields( $inc_sub, $where ); |
331 | 331 | $results = self::getAll( $where, 'field_order', $limit ); |
332 | 332 | self::$use_cache = true; |
333 | - self::include_sub_fields($results, $inc_sub, $type); |
|
333 | + self::include_sub_fields( $results, $inc_sub, $type ); |
|
334 | 334 | |
335 | 335 | return $results; |
336 | 336 | } |
@@ -342,15 +342,15 @@ discard block |
||
342 | 342 | |
343 | 343 | $results = self::get_fields_from_transients( $form_id, array( 'inc_embed' => $inc_embed, 'inc_repeat' => $inc_repeat ) ); |
344 | 344 | if ( ! empty( $results ) ) { |
345 | - if ( empty($limit) ) { |
|
345 | + if ( empty( $limit ) ) { |
|
346 | 346 | return $results; |
347 | 347 | } |
348 | 348 | |
349 | 349 | $fields = array(); |
350 | 350 | $count = 0; |
351 | 351 | foreach ( $results as $result ) { |
352 | - $fields[ $result->id ] = $result; |
|
353 | - if ( ! empty($limit) && $count >= $limit ) { |
|
352 | + $fields[$result->id] = $result; |
|
353 | + if ( ! empty( $limit ) && $count >= $limit ) { |
|
354 | 354 | break; |
355 | 355 | } |
356 | 356 | } |
@@ -368,7 +368,7 @@ discard block |
||
368 | 368 | |
369 | 369 | self::include_sub_fields( $results, $inc_embed, 'all' ); |
370 | 370 | |
371 | - if ( empty($limit) ) { |
|
371 | + if ( empty( $limit ) ) { |
|
372 | 372 | self::set_field_transient( $results, $form_id, 0, array( 'inc_embed' => $inc_embed, 'inc_repeat' => $inc_repeat ) ); |
373 | 373 | } |
374 | 374 | |
@@ -397,22 +397,22 @@ discard block |
||
397 | 397 | $form_fields = $results; |
398 | 398 | $index_offset = 1; |
399 | 399 | foreach ( $form_fields as $k => $field ) { |
400 | - if ( 'form' != $field->type || ! isset($field->field_options['form_select']) ) { |
|
400 | + if ( 'form' != $field->type || ! isset( $field->field_options['form_select'] ) ) { |
|
401 | 401 | continue; |
402 | 402 | } |
403 | 403 | |
404 | 404 | if ( $type == 'all' ) { |
405 | 405 | $sub_fields = self::get_all_for_form( $field->field_options['form_select'] ); |
406 | 406 | } else { |
407 | - $sub_fields = self::get_all_types_in_form($field->form_id, $type); |
|
407 | + $sub_fields = self::get_all_types_in_form( $field->form_id, $type ); |
|
408 | 408 | } |
409 | 409 | |
410 | - if ( ! empty($sub_fields) ) { |
|
410 | + if ( ! empty( $sub_fields ) ) { |
|
411 | 411 | $index = $k + $index_offset; |
412 | 412 | $index_offset += count( $sub_fields ); |
413 | - array_splice($results, $index, 0, $sub_fields); |
|
413 | + array_splice( $results, $index, 0, $sub_fields ); |
|
414 | 414 | } |
415 | - unset($field, $sub_fields); |
|
415 | + unset( $field, $sub_fields ); |
|
416 | 416 | } |
417 | 417 | } |
418 | 418 | |
@@ -420,9 +420,9 @@ discard block |
||
420 | 420 | $cache_key = maybe_serialize( $where ) . $order_by . 'l' . $limit . 'b' . $blog_id; |
421 | 421 | if ( self::$use_cache ) { |
422 | 422 | // make sure old cache doesn't get saved as a transient |
423 | - $results = wp_cache_get($cache_key, 'frm_field'); |
|
423 | + $results = wp_cache_get( $cache_key, 'frm_field' ); |
|
424 | 424 | if ( false !== $results ) { |
425 | - return stripslashes_deep($results); |
|
425 | + return stripslashes_deep( $results ); |
|
426 | 426 | } |
427 | 427 | } |
428 | 428 | |
@@ -447,16 +447,16 @@ discard block |
||
447 | 447 | $order_by = ' ORDER BY ' . $order_by; |
448 | 448 | } |
449 | 449 | |
450 | - $limit = FrmAppHelper::esc_limit($limit); |
|
450 | + $limit = FrmAppHelper::esc_limit( $limit ); |
|
451 | 451 | |
452 | 452 | $query = "SELECT fi.*, fr.name as form_name FROM {$table_name} fi LEFT OUTER JOIN {$form_table_name} fr ON fi.form_id=fr.id"; |
453 | 453 | $query_type = ( $limit == ' LIMIT 1' || $limit == 1 ) ? 'row' : 'results'; |
454 | 454 | |
455 | - if ( is_array($where) ) { |
|
455 | + if ( is_array( $where ) ) { |
|
456 | 456 | $results = FrmDb::get_var( $table_name . ' fi LEFT OUTER JOIN ' . $form_table_name . ' fr ON fi.form_id=fr.id', $where, 'fi.*, fr.name as form_name', array( 'order_by' => $order_by, 'limit' => $limit ), '', $query_type ); |
457 | 457 | } else { |
458 | 458 | // if the query is not an array, then it has already been prepared |
459 | - $query .= FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit; |
|
459 | + $query .= FrmAppHelper::prepend_and_or_where( ' WHERE ', $where ) . $order_by . $limit; |
|
460 | 460 | |
461 | 461 | $function_name = ( $query_type == 'row' ) ? 'get_row' : 'get_results'; |
462 | 462 | $results = $wpdb->$function_name( $query ); |
@@ -479,9 +479,9 @@ discard block |
||
479 | 479 | wp_cache_set( $result->id, $result, 'frm_field' ); |
480 | 480 | wp_cache_set( $result->field_key, $result, 'frm_field' ); |
481 | 481 | |
482 | - $results[ $r_key ]->field_options = maybe_unserialize( $result->field_options ); |
|
483 | - $results[ $r_key ]->options = maybe_unserialize( $result->options ); |
|
484 | - $results[ $r_key ]->default_value = maybe_unserialize( $result->default_value ); |
|
482 | + $results[$r_key]->field_options = maybe_unserialize( $result->field_options ); |
|
483 | + $results[$r_key]->options = maybe_unserialize( $result->options ); |
|
484 | + $results[$r_key]->default_value = maybe_unserialize( $result->default_value ); |
|
485 | 485 | |
486 | 486 | unset( $r_key, $result ); |
487 | 487 | } |
@@ -500,8 +500,8 @@ discard block |
||
500 | 500 | private static function prepare_options( &$results ) { |
501 | 501 | $results->field_options = maybe_unserialize( $results->field_options ); |
502 | 502 | |
503 | - $results->options = maybe_unserialize($results->options); |
|
504 | - $results->default_value = maybe_unserialize($results->default_value); |
|
503 | + $results->options = maybe_unserialize( $results->options ); |
|
504 | + $results->default_value = maybe_unserialize( $results->default_value ); |
|
505 | 505 | } |
506 | 506 | |
507 | 507 | /** |
@@ -528,7 +528,7 @@ discard block |
||
528 | 528 | |
529 | 529 | if ( count( $next_fields ) >= self::$transient_size ) { |
530 | 530 | // if this transient is full, check for another |
531 | - $next++; |
|
531 | + $next ++; |
|
532 | 532 | self::get_next_transient( $fields, $base_name, $next ); |
533 | 533 | } |
534 | 534 | } |
@@ -554,14 +554,14 @@ discard block |
||
554 | 554 | return; |
555 | 555 | } |
556 | 556 | |
557 | - $next++; |
|
557 | + $next ++; |
|
558 | 558 | } |
559 | 559 | } |
560 | 560 | |
561 | 561 | public static function getIds( $where = '', $order_by = '', $limit = '' ) { |
562 | 562 | _deprecated_function( __FUNCTION__, '2.0' ); |
563 | 563 | global $wpdb; |
564 | - if ( ! empty($order_by) && ! strpos($order_by, 'ORDER BY') !== false ) { |
|
564 | + if ( ! empty( $order_by ) && ! strpos( $order_by, 'ORDER BY' ) !== false ) { |
|
565 | 565 | $order_by = ' ORDER BY ' . $order_by; |
566 | 566 | } |
567 | 567 | |
@@ -571,7 +571,7 @@ discard block |
||
571 | 571 | |
572 | 572 | $method = ( $limit == ' LIMIT 1' || $limit == 1 ) ? 'get_var' : 'get_col'; |
573 | 573 | $cache_key = 'getIds_' . maybe_serialize( $where ) . $order_by . $limit; |
574 | - $results = FrmAppHelper::check_cache($cache_key, 'frm_field', $query, $method); |
|
574 | + $results = FrmAppHelper::check_cache( $cache_key, 'frm_field', $query, $method ); |
|
575 | 575 | |
576 | 576 | return $results; |
577 | 577 | } |
@@ -598,9 +598,9 @@ discard block |
||
598 | 598 | } |
599 | 599 | |
600 | 600 | if ( is_array( $field ) ) { |
601 | - return $field['type'] == 'checkbox' || ( $field['type'] == 'data' && isset($field['data_type']) && $field['data_type'] == 'checkbox' ) || self::is_multiple_select( $field ); |
|
601 | + return $field['type'] == 'checkbox' || ( $field['type'] == 'data' && isset( $field['data_type'] ) && $field['data_type'] == 'checkbox' ) || self::is_multiple_select( $field ); |
|
602 | 602 | } else { |
603 | - return $field->type == 'checkbox' || ( $field->type == 'data' && isset( $field->field_options['data_type'] ) && $field->field_options['data_type'] == 'checkbox' ) || self::is_multiple_select($field); |
|
603 | + return $field->type == 'checkbox' || ( $field->type == 'data' && isset( $field->field_options['data_type'] ) && $field->field_options['data_type'] == 'checkbox' ) || self::is_multiple_select( $field ); |
|
604 | 604 | } |
605 | 605 | } |
606 | 606 | |
@@ -612,9 +612,9 @@ discard block |
||
612 | 612 | */ |
613 | 613 | public static function is_multiple_select( $field ) { |
614 | 614 | if ( is_array( $field ) ) { |
615 | - return self::is_option_true( $field, 'multiple' ) && ( ( $field['type'] == 'select' || ( $field['type'] == 'data' && isset( $field['data_type'] ) && $field['data_type'] == 'select') ) ); |
|
615 | + return self::is_option_true( $field, 'multiple' ) && ( ( $field['type'] == 'select' || ( $field['type'] == 'data' && isset( $field['data_type'] ) && $field['data_type'] == 'select' ) ) ); |
|
616 | 616 | } else { |
617 | - return self::is_option_true( $field, 'multiple' ) && ( ( $field->type == 'select' || ( $field->type == 'data' && isset($field->field_options['data_type'] ) && $field->field_options['data_type'] == 'select') ) ); |
|
617 | + return self::is_option_true( $field, 'multiple' ) && ( ( $field->type == 'select' || ( $field->type == 'data' && isset( $field->field_options['data_type'] ) && $field->field_options['data_type'] == 'select' ) ) ); |
|
618 | 618 | } |
619 | 619 | } |
620 | 620 | |
@@ -661,23 +661,23 @@ discard block |
||
661 | 661 | } |
662 | 662 | |
663 | 663 | public static function is_option_true_in_array( $field, $option ) { |
664 | - return isset( $field[ $option ] ) && $field[ $option ]; |
|
664 | + return isset( $field[$option] ) && $field[$option]; |
|
665 | 665 | } |
666 | 666 | |
667 | 667 | public static function is_option_true_in_object( $field, $option ) { |
668 | - return isset( $field->field_options[ $option ] ) && $field->field_options[ $option ]; |
|
668 | + return isset( $field->field_options[$option] ) && $field->field_options[$option]; |
|
669 | 669 | } |
670 | 670 | |
671 | 671 | public static function is_option_empty_in_array( $field, $option ) { |
672 | - return ! isset( $field[ $option ] ) || empty( $field[ $option ] ); |
|
672 | + return ! isset( $field[$option] ) || empty( $field[$option] ); |
|
673 | 673 | } |
674 | 674 | |
675 | 675 | public static function is_option_empty_in_object( $field, $option ) { |
676 | - return ! isset( $field->field_options[ $option ] ) || empty( $field->field_options[ $option ] ); |
|
676 | + return ! isset( $field->field_options[$option] ) || empty( $field->field_options[$option] ); |
|
677 | 677 | } |
678 | 678 | |
679 | 679 | public static function is_option_value_in_object( $field, $option ) { |
680 | - return isset( $field->field_options[ $option ] ) && $field->field_options[ $option ] != ''; |
|
680 | + return isset( $field->field_options[$option] ) && $field->field_options[$option] != ''; |
|
681 | 681 | } |
682 | 682 | |
683 | 683 | /** |
@@ -693,11 +693,11 @@ discard block |
||
693 | 693 | } |
694 | 694 | |
695 | 695 | public static function get_option_in_array( $field, $option ) { |
696 | - return $field[ $option ]; |
|
696 | + return $field[$option]; |
|
697 | 697 | } |
698 | 698 | |
699 | 699 | public static function get_option_in_object( $field, $option ) { |
700 | - return isset( $field->field_options[ $option ] ) ? $field->field_options[ $option ] : ''; |
|
700 | + return isset( $field->field_options[$option] ) ? $field->field_options[$option] : ''; |
|
701 | 701 | } |
702 | 702 | |
703 | 703 | /** |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | public $action_options; // Option array passed to wp_register_sidebar_widget() |
9 | 9 | public $control_options; // Option array passed to wp_register_widget_control() |
10 | 10 | |
11 | - public $form_id; // The ID of the form to evaluate |
|
11 | + public $form_id; // The ID of the form to evaluate |
|
12 | 12 | public $number = false; // Unique ID number of the current instance. |
13 | 13 | public $id = ''; // Unique ID string of the current instance (id_base-number) |
14 | 14 | public $updated = false; // Set true when we update the data after a POST submit - makes sure we don't do it twice. |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | } |
30 | 30 | |
31 | 31 | /** |
32 | - * Echo the settings update form |
|
32 | + * Echo the settings update form |
|
33 | 33 | * |
34 | 34 | * @param array $instance Current settings |
35 | 35 | */ |
@@ -42,15 +42,15 @@ discard block |
||
42 | 42 | * @return array of the default options |
43 | 43 | */ |
44 | 44 | public function get_defaults() { |
45 | - return array(); |
|
45 | + return array(); |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | public function get_switch_fields() { |
49 | - return array(); |
|
49 | + return array(); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | public function migrate_values( $action, $form ) { |
53 | - return $action; |
|
53 | + return $action; |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | // Functions you'll need to call. |
@@ -69,24 +69,24 @@ discard block |
||
69 | 69 | * - height: currently not used but may be needed in the future |
70 | 70 | */ |
71 | 71 | public function __construct( $id_base, $name, $action_options = array(), $control_options = array() ) { |
72 | - if ( ! defined('ABSPATH') ) { |
|
73 | - die('You are not allowed to call this page directly.'); |
|
74 | - } |
|
72 | + if ( ! defined('ABSPATH') ) { |
|
73 | + die('You are not allowed to call this page directly.'); |
|
74 | + } |
|
75 | 75 | |
76 | 76 | $this->id_base = strtolower($id_base); |
77 | 77 | $this->name = $name; |
78 | 78 | $this->option_name = 'frm_' . $this->id_base . '_action'; |
79 | 79 | |
80 | - $default_options = array( |
|
81 | - 'classes' => '', |
|
82 | - 'active' => true, |
|
80 | + $default_options = array( |
|
81 | + 'classes' => '', |
|
82 | + 'active' => true, |
|
83 | 83 | 'event' => array( 'create' ), |
84 | - 'limit' => 1, |
|
85 | - 'force_event' => false, |
|
86 | - 'priority' => 20, |
|
87 | - 'ajax_load' => true, |
|
88 | - 'tooltip' => $name, |
|
89 | - ); |
|
84 | + 'limit' => 1, |
|
85 | + 'force_event' => false, |
|
86 | + 'priority' => 20, |
|
87 | + 'ajax_load' => true, |
|
88 | + 'tooltip' => $name, |
|
89 | + ); |
|
90 | 90 | |
91 | 91 | $action_options = apply_filters( 'frm_' . $id_base . '_action_options', $action_options ); |
92 | 92 | $this->action_options = wp_parse_args( $action_options, $default_options ); |
@@ -135,132 +135,132 @@ discard block |
||
135 | 135 | } |
136 | 136 | |
137 | 137 | public function prepare_new( $form_id = false ) { |
138 | - if ( $form_id ) { |
|
139 | - $this->form_id = $form_id; |
|
140 | - } |
|
141 | - |
|
142 | - $post_content = array(); |
|
143 | - $default_values = $this->get_global_defaults(); |
|
144 | - |
|
145 | - // fill default values |
|
146 | - $post_content = wp_parse_args( $post_content, $default_values); |
|
147 | - |
|
148 | - if ( ! isset($post_content['event']) && ! $this->action_options['force_event'] ) { |
|
149 | - $post_content['event'] = array( reset($this->action_options['event']) ); |
|
150 | - } |
|
151 | - |
|
152 | - $form_action = array( |
|
153 | - 'post_title' => $this->name, |
|
154 | - 'post_content' => $post_content, |
|
155 | - 'post_excerpt' => $this->id_base, |
|
156 | - 'ID' => '', |
|
157 | - 'post_status' => 'publish', |
|
158 | - 'post_type' => FrmFormActionsController::$action_post_type, |
|
138 | + if ( $form_id ) { |
|
139 | + $this->form_id = $form_id; |
|
140 | + } |
|
141 | + |
|
142 | + $post_content = array(); |
|
143 | + $default_values = $this->get_global_defaults(); |
|
144 | + |
|
145 | + // fill default values |
|
146 | + $post_content = wp_parse_args( $post_content, $default_values); |
|
147 | + |
|
148 | + if ( ! isset($post_content['event']) && ! $this->action_options['force_event'] ) { |
|
149 | + $post_content['event'] = array( reset($this->action_options['event']) ); |
|
150 | + } |
|
151 | + |
|
152 | + $form_action = array( |
|
153 | + 'post_title' => $this->name, |
|
154 | + 'post_content' => $post_content, |
|
155 | + 'post_excerpt' => $this->id_base, |
|
156 | + 'ID' => '', |
|
157 | + 'post_status' => 'publish', |
|
158 | + 'post_type' => FrmFormActionsController::$action_post_type, |
|
159 | 159 | 'post_name' => $this->form_id . '_' . $this->id_base . '_' . $this->number, |
160 | - 'menu_order' => $this->form_id, |
|
161 | - ); |
|
162 | - unset($post_content); |
|
160 | + 'menu_order' => $this->form_id, |
|
161 | + ); |
|
162 | + unset($post_content); |
|
163 | 163 | |
164 | - return (object) $form_action; |
|
165 | - } |
|
164 | + return (object) $form_action; |
|
165 | + } |
|
166 | 166 | |
167 | 167 | public function create( $form_id ) { |
168 | - $this->form_id = $form_id; |
|
168 | + $this->form_id = $form_id; |
|
169 | 169 | |
170 | - $action = $this->prepare_new(); |
|
170 | + $action = $this->prepare_new(); |
|
171 | 171 | |
172 | - return $this->save_settings($action); |
|
173 | - } |
|
172 | + return $this->save_settings($action); |
|
173 | + } |
|
174 | 174 | |
175 | 175 | public function duplicate_form_actions( $form_id, $old_id ) { |
176 | - if ( $form_id == $old_id ) { |
|
177 | - // don't duplicate the actions if this is a template getting updated |
|
178 | - return; |
|
179 | - } |
|
180 | - |
|
181 | - $this->form_id = $old_id; |
|
182 | - $actions = $this->get_all( $old_id ); |
|
183 | - |
|
184 | - $this->form_id = $form_id; |
|
185 | - foreach ( $actions as $action ) { |
|
186 | - $this->duplicate_one($action, $form_id); |
|
187 | - unset($action); |
|
188 | - } |
|
189 | - } |
|
190 | - |
|
191 | - /* Check if imported action should be created or updated |
|
176 | + if ( $form_id == $old_id ) { |
|
177 | + // don't duplicate the actions if this is a template getting updated |
|
178 | + return; |
|
179 | + } |
|
180 | + |
|
181 | + $this->form_id = $old_id; |
|
182 | + $actions = $this->get_all( $old_id ); |
|
183 | + |
|
184 | + $this->form_id = $form_id; |
|
185 | + foreach ( $actions as $action ) { |
|
186 | + $this->duplicate_one($action, $form_id); |
|
187 | + unset($action); |
|
188 | + } |
|
189 | + } |
|
190 | + |
|
191 | + /* Check if imported action should be created or updated |
|
192 | 192 | * |
193 | 193 | * Since 2.0 |
194 | 194 | * |
195 | 195 | * @param array $action |
196 | 196 | * @return integer $post_id |
197 | 197 | */ |
198 | - public function maybe_create_action( $action, $forms ) { |
|
198 | + public function maybe_create_action( $action, $forms ) { |
|
199 | 199 | if ( isset( $action['ID'] ) && is_numeric( $action['ID'] ) && $forms[ $action['menu_order'] ] == 'updated' ) { |
200 | - // Update action only |
|
201 | - $action['post_content'] = FrmAppHelper::maybe_json_decode( $action['post_content'] ); |
|
202 | - $post_id = $this->save_settings( $action ); |
|
203 | - } else { |
|
204 | - // Create action |
|
205 | - $action['post_content'] = FrmAppHelper::maybe_json_decode($action['post_content']); |
|
206 | - $post_id = $this->duplicate_one( (object) $action, $action['menu_order']); |
|
207 | - } |
|
208 | - return $post_id; |
|
209 | - } |
|
200 | + // Update action only |
|
201 | + $action['post_content'] = FrmAppHelper::maybe_json_decode( $action['post_content'] ); |
|
202 | + $post_id = $this->save_settings( $action ); |
|
203 | + } else { |
|
204 | + // Create action |
|
205 | + $action['post_content'] = FrmAppHelper::maybe_json_decode($action['post_content']); |
|
206 | + $post_id = $this->duplicate_one( (object) $action, $action['menu_order']); |
|
207 | + } |
|
208 | + return $post_id; |
|
209 | + } |
|
210 | 210 | |
211 | 211 | public function duplicate_one( $action, $form_id ) { |
212 | - global $frm_duplicate_ids; |
|
212 | + global $frm_duplicate_ids; |
|
213 | 213 | |
214 | - $action->menu_order = $form_id; |
|
215 | - $switch = $this->get_global_switch_fields(); |
|
216 | - foreach ( (array) $action->post_content as $key => $val ) { |
|
214 | + $action->menu_order = $form_id; |
|
215 | + $switch = $this->get_global_switch_fields(); |
|
216 | + foreach ( (array) $action->post_content as $key => $val ) { |
|
217 | 217 | if ( is_numeric( $val ) && isset( $frm_duplicate_ids[ $val ] ) ) { |
218 | 218 | $action->post_content[ $key ] = $frm_duplicate_ids[ $val ]; |
219 | - } else if ( ! is_array( $val ) ) { |
|
219 | + } else if ( ! is_array( $val ) ) { |
|
220 | 220 | $action->post_content[ $key ] = FrmFieldsHelper::switch_field_ids( $val ); |
221 | 221 | } else if ( isset( $switch[ $key ] ) && is_array( $switch[ $key ] ) ) { |
222 | - // loop through each value if empty |
|
222 | + // loop through each value if empty |
|
223 | 223 | if ( empty( $switch[ $key ] ) ) { |
224 | 224 | $switch[ $key ] = array_keys( $val ); |
225 | 225 | } |
226 | 226 | |
227 | 227 | foreach ( $switch[ $key ] as $subkey ) { |
228 | 228 | $action->post_content[ $key ] = $this->duplicate_array_walk( $action->post_content[ $key ], $subkey, $val ); |
229 | - } |
|
230 | - } |
|
229 | + } |
|
230 | + } |
|
231 | 231 | |
232 | - unset($key, $val); |
|
233 | - } |
|
234 | - unset($action->ID); |
|
232 | + unset($key, $val); |
|
233 | + } |
|
234 | + unset($action->ID); |
|
235 | 235 | |
236 | - return $this->save_settings($action); |
|
237 | - } |
|
236 | + return $this->save_settings($action); |
|
237 | + } |
|
238 | 238 | |
239 | 239 | private function duplicate_array_walk( $action, $subkey, $val ) { |
240 | - global $frm_duplicate_ids; |
|
240 | + global $frm_duplicate_ids; |
|
241 | 241 | |
242 | - if ( is_array($subkey) ) { |
|
243 | - foreach ( $subkey as $subkey2 ) { |
|
244 | - foreach ( (array) $val as $ck => $cv ) { |
|
245 | - if ( is_array($cv) ) { |
|
242 | + if ( is_array($subkey) ) { |
|
243 | + foreach ( $subkey as $subkey2 ) { |
|
244 | + foreach ( (array) $val as $ck => $cv ) { |
|
245 | + if ( is_array($cv) ) { |
|
246 | 246 | $action[ $ck ] = $this->duplicate_array_walk( $action[ $ck ], $subkey2, $cv ); |
247 | 247 | } else if ( isset( $cv[ $subkey ] ) && is_numeric( $cv[ $subkey ] ) && isset( $frm_duplicate_ids[ $cv[ $subkey ] ] ) ) { |
248 | 248 | $action[ $ck ][ $subkey ] = $frm_duplicate_ids[ $cv[ $subkey ] ]; |
249 | - } |
|
250 | - } |
|
251 | - } |
|
252 | - } else { |
|
253 | - foreach ( (array) $val as $ck => $cv ) { |
|
254 | - if ( is_array($cv) ) { |
|
249 | + } |
|
250 | + } |
|
251 | + } |
|
252 | + } else { |
|
253 | + foreach ( (array) $val as $ck => $cv ) { |
|
254 | + if ( is_array($cv) ) { |
|
255 | 255 | $action[ $ck ] = $this->duplicate_array_walk( $action[ $ck ], $subkey, $cv ); |
256 | 256 | } else if ( $ck == $subkey && isset( $frm_duplicate_ids[ $cv ] ) ) { |
257 | 257 | $action[ $ck ] = $frm_duplicate_ids[ $cv ]; |
258 | - } |
|
259 | - } |
|
260 | - } |
|
258 | + } |
|
259 | + } |
|
260 | + } |
|
261 | 261 | |
262 | - return $action; |
|
263 | - } |
|
262 | + return $action; |
|
263 | + } |
|
264 | 264 | |
265 | 265 | /** |
266 | 266 | * Deal with changed settings. |
@@ -269,7 +269,7 @@ discard block |
||
269 | 269 | * |
270 | 270 | */ |
271 | 271 | public function update_callback( $form_id ) { |
272 | - $this->form_id = $form_id; |
|
272 | + $this->form_id = $form_id; |
|
273 | 273 | |
274 | 274 | $all_instances = $this->get_settings(); |
275 | 275 | |
@@ -284,25 +284,25 @@ discard block |
||
284 | 284 | return; |
285 | 285 | } |
286 | 286 | |
287 | - $action_ids = array(); |
|
287 | + $action_ids = array(); |
|
288 | 288 | |
289 | 289 | foreach ( $settings as $number => $new_instance ) { |
290 | 290 | $this->_set($number); |
291 | 291 | |
292 | 292 | if ( ! isset($new_instance['post_title']) ) { |
293 | - // settings were never opened, so don't update |
|
294 | - $action_ids[] = $new_instance['ID']; |
|
295 | - $this->updated = true; |
|
296 | - continue; |
|
293 | + // settings were never opened, so don't update |
|
294 | + $action_ids[] = $new_instance['ID']; |
|
295 | + $this->updated = true; |
|
296 | + continue; |
|
297 | 297 | } |
298 | 298 | |
299 | 299 | $old_instance = isset( $all_instances[ $number ] ) ? $all_instances[ $number ] : array(); |
300 | 300 | |
301 | 301 | $new_instance['post_type'] = FrmFormActionsController::$action_post_type; |
302 | 302 | $new_instance['post_name'] = $this->form_id . '_' . $this->id_base . '_' . $this->number; |
303 | - $new_instance['menu_order'] = $this->form_id; |
|
304 | - $new_instance['post_status'] = 'publish'; |
|
305 | - $new_instance['post_date'] = isset( $old_instance->post_date ) ? $old_instance->post_date : ''; |
|
303 | + $new_instance['menu_order'] = $this->form_id; |
|
304 | + $new_instance['post_status'] = 'publish'; |
|
305 | + $new_instance['post_date'] = isset( $old_instance->post_date ) ? $old_instance->post_date : ''; |
|
306 | 306 | |
307 | 307 | $instance = $this->update( $new_instance, $old_instance ); |
308 | 308 | |
@@ -328,9 +328,9 @@ discard block |
||
328 | 328 | $all_instances[ $number ] = $instance; |
329 | 329 | } |
330 | 330 | |
331 | - $action_ids[] = $this->save_settings($instance); |
|
331 | + $action_ids[] = $this->save_settings($instance); |
|
332 | 332 | |
333 | - $this->updated = true; |
|
333 | + $this->updated = true; |
|
334 | 334 | } |
335 | 335 | |
336 | 336 | return $action_ids; |
@@ -342,100 +342,100 @@ discard block |
||
342 | 342 | } |
343 | 343 | |
344 | 344 | public function get_single_action( $id ) { |
345 | - $action = get_post($id); |
|
345 | + $action = get_post($id); |
|
346 | 346 | if ( $action ) { |
347 | 347 | $action = $this->prepare_action( $action ); |
348 | 348 | $this->_set( $id ); |
349 | 349 | } |
350 | - return $action; |
|
350 | + return $action; |
|
351 | 351 | } |
352 | 352 | |
353 | 353 | public function get_one( $form_id ) { |
354 | - return $this->get_all($form_id, 1); |
|
354 | + return $this->get_all($form_id, 1); |
|
355 | 355 | } |
356 | 356 | |
357 | - public static function get_action_for_form( $form_id, $type = 'all', $limit = 99 ) { |
|
358 | - $action_controls = FrmFormActionsController::get_form_actions( $type ); |
|
359 | - if ( empty($action_controls) ) { |
|
360 | - // don't continue if there are no available actions |
|
361 | - return array(); |
|
362 | - } |
|
357 | + public static function get_action_for_form( $form_id, $type = 'all', $limit = 99 ) { |
|
358 | + $action_controls = FrmFormActionsController::get_form_actions( $type ); |
|
359 | + if ( empty($action_controls) ) { |
|
360 | + // don't continue if there are no available actions |
|
361 | + return array(); |
|
362 | + } |
|
363 | 363 | |
364 | - if ( 'all' != $type ) { |
|
365 | - return $action_controls->get_all( $form_id, $limit ); |
|
366 | - } |
|
364 | + if ( 'all' != $type ) { |
|
365 | + return $action_controls->get_all( $form_id, $limit ); |
|
366 | + } |
|
367 | 367 | |
368 | 368 | $args = self::action_args( $form_id, $limit ); |
369 | 369 | $actions = FrmAppHelper::check_cache( serialize( $args ), 'frm_actions', $args, 'get_posts' ); |
370 | 370 | |
371 | - if ( ! $actions ) { |
|
372 | - return array(); |
|
373 | - } |
|
371 | + if ( ! $actions ) { |
|
372 | + return array(); |
|
373 | + } |
|
374 | 374 | |
375 | - $settings = array(); |
|
376 | - foreach ( $actions as $action ) { |
|
375 | + $settings = array(); |
|
376 | + foreach ( $actions as $action ) { |
|
377 | 377 | // some plugins/themes are formatting the post_excerpt |
378 | 378 | $action->post_excerpt = sanitize_title( $action->post_excerpt ); |
379 | 379 | |
380 | 380 | if ( ! isset( $action_controls[ $action->post_excerpt ] ) ) { |
381 | - continue; |
|
382 | - } |
|
381 | + continue; |
|
382 | + } |
|
383 | 383 | |
384 | - $action = $action_controls[ $action->post_excerpt ]->prepare_action( $action ); |
|
384 | + $action = $action_controls[ $action->post_excerpt ]->prepare_action( $action ); |
|
385 | 385 | $settings[ $action->ID ] = $action; |
386 | 386 | |
387 | 387 | if ( count( $settings ) >= $limit ) { |
388 | 388 | break; |
389 | 389 | } |
390 | - } |
|
390 | + } |
|
391 | 391 | |
392 | - if ( 1 === $limit ) { |
|
393 | - $settings = reset($settings); |
|
394 | - } |
|
392 | + if ( 1 === $limit ) { |
|
393 | + $settings = reset($settings); |
|
394 | + } |
|
395 | 395 | |
396 | - return $settings; |
|
397 | - } |
|
396 | + return $settings; |
|
397 | + } |
|
398 | 398 | |
399 | 399 | public function get_all( $form_id = false, $limit = 99 ) { |
400 | - if ( $form_id ) { |
|
401 | - $this->form_id = $form_id; |
|
402 | - } |
|
400 | + if ( $form_id ) { |
|
401 | + $this->form_id = $form_id; |
|
402 | + } |
|
403 | 403 | |
404 | - $type = $this->id_base; |
|
404 | + $type = $this->id_base; |
|
405 | 405 | |
406 | - global $frm_vars; |
|
407 | - $frm_vars['action_type'] = $type; |
|
406 | + global $frm_vars; |
|
407 | + $frm_vars['action_type'] = $type; |
|
408 | 408 | |
409 | - add_filter( 'posts_where' , 'FrmFormActionsController::limit_by_type' ); |
|
409 | + add_filter( 'posts_where' , 'FrmFormActionsController::limit_by_type' ); |
|
410 | 410 | $query = self::action_args( $form_id, $limit ); |
411 | - $query['post_status'] = 'any'; |
|
412 | - $query['suppress_filters'] = false; |
|
411 | + $query['post_status'] = 'any'; |
|
412 | + $query['suppress_filters'] = false; |
|
413 | 413 | |
414 | 414 | $actions = FrmAppHelper::check_cache( serialize( $query ) . '_type_' . $type, 'frm_actions', $query, 'get_posts' ); |
415 | - unset($query); |
|
415 | + unset($query); |
|
416 | 416 | |
417 | - remove_filter( 'posts_where' , 'FrmFormActionsController::limit_by_type' ); |
|
417 | + remove_filter( 'posts_where' , 'FrmFormActionsController::limit_by_type' ); |
|
418 | 418 | |
419 | - if ( empty($actions) ) { |
|
420 | - return array(); |
|
421 | - } |
|
419 | + if ( empty($actions) ) { |
|
420 | + return array(); |
|
421 | + } |
|
422 | 422 | |
423 | - $settings = array(); |
|
424 | - foreach ( $actions as $action ) { |
|
425 | - if ( count($settings) >= $limit ) { |
|
426 | - continue; |
|
427 | - } |
|
423 | + $settings = array(); |
|
424 | + foreach ( $actions as $action ) { |
|
425 | + if ( count($settings) >= $limit ) { |
|
426 | + continue; |
|
427 | + } |
|
428 | 428 | |
429 | - $action = $this->prepare_action($action); |
|
429 | + $action = $this->prepare_action($action); |
|
430 | 430 | |
431 | 431 | $settings[ $action->ID ] = $action; |
432 | - } |
|
432 | + } |
|
433 | 433 | |
434 | - if ( 1 === $limit ) { |
|
435 | - $settings = reset($settings); |
|
436 | - } |
|
434 | + if ( 1 === $limit ) { |
|
435 | + $settings = reset($settings); |
|
436 | + } |
|
437 | 437 | |
438 | - return $settings; |
|
438 | + return $settings; |
|
439 | 439 | } |
440 | 440 | |
441 | 441 | public static function action_args( $form_id = 0, $limit = 99 ) { |
@@ -458,45 +458,45 @@ discard block |
||
458 | 458 | $action->post_content = (array) FrmAppHelper::maybe_json_decode($action->post_content); |
459 | 459 | $action->post_excerpt = sanitize_title( $action->post_excerpt ); |
460 | 460 | |
461 | - $default_values = $this->get_global_defaults(); |
|
461 | + $default_values = $this->get_global_defaults(); |
|
462 | 462 | |
463 | - // fill default values |
|
464 | - $action->post_content += $default_values; |
|
463 | + // fill default values |
|
464 | + $action->post_content += $default_values; |
|
465 | 465 | |
466 | - foreach ( $default_values as $k => $vals ) { |
|
467 | - if ( is_array($vals) && ! empty($vals) ) { |
|
466 | + foreach ( $default_values as $k => $vals ) { |
|
467 | + if ( is_array($vals) && ! empty($vals) ) { |
|
468 | 468 | if ( 'event' == $k && ! $this->action_options['force_event'] && ! empty( $action->post_content[ $k ] ) ) { |
469 | - continue; |
|
470 | - } |
|
469 | + continue; |
|
470 | + } |
|
471 | 471 | $action->post_content[ $k ] = wp_parse_args( $action->post_content[ $k ], $vals ); |
472 | - } |
|
473 | - } |
|
472 | + } |
|
473 | + } |
|
474 | 474 | |
475 | - if ( ! is_array($action->post_content['event']) ) { |
|
476 | - $action->post_content['event'] = explode(',', $action->post_content['event']); |
|
477 | - } |
|
475 | + if ( ! is_array($action->post_content['event']) ) { |
|
476 | + $action->post_content['event'] = explode(',', $action->post_content['event']); |
|
477 | + } |
|
478 | 478 | |
479 | - return $action; |
|
479 | + return $action; |
|
480 | 480 | } |
481 | 481 | |
482 | 482 | public function destroy( $form_id = false, $type = 'default' ) { |
483 | - global $wpdb; |
|
483 | + global $wpdb; |
|
484 | 484 | |
485 | - $this->form_id = $form_id; |
|
485 | + $this->form_id = $form_id; |
|
486 | 486 | |
487 | - $query = array( 'post_type' => FrmFormActionsController::$action_post_type ); |
|
488 | - if ( $form_id ) { |
|
489 | - $query['menu_order'] = $form_id; |
|
490 | - } |
|
491 | - if ( 'all' != $type ) { |
|
492 | - $query['post_excerpt'] = $this->id_base; |
|
493 | - } |
|
487 | + $query = array( 'post_type' => FrmFormActionsController::$action_post_type ); |
|
488 | + if ( $form_id ) { |
|
489 | + $query['menu_order'] = $form_id; |
|
490 | + } |
|
491 | + if ( 'all' != $type ) { |
|
492 | + $query['post_excerpt'] = $this->id_base; |
|
493 | + } |
|
494 | 494 | |
495 | - $post_ids = FrmDb::get_col( $wpdb->posts, $query, 'ID' ); |
|
495 | + $post_ids = FrmDb::get_col( $wpdb->posts, $query, 'ID' ); |
|
496 | 496 | |
497 | - foreach ( $post_ids as $id ) { |
|
498 | - wp_delete_post($id); |
|
499 | - } |
|
497 | + foreach ( $post_ids as $id ) { |
|
498 | + wp_delete_post($id); |
|
499 | + } |
|
500 | 500 | self::clear_cache(); |
501 | 501 | } |
502 | 502 | |
@@ -514,69 +514,69 @@ discard block |
||
514 | 514 | } |
515 | 515 | |
516 | 516 | public function get_global_defaults() { |
517 | - $defaults = $this->get_defaults(); |
|
517 | + $defaults = $this->get_defaults(); |
|
518 | 518 | |
519 | - if ( ! isset($defaults['event']) ) { |
|
519 | + if ( ! isset($defaults['event']) ) { |
|
520 | 520 | $defaults['event'] = array( 'create' ); |
521 | - } |
|
521 | + } |
|
522 | 522 | |
523 | - if ( ! isset($defaults['conditions']) ) { |
|
524 | - $defaults['conditions'] = array( |
|
525 | - 'send_stop' => '', |
|
526 | - 'any_all' => '', |
|
527 | - ); |
|
528 | - } |
|
523 | + if ( ! isset($defaults['conditions']) ) { |
|
524 | + $defaults['conditions'] = array( |
|
525 | + 'send_stop' => '', |
|
526 | + 'any_all' => '', |
|
527 | + ); |
|
528 | + } |
|
529 | 529 | |
530 | - return $defaults; |
|
530 | + return $defaults; |
|
531 | 531 | } |
532 | 532 | |
533 | 533 | public function get_global_switch_fields() { |
534 | - $switch = $this->get_switch_fields(); |
|
534 | + $switch = $this->get_switch_fields(); |
|
535 | 535 | $switch['conditions'] = array( 'hide_field' ); |
536 | - return $switch; |
|
536 | + return $switch; |
|
537 | 537 | } |
538 | 538 | |
539 | 539 | /** |
540 | 540 | * Migrate settings from form->options into new action. |
541 | 541 | */ |
542 | 542 | public function migrate_to_2( $form, $update = 'update' ) { |
543 | - $action = $this->prepare_new($form->id); |
|
544 | - $form->options = maybe_unserialize($form->options); |
|
543 | + $action = $this->prepare_new($form->id); |
|
544 | + $form->options = maybe_unserialize($form->options); |
|
545 | 545 | |
546 | - // fill with existing options |
|
547 | - foreach ( $action->post_content as $name => $val ) { |
|
546 | + // fill with existing options |
|
547 | + foreach ( $action->post_content as $name => $val ) { |
|
548 | 548 | if ( isset( $form->options[ $name ] ) ) { |
549 | 549 | $action->post_content[ $name ] = $form->options[ $name ]; |
550 | 550 | unset( $form->options[ $name ] ); |
551 | - } |
|
552 | - } |
|
551 | + } |
|
552 | + } |
|
553 | 553 | |
554 | - $action = $this->migrate_values($action, $form); |
|
554 | + $action = $this->migrate_values($action, $form); |
|
555 | 555 | |
556 | - // check if action already exists |
|
557 | - $post_id = get_posts( array( |
|
558 | - 'name' => $action->post_name, |
|
559 | - 'post_type' => FrmFormActionsController::$action_post_type, |
|
560 | - 'post_status' => $action->post_status, |
|
561 | - 'numberposts' => 1, |
|
562 | - ) ); |
|
556 | + // check if action already exists |
|
557 | + $post_id = get_posts( array( |
|
558 | + 'name' => $action->post_name, |
|
559 | + 'post_type' => FrmFormActionsController::$action_post_type, |
|
560 | + 'post_status' => $action->post_status, |
|
561 | + 'numberposts' => 1, |
|
562 | + ) ); |
|
563 | 563 | |
564 | - if ( empty($post_id) ) { |
|
565 | - // create action now |
|
566 | - $post_id = $this->save_settings($action); |
|
567 | - } |
|
564 | + if ( empty($post_id) ) { |
|
565 | + // create action now |
|
566 | + $post_id = $this->save_settings($action); |
|
567 | + } |
|
568 | 568 | |
569 | - if ( $post_id && 'update' == $update ) { |
|
570 | - global $wpdb; |
|
571 | - $form->options = maybe_serialize($form->options); |
|
569 | + if ( $post_id && 'update' == $update ) { |
|
570 | + global $wpdb; |
|
571 | + $form->options = maybe_serialize($form->options); |
|
572 | 572 | |
573 | - // update form options |
|
573 | + // update form options |
|
574 | 574 | $wpdb->update( $wpdb->prefix . 'frm_forms', array( 'options' => $form->options ), array( 'id' => $form->id ) ); |
575 | - wp_cache_delete( $form->id, 'frm_form'); |
|
576 | - } |
|
575 | + wp_cache_delete( $form->id, 'frm_form'); |
|
576 | + } |
|
577 | 577 | |
578 | - return $post_id; |
|
579 | - } |
|
578 | + return $post_id; |
|
579 | + } |
|
580 | 580 | |
581 | 581 | public static function action_conditions_met( $action, $entry ) { |
582 | 582 | $notification = $action->post_content; |
@@ -2,16 +2,16 @@ discard block |
||
2 | 2 | |
3 | 3 | class FrmFormAction { |
4 | 4 | |
5 | - public $id_base; // Root id for all actions of this type. |
|
6 | - public $name; // Name for this action type. |
|
5 | + public $id_base; // Root id for all actions of this type. |
|
6 | + public $name; // Name for this action type. |
|
7 | 7 | public $option_name; |
8 | - public $action_options; // Option array passed to wp_register_sidebar_widget() |
|
9 | - public $control_options; // Option array passed to wp_register_widget_control() |
|
8 | + public $action_options; // Option array passed to wp_register_sidebar_widget() |
|
9 | + public $control_options; // Option array passed to wp_register_widget_control() |
|
10 | 10 | |
11 | - public $form_id; // The ID of the form to evaluate |
|
12 | - public $number = false; // Unique ID number of the current instance. |
|
13 | - public $id = ''; // Unique ID string of the current instance (id_base-number) |
|
14 | - public $updated = false; // Set true when we update the data after a POST submit - makes sure we don't do it twice. |
|
11 | + public $form_id; // The ID of the form to evaluate |
|
12 | + public $number = false; // Unique ID number of the current instance. |
|
13 | + public $id = ''; // Unique ID string of the current instance (id_base-number) |
|
14 | + public $updated = false; // Set true when we update the data after a POST submit - makes sure we don't do it twice. |
|
15 | 15 | |
16 | 16 | // Member functions that you must over-ride. |
17 | 17 | |
@@ -69,11 +69,11 @@ discard block |
||
69 | 69 | * - height: currently not used but may be needed in the future |
70 | 70 | */ |
71 | 71 | public function __construct( $id_base, $name, $action_options = array(), $control_options = array() ) { |
72 | - if ( ! defined('ABSPATH') ) { |
|
73 | - die('You are not allowed to call this page directly.'); |
|
72 | + if ( ! defined( 'ABSPATH' ) ) { |
|
73 | + die( 'You are not allowed to call this page directly.' ); |
|
74 | 74 | } |
75 | 75 | |
76 | - $this->id_base = strtolower($id_base); |
|
76 | + $this->id_base = strtolower( $id_base ); |
|
77 | 77 | $this->name = $name; |
78 | 78 | $this->option_name = 'frm_' . $this->id_base . '_action'; |
79 | 79 | |
@@ -143,10 +143,10 @@ discard block |
||
143 | 143 | $default_values = $this->get_global_defaults(); |
144 | 144 | |
145 | 145 | // fill default values |
146 | - $post_content = wp_parse_args( $post_content, $default_values); |
|
146 | + $post_content = wp_parse_args( $post_content, $default_values ); |
|
147 | 147 | |
148 | - if ( ! isset($post_content['event']) && ! $this->action_options['force_event'] ) { |
|
149 | - $post_content['event'] = array( reset($this->action_options['event']) ); |
|
148 | + if ( ! isset( $post_content['event'] ) && ! $this->action_options['force_event'] ) { |
|
149 | + $post_content['event'] = array( reset( $this->action_options['event'] ) ); |
|
150 | 150 | } |
151 | 151 | |
152 | 152 | $form_action = array( |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | 'post_name' => $this->form_id . '_' . $this->id_base . '_' . $this->number, |
160 | 160 | 'menu_order' => $this->form_id, |
161 | 161 | ); |
162 | - unset($post_content); |
|
162 | + unset( $post_content ); |
|
163 | 163 | |
164 | 164 | return (object) $form_action; |
165 | 165 | } |
@@ -169,7 +169,7 @@ discard block |
||
169 | 169 | |
170 | 170 | $action = $this->prepare_new(); |
171 | 171 | |
172 | - return $this->save_settings($action); |
|
172 | + return $this->save_settings( $action ); |
|
173 | 173 | } |
174 | 174 | |
175 | 175 | public function duplicate_form_actions( $form_id, $old_id ) { |
@@ -183,8 +183,8 @@ discard block |
||
183 | 183 | |
184 | 184 | $this->form_id = $form_id; |
185 | 185 | foreach ( $actions as $action ) { |
186 | - $this->duplicate_one($action, $form_id); |
|
187 | - unset($action); |
|
186 | + $this->duplicate_one( $action, $form_id ); |
|
187 | + unset( $action ); |
|
188 | 188 | } |
189 | 189 | } |
190 | 190 | |
@@ -196,14 +196,14 @@ discard block |
||
196 | 196 | * @return integer $post_id |
197 | 197 | */ |
198 | 198 | public function maybe_create_action( $action, $forms ) { |
199 | - if ( isset( $action['ID'] ) && is_numeric( $action['ID'] ) && $forms[ $action['menu_order'] ] == 'updated' ) { |
|
199 | + if ( isset( $action['ID'] ) && is_numeric( $action['ID'] ) && $forms[$action['menu_order']] == 'updated' ) { |
|
200 | 200 | // Update action only |
201 | 201 | $action['post_content'] = FrmAppHelper::maybe_json_decode( $action['post_content'] ); |
202 | 202 | $post_id = $this->save_settings( $action ); |
203 | 203 | } else { |
204 | 204 | // Create action |
205 | - $action['post_content'] = FrmAppHelper::maybe_json_decode($action['post_content']); |
|
206 | - $post_id = $this->duplicate_one( (object) $action, $action['menu_order']); |
|
205 | + $action['post_content'] = FrmAppHelper::maybe_json_decode( $action['post_content'] ); |
|
206 | + $post_id = $this->duplicate_one( (object) $action, $action['menu_order'] ); |
|
207 | 207 | } |
208 | 208 | return $post_id; |
209 | 209 | } |
@@ -214,47 +214,47 @@ discard block |
||
214 | 214 | $action->menu_order = $form_id; |
215 | 215 | $switch = $this->get_global_switch_fields(); |
216 | 216 | foreach ( (array) $action->post_content as $key => $val ) { |
217 | - if ( is_numeric( $val ) && isset( $frm_duplicate_ids[ $val ] ) ) { |
|
218 | - $action->post_content[ $key ] = $frm_duplicate_ids[ $val ]; |
|
217 | + if ( is_numeric( $val ) && isset( $frm_duplicate_ids[$val] ) ) { |
|
218 | + $action->post_content[$key] = $frm_duplicate_ids[$val]; |
|
219 | 219 | } else if ( ! is_array( $val ) ) { |
220 | - $action->post_content[ $key ] = FrmFieldsHelper::switch_field_ids( $val ); |
|
221 | - } else if ( isset( $switch[ $key ] ) && is_array( $switch[ $key ] ) ) { |
|
220 | + $action->post_content[$key] = FrmFieldsHelper::switch_field_ids( $val ); |
|
221 | + } else if ( isset( $switch[$key] ) && is_array( $switch[$key] ) ) { |
|
222 | 222 | // loop through each value if empty |
223 | - if ( empty( $switch[ $key ] ) ) { |
|
224 | - $switch[ $key ] = array_keys( $val ); |
|
223 | + if ( empty( $switch[$key] ) ) { |
|
224 | + $switch[$key] = array_keys( $val ); |
|
225 | 225 | } |
226 | 226 | |
227 | - foreach ( $switch[ $key ] as $subkey ) { |
|
228 | - $action->post_content[ $key ] = $this->duplicate_array_walk( $action->post_content[ $key ], $subkey, $val ); |
|
227 | + foreach ( $switch[$key] as $subkey ) { |
|
228 | + $action->post_content[$key] = $this->duplicate_array_walk( $action->post_content[$key], $subkey, $val ); |
|
229 | 229 | } |
230 | 230 | } |
231 | 231 | |
232 | - unset($key, $val); |
|
232 | + unset( $key, $val ); |
|
233 | 233 | } |
234 | - unset($action->ID); |
|
234 | + unset( $action->ID ); |
|
235 | 235 | |
236 | - return $this->save_settings($action); |
|
236 | + return $this->save_settings( $action ); |
|
237 | 237 | } |
238 | 238 | |
239 | 239 | private function duplicate_array_walk( $action, $subkey, $val ) { |
240 | 240 | global $frm_duplicate_ids; |
241 | 241 | |
242 | - if ( is_array($subkey) ) { |
|
242 | + if ( is_array( $subkey ) ) { |
|
243 | 243 | foreach ( $subkey as $subkey2 ) { |
244 | 244 | foreach ( (array) $val as $ck => $cv ) { |
245 | - if ( is_array($cv) ) { |
|
246 | - $action[ $ck ] = $this->duplicate_array_walk( $action[ $ck ], $subkey2, $cv ); |
|
247 | - } else if ( isset( $cv[ $subkey ] ) && is_numeric( $cv[ $subkey ] ) && isset( $frm_duplicate_ids[ $cv[ $subkey ] ] ) ) { |
|
248 | - $action[ $ck ][ $subkey ] = $frm_duplicate_ids[ $cv[ $subkey ] ]; |
|
245 | + if ( is_array( $cv ) ) { |
|
246 | + $action[$ck] = $this->duplicate_array_walk( $action[$ck], $subkey2, $cv ); |
|
247 | + } else if ( isset( $cv[$subkey] ) && is_numeric( $cv[$subkey] ) && isset( $frm_duplicate_ids[$cv[$subkey]] ) ) { |
|
248 | + $action[$ck][$subkey] = $frm_duplicate_ids[$cv[$subkey]]; |
|
249 | 249 | } |
250 | 250 | } |
251 | 251 | } |
252 | 252 | } else { |
253 | 253 | foreach ( (array) $val as $ck => $cv ) { |
254 | - if ( is_array($cv) ) { |
|
255 | - $action[ $ck ] = $this->duplicate_array_walk( $action[ $ck ], $subkey, $cv ); |
|
256 | - } else if ( $ck == $subkey && isset( $frm_duplicate_ids[ $cv ] ) ) { |
|
257 | - $action[ $ck ] = $frm_duplicate_ids[ $cv ]; |
|
254 | + if ( is_array( $cv ) ) { |
|
255 | + $action[$ck] = $this->duplicate_array_walk( $action[$ck], $subkey, $cv ); |
|
256 | + } else if ( $ck == $subkey && isset( $frm_duplicate_ids[$cv] ) ) { |
|
257 | + $action[$ck] = $frm_duplicate_ids[$cv]; |
|
258 | 258 | } |
259 | 259 | } |
260 | 260 | } |
@@ -278,8 +278,8 @@ discard block |
||
278 | 278 | return; |
279 | 279 | } |
280 | 280 | |
281 | - if ( isset( $_POST[ $this->option_name ] ) && is_array( $_POST[ $this->option_name ] ) ) { |
|
282 | - $settings = $_POST[ $this->option_name ]; |
|
281 | + if ( isset( $_POST[$this->option_name] ) && is_array( $_POST[$this->option_name] ) ) { |
|
282 | + $settings = $_POST[$this->option_name]; |
|
283 | 283 | } else { |
284 | 284 | return; |
285 | 285 | } |
@@ -287,19 +287,19 @@ discard block |
||
287 | 287 | $action_ids = array(); |
288 | 288 | |
289 | 289 | foreach ( $settings as $number => $new_instance ) { |
290 | - $this->_set($number); |
|
290 | + $this->_set( $number ); |
|
291 | 291 | |
292 | - if ( ! isset($new_instance['post_title']) ) { |
|
292 | + if ( ! isset( $new_instance['post_title'] ) ) { |
|
293 | 293 | // settings were never opened, so don't update |
294 | 294 | $action_ids[] = $new_instance['ID']; |
295 | 295 | $this->updated = true; |
296 | 296 | continue; |
297 | 297 | } |
298 | 298 | |
299 | - $old_instance = isset( $all_instances[ $number ] ) ? $all_instances[ $number ] : array(); |
|
299 | + $old_instance = isset( $all_instances[$number] ) ? $all_instances[$number] : array(); |
|
300 | 300 | |
301 | - $new_instance['post_type'] = FrmFormActionsController::$action_post_type; |
|
302 | - $new_instance['post_name'] = $this->form_id . '_' . $this->id_base . '_' . $this->number; |
|
301 | + $new_instance['post_type'] = FrmFormActionsController::$action_post_type; |
|
302 | + $new_instance['post_name'] = $this->form_id . '_' . $this->id_base . '_' . $this->number; |
|
303 | 303 | $new_instance['menu_order'] = $this->form_id; |
304 | 304 | $new_instance['post_status'] = 'publish'; |
305 | 305 | $new_instance['post_date'] = isset( $old_instance->post_date ) ? $old_instance->post_date : ''; |
@@ -321,14 +321,14 @@ discard block |
||
321 | 321 | */ |
322 | 322 | $instance = apply_filters( 'frm_action_update_callback', $instance, $new_instance, $old_instance, $this ); |
323 | 323 | |
324 | - $instance['post_content'] = apply_filters('frm_before_save_action', $instance['post_content'], $instance, $new_instance, $old_instance, $this); |
|
324 | + $instance['post_content'] = apply_filters( 'frm_before_save_action', $instance['post_content'], $instance, $new_instance, $old_instance, $this ); |
|
325 | 325 | $instance['post_content'] = apply_filters( 'frm_before_save_' . $this->id_base . '_action', $new_instance['post_content'], $instance, $new_instance, $old_instance, $this ); |
326 | 326 | |
327 | 327 | if ( false !== $instance ) { |
328 | - $all_instances[ $number ] = $instance; |
|
328 | + $all_instances[$number] = $instance; |
|
329 | 329 | } |
330 | 330 | |
331 | - $action_ids[] = $this->save_settings($instance); |
|
331 | + $action_ids[] = $this->save_settings( $instance ); |
|
332 | 332 | |
333 | 333 | $this->updated = true; |
334 | 334 | } |
@@ -342,7 +342,7 @@ discard block |
||
342 | 342 | } |
343 | 343 | |
344 | 344 | public function get_single_action( $id ) { |
345 | - $action = get_post($id); |
|
345 | + $action = get_post( $id ); |
|
346 | 346 | if ( $action ) { |
347 | 347 | $action = $this->prepare_action( $action ); |
348 | 348 | $this->_set( $id ); |
@@ -351,12 +351,12 @@ discard block |
||
351 | 351 | } |
352 | 352 | |
353 | 353 | public function get_one( $form_id ) { |
354 | - return $this->get_all($form_id, 1); |
|
354 | + return $this->get_all( $form_id, 1 ); |
|
355 | 355 | } |
356 | 356 | |
357 | 357 | public static function get_action_for_form( $form_id, $type = 'all', $limit = 99 ) { |
358 | 358 | $action_controls = FrmFormActionsController::get_form_actions( $type ); |
359 | - if ( empty($action_controls) ) { |
|
359 | + if ( empty( $action_controls ) ) { |
|
360 | 360 | // don't continue if there are no available actions |
361 | 361 | return array(); |
362 | 362 | } |
@@ -377,12 +377,12 @@ discard block |
||
377 | 377 | // some plugins/themes are formatting the post_excerpt |
378 | 378 | $action->post_excerpt = sanitize_title( $action->post_excerpt ); |
379 | 379 | |
380 | - if ( ! isset( $action_controls[ $action->post_excerpt ] ) ) { |
|
380 | + if ( ! isset( $action_controls[$action->post_excerpt] ) ) { |
|
381 | 381 | continue; |
382 | 382 | } |
383 | 383 | |
384 | - $action = $action_controls[ $action->post_excerpt ]->prepare_action( $action ); |
|
385 | - $settings[ $action->ID ] = $action; |
|
384 | + $action = $action_controls[$action->post_excerpt]->prepare_action( $action ); |
|
385 | + $settings[$action->ID] = $action; |
|
386 | 386 | |
387 | 387 | if ( count( $settings ) >= $limit ) { |
388 | 388 | break; |
@@ -390,7 +390,7 @@ discard block |
||
390 | 390 | } |
391 | 391 | |
392 | 392 | if ( 1 === $limit ) { |
393 | - $settings = reset($settings); |
|
393 | + $settings = reset( $settings ); |
|
394 | 394 | } |
395 | 395 | |
396 | 396 | return $settings; |
@@ -406,33 +406,33 @@ discard block |
||
406 | 406 | global $frm_vars; |
407 | 407 | $frm_vars['action_type'] = $type; |
408 | 408 | |
409 | - add_filter( 'posts_where' , 'FrmFormActionsController::limit_by_type' ); |
|
409 | + add_filter( 'posts_where', 'FrmFormActionsController::limit_by_type' ); |
|
410 | 410 | $query = self::action_args( $form_id, $limit ); |
411 | 411 | $query['post_status'] = 'any'; |
412 | 412 | $query['suppress_filters'] = false; |
413 | 413 | |
414 | 414 | $actions = FrmAppHelper::check_cache( serialize( $query ) . '_type_' . $type, 'frm_actions', $query, 'get_posts' ); |
415 | - unset($query); |
|
415 | + unset( $query ); |
|
416 | 416 | |
417 | - remove_filter( 'posts_where' , 'FrmFormActionsController::limit_by_type' ); |
|
417 | + remove_filter( 'posts_where', 'FrmFormActionsController::limit_by_type' ); |
|
418 | 418 | |
419 | - if ( empty($actions) ) { |
|
419 | + if ( empty( $actions ) ) { |
|
420 | 420 | return array(); |
421 | 421 | } |
422 | 422 | |
423 | 423 | $settings = array(); |
424 | 424 | foreach ( $actions as $action ) { |
425 | - if ( count($settings) >= $limit ) { |
|
425 | + if ( count( $settings ) >= $limit ) { |
|
426 | 426 | continue; |
427 | 427 | } |
428 | 428 | |
429 | - $action = $this->prepare_action($action); |
|
429 | + $action = $this->prepare_action( $action ); |
|
430 | 430 | |
431 | - $settings[ $action->ID ] = $action; |
|
431 | + $settings[$action->ID] = $action; |
|
432 | 432 | } |
433 | 433 | |
434 | 434 | if ( 1 === $limit ) { |
435 | - $settings = reset($settings); |
|
435 | + $settings = reset( $settings ); |
|
436 | 436 | } |
437 | 437 | |
438 | 438 | return $settings; |
@@ -455,7 +455,7 @@ discard block |
||
455 | 455 | } |
456 | 456 | |
457 | 457 | public function prepare_action( $action ) { |
458 | - $action->post_content = (array) FrmAppHelper::maybe_json_decode($action->post_content); |
|
458 | + $action->post_content = (array) FrmAppHelper::maybe_json_decode( $action->post_content ); |
|
459 | 459 | $action->post_excerpt = sanitize_title( $action->post_excerpt ); |
460 | 460 | |
461 | 461 | $default_values = $this->get_global_defaults(); |
@@ -464,16 +464,16 @@ discard block |
||
464 | 464 | $action->post_content += $default_values; |
465 | 465 | |
466 | 466 | foreach ( $default_values as $k => $vals ) { |
467 | - if ( is_array($vals) && ! empty($vals) ) { |
|
468 | - if ( 'event' == $k && ! $this->action_options['force_event'] && ! empty( $action->post_content[ $k ] ) ) { |
|
467 | + if ( is_array( $vals ) && ! empty( $vals ) ) { |
|
468 | + if ( 'event' == $k && ! $this->action_options['force_event'] && ! empty( $action->post_content[$k] ) ) { |
|
469 | 469 | continue; |
470 | 470 | } |
471 | - $action->post_content[ $k ] = wp_parse_args( $action->post_content[ $k ], $vals ); |
|
471 | + $action->post_content[$k] = wp_parse_args( $action->post_content[$k], $vals ); |
|
472 | 472 | } |
473 | 473 | } |
474 | 474 | |
475 | - if ( ! is_array($action->post_content['event']) ) { |
|
476 | - $action->post_content['event'] = explode(',', $action->post_content['event']); |
|
475 | + if ( ! is_array( $action->post_content['event'] ) ) { |
|
476 | + $action->post_content['event'] = explode( ',', $action->post_content['event'] ); |
|
477 | 477 | } |
478 | 478 | |
479 | 479 | return $action; |
@@ -495,7 +495,7 @@ discard block |
||
495 | 495 | $post_ids = FrmDb::get_col( $wpdb->posts, $query, 'ID' ); |
496 | 496 | |
497 | 497 | foreach ( $post_ids as $id ) { |
498 | - wp_delete_post($id); |
|
498 | + wp_delete_post( $id ); |
|
499 | 499 | } |
500 | 500 | self::clear_cache(); |
501 | 501 | } |
@@ -516,11 +516,11 @@ discard block |
||
516 | 516 | public function get_global_defaults() { |
517 | 517 | $defaults = $this->get_defaults(); |
518 | 518 | |
519 | - if ( ! isset($defaults['event']) ) { |
|
519 | + if ( ! isset( $defaults['event'] ) ) { |
|
520 | 520 | $defaults['event'] = array( 'create' ); |
521 | 521 | } |
522 | 522 | |
523 | - if ( ! isset($defaults['conditions']) ) { |
|
523 | + if ( ! isset( $defaults['conditions'] ) ) { |
|
524 | 524 | $defaults['conditions'] = array( |
525 | 525 | 'send_stop' => '', |
526 | 526 | 'any_all' => '', |
@@ -540,18 +540,18 @@ discard block |
||
540 | 540 | * Migrate settings from form->options into new action. |
541 | 541 | */ |
542 | 542 | public function migrate_to_2( $form, $update = 'update' ) { |
543 | - $action = $this->prepare_new($form->id); |
|
544 | - $form->options = maybe_unserialize($form->options); |
|
543 | + $action = $this->prepare_new( $form->id ); |
|
544 | + $form->options = maybe_unserialize( $form->options ); |
|
545 | 545 | |
546 | 546 | // fill with existing options |
547 | 547 | foreach ( $action->post_content as $name => $val ) { |
548 | - if ( isset( $form->options[ $name ] ) ) { |
|
549 | - $action->post_content[ $name ] = $form->options[ $name ]; |
|
550 | - unset( $form->options[ $name ] ); |
|
548 | + if ( isset( $form->options[$name] ) ) { |
|
549 | + $action->post_content[$name] = $form->options[$name]; |
|
550 | + unset( $form->options[$name] ); |
|
551 | 551 | } |
552 | 552 | } |
553 | 553 | |
554 | - $action = $this->migrate_values($action, $form); |
|
554 | + $action = $this->migrate_values( $action, $form ); |
|
555 | 555 | |
556 | 556 | // check if action already exists |
557 | 557 | $post_id = get_posts( array( |
@@ -561,18 +561,18 @@ discard block |
||
561 | 561 | 'numberposts' => 1, |
562 | 562 | ) ); |
563 | 563 | |
564 | - if ( empty($post_id) ) { |
|
564 | + if ( empty( $post_id ) ) { |
|
565 | 565 | // create action now |
566 | - $post_id = $this->save_settings($action); |
|
566 | + $post_id = $this->save_settings( $action ); |
|
567 | 567 | } |
568 | 568 | |
569 | 569 | if ( $post_id && 'update' == $update ) { |
570 | 570 | global $wpdb; |
571 | - $form->options = maybe_serialize($form->options); |
|
571 | + $form->options = maybe_serialize( $form->options ); |
|
572 | 572 | |
573 | 573 | // update form options |
574 | 574 | $wpdb->update( $wpdb->prefix . 'frm_forms', array( 'options' => $form->options ), array( 'id' => $form->id ) ); |
575 | - wp_cache_delete( $form->id, 'frm_form'); |
|
575 | + wp_cache_delete( $form->id, 'frm_form' ); |
|
576 | 576 | } |
577 | 577 | |
578 | 578 | return $post_id; |
@@ -596,27 +596,27 @@ discard block |
||
596 | 596 | continue; |
597 | 597 | } |
598 | 598 | |
599 | - if ( is_array($condition['hide_opt']) ) { |
|
600 | - $condition['hide_opt'] = reset($condition['hide_opt']); |
|
599 | + if ( is_array( $condition['hide_opt'] ) ) { |
|
600 | + $condition['hide_opt'] = reset( $condition['hide_opt'] ); |
|
601 | 601 | } |
602 | 602 | |
603 | - $observed_value = isset( $entry->metas[ $condition['hide_field'] ] ) ? $entry->metas[ $condition['hide_field'] ] : ''; |
|
603 | + $observed_value = isset( $entry->metas[$condition['hide_field']] ) ? $entry->metas[$condition['hide_field']] : ''; |
|
604 | 604 | if ( $condition['hide_opt'] == 'current_user' ) { |
605 | 605 | $condition['hide_opt'] = get_current_user_id(); |
606 | 606 | } |
607 | 607 | |
608 | - $stop = FrmFieldsHelper::value_meets_condition($observed_value, $condition['hide_field_cond'], $condition['hide_opt']); |
|
608 | + $stop = FrmFieldsHelper::value_meets_condition( $observed_value, $condition['hide_field_cond'], $condition['hide_opt'] ); |
|
609 | 609 | |
610 | 610 | if ( $notification['conditions']['send_stop'] == 'send' ) { |
611 | 611 | $stop = $stop ? false : true; |
612 | 612 | } |
613 | 613 | |
614 | - $met[ $stop ] = $stop; |
|
614 | + $met[$stop] = $stop; |
|
615 | 615 | } |
616 | 616 | |
617 | 617 | if ( $notification['conditions']['any_all'] == 'all' && ! empty( $met ) && isset( $met[0] ) && isset( $met[1] ) ) { |
618 | - $stop = ($notification['conditions']['send_stop'] == 'send'); |
|
619 | - } else if ( $notification['conditions']['any_all'] == 'any' && $notification['conditions']['send_stop'] == 'send' && isset($met[0]) ) { |
|
618 | + $stop = ( $notification['conditions']['send_stop'] == 'send' ); |
|
619 | + } else if ( $notification['conditions']['any_all'] == 'any' && $notification['conditions']['send_stop'] == 'send' && isset( $met[0] ) ) { |
|
620 | 620 | $stop = false; |
621 | 621 | } |
622 | 622 |
@@ -1,251 +1,251 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | if ( ! defined('ABSPATH') ) { |
3 | - die('You are not allowed to call this page directly.'); |
|
3 | + die('You are not allowed to call this page directly.'); |
|
4 | 4 | } |
5 | 5 | |
6 | 6 | class FrmForm { |
7 | 7 | |
8 | - /** |
|
9 | - * @return int|boolean id on success or false on failure |
|
10 | - */ |
|
11 | - public static function create( $values ) { |
|
12 | - global $wpdb; |
|
8 | + /** |
|
9 | + * @return int|boolean id on success or false on failure |
|
10 | + */ |
|
11 | + public static function create( $values ) { |
|
12 | + global $wpdb; |
|
13 | 13 | |
14 | - $new_values = array( |
|
14 | + $new_values = array( |
|
15 | 15 | 'form_key' => FrmAppHelper::get_unique_key( $values['form_key'], $wpdb->prefix . 'frm_forms', 'form_key' ), |
16 | - 'name' => $values['name'], |
|
17 | - 'description' => $values['description'], |
|
18 | - 'status' => isset($values['status']) ? $values['status'] : 'draft', |
|
19 | - 'logged_in' => isset($values['logged_in']) ? $values['logged_in'] : 0, |
|
20 | - 'is_template' => isset($values['is_template']) ? (int) $values['is_template'] : 0, |
|
16 | + 'name' => $values['name'], |
|
17 | + 'description' => $values['description'], |
|
18 | + 'status' => isset($values['status']) ? $values['status'] : 'draft', |
|
19 | + 'logged_in' => isset($values['logged_in']) ? $values['logged_in'] : 0, |
|
20 | + 'is_template' => isset($values['is_template']) ? (int) $values['is_template'] : 0, |
|
21 | 21 | 'parent_form_id' => isset( $values['parent_form_id'] ) ? absint( $values['parent_form_id'] ) : 0, |
22 | - 'editable' => isset($values['editable']) ? (int) $values['editable'] : 0, |
|
23 | - 'default_template' => isset($values['default_template']) ? (int) $values['default_template'] : 0, |
|
24 | - 'created_at' => isset($values['created_at']) ? $values['created_at'] : current_time('mysql', 1), |
|
25 | - ); |
|
22 | + 'editable' => isset($values['editable']) ? (int) $values['editable'] : 0, |
|
23 | + 'default_template' => isset($values['default_template']) ? (int) $values['default_template'] : 0, |
|
24 | + 'created_at' => isset($values['created_at']) ? $values['created_at'] : current_time('mysql', 1), |
|
25 | + ); |
|
26 | 26 | |
27 | - $options = array(); |
|
27 | + $options = array(); |
|
28 | 28 | FrmFormsHelper::fill_form_options( $options, $values ); |
29 | 29 | |
30 | - $options['before_html'] = isset($values['options']['before_html']) ? $values['options']['before_html'] : FrmFormsHelper::get_default_html('before'); |
|
31 | - $options['after_html'] = isset($values['options']['after_html']) ? $values['options']['after_html'] : FrmFormsHelper::get_default_html('after'); |
|
32 | - $options['submit_html'] = isset($values['options']['submit_html']) ? $values['options']['submit_html'] : FrmFormsHelper::get_default_html('submit'); |
|
30 | + $options['before_html'] = isset($values['options']['before_html']) ? $values['options']['before_html'] : FrmFormsHelper::get_default_html('before'); |
|
31 | + $options['after_html'] = isset($values['options']['after_html']) ? $values['options']['after_html'] : FrmFormsHelper::get_default_html('after'); |
|
32 | + $options['submit_html'] = isset($values['options']['submit_html']) ? $values['options']['submit_html'] : FrmFormsHelper::get_default_html('submit'); |
|
33 | 33 | |
34 | - $options = apply_filters('frm_form_options_before_update', $options, $values); |
|
35 | - $new_values['options'] = serialize($options); |
|
34 | + $options = apply_filters('frm_form_options_before_update', $options, $values); |
|
35 | + $new_values['options'] = serialize($options); |
|
36 | 36 | |
37 | - //if(isset($values['id']) && is_numeric($values['id'])) |
|
38 | - // $new_values['id'] = $values['id']; |
|
37 | + //if(isset($values['id']) && is_numeric($values['id'])) |
|
38 | + // $new_values['id'] = $values['id']; |
|
39 | 39 | |
40 | 40 | $wpdb->insert( $wpdb->prefix . 'frm_forms', $new_values ); |
41 | 41 | |
42 | - $id = $wpdb->insert_id; |
|
42 | + $id = $wpdb->insert_id; |
|
43 | 43 | |
44 | 44 | // Clear form caching |
45 | 45 | self::clear_form_cache(); |
46 | 46 | |
47 | - return $id; |
|
48 | - } |
|
47 | + return $id; |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * @return int|boolean ID on success or false on failure |
|
52 | - */ |
|
53 | - public static function duplicate( $id, $template = false, $copy_keys = false, $blog_id = false ) { |
|
54 | - global $wpdb; |
|
50 | + /** |
|
51 | + * @return int|boolean ID on success or false on failure |
|
52 | + */ |
|
53 | + public static function duplicate( $id, $template = false, $copy_keys = false, $blog_id = false ) { |
|
54 | + global $wpdb; |
|
55 | 55 | |
56 | - $values = self::getOne( $id, $blog_id ); |
|
57 | - if ( ! $values ) { |
|
58 | - return false; |
|
59 | - } |
|
56 | + $values = self::getOne( $id, $blog_id ); |
|
57 | + if ( ! $values ) { |
|
58 | + return false; |
|
59 | + } |
|
60 | 60 | |
61 | - $new_key = $copy_keys ? $values->form_key : ''; |
|
61 | + $new_key = $copy_keys ? $values->form_key : ''; |
|
62 | 62 | |
63 | - $new_values = array( |
|
63 | + $new_values = array( |
|
64 | 64 | 'form_key' => FrmAppHelper::get_unique_key( $new_key, $wpdb->prefix . 'frm_forms', 'form_key' ), |
65 | - 'name' => $values->name, |
|
66 | - 'description' => $values->description, |
|
67 | - 'status' => $template ? 'published' : 'draft', |
|
68 | - 'logged_in' => $values->logged_in ? $values->logged_in : 0, |
|
69 | - 'editable' => $values->editable ? $values->editable : 0, |
|
70 | - 'created_at' => current_time('mysql', 1), |
|
71 | - 'is_template' => $template ? 1 : 0, |
|
72 | - ); |
|
73 | - |
|
74 | - if ( $blog_id ) { |
|
75 | - $new_values['status'] = 'published'; |
|
76 | - $new_options = maybe_unserialize($values->options); |
|
77 | - $new_options['email_to'] = get_option('admin_email'); |
|
78 | - $new_options['copy'] = false; |
|
79 | - $new_values['options'] = $new_options; |
|
80 | - } else { |
|
81 | - $new_values['options'] = $values->options; |
|
82 | - } |
|
83 | - |
|
84 | - if ( is_array($new_values['options']) ) { |
|
85 | - $new_values['options'] = serialize($new_values['options']); |
|
86 | - } |
|
65 | + 'name' => $values->name, |
|
66 | + 'description' => $values->description, |
|
67 | + 'status' => $template ? 'published' : 'draft', |
|
68 | + 'logged_in' => $values->logged_in ? $values->logged_in : 0, |
|
69 | + 'editable' => $values->editable ? $values->editable : 0, |
|
70 | + 'created_at' => current_time('mysql', 1), |
|
71 | + 'is_template' => $template ? 1 : 0, |
|
72 | + ); |
|
73 | + |
|
74 | + if ( $blog_id ) { |
|
75 | + $new_values['status'] = 'published'; |
|
76 | + $new_options = maybe_unserialize($values->options); |
|
77 | + $new_options['email_to'] = get_option('admin_email'); |
|
78 | + $new_options['copy'] = false; |
|
79 | + $new_values['options'] = $new_options; |
|
80 | + } else { |
|
81 | + $new_values['options'] = $values->options; |
|
82 | + } |
|
83 | + |
|
84 | + if ( is_array($new_values['options']) ) { |
|
85 | + $new_values['options'] = serialize($new_values['options']); |
|
86 | + } |
|
87 | 87 | |
88 | 88 | $query_results = $wpdb->insert( $wpdb->prefix . 'frm_forms', $new_values ); |
89 | 89 | |
90 | - if ( $query_results ) { |
|
90 | + if ( $query_results ) { |
|
91 | 91 | // Clear form caching |
92 | 92 | self::clear_form_cache(); |
93 | 93 | |
94 | - $form_id = $wpdb->insert_id; |
|
95 | - FrmField::duplicate($id, $form_id, $copy_keys, $blog_id); |
|
94 | + $form_id = $wpdb->insert_id; |
|
95 | + FrmField::duplicate($id, $form_id, $copy_keys, $blog_id); |
|
96 | 96 | |
97 | - // update form settings after fields are created |
|
97 | + // update form settings after fields are created |
|
98 | 98 | do_action( 'frm_after_duplicate_form', $form_id, $new_values, array( 'old_id' => $id ) ); |
99 | - return $form_id; |
|
100 | - } |
|
99 | + return $form_id; |
|
100 | + } |
|
101 | 101 | |
102 | - return false; |
|
103 | - } |
|
102 | + return false; |
|
103 | + } |
|
104 | 104 | |
105 | 105 | public static function after_duplicate( $form_id, $values ) { |
106 | - $new_opts = $values['options'] = maybe_unserialize($values['options']); |
|
106 | + $new_opts = $values['options'] = maybe_unserialize($values['options']); |
|
107 | 107 | |
108 | - if ( isset($new_opts['success_msg']) ) { |
|
109 | - $new_opts['success_msg'] = FrmFieldsHelper::switch_field_ids($new_opts['success_msg']); |
|
110 | - } |
|
108 | + if ( isset($new_opts['success_msg']) ) { |
|
109 | + $new_opts['success_msg'] = FrmFieldsHelper::switch_field_ids($new_opts['success_msg']); |
|
110 | + } |
|
111 | 111 | |
112 | - $new_opts = apply_filters('frm_after_duplicate_form_values', $new_opts, $form_id); |
|
112 | + $new_opts = apply_filters('frm_after_duplicate_form_values', $new_opts, $form_id); |
|
113 | 113 | |
114 | - if ( $new_opts != $values['options'] ) { |
|
115 | - global $wpdb; |
|
114 | + if ( $new_opts != $values['options'] ) { |
|
115 | + global $wpdb; |
|
116 | 116 | $wpdb->update( $wpdb->prefix . 'frm_forms', array( 'options' => maybe_serialize( $new_opts ) ), array( 'id' => $form_id ) ); |
117 | - } |
|
118 | - } |
|
117 | + } |
|
118 | + } |
|
119 | 119 | |
120 | - /** |
|
121 | - * @return int|boolean |
|
122 | - */ |
|
123 | - public static function update( $id, $values, $create_link = false ) { |
|
124 | - global $wpdb; |
|
120 | + /** |
|
121 | + * @return int|boolean |
|
122 | + */ |
|
123 | + public static function update( $id, $values, $create_link = false ) { |
|
124 | + global $wpdb; |
|
125 | 125 | |
126 | - if ( ! isset( $values['status'] ) && ( $create_link || isset( $values['options'] ) || isset( $values['item_meta'] ) || isset( $values['field_options'] ) ) ) { |
|
127 | - $values['status'] = 'published'; |
|
128 | - } |
|
126 | + if ( ! isset( $values['status'] ) && ( $create_link || isset( $values['options'] ) || isset( $values['item_meta'] ) || isset( $values['field_options'] ) ) ) { |
|
127 | + $values['status'] = 'published'; |
|
128 | + } |
|
129 | 129 | |
130 | - if ( isset($values['form_key']) ) { |
|
130 | + if ( isset($values['form_key']) ) { |
|
131 | 131 | $values['form_key'] = FrmAppHelper::get_unique_key( $values['form_key'], $wpdb->prefix . 'frm_forms', 'form_key', $id ); |
132 | - } |
|
132 | + } |
|
133 | 133 | |
134 | - $form_fields = array( 'form_key', 'name', 'description', 'status', 'parent_form_id' ); |
|
134 | + $form_fields = array( 'form_key', 'name', 'description', 'status', 'parent_form_id' ); |
|
135 | 135 | |
136 | - $new_values = self::set_update_options( array(), $values); |
|
136 | + $new_values = self::set_update_options( array(), $values); |
|
137 | 137 | |
138 | - foreach ( $values as $value_key => $value ) { |
|
139 | - if ( in_array($value_key, $form_fields) ) { |
|
138 | + foreach ( $values as $value_key => $value ) { |
|
139 | + if ( in_array($value_key, $form_fields) ) { |
|
140 | 140 | $new_values[ $value_key ] = $value; |
141 | - } |
|
142 | - } |
|
141 | + } |
|
142 | + } |
|
143 | 143 | |
144 | - if ( isset( $values['new_status'] ) && ! empty( $values['new_status'] ) ) { |
|
145 | - $new_values['status'] = $values['new_status']; |
|
146 | - } |
|
144 | + if ( isset( $values['new_status'] ) && ! empty( $values['new_status'] ) ) { |
|
145 | + $new_values['status'] = $values['new_status']; |
|
146 | + } |
|
147 | 147 | |
148 | - if ( ! empty( $new_values ) ) { |
|
148 | + if ( ! empty( $new_values ) ) { |
|
149 | 149 | $query_results = $wpdb->update( $wpdb->prefix . 'frm_forms', $new_values, array( 'id' => $id ) ); |
150 | - if ( $query_results ) { |
|
150 | + if ( $query_results ) { |
|
151 | 151 | self::clear_form_cache(); |
152 | - } |
|
153 | - } else { |
|
154 | - $query_results = true; |
|
155 | - } |
|
156 | - unset($new_values); |
|
152 | + } |
|
153 | + } else { |
|
154 | + $query_results = true; |
|
155 | + } |
|
156 | + unset($new_values); |
|
157 | 157 | |
158 | - $values = self::update_fields($id, $values); |
|
158 | + $values = self::update_fields($id, $values); |
|
159 | 159 | |
160 | 160 | do_action( 'frm_update_form', $id, $values ); |
161 | 161 | do_action( 'frm_update_form_' . $id, $values ); |
162 | 162 | |
163 | - return $query_results; |
|
164 | - } |
|
163 | + return $query_results; |
|
164 | + } |
|
165 | 165 | |
166 | - /** |
|
167 | - * @return array |
|
168 | - */ |
|
166 | + /** |
|
167 | + * @return array |
|
168 | + */ |
|
169 | 169 | public static function set_update_options( $new_values, $values ) { |
170 | - if ( ! isset($values['options']) ) { |
|
171 | - return $new_values; |
|
172 | - } |
|
170 | + if ( ! isset($values['options']) ) { |
|
171 | + return $new_values; |
|
172 | + } |
|
173 | 173 | |
174 | - $options = array(); |
|
174 | + $options = array(); |
|
175 | 175 | FrmFormsHelper::fill_form_options( $options, $values ); |
176 | 176 | |
177 | - $options['custom_style'] = isset($values['options']['custom_style']) ? $values['options']['custom_style'] : 0; |
|
178 | - $options['before_html'] = isset($values['options']['before_html']) ? $values['options']['before_html'] : FrmFormsHelper::get_default_html('before'); |
|
179 | - $options['after_html'] = isset($values['options']['after_html']) ? $values['options']['after_html'] : FrmFormsHelper::get_default_html('after'); |
|
180 | - $options['submit_html'] = (isset($values['options']['submit_html']) && $values['options']['submit_html'] != '') ? $values['options']['submit_html'] : FrmFormsHelper::get_default_html('submit'); |
|
177 | + $options['custom_style'] = isset($values['options']['custom_style']) ? $values['options']['custom_style'] : 0; |
|
178 | + $options['before_html'] = isset($values['options']['before_html']) ? $values['options']['before_html'] : FrmFormsHelper::get_default_html('before'); |
|
179 | + $options['after_html'] = isset($values['options']['after_html']) ? $values['options']['after_html'] : FrmFormsHelper::get_default_html('after'); |
|
180 | + $options['submit_html'] = (isset($values['options']['submit_html']) && $values['options']['submit_html'] != '') ? $values['options']['submit_html'] : FrmFormsHelper::get_default_html('submit'); |
|
181 | 181 | |
182 | - $options = apply_filters('frm_form_options_before_update', $options, $values); |
|
183 | - $new_values['options'] = serialize($options); |
|
182 | + $options = apply_filters('frm_form_options_before_update', $options, $values); |
|
183 | + $new_values['options'] = serialize($options); |
|
184 | 184 | |
185 | - return $new_values; |
|
186 | - } |
|
185 | + return $new_values; |
|
186 | + } |
|
187 | 187 | |
188 | 188 | |
189 | - /** |
|
190 | - * @return array |
|
191 | - */ |
|
189 | + /** |
|
190 | + * @return array |
|
191 | + */ |
|
192 | 192 | public static function update_fields( $id, $values ) { |
193 | 193 | |
194 | - if ( ! isset($values['options']) && ! isset($values['item_meta']) && ! isset($values['field_options']) ) { |
|
195 | - return $values; |
|
196 | - } |
|
194 | + if ( ! isset($values['options']) && ! isset($values['item_meta']) && ! isset($values['field_options']) ) { |
|
195 | + return $values; |
|
196 | + } |
|
197 | 197 | |
198 | - $all_fields = FrmField::get_all_for_form($id); |
|
199 | - if ( empty($all_fields) ) { |
|
200 | - return $values; |
|
201 | - } |
|
198 | + $all_fields = FrmField::get_all_for_form($id); |
|
199 | + if ( empty($all_fields) ) { |
|
200 | + return $values; |
|
201 | + } |
|
202 | 202 | |
203 | - if ( ! isset($values['item_meta']) ) { |
|
204 | - $values['item_meta'] = array(); |
|
205 | - } |
|
203 | + if ( ! isset($values['item_meta']) ) { |
|
204 | + $values['item_meta'] = array(); |
|
205 | + } |
|
206 | 206 | |
207 | - $field_array = array(); |
|
208 | - $existing_keys = array_keys($values['item_meta']); |
|
209 | - foreach ( $all_fields as $fid ) { |
|
210 | - if ( ! in_array($fid->id, $existing_keys) && ( isset($values['frm_fields_submitted']) && in_array($fid->id, $values['frm_fields_submitted']) ) || isset($values['options']) ) { |
|
207 | + $field_array = array(); |
|
208 | + $existing_keys = array_keys($values['item_meta']); |
|
209 | + foreach ( $all_fields as $fid ) { |
|
210 | + if ( ! in_array($fid->id, $existing_keys) && ( isset($values['frm_fields_submitted']) && in_array($fid->id, $values['frm_fields_submitted']) ) || isset($values['options']) ) { |
|
211 | 211 | $values['item_meta'][ $fid->id ] = ''; |
212 | - } |
|
212 | + } |
|
213 | 213 | $field_array[ $fid->id ] = $fid; |
214 | - } |
|
215 | - unset($all_fields); |
|
214 | + } |
|
215 | + unset($all_fields); |
|
216 | 216 | |
217 | - foreach ( $values['item_meta'] as $field_id => $default_value ) { |
|
217 | + foreach ( $values['item_meta'] as $field_id => $default_value ) { |
|
218 | 218 | if ( isset( $field_array[ $field_id ] ) ) { |
219 | 219 | $field = $field_array[ $field_id ]; |
220 | - } else { |
|
221 | - $field = FrmField::getOne($field_id); |
|
222 | - } |
|
220 | + } else { |
|
221 | + $field = FrmField::getOne($field_id); |
|
222 | + } |
|
223 | 223 | |
224 | - if ( ! $field ) { |
|
225 | - continue; |
|
226 | - } |
|
224 | + if ( ! $field ) { |
|
225 | + continue; |
|
226 | + } |
|
227 | 227 | |
228 | 228 | if ( isset( $values['options'] ) || isset( $values['field_options'][ 'custom_html_' . $field_id ] ) ) { |
229 | - //updating the settings page |
|
229 | + //updating the settings page |
|
230 | 230 | if ( isset( $values['field_options'][ 'custom_html_' . $field_id ] ) ) { |
231 | 231 | $field->field_options['custom_html'] = isset( $values['field_options'][ 'custom_html_' . $field_id ] ) ? $values['field_options'][ 'custom_html_' . $field_id ] : ( isset( $field->field_options['custom_html'] ) ? $field->field_options['custom_html'] : FrmFieldsHelper::get_default_html( $field->type ) ); |
232 | - $field->field_options = apply_filters('frm_update_form_field_options', $field->field_options, $field, $values); |
|
232 | + $field->field_options = apply_filters('frm_update_form_field_options', $field->field_options, $field, $values); |
|
233 | 233 | FrmField::update( $field_id, array( 'field_options' => $field->field_options ) ); |
234 | - } else if ( $field->type == 'hidden' || $field->type == 'user_id' ) { |
|
235 | - $prev_opts = $field->field_options; |
|
236 | - $field->field_options = apply_filters('frm_update_form_field_options', $field->field_options, $field, $values); |
|
237 | - if ( $prev_opts != $field->field_options ) { |
|
234 | + } else if ( $field->type == 'hidden' || $field->type == 'user_id' ) { |
|
235 | + $prev_opts = $field->field_options; |
|
236 | + $field->field_options = apply_filters('frm_update_form_field_options', $field->field_options, $field, $values); |
|
237 | + if ( $prev_opts != $field->field_options ) { |
|
238 | 238 | FrmField::update( $field_id, array( 'field_options' => $field->field_options ) ); |
239 | - } |
|
240 | - unset($prev_opts); |
|
241 | - } |
|
242 | - } |
|
239 | + } |
|
240 | + unset($prev_opts); |
|
241 | + } |
|
242 | + } |
|
243 | 243 | |
244 | 244 | if ( ( isset( $values['options'] ) || isset( $values['field_options'][ 'custom_html_' . $field_id ] ) ) && ! defined( 'WP_IMPORTING' ) ) { |
245 | - continue; |
|
246 | - } |
|
245 | + continue; |
|
246 | + } |
|
247 | 247 | |
248 | - //updating the form |
|
248 | + //updating the form |
|
249 | 249 | $update_options = array( |
250 | 250 | 'size', 'max', 'label', 'invalid', 'blank', |
251 | 251 | 'classes', 'captcha_size', 'default_blank', |
@@ -254,129 +254,129 @@ discard block |
||
254 | 254 | $update_options = apply_filters( 'frm_field_options_to_update', $update_options ); |
255 | 255 | foreach ( $update_options as $opt ) { |
256 | 256 | $field->field_options[ $opt ] = isset( $values['field_options'][ $opt . '_' . $field_id ] ) ? trim( $values['field_options'][ $opt . '_' . $field_id ] ) : ''; |
257 | - } |
|
257 | + } |
|
258 | 258 | |
259 | 259 | $field->field_options['required_indicator'] = isset( $values['field_options'][ 'required_indicator_' . $field_id ] ) ? trim( $values['field_options'][ 'required_indicator_' . $field_id ] ) : '*'; |
260 | 260 | $field->field_options['separate_value'] = isset( $values['field_options'][ 'separate_value_' . $field_id ] ) ? trim( $values['field_options'][ 'separate_value_' . $field_id ] ) : 0; |
261 | 261 | |
262 | - $field->field_options = apply_filters('frm_update_field_options', $field->field_options, $field, $values); |
|
262 | + $field->field_options = apply_filters('frm_update_field_options', $field->field_options, $field, $values); |
|
263 | 263 | $default_value = maybe_serialize( $values['item_meta'][ $field_id ] ); |
264 | 264 | $field_key = isset( $values['field_options'][ 'field_key_' . $field_id ] ) ? $values['field_options'][ 'field_key_' . $field_id ] : $field->field_key; |
265 | 265 | $required = isset( $values['field_options'][ 'required_' . $field_id ] ) ? $values['field_options'][ 'required_' . $field_id ] : false; |
266 | 266 | $field_type = isset( $values['field_options'][ 'type_' . $field_id ] ) ? $values['field_options'][ 'type_' . $field_id ] : $field->type; |
267 | 267 | $field_description = isset( $values['field_options'][ 'description_' . $field_id ] ) ? $values['field_options'][ 'description_' . $field_id ] : $field->description; |
268 | 268 | |
269 | - FrmField::update($field_id, array( |
|
270 | - 'field_key' => $field_key, 'type' => $field_type, |
|
271 | - 'default_value' => $default_value, 'field_options' => $field->field_options, |
|
272 | - 'description' => $field_description, 'required' => $required, |
|
273 | - ) ); |
|
269 | + FrmField::update($field_id, array( |
|
270 | + 'field_key' => $field_key, 'type' => $field_type, |
|
271 | + 'default_value' => $default_value, 'field_options' => $field->field_options, |
|
272 | + 'description' => $field_description, 'required' => $required, |
|
273 | + ) ); |
|
274 | 274 | |
275 | - FrmField::delete_form_transient($field->form_id); |
|
276 | - } |
|
275 | + FrmField::delete_form_transient($field->form_id); |
|
276 | + } |
|
277 | 277 | |
278 | - return $values; |
|
279 | - } |
|
278 | + return $values; |
|
279 | + } |
|
280 | 280 | |
281 | - /** |
|
282 | - * @param string $status |
|
283 | - * @return int|boolean |
|
284 | - */ |
|
281 | + /** |
|
282 | + * @param string $status |
|
283 | + * @return int|boolean |
|
284 | + */ |
|
285 | 285 | public static function set_status( $id, $status ) { |
286 | - if ( 'trash' == $status ) { |
|
287 | - return self::trash($id); |
|
288 | - } |
|
286 | + if ( 'trash' == $status ) { |
|
287 | + return self::trash($id); |
|
288 | + } |
|
289 | 289 | |
290 | 290 | $statuses = array( 'published', 'draft', 'trash' ); |
291 | - if ( ! in_array( $status, $statuses ) ) { |
|
292 | - return false; |
|
293 | - } |
|
291 | + if ( ! in_array( $status, $statuses ) ) { |
|
292 | + return false; |
|
293 | + } |
|
294 | 294 | |
295 | - global $wpdb; |
|
295 | + global $wpdb; |
|
296 | 296 | |
297 | - if ( is_array($id) ) { |
|
297 | + if ( is_array($id) ) { |
|
298 | 298 | $where = array( 'id' => $id ); |
299 | 299 | FrmDb::get_where_clause_and_values( $where ); |
300 | 300 | array_unshift( $where['values'], $status ); |
301 | 301 | |
302 | 302 | $query_results = $wpdb->query( $wpdb->prepare( 'UPDATE ' . $wpdb->prefix . 'frm_forms SET status = %s ' . $where['where'], $where['values'] ) ); |
303 | - } else { |
|
303 | + } else { |
|
304 | 304 | $query_results = $wpdb->update( $wpdb->prefix . 'frm_forms', array( 'status' => $status ), array( 'id' => $id ) ); |
305 | - } |
|
305 | + } |
|
306 | 306 | |
307 | - if ( $query_results ) { |
|
307 | + if ( $query_results ) { |
|
308 | 308 | self::clear_form_cache(); |
309 | - } |
|
309 | + } |
|
310 | 310 | |
311 | - return $query_results; |
|
312 | - } |
|
311 | + return $query_results; |
|
312 | + } |
|
313 | 313 | |
314 | - /** |
|
315 | - * @return int|boolean |
|
316 | - */ |
|
314 | + /** |
|
315 | + * @return int|boolean |
|
316 | + */ |
|
317 | 317 | public static function trash( $id ) { |
318 | - if ( ! EMPTY_TRASH_DAYS ) { |
|
319 | - return self::destroy( $id ); |
|
320 | - } |
|
318 | + if ( ! EMPTY_TRASH_DAYS ) { |
|
319 | + return self::destroy( $id ); |
|
320 | + } |
|
321 | 321 | |
322 | - $form = self::getOne($id); |
|
323 | - if ( ! $form ) { |
|
324 | - return false; |
|
325 | - } |
|
322 | + $form = self::getOne($id); |
|
323 | + if ( ! $form ) { |
|
324 | + return false; |
|
325 | + } |
|
326 | 326 | |
327 | - $options = $form->options; |
|
328 | - $options['trash_time'] = time(); |
|
327 | + $options = $form->options; |
|
328 | + $options['trash_time'] = time(); |
|
329 | 329 | |
330 | - global $wpdb; |
|
331 | - $query_results = $wpdb->update( |
|
330 | + global $wpdb; |
|
331 | + $query_results = $wpdb->update( |
|
332 | 332 | $wpdb->prefix . 'frm_forms', |
333 | 333 | array( 'status' => 'trash', 'options' => serialize( $options ) ), |
334 | 334 | array( 'id' => $id ) |
335 | - ); |
|
335 | + ); |
|
336 | 336 | |
337 | - if ( $query_results ) { |
|
337 | + if ( $query_results ) { |
|
338 | 338 | self::clear_form_cache(); |
339 | - } |
|
339 | + } |
|
340 | 340 | |
341 | - return $query_results; |
|
342 | - } |
|
341 | + return $query_results; |
|
342 | + } |
|
343 | 343 | |
344 | - /** |
|
345 | - * @return int|boolean |
|
346 | - */ |
|
344 | + /** |
|
345 | + * @return int|boolean |
|
346 | + */ |
|
347 | 347 | public static function destroy( $id ) { |
348 | - global $wpdb; |
|
348 | + global $wpdb; |
|
349 | 349 | |
350 | - $form = self::getOne($id); |
|
351 | - if ( ! $form ) { |
|
352 | - return false; |
|
353 | - } |
|
350 | + $form = self::getOne($id); |
|
351 | + if ( ! $form ) { |
|
352 | + return false; |
|
353 | + } |
|
354 | 354 | |
355 | - // Disconnect the entries from this form |
|
355 | + // Disconnect the entries from this form |
|
356 | 356 | $entries = FrmDb::get_col( $wpdb->prefix . 'frm_items', array( 'form_id' => $id ) ); |
357 | - foreach ( $entries as $entry_id ) { |
|
358 | - FrmEntry::destroy($entry_id); |
|
359 | - unset($entry_id); |
|
360 | - } |
|
357 | + foreach ( $entries as $entry_id ) { |
|
358 | + FrmEntry::destroy($entry_id); |
|
359 | + unset($entry_id); |
|
360 | + } |
|
361 | 361 | |
362 | - // Disconnect the fields from this form |
|
362 | + // Disconnect the fields from this form |
|
363 | 363 | $wpdb->query( $wpdb->prepare( 'DELETE fi FROM ' . $wpdb->prefix . 'frm_fields AS fi LEFT JOIN ' . $wpdb->prefix . 'frm_forms fr ON (fi.form_id = fr.id) WHERE fi.form_id=%d OR parent_form_id=%d', $id, $id ) ); |
364 | 364 | |
365 | 365 | $query_results = $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_forms WHERE id=%d OR parent_form_id=%d', $id, $id ) ); |
366 | - if ( $query_results ) { |
|
367 | - // Delete all form actions linked to this form |
|
368 | - $action_control = FrmFormActionsController::get_form_actions( 'email' ); |
|
369 | - $action_control->destroy($id, 'all'); |
|
366 | + if ( $query_results ) { |
|
367 | + // Delete all form actions linked to this form |
|
368 | + $action_control = FrmFormActionsController::get_form_actions( 'email' ); |
|
369 | + $action_control->destroy($id, 'all'); |
|
370 | 370 | |
371 | 371 | // Clear form caching |
372 | 372 | self::clear_form_cache(); |
373 | 373 | |
374 | 374 | do_action( 'frm_destroy_form', $id ); |
375 | 375 | do_action( 'frm_destroy_form_' . $id ); |
376 | - } |
|
376 | + } |
|
377 | 377 | |
378 | - return $query_results; |
|
379 | - } |
|
378 | + return $query_results; |
|
379 | + } |
|
380 | 380 | |
381 | 381 | /** |
382 | 382 | * Delete trashed forms based on how long they have been trashed |
@@ -408,49 +408,49 @@ discard block |
||
408 | 408 | return $count; |
409 | 409 | } |
410 | 410 | |
411 | - /** |
|
412 | - * @return string form name |
|
413 | - */ |
|
414 | - public static function &getName( $id ) { |
|
415 | - global $wpdb; |
|
416 | - |
|
417 | - $form = FrmAppHelper::check_cache($id, 'frm_form'); |
|
418 | - if ( $form ) { |
|
419 | - $r = stripslashes($form->name); |
|
420 | - return $r; |
|
421 | - } |
|
422 | - |
|
423 | - $query_key = is_numeric( $id ) ? 'id' : 'form_key'; |
|
424 | - $r = FrmDb::get_var( 'frm_forms', array( $query_key => $id ), 'name' ); |
|
425 | - $r = stripslashes($r); |
|
426 | - |
|
427 | - return $r; |
|
428 | - } |
|
429 | - |
|
430 | - /** |
|
431 | - * @param string $key |
|
432 | - * @return int form id |
|
433 | - */ |
|
411 | + /** |
|
412 | + * @return string form name |
|
413 | + */ |
|
414 | + public static function &getName( $id ) { |
|
415 | + global $wpdb; |
|
416 | + |
|
417 | + $form = FrmAppHelper::check_cache($id, 'frm_form'); |
|
418 | + if ( $form ) { |
|
419 | + $r = stripslashes($form->name); |
|
420 | + return $r; |
|
421 | + } |
|
422 | + |
|
423 | + $query_key = is_numeric( $id ) ? 'id' : 'form_key'; |
|
424 | + $r = FrmDb::get_var( 'frm_forms', array( $query_key => $id ), 'name' ); |
|
425 | + $r = stripslashes($r); |
|
426 | + |
|
427 | + return $r; |
|
428 | + } |
|
429 | + |
|
430 | + /** |
|
431 | + * @param string $key |
|
432 | + * @return int form id |
|
433 | + */ |
|
434 | 434 | public static function &getIdByKey( $key ) { |
435 | - $id = FrmDb::get_var( 'frm_forms', array( 'form_key' => sanitize_title( $key ) ) ); |
|
436 | - return $id; |
|
437 | - } |
|
438 | - |
|
439 | - /** |
|
440 | - * @param int $id |
|
441 | - * @return string form key |
|
442 | - */ |
|
435 | + $id = FrmDb::get_var( 'frm_forms', array( 'form_key' => sanitize_title( $key ) ) ); |
|
436 | + return $id; |
|
437 | + } |
|
438 | + |
|
439 | + /** |
|
440 | + * @param int $id |
|
441 | + * @return string form key |
|
442 | + */ |
|
443 | 443 | public static function &getKeyById( $id ) { |
444 | - $id = (int) $id; |
|
445 | - $cache = FrmAppHelper::check_cache($id, 'frm_form'); |
|
446 | - if ( $cache ) { |
|
447 | - return $cache->form_key; |
|
448 | - } |
|
444 | + $id = (int) $id; |
|
445 | + $cache = FrmAppHelper::check_cache($id, 'frm_form'); |
|
446 | + if ( $cache ) { |
|
447 | + return $cache->form_key; |
|
448 | + } |
|
449 | 449 | |
450 | - $key = FrmDb::get_var( 'frm_forms', array( 'id' => $id ), 'form_key' ); |
|
450 | + $key = FrmDb::get_var( 'frm_forms', array( 'id' => $id ), 'form_key' ); |
|
451 | 451 | |
452 | - return $key; |
|
453 | - } |
|
452 | + return $key; |
|
453 | + } |
|
454 | 454 | |
455 | 455 | /** |
456 | 456 | * If $form is numeric, get the form object |
@@ -463,47 +463,47 @@ discard block |
||
463 | 463 | } |
464 | 464 | } |
465 | 465 | |
466 | - /** |
|
467 | - * @return object form |
|
468 | - */ |
|
469 | - public static function getOne( $id, $blog_id = false ) { |
|
470 | - global $wpdb; |
|
466 | + /** |
|
467 | + * @return object form |
|
468 | + */ |
|
469 | + public static function getOne( $id, $blog_id = false ) { |
|
470 | + global $wpdb; |
|
471 | 471 | |
472 | - if ( $blog_id && is_multisite() ) { |
|
473 | - global $wpmuBaseTablePrefix; |
|
472 | + if ( $blog_id && is_multisite() ) { |
|
473 | + global $wpmuBaseTablePrefix; |
|
474 | 474 | $prefix = $wpmuBaseTablePrefix ? $wpmuBaseTablePrefix . $blog_id . '_' : $wpdb->get_blog_prefix( $blog_id ); |
475 | 475 | |
476 | 476 | $table_name = $prefix . 'frm_forms'; |
477 | - } else { |
|
477 | + } else { |
|
478 | 478 | $table_name = $wpdb->prefix . 'frm_forms'; |
479 | - $cache = wp_cache_get($id, 'frm_form'); |
|
480 | - if ( $cache ) { |
|
481 | - if ( isset($cache->options) ) { |
|
482 | - $cache->options = maybe_unserialize($cache->options); |
|
483 | - } |
|
484 | - |
|
485 | - return stripslashes_deep($cache); |
|
486 | - } |
|
487 | - } |
|
488 | - |
|
489 | - if ( is_numeric($id) ) { |
|
490 | - $where = array( 'id' => $id ); |
|
491 | - } else { |
|
492 | - $where = array( 'form_key' => $id ); |
|
493 | - } |
|
494 | - |
|
495 | - $results = FrmDb::get_row( $table_name, $where ); |
|
496 | - |
|
497 | - if ( isset($results->options) ) { |
|
498 | - wp_cache_set($results->id, $results, 'frm_form'); |
|
499 | - $results->options = maybe_unserialize($results->options); |
|
500 | - } |
|
501 | - return stripslashes_deep($results); |
|
502 | - } |
|
503 | - |
|
504 | - /** |
|
505 | - * @return object|array of objects |
|
506 | - */ |
|
479 | + $cache = wp_cache_get($id, 'frm_form'); |
|
480 | + if ( $cache ) { |
|
481 | + if ( isset($cache->options) ) { |
|
482 | + $cache->options = maybe_unserialize($cache->options); |
|
483 | + } |
|
484 | + |
|
485 | + return stripslashes_deep($cache); |
|
486 | + } |
|
487 | + } |
|
488 | + |
|
489 | + if ( is_numeric($id) ) { |
|
490 | + $where = array( 'id' => $id ); |
|
491 | + } else { |
|
492 | + $where = array( 'form_key' => $id ); |
|
493 | + } |
|
494 | + |
|
495 | + $results = FrmDb::get_row( $table_name, $where ); |
|
496 | + |
|
497 | + if ( isset($results->options) ) { |
|
498 | + wp_cache_set($results->id, $results, 'frm_form'); |
|
499 | + $results->options = maybe_unserialize($results->options); |
|
500 | + } |
|
501 | + return stripslashes_deep($results); |
|
502 | + } |
|
503 | + |
|
504 | + /** |
|
505 | + * @return object|array of objects |
|
506 | + */ |
|
507 | 507 | public static function getAll( $where = array(), $order_by = '', $limit = '' ) { |
508 | 508 | if ( is_array( $where ) && ! empty( $where ) ) { |
509 | 509 | $results = FrmDb::get_results( 'frm_forms', $where, '*', array( 'order_by' => $order_by, 'limit' => $limit ) ); |
@@ -527,8 +527,8 @@ discard block |
||
527 | 527 | $results = reset( $results ); |
528 | 528 | } |
529 | 529 | |
530 | - return stripslashes_deep($results); |
|
531 | - } |
|
530 | + return stripslashes_deep($results); |
|
531 | + } |
|
532 | 532 | |
533 | 533 | /** |
534 | 534 | * Get all published forms |
@@ -546,47 +546,47 @@ discard block |
||
546 | 546 | return $forms; |
547 | 547 | } |
548 | 548 | |
549 | - /** |
|
550 | - * @return int count of forms |
|
551 | - */ |
|
552 | - public static function &get_count() { |
|
553 | - global $wpdb; |
|
549 | + /** |
|
550 | + * @return int count of forms |
|
551 | + */ |
|
552 | + public static function &get_count() { |
|
553 | + global $wpdb; |
|
554 | 554 | |
555 | - $cache_key = 'frm_form_counts'; |
|
555 | + $cache_key = 'frm_form_counts'; |
|
556 | 556 | |
557 | - $counts = wp_cache_get( $cache_key, 'counts' ); |
|
558 | - if ( false !== $counts ) { |
|
559 | - return $counts; |
|
560 | - } |
|
557 | + $counts = wp_cache_get( $cache_key, 'counts' ); |
|
558 | + if ( false !== $counts ) { |
|
559 | + return $counts; |
|
560 | + } |
|
561 | 561 | |
562 | - $results = (array) FrmDb::get_results( 'frm_forms', array( 'or' => 1, 'parent_form_id' => null, 'parent_form_id <' => 0 ), 'status, is_template' ); |
|
562 | + $results = (array) FrmDb::get_results( 'frm_forms', array( 'or' => 1, 'parent_form_id' => null, 'parent_form_id <' => 0 ), 'status, is_template' ); |
|
563 | 563 | |
564 | 564 | $statuses = array( 'published', 'draft', 'template', 'trash' ); |
565 | - $counts = array_fill_keys( $statuses, 0 ); |
|
565 | + $counts = array_fill_keys( $statuses, 0 ); |
|
566 | 566 | |
567 | - foreach ( $results as $row ) { |
|
568 | - if ( 'trash' != $row->status ) { |
|
569 | - if ( $row->is_template ) { |
|
567 | + foreach ( $results as $row ) { |
|
568 | + if ( 'trash' != $row->status ) { |
|
569 | + if ( $row->is_template ) { |
|
570 | 570 | $counts['template']++; |
571 | - } else { |
|
571 | + } else { |
|
572 | 572 | $counts['published']++; |
573 | - } |
|
574 | - } else { |
|
573 | + } |
|
574 | + } else { |
|
575 | 575 | $counts['trash']++; |
576 | - } |
|
576 | + } |
|
577 | 577 | |
578 | - if ( 'draft' == $row->status ) { |
|
578 | + if ( 'draft' == $row->status ) { |
|
579 | 579 | $counts['draft']++; |
580 | - } |
|
580 | + } |
|
581 | 581 | |
582 | - unset($row); |
|
583 | - } |
|
582 | + unset($row); |
|
583 | + } |
|
584 | 584 | |
585 | - $counts = (object) $counts; |
|
586 | - wp_cache_set( $cache_key, $counts, 'counts' ); |
|
585 | + $counts = (object) $counts; |
|
586 | + wp_cache_set( $cache_key, $counts, 'counts' ); |
|
587 | 587 | |
588 | - return $counts; |
|
589 | - } |
|
588 | + return $counts; |
|
589 | + } |
|
590 | 590 | |
591 | 591 | /** |
592 | 592 | * Clear form caching |
@@ -599,14 +599,14 @@ discard block |
||
599 | 599 | FrmAppHelper::cache_delete_group( 'frm_form' ); |
600 | 600 | } |
601 | 601 | |
602 | - /** |
|
603 | - * @return array of errors |
|
604 | - */ |
|
602 | + /** |
|
603 | + * @return array of errors |
|
604 | + */ |
|
605 | 605 | public static function validate( $values ) { |
606 | - $errors = array(); |
|
606 | + $errors = array(); |
|
607 | 607 | |
608 | - return apply_filters('frm_validate_form', $errors, $values); |
|
609 | - } |
|
608 | + return apply_filters('frm_validate_form', $errors, $values); |
|
609 | + } |
|
610 | 610 | |
611 | 611 | public static function get_params( $form = null ) { |
612 | 612 | global $frm_vars; |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined('ABSPATH') ) { |
|
3 | - die('You are not allowed to call this page directly.'); |
|
2 | +if ( ! defined( 'ABSPATH' ) ) { |
|
3 | + die( 'You are not allowed to call this page directly.' ); |
|
4 | 4 | } |
5 | 5 | |
6 | 6 | class FrmForm { |
@@ -15,24 +15,24 @@ discard block |
||
15 | 15 | 'form_key' => FrmAppHelper::get_unique_key( $values['form_key'], $wpdb->prefix . 'frm_forms', 'form_key' ), |
16 | 16 | 'name' => $values['name'], |
17 | 17 | 'description' => $values['description'], |
18 | - 'status' => isset($values['status']) ? $values['status'] : 'draft', |
|
19 | - 'logged_in' => isset($values['logged_in']) ? $values['logged_in'] : 0, |
|
20 | - 'is_template' => isset($values['is_template']) ? (int) $values['is_template'] : 0, |
|
18 | + 'status' => isset( $values['status'] ) ? $values['status'] : 'draft', |
|
19 | + 'logged_in' => isset( $values['logged_in'] ) ? $values['logged_in'] : 0, |
|
20 | + 'is_template' => isset( $values['is_template'] ) ? (int) $values['is_template'] : 0, |
|
21 | 21 | 'parent_form_id' => isset( $values['parent_form_id'] ) ? absint( $values['parent_form_id'] ) : 0, |
22 | - 'editable' => isset($values['editable']) ? (int) $values['editable'] : 0, |
|
23 | - 'default_template' => isset($values['default_template']) ? (int) $values['default_template'] : 0, |
|
24 | - 'created_at' => isset($values['created_at']) ? $values['created_at'] : current_time('mysql', 1), |
|
22 | + 'editable' => isset( $values['editable'] ) ? (int) $values['editable'] : 0, |
|
23 | + 'default_template' => isset( $values['default_template'] ) ? (int) $values['default_template'] : 0, |
|
24 | + 'created_at' => isset( $values['created_at'] ) ? $values['created_at'] : current_time( 'mysql', 1 ), |
|
25 | 25 | ); |
26 | 26 | |
27 | 27 | $options = array(); |
28 | 28 | FrmFormsHelper::fill_form_options( $options, $values ); |
29 | 29 | |
30 | - $options['before_html'] = isset($values['options']['before_html']) ? $values['options']['before_html'] : FrmFormsHelper::get_default_html('before'); |
|
31 | - $options['after_html'] = isset($values['options']['after_html']) ? $values['options']['after_html'] : FrmFormsHelper::get_default_html('after'); |
|
32 | - $options['submit_html'] = isset($values['options']['submit_html']) ? $values['options']['submit_html'] : FrmFormsHelper::get_default_html('submit'); |
|
30 | + $options['before_html'] = isset( $values['options']['before_html'] ) ? $values['options']['before_html'] : FrmFormsHelper::get_default_html( 'before' ); |
|
31 | + $options['after_html'] = isset( $values['options']['after_html'] ) ? $values['options']['after_html'] : FrmFormsHelper::get_default_html( 'after' ); |
|
32 | + $options['submit_html'] = isset( $values['options']['submit_html'] ) ? $values['options']['submit_html'] : FrmFormsHelper::get_default_html( 'submit' ); |
|
33 | 33 | |
34 | - $options = apply_filters('frm_form_options_before_update', $options, $values); |
|
35 | - $new_values['options'] = serialize($options); |
|
34 | + $options = apply_filters( 'frm_form_options_before_update', $options, $values ); |
|
35 | + $new_values['options'] = serialize( $options ); |
|
36 | 36 | |
37 | 37 | //if(isset($values['id']) && is_numeric($values['id'])) |
38 | 38 | // $new_values['id'] = $values['id']; |
@@ -67,22 +67,22 @@ discard block |
||
67 | 67 | 'status' => $template ? 'published' : 'draft', |
68 | 68 | 'logged_in' => $values->logged_in ? $values->logged_in : 0, |
69 | 69 | 'editable' => $values->editable ? $values->editable : 0, |
70 | - 'created_at' => current_time('mysql', 1), |
|
70 | + 'created_at' => current_time( 'mysql', 1 ), |
|
71 | 71 | 'is_template' => $template ? 1 : 0, |
72 | 72 | ); |
73 | 73 | |
74 | 74 | if ( $blog_id ) { |
75 | 75 | $new_values['status'] = 'published'; |
76 | - $new_options = maybe_unserialize($values->options); |
|
77 | - $new_options['email_to'] = get_option('admin_email'); |
|
76 | + $new_options = maybe_unserialize( $values->options ); |
|
77 | + $new_options['email_to'] = get_option( 'admin_email' ); |
|
78 | 78 | $new_options['copy'] = false; |
79 | 79 | $new_values['options'] = $new_options; |
80 | 80 | } else { |
81 | 81 | $new_values['options'] = $values->options; |
82 | 82 | } |
83 | 83 | |
84 | - if ( is_array($new_values['options']) ) { |
|
85 | - $new_values['options'] = serialize($new_values['options']); |
|
84 | + if ( is_array( $new_values['options'] ) ) { |
|
85 | + $new_values['options'] = serialize( $new_values['options'] ); |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | $query_results = $wpdb->insert( $wpdb->prefix . 'frm_forms', $new_values ); |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | self::clear_form_cache(); |
93 | 93 | |
94 | 94 | $form_id = $wpdb->insert_id; |
95 | - FrmField::duplicate($id, $form_id, $copy_keys, $blog_id); |
|
95 | + FrmField::duplicate( $id, $form_id, $copy_keys, $blog_id ); |
|
96 | 96 | |
97 | 97 | // update form settings after fields are created |
98 | 98 | do_action( 'frm_after_duplicate_form', $form_id, $new_values, array( 'old_id' => $id ) ); |
@@ -103,13 +103,13 @@ discard block |
||
103 | 103 | } |
104 | 104 | |
105 | 105 | public static function after_duplicate( $form_id, $values ) { |
106 | - $new_opts = $values['options'] = maybe_unserialize($values['options']); |
|
106 | + $new_opts = $values['options'] = maybe_unserialize( $values['options'] ); |
|
107 | 107 | |
108 | - if ( isset($new_opts['success_msg']) ) { |
|
109 | - $new_opts['success_msg'] = FrmFieldsHelper::switch_field_ids($new_opts['success_msg']); |
|
108 | + if ( isset( $new_opts['success_msg'] ) ) { |
|
109 | + $new_opts['success_msg'] = FrmFieldsHelper::switch_field_ids( $new_opts['success_msg'] ); |
|
110 | 110 | } |
111 | 111 | |
112 | - $new_opts = apply_filters('frm_after_duplicate_form_values', $new_opts, $form_id); |
|
112 | + $new_opts = apply_filters( 'frm_after_duplicate_form_values', $new_opts, $form_id ); |
|
113 | 113 | |
114 | 114 | if ( $new_opts != $values['options'] ) { |
115 | 115 | global $wpdb; |
@@ -127,17 +127,17 @@ discard block |
||
127 | 127 | $values['status'] = 'published'; |
128 | 128 | } |
129 | 129 | |
130 | - if ( isset($values['form_key']) ) { |
|
130 | + if ( isset( $values['form_key'] ) ) { |
|
131 | 131 | $values['form_key'] = FrmAppHelper::get_unique_key( $values['form_key'], $wpdb->prefix . 'frm_forms', 'form_key', $id ); |
132 | 132 | } |
133 | 133 | |
134 | 134 | $form_fields = array( 'form_key', 'name', 'description', 'status', 'parent_form_id' ); |
135 | 135 | |
136 | - $new_values = self::set_update_options( array(), $values); |
|
136 | + $new_values = self::set_update_options( array(), $values ); |
|
137 | 137 | |
138 | 138 | foreach ( $values as $value_key => $value ) { |
139 | - if ( in_array($value_key, $form_fields) ) { |
|
140 | - $new_values[ $value_key ] = $value; |
|
139 | + if ( in_array( $value_key, $form_fields ) ) { |
|
140 | + $new_values[$value_key] = $value; |
|
141 | 141 | } |
142 | 142 | } |
143 | 143 | |
@@ -153,9 +153,9 @@ discard block |
||
153 | 153 | } else { |
154 | 154 | $query_results = true; |
155 | 155 | } |
156 | - unset($new_values); |
|
156 | + unset( $new_values ); |
|
157 | 157 | |
158 | - $values = self::update_fields($id, $values); |
|
158 | + $values = self::update_fields( $id, $values ); |
|
159 | 159 | |
160 | 160 | do_action( 'frm_update_form', $id, $values ); |
161 | 161 | do_action( 'frm_update_form_' . $id, $values ); |
@@ -167,20 +167,20 @@ discard block |
||
167 | 167 | * @return array |
168 | 168 | */ |
169 | 169 | public static function set_update_options( $new_values, $values ) { |
170 | - if ( ! isset($values['options']) ) { |
|
170 | + if ( ! isset( $values['options'] ) ) { |
|
171 | 171 | return $new_values; |
172 | 172 | } |
173 | 173 | |
174 | 174 | $options = array(); |
175 | 175 | FrmFormsHelper::fill_form_options( $options, $values ); |
176 | 176 | |
177 | - $options['custom_style'] = isset($values['options']['custom_style']) ? $values['options']['custom_style'] : 0; |
|
178 | - $options['before_html'] = isset($values['options']['before_html']) ? $values['options']['before_html'] : FrmFormsHelper::get_default_html('before'); |
|
179 | - $options['after_html'] = isset($values['options']['after_html']) ? $values['options']['after_html'] : FrmFormsHelper::get_default_html('after'); |
|
180 | - $options['submit_html'] = (isset($values['options']['submit_html']) && $values['options']['submit_html'] != '') ? $values['options']['submit_html'] : FrmFormsHelper::get_default_html('submit'); |
|
177 | + $options['custom_style'] = isset( $values['options']['custom_style'] ) ? $values['options']['custom_style'] : 0; |
|
178 | + $options['before_html'] = isset( $values['options']['before_html'] ) ? $values['options']['before_html'] : FrmFormsHelper::get_default_html( 'before' ); |
|
179 | + $options['after_html'] = isset( $values['options']['after_html'] ) ? $values['options']['after_html'] : FrmFormsHelper::get_default_html( 'after' ); |
|
180 | + $options['submit_html'] = ( isset( $values['options']['submit_html'] ) && $values['options']['submit_html'] != '' ) ? $values['options']['submit_html'] : FrmFormsHelper::get_default_html( 'submit' ); |
|
181 | 181 | |
182 | - $options = apply_filters('frm_form_options_before_update', $options, $values); |
|
183 | - $new_values['options'] = serialize($options); |
|
182 | + $options = apply_filters( 'frm_form_options_before_update', $options, $values ); |
|
183 | + $new_values['options'] = serialize( $options ); |
|
184 | 184 | |
185 | 185 | return $new_values; |
186 | 186 | } |
@@ -191,57 +191,57 @@ discard block |
||
191 | 191 | */ |
192 | 192 | public static function update_fields( $id, $values ) { |
193 | 193 | |
194 | - if ( ! isset($values['options']) && ! isset($values['item_meta']) && ! isset($values['field_options']) ) { |
|
194 | + if ( ! isset( $values['options'] ) && ! isset( $values['item_meta'] ) && ! isset( $values['field_options'] ) ) { |
|
195 | 195 | return $values; |
196 | 196 | } |
197 | 197 | |
198 | - $all_fields = FrmField::get_all_for_form($id); |
|
199 | - if ( empty($all_fields) ) { |
|
198 | + $all_fields = FrmField::get_all_for_form( $id ); |
|
199 | + if ( empty( $all_fields ) ) { |
|
200 | 200 | return $values; |
201 | 201 | } |
202 | 202 | |
203 | - if ( ! isset($values['item_meta']) ) { |
|
203 | + if ( ! isset( $values['item_meta'] ) ) { |
|
204 | 204 | $values['item_meta'] = array(); |
205 | 205 | } |
206 | 206 | |
207 | 207 | $field_array = array(); |
208 | - $existing_keys = array_keys($values['item_meta']); |
|
208 | + $existing_keys = array_keys( $values['item_meta'] ); |
|
209 | 209 | foreach ( $all_fields as $fid ) { |
210 | - if ( ! in_array($fid->id, $existing_keys) && ( isset($values['frm_fields_submitted']) && in_array($fid->id, $values['frm_fields_submitted']) ) || isset($values['options']) ) { |
|
211 | - $values['item_meta'][ $fid->id ] = ''; |
|
210 | + if ( ! in_array( $fid->id, $existing_keys ) && ( isset( $values['frm_fields_submitted'] ) && in_array( $fid->id, $values['frm_fields_submitted'] ) ) || isset( $values['options'] ) ) { |
|
211 | + $values['item_meta'][$fid->id] = ''; |
|
212 | 212 | } |
213 | - $field_array[ $fid->id ] = $fid; |
|
213 | + $field_array[$fid->id] = $fid; |
|
214 | 214 | } |
215 | - unset($all_fields); |
|
215 | + unset( $all_fields ); |
|
216 | 216 | |
217 | 217 | foreach ( $values['item_meta'] as $field_id => $default_value ) { |
218 | - if ( isset( $field_array[ $field_id ] ) ) { |
|
219 | - $field = $field_array[ $field_id ]; |
|
218 | + if ( isset( $field_array[$field_id] ) ) { |
|
219 | + $field = $field_array[$field_id]; |
|
220 | 220 | } else { |
221 | - $field = FrmField::getOne($field_id); |
|
221 | + $field = FrmField::getOne( $field_id ); |
|
222 | 222 | } |
223 | 223 | |
224 | 224 | if ( ! $field ) { |
225 | 225 | continue; |
226 | 226 | } |
227 | 227 | |
228 | - if ( isset( $values['options'] ) || isset( $values['field_options'][ 'custom_html_' . $field_id ] ) ) { |
|
228 | + if ( isset( $values['options'] ) || isset( $values['field_options']['custom_html_' . $field_id] ) ) { |
|
229 | 229 | //updating the settings page |
230 | - if ( isset( $values['field_options'][ 'custom_html_' . $field_id ] ) ) { |
|
231 | - $field->field_options['custom_html'] = isset( $values['field_options'][ 'custom_html_' . $field_id ] ) ? $values['field_options'][ 'custom_html_' . $field_id ] : ( isset( $field->field_options['custom_html'] ) ? $field->field_options['custom_html'] : FrmFieldsHelper::get_default_html( $field->type ) ); |
|
232 | - $field->field_options = apply_filters('frm_update_form_field_options', $field->field_options, $field, $values); |
|
230 | + if ( isset( $values['field_options']['custom_html_' . $field_id] ) ) { |
|
231 | + $field->field_options['custom_html'] = isset( $values['field_options']['custom_html_' . $field_id] ) ? $values['field_options']['custom_html_' . $field_id] : ( isset( $field->field_options['custom_html'] ) ? $field->field_options['custom_html'] : FrmFieldsHelper::get_default_html( $field->type ) ); |
|
232 | + $field->field_options = apply_filters( 'frm_update_form_field_options', $field->field_options, $field, $values ); |
|
233 | 233 | FrmField::update( $field_id, array( 'field_options' => $field->field_options ) ); |
234 | 234 | } else if ( $field->type == 'hidden' || $field->type == 'user_id' ) { |
235 | 235 | $prev_opts = $field->field_options; |
236 | - $field->field_options = apply_filters('frm_update_form_field_options', $field->field_options, $field, $values); |
|
236 | + $field->field_options = apply_filters( 'frm_update_form_field_options', $field->field_options, $field, $values ); |
|
237 | 237 | if ( $prev_opts != $field->field_options ) { |
238 | 238 | FrmField::update( $field_id, array( 'field_options' => $field->field_options ) ); |
239 | 239 | } |
240 | - unset($prev_opts); |
|
240 | + unset( $prev_opts ); |
|
241 | 241 | } |
242 | 242 | } |
243 | 243 | |
244 | - if ( ( isset( $values['options'] ) || isset( $values['field_options'][ 'custom_html_' . $field_id ] ) ) && ! defined( 'WP_IMPORTING' ) ) { |
|
244 | + if ( ( isset( $values['options'] ) || isset( $values['field_options']['custom_html_' . $field_id] ) ) && ! defined( 'WP_IMPORTING' ) ) { |
|
245 | 245 | continue; |
246 | 246 | } |
247 | 247 | |
@@ -251,23 +251,23 @@ discard block |
||
251 | 251 | $update_options = apply_filters( 'frm_field_options_to_update', $update_options ); |
252 | 252 | |
253 | 253 | foreach ( $update_options as $opt => $default ) { |
254 | - $field->field_options[ $opt ] = isset( $values['field_options'][ $opt . '_' . $field_id ] ) ? trim( sanitize_text_field( $values['field_options'][ $opt . '_' . $field_id ] ) ) : $default; |
|
254 | + $field->field_options[$opt] = isset( $values['field_options'][$opt . '_' . $field_id] ) ? trim( sanitize_text_field( $values['field_options'][$opt . '_' . $field_id] ) ) : $default; |
|
255 | 255 | } |
256 | 256 | |
257 | - $field->field_options = apply_filters('frm_update_field_options', $field->field_options, $field, $values); |
|
258 | - $default_value = maybe_serialize( $values['item_meta'][ $field_id ] ); |
|
259 | - $field_key = isset( $values['field_options'][ 'field_key_' . $field_id ] ) ? $values['field_options'][ 'field_key_' . $field_id ] : $field->field_key; |
|
260 | - $required = isset( $values['field_options'][ 'required_' . $field_id ] ) ? $values['field_options'][ 'required_' . $field_id ] : false; |
|
261 | - $field_type = isset( $values['field_options'][ 'type_' . $field_id ] ) ? $values['field_options'][ 'type_' . $field_id ] : $field->type; |
|
262 | - $field_description = isset( $values['field_options'][ 'description_' . $field_id ] ) ? $values['field_options'][ 'description_' . $field_id ] : $field->description; |
|
257 | + $field->field_options = apply_filters( 'frm_update_field_options', $field->field_options, $field, $values ); |
|
258 | + $default_value = maybe_serialize( $values['item_meta'][$field_id] ); |
|
259 | + $field_key = isset( $values['field_options']['field_key_' . $field_id] ) ? $values['field_options']['field_key_' . $field_id] : $field->field_key; |
|
260 | + $required = isset( $values['field_options']['required_' . $field_id] ) ? $values['field_options']['required_' . $field_id] : false; |
|
261 | + $field_type = isset( $values['field_options']['type_' . $field_id] ) ? $values['field_options']['type_' . $field_id] : $field->type; |
|
262 | + $field_description = isset( $values['field_options']['description_' . $field_id] ) ? $values['field_options']['description_' . $field_id] : $field->description; |
|
263 | 263 | |
264 | - FrmField::update($field_id, array( |
|
264 | + FrmField::update( $field_id, array( |
|
265 | 265 | 'field_key' => $field_key, 'type' => $field_type, |
266 | 266 | 'default_value' => $default_value, 'field_options' => $field->field_options, |
267 | 267 | 'description' => $field_description, 'required' => $required, |
268 | 268 | ) ); |
269 | 269 | |
270 | - FrmField::delete_form_transient($field->form_id); |
|
270 | + FrmField::delete_form_transient( $field->form_id ); |
|
271 | 271 | } |
272 | 272 | |
273 | 273 | return $values; |
@@ -279,17 +279,17 @@ discard block |
||
279 | 279 | */ |
280 | 280 | public static function set_status( $id, $status ) { |
281 | 281 | if ( 'trash' == $status ) { |
282 | - return self::trash($id); |
|
282 | + return self::trash( $id ); |
|
283 | 283 | } |
284 | 284 | |
285 | - $statuses = array( 'published', 'draft', 'trash' ); |
|
285 | + $statuses = array( 'published', 'draft', 'trash' ); |
|
286 | 286 | if ( ! in_array( $status, $statuses ) ) { |
287 | 287 | return false; |
288 | 288 | } |
289 | 289 | |
290 | 290 | global $wpdb; |
291 | 291 | |
292 | - if ( is_array($id) ) { |
|
292 | + if ( is_array( $id ) ) { |
|
293 | 293 | $where = array( 'id' => $id ); |
294 | 294 | FrmDb::get_where_clause_and_values( $where ); |
295 | 295 | array_unshift( $where['values'], $status ); |
@@ -314,7 +314,7 @@ discard block |
||
314 | 314 | return self::destroy( $id ); |
315 | 315 | } |
316 | 316 | |
317 | - $form = self::getOne($id); |
|
317 | + $form = self::getOne( $id ); |
|
318 | 318 | if ( ! $form ) { |
319 | 319 | return false; |
320 | 320 | } |
@@ -342,7 +342,7 @@ discard block |
||
342 | 342 | public static function destroy( $id ) { |
343 | 343 | global $wpdb; |
344 | 344 | |
345 | - $form = self::getOne($id); |
|
345 | + $form = self::getOne( $id ); |
|
346 | 346 | if ( ! $form ) { |
347 | 347 | return false; |
348 | 348 | } |
@@ -350,8 +350,8 @@ discard block |
||
350 | 350 | // Disconnect the entries from this form |
351 | 351 | $entries = FrmDb::get_col( $wpdb->prefix . 'frm_items', array( 'form_id' => $id ) ); |
352 | 352 | foreach ( $entries as $entry_id ) { |
353 | - FrmEntry::destroy($entry_id); |
|
354 | - unset($entry_id); |
|
353 | + FrmEntry::destroy( $entry_id ); |
|
354 | + unset( $entry_id ); |
|
355 | 355 | } |
356 | 356 | |
357 | 357 | // Disconnect the fields from this form |
@@ -361,7 +361,7 @@ discard block |
||
361 | 361 | if ( $query_results ) { |
362 | 362 | // Delete all form actions linked to this form |
363 | 363 | $action_control = FrmFormActionsController::get_form_actions( 'email' ); |
364 | - $action_control->destroy($id, 'all'); |
|
364 | + $action_control->destroy( $id, 'all' ); |
|
365 | 365 | |
366 | 366 | // Clear form caching |
367 | 367 | self::clear_form_cache(); |
@@ -395,7 +395,7 @@ discard block |
||
395 | 395 | $form->options = maybe_unserialize( $form->options ); |
396 | 396 | if ( ! isset( $form->options['trash_time'] ) || $form->options['trash_time'] < $delete_timestamp ) { |
397 | 397 | self::destroy( $form->id ); |
398 | - $count++; |
|
398 | + $count ++; |
|
399 | 399 | } |
400 | 400 | |
401 | 401 | unset( $form ); |
@@ -409,15 +409,15 @@ discard block |
||
409 | 409 | public static function &getName( $id ) { |
410 | 410 | global $wpdb; |
411 | 411 | |
412 | - $form = FrmAppHelper::check_cache($id, 'frm_form'); |
|
412 | + $form = FrmAppHelper::check_cache( $id, 'frm_form' ); |
|
413 | 413 | if ( $form ) { |
414 | - $r = stripslashes($form->name); |
|
414 | + $r = stripslashes( $form->name ); |
|
415 | 415 | return $r; |
416 | 416 | } |
417 | 417 | |
418 | 418 | $query_key = is_numeric( $id ) ? 'id' : 'form_key'; |
419 | 419 | $r = FrmDb::get_var( 'frm_forms', array( $query_key => $id ), 'name' ); |
420 | - $r = stripslashes($r); |
|
420 | + $r = stripslashes( $r ); |
|
421 | 421 | |
422 | 422 | return $r; |
423 | 423 | } |
@@ -437,7 +437,7 @@ discard block |
||
437 | 437 | */ |
438 | 438 | public static function &getKeyById( $id ) { |
439 | 439 | $id = (int) $id; |
440 | - $cache = FrmAppHelper::check_cache($id, 'frm_form'); |
|
440 | + $cache = FrmAppHelper::check_cache( $id, 'frm_form' ); |
|
441 | 441 | if ( $cache ) { |
442 | 442 | return $cache->form_key; |
443 | 443 | } |
@@ -471,17 +471,17 @@ discard block |
||
471 | 471 | $table_name = $prefix . 'frm_forms'; |
472 | 472 | } else { |
473 | 473 | $table_name = $wpdb->prefix . 'frm_forms'; |
474 | - $cache = wp_cache_get($id, 'frm_form'); |
|
474 | + $cache = wp_cache_get( $id, 'frm_form' ); |
|
475 | 475 | if ( $cache ) { |
476 | - if ( isset($cache->options) ) { |
|
477 | - $cache->options = maybe_unserialize($cache->options); |
|
476 | + if ( isset( $cache->options ) ) { |
|
477 | + $cache->options = maybe_unserialize( $cache->options ); |
|
478 | 478 | } |
479 | 479 | |
480 | - return stripslashes_deep($cache); |
|
480 | + return stripslashes_deep( $cache ); |
|
481 | 481 | } |
482 | 482 | } |
483 | 483 | |
484 | - if ( is_numeric($id) ) { |
|
484 | + if ( is_numeric( $id ) ) { |
|
485 | 485 | $where = array( 'id' => $id ); |
486 | 486 | } else { |
487 | 487 | $where = array( 'form_key' => $id ); |
@@ -489,11 +489,11 @@ discard block |
||
489 | 489 | |
490 | 490 | $results = FrmDb::get_row( $table_name, $where ); |
491 | 491 | |
492 | - if ( isset($results->options) ) { |
|
493 | - wp_cache_set($results->id, $results, 'frm_form'); |
|
494 | - $results->options = maybe_unserialize($results->options); |
|
492 | + if ( isset( $results->options ) ) { |
|
493 | + wp_cache_set( $results->id, $results, 'frm_form' ); |
|
494 | + $results->options = maybe_unserialize( $results->options ); |
|
495 | 495 | } |
496 | - return stripslashes_deep($results); |
|
496 | + return stripslashes_deep( $results ); |
|
497 | 497 | } |
498 | 498 | |
499 | 499 | /** |
@@ -522,7 +522,7 @@ discard block |
||
522 | 522 | $results = reset( $results ); |
523 | 523 | } |
524 | 524 | |
525 | - return stripslashes_deep($results); |
|
525 | + return stripslashes_deep( $results ); |
|
526 | 526 | } |
527 | 527 | |
528 | 528 | /** |
@@ -562,19 +562,19 @@ discard block |
||
562 | 562 | foreach ( $results as $row ) { |
563 | 563 | if ( 'trash' != $row->status ) { |
564 | 564 | if ( $row->is_template ) { |
565 | - $counts['template']++; |
|
565 | + $counts['template'] ++; |
|
566 | 566 | } else { |
567 | - $counts['published']++; |
|
567 | + $counts['published'] ++; |
|
568 | 568 | } |
569 | 569 | } else { |
570 | - $counts['trash']++; |
|
570 | + $counts['trash'] ++; |
|
571 | 571 | } |
572 | 572 | |
573 | 573 | if ( 'draft' == $row->status ) { |
574 | - $counts['draft']++; |
|
574 | + $counts['draft'] ++; |
|
575 | 575 | } |
576 | 576 | |
577 | - unset($row); |
|
577 | + unset( $row ); |
|
578 | 578 | } |
579 | 579 | |
580 | 580 | $counts = (object) $counts; |
@@ -600,7 +600,7 @@ discard block |
||
600 | 600 | public static function validate( $values ) { |
601 | 601 | $errors = array(); |
602 | 602 | |
603 | - return apply_filters('frm_validate_form', $errors, $values); |
|
603 | + return apply_filters( 'frm_validate_form', $errors, $values ); |
|
604 | 604 | } |
605 | 605 | |
606 | 606 | public static function get_params( $form = null ) { |
@@ -612,11 +612,11 @@ discard block |
||
612 | 612 | self::maybe_get_form( $form ); |
613 | 613 | } |
614 | 614 | |
615 | - if ( isset( $frm_vars['form_params'] ) && is_array( $frm_vars['form_params'] ) && isset( $frm_vars['form_params'][ $form->id ] ) ) { |
|
616 | - return $frm_vars['form_params'][ $form->id ]; |
|
615 | + if ( isset( $frm_vars['form_params'] ) && is_array( $frm_vars['form_params'] ) && isset( $frm_vars['form_params'][$form->id] ) ) { |
|
616 | + return $frm_vars['form_params'][$form->id]; |
|
617 | 617 | } |
618 | 618 | |
619 | - $action_var = isset($_REQUEST['frm_action']) ? 'frm_action' : 'action'; |
|
619 | + $action_var = isset( $_REQUEST['frm_action'] ) ? 'frm_action' : 'action'; |
|
620 | 620 | $action = apply_filters( 'frm_show_new_entry_page', FrmAppHelper::get_param( $action_var, 'new', 'get', 'sanitize_title' ), $form ); |
621 | 621 | |
622 | 622 | $default_values = array( |
@@ -634,15 +634,15 @@ discard block |
||
634 | 634 | //if there are two forms on the same page, make sure not to submit both |
635 | 635 | foreach ( $default_values as $var => $default ) { |
636 | 636 | if ( $var == 'action' ) { |
637 | - $values[ $var ] = FrmAppHelper::get_param( $action_var, $default, 'get', 'sanitize_title' ); |
|
637 | + $values[$var] = FrmAppHelper::get_param( $action_var, $default, 'get', 'sanitize_title' ); |
|
638 | 638 | } else { |
639 | - $values[ $var ] = FrmAppHelper::get_param( $var, $default ); |
|
639 | + $values[$var] = FrmAppHelper::get_param( $var, $default ); |
|
640 | 640 | } |
641 | 641 | unset( $var, $default ); |
642 | 642 | } |
643 | 643 | } else { |
644 | 644 | foreach ( $default_values as $var => $default ) { |
645 | - $values[ $var ] = $default; |
|
645 | + $values[$var] = $default; |
|
646 | 646 | unset( $var, $default ); |
647 | 647 | } |
648 | 648 | } |
@@ -657,7 +657,7 @@ discard block |
||
657 | 657 | public static function list_page_params() { |
658 | 658 | $values = array(); |
659 | 659 | foreach ( array( 'template' => 0, 'id' => '', 'paged' => 1, 'form' => '', 'search' => '', 'sort' => '', 'sdir' => '' ) as $var => $default ) { |
660 | - $values[ $var ] = FrmAppHelper::get_param( $var, $default ); |
|
660 | + $values[$var] = FrmAppHelper::get_param( $var, $default ); |
|
661 | 661 | } |
662 | 662 | |
663 | 663 | return $values; |
@@ -677,7 +677,7 @@ discard block |
||
677 | 677 | 'field_id' => '', 'search' => '', 'sort' => '', 'sdir' => '', 'fid' => '', |
678 | 678 | 'keep_post' => '', |
679 | 679 | ) as $var => $default ) { |
680 | - $values[ $var ] = FrmAppHelper::get_param( $var, $default ); |
|
680 | + $values[$var] = FrmAppHelper::get_param( $var, $default ); |
|
681 | 681 | } |
682 | 682 | |
683 | 683 | return $values; |
@@ -719,16 +719,16 @@ discard block |
||
719 | 719 | $small_form = new stdClass(); |
720 | 720 | foreach ( array( 'id', 'form_key', 'name' ) as $var ) { |
721 | 721 | $small_form->{$var} = $form->{$var}; |
722 | - unset($var); |
|
722 | + unset( $var ); |
|
723 | 723 | } |
724 | 724 | |
725 | 725 | $frm_vars['forms_loaded'][] = $small_form; |
726 | 726 | |
727 | - if ( $this_load && empty($global_load) ) { |
|
727 | + if ( $this_load && empty( $global_load ) ) { |
|
728 | 728 | $global_load = $frm_vars['load_css'] = true; |
729 | 729 | } |
730 | 730 | |
731 | - return ( ( ! isset($frm_vars['css_loaded']) || ! $frm_vars['css_loaded'] ) && $global_load ); |
|
731 | + return ( ( ! isset( $frm_vars['css_loaded'] ) || ! $frm_vars['css_loaded'] ) && $global_load ); |
|
732 | 732 | } |
733 | 733 | |
734 | 734 | public static function show_submit( $form ) { |
@@ -6,11 +6,11 @@ discard block |
||
6 | 6 | class FrmEntry { |
7 | 7 | |
8 | 8 | /** |
9 | - * Create a new entry |
|
10 | - * |
|
11 | - * @param array $values |
|
12 | - * @return int | boolean $entry_id |
|
13 | - */ |
|
9 | + * Create a new entry |
|
10 | + * |
|
11 | + * @param array $values |
|
12 | + * @return int | boolean $entry_id |
|
13 | + */ |
|
14 | 14 | public static function create( $values ) { |
15 | 15 | $entry_id = self::create_entry( $values, 'standard' ); |
16 | 16 | |
@@ -18,12 +18,12 @@ discard block |
||
18 | 18 | } |
19 | 19 | |
20 | 20 | /** |
21 | - * Create a new entry with some differences depending on type |
|
22 | - * |
|
23 | - * @param array $values |
|
24 | - * @param string $type |
|
25 | - * @return int | boolean $entry_id |
|
26 | - */ |
|
21 | + * Create a new entry with some differences depending on type |
|
22 | + * |
|
23 | + * @param array $values |
|
24 | + * @param string $type |
|
25 | + * @return int | boolean $entry_id |
|
26 | + */ |
|
27 | 27 | private static function create_entry( $values, $type ) { |
28 | 28 | $new_values = self::before_insert_entry_in_database( $values, $type ); |
29 | 29 | |
@@ -37,10 +37,10 @@ discard block |
||
37 | 37 | return $entry_id; |
38 | 38 | } |
39 | 39 | |
40 | - /** |
|
41 | - * check for duplicate entries created in the last minute |
|
42 | - * @return boolean |
|
43 | - */ |
|
40 | + /** |
|
41 | + * check for duplicate entries created in the last minute |
|
42 | + * @return boolean |
|
43 | + */ |
|
44 | 44 | public static function is_duplicate( $new_values, $values ) { |
45 | 45 | $duplicate_entry_time = 60; |
46 | 46 | |
@@ -48,55 +48,55 @@ discard block |
||
48 | 48 | return false; |
49 | 49 | } |
50 | 50 | |
51 | - $check_val = $new_values; |
|
51 | + $check_val = $new_values; |
|
52 | 52 | $check_val['created_at >'] = date( 'Y-m-d H:i:s', ( strtotime( $new_values['created_at'] ) - absint( $duplicate_entry_time ) ) ); |
53 | 53 | |
54 | 54 | unset( $check_val['created_at'], $check_val['updated_at'] ); |
55 | 55 | unset( $check_val['is_draft'], $check_val['id'], $check_val['item_key'] ); |
56 | 56 | |
57 | - if ( $new_values['item_key'] == $new_values['name'] ) { |
|
58 | - unset($check_val['name']); |
|
59 | - } |
|
57 | + if ( $new_values['item_key'] == $new_values['name'] ) { |
|
58 | + unset($check_val['name']); |
|
59 | + } |
|
60 | 60 | |
61 | - global $wpdb; |
|
61 | + global $wpdb; |
|
62 | 62 | $entry_exists = FrmDb::get_col( $wpdb->prefix . 'frm_items', $check_val, 'id', array( 'order_by' => 'created_at DESC' ) ); |
63 | 63 | |
64 | - if ( ! $entry_exists || empty($entry_exists) || ! isset($values['item_meta']) ) { |
|
65 | - return false; |
|
66 | - } |
|
64 | + if ( ! $entry_exists || empty($entry_exists) || ! isset($values['item_meta']) ) { |
|
65 | + return false; |
|
66 | + } |
|
67 | 67 | |
68 | - $is_duplicate = false; |
|
69 | - foreach ( $entry_exists as $entry_exist ) { |
|
70 | - $is_duplicate = true; |
|
68 | + $is_duplicate = false; |
|
69 | + foreach ( $entry_exists as $entry_exist ) { |
|
70 | + $is_duplicate = true; |
|
71 | 71 | |
72 | - //add more checks here to make sure it's a duplicate |
|
73 | - $metas = FrmEntryMeta::get_entry_meta_info($entry_exist); |
|
74 | - $field_metas = array(); |
|
75 | - foreach ( $metas as $meta ) { |
|
72 | + //add more checks here to make sure it's a duplicate |
|
73 | + $metas = FrmEntryMeta::get_entry_meta_info($entry_exist); |
|
74 | + $field_metas = array(); |
|
75 | + foreach ( $metas as $meta ) { |
|
76 | 76 | $field_metas[ $meta->field_id ] = $meta->meta_value; |
77 | - } |
|
78 | - |
|
79 | - // If prev entry is empty and current entry is not, they are not duplicates |
|
80 | - $filtered_vals = array_filter( $values['item_meta'] ); |
|
81 | - if ( empty( $field_metas ) && ! empty( $filtered_vals ) ) { |
|
82 | - return false; |
|
83 | - } |
|
84 | - |
|
85 | - $diff = array_diff_assoc($field_metas, array_map('maybe_serialize', $values['item_meta'])); |
|
86 | - foreach ( $diff as $field_id => $meta_value ) { |
|
87 | - if ( ! empty($meta_value) ) { |
|
88 | - $is_duplicate = false; |
|
89 | - continue; |
|
90 | - } |
|
91 | - } |
|
92 | - |
|
93 | - if ( $is_duplicate ) { |
|
77 | + } |
|
78 | + |
|
79 | + // If prev entry is empty and current entry is not, they are not duplicates |
|
80 | + $filtered_vals = array_filter( $values['item_meta'] ); |
|
81 | + if ( empty( $field_metas ) && ! empty( $filtered_vals ) ) { |
|
82 | + return false; |
|
83 | + } |
|
84 | + |
|
85 | + $diff = array_diff_assoc($field_metas, array_map('maybe_serialize', $values['item_meta'])); |
|
86 | + foreach ( $diff as $field_id => $meta_value ) { |
|
87 | + if ( ! empty($meta_value) ) { |
|
88 | + $is_duplicate = false; |
|
89 | + continue; |
|
90 | + } |
|
91 | + } |
|
92 | + |
|
93 | + if ( $is_duplicate ) { |
|
94 | 94 | break; |
95 | - } |
|
96 | - } |
|
95 | + } |
|
96 | + } |
|
97 | 97 | |
98 | - return $is_duplicate; |
|
99 | - } |
|
98 | + return $is_duplicate; |
|
99 | + } |
|
100 | 100 | |
101 | 101 | /** |
102 | 102 | * Determine if an entry needs to be checked as a possible duplicate |
@@ -127,46 +127,46 @@ discard block |
||
127 | 127 | return true; |
128 | 128 | } |
129 | 129 | |
130 | - public static function duplicate( $id ) { |
|
131 | - global $wpdb; |
|
130 | + public static function duplicate( $id ) { |
|
131 | + global $wpdb; |
|
132 | 132 | |
133 | - $values = self::getOne( $id ); |
|
133 | + $values = self::getOne( $id ); |
|
134 | 134 | |
135 | - $new_values = array(); |
|
135 | + $new_values = array(); |
|
136 | 136 | $new_values['item_key'] = FrmAppHelper::get_unique_key( '', $wpdb->prefix . 'frm_items', 'item_key' ); |
137 | - $new_values['name'] = $values->name; |
|
138 | - $new_values['is_draft'] = $values->is_draft; |
|
139 | - $new_values['user_id'] = $new_values['updated_by'] = (int) $values->user_id; |
|
140 | - $new_values['form_id'] = $values->form_id ? (int) $values->form_id: null; |
|
141 | - $new_values['created_at'] = $new_values['updated_at'] = current_time('mysql', 1); |
|
137 | + $new_values['name'] = $values->name; |
|
138 | + $new_values['is_draft'] = $values->is_draft; |
|
139 | + $new_values['user_id'] = $new_values['updated_by'] = (int) $values->user_id; |
|
140 | + $new_values['form_id'] = $values->form_id ? (int) $values->form_id: null; |
|
141 | + $new_values['created_at'] = $new_values['updated_at'] = current_time('mysql', 1); |
|
142 | 142 | |
143 | 143 | $query_results = $wpdb->insert( $wpdb->prefix . 'frm_items', $new_values ); |
144 | - if ( ! $query_results ) { |
|
145 | - return false; |
|
146 | - } |
|
144 | + if ( ! $query_results ) { |
|
145 | + return false; |
|
146 | + } |
|
147 | 147 | |
148 | - $entry_id = $wpdb->insert_id; |
|
148 | + $entry_id = $wpdb->insert_id; |
|
149 | 149 | |
150 | - global $frm_vars; |
|
151 | - if ( ! isset($frm_vars['saved_entries']) ) { |
|
152 | - $frm_vars['saved_entries'] = array(); |
|
153 | - } |
|
154 | - $frm_vars['saved_entries'][] = (int) $entry_id; |
|
150 | + global $frm_vars; |
|
151 | + if ( ! isset($frm_vars['saved_entries']) ) { |
|
152 | + $frm_vars['saved_entries'] = array(); |
|
153 | + } |
|
154 | + $frm_vars['saved_entries'][] = (int) $entry_id; |
|
155 | 155 | |
156 | - FrmEntryMeta::duplicate_entry_metas($id, $entry_id); |
|
156 | + FrmEntryMeta::duplicate_entry_metas($id, $entry_id); |
|
157 | 157 | self::clear_cache(); |
158 | 158 | |
159 | 159 | do_action( 'frm_after_duplicate_entry', $entry_id, $new_values['form_id'], array( 'old_id' => $id ) ); |
160 | - return $entry_id; |
|
161 | - } |
|
160 | + return $entry_id; |
|
161 | + } |
|
162 | 162 | |
163 | 163 | /** |
164 | - * Update an entry (not via XML) |
|
165 | - * |
|
166 | - * @param int $id |
|
167 | - * @param array $values |
|
168 | - * @return boolean|int $update_results |
|
169 | - */ |
|
164 | + * Update an entry (not via XML) |
|
165 | + * |
|
166 | + * @param int $id |
|
167 | + * @param array $values |
|
168 | + * @return boolean|int $update_results |
|
169 | + */ |
|
170 | 170 | public static function update( $id, $values ) { |
171 | 171 | $update_results = self::update_entry( $id, $values, 'standard' ); |
172 | 172 | |
@@ -174,14 +174,14 @@ discard block |
||
174 | 174 | } |
175 | 175 | |
176 | 176 | /** |
177 | - * Update an entry with some differences depending on the update type |
|
178 | - * |
|
179 | - * @since 2.0.16 |
|
180 | - * |
|
181 | - * @param int $id |
|
182 | - * @param array $values |
|
183 | - * @return boolean|int $query_results |
|
184 | - */ |
|
177 | + * Update an entry with some differences depending on the update type |
|
178 | + * |
|
179 | + * @since 2.0.16 |
|
180 | + * |
|
181 | + * @param int $id |
|
182 | + * @param array $values |
|
183 | + * @return boolean|int $query_results |
|
184 | + */ |
|
185 | 185 | private static function update_entry( $id, $values, $update_type ) { |
186 | 186 | global $wpdb; |
187 | 187 | |
@@ -200,34 +200,34 @@ discard block |
||
200 | 200 | } |
201 | 201 | |
202 | 202 | public static function &destroy( $id ) { |
203 | - global $wpdb; |
|
204 | - $id = (int) $id; |
|
203 | + global $wpdb; |
|
204 | + $id = (int) $id; |
|
205 | 205 | |
206 | 206 | $entry = self::getOne( $id ); |
207 | - if ( ! $entry ) { |
|
208 | - $result = false; |
|
209 | - return $result; |
|
210 | - } |
|
207 | + if ( ! $entry ) { |
|
208 | + $result = false; |
|
209 | + return $result; |
|
210 | + } |
|
211 | 211 | |
212 | - do_action('frm_before_destroy_entry', $id, $entry); |
|
212 | + do_action('frm_before_destroy_entry', $id, $entry); |
|
213 | 213 | |
214 | 214 | $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_item_metas WHERE item_id=%d', $id ) ); |
215 | 215 | $result = $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_items WHERE id=%d', $id ) ); |
216 | 216 | |
217 | 217 | self::clear_cache(); |
218 | 218 | |
219 | - return $result; |
|
220 | - } |
|
219 | + return $result; |
|
220 | + } |
|
221 | 221 | |
222 | 222 | public static function &update_form( $id, $value, $form_id ) { |
223 | - global $wpdb; |
|
224 | - $form_id = isset($value) ? $form_id : null; |
|
223 | + global $wpdb; |
|
224 | + $form_id = isset($value) ? $form_id : null; |
|
225 | 225 | $result = $wpdb->update( $wpdb->prefix . 'frm_items', array( 'form_id' => $form_id ), array( 'id' => $id ) ); |
226 | 226 | if ( $result ) { |
227 | 227 | self::clear_cache(); |
228 | 228 | } |
229 | - return $result; |
|
230 | - } |
|
229 | + return $result; |
|
230 | + } |
|
231 | 231 | |
232 | 232 | /** |
233 | 233 | * Clear entry caching |
@@ -263,161 +263,161 @@ discard block |
||
263 | 263 | } |
264 | 264 | |
265 | 265 | public static function getOne( $id, $meta = false ) { |
266 | - global $wpdb; |
|
266 | + global $wpdb; |
|
267 | 267 | |
268 | - $query = "SELECT it.*, fr.name as form_name, fr.form_key as form_key FROM {$wpdb->prefix}frm_items it |
|
268 | + $query = "SELECT it.*, fr.name as form_name, fr.form_key as form_key FROM {$wpdb->prefix}frm_items it |
|
269 | 269 | LEFT OUTER JOIN {$wpdb->prefix}frm_forms fr ON it.form_id=fr.id WHERE "; |
270 | 270 | |
271 | - $query .= is_numeric($id) ? 'it.id=%d' : 'it.item_key=%s'; |
|
272 | - $query_args = array( $id ); |
|
273 | - $query = $wpdb->prepare( $query, $query_args ); |
|
271 | + $query .= is_numeric($id) ? 'it.id=%d' : 'it.item_key=%s'; |
|
272 | + $query_args = array( $id ); |
|
273 | + $query = $wpdb->prepare( $query, $query_args ); |
|
274 | 274 | |
275 | - if ( ! $meta ) { |
|
275 | + if ( ! $meta ) { |
|
276 | 276 | $entry = FrmAppHelper::check_cache( $id . '_nometa', 'frm_entry', $query, 'get_row' ); |
277 | - return stripslashes_deep($entry); |
|
278 | - } |
|
277 | + return stripslashes_deep($entry); |
|
278 | + } |
|
279 | 279 | |
280 | - $entry = FrmAppHelper::check_cache( $id, 'frm_entry' ); |
|
281 | - if ( $entry !== false ) { |
|
282 | - return stripslashes_deep($entry); |
|
283 | - } |
|
280 | + $entry = FrmAppHelper::check_cache( $id, 'frm_entry' ); |
|
281 | + if ( $entry !== false ) { |
|
282 | + return stripslashes_deep($entry); |
|
283 | + } |
|
284 | 284 | |
285 | - $entry = $wpdb->get_row( $query ); |
|
286 | - $entry = self::get_meta($entry); |
|
285 | + $entry = $wpdb->get_row( $query ); |
|
286 | + $entry = self::get_meta($entry); |
|
287 | 287 | |
288 | - return stripslashes_deep($entry); |
|
289 | - } |
|
288 | + return stripslashes_deep($entry); |
|
289 | + } |
|
290 | 290 | |
291 | 291 | public static function get_meta( $entry ) { |
292 | - if ( ! $entry ) { |
|
293 | - return $entry; |
|
294 | - } |
|
292 | + if ( ! $entry ) { |
|
293 | + return $entry; |
|
294 | + } |
|
295 | 295 | |
296 | - global $wpdb; |
|
296 | + global $wpdb; |
|
297 | 297 | $metas = FrmDb::get_results( $wpdb->prefix . 'frm_item_metas m LEFT JOIN ' . $wpdb->prefix . 'frm_fields f ON m.field_id=f.id', array( 'item_id' => $entry->id, 'field_id !' => 0 ), 'field_id, meta_value, field_key, item_id' ); |
298 | 298 | |
299 | - $entry->metas = array(); |
|
299 | + $entry->metas = array(); |
|
300 | 300 | |
301 | 301 | $include_key = apply_filters( 'frm_include_meta_keys', false ); |
302 | - foreach ( $metas as $meta_val ) { |
|
303 | - if ( $meta_val->item_id == $entry->id ) { |
|
302 | + foreach ( $metas as $meta_val ) { |
|
303 | + if ( $meta_val->item_id == $entry->id ) { |
|
304 | 304 | $entry->metas[ $meta_val->field_id ] = maybe_unserialize( $meta_val->meta_value ); |
305 | 305 | if ( $include_key ) { |
306 | 306 | $entry->metas[ $meta_val->field_key ] = $entry->metas[ $meta_val->field_id ]; |
307 | 307 | } |
308 | - continue; |
|
309 | - } |
|
308 | + continue; |
|
309 | + } |
|
310 | 310 | |
311 | - // include sub entries in an array |
|
311 | + // include sub entries in an array |
|
312 | 312 | if ( ! isset( $entry_metas[ $meta_val->field_id ] ) ) { |
313 | 313 | $entry->metas[ $meta_val->field_id ] = array(); |
314 | - } |
|
314 | + } |
|
315 | 315 | |
316 | 316 | $entry->metas[ $meta_val->field_id ][] = maybe_unserialize( $meta_val->meta_value ); |
317 | 317 | |
318 | - unset($meta_val); |
|
319 | - } |
|
320 | - unset($metas); |
|
318 | + unset($meta_val); |
|
319 | + } |
|
320 | + unset($metas); |
|
321 | 321 | |
322 | - wp_cache_set( $entry->id, $entry, 'frm_entry'); |
|
322 | + wp_cache_set( $entry->id, $entry, 'frm_entry'); |
|
323 | 323 | |
324 | - return $entry; |
|
325 | - } |
|
324 | + return $entry; |
|
325 | + } |
|
326 | 326 | |
327 | - /** |
|
328 | - * @param string $id |
|
329 | - */ |
|
327 | + /** |
|
328 | + * @param string $id |
|
329 | + */ |
|
330 | 330 | public static function &exists( $id ) { |
331 | - global $wpdb; |
|
332 | - |
|
333 | - if ( FrmAppHelper::check_cache( $id, 'frm_entry' ) ) { |
|
334 | - $exists = true; |
|
335 | - return $exists; |
|
336 | - } |
|
337 | - |
|
338 | - if ( is_numeric($id) ) { |
|
339 | - $where = array( 'id' => $id ); |
|
340 | - } else { |
|
341 | - $where = array( 'item_key' => $id ); |
|
342 | - } |
|
331 | + global $wpdb; |
|
332 | + |
|
333 | + if ( FrmAppHelper::check_cache( $id, 'frm_entry' ) ) { |
|
334 | + $exists = true; |
|
335 | + return $exists; |
|
336 | + } |
|
337 | + |
|
338 | + if ( is_numeric($id) ) { |
|
339 | + $where = array( 'id' => $id ); |
|
340 | + } else { |
|
341 | + $where = array( 'item_key' => $id ); |
|
342 | + } |
|
343 | 343 | $id = FrmDb::get_var( $wpdb->prefix . 'frm_items', $where ); |
344 | 344 | |
345 | - $exists = ($id && $id > 0) ? true : false; |
|
346 | - return $exists; |
|
347 | - } |
|
345 | + $exists = ($id && $id > 0) ? true : false; |
|
346 | + return $exists; |
|
347 | + } |
|
348 | 348 | |
349 | - public static function getAll( $where, $order_by = '', $limit = '', $meta = false, $inc_form = true ) { |
|
349 | + public static function getAll( $where, $order_by = '', $limit = '', $meta = false, $inc_form = true ) { |
|
350 | 350 | global $wpdb; |
351 | 351 | |
352 | - $limit = FrmAppHelper::esc_limit($limit); |
|
352 | + $limit = FrmAppHelper::esc_limit($limit); |
|
353 | 353 | |
354 | - $cache_key = maybe_serialize($where) . $order_by . $limit . $inc_form; |
|
355 | - $entries = wp_cache_get($cache_key, 'frm_entry'); |
|
354 | + $cache_key = maybe_serialize($where) . $order_by . $limit . $inc_form; |
|
355 | + $entries = wp_cache_get($cache_key, 'frm_entry'); |
|
356 | 356 | |
357 | - if ( false === $entries ) { |
|
358 | - $fields = 'it.id, it.item_key, it.name, it.ip, it.form_id, it.post_id, it.user_id, it.parent_item_id, it.updated_by, it.created_at, it.updated_at, it.is_draft'; |
|
357 | + if ( false === $entries ) { |
|
358 | + $fields = 'it.id, it.item_key, it.name, it.ip, it.form_id, it.post_id, it.user_id, it.parent_item_id, it.updated_by, it.created_at, it.updated_at, it.is_draft'; |
|
359 | 359 | $table = $wpdb->prefix . 'frm_items it '; |
360 | 360 | |
361 | - if ( $inc_form ) { |
|
362 | - $fields = 'it.*, fr.name as form_name,fr.form_key as form_key'; |
|
363 | - $table .= 'LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_forms fr ON it.form_id=fr.id '; |
|
364 | - } |
|
361 | + if ( $inc_form ) { |
|
362 | + $fields = 'it.*, fr.name as form_name,fr.form_key as form_key'; |
|
363 | + $table .= 'LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_forms fr ON it.form_id=fr.id '; |
|
364 | + } |
|
365 | 365 | |
366 | - if ( preg_match( '/ meta_([0-9]+)/', $order_by, $order_matches ) ) { |
|
367 | - // sort by a requested field |
|
368 | - $field_id = (int) $order_matches[1]; |
|
366 | + if ( preg_match( '/ meta_([0-9]+)/', $order_by, $order_matches ) ) { |
|
367 | + // sort by a requested field |
|
368 | + $field_id = (int) $order_matches[1]; |
|
369 | 369 | $fields .= ', (SELECT meta_value FROM ' . $wpdb->prefix . 'frm_item_metas WHERE field_id = ' . $field_id . ' AND item_id = it.id) as meta_' . $field_id; |
370 | 370 | unset( $order_matches, $field_id ); |
371 | - } |
|
371 | + } |
|
372 | 372 | |
373 | 373 | // prepare the query |
374 | 374 | $query = 'SELECT ' . $fields . ' FROM ' . $table . FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit; |
375 | 375 | |
376 | - $entries = $wpdb->get_results($query, OBJECT_K); |
|
377 | - unset($query); |
|
376 | + $entries = $wpdb->get_results($query, OBJECT_K); |
|
377 | + unset($query); |
|
378 | 378 | |
379 | 379 | if ( ! FrmAppHelper::prevent_caching() ) { |
380 | 380 | wp_cache_set( $cache_key, $entries, 'frm_entry', 300 ); |
381 | 381 | } |
382 | - } |
|
382 | + } |
|
383 | 383 | |
384 | - if ( ! $meta || ! $entries ) { |
|
385 | - return stripslashes_deep($entries); |
|
386 | - } |
|
387 | - unset($meta); |
|
384 | + if ( ! $meta || ! $entries ) { |
|
385 | + return stripslashes_deep($entries); |
|
386 | + } |
|
387 | + unset($meta); |
|
388 | 388 | |
389 | - if ( ! is_array( $where ) && preg_match('/^it\.form_id=\d+$/', $where) ) { |
|
389 | + if ( ! is_array( $where ) && preg_match('/^it\.form_id=\d+$/', $where) ) { |
|
390 | 390 | $where = array( 'it.form_id' => substr( $where, 11 ) ); |
391 | - } |
|
391 | + } |
|
392 | 392 | |
393 | - $meta_where = array( 'field_id !' => 0 ); |
|
394 | - if ( $limit == '' && is_array($where) && count($where) == 1 && isset($where['it.form_id']) ) { |
|
395 | - $meta_where['fi.form_id'] = $where['it.form_id']; |
|
396 | - } else { |
|
397 | - $meta_where['item_id'] = array_keys( $entries ); |
|
398 | - } |
|
393 | + $meta_where = array( 'field_id !' => 0 ); |
|
394 | + if ( $limit == '' && is_array($where) && count($where) == 1 && isset($where['it.form_id']) ) { |
|
395 | + $meta_where['fi.form_id'] = $where['it.form_id']; |
|
396 | + } else { |
|
397 | + $meta_where['item_id'] = array_keys( $entries ); |
|
398 | + } |
|
399 | 399 | |
400 | - $metas = FrmDb::get_results( $wpdb->prefix . 'frm_item_metas it LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_fields fi ON (it.field_id = fi.id)', $meta_where, 'item_id, meta_value, field_id, field_key, form_id' ); |
|
400 | + $metas = FrmDb::get_results( $wpdb->prefix . 'frm_item_metas it LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_fields fi ON (it.field_id = fi.id)', $meta_where, 'item_id, meta_value, field_id, field_key, form_id' ); |
|
401 | 401 | |
402 | - unset( $meta_where ); |
|
402 | + unset( $meta_where ); |
|
403 | 403 | |
404 | - if ( ! $metas ) { |
|
405 | - return stripslashes_deep($entries); |
|
406 | - } |
|
404 | + if ( ! $metas ) { |
|
405 | + return stripslashes_deep($entries); |
|
406 | + } |
|
407 | 407 | |
408 | - foreach ( $metas as $m_key => $meta_val ) { |
|
409 | - if ( ! isset( $entries[ $meta_val->item_id ] ) ) { |
|
410 | - continue; |
|
411 | - } |
|
408 | + foreach ( $metas as $m_key => $meta_val ) { |
|
409 | + if ( ! isset( $entries[ $meta_val->item_id ] ) ) { |
|
410 | + continue; |
|
411 | + } |
|
412 | 412 | |
413 | - if ( ! isset( $entries[ $meta_val->item_id ]->metas ) ) { |
|
413 | + if ( ! isset( $entries[ $meta_val->item_id ]->metas ) ) { |
|
414 | 414 | $entries[ $meta_val->item_id ]->metas = array(); |
415 | - } |
|
415 | + } |
|
416 | 416 | |
417 | 417 | $entries[ $meta_val->item_id ]->metas[ $meta_val->field_id ] = maybe_unserialize( $meta_val->meta_value ); |
418 | 418 | |
419 | - unset($m_key, $meta_val); |
|
420 | - } |
|
419 | + unset($m_key, $meta_val); |
|
420 | + } |
|
421 | 421 | |
422 | 422 | if ( ! FrmAppHelper::prevent_caching() ) { |
423 | 423 | foreach ( $entries as $entry ) { |
@@ -426,46 +426,46 @@ discard block |
||
426 | 426 | } |
427 | 427 | } |
428 | 428 | |
429 | - return stripslashes_deep($entries); |
|
430 | - } |
|
429 | + return stripslashes_deep($entries); |
|
430 | + } |
|
431 | 431 | |
432 | - // Pagination Methods |
|
433 | - public static function getRecordCount( $where = '' ) { |
|
434 | - global $wpdb; |
|
432 | + // Pagination Methods |
|
433 | + public static function getRecordCount( $where = '' ) { |
|
434 | + global $wpdb; |
|
435 | 435 | $table_join = $wpdb->prefix . 'frm_items it LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_forms fr ON it.form_id=fr.id'; |
436 | 436 | |
437 | - if ( is_numeric($where) ) { |
|
438 | - $table_join = 'frm_items'; |
|
439 | - $where = array( 'form_id' => $where ); |
|
440 | - } |
|
437 | + if ( is_numeric($where) ) { |
|
438 | + $table_join = 'frm_items'; |
|
439 | + $where = array( 'form_id' => $where ); |
|
440 | + } |
|
441 | 441 | |
442 | - if ( is_array( $where ) ) { |
|
443 | - $count = FrmDb::get_count( $table_join, $where ); |
|
444 | - } else { |
|
442 | + if ( is_array( $where ) ) { |
|
443 | + $count = FrmDb::get_count( $table_join, $where ); |
|
444 | + } else { |
|
445 | 445 | $cache_key = 'count_' . maybe_serialize( $where ); |
446 | 446 | $query = 'SELECT COUNT(*) FROM ' . $table_join . FrmAppHelper::prepend_and_or_where( ' WHERE ', $where ); |
447 | 447 | $count = FrmAppHelper::check_cache( $cache_key, 'frm_entry', $query, 'get_var' ); |
448 | - } |
|
449 | - |
|
450 | - return $count; |
|
451 | - } |
|
452 | - |
|
453 | - public static function getPageCount( $p_size, $where = '' ) { |
|
454 | - if ( is_numeric($where) ) { |
|
455 | - return ceil( (int) $where / (int) $p_size ); |
|
456 | - } else { |
|
457 | - return ceil( (int) self::getRecordCount($where) / (int) $p_size ); |
|
458 | - } |
|
459 | - } |
|
460 | - |
|
461 | - /** |
|
462 | - * Prepare the data before inserting it into the database |
|
463 | - * |
|
464 | - * @since 2.0.16 |
|
465 | - * @param array $values |
|
466 | - * @param string $type |
|
467 | - * @return array $new_values |
|
468 | - */ |
|
448 | + } |
|
449 | + |
|
450 | + return $count; |
|
451 | + } |
|
452 | + |
|
453 | + public static function getPageCount( $p_size, $where = '' ) { |
|
454 | + if ( is_numeric($where) ) { |
|
455 | + return ceil( (int) $where / (int) $p_size ); |
|
456 | + } else { |
|
457 | + return ceil( (int) self::getRecordCount($where) / (int) $p_size ); |
|
458 | + } |
|
459 | + } |
|
460 | + |
|
461 | + /** |
|
462 | + * Prepare the data before inserting it into the database |
|
463 | + * |
|
464 | + * @since 2.0.16 |
|
465 | + * @param array $values |
|
466 | + * @param string $type |
|
467 | + * @return array $new_values |
|
468 | + */ |
|
469 | 469 | private static function before_insert_entry_in_database( &$values, $type ) { |
470 | 470 | |
471 | 471 | self::sanitize_entry_post( $values ); |
@@ -480,13 +480,13 @@ discard block |
||
480 | 480 | } |
481 | 481 | |
482 | 482 | /** |
483 | - * Create an entry and perform after create actions |
|
484 | - * |
|
485 | - * @since 2.0.16 |
|
486 | - * @param array $values |
|
487 | - * @param array $new_values |
|
488 | - * @return boolean|int $entry_id |
|
489 | - */ |
|
483 | + * Create an entry and perform after create actions |
|
484 | + * |
|
485 | + * @since 2.0.16 |
|
486 | + * @param array $values |
|
487 | + * @param array $new_values |
|
488 | + * @return boolean|int $entry_id |
|
489 | + */ |
|
490 | 490 | private static function continue_to_create_entry( $values, $new_values ) { |
491 | 491 | $entry_id = self::insert_entry_into_database( $new_values ); |
492 | 492 | if ( ! $entry_id ) { |
@@ -498,37 +498,37 @@ discard block |
||
498 | 498 | return $entry_id; |
499 | 499 | } |
500 | 500 | |
501 | - /** |
|
502 | - * Sanitize the POST values before we use them |
|
503 | - * |
|
504 | - * @since 2.0 |
|
505 | - * @param array $values The POST values by reference |
|
506 | - */ |
|
507 | - public static function sanitize_entry_post( &$values ) { |
|
508 | - $sanitize_method = array( |
|
509 | - 'form_id' => 'absint', |
|
510 | - 'frm_action' => 'sanitize_title', |
|
511 | - 'form_key' => 'sanitize_title', |
|
512 | - 'item_key' => 'sanitize_title', |
|
513 | - 'item_name' => 'sanitize_text_field', |
|
514 | - 'frm_saving_draft' => 'absint', |
|
515 | - 'is_draft' => 'absint', |
|
516 | - 'post_id' => 'absint', |
|
517 | - 'parent_item_id' => 'absint', |
|
518 | - 'created_at' => 'sanitize_text_field', |
|
519 | - 'updated_at' => 'sanitize_text_field', |
|
520 | - ); |
|
521 | - |
|
522 | - FrmAppHelper::sanitize_request( $sanitize_method, $values ); |
|
523 | - } |
|
524 | - |
|
525 | - /** |
|
526 | - * Prepare the new values for inserting into the database |
|
527 | - * |
|
528 | - * @since 2.0.16 |
|
529 | - * @param array $values |
|
530 | - * @return array $new_values |
|
531 | - */ |
|
501 | + /** |
|
502 | + * Sanitize the POST values before we use them |
|
503 | + * |
|
504 | + * @since 2.0 |
|
505 | + * @param array $values The POST values by reference |
|
506 | + */ |
|
507 | + public static function sanitize_entry_post( &$values ) { |
|
508 | + $sanitize_method = array( |
|
509 | + 'form_id' => 'absint', |
|
510 | + 'frm_action' => 'sanitize_title', |
|
511 | + 'form_key' => 'sanitize_title', |
|
512 | + 'item_key' => 'sanitize_title', |
|
513 | + 'item_name' => 'sanitize_text_field', |
|
514 | + 'frm_saving_draft' => 'absint', |
|
515 | + 'is_draft' => 'absint', |
|
516 | + 'post_id' => 'absint', |
|
517 | + 'parent_item_id' => 'absint', |
|
518 | + 'created_at' => 'sanitize_text_field', |
|
519 | + 'updated_at' => 'sanitize_text_field', |
|
520 | + ); |
|
521 | + |
|
522 | + FrmAppHelper::sanitize_request( $sanitize_method, $values ); |
|
523 | + } |
|
524 | + |
|
525 | + /** |
|
526 | + * Prepare the new values for inserting into the database |
|
527 | + * |
|
528 | + * @since 2.0.16 |
|
529 | + * @param array $values |
|
530 | + * @return array $new_values |
|
531 | + */ |
|
532 | 532 | private static function package_entry_data( &$values ) { |
533 | 533 | global $wpdb; |
534 | 534 | |
@@ -561,67 +561,67 @@ discard block |
||
561 | 561 | } |
562 | 562 | |
563 | 563 | /** |
564 | - * Get the is_draft value for a new entry |
|
565 | - * |
|
566 | - * @since 2.0.16 |
|
567 | - * @param array $values |
|
568 | - * @return int |
|
569 | - */ |
|
564 | + * Get the is_draft value for a new entry |
|
565 | + * |
|
566 | + * @since 2.0.16 |
|
567 | + * @param array $values |
|
568 | + * @return int |
|
569 | + */ |
|
570 | 570 | private static function get_is_draft_value( $values ) { |
571 | 571 | return ( ( isset( $values['frm_saving_draft'] ) && $values['frm_saving_draft'] == 1 ) || ( isset( $values['is_draft'] ) && $values['is_draft'] == 1 ) ) ? 1 : 0; |
572 | 572 | } |
573 | 573 | |
574 | 574 | /** |
575 | - * Get the form_id value for a new entry |
|
576 | - * |
|
577 | - * @since 2.0.16 |
|
578 | - * @param array $values |
|
579 | - * @return int|null |
|
580 | - */ |
|
575 | + * Get the form_id value for a new entry |
|
576 | + * |
|
577 | + * @since 2.0.16 |
|
578 | + * @param array $values |
|
579 | + * @return int|null |
|
580 | + */ |
|
581 | 581 | private static function get_form_id( $values ) { |
582 | 582 | return isset( $values['form_id'] ) ? (int) $values['form_id'] : null; |
583 | 583 | } |
584 | 584 | |
585 | 585 | /** |
586 | - * Get the post_id value for a new entry |
|
587 | - * |
|
588 | - * @since 2.0.16 |
|
589 | - * @param array $values |
|
590 | - * @return int |
|
591 | - */ |
|
586 | + * Get the post_id value for a new entry |
|
587 | + * |
|
588 | + * @since 2.0.16 |
|
589 | + * @param array $values |
|
590 | + * @return int |
|
591 | + */ |
|
592 | 592 | private static function get_post_id( $values ) { |
593 | 593 | return isset( $values['post_id'] ) ? (int) $values['post_id']: 0; |
594 | 594 | } |
595 | 595 | |
596 | 596 | /** |
597 | - * Get the parent_item_id value for a new entry |
|
598 | - * |
|
599 | - * @since 2.0.16 |
|
600 | - * @param array $values |
|
601 | - * @return int |
|
602 | - */ |
|
597 | + * Get the parent_item_id value for a new entry |
|
598 | + * |
|
599 | + * @since 2.0.16 |
|
600 | + * @param array $values |
|
601 | + * @return int |
|
602 | + */ |
|
603 | 603 | private static function get_parent_item_id( $values ) { |
604 | 604 | return isset( $values['parent_item_id'] ) ? (int) $values['parent_item_id']: 0; |
605 | 605 | } |
606 | 606 | |
607 | 607 | /** |
608 | - * Get the created_at value for a new entry |
|
609 | - * |
|
610 | - * @since 2.0.16 |
|
611 | - * @param array $values |
|
612 | - * @return string |
|
613 | - */ |
|
608 | + * Get the created_at value for a new entry |
|
609 | + * |
|
610 | + * @since 2.0.16 |
|
611 | + * @param array $values |
|
612 | + * @return string |
|
613 | + */ |
|
614 | 614 | private static function get_created_at( $values ) { |
615 | 615 | return isset( $values['created_at'] ) ? $values['created_at']: current_time('mysql', 1); |
616 | 616 | } |
617 | 617 | |
618 | 618 | /** |
619 | - * Get the updated_at value for a new entry |
|
620 | - * |
|
621 | - * @since 2.0.16 |
|
622 | - * @param array $values |
|
623 | - * @return string |
|
624 | - */ |
|
619 | + * Get the updated_at value for a new entry |
|
620 | + * |
|
621 | + * @since 2.0.16 |
|
622 | + * @param array $values |
|
623 | + * @return string |
|
624 | + */ |
|
625 | 625 | private static function get_updated_at( $values ) { |
626 | 626 | if ( isset( $values['updated_at'] ) ) { |
627 | 627 | $updated_at = $values['updated_at']; |
@@ -633,12 +633,12 @@ discard block |
||
633 | 633 | } |
634 | 634 | |
635 | 635 | /** |
636 | - * Get the description value for a new entry |
|
637 | - * |
|
638 | - * @since 2.0.16 |
|
639 | - * @param array $values |
|
640 | - * @return string |
|
641 | - */ |
|
636 | + * Get the description value for a new entry |
|
637 | + * |
|
638 | + * @since 2.0.16 |
|
639 | + * @param array $values |
|
640 | + * @return string |
|
641 | + */ |
|
642 | 642 | private static function get_entry_description( $values ) { |
643 | 643 | if ( isset( $values['description'] ) && ! empty( $values['description'] ) ) { |
644 | 644 | $description = maybe_serialize( $values['description'] ); |
@@ -653,12 +653,12 @@ discard block |
||
653 | 653 | } |
654 | 654 | |
655 | 655 | /** |
656 | - * Get the user_id value for a new entry |
|
657 | - * |
|
658 | - * @since 2.0.16 |
|
659 | - * @param array $values |
|
660 | - * @return int |
|
661 | - */ |
|
656 | + * Get the user_id value for a new entry |
|
657 | + * |
|
658 | + * @since 2.0.16 |
|
659 | + * @param array $values |
|
660 | + * @return int |
|
661 | + */ |
|
662 | 662 | private static function get_entry_user_id( $values ) { |
663 | 663 | if ( isset( $values['frm_user_id'] ) && ( is_numeric( $values['frm_user_id'] ) || FrmAppHelper::is_admin() ) ) { |
664 | 664 | $user_id = $values['frm_user_id']; |
@@ -671,12 +671,12 @@ discard block |
||
671 | 671 | } |
672 | 672 | |
673 | 673 | /** |
674 | - * Insert new entry into the database |
|
675 | - * |
|
676 | - * @since 2.0.16 |
|
677 | - * @param array $new_values |
|
678 | - * @return int | boolean $entry_id |
|
679 | - */ |
|
674 | + * Insert new entry into the database |
|
675 | + * |
|
676 | + * @since 2.0.16 |
|
677 | + * @param array $new_values |
|
678 | + * @return int | boolean $entry_id |
|
679 | + */ |
|
680 | 680 | private static function insert_entry_into_database( $new_values ) { |
681 | 681 | global $wpdb; |
682 | 682 | |
@@ -692,11 +692,11 @@ discard block |
||
692 | 692 | } |
693 | 693 | |
694 | 694 | /** |
695 | - * Add the new entry to global $frm_vars |
|
696 | - * |
|
697 | - * @since 2.0.16 |
|
698 | - * @param int $entry_id |
|
699 | - */ |
|
695 | + * Add the new entry to global $frm_vars |
|
696 | + * |
|
697 | + * @since 2.0.16 |
|
698 | + * @param int $entry_id |
|
699 | + */ |
|
700 | 700 | private static function add_new_entry_to_frm_vars( $entry_id ) { |
701 | 701 | global $frm_vars; |
702 | 702 | |
@@ -708,12 +708,12 @@ discard block |
||
708 | 708 | } |
709 | 709 | |
710 | 710 | /** |
711 | - * Add entry metas, if there are any |
|
712 | - * |
|
713 | - * @since 2.0.16 |
|
714 | - * @param array $values |
|
715 | - * @param int $entry_id |
|
716 | - */ |
|
711 | + * Add entry metas, if there are any |
|
712 | + * |
|
713 | + * @since 2.0.16 |
|
714 | + * @param array $values |
|
715 | + * @param int $entry_id |
|
716 | + */ |
|
717 | 717 | private static function maybe_add_entry_metas( $values, $entry_id ) { |
718 | 718 | if ( isset($values['item_meta']) ) { |
719 | 719 | FrmEntryMeta::update_entry_metas( $entry_id, $values['item_meta'] ); |
@@ -721,12 +721,12 @@ discard block |
||
721 | 721 | } |
722 | 722 | |
723 | 723 | /** |
724 | - * Trigger frm_after_create_entry hooks |
|
725 | - * |
|
726 | - * @since 2.0.16 |
|
727 | - * @param int $entry_id |
|
728 | - * @param array $new_values |
|
729 | - */ |
|
724 | + * Trigger frm_after_create_entry hooks |
|
725 | + * |
|
726 | + * @since 2.0.16 |
|
727 | + * @param int $entry_id |
|
728 | + * @param array $new_values |
|
729 | + */ |
|
730 | 730 | private static function after_entry_created_actions( $entry_id, $values, $new_values ) { |
731 | 731 | // this is a child entry |
732 | 732 | $is_child = isset( $values['parent_form_id'] ) && isset( $values['parent_nonce'] ) && ! empty( $values['parent_form_id'] ) && wp_verify_nonce( $values['parent_nonce'], 'parent' ); |
@@ -736,13 +736,13 @@ discard block |
||
736 | 736 | } |
737 | 737 | |
738 | 738 | /** |
739 | - * Actions to perform immediately after an entry is inserted in the frm_items database |
|
740 | - * |
|
741 | - * @since 2.0.16 |
|
742 | - * @param array $values |
|
743 | - * @param array $new_values |
|
744 | - * @param int $entry_id |
|
745 | - */ |
|
739 | + * Actions to perform immediately after an entry is inserted in the frm_items database |
|
740 | + * |
|
741 | + * @since 2.0.16 |
|
742 | + * @param array $values |
|
743 | + * @param array $new_values |
|
744 | + * @param int $entry_id |
|
745 | + */ |
|
746 | 746 | private static function after_insert_entry_in_database( $values, $new_values, $entry_id ) { |
747 | 747 | |
748 | 748 | self::add_new_entry_to_frm_vars( $entry_id ); |
@@ -755,14 +755,14 @@ discard block |
||
755 | 755 | } |
756 | 756 | |
757 | 757 | /** |
758 | - * Perform some actions right before updating an entry |
|
759 | - * |
|
760 | - * @since 2.0.16 |
|
761 | - * @param int $id |
|
762 | - * @param array $values |
|
763 | - * @param string $update_type |
|
764 | - * @return boolean $update |
|
765 | - */ |
|
758 | + * Perform some actions right before updating an entry |
|
759 | + * |
|
760 | + * @since 2.0.16 |
|
761 | + * @param int $id |
|
762 | + * @param array $values |
|
763 | + * @param string $update_type |
|
764 | + * @return boolean $update |
|
765 | + */ |
|
766 | 766 | private static function before_update_entry( $id, &$values, $update_type ) { |
767 | 767 | $update = true; |
768 | 768 | |
@@ -780,13 +780,13 @@ discard block |
||
780 | 780 | } |
781 | 781 | |
782 | 782 | /** |
783 | - * Package the entry data for updating |
|
784 | - * |
|
785 | - * @since 2.0.16 |
|
786 | - * @param int $id |
|
787 | - * @param array $values |
|
788 | - * @return array $new_values |
|
789 | - */ |
|
783 | + * Package the entry data for updating |
|
784 | + * |
|
785 | + * @since 2.0.16 |
|
786 | + * @param int $id |
|
787 | + * @param array $values |
|
788 | + * @return array $new_values |
|
789 | + */ |
|
790 | 790 | private static function package_entry_to_update( $id, $values ) { |
791 | 791 | global $wpdb; |
792 | 792 | |
@@ -820,14 +820,14 @@ discard block |
||
820 | 820 | } |
821 | 821 | |
822 | 822 | /** |
823 | - * Perform some actions right after updating an entry |
|
824 | - * |
|
825 | - * @since 2.0.16 |
|
826 | - * @param boolean|int $query_results |
|
827 | - * @param int $id |
|
828 | - * @param array $values |
|
829 | - * @param array $new_values |
|
830 | - */ |
|
823 | + * Perform some actions right after updating an entry |
|
824 | + * |
|
825 | + * @since 2.0.16 |
|
826 | + * @param boolean|int $query_results |
|
827 | + * @param int $id |
|
828 | + * @param array $values |
|
829 | + * @param array $new_values |
|
830 | + */ |
|
831 | 831 | private static function after_update_entry( $query_results, $id, $values, $new_values ) { |
832 | 832 | if ( $query_results ) { |
833 | 833 | self::clear_cache(); |
@@ -849,13 +849,13 @@ discard block |
||
849 | 849 | } |
850 | 850 | |
851 | 851 | /** |
852 | - * Create entry from an XML import |
|
853 | - * Certain actions aren't necessary when importing (like saving sub entries, checking for duplicates, etc.) |
|
854 | - * |
|
855 | - * @since 2.0.16 |
|
856 | - * @param array $values |
|
857 | - * @return int | boolean $entry_id |
|
858 | - */ |
|
852 | + * Create entry from an XML import |
|
853 | + * Certain actions aren't necessary when importing (like saving sub entries, checking for duplicates, etc.) |
|
854 | + * |
|
855 | + * @since 2.0.16 |
|
856 | + * @param array $values |
|
857 | + * @return int | boolean $entry_id |
|
858 | + */ |
|
859 | 859 | public static function create_entry_from_xml( $values ) { |
860 | 860 | $entry_id = self::create_entry( $values, 'xml' ); |
861 | 861 | |
@@ -863,28 +863,28 @@ discard block |
||
863 | 863 | } |
864 | 864 | |
865 | 865 | /** |
866 | - * Update entry from an XML import |
|
867 | - * Certain actions aren't necessary when importing (like saving sub entries and modifying other vals) |
|
868 | - * |
|
869 | - * @since 2.0.16 |
|
870 | - * @param int $id |
|
871 | - * @param array $values |
|
872 | - * @return int | boolean $updated |
|
873 | - */ |
|
866 | + * Update entry from an XML import |
|
867 | + * Certain actions aren't necessary when importing (like saving sub entries and modifying other vals) |
|
868 | + * |
|
869 | + * @since 2.0.16 |
|
870 | + * @param int $id |
|
871 | + * @param array $values |
|
872 | + * @return int | boolean $updated |
|
873 | + */ |
|
874 | 874 | public static function update_entry_from_xml( $id, $values ) { |
875 | 875 | $updated = self::update_entry( $id, $values, 'xml' ); |
876 | 876 | |
877 | 877 | return $updated; |
878 | 878 | } |
879 | 879 | |
880 | - /** |
|
881 | - * @param string $key |
|
882 | - * @return int entry_id |
|
883 | - */ |
|
880 | + /** |
|
881 | + * @param string $key |
|
882 | + * @return int entry_id |
|
883 | + */ |
|
884 | 884 | public static function get_id_by_key( $key ) { |
885 | - $entry_id = FrmDb::get_var( 'frm_items', array( 'item_key' => sanitize_title( $key ) ) ); |
|
886 | - return $entry_id; |
|
887 | - } |
|
885 | + $entry_id = FrmDb::get_var( 'frm_items', array( 'item_key' => sanitize_title( $key ) ) ); |
|
886 | + return $entry_id; |
|
887 | + } |
|
888 | 888 | |
889 | 889 | public static function validate( $values, $exclude = false ) { |
890 | 890 | _deprecated_function( __FUNCTION__, '2.0.9', 'FrmEntryValidate::validate' ); |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined('ABSPATH') ) { |
|
2 | +if ( ! defined( 'ABSPATH' ) ) { |
|
3 | 3 | die( 'You are not allowed to call this page directly.' ); |
4 | 4 | } |
5 | 5 | |
@@ -55,13 +55,13 @@ discard block |
||
55 | 55 | unset( $check_val['is_draft'], $check_val['id'], $check_val['item_key'] ); |
56 | 56 | |
57 | 57 | if ( $new_values['item_key'] == $new_values['name'] ) { |
58 | - unset($check_val['name']); |
|
58 | + unset( $check_val['name'] ); |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | global $wpdb; |
62 | 62 | $entry_exists = FrmDb::get_col( $wpdb->prefix . 'frm_items', $check_val, 'id', array( 'order_by' => 'created_at DESC' ) ); |
63 | 63 | |
64 | - if ( ! $entry_exists || empty($entry_exists) || ! isset($values['item_meta']) ) { |
|
64 | + if ( ! $entry_exists || empty( $entry_exists ) || ! isset( $values['item_meta'] ) ) { |
|
65 | 65 | return false; |
66 | 66 | } |
67 | 67 | |
@@ -70,10 +70,10 @@ discard block |
||
70 | 70 | $is_duplicate = true; |
71 | 71 | |
72 | 72 | //add more checks here to make sure it's a duplicate |
73 | - $metas = FrmEntryMeta::get_entry_meta_info($entry_exist); |
|
73 | + $metas = FrmEntryMeta::get_entry_meta_info( $entry_exist ); |
|
74 | 74 | $field_metas = array(); |
75 | 75 | foreach ( $metas as $meta ) { |
76 | - $field_metas[ $meta->field_id ] = $meta->meta_value; |
|
76 | + $field_metas[$meta->field_id] = $meta->meta_value; |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | // If prev entry is empty and current entry is not, they are not duplicates |
@@ -82,9 +82,9 @@ discard block |
||
82 | 82 | return false; |
83 | 83 | } |
84 | 84 | |
85 | - $diff = array_diff_assoc($field_metas, array_map('maybe_serialize', $values['item_meta'])); |
|
85 | + $diff = array_diff_assoc( $field_metas, array_map( 'maybe_serialize', $values['item_meta'] ) ); |
|
86 | 86 | foreach ( $diff as $field_id => $meta_value ) { |
87 | - if ( ! empty($meta_value) ) { |
|
87 | + if ( ! empty( $meta_value ) ) { |
|
88 | 88 | $is_duplicate = false; |
89 | 89 | continue; |
90 | 90 | } |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | */ |
110 | 110 | private static function is_duplicate_check_needed( $new_values, $values, &$duplicate_entry_time ) { |
111 | 111 | // If CSV is importing, don't check for duplicates |
112 | - if ( defined('WP_IMPORTING') && WP_IMPORTING ) { |
|
112 | + if ( defined( 'WP_IMPORTING' ) && WP_IMPORTING ) { |
|
113 | 113 | return false; |
114 | 114 | } |
115 | 115 | |
@@ -137,8 +137,8 @@ discard block |
||
137 | 137 | $new_values['name'] = $values->name; |
138 | 138 | $new_values['is_draft'] = $values->is_draft; |
139 | 139 | $new_values['user_id'] = $new_values['updated_by'] = (int) $values->user_id; |
140 | - $new_values['form_id'] = $values->form_id ? (int) $values->form_id: null; |
|
141 | - $new_values['created_at'] = $new_values['updated_at'] = current_time('mysql', 1); |
|
140 | + $new_values['form_id'] = $values->form_id ? (int) $values->form_id : null; |
|
141 | + $new_values['created_at'] = $new_values['updated_at'] = current_time( 'mysql', 1 ); |
|
142 | 142 | |
143 | 143 | $query_results = $wpdb->insert( $wpdb->prefix . 'frm_items', $new_values ); |
144 | 144 | if ( ! $query_results ) { |
@@ -148,12 +148,12 @@ discard block |
||
148 | 148 | $entry_id = $wpdb->insert_id; |
149 | 149 | |
150 | 150 | global $frm_vars; |
151 | - if ( ! isset($frm_vars['saved_entries']) ) { |
|
151 | + if ( ! isset( $frm_vars['saved_entries'] ) ) { |
|
152 | 152 | $frm_vars['saved_entries'] = array(); |
153 | 153 | } |
154 | 154 | $frm_vars['saved_entries'][] = (int) $entry_id; |
155 | 155 | |
156 | - FrmEntryMeta::duplicate_entry_metas($id, $entry_id); |
|
156 | + FrmEntryMeta::duplicate_entry_metas( $id, $entry_id ); |
|
157 | 157 | self::clear_cache(); |
158 | 158 | |
159 | 159 | do_action( 'frm_after_duplicate_entry', $entry_id, $new_values['form_id'], array( 'old_id' => $id ) ); |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | |
193 | 193 | $new_values = self::package_entry_to_update( $id, $values ); |
194 | 194 | |
195 | - $query_results = $wpdb->update( $wpdb->prefix . 'frm_items', $new_values, compact('id') ); |
|
195 | + $query_results = $wpdb->update( $wpdb->prefix . 'frm_items', $new_values, compact( 'id' ) ); |
|
196 | 196 | |
197 | 197 | self::after_update_entry( $query_results, $id, $values, $new_values ); |
198 | 198 | |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | return $result; |
210 | 210 | } |
211 | 211 | |
212 | - do_action('frm_before_destroy_entry', $id, $entry); |
|
212 | + do_action( 'frm_before_destroy_entry', $id, $entry ); |
|
213 | 213 | |
214 | 214 | $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_item_metas WHERE item_id=%d', $id ) ); |
215 | 215 | $result = $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_items WHERE id=%d', $id ) ); |
@@ -221,7 +221,7 @@ discard block |
||
221 | 221 | |
222 | 222 | public static function &update_form( $id, $value, $form_id ) { |
223 | 223 | global $wpdb; |
224 | - $form_id = isset($value) ? $form_id : null; |
|
224 | + $form_id = isset( $value ) ? $form_id : null; |
|
225 | 225 | $result = $wpdb->update( $wpdb->prefix . 'frm_items', array( 'form_id' => $form_id ), array( 'id' => $id ) ); |
226 | 226 | if ( $result ) { |
227 | 227 | self::clear_cache(); |
@@ -268,24 +268,24 @@ discard block |
||
268 | 268 | $query = "SELECT it.*, fr.name as form_name, fr.form_key as form_key FROM {$wpdb->prefix}frm_items it |
269 | 269 | LEFT OUTER JOIN {$wpdb->prefix}frm_forms fr ON it.form_id=fr.id WHERE "; |
270 | 270 | |
271 | - $query .= is_numeric($id) ? 'it.id=%d' : 'it.item_key=%s'; |
|
271 | + $query .= is_numeric( $id ) ? 'it.id=%d' : 'it.item_key=%s'; |
|
272 | 272 | $query_args = array( $id ); |
273 | 273 | $query = $wpdb->prepare( $query, $query_args ); |
274 | 274 | |
275 | 275 | if ( ! $meta ) { |
276 | 276 | $entry = FrmAppHelper::check_cache( $id . '_nometa', 'frm_entry', $query, 'get_row' ); |
277 | - return stripslashes_deep($entry); |
|
277 | + return stripslashes_deep( $entry ); |
|
278 | 278 | } |
279 | 279 | |
280 | 280 | $entry = FrmAppHelper::check_cache( $id, 'frm_entry' ); |
281 | 281 | if ( $entry !== false ) { |
282 | - return stripslashes_deep($entry); |
|
282 | + return stripslashes_deep( $entry ); |
|
283 | 283 | } |
284 | 284 | |
285 | 285 | $entry = $wpdb->get_row( $query ); |
286 | - $entry = self::get_meta($entry); |
|
286 | + $entry = self::get_meta( $entry ); |
|
287 | 287 | |
288 | - return stripslashes_deep($entry); |
|
288 | + return stripslashes_deep( $entry ); |
|
289 | 289 | } |
290 | 290 | |
291 | 291 | public static function get_meta( $entry ) { |
@@ -301,25 +301,25 @@ discard block |
||
301 | 301 | $include_key = apply_filters( 'frm_include_meta_keys', false ); |
302 | 302 | foreach ( $metas as $meta_val ) { |
303 | 303 | if ( $meta_val->item_id == $entry->id ) { |
304 | - $entry->metas[ $meta_val->field_id ] = maybe_unserialize( $meta_val->meta_value ); |
|
304 | + $entry->metas[$meta_val->field_id] = maybe_unserialize( $meta_val->meta_value ); |
|
305 | 305 | if ( $include_key ) { |
306 | - $entry->metas[ $meta_val->field_key ] = $entry->metas[ $meta_val->field_id ]; |
|
306 | + $entry->metas[$meta_val->field_key] = $entry->metas[$meta_val->field_id]; |
|
307 | 307 | } |
308 | 308 | continue; |
309 | 309 | } |
310 | 310 | |
311 | 311 | // include sub entries in an array |
312 | - if ( ! isset( $entry_metas[ $meta_val->field_id ] ) ) { |
|
313 | - $entry->metas[ $meta_val->field_id ] = array(); |
|
312 | + if ( ! isset( $entry_metas[$meta_val->field_id] ) ) { |
|
313 | + $entry->metas[$meta_val->field_id] = array(); |
|
314 | 314 | } |
315 | 315 | |
316 | - $entry->metas[ $meta_val->field_id ][] = maybe_unserialize( $meta_val->meta_value ); |
|
316 | + $entry->metas[$meta_val->field_id][] = maybe_unserialize( $meta_val->meta_value ); |
|
317 | 317 | |
318 | - unset($meta_val); |
|
318 | + unset( $meta_val ); |
|
319 | 319 | } |
320 | - unset($metas); |
|
320 | + unset( $metas ); |
|
321 | 321 | |
322 | - wp_cache_set( $entry->id, $entry, 'frm_entry'); |
|
322 | + wp_cache_set( $entry->id, $entry, 'frm_entry' ); |
|
323 | 323 | |
324 | 324 | return $entry; |
325 | 325 | } |
@@ -335,24 +335,24 @@ discard block |
||
335 | 335 | return $exists; |
336 | 336 | } |
337 | 337 | |
338 | - if ( is_numeric($id) ) { |
|
338 | + if ( is_numeric( $id ) ) { |
|
339 | 339 | $where = array( 'id' => $id ); |
340 | 340 | } else { |
341 | 341 | $where = array( 'item_key' => $id ); |
342 | 342 | } |
343 | 343 | $id = FrmDb::get_var( $wpdb->prefix . 'frm_items', $where ); |
344 | 344 | |
345 | - $exists = ($id && $id > 0) ? true : false; |
|
345 | + $exists = ( $id && $id > 0 ) ? true : false; |
|
346 | 346 | return $exists; |
347 | 347 | } |
348 | 348 | |
349 | 349 | public static function getAll( $where, $order_by = '', $limit = '', $meta = false, $inc_form = true ) { |
350 | 350 | global $wpdb; |
351 | 351 | |
352 | - $limit = FrmAppHelper::esc_limit($limit); |
|
352 | + $limit = FrmAppHelper::esc_limit( $limit ); |
|
353 | 353 | |
354 | - $cache_key = maybe_serialize($where) . $order_by . $limit . $inc_form; |
|
355 | - $entries = wp_cache_get($cache_key, 'frm_entry'); |
|
354 | + $cache_key = maybe_serialize( $where ) . $order_by . $limit . $inc_form; |
|
355 | + $entries = wp_cache_get( $cache_key, 'frm_entry' ); |
|
356 | 356 | |
357 | 357 | if ( false === $entries ) { |
358 | 358 | $fields = 'it.id, it.item_key, it.name, it.ip, it.form_id, it.post_id, it.user_id, it.parent_item_id, it.updated_by, it.created_at, it.updated_at, it.is_draft'; |
@@ -371,10 +371,10 @@ discard block |
||
371 | 371 | } |
372 | 372 | |
373 | 373 | // prepare the query |
374 | - $query = 'SELECT ' . $fields . ' FROM ' . $table . FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit; |
|
374 | + $query = 'SELECT ' . $fields . ' FROM ' . $table . FrmAppHelper::prepend_and_or_where( ' WHERE ', $where ) . $order_by . $limit; |
|
375 | 375 | |
376 | - $entries = $wpdb->get_results($query, OBJECT_K); |
|
377 | - unset($query); |
|
376 | + $entries = $wpdb->get_results( $query, OBJECT_K ); |
|
377 | + unset( $query ); |
|
378 | 378 | |
379 | 379 | if ( ! FrmAppHelper::prevent_caching() ) { |
380 | 380 | wp_cache_set( $cache_key, $entries, 'frm_entry', 300 ); |
@@ -382,16 +382,16 @@ discard block |
||
382 | 382 | } |
383 | 383 | |
384 | 384 | if ( ! $meta || ! $entries ) { |
385 | - return stripslashes_deep($entries); |
|
385 | + return stripslashes_deep( $entries ); |
|
386 | 386 | } |
387 | - unset($meta); |
|
387 | + unset( $meta ); |
|
388 | 388 | |
389 | - if ( ! is_array( $where ) && preg_match('/^it\.form_id=\d+$/', $where) ) { |
|
389 | + if ( ! is_array( $where ) && preg_match( '/^it\.form_id=\d+$/', $where ) ) { |
|
390 | 390 | $where = array( 'it.form_id' => substr( $where, 11 ) ); |
391 | 391 | } |
392 | 392 | |
393 | 393 | $meta_where = array( 'field_id !' => 0 ); |
394 | - if ( $limit == '' && is_array($where) && count($where) == 1 && isset($where['it.form_id']) ) { |
|
394 | + if ( $limit == '' && is_array( $where ) && count( $where ) == 1 && isset( $where['it.form_id'] ) ) { |
|
395 | 395 | $meta_where['fi.form_id'] = $where['it.form_id']; |
396 | 396 | } else { |
397 | 397 | $meta_where['item_id'] = array_keys( $entries ); |
@@ -402,21 +402,21 @@ discard block |
||
402 | 402 | unset( $meta_where ); |
403 | 403 | |
404 | 404 | if ( ! $metas ) { |
405 | - return stripslashes_deep($entries); |
|
405 | + return stripslashes_deep( $entries ); |
|
406 | 406 | } |
407 | 407 | |
408 | 408 | foreach ( $metas as $m_key => $meta_val ) { |
409 | - if ( ! isset( $entries[ $meta_val->item_id ] ) ) { |
|
409 | + if ( ! isset( $entries[$meta_val->item_id] ) ) { |
|
410 | 410 | continue; |
411 | 411 | } |
412 | 412 | |
413 | - if ( ! isset( $entries[ $meta_val->item_id ]->metas ) ) { |
|
414 | - $entries[ $meta_val->item_id ]->metas = array(); |
|
413 | + if ( ! isset( $entries[$meta_val->item_id]->metas ) ) { |
|
414 | + $entries[$meta_val->item_id]->metas = array(); |
|
415 | 415 | } |
416 | 416 | |
417 | - $entries[ $meta_val->item_id ]->metas[ $meta_val->field_id ] = maybe_unserialize( $meta_val->meta_value ); |
|
417 | + $entries[$meta_val->item_id]->metas[$meta_val->field_id] = maybe_unserialize( $meta_val->meta_value ); |
|
418 | 418 | |
419 | - unset($m_key, $meta_val); |
|
419 | + unset( $m_key, $meta_val ); |
|
420 | 420 | } |
421 | 421 | |
422 | 422 | if ( ! FrmAppHelper::prevent_caching() ) { |
@@ -426,7 +426,7 @@ discard block |
||
426 | 426 | } |
427 | 427 | } |
428 | 428 | |
429 | - return stripslashes_deep($entries); |
|
429 | + return stripslashes_deep( $entries ); |
|
430 | 430 | } |
431 | 431 | |
432 | 432 | // Pagination Methods |
@@ -434,7 +434,7 @@ discard block |
||
434 | 434 | global $wpdb; |
435 | 435 | $table_join = $wpdb->prefix . 'frm_items it LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_forms fr ON it.form_id=fr.id'; |
436 | 436 | |
437 | - if ( is_numeric($where) ) { |
|
437 | + if ( is_numeric( $where ) ) { |
|
438 | 438 | $table_join = 'frm_items'; |
439 | 439 | $where = array( 'form_id' => $where ); |
440 | 440 | } |
@@ -451,10 +451,10 @@ discard block |
||
451 | 451 | } |
452 | 452 | |
453 | 453 | public static function getPageCount( $p_size, $where = '' ) { |
454 | - if ( is_numeric($where) ) { |
|
454 | + if ( is_numeric( $where ) ) { |
|
455 | 455 | return ceil( (int) $where / (int) $p_size ); |
456 | 456 | } else { |
457 | - return ceil( (int) self::getRecordCount($where) / (int) $p_size ); |
|
457 | + return ceil( (int) self::getRecordCount( $where ) / (int) $p_size ); |
|
458 | 458 | } |
459 | 459 | } |
460 | 460 | |
@@ -471,7 +471,7 @@ discard block |
||
471 | 471 | self::sanitize_entry_post( $values ); |
472 | 472 | |
473 | 473 | if ( $type != 'xml' ) { |
474 | - $values = apply_filters('frm_pre_create_entry', $values); |
|
474 | + $values = apply_filters( 'frm_pre_create_entry', $values ); |
|
475 | 475 | } |
476 | 476 | |
477 | 477 | $new_values = self::package_entry_data( $values ); |
@@ -551,11 +551,11 @@ discard block |
||
551 | 551 | 'user_id' => self::get_entry_user_id( $values ), |
552 | 552 | ); |
553 | 553 | |
554 | - if ( is_array($new_values['name']) ) { |
|
555 | - $new_values['name'] = reset($new_values['name']); |
|
554 | + if ( is_array( $new_values['name'] ) ) { |
|
555 | + $new_values['name'] = reset( $new_values['name'] ); |
|
556 | 556 | } |
557 | 557 | |
558 | - $new_values['updated_by'] = isset($values['updated_by']) ? $values['updated_by'] : $new_values['user_id']; |
|
558 | + $new_values['updated_by'] = isset( $values['updated_by'] ) ? $values['updated_by'] : $new_values['user_id']; |
|
559 | 559 | |
560 | 560 | return $new_values; |
561 | 561 | } |
@@ -568,7 +568,7 @@ discard block |
||
568 | 568 | * @return int |
569 | 569 | */ |
570 | 570 | private static function get_is_draft_value( $values ) { |
571 | - return ( ( isset( $values['frm_saving_draft'] ) && $values['frm_saving_draft'] == 1 ) || ( isset( $values['is_draft'] ) && $values['is_draft'] == 1 ) ) ? 1 : 0; |
|
571 | + return ( ( isset( $values['frm_saving_draft'] ) && $values['frm_saving_draft'] == 1 ) || ( isset( $values['is_draft'] ) && $values['is_draft'] == 1 ) ) ? 1 : 0; |
|
572 | 572 | } |
573 | 573 | |
574 | 574 | /** |
@@ -590,7 +590,7 @@ discard block |
||
590 | 590 | * @return int |
591 | 591 | */ |
592 | 592 | private static function get_post_id( $values ) { |
593 | - return isset( $values['post_id'] ) ? (int) $values['post_id']: 0; |
|
593 | + return isset( $values['post_id'] ) ? (int) $values['post_id'] : 0; |
|
594 | 594 | } |
595 | 595 | |
596 | 596 | /** |
@@ -601,7 +601,7 @@ discard block |
||
601 | 601 | * @return int |
602 | 602 | */ |
603 | 603 | private static function get_parent_item_id( $values ) { |
604 | - return isset( $values['parent_item_id'] ) ? (int) $values['parent_item_id']: 0; |
|
604 | + return isset( $values['parent_item_id'] ) ? (int) $values['parent_item_id'] : 0; |
|
605 | 605 | } |
606 | 606 | |
607 | 607 | /** |
@@ -612,7 +612,7 @@ discard block |
||
612 | 612 | * @return string |
613 | 613 | */ |
614 | 614 | private static function get_created_at( $values ) { |
615 | - return isset( $values['created_at'] ) ? $values['created_at']: current_time('mysql', 1); |
|
615 | + return isset( $values['created_at'] ) ? $values['created_at'] : current_time( 'mysql', 1 ); |
|
616 | 616 | } |
617 | 617 | |
618 | 618 | /** |
@@ -700,7 +700,7 @@ discard block |
||
700 | 700 | private static function add_new_entry_to_frm_vars( $entry_id ) { |
701 | 701 | global $frm_vars; |
702 | 702 | |
703 | - if ( ! isset($frm_vars['saved_entries']) ) { |
|
703 | + if ( ! isset( $frm_vars['saved_entries'] ) ) { |
|
704 | 704 | $frm_vars['saved_entries'] = array(); |
705 | 705 | } |
706 | 706 | |
@@ -715,7 +715,7 @@ discard block |
||
715 | 715 | * @param int $entry_id |
716 | 716 | */ |
717 | 717 | private static function maybe_add_entry_metas( $values, $entry_id ) { |
718 | - if ( isset($values['item_meta']) ) { |
|
718 | + if ( isset( $values['item_meta'] ) ) { |
|
719 | 719 | FrmEntryMeta::update_entry_metas( $entry_id, $values['item_meta'] ); |
720 | 720 | } |
721 | 721 | } |
@@ -732,7 +732,7 @@ discard block |
||
732 | 732 | $is_child = isset( $values['parent_form_id'] ) && isset( $values['parent_nonce'] ) && ! empty( $values['parent_form_id'] ) && wp_verify_nonce( $values['parent_nonce'], 'parent' ); |
733 | 733 | |
734 | 734 | do_action( 'frm_after_create_entry', $entry_id, $new_values['form_id'], compact( 'is_child' ) ); |
735 | - do_action( 'frm_after_create_entry_' . $new_values['form_id'], $entry_id , compact( 'is_child' ) ); |
|
735 | + do_action( 'frm_after_create_entry_' . $new_values['form_id'], $entry_id, compact( 'is_child' ) ); |
|
736 | 736 | } |
737 | 737 | |
738 | 738 | /** |
@@ -773,7 +773,7 @@ discard block |
||
773 | 773 | } |
774 | 774 | |
775 | 775 | if ( $update && $update_type != 'xml' ) { |
776 | - $values = apply_filters('frm_pre_update_entry', $values, $id); |
|
776 | + $values = apply_filters( 'frm_pre_update_entry', $values, $id ); |
|
777 | 777 | } |
778 | 778 | |
779 | 779 | return $update; |
@@ -794,27 +794,27 @@ discard block |
||
794 | 794 | 'name' => self::get_new_entry_name( $values ), |
795 | 795 | 'form_id' => self::get_form_id( $values ), |
796 | 796 | 'is_draft' => self::get_is_draft_value( $values ), |
797 | - 'updated_at' => current_time('mysql', 1), |
|
798 | - 'updated_by' => isset($values['updated_by']) ? $values['updated_by'] : get_current_user_id(), |
|
797 | + 'updated_at' => current_time( 'mysql', 1 ), |
|
798 | + 'updated_by' => isset( $values['updated_by'] ) ? $values['updated_by'] : get_current_user_id(), |
|
799 | 799 | ); |
800 | 800 | |
801 | - if ( isset($values['post_id']) ) { |
|
801 | + if ( isset( $values['post_id'] ) ) { |
|
802 | 802 | $new_values['post_id'] = (int) $values['post_id']; |
803 | 803 | } |
804 | 804 | |
805 | - if ( isset($values['item_key']) ) { |
|
805 | + if ( isset( $values['item_key'] ) ) { |
|
806 | 806 | $new_values['item_key'] = FrmAppHelper::get_unique_key( $values['item_key'], $wpdb->prefix . 'frm_items', 'item_key', $id ); |
807 | 807 | } |
808 | 808 | |
809 | - if ( isset($values['parent_item_id']) ) { |
|
809 | + if ( isset( $values['parent_item_id'] ) ) { |
|
810 | 810 | $new_values['parent_item_id'] = (int) $values['parent_item_id']; |
811 | 811 | } |
812 | 812 | |
813 | - if ( isset($values['frm_user_id']) && is_numeric($values['frm_user_id']) ) { |
|
813 | + if ( isset( $values['frm_user_id'] ) && is_numeric( $values['frm_user_id'] ) ) { |
|
814 | 814 | $new_values['user_id'] = $values['frm_user_id']; |
815 | 815 | } |
816 | 816 | |
817 | - $new_values = apply_filters('frm_update_entry', $new_values, $id); |
|
817 | + $new_values = apply_filters( 'frm_update_entry', $new_values, $id ); |
|
818 | 818 | |
819 | 819 | return $new_values; |
820 | 820 | } |
@@ -1,64 +1,64 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | class FrmDb { |
4 | - var $fields; |
|
5 | - var $forms; |
|
6 | - var $entries; |
|
7 | - var $entry_metas; |
|
8 | - |
|
9 | - public function __construct() { |
|
10 | - if ( ! defined('ABSPATH') ) { |
|
11 | - die('You are not allowed to call this page directly.'); |
|
12 | - } |
|
13 | - |
|
14 | - global $wpdb; |
|
15 | - $this->fields = $wpdb->prefix . 'frm_fields'; |
|
16 | - $this->forms = $wpdb->prefix . 'frm_forms'; |
|
17 | - $this->entries = $wpdb->prefix . 'frm_items'; |
|
18 | - $this->entry_metas = $wpdb->prefix . 'frm_item_metas'; |
|
19 | - } |
|
20 | - |
|
21 | - public function upgrade( $old_db_version = false ) { |
|
22 | - global $wpdb; |
|
23 | - //$frm_db_version is the version of the database we're moving to |
|
24 | - $frm_db_version = FrmAppHelper::$db_version; |
|
25 | - $old_db_version = (float) $old_db_version; |
|
26 | - if ( ! $old_db_version ) { |
|
27 | - $old_db_version = get_option('frm_db_version'); |
|
28 | - } |
|
29 | - |
|
30 | - if ( $frm_db_version != $old_db_version ) { |
|
4 | + var $fields; |
|
5 | + var $forms; |
|
6 | + var $entries; |
|
7 | + var $entry_metas; |
|
8 | + |
|
9 | + public function __construct() { |
|
10 | + if ( ! defined('ABSPATH') ) { |
|
11 | + die('You are not allowed to call this page directly.'); |
|
12 | + } |
|
13 | + |
|
14 | + global $wpdb; |
|
15 | + $this->fields = $wpdb->prefix . 'frm_fields'; |
|
16 | + $this->forms = $wpdb->prefix . 'frm_forms'; |
|
17 | + $this->entries = $wpdb->prefix . 'frm_items'; |
|
18 | + $this->entry_metas = $wpdb->prefix . 'frm_item_metas'; |
|
19 | + } |
|
20 | + |
|
21 | + public function upgrade( $old_db_version = false ) { |
|
22 | + global $wpdb; |
|
23 | + //$frm_db_version is the version of the database we're moving to |
|
24 | + $frm_db_version = FrmAppHelper::$db_version; |
|
25 | + $old_db_version = (float) $old_db_version; |
|
26 | + if ( ! $old_db_version ) { |
|
27 | + $old_db_version = get_option('frm_db_version'); |
|
28 | + } |
|
29 | + |
|
30 | + if ( $frm_db_version != $old_db_version ) { |
|
31 | 31 | // update rewrite rules for views and other custom post types |
32 | 32 | flush_rewrite_rules(); |
33 | 33 | |
34 | 34 | require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
35 | 35 | |
36 | - $this->create_tables(); |
|
37 | - $this->migrate_data($frm_db_version, $old_db_version); |
|
36 | + $this->create_tables(); |
|
37 | + $this->migrate_data($frm_db_version, $old_db_version); |
|
38 | 38 | |
39 | - /***** SAVE DB VERSION *****/ |
|
40 | - update_option('frm_db_version', $frm_db_version); |
|
39 | + /***** SAVE DB VERSION *****/ |
|
40 | + update_option('frm_db_version', $frm_db_version); |
|
41 | 41 | |
42 | - /**** ADD/UPDATE DEFAULT TEMPLATES ****/ |
|
43 | - FrmXMLController::add_default_templates(); |
|
44 | - } |
|
42 | + /**** ADD/UPDATE DEFAULT TEMPLATES ****/ |
|
43 | + FrmXMLController::add_default_templates(); |
|
44 | + } |
|
45 | 45 | |
46 | - do_action('frm_after_install'); |
|
46 | + do_action('frm_after_install'); |
|
47 | 47 | |
48 | - /**** update the styling settings ****/ |
|
48 | + /**** update the styling settings ****/ |
|
49 | 49 | if ( is_admin() && function_exists( 'get_filesystem_method' ) ) { |
50 | 50 | $frm_style = new FrmStyle(); |
51 | 51 | $frm_style->update( 'default' ); |
52 | 52 | } |
53 | - } |
|
53 | + } |
|
54 | 54 | |
55 | - public function collation() { |
|
56 | - global $wpdb; |
|
57 | - if ( ! $wpdb->has_cap( 'collation' ) ) { |
|
58 | - return ''; |
|
59 | - } |
|
55 | + public function collation() { |
|
56 | + global $wpdb; |
|
57 | + if ( ! $wpdb->has_cap( 'collation' ) ) { |
|
58 | + return ''; |
|
59 | + } |
|
60 | 60 | |
61 | - $charset_collate = ''; |
|
61 | + $charset_collate = ''; |
|
62 | 62 | if ( ! empty( $wpdb->charset ) ) { |
63 | 63 | $charset_collate .= ' DEFAULT CHARACTER SET ' . $wpdb->charset; |
64 | 64 | } |
@@ -67,14 +67,14 @@ discard block |
||
67 | 67 | $charset_collate .= ' COLLATE ' . $wpdb->collate; |
68 | 68 | } |
69 | 69 | |
70 | - return $charset_collate; |
|
71 | - } |
|
70 | + return $charset_collate; |
|
71 | + } |
|
72 | 72 | |
73 | - private function create_tables() { |
|
74 | - $charset_collate = $this->collation(); |
|
75 | - $sql = array(); |
|
73 | + private function create_tables() { |
|
74 | + $charset_collate = $this->collation(); |
|
75 | + $sql = array(); |
|
76 | 76 | |
77 | - /* Create/Upgrade Fields Table */ |
|
77 | + /* Create/Upgrade Fields Table */ |
|
78 | 78 | $sql[] = 'CREATE TABLE ' . $this->fields . ' ( |
79 | 79 | id int(11) NOT NULL auto_increment, |
80 | 80 | field_key varchar(100) default NULL, |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | UNIQUE KEY field_key (field_key) |
94 | 94 | )'; |
95 | 95 | |
96 | - /* Create/Upgrade Forms Table */ |
|
96 | + /* Create/Upgrade Forms Table */ |
|
97 | 97 | $sql[] = 'CREATE TABLE ' . $this->forms . ' ( |
98 | 98 | id int(11) NOT NULL auto_increment, |
99 | 99 | form_key varchar(100) default NULL, |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | UNIQUE KEY form_key (form_key) |
112 | 112 | )'; |
113 | 113 | |
114 | - /* Create/Upgrade Items Table */ |
|
114 | + /* Create/Upgrade Items Table */ |
|
115 | 115 | $sql[] = 'CREATE TABLE ' . $this->entries . ' ( |
116 | 116 | id int(11) NOT NULL auto_increment, |
117 | 117 | item_key varchar(100) default NULL, |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | UNIQUE KEY item_key (item_key) |
135 | 135 | )'; |
136 | 136 | |
137 | - /* Create/Upgrade Meta Table */ |
|
137 | + /* Create/Upgrade Meta Table */ |
|
138 | 138 | $sql[] = 'CREATE TABLE ' . $this->entry_metas . ' ( |
139 | 139 | id int(11) NOT NULL auto_increment, |
140 | 140 | meta_value longtext default NULL, |
@@ -146,39 +146,39 @@ discard block |
||
146 | 146 | KEY item_id (item_id) |
147 | 147 | )'; |
148 | 148 | |
149 | - foreach ( $sql as $q ) { |
|
149 | + foreach ( $sql as $q ) { |
|
150 | 150 | if ( function_exists( 'dbDelta' ) ) { |
151 | 151 | dbDelta( $q . $charset_collate . ';' ); |
152 | 152 | } else { |
153 | 153 | global $wpdb; |
154 | 154 | $wpdb->query( $q . $charset_collate ); |
155 | 155 | } |
156 | - unset($q); |
|
157 | - } |
|
158 | - } |
|
156 | + unset($q); |
|
157 | + } |
|
158 | + } |
|
159 | 159 | |
160 | - /** |
|
161 | - * @param integer $frm_db_version |
|
162 | - */ |
|
160 | + /** |
|
161 | + * @param integer $frm_db_version |
|
162 | + */ |
|
163 | 163 | private function migrate_data( $frm_db_version, $old_db_version ) { |
164 | 164 | $migrations = array( 4, 6, 11, 16, 17, 23, 25 ); |
165 | - foreach ( $migrations as $migration ) { |
|
166 | - if ( $frm_db_version >= $migration && $old_db_version < $migration ) { |
|
165 | + foreach ( $migrations as $migration ) { |
|
166 | + if ( $frm_db_version >= $migration && $old_db_version < $migration ) { |
|
167 | 167 | $function_name = 'migrate_to_' . $migration; |
168 | - $this->$function_name(); |
|
169 | - } |
|
170 | - } |
|
171 | - } |
|
172 | - |
|
173 | - /** |
|
174 | - * Change array into format $wpdb->prepare can use |
|
175 | - */ |
|
176 | - public static function get_where_clause_and_values( &$args, $starts_with = ' WHERE ' ) { |
|
177 | - if ( empty($args) ) { |
|
168 | + $this->$function_name(); |
|
169 | + } |
|
170 | + } |
|
171 | + } |
|
172 | + |
|
173 | + /** |
|
174 | + * Change array into format $wpdb->prepare can use |
|
175 | + */ |
|
176 | + public static function get_where_clause_and_values( &$args, $starts_with = ' WHERE ' ) { |
|
177 | + if ( empty($args) ) { |
|
178 | 178 | // add an arg to prevent prepare from failing |
179 | 179 | $args = array( 'where' => $starts_with . '1=%d', 'values' => array( 1 ) ); |
180 | 180 | return; |
181 | - } |
|
181 | + } |
|
182 | 182 | |
183 | 183 | $where = ''; |
184 | 184 | $values = array(); |
@@ -189,60 +189,60 @@ discard block |
||
189 | 189 | } |
190 | 190 | |
191 | 191 | $args = compact( 'where', 'values' ); |
192 | - } |
|
193 | - |
|
194 | - /** |
|
195 | - * @param string $base_where |
|
196 | - * @param string $where |
|
197 | - */ |
|
198 | - public static function parse_where_from_array( $args, $base_where, &$where, &$values ) { |
|
199 | - $condition = ' AND'; |
|
200 | - if ( isset( $args['or'] ) ) { |
|
201 | - $condition = ' OR'; |
|
202 | - unset( $args['or'] ); |
|
203 | - } |
|
204 | - |
|
205 | - foreach ( $args as $key => $value ) { |
|
206 | - $where .= empty( $where ) ? $base_where : $condition; |
|
207 | - $array_inc_null = ( ! is_numeric( $key ) && is_array( $value ) && in_array( null, $value ) ); |
|
208 | - if ( is_numeric( $key ) || $array_inc_null ) { |
|
209 | - $where .= ' ( '; |
|
210 | - $nested_where = ''; |
|
211 | - if ( $array_inc_null ) { |
|
212 | - foreach ( $value as $val ) { |
|
213 | - self::parse_where_from_array( array( $key => $val, 'or' => 1 ), '', $nested_where, $values ); |
|
214 | - } |
|
215 | - } else { |
|
216 | - self::parse_where_from_array( $value, '', $nested_where, $values ); |
|
217 | - } |
|
218 | - $where .= $nested_where; |
|
219 | - $where .= ' ) '; |
|
220 | - } else { |
|
221 | - self::interpret_array_to_sql( $key, $value, $where, $values ); |
|
222 | - } |
|
223 | - } |
|
224 | - } |
|
225 | - |
|
226 | - /** |
|
227 | - * @param string $key |
|
228 | - * @param string $where |
|
229 | - */ |
|
230 | - private static function interpret_array_to_sql( $key, $value, &$where, &$values ) { |
|
192 | + } |
|
193 | + |
|
194 | + /** |
|
195 | + * @param string $base_where |
|
196 | + * @param string $where |
|
197 | + */ |
|
198 | + public static function parse_where_from_array( $args, $base_where, &$where, &$values ) { |
|
199 | + $condition = ' AND'; |
|
200 | + if ( isset( $args['or'] ) ) { |
|
201 | + $condition = ' OR'; |
|
202 | + unset( $args['or'] ); |
|
203 | + } |
|
204 | + |
|
205 | + foreach ( $args as $key => $value ) { |
|
206 | + $where .= empty( $where ) ? $base_where : $condition; |
|
207 | + $array_inc_null = ( ! is_numeric( $key ) && is_array( $value ) && in_array( null, $value ) ); |
|
208 | + if ( is_numeric( $key ) || $array_inc_null ) { |
|
209 | + $where .= ' ( '; |
|
210 | + $nested_where = ''; |
|
211 | + if ( $array_inc_null ) { |
|
212 | + foreach ( $value as $val ) { |
|
213 | + self::parse_where_from_array( array( $key => $val, 'or' => 1 ), '', $nested_where, $values ); |
|
214 | + } |
|
215 | + } else { |
|
216 | + self::parse_where_from_array( $value, '', $nested_where, $values ); |
|
217 | + } |
|
218 | + $where .= $nested_where; |
|
219 | + $where .= ' ) '; |
|
220 | + } else { |
|
221 | + self::interpret_array_to_sql( $key, $value, $where, $values ); |
|
222 | + } |
|
223 | + } |
|
224 | + } |
|
225 | + |
|
226 | + /** |
|
227 | + * @param string $key |
|
228 | + * @param string $where |
|
229 | + */ |
|
230 | + private static function interpret_array_to_sql( $key, $value, &$where, &$values ) { |
|
231 | 231 | $key = trim( $key ); |
232 | 232 | |
233 | - if ( strpos( $key, 'created_at' ) !== false || strpos( $key, 'updated_at' ) !== false ) { |
|
234 | - $k = explode(' ', $key); |
|
235 | - $where .= ' DATE_FORMAT(' . reset( $k ) . ', %s) ' . str_replace( reset( $k ), '', $key ); |
|
236 | - $values[] = '%Y-%m-%d %H:%i:%s'; |
|
237 | - } else { |
|
233 | + if ( strpos( $key, 'created_at' ) !== false || strpos( $key, 'updated_at' ) !== false ) { |
|
234 | + $k = explode(' ', $key); |
|
235 | + $where .= ' DATE_FORMAT(' . reset( $k ) . ', %s) ' . str_replace( reset( $k ), '', $key ); |
|
236 | + $values[] = '%Y-%m-%d %H:%i:%s'; |
|
237 | + } else { |
|
238 | 238 | $where .= ' ' . $key; |
239 | - } |
|
239 | + } |
|
240 | 240 | |
241 | 241 | $lowercase_key = explode( ' ', strtolower( $key ) ); |
242 | 242 | $lowercase_key = end( $lowercase_key ); |
243 | 243 | |
244 | - if ( is_array( $value ) ) { |
|
245 | - // translate array of values to "in" |
|
244 | + if ( is_array( $value ) ) { |
|
245 | + // translate array of values to "in" |
|
246 | 246 | if ( strpos( $lowercase_key, 'like' ) !== false ) { |
247 | 247 | $where = rtrim( $where, $key ); |
248 | 248 | $where .= '('; |
@@ -260,7 +260,7 @@ discard block |
||
260 | 260 | $where .= ' in (' . FrmAppHelper::prepare_array_values( $value, '%s' ) . ')'; |
261 | 261 | $values = array_merge( $values, $value ); |
262 | 262 | } |
263 | - } else if ( strpos( $lowercase_key, 'like' ) !== false ) { |
|
263 | + } else if ( strpos( $lowercase_key, 'like' ) !== false ) { |
|
264 | 264 | /** |
265 | 265 | * Allow string to start or end with the value |
266 | 266 | * If the key is like% then skip the first % for starts with |
@@ -279,9 +279,9 @@ discard block |
||
279 | 279 | $where .= ' %s'; |
280 | 280 | $values[] = $start . FrmAppHelper::esc_like( $value ) . $end; |
281 | 281 | |
282 | - } else if ( $value === null ) { |
|
283 | - $where .= ' IS NULL'; |
|
284 | - } else { |
|
282 | + } else if ( $value === null ) { |
|
283 | + $where .= ' IS NULL'; |
|
284 | + } else { |
|
285 | 285 | // allow a - to prevent = from being added |
286 | 286 | if ( substr( $key, -1 ) == '-' ) { |
287 | 287 | $where = rtrim( $where, '-' ); |
@@ -289,28 +289,28 @@ discard block |
||
289 | 289 | $where .= '='; |
290 | 290 | } |
291 | 291 | |
292 | - $where .= is_numeric( $value ) ? ( strpos( $value, '.' ) !== false ? '%f' : '%d' ) : '%s'; |
|
293 | - $values[] = $value; |
|
294 | - } |
|
295 | - } |
|
296 | - |
|
297 | - /** |
|
298 | - * @param string $table |
|
299 | - */ |
|
300 | - public static function get_count( $table, $where = array(), $args = array() ) { |
|
301 | - $count = self::get_var( $table, $where, 'COUNT(*)', $args ); |
|
302 | - return $count; |
|
303 | - } |
|
304 | - |
|
305 | - public static function get_var( $table, $where = array(), $field = 'id', $args = array(), $limit = '', $type = 'var' ) { |
|
306 | - $group = ''; |
|
307 | - self::get_group_and_table_name( $table, $group ); |
|
292 | + $where .= is_numeric( $value ) ? ( strpos( $value, '.' ) !== false ? '%f' : '%d' ) : '%s'; |
|
293 | + $values[] = $value; |
|
294 | + } |
|
295 | + } |
|
296 | + |
|
297 | + /** |
|
298 | + * @param string $table |
|
299 | + */ |
|
300 | + public static function get_count( $table, $where = array(), $args = array() ) { |
|
301 | + $count = self::get_var( $table, $where, 'COUNT(*)', $args ); |
|
302 | + return $count; |
|
303 | + } |
|
304 | + |
|
305 | + public static function get_var( $table, $where = array(), $field = 'id', $args = array(), $limit = '', $type = 'var' ) { |
|
306 | + $group = ''; |
|
307 | + self::get_group_and_table_name( $table, $group ); |
|
308 | 308 | self::convert_options_to_array( $args, '', $limit ); |
309 | 309 | |
310 | 310 | $query = 'SELECT ' . $field . ' FROM ' . $table; |
311 | 311 | if ( is_array( $where ) || empty( $where ) ) { |
312 | 312 | // only separate into array values and query string if is array |
313 | - self::get_where_clause_and_values( $where ); |
|
313 | + self::get_where_clause_and_values( $where ); |
|
314 | 314 | global $wpdb; |
315 | 315 | $query = $wpdb->prepare( $query . $where['where'] . ' ' . implode( ' ', $args ), $where['values'] ); |
316 | 316 | } else { |
@@ -324,47 +324,47 @@ discard block |
||
324 | 324 | |
325 | 325 | $cache_key = str_replace( array( ' ', ',' ), '_', trim( implode( '_', FrmAppHelper::array_flatten( $where ) ) . implode( '_', $args ) . $field . '_' . $type, ' WHERE' ) ); |
326 | 326 | $results = FrmAppHelper::check_cache( $cache_key, $group, $query, 'get_' . $type ); |
327 | - return $results; |
|
328 | - } |
|
329 | - |
|
330 | - /** |
|
331 | - * @param string $table |
|
332 | - * @param array $where |
|
333 | - */ |
|
334 | - public static function get_col( $table, $where = array(), $field = 'id', $args = array(), $limit = '' ) { |
|
335 | - return self::get_var( $table, $where, $field, $args, $limit, 'col' ); |
|
336 | - } |
|
337 | - |
|
338 | - /** |
|
339 | - * @since 2.0 |
|
340 | - * @param string $table |
|
341 | - */ |
|
342 | - public static function get_row( $table, $where = array(), $fields = '*', $args = array() ) { |
|
343 | - $args['limit'] = 1; |
|
344 | - return self::get_var( $table, $where, $fields, $args, '', 'row' ); |
|
345 | - } |
|
346 | - |
|
347 | - /** |
|
348 | - * @param string $table |
|
349 | - */ |
|
350 | - public static function get_one_record( $table, $args = array(), $fields = '*', $order_by = '' ) { |
|
351 | - _deprecated_function( __FUNCTION__, '2.0', 'FrmDb::get_row' ); |
|
327 | + return $results; |
|
328 | + } |
|
329 | + |
|
330 | + /** |
|
331 | + * @param string $table |
|
332 | + * @param array $where |
|
333 | + */ |
|
334 | + public static function get_col( $table, $where = array(), $field = 'id', $args = array(), $limit = '' ) { |
|
335 | + return self::get_var( $table, $where, $field, $args, $limit, 'col' ); |
|
336 | + } |
|
337 | + |
|
338 | + /** |
|
339 | + * @since 2.0 |
|
340 | + * @param string $table |
|
341 | + */ |
|
342 | + public static function get_row( $table, $where = array(), $fields = '*', $args = array() ) { |
|
343 | + $args['limit'] = 1; |
|
344 | + return self::get_var( $table, $where, $fields, $args, '', 'row' ); |
|
345 | + } |
|
346 | + |
|
347 | + /** |
|
348 | + * @param string $table |
|
349 | + */ |
|
350 | + public static function get_one_record( $table, $args = array(), $fields = '*', $order_by = '' ) { |
|
351 | + _deprecated_function( __FUNCTION__, '2.0', 'FrmDb::get_row' ); |
|
352 | 352 | return self::get_var( $table, $args, $fields, array( 'order_by' => $order_by, 'limit' => 1 ), '', 'row' ); |
353 | - } |
|
354 | - |
|
355 | - public static function get_records( $table, $args = array(), $order_by = '', $limit = '', $fields = '*' ) { |
|
356 | - _deprecated_function( __FUNCTION__, '2.0', 'FrmDb::get_results' ); |
|
357 | - return self::get_results( $table, $args, $fields, compact('order_by', 'limit') ); |
|
358 | - } |
|
359 | - |
|
360 | - /** |
|
361 | - * Prepare a key/value array before DB call |
|
362 | - * @since 2.0 |
|
363 | - * @param string $table |
|
364 | - */ |
|
365 | - public static function get_results( $table, $where = array(), $fields = '*', $args = array() ) { |
|
366 | - return self::get_var( $table, $where, $fields, $args, '', 'results' ); |
|
367 | - } |
|
353 | + } |
|
354 | + |
|
355 | + public static function get_records( $table, $args = array(), $order_by = '', $limit = '', $fields = '*' ) { |
|
356 | + _deprecated_function( __FUNCTION__, '2.0', 'FrmDb::get_results' ); |
|
357 | + return self::get_results( $table, $args, $fields, compact('order_by', 'limit') ); |
|
358 | + } |
|
359 | + |
|
360 | + /** |
|
361 | + * Prepare a key/value array before DB call |
|
362 | + * @since 2.0 |
|
363 | + * @param string $table |
|
364 | + */ |
|
365 | + public static function get_results( $table, $where = array(), $fields = '*', $args = array() ) { |
|
366 | + return self::get_var( $table, $where, $fields, $args, '', 'results' ); |
|
367 | + } |
|
368 | 368 | |
369 | 369 | /** |
370 | 370 | * Check for like, not like, in, not in, =, !=, >, <, <=, >= |
@@ -400,86 +400,86 @@ discard block |
||
400 | 400 | return ''; |
401 | 401 | } |
402 | 402 | |
403 | - /** |
|
404 | - * Get 'frm_forms' from wp_frm_forms or a longer table param that includes a join |
|
405 | - * Also add the wpdb->prefix to the table if it's missing |
|
406 | - * |
|
407 | - * @param string $table |
|
408 | - * @param string $group |
|
409 | - */ |
|
410 | - private static function get_group_and_table_name( &$table, &$group ) { |
|
403 | + /** |
|
404 | + * Get 'frm_forms' from wp_frm_forms or a longer table param that includes a join |
|
405 | + * Also add the wpdb->prefix to the table if it's missing |
|
406 | + * |
|
407 | + * @param string $table |
|
408 | + * @param string $group |
|
409 | + */ |
|
410 | + private static function get_group_and_table_name( &$table, &$group ) { |
|
411 | 411 | global $wpdb, $wpmuBaseTablePrefix; |
412 | 412 | |
413 | - $table_parts = explode(' ', $table); |
|
414 | - $group = reset($table_parts); |
|
415 | - $group = str_replace( $wpdb->prefix, '', $group ); |
|
413 | + $table_parts = explode(' ', $table); |
|
414 | + $group = reset($table_parts); |
|
415 | + $group = str_replace( $wpdb->prefix, '', $group ); |
|
416 | 416 | |
417 | 417 | $prefix = $wpmuBaseTablePrefix ? $wpmuBaseTablePrefix : $wpdb->base_prefix; |
418 | 418 | $group = str_replace( $prefix, '', $group ); |
419 | 419 | |
420 | - if ( $group == $table ) { |
|
421 | - $table = $wpdb->prefix . $table; |
|
422 | - } |
|
420 | + if ( $group == $table ) { |
|
421 | + $table = $wpdb->prefix . $table; |
|
422 | + } |
|
423 | 423 | |
424 | 424 | // switch to singular group name |
425 | 425 | $group = rtrim( $group, 's' ); |
426 | - } |
|
426 | + } |
|
427 | 427 | |
428 | - private static function convert_options_to_array( &$args, $order_by = '', $limit = '' ) { |
|
429 | - if ( ! is_array($args) ) { |
|
428 | + private static function convert_options_to_array( &$args, $order_by = '', $limit = '' ) { |
|
429 | + if ( ! is_array($args) ) { |
|
430 | 430 | $args = array( 'order_by' => $args ); |
431 | - } |
|
431 | + } |
|
432 | 432 | |
433 | - if ( ! empty( $order_by ) ) { |
|
434 | - $args['order_by'] = $order_by; |
|
435 | - } |
|
433 | + if ( ! empty( $order_by ) ) { |
|
434 | + $args['order_by'] = $order_by; |
|
435 | + } |
|
436 | 436 | |
437 | - if ( ! empty( $limit ) ) { |
|
438 | - $args['limit'] = $limit; |
|
439 | - } |
|
437 | + if ( ! empty( $limit ) ) { |
|
438 | + $args['limit'] = $limit; |
|
439 | + } |
|
440 | 440 | |
441 | - $temp_args = $args; |
|
442 | - foreach ( $temp_args as $k => $v ) { |
|
443 | - if ( $v == '' ) { |
|
441 | + $temp_args = $args; |
|
442 | + foreach ( $temp_args as $k => $v ) { |
|
443 | + if ( $v == '' ) { |
|
444 | 444 | unset( $args[ $k ] ); |
445 | - continue; |
|
446 | - } |
|
445 | + continue; |
|
446 | + } |
|
447 | 447 | |
448 | - if ( $k == 'limit' ) { |
|
448 | + if ( $k == 'limit' ) { |
|
449 | 449 | $args[ $k ] = FrmAppHelper::esc_limit( $v ); |
450 | - } |
|
451 | - $db_name = strtoupper( str_replace( '_', ' ', $k ) ); |
|
452 | - if ( strpos( $v, $db_name ) === false ) { |
|
450 | + } |
|
451 | + $db_name = strtoupper( str_replace( '_', ' ', $k ) ); |
|
452 | + if ( strpos( $v, $db_name ) === false ) { |
|
453 | 453 | $args[ $k ] = $db_name . ' ' . $v; |
454 | - } |
|
455 | - } |
|
456 | - } |
|
454 | + } |
|
455 | + } |
|
456 | + } |
|
457 | 457 | |
458 | - public function uninstall() { |
|
458 | + public function uninstall() { |
|
459 | 459 | if ( ! current_user_can( 'administrator' ) ) { |
460 | - $frm_settings = FrmAppHelper::get_settings(); |
|
461 | - wp_die($frm_settings->admin_permission); |
|
462 | - } |
|
460 | + $frm_settings = FrmAppHelper::get_settings(); |
|
461 | + wp_die($frm_settings->admin_permission); |
|
462 | + } |
|
463 | 463 | |
464 | - global $wpdb, $wp_roles; |
|
464 | + global $wpdb, $wp_roles; |
|
465 | 465 | |
466 | 466 | $wpdb->query( 'DROP TABLE IF EXISTS ' . $this->fields ); |
467 | 467 | $wpdb->query( 'DROP TABLE IF EXISTS ' . $this->forms ); |
468 | 468 | $wpdb->query( 'DROP TABLE IF EXISTS ' . $this->entries ); |
469 | 469 | $wpdb->query( 'DROP TABLE IF EXISTS ' . $this->entry_metas ); |
470 | 470 | |
471 | - delete_option('frm_options'); |
|
472 | - delete_option('frm_db_version'); |
|
471 | + delete_option('frm_options'); |
|
472 | + delete_option('frm_db_version'); |
|
473 | 473 | |
474 | - //delete roles |
|
475 | - $frm_roles = FrmAppHelper::frm_capabilities(); |
|
476 | - $roles = get_editable_roles(); |
|
477 | - foreach ( $frm_roles as $frm_role => $frm_role_description ) { |
|
478 | - foreach ( $roles as $role => $details ) { |
|
479 | - $wp_roles->remove_cap( $role, $frm_role ); |
|
480 | - unset($role, $details); |
|
481 | - } |
|
482 | - unset($frm_role, $frm_role_description); |
|
474 | + //delete roles |
|
475 | + $frm_roles = FrmAppHelper::frm_capabilities(); |
|
476 | + $roles = get_editable_roles(); |
|
477 | + foreach ( $frm_roles as $frm_role => $frm_role_description ) { |
|
478 | + foreach ( $roles as $role => $details ) { |
|
479 | + $wp_roles->remove_cap( $role, $frm_role ); |
|
480 | + unset($role, $details); |
|
481 | + } |
|
482 | + unset($frm_role, $frm_role_description); |
|
483 | 483 | } |
484 | 484 | unset($roles, $frm_roles); |
485 | 485 | |
@@ -503,9 +503,9 @@ discard block |
||
503 | 503 | |
504 | 504 | $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->options . ' WHERE option_name LIKE %s OR option_name LIKE %s', '_transient_timeout_frm_form_fields_%', '_transient_frm_form_fields_%' ) ); |
505 | 505 | |
506 | - do_action('frm_after_uninstall'); |
|
507 | - return true; |
|
508 | - } |
|
506 | + do_action('frm_after_uninstall'); |
|
507 | + return true; |
|
508 | + } |
|
509 | 509 | |
510 | 510 | /** |
511 | 511 | * Migrate old styling settings. If sites are using the old |
@@ -544,150 +544,150 @@ discard block |
||
544 | 544 | } |
545 | 545 | } |
546 | 546 | |
547 | - /** |
|
548 | - * Change field size from character to pixel -- Multiply by 9 |
|
549 | - */ |
|
550 | - private function migrate_to_17() { |
|
551 | - global $wpdb; |
|
547 | + /** |
|
548 | + * Change field size from character to pixel -- Multiply by 9 |
|
549 | + */ |
|
550 | + private function migrate_to_17() { |
|
551 | + global $wpdb; |
|
552 | 552 | $pixel_conversion = 9; |
553 | 553 | |
554 | - // Get query arguments |
|
554 | + // Get query arguments |
|
555 | 555 | $field_types = array( 'textarea', 'text', 'number', 'email', 'url', 'rte', 'date', 'phone', 'password', 'image', 'tag', 'file' ); |
556 | 556 | $query = array( 'type' => $field_types, 'field_options like' => 's:4:"size";', 'field_options not like' => 's:4:"size";s:0:' ); |
557 | 557 | |
558 | - // Get results |
|
558 | + // Get results |
|
559 | 559 | $fields = FrmDb::get_results( $this->fields, $query, 'id, field_options' ); |
560 | 560 | |
561 | - $updated = 0; |
|
562 | - foreach ( $fields as $f ) { |
|
563 | - $f->field_options = maybe_unserialize($f->field_options); |
|
564 | - if ( empty($f->field_options['size']) || ! is_numeric($f->field_options['size']) ) { |
|
565 | - continue; |
|
566 | - } |
|
561 | + $updated = 0; |
|
562 | + foreach ( $fields as $f ) { |
|
563 | + $f->field_options = maybe_unserialize($f->field_options); |
|
564 | + if ( empty($f->field_options['size']) || ! is_numeric($f->field_options['size']) ) { |
|
565 | + continue; |
|
566 | + } |
|
567 | 567 | |
568 | 568 | $f->field_options['size'] = round( $pixel_conversion * (int) $f->field_options['size'] ); |
569 | - $f->field_options['size'] .= 'px'; |
|
570 | - $u = FrmField::update( $f->id, array( 'field_options' => $f->field_options ) ); |
|
571 | - if ( $u ) { |
|
572 | - $updated++; |
|
573 | - } |
|
574 | - unset($f); |
|
575 | - } |
|
576 | - |
|
577 | - // Change the characters in widgets to pixels |
|
578 | - $widgets = get_option('widget_frm_show_form'); |
|
579 | - if ( empty($widgets) ) { |
|
580 | - return; |
|
581 | - } |
|
582 | - |
|
583 | - $widgets = maybe_unserialize($widgets); |
|
584 | - foreach ( $widgets as $k => $widget ) { |
|
585 | - if ( ! is_array($widget) || ! isset($widget['size']) ) { |
|
586 | - continue; |
|
587 | - } |
|
569 | + $f->field_options['size'] .= 'px'; |
|
570 | + $u = FrmField::update( $f->id, array( 'field_options' => $f->field_options ) ); |
|
571 | + if ( $u ) { |
|
572 | + $updated++; |
|
573 | + } |
|
574 | + unset($f); |
|
575 | + } |
|
576 | + |
|
577 | + // Change the characters in widgets to pixels |
|
578 | + $widgets = get_option('widget_frm_show_form'); |
|
579 | + if ( empty($widgets) ) { |
|
580 | + return; |
|
581 | + } |
|
582 | + |
|
583 | + $widgets = maybe_unserialize($widgets); |
|
584 | + foreach ( $widgets as $k => $widget ) { |
|
585 | + if ( ! is_array($widget) || ! isset($widget['size']) ) { |
|
586 | + continue; |
|
587 | + } |
|
588 | 588 | $size = round( $pixel_conversion * (int) $widget['size'] ); |
589 | - $size .= 'px'; |
|
589 | + $size .= 'px'; |
|
590 | 590 | $widgets[ $k ]['size'] = $size; |
591 | - } |
|
592 | - update_option('widget_frm_show_form', $widgets); |
|
593 | - } |
|
594 | - |
|
595 | - /** |
|
596 | - * Migrate post and email notification settings into actions |
|
597 | - */ |
|
598 | - private function migrate_to_16() { |
|
599 | - global $wpdb; |
|
600 | - |
|
601 | - $forms = FrmDb::get_results( $this->forms, array(), 'id, options, is_template, default_template' ); |
|
602 | - |
|
603 | - /** |
|
604 | - * Old email settings format: |
|
605 | - * email_to: Email or field id |
|
606 | - * also_email_to: array of fields ids |
|
607 | - * reply_to: Email, field id, 'custom' |
|
608 | - * cust_reply_to: string |
|
609 | - * reply_to_name: field id, 'custom' |
|
610 | - * cust_reply_to_name: string |
|
611 | - * plain_text: 0|1 |
|
612 | - * email_message: string or '' |
|
613 | - * email_subject: string or '' |
|
614 | - * inc_user_info: 0|1 |
|
615 | - * update_email: 0, 1, 2 |
|
616 | - * |
|
617 | - * Old autoresponder settings format: |
|
618 | - * auto_responder: 0|1 |
|
619 | - * ar_email_message: string or '' |
|
620 | - * ar_email_to: field id |
|
621 | - * ar_plain_text: 0|1 |
|
622 | - * ar_reply_to_name: string |
|
623 | - * ar_reply_to: string |
|
624 | - * ar_email_subject: string |
|
625 | - * ar_update_email: 0, 1, 2 |
|
626 | - * |
|
627 | - * New email settings: |
|
628 | - * post_content: json settings |
|
629 | - * post_title: form id |
|
630 | - * post_excerpt: message |
|
631 | - * |
|
632 | - */ |
|
633 | - |
|
634 | - foreach ( $forms as $form ) { |
|
591 | + } |
|
592 | + update_option('widget_frm_show_form', $widgets); |
|
593 | + } |
|
594 | + |
|
595 | + /** |
|
596 | + * Migrate post and email notification settings into actions |
|
597 | + */ |
|
598 | + private function migrate_to_16() { |
|
599 | + global $wpdb; |
|
600 | + |
|
601 | + $forms = FrmDb::get_results( $this->forms, array(), 'id, options, is_template, default_template' ); |
|
602 | + |
|
603 | + /** |
|
604 | + * Old email settings format: |
|
605 | + * email_to: Email or field id |
|
606 | + * also_email_to: array of fields ids |
|
607 | + * reply_to: Email, field id, 'custom' |
|
608 | + * cust_reply_to: string |
|
609 | + * reply_to_name: field id, 'custom' |
|
610 | + * cust_reply_to_name: string |
|
611 | + * plain_text: 0|1 |
|
612 | + * email_message: string or '' |
|
613 | + * email_subject: string or '' |
|
614 | + * inc_user_info: 0|1 |
|
615 | + * update_email: 0, 1, 2 |
|
616 | + * |
|
617 | + * Old autoresponder settings format: |
|
618 | + * auto_responder: 0|1 |
|
619 | + * ar_email_message: string or '' |
|
620 | + * ar_email_to: field id |
|
621 | + * ar_plain_text: 0|1 |
|
622 | + * ar_reply_to_name: string |
|
623 | + * ar_reply_to: string |
|
624 | + * ar_email_subject: string |
|
625 | + * ar_update_email: 0, 1, 2 |
|
626 | + * |
|
627 | + * New email settings: |
|
628 | + * post_content: json settings |
|
629 | + * post_title: form id |
|
630 | + * post_excerpt: message |
|
631 | + * |
|
632 | + */ |
|
633 | + |
|
634 | + foreach ( $forms as $form ) { |
|
635 | 635 | if ( $form->is_template && $form->default_template ) { |
636 | 636 | // don't migrate the default templates since the email will be added anyway |
637 | 637 | continue; |
638 | 638 | } |
639 | 639 | |
640 | - // Format form options |
|
641 | - $form_options = maybe_unserialize($form->options); |
|
640 | + // Format form options |
|
641 | + $form_options = maybe_unserialize($form->options); |
|
642 | 642 | |
643 | - // Migrate settings to actions |
|
644 | - FrmXMLHelper::migrate_form_settings_to_actions( $form_options, $form->id ); |
|
645 | - } |
|
646 | - } |
|
643 | + // Migrate settings to actions |
|
644 | + FrmXMLHelper::migrate_form_settings_to_actions( $form_options, $form->id ); |
|
645 | + } |
|
646 | + } |
|
647 | 647 | |
648 | - private function migrate_to_11() { |
|
649 | - global $wpdb; |
|
648 | + private function migrate_to_11() { |
|
649 | + global $wpdb; |
|
650 | 650 | |
651 | - $forms = FrmDb::get_results( $this->forms, array(), 'id, options'); |
|
651 | + $forms = FrmDb::get_results( $this->forms, array(), 'id, options'); |
|
652 | 652 | |
653 | - $sending = __( 'Sending', 'formidable' ); |
|
653 | + $sending = __( 'Sending', 'formidable' ); |
|
654 | 654 | $img = FrmAppHelper::plugin_url() . '/images/ajax_loader.gif'; |
655 | - $old_default_html = <<<DEFAULT_HTML |
|
655 | + $old_default_html = <<<DEFAULT_HTML |
|
656 | 656 | <div class="frm_submit"> |
657 | 657 | [if back_button]<input type="submit" value="[back_label]" name="frm_prev_page" formnovalidate="formnovalidate" [back_hook] />[/if back_button] |
658 | 658 | <input type="submit" value="[button_label]" [button_action] /> |
659 | 659 | <img class="frm_ajax_loading" src="$img" alt="$sending" style="visibility:hidden;" /> |
660 | 660 | </div> |
661 | 661 | DEFAULT_HTML; |
662 | - unset($sending, $img); |
|
662 | + unset($sending, $img); |
|
663 | 663 | |
664 | - $new_default_html = FrmFormsHelper::get_default_html('submit'); |
|
665 | - $draft_link = FrmFormsHelper::get_draft_link(); |
|
664 | + $new_default_html = FrmFormsHelper::get_default_html('submit'); |
|
665 | + $draft_link = FrmFormsHelper::get_draft_link(); |
|
666 | 666 | foreach ( $forms as $form ) { |
667 | - $form->options = maybe_unserialize($form->options); |
|
668 | - if ( ! isset($form->options['submit_html']) || empty($form->options['submit_html']) ) { |
|
669 | - continue; |
|
670 | - } |
|
667 | + $form->options = maybe_unserialize($form->options); |
|
668 | + if ( ! isset($form->options['submit_html']) || empty($form->options['submit_html']) ) { |
|
669 | + continue; |
|
670 | + } |
|
671 | 671 | |
672 | - if ( $form->options['submit_html'] != $new_default_html && $form->options['submit_html'] == $old_default_html ) { |
|
673 | - $form->options['submit_html'] = $new_default_html; |
|
672 | + if ( $form->options['submit_html'] != $new_default_html && $form->options['submit_html'] == $old_default_html ) { |
|
673 | + $form->options['submit_html'] = $new_default_html; |
|
674 | 674 | $wpdb->update( $this->forms, array( 'options' => serialize( $form->options ) ), array( 'id' => $form->id ) ); |
675 | 675 | } else if ( ! strpos( $form->options['submit_html'], 'save_draft' ) ) { |
676 | 676 | $form->options['submit_html'] = preg_replace( '~\<\/div\>(?!.*\<\/div\>)~', $draft_link . "\r\n</div>", $form->options['submit_html'] ); |
677 | 677 | $wpdb->update( $this->forms, array( 'options' => serialize( $form->options ) ), array( 'id' => $form->id ) ); |
678 | - } |
|
679 | - unset($form); |
|
680 | - } |
|
681 | - unset($forms); |
|
682 | - } |
|
678 | + } |
|
679 | + unset($form); |
|
680 | + } |
|
681 | + unset($forms); |
|
682 | + } |
|
683 | 683 | |
684 | - private function migrate_to_6() { |
|
685 | - global $wpdb; |
|
684 | + private function migrate_to_6() { |
|
685 | + global $wpdb; |
|
686 | 686 | |
687 | 687 | $no_save = array_merge( FrmField::no_save_fields(), array( 'form', 'hidden', 'user_id' ) ); |
688 | 688 | $fields = FrmDb::get_results( $this->fields, array( 'type NOT' => $no_save ), 'id, field_options' ); |
689 | 689 | |
690 | - $default_html = <<<DEFAULT_HTML |
|
690 | + $default_html = <<<DEFAULT_HTML |
|
691 | 691 | <div id="frm_field_[id]_container" class="form-field [required_class] [error_class]"> |
692 | 692 | <label class="frm_pos_[label_position]">[field_name] |
693 | 693 | <span class="frm_required">[required_label]</span> |
@@ -697,7 +697,7 @@ discard block |
||
697 | 697 | </div> |
698 | 698 | DEFAULT_HTML; |
699 | 699 | |
700 | - $old_default_html = <<<DEFAULT_HTML |
|
700 | + $old_default_html = <<<DEFAULT_HTML |
|
701 | 701 | <div id="frm_field_[id]_container" class="form-field [required_class] [error_class]"> |
702 | 702 | <label class="frm_pos_[label_position]">[field_name] |
703 | 703 | <span class="frm_required">[required_label]</span> |
@@ -707,23 +707,23 @@ discard block |
||
707 | 707 | </div> |
708 | 708 | DEFAULT_HTML; |
709 | 709 | |
710 | - $new_default_html = FrmFieldsHelper::get_default_html('text'); |
|
711 | - foreach ( $fields as $field ) { |
|
712 | - $field->field_options = maybe_unserialize($field->field_options); |
|
710 | + $new_default_html = FrmFieldsHelper::get_default_html('text'); |
|
711 | + foreach ( $fields as $field ) { |
|
712 | + $field->field_options = maybe_unserialize($field->field_options); |
|
713 | 713 | if ( ! FrmField::is_option_empty( $field, 'custom_html' ) || $field->field_options['custom_html'] == $default_html || $field->field_options['custom_html'] == $old_default_html ) { |
714 | - $field->field_options['custom_html'] = $new_default_html; |
|
714 | + $field->field_options['custom_html'] = $new_default_html; |
|
715 | 715 | $wpdb->update( $this->fields, array( 'field_options' => maybe_serialize( $field->field_options ) ), array( 'id' => $field->id ) ); |
716 | - } |
|
717 | - unset($field); |
|
718 | - } |
|
719 | - unset($default_html, $old_default_html, $fields); |
|
720 | - } |
|
721 | - |
|
722 | - private function migrate_to_4() { |
|
723 | - global $wpdb; |
|
716 | + } |
|
717 | + unset($field); |
|
718 | + } |
|
719 | + unset($default_html, $old_default_html, $fields); |
|
720 | + } |
|
721 | + |
|
722 | + private function migrate_to_4() { |
|
723 | + global $wpdb; |
|
724 | 724 | $user_ids = FrmEntryMeta::getAll( array( 'fi.type' => 'user_id' ) ); |
725 | - foreach ( $user_ids as $user_id ) { |
|
725 | + foreach ( $user_ids as $user_id ) { |
|
726 | 726 | $wpdb->update( $this->entries, array( 'user_id' => $user_id->meta_value ), array( 'id' => $user_id->item_id ) ); |
727 | - } |
|
728 | - } |
|
727 | + } |
|
728 | + } |
|
729 | 729 | } |
@@ -7,8 +7,8 @@ discard block |
||
7 | 7 | var $entry_metas; |
8 | 8 | |
9 | 9 | public function __construct() { |
10 | - if ( ! defined('ABSPATH') ) { |
|
11 | - die('You are not allowed to call this page directly.'); |
|
10 | + if ( ! defined( 'ABSPATH' ) ) { |
|
11 | + die( 'You are not allowed to call this page directly.' ); |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | global $wpdb; |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | $frm_db_version = FrmAppHelper::$db_version; |
25 | 25 | $old_db_version = (float) $old_db_version; |
26 | 26 | if ( ! $old_db_version ) { |
27 | - $old_db_version = get_option('frm_db_version'); |
|
27 | + $old_db_version = get_option( 'frm_db_version' ); |
|
28 | 28 | } |
29 | 29 | |
30 | 30 | if ( $frm_db_version != $old_db_version ) { |
@@ -34,16 +34,16 @@ discard block |
||
34 | 34 | require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
35 | 35 | |
36 | 36 | $this->create_tables(); |
37 | - $this->migrate_data($frm_db_version, $old_db_version); |
|
37 | + $this->migrate_data( $frm_db_version, $old_db_version ); |
|
38 | 38 | |
39 | 39 | /***** SAVE DB VERSION *****/ |
40 | - update_option('frm_db_version', $frm_db_version); |
|
40 | + update_option( 'frm_db_version', $frm_db_version ); |
|
41 | 41 | |
42 | 42 | /**** ADD/UPDATE DEFAULT TEMPLATES ****/ |
43 | 43 | FrmXMLController::add_default_templates(); |
44 | 44 | } |
45 | 45 | |
46 | - do_action('frm_after_install'); |
|
46 | + do_action( 'frm_after_install' ); |
|
47 | 47 | |
48 | 48 | /**** update the styling settings ****/ |
49 | 49 | if ( is_admin() && function_exists( 'get_filesystem_method' ) ) { |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | global $wpdb; |
154 | 154 | $wpdb->query( $q . $charset_collate ); |
155 | 155 | } |
156 | - unset($q); |
|
156 | + unset( $q ); |
|
157 | 157 | } |
158 | 158 | } |
159 | 159 | |
@@ -174,7 +174,7 @@ discard block |
||
174 | 174 | * Change array into format $wpdb->prepare can use |
175 | 175 | */ |
176 | 176 | public static function get_where_clause_and_values( &$args, $starts_with = ' WHERE ' ) { |
177 | - if ( empty($args) ) { |
|
177 | + if ( empty( $args ) ) { |
|
178 | 178 | // add an arg to prevent prepare from failing |
179 | 179 | $args = array( 'where' => $starts_with . '1=%d', 'values' => array( 1 ) ); |
180 | 180 | return; |
@@ -230,8 +230,8 @@ discard block |
||
230 | 230 | private static function interpret_array_to_sql( $key, $value, &$where, &$values ) { |
231 | 231 | $key = trim( $key ); |
232 | 232 | |
233 | - if ( strpos( $key, 'created_at' ) !== false || strpos( $key, 'updated_at' ) !== false ) { |
|
234 | - $k = explode(' ', $key); |
|
233 | + if ( strpos( $key, 'created_at' ) !== false || strpos( $key, 'updated_at' ) !== false ) { |
|
234 | + $k = explode( ' ', $key ); |
|
235 | 235 | $where .= ' DATE_FORMAT(' . reset( $k ) . ', %s) ' . str_replace( reset( $k ), '', $key ); |
236 | 236 | $values[] = '%Y-%m-%d %H:%i:%s'; |
237 | 237 | } else { |
@@ -354,7 +354,7 @@ discard block |
||
354 | 354 | |
355 | 355 | public static function get_records( $table, $args = array(), $order_by = '', $limit = '', $fields = '*' ) { |
356 | 356 | _deprecated_function( __FUNCTION__, '2.0', 'FrmDb::get_results' ); |
357 | - return self::get_results( $table, $args, $fields, compact('order_by', 'limit') ); |
|
357 | + return self::get_results( $table, $args, $fields, compact( 'order_by', 'limit' ) ); |
|
358 | 358 | } |
359 | 359 | |
360 | 360 | /** |
@@ -387,8 +387,8 @@ discard block |
||
387 | 387 | ); |
388 | 388 | |
389 | 389 | $where_is = strtolower( $where_is ); |
390 | - if ( isset( $switch_to[ $where_is ] ) ) { |
|
391 | - return ' ' . $switch_to[ $where_is ]; |
|
390 | + if ( isset( $switch_to[$where_is] ) ) { |
|
391 | + return ' ' . $switch_to[$where_is]; |
|
392 | 392 | } |
393 | 393 | |
394 | 394 | // > and < need a little more work since we don't want them switched to >= and <= |
@@ -410,8 +410,8 @@ discard block |
||
410 | 410 | private static function get_group_and_table_name( &$table, &$group ) { |
411 | 411 | global $wpdb, $wpmuBaseTablePrefix; |
412 | 412 | |
413 | - $table_parts = explode(' ', $table); |
|
414 | - $group = reset($table_parts); |
|
413 | + $table_parts = explode( ' ', $table ); |
|
414 | + $group = reset( $table_parts ); |
|
415 | 415 | $group = str_replace( $wpdb->prefix, '', $group ); |
416 | 416 | |
417 | 417 | $prefix = $wpmuBaseTablePrefix ? $wpmuBaseTablePrefix : $wpdb->base_prefix; |
@@ -426,7 +426,7 @@ discard block |
||
426 | 426 | } |
427 | 427 | |
428 | 428 | private static function convert_options_to_array( &$args, $order_by = '', $limit = '' ) { |
429 | - if ( ! is_array($args) ) { |
|
429 | + if ( ! is_array( $args ) ) { |
|
430 | 430 | $args = array( 'order_by' => $args ); |
431 | 431 | } |
432 | 432 | |
@@ -441,16 +441,16 @@ discard block |
||
441 | 441 | $temp_args = $args; |
442 | 442 | foreach ( $temp_args as $k => $v ) { |
443 | 443 | if ( $v == '' ) { |
444 | - unset( $args[ $k ] ); |
|
444 | + unset( $args[$k] ); |
|
445 | 445 | continue; |
446 | 446 | } |
447 | 447 | |
448 | 448 | if ( $k == 'limit' ) { |
449 | - $args[ $k ] = FrmAppHelper::esc_limit( $v ); |
|
449 | + $args[$k] = FrmAppHelper::esc_limit( $v ); |
|
450 | 450 | } |
451 | 451 | $db_name = strtoupper( str_replace( '_', ' ', $k ) ); |
452 | 452 | if ( strpos( $v, $db_name ) === false ) { |
453 | - $args[ $k ] = $db_name . ' ' . $v; |
|
453 | + $args[$k] = $db_name . ' ' . $v; |
|
454 | 454 | } |
455 | 455 | } |
456 | 456 | } |
@@ -458,7 +458,7 @@ discard block |
||
458 | 458 | public function uninstall() { |
459 | 459 | if ( ! current_user_can( 'administrator' ) ) { |
460 | 460 | $frm_settings = FrmAppHelper::get_settings(); |
461 | - wp_die($frm_settings->admin_permission); |
|
461 | + wp_die( $frm_settings->admin_permission ); |
|
462 | 462 | } |
463 | 463 | |
464 | 464 | global $wpdb, $wp_roles; |
@@ -468,8 +468,8 @@ discard block |
||
468 | 468 | $wpdb->query( 'DROP TABLE IF EXISTS ' . $this->entries ); |
469 | 469 | $wpdb->query( 'DROP TABLE IF EXISTS ' . $this->entry_metas ); |
470 | 470 | |
471 | - delete_option('frm_options'); |
|
472 | - delete_option('frm_db_version'); |
|
471 | + delete_option( 'frm_options' ); |
|
472 | + delete_option( 'frm_db_version' ); |
|
473 | 473 | |
474 | 474 | //delete roles |
475 | 475 | $frm_roles = FrmAppHelper::frm_capabilities(); |
@@ -477,11 +477,11 @@ discard block |
||
477 | 477 | foreach ( $frm_roles as $frm_role => $frm_role_description ) { |
478 | 478 | foreach ( $roles as $role => $details ) { |
479 | 479 | $wp_roles->remove_cap( $role, $frm_role ); |
480 | - unset($role, $details); |
|
480 | + unset( $role, $details ); |
|
481 | 481 | } |
482 | - unset($frm_role, $frm_role_description); |
|
482 | + unset( $frm_role, $frm_role_description ); |
|
483 | 483 | } |
484 | - unset($roles, $frm_roles); |
|
484 | + unset( $roles, $frm_roles ); |
|
485 | 485 | |
486 | 486 | // delete actions, views, and styles |
487 | 487 | |
@@ -503,7 +503,7 @@ discard block |
||
503 | 503 | |
504 | 504 | $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->options . ' WHERE option_name LIKE %s OR option_name LIKE %s', '_transient_timeout_frm_form_fields_%', '_transient_frm_form_fields_%' ) ); |
505 | 505 | |
506 | - do_action('frm_after_uninstall'); |
|
506 | + do_action( 'frm_after_uninstall' ); |
|
507 | 507 | return true; |
508 | 508 | } |
509 | 509 | |
@@ -560,8 +560,8 @@ discard block |
||
560 | 560 | |
561 | 561 | $updated = 0; |
562 | 562 | foreach ( $fields as $f ) { |
563 | - $f->field_options = maybe_unserialize($f->field_options); |
|
564 | - if ( empty($f->field_options['size']) || ! is_numeric($f->field_options['size']) ) { |
|
563 | + $f->field_options = maybe_unserialize( $f->field_options ); |
|
564 | + if ( empty( $f->field_options['size'] ) || ! is_numeric( $f->field_options['size'] ) ) { |
|
565 | 565 | continue; |
566 | 566 | } |
567 | 567 | |
@@ -569,27 +569,27 @@ discard block |
||
569 | 569 | $f->field_options['size'] .= 'px'; |
570 | 570 | $u = FrmField::update( $f->id, array( 'field_options' => $f->field_options ) ); |
571 | 571 | if ( $u ) { |
572 | - $updated++; |
|
572 | + $updated ++; |
|
573 | 573 | } |
574 | - unset($f); |
|
574 | + unset( $f ); |
|
575 | 575 | } |
576 | 576 | |
577 | 577 | // Change the characters in widgets to pixels |
578 | - $widgets = get_option('widget_frm_show_form'); |
|
579 | - if ( empty($widgets) ) { |
|
578 | + $widgets = get_option( 'widget_frm_show_form' ); |
|
579 | + if ( empty( $widgets ) ) { |
|
580 | 580 | return; |
581 | 581 | } |
582 | 582 | |
583 | - $widgets = maybe_unserialize($widgets); |
|
583 | + $widgets = maybe_unserialize( $widgets ); |
|
584 | 584 | foreach ( $widgets as $k => $widget ) { |
585 | - if ( ! is_array($widget) || ! isset($widget['size']) ) { |
|
585 | + if ( ! is_array( $widget ) || ! isset( $widget['size'] ) ) { |
|
586 | 586 | continue; |
587 | 587 | } |
588 | 588 | $size = round( $pixel_conversion * (int) $widget['size'] ); |
589 | 589 | $size .= 'px'; |
590 | - $widgets[ $k ]['size'] = $size; |
|
590 | + $widgets[$k]['size'] = $size; |
|
591 | 591 | } |
592 | - update_option('widget_frm_show_form', $widgets); |
|
592 | + update_option( 'widget_frm_show_form', $widgets ); |
|
593 | 593 | } |
594 | 594 | |
595 | 595 | /** |
@@ -638,7 +638,7 @@ discard block |
||
638 | 638 | } |
639 | 639 | |
640 | 640 | // Format form options |
641 | - $form_options = maybe_unserialize($form->options); |
|
641 | + $form_options = maybe_unserialize( $form->options ); |
|
642 | 642 | |
643 | 643 | // Migrate settings to actions |
644 | 644 | FrmXMLHelper::migrate_form_settings_to_actions( $form_options, $form->id ); |
@@ -648,7 +648,7 @@ discard block |
||
648 | 648 | private function migrate_to_11() { |
649 | 649 | global $wpdb; |
650 | 650 | |
651 | - $forms = FrmDb::get_results( $this->forms, array(), 'id, options'); |
|
651 | + $forms = FrmDb::get_results( $this->forms, array(), 'id, options' ); |
|
652 | 652 | |
653 | 653 | $sending = __( 'Sending', 'formidable' ); |
654 | 654 | $img = FrmAppHelper::plugin_url() . '/images/ajax_loader.gif'; |
@@ -659,13 +659,13 @@ discard block |
||
659 | 659 | <img class="frm_ajax_loading" src="$img" alt="$sending" style="visibility:hidden;" /> |
660 | 660 | </div> |
661 | 661 | DEFAULT_HTML; |
662 | - unset($sending, $img); |
|
662 | + unset( $sending, $img ); |
|
663 | 663 | |
664 | - $new_default_html = FrmFormsHelper::get_default_html('submit'); |
|
664 | + $new_default_html = FrmFormsHelper::get_default_html( 'submit' ); |
|
665 | 665 | $draft_link = FrmFormsHelper::get_draft_link(); |
666 | 666 | foreach ( $forms as $form ) { |
667 | - $form->options = maybe_unserialize($form->options); |
|
668 | - if ( ! isset($form->options['submit_html']) || empty($form->options['submit_html']) ) { |
|
667 | + $form->options = maybe_unserialize( $form->options ); |
|
668 | + if ( ! isset( $form->options['submit_html'] ) || empty( $form->options['submit_html'] ) ) { |
|
669 | 669 | continue; |
670 | 670 | } |
671 | 671 | |
@@ -676,9 +676,9 @@ discard block |
||
676 | 676 | $form->options['submit_html'] = preg_replace( '~\<\/div\>(?!.*\<\/div\>)~', $draft_link . "\r\n</div>", $form->options['submit_html'] ); |
677 | 677 | $wpdb->update( $this->forms, array( 'options' => serialize( $form->options ) ), array( 'id' => $form->id ) ); |
678 | 678 | } |
679 | - unset($form); |
|
679 | + unset( $form ); |
|
680 | 680 | } |
681 | - unset($forms); |
|
681 | + unset( $forms ); |
|
682 | 682 | } |
683 | 683 | |
684 | 684 | private function migrate_to_6() { |
@@ -707,16 +707,16 @@ discard block |
||
707 | 707 | </div> |
708 | 708 | DEFAULT_HTML; |
709 | 709 | |
710 | - $new_default_html = FrmFieldsHelper::get_default_html('text'); |
|
710 | + $new_default_html = FrmFieldsHelper::get_default_html( 'text' ); |
|
711 | 711 | foreach ( $fields as $field ) { |
712 | - $field->field_options = maybe_unserialize($field->field_options); |
|
712 | + $field->field_options = maybe_unserialize( $field->field_options ); |
|
713 | 713 | if ( ! FrmField::is_option_empty( $field, 'custom_html' ) || $field->field_options['custom_html'] == $default_html || $field->field_options['custom_html'] == $old_default_html ) { |
714 | 714 | $field->field_options['custom_html'] = $new_default_html; |
715 | 715 | $wpdb->update( $this->fields, array( 'field_options' => maybe_serialize( $field->field_options ) ), array( 'id' => $field->id ) ); |
716 | 716 | } |
717 | - unset($field); |
|
717 | + unset( $field ); |
|
718 | 718 | } |
719 | - unset($default_html, $old_default_html, $fields); |
|
719 | + unset( $default_html, $old_default_html, $fields ); |
|
720 | 720 | } |
721 | 721 | |
722 | 722 | private function migrate_to_4() { |
@@ -2,166 +2,166 @@ discard block |
||
2 | 2 | |
3 | 3 | class FrmNotification { |
4 | 4 | public function __construct() { |
5 | - if ( ! defined('ABSPATH') ) { |
|
6 | - die('You are not allowed to call this page directly.'); |
|
7 | - } |
|
8 | - add_action('frm_trigger_email_action', 'FrmNotification::trigger_email', 10, 3); |
|
9 | - } |
|
5 | + if ( ! defined('ABSPATH') ) { |
|
6 | + die('You are not allowed to call this page directly.'); |
|
7 | + } |
|
8 | + add_action('frm_trigger_email_action', 'FrmNotification::trigger_email', 10, 3); |
|
9 | + } |
|
10 | 10 | |
11 | 11 | public static function trigger_email( $action, $entry, $form ) { |
12 | 12 | if ( defined( 'WP_IMPORTING' ) && WP_IMPORTING ) { |
13 | - return; |
|
14 | - } |
|
15 | - |
|
16 | - global $wpdb; |
|
17 | - |
|
18 | - $notification = $action->post_content; |
|
19 | - $email_key = $action->ID; |
|
20 | - |
|
21 | - // Set the subject |
|
22 | - if ( empty($notification['email_subject']) ) { |
|
23 | - $notification['email_subject'] = sprintf(__( '%1$s Form submitted on %2$s', 'formidable' ), $form->name, '[sitename]'); |
|
24 | - } |
|
25 | - |
|
26 | - $plain_text = $notification['plain_text'] ? true : false; |
|
27 | - |
|
28 | - //Filter these fields |
|
29 | - $filter_fields = array( |
|
30 | - 'email_to', 'cc', 'bcc', |
|
31 | - 'reply_to', 'from', |
|
32 | - 'email_subject', 'email_message', |
|
33 | - ); |
|
34 | - |
|
35 | - add_filter('frm_plain_text_email', ($plain_text ? '__return_true' : '__return_false')); |
|
36 | - |
|
37 | - //Get all values in entry in order to get User ID field ID |
|
38 | - $values = FrmEntryMeta::getAll( array( 'it.field_id !' => 0, 'it.item_id' => $entry->id ), ' ORDER BY fi.field_order' ); |
|
39 | - $user_id_field = $user_id_key = ''; |
|
40 | - foreach ( $values as $value ) { |
|
41 | - if ( $value->field_type == 'user_id' ) { |
|
42 | - $user_id_field = $value->field_id; |
|
43 | - $user_id_key = $value->field_key; |
|
44 | - break; |
|
45 | - } |
|
46 | - unset($value); |
|
47 | - } |
|
48 | - |
|
49 | - //Filter and prepare the email fields |
|
50 | - foreach ( $filter_fields as $f ) { |
|
51 | - //Don't allow empty From |
|
13 | + return; |
|
14 | + } |
|
15 | + |
|
16 | + global $wpdb; |
|
17 | + |
|
18 | + $notification = $action->post_content; |
|
19 | + $email_key = $action->ID; |
|
20 | + |
|
21 | + // Set the subject |
|
22 | + if ( empty($notification['email_subject']) ) { |
|
23 | + $notification['email_subject'] = sprintf(__( '%1$s Form submitted on %2$s', 'formidable' ), $form->name, '[sitename]'); |
|
24 | + } |
|
25 | + |
|
26 | + $plain_text = $notification['plain_text'] ? true : false; |
|
27 | + |
|
28 | + //Filter these fields |
|
29 | + $filter_fields = array( |
|
30 | + 'email_to', 'cc', 'bcc', |
|
31 | + 'reply_to', 'from', |
|
32 | + 'email_subject', 'email_message', |
|
33 | + ); |
|
34 | + |
|
35 | + add_filter('frm_plain_text_email', ($plain_text ? '__return_true' : '__return_false')); |
|
36 | + |
|
37 | + //Get all values in entry in order to get User ID field ID |
|
38 | + $values = FrmEntryMeta::getAll( array( 'it.field_id !' => 0, 'it.item_id' => $entry->id ), ' ORDER BY fi.field_order' ); |
|
39 | + $user_id_field = $user_id_key = ''; |
|
40 | + foreach ( $values as $value ) { |
|
41 | + if ( $value->field_type == 'user_id' ) { |
|
42 | + $user_id_field = $value->field_id; |
|
43 | + $user_id_key = $value->field_key; |
|
44 | + break; |
|
45 | + } |
|
46 | + unset($value); |
|
47 | + } |
|
48 | + |
|
49 | + //Filter and prepare the email fields |
|
50 | + foreach ( $filter_fields as $f ) { |
|
51 | + //Don't allow empty From |
|
52 | 52 | if ( $f == 'from' && empty( $notification[ $f ] ) ) { |
53 | 53 | $notification[ $f ] = '[admin_email]'; |
54 | 54 | } else if ( in_array( $f, array( 'email_to', 'cc', 'bcc', 'reply_to', 'from' ) ) ) { |
55 | 55 | //Remove brackets |
56 | - //Add a space in case there isn't one |
|
56 | + //Add a space in case there isn't one |
|
57 | 57 | $notification[ $f ] = str_replace( '<', ' ', $notification[ $f ] ); |
58 | 58 | $notification[ $f ] = str_replace( array( '"', '>' ), '', $notification[ $f ] ); |
59 | 59 | |
60 | - //Switch userID shortcode to email address |
|
60 | + //Switch userID shortcode to email address |
|
61 | 61 | if ( strpos( $notification[ $f ], '[' . $user_id_field . ']' ) !== false || strpos( $notification[ $f ], '[' . $user_id_key . ']' ) !== false ) { |
62 | 62 | $user_data = get_userdata( $entry->metas[ $user_id_field ] ); |
63 | - $user_email = $user_data->user_email; |
|
63 | + $user_email = $user_data->user_email; |
|
64 | 64 | $notification[ $f ] = str_replace( array( '[' . $user_id_field . ']', '[' . $user_id_key . ']' ), $user_email, $notification[ $f ] ); |
65 | - } |
|
66 | - } |
|
65 | + } |
|
66 | + } |
|
67 | 67 | |
68 | 68 | $notification[ $f ] = FrmFieldsHelper::basic_replace_shortcodes( $notification[ $f ], $form, $entry ); |
69 | - } |
|
69 | + } |
|
70 | 70 | |
71 | - //Put recipients, cc, and bcc into an array if they aren't empty |
|
71 | + //Put recipients, cc, and bcc into an array if they aren't empty |
|
72 | 72 | $to_emails = self::explode_emails( $notification['email_to'] ); |
73 | 73 | $cc = self::explode_emails( $notification['cc'] ); |
74 | 74 | $bcc = self::explode_emails( $notification['bcc'] ); |
75 | 75 | |
76 | - $to_emails = apply_filters('frm_to_email', $to_emails, $values, $form->id, compact('email_key', 'entry', 'form')); |
|
76 | + $to_emails = apply_filters('frm_to_email', $to_emails, $values, $form->id, compact('email_key', 'entry', 'form')); |
|
77 | 77 | |
78 | - // Stop now if there aren't any recipients |
|
79 | - if ( empty( $to_emails ) && empty( $cc ) && empty( $bcc ) ) { |
|
80 | - return; |
|
81 | - } |
|
78 | + // Stop now if there aren't any recipients |
|
79 | + if ( empty( $to_emails ) && empty( $cc ) && empty( $bcc ) ) { |
|
80 | + return; |
|
81 | + } |
|
82 | 82 | |
83 | - $to_emails = array_unique( (array) $to_emails ); |
|
83 | + $to_emails = array_unique( (array) $to_emails ); |
|
84 | 84 | |
85 | - $prev_mail_body = $mail_body = $notification['email_message']; |
|
86 | - $mail_body = FrmEntriesHelper::replace_default_message($mail_body, array( |
|
87 | - 'id' => $entry->id, 'entry' => $entry, 'plain_text' => $plain_text, |
|
88 | - 'user_info' => (isset($notification['inc_user_info']) ? $notification['inc_user_info'] : false), |
|
89 | - ) ); |
|
85 | + $prev_mail_body = $mail_body = $notification['email_message']; |
|
86 | + $mail_body = FrmEntriesHelper::replace_default_message($mail_body, array( |
|
87 | + 'id' => $entry->id, 'entry' => $entry, 'plain_text' => $plain_text, |
|
88 | + 'user_info' => (isset($notification['inc_user_info']) ? $notification['inc_user_info'] : false), |
|
89 | + ) ); |
|
90 | 90 | |
91 | - // Add the user info if it isn't already included |
|
92 | - if ( $notification['inc_user_info'] && $prev_mail_body == $mail_body ) { |
|
93 | - $data = maybe_unserialize($entry->description); |
|
91 | + // Add the user info if it isn't already included |
|
92 | + if ( $notification['inc_user_info'] && $prev_mail_body == $mail_body ) { |
|
93 | + $data = maybe_unserialize($entry->description); |
|
94 | 94 | $mail_body .= "\r\n\r\n" . __( 'User Information', 'formidable' ) . "\r\n"; |
95 | 95 | $mail_body .= __( 'IP Address', 'formidable' ) . ': ' . $entry->ip . "\r\n"; |
96 | 96 | $mail_body .= __( 'User-Agent (Browser/OS)', 'formidable' ) . ': ' . FrmEntryFormat::get_browser( $data['browser'] ) . "\r\n"; |
97 | 97 | $mail_body .= __( 'Referrer', 'formidable' ) . ': ' . $data['referrer'] . "\r\n"; |
98 | - } |
|
99 | - unset($prev_mail_body); |
|
100 | - |
|
101 | - // Add attachments |
|
102 | - $attachments = apply_filters('frm_notification_attachment', array(), $form, compact('entry', 'email_key') ); |
|
103 | - |
|
104 | - if ( ! empty($notification['email_subject']) ) { |
|
105 | - $notification['email_subject'] = apply_filters('frm_email_subject', $notification['email_subject'], compact('form', 'entry', 'email_key')); |
|
106 | - } |
|
107 | - |
|
108 | - // check for a phone number |
|
109 | - foreach ( (array) $to_emails as $email_key => $e ) { |
|
110 | - if ( $e != '[admin_email]' && ! is_email($e) ) { |
|
111 | - $e = explode(' ', $e); |
|
112 | - |
|
113 | - //If to_email has name <[email protected]> format |
|
114 | - if ( is_email(end($e)) ) { |
|
115 | - continue; |
|
116 | - } |
|
117 | - |
|
118 | - do_action('frm_send_to_not_email', array( |
|
119 | - 'e' => $e, |
|
120 | - 'subject' => $notification['email_subject'], |
|
121 | - 'mail_body' => $mail_body, |
|
122 | - 'reply_to' => $notification['reply_to'], |
|
123 | - 'from' => $notification['from'], |
|
124 | - 'plain_text' => $plain_text, |
|
125 | - 'attachments' => $attachments, |
|
126 | - 'form' => $form, |
|
127 | - 'email_key' => $email_key, |
|
128 | - ) ); |
|
98 | + } |
|
99 | + unset($prev_mail_body); |
|
100 | + |
|
101 | + // Add attachments |
|
102 | + $attachments = apply_filters('frm_notification_attachment', array(), $form, compact('entry', 'email_key') ); |
|
103 | + |
|
104 | + if ( ! empty($notification['email_subject']) ) { |
|
105 | + $notification['email_subject'] = apply_filters('frm_email_subject', $notification['email_subject'], compact('form', 'entry', 'email_key')); |
|
106 | + } |
|
107 | + |
|
108 | + // check for a phone number |
|
109 | + foreach ( (array) $to_emails as $email_key => $e ) { |
|
110 | + if ( $e != '[admin_email]' && ! is_email($e) ) { |
|
111 | + $e = explode(' ', $e); |
|
112 | + |
|
113 | + //If to_email has name <[email protected]> format |
|
114 | + if ( is_email(end($e)) ) { |
|
115 | + continue; |
|
116 | + } |
|
117 | + |
|
118 | + do_action('frm_send_to_not_email', array( |
|
119 | + 'e' => $e, |
|
120 | + 'subject' => $notification['email_subject'], |
|
121 | + 'mail_body' => $mail_body, |
|
122 | + 'reply_to' => $notification['reply_to'], |
|
123 | + 'from' => $notification['from'], |
|
124 | + 'plain_text' => $plain_text, |
|
125 | + 'attachments' => $attachments, |
|
126 | + 'form' => $form, |
|
127 | + 'email_key' => $email_key, |
|
128 | + ) ); |
|
129 | 129 | |
130 | 130 | unset( $to_emails[ $email_key ] ); |
131 | - } |
|
132 | - } |
|
133 | - |
|
134 | - // Send the email now |
|
135 | - $sent_to = self::send_email( array( |
|
136 | - 'to_email' => $to_emails, |
|
137 | - 'subject' => $notification['email_subject'], |
|
138 | - 'message' => $mail_body, |
|
139 | - 'from' => $notification['from'], |
|
140 | - 'plain_text' => $plain_text, |
|
141 | - 'reply_to' => $notification['reply_to'], |
|
142 | - 'attachments' => $attachments, |
|
143 | - 'cc' => $cc, |
|
144 | - 'bcc' => $bcc, |
|
145 | - ) ); |
|
146 | - |
|
147 | - return $sent_to; |
|
148 | - } |
|
131 | + } |
|
132 | + } |
|
133 | + |
|
134 | + // Send the email now |
|
135 | + $sent_to = self::send_email( array( |
|
136 | + 'to_email' => $to_emails, |
|
137 | + 'subject' => $notification['email_subject'], |
|
138 | + 'message' => $mail_body, |
|
139 | + 'from' => $notification['from'], |
|
140 | + 'plain_text' => $plain_text, |
|
141 | + 'reply_to' => $notification['reply_to'], |
|
142 | + 'attachments' => $attachments, |
|
143 | + 'cc' => $cc, |
|
144 | + 'bcc' => $bcc, |
|
145 | + ) ); |
|
146 | + |
|
147 | + return $sent_to; |
|
148 | + } |
|
149 | 149 | |
150 | 150 | public function entry_created( $entry_id, $form_id ) { |
151 | 151 | $new_function = 'FrmFormActionsController::trigger_actions("create", ' . $form_id . ', ' . $entry_id . ', "email")'; |
152 | 152 | _deprecated_function( __FUNCTION__, '2.0', $new_function ); |
153 | - FrmFormActionsController::trigger_actions('create', $form_id, $entry_id, 'email'); |
|
154 | - } |
|
153 | + FrmFormActionsController::trigger_actions('create', $form_id, $entry_id, 'email'); |
|
154 | + } |
|
155 | 155 | |
156 | 156 | public function send_notification_email( $to_email, $subject, $message, $from = '', $from_name = '', $plain_text = true, $attachments = array(), $reply_to = '' ) { |
157 | - _deprecated_function( __FUNCTION__, '2.0', 'FrmNotification::send_email' ); |
|
157 | + _deprecated_function( __FUNCTION__, '2.0', 'FrmNotification::send_email' ); |
|
158 | 158 | |
159 | - return self::send_email(compact( |
|
160 | - 'to_email', 'subject', 'message', |
|
161 | - 'from', 'from_name', 'plain_text', |
|
162 | - 'attachments', 'reply_to' |
|
163 | - )); |
|
164 | - } |
|
159 | + return self::send_email(compact( |
|
160 | + 'to_email', 'subject', 'message', |
|
161 | + 'from', 'from_name', 'plain_text', |
|
162 | + 'attachments', 'reply_to' |
|
163 | + )); |
|
164 | + } |
|
165 | 165 | |
166 | 166 | /** |
167 | 167 | * Extract the emails from cc and bcc. Allow separation by , or ;. |
@@ -179,53 +179,53 @@ discard block |
||
179 | 179 | return $emails; |
180 | 180 | } |
181 | 181 | |
182 | - /** |
|
183 | - * Put To, BCC, CC, Reply To, and From fields in Name <[email protected]> format |
|
184 | - * Formats that should work: Name, "Name", [email protected], <[email protected]>, Name <[email protected]>, |
|
185 | - * "Name" <[email protected]>, Name [email protected], "Name" [email protected], Name<[email protected]>, "Name"<[email protected]> |
|
186 | - * "First Last" <[email protected]> |
|
187 | - * |
|
188 | - * Things that won't work: First Last (with no email entered) |
|
189 | - * @since 2.0 |
|
190 | - * @param array $atts array of email fields, pass by reference |
|
191 | - * @param $admin_email |
|
192 | - */ |
|
193 | - private static function format_email_fields( &$atts, $admin_email ) { |
|
194 | - |
|
195 | - // If from is empty or is set to admin_email, set it now |
|
196 | - $atts['from'] = ( empty($atts['from']) || $atts['from'] == '[admin_email]' ) ? $admin_email : $atts['from']; |
|
197 | - |
|
198 | - // Filter values in these fields |
|
182 | + /** |
|
183 | + * Put To, BCC, CC, Reply To, and From fields in Name <[email protected]> format |
|
184 | + * Formats that should work: Name, "Name", [email protected], <[email protected]>, Name <[email protected]>, |
|
185 | + * "Name" <[email protected]>, Name [email protected], "Name" [email protected], Name<[email protected]>, "Name"<[email protected]> |
|
186 | + * "First Last" <[email protected]> |
|
187 | + * |
|
188 | + * Things that won't work: First Last (with no email entered) |
|
189 | + * @since 2.0 |
|
190 | + * @param array $atts array of email fields, pass by reference |
|
191 | + * @param $admin_email |
|
192 | + */ |
|
193 | + private static function format_email_fields( &$atts, $admin_email ) { |
|
194 | + |
|
195 | + // If from is empty or is set to admin_email, set it now |
|
196 | + $atts['from'] = ( empty($atts['from']) || $atts['from'] == '[admin_email]' ) ? $admin_email : $atts['from']; |
|
197 | + |
|
198 | + // Filter values in these fields |
|
199 | 199 | $filter_fields = array( 'to_email', 'bcc', 'cc', 'from', 'reply_to' ); |
200 | 200 | |
201 | - foreach ( $filter_fields as $f ) { |
|
202 | - // If empty, just skip it |
|
201 | + foreach ( $filter_fields as $f ) { |
|
202 | + // If empty, just skip it |
|
203 | 203 | if ( empty( $atts[ $f ] ) ) { |
204 | - continue; |
|
205 | - } |
|
204 | + continue; |
|
205 | + } |
|
206 | 206 | |
207 | - // to_email, cc, and bcc can be an array |
|
207 | + // to_email, cc, and bcc can be an array |
|
208 | 208 | if ( is_array( $atts[ $f ] ) ) { |
209 | 209 | foreach ( $atts[ $f ] as $key => $val ) { |
210 | - self::format_single_field( $atts, $f, $val, $key ); |
|
211 | - unset( $key, $val ); |
|
212 | - } |
|
213 | - unset($f); |
|
214 | - continue; |
|
215 | - } |
|
210 | + self::format_single_field( $atts, $f, $val, $key ); |
|
211 | + unset( $key, $val ); |
|
212 | + } |
|
213 | + unset($f); |
|
214 | + continue; |
|
215 | + } |
|
216 | 216 | |
217 | 217 | self::format_single_field( $atts, $f, $atts[ $f ] ); |
218 | - } |
|
218 | + } |
|
219 | 219 | |
220 | - // If reply-to isn't set, make it match the from settings |
|
221 | - if ( empty( $atts['reply_to'] ) ) { |
|
222 | - $atts['reply_to'] = self::get_email_from_formatted_string( $atts['from'] ); |
|
223 | - } |
|
220 | + // If reply-to isn't set, make it match the from settings |
|
221 | + if ( empty( $atts['reply_to'] ) ) { |
|
222 | + $atts['reply_to'] = self::get_email_from_formatted_string( $atts['from'] ); |
|
223 | + } |
|
224 | 224 | |
225 | - if ( ! is_array($atts['to_email']) && '[admin_email]' == $atts['to_email'] ) { |
|
226 | - $atts['to_email'] = $admin_email; |
|
227 | - } |
|
228 | - } |
|
225 | + if ( ! is_array($atts['to_email']) && '[admin_email]' == $atts['to_email'] ) { |
|
226 | + $atts['to_email'] = $admin_email; |
|
227 | + } |
|
228 | + } |
|
229 | 229 | |
230 | 230 | private static function get_email_from_formatted_string( $value ) { |
231 | 231 | if ( strpos( $value, '<' ) !== false ) { |
@@ -235,48 +235,48 @@ discard block |
||
235 | 235 | return $value; |
236 | 236 | } |
237 | 237 | |
238 | - /** |
|
239 | - * Format individual email fields |
|
240 | - * |
|
241 | - * @since 2.0 |
|
242 | - * @param array $atts pass by reference |
|
243 | - * @param string $f (to, from, reply_to, etc) |
|
244 | - * @param string $val value saved in field |
|
245 | - * @param int $key if in array, this will be set |
|
246 | - */ |
|
247 | - private static function format_single_field( &$atts, $f, $val, $key = false ) { |
|
248 | - $val = trim($val); |
|
249 | - |
|
250 | - // If just a plain email is used |
|
251 | - if ( is_email($val) ) { |
|
252 | - // add sender's name if not included in $from |
|
253 | - if ( $f == 'from' ) { |
|
238 | + /** |
|
239 | + * Format individual email fields |
|
240 | + * |
|
241 | + * @since 2.0 |
|
242 | + * @param array $atts pass by reference |
|
243 | + * @param string $f (to, from, reply_to, etc) |
|
244 | + * @param string $val value saved in field |
|
245 | + * @param int $key if in array, this will be set |
|
246 | + */ |
|
247 | + private static function format_single_field( &$atts, $f, $val, $key = false ) { |
|
248 | + $val = trim($val); |
|
249 | + |
|
250 | + // If just a plain email is used |
|
251 | + if ( is_email($val) ) { |
|
252 | + // add sender's name if not included in $from |
|
253 | + if ( $f == 'from' ) { |
|
254 | 254 | $part_2 = $atts[ $f ]; |
255 | - $part_1 = $atts['from_name'] ? $atts['from_name'] : wp_specialchars_decode( FrmAppHelper::site_name(), ENT_QUOTES ); |
|
256 | - } else { |
|
257 | - return; |
|
258 | - } |
|
259 | - } else { |
|
260 | - $parts = explode(' ', $val); |
|
261 | - $part_2 = end($parts); |
|
262 | - |
|
263 | - // If inputted correcly, $part_2 should be an email |
|
264 | - if ( is_email( $part_2 ) ) { |
|
265 | - $part_1 = trim( str_replace( $part_2, '', $val ) ); |
|
266 | - } else if ( in_array( $f, array( 'from', 'reply_to' ) ) ) { |
|
255 | + $part_1 = $atts['from_name'] ? $atts['from_name'] : wp_specialchars_decode( FrmAppHelper::site_name(), ENT_QUOTES ); |
|
256 | + } else { |
|
257 | + return; |
|
258 | + } |
|
259 | + } else { |
|
260 | + $parts = explode(' ', $val); |
|
261 | + $part_2 = end($parts); |
|
262 | + |
|
263 | + // If inputted correcly, $part_2 should be an email |
|
264 | + if ( is_email( $part_2 ) ) { |
|
265 | + $part_1 = trim( str_replace( $part_2, '', $val ) ); |
|
266 | + } else if ( in_array( $f, array( 'from', 'reply_to' ) ) ) { |
|
267 | 267 | // In case someone just puts a name in the From or Reply To field |
268 | 268 | $part_1 = $val; |
269 | - $part_2 = get_option('admin_email'); |
|
270 | - } else { |
|
269 | + $part_2 = get_option('admin_email'); |
|
270 | + } else { |
|
271 | 271 | // In case someone just puts a name in any other email field |
272 | - if ( false !== $key ) { |
|
272 | + if ( false !== $key ) { |
|
273 | 273 | unset( $atts[ $f ][ $key ] ); |
274 | - return; |
|
275 | - } |
|
274 | + return; |
|
275 | + } |
|
276 | 276 | $atts[ $f ] = ''; |
277 | - return; |
|
278 | - } |
|
279 | - } |
|
277 | + return; |
|
278 | + } |
|
279 | + } |
|
280 | 280 | |
281 | 281 | // if sending the email from a yahoo address, change it to the WordPress default |
282 | 282 | if ( $f == 'from' && strpos( $part_2, '@yahoo.com' ) ) { |
@@ -289,110 +289,110 @@ discard block |
||
289 | 289 | $part_2 = 'wordpress@' . $sitename; |
290 | 290 | } |
291 | 291 | |
292 | - // Set up formatted value |
|
292 | + // Set up formatted value |
|
293 | 293 | $final_val = str_replace( '"', '', $part_1 ) . ' <' . $part_2 . '>'; |
294 | 294 | |
295 | - // If value is an array |
|
296 | - if ( false !== $key ) { |
|
295 | + // If value is an array |
|
296 | + if ( false !== $key ) { |
|
297 | 297 | $atts[ $f ][ $key ] = $final_val; |
298 | - return; |
|
299 | - } |
|
298 | + return; |
|
299 | + } |
|
300 | 300 | $atts[ $f ] = $final_val; |
301 | - } |
|
301 | + } |
|
302 | 302 | |
303 | 303 | public static function send_email( $atts ) { |
304 | - $admin_email = get_option('admin_email'); |
|
305 | - $defaults = array( |
|
306 | - 'to_email' => $admin_email, |
|
307 | - 'subject' => '', |
|
308 | - 'message' => '', |
|
309 | - 'from' => $admin_email, |
|
310 | - 'from_name' => '', |
|
311 | - 'cc' => '', |
|
312 | - 'bcc' => '', |
|
313 | - 'plain_text' => true, |
|
314 | - 'reply_to' => $admin_email, |
|
315 | - 'attachments' => array(), |
|
316 | - ); |
|
317 | - $atts = wp_parse_args($atts, $defaults); |
|
318 | - |
|
319 | - // Put To, BCC, CC, Reply To, and From fields in the correct format |
|
320 | - self::format_email_fields( $atts, $admin_email ); |
|
321 | - |
|
322 | - $recipient = $atts['to_email']; //recipient |
|
323 | - $header = array(); |
|
324 | - $header[] = 'From: ' . $atts['from']; |
|
325 | - |
|
326 | - //Allow for cc and bcc arrays |
|
304 | + $admin_email = get_option('admin_email'); |
|
305 | + $defaults = array( |
|
306 | + 'to_email' => $admin_email, |
|
307 | + 'subject' => '', |
|
308 | + 'message' => '', |
|
309 | + 'from' => $admin_email, |
|
310 | + 'from_name' => '', |
|
311 | + 'cc' => '', |
|
312 | + 'bcc' => '', |
|
313 | + 'plain_text' => true, |
|
314 | + 'reply_to' => $admin_email, |
|
315 | + 'attachments' => array(), |
|
316 | + ); |
|
317 | + $atts = wp_parse_args($atts, $defaults); |
|
318 | + |
|
319 | + // Put To, BCC, CC, Reply To, and From fields in the correct format |
|
320 | + self::format_email_fields( $atts, $admin_email ); |
|
321 | + |
|
322 | + $recipient = $atts['to_email']; //recipient |
|
323 | + $header = array(); |
|
324 | + $header[] = 'From: ' . $atts['from']; |
|
325 | + |
|
326 | + //Allow for cc and bcc arrays |
|
327 | 327 | $array_fields = array( 'CC' => $atts['cc'], 'BCC' => $atts['bcc'] ); |
328 | 328 | $cc = array( 'CC' => array(), 'BCC' => array() ); |
329 | - foreach ( $array_fields as $key => $a_field ) { |
|
330 | - if ( empty($a_field) ) { |
|
331 | - continue; |
|
332 | - } |
|
329 | + foreach ( $array_fields as $key => $a_field ) { |
|
330 | + if ( empty($a_field) ) { |
|
331 | + continue; |
|
332 | + } |
|
333 | 333 | |
334 | 334 | foreach ( (array) $a_field as $email ) { |
335 | 335 | $cc[ $key ][] = $email; |
336 | - } |
|
337 | - unset($key, $a_field); |
|
338 | - } |
|
336 | + } |
|
337 | + unset($key, $a_field); |
|
338 | + } |
|
339 | 339 | $cc = array_filter( $cc ); // remove cc and bcc if they are empty |
340 | 340 | |
341 | 341 | foreach ( $cc as $k => $v ) { |
342 | 342 | $header[] = $k . ': ' . implode( ',', $v ); |
343 | 343 | } |
344 | 344 | |
345 | - $content_type = $atts['plain_text'] ? 'text/plain' : 'text/html'; |
|
346 | - $charset = get_option('blog_charset'); |
|
345 | + $content_type = $atts['plain_text'] ? 'text/plain' : 'text/html'; |
|
346 | + $charset = get_option('blog_charset'); |
|
347 | 347 | |
348 | 348 | $header[] = 'Reply-To: ' . $atts['reply_to']; |
349 | 349 | $header[] = 'Content-Type: ' . $content_type . '; charset="' . esc_attr( $charset ) . '"'; |
350 | - $atts['subject'] = wp_specialchars_decode(strip_tags(stripslashes($atts['subject'])), ENT_QUOTES ); |
|
350 | + $atts['subject'] = wp_specialchars_decode(strip_tags(stripslashes($atts['subject'])), ENT_QUOTES ); |
|
351 | 351 | |
352 | - $message = do_shortcode($atts['message']); |
|
352 | + $message = do_shortcode($atts['message']); |
|
353 | 353 | |
354 | - if ( $atts['plain_text'] ) { |
|
355 | - //$message = wordwrap($message, 70, "\r\n"); //in case any lines are longer than 70 chars |
|
356 | - $message = wp_specialchars_decode(strip_tags($message), ENT_QUOTES ); |
|
357 | - } else { |
|
354 | + if ( $atts['plain_text'] ) { |
|
355 | + //$message = wordwrap($message, 70, "\r\n"); //in case any lines are longer than 70 chars |
|
356 | + $message = wp_specialchars_decode(strip_tags($message), ENT_QUOTES ); |
|
357 | + } else { |
|
358 | 358 | // remove line breaks in HTML emails to prevent conflicts with Mandrill |
359 | - add_filter( 'mandrill_nl2br', 'FrmNotification::remove_mandrill_br' ); |
|
360 | - } |
|
359 | + add_filter( 'mandrill_nl2br', 'FrmNotification::remove_mandrill_br' ); |
|
360 | + } |
|
361 | 361 | $message = apply_filters( 'frm_email_message', $message, $atts ); |
362 | 362 | |
363 | - $header = apply_filters('frm_email_header', $header, array( |
|
363 | + $header = apply_filters('frm_email_header', $header, array( |
|
364 | 364 | 'to_email' => $atts['to_email'], 'subject' => $atts['subject'], |
365 | 365 | ) ); |
366 | 366 | |
367 | - if ( apply_filters('frm_encode_subject', 1, $atts['subject'] ) ) { |
|
367 | + if ( apply_filters('frm_encode_subject', 1, $atts['subject'] ) ) { |
|
368 | 368 | $atts['subject'] = '=?' . $charset . '?B?' . base64_encode( $atts['subject'] ) . '?='; |
369 | - } |
|
369 | + } |
|
370 | 370 | |
371 | - remove_filter('wp_mail_from', 'bp_core_email_from_address_filter' ); |
|
372 | - remove_filter('wp_mail_from_name', 'bp_core_email_from_name_filter'); |
|
371 | + remove_filter('wp_mail_from', 'bp_core_email_from_address_filter' ); |
|
372 | + remove_filter('wp_mail_from_name', 'bp_core_email_from_name_filter'); |
|
373 | 373 | |
374 | - $sent = wp_mail($recipient, $atts['subject'], $message, $header, $atts['attachments']); |
|
375 | - if ( ! $sent ) { |
|
374 | + $sent = wp_mail($recipient, $atts['subject'], $message, $header, $atts['attachments']); |
|
375 | + if ( ! $sent ) { |
|
376 | 376 | $header = 'From: ' . $atts['from'] . "\r\n"; |
377 | - $recipient = implode(',', (array) $recipient); |
|
378 | - $sent = mail($recipient, $atts['subject'], $message, $header); |
|
379 | - } |
|
377 | + $recipient = implode(',', (array) $recipient); |
|
378 | + $sent = mail($recipient, $atts['subject'], $message, $header); |
|
379 | + } |
|
380 | 380 | |
381 | 381 | // remove the filter now so other emails can still use it |
382 | 382 | remove_filter( 'mandrill_nl2br', 'FrmNotification::remove_mandrill_br' ); |
383 | 383 | |
384 | - do_action('frm_notification', $recipient, $atts['subject'], $message); |
|
384 | + do_action('frm_notification', $recipient, $atts['subject'], $message); |
|
385 | 385 | |
386 | - if ( $sent ) { |
|
386 | + if ( $sent ) { |
|
387 | 387 | $sent_to = array_merge( (array) $atts['to_email'], (array) $atts['cc'], (array) $atts['bcc'] ); |
388 | - $sent_to = array_filter( $sent_to ); |
|
389 | - if ( apply_filters('frm_echo_emails', false) ) { |
|
390 | - $temp = str_replace('<', '<', $sent_to); |
|
388 | + $sent_to = array_filter( $sent_to ); |
|
389 | + if ( apply_filters('frm_echo_emails', false) ) { |
|
390 | + $temp = str_replace('<', '<', $sent_to); |
|
391 | 391 | echo ' ' . FrmAppHelper::kses( implode(', ', (array) $temp ) ); |
392 | - } |
|
393 | - return $sent_to; |
|
394 | - } |
|
395 | - } |
|
392 | + } |
|
393 | + return $sent_to; |
|
394 | + } |
|
395 | + } |
|
396 | 396 | |
397 | 397 | /** |
398 | 398 | * This function should only be fired when Mandrill is sending an HTML email |
@@ -2,14 +2,14 @@ discard block |
||
2 | 2 | |
3 | 3 | class FrmNotification { |
4 | 4 | public function __construct() { |
5 | - if ( ! defined('ABSPATH') ) { |
|
6 | - die('You are not allowed to call this page directly.'); |
|
5 | + if ( ! defined( 'ABSPATH' ) ) { |
|
6 | + die( 'You are not allowed to call this page directly.' ); |
|
7 | 7 | } |
8 | - add_action('frm_trigger_email_action', 'FrmNotification::trigger_email', 10, 3); |
|
8 | + add_action( 'frm_trigger_email_action', 'FrmNotification::trigger_email', 10, 3 ); |
|
9 | 9 | } |
10 | 10 | |
11 | 11 | public static function trigger_email( $action, $entry, $form ) { |
12 | - if ( defined( 'WP_IMPORTING' ) && WP_IMPORTING ) { |
|
12 | + if ( defined( 'WP_IMPORTING' ) && WP_IMPORTING ) { |
|
13 | 13 | return; |
14 | 14 | } |
15 | 15 | |
@@ -19,8 +19,8 @@ discard block |
||
19 | 19 | $email_key = $action->ID; |
20 | 20 | |
21 | 21 | // Set the subject |
22 | - if ( empty($notification['email_subject']) ) { |
|
23 | - $notification['email_subject'] = sprintf(__( '%1$s Form submitted on %2$s', 'formidable' ), $form->name, '[sitename]'); |
|
22 | + if ( empty( $notification['email_subject'] ) ) { |
|
23 | + $notification['email_subject'] = sprintf( __( '%1$s Form submitted on %2$s', 'formidable' ), $form->name, '[sitename]' ); |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | $plain_text = $notification['plain_text'] ? true : false; |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | 'email_subject', 'email_message', |
33 | 33 | ); |
34 | 34 | |
35 | - add_filter('frm_plain_text_email', ($plain_text ? '__return_true' : '__return_false')); |
|
35 | + add_filter( 'frm_plain_text_email', ( $plain_text ? '__return_true' : '__return_false' ) ); |
|
36 | 36 | |
37 | 37 | //Get all values in entry in order to get User ID field ID |
38 | 38 | $values = FrmEntryMeta::getAll( array( 'it.field_id !' => 0, 'it.item_id' => $entry->id ), ' ORDER BY fi.field_order' ); |
@@ -43,29 +43,29 @@ discard block |
||
43 | 43 | $user_id_key = $value->field_key; |
44 | 44 | break; |
45 | 45 | } |
46 | - unset($value); |
|
46 | + unset( $value ); |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | //Filter and prepare the email fields |
50 | 50 | foreach ( $filter_fields as $f ) { |
51 | 51 | //Don't allow empty From |
52 | - if ( $f == 'from' && empty( $notification[ $f ] ) ) { |
|
53 | - $notification[ $f ] = '[admin_email]'; |
|
52 | + if ( $f == 'from' && empty( $notification[$f] ) ) { |
|
53 | + $notification[$f] = '[admin_email]'; |
|
54 | 54 | } else if ( in_array( $f, array( 'email_to', 'cc', 'bcc', 'reply_to', 'from' ) ) ) { |
55 | 55 | //Remove brackets |
56 | 56 | //Add a space in case there isn't one |
57 | - $notification[ $f ] = str_replace( '<', ' ', $notification[ $f ] ); |
|
58 | - $notification[ $f ] = str_replace( array( '"', '>' ), '', $notification[ $f ] ); |
|
57 | + $notification[$f] = str_replace( '<', ' ', $notification[$f] ); |
|
58 | + $notification[$f] = str_replace( array( '"', '>' ), '', $notification[$f] ); |
|
59 | 59 | |
60 | 60 | //Switch userID shortcode to email address |
61 | - if ( strpos( $notification[ $f ], '[' . $user_id_field . ']' ) !== false || strpos( $notification[ $f ], '[' . $user_id_key . ']' ) !== false ) { |
|
62 | - $user_data = get_userdata( $entry->metas[ $user_id_field ] ); |
|
61 | + if ( strpos( $notification[$f], '[' . $user_id_field . ']' ) !== false || strpos( $notification[$f], '[' . $user_id_key . ']' ) !== false ) { |
|
62 | + $user_data = get_userdata( $entry->metas[$user_id_field] ); |
|
63 | 63 | $user_email = $user_data->user_email; |
64 | - $notification[ $f ] = str_replace( array( '[' . $user_id_field . ']', '[' . $user_id_key . ']' ), $user_email, $notification[ $f ] ); |
|
64 | + $notification[$f] = str_replace( array( '[' . $user_id_field . ']', '[' . $user_id_key . ']' ), $user_email, $notification[$f] ); |
|
65 | 65 | } |
66 | 66 | } |
67 | 67 | |
68 | - $notification[ $f ] = FrmFieldsHelper::basic_replace_shortcodes( $notification[ $f ], $form, $entry ); |
|
68 | + $notification[$f] = FrmFieldsHelper::basic_replace_shortcodes( $notification[$f], $form, $entry ); |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | //Put recipients, cc, and bcc into an array if they aren't empty |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | $cc = self::explode_emails( $notification['cc'] ); |
74 | 74 | $bcc = self::explode_emails( $notification['bcc'] ); |
75 | 75 | |
76 | - $to_emails = apply_filters('frm_to_email', $to_emails, $values, $form->id, compact('email_key', 'entry', 'form')); |
|
76 | + $to_emails = apply_filters( 'frm_to_email', $to_emails, $values, $form->id, compact( 'email_key', 'entry', 'form' ) ); |
|
77 | 77 | |
78 | 78 | // Stop now if there aren't any recipients |
79 | 79 | if ( empty( $to_emails ) && empty( $cc ) && empty( $bcc ) ) { |
@@ -83,39 +83,39 @@ discard block |
||
83 | 83 | $to_emails = array_unique( (array) $to_emails ); |
84 | 84 | |
85 | 85 | $prev_mail_body = $mail_body = $notification['email_message']; |
86 | - $mail_body = FrmEntriesHelper::replace_default_message($mail_body, array( |
|
86 | + $mail_body = FrmEntriesHelper::replace_default_message( $mail_body, array( |
|
87 | 87 | 'id' => $entry->id, 'entry' => $entry, 'plain_text' => $plain_text, |
88 | - 'user_info' => (isset($notification['inc_user_info']) ? $notification['inc_user_info'] : false), |
|
88 | + 'user_info' => ( isset( $notification['inc_user_info'] ) ? $notification['inc_user_info'] : false ), |
|
89 | 89 | ) ); |
90 | 90 | |
91 | 91 | // Add the user info if it isn't already included |
92 | 92 | if ( $notification['inc_user_info'] && $prev_mail_body == $mail_body ) { |
93 | - $data = maybe_unserialize($entry->description); |
|
93 | + $data = maybe_unserialize( $entry->description ); |
|
94 | 94 | $mail_body .= "\r\n\r\n" . __( 'User Information', 'formidable' ) . "\r\n"; |
95 | 95 | $mail_body .= __( 'IP Address', 'formidable' ) . ': ' . $entry->ip . "\r\n"; |
96 | 96 | $mail_body .= __( 'User-Agent (Browser/OS)', 'formidable' ) . ': ' . FrmEntryFormat::get_browser( $data['browser'] ) . "\r\n"; |
97 | 97 | $mail_body .= __( 'Referrer', 'formidable' ) . ': ' . $data['referrer'] . "\r\n"; |
98 | 98 | } |
99 | - unset($prev_mail_body); |
|
99 | + unset( $prev_mail_body ); |
|
100 | 100 | |
101 | 101 | // Add attachments |
102 | - $attachments = apply_filters('frm_notification_attachment', array(), $form, compact('entry', 'email_key') ); |
|
102 | + $attachments = apply_filters( 'frm_notification_attachment', array(), $form, compact( 'entry', 'email_key' ) ); |
|
103 | 103 | |
104 | - if ( ! empty($notification['email_subject']) ) { |
|
105 | - $notification['email_subject'] = apply_filters('frm_email_subject', $notification['email_subject'], compact('form', 'entry', 'email_key')); |
|
104 | + if ( ! empty( $notification['email_subject'] ) ) { |
|
105 | + $notification['email_subject'] = apply_filters( 'frm_email_subject', $notification['email_subject'], compact( 'form', 'entry', 'email_key' ) ); |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | // check for a phone number |
109 | 109 | foreach ( (array) $to_emails as $email_key => $e ) { |
110 | - if ( $e != '[admin_email]' && ! is_email($e) ) { |
|
111 | - $e = explode(' ', $e); |
|
110 | + if ( $e != '[admin_email]' && ! is_email( $e ) ) { |
|
111 | + $e = explode( ' ', $e ); |
|
112 | 112 | |
113 | 113 | //If to_email has name <[email protected]> format |
114 | - if ( is_email(end($e)) ) { |
|
114 | + if ( is_email( end( $e ) ) ) { |
|
115 | 115 | continue; |
116 | 116 | } |
117 | 117 | |
118 | - do_action('frm_send_to_not_email', array( |
|
118 | + do_action( 'frm_send_to_not_email', array( |
|
119 | 119 | 'e' => $e, |
120 | 120 | 'subject' => $notification['email_subject'], |
121 | 121 | 'mail_body' => $mail_body, |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | 'email_key' => $email_key, |
128 | 128 | ) ); |
129 | 129 | |
130 | - unset( $to_emails[ $email_key ] ); |
|
130 | + unset( $to_emails[$email_key] ); |
|
131 | 131 | } |
132 | 132 | } |
133 | 133 | |
@@ -150,17 +150,17 @@ discard block |
||
150 | 150 | public function entry_created( $entry_id, $form_id ) { |
151 | 151 | $new_function = 'FrmFormActionsController::trigger_actions("create", ' . $form_id . ', ' . $entry_id . ', "email")'; |
152 | 152 | _deprecated_function( __FUNCTION__, '2.0', $new_function ); |
153 | - FrmFormActionsController::trigger_actions('create', $form_id, $entry_id, 'email'); |
|
153 | + FrmFormActionsController::trigger_actions( 'create', $form_id, $entry_id, 'email' ); |
|
154 | 154 | } |
155 | 155 | |
156 | 156 | public function send_notification_email( $to_email, $subject, $message, $from = '', $from_name = '', $plain_text = true, $attachments = array(), $reply_to = '' ) { |
157 | 157 | _deprecated_function( __FUNCTION__, '2.0', 'FrmNotification::send_email' ); |
158 | 158 | |
159 | - return self::send_email(compact( |
|
159 | + return self::send_email( compact( |
|
160 | 160 | 'to_email', 'subject', 'message', |
161 | 161 | 'from', 'from_name', 'plain_text', |
162 | 162 | 'attachments', 'reply_to' |
163 | - )); |
|
163 | + ) ); |
|
164 | 164 | } |
165 | 165 | |
166 | 166 | /** |
@@ -193,28 +193,28 @@ discard block |
||
193 | 193 | private static function format_email_fields( &$atts, $admin_email ) { |
194 | 194 | |
195 | 195 | // If from is empty or is set to admin_email, set it now |
196 | - $atts['from'] = ( empty($atts['from']) || $atts['from'] == '[admin_email]' ) ? $admin_email : $atts['from']; |
|
196 | + $atts['from'] = ( empty( $atts['from'] ) || $atts['from'] == '[admin_email]' ) ? $admin_email : $atts['from']; |
|
197 | 197 | |
198 | 198 | // Filter values in these fields |
199 | 199 | $filter_fields = array( 'to_email', 'bcc', 'cc', 'from', 'reply_to' ); |
200 | 200 | |
201 | 201 | foreach ( $filter_fields as $f ) { |
202 | 202 | // If empty, just skip it |
203 | - if ( empty( $atts[ $f ] ) ) { |
|
203 | + if ( empty( $atts[$f] ) ) { |
|
204 | 204 | continue; |
205 | 205 | } |
206 | 206 | |
207 | 207 | // to_email, cc, and bcc can be an array |
208 | - if ( is_array( $atts[ $f ] ) ) { |
|
209 | - foreach ( $atts[ $f ] as $key => $val ) { |
|
208 | + if ( is_array( $atts[$f] ) ) { |
|
209 | + foreach ( $atts[$f] as $key => $val ) { |
|
210 | 210 | self::format_single_field( $atts, $f, $val, $key ); |
211 | 211 | unset( $key, $val ); |
212 | 212 | } |
213 | - unset($f); |
|
213 | + unset( $f ); |
|
214 | 214 | continue; |
215 | 215 | } |
216 | 216 | |
217 | - self::format_single_field( $atts, $f, $atts[ $f ] ); |
|
217 | + self::format_single_field( $atts, $f, $atts[$f] ); |
|
218 | 218 | } |
219 | 219 | |
220 | 220 | // If reply-to isn't set, make it match the from settings |
@@ -222,7 +222,7 @@ discard block |
||
222 | 222 | $atts['reply_to'] = self::get_email_from_formatted_string( $atts['from'] ); |
223 | 223 | } |
224 | 224 | |
225 | - if ( ! is_array($atts['to_email']) && '[admin_email]' == $atts['to_email'] ) { |
|
225 | + if ( ! is_array( $atts['to_email'] ) && '[admin_email]' == $atts['to_email'] ) { |
|
226 | 226 | $atts['to_email'] = $admin_email; |
227 | 227 | } |
228 | 228 | } |
@@ -245,20 +245,20 @@ discard block |
||
245 | 245 | * @param int $key if in array, this will be set |
246 | 246 | */ |
247 | 247 | private static function format_single_field( &$atts, $f, $val, $key = false ) { |
248 | - $val = trim($val); |
|
248 | + $val = trim( $val ); |
|
249 | 249 | |
250 | 250 | // If just a plain email is used |
251 | - if ( is_email($val) ) { |
|
251 | + if ( is_email( $val ) ) { |
|
252 | 252 | // add sender's name if not included in $from |
253 | 253 | if ( $f == 'from' ) { |
254 | - $part_2 = $atts[ $f ]; |
|
255 | - $part_1 = $atts['from_name'] ? $atts['from_name'] : wp_specialchars_decode( FrmAppHelper::site_name(), ENT_QUOTES ); |
|
254 | + $part_2 = $atts[$f]; |
|
255 | + $part_1 = $atts['from_name'] ? $atts['from_name'] : wp_specialchars_decode( FrmAppHelper::site_name(), ENT_QUOTES ); |
|
256 | 256 | } else { |
257 | 257 | return; |
258 | 258 | } |
259 | 259 | } else { |
260 | - $parts = explode(' ', $val); |
|
261 | - $part_2 = end($parts); |
|
260 | + $parts = explode( ' ', $val ); |
|
261 | + $part_2 = end( $parts ); |
|
262 | 262 | |
263 | 263 | // If inputted correcly, $part_2 should be an email |
264 | 264 | if ( is_email( $part_2 ) ) { |
@@ -266,14 +266,14 @@ discard block |
||
266 | 266 | } else if ( in_array( $f, array( 'from', 'reply_to' ) ) ) { |
267 | 267 | // In case someone just puts a name in the From or Reply To field |
268 | 268 | $part_1 = $val; |
269 | - $part_2 = get_option('admin_email'); |
|
269 | + $part_2 = get_option( 'admin_email' ); |
|
270 | 270 | } else { |
271 | 271 | // In case someone just puts a name in any other email field |
272 | 272 | if ( false !== $key ) { |
273 | - unset( $atts[ $f ][ $key ] ); |
|
273 | + unset( $atts[$f][$key] ); |
|
274 | 274 | return; |
275 | 275 | } |
276 | - $atts[ $f ] = ''; |
|
276 | + $atts[$f] = ''; |
|
277 | 277 | return; |
278 | 278 | } |
279 | 279 | } |
@@ -294,14 +294,14 @@ discard block |
||
294 | 294 | |
295 | 295 | // If value is an array |
296 | 296 | if ( false !== $key ) { |
297 | - $atts[ $f ][ $key ] = $final_val; |
|
297 | + $atts[$f][$key] = $final_val; |
|
298 | 298 | return; |
299 | 299 | } |
300 | - $atts[ $f ] = $final_val; |
|
300 | + $atts[$f] = $final_val; |
|
301 | 301 | } |
302 | 302 | |
303 | 303 | public static function send_email( $atts ) { |
304 | - $admin_email = get_option('admin_email'); |
|
304 | + $admin_email = get_option( 'admin_email' ); |
|
305 | 305 | $defaults = array( |
306 | 306 | 'to_email' => $admin_email, |
307 | 307 | 'subject' => '', |
@@ -314,7 +314,7 @@ discard block |
||
314 | 314 | 'reply_to' => $admin_email, |
315 | 315 | 'attachments' => array(), |
316 | 316 | ); |
317 | - $atts = wp_parse_args($atts, $defaults); |
|
317 | + $atts = wp_parse_args( $atts, $defaults ); |
|
318 | 318 | |
319 | 319 | // Put To, BCC, CC, Reply To, and From fields in the correct format |
320 | 320 | self::format_email_fields( $atts, $admin_email ); |
@@ -327,14 +327,14 @@ discard block |
||
327 | 327 | $array_fields = array( 'CC' => $atts['cc'], 'BCC' => $atts['bcc'] ); |
328 | 328 | $cc = array( 'CC' => array(), 'BCC' => array() ); |
329 | 329 | foreach ( $array_fields as $key => $a_field ) { |
330 | - if ( empty($a_field) ) { |
|
330 | + if ( empty( $a_field ) ) { |
|
331 | 331 | continue; |
332 | 332 | } |
333 | 333 | |
334 | 334 | foreach ( (array) $a_field as $email ) { |
335 | - $cc[ $key ][] = $email; |
|
335 | + $cc[$key][] = $email; |
|
336 | 336 | } |
337 | - unset($key, $a_field); |
|
337 | + unset( $key, $a_field ); |
|
338 | 338 | } |
339 | 339 | $cc = array_filter( $cc ); // remove cc and bcc if they are empty |
340 | 340 | |
@@ -343,52 +343,52 @@ discard block |
||
343 | 343 | } |
344 | 344 | |
345 | 345 | $content_type = $atts['plain_text'] ? 'text/plain' : 'text/html'; |
346 | - $charset = get_option('blog_charset'); |
|
346 | + $charset = get_option( 'blog_charset' ); |
|
347 | 347 | |
348 | 348 | $header[] = 'Reply-To: ' . $atts['reply_to']; |
349 | 349 | $header[] = 'Content-Type: ' . $content_type . '; charset="' . esc_attr( $charset ) . '"'; |
350 | - $atts['subject'] = wp_specialchars_decode(strip_tags(stripslashes($atts['subject'])), ENT_QUOTES ); |
|
350 | + $atts['subject'] = wp_specialchars_decode( strip_tags( stripslashes( $atts['subject'] ) ), ENT_QUOTES ); |
|
351 | 351 | |
352 | - $message = do_shortcode($atts['message']); |
|
352 | + $message = do_shortcode( $atts['message'] ); |
|
353 | 353 | |
354 | 354 | if ( $atts['plain_text'] ) { |
355 | 355 | //$message = wordwrap($message, 70, "\r\n"); //in case any lines are longer than 70 chars |
356 | - $message = wp_specialchars_decode(strip_tags($message), ENT_QUOTES ); |
|
356 | + $message = wp_specialchars_decode( strip_tags( $message ), ENT_QUOTES ); |
|
357 | 357 | } else { |
358 | 358 | // remove line breaks in HTML emails to prevent conflicts with Mandrill |
359 | 359 | add_filter( 'mandrill_nl2br', 'FrmNotification::remove_mandrill_br' ); |
360 | 360 | } |
361 | 361 | $message = apply_filters( 'frm_email_message', $message, $atts ); |
362 | 362 | |
363 | - $header = apply_filters('frm_email_header', $header, array( |
|
363 | + $header = apply_filters( 'frm_email_header', $header, array( |
|
364 | 364 | 'to_email' => $atts['to_email'], 'subject' => $atts['subject'], |
365 | 365 | ) ); |
366 | 366 | |
367 | - if ( apply_filters('frm_encode_subject', 1, $atts['subject'] ) ) { |
|
367 | + if ( apply_filters( 'frm_encode_subject', 1, $atts['subject'] ) ) { |
|
368 | 368 | $atts['subject'] = '=?' . $charset . '?B?' . base64_encode( $atts['subject'] ) . '?='; |
369 | 369 | } |
370 | 370 | |
371 | - remove_filter('wp_mail_from', 'bp_core_email_from_address_filter' ); |
|
372 | - remove_filter('wp_mail_from_name', 'bp_core_email_from_name_filter'); |
|
371 | + remove_filter( 'wp_mail_from', 'bp_core_email_from_address_filter' ); |
|
372 | + remove_filter( 'wp_mail_from_name', 'bp_core_email_from_name_filter' ); |
|
373 | 373 | |
374 | - $sent = wp_mail($recipient, $atts['subject'], $message, $header, $atts['attachments']); |
|
374 | + $sent = wp_mail( $recipient, $atts['subject'], $message, $header, $atts['attachments'] ); |
|
375 | 375 | if ( ! $sent ) { |
376 | 376 | $header = 'From: ' . $atts['from'] . "\r\n"; |
377 | - $recipient = implode(',', (array) $recipient); |
|
378 | - $sent = mail($recipient, $atts['subject'], $message, $header); |
|
377 | + $recipient = implode( ',', (array) $recipient ); |
|
378 | + $sent = mail( $recipient, $atts['subject'], $message, $header ); |
|
379 | 379 | } |
380 | 380 | |
381 | 381 | // remove the filter now so other emails can still use it |
382 | 382 | remove_filter( 'mandrill_nl2br', 'FrmNotification::remove_mandrill_br' ); |
383 | 383 | |
384 | - do_action('frm_notification', $recipient, $atts['subject'], $message); |
|
384 | + do_action( 'frm_notification', $recipient, $atts['subject'], $message ); |
|
385 | 385 | |
386 | 386 | if ( $sent ) { |
387 | 387 | $sent_to = array_merge( (array) $atts['to_email'], (array) $atts['cc'], (array) $atts['bcc'] ); |
388 | 388 | $sent_to = array_filter( $sent_to ); |
389 | - if ( apply_filters('frm_echo_emails', false) ) { |
|
390 | - $temp = str_replace('<', '<', $sent_to); |
|
391 | - echo ' ' . FrmAppHelper::kses( implode(', ', (array) $temp ) ); |
|
389 | + if ( apply_filters( 'frm_echo_emails', false ) ) { |
|
390 | + $temp = str_replace( '<', '<', $sent_to ); |
|
391 | + echo ' ' . FrmAppHelper::kses( implode( ', ', (array) $temp ) ); |
|
392 | 392 | } |
393 | 393 | return $sent_to; |
394 | 394 | } |
@@ -7,71 +7,71 @@ discard block |
||
7 | 7 | |
8 | 8 | public static function setup_new_vars( $type = '', $form_id = '' ) { |
9 | 9 | |
10 | - if ( strpos($type, '|') ) { |
|
11 | - list($type, $setting) = explode('|', $type); |
|
12 | - } |
|
13 | - |
|
14 | - $defaults = self::get_default_field_opts($type, $form_id); |
|
15 | - $defaults['field_options']['custom_html'] = self::get_default_html($type); |
|
16 | - |
|
17 | - $values = array(); |
|
18 | - |
|
19 | - foreach ( $defaults as $var => $default ) { |
|
20 | - if ( $var == 'field_options' ) { |
|
21 | - $values['field_options'] = array(); |
|
22 | - foreach ( $default as $opt_var => $opt_default ) { |
|
23 | - $values['field_options'][ $opt_var ] = $opt_default; |
|
24 | - unset($opt_var, $opt_default); |
|
25 | - } |
|
26 | - } else { |
|
27 | - $values[ $var ] = $default; |
|
28 | - } |
|
29 | - unset($var, $default); |
|
30 | - } |
|
31 | - |
|
32 | - if ( isset( $setting ) && ! empty( $setting ) ) { |
|
33 | - if ( 'data' == $type ) { |
|
34 | - $values['field_options']['data_type'] = $setting; |
|
35 | - } else { |
|
36 | - $values['field_options'][ $setting ] = 1; |
|
37 | - } |
|
38 | - } |
|
39 | - |
|
40 | - if ( $type == 'radio' || $type == 'checkbox' ) { |
|
41 | - $values['options'] = serialize( array( |
|
42 | - __( 'Option 1', 'formidable' ), |
|
43 | - __( 'Option 2', 'formidable' ), |
|
44 | - ) ); |
|
45 | - } else if ( $type == 'select' ) { |
|
46 | - $values['options'] = serialize( array( |
|
47 | - '', __( 'Option 1', 'formidable' ), |
|
48 | - ) ); |
|
49 | - } else if ( $type == 'textarea' ) { |
|
50 | - $values['field_options']['max'] = '5'; |
|
51 | - } else if ( $type == 'captcha' ) { |
|
52 | - $frm_settings = FrmAppHelper::get_settings(); |
|
53 | - $values['invalid'] = $frm_settings->re_msg; |
|
54 | - } else if ( 'url' == $type ) { |
|
55 | - $values['name'] = __( 'Website', 'formidable' ); |
|
56 | - } |
|
10 | + if ( strpos($type, '|') ) { |
|
11 | + list($type, $setting) = explode('|', $type); |
|
12 | + } |
|
13 | + |
|
14 | + $defaults = self::get_default_field_opts($type, $form_id); |
|
15 | + $defaults['field_options']['custom_html'] = self::get_default_html($type); |
|
16 | + |
|
17 | + $values = array(); |
|
18 | + |
|
19 | + foreach ( $defaults as $var => $default ) { |
|
20 | + if ( $var == 'field_options' ) { |
|
21 | + $values['field_options'] = array(); |
|
22 | + foreach ( $default as $opt_var => $opt_default ) { |
|
23 | + $values['field_options'][ $opt_var ] = $opt_default; |
|
24 | + unset($opt_var, $opt_default); |
|
25 | + } |
|
26 | + } else { |
|
27 | + $values[ $var ] = $default; |
|
28 | + } |
|
29 | + unset($var, $default); |
|
30 | + } |
|
31 | + |
|
32 | + if ( isset( $setting ) && ! empty( $setting ) ) { |
|
33 | + if ( 'data' == $type ) { |
|
34 | + $values['field_options']['data_type'] = $setting; |
|
35 | + } else { |
|
36 | + $values['field_options'][ $setting ] = 1; |
|
37 | + } |
|
38 | + } |
|
39 | + |
|
40 | + if ( $type == 'radio' || $type == 'checkbox' ) { |
|
41 | + $values['options'] = serialize( array( |
|
42 | + __( 'Option 1', 'formidable' ), |
|
43 | + __( 'Option 2', 'formidable' ), |
|
44 | + ) ); |
|
45 | + } else if ( $type == 'select' ) { |
|
46 | + $values['options'] = serialize( array( |
|
47 | + '', __( 'Option 1', 'formidable' ), |
|
48 | + ) ); |
|
49 | + } else if ( $type == 'textarea' ) { |
|
50 | + $values['field_options']['max'] = '5'; |
|
51 | + } else if ( $type == 'captcha' ) { |
|
52 | + $frm_settings = FrmAppHelper::get_settings(); |
|
53 | + $values['invalid'] = $frm_settings->re_msg; |
|
54 | + } else if ( 'url' == $type ) { |
|
55 | + $values['name'] = __( 'Website', 'formidable' ); |
|
56 | + } |
|
57 | 57 | |
58 | 58 | $fields = FrmField::field_selection(); |
59 | - $fields = array_merge($fields, FrmField::pro_field_selection()); |
|
59 | + $fields = array_merge($fields, FrmField::pro_field_selection()); |
|
60 | 60 | |
61 | - if ( isset( $fields[ $type ] ) ) { |
|
62 | - $values['name'] = is_array( $fields[ $type ] ) ? $fields[ $type ]['name'] : $fields[ $type ]; |
|
63 | - } |
|
61 | + if ( isset( $fields[ $type ] ) ) { |
|
62 | + $values['name'] = is_array( $fields[ $type ] ) ? $fields[ $type ]['name'] : $fields[ $type ]; |
|
63 | + } |
|
64 | 64 | |
65 | - unset($fields); |
|
65 | + unset($fields); |
|
66 | 66 | |
67 | - return $values; |
|
68 | - } |
|
67 | + return $values; |
|
68 | + } |
|
69 | 69 | |
70 | 70 | public static function get_html_id( $field, $plus = '' ) { |
71 | 71 | return apply_filters( 'frm_field_html_id', 'field_' . $field['field_key'] . $plus, $field ); |
72 | - } |
|
72 | + } |
|
73 | 73 | |
74 | - public static function setup_edit_vars( $record, $doing_ajax = false ) { |
|
74 | + public static function setup_edit_vars( $record, $doing_ajax = false ) { |
|
75 | 75 | $values = array( 'id' => $record->id, 'form_id' => $record->form_id ); |
76 | 76 | $defaults = array( |
77 | 77 | 'name' => $record->name, |
@@ -84,86 +84,86 @@ discard block |
||
84 | 84 | ); |
85 | 85 | |
86 | 86 | if ( $doing_ajax ) { |
87 | - $values = $values + $defaults; |
|
88 | - $values['form_name'] = ''; |
|
87 | + $values = $values + $defaults; |
|
88 | + $values['form_name'] = ''; |
|
89 | 89 | } else { |
90 | 90 | foreach ( $defaults as $var => $default ) { |
91 | - $values[ $var ] = FrmAppHelper::get_param( $var, $default, 'get', 'htmlspecialchars' ); |
|
92 | - unset($var, $default); |
|
93 | - } |
|
91 | + $values[ $var ] = FrmAppHelper::get_param( $var, $default, 'get', 'htmlspecialchars' ); |
|
92 | + unset($var, $default); |
|
93 | + } |
|
94 | 94 | |
95 | 95 | $values['form_name'] = $record->form_id ? FrmForm::getName( $record->form_id ) : ''; |
96 | - } |
|
96 | + } |
|
97 | 97 | |
98 | 98 | unset( $defaults ); |
99 | 99 | |
100 | - $values['options'] = $record->options; |
|
101 | - $values['field_options'] = $record->field_options; |
|
100 | + $values['options'] = $record->options; |
|
101 | + $values['field_options'] = $record->field_options; |
|
102 | 102 | |
103 | - $defaults = self::get_default_field_opts($values['type'], $record, true); |
|
103 | + $defaults = self::get_default_field_opts($values['type'], $record, true); |
|
104 | 104 | |
105 | 105 | if ( $values['type'] == 'captcha' ) { |
106 | - $frm_settings = FrmAppHelper::get_settings(); |
|
107 | - $defaults['invalid'] = $frm_settings->re_msg; |
|
108 | - } |
|
106 | + $frm_settings = FrmAppHelper::get_settings(); |
|
107 | + $defaults['invalid'] = $frm_settings->re_msg; |
|
108 | + } |
|
109 | 109 | |
110 | 110 | foreach ( $defaults as $opt => $default ) { |
111 | - $values[ $opt ] = isset( $record->field_options[ $opt ] ) ? $record->field_options[ $opt ] : $default; |
|
112 | - unset($opt, $default); |
|
113 | - } |
|
111 | + $values[ $opt ] = isset( $record->field_options[ $opt ] ) ? $record->field_options[ $opt ] : $default; |
|
112 | + unset($opt, $default); |
|
113 | + } |
|
114 | 114 | |
115 | - $values['custom_html'] = (isset($record->field_options['custom_html'])) ? $record->field_options['custom_html'] : self::get_default_html($record->type); |
|
115 | + $values['custom_html'] = (isset($record->field_options['custom_html'])) ? $record->field_options['custom_html'] : self::get_default_html($record->type); |
|
116 | 116 | |
117 | 117 | return apply_filters( 'frm_setup_edit_field_vars', $values, array( 'doing_ajax' => $doing_ajax ) ); |
118 | - } |
|
118 | + } |
|
119 | 119 | |
120 | - public static function get_default_field_opts( $type, $field, $limit = false ) { |
|
121 | - $field_options = array( |
|
122 | - 'size' => '', 'max' => '', 'label' => '', 'blank' => '', |
|
123 | - 'required_indicator' => '*', 'invalid' => '', 'separate_value' => 0, |
|
124 | - 'clear_on_focus' => 0, 'default_blank' => 0, 'classes' => '', |
|
120 | + public static function get_default_field_opts( $type, $field, $limit = false ) { |
|
121 | + $field_options = array( |
|
122 | + 'size' => '', 'max' => '', 'label' => '', 'blank' => '', |
|
123 | + 'required_indicator' => '*', 'invalid' => '', 'separate_value' => 0, |
|
124 | + 'clear_on_focus' => 0, 'default_blank' => 0, 'classes' => '', |
|
125 | 125 | 'custom_html' => '', 'captcha_size' => 'default', |
126 | - ); |
|
126 | + ); |
|
127 | 127 | |
128 | 128 | if ( $limit ) { |
129 | - return $field_options; |
|
129 | + return $field_options; |
|
130 | 130 | } |
131 | 131 | |
132 | - global $wpdb; |
|
132 | + global $wpdb; |
|
133 | 133 | |
134 | - $form_id = (is_numeric($field)) ? $field : $field->form_id; |
|
134 | + $form_id = (is_numeric($field)) ? $field : $field->form_id; |
|
135 | 135 | |
136 | 136 | $key = is_numeric( $field ) ? FrmAppHelper::get_unique_key( '', $wpdb->prefix . 'frm_fields', 'field_key' ) : $field->field_key; |
137 | 137 | |
138 | - $field_count = FrmDb::get_var( 'frm_fields', array( 'form_id' => $form_id ), 'field_order', array( 'order_by' => 'field_order DESC' ) ); |
|
138 | + $field_count = FrmDb::get_var( 'frm_fields', array( 'form_id' => $form_id ), 'field_order', array( 'order_by' => 'field_order DESC' ) ); |
|
139 | 139 | |
140 | - $frm_settings = FrmAppHelper::get_settings(); |
|
141 | - return array( |
|
142 | - 'name' => __( 'Untitled', 'formidable' ), 'description' => '', |
|
140 | + $frm_settings = FrmAppHelper::get_settings(); |
|
141 | + return array( |
|
142 | + 'name' => __( 'Untitled', 'formidable' ), 'description' => '', |
|
143 | 143 | 'field_key' => $key, 'type' => $type, 'options' => '', 'default_value' => '', |
144 | 144 | 'field_order' => $field_count + 1, 'required' => false, |
145 | - 'blank' => $frm_settings->blank_msg, 'unique_msg' => $frm_settings->unique_msg, |
|
146 | - 'invalid' => __( 'This field is invalid', 'formidable' ), 'form_id' => $form_id, |
|
145 | + 'blank' => $frm_settings->blank_msg, 'unique_msg' => $frm_settings->unique_msg, |
|
146 | + 'invalid' => __( 'This field is invalid', 'formidable' ), 'form_id' => $form_id, |
|
147 | 147 | 'field_options' => $field_options, |
148 | - ); |
|
149 | - } |
|
148 | + ); |
|
149 | + } |
|
150 | 150 | |
151 | - public static function fill_field( &$values, $field, $form_id, $new_key = '' ) { |
|
152 | - global $wpdb; |
|
151 | + public static function fill_field( &$values, $field, $form_id, $new_key = '' ) { |
|
152 | + global $wpdb; |
|
153 | 153 | |
154 | 154 | $values['field_key'] = FrmAppHelper::get_unique_key( $new_key, $wpdb->prefix . 'frm_fields', 'field_key' ); |
155 | - $values['form_id'] = $form_id; |
|
156 | - $values['options'] = maybe_serialize($field->options); |
|
157 | - $values['default_value'] = maybe_serialize($field->default_value); |
|
158 | - |
|
159 | - foreach ( array( 'name', 'description', 'type', 'field_order', 'field_options', 'required' ) as $col ) { |
|
160 | - $values[ $col ] = $field->{$col}; |
|
161 | - } |
|
162 | - } |
|
163 | - |
|
164 | - /** |
|
165 | - * @since 2.0 |
|
166 | - */ |
|
155 | + $values['form_id'] = $form_id; |
|
156 | + $values['options'] = maybe_serialize($field->options); |
|
157 | + $values['default_value'] = maybe_serialize($field->default_value); |
|
158 | + |
|
159 | + foreach ( array( 'name', 'description', 'type', 'field_order', 'field_options', 'required' ) as $col ) { |
|
160 | + $values[ $col ] = $field->{$col}; |
|
161 | + } |
|
162 | + } |
|
163 | + |
|
164 | + /** |
|
165 | + * @since 2.0 |
|
166 | + */ |
|
167 | 167 | public static function get_error_msg( $field, $error ) { |
168 | 168 | $frm_settings = FrmAppHelper::get_settings(); |
169 | 169 | $default_settings = $frm_settings->default_options(); |
@@ -180,21 +180,21 @@ discard block |
||
180 | 180 | return $msg; |
181 | 181 | } |
182 | 182 | |
183 | - public static function get_form_fields( $form_id, $error = false ) { |
|
184 | - $fields = FrmField::get_all_for_form($form_id); |
|
185 | - $fields = apply_filters('frm_get_paged_fields', $fields, $form_id, $error); |
|
186 | - return $fields; |
|
187 | - } |
|
183 | + public static function get_form_fields( $form_id, $error = false ) { |
|
184 | + $fields = FrmField::get_all_for_form($form_id); |
|
185 | + $fields = apply_filters('frm_get_paged_fields', $fields, $form_id, $error); |
|
186 | + return $fields; |
|
187 | + } |
|
188 | 188 | |
189 | 189 | public static function get_default_html( $type = 'text' ) { |
190 | 190 | if ( apply_filters( 'frm_normal_field_type_html', true, $type ) ) { |
191 | 191 | $input = ( in_array( $type, array( 'radio', 'checkbox', 'data' ) ) ) ? '<div class="frm_opt_container">[input]</div>' : '[input]'; |
192 | - $for = ''; |
|
192 | + $for = ''; |
|
193 | 193 | if ( ! in_array( $type, array( 'radio', 'checkbox', 'data', 'scale' ) ) ) { |
194 | - $for = 'for="field_[key]"'; |
|
195 | - } |
|
194 | + $for = 'for="field_[key]"'; |
|
195 | + } |
|
196 | 196 | |
197 | - $default_html = <<<DEFAULT_HTML |
|
197 | + $default_html = <<<DEFAULT_HTML |
|
198 | 198 | <div id="frm_field_[id]_container" class="frm_form_field form-field [required_class][error_class]"> |
199 | 199 | <label $for class="frm_primary_label">[field_name] |
200 | 200 | <span class="frm_required">[required_label]</span> |
@@ -204,145 +204,145 @@ discard block |
||
204 | 204 | [if error]<div class="frm_error">[error]</div>[/if error] |
205 | 205 | </div> |
206 | 206 | DEFAULT_HTML; |
207 | - } else { |
|
207 | + } else { |
|
208 | 208 | $default_html = apply_filters('frm_other_custom_html', '', $type); |
209 | - } |
|
209 | + } |
|
210 | 210 | |
211 | - return apply_filters('frm_custom_html', $default_html, $type); |
|
212 | - } |
|
211 | + return apply_filters('frm_custom_html', $default_html, $type); |
|
212 | + } |
|
213 | 213 | |
214 | 214 | public static function replace_shortcodes( $html, $field, $errors = array(), $form = false, $args = array() ) { |
215 | - $html = apply_filters('frm_before_replace_shortcodes', $html, $field, $errors, $form); |
|
215 | + $html = apply_filters('frm_before_replace_shortcodes', $html, $field, $errors, $form); |
|
216 | 216 | |
217 | - $defaults = array( |
|
217 | + $defaults = array( |
|
218 | 218 | 'field_name' => 'item_meta[' . $field['id'] . ']', |
219 | 219 | 'field_id' => $field['id'], |
220 | - 'field_plus_id' => '', |
|
221 | - 'section_id' => '', |
|
222 | - ); |
|
223 | - $args = wp_parse_args($args, $defaults); |
|
224 | - $field_name = $args['field_name']; |
|
225 | - $field_id = $args['field_id']; |
|
226 | - $html_id = self::get_html_id($field, $args['field_plus_id']); |
|
220 | + 'field_plus_id' => '', |
|
221 | + 'section_id' => '', |
|
222 | + ); |
|
223 | + $args = wp_parse_args($args, $defaults); |
|
224 | + $field_name = $args['field_name']; |
|
225 | + $field_id = $args['field_id']; |
|
226 | + $html_id = self::get_html_id($field, $args['field_plus_id']); |
|
227 | 227 | |
228 | - if ( FrmField::is_multiple_select($field) ) { |
|
229 | - $field_name .= '[]'; |
|
230 | - } |
|
228 | + if ( FrmField::is_multiple_select($field) ) { |
|
229 | + $field_name .= '[]'; |
|
230 | + } |
|
231 | 231 | |
232 | - //replace [id] |
|
233 | - $html = str_replace('[id]', $field_id, $html); |
|
232 | + //replace [id] |
|
233 | + $html = str_replace('[id]', $field_id, $html); |
|
234 | 234 | |
235 | - // Remove the for attribute for captcha |
|
236 | - if ( $field['type'] == 'captcha' ) { |
|
237 | - $html = str_replace(' for="field_[key]"', '', $html); |
|
238 | - } |
|
235 | + // Remove the for attribute for captcha |
|
236 | + if ( $field['type'] == 'captcha' ) { |
|
237 | + $html = str_replace(' for="field_[key]"', '', $html); |
|
238 | + } |
|
239 | 239 | |
240 | - // set the label for |
|
241 | - $html = str_replace('field_[key]', $html_id, $html); |
|
240 | + // set the label for |
|
241 | + $html = str_replace('field_[key]', $html_id, $html); |
|
242 | 242 | |
243 | - //replace [key] |
|
244 | - $html = str_replace('[key]', $field['field_key'], $html); |
|
243 | + //replace [key] |
|
244 | + $html = str_replace('[key]', $field['field_key'], $html); |
|
245 | 245 | |
246 | - //replace [description] and [required_label] and [error] |
|
246 | + //replace [description] and [required_label] and [error] |
|
247 | 247 | $required = FrmField::is_required( $field ) ? $field['required_indicator'] : ''; |
248 | - if ( ! is_array( $errors ) ) { |
|
249 | - $errors = array(); |
|
250 | - } |
|
248 | + if ( ! is_array( $errors ) ) { |
|
249 | + $errors = array(); |
|
250 | + } |
|
251 | 251 | $error = isset( $errors[ 'field' . $field_id ] ) ? $errors[ 'field' . $field_id ] : false; |
252 | 252 | |
253 | - //If field type is section heading, add class so a bottom margin can be added to either the h3 or description |
|
254 | - if ( $field['type'] == 'divider' ) { |
|
255 | - if ( FrmField::is_option_true( $field, 'description' ) ) { |
|
256 | - $html = str_replace( 'frm_description', 'frm_description frm_section_spacing', $html ); |
|
257 | - } else { |
|
258 | - $html = str_replace('[label_position]', '[label_position] frm_section_spacing', $html); |
|
259 | - } |
|
260 | - } |
|
253 | + //If field type is section heading, add class so a bottom margin can be added to either the h3 or description |
|
254 | + if ( $field['type'] == 'divider' ) { |
|
255 | + if ( FrmField::is_option_true( $field, 'description' ) ) { |
|
256 | + $html = str_replace( 'frm_description', 'frm_description frm_section_spacing', $html ); |
|
257 | + } else { |
|
258 | + $html = str_replace('[label_position]', '[label_position] frm_section_spacing', $html); |
|
259 | + } |
|
260 | + } |
|
261 | 261 | |
262 | 262 | foreach ( array( 'description' => $field['description'], 'required_label' => $required, 'error' => $error ) as $code => $value ) { |
263 | - self::remove_inline_conditions( ( $value && $value != '' ), $code, $value, $html ); |
|
264 | - } |
|
263 | + self::remove_inline_conditions( ( $value && $value != '' ), $code, $value, $html ); |
|
264 | + } |
|
265 | 265 | |
266 | - //replace [required_class] |
|
266 | + //replace [required_class] |
|
267 | 267 | $required_class = FrmField::is_required( $field ) ? ' frm_required_field' : ''; |
268 | - $html = str_replace('[required_class]', $required_class, $html); |
|
268 | + $html = str_replace('[required_class]', $required_class, $html); |
|
269 | 269 | |
270 | - //replace [label_position] |
|
271 | - $field['label'] = apply_filters('frm_html_label_position', $field['label'], $field, $form); |
|
272 | - $field['label'] = ( $field['label'] && $field['label'] != '' ) ? $field['label'] : 'top'; |
|
270 | + //replace [label_position] |
|
271 | + $field['label'] = apply_filters('frm_html_label_position', $field['label'], $field, $form); |
|
272 | + $field['label'] = ( $field['label'] && $field['label'] != '' ) ? $field['label'] : 'top'; |
|
273 | 273 | $html = str_replace( '[label_position]', ( ( in_array( $field['type'], array( 'divider', 'end_divider', 'break' ) ) ) ? $field['label'] : ' frm_primary_label' ), $html ); |
274 | 274 | |
275 | - //replace [field_name] |
|
276 | - $html = str_replace('[field_name]', $field['name'], $html); |
|
275 | + //replace [field_name] |
|
276 | + $html = str_replace('[field_name]', $field['name'], $html); |
|
277 | 277 | |
278 | - //replace [error_class] |
|
278 | + //replace [error_class] |
|
279 | 279 | $error_class = isset( $errors[ 'field' . $field_id ] ) ? ' frm_blank_field' : ''; |
280 | 280 | self::get_more_field_classes( $error_class, $field, $field_id, $html ); |
281 | 281 | if ( $field['type'] == 'html' && strpos( $html, '[error_class]' ) === false ) { |
282 | 282 | // there is no error_class shortcode to use for addign fields |
283 | 283 | $html = str_replace( 'class="frm_form_field', 'class="frm_form_field ' . $error_class, $html ); |
284 | 284 | } |
285 | - $html = str_replace('[error_class]', $error_class, $html); |
|
285 | + $html = str_replace('[error_class]', $error_class, $html); |
|
286 | 286 | |
287 | - //replace [entry_key] |
|
288 | - $entry_key = FrmAppHelper::simple_get( 'entry', 'sanitize_title' ); |
|
289 | - $html = str_replace('[entry_key]', $entry_key, $html); |
|
287 | + //replace [entry_key] |
|
288 | + $entry_key = FrmAppHelper::simple_get( 'entry', 'sanitize_title' ); |
|
289 | + $html = str_replace('[entry_key]', $entry_key, $html); |
|
290 | 290 | |
291 | - //replace [input] |
|
292 | - preg_match_all("/\[(input|deletelink)\b(.*?)(?:(\/))?\]/s", $html, $shortcodes, PREG_PATTERN_ORDER); |
|
293 | - global $frm_vars; |
|
294 | - $frm_settings = FrmAppHelper::get_settings(); |
|
291 | + //replace [input] |
|
292 | + preg_match_all("/\[(input|deletelink)\b(.*?)(?:(\/))?\]/s", $html, $shortcodes, PREG_PATTERN_ORDER); |
|
293 | + global $frm_vars; |
|
294 | + $frm_settings = FrmAppHelper::get_settings(); |
|
295 | 295 | |
296 | - foreach ( $shortcodes[0] as $short_key => $tag ) { |
|
297 | - $atts = shortcode_parse_atts( $shortcodes[2][ $short_key ] ); |
|
296 | + foreach ( $shortcodes[0] as $short_key => $tag ) { |
|
297 | + $atts = shortcode_parse_atts( $shortcodes[2][ $short_key ] ); |
|
298 | 298 | $tag = self::get_shortcode_tag( $shortcodes, $short_key, array( 'conditional' => false, 'conditional_check' => false ) ); |
299 | 299 | |
300 | - $replace_with = ''; |
|
300 | + $replace_with = ''; |
|
301 | 301 | |
302 | - if ( $tag == 'input' ) { |
|
303 | - if ( isset($atts['opt']) ) { |
|
304 | - $atts['opt']--; |
|
305 | - } |
|
302 | + if ( $tag == 'input' ) { |
|
303 | + if ( isset($atts['opt']) ) { |
|
304 | + $atts['opt']--; |
|
305 | + } |
|
306 | 306 | |
307 | - $field['input_class'] = isset($atts['class']) ? $atts['class'] : ''; |
|
308 | - if ( isset($atts['class']) ) { |
|
309 | - unset($atts['class']); |
|
310 | - } |
|
307 | + $field['input_class'] = isset($atts['class']) ? $atts['class'] : ''; |
|
308 | + if ( isset($atts['class']) ) { |
|
309 | + unset($atts['class']); |
|
310 | + } |
|
311 | 311 | |
312 | - $field['shortcodes'] = $atts; |
|
313 | - ob_start(); |
|
312 | + $field['shortcodes'] = $atts; |
|
313 | + ob_start(); |
|
314 | 314 | include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/input.php' ); |
315 | - $replace_with = ob_get_contents(); |
|
316 | - ob_end_clean(); |
|
317 | - } else if ( $tag == 'deletelink' && FrmAppHelper::pro_is_installed() ) { |
|
318 | - $replace_with = FrmProEntriesController::entry_delete_link($atts); |
|
319 | - } |
|
315 | + $replace_with = ob_get_contents(); |
|
316 | + ob_end_clean(); |
|
317 | + } else if ( $tag == 'deletelink' && FrmAppHelper::pro_is_installed() ) { |
|
318 | + $replace_with = FrmProEntriesController::entry_delete_link($atts); |
|
319 | + } |
|
320 | 320 | |
321 | - $html = str_replace( $shortcodes[0][ $short_key ], $replace_with, $html ); |
|
322 | - } |
|
321 | + $html = str_replace( $shortcodes[0][ $short_key ], $replace_with, $html ); |
|
322 | + } |
|
323 | 323 | |
324 | 324 | if ( $form ) { |
325 | - $form = (array) $form; |
|
325 | + $form = (array) $form; |
|
326 | 326 | |
327 | - //replace [form_key] |
|
328 | - $html = str_replace('[form_key]', $form['form_key'], $html); |
|
327 | + //replace [form_key] |
|
328 | + $html = str_replace('[form_key]', $form['form_key'], $html); |
|
329 | 329 | |
330 | - //replace [form_name] |
|
331 | - $html = str_replace('[form_name]', $form['name'], $html); |
|
332 | - } |
|
333 | - $html .= "\n"; |
|
330 | + //replace [form_name] |
|
331 | + $html = str_replace('[form_name]', $form['name'], $html); |
|
332 | + } |
|
333 | + $html .= "\n"; |
|
334 | 334 | |
335 | - //Return html if conf_field to prevent loop |
|
336 | - if ( isset($field['conf_field']) && $field['conf_field'] == 'stop' ) { |
|
337 | - return $html; |
|
338 | - } |
|
335 | + //Return html if conf_field to prevent loop |
|
336 | + if ( isset($field['conf_field']) && $field['conf_field'] == 'stop' ) { |
|
337 | + return $html; |
|
338 | + } |
|
339 | 339 | |
340 | - //If field is in repeating section |
|
341 | - if ( $args['section_id'] ) { |
|
342 | - $html = apply_filters('frm_replace_shortcodes', $html, $field, array( 'errors' => $errors, 'form' => $form, 'field_name' => $field_name, 'field_id' => $field_id, 'field_plus_id' => $args['field_plus_id'], 'section_id' => $args['section_id'] )); |
|
343 | - } else { |
|
344 | - $html = apply_filters('frm_replace_shortcodes', $html, $field, array( 'errors' => $errors, 'form' => $form )); |
|
345 | - } |
|
340 | + //If field is in repeating section |
|
341 | + if ( $args['section_id'] ) { |
|
342 | + $html = apply_filters('frm_replace_shortcodes', $html, $field, array( 'errors' => $errors, 'form' => $form, 'field_name' => $field_name, 'field_id' => $field_id, 'field_plus_id' => $args['field_plus_id'], 'section_id' => $args['section_id'] )); |
|
343 | + } else { |
|
344 | + $html = apply_filters('frm_replace_shortcodes', $html, $field, array( 'errors' => $errors, 'form' => $form )); |
|
345 | + } |
|
346 | 346 | |
347 | 347 | self::remove_collapse_shortcode( $html ); |
348 | 348 | |
@@ -350,18 +350,18 @@ discard block |
||
350 | 350 | $html = do_shortcode( $html ); |
351 | 351 | } |
352 | 352 | |
353 | - return $html; |
|
354 | - } |
|
353 | + return $html; |
|
354 | + } |
|
355 | 355 | |
356 | 356 | /** |
357 | - * Add more classes to certain fields (like confirmation fields, other fields, repeating fields, etc.) |
|
358 | - * |
|
359 | - * @since 2.0 |
|
360 | - * @param $error_class string, pass by reference |
|
361 | - * @param $field array |
|
362 | - * @param $field_id int |
|
363 | - * @param $html string |
|
364 | - */ |
|
357 | + * Add more classes to certain fields (like confirmation fields, other fields, repeating fields, etc.) |
|
358 | + * |
|
359 | + * @since 2.0 |
|
360 | + * @param $error_class string, pass by reference |
|
361 | + * @param $field array |
|
362 | + * @param $field_id int |
|
363 | + * @param $html string |
|
364 | + */ |
|
365 | 365 | private static function get_more_field_classes( &$error_class, $field, $field_id, $html ) { |
366 | 366 | $error_class .= ' frm_' . $field['label'] . '_container'; |
367 | 367 | if ( $field['id'] != $field_id ) { |
@@ -425,46 +425,46 @@ discard block |
||
425 | 425 | } |
426 | 426 | } |
427 | 427 | |
428 | - public static function remove_inline_conditions( $no_vars, $code, $replace_with, &$html ) { |
|
429 | - if ( $no_vars ) { |
|
428 | + public static function remove_inline_conditions( $no_vars, $code, $replace_with, &$html ) { |
|
429 | + if ( $no_vars ) { |
|
430 | 430 | $html = str_replace( '[if ' . $code . ']', '', $html ); |
431 | 431 | $html = str_replace( '[/if ' . $code . ']', '', $html ); |
432 | - } else { |
|
432 | + } else { |
|
433 | 433 | $html = preg_replace( '/(\[if\s+' . $code . '\])(.*?)(\[\/if\s+' . $code . '\])/mis', '', $html ); |
434 | - } |
|
434 | + } |
|
435 | 435 | |
436 | 436 | $html = str_replace( '[' . $code . ']', $replace_with, $html ); |
437 | - } |
|
437 | + } |
|
438 | 438 | |
439 | 439 | public static function get_shortcode_tag( $shortcodes, $short_key, $args ) { |
440 | 440 | $args = wp_parse_args( $args, array( 'conditional' => false, 'conditional_check' => false, 'foreach' => false ) ); |
441 | - if ( ( $args['conditional'] || $args['foreach'] ) && ! $args['conditional_check'] ) { |
|
442 | - $args['conditional_check'] = true; |
|
443 | - } |
|
444 | - |
|
445 | - $prefix = ''; |
|
446 | - if ( $args['conditional_check'] ) { |
|
447 | - if ( $args['conditional'] ) { |
|
448 | - $prefix = 'if '; |
|
449 | - } else if ( $args['foreach'] ) { |
|
450 | - $prefix = 'foreach '; |
|
451 | - } |
|
452 | - } |
|
453 | - |
|
454 | - $with_tags = $args['conditional_check'] ? 3 : 2; |
|
455 | - if ( ! empty( $shortcodes[ $with_tags ][ $short_key ] ) ) { |
|
456 | - $tag = str_replace( '[' . $prefix, '', $shortcodes[0][ $short_key ] ); |
|
457 | - $tag = str_replace(']', '', $tag); |
|
458 | - $tags = explode(' ', $tag); |
|
459 | - if ( is_array($tags) ) { |
|
460 | - $tag = $tags[0]; |
|
461 | - } |
|
462 | - } else { |
|
463 | - $tag = $shortcodes[ $with_tags - 1 ][ $short_key ]; |
|
464 | - } |
|
465 | - |
|
466 | - return $tag; |
|
467 | - } |
|
441 | + if ( ( $args['conditional'] || $args['foreach'] ) && ! $args['conditional_check'] ) { |
|
442 | + $args['conditional_check'] = true; |
|
443 | + } |
|
444 | + |
|
445 | + $prefix = ''; |
|
446 | + if ( $args['conditional_check'] ) { |
|
447 | + if ( $args['conditional'] ) { |
|
448 | + $prefix = 'if '; |
|
449 | + } else if ( $args['foreach'] ) { |
|
450 | + $prefix = 'foreach '; |
|
451 | + } |
|
452 | + } |
|
453 | + |
|
454 | + $with_tags = $args['conditional_check'] ? 3 : 2; |
|
455 | + if ( ! empty( $shortcodes[ $with_tags ][ $short_key ] ) ) { |
|
456 | + $tag = str_replace( '[' . $prefix, '', $shortcodes[0][ $short_key ] ); |
|
457 | + $tag = str_replace(']', '', $tag); |
|
458 | + $tags = explode(' ', $tag); |
|
459 | + if ( is_array($tags) ) { |
|
460 | + $tag = $tags[0]; |
|
461 | + } |
|
462 | + } else { |
|
463 | + $tag = $shortcodes[ $with_tags - 1 ][ $short_key ]; |
|
464 | + } |
|
465 | + |
|
466 | + return $tag; |
|
467 | + } |
|
468 | 468 | |
469 | 469 | /** |
470 | 470 | * Remove [collapse_this] if it's still included after all processing |
@@ -477,128 +477,128 @@ discard block |
||
477 | 477 | } |
478 | 478 | |
479 | 479 | public static function display_recaptcha( $field ) { |
480 | - $frm_settings = FrmAppHelper::get_settings(); |
|
481 | - $lang = apply_filters('frm_recaptcha_lang', $frm_settings->re_lang, $field); |
|
480 | + $frm_settings = FrmAppHelper::get_settings(); |
|
481 | + $lang = apply_filters('frm_recaptcha_lang', $frm_settings->re_lang, $field); |
|
482 | 482 | |
483 | - $api_js_url = 'https://www.google.com/recaptcha/api.js?onload=frmRecaptcha&render=explicit'; |
|
484 | - if ( $lang != 'en' ) { |
|
483 | + $api_js_url = 'https://www.google.com/recaptcha/api.js?onload=frmRecaptcha&render=explicit'; |
|
484 | + if ( $lang != 'en' ) { |
|
485 | 485 | $api_js_url .= '&hl=' . $lang; |
486 | - } |
|
487 | - $api_js_url = apply_filters('frm_recpatcha_js_url', $api_js_url); |
|
486 | + } |
|
487 | + $api_js_url = apply_filters('frm_recpatcha_js_url', $api_js_url); |
|
488 | 488 | |
489 | - wp_register_script('recaptcha-api', $api_js_url, '', true); |
|
490 | - wp_enqueue_script('recaptcha-api'); |
|
489 | + wp_register_script('recaptcha-api', $api_js_url, '', true); |
|
490 | + wp_enqueue_script('recaptcha-api'); |
|
491 | 491 | |
492 | 492 | ?> |
493 | 493 | <div id="field_<?php echo esc_attr( $field['field_key'] ) ?>" class="frm-g-recaptcha" data-sitekey="<?php echo esc_attr( $frm_settings->pubkey ) ?>" data-size="<?php echo esc_attr( $field['captcha_size'] ) ?>"></div> |
494 | 494 | <?php |
495 | - } |
|
495 | + } |
|
496 | 496 | |
497 | 497 | public static function show_single_option( $field ) { |
498 | - $field_name = $field['name']; |
|
499 | - $html_id = self::get_html_id($field); |
|
500 | - foreach ( $field['options'] as $opt_key => $opt ) { |
|
501 | - $field_val = apply_filters('frm_field_value_saved', $opt, $opt_key, $field); |
|
502 | - $opt = apply_filters('frm_field_label_seen', $opt, $opt_key, $field); |
|
498 | + $field_name = $field['name']; |
|
499 | + $html_id = self::get_html_id($field); |
|
500 | + foreach ( $field['options'] as $opt_key => $opt ) { |
|
501 | + $field_val = apply_filters('frm_field_value_saved', $opt, $opt_key, $field); |
|
502 | + $opt = apply_filters('frm_field_label_seen', $opt, $opt_key, $field); |
|
503 | 503 | |
504 | - // If this is an "Other" option, get the HTML for it |
|
504 | + // If this is an "Other" option, get the HTML for it |
|
505 | 505 | if ( self::is_other_opt( $opt_key ) ) { |
506 | - // Get string for Other text field, if needed |
|
506 | + // Get string for Other text field, if needed |
|
507 | 507 | $other_val = self::get_other_val( compact( 'opt_key', 'field' ) ); |
508 | 508 | require( FrmAppHelper::plugin_path() . '/pro/classes/views/frmpro-fields/other-option.php' ); |
509 | - } else { |
|
509 | + } else { |
|
510 | 510 | require( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/single-option.php' ); |
511 | - } |
|
512 | - } |
|
513 | - } |
|
511 | + } |
|
512 | + } |
|
513 | + } |
|
514 | 514 | |
515 | 515 | public static function dropdown_categories( $args ) { |
516 | 516 | $defaults = array( 'field' => false, 'name' => false, 'show_option_all' => ' ' ); |
517 | - $args = wp_parse_args($args, $defaults); |
|
517 | + $args = wp_parse_args($args, $defaults); |
|
518 | 518 | |
519 | - if ( ! $args['field'] ) { |
|
520 | - return; |
|
521 | - } |
|
519 | + if ( ! $args['field'] ) { |
|
520 | + return; |
|
521 | + } |
|
522 | 522 | |
523 | - if ( ! $args['name'] ) { |
|
523 | + if ( ! $args['name'] ) { |
|
524 | 524 | $args['name'] = 'item_meta[' . $args['field']['id'] . ']'; |
525 | - } |
|
525 | + } |
|
526 | 526 | |
527 | - $id = self::get_html_id($args['field']); |
|
528 | - $class = $args['field']['type']; |
|
527 | + $id = self::get_html_id($args['field']); |
|
528 | + $class = $args['field']['type']; |
|
529 | 529 | |
530 | - $exclude = (is_array($args['field']['exclude_cat'])) ? implode(',', $args['field']['exclude_cat']) : $args['field']['exclude_cat']; |
|
531 | - $exclude = apply_filters('frm_exclude_cats', $exclude, $args['field']); |
|
530 | + $exclude = (is_array($args['field']['exclude_cat'])) ? implode(',', $args['field']['exclude_cat']) : $args['field']['exclude_cat']; |
|
531 | + $exclude = apply_filters('frm_exclude_cats', $exclude, $args['field']); |
|
532 | 532 | |
533 | - if ( is_array($args['field']['value']) ) { |
|
534 | - if ( ! empty($exclude) ) { |
|
535 | - $args['field']['value'] = array_diff($args['field']['value'], explode(',', $exclude)); |
|
536 | - } |
|
537 | - $selected = reset($args['field']['value']); |
|
538 | - } else { |
|
539 | - $selected = $args['field']['value']; |
|
540 | - } |
|
533 | + if ( is_array($args['field']['value']) ) { |
|
534 | + if ( ! empty($exclude) ) { |
|
535 | + $args['field']['value'] = array_diff($args['field']['value'], explode(',', $exclude)); |
|
536 | + } |
|
537 | + $selected = reset($args['field']['value']); |
|
538 | + } else { |
|
539 | + $selected = $args['field']['value']; |
|
540 | + } |
|
541 | 541 | |
542 | - $tax_atts = array( |
|
543 | - 'show_option_all' => $args['show_option_all'], 'hierarchical' => 1, 'name' => $args['name'], |
|
544 | - 'id' => $id, 'exclude' => $exclude, 'class' => $class, 'selected' => $selected, |
|
545 | - 'hide_empty' => false, 'echo' => 0, 'orderby' => 'name', |
|
546 | - ); |
|
542 | + $tax_atts = array( |
|
543 | + 'show_option_all' => $args['show_option_all'], 'hierarchical' => 1, 'name' => $args['name'], |
|
544 | + 'id' => $id, 'exclude' => $exclude, 'class' => $class, 'selected' => $selected, |
|
545 | + 'hide_empty' => false, 'echo' => 0, 'orderby' => 'name', |
|
546 | + ); |
|
547 | 547 | |
548 | - $tax_atts = apply_filters('frm_dropdown_cat', $tax_atts, $args['field']); |
|
548 | + $tax_atts = apply_filters('frm_dropdown_cat', $tax_atts, $args['field']); |
|
549 | 549 | |
550 | - if ( FrmAppHelper::pro_is_installed() ) { |
|
551 | - $post_type = FrmProFormsHelper::post_type($args['field']['form_id']); |
|
552 | - $tax_atts['taxonomy'] = FrmProAppHelper::get_custom_taxonomy($post_type, $args['field']); |
|
553 | - if ( ! $tax_atts['taxonomy'] ) { |
|
554 | - return; |
|
555 | - } |
|
550 | + if ( FrmAppHelper::pro_is_installed() ) { |
|
551 | + $post_type = FrmProFormsHelper::post_type($args['field']['form_id']); |
|
552 | + $tax_atts['taxonomy'] = FrmProAppHelper::get_custom_taxonomy($post_type, $args['field']); |
|
553 | + if ( ! $tax_atts['taxonomy'] ) { |
|
554 | + return; |
|
555 | + } |
|
556 | 556 | |
557 | - // If field type is dropdown (not Dynamic), exclude children when parent is excluded |
|
558 | - if ( $args['field']['type'] != 'data' && is_taxonomy_hierarchical($tax_atts['taxonomy']) ) { |
|
559 | - $tax_atts['exclude_tree'] = $exclude; |
|
560 | - } |
|
561 | - } |
|
557 | + // If field type is dropdown (not Dynamic), exclude children when parent is excluded |
|
558 | + if ( $args['field']['type'] != 'data' && is_taxonomy_hierarchical($tax_atts['taxonomy']) ) { |
|
559 | + $tax_atts['exclude_tree'] = $exclude; |
|
560 | + } |
|
561 | + } |
|
562 | 562 | |
563 | - $dropdown = wp_dropdown_categories($tax_atts); |
|
563 | + $dropdown = wp_dropdown_categories($tax_atts); |
|
564 | 564 | |
565 | - $add_html = FrmFieldsController::input_html($args['field'], false); |
|
565 | + $add_html = FrmFieldsController::input_html($args['field'], false); |
|
566 | 566 | |
567 | - if ( FrmAppHelper::pro_is_installed() ) { |
|
568 | - $add_html .= FrmProFieldsController::input_html($args['field'], false); |
|
569 | - } |
|
567 | + if ( FrmAppHelper::pro_is_installed() ) { |
|
568 | + $add_html .= FrmProFieldsController::input_html($args['field'], false); |
|
569 | + } |
|
570 | 570 | |
571 | 571 | $dropdown = str_replace( "<select name='" . esc_attr( $args['name'] ) . "' id='" . esc_attr( $id ) . "' class='" . esc_attr( $class ) . "'", "<select name='" . esc_attr( $args['name'] ) . "' id='" . esc_attr( $id ) . "' " . $add_html, $dropdown ); |
572 | 572 | |
573 | - if ( is_array($args['field']['value']) ) { |
|
574 | - $skip = true; |
|
575 | - foreach ( $args['field']['value'] as $v ) { |
|
573 | + if ( is_array($args['field']['value']) ) { |
|
574 | + $skip = true; |
|
575 | + foreach ( $args['field']['value'] as $v ) { |
|
576 | 576 | if ( $skip ) { |
577 | - $skip = false; |
|
578 | - continue; |
|
579 | - } |
|
577 | + $skip = false; |
|
578 | + continue; |
|
579 | + } |
|
580 | 580 | $dropdown = str_replace(' value="' . esc_attr( $v ) . '"', ' value="' . esc_attr( $v ) . '" selected="selected"', $dropdown ); |
581 | - unset($v); |
|
582 | - } |
|
583 | - } |
|
581 | + unset($v); |
|
582 | + } |
|
583 | + } |
|
584 | 584 | |
585 | - return $dropdown; |
|
586 | - } |
|
585 | + return $dropdown; |
|
586 | + } |
|
587 | 587 | |
588 | 588 | public static function get_term_link( $tax_id ) { |
589 | - $tax = get_taxonomy($tax_id); |
|
590 | - if ( ! $tax ) { |
|
591 | - return; |
|
592 | - } |
|
589 | + $tax = get_taxonomy($tax_id); |
|
590 | + if ( ! $tax ) { |
|
591 | + return; |
|
592 | + } |
|
593 | 593 | |
594 | - $link = sprintf( |
|
595 | - __( 'Please add options from the WordPress "%1$s" page', 'formidable' ), |
|
594 | + $link = sprintf( |
|
595 | + __( 'Please add options from the WordPress "%1$s" page', 'formidable' ), |
|
596 | 596 | '<a href="' . esc_url( admin_url( 'edit-tags.php?taxonomy=' . $tax->name ) ) . '" target="_blank">' . ( empty( $tax->labels->name ) ? __( 'Categories' ) : $tax->labels->name ) . '</a>' |
597 | - ); |
|
598 | - unset($tax); |
|
597 | + ); |
|
598 | + unset($tax); |
|
599 | 599 | |
600 | - return $link; |
|
601 | - } |
|
600 | + return $link; |
|
601 | + } |
|
602 | 602 | |
603 | 603 | public static function value_meets_condition( $observed_value, $cond, $hide_opt ) { |
604 | 604 | // Remove white space from hide_opt |
@@ -606,195 +606,195 @@ discard block |
||
606 | 606 | $hide_opt = rtrim( $hide_opt ); |
607 | 607 | } |
608 | 608 | |
609 | - if ( is_array($observed_value) ) { |
|
610 | - return self::array_value_condition($observed_value, $cond, $hide_opt); |
|
611 | - } |
|
612 | - |
|
613 | - $m = false; |
|
614 | - if ( $cond == '==' ) { |
|
615 | - $m = $observed_value == $hide_opt; |
|
616 | - } else if ( $cond == '!=' ) { |
|
617 | - $m = $observed_value != $hide_opt; |
|
618 | - } else if ( $cond == '>' ) { |
|
619 | - $m = $observed_value > $hide_opt; |
|
620 | - } else if ( $cond == '<' ) { |
|
621 | - $m = $observed_value < $hide_opt; |
|
622 | - } else if ( $cond == 'LIKE' || $cond == 'not LIKE' ) { |
|
623 | - $m = stripos($observed_value, $hide_opt); |
|
624 | - if ( $cond == 'not LIKE' ) { |
|
625 | - $m = ( $m === false ) ? true : false; |
|
626 | - } else { |
|
627 | - $m = ( $m === false ) ? false : true; |
|
628 | - } |
|
629 | - } |
|
630 | - return $m; |
|
631 | - } |
|
609 | + if ( is_array($observed_value) ) { |
|
610 | + return self::array_value_condition($observed_value, $cond, $hide_opt); |
|
611 | + } |
|
612 | + |
|
613 | + $m = false; |
|
614 | + if ( $cond == '==' ) { |
|
615 | + $m = $observed_value == $hide_opt; |
|
616 | + } else if ( $cond == '!=' ) { |
|
617 | + $m = $observed_value != $hide_opt; |
|
618 | + } else if ( $cond == '>' ) { |
|
619 | + $m = $observed_value > $hide_opt; |
|
620 | + } else if ( $cond == '<' ) { |
|
621 | + $m = $observed_value < $hide_opt; |
|
622 | + } else if ( $cond == 'LIKE' || $cond == 'not LIKE' ) { |
|
623 | + $m = stripos($observed_value, $hide_opt); |
|
624 | + if ( $cond == 'not LIKE' ) { |
|
625 | + $m = ( $m === false ) ? true : false; |
|
626 | + } else { |
|
627 | + $m = ( $m === false ) ? false : true; |
|
628 | + } |
|
629 | + } |
|
630 | + return $m; |
|
631 | + } |
|
632 | 632 | |
633 | 633 | public static function array_value_condition( $observed_value, $cond, $hide_opt ) { |
634 | - $m = false; |
|
635 | - if ( $cond == '==' ) { |
|
636 | - if ( is_array($hide_opt) ) { |
|
637 | - $m = array_intersect($hide_opt, $observed_value); |
|
638 | - $m = empty($m) ? false : true; |
|
639 | - } else { |
|
640 | - $m = in_array($hide_opt, $observed_value); |
|
641 | - } |
|
642 | - } else if ( $cond == '!=' ) { |
|
643 | - $m = ! in_array($hide_opt, $observed_value); |
|
644 | - } else if ( $cond == '>' ) { |
|
645 | - $min = min($observed_value); |
|
646 | - $m = $min > $hide_opt; |
|
647 | - } else if ( $cond == '<' ) { |
|
648 | - $max = max($observed_value); |
|
649 | - $m = $max < $hide_opt; |
|
650 | - } else if ( $cond == 'LIKE' || $cond == 'not LIKE' ) { |
|
651 | - foreach ( $observed_value as $ob ) { |
|
652 | - $m = strpos($ob, $hide_opt); |
|
653 | - if ( $m !== false ) { |
|
654 | - $m = true; |
|
655 | - break; |
|
656 | - } |
|
657 | - } |
|
658 | - |
|
659 | - if ( $cond == 'not LIKE' ) { |
|
660 | - $m = ( $m === false ) ? true : false; |
|
661 | - } |
|
662 | - } |
|
663 | - |
|
664 | - return $m; |
|
665 | - } |
|
666 | - |
|
667 | - /** |
|
668 | - * Replace a few basic shortcodes and field ids |
|
669 | - * @since 2.0 |
|
670 | - * @return string |
|
671 | - */ |
|
634 | + $m = false; |
|
635 | + if ( $cond == '==' ) { |
|
636 | + if ( is_array($hide_opt) ) { |
|
637 | + $m = array_intersect($hide_opt, $observed_value); |
|
638 | + $m = empty($m) ? false : true; |
|
639 | + } else { |
|
640 | + $m = in_array($hide_opt, $observed_value); |
|
641 | + } |
|
642 | + } else if ( $cond == '!=' ) { |
|
643 | + $m = ! in_array($hide_opt, $observed_value); |
|
644 | + } else if ( $cond == '>' ) { |
|
645 | + $min = min($observed_value); |
|
646 | + $m = $min > $hide_opt; |
|
647 | + } else if ( $cond == '<' ) { |
|
648 | + $max = max($observed_value); |
|
649 | + $m = $max < $hide_opt; |
|
650 | + } else if ( $cond == 'LIKE' || $cond == 'not LIKE' ) { |
|
651 | + foreach ( $observed_value as $ob ) { |
|
652 | + $m = strpos($ob, $hide_opt); |
|
653 | + if ( $m !== false ) { |
|
654 | + $m = true; |
|
655 | + break; |
|
656 | + } |
|
657 | + } |
|
658 | + |
|
659 | + if ( $cond == 'not LIKE' ) { |
|
660 | + $m = ( $m === false ) ? true : false; |
|
661 | + } |
|
662 | + } |
|
663 | + |
|
664 | + return $m; |
|
665 | + } |
|
666 | + |
|
667 | + /** |
|
668 | + * Replace a few basic shortcodes and field ids |
|
669 | + * @since 2.0 |
|
670 | + * @return string |
|
671 | + */ |
|
672 | 672 | public static function basic_replace_shortcodes( $value, $form, $entry ) { |
673 | - if ( strpos($value, '[sitename]') !== false ) { |
|
674 | - $new_value = wp_specialchars_decode( FrmAppHelper::site_name(), ENT_QUOTES ); |
|
675 | - $value = str_replace('[sitename]', $new_value, $value); |
|
676 | - } |
|
673 | + if ( strpos($value, '[sitename]') !== false ) { |
|
674 | + $new_value = wp_specialchars_decode( FrmAppHelper::site_name(), ENT_QUOTES ); |
|
675 | + $value = str_replace('[sitename]', $new_value, $value); |
|
676 | + } |
|
677 | 677 | |
678 | - $value = apply_filters('frm_content', $value, $form, $entry); |
|
679 | - $value = do_shortcode($value); |
|
678 | + $value = apply_filters('frm_content', $value, $form, $entry); |
|
679 | + $value = do_shortcode($value); |
|
680 | 680 | |
681 | - return $value; |
|
682 | - } |
|
681 | + return $value; |
|
682 | + } |
|
683 | 683 | |
684 | 684 | public static function get_shortcodes( $content, $form_id ) { |
685 | - if ( FrmAppHelper::pro_is_installed() ) { |
|
686 | - return FrmProDisplaysHelper::get_shortcodes($content, $form_id); |
|
687 | - } |
|
685 | + if ( FrmAppHelper::pro_is_installed() ) { |
|
686 | + return FrmProDisplaysHelper::get_shortcodes($content, $form_id); |
|
687 | + } |
|
688 | 688 | |
689 | - $fields = FrmField::getAll( array( 'fi.form_id' => (int) $form_id, 'fi.type not' => FrmField::no_save_fields() ) ); |
|
689 | + $fields = FrmField::getAll( array( 'fi.form_id' => (int) $form_id, 'fi.type not' => FrmField::no_save_fields() ) ); |
|
690 | 690 | |
691 | - $tagregexp = self::allowed_shortcodes($fields); |
|
691 | + $tagregexp = self::allowed_shortcodes($fields); |
|
692 | 692 | |
693 | - preg_match_all("/\[(if )?($tagregexp)\b(.*?)(?:(\/))?\](?:(.+?)\[\/\2\])?/s", $content, $matches, PREG_PATTERN_ORDER); |
|
693 | + preg_match_all("/\[(if )?($tagregexp)\b(.*?)(?:(\/))?\](?:(.+?)\[\/\2\])?/s", $content, $matches, PREG_PATTERN_ORDER); |
|
694 | 694 | |
695 | - return $matches; |
|
696 | - } |
|
695 | + return $matches; |
|
696 | + } |
|
697 | 697 | |
698 | 698 | public static function allowed_shortcodes( $fields = array() ) { |
699 | - $tagregexp = array( |
|
700 | - 'editlink', 'id', 'key', 'ip', |
|
701 | - 'siteurl', 'sitename', 'admin_email', |
|
702 | - 'post[-|_]id', 'created[-|_]at', 'updated[-|_]at', 'updated[-|_]by', |
|
699 | + $tagregexp = array( |
|
700 | + 'editlink', 'id', 'key', 'ip', |
|
701 | + 'siteurl', 'sitename', 'admin_email', |
|
702 | + 'post[-|_]id', 'created[-|_]at', 'updated[-|_]at', 'updated[-|_]by', |
|
703 | 703 | 'parent[-|_]id', |
704 | - ); |
|
704 | + ); |
|
705 | 705 | |
706 | - foreach ( $fields as $field ) { |
|
707 | - $tagregexp[] = $field->id; |
|
708 | - $tagregexp[] = $field->field_key; |
|
709 | - } |
|
706 | + foreach ( $fields as $field ) { |
|
707 | + $tagregexp[] = $field->id; |
|
708 | + $tagregexp[] = $field->field_key; |
|
709 | + } |
|
710 | 710 | |
711 | - $tagregexp = implode('|', $tagregexp); |
|
712 | - return $tagregexp; |
|
713 | - } |
|
711 | + $tagregexp = implode('|', $tagregexp); |
|
712 | + return $tagregexp; |
|
713 | + } |
|
714 | 714 | |
715 | 715 | public static function replace_content_shortcodes( $content, $entry, $shortcodes ) { |
716 | - $shortcode_values = array( |
|
717 | - 'id' => $entry->id, |
|
718 | - 'key' => $entry->item_key, |
|
719 | - 'ip' => $entry->ip, |
|
720 | - ); |
|
716 | + $shortcode_values = array( |
|
717 | + 'id' => $entry->id, |
|
718 | + 'key' => $entry->item_key, |
|
719 | + 'ip' => $entry->ip, |
|
720 | + ); |
|
721 | 721 | |
722 | - foreach ( $shortcodes[0] as $short_key => $tag ) { |
|
723 | - $atts = shortcode_parse_atts( $shortcodes[3][ $short_key ] ); |
|
722 | + foreach ( $shortcodes[0] as $short_key => $tag ) { |
|
723 | + $atts = shortcode_parse_atts( $shortcodes[3][ $short_key ] ); |
|
724 | 724 | |
725 | - if ( ! empty( $shortcodes[3][ $short_key ] ) ) { |
|
725 | + if ( ! empty( $shortcodes[3][ $short_key ] ) ) { |
|
726 | 726 | $tag = str_replace( array( '[', ']' ), '', $shortcodes[0][ $short_key ] ); |
727 | - $tags = explode(' ', $tag); |
|
728 | - if ( is_array($tags) ) { |
|
729 | - $tag = $tags[0]; |
|
730 | - } |
|
731 | - } else { |
|
732 | - $tag = $shortcodes[2][ $short_key ]; |
|
733 | - } |
|
734 | - |
|
735 | - switch ( $tag ) { |
|
736 | - case 'id': |
|
737 | - case 'key': |
|
738 | - case 'ip': |
|
739 | - $replace_with = $shortcode_values[ $tag ]; |
|
740 | - break; |
|
741 | - |
|
742 | - case 'user_agent': |
|
743 | - case 'user-agent': |
|
744 | - $entry->description = maybe_unserialize($entry->description); |
|
727 | + $tags = explode(' ', $tag); |
|
728 | + if ( is_array($tags) ) { |
|
729 | + $tag = $tags[0]; |
|
730 | + } |
|
731 | + } else { |
|
732 | + $tag = $shortcodes[2][ $short_key ]; |
|
733 | + } |
|
734 | + |
|
735 | + switch ( $tag ) { |
|
736 | + case 'id': |
|
737 | + case 'key': |
|
738 | + case 'ip': |
|
739 | + $replace_with = $shortcode_values[ $tag ]; |
|
740 | + break; |
|
741 | + |
|
742 | + case 'user_agent': |
|
743 | + case 'user-agent': |
|
744 | + $entry->description = maybe_unserialize($entry->description); |
|
745 | 745 | $replace_with = FrmEntryFormat::get_browser( $entry->description['browser'] ); |
746 | - break; |
|
747 | - |
|
748 | - case 'created_at': |
|
749 | - case 'created-at': |
|
750 | - case 'updated_at': |
|
751 | - case 'updated-at': |
|
752 | - if ( isset($atts['format']) ) { |
|
753 | - $time_format = ' '; |
|
754 | - } else { |
|
755 | - $atts['format'] = get_option('date_format'); |
|
756 | - $time_format = ''; |
|
757 | - } |
|
758 | - |
|
759 | - $this_tag = str_replace('-', '_', $tag); |
|
760 | - $replace_with = FrmAppHelper::get_formatted_time($entry->{$this_tag}, $atts['format'], $time_format); |
|
761 | - unset($this_tag); |
|
762 | - break; |
|
763 | - |
|
764 | - case 'created_by': |
|
765 | - case 'created-by': |
|
766 | - case 'updated_by': |
|
767 | - case 'updated-by': |
|
768 | - $this_tag = str_replace('-', '_', $tag); |
|
746 | + break; |
|
747 | + |
|
748 | + case 'created_at': |
|
749 | + case 'created-at': |
|
750 | + case 'updated_at': |
|
751 | + case 'updated-at': |
|
752 | + if ( isset($atts['format']) ) { |
|
753 | + $time_format = ' '; |
|
754 | + } else { |
|
755 | + $atts['format'] = get_option('date_format'); |
|
756 | + $time_format = ''; |
|
757 | + } |
|
758 | + |
|
759 | + $this_tag = str_replace('-', '_', $tag); |
|
760 | + $replace_with = FrmAppHelper::get_formatted_time($entry->{$this_tag}, $atts['format'], $time_format); |
|
761 | + unset($this_tag); |
|
762 | + break; |
|
763 | + |
|
764 | + case 'created_by': |
|
765 | + case 'created-by': |
|
766 | + case 'updated_by': |
|
767 | + case 'updated-by': |
|
768 | + $this_tag = str_replace('-', '_', $tag); |
|
769 | 769 | $replace_with = self::get_display_value( $entry->{$this_tag}, (object) array( 'type' => 'user_id' ), $atts ); |
770 | - unset($this_tag); |
|
771 | - break; |
|
772 | - |
|
773 | - case 'admin_email': |
|
774 | - case 'siteurl': |
|
775 | - case 'frmurl': |
|
776 | - case 'sitename': |
|
777 | - case 'get': |
|
778 | - $replace_with = self::dynamic_default_values( $tag, $atts ); |
|
779 | - break; |
|
780 | - |
|
781 | - default: |
|
782 | - $field = FrmField::getOne( $tag ); |
|
783 | - if ( ! $field ) { |
|
784 | - break; |
|
785 | - } |
|
786 | - |
|
787 | - $sep = isset($atts['sep']) ? $atts['sep'] : ', '; |
|
788 | - |
|
789 | - $replace_with = FrmEntryMeta::get_meta_value( $entry, $field->id ); |
|
790 | - |
|
791 | - $atts['entry_id'] = $entry->id; |
|
792 | - $atts['entry_key'] = $entry->item_key; |
|
793 | - |
|
794 | - if ( isset($atts['show']) && $atts['show'] == 'field_label' ) { |
|
795 | - $replace_with = $field->name; |
|
796 | - } else if ( isset($atts['show']) && $atts['show'] == 'description' ) { |
|
797 | - $replace_with = $field->description; |
|
770 | + unset($this_tag); |
|
771 | + break; |
|
772 | + |
|
773 | + case 'admin_email': |
|
774 | + case 'siteurl': |
|
775 | + case 'frmurl': |
|
776 | + case 'sitename': |
|
777 | + case 'get': |
|
778 | + $replace_with = self::dynamic_default_values( $tag, $atts ); |
|
779 | + break; |
|
780 | + |
|
781 | + default: |
|
782 | + $field = FrmField::getOne( $tag ); |
|
783 | + if ( ! $field ) { |
|
784 | + break; |
|
785 | + } |
|
786 | + |
|
787 | + $sep = isset($atts['sep']) ? $atts['sep'] : ', '; |
|
788 | + |
|
789 | + $replace_with = FrmEntryMeta::get_meta_value( $entry, $field->id ); |
|
790 | + |
|
791 | + $atts['entry_id'] = $entry->id; |
|
792 | + $atts['entry_key'] = $entry->item_key; |
|
793 | + |
|
794 | + if ( isset($atts['show']) && $atts['show'] == 'field_label' ) { |
|
795 | + $replace_with = $field->name; |
|
796 | + } else if ( isset($atts['show']) && $atts['show'] == 'description' ) { |
|
797 | + $replace_with = $field->description; |
|
798 | 798 | } else { |
799 | 799 | $string_value = $replace_with; |
800 | 800 | if ( is_array( $replace_with ) ) { |
@@ -808,82 +808,82 @@ discard block |
||
808 | 808 | } |
809 | 809 | } |
810 | 810 | |
811 | - unset($field); |
|
812 | - break; |
|
813 | - } |
|
811 | + unset($field); |
|
812 | + break; |
|
813 | + } |
|
814 | 814 | |
815 | - if ( isset($replace_with) ) { |
|
816 | - $content = str_replace( $shortcodes[0][ $short_key ], $replace_with, $content ); |
|
817 | - } |
|
815 | + if ( isset($replace_with) ) { |
|
816 | + $content = str_replace( $shortcodes[0][ $short_key ], $replace_with, $content ); |
|
817 | + } |
|
818 | 818 | |
819 | - unset($atts, $conditional, $replace_with); |
|
819 | + unset($atts, $conditional, $replace_with); |
|
820 | 820 | } |
821 | 821 | |
822 | 822 | return $content; |
823 | - } |
|
824 | - |
|
825 | - /** |
|
826 | - * Get the value to replace a few standard shortcodes |
|
827 | - * |
|
828 | - * @since 2.0 |
|
829 | - * @return string |
|
830 | - */ |
|
831 | - public static function dynamic_default_values( $tag, $atts = array(), $return_array = false ) { |
|
832 | - $new_value = ''; |
|
833 | - switch ( $tag ) { |
|
834 | - case 'admin_email': |
|
835 | - $new_value = get_option('admin_email'); |
|
836 | - break; |
|
837 | - case 'siteurl': |
|
838 | - $new_value = FrmAppHelper::site_url(); |
|
839 | - break; |
|
840 | - case 'frmurl': |
|
841 | - $new_value = FrmAppHelper::plugin_url(); |
|
842 | - break; |
|
843 | - case 'sitename': |
|
844 | - $new_value = FrmAppHelper::site_name(); |
|
845 | - break; |
|
846 | - case 'get': |
|
847 | - $new_value = self::process_get_shortcode( $atts, $return_array ); |
|
848 | - break; |
|
849 | - } |
|
850 | - |
|
851 | - return $new_value; |
|
852 | - } |
|
853 | - |
|
854 | - /** |
|
855 | - * Process the [get] shortcode |
|
856 | - * |
|
857 | - * @since 2.0 |
|
858 | - * @return string|array |
|
859 | - */ |
|
860 | - public static function process_get_shortcode( $atts, $return_array = false ) { |
|
861 | - if ( ! isset($atts['param']) ) { |
|
862 | - return ''; |
|
863 | - } |
|
864 | - |
|
865 | - if ( strpos($atts['param'], '[') ) { |
|
866 | - $atts['param'] = str_replace('[', '[', $atts['param']); |
|
867 | - $atts['param'] = str_replace(']', ']', $atts['param']); |
|
868 | - } |
|
869 | - |
|
870 | - $new_value = FrmAppHelper::get_param($atts['param'], ''); |
|
871 | - $new_value = FrmAppHelper::get_query_var( $new_value, $atts['param'] ); |
|
872 | - |
|
873 | - if ( $new_value == '' ) { |
|
874 | - if ( ! isset($atts['prev_val']) ) { |
|
875 | - $atts['prev_val'] = ''; |
|
876 | - } |
|
877 | - |
|
878 | - $new_value = isset($atts['default']) ? $atts['default'] : $atts['prev_val']; |
|
879 | - } |
|
880 | - |
|
881 | - if ( is_array($new_value) && ! $return_array ) { |
|
882 | - $new_value = implode(', ', $new_value); |
|
883 | - } |
|
884 | - |
|
885 | - return $new_value; |
|
886 | - } |
|
823 | + } |
|
824 | + |
|
825 | + /** |
|
826 | + * Get the value to replace a few standard shortcodes |
|
827 | + * |
|
828 | + * @since 2.0 |
|
829 | + * @return string |
|
830 | + */ |
|
831 | + public static function dynamic_default_values( $tag, $atts = array(), $return_array = false ) { |
|
832 | + $new_value = ''; |
|
833 | + switch ( $tag ) { |
|
834 | + case 'admin_email': |
|
835 | + $new_value = get_option('admin_email'); |
|
836 | + break; |
|
837 | + case 'siteurl': |
|
838 | + $new_value = FrmAppHelper::site_url(); |
|
839 | + break; |
|
840 | + case 'frmurl': |
|
841 | + $new_value = FrmAppHelper::plugin_url(); |
|
842 | + break; |
|
843 | + case 'sitename': |
|
844 | + $new_value = FrmAppHelper::site_name(); |
|
845 | + break; |
|
846 | + case 'get': |
|
847 | + $new_value = self::process_get_shortcode( $atts, $return_array ); |
|
848 | + break; |
|
849 | + } |
|
850 | + |
|
851 | + return $new_value; |
|
852 | + } |
|
853 | + |
|
854 | + /** |
|
855 | + * Process the [get] shortcode |
|
856 | + * |
|
857 | + * @since 2.0 |
|
858 | + * @return string|array |
|
859 | + */ |
|
860 | + public static function process_get_shortcode( $atts, $return_array = false ) { |
|
861 | + if ( ! isset($atts['param']) ) { |
|
862 | + return ''; |
|
863 | + } |
|
864 | + |
|
865 | + if ( strpos($atts['param'], '[') ) { |
|
866 | + $atts['param'] = str_replace('[', '[', $atts['param']); |
|
867 | + $atts['param'] = str_replace(']', ']', $atts['param']); |
|
868 | + } |
|
869 | + |
|
870 | + $new_value = FrmAppHelper::get_param($atts['param'], ''); |
|
871 | + $new_value = FrmAppHelper::get_query_var( $new_value, $atts['param'] ); |
|
872 | + |
|
873 | + if ( $new_value == '' ) { |
|
874 | + if ( ! isset($atts['prev_val']) ) { |
|
875 | + $atts['prev_val'] = ''; |
|
876 | + } |
|
877 | + |
|
878 | + $new_value = isset($atts['default']) ? $atts['default'] : $atts['prev_val']; |
|
879 | + } |
|
880 | + |
|
881 | + if ( is_array($new_value) && ! $return_array ) { |
|
882 | + $new_value = implode(', ', $new_value); |
|
883 | + } |
|
884 | + |
|
885 | + return $new_value; |
|
886 | + } |
|
887 | 887 | |
888 | 888 | public static function get_display_value( $replace_with, $field, $atts = array() ) { |
889 | 889 | $atts['sep'] = isset( $atts['sep'] ) ? $atts['sep'] : ', '; |
@@ -891,14 +891,14 @@ discard block |
||
891 | 891 | $replace_with = apply_filters( 'frm_get_' . $field->type . '_display_value', $replace_with, $field, $atts ); |
892 | 892 | $replace_with = apply_filters( 'frm_get_display_value', $replace_with, $field, $atts ); |
893 | 893 | |
894 | - if ( $field->type == 'textarea' || $field->type == 'rte' ) { |
|
895 | - $autop = isset($atts['wpautop']) ? $atts['wpautop'] : true; |
|
896 | - if ( apply_filters('frm_use_wpautop', $autop) ) { |
|
897 | - if ( is_array($replace_with) ) { |
|
898 | - $replace_with = implode("\n", $replace_with); |
|
899 | - } |
|
900 | - $replace_with = wpautop($replace_with); |
|
901 | - } |
|
894 | + if ( $field->type == 'textarea' || $field->type == 'rte' ) { |
|
895 | + $autop = isset($atts['wpautop']) ? $atts['wpautop'] : true; |
|
896 | + if ( apply_filters('frm_use_wpautop', $autop) ) { |
|
897 | + if ( is_array($replace_with) ) { |
|
898 | + $replace_with = implode("\n", $replace_with); |
|
899 | + } |
|
900 | + $replace_with = wpautop($replace_with); |
|
901 | + } |
|
902 | 902 | unset( $autop ); |
903 | 903 | } else if ( is_array( $replace_with ) ) { |
904 | 904 | $replace_with = implode( $atts['sep'], $replace_with ); |
@@ -908,57 +908,57 @@ discard block |
||
908 | 908 | } |
909 | 909 | |
910 | 910 | public static function get_field_types( $type ) { |
911 | - $single_input = array( |
|
912 | - 'text', 'textarea', 'rte', 'number', 'email', 'url', |
|
913 | - 'image', 'file', 'date', 'phone', 'hidden', 'time', |
|
914 | - 'user_id', 'tag', 'password', |
|
915 | - ); |
|
911 | + $single_input = array( |
|
912 | + 'text', 'textarea', 'rte', 'number', 'email', 'url', |
|
913 | + 'image', 'file', 'date', 'phone', 'hidden', 'time', |
|
914 | + 'user_id', 'tag', 'password', |
|
915 | + ); |
|
916 | 916 | $multiple_input = array( 'radio', 'checkbox', 'select', 'scale' ); |
917 | 917 | $other_type = array( 'divider', 'html', 'break' ); |
918 | 918 | |
919 | 919 | $field_selection = array_merge( FrmField::pro_field_selection(), FrmField::field_selection() ); |
920 | 920 | |
921 | - $field_types = array(); |
|
922 | - if ( in_array($type, $single_input) ) { |
|
923 | - self::field_types_for_input( $single_input, $field_selection, $field_types ); |
|
924 | - } else if ( in_array($type, $multiple_input) ) { |
|
925 | - self::field_types_for_input( $multiple_input, $field_selection, $field_types ); |
|
926 | - } else if ( in_array($type, $other_type) ) { |
|
927 | - self::field_types_for_input( $other_type, $field_selection, $field_types ); |
|
921 | + $field_types = array(); |
|
922 | + if ( in_array($type, $single_input) ) { |
|
923 | + self::field_types_for_input( $single_input, $field_selection, $field_types ); |
|
924 | + } else if ( in_array($type, $multiple_input) ) { |
|
925 | + self::field_types_for_input( $multiple_input, $field_selection, $field_types ); |
|
926 | + } else if ( in_array($type, $other_type) ) { |
|
927 | + self::field_types_for_input( $other_type, $field_selection, $field_types ); |
|
928 | 928 | } else if ( isset( $field_selection[ $type ] ) ) { |
929 | - $field_types[ $type ] = $field_selection[ $type ]; |
|
930 | - } |
|
931 | - |
|
932 | - return $field_types; |
|
933 | - } |
|
934 | - |
|
935 | - private static function field_types_for_input( $inputs, $fields, &$field_types ) { |
|
936 | - foreach ( $inputs as $input ) { |
|
937 | - $field_types[ $input ] = $fields[ $input ]; |
|
938 | - unset($input); |
|
939 | - } |
|
940 | - } |
|
941 | - |
|
942 | - /** |
|
943 | - * Check if current field option is an "other" option |
|
944 | - * |
|
945 | - * @since 2.0.6 |
|
946 | - * |
|
947 | - * @param string $opt_key |
|
948 | - * @return boolean Returns true if current field option is an "Other" option |
|
949 | - */ |
|
950 | - public static function is_other_opt( $opt_key ) { |
|
951 | - return $opt_key && strpos( $opt_key, 'other' ) !== false; |
|
952 | - } |
|
953 | - |
|
954 | - /** |
|
955 | - * Get value that belongs in "Other" text box |
|
956 | - * |
|
957 | - * @since 2.0.6 |
|
958 | - * |
|
959 | - * @param array $args |
|
960 | - */ |
|
961 | - public static function get_other_val( $args ) { |
|
929 | + $field_types[ $type ] = $field_selection[ $type ]; |
|
930 | + } |
|
931 | + |
|
932 | + return $field_types; |
|
933 | + } |
|
934 | + |
|
935 | + private static function field_types_for_input( $inputs, $fields, &$field_types ) { |
|
936 | + foreach ( $inputs as $input ) { |
|
937 | + $field_types[ $input ] = $fields[ $input ]; |
|
938 | + unset($input); |
|
939 | + } |
|
940 | + } |
|
941 | + |
|
942 | + /** |
|
943 | + * Check if current field option is an "other" option |
|
944 | + * |
|
945 | + * @since 2.0.6 |
|
946 | + * |
|
947 | + * @param string $opt_key |
|
948 | + * @return boolean Returns true if current field option is an "Other" option |
|
949 | + */ |
|
950 | + public static function is_other_opt( $opt_key ) { |
|
951 | + return $opt_key && strpos( $opt_key, 'other' ) !== false; |
|
952 | + } |
|
953 | + |
|
954 | + /** |
|
955 | + * Get value that belongs in "Other" text box |
|
956 | + * |
|
957 | + * @since 2.0.6 |
|
958 | + * |
|
959 | + * @param array $args |
|
960 | + */ |
|
961 | + public static function get_other_val( $args ) { |
|
962 | 962 | $defaults = array( |
963 | 963 | 'opt_key' => 0, 'field' => array(), |
964 | 964 | 'parent' => false, 'pointer' => false, |
@@ -1034,20 +1034,20 @@ discard block |
||
1034 | 1034 | } |
1035 | 1035 | |
1036 | 1036 | return $other_val; |
1037 | - } |
|
1038 | - |
|
1039 | - /** |
|
1040 | - * Check if there is a saved value for the "Other" text field. If so, set it as the $other_val. |
|
1041 | - * Intended for front-end use |
|
1042 | - * |
|
1043 | - * @since 2.0.6 |
|
1044 | - * |
|
1045 | - * @param array $args should include field, opt_key and field name |
|
1046 | - * @param boolean $other_opt |
|
1047 | - * @param string $checked |
|
1048 | - * @return string $other_val |
|
1049 | - */ |
|
1050 | - public static function prepare_other_input( $args, &$other_opt, &$checked ) { |
|
1037 | + } |
|
1038 | + |
|
1039 | + /** |
|
1040 | + * Check if there is a saved value for the "Other" text field. If so, set it as the $other_val. |
|
1041 | + * Intended for front-end use |
|
1042 | + * |
|
1043 | + * @since 2.0.6 |
|
1044 | + * |
|
1045 | + * @param array $args should include field, opt_key and field name |
|
1046 | + * @param boolean $other_opt |
|
1047 | + * @param string $checked |
|
1048 | + * @return string $other_val |
|
1049 | + */ |
|
1050 | + public static function prepare_other_input( $args, &$other_opt, &$checked ) { |
|
1051 | 1051 | //Check if this is an "Other" option |
1052 | 1052 | if ( ! self::is_other_opt( $args['opt_key'] ) ) { |
1053 | 1053 | return; |
@@ -1063,8 +1063,8 @@ discard block |
||
1063 | 1063 | $checked = 'checked="checked" '; |
1064 | 1064 | } |
1065 | 1065 | |
1066 | - return $other_args; |
|
1067 | - } |
|
1066 | + return $other_args; |
|
1067 | + } |
|
1068 | 1068 | |
1069 | 1069 | /** |
1070 | 1070 | * @param array $args |
@@ -1113,8 +1113,8 @@ discard block |
||
1113 | 1113 | * @since 2.0.6 |
1114 | 1114 | */ |
1115 | 1115 | public static function include_other_input( $args ) { |
1116 | - if ( ! $args['other_opt'] ) { |
|
1117 | - return; |
|
1116 | + if ( ! $args['other_opt'] ) { |
|
1117 | + return; |
|
1118 | 1118 | } |
1119 | 1119 | |
1120 | 1120 | $classes = array( 'frm_other_input' ); |
@@ -1135,15 +1135,15 @@ discard block |
||
1135 | 1135 | } |
1136 | 1136 | |
1137 | 1137 | /** |
1138 | - * Get the HTML id for an "Other" text field |
|
1139 | - * Note: This does not affect fields in repeating sections |
|
1140 | - * |
|
1141 | - * @since 2.0.08 |
|
1142 | - * @param string $type - field type |
|
1143 | - * @param string $html_id |
|
1144 | - * @param string|boolean $opt_key |
|
1145 | - * @return string $other_id |
|
1146 | - */ |
|
1138 | + * Get the HTML id for an "Other" text field |
|
1139 | + * Note: This does not affect fields in repeating sections |
|
1140 | + * |
|
1141 | + * @since 2.0.08 |
|
1142 | + * @param string $type - field type |
|
1143 | + * @param string $html_id |
|
1144 | + * @param string|boolean $opt_key |
|
1145 | + * @return string $other_id |
|
1146 | + */ |
|
1147 | 1147 | public static function get_other_field_html_id( $type, $html_id, $opt_key = false ) { |
1148 | 1148 | $other_id = $html_id; |
1149 | 1149 | |
@@ -1201,10 +1201,10 @@ discard block |
||
1201 | 1201 | } |
1202 | 1202 | |
1203 | 1203 | public static function switch_field_ids( $val ) { |
1204 | - global $frm_duplicate_ids; |
|
1205 | - $replace = array(); |
|
1206 | - $replace_with = array(); |
|
1207 | - foreach ( (array) $frm_duplicate_ids as $old => $new ) { |
|
1204 | + global $frm_duplicate_ids; |
|
1205 | + $replace = array(); |
|
1206 | + $replace_with = array(); |
|
1207 | + foreach ( (array) $frm_duplicate_ids as $old => $new ) { |
|
1208 | 1208 | $replace[] = '[if ' . $old . ']'; |
1209 | 1209 | $replace_with[] = '[if ' . $new . ']'; |
1210 | 1210 | $replace[] = '[if ' . $old . ' '; |
@@ -1219,153 +1219,153 @@ discard block |
||
1219 | 1219 | $replace_with[] = '[' . $new . ']'; |
1220 | 1220 | $replace[] = '[' . $old . ' '; |
1221 | 1221 | $replace_with[] = '[' . $new . ' '; |
1222 | - unset($old, $new); |
|
1223 | - } |
|
1222 | + unset($old, $new); |
|
1223 | + } |
|
1224 | 1224 | if ( is_array( $val ) ) { |
1225 | 1225 | foreach ( $val as $k => $v ) { |
1226 | - $val[ $k ] = str_replace( $replace, $replace_with, $v ); |
|
1227 | - unset($k, $v); |
|
1228 | - } |
|
1229 | - } else { |
|
1230 | - $val = str_replace($replace, $replace_with, $val); |
|
1231 | - } |
|
1232 | - |
|
1233 | - return $val; |
|
1234 | - } |
|
1235 | - |
|
1236 | - public static function get_us_states() { |
|
1237 | - return apply_filters( 'frm_us_states', array( |
|
1238 | - 'AL' => 'Alabama', 'AK' => 'Alaska', 'AR' => 'Arkansas', 'AZ' => 'Arizona', |
|
1239 | - 'CA' => 'California', 'CO' => 'Colorado', 'CT' => 'Connecticut', 'DE' => 'Delaware', |
|
1240 | - 'DC' => 'District of Columbia', |
|
1241 | - 'FL' => 'Florida', 'GA' => 'Georgia', 'HI' => 'Hawaii', 'ID' => 'Idaho', |
|
1242 | - 'IL' => 'Illinois', 'IN' => 'Indiana', 'IA' => 'Iowa', 'KS' => 'Kansas', |
|
1243 | - 'KY' => 'Kentucky', 'LA' => 'Louisiana', 'ME' => 'Maine','MD' => 'Maryland', |
|
1244 | - 'MA' => 'Massachusetts', 'MI' => 'Michigan', 'MN' => 'Minnesota', 'MS' => 'Mississippi', |
|
1245 | - 'MO' => 'Missouri', 'MT' => 'Montana', 'NE' => 'Nebraska', 'NV' => 'Nevada', |
|
1246 | - 'NH' => 'New Hampshire', 'NJ' => 'New Jersey', 'NM' => 'New Mexico', 'NY' => 'New York', |
|
1247 | - 'NC' => 'North Carolina', 'ND' => 'North Dakota', 'OH' => 'Ohio', 'OK' => 'Oklahoma', |
|
1248 | - 'OR' => 'Oregon', 'PA' => 'Pennsylvania', 'RI' => 'Rhode Island', 'SC' => 'South Carolina', |
|
1249 | - 'SD' => 'South Dakota', 'TN' => 'Tennessee', 'TX' => 'Texas', 'UT' => 'Utah', |
|
1250 | - 'VT' => 'Vermont', 'VA' => 'Virginia', 'WA' => 'Washington', 'WV' => 'West Virginia', |
|
1251 | - 'WI' => 'Wisconsin', 'WY' => 'Wyoming', |
|
1252 | - ) ); |
|
1253 | - } |
|
1254 | - |
|
1255 | - public static function get_countries() { |
|
1256 | - return apply_filters( 'frm_countries', array( |
|
1257 | - __( 'Afghanistan', 'formidable' ), __( 'Albania', 'formidable' ), __( 'Algeria', 'formidable' ), |
|
1258 | - __( 'American Samoa', 'formidable' ), __( 'Andorra', 'formidable' ), __( 'Angola', 'formidable' ), |
|
1259 | - __( 'Anguilla', 'formidable' ), __( 'Antarctica', 'formidable' ), __( 'Antigua and Barbuda', 'formidable' ), |
|
1260 | - __( 'Argentina', 'formidable' ), __( 'Armenia', 'formidable' ), __( 'Aruba', 'formidable' ), |
|
1261 | - __( 'Australia', 'formidable' ), __( 'Austria', 'formidable' ), __( 'Azerbaijan', 'formidable' ), |
|
1262 | - __( 'Bahamas', 'formidable' ), __( 'Bahrain', 'formidable' ), __( 'Bangladesh', 'formidable' ), |
|
1263 | - __( 'Barbados', 'formidable' ), __( 'Belarus', 'formidable' ), __( 'Belgium', 'formidable' ), |
|
1264 | - __( 'Belize', 'formidable' ), __( 'Benin', 'formidable' ), __( 'Bermuda', 'formidable' ), |
|
1265 | - __( 'Bhutan', 'formidable' ), __( 'Bolivia', 'formidable' ), __( 'Bosnia and Herzegovina', 'formidable' ), |
|
1266 | - __( 'Botswana', 'formidable' ), __( 'Brazil', 'formidable' ), __( 'Brunei', 'formidable' ), |
|
1267 | - __( 'Bulgaria', 'formidable' ), __( 'Burkina Faso', 'formidable' ), __( 'Burundi', 'formidable' ), |
|
1268 | - __( 'Cambodia', 'formidable' ), __( 'Cameroon', 'formidable' ), __( 'Canada', 'formidable' ), |
|
1269 | - __( 'Cape Verde', 'formidable' ), __( 'Cayman Islands', 'formidable' ), __( 'Central African Republic', 'formidable' ), |
|
1270 | - __( 'Chad', 'formidable' ), __( 'Chile', 'formidable' ), __( 'China', 'formidable' ), |
|
1271 | - __( 'Colombia', 'formidable' ), __( 'Comoros', 'formidable' ), __( 'Congo', 'formidable' ), |
|
1272 | - __( 'Costa Rica', 'formidable' ), __( 'Côte d\'Ivoire', 'formidable' ), __( 'Croatia', 'formidable' ), |
|
1273 | - __( 'Cuba', 'formidable' ), __( 'Cyprus', 'formidable' ), __( 'Czech Republic', 'formidable' ), |
|
1274 | - __( 'Denmark', 'formidable' ), __( 'Djibouti', 'formidable' ), __( 'Dominica', 'formidable' ), |
|
1275 | - __( 'Dominican Republic', 'formidable' ), __( 'East Timor', 'formidable' ), __( 'Ecuador', 'formidable' ), |
|
1276 | - __( 'Egypt', 'formidable' ), __( 'El Salvador', 'formidable' ), __( 'Equatorial Guinea', 'formidable' ), |
|
1277 | - __( 'Eritrea', 'formidable' ), __( 'Estonia', 'formidable' ), __( 'Ethiopia', 'formidable' ), |
|
1278 | - __( 'Fiji', 'formidable' ), __( 'Finland', 'formidable' ), __( 'France', 'formidable' ), |
|
1279 | - __( 'French Guiana', 'formidable' ), __( 'French Polynesia', 'formidable' ), __( 'Gabon', 'formidable' ), |
|
1280 | - __( 'Gambia', 'formidable' ), __( 'Georgia', 'formidable' ), __( 'Germany', 'formidable' ), |
|
1281 | - __( 'Ghana', 'formidable' ), __( 'Gibraltar', 'formidable' ), __( 'Greece', 'formidable' ), |
|
1282 | - __( 'Greenland', 'formidable' ), __( 'Grenada', 'formidable' ), __( 'Guam', 'formidable' ), |
|
1283 | - __( 'Guatemala', 'formidable' ), __( 'Guinea', 'formidable' ), __( 'Guinea-Bissau', 'formidable' ), |
|
1284 | - __( 'Guyana', 'formidable' ), __( 'Haiti', 'formidable' ), __( 'Honduras', 'formidable' ), |
|
1285 | - __( 'Hong Kong', 'formidable' ), __( 'Hungary', 'formidable' ), __( 'Iceland', 'formidable' ), |
|
1286 | - __( 'India', 'formidable' ), __( 'Indonesia', 'formidable' ), __( 'Iran', 'formidable' ), |
|
1287 | - __( 'Iraq', 'formidable' ), __( 'Ireland', 'formidable' ), __( 'Israel', 'formidable' ), |
|
1288 | - __( 'Italy', 'formidable' ), __( 'Jamaica', 'formidable' ), __( 'Japan', 'formidable' ), |
|
1289 | - __( 'Jordan', 'formidable' ), __( 'Kazakhstan', 'formidable' ), __( 'Kenya', 'formidable' ), |
|
1290 | - __( 'Kiribati', 'formidable' ), __( 'North Korea', 'formidable' ), __( 'South Korea', 'formidable' ), |
|
1291 | - __( 'Kuwait', 'formidable' ), __( 'Kyrgyzstan', 'formidable' ), __( 'Laos', 'formidable' ), |
|
1292 | - __( 'Latvia', 'formidable' ), __( 'Lebanon', 'formidable' ), __( 'Lesotho', 'formidable' ), |
|
1293 | - __( 'Liberia', 'formidable' ), __( 'Libya', 'formidable' ), __( 'Liechtenstein', 'formidable' ), |
|
1294 | - __( 'Lithuania', 'formidable' ), __( 'Luxembourg', 'formidable' ), __( 'Macedonia', 'formidable' ), |
|
1295 | - __( 'Madagascar', 'formidable' ), __( 'Malawi', 'formidable' ), __( 'Malaysia', 'formidable' ), |
|
1296 | - __( 'Maldives', 'formidable' ), __( 'Mali', 'formidable' ), __( 'Malta', 'formidable' ), |
|
1297 | - __( 'Marshall Islands', 'formidable' ), __( 'Mauritania', 'formidable' ), __( 'Mauritius', 'formidable' ), |
|
1298 | - __( 'Mexico', 'formidable' ), __( 'Micronesia', 'formidable' ), __( 'Moldova', 'formidable' ), |
|
1299 | - __( 'Monaco', 'formidable' ), __( 'Mongolia', 'formidable' ), __( 'Montenegro', 'formidable' ), |
|
1300 | - __( 'Montserrat', 'formidable' ), __( 'Morocco', 'formidable' ), __( 'Mozambique', 'formidable' ), |
|
1301 | - __( 'Myanmar', 'formidable' ), __( 'Namibia', 'formidable' ), __( 'Nauru', 'formidable' ), |
|
1302 | - __( 'Nepal', 'formidable' ), __( 'Netherlands', 'formidable' ), __( 'New Zealand', 'formidable' ), |
|
1303 | - __( 'Nicaragua', 'formidable' ), __( 'Niger', 'formidable' ), __( 'Nigeria', 'formidable' ), |
|
1304 | - __( 'Norway', 'formidable' ), __( 'Northern Mariana Islands', 'formidable' ), __( 'Oman', 'formidable' ), |
|
1305 | - __( 'Pakistan', 'formidable' ), __( 'Palau', 'formidable' ), __( 'Palestine', 'formidable' ), |
|
1306 | - __( 'Panama', 'formidable' ), __( 'Papua New Guinea', 'formidable' ), __( 'Paraguay', 'formidable' ), |
|
1307 | - __( 'Peru', 'formidable' ), __( 'Philippines', 'formidable' ), __( 'Poland', 'formidable' ), |
|
1308 | - __( 'Portugal', 'formidable' ), __( 'Puerto Rico', 'formidable' ), __( 'Qatar', 'formidable' ), |
|
1309 | - __( 'Romania', 'formidable' ), __( 'Russia', 'formidable' ), __( 'Rwanda', 'formidable' ), |
|
1310 | - __( 'Saint Kitts and Nevis', 'formidable' ), __( 'Saint Lucia', 'formidable' ), |
|
1311 | - __( 'Saint Vincent and the Grenadines', 'formidable' ), __( 'Samoa', 'formidable' ), |
|
1312 | - __( 'San Marino', 'formidable' ), __( 'Sao Tome and Principe', 'formidable' ), __( 'Saudi Arabia', 'formidable' ), |
|
1313 | - __( 'Senegal', 'formidable' ), __( 'Serbia and Montenegro', 'formidable' ), __( 'Seychelles', 'formidable' ), |
|
1314 | - __( 'Sierra Leone', 'formidable' ), __( 'Singapore', 'formidable' ), __( 'Slovakia', 'formidable' ), |
|
1315 | - __( 'Slovenia', 'formidable' ), __( 'Solomon Islands', 'formidable' ), __( 'Somalia', 'formidable' ), |
|
1316 | - __( 'South Africa', 'formidable' ), __( 'South Sudan', 'formidable' ), |
|
1317 | - __( 'Spain', 'formidable' ), __( 'Sri Lanka', 'formidable' ), |
|
1318 | - __( 'Sudan', 'formidable' ), __( 'Suriname', 'formidable' ), __( 'Swaziland', 'formidable' ), |
|
1319 | - __( 'Sweden', 'formidable' ), __( 'Switzerland', 'formidable' ), __( 'Syria', 'formidable' ), |
|
1320 | - __( 'Taiwan', 'formidable' ), __( 'Tajikistan', 'formidable' ), __( 'Tanzania', 'formidable' ), |
|
1321 | - __( 'Thailand', 'formidable' ), __( 'Togo', 'formidable' ), __( 'Tonga', 'formidable' ), |
|
1322 | - __( 'Trinidad and Tobago', 'formidable' ), __( 'Tunisia', 'formidable' ), __( 'Turkey', 'formidable' ), |
|
1323 | - __( 'Turkmenistan', 'formidable' ), __( 'Tuvalu', 'formidable' ), __( 'Uganda', 'formidable' ), |
|
1324 | - __( 'Ukraine', 'formidable' ), __( 'United Arab Emirates', 'formidable' ), __( 'United Kingdom', 'formidable' ), |
|
1325 | - __( 'United States', 'formidable' ), __( 'Uruguay', 'formidable' ), __( 'Uzbekistan', 'formidable' ), |
|
1326 | - __( 'Vanuatu', 'formidable' ), __( 'Vatican City', 'formidable' ), __( 'Venezuela', 'formidable' ), |
|
1327 | - __( 'Vietnam', 'formidable' ), __( 'Virgin Islands, British', 'formidable' ), |
|
1328 | - __( 'Virgin Islands, U.S.', 'formidable' ), __( 'Yemen', 'formidable' ), __( 'Zambia', 'formidable' ), |
|
1329 | - __( 'Zimbabwe', 'formidable' ), |
|
1330 | - ) ); |
|
1331 | - } |
|
1226 | + $val[ $k ] = str_replace( $replace, $replace_with, $v ); |
|
1227 | + unset($k, $v); |
|
1228 | + } |
|
1229 | + } else { |
|
1230 | + $val = str_replace($replace, $replace_with, $val); |
|
1231 | + } |
|
1232 | + |
|
1233 | + return $val; |
|
1234 | + } |
|
1235 | + |
|
1236 | + public static function get_us_states() { |
|
1237 | + return apply_filters( 'frm_us_states', array( |
|
1238 | + 'AL' => 'Alabama', 'AK' => 'Alaska', 'AR' => 'Arkansas', 'AZ' => 'Arizona', |
|
1239 | + 'CA' => 'California', 'CO' => 'Colorado', 'CT' => 'Connecticut', 'DE' => 'Delaware', |
|
1240 | + 'DC' => 'District of Columbia', |
|
1241 | + 'FL' => 'Florida', 'GA' => 'Georgia', 'HI' => 'Hawaii', 'ID' => 'Idaho', |
|
1242 | + 'IL' => 'Illinois', 'IN' => 'Indiana', 'IA' => 'Iowa', 'KS' => 'Kansas', |
|
1243 | + 'KY' => 'Kentucky', 'LA' => 'Louisiana', 'ME' => 'Maine','MD' => 'Maryland', |
|
1244 | + 'MA' => 'Massachusetts', 'MI' => 'Michigan', 'MN' => 'Minnesota', 'MS' => 'Mississippi', |
|
1245 | + 'MO' => 'Missouri', 'MT' => 'Montana', 'NE' => 'Nebraska', 'NV' => 'Nevada', |
|
1246 | + 'NH' => 'New Hampshire', 'NJ' => 'New Jersey', 'NM' => 'New Mexico', 'NY' => 'New York', |
|
1247 | + 'NC' => 'North Carolina', 'ND' => 'North Dakota', 'OH' => 'Ohio', 'OK' => 'Oklahoma', |
|
1248 | + 'OR' => 'Oregon', 'PA' => 'Pennsylvania', 'RI' => 'Rhode Island', 'SC' => 'South Carolina', |
|
1249 | + 'SD' => 'South Dakota', 'TN' => 'Tennessee', 'TX' => 'Texas', 'UT' => 'Utah', |
|
1250 | + 'VT' => 'Vermont', 'VA' => 'Virginia', 'WA' => 'Washington', 'WV' => 'West Virginia', |
|
1251 | + 'WI' => 'Wisconsin', 'WY' => 'Wyoming', |
|
1252 | + ) ); |
|
1253 | + } |
|
1254 | + |
|
1255 | + public static function get_countries() { |
|
1256 | + return apply_filters( 'frm_countries', array( |
|
1257 | + __( 'Afghanistan', 'formidable' ), __( 'Albania', 'formidable' ), __( 'Algeria', 'formidable' ), |
|
1258 | + __( 'American Samoa', 'formidable' ), __( 'Andorra', 'formidable' ), __( 'Angola', 'formidable' ), |
|
1259 | + __( 'Anguilla', 'formidable' ), __( 'Antarctica', 'formidable' ), __( 'Antigua and Barbuda', 'formidable' ), |
|
1260 | + __( 'Argentina', 'formidable' ), __( 'Armenia', 'formidable' ), __( 'Aruba', 'formidable' ), |
|
1261 | + __( 'Australia', 'formidable' ), __( 'Austria', 'formidable' ), __( 'Azerbaijan', 'formidable' ), |
|
1262 | + __( 'Bahamas', 'formidable' ), __( 'Bahrain', 'formidable' ), __( 'Bangladesh', 'formidable' ), |
|
1263 | + __( 'Barbados', 'formidable' ), __( 'Belarus', 'formidable' ), __( 'Belgium', 'formidable' ), |
|
1264 | + __( 'Belize', 'formidable' ), __( 'Benin', 'formidable' ), __( 'Bermuda', 'formidable' ), |
|
1265 | + __( 'Bhutan', 'formidable' ), __( 'Bolivia', 'formidable' ), __( 'Bosnia and Herzegovina', 'formidable' ), |
|
1266 | + __( 'Botswana', 'formidable' ), __( 'Brazil', 'formidable' ), __( 'Brunei', 'formidable' ), |
|
1267 | + __( 'Bulgaria', 'formidable' ), __( 'Burkina Faso', 'formidable' ), __( 'Burundi', 'formidable' ), |
|
1268 | + __( 'Cambodia', 'formidable' ), __( 'Cameroon', 'formidable' ), __( 'Canada', 'formidable' ), |
|
1269 | + __( 'Cape Verde', 'formidable' ), __( 'Cayman Islands', 'formidable' ), __( 'Central African Republic', 'formidable' ), |
|
1270 | + __( 'Chad', 'formidable' ), __( 'Chile', 'formidable' ), __( 'China', 'formidable' ), |
|
1271 | + __( 'Colombia', 'formidable' ), __( 'Comoros', 'formidable' ), __( 'Congo', 'formidable' ), |
|
1272 | + __( 'Costa Rica', 'formidable' ), __( 'Côte d\'Ivoire', 'formidable' ), __( 'Croatia', 'formidable' ), |
|
1273 | + __( 'Cuba', 'formidable' ), __( 'Cyprus', 'formidable' ), __( 'Czech Republic', 'formidable' ), |
|
1274 | + __( 'Denmark', 'formidable' ), __( 'Djibouti', 'formidable' ), __( 'Dominica', 'formidable' ), |
|
1275 | + __( 'Dominican Republic', 'formidable' ), __( 'East Timor', 'formidable' ), __( 'Ecuador', 'formidable' ), |
|
1276 | + __( 'Egypt', 'formidable' ), __( 'El Salvador', 'formidable' ), __( 'Equatorial Guinea', 'formidable' ), |
|
1277 | + __( 'Eritrea', 'formidable' ), __( 'Estonia', 'formidable' ), __( 'Ethiopia', 'formidable' ), |
|
1278 | + __( 'Fiji', 'formidable' ), __( 'Finland', 'formidable' ), __( 'France', 'formidable' ), |
|
1279 | + __( 'French Guiana', 'formidable' ), __( 'French Polynesia', 'formidable' ), __( 'Gabon', 'formidable' ), |
|
1280 | + __( 'Gambia', 'formidable' ), __( 'Georgia', 'formidable' ), __( 'Germany', 'formidable' ), |
|
1281 | + __( 'Ghana', 'formidable' ), __( 'Gibraltar', 'formidable' ), __( 'Greece', 'formidable' ), |
|
1282 | + __( 'Greenland', 'formidable' ), __( 'Grenada', 'formidable' ), __( 'Guam', 'formidable' ), |
|
1283 | + __( 'Guatemala', 'formidable' ), __( 'Guinea', 'formidable' ), __( 'Guinea-Bissau', 'formidable' ), |
|
1284 | + __( 'Guyana', 'formidable' ), __( 'Haiti', 'formidable' ), __( 'Honduras', 'formidable' ), |
|
1285 | + __( 'Hong Kong', 'formidable' ), __( 'Hungary', 'formidable' ), __( 'Iceland', 'formidable' ), |
|
1286 | + __( 'India', 'formidable' ), __( 'Indonesia', 'formidable' ), __( 'Iran', 'formidable' ), |
|
1287 | + __( 'Iraq', 'formidable' ), __( 'Ireland', 'formidable' ), __( 'Israel', 'formidable' ), |
|
1288 | + __( 'Italy', 'formidable' ), __( 'Jamaica', 'formidable' ), __( 'Japan', 'formidable' ), |
|
1289 | + __( 'Jordan', 'formidable' ), __( 'Kazakhstan', 'formidable' ), __( 'Kenya', 'formidable' ), |
|
1290 | + __( 'Kiribati', 'formidable' ), __( 'North Korea', 'formidable' ), __( 'South Korea', 'formidable' ), |
|
1291 | + __( 'Kuwait', 'formidable' ), __( 'Kyrgyzstan', 'formidable' ), __( 'Laos', 'formidable' ), |
|
1292 | + __( 'Latvia', 'formidable' ), __( 'Lebanon', 'formidable' ), __( 'Lesotho', 'formidable' ), |
|
1293 | + __( 'Liberia', 'formidable' ), __( 'Libya', 'formidable' ), __( 'Liechtenstein', 'formidable' ), |
|
1294 | + __( 'Lithuania', 'formidable' ), __( 'Luxembourg', 'formidable' ), __( 'Macedonia', 'formidable' ), |
|
1295 | + __( 'Madagascar', 'formidable' ), __( 'Malawi', 'formidable' ), __( 'Malaysia', 'formidable' ), |
|
1296 | + __( 'Maldives', 'formidable' ), __( 'Mali', 'formidable' ), __( 'Malta', 'formidable' ), |
|
1297 | + __( 'Marshall Islands', 'formidable' ), __( 'Mauritania', 'formidable' ), __( 'Mauritius', 'formidable' ), |
|
1298 | + __( 'Mexico', 'formidable' ), __( 'Micronesia', 'formidable' ), __( 'Moldova', 'formidable' ), |
|
1299 | + __( 'Monaco', 'formidable' ), __( 'Mongolia', 'formidable' ), __( 'Montenegro', 'formidable' ), |
|
1300 | + __( 'Montserrat', 'formidable' ), __( 'Morocco', 'formidable' ), __( 'Mozambique', 'formidable' ), |
|
1301 | + __( 'Myanmar', 'formidable' ), __( 'Namibia', 'formidable' ), __( 'Nauru', 'formidable' ), |
|
1302 | + __( 'Nepal', 'formidable' ), __( 'Netherlands', 'formidable' ), __( 'New Zealand', 'formidable' ), |
|
1303 | + __( 'Nicaragua', 'formidable' ), __( 'Niger', 'formidable' ), __( 'Nigeria', 'formidable' ), |
|
1304 | + __( 'Norway', 'formidable' ), __( 'Northern Mariana Islands', 'formidable' ), __( 'Oman', 'formidable' ), |
|
1305 | + __( 'Pakistan', 'formidable' ), __( 'Palau', 'formidable' ), __( 'Palestine', 'formidable' ), |
|
1306 | + __( 'Panama', 'formidable' ), __( 'Papua New Guinea', 'formidable' ), __( 'Paraguay', 'formidable' ), |
|
1307 | + __( 'Peru', 'formidable' ), __( 'Philippines', 'formidable' ), __( 'Poland', 'formidable' ), |
|
1308 | + __( 'Portugal', 'formidable' ), __( 'Puerto Rico', 'formidable' ), __( 'Qatar', 'formidable' ), |
|
1309 | + __( 'Romania', 'formidable' ), __( 'Russia', 'formidable' ), __( 'Rwanda', 'formidable' ), |
|
1310 | + __( 'Saint Kitts and Nevis', 'formidable' ), __( 'Saint Lucia', 'formidable' ), |
|
1311 | + __( 'Saint Vincent and the Grenadines', 'formidable' ), __( 'Samoa', 'formidable' ), |
|
1312 | + __( 'San Marino', 'formidable' ), __( 'Sao Tome and Principe', 'formidable' ), __( 'Saudi Arabia', 'formidable' ), |
|
1313 | + __( 'Senegal', 'formidable' ), __( 'Serbia and Montenegro', 'formidable' ), __( 'Seychelles', 'formidable' ), |
|
1314 | + __( 'Sierra Leone', 'formidable' ), __( 'Singapore', 'formidable' ), __( 'Slovakia', 'formidable' ), |
|
1315 | + __( 'Slovenia', 'formidable' ), __( 'Solomon Islands', 'formidable' ), __( 'Somalia', 'formidable' ), |
|
1316 | + __( 'South Africa', 'formidable' ), __( 'South Sudan', 'formidable' ), |
|
1317 | + __( 'Spain', 'formidable' ), __( 'Sri Lanka', 'formidable' ), |
|
1318 | + __( 'Sudan', 'formidable' ), __( 'Suriname', 'formidable' ), __( 'Swaziland', 'formidable' ), |
|
1319 | + __( 'Sweden', 'formidable' ), __( 'Switzerland', 'formidable' ), __( 'Syria', 'formidable' ), |
|
1320 | + __( 'Taiwan', 'formidable' ), __( 'Tajikistan', 'formidable' ), __( 'Tanzania', 'formidable' ), |
|
1321 | + __( 'Thailand', 'formidable' ), __( 'Togo', 'formidable' ), __( 'Tonga', 'formidable' ), |
|
1322 | + __( 'Trinidad and Tobago', 'formidable' ), __( 'Tunisia', 'formidable' ), __( 'Turkey', 'formidable' ), |
|
1323 | + __( 'Turkmenistan', 'formidable' ), __( 'Tuvalu', 'formidable' ), __( 'Uganda', 'formidable' ), |
|
1324 | + __( 'Ukraine', 'formidable' ), __( 'United Arab Emirates', 'formidable' ), __( 'United Kingdom', 'formidable' ), |
|
1325 | + __( 'United States', 'formidable' ), __( 'Uruguay', 'formidable' ), __( 'Uzbekistan', 'formidable' ), |
|
1326 | + __( 'Vanuatu', 'formidable' ), __( 'Vatican City', 'formidable' ), __( 'Venezuela', 'formidable' ), |
|
1327 | + __( 'Vietnam', 'formidable' ), __( 'Virgin Islands, British', 'formidable' ), |
|
1328 | + __( 'Virgin Islands, U.S.', 'formidable' ), __( 'Yemen', 'formidable' ), __( 'Zambia', 'formidable' ), |
|
1329 | + __( 'Zimbabwe', 'formidable' ), |
|
1330 | + ) ); |
|
1331 | + } |
|
1332 | 1332 | |
1333 | 1333 | public static function get_bulk_prefilled_opts( array &$prepop ) { |
1334 | 1334 | $prepop[ __( 'Countries', 'formidable' ) ] = FrmFieldsHelper::get_countries(); |
1335 | 1335 | |
1336 | - $states = FrmFieldsHelper::get_us_states(); |
|
1337 | - $state_abv = array_keys($states); |
|
1338 | - sort($state_abv); |
|
1336 | + $states = FrmFieldsHelper::get_us_states(); |
|
1337 | + $state_abv = array_keys($states); |
|
1338 | + sort($state_abv); |
|
1339 | 1339 | $prepop[ __( 'U.S. State Abbreviations', 'formidable' ) ] = $state_abv; |
1340 | 1340 | |
1341 | - $states = array_values($states); |
|
1342 | - sort($states); |
|
1341 | + $states = array_values($states); |
|
1342 | + sort($states); |
|
1343 | 1343 | $prepop[ __( 'U.S. States', 'formidable' ) ] = $states; |
1344 | - unset($state_abv, $states); |
|
1344 | + unset($state_abv, $states); |
|
1345 | 1345 | |
1346 | 1346 | $prepop[ __( 'Age', 'formidable' ) ] = array( |
1347 | - __( 'Under 18', 'formidable' ), __( '18-24', 'formidable' ), __( '25-34', 'formidable' ), |
|
1348 | - __( '35-44', 'formidable' ), __( '45-54', 'formidable' ), __( '55-64', 'formidable' ), |
|
1349 | - __( '65 or Above', 'formidable' ), __( 'Prefer Not to Answer', 'formidable' ), |
|
1350 | - ); |
|
1347 | + __( 'Under 18', 'formidable' ), __( '18-24', 'formidable' ), __( '25-34', 'formidable' ), |
|
1348 | + __( '35-44', 'formidable' ), __( '45-54', 'formidable' ), __( '55-64', 'formidable' ), |
|
1349 | + __( '65 or Above', 'formidable' ), __( 'Prefer Not to Answer', 'formidable' ), |
|
1350 | + ); |
|
1351 | 1351 | |
1352 | 1352 | $prepop[ __( 'Satisfaction', 'formidable' ) ] = array( |
1353 | - __( 'Very Satisfied', 'formidable' ), __( 'Satisfied', 'formidable' ), __( 'Neutral', 'formidable' ), |
|
1354 | - __( 'Unsatisfied', 'formidable' ), __( 'Very Unsatisfied', 'formidable' ), __( 'N/A', 'formidable' ), |
|
1355 | - ); |
|
1353 | + __( 'Very Satisfied', 'formidable' ), __( 'Satisfied', 'formidable' ), __( 'Neutral', 'formidable' ), |
|
1354 | + __( 'Unsatisfied', 'formidable' ), __( 'Very Unsatisfied', 'formidable' ), __( 'N/A', 'formidable' ), |
|
1355 | + ); |
|
1356 | 1356 | |
1357 | 1357 | $prepop[ __( 'Importance', 'formidable' ) ] = array( |
1358 | - __( 'Very Important', 'formidable' ), __( 'Important', 'formidable' ), __( 'Neutral', 'formidable' ), |
|
1359 | - __( 'Somewhat Important', 'formidable' ), __( 'Not at all Important', 'formidable' ), __( 'N/A', 'formidable' ), |
|
1360 | - ); |
|
1358 | + __( 'Very Important', 'formidable' ), __( 'Important', 'formidable' ), __( 'Neutral', 'formidable' ), |
|
1359 | + __( 'Somewhat Important', 'formidable' ), __( 'Not at all Important', 'formidable' ), __( 'N/A', 'formidable' ), |
|
1360 | + ); |
|
1361 | 1361 | |
1362 | 1362 | $prepop[ __( 'Agreement', 'formidable' ) ] = array( |
1363 | - __( 'Strongly Agree', 'formidable' ), __( 'Agree', 'formidable' ), __( 'Neutral', 'formidable' ), |
|
1364 | - __( 'Disagree', 'formidable' ), __( 'Strongly Disagree', 'formidable' ), __( 'N/A', 'formidable' ), |
|
1365 | - ); |
|
1363 | + __( 'Strongly Agree', 'formidable' ), __( 'Agree', 'formidable' ), __( 'Neutral', 'formidable' ), |
|
1364 | + __( 'Disagree', 'formidable' ), __( 'Strongly Disagree', 'formidable' ), __( 'N/A', 'formidable' ), |
|
1365 | + ); |
|
1366 | 1366 | |
1367 | 1367 | $prepop = apply_filters( 'frm_bulk_field_choices', $prepop ); |
1368 | - } |
|
1368 | + } |
|
1369 | 1369 | |
1370 | 1370 | public static function field_selection() { |
1371 | 1371 | _deprecated_function( __FUNCTION__, '2.0.9', 'FrmField::field_selection' ); |
@@ -1402,8 +1402,8 @@ discard block |
||
1402 | 1402 | return FrmField::is_required( $field ); |
1403 | 1403 | } |
1404 | 1404 | |
1405 | - public static function maybe_get_field( &$field ) { |
|
1405 | + public static function maybe_get_field( &$field ) { |
|
1406 | 1406 | _deprecated_function( __FUNCTION__, '2.0.9', 'FrmField::maybe_get_field' ); |
1407 | 1407 | FrmField::maybe_get_field( $field ); |
1408 | - } |
|
1408 | + } |
|
1409 | 1409 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined('ABSPATH') ) { |
|
2 | +if ( ! defined( 'ABSPATH' ) ) { |
|
3 | 3 | die( 'You are not allowed to call this page directly.' ); |
4 | 4 | } |
5 | 5 | |
@@ -7,12 +7,12 @@ discard block |
||
7 | 7 | |
8 | 8 | public static function setup_new_vars( $type = '', $form_id = '' ) { |
9 | 9 | |
10 | - if ( strpos($type, '|') ) { |
|
11 | - list($type, $setting) = explode('|', $type); |
|
10 | + if ( strpos( $type, '|' ) ) { |
|
11 | + list( $type, $setting ) = explode( '|', $type ); |
|
12 | 12 | } |
13 | 13 | |
14 | - $defaults = self::get_default_field_opts($type, $form_id); |
|
15 | - $defaults['field_options']['custom_html'] = self::get_default_html($type); |
|
14 | + $defaults = self::get_default_field_opts( $type, $form_id ); |
|
15 | + $defaults['field_options']['custom_html'] = self::get_default_html( $type ); |
|
16 | 16 | |
17 | 17 | $values = array(); |
18 | 18 | |
@@ -20,20 +20,20 @@ discard block |
||
20 | 20 | if ( $var == 'field_options' ) { |
21 | 21 | $values['field_options'] = array(); |
22 | 22 | foreach ( $default as $opt_var => $opt_default ) { |
23 | - $values['field_options'][ $opt_var ] = $opt_default; |
|
24 | - unset($opt_var, $opt_default); |
|
23 | + $values['field_options'][$opt_var] = $opt_default; |
|
24 | + unset( $opt_var, $opt_default ); |
|
25 | 25 | } |
26 | 26 | } else { |
27 | - $values[ $var ] = $default; |
|
27 | + $values[$var] = $default; |
|
28 | 28 | } |
29 | - unset($var, $default); |
|
29 | + unset( $var, $default ); |
|
30 | 30 | } |
31 | 31 | |
32 | 32 | if ( isset( $setting ) && ! empty( $setting ) ) { |
33 | 33 | if ( 'data' == $type ) { |
34 | 34 | $values['field_options']['data_type'] = $setting; |
35 | 35 | } else { |
36 | - $values['field_options'][ $setting ] = 1; |
|
36 | + $values['field_options'][$setting] = 1; |
|
37 | 37 | } |
38 | 38 | } |
39 | 39 | |
@@ -56,13 +56,13 @@ discard block |
||
56 | 56 | } |
57 | 57 | |
58 | 58 | $fields = FrmField::field_selection(); |
59 | - $fields = array_merge($fields, FrmField::pro_field_selection()); |
|
59 | + $fields = array_merge( $fields, FrmField::pro_field_selection() ); |
|
60 | 60 | |
61 | - if ( isset( $fields[ $type ] ) ) { |
|
62 | - $values['name'] = is_array( $fields[ $type ] ) ? $fields[ $type ]['name'] : $fields[ $type ]; |
|
61 | + if ( isset( $fields[$type] ) ) { |
|
62 | + $values['name'] = is_array( $fields[$type] ) ? $fields[$type]['name'] : $fields[$type]; |
|
63 | 63 | } |
64 | 64 | |
65 | - unset($fields); |
|
65 | + unset( $fields ); |
|
66 | 66 | |
67 | 67 | return $values; |
68 | 68 | } |
@@ -88,8 +88,8 @@ discard block |
||
88 | 88 | $values['form_name'] = ''; |
89 | 89 | } else { |
90 | 90 | foreach ( $defaults as $var => $default ) { |
91 | - $values[ $var ] = FrmAppHelper::get_param( $var, $default, 'get', 'htmlspecialchars' ); |
|
92 | - unset($var, $default); |
|
91 | + $values[$var] = FrmAppHelper::get_param( $var, $default, 'get', 'htmlspecialchars' ); |
|
92 | + unset( $var, $default ); |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | $values['form_name'] = $record->form_id ? FrmForm::getName( $record->form_id ) : ''; |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | $values['options'] = $record->options; |
101 | 101 | $values['field_options'] = $record->field_options; |
102 | 102 | |
103 | - $defaults = self::get_default_field_opts($values['type'], $record, true); |
|
103 | + $defaults = self::get_default_field_opts( $values['type'], $record, true ); |
|
104 | 104 | |
105 | 105 | if ( $values['type'] == 'captcha' ) { |
106 | 106 | $frm_settings = FrmAppHelper::get_settings(); |
@@ -108,11 +108,11 @@ discard block |
||
108 | 108 | } |
109 | 109 | |
110 | 110 | foreach ( $defaults as $opt => $default ) { |
111 | - $values[ $opt ] = isset( $record->field_options[ $opt ] ) ? $record->field_options[ $opt ] : $default; |
|
112 | - unset($opt, $default); |
|
111 | + $values[$opt] = isset( $record->field_options[$opt] ) ? $record->field_options[$opt] : $default; |
|
112 | + unset( $opt, $default ); |
|
113 | 113 | } |
114 | 114 | |
115 | - $values['custom_html'] = (isset($record->field_options['custom_html'])) ? $record->field_options['custom_html'] : self::get_default_html($record->type); |
|
115 | + $values['custom_html'] = ( isset( $record->field_options['custom_html'] ) ) ? $record->field_options['custom_html'] : self::get_default_html( $record->type ); |
|
116 | 116 | |
117 | 117 | return apply_filters( 'frm_setup_edit_field_vars', $values, array( 'doing_ajax' => $doing_ajax ) ); |
118 | 118 | } |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | |
132 | 132 | global $wpdb; |
133 | 133 | |
134 | - $form_id = (is_numeric($field)) ? $field : $field->form_id; |
|
134 | + $form_id = ( is_numeric( $field ) ) ? $field : $field->form_id; |
|
135 | 135 | |
136 | 136 | $key = is_numeric( $field ) ? FrmAppHelper::get_unique_key( '', $wpdb->prefix . 'frm_fields', 'field_key' ) : $field->field_key; |
137 | 137 | |
@@ -153,11 +153,11 @@ discard block |
||
153 | 153 | |
154 | 154 | $values['field_key'] = FrmAppHelper::get_unique_key( $new_key, $wpdb->prefix . 'frm_fields', 'field_key' ); |
155 | 155 | $values['form_id'] = $form_id; |
156 | - $values['options'] = maybe_serialize($field->options); |
|
157 | - $values['default_value'] = maybe_serialize($field->default_value); |
|
156 | + $values['options'] = maybe_serialize( $field->options ); |
|
157 | + $values['default_value'] = maybe_serialize( $field->default_value ); |
|
158 | 158 | |
159 | 159 | foreach ( array( 'name', 'description', 'type', 'field_order', 'field_options', 'required' ) as $col ) { |
160 | - $values[ $col ] = $field->{$col}; |
|
160 | + $values[$col] = $field->{$col}; |
|
161 | 161 | } |
162 | 162 | } |
163 | 163 | |
@@ -170,19 +170,19 @@ discard block |
||
170 | 170 | $field_name = is_array( $field ) ? $field['name'] : $field->name; |
171 | 171 | |
172 | 172 | $defaults = array( |
173 | - 'unique_msg' => array( 'full' => $default_settings['unique_msg'], 'part' => sprintf( __('%s must be unique', 'formidable' ), $field_name ) ), |
|
174 | - 'invalid' => array( 'full' => __( 'This field is invalid', 'formidable' ), 'part' => sprintf( __('%s is invalid', 'formidable' ), $field_name ) ), |
|
173 | + 'unique_msg' => array( 'full' => $default_settings['unique_msg'], 'part' => sprintf( __( '%s must be unique', 'formidable' ), $field_name ) ), |
|
174 | + 'invalid' => array( 'full' => __( 'This field is invalid', 'formidable' ), 'part' => sprintf( __( '%s is invalid', 'formidable' ), $field_name ) ), |
|
175 | 175 | 'blank' => array( 'full' => $frm_settings->blank_msg, 'part' => $frm_settings->blank_msg ), |
176 | 176 | ); |
177 | 177 | |
178 | 178 | $msg = FrmField::get_option( $field, $error ); |
179 | - $msg = ( $msg == $defaults[ $error ]['full'] || empty( $msg ) ) ? $defaults[ $error ]['part'] : $msg; |
|
179 | + $msg = ( $msg == $defaults[$error]['full'] || empty( $msg ) ) ? $defaults[$error]['part'] : $msg; |
|
180 | 180 | return $msg; |
181 | 181 | } |
182 | 182 | |
183 | 183 | public static function get_form_fields( $form_id, $error = false ) { |
184 | - $fields = FrmField::get_all_for_form($form_id); |
|
185 | - $fields = apply_filters('frm_get_paged_fields', $fields, $form_id, $error); |
|
184 | + $fields = FrmField::get_all_for_form( $form_id ); |
|
185 | + $fields = apply_filters( 'frm_get_paged_fields', $fields, $form_id, $error ); |
|
186 | 186 | return $fields; |
187 | 187 | } |
188 | 188 | |
@@ -205,14 +205,14 @@ discard block |
||
205 | 205 | </div> |
206 | 206 | DEFAULT_HTML; |
207 | 207 | } else { |
208 | - $default_html = apply_filters('frm_other_custom_html', '', $type); |
|
208 | + $default_html = apply_filters( 'frm_other_custom_html', '', $type ); |
|
209 | 209 | } |
210 | 210 | |
211 | - return apply_filters('frm_custom_html', $default_html, $type); |
|
211 | + return apply_filters( 'frm_custom_html', $default_html, $type ); |
|
212 | 212 | } |
213 | 213 | |
214 | 214 | public static function replace_shortcodes( $html, $field, $errors = array(), $form = false, $args = array() ) { |
215 | - $html = apply_filters('frm_before_replace_shortcodes', $html, $field, $errors, $form); |
|
215 | + $html = apply_filters( 'frm_before_replace_shortcodes', $html, $field, $errors, $form ); |
|
216 | 216 | |
217 | 217 | $defaults = array( |
218 | 218 | 'field_name' => 'item_meta[' . $field['id'] . ']', |
@@ -220,42 +220,42 @@ discard block |
||
220 | 220 | 'field_plus_id' => '', |
221 | 221 | 'section_id' => '', |
222 | 222 | ); |
223 | - $args = wp_parse_args($args, $defaults); |
|
223 | + $args = wp_parse_args( $args, $defaults ); |
|
224 | 224 | $field_name = $args['field_name']; |
225 | 225 | $field_id = $args['field_id']; |
226 | - $html_id = self::get_html_id($field, $args['field_plus_id']); |
|
226 | + $html_id = self::get_html_id( $field, $args['field_plus_id'] ); |
|
227 | 227 | |
228 | - if ( FrmField::is_multiple_select($field) ) { |
|
228 | + if ( FrmField::is_multiple_select( $field ) ) { |
|
229 | 229 | $field_name .= '[]'; |
230 | 230 | } |
231 | 231 | |
232 | 232 | //replace [id] |
233 | - $html = str_replace('[id]', $field_id, $html); |
|
233 | + $html = str_replace( '[id]', $field_id, $html ); |
|
234 | 234 | |
235 | 235 | // Remove the for attribute for captcha |
236 | 236 | if ( $field['type'] == 'captcha' ) { |
237 | - $html = str_replace(' for="field_[key]"', '', $html); |
|
237 | + $html = str_replace( ' for="field_[key]"', '', $html ); |
|
238 | 238 | } |
239 | 239 | |
240 | 240 | // set the label for |
241 | - $html = str_replace('field_[key]', $html_id, $html); |
|
241 | + $html = str_replace( 'field_[key]', $html_id, $html ); |
|
242 | 242 | |
243 | 243 | //replace [key] |
244 | - $html = str_replace('[key]', $field['field_key'], $html); |
|
244 | + $html = str_replace( '[key]', $field['field_key'], $html ); |
|
245 | 245 | |
246 | 246 | //replace [description] and [required_label] and [error] |
247 | 247 | $required = FrmField::is_required( $field ) ? $field['required_indicator'] : ''; |
248 | 248 | if ( ! is_array( $errors ) ) { |
249 | 249 | $errors = array(); |
250 | 250 | } |
251 | - $error = isset( $errors[ 'field' . $field_id ] ) ? $errors[ 'field' . $field_id ] : false; |
|
251 | + $error = isset( $errors['field' . $field_id] ) ? $errors['field' . $field_id] : false; |
|
252 | 252 | |
253 | 253 | //If field type is section heading, add class so a bottom margin can be added to either the h3 or description |
254 | 254 | if ( $field['type'] == 'divider' ) { |
255 | 255 | if ( FrmField::is_option_true( $field, 'description' ) ) { |
256 | 256 | $html = str_replace( 'frm_description', 'frm_description frm_section_spacing', $html ); |
257 | 257 | } else { |
258 | - $html = str_replace('[label_position]', '[label_position] frm_section_spacing', $html); |
|
258 | + $html = str_replace( '[label_position]', '[label_position] frm_section_spacing', $html ); |
|
259 | 259 | } |
260 | 260 | } |
261 | 261 | |
@@ -265,48 +265,48 @@ discard block |
||
265 | 265 | |
266 | 266 | //replace [required_class] |
267 | 267 | $required_class = FrmField::is_required( $field ) ? ' frm_required_field' : ''; |
268 | - $html = str_replace('[required_class]', $required_class, $html); |
|
268 | + $html = str_replace( '[required_class]', $required_class, $html ); |
|
269 | 269 | |
270 | 270 | //replace [label_position] |
271 | - $field['label'] = apply_filters('frm_html_label_position', $field['label'], $field, $form); |
|
271 | + $field['label'] = apply_filters( 'frm_html_label_position', $field['label'], $field, $form ); |
|
272 | 272 | $field['label'] = ( $field['label'] && $field['label'] != '' ) ? $field['label'] : 'top'; |
273 | 273 | $html = str_replace( '[label_position]', ( ( in_array( $field['type'], array( 'divider', 'end_divider', 'break' ) ) ) ? $field['label'] : ' frm_primary_label' ), $html ); |
274 | 274 | |
275 | 275 | //replace [field_name] |
276 | - $html = str_replace('[field_name]', $field['name'], $html); |
|
276 | + $html = str_replace( '[field_name]', $field['name'], $html ); |
|
277 | 277 | |
278 | 278 | //replace [error_class] |
279 | - $error_class = isset( $errors[ 'field' . $field_id ] ) ? ' frm_blank_field' : ''; |
|
279 | + $error_class = isset( $errors['field' . $field_id] ) ? ' frm_blank_field' : ''; |
|
280 | 280 | self::get_more_field_classes( $error_class, $field, $field_id, $html ); |
281 | 281 | if ( $field['type'] == 'html' && strpos( $html, '[error_class]' ) === false ) { |
282 | 282 | // there is no error_class shortcode to use for addign fields |
283 | 283 | $html = str_replace( 'class="frm_form_field', 'class="frm_form_field ' . $error_class, $html ); |
284 | 284 | } |
285 | - $html = str_replace('[error_class]', $error_class, $html); |
|
285 | + $html = str_replace( '[error_class]', $error_class, $html ); |
|
286 | 286 | |
287 | 287 | //replace [entry_key] |
288 | 288 | $entry_key = FrmAppHelper::simple_get( 'entry', 'sanitize_title' ); |
289 | - $html = str_replace('[entry_key]', $entry_key, $html); |
|
289 | + $html = str_replace( '[entry_key]', $entry_key, $html ); |
|
290 | 290 | |
291 | 291 | //replace [input] |
292 | - preg_match_all("/\[(input|deletelink)\b(.*?)(?:(\/))?\]/s", $html, $shortcodes, PREG_PATTERN_ORDER); |
|
292 | + preg_match_all( "/\[(input|deletelink)\b(.*?)(?:(\/))?\]/s", $html, $shortcodes, PREG_PATTERN_ORDER ); |
|
293 | 293 | global $frm_vars; |
294 | 294 | $frm_settings = FrmAppHelper::get_settings(); |
295 | 295 | |
296 | 296 | foreach ( $shortcodes[0] as $short_key => $tag ) { |
297 | - $atts = shortcode_parse_atts( $shortcodes[2][ $short_key ] ); |
|
297 | + $atts = shortcode_parse_atts( $shortcodes[2][$short_key] ); |
|
298 | 298 | $tag = self::get_shortcode_tag( $shortcodes, $short_key, array( 'conditional' => false, 'conditional_check' => false ) ); |
299 | 299 | |
300 | 300 | $replace_with = ''; |
301 | 301 | |
302 | 302 | if ( $tag == 'input' ) { |
303 | - if ( isset($atts['opt']) ) { |
|
304 | - $atts['opt']--; |
|
303 | + if ( isset( $atts['opt'] ) ) { |
|
304 | + $atts['opt'] --; |
|
305 | 305 | } |
306 | 306 | |
307 | - $field['input_class'] = isset($atts['class']) ? $atts['class'] : ''; |
|
308 | - if ( isset($atts['class']) ) { |
|
309 | - unset($atts['class']); |
|
307 | + $field['input_class'] = isset( $atts['class'] ) ? $atts['class'] : ''; |
|
308 | + if ( isset( $atts['class'] ) ) { |
|
309 | + unset( $atts['class'] ); |
|
310 | 310 | } |
311 | 311 | |
312 | 312 | $field['shortcodes'] = $atts; |
@@ -315,33 +315,33 @@ discard block |
||
315 | 315 | $replace_with = ob_get_contents(); |
316 | 316 | ob_end_clean(); |
317 | 317 | } else if ( $tag == 'deletelink' && FrmAppHelper::pro_is_installed() ) { |
318 | - $replace_with = FrmProEntriesController::entry_delete_link($atts); |
|
318 | + $replace_with = FrmProEntriesController::entry_delete_link( $atts ); |
|
319 | 319 | } |
320 | 320 | |
321 | - $html = str_replace( $shortcodes[0][ $short_key ], $replace_with, $html ); |
|
321 | + $html = str_replace( $shortcodes[0][$short_key], $replace_with, $html ); |
|
322 | 322 | } |
323 | 323 | |
324 | 324 | if ( $form ) { |
325 | 325 | $form = (array) $form; |
326 | 326 | |
327 | 327 | //replace [form_key] |
328 | - $html = str_replace('[form_key]', $form['form_key'], $html); |
|
328 | + $html = str_replace( '[form_key]', $form['form_key'], $html ); |
|
329 | 329 | |
330 | 330 | //replace [form_name] |
331 | - $html = str_replace('[form_name]', $form['name'], $html); |
|
331 | + $html = str_replace( '[form_name]', $form['name'], $html ); |
|
332 | 332 | } |
333 | 333 | $html .= "\n"; |
334 | 334 | |
335 | 335 | //Return html if conf_field to prevent loop |
336 | - if ( isset($field['conf_field']) && $field['conf_field'] == 'stop' ) { |
|
336 | + if ( isset( $field['conf_field'] ) && $field['conf_field'] == 'stop' ) { |
|
337 | 337 | return $html; |
338 | 338 | } |
339 | 339 | |
340 | 340 | //If field is in repeating section |
341 | 341 | if ( $args['section_id'] ) { |
342 | - $html = apply_filters('frm_replace_shortcodes', $html, $field, array( 'errors' => $errors, 'form' => $form, 'field_name' => $field_name, 'field_id' => $field_id, 'field_plus_id' => $args['field_plus_id'], 'section_id' => $args['section_id'] )); |
|
342 | + $html = apply_filters( 'frm_replace_shortcodes', $html, $field, array( 'errors' => $errors, 'form' => $form, 'field_name' => $field_name, 'field_id' => $field_id, 'field_plus_id' => $args['field_plus_id'], 'section_id' => $args['section_id'] ) ); |
|
343 | 343 | } else { |
344 | - $html = apply_filters('frm_replace_shortcodes', $html, $field, array( 'errors' => $errors, 'form' => $form )); |
|
344 | + $html = apply_filters( 'frm_replace_shortcodes', $html, $field, array( 'errors' => $errors, 'form' => $form ) ); |
|
345 | 345 | } |
346 | 346 | |
347 | 347 | self::remove_collapse_shortcode( $html ); |
@@ -418,7 +418,7 @@ discard block |
||
418 | 418 | |
419 | 419 | //insert custom CSS classes |
420 | 420 | if ( ! empty( $field['classes'] ) ) { |
421 | - if ( ! strpos( $html, 'frm_form_field ') ) { |
|
421 | + if ( ! strpos( $html, 'frm_form_field ' ) ) { |
|
422 | 422 | $error_class .= ' frm_form_field'; |
423 | 423 | } |
424 | 424 | $error_class .= ' ' . $field['classes']; |
@@ -452,15 +452,15 @@ discard block |
||
452 | 452 | } |
453 | 453 | |
454 | 454 | $with_tags = $args['conditional_check'] ? 3 : 2; |
455 | - if ( ! empty( $shortcodes[ $with_tags ][ $short_key ] ) ) { |
|
456 | - $tag = str_replace( '[' . $prefix, '', $shortcodes[0][ $short_key ] ); |
|
457 | - $tag = str_replace(']', '', $tag); |
|
458 | - $tags = explode(' ', $tag); |
|
459 | - if ( is_array($tags) ) { |
|
455 | + if ( ! empty( $shortcodes[$with_tags][$short_key] ) ) { |
|
456 | + $tag = str_replace( '[' . $prefix, '', $shortcodes[0][$short_key] ); |
|
457 | + $tag = str_replace( ']', '', $tag ); |
|
458 | + $tags = explode( ' ', $tag ); |
|
459 | + if ( is_array( $tags ) ) { |
|
460 | 460 | $tag = $tags[0]; |
461 | 461 | } |
462 | 462 | } else { |
463 | - $tag = $shortcodes[ $with_tags - 1 ][ $short_key ]; |
|
463 | + $tag = $shortcodes[$with_tags - 1][$short_key]; |
|
464 | 464 | } |
465 | 465 | |
466 | 466 | return $tag; |
@@ -478,16 +478,16 @@ discard block |
||
478 | 478 | |
479 | 479 | public static function display_recaptcha( $field ) { |
480 | 480 | $frm_settings = FrmAppHelper::get_settings(); |
481 | - $lang = apply_filters('frm_recaptcha_lang', $frm_settings->re_lang, $field); |
|
481 | + $lang = apply_filters( 'frm_recaptcha_lang', $frm_settings->re_lang, $field ); |
|
482 | 482 | |
483 | 483 | $api_js_url = 'https://www.google.com/recaptcha/api.js?onload=frmRecaptcha&render=explicit'; |
484 | 484 | if ( $lang != 'en' ) { |
485 | 485 | $api_js_url .= '&hl=' . $lang; |
486 | 486 | } |
487 | - $api_js_url = apply_filters('frm_recpatcha_js_url', $api_js_url); |
|
487 | + $api_js_url = apply_filters( 'frm_recpatcha_js_url', $api_js_url ); |
|
488 | 488 | |
489 | - wp_register_script('recaptcha-api', $api_js_url, '', true); |
|
490 | - wp_enqueue_script('recaptcha-api'); |
|
489 | + wp_register_script( 'recaptcha-api', $api_js_url, '', true ); |
|
490 | + wp_enqueue_script( 'recaptcha-api' ); |
|
491 | 491 | |
492 | 492 | ?> |
493 | 493 | <div id="field_<?php echo esc_attr( $field['field_key'] ) ?>" class="frm-g-recaptcha" data-sitekey="<?php echo esc_attr( $frm_settings->pubkey ) ?>" data-size="<?php echo esc_attr( $field['captcha_size'] ) ?>"></div> |
@@ -496,10 +496,10 @@ discard block |
||
496 | 496 | |
497 | 497 | public static function show_single_option( $field ) { |
498 | 498 | $field_name = $field['name']; |
499 | - $html_id = self::get_html_id($field); |
|
499 | + $html_id = self::get_html_id( $field ); |
|
500 | 500 | foreach ( $field['options'] as $opt_key => $opt ) { |
501 | - $field_val = apply_filters('frm_field_value_saved', $opt, $opt_key, $field); |
|
502 | - $opt = apply_filters('frm_field_label_seen', $opt, $opt_key, $field); |
|
501 | + $field_val = apply_filters( 'frm_field_value_saved', $opt, $opt_key, $field ); |
|
502 | + $opt = apply_filters( 'frm_field_label_seen', $opt, $opt_key, $field ); |
|
503 | 503 | |
504 | 504 | // If this is an "Other" option, get the HTML for it |
505 | 505 | if ( self::is_other_opt( $opt_key ) ) { |
@@ -514,7 +514,7 @@ discard block |
||
514 | 514 | |
515 | 515 | public static function dropdown_categories( $args ) { |
516 | 516 | $defaults = array( 'field' => false, 'name' => false, 'show_option_all' => ' ' ); |
517 | - $args = wp_parse_args($args, $defaults); |
|
517 | + $args = wp_parse_args( $args, $defaults ); |
|
518 | 518 | |
519 | 519 | if ( ! $args['field'] ) { |
520 | 520 | return; |
@@ -524,17 +524,17 @@ discard block |
||
524 | 524 | $args['name'] = 'item_meta[' . $args['field']['id'] . ']'; |
525 | 525 | } |
526 | 526 | |
527 | - $id = self::get_html_id($args['field']); |
|
527 | + $id = self::get_html_id( $args['field'] ); |
|
528 | 528 | $class = $args['field']['type']; |
529 | 529 | |
530 | - $exclude = (is_array($args['field']['exclude_cat'])) ? implode(',', $args['field']['exclude_cat']) : $args['field']['exclude_cat']; |
|
531 | - $exclude = apply_filters('frm_exclude_cats', $exclude, $args['field']); |
|
530 | + $exclude = ( is_array( $args['field']['exclude_cat'] ) ) ? implode( ',', $args['field']['exclude_cat'] ) : $args['field']['exclude_cat']; |
|
531 | + $exclude = apply_filters( 'frm_exclude_cats', $exclude, $args['field'] ); |
|
532 | 532 | |
533 | - if ( is_array($args['field']['value']) ) { |
|
534 | - if ( ! empty($exclude) ) { |
|
535 | - $args['field']['value'] = array_diff($args['field']['value'], explode(',', $exclude)); |
|
533 | + if ( is_array( $args['field']['value'] ) ) { |
|
534 | + if ( ! empty( $exclude ) ) { |
|
535 | + $args['field']['value'] = array_diff( $args['field']['value'], explode( ',', $exclude ) ); |
|
536 | 536 | } |
537 | - $selected = reset($args['field']['value']); |
|
537 | + $selected = reset( $args['field']['value'] ); |
|
538 | 538 | } else { |
539 | 539 | $selected = $args['field']['value']; |
540 | 540 | } |
@@ -545,40 +545,40 @@ discard block |
||
545 | 545 | 'hide_empty' => false, 'echo' => 0, 'orderby' => 'name', |
546 | 546 | ); |
547 | 547 | |
548 | - $tax_atts = apply_filters('frm_dropdown_cat', $tax_atts, $args['field']); |
|
548 | + $tax_atts = apply_filters( 'frm_dropdown_cat', $tax_atts, $args['field'] ); |
|
549 | 549 | |
550 | 550 | if ( FrmAppHelper::pro_is_installed() ) { |
551 | - $post_type = FrmProFormsHelper::post_type($args['field']['form_id']); |
|
552 | - $tax_atts['taxonomy'] = FrmProAppHelper::get_custom_taxonomy($post_type, $args['field']); |
|
551 | + $post_type = FrmProFormsHelper::post_type( $args['field']['form_id'] ); |
|
552 | + $tax_atts['taxonomy'] = FrmProAppHelper::get_custom_taxonomy( $post_type, $args['field'] ); |
|
553 | 553 | if ( ! $tax_atts['taxonomy'] ) { |
554 | 554 | return; |
555 | 555 | } |
556 | 556 | |
557 | 557 | // If field type is dropdown (not Dynamic), exclude children when parent is excluded |
558 | - if ( $args['field']['type'] != 'data' && is_taxonomy_hierarchical($tax_atts['taxonomy']) ) { |
|
558 | + if ( $args['field']['type'] != 'data' && is_taxonomy_hierarchical( $tax_atts['taxonomy'] ) ) { |
|
559 | 559 | $tax_atts['exclude_tree'] = $exclude; |
560 | 560 | } |
561 | 561 | } |
562 | 562 | |
563 | - $dropdown = wp_dropdown_categories($tax_atts); |
|
563 | + $dropdown = wp_dropdown_categories( $tax_atts ); |
|
564 | 564 | |
565 | - $add_html = FrmFieldsController::input_html($args['field'], false); |
|
565 | + $add_html = FrmFieldsController::input_html( $args['field'], false ); |
|
566 | 566 | |
567 | 567 | if ( FrmAppHelper::pro_is_installed() ) { |
568 | - $add_html .= FrmProFieldsController::input_html($args['field'], false); |
|
568 | + $add_html .= FrmProFieldsController::input_html( $args['field'], false ); |
|
569 | 569 | } |
570 | 570 | |
571 | 571 | $dropdown = str_replace( "<select name='" . esc_attr( $args['name'] ) . "' id='" . esc_attr( $id ) . "' class='" . esc_attr( $class ) . "'", "<select name='" . esc_attr( $args['name'] ) . "' id='" . esc_attr( $id ) . "' " . $add_html, $dropdown ); |
572 | 572 | |
573 | - if ( is_array($args['field']['value']) ) { |
|
573 | + if ( is_array( $args['field']['value'] ) ) { |
|
574 | 574 | $skip = true; |
575 | 575 | foreach ( $args['field']['value'] as $v ) { |
576 | 576 | if ( $skip ) { |
577 | 577 | $skip = false; |
578 | 578 | continue; |
579 | 579 | } |
580 | - $dropdown = str_replace(' value="' . esc_attr( $v ) . '"', ' value="' . esc_attr( $v ) . '" selected="selected"', $dropdown ); |
|
581 | - unset($v); |
|
580 | + $dropdown = str_replace( ' value="' . esc_attr( $v ) . '"', ' value="' . esc_attr( $v ) . '" selected="selected"', $dropdown ); |
|
581 | + unset( $v ); |
|
582 | 582 | } |
583 | 583 | } |
584 | 584 | |
@@ -586,7 +586,7 @@ discard block |
||
586 | 586 | } |
587 | 587 | |
588 | 588 | public static function get_term_link( $tax_id ) { |
589 | - $tax = get_taxonomy($tax_id); |
|
589 | + $tax = get_taxonomy( $tax_id ); |
|
590 | 590 | if ( ! $tax ) { |
591 | 591 | return; |
592 | 592 | } |
@@ -595,7 +595,7 @@ discard block |
||
595 | 595 | __( 'Please add options from the WordPress "%1$s" page', 'formidable' ), |
596 | 596 | '<a href="' . esc_url( admin_url( 'edit-tags.php?taxonomy=' . $tax->name ) ) . '" target="_blank">' . ( empty( $tax->labels->name ) ? __( 'Categories' ) : $tax->labels->name ) . '</a>' |
597 | 597 | ); |
598 | - unset($tax); |
|
598 | + unset( $tax ); |
|
599 | 599 | |
600 | 600 | return $link; |
601 | 601 | } |
@@ -606,8 +606,8 @@ discard block |
||
606 | 606 | $hide_opt = rtrim( $hide_opt ); |
607 | 607 | } |
608 | 608 | |
609 | - if ( is_array($observed_value) ) { |
|
610 | - return self::array_value_condition($observed_value, $cond, $hide_opt); |
|
609 | + if ( is_array( $observed_value ) ) { |
|
610 | + return self::array_value_condition( $observed_value, $cond, $hide_opt ); |
|
611 | 611 | } |
612 | 612 | |
613 | 613 | $m = false; |
@@ -620,7 +620,7 @@ discard block |
||
620 | 620 | } else if ( $cond == '<' ) { |
621 | 621 | $m = $observed_value < $hide_opt; |
622 | 622 | } else if ( $cond == 'LIKE' || $cond == 'not LIKE' ) { |
623 | - $m = stripos($observed_value, $hide_opt); |
|
623 | + $m = stripos( $observed_value, $hide_opt ); |
|
624 | 624 | if ( $cond == 'not LIKE' ) { |
625 | 625 | $m = ( $m === false ) ? true : false; |
626 | 626 | } else { |
@@ -633,23 +633,23 @@ discard block |
||
633 | 633 | public static function array_value_condition( $observed_value, $cond, $hide_opt ) { |
634 | 634 | $m = false; |
635 | 635 | if ( $cond == '==' ) { |
636 | - if ( is_array($hide_opt) ) { |
|
637 | - $m = array_intersect($hide_opt, $observed_value); |
|
638 | - $m = empty($m) ? false : true; |
|
636 | + if ( is_array( $hide_opt ) ) { |
|
637 | + $m = array_intersect( $hide_opt, $observed_value ); |
|
638 | + $m = empty( $m ) ? false : true; |
|
639 | 639 | } else { |
640 | - $m = in_array($hide_opt, $observed_value); |
|
640 | + $m = in_array( $hide_opt, $observed_value ); |
|
641 | 641 | } |
642 | 642 | } else if ( $cond == '!=' ) { |
643 | - $m = ! in_array($hide_opt, $observed_value); |
|
643 | + $m = ! in_array( $hide_opt, $observed_value ); |
|
644 | 644 | } else if ( $cond == '>' ) { |
645 | - $min = min($observed_value); |
|
645 | + $min = min( $observed_value ); |
|
646 | 646 | $m = $min > $hide_opt; |
647 | 647 | } else if ( $cond == '<' ) { |
648 | - $max = max($observed_value); |
|
648 | + $max = max( $observed_value ); |
|
649 | 649 | $m = $max < $hide_opt; |
650 | 650 | } else if ( $cond == 'LIKE' || $cond == 'not LIKE' ) { |
651 | 651 | foreach ( $observed_value as $ob ) { |
652 | - $m = strpos($ob, $hide_opt); |
|
652 | + $m = strpos( $ob, $hide_opt ); |
|
653 | 653 | if ( $m !== false ) { |
654 | 654 | $m = true; |
655 | 655 | break; |
@@ -670,27 +670,27 @@ discard block |
||
670 | 670 | * @return string |
671 | 671 | */ |
672 | 672 | public static function basic_replace_shortcodes( $value, $form, $entry ) { |
673 | - if ( strpos($value, '[sitename]') !== false ) { |
|
673 | + if ( strpos( $value, '[sitename]' ) !== false ) { |
|
674 | 674 | $new_value = wp_specialchars_decode( FrmAppHelper::site_name(), ENT_QUOTES ); |
675 | - $value = str_replace('[sitename]', $new_value, $value); |
|
675 | + $value = str_replace( '[sitename]', $new_value, $value ); |
|
676 | 676 | } |
677 | 677 | |
678 | - $value = apply_filters('frm_content', $value, $form, $entry); |
|
679 | - $value = do_shortcode($value); |
|
678 | + $value = apply_filters( 'frm_content', $value, $form, $entry ); |
|
679 | + $value = do_shortcode( $value ); |
|
680 | 680 | |
681 | 681 | return $value; |
682 | 682 | } |
683 | 683 | |
684 | 684 | public static function get_shortcodes( $content, $form_id ) { |
685 | 685 | if ( FrmAppHelper::pro_is_installed() ) { |
686 | - return FrmProDisplaysHelper::get_shortcodes($content, $form_id); |
|
686 | + return FrmProDisplaysHelper::get_shortcodes( $content, $form_id ); |
|
687 | 687 | } |
688 | 688 | |
689 | 689 | $fields = FrmField::getAll( array( 'fi.form_id' => (int) $form_id, 'fi.type not' => FrmField::no_save_fields() ) ); |
690 | 690 | |
691 | - $tagregexp = self::allowed_shortcodes($fields); |
|
691 | + $tagregexp = self::allowed_shortcodes( $fields ); |
|
692 | 692 | |
693 | - preg_match_all("/\[(if )?($tagregexp)\b(.*?)(?:(\/))?\](?:(.+?)\[\/\2\])?/s", $content, $matches, PREG_PATTERN_ORDER); |
|
693 | + preg_match_all( "/\[(if )?($tagregexp)\b(.*?)(?:(\/))?\](?:(.+?)\[\/\2\])?/s", $content, $matches, PREG_PATTERN_ORDER ); |
|
694 | 694 | |
695 | 695 | return $matches; |
696 | 696 | } |
@@ -708,7 +708,7 @@ discard block |
||
708 | 708 | $tagregexp[] = $field->field_key; |
709 | 709 | } |
710 | 710 | |
711 | - $tagregexp = implode('|', $tagregexp); |
|
711 | + $tagregexp = implode( '|', $tagregexp ); |
|
712 | 712 | return $tagregexp; |
713 | 713 | } |
714 | 714 | |
@@ -720,28 +720,28 @@ discard block |
||
720 | 720 | ); |
721 | 721 | |
722 | 722 | foreach ( $shortcodes[0] as $short_key => $tag ) { |
723 | - $atts = shortcode_parse_atts( $shortcodes[3][ $short_key ] ); |
|
723 | + $atts = shortcode_parse_atts( $shortcodes[3][$short_key] ); |
|
724 | 724 | |
725 | - if ( ! empty( $shortcodes[3][ $short_key ] ) ) { |
|
726 | - $tag = str_replace( array( '[', ']' ), '', $shortcodes[0][ $short_key ] ); |
|
727 | - $tags = explode(' ', $tag); |
|
728 | - if ( is_array($tags) ) { |
|
725 | + if ( ! empty( $shortcodes[3][$short_key] ) ) { |
|
726 | + $tag = str_replace( array( '[', ']' ), '', $shortcodes[0][$short_key] ); |
|
727 | + $tags = explode( ' ', $tag ); |
|
728 | + if ( is_array( $tags ) ) { |
|
729 | 729 | $tag = $tags[0]; |
730 | 730 | } |
731 | 731 | } else { |
732 | - $tag = $shortcodes[2][ $short_key ]; |
|
732 | + $tag = $shortcodes[2][$short_key]; |
|
733 | 733 | } |
734 | 734 | |
735 | 735 | switch ( $tag ) { |
736 | 736 | case 'id': |
737 | 737 | case 'key': |
738 | 738 | case 'ip': |
739 | - $replace_with = $shortcode_values[ $tag ]; |
|
739 | + $replace_with = $shortcode_values[$tag]; |
|
740 | 740 | break; |
741 | 741 | |
742 | 742 | case 'user_agent': |
743 | 743 | case 'user-agent': |
744 | - $entry->description = maybe_unserialize($entry->description); |
|
744 | + $entry->description = maybe_unserialize( $entry->description ); |
|
745 | 745 | $replace_with = FrmEntryFormat::get_browser( $entry->description['browser'] ); |
746 | 746 | break; |
747 | 747 | |
@@ -749,25 +749,25 @@ discard block |
||
749 | 749 | case 'created-at': |
750 | 750 | case 'updated_at': |
751 | 751 | case 'updated-at': |
752 | - if ( isset($atts['format']) ) { |
|
752 | + if ( isset( $atts['format'] ) ) { |
|
753 | 753 | $time_format = ' '; |
754 | 754 | } else { |
755 | - $atts['format'] = get_option('date_format'); |
|
755 | + $atts['format'] = get_option( 'date_format' ); |
|
756 | 756 | $time_format = ''; |
757 | 757 | } |
758 | 758 | |
759 | - $this_tag = str_replace('-', '_', $tag); |
|
760 | - $replace_with = FrmAppHelper::get_formatted_time($entry->{$this_tag}, $atts['format'], $time_format); |
|
761 | - unset($this_tag); |
|
759 | + $this_tag = str_replace( '-', '_', $tag ); |
|
760 | + $replace_with = FrmAppHelper::get_formatted_time( $entry->{$this_tag}, $atts['format'], $time_format ); |
|
761 | + unset( $this_tag ); |
|
762 | 762 | break; |
763 | 763 | |
764 | 764 | case 'created_by': |
765 | 765 | case 'created-by': |
766 | 766 | case 'updated_by': |
767 | 767 | case 'updated-by': |
768 | - $this_tag = str_replace('-', '_', $tag); |
|
768 | + $this_tag = str_replace( '-', '_', $tag ); |
|
769 | 769 | $replace_with = self::get_display_value( $entry->{$this_tag}, (object) array( 'type' => 'user_id' ), $atts ); |
770 | - unset($this_tag); |
|
770 | + unset( $this_tag ); |
|
771 | 771 | break; |
772 | 772 | |
773 | 773 | case 'admin_email': |
@@ -784,16 +784,16 @@ discard block |
||
784 | 784 | break; |
785 | 785 | } |
786 | 786 | |
787 | - $sep = isset($atts['sep']) ? $atts['sep'] : ', '; |
|
787 | + $sep = isset( $atts['sep'] ) ? $atts['sep'] : ', '; |
|
788 | 788 | |
789 | 789 | $replace_with = FrmEntryMeta::get_meta_value( $entry, $field->id ); |
790 | 790 | |
791 | 791 | $atts['entry_id'] = $entry->id; |
792 | 792 | $atts['entry_key'] = $entry->item_key; |
793 | 793 | |
794 | - if ( isset($atts['show']) && $atts['show'] == 'field_label' ) { |
|
794 | + if ( isset( $atts['show'] ) && $atts['show'] == 'field_label' ) { |
|
795 | 795 | $replace_with = $field->name; |
796 | - } else if ( isset($atts['show']) && $atts['show'] == 'description' ) { |
|
796 | + } else if ( isset( $atts['show'] ) && $atts['show'] == 'description' ) { |
|
797 | 797 | $replace_with = $field->description; |
798 | 798 | } else { |
799 | 799 | $string_value = $replace_with; |
@@ -808,15 +808,15 @@ discard block |
||
808 | 808 | } |
809 | 809 | } |
810 | 810 | |
811 | - unset($field); |
|
811 | + unset( $field ); |
|
812 | 812 | break; |
813 | 813 | } |
814 | 814 | |
815 | - if ( isset($replace_with) ) { |
|
816 | - $content = str_replace( $shortcodes[0][ $short_key ], $replace_with, $content ); |
|
815 | + if ( isset( $replace_with ) ) { |
|
816 | + $content = str_replace( $shortcodes[0][$short_key], $replace_with, $content ); |
|
817 | 817 | } |
818 | 818 | |
819 | - unset($atts, $conditional, $replace_with); |
|
819 | + unset( $atts, $conditional, $replace_with ); |
|
820 | 820 | } |
821 | 821 | |
822 | 822 | return $content; |
@@ -832,7 +832,7 @@ discard block |
||
832 | 832 | $new_value = ''; |
833 | 833 | switch ( $tag ) { |
834 | 834 | case 'admin_email': |
835 | - $new_value = get_option('admin_email'); |
|
835 | + $new_value = get_option( 'admin_email' ); |
|
836 | 836 | break; |
837 | 837 | case 'siteurl': |
838 | 838 | $new_value = FrmAppHelper::site_url(); |
@@ -858,28 +858,28 @@ discard block |
||
858 | 858 | * @return string|array |
859 | 859 | */ |
860 | 860 | public static function process_get_shortcode( $atts, $return_array = false ) { |
861 | - if ( ! isset($atts['param']) ) { |
|
861 | + if ( ! isset( $atts['param'] ) ) { |
|
862 | 862 | return ''; |
863 | 863 | } |
864 | 864 | |
865 | - if ( strpos($atts['param'], '[') ) { |
|
866 | - $atts['param'] = str_replace('[', '[', $atts['param']); |
|
867 | - $atts['param'] = str_replace(']', ']', $atts['param']); |
|
865 | + if ( strpos( $atts['param'], '[' ) ) { |
|
866 | + $atts['param'] = str_replace( '[', '[', $atts['param'] ); |
|
867 | + $atts['param'] = str_replace( ']', ']', $atts['param'] ); |
|
868 | 868 | } |
869 | 869 | |
870 | - $new_value = FrmAppHelper::get_param($atts['param'], ''); |
|
870 | + $new_value = FrmAppHelper::get_param( $atts['param'], '' ); |
|
871 | 871 | $new_value = FrmAppHelper::get_query_var( $new_value, $atts['param'] ); |
872 | 872 | |
873 | 873 | if ( $new_value == '' ) { |
874 | - if ( ! isset($atts['prev_val']) ) { |
|
874 | + if ( ! isset( $atts['prev_val'] ) ) { |
|
875 | 875 | $atts['prev_val'] = ''; |
876 | 876 | } |
877 | 877 | |
878 | - $new_value = isset($atts['default']) ? $atts['default'] : $atts['prev_val']; |
|
878 | + $new_value = isset( $atts['default'] ) ? $atts['default'] : $atts['prev_val']; |
|
879 | 879 | } |
880 | 880 | |
881 | - if ( is_array($new_value) && ! $return_array ) { |
|
882 | - $new_value = implode(', ', $new_value); |
|
881 | + if ( is_array( $new_value ) && ! $return_array ) { |
|
882 | + $new_value = implode( ', ', $new_value ); |
|
883 | 883 | } |
884 | 884 | |
885 | 885 | return $new_value; |
@@ -892,12 +892,12 @@ discard block |
||
892 | 892 | $replace_with = apply_filters( 'frm_get_display_value', $replace_with, $field, $atts ); |
893 | 893 | |
894 | 894 | if ( $field->type == 'textarea' || $field->type == 'rte' ) { |
895 | - $autop = isset($atts['wpautop']) ? $atts['wpautop'] : true; |
|
896 | - if ( apply_filters('frm_use_wpautop', $autop) ) { |
|
897 | - if ( is_array($replace_with) ) { |
|
898 | - $replace_with = implode("\n", $replace_with); |
|
895 | + $autop = isset( $atts['wpautop'] ) ? $atts['wpautop'] : true; |
|
896 | + if ( apply_filters( 'frm_use_wpautop', $autop ) ) { |
|
897 | + if ( is_array( $replace_with ) ) { |
|
898 | + $replace_with = implode( "\n", $replace_with ); |
|
899 | 899 | } |
900 | - $replace_with = wpautop($replace_with); |
|
900 | + $replace_with = wpautop( $replace_with ); |
|
901 | 901 | } |
902 | 902 | unset( $autop ); |
903 | 903 | } else if ( is_array( $replace_with ) ) { |
@@ -919,14 +919,14 @@ discard block |
||
919 | 919 | $field_selection = array_merge( FrmField::pro_field_selection(), FrmField::field_selection() ); |
920 | 920 | |
921 | 921 | $field_types = array(); |
922 | - if ( in_array($type, $single_input) ) { |
|
922 | + if ( in_array( $type, $single_input ) ) { |
|
923 | 923 | self::field_types_for_input( $single_input, $field_selection, $field_types ); |
924 | - } else if ( in_array($type, $multiple_input) ) { |
|
924 | + } else if ( in_array( $type, $multiple_input ) ) { |
|
925 | 925 | self::field_types_for_input( $multiple_input, $field_selection, $field_types ); |
926 | - } else if ( in_array($type, $other_type) ) { |
|
926 | + } else if ( in_array( $type, $other_type ) ) { |
|
927 | 927 | self::field_types_for_input( $other_type, $field_selection, $field_types ); |
928 | - } else if ( isset( $field_selection[ $type ] ) ) { |
|
929 | - $field_types[ $type ] = $field_selection[ $type ]; |
|
928 | + } else if ( isset( $field_selection[$type] ) ) { |
|
929 | + $field_types[$type] = $field_selection[$type]; |
|
930 | 930 | } |
931 | 931 | |
932 | 932 | return $field_types; |
@@ -934,8 +934,8 @@ discard block |
||
934 | 934 | |
935 | 935 | private static function field_types_for_input( $inputs, $fields, &$field_types ) { |
936 | 936 | foreach ( $inputs as $input ) { |
937 | - $field_types[ $input ] = $fields[ $input ]; |
|
938 | - unset($input); |
|
937 | + $field_types[$input] = $fields[$input]; |
|
938 | + unset( $input ); |
|
939 | 939 | } |
940 | 940 | } |
941 | 941 | |
@@ -980,21 +980,21 @@ discard block |
||
980 | 980 | // Check posted vals before checking saved values |
981 | 981 | |
982 | 982 | // For fields inside repeating sections - note, don't check if $pointer is true because it will often be zero |
983 | - if ( $parent && isset( $_POST['item_meta'][ $parent ][ $pointer ]['other'][ $field['id'] ] ) ) { |
|
983 | + if ( $parent && isset( $_POST['item_meta'][$parent][$pointer]['other'][$field['id']] ) ) { |
|
984 | 984 | if ( FrmField::is_field_with_multiple_values( $field ) ) { |
985 | - $other_val = isset( $_POST['item_meta'][ $parent ][ $pointer ]['other'][ $field['id'] ][ $opt_key ] ) ? sanitize_text_field( $_POST['item_meta'][ $parent ][ $pointer ]['other'][ $field['id'] ][ $opt_key ] ) : ''; |
|
985 | + $other_val = isset( $_POST['item_meta'][$parent][$pointer]['other'][$field['id']][$opt_key] ) ? sanitize_text_field( $_POST['item_meta'][$parent][$pointer]['other'][$field['id']][$opt_key] ) : ''; |
|
986 | 986 | } else { |
987 | - $other_val = sanitize_text_field( $_POST['item_meta'][ $parent ][ $pointer ]['other'][ $field['id'] ] ); |
|
987 | + $other_val = sanitize_text_field( $_POST['item_meta'][$parent][$pointer]['other'][$field['id']] ); |
|
988 | 988 | } |
989 | 989 | return $other_val; |
990 | 990 | |
991 | - } else if ( isset( $field['id'] ) && isset( $_POST['item_meta']['other'][ $field['id'] ] ) ) { |
|
991 | + } else if ( isset( $field['id'] ) && isset( $_POST['item_meta']['other'][$field['id']] ) ) { |
|
992 | 992 | // For normal fields |
993 | 993 | |
994 | 994 | if ( FrmField::is_field_with_multiple_values( $field ) ) { |
995 | - $other_val = isset( $_POST['item_meta']['other'][ $field['id'] ][ $opt_key ] ) ? sanitize_text_field( $_POST['item_meta']['other'][ $field['id'] ][ $opt_key ] ) : ''; |
|
995 | + $other_val = isset( $_POST['item_meta']['other'][$field['id']][$opt_key] ) ? sanitize_text_field( $_POST['item_meta']['other'][$field['id']][$opt_key] ) : ''; |
|
996 | 996 | } else { |
997 | - $other_val = sanitize_text_field( $_POST['item_meta']['other'][ $field['id'] ] ); |
|
997 | + $other_val = sanitize_text_field( $_POST['item_meta']['other'][$field['id']] ); |
|
998 | 998 | } |
999 | 999 | return $other_val; |
1000 | 1000 | } |
@@ -1003,8 +1003,8 @@ discard block |
||
1003 | 1003 | if ( $field['type'] == 'checkbox' && is_array( $field['value'] ) ) { |
1004 | 1004 | // Check if there is an "other" val in saved value and make sure the |
1005 | 1005 | // "other" val is not equal to the Other checkbox option |
1006 | - if ( isset( $field['value'][ $opt_key ] ) && $field['options'][ $opt_key ] != $field['value'][ $opt_key ] ) { |
|
1007 | - $other_val = $field['value'][ $opt_key ]; |
|
1006 | + if ( isset( $field['value'][$opt_key] ) && $field['options'][$opt_key] != $field['value'][$opt_key] ) { |
|
1007 | + $other_val = $field['value'][$opt_key]; |
|
1008 | 1008 | } |
1009 | 1009 | } else { |
1010 | 1010 | /** |
@@ -1016,8 +1016,8 @@ discard block |
||
1016 | 1016 | // Multi-select dropdowns - key is not preserved |
1017 | 1017 | if ( is_array( $field['value'] ) ) { |
1018 | 1018 | $o_key = array_search( $temp_val, $field['value'] ); |
1019 | - if ( isset( $field['value'][ $o_key ] ) ) { |
|
1020 | - unset( $field['value'][ $o_key ], $o_key ); |
|
1019 | + if ( isset( $field['value'][$o_key] ) ) { |
|
1020 | + unset( $field['value'][$o_key], $o_key ); |
|
1021 | 1021 | } |
1022 | 1022 | } else if ( $temp_val == $field['value'] ) { |
1023 | 1023 | // For radio and regular dropdowns |
@@ -1074,7 +1074,7 @@ discard block |
||
1074 | 1074 | private static function set_other_name( $args, &$other_args ) { |
1075 | 1075 | //Set up name for other field |
1076 | 1076 | $other_args['name'] = str_replace( '[]', '', $args['field_name'] ); |
1077 | - $other_args['name'] = preg_replace('/\[' . $args['field']['id'] . '\]$/', '', $other_args['name']); |
|
1077 | + $other_args['name'] = preg_replace( '/\[' . $args['field']['id'] . '\]$/', '', $other_args['name'] ); |
|
1078 | 1078 | $other_args['name'] = $other_args['name'] . '[other]' . '[' . $args['field']['id'] . ']'; |
1079 | 1079 | |
1080 | 1080 | //Converts item_meta[field_id] => item_meta[other][field_id] and |
@@ -1100,7 +1100,7 @@ discard block |
||
1100 | 1100 | // Count should only be greater than 3 if inside of a repeating section |
1101 | 1101 | if ( count( $temp_array ) > 3 ) { |
1102 | 1102 | $parent = str_replace( ']', '', $temp_array[1] ); |
1103 | - $pointer = str_replace( ']', '', $temp_array[2]); |
|
1103 | + $pointer = str_replace( ']', '', $temp_array[2] ); |
|
1104 | 1104 | } |
1105 | 1105 | |
1106 | 1106 | // Get text for "other" text field |
@@ -1219,15 +1219,15 @@ discard block |
||
1219 | 1219 | $replace_with[] = '[' . $new . ']'; |
1220 | 1220 | $replace[] = '[' . $old . ' '; |
1221 | 1221 | $replace_with[] = '[' . $new . ' '; |
1222 | - unset($old, $new); |
|
1222 | + unset( $old, $new ); |
|
1223 | 1223 | } |
1224 | 1224 | if ( is_array( $val ) ) { |
1225 | 1225 | foreach ( $val as $k => $v ) { |
1226 | - $val[ $k ] = str_replace( $replace, $replace_with, $v ); |
|
1227 | - unset($k, $v); |
|
1226 | + $val[$k] = str_replace( $replace, $replace_with, $v ); |
|
1227 | + unset( $k, $v ); |
|
1228 | 1228 | } |
1229 | 1229 | } else { |
1230 | - $val = str_replace($replace, $replace_with, $val); |
|
1230 | + $val = str_replace( $replace, $replace_with, $val ); |
|
1231 | 1231 | } |
1232 | 1232 | |
1233 | 1233 | return $val; |
@@ -1240,7 +1240,7 @@ discard block |
||
1240 | 1240 | 'DC' => 'District of Columbia', |
1241 | 1241 | 'FL' => 'Florida', 'GA' => 'Georgia', 'HI' => 'Hawaii', 'ID' => 'Idaho', |
1242 | 1242 | 'IL' => 'Illinois', 'IN' => 'Indiana', 'IA' => 'Iowa', 'KS' => 'Kansas', |
1243 | - 'KY' => 'Kentucky', 'LA' => 'Louisiana', 'ME' => 'Maine','MD' => 'Maryland', |
|
1243 | + 'KY' => 'Kentucky', 'LA' => 'Louisiana', 'ME' => 'Maine', 'MD' => 'Maryland', |
|
1244 | 1244 | 'MA' => 'Massachusetts', 'MI' => 'Michigan', 'MN' => 'Minnesota', 'MS' => 'Mississippi', |
1245 | 1245 | 'MO' => 'Missouri', 'MT' => 'Montana', 'NE' => 'Nebraska', 'NV' => 'Nevada', |
1246 | 1246 | 'NH' => 'New Hampshire', 'NJ' => 'New Jersey', 'NM' => 'New Mexico', 'NY' => 'New York', |
@@ -1331,35 +1331,35 @@ discard block |
||
1331 | 1331 | } |
1332 | 1332 | |
1333 | 1333 | public static function get_bulk_prefilled_opts( array &$prepop ) { |
1334 | - $prepop[ __( 'Countries', 'formidable' ) ] = FrmFieldsHelper::get_countries(); |
|
1334 | + $prepop[__( 'Countries', 'formidable' )] = FrmFieldsHelper::get_countries(); |
|
1335 | 1335 | |
1336 | 1336 | $states = FrmFieldsHelper::get_us_states(); |
1337 | - $state_abv = array_keys($states); |
|
1338 | - sort($state_abv); |
|
1339 | - $prepop[ __( 'U.S. State Abbreviations', 'formidable' ) ] = $state_abv; |
|
1337 | + $state_abv = array_keys( $states ); |
|
1338 | + sort( $state_abv ); |
|
1339 | + $prepop[__( 'U.S. State Abbreviations', 'formidable' )] = $state_abv; |
|
1340 | 1340 | |
1341 | - $states = array_values($states); |
|
1342 | - sort($states); |
|
1343 | - $prepop[ __( 'U.S. States', 'formidable' ) ] = $states; |
|
1344 | - unset($state_abv, $states); |
|
1341 | + $states = array_values( $states ); |
|
1342 | + sort( $states ); |
|
1343 | + $prepop[__( 'U.S. States', 'formidable' )] = $states; |
|
1344 | + unset( $state_abv, $states ); |
|
1345 | 1345 | |
1346 | - $prepop[ __( 'Age', 'formidable' ) ] = array( |
|
1346 | + $prepop[__( 'Age', 'formidable' )] = array( |
|
1347 | 1347 | __( 'Under 18', 'formidable' ), __( '18-24', 'formidable' ), __( '25-34', 'formidable' ), |
1348 | 1348 | __( '35-44', 'formidable' ), __( '45-54', 'formidable' ), __( '55-64', 'formidable' ), |
1349 | 1349 | __( '65 or Above', 'formidable' ), __( 'Prefer Not to Answer', 'formidable' ), |
1350 | 1350 | ); |
1351 | 1351 | |
1352 | - $prepop[ __( 'Satisfaction', 'formidable' ) ] = array( |
|
1352 | + $prepop[__( 'Satisfaction', 'formidable' )] = array( |
|
1353 | 1353 | __( 'Very Satisfied', 'formidable' ), __( 'Satisfied', 'formidable' ), __( 'Neutral', 'formidable' ), |
1354 | 1354 | __( 'Unsatisfied', 'formidable' ), __( 'Very Unsatisfied', 'formidable' ), __( 'N/A', 'formidable' ), |
1355 | 1355 | ); |
1356 | 1356 | |
1357 | - $prepop[ __( 'Importance', 'formidable' ) ] = array( |
|
1357 | + $prepop[__( 'Importance', 'formidable' )] = array( |
|
1358 | 1358 | __( 'Very Important', 'formidable' ), __( 'Important', 'formidable' ), __( 'Neutral', 'formidable' ), |
1359 | 1359 | __( 'Somewhat Important', 'formidable' ), __( 'Not at all Important', 'formidable' ), __( 'N/A', 'formidable' ), |
1360 | 1360 | ); |
1361 | 1361 | |
1362 | - $prepop[ __( 'Agreement', 'formidable' ) ] = array( |
|
1362 | + $prepop[__( 'Agreement', 'formidable' )] = array( |
|
1363 | 1363 | __( 'Strongly Agree', 'formidable' ), __( 'Agree', 'formidable' ), __( 'Neutral', 'formidable' ), |
1364 | 1364 | __( 'Disagree', 'formidable' ), __( 'Strongly Disagree', 'formidable' ), __( 'N/A', 'formidable' ), |
1365 | 1365 | ); |