@@ -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() { |
@@ -51,39 +51,39 @@ discard block |
||
| 51 | 51 | )); |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | - public static function create( $values, $return = true ) { |
|
| 55 | - global $wpdb, $frm_duplicate_ids; |
|
| 54 | + public static function create( $values, $return = true ) { |
|
| 55 | + global $wpdb, $frm_duplicate_ids; |
|
| 56 | 56 | |
| 57 | - $new_values = array(); |
|
| 58 | - $key = isset($values['field_key']) ? $values['field_key'] : $values['name']; |
|
| 57 | + $new_values = array(); |
|
| 58 | + $key = isset($values['field_key']) ? $values['field_key'] : $values['name']; |
|
| 59 | 59 | $new_values['field_key'] = FrmAppHelper::get_unique_key( $key, $wpdb->prefix . 'frm_fields', 'field_key' ); |
| 60 | 60 | |
| 61 | 61 | foreach ( array( 'name', 'description', 'type', 'default_value' ) as $col ) { |
| 62 | 62 | $new_values[ $col ] = $values[ $col ]; |
| 63 | - } |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - $new_values['options'] = $values['options']; |
|
| 65 | + $new_values['options'] = $values['options']; |
|
| 66 | 66 | |
| 67 | - $new_values['field_order'] = isset($values['field_order']) ? (int) $values['field_order'] : null; |
|
| 68 | - $new_values['required'] = isset($values['required']) ? (int) $values['required'] : 0; |
|
| 69 | - $new_values['form_id'] = isset($values['form_id']) ? (int) $values['form_id'] : null; |
|
| 70 | - $new_values['field_options'] = $values['field_options']; |
|
| 71 | - $new_values['created_at'] = current_time('mysql', 1); |
|
| 67 | + $new_values['field_order'] = isset($values['field_order']) ? (int) $values['field_order'] : null; |
|
| 68 | + $new_values['required'] = isset($values['required']) ? (int) $values['required'] : 0; |
|
| 69 | + $new_values['form_id'] = isset($values['form_id']) ? (int) $values['form_id'] : null; |
|
| 70 | + $new_values['field_options'] = $values['field_options']; |
|
| 71 | + $new_values['created_at'] = current_time('mysql', 1); |
|
| 72 | 72 | |
| 73 | 73 | if ( isset( $values['id'] ) ) { |
| 74 | 74 | $frm_duplicate_ids[ $values['field_key'] ] = $new_values['field_key']; |
| 75 | - $new_values = apply_filters('frm_duplicated_field', $new_values); |
|
| 76 | - } |
|
| 75 | + $new_values = apply_filters('frm_duplicated_field', $new_values); |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | 78 | foreach ( $new_values as $k => $v ) { |
| 79 | - if ( is_array( $v ) ) { |
|
| 79 | + if ( is_array( $v ) ) { |
|
| 80 | 80 | $new_values[ $k ] = serialize( $v ); |
| 81 | 81 | } |
| 82 | - unset( $k, $v ); |
|
| 83 | - } |
|
| 82 | + unset( $k, $v ); |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | - //if(isset($values['id']) and is_numeric($values['id'])) |
|
| 86 | - // $new_values['id'] = $values['id']; |
|
| 85 | + //if(isset($values['id']) and is_numeric($values['id'])) |
|
| 86 | + // $new_values['id'] = $values['id']; |
|
| 87 | 87 | |
| 88 | 88 | $query_results = $wpdb->insert( $wpdb->prefix . 'frm_fields', $new_values ); |
| 89 | 89 | $new_id = 0; |
@@ -104,22 +104,22 @@ discard block |
||
| 104 | 104 | } else { |
| 105 | 105 | return false; |
| 106 | 106 | } |
| 107 | - } |
|
| 107 | + } |
|
| 108 | 108 | |
| 109 | - public static function duplicate( $old_form_id, $form_id, $copy_keys = false, $blog_id = false ) { |
|
| 110 | - global $frm_duplicate_ids; |
|
| 109 | + public static function duplicate( $old_form_id, $form_id, $copy_keys = false, $blog_id = false ) { |
|
| 110 | + global $frm_duplicate_ids; |
|
| 111 | 111 | |
| 112 | 112 | $where = array( array( 'or' => 1, 'fi.form_id' => $old_form_id, 'fr.parent_form_id' => $old_form_id ) ); |
| 113 | 113 | $fields = self::getAll( $where, 'field_order', '', $blog_id ); |
| 114 | 114 | |
| 115 | - foreach ( (array) $fields as $field ) { |
|
| 116 | - $new_key = ($copy_keys) ? $field->field_key : ''; |
|
| 117 | - if ( $copy_keys && substr($field->field_key, -1) == 2 ) { |
|
| 118 | - $new_key = rtrim($new_key, 2); |
|
| 119 | - } |
|
| 115 | + foreach ( (array) $fields as $field ) { |
|
| 116 | + $new_key = ($copy_keys) ? $field->field_key : ''; |
|
| 117 | + if ( $copy_keys && substr($field->field_key, -1) == 2 ) { |
|
| 118 | + $new_key = rtrim($new_key, 2); |
|
| 119 | + } |
|
| 120 | 120 | |
| 121 | - $values = array(); |
|
| 122 | - FrmFieldsHelper::fill_field( $values, $field, $form_id, $new_key ); |
|
| 121 | + $values = array(); |
|
| 122 | + FrmFieldsHelper::fill_field( $values, $field, $form_id, $new_key ); |
|
| 123 | 123 | |
| 124 | 124 | // If this is a repeating section, create new form |
| 125 | 125 | if ( self::is_repeating_field( $field ) ) { |
@@ -138,16 +138,16 @@ discard block |
||
| 138 | 138 | $values['form_id'] = $new_repeat_form_id; |
| 139 | 139 | } |
| 140 | 140 | |
| 141 | - $values = apply_filters('frm_duplicated_field', $values); |
|
| 142 | - $new_id = self::create($values); |
|
| 143 | - $frm_duplicate_ids[ $field->id ] = $new_id; |
|
| 144 | - $frm_duplicate_ids[ $field->field_key ] = $new_id; |
|
| 145 | - unset($field); |
|
| 146 | - } |
|
| 147 | - } |
|
| 141 | + $values = apply_filters('frm_duplicated_field', $values); |
|
| 142 | + $new_id = self::create($values); |
|
| 143 | + $frm_duplicate_ids[ $field->id ] = $new_id; |
|
| 144 | + $frm_duplicate_ids[ $field->field_key ] = $new_id; |
|
| 145 | + unset($field); |
|
| 146 | + } |
|
| 147 | + } |
|
| 148 | 148 | |
| 149 | 149 | public static function update( $id, $values ) { |
| 150 | - global $wpdb; |
|
| 150 | + global $wpdb; |
|
| 151 | 151 | |
| 152 | 152 | $id = absint( $id ); |
| 153 | 153 | |
@@ -155,9 +155,9 @@ discard block |
||
| 155 | 155 | $values['field_key'] = FrmAppHelper::get_unique_key( $values['field_key'], $wpdb->prefix . 'frm_fields', 'field_key', $id ); |
| 156 | 156 | } |
| 157 | 157 | |
| 158 | - if ( isset($values['required']) ) { |
|
| 159 | - $values['required'] = (int) $values['required']; |
|
| 160 | - } |
|
| 158 | + if ( isset($values['required']) ) { |
|
| 159 | + $values['required'] = (int) $values['required']; |
|
| 160 | + } |
|
| 161 | 161 | |
| 162 | 162 | self::preserve_format_option_backslashes( $values ); |
| 163 | 163 | |
@@ -174,41 +174,41 @@ discard block |
||
| 174 | 174 | |
| 175 | 175 | $query_results = $wpdb->update( $wpdb->prefix . 'frm_fields', $values, array( 'id' => $id ) ); |
| 176 | 176 | |
| 177 | - $form_id = 0; |
|
| 177 | + $form_id = 0; |
|
| 178 | 178 | if ( isset( $values['form_id'] ) ) { |
| 179 | - $form_id = absint( $values['form_id'] ); |
|
| 179 | + $form_id = absint( $values['form_id'] ); |
|
| 180 | 180 | } else { |
| 181 | - $field = self::getOne($id); |
|
| 182 | - if ( $field ) { |
|
| 183 | - $form_id = $field->form_id; |
|
| 184 | - } |
|
| 185 | - unset($field); |
|
| 186 | - } |
|
| 187 | - unset($values); |
|
| 181 | + $field = self::getOne($id); |
|
| 182 | + if ( $field ) { |
|
| 183 | + $form_id = $field->form_id; |
|
| 184 | + } |
|
| 185 | + unset($field); |
|
| 186 | + } |
|
| 187 | + unset($values); |
|
| 188 | 188 | |
| 189 | 189 | if ( $query_results ) { |
| 190 | - wp_cache_delete( $id, 'frm_field' ); |
|
| 191 | - if ( $form_id ) { |
|
| 192 | - self::delete_form_transient( $form_id ); |
|
| 193 | - } |
|
| 194 | - } |
|
| 190 | + wp_cache_delete( $id, 'frm_field' ); |
|
| 191 | + if ( $form_id ) { |
|
| 192 | + self::delete_form_transient( $form_id ); |
|
| 193 | + } |
|
| 194 | + } |
|
| 195 | 195 | |
| 196 | - return $query_results; |
|
| 197 | - } |
|
| 196 | + return $query_results; |
|
| 197 | + } |
|
| 198 | 198 | |
| 199 | 199 | /** |
| 200 | - * Keep backslashes in the phone format option |
|
| 201 | - * |
|
| 202 | - * @since 2.0.8 |
|
| 203 | - * @param $values array - pass by reference |
|
| 204 | - */ |
|
| 200 | + * Keep backslashes in the phone format option |
|
| 201 | + * |
|
| 202 | + * @since 2.0.8 |
|
| 203 | + * @param $values array - pass by reference |
|
| 204 | + */ |
|
| 205 | 205 | private static function preserve_format_option_backslashes( &$values ) { |
| 206 | 206 | if ( isset( $values['field_options']['format'] ) ) { |
| 207 | 207 | $values['field_options']['format'] = FrmAppHelper::preserve_backslashes( $values['field_options']['format'] ); |
| 208 | 208 | } |
| 209 | 209 | } |
| 210 | 210 | |
| 211 | - public static function destroy( $id ) { |
|
| 211 | + public static function destroy( $id ) { |
|
| 212 | 212 | global $wpdb; |
| 213 | 213 | |
| 214 | 214 | do_action( 'frm_before_destroy_field', $id ); |
@@ -223,7 +223,7 @@ discard block |
||
| 223 | 223 | |
| 224 | 224 | $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_item_metas WHERE field_id=%d', $id ) ); |
| 225 | 225 | return $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_fields WHERE id=%d', $id ) ); |
| 226 | - } |
|
| 226 | + } |
|
| 227 | 227 | |
| 228 | 228 | public static function delete_form_transient( $form_id ) { |
| 229 | 229 | $form_id = absint( $form_id ); |
@@ -236,17 +236,17 @@ discard block |
||
| 236 | 236 | $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%' ) ); |
| 237 | 237 | |
| 238 | 238 | $cache_key = serialize( array( 'fi.form_id' => $form_id ) ) . 'field_orderlb'; |
| 239 | - wp_cache_delete($cache_key, 'frm_field'); |
|
| 239 | + wp_cache_delete($cache_key, 'frm_field'); |
|
| 240 | 240 | |
| 241 | 241 | // this cache key is autogenerated in FrmDb::get_var |
| 242 | 242 | 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' ); |
| 243 | 243 | wp_cache_delete( '1_' . $form_id . '_' . $form_id . '_ORDER_BY_field_orderfi.*__fr.name_as_form_name_results', 'frm_field' ); |
| 244 | 244 | |
| 245 | - $form = FrmForm::getOne($form_id); |
|
| 246 | - if ( $form && $form->parent_form_id ) { |
|
| 247 | - self::delete_form_transient( $form->parent_form_id ); |
|
| 248 | - } |
|
| 249 | - } |
|
| 245 | + $form = FrmForm::getOne($form_id); |
|
| 246 | + if ( $form && $form->parent_form_id ) { |
|
| 247 | + self::delete_form_transient( $form->parent_form_id ); |
|
| 248 | + } |
|
| 249 | + } |
|
| 250 | 250 | |
| 251 | 251 | /** |
| 252 | 252 | * If $field is numeric, get the field object |
@@ -262,131 +262,131 @@ discard block |
||
| 262 | 262 | return; |
| 263 | 263 | } |
| 264 | 264 | |
| 265 | - global $wpdb; |
|
| 265 | + global $wpdb; |
|
| 266 | 266 | |
| 267 | - $where = is_numeric($id) ? 'id=%d' : 'field_key=%s'; |
|
| 267 | + $where = is_numeric($id) ? 'id=%d' : 'field_key=%s'; |
|
| 268 | 268 | $query = $wpdb->prepare( 'SELECT * FROM ' . $wpdb->prefix . 'frm_fields WHERE ' . $where, $id ); |
| 269 | 269 | |
| 270 | - $results = FrmAppHelper::check_cache( $id, 'frm_field', $query, 'get_row', 0 ); |
|
| 270 | + $results = FrmAppHelper::check_cache( $id, 'frm_field', $query, 'get_row', 0 ); |
|
| 271 | 271 | |
| 272 | - if ( empty($results) ) { |
|
| 273 | - return $results; |
|
| 274 | - } |
|
| 272 | + if ( empty($results) ) { |
|
| 273 | + return $results; |
|
| 274 | + } |
|
| 275 | 275 | |
| 276 | - if ( is_numeric($id) ) { |
|
| 277 | - wp_cache_set( $results->field_key, $results, 'frm_field' ); |
|
| 278 | - } else if ( $results ) { |
|
| 279 | - wp_cache_set( $results->id, $results, 'frm_field' ); |
|
| 280 | - } |
|
| 276 | + if ( is_numeric($id) ) { |
|
| 277 | + wp_cache_set( $results->field_key, $results, 'frm_field' ); |
|
| 278 | + } else if ( $results ) { |
|
| 279 | + wp_cache_set( $results->id, $results, 'frm_field' ); |
|
| 280 | + } |
|
| 281 | 281 | |
| 282 | 282 | self::prepare_options( $results ); |
| 283 | 283 | |
| 284 | - return stripslashes_deep($results); |
|
| 285 | - } |
|
| 284 | + return stripslashes_deep($results); |
|
| 285 | + } |
|
| 286 | 286 | |
| 287 | - /** |
|
| 288 | - * Get the field type by key or id |
|
| 289 | - * @param int|string The field id or key |
|
| 287 | + /** |
|
| 288 | + * Get the field type by key or id |
|
| 289 | + * @param int|string The field id or key |
|
| 290 | 290 | * @param mixed $col The name of the column in the fields database table |
| 291 | - */ |
|
| 292 | - public static function &get_type( $id, $col = 'type' ) { |
|
| 293 | - $field = FrmAppHelper::check_cache( $id, 'frm_field' ); |
|
| 294 | - if ( $field ) { |
|
| 295 | - $type = $field->{$col}; |
|
| 296 | - } else { |
|
| 297 | - $type = FrmDb::get_var( 'frm_fields', array( 'or' => 1, 'id' => $id, 'field_key' => $id ), $col ); |
|
| 298 | - } |
|
| 299 | - |
|
| 300 | - return $type; |
|
| 301 | - } |
|
| 291 | + */ |
|
| 292 | + public static function &get_type( $id, $col = 'type' ) { |
|
| 293 | + $field = FrmAppHelper::check_cache( $id, 'frm_field' ); |
|
| 294 | + if ( $field ) { |
|
| 295 | + $type = $field->{$col}; |
|
| 296 | + } else { |
|
| 297 | + $type = FrmDb::get_var( 'frm_fields', array( 'or' => 1, 'id' => $id, 'field_key' => $id ), $col ); |
|
| 298 | + } |
|
| 299 | + |
|
| 300 | + return $type; |
|
| 301 | + } |
|
| 302 | 302 | |
| 303 | 303 | public static function get_all_types_in_form( $form_id, $type, $limit = '', $inc_sub = 'exclude' ) { |
| 304 | - if ( ! $form_id ) { |
|
| 305 | - return array(); |
|
| 306 | - } |
|
| 304 | + if ( ! $form_id ) { |
|
| 305 | + return array(); |
|
| 306 | + } |
|
| 307 | 307 | |
| 308 | 308 | $results = self::get_fields_from_transients( $form_id, array( 'inc_embed' => $inc_sub, 'inc_repeat' => $inc_sub ) ); |
| 309 | 309 | if ( ! empty( $results ) ) { |
| 310 | - $fields = array(); |
|
| 311 | - $count = 0; |
|
| 312 | - foreach ( $results as $result ) { |
|
| 313 | - if ( $type != $result->type ) { |
|
| 314 | - continue; |
|
| 315 | - } |
|
| 310 | + $fields = array(); |
|
| 311 | + $count = 0; |
|
| 312 | + foreach ( $results as $result ) { |
|
| 313 | + if ( $type != $result->type ) { |
|
| 314 | + continue; |
|
| 315 | + } |
|
| 316 | 316 | |
| 317 | 317 | $fields[ $result->id ] = $result; |
| 318 | - $count++; |
|
| 319 | - if ( $limit == 1 ) { |
|
| 320 | - $fields = $result; |
|
| 321 | - break; |
|
| 322 | - } |
|
| 318 | + $count++; |
|
| 319 | + if ( $limit == 1 ) { |
|
| 320 | + $fields = $result; |
|
| 321 | + break; |
|
| 322 | + } |
|
| 323 | 323 | |
| 324 | - if ( ! empty($limit) && $count >= $limit ) { |
|
| 325 | - break; |
|
| 326 | - } |
|
| 324 | + if ( ! empty($limit) && $count >= $limit ) { |
|
| 325 | + break; |
|
| 326 | + } |
|
| 327 | 327 | |
| 328 | - unset($result); |
|
| 329 | - } |
|
| 330 | - return stripslashes_deep($fields); |
|
| 331 | - } |
|
| 328 | + unset($result); |
|
| 329 | + } |
|
| 330 | + return stripslashes_deep($fields); |
|
| 331 | + } |
|
| 332 | 332 | |
| 333 | - self::$use_cache = false; |
|
| 333 | + self::$use_cache = false; |
|
| 334 | 334 | |
| 335 | 335 | $where = array( 'fi.form_id' => (int) $form_id, 'fi.type' => $type ); |
| 336 | 336 | self::maybe_include_repeating_fields( $inc_sub, $where ); |
| 337 | 337 | $results = self::getAll( $where, 'field_order', $limit ); |
| 338 | - self::$use_cache = true; |
|
| 339 | - self::include_sub_fields($results, $inc_sub, $type); |
|
| 338 | + self::$use_cache = true; |
|
| 339 | + self::include_sub_fields($results, $inc_sub, $type); |
|
| 340 | 340 | |
| 341 | - return $results; |
|
| 342 | - } |
|
| 341 | + return $results; |
|
| 342 | + } |
|
| 343 | 343 | |
| 344 | 344 | public static function get_all_for_form( $form_id, $limit = '', $inc_embed = 'exclude', $inc_repeat = 'include' ) { |
| 345 | - if ( ! (int) $form_id ) { |
|
| 346 | - return array(); |
|
| 347 | - } |
|
| 345 | + if ( ! (int) $form_id ) { |
|
| 346 | + return array(); |
|
| 347 | + } |
|
| 348 | 348 | |
| 349 | 349 | $results = self::get_fields_from_transients( $form_id, array( 'inc_embed' => $inc_embed, 'inc_repeat' => $inc_repeat ) ); |
| 350 | 350 | if ( ! empty( $results ) ) { |
| 351 | - if ( empty($limit) ) { |
|
| 351 | + if ( empty($limit) ) { |
|
| 352 | 352 | return $results; |
| 353 | - } |
|
| 353 | + } |
|
| 354 | 354 | |
| 355 | - $fields = array(); |
|
| 356 | - $count = 0; |
|
| 357 | - foreach ( $results as $result ) { |
|
| 355 | + $fields = array(); |
|
| 356 | + $count = 0; |
|
| 357 | + foreach ( $results as $result ) { |
|
| 358 | 358 | $fields[ $result->id ] = $result; |
| 359 | - if ( ! empty($limit) && $count >= $limit ) { |
|
| 360 | - break; |
|
| 361 | - } |
|
| 362 | - } |
|
| 359 | + if ( ! empty($limit) && $count >= $limit ) { |
|
| 360 | + break; |
|
| 361 | + } |
|
| 362 | + } |
|
| 363 | 363 | |
| 364 | 364 | return $fields; |
| 365 | - } |
|
| 365 | + } |
|
| 366 | 366 | |
| 367 | - self::$use_cache = false; |
|
| 367 | + self::$use_cache = false; |
|
| 368 | 368 | |
| 369 | 369 | $where = array( 'fi.form_id' => absint( $form_id ) ); |
| 370 | 370 | self::maybe_include_repeating_fields( $inc_repeat, $where ); |
| 371 | 371 | $results = self::getAll( $where, 'field_order', $limit ); |
| 372 | 372 | |
| 373 | - self::$use_cache = true; |
|
| 373 | + self::$use_cache = true; |
|
| 374 | 374 | |
| 375 | 375 | self::include_sub_fields( $results, $inc_embed, 'all' ); |
| 376 | 376 | |
| 377 | - if ( empty($limit) ) { |
|
| 377 | + if ( empty($limit) ) { |
|
| 378 | 378 | self::set_field_transient( $results, $form_id, 0, array( 'inc_embed' => $inc_embed, 'inc_repeat' => $inc_repeat ) ); |
| 379 | - } |
|
| 379 | + } |
|
| 380 | 380 | |
| 381 | 381 | return $results; |
| 382 | - } |
|
| 382 | + } |
|
| 383 | 383 | |
| 384 | 384 | /** |
| 385 | - * If repeating fields should be included, adjust $where accordingly |
|
| 386 | - * |
|
| 387 | - * @param string $inc_repeat |
|
| 388 | - * @param array $where - pass by reference |
|
| 389 | - */ |
|
| 385 | + * If repeating fields should be included, adjust $where accordingly |
|
| 386 | + * |
|
| 387 | + * @param string $inc_repeat |
|
| 388 | + * @param array $where - pass by reference |
|
| 389 | + */ |
|
| 390 | 390 | private static function maybe_include_repeating_fields( $inc_repeat, &$where ) { |
| 391 | 391 | if ( $inc_repeat == 'include' ) { |
| 392 | 392 | $form_id = $where['fi.form_id']; |
@@ -397,77 +397,77 @@ discard block |
||
| 397 | 397 | |
| 398 | 398 | public static function include_sub_fields( &$results, $inc_embed, $type = 'all' ) { |
| 399 | 399 | if ( 'include' != $inc_embed || empty( $results ) ) { |
| 400 | - return; |
|
| 401 | - } |
|
| 400 | + return; |
|
| 401 | + } |
|
| 402 | 402 | |
| 403 | - $form_fields = $results; |
|
| 403 | + $form_fields = $results; |
|
| 404 | 404 | $index_offset = 1; |
| 405 | - foreach ( $form_fields as $k => $field ) { |
|
| 406 | - if ( 'form' != $field->type || ! isset($field->field_options['form_select']) ) { |
|
| 407 | - continue; |
|
| 408 | - } |
|
| 409 | - |
|
| 410 | - if ( $type == 'all' ) { |
|
| 411 | - $sub_fields = self::get_all_for_form( $field->field_options['form_select'] ); |
|
| 412 | - } else { |
|
| 413 | - $sub_fields = self::get_all_types_in_form($field->form_id, $type); |
|
| 414 | - } |
|
| 415 | - |
|
| 416 | - if ( ! empty($sub_fields) ) { |
|
| 405 | + foreach ( $form_fields as $k => $field ) { |
|
| 406 | + if ( 'form' != $field->type || ! isset($field->field_options['form_select']) ) { |
|
| 407 | + continue; |
|
| 408 | + } |
|
| 409 | + |
|
| 410 | + if ( $type == 'all' ) { |
|
| 411 | + $sub_fields = self::get_all_for_form( $field->field_options['form_select'] ); |
|
| 412 | + } else { |
|
| 413 | + $sub_fields = self::get_all_types_in_form($field->form_id, $type); |
|
| 414 | + } |
|
| 415 | + |
|
| 416 | + if ( ! empty($sub_fields) ) { |
|
| 417 | 417 | $index = $k + $index_offset; |
| 418 | 418 | $index_offset += count( $sub_fields ); |
| 419 | 419 | array_splice($results, $index, 0, $sub_fields); |
| 420 | - } |
|
| 421 | - unset($field, $sub_fields); |
|
| 422 | - } |
|
| 423 | - } |
|
| 420 | + } |
|
| 421 | + unset($field, $sub_fields); |
|
| 422 | + } |
|
| 423 | + } |
|
| 424 | 424 | |
| 425 | 425 | public static function getAll( $where = array(), $order_by = '', $limit = '', $blog_id = false ) { |
| 426 | 426 | $cache_key = maybe_serialize( $where ) . $order_by . 'l' . $limit . 'b' . $blog_id; |
| 427 | - if ( self::$use_cache ) { |
|
| 428 | - // make sure old cache doesn't get saved as a transient |
|
| 429 | - $results = wp_cache_get($cache_key, 'frm_field'); |
|
| 430 | - if ( false !== $results ) { |
|
| 431 | - return stripslashes_deep($results); |
|
| 432 | - } |
|
| 433 | - } |
|
| 434 | - |
|
| 435 | - global $wpdb; |
|
| 436 | - |
|
| 437 | - if ( $blog_id && is_multisite() ) { |
|
| 438 | - global $wpmuBaseTablePrefix; |
|
| 439 | - if ( $wpmuBaseTablePrefix ) { |
|
| 427 | + if ( self::$use_cache ) { |
|
| 428 | + // make sure old cache doesn't get saved as a transient |
|
| 429 | + $results = wp_cache_get($cache_key, 'frm_field'); |
|
| 430 | + if ( false !== $results ) { |
|
| 431 | + return stripslashes_deep($results); |
|
| 432 | + } |
|
| 433 | + } |
|
| 434 | + |
|
| 435 | + global $wpdb; |
|
| 436 | + |
|
| 437 | + if ( $blog_id && is_multisite() ) { |
|
| 438 | + global $wpmuBaseTablePrefix; |
|
| 439 | + if ( $wpmuBaseTablePrefix ) { |
|
| 440 | 440 | $prefix = $wpmuBaseTablePrefix . $blog_id . '_'; |
| 441 | - } else { |
|
| 442 | - $prefix = $wpdb->get_blog_prefix( $blog_id ); |
|
| 443 | - } |
|
| 441 | + } else { |
|
| 442 | + $prefix = $wpdb->get_blog_prefix( $blog_id ); |
|
| 443 | + } |
|
| 444 | 444 | |
| 445 | 445 | $table_name = $prefix . 'frm_fields'; |
| 446 | 446 | $form_table_name = $prefix . 'frm_forms'; |
| 447 | 447 | } else { |
| 448 | 448 | $table_name = $wpdb->prefix . 'frm_fields'; |
| 449 | 449 | $form_table_name = $wpdb->prefix . 'frm_forms'; |
| 450 | - } |
|
| 450 | + } |
|
| 451 | 451 | |
| 452 | 452 | if ( ! empty( $order_by ) && strpos( $order_by, 'ORDER BY' ) === false ) { |
| 453 | 453 | $order_by = ' ORDER BY ' . $order_by; |
| 454 | 454 | } |
| 455 | 455 | |
| 456 | - $limit = FrmAppHelper::esc_limit($limit); |
|
| 456 | + $limit = FrmAppHelper::esc_limit($limit); |
|
| 457 | 457 | |
| 458 | - $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"; |
|
| 459 | - $query_type = ( $limit == ' LIMIT 1' || $limit == 1 ) ? 'row' : 'results'; |
|
| 458 | + $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"; |
|
| 459 | + $query_type = ( $limit == ' LIMIT 1' || $limit == 1 ) ? 'row' : 'results'; |
|
| 460 | 460 | |
| 461 | - if ( is_array($where) ) { |
|
| 462 | - $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 ); |
|
| 461 | + if ( is_array($where) ) { |
|
| 462 | + $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 ); |
|
| 463 | 463 | } else { |
| 464 | 464 | // if the query is not an array, then it has already been prepared |
| 465 | - $query .= FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit; |
|
| 465 | + $query .= FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit; |
|
| 466 | 466 | |
| 467 | 467 | $function_name = ( $query_type == 'row' ) ? 'get_row' : 'get_results'; |
| 468 | 468 | $results = $wpdb->$function_name( $query ); |
| 469 | - } |
|
| 470 | - unset( $where ); |
|
| 469 | + } |
|
| 470 | + unset( $where ); |
|
| 471 | 471 | |
| 472 | 472 | self::format_field_results( $results ); |
| 473 | 473 | |
@@ -566,21 +566,21 @@ discard block |
||
| 566 | 566 | |
| 567 | 567 | public static function getIds( $where = '', $order_by = '', $limit = '' ) { |
| 568 | 568 | _deprecated_function( __FUNCTION__, '2.0' ); |
| 569 | - global $wpdb; |
|
| 570 | - if ( ! empty($order_by) && ! strpos($order_by, 'ORDER BY') !== false ) { |
|
| 569 | + global $wpdb; |
|
| 570 | + if ( ! empty($order_by) && ! strpos($order_by, 'ORDER BY') !== false ) { |
|
| 571 | 571 | $order_by = ' ORDER BY ' . $order_by; |
| 572 | - } |
|
| 572 | + } |
|
| 573 | 573 | |
| 574 | 574 | $query = 'SELECT fi.id FROM ' . $wpdb->prefix . 'frm_fields fi ' . |
| 575 | 575 | 'LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_forms fr ON fi.form_id=fr.id' . |
| 576 | 576 | FrmAppHelper::prepend_and_or_where( ' WHERE ', $where ) . $order_by . $limit; |
| 577 | 577 | |
| 578 | - $method = ( $limit == ' LIMIT 1' || $limit == 1 ) ? 'get_var' : 'get_col'; |
|
| 578 | + $method = ( $limit == ' LIMIT 1' || $limit == 1 ) ? 'get_var' : 'get_col'; |
|
| 579 | 579 | $cache_key = 'getIds_' . maybe_serialize( $where ) . $order_by . $limit; |
| 580 | - $results = FrmAppHelper::check_cache($cache_key, 'frm_field', $query, $method); |
|
| 580 | + $results = FrmAppHelper::check_cache($cache_key, 'frm_field', $query, $method); |
|
| 581 | 581 | |
| 582 | - return $results; |
|
| 583 | - } |
|
| 582 | + return $results; |
|
| 583 | + } |
|
| 584 | 584 | |
| 585 | 585 | public static function is_no_save_field( $type ) { |
| 586 | 586 | return in_array( $type, self::no_save_fields() ); |
@@ -723,8 +723,8 @@ discard block |
||
| 723 | 723 | } |
| 724 | 724 | |
| 725 | 725 | /** |
| 726 | - * @since 2.0.09 |
|
| 727 | - */ |
|
| 726 | + * @since 2.0.09 |
|
| 727 | + */ |
|
| 728 | 728 | public static function is_repeating_field( $field ) { |
| 729 | 729 | if ( is_array( $field ) ) { |
| 730 | 730 | $is_repeating_field = ( 'divider' == $field['type'] ); |
@@ -734,14 +734,14 @@ discard block |
||
| 734 | 734 | return ( $is_repeating_field && self::is_option_true( $field, 'repeat' ) ); |
| 735 | 735 | } |
| 736 | 736 | |
| 737 | - /** |
|
| 738 | - * @param string $key |
|
| 739 | - * @return int field id |
|
| 740 | - */ |
|
| 737 | + /** |
|
| 738 | + * @param string $key |
|
| 739 | + * @return int field id |
|
| 740 | + */ |
|
| 741 | 741 | public static function get_id_by_key( $key ) { |
| 742 | - $id = FrmDb::get_var( 'frm_fields', array( 'field_key' => sanitize_title( $key ) ) ); |
|
| 743 | - return $id; |
|
| 744 | - } |
|
| 742 | + $id = FrmDb::get_var( 'frm_fields', array( 'field_key' => sanitize_title( $key ) ) ); |
|
| 743 | + return $id; |
|
| 744 | + } |
|
| 745 | 745 | |
| 746 | 746 | /** |
| 747 | 747 | * @param string $id |
@@ -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', |
@@ -48,36 +48,36 @@ discard block |
||
| 48 | 48 | 'tag' => __( 'Tags', 'formidable' ), |
| 49 | 49 | 'credit_card' => __( 'Credit Card', 'formidable' ), |
| 50 | 50 | 'address' => __( 'Address', 'formidable' ), |
| 51 | - )); |
|
| 51 | + ) ); |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | public static function create( $values, $return = true ) { |
| 55 | 55 | global $wpdb, $frm_duplicate_ids; |
| 56 | 56 | |
| 57 | 57 | $new_values = array(); |
| 58 | - $key = isset($values['field_key']) ? $values['field_key'] : $values['name']; |
|
| 58 | + $key = isset( $values['field_key'] ) ? $values['field_key'] : $values['name']; |
|
| 59 | 59 | $new_values['field_key'] = FrmAppHelper::get_unique_key( $key, $wpdb->prefix . 'frm_fields', 'field_key' ); |
| 60 | 60 | |
| 61 | 61 | foreach ( array( 'name', 'description', 'type', 'default_value' ) as $col ) { |
| 62 | - $new_values[ $col ] = $values[ $col ]; |
|
| 62 | + $new_values[$col] = $values[$col]; |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | $new_values['options'] = $values['options']; |
| 66 | 66 | |
| 67 | - $new_values['field_order'] = isset($values['field_order']) ? (int) $values['field_order'] : null; |
|
| 68 | - $new_values['required'] = isset($values['required']) ? (int) $values['required'] : 0; |
|
| 69 | - $new_values['form_id'] = isset($values['form_id']) ? (int) $values['form_id'] : null; |
|
| 67 | + $new_values['field_order'] = isset( $values['field_order'] ) ? (int) $values['field_order'] : null; |
|
| 68 | + $new_values['required'] = isset( $values['required'] ) ? (int) $values['required'] : 0; |
|
| 69 | + $new_values['form_id'] = isset( $values['form_id'] ) ? (int) $values['form_id'] : null; |
|
| 70 | 70 | $new_values['field_options'] = $values['field_options']; |
| 71 | - $new_values['created_at'] = current_time('mysql', 1); |
|
| 71 | + $new_values['created_at'] = current_time( 'mysql', 1 ); |
|
| 72 | 72 | |
| 73 | 73 | if ( isset( $values['id'] ) ) { |
| 74 | - $frm_duplicate_ids[ $values['field_key'] ] = $new_values['field_key']; |
|
| 75 | - $new_values = apply_filters('frm_duplicated_field', $new_values); |
|
| 74 | + $frm_duplicate_ids[$values['field_key']] = $new_values['field_key']; |
|
| 75 | + $new_values = apply_filters( 'frm_duplicated_field', $new_values ); |
|
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | foreach ( $new_values as $k => $v ) { |
| 79 | 79 | if ( is_array( $v ) ) { |
| 80 | - $new_values[ $k ] = serialize( $v ); |
|
| 80 | + $new_values[$k] = serialize( $v ); |
|
| 81 | 81 | } |
| 82 | 82 | unset( $k, $v ); |
| 83 | 83 | } |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | |
| 99 | 99 | if ( $query_results ) { |
| 100 | 100 | if ( isset( $values['id'] ) ) { |
| 101 | - $frm_duplicate_ids[ $values['id'] ] = $new_id; |
|
| 101 | + $frm_duplicate_ids[$values['id']] = $new_id; |
|
| 102 | 102 | } |
| 103 | 103 | return $new_id; |
| 104 | 104 | } else { |
@@ -113,9 +113,9 @@ discard block |
||
| 113 | 113 | $fields = self::getAll( $where, 'field_order', '', $blog_id ); |
| 114 | 114 | |
| 115 | 115 | foreach ( (array) $fields as $field ) { |
| 116 | - $new_key = ($copy_keys) ? $field->field_key : ''; |
|
| 117 | - if ( $copy_keys && substr($field->field_key, -1) == 2 ) { |
|
| 118 | - $new_key = rtrim($new_key, 2); |
|
| 116 | + $new_key = ( $copy_keys ) ? $field->field_key : ''; |
|
| 117 | + if ( $copy_keys && substr( $field->field_key, -1 ) == 2 ) { |
|
| 118 | + $new_key = rtrim( $new_key, 2 ); |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | $values = array(); |
@@ -138,11 +138,11 @@ discard block |
||
| 138 | 138 | $values['form_id'] = $new_repeat_form_id; |
| 139 | 139 | } |
| 140 | 140 | |
| 141 | - $values = apply_filters('frm_duplicated_field', $values); |
|
| 142 | - $new_id = self::create($values); |
|
| 143 | - $frm_duplicate_ids[ $field->id ] = $new_id; |
|
| 144 | - $frm_duplicate_ids[ $field->field_key ] = $new_id; |
|
| 145 | - unset($field); |
|
| 141 | + $values = apply_filters( 'frm_duplicated_field', $values ); |
|
| 142 | + $new_id = self::create( $values ); |
|
| 143 | + $frm_duplicate_ids[$field->id] = $new_id; |
|
| 144 | + $frm_duplicate_ids[$field->field_key] = $new_id; |
|
| 145 | + unset( $field ); |
|
| 146 | 146 | } |
| 147 | 147 | } |
| 148 | 148 | |
@@ -155,7 +155,7 @@ discard block |
||
| 155 | 155 | $values['field_key'] = FrmAppHelper::get_unique_key( $values['field_key'], $wpdb->prefix . 'frm_fields', 'field_key', $id ); |
| 156 | 156 | } |
| 157 | 157 | |
| 158 | - if ( isset($values['required']) ) { |
|
| 158 | + if ( isset( $values['required'] ) ) { |
|
| 159 | 159 | $values['required'] = (int) $values['required']; |
| 160 | 160 | } |
| 161 | 161 | |
@@ -167,8 +167,8 @@ discard block |
||
| 167 | 167 | |
| 168 | 168 | // serialize array values |
| 169 | 169 | foreach ( array( 'default_value', 'field_options', 'options' ) as $opt ) { |
| 170 | - if ( isset( $values[ $opt ] ) && is_array( $values[ $opt ] ) ) { |
|
| 171 | - $values[ $opt ] = serialize( $values[ $opt ] ); |
|
| 170 | + if ( isset( $values[$opt] ) && is_array( $values[$opt] ) ) { |
|
| 171 | + $values[$opt] = serialize( $values[$opt] ); |
|
| 172 | 172 | } |
| 173 | 173 | } |
| 174 | 174 | |
@@ -178,13 +178,13 @@ discard block |
||
| 178 | 178 | if ( isset( $values['form_id'] ) ) { |
| 179 | 179 | $form_id = absint( $values['form_id'] ); |
| 180 | 180 | } else { |
| 181 | - $field = self::getOne($id); |
|
| 181 | + $field = self::getOne( $id ); |
|
| 182 | 182 | if ( $field ) { |
| 183 | 183 | $form_id = $field->form_id; |
| 184 | 184 | } |
| 185 | - unset($field); |
|
| 185 | + unset( $field ); |
|
| 186 | 186 | } |
| 187 | - unset($values); |
|
| 187 | + unset( $values ); |
|
| 188 | 188 | |
| 189 | 189 | if ( $query_results ) { |
| 190 | 190 | wp_cache_delete( $id, 'frm_field' ); |
@@ -236,13 +236,13 @@ discard block |
||
| 236 | 236 | $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%' ) ); |
| 237 | 237 | |
| 238 | 238 | $cache_key = serialize( array( 'fi.form_id' => $form_id ) ) . 'field_orderlb'; |
| 239 | - wp_cache_delete($cache_key, 'frm_field'); |
|
| 239 | + wp_cache_delete( $cache_key, 'frm_field' ); |
|
| 240 | 240 | |
| 241 | 241 | // this cache key is autogenerated in FrmDb::get_var |
| 242 | 242 | 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' ); |
| 243 | 243 | wp_cache_delete( '1_' . $form_id . '_' . $form_id . '_ORDER_BY_field_orderfi.*__fr.name_as_form_name_results', 'frm_field' ); |
| 244 | 244 | |
| 245 | - $form = FrmForm::getOne($form_id); |
|
| 245 | + $form = FrmForm::getOne( $form_id ); |
|
| 246 | 246 | if ( $form && $form->parent_form_id ) { |
| 247 | 247 | self::delete_form_transient( $form->parent_form_id ); |
| 248 | 248 | } |
@@ -264,16 +264,16 @@ discard block |
||
| 264 | 264 | |
| 265 | 265 | global $wpdb; |
| 266 | 266 | |
| 267 | - $where = is_numeric($id) ? 'id=%d' : 'field_key=%s'; |
|
| 267 | + $where = is_numeric( $id ) ? 'id=%d' : 'field_key=%s'; |
|
| 268 | 268 | $query = $wpdb->prepare( 'SELECT * FROM ' . $wpdb->prefix . 'frm_fields WHERE ' . $where, $id ); |
| 269 | 269 | |
| 270 | 270 | $results = FrmAppHelper::check_cache( $id, 'frm_field', $query, 'get_row', 0 ); |
| 271 | 271 | |
| 272 | - if ( empty($results) ) { |
|
| 272 | + if ( empty( $results ) ) { |
|
| 273 | 273 | return $results; |
| 274 | 274 | } |
| 275 | 275 | |
| 276 | - if ( is_numeric($id) ) { |
|
| 276 | + if ( is_numeric( $id ) ) { |
|
| 277 | 277 | wp_cache_set( $results->field_key, $results, 'frm_field' ); |
| 278 | 278 | } else if ( $results ) { |
| 279 | 279 | wp_cache_set( $results->id, $results, 'frm_field' ); |
@@ -281,7 +281,7 @@ discard block |
||
| 281 | 281 | |
| 282 | 282 | self::prepare_options( $results ); |
| 283 | 283 | |
| 284 | - return stripslashes_deep($results); |
|
| 284 | + return stripslashes_deep( $results ); |
|
| 285 | 285 | } |
| 286 | 286 | |
| 287 | 287 | /** |
@@ -314,20 +314,20 @@ discard block |
||
| 314 | 314 | continue; |
| 315 | 315 | } |
| 316 | 316 | |
| 317 | - $fields[ $result->id ] = $result; |
|
| 318 | - $count++; |
|
| 317 | + $fields[$result->id] = $result; |
|
| 318 | + $count ++; |
|
| 319 | 319 | if ( $limit == 1 ) { |
| 320 | 320 | $fields = $result; |
| 321 | 321 | break; |
| 322 | 322 | } |
| 323 | 323 | |
| 324 | - if ( ! empty($limit) && $count >= $limit ) { |
|
| 324 | + if ( ! empty( $limit ) && $count >= $limit ) { |
|
| 325 | 325 | break; |
| 326 | 326 | } |
| 327 | 327 | |
| 328 | - unset($result); |
|
| 328 | + unset( $result ); |
|
| 329 | 329 | } |
| 330 | - return stripslashes_deep($fields); |
|
| 330 | + return stripslashes_deep( $fields ); |
|
| 331 | 331 | } |
| 332 | 332 | |
| 333 | 333 | self::$use_cache = false; |
@@ -336,7 +336,7 @@ discard block |
||
| 336 | 336 | self::maybe_include_repeating_fields( $inc_sub, $where ); |
| 337 | 337 | $results = self::getAll( $where, 'field_order', $limit ); |
| 338 | 338 | self::$use_cache = true; |
| 339 | - self::include_sub_fields($results, $inc_sub, $type); |
|
| 339 | + self::include_sub_fields( $results, $inc_sub, $type ); |
|
| 340 | 340 | |
| 341 | 341 | return $results; |
| 342 | 342 | } |
@@ -348,15 +348,15 @@ discard block |
||
| 348 | 348 | |
| 349 | 349 | $results = self::get_fields_from_transients( $form_id, array( 'inc_embed' => $inc_embed, 'inc_repeat' => $inc_repeat ) ); |
| 350 | 350 | if ( ! empty( $results ) ) { |
| 351 | - if ( empty($limit) ) { |
|
| 351 | + if ( empty( $limit ) ) { |
|
| 352 | 352 | return $results; |
| 353 | 353 | } |
| 354 | 354 | |
| 355 | 355 | $fields = array(); |
| 356 | 356 | $count = 0; |
| 357 | 357 | foreach ( $results as $result ) { |
| 358 | - $fields[ $result->id ] = $result; |
|
| 359 | - if ( ! empty($limit) && $count >= $limit ) { |
|
| 358 | + $fields[$result->id] = $result; |
|
| 359 | + if ( ! empty( $limit ) && $count >= $limit ) { |
|
| 360 | 360 | break; |
| 361 | 361 | } |
| 362 | 362 | } |
@@ -374,7 +374,7 @@ discard block |
||
| 374 | 374 | |
| 375 | 375 | self::include_sub_fields( $results, $inc_embed, 'all' ); |
| 376 | 376 | |
| 377 | - if ( empty($limit) ) { |
|
| 377 | + if ( empty( $limit ) ) { |
|
| 378 | 378 | self::set_field_transient( $results, $form_id, 0, array( 'inc_embed' => $inc_embed, 'inc_repeat' => $inc_repeat ) ); |
| 379 | 379 | } |
| 380 | 380 | |
@@ -403,22 +403,22 @@ discard block |
||
| 403 | 403 | $form_fields = $results; |
| 404 | 404 | $index_offset = 1; |
| 405 | 405 | foreach ( $form_fields as $k => $field ) { |
| 406 | - if ( 'form' != $field->type || ! isset($field->field_options['form_select']) ) { |
|
| 406 | + if ( 'form' != $field->type || ! isset( $field->field_options['form_select'] ) ) { |
|
| 407 | 407 | continue; |
| 408 | 408 | } |
| 409 | 409 | |
| 410 | 410 | if ( $type == 'all' ) { |
| 411 | 411 | $sub_fields = self::get_all_for_form( $field->field_options['form_select'] ); |
| 412 | 412 | } else { |
| 413 | - $sub_fields = self::get_all_types_in_form($field->form_id, $type); |
|
| 413 | + $sub_fields = self::get_all_types_in_form( $field->form_id, $type ); |
|
| 414 | 414 | } |
| 415 | 415 | |
| 416 | - if ( ! empty($sub_fields) ) { |
|
| 416 | + if ( ! empty( $sub_fields ) ) { |
|
| 417 | 417 | $index = $k + $index_offset; |
| 418 | 418 | $index_offset += count( $sub_fields ); |
| 419 | - array_splice($results, $index, 0, $sub_fields); |
|
| 419 | + array_splice( $results, $index, 0, $sub_fields ); |
|
| 420 | 420 | } |
| 421 | - unset($field, $sub_fields); |
|
| 421 | + unset( $field, $sub_fields ); |
|
| 422 | 422 | } |
| 423 | 423 | } |
| 424 | 424 | |
@@ -426,9 +426,9 @@ discard block |
||
| 426 | 426 | $cache_key = maybe_serialize( $where ) . $order_by . 'l' . $limit . 'b' . $blog_id; |
| 427 | 427 | if ( self::$use_cache ) { |
| 428 | 428 | // make sure old cache doesn't get saved as a transient |
| 429 | - $results = wp_cache_get($cache_key, 'frm_field'); |
|
| 429 | + $results = wp_cache_get( $cache_key, 'frm_field' ); |
|
| 430 | 430 | if ( false !== $results ) { |
| 431 | - return stripslashes_deep($results); |
|
| 431 | + return stripslashes_deep( $results ); |
|
| 432 | 432 | } |
| 433 | 433 | } |
| 434 | 434 | |
@@ -453,16 +453,16 @@ discard block |
||
| 453 | 453 | $order_by = ' ORDER BY ' . $order_by; |
| 454 | 454 | } |
| 455 | 455 | |
| 456 | - $limit = FrmAppHelper::esc_limit($limit); |
|
| 456 | + $limit = FrmAppHelper::esc_limit( $limit ); |
|
| 457 | 457 | |
| 458 | 458 | $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"; |
| 459 | 459 | $query_type = ( $limit == ' LIMIT 1' || $limit == 1 ) ? 'row' : 'results'; |
| 460 | 460 | |
| 461 | - if ( is_array($where) ) { |
|
| 461 | + if ( is_array( $where ) ) { |
|
| 462 | 462 | $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 ); |
| 463 | 463 | } else { |
| 464 | 464 | // if the query is not an array, then it has already been prepared |
| 465 | - $query .= FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit; |
|
| 465 | + $query .= FrmAppHelper::prepend_and_or_where( ' WHERE ', $where ) . $order_by . $limit; |
|
| 466 | 466 | |
| 467 | 467 | $function_name = ( $query_type == 'row' ) ? 'get_row' : 'get_results'; |
| 468 | 468 | $results = $wpdb->$function_name( $query ); |
@@ -485,9 +485,9 @@ discard block |
||
| 485 | 485 | wp_cache_set( $result->id, $result, 'frm_field' ); |
| 486 | 486 | wp_cache_set( $result->field_key, $result, 'frm_field' ); |
| 487 | 487 | |
| 488 | - $results[ $r_key ]->field_options = maybe_unserialize( $result->field_options ); |
|
| 489 | - $results[ $r_key ]->options = maybe_unserialize( $result->options ); |
|
| 490 | - $results[ $r_key ]->default_value = maybe_unserialize( $result->default_value ); |
|
| 488 | + $results[$r_key]->field_options = maybe_unserialize( $result->field_options ); |
|
| 489 | + $results[$r_key]->options = maybe_unserialize( $result->options ); |
|
| 490 | + $results[$r_key]->default_value = maybe_unserialize( $result->default_value ); |
|
| 491 | 491 | |
| 492 | 492 | unset( $r_key, $result ); |
| 493 | 493 | } |
@@ -506,8 +506,8 @@ discard block |
||
| 506 | 506 | private static function prepare_options( &$results ) { |
| 507 | 507 | $results->field_options = maybe_unserialize( $results->field_options ); |
| 508 | 508 | |
| 509 | - $results->options = maybe_unserialize($results->options); |
|
| 510 | - $results->default_value = maybe_unserialize($results->default_value); |
|
| 509 | + $results->options = maybe_unserialize( $results->options ); |
|
| 510 | + $results->default_value = maybe_unserialize( $results->default_value ); |
|
| 511 | 511 | } |
| 512 | 512 | |
| 513 | 513 | /** |
@@ -534,7 +534,7 @@ discard block |
||
| 534 | 534 | |
| 535 | 535 | if ( count( $next_fields ) >= self::$transient_size ) { |
| 536 | 536 | // if this transient is full, check for another |
| 537 | - $next++; |
|
| 537 | + $next ++; |
|
| 538 | 538 | self::get_next_transient( $fields, $base_name, $next ); |
| 539 | 539 | } |
| 540 | 540 | } |
@@ -560,14 +560,14 @@ discard block |
||
| 560 | 560 | return; |
| 561 | 561 | } |
| 562 | 562 | |
| 563 | - $next++; |
|
| 563 | + $next ++; |
|
| 564 | 564 | } |
| 565 | 565 | } |
| 566 | 566 | |
| 567 | 567 | public static function getIds( $where = '', $order_by = '', $limit = '' ) { |
| 568 | 568 | _deprecated_function( __FUNCTION__, '2.0' ); |
| 569 | 569 | global $wpdb; |
| 570 | - if ( ! empty($order_by) && ! strpos($order_by, 'ORDER BY') !== false ) { |
|
| 570 | + if ( ! empty( $order_by ) && ! strpos( $order_by, 'ORDER BY' ) !== false ) { |
|
| 571 | 571 | $order_by = ' ORDER BY ' . $order_by; |
| 572 | 572 | } |
| 573 | 573 | |
@@ -577,7 +577,7 @@ discard block |
||
| 577 | 577 | |
| 578 | 578 | $method = ( $limit == ' LIMIT 1' || $limit == 1 ) ? 'get_var' : 'get_col'; |
| 579 | 579 | $cache_key = 'getIds_' . maybe_serialize( $where ) . $order_by . $limit; |
| 580 | - $results = FrmAppHelper::check_cache($cache_key, 'frm_field', $query, $method); |
|
| 580 | + $results = FrmAppHelper::check_cache( $cache_key, 'frm_field', $query, $method ); |
|
| 581 | 581 | |
| 582 | 582 | return $results; |
| 583 | 583 | } |
@@ -608,8 +608,8 @@ discard block |
||
| 608 | 608 | $is_multi_value_field = ( |
| 609 | 609 | $field['type'] == 'checkbox' || |
| 610 | 610 | $field['type'] == 'address' || |
| 611 | - ( $field['type'] == 'data' && isset($field['data_type']) && $field['data_type'] == 'checkbox' ) || |
|
| 612 | - ( $field['type'] == 'lookup' && isset($field['data_type']) && $field['data_type'] == 'checkbox' ) || |
|
| 611 | + ( $field['type'] == 'data' && isset( $field['data_type'] ) && $field['data_type'] == 'checkbox' ) || |
|
| 612 | + ( $field['type'] == 'lookup' && isset( $field['data_type'] ) && $field['data_type'] == 'checkbox' ) || |
|
| 613 | 613 | self::is_multiple_select( $field ) |
| 614 | 614 | ); |
| 615 | 615 | |
@@ -634,9 +634,9 @@ discard block |
||
| 634 | 634 | */ |
| 635 | 635 | public static function is_multiple_select( $field ) { |
| 636 | 636 | if ( is_array( $field ) ) { |
| 637 | - return self::is_option_true( $field, 'multiple' ) && ( ( $field['type'] == 'select' || ( $field['type'] == 'data' && isset( $field['data_type'] ) && $field['data_type'] == 'select') ) ); |
|
| 637 | + return self::is_option_true( $field, 'multiple' ) && ( ( $field['type'] == 'select' || ( $field['type'] == 'data' && isset( $field['data_type'] ) && $field['data_type'] == 'select' ) ) ); |
|
| 638 | 638 | } else { |
| 639 | - 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') ) ); |
|
| 639 | + 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' ) ) ); |
|
| 640 | 640 | } |
| 641 | 641 | } |
| 642 | 642 | |
@@ -683,23 +683,23 @@ discard block |
||
| 683 | 683 | } |
| 684 | 684 | |
| 685 | 685 | public static function is_option_true_in_array( $field, $option ) { |
| 686 | - return isset( $field[ $option ] ) && $field[ $option ]; |
|
| 686 | + return isset( $field[$option] ) && $field[$option]; |
|
| 687 | 687 | } |
| 688 | 688 | |
| 689 | 689 | public static function is_option_true_in_object( $field, $option ) { |
| 690 | - return isset( $field->field_options[ $option ] ) && $field->field_options[ $option ]; |
|
| 690 | + return isset( $field->field_options[$option] ) && $field->field_options[$option]; |
|
| 691 | 691 | } |
| 692 | 692 | |
| 693 | 693 | public static function is_option_empty_in_array( $field, $option ) { |
| 694 | - return ! isset( $field[ $option ] ) || empty( $field[ $option ] ); |
|
| 694 | + return ! isset( $field[$option] ) || empty( $field[$option] ); |
|
| 695 | 695 | } |
| 696 | 696 | |
| 697 | 697 | public static function is_option_empty_in_object( $field, $option ) { |
| 698 | - return ! isset( $field->field_options[ $option ] ) || empty( $field->field_options[ $option ] ); |
|
| 698 | + return ! isset( $field->field_options[$option] ) || empty( $field->field_options[$option] ); |
|
| 699 | 699 | } |
| 700 | 700 | |
| 701 | 701 | public static function is_option_value_in_object( $field, $option ) { |
| 702 | - return isset( $field->field_options[ $option ] ) && $field->field_options[ $option ] != ''; |
|
| 702 | + return isset( $field->field_options[$option] ) && $field->field_options[$option] != ''; |
|
| 703 | 703 | } |
| 704 | 704 | |
| 705 | 705 | /** |
@@ -715,11 +715,11 @@ discard block |
||
| 715 | 715 | } |
| 716 | 716 | |
| 717 | 717 | public static function get_option_in_array( $field, $option ) { |
| 718 | - return $field[ $option ]; |
|
| 718 | + return $field[$option]; |
|
| 719 | 719 | } |
| 720 | 720 | |
| 721 | 721 | public static function get_option_in_object( $field, $option ) { |
| 722 | - return isset( $field->field_options[ $option ] ) ? $field->field_options[ $option ] : ''; |
|
| 722 | + return isset( $field->field_options[$option] ) ? $field->field_options[$option] : ''; |
|
| 723 | 723 | } |
| 724 | 724 | |
| 725 | 725 | /** |
@@ -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,54 +191,54 @@ 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 | - $is_settings_page = ( isset( $values['options'] ) || isset( $values['field_options'][ 'custom_html_' . $field_id ] ) ); |
|
| 228 | + $is_settings_page = ( isset( $values['options'] ) || isset( $values['field_options']['custom_html_' . $field_id] ) ); |
|
| 229 | 229 | if ( $is_settings_page ) { |
| 230 | 230 | //updating the settings page |
| 231 | - if ( isset( $values['field_options'][ 'custom_html_' . $field_id ] ) ) { |
|
| 232 | - $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 ) ); |
|
| 233 | - $field->field_options = apply_filters('frm_update_form_field_options', $field->field_options, $field, $values); |
|
| 231 | + if ( isset( $values['field_options']['custom_html_' . $field_id] ) ) { |
|
| 232 | + $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 ) ); |
|
| 233 | + $field->field_options = apply_filters( 'frm_update_form_field_options', $field->field_options, $field, $values ); |
|
| 234 | 234 | FrmField::update( $field_id, array( 'field_options' => $field->field_options ) ); |
| 235 | 235 | } else if ( $field->type == 'hidden' || $field->type == 'user_id' ) { |
| 236 | 236 | $prev_opts = $field->field_options; |
| 237 | - $field->field_options = apply_filters('frm_update_form_field_options', $field->field_options, $field, $values); |
|
| 237 | + $field->field_options = apply_filters( 'frm_update_form_field_options', $field->field_options, $field, $values ); |
|
| 238 | 238 | if ( $prev_opts != $field->field_options ) { |
| 239 | 239 | FrmField::update( $field_id, array( 'field_options' => $field->field_options ) ); |
| 240 | 240 | } |
| 241 | - unset($prev_opts); |
|
| 241 | + unset( $prev_opts ); |
|
| 242 | 242 | } |
| 243 | 243 | } |
| 244 | 244 | |
@@ -252,23 +252,23 @@ discard block |
||
| 252 | 252 | $update_options = apply_filters( 'frm_field_options_to_update', $update_options ); |
| 253 | 253 | |
| 254 | 254 | foreach ( $update_options as $opt => $default ) { |
| 255 | - $field->field_options[ $opt ] = isset( $values['field_options'][ $opt . '_' . $field_id ] ) ? trim( sanitize_text_field( $values['field_options'][ $opt . '_' . $field_id ] ) ) : $default; |
|
| 255 | + $field->field_options[$opt] = isset( $values['field_options'][$opt . '_' . $field_id] ) ? trim( sanitize_text_field( $values['field_options'][$opt . '_' . $field_id] ) ) : $default; |
|
| 256 | 256 | } |
| 257 | 257 | |
| 258 | - $field->field_options = apply_filters('frm_update_field_options', $field->field_options, $field, $values); |
|
| 259 | - $default_value = maybe_serialize( $values['item_meta'][ $field_id ] ); |
|
| 260 | - $field_key = isset( $values['field_options'][ 'field_key_' . $field_id ] ) ? $values['field_options'][ 'field_key_' . $field_id ] : $field->field_key; |
|
| 261 | - $required = isset( $values['field_options'][ 'required_' . $field_id ] ) ? $values['field_options'][ 'required_' . $field_id ] : false; |
|
| 262 | - $field_type = isset( $values['field_options'][ 'type_' . $field_id ] ) ? $values['field_options'][ 'type_' . $field_id ] : $field->type; |
|
| 263 | - $field_description = isset( $values['field_options'][ 'description_' . $field_id ] ) ? $values['field_options'][ 'description_' . $field_id ] : $field->description; |
|
| 258 | + $field->field_options = apply_filters( 'frm_update_field_options', $field->field_options, $field, $values ); |
|
| 259 | + $default_value = maybe_serialize( $values['item_meta'][$field_id] ); |
|
| 260 | + $field_key = isset( $values['field_options']['field_key_' . $field_id] ) ? $values['field_options']['field_key_' . $field_id] : $field->field_key; |
|
| 261 | + $required = isset( $values['field_options']['required_' . $field_id] ) ? $values['field_options']['required_' . $field_id] : false; |
|
| 262 | + $field_type = isset( $values['field_options']['type_' . $field_id] ) ? $values['field_options']['type_' . $field_id] : $field->type; |
|
| 263 | + $field_description = isset( $values['field_options']['description_' . $field_id] ) ? $values['field_options']['description_' . $field_id] : $field->description; |
|
| 264 | 264 | |
| 265 | - FrmField::update($field_id, array( |
|
| 265 | + FrmField::update( $field_id, array( |
|
| 266 | 266 | 'field_key' => $field_key, 'type' => $field_type, |
| 267 | 267 | 'default_value' => $default_value, 'field_options' => $field->field_options, |
| 268 | 268 | 'description' => $field_description, 'required' => $required, |
| 269 | 269 | ) ); |
| 270 | 270 | |
| 271 | - FrmField::delete_form_transient($field->form_id); |
|
| 271 | + FrmField::delete_form_transient( $field->form_id ); |
|
| 272 | 272 | } |
| 273 | 273 | self::clear_form_cache(); |
| 274 | 274 | |
@@ -281,17 +281,17 @@ discard block |
||
| 281 | 281 | */ |
| 282 | 282 | public static function set_status( $id, $status ) { |
| 283 | 283 | if ( 'trash' == $status ) { |
| 284 | - return self::trash($id); |
|
| 284 | + return self::trash( $id ); |
|
| 285 | 285 | } |
| 286 | 286 | |
| 287 | - $statuses = array( 'published', 'draft', 'trash' ); |
|
| 287 | + $statuses = array( 'published', 'draft', 'trash' ); |
|
| 288 | 288 | if ( ! in_array( $status, $statuses ) ) { |
| 289 | 289 | return false; |
| 290 | 290 | } |
| 291 | 291 | |
| 292 | 292 | global $wpdb; |
| 293 | 293 | |
| 294 | - if ( is_array($id) ) { |
|
| 294 | + if ( is_array( $id ) ) { |
|
| 295 | 295 | $where = array( 'id' => $id ); |
| 296 | 296 | FrmDb::get_where_clause_and_values( $where ); |
| 297 | 297 | array_unshift( $where['values'], $status ); |
@@ -316,7 +316,7 @@ discard block |
||
| 316 | 316 | return self::destroy( $id ); |
| 317 | 317 | } |
| 318 | 318 | |
| 319 | - $form = self::getOne($id); |
|
| 319 | + $form = self::getOne( $id ); |
|
| 320 | 320 | if ( ! $form ) { |
| 321 | 321 | return false; |
| 322 | 322 | } |
@@ -344,7 +344,7 @@ discard block |
||
| 344 | 344 | public static function destroy( $id ) { |
| 345 | 345 | global $wpdb; |
| 346 | 346 | |
| 347 | - $form = self::getOne($id); |
|
| 347 | + $form = self::getOne( $id ); |
|
| 348 | 348 | if ( ! $form ) { |
| 349 | 349 | return false; |
| 350 | 350 | } |
@@ -353,8 +353,8 @@ discard block |
||
| 353 | 353 | // Disconnect the entries from this form |
| 354 | 354 | $entries = FrmDb::get_col( $wpdb->prefix . 'frm_items', array( 'form_id' => $id ) ); |
| 355 | 355 | foreach ( $entries as $entry_id ) { |
| 356 | - FrmEntry::destroy($entry_id); |
|
| 357 | - unset($entry_id); |
|
| 356 | + FrmEntry::destroy( $entry_id ); |
|
| 357 | + unset( $entry_id ); |
|
| 358 | 358 | } |
| 359 | 359 | |
| 360 | 360 | // Disconnect the fields from this form |
@@ -364,7 +364,7 @@ discard block |
||
| 364 | 364 | if ( $query_results ) { |
| 365 | 365 | // Delete all form actions linked to this form |
| 366 | 366 | $action_control = FrmFormActionsController::get_form_actions( 'email' ); |
| 367 | - $action_control->destroy($id, 'all'); |
|
| 367 | + $action_control->destroy( $id, 'all' ); |
|
| 368 | 368 | |
| 369 | 369 | // Clear form caching |
| 370 | 370 | self::clear_form_cache(); |
@@ -398,7 +398,7 @@ discard block |
||
| 398 | 398 | $form->options = maybe_unserialize( $form->options ); |
| 399 | 399 | if ( ! isset( $form->options['trash_time'] ) || $form->options['trash_time'] < $delete_timestamp ) { |
| 400 | 400 | self::destroy( $form->id ); |
| 401 | - $count++; |
|
| 401 | + $count ++; |
|
| 402 | 402 | } |
| 403 | 403 | |
| 404 | 404 | unset( $form ); |
@@ -412,15 +412,15 @@ discard block |
||
| 412 | 412 | public static function &getName( $id ) { |
| 413 | 413 | global $wpdb; |
| 414 | 414 | |
| 415 | - $form = FrmAppHelper::check_cache($id, 'frm_form'); |
|
| 415 | + $form = FrmAppHelper::check_cache( $id, 'frm_form' ); |
|
| 416 | 416 | if ( $form ) { |
| 417 | - $r = stripslashes($form->name); |
|
| 417 | + $r = stripslashes( $form->name ); |
|
| 418 | 418 | return $r; |
| 419 | 419 | } |
| 420 | 420 | |
| 421 | 421 | $query_key = is_numeric( $id ) ? 'id' : 'form_key'; |
| 422 | 422 | $r = FrmDb::get_var( 'frm_forms', array( $query_key => $id ), 'name' ); |
| 423 | - $r = stripslashes($r); |
|
| 423 | + $r = stripslashes( $r ); |
|
| 424 | 424 | |
| 425 | 425 | return $r; |
| 426 | 426 | } |
@@ -440,7 +440,7 @@ discard block |
||
| 440 | 440 | */ |
| 441 | 441 | public static function &getKeyById( $id ) { |
| 442 | 442 | $id = (int) $id; |
| 443 | - $cache = FrmAppHelper::check_cache($id, 'frm_form'); |
|
| 443 | + $cache = FrmAppHelper::check_cache( $id, 'frm_form' ); |
|
| 444 | 444 | if ( $cache ) { |
| 445 | 445 | return $cache->form_key; |
| 446 | 446 | } |
@@ -474,17 +474,17 @@ discard block |
||
| 474 | 474 | $table_name = $prefix . 'frm_forms'; |
| 475 | 475 | } else { |
| 476 | 476 | $table_name = $wpdb->prefix . 'frm_forms'; |
| 477 | - $cache = wp_cache_get($id, 'frm_form'); |
|
| 477 | + $cache = wp_cache_get( $id, 'frm_form' ); |
|
| 478 | 478 | if ( $cache ) { |
| 479 | - if ( isset($cache->options) ) { |
|
| 480 | - $cache->options = maybe_unserialize($cache->options); |
|
| 479 | + if ( isset( $cache->options ) ) { |
|
| 480 | + $cache->options = maybe_unserialize( $cache->options ); |
|
| 481 | 481 | } |
| 482 | 482 | |
| 483 | - return stripslashes_deep($cache); |
|
| 483 | + return stripslashes_deep( $cache ); |
|
| 484 | 484 | } |
| 485 | 485 | } |
| 486 | 486 | |
| 487 | - if ( is_numeric($id) ) { |
|
| 487 | + if ( is_numeric( $id ) ) { |
|
| 488 | 488 | $where = array( 'id' => $id ); |
| 489 | 489 | } else { |
| 490 | 490 | $where = array( 'form_key' => $id ); |
@@ -492,11 +492,11 @@ discard block |
||
| 492 | 492 | |
| 493 | 493 | $results = FrmDb::get_row( $table_name, $where ); |
| 494 | 494 | |
| 495 | - if ( isset($results->options) ) { |
|
| 496 | - wp_cache_set($results->id, $results, 'frm_form'); |
|
| 497 | - $results->options = maybe_unserialize($results->options); |
|
| 495 | + if ( isset( $results->options ) ) { |
|
| 496 | + wp_cache_set( $results->id, $results, 'frm_form' ); |
|
| 497 | + $results->options = maybe_unserialize( $results->options ); |
|
| 498 | 498 | } |
| 499 | - return stripslashes_deep($results); |
|
| 499 | + return stripslashes_deep( $results ); |
|
| 500 | 500 | } |
| 501 | 501 | |
| 502 | 502 | /** |
@@ -525,7 +525,7 @@ discard block |
||
| 525 | 525 | $results = reset( $results ); |
| 526 | 526 | } |
| 527 | 527 | |
| 528 | - return stripslashes_deep($results); |
|
| 528 | + return stripslashes_deep( $results ); |
|
| 529 | 529 | } |
| 530 | 530 | |
| 531 | 531 | /** |
@@ -565,19 +565,19 @@ discard block |
||
| 565 | 565 | foreach ( $results as $row ) { |
| 566 | 566 | if ( 'trash' != $row->status ) { |
| 567 | 567 | if ( $row->is_template ) { |
| 568 | - $counts['template']++; |
|
| 568 | + $counts['template'] ++; |
|
| 569 | 569 | } else { |
| 570 | - $counts['published']++; |
|
| 570 | + $counts['published'] ++; |
|
| 571 | 571 | } |
| 572 | 572 | } else { |
| 573 | - $counts['trash']++; |
|
| 573 | + $counts['trash'] ++; |
|
| 574 | 574 | } |
| 575 | 575 | |
| 576 | 576 | if ( 'draft' == $row->status ) { |
| 577 | - $counts['draft']++; |
|
| 577 | + $counts['draft'] ++; |
|
| 578 | 578 | } |
| 579 | 579 | |
| 580 | - unset($row); |
|
| 580 | + unset( $row ); |
|
| 581 | 581 | } |
| 582 | 582 | |
| 583 | 583 | $counts = (object) $counts; |
@@ -603,7 +603,7 @@ discard block |
||
| 603 | 603 | public static function validate( $values ) { |
| 604 | 604 | $errors = array(); |
| 605 | 605 | |
| 606 | - return apply_filters('frm_validate_form', $errors, $values); |
|
| 606 | + return apply_filters( 'frm_validate_form', $errors, $values ); |
|
| 607 | 607 | } |
| 608 | 608 | |
| 609 | 609 | public static function get_params( $form = null ) { |
@@ -615,11 +615,11 @@ discard block |
||
| 615 | 615 | self::maybe_get_form( $form ); |
| 616 | 616 | } |
| 617 | 617 | |
| 618 | - if ( isset( $frm_vars['form_params'] ) && is_array( $frm_vars['form_params'] ) && isset( $frm_vars['form_params'][ $form->id ] ) ) { |
|
| 619 | - return $frm_vars['form_params'][ $form->id ]; |
|
| 618 | + if ( isset( $frm_vars['form_params'] ) && is_array( $frm_vars['form_params'] ) && isset( $frm_vars['form_params'][$form->id] ) ) { |
|
| 619 | + return $frm_vars['form_params'][$form->id]; |
|
| 620 | 620 | } |
| 621 | 621 | |
| 622 | - $action_var = isset($_REQUEST['frm_action']) ? 'frm_action' : 'action'; |
|
| 622 | + $action_var = isset( $_REQUEST['frm_action'] ) ? 'frm_action' : 'action'; |
|
| 623 | 623 | $action = apply_filters( 'frm_show_new_entry_page', FrmAppHelper::get_param( $action_var, 'new', 'get', 'sanitize_title' ), $form ); |
| 624 | 624 | |
| 625 | 625 | $default_values = array( |
@@ -637,15 +637,15 @@ discard block |
||
| 637 | 637 | //if there are two forms on the same page, make sure not to submit both |
| 638 | 638 | foreach ( $default_values as $var => $default ) { |
| 639 | 639 | if ( $var == 'action' ) { |
| 640 | - $values[ $var ] = FrmAppHelper::get_param( $action_var, $default, 'get', 'sanitize_title' ); |
|
| 640 | + $values[$var] = FrmAppHelper::get_param( $action_var, $default, 'get', 'sanitize_title' ); |
|
| 641 | 641 | } else { |
| 642 | - $values[ $var ] = FrmAppHelper::get_param( $var, $default ); |
|
| 642 | + $values[$var] = FrmAppHelper::get_param( $var, $default ); |
|
| 643 | 643 | } |
| 644 | 644 | unset( $var, $default ); |
| 645 | 645 | } |
| 646 | 646 | } else { |
| 647 | 647 | foreach ( $default_values as $var => $default ) { |
| 648 | - $values[ $var ] = $default; |
|
| 648 | + $values[$var] = $default; |
|
| 649 | 649 | unset( $var, $default ); |
| 650 | 650 | } |
| 651 | 651 | } |
@@ -660,7 +660,7 @@ discard block |
||
| 660 | 660 | public static function list_page_params() { |
| 661 | 661 | $values = array(); |
| 662 | 662 | foreach ( array( 'template' => 0, 'id' => '', 'paged' => 1, 'form' => '', 'search' => '', 'sort' => '', 'sdir' => '' ) as $var => $default ) { |
| 663 | - $values[ $var ] = FrmAppHelper::get_param( $var, $default ); |
|
| 663 | + $values[$var] = FrmAppHelper::get_param( $var, $default ); |
|
| 664 | 664 | } |
| 665 | 665 | |
| 666 | 666 | return $values; |
@@ -680,7 +680,7 @@ discard block |
||
| 680 | 680 | 'field_id' => '', 'search' => '', 'sort' => '', 'sdir' => '', 'fid' => '', |
| 681 | 681 | 'keep_post' => '', |
| 682 | 682 | ) as $var => $default ) { |
| 683 | - $values[ $var ] = FrmAppHelper::get_param( $var, $default ); |
|
| 683 | + $values[$var] = FrmAppHelper::get_param( $var, $default ); |
|
| 684 | 684 | } |
| 685 | 685 | |
| 686 | 686 | return $values; |
@@ -722,16 +722,16 @@ discard block |
||
| 722 | 722 | $small_form = new stdClass(); |
| 723 | 723 | foreach ( array( 'id', 'form_key', 'name' ) as $var ) { |
| 724 | 724 | $small_form->{$var} = $form->{$var}; |
| 725 | - unset($var); |
|
| 725 | + unset( $var ); |
|
| 726 | 726 | } |
| 727 | 727 | |
| 728 | 728 | $frm_vars['forms_loaded'][] = $small_form; |
| 729 | 729 | |
| 730 | - if ( $this_load && empty($global_load) ) { |
|
| 730 | + if ( $this_load && empty( $global_load ) ) { |
|
| 731 | 731 | $global_load = $frm_vars['load_css'] = true; |
| 732 | 732 | } |
| 733 | 733 | |
| 734 | - return ( ( ! isset($frm_vars['css_loaded']) || ! $frm_vars['css_loaded'] ) && $global_load ); |
|
| 734 | + return ( ( ! isset( $frm_vars['css_loaded'] ) || ! $frm_vars['css_loaded'] ) && $global_load ); |
|
| 735 | 735 | } |
| 736 | 736 | |
| 737 | 737 | public static function show_submit( $form ) { |