PluginProbe
MxChat – AI Chatbot & Content Generation for WordPress / 3.1.1
MxChat – AI Chatbot & Content Generation for WordPress v3.1.1
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 +8 -635 3.2.143.1.1 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
@@ -555,19 +549,8 @@
555 549 <h4><?php esc_html_e('PDF Upload', 'mxchat'); ?></h4>
556 550 <p><?php esc_html_e('Upload a PDF file from your computer.', 'mxchat'); ?></p>
557 551 </div>
558 552 </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 553 </div>
571 554
572 555 <!-- Detected Sitemaps Section (hidden by default, shown when Sitemap Import is clicked) -->
573 556 <div id="mxchat-detected-sitemaps" class="mxchat-detected-sitemaps" style="display: none;">
@@ -669,54 +652,8 @@
669 652 <?php esc_html_e('Import PDF', 'mxchat'); ?>
670 653 </button>
671 654 </form>
672 655 </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 656 <?php endif; ?>
720 657 </div>
721 658 </div>
722 659 </div>
@@ -908,39 +845,15 @@
908 845 </form>
909 846 <!-- Delete Button Container - transforms between Delete All and Delete Selected -->
910 847 <div class="mxchat-delete-container" id="mxchat-delete-container">
911 848 <!-- 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); ?>');">
849 + <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 850 <?php wp_nonce_field('mxchat_delete_all_prompts_action', 'mxchat_delete_all_prompts_nonce'); ?>
935 851 <input type="hidden" name="data_source" value="<?php echo esc_attr($data_source); ?>" />
936 852 <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 853 <button type="submit" class="mxch-btn mxch-btn-secondary mxch-btn-sm" style="color: var(--mxch-error);">
941 854 <span class="dashicons dashicons-trash" style="font-size: 14px;"></span>
942 - <?php echo esc_html($delete_all_label); ?>
855 + <?php esc_html_e('Delete All', 'mxchat'); ?>
943 856 </button>
944 857 </form>
945 858 <!-- Delete Selected Button (shown when items selected) -->
946 859 <button type="button"
@@ -1048,32 +961,10 @@
1048 961 <?php else : ?>
1049 962 <span style="color: var(--mxch-text-muted);"><?php esc_html_e('Manual Content', 'mxchat'); ?></span>
1050 963 <?php endif; ?>
1051 964 </td>
1052 - <td class="mxchat-actions-cell" style="padding: 12px 16px; white-space: nowrap;">
965 + <td class="mxchat-actions-cell" style="padding: 12px 16px;">
1053 966 <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 967 class="mxch-btn mxch-btn-ghost mxch-btn-sm delete-button-group"
1077 968 data-source-url="<?php echo esc_attr($source_url); ?>"
1078 969 data-chunk-count="<?php echo esc_attr($chunk_count); ?>"
1079 970 data-data-source="<?php echo esc_attr($data_source); ?>"
@@ -1208,31 +1099,9 @@
1208 1099 <?php else : ?>
1209 1100 <span style="color: var(--mxch-text-muted);"><?php esc_html_e('Manual', 'mxchat'); ?></span>
1210 1101 <?php endif; ?>
1211 1102 </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; ?>
1103 + <td style="padding: 12px 16px;">
1235 1104 <?php if ($data_source === 'pinecone') : ?>
1236 1105 <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 1106 <span class="dashicons dashicons-trash" style="font-size: 14px;"></span>
1238 1107 </button>
@@ -1326,19 +1195,8 @@
1326 1195 <span style="font-weight: 500;"><?php esc_html_e('Auto-sync Pages', 'mxchat'); ?></span>
1327 1196 </div>
1328 1197 </div>
1329 1198
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 1199 <div style="margin-top: 24px;">
1342 1200 <button id="mxchat-custom-post-types-toggle" class="mxch-btn mxch-btn-secondary">
1343 1201 <?php esc_html_e('Advanced Custom Post Sync Settings', 'mxchat'); ?>
1344 1202 <span style="margin-left: 5px;">▼</span>
@@ -1446,11 +1304,10 @@
1446 1304
1447 1305 <h4 style="margin: 0 0 16px 0;"><?php esc_html_e('Add Tag-Role Mapping', 'mxchat'); ?></h4>
1448 1306 <div style="display: flex; gap: 15px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 24px;">
1449 1307 <div class="mxch-field" style="flex: 1; min-width: 200px; margin-bottom: 0;">
1450 - <label class="mxch-field-label" for="mxchat-tag-input"><?php esc_html_e('Tag (name or slug)', 'mxchat'); ?></label>
1451 - <input type="text" id="mxchat-tag-input" class="mxch-input" placeholder="<?php esc_attr_e('e.g., Premium Content or premium-content', 'mxchat'); ?>">
1452 - <span class="mxch-field-hint"><?php esc_html_e('Enter an existing post tag by its display name or its slug.', 'mxchat'); ?></span>
1308 + <label class="mxch-field-label" for="mxchat-tag-input"><?php esc_html_e('Tag Name', 'mxchat'); ?></label>
1309 + <input type="text" id="mxchat-tag-input" class="mxch-input" placeholder="<?php esc_attr_e('e.g., premium, members-only', 'mxchat'); ?>">
1453 1310 </div>
1454 1311 <div class="mxch-field" style="flex: 1; min-width: 200px; margin-bottom: 0;">
1455 1312 <label class="mxch-field-label" for="mxchat-role-select"><?php esc_html_e('Required Role', 'mxchat'); ?></label>
1456 1313 <select id="mxchat-role-select" class="mxch-select">
@@ -1589,28 +1446,8 @@
1589 1446 <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>
1590 1447 <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>
1591 1448 </div>
1592 1449
1593 - <!-- Meta-key discovery scanner (plan-mxchat-20260709-fe8e4e): mirror the ACF picker's
1594 - discover-for-you UX for non-ACF meta, so owners click keys instead of typing them blind. -->
1595 - <div class="mxch-field mxchat-meta-scan">
1596 - <label class="mxch-field-label"><?php esc_html_e('Discover meta keys', 'mxchat'); ?></label>
1597 - <p class="mxch-field-description" style="margin-top: 0;">
1598 - <?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'); ?>
1599 - </p>
1600 - <div class="mxchat-meta-scan-controls">
1601 - <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')); ?>">
1602 - <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>
1603 - <span class="mxchat-scan-label"><?php esc_html_e('Scan my content for meta keys', 'mxchat'); ?></span>
1604 - </button>
1605 - <label class="mxchat-meta-scan-internal">
1606 - <input type="checkbox" id="mxchat-scan-internal">
1607 - <?php esc_html_e('Include internal keys (underscore-prefixed)', 'mxchat'); ?>
1608 - </label>
1609 - </div>
1610 - <div id="mxchat-meta-scan-results" class="mxchat-meta-scan-results" aria-live="polite"></div>
1611 - </div>
1612 -
1613 1450 <div class="mxch-field">
1614 1451 <label class="mxch-field-label" for="mxchat_custom_meta_whitelist">
1615 1452 <?php esc_html_e('Meta Key Whitelist', 'mxchat'); ?>
1616 1453 </label>
@@ -1623,9 +1460,9 @@
1623 1460 data-nonce="<?php echo wp_create_nonce('mxchat_prompts_setting_nonce'); ?>"
1624 1461 style="font-family: monospace;"
1625 1462 ><?php echo esc_textarea($whitelist); ?></textarea>
1626 1463 <p class="mxch-field-description">
1627 - <?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'); ?>
1464 + <?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'); ?>
1628 1465 </p>
1629 1466 </div>
1630 1467
1631 1468 <div style="margin-top: 20px; padding: 16px; background: #f8fafc; border-radius: var(--mxch-radius-md);">
@@ -1632,9 +1469,9 @@
1632 1469 <h4 style="margin: 0 0 12px 0; font-size: 14px;"><?php esc_html_e('How to find meta keys:', 'mxchat'); ?></h4>
1633 1470 <ul style="margin: 0; padding-left: 20px; color: var(--mxch-text-secondary); font-size: 13px;">
1634 1471 <li><?php esc_html_e('Check your theme documentation for meta key names', 'mxchat'); ?></li>
1635 1472 <li><?php esc_html_e('Look in the wp_postmeta database table', 'mxchat'); ?></li>
1636 - <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>
1473 + <li><?php esc_html_e('Use a plugin like "Show Post Meta" to view meta keys on any post', 'mxchat'); ?></li>
1637 1474 <li><?php esc_html_e('Meta keys starting with underscore (_) are usually hidden/internal', 'mxchat'); ?></li>
1638 1475 </ul>
1639 1476 </div>
1640 1477 </div>
@@ -1877,15 +1714,8 @@
1877 1714 </div>
1878 1715 </div>
1879 1716 <div class="mxchat-kb-modal-footer">
1880 1717 <div class="mxchat-kb-pagination"></div>
1881 - <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);">
1882 - <input type="checkbox" id="mxchat-kb-acf-pdf-extract" style="margin-top:2px;">
1883 - <label for="mxchat-kb-acf-pdf-extract" style="cursor:pointer; line-height:1.4;">
1884 - <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>
1885 - <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>
1886 - </label>
1887 - </div>
1888 1718 <div class="mxchat-kb-footer-actions">
1889 1719 <button type="button" id="mxchat-kb-process-selected" class="mxchat-kb-button-primary" disabled>
1890 1720 <?php esc_html_e('Process Selected Content', 'mxchat'); ?>
1891 1721 <span class="mxchat-kb-selected-count">(0)</span>
@@ -1900,257 +1730,8 @@
1900 1730 <?php
1901 1731 }
1902 1732
1903 1733 /**
1904 - * Render Edit Entry Modal
1905 - */
1906 -function mxchat_render_edit_entry_modal() {
1907 - ?>
1908 - <div id="mxchat-kb-edit-modal" class="mxchat-kb-modal">
1909 - <div class="mxchat-kb-modal-content mxchat-kb-edit-modal-content">
1910 - <div class="mxchat-kb-modal-header">
1911 - <h3 id="mxchat-kb-edit-title"><?php esc_html_e('Edit Knowledge Entry', 'mxchat'); ?></h3>
1912 - <span class="mxchat-kb-modal-close" id="mxchat-kb-edit-close">&times;</span>
1913 - </div>
1914 - <div class="mxchat-kb-edit-body">
1915 - <div class="mxchat-kb-edit-source" id="mxchat-kb-edit-source"></div>
1916 - <textarea id="mxchat-kb-edit-textarea" class="mxchat-kb-edit-textarea" placeholder="<?php esc_attr_e('Loading content...', 'mxchat'); ?>"></textarea>
1917 - <div class="mxchat-kb-edit-meta">
1918 - <span id="mxchat-kb-edit-charcount"></span>
1919 - <span id="mxchat-kb-edit-chunkinfo"></span>
1920 - </div>
1921 - </div>
1922 - <div class="mxchat-kb-edit-footer">
1923 - <div class="mxchat-kb-edit-notice" id="mxchat-kb-edit-notice"></div>
1924 - <div class="mxchat-kb-edit-actions">
1925 - <button type="button" id="mxchat-kb-edit-cancel" class="mxch-btn mxch-btn-ghost">
1926 - <?php esc_html_e('Cancel', 'mxchat'); ?>
1927 - </button>
1928 - <button type="button" id="mxchat-kb-edit-save" class="mxch-btn mxch-btn-primary">
1929 - <span class="mxchat-kb-edit-save-text"><?php esc_html_e('Save & Re-embed', 'mxchat'); ?></span>
1930 - <span class="mxchat-kb-edit-save-spinner" style="display:none;">
1931 - <span class="mxchat-kb-spinner is-active" style="margin: 0;"></span>
1932 - <?php esc_html_e('Saving...', 'mxchat'); ?>
1933 - </span>
1934 - </button>
1935 - </div>
1936 - </div>
1937 - </div>
1938 - </div>
1939 - <?php
1940 -}
1941 -
1942 -/**
1943 - * Render the read-only Knowledge Inspector modal (plan-mxchat-20260628-d8cb4b).
1944 - * Shows exactly what was indexed for an entry: the per-chunk stored text + lengths
1945 - * and (for Pinecone) the stored metadata fields, rendered with the Testing tab's
1946 - * own card components so the two surfaces feel like one system. Self-contained
1947 - * markup + JS so it doesn't entangle the edit-modal init.
1948 - */
1949 -function mxchat_render_inspect_entry_modal() {
1950 - ?>
1951 - <div id="mxchat-kb-inspect-modal" class="mxchat-kb-modal">
1952 - <div class="mxchat-kb-modal-content mxchat-kb-inspect-modal-content">
1953 - <div class="mxchat-kb-modal-header">
1954 - <h3 id="mxchat-kb-inspect-title"><?php esc_html_e('Indexed Content', 'mxchat'); ?></h3>
1955 - <span class="mxchat-kb-modal-close" id="mxchat-kb-inspect-close">&times;</span>
1956 - </div>
1957 - <div class="mxchat-kb-inspect-body">
1958 - <div class="mxchat-kb-edit-source" id="mxchat-kb-inspect-source"></div>
1959 - <div class="mxch-testing-results" id="mxchat-kb-inspect-results">
1960 - <div class="mxch-testing-no-data"><?php esc_html_e('Loading indexed content…', 'mxchat'); ?></div>
1961 - </div>
1962 - </div>
1963 - <div class="mxchat-kb-edit-footer">
1964 - <div class="mxchat-kb-edit-notice" id="mxchat-kb-inspect-notice"></div>
1965 - <div class="mxchat-kb-edit-actions">
1966 - <button type="button" id="mxchat-kb-inspect-close-btn" class="mxch-btn mxch-btn-primary">
1967 - <?php esc_html_e('Close', 'mxchat'); ?>
1968 - </button>
1969 - </div>
1970 - </div>
1971 - </div>
1972 - </div>
1973 - <script>
1974 - (function() {
1975 - 'use strict';
1976 - document.addEventListener('DOMContentLoaded', function() {
1977 - var modal = document.getElementById('mxchat-kb-inspect-modal');
1978 - if (!modal) return;
1979 - var closeX = document.getElementById('mxchat-kb-inspect-close');
1980 - var closeBtn = document.getElementById('mxchat-kb-inspect-close-btn');
1981 - var sourceEl = document.getElementById('mxchat-kb-inspect-source');
1982 - var resultsEl= document.getElementById('mxchat-kb-inspect-results');
1983 - var titleEl = document.getElementById('mxchat-kb-inspect-title');
1984 - var noticeEl = document.getElementById('mxchat-kb-inspect-notice');
1985 -
1986 - var I18N = {
1987 - title: <?php echo wp_json_encode( esc_html__('Indexed Content', 'mxchat') ); ?>,
1988 - loading: <?php echo wp_json_encode( esc_html__('Loading indexed content…', 'mxchat') ); ?>,
1989 - manual: <?php echo wp_json_encode( esc_html__('Manual Content', 'mxchat') ); ?>,
1990 - source: <?php echo wp_json_encode( esc_html__('Source', 'mxchat') ); ?>,
1991 - store: <?php echo wp_json_encode( esc_html__('Storage', 'mxchat') ); ?>,
1992 - type: <?php echo wp_json_encode( esc_html__('Content type', 'mxchat') ); ?>,
1993 - chunksLbl:<?php echo wp_json_encode( esc_html__('Chunks', 'mxchat') ); ?>,
1994 - totalLen: <?php echo wp_json_encode( esc_html__('Total indexed length', 'mxchat') ); ?>,
1995 - chunk: <?php echo wp_json_encode( esc_html__('Chunk', 'mxchat') ); ?>,
1996 - indexed: <?php echo wp_json_encode( esc_html__('Indexed', 'mxchat') ); ?>,
1997 - chars: <?php echo wp_json_encode( esc_html__('chars', 'mxchat') ); ?>,
1998 - showText: <?php echo wp_json_encode( esc_html__('Show indexed text', 'mxchat') ); ?>,
1999 - hideText: <?php echo wp_json_encode( esc_html__('Hide indexed text', 'mxchat') ); ?>,
2000 - wpStore: <?php echo wp_json_encode( esc_html__('Local WordPress database', 'mxchat') ); ?>,
2001 - pcStore: <?php echo wp_json_encode( esc_html__('Pinecone', 'mxchat') ); ?>,
2002 - meta: <?php echo wp_json_encode( esc_html__('Vector metadata', 'mxchat') ); ?>,
2003 - loadFail: <?php echo wp_json_encode( esc_html__('Failed to load indexed content.', 'mxchat') ); ?>,
2004 - netErr: <?php echo wp_json_encode( esc_html__('Network error: ', 'mxchat') ); ?>
2005 - };
2006 -
2007 - function esc(str) {
2008 - var d = document.createElement('div');
2009 - d.textContent = (str === null || str === undefined) ? '' : String(str);
2010 - return d.innerHTML;
2011 - }
2012 - function fmt(n) { try { return Number(n).toLocaleString(); } catch (e) { return n; } }
2013 -
2014 - document.addEventListener('click', function(e) {
2015 - var btn = e.target.closest('.mxchat-inspect-entry-btn');
2016 - if (btn) { e.preventDefault(); open(btn); }
2017 - });
2018 - if (closeX) closeX.addEventListener('click', close);
2019 - if (closeBtn) closeBtn.addEventListener('click', close);
2020 - // Overlay click closes, but only when the whole gesture happened on the
2021 - // overlay — otherwise selecting indexed text and releasing past the
2022 - // dialog edge dispatches the click on the overlay and closes it.
2023 - var downOnOverlay = false;
2024 - modal.addEventListener('mousedown', function(e) { downOnOverlay = (e.target === modal); });
2025 - modal.addEventListener('click', function(e) {
2026 - var overlayGesture = downOnOverlay;
2027 - downOnOverlay = false;
2028 - if (e.target === modal && overlayGesture) close();
2029 - });
2030 - document.addEventListener('keydown', function(e) {
2031 - if (e.key === 'Escape' && modal.classList.contains('active')) close();
2032 - });
2033 -
2034 - function close() { modal.classList.remove('active'); }
2035 -
2036 - function open(btn) {
2037 - var entry = {
2038 - sourceUrl: btn.getAttribute('data-source-url') || '',
2039 - entryId: btn.getAttribute('data-entry-id') || '',
2040 - dataSource: btn.getAttribute('data-data-source') || 'wordpress',
2041 - botId: btn.getAttribute('data-bot-id') || 'default',
2042 - nonce: btn.getAttribute('data-nonce') || ''
2043 - };
2044 -
2045 - titleEl.textContent = I18N.title;
2046 - noticeEl.textContent = '';
2047 - noticeEl.className = 'mxchat-kb-edit-notice';
2048 - resultsEl.innerHTML = '<div class="mxch-testing-no-data">' + esc(I18N.loading) + '</div>';
2049 -
2050 - if (entry.sourceUrl && entry.sourceUrl.indexOf('mxchat://') !== 0 && entry.sourceUrl.indexOf('_ungrouped_') !== 0) {
2051 - sourceEl.innerHTML = esc(I18N.source) + ': <a href="' + esc(entry.sourceUrl) + '" target="_blank" rel="noopener">' + esc(entry.sourceUrl) + '</a>';
2052 - } else {
2053 - sourceEl.textContent = I18N.manual;
2054 - }
2055 -
2056 - modal.classList.add('active');
2057 -
2058 - var fd = new FormData();
2059 - fd.append('action', 'mxchat_inspect_entry');
2060 - fd.append('nonce', entry.nonce);
2061 - fd.append('source_url', entry.sourceUrl);
2062 - fd.append('entry_id', entry.entryId);
2063 - fd.append('data_source', entry.dataSource);
2064 - fd.append('bot_id', entry.botId);
2065 -
2066 - fetch(ajaxurl, { method: 'POST', body: fd })
2067 - .then(function(r) { return r.json(); })
2068 - .then(function(resp) {
2069 - if (resp && resp.success) {
2070 - render(resp.data);
2071 - } else {
2072 - var msg = (resp && resp.data && resp.data.message) || I18N.loadFail;
2073 - resultsEl.innerHTML = '';
2074 - showNotice(msg, 'error');
2075 - }
2076 - })
2077 - .catch(function(err) {
2078 - resultsEl.innerHTML = '';
2079 - showNotice(I18N.netErr + err.message, 'error');
2080 - });
2081 - }
2082 -
2083 - function render(data) {
2084 - var storeLabel = data.store === 'pinecone' ? I18N.pcStore : I18N.wpStore;
2085 - var html = '';
2086 -
2087 - // Summary card — what this entry is + how much was indexed.
2088 - html += '<div class="match-card above-threshold">' +
2089 - '<div class="match-header">' +
2090 - '<div class="match-title"><span class="status-icon">&#128230;</span> ' + esc(data.chunk_count) + ' ' + esc(I18N.chunksLbl.toLowerCase()) + '</div>' +
2091 - '<span class="context-label">' + esc(storeLabel) + '</span>' +
2092 - '</div>' +
2093 - '<div class="mxch-testing-field"><label>' + esc(I18N.type) + '</label><code>' + esc(data.content_type || '—') + '</code> ' +
2094 - '&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>';
2095 - if (data.metadata_note) {
2096 - html += '<div class="match-source"><span class="source-icon">&#8505;&#65039;</span> ' + esc(data.metadata_note) + '</div>';
2097 - }
2098 - html += '</div>';
2099 -
2100 - // One card per stored chunk — the actual embedded text.
2101 - var chunks = data.chunks || [];
2102 - chunks.forEach(function(chunk, i) {
2103 - var num = (chunk.index !== null && chunk.index !== undefined) ? (chunk.index + 1) : (i + 1);
2104 - var metaRows = '';
2105 - if (chunk.metadata && typeof chunk.metadata === 'object') {
2106 - var keys = Object.keys(chunk.metadata);
2107 - if (keys.length) {
2108 - metaRows += '<div class="chunk-detail-row chunk-used" style="display:block;"><span class="chunk-detail-num">' + esc(I18N.meta) + '</span></div>';
2109 - keys.forEach(function(k) {
2110 - 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>';
2111 - });
2112 - }
2113 - }
2114 - html += '<div class="match-card above-threshold">' +
2115 - '<div class="match-header">' +
2116 - '<div class="match-title"><span class="status-icon">&#10003;</span> ' + esc(I18N.chunk) + ' ' + esc(num) +
2117 - '<span class="chunk-summary">' + esc(fmt(chunk.length)) + ' ' + esc(I18N.chars) + '</span>' +
2118 - '</div>' +
2119 - '<span class="context-label">' + esc(I18N.indexed) + '</span>' +
2120 - '</div>' +
2121 - '<span class="chunk-expand-toggle" data-chunk="' + i + '">&#9654; ' + esc(I18N.showText) + '</span>' +
2122 - '<div class="chunk-details" data-chunk="' + i + '">' +
2123 - '<pre class="mxch-kb-inspect-chunk-text">' + esc(chunk.text) + '</pre>' +
2124 - metaRows +
2125 - '</div>' +
2126 - '</div>';
2127 - });
2128 -
2129 - resultsEl.innerHTML = html;
2130 -
2131 - resultsEl.querySelectorAll('.chunk-expand-toggle').forEach(function(toggle) {
2132 - toggle.addEventListener('click', function() {
2133 - var id = this.getAttribute('data-chunk');
2134 - var details = resultsEl.querySelector('.chunk-details[data-chunk="' + id + '"]');
2135 - if (!details) return;
2136 - var expanded = details.classList.toggle('expanded');
2137 - this.innerHTML = (expanded ? '&#9660; ' + esc(I18N.hideText) : '&#9654; ' + esc(I18N.showText));
2138 - });
2139 - });
2140 - }
2141 -
2142 - function showNotice(msg, type) {
2143 - noticeEl.textContent = msg;
2144 - noticeEl.className = 'mxchat-kb-edit-notice' + (type ? ' ' + type : '');
2145 - }
2146 - });
2147 - })();
2148 - </script>
2149 - <?php
2150 -}
2151 -
2152 -/**
2153 1734 * Render Knowledge Page Navigation Scripts
2154 1735 */
2155 1736 function mxchat_render_knowledge_page_scripts() {
2156 1737 ?>
@@ -2325,216 +1906,8 @@
2325 1906 }
2326 1907
2327 1908 // Sitemap detection is now handled by knowledge-processing.js
2328 1909 // It will be initialized when user clicks "Sitemap Import" option
2329 -
2330 - // ─── Edit Entry Modal ────────────────────────────────────
2331 - initEditModal();
2332 -
2333 - function initEditModal() {
2334 - var modal = document.getElementById('mxchat-kb-edit-modal');
2335 - var textarea = document.getElementById('mxchat-kb-edit-textarea');
2336 - var saveBtn = document.getElementById('mxchat-kb-edit-save');
2337 - var cancelBtn = document.getElementById('mxchat-kb-edit-cancel');
2338 - var closeBtn = document.getElementById('mxchat-kb-edit-close');
2339 - var notice = document.getElementById('mxchat-kb-edit-notice');
2340 - var charCount = document.getElementById('mxchat-kb-edit-charcount');
2341 - var chunkInfo = document.getElementById('mxchat-kb-edit-chunkinfo');
2342 - var sourceEl = document.getElementById('mxchat-kb-edit-source');
2343 - var titleEl = document.getElementById('mxchat-kb-edit-title');
2344 - var saveText = saveBtn ? saveBtn.querySelector('.mxchat-kb-edit-save-text') : null;
2345 - var saveSpin = saveBtn ? saveBtn.querySelector('.mxchat-kb-edit-save-spinner') : null;
2346 -
2347 - if (!modal) return;
2348 -
2349 - var currentEntry = {};
2350 - var loadedContent = '';
2351 -
2352 - var EDIT_I18N = {
2353 - discard: <?php echo wp_json_encode( __('Discard your unsaved changes to this entry?', 'mxchat') ); ?>
2354 - };
2355 -
2356 - // Bind edit buttons (delegated)
2357 - document.addEventListener('click', function(e) {
2358 - var btn = e.target.closest('.mxchat-edit-entry-btn');
2359 - if (btn) {
2360 - e.preventDefault();
2361 - openEditModal(btn);
2362 - }
2363 - });
2364 -
2365 - // Close handlers. The overlay deliberately has no click-to-close: a click
2366 - // fires on the common ancestor of its mousedown and mouseup, so releasing
2367 - // a text-selection drag past the dialog edge targets the overlay and would
2368 - // discard the edit. Closing is explicit only, and confirms when dirty.
2369 - if (closeBtn) closeBtn.addEventListener('click', requestClose);
2370 - if (cancelBtn) cancelBtn.addEventListener('click', requestClose);
2371 - document.addEventListener('keydown', function(e) {
2372 - if (e.key === 'Escape' && modal.classList.contains('active')) requestClose();
2373 - });
2374 -
2375 - // Character count
2376 - if (textarea) {
2377 - textarea.addEventListener('input', function() {
2378 - updateCharCount();
2379 - });
2380 - }
2381 -
2382 - // Save handler
2383 - if (saveBtn) saveBtn.addEventListener('click', saveContent);
2384 -
2385 - function openEditModal(btn) {
2386 - currentEntry = {
2387 - sourceUrl: btn.getAttribute('data-source-url') || '',
2388 - entryId: btn.getAttribute('data-entry-id') || '',
2389 - dataSource: btn.getAttribute('data-data-source') || 'wordpress',
2390 - botId: btn.getAttribute('data-bot-id') || 'default',
2391 - nonce: btn.getAttribute('data-nonce') || ''
2392 - };
2393 -
2394 - // Reset state
2395 - textarea.value = '';
2396 - loadedContent = '';
2397 - textarea.placeholder = 'Loading content...';
2398 - textarea.disabled = true;
2399 - saveBtn.disabled = true;
2400 - notice.textContent = '';
2401 - notice.className = 'mxchat-kb-edit-notice';
2402 - charCount.textContent = '';
2403 - chunkInfo.textContent = '';
2404 -
2405 - // Show source
2406 - if (currentEntry.sourceUrl && currentEntry.sourceUrl.indexOf('mxchat://') !== 0) {
2407 - sourceEl.innerHTML = 'Source: <a href="' + escapeHtml(currentEntry.sourceUrl) + '" target="_blank">' + escapeHtml(truncate(currentEntry.sourceUrl, 60)) + '</a>';
2408 - } else {
2409 - sourceEl.textContent = 'Manual Content';
2410 - }
2411 -
2412 - // Show modal
2413 - modal.classList.add('active');
2414 -
2415 - // Fetch content
2416 - var formData = new FormData();
2417 - formData.append('action', 'mxchat_get_entry_content');
2418 - formData.append('nonce', currentEntry.nonce);
2419 - formData.append('source_url', currentEntry.sourceUrl);
2420 - formData.append('entry_id', currentEntry.entryId);
2421 - formData.append('data_source', currentEntry.dataSource);
2422 - formData.append('bot_id', currentEntry.botId);
2423 -
2424 - fetch(ajaxurl, { method: 'POST', body: formData })
2425 - .then(function(r) { return r.json(); })
2426 - .then(function(resp) {
2427 - if (resp.success) {
2428 - textarea.value = resp.data.content || '';
2429 - loadedContent = textarea.value;
2430 - textarea.disabled = false;
2431 - textarea.placeholder = 'Edit your content here...';
2432 - saveBtn.disabled = false;
2433 - currentEntry.contentType = resp.data.content_type || 'content';
2434 -
2435 - updateCharCount();
2436 -
2437 - if (resp.data.is_chunked) {
2438 - chunkInfo.textContent = resp.data.chunk_count + ' chunks — will be re-chunked on save';
2439 - titleEl.textContent = 'Edit Knowledge Entry (' + resp.data.chunk_count + ' chunks)';
2440 - } else {
2441 - chunkInfo.textContent = '';
2442 - titleEl.textContent = 'Edit Knowledge Entry';
2443 - }
2444 -
2445 - textarea.focus();
2446 - } else {
2447 - textarea.placeholder = '';
2448 - showNotice((resp.data && resp.data.message) || 'Failed to load content.', 'error');
2449 - }
2450 - })
2451 - .catch(function(err) {
2452 - textarea.placeholder = '';
2453 - showNotice('Network error: ' + err.message, 'error');
2454 - });
2455 - }
2456 -
2457 - function saveContent() {
2458 - if (!textarea.value.trim()) {
2459 - showNotice('Content cannot be empty.', 'error');
2460 - return;
2461 - }
2462 -
2463 - saveBtn.disabled = true;
2464 - if (saveText) saveText.style.display = 'none';
2465 - if (saveSpin) saveSpin.style.display = '';
2466 - showNotice('Saving and re-embedding...', '');
2467 -
2468 - var formData = new FormData();
2469 - formData.append('action', 'mxchat_save_entry_content');
2470 - formData.append('nonce', currentEntry.nonce);
2471 - formData.append('source_url', currentEntry.sourceUrl);
2472 - formData.append('entry_id', currentEntry.entryId);
2473 - formData.append('content', textarea.value);
2474 - formData.append('data_source', currentEntry.dataSource);
2475 - formData.append('bot_id', currentEntry.botId);
2476 - formData.append('content_type', currentEntry.contentType || 'content');
2477 -
2478 - fetch(ajaxurl, { method: 'POST', body: formData })
2479 - .then(function(r) { return r.json(); })
2480 - .then(function(resp) {
2481 - if (saveText) saveText.style.display = '';
2482 - if (saveSpin) saveSpin.style.display = 'none';
2483 - saveBtn.disabled = false;
2484 -
2485 - if (resp.success) {
2486 - showNotice('Saved successfully!', 'success');
2487 - setTimeout(function() {
2488 - closeModal();
2489 - window.location.reload();
2490 - }, 1000);
2491 - } else {
2492 - showNotice((resp.data && resp.data.message) || 'Save failed.', 'error');
2493 - }
2494 - })
2495 - .catch(function(err) {
2496 - if (saveText) saveText.style.display = '';
2497 - if (saveSpin) saveSpin.style.display = 'none';
2498 - saveBtn.disabled = false;
2499 - showNotice('Network error: ' + err.message, 'error');
2500 - });
2501 - }
2502 -
2503 - function isDirty() {
2504 - return !textarea.disabled && textarea.value !== loadedContent;
2505 - }
2506 -
2507 - function requestClose() {
2508 - if (isDirty() && !window.confirm(EDIT_I18N.discard)) return;
2509 - closeModal();
2510 - }
2511 -
2512 - function closeModal() {
2513 - modal.classList.remove('active');
2514 - }
2515 -
2516 - function updateCharCount() {
2517 - var len = textarea.value.length;
2518 - charCount.textContent = len.toLocaleString() + ' characters';
2519 - }
2520 -
2521 - function showNotice(msg, type) {
2522 - notice.textContent = msg;
2523 - notice.className = 'mxchat-kb-edit-notice' + (type ? ' ' + type : '');
2524 - }
2525 -
2526 - function escapeHtml(str) {
2527 - var div = document.createElement('div');
2528 - div.textContent = str;
2529 - return div.innerHTML;
2530 - }
2531 -
2532 - function truncate(str, max) {
2533 - return str.length > max ? str.substring(0, max) + '...' : str;
2534 - }
2535 - }
2536 -
2537 1910 })();
2538 1911 </script>
2539 1912 <?php
2540 1913 }