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 +80 -745 3.2.193.0.9 View file →
@@ -73,9 +73,9 @@
73 73 <span><?php esc_html_e('Auto-Sync', 'mxchat'); ?></span>
74 74 </button>
75 75 <button class="mxch-mobile-nav-link" data-target="chunking">
76 76 <svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="7" height="7"/><rect x="14" y="3" width="7" height="7"/><rect x="14" y="14" width="7" height="7"/><rect x="3" y="14" width="7" height="7"/></svg>
77 - <span><?php esc_html_e('Chunking & Retrieval', 'mxchat'); ?></span>
77 + <span><?php esc_html_e('Content Chunking', 'mxchat'); ?></span>
78 78 </button>
79 79 <button class="mxch-mobile-nav-link" data-target="role-restrictions">
80 80 <svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"/></svg>
81 81 <span><?php esc_html_e('Role Restrictions', 'mxchat'); ?></span>
@@ -172,9 +172,9 @@
172 172 <button class="mxch-nav-link" data-target="chunking">
173 173 <span class="mxch-nav-link-icon">
174 174 <svg 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"><rect x="3" y="3" width="7" height="7"/><rect x="14" y="3" width="7" height="7"/><rect x="14" y="14" width="7" height="7"/><rect x="3" y="14" width="7" height="7"/></svg>
175 175 </span>
176 - <span class="mxch-nav-link-text"><?php esc_html_e('Chunking & Retrieval', 'mxchat'); ?></span>
176 + <span class="mxch-nav-link-text"><?php esc_html_e('Content Chunking', 'mxchat'); ?></span>
177 177 </button>
178 178 </div>
179 179
180 180 <div class="mxch-nav-item" data-section="role-restrictions">
@@ -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,40 +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 -
560 - <!-- YouTube Video Import Option -->
561 - <button type="button" class="mxchat-import-box" data-option="youtube" data-type="youtube">
562 - <div class="mxchat-import-icon">
563 - <span class="dashicons dashicons-youtube"></span>
564 - </div>
565 - <div class="mxchat-import-content">
566 - <h4><?php esc_html_e('YouTube', 'mxchat'); ?></h4>
567 - <p><?php esc_html_e('Index a video so the chat can surface it as a playable embed.', 'mxchat'); ?></p>
568 - </div>
569 - </button>
570 542 </div>
571 543
572 544 <!-- Detected Sitemaps Section (hidden by default, shown when Sitemap Import is clicked) -->
573 545 <div id="mxchat-detected-sitemaps" class="mxchat-detected-sitemaps" style="display: none;">
@@ -651,72 +623,8 @@
651 623 <?php esc_html_e('Import Content', 'mxchat'); ?>
652 624 </button>
653 625 </form>
654 626 </div>
655 -
656 - <div class="mxchat-import-input-area" id="mxchat-pdf-upload-area" style="display: none; margin-top: 20px;">
657 - <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">
658 - <?php wp_nonce_field('mxchat_submit_pdf_file_action', 'mxchat_submit_pdf_file_nonce'); ?>
659 - <?php if ($multibot_active && $current_bot_id !== 'default') : ?>
660 - <input type="hidden" name="bot_id" value="<?php echo esc_attr($current_bot_id); ?>">
661 - <?php endif; ?>
662 - <div class="mxch-field">
663 - <input type="file" name="pdf_file" id="mxchat-pdf-file-input" accept=".pdf" required>
664 - </div>
665 - <p class="mxch-field-description">
666 - <?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'); ?>
667 - </p>
668 - <button type="submit" name="submit_pdf_file" class="mxch-btn mxch-btn-primary">
669 - <?php esc_html_e('Import PDF', 'mxchat'); ?>
670 - </button>
671 - </form>
672 - </div>
673 -
674 - <?php
675 - // Prefill state: set when an auto-import found no transcript — the
676 - // handler bounced back here so the admin can augment the entry with
677 - // a manual description (re-importing the same URL updates the row).
678 - $yt_prefill = isset($_GET['mxchat_yt_prefill']) && $_GET['mxchat_yt_prefill'] === '1';
679 - $yt_prefill_url = $yt_prefill && isset($_GET['yt_url']) ? esc_url_raw(rawurldecode(wp_unslash($_GET['yt_url']))) : '';
680 - $yt_prefill_title = $yt_prefill && isset($_GET['yt_title']) ? sanitize_text_field(rawurldecode(wp_unslash($_GET['yt_title']))) : '';
681 - ?>
682 - <div class="mxchat-import-input-area" id="mxchat-youtube-input-area" style="display: none; margin-top: 20px;">
683 - <form id="mxchat-youtube-form" method="post" action="<?php echo esc_url(admin_url('admin-post.php?action=mxchat_submit_youtube')); ?>"<?php echo $yt_prefill ? ' data-yt-prefill="1"' : ''; ?>>
684 - <?php wp_nonce_field('mxchat_submit_youtube_action', 'mxchat_submit_youtube_nonce'); ?>
685 - <?php if ($multibot_active && $current_bot_id !== 'default') : ?>
686 - <input type="hidden" name="bot_id" value="<?php echo esc_attr($current_bot_id); ?>">
687 - <?php endif; ?>
688 - <div class="mxch-field">
689 - <input type="url" name="youtube_url" id="mxchat-youtube-url" class="mxch-input" placeholder="<?php esc_attr_e('Paste a YouTube video URL (watch, youtu.be, or Shorts link)', 'mxchat'); ?>" required value="<?php echo esc_attr($yt_prefill_url); ?>">
690 - </div>
691 - <div class="mxch-field">
692 - <span class="mxch-field-label"><?php esc_html_e('How should this video be described for matching?', 'mxchat'); ?></span>
693 - <div style="display: flex; flex-direction: column; gap: 6px; margin-top: 8px;">
694 - <label style="display: flex; align-items: baseline; gap: 8px; cursor: pointer;">
695 - <input type="radio" name="youtube_description_mode" value="auto" <?php checked(!$yt_prefill); ?>>
696 - <span>
697 - <strong><?php esc_html_e('Auto-fetch', 'mxchat'); ?></strong>
698 - <span class="mxch-field-description" style="display: block; margin: 2px 0 0;"><?php esc_html_e('We pull the video\'s title, channel, and captions (when available) to describe it.', 'mxchat'); ?></span>
699 - </span>
700 - </label>
701 - <label style="display: flex; align-items: baseline; gap: 8px; cursor: pointer;">
702 - <input type="radio" name="youtube_description_mode" value="manual" <?php checked($yt_prefill); ?>>
703 - <span>
704 - <strong><?php esc_html_e('Write my own', 'mxchat'); ?></strong>
705 - <span class="mxch-field-description" style="display: block; margin: 2px 0 0;"><?php esc_html_e('You write the description the chatbot matches against — best for curated guides.', 'mxchat'); ?></span>
706 - </span>
707 - </label>
708 - </div>
709 - </div>
710 - <div class="mxch-field" id="mxchat-youtube-description-field" style="<?php echo $yt_prefill ? '' : 'display: none;'; ?>">
711 - <textarea name="youtube_description" id="mxchat-youtube-description" class="mxch-textarea" rows="5" placeholder="<?php esc_attr_e('Describe what this video covers and the questions it answers...', 'mxchat'); ?>"><?php echo esc_textarea($yt_prefill_title !== '' ? $yt_prefill_title . "\n\n" : ''); ?></textarea>
712 - <p class="mxch-field-description"><?php esc_html_e('This text is what gets matched against visitor questions. Importing the same video URL again updates its existing entry.', 'mxchat'); ?></p>
713 - </div>
714 - <button type="submit" name="submit_youtube" value="1" class="mxch-btn mxch-btn-primary">
715 - <?php esc_html_e('Import Video', 'mxchat'); ?>
716 - </button>
717 - </form>
718 - </div>
719 627 <?php endif; ?>
720 628 </div>
721 629 </div>
722 630 </div>
@@ -908,39 +816,15 @@
908 816 </form>
909 817 <!-- Delete Button Container - transforms between Delete All and Delete Selected -->
910 818 <div class="mxchat-delete-container" id="mxchat-delete-container">
911 819 <!-- Delete All Form (shown when nothing selected) -->
912 - <?php
913 - // Build confirm message and button text based on active filter
914 - $delete_all_label = __('Delete All', 'mxchat');
915 - $delete_all_confirm = __('Are you sure you want to delete all knowledge?', 'mxchat');
916 - if (!empty($content_type_filter)) {
917 - $filter_display = $content_type_filter;
918 - // Try to get a human-readable label
919 - $pt_obj = get_post_type_object($content_type_filter);
920 - if ($pt_obj) {
921 - $filter_display = $pt_obj->label;
922 - } elseif ($content_type_filter === 'pdf') {
923 - $filter_display = 'PDFs';
924 - } elseif ($content_type_filter === 'url') {
925 - $filter_display = 'URLs';
926 - }
927 - /* translators: %s: content type label (e.g. "Pages", "PDFs") */
928 - $delete_all_label = sprintf(__('Delete All %s', 'mxchat'), $filter_display);
929 - /* translators: %s: content type label */
930 - $delete_all_confirm = sprintf(__('Are you sure you want to delete all %s from the knowledge base?', 'mxchat'), $filter_display);
931 - }
932 - ?>
933 - <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'); ?>');">
934 821 <?php wp_nonce_field('mxchat_delete_all_prompts_action', 'mxchat_delete_all_prompts_nonce'); ?>
935 822 <input type="hidden" name="data_source" value="<?php echo esc_attr($data_source); ?>" />
936 823 <input type="hidden" name="bot_id" value="<?php echo esc_attr($current_bot_id); ?>" />
937 - <?php if (!empty($content_type_filter)) : ?>
938 - <input type="hidden" name="content_type_filter" value="<?php echo esc_attr($content_type_filter); ?>" />
939 - <?php endif; ?>
940 824 <button type="submit" class="mxch-btn mxch-btn-secondary mxch-btn-sm" style="color: var(--mxch-error);">
941 825 <span class="dashicons dashicons-trash" style="font-size: 14px;"></span>
942 - <?php echo esc_html($delete_all_label); ?>
826 + <?php esc_html_e('Delete All', 'mxchat'); ?>
943 827 </button>
944 828 </form>
945 829 <!-- Delete Selected Button (shown when items selected) -->
946 830 <button type="button"
@@ -1048,32 +932,10 @@
1048 932 <?php else : ?>
1049 933 <span style="color: var(--mxch-text-muted);"><?php esc_html_e('Manual Content', 'mxchat'); ?></span>
1050 934 <?php endif; ?>
1051 935 </td>
1052 - <td class="mxchat-actions-cell" style="padding: 12px 16px; white-space: nowrap;">
936 + <td class="mxchat-actions-cell" style="padding: 12px 16px;">
1053 937 <button type="button"
1054 - class="mxch-btn mxch-btn-ghost mxch-btn-sm mxchat-inspect-entry-btn"
1055 - data-source-url="<?php echo esc_attr($source_url); ?>"
1056 - data-entry-id="<?php echo esc_attr($first_prompt->id); ?>"
1057 - data-data-source="<?php echo esc_attr($data_source); ?>"
1058 - data-bot-id="<?php echo esc_attr($current_bot_id); ?>"
1059 - data-nonce="<?php echo wp_create_nonce('mxchat_inspect_entry_nonce'); ?>"
1060 - title="<?php esc_attr_e('View indexed content', 'mxchat'); ?>">
1061 - <span class="dashicons dashicons-visibility" style="font-size: 14px;"></span>
1062 - </button>
1063 - <?php if ($data_source !== 'pinecone') : ?>
1064 - <button type="button"
1065 - class="mxch-btn mxch-btn-ghost mxch-btn-sm mxchat-edit-entry-btn"
1066 - data-source-url="<?php echo esc_attr($source_url); ?>"
1067 - data-entry-id="<?php echo esc_attr($first_prompt->id); ?>"
1068 - data-data-source="<?php echo esc_attr($data_source); ?>"
1069 - data-bot-id="<?php echo esc_attr($current_bot_id); ?>"
1070 - data-nonce="<?php echo wp_create_nonce('mxchat_edit_entry_nonce'); ?>"
1071 - title="<?php esc_attr_e('Edit content', 'mxchat'); ?>">
1072 - <span class="dashicons dashicons-edit" style="font-size: 14px;"></span>
1073 - </button>
1074 - <?php endif; ?>
1075 - <button type="button"
1076 938 class="mxch-btn mxch-btn-ghost mxch-btn-sm delete-button-group"
1077 939 data-source-url="<?php echo esc_attr($source_url); ?>"
1078 940 data-chunk-count="<?php echo esc_attr($chunk_count); ?>"
1079 941 data-data-source="<?php echo esc_attr($data_source); ?>"
@@ -1208,31 +1070,9 @@
1208 1070 <?php else : ?>
1209 1071 <span style="color: var(--mxch-text-muted);"><?php esc_html_e('Manual', 'mxchat'); ?></span>
1210 1072 <?php endif; ?>
1211 1073 </td>
1212 - <td style="padding: 12px 16px; white-space: nowrap;">
1213 - <button type="button"
1214 - class="mxch-btn mxch-btn-ghost mxch-btn-sm mxchat-inspect-entry-btn"
1215 - data-source-url="<?php echo esc_attr($prompt->source_url ?? ''); ?>"
1216 - data-entry-id="<?php echo esc_attr($prompt->id); ?>"
1217 - data-data-source="<?php echo esc_attr($data_source); ?>"
1218 - data-bot-id="<?php echo esc_attr($current_bot_id); ?>"
1219 - data-nonce="<?php echo wp_create_nonce('mxchat_inspect_entry_nonce'); ?>"
1220 - title="<?php esc_attr_e('View indexed content', 'mxchat'); ?>">
1221 - <span class="dashicons dashicons-visibility" style="font-size: 14px;"></span>
1222 - </button>
1223 - <?php if ($data_source !== 'pinecone') : ?>
1224 - <button type="button"
1225 - class="mxch-btn mxch-btn-ghost mxch-btn-sm mxchat-edit-entry-btn"
1226 - data-source-url="<?php echo esc_attr($prompt->source_url ?? ''); ?>"
1227 - data-entry-id="<?php echo esc_attr($prompt->id); ?>"
1228 - data-data-source="<?php echo esc_attr($data_source); ?>"
1229 - data-bot-id="<?php echo esc_attr($current_bot_id); ?>"
1230 - data-nonce="<?php echo wp_create_nonce('mxchat_edit_entry_nonce'); ?>"
1231 - title="<?php esc_attr_e('Edit content', 'mxchat'); ?>">
1232 - <span class="dashicons dashicons-edit" style="font-size: 14px;"></span>
1233 - </button>
1234 - <?php endif; ?>
1074 + <td style="padding: 12px 16px;">
1235 1075 <?php if ($data_source === 'pinecone') : ?>
1236 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);">
1237 1077 <span class="dashicons dashicons-trash" style="font-size: 14px;"></span>
1238 1078 </button>
@@ -1326,19 +1166,8 @@
1326 1166 <span style="font-weight: 500;"><?php esc_html_e('Auto-sync Pages', 'mxchat'); ?></span>
1327 1167 </div>
1328 1168 </div>
1329 1169
1330 - <div class="mxch-field" style="margin-top: 24px; padding-top: 20px; border-top: 1px solid var(--mxch-card-border);">
1331 - <div style="display: flex; align-items: center; gap: 12px;">
1332 - <label class="mxchat-toggle-switch">
1333 - <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'); ?>>
1334 - <span class="mxchat-toggle-slider"></span>
1335 - </label>
1336 - <span style="font-weight: 500;"><?php esc_html_e('Extract text from PDFs in ACF fields on save', 'mxchat'); ?></span>
1337 - </div>
1338 - <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>
1339 - </div>
1340 -
1341 1170 <div style="margin-top: 24px;">
1342 1171 <button id="mxchat-custom-post-types-toggle" class="mxch-btn mxch-btn-secondary">
1343 1172 <?php esc_html_e('Advanced Custom Post Sync Settings', 'mxchat'); ?>
1344 1173 <span style="margin-left: 5px;">▼</span>
@@ -1384,16 +1213,13 @@
1384 1213 $chunk_size = $chunking_settings['chunk_size'];
1385 1214 ?>
1386 1215 <div id="chunking" class="mxch-section">
1387 1216 <div class="mxch-content-header">
1388 - <h1 class="mxch-content-title"><?php esc_html_e('Chunking & Retrieval', 'mxchat'); ?></h1>
1389 - <p class="mxch-content-subtitle"><?php esc_html_e('Control how content is split for indexing and how the knowledge base is searched.', 'mxchat'); ?></p>
1217 + <h1 class="mxch-content-title"><?php esc_html_e('Content Chunking', 'mxchat'); ?></h1>
1218 + <p class="mxch-content-subtitle"><?php esc_html_e('Split large content into smaller segments for more accurate semantic search.', 'mxchat'); ?></p>
1390 1219 </div>
1391 1220
1392 1221 <div class="mxch-card">
1393 - <div class="mxch-card-header">
1394 - <h2 class="mxch-card-title"><?php esc_html_e('Chunking', 'mxchat'); ?></h2>
1395 - </div>
1396 1222 <div class="mxch-card-body mxchat-autosave-section">
1397 1223 <div class="mxch-notice mxch-notice-info" style="margin-bottom: 20px;">
1398 1224 <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>
1399 1225 <span><?php esc_html_e('Chunking improves retrieval quality for long documents. All chunks are reassembled before sending to the AI. Only applies to new submissions.', 'mxchat'); ?></span>
@@ -1415,74 +1241,8 @@
1415 1241 <p class="mxch-field-description"><?php esc_html_e('Recommended: 4000 characters (~1000 tokens). Range: 1000-10000. Larger chunks preserve more context.', 'mxchat'); ?></p>
1416 1242 </div>
1417 1243 </div>
1418 1244 </div>
1419 -
1420 - <?php
1421 - // Retrieval tuning (plan 11720c) — the hybrid keyword boost moved here
1422 - // from Settings → Behavior: it is KB retrieval tuning, so it lives with
1423 - // its natural siblings. SAME option key and save transport as before —
1424 - // the name routes to the mxchat_save_setting handler, whose
1425 - // mxchat_hybrid_keyword_toggle case still runs capability detection.
1426 - ?>
1427 - <div class="mxch-card">
1428 - <div class="mxch-card-header">
1429 - <h2 class="mxch-card-title"><?php esc_html_e('Retrieval', 'mxchat'); ?></h2>
1430 - </div>
1431 - <div class="mxch-card-body mxchat-autosave-section">
1432 - <div class="mxch-field">
1433 - <div style="display: flex; align-items: center; gap: 12px;">
1434 - <label class="mxchat-toggle-switch">
1435 - <input type="checkbox" name="mxchat_hybrid_keyword_toggle" id="mxchat_hybrid_keyword_toggle" class="mxchat-autosave-field" value="on" <?php checked(get_option('mxchat_hybrid_keyword_toggle', 'off'), 'on'); ?>>
1436 - <span class="mxchat-toggle-slider"></span>
1437 - </label>
1438 - <span style="font-weight: 500;"><?php esc_html_e('Hybrid keyword boost (WP-DB knowledge base)', 'mxchat'); ?></span>
1439 - </div>
1440 - <p class="mxch-field-description" style="margin-top: 8px;"><?php esc_html_e('Combines keyword matching with vector similarity when searching your WordPress-database knowledge base. Helps exact-token questions — product codes, SKUs, error codes, names — find the right document even when semantic similarity alone would miss it.', 'mxchat'); ?></p>
1441 - <p class="mxch-field-hint"><?php esc_html_e('Only affects the WordPress-database knowledge base; Pinecone is unaffected. Changes which sources are retrieved on existing installs, so test after enabling. The Transcripts sources panel labels how each match was found while this is on.', 'mxchat'); ?></p>
1442 - </div>
1443 - </div>
1444 - </div>
1445 -
1446 - <?php
1447 - // Video cards (plan f52492). Lives on the Knowledge screen because that
1448 - // is where the owner imported the video in the first place, and beside
1449 - // Retrieval because it is a retrieval-confidence question. Standalone
1450 - // options — see the mxchat_video_embed_* cases in class-ajax-handler.php.
1451 - $video_embed_enabled = MxChat_Utils::video_embed_enabled();
1452 - $video_embed_threshold = (int) round(MxChat_Utils::video_embed_threshold() * 100);
1453 - $mxchat_core_options = get_option('mxchat_options', array());
1454 - $site_threshold = isset($mxchat_core_options['similarity_threshold'])
1455 - ? (int) $mxchat_core_options['similarity_threshold']
1456 - : 35;
1457 - ?>
1458 - <div class="mxch-card">
1459 - <div class="mxch-card-header">
1460 - <h2 class="mxch-card-title"><?php esc_html_e('Video Cards', 'mxchat'); ?></h2>
1461 - </div>
1462 - <div class="mxch-card-body mxchat-autosave-section">
1463 - <div class="mxch-field" style="margin-bottom: 20px; padding-bottom: 20px; border-bottom: 1px solid var(--mxch-card-border);">
1464 - <div style="display: flex; align-items: center; gap: 12px;">
1465 - <label class="mxchat-toggle-switch">
1466 - <input type="checkbox" name="mxchat_video_embed_enabled" id="mxchat_video_embed_enabled" class="mxchat-autosave-field" value="on" <?php checked($video_embed_enabled, true); ?>>
1467 - <span class="mxchat-toggle-slider"></span>
1468 - </label>
1469 - <span style="font-weight: 500;"><?php esc_html_e('Show a video card when a YouTube source answers the question', 'mxchat'); ?></span>
1470 - </div>
1471 - <p class="mxch-field-description" style="margin-top: 8px;"><?php esc_html_e('Adds a click-to-play card beneath the reply when the answer came from a YouTube video you imported. Turn this off to stop video cards entirely without removing the videos from your knowledge base.', 'mxchat'); ?></p>
1472 - </div>
1473 -
1474 - <div class="mxch-field" id="mxchat-video-embed-threshold-field" style="<?php echo $video_embed_enabled ? '' : 'display: none;'; ?>">
1475 - <label class="mxch-field-label" for="mxchat_video_embed_threshold"><?php esc_html_e('Video Card Match Threshold (%)', 'mxchat'); ?></label>
1476 - <input type="number" name="mxchat_video_embed_threshold" id="mxchat_video_embed_threshold" class="mxch-input mxchat-autosave-field" value="<?php echo esc_attr($video_embed_threshold); ?>" min="20" max="95" step="1" style="max-width: 200px;">
1477 - <p class="mxch-field-description"><?php
1478 - /* translators: %d is the site-wide Similarity Threshold percentage. */
1479 - printf(esc_html__('How closely the video must match the question before its card is shown. Higher means fewer, more relevant cards. This is separate from the site-wide Similarity Threshold (currently %d%%), which decides what the AI reads — a video is worth reading from at a lower score than it is worth putting on screen.', 'mxchat'), (int) $site_threshold);
1480 - ?></p>
1481 - <p class="mxch-field-hint"><?php esc_html_e('Range 20-95. Raise this if visitors are shown videos unrelated to what they asked; lower it if a video that clearly answers the question is not appearing. The right number depends on your embedding model: older models such as text-embedding-ada-002 score even unrelated content around 70%, so those sites usually need 80 or higher before this has any effect. The Transcripts sources panel shows the match percentage of each source, which is the number to compare against.', 'mxchat'); ?></p>
1482 - </div>
1483 - </div>
1484 - </div>
1485 1245 </div>
1486 1246 <?php
1487 1247 }
1488 1248
@@ -1515,11 +1275,10 @@
1515 1275
1516 1276 <h4 style="margin: 0 0 16px 0;"><?php esc_html_e('Add Tag-Role Mapping', 'mxchat'); ?></h4>
1517 1277 <div style="display: flex; gap: 15px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 24px;">
1518 1278 <div class="mxch-field" style="flex: 1; min-width: 200px; margin-bottom: 0;">
1519 - <label class="mxch-field-label" for="mxchat-tag-input"><?php esc_html_e('Tag (name or slug)', 'mxchat'); ?></label>
1520 - <input type="text" id="mxchat-tag-input" class="mxch-input" placeholder="<?php esc_attr_e('e.g., Premium Content or premium-content', 'mxchat'); ?>">
1521 - <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'); ?>">
1522 1281 </div>
1523 1282 <div class="mxch-field" style="flex: 1; min-width: 200px; margin-bottom: 0;">
1524 1283 <label class="mxch-field-label" for="mxchat-role-select"><?php esc_html_e('Required Role', 'mxchat'); ?></label>
1525 1284 <select id="mxchat-role-select" class="mxch-select">
@@ -1582,23 +1341,8 @@
1582 1341 </div>
1583 1342
1584 1343 <div class="mxch-card">
1585 1344 <div class="mxch-card-body mxchat-autosave-section">
1586 - <?php
1587 - // Install-level ACF→PDF import extraction (plan 11720c) — moved
1588 - // here from a per-import checkbox in the content-selector modal.
1589 - // Default OFF, matching its own "recommended only if…" guidance.
1590 - ?>
1591 - <div class="mxch-field" style="margin-bottom: 20px; padding-bottom: 20px; border-bottom: 1px solid var(--mxch-card-border);">
1592 - <div style="display: flex; align-items: center; gap: 12px;">
1593 - <label class="mxchat-toggle-switch">
1594 - <input type="checkbox" name="mxchat_acf_pdf_extraction" id="mxchat_acf_pdf_extraction" class="mxchat-autosave-field" value="on" <?php checked(get_option('mxchat_acf_pdf_extraction', '0'), '1'); ?>>
1595 - <span class="mxchat-toggle-slider"></span>
1596 - </label>
1597 - <span style="font-weight: 500;"><?php esc_html_e('Extract text from PDFs linked in ACF File/Image fields during imports', 'mxchat'); ?></span>
1598 - </div>
1599 - <p class="mxch-field-description" style="margin-top: 8px;"><?php esc_html_e('Applies to WordPress Content imports. Adds 200-500ms per post and ~30 KB to each knowledge base entry. Recommended only if your ACF setup uses PDF attachments for primary content. Editor-save extraction has its own toggle under Auto-Sync.', 'mxchat'); ?></p>
1600 - </div>
1601 1345 <?php if (!function_exists('acf_get_field_groups')): ?>
1602 1346 <div class="mxch-notice mxch-notice-info">
1603 1347 <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>
1604 1348 <span><?php esc_html_e('Advanced Custom Fields (ACF) plugin is not detected. Install and activate ACF to use this feature.', 'mxchat'); ?></span>
@@ -1673,28 +1417,8 @@
1673 1417 <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>
1674 1418 <span><?php esc_html_e('Enter post meta keys to include in embeddings. This is useful for OptionTree fields, theme meta boxes, or any custom post meta that is not managed by ACF.', 'mxchat'); ?></span>
1675 1419 </div>
1676 1420
1677 - <!-- Meta-key discovery scanner (plan-mxchat-20260709-fe8e4e): mirror the ACF picker's
1678 - discover-for-you UX for non-ACF meta, so owners click keys instead of typing them blind. -->
1679 - <div class="mxch-field mxchat-meta-scan">
1680 - <label class="mxch-field-label"><?php esc_html_e('Discover meta keys', 'mxchat'); ?></label>
1681 - <p class="mxch-field-description" style="margin-top: 0;">
1682 - <?php esc_html_e('Scan your published content for custom meta keys, then click any you want to include. This gives non-ACF meta the same discover-and-click experience as the ACF picker.', 'mxchat'); ?>
1683 - </p>
1684 - <div class="mxchat-meta-scan-controls">
1685 - <button type="button" id="mxchat-scan-meta-btn" class="mxch-btn mxch-btn-secondary" data-nonce="<?php echo esc_attr(wp_create_nonce('mxchat_prompts_setting_nonce')); ?>">
1686 - <svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="11" cy="11" r="8"/><line x1="21" y1="21" x2="16.65" y2="16.65"/></svg>
1687 - <span class="mxchat-scan-label"><?php esc_html_e('Scan my content for meta keys', 'mxchat'); ?></span>
1688 - </button>
1689 - <label class="mxchat-meta-scan-internal">
1690 - <input type="checkbox" id="mxchat-scan-internal">
1691 - <?php esc_html_e('Include internal keys (underscore-prefixed)', 'mxchat'); ?>
1692 - </label>
1693 - </div>
1694 - <div id="mxchat-meta-scan-results" class="mxchat-meta-scan-results" aria-live="polite"></div>
1695 - </div>
1696 -
1697 1421 <div class="mxch-field">
1698 1422 <label class="mxch-field-label" for="mxchat_custom_meta_whitelist">
1699 1423 <?php esc_html_e('Meta Key Whitelist', 'mxchat'); ?>
1700 1424 </label>
@@ -1707,9 +1431,9 @@
1707 1431 data-nonce="<?php echo wp_create_nonce('mxchat_prompts_setting_nonce'); ?>"
1708 1432 style="font-family: monospace;"
1709 1433 ><?php echo esc_textarea($whitelist); ?></textarea>
1710 1434 <p class="mxch-field-description">
1711 - <?php esc_html_e('Enter one meta key per line. These fields will be appended to the content during embedding. Text values are added as-is; array or repeater values are flattened into a comma-separated list. Empty values are skipped.', 'mxchat'); ?>
1435 + <?php esc_html_e('Enter one meta key per line. These fields will be appended to the content during embedding. Only string values are included.', 'mxchat'); ?>
1712 1436 </p>
1713 1437 </div>
1714 1438
1715 1439 <div style="margin-top: 20px; padding: 16px; background: #f8fafc; border-radius: var(--mxch-radius-md);">
@@ -1716,9 +1440,9 @@
1716 1440 <h4 style="margin: 0 0 12px 0; font-size: 14px;"><?php esc_html_e('How to find meta keys:', 'mxchat'); ?></h4>
1717 1441 <ul style="margin: 0; padding-left: 20px; color: var(--mxch-text-secondary); font-size: 13px;">
1718 1442 <li><?php esc_html_e('Check your theme documentation for meta key names', 'mxchat'); ?></li>
1719 1443 <li><?php esc_html_e('Look in the wp_postmeta database table', 'mxchat'); ?></li>
1720 - <li><?php esc_html_e('Use the Scan my content for meta keys button above to discover the keys on your published content automatically', 'mxchat'); ?></li>
1444 + <li><?php esc_html_e('Use a plugin like "Show Post Meta" to view meta keys on any post', 'mxchat'); ?></li>
1721 1445 <li><?php esc_html_e('Meta keys starting with underscore (_) are usually hidden/internal', 'mxchat'); ?></li>
1722 1446 </ul>
1723 1447 </div>
1724 1448 </div>
@@ -1820,9 +1544,9 @@
1820 1544 $max_results = $vectorstore_options['mxchat_vectorstore_max_results'] ?? 5;
1821 1545
1822 1546 // Get current chat model to check compatibility
1823 1547 $mxchat_options = get_option('mxchat_options', array());
1824 - $current_model = $mxchat_options['model'] ?? 'gpt-5.6-sol';
1548 + $current_model = $mxchat_options['model'] ?? 'gpt-5.1-chat-latest';
1825 1549 $is_openai_model = preg_match('/^(gpt-|o1-|o3-)/', $current_model);
1826 1550 ?>
1827 1551 <div id="openai-vectorstore" class="mxch-section">
1828 1552 <div class="mxch-content-header">
@@ -1833,9 +1557,9 @@
1833 1557 <div class="mxch-card">
1834 1558 <div class="mxch-card-body">
1835 1559 <div class="mxch-notice mxch-notice-info" style="margin-bottom: 20px;">
1836 1560 <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>
1837 - <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.6-sol, gpt-5.6-terra, etc.). Create Vector Stores in your OpenAI Dashboard.', 'mxchat'); ?></span>
1561 + <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>
1838 1562 </div>
1839 1563
1840 1564 <?php if (!$is_openai_model && $use_vectorstore === '1'): ?>
1841 1565 <div class="mxch-notice mxch-notice-warning" style="margin-bottom: 20px;">
@@ -1977,274 +1701,93 @@
1977 1701 <?php
1978 1702 }
1979 1703
1980 1704 /**
1981 - * Render Edit Entry Modal
1705 + * Render Knowledge Page Navigation Scripts
1982 1706 */
1983 -function mxchat_render_edit_entry_modal() {
1707 +function mxchat_render_knowledge_page_scripts() {
1984 1708 ?>
1985 - <div id="mxchat-kb-edit-modal" class="mxchat-kb-modal">
1986 - <div class="mxchat-kb-modal-content mxchat-kb-edit-modal-content">
1987 - <div class="mxchat-kb-modal-header">
1988 - <h3 id="mxchat-kb-edit-title"><?php esc_html_e('Edit Knowledge Entry', 'mxchat'); ?></h3>
1989 - <span class="mxchat-kb-modal-close" id="mxchat-kb-edit-close">&times;</span>
1990 - </div>
1991 - <div class="mxchat-kb-edit-body">
1992 - <div class="mxchat-kb-edit-source" id="mxchat-kb-edit-source"></div>
1993 - <textarea id="mxchat-kb-edit-textarea" class="mxchat-kb-edit-textarea" placeholder="<?php esc_attr_e('Loading content...', 'mxchat'); ?>"></textarea>
1994 - <div class="mxchat-kb-edit-meta">
1995 - <span id="mxchat-kb-edit-charcount"></span>
1996 - <span id="mxchat-kb-edit-chunkinfo"></span>
1997 - </div>
1998 - </div>
1999 - <div class="mxchat-kb-edit-footer">
2000 - <div class="mxchat-kb-edit-notice" id="mxchat-kb-edit-notice"></div>
2001 - <div class="mxchat-kb-edit-actions">
2002 - <button type="button" id="mxchat-kb-edit-cancel" class="mxch-btn mxch-btn-ghost">
2003 - <?php esc_html_e('Cancel', 'mxchat'); ?>
2004 - </button>
2005 - <button type="button" id="mxchat-kb-edit-save" class="mxch-btn mxch-btn-primary">
2006 - <span class="mxchat-kb-edit-save-text"><?php esc_html_e('Save & Re-embed', 'mxchat'); ?></span>
2007 - <span class="mxchat-kb-edit-save-spinner" style="display:none;">
2008 - <span class="mxchat-kb-spinner is-active" style="margin: 0;"></span>
2009 - <?php esc_html_e('Saving...', 'mxchat'); ?>
2010 - </span>
2011 - </button>
2012 - </div>
2013 - </div>
2014 - </div>
2015 - </div>
2016 - <?php
2017 -}
2018 -
2019 -/**
2020 - * Render the read-only Knowledge Inspector modal (plan-mxchat-20260628-d8cb4b).
2021 - * Shows exactly what was indexed for an entry: the per-chunk stored text + lengths
2022 - * and (for Pinecone) the stored metadata fields, rendered with the Testing tab's
2023 - * own card components so the two surfaces feel like one system. Self-contained
2024 - * markup + JS so it doesn't entangle the edit-modal init.
2025 - */
2026 -function mxchat_render_inspect_entry_modal() {
2027 - ?>
2028 - <div id="mxchat-kb-inspect-modal" class="mxchat-kb-modal">
2029 - <div class="mxchat-kb-modal-content mxchat-kb-inspect-modal-content">
2030 - <div class="mxchat-kb-modal-header">
2031 - <h3 id="mxchat-kb-inspect-title"><?php esc_html_e('Indexed Content', 'mxchat'); ?></h3>
2032 - <span class="mxchat-kb-modal-close" id="mxchat-kb-inspect-close">&times;</span>
2033 - </div>
2034 - <div class="mxchat-kb-inspect-body">
2035 - <div class="mxchat-kb-edit-source" id="mxchat-kb-inspect-source"></div>
2036 - <div class="mxch-testing-results" id="mxchat-kb-inspect-results">
2037 - <div class="mxch-testing-no-data"><?php esc_html_e('Loading indexed content…', 'mxchat'); ?></div>
2038 - </div>
2039 - </div>
2040 - <div class="mxchat-kb-edit-footer">
2041 - <div class="mxchat-kb-edit-notice" id="mxchat-kb-inspect-notice"></div>
2042 - <div class="mxchat-kb-edit-actions">
2043 - <button type="button" id="mxchat-kb-inspect-close-btn" class="mxch-btn mxch-btn-primary">
2044 - <?php esc_html_e('Close', 'mxchat'); ?>
2045 - </button>
2046 - </div>
2047 - </div>
2048 - </div>
2049 - </div>
2050 1709 <script>
2051 1710 (function() {
2052 1711 'use strict';
1712 +
1713 + // Wait for DOM
2053 1714 document.addEventListener('DOMContentLoaded', function() {
2054 - var modal = document.getElementById('mxchat-kb-inspect-modal');
2055 - if (!modal) return;
2056 - var closeX = document.getElementById('mxchat-kb-inspect-close');
2057 - var closeBtn = document.getElementById('mxchat-kb-inspect-close-btn');
2058 - var sourceEl = document.getElementById('mxchat-kb-inspect-source');
2059 - var resultsEl= document.getElementById('mxchat-kb-inspect-results');
2060 - var titleEl = document.getElementById('mxchat-kb-inspect-title');
2061 - var noticeEl = document.getElementById('mxchat-kb-inspect-notice');
1715 + initKnowledgeNavigation();
1716 + initMobileMenu();
1717 + initImportOptions();
1718 + initCustomPostTypesToggle();
1719 + // Sitemap detection is now initialized when user clicks the Sitemap Import option
1720 + });
2062 1721
2063 - var I18N = {
2064 - title: <?php echo wp_json_encode( esc_html__('Indexed Content', 'mxchat') ); ?>,
2065 - loading: <?php echo wp_json_encode( esc_html__('Loading indexed content…', 'mxchat') ); ?>,
2066 - manual: <?php echo wp_json_encode( esc_html__('Manual Content', 'mxchat') ); ?>,
2067 - source: <?php echo wp_json_encode( esc_html__('Source', 'mxchat') ); ?>,
2068 - store: <?php echo wp_json_encode( esc_html__('Storage', 'mxchat') ); ?>,
2069 - type: <?php echo wp_json_encode( esc_html__('Content type', 'mxchat') ); ?>,
2070 - chunksLbl:<?php echo wp_json_encode( esc_html__('Chunks', 'mxchat') ); ?>,
2071 - totalLen: <?php echo wp_json_encode( esc_html__('Total indexed length', 'mxchat') ); ?>,
2072 - chunk: <?php echo wp_json_encode( esc_html__('Chunk', 'mxchat') ); ?>,
2073 - indexed: <?php echo wp_json_encode( esc_html__('Indexed', 'mxchat') ); ?>,
2074 - chars: <?php echo wp_json_encode( esc_html__('chars', 'mxchat') ); ?>,
2075 - showText: <?php echo wp_json_encode( esc_html__('Show indexed text', 'mxchat') ); ?>,
2076 - hideText: <?php echo wp_json_encode( esc_html__('Hide indexed text', 'mxchat') ); ?>,
2077 - wpStore: <?php echo wp_json_encode( esc_html__('Local WordPress database', 'mxchat') ); ?>,
2078 - pcStore: <?php echo wp_json_encode( esc_html__('Pinecone', 'mxchat') ); ?>,
2079 - meta: <?php echo wp_json_encode( esc_html__('Vector metadata', 'mxchat') ); ?>,
2080 - loadFail: <?php echo wp_json_encode( esc_html__('Failed to load indexed content.', 'mxchat') ); ?>,
2081 - netErr: <?php echo wp_json_encode( esc_html__('Network error: ', 'mxchat') ); ?>
2082 - };
1722 + function initKnowledgeNavigation() {
1723 + const navLinks = document.querySelectorAll('.mxch-nav-link[data-target], .mxch-mobile-nav-link[data-target]');
1724 + const sections = document.querySelectorAll('.mxch-section');
2083 1725
2084 - function esc(str) {
2085 - var d = document.createElement('div');
2086 - d.textContent = (str === null || str === undefined) ? '' : String(str);
2087 - return d.innerHTML;
1726 + function showSection(targetId) {
1727 + // Hide all sections
1728 + sections.forEach(section => section.classList.remove('active'));
1729 + // Show target section
1730 + const target = document.getElementById(targetId);
1731 + if (target) {
1732 + target.classList.add('active');
1733 + }
1734 + // Update nav links
1735 + navLinks.forEach(link => {
1736 + link.classList.toggle('active', link.dataset.target === targetId);
1737 + });
1738 + // Update URL hash
1739 + history.replaceState(null, null, '#' + targetId);
2088 1740 }
2089 - function fmt(n) { try { return Number(n).toLocaleString(); } catch (e) { return n; } }
2090 1741
2091 - document.addEventListener('click', function(e) {
2092 - var btn = e.target.closest('.mxchat-inspect-entry-btn');
2093 - if (btn) { e.preventDefault(); open(btn); }
1742 + navLinks.forEach(link => {
1743 + link.addEventListener('click', function(e) {
1744 + e.preventDefault();
1745 + const targetId = this.dataset.target;
1746 + showSection(targetId);
1747 + // Close mobile menu if open
1748 + const mobileMenu = document.querySelector('.mxch-mobile-menu');
1749 + const overlay = document.querySelector('.mxch-mobile-overlay');
1750 + if (mobileMenu) mobileMenu.classList.remove('open');
1751 + if (overlay) overlay.classList.remove('open');
1752 + });
2094 1753 });
2095 - if (closeX) closeX.addEventListener('click', close);
2096 - if (closeBtn) closeBtn.addEventListener('click', close);
2097 - // Overlay click closes, but only when the whole gesture happened on the
2098 - // overlay — otherwise selecting indexed text and releasing past the
2099 - // dialog edge dispatches the click on the overlay and closes it.
2100 - var downOnOverlay = false;
2101 - modal.addEventListener('mousedown', function(e) { downOnOverlay = (e.target === modal); });
2102 - modal.addEventListener('click', function(e) {
2103 - var overlayGesture = downOnOverlay;
2104 - downOnOverlay = false;
2105 - if (e.target === modal && overlayGesture) close();
2106 - });
2107 - document.addEventListener('keydown', function(e) {
2108 - if (e.key === 'Escape' && modal.classList.contains('active')) close();
2109 - });
2110 1754
2111 - function close() { modal.classList.remove('active'); }
2112 -
2113 - function open(btn) {
2114 - var entry = {
2115 - sourceUrl: btn.getAttribute('data-source-url') || '',
2116 - entryId: btn.getAttribute('data-entry-id') || '',
2117 - dataSource: btn.getAttribute('data-data-source') || 'wordpress',
2118 - botId: btn.getAttribute('data-bot-id') || 'default',
2119 - nonce: btn.getAttribute('data-nonce') || ''
2120 - };
2121 -
2122 - titleEl.textContent = I18N.title;
2123 - noticeEl.textContent = '';
2124 - noticeEl.className = 'mxchat-kb-edit-notice';
2125 - resultsEl.innerHTML = '<div class="mxch-testing-no-data">' + esc(I18N.loading) + '</div>';
2126 -
2127 - if (entry.sourceUrl && entry.sourceUrl.indexOf('mxchat://') !== 0 && entry.sourceUrl.indexOf('_ungrouped_') !== 0) {
2128 - sourceEl.innerHTML = esc(I18N.source) + ': <a href="' + esc(entry.sourceUrl) + '" target="_blank" rel="noopener">' + esc(entry.sourceUrl) + '</a>';
2129 - } else {
2130 - sourceEl.textContent = I18N.manual;
2131 - }
2132 -
2133 - modal.classList.add('active');
2134 -
2135 - var fd = new FormData();
2136 - fd.append('action', 'mxchat_inspect_entry');
2137 - fd.append('nonce', entry.nonce);
2138 - fd.append('source_url', entry.sourceUrl);
2139 - fd.append('entry_id', entry.entryId);
2140 - fd.append('data_source', entry.dataSource);
2141 - fd.append('bot_id', entry.botId);
2142 -
2143 - fetch(ajaxurl, { method: 'POST', body: fd })
2144 - .then(function(r) { return r.json(); })
2145 - .then(function(resp) {
2146 - if (resp && resp.success) {
2147 - render(resp.data);
2148 - } else {
2149 - var msg = (resp && resp.data && resp.data.message) || I18N.loadFail;
2150 - resultsEl.innerHTML = '';
2151 - showNotice(msg, 'error');
2152 - }
2153 - })
2154 - .catch(function(err) {
2155 - resultsEl.innerHTML = '';
2156 - showNotice(I18N.netErr + err.message, 'error');
2157 - });
1755 + // Handle initial hash
1756 + const hash = window.location.hash.substring(1);
1757 + if (hash && document.getElementById(hash)) {
1758 + showSection(hash);
2158 1759 }
1760 + }
2159 1761
2160 - function render(data) {
2161 - var storeLabel = data.store === 'pinecone' ? I18N.pcStore : I18N.wpStore;
2162 - var html = '';
1762 + function initMobileMenu() {
1763 + const menuBtn = document.querySelector('.mxch-mobile-menu-btn');
1764 + const closeBtn = document.querySelector('.mxch-mobile-menu-close');
1765 + const overlay = document.querySelector('.mxch-mobile-overlay');
1766 + const menu = document.querySelector('.mxch-mobile-menu');
2163 1767
2164 - // Summary card — what this entry is + how much was indexed.
2165 - html += '<div class="match-card above-threshold">' +
2166 - '<div class="match-header">' +
2167 - '<div class="match-title"><span class="status-icon">&#128230;</span> ' + esc(data.chunk_count) + ' ' + esc(I18N.chunksLbl.toLowerCase()) + '</div>' +
2168 - '<span class="context-label">' + esc(storeLabel) + '</span>' +
2169 - '</div>' +
2170 - '<div class="mxch-testing-field"><label>' + esc(I18N.type) + '</label><code>' + esc(data.content_type || '—') + '</code> ' +
2171 - '&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>';
2172 - if (data.metadata_note) {
2173 - html += '<div class="match-source"><span class="source-icon">&#8505;&#65039;</span> ' + esc(data.metadata_note) + '</div>';
2174 - }
2175 - html += '</div>';
2176 -
2177 - // One card per stored chunk — the actual embedded text.
2178 - var chunks = data.chunks || [];
2179 - chunks.forEach(function(chunk, i) {
2180 - var num = (chunk.index !== null && chunk.index !== undefined) ? (chunk.index + 1) : (i + 1);
2181 - var metaRows = '';
2182 - if (chunk.metadata && typeof chunk.metadata === 'object') {
2183 - var keys = Object.keys(chunk.metadata);
2184 - if (keys.length) {
2185 - metaRows += '<div class="chunk-detail-row chunk-used" style="display:block;"><span class="chunk-detail-num">' + esc(I18N.meta) + '</span></div>';
2186 - keys.forEach(function(k) {
2187 - 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>';
2188 - });
2189 - }
2190 - }
2191 - html += '<div class="match-card above-threshold">' +
2192 - '<div class="match-header">' +
2193 - '<div class="match-title"><span class="status-icon">&#10003;</span> ' + esc(I18N.chunk) + ' ' + esc(num) +
2194 - '<span class="chunk-summary">' + esc(fmt(chunk.length)) + ' ' + esc(I18N.chars) + '</span>' +
2195 - '</div>' +
2196 - '<span class="context-label">' + esc(I18N.indexed) + '</span>' +
2197 - '</div>' +
2198 - '<span class="chunk-expand-toggle" data-chunk="' + i + '">&#9654; ' + esc(I18N.showText) + '</span>' +
2199 - '<div class="chunk-details" data-chunk="' + i + '">' +
2200 - '<pre class="mxch-kb-inspect-chunk-text">' + esc(chunk.text) + '</pre>' +
2201 - metaRows +
2202 - '</div>' +
2203 - '</div>';
1768 + if (menuBtn && menu) {
1769 + menuBtn.addEventListener('click', function() {
1770 + menu.classList.add('open');
1771 + if (overlay) overlay.classList.add('open');
2204 1772 });
1773 + }
2205 1774
2206 - resultsEl.innerHTML = html;
2207 -
2208 - resultsEl.querySelectorAll('.chunk-expand-toggle').forEach(function(toggle) {
2209 - toggle.addEventListener('click', function() {
2210 - var id = this.getAttribute('data-chunk');
2211 - var details = resultsEl.querySelector('.chunk-details[data-chunk="' + id + '"]');
2212 - if (!details) return;
2213 - var expanded = details.classList.toggle('expanded');
2214 - this.innerHTML = (expanded ? '&#9660; ' + esc(I18N.hideText) : '&#9654; ' + esc(I18N.showText));
2215 - });
1775 + if (closeBtn && menu) {
1776 + closeBtn.addEventListener('click', function() {
1777 + menu.classList.remove('open');
1778 + if (overlay) overlay.classList.remove('open');
2216 1779 });
2217 1780 }
2218 1781
2219 - function showNotice(msg, type) {
2220 - noticeEl.textContent = msg;
2221 - noticeEl.className = 'mxchat-kb-edit-notice' + (type ? ' ' + type : '');
1782 + if (overlay && menu) {
1783 + overlay.addEventListener('click', function() {
1784 + menu.classList.remove('open');
1785 + overlay.classList.remove('open');
1786 + });
2222 1787 }
2223 - });
2224 - })();
2225 - </script>
2226 - <?php
2227 -}
1788 + }
2228 1789
2229 -/**
2230 - * Render Knowledge Page Navigation Scripts
2231 - */
2232 -function mxchat_render_knowledge_page_scripts() {
2233 - ?>
2234 - <script>
2235 - (function() {
2236 - 'use strict';
2237 -
2238 - // Wait for DOM
2239 - document.addEventListener('DOMContentLoaded', function() {
2240 - // Tab navigation + mobile menu live in the shared shell script
2241 - // (js/admin-sidebar.js), enqueued for this page by plan c192a4.
2242 - initImportOptions();
2243 - initCustomPostTypesToggle();
2244 - // Sitemap detection is now initialized when user clicks the Sitemap Import option
2245 - });
2246 -
2247 1790 function initImportOptions() {
2248 1791 const importBoxes = document.querySelectorAll('.mxchat-import-box');
2249 1792 const urlInputArea = document.getElementById('mxchat-url-input-area');
2250 1793 const contentInputArea = document.getElementById('mxchat-content-input-area');
@@ -2334,216 +1877,8 @@
2334 1877 }
2335 1878
2336 1879 // Sitemap detection is now handled by knowledge-processing.js
2337 1880 // It will be initialized when user clicks "Sitemap Import" option
2338 -
2339 - // ─── Edit Entry Modal ────────────────────────────────────
2340 - initEditModal();
2341 -
2342 - function initEditModal() {
2343 - var modal = document.getElementById('mxchat-kb-edit-modal');
2344 - var textarea = document.getElementById('mxchat-kb-edit-textarea');
2345 - var saveBtn = document.getElementById('mxchat-kb-edit-save');
2346 - var cancelBtn = document.getElementById('mxchat-kb-edit-cancel');
2347 - var closeBtn = document.getElementById('mxchat-kb-edit-close');
2348 - var notice = document.getElementById('mxchat-kb-edit-notice');
2349 - var charCount = document.getElementById('mxchat-kb-edit-charcount');
2350 - var chunkInfo = document.getElementById('mxchat-kb-edit-chunkinfo');
2351 - var sourceEl = document.getElementById('mxchat-kb-edit-source');
2352 - var titleEl = document.getElementById('mxchat-kb-edit-title');
2353 - var saveText = saveBtn ? saveBtn.querySelector('.mxchat-kb-edit-save-text') : null;
2354 - var saveSpin = saveBtn ? saveBtn.querySelector('.mxchat-kb-edit-save-spinner') : null;
2355 -
2356 - if (!modal) return;
2357 -
2358 - var currentEntry = {};
2359 - var loadedContent = '';
2360 -
2361 - var EDIT_I18N = {
2362 - discard: <?php echo wp_json_encode( __('Discard your unsaved changes to this entry?', 'mxchat') ); ?>
2363 - };
2364 -
2365 - // Bind edit buttons (delegated)
2366 - document.addEventListener('click', function(e) {
2367 - var btn = e.target.closest('.mxchat-edit-entry-btn');
2368 - if (btn) {
2369 - e.preventDefault();
2370 - openEditModal(btn);
2371 - }
2372 - });
2373 -
2374 - // Close handlers. The overlay deliberately has no click-to-close: a click
2375 - // fires on the common ancestor of its mousedown and mouseup, so releasing
2376 - // a text-selection drag past the dialog edge targets the overlay and would
2377 - // discard the edit. Closing is explicit only, and confirms when dirty.
2378 - if (closeBtn) closeBtn.addEventListener('click', requestClose);
2379 - if (cancelBtn) cancelBtn.addEventListener('click', requestClose);
2380 - document.addEventListener('keydown', function(e) {
2381 - if (e.key === 'Escape' && modal.classList.contains('active')) requestClose();
2382 - });
2383 -
2384 - // Character count
2385 - if (textarea) {
2386 - textarea.addEventListener('input', function() {
2387 - updateCharCount();
2388 - });
2389 - }
2390 -
2391 - // Save handler
2392 - if (saveBtn) saveBtn.addEventListener('click', saveContent);
2393 -
2394 - function openEditModal(btn) {
2395 - currentEntry = {
2396 - sourceUrl: btn.getAttribute('data-source-url') || '',
2397 - entryId: btn.getAttribute('data-entry-id') || '',
2398 - dataSource: btn.getAttribute('data-data-source') || 'wordpress',
2399 - botId: btn.getAttribute('data-bot-id') || 'default',
2400 - nonce: btn.getAttribute('data-nonce') || ''
2401 - };
2402 -
2403 - // Reset state
2404 - textarea.value = '';
2405 - loadedContent = '';
2406 - textarea.placeholder = 'Loading content...';
2407 - textarea.disabled = true;
2408 - saveBtn.disabled = true;
2409 - notice.textContent = '';
2410 - notice.className = 'mxchat-kb-edit-notice';
2411 - charCount.textContent = '';
2412 - chunkInfo.textContent = '';
2413 -
2414 - // Show source
2415 - if (currentEntry.sourceUrl && currentEntry.sourceUrl.indexOf('mxchat://') !== 0) {
2416 - sourceEl.innerHTML = 'Source: <a href="' + escapeHtml(currentEntry.sourceUrl) + '" target="_blank">' + escapeHtml(truncate(currentEntry.sourceUrl, 60)) + '</a>';
2417 - } else {
2418 - sourceEl.textContent = 'Manual Content';
2419 - }
2420 -
2421 - // Show modal
2422 - modal.classList.add('active');
2423 -
2424 - // Fetch content
2425 - var formData = new FormData();
2426 - formData.append('action', 'mxchat_get_entry_content');
2427 - formData.append('nonce', currentEntry.nonce);
2428 - formData.append('source_url', currentEntry.sourceUrl);
2429 - formData.append('entry_id', currentEntry.entryId);
2430 - formData.append('data_source', currentEntry.dataSource);
2431 - formData.append('bot_id', currentEntry.botId);
2432 -
2433 - fetch(ajaxurl, { method: 'POST', body: formData })
2434 - .then(function(r) { return r.json(); })
2435 - .then(function(resp) {
2436 - if (resp.success) {
2437 - textarea.value = resp.data.content || '';
2438 - loadedContent = textarea.value;
2439 - textarea.disabled = false;
2440 - textarea.placeholder = 'Edit your content here...';
2441 - saveBtn.disabled = false;
2442 - currentEntry.contentType = resp.data.content_type || 'content';
2443 -
2444 - updateCharCount();
2445 -
2446 - if (resp.data.is_chunked) {
2447 - chunkInfo.textContent = resp.data.chunk_count + ' chunks — will be re-chunked on save';
2448 - titleEl.textContent = 'Edit Knowledge Entry (' + resp.data.chunk_count + ' chunks)';
2449 - } else {
2450 - chunkInfo.textContent = '';
2451 - titleEl.textContent = 'Edit Knowledge Entry';
2452 - }
2453 -
2454 - textarea.focus();
2455 - } else {
2456 - textarea.placeholder = '';
2457 - showNotice((resp.data && resp.data.message) || 'Failed to load content.', 'error');
2458 - }
2459 - })
2460 - .catch(function(err) {
2461 - textarea.placeholder = '';
2462 - showNotice('Network error: ' + err.message, 'error');
2463 - });
2464 - }
2465 -
2466 - function saveContent() {
2467 - if (!textarea.value.trim()) {
2468 - showNotice('Content cannot be empty.', 'error');
2469 - return;
2470 - }
2471 -
2472 - saveBtn.disabled = true;
2473 - if (saveText) saveText.style.display = 'none';
2474 - if (saveSpin) saveSpin.style.display = '';
2475 - showNotice('Saving and re-embedding...', '');
2476 -
2477 - var formData = new FormData();
2478 - formData.append('action', 'mxchat_save_entry_content');
2479 - formData.append('nonce', currentEntry.nonce);
2480 - formData.append('source_url', currentEntry.sourceUrl);
2481 - formData.append('entry_id', currentEntry.entryId);
2482 - formData.append('content', textarea.value);
2483 - formData.append('data_source', currentEntry.dataSource);
2484 - formData.append('bot_id', currentEntry.botId);
2485 - formData.append('content_type', currentEntry.contentType || 'content');
2486 -
2487 - fetch(ajaxurl, { method: 'POST', body: formData })
2488 - .then(function(r) { return r.json(); })
2489 - .then(function(resp) {
2490 - if (saveText) saveText.style.display = '';
2491 - if (saveSpin) saveSpin.style.display = 'none';
2492 - saveBtn.disabled = false;
2493 -
2494 - if (resp.success) {
2495 - showNotice('Saved successfully!', 'success');
2496 - setTimeout(function() {
2497 - closeModal();
2498 - window.location.reload();
2499 - }, 1000);
2500 - } else {
2501 - showNotice((resp.data && resp.data.message) || 'Save failed.', 'error');
2502 - }
2503 - })
2504 - .catch(function(err) {
2505 - if (saveText) saveText.style.display = '';
2506 - if (saveSpin) saveSpin.style.display = 'none';
2507 - saveBtn.disabled = false;
2508 - showNotice('Network error: ' + err.message, 'error');
2509 - });
2510 - }
2511 -
2512 - function isDirty() {
2513 - return !textarea.disabled && textarea.value !== loadedContent;
2514 - }
2515 -
2516 - function requestClose() {
2517 - if (isDirty() && !window.confirm(EDIT_I18N.discard)) return;
2518 - closeModal();
2519 - }
2520 -
2521 - function closeModal() {
2522 - modal.classList.remove('active');
2523 - }
2524 -
2525 - function updateCharCount() {
2526 - var len = textarea.value.length;
2527 - charCount.textContent = len.toLocaleString() + ' characters';
2528 - }
2529 -
2530 - function showNotice(msg, type) {
2531 - notice.textContent = msg;
2532 - notice.className = 'mxchat-kb-edit-notice' + (type ? ' ' + type : '');
2533 - }
2534 -
2535 - function escapeHtml(str) {
2536 - var div = document.createElement('div');
2537 - div.textContent = str;
2538 - return div.innerHTML;
2539 - }
2540 -
2541 - function truncate(str, max) {
2542 - return str.length > max ? str.substring(0, max) + '...' : str;
2543 - }
2544 - }
2545 -
2546 1881 })();
2547 1882 </script>
2548 1883 <?php
2549 1884 }