Skip to content

Commit

Permalink
Merge pull request #3 from alvinjohnsonso/apply-coding-standards
Browse files Browse the repository at this point in the history
- fixed spacing format
- transferred backend functions to a separate file
- renamed main tawk to admin file name to `tawk_to_widget_admin.php`
- added build script
  • Loading branch information
alvinjohnsonso authored Mar 25, 2021
2 parents 1b3c386 + ec2dcd6 commit 1465617
Show file tree
Hide file tree
Showing 14 changed files with 966 additions and 214 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.zip
./build/tawk-zencart-*/
57 changes: 39 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,44 @@
tawk/tawk-zencart
================
# tawk.to Live Chat

# About tawk.to
tawk.to is a free live chat app that lets you monitor and chat with visitors on your website
or from a free customizable page. No catch. No spam. No wares. It's truly free and always will be.
Free live chat widget for your site

# Installation
Copy files to your Zen Cart directory. Zen Cart uses customized directories for admin
so you have to copy files from YOUR_ADMIN_FOLDER to folder where you have moved Zen Cart
admin files. Same thing applies to templates, copy includes/templates/YOUR_TEMPLATE content
to folder with template you are using
## Description

HINT: If you don't know what the template directory name you are using, then you can find it out by following these steps:
1) Login to your Zen Cart admin dashboard.
2) From the menu, Go to "Tools > Template Selection".
3) From the screen that shows Template Selection, look under the column that is titled "Template Directory". The name you find under that column is the template directory name that your Zen Cart site is currently using. That EXACT name is the one that you will use to replace each instance of "includes/templates/YOUR_TEMPLATE_FOLDER_NAME".
The tawk.to Live Chat app makes it easy to monitor and chat with visitors on your website. Be there when they need you with unlimited messaging, ticketing and your own Knowledge Base — all 100% FREE.

# Usage
Go to administration page -> tools -> Tawk.to widget and select widget you want to use in your
Zen Cart store, selected widget will appear in all the pages of your store.
Compatible with all modern browsers, tawk.to was created in response to the growing need for businesses to respond in real time, with real people.

If you don't have [tawk.to](https://tawk.to/?utm_source=zencart&utm_medium=link&utm_campaign=signup) account, you can always [create one for free](https://tawk.to/?utm_source=wpdirectory&utm_medium=link&utm_campaign=signup)
Never lose another lead or sale again — tawk.to offers iOS, Android, Windows and Mac OSX apps to keep you connected wherever you go.

