-
Notifications
You must be signed in to change notification settings - Fork 0
/
nexai_chat.php
96 lines (84 loc) · 3.28 KB
/
nexai_chat.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
/**
* @package Nexai Chat Integration for Joomla!
* @type Plugin (System)
* @filename nexai_chat.php
* @folder <root>/plugins/system/nexai_chat
* @version 0.0.1
* @modified May 3rd 20203
* @author nexai.site / Nexai
* @website https://nexai.site
* @url https://nexai.site
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
*
* @copyright (C) 2023-2023 nexai.site
*
* This program can be used under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version 3 of the License.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
**/
defined( '_JEXEC' ) or die( 'Restricted access' );
use Joomla\CMS\User;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\CMS\Uri\Uri;
use Joomla\String\StringHelper;
use Joomla\CMS\HTML\HTMLHelper;
class plgSystemNexai_Chat extends CMSPlugin
{
protected $app;
protected $runApp=0;
function onBeforeRender()
{
if($this->app->isClient('site'))
{
$this->runApp=1;
}
}
public function onAfterRender()
{
if (!$this->runApp) {
return;
}
// Get the user object
$user = JUser::getInstance();
// Initialize variables for user name, email, and avatar URL
$userName = '';
$userEmail = '';
$userAvatarUrl = '';
// Check if the user is logged in
if (!$user->guest) {
// Set the user's name and email
$userName = $user->name;
$userEmail = $user->email;
// Check if the user avatar is available
if (!empty($user->avatar)) {
// Set the user's avatar URL
$userAvatarUrl = JUri::root() . $user->avatar;
}
}
$buffer = $this->app->getBody();
$jsBuffer = '';
$jsBuffer .= "<script src=\"https://nexai.site/ai/embed.umd.js\"></script>\n";
$jsBuffer .= "<script>\n";
$jsBuffer .= "// edit the configurations for your website\n";
$jsBuffer .= "NexaiChatBubble.render({\n";
$jsBuffer .= " bottom: " . (int)$this->params->get('bottom', 30) . ",\n";
$jsBuffer .= " right: " . (int)$this->params->get('right', 30) . ",\n";
$jsBuffer .= " width: " . (int)$this->params->get('width', 400) . ",\n";
$jsBuffer .= " nexaiApiKey: '" . StringHelper::trim($this->params->get('nexaiApiKey', '')) . "',\n";
$jsBuffer .= " aiName: '" . StringHelper::trim($this->params->get('aiName', 'AI Assistant')) . "',\n";
$jsBuffer .= " aiAvatarUrl: '" . StringHelper::trim($this->params->get('aiAvatarUrl', '')) . "',\n";
$jsBuffer .= " projectName: '" . StringHelper::trim($this->params->get('projectName', 'Chat Support')) . "',\n";
$jsBuffer .= " inputPlaceholder: '" . StringHelper::trim($this->params->get('inputPlaceholder', '')) . "',\n";
$jsBuffer .= " chatSuggests: " . $this->params->get('chatSuggests', '[]') . ",\n";
$jsBuffer .= " userName: '" . $userName . "',\n";
$jsBuffer .= " userEmail: '" . $userEmail . "',\n";
$jsBuffer .= " userAvatarUrl: '" . $userAvatarUrl . "'\n";
$jsBuffer .= "});\n";
$jsBuffer .= "</script>\n";
$buffer = str_replace("</body>", $jsBuffer . "</body>", $buffer);
$this->app->setBody($buffer);
}
}