550 | | * @param string $query Query statement with sprintf()-like placeholders |
551 | | * @param array|mixed $args The array of variables to substitute into the query's placeholders if being called like {@link http://php.net/vsprintf vsprintf()}, or the first variable to substitute into the query's placeholders if being called like {@link http://php.net/sprintf sprintf()}. |
552 | | * @param mixed $args,... further variables to substitute into the query's placeholders if being called like {@link http://php.net/sprintf sprintf()}. |
| 562 | * @param string $query Query statement with wpdb->prepare placeholders |
| 563 | * @param array|mixed $args The array of variables to substitute into the query's placeholders if being called compareable to {@link http://php.net/vsprintf vsprintf()}, or the first variable to substitute into the query's placeholders if being called like {@link http://php.net/sprintf sprintf()}. |
| 564 | * @param mixed $args,... further variables to substitute. |
563 | | $query = str_replace("'%s'", '%s', $query); // in case someone mistakenly already singlequoted it |
564 | | $query = str_replace('"%s"', '%s', $query); // doublequote unquoting |
565 | | $query = str_replace('%s', "'%s'", $query); // quote the strings |
| 575 | |
| 576 | $query = $this->_prepare_quote_lits($query); //quote %s in query-pattern |
| 577 | $query = str_replace( array( "''%s''", "\"'%'\"" ), "'%s'", $query ); // in case someone mistakenly already single/double quoted it |
| 578 | |
| 584 | * helper function for prepare() |
| 585 | * |
| 586 | * will quote %s tokens with single quotes |
| 587 | * allowed tokens are: %%, %d and %s |
| 588 | * |
| 589 | * can do strict parsing and return false if the query is |
| 590 | * not valid. |
| 591 | * |
| 592 | * @access private |
| 593 | * @param string $query wpdb prepare-pattern that needs to be single-quoted to %s |
| 594 | * @param bool $strict (optional) wether or not do strict parsing of the query |
| 595 | * @return string pattern with single quotes added around %s literals |
| 596 | * @return bool false on syntax error if $strict param is true |
| 597 | */ |
| 598 | function _prepare_quote_lits( $query, $strict = false ) { |
| 599 | $query = (string) $query; |
| 600 | $m = strlen( $query ); |
| 601 | for ( $i = -1; $c = $query[++$i], $i < $m; ) { |
| 602 | if ( '%' == $c ) { |
| 603 | switch ( $query[$i+1] ) { |
| 604 | case 's': |
| 605 | $query = substr( $query, 0, $i) . "'%s'" . substr( $query, $i+=2 ); |
| 606 | case '%': |
| 607 | case 'd': |
| 608 | $i++; |
| 609 | break; |
| 610 | default: # illegal pattern |
| 611 | if ( $strict ) return false; |
| 612 | } |
| 613 | } |
| 614 | } |
| 615 | return $query; |
| 616 | } |
| 617 | |
| 618 | /** |