. */ defined('ABSPATH') or die('Direct script access disallowed.'); define('AI24AI_VERSION', '1.0.9.2'); // Define constants to use correct paths if they are not already defined if (!defined('AI24AI_PLUGIN_DIR')) { define('AI24AI_PLUGIN_DIR', plugin_dir_path(__FILE__) . '../ai24-assistant-integrator/'); } if (!defined('AI24AI_PLUGIN_URL')) { define('AI24AI_PLUGIN_URL', plugin_dir_url(__FILE__) . '../ai24-assistant-integrator/'); } if (!defined('AI24AI_CHILD_FUNCTIONS_FILE')) { define('AI24AI_CHILD_FUNCTIONS_FILE', plugin_dir_path(__FILE__) . 'includes/functions.php'); } // Plugin Activation if (!function_exists('AI24AI_activate')) { function AI24AI_activate() { error_log('AI24AI_activate called'); // Get the previously stored version $previous_version = get_option('AI24AI_version'); error_log('Previous version: ' . $previous_version); $new_plugin_dir = plugin_dir_path(__FILE__); $plugin_base_dir = dirname($new_plugin_dir); // Base directory where all plugin versions reside // Perform any necessary actions when updating from a previous version if ($previous_version && $previous_version !== AI24AI_VERSION) { // Any additional actions for version updates can be added here error_log('Updating from version: ' . $previous_version . ' to version: ' . AI24AI_VERSION); } // Update to the new version update_option('AI24AI_version', AI24AI_VERSION); error_log('Updated version to: ' . AI24AI_VERSION); // Ensure the widget option is set if (get_option('AI24AI_enable_widget') === false) { update_option('AI24AI_enable_widget', 'no'); error_log('AI24AI_enable_widget set to no'); } } } register_activation_hook(__FILE__, 'AI24AI_activate'); // Plugin Deactivation if (!function_exists('AI24AI_deactivate')) { function AI24AI_deactivate() { update_option('AI24AI_active', 'no'); error_log('AI24AI_deactivate called'); } } register_deactivation_hook(__FILE__, 'AI24AI_deactivate'); // Check for plugin updates if (!function_exists('AI24AI_check_version')) { function AI24AI_check_version() { $installed_version = get_option('AI24AI_version'); //error_log('Checking version: ' . $installed_version); if ($installed_version !== AI24AI_VERSION) { AI24AI_activate(); } } } add_action('plugins_loaded', 'AI24AI_check_version'); // Function to add the settings link function ai24ai_add_plugin_settings_link($links) { // error_log('ai24ai_add_plugin_settings_link called'); $settings_link = 'Settings'; array_unshift($links, $settings_link); return $links; } add_filter('plugin_action_links_' . plugin_basename(__FILE__), 'ai24ai_add_plugin_settings_link'); require_once plugin_dir_path(__FILE__) . 'includes/settings-page.php'; require_once plugin_dir_path(__FILE__) . 'assets/php/Parsedown.php'; $options = get_option('AI24AI_functions_option'); $handler_type = is_array($options) && isset($options['handler_type']) ? $options['handler_type'] : 'apiv2'; // Conditionally include the appropriate file if ($handler_type === 'apiv1') { require_once plugin_dir_path(__FILE__) . 'includes/api-handler-v1.php'; } else { require_once plugin_dir_path(__FILE__) . 'includes/api-handler-v2.php'; } // Plugin code below this line function AI24AI_enqueue_scripts() { $options = get_option('AI24AI_font_settings', array('font' => 'AI24AIKumbhsans')); $font_family = isset($options['font']) ? $options['font'] : 'AI24AIKumbhsans'; if ($font_family === 'AI24AIKumbhsans') { wp_enqueue_style('AI24AI-kumbhsans-font', plugin_dir_url(__FILE__) . 'assets/css/ai24ai-kumbhsans.css', array(), null); } else { //wp_enqueue_style('AI24AI-custom-font', plugin_dir_url(__FILE__) . 'assets/fonts/' . $font_family . '.css', array(), null); } // Enqueue front-end styles wp_enqueue_style( 'AI24AI-style', AI24AI_PLUGIN_URL . 'assets/css/AI24AI-style.css', array(), filemtime(plugin_dir_path(__FILE__) . 'assets/css/AI24AI-style.css') ); // Enqueue front-end script wp_enqueue_script( 'AI24AI-script', AI24AI_PLUGIN_URL . 'assets/js/AI24AI-script.js', array('jquery', 'lottie'), filemtime(plugin_dir_path(__FILE__) . 'assets/js/AI24AI-script.js'), true ); // previous code here /**Atharva was here */ // Add React app wp_enqueue_script( 'AI24AI-chat-main', plugins_url('assets/js/chat-main.js', __FILE__), array('wp-element'), '1.0', true ); wp_script_add_data('AI24AI-chat-main', 'type', 'module'); /**Atharva was here */ // Add inline style to apply the selected font wp_add_inline_style('AI24AI-style', " #AI24AI-chatbot-container, #AI24AI-chatbot-container * { font-family: 'AI24AIKumbhsans', sans-serif !important; }, 999"); // Welcome messages array $context_messages = array(); for ($i = 1; $i <= 3; $i++) { $is_toggle_on = $i === 1 ? true : get_option("AI24AI_assistant_context_toggle_$i", 'off') === 'on'; if ($is_toggle_on) { $context_message = get_option("AI24AI_assistant_context_message_$i", ''); if (!empty($context_message)) { // Additional check to ensure message isn't empty $context_messages[] = $context_message; } } } $nonce = wp_create_nonce('AI24AI_nonce'); // Localize the front-end script with necessary data $assistant_styling = array( 'name' => get_option('AI24AI_assistant_name'), 'description' => get_option('AI24AI_assistant_description'), 'image' => get_option('AI24AI_assistant_image'), 'contextMessages' => $context_messages, 'typingAnimationPath' => plugins_url('assets/images/TypingAnimation.json', __FILE__), ); wp_localize_script('AI24AI-script', 'AI24AI_params', array_merge( array( 'ajax_url' => admin_url('admin-ajax.php'), 'nonce' => $nonce, ), $assistant_styling )); } add_action('wp_enqueue_scripts', 'AI24AI_enqueue_scripts'); // Function to enqueue Lottie from local assets function AI24AI_enqueue_lottie_script() { wp_enqueue_script('lottie', plugins_url('assets/js/lottie.min.js', __FILE__), array(), '5.12.2', true); } add_action('wp_enqueue_scripts', 'AI24AI_enqueue_lottie_script'); // Function to add 'defer' attribute to specific scripts function AI24AI_add_defer_attribute($tag, $handle) { if ('lottie' === $handle) { return str_replace(' src', ' defer="defer" src', $tag); } return $tag; } add_filter('script_loader_tag', 'AI24AI_add_defer_attribute', 10, 2); //AJAX HANDLER function AI24AI_handle_chat_request() { // Extract & Sanitize User Input $user_input = sanitize_text_field($_POST['user_input']); $assistant_id = get_option('AI24AI_assistant_id'); $thread_id = isset($_POST['thread_id']) ? sanitize_text_field($_POST['thread_id']) : ''; if (empty($thread_id)) { // No thread - create a new thread and run $response = AI24AI_create_thread_and_run($user_input, $assistant_id); if (!$response) { wp_send_json_error(['error' => 'Thread and run creation failed']); return; } $thread_id = $response['thread_id']; $run_id = $response['run_id']; } else { // Existing thread - send a message and create a run $message_id = AI24AI_send_message_to_thread($thread_id, $user_input); $run_id = AI24AI_create_run($thread_id, $assistant_id); if (!$run_id) { wp_send_json_error(['error' => 'Failed to start assistant run']); return; } } // Poll for Response $poll_result = AI24AI_poll_for_response_and_retrieve_details($thread_id, $run_id); $messages = $poll_result['messages'] ?? []; wp_send_json_success([ 'thread_id' => $thread_id, 'messages' => $messages ]); } add_action('wp_ajax_AI24AI_chat', 'AI24AI_handle_chat_request'); add_action('wp_ajax_nopriv_AI24AI_chat', 'AI24AI_handle_chat_request'); // Function that controls the placement of the widget on the front end function AI24AI_output_chatbox() { $widget_enabled = get_option('AI24AI_enable_widget', 'yes'); $widget_pages = get_option('AI24AI_widget_pages', array()); if ($widget_enabled !== 'yes') { return; } if (!empty($widget_pages) && !is_page($widget_pages)) { return; } $va_name = get_option('AI24AI_assistant_name', 'Voxel Virtual Assistant'); $va_image = get_option('AI24AI_assistant_image'); $va_description = get_option('AI24AI_assistant_description', ''); $chat_input_placeholder = get_option('AI24AI_chat_input_placeholder'); if (empty($chat_input_placeholder)) { $chat_input_placeholder = 'Type your message here...'; } $exit_confirmation_text = get_option('AI24AI_exit_confirmation_text'); if (empty($exit_confirmation_text)) { $exit_confirmation_text = 'Are you sure you want to exit? Your current conversation will be lost.'; } $confirm_exit_button_text = get_option('AI24AI_confirm_exit_button'); if (empty($confirm_exit_button_text)) { $confirm_exit_button_text = 'Yes, exit'; } $cancel_exit_button_text = get_option('AI24AI_cancel_exit_button'); if (empty($cancel_exit_button_text)) { $cancel_exit_button_text = 'No, cancel'; } $toggle_image_url = get_option('AI24AI_toggle_image'); $send_icon_url = plugins_url('assets/images/site24-send-button.svg', __FILE__); if (empty($toggle_image_url)) { if (defined('AI24AI_PLUGIN_BASE_URL')) { $toggle_image_url = get_option('AI24AI_toggle_image', AI24AI_PLUGIN_BASE_URL . 'assets/images/messagebubble.svg'); } else { // Fallback if AI24AI_PLUGIN_BASE_URL is not defined $toggle_image_url = get_option('AI24AI_toggle_image', plugins_url('assets/images/messagebubble.svg', __DIR__)); } } $sidebar_content = get_option('AI24AI_sidebar_content', 'icon'); $sidebar_text = get_option('AI24AI_sidebar_text', ''); ?>
Chat Toggle
<?php echo esc_attr($va_name); ?>
<?php echo esc_attr($va_name); ?>
Send
Powered by AI24