| @@ -148,11 +148,11 @@ | ||
| 148 | 148 | $where_clause = " AND (post_title LIKE %s)"; |
| 149 | 149 | $sql_params[] = '%' . $wpdb->esc_like($keyword) . '%'; |
| 150 | 150 | } |
| 151 | 151 | |
| 152 | - // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter | |
| 152 | + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter | |
| 153 | 153 | $results = $wpdb->get_results( $wpdb->prepare( |
| 154 | - "SELECT * FROM " . $wpdb->prefix . "posts WHERE post_status = %s " . $where_clause . " ORDER BY ID DESC LIMIT %d", | |
| 154 | + "SELECT * FROM " . $wpdb->prefix . "posts WHERE post_status = %s " . $where_clause . " ORDER BY ID DESC LIMIT %d", // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared | |
| 155 | 155 | array_merge(['publish'], $sql_params, [$limit]) |
| 156 | 156 | ) ); |
| 157 | 157 | } |
| 158 | 158 | |
| @@ -351,9 +351,9 @@ | ||
| 351 | 351 | |
| 352 | 352 | if ( is_array( $load_more ) && isset( $load_more[ get_locale() ] ) ) { |
| 353 | 353 | $load_more = $load_more[ get_locale() ]; |
| 354 | 354 | } |
| 355 | - if ( is_array( $load_more ) ) { | |
| 355 | + if ( is_array( $load_more ) && ! empty( $load_more ) ) { | |
| 356 | 356 | $load_more = $load_more[ array_rand( $load_more ) ]; |
| 357 | 357 | } |
| 358 | 358 | $searchlimit = ( get_option( 'wppt_number_of_result' ) == '' ? 5 : absint( get_option( 'wppt_number_of_result' ) ) ); |
| 359 | 359 | $orderby = ( get_option( 'wppt_result_orderby' ) == '' ? 'none' : get_option( 'wppt_result_orderby' ) ); |
| @@ -460,9 +460,9 @@ | ||
| 460 | 460 | )); |
| 461 | 461 | } |
| 462 | 462 | } else { |
| 463 | 463 | if ( $orderby != 'none' && $orderby != 'rand' ) { |
| 464 | - // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter | |
| 464 | + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter | |
| 465 | 465 | $results = $wpdb->get_results( $wpdb->prepare( |
| 466 | 466 | "SELECT * FROM " . $wpdb->prefix . "posts |
| 467 | 467 | WHERE post_type = %s |
| 468 | 468 | AND post_status = %s |
| @@ -467,9 +467,9 @@ | ||
| 467 | 467 | WHERE post_type = %s |
| 468 | 468 | AND post_status = %s |
| 469 | 469 | AND (post_title REGEXP %s OR post_content REGEXP %s) |
| 470 | 470 | ORDER BY " . $orderby . " " . $order . " |
| 471 | - LIMIT %d, %d", | |
| 471 | + LIMIT %d, %d", // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared | |
| 472 | 472 | $post_type, |
| 473 | 473 | 'publish', |
| 474 | 474 | '[[:<:]]' . $searchkeyword . '[[:>:]]', |
| 475 | 475 | '[[:<:]]' . $searchkeyword . '[[:>:]]', |
| @@ -636,11 +636,12 @@ | ||
| 636 | 636 | global $wpdb; |
| 637 | 637 | |
| 638 | 638 | $keyword = isset( $_POST['keyword'] ) ? sanitize_text_field(wp_unslash($_POST['keyword'])) : ''; |
| 639 | 639 | |
| 640 | - $table = $wpdb->prefix.'wpbot_response'; | |
| 640 | + $table = $wpdb->prefix . 'wpbot_response'; | |
| 641 | + $table_sql = '`' . esc_sql( $table ) . '`'; | |
| 641 | 642 | |
| 642 | - $result = $wpdb->get_row( $wpdb->prepare("SELECT `response` FROM %i WHERE 1 and `intent` = %s", $table, $keyword) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 643 | + $result = $wpdb->get_row( $wpdb->prepare( "SELECT `response` FROM {$table_sql} WHERE 1 AND `intent` = %s", $keyword ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter | |
| 643 | 644 | |
| 644 | 645 | $response = array('status'=>'fail'); |
| 645 | 646 | |
| 646 | 647 | if(!empty($result)){ |
| @@ -657,9 +658,10 @@ | ||
| 657 | 658 | } |
| 658 | 659 | function qcld_wb_chatbot_email_subscription() { |
| 659 | 660 | |
| 660 | 661 | global $wpdb; |
| 661 | - $table = $wpdb->prefix . 'wpbot_subscription'; | |
| 662 | + $table = $wpdb->prefix . 'wpbot_subscription'; | |
| 663 | + $table_sql = '`' . esc_sql( $table ) . '`'; | |
| 662 | 664 | |
| 663 | 665 | $name = sanitize_text_field( $_POST['name'] );// phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 664 | 666 | $email = sanitize_email( $_POST['email'] );// phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 665 | 667 | $url = esc_url_raw( $_POST['url'] );// phpcs:ignore WordPress.Security.NonceVerification.Missing |
| @@ -669,11 +671,11 @@ | ||
| 669 | 671 | |
| 670 | 672 | $phone = sanitize_text_field( $_POST['phone'] );// phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 671 | 673 | if ( $email != '' ) { |
| 672 | 674 | |
| 673 | - $email_exists = $wpdb->get_row( $wpdb->prepare( "select * from %i where 1 and email = %s", $table, $email ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, PluginCheck.Security.DirectDB.UnescapedDBParameter | |
| 675 | + $email_exists = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$table_sql} WHERE 1 AND email = %s", $email ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter | |
| 674 | 676 | if ( ! empty( $email_exists ) ) { |
| 675 | - $wpdb->update( // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery | |
| 677 | + $wpdb->update( // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 676 | 678 | $table, |
| 677 | 679 | array( |
| 678 | 680 | 'phone' => $phone, |
| 679 | 681 | ), |
| @@ -717,9 +719,9 @@ | ||
| 717 | 719 | |
| 718 | 720 | $response = array(); |
| 719 | 721 | $response['status'] = 'fail'; |
| 720 | 722 | |
| 721 | - $email_exists = $wpdb->get_row( $wpdb->prepare( "select * from %i where 1 and email = %s", $table, $email ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, PluginCheck.Security.DirectDB.UnescapedDBParameter | |
| 723 | + $email_exists = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$table_sql} WHERE 1 AND email = %s", $email ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter | |
| 722 | 724 | if ( empty( $email_exists ) ) { |
| 723 | 725 | |
| 724 | 726 | $wpdb->insert( // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery |
| 725 | 727 | $table, |
| @@ -735,9 +737,15 @@ | ||
| 735 | 737 | $texts = maybe_unserialize( get_option( 'qlcd_wp_email_subscription_success' ) ); |
| 736 | 738 | if ( is_array( $texts ) && isset( $texts[ get_wpbot_locale() ] ) ) { |
| 737 | 739 | $texts = $texts[ get_wpbot_locale() ]; |
| 738 | 740 | } |
| 739 | - $response['msg'] = $texts[ array_rand( $texts ) ]; | |
| 741 | + if ( is_array( $texts ) && ! empty( $texts ) ) { | |
| 742 | + $response['msg'] = $texts[ array_rand( $texts ) ]; | |
| 743 | + } elseif ( is_string( $texts ) && ! empty( $texts ) ) { | |
| 744 | + $response['msg'] = $texts; | |
| 745 | + } else { | |
| 746 | + $response['msg'] = 'Thank you for subscribing.'; | |
| 747 | + } | |
| 740 | 748 | |
| 741 | 749 | } else { |
| 742 | 750 | $texts = maybe_unserialize( get_option( 'qlcd_wp_email_already_subscribe' ) ); |
| 743 | 751 | |
| @@ -744,9 +752,15 @@ | ||
| 744 | 752 | if ( is_array( $texts ) && isset( $texts[ get_wpbot_locale() ] ) ) { |
| 745 | 753 | $texts = $texts[ get_wpbot_locale() ]; |
| 746 | 754 | } |
| 747 | 755 | |
| 748 | - $response['msg'] = $texts[ array_rand( $texts ) ]; | |
| 756 | + if ( is_array( $texts ) && ! empty( $texts ) ) { | |
| 757 | + $response['msg'] = $texts[ array_rand( $texts ) ]; | |
| 758 | + } elseif ( is_string( $texts ) && ! empty( $texts ) ) { | |
| 759 | + $response['msg'] = $texts; | |
| 760 | + } else { | |
| 761 | + $response['msg'] = 'You have already subscribed!'; | |
| 762 | + } | |
| 749 | 763 | } |
| 750 | 764 | |
| 751 | 765 | do_action( 'qcld_mailing_list_subscription_success', $name, $email ); |
| 752 | 766 | |
| @@ -758,9 +772,15 @@ | ||
| 758 | 772 | $offertextss = maybe_unserialize( get_option( 'qlcd_wp_email_subscription_offer_subject' ) ); |
| 759 | 773 | if ( is_array( $offertextss ) && isset( $offertextss[ get_wpbot_locale() ] ) ) { |
| 760 | 774 | $offertextss = $offertextss[ get_wpbot_locale() ]; |
| 761 | 775 | } |
| 762 | - $subject = str_replace( '%%username%%', $name, $offertextss[ array_rand( $offertextss ) ] ); | |
| 776 | + if ( is_array( $offertextss ) && ! empty( $offertextss ) ) { | |
| 777 | + $subject = str_replace( '%%username%%', $name, $offertextss[ array_rand( $offertextss ) ] ); | |
| 778 | + } elseif ( is_string( $offertextss ) && ! empty( $offertextss ) ) { | |
| 779 | + $subject = str_replace( '%%username%%', $name, $offertextss ); | |
| 780 | + } else { | |
| 781 | + $subject = 'Email subscription offer'; | |
| 782 | + } | |
| 763 | 783 | |
| 764 | 784 | } else { |
| 765 | 785 | $subject = 'Email subscription offer'; |
| 766 | 786 | } |
| @@ -766,10 +786,10 @@ | ||
| 766 | 786 | } |
| 767 | 787 | |
| 768 | 788 | // Extract Domain |
| 769 | 789 | $url = get_site_url(); |
| 770 | - $url = parse_url( $url ); | |
| 771 | - $domain = $url['host']; | |
| 790 | + $url = wp_parse_url( $url ); | |
| 791 | + $domain = isset( $url['host'] ) ? $url['host'] : ''; | |
| 772 | 792 | $toEmail = $email; |
| 773 | 793 | $fromEmail = 'wordpress@' . $domain; |
| 774 | 794 | $fromname = ( get_option( 'qlcd_wp_chatbot_from_name' ) ? get_option( 'qlcd_wp_chatbot_from_name' ) : 'WordPress' ); |
| 775 | 795 | |
| @@ -789,11 +809,17 @@ | ||
| 789 | 809 | $offertexts = $offertexts[ get_wpbot_locale() ]; |
| 790 | 810 | } |
| 791 | 811 | // build email body. |
| 792 | 812 | $bodyContent = ''; |
| 793 | - $bodyContent .= '<p><strong>' . esc_html__( 'Offer Details', 'wpchatbot' ) . ':</strong></p><hr>'; | |
| 794 | - $bodyContent .= '<p>' . str_replace( '%%username%%', $name, $offertexts[ array_rand( $offertexts ) ] ) . '</p>'; | |
| 795 | - $bodyContent .= '<p>' . esc_html__( 'Mail Generated on', 'wpchatbot' ) . ': ' . current_time( 'F j, Y, g:i a' ) . '</p>'; | |
| 813 | + $bodyContent .= '<p><strong>' . esc_html__( 'Offer Details', 'chatbot' ) . ':</strong></p><hr>'; | |
| 814 | + if ( is_array( $offertexts ) && ! empty( $offertexts ) ) { | |
| 815 | + $bodyContent .= '<p>' . str_replace( '%%username%%', $name, $offertexts[ array_rand( $offertexts ) ] ) . '</p>'; | |
| 816 | + } elseif ( is_string( $offertexts ) && ! empty( $offertexts ) ) { | |
| 817 | + $bodyContent .= '<p>' . str_replace( '%%username%%', $name, $offertexts ) . '</p>'; | |
| 818 | + } else { | |
| 819 | + $bodyContent .= '<p></p>'; | |
| 820 | + } | |
| 821 | + $bodyContent .= '<p>' . esc_html__( 'Mail Generated on', 'chatbot' ) . ': ' . current_time( 'F j, Y, g:i a' ) . '</p>'; | |
| 796 | 822 | $to = $toEmail; |
| 797 | 823 | $body = $bodyContent; |
| 798 | 824 | |
| 799 | 825 | $headers = array(); |
| @@ -820,8 +846,9 @@ | ||
| 820 | 846 | if ( count( $array ) == 0 ) { |
| 821 | 847 | return null; |
| 822 | 848 | } |
| 823 | 849 | ob_start(); |
| 850 | + // phpcs:disable WordPress.WP.AlternativeFunctions.file_system_operations_fopen, WordPress.WP.AlternativeFunctions.file_system_operations_fclose -- php://output memory stream for CSV export. | |
| 824 | 851 | $df = fopen( 'php://output', 'w' ); |
| 825 | 852 | fputcsv( $df, array( 'Name', 'Email' ), ',', '"', '\\' ); |
| 826 | 853 | foreach ( $array as $row ) { |
| 827 | 854 | fputcsv( $df, $row, ',', '"', '\\' ); |
| @@ -826,8 +853,9 @@ | ||
| 826 | 853 | foreach ( $array as $row ) { |
| 827 | 854 | fputcsv( $df, $row, ',', '"', '\\' ); |
| 828 | 855 | } |
| 829 | 856 | fclose( $df ); |
| 857 | + // phpcs:enable WordPress.WP.AlternativeFunctions.file_system_operations_fopen, WordPress.WP.AlternativeFunctions.file_system_operations_fclose | |
| 830 | 858 | return ob_get_clean(); |
| 831 | 859 | } |
| 832 | 860 | } |
| 833 | 861 | |
| @@ -832,15 +860,16 @@ | ||
| 832 | 860 | } |
| 833 | 861 | |
| 834 | 862 | function qcld_wpb_export_email_csv() { |
| 835 | 863 | global $wpdb; |
| 836 | - $table = $wpdb->prefix . 'wpbot_subscription'; | |
| 864 | + $table = $wpdb->prefix . 'wpbot_subscription'; | |
| 865 | + $table_sql = '`' . esc_sql( $table ) . '`'; | |
| 837 | 866 | |
| 838 | 867 | if ( ! current_user_can( 'manage_options' ) ) { |
| 839 | 868 | return; |
| 840 | 869 | } |
| 841 | 870 | |
| 842 | - $emails = $wpdb->get_results( $wpdb->prepare( "select * from %i WHERE %d", $table, 1 ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, PluginCheck.Security.DirectDB.UnescapedDBParameter | |
| 871 | + $emails = $wpdb->get_results( "SELECT * FROM {$table_sql}" ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter | |
| 843 | 872 | $childArray = array(); |
| 844 | 873 | foreach ( $emails as $email ) { |
| 845 | 874 | $innerArray = array(); |
| 846 | 875 | $innerArray[0] = $email->name; |
| @@ -873,11 +902,12 @@ | ||
| 873 | 902 | |
| 874 | 903 | if( !function_exists( 'wpbo_search_response_catlist' )){ |
| 875 | 904 | function wpbo_search_response_catlist(){ |
| 876 | 905 | global $wpdb; |
| 877 | - $table = $wpdb->prefix.'wpbot_response_category'; | |
| 878 | - $status = array('status'=>'fail'); | |
| 879 | - $results = $wpdb->get_results($wpdb->prepare("SELECT * FROM %i", $table)); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 906 | + $table = $wpdb->prefix . 'wpbot_response_category'; | |
| 907 | + $table_sql = '`' . esc_sql( $table ) . '`'; | |
| 908 | + $status = array( 'status' => 'fail' ); | |
| 909 | + $results = $wpdb->get_results( "SELECT * FROM {$table_sql}" ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter | |
| 880 | 910 | $response_result = array(); |
| 881 | 911 | |
| 882 | 912 | if(!empty($results)){ |
| 883 | 913 | foreach($results as $result){ |
| @@ -907,19 +937,19 @@ | ||
| 907 | 937 | |
| 908 | 938 | function qcld_wpbo_search_response(){ |
| 909 | 939 | |
| 910 | 940 | global $wpdb; |
| 911 | - $keyword = isset( $_POST['keyword'] ) ? (sanitize_text_field(wp_unslash($_POST['keyword']))) : ''; | |
| 912 | - $strid = isset( $_POST['strid'] ) ? (sanitize_text_field(wp_unslash($_POST['strid']))) : ''; | |
| 913 | - $table = $wpdb->prefix.'wpbot_response'; | |
| 914 | - | |
| 941 | + $keyword = isset( $_POST['keyword'] ) ? ( sanitize_text_field( wp_unslash( $_POST['keyword'] ) ) ) : ''; | |
| 942 | + $strid = isset( $_POST['strid'] ) ? ( sanitize_text_field( wp_unslash( $_POST['strid'] ) ) ) : ''; | |
| 943 | + $table = $wpdb->prefix . 'wpbot_response'; | |
| 944 | + $table_sql = '`' . esc_sql( $table ) . '`'; | |
| 915 | 945 | |
| 916 | 946 | $response_result = array(); |
| 917 | 947 | |
| 918 | - $status = array('status'=>'fail', 'multiple'=>false); | |
| 919 | - $field = "ID"; | |
| 920 | - if(($strid != '') && empty($response_result)){ | |
| 921 | - $results = $wpdb->get_results($wpdb->prepare("SELECT * FROM %i WHERE %i = %d",$table,$field,$strid)); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 948 | + $status = array( 'status' => 'fail', 'multiple' => false ); | |
| 949 | + $field = 'ID'; | |
| 950 | + if ( ( $strid != '' ) && empty( $response_result ) ) { | |
| 951 | + $results = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$table_sql} WHERE `ID` = %d", $strid ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter | |
| 922 | 952 | if(!empty($results)){ |
| 923 | 953 | foreach($results as $result){ |
| 924 | 954 | |
| 925 | 955 | $response_result[] = array('id'=>$result->id,'query'=>$result->query, 'response'=>$result->response, 'score'=>1); |
| @@ -926,10 +956,10 @@ | ||
| 926 | 956 | |
| 927 | 957 | } |
| 928 | 958 | } |
| 929 | 959 | } |
| 930 | - $field = "query"; | |
| 931 | - $results = $wpdb->get_results( $wpdb->prepare("SELECT `id`, `query`, `response` FROM %i WHERE 1 and %i = %s", $table, $field,$keyword) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 960 | + $field = 'query'; | |
| 961 | + $results = $wpdb->get_results( $wpdb->prepare( "SELECT `id`, `query`, `response` FROM {$table_sql} WHERE 1 AND `query` = %s", $keyword ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter | |
| 932 | 962 | |
| 933 | 963 | |
| 934 | 964 | if(!empty($results)){ |
| 935 | 965 | foreach($results as $result){ |
| @@ -938,11 +968,11 @@ | ||
| 938 | 968 | |
| 939 | 969 | } |
| 940 | 970 | } |
| 941 | 971 | |
| 942 | - $field = "category"; | |
| 943 | - if(empty($response_result)){ | |
| 944 | - $results = $wpdb->get_results( $wpdb->prepare("SELECT `id`, `query`, `response` FROM %i WHERE 1 and %i = %s", $table,$field, $keyword) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 972 | + $field = 'category'; | |
| 973 | + if ( empty( $response_result ) ) { | |
| 974 | + $results = $wpdb->get_results( $wpdb->prepare( "SELECT `id`, `query`, `response` FROM {$table_sql} WHERE 1 AND `category` = %s", $keyword ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter | |
| 945 | 975 | |
| 946 | 976 | |
| 947 | 977 | if(!empty($results)){ |
| 948 | 978 | foreach($results as $result){ |
| @@ -990,10 +1020,10 @@ | ||
| 990 | 1020 | } |
| 991 | 1021 | |
| 992 | 1022 | |
| 993 | 1023 | |
| 994 | - // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter | |
| 995 | - $results = $wpdb->get_results( $wpdb->prepare("SELECT `id`, `query`, `response`, MATCH($qfields) AGAINST(%s IN NATURAL LANGUAGE MODE) as score FROM %i WHERE MATCH($qfields) AGAINST(%s IN NATURAL LANGUAGE MODE) order by score desc limit 15",$keyword,$table,$keyword) ); | |
| 1024 | + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter | |
| 1025 | + $results = $wpdb->get_results( $wpdb->prepare( "SELECT `id`, `query`, `response`, MATCH({$qfields}) AGAINST(%s IN NATURAL LANGUAGE MODE) as score FROM {$table_sql} WHERE MATCH({$qfields}) AGAINST(%s IN NATURAL LANGUAGE MODE) order by score desc limit 15", $keyword, $keyword ) ); | |
| 996 | 1026 | |
| 997 | 1027 | $weight = get_option('qc_bot_str_weight')!=''?get_option('qc_bot_str_weight'):'0.4'; |
| 998 | 1028 | |
| 999 | 1029 | if(!empty($results)){ |
| @@ -1007,14 +1037,14 @@ | ||
| 1007 | 1037 | } |
| 1008 | 1038 | } |
| 1009 | 1039 | } |
| 1010 | 1040 | } |
| 1011 | - $field = "keyword"; | |
| 1012 | - if( empty( $response_result ) ){ | |
| 1041 | + $field = 'keyword'; | |
| 1042 | + if ( empty( $response_result ) ) { | |
| 1043 | + | |
| 1044 | + $results = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$table_sql} WHERE `keyword` REGEXP %s", $keyword ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter | |
| 1013 | 1045 | |
| 1014 | - $results = $wpdb->get_results($wpdb->prepare("SELECT * FROM %i WHERE %i REGEXP %s", $table,$field,$keyword)); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 1015 | 1046 | |
| 1016 | - | |
| 1017 | 1047 | if(!empty($results)){ |
| 1018 | 1048 | foreach($results as $result){ |
| 1019 | 1049 | $response_result[] = array('id'=>$result->id,'query'=>$result->query, 'response'=>$result->response, 'score'=>1); |
| 1020 | 1050 | } |
| @@ -1038,10 +1068,10 @@ | ||
| 1038 | 1068 | $keyword2 = preg_replace('/ \?$/', '?', $keyword); |
| 1039 | 1069 | // Try again with new keyword. |
| 1040 | 1070 | // Repeat the main search logic with $keyword2. |
| 1041 | 1071 | $response_result = array(); |
| 1042 | - $field = "query"; | |
| 1043 | - $results = $wpdb->get_results( $wpdb->prepare("SELECT `id`, `query`, `response` FROM %i WHERE 1 and %i = %s", $table, $field, $keyword2) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 1072 | + $field = 'query'; | |
| 1073 | + $results = $wpdb->get_results( $wpdb->prepare( "SELECT `id`, `query`, `response` FROM {$table_sql} WHERE 1 AND `query` = %s", $keyword2 ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter | |
| 1044 | 1074 | if(!empty($results)){ |
| 1045 | 1075 | foreach($results as $result){ |
| 1046 | 1076 | $response_result[] = array('id'=>$result->id,'query'=>$result->query, 'response'=>$result->response, 'score'=>1); |
| 1047 | 1077 | } |
| @@ -1058,9 +1088,9 @@ | ||
| 1058 | 1088 | if(empty($status['data']) || (isset($status['status']) && $status['status']==='fail')){ |
| 1059 | 1089 | // Try a partial match if still nothing found. |
| 1060 | 1090 | if(empty($status['data'])) { |
| 1061 | 1091 | $keyword_like = '%' . preg_replace('/[\\s\\?]+/', '%', $keyword) . '%'; |
| 1062 | - $results = $wpdb->get_results( $wpdb->prepare("SELECT `id`, `query`, `response` FROM %i WHERE `query` LIKE %s", $table, $keyword_like) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 1092 | + $results = $wpdb->get_results( $wpdb->prepare( "SELECT `id`, `query`, `response` FROM {$table_sql} WHERE `query` LIKE %s", $keyword_like ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter | |
| 1063 | 1093 | $response_result = array(); |
| 1064 | 1094 | if(!empty($results)){ |
| 1065 | 1095 | foreach($results as $result){ |
| 1066 | 1096 | $response_result[] = array('id'=>$result->id,'query'=>$result->query, 'response'=>$result->response, 'score'=>1); |