Changeset 3092553
- Timestamp:
- 05/25/2024 08:12:27 PM (22 months ago)
- Location:
- instant-search
- Files:
-
- 13 added
- 5 edited
-
tags/1.02 (added)
-
tags/1.02/banner (added)
-
tags/1.02/banner/et-affiliate.png (added)
-
tags/1.02/banner/hosterion-affiliate.png (added)
-
tags/1.02/banner/index.php (added)
-
tags/1.02/banner/rey.png (added)
-
tags/1.02/instant-search.php (added)
-
tags/1.02/instant_search.css (added)
-
tags/1.02/instant_search.js (added)
-
tags/1.02/readme.txt (added)
-
tags/1.02/searchform.php (added)
-
tags/1.02/settings.css (added)
-
trunk/instant-search.php (modified) (7 diffs)
-
trunk/instant_search.css (modified) (10 diffs)
-
trunk/instant_search.js (modified) (8 diffs)
-
trunk/readme.txt (modified) (5 diffs)
-
trunk/searchform.php (modified) (1 diff)
-
trunk/settings.css (added)
Legend:
- Unmodified
- Added
- Removed
-
instant-search/trunk/instant-search.php
r3086833 r3092553 9 9 * Plugin URI: https://instant-search.marincas.net 10 10 * Description: A WordPress search plugin with live and voice search. 11 * Version: 1.0. 111 * Version: 1.0.2 12 12 * Author: webmaster85 13 13 * Author URI: https://www.marincas.net … … 17 17 18 18 function instant_search_form() { 19 ob_start(); 20 include plugin_dir_path(__FILE__) . 'searchform.php'; 21 $form = ob_get_clean(); 22 return $form; 19 ob_start(); 20 include plugin_dir_path(__FILE__) . 'searchform.php'; 21 $form = ob_get_clean(); 22 return $form; 23 23 } 24 24 add_shortcode('instant_search', 'instant_search_form'); … … 27 27 wp_enqueue_script('instant_search', plugins_url('instant_search.js', __FILE__), array('jquery'), '1.0', true); 28 28 wp_enqueue_style('instant_search', plugins_url('instant_search.css', __FILE__)); 29 wp_enqueue_style('font-awesome', 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/css/all.min.css'); // Enqueue Font Awesome29 wp_enqueue_style('font-awesome', 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/css/all.min.css'); 30 30 wp_localize_script('instant_search', 'instant_search', array('ajax_url' => admin_url('admin-ajax.php'), 'display_style' => get_option('instant_search_display_style', 'list'))); 31 31 } 32 32 33 add_action('wp_enqueue_scripts', 'instant_search_scripts'); 34 35 function wpdocs_enqueue_custom_admin_style() { 36 wp_register_style( 'custom_wp_admin_css', plugin_dir_url( __FILE__ ) . 'settings.css', false, '1.0.0' ); 37 wp_enqueue_style( 'custom_wp_admin_css' ); 38 } 39 add_action( 'admin_enqueue_scripts', 'wpdocs_enqueue_custom_admin_style' ); 33 40 34 41 function instant_search_ajax() { … … 61 68 add_action('admin_menu', 'instant_search_menu'); 62 69 63 64 /* SEARCH BY SKU START */ 70 function instant_search_custom_styles() { 71 $search_form_width = get_option('instant_search_form_width', '300px'); 72 echo '<style> 73 .search-wrapper { 74 width: ' . esc_attr($search_form_width) . '; 75 } 76 </style>'; 77 } 78 add_action('wp_head', 'instant_search_custom_styles'); 79 65 80 function search_by_sku( $search, $query_vars ) { 66 81 global $wpdb; … … 90 105 } 91 106 add_filter( 'posts_search', 'search_by_sku', 999, 2 ); 92 /* SEARCH BY SKU STOP */93 107 94 108 function instant_search_options() { … … 96 110 wp_die(__('You do not have sufficient permissions to access this page.')); 97 111 } 98 // Check if form has been submitted and process it 99 if (isset($_POST['post_types'])) { 100 $post_types = array_map('sanitize_text_field', $_POST['post_types']); 101 update_option('instant_search_post_types', $post_types); 102 } 103 if (isset($_POST['display_style'])) { 104 $display_style = sanitize_text_field($_POST['display_style']); 105 update_option('instant_search_display_style', $display_style); 106 } 107 // Retrieve options 108 $post_types = get_option('instant_search_post_types', array('post', 'page')); 112 if ($_SERVER['REQUEST_METHOD'] === 'POST') { 113 if (isset($_POST['post_types'])) { 114 $post_types = array_map('sanitize_text_field', $_POST['post_types']); 115 update_option('instant_search_post_types', $post_types); 116 } 117 if (isset($_POST['display_style'])) { 118 $display_style = sanitize_text_field($_POST['display_style']); 119 update_option('instant_search_display_style', $display_style); 120 } 121 if (isset($_POST['search_placeholder'])) { 122 $search_placeholder = sanitize_text_field($_POST['search_placeholder']); 123 update_option('instant_search_placeholder', $search_placeholder); 124 } 125 if (isset($_POST['search_form_width'])) { 126 $search_form_width = sanitize_text_field($_POST['search_form_width']); 127 update_option('instant_search_form_width', $search_form_width); 128 } 129 } 130 $post_types = get_option('instant_search_post_types', array('post', 'page')); 109 131 $display_style = get_option('instant_search_display_style', 'list'); 132 $search_placeholder = get_option('instant_search_placeholder', 'What are we searching for today?'); 110 133 $all_post_types = get_post_types(array('public' => true), 'names'); 111 ?> 112 113 <div class="wrap"> 114 <h2>Instant Search Settings</h2> 115 <h2>Use this shortcode to display the search form anywhere: 116 <h1>[instant_search]</h1> 117 </h2> 118 <h3>Select the post types you like the form to show results for:</h3> 119 <form method="post" action=""> 120 <?php foreach ($all_post_types as $post_type): ?> 121 <input type="checkbox" name="post_types[]" value="<?php echo esc_attr($post_type); ?>"<?php if (in_array($post_type, $post_types)) echo ' checked'; ?> /> <?php echo esc_html($post_type); ?><br /> 122 <?php endforeach; ?> 123 <h3>Select how the search results should be displayed:</h3> 124 <select name="display_style"> 125 <option value="list"<?php if ($display_style == 'list') echo ' selected'; ?>>List</option> 126 <option value="grid"<?php if ($display_style == 'grid') echo ' selected'; ?>>Grid</option> 127 </select> 134 $search_form_width = get_option('instant_search_form_width', '50%'); 135 ?> 136 137 <div class="wrapper"> 138 <h2 class="bigtitle">Instant Search Settings <button id="toggle-ads-button">Show Ads</button></h2> 139 <div id="toggle-ads"> 140 <script> 141 jQuery(document).ready(function() { 142 jQuery("#toggle-ads-button").click(function() { 143 jQuery("#toggle-ads").toggle(); 144 if (jQuery("#toggle-ads").is(":visible")) { 145 jQuery("#toggle-ads-button").text("Hide Ads").css("background-color", "red");; 146 } else { 147 jQuery("#toggle-ads-button").text("Show Ads").css("background-color", "#1ED760"); 148 } 149 }); 150 }); 151 </script> 152 <div class="ads-images"> 128 153 <h3>Want to create stunning websites with the assistance of AI?</h3> 129 154 <a href="https://www.elegantthemes.com/affiliates/idevaffiliate.php?id=47480" target="_blank" rel="nofollow"> 130 155 <img style="border:0px" src="<?php echo esc_url(plugins_url('/banner/et-affiliate.png', __FILE__)); ?>" width="570" height="100" alt=""> 131 </a> 156 </a> 132 157 <h3>Check out the best E-Commerce theme:</h3> 133 158 <a href="https://themeforest.net/item/rey-multipurpose-woocommerce-theme/24689383" target="_blank" rel="nofollow"> … … 137 162 <a href="https://hosterion.ro/client/aff.php?aff=160" target="_blank" rel="nofollow"> 138 163 <img style="border:0px" src="<?php echo esc_url(plugins_url('/banner/hosterion-affiliate.png', __FILE__)); ?>" width="570" height="100" alt=""> 139 </a> 140 <h1>Do you like the plugin? You can support it by donating <a href="https://instant-search.marincas.net/#donate" target="_blank">here</a>.</h1> 141 <p class="submit"> 164 </a> 165 </div> 166 </div> 167 <form method="post" action=""> 168 <div class="articles"> 169 <article> 170 <div class="article-wrapper"> 171 <h1> 172 1 173 </h1> 174 <div class="article-body"> 175 <h2>Select the post types</h2> 176 <p> 177 Choose the types of posts you'd like the form to display results for. Each WordPress site, depending on the themes and plugins in use, may have various custom post types. These might include products, posts, pages, attachments, global sections, templates, etc. The plugin automatically detects all available post types, so you can get search results from any of them. Feel free to select multiple options. 178 </p> 179 <p> 180 <?php foreach ($all_post_types as $post_type): ?> 181 <input type="checkbox" name="post_types[]" value="<?php echo esc_attr($post_type); ?>"<?php if (in_array($post_type, $post_types)) echo ' checked'; ?> /> <?php echo esc_html($post_type); ?><br /> 182 <?php endforeach; ?> 183 </p> 184 </div> 185 </div> 186 </article> 187 <article> 188 <div class="article-wrapper"> 189 <h1> 190 2 191 </h1> 192 <div class="article-body"> 193 <h2>Search results display</h2> 194 <p> 195 Depending on your choice here, your website visitors will see search results either in a grid (3 columns) or in a list format. The grid view is perfect for desktops, offering a visually appealing layout, while the list view is ideal for small screens like phones, ensuring better readability and easier navigation. 196 </p> 197 <p class="display-styles"> 198 <select name="display_style"> 199 <option value="list"<?php if ($display_style == 'list') echo ' selected'; ?>>List</option> 200 <option value="grid"<?php if ($display_style == 'grid') echo ' selected'; ?>>Grid</option> 201 </select> 202 </p> 203 </div> 204 </div> 205 </article> 206 <article> 207 <div class="article-wrapper"> 208 <h1> 209 3 210 </h1> 211 <div class="article-body"> 212 <h2>Placeholder text</h2> 213 <p> 214 In this field, you can set a personalized message that will be displayed inside the search form. The default is usually "Search..." but you have the flexibility to change it. For example, you could use "What are we searching for today?" or anything else that suits your needs. 215 </p> 216 <p class="placeholder-text"> 217 <input type="text" style="min-width:250px;" name="search_placeholder" value="<?php echo esc_attr($search_placeholder); ?>" /> 218 </p> 219 </div> 220 </div> 221 </article> 222 <article> 223 <div class="article-wrapper"> 224 <h1> 225 4 226 </h1> 227 <div class="article-body"> 228 <h2>Width</h2> 229 <p> 230 You can customize the width of the search form in this field. By default it's set to 300px, but you can change it to any CSS unit that suits your website's layout. For instance, you could use 50% for a responsive design, 300px for a fixed width, or 30vh to make it proportional to the viewport height. 231 </p> 232 <p class="width-text"> 233 <input type="text" style="min-width:250px;" name="search_form_width" value="<?php echo esc_attr($search_form_width); ?>" placeholder="e.g., 50%, 300px, 30vh" /> 234 </p> 235 </div> 236 </div> 237 </article> 238 <article> 239 <div class="article-wrapper"> 240 <h1> 241 5 242 </h1> 243 <div class="article-body"> 244 <h2>Shortcode</h2> 245 <p> 246 Use the shortcode to display a search form anywhere. Personally, I find it works best when placed in the website's header. It optimizes user experience and navigation, as it's a prime location for visitors to initiate searches, thus enhancing overall site usability. 247 </p> 248 <h3 class="the-shortcode"> 249 [instant_search] 250 </h3> 251 </div> 252 </div> 253 </article> 254 <article> 255 <div class="article-wrapper"> 256 <h1> 257 6 258 </h1> 259 <div class="article-body"> 260 <h2>Donate</h2> 261 <p> 262 I use the donations to improve the plugin. That could mean a variety of things. I mainly buy web development courses that let me upgrade my skills to understand the whole environment better, how the search works in-depth, and see the big picture. 263 </p> 264 <p style="text-align:center;"> 265 <button class="donate-button" ><a href="https://instant-search.marincas.net/#donate" target="_blank">Donate here</a></button> 266 </p> 267 </div> 268 </div> 269 </article> 270 </div> 271 <p class="submit"> 142 272 <input type="submit" class="button-primary" value="Save Changes" /> 143 </p> 144 </form> 145 </div> 146 273 </p> 274 </form> 275 </div> 147 276 <?php 148 } // End of instant_search_options function277 } 149 278 ?> -
instant-search/trunk/instant_search.css
r3086833 r3092553 2 2 box-sizing: border-box; 3 3 } 4 5 4 #search-results.list .search-result { 6 5 display: block; … … 9 8 padding: 25px; 10 9 } 11 12 10 #search-results.list .search-result img { 13 11 width: -webkit-fill-available; 14 12 } 15 16 13 #search-results.grid .search-result { 17 14 display: inline-block; … … 20 17 box-sizing: border-box; 21 18 } 22 23 19 #search-results.grid .search-result img { 24 20 width: 100%; 25 21 26 22 } 27 28 23 #search-results { 29 24 text-align:center; … … 34 29 35 30 } 36 37 31 #search-results * { 38 32 font-size:1em!important; 39 33 line-height: 1em!important; 40 34 } 41 42 35 #search-results img { 43 36 margin-bottom:10px; 44 37 45 38 } 46 47 48 49 39 form#searchform input[type=text] { 50 40 padding: 10px; … … 55 45 56 46 } 57 58 /* Overlay Styles */59 47 .search-overlay { 60 48 position: fixed; … … 69 57 align-items: center; 70 58 } 71 72 59 #search-results { 73 60 display:none; … … 81 68 box-shadow: 0 4px 6px rgba(0,0,0,0.1); 82 69 } 83 84 85 86 70 .search-wrapper { 87 71 position: relative; … … 89 73 align-items: center; 90 74 } 91 92 75 #s { 93 flex-grow: 1; /* Makes the input take up the available space */94 padding-right: 40px; /* Adds padding to prevent text from being hidden behind the button */76 flex-grow: 1; 77 padding-right: 40px; 95 78 } 96 97 79 #voice-search-btn { 98 80 position: absolute; … … 102 84 background: none; 103 85 cursor: pointer; 104 color: #333; /* Adjust color as needed */86 color: #333; 105 87 padding: 10px; 106 88 } 107 108 89 #voice-search-btn i { 109 font-size: 20px; /* Adjust size as needed */90 font-size: 20px; 110 91 } 111 112 113 114 /* MEDIA QUERIES */115 92 @media only screen and (max-width: 767px) { 116 93 … … 119 96 padding: 5px; 120 97 } 121 122 123 98 #search-results.list .search-result { 124 99 width: 90%; 125 100 padding: 5px; 126 101 } 127 128 102 #search-results.grid .search-result { 129 103 width: 40%; 130 104 } 131 132 105 form#searchform input[type=text] { 133 106 min-width:100%; 134 135 107 } 136 137 138 108 } -
instant-search/trunk/instant_search.js
r3089664 r3092553 1 1 jQuery(document).ready(function($) { 2 // Function to create and get the overlay3 2 function getOrCreateOverlay() { 4 3 let overlay = $('#search-overlay'); 5 // Check if the overlay already exists6 4 if (overlay.length === 0) { 7 // Create the overlay and search results container8 5 overlay = $('<div id="search-overlay" class="search-overlay" style="display: none;"></div>'); 9 6 let searchResults = $('<div id="search-results" class="' + instant_search.display_style + '" style="display: none;"></div>'); … … 13 10 return overlay; 14 11 } 15 16 12 var debounceTimeout; 17 var currentRequest = null; // Track the current AJAX request 18 var delay = 300; // Delay in milliseconds 19 13 var currentRequest = null; 14 var delay = 100; 20 15 $('#s').on('input', function() { 21 16 clearTimeout(debounceTimeout); … … 31 26 } else { 32 27 if (currentRequest != null) { 33 currentRequest.abort(); // Abort the ongoing request28 currentRequest.abort(); 34 29 } 35 30 currentRequest = $.ajax({ … … 45 40 }, 46 41 complete: function() { 47 currentRequest = null; // Reset the current request tracker42 currentRequest = null; 48 43 } 49 44 }); … … 51 46 }, delay); 52 47 }); 53 // Close overlay on click outside of search results54 48 $(document).on('click', '#search-overlay', function(e) { 55 49 if ($(e.target).closest('#search-results').length === 0) { … … 59 53 } 60 54 }); 61 // Prevent closing when clicking inside the search results62 55 $(document).on('click', '#search-results', function(e) { 63 e.stopPropagation(); // Prevent event from bubbling to overlay56 e.stopPropagation(); 64 57 }); 65 /* VOICE SEARCH START */ 58 66 59 if ('webkitSpeechRecognition' in window) { 67 60 var recognition = new webkitSpeechRecognition(); … … 71 64 recognition.onresult = function(event) { 72 65 var transcript = event.results[0][0].transcript; 73 var cleanedTranscript = transcript.replace(/[.,\/#!$%\^&\*;:{}=\-_`~()]/g,""); // Regex to remove punctuation74 $('#s').val(cleanedTranscript).trigger('input'); // Set cleaned transcript66 var cleanedTranscript = transcript.replace(/[.,\/#!$%\^&\*;:{}=\-_`~()]/g,""); 67 $('#s').val(cleanedTranscript).trigger('input'); 75 68 }; 76 69 … … 79 72 }); 80 73 } else { 81 $('#voice-search-btn').hide(); // Hide the button if not supported 82 } 83 /* VOICE SEARCH STOP */ 74 $('#voice-search-btn').hide(); 75 } 84 76 }); -
instant-search/trunk/readme.txt
r3089664 r3092553 5 5 Requires at least: 4.7 6 6 Tested up to: 6.5.3 7 Stable tag: 1.0. 17 Stable tag: 1.0.2 8 8 Requires PHP: 7.4 9 9 License: GPLv2 or later … … 31 31 - Display live search results in a grid 32 32 - Display live search results in a list 33 - Customize the text 34 - Customize the width 33 35 - Submit for searching 34 36 … … 69 71 - Display live search results in a grid 70 72 - Display live search results in a list 73 - Customize the text 74 - Customize the width 71 75 - Submit for searching 72 76 … … 98 102 99 103 == Changelog == 104 105 = 1.0.2 = 106 107 Added improvements. 108 100 109 = 1.0.1 = 101 110 … … 115 124 116 125 == Upgrade Notice == 117 Added features. 126 127 Added improvements. -
instant-search/trunk/searchform.php
r3086833 r3092553 1 1 <?php 2 2 if ( ! defined( 'ABSPATH' ) ) { 3 exit; // Exit if accessed directly3 exit; 4 4 } 5 5 ?> 6 6 <form role="search" method="get" id="searchform" action="<?php echo esc_url(home_url('/')); ?>"> 7 7 <div class="search-wrapper"> 8 <input type="text" value="" name="s" id="s" placeholder=" What are we searching for today?" />8 <input type="text" value="" name="s" id="s" placeholder="<?php echo esc_attr(get_option('instant_search_placeholder', 'What are we searching for today?')); ?>" /> 9 9 <button type="button" id="voice-search-btn" aria-label="Voice Search"><i class="fas fa-microphone"></i></button> 10 10 </div>
Note: See TracChangeset
for help on using the changeset viewer.