Plugin Directory


Ignore:
Timestamp:
10/28/2023 12:20:52 AM (18 months ago)
Author:
jonas.hjalmarsson
Message:

Security updates - all attributes now escaped

Location:
hk-filter-and-search
Files:
12 added
2 deleted
2 edited
3 copied

Legend:

Unmodified
Added
Removed
  • hk-filter-and-search/tags/2.8/hk-filter-and-search.php

    r2957037 r2985200  
    44Plugin URI: http://wordpress.org/plugins/hk-filter-and-search
    55Description: Easy way to enable jquery HTML filter or a CSV-file-search to a webpage. Use the shortcodes [csvsearch] and [filtersearch] to enable.
    6 Version: 2.7
     6Version: 2.8
    77Author: jonashjalmarsson
    88Author URI: https://jonashjalmarsson.se
    99License: GPLv3
    10 Text domain: hk-filter-and-search
     10Text Domain: hk-filter-and-search
     11Domain Path: /languages
    1112*/
    1213
    1314namespace hk_filter_and_search;
    1415
     16if ( ! defined( 'ABSPATH' ) ) {
     17    exit; // Exit if accessed directly.
     18}
     19
     20/*
     21 * load textdomain
     22 */
     23function hk_load_textdomain() {
     24    load_plugin_textdomain( 'hk-filter-and-search', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
     25}
     26add_action( 'init', __NAMESPACE__ . '\\hk_load_textdomain' );
     27
     28/*
     29 * enqueue scripts
     30 */
    1531function hk_filter_search_scripts() {
    1632    if ( ! wp_script_is( 'jquery', 'enqueued' )) {
     
    3046            'charset' => 'iso-8859-1',
    3147            'format' => '{b}{0}{/b}, {1}, {2}{br/}',
    32             'searchtext' => 'sök',
     48            'searchtext' => __('Search', 'hk-filter-and-search'),
    3349            'instantformat' => '{0}',
    3450            'instantsearch' => 'false',
    3551            'dataidformat' => "{0}",
    3652            'csv_separator' => ";",
    37             'nothing_found_message' => 'Nothing found when searching for: ',
     53            'nothing_found_message' => __('Nothing found when searching for: ', 'hk-filter-and-search'),
    3854            'placeholder_text' => '',
    3955            'exact_match' => 'false',
     
    4460            'ignore_default_header_style' => 'false',
    4561            'set_focus_on_load' => 'false',
    46         ), $atts );
    47 
    48     /*foreach ( $defaults as $default => $value ) { // add defaults
    49         if ( ! @array_key_exists( $default, $atts ) ) { // mute warning with "@" when no params at all
    50             $atts[$default] = $value;
    51         }
    52     }*/
    53 
    54    
     62    ), $atts );
     63
     64    $atts = hk_escape_atts($atts);
     65
    5566    $src = $atts["src"];
    5667   
     
    5869    $html .= "<div class='content-container  csv-container'>";
    5970
    60     $src = $atts["src"];
    6171    $src = trim($src, '\'"”`´ ');
     72
     73    if (empty($src)) {
     74        $html .= '<b>' . __('No file found or not a valid .csv file!', 'hk-filter-and-search') . '</b><br/>';
     75        $html .= '<b>' . __("Src has to be set and point to a .csv file.", 'hk-filter-and-search') . '</b><br/>';
     76        $html .= '</div><!-- END HK CSV search -->';
     77        return wp_kses_post($html);
     78    }
     79
    6280    $rand = rand(0,10000);
    6381    $charset = $atts["charset"];
     
    7492    $dataidformat = $atts["dataidformat"];
    7593    $csv_separator = $atts["csv_separator"];
     94    $nothing_found_message = $atts["nothing_found_message"];
    7695    $placeholder_text = $atts["placeholder_text"];
    7796    $only_search_in_column = $atts["only_search_in_column"];
     
    114133    $src_without_site_url = str_replace($site_url, '', $src);
    115134   
    116 
    117     $file_valid = true;
    118     if (empty($src)) {
    119         $html .= '<b>No file found!</b><br/>';
    120         $html .= "<b>Src has to be set to use csvsearch shortcode.</b><br/>";
    121         $file_valid = false;
    122     }
    123    
    124135    if ($skip_file_check == "true") {
    125136        // skip file check
     
    132143    }
    133144    else {
    134         $html .= "<b>File: " . $src . " not found.</b> Only support for local files.<br/>";
    135         $file_valid = false;
    136     }
    137 
    138     if ($file_valid) {
    139         $html .= '<div class="hk-csv-search-wrapper">';
    140         $html .= '<form method="POST" class="hk-csv-search-form-'.$rand.'">';
    141         $html .= '<input type="text" name="hk-csv-input" class="hk-csv-input" ' . $autofocus . '/>';
    142         $html .= '<input type="submit" name="hk-csv-button" class="hk-csv-button" value="' . $search_text . '" />';
    143         if ($instantsearch == "true") {
    144             $html .= '<div class="hk-csv-instantsearch">'.$placeholder_text.'</div>';       
    145         }
    146         $html .= '<div class="hk-csv-search-output">'.$placeholder_text.'</div>';
    147         $html .= '</form></div>';
    148     }
    149    
     145        /* translators: %s: filename */
     146        $html .= __(sprintf("<b>File: %s not found.</b> Only support for local files.", $src), 'hk-filter-and-search') . '<br />';
     147        $html .= '</div><!-- END HK CSV search -->';
     148        return wp_kses_post($html);
     149    }
     150
     151    $keep_writing = __('Keep writing...', 'hk-filter-and-search');
     152
     153    $html .= '<div class="hk-csv-search-wrapper">';
     154    $html .= '<form method="POST" class="hk-csv-search-form-'.$rand.'">';
     155    $html .= '<input type="text" name="hk-csv-input" class="hk-csv-input" ' . $autofocus . '/>';
     156    $html .= '<input type="submit" name="hk-csv-button" class="hk-csv-button" value="' . $search_text . '" />';
     157    if ($instantsearch == "true") {
     158        $html .= '<div class="hk-csv-instantsearch">'.$placeholder_text.'</div>';       
     159    }
     160    $html .= '<div class="hk-csv-search-output">'.$placeholder_text.'</div>';
     161    $html .= '</form></div>';
    150162    $html .= '</div>'."\n";
    151163   
    152     $html .= '<style>.hk_header_row { font-weight: bold } .hk-csv-instant-list { list-style-type: none; margin-left: 0; display: inline-block; border: 1px solid #ddd; } .hk-csv-instant-list li { padding: 4px; } .hk-csv-instant-list li:hover { background-color: #ddd; }</style>'."\n";
    153     $html .= '<script>
     164    $style = '.hk_header_row { font-weight: bold } .hk-csv-instant-list { list-style-type: none; margin-left: 0; display: inline-block; border: 1px solid #ddd; } .hk-csv-instant-list li { padding: 4px; } .hk-csv-instant-list li:hover { background-color: #ddd; }';
     165    $js = '
    154166        (function($) {
    155167            show_header_row_' . $rand . ' = ' . $show_header_row . ';
    156168            $(document).ready(function () {
    157169                var lines' . $rand . ' = [];
    158                 var nothing_msg_' . $rand . ' = "' . $atts['nothing_found_message'] . '";
     170                var nothing_msg_' . $rand . ' = "' . $nothing_found_message . '";
    159171                // search button
    160172                $( ".hk-csv-search-form-' . $rand . '" ).submit(function( event ) {
     
    185197                // on list click
    186198                $(document).on("click", ".hk-csv-search-form-' . $rand . ' .hk-csv-instant-list li a", function(event){
    187                     //$(".hk-csv-search-form-' . $rand . ' .hk-csv-instant-list li a").click( function(event){
    188                         event.preventDefault();
    189                         search = $(this).data("id");
    190                         if (search != "") {
    191                             $(this).parents("ul").remove();
    192                         }
    193                        
    194                         doSearch' . $rand . '(search);
    195                     });
     199                    event.preventDefault();
     200                    search = $(this).data("id");
     201                    if (search != "") {
     202                        $(this).parents("ul").remove();
     203                    }
     204                   
     205                    doSearch' . $rand . '(search);
     206                });
    196207                   
    197208                   
    198                     // do search
    199                     function doSearch' . $rand . '(search) {
    200                         if (search != "") {
    201                             $(".hk-csv-search-form-' . $rand . ' .hk-csv-search-output").html("");
    202                             var output = searchData' . $rand . '(search);
    203                            
     209                // do search
     210                function doSearch' . $rand . '(search) {
     211                    if (search != "") {
     212                        $(".hk-csv-search-form-' . $rand . ' .hk-csv-search-output").html("");
     213                        var output = searchData' . $rand . '(search);
     214                       
    204215                        if ((!show_header_row_' . $rand . ' && output.length == 0) || (show_header_row_' . $rand . ' && output.length <= 1)) {
    205                             $(".hk-csv-search-form-' . $rand . ' .hk-csv-search-output").append(nothing_msg_' . $rand . ' + search);
     216                            $(".hk-csv-search-form-' . $rand . ' .hk-csv-search-output").append(nothing_msg_' . $rand . ' + " " + search);
    206217                        }
    207218                        else {
     
    220231                                retline = retline.replace(/\{/g,"<");
    221232                                retline = retline.replace(/\}/g,">");
    222                                 //retline = retline.toLowerCase();
    223233                                $(".hk-csv-search-form-' . $rand . ' .hk-csv-search-output").append(retline);
    224234                            }
     
    233243                    var output = searchData' . $rand . '(search);
    234244                    if (search.length < 3) {
    235                         $(event).parents(".hk-csv-search-wrapper").find(".hk-csv-instantsearch").html("<ul class=\'hk-csv-instant-list\'><li>Forts&auml;tt skriva...</li></ul>");
     245                        $(event).parents(".hk-csv-search-wrapper").find(".hk-csv-instantsearch").html("<ul class=\'hk-csv-instant-list\'><li>' . $keep_writing . '</li></ul>");
    236246                    }
    237247                    else {
     
    339349
    340350        })(jQuery);
    341         </script>
     351       
    342352    ';
    343     $html .= "\n".'<!-- END HK CSV search -->'."\n";
    344 
    345 
    346     return $html;
     353   
     354    return wp_kses(
     355            $html,
     356            array(
     357                'a'      => array(
     358                    'href'  => array(),
     359                    'title' => array(),
     360                ),
     361                'br'     => array(),
     362                'em'     => array(),
     363                'strong' => array(),
     364                'div' => array(
     365                    'class' => array(),
     366                ),
     367                'form' => array(
     368                    'method' => array(),
     369                    'class' => array(),
     370                ),
     371                'input' => array(
     372                    'type' => array(),
     373                    'name' => array(),
     374                    'class' => array(),
     375                    'value' => array(),
     376                ),
     377            ) ) .
     378        "<script>" . $js . "</script>\n" .
     379        "<style>" . esc_attr($style) . "</style>\n" .
     380        '<!-- END HK CSV search -->'."\n";
    347381}
    348382
     
    359393            'search_element' => 'table',
    360394            'show_header_in_table' => 'false',
    361             'text' => 's&ouml;k p&aring; denna sida',
     395            'text' => __('Search on this site', 'hk-filter-and-search'),
    362396            'clear_icon_class' => 'delete-icon',
    363397            'clear_text' => '',
     
    365399            'set_focus_on_load' => 'true',
    366400        ), $atts );
     401       
     402    $atts = hk_escape_atts($atts);
    367403
    368404    $html = "";
     
    405441    $html .= "</div>";
    406442    /* add default filter style */
    407     $html .= '<style>
     443    $style = '
    408444        .filtersearch' . $rand . ' {
    409445            background-color: #C6CACB;
     
    434470            display: none;
    435471            cursor: pointer;
    436         </style>';
     472        ';
    437473    /* add the jquery script, the script uses random id to work even if added more than once in a page */
    438     $html .= '<script>
     474    $warning_text = __('Warning: Nothing to filter!', 'hk-filter-and-search');
     475    $js = '
    439476        (function($) {
    440477            /* case insensitive contain */
     
    469506                if ($(selected_element) === undefined || $(selected_element).length == 0) {
    470507                    if($("#hk_filter_warning'.$rand.'").length > 0) {
    471                         $("#hk_filter_warning'.$rand.'").html("<b>Warning: Nothing to filter!</b>");
     508                        $("#hk_filter_warning'.$rand.'").html("<b>'.$warning_text.'</b>");
    472509                    }
    473510                    else {
    474                         $(el).after("<p id=\"hk_filter_warning'.$rand.'\"><b>Warning: Nothing to filter!</b></p>");
     511                        $(el).after("<p id=\"hk_filter_warning'.$rand.'\"><b>'.$warning_text.'</b></p>");
    475512                    }
    476513                }
     
    540577
    541578        })(jQuery);
    542         </script>
    543579    ';
    544     $html .= "\n".'<!-- END HK filter search -->'."\n";
    545 
    546     return $html;
     580
     581    return wp_kses(
     582            $html,
     583            array(
     584                'span' => array(
     585                    'class' => array(),
     586                ),
     587                'div' => array(
     588                    'class' => array(),
     589                ),
     590                'input' => array(
     591                    'type' => array(),
     592                    'name' => array(),
     593                    'class' => array(),
     594                    'value' => array(),
     595                ),
     596            ) ) .
     597        "<script>" . $js . "</script>\n" .
     598        "<style>" . esc_attr($style) . "</style>\n" .
     599        '<!-- END HK filter search -->'."\n";
    547600}
    548601
     
    556609
    557610
    558 
     611function hk_escape_atts($atts) {
     612    foreach($atts as $key => $value) {
     613        if ($key == "src") {
     614            $atts[$key] = esc_url($value);
     615            // ignore src if not ending with .csv
     616            if (substr($atts[$key], -4) != ".csv") {
     617                $atts[$key] = "";
     618            }
     619        }
     620        else {
     621            $atts[$key] = esc_attr($value);
     622        }
     623    }
     624    return $atts;
     625}
     626
     627
  • hk-filter-and-search/tags/2.8/readme.txt

    r2957037 r2985200  
    33Tags: filter, csv, excel, search, jquery
    44Requires at least: 5.0
    5 Tested up to: 6.3
    6 Stable tag: 2.7
     5Tested up to: 6.3.2
     6Stable tag: 2.8
    77License: GPLv3
     8Text Domain: hk-filter-and-search
     9Domain Path: /languages
    810License URI: http://www.gnu.org/licenses/gpl.html
    911
     
    103105== Changelog ==
    104106
     107= 2.8 =
     108Major security fix. Attributes escaped. Cross scripting fix. Please update to this version!
     109Translation added. Swedish and English.
     110
    105111= 2.7 =
    106112Bugfixes for filtersearch, search per td cell if filtering table. Support if thead is used in table.
    107 
    108113
    109114= 2.6 =
  • hk-filter-and-search/trunk/hk-filter-and-search.php

    r2957037 r2985200  
    44Plugin URI: http://wordpress.org/plugins/hk-filter-and-search
    55Description: Easy way to enable jquery HTML filter or a CSV-file-search to a webpage. Use the shortcodes [csvsearch] and [filtersearch] to enable.
    6 Version: 2.7
     6Version: 2.8
    77Author: jonashjalmarsson
    88Author URI: https://jonashjalmarsson.se
    99License: GPLv3
    10 Text domain: hk-filter-and-search
     10Text Domain: hk-filter-and-search
     11Domain Path: /languages
    1112*/
    1213
    1314namespace hk_filter_and_search;
    1415
     16if ( ! defined( 'ABSPATH' ) ) {
     17    exit; // Exit if accessed directly.
     18}
     19
     20/*
     21 * load textdomain
     22 */
     23function hk_load_textdomain() {
     24    load_plugin_textdomain( 'hk-filter-and-search', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
     25}
     26add_action( 'init', __NAMESPACE__ . '\\hk_load_textdomain' );
     27
     28/*
     29 * enqueue scripts
     30 */
    1531function hk_filter_search_scripts() {
    1632    if ( ! wp_script_is( 'jquery', 'enqueued' )) {
     
    3046            'charset' => 'iso-8859-1',
    3147            'format' => '{b}{0}{/b}, {1}, {2}{br/}',
    32             'searchtext' => 's&ouml;k',
     48            'searchtext' => __('Search', 'hk-filter-and-search'),
    3349            'instantformat' => '{0}',
    3450            'instantsearch' => 'false',
    3551            'dataidformat' => "{0}",
    3652            'csv_separator' => ";",
    37             'nothing_found_message' => 'Nothing found when searching for: ',
     53            'nothing_found_message' => __('Nothing found when searching for: ', 'hk-filter-and-search'),
    3854            'placeholder_text' => '',
    3955            'exact_match' => 'false',
     
    4460            'ignore_default_header_style' => 'false',
    4561            'set_focus_on_load' => 'false',
    46         ), $atts );
    47 
    48     /*foreach ( $defaults as $default => $value ) { // add defaults
    49         if ( ! @array_key_exists( $default, $atts ) ) { // mute warning with "@" when no params at all
    50             $atts[$default] = $value;
    51         }
    52     }*/
    53 
    54    
     62    ), $atts );
     63
     64    $atts = hk_escape_atts($atts);
     65
    5566    $src = $atts["src"];
    5667   
     
    5869    $html .= "<div class='content-container  csv-container'>";
    5970
    60     $src = $atts["src"];
    6171    $src = trim($src, '\'"”`´ ');
     72
     73    if (empty($src)) {
     74        $html .= '<b>' . __('No file found or not a valid .csv file!', 'hk-filter-and-search') . '</b><br/>';
     75        $html .= '<b>' . __("Src has to be set and point to a .csv file.", 'hk-filter-and-search') . '</b><br/>';
     76        $html .= '</div><!-- END HK CSV search -->';
     77        return wp_kses_post($html);
     78    }
     79
    6280    $rand = rand(0,10000);
    6381    $charset = $atts["charset"];
     
    7492    $dataidformat = $atts["dataidformat"];
    7593    $csv_separator = $atts["csv_separator"];
     94    $nothing_found_message = $atts["nothing_found_message"];
    7695    $placeholder_text = $atts["placeholder_text"];
    7796    $only_search_in_column = $atts["only_search_in_column"];
     
    114133    $src_without_site_url = str_replace($site_url, '', $src);
    115134   
    116 
    117     $file_valid = true;
    118     if (empty($src)) {
    119         $html .= '<b>No file found!</b><br/>';
    120         $html .= "<b>Src has to be set to use csvsearch shortcode.</b><br/>";
    121         $file_valid = false;
    122     }
    123    
    124135    if ($skip_file_check == "true") {
    125136        // skip file check
     
    132143    }
    133144    else {
    134         $html .= "<b>File: " . $src . " not found.</b> Only support for local files.<br/>";
    135         $file_valid = false;
    136     }
    137 
    138     if ($file_valid) {
    139         $html .= '<div class="hk-csv-search-wrapper">';
    140         $html .= '<form method="POST" class="hk-csv-search-form-'.$rand.'">';
    141         $html .= '<input type="text" name="hk-csv-input" class="hk-csv-input" ' . $autofocus . '/>';
    142         $html .= '<input type="submit" name="hk-csv-button" class="hk-csv-button" value="' . $search_text . '" />';
    143         if ($instantsearch == "true") {
    144             $html .= '<div class="hk-csv-instantsearch">'.$placeholder_text.'</div>';       
    145         }
    146         $html .= '<div class="hk-csv-search-output">'.$placeholder_text.'</div>';
    147         $html .= '</form></div>';
    148     }
    149    
     145        /* translators: %s: filename */
     146        $html .= __(sprintf("<b>File: %s not found.</b> Only support for local files.", $src), 'hk-filter-and-search') . '<br />';
     147        $html .= '</div><!-- END HK CSV search -->';
     148        return wp_kses_post($html);
     149    }
     150
     151    $keep_writing = __('Keep writing...', 'hk-filter-and-search');
     152
     153    $html .= '<div class="hk-csv-search-wrapper">';
     154    $html .= '<form method="POST" class="hk-csv-search-form-'.$rand.'">';
     155    $html .= '<input type="text" name="hk-csv-input" class="hk-csv-input" ' . $autofocus . '/>';
     156    $html .= '<input type="submit" name="hk-csv-button" class="hk-csv-button" value="' . $search_text . '" />';
     157    if ($instantsearch == "true") {
     158        $html .= '<div class="hk-csv-instantsearch">'.$placeholder_text.'</div>';       
     159    }
     160    $html .= '<div class="hk-csv-search-output">'.$placeholder_text.'</div>';
     161    $html .= '</form></div>';
    150162    $html .= '</div>'."\n";
    151163   
    152     $html .= '<style>.hk_header_row { font-weight: bold } .hk-csv-instant-list { list-style-type: none; margin-left: 0; display: inline-block; border: 1px solid #ddd; } .hk-csv-instant-list li { padding: 4px; } .hk-csv-instant-list li:hover { background-color: #ddd; }</style>'."\n";
    153     $html .= '<script>
     164    $style = '.hk_header_row { font-weight: bold } .hk-csv-instant-list { list-style-type: none; margin-left: 0; display: inline-block; border: 1px solid #ddd; } .hk-csv-instant-list li { padding: 4px; } .hk-csv-instant-list li:hover { background-color: #ddd; }';
     165    $js = '
    154166        (function($) {
    155167            show_header_row_' . $rand . ' = ' . $show_header_row . ';
    156168            $(document).ready(function () {
    157169                var lines' . $rand . ' = [];
    158                 var nothing_msg_' . $rand . ' = "' . $atts['nothing_found_message'] . '";
     170                var nothing_msg_' . $rand . ' = "' . $nothing_found_message . '";
    159171                // search button
    160172                $( ".hk-csv-search-form-' . $rand . '" ).submit(function( event ) {
     
    185197                // on list click
    186198                $(document).on("click", ".hk-csv-search-form-' . $rand . ' .hk-csv-instant-list li a", function(event){
    187                     //$(".hk-csv-search-form-' . $rand . ' .hk-csv-instant-list li a").click( function(event){
    188                         event.preventDefault();
    189                         search = $(this).data("id");
    190                         if (search != "") {
    191                             $(this).parents("ul").remove();
    192                         }
    193                        
    194                         doSearch' . $rand . '(search);
    195                     });
     199                    event.preventDefault();
     200                    search = $(this).data("id");
     201                    if (search != "") {
     202                        $(this).parents("ul").remove();
     203                    }
     204                   
     205                    doSearch' . $rand . '(search);
     206                });
    196207                   
    197208                   
    198                     // do search
    199                     function doSearch' . $rand . '(search) {
    200                         if (search != "") {
    201                             $(".hk-csv-search-form-' . $rand . ' .hk-csv-search-output").html("");
    202                             var output = searchData' . $rand . '(search);
    203                            
     209                // do search
     210                function doSearch' . $rand . '(search) {
     211                    if (search != "") {
     212                        $(".hk-csv-search-form-' . $rand . ' .hk-csv-search-output").html("");
     213                        var output = searchData' . $rand . '(search);
     214                       
    204215                        if ((!show_header_row_' . $rand . ' && output.length == 0) || (show_header_row_' . $rand . ' && output.length <= 1)) {
    205                             $(".hk-csv-search-form-' . $rand . ' .hk-csv-search-output").append(nothing_msg_' . $rand . ' + search);
     216                            $(".hk-csv-search-form-' . $rand . ' .hk-csv-search-output").append(nothing_msg_' . $rand . ' + " " + search);
    206217                        }
    207218                        else {
     
    220231                                retline = retline.replace(/\{/g,"<");
    221232                                retline = retline.replace(/\}/g,">");
    222                                 //retline = retline.toLowerCase();
    223233                                $(".hk-csv-search-form-' . $rand . ' .hk-csv-search-output").append(retline);
    224234                            }
     
    233243                    var output = searchData' . $rand . '(search);
    234244                    if (search.length < 3) {
    235                         $(event).parents(".hk-csv-search-wrapper").find(".hk-csv-instantsearch").html("<ul class=\'hk-csv-instant-list\'><li>Forts&auml;tt skriva...</li></ul>");
     245                        $(event).parents(".hk-csv-search-wrapper").find(".hk-csv-instantsearch").html("<ul class=\'hk-csv-instant-list\'><li>' . $keep_writing . '</li></ul>");
    236246                    }
    237247                    else {
     
    339349
    340350        })(jQuery);
    341         </script>
     351       
    342352    ';
    343     $html .= "\n".'<!-- END HK CSV search -->'."\n";
    344 
    345 
    346     return $html;
     353   
     354    return wp_kses(
     355            $html,
     356            array(
     357                'a'      => array(
     358                    'href'  => array(),
     359                    'title' => array(),
     360                ),
     361                'br'     => array(),
     362                'em'     => array(),
     363                'strong' => array(),
     364                'div' => array(
     365                    'class' => array(),
     366                ),
     367                'form' => array(
     368                    'method' => array(),
     369                    'class' => array(),
     370                ),
     371                'input' => array(
     372                    'type' => array(),
     373                    'name' => array(),
     374                    'class' => array(),
     375                    'value' => array(),
     376                ),
     377            ) ) .
     378        "<script>" . $js . "</script>\n" .
     379        "<style>" . esc_attr($style) . "</style>\n" .
     380        '<!-- END HK CSV search -->'."\n";
    347381}
    348382
     
    359393            'search_element' => 'table',
    360394            'show_header_in_table' => 'false',
    361             'text' => 's&ouml;k p&aring; denna sida',
     395            'text' => __('Search on this site', 'hk-filter-and-search'),
    362396            'clear_icon_class' => 'delete-icon',
    363397            'clear_text' => '',
     
    365399            'set_focus_on_load' => 'true',
    366400        ), $atts );
     401       
     402    $atts = hk_escape_atts($atts);
    367403
    368404    $html = "";
     
    405441    $html .= "</div>";
    406442    /* add default filter style */
    407     $html .= '<style>
     443    $style = '
    408444        .filtersearch' . $rand . ' {
    409445            background-color: #C6CACB;
     
    434470            display: none;
    435471            cursor: pointer;
    436         </style>';
     472        ';
    437473    /* add the jquery script, the script uses random id to work even if added more than once in a page */
    438     $html .= '<script>
     474    $warning_text = __('Warning: Nothing to filter!', 'hk-filter-and-search');
     475    $js = '
    439476        (function($) {
    440477            /* case insensitive contain */
     
    469506                if ($(selected_element) === undefined || $(selected_element).length == 0) {
    470507                    if($("#hk_filter_warning'.$rand.'").length > 0) {
    471                         $("#hk_filter_warning'.$rand.'").html("<b>Warning: Nothing to filter!</b>");
     508                        $("#hk_filter_warning'.$rand.'").html("<b>'.$warning_text.'</b>");
    472509                    }
    473510                    else {
    474                         $(el).after("<p id=\"hk_filter_warning'.$rand.'\"><b>Warning: Nothing to filter!</b></p>");
     511                        $(el).after("<p id=\"hk_filter_warning'.$rand.'\"><b>'.$warning_text.'</b></p>");
    475512                    }
    476513                }
     
    540577
    541578        })(jQuery);
    542         </script>
    543579    ';
    544     $html .= "\n".'<!-- END HK filter search -->'."\n";
    545 
    546     return $html;
     580
     581    return wp_kses(
     582            $html,
     583            array(
     584                'span' => array(
     585                    'class' => array(),
     586                ),
     587                'div' => array(
     588                    'class' => array(),
     589                ),
     590                'input' => array(
     591                    'type' => array(),
     592                    'name' => array(),
     593                    'class' => array(),
     594                    'value' => array(),
     595                ),
     596            ) ) .
     597        "<script>" . $js . "</script>\n" .
     598        "<style>" . esc_attr($style) . "</style>\n" .
     599        '<!-- END HK filter search -->'."\n";
    547600}
    548601
     
    556609
    557610
    558 
     611function hk_escape_atts($atts) {
     612    foreach($atts as $key => $value) {
     613        if ($key == "src") {
     614            $atts[$key] = esc_url($value);
     615            // ignore src if not ending with .csv
     616            if (substr($atts[$key], -4) != ".csv") {
     617                $atts[$key] = "";
     618            }
     619        }
     620        else {
     621            $atts[$key] = esc_attr($value);
     622        }
     623    }
     624    return $atts;
     625}
     626
     627
  • hk-filter-and-search/trunk/readme.txt

    r2957037 r2985200  
    33Tags: filter, csv, excel, search, jquery
    44Requires at least: 5.0
    5 Tested up to: 6.3
    6 Stable tag: 2.7
     5Tested up to: 6.3.2
     6Stable tag: 2.8
    77License: GPLv3
     8Text Domain: hk-filter-and-search
     9Domain Path: /languages
    810License URI: http://www.gnu.org/licenses/gpl.html
    911
     
    103105== Changelog ==
    104106
     107= 2.8 =
     108Major security fix. Attributes escaped. Cross scripting fix. Please update to this version!
     109Translation added. Swedish and English.
     110
    105111= 2.7 =
    106112Bugfixes for filtersearch, search per td cell if filtering table. Support if thead is used in table.
    107 
    108113
    109114= 2.6 =
Note: See TracChangeset for help on using the changeset viewer.