Plugin Directory

Changeset 2142981


Ignore:
Timestamp:
08/21/2019 08:37:10 AM (7 years ago)
Author:
tawkto
Message:

Added support for wildcard url match for include URL and exclude URL

Location:
tawkto-live-chat/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • tawkto-live-chat/trunk/readme.txt

    r2111964 r2142981  
    44Requires at least: 2.7
    55Tested up to: 5.2.2
    6 Stable tag: 0.3.8
     6Stable tag: 0.4.0
    77
    88(OFFICIAL tawk.to plugin) Instantly chat with  visitors on your website with the free tawk.to chat widget.
     
    9999* modified plugin settings page interface
    100100
    101 = 0.2.5 = 
     101= 0.2.5 =
    102102* Fixed include url warning message thrown
    103103
    104 = 0.2.6 = 
     104= 0.2.6 =
    105105* wrapped all hard-coded text in plugin settings with gettext functions
    106106
    107 = 0.2.7 = 
     107= 0.2.7 =
    108108* added woocommerce support
    109109
    110 = 0.2.8 = 
    111 * added updated plugin admin interface 
     110= 0.2.8 =
     111* added updated plugin admin interface
    112112
    113 = 0.2.9 = 
    114 * fixed issue with assets folder 
     113= 0.2.9 =
     114* fixed issue with assets folder
    115115
    116 = 0.3.0 = 
     116= 0.3.0 =
    117117* fixed issues with visibility filters
    118118
    119 = 0.3.0 = 
     119= 0.3.0 =
    120120* fixed issues with visibility filters
    121121
    122 = 0.3.1 = 
     122= 0.3.1 =
    123123* plugin notifications update
    124124* logged in user recognition
    125125  If user is logged in, the widget will fill the pre-chat form automatically
    126  
    127  = 0.3.2 =
     126
     127= 0.3.2 =
    128128* fixed issues on widget settings on fresh install
    129129
    130  = 0.3.3 =
     130= 0.3.3 =
    131131* fixed user recognition vulnerability
    132132* updated admin page texts
     
    148148* supported version bump 5.2.2
    149149
    150 ## Frequently Asked Questions
     150= 0.4.0 =
     151* Added support for wildcard url match for include URL and exclude URL
     152
     153## Frequently Asked Questions
    151154
    152155= How much does this cost? =
  • tawkto-live-chat/trunk/tawkto.php

    r2111964 r2142981  
    5656
    5757            wp_enqueue_script( 'tawk_admin_script', plugins_url( 'assets/tawk.admin.js' , __FILE__ ) );
    58        
     58
    5959        }
    6060
     
    7979            update_option(self::TAWK_WIDGET_ID_VARIABLE, $_POST['widgetId']);
    8080
    81            
     81
    8282            echo json_encode(array('success' => TRUE));
    8383            die();
     
    8686        function tawk_admin_notice() {
    8787
    88             if( isset($_GET["settings-updated"]) ) 
     88            if( isset($_GET["settings-updated"]) )
    8989            {
    9090                ?>
     
    139139                    .form-table th.tawksetting {
    140140                      width: 350px;
    141                     } 
     141                    }
    142142                    .tawknotice{
    143143                        font-size:14px;
     
    226226        }
    227227
    228         public function embed_code()
    229         {
     228        public function embed_code() {
    230229            $page_id = get_option('tawkto-embed-widget-page-id');
    231230            $widget_id = get_option('tawkto-embed-widget-widget-id');
    232231
    233             $customer_details = $this->getCurrentCustomerDetails();
    234            
    235             if(!empty($page_id) && !empty($widget_id))
    236             {
     232            $customer_details = $this->getCurrentCustomerDetails();
     233
     234            if (!empty($page_id) && !empty($widget_id)) {
    237235                include(sprintf("%s/templates/widget.php", dirname(__FILE__)));
    238236            }
    239237        }
    240238
    241         public function print_embed_code()
    242         {
    243             $vsibility = get_option( 'tawkto-visibility-options' );
    244            
    245             $display = FALSE;
    246 
    247             if(($vsibility['show_onfrontpage'] == 1) && (is_home() || is_front_page()) ){ $display = TRUE; }
    248             if(($vsibility['show_oncategory'] == 1) && is_category() ){ $display = TRUE; }
    249             if(($vsibility['show_ontagpage'] == 1) && is_tag() ){ $display = TRUE; }
    250             if($vsibility['always_display'] == 1){ $display = TRUE; }
    251             if(($vsibility['show_onarticlepages'] == 1) && is_single() ){ $display = TRUE; }
    252 
    253             if(($vsibility['exclude_url'] == 1)){
     239        private function get_current_url() {
     240            $current_url = $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
     241            $current_url = urldecode($current_url);
     242
     243            $protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 'https://' : 'http://';
     244
     245            return strtolower($protocol . $current_url);
     246        }
     247
     248        private function match_url($url, $url_pattern) {
     249            // do partial match if wildcard character matched at the end pattern
     250            if (substr($url_pattern, -1) === '*') {
     251                $url_pattern = substr($url_pattern, 0, -1);
     252
     253                return (strpos($url, $url_pattern) === 0);
     254            }
     255
     256            // do extact match if wildcard character not matched at the end pattern
     257            return (strcmp($url, $url_pattern) === 0);
     258        }
     259
     260        public function print_embed_code() {
     261            $vsibility = get_option('tawkto-visibility-options');
     262            $display = false;
     263
     264            if ($vsibility['always_display'] == 1) {
     265                $display = true;
     266            }
     267
     268            if (($vsibility['show_onfrontpage'] == 1) && (is_home() || is_front_page())) {
     269                $display = true;
     270            }
     271
     272            if (($vsibility['show_oncategory'] == 1) && is_category()) {
     273                $display = true;
     274            }
     275
     276            if (($vsibility['show_ontagpage'] == 1) && is_tag()) {
     277                $display = true;
     278            }
     279
     280            if (($vsibility['show_onarticlepages'] == 1) && is_single()) {
     281                $display = true;
     282            }
     283
     284            if (in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_option('active_plugins')))) {
     285                if (($vsibility['display_on_shop'] == 1) && is_shop()) {
     286                    $display = true;
     287                }
     288
     289                if (($vsibility['display_on_productcategory'] == 1) && is_product_category()) {
     290                    $display = true;
     291                }
     292
     293                if (($vsibility['display_on_productpage'] == 1) && is_product()) {
     294                    $display = true;
     295                }
     296
     297                if (($vsibility['display_on_producttag'] == 1) && is_product_tag()) {
     298                    $display = true;
     299                }
     300            }
     301
     302            if (isset($vsibility['include_url']) && $vsibility['include_url'] == 1) {
     303                $current_url = $this->get_current_url();
     304
     305                $included_url_list = $vsibility['included_url_list'];
     306                $included_url_list = preg_split("/,/", $included_url_list);
     307
     308                foreach ($included_url_list as $include_url) {
     309                    $include_url = strtolower(urldecode(trim($include_url)));
     310
     311                    if (!empty($include_url) && $this->match_url($current_url, $include_url)) {
     312                        $display = true;
     313                    }
     314                }
     315            }
     316
     317            if (isset($vsibility['exclude_url']) && ($vsibility['exclude_url'] == 1)) {
     318                $current_url = $this->get_current_url();
     319
    254320                $excluded_url_list = $vsibility['excluded_url_list'];
    255 
    256                 $current_url = $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"];
    257                 $current_url = urldecode($current_url);
    258 
    259                 $ssl      = ( ! empty( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] == 'on' );
    260                 $sp       = strtolower( $_SERVER['SERVER_PROTOCOL'] );
    261                 $protocol = substr( $sp, 0, strpos( $sp, '/' ) ) . ( ( $ssl ) ? 's' : '' );
    262 
    263                 $current_url = $protocol.'://'.$current_url;
    264                 $current_url = strtolower($current_url);
    265 
    266321                $excluded_url_list = preg_split("/,/", $excluded_url_list);
    267                 foreach($excluded_url_list as $exclude_url)
    268                 {
     322
     323                foreach ($excluded_url_list as $exclude_url) {
    269324                    $exclude_url = strtolower(urldecode(trim($exclude_url)));
    270                     if(!empty($exclude_url))
    271                     {
    272                         if (strpos($current_url, $exclude_url) !== false)
    273                         {
    274                             if(strcmp($current_url, $exclude_url) === 0)
    275                             {
    276                                 $display = false;
    277                             }
    278                         }
     325
     326                    if (!empty($exclude_url) && $this->match_url($current_url, $exclude_url)) {
     327                        $display = false;
    279328                    }
    280329                }
    281330            }
    282331
    283             if(isset($vsibility['include_url']) && $vsibility['include_url'] == 1){
    284                 $included_url_list = $vsibility['included_url_list'];
    285                 $current_url = $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"];
    286                 $current_url = urldecode($current_url);
    287 
    288                 $ssl      = ( ! empty( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] == 'on' );
    289                 $sp       = strtolower( $_SERVER['SERVER_PROTOCOL'] );
    290                 $protocol = substr( $sp, 0, strpos( $sp, '/' ) ) . ( ( $ssl ) ? 's' : '' );
    291 
    292                 $current_url = $protocol.'://'.$current_url;
    293                 $current_url = strtolower($current_url);
    294 
    295                 $included_url_list = preg_split("/,/", $included_url_list);
    296                 foreach($included_url_list as $include_url)
    297                 {
    298                     $include_url = strtolower(urldecode(trim($include_url)));
    299                     if(!empty($include_url))
    300                     {
    301                         if (strpos($current_url, $include_url) !== false)
    302                         {
    303                             if(strcmp($current_url, $include_url) === 0)
    304                             {
    305                                 $display = TRUE;
    306                             }
    307                         }
    308                     }
    309                 }
    310             }
    311 
    312             if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) )
    313             {
    314                 if(($vsibility['display_on_shop'] == 1) && is_shop() ){ $display = TRUE; }
    315                 if(($vsibility['display_on_productcategory'] == 1) && is_product_category() ){ $display = TRUE; }
    316                 if(($vsibility['display_on_productpage'] == 1) && is_product() ){ $display = TRUE; }
    317                 if(($vsibility['display_on_producttag'] == 1) && is_product_tag() ){ $display = TRUE; }
    318             }
    319 
    320             if($display == TRUE)
    321             {
     332            if ($display) {
    322333                $this->embed_code();
    323334            }
  • tawkto-live-chat/trunk/templates/settings.php

    r1700707 r2142981  
    77 * @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
    88**/
    9 if ( ! defined( 'ABSPATH' ) ) { 
     9if ( ! defined( 'ABSPATH' ) ) {
    1010    exit; // Exit if accessed directly
    1111}
     
    2727      <button class="tawktablinks" onclick="opentab(event, 'account')" id="defaultOpen">Account Settings</button>
    2828      <button class="tawktablinks" onclick="opentab(event, 'visibility')">Visibility Options</button>
    29         <?php 
    30         if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) 
     29        <?php
     30        if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) )
    3131        {
    3232        ?>
     
    3636
    3737    <div id="account" class="tawktabcontent" >
    38   <?php 
     38  <?php
    3939      $page_id = get_option(self::TAWK_PAGE_ID_VARIABLE);
    4040      $widget_id = get_option(self::TAWK_WIDGET_ID_VARIABLE);
     
    4949    }
    5050    if($override == TRUE){
    51         $display_widgetsettings = true; 
     51        $display_widgetsettings = true;
    5252    }
    5353  if ($display_widgetsettings == TRUE){
     
    8383                    widgetId : e.data.widgetId
    8484                }, function(r) {
    85                     if(r.success) { 
     85                    if(r.success) {
    8686                        e.source.postMessage({action: 'setDone'}, '<?php echo $base_url ?>');
    8787                    } else {
     
    141141    <BR>
    142142    <?php _e('on any page independent of these visibility options by simply using the <b>[tawkto]</b> shortcode in','tawk-to-live-chat'); ?>
    143     <BR> 
     143    <BR>
    144144    <?php _e('the post or page.','tawk-to-live-chat'); ?>
    145145    </p>
     
    199199        <div id="exlucded_urls_container" style="display:none;">
    200200        <textarea id="excluded_url_list" name="tawkto-visibility-options[excluded_url_list]" cols="50" rows="10"><?php echo $visibility['excluded_url_list']; ?></textarea><BR>
    201         <?php _e('Enter the url where you <b>DO NOT</b> want the widget to display.','tawk-to-live-chat'); ?>
    202         <BR>
     201        <?php _e('Enter the url where you <b>DO NOT</b> want the widget to display.','tawk-to-live-chat'); ?><BR>
    203202                <?php _e('Separate entries with comma','tawk-to-live-chat'); ?>(,).<BR>
     203        <?php _e('Add (*) at the end of the entry to match wildcard url.','tawk-to-live-chat'); ?><BR>
    204204        </div>
    205205      </td>
     
    216216        <?php _e('Enter the url where you <b>WANT</b> the widget to display.','tawk-to-live-chat'); ?><BR>
    217217                <?php _e('Separate entries with comma ','tawk-to-live-chat'); ?>(,).<BR>
     218        <?php _e('Add (*) at the end of the entry to match wildcard url.','tawk-to-live-chat'); ?><BR>
    218219        </div>
    219220      </td>
     
    224225
    225226    <div id="woocommerce" class="tawktabcontent">
    226        <?php 
    227        if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) 
     227       <?php
     228       if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) )
    228229       {
    229230
Note: See TracChangeset for help on using the changeset viewer.