Don’t have a tawk.to account yet? [Create one here.](https://tawk.to/?utm_source=zencart&utm_medium=link&utm_campaign=signup)

## Installation
1. Extract the zip file.
2. Copy the contents of the `YOUR_ADMIN_FOLDER` to `<ZENCART_INSTALLATION>`/`<YOUR_ADMIN_FOLDER>`
3. Copy the contents of the `includes`/`templates`/`YOUR_TEMPLATE` to `<ZENCART_INSTALLATION>`/`includes`/`templates`/`<YOUR_CURRENT_TEMPLATE>`.
4. Copy the other contents of the `includes` folder to `<ZENCART_INSTALLATION>`/`includes`.

NOTE: If you don't know what the template directory name you are using, then you can find it out by following these steps:
1. Go to `Dashboard` -> `Tools` -> `Template Selection`.
2. From the screen that shows `Template Selection`, look under the column that is titled `Template Directory`. You can find the name of your template directory that your Zen Cart site is currently using. That `EXACT` name is the one that you will use to replace each instance of `<YOUR_CURRENT_TEMPLATE>`.

## Widget Configuration
1. Go to `Dashboard` -> `Tools` -> `tawk.to widget`.
2. Log in to your tawk.to account.
3. Select the property and the widget you want to place on your store and click `Use selected widget`.
4. The widget will now appear on your store.

## How To Remove
Delete all the files included in this module. These are the files with `tawk_to` in the filename and can be found under these folders:
- `includes`/`extra_datafiles`
- `includes`/`templates`/`YOUR_TEMPLATE`/`jscript`
- `YOUR_ADMIN_FOLDER`
- `YOUR_ADMIN_FOLDER`/`includes`/`auto_loaders`
- `YOUR_ADMIN_FOLDER`/`includes`/`extra_datafiles`
- `YOUR_ADMIN_FOLDER`/`includes`/`functions`
- `YOUR_ADMIN_FOLDER`/`includes`/`functions`/`extra_functions`
- `YOUR_ADMIN_FOLDER`/`includes`/`init_includes`
- `YOUR_ADMIN_FOLDER`/`includes`/`languages`/`english`/`extra_definitions`

## Frequently Asked Questions
Visit our [Help Center](https://help.tawk.to/) for answers to FAQs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php
if (!defined('IS_ADMIN_FLAG')) {
die('Illegal Access');
die('Illegal Access');
}

$autoLoadConfig[999][] = array(
'autoType' => 'init_script',
'loadFile' => 'init_tawk_to_widget.php'
);
'autoType' => 'init_script',
'loadFile' => 'init_tawk_to_widget.php'
);
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
define('TAWK_TO_PAGE_ID_FIELD', 'tawk_to_page_id');
define('TAWK_TO_WIDGET_ID_FIELD', 'tawk_to_widget_id');
define('FILENAME_TAWK_TO_WIDGET', 'tawk_to_widget');
define('TAWK_TO_WIDGET_BASE_URL', 'https://plugins.tawk.to');
define('TAWK_TO_PAGE_ID_FIELD', 'tawk_to_page_id');
define('TAWK_TO_WIDGET_ID_FIELD', 'tawk_to_widget_id');
define('FILENAME_TAWK_TO_WIDGET', 'tawk_to_widget_admin');
define('TAWK_TO_WIDGET_BASE_URL', 'https://plugins.tawk.to');
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
// generated!
//
if (function_exists('zen_register_admin_page')) {
if (!zen_page_key_exists('tawkToWidget')) {
zen_register_admin_page('tawkToWidget', 'BOX_TOOLS_TAWK_TO_WIDGET', 'FILENAME_TAWK_TO_WIDGET','' , 'tools', 'Y', 999);
}
// $page_key, $language_key, $main_page, $page_params, $menu_key, $display_on_menu, $sort_order
if (!zen_page_key_exists('tawkToWidget')) {
zen_register_admin_page('tawkToWidget', 'BOX_TOOLS_TAWK_TO_WIDGET', 'FILENAME_TAWK_TO_WIDGET','' , 'tools', 'Y', 999);
}
// $page_key, $language_key, $main_page, $page_params, $menu_key, $display_on_menu, $sort_order
} else {
die('no register function');
}
die('no register function');
}
9 changes: 4 additions & 5 deletions YOUR_ADMIN_FOLDER/includes/functions/init_tawk_to_widget.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
if (!defined('IS_ADMIN_FLAG')) {
die('Illegal Access');
}
die('init tawk')

//----
// If the installation supports admin-page registration (i.e. v1.5.0 and later), then
Expand All @@ -17,7 +16,7 @@
// generated!
//
if (function_exists('zen_register_admin_page')) {
if (!zen_page_key_exists('tawkToWidget')) {
zen_register_admin_page('tawkToWidget', 'BOX_TOOLS_TAWK_TO_WIDGET', 'FILENAME_TAWK_TO_WIDGET','' , 'tools', 'Y', 999);
}
}
if (!zen_page_key_exists('tawkToWidget')) {
zen_register_admin_page('tawkToWidget', 'BOX_TOOLS_TAWK_TO_WIDGET', 'FILENAME_TAWK_TO_WIDGET', '', 'tools', 'Y', 999);
}
}
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<?php
define('BOX_TOOLS_TAWK_TO_WIDGET', 'Tawk.to widget');
define('BOX_TOOLS_TAWK_TO_WIDGET', 'tawk.to widget');
155 changes: 0 additions & 155 deletions YOUR_ADMIN_FOLDER/tawk_to_widget.php

