PluginProbe
VikBooking Hotel Booking Engine & PMS / 1.7.2
VikBooking Hotel Booking Engine & PMS v1.7.2
1.8.16 1.8.15 1.8.14 1.8.13 1.8.12 1.8.11 1.8.10 1.8.9 1.8.6 1.8.7 1.8.8 trunk 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.6.9 1.7.0 1.7.1 1.7.2 All 37 releases
vikbooking / admin / helpers / widgets / aitools.php

aitools.php in VikBooking Hotel Booking Engine & PMS 1.7.2, at admin/helpers/widgets/aitools.php

137 lines 3.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @package VikBooking
4 * @subpackage com_vikbooking
5 * @author Alessio Gaggii - E4J srl
6 * @copyright Copyright (C) 2024 E4J srl. All rights reserved.
7 * @license GNU General Public License version 2 or later; see LICENSE
8 * @link https://vikwp.com
9 */
10
11 defined('ABSPATH') or die('No script kiddies please!');
12
13 /**
14 * Class handler for admin widget "AI Tools".
15 *
16 * @since 1.17 (J) - 1.7 (WP)
17 */
18 class VikBookingAdminWidgetAitools extends VikBookingAdminWidget
19 {
20 /**
21 * @inheritDOc
22 */
23 public function __construct()
24 {
25 // call parent constructor
26 parent::__construct();
27
28 $this->widgetName = JText::translate('VBO_W_AITOOLS_TITLE');
29 $this->widgetDescr = JText::translate('VBO_W_AITOOLS_DESCR');
30 $this->widgetId = basename(__FILE__, '.php');
31
32 $this->widgetIcon = '<i class="' . VikBookingIcons::i('magic') . '"></i>';
33 $this->widgetStyleName = 'violet';
34 }
35
36 /**
37 * @inheritDoc
38 */
39 public function getPriority()
40 {
41 // give this widget a higher priority
42 return 15;
43 }
44
45 /**
46 * @inheritDoc
47 */
48 public function preflight()
49 {
50 // can be used only if VCM is installed and the AI channel is supported (not necessarily active)
51 return class_exists('VikChannelManager') && defined('VikChannelManagerConfig::AI');
52 }
53
54 /**
55 * @inheritDoc
56 */
57 public function preload()
58 {
59 $options = [
60 'version' => defined('VIKCHANNELMANAGER_SOFTWARE_VERSION') ? VIKCHANNELMANAGER_SOFTWARE_VERSION : VIKBOOKING_SOFTWARE_VERSION,
61 ];
62
63 // manually load required dependencies
64 JHtml::fetch('script', VCM_ADMIN_URI . 'layouts/ai/assistant/aitools.js', $options);
65 JHtml::fetch('stylesheet', VCM_ADMIN_URI . 'layouts/ai/assistant/aitools.css', $options);
66
67 JHtml::fetch('script', VCM_ADMIN_URI . 'assets/js/katex/katex.min.js', $options);
68 JHtml::fetch('script', VCM_ADMIN_URI . 'assets/js/katex/auto-render.min.js', $options);
69 JHtml::fetch('stylesheet', VCM_ADMIN_URI . 'assets/js/katex/katex.min.css', $options);
70
71 // language definitions
72 JText::script('VBO_AI_ASSISTANT_DISCLAIMER');
73 JText::script('VBO_AI_ASSISTANT_DISCOVER_HINT');
74 JText::script('VBO_AI_ASSISTANT_DISCOVER_TITLE');
75 }
76
77 /**
78 * @inheritDoc
79 */
80 public function render(VBOMultitaskData $data = null)
81 {
82 $auto_focus = false;
83 $prompt = null;
84
85 // if we are rendering the widget on a modal, register a script to prevent the latter
86 // from dismissing whenever the ESC key is pressed
87 if ($data && $data->isModalRendering()) {
88 $auto_focus = true;
89 $prompt = (array) $this->getOption('prompt', null);
90 ?>
91 <script>
92 (function() {
93 const vbo_modal_ai_assistant_dismiss = (event) => {
94 if (event.key == 'Escape') {
95 event.preventDefault();
96 event.stopPropagation();
97 return false;
98 }
99 };
100
101 document.addEventListener('keyup', vbo_modal_ai_assistant_dismiss);
102
103 document.addEventListener(VBOCore.widget_modal_dismissed + '<?php echo $data->getModalJsIdentifier(); ?>', (e) => {
104 document.removeEventListener('keyup', vbo_modal_ai_assistant_dismiss);
105 VBOCore.emitEvent('vbo-widget-ai-tools-dismissed');
106 });
107 })();
108 </script>
109 <?php
110 }
111
112 // display by using a specific layout provided by VCM
113 echo JLayoutHelper::render(
114 'ai.assistant.chat',
115 [
116 // prevent the layout from loading the required assets
117 'load_assets' => false,
118 // auto-focus textarea
119 'auto_focus' => $auto_focus,
120 // default prompt
121 'prompt' => $prompt,
122 // show widget title (VBO dashboard only)
123 'widget_title' => is_null($data),
124 // widget icon
125 'widget_icon' => $this->widgetIcon,
126 // widget name
127 'widget_name' => $this->widgetName,
128 ],
129 null,
130 [
131 'client' => 'administrator',
132 'component' => 'com_vikchannelmanager',
133 ]
134 );
135 }
136 }
137