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
mxchat-basic / includes / admin-knowledge-page.php

admin-knowledge-page.php in MxChat – AI Chatbot & Content Generation for WordPress 3.1.1, at includes/admin-knowledge-page.php

1,914 lines 133.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * MxChat Knowledge Base Page - Redesigned with Sidebar Navigation
4 *
5 * @package MxChat
6 * @since 2.7.0
7 */
8
9 if (!defined('ABSPATH')) {
10 exit;
11 }
12
13 /**
14 * Render the new sidebar-based Knowledge Base page
15 */
16 function mxchat_render_knowledge_page($admin_instance, $knowledge_manager, $page_data) {
17 $is_activated = $admin_instance->is_activated();
18 $plugin_url = plugin_dir_url(dirname(__FILE__));
19
20 // Check if integrations are active
21 $pinecone_options = get_option('mxchat_pinecone_addon_options', array());
22 $is_pinecone_active = ($pinecone_options['mxchat_use_pinecone'] ?? '0') === '1';
23
24 $vectorstore_options = get_option('mxchat_openai_vectorstore_options', array());
25 $is_vectorstore_active = ($vectorstore_options['mxchat_use_openai_vectorstore'] ?? '0') === '1';
26
27 // Extract page data
28 extract($page_data);
29 ?>
30 <div class="mxch-admin-wrapper">
31 <!-- Mobile Header -->
32 <header class="mxch-mobile-header">
33 <a href="#" class="mxch-mobile-logo">
34 <div class="mxch-mobile-logo-icon">
35 <img src="<?php echo esc_url($plugin_url . 'images/icon-128x128.png'); ?>" alt="MxChat">
36 </div>
37 <span class="mxch-mobile-logo-text">MxChat</span>
38 </a>
39 <button type="button" class="mxch-mobile-menu-btn" aria-label="<?php esc_attr_e('Open menu', 'mxchat'); ?>">
40 <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"><circle cx="12" cy="12" r="1"/><circle cx="12" cy="5" r="1"/><circle cx="12" cy="19" r="1"/></svg>
41 </button>
42 </header>
43
44 <!-- Mobile Menu Overlay -->
45 <div class="mxch-mobile-overlay"></div>
46
47 <!-- Mobile Menu Modal -->
48 <div class="mxch-mobile-menu">
49 <div class="mxch-mobile-menu-header">
50 <span class="mxch-mobile-menu-title"><?php esc_html_e('Knowledge Base', 'mxchat'); ?></span>
51 <button type="button" class="mxch-mobile-menu-close" aria-label="<?php esc_attr_e('Close menu', 'mxchat'); ?>">
52 <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"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>
53 </button>
54 </div>
55 <nav class="mxch-mobile-menu-nav">
56 <!-- Import Section -->
57 <div class="mxch-mobile-nav-section">
58 <div class="mxch-mobile-nav-section-title"><?php esc_html_e('Import', 'mxchat'); ?></div>
59 <button class="mxch-mobile-nav-link active" data-target="import-options">
60 <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="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="17 8 12 3 7 8"/><line x1="12" y1="3" x2="12" y2="15"/></svg>
61 <span><?php esc_html_e('Import Options', 'mxchat'); ?></span>
62 </button>
63 <button class="mxch-mobile-nav-link" data-target="knowledge-base">
64 <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"><ellipse cx="12" cy="5" rx="9" ry="3"/><path d="M21 12c0 1.66-4 3-9 3s-9-1.34-9-3"/><path d="M3 5v14c0 1.66 4 3 9 3s9-1.34 9-3V5"/></svg>
65 <span><?php esc_html_e('Knowledge Base', 'mxchat'); ?></span>
66 </button>
67 </div>
68 <!-- Settings Section -->
69 <div class="mxch-mobile-nav-section">
70 <div class="mxch-mobile-nav-section-title"><?php esc_html_e('Settings', 'mxchat'); ?></div>
71 <button class="mxch-mobile-nav-link" data-target="auto-sync">
72 <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="M21 12a9 9 0 0 0-9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"/><path d="M3 3v5h5"/><path d="M3 12a9 9 0 0 0 9 9 9.75 9.75 0 0 0 6.74-2.74L21 16"/><path d="M16 16h5v5"/></svg>
73 <span><?php esc_html_e('Auto-Sync', 'mxchat'); ?></span>
74 </button>
75 <button class="mxch-mobile-nav-link" data-target="chunking">
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('Content Chunking', 'mxchat'); ?></span>
78 </button>
79 <button class="mxch-mobile-nav-link" data-target="role-restrictions">
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 <span><?php esc_html_e('Role Restrictions', 'mxchat'); ?></span>
82 </button>
83 <button class="mxch-mobile-nav-link" data-target="acf-fields">
84 <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="M14.5 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7.5L14.5 2z"/><polyline points="14 2 14 8 20 8"/><line x1="16" y1="13" x2="8" y2="13"/><line x1="16" y1="17" x2="8" y2="17"/><line x1="10" y1="9" x2="8" y2="9"/></svg>
85 <span><?php esc_html_e('ACF Fields', 'mxchat'); ?></span>
86 </button>
87 <button class="mxch-mobile-nav-link" data-target="custom-meta">
88 <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="M4 7V4h16v3"/><path d="M9 20h6"/><path d="M12 4v16"/></svg>
89 <span><?php esc_html_e('Custom Meta', 'mxchat'); ?></span>
90 </button>
91 </div>
92 <!-- Integrations Section -->
93 <div class="mxch-mobile-nav-section">
94 <div class="mxch-mobile-nav-section-title"><?php esc_html_e('Integrations', 'mxchat'); ?></div>
95 <button class="mxch-mobile-nav-link" data-target="pinecone">
96 <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="M17.5 19H9a7 7 0 1 1 6.71-9h1.79a4.5 4.5 0 1 1 0 9Z"/></svg>
97 <span><?php esc_html_e('Pinecone', 'mxchat'); ?></span>
98 <?php if ($is_pinecone_active): ?>
99 <span class="mxch-nav-link-badge mxch-active-badge"><?php esc_html_e('Active', 'mxchat'); ?></span>
100 <?php endif; ?>
101 </button>
102 <button class="mxch-mobile-nav-link" data-target="openai-vectorstore">
103 <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"/><path d="m21 21-4.3-4.3"/><path d="M11 8v6"/><path d="M8 11h6"/></svg>
104 <span><?php esc_html_e('OpenAI Vector Store', 'mxchat'); ?></span>
105 <?php if ($is_vectorstore_active): ?>
106 <span class="mxch-nav-link-badge mxch-active-badge"><?php esc_html_e('Active', 'mxchat'); ?></span>
107 <?php endif; ?>
108 </button>
109 </div>
110 <?php if (!$is_activated): ?>
111 <div class="mxch-mobile-menu-footer">
112 <a href="https://mxchat.ai/" target="_blank" class="mxch-mobile-upgrade-btn">
113 <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="M6 9H4.5a2.5 2.5 0 0 1 0-5H6"/><path d="M18 9h1.5a2.5 2.5 0 0 0 0-5H18"/><path d="M4 22h16"/><path d="M10 14.66V17c0 .55-.47.98-.97 1.21C7.85 18.75 7 20.24 7 22"/><path d="M14 14.66V17c0 .55.47.98.97 1.21C16.15 18.75 17 20.24 17 22"/><path d="M18 2H6v7a6 6 0 0 0 12 0V2Z"/></svg>
114 <?php esc_html_e('Upgrade to Pro', 'mxchat'); ?>
115 </a>
116 </div>
117 <?php endif; ?>
118 </nav>
119 </div>
120
121 <!-- Sidebar Navigation -->
122 <aside class="mxch-sidebar">
123 <div class="mxch-sidebar-header">
124 <a href="#" class="mxch-sidebar-logo">
125 <div class="mxch-sidebar-logo-icon">
126 <img src="<?php echo esc_url($plugin_url . 'images/icon-128x128.png'); ?>" alt="MxChat">
127 </div>
128 <span class="mxch-sidebar-logo-text">MxChat</span>
129 <span class="mxch-sidebar-version">v<?php echo esc_html(MXCHAT_VERSION ?? '2.7.0'); ?></span>
130 </a>
131 </div>
132
133 <nav class="mxch-sidebar-nav">
134 <!-- Import Section -->
135 <div class="mxch-nav-section">
136 <div class="mxch-nav-section-title"><?php esc_html_e('Import', 'mxchat'); ?></div>
137
138 <div class="mxch-nav-item" data-section="import-options">
139 <button class="mxch-nav-link active" data-target="import-options">
140 <span class="mxch-nav-link-icon">
141 <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"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="17 8 12 3 7 8"/><line x1="12" y1="3" x2="12" y2="15"/></svg>
142 </span>
143 <span class="mxch-nav-link-text"><?php esc_html_e('Import Options', 'mxchat'); ?></span>
144 </button>
145 </div>
146
147 <div class="mxch-nav-item" data-section="knowledge-base">
148 <button class="mxch-nav-link" data-target="knowledge-base">
149 <span class="mxch-nav-link-icon">
150 <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"><ellipse cx="12" cy="5" rx="9" ry="3"/><path d="M21 12c0 1.66-4 3-9 3s-9-1.34-9-3"/><path d="M3 5v14c0 1.66 4 3 9 3s9-1.34 9-3V5"/></svg>
151 </span>
152 <span class="mxch-nav-link-text"><?php esc_html_e('Knowledge Base', 'mxchat'); ?></span>
153 <span id="mxchat-sidebar-count" class="mxch-nav-link-badge"><?php echo esc_html($total_records); ?></span>
154 </button>
155 </div>
156 </div>
157
158 <!-- Settings Section -->
159 <div class="mxch-nav-section">
160 <div class="mxch-nav-section-title"><?php esc_html_e('Settings', 'mxchat'); ?></div>
161
162 <div class="mxch-nav-item" data-section="auto-sync">
163 <button class="mxch-nav-link" data-target="auto-sync">
164 <span class="mxch-nav-link-icon">
165 <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"><path d="M21 12a9 9 0 0 0-9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"/><path d="M3 3v5h5"/><path d="M3 12a9 9 0 0 0 9 9 9.75 9.75 0 0 0 6.74-2.74L21 16"/><path d="M16 16h5v5"/></svg>
166 </span>
167 <span class="mxch-nav-link-text"><?php esc_html_e('Auto-Sync', 'mxchat'); ?></span>
168 </button>
169 </div>
170
171 <div class="mxch-nav-item" data-section="chunking">
172 <button class="mxch-nav-link" data-target="chunking">
173 <span class="mxch-nav-link-icon">
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 </span>
176 <span class="mxch-nav-link-text"><?php esc_html_e('Content Chunking', 'mxchat'); ?></span>
177 </button>
178 </div>
179
180 <div class="mxch-nav-item" data-section="role-restrictions">
181 <button class="mxch-nav-link" data-target="role-restrictions">
182 <span class="mxch-nav-link-icon">
183 <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"><path d="M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"/></svg>
184 </span>
185 <span class="mxch-nav-link-text"><?php esc_html_e('Role Restrictions', 'mxchat'); ?></span>
186 </button>
187 </div>
188
189 <div class="mxch-nav-item" data-section="acf-fields">
190 <button class="mxch-nav-link" data-target="acf-fields">
191 <span class="mxch-nav-link-icon">
192 <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"><path d="M14.5 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7.5L14.5 2z"/><polyline points="14 2 14 8 20 8"/><line x1="16" y1="13" x2="8" y2="13"/><line x1="16" y1="17" x2="8" y2="17"/><line x1="10" y1="9" x2="8" y2="9"/></svg>
193 </span>
194 <span class="mxch-nav-link-text"><?php esc_html_e('ACF Fields', 'mxchat'); ?></span>
195 </button>
196 </div>
197
198 <div class="mxch-nav-item" data-section="custom-meta">
199 <button class="mxch-nav-link" data-target="custom-meta">
200 <span class="mxch-nav-link-icon">
201 <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"><path d="M4 7V4h16v3"/><path d="M9 20h6"/><path d="M12 4v16"/></svg>
202 </span>
203 <span class="mxch-nav-link-text"><?php esc_html_e('Custom Meta', 'mxchat'); ?></span>
204 </button>
205 </div>
206 </div>
207
208 <!-- Integrations Section -->
209 <div class="mxch-nav-section">
210 <div class="mxch-nav-section-title"><?php esc_html_e('Integrations', 'mxchat'); ?></div>
211
212 <div class="mxch-nav-item" data-section="pinecone">
213 <button class="mxch-nav-link" data-target="pinecone">
214 <span class="mxch-nav-link-icon">
215 <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"><path d="M17.5 19H9a7 7 0 1 1 6.71-9h1.79a4.5 4.5 0 1 1 0 9Z"/></svg>
216 </span>
217 <span class="mxch-nav-link-text"><?php esc_html_e('Pinecone', 'mxchat'); ?></span>
218 <?php if ($is_pinecone_active): ?>
219 <span class="mxch-nav-link-badge mxch-active-badge"><?php esc_html_e('Active', 'mxchat'); ?></span>
220 <?php endif; ?>
221 </button>
222 </div>
223
224 <div class="mxch-nav-item" data-section="openai-vectorstore">
225 <button class="mxch-nav-link" data-target="openai-vectorstore">
226 <span class="mxch-nav-link-icon">
227 <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"><circle cx="11" cy="11" r="8"/><path d="m21 21-4.3-4.3"/><path d="M11 8v6"/><path d="M8 11h6"/></svg>
228 </span>
229 <span class="mxch-nav-link-text"><?php esc_html_e('OpenAI Vector Store', 'mxchat'); ?></span>
230 <?php if ($is_vectorstore_active): ?>
231 <span class="mxch-nav-link-badge mxch-active-badge"><?php esc_html_e('Active', 'mxchat'); ?></span>
232 <?php endif; ?>
233 </button>
234 </div>
235 </div>
236 </nav>
237
238 <?php if (!$is_activated): ?>
239 <div class="mxch-sidebar-footer">
240 <a href="https://mxchat.ai/" target="_blank" class="mxch-sidebar-upgrade-v2">
241 <svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polygon points="12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2"/></svg>
242 <?php esc_html_e('Pro Upgrade', 'mxchat'); ?>
243 </a>
244 </div>
245 <?php endif; ?>
246 </aside>
247
248 <!-- Main Content Area -->
249 <main class="mxch-content">
250 <?php
251 // Multi-Bot Selector
252 mxchat_render_knowledge_bot_selector($multibot_active, $current_bot_id);
253
254 // Global Processing Status - Always visible when processing
255 mxchat_render_global_processing_status($page_data, $knowledge_manager);
256
257 // Render content sections
258 mxchat_render_import_options_section($admin_instance, $knowledge_manager, $page_data);
259 mxchat_render_knowledge_base_section($admin_instance, $knowledge_manager, $page_data);
260 mxchat_render_auto_sync_section($knowledge_manager);
261 mxchat_render_chunking_section();
262 mxchat_render_role_restrictions_section($knowledge_manager);
263 mxchat_render_acf_fields_section($knowledge_manager);
264 mxchat_render_custom_meta_section();
265 mxchat_render_pinecone_section();
266 mxchat_render_openai_vectorstore_section();
267 ?>
268
269 </main>
270 </div>
271
272 <?php
273 // Render the Content Selector Modal
274 mxchat_render_content_selector_modal();
275
276 // Render the navigation JavaScript
277 mxchat_render_knowledge_page_scripts();
278 }
279
280 /**
281 * Render Multi-Bot Selector
282 */
283 function mxchat_render_knowledge_bot_selector($multibot_active, $current_bot_id) {
284 if (!$multibot_active || !class_exists('MxChat_Multi_Bot_Manager')) {
285 return;
286 }
287
288 $multi_bot_manager = MxChat_Multi_Bot_Core_Manager::get_instance();
289 $available_bots = $multi_bot_manager->get_available_bots();
290 ?>
291 <div class="mxch-card" style="margin-bottom: 24px;">
292 <div class="mxch-card-body">
293 <div style="display: flex; align-items: center; gap: 15px; flex-wrap: wrap;">
294 <label for="mxchat-bot-selector" style="font-weight: 600; white-space: nowrap;">
295 <?php esc_html_e('Select Bot Database:', 'mxchat'); ?>
296 </label>
297 <select id="mxchat-bot-selector" class="mxch-select" style="min-width: 200px; max-width: 300px;">
298 <?php foreach ($available_bots as $bot_id => $bot_name) : ?>
299 <option value="<?php echo esc_attr($bot_id); ?>" <?php selected($current_bot_id, $bot_id); ?>>
300 <?php echo esc_html($bot_name); ?>
301 </option>
302 <?php endforeach; ?>
303 </select>
304 <span style="color: var(--mxch-text-secondary); font-size: 13px;">
305 <?php esc_html_e('Content will be added to the selected bot\'s knowledge base', 'mxchat'); ?>
306 </span>
307 <span id="mxchat-bot-save-status" style="display: none; color: var(--mxch-success); font-size: 13px;">
308 <?php esc_html_e('Saved', 'mxchat'); ?>
309 </span>
310 </div>
311 </div>
312 </div>
313 <?php
314 }
315
316 /**
317 * Render Global Processing Status - Always visible when processing is active
318 */
319 function mxchat_render_global_processing_status($page_data, $knowledge_manager) {
320 extract($page_data);
321
322 // Only show if there's active processing
323 if (!$is_processing) {
324 return;
325 }
326 ?>
327 <div class="mxch-processing-status-global mxchat-import-section" style="margin-bottom: 24px;">
328 <?php
329 // PDF Processing Status - Using mxchat-status-card class for JavaScript compatibility
330 if ($pdf_status && $pdf_status['status'] === 'processing') : ?>
331 <div class="mxchat-status-card mxch-card" data-card-type="pdf" data-queue-id="<?php echo esc_attr(get_transient('mxchat_active_queue_pdf')); ?>" style="border-left: 4px solid var(--mxch-primary); margin-bottom: 16px;">
332 <div class="mxchat-status-header mxch-card-header" style="background: var(--mxch-primary-light);">
333 <h4 style="margin: 0; display: flex; align-items: center; gap: 8px; font-size: 15px; font-weight: 600;">
334 <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M14.5 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7.5L14.5 2z"/><polyline points="14 2 14 8 20 8"/></svg>
335 <?php esc_html_e('PDF Processing Status', 'mxchat'); ?>
336 </h4>
337 <div class="mxchat-status-warning" style="background: #fff3cd; color: #856404; padding: 8px 12px; border-radius: 4px; font-size: 13px; margin: 10px 0;">
338 <?php esc_html_e('Keep this tab open - Processing runs in your browser', 'mxchat'); ?>
339 </div>
340 <form method="post" class="mxchat-stop-form" action="<?php echo esc_url(admin_url('admin-post.php?action=mxchat_stop_processing')); ?>">
341 <?php wp_nonce_field('mxchat_stop_processing_action', 'mxchat_stop_processing_nonce'); ?>
342 <button type="submit" name="stop_processing" class="mxchat-button-secondary mxch-btn mxch-btn-secondary mxch-btn-sm">
343 <?php esc_html_e('Stop Processing', 'mxchat'); ?>
344 </button>
345 </form>
346 </div>
347 <div class="mxchat-progress-bar" style="height: 8px; background: #e2e8f0; border-radius: 4px; overflow: hidden; margin: 0;">
348 <div class="mxchat-progress-fill" style="height: 100%; background: var(--mxch-primary); width: <?php echo esc_attr($pdf_status['percentage']); ?>%; transition: width 0.3s;"></div>
349 </div>
350 <div class="mxchat-status-details mxch-card-body">
351 <p><?php printf(esc_html__('Progress: %1$d of %2$d pages (%3$d%%)', 'mxchat'), absint($pdf_status['processed_pages']), absint($pdf_status['total_pages']), absint($pdf_status['percentage'])); ?></p>
352 <?php if (!empty($pdf_status['failed_pages']) && $pdf_status['failed_pages'] > 0) : ?>
353 <p class="error-count" style="color: var(--mxch-error);"><strong><?php esc_html_e('Failed pages:', 'mxchat'); ?></strong> <?php echo esc_html($pdf_status['failed_pages']); ?></p>
354 <?php endif; ?>
355 <p><strong><?php esc_html_e('Status:', 'mxchat'); ?></strong> <?php esc_html_e('Processing', 'mxchat'); ?></p>
356 </div>
357 </div>
358 <?php endif;
359
360 // Sitemap Processing Status - Using mxchat-status-card class for JavaScript compatibility
361 if ($sitemap_status && $sitemap_status['status'] === 'processing') : ?>
362 <div class="mxchat-status-card mxch-card" data-card-type="sitemap" data-queue-id="<?php echo esc_attr(get_transient('mxchat_active_queue_sitemap')); ?>" style="border-left: 4px solid var(--mxch-primary); margin-bottom: 16px;">
363 <div class="mxchat-status-header mxch-card-header" style="background: var(--mxch-primary-light);">
364 <h4 style="margin: 0; display: flex; align-items: center; gap: 8px; font-size: 15px; font-weight: 600;">
365 <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><line x1="2" y1="12" x2="22" y2="12"/><path d="M12 2a15.3 15.3 0 0 1 4 10 15.3 15.3 0 0 1-4 10 15.3 15.3 0 0 1-4-10 15.3 15.3 0 0 1 4-10z"/></svg>
366 <?php esc_html_e('Sitemap Processing Status', 'mxchat'); ?>
367 </h4>
368 <div class="mxchat-status-warning" style="background: #fff3cd; color: #856404; padding: 8px 12px; border-radius: 4px; font-size: 13px; margin: 10px 0;">
369 <?php esc_html_e('Keep this tab open - Processing runs in your browser', 'mxchat'); ?>
370 </div>
371 <form method="post" class="mxchat-stop-form" action="<?php echo esc_url(admin_url('admin-post.php?action=mxchat_stop_processing')); ?>">
372 <?php wp_nonce_field('mxchat_stop_processing_action', 'mxchat_stop_processing_nonce'); ?>
373 <button type="submit" name="stop_processing" class="mxchat-button-secondary mxch-btn mxch-btn-secondary mxch-btn-sm">
374 <?php esc_html_e('Stop Processing', 'mxchat'); ?>
375 </button>
376 </form>
377 </div>
378 <div class="mxchat-progress-bar" style="height: 8px; background: #e2e8f0; border-radius: 4px; overflow: hidden; margin: 0;">
379 <div class="mxchat-progress-fill" style="height: 100%; background: var(--mxch-primary); width: <?php echo esc_attr($sitemap_status['percentage']); ?>%; transition: width 0.3s;"></div>
380 </div>
381 <div class="mxchat-status-details mxch-card-body">
382 <p><?php printf(esc_html__('Progress: %1$d of %2$d URLs (%3$d%%)', 'mxchat'), absint($sitemap_status['processed_urls']), absint($sitemap_status['total_urls']), absint($sitemap_status['percentage'])); ?></p>
383 <?php if (!empty($sitemap_status['failed_urls']) && $sitemap_status['failed_urls'] > 0) : ?>
384 <p class="error-count" style="color: var(--mxch-error);"><strong><?php esc_html_e('Failed URLs:', 'mxchat'); ?></strong> <?php echo esc_html($sitemap_status['failed_urls']); ?></p>
385 <?php endif; ?>
386 <p><strong><?php esc_html_e('Status:', 'mxchat'); ?></strong> <?php esc_html_e('Processing', 'mxchat'); ?></p>
387 </div>
388 </div>
389 <?php endif;
390
391 // Completed status cards
392 echo $knowledge_manager->mxchat_render_completed_status_cards();
393 ?>
394 </div>
395 <?php
396 }
397
398 /**
399 * Render Import Options Section
400 */
401 function mxchat_render_import_options_section($admin_instance, $knowledge_manager, $page_data) {
402 extract($page_data);
403 $options = $admin_instance->options ?? get_option('mxchat_options', array());
404
405 // Check if user is using WordPress database (not Pinecone or OpenAI Vector Store)
406 $pinecone_options = get_option('mxchat_pinecone_addon_options', array());
407 $is_pinecone_active = ($pinecone_options['mxchat_use_pinecone'] ?? '0') === '1';
408 $vectorstore_options = get_option('mxchat_openai_vectorstore_options', array());
409 $is_vectorstore_active = ($vectorstore_options['mxchat_use_openai_vectorstore'] ?? '0') === '1';
410 $is_using_wordpress_db = !$is_pinecone_active && !$is_vectorstore_active;
411
412 // Check embedding API key
413 $embedding_model = isset($options['embedding_model']) ? esc_attr($options['embedding_model']) : 'text-embedding-ada-002';
414 $has_openai_key = !empty($options['api_key']);
415 $has_voyage_key = !empty($options['voyage_api_key']);
416 $has_gemini_key = !empty($options['gemini_api_key']);
417
418 $has_required_key = false;
419 $required_key_type = '';
420
421 if (strpos($embedding_model, 'text-embedding-') !== false && $has_openai_key) {
422 $has_required_key = true;
423 $required_key_type = 'OpenAI';
424 } elseif (strpos($embedding_model, 'voyage-') !== false && $has_voyage_key) {
425 $has_required_key = true;
426 $required_key_type = 'Voyage AI';
427 } elseif (strpos($embedding_model, 'gemini-embedding-') !== false && $has_gemini_key) {
428 $has_required_key = true;
429 $required_key_type = 'Google Gemini';
430 } elseif (strpos($embedding_model, 'text-embedding-') !== false) {
431 $required_key_type = 'OpenAI';
432 } elseif (strpos($embedding_model, 'voyage-') !== false) {
433 $required_key_type = 'Voyage AI';
434 } elseif (strpos($embedding_model, 'gemini-embedding-') !== false) {
435 $required_key_type = 'Google Gemini';
436 }
437 ?>
438 <div id="import-options" class="mxch-section active">
439 <div class="mxch-content-header">
440 <h1 class="mxch-content-title"><?php esc_html_e('Import Options', 'mxchat'); ?></h1>
441 <p class="mxch-content-subtitle"><?php esc_html_e('Import content to your knowledge base from various sources.', 'mxchat'); ?></p>
442 </div>
443
444 <!-- API Key Status -->
445 <div class="mxch-notice <?php echo $has_required_key ? 'mxch-notice-success' : 'mxch-notice-warning'; ?>" style="margin-bottom: 24px;">
446 <svg class="mxch-notice-icon" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
447 <?php if ($has_required_key): ?>
448 <path d="M22 11.08V12a10 10 0 1 1-5.93-9.14"/><polyline points="22 4 12 14.01 9 11.01"/>
449 <?php else: ?>
450 <path d="m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3Z"/><line x1="12" y1="9" x2="12" y2="13"/><line x1="12" y1="17" x2="12.01" y2="17"/>
451 <?php endif; ?>
452 </svg>
453 <div>
454 <?php if ($has_required_key): ?>
455 <?php echo wp_kses_post(sprintf(__('We detected your %s API key. <strong>Remember to add credits to your %s account</strong> before using the knowledgebase.', 'mxchat'), $required_key_type, $required_key_type)); ?>
456 <?php else: ?>
457 <strong><?php esc_html_e('Important:', 'mxchat'); ?></strong>
458 <?php echo sprintf(esc_html__('Before importing knowledge, you must add a %s API key with sufficient credits in the Chatbot settings.', 'mxchat'), $required_key_type); ?>
459 <a href="<?php echo admin_url('admin.php?page=mxchat-max#api-keys'); ?>"><?php esc_html_e('Go to API Key Settings', 'mxchat'); ?></a>
460 <?php endif; ?>
461 </div>
462 </div>
463
464 <?php if ($is_using_wordpress_db): ?>
465 <!-- WordPress Database Caution Notice -->
466 <div class="mxch-notice mxch-notice-warning" style="margin-bottom: 24px;">
467 <svg class="mxch-notice-icon" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
468 <path d="m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3Z"/><line x1="12" y1="9" x2="12" y2="13"/><line x1="12" y1="17" x2="12.01" y2="17"/>
469 </svg>
470 <div>
471 <strong><?php esc_html_e('Using WordPress Database:', 'mxchat'); ?></strong>
472 <?php esc_html_e('The WordPress database is not optimized for vector search with large datasets. If you plan to have more than 500 knowledge entries, we highly recommend using Pinecone for better performance and scalability.', 'mxchat'); ?>
473 </div>
474 </div>
475 <?php endif; ?>
476
477 <div class="mxch-card">
478 <div class="mxch-card-header">
479 <h3 class="mxch-card-title">
480 <svg class="mxch-card-title-icon" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="17 8 12 3 7 8"/><line x1="12" y1="3" x2="12" y2="15"/></svg>
481 <?php esc_html_e('Choose Import Method', 'mxchat'); ?>
482 </h3>
483 </div>
484 <div class="mxch-card-body">
485 <!-- Import Options Grid -->
486 <div class="mxchat-import-options">
487 <!-- WordPress Import Option -->
488 <button type="button" id="mxchat-open-content-selector" class="mxchat-import-box mxchat-import-wordpress" data-option="wordpress">
489 <div class="mxchat-import-icon">
490 <span class="dashicons dashicons-wordpress"></span>
491 </div>
492 <div class="mxchat-import-content">
493 <h4><?php esc_html_e('WordPress Content', 'mxchat'); ?></h4>
494 <p><?php esc_html_e('Import specific posts and pages to your knowledge base.', 'mxchat'); ?></p>
495 </div>
496 <div class="mxchat-recommended-tag"><?php esc_html_e('Recommended', 'mxchat'); ?></div>
497 </button>
498
499 <!-- Sitemap Import Option -->
500 <button type="button" class="mxchat-import-box" data-option="sitemap" data-placeholder="<?php esc_attr_e('Enter sitemap URL here', 'mxchat'); ?>" data-type="sitemap">
501 <div class="mxchat-import-icon">
502 <span class="dashicons dashicons-admin-site-alt"></span>
503 </div>
504 <div class="mxchat-import-content">
505 <h4><?php esc_html_e('Sitemap Import', 'mxchat'); ?></h4>
506 <p><?php esc_html_e('Use a content-specific sub-sitemap, not the sitemap index.', 'mxchat'); ?></p>
507 </div>
508 </button>
509
510 <!-- Direct URL Import Option -->
511 <button type="button" class="mxchat-import-box" data-option="url" data-placeholder="<?php esc_attr_e('Enter webpage URL here', 'mxchat'); ?>" data-type="url">
512 <div class="mxchat-import-icon">
513 <span class="dashicons dashicons-admin-links"></span>
514 </div>
515 <div class="mxchat-import-content">
516 <h4><?php esc_html_e('Direct URL', 'mxchat'); ?></h4>
517 <p><?php esc_html_e('Import content from any webpage.', 'mxchat'); ?></p>
518 </div>
519 </button>
520
521 <!-- Direct Content Import Option -->
522 <button type="button" class="mxchat-import-box" data-option="content" data-type="content">
523 <div class="mxchat-import-icon">
524 <span class="dashicons dashicons-editor-paste-text"></span>
525 </div>
526 <div class="mxchat-import-content">
527 <h4><?php esc_html_e('Direct Content', 'mxchat'); ?></h4>
528 <p><?php esc_html_e('Submit content to be vectorized.', 'mxchat'); ?></p>
529 </div>
530 </button>
531
532 <!-- PDF Import Option (URL) -->
533 <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">
534 <div class="mxchat-import-icon">
535 <span class="dashicons dashicons-media-document"></span>
536 </div>
537 <div class="mxchat-import-content">
538 <h4><?php esc_html_e('PDF Import', 'mxchat'); ?></h4>
539 <p><?php esc_html_e('Import knowledge from PDF URL.', 'mxchat'); ?></p>
540 </div>
541 </button>
542
543 <!-- PDF File Upload Option -->
544 <button type="button" class="mxchat-import-box" data-option="pdf-upload" data-type="pdf-upload">
545 <div class="mxchat-import-icon">
546 <span class="dashicons dashicons-upload"></span>
547 </div>
548 <div class="mxchat-import-content">
549 <h4><?php esc_html_e('PDF Upload', 'mxchat'); ?></h4>
550 <p><?php esc_html_e('Upload a PDF file from your computer.', 'mxchat'); ?></p>
551 </div>
552 </button>
553 </div>
554
555 <!-- Detected Sitemaps Section (hidden by default, shown when Sitemap Import is clicked) -->
556 <div id="mxchat-detected-sitemaps" class="mxchat-detected-sitemaps" style="display: none;">
557 <div class="mxchat-sitemaps-header">
558 <h4>
559 <span class="dashicons dashicons-admin-site-alt"></span>
560 <?php esc_html_e('Detected Sitemaps', 'mxchat'); ?>
561 </h4>
562 <button type="button" id="mxchat-refresh-sitemaps" class="mxch-btn mxch-btn-ghost mxch-btn-sm" title="<?php esc_attr_e('Refresh', 'mxchat'); ?>">
563 <span class="dashicons dashicons-update"></span>
564 </button>
565 </div>
566 <div id="mxchat-sitemaps-list" class="mxchat-sitemaps-list">
567 <!-- Sitemaps will be loaded here via AJAX -->
568 </div>
569 <input type="hidden" id="mxchat-detect-sitemaps-nonce" value="<?php echo wp_create_nonce('mxchat_detect_sitemaps_nonce'); ?>">
570 <?php if ($multibot_active && $current_bot_id !== 'default') : ?>
571 <input type="hidden" id="mxchat-sitemap-bot-id" value="<?php echo esc_attr($current_bot_id); ?>">
572 <?php endif; ?>
573 </div>
574
575 <!-- No Sitemaps Found Message (hidden by default) -->
576 <div id="mxchat-no-sitemaps" class="mxchat-no-sitemaps" style="display: none;">
577 <span class="dashicons dashicons-info"></span>
578 <p>
579 <?php esc_html_e('No sitemaps detected. You can manually enter a sitemap URL using the input field above.', 'mxchat'); ?>
580 </p>
581 </div>
582
583 <!-- Sitemaps Loading State (hidden by default) -->
584 <div id="mxchat-sitemaps-loading" class="mxchat-sitemaps-loading" style="display: none;">
585 <span class="dashicons dashicons-update spin"></span>
586 <p><?php esc_html_e('Detecting sitemaps...', 'mxchat'); ?></p>
587 </div>
588
589 <!-- Input Areas for URL and Content -->
590 <?php if (!$is_processing) : ?>
591 <div class="mxchat-import-input-area" id="mxchat-url-input-area" style="display: none; margin-top: 20px;">
592 <form id="mxchat-url-form" method="post" action="<?php echo esc_url(admin_url('admin-post.php?action=mxchat_submit_sitemap')); ?>">
593 <?php wp_nonce_field('mxchat_submit_sitemap_action', 'mxchat_submit_sitemap_nonce'); ?>
594 <input type="hidden" name="import_type" id="import_type" value="url">
595 <?php if ($multibot_active && $current_bot_id !== 'default') : ?>
596 <input type="hidden" name="bot_id" value="<?php echo esc_attr($current_bot_id); ?>">
597 <?php endif; ?>
598 <div style="display: flex; gap: 10px;">
599 <input type="url" name="sitemap_url" id="sitemap_url" class="mxch-input" placeholder="<?php esc_attr_e('Enter URL here', 'mxchat'); ?>" required style="flex: 1;" />
600 <button type="submit" name="submit_sitemap" class="mxch-btn mxch-btn-primary">
601 <?php esc_html_e('Import', 'mxchat'); ?>
602 </button>
603 </div>
604 <p class="mxch-field-description" id="url-description-text"></p>
605 </form>
606 </div>
607
608 <div class="mxchat-import-input-area" id="mxchat-content-input-area" style="display: none; margin-top: 20px;">
609 <form id="mxchat-content-form" method="post" action="<?php echo esc_url(admin_url('admin-post.php?action=mxchat_submit_content')); ?>">
610 <?php wp_nonce_field('mxchat_submit_content_action', 'mxchat_submit_content_nonce'); ?>
611 <?php if ($multibot_active && $current_bot_id !== 'default') : ?>
612 <input type="hidden" name="bot_id" value="<?php echo esc_attr($current_bot_id); ?>">
613 <?php endif; ?>
614 <div class="mxch-field">
615 <textarea name="article_content" id="article_content" class="mxch-textarea" placeholder="<?php esc_attr_e('Enter your content here...', 'mxchat'); ?>" required rows="6"></textarea>
616 </div>
617 <div class="mxch-field">
618 <input type="url" name="article_url" id="article_url" class="mxch-input" placeholder="<?php esc_attr_e('Enter source URL (Optional)', 'mxchat'); ?>">
619 <div style="margin-top: 8px; display: flex; align-items: center; gap: 8px;">
620 <label style="display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--mxch-text-secondary); cursor: pointer;">
621 <input type="checkbox" id="mxchat-unique-url-toggle" style="margin: 0;">
622 <?php esc_html_e('Generate unique URL for duplicate content', 'mxchat'); ?>
623 </label>
624 <button type="button" id="mxchat-generate-unique-url" class="mxch-btn mxch-btn-secondary mxch-btn-sm" style="display: none;">
625 <span class="dashicons dashicons-randomize" style="font-size: 14px; margin-top: 2px;"></span>
626 <?php esc_html_e('Generate Unique', 'mxchat'); ?>
627 </button>
628 </div>
629 <p class="mxch-field-description">
630 <?php esc_html_e('Enable this option to submit multiple entries with the same base URL. A unique reference will be appended.', 'mxchat'); ?>
631 </p>
632 </div>
633 <button type="submit" name="submit_content" class="mxch-btn mxch-btn-primary">
634 <?php esc_html_e('Import Content', 'mxchat'); ?>
635 </button>
636 </form>
637 </div>
638
639 <div class="mxchat-import-input-area" id="mxchat-pdf-upload-area" style="display: none; margin-top: 20px;">
640 <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">
641 <?php wp_nonce_field('mxchat_submit_pdf_file_action', 'mxchat_submit_pdf_file_nonce'); ?>
642 <?php if ($multibot_active && $current_bot_id !== 'default') : ?>
643 <input type="hidden" name="bot_id" value="<?php echo esc_attr($current_bot_id); ?>">
644 <?php endif; ?>
645 <div class="mxch-field">
646 <input type="file" name="pdf_file" id="mxchat-pdf-file-input" accept=".pdf" required>
647 </div>
648 <p class="mxch-field-description">
649 <?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'); ?>
650 </p>
651 <button type="submit" name="submit_pdf_file" class="mxch-btn mxch-btn-primary">
652 <?php esc_html_e('Import PDF', 'mxchat'); ?>
653 </button>
654 </form>
655 </div>
656 <?php endif; ?>
657 </div>
658 </div>
659 </div>
660 <?php
661 }
662
663 /**
664 * Render Processing Status Cards (legacy - kept for reference)
665 * Note: Processing status is now rendered globally via mxchat_render_global_processing_status()
666 */
667 function mxchat_render_processing_status($page_data, $knowledge_manager) {
668 extract($page_data);
669
670 // PDF Processing Status
671 if ($pdf_status && $pdf_status['status'] === 'processing') : ?>
672 <div class="mxch-card" style="margin-top: 20px;">
673 <div class="mxch-card-header" style="background: var(--mxch-primary-light);">
674 <h3 class="mxch-card-title"><?php esc_html_e('PDF Processing Status', 'mxchat'); ?></h3>
675 <div style="display: flex; gap: 10px;">
676 <form method="post" action="<?php echo esc_url(admin_url('admin-post.php?action=mxchat_stop_processing')); ?>">
677 <?php wp_nonce_field('mxchat_stop_processing_action', 'mxchat_stop_processing_nonce'); ?>
678 <button type="submit" name="stop_processing" class="mxch-btn mxch-btn-secondary mxch-btn-sm">
679 <?php esc_html_e('Stop Processing', 'mxchat'); ?>
680 </button>
681 </form>
682 <button type="button" class="mxch-btn mxch-btn-primary mxch-btn-sm mxchat-manual-batch-btn" data-process-type="pdf" data-url="<?php echo esc_attr(get_transient('mxchat_last_pdf_url')); ?>">
683 <?php esc_html_e('Process Batch', 'mxchat'); ?>
684 </button>
685 </div>
686 </div>
687 <div class="mxch-card-body">
688 <div class="mxchat-progress-bar" style="height: 8px; background: #e2e8f0; border-radius: 4px; overflow: hidden; margin-bottom: 15px;">
689 <div class="mxchat-progress-fill" style="height: 100%; background: var(--mxch-primary); width: <?php echo esc_attr($pdf_status['percentage']); ?>%; transition: width 0.3s;"></div>
690 </div>
691 <p><?php printf(esc_html__('Progress: %1$d of %2$d pages (%3$d%%)', 'mxchat'), absint($pdf_status['processed_pages']), absint($pdf_status['total_pages']), absint($pdf_status['percentage'])); ?></p>
692 <?php if (!empty($pdf_status['failed_pages']) && $pdf_status['failed_pages'] > 0) : ?>
693 <p><strong><?php esc_html_e('Failed pages:', 'mxchat'); ?></strong> <?php echo esc_html($pdf_status['failed_pages']); ?></p>
694 <?php endif; ?>
695 <p><strong><?php esc_html_e('Last update:', 'mxchat'); ?></strong> <?php echo esc_html($pdf_status['last_update']); ?></p>
696 </div>
697 </div>
698 <?php endif;
699
700 // Sitemap Processing Status
701 if ($sitemap_status && $sitemap_status['status'] === 'processing') : ?>
702 <div class="mxch-card" style="margin-top: 20px;">
703 <div class="mxch-card-header" style="background: var(--mxch-primary-light);">
704 <h3 class="mxch-card-title"><?php esc_html_e('Sitemap Processing Status', 'mxchat'); ?></h3>
705 <div style="display: flex; gap: 10px;">
706 <form method="post" action="<?php echo esc_url(admin_url('admin-post.php?action=mxchat_stop_processing')); ?>">
707 <?php wp_nonce_field('mxchat_stop_processing_action', 'mxchat_stop_processing_nonce'); ?>
708 <button type="submit" name="stop_processing" class="mxch-btn mxch-btn-secondary mxch-btn-sm">
709 <?php esc_html_e('Stop Processing', 'mxchat'); ?>
710 </button>
711 </form>
712 <button type="button" class="mxch-btn mxch-btn-primary mxch-btn-sm mxchat-manual-batch-btn" data-process-type="sitemap" data-url="<?php echo esc_attr(get_transient('mxchat_last_sitemap_url')); ?>">
713 <?php esc_html_e('Process Batch', 'mxchat'); ?>
714 </button>
715 </div>
716 </div>
717 <div class="mxch-card-body">
718 <div class="mxchat-progress-bar" style="height: 8px; background: #e2e8f0; border-radius: 4px; overflow: hidden; margin-bottom: 15px;">
719 <div class="mxchat-progress-fill" style="height: 100%; background: var(--mxch-primary); width: <?php echo esc_attr($sitemap_status['percentage']); ?>%; transition: width 0.3s;"></div>
720 </div>
721 <p><?php printf(esc_html__('Progress: %1$d of %2$d URLs (%3$d%%)', 'mxchat'), absint($sitemap_status['processed_urls']), absint($sitemap_status['total_urls']), absint($sitemap_status['percentage'])); ?></p>
722 <?php if (!empty($sitemap_status['failed_urls']) && $sitemap_status['failed_urls'] > 0) : ?>
723 <p><strong><?php esc_html_e('Failed URLs:', 'mxchat'); ?></strong> <?php echo esc_html($sitemap_status['failed_urls']); ?></p>
724 <?php endif; ?>
725 <p><strong><?php esc_html_e('Last update:', 'mxchat'); ?></strong> <?php echo esc_html($sitemap_status['last_update']); ?></p>
726 </div>
727 </div>
728 <?php endif;
729
730 // Completed status cards
731 echo $knowledge_manager->mxchat_render_completed_status_cards();
732 }
733
734 /**
735 * Render Knowledge Base Section (table)
736 */
737 function mxchat_render_knowledge_base_section($admin_instance, $knowledge_manager, $page_data) {
738 extract($page_data);
739
740 // Group prompts by source_url for chunked content display
741 $grouped_prompts = array();
742
743 if ($prompts) {
744 foreach ($prompts as $prompt) {
745 $source_url = $prompt->source_url ?? '';
746
747 // Check if chunk metadata exists on the record itself (Pinecone)
748 if (isset($prompt->chunk_index) && $prompt->chunk_index !== null) {
749 // Pinecone: metadata is already on the record object
750 $prompt->chunk_metadata = array(
751 'chunk_index' => intval($prompt->chunk_index),
752 'total_chunks' => isset($prompt->total_chunks) ? intval($prompt->total_chunks) : null,
753 'is_chunked' => isset($prompt->is_chunked) ? (bool) $prompt->is_chunked : true
754 );
755 $prompt->display_content = $prompt->article_content; // Pinecone content is already clean
756 } else {
757 // WordPress: Parse chunk metadata from JSON prefix in article_content
758 if (class_exists('MxChat_Chunker')) {
759 $chunk_meta = MxChat_Chunker::parse_stored_chunk($prompt->article_content);
760 $prompt->chunk_metadata = $chunk_meta['metadata'];
761 $prompt->display_content = $chunk_meta['text']; // Store clean content without JSON prefix
762 } else {
763 $prompt->chunk_metadata = array();
764 $prompt->display_content = $prompt->article_content;
765 }
766 }
767
768 if (!empty($source_url)) {
769 if (!isset($grouped_prompts[$source_url])) {
770 $grouped_prompts[$source_url] = array();
771 }
772 $grouped_prompts[$source_url][] = $prompt;
773 } else {
774 // Use a unique key for ungrouped prompts
775 $grouped_prompts['_ungrouped_' . $prompt->id] = array($prompt);
776 }
777 }
778
779 // Sort each group by chunk_index from metadata
780 foreach ($grouped_prompts as $source_url => &$group) {
781 usort($group, function($a, $b) {
782 $index_a = isset($a->chunk_metadata['chunk_index']) ? intval($a->chunk_metadata['chunk_index']) : 0;
783 $index_b = isset($b->chunk_metadata['chunk_index']) ? intval($b->chunk_metadata['chunk_index']) : 0;
784 return $index_a - $index_b;
785 });
786 }
787 unset($group); // Break reference
788 }
789 $display_index = 0;
790 ?>
791 <div id="knowledge-base" class="mxch-section">
792 <div class="mxch-content-header">
793 <h1 class="mxch-content-title"><?php esc_html_e('Knowledge Base', 'mxchat'); ?></h1>
794 <p class="mxch-content-subtitle"><?php esc_html_e('View and manage your imported knowledge entries.', 'mxchat'); ?></p>
795 </div>
796
797 <?php if (!empty($use_vectorstore)) : ?>
798 <div class="mxch-notice mxch-notice-info" style="margin-bottom: 20px;">
799 <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>
800 <span><strong><?php esc_html_e('OpenAI Vector Store is Active', 'mxchat'); ?></strong> - <?php esc_html_e('Your chatbot is using OpenAI\'s hosted Vector Store for knowledge retrieval. The entries below are stored locally and are not being searched. To use this local database, disable Vector Store in the Integrations settings.', 'mxchat'); ?></span>
801 </div>
802 <?php endif; ?>
803
804 <div class="mxch-card">
805 <div class="mxch-card-header">
806 <h3 class="mxch-card-title">
807 <?php esc_html_e('Knowledge Entries', 'mxchat'); ?>
808 <span id="mxchat-entry-count" style="font-weight: normal; color: var(--mxch-text-secondary);">(<?php echo esc_html($total_records); ?>)</span>
809 <?php if (!empty($use_vectorstore)) : ?>
810 <span style="display: inline-flex; align-items: center; gap: 4px; padding: 4px 8px; border-radius: 12px; font-size: 12px; font-weight: 500; margin-left: 8px; background: #fff3e0; color: #e65100;">
811 <span class="dashicons dashicons-database" style="font-size: 14px;"></span>
812 <?php esc_html_e('Not in use', 'mxchat'); ?>
813 </span>
814 <?php elseif ($use_pinecone) : ?>
815 <span style="display: inline-flex; align-items: center; gap: 4px; padding: 4px 8px; border-radius: 12px; font-size: 12px; font-weight: 500; margin-left: 8px; background: #e3f2fd; color: #1976d2;">
816 <span class="dashicons dashicons-cloud" style="font-size: 14px;"></span>
817 <?php esc_html_e('Pinecone', 'mxchat'); ?>
818 </span>
819 <?php else : ?>
820 <span style="display: inline-flex; align-items: center; gap: 4px; padding: 4px 8px; border-radius: 12px; font-size: 12px; font-weight: 500; margin-left: 8px; background: #f3e5f5; color: #7b1fa2;">
821 <span class="dashicons dashicons-database-view" style="font-size: 14px;"></span>
822 <?php esc_html_e('WordPress DB', 'mxchat'); ?>
823 </span>
824 <?php endif; ?>
825 </h3>
826 <div class="mxch-kb-header-controls">
827 <form method="get" id="knowledge-search" class="mxch-kb-search-form">
828 <?php wp_nonce_field('mxchat_prompts_search_nonce'); ?>
829 <input type="hidden" name="page" value="mxchat-prompts" />
830 <?php if ($multibot_active && !empty($current_bot_id) && $current_bot_id !== 'default') : ?>
831 <input type="hidden" name="bot_id" value="<?php echo esc_attr($current_bot_id); ?>" />
832 <?php endif; ?>
833 <input type="text" name="search" class="mxch-input mxch-input-sm mxch-kb-search-input" placeholder="<?php esc_attr_e('Search...', 'mxchat'); ?>" value="<?php echo esc_attr($search_query); ?>" />
834 <select name="content_type" class="mxch-select mxch-kb-type-filter" onchange="this.form.submit()">
835 <option value=""><?php esc_html_e('All Types', 'mxchat'); ?></option>
836 <?php
837 $post_types = get_post_types(array('public' => true), 'objects');
838 foreach ($post_types as $post_type) {
839 echo '<option value="' . esc_attr($post_type->name) . '" ' . selected($content_type_filter, $post_type->name, false) . '>' . esc_html($post_type->label) . '</option>';
840 }
841 ?>
842 <option value="pdf" <?php selected($content_type_filter, 'pdf'); ?>><?php esc_html_e('PDFs', 'mxchat'); ?></option>
843 <option value="url" <?php selected($content_type_filter, 'url'); ?>><?php esc_html_e('URLs', 'mxchat'); ?></option>
844 </select>
845 </form>
846 <!-- Delete Button Container - transforms between Delete All and Delete Selected -->
847 <div class="mxchat-delete-container" id="mxchat-delete-container">
848 <!-- Delete All Form (shown when nothing selected) -->
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'); ?>');">
850 <?php wp_nonce_field('mxchat_delete_all_prompts_action', 'mxchat_delete_all_prompts_nonce'); ?>
851 <input type="hidden" name="data_source" value="<?php echo esc_attr($data_source); ?>" />
852 <input type="hidden" name="bot_id" value="<?php echo esc_attr($current_bot_id); ?>" />
853 <button type="submit" class="mxch-btn mxch-btn-secondary mxch-btn-sm" style="color: var(--mxch-error);">
854 <span class="dashicons dashicons-trash" style="font-size: 14px;"></span>
855 <?php esc_html_e('Delete All', 'mxchat'); ?>
856 </button>
857 </form>
858 <!-- Delete Selected Button (shown when items selected) -->
859 <button type="button"
860 class="mxch-btn mxch-btn-secondary mxch-btn-sm mxchat-bulk-delete"
861 id="mxchat-delete-selected-entries"
862 style="display: none; color: var(--mxch-error);"
863 data-nonce="<?php echo wp_create_nonce('mxchat_bulk_delete_knowledge_nonce'); ?>"
864 data-bot-id="<?php echo esc_attr($current_bot_id); ?>"
865 data-data-source="<?php echo esc_attr($data_source); ?>">
866 <span class="dashicons dashicons-trash" style="font-size: 14px;"></span>
867 <span class="mxchat-bulk-delete-text"><?php esc_html_e('Delete Selected', 'mxchat'); ?></span>
868 <span class="mxchat-selected-count" id="mxchat-selected-entry-count"></span>
869 </button>
870 </div>
871 </div>
872 </div>
873 <div class="mxch-card-body" style="padding: 0;">
874 <?php if ($use_pinecone) : ?>
875 <div class="mxch-notice mxch-notice-info mxch-pinecone-notice" style="margin: 16px; border-radius: var(--mxch-radius-md); display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px;">
876 <div style="display: flex; align-items: center; gap: 8px;">
877 <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>
878 <span><?php esc_html_e('Changes may take up to 60 seconds to process in Pinecone. Click "Refresh Entries" to see updates.', 'mxchat'); ?></span>
879 </div>
880 <button type="button" id="mxchat-refresh-pinecone-entries" class="mxch-btn mxch-btn-secondary mxch-btn-sm">
881 <span class="dashicons dashicons-update"></span>
882 <?php esc_html_e('Refresh Entries', 'mxchat'); ?>
883 </button>
884 </div>
885 <?php endif; ?>
886
887 <div class="mxchat-table-wrapper" style="overflow-x: auto;">
888 <table class="mxchat-records-table" id="mxchat-records-table" style="width: 100%; border-collapse: collapse;">
889 <thead>
890 <tr style="background: #f8fafc; border-bottom: 1px solid var(--mxch-card-border);">
891 <th style="padding: 12px 16px; width: 40px; text-align: center;">
892 <input type="checkbox" id="mxchat-select-all-entries" class="mxchat-entry-checkbox-all" title="<?php esc_attr_e('Select All', 'mxchat'); ?>">
893 </th>
894 <th style="padding: 12px 16px; text-align: left; font-weight: 600; color: var(--mxch-text-secondary); font-size: 12px; text-transform: uppercase;"><?php esc_html_e('ID', 'mxchat'); ?></th>
895 <th style="padding: 12px 16px; text-align: left; font-weight: 600; color: var(--mxch-text-secondary); font-size: 12px; text-transform: uppercase;"><?php esc_html_e('Content', 'mxchat'); ?></th>
896 <th style="padding: 12px 16px; text-align: left; font-weight: 600; color: var(--mxch-text-secondary); font-size: 12px; text-transform: uppercase;"><?php esc_html_e('Source', 'mxchat'); ?></th>
897 <th style="padding: 12px 16px; text-align: left; font-weight: 600; color: var(--mxch-text-secondary); font-size: 12px; text-transform: uppercase;"><?php esc_html_e('Actions', 'mxchat'); ?></th>
898 </tr>
899 </thead>
900 <tbody id="mxchat-entries-tbody">
901 <?php if (empty($grouped_prompts)) : ?>
902 <tr>
903 <td colspan="5" style="padding: 40px; text-align: center; color: var(--mxch-text-muted);">
904 <?php esc_html_e('No knowledge entries found. Use the Import Options to add content.', 'mxchat'); ?>
905 </td>
906 </tr>
907 <?php else : ?>
908 <?php
909 // Display grouped prompts
910 foreach ($grouped_prompts as $source_url => $group) :
911 $chunk_count = count($group);
912 $first_prompt = $group[0];
913 $display_index++;
914
915 if ($chunk_count > 1) :
916 // Multiple chunks - show grouped row with expand button
917 $group_id = 'group-' . md5($source_url);
918 ?>
919 <tr id="prompt-<?php echo esc_attr($first_prompt->id); ?>"
920 class="mxchat-chunk-group-header"
921 data-source="<?php echo esc_attr($data_source); ?>"
922 data-group-id="<?php echo esc_attr($group_id); ?>"
923 style="border-bottom: 1px solid var(--mxch-card-border); <?php if ($data_source === 'pinecone') echo 'background: rgba(33, 150, 243, 0.02);'; ?>">
924 <td style="padding: 12px 16px; text-align: center;">
925 <input type="checkbox"
926 class="mxchat-entry-checkbox"
927 data-entry-id="<?php echo esc_attr($first_prompt->id); ?>"
928 data-source="<?php echo esc_attr($data_source); ?>"
929 data-source-url="<?php echo esc_attr($source_url); ?>"
930 data-is-group="true"
931 data-chunk-count="<?php echo esc_attr($chunk_count); ?>">
932 </td>
933 <td style="padding: 12px 16px; font-size: 13px;">
934 <?php if ($data_source === 'pinecone') : ?>
935 <?php echo esc_html($display_index + (($current_page - 1) * $per_page)); ?>
936 <?php else : ?>
937 <?php echo esc_html($first_prompt->id); ?>
938 <?php endif; ?>
939 </td>
940 <td class="mxchat-content-cell" style="padding: 12px 16px; font-size: 13px;">
941 <div class="mxchat-chunk-group-info">
942 <button type="button" class="mxchat-chunk-toggle" data-group-id="<?php echo esc_attr($group_id); ?>">
943 <span class="dashicons dashicons-arrow-right-alt2"></span>
944 </button>
945 <span class="mxchat-chunk-badge"><?php echo esc_html($chunk_count); ?> <?php esc_html_e('chunks', 'mxchat'); ?></span>
946 <span class="mxchat-chunk-preview">
947 <?php
948 $parent_content = isset($first_prompt->display_content) ? $first_prompt->display_content : $first_prompt->article_content;
949 $content_preview = mb_substr($parent_content, 0, 100);
950 echo esc_html($content_preview . '...');
951 ?>
952 </span>
953 </div>
954 </td>
955 <td class="mxchat-url-cell" style="padding: 12px 16px; font-size: 13px;">
956 <?php if (!empty($source_url) && strpos($source_url, 'mxchat://') !== 0 && strpos($source_url, '_ungrouped_') !== 0) : ?>
957 <a href="<?php echo esc_url($source_url); ?>" target="_blank" style="color: var(--mxch-primary); text-decoration: none;">
958 <span class="dashicons dashicons-external" style="font-size: 14px;"></span>
959 <?php esc_html_e('View Source', 'mxchat'); ?>
960 </a>
961 <?php else : ?>
962 <span style="color: var(--mxch-text-muted);"><?php esc_html_e('Manual Content', 'mxchat'); ?></span>
963 <?php endif; ?>
964 </td>
965 <td class="mxchat-actions-cell" style="padding: 12px 16px;">
966 <button type="button"
967 class="mxch-btn mxch-btn-ghost mxch-btn-sm delete-button-group"
968 data-source-url="<?php echo esc_attr($source_url); ?>"
969 data-chunk-count="<?php echo esc_attr($chunk_count); ?>"
970 data-data-source="<?php echo esc_attr($data_source); ?>"
971 data-bot-id="<?php echo esc_attr($current_bot_id); ?>"
972 data-nonce="<?php echo wp_create_nonce('mxchat_delete_chunks_nonce'); ?>"
973 style="color: var(--mxch-error);"
974 title="<?php esc_attr_e('Delete all chunks', 'mxchat'); ?>">
975 <span class="dashicons dashicons-trash" style="font-size: 14px;"></span>
976 </button>
977 </td>
978 </tr>
979 <?php
980 // Render hidden chunk rows
981 foreach ($group as $chunk_index => $prompt) :
982 $meta_chunk_index = isset($prompt->chunk_metadata['chunk_index']) ? intval($prompt->chunk_metadata['chunk_index']) : $chunk_index;
983 $meta_total_chunks = isset($prompt->chunk_metadata['total_chunks']) ? intval($prompt->chunk_metadata['total_chunks']) : $chunk_count;
984 $content = isset($prompt->display_content) ? $prompt->display_content : $prompt->article_content;
985 $preview_length = 150;
986 $content_preview = mb_strlen($content) > $preview_length
987 ? mb_substr($content, 0, $preview_length) . '...'
988 : $content;
989 ?>
990 <tr id="prompt-<?php echo esc_attr($prompt->id); ?>"
991 class="mxchat-chunk-row <?php echo esc_attr($group_id); ?>"
992 data-source="<?php echo esc_attr($data_source); ?>"
993 style="display: none; background: #f8f9fa; border-bottom: 1px solid var(--mxch-card-border);">
994 <td style="padding: 12px 16px; text-align: center;">
995 <!-- Checkbox placeholder for chunk rows -->
996 </td>
997 <td style="padding: 12px 16px 12px 30px; font-size: 13px;">
998 <!-- Hidden ID column for chunks -->
999 </td>
1000 <td class="mxchat-content-cell" style="padding: 12px 16px; font-size: 13px;">
1001 <div class="mxchat-accordion-wrapper">
1002 <div class="mxchat-content-preview">
1003 <span class="mxchat-chunk-indicator" style="margin-right: 10px; color: var(--mxch-text-secondary); font-size: 12px;">
1004 <?php printf(esc_html__('Chunk %d of %d', 'mxchat'), $meta_chunk_index + 1, $meta_total_chunks); ?>
1005 </span>
1006 <span class="preview-text"><?php echo esc_html($content_preview); ?></span>
1007 <?php if (mb_strlen($content) > $preview_length) : ?>
1008 <button class="mxchat-expand-toggle" type="button">
1009 <span class="dashicons dashicons-arrow-down-alt2"></span>
1010 </button>
1011 <?php endif; ?>
1012 </div>
1013 <div class="mxchat-content-full" style="display: none;">
1014 <div class="content-view">
1015 <?php
1016 if (preg_match('/[\x{0590}-\x{05FF}]/u', $content)) {
1017 echo '<div dir="rtl" lang="he" class="rtl-content">';
1018 echo wp_kses_post(wpautop($content));
1019 echo '</div>';
1020 } else {
1021 echo wp_kses_post(wpautop($content));
1022 }
1023 ?>
1024 </div>
1025 </div>
1026 </div>
1027 </td>
1028 <td class="mxchat-url-cell" style="padding: 12px 16px; font-size: 13px;">
1029 <span class="mxchat-chunk-label" style="color: var(--mxch-text-muted);"><?php esc_html_e('Same as parent', 'mxchat'); ?></span>
1030 </td>
1031 <td class="mxchat-actions-cell" style="padding: 12px 16px;">
1032 <span class="mxchat-chunk-label" style="color: var(--mxch-text-muted);"><?php esc_html_e('Managed by group', 'mxchat'); ?></span>
1033 </td>
1034 </tr>
1035 <?php endforeach; ?>
1036 <?php else :
1037 // Single entry - display normally with accordion
1038 $prompt = $first_prompt;
1039 $content = isset($prompt->display_content) ? $prompt->display_content : $prompt->article_content;
1040 $preview_length = 150;
1041 $content_preview = mb_strlen($content) > $preview_length
1042 ? mb_substr($content, 0, $preview_length) . '...'
1043 : $content;
1044 ?>
1045 <tr id="prompt-<?php echo esc_attr($prompt->id); ?>"
1046 data-source="<?php echo esc_attr($data_source); ?>"
1047 style="border-bottom: 1px solid var(--mxch-card-border); <?php if ($data_source === 'pinecone') echo 'background: rgba(33, 150, 243, 0.02);'; ?>">
1048 <td style="padding: 12px 16px; text-align: center;">
1049 <input type="checkbox"
1050 class="mxchat-entry-checkbox"
1051 data-entry-id="<?php echo esc_attr($prompt->id); ?>"
1052 data-source="<?php echo esc_attr($data_source); ?>"
1053 data-source-url="<?php echo esc_attr($source_url); ?>"
1054 data-is-group="false">
1055 </td>
1056 <td style="padding: 12px 16px; font-size: 13px;">
1057 <?php if ($data_source === 'pinecone') : ?>
1058 <?php echo esc_html($display_index + (($current_page - 1) * $per_page)); ?>
1059 <?php else : ?>
1060 <?php echo esc_html($prompt->id); ?>
1061 <?php endif; ?>
1062 </td>
1063 <td class="mxchat-content-cell" style="padding: 12px 16px; font-size: 13px;">
1064 <div class="mxchat-accordion-wrapper">
1065 <div class="mxchat-content-preview">
1066 <span class="preview-text"><?php echo esc_html($content_preview); ?></span>
1067 <?php if (mb_strlen($content) > $preview_length) : ?>
1068 <button class="mxchat-expand-toggle" type="button">
1069 <span class="dashicons dashicons-arrow-down-alt2"></span>
1070 </button>
1071 <?php endif; ?>
1072 </div>
1073 <div class="mxchat-content-full" style="display: none;">
1074 <div class="content-view">
1075 <?php
1076 if (preg_match('/[\x{0590}-\x{05FF}]/u', $content)) {
1077 echo '<div dir="rtl" lang="he" class="rtl-content">';
1078 echo wp_kses_post(wpautop($content));
1079 echo '</div>';
1080 } else {
1081 echo wp_kses_post(wpautop($content));
1082 }
1083 ?>
1084 </div>
1085 </div>
1086 </div>
1087 </td>
1088 <td class="mxchat-url-cell" style="padding: 12px 16px; font-size: 13px;">
1089 <?php
1090 $actual_source = $source_url;
1091 if (strpos($source_url, '_ungrouped_') === 0) {
1092 $actual_source = $prompt->source_url ?? '';
1093 }
1094 if (!empty($actual_source) && strpos($actual_source, 'mxchat://') !== 0) : ?>
1095 <a href="<?php echo esc_url($actual_source); ?>" target="_blank" style="color: var(--mxch-primary); text-decoration: none;">
1096 <span class="dashicons dashicons-external" style="font-size: 14px;"></span>
1097 <?php esc_html_e('View', 'mxchat'); ?>
1098 </a>
1099 <?php else : ?>
1100 <span style="color: var(--mxch-text-muted);"><?php esc_html_e('Manual', 'mxchat'); ?></span>
1101 <?php endif; ?>
1102 </td>
1103 <td style="padding: 12px 16px;">
1104 <?php if ($data_source === 'pinecone') : ?>
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);">
1106 <span class="dashicons dashicons-trash" style="font-size: 14px;"></span>
1107 </button>
1108 <?php else : ?>
1109 <button type="button" class="mxch-btn mxch-btn-ghost mxch-btn-sm delete-button-wordpress" data-entry-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_wordpress_prompt_nonce'); ?>" style="color: var(--mxch-error);">
1110 <span class="dashicons dashicons-trash" style="font-size: 14px;"></span>
1111 </button>
1112 <?php endif; ?>
1113 </td>
1114 </tr>
1115 <?php endif; ?>
1116 <?php endforeach; ?>
1117 <?php endif; ?>
1118 </tbody>
1119 </table>
1120 </div>
1121
1122 <!-- Pagination wrapper - always present so JS can populate it after processing -->
1123 <div id="mxchat-kb-pagination" class="mxchat-kb-pagination-wrapper" style="<?php echo $total_pages > 1 ? 'padding: 16px; border-top: 1px solid var(--mxch-card-border); text-align: center;' : ''; ?>" data-current-page="<?php echo esc_attr($current_page); ?>" data-total-pages="<?php echo esc_attr($total_pages); ?>" data-search="<?php echo esc_attr($search_query); ?>" data-content-type="<?php echo esc_attr($content_type_filter); ?>">
1124 <?php if ($total_pages > 1) : ?>
1125 <div class="mxchat-ajax-pagination" data-current-page="<?php echo esc_attr($current_page); ?>" data-total-pages="<?php echo esc_attr($total_pages); ?>">
1126 <?php if ($current_page > 1) : ?>
1127 <a href="#" class="mxchat-page-link" data-page="<?php echo ($current_page - 1); ?>"><?php esc_html_e('&laquo; Previous', 'mxchat'); ?></a>
1128 <?php endif; ?>
1129
1130 <?php
1131 $start_page = max(1, $current_page - 2);
1132 $end_page = min($total_pages, $current_page + 2);
1133
1134 if ($start_page > 1) {
1135 echo '<a href="#" class="mxchat-page-link" data-page="1">1</a> ';
1136 if ($start_page > 2) {
1137 echo '<span class="mxchat-page-dots">...</span> ';
1138 }
1139 }
1140
1141 for ($i = $start_page; $i <= $end_page; $i++) {
1142 if ($i == $current_page) {
1143 echo '<span class="mxchat-page-current">' . $i . '</span> ';
1144 } else {
1145 echo '<a href="#" class="mxchat-page-link" data-page="' . $i . '">' . $i . '</a> ';
1146 }
1147 }
1148
1149 if ($end_page < $total_pages) {
1150 if ($end_page < $total_pages - 1) {
1151 echo '<span class="mxchat-page-dots">...</span> ';
1152 }
1153 echo '<a href="#" class="mxchat-page-link" data-page="' . $total_pages . '">' . $total_pages . '</a> ';
1154 }
1155 ?>
1156
1157 <?php if ($current_page < $total_pages) : ?>
1158 <a href="#" class="mxchat-page-link" data-page="<?php echo ($current_page + 1); ?>"><?php esc_html_e('Next &raquo;', 'mxchat'); ?></a>
1159 <?php endif; ?>
1160 </div>
1161 <?php endif; ?>
1162 </div>
1163 </div>
1164 </div>
1165 </div>
1166 <?php
1167 }
1168
1169 /**
1170 * Render Auto-Sync Section
1171 */
1172 function mxchat_render_auto_sync_section($knowledge_manager) {
1173 ?>
1174 <div id="auto-sync" class="mxch-section">
1175 <div class="mxch-content-header">
1176 <h1 class="mxch-content-title"><?php esc_html_e('Auto-Sync Settings', 'mxchat'); ?></h1>
1177 <p class="mxch-content-subtitle"><?php esc_html_e('Automatically sync WordPress content to your knowledge base when published or updated.', 'mxchat'); ?></p>
1178 </div>
1179
1180 <div class="mxch-card">
1181 <div class="mxch-card-body mxchat-autosave-section">
1182 <div class="mxch-field">
1183 <div style="display: flex; align-items: center; gap: 12px; margin-bottom: 16px;">
1184 <label class="mxchat-toggle-switch">
1185 <input type="checkbox" name="mxchat_auto_sync_posts" class="mxchat-autosave-field" value="1" data-nonce="<?php echo wp_create_nonce('mxchat_prompts_setting_nonce'); ?>" <?php checked(get_option('mxchat_auto_sync_posts', '0'), '1'); ?>>
1186 <span class="mxchat-toggle-slider"></span>
1187 </label>
1188 <span style="font-weight: 500;"><?php esc_html_e('Auto-sync Posts', 'mxchat'); ?></span>
1189 </div>
1190 <div style="display: flex; align-items: center; gap: 12px;">
1191 <label class="mxchat-toggle-switch">
1192 <input type="checkbox" name="mxchat_auto_sync_pages" class="mxchat-autosave-field" value="1" data-nonce="<?php echo wp_create_nonce('mxchat_prompts_setting_nonce'); ?>" <?php checked(get_option('mxchat_auto_sync_pages', '0'), '1'); ?>>
1193 <span class="mxchat-toggle-slider"></span>
1194 </label>
1195 <span style="font-weight: 500;"><?php esc_html_e('Auto-sync Pages', 'mxchat'); ?></span>
1196 </div>
1197 </div>
1198
1199 <div style="margin-top: 24px;">
1200 <button id="mxchat-custom-post-types-toggle" class="mxch-btn mxch-btn-secondary">
1201 <?php esc_html_e('Advanced Custom Post Sync Settings', 'mxchat'); ?>
1202 <span style="margin-left: 5px;"></span>
1203 </button>
1204 <div id="mxchat-custom-post-types-container" style="display: none; margin-top: 16px; padding: 16px; background: #f8fafc; border-radius: var(--mxch-radius-md);">
1205 <h4 style="margin: 0 0 12px 0;"><?php esc_html_e('Sync Custom Post Types', 'mxchat'); ?></h4>
1206 <?php
1207 $post_types = $knowledge_manager->mxchat_get_public_post_types();
1208 unset($post_types['post'], $post_types['page']);
1209
1210 if (!empty($post_types)) {
1211 foreach ($post_types as $post_type => $label) {
1212 $option_name = 'mxchat_auto_sync_' . $post_type;
1213 $is_enabled = get_option($option_name, '0');
1214 ?>
1215 <div style="display: flex; align-items: center; gap: 12px; margin-bottom: 8px;">
1216 <label class="mxchat-toggle-switch">
1217 <input type="checkbox" name="<?php echo esc_attr($option_name); ?>" class="mxchat-autosave-field" value="1" data-nonce="<?php echo wp_create_nonce('mxchat_prompts_setting_nonce'); ?>" <?php checked($is_enabled, '1'); ?>>
1218 <span class="mxchat-toggle-slider"></span>
1219 </label>
1220 <span><?php echo esc_html($label); ?> (<?php echo esc_html($post_type); ?>)</span>
1221 </div>
1222 <?php
1223 }
1224 } else {
1225 echo '<p style="color: var(--mxch-text-muted);">' . esc_html__('No custom post types found.', 'mxchat') . '</p>';
1226 }
1227 ?>
1228 </div>
1229 </div>
1230 </div>
1231 </div>
1232 </div>
1233 <?php
1234 }
1235
1236 /**
1237 * Render Chunking Section
1238 */
1239 function mxchat_render_chunking_section() {
1240 $chunking_settings = MxChat_Chunker::get_settings();
1241 $chunking_enabled = $chunking_settings['chunking_enabled'];
1242 $chunk_size = $chunking_settings['chunk_size'];
1243 ?>
1244 <div id="chunking" class="mxch-section">
1245 <div class="mxch-content-header">
1246 <h1 class="mxch-content-title"><?php esc_html_e('Content Chunking', 'mxchat'); ?></h1>
1247 <p class="mxch-content-subtitle"><?php esc_html_e('Split large content into smaller segments for more accurate semantic search.', 'mxchat'); ?></p>
1248 </div>
1249
1250 <div class="mxch-card">
1251 <div class="mxch-card-body mxchat-autosave-section">
1252 <div class="mxch-notice mxch-notice-info" style="margin-bottom: 20px;">
1253 <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>
1254 <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>
1255 </div>
1256
1257 <div class="mxch-field">
1258 <div style="display: flex; align-items: center; gap: 12px; margin-bottom: 20px;">
1259 <label class="mxchat-toggle-switch">
1260 <input type="checkbox" name="mxchat_chunking_enabled" id="mxchat_chunking_enabled" class="mxchat-autosave-field" value="1" data-option-name="mxchat_chunking_enabled" data-nonce="<?php echo wp_create_nonce('mxchat_prompts_setting_nonce'); ?>" <?php checked($chunking_enabled, true); ?>>
1261 <span class="mxchat-toggle-slider"></span>
1262 </label>
1263 <span style="font-weight: 500;"><?php esc_html_e('Enable Content Chunking', 'mxchat'); ?></span>
1264 </div>
1265 </div>
1266
1267 <div class="mxch-field">
1268 <label class="mxch-field-label" for="mxchat_chunk_size"><?php esc_html_e('Chunk Size (characters)', 'mxchat'); ?></label>
1269 <input type="number" name="mxchat_chunk_size" id="mxchat_chunk_size" class="mxch-input mxchat-autosave-field" value="<?php echo esc_attr($chunk_size); ?>" min="1000" max="10000" step="500" data-option-name="mxchat_chunk_size" data-nonce="<?php echo wp_create_nonce('mxchat_prompts_setting_nonce'); ?>" style="max-width: 200px;">
1270 <p class="mxch-field-description"><?php esc_html_e('Recommended: 4000 characters (~1000 tokens). Range: 1000-10000. Larger chunks preserve more context.', 'mxchat'); ?></p>
1271 </div>
1272 </div>
1273 </div>
1274 </div>
1275 <?php
1276 }
1277
1278 /**
1279 * Render Role Restrictions Section
1280 */
1281 function mxchat_render_role_restrictions_section($knowledge_manager) {
1282 $role_options = array(
1283 'public' => __('Public (Everyone)', 'mxchat'),
1284 'logged_in' => __('Logged In Users', 'mxchat'),
1285 'subscriber' => __('Subscribers & Above', 'mxchat'),
1286 'contributor' => __('Contributors & Above', 'mxchat'),
1287 'author' => __('Authors & Above', 'mxchat'),
1288 'editor' => __('Editors & Above', 'mxchat'),
1289 'administrator' => __('Administrators Only', 'mxchat')
1290 );
1291 ?>
1292 <div id="role-restrictions" class="mxch-section">
1293 <div class="mxch-content-header">
1294 <h1 class="mxch-content-title"><?php esc_html_e('Role-Based Content Restrictions', 'mxchat'); ?></h1>
1295 <p class="mxch-content-subtitle"><?php esc_html_e('Automatically restrict content access based on WordPress tags.', 'mxchat'); ?></p>
1296 </div>
1297
1298 <div class="mxch-card">
1299 <div class="mxch-card-body">
1300 <div class="mxch-notice mxch-notice-info" style="margin-bottom: 20px;">
1301 <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>
1302 <span><strong><?php esc_html_e('How it works:', 'mxchat'); ?></strong> <?php esc_html_e('Add a tag below and select which role should have access. Content with that tag will be restricted to that role level.', 'mxchat'); ?></span>
1303 </div>
1304
1305 <h4 style="margin: 0 0 16px 0;"><?php esc_html_e('Add Tag-Role Mapping', 'mxchat'); ?></h4>
1306 <div style="display: flex; gap: 15px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 24px;">
1307 <div class="mxch-field" style="flex: 1; min-width: 200px; margin-bottom: 0;">
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'); ?>">
1310 </div>
1311 <div class="mxch-field" style="flex: 1; min-width: 200px; margin-bottom: 0;">
1312 <label class="mxch-field-label" for="mxchat-role-select"><?php esc_html_e('Required Role', 'mxchat'); ?></label>
1313 <select id="mxchat-role-select" class="mxch-select">
1314 <?php foreach ($role_options as $role_key => $role_label) : ?>
1315 <option value="<?php echo esc_attr($role_key); ?>"><?php echo esc_html($role_label); ?></option>
1316 <?php endforeach; ?>
1317 </select>
1318 </div>
1319 <button type="button" id="mxchat-add-tag-role" class="mxch-btn mxch-btn-primary">
1320 <span class="dashicons dashicons-plus-alt" style="font-size: 16px;"></span>
1321 <?php esc_html_e('Add Mapping', 'mxchat'); ?>
1322 </button>
1323 </div>
1324
1325 <h4 style="margin: 24px 0 16px 0;"><?php esc_html_e('Current Tag-Role Mappings', 'mxchat'); ?></h4>
1326 <div id="mxchat-mappings-container">
1327 <div class="mxchat-loading-mappings" style="text-align: center; padding: 20px; color: var(--mxch-text-muted);">
1328 <?php esc_html_e('Loading mappings...', 'mxchat'); ?>
1329 </div>
1330 </div>
1331 <div id="mxchat-no-mappings" style="display: none; text-align: center; padding: 40px; color: var(--mxch-text-muted);">
1332 <span class="dashicons dashicons-tag" style="font-size: 48px; opacity: 0.3;"></span>
1333 <p><?php esc_html_e('No tag-role mappings yet. Add your first mapping above.', 'mxchat'); ?></p>
1334 </div>
1335
1336 <div style="margin-top: 30px; padding-top: 24px; border-top: 1px solid var(--mxch-card-border);">
1337 <h4 style="margin: 0 0 12px 0;"><?php esc_html_e('Bulk Update Existing Content', 'mxchat'); ?></h4>
1338 <p class="mxch-field-description" style="margin-bottom: 16px;"><?php esc_html_e('Apply role restrictions to all existing content that has the mapped tags.', 'mxchat'); ?></p>
1339 <button type="button" id="mxchat-bulk-update-roles" class="mxch-btn mxch-btn-secondary">
1340 <span class="dashicons dashicons-update" style="font-size: 16px;"></span>
1341 <?php esc_html_e('Update All Existing Content', 'mxchat'); ?>
1342 </button>
1343 <div id="mxchat-bulk-update-progress" style="display: none; margin-top: 15px;">
1344 <div style="height: 8px; background: #e2e8f0; border-radius: 4px; overflow: hidden;">
1345 <div class="mxchat-progress-fill" style="height: 100%; background: var(--mxch-primary); width: 0%; transition: width 0.3s;"></div>
1346 </div>
1347 <p class="mxchat-progress-text" style="margin-top: 10px; color: var(--mxch-text-secondary);"><?php esc_html_e('Processing...', 'mxchat'); ?></p>
1348 </div>
1349 <div id="mxchat-bulk-update-result" style="display: none; margin-top: 15px;"></div>
1350 </div>
1351 </div>
1352 </div>
1353 </div>
1354 <?php
1355 }
1356
1357 /**
1358 * Render ACF Fields Section
1359 */
1360 function mxchat_render_acf_fields_section($knowledge_manager) {
1361 $excluded_fields = get_option('mxchat_acf_excluded_fields', array());
1362 if (!is_array($excluded_fields)) {
1363 $excluded_fields = array();
1364 }
1365 ?>
1366 <div id="acf-fields" class="mxch-section">
1367 <div class="mxch-content-header">
1368 <h1 class="mxch-content-title"><?php esc_html_e('ACF Field Settings', 'mxchat'); ?></h1>
1369 <p class="mxch-content-subtitle"><?php esc_html_e('Control which Advanced Custom Fields are included in knowledge base embeddings.', 'mxchat'); ?></p>
1370 </div>
1371
1372 <div class="mxch-card">
1373 <div class="mxch-card-body mxchat-autosave-section">
1374 <?php if (!function_exists('acf_get_field_groups')): ?>
1375 <div class="mxch-notice mxch-notice-info">
1376 <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>
1377 <span><?php esc_html_e('Advanced Custom Fields (ACF) plugin is not detected. Install and activate ACF to use this feature.', 'mxchat'); ?></span>
1378 </div>
1379 <?php else:
1380 $all_acf_fields = $knowledge_manager->mxchat_get_all_acf_fields();
1381
1382 if (empty($all_acf_fields)): ?>
1383 <div class="mxch-notice mxch-notice-info">
1384 <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>
1385 <span><?php esc_html_e('No ACF field groups found. Create field groups in ACF to control which fields are included in embeddings.', 'mxchat'); ?></span>
1386 </div>
1387 <?php else: ?>
1388 <div class="mxch-notice mxch-notice-info" style="margin-bottom: 20px;">
1389 <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>
1390 <span><?php esc_html_e('Toggle fields ON to include them in knowledge base embeddings. Toggle OFF to exclude sensitive or irrelevant fields.', 'mxchat'); ?></span>
1391 </div>
1392
1393 <?php foreach ($all_acf_fields as $group_title => $fields): ?>
1394 <div class="mxchat-acf-field-group" style="margin-bottom: 24px;">
1395 <h4 style="margin: 0 0 12px 0; color: var(--mxch-text-primary); font-weight: 600;">
1396 <?php echo esc_html($group_title); ?>
1397 </h4>
1398 <div style="background: #f8fafc; border-radius: var(--mxch-radius-md); padding: 16px;">
1399 <?php foreach ($fields as $field):
1400 $field_name = $field['name'];
1401 $is_enabled = !in_array($field_name, $excluded_fields);
1402 ?>
1403 <div style="display: flex; align-items: center; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid #e2e8f0;">
1404 <div>
1405 <span style="font-weight: 500;"><?php echo esc_html($field['label']); ?></span>
1406 <span style="color: var(--mxch-text-muted); font-size: 12px; margin-left: 8px;">(<?php echo esc_html($field_name); ?>)</span>
1407 <span style="color: var(--mxch-text-muted); font-size: 11px; margin-left: 8px; background: #e2e8f0; padding: 2px 6px; border-radius: 4px;"><?php echo esc_html($field['type']); ?></span>
1408 </div>
1409 <label class="mxchat-toggle-switch">
1410 <input type="checkbox"
1411 name="mxchat_acf_field_<?php echo esc_attr($field_name); ?>"
1412 class="mxchat-autosave-field"
1413 value="on"
1414 data-nonce="<?php echo wp_create_nonce('mxchat_prompts_setting_nonce'); ?>"
1415 <?php checked($is_enabled, true); ?>>
1416 <span class="mxchat-toggle-slider"></span>
1417 </label>
1418 </div>
1419 <?php endforeach; ?>
1420 </div>
1421 </div>
1422 <?php endforeach; ?>
1423 <?php endif; ?>
1424 <?php endif; ?>
1425 </div>
1426 </div>
1427 </div>
1428 <?php
1429 }
1430
1431 /**
1432 * Render Custom Meta Section
1433 */
1434 function mxchat_render_custom_meta_section() {
1435 $whitelist = get_option('mxchat_custom_meta_whitelist', '');
1436 ?>
1437 <div id="custom-meta" class="mxch-section">
1438 <div class="mxch-content-header">
1439 <h1 class="mxch-content-title"><?php esc_html_e('Custom Post Meta', 'mxchat'); ?></h1>
1440 <p class="mxch-content-subtitle"><?php esc_html_e('Include custom post meta fields (non-ACF) in knowledge base embeddings.', 'mxchat'); ?></p>
1441 </div>
1442
1443 <div class="mxch-card">
1444 <div class="mxch-card-body mxchat-autosave-section">
1445 <div class="mxch-notice mxch-notice-info" style="margin-bottom: 20px;">
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>
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>
1448 </div>
1449
1450 <div class="mxch-field">
1451 <label class="mxch-field-label" for="mxchat_custom_meta_whitelist">
1452 <?php esc_html_e('Meta Key Whitelist', 'mxchat'); ?>
1453 </label>
1454 <textarea
1455 name="mxchat_custom_meta_whitelist"
1456 id="mxchat_custom_meta_whitelist"
1457 class="mxch-textarea mxchat-autosave-field"
1458 rows="6"
1459 placeholder="speaker_profession&#10;speaker_company&#10;event_location&#10;_custom_field_key"
1460 data-nonce="<?php echo wp_create_nonce('mxchat_prompts_setting_nonce'); ?>"
1461 style="font-family: monospace;"
1462 ><?php echo esc_textarea($whitelist); ?></textarea>
1463 <p class="mxch-field-description">
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'); ?>
1465 </p>
1466 </div>
1467
1468 <div style="margin-top: 20px; padding: 16px; background: #f8fafc; border-radius: var(--mxch-radius-md);">
1469 <h4 style="margin: 0 0 12px 0; font-size: 14px;"><?php esc_html_e('How to find meta keys:', 'mxchat'); ?></h4>
1470 <ul style="margin: 0; padding-left: 20px; color: var(--mxch-text-secondary); font-size: 13px;">
1471 <li><?php esc_html_e('Check your theme documentation for meta key names', 'mxchat'); ?></li>
1472 <li><?php esc_html_e('Look in the wp_postmeta database table', 'mxchat'); ?></li>
1473 <li><?php esc_html_e('Use a plugin like "Show Post Meta" to view meta keys on any post', 'mxchat'); ?></li>
1474 <li><?php esc_html_e('Meta keys starting with underscore (_) are usually hidden/internal', 'mxchat'); ?></li>
1475 </ul>
1476 </div>
1477 </div>
1478 </div>
1479 </div>
1480 <?php
1481 }
1482
1483 /**
1484 * Render Pinecone Section
1485 */
1486 function mxchat_render_pinecone_section() {
1487 $pinecone_options = get_option('mxchat_pinecone_addon_options', array());
1488 $use_pinecone = $pinecone_options['mxchat_use_pinecone'] ?? '0';
1489 ?>
1490 <div id="pinecone" class="mxch-section">
1491 <div class="mxch-content-header">
1492 <h1 class="mxch-content-title"><?php esc_html_e('Pinecone Vector Database', 'mxchat'); ?></h1>
1493 <p class="mxch-content-subtitle"><?php esc_html_e('Configure Pinecone for enhanced search performance with larger knowledge bases.', 'mxchat'); ?></p>
1494 </div>
1495
1496 <div class="mxch-card">
1497 <div class="mxch-card-body">
1498 <div class="mxch-notice mxch-notice-info" style="margin-bottom: 20px;">
1499 <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>
1500 <span><strong><?php esc_html_e('Pinecone is optional.', 'mxchat'); ?></strong> <?php esc_html_e('MxChat works without it. When enabled, content is stored in Pinecone for faster similarity searches.', 'mxchat'); ?></span>
1501 </div>
1502
1503 <form method="post" action="options.php">
1504 <?php settings_fields('mxchat_pinecone_addon_options'); ?>
1505
1506 <div class="mxch-field">
1507 <div style="display: flex; align-items: center; gap: 12px; margin-bottom: 20px;">
1508 <label class="mxchat-toggle-switch">
1509 <input type="checkbox" name="mxchat_pinecone_addon_options[mxchat_use_pinecone]" value="1" <?php checked($use_pinecone, '1'); ?>>
1510 <span class="mxchat-toggle-slider"></span>
1511 </label>
1512 <span style="font-weight: 500;"><?php esc_html_e('Enable Pinecone Database', 'mxchat'); ?></span>
1513 </div>
1514 </div>
1515
1516 <div class="mxchat-pinecone-settings" <?php echo $use_pinecone ? '' : 'style="display: none;"'; ?>>
1517 <?php if ($use_pinecone) : ?>
1518 <div class="mxch-notice mxch-notice-success" style="margin-bottom: 20px;">
1519 <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"><path d="M22 11.08V12a10 10 0 1 1-5.93-9.14"/><polyline points="22 4 12 14.01 9 11.01"/></svg>
1520 <span><?php esc_html_e('Pinecone is enabled. All new knowledge base content will be stored in Pinecone.', 'mxchat'); ?></span>
1521 </div>
1522 <?php endif; ?>
1523
1524 <div class="mxch-field">
1525 <label class="mxch-field-label" for="mxchat_pinecone_api_key">
1526 <?php esc_html_e('Pinecone API Key', 'mxchat'); ?> <span class="mxch-field-label-required">*</span>
1527 </label>
1528 <input type="password" id="mxchat_pinecone_api_key" name="mxchat_pinecone_addon_options[mxchat_pinecone_api_key]" value="<?php echo esc_attr($pinecone_options['mxchat_pinecone_api_key'] ?? ''); ?>" class="mxch-input" placeholder="pcsk_...">
1529 <p class="mxch-field-description">
1530 <?php esc_html_e('Found in your Pinecone dashboard under API Keys.', 'mxchat'); ?>
1531 <a href="https://app.pinecone.io/" target="_blank"><?php esc_html_e('Open Pinecone Dashboard', 'mxchat'); ?></a>
1532 </p>
1533 </div>
1534
1535 <div class="mxch-field">
1536 <label class="mxch-field-label" for="mxchat_pinecone_environment"><?php esc_html_e('Region', 'mxchat'); ?></label>
1537 <input type="text" id="mxchat_pinecone_environment" name="mxchat_pinecone_addon_options[mxchat_pinecone_environment]" value="<?php echo esc_attr($pinecone_options['mxchat_pinecone_environment'] ?? ''); ?>" class="mxch-input" placeholder="e.g., gcp-starter">
1538 <p class="mxch-field-description"><?php esc_html_e('Your Pinecone environment/region (e.g., gcp-starter, us-west1-gcp)', 'mxchat'); ?></p>
1539 </div>
1540
1541 <div class="mxch-field">
1542 <label class="mxch-field-label" for="mxchat_pinecone_index">
1543 <?php esc_html_e('Index Name', 'mxchat'); ?> <span class="mxch-field-label-required">*</span>
1544 </label>
1545 <input type="text" id="mxchat_pinecone_index" name="mxchat_pinecone_addon_options[mxchat_pinecone_index]" value="<?php echo esc_attr($pinecone_options['mxchat_pinecone_index'] ?? ''); ?>" class="mxch-input" placeholder="e.g., my-wordpress-vectors">
1546 <p class="mxch-field-description"><?php esc_html_e('The name of your Pinecone index. Must be created in your Pinecone dashboard first.', 'mxchat'); ?></p>
1547 </div>
1548
1549 <div class="mxch-field">
1550 <label class="mxch-field-label" for="mxchat_pinecone_host">
1551 <?php esc_html_e('Pinecone Host', 'mxchat'); ?> <span class="mxch-field-label-required">*</span>
1552 </label>
1553 <input type="text" id="mxchat_pinecone_host" name="mxchat_pinecone_addon_options[mxchat_pinecone_host]" value="<?php echo esc_attr($pinecone_options['mxchat_pinecone_host'] ?? ''); ?>" class="mxch-input" placeholder="e.g., my-index-xyz123.svc.pinecone.io">
1554 <p class="mxch-field-description"><?php esc_html_e('The hostname from your Pinecone index URL (exclude https://). Found in index details.', 'mxchat'); ?></p>
1555 </div>
1556 </div>
1557
1558 <?php submit_button(__('Save Pinecone Settings', 'mxchat'), 'primary', 'submit', true, array('class' => 'mxch-btn mxch-btn-primary')); ?>
1559 </form>
1560 </div>
1561 </div>
1562 </div>
1563 <?php
1564 }
1565
1566 /**
1567 * Render OpenAI Vector Store Section
1568 */
1569 function mxchat_render_openai_vectorstore_section() {
1570 $vectorstore_options = get_option('mxchat_openai_vectorstore_options', array());
1571 $use_vectorstore = $vectorstore_options['mxchat_use_openai_vectorstore'] ?? '0';
1572 $vectorstore_ids = $vectorstore_options['mxchat_vectorstore_ids'] ?? '';
1573 $max_results = $vectorstore_options['mxchat_vectorstore_max_results'] ?? 5;
1574
1575 // Get current chat model to check compatibility
1576 $mxchat_options = get_option('mxchat_options', array());
1577 $current_model = $mxchat_options['model'] ?? 'gpt-5.1-chat-latest';
1578 $is_openai_model = preg_match('/^(gpt-|o1-|o3-)/', $current_model);
1579 ?>
1580 <div id="openai-vectorstore" class="mxch-section">
1581 <div class="mxch-content-header">
1582 <h1 class="mxch-content-title"><?php esc_html_e('OpenAI Vector Store', 'mxchat'); ?></h1>
1583 <p class="mxch-content-subtitle"><?php esc_html_e('Use OpenAI\'s hosted vector database for knowledge retrieval. Your documents are stored and searched directly on OpenAI\'s platform.', 'mxchat'); ?></p>
1584 </div>
1585
1586 <div class="mxch-card">
1587 <div class="mxch-card-body">
1588 <div class="mxch-notice mxch-notice-info" style="margin-bottom: 20px;">
1589 <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 <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>
1591 </div>
1592
1593 <?php if (!$is_openai_model && $use_vectorstore === '1'): ?>
1594 <div class="mxch-notice mxch-notice-warning" style="margin-bottom: 20px;">
1595 <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"><path d="M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"/><line x1="12" y1="9" x2="12" y2="13"/><line x1="12" y1="17" x2="12.01" y2="17"/></svg>
1596 <span><strong><?php esc_html_e('Model Incompatible:', 'mxchat'); ?></strong> <?php printf(esc_html__('Your current chat model (%s) is not an OpenAI model. Vector Store search will not work until you switch to an OpenAI model.', 'mxchat'), esc_html($current_model)); ?></span>
1597 </div>
1598 <?php endif; ?>
1599
1600 <form method="post" action="options.php" id="mxchat-vectorstore-form">
1601 <?php settings_fields('mxchat_openai_vectorstore_options'); ?>
1602
1603 <div class="mxch-field">
1604 <div style="display: flex; align-items: center; gap: 12px; margin-bottom: 20px;">
1605 <label class="mxchat-toggle-switch">
1606 <input type="checkbox" name="mxchat_openai_vectorstore_options[mxchat_use_openai_vectorstore]" value="1" <?php checked($use_vectorstore, '1'); ?> id="mxchat_use_openai_vectorstore">
1607 <span class="mxchat-toggle-slider"></span>
1608 </label>
1609 <span style="font-weight: 500;"><?php esc_html_e('Enable OpenAI Vector Store', 'mxchat'); ?></span>
1610 </div>
1611 </div>
1612
1613 <div class="mxchat-vectorstore-settings" <?php echo $use_vectorstore === '1' ? '' : 'style="display: none;"'; ?>>
1614 <?php if ($use_vectorstore === '1'): ?>
1615 <div class="mxch-notice mxch-notice-success" style="margin-bottom: 20px;">
1616 <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"><path d="M22 11.08V12a10 10 0 1 1-5.93-9.14"/><polyline points="22 4 12 14.01 9 11.01"/></svg>
1617 <span><?php esc_html_e('OpenAI Vector Store is enabled. Queries will search your Vector Store for relevant content.', 'mxchat'); ?></span>
1618 </div>
1619 <?php endif; ?>
1620
1621 <div class="mxch-field">
1622 <label class="mxch-field-label" for="mxchat_vectorstore_ids">
1623 <?php esc_html_e('Vector Store ID(s)', 'mxchat'); ?> <span class="mxch-field-label-required">*</span>
1624 </label>
1625 <input type="text" id="mxchat_vectorstore_ids" name="mxchat_openai_vectorstore_options[mxchat_vectorstore_ids]" value="<?php echo esc_attr($vectorstore_ids); ?>" class="mxch-input" placeholder="vs_abc123xyz">
1626 <p class="mxch-field-description">
1627 <?php esc_html_e('Enter your Vector Store ID from the OpenAI Dashboard. For multiple stores, separate with commas.', 'mxchat'); ?>
1628 <a href="https://platform.openai.com/storage/vector_stores" target="_blank"><?php esc_html_e('Open OpenAI Vector Store Dashboard', 'mxchat'); ?></a>
1629 </p>
1630 </div>
1631
1632 <div class="mxch-field">
1633 <label class="mxch-field-label" for="mxchat_vectorstore_max_results">
1634 <?php esc_html_e('Max Results', 'mxchat'); ?>
1635 </label>
1636 <select id="mxchat_vectorstore_max_results" name="mxchat_openai_vectorstore_options[mxchat_vectorstore_max_results]" class="mxch-input" style="width: auto;">
1637 <?php for ($i = 1; $i <= 10; $i++): ?>
1638 <option value="<?php echo $i; ?>" <?php selected($max_results, $i); ?>><?php echo $i; ?></option>
1639 <?php endfor; ?>
1640 </select>
1641 <p class="mxch-field-description"><?php esc_html_e('Maximum number of content chunks to retrieve from the Vector Store.', 'mxchat'); ?></p>
1642 </div>
1643 </div>
1644
1645 <?php submit_button(__('Save Vector Store Settings', 'mxchat'), 'primary', 'submit', true, array('class' => 'mxch-btn mxch-btn-primary')); ?>
1646 </form>
1647 </div>
1648 </div>
1649 </div>
1650 <?php
1651 }
1652
1653 /**
1654 * Render Content Selector Modal
1655 */
1656 function mxchat_render_content_selector_modal() {
1657 ?>
1658 <div id="mxchat-kb-content-selector-modal" class="mxchat-kb-modal">
1659 <div class="mxchat-kb-modal-content">
1660 <div class="mxchat-kb-modal-header">
1661 <h3>
1662 <?php esc_html_e('Select WordPress Content', 'mxchat'); ?><br>
1663 <span class="mxchat-kb-header-note"><?php esc_html_e('(Content imported here will be tagged "In Knowledge Base")', 'mxchat'); ?></span>
1664 </h3>
1665 <span class="mxchat-kb-modal-close">&times;</span>
1666 </div>
1667 <div class="mxchat-kb-modal-filters">
1668 <div class="mxchat-kb-search-group">
1669 <input type="text" id="mxchat-kb-content-search" placeholder="<?php esc_attr_e('Search...', 'mxchat'); ?>">
1670 </div>
1671 <div class="mxchat-kb-filter-group">
1672 <select id="mxchat-kb-content-type-filter">
1673 <option value="all"><?php esc_html_e('All Content Types', 'mxchat'); ?></option>
1674 <option value="post"><?php esc_html_e('Posts', 'mxchat'); ?></option>
1675 <option value="page"><?php esc_html_e('Pages', 'mxchat'); ?></option>
1676 <?php
1677 $post_types = get_post_types(array('public' => true), 'objects');
1678 foreach ($post_types as $post_type) {
1679 if (!in_array($post_type->name, array('post', 'page'))) {
1680 echo '<option value="' . esc_attr($post_type->name) . '">' . esc_html($post_type->label) . '</option>';
1681 }
1682 }
1683 ?>
1684 </select>
1685 <select id="mxchat-kb-content-status-filter">
1686 <option value="publish"><?php esc_html_e('Published', 'mxchat'); ?></option>
1687 <option value="draft"><?php esc_html_e('Drafts', 'mxchat'); ?></option>
1688 <option value="all"><?php esc_html_e('All Statuses', 'mxchat'); ?></option>
1689 </select>
1690 <select id="mxchat-kb-processed-filter">
1691 <option value="all"><?php esc_html_e('All Content', 'mxchat'); ?></option>
1692 <option value="processed"><?php esc_html_e('In Knowledge Base', 'mxchat'); ?></option>
1693 <option value="unprocessed"><?php esc_html_e('Not In Knowledge Base', 'mxchat'); ?></option>
1694 </select>
1695 </div>
1696 </div>
1697 <div class="mxchat-kb-content-selection">
1698 <div class="mxchat-kb-selection-header">
1699 <label>
1700 <input type="checkbox" id="mxchat-kb-select-all">
1701 <?php esc_html_e('Select All on Page', 'mxchat'); ?>
1702 </label>
1703 <span class="mxchat-kb-selection-count">0 <?php esc_html_e('selected', 'mxchat'); ?></span>
1704 <span class="mxchat-kb-selection-hint" style="margin-left: auto; font-size: 12px; color: var(--mxch-text-muted);">
1705 <span class="dashicons dashicons-info-outline" style="font-size: 14px; vertical-align: middle;"></span>
1706 <?php esc_html_e('Selections persist across pages', 'mxchat'); ?>
1707 </span>
1708 </div>
1709 <div class="mxchat-kb-content-list">
1710 <div class="mxchat-kb-loading">
1711 <span class="mxchat-kb-spinner is-active"></span>
1712 <?php esc_html_e('Loading content...', 'mxchat'); ?>
1713 </div>
1714 </div>
1715 </div>
1716 <div class="mxchat-kb-modal-footer">
1717 <div class="mxchat-kb-pagination"></div>
1718 <div class="mxchat-kb-footer-actions">
1719 <button type="button" id="mxchat-kb-process-selected" class="mxchat-kb-button-primary" disabled>
1720 <?php esc_html_e('Process Selected Content', 'mxchat'); ?>
1721 <span class="mxchat-kb-selected-count">(0)</span>
1722 </button>
1723 <button type="button" class="mxchat-kb-button-secondary mxchat-kb-modal-close">
1724 <?php esc_html_e('Cancel', 'mxchat'); ?>
1725 </button>
1726 </div>
1727 </div>
1728 </div>
1729 </div>
1730 <?php
1731 }
1732
1733 /**
1734 * Render Knowledge Page Navigation Scripts
1735 */
1736 function mxchat_render_knowledge_page_scripts() {
1737 ?>
1738 <script>
1739 (function() {
1740 'use strict';
1741
1742 // Wait for DOM
1743 document.addEventListener('DOMContentLoaded', function() {
1744 initKnowledgeNavigation();
1745 initMobileMenu();
1746 initImportOptions();
1747 initCustomPostTypesToggle();
1748 // Sitemap detection is now initialized when user clicks the Sitemap Import option
1749 });
1750
1751 function initKnowledgeNavigation() {
1752 const navLinks = document.querySelectorAll('.mxch-nav-link[data-target], .mxch-mobile-nav-link[data-target]');
1753 const sections = document.querySelectorAll('.mxch-section');
1754
1755 function showSection(targetId) {
1756 // Hide all sections
1757 sections.forEach(section => section.classList.remove('active'));
1758 // Show target section
1759 const target = document.getElementById(targetId);
1760 if (target) {
1761 target.classList.add('active');
1762 }
1763 // Update nav links
1764 navLinks.forEach(link => {
1765 link.classList.toggle('active', link.dataset.target === targetId);
1766 });
1767 // Update URL hash
1768 history.replaceState(null, null, '#' + targetId);
1769 }
1770
1771 navLinks.forEach(link => {
1772 link.addEventListener('click', function(e) {
1773 e.preventDefault();
1774 const targetId = this.dataset.target;
1775 showSection(targetId);
1776 // Close mobile menu if open
1777 const mobileMenu = document.querySelector('.mxch-mobile-menu');
1778 const overlay = document.querySelector('.mxch-mobile-overlay');
1779 if (mobileMenu) mobileMenu.classList.remove('open');
1780 if (overlay) overlay.classList.remove('open');
1781 });
1782 });
1783
1784 // Handle initial hash
1785 const hash = window.location.hash.substring(1);
1786 if (hash && document.getElementById(hash)) {
1787 showSection(hash);
1788 }
1789 }
1790
1791 function initMobileMenu() {
1792 const menuBtn = document.querySelector('.mxch-mobile-menu-btn');
1793 const closeBtn = document.querySelector('.mxch-mobile-menu-close');
1794 const overlay = document.querySelector('.mxch-mobile-overlay');
1795 const menu = document.querySelector('.mxch-mobile-menu');
1796
1797 if (menuBtn && menu) {
1798 menuBtn.addEventListener('click', function() {
1799 menu.classList.add('open');
1800 if (overlay) overlay.classList.add('open');
1801 });
1802 }
1803
1804 if (closeBtn && menu) {
1805 closeBtn.addEventListener('click', function() {
1806 menu.classList.remove('open');
1807 if (overlay) overlay.classList.remove('open');
1808 });
1809 }
1810
1811 if (overlay && menu) {
1812 overlay.addEventListener('click', function() {
1813 menu.classList.remove('open');
1814 overlay.classList.remove('open');
1815 });
1816 }
1817 }
1818
1819 function initImportOptions() {
1820 const importBoxes = document.querySelectorAll('.mxchat-import-box');
1821 const urlInputArea = document.getElementById('mxchat-url-input-area');
1822 const contentInputArea = document.getElementById('mxchat-content-input-area');
1823 const urlInput = document.getElementById('sitemap_url');
1824 const importTypeField = document.getElementById('import_type');
1825 const descriptionText = document.getElementById('url-description-text');
1826
1827 // Sitemap detection elements
1828 const sitemapsLoading = document.getElementById('mxchat-sitemaps-loading');
1829 const detectedSitemaps = document.getElementById('mxchat-detected-sitemaps');
1830 const noSitemaps = document.getElementById('mxchat-no-sitemaps');
1831
1832 // Helper to hide all sitemap detection UI
1833 function hideSitemapDetection() {
1834 if (sitemapsLoading) sitemapsLoading.style.display = 'none';
1835 if (detectedSitemaps) detectedSitemaps.style.display = 'none';
1836 if (noSitemaps) noSitemaps.style.display = 'none';
1837 }
1838
1839 importBoxes.forEach(box => {
1840 box.addEventListener('click', function() {
1841 const option = this.dataset.option;
1842 const type = this.dataset.type;
1843
1844 // Remove active from all boxes
1845 importBoxes.forEach(b => b.classList.remove('active'));
1846 this.classList.add('active');
1847
1848 // Handle different import types
1849 if (option === 'wordpress') {
1850 // WordPress content selector - handled by existing modal
1851 hideSitemapDetection();
1852 return;
1853 }
1854
1855 if (option === 'content') {
1856 if (urlInputArea) urlInputArea.style.display = 'none';
1857 if (contentInputArea) contentInputArea.style.display = 'block';
1858 hideSitemapDetection();
1859 } else if (type === 'sitemap' || type === 'url' || type === 'pdf') {
1860 if (contentInputArea) contentInputArea.style.display = 'none';
1861 if (urlInputArea) urlInputArea.style.display = 'block';
1862
1863 if (urlInput) {
1864 urlInput.placeholder = this.dataset.placeholder || 'Enter URL here';
1865 }
1866 if (importTypeField) {
1867 importTypeField.value = type;
1868 }
1869 if (descriptionText) {
1870 const descriptions = {
1871 'sitemap': '<?php echo esc_js(__('Use a content-specific sub-sitemap (e.g., post-sitemap.xml), not the main sitemap index.', 'mxchat')); ?>',
1872 'url': '<?php echo esc_js(__('Enter the URL of any webpage to import its content.', 'mxchat')); ?>',
1873 'pdf': '<?php echo esc_js(__('Enter the URL of a publicly accessible PDF file.', 'mxchat')); ?>'
1874 };
1875 descriptionText.textContent = descriptions[type] || '';
1876 }
1877
1878 // Only show sitemap detection when Sitemap Import is selected
1879 if (type === 'sitemap') {
1880 // Initialize sitemap detection (function is defined in knowledge-processing.js)
1881 if (typeof window.mxchatInitSitemapDetection === 'function') {
1882 window.mxchatInitSitemapDetection();
1883 }
1884 } else {
1885 hideSitemapDetection();
1886 }
1887 }
1888 });
1889 });
1890 }
1891
1892 function initCustomPostTypesToggle() {
1893 const toggleBtn = document.getElementById('mxchat-custom-post-types-toggle');
1894 const container = document.getElementById('mxchat-custom-post-types-container');
1895
1896 if (toggleBtn && container) {
1897 toggleBtn.addEventListener('click', function() {
1898 const isHidden = container.style.display === 'none';
1899 container.style.display = isHidden ? 'block' : 'none';
1900 const icon = this.querySelector('span:last-child');
1901 if (icon) {
1902 icon.textContent = isHidden ? '' : '';
1903 }
1904 });
1905 }
1906 }
1907
1908 // Sitemap detection is now handled by knowledge-processing.js
1909 // It will be initialized when user clicks "Sitemap Import" option
1910 })();
1911 </script>
1912 <?php
1913 }
1914