Changeset 3329961
- Timestamp:
- 07/17/2025 11:38:15 PM (7 months ago)
- Location:
- wp-browser-update/trunk
- Files:
-
- 2 edited
-
WP-BrowserUpdate.php (modified) (6 diffs)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
wp-browser-update/trunk/WP-BrowserUpdate.php
r3269228 r3329961 4 4 Plugin URI: https://wpbu.steinbrecher.co/ 5 5 Description: This plugin notifies website visitors to update their outdated browser in a non-intrusive way. Visit <a href="https://browserupdate.org/" title="browserupdate.org" target="_blank">browserupdate.org</a> for more information… 6 Version: 5. 0.26 Version: 5.1 7 7 Author: Marco Steinbrecher 8 8 Author URI: https://profiles.wordpress.org/macsteini … … 24 24 } 25 25 26 function wpbu_fetchurl($url) { 27 $ch = curl_init($url); 28 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 29 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); 30 curl_setopt($ch, CURLOPT_TIMEOUT, 10); 31 curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MyBrowserVersionBot/1.0)'); 32 $data = curl_exec($ch); 33 curl_close($ch); 34 return $data; 35 } 36 37 function wpbu_getversion($url, $xpathQuery, $regex = '/\d+(\.\d+)+/') { 38 $html = wpbu_fetchurl($url); 39 if (!$html) return; 40 41 libxml_use_internal_errors(true); 42 $dom = new DOMDocument(); 43 $dom->loadHTML($html); 44 libxml_clear_errors(); 45 46 $xpath = new DOMXPath($dom); 47 $nodes = $xpath->query($xpathQuery); 48 49 if ($nodes->length>0) { 50 $text = $nodes->item(0)->textContent; 51 if (preg_match($regex, $text, $match)) { 52 return trim($match[0]); 53 } else return "Version number not found."; 54 } else return "Stable release not found."; 55 } 56 57 function wpbu_getversion_cached($url, $xpath, $regex = '/\d+(\.\d+)+/', $hours=6) { 58 $hours = apply_filters('wpbu_browser_version_cache_hours', $hours, $url, $xpath, $regex); 59 $key = 'wpbu_'.md5($url.$xpath.$regex); 60 $version = get_transient($key); 61 if ($version!==false) return $version; 62 $version = wpbu_getversion($url, $xpath, $regex); 63 if (is_string($version) && strlen($version)<255) set_transient($key, $version, $hours*HOUR_IN_SECONDS); 64 return $version; 65 } 66 26 67 function wpbu() { 27 68 $wpbu_vars = explode(' ', get_option('wp_browserupdate_browsers', '0 0 0 0 0')); … … 29 70 $browser = 'e:'.$wpbu_vars[0].',f:'.$wpbu_vars[1].',o:'.$wpbu_vars[2].',s:'.$wpbu_vars[3].(!isset($wpbu_vars[4])?'':',c:'.$wpbu_vars[4]); 30 71 echo '<script> 31 var $buoop = {required:{e:'.$wpbu_vars[0].',f:'.$wpbu_vars[1].',o:'.$wpbu_vars[2].',s:'.$wpbu_vars[3].(!isset($wpbu_vars[4])?'':',c:'.$wpbu_vars[4]).'},test:'.($wpbu_js[1] ?? '').',newwindow:'.($wpbu_js[2] ?? '').',style:"'.($wpbu_js[3] ?? '').'",insecure:'.($wpbu_js[4] ?? '').',unsupported:'.($wpbu_js[5] ?? '').',mobile:'.($wpbu_js[6] ?? '').',shift_page_down:'.($wpbu_js[7] ?? '').',api:2025.0 4};72 var $buoop = {required:{e:'.$wpbu_vars[0].',f:'.$wpbu_vars[1].',o:'.$wpbu_vars[2].',s:'.$wpbu_vars[3].(!isset($wpbu_vars[4])?'':',c:'.$wpbu_vars[4]).'},test:'.($wpbu_js[1] ?? '').',newwindow:'.($wpbu_js[2] ?? '').',style:"'.($wpbu_js[3] ?? '').'",insecure:'.($wpbu_js[4] ?? '').',unsupported:'.($wpbu_js[5] ?? '').',mobile:'.($wpbu_js[6] ?? '').',shift_page_down:'.($wpbu_js[7] ?? '').',api:2025.07}; 32 73 33 74 function $buo_f(){ … … 42 83 43 84 function wpbu_administration() { 85 if (!current_user_can('manage_options')) wp_die(__('You do not have sufficient permissions to access this page.')); 86 44 87 if (isset($_POST['wpbu_submit']) and wp_verify_nonce($_POST['form_nonce'], 'test-nonce')) { 45 46 $fields_to_sanitize = ['wpbu_msie', 'wpbu_firefox', 'wpbu_opera', 'wpbu_safari', 'wpbu_google', 'wpbu_reminder', 'wpbu_testing', 'wpbu_newwindow', 'wpbu_style', 'wpbu_secis', 'wpbu_unsup', 'wpbu_mobile', 'wpbu_shift']; 47 88 foreach (['wpbu_msie', 'wpbu_firefox', 'wpbu_opera', 'wpbu_safari', 'wpbu_google'] as $field) { 89 if (isset($_POST[$field])) $_POST[$field] = preg_replace('/[^0-9.\-]/', '', $_POST[$field]); 90 } 91 92 $fields_to_sanitize = ['wpbu_reminder', 'wpbu_testing', 'wpbu_newwindow', 'wpbu_style', 'wpbu_secis', 'wpbu_unsup', 'wpbu_mobile', 'wpbu_shift']; 48 93 foreach ($fields_to_sanitize as $field) { 49 94 if (isset($_POST[$field])) $_POST[$field] = sanitize_text_field($_POST[$field]); … … 52 97 $_POST['wpbu_css_buorg'] = sanitize_textarea_field($_POST['wpbu_css_buorg']); 53 98 54 $browsers = ['msie' => sanitize_text_field($_POST['wpbu_msie'] ?? '0'), 'firefox'=> sanitize_text_field($_POST['wpbu_firefox'] ?? '0'), 'opera'=> sanitize_text_field($_POST['wpbu_opera'] ?? '0'), 'safari' => sanitize_text_field($_POST['wpbu_safari'] ?? '0'), 'google' => sanitize_text_field($_POST['wpbu_google'] ?? '0')];99 $browsers = ['msie' => $_POST['wpbu_msie'] ?? '0', 'firefox'=> $_POST['wpbu_firefox'] ?? '0', 'opera'=> $_POST['wpbu_opera'] ?? '0', 'safari' => $_POST['wpbu_safari'] ?? '0', 'google' => $_POST['wpbu_google'] ?? '0']; 55 100 56 101 $js_settings = [(int) ($_POST['wpbu_reminder'] ?? 12), sanitize_text_field($_POST['wpbu_testing'] ?? 'false'), sanitize_text_field($_POST['wpbu_newwindow'] ?? 'false'), sanitize_text_field($_POST['wpbu_style'] ?? 'top'), sanitize_text_field($_POST['wpbu_secis'] ?? 'false'), sanitize_text_field($_POST['wpbu_unsup'] ?? 'false'), sanitize_text_field($_POST['wpbu_mobile'] ?? 'false'), sanitize_text_field($_POST['wpbu_shift'] ?? 'false')]; … … 61 106 62 107 echo '<div class="updated"><p><strong>'.esc_html__('Settings saved.', 'wp-browser-update').'</strong></p></div>'; 63 unset($_POST['form_nonce']); 64 unset($_POST['wpbu_submit']); 65 } 66 67 $morethan = [ 68 ['0', __('Every outdated version', 'wp-browser-update')], 69 ['-5', __('More than five versions outdated', 'wp-browser-update')], 70 ['-4', __('More than four versions outdated', 'wp-browser-update')], 71 ['-3', __('More than three versions outdated', 'wp-browser-update')], 72 ['-2', __('More than two versions outdated', 'wp-browser-update')], 73 ['-1', __('More than one version outdated', 'wp-browser-update')] 108 } 109 110 $wpbu_vars = explode(' ', get_option('wp_browserupdate_browsers', '0 0 0 0 0')); 111 112 $browsers = [ 113 'msie' => [ 114 'name' => 'Microsoft Edge', 115 'selected' => $wpbu_vars[0], 116 'download' => 'https://microsoft.com/edge', 117 'url' => 'https://en.wikipedia.org/wiki/Microsoft_Edge', 118 'xpath' => "//table[contains(@class,'infobox')]//tr[th//a[text()='Stable release(s)']]/following-sibling::tr[1]//table[contains(@class, 'infobox-subbox')]//tr[th[contains(text(),'Windows')]]/td", 119 ], 120 121 'firefox' => [ 122 'name' => 'Mozilla Firefox', 123 'selected' => $wpbu_vars[1], 124 'download' => 'https://firefox.com/', 125 'url' => 'https://en.wikipedia.org/wiki/Firefox', 126 'xpath' => "//table[contains(@class,'infobox')]//tr[th//a[text()='Stable release(s)']]/following-sibling::tr[1]//table[contains(@class, 'infobox-subbox')]//tr[th[text()='Standard']]/td", 127 'regex' => '/\d+(\.\d+)+/', 128 ], 129 130 'opera' => [ 131 'name' => 'Opera', 132 'selected' => $wpbu_vars[2], 133 'download' => 'https://opera.com/', 134 'url' => 'https://en.wikipedia.org/wiki/Opera_(web_browser)', 135 'xpath' => "//table[contains(@class,'infobox')]//tr[th//a[text()='Stable release']]/td", 136 ], 137 138 'safari' => [ 139 'name' => 'Apple Safari', 140 'selected' => $wpbu_vars[3], 141 'download' => 'https://support.apple.com/102665', 142 'url' => 'https://en.wikipedia.org/wiki/Safari_(web_browser)', 143 'xpath' => "//table[contains(@class,'infobox')]//tr[th//a[text()='Stable release(s)']]/following-sibling::tr[1]//table[contains(@class, 'infobox-subbox')]//tr[th[text()='macOS']]/td", 144 'regex' => '/\d+(\.\d+)+/', 145 ], 146 147 'google' => [ 148 'name' => 'Google Chrome', 149 'selected' => $wpbu_vars[4], 150 'download' => 'https://chrome.google.com/', 151 'url' => 'https://en.wikipedia.org/wiki/Google_Chrome', 152 'xpath' => "//table[contains(@class,'infobox')]//tr[th//a[text()='Stable release(s)']]/following-sibling::tr[1]//table[contains(@class, 'infobox-subbox')]//tr[th[contains(text(),'Windows')]]/td", 153 ], 74 154 ]; 75 155 76 $version_ranges = [ 77 'msie' => [135, 120, 110, 100, 90], 78 'firefox' => [137, 120, 100, 80, 60], 79 'opera' => [117, 85, 75, 65, 55], 80 'safari' => [18, 17, 16, 15, 14], 81 'google' => [135, 120, 100, 80, 60], 82 ]; 83 156 ### 157 ### One-time migration for negative values 158 ### 159 160 $needs_migration = false; 161 foreach (array_keys($browsers) as $i => $key) { 162 $val = $wpbu_vars[$i] ?? '0'; 163 if (is_numeric($val) && (float)$val < 0) { 164 $browser = $browsers[$key]; 165 $regex = isset($browser['regex']) ? $browser['regex'] : '/\d+(\.\d+)+/'; 166 $version = wpbu_getversion_cached($browser['url'], $browser['xpath'], $regex); 167 if (preg_match('/^([\d\.]+)/', $version, $m)) { 168 $current_version = $m[1]; 169 $parts = explode('.', $current_version); 170 $diff = abs((int)$val); 171 $parts[0] = max(0, (int)$parts[0] - $diff); 172 $newval = implode('.', $parts); 173 $wpbu_vars[$i] = $newval; 174 $needs_migration = true; 175 } 176 } 177 } 178 179 if ($needs_migration) { 180 update_option('wp_browserupdate_browsers', implode(' ', $wpbu_vars)); 84 181 $wpbu_vars = explode(' ', get_option('wp_browserupdate_browsers', '0 0 0 0 0')); 85 86 $browsers = [ 87 'msie' => ['name' => 'Microsoft Edge', 'selected' => $wpbu_vars[0], 'download' => 'https://microsoft.com/edge'], 88 'firefox' => ['name' => 'Mozilla Firefox', 'selected' => $wpbu_vars[1], 'download' => 'https://mozilla.org/firefox'], 89 'opera' => ['name' => 'Opera', 'selected' => $wpbu_vars[2], 'download' => 'https://opera.com/'], 90 'safari' => ['name' => 'Apple Safari', 'selected' => $wpbu_vars[3], 'download' => 'https://support.apple.com/102665'], 91 'google' => ['name' => 'Google Chrome', 'selected' => $wpbu_vars[4], 'download' => 'https://chrome.google.com/'], 92 ]; 93 94 echo '<div class="wrap"><form action="'.esc_url($_SERVER['REQUEST_URI']).'" method="post"><input type="hidden" name="form_nonce" value="'.esc_attr(wp_create_nonce('test-nonce')).'" /><h1>WP BrowserUpdate</h1><h2>'.esc_html__('Outdated Browser Versions', 'wp-browser-update').'</h2><p>'.esc_html__('Select the browser versions you consider outdated (including all earlier versions). If left unchanged, WP BrowserUpdate will use the default settings.', 'wp-browser-update').'</p>'; 95 96 $output = ''; 182 $browser_keys = array_keys($browsers); 183 foreach ($browser_keys as $i => $key) { 184 $browsers[$key]['selected'] = $wpbu_vars[$i] ?? '0'; 185 } 186 } 187 188 ### 189 ### 190 ### 191 192 echo '<div class="wrap"><form action="'.esc_url($_SERVER['REQUEST_URI']).'" method="post"><input type="hidden" name="form_nonce" value="'.esc_attr(wp_create_nonce('test-nonce')).'" /><h1>WP BrowserUpdate</h1><h2>'.esc_html__('Outdated Browser Versions', 'wp-browser-update').'</h2><p>'.esc_html__('Select the browser versions you consider outdated (including all earlier versions). If left unchanged, WP BrowserUpdate will use the default settings.', 'wp-browser-update').'</p><p>'.esc_html__('If you set the browser version to 0, a notification will be shown for every outdated browser version.', 'wp-browser-update').'</p>'; 193 194 $output = '<table class="form-table">'; 97 195 98 196 foreach ($browsers as $key => $browser) { 99 $versions = array_merge($morethan, array_map(fn($v) => [$v, $v.' '.esc_html__('or earlier')], $version_ranges[$key])); 100 101 $output .= '<p><a href="'.esc_url($browser['download']).'" target="_blank" title="'.esc_attr(__('Download', 'wp-browser-update')).'">'.esc_html($browser['name']).'</a>: <select name="wpbu_'.esc_attr($key).'">'; 102 103 foreach ($versions as $version) { 104 $selected = ($browser['selected'] == $version[0]) ? ' selected="selected"' : ''; 105 $output .= '<option value="'.esc_attr($version[0]).'"'.$selected.'>'.esc_html($version[1]).'</option>'; 106 } 107 108 $output .= '</select></p>'; 109 } 110 111 echo $output; 197 $version = ''; 198 if (!empty($browser['url']) && !empty($browser['xpath'])) { 199 $regex = isset($browser['regex']) ? $browser['regex'] : '/\d+\.\d+\.\d+\.\d+/'; 200 $version = wpbu_getversion_cached($browser['url'], $browser['xpath'], $regex); 201 } 202 $output .= '<tr><th scope="row"><label for="wpbu_'.esc_attr($key).'"><a href="'.$browser['download'].'" target="_blank">'.esc_html($browser['name']).'</a></label></th><td><input type="text" pattern="^[0-9.]+$" name="wpbu_'.esc_attr($key).'" id="wpbu_'.esc_attr($key).'" value="'.esc_attr($browser['selected']).'" title="'.__('Only numbers and dots are allowed', 'wp-browser-update').'" size="12" />'; 203 if ($version) $output .= ' <small>'.esc_html__('Latest version', 'wp-browser-update').': '.esc_html($version).'</small>'; 204 $output .= '</td></tr>'; 205 } 206 207 echo $output.'</table>'; 112 208 113 209 $wpbu_defaults = ['12', 'false', 'true', 'top', 'true', 'true', 'true', 'true']; -
wp-browser-update/trunk/readme.txt
r3269228 r3329961 6 6 Requires at least: 4.6 7 7 Requires PHP: 7.4 8 Stable tag: 5. 0.28 Stable tag: 5.1 9 9 License: GPLv3 or later 10 10 License URI: https://gnu.org/licenses/gpl … … 62 62 63 63 == Changelog == 64 = 5.1 = 65 * Added: 66 * Support for free-text input of browser versions (replaces dropdown selection) 67 * Browser version check and caching 68 * Cache duration filter: Added a wpbu_browser_version_cache_hours filter to allow developers to adjust the browser version cache duration (default: 6 hours). 69 * Changed: 70 * Admin settings page follows WordPress admin standards 71 * Cleaner field structure: Improved markup and consistency of settings form fields 72 * Security: Improved sanitization and nonce handling for all settings fields 73 * Performance: Fewer unnecessary remote lookups when opening the admin settings page 74 64 75 = 5.0.2 = 65 76 * Updated outdated browser versions.
Note: See TracChangeset
for help on using the changeset viewer.