| @@ -272,11 +272,8 @@ | ||
| 272 | 272 | <?php |
| 273 | 273 | // Render the Content Selector Modal |
| 274 | 274 | mxchat_render_content_selector_modal(); |
| 275 | 275 | |
| 276 | - // Render the Edit Entry Modal | |
| 277 | - mxchat_render_edit_entry_modal(); | |
| 278 | - | |
| 279 | 276 | // Render the navigation JavaScript |
| 280 | 277 | mxchat_render_knowledge_page_scripts(); |
| 281 | 278 | } |
| 282 | 279 | |
| @@ -404,15 +401,8 @@ | ||
| 404 | 401 | function mxchat_render_import_options_section($admin_instance, $knowledge_manager, $page_data) { |
| 405 | 402 | extract($page_data); |
| 406 | 403 | $options = $admin_instance->options ?? get_option('mxchat_options', array()); |
| 407 | 404 | |
| 408 | - // Check if user is using WordPress database (not Pinecone or OpenAI Vector Store) | |
| 409 | - $pinecone_options = get_option('mxchat_pinecone_addon_options', array()); | |
| 410 | - $is_pinecone_active = ($pinecone_options['mxchat_use_pinecone'] ?? '0') === '1'; | |
| 411 | - $vectorstore_options = get_option('mxchat_openai_vectorstore_options', array()); | |
| 412 | - $is_vectorstore_active = ($vectorstore_options['mxchat_use_openai_vectorstore'] ?? '0') === '1'; | |
| 413 | - $is_using_wordpress_db = !$is_pinecone_active && !$is_vectorstore_active; | |
| 414 | - | |
| 415 | 405 | // Check embedding API key |
| 416 | 406 | $embedding_model = isset($options['embedding_model']) ? esc_attr($options['embedding_model']) : 'text-embedding-ada-002'; |
| 417 | 407 | $has_openai_key = !empty($options['api_key']); |
| 418 | 408 | $has_voyage_key = !empty($options['voyage_api_key']); |
| @@ -463,21 +453,8 @@ | ||
| 463 | 453 | <?php endif; ?> |
| 464 | 454 | </div> |
| 465 | 455 | </div> |
| 466 | 456 | |
| 467 | - <?php if ($is_using_wordpress_db): ?> | |
| 468 | - <!-- WordPress Database Caution Notice --> | |
| 469 | - <div class="mxch-notice mxch-notice-warning" style="margin-bottom: 24px;"> | |
| 470 | - <svg class="mxch-notice-icon" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> | |
| 471 | - <path d="m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3Z"/><line x1="12" y1="9" x2="12" y2="13"/><line x1="12" y1="17" x2="12.01" y2="17"/> | |
| 472 | - </svg> | |
| 473 | - <div> | |
| 474 | - <strong><?php esc_html_e('Using WordPress Database:', 'mxchat'); ?></strong> | |
| 475 | - <?php esc_html_e('The WordPress database is not optimized for vector search with large datasets. If you plan to have more than 500 knowledge entries, we highly recommend using Pinecone for better performance and scalability.', 'mxchat'); ?> | |
| 476 | - </div> | |
| 477 | - </div> | |
| 478 | - <?php endif; ?> | |
| 479 | - | |
| 480 | 457 | <div class="mxch-card"> |
| 481 | 458 | <div class="mxch-card-header"> |
| 482 | 459 | <h3 class="mxch-card-title"> |
| 483 | 460 | <svg class="mxch-card-title-icon" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="17 8 12 3 7 8"/><line x1="12" y1="3" x2="12" y2="15"/></svg> |
| @@ -531,29 +508,18 @@ | ||
| 531 | 508 | <p><?php esc_html_e('Submit content to be vectorized.', 'mxchat'); ?></p> |
| 532 | 509 | </div> |
| 533 | 510 | </button> |
| 534 | 511 | |
| 535 | - <!-- PDF Import Option (URL) --> | |
| 536 | - <button type="button" class="mxchat-import-box" data-option="pdf-url" data-placeholder="<?php esc_attr_e('Enter PDF URL here', 'mxchat'); ?>" data-type="pdf"> | |
| 512 | + <!-- PDF Import Option --> | |
| 513 | + <button type="button" class="mxchat-import-box" data-option="pdf" data-placeholder="<?php esc_attr_e('Enter PDF URL here', 'mxchat'); ?>" data-type="pdf"> | |
| 537 | 514 | <div class="mxchat-import-icon"> |
| 538 | 515 | <span class="dashicons dashicons-media-document"></span> |
| 539 | 516 | </div> |
| 540 | 517 | <div class="mxchat-import-content"> |
| 541 | 518 | <h4><?php esc_html_e('PDF Import', 'mxchat'); ?></h4> |
| 542 | - <p><?php esc_html_e('Import knowledge from PDF URL.', 'mxchat'); ?></p> | |
| 519 | + <p><?php esc_html_e('Import knowledge from PDF documents.', 'mxchat'); ?></p> | |
| 543 | 520 | </div> |
| 544 | 521 | </button> |
| 545 | - | |
| 546 | - <!-- PDF File Upload Option --> | |
| 547 | - <button type="button" class="mxchat-import-box" data-option="pdf-upload" data-type="pdf-upload"> | |
| 548 | - <div class="mxchat-import-icon"> | |
| 549 | - <span class="dashicons dashicons-upload"></span> | |
| 550 | - </div> | |
| 551 | - <div class="mxchat-import-content"> | |
| 552 | - <h4><?php esc_html_e('PDF Upload', 'mxchat'); ?></h4> | |
| 553 | - <p><?php esc_html_e('Upload a PDF file from your computer.', 'mxchat'); ?></p> | |
| 554 | - </div> | |
| 555 | - </button> | |
| 556 | 522 | </div> |
| 557 | 523 | |
| 558 | 524 | <!-- Detected Sitemaps Section (hidden by default, shown when Sitemap Import is clicked) --> |
| 559 | 525 | <div id="mxchat-detected-sitemaps" class="mxchat-detected-sitemaps" style="display: none;"> |
| @@ -637,26 +603,8 @@ | ||
| 637 | 603 | <?php esc_html_e('Import Content', 'mxchat'); ?> |
| 638 | 604 | </button> |
| 639 | 605 | </form> |
| 640 | 606 | </div> |
| 641 | - | |
| 642 | - <div class="mxchat-import-input-area" id="mxchat-pdf-upload-area" style="display: none; margin-top: 20px;"> | |
| 643 | - <form id="mxchat-pdf-upload-form" method="post" action="<?php echo esc_url(admin_url('admin-post.php?action=mxchat_submit_pdf_file')); ?>" enctype="multipart/form-data"> | |
| 644 | - <?php wp_nonce_field('mxchat_submit_pdf_file_action', 'mxchat_submit_pdf_file_nonce'); ?> | |
| 645 | - <?php if ($multibot_active && $current_bot_id !== 'default') : ?> | |
| 646 | - <input type="hidden" name="bot_id" value="<?php echo esc_attr($current_bot_id); ?>"> | |
| 647 | - <?php endif; ?> | |
| 648 | - <div class="mxch-field"> | |
| 649 | - <input type="file" name="pdf_file" id="mxchat-pdf-file-input" accept=".pdf" required> | |
| 650 | - </div> | |
| 651 | - <p class="mxch-field-description"> | |
| 652 | - <?php esc_html_e('Select a PDF file from your computer to import into the knowledge base. Maximum file size depends on your server settings.', 'mxchat'); ?> | |
| 653 | - </p> | |
| 654 | - <button type="submit" name="submit_pdf_file" class="mxch-btn mxch-btn-primary"> | |
| 655 | - <?php esc_html_e('Import PDF', 'mxchat'); ?> | |
| 656 | - </button> | |
| 657 | - </form> | |
| 658 | - </div> | |
| 659 | 607 | <?php endif; ?> |
| 660 | 608 | </div> |
| 661 | 609 | </div> |
| 662 | 610 | </div> |
| @@ -825,24 +773,21 @@ | ||
| 825 | 773 | <?php esc_html_e('WordPress DB', 'mxchat'); ?> |
| 826 | 774 | </span> |
| 827 | 775 | <?php endif; ?> |
| 828 | 776 | </h3> |
| 829 | - <div class="mxch-kb-header-controls"> | |
| 830 | - <form method="get" id="knowledge-search" class="mxch-kb-search-form"> | |
| 777 | + <div style="display: flex; gap: 10px; align-items: center;"> | |
| 778 | + <form method="get" id="knowledge-search" style="display: flex; gap: 10px;"> | |
| 831 | 779 | <?php wp_nonce_field('mxchat_prompts_search_nonce'); ?> |
| 832 | 780 | <input type="hidden" name="page" value="mxchat-prompts" /> |
| 833 | 781 | <?php if ($multibot_active && !empty($current_bot_id) && $current_bot_id !== 'default') : ?> |
| 834 | 782 | <input type="hidden" name="bot_id" value="<?php echo esc_attr($current_bot_id); ?>" /> |
| 835 | 783 | <?php endif; ?> |
| 836 | - <input type="text" name="search" class="mxch-input mxch-input-sm mxch-kb-search-input" placeholder="<?php esc_attr_e('Search...', 'mxchat'); ?>" value="<?php echo esc_attr($search_query); ?>" /> | |
| 837 | - <select name="content_type" class="mxch-select mxch-kb-type-filter" onchange="this.form.submit()"> | |
| 784 | + <input type="text" name="search" class="mxch-input mxch-input-sm" placeholder="<?php esc_attr_e('Search...', 'mxchat'); ?>" value="<?php echo esc_attr($search_query); ?>" style="width: 200px;" /> | |
| 785 | + <select name="content_type" class="mxch-select" style="width: auto;" onchange="this.form.submit()"> | |
| 838 | 786 | <option value=""><?php esc_html_e('All Types', 'mxchat'); ?></option> |
| 839 | - <?php | |
| 840 | - $post_types = get_post_types(array('public' => true), 'objects'); | |
| 841 | - foreach ($post_types as $post_type) { | |
| 842 | - echo '<option value="' . esc_attr($post_type->name) . '" ' . selected($content_type_filter, $post_type->name, false) . '>' . esc_html($post_type->label) . '</option>'; | |
| 843 | - } | |
| 844 | - ?> | |
| 787 | + <option value="post" <?php selected($content_type_filter, 'post'); ?>><?php esc_html_e('Posts', 'mxchat'); ?></option> | |
| 788 | + <option value="page" <?php selected($content_type_filter, 'page'); ?>><?php esc_html_e('Pages', 'mxchat'); ?></option> | |
| 789 | + <option value="product" <?php selected($content_type_filter, 'product'); ?>><?php esc_html_e('Products', 'mxchat'); ?></option> | |
| 845 | 790 | <option value="pdf" <?php selected($content_type_filter, 'pdf'); ?>><?php esc_html_e('PDFs', 'mxchat'); ?></option> |
| 846 | 791 | <option value="url" <?php selected($content_type_filter, 'url'); ?>><?php esc_html_e('URLs', 'mxchat'); ?></option> |
| 847 | 792 | </select> |
| 848 | 793 | </form> |
| @@ -848,39 +793,15 @@ | ||
| 848 | 793 | </form> |
| 849 | 794 | <!-- Delete Button Container - transforms between Delete All and Delete Selected --> |
| 850 | 795 | <div class="mxchat-delete-container" id="mxchat-delete-container"> |
| 851 | 796 | <!-- Delete All Form (shown when nothing selected) --> |
| 852 | - <?php | |
| 853 | - // Build confirm message and button text based on active filter | |
| 854 | - $delete_all_label = __('Delete All', 'mxchat'); | |
| 855 | - $delete_all_confirm = __('Are you sure you want to delete all knowledge?', 'mxchat'); | |
| 856 | - if (!empty($content_type_filter)) { | |
| 857 | - $filter_display = $content_type_filter; | |
| 858 | - // Try to get a human-readable label | |
| 859 | - $pt_obj = get_post_type_object($content_type_filter); | |
| 860 | - if ($pt_obj) { | |
| 861 | - $filter_display = $pt_obj->label; | |
| 862 | - } elseif ($content_type_filter === 'pdf') { | |
| 863 | - $filter_display = 'PDFs'; | |
| 864 | - } elseif ($content_type_filter === 'url') { | |
| 865 | - $filter_display = 'URLs'; | |
| 866 | - } | |
| 867 | - /* translators: %s: content type label (e.g. "Pages", "PDFs") */ | |
| 868 | - $delete_all_label = sprintf(__('Delete All %s', 'mxchat'), $filter_display); | |
| 869 | - /* translators: %s: content type label */ | |
| 870 | - $delete_all_confirm = sprintf(__('Are you sure you want to delete all %s from the knowledge base?', 'mxchat'), $filter_display); | |
| 871 | - } | |
| 872 | - ?> | |
| 873 | - <form method="post" action="<?php echo esc_url(admin_url('admin-post.php?action=mxchat_delete_all_prompts')); ?>" id="mxchat-delete-all-form" onsubmit="return confirm('<?php echo esc_attr($delete_all_confirm); ?>');"> | |
| 797 | + <form method="post" action="<?php echo esc_url(admin_url('admin-post.php?action=mxchat_delete_all_prompts')); ?>" id="mxchat-delete-all-form" onsubmit="return confirm('<?php esc_attr_e('Are you sure you want to delete all knowledge?', 'mxchat'); ?>');"> | |
| 874 | 798 | <?php wp_nonce_field('mxchat_delete_all_prompts_action', 'mxchat_delete_all_prompts_nonce'); ?> |
| 875 | 799 | <input type="hidden" name="data_source" value="<?php echo esc_attr($data_source); ?>" /> |
| 876 | 800 | <input type="hidden" name="bot_id" value="<?php echo esc_attr($current_bot_id); ?>" /> |
| 877 | - <?php if (!empty($content_type_filter)) : ?> | |
| 878 | - <input type="hidden" name="content_type_filter" value="<?php echo esc_attr($content_type_filter); ?>" /> | |
| 879 | - <?php endif; ?> | |
| 880 | 801 | <button type="submit" class="mxch-btn mxch-btn-secondary mxch-btn-sm" style="color: var(--mxch-error);"> |
| 881 | 802 | <span class="dashicons dashicons-trash" style="font-size: 14px;"></span> |
| 882 | - <?php echo esc_html($delete_all_label); ?> | |
| 803 | + <?php esc_html_e('Delete All', 'mxchat'); ?> | |
| 883 | 804 | </button> |
| 884 | 805 | </form> |
| 885 | 806 | <!-- Delete Selected Button (shown when items selected) --> |
| 886 | 807 | <button type="button" |
| @@ -988,22 +909,10 @@ | ||
| 988 | 909 | <?php else : ?> |
| 989 | 910 | <span style="color: var(--mxch-text-muted);"><?php esc_html_e('Manual Content', 'mxchat'); ?></span> |
| 990 | 911 | <?php endif; ?> |
| 991 | 912 | </td> |
| 992 | - <td class="mxchat-actions-cell" style="padding: 12px 16px; white-space: nowrap;"> | |
| 993 | - <?php if ($data_source !== 'pinecone') : ?> | |
| 913 | + <td class="mxchat-actions-cell" style="padding: 12px 16px;"> | |
| 994 | 914 | <button type="button" |
| 995 | - class="mxch-btn mxch-btn-ghost mxch-btn-sm mxchat-edit-entry-btn" | |
| 996 | - data-source-url="<?php echo esc_attr($source_url); ?>" | |
| 997 | - data-entry-id="<?php echo esc_attr($first_prompt->id); ?>" | |
| 998 | - data-data-source="<?php echo esc_attr($data_source); ?>" | |
| 999 | - data-bot-id="<?php echo esc_attr($current_bot_id); ?>" | |
| 1000 | - data-nonce="<?php echo wp_create_nonce('mxchat_edit_entry_nonce'); ?>" | |
| 1001 | - title="<?php esc_attr_e('Edit content', 'mxchat'); ?>"> | |
| 1002 | - <span class="dashicons dashicons-edit" style="font-size: 14px;"></span> | |
| 1003 | - </button> | |
| 1004 | - <?php endif; ?> | |
| 1005 | - <button type="button" | |
| 1006 | 915 | class="mxch-btn mxch-btn-ghost mxch-btn-sm delete-button-group" |
| 1007 | 916 | data-source-url="<?php echo esc_attr($source_url); ?>" |
| 1008 | 917 | data-chunk-count="<?php echo esc_attr($chunk_count); ?>" |
| 1009 | 918 | data-data-source="<?php echo esc_attr($data_source); ?>" |
| @@ -1138,21 +1047,9 @@ | ||
| 1138 | 1047 | <?php else : ?> |
| 1139 | 1048 | <span style="color: var(--mxch-text-muted);"><?php esc_html_e('Manual', 'mxchat'); ?></span> |
| 1140 | 1049 | <?php endif; ?> |
| 1141 | 1050 | </td> |
| 1142 | - <td style="padding: 12px 16px; white-space: nowrap;"> | |
| 1143 | - <?php if ($data_source !== 'pinecone') : ?> | |
| 1144 | - <button type="button" | |
| 1145 | - class="mxch-btn mxch-btn-ghost mxch-btn-sm mxchat-edit-entry-btn" | |
| 1146 | - data-source-url="<?php echo esc_attr($prompt->source_url ?? ''); ?>" | |
| 1147 | - data-entry-id="<?php echo esc_attr($prompt->id); ?>" | |
| 1148 | - data-data-source="<?php echo esc_attr($data_source); ?>" | |
| 1149 | - data-bot-id="<?php echo esc_attr($current_bot_id); ?>" | |
| 1150 | - data-nonce="<?php echo wp_create_nonce('mxchat_edit_entry_nonce'); ?>" | |
| 1151 | - title="<?php esc_attr_e('Edit content', 'mxchat'); ?>"> | |
| 1152 | - <span class="dashicons dashicons-edit" style="font-size: 14px;"></span> | |
| 1153 | - </button> | |
| 1154 | - <?php endif; ?> | |
| 1051 | + <td style="padding: 12px 16px;"> | |
| 1155 | 1052 | <?php if ($data_source === 'pinecone') : ?> |
| 1156 | 1053 | <button type="button" class="mxch-btn mxch-btn-ghost mxch-btn-sm delete-button-ajax" data-vector-id="<?php echo esc_attr($prompt->id); ?>" data-bot-id="<?php echo esc_attr($current_bot_id); ?>" data-nonce="<?php echo wp_create_nonce('mxchat_delete_pinecone_prompt_nonce'); ?>" style="color: var(--mxch-error);"> |
| 1157 | 1054 | <span class="dashicons dashicons-trash" style="font-size: 14px;"></span> |
| 1158 | 1055 | </button> |
| @@ -1624,9 +1521,9 @@ | ||
| 1624 | 1521 | $max_results = $vectorstore_options['mxchat_vectorstore_max_results'] ?? 5; |
| 1625 | 1522 | |
| 1626 | 1523 | // Get current chat model to check compatibility |
| 1627 | 1524 | $mxchat_options = get_option('mxchat_options', array()); |
| 1628 | - $current_model = $mxchat_options['model'] ?? 'gpt-5.1-chat-latest'; | |
| 1525 | + $current_model = $mxchat_options['model'] ?? 'gpt-4o'; | |
| 1629 | 1526 | $is_openai_model = preg_match('/^(gpt-|o1-|o3-)/', $current_model); |
| 1630 | 1527 | ?> |
| 1631 | 1528 | <div id="openai-vectorstore" class="mxch-section"> |
| 1632 | 1529 | <div class="mxch-content-header"> |
| @@ -1637,9 +1534,9 @@ | ||
| 1637 | 1534 | <div class="mxch-card"> |
| 1638 | 1535 | <div class="mxch-card-body"> |
| 1639 | 1536 | <div class="mxch-notice mxch-notice-info" style="margin-bottom: 20px;"> |
| 1640 | 1537 | <svg class="mxch-notice-icon" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="10"/><line x1="12" y1="16" x2="12" y2="12"/><line x1="12" y1="8" x2="12.01" y2="8"/></svg> |
| 1641 | - <span><strong><?php esc_html_e('Requires OpenAI Chat Model.', 'mxchat'); ?></strong> <?php esc_html_e('Vector Store search only works with OpenAI models (gpt-5.1-chat-latest, gpt-5-mini, etc.). Create Vector Stores in your OpenAI Dashboard.', 'mxchat'); ?></span> | |
| 1538 | + <span><strong><?php esc_html_e('Requires OpenAI Chat Model.', 'mxchat'); ?></strong> <?php esc_html_e('Vector Store search only works with OpenAI models (gpt-4o, gpt-4o-mini, etc.). Create Vector Stores in your OpenAI Dashboard.', 'mxchat'); ?></span> | |
| 1642 | 1539 | </div> |
| 1643 | 1540 | |
| 1644 | 1541 | <?php if (!$is_openai_model && $use_vectorstore === '1'): ?> |
| 1645 | 1542 | <div class="mxch-notice mxch-notice-warning" style="margin-bottom: 20px;"> |
| @@ -1781,47 +1678,8 @@ | ||
| 1781 | 1678 | <?php |
| 1782 | 1679 | } |
| 1783 | 1680 | |
| 1784 | 1681 | /** |
| 1785 | - * Render Edit Entry Modal | |
| 1786 | - */ | |
| 1787 | -function mxchat_render_edit_entry_modal() { | |
| 1788 | - ?> | |
| 1789 | - <div id="mxchat-kb-edit-modal" class="mxchat-kb-modal"> | |
| 1790 | - <div class="mxchat-kb-modal-content mxchat-kb-edit-modal-content"> | |
| 1791 | - <div class="mxchat-kb-modal-header"> | |
| 1792 | - <h3 id="mxchat-kb-edit-title"><?php esc_html_e('Edit Knowledge Entry', 'mxchat'); ?></h3> | |
| 1793 | - <span class="mxchat-kb-modal-close" id="mxchat-kb-edit-close">×</span> | |
| 1794 | - </div> | |
| 1795 | - <div class="mxchat-kb-edit-body"> | |
| 1796 | - <div class="mxchat-kb-edit-source" id="mxchat-kb-edit-source"></div> | |
| 1797 | - <textarea id="mxchat-kb-edit-textarea" class="mxchat-kb-edit-textarea" placeholder="<?php esc_attr_e('Loading content...', 'mxchat'); ?>"></textarea> | |
| 1798 | - <div class="mxchat-kb-edit-meta"> | |
| 1799 | - <span id="mxchat-kb-edit-charcount"></span> | |
| 1800 | - <span id="mxchat-kb-edit-chunkinfo"></span> | |
| 1801 | - </div> | |
| 1802 | - </div> | |
| 1803 | - <div class="mxchat-kb-edit-footer"> | |
| 1804 | - <div class="mxchat-kb-edit-notice" id="mxchat-kb-edit-notice"></div> | |
| 1805 | - <div class="mxchat-kb-edit-actions"> | |
| 1806 | - <button type="button" id="mxchat-kb-edit-cancel" class="mxch-btn mxch-btn-ghost"> | |
| 1807 | - <?php esc_html_e('Cancel', 'mxchat'); ?> | |
| 1808 | - </button> | |
| 1809 | - <button type="button" id="mxchat-kb-edit-save" class="mxch-btn mxch-btn-primary"> | |
| 1810 | - <span class="mxchat-kb-edit-save-text"><?php esc_html_e('Save & Re-embed', 'mxchat'); ?></span> | |
| 1811 | - <span class="mxchat-kb-edit-save-spinner" style="display:none;"> | |
| 1812 | - <span class="mxchat-kb-spinner is-active" style="margin: 0;"></span> | |
| 1813 | - <?php esc_html_e('Saving...', 'mxchat'); ?> | |
| 1814 | - </span> | |
| 1815 | - </button> | |
| 1816 | - </div> | |
| 1817 | - </div> | |
| 1818 | - </div> | |
| 1819 | - </div> | |
| 1820 | - <?php | |
| 1821 | -} | |
| 1822 | - | |
| 1823 | -/** | |
| 1824 | 1682 | * Render Knowledge Page Navigation Scripts |
| 1825 | 1683 | */ |
| 1826 | 1684 | function mxchat_render_knowledge_page_scripts() { |
| 1827 | 1685 | ?> |
| @@ -1996,197 +1854,8 @@ | ||
| 1996 | 1854 | } |
| 1997 | 1855 | |
| 1998 | 1856 | // Sitemap detection is now handled by knowledge-processing.js |
| 1999 | 1857 | // It will be initialized when user clicks "Sitemap Import" option |
| 2000 | - | |
| 2001 | - // ─── Edit Entry Modal ──────────────────────────────────── | |
| 2002 | - initEditModal(); | |
| 2003 | - | |
| 2004 | - function initEditModal() { | |
| 2005 | - var modal = document.getElementById('mxchat-kb-edit-modal'); | |
| 2006 | - var textarea = document.getElementById('mxchat-kb-edit-textarea'); | |
| 2007 | - var saveBtn = document.getElementById('mxchat-kb-edit-save'); | |
| 2008 | - var cancelBtn = document.getElementById('mxchat-kb-edit-cancel'); | |
| 2009 | - var closeBtn = document.getElementById('mxchat-kb-edit-close'); | |
| 2010 | - var notice = document.getElementById('mxchat-kb-edit-notice'); | |
| 2011 | - var charCount = document.getElementById('mxchat-kb-edit-charcount'); | |
| 2012 | - var chunkInfo = document.getElementById('mxchat-kb-edit-chunkinfo'); | |
| 2013 | - var sourceEl = document.getElementById('mxchat-kb-edit-source'); | |
| 2014 | - var titleEl = document.getElementById('mxchat-kb-edit-title'); | |
| 2015 | - var saveText = saveBtn ? saveBtn.querySelector('.mxchat-kb-edit-save-text') : null; | |
| 2016 | - var saveSpin = saveBtn ? saveBtn.querySelector('.mxchat-kb-edit-save-spinner') : null; | |
| 2017 | - | |
| 2018 | - if (!modal) return; | |
| 2019 | - | |
| 2020 | - var currentEntry = {}; | |
| 2021 | - | |
| 2022 | - // Bind edit buttons (delegated) | |
| 2023 | - document.addEventListener('click', function(e) { | |
| 2024 | - var btn = e.target.closest('.mxchat-edit-entry-btn'); | |
| 2025 | - if (btn) { | |
| 2026 | - e.preventDefault(); | |
| 2027 | - openEditModal(btn); | |
| 2028 | - } | |
| 2029 | - }); | |
| 2030 | - | |
| 2031 | - // Close handlers | |
| 2032 | - if (closeBtn) closeBtn.addEventListener('click', closeModal); | |
| 2033 | - if (cancelBtn) cancelBtn.addEventListener('click', closeModal); | |
| 2034 | - modal.addEventListener('click', function(e) { | |
| 2035 | - if (e.target === modal) closeModal(); | |
| 2036 | - }); | |
| 2037 | - | |
| 2038 | - // Character count | |
| 2039 | - if (textarea) { | |
| 2040 | - textarea.addEventListener('input', function() { | |
| 2041 | - updateCharCount(); | |
| 2042 | - }); | |
| 2043 | - } | |
| 2044 | - | |
| 2045 | - // Save handler | |
| 2046 | - if (saveBtn) saveBtn.addEventListener('click', saveContent); | |
| 2047 | - | |
| 2048 | - function openEditModal(btn) { | |
| 2049 | - currentEntry = { | |
| 2050 | - sourceUrl: btn.getAttribute('data-source-url') || '', | |
| 2051 | - entryId: btn.getAttribute('data-entry-id') || '', | |
| 2052 | - dataSource: btn.getAttribute('data-data-source') || 'wordpress', | |
| 2053 | - botId: btn.getAttribute('data-bot-id') || 'default', | |
| 2054 | - nonce: btn.getAttribute('data-nonce') || '' | |
| 2055 | - }; | |
| 2056 | - | |
| 2057 | - // Reset state | |
| 2058 | - textarea.value = ''; | |
| 2059 | - textarea.placeholder = 'Loading content...'; | |
| 2060 | - textarea.disabled = true; | |
| 2061 | - saveBtn.disabled = true; | |
| 2062 | - notice.textContent = ''; | |
| 2063 | - notice.className = 'mxchat-kb-edit-notice'; | |
| 2064 | - charCount.textContent = ''; | |
| 2065 | - chunkInfo.textContent = ''; | |
| 2066 | - | |
| 2067 | - // Show source | |
| 2068 | - if (currentEntry.sourceUrl && currentEntry.sourceUrl.indexOf('mxchat://') !== 0) { | |
| 2069 | - sourceEl.innerHTML = 'Source: <a href="' + escapeHtml(currentEntry.sourceUrl) + '" target="_blank">' + escapeHtml(truncate(currentEntry.sourceUrl, 60)) + '</a>'; | |
| 2070 | - } else { | |
| 2071 | - sourceEl.textContent = 'Manual Content'; | |
| 2072 | - } | |
| 2073 | - | |
| 2074 | - // Show modal | |
| 2075 | - modal.classList.add('active'); | |
| 2076 | - | |
| 2077 | - // Fetch content | |
| 2078 | - var formData = new FormData(); | |
| 2079 | - formData.append('action', 'mxchat_get_entry_content'); | |
| 2080 | - formData.append('nonce', currentEntry.nonce); | |
| 2081 | - formData.append('source_url', currentEntry.sourceUrl); | |
| 2082 | - formData.append('entry_id', currentEntry.entryId); | |
| 2083 | - formData.append('data_source', currentEntry.dataSource); | |
| 2084 | - formData.append('bot_id', currentEntry.botId); | |
| 2085 | - | |
| 2086 | - fetch(ajaxurl, { method: 'POST', body: formData }) | |
| 2087 | - .then(function(r) { return r.json(); }) | |
| 2088 | - .then(function(resp) { | |
| 2089 | - if (resp.success) { | |
| 2090 | - textarea.value = resp.data.content || ''; | |
| 2091 | - textarea.disabled = false; | |
| 2092 | - textarea.placeholder = 'Edit your content here...'; | |
| 2093 | - saveBtn.disabled = false; | |
| 2094 | - currentEntry.contentType = resp.data.content_type || 'content'; | |
| 2095 | - | |
| 2096 | - updateCharCount(); | |
| 2097 | - | |
| 2098 | - if (resp.data.is_chunked) { | |
| 2099 | - chunkInfo.textContent = resp.data.chunk_count + ' chunks — will be re-chunked on save'; | |
| 2100 | - titleEl.textContent = 'Edit Knowledge Entry (' + resp.data.chunk_count + ' chunks)'; | |
| 2101 | - } else { | |
| 2102 | - chunkInfo.textContent = ''; | |
| 2103 | - titleEl.textContent = 'Edit Knowledge Entry'; | |
| 2104 | - } | |
| 2105 | - | |
| 2106 | - textarea.focus(); | |
| 2107 | - } else { | |
| 2108 | - textarea.placeholder = ''; | |
| 2109 | - showNotice((resp.data && resp.data.message) || 'Failed to load content.', 'error'); | |
| 2110 | - } | |
| 2111 | - }) | |
| 2112 | - .catch(function(err) { | |
| 2113 | - textarea.placeholder = ''; | |
| 2114 | - showNotice('Network error: ' + err.message, 'error'); | |
| 2115 | - }); | |
| 2116 | - } | |
| 2117 | - | |
| 2118 | - function saveContent() { | |
| 2119 | - if (!textarea.value.trim()) { | |
| 2120 | - showNotice('Content cannot be empty.', 'error'); | |
| 2121 | - return; | |
| 2122 | - } | |
| 2123 | - | |
| 2124 | - saveBtn.disabled = true; | |
| 2125 | - if (saveText) saveText.style.display = 'none'; | |
| 2126 | - if (saveSpin) saveSpin.style.display = ''; | |
| 2127 | - showNotice('Saving and re-embedding...', ''); | |
| 2128 | - | |
| 2129 | - var formData = new FormData(); | |
| 2130 | - formData.append('action', 'mxchat_save_entry_content'); | |
| 2131 | - formData.append('nonce', currentEntry.nonce); | |
| 2132 | - formData.append('source_url', currentEntry.sourceUrl); | |
| 2133 | - formData.append('entry_id', currentEntry.entryId); | |
| 2134 | - formData.append('content', textarea.value); | |
| 2135 | - formData.append('data_source', currentEntry.dataSource); | |
| 2136 | - formData.append('bot_id', currentEntry.botId); | |
| 2137 | - formData.append('content_type', currentEntry.contentType || 'content'); | |
| 2138 | - | |
| 2139 | - fetch(ajaxurl, { method: 'POST', body: formData }) | |
| 2140 | - .then(function(r) { return r.json(); }) | |
| 2141 | - .then(function(resp) { | |
| 2142 | - if (saveText) saveText.style.display = ''; | |
| 2143 | - if (saveSpin) saveSpin.style.display = 'none'; | |
| 2144 | - saveBtn.disabled = false; | |
| 2145 | - | |
| 2146 | - if (resp.success) { | |
| 2147 | - showNotice('Saved successfully!', 'success'); | |
| 2148 | - setTimeout(function() { | |
| 2149 | - closeModal(); | |
| 2150 | - window.location.reload(); | |
| 2151 | - }, 1000); | |
| 2152 | - } else { | |
| 2153 | - showNotice((resp.data && resp.data.message) || 'Save failed.', 'error'); | |
| 2154 | - } | |
| 2155 | - }) | |
| 2156 | - .catch(function(err) { | |
| 2157 | - if (saveText) saveText.style.display = ''; | |
| 2158 | - if (saveSpin) saveSpin.style.display = 'none'; | |
| 2159 | - saveBtn.disabled = false; | |
| 2160 | - showNotice('Network error: ' + err.message, 'error'); | |
| 2161 | - }); | |
| 2162 | - } | |
| 2163 | - | |
| 2164 | - function closeModal() { | |
| 2165 | - modal.classList.remove('active'); | |
| 2166 | - } | |
| 2167 | - | |
| 2168 | - function updateCharCount() { | |
| 2169 | - var len = textarea.value.length; | |
| 2170 | - charCount.textContent = len.toLocaleString() + ' characters'; | |
| 2171 | - } | |
| 2172 | - | |
| 2173 | - function showNotice(msg, type) { | |
| 2174 | - notice.textContent = msg; | |
| 2175 | - notice.className = 'mxchat-kb-edit-notice' + (type ? ' ' + type : ''); | |
| 2176 | - } | |
| 2177 | - | |
| 2178 | - function escapeHtml(str) { | |
| 2179 | - var div = document.createElement('div'); | |
| 2180 | - div.textContent = str; | |
| 2181 | - return div.innerHTML; | |
| 2182 | - } | |
| 2183 | - | |
| 2184 | - function truncate(str, max) { | |
| 2185 | - return str.length > max ? str.substring(0, max) + '...' : str; | |
| 2186 | - } | |
| 2187 | - } | |
| 2188 | - | |
| 2189 | 1858 | })(); |
| 2190 | 1859 | </script> |
| 2191 | 1860 | <?php |
| 2192 | 1861 | } |