@@ -1,15 +1,15 @@ 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 | 14 | $new_values = array( |
| 15 | 15 | 'form_key' => FrmAppHelper::get_unique_key( $values['form_key'], $wpdb->prefix . 'frm_forms', 'form_key' ), |
@@ -34,52 +34,52 @@ discard block |
||
| 34 | 34 | $options = apply_filters( 'frm_form_options_before_update', $options, $values ); |
| 35 | 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, |
|
| 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 | 70 | 'created_at' => current_time( 'mysql', 1 ), |
| 71 | - 'is_template' => $template ? 1 : 0, |
|
| 72 | - ); |
|
| 71 | + 'is_template' => $template ? 1 : 0, |
|
| 72 | + ); |
|
| 73 | 73 | |
| 74 | - if ( $blog_id ) { |
|
| 75 | - $new_values['status'] = 'published'; |
|
| 74 | + if ( $blog_id ) { |
|
| 75 | + $new_values['status'] = 'published'; |
|
| 76 | 76 | $new_options = maybe_unserialize( $values->options ); |
| 77 | 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 | - } |
|
| 78 | + $new_options['copy'] = false; |
|
| 79 | + $new_values['options'] = $new_options; |
|
| 80 | + } else { |
|
| 81 | + $new_values['options'] = $values->options; |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | 84 | if ( is_array( $new_values['options'] ) ) { |
| 85 | 85 | $new_values['options'] = serialize( $new_values['options'] ); |
@@ -87,20 +87,20 @@ discard block |
||
| 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; |
|
| 94 | + $form_id = $wpdb->insert_id; |
|
| 95 | 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 | 106 | $new_opts = maybe_unserialize( $values['options'] ); |
@@ -112,48 +112,48 @@ discard block |
||
| 112 | 112 | |
| 113 | 113 | $new_opts = apply_filters( 'frm_after_duplicate_form_values', $new_opts, $form_id ); |
| 114 | 114 | |
| 115 | - if ( $new_opts != $values['options'] ) { |
|
| 116 | - global $wpdb; |
|
| 115 | + if ( $new_opts != $values['options'] ) { |
|
| 116 | + global $wpdb; |
|
| 117 | 117 | $wpdb->update( $wpdb->prefix . 'frm_forms', array( 'options' => maybe_serialize( $new_opts ) ), array( 'id' => $form_id ) ); |
| 118 | - } |
|
| 119 | - } |
|
| 118 | + } |
|
| 119 | + } |
|
| 120 | 120 | |
| 121 | - /** |
|
| 122 | - * @return int|boolean |
|
| 123 | - */ |
|
| 124 | - public static function update( $id, $values, $create_link = false ) { |
|
| 125 | - global $wpdb; |
|
| 121 | + /** |
|
| 122 | + * @return int|boolean |
|
| 123 | + */ |
|
| 124 | + public static function update( $id, $values, $create_link = false ) { |
|
| 125 | + global $wpdb; |
|
| 126 | 126 | |
| 127 | - if ( ! isset( $values['status'] ) && ( $create_link || isset( $values['options'] ) || isset( $values['item_meta'] ) || isset( $values['field_options'] ) ) ) { |
|
| 128 | - $values['status'] = 'published'; |
|
| 129 | - } |
|
| 127 | + if ( ! isset( $values['status'] ) && ( $create_link || isset( $values['options'] ) || isset( $values['item_meta'] ) || isset( $values['field_options'] ) ) ) { |
|
| 128 | + $values['status'] = 'published'; |
|
| 129 | + } |
|
| 130 | 130 | |
| 131 | 131 | if ( isset( $values['form_key'] ) ) { |
| 132 | 132 | $values['form_key'] = FrmAppHelper::get_unique_key( $values['form_key'], $wpdb->prefix . 'frm_forms', 'form_key', $id ); |
| 133 | - } |
|
| 133 | + } |
|
| 134 | 134 | |
| 135 | 135 | $form_fields = array( 'form_key', 'name', 'description', 'status', 'parent_form_id' ); |
| 136 | 136 | |
| 137 | 137 | $new_values = self::set_update_options( array(), $values ); |
| 138 | 138 | |
| 139 | - foreach ( $values as $value_key => $value ) { |
|
| 139 | + foreach ( $values as $value_key => $value ) { |
|
| 140 | 140 | if ( $value_key && in_array( $value_key, $form_fields ) ) { |
| 141 | 141 | $new_values[ $value_key ] = $value; |
| 142 | - } |
|
| 143 | - } |
|
| 142 | + } |
|
| 143 | + } |
|
| 144 | 144 | |
| 145 | - if ( isset( $values['new_status'] ) && ! empty( $values['new_status'] ) ) { |
|
| 146 | - $new_values['status'] = $values['new_status']; |
|
| 147 | - } |
|
| 145 | + if ( isset( $values['new_status'] ) && ! empty( $values['new_status'] ) ) { |
|
| 146 | + $new_values['status'] = $values['new_status']; |
|
| 147 | + } |
|
| 148 | 148 | |
| 149 | - if ( ! empty( $new_values ) ) { |
|
| 149 | + if ( ! empty( $new_values ) ) { |
|
| 150 | 150 | $query_results = $wpdb->update( $wpdb->prefix . 'frm_forms', $new_values, array( 'id' => $id ) ); |
| 151 | - if ( $query_results ) { |
|
| 151 | + if ( $query_results ) { |
|
| 152 | 152 | self::clear_form_cache(); |
| 153 | - } |
|
| 154 | - } else { |
|
| 155 | - $query_results = true; |
|
| 156 | - } |
|
| 153 | + } |
|
| 154 | + } else { |
|
| 155 | + $query_results = true; |
|
| 156 | + } |
|
| 157 | 157 | unset( $new_values ); |
| 158 | 158 | |
| 159 | 159 | $values = self::update_fields( $id, $values ); |
@@ -161,16 +161,16 @@ discard block |
||
| 161 | 161 | do_action( 'frm_update_form', $id, $values ); |
| 162 | 162 | do_action( 'frm_update_form_' . $id, $values ); |
| 163 | 163 | |
| 164 | - return $query_results; |
|
| 165 | - } |
|
| 164 | + return $query_results; |
|
| 165 | + } |
|
| 166 | 166 | |
| 167 | - /** |
|
| 168 | - * @return array |
|
| 169 | - */ |
|
| 167 | + /** |
|
| 168 | + * @return array |
|
| 169 | + */ |
|
| 170 | 170 | public static function set_update_options( $new_values, $values ) { |
| 171 | 171 | if ( ! isset( $values['options'] ) ) { |
| 172 | - return $new_values; |
|
| 173 | - } |
|
| 172 | + return $new_values; |
|
| 173 | + } |
|
| 174 | 174 | |
| 175 | 175 | $options = isset( $values['options'] ) ? (array) $values['options'] : array(); |
| 176 | 176 | FrmFormsHelper::fill_form_options( $options, $values ); |
@@ -184,17 +184,17 @@ discard block |
||
| 184 | 184 | $new_values['options'] = serialize( $options ); |
| 185 | 185 | |
| 186 | 186 | return $new_values; |
| 187 | - } |
|
| 187 | + } |
|
| 188 | 188 | |
| 189 | 189 | |
| 190 | - /** |
|
| 191 | - * @return array |
|
| 192 | - */ |
|
| 190 | + /** |
|
| 191 | + * @return array |
|
| 192 | + */ |
|
| 193 | 193 | public static function update_fields( $id, $values ) { |
| 194 | 194 | |
| 195 | 195 | if ( ! isset( $values['item_meta'] ) && ! isset( $values['field_options'] ) ) { |
| 196 | - return $values; |
|
| 197 | - } |
|
| 196 | + return $values; |
|
| 197 | + } |
|
| 198 | 198 | |
| 199 | 199 | $all_fields = FrmField::get_all_for_form( $id ); |
| 200 | 200 | if ( empty( $all_fields ) ) { |
@@ -205,26 +205,26 @@ discard block |
||
| 205 | 205 | $values['item_meta'] = array(); |
| 206 | 206 | } |
| 207 | 207 | |
| 208 | - $field_array = array(); |
|
| 209 | - $existing_keys = array_keys( $values['item_meta'] ); |
|
| 210 | - foreach ( $all_fields as $fid ) { |
|
| 208 | + $field_array = array(); |
|
| 209 | + $existing_keys = array_keys( $values['item_meta'] ); |
|
| 210 | + foreach ( $all_fields as $fid ) { |
|
| 211 | 211 | if ( ! in_array( $fid->id, $existing_keys ) && ( isset( $values['frm_fields_submitted'] ) && in_array( $fid->id, $values['frm_fields_submitted'] ) ) || isset( $values['options'] ) ) { |
| 212 | 212 | $values['item_meta'][ $fid->id ] = ''; |
| 213 | - } |
|
| 213 | + } |
|
| 214 | 214 | $field_array[ $fid->id ] = $fid; |
| 215 | - } |
|
| 215 | + } |
|
| 216 | 216 | unset( $all_fields ); |
| 217 | 217 | |
| 218 | - foreach ( $values['item_meta'] as $field_id => $default_value ) { |
|
| 218 | + foreach ( $values['item_meta'] as $field_id => $default_value ) { |
|
| 219 | 219 | if ( isset( $field_array[ $field_id ] ) ) { |
| 220 | 220 | $field = $field_array[ $field_id ]; |
| 221 | - } else { |
|
| 221 | + } else { |
|
| 222 | 222 | $field = FrmField::getOne( $field_id ); |
| 223 | - } |
|
| 223 | + } |
|
| 224 | 224 | |
| 225 | - if ( ! $field ) { |
|
| 226 | - continue; |
|
| 227 | - } |
|
| 225 | + if ( ! $field ) { |
|
| 226 | + continue; |
|
| 227 | + } |
|
| 228 | 228 | |
| 229 | 229 | $is_settings_page = ( isset( $values['options'] ) || isset( $values['field_options'][ 'custom_html_' . $field_id ] ) ); |
| 230 | 230 | if ( $is_settings_page ) { |
@@ -243,7 +243,7 @@ discard block |
||
| 243 | 243 | foreach ( $update_options as $opt => $default ) { |
| 244 | 244 | $field->field_options[ $opt ] = isset( $values['field_options'][ $opt . '_' . $field_id ] ) ? $values['field_options'][ $opt . '_' . $field_id ] : $default; |
| 245 | 245 | self::sanitize_field_opt( $opt, $field->field_options[ $opt ] ); |
| 246 | - } |
|
| 246 | + } |
|
| 247 | 247 | |
| 248 | 248 | $field->field_options = apply_filters( 'frm_update_field_options', $field->field_options, $field, $values ); |
| 249 | 249 | $default_value = maybe_serialize( $values['item_meta'][ $field_id ] ); |
@@ -258,11 +258,11 @@ discard block |
||
| 258 | 258 | FrmField::update( $field_id, $new_field ); |
| 259 | 259 | |
| 260 | 260 | FrmField::delete_form_transient( $field->form_id ); |
| 261 | - } |
|
| 261 | + } |
|
| 262 | 262 | self::clear_form_cache(); |
| 263 | 263 | |
| 264 | - return $values; |
|
| 265 | - } |
|
| 264 | + return $values; |
|
| 265 | + } |
|
| 266 | 266 | |
| 267 | 267 | private static function sanitize_field_opt( $opt, &$value ) { |
| 268 | 268 | if ( is_string( $value ) ) { |
@@ -310,21 +310,21 @@ discard block |
||
| 310 | 310 | } |
| 311 | 311 | } |
| 312 | 312 | |
| 313 | - /** |
|
| 314 | - * @param string $status |
|
| 315 | - * @return int|boolean |
|
| 316 | - */ |
|
| 313 | + /** |
|
| 314 | + * @param string $status |
|
| 315 | + * @return int|boolean |
|
| 316 | + */ |
|
| 317 | 317 | public static function set_status( $id, $status ) { |
| 318 | - if ( 'trash' == $status ) { |
|
| 318 | + if ( 'trash' == $status ) { |
|
| 319 | 319 | return self::trash( $id ); |
| 320 | - } |
|
| 320 | + } |
|
| 321 | 321 | |
| 322 | 322 | $statuses = array( 'published', 'draft', 'trash' ); |
| 323 | - if ( ! in_array( $status, $statuses ) ) { |
|
| 324 | - return false; |
|
| 325 | - } |
|
| 323 | + if ( ! in_array( $status, $statuses ) ) { |
|
| 324 | + return false; |
|
| 325 | + } |
|
| 326 | 326 | |
| 327 | - global $wpdb; |
|
| 327 | + global $wpdb; |
|
| 328 | 328 | |
| 329 | 329 | if ( is_array( $id ) ) { |
| 330 | 330 | $where = array( |
@@ -336,33 +336,33 @@ discard block |
||
| 336 | 336 | array_unshift( $where['values'], $status ); |
| 337 | 337 | |
| 338 | 338 | $query_results = $wpdb->query( $wpdb->prepare( 'UPDATE ' . $wpdb->prefix . 'frm_forms SET status = %s ' . $where['where'], $where['values'] ) ); // WPCS: unprepared SQL ok. |
| 339 | - } else { |
|
| 339 | + } else { |
|
| 340 | 340 | $query_results = $wpdb->update( $wpdb->prefix . 'frm_forms', array( 'status' => $status ), array( 'id' => $id ) ); |
| 341 | 341 | $wpdb->update( $wpdb->prefix . 'frm_forms', array( 'status' => $status ), array( 'parent_form_id' => $id ) ); |
| 342 | - } |
|
| 342 | + } |
|
| 343 | 343 | |
| 344 | - if ( $query_results ) { |
|
| 344 | + if ( $query_results ) { |
|
| 345 | 345 | self::clear_form_cache(); |
| 346 | - } |
|
| 346 | + } |
|
| 347 | 347 | |
| 348 | - return $query_results; |
|
| 349 | - } |
|
| 348 | + return $query_results; |
|
| 349 | + } |
|
| 350 | 350 | |
| 351 | - /** |
|
| 352 | - * @return int|boolean |
|
| 353 | - */ |
|
| 351 | + /** |
|
| 352 | + * @return int|boolean |
|
| 353 | + */ |
|
| 354 | 354 | public static function trash( $id ) { |
| 355 | - if ( ! EMPTY_TRASH_DAYS ) { |
|
| 356 | - return self::destroy( $id ); |
|
| 357 | - } |
|
| 355 | + if ( ! EMPTY_TRASH_DAYS ) { |
|
| 356 | + return self::destroy( $id ); |
|
| 357 | + } |
|
| 358 | 358 | |
| 359 | 359 | $form = self::getOne( $id ); |
| 360 | - if ( ! $form ) { |
|
| 361 | - return false; |
|
| 362 | - } |
|
| 360 | + if ( ! $form ) { |
|
| 361 | + return false; |
|
| 362 | + } |
|
| 363 | 363 | |
| 364 | - $options = $form->options; |
|
| 365 | - $options['trash_time'] = time(); |
|
| 364 | + $options = $form->options; |
|
| 365 | + $options['trash_time'] = time(); |
|
| 366 | 366 | |
| 367 | 367 | global $wpdb; |
| 368 | 368 | $query_results = $wpdb->update( |
@@ -387,39 +387,39 @@ discard block |
||
| 387 | 387 | ) |
| 388 | 388 | ); |
| 389 | 389 | |
| 390 | - if ( $query_results ) { |
|
| 390 | + if ( $query_results ) { |
|
| 391 | 391 | self::clear_form_cache(); |
| 392 | - } |
|
| 392 | + } |
|
| 393 | 393 | |
| 394 | - return $query_results; |
|
| 395 | - } |
|
| 394 | + return $query_results; |
|
| 395 | + } |
|
| 396 | 396 | |
| 397 | - /** |
|
| 398 | - * @return int|boolean |
|
| 399 | - */ |
|
| 397 | + /** |
|
| 398 | + * @return int|boolean |
|
| 399 | + */ |
|
| 400 | 400 | public static function destroy( $id ) { |
| 401 | - global $wpdb; |
|
| 401 | + global $wpdb; |
|
| 402 | 402 | |
| 403 | 403 | $form = self::getOne( $id ); |
| 404 | - if ( ! $form ) { |
|
| 405 | - return false; |
|
| 406 | - } |
|
| 404 | + if ( ! $form ) { |
|
| 405 | + return false; |
|
| 406 | + } |
|
| 407 | 407 | $id = $form->id; |
| 408 | 408 | |
| 409 | - // Disconnect the entries from this form |
|
| 409 | + // Disconnect the entries from this form |
|
| 410 | 410 | $entries = FrmDb::get_col( $wpdb->prefix . 'frm_items', array( 'form_id' => $id ) ); |
| 411 | 411 | foreach ( $entries as $entry_id ) { |
| 412 | 412 | FrmEntry::destroy( $entry_id ); |
| 413 | 413 | unset( $entry_id ); |
| 414 | 414 | } |
| 415 | 415 | |
| 416 | - // Disconnect the fields from this form |
|
| 416 | + // Disconnect the fields from this form |
|
| 417 | 417 | $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 ) ); |
| 418 | 418 | |
| 419 | 419 | $query_results = $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_forms WHERE id=%d OR parent_form_id=%d', $id, $id ) ); |
| 420 | - if ( $query_results ) { |
|
| 421 | - // Delete all form actions linked to this form |
|
| 422 | - $action_control = FrmFormActionsController::get_form_actions( 'email' ); |
|
| 420 | + if ( $query_results ) { |
|
| 421 | + // Delete all form actions linked to this form |
|
| 422 | + $action_control = FrmFormActionsController::get_form_actions( 'email' ); |
|
| 423 | 423 | $action_control->destroy( $id, 'all' ); |
| 424 | 424 | |
| 425 | 425 | // Clear form caching |
@@ -427,10 +427,10 @@ discard block |
||
| 427 | 427 | |
| 428 | 428 | do_action( 'frm_destroy_form', $id ); |
| 429 | 429 | do_action( 'frm_destroy_form_' . $id ); |
| 430 | - } |
|
| 430 | + } |
|
| 431 | 431 | |
| 432 | - return $query_results; |
|
| 433 | - } |
|
| 432 | + return $query_results; |
|
| 433 | + } |
|
| 434 | 434 | |
| 435 | 435 | /** |
| 436 | 436 | * Delete trashed forms based on how long they have been trashed |
@@ -462,60 +462,60 @@ discard block |
||
| 462 | 462 | return $count; |
| 463 | 463 | } |
| 464 | 464 | |
| 465 | - /** |
|
| 466 | - * @return string form name |
|
| 467 | - */ |
|
| 468 | - public static function getName( $id ) { |
|
| 465 | + /** |
|
| 466 | + * @return string form name |
|
| 467 | + */ |
|
| 468 | + public static function getName( $id ) { |
|
| 469 | 469 | $form = FrmDb::check_cache( $id, 'frm_form' ); |
| 470 | - if ( $form ) { |
|
| 470 | + if ( $form ) { |
|
| 471 | 471 | $r = stripslashes( $form->name ); |
| 472 | - return $r; |
|
| 473 | - } |
|
| 472 | + return $r; |
|
| 473 | + } |
|
| 474 | 474 | |
| 475 | - $query_key = is_numeric( $id ) ? 'id' : 'form_key'; |
|
| 476 | - $r = FrmDb::get_var( 'frm_forms', array( $query_key => $id ), 'name' ); |
|
| 475 | + $query_key = is_numeric( $id ) ? 'id' : 'form_key'; |
|
| 476 | + $r = FrmDb::get_var( 'frm_forms', array( $query_key => $id ), 'name' ); |
|
| 477 | 477 | $r = stripslashes( $r ); |
| 478 | 478 | |
| 479 | - return $r; |
|
| 480 | - } |
|
| 479 | + return $r; |
|
| 480 | + } |
|
| 481 | 481 | |
| 482 | - /** |
|
| 482 | + /** |
|
| 483 | 483 | * @since 3.0 |
| 484 | - * @param string $key |
|
| 485 | - * @return int form id |
|
| 486 | - */ |
|
| 484 | + * @param string $key |
|
| 485 | + * @return int form id |
|
| 486 | + */ |
|
| 487 | 487 | public static function get_id_by_key( $key ) { |
| 488 | 488 | return (int) FrmDb::get_var( 'frm_forms', array( 'form_key' => sanitize_title( $key ) ) ); |
| 489 | - } |
|
| 489 | + } |
|
| 490 | 490 | |
| 491 | 491 | /** |
| 492 | 492 | * @deprecated 3.0 |
| 493 | 493 | * @codeCoverageIgnore |
| 494 | 494 | * |
| 495 | - * @param string $key |
|
| 496 | - * @return int form id |
|
| 497 | - */ |
|
| 495 | + * @param string $key |
|
| 496 | + * @return int form id |
|
| 497 | + */ |
|
| 498 | 498 | public static function getIdByKey( $key ) { |
| 499 | 499 | _deprecated_function( __METHOD__, '3.0', 'FrmForm::get_id_by_key' ); |
| 500 | 500 | return self::get_id_by_key( $key ); |
| 501 | - } |
|
| 501 | + } |
|
| 502 | 502 | |
| 503 | - /** |
|
| 503 | + /** |
|
| 504 | 504 | * @since 3.0 |
| 505 | - * @param int $id |
|
| 506 | - * @return string form key |
|
| 507 | - */ |
|
| 505 | + * @param int $id |
|
| 506 | + * @return string form key |
|
| 507 | + */ |
|
| 508 | 508 | public static function get_key_by_id( $id ) { |
| 509 | - $id = (int) $id; |
|
| 509 | + $id = (int) $id; |
|
| 510 | 510 | $cache = FrmDb::check_cache( $id, 'frm_form' ); |
| 511 | - if ( $cache ) { |
|
| 512 | - return $cache->form_key; |
|
| 513 | - } |
|
| 511 | + if ( $cache ) { |
|
| 512 | + return $cache->form_key; |
|
| 513 | + } |
|
| 514 | 514 | |
| 515 | - $key = FrmDb::get_var( 'frm_forms', array( 'id' => $id ), 'form_key' ); |
|
| 515 | + $key = FrmDb::get_var( 'frm_forms', array( 'id' => $id ), 'form_key' ); |
|
| 516 | 516 | |
| 517 | - return $key; |
|
| 518 | - } |
|
| 517 | + return $key; |
|
| 518 | + } |
|
| 519 | 519 | |
| 520 | 520 | /** |
| 521 | 521 | * @deprecated 3.0 |
@@ -537,47 +537,47 @@ discard block |
||
| 537 | 537 | } |
| 538 | 538 | } |
| 539 | 539 | |
| 540 | - /** |
|
| 541 | - * @return object form |
|
| 542 | - */ |
|
| 543 | - public static function getOne( $id, $blog_id = false ) { |
|
| 544 | - global $wpdb; |
|
| 540 | + /** |
|
| 541 | + * @return object form |
|
| 542 | + */ |
|
| 543 | + public static function getOne( $id, $blog_id = false ) { |
|
| 544 | + global $wpdb; |
|
| 545 | 545 | |
| 546 | - if ( $blog_id && is_multisite() ) { |
|
| 547 | - global $wpmuBaseTablePrefix; |
|
| 546 | + if ( $blog_id && is_multisite() ) { |
|
| 547 | + global $wpmuBaseTablePrefix; |
|
| 548 | 548 | $prefix = $wpmuBaseTablePrefix ? $wpmuBaseTablePrefix . $blog_id . '_' : $wpdb->get_blog_prefix( $blog_id ); |
| 549 | 549 | |
| 550 | 550 | $table_name = $prefix . 'frm_forms'; |
| 551 | - } else { |
|
| 551 | + } else { |
|
| 552 | 552 | $table_name = $wpdb->prefix . 'frm_forms'; |
| 553 | 553 | $cache = wp_cache_get( $id, 'frm_form' ); |
| 554 | - if ( $cache ) { |
|
| 554 | + if ( $cache ) { |
|
| 555 | 555 | if ( isset( $cache->options ) ) { |
| 556 | 556 | $cache->options = maybe_unserialize( $cache->options ); |
| 557 | - } |
|
| 557 | + } |
|
| 558 | 558 | |
| 559 | 559 | return stripslashes_deep( $cache ); |
| 560 | - } |
|
| 561 | - } |
|
| 560 | + } |
|
| 561 | + } |
|
| 562 | 562 | |
| 563 | 563 | if ( is_numeric( $id ) ) { |
| 564 | - $where = array( 'id' => $id ); |
|
| 565 | - } else { |
|
| 566 | - $where = array( 'form_key' => $id ); |
|
| 567 | - } |
|
| 564 | + $where = array( 'id' => $id ); |
|
| 565 | + } else { |
|
| 566 | + $where = array( 'form_key' => $id ); |
|
| 567 | + } |
|
| 568 | 568 | |
| 569 | - $results = FrmDb::get_row( $table_name, $where ); |
|
| 569 | + $results = FrmDb::get_row( $table_name, $where ); |
|
| 570 | 570 | |
| 571 | 571 | if ( isset( $results->options ) ) { |
| 572 | 572 | FrmDb::set_cache( $results->id, $results, 'frm_form' ); |
| 573 | 573 | $results->options = maybe_unserialize( $results->options ); |
| 574 | - } |
|
| 574 | + } |
|
| 575 | 575 | return stripslashes_deep( $results ); |
| 576 | - } |
|
| 576 | + } |
|
| 577 | 577 | |
| 578 | - /** |
|
| 579 | - * @return object|array of objects |
|
| 580 | - */ |
|
| 578 | + /** |
|
| 579 | + * @return object|array of objects |
|
| 580 | + */ |
|
| 581 | 581 | public static function getAll( $where = array(), $order_by = '', $limit = '' ) { |
| 582 | 582 | if ( is_array( $where ) && ! empty( $where ) ) { |
| 583 | 583 | if ( isset( $where['is_template'] ) && $where['is_template'] && ! isset( $where['status'] ) ) { |
@@ -610,7 +610,7 @@ discard block |
||
| 610 | 610 | } |
| 611 | 611 | |
| 612 | 612 | return stripslashes_deep( $results ); |
| 613 | - } |
|
| 613 | + } |
|
| 614 | 614 | |
| 615 | 615 | /** |
| 616 | 616 | * Get all published forms |
@@ -628,18 +628,18 @@ discard block |
||
| 628 | 628 | return $forms; |
| 629 | 629 | } |
| 630 | 630 | |
| 631 | - /** |
|
| 632 | - * @return int count of forms |
|
| 633 | - */ |
|
| 634 | - public static function get_count() { |
|
| 635 | - global $wpdb; |
|
| 631 | + /** |
|
| 632 | + * @return int count of forms |
|
| 633 | + */ |
|
| 634 | + public static function get_count() { |
|
| 635 | + global $wpdb; |
|
| 636 | 636 | |
| 637 | - $cache_key = 'frm_form_counts'; |
|
| 637 | + $cache_key = 'frm_form_counts'; |
|
| 638 | 638 | |
| 639 | - $counts = wp_cache_get( $cache_key, 'frm_form' ); |
|
| 640 | - if ( false !== $counts ) { |
|
| 641 | - return $counts; |
|
| 642 | - } |
|
| 639 | + $counts = wp_cache_get( $cache_key, 'frm_form' ); |
|
| 640 | + if ( false !== $counts ) { |
|
| 641 | + return $counts; |
|
| 642 | + } |
|
| 643 | 643 | |
| 644 | 644 | $results = (array) FrmDb::get_results( 'frm_forms', array( |
| 645 | 645 | 'or' => 1, |
@@ -648,31 +648,31 @@ discard block |
||
| 648 | 648 | ), 'status, is_template' ); |
| 649 | 649 | |
| 650 | 650 | $statuses = array( 'published', 'draft', 'template', 'trash' ); |
| 651 | - $counts = array_fill_keys( $statuses, 0 ); |
|
| 651 | + $counts = array_fill_keys( $statuses, 0 ); |
|
| 652 | 652 | |
| 653 | - foreach ( $results as $row ) { |
|
| 654 | - if ( 'trash' != $row->status ) { |
|
| 655 | - if ( $row->is_template ) { |
|
| 653 | + foreach ( $results as $row ) { |
|
| 654 | + if ( 'trash' != $row->status ) { |
|
| 655 | + if ( $row->is_template ) { |
|
| 656 | 656 | $counts['template']++; |
| 657 | - } else { |
|
| 657 | + } else { |
|
| 658 | 658 | $counts['published']++; |
| 659 | - } |
|
| 660 | - } else { |
|
| 659 | + } |
|
| 660 | + } else { |
|
| 661 | 661 | $counts['trash']++; |
| 662 | - } |
|
| 662 | + } |
|
| 663 | 663 | |
| 664 | - if ( 'draft' == $row->status ) { |
|
| 664 | + if ( 'draft' == $row->status ) { |
|
| 665 | 665 | $counts['draft']++; |
| 666 | - } |
|
| 666 | + } |
|
| 667 | 667 | |
| 668 | 668 | unset( $row ); |
| 669 | - } |
|
| 669 | + } |
|
| 670 | 670 | |
| 671 | - $counts = (object) $counts; |
|
| 671 | + $counts = (object) $counts; |
|
| 672 | 672 | FrmDb::set_cache( $cache_key, $counts, 'frm_form' ); |
| 673 | 673 | |
| 674 | - return $counts; |
|
| 675 | - } |
|
| 674 | + return $counts; |
|
| 675 | + } |
|
| 676 | 676 | |
| 677 | 677 | /** |
| 678 | 678 | * Clear form caching |
@@ -685,14 +685,14 @@ discard block |
||
| 685 | 685 | FrmDb::cache_delete_group( 'frm_form' ); |
| 686 | 686 | } |
| 687 | 687 | |
| 688 | - /** |
|
| 689 | - * @return array of errors |
|
| 690 | - */ |
|
| 688 | + /** |
|
| 689 | + * @return array of errors |
|
| 690 | + */ |
|
| 691 | 691 | public static function validate( $values ) { |
| 692 | - $errors = array(); |
|
| 692 | + $errors = array(); |
|
| 693 | 693 | |
| 694 | 694 | return apply_filters( 'frm_validate_form', $errors, $values ); |
| 695 | - } |
|
| 695 | + } |
|
| 696 | 696 | |
| 697 | 697 | public static function get_params( $form = null ) { |
| 698 | 698 | global $frm_vars; |
@@ -138,7 +138,7 @@ discard block |
||
| 138 | 138 | |
| 139 | 139 | foreach ( $values as $value_key => $value ) { |
| 140 | 140 | if ( $value_key && in_array( $value_key, $form_fields ) ) { |
| 141 | - $new_values[ $value_key ] = $value; |
|
| 141 | + $new_values[$value_key] = $value; |
|
| 142 | 142 | } |
| 143 | 143 | } |
| 144 | 144 | |
@@ -209,15 +209,15 @@ discard block |
||
| 209 | 209 | $existing_keys = array_keys( $values['item_meta'] ); |
| 210 | 210 | foreach ( $all_fields as $fid ) { |
| 211 | 211 | if ( ! in_array( $fid->id, $existing_keys ) && ( isset( $values['frm_fields_submitted'] ) && in_array( $fid->id, $values['frm_fields_submitted'] ) ) || isset( $values['options'] ) ) { |
| 212 | - $values['item_meta'][ $fid->id ] = ''; |
|
| 212 | + $values['item_meta'][$fid->id] = ''; |
|
| 213 | 213 | } |
| 214 | - $field_array[ $fid->id ] = $fid; |
|
| 214 | + $field_array[$fid->id] = $fid; |
|
| 215 | 215 | } |
| 216 | 216 | unset( $all_fields ); |
| 217 | 217 | |
| 218 | 218 | foreach ( $values['item_meta'] as $field_id => $default_value ) { |
| 219 | - if ( isset( $field_array[ $field_id ] ) ) { |
|
| 220 | - $field = $field_array[ $field_id ]; |
|
| 219 | + if ( isset( $field_array[$field_id] ) ) { |
|
| 220 | + $field = $field_array[$field_id]; |
|
| 221 | 221 | } else { |
| 222 | 222 | $field = FrmField::getOne( $field_id ); |
| 223 | 223 | } |
@@ -226,7 +226,7 @@ discard block |
||
| 226 | 226 | continue; |
| 227 | 227 | } |
| 228 | 228 | |
| 229 | - $is_settings_page = ( isset( $values['options'] ) || isset( $values['field_options'][ 'custom_html_' . $field_id ] ) ); |
|
| 229 | + $is_settings_page = ( isset( $values['options'] ) || isset( $values['field_options']['custom_html_' . $field_id] ) ); |
|
| 230 | 230 | if ( $is_settings_page ) { |
| 231 | 231 | self::get_settings_page_html( $values, $field ); |
| 232 | 232 | |
@@ -241,12 +241,12 @@ discard block |
||
| 241 | 241 | $update_options = apply_filters( 'frm_field_options_to_update', $update_options ); |
| 242 | 242 | |
| 243 | 243 | foreach ( $update_options as $opt => $default ) { |
| 244 | - $field->field_options[ $opt ] = isset( $values['field_options'][ $opt . '_' . $field_id ] ) ? $values['field_options'][ $opt . '_' . $field_id ] : $default; |
|
| 245 | - self::sanitize_field_opt( $opt, $field->field_options[ $opt ] ); |
|
| 244 | + $field->field_options[$opt] = isset( $values['field_options'][$opt . '_' . $field_id] ) ? $values['field_options'][$opt . '_' . $field_id] : $default; |
|
| 245 | + self::sanitize_field_opt( $opt, $field->field_options[$opt] ); |
|
| 246 | 246 | } |
| 247 | 247 | |
| 248 | 248 | $field->field_options = apply_filters( 'frm_update_field_options', $field->field_options, $field, $values ); |
| 249 | - $default_value = maybe_serialize( $values['item_meta'][ $field_id ] ); |
|
| 249 | + $default_value = maybe_serialize( $values['item_meta'][$field_id] ); |
|
| 250 | 250 | |
| 251 | 251 | $new_field = array( |
| 252 | 252 | 'field_options' => $field->field_options, |
@@ -279,10 +279,10 @@ discard block |
||
| 279 | 279 | * updating the settings page |
| 280 | 280 | */ |
| 281 | 281 | private static function get_settings_page_html( $values, &$field ) { |
| 282 | - if ( isset( $values['field_options'][ 'custom_html_' . $field->id ] ) ) { |
|
| 282 | + if ( isset( $values['field_options']['custom_html_' . $field->id] ) ) { |
|
| 283 | 283 | $prev_opts = array(); |
| 284 | 284 | $fallback_html = isset( $field->field_options['custom_html'] ) ? $field->field_options['custom_html'] : FrmFieldsHelper::get_default_html( $field->type ); |
| 285 | - $field->field_options['custom_html'] = isset( $values['field_options'][ 'custom_html_' . $field->id ] ) ? $values['field_options'][ 'custom_html_' . $field->id ] : $fallback_html; |
|
| 285 | + $field->field_options['custom_html'] = isset( $values['field_options']['custom_html_' . $field->id] ) ? $values['field_options']['custom_html_' . $field->id] : $fallback_html; |
|
| 286 | 286 | } elseif ( $field->type == 'hidden' || $field->type == 'user_id' ) { |
| 287 | 287 | $prev_opts = $field->field_options; |
| 288 | 288 | } |
@@ -306,7 +306,7 @@ discard block |
||
| 306 | 306 | ); |
| 307 | 307 | foreach ( $field_cols as $col => $default ) { |
| 308 | 308 | $default = ( $default === '' ) ? $field->{$col} : $default; |
| 309 | - $new_field[ $col ] = isset( $values['field_options'][ $col . '_' . $field->id ] ) ? $values['field_options'][ $col . '_' . $field->id ] : $default; |
|
| 309 | + $new_field[$col] = isset( $values['field_options'][$col . '_' . $field->id] ) ? $values['field_options'][$col . '_' . $field->id] : $default; |
|
| 310 | 310 | } |
| 311 | 311 | } |
| 312 | 312 | |
@@ -319,7 +319,7 @@ discard block |
||
| 319 | 319 | return self::trash( $id ); |
| 320 | 320 | } |
| 321 | 321 | |
| 322 | - $statuses = array( 'published', 'draft', 'trash' ); |
|
| 322 | + $statuses = array( 'published', 'draft', 'trash' ); |
|
| 323 | 323 | if ( ! in_array( $status, $statuses ) ) { |
| 324 | 324 | return false; |
| 325 | 325 | } |
@@ -454,7 +454,7 @@ discard block |
||
| 454 | 454 | $form->options = maybe_unserialize( $form->options ); |
| 455 | 455 | if ( ! isset( $form->options['trash_time'] ) || $form->options['trash_time'] < $delete_timestamp ) { |
| 456 | 456 | self::destroy( $form->id ); |
| 457 | - $count++; |
|
| 457 | + $count ++; |
|
| 458 | 458 | } |
| 459 | 459 | |
| 460 | 460 | unset( $form ); |
@@ -653,16 +653,16 @@ discard block |
||
| 653 | 653 | foreach ( $results as $row ) { |
| 654 | 654 | if ( 'trash' != $row->status ) { |
| 655 | 655 | if ( $row->is_template ) { |
| 656 | - $counts['template']++; |
|
| 656 | + $counts['template'] ++; |
|
| 657 | 657 | } else { |
| 658 | - $counts['published']++; |
|
| 658 | + $counts['published'] ++; |
|
| 659 | 659 | } |
| 660 | 660 | } else { |
| 661 | - $counts['trash']++; |
|
| 661 | + $counts['trash'] ++; |
|
| 662 | 662 | } |
| 663 | 663 | |
| 664 | 664 | if ( 'draft' == $row->status ) { |
| 665 | - $counts['draft']++; |
|
| 665 | + $counts['draft'] ++; |
|
| 666 | 666 | } |
| 667 | 667 | |
| 668 | 668 | unset( $row ); |
@@ -703,8 +703,8 @@ discard block |
||
| 703 | 703 | self::maybe_get_form( $form ); |
| 704 | 704 | } |
| 705 | 705 | |
| 706 | - if ( isset( $frm_vars['form_params'] ) && is_array( $frm_vars['form_params'] ) && isset( $frm_vars['form_params'][ $form->id ] ) ) { |
|
| 707 | - return $frm_vars['form_params'][ $form->id ]; |
|
| 706 | + if ( isset( $frm_vars['form_params'] ) && is_array( $frm_vars['form_params'] ) && isset( $frm_vars['form_params'][$form->id] ) ) { |
|
| 707 | + return $frm_vars['form_params'][$form->id]; |
|
| 708 | 708 | } |
| 709 | 709 | |
| 710 | 710 | $action_var = isset( $_REQUEST['frm_action'] ) ? 'frm_action' : 'action'; // WPCS: CSRF ok. |
@@ -733,15 +733,15 @@ discard block |
||
| 733 | 733 | //if there are two forms on the same page, make sure not to submit both |
| 734 | 734 | foreach ( $default_values as $var => $default ) { |
| 735 | 735 | if ( $var == 'action' ) { |
| 736 | - $values[ $var ] = FrmAppHelper::get_param( $action_var, $default, 'get', 'sanitize_title' ); |
|
| 736 | + $values[$var] = FrmAppHelper::get_param( $action_var, $default, 'get', 'sanitize_title' ); |
|
| 737 | 737 | } else { |
| 738 | - $values[ $var ] = FrmAppHelper::get_param( $var, $default, 'get', 'sanitize_text_field' ); |
|
| 738 | + $values[$var] = FrmAppHelper::get_param( $var, $default, 'get', 'sanitize_text_field' ); |
|
| 739 | 739 | } |
| 740 | 740 | unset( $var, $default ); |
| 741 | 741 | } |
| 742 | 742 | } else { |
| 743 | 743 | foreach ( $default_values as $var => $default ) { |
| 744 | - $values[ $var ] = $default; |
|
| 744 | + $values[$var] = $default; |
|
| 745 | 745 | unset( $var, $default ); |
| 746 | 746 | } |
| 747 | 747 | } |
@@ -765,7 +765,7 @@ discard block |
||
| 765 | 765 | 'sdir' => '', |
| 766 | 766 | ); |
| 767 | 767 | foreach ( $defaults as $var => $default ) { |
| 768 | - $values[ $var ] = FrmAppHelper::get_param( $var, $default, 'get', 'sanitize_text_field' ); |
|
| 768 | + $values[$var] = FrmAppHelper::get_param( $var, $default, 'get', 'sanitize_text_field' ); |
|
| 769 | 769 | } |
| 770 | 770 | |
| 771 | 771 | return $values; |
@@ -793,7 +793,7 @@ discard block |
||
| 793 | 793 | 'keep_post' => '', |
| 794 | 794 | ); |
| 795 | 795 | foreach ( $defaults as $var => $default ) { |
| 796 | - $values[ $var ] = FrmAppHelper::get_param( $var, $default, 'get', 'sanitize_text_field' ); |
|
| 796 | + $values[$var] = FrmAppHelper::get_param( $var, $default, 'get', 'sanitize_text_field' ); |
|
| 797 | 797 | } |
| 798 | 798 | |
| 799 | 799 | return $values; |
@@ -874,6 +874,6 @@ discard block |
||
| 874 | 874 | */ |
| 875 | 875 | public static function get_option( $atts ) { |
| 876 | 876 | $form = $atts['form']; |
| 877 | - return isset( $form->options[ $atts['option'] ] ) ? $form->options[ $atts['option'] ] : $atts['default']; |
|
| 877 | + return isset( $form->options[$atts['option']] ) ? $form->options[$atts['option']] : $atts['default']; |
|
| 878 | 878 | } |
| 879 | 879 | } |