99 lines
2.4 KiB
PHP
99 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace Paymenter\Extensions\Others\JivoChat;
|
|
|
|
use App\Classes\Extension\Extension;
|
|
|
|
class JivoChat extends Extension
|
|
{
|
|
public function getName(): string
|
|
{
|
|
return 'JivoChat Live Chat';
|
|
}
|
|
|
|
public function getDescription(): string
|
|
{
|
|
return 'Integrates JivoChat live chat widget into your site for real-time customer support.';
|
|
}
|
|
|
|
public function getVersion(): string
|
|
{
|
|
return '1.0';
|
|
}
|
|
|
|
public function getAuthor(): string
|
|
{
|
|
return 'QKingsoftware';
|
|
}
|
|
|
|
public function getConfig($values = []): array
|
|
{
|
|
return [
|
|
[
|
|
'name' => 'widget_id',
|
|
'type' => 'text',
|
|
'label' => 'JivoChat Widget ID',
|
|
'description' => 'Your JivoChat Widget ID (found in JivoChat settings).',
|
|
'required' => true,
|
|
'value' => $values['widget_id'] ?? '',
|
|
],
|
|
[
|
|
'name' => 'show_on_admin',
|
|
'type' => 'checkbox',
|
|
'label' => 'Show on Admin Panel',
|
|
'description' => 'Enable JivoChat widget on admin panel pages.',
|
|
'required' => false,
|
|
'value' => $values['show_on_admin'] ?? false,
|
|
],
|
|
];
|
|
}
|
|
|
|
public function boot(): void
|
|
{
|
|
if (!request()->isMethod('GET')) {
|
|
return;
|
|
}
|
|
|
|
// I dont like it on admin but it's your preference.....
|
|
if (request()->is('admin*') && !$this->config('show_on_admin', false)) {
|
|
return;
|
|
}
|
|
|
|
$this->injectJivoChat();
|
|
}
|
|
|
|
private function injectJivoChat(): void
|
|
{
|
|
if (!function_exists('app') || !app()->bound('view')) return;
|
|
|
|
echo $this->getJivoChatScript();
|
|
}
|
|
|
|
private function getJivoChatScript(): string
|
|
{
|
|
static $injected = false;
|
|
if ($injected) return '';
|
|
$injected = true;
|
|
|
|
$widgetId = $this->config('widget_id', '');
|
|
|
|
if (empty($widgetId)) {
|
|
return "<!-- JivoChat widget ID not configured -->";
|
|
}
|
|
|
|
return <<<HTML
|
|
<!-- JivoChat Itself -->
|
|
<script src="//code.jivo.ru/widget/$widgetId" async></script>
|
|
HTML;
|
|
}
|
|
|
|
public function enabled(): void {}
|
|
public function disabled(): void {}
|
|
public function updated(): void {}
|
|
|
|
public function install(): void
|
|
{
|
|
// Nothing
|
|
}
|
|
}
|