This file was deleted.

106 changes: 106 additions & 0 deletions YOUR_ADMIN_FOLDER/tawk_to_widget_admin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<?php
/**
* @package tawk.to
* @copyright Copyright 2021 tawk.to
* @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
* @version 1.1.0
*/

require('includes/application_top.php');

$tawk_widget_current_values = array(
'page_id' => zen_get_configuration_key_value(TAWK_TO_PAGE_ID_FIELD),
'widget_id' => zen_get_configuration_key_value(TAWK_TO_WIDGET_ID_FIELD)
);

//zen cart returns span with error message if configuration key can't be found
if (strpos($tawk_widget_current_values['page_id'], '<') === 0) {
$tawk_widget_current_values['page_id'] = '';
$tawk_widget_current_values['widget_id'] = '';
}
?>

<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html <?php echo HTML_PARAMS; ?>>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">
<title><?php echo TITLE; ?></title>
<link rel="stylesheet" type="text/css" href="includes/stylesheet.css">
<link rel="stylesheet" type="text/css" href="includes/cssjsmenuhover.css" media="all" id="hoverJS">
<script language="javascript" src="includes/menu.js"></script>
<script language="javascript" src="includes/general.js"></script>
<script type="text/javascript" src="<?php echo TAWK_TO_WIDGET_BASE_URL ?>/public/js/jquery-1.11.0.min.js"></script>
<script type="text/javascript">
function init()
{
cssjsmenu('navbar');
if (document.getElementById) {
var kill = document.getElementById('hoverJS');
kill.disabled = true;
}
}
</script>

</head>
<body onload="init()">
<!-- header //-->
<?php require(DIR_WS_INCLUDES . 'header.php'); ?>
<!-- header_eof //-->

<!-- body //-->
<div style="width:100%; height: 100%; margin: 10px auto">
<iframe id="tawkIframe" src="" style="width:100%; height: 100%; border: none"></iframe>
</div>
<script type="text/javascript">
var currentHost = window.location.protocol + "//" + window.location.host;
var url = "<?php echo TAWK_TO_WIDGET_BASE_URL ?>/generic/widgets?currentWidgetId=<?php echo $tawk_widget_current_values['widget_id'] ?>&currentPageId=<?php echo $tawk_widget_current_values['page_id']?>&parentDomain=" + currentHost;

jQuery('#tawkIframe').attr('src', url);

var iframe = jQuery('#tawk_widget_customization')[0];

window.addEventListener('message', function(e) {
if (e.origin === '<?php echo TAWK_TO_WIDGET_BASE_URL ?>') {

if(e.data.action === 'setWidget') {
setWidget(e);
}

if(e.data.action === 'removeWidget') {
removeWidget(e);
}
}
});

function setWidget(e) {
jQuery.post('tawk_to_widget_manager.php?actionType=set', {
page_id : e.data.pageId,
widget_id : e.data.widgetId
}, function(r) {
if (r.success) {
e.source.postMessage({action: 'setDone'}, '<?php echo TAWK_TO_WIDGET_BASE_URL ?>');
} else {
e.source.postMessage({action: 'setFail'}, '<?php echo TAWK_TO_WIDGET_BASE_URL ?>');
}

});
}

function removeWidget(e) {
jQuery.post('tawk_to_widget_manager.php?actionType=remove', {}, function(r) {
if (r.success) {
e.source.postMessage({action: 'removeDone'}, '<?php echo TAWK_TO_WIDGET_BASE_URL ?>');
} else {
e.source.postMessage({action: 'removeFail'}, '<?php echo TAWK_TO_WIDGET_BASE_URL ?>');
}
});
}
</script>
<!-- body_eof //-->

<!-- footer //-->
<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
<!-- footer_eof //-->
</body>
</html>
<?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>
Loading

0 comments on commit 1465617

Please sign in to comment.