Add all files
This commit is contained in:
106
extensions/Others/OpenWidget/OpenWidget.php
Normal file
106
extensions/Others/OpenWidget/OpenWidget.php
Normal file
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
|
||||
namespace Paymenter\Extensions\Others\OpenWidget;
|
||||
|
||||
use App\Classes\Extension\Extension;
|
||||
|
||||
class OpenWidget extends Extension
|
||||
{
|
||||
public function getName(): string
|
||||
{
|
||||
return 'OpenWidget Live Chat';
|
||||
}
|
||||
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'Integrates OpenWidget into your site for real-time customer support and engagement.';
|
||||
}
|
||||
|
||||
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' => 'OpenWidget ID',
|
||||
'description' => 'Your OpenWidget organization ID (from the OpenWidget configurator).',
|
||||
'required' => true,
|
||||
'value' => $values['widget_id'] ?? '',
|
||||
],
|
||||
[
|
||||
'name' => 'show_on_admin',
|
||||
'type' => 'checkbox',
|
||||
'label' => 'Show on Admin Panel',
|
||||
'description' => 'Enable OpenWidget on admin panel pages.',
|
||||
'required' => false,
|
||||
'value' => $values['show_on_admin'] ?? false,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function boot(): void
|
||||
{
|
||||
if (!request()->isMethod('GET')) {
|
||||
return;
|
||||
}
|
||||
|
||||
// I think that it's questionable if you want this on admin pages....
|
||||
if (request()->is('admin*') && !$this->config('show_on_admin', false)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->injectWidget();
|
||||
}
|
||||
|
||||
private function injectWidget(): void
|
||||
{
|
||||
if (!function_exists('app') || !app()->bound('view')) return;
|
||||
|
||||
echo $this->getWidgetScript();
|
||||
}
|
||||
|
||||
private function getWidgetScript(): string
|
||||
{
|
||||
static $injected = false;
|
||||
if ($injected) return '';
|
||||
$injected = true;
|
||||
|
||||
$widgetId = $this->config('widget_id', '');
|
||||
|
||||
if (empty($widgetId)) {
|
||||
return "<!-- OpenWidget ID not configured -->";
|
||||
}
|
||||
|
||||
return <<<HTML
|
||||
<!-- OpenWidget widget -->
|
||||
<script>
|
||||
window.__ow = window.__ow || {};
|
||||
window.__ow.organizationId = "$widgetId";
|
||||
(function(n,t,c,p,e,a,s){
|
||||
n[p]=n[p]||function(){(n[p].q=n[p].q||[]).push(arguments)};
|
||||
a=t.createElement(c),s=t.getElementsByTagName(c)[0];
|
||||
a.async=!0;a.src=e;s.parentNode.insertBefore(a,s)
|
||||
})(window,document,"script","ow","https://cdn.openwidget.com/openwidget.js");
|
||||
</script>
|
||||
HTML;
|
||||
}
|
||||
|
||||
public function enabled(): void {}
|
||||
public function disabled(): void {}
|
||||
public function updated(): void {}
|
||||
|
||||
public function install(): void
|
||||
{
|
||||
// Send it to the void!
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user