Skip to content

Commit 7373769

Browse files
Merge pull request #4 from alvinjohnsonso/feature/toggle-visitor-recognition
- added option to enable/disable visitor recognition feature - fixed checkboxes spacing
2 parents 9b4fd17 + c160d8b commit 7373769

File tree

3 files changed

+74
-35
lines changed

3 files changed

+74
-35
lines changed

tawk_to.module

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
/**
44
* @file
5-
* @package Tawk.to module for Drupal
6-
* @copyright (C) 2014- Tawk.to
5+
* @package tawk.to module for Drupal
6+
* @copyright (C) 2021 tawk.to
77
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
88
*/
99

@@ -45,12 +45,12 @@ function tawk_to_get_widget()
4545
function tawk_to_page_build(&$page)
4646
{
4747
global $base_url;
48-
48+
4949
// backend checking; do not show chat widget on admin page(s)
5050
if (path_is_admin(current_path())) {
5151
return;
5252
}
53-
53+
5454
$widget = tawk_to_get_widget();
5555

5656
if ($widget['page_id'] === '' || $widget['widget_id'] === '') {
@@ -61,9 +61,16 @@ function tawk_to_page_build(&$page)
6161

6262
// get visibility options
6363
$options = variable_get(TAWKTO_WIDGET_OPTIONS, '');
64+
$markupOptions = array(
65+
'enable_visitor_recognition' => true, // default value
66+
);
6467
if ($options) {
6568
$options = json_decode($options);
6669

70+
if (isset($options->enable_visitor_recognition)) {
71+
$markupOptions['enable_visitor_recognition'] = $options->enable_visitor_recognition;
72+
}
73+
6774
// prepare visibility
6875
$currentUrl = $base_url.$_SERVER["REQUEST_URI"];
6976
if (false==$options->always_display) {
@@ -77,18 +84,18 @@ function tawk_to_page_build(&$page)
7784
break;
7885
}
7986
}
80-
87+
8188
// taxonomy page
8289
if (arg(0) == "taxonomy" && arg(1) == "term" && is_numeric(arg(2)) && arg(3) == "") {
8390
if (false != $options->show_oncategory) {
8491
$show = true;
8592
}
8693
}
87-
94+
8895
if (drupal_is_front_page()) {
8996
if (false != $options->show_onfrontpage) {
9097
$show = true;
91-
}
98+
}
9299
}
93100

94101
if (!$show) {
@@ -98,19 +105,19 @@ function tawk_to_page_build(&$page)
98105
if (isset($options->hide_oncustom)) {
99106
$hide_pages = json_decode($options->hide_oncustom);
100107
$show = true;
101-
108+
102109
// $currentUrl = urlencode($current_page);
103110
$currentUrl = (string) $currentUrl;
104111
foreach ($hide_pages as $slug) {
105112
$slug = (string) htmlspecialchars($slug); // we need to add htmlspecialchars due to slashes added when saving to database
106-
113+
107114
// if (stripos($currentUrl, $slug)!==false) {
108115
if ($currentUrl == $slug) {
109116
$show = false;
110117
break;
111118
}
112119
}
113-
120+
114121
if (!$show) {
115122
return;
116123
}
@@ -119,8 +126,8 @@ function tawk_to_page_build(&$page)
119126
}
120127

121128
$page['page_bottom']['tawkto_widget'] = array(
122-
'#markup' => tawk_to_render_widget($page_id, $widget_id),
123-
);
129+
'#markup' => tawk_to_render_widget($page_id, $widget_id, $markupOptions),
130+
);
124131

125132
return $page;
126133
}
@@ -196,7 +203,7 @@ function tawkto_widget_customization()
196203
if (!empty($value) && $user->uid!=$value) {
197204
$sameUser = false;
198205
}
199-
206+
200207
$displayOpts = variable_get(TAWKTO_WIDGET_OPTIONS, '');
201208
if ($displayOpts && !empty($displayOpts)) {
202209
$displayOpts = json_decode($displayOpts);
@@ -275,6 +282,7 @@ function tawkto_widget_options()
275282
'show_oncategory' => false,
276283
'show_onproduct' => false,
277284
'show_oncustom' => array(),
285+
'enable_visitor_recognition' => false
278286
);
279287

