Skip to content

Commit f3b6d0c

Browse files
authored
Merge pull request #10 from wanasyraf96/include-composer-install-build
Implement URL pattern matching with include and exclude options
2 parents b390298 + 89af2cd commit f3b6d0c

File tree

9 files changed

+252
-33
lines changed

9 files changed

+252
-33
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
# exclude docker files from archive
22
/docker export-ignore
3+
/.github export-ignore

.github/workflows/release.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: create-release-artifact
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
jobs:
8+
create-release-artifact:
9+
name: Creating release artifact
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: checkout
13+
uses: actions/checkout@v2
14+
15+
- name: cached dependencies
16+
uses: actions/cache@v2
17+
id: cached-dependencies
18+
with:
19+
path: ./tawk_to/vendor
20+
# the key will change if composer.lock changes
21+
key: ${{ runner.os }}-dependencies-${{ hashFiles('**/composer.lock') }}
22+
23+
- name: install dependencies
24+
uses: php-actions/composer@v6
25+
with:
26+
command: run build:prod
27+
28+
- name: build artifact
29+
run: composer run package && mv ./tmp/tawk_to.zip tawk_to.zip
30+
31+
- name: upload artifact
32+
uses: actions/upload-release-asset@v1
33+
env:
34+
GITHUB_TOKEN: ${{ github.token }}
35+
with:
36+
upload_url: ${{ github.event.release.upload_url }}
37+
asset_path: ./tawk_to.zip
38+
asset_name: tawk_to.zip
39+
asset_content_type: application/zip

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
11
docker/bin
2+
/tawk_to/vendor
3+
/vendor
4+
/tmp

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ Don't have a tawk.to account yet? [Create one here.](https://www.tawk.to/?utm_so
1414
## Installation
1515

