Skip to content

Commit

Permalink
Must be in folder (ZIP) for CMS manual upload
Browse files Browse the repository at this point in the history
  • Loading branch information
krsiakdaniel committed Jul 12, 2018
1 parent 06a43fb commit 18b0d90
Show file tree
Hide file tree
Showing 56 changed files with 4,031 additions and 0 deletions.
26 changes: 26 additions & 0 deletions smartsupp.ocmod/install.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<modification>
<name>Smartsupp Live Chat</name>
<code>smartsupp</code>
<version>1.0</version>
<author>Kurzor</author>
<link>http://www.smartsupp.com</link>
<file path="catalog/view/theme/default/template/common/footer.twig">
<operation>
<search><![CDATA[</footer>]]></search>
<add position="before"><![CDATA[
{{ smartSupp }}
]]></add>
</operation>
</file>
<file path="catalog/controller/common/footer.php">
<operation>
<search><![CDATA[
return $this->load->view('common/footer', $data);
]]></search>
<add position="before"><![CDATA[
$data['smartSupp'] = $this->load->controller('extension/module/smartsupp');
]]></add>
</operation>
</file>
</modification>
125 changes: 125 additions & 0 deletions smartsupp.ocmod/upload/admin/controller/extension/module/smartsupp.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
<?php
/**
* @author Tomáš Blatný
*/

use Smartsupp\Auth\Api;


require __DIR__ . '/../../../../system/library/smartsupp/vendor/autoload.php';

class ControllerExtensionModuleSmartsupp extends Controller
{

const SETTING_NAME = 'smartsupp';

public function index()
{
$this->load->language('extension/module/smartsupp');
$this->load->model('setting/setting');

$settings = $this->model_setting_setting->getSetting(self::SETTING_NAME);

$message = NULL;
$formAction = NULL;

if (isset($_GET['action'])) {
switch ($_GET['action']) {
case 'disable':
$this->model_setting_setting->deleteSetting(self::SETTING_NAME);
break;
case 'login':
case 'register':
$api = new Api;
$data = array(
'email' => $_POST['email'],
'password' => $_POST['password'],
);
$result = $_GET['action'] === 'register' ? $api->create($data + array('lang' => $this->language->get('code'))) : $api->login($data + array('partnerKey' => 'j29hnc919y'));
if (isset($result['error'])) {
$message = $result['message'];
$formAction = $_GET['action'];
$data['email'] = $_POST['email'];
} else {
$this->model_setting_setting->editSetting(self::SETTING_NAME, array(
self::SETTING_NAME . 'firstRun' => TRUE,
self::SETTING_NAME . 'email' => $_POST['email'],
self::SETTING_NAME . 'chatId' => $result['account']['key'],
self::SETTING_NAME . 'customCode' => ''
));
}
break;
case 'update':
$smartsupp = $this->model_setting_setting->getSetting(self::SETTING_NAME);
$smartsupp[self::SETTING_NAME . 'customCode'] = $_POST['code'];
$this->model_setting_setting->editSetting(self::SETTING_NAME, $smartsupp);
$message = 'Custom code was updated.';
break;
}
}

$that = $this;
$data['translator'] = new SmartsuppModuleExtensionTranslator($_ = function ($text) use ($that) {
return $that->language->get($text);
});

if (isset($this->request->server['HTTPS']) && (($this->request->server['HTTPS'] == 'on') || ($this->request->server['HTTPS'] == '1'))) {
$base = HTTPS_SERVER;
} else {
$base = HTTP_SERVER;
}

$base = rtrim($base, '/\\');

$this->document->addScript($base . '/view/javascript/smartsupp.js');
$this->document->addStyle($base . '/view/stylesheet/bootstrap-smartsupp.css');
$this->document->addStyle($base . '/view/stylesheet/smartsupp.css');
$this->document->setTitle($title = $_('headingTitle'));

$settings = $this->model_setting_setting->getSetting(self::SETTING_NAME);
if (isset($settings[self::SETTING_NAME . 'email'])) {
$data['email'] = $settings[self::SETTING_NAME . 'email'];
$data['enabled'] = TRUE;
} else {
$data['enabled'] = FALSE;
}
if (isset($settings[self::SETTING_NAME . 'customCode'])) {
$data['customCode'] = $settings[self::SETTING_NAME . 'customCode'];
}
$data['base'] = $base;
$data['headingTitle'] = $title;

if (isset($_GET['action'])) {
$data['header'] = '';
$data['leftMenu'] = '';
$data['footer'] = '';
} else {
$data['header'] = $this->load->controller('common/header');
$data['leftMenu'] = $this->load->controller('common/column_left');
$data['footer'] = $this->load->controller('common/footer');
}

$data['message'] = $message;
$data['formAction'] = $formAction;

$this->response->setOutput($this->load->view('extension/module/smartsupp', $data));
}

}

