| @@ -3,13 +3,10 @@ | ||
| 3 | 3 | /** |
| 4 | 4 | * AI Assistant Template - RAG Feature Extended |
| 5 | 5 | * @package Botmaster |
| 6 | 6 | */ |
| 7 | -if (get_option('wpchatbot_license_valid') == 'master' && get_option('wpchatbot_license_valid') == 'professional') { | |
| 8 | - update_option('wpchatbot_license_valid', 'starter'); | |
| 9 | -} | |
| 10 | 7 | |
| 11 | -$wpchatbot_license_valid = get_option('wpchatbot_license_valid'); | |
| 8 | +$wpchatbot_license_valid = get_option('wpchatbot_license_valid'); | |
| 12 | 9 | // $wpchatbot_license_valid = 'starter'; |
| 13 | 10 | |
| 14 | 11 | ?> |
| 15 | 12 | |
| @@ -18,9 +15,8 @@ | ||
| 18 | 15 | |
| 19 | 16 | |
| 20 | 17 | <h2 class="nav-tab-wrapper"> |
| 21 | 18 | <a href="#qcld-rag-settings-tab" class="nav-tab nav-tab-active"> Setting options</a> |
| 22 | - <a href="#qcld-rag-settings-sql" class="nav-tab">RAG from DB Tables</a> | |
| 23 | 19 | <a href="#rag-sync" class="nav-tab">Sync and upload options</a> |
| 24 | 20 | <a href="#rag-sources" class="nav-tab">Manage Sources</a> |
| 25 | 21 | <a href="#rag-database" class="nav-tab">KnowledgeBase Database</a> |
| 26 | 22 | </h2> |
| @@ -26,10 +22,10 @@ | ||
| 26 | 22 | </h2> |
| 27 | 23 | |
| 28 | 24 | <div id="qcld-rag-settings-tab" class="qcld-tab-content active"> |
| 29 | 25 | <!-- =========================== |
| 30 | - EMBEDDING SOURCE OPTIONS | |
| 31 | - ============================ --> | |
| 26 | + EMBEDDING SOURCE OPTIONS | |
| 27 | + ============================ --> | |
| 32 | 28 | <div class="wrap"> |
| 33 | 29 | <h3>Choose Data Sources to Embed</h3> |
| 34 | 30 | |
| 35 | 31 | <div class="mb-3"> |
| @@ -65,22 +61,9 @@ | ||
| 65 | 61 | <?php endforeach; ?> |
| 66 | 62 | </div> |
| 67 | 63 | <p class="description">Select multiple custom post types to embed.</p> |
| 68 | 64 | </div> |
| 69 | - <div class="mb-4" style="background: #f9f9f9; padding: 15px; border-radius: 8px; border-left: 4px solid #007bff;"> | |
| 70 | - <h4 style="margin-top: 0;"><i class="fa fa-tags"></i> Post Meta Data Settings <span class="pro-badge" style="display:inline-block; margin-left:8px; padding:2px 6px; background:#f0b429; color:#fff; border-radius:3px; font-size:11px; font-weight:bold; text-transform:uppercase;">PRO</span></h4> | |
| 71 | - <div class="mb-3"> | |
| 72 | - <input type="checkbox" id="rag_embed_meta" <?php checked(get_option('rag_embed_meta'), '1'); ?> disabled> | |
| 73 | - <label for="rag_embed_meta"><strong>Include Post Meta Data</strong></label> | |
| 74 | - <p class="description">Enable this to include custom fields/meta data in the embeddings.</p> | |
| 75 | - </div> | |
| 76 | 65 | |
| 77 | - <div class="mb-3"> | |
| 78 | - <label for="rag_embed_meta_keys"><strong>Meta Keys to Include (comma separated):</strong></label><br> | |
| 79 | - <input type="text" id="rag_embed_meta_keys" value="<?php echo esc_attr(get_option('rag_embed_meta_keys', '')); ?>" placeholder="e.g. _price, _sku, custom_field_key" style="width: 100%; max-width: 400px; margin-top: 5px;" disabled> | |
| 80 | - <p class="description">Specify the meta keys you want to include in the context. Leave empty to include all meta (not recommended).</p> | |
| 81 | - </div> | |
| 82 | - </div> | |
| 83 | 66 | |
| 84 | 67 | </div> |
| 85 | 68 | <!-- =========================== |
| 86 | 69 | EXECUTION BUTTON |
| @@ -113,131 +96,10 @@ | ||
| 113 | 96 | <div class="wrap"> |
| 114 | 97 | <button class="qcld-btn-primary" id="save_rag_setting">Save Settings</button> |
| 115 | 98 | </div> |
| 116 | 99 | </div> |
| 117 | - <div id="qcld-rag-settings-sql" class="qcld-tab-content"> | |
| 118 | - | |
| 119 | - <div class="wrap"> | |
| 120 | - <h3>Choose Data Sources to Embed</h3> | |
| 121 | - <?php if ( $wpchatbot_license_valid != 'master' && $wpchatbot_license_valid != 'professional'): ?> | |
| 122 | - <div class="wrap"> | |
| 123 | - <div style="background-color: #fee; border: 1px solid #c33; padding: 15px; margin: 20px 0; border-radius: 4px;"> | |
| 124 | - <p style="color: #c33; font-weight: bold; margin: 0; font-size: 14px;"> | |
| 125 | - These options are available with the WPBot Pro <a href="https://www.wpbot.pro/pricing/" target="_blank" style="color: #c33; text-decoration: underline;">Professional</a> and <a href="https://www.wpbot.pro/pricing/" target="_blank" style="color: #c33; text-decoration: underline;">Master</a> Licenses | |
| 126 | - </p> | |
| 127 | - </div> | |
| 128 | - </div> | |
| 129 | - <?php endif; ?> | |
| 130 | - <div class="mb-3" style="<?php if ( $wpchatbot_license_valid != 'master' && $wpchatbot_license_valid != 'professional'){ echo 'opacity:0.5; pointer-events:none;'; } ?>"> | |
| 131 | - <input type="checkbox" id="rag_embed_sql" checked disabled <?php checked(get_option('rag_embed_sql'), '1'); ?>> | |
| 132 | - <label for="rag_embed_sql">Database Table (SQL)</label> | |
| 133 | - <div id="rag_sql_options" style=""> | |
| 134 | - <table id="rag_sql_tables_list" class="wp-list-table widefat striped" style="max-width: 600px; margin-bottom: 10px;"> | |
| 135 | - <thead> | |
| 136 | - <tr> | |
| 137 | - <th>Table Name</th> | |
| 138 | - <th>Table Field(s)</th> | |
| 139 | - <th>Actions</th> | |
| 140 | - </tr> | |
| 141 | - </thead> | |
| 142 | - <tbody> | |
| 143 | - <?php | |
| 144 | - $sql_tables = get_option('rag_sql_tables', []); | |
| 145 | - if (!is_array($sql_tables) && !empty($sql_tables)) { | |
| 146 | - $sql_tables = json_decode($sql_tables, true); | |
| 147 | - } | |
| 148 | - | |
| 149 | - if (empty($sql_tables)) { | |
| 150 | - $table_name = get_option('rag_sql_table_name', ''); | |
| 151 | - $table_field = get_option('rag_sql_table_field', ''); | |
| 152 | - if ($table_name && $table_field) { | |
| 153 | - $sql_tables[] = ['table_name' => $table_name, 'table_field' => $table_field]; | |
| 154 | - } | |
| 155 | - } | |
| 156 | 100 | |
| 157 | - if (!empty($sql_tables)) { | |
| 158 | - foreach ($sql_tables as $table) { | |
| 159 | - ?> | |
| 160 | - <tr> | |
| 161 | - <td><input type="text" name="rag_sql_table_name[]" value="<?php echo esc_attr($table['table_name']); ?>" class="regular-text" style="width:100%;"></td> | |
| 162 | - <td><input type="text" name="rag_sql_table_field[]" value="<?php echo esc_attr($table['table_field']); ?>" class="regular-text" style="width:100%;"></td> | |
| 163 | - <td><button type="button" class="button button-link-delete rag_sql_remove_table">Remove</button></td> | |
| 164 | - </tr> | |
| 165 | - <?php | |
| 166 | - } | |
| 167 | - } else { | |
| 168 | - ?> | |
| 169 | - <tr> | |
| 170 | - <td><input type="text" name="rag_sql_table_name[]" value="" placeholder="e.g. wp_users" class="regular-text" style="width:100%;"></td> | |
| 171 | - <td><input type="text" name="rag_sql_table_field[]" value="" placeholder="e.g. user_email" class="regular-text" style="width:100%;"></td> | |
| 172 | - <td><button type="button" class="button button-link-delete rag_sql_remove_table">Remove</button></td> | |
| 173 | - </tr> | |
| 174 | - <?php | |
| 175 | - } | |
| 176 | - ?> | |
| 177 | - </tbody> | |
| 178 | - </table> | |
| 179 | - <button type="button" class="button button-primary" id="rag_sql_add_table">Add New Table</button> | |
| 180 | - <button type="button" class="button button-secondary" id="sql_instruction" style="margin-left: 5px;">View Available SQL Tables & Fields</button> | |
| 181 | - <p class="description">Add multiple tables and fields. Separate multiple fields in the same table with commas.</p> | |
| 182 | - </div> | |
| 183 | - </div> | |
| 184 | - <br><br> | |
| 185 | - <div class="mb-3" style="<?php if ( $wpchatbot_license_valid != 'master' && $wpchatbot_license_valid != 'professional'){ echo 'opacity:0.5; pointer-events:none;'; } ?> "> | |
| 186 | - <input type="checkbox" id="rag_sql_auto_sync_enabled" <?php checked(get_option('rag_sql_auto_sync_enabled'), '1'); ?>> | |
| 187 | - <label for="rag_sql_auto_sync_enabled"><strong>Enable Auto Sync (on Save)</strong></label> | |
| 188 | - <p class="description">Automatically update embeddings </p> | |
| 189 | - </div> | |
| 190 | - <hr> | |
| 191 | - <?php | |
| 192 | - $sql_sync_interval = get_option('rag_sql_sync_interval', 'daily'); | |
| 193 | - $sql_interval_labels = [ | |
| 194 | - 'hourly' => '(Hourly)', | |
| 195 | - 'twicedaily' => '(Twice Daily)', | |
| 196 | - 'daily' => '(Daily)', | |
| 197 | - 'weekly' => '(Weekly)', | |
| 198 | - ]; | |
| 199 | - $sql_interval_desc = [ | |
| 200 | - 'hourly' => 'once per hour', | |
| 201 | - 'twicedaily' => 'twice per day', | |
| 202 | - 'daily' => 'once per day', | |
| 203 | - 'weekly' => 'once per week', | |
| 204 | - ]; | |
| 205 | - $sql_current_label = $sql_interval_labels[$sql_sync_interval] ?? '(Daily)'; | |
| 206 | - $sql_current_desc = $sql_interval_desc[$sql_sync_interval] ?? 'once per day'; | |
| 207 | - ?> | |
| 208 | 101 | |
| 209 | - <div class="mb-3" style="<?php if ( $wpchatbot_license_valid != 'master' && $wpchatbot_license_valid != 'professional'){ echo 'opacity:0.5; pointer-events:none;'; } ?>"> | |
| 210 | - <label for="rag_sql_sync_interval"><strong>Sync Interval:</strong></label> | |
| 211 | - <select id="rag_sql_sync_interval"> | |
| 212 | - <option value="five_minutes" <?php selected(get_option('rag_sql_sync_interval'), 'five_minutes'); ?>>Every 5 Minutes</option> | |
| 213 | - <option value="hourly" <?php selected(get_option('rag_sql_sync_interval'), 'hourly'); ?>>Hourly</option> | |
| 214 | - <option value="twicedaily" <?php selected(get_option('rag_sql_sync_interval'), 'twicedaily'); ?>>Twice Daily</option> | |
| 215 | - <option value="daily" <?php selected(get_option('rag_sql_sync_interval', 'daily'), 'daily'); ?>>Once Daily</option> | |
| 216 | - <option value="weekly" <?php selected(get_option('rag_sql_sync_interval'), 'weekly'); ?>>Weekly</option> | |
| 217 | - </select> | |
| 218 | - <p class="description">Choose how often to run the automated synchronization.</p> | |
| 219 | - </div> | |
| 220 | - | |
| 221 | - </div> | |
| 222 | - | |
| 223 | - <div class="wrap my-4" style="<?php if ( $wpchatbot_license_valid != 'master' && $wpchatbot_license_valid != 'professional'){ echo 'opacity:0.5; pointer-events:none;'; } ?>"> | |
| 224 | - <button type="button" id="rag_embed_sql_btn" class="button button-primary">Embed Selected Database Data</button> | |
| 225 | - | |
| 226 | - <div id="rag_sql_progress_container" style="display:none; margin-top: 20px;"> | |
| 227 | - <div class="progress" style="height: 25px; background-color: #f1f1f1; border-radius: 5px; overflow: hidden;"> | |
| 228 | - <div id="rag_sql_progress_bar" class="progress-bar progress-bar-striped progress-bar-animated" role="progressbar" style="width: 0%; height: 100%; background-color: #007bff; transition: width 0.3s ease;"></div> | |
| 229 | - </div> | |
| 230 | - <p id="rag_sql_progress_status" style="margin-top: 10px; font-weight: bold;"></p> | |
| 231 | - </div> | |
| 232 | - </div> | |
| 233 | - | |
| 234 | - <!-- SAVE SETTINGS BUTTON --> | |
| 235 | - <div class="wrap" style="<?php if ( $wpchatbot_license_valid != 'master' && $wpchatbot_license_valid != 'professional'){ echo 'opacity:0.5; pointer-events:none;'; } ?>"> | |
| 236 | - <button class="qcld-btn-primary" id="save_rag_setting">Save Settings</button> | |
| 237 | - </div> | |
| 238 | - </div> | |
| 239 | - | |
| 240 | 102 | <div id="rag-sync" class="qcld-tab-content"> |
| 241 | 103 | <?php if ( $wpchatbot_license_valid != 'master' && $wpchatbot_license_valid != 'professional'): ?> |
| 242 | 104 | <div class="wrap"> |
| 243 | 105 | <div style="background-color: #fee; border: 1px solid #c33; padding: 15px; margin: 20px 0; border-radius: 4px;"> |
| @@ -283,16 +145,16 @@ | ||
| 283 | 145 | ?> |
| 284 | 146 | |
| 285 | 147 | <div class="mb-3"> |
| 286 | 148 | <input type="checkbox" id="rag_googlesheets_autosync_enabled" <?php checked(get_option('rag_googlesheets_autosync_enabled'), '1'); ?>> |
| 287 | - <label for="rag_googlesheets_autosync_enabled"><strong>Enable Google Sheets Auto Sync <span class="rag-sync-label"><?php echo esc_html( $current_label ); ?></span></strong></label> | |
| 288 | - <p class="description">Automatically re-sync all Google Sheets in the knowledge base <span class="rag-sync-desc"><?php echo esc_html( $current_desc ); ?></span>.</p> | |
| 149 | + <label for="rag_googlesheets_autosync_enabled"><strong>Enable Google Sheets Auto Sync <span class="rag-sync-label"><?php echo $current_label; ?></span></strong></label> | |
| 150 | + <p class="description">Automatically re-sync all Google Sheets in the knowledge base <span class="rag-sync-desc"><?php echo $current_desc; ?></span>.</p> | |
| 289 | 151 | </div> |
| 290 | 152 | |
| 291 | 153 | <div class="mb-3"> |
| 292 | 154 | <input type="checkbox" id="rag_googledocs_autosync_enabled" <?php checked(get_option('rag_googledocs_autosync_enabled'), '1'); ?>> |
| 293 | - <label for="rag_googledocs_autosync_enabled"><strong>Enable Google Docs Auto Sync <span class="rag-sync-label"><?php echo esc_html( $current_label ); ?></span></strong></label> | |
| 294 | - <p class="description">Automatically re-sync all Google Docs in the knowledge base <span class="rag-sync-desc"><?php echo esc_html( $current_desc ); ?></span>.</p> | |
| 155 | + <label for="rag_googledocs_autosync_enabled"><strong>Enable Google Docs Auto Sync <span class="rag-sync-label"><?php echo $current_label; ?></span></strong></label> | |
| 156 | + <p class="description">Automatically re-sync all Google Docs in the knowledge base <span class="rag-sync-desc"><?php echo $current_desc; ?></span>.</p> | |
| 295 | 157 | </div> |
| 296 | 158 | |
| 297 | 159 | <div class="mb-3"> |
| 298 | 160 | <label for="rag_sync_interval"><strong>Sync Interval:</strong></label> |
| @@ -334,9 +196,9 @@ | ||
| 334 | 196 | CSV UPLOAD (AJAX) |
| 335 | 197 | ============================ --> |
| 336 | 198 | <div class="wrap"> |
| 337 | 199 | <h3>Upload CSV Data for RAG</h3> |
| 338 | - <p>Upload CSV files with data to be embedded. Each row will be processed as a separate document. <a href="<?php echo esc_url( plugin_dir_url(__FILE__).'download/rag_test_data.csv' ); ?>">Download Test Data</a></p> | |
| 200 | + <p>Upload CSV files with data to be embedded. Each row will be processed as a separate document. <a href="<?php echo plugin_dir_url(__FILE__).'download/rag_test_data.csv'; ?>">Download Test Data</a></p> | |
| 339 | 201 | |
| 340 | 202 | <form id="rag-csv-form"> |
| 341 | 203 | <input type="file" id="rag-csv-files" name="rag_csv[]" multiple accept=".csv,text/csv" /> |
| 342 | 204 | <br><br> |
| @@ -440,9 +302,9 @@ | ||
| 440 | 302 | |
| 441 | 303 | <div id="botmaster_googledoc_status" style="margin-top: 10px;"></div> |
| 442 | 304 | </div> |
| 443 | 305 | </div> |
| 444 | - <h5 style="color: #c33;">Notes: These are based on AI system, so make sure you have enabled any AI features and set up valid API keys. <b><a href="<?php echo esc_url('https://wpbot.pro/docs/knowledgebase/how-to-use-an-embedded-vector-database-and-rag-to-get-customized-responses-from-ai/'); ?>" target="_blank">Check this Tutorial for more details.</a></b></h5> | |
| 306 | + <h5 style="color: #c33;">Notes: These are based on AI system, so make sure you have enabled any AI features and set up valid API keys. <b><a href="https://wpbot.pro/docs/knowledgebase/how-to-use-an-embedded-vector-database-and-rag-to-get-customized-responses-from-ai/" target="_blank">Check this Tutorial for more details.</a></b></h5> | |
| 445 | 307 | <div class="wrap"> |
| 446 | 308 | <button class="qcld-btn-primary" id="save_rag_setting">Save Settings</button> |
| 447 | 309 | </div> |
| 448 | 310 | </div> |
| @@ -473,9 +335,9 @@ | ||
| 473 | 335 | |
| 474 | 336 | $.post(ajaxurl, { |
| 475 | 337 | action: 'botmaster_submit_sitemap', |
| 476 | 338 | sitemap_url: sitemapUrl, |
| 477 | - nonce: '<?php echo esc_attr( wp_create_nonce('botmaster_kb_nonce') ); ?>' | |
| 339 | + nonce: '<?php echo wp_create_nonce("botmaster_kb_nonce"); ?>' | |
| 478 | 340 | }, function(response) { |
| 479 | 341 | $('#botmaster_submit_sitemap_btn').prop('disabled', false); |
| 480 | 342 | if (response.success) { |
| 481 | 343 | statusDiv.html('<div class="notice notice-success inline"><p>' + response.data.message + '</p></div>'); |
| @@ -490,9 +352,9 @@ | ||
| 490 | 352 | <?php if ( $wpchatbot_license_valid != 'master' && $wpchatbot_license_valid != 'professional'): ?> |
| 491 | 353 | <div class="wrap"> |
| 492 | 354 | <div style="background-color: #fee; border: 1px solid #c33; padding: 15px; margin: 20px 0; border-radius: 4px;"> |
| 493 | 355 | <p style="color: #c33; font-weight: bold; margin: 0; font-size: 14px;"> |
| 494 | - These options are available with the WPBot Pro <a href="<?php echo esc_url('https://www.wpbot.pro/pricing/'); ?>" target="_blank" style="color: #c33; text-decoration: underline;">Professional</a> and <a href="<?php echo esc_url('https://www.wpbot.pro/pricing/'); ?>" target="_blank" style="color: #c33; text-decoration: underline;">Master</a> Licenses | |
| 356 | + These options are available with the WPBot Pro <a href="https://www.wpbot.pro/pricing/" target="_blank" style="color: #c33; text-decoration: underline;">Professional</a> and <a href="https://www.wpbot.pro/pricing/" target="_blank" style="color: #c33; text-decoration: underline;">Master</a> Licenses | |
| 495 | 357 | </p> |
| 496 | 358 | </div> |
| 497 | 359 | </div> |
| 498 | 360 | <?php endif; ?> |
| @@ -515,9 +377,9 @@ | ||
| 515 | 377 | <tbody id="rag-sources-list"> |
| 516 | 378 | <?php |
| 517 | 379 | global $wpdb; |
| 518 | 380 | $table = $wpdb->prefix . 'rag_documents'; |
| 519 | - $sources = $wpdb->get_results("SELECT source_url, source_type, COUNT(*) as count, MAX(title) as display_name FROM {$table} GROUP BY source_url, source_type ORDER BY count DESC"); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, PluginCheck.Security.DirectDB.UnescapedDBParameter | |
| 381 | + $sources = $wpdb->get_results("SELECT source_url, source_type, COUNT(*) as count, MAX(title) as display_name FROM $table GROUP BY source_url, source_type ORDER BY count DESC"); | |
| 520 | 382 | |
| 521 | 383 | if ($sources) { |
| 522 | 384 | foreach ($sources as $source) { |
| 523 | 385 | $display_url = $source->source_url ?: "Manual Upload"; |
| @@ -629,9 +491,9 @@ | ||
| 629 | 491 | echo '<div class="notice notice-success inline"><p>Database table created successfully.</p></div>'; |
| 630 | 492 | } |
| 631 | 493 | |
| 632 | 494 | // Check if table exists |
| 633 | - $table_exists = $wpdb->get_var($wpdb->prepare("SHOW TABLES LIKE %s", $wpdb->esc_like($table_rag_documents))) === $table_rag_documents; // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 495 | + $table_exists = $wpdb->get_var($wpdb->prepare("SHOW TABLES LIKE %s", $wpdb->esc_like($table_rag_documents))) === $table_rag_documents; | |
| 634 | 496 | |
| 635 | 497 | if (!$table_exists) { |
| 636 | 498 | ?> |
| 637 | 499 | <div class="wrap"> |
| @@ -654,11 +516,11 @@ | ||
| 654 | 516 | $search_query = isset($_GET['s']) ? sanitize_text_field(wp_unslash($_GET['s'])) : ''; |
| 655 | 517 | |
| 656 | 518 | if ($search_query) { |
| 657 | 519 | $like = '%' . $wpdb->esc_like($search_query) . '%'; |
| 658 | - $total_items = $wpdb->get_var($wpdb->prepare("SELECT COUNT(id) FROM {$table_name} WHERE title LIKE %s OR content LIKE %s", $like, $like)); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, PluginCheck.Security.DirectDB.UnescapedDBParameter | |
| 520 | + $total_items = $wpdb->get_var($wpdb->prepare("SELECT COUNT(id) FROM {$table_name} WHERE title LIKE %s OR content LIKE %s", $like, $like)); | |
| 659 | 521 | } else { |
| 660 | - $total_items = $wpdb->get_var("SELECT COUNT(id) FROM {$table_name}"); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, PluginCheck.Security.DirectDB.UnescapedDBParameter | |
| 522 | + $total_items = $wpdb->get_var("SELECT COUNT(id) FROM {$table_name}"); | |
| 661 | 523 | } |
| 662 | 524 | $items_per_page = 50; |
| 663 | 525 | $page = isset($_GET['paged']) ? absint(wp_unslash($_GET['paged'])) : 1; |
| 664 | 526 | $offset = ($page - 1) * $items_per_page; |
| @@ -666,10 +528,10 @@ | ||
| 666 | 528 | |
| 667 | 529 | $pagination_args = array( |
| 668 | 530 | 'base' => add_query_arg(array('paged' => '%#%', 's' => $search_query), '?page=wpbot_openAi') . '#ai-knowledge-base-tab#rag-database', |
| 669 | 531 | 'format' => '', |
| 670 | - 'prev_text' => __( '«', 'chatbot' ), | |
| 671 | - 'next_text' => __( '»', 'chatbot' ), | |
| 532 | + 'prev_text' => __('«'), | |
| 533 | + 'next_text' => __('»'), | |
| 672 | 534 | 'total' => $total_pages, |
| 673 | 535 | 'current' => $page, |
| 674 | 536 | 'type' => 'plain', |
| 675 | 537 | ); |
| @@ -674,11 +536,10 @@ | ||
| 674 | 536 | 'type' => 'plain', |
| 675 | 537 | ); |
| 676 | 538 | |
| 677 | 539 | if ($total_pages > 1) { |
| 678 | - // translators: %s: number of items. | |
| 679 | - echo '<div class="tablenav-pages"><span class="displaying-num">' . sprintf( esc_html( _n( '%s item', '%s items', $total_items, 'chatbot' ) ), esc_html( number_format_i18n($total_items) ) ) . '</span>'; | |
| 680 | - echo wp_kses_post( paginate_links($pagination_args) ); | |
| 540 | + echo '<div class="tablenav-pages"><span class="displaying-num">' . sprintf(_n('%s item', '%s items', $total_items), number_format_i18n($total_items)) . '</span>'; | |
| 541 | + echo paginate_links($pagination_args); | |
| 681 | 542 | echo '</div>'; |
| 682 | 543 | } |
| 683 | 544 | ?> |
| 684 | 545 | |
| @@ -699,19 +560,19 @@ | ||
| 699 | 560 | <tbody id="rag-knowledge-base-list"> |
| 700 | 561 | <?php |
| 701 | 562 | if ($search_query) { |
| 702 | 563 | $like = '%' . $wpdb->esc_like($search_query) . '%'; |
| 703 | - $documents = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$table_name} WHERE title LIKE %s OR content LIKE %s ORDER BY created_at DESC LIMIT %d OFFSET %d", $like, $like, $items_per_page, $offset)); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, PluginCheck.Security.DirectDB.UnescapedDBParameter | |
| 564 | + $documents = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$table_name} WHERE title LIKE %s OR content LIKE %s ORDER BY created_at DESC LIMIT %d OFFSET %d", $like, $like, $items_per_page, $offset)); | |
| 704 | 565 | } else { |
| 705 | - $documents = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$table_name} ORDER BY created_at DESC LIMIT %d OFFSET %d", $items_per_page, $offset)); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, PluginCheck.Security.DirectDB.UnescapedDBParameter | |
| 566 | + $documents = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$table_name} ORDER BY created_at DESC LIMIT %d OFFSET %d", $items_per_page, $offset)); | |
| 706 | 567 | } |
| 707 | 568 | |
| 708 | 569 | if ($documents) { |
| 709 | 570 | foreach ($documents as $doc) { |
| 710 | 571 | ?> |
| 711 | - <tr id="rag-doc-<?php echo esc_attr( $doc->id ); ?>"> | |
| 572 | + <tr id="rag-doc-<?php echo $doc->id; ?>"> | |
| 712 | 573 | <th scope="qcld-row" class="check-column"> |
| 713 | - <input type="checkbox" class="rag-doc-checkbox" value="<?php echo esc_attr( $doc->id ); ?>"> | |
| 574 | + <input type="checkbox" class="rag-doc-checkbox" value="<?php echo $doc->id; ?>"> | |
| 714 | 575 | </th> |
| 715 | 576 | <td><?php echo esc_html($doc->title); ?></td> |
| 716 | 577 | <td> |
| 717 | 578 | <div style="max-height: 4.5em; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 3; line-clamp: 3; -webkit-box-orient: vertical; line-height: 1.5em; font-size: 13px; color: #666;"> |
| @@ -722,12 +583,12 @@ | ||
| 722 | 583 | <td><?php echo esc_html($doc->source_url ?: $doc->file_url); ?></td> |
| 723 | 584 | <td><?php echo esc_html($doc->status); ?></td> |
| 724 | 585 | <td> |
| 725 | 586 | <?php if (!in_array($doc->source_type, ['csv', 'xml', 'xaml','sitemap'])): ?> |
| 726 | - <button class="button button-small rag-sync-doc" data-id="<?php echo esc_attr( $doc->id ); ?>" title="Re-sync data from source">Sync</button> | |
| 587 | + <button class="button button-small rag-sync-doc" data-id="<?php echo $doc->id; ?>" title="Re-sync data from source">Sync</button> | |
| 727 | 588 | <?php endif; ?> |
| 728 | - <button class="button button-small rag-edit-doc" data-id="<?php echo esc_attr( $doc->id ); ?>">Edit</button> | |
| 729 | - <button class="button button-small button-link-delete rag-delete-doc" data-id="<?php echo esc_attr( $doc->id ); ?>">Delete</button> | |
| 589 | + <button class="button button-small rag-edit-doc" data-id="<?php echo $doc->id; ?>">Edit</button> | |
| 590 | + <button class="button button-small button-link-delete rag-delete-doc" data-id="<?php echo $doc->id; ?>">Delete</button> | |
| 730 | 591 | </td> |
| 731 | 592 | </tr> |
| 732 | 593 | <?php |
| 733 | 594 | } |
| @@ -740,11 +601,10 @@ | ||
| 740 | 601 | |
| 741 | 602 | <div class="tablenav bottom"> |
| 742 | 603 | <?php |
| 743 | 604 | if ($total_pages > 1) { |
| 744 | - // translators: %s: number of items. | |
| 745 | - echo '<div class="tablenav-pages"><span class="displaying-num">' . sprintf( esc_html( _n( '%s item', '%s items', $total_items, 'chatbot' ) ), esc_html( number_format_i18n($total_items) ) ) . '</span>'; | |
| 746 | - echo wp_kses_post( paginate_links($pagination_args) ); | |
| 605 | + echo '<div class="tablenav-pages"><span class="displaying-num">' . sprintf(_n('%s item', '%s items', $total_items), number_format_i18n($total_items)) . '</span>'; | |
| 606 | + echo paginate_links($pagination_args); | |
| 747 | 607 | echo '</div>'; |
| 748 | 608 | } |
| 749 | 609 | ?> |
| 750 | 610 | <br class="clear"> |
| @@ -793,9 +653,9 @@ | ||
| 793 | 653 | for (var i = 0; i < fileInput.files.length; i++) { |
| 794 | 654 | formData.append('rag_pdf[]', fileInput.files[i]); |
| 795 | 655 | } |
| 796 | 656 | formData.append('action', 'rag_upload_pdf'); |
| 797 | - formData.append('nonce', '<?php echo esc_js( wp_create_nonce('rag_upload_nonce') ); ?>'); | |
| 657 | + formData.append('nonce', '<?php echo wp_create_nonce('rag_upload_nonce'); ?>'); | |
| 798 | 658 | |
| 799 | 659 | $('#rag-pdf-submit').prop('disabled', true); |
| 800 | 660 | $('#rag-pdf-status').html('<span class="spinner is-active" style="float:none;"></span> Uploading and processing...'); |
| 801 | 661 | $('#rag-pdf-output').html(''); |
| @@ -839,9 +699,9 @@ | ||
| 839 | 699 | for (var i = 0; i < fileInput.files.length; i++) { |
| 840 | 700 | formData.append('rag_csv[]', fileInput.files[i]); |
| 841 | 701 | } |
| 842 | 702 | formData.append('action', 'rag_upload_csv'); |
| 843 | - formData.append('nonce', '<?php echo esc_js( wp_create_nonce('rag_upload_nonce') ); ?>'); | |
| 703 | + formData.append('nonce', '<?php echo wp_create_nonce('rag_upload_nonce'); ?>'); | |
| 844 | 704 | |
| 845 | 705 | $('#rag-csv-submit').prop('disabled', true); |
| 846 | 706 | $('#rag-csv-status').html('<span class="spinner is-active" style="float:none;"></span> Uploading and processing...'); |
| 847 | 707 | $('#rag-csv-output').html(''); |
| @@ -885,9 +745,9 @@ | ||
| 885 | 745 | for (var i = 0; i < fileInput.files.length; i++) { |
| 886 | 746 | formData.append('rag_xaml[]', fileInput.files[i]); |
| 887 | 747 | } |
| 888 | 748 | formData.append('action', 'rag_upload_xaml'); |
| 889 | - formData.append('nonce', '<?php echo esc_js( wp_create_nonce('rag_upload_nonce') ); ?>'); | |
| 749 | + formData.append('nonce', '<?php echo wp_create_nonce('rag_upload_nonce'); ?>'); | |
| 890 | 750 | |
| 891 | 751 | $('#rag-xaml-submit').prop('disabled', true); |
| 892 | 752 | $('#rag-xaml-status').html('<span class="spinner is-active" style="float:none;"></span> Uploading and processing...'); |
| 893 | 753 | $('#rag-xaml-output').html(''); |