@@ -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 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | } |
5 | 5 | |
6 | 6 | class FrmFormsListHelper extends FrmListHelper { |
7 | - var $status = ''; |
|
7 | + var $status = ''; |
|
8 | 8 | |
9 | 9 | public function __construct( $args ) { |
10 | 10 | $this->status = isset( $_REQUEST['form_type'] ) ? $_REQUEST['form_type'] : ''; |
@@ -13,14 +13,14 @@ discard block |
||
13 | 13 | } |
14 | 14 | |
15 | 15 | public function prepare_items() { |
16 | - global $wpdb, $per_page, $mode; |
|
16 | + global $wpdb, $per_page, $mode; |
|
17 | 17 | |
18 | - $mode = empty( $_REQUEST['mode'] ) ? 'list' : $_REQUEST['mode']; |
|
18 | + $mode = empty( $_REQUEST['mode'] ) ? 'list' : $_REQUEST['mode']; |
|
19 | 19 | |
20 | 20 | $default_orderby = 'name'; |
21 | 21 | $default_order = 'ASC'; |
22 | 22 | |
23 | - $orderby = ( isset( $_REQUEST['orderby'] ) ) ? $_REQUEST['orderby'] : $default_orderby; |
|
23 | + $orderby = ( isset( $_REQUEST['orderby'] ) ) ? $_REQUEST['orderby'] : $default_orderby; |
|
24 | 24 | $order = ( isset( $_REQUEST['order'] ) ) ? $_REQUEST['order'] : $default_order; |
25 | 25 | |
26 | 26 | $page = $this->get_pagenum(); |
@@ -28,40 +28,40 @@ discard block |
||
28 | 28 | |
29 | 29 | $start = ( isset( $_REQUEST['start'] ) ) ? $_REQUEST['start'] : (( $page - 1 ) * $per_page); |
30 | 30 | |
31 | - $s_query = array(); |
|
32 | - $s_query[] = array( 'or' => 1, 'parent_form_id' => null, 'parent_form_id <' => 1 ); |
|
31 | + $s_query = array(); |
|
32 | + $s_query[] = array( 'or' => 1, 'parent_form_id' => null, 'parent_form_id <' => 1 ); |
|
33 | 33 | switch ( $this->status ) { |
34 | - case 'template': |
|
35 | - $s_query['is_template'] = 1; |
|
36 | - $s_query['status !'] = 'trash'; |
|
37 | - break; |
|
38 | - case 'draft': |
|
39 | - $s_query['is_template'] = 0; |
|
40 | - $s_query['status'] = 'draft'; |
|
41 | - break; |
|
42 | - case 'trash': |
|
43 | - $s_query['status'] = 'trash'; |
|
44 | - break; |
|
45 | - default: |
|
46 | - $s_query['is_template'] = 0; |
|
47 | - $s_query['status !'] = 'trash'; |
|
48 | - break; |
|
34 | + case 'template': |
|
35 | + $s_query['is_template'] = 1; |
|
36 | + $s_query['status !'] = 'trash'; |
|
37 | + break; |
|
38 | + case 'draft': |
|
39 | + $s_query['is_template'] = 0; |
|
40 | + $s_query['status'] = 'draft'; |
|
41 | + break; |
|
42 | + case 'trash': |
|
43 | + $s_query['status'] = 'trash'; |
|
44 | + break; |
|
45 | + default: |
|
46 | + $s_query['is_template'] = 0; |
|
47 | + $s_query['status !'] = 'trash'; |
|
48 | + break; |
|
49 | 49 | } |
50 | 50 | |
51 | - $s = isset( $_REQUEST['s'] ) ? stripslashes($_REQUEST['s']) : ''; |
|
52 | - if ( $s != '' ) { |
|
53 | - preg_match_all('/".*?("|$)|((?<=[\\s",+])|^)[^\\s",+]+/', $s, $matches); |
|
54 | - $search_terms = array_map('trim', $matches[0]); |
|
55 | - foreach ( (array) $search_terms as $term ) { |
|
56 | - $s_query[] = array( |
|
57 | - 'or' => true, 'name LIKE' => $term, 'description LIKE' => $term, 'created_at LIKE' => $term, |
|
58 | - ); |
|
59 | - unset($term); |
|
60 | - } |
|
61 | - } |
|
51 | + $s = isset( $_REQUEST['s'] ) ? stripslashes($_REQUEST['s']) : ''; |
|
52 | + if ( $s != '' ) { |
|
53 | + preg_match_all('/".*?("|$)|((?<=[\\s",+])|^)[^\\s",+]+/', $s, $matches); |
|
54 | + $search_terms = array_map('trim', $matches[0]); |
|
55 | + foreach ( (array) $search_terms as $term ) { |
|
56 | + $s_query[] = array( |
|
57 | + 'or' => true, 'name LIKE' => $term, 'description LIKE' => $term, 'created_at LIKE' => $term, |
|
58 | + ); |
|
59 | + unset($term); |
|
60 | + } |
|
61 | + } |
|
62 | 62 | |
63 | 63 | $this->items = FrmForm::getAll( $s_query, $orderby . ' ' . $order, $start . ',' . $per_page ); |
64 | - $total_items = FrmDb::get_count( 'frm_forms', $s_query ); |
|
64 | + $total_items = FrmDb::get_count( 'frm_forms', $s_query ); |
|
65 | 65 | |
66 | 66 | $this->set_pagination_args( array( |
67 | 67 | 'total_items' => $total_items, |
@@ -70,69 +70,69 @@ discard block |
||
70 | 70 | } |
71 | 71 | |
72 | 72 | public function no_items() { |
73 | - if ( 'template' == $this->status ) { |
|
74 | - _e( 'No Templates Found.', 'formidable' ) ?> |
|
73 | + if ( 'template' == $this->status ) { |
|
74 | + _e( 'No Templates Found.', 'formidable' ) ?> |
|
75 | 75 | <br/><br/><?php _e( 'To add a new template:', 'formidable' ) ?> |
76 | 76 | <ol><li><?php printf( __( 'Create a new %1$sform%2$s.', 'formidable' ), '<a href="' . esc_url( admin_url( 'admin?page=formidable&frm_action=new' ) ) . '"', '</a>' ) ?></li> |
77 | 77 | <li><?php printf(__( 'After your form is created, go to Formidable -> %1$sForms%2$s.', 'formidable' ), '<a href="?page=formidable">', '</a>') ?></li> |
78 | 78 | <li><?php _e( 'Place your mouse over the name of the form you just created, and click the "Create Template" link.', 'formidable' ) ?></li> |
79 | 79 | </ol> |
80 | 80 | <?php } else { |
81 | - _e( 'No Forms Found.', 'formidable' ) ?> |
|
81 | + _e( 'No Forms Found.', 'formidable' ) ?> |
|
82 | 82 | <a href="<?php echo esc_url( admin_url( 'admin.php?page=formidable&frm_action=new' ) ) ?>"><?php _e( 'Add New', 'formidable' ); ?></a> |
83 | 83 | <?php } |
84 | 84 | } |
85 | 85 | |
86 | 86 | public function get_bulk_actions() { |
87 | - $actions = array(); |
|
87 | + $actions = array(); |
|
88 | 88 | |
89 | 89 | if ( in_array( $this->status, array( '', 'published' ) ) ) { |
90 | - $actions['bulk_create_template'] = __( 'Create Template', 'formidable' ); |
|
91 | - } |
|
92 | - |
|
93 | - if ( 'trash' == $this->status ) { |
|
94 | - if ( current_user_can('frm_edit_forms') ) { |
|
95 | - $actions['bulk_untrash'] = __( 'Restore', 'formidable' ); |
|
96 | - } |
|
97 | - |
|
98 | - if ( current_user_can('frm_delete_forms') ) { |
|
99 | - $actions['bulk_delete'] = __( 'Delete Permanently', 'formidable' ); |
|
100 | - } |
|
101 | - } else if ( EMPTY_TRASH_DAYS && current_user_can('frm_delete_forms') ) { |
|
102 | - $actions['bulk_trash'] = __( 'Move to Trash', 'formidable' ); |
|
103 | - } else if ( current_user_can('frm_delete_forms') ) { |
|
104 | - $actions['bulk_delete'] = __( 'Delete'); |
|
105 | - } |
|
106 | - |
|
107 | - return $actions; |
|
108 | - } |
|
90 | + $actions['bulk_create_template'] = __( 'Create Template', 'formidable' ); |
|
91 | + } |
|
92 | + |
|
93 | + if ( 'trash' == $this->status ) { |
|
94 | + if ( current_user_can('frm_edit_forms') ) { |
|
95 | + $actions['bulk_untrash'] = __( 'Restore', 'formidable' ); |
|
96 | + } |
|
97 | + |
|
98 | + if ( current_user_can('frm_delete_forms') ) { |
|
99 | + $actions['bulk_delete'] = __( 'Delete Permanently', 'formidable' ); |
|
100 | + } |
|
101 | + } else if ( EMPTY_TRASH_DAYS && current_user_can('frm_delete_forms') ) { |
|
102 | + $actions['bulk_trash'] = __( 'Move to Trash', 'formidable' ); |
|
103 | + } else if ( current_user_can('frm_delete_forms') ) { |
|
104 | + $actions['bulk_delete'] = __( 'Delete'); |
|
105 | + } |
|
106 | + |
|
107 | + return $actions; |
|
108 | + } |
|
109 | 109 | |
110 | 110 | public function extra_tablenav( $which ) { |
111 | - if ( 'top' != $which ) { |
|
112 | - return; |
|
113 | - } |
|
111 | + if ( 'top' != $which ) { |
|
112 | + return; |
|
113 | + } |
|
114 | 114 | |
115 | - if ( 'trash' == $this->status && current_user_can('frm_delete_forms') ) { |
|
115 | + if ( 'trash' == $this->status && current_user_can('frm_delete_forms') ) { |
|
116 | 116 | ?> |
117 | 117 | <div class="alignleft actions frm_visible_overflow"> |
118 | 118 | <?php submit_button( __( 'Empty Trash' ), 'apply', 'delete_all', false ); ?> |
119 | 119 | </div> |
120 | 120 | <?php |
121 | - return; |
|
122 | - } |
|
121 | + return; |
|
122 | + } |
|
123 | 123 | |
124 | - if ( 'template' != $this->status ) { |
|
125 | - return; |
|
126 | - } |
|
124 | + if ( 'template' != $this->status ) { |
|
125 | + return; |
|
126 | + } |
|
127 | 127 | |
128 | 128 | $where = apply_filters( 'frm_forms_dropdown', array(), '' ); |
129 | 129 | $forms = FrmForm::get_published_forms( $where ); |
130 | 130 | |
131 | - $base = admin_url('admin.php?page=formidable&form_type=template'); |
|
132 | - $args = array( |
|
133 | - 'frm_action' => 'duplicate', |
|
134 | - 'template' => true, |
|
135 | - ); |
|
131 | + $base = admin_url('admin.php?page=formidable&form_type=template'); |
|
132 | + $args = array( |
|
133 | + 'frm_action' => 'duplicate', |
|
134 | + 'template' => true, |
|
135 | + ); |
|
136 | 136 | |
137 | 137 | ?> |
138 | 138 | <div class="alignleft actions frm_visible_overflow"> |
@@ -140,18 +140,18 @@ discard block |
||
140 | 140 | <a href="#" id="frm-templateDrop" class="frm-dropdown-toggle button" data-toggle="dropdown"><?php _e( 'Create New Template', 'formidable' ) ?> <b class="caret"></b></a> |
141 | 141 | <ul class="frm-dropdown-menu" role="menu" aria-labelledby="frm-templateDrop"> |
142 | 142 | <?php |
143 | - if ( empty( $forms ) ) { ?> |
|
143 | + if ( empty( $forms ) ) { ?> |
|
144 | 144 | <li class="frm_dropdown_li"><?php _e( 'You have not created any forms yet. <br/>You must create a form before you can make a template.', 'formidable' ) ?></li> |
145 | 145 | <?php |
146 | - } else { |
|
147 | - foreach ( $forms as $form ) { |
|
148 | - $args['id'] = $form->id; ?> |
|
146 | + } else { |
|
147 | + foreach ( $forms as $form ) { |
|
148 | + $args['id'] = $form->id; ?> |
|
149 | 149 | <li><a href="<?php echo esc_url( add_query_arg( $args, $base ) ); ?>" tabindex="-1"><?php echo esc_html( empty( $form->name ) ? __( '(no title)' ) : FrmAppHelper::truncate( $form->name, 33 ) ); ?></a></li> |
150 | 150 | <?php |
151 | - unset($form); |
|
151 | + unset($form); |
|
152 | 152 | } |
153 | - } |
|
154 | - ?> |
|
153 | + } |
|
154 | + ?> |
|
155 | 155 | </ul> |
156 | 156 | </div> |
157 | 157 | </div> |
@@ -161,30 +161,30 @@ discard block |
||
161 | 161 | public function get_views() { |
162 | 162 | |
163 | 163 | $statuses = array( |
164 | - 'published' => __( 'My Forms', 'formidable' ), |
|
165 | - 'template' => __( 'Templates', 'formidable' ), |
|
166 | - 'draft' => __( 'Drafts', 'formidable' ), |
|
167 | - 'trash' => __( 'Trash', 'formidable' ), |
|
164 | + 'published' => __( 'My Forms', 'formidable' ), |
|
165 | + 'template' => __( 'Templates', 'formidable' ), |
|
166 | + 'draft' => __( 'Drafts', 'formidable' ), |
|
167 | + 'trash' => __( 'Trash', 'formidable' ), |
|
168 | 168 | ); |
169 | 169 | |
170 | - $links = array(); |
|
171 | - $counts = FrmForm::get_count(); |
|
172 | - $form_type = isset( $_REQUEST['form_type'] ) ? sanitize_text_field( $_REQUEST['form_type'] ) : 'published'; |
|
170 | + $links = array(); |
|
171 | + $counts = FrmForm::get_count(); |
|
172 | + $form_type = isset( $_REQUEST['form_type'] ) ? sanitize_text_field( $_REQUEST['form_type'] ) : 'published'; |
|
173 | 173 | |
174 | - foreach ( $statuses as $status => $name ) { |
|
174 | + foreach ( $statuses as $status => $name ) { |
|
175 | 175 | |
176 | - if ( $status == $form_type ) { |
|
177 | - $class = ' class="current"'; |
|
178 | - } else { |
|
179 | - $class = ''; |
|
180 | - } |
|
176 | + if ( $status == $form_type ) { |
|
177 | + $class = ' class="current"'; |
|
178 | + } else { |
|
179 | + $class = ''; |
|
180 | + } |
|
181 | 181 | |
182 | - if ( $counts->{$status} || 'published' == $status ) { |
|
182 | + if ( $counts->{$status} || 'published' == $status ) { |
|
183 | 183 | $links[ $status ] = '<a href="' . esc_url( '?page=formidable&form_type=' . $status ) . '" ' . $class . '>' . sprintf( __( '%1$s <span class="count">(%2$s)</span>', 'formidable' ), $name, number_format_i18n( $counts->{$status} ) ) . '</a>'; |
184 | - } |
|
184 | + } |
|
185 | 185 | |
186 | - unset($status, $name); |
|
187 | - } |
|
186 | + unset($status, $name); |
|
187 | + } |
|
188 | 188 | |
189 | 189 | return $links; |
190 | 190 | } |
@@ -200,16 +200,16 @@ discard block |
||
200 | 200 | } |
201 | 201 | |
202 | 202 | public function single_row( $item, $style = '' ) { |
203 | - global $frm_vars, $mode; |
|
203 | + global $frm_vars, $mode; |
|
204 | 204 | |
205 | 205 | // Set up the hover actions for this user |
206 | 206 | $actions = array(); |
207 | 207 | $edit_link = '?page=formidable&frm_action=edit&id=' . $item->id; |
208 | 208 | $duplicate_link = '?page=formidable&frm_action=duplicate&id=' . $item->id; |
209 | 209 | |
210 | - $this->get_actions($actions, $item, $edit_link, $duplicate_link); |
|
210 | + $this->get_actions($actions, $item, $edit_link, $duplicate_link); |
|
211 | 211 | |
212 | - $action_links = $this->row_actions( $actions ); |
|
212 | + $action_links = $this->row_actions( $actions ); |
|
213 | 213 | |
214 | 214 | // Set up the checkbox ( because the user is editable, otherwise its empty ) |
215 | 215 | $checkbox = '<input type="checkbox" name="item-action[]" id="cb-item-action-' . absint( $item->id ) . '" value="' . esc_attr( $item->id ) . '" />'; |
@@ -218,9 +218,9 @@ discard block |
||
218 | 218 | |
219 | 219 | list( $columns, $hidden ) = $this->get_column_info(); |
220 | 220 | |
221 | - $format = 'Y/m/d'; |
|
222 | - if ( 'list' != $mode ) { |
|
223 | - $format .= ' \<\b\r \/\> g:i:s a'; |
|
221 | + $format = 'Y/m/d'; |
|
222 | + if ( 'list' != $mode ) { |
|
223 | + $format .= ' \<\b\r \/\> g:i:s a'; |
|
224 | 224 | } |
225 | 225 | |
226 | 226 | foreach ( $columns as $column_name => $column_display_name ) { |
@@ -228,7 +228,7 @@ discard block |
||
228 | 228 | |
229 | 229 | $style = ''; |
230 | 230 | if ( in_array( $column_name, $hidden ) ) { |
231 | - $class .= ' frm_hidden'; |
|
231 | + $class .= ' frm_hidden'; |
|
232 | 232 | } |
233 | 233 | |
234 | 234 | $class = 'class="' . esc_attr( $class ) . '"'; |
@@ -241,41 +241,41 @@ discard block |
||
241 | 241 | break; |
242 | 242 | case 'id': |
243 | 243 | case 'form_key': |
244 | - $val = $item->{$column_name}; |
|
245 | - break; |
|
244 | + $val = $item->{$column_name}; |
|
245 | + break; |
|
246 | 246 | case 'name': |
247 | - $val = $this->get_form_name( $item, $actions, $edit_link, $mode ); |
|
248 | - $val .= $action_links; |
|
247 | + $val = $this->get_form_name( $item, $actions, $edit_link, $mode ); |
|
248 | + $val .= $action_links; |
|
249 | 249 | |
250 | - break; |
|
250 | + break; |
|
251 | 251 | case 'created_at': |
252 | - $date = date($format, strtotime($item->created_at)); |
|
252 | + $date = date($format, strtotime($item->created_at)); |
|
253 | 253 | $val = '<abbr title="' . esc_attr( date( 'Y/m/d g:i:s A', strtotime( $item->created_at ) ) ) . '">' . $date . '</abbr>'; |
254 | 254 | break; |
255 | 255 | case 'shortcode': |
256 | 256 | $val = '<input type="text" readonly="readonly" class="frm_select_box" value="' . esc_attr( '[formidable id=' . $item->id . ']' ) . '" /><br/>'; |
257 | - if ( 'excerpt' == $mode ) { |
|
257 | + if ( 'excerpt' == $mode ) { |
|
258 | 258 | $val .= '<input type="text" readonly="readonly" class="frm_select_box" value="' . esc_attr( '[formidable key=' . $item->form_key . ']' ) . '" />'; |
259 | - } |
|
260 | - break; |
|
261 | - case 'entries': |
|
259 | + } |
|
260 | + break; |
|
261 | + case 'entries': |
|
262 | 262 | if ( isset( $item->options['no_save'] ) && $item->options['no_save'] ) { |
263 | 263 | $val = '<i class="frm_icon_font frm_forbid_icon frm_bstooltip" title="' . esc_attr('Entries are not being saved', 'formidable' ) . '"></i>'; |
264 | - } else { |
|
265 | - $text = FrmEntry::getRecordCount($item->id); |
|
264 | + } else { |
|
265 | + $text = FrmEntry::getRecordCount($item->id); |
|
266 | 266 | $val = current_user_can('frm_view_entries') ? '<a href="' . esc_url( admin_url( 'admin.php?page=formidable-entries&form=' . $item->id ) ) . '">' . $text . '</a>' : $text; |
267 | - unset($text); |
|
268 | - } |
|
269 | - break; |
|
270 | - case 'type': |
|
271 | - $val = ( $item->is_template && $item->default_template ) ? __( 'Default', 'formidable' ) : __( 'Custom', 'formidable' ); |
|
272 | - break; |
|
267 | + unset($text); |
|
268 | + } |
|
269 | + break; |
|
270 | + case 'type': |
|
271 | + $val = ( $item->is_template && $item->default_template ) ? __( 'Default', 'formidable' ) : __( 'Custom', 'formidable' ); |
|
272 | + break; |
|
273 | 273 | } |
274 | 274 | |
275 | 275 | if ( isset($val) ) { |
276 | - $r .= "<td $attributes>"; |
|
277 | - $r .= $val; |
|
278 | - $r .= '</td>'; |
|
276 | + $r .= "<td $attributes>"; |
|
277 | + $r .= $val; |
|
278 | + $r .= '</td>'; |
|
279 | 279 | } |
280 | 280 | unset($val); |
281 | 281 | } |
@@ -284,38 +284,38 @@ discard block |
||
284 | 284 | return $r; |
285 | 285 | } |
286 | 286 | |
287 | - /** |
|
288 | - * @param string $edit_link |
|
289 | - * @param string $duplicate_link |
|
290 | - */ |
|
291 | - private function get_actions( &$actions, $item, $edit_link, $duplicate_link ) { |
|
287 | + /** |
|
288 | + * @param string $edit_link |
|
289 | + * @param string $duplicate_link |
|
290 | + */ |
|
291 | + private function get_actions( &$actions, $item, $edit_link, $duplicate_link ) { |
|
292 | 292 | if ( 'trash' == $this->status ) { |
293 | 293 | if ( current_user_can('frm_edit_forms') ) { |
294 | 294 | $actions['restore'] = FrmFormsHelper::delete_trash_link( $item->id, $item->status, 'short' ); |
295 | 295 | } |
296 | 296 | |
297 | - if ( current_user_can('frm_delete_forms') ) { |
|
297 | + if ( current_user_can('frm_delete_forms') ) { |
|
298 | 298 | $trash_url = wp_nonce_url( '?page=formidable&form_status=trash&frm_action=destroy&id=' . $item->id, 'destroy_form_' . $item->id ); |
299 | 299 | $actions['trash'] = '<a href="' . esc_url( $trash_url ) .'" class="submitdelete" onclick="return confirm(\'' . __( 'Are you sure you want to permanently delete that?', 'formidable' ) . '\')">' . __( 'Delete Permanently' ) . '</a>'; |
300 | - } |
|
301 | - return; |
|
300 | + } |
|
301 | + return; |
|
302 | 302 | } |
303 | 303 | |
304 | 304 | if ( current_user_can('frm_edit_forms') ) { |
305 | - if ( ! $item->is_template || ! $item->default_template ) { |
|
305 | + if ( ! $item->is_template || ! $item->default_template ) { |
|
306 | 306 | $actions['frm_edit'] = '<a href="' . esc_url( $edit_link ) . '">' . __( 'Edit' ) . '</a>'; |
307 | - } |
|
307 | + } |
|
308 | 308 | |
309 | - if ( $item->is_template ) { |
|
309 | + if ( $item->is_template ) { |
|
310 | 310 | $actions['frm_duplicate'] = '<a href="'. esc_url( wp_nonce_url( $duplicate_link ) ) . '">' . __( 'Create Form from Template', 'formidable' ) . '</a>'; |
311 | - } else { |
|
311 | + } else { |
|
312 | 312 | $actions['frm_settings'] = '<a href="' . esc_url( '?page=formidable&frm_action=settings&id=' . $item->id ) . '">' . __( 'Settings', 'formidable' ) . '</a>'; |
313 | 313 | |
314 | - if ( FrmAppHelper::pro_is_installed() ) { |
|
314 | + if ( FrmAppHelper::pro_is_installed() ) { |
|
315 | 315 | $actions['duplicate'] = '<a href="' . esc_url( wp_nonce_url( $duplicate_link ) ) . '">' . __( 'Duplicate', 'formidable' ) . '</a>'; |
316 | - } |
|
317 | - } |
|
318 | - } |
|
316 | + } |
|
317 | + } |
|
318 | + } |
|
319 | 319 | |
320 | 320 | $actions['trash'] = FrmFormsHelper::delete_trash_link( $item->id, $item->status, 'short' ); |
321 | 321 | if ( empty( $actions['trash'] ) ) { |
@@ -324,52 +324,52 @@ discard block |
||
324 | 324 | } |
325 | 325 | |
326 | 326 | $actions['view'] = '<a href="' . esc_url( FrmFormsHelper::get_direct_link( $item->form_key, $item ) ) . '" target="_blank">' . __( 'Preview') . '</a>'; |
327 | - } |
|
327 | + } |
|
328 | 328 | |
329 | - /** |
|
330 | - * @param string $edit_link |
|
331 | - */ |
|
329 | + /** |
|
330 | + * @param string $edit_link |
|
331 | + */ |
|
332 | 332 | private function get_form_name( $item, $actions, $edit_link, $mode = 'list' ) { |
333 | - $form_name = $item->name; |
|
334 | - if ( trim($form_name) == '' ) { |
|
335 | - $form_name = __( '(no title)'); |
|
336 | - } |
|
333 | + $form_name = $item->name; |
|
334 | + if ( trim($form_name) == '' ) { |
|
335 | + $form_name = __( '(no title)'); |
|
336 | + } |
|
337 | 337 | $form_name = FrmAppHelper::kses( $form_name ); |
338 | 338 | if ( 'excerpt' != $mode ) { |
339 | 339 | $form_name = FrmAppHelper::truncate( $form_name, 50 ); |
340 | 340 | } |
341 | 341 | |
342 | - $val = '<strong>'; |
|
343 | - if ( 'trash' == $this->status ) { |
|
344 | - $val .= $form_name; |
|
345 | - } else { |
|
342 | + $val = '<strong>'; |
|
343 | + if ( 'trash' == $this->status ) { |
|
344 | + $val .= $form_name; |
|
345 | + } else { |
|
346 | 346 | $val .= '<a href="' . esc_url( isset( $actions['frm_edit'] ) ? $edit_link : FrmFormsHelper::get_direct_link( $item->form_key, $item ) ) . '" class="row-title">' . FrmAppHelper::kses( $form_name ) . '</a> '; |
347 | - } |
|
347 | + } |
|
348 | 348 | |
349 | - $this->add_draft_label( $item, $val ); |
|
350 | - $val .= '</strong>'; |
|
349 | + $this->add_draft_label( $item, $val ); |
|
350 | + $val .= '</strong>'; |
|
351 | 351 | |
352 | - $this->add_form_description( $item, $val ); |
|
352 | + $this->add_form_description( $item, $val ); |
|
353 | 353 | |
354 | - return $val; |
|
355 | - } |
|
354 | + return $val; |
|
355 | + } |
|
356 | 356 | |
357 | - /** |
|
358 | - * @param string $val |
|
359 | - */ |
|
360 | - private function add_draft_label( $item, &$val ) { |
|
361 | - if ( 'draft' == $item->status && 'draft' != $this->status ) { |
|
357 | + /** |
|
358 | + * @param string $val |
|
359 | + */ |
|
360 | + private function add_draft_label( $item, &$val ) { |
|
361 | + if ( 'draft' == $item->status && 'draft' != $this->status ) { |
|
362 | 362 | $val .= ' - <span class="post-state">' . __( 'Draft', 'formidable' ) . '</span>'; |
363 | - } |
|
364 | - } |
|
365 | - |
|
366 | - /** |
|
367 | - * @param string $val |
|
368 | - */ |
|
369 | - private function add_form_description( $item, &$val ) { |
|
370 | - global $mode; |
|
371 | - if ( 'excerpt' == $mode ) { |
|
372 | - $val .= FrmAppHelper::truncate(strip_tags($item->description), 50); |
|
373 | - } |
|
374 | - } |
|
363 | + } |
|
364 | + } |
|
365 | + |
|
366 | + /** |
|
367 | + * @param string $val |
|
368 | + */ |
|
369 | + private function add_form_description( $item, &$val ) { |
|
370 | + global $mode; |
|
371 | + if ( 'excerpt' == $mode ) { |
|
372 | + $val .= FrmAppHelper::truncate(strip_tags($item->description), 50); |
|
373 | + } |
|
374 | + } |
|
375 | 375 | } |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | $page = $this->get_pagenum(); |
27 | 27 | $per_page = $this->get_items_per_page( 'formidable_page_formidable_per_page' ); |
28 | 28 | |
29 | - $start = ( isset( $_REQUEST['start'] ) ) ? $_REQUEST['start'] : (( $page - 1 ) * $per_page); |
|
29 | + $start = ( isset( $_REQUEST['start'] ) ) ? $_REQUEST['start'] : ( ( $page - 1 ) * $per_page ); |
|
30 | 30 | |
31 | 31 | $s_query = array(); |
32 | 32 | $s_query[] = array( 'or' => 1, 'parent_form_id' => null, 'parent_form_id <' => 1 ); |
@@ -48,15 +48,15 @@ discard block |
||
48 | 48 | break; |
49 | 49 | } |
50 | 50 | |
51 | - $s = isset( $_REQUEST['s'] ) ? stripslashes($_REQUEST['s']) : ''; |
|
51 | + $s = isset( $_REQUEST['s'] ) ? stripslashes( $_REQUEST['s'] ) : ''; |
|
52 | 52 | if ( $s != '' ) { |
53 | - preg_match_all('/".*?("|$)|((?<=[\\s",+])|^)[^\\s",+]+/', $s, $matches); |
|
54 | - $search_terms = array_map('trim', $matches[0]); |
|
53 | + preg_match_all( '/".*?("|$)|((?<=[\\s",+])|^)[^\\s",+]+/', $s, $matches ); |
|
54 | + $search_terms = array_map( 'trim', $matches[0] ); |
|
55 | 55 | foreach ( (array) $search_terms as $term ) { |
56 | 56 | $s_query[] = array( |
57 | 57 | 'or' => true, 'name LIKE' => $term, 'description LIKE' => $term, 'created_at LIKE' => $term, |
58 | 58 | ); |
59 | - unset($term); |
|
59 | + unset( $term ); |
|
60 | 60 | } |
61 | 61 | } |
62 | 62 | |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | _e( 'No Templates Found.', 'formidable' ) ?> |
75 | 75 | <br/><br/><?php _e( 'To add a new template:', 'formidable' ) ?> |
76 | 76 | <ol><li><?php printf( __( 'Create a new %1$sform%2$s.', 'formidable' ), '<a href="' . esc_url( admin_url( 'admin?page=formidable&frm_action=new' ) ) . '"', '</a>' ) ?></li> |
77 | - <li><?php printf(__( 'After your form is created, go to Formidable -> %1$sForms%2$s.', 'formidable' ), '<a href="?page=formidable">', '</a>') ?></li> |
|
77 | + <li><?php printf( __( 'After your form is created, go to Formidable -> %1$sForms%2$s.', 'formidable' ), '<a href="?page=formidable">', '</a>' ) ?></li> |
|
78 | 78 | <li><?php _e( 'Place your mouse over the name of the form you just created, and click the "Create Template" link.', 'formidable' ) ?></li> |
79 | 79 | </ol> |
80 | 80 | <?php } else { |
@@ -91,17 +91,17 @@ discard block |
||
91 | 91 | } |
92 | 92 | |
93 | 93 | if ( 'trash' == $this->status ) { |
94 | - if ( current_user_can('frm_edit_forms') ) { |
|
94 | + if ( current_user_can( 'frm_edit_forms' ) ) { |
|
95 | 95 | $actions['bulk_untrash'] = __( 'Restore', 'formidable' ); |
96 | 96 | } |
97 | 97 | |
98 | - if ( current_user_can('frm_delete_forms') ) { |
|
98 | + if ( current_user_can( 'frm_delete_forms' ) ) { |
|
99 | 99 | $actions['bulk_delete'] = __( 'Delete Permanently', 'formidable' ); |
100 | 100 | } |
101 | - } else if ( EMPTY_TRASH_DAYS && current_user_can('frm_delete_forms') ) { |
|
101 | + } else if ( EMPTY_TRASH_DAYS && current_user_can( 'frm_delete_forms' ) ) { |
|
102 | 102 | $actions['bulk_trash'] = __( 'Move to Trash', 'formidable' ); |
103 | - } else if ( current_user_can('frm_delete_forms') ) { |
|
104 | - $actions['bulk_delete'] = __( 'Delete'); |
|
103 | + } else if ( current_user_can( 'frm_delete_forms' ) ) { |
|
104 | + $actions['bulk_delete'] = __( 'Delete' ); |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | return $actions; |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | return; |
113 | 113 | } |
114 | 114 | |
115 | - if ( 'trash' == $this->status && current_user_can('frm_delete_forms') ) { |
|
115 | + if ( 'trash' == $this->status && current_user_can( 'frm_delete_forms' ) ) { |
|
116 | 116 | ?> |
117 | 117 | <div class="alignleft actions frm_visible_overflow"> |
118 | 118 | <?php submit_button( __( 'Empty Trash' ), 'apply', 'delete_all', false ); ?> |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | $where = apply_filters( 'frm_forms_dropdown', array(), '' ); |
129 | 129 | $forms = FrmForm::get_published_forms( $where ); |
130 | 130 | |
131 | - $base = admin_url('admin.php?page=formidable&form_type=template'); |
|
131 | + $base = admin_url( 'admin.php?page=formidable&form_type=template' ); |
|
132 | 132 | $args = array( |
133 | 133 | 'frm_action' => 'duplicate', |
134 | 134 | 'template' => true, |
@@ -148,7 +148,7 @@ discard block |
||
148 | 148 | $args['id'] = $form->id; ?> |
149 | 149 | <li><a href="<?php echo esc_url( add_query_arg( $args, $base ) ); ?>" tabindex="-1"><?php echo esc_html( empty( $form->name ) ? __( '(no title)' ) : FrmAppHelper::truncate( $form->name, 33 ) ); ?></a></li> |
150 | 150 | <?php |
151 | - unset($form); |
|
151 | + unset( $form ); |
|
152 | 152 | } |
153 | 153 | } |
154 | 154 | ?> |
@@ -180,10 +180,10 @@ discard block |
||
180 | 180 | } |
181 | 181 | |
182 | 182 | if ( $counts->{$status} || 'published' == $status ) { |
183 | - $links[ $status ] = '<a href="' . esc_url( '?page=formidable&form_type=' . $status ) . '" ' . $class . '>' . sprintf( __( '%1$s <span class="count">(%2$s)</span>', 'formidable' ), $name, number_format_i18n( $counts->{$status} ) ) . '</a>'; |
|
183 | + $links[$status] = '<a href="' . esc_url( '?page=formidable&form_type=' . $status ) . '" ' . $class . '>' . sprintf( __( '%1$s <span class="count">(%2$s)</span>', 'formidable' ), $name, number_format_i18n( $counts->{$status} ) ) . '</a>'; |
|
184 | 184 | } |
185 | 185 | |
186 | - unset($status, $name); |
|
186 | + unset( $status, $name ); |
|
187 | 187 | } |
188 | 188 | |
189 | 189 | return $links; |
@@ -207,7 +207,7 @@ discard block |
||
207 | 207 | $edit_link = '?page=formidable&frm_action=edit&id=' . $item->id; |
208 | 208 | $duplicate_link = '?page=formidable&frm_action=duplicate&id=' . $item->id; |
209 | 209 | |
210 | - $this->get_actions($actions, $item, $edit_link, $duplicate_link); |
|
210 | + $this->get_actions( $actions, $item, $edit_link, $duplicate_link ); |
|
211 | 211 | |
212 | 212 | $action_links = $this->row_actions( $actions ); |
213 | 213 | |
@@ -249,7 +249,7 @@ discard block |
||
249 | 249 | |
250 | 250 | break; |
251 | 251 | case 'created_at': |
252 | - $date = date($format, strtotime($item->created_at)); |
|
252 | + $date = date( $format, strtotime( $item->created_at ) ); |
|
253 | 253 | $val = '<abbr title="' . esc_attr( date( 'Y/m/d g:i:s A', strtotime( $item->created_at ) ) ) . '">' . $date . '</abbr>'; |
254 | 254 | break; |
255 | 255 | case 'shortcode': |
@@ -260,11 +260,11 @@ discard block |
||
260 | 260 | break; |
261 | 261 | case 'entries': |
262 | 262 | if ( isset( $item->options['no_save'] ) && $item->options['no_save'] ) { |
263 | - $val = '<i class="frm_icon_font frm_forbid_icon frm_bstooltip" title="' . esc_attr('Entries are not being saved', 'formidable' ) . '"></i>'; |
|
263 | + $val = '<i class="frm_icon_font frm_forbid_icon frm_bstooltip" title="' . esc_attr( 'Entries are not being saved', 'formidable' ) . '"></i>'; |
|
264 | 264 | } else { |
265 | - $text = FrmEntry::getRecordCount($item->id); |
|
266 | - $val = current_user_can('frm_view_entries') ? '<a href="' . esc_url( admin_url( 'admin.php?page=formidable-entries&form=' . $item->id ) ) . '">' . $text . '</a>' : $text; |
|
267 | - unset($text); |
|
265 | + $text = FrmEntry::getRecordCount( $item->id ); |
|
266 | + $val = current_user_can( 'frm_view_entries' ) ? '<a href="' . esc_url( admin_url( 'admin.php?page=formidable-entries&form=' . $item->id ) ) . '">' . $text . '</a>' : $text; |
|
267 | + unset( $text ); |
|
268 | 268 | } |
269 | 269 | break; |
270 | 270 | case 'type': |
@@ -272,12 +272,12 @@ discard block |
||
272 | 272 | break; |
273 | 273 | } |
274 | 274 | |
275 | - if ( isset($val) ) { |
|
275 | + if ( isset( $val ) ) { |
|
276 | 276 | $r .= "<td $attributes>"; |
277 | 277 | $r .= $val; |
278 | 278 | $r .= '</td>'; |
279 | 279 | } |
280 | - unset($val); |
|
280 | + unset( $val ); |
|
281 | 281 | } |
282 | 282 | $r .= '</tr>'; |
283 | 283 | |
@@ -290,18 +290,18 @@ discard block |
||
290 | 290 | */ |
291 | 291 | private function get_actions( &$actions, $item, $edit_link, $duplicate_link ) { |
292 | 292 | if ( 'trash' == $this->status ) { |
293 | - if ( current_user_can('frm_edit_forms') ) { |
|
293 | + if ( current_user_can( 'frm_edit_forms' ) ) { |
|
294 | 294 | $actions['restore'] = FrmFormsHelper::delete_trash_link( $item->id, $item->status, 'short' ); |
295 | 295 | } |
296 | 296 | |
297 | - if ( current_user_can('frm_delete_forms') ) { |
|
297 | + if ( current_user_can( 'frm_delete_forms' ) ) { |
|
298 | 298 | $trash_url = wp_nonce_url( '?page=formidable&form_status=trash&frm_action=destroy&id=' . $item->id, 'destroy_form_' . $item->id ); |
299 | 299 | $actions['trash'] = '<a href="' . esc_url( $trash_url ) . '" class="submitdelete" onclick="return confirm(\'' . __( 'Are you sure you want to permanently delete that?', 'formidable' ) . '\')">' . __( 'Delete Permanently' ) . '</a>'; |
300 | 300 | } |
301 | 301 | return; |
302 | 302 | } |
303 | 303 | |
304 | - if ( current_user_can('frm_edit_forms') ) { |
|
304 | + if ( current_user_can( 'frm_edit_forms' ) ) { |
|
305 | 305 | if ( ! $item->is_template || ! $item->default_template ) { |
306 | 306 | $actions['frm_edit'] = '<a href="' . esc_url( $edit_link ) . '">' . __( 'Edit' ) . '</a>'; |
307 | 307 | } |
@@ -323,7 +323,7 @@ discard block |
||
323 | 323 | unset( $actions['trash'] ); |
324 | 324 | } |
325 | 325 | |
326 | - $actions['view'] = '<a href="' . esc_url( FrmFormsHelper::get_direct_link( $item->form_key, $item ) ) . '" target="_blank">' . __( 'Preview') . '</a>'; |
|
326 | + $actions['view'] = '<a href="' . esc_url( FrmFormsHelper::get_direct_link( $item->form_key, $item ) ) . '" target="_blank">' . __( 'Preview' ) . '</a>'; |
|
327 | 327 | } |
328 | 328 | |
329 | 329 | /** |
@@ -331,8 +331,8 @@ discard block |
||
331 | 331 | */ |
332 | 332 | private function get_form_name( $item, $actions, $edit_link, $mode = 'list' ) { |
333 | 333 | $form_name = $item->name; |
334 | - if ( trim($form_name) == '' ) { |
|
335 | - $form_name = __( '(no title)'); |
|
334 | + if ( trim( $form_name ) == '' ) { |
|
335 | + $form_name = __( '(no title)' ); |
|
336 | 336 | } |
337 | 337 | $form_name = FrmAppHelper::kses( $form_name ); |
338 | 338 | if ( 'excerpt' != $mode ) { |
@@ -369,7 +369,7 @@ discard block |
||
369 | 369 | private function add_form_description( $item, &$val ) { |
370 | 370 | global $mode; |
371 | 371 | if ( 'excerpt' == $mode ) { |
372 | - $val .= FrmAppHelper::truncate(strip_tags($item->description), 50); |
|
372 | + $val .= FrmAppHelper::truncate( strip_tags( $item->description ), 50 ); |
|
373 | 373 | } |
374 | 374 | } |
375 | 375 | } |