class SmartsuppModuleExtensionTranslator
{
private $translateFunc;

public function __construct($translateFunc)
{
$this->translateFunc = $translateFunc;
}

public function translate($text)
{
$tr = $this->translateFunc;
return $tr($text);

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php
/**
* @author Tomáš Blatný
*/

$_['headingTitle'] = 'Smartsupp';
$_['heading_title'] = 'Smartsupp';
$_['deactivateChat'] = 'Deactivate Chat';
$_['infoSmartsuppText'] = "Smartsupp’s chat box is now visible on your website.";
$_['goToSmartsuppText'] = 'Go to Smartsupp to chat with visitors, customize chat box design and access all features.';
$_['goToSmartsupp'] = 'Go to Smartsupp';
$_['openInNewTab'] = '(This will open a new browser tab)';
$_['advancedSettings'] = 'Advanced settings';
$_['optionalCode'] = 'Don\'t put the chat code here — this box is for (optional) advanced customizations via <a href="https://developers.smartsupp.com?utm_source=OpenCart&utm_medium=integration&utm_campaign=link" target="_blank">Smartsupp API</a>';
$_['saveChanges'] = 'Save changes';
$_['connectAccount'] = 'Connect existing account';
$_['freeChat'] = 'Free live chat with visitor recording';
$_['customersOnWebsite'] = 'Your customers are on your website right now.';
$_['chatWithThem'] = 'Chat with them and see what they do.';
$_['createAccount'] = 'Create a free account';
$_['freeOrPremium'] = 'Enjoy unlimited agents and chats forever for free<br />or take advantage of premium packages with advanced features.';
$_['allFeatures'] = '<strong>See all features on </strong><a href="https://www.smartsupp.com?utm_source=OpenCart&utm_medium=integration&utm_campaign=link" target="_blank"> our website.';
$_['chatInRealTime'] = 'Chat with visitors in real-time';
$_['loyalty'] = 'Answering questions right away improves loyalty and helps you build closer relationships with your customers.';
$_['increaseSales'] = 'Increase online sales';
$_['visitorsToCustomers'] = 'Turn your visitors into customers.<br />Visitors who chat with you buy up to 5x more often - measurable in Google Analytics.';
$_['screenRecording'] = 'Visitor screen recording';
$_['visitorBehavior'] = 'Watch visitor\'s behavior on your store.<br />You see his screen, mouse movement, clicks and what he filled into forms.';
$_['email'] = 'E-mail';
$_['password'] = 'Password';
$_['connectAccountButton'] = 'Connect account';
$_['signUp'] = 'Sign up';
$_['trusted'] = 'Trusted by more than 55 000 companies';
$_['Email does not exist'] = 'Email does not exist';
$_['Invalid password'] = 'Invalid password';
$_['Email is required'] = 'Email is required';
$_['Email already exists'] = 'Email already exists';
$_['Password is too short. Minimal length is 6 characters.'] = 'Password is too short. Minimal length is 6 characters.';
$_['Custom code was updated.'] = 'Custom code was updated.';
$_['Invalid action'] = 'Invalid action';
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
116 changes: 116 additions & 0 deletions smartsupp.ocmod/upload/admin/view/javascript/smartsupp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
(function ($, document, undefined) {
$(function () {
var lastOpen = null;

function openForm(type) {
lastOpen = type;
updateTexts(type);
updateClass(type);
$('#home').hide();
$('#connect').show();
$('.js-clear').hide();
}

function closeForm() {
$('#connect').hide();
$('#home').show();
}

function updateClass(type) {
if (type === 'login') {
$('[data-toggle-class]').addClass('js-login-form').removeClass('js-register-form');
} else {
$('[data-toggle-class]').removeClass('js-login-form').addClass('js-register-form');
}
}

function updateTexts(type) {
$('[data-multitext]').each(function () {
$(this).text($(this).data(type));
})
}

function decodeQueryString(query) {
var params = {}, tokens, regexp = /[?&]?([^=]+)=([^&]*)/g;
query = query.split('+').join(' ');
while (tokens = regexp.exec(query)) {
params[decodeURIComponent(tokens[1])] = decodeURIComponent(tokens[2]);
}
return params;
}

function getToken() {
var params = decodeQueryString(document.location.search);
return params.user_token;
}

function getLink(action) {
var params = decodeQueryString(document.location.search);
return '?user_token=' + params.user_token + '&route=' + params.route + '&action=' + action;
}

function getBaseLink() {
var params = decodeQueryString(document.location.search);
return '?user_token=' + params.user_token + '&route=common/dashboard';
}

var $content = $('#content'), $document = $(document);

$document.on('click', '.js-login', function () {
openForm('login');
}).on('click', '.js-register', function () {
openForm('register');
}).on('click', '[data-toggle-form]', function () {
if (lastOpen === 'login') {
openForm('register');
} else {
openForm('login');
}
}).on('click', '.js-close-form', function () {
closeForm();
}).on('click', '.js-action-disable', function () {
$content.load(getLink('disable') + ' #content');
}).on('click', '.js-remove-plugin', function () {
if (confirm('Do you really want to remove Smartsupp plugin and all it\'s data? This action cannot be undone.')) {
$content.load(getLink('remove') + ' #content', function () {
document.location.href = getBaseLink();
});
}
}).on('submit', '.js-login-form', function (event) {
event.preventDefault();
var $loader = $(this).find('.loader'), $button = $(this).find('button'), $loginForm = $('.js-login-form');
$button.hide();
$loader.show();
$content.load(getLink('login') + ' #content', {
email: $loginForm.find('input[name="email"]').val(),
password: $loginForm.find('input[name="password"]').val()
}, function () {
$loader.hide();
$button.show();
});
}).on('submit', '.js-register-form', function (event) {
event.preventDefault();
var $loader = $(this).find('.loader'), $button = $(this).find('button'), $registerForm = $('.js-register-form');
$button.hide();
$loader.show();
$content.load(getLink('register') + ' #content', {
email: $registerForm.find('input[name="email"]').val(),
password: $registerForm.find('input[name="password"]').val()
}, function () {
$loader.hide();
$button.show();
});
}).on('submit', '.js-code-form', function (event) {
event.preventDefault();
var $loader = $(this).find('.loader'), $button = $(this).find('button'), $codeForm = $('.js-code-form');
$button.hide();
$loader.show();
$content.load(getLink('update') + ' #content', {
code: $codeForm.find('textarea[name="code"]').val()
}, function () {
$loader.hide();
$button.show();
});
});
});
})(jQuery, document);
Loading

0 comments on commit 18b0d90

Please sign in to comment.