1616
### Module Installer
17-
1. Download the [plugin module](https://www.drupal.org/project/tawkto).
17+
1. Download the `tawk_to.zip` from [latest release.](https://github.com/tawk/tawk-drupal8/releases).
1818
2. Log in to the your administration panel and click on `Extend`.
1919
3. In the module list, click on the `Install new module` button.
2020
4. Click on `Choose File`, select the downloaded module, and click on the `Install` button.
2121
5. After the installation completes, click on `Enable newly added modules` to complete the installation.
2222

2323
### Manual Installation
24-
1. Download the [plugin module](https://www.drupal.org/project/tawkto) and extract the contents.
24+
1. Download the `tawk_to.zip` from [latest release.](https://github.com/tawk/tawk-drupal8/releases).
2525
2. In the extracted files, copy the `tawkto` directory to the `<DRUPAL_INSTALLATION>/modules` directory.
2626
3. Log in to the your administration panel and click on `Extend`.
2727
4. In the module list, search for `tawk.to` and enable the module by ticking the checkbox beside `tawk.to Module`.

composer.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "tawk/tawk-drupal8",
3+
"description": "tawk.to Live Chat module for Drupal 8 CMS",
4+
"type": "project",
5+
"license": "GPLv3",
6+
"require": {
7+
"tawk/url-utils": "2.0.1"
8+
},
9+
"repositories": {
10+
"tawk-url-utils": {
11+
"type": "vcs",
12+
"url": "https://github.com/tawk/tawk-url-utils.git"
13+
}
14+
},
15+
"scripts": {
16+
"build:prod": "COMPOSER_VENDOR_DIR=./tawk_to/vendor composer install --no-dev",
17+
"package": "composer run clean && mkdir -p ./tmp && cp -r ./tawk_to ./tmp && (cd ./tmp && zip -9 -rq ./tawk_to.zip ./tawk_to)",
18+
"clean": "rm -rf ./tmp"
19+
}
20+
}

composer.lock

Lines changed: 68 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docker/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ Docker containers for Drupal
1010
- install docker-compose [http://docs.docker.com/compose/install/](http://docs.docker.com/compose/install/)
1111

1212
## Usage
13+
Build using defined environment:
14+
- ```cd ./docker && ./build.sh envs/<env-file>```
15+
1316
Start the container:
1417
- ```docker-compose --env-file envs/<env-file> up```
1518

docker/build.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ fi
1212
echo "Creating module folder";
1313
mkdir -p $module_dir;
1414

15+
echo "Installing dependency"
16+
composer run build:prod --working-dir=$build_dir/..
17+
1518
echo "Copying files to module folder";
1619
cp -r $build_dir/../tawk_to/* $module_dir
1720

tawk_to/src/core/TawktoGenerator.php

Lines changed: 113 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
<?php
22
namespace Drupal\tawk_to\core;
33

4+
require_once drupal_get_path('module', 'tawk_to').'/vendor/autoload.php';
5+
46
use Symfony\Component\HttpFoundation\JsonResponse;
57
use \Drupal\Core\Cache\Cache;
8+
use Tawk\Modules\UrlPatternMatcher;
69

710
define('TAWK_TO_WIDGET_PID', 'tawk_to_widget_pid'); // page ID
811
define('TAWK_TO_WIDGET_WID', 'tawk_to_widget_wid'); // widget ID
@@ -89,17 +92,8 @@ private function shouldDisplayWidget($options = null)
8992
// prepare visibility
9093
$currentUrl = $base_url.$_SERVER["REQUEST_URI"];
9194
if ($options->always_display == false) {
92-
93-
$showPages = json_decode($options->show_oncustom);
94-
foreach ($showPages as $slug) {
95-
if (empty(trim($slug))) {
96-
continue;
97-
}
98-
99-
if ($currentUrl == $slug) {
100-
$show = true;
101-
break;
102-
}
95+
if (UrlPatternMatcher::match($currentUrl, $showPages)) {
96+
$show = true;
10397
}
10498

10599
// check if category/taxonomy page
@@ -121,18 +115,8 @@ private function shouldDisplayWidget($options = null)
121115
$show = true;
122116

123117
$currentUrl = (string) $currentUrl;
124-
foreach ($hide_pages as $slug) {
125-
126-
if (empty(trim($slug))) {
127-
continue;
128-
}
129-
130-
$slug = (string) htmlspecialchars($slug); // we need to add htmlspecialchars due to slashes added when saving to database
131-
132-
if ($currentUrl == $slug) {
133-
$show = false;
134-
break;
135-
}
118+
if (UrlPatternMatcher::match($currentUrl, $hide_pages)) {
119+
$show = false;
136120
}
137121
}
138122

@@ -203,6 +187,46 @@ public function getIframe()
203187
display: block;
204188
}
205189
}
190+
191+
/* Tooltip */
192+
.tooltip {
193+
position: relative;
194+
display: inline;
195+
color: #03a84e;
196+
}
197+
198+
.tooltip .tooltiptext {
199+
visibility: hidden;
200+
background-color: #545454;
201+
color: #fff;
202+
text-align: center;
203+
padding: 0.5rem;
204+
max-width: 300px;
205+
border-radius: 0.5rem;
206+
line-height: 0.9;
207+
208+
/* Position the tooltip text - see examples below! */
209+
position: absolute;
210+
z-index: 1000;
211+
top: 12px;
212+
}
213+
214+
.tooltip .tooltiptext::before {
215+
content: "";
216+
display: block;
217+
width: 0;
218+
height: 0;
219+
position: absolute;
220+
border-left: 5px solid transparent;
221+
border-right: 5px solid transparent;
222+
border-bottom: 5px solid #545454;
223+
top: -5px;
224+
left: 5px;
225+
}
226+
227+
.tooltip:hover .tooltiptext {
228+
visibility: visible;
229+
}
206230
</style>
207231
<?php if (!$sameUser) : ?>
208232
<div id="widget_already_set" style="width: 100%; float: left; color: #3c763d; border-color: #d6e9c6; font-weight: bold; margin: 20px 0;" class="alert alert-warning">Notice: Widget already set by other user</div>
@@ -247,10 +271,39 @@ public function getIframe()
247271
<textarea class="form-control hide_specific" name="hide_oncustom" id="hide_oncustom" cols="30" rows="10"></textarea>
248272
<?php endif; ?>
249273
<br>
250-
<p style="text-align: justify;">
251-
Add URLs to pages in which you would like to hide the widget. ( if "always show" is checked )<br>
252-
Put each URL in a new line.
253-
</p>
274+
<div style="text-align: justify;">
275+
Add URLs/paths to pages in which you would like to hide the widget.<br>
276+
Put each URL/path in a new line. Paths should have a leading '/'.
277+
<br>
278+
<div class="tooltip">
279+
Examples of accepted path patterns
280+
<ul class="tooltiptext">
281+
<li>*</li>
282+
<li>*/to/somewhere</li>
283+
<li>/*/to/somewhere</li>
284+
<li>/path/*/somewhere</li>
285+
<li>/path/*/lead/*/somewhere</li>
286+
<li>/path/*/*/somewhere</li>
287+
<li>/path/to/*</li>
288+
<li>/path/to/*/</li>
289+
<li>*/to/*/page</li>
290+
<li>/*/to/*/page</li>
291+
<li>/path/*/other/*</li>
292+
<li>/path/*/other/*/</li>
293+
<li>http://www.example.com/</li>
294+
<li>http://www.example.com/*</li>
295+
<li>http://www.example.com/*/to/somewhere</li>
296+
<li>http://www.example.com/path/*/somewhere</li>
297+
<li>http://www.example.com/path/*/lead/*/somewhere</li>
298+
<li>http://www.example.com/path/*/*/somewhere</li>
299+
<li>http://www.example.com/path/to/*</li>
300+
<li>http://www.example.com/path/to/*/</li>
301+
<li>http://www.example.com/*/to/*/page</li>
302+
<li>http://www.example.com/path/*/other/*</li>
303+
<li>http://www.example.com/path/*/other/*/</li>
304+
</ul>
305+
</div>
306+
</div>
254307
</div>
255308
</div>
256309

@@ -298,10 +351,39 @@ public function getIframe()
298351
<textarea class="form-control show_specific" name="show_oncustom" id="show_oncustom" cols="30" rows="10"></textarea>
299352
<?php endif; ?>
300353
<br>
301-
<p style="text-align: justify;">
302-
Add URLs to pages in which you would like to show the widget.<br>
303-
Put each URL in a new line.
304-
</p>
354+
<div style="text-align: justify;">
355+
Add URLs/paths to pages in which you would like to show the widget.<br>
356+
Put each URL/path in a new line. Paths should have a leading '/'.
357+
<br>
358+
<div class="tooltip">
359+
Examples of accepted path patterns
360+
<ul class="tooltiptext">
361+
<li>*</li>
362+
<li>*/to/somewhere</li>
363+
<li>/*/to/somewhere</li>
364+
<li>/path/*/somewhere</li>
365+
<li>/path/*/lead/*/somewhere</li>
366+
<li>/path/*/*/somewhere</li>
367+
<li>/path/to/*</li>
368+
<li>/path/to/*/</li>
369+
<li>*/to/*/page</li>
370+
<li>/*/to/*/page</li>
371+
<li>/path/*/other/*</li>
372+
<li>/path/*/other/*/</li>
373+
<li>http://www.example.com/</li>
374+
<li>http://www.example.com/*</li>
375+
<li>http://www.example.com/*/to/somewhere</li>
376+
<li>http://www.example.com/path/*/somewhere</li>
377+
<li>http://www.example.com/path/*/lead/*/somewhere</li>
378+
<li>http://www.example.com/path/*/*/somewhere</li>
379+
<li>http://www.example.com/path/to/*</li>
380+
<li>http://www.example.com/path/to/*/</li>
381+
<li>http://www.example.com/*/to/*/page</li>
382+
<li>http://www.example.com/path/*/other/*</li>
383+
<li>http://www.example.com/path/*/other/*/</li>
384+
</ul>
385+
</div>
386+
</div>
305387
</div>
306388
</div>
307389
</div>

0 commit comments

Comments
 (0)