PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.0
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.0
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 +156 -257 6.286.0 View file →
@@ -3,35 +3,11 @@
3 3 die( 'You are not allowed to call this page directly.' );
4 4 }
5 5
6 6 class FrmDb {
7 -
8 - /**
9 - * The table name for Formidable Fields.
10 - *
11 - * @var string
12 - */
13 7 public $fields;
14 -
15 - /**
16 - * The table name for Formidable Forms.
17 - *
18 - * @var string
19 - */
20 8 public $forms;
21 -
22 - /**
23 - * The table name for Formidable Entries.
24 - *
25 - * @var string
26 - */
27 9 public $entries;
28 -
29 - /**
30 - * The table name for Formidable Entry Metas.
31 - *
32 - * @var string
33 - */
34 10 public $entry_metas;
35 11
36 12 public function __construct() {
37 13 if ( ! defined( 'ABSPATH' ) ) {
@@ -48,16 +24,14 @@
48 24
49 25 /**
50 26 * Change array into format $wpdb->prepare can use
51 27 *
52 - * @param array $args
28 + * @param array $args
53 29 * @param string $starts_with
54 - *
55 - * @return void
56 30 */
57 31 public static function get_where_clause_and_values( &$args, $starts_with = ' WHERE ' ) {
58 - if ( ! $args ) {
59 - // Add an arg to prevent prepare from failing
32 + if ( empty( $args ) ) {
33 + // add an arg to prevent prepare from failing
60 34 $args = array(
61 35 'where' => $starts_with . '1=%d',
62 36 'values' => array( 1 ),
63 37 );
@@ -76,18 +50,15 @@
76 50 $args = compact( 'where', 'values' );
77 51 }
78 52
79 53 /**
80 - * @param array $args
54 + * @param array $args
81 55 * @param string $base_where
82 56 * @param string $where
83 - * @param array $values
84 - *
85 - * @return void
57 + * @param array $values
86 58 */
87 59 public static function parse_where_from_array( $args, $base_where, &$where, &$values ) {
88 60 $condition = ' AND';
89 -
90 61 if ( isset( $args['or'] ) ) {
91 62 $condition = ' OR';
92 63 unset( $args['or'] );
93 64 }
@@ -92,16 +63,13 @@
92 63 unset( $args['or'] );
93 64 }
94 65
95 66 foreach ( $args as $key => $value ) {
96 - $where .= $where ? $condition : $base_where;
97 - // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict
98 - $array_inc_null = ! is_numeric( $key ) && is_array( $value ) && in_array( null, $value );
99 -
67 + $where .= empty( $where ) ? $base_where : $condition;
68 + $array_inc_null = ( ! is_numeric( $key ) && is_array( $value ) && in_array( null, $value ) );
100 69 if ( is_numeric( $key ) || $array_inc_null ) {
101 - $where .= ' ( ';
70 + $where .= ' ( ';
102 71 $nested_where = '';
103 -
104 72 if ( $array_inc_null ) {
105 73 foreach ( $value as $val ) {
106 74 $parse_where = array(
107 75 $key => $val,
@@ -111,31 +79,29 @@
111 79 }
112 80 } else {
113 81 self::parse_where_from_array( $value, '', $nested_where, $values );
114 82 }
115 -
116 83 $where .= $nested_where;
117 84 $where .= ' ) ';
118 85 } else {
119 86 self::interpret_array_to_sql( $key, $value, $where, $values );
120 - }//end if
121 - }//end foreach
87 + }
88 + }
122 89 }
123 90
124 91 /**
125 - * @param string $key
126 - * @param array|string|null $value
127 - * @param string $where
128 - * @param array $values
129 - *
130 - * @return void
92 + * @param string $key
93 + * @param string|array $value
94 + * @param string $where
95 + * @param array $values
131 96 */
132 97 private static function interpret_array_to_sql( $key, $value, &$where, &$values ) {
133 98 $key = trim( $key );
134 99
135 - if ( str_contains( $key, 'created_at' ) || str_contains( $key, 'updated_at' ) ) {
136 - $k = explode( ' ', $key );
137 - $where .= ' CAST(' . reset( $k ) . ' as CHAR) ' . str_replace( reset( $k ), '', $key );
100 + if ( strpos( $key, 'created_at' ) !== false || strpos( $key, 'updated_at' ) !== false ) {
101 + $k = explode( ' ', $key );
102 + $where .= ' DATE_FORMAT(' . reset( $k ) . ', %s) ' . str_replace( reset( $k ), '', $key );
103 + $values[] = '%Y-%m-%d %H:%i:%s';
138 104 } else {
139 105 $where .= ' ' . $key;
140 106 }
141 107
@@ -142,30 +108,27 @@
142 108 $lowercase_key = explode( ' ', strtolower( $key ) );
143 109 $lowercase_key = end( $lowercase_key );
144 110
145 111 if ( is_array( $value ) ) {
146 - // Translate array of values to "in"
147 - if ( str_contains( $lowercase_key, 'like' ) ) {
148 - $where = preg_replace( '/' . $key . '$/', '', $where );
112 + // translate array of values to "in"
113 + if ( strpos( $lowercase_key, 'like' ) !== false ) {
114 + $where = preg_replace( '/' . $key . '$/', '', $where );
149 115 $where .= '(';
150 - $start = true;
151 -
116 + $start = true;
152 117 foreach ( $value as $v ) {
153 118 if ( ! $start ) {
154 119 $where .= ' OR ';
155 120 }
156 -
157 121 $start = false;
158 - $where .= $key . ' %s';
122 + $where .= $key . ' %s';
159 123 $values[] = '%' . self::esc_like( $v ) . '%';
160 124 }
161 -
162 125 $where .= ')';
163 - } elseif ( $value ) {
164 - $where .= ' in (' . self::prepare_array_values( $value, '%s' ) . ')';
126 + } elseif ( ! empty( $value ) ) {
127 + $where .= ' in (' . self::prepare_array_values( $value, '%s' ) . ')';
165 128 $values = array_merge( $values, $value );
166 129 }
167 - } elseif ( str_contains( $lowercase_key, 'like' ) ) {
130 + } elseif ( strpos( $lowercase_key, 'like' ) !== false ) {
168 131 /**
169 132 * Allow string to start or end with the value
170 133 * If the key is like% then skip the first % for starts with
171 134 * If the key is %like then skip the last % for ends with
@@ -171,25 +134,25 @@
171 134 * If the key is %like then skip the last % for ends with
172 135 */
173 136 $start = '%';
174 137 $end = '%';
175 -
176 - if ( $lowercase_key === 'like%' ) {
138 + if ( $lowercase_key == 'like%' ) {
177 139 $start = '';
178 140 $where = rtrim( $where, '%' );
179 - } elseif ( $lowercase_key === '%like' ) {
180 - $end = '';
181 - $where = rtrim( rtrim( $where, '%like' ), '%LIKE' );
141 + } elseif ( $lowercase_key == '%like' ) {
142 + $end = '';
143 + $where = rtrim( rtrim( $where, '%like' ), '%LIKE' );
182 144 $where .= 'like';
183 145 }
184 146
185 - $where .= ' %s';
147 + $where .= ' %s';
186 148 $values[] = $start . self::esc_like( $value ) . $end;
149 +
187 150 } elseif ( $value === null ) {
188 151 $where .= ' IS NULL';
189 152 } else {
190 153 // allow a - to prevent = from being added
191 - if ( str_ends_with( $key, '-' ) ) {
154 + if ( substr( $key, - 1 ) == '-' ) {
192 155 $where = rtrim( $where, '-' );
193 156 } else {
194 157 $where .= '=';
195 158 }
@@ -196,9 +159,9 @@
196 159
197 160 self::add_query_placeholder( $key, $value, $where );
198 161
199 162 $values[] = $value;
200 - }//end if
163 + }
201 164 }
202 165
203 166 /**
204 167 * Add %d, or %s to query
@@ -204,18 +167,15 @@
204 167 * Add %d, or %s to query
205 168 *
206 169 * @since 2.02.05
207 170 *
208 - * @param string $key
171 + * @param string $key
209 172 * @param int|string $value
210 - * @param string $where
211 - *
212 - * @return void
173 + * @param string $where
213 174 */
214 175 private static function add_query_placeholder( $key, $value, &$where ) {
215 - if ( is_numeric( $value ) && ( ! str_contains( $key, 'meta_value' ) || str_contains( $key, '+0' ) ) ) {
216 - // Switch string to number.
217 - $value = $value + 0;
176 + if ( is_numeric( $value ) && ( strpos( $key, 'meta_value' ) === false || strpos( $key, '+0' ) !== false ) ) {
177 + $value = $value + 0; // switch string to number
218 178 $where .= is_float( $value ) ? '%f' : '%d';
219 179 } else {
220 180 $where .= '%s';
221 181 }
@@ -222,41 +182,43 @@
222 182 }
223 183
224 184 /**
225 185 * @param string $table
226 - * @param array $where
227 - * @param array $args
186 + * @param array $where
187 + * @param array $args
228 188 *
229 189 * @return int
230 190 */
231 191 public static function get_count( $table, $where = array(), $args = array() ) {
232 192 $count = self::get_var( $table, $where, 'COUNT(*)', $args );
193 +
233 194 return (int) $count;
234 195 }
235 196
236 197 /**
237 198 * @param string $table
238 - * @param array $where
199 + * @param array $where
239 200 * @param string $field
240 - * @param array $args
201 + * @param array $args
241 202 * @param string $limit
242 203 * @param string $type
243 204 *
244 - * @return array|object|string|null
205 + * @return array|null|string|object
245 206 */
246 207 public static function get_var( $table, $where = array(), $field = 'id', $args = array(), $limit = '', $type = 'var' ) {
247 208 $group = '';
248 209 self::get_group_and_table_name( $table, $group );
249 210 self::convert_options_to_array( $args, '', $limit );
250 -
251 211 if ( $type === 'var' && ! isset( $args['limit'] ) ) {
252 212 $args['limit'] = 1;
253 213 }
254 214
255 - $query = self::generate_query_string_from_pieces( $field, $table, $where, $args );
215 + $query = self::generate_query_string_from_pieces( $field, $table, $where, $args );
216 +
256 217 $cache_key = self::generate_cache_key( $where, $args, $field, $type );
218 + $results = self::check_cache( $cache_key, $group, $query, 'get_' . $type );
257 219
258 - return self::check_cache( $cache_key, $group, $query, 'get_' . $type );
220 + return $results;
259 221 }
260 222
261 223 /**
262 224 * Generate a cache key from the where query, field, type, and other arguments
@@ -262,10 +224,10 @@
262 224 * Generate a cache key from the where query, field, type, and other arguments
263 225 *
264 226 * @since 2.03.07
265 227 *
266 - * @param array $where
267 - * @param array $args
228 + * @param array $where
229 + * @param array $args
268 230 * @param string $field
269 231 * @param string $type
270 232 *
271 233 * @return string
@@ -272,26 +234,25 @@
272 234 */
273 235 public static function generate_cache_key( $where, $args, $field, $type ) {
274 236 $cache_key = '';
275 237 $where = FrmAppHelper::array_flatten( $where );
276 -
277 238 foreach ( $where as $key => $value ) {
278 239 $cache_key .= $key . '_' . $value;
279 240 }
280 -
281 241 $cache_key .= implode( '_', $args ) . $field . '_' . $type;
242 + $cache_key = str_replace( array( ' ', ',' ), '_', $cache_key );
282 243
283 - return str_replace( array( ' ', ',' ), '_', $cache_key );
244 + return $cache_key;
284 245 }
285 246
286 247 /**
287 248 * @param string $table
288 - * @param array $where
249 + * @param array $where
289 250 * @param string $field
290 - * @param array $args
251 + * @param array $args
291 252 * @param string $limit
292 253 *
293 - * @return array
254 + * @return mixed
294 255 */
295 256 public static function get_col( $table, $where = array(), $field = 'id', $args = array(), $limit = '' ) {
296 257 return self::get_var( $table, $where, $field, $args, $limit, 'col' );
297 258 }
@@ -299,16 +260,17 @@
299 260 /**
300 261 * @since 2.0
301 262 *
302 263 * @param string $table
303 - * @param array $where
264 + * @param array $where
304 265 * @param string $fields
305 - * @param array $args
266 + * @param array $args
306 267 *
307 268 * @return mixed
308 269 */
309 270 public static function get_row( $table, $where = array(), $fields = '*', $args = array() ) {
310 271 $args['limit'] = 1;
272 +
311 273 return self::get_var( $table, $where, $fields, $args, '', 'row' );
312 274 }
313 275
314 276 /**
@@ -316,13 +278,13 @@
316 278 *
317 279 * @since 2.0
318 280 *
319 281 * @param string $table
320 - * @param array $where
282 + * @param array $where
321 283 * @param string $fields
322 - * @param array $args
284 + * @param array $args
323 285 *
324 - * @return array
286 + * @return mixed
325 287 */
326 288 public static function get_results( $table, $where = array(), $fields = '*', $args = array() ) {
327 289 return self::get_var( $table, $where, $fields, $args, '', 'results' );
328 290 }
@@ -349,17 +311,15 @@
349 311 '%like' => '%like',
350 312 );
351 313
352 314 $where_is = strtolower( $where_is );
353 -
354 315 if ( isset( $switch_to[ $where_is ] ) ) {
355 316 return ' ' . $switch_to[ $where_is ];
356 317 }
357 318
358 319 // > and < need a little more work since we don't want them switched to >= and <=
359 - if ( $where_is === '>' || $where_is === '<' ) {
360 - // The - indicates that the = should not be added later.
361 - return ' ' . $where_is . '-';
320 + if ( $where_is == '>' || $where_is == '<' ) {
321 + return ' ' . $where_is . '-'; // the - indicates that the = should not be added later
362 322 }
363 323
364 324 // fallback to = if the query is none of these
365 325 return '';
@@ -370,26 +330,24 @@
370 330 * Also add the wpdb->prefix to the table if it's missing
371 331 *
372 332 * @param string $table
373 333 * @param string $group
374 - *
375 - * @return void
376 334 */
377 335 private static function get_group_and_table_name( &$table, &$group ) {
378 - global $wpdb;
336 + global $wpdb, $wpmuBaseTablePrefix;
379 337
380 338 $table_parts = explode( ' ', $table );
381 339 $group = reset( $table_parts );
382 340 self::maybe_remove_prefix( $wpdb->prefix, $group );
383 341
384 - $prefix = $wpdb->base_prefix;
342 + $prefix = $wpmuBaseTablePrefix ? $wpmuBaseTablePrefix : $wpdb->base_prefix;
385 343 self::maybe_remove_prefix( $prefix, $group );
386 344
387 - if ( $group === $table ) {
345 + if ( $group == $table ) {
388 346 $table = $wpdb->prefix . $table;
389 347 }
390 348
391 - // Switch to singular group name
349 + // switch to singular group name
392 350 $group = rtrim( $group, 's' );
393 351 }
394 352
395 353 /**
@@ -395,44 +353,30 @@
395 353 /**
396 354 * Only remove the db prefix when at the beginning.
397 355 *
398 356 * @since 4.04.02
399 - *
400 - * @param string $prefix Prefix to remove.
401 - * @param string $name Name to strip prefix from, passed by reference.
402 - *
403 - * @return void
404 357 */
405 358 private static function maybe_remove_prefix( $prefix, &$name ) {
406 - if ( str_starts_with( $name, $prefix ) ) {
359 + if ( substr( $name, 0, strlen( $prefix ) ) === $prefix ) {
407 360 $name = substr( $name, strlen( $prefix ) );
408 361 }
409 362 }
410 363
411 - /**
412 - * @param array|string $args
413 - * @param string $order_by
414 - * @param int|string $limit
415 - *
416 - * @return void
417 - */
418 364 private static function convert_options_to_array( &$args, $order_by = '', $limit = '' ) {
419 365 if ( ! is_array( $args ) ) {
420 366 $args = array( 'order_by' => $args );
421 367 }
422 368
423 - if ( $order_by ) {
369 + if ( ! empty( $order_by ) ) {
424 370 $args['order_by'] = $order_by;
425 371 }
426 372
427 - if ( $limit ) {
373 + if ( ! empty( $limit ) ) {
428 374 $args['limit'] = $limit;
429 375 }
430 376
431 377 $temp_args = $args;
432 -
433 378 foreach ( $temp_args as $k => $v ) {
434 - // phpcs:ignore Universal.Operators.StrictComparisons
435 379 if ( $v == '' ) {
436 380 unset( $args[ $k ] );
437 381 continue;
438 382 }
@@ -437,22 +381,19 @@
437 381 continue;
438 382 }
439 383
440 384 $db_name = strtoupper( str_replace( '_', ' ', $k ) );
441 -
442 - if ( ! str_contains( $v, $db_name ) ) {
385 + if ( strpos( $v, $db_name ) === false ) {
443 386 $args[ $k ] = $db_name . ' ' . $v;
444 387 }
445 388 }
446 389
447 390 // Make sure LIMIT is the last argument
448 - if ( ! isset( $args['order_by'] ) || ! isset( $args['limit'] ) ) {
449 - return;
391 + if ( isset( $args['order_by'] ) && isset( $args['limit'] ) ) {
392 + $temp_limit = $args['limit'];
393 + unset( $args['limit'] );
394 + $args['limit'] = $temp_limit;
450 395 }
451 -
452 - $temp_limit = $args['limit'];
453 - unset( $args['limit'] );
454 - $args['limit'] = $temp_limit;
455 396 }
456 397
457 398 /**
458 399 * Get the associative array results for the given columns, table, and where query
@@ -460,9 +401,9 @@
460 401 * @since 2.02.05
461 402 *
462 403 * @param string $columns
463 404 * @param string $table
464 - * @param array $where
405 + * @param array $where
465 406 *
466 407 * @return mixed
467 408 */
468 409 public static function get_associative_array_results( $columns, $table, $where ) {
@@ -468,12 +409,14 @@
468 409 public static function get_associative_array_results( $columns, $table, $where ) {
469 410 $group = '';
470 411 self::get_group_and_table_name( $table, $group );
471 412
472 - $query = self::generate_query_string_from_pieces( $columns, $table, $where );
413 + $query = self::generate_query_string_from_pieces( $columns, $table, $where );
414 +
473 415 $cache_key = str_replace( array( ' ', ',' ), '_', trim( implode( '_', FrmAppHelper::array_flatten( $where ) ) . $columns . '_results_ARRAY_A', ' WHERE' ) );
416 + $results = self::check_cache( $cache_key, $group, $query, 'get_associative_results' );
474 417
475 - return self::check_cache( $cache_key, $group, $query, 'get_associative_results' );
418 + return $results;
476 419 }
477 420
478 421 /**
479 422 * Combine the pieces of a query to form a full, prepared query
@@ -481,10 +424,10 @@
481 424 * @since 2.02.05
482 425 *
483 426 * @param string $columns
484 427 * @param string $table
485 - * @param mixed $where
486 - * @param array $args
428 + * @param mixed $where
429 + * @param array $args
487 430 *
488 431 * @return string
489 432 */
490 433 private static function generate_query_string_from_pieces( $columns, $table, $where, $args = array() ) {
@@ -491,35 +434,35 @@
491 434 $query = 'SELECT ' . $columns . ' FROM ' . $table;
492 435
493 436 self::esc_query_args( $args );
494 437
495 - if ( ! is_array( $where ) && $where ) {
496 - return $query;
438 + if ( is_array( $where ) || empty( $where ) ) {
439 + self::get_where_clause_and_values( $where );
440 + global $wpdb;
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 );
497 449 }
498 450
499 - self::get_where_clause_and_values( $where );
500 - global $wpdb;
501 -
502 - // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
503 - return $wpdb->prepare( $query . $where['where'] . ' ' . implode( ' ', $args ), $where['values'] );
451 + return $query;
504 452 }
505 453
506 454 /**
507 455 * @since 2.05.07
508 - *
509 - * @param array $args Query arguments, passed by reference.
510 - *
511 - * @return void
512 456 */
513 457 private static function esc_query_args( &$args ) {
514 458 foreach ( $args as $param => $value ) {
515 - if ( $param === 'order_by' ) {
459 + if ( $param == 'order_by' ) {
516 460 $args[ $param ] = self::esc_order( $value );
517 - } elseif ( $param === 'limit' ) {
461 + } elseif ( $param == 'limit' ) {
518 462 $args[ $param ] = self::esc_limit( $value );
519 463 }
520 464
521 - // phpcs:ignore Universal.Operators.StrictComparisons
522 465 if ( $args[ $param ] == '' ) {
523 466 unset( $args[ $param ] );
524 467 }
525 468 }
@@ -525,18 +468,19 @@
525 468 }
526 469 }
527 470
528 471 /**
529 - * Added for < WP 4.0 compatibility
472 + * Added for < WP 4.0 compatability
530 473 *
531 474 * @since 2.05.06
532 475 *
533 - * @param string $term The value to escape.
476 + * @param string $term The value to escape
534 477 *
535 478 * @return string The escaped value
536 479 */
537 480 public static function esc_like( $term ) {
538 481 global $wpdb;
482 +
539 483 return $wpdb->esc_like( $term );
540 484 }
541 485
542 486 /**
@@ -542,33 +486,29 @@
542 486 /**
543 487 * @since 2.05.06
544 488 *
545 489 * @param string $order_query
546 - *
547 - * @return string
548 490 */
549 491 public static function esc_order( $order_query ) {
550 - if ( ! $order_query ) {
492 + if ( empty( $order_query ) ) {
551 493 return '';
552 494 }
553 495
554 - // Remove ORDER BY before sanitizing.
496 + // remove ORDER BY before santizing
555 497 $order_query = strtolower( $order_query );
556 -
557 - if ( str_contains( $order_query, 'order by' ) ) {
498 + if ( strpos( $order_query, 'order by' ) !== false ) {
558 499 $order_query = str_replace( 'order by', '', $order_query );
559 500 }
560 501
561 502 $order_query = explode( ' ', trim( $order_query ) );
562 - $order = trim( reset( $order_query ) );
563 - $safe_order = array( 'count(*)' );
564 503
565 - if ( ! in_array( strtolower( $order ), $safe_order, true ) ) {
504 + $order = trim( reset( $order_query ) );
505 + $safe_order = array( 'count(*)' );
506 + if ( ! in_array( strtolower( $order ), $safe_order ) ) {
566 507 $order = preg_replace( '/[^a-zA-Z0-9\-\_\.\+]/', '', $order );
567 508 }
568 509
569 510 $order_by = '';
570 -
571 511 if ( count( $order_query ) > 1 ) {
572 512 $order_by = end( $order_query );
573 513 self::esc_order_by( $order_by );
574 514 }
@@ -579,41 +519,32 @@
579 519 /**
580 520 * Make sure this is ordering by either ASC or DESC
581 521 *
582 522 * @since 2.05.06
583 - *
584 - * @param string $order_by Sort direction, passed by reference.
585 - *
586 - * @return void
587 523 */
588 524 public static function esc_order_by( &$order_by ) {
589 525 $sort_options = array( 'asc', 'desc' );
590 -
591 - if ( ! in_array( strtolower( $order_by ), $sort_options, true ) ) {
526 + if ( ! in_array( strtolower( $order_by ), $sort_options ) ) {
592 527 $order_by = 'asc';
593 528 }
594 529 }
595 530
596 531 /**
597 - * @since 2.05.06
598 - *
599 532 * @param string $limit
600 533 *
601 - * @return string
534 + * @since 2.05.06
602 535 */
603 536 public static function esc_limit( $limit ) {
604 - if ( ! $limit ) {
537 + if ( empty( $limit ) ) {
605 538 return '';
606 539 }
607 540
608 541 $limit = trim( str_replace( 'limit ', '', strtolower( $limit ) ) );
609 -
610 542 if ( is_numeric( $limit ) ) {
611 543 return ' LIMIT ' . $limit;
612 544 }
613 545
614 546 $limit = explode( ',', trim( $limit ) );
615 -
616 547 foreach ( $limit as $k => $l ) {
617 548 if ( is_numeric( $l ) ) {
618 549 $limit[ $k ] = $l;
619 550 }
@@ -627,36 +558,29 @@
627 558 /**
628 559 * Get an array of values ready to go through $wpdb->prepare
629 560 *
630 561 * @since 2.05.06
631 - *
632 - * @param array $array Array of values.
633 - * @param string $type Placeholder type.
634 - *
635 - * @return string
636 562 */
637 563 public static function prepare_array_values( $array, $type = '%s' ) {
638 564 $placeholders = array_fill( 0, count( $array ), $type );
565 +
639 566 return implode( ', ', $placeholders );
640 567 }
641 568
642 569 /**
643 570 * @since 2.05.06
644 - *
645 - * @param string $starts_with
646 - * @param array|string $where
647 - *
648 - * @return string
649 571 */
650 572 public static function prepend_and_or_where( $starts_with = ' WHERE ', $where = '' ) {
651 - if ( ! $where ) {
573 + if ( empty( $where ) ) {
652 574 $where = '';
653 - } elseif ( is_array( $where ) ) {
654 - global $wpdb;
655 - self::get_where_clause_and_values( $where, $starts_with );
656 - $where = $wpdb->prepare( $where['where'], $where['values'] ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
657 575 } else {
658 - $where = $starts_with . $where;
576 + if ( is_array( $where ) ) {
577 + global $wpdb;
578 + self::get_where_clause_and_values( $where, $starts_with );
579 + $where = $wpdb->prepare( $where['where'], $where['values'] ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
580 + } else {
581 + $where = $starts_with . $where;
582 + }
659 583 }
660 584
661 585 /**
662 586 * Allows modifying where clause when using FrmDb::prepend_and_or_where() method.
@@ -671,14 +595,12 @@
671 595
672 596 /**
673 597 * Prepare and save settings in styles and actions
674 598 *
599 + * @param array $settings
600 + * @param string $group
601 + *
675 602 * @since 2.05.06
676 - *
677 - * @param array|object $settings
678 - * @param string $group
679 - *
680 - * @return int|WP_Error
681 603 */
682 604 public static function save_settings( $settings, $group ) {
683 605 $settings = (array) $settings;
684 606 $settings['post_content'] = FrmAppHelper::prepare_and_encode( $settings['post_content'] );
@@ -686,9 +608,9 @@
686 608 if ( empty( $settings['ID'] ) ) {
687 609 unset( $settings['ID'] );
688 610 }
689 611
690 - // Delete all caches for this group
612 + // delete all caches for this group
691 613 self::cache_delete_group( $group );
692 614
693 615 return self::save_json_post( $settings );
694 616 }
@@ -702,14 +624,12 @@
702 624 *
703 625 * @since 2.05.06
704 626 *
705 627 * @param array $settings
706 - *
707 628 * @return int|WP_Error
708 629 */
709 630 public static function save_json_post( $settings ) {
710 631 global $wp_filter;
711 -
712 632 if ( isset( $wp_filter['content_save_pre'] ) ) {
713 633 $filters = $wp_filter['content_save_pre'];
714 634 }
715 635
@@ -717,9 +637,9 @@
717 637 remove_all_filters( 'content_save_pre' );
718 638
719 639 $post = wp_insert_post( $settings );
720 640
721 - // Add the content filters back for views or posts
641 + // add the content filters back for views or posts
722 642 if ( isset( $filters ) ) {
723 643 $wp_filter['content_save_pre'] = $filters;
724 644 }
725 645
@@ -730,27 +650,24 @@
730 650 * Check cache before fetching values and saving to cache
731 651 *
732 652 * @since 2.05.06
733 653 *
734 - * @param string $cache_key The unique name for this cache.
735 - * @param string $group The name of the cache group.
736 - * @param string $query If blank, don't run a db call.
737 - * @param string $type The wpdb function to use with this query.
738 - * @param int $time Cache expiration time in seconds.
654 + * @param string $cache_key The unique name for this cache
655 + * @param string $group The name of the cache group
656 + * @param string $query If blank, don't run a db call
657 + * @param string $type The wpdb function to use with this query
739 658 *
740 659 * @return mixed $results The cache or query results
741 660 */
742 661 public static function check_cache( $cache_key, $group = '', $query = '', $type = 'get_var', $time = 300 ) {
743 - $found = null;
744 - $results = wp_cache_get( $cache_key, $group, false, $found );
745 -
746 - if ( ( $found === true && $results !== false ) || ! $query ) {
662 + $results = wp_cache_get( $cache_key, $group );
663 + if ( ! FrmAppHelper::is_empty_value( $results, false ) || empty( $query ) ) {
747 664 return $results;
748 665 }
749 666
750 - if ( 'get_posts' === $type ) {
667 + if ( 'get_posts' == $type ) {
751 668 $results = get_posts( $query );
752 - } elseif ( 'get_associative_results' === $type ) {
669 + } elseif ( 'get_associative_results' == $type ) {
753 670 global $wpdb;
754 671 $results = $wpdb->get_results( $query, OBJECT_K ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
755 672 } else {
756 673 global $wpdb;
@@ -763,15 +680,8 @@
763 680 }
764 681
765 682 /**
766 683 * @since 2.05.06
767 - *
768 - * @param string $cache_key The unique name for this cache.
769 - * @param mixed $results Cached results.
770 - * @param string $group The name of the cache group.
771 - * @param int $time Cache expiration time in seconds.
772 - *
773 - * @return void
774 684 */
775 685 public static function set_cache( $cache_key, $results, $group = '', $time = 300 ) {
776 686 if ( ! FrmAppHelper::prevent_caching() ) {
777 687 self::add_key_to_group_cache( $cache_key, $group );
@@ -783,13 +693,8 @@
783 693 * Keep track of the keys cached in each group so they can be deleted
784 694 * in Redis and Memcache
785 695 *
786 696 * @since 2.05.06
787 - *
788 - * @param string $key Cache key.
789 - * @param string $group Cache group name.
790 - *
791 - * @return void
792 697 */
793 698 public static function add_key_to_group_cache( $key, $group ) {
794 699 $cached = self::get_group_cached_keys( $group );
795 700 $cached[ $key ] = $key;
@@ -797,18 +702,13 @@
797 702 }
798 703
799 704 /**
800 705 * @since 2.05.06
801 - *
802 - * @param string $group Cache group name.
803 - *
804 - * @return array
805 706 */
806 707 public static function get_group_cached_keys( $group ) {
807 708 $cached = wp_cache_get( 'cached_keys', $group );
808 -
809 709 if ( ! $cached || ! is_array( $cached ) ) {
810 - return array();
710 + $cached = array();
811 711 }
812 712
813 713 return $cached;
814 714 }
@@ -815,12 +715,9 @@
815 715
816 716 /**
817 717 * @since 2.05.06
818 718 *
819 - * @param string $cache_key Cache key to delete.
820 - * @param string $group Cache group name.
821 - *
822 - * @return void
719 + * @param string $cache_key
823 720 */
824 721 public static function delete_cache_and_transient( $cache_key, $group = 'default' ) {
825 722 delete_transient( $cache_key );
826 723 wp_cache_delete( $cache_key, $group );
@@ -830,40 +727,42 @@
830 727 * Delete all caching in a single group
831 728 *
832 729 * @since 2.05.06
833 730 *
834 - * @param string $group The name of the cache group.
835 - *
836 - * @return void
731 + * @param string $group The name of the cache group
837 732 */
838 733 public static function cache_delete_group( $group ) {
839 734 $cached_keys = self::get_group_cached_keys( $group );
840 735
841 - if ( ! $cached_keys ) {
842 - return;
843 - }
736 + if ( ! empty( $cached_keys ) ) {
737 + foreach ( $cached_keys as $key ) {
738 + wp_cache_delete( $key, $group );
739 + }
844 740
845 - foreach ( $cached_keys as $key ) {
846 - wp_cache_delete( $key, $group );
741 + wp_cache_delete( 'cached_keys', $group );
847 742 }
743 + }
848 744
849 - wp_cache_delete( 'cached_keys', $group );
745 + /**
746 + * @deprecated 2.05.06
747 + * @codeCoverageIgnore
748 + */
749 + public function upgrade() {
750 + FrmDeprecated::upgrade();
850 751 }
851 752
852 753 /**
853 - * Checks if a DB column exists.
854 - *
855 - * @since 6.7
856 - *
857 - * @param string $table Table name without `$wpdb->prefix`.
858 - * @param string $column Column name.
859 - *
860 - * @return bool
754 + * @deprecated 2.05.06
755 + * @codeCoverageIgnore
861 756 */
862 - public static function db_column_exists( $table, $column ) {
863 - global $wpdb;
757 + public function collation() {
758 + return FrmDeprecated::collation();
759 + }
864 760
865 - // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
866 - $result = $wpdb->get_results( $wpdb->prepare( 'SHOW COLUMNS FROM ' . $wpdb->prefix . $table . ' LIKE %s', $column ) );
867 - return ! empty( $result );
761 + /**
762 + * @deprecated 2.05.06
763 + * @codeCoverageIgnore
764 + */
765 + public function uninstall() {
766 + FrmDeprecated::uninstall();
868 767 }
869 768 }