PluginProbe
MxChat – AI Chatbot & Content Generation for WordPress / 3.0.9
MxChat – AI Chatbot & Content Generation for WordPress v3.0.9
3.2.21 3.2.20 3.2.19 3.2.18 3.2.17 3.2.16 3.2.15 3.2.14 3.2.12 3.2.13 3.2.11 3.2.10 3.2.9 3.2.8 3.2.7 3.2.6 3.2.5 3.2.4 3.2.3 3.2.2 3.2.1 2.0.3 2.0.4 2.0.5 2.0.6 All 152 releases
← All changes | includes/admin-knowledge-page.php +9 -560 3.2.113.0.9 View file →
@@ -272,14 +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 - // Render the read-only Knowledge Inspector modal (plan-d8cb4b)
280 - mxchat_render_inspect_entry_modal();
281 -
282 276 // Render the navigation JavaScript
283 277 mxchat_render_knowledge_page_scripts();
284 278 }
285 279
@@ -534,29 +528,18 @@
534 528 <p><?php esc_html_e('Submit content to be vectorized.', 'mxchat'); ?></p>
535 529 </div>
536 530 </button>
537 531
538 - <!-- PDF Import Option (URL) -->
539 - <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">
532 + <!-- PDF Import Option -->
533 + <button type="button" class="mxchat-import-box" data-option="pdf" data-placeholder="<?php esc_attr_e('Enter PDF URL here', 'mxchat'); ?>" data-type="pdf">
540 534 <div class="mxchat-import-icon">
541 535 <span class="dashicons dashicons-media-document"></span>
542 536 </div>
543 537 <div class="mxchat-import-content">
544 538 <h4><?php esc_html_e('PDF Import', 'mxchat'); ?></h4>
545 - <p><?php esc_html_e('Import knowledge from PDF URL.', 'mxchat'); ?></p>
539 + <p><?php esc_html_e('Import knowledge from PDF documents.', 'mxchat'); ?></p>
546 540 </div>
547 541 </button>
548 -
549 - <!-- PDF File Upload Option -->
550 - <button type="button" class="mxchat-import-box" data-option="pdf-upload" data-type="pdf-upload">
551 - <div class="mxchat-import-icon">
552 - <span class="dashicons dashicons-upload"></span>
553 - </div>
554 - <div class="mxchat-import-content">
555 - <h4><?php esc_html_e('PDF Upload', 'mxchat'); ?></h4>
556 - <p><?php esc_html_e('Upload a PDF file from your computer.', 'mxchat'); ?></p>
557 - </div>
558 - </button>
559 542 </div>
560 543
561 544 <!-- Detected Sitemaps Section (hidden by default, shown when Sitemap Import is clicked) -->
562 545 <div id="mxchat-detected-sitemaps" class="mxchat-detected-sitemaps" style="display: none;">
@@ -640,26 +623,8 @@
640 623 <?php esc_html_e('Import Content', 'mxchat'); ?>
641 624 </button>
642 625 </form>
643 626 </div>
644 -
645 - <div class="mxchat-import-input-area" id="mxchat-pdf-upload-area" style="display: none; margin-top: 20px;">
646 - <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">
647 - <?php wp_nonce_field('mxchat_submit_pdf_file_action', 'mxchat_submit_pdf_file_nonce'); ?>
648 - <?php if ($multibot_active && $current_bot_id !== 'default') : ?>
649 - <input type="hidden" name="bot_id" value="<?php echo esc_attr($current_bot_id); ?>">
650 - <?php endif; ?>
651 - <div class="mxch-field">
652 - <input type="file" name="pdf_file" id="mxchat-pdf-file-input" accept=".pdf" required>
653 - </div>
654 - <p class="mxch-field-description">
655 - <?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'); ?>
656 - </p>
657 - <button type="submit" name="submit_pdf_file" class="mxch-btn mxch-btn-primary">
658 - <?php esc_html_e('Import PDF', 'mxchat'); ?>
659 - </button>
660 - </form>
661 - </div>
662 627 <?php endif; ?>
663 628 </div>
664 629 </div>
665 630 </div>
@@ -851,39 +816,15 @@
851 816 </form>
852 817 <!-- Delete Button Container - transforms between Delete All and Delete Selected -->
853 818 <div class="mxchat-delete-container" id="mxchat-delete-container">
854 819 <!-- Delete All Form (shown when nothing selected) -->
855 - <?php
856 - // Build confirm message and button text based on active filter
857 - $delete_all_label = __('Delete All', 'mxchat');
858 - $delete_all_confirm = __('Are you sure you want to delete all knowledge?', 'mxchat');
859 - if (!empty($content_type_filter)) {
860 - $filter_display = $content_type_filter;
861 - // Try to get a human-readable label
862 - $pt_obj = get_post_type_object($content_type_filter);
863 - if ($pt_obj) {
864 - $filter_display = $pt_obj->label;
865 - } elseif ($content_type_filter === 'pdf') {
866 - $filter_display = 'PDFs';
867 - } elseif ($content_type_filter === 'url') {
868 - $filter_display = 'URLs';
869 - }
870 - /* translators: %s: content type label (e.g. "Pages", "PDFs") */
871 - $delete_all_label = sprintf(__('Delete All %s', 'mxchat'), $filter_display);
872 - /* translators: %s: content type label */
873 - $delete_all_confirm = sprintf(__('Are you sure you want to delete all %s from the knowledge base?', 'mxchat'), $filter_display);
874 - }
875 - ?>
876 - <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); ?>');">
820 + <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'); ?>');">
877 821 <?php wp_nonce_field('mxchat_delete_all_prompts_action', 'mxchat_delete_all_prompts_nonce'); ?>
878 822 <input type="hidden" name="data_source" value="<?php echo esc_attr($data_source); ?>" />
879 823 <input type="hidden" name="bot_id" value="<?php echo esc_attr($current_bot_id); ?>" />
880 - <?php if (!empty($content_type_filter)) : ?>
881 - <input type="hidden" name="content_type_filter" value="<?php echo esc_attr($content_type_filter); ?>" />
882 - <?php endif; ?>
883 824 <button type="submit" class="mxch-btn mxch-btn-secondary mxch-btn-sm" style="color: var(--mxch-error);">
884 825 <span class="dashicons dashicons-trash" style="font-size: 14px;"></span>
885 - <?php echo esc_html($delete_all_label); ?>
826 + <?php esc_html_e('Delete All', 'mxchat'); ?>
886 827 </button>
887 828 </form>
888 829 <!-- Delete Selected Button (shown when items selected) -->
889 830 <button type="button"
@@ -991,32 +932,10 @@
991 932 <?php else : ?>
992 933 <span style="color: var(--mxch-text-muted);"><?php esc_html_e('Manual Content', 'mxchat'); ?></span>
993 934 <?php endif; ?>
994 935 </td>
995 - <td class="mxchat-actions-cell" style="padding: 12px 16px; white-space: nowrap;">
936 + <td class="mxchat-actions-cell" style="padding: 12px 16px;">
996 937 <button type="button"
997 - class="mxch-btn mxch-btn-ghost mxch-btn-sm mxchat-inspect-entry-btn"
998 - data-source-url="<?php echo esc_attr($source_url); ?>"
999 - data-entry-id="<?php echo esc_attr($first_prompt->id); ?>"
1000 - data-data-source="<?php echo esc_attr($data_source); ?>"
1001 - data-bot-id="<?php echo esc_attr($current_bot_id); ?>"
1002 - data-nonce="<?php echo wp_create_nonce('mxchat_inspect_entry_nonce'); ?>"
1003 - title="<?php esc_attr_e('View indexed content', 'mxchat'); ?>">
1004 - <span class="dashicons dashicons-visibility" style="font-size: 14px;"></span>
1005 - </button>
1006 - <?php if ($data_source !== 'pinecone') : ?>
1007 - <button type="button"
1008 - class="mxch-btn mxch-btn-ghost mxch-btn-sm mxchat-edit-entry-btn"
1009 - data-source-url="<?php echo esc_attr($source_url); ?>"
1010 - data-entry-id="<?php echo esc_attr($first_prompt->id); ?>"
1011 - data-data-source="<?php echo esc_attr($data_source); ?>"
1012 - data-bot-id="<?php echo esc_attr($current_bot_id); ?>"
1013 - data-nonce="<?php echo wp_create_nonce('mxchat_edit_entry_nonce'); ?>"
1014 - title="<?php esc_attr_e('Edit content', 'mxchat'); ?>">
1015 - <span class="dashicons dashicons-edit" style="font-size: 14px;"></span>
1016 - </button>
1017 - <?php endif; ?>
1018 - <button type="button"
1019 938 class="mxch-btn mxch-btn-ghost mxch-btn-sm delete-button-group"
1020 939 data-source-url="<?php echo esc_attr($source_url); ?>"
1021 940 data-chunk-count="<?php echo esc_attr($chunk_count); ?>"
1022 941 data-data-source="<?php echo esc_attr($data_source); ?>"
@@ -1151,31 +1070,9 @@
1151 1070 <?php else : ?>
1152 1071 <span style="color: var(--mxch-text-muted);"><?php esc_html_e('Manual', 'mxchat'); ?></span>
1153 1072 <?php endif; ?>
1154 1073 </td>
1155 - <td style="padding: 12px 16px; white-space: nowrap;">
1156 - <button type="button"
1157 - class="mxch-btn mxch-btn-ghost mxch-btn-sm mxchat-inspect-entry-btn"
1158 - data-source-url="<?php echo esc_attr($prompt->source_url ?? ''); ?>"
1159 - data-entry-id="<?php echo esc_attr($prompt->id); ?>"
1160 - data-data-source="<?php echo esc_attr($data_source); ?>"
1161 - data-bot-id="<?php echo esc_attr($current_bot_id); ?>"
1162 - data-nonce="<?php echo wp_create_nonce('mxchat_inspect_entry_nonce'); ?>"
1163 - title="<?php esc_attr_e('View indexed content', 'mxchat'); ?>">
1164 - <span class="dashicons dashicons-visibility" style="font-size: 14px;"></span>
1165 - </button>
1166 - <?php if ($data_source !== 'pinecone') : ?>
1167 - <button type="button"
1168 - class="mxch-btn mxch-btn-ghost mxch-btn-sm mxchat-edit-entry-btn"
1169 - data-source-url="<?php echo esc_attr($prompt->source_url ?? ''); ?>"
1170 - data-entry-id="<?php echo esc_attr($prompt->id); ?>"
1171 - data-data-source="<?php echo esc_attr($data_source); ?>"
1172 - data-bot-id="<?php echo esc_attr($current_bot_id); ?>"
1173 - data-nonce="<?php echo wp_create_nonce('mxchat_edit_entry_nonce'); ?>"
1174 - title="<?php esc_attr_e('Edit content', 'mxchat'); ?>">
1175 - <span class="dashicons dashicons-edit" style="font-size: 14px;"></span>
1176 - </button>
1177 - <?php endif; ?>
1074 + <td style="padding: 12px 16px;">
1178 1075 <?php if ($data_source === 'pinecone') : ?>
1179 1076 <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);">
1180 1077 <span class="dashicons dashicons-trash" style="font-size: 14px;"></span>
1181 1078 </button>
@@ -1269,19 +1166,8 @@
1269 1166 <span style="font-weight: 500;"><?php esc_html_e('Auto-sync Pages', 'mxchat'); ?></span>
1270 1167 </div>
1271 1168 </div>
1272 1169
1273 - <div class="mxch-field" style="margin-top: 24px; padding-top: 20px; border-top: 1px solid var(--mxch-card-border);">
1274 - <div style="display: flex; align-items: center; gap: 12px;">
1275 - <label class="mxchat-toggle-switch">
1276 - <input type="checkbox" name="mxchat_auto_sync_acf_pdfs" class="mxchat-autosave-field" value="1" data-nonce="<?php echo wp_create_nonce('mxchat_prompts_setting_nonce'); ?>" <?php checked(get_option('mxchat_auto_sync_acf_pdfs', '0'), '1'); ?>>
1277 - <span class="mxchat-toggle-slider"></span>
1278 - </label>
1279 - <span style="font-weight: 500;"><?php esc_html_e('Extract text from PDFs in ACF fields on save', 'mxchat'); ?></span>
1280 - </div>
1281 - <p class="mxch-field-description" style="margin-top: 8px;"><?php esc_html_e('When ON, editor saves re-extract every PDF referenced in ACF fields. Default OFF — saves stay fast and don\'t re-parse the same PDFs on every edit. The manual content selector has its own per-batch checkbox; this setting only controls the auto-sync path.', 'mxchat'); ?></p>
1282 - </div>
1283 -
1284 1170 <div style="margin-top: 24px;">
1285 1171 <button id="mxchat-custom-post-types-toggle" class="mxch-btn mxch-btn-secondary">
1286 1172 <?php esc_html_e('Advanced Custom Post Sync Settings', 'mxchat'); ?>
1287 1173 <span style="margin-left: 5px;">▼</span>
@@ -1389,11 +1275,10 @@
1389 1275
1390 1276 <h4 style="margin: 0 0 16px 0;"><?php esc_html_e('Add Tag-Role Mapping', 'mxchat'); ?></h4>
1391 1277 <div style="display: flex; gap: 15px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 24px;">
1392 1278 <div class="mxch-field" style="flex: 1; min-width: 200px; margin-bottom: 0;">
1393 - <label class="mxch-field-label" for="mxchat-tag-input"><?php esc_html_e('Tag (name or slug)', 'mxchat'); ?></label>
1394 - <input type="text" id="mxchat-tag-input" class="mxch-input" placeholder="<?php esc_attr_e('e.g., Premium Content or premium-content', 'mxchat'); ?>">
1395 - <span class="mxch-field-hint"><?php esc_html_e('Enter an existing post tag by its display name or its slug.', 'mxchat'); ?></span>
1279 + <label class="mxch-field-label" for="mxchat-tag-input"><?php esc_html_e('Tag Name', 'mxchat'); ?></label>
1280 + <input type="text" id="mxchat-tag-input" class="mxch-input" placeholder="<?php esc_attr_e('e.g., premium, members-only', 'mxchat'); ?>">
1396 1281 </div>
1397 1282 <div class="mxch-field" style="flex: 1; min-width: 200px; margin-bottom: 0;">
1398 1283 <label class="mxch-field-label" for="mxchat-role-select"><?php esc_html_e('Required Role', 'mxchat'); ?></label>
1399 1284 <select id="mxchat-role-select" class="mxch-select">
@@ -1800,15 +1685,8 @@
1800 1685 </div>
1801 1686 </div>
1802 1687 <div class="mxchat-kb-modal-footer">
1803 1688 <div class="mxchat-kb-pagination"></div>
1804 - <div class="mxchat-kb-acf-pdf-option" style="display:flex; align-items:flex-start; gap:8px; padding:8px 0; font-size:12px; color: var(--mxch-text-secondary, #64748b);">
1805 - <input type="checkbox" id="mxchat-kb-acf-pdf-extract" style="margin-top:2px;">
1806 - <label for="mxchat-kb-acf-pdf-extract" style="cursor:pointer; line-height:1.4;">
1807 - <strong style="color: var(--mxch-text-primary, #1a1a2e);"><?php esc_html_e('Also extract text from PDFs linked in ACF File/Image fields', 'mxchat'); ?></strong><br>
1808 - <span><?php esc_html_e('Adds 200-500ms per post and ~30 KB to each KB entry. Recommended only if your ACF setup uses PDF attachments for primary content.', 'mxchat'); ?></span>
1809 - </label>
1810 - </div>
1811 1689 <div class="mxchat-kb-footer-actions">
1812 1690 <button type="button" id="mxchat-kb-process-selected" class="mxchat-kb-button-primary" disabled>
1813 1691 <?php esc_html_e('Process Selected Content', 'mxchat'); ?>
1814 1692 <span class="mxchat-kb-selected-count">(0)</span>
@@ -1823,248 +1701,8 @@
1823 1701 <?php
1824 1702 }
1825 1703
1826 1704 /**
1827 - * Render Edit Entry Modal
1828 - */
1829 -function mxchat_render_edit_entry_modal() {
1830 - ?>
1831 - <div id="mxchat-kb-edit-modal" class="mxchat-kb-modal">
1832 - <div class="mxchat-kb-modal-content mxchat-kb-edit-modal-content">
1833 - <div class="mxchat-kb-modal-header">
1834 - <h3 id="mxchat-kb-edit-title"><?php esc_html_e('Edit Knowledge Entry', 'mxchat'); ?></h3>
1835 - <span class="mxchat-kb-modal-close" id="mxchat-kb-edit-close">&times;</span>
1836 - </div>
1837 - <div class="mxchat-kb-edit-body">
1838 - <div class="mxchat-kb-edit-source" id="mxchat-kb-edit-source"></div>
1839 - <textarea id="mxchat-kb-edit-textarea" class="mxchat-kb-edit-textarea" placeholder="<?php esc_attr_e('Loading content...', 'mxchat'); ?>"></textarea>
1840 - <div class="mxchat-kb-edit-meta">
1841 - <span id="mxchat-kb-edit-charcount"></span>
1842 - <span id="mxchat-kb-edit-chunkinfo"></span>
1843 - </div>
1844 - </div>
1845 - <div class="mxchat-kb-edit-footer">
1846 - <div class="mxchat-kb-edit-notice" id="mxchat-kb-edit-notice"></div>
1847 - <div class="mxchat-kb-edit-actions">
1848 - <button type="button" id="mxchat-kb-edit-cancel" class="mxch-btn mxch-btn-ghost">
1849 - <?php esc_html_e('Cancel', 'mxchat'); ?>
1850 - </button>
1851 - <button type="button" id="mxchat-kb-edit-save" class="mxch-btn mxch-btn-primary">
1852 - <span class="mxchat-kb-edit-save-text"><?php esc_html_e('Save & Re-embed', 'mxchat'); ?></span>
1853 - <span class="mxchat-kb-edit-save-spinner" style="display:none;">
1854 - <span class="mxchat-kb-spinner is-active" style="margin: 0;"></span>
1855 - <?php esc_html_e('Saving...', 'mxchat'); ?>
1856 - </span>
1857 - </button>
1858 - </div>
1859 - </div>
1860 - </div>
1861 - </div>
1862 - <?php
1863 -}
1864 -
1865 -/**
1866 - * Render the read-only Knowledge Inspector modal (plan-mxchat-20260628-d8cb4b).
1867 - * Shows exactly what was indexed for an entry: the per-chunk stored text + lengths
1868 - * and (for Pinecone) the stored metadata fields, rendered with the Testing tab's
1869 - * own card components so the two surfaces feel like one system. Self-contained
1870 - * markup + JS so it doesn't entangle the edit-modal init.
1871 - */
1872 -function mxchat_render_inspect_entry_modal() {
1873 - ?>
1874 - <div id="mxchat-kb-inspect-modal" class="mxchat-kb-modal">
1875 - <div class="mxchat-kb-modal-content mxchat-kb-inspect-modal-content">
1876 - <div class="mxchat-kb-modal-header">
1877 - <h3 id="mxchat-kb-inspect-title"><?php esc_html_e('Indexed Content', 'mxchat'); ?></h3>
1878 - <span class="mxchat-kb-modal-close" id="mxchat-kb-inspect-close">&times;</span>
1879 - </div>
1880 - <div class="mxchat-kb-inspect-body">
1881 - <div class="mxchat-kb-edit-source" id="mxchat-kb-inspect-source"></div>
1882 - <div class="mxch-testing-results" id="mxchat-kb-inspect-results">
1883 - <div class="mxch-testing-no-data"><?php esc_html_e('Loading indexed content…', 'mxchat'); ?></div>
1884 - </div>
1885 - </div>
1886 - <div class="mxchat-kb-edit-footer">
1887 - <div class="mxchat-kb-edit-notice" id="mxchat-kb-inspect-notice"></div>
1888 - <div class="mxchat-kb-edit-actions">
1889 - <button type="button" id="mxchat-kb-inspect-close-btn" class="mxch-btn mxch-btn-primary">
1890 - <?php esc_html_e('Close', 'mxchat'); ?>
1891 - </button>
1892 - </div>
1893 - </div>
1894 - </div>
1895 - </div>
1896 - <script>
1897 - (function() {
1898 - 'use strict';
1899 - document.addEventListener('DOMContentLoaded', function() {
1900 - var modal = document.getElementById('mxchat-kb-inspect-modal');
1901 - if (!modal) return;
1902 - var closeX = document.getElementById('mxchat-kb-inspect-close');
1903 - var closeBtn = document.getElementById('mxchat-kb-inspect-close-btn');
1904 - var sourceEl = document.getElementById('mxchat-kb-inspect-source');
1905 - var resultsEl= document.getElementById('mxchat-kb-inspect-results');
1906 - var titleEl = document.getElementById('mxchat-kb-inspect-title');
1907 - var noticeEl = document.getElementById('mxchat-kb-inspect-notice');
1908 -
1909 - var I18N = {
1910 - title: <?php echo wp_json_encode( esc_html__('Indexed Content', 'mxchat') ); ?>,
1911 - loading: <?php echo wp_json_encode( esc_html__('Loading indexed content…', 'mxchat') ); ?>,
1912 - manual: <?php echo wp_json_encode( esc_html__('Manual Content', 'mxchat') ); ?>,
1913 - source: <?php echo wp_json_encode( esc_html__('Source', 'mxchat') ); ?>,
1914 - store: <?php echo wp_json_encode( esc_html__('Storage', 'mxchat') ); ?>,
1915 - type: <?php echo wp_json_encode( esc_html__('Content type', 'mxchat') ); ?>,
1916 - chunksLbl:<?php echo wp_json_encode( esc_html__('Chunks', 'mxchat') ); ?>,
1917 - totalLen: <?php echo wp_json_encode( esc_html__('Total indexed length', 'mxchat') ); ?>,
1918 - chunk: <?php echo wp_json_encode( esc_html__('Chunk', 'mxchat') ); ?>,
1919 - indexed: <?php echo wp_json_encode( esc_html__('Indexed', 'mxchat') ); ?>,
1920 - chars: <?php echo wp_json_encode( esc_html__('chars', 'mxchat') ); ?>,
1921 - showText: <?php echo wp_json_encode( esc_html__('Show indexed text', 'mxchat') ); ?>,
1922 - hideText: <?php echo wp_json_encode( esc_html__('Hide indexed text', 'mxchat') ); ?>,
1923 - wpStore: <?php echo wp_json_encode( esc_html__('Local WordPress database', 'mxchat') ); ?>,
1924 - pcStore: <?php echo wp_json_encode( esc_html__('Pinecone', 'mxchat') ); ?>,
1925 - meta: <?php echo wp_json_encode( esc_html__('Vector metadata', 'mxchat') ); ?>,
1926 - loadFail: <?php echo wp_json_encode( esc_html__('Failed to load indexed content.', 'mxchat') ); ?>,
1927 - netErr: <?php echo wp_json_encode( esc_html__('Network error: ', 'mxchat') ); ?>
1928 - };
1929 -
1930 - function esc(str) {
1931 - var d = document.createElement('div');
1932 - d.textContent = (str === null || str === undefined) ? '' : String(str);
1933 - return d.innerHTML;
1934 - }
1935 - function fmt(n) { try { return Number(n).toLocaleString(); } catch (e) { return n; } }
1936 -
1937 - document.addEventListener('click', function(e) {
1938 - var btn = e.target.closest('.mxchat-inspect-entry-btn');
1939 - if (btn) { e.preventDefault(); open(btn); }
1940 - });
1941 - if (closeX) closeX.addEventListener('click', close);
1942 - if (closeBtn) closeBtn.addEventListener('click', close);
1943 - modal.addEventListener('click', function(e) { if (e.target === modal) close(); });
1944 - document.addEventListener('keydown', function(e) {
1945 - if (e.key === 'Escape' && modal.classList.contains('active')) close();
1946 - });
1947 -
1948 - function close() { modal.classList.remove('active'); }
1949 -
1950 - function open(btn) {
1951 - var entry = {
1952 - sourceUrl: btn.getAttribute('data-source-url') || '',
1953 - entryId: btn.getAttribute('data-entry-id') || '',
1954 - dataSource: btn.getAttribute('data-data-source') || 'wordpress',
1955 - botId: btn.getAttribute('data-bot-id') || 'default',
1956 - nonce: btn.getAttribute('data-nonce') || ''
1957 - };
1958 -
1959 - titleEl.textContent = I18N.title;
1960 - noticeEl.textContent = '';
1961 - noticeEl.className = 'mxchat-kb-edit-notice';
1962 - resultsEl.innerHTML = '<div class="mxch-testing-no-data">' + esc(I18N.loading) + '</div>';
1963 -
1964 - if (entry.sourceUrl && entry.sourceUrl.indexOf('mxchat://') !== 0 && entry.sourceUrl.indexOf('_ungrouped_') !== 0) {
1965 - sourceEl.innerHTML = esc(I18N.source) + ': <a href="' + esc(entry.sourceUrl) + '" target="_blank" rel="noopener">' + esc(entry.sourceUrl) + '</a>';
1966 - } else {
1967 - sourceEl.textContent = I18N.manual;
1968 - }
1969 -
1970 - modal.classList.add('active');
1971 -
1972 - var fd = new FormData();
1973 - fd.append('action', 'mxchat_inspect_entry');
1974 - fd.append('nonce', entry.nonce);
1975 - fd.append('source_url', entry.sourceUrl);
1976 - fd.append('entry_id', entry.entryId);
1977 - fd.append('data_source', entry.dataSource);
1978 - fd.append('bot_id', entry.botId);
1979 -
1980 - fetch(ajaxurl, { method: 'POST', body: fd })
1981 - .then(function(r) { return r.json(); })
1982 - .then(function(resp) {
1983 - if (resp && resp.success) {
1984 - render(resp.data);
1985 - } else {
1986 - var msg = (resp && resp.data && resp.data.message) || I18N.loadFail;
1987 - resultsEl.innerHTML = '';
1988 - showNotice(msg, 'error');
1989 - }
1990 - })
1991 - .catch(function(err) {
1992 - resultsEl.innerHTML = '';
1993 - showNotice(I18N.netErr + err.message, 'error');
1994 - });
1995 - }
1996 -
1997 - function render(data) {
1998 - var storeLabel = data.store === 'pinecone' ? I18N.pcStore : I18N.wpStore;
1999 - var html = '';
2000 -
2001 - // Summary card — what this entry is + how much was indexed.
2002 - html += '<div class="match-card above-threshold">' +
2003 - '<div class="match-header">' +
2004 - '<div class="match-title"><span class="status-icon">&#128230;</span> ' + esc(data.chunk_count) + ' ' + esc(I18N.chunksLbl.toLowerCase()) + '</div>' +
2005 - '<span class="context-label">' + esc(storeLabel) + '</span>' +
2006 - '</div>' +
2007 - '<div class="mxch-testing-field"><label>' + esc(I18N.type) + '</label><code>' + esc(data.content_type || '—') + '</code> ' +
2008 - '&nbsp; <label style="display:inline; text-transform:none; letter-spacing:0; font-weight:600;">' + esc(I18N.totalLen) + ':</label> ' + esc(fmt(data.assembled_length)) + ' ' + esc(I18N.chars) + '</div>';
2009 - if (data.metadata_note) {
2010 - html += '<div class="match-source"><span class="source-icon">&#8505;&#65039;</span> ' + esc(data.metadata_note) + '</div>';
2011 - }
2012 - html += '</div>';
2013 -
2014 - // One card per stored chunk — the actual embedded text.
2015 - var chunks = data.chunks || [];
2016 - chunks.forEach(function(chunk, i) {
2017 - var num = (chunk.index !== null && chunk.index !== undefined) ? (chunk.index + 1) : (i + 1);
2018 - var metaRows = '';
2019 - if (chunk.metadata && typeof chunk.metadata === 'object') {
2020 - var keys = Object.keys(chunk.metadata);
2021 - if (keys.length) {
2022 - metaRows += '<div class="chunk-detail-row chunk-used" style="display:block;"><span class="chunk-detail-num">' + esc(I18N.meta) + '</span></div>';
2023 - keys.forEach(function(k) {
2024 - metaRows += '<div class="chunk-detail-row"><span class="chunk-detail-num">' + esc(k) + '</span><span class="chunk-detail-score">' + esc(chunk.metadata[k]) + '</span></div>';
2025 - });
2026 - }
2027 - }
2028 - html += '<div class="match-card above-threshold">' +
2029 - '<div class="match-header">' +
2030 - '<div class="match-title"><span class="status-icon">&#10003;</span> ' + esc(I18N.chunk) + ' ' + esc(num) +
2031 - '<span class="chunk-summary">' + esc(fmt(chunk.length)) + ' ' + esc(I18N.chars) + '</span>' +
2032 - '</div>' +
2033 - '<span class="context-label">' + esc(I18N.indexed) + '</span>' +
2034 - '</div>' +
2035 - '<span class="chunk-expand-toggle" data-chunk="' + i + '">&#9654; ' + esc(I18N.showText) + '</span>' +
2036 - '<div class="chunk-details" data-chunk="' + i + '">' +
2037 - '<pre class="mxch-kb-inspect-chunk-text">' + esc(chunk.text) + '</pre>' +
2038 - metaRows +
2039 - '</div>' +
2040 - '</div>';
2041 - });
2042 -
2043 - resultsEl.innerHTML = html;
2044 -
2045 - resultsEl.querySelectorAll('.chunk-expand-toggle').forEach(function(toggle) {
2046 - toggle.addEventListener('click', function() {
2047 - var id = this.getAttribute('data-chunk');
2048 - var details = resultsEl.querySelector('.chunk-details[data-chunk="' + id + '"]');
2049 - if (!details) return;
2050 - var expanded = details.classList.toggle('expanded');
2051 - this.innerHTML = (expanded ? '&#9660; ' + esc(I18N.hideText) : '&#9654; ' + esc(I18N.showText));
2052 - });
2053 - });
2054 - }
2055 -
2056 - function showNotice(msg, type) {
2057 - noticeEl.textContent = msg;
2058 - noticeEl.className = 'mxchat-kb-edit-notice' + (type ? ' ' + type : '');
2059 - }
2060 - });
2061 - })();
2062 - </script>
2063 - <?php
2064 -}
2065 -
2066 -/**
2067 1705 * Render Knowledge Page Navigation Scripts
2068 1706 */
2069 1707 function mxchat_render_knowledge_page_scripts() {
2070 1708 ?>
@@ -2239,197 +1877,8 @@
2239 1877 }
2240 1878
2241 1879 // Sitemap detection is now handled by knowledge-processing.js
2242 1880 // It will be initialized when user clicks "Sitemap Import" option
2243 -
2244 - // ─── Edit Entry Modal ────────────────────────────────────
2245 - initEditModal();
2246 -
2247 - function initEditModal() {
2248 - var modal = document.getElementById('mxchat-kb-edit-modal');
2249 - var textarea = document.getElementById('mxchat-kb-edit-textarea');
2250 - var saveBtn = document.getElementById('mxchat-kb-edit-save');
2251 - var cancelBtn = document.getElementById('mxchat-kb-edit-cancel');
2252 - var closeBtn = document.getElementById('mxchat-kb-edit-close');
2253 - var notice = document.getElementById('mxchat-kb-edit-notice');
2254 - var charCount = document.getElementById('mxchat-kb-edit-charcount');
2255 - var chunkInfo = document.getElementById('mxchat-kb-edit-chunkinfo');
2256 - var sourceEl = document.getElementById('mxchat-kb-edit-source');
2257 - var titleEl = document.getElementById('mxchat-kb-edit-title');
2258 - var saveText = saveBtn ? saveBtn.querySelector('.mxchat-kb-edit-save-text') : null;
2259 - var saveSpin = saveBtn ? saveBtn.querySelector('.mxchat-kb-edit-save-spinner') : null;
2260 -
2261 - if (!modal) return;
2262 -
2263 - var currentEntry = {};
2264 -
2265 - // Bind edit buttons (delegated)
2266 - document.addEventListener('click', function(e) {
2267 - var btn = e.target.closest('.mxchat-edit-entry-btn');
2268 - if (btn) {
2269 - e.preventDefault();
2270 - openEditModal(btn);
2271 - }
2272 - });
2273 -
2274 - // Close handlers
2275 - if (closeBtn) closeBtn.addEventListener('click', closeModal);
2276 - if (cancelBtn) cancelBtn.addEventListener('click', closeModal);
2277 - modal.addEventListener('click', function(e) {
2278 - if (e.target === modal) closeModal();
2279 - });
2280 -
2281 - // Character count
2282 - if (textarea) {
2283 - textarea.addEventListener('input', function() {
2284 - updateCharCount();
2285 - });
2286 - }
2287 -
2288 - // Save handler
2289 - if (saveBtn) saveBtn.addEventListener('click', saveContent);
2290 -
2291 - function openEditModal(btn) {
2292 - currentEntry = {
2293 - sourceUrl: btn.getAttribute('data-source-url') || '',
2294 - entryId: btn.getAttribute('data-entry-id') || '',
2295 - dataSource: btn.getAttribute('data-data-source') || 'wordpress',
2296 - botId: btn.getAttribute('data-bot-id') || 'default',
2297 - nonce: btn.getAttribute('data-nonce') || ''
2298 - };
2299 -
2300 - // Reset state
2301 - textarea.value = '';
2302 - textarea.placeholder = 'Loading content...';
2303 - textarea.disabled = true;
2304 - saveBtn.disabled = true;
2305 - notice.textContent = '';
2306 - notice.className = 'mxchat-kb-edit-notice';
2307 - charCount.textContent = '';
2308 - chunkInfo.textContent = '';
2309 -
2310 - // Show source
2311 - if (currentEntry.sourceUrl && currentEntry.sourceUrl.indexOf('mxchat://') !== 0) {
2312 - sourceEl.innerHTML = 'Source: <a href="' + escapeHtml(currentEntry.sourceUrl) + '" target="_blank">' + escapeHtml(truncate(currentEntry.sourceUrl, 60)) + '</a>';
2313 - } else {
2314 - sourceEl.textContent = 'Manual Content';
2315 - }
2316 -
2317 - // Show modal
2318 - modal.classList.add('active');
2319 -
2320 - // Fetch content
2321 - var formData = new FormData();
2322 - formData.append('action', 'mxchat_get_entry_content');
2323 - formData.append('nonce', currentEntry.nonce);
2324 - formData.append('source_url', currentEntry.sourceUrl);
2325 - formData.append('entry_id', currentEntry.entryId);
2326 - formData.append('data_source', currentEntry.dataSource);
2327 - formData.append('bot_id', currentEntry.botId);
2328 -
2329 - fetch(ajaxurl, { method: 'POST', body: formData })
2330 - .then(function(r) { return r.json(); })
2331 - .then(function(resp) {
2332 - if (resp.success) {
2333 - textarea.value = resp.data.content || '';
2334 - textarea.disabled = false;
2335 - textarea.placeholder = 'Edit your content here...';
2336 - saveBtn.disabled = false;
2337 - currentEntry.contentType = resp.data.content_type || 'content';
2338 -
2339 - updateCharCount();
2340 -
2341 - if (resp.data.is_chunked) {
2342 - chunkInfo.textContent = resp.data.chunk_count + ' chunks — will be re-chunked on save';
2343 - titleEl.textContent = 'Edit Knowledge Entry (' + resp.data.chunk_count + ' chunks)';
2344 - } else {
2345 - chunkInfo.textContent = '';
2346 - titleEl.textContent = 'Edit Knowledge Entry';
2347 - }
2348 -
2349 - textarea.focus();
2350 - } else {
2351 - textarea.placeholder = '';
2352 - showNotice((resp.data && resp.data.message) || 'Failed to load content.', 'error');
2353 - }
2354 - })
2355 - .catch(function(err) {
2356 - textarea.placeholder = '';
2357 - showNotice('Network error: ' + err.message, 'error');
2358 - });
2359 - }
2360 -
2361 - function saveContent() {
2362 - if (!textarea.value.trim()) {
2363 - showNotice('Content cannot be empty.', 'error');
2364 - return;
2365 - }
2366 -
2367 - saveBtn.disabled = true;
2368 - if (saveText) saveText.style.display = 'none';
2369 - if (saveSpin) saveSpin.style.display = '';
2370 - showNotice('Saving and re-embedding...', '');
2371 -
2372 - var formData = new FormData();
2373 - formData.append('action', 'mxchat_save_entry_content');
2374 - formData.append('nonce', currentEntry.nonce);
2375 - formData.append('source_url', currentEntry.sourceUrl);
2376 - formData.append('entry_id', currentEntry.entryId);
2377 - formData.append('content', textarea.value);
2378 - formData.append('data_source', currentEntry.dataSource);
2379 - formData.append('bot_id', currentEntry.botId);
2380 - formData.append('content_type', currentEntry.contentType || 'content');
2381 -
2382 - fetch(ajaxurl, { method: 'POST', body: formData })
2383 - .then(function(r) { return r.json(); })
2384 - .then(function(resp) {
2385 - if (saveText) saveText.style.display = '';
2386 - if (saveSpin) saveSpin.style.display = 'none';
2387 - saveBtn.disabled = false;
2388 -
2389 - if (resp.success) {
2390 - showNotice('Saved successfully!', 'success');
2391 - setTimeout(function() {
2392 - closeModal();
2393 - window.location.reload();
2394 - }, 1000);
2395 - } else {
2396 - showNotice((resp.data && resp.data.message) || 'Save failed.', 'error');
2397 - }
2398 - })
2399 - .catch(function(err) {
2400 - if (saveText) saveText.style.display = '';
2401 - if (saveSpin) saveSpin.style.display = 'none';
2402 - saveBtn.disabled = false;
2403 - showNotice('Network error: ' + err.message, 'error');
2404 - });
2405 - }
2406 -
2407 - function closeModal() {
2408 - modal.classList.remove('active');
2409 - }
2410 -
2411 - function updateCharCount() {
2412 - var len = textarea.value.length;
2413 - charCount.textContent = len.toLocaleString() + ' characters';
2414 - }
2415 -
2416 - function showNotice(msg, type) {
2417 - notice.textContent = msg;
2418 - notice.className = 'mxchat-kb-edit-notice' + (type ? ' ' + type : '');
2419 - }
2420 -
2421 - function escapeHtml(str) {
2422 - var div = document.createElement('div');
2423 - div.textContent = str;
2424 - return div.innerHTML;
2425 - }
2426 -
2427 - function truncate(str, max) {
2428 - return str.length > max ? str.substring(0, max) + '...' : str;
2429 - }
2430 - }
2431 -
2432 1881 })();
2433 1882 </script>
2434 1883 <?php
2435 1884 }