diff --git a/assets/js/cooked-functions.js b/assets/js/cooked-functions.js index f128724..e9eac28 100644 --- a/assets/js/cooked-functions.js +++ b/assets/js/cooked-functions.js @@ -117,20 +117,20 @@ var cooked_loading = false; // Get form values const formValues = { - category: $(this).find('[name="cp_recipe_category"]').val() || '', - method: $(this).find('[name="cp_recipe_cooking_method"]').val() || '', - cuisine: $(this).find('[name="cp_recipe_cuisine"]').val() || '', - tags: $(this).find('[name="cp_recipe_tags"]').val() || '', - diet: $(this).find('[name="cp_recipe_diet"]').val() || '', - search: $(this).find('[name="cooked_search_s"]').val() || '', - sort: $(this).find('[name="cooked_browse_sort_by"]').val() || 'date_desc', + category: wp.sanitize.stripTags($(this).find('[name="cp_recipe_category"]').val() || ''), + method: wp.sanitize.stripTags($(this).find('[name="cp_recipe_cooking_method"]').val() || ''), + cuisine: wp.sanitize.stripTags($(this).find('[name="cp_recipe_cuisine"]').val() || ''), + tags: wp.sanitize.stripTags($(this).find('[name="cp_recipe_tags"]').val() || ''), + diet: wp.sanitize.stripTags($(this).find('[name="cp_recipe_diet"]').val() || ''), + search: wp.sanitize.stripTags($(this).find('[name="cooked_search_s"]').val() || ''), + sort: wp.sanitize.stripTags($(this).find('[name="cooked_browse_sort_by"]').val() || 'date_desc'), }; - // Create URL segments + // Create URL segments with proper encoding const urlSegments = []; - urlSegments.push(cooked_js_vars.browse_recipes_slug); + urlSegments.push(encodeURIComponent(cooked_js_vars.browse_recipes_slug)); - // Add taxonomy segments + // Add taxonomy segments with improved encoding const taxonomyFields = [ { value: formValues.category, prefix: cooked_js_vars.recipe_category_slug }, { value: formValues.method, prefix: cooked_js_vars.recipe_cooking_method_slug }, @@ -141,7 +141,9 @@ var cooked_loading = false; taxonomyFields.forEach(field => { if (field.value) { - urlSegments.push(`${field.prefix}/${encodeURIComponent(field.value)}`); + const safePrefix = encodeURIComponent(field.prefix); + const safeValue = encodeURIComponent(field.value); + urlSegments.push(`${safePrefix}/${safeValue}`); } }); diff --git a/assets/js/cooked-functions.min.js b/assets/js/cooked-functions.min.js index d72e827..93df487 100644 --- a/assets/js/cooked-functions.min.js +++ b/assets/js/cooked-functions.min.js @@ -1 +1 @@ -var cooked_loading=!1;(l=>{$_Cooked_Ingredient_Boxes=l(".cooked-ingredient-checkbox"),$_Cooked_Fotorama=l(".cooked-recipe-gallery"),$_Cooked_Ajax_List=l(".cooked-recipe-loader"),$_Cooked_Recipe_Search=l(".cooked-recipe-search"),$_Cooked_Timers=l(".cooked-timer > a"),$_Cooked_FSM_Button=l(".cooked-fsm-button"),$_Cooked_Fotorama.length&&$_Cooked_Fotorama.on("fotorama:ready",function(e,o){setTimeout(function(){$_Cooked_Fotorama.addClass("cooked-gallery-loaded")},100)}),l(document).ready(function(){$_Cooked_Fotorama.length&&$_Cooked_Fotorama.fotorama();{function s(e){e.on("click",function(e){var o=l(this);o.hasClass("cooked-checked")?(o.parent().removeClass("cooked-checked"),o.removeClass("cooked-checked")):(o.parent().addClass("cooked-checked"),o.addClass("cooked-checked"))})}$_Cooked_Ingredient_Boxes.length&&s($_Cooked_Ingredient_Boxes)}var a,i;function d(e){e.on("click",function(e){e.preventDefault();var o,c,e=l(this),s="cookedTimer-"+e.data("timer-id"),i=l("#cooked-timers-wrap").find(".cooked-timer-block").length;l("div#"+s).length?(l("div#"+s).css({background:"#eeeeee"}),setTimeout(function(){l("div#"+s).css({background:""})},200)):4==i?(l("#cooked-timers-wrap").css({transform:"translate3d(0,0.5em,0)"}),setTimeout(function(){l("#cooked-timers-wrap").css({transform:""})},200)):(o=7.5*(i+=1),c=e.parents(".cooked-single-direction").length?e.parents(".cooked-single-direction").data("step"):cooked_js_vars.i18n_timer,c={id:s,seconds:e.data("seconds"),step:c,desc:e.data("desc")},l("#cooked-timers-wrap").length?(e=1==i?" cooked-visible":"",a",{id:"cooked-timers-wrap"}),i=t(c),e.append(i),l("body").append(e),n(l("#"+c.id).find(".cooked-timer-obj"),!1),setTimeout(function(){l("#cooked-timers-wrap").addClass("cooked-visible")},50)))})}function t(e,o="cooked-visible"){o=l("
",{id:e.id,class:"cooked-timer-block "+o}),l("",{class:"cooked-timer-step",text:e.step}).appendTo(o),l("",{class:"cooked-timer-desc",text:e.desc}).appendTo(o),l("
",{class:"cooked-timer-obj","data-seconds-left":e.seconds}).appendTo(o),l("",{class:"cooked-icon cooked-icon-times"}).appendTo(o),e=l("
",{class:"cooked-progress"});return l("").appendTo(e),e.appendTo(o),o}function n(o,e){var c=cooked_js_vars.timer_sound,s=new Audio(c),i=o.parents(".cooked-timer-block").attr("id"),d=o.data("seconds-left"),t=o.parents(".cooked-timer-block");o.startTimer({classNames:{hours:"cooked-timer-hours",minutes:"cooked-timer-minutes",seconds:"cooked-timer-seconds",clearDiv:"cooked-timer-clearDiv",timeout:"cooked-timer-timeout"},onComplete:function(){s.play(),o.addClass("cooked-timer-complete")}}),o.prepend(''),e&&(o.trigger("pause"),t.addClass("cooked-paused"),t.find("i.cooked-icon-pause").hide(),t.find("i.cooked-icon-play").css({display:"inline-block"}),t.addClass("cooked-paused"),l(this).parent().find("i.cooked-icon-play").css({display:"inline-block"})),r(t,10,10),o.on("update",function(e,o){r(t,o,d)}),o.on("complete",function(e,o){s.play(),t.find("i.cooked-icon-pause").hide(),t.find("i.cooked-icon-play").hide(),t.find(".cooked-timer-seconds").html("00")}),o.on("click","i.cooked-icon-pause",function(e){e.preventDefault(),l(this).hide(),t.addClass("cooked-paused"),l(this).parent().find("i.cooked-icon-play").css({display:"inline-block"}),o.trigger("pause")}),o.on("click","i.cooked-icon-play",function(e){e.preventDefault(),l(this).hide(),t.removeClass("cooked-paused cooked-complete"),l(this).parent().find("i.cooked-icon-pause").css({display:"inline-block"}),o.trigger("resume")}),o.on("click","i.cooked-icon-reverse",function(e){e.preventDefault(),t.removeClass("cooked-paused cooked-complete"),l(this).parent().find("i.cooked-icon-play").css({display:"inline-block"}),l(this).parent().find("i.cooked-icon-pause").hide(),o.remove(),l("#"+i).append('
'),n(l("#"+i).find(".cooked-timer-obj"),!0)}),t.on("click","i.cooked-icon-times",function(e){var o;e.preventDefault(),1==l("#cooked-timers-wrap").find(".cooked-timer-block").length?l("#cooked-timers-wrap").removeClass("cooked-visible"):(o=7.5*(e=l("#cooked-timers-wrap").find(".cooked-timer-block").length-1),l("#cooked-timers-wrap").css({height:o+"em"}),t.removeClass("cooked-visible"),e==a&&l("#cooked-timers-wrap").removeClass("cooked-multiples")),setTimeout(function(){t.remove()},200)})}function r(e,o,c){o=100-o/c*100;e.find(".cooked-progress > span").css({width:o+"%"}),100<=o&&e.addClass("cooked-complete")}l(".cooked-servings").length&&l(".cooked-servings").find("select").on("change",function(e){e.preventDefault();var e=l(this).children("option:selected").val(),o=new URL(window.location.href);o.searchParams.set("servings",e),window.location.href=o.toString()}),$_Cooked_Recipe_Search.length&&(l("body").on("click",function(e){var o=!1;0{e.value&&o.push(e.prefix+"/"+encodeURIComponent(e.value))}),e.search&&o.push("search/"+encodeURIComponent(e.search)),o.push("sort/"+encodeURIComponent(e.sort));e=o.filter(Boolean).join("/"),e=(new URL(cooked_js_vars.site_url).pathname+"/"+e).replace(/\/+/g,"/");window.location.href=e}),$_Cooked_Timers.length&&(a=1,d($_Cooked_Timers)),$_Cooked_FSM_Button.length&&(i=new NoSleep,$_Cooked_FSM_Button.on("click",function(e){e.preventDefault();var e=l(this).data("recipe-id"),e=l('.cooked-fsm[data-recipe-id="'+e+'"]'),o=(l("body").addClass("cooked-noscroll cooked-fsm-active"),e.clone().appendTo("body")),e=(setTimeout(function(){o.addClass("cooked-visible")},10),setTimeout(function(){o.addClass("cooked-active")},50),o.find(".cooked-timer > a")),c=o.find(".cooked-ingredient-checkbox");d(e),s(c),i.enable(),o.on("click",".cooked-close-fsm",function(e){e.preventDefault(),o.removeClass("cooked-active"),l("body").removeClass("cooked-noscroll cooked-fsm-active"),i.disable(),setTimeout(function(){o.remove()},350)})}),l("body").on("click",".cooked-fsm-mobile-nav > a",function(e){e.preventDefault();var e=l(this),o=e.data("nav-id"),c=e.parents(".cooked-fsm");c.find(".cooked-fsm-mobile-nav > a").removeClass("cooked-active"),c.find(".cooked-fsm-content").removeClass("cooked-active"),e.addClass("cooked-active"),("ingredients"==o?c.find(".cooked-fsm-content.cooked-fsm-ingredients"):(c.find(".cooked-fsm-content.cooked-fsm-directions-wrap").addClass("cooked-active"),c.find(".cooked-fsm-content.cooked-fsm-directions").addClass("cooked-active"),c.find(".cooked-fsm-content.cooked-fsm-notes"))).addClass("cooked-active")}))})})(jQuery); \ No newline at end of file +var cooked_loading=!1;(l=>{$_Cooked_Ingredient_Boxes=l(".cooked-ingredient-checkbox"),$_Cooked_Fotorama=l(".cooked-recipe-gallery"),$_Cooked_Ajax_List=l(".cooked-recipe-loader"),$_Cooked_Recipe_Search=l(".cooked-recipe-search"),$_Cooked_Timers=l(".cooked-timer > a"),$_Cooked_FSM_Button=l(".cooked-fsm-button"),$_Cooked_Fotorama.length&&$_Cooked_Fotorama.on("fotorama:ready",function(e,o){setTimeout(function(){$_Cooked_Fotorama.addClass("cooked-gallery-loaded")},100)}),l(document).ready(function(){$_Cooked_Fotorama.length&&$_Cooked_Fotorama.fotorama();{function c(e){e.on("click",function(e){var o=l(this);o.hasClass("cooked-checked")?(o.parent().removeClass("cooked-checked"),o.removeClass("cooked-checked")):(o.parent().addClass("cooked-checked"),o.addClass("cooked-checked"))})}$_Cooked_Ingredient_Boxes.length&&c($_Cooked_Ingredient_Boxes)}var a,i;function d(e){e.on("click",function(e){e.preventDefault();var o,s,e=l(this),c="cookedTimer-"+e.data("timer-id"),i=l("#cooked-timers-wrap").find(".cooked-timer-block").length;l("div#"+c).length?(l("div#"+c).css({background:"#eeeeee"}),setTimeout(function(){l("div#"+c).css({background:""})},200)):4==i?(l("#cooked-timers-wrap").css({transform:"translate3d(0,0.5em,0)"}),setTimeout(function(){l("#cooked-timers-wrap").css({transform:""})},200)):(o=7.5*(i+=1),s=e.parents(".cooked-single-direction").length?e.parents(".cooked-single-direction").data("step"):cooked_js_vars.i18n_timer,s={id:c,seconds:e.data("seconds"),step:s,desc:e.data("desc")},l("#cooked-timers-wrap").length?(e=1==i?" cooked-visible":"",a",{id:"cooked-timers-wrap"}),i=t(s),e.append(i),l("body").append(e),n(l("#"+s.id).find(".cooked-timer-obj"),!1),setTimeout(function(){l("#cooked-timers-wrap").addClass("cooked-visible")},50)))})}function t(e,o="cooked-visible"){o=l("
",{id:e.id,class:"cooked-timer-block "+o}),l("",{class:"cooked-timer-step",text:e.step}).appendTo(o),l("",{class:"cooked-timer-desc",text:e.desc}).appendTo(o),l("
",{class:"cooked-timer-obj","data-seconds-left":e.seconds}).appendTo(o),l("",{class:"cooked-icon cooked-icon-times"}).appendTo(o),e=l("
",{class:"cooked-progress"});return l("").appendTo(e),e.appendTo(o),o}function n(o,e){var s=cooked_js_vars.timer_sound,c=new Audio(s),i=o.parents(".cooked-timer-block").attr("id"),d=o.data("seconds-left"),t=o.parents(".cooked-timer-block");o.startTimer({classNames:{hours:"cooked-timer-hours",minutes:"cooked-timer-minutes",seconds:"cooked-timer-seconds",clearDiv:"cooked-timer-clearDiv",timeout:"cooked-timer-timeout"},onComplete:function(){c.play(),o.addClass("cooked-timer-complete")}}),o.prepend(''),e&&(o.trigger("pause"),t.addClass("cooked-paused"),t.find("i.cooked-icon-pause").hide(),t.find("i.cooked-icon-play").css({display:"inline-block"}),t.addClass("cooked-paused"),l(this).parent().find("i.cooked-icon-play").css({display:"inline-block"})),r(t,10,10),o.on("update",function(e,o){r(t,o,d)}),o.on("complete",function(e,o){c.play(),t.find("i.cooked-icon-pause").hide(),t.find("i.cooked-icon-play").hide(),t.find(".cooked-timer-seconds").html("00")}),o.on("click","i.cooked-icon-pause",function(e){e.preventDefault(),l(this).hide(),t.addClass("cooked-paused"),l(this).parent().find("i.cooked-icon-play").css({display:"inline-block"}),o.trigger("pause")}),o.on("click","i.cooked-icon-play",function(e){e.preventDefault(),l(this).hide(),t.removeClass("cooked-paused cooked-complete"),l(this).parent().find("i.cooked-icon-pause").css({display:"inline-block"}),o.trigger("resume")}),o.on("click","i.cooked-icon-reverse",function(e){e.preventDefault(),t.removeClass("cooked-paused cooked-complete"),l(this).parent().find("i.cooked-icon-play").css({display:"inline-block"}),l(this).parent().find("i.cooked-icon-pause").hide(),o.remove(),l("#"+i).append('
'),n(l("#"+i).find(".cooked-timer-obj"),!0)}),t.on("click","i.cooked-icon-times",function(e){var o;e.preventDefault(),1==l("#cooked-timers-wrap").find(".cooked-timer-block").length?l("#cooked-timers-wrap").removeClass("cooked-visible"):(o=7.5*(e=l("#cooked-timers-wrap").find(".cooked-timer-block").length-1),l("#cooked-timers-wrap").css({height:o+"em"}),t.removeClass("cooked-visible"),e==a&&l("#cooked-timers-wrap").removeClass("cooked-multiples")),setTimeout(function(){t.remove()},200)})}function r(e,o,s){o=100-o/s*100;e.find(".cooked-progress > span").css({width:o+"%"}),100<=o&&e.addClass("cooked-complete")}l(".cooked-servings").length&&l(".cooked-servings").find("select").on("change",function(e){e.preventDefault();var e=l(this).children("option:selected").val(),o=new URL(window.location.href);o.searchParams.set("servings",e),window.location.href=o.toString()}),$_Cooked_Recipe_Search.length&&(l("body").on("click",function(e){var o=!1;0{var o;e.value&&(o=encodeURIComponent(e.prefix),e=encodeURIComponent(e.value),s.push(o+"/"+e))}),e.search&&s.push("search/"+encodeURIComponent(e.search)),s.push("sort/"+encodeURIComponent(e.sort));e=s.filter(Boolean).join("/"),e=(new URL(cooked_js_vars.site_url).pathname+"/"+e).replace(/\/+/g,"/");window.location.href=e}),$_Cooked_Timers.length&&(a=1,d($_Cooked_Timers)),$_Cooked_FSM_Button.length&&(i=new NoSleep,$_Cooked_FSM_Button.on("click",function(e){e.preventDefault();var e=l(this).data("recipe-id"),e=l('.cooked-fsm[data-recipe-id="'+e+'"]'),o=(l("body").addClass("cooked-noscroll cooked-fsm-active"),e.clone().appendTo("body")),e=(setTimeout(function(){o.addClass("cooked-visible")},10),setTimeout(function(){o.addClass("cooked-active")},50),o.find(".cooked-timer > a")),s=o.find(".cooked-ingredient-checkbox");d(e),c(s),i.enable(),o.on("click",".cooked-close-fsm",function(e){e.preventDefault(),o.removeClass("cooked-active"),l("body").removeClass("cooked-noscroll cooked-fsm-active"),i.disable(),setTimeout(function(){o.remove()},350)})}),l("body").on("click",".cooked-fsm-mobile-nav > a",function(e){e.preventDefault();var e=l(this),o=e.data("nav-id"),s=e.parents(".cooked-fsm");s.find(".cooked-fsm-mobile-nav > a").removeClass("cooked-active"),s.find(".cooked-fsm-content").removeClass("cooked-active"),e.addClass("cooked-active"),("ingredients"==o?s.find(".cooked-fsm-content.cooked-fsm-ingredients"):(s.find(".cooked-fsm-content.cooked-fsm-directions-wrap").addClass("cooked-active"),s.find(".cooked-fsm-content.cooked-fsm-directions").addClass("cooked-active"),s.find(".cooked-fsm-content.cooked-fsm-notes"))).addClass("cooked-active")}))})})(jQuery); \ No newline at end of file diff --git a/includes/class.cooked-enqueues.php b/includes/class.cooked-enqueues.php index cb39640..4e9f681 100644 --- a/includes/class.cooked-enqueues.php +++ b/includes/class.cooked-enqueues.php @@ -62,7 +62,8 @@ public function enqueues($hook) { wp_register_script('cooked-appear', COOKED_URL . 'assets/js/appear/jquery.appear' . $min . '.js', ['jquery'], '0.3.6'); } - wp_register_script('cooked-functions', COOKED_URL . 'assets/js/cooked-functions' . $min . '.js', ['jquery'], COOKED_VERSION); + wp_enqueue_script('wp-sanitize'); + wp_register_script('cooked-functions', COOKED_URL . 'assets/js/cooked-functions' . $min . '.js', ['jquery', 'wp-sanitize'], COOKED_VERSION); wp_localize_script('cooked-functions', 'cooked_js_vars', $cooked_js_vars); } diff --git a/includes/class.cooked-recipes.php b/includes/class.cooked-recipes.php index cb23a01..8965d65 100644 --- a/includes/class.cooked-recipes.php +++ b/includes/class.cooked-recipes.php @@ -33,7 +33,7 @@ public function __construct() { add_filter('get_canonical_url', [&$this, 'modify_browse_page_canonical_url'], 20, 2); } - public static function get( $args = false, $single = false, $ids_only = false, $limit = false ) { + public static function get( $args = false, $single = false, $ids_only = false, $limit = false, $ids_and_titles_only = false ) { $recipes = []; $counter = 0; @@ -58,7 +58,7 @@ public static function get( $args = false, $single = false, $ids_only = false, $ 'order' => 'ASC' ]; - if ( $ids_only ): + if ( $ids_only || $ids_and_titles_only ): $args['fields'] = 'ids'; endif; @@ -104,25 +104,35 @@ public static function get( $args = false, $single = false, $ids_only = false, $ $recipes_results = new WP_Query($args); - if ( $recipes_results->have_posts() ): - if ( $ids_only ): + if ( $recipes_results->have_posts() ) { + if ( $ids_only ) { return $recipes_results->posts; - else: - while ( $recipes_results->have_posts() ): + } elseif ( $ids_and_titles_only ) { + while ( $recipes_results->have_posts() ) { + $recipes_results->the_post(); + $recipes[$counter]['id'] = $recipes_results->post->ID; + $recipes[$counter]['title'] = $recipes_results->post->post_title; + + $counter++; + } + } else { + while ( $recipes_results->have_posts() ) { $recipes_results->the_post(); $recipes[$counter]['id'] = $recipes_results->post->ID; $recipes[$counter]['title'] = $recipes_results->post->post_title; $recipe_settings = self::get_settings($recipes_results->post->ID); - foreach($recipe_settings as $key => $setting): + + foreach ($recipe_settings as $key => $setting) { $recipes[$counter][$key] = $setting; - endforeach; + } + $counter++; - endwhile; - endif; - else: + } + } + } else { wp_reset_postdata(); return; - endif; + } $recipes['raw'] = $recipes_results; @@ -474,6 +484,7 @@ public static function list_view( $list_atts = false ) { $sorting_types = explode('_', $sorting_type); $text_search = get_query_var('cooked_search_s', ''); + $text_search = urldecode($text_search); $text_search = esc_html($text_search); $recipes_per_page = ( $atts['show'] ? $atts['show'] : ( isset($_cooked_settings['recipes_per_page']) && $_cooked_settings['recipes_per_page'] ? $_cooked_settings['recipes_per_page'] : get_option( 'posts_per_page' ) ) ); $current_recipe_page = Cooked_Recipes::current_page(); @@ -1019,6 +1030,8 @@ public static function recipe_search_box( $options = false ) { $form_redirect = get_permalink($page_id); $cooked_search_s = get_query_var('cooked_search_s', ''); + $cooked_search_s = urldecode($cooked_search_s); + $cooked_search_s = Cooked_Functions::sanitize_text_field( $cooked_search_s ); ob_start(); @@ -1035,7 +1048,7 @@ public static function recipe_search_box( $options = false ) { echo !$options['hide_browse'] && $taxonomy_search_fields ? $taxonomy_search_fields : ''; - echo ''; + echo ''; echo ''; diff --git a/includes/class.cooked-widgets.php b/includes/class.cooked-widgets.php index 39d831b..d9a9770 100644 --- a/includes/class.cooked-widgets.php +++ b/includes/class.cooked-widgets.php @@ -39,7 +39,7 @@ public static function recipe_finder( $field_id = '', $field_name = '', $include echo '