280288
if (isset($_REQUEST['options']) && !empty($_REQUEST['options'])) {
@@ -291,13 +299,13 @@ function tawkto_widget_options()
291299
$value = (empty($value)||!$value)?array():$value;
292300
$jsonOpts[$column] = json_encode($value);
293301
break;
294-
302+
295303
case 'show_onfrontpage':
296304
case 'show_oncategory':
297305
case 'show_onproduct':
298306
case 'always_display':
299-
// default:
300-
$jsonOpts[$column] = ($value==1)?true:false;
307+
case 'enable_visitor_recognition':
308+
$jsonOpts[$column] = $value == 1;
301309
break;
302310
}
303311
}

views/admin.php.inc

Lines changed: 47 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?php
22
/**
33
* @file
4-
* @package Tawk.to module for Drupal
5-
* @copyright (C) 2014- Tawk.to
4+
* @package tawk.to module for Drupal
5+
* @copyright (C) 2021 tawk.to
66
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
77
*/
88

@@ -13,6 +13,18 @@ function tawk_to_render_widget_iframe($base_url, $iframe_url, $widget=array(), $
1313
{
1414
ob_start();
1515
?><link href="https://plugins.tawk.to/public/bootstrap/css/bootstrap.min.css" rel="stylesheet">
16+
<style>
17+
#module_form .checkbox {
18+
display: inline-block;
19+
min-height: 20px;
20+
}
21+
22+
@media only screen and (min-width: 1200px) {
23+
#module_form .checkbox {
24+
display: block;
25+
}
26+
}
27+
</style>
1628
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
1729
<?php if (!$sameUser) : ?>
1830
<div id="widget_already_set" style="width: 100%; float: left; color: #3c763d; border-color: #d6e9c6; font-weight: bold; margin: 20px 0 0;" class="alert alert-warning">Notice: Widget already set by other user</div>
@@ -42,7 +54,7 @@ function tawk_to_render_widget_iframe($base_url, $iframe_url, $widget=array(), $
4254
}
4355
}
4456
?>
45-
<input type="checkbox" class="col-lg-6" name="always_display" id="always_display" value="1"
57+
<input type="checkbox" class="checkbox" name="always_display" id="always_display" value="1"
4658
<?php echo ($checked)?'checked':'';?> />
4759
</div>
4860
</div>
@@ -51,7 +63,7 @@ function tawk_to_render_widget_iframe($base_url, $iframe_url, $widget=array(), $
5163
<div class="col-lg-6 control-label">
5264
<?php if (!empty($display_opts->hide_oncustom)) : ?>
5365
<?php $whitelist = json_decode($display_opts->hide_oncustom) ?>
54-
<textarea class="form-control hide_specific" name="hide_oncustom"
66+
<textarea class="form-control hide_specific" name="hide_oncustom"
5567
id="hide_oncustom" cols="30" rows="10"><?php foreach ($whitelist as $page) { echo $page."\r\n"; } ?></textarea>
5668
<?php else : ?>
5769
<textarea class="form-control hide_specific" name="hide_oncustom" id="hide_oncustom" cols="30" rows="10"></textarea>
@@ -63,7 +75,7 @@ function tawk_to_render_widget_iframe($base_url, $iframe_url, $widget=array(), $
6375
</p>
6476
</div>
6577
</div>
66-
78+
6779
<div class="form-group col-lg-12">
6880
<label for="show_onfrontpage" class="col-lg-6 control-label">Show on frontpage</label>
6981
<div class="col-lg-6 control-label ">
@@ -75,12 +87,12 @@ function tawk_to_render_widget_iframe($base_url, $iframe_url, $widget=array(), $
7587
}
7688
}
7789
?>
78-
<input type="checkbox" class="col-lg-6 show_specific" name="show_onfrontpage"
79-
id="show_onfrontpage" value="1"
90+
<input type="checkbox" class="checkbox show_specific" name="show_onfrontpage"
91+
id="show_onfrontpage" value="1"
8092
<?php echo ($checked)?'checked':'';?> />
8193
</div>
8294
</div>
83-
95+
8496
<div class="form-group col-lg-12">
8597
<label for="show_oncategory" class="col-lg-6 control-label">Show on category pages</label>
8698
<div class="col-lg-6 control-label ">
@@ -92,7 +104,7 @@ function tawk_to_render_widget_iframe($base_url, $iframe_url, $widget=array(), $
92104
}
93105
}
94106
?>
95-
<input type="checkbox" class="col-lg-6 show_specific" name="show_oncategory" id="show_oncategory" value="1"
107+
<input type="checkbox" class="checkbox show_specific" name="show_oncategory" id="show_oncategory" value="1"
96108
<?php echo ($checked)?'checked':'';?> />
97109
</div>
98110
</div>
@@ -101,7 +113,7 @@ function tawk_to_render_widget_iframe($base_url, $iframe_url, $widget=array(), $
101113
<div class="col-lg-6 control-label">
102114
<?php if (isset($display_opts->show_oncustom) && !empty($display_opts->show_oncustom)) : ?>
103115
<?php $whitelist = json_decode($display_opts->show_oncustom) ?>
104-
<textarea class="form-control show_specific" name="show_oncustom"
116+
<textarea class="form-control show_specific" name="show_oncustom"
105117
id="show_oncustom" cols="30" rows="10"><?php foreach ($whitelist as $page) { echo $page."\r\n"; } ?></textarea>
106118
<?php else : ?>
107119
<textarea class="form-control show_specific" name="show_oncustom" id="show_oncustom" cols="30" rows="10"></textarea>
@@ -113,16 +125,35 @@ function tawk_to_render_widget_iframe($base_url, $iframe_url, $widget=array(), $
113125
</p>
114126
</div>
115127
</div>
128+
129+
<div class="form-group col-lg-12">
130+
<div class="panel-heading"><strong>Privacy Options</strong></div>
131+
</div>
132+
<br>
133+
<div class="form-group col-lg-12">
134+
<label for="enable_visitor_recognition" class="col-lg-6 control-label">Enable Visitor Recognition</label>
135+
<div class="col-lg-6 control-label">
136+
<?php
137+
$checked = 'checked';
138+
if (!is_null($display_opts) && !$display_opts->enable_visitor_recognition) {
139+
$checked = '';
140+
}
141+
?>
142+
<input type="checkbox" class="checkbox" name="enable_visitor_recognition" id="enable_visitor_recognition" value="1"
143+
<?php echo $checked ?> />
144+
</div>
145+
</div>
116146
</div>
117-
<div class="panel-footer" style="position: relative; overflow: hidden; width: 100%; padding: 5px 0;">
118-
<div id="optionsSuccessMessage" style="position:absolute;top:0;left;0;background-color: #dff0d8; color: #3c763d; border-color: #d6e9c6; font-weight: bold;padding: 8px 15px; display: none;" class="alert alert-success col-lg-5">Successfully set widget options to your site</div>
119-
<label for="show_oncustom" class="col-lg-6 control-label"></label>
120-
<div class="form-group">
121-
<button type="submit" value="1" id="module_form_submit_btn" name="submitBlockCategories" class="btn btn-default pull-right"><i class="process-icon-save"></i> Save</button>
147+
<div class="panel-footer">
148+
<div class="col-lg-6 col-xs-12" style="text-align: right; margin-bottom: 10px;">
149+
<button type="submit" value="1" id="module_form_submit_btn" name="submitBlockCategories" class="btn btn-default"><i class="process-icon-save"></i> Save</button>
150+
</div>
151+
<div class="col-lg-6 col-xs-12" style="min-height: 60px;">
152+
<div id="optionsSuccessMessage" style="background-color: #dff0d8; color: #3c763d; border-color: #d6e9c6; font-weight:bold; display: none; margin-bottom: 0;" class="alert alert-success col-lg-12">Successfully set widget options to your site</div>
122153
</div>
123154
</div>
124155
</form>
125-
156+
126157
</div>
127158
<div class="col-lg-4"></div>
128159
</div>

views/widget.php.inc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22
/**
33
* @file
44
* @package tawk.to module for Drupal
5-
* @copyright (C) 2014- tawk.to
5+
* @copyright (C) 2021 tawk.to
66
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
77
*/
88

99
/**
1010
* Creates markup for embed script element.
1111
*/
12-
function tawk_to_render_widget($page_id, $widget_id)
12+
function tawk_to_render_widget($page_id, $widget_id, $options)
1313
{
1414
global $user;
1515
$apiString = '';
16-
if ($GLOBALS['user']->uid) {
16+
if ($GLOBALS['user']->uid && $options['enable_visitor_recognition']) {
1717
global $user;
1818
$apiString = '$_Tawk_API.visitor = {
1919
name : "'.$user->name.'",

0 commit comments

Comments
 (0)