11<?php
22namespace Drupal \tawk_to \core ;
33
4+ require_once drupal_get_path ('module ' , 'tawk_to ' ).'/vendor/autoload.php ' ;
5+
46use Symfony \Component \HttpFoundation \JsonResponse ;
57use \Drupal \Core \Cache \Cache ;
8+ use Tawk \Modules \UrlPatternMatcher ;
69
710define ('TAWK_TO_WIDGET_PID ' , 'tawk_to_widget_pid ' ); // page ID
811define ('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