-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathChatGPT.php
More file actions
84 lines (73 loc) · 2.52 KB
/
ChatGPT.php
File metadata and controls
84 lines (73 loc) · 2.52 KB
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
<?php
/**
* Matomo - free/libre analytics platform
*
* @link https://matomo.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
namespace Piwik\Plugins\ChatGPT;
class ChatGPT extends \Piwik\Plugin
{
public function registerEvents()
{
return array(
'AssetManager.getJavaScriptFiles' => 'getJavaScriptFiles',
'AssetManager.getStylesheetFiles' => 'getStylesheetFiles',
'Translate.getClientSideTranslationKeys' => 'getClientSideTranslationKeys',
);
}
public function getClientSideTranslationKeys(&$translationKeys)
{
$translationKeys[] = 'ChatGPT_Insights';
$translationKeys[] = 'ChatGPT_Loading';
$translationKeys[] = 'ChatGPT_Submit';
$translationKeys[] = 'ChatGPT_You';
$translationKeys[] = 'ChatGPT_AI';
$translationKeys[] = 'ChatGPT_ErrorMessage';
$translationKeys[] = 'ChatGPT_MessagePlaceholder';
$translationKeys[] = 'ChatGPT_AskQuestion';
$translationKeys[] = 'ChatGPT_InvalidResponse';
$translationKeys[] = 'ChatGPT_AnErrorOccurred';
$translationKeys[] = 'ChatGPT_NoResponseBody';
$translationKeys[] = 'ChatGPT_WaitingForResponse';
}
public function getJavaScriptFiles(&$files)
{
if ($this->pluginIsConfigured()) {
$files[] = "plugins/ChatGPT/assets/js/app.js";
}
}
public function getStylesheetFiles(&$files)
{
if ($this->pluginIsConfigured()) {
$files[] = "plugins/ChatGPT/assets/css/app.css";
}
}
private function pluginIsConfigured(): bool
{
try {
$settings = new SystemSettings();
// Check if settings properties exist and are properly initialized
if (!isset($settings->host) || $settings->host === null) {
return false;
}
if (!isset($settings->apiKey) || $settings->apiKey === null) {
return false;
}
$host = $settings->host->getValue();
$apiKey = $settings->apiKey->getValue();
if (empty($host)) {
return false;
}
// Custom host doesn't require API key
$isCustomHost = $host !== Config::DEFAULT_HOST;
if (!$isCustomHost && empty($apiKey)) {
return false;
}
return true;
} catch (\Throwable $e) {
// Catch any error during plugin installation/initialization
return false;
}
}
}