PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / trunk
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More vtrunk
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
← All changes | classes/models/FrmDb.php +40 -74 6.27 → trunk View file →
@@ -5,49 +5,8 @@
5 5
6 6 class FrmDb {
7 7
8 8 /**
9 - * The table name for Formidable Fields.
10 - *
11 - * @var string
12 - */
13 - public $fields;
14 -
15 - /**
16 - * The table name for Formidable Forms.
17 - *
18 - * @var string
19 - */
20 - public $forms;
21 -
22 - /**
23 - * The table name for Formidable Entries.
24 - *
25 - * @var string
26 - */
27 - public $entries;
28 -
29 - /**
30 - * The table name for Formidable Entry Metas.
31 - *
32 - * @var string
33 - */
34 - public $entry_metas;
35 -
36 - public function __construct() {
37 - if ( ! defined( 'ABSPATH' ) ) {
38 - die( 'You are not allowed to call this page directly.' );
39 - }
40 -
41 - _deprecated_function( __METHOD__, '2.05.06', 'FrmMigrate' );
42 - global $wpdb;
43 - $this->fields = $wpdb->prefix . 'frm_fields';
44 - $this->forms = $wpdb->prefix . 'frm_forms';
45 - $this->entries = $wpdb->prefix . 'frm_items';
46 - $this->entry_metas = $wpdb->prefix . 'frm_item_metas';
47 - }
48 -
49 - /**
50 9 * Change array into format $wpdb->prepare can use
51 10 *
52 11 * @param array $args
53 12 * @param string $starts_with
@@ -55,9 +14,9 @@
55 14 * @return void
56 15 */
57 16 public static function get_where_clause_and_values( &$args, $starts_with = ' WHERE ' ) {
58 17 if ( ! $args ) {
59 - // add an arg to prevent prepare from failing
18 + // Add an arg to prevent prepare from failing
60 19 $args = array(
61 20 'where' => $starts_with . '1=%d',
62 21 'values' => array( 1 ),
63 22 );
@@ -92,9 +51,9 @@
92 51 unset( $args['or'] );
93 52 }
94 53
95 54 foreach ( $args as $key => $value ) {
96 - $where .= empty( $where ) ? $base_where : $condition;
55 + $where .= $where ? $condition : $base_where;
97 56 // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict
98 57 $array_inc_null = ! is_numeric( $key ) && is_array( $value ) && in_array( null, $value );
99 58
100 59 if ( is_numeric( $key ) || $array_inc_null ) {
@@ -121,12 +80,12 @@
121 80 }//end foreach
122 81 }
123 82
124 83 /**
125 - * @param string $key
126 - * @param array|string $value
127 - * @param string $where
128 - * @param array $values
84 + * @param string $key
85 + * @param array|string|null $value
86 + * @param string $where
87 + * @param array $values
129 88 *
130 89 * @return void
131 90 */
132 91 private static function interpret_array_to_sql( $key, $value, &$where, &$values ) {
@@ -142,9 +101,9 @@
142 101 $lowercase_key = explode( ' ', strtolower( $key ) );
143 102 $lowercase_key = end( $lowercase_key );
144 103
145 104 if ( is_array( $value ) ) {
146 - // translate array of values to "in"
105 + // Translate array of values to "in"
147 106 if ( str_contains( $lowercase_key, 'like' ) ) {
148 107 $where = preg_replace( '/' . $key . '$/', '', $where );
149 108 $where .= '(';
150 109 $start = true;
@@ -183,9 +142,8 @@
183 142 }
184 143
185 144 $where .= ' %s';
186 145 $values[] = $start . self::esc_like( $value ) . $end;
187 -
188 146 } elseif ( $value === null ) {
189 147 $where .= ' IS NULL';
190 148 } else {
191 149 // allow a - to prevent = from being added
@@ -388,9 +346,9 @@
388 346 if ( $group === $table ) {
389 347 $table = $wpdb->prefix . $table;
390 348 }
391 349
392 - // switch to singular group name
350 + // Switch to singular group name
393 351 $group = rtrim( $group, 's' );
394 352 }
395 353
396 354 /**
@@ -445,13 +403,15 @@
445 403 }
446 404 }
447 405
448 406 // Make sure LIMIT is the last argument
449 - if ( isset( $args['order_by'] ) && isset( $args['limit'] ) ) {
450 - $temp_limit = $args['limit'];
451 - unset( $args['limit'] );
452 - $args['limit'] = $temp_limit;
407 + if ( ! isset( $args['order_by'] ) || ! isset( $args['limit'] ) ) {
408 + return;
453 409 }
410 +
411 + $temp_limit = $args['limit'];
412 + unset( $args['limit'] );
413 + $args['limit'] = $temp_limit;
454 414 }
455 415
456 416 /**
457 417 * Get the associative array results for the given columns, table, and where query
@@ -490,15 +450,17 @@
490 450 $query = 'SELECT ' . $columns . ' FROM ' . $table;
491 451
492 452 self::esc_query_args( $args );
493 453
494 - if ( is_array( $where ) || empty( $where ) ) {
495 - self::get_where_clause_and_values( $where );
496 - global $wpdb;
497 - $query = $wpdb->prepare( $query . $where['where'] . ' ' . implode( ' ', $args ), $where['values'] ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
454 + if ( ! is_array( $where ) && $where ) {
455 + return $query;
498 456 }
499 457
500 - return $query;
458 + self::get_where_clause_and_values( $where );
459 + global $wpdb;
460 +
461 + // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
462 + return $wpdb->prepare( $query . $where['where'] . ' ' . implode( ' ', $args ), $where['values'] );
501 463 }
502 464
503 465 /**
504 466 * @since 2.05.07
@@ -647,11 +609,11 @@
647 609 public static function prepend_and_or_where( $starts_with = ' WHERE ', $where = '' ) {
648 610 if ( ! $where ) {
649 611 $where = '';
650 612 } elseif ( is_array( $where ) ) {
651 - global $wpdb;
652 - self::get_where_clause_and_values( $where, $starts_with );
653 - $where = $wpdb->prepare( $where['where'], $where['values'] ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
613 + global $wpdb;
614 + self::get_where_clause_and_values( $where, $starts_with );
615 + $where = $wpdb->prepare( $where['where'], $where['values'] ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
654 616 } else {
655 617 $where = $starts_with . $where;
656 618 }
657 619
@@ -683,9 +645,9 @@
683 645 if ( empty( $settings['ID'] ) ) {
684 646 unset( $settings['ID'] );
685 647 }
686 648
687 - // delete all caches for this group
649 + // Delete all caches for this group
688 650 self::cache_delete_group( $group );
689 651
690 652 return self::save_json_post( $settings );
691 653 }
@@ -714,9 +676,9 @@
714 676 remove_all_filters( 'content_save_pre' );
715 677
716 678 $post = wp_insert_post( $settings );
717 679
718 - // add the content filters back for views or posts
680 + // Add the content filters back for views or posts
719 681 if ( isset( $filters ) ) {
720 682 $wp_filter['content_save_pre'] = $filters;
721 683 }
722 684
@@ -739,9 +701,9 @@
739 701 public static function check_cache( $cache_key, $group = '', $query = '', $type = 'get_var', $time = 300 ) {
740 702 $found = null;
741 703 $results = wp_cache_get( $cache_key, $group, false, $found );
742 704
743 - if ( ( $found === true && $results !== false ) || empty( $query ) ) {
705 + if ( ( $found === true && $results !== false ) || ! $query ) {
744 706 return $results;
745 707 }
746 708
747 709 if ( 'get_posts' === $type ) {
@@ -769,12 +731,14 @@
769 731 *
770 732 * @return void
771 733 */
772 734 public static function set_cache( $cache_key, $results, $group = '', $time = 300 ) {
773 - if ( ! FrmAppHelper::prevent_caching() ) {
774 - self::add_key_to_group_cache( $cache_key, $group );
775 - wp_cache_set( $cache_key, $results, $group, $time );
735 + if ( FrmAppHelper::prevent_caching() ) {
736 + return;
776 737 }
738 +
739 + self::add_key_to_group_cache( $cache_key, $group );
740 + wp_cache_set( $cache_key, $results, $group, $time );
777 741 }
778 742
779 743 /**
780 744 * Keep track of the keys cached in each group so they can be deleted
@@ -803,9 +767,9 @@
803 767 public static function get_group_cached_keys( $group ) {
804 768 $cached = wp_cache_get( 'cached_keys', $group );
805 769
806 770 if ( ! $cached || ! is_array( $cached ) ) {
807 - $cached = array();
771 + return array();
808 772 }
809 773
810 774 return $cached;
811 775 }
@@ -834,15 +798,17 @@
834 798 */
835 799 public static function cache_delete_group( $group ) {
836 800 $cached_keys = self::get_group_cached_keys( $group );
837 801
838 - if ( $cached_keys ) {
839 - foreach ( $cached_keys as $key ) {
840 - wp_cache_delete( $key, $group );
841 - }
802 + if ( ! $cached_keys ) {
803 + return;
804 + }
842 805
843 - wp_cache_delete( 'cached_keys', $group );
806 + foreach ( $cached_keys as $key ) {
807 + wp_cache_delete( $key, $group );
844 808 }
809 +
810 + wp_cache_delete( 'cached_keys', $group );
845 811 }
846 812
847 813 /**
848 814 * Checks if a DB column exists.