@@ -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 ) { |
@@ -245,7 +245,7 @@ discard block |
||
| 245 | 245 | if ( is_string( $field->field_options[ $opt ] ) ) { |
| 246 | 246 | $field->field_options[ $opt ] = trim( FrmAppHelper::kses( $field->field_options[ $opt ], 'all' ) ); |
| 247 | 247 | } |
| 248 | - } |
|
| 248 | + } |
|
| 249 | 249 | |
| 250 | 250 | $field->field_options = apply_filters( 'frm_update_field_options', $field->field_options, $field, $values ); |
| 251 | 251 | $default_value = maybe_serialize( $values['item_meta'][ $field_id ] ); |
@@ -260,11 +260,11 @@ discard block |
||
| 260 | 260 | FrmField::update( $field_id, $new_field ); |
| 261 | 261 | |
| 262 | 262 | FrmField::delete_form_transient( $field->form_id ); |
| 263 | - } |
|
| 263 | + } |
|
| 264 | 264 | self::clear_form_cache(); |
| 265 | 265 | |
| 266 | - return $values; |
|
| 267 | - } |
|
| 266 | + return $values; |
|
| 267 | + } |
|
| 268 | 268 | |
| 269 | 269 | /** |
| 270 | 270 | * updating the settings page |
@@ -301,21 +301,21 @@ discard block |
||
| 301 | 301 | } |
| 302 | 302 | } |
| 303 | 303 | |
| 304 | - /** |
|
| 305 | - * @param string $status |
|
| 306 | - * @return int|boolean |
|
| 307 | - */ |
|
| 304 | + /** |
|
| 305 | + * @param string $status |
|
| 306 | + * @return int|boolean |
|
| 307 | + */ |
|
| 308 | 308 | public static function set_status( $id, $status ) { |
| 309 | - if ( 'trash' == $status ) { |
|
| 309 | + if ( 'trash' == $status ) { |
|
| 310 | 310 | return self::trash( $id ); |
| 311 | - } |
|
| 311 | + } |
|
| 312 | 312 | |
| 313 | 313 | $statuses = array( 'published', 'draft', 'trash' ); |
| 314 | - if ( ! in_array( $status, $statuses ) ) { |
|
| 315 | - return false; |
|
| 316 | - } |
|
| 314 | + if ( ! in_array( $status, $statuses ) ) { |
|
| 315 | + return false; |
|
| 316 | + } |
|
| 317 | 317 | |
| 318 | - global $wpdb; |
|
| 318 | + global $wpdb; |
|
| 319 | 319 | |
| 320 | 320 | if ( is_array( $id ) ) { |
| 321 | 321 | $where = array( |
@@ -327,33 +327,33 @@ discard block |
||
| 327 | 327 | array_unshift( $where['values'], $status ); |
| 328 | 328 | |
| 329 | 329 | $query_results = $wpdb->query( $wpdb->prepare( 'UPDATE ' . $wpdb->prefix . 'frm_forms SET status = %s ' . $where['where'], $where['values'] ) ); |
| 330 | - } else { |
|
| 330 | + } else { |
|
| 331 | 331 | $query_results = $wpdb->update( $wpdb->prefix . 'frm_forms', array( 'status' => $status ), array( 'id' => $id ) ); |
| 332 | 332 | $wpdb->update( $wpdb->prefix . 'frm_forms', array( 'status' => $status ), array( 'parent_form_id' => $id ) ); |
| 333 | - } |
|
| 333 | + } |
|
| 334 | 334 | |
| 335 | - if ( $query_results ) { |
|
| 335 | + if ( $query_results ) { |
|
| 336 | 336 | self::clear_form_cache(); |
| 337 | - } |
|
| 337 | + } |
|
| 338 | 338 | |
| 339 | - return $query_results; |
|
| 340 | - } |
|
| 339 | + return $query_results; |
|
| 340 | + } |
|
| 341 | 341 | |
| 342 | - /** |
|
| 343 | - * @return int|boolean |
|
| 344 | - */ |
|
| 342 | + /** |
|
| 343 | + * @return int|boolean |
|
| 344 | + */ |
|
| 345 | 345 | public static function trash( $id ) { |
| 346 | - if ( ! EMPTY_TRASH_DAYS ) { |
|
| 347 | - return self::destroy( $id ); |
|
| 348 | - } |
|
| 346 | + if ( ! EMPTY_TRASH_DAYS ) { |
|
| 347 | + return self::destroy( $id ); |
|
| 348 | + } |
|
| 349 | 349 | |
| 350 | 350 | $form = self::getOne( $id ); |
| 351 | - if ( ! $form ) { |
|
| 352 | - return false; |
|
| 353 | - } |
|
| 351 | + if ( ! $form ) { |
|
| 352 | + return false; |
|
| 353 | + } |
|
| 354 | 354 | |
| 355 | - $options = $form->options; |
|
| 356 | - $options['trash_time'] = time(); |
|
| 355 | + $options = $form->options; |
|
| 356 | + $options['trash_time'] = time(); |
|
| 357 | 357 | |
| 358 | 358 | global $wpdb; |
| 359 | 359 | $query_results = $wpdb->update( |
@@ -378,39 +378,39 @@ discard block |
||
| 378 | 378 | ) |
| 379 | 379 | ); |
| 380 | 380 | |
| 381 | - if ( $query_results ) { |
|
| 381 | + if ( $query_results ) { |
|
| 382 | 382 | self::clear_form_cache(); |
| 383 | - } |
|
| 383 | + } |
|
| 384 | 384 | |
| 385 | - return $query_results; |
|
| 386 | - } |
|
| 385 | + return $query_results; |
|
| 386 | + } |
|
| 387 | 387 | |
| 388 | - /** |
|
| 389 | - * @return int|boolean |
|
| 390 | - */ |
|
| 388 | + /** |
|
| 389 | + * @return int|boolean |
|
| 390 | + */ |
|
| 391 | 391 | public static function destroy( $id ) { |
| 392 | - global $wpdb; |
|
| 392 | + global $wpdb; |
|
| 393 | 393 | |
| 394 | 394 | $form = self::getOne( $id ); |
| 395 | - if ( ! $form ) { |
|
| 396 | - return false; |
|
| 397 | - } |
|
| 395 | + if ( ! $form ) { |
|
| 396 | + return false; |
|
| 397 | + } |
|
| 398 | 398 | $id = $form->id; |
| 399 | 399 | |
| 400 | - // Disconnect the entries from this form |
|
| 400 | + // Disconnect the entries from this form |
|
| 401 | 401 | $entries = FrmDb::get_col( $wpdb->prefix . 'frm_items', array( 'form_id' => $id ) ); |
| 402 | 402 | foreach ( $entries as $entry_id ) { |
| 403 | 403 | FrmEntry::destroy( $entry_id ); |
| 404 | 404 | unset( $entry_id ); |
| 405 | 405 | } |
| 406 | 406 | |
| 407 | - // Disconnect the fields from this form |
|
| 407 | + // Disconnect the fields from this form |
|
| 408 | 408 | $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 ) ); |
| 409 | 409 | |
| 410 | 410 | $query_results = $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_forms WHERE id=%d OR parent_form_id=%d', $id, $id ) ); |
| 411 | - if ( $query_results ) { |
|
| 412 | - // Delete all form actions linked to this form |
|
| 413 | - $action_control = FrmFormActionsController::get_form_actions( 'email' ); |
|
| 411 | + if ( $query_results ) { |
|
| 412 | + // Delete all form actions linked to this form |
|
| 413 | + $action_control = FrmFormActionsController::get_form_actions( 'email' ); |
|
| 414 | 414 | $action_control->destroy( $id, 'all' ); |
| 415 | 415 | |
| 416 | 416 | // Clear form caching |
@@ -418,10 +418,10 @@ discard block |
||
| 418 | 418 | |
| 419 | 419 | do_action( 'frm_destroy_form', $id ); |
| 420 | 420 | do_action( 'frm_destroy_form_' . $id ); |
| 421 | - } |
|
| 421 | + } |
|
| 422 | 422 | |
| 423 | - return $query_results; |
|
| 424 | - } |
|
| 423 | + return $query_results; |
|
| 424 | + } |
|
| 425 | 425 | |
| 426 | 426 | /** |
| 427 | 427 | * Delete trashed forms based on how long they have been trashed |
@@ -453,60 +453,60 @@ discard block |
||
| 453 | 453 | return $count; |
| 454 | 454 | } |
| 455 | 455 | |
| 456 | - /** |
|
| 457 | - * @return string form name |
|
| 458 | - */ |
|
| 459 | - public static function getName( $id ) { |
|
| 456 | + /** |
|
| 457 | + * @return string form name |
|
| 458 | + */ |
|
| 459 | + public static function getName( $id ) { |
|
| 460 | 460 | $form = FrmDb::check_cache( $id, 'frm_form' ); |
| 461 | - if ( $form ) { |
|
| 461 | + if ( $form ) { |
|
| 462 | 462 | $r = stripslashes( $form->name ); |
| 463 | - return $r; |
|
| 464 | - } |
|
| 463 | + return $r; |
|
| 464 | + } |
|
| 465 | 465 | |
| 466 | - $query_key = is_numeric( $id ) ? 'id' : 'form_key'; |
|
| 467 | - $r = FrmDb::get_var( 'frm_forms', array( $query_key => $id ), 'name' ); |
|
| 466 | + $query_key = is_numeric( $id ) ? 'id' : 'form_key'; |
|
| 467 | + $r = FrmDb::get_var( 'frm_forms', array( $query_key => $id ), 'name' ); |
|
| 468 | 468 | $r = stripslashes( $r ); |
| 469 | 469 | |
| 470 | - return $r; |
|
| 471 | - } |
|
| 470 | + return $r; |
|
| 471 | + } |
|
| 472 | 472 | |
| 473 | - /** |
|
| 473 | + /** |
|
| 474 | 474 | * @since 3.0 |
| 475 | - * @param string $key |
|
| 476 | - * @return int form id |
|
| 477 | - */ |
|
| 475 | + * @param string $key |
|
| 476 | + * @return int form id |
|
| 477 | + */ |
|
| 478 | 478 | public static function get_id_by_key( $key ) { |
| 479 | 479 | return (int) FrmDb::get_var( 'frm_forms', array( 'form_key' => sanitize_title( $key ) ) ); |
| 480 | - } |
|
| 480 | + } |
|
| 481 | 481 | |
| 482 | 482 | /** |
| 483 | 483 | * @deprecated 3.0 |
| 484 | 484 | * @codeCoverageIgnore |
| 485 | 485 | * |
| 486 | - * @param string $key |
|
| 487 | - * @return int form id |
|
| 488 | - */ |
|
| 486 | + * @param string $key |
|
| 487 | + * @return int form id |
|
| 488 | + */ |
|
| 489 | 489 | public static function getIdByKey( $key ) { |
| 490 | 490 | _deprecated_function( __METHOD__, '3.0', 'FrmForm::get_id_by_key' ); |
| 491 | 491 | return self::get_id_by_key( $key ); |
| 492 | - } |
|
| 492 | + } |
|
| 493 | 493 | |
| 494 | - /** |
|
| 494 | + /** |
|
| 495 | 495 | * @since 3.0 |
| 496 | - * @param int $id |
|
| 497 | - * @return string form key |
|
| 498 | - */ |
|
| 496 | + * @param int $id |
|
| 497 | + * @return string form key |
|
| 498 | + */ |
|
| 499 | 499 | public static function get_key_by_id( $id ) { |
| 500 | - $id = (int) $id; |
|
| 500 | + $id = (int) $id; |
|
| 501 | 501 | $cache = FrmDb::check_cache( $id, 'frm_form' ); |
| 502 | - if ( $cache ) { |
|
| 503 | - return $cache->form_key; |
|
| 504 | - } |
|
| 502 | + if ( $cache ) { |
|
| 503 | + return $cache->form_key; |
|
| 504 | + } |
|
| 505 | 505 | |
| 506 | - $key = FrmDb::get_var( 'frm_forms', array( 'id' => $id ), 'form_key' ); |
|
| 506 | + $key = FrmDb::get_var( 'frm_forms', array( 'id' => $id ), 'form_key' ); |
|
| 507 | 507 | |
| 508 | - return $key; |
|
| 509 | - } |
|
| 508 | + return $key; |
|
| 509 | + } |
|
| 510 | 510 | |
| 511 | 511 | /** |
| 512 | 512 | * @deprecated 3.0 |
@@ -528,47 +528,47 @@ discard block |
||
| 528 | 528 | } |
| 529 | 529 | } |
| 530 | 530 | |
| 531 | - /** |
|
| 532 | - * @return object form |
|
| 533 | - */ |
|
| 534 | - public static function getOne( $id, $blog_id = false ) { |
|
| 535 | - global $wpdb; |
|
| 531 | + /** |
|
| 532 | + * @return object form |
|
| 533 | + */ |
|
| 534 | + public static function getOne( $id, $blog_id = false ) { |
|
| 535 | + global $wpdb; |
|
| 536 | 536 | |
| 537 | - if ( $blog_id && is_multisite() ) { |
|
| 538 | - global $wpmuBaseTablePrefix; |
|
| 537 | + if ( $blog_id && is_multisite() ) { |
|
| 538 | + global $wpmuBaseTablePrefix; |
|
| 539 | 539 | $prefix = $wpmuBaseTablePrefix ? $wpmuBaseTablePrefix . $blog_id . '_' : $wpdb->get_blog_prefix( $blog_id ); |
| 540 | 540 | |
| 541 | 541 | $table_name = $prefix . 'frm_forms'; |
| 542 | - } else { |
|
| 542 | + } else { |
|
| 543 | 543 | $table_name = $wpdb->prefix . 'frm_forms'; |
| 544 | 544 | $cache = wp_cache_get( $id, 'frm_form' ); |
| 545 | - if ( $cache ) { |
|
| 545 | + if ( $cache ) { |
|
| 546 | 546 | if ( isset( $cache->options ) ) { |
| 547 | 547 | $cache->options = maybe_unserialize( $cache->options ); |
| 548 | - } |
|
| 548 | + } |
|
| 549 | 549 | |
| 550 | 550 | return stripslashes_deep( $cache ); |
| 551 | - } |
|
| 552 | - } |
|
| 551 | + } |
|
| 552 | + } |
|
| 553 | 553 | |
| 554 | 554 | if ( is_numeric( $id ) ) { |
| 555 | - $where = array( 'id' => $id ); |
|
| 556 | - } else { |
|
| 557 | - $where = array( 'form_key' => $id ); |
|
| 558 | - } |
|
| 555 | + $where = array( 'id' => $id ); |
|
| 556 | + } else { |
|
| 557 | + $where = array( 'form_key' => $id ); |
|
| 558 | + } |
|
| 559 | 559 | |
| 560 | - $results = FrmDb::get_row( $table_name, $where ); |
|
| 560 | + $results = FrmDb::get_row( $table_name, $where ); |
|
| 561 | 561 | |
| 562 | 562 | if ( isset( $results->options ) ) { |
| 563 | 563 | FrmDb::set_cache( $results->id, $results, 'frm_form' ); |
| 564 | 564 | $results->options = maybe_unserialize( $results->options ); |
| 565 | - } |
|
| 565 | + } |
|
| 566 | 566 | return stripslashes_deep( $results ); |
| 567 | - } |
|
| 567 | + } |
|
| 568 | 568 | |
| 569 | - /** |
|
| 570 | - * @return object|array of objects |
|
| 571 | - */ |
|
| 569 | + /** |
|
| 570 | + * @return object|array of objects |
|
| 571 | + */ |
|
| 572 | 572 | public static function getAll( $where = array(), $order_by = '', $limit = '' ) { |
| 573 | 573 | if ( is_array( $where ) && ! empty( $where ) ) { |
| 574 | 574 | $results = FrmDb::get_results( 'frm_forms', $where, '*', array( |
@@ -596,7 +596,7 @@ discard block |
||
| 596 | 596 | } |
| 597 | 597 | |
| 598 | 598 | return stripslashes_deep( $results ); |
| 599 | - } |
|
| 599 | + } |
|
| 600 | 600 | |
| 601 | 601 | /** |
| 602 | 602 | * Get all published forms |
@@ -614,18 +614,18 @@ discard block |
||
| 614 | 614 | return $forms; |
| 615 | 615 | } |
| 616 | 616 | |
| 617 | - /** |
|
| 618 | - * @return int count of forms |
|
| 619 | - */ |
|
| 620 | - public static function get_count() { |
|
| 621 | - global $wpdb; |
|
| 617 | + /** |
|
| 618 | + * @return int count of forms |
|
| 619 | + */ |
|
| 620 | + public static function get_count() { |
|
| 621 | + global $wpdb; |
|
| 622 | 622 | |
| 623 | - $cache_key = 'frm_form_counts'; |
|
| 623 | + $cache_key = 'frm_form_counts'; |
|
| 624 | 624 | |
| 625 | - $counts = wp_cache_get( $cache_key, 'frm_form' ); |
|
| 626 | - if ( false !== $counts ) { |
|
| 627 | - return $counts; |
|
| 628 | - } |
|
| 625 | + $counts = wp_cache_get( $cache_key, 'frm_form' ); |
|
| 626 | + if ( false !== $counts ) { |
|
| 627 | + return $counts; |
|
| 628 | + } |
|
| 629 | 629 | |
| 630 | 630 | $results = (array) FrmDb::get_results( 'frm_forms', array( |
| 631 | 631 | 'or' => 1, |
@@ -634,31 +634,31 @@ discard block |
||
| 634 | 634 | ), 'status, is_template' ); |
| 635 | 635 | |
| 636 | 636 | $statuses = array( 'published', 'draft', 'template', 'trash' ); |
| 637 | - $counts = array_fill_keys( $statuses, 0 ); |
|
| 637 | + $counts = array_fill_keys( $statuses, 0 ); |
|
| 638 | 638 | |
| 639 | - foreach ( $results as $row ) { |
|
| 640 | - if ( 'trash' != $row->status ) { |
|
| 641 | - if ( $row->is_template ) { |
|
| 639 | + foreach ( $results as $row ) { |
|
| 640 | + if ( 'trash' != $row->status ) { |
|
| 641 | + if ( $row->is_template ) { |
|
| 642 | 642 | $counts['template']++; |
| 643 | - } else { |
|
| 643 | + } else { |
|
| 644 | 644 | $counts['published']++; |
| 645 | - } |
|
| 646 | - } else { |
|
| 645 | + } |
|
| 646 | + } else { |
|
| 647 | 647 | $counts['trash']++; |
| 648 | - } |
|
| 648 | + } |
|
| 649 | 649 | |
| 650 | - if ( 'draft' == $row->status ) { |
|
| 650 | + if ( 'draft' == $row->status ) { |
|
| 651 | 651 | $counts['draft']++; |
| 652 | - } |
|
| 652 | + } |
|
| 653 | 653 | |
| 654 | 654 | unset( $row ); |
| 655 | - } |
|
| 655 | + } |
|
| 656 | 656 | |
| 657 | - $counts = (object) $counts; |
|
| 657 | + $counts = (object) $counts; |
|
| 658 | 658 | FrmDb::set_cache( $cache_key, $counts, 'frm_form' ); |
| 659 | 659 | |
| 660 | - return $counts; |
|
| 661 | - } |
|
| 660 | + return $counts; |
|
| 661 | + } |
|
| 662 | 662 | |
| 663 | 663 | /** |
| 664 | 664 | * Clear form caching |
@@ -671,14 +671,14 @@ discard block |
||
| 671 | 671 | FrmDb::cache_delete_group( 'frm_form' ); |
| 672 | 672 | } |
| 673 | 673 | |
| 674 | - /** |
|
| 675 | - * @return array of errors |
|
| 676 | - */ |
|
| 674 | + /** |
|
| 675 | + * @return array of errors |
|
| 676 | + */ |
|
| 677 | 677 | public static function validate( $values ) { |
| 678 | - $errors = array(); |
|
| 678 | + $errors = array(); |
|
| 679 | 679 | |
| 680 | 680 | return apply_filters( 'frm_validate_form', $errors, $values ); |
| 681 | - } |
|
| 681 | + } |
|
| 682 | 682 | |
| 683 | 683 | public static function get_params( $form = null ) { |
| 684 | 684 | 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,14 +241,14 @@ 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 | - if ( is_string( $field->field_options[ $opt ] ) ) { |
|
| 246 | - $field->field_options[ $opt ] = trim( FrmAppHelper::kses( $field->field_options[ $opt ], 'all' ) ); |
|
| 244 | + $field->field_options[$opt] = isset( $values['field_options'][$opt . '_' . $field_id] ) ? $values['field_options'][$opt . '_' . $field_id] : $default; |
|
| 245 | + if ( is_string( $field->field_options[$opt] ) ) { |
|
| 246 | + $field->field_options[$opt] = trim( FrmAppHelper::kses( $field->field_options[$opt], 'all' ) ); |
|
| 247 | 247 | } |
| 248 | 248 | } |
| 249 | 249 | |
| 250 | 250 | $field->field_options = apply_filters( 'frm_update_field_options', $field->field_options, $field, $values ); |
| 251 | - $default_value = maybe_serialize( $values['item_meta'][ $field_id ] ); |
|
| 251 | + $default_value = maybe_serialize( $values['item_meta'][$field_id] ); |
|
| 252 | 252 | |
| 253 | 253 | $new_field = array( |
| 254 | 254 | 'field_options' => $field->field_options, |
@@ -270,10 +270,10 @@ discard block |
||
| 270 | 270 | * updating the settings page |
| 271 | 271 | */ |
| 272 | 272 | private static function get_settings_page_html( $values, &$field ) { |
| 273 | - if ( isset( $values['field_options'][ 'custom_html_' . $field->id ] ) ) { |
|
| 273 | + if ( isset( $values['field_options']['custom_html_' . $field->id] ) ) { |
|
| 274 | 274 | $prev_opts = array(); |
| 275 | 275 | $fallback_html = isset( $field->field_options['custom_html'] ) ? $field->field_options['custom_html'] : FrmFieldsHelper::get_default_html( $field->type ); |
| 276 | - $field->field_options['custom_html'] = isset( $values['field_options'][ 'custom_html_' . $field->id ] ) ? $values['field_options'][ 'custom_html_' . $field->id ] : $fallback_html; |
|
| 276 | + $field->field_options['custom_html'] = isset( $values['field_options']['custom_html_' . $field->id] ) ? $values['field_options']['custom_html_' . $field->id] : $fallback_html; |
|
| 277 | 277 | } elseif ( $field->type == 'hidden' || $field->type == 'user_id' ) { |
| 278 | 278 | $prev_opts = $field->field_options; |
| 279 | 279 | } |
@@ -297,7 +297,7 @@ discard block |
||
| 297 | 297 | ); |
| 298 | 298 | foreach ( $field_cols as $col => $default ) { |
| 299 | 299 | $default = ( $default === '' ) ? $field->{$col} : $default; |
| 300 | - $new_field[ $col ] = isset( $values['field_options'][ $col . '_' . $field->id ] ) ? $values['field_options'][ $col . '_' . $field->id ] : $default; |
|
| 300 | + $new_field[$col] = isset( $values['field_options'][$col . '_' . $field->id] ) ? $values['field_options'][$col . '_' . $field->id] : $default; |
|
| 301 | 301 | } |
| 302 | 302 | } |
| 303 | 303 | |
@@ -310,7 +310,7 @@ discard block |
||
| 310 | 310 | return self::trash( $id ); |
| 311 | 311 | } |
| 312 | 312 | |
| 313 | - $statuses = array( 'published', 'draft', 'trash' ); |
|
| 313 | + $statuses = array( 'published', 'draft', 'trash' ); |
|
| 314 | 314 | if ( ! in_array( $status, $statuses ) ) { |
| 315 | 315 | return false; |
| 316 | 316 | } |
@@ -445,7 +445,7 @@ discard block |
||
| 445 | 445 | $form->options = maybe_unserialize( $form->options ); |
| 446 | 446 | if ( ! isset( $form->options['trash_time'] ) || $form->options['trash_time'] < $delete_timestamp ) { |
| 447 | 447 | self::destroy( $form->id ); |
| 448 | - $count++; |
|
| 448 | + $count ++; |
|
| 449 | 449 | } |
| 450 | 450 | |
| 451 | 451 | unset( $form ); |
@@ -639,16 +639,16 @@ discard block |
||
| 639 | 639 | foreach ( $results as $row ) { |
| 640 | 640 | if ( 'trash' != $row->status ) { |
| 641 | 641 | if ( $row->is_template ) { |
| 642 | - $counts['template']++; |
|
| 642 | + $counts['template'] ++; |
|
| 643 | 643 | } else { |
| 644 | - $counts['published']++; |
|
| 644 | + $counts['published'] ++; |
|
| 645 | 645 | } |
| 646 | 646 | } else { |
| 647 | - $counts['trash']++; |
|
| 647 | + $counts['trash'] ++; |
|
| 648 | 648 | } |
| 649 | 649 | |
| 650 | 650 | if ( 'draft' == $row->status ) { |
| 651 | - $counts['draft']++; |
|
| 651 | + $counts['draft'] ++; |
|
| 652 | 652 | } |
| 653 | 653 | |
| 654 | 654 | unset( $row ); |
@@ -689,8 +689,8 @@ discard block |
||
| 689 | 689 | self::maybe_get_form( $form ); |
| 690 | 690 | } |
| 691 | 691 | |
| 692 | - if ( isset( $frm_vars['form_params'] ) && is_array( $frm_vars['form_params'] ) && isset( $frm_vars['form_params'][ $form->id ] ) ) { |
|
| 693 | - return $frm_vars['form_params'][ $form->id ]; |
|
| 692 | + if ( isset( $frm_vars['form_params'] ) && is_array( $frm_vars['form_params'] ) && isset( $frm_vars['form_params'][$form->id] ) ) { |
|
| 693 | + return $frm_vars['form_params'][$form->id]; |
|
| 694 | 694 | } |
| 695 | 695 | |
| 696 | 696 | $action_var = isset( $_REQUEST['frm_action'] ) ? 'frm_action' : 'action'; |
@@ -719,15 +719,15 @@ discard block |
||
| 719 | 719 | //if there are two forms on the same page, make sure not to submit both |
| 720 | 720 | foreach ( $default_values as $var => $default ) { |
| 721 | 721 | if ( $var == 'action' ) { |
| 722 | - $values[ $var ] = FrmAppHelper::get_param( $action_var, $default, 'get', 'sanitize_title' ); |
|
| 722 | + $values[$var] = FrmAppHelper::get_param( $action_var, $default, 'get', 'sanitize_title' ); |
|
| 723 | 723 | } else { |
| 724 | - $values[ $var ] = FrmAppHelper::get_param( $var, $default, 'get', 'sanitize_text_field' ); |
|
| 724 | + $values[$var] = FrmAppHelper::get_param( $var, $default, 'get', 'sanitize_text_field' ); |
|
| 725 | 725 | } |
| 726 | 726 | unset( $var, $default ); |
| 727 | 727 | } |
| 728 | 728 | } else { |
| 729 | 729 | foreach ( $default_values as $var => $default ) { |
| 730 | - $values[ $var ] = $default; |
|
| 730 | + $values[$var] = $default; |
|
| 731 | 731 | unset( $var, $default ); |
| 732 | 732 | } |
| 733 | 733 | } |
@@ -751,7 +751,7 @@ discard block |
||
| 751 | 751 | 'sdir' => '', |
| 752 | 752 | ); |
| 753 | 753 | foreach ( $defaults as $var => $default ) { |
| 754 | - $values[ $var ] = FrmAppHelper::get_param( $var, $default, 'get', 'sanitize_text_field' ); |
|
| 754 | + $values[$var] = FrmAppHelper::get_param( $var, $default, 'get', 'sanitize_text_field' ); |
|
| 755 | 755 | } |
| 756 | 756 | |
| 757 | 757 | return $values; |
@@ -779,7 +779,7 @@ discard block |
||
| 779 | 779 | 'keep_post' => '', |
| 780 | 780 | ); |
| 781 | 781 | foreach ( $defaults as $var => $default ) { |
| 782 | - $values[ $var ] = FrmAppHelper::get_param( $var, $default, 'get', 'sanitize_text_field' ); |
|
| 782 | + $values[$var] = FrmAppHelper::get_param( $var, $default, 'get', 'sanitize_text_field' ); |
|
| 783 | 783 | } |
| 784 | 784 | |
| 785 | 785 | return $values; |
@@ -860,6 +860,6 @@ discard block |
||
| 860 | 860 | */ |
| 861 | 861 | public static function get_option( $atts ) { |
| 862 | 862 | $form = $atts['form']; |
| 863 | - return isset( $form->options[ $atts['option'] ] ) ? $form->options[ $atts['option'] ] : $atts['default']; |
|
| 863 | + return isset( $form->options[$atts['option']] ) ? $form->options[$atts['option']] : $atts['default']; |
|
| 864 | 864 | } |
| 865 | 865 | } |