PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.4
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.4
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 +99 -93 6.255.4 View file →
@@ -24,11 +24,10 @@
24 24
25 25 /**
26 26 * Change array into format $wpdb->prepare can use
27 27 *
28 - * @param array $args
28 + * @param array $args
29 29 * @param string $starts_with
30 - * @return void
31 30 */
32 31 public static function get_where_clause_and_values( &$args, $starts_with = ' WHERE ' ) {
33 32 if ( empty( $args ) ) {
34 33 // add an arg to prevent prepare from failing
@@ -51,12 +50,12 @@
51 50 $args = compact( 'where', 'values' );
52 51 }
53 52
54 53 /**
55 - * @param array $args
54 + * @param array $args
56 55 * @param string $base_where
57 56 * @param string $where
58 - * @param array $values
57 + * @param array $values
59 58 */
60 59 public static function parse_where_from_array( $args, $base_where, &$where, &$values ) {
61 60 $condition = ' AND';
62 61 if ( isset( $args['or'] ) ) {
@@ -64,12 +63,12 @@
64 63 unset( $args['or'] );
65 64 }
66 65
67 66 foreach ( $args as $key => $value ) {
68 - $where .= empty( $where ) ? $base_where : $condition;
67 + $where .= empty( $where ) ? $base_where : $condition;
69 68 $array_inc_null = ( ! is_numeric( $key ) && is_array( $value ) && in_array( null, $value ) );
70 69 if ( is_numeric( $key ) || $array_inc_null ) {
71 - $where .= ' ( ';
70 + $where .= ' ( ';
72 71 $nested_where = '';
73 72 if ( $array_inc_null ) {
74 73 foreach ( $value as $val ) {
75 74 $parse_where = array(
@@ -85,24 +84,24 @@
85 84 $where .= ' ) ';
86 85 } else {
87 86 self::interpret_array_to_sql( $key, $value, $where, $values );
88 87 }
89 - }//end foreach
88 + }
90 89 }
91 90
92 91 /**
93 - * @param string $key
94 - * @param array|string $value
95 - * @param string $where
96 - * @param array $values
97 - * @return void
92 + * @param string $key
93 + * @param string|array $value
94 + * @param string $where
95 + * @param array $values
98 96 */
99 97 private static function interpret_array_to_sql( $key, $value, &$where, &$values ) {
100 98 $key = trim( $key );
101 99
102 100 if ( strpos( $key, 'created_at' ) !== false || strpos( $key, 'updated_at' ) !== false ) {
103 - $k = explode( ' ', $key );
104 - $where .= ' CAST(' . reset( $k ) . ' as CHAR) ' . str_replace( reset( $k ), '', $key );
101 + $k = explode( ' ', $key );
102 + $where .= ' DATE_FORMAT(' . reset( $k ) . ', %s) ' . str_replace( reset( $k ), '', $key );
103 + $values[] = '%Y-%m-%d %H:%i:%s';
105 104 } else {
106 105 $where .= ' ' . $key;
107 106 }
108 107
@@ -111,22 +110,22 @@
111 110
112 111 if ( is_array( $value ) ) {
113 112 // translate array of values to "in"
114 113 if ( strpos( $lowercase_key, 'like' ) !== false ) {
115 - $where = preg_replace( '/' . $key . '$/', '', $where );
114 + $where = preg_replace( '/' . $key . '$/', '', $where );
116 115 $where .= '(';
117 - $start = true;
116 + $start = true;
118 117 foreach ( $value as $v ) {
119 118 if ( ! $start ) {
120 119 $where .= ' OR ';
121 120 }
122 121 $start = false;
123 - $where .= $key . ' %s';
122 + $where .= $key . ' %s';
124 123 $values[] = '%' . self::esc_like( $v ) . '%';
125 124 }
126 125 $where .= ')';
127 126 } elseif ( ! empty( $value ) ) {
128 - $where .= ' in (' . self::prepare_array_values( $value, '%s' ) . ')';
127 + $where .= ' in (' . self::prepare_array_values( $value, '%s' ) . ')';
129 128 $values = array_merge( $values, $value );
130 129 }
131 130 } elseif ( strpos( $lowercase_key, 'like' ) !== false ) {
132 131 /**
@@ -135,18 +134,18 @@
135 134 * If the key is %like then skip the last % for ends with
136 135 */
137 136 $start = '%';
138 137 $end = '%';
139 - if ( $lowercase_key === 'like%' ) {
138 + if ( $lowercase_key == 'like%' ) {
140 139 $start = '';
141 140 $where = rtrim( $where, '%' );
142 141 } elseif ( $lowercase_key == '%like' ) {
143 - $end = '';
144 - $where = rtrim( rtrim( $where, '%like' ), '%LIKE' );
142 + $end = '';
143 + $where = rtrim( rtrim( $where, '%like' ), '%LIKE' );
145 144 $where .= 'like';
146 145 }
147 146
148 - $where .= ' %s';
147 + $where .= ' %s';
149 148 $values[] = $start . self::esc_like( $value ) . $end;
150 149
151 150 } elseif ( $value === null ) {
152 151 $where .= ' IS NULL';
@@ -151,9 +150,9 @@
151 150 } elseif ( $value === null ) {
152 151 $where .= ' IS NULL';
153 152 } else {
154 153 // allow a - to prevent = from being added
155 - if ( substr( $key, - 1 ) === '-' ) {
154 + if ( substr( $key, - 1 ) == '-' ) {
156 155 $where = rtrim( $where, '-' );
157 156 } else {
158 157 $where .= '=';
159 158 }
@@ -160,9 +159,9 @@
160 159
161 160 self::add_query_placeholder( $key, $value, $where );
162 161
163 162 $values[] = $value;
164 - }//end if
163 + }
165 164 }
166 165
167 166 /**
168 167 * Add %d, or %s to query
@@ -168,16 +167,15 @@
168 167 * Add %d, or %s to query
169 168 *
170 169 * @since 2.02.05
171 170 *
172 - * @param string $key
171 + * @param string $key
173 172 * @param int|string $value
174 - * @param string $where
173 + * @param string $where
175 174 */
176 175 private static function add_query_placeholder( $key, $value, &$where ) {
177 176 if ( is_numeric( $value ) && ( strpos( $key, 'meta_value' ) === false || strpos( $key, '+0' ) !== false ) ) {
178 - // Switch string to number.
179 - $value = $value + 0;
177 + $value = $value + 0; // switch string to number
180 178 $where .= is_float( $value ) ? '%f' : '%d';
181 179 } else {
182 180 $where .= '%s';
183 181 }
@@ -184,10 +182,10 @@
184 182 }
185 183
186 184 /**
187 185 * @param string $table
188 - * @param array $where
189 - * @param array $args
186 + * @param array $where
187 + * @param array $args
190 188 *
191 189 * @return int
192 190 */
193 191 public static function get_count( $table, $where = array(), $args = array() ) {
@@ -197,15 +195,15 @@
197 195 }
198 196
199 197 /**
200 198 * @param string $table
201 - * @param array $where
199 + * @param array $where
202 200 * @param string $field
203 - * @param array $args
201 + * @param array $args
204 202 * @param string $limit
205 203 * @param string $type
206 204 *
207 - * @return array|object|string|null
205 + * @return array|null|string|object
208 206 */
209 207 public static function get_var( $table, $where = array(), $field = 'id', $args = array(), $limit = '', $type = 'var' ) {
210 208 $group = '';
211 209 self::get_group_and_table_name( $table, $group );
@@ -226,16 +224,16 @@
226 224 * Generate a cache key from the where query, field, type, and other arguments
227 225 *
228 226 * @since 2.03.07
229 227 *
230 - * @param array $where
231 - * @param array $args
228 + * @param array $where
229 + * @param array $args
232 230 * @param string $field
233 231 * @param string $type
234 232 *
235 233 * @return string
236 234 */
237 - public static function generate_cache_key( $where, $args, $field, $type ) {
235 + private static function generate_cache_key( $where, $args, $field, $type ) {
238 236 $cache_key = '';
239 237 $where = FrmAppHelper::array_flatten( $where );
240 238 foreach ( $where as $key => $value ) {
241 239 $cache_key .= $key . '_' . $value;
@@ -240,9 +238,9 @@
240 238 foreach ( $where as $key => $value ) {
241 239 $cache_key .= $key . '_' . $value;
242 240 }
243 241 $cache_key .= implode( '_', $args ) . $field . '_' . $type;
244 - $cache_key = str_replace( array( ' ', ',' ), '_', $cache_key );
242 + $cache_key = str_replace( array( ' ', ',' ), '_', $cache_key );
245 243
246 244 return $cache_key;
247 245 }
248 246
@@ -247,14 +245,14 @@
247 245 }
248 246
249 247 /**
250 248 * @param string $table
251 - * @param array $where
249 + * @param array $where
252 250 * @param string $field
253 - * @param array $args
251 + * @param array $args
254 252 * @param string $limit
255 253 *
256 - * @return array
254 + * @return mixed
257 255 */
258 256 public static function get_col( $table, $where = array(), $field = 'id', $args = array(), $limit = '' ) {
259 257 return self::get_var( $table, $where, $field, $args, $limit, 'col' );
260 258 }
@@ -262,16 +260,17 @@
262 260 /**
263 261 * @since 2.0
264 262 *
265 263 * @param string $table
266 - * @param array $where
264 + * @param array $where
267 265 * @param string $fields
268 - * @param array $args
266 + * @param array $args
269 267 *
270 268 * @return mixed
271 269 */
272 270 public static function get_row( $table, $where = array(), $fields = '*', $args = array() ) {
273 271 $args['limit'] = 1;
272 +
274 273 return self::get_var( $table, $where, $fields, $args, '', 'row' );
275 274 }
276 275
277 276 /**
@@ -279,13 +278,13 @@
279 278 *
280 279 * @since 2.0
281 280 *
282 281 * @param string $table
283 - * @param array $where
282 + * @param array $where
284 283 * @param string $fields
285 - * @param array $args
284 + * @param array $args
286 285 *
287 - * @return array
286 + * @return mixed
288 287 */
289 288 public static function get_results( $table, $where = array(), $fields = '*', $args = array() ) {
290 289 return self::get_var( $table, $where, $fields, $args, '', 'results' );
291 290 }
@@ -317,11 +316,10 @@
317 316 return ' ' . $switch_to[ $where_is ];
318 317 }
319 318
320 319 // > and < need a little more work since we don't want them switched to >= and <=
321 - if ( $where_is === '>' || $where_is === '<' ) {
322 - // The - indicates that the = should not be added later.
323 - return ' ' . $where_is . '-';
320 + if ( $where_is == '>' || $where_is == '<' ) {
321 + return ' ' . $where_is . '-'; // the - indicates that the = should not be added later
324 322 }
325 323
326 324 // fallback to = if the query is none of these
327 325 return '';
@@ -403,9 +401,9 @@
403 401 * @since 2.02.05
404 402 *
405 403 * @param string $columns
406 404 * @param string $table
407 - * @param array $where
405 + * @param array $where
408 406 *
409 407 * @return mixed
410 408 */
411 409 public static function get_associative_array_results( $columns, $table, $where ) {
@@ -426,10 +424,10 @@
426 424 * @since 2.02.05
427 425 *
428 426 * @param string $columns
429 427 * @param string $table
430 - * @param mixed $where
431 - * @param array $args
428 + * @param mixed $where
429 + * @param array $args
432 430 *
433 431 * @return string
434 432 */
435 433 private static function generate_query_string_from_pieces( $columns, $table, $where, $args = array() ) {
@@ -440,8 +438,15 @@
440 438 if ( is_array( $where ) || empty( $where ) ) {
441 439 self::get_where_clause_and_values( $where );
442 440 global $wpdb;
443 441 $query = $wpdb->prepare( $query . $where['where'] . ' ' . implode( ' ', $args ), $where['values'] ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
442 + } else {
443 + /**
444 + * Allow the $where to be prepared before we recieve it here.
445 + * This is a fallback for reverse compatibility, but is not recommended
446 + */
447 + _deprecated_argument( 'where', '2.0', esc_html__( 'Use the query in an array format so it can be properly prepared.', 'formidable' ) );
448 + $query .= $where . ' ' . implode( ' ', $args );
444 449 }
445 450
446 451 return $query;
447 452 }
@@ -450,11 +455,11 @@
450 455 * @since 2.05.07
451 456 */
452 457 private static function esc_query_args( &$args ) {
453 458 foreach ( $args as $param => $value ) {
454 - if ( $param === 'order_by' ) {
459 + if ( $param == 'order_by' ) {
455 460 $args[ $param ] = self::esc_order( $value );
456 - } elseif ( $param === 'limit' ) {
461 + } elseif ( $param == 'limit' ) {
457 462 $args[ $param ] = self::esc_limit( $value );
458 463 }
459 464
460 465 if ( $args[ $param ] == '' ) {
@@ -463,13 +468,13 @@
463 468 }
464 469 }
465 470
466 471 /**
467 - * Added for < WP 4.0 compatibility
472 + * Added for < WP 4.0 compatability
468 473 *
469 474 * @since 2.05.06
470 475 *
471 - * @param string $term The value to escape.
476 + * @param string $term The value to escape
472 477 *
473 478 * @return string The escaped value
474 479 */
475 480 public static function esc_like( $term ) {
@@ -487,9 +492,9 @@
487 492 if ( empty( $order_query ) ) {
488 493 return '';
489 494 }
490 495
491 - // Remove ORDER BY before sanitizing.
496 + // remove ORDER BY before santizing
492 497 $order_query = strtolower( $order_query );
493 498 if ( strpos( $order_query, 'order by' ) !== false ) {
494 499 $order_query = str_replace( 'order by', '', $order_query );
495 500 }
@@ -517,16 +522,17 @@
517 522 * @since 2.05.06
518 523 */
519 524 public static function esc_order_by( &$order_by ) {
520 525 $sort_options = array( 'asc', 'desc' );
521 - if ( ! in_array( strtolower( $order_by ), $sort_options, true ) ) {
526 + if ( ! in_array( strtolower( $order_by ), $sort_options ) ) {
522 527 $order_by = 'asc';
523 528 }
524 529 }
525 530
526 531 /**
532 + * @param string $limit
533 + *
527 534 * @since 2.05.06
528 - * @param string $limit
529 535 */
530 536 public static function esc_limit( $limit ) {
531 537 if ( empty( $limit ) ) {
532 538 return '';
@@ -561,22 +567,20 @@
561 567 }
562 568
563 569 /**
564 570 * @since 2.05.06
565 - *
566 - * @param string $starts_with
567 - * @param array|string $where
568 - * @return string
569 571 */
570 572 public static function prepend_and_or_where( $starts_with = ' WHERE ', $where = '' ) {
571 573 if ( empty( $where ) ) {
572 574 $where = '';
573 - } elseif ( is_array( $where ) ) {
575 + } else {
576 + if ( is_array( $where ) ) {
574 577 global $wpdb;
575 578 self::get_where_clause_and_values( $where, $starts_with );
576 579 $where = $wpdb->prepare( $where['where'], $where['values'] ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
577 - } else {
578 - $where = $starts_with . $where;
580 + } else {
581 + $where = $starts_with . $where;
582 + }
579 583 }
580 584
581 585 /**
582 586 * Allows modifying where clause when using FrmDb::prepend_and_or_where() method.
@@ -591,12 +595,12 @@
591 595
592 596 /**
593 597 * Prepare and save settings in styles and actions
594 598 *
599 + * @param array $settings
600 + * @param string $group
601 + *
595 602 * @since 2.05.06
596 - * @param array $settings
597 - * @param string $group
598 - * @return int|WP_Error
599 603 */
600 604 public static function save_settings( $settings, $group ) {
601 605 $settings = (array) $settings;
602 606 $settings['post_content'] = FrmAppHelper::prepare_and_encode( $settings['post_content'] );
@@ -618,11 +622,8 @@
618 622 *
619 623 * Used when saving form actions and styles
620 624 *
621 625 * @since 2.05.06
622 - *
623 - * @param array $settings
624 - * @return int|WP_Error
625 626 */
626 627 public static function save_json_post( $settings ) {
627 628 global $wp_filter;
628 629 if ( isset( $wp_filter['content_save_pre'] ) ) {
@@ -646,26 +647,24 @@
646 647 * Check cache before fetching values and saving to cache
647 648 *
648 649 * @since 2.05.06
649 650 *
650 - * @param string $cache_key The unique name for this cache.
651 - * @param string $group The name of the cache group.
652 - * @param string $query If blank, don't run a db call.
653 - * @param string $type The wpdb function to use with this query.
651 + * @param string $cache_key The unique name for this cache
652 + * @param string $group The name of the cache group
653 + * @param string $query If blank, don't run a db call
654 + * @param string $type The wpdb function to use with this query
654 655 *
655 656 * @return mixed $results The cache or query results
656 657 */
657 658 public static function check_cache( $cache_key, $group = '', $query = '', $type = 'get_var', $time = 300 ) {
658 - $found = null;
659 - $results = wp_cache_get( $cache_key, $group, false, $found );
660 -
661 - if ( ( $found === true && $results !== false ) || empty( $query ) ) {
659 + $results = wp_cache_get( $cache_key, $group );
660 + if ( ! FrmAppHelper::is_empty_value( $results, false ) || empty( $query ) ) {
662 661 return $results;
663 662 }
664 663
665 664 if ( 'get_posts' == $type ) {
666 665 $results = get_posts( $query );
667 - } elseif ( 'get_associative_results' === $type ) {
666 + } elseif ( 'get_associative_results' == $type ) {
668 667 global $wpdb;
669 668 $results = $wpdb->get_results( $query, OBJECT_K ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
670 669 } else {
671 670 global $wpdb;
@@ -725,9 +724,9 @@
725 724 * Delete all caching in a single group
726 725 *
727 726 * @since 2.05.06
728 727 *
729 - * @param string $group The name of the cache group.
728 + * @param string $group The name of the cache group
730 729 */
731 730 public static function cache_delete_group( $group ) {
732 731 $cached_keys = self::get_group_cached_keys( $group );
733 732
@@ -740,20 +739,27 @@
740 739 }
741 740 }
742 741
743 742 /**
744 - * Checks if a DB column exists.
745 - *
746 - * @since 6.7
747 - *
748 - * @param string $table Table name without `$wpdb->prefix`.
749 - * @param string $column Column name.
750 - * @return bool
743 + * @deprecated 2.05.06
744 + * @codeCoverageIgnore
751 745 */
752 - public static function db_column_exists( $table, $column ) {
753 - global $wpdb;
746 + public function upgrade() {
747 + FrmDeprecated::upgrade();
748 + }
754 749
755 - // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
756 - $result = $wpdb->get_results( $wpdb->prepare( 'SHOW COLUMNS FROM ' . $wpdb->prefix . $table . ' LIKE %s', $column ) );
757 - return ! empty( $result );
750 + /**
751 + * @deprecated 2.05.06
752 + * @codeCoverageIgnore
753 + */
754 + public function collation() {
755 + return FrmDeprecated::collation();
756 + }
757 +
758 + /**
759 + * @deprecated 2.05.06
760 + * @codeCoverageIgnore
761 + */
762 + public function uninstall() {
763 + FrmDeprecated::uninstall();
758 764 }
759 765 }