Plugin Directory

Changeset 3329961


Ignore:
Timestamp:
07/17/2025 11:38:15 PM (7 months ago)
Author:
MacSteini
Message:

Updated

Location:
wp-browser-update/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • wp-browser-update/trunk/WP-BrowserUpdate.php

    r3269228 r3329961  
    44Plugin URI: https://wpbu.steinbrecher.co/
    55Description: 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.2
     6Version: 5.1
    77Author: Marco Steinbrecher
    88Author URI: https://profiles.wordpress.org/macsteini
     
    2424}
    2525
     26function wpbu_fetchurl($url) {
     27$ch = curl_init($url);
     28curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     29curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
     30curl_setopt($ch, CURLOPT_TIMEOUT, 10);
     31curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MyBrowserVersionBot/1.0)');
     32$data = curl_exec($ch);
     33curl_close($ch);
     34return $data;
     35}
     36
     37function wpbu_getversion($url, $xpathQuery, $regex = '/\d+(\.\d+)+/') {
     38$html = wpbu_fetchurl($url);
     39if (!$html) return;
     40
     41libxml_use_internal_errors(true);
     42$dom = new DOMDocument();
     43$dom->loadHTML($html);
     44libxml_clear_errors();
     45
     46$xpath = new DOMXPath($dom);
     47$nodes = $xpath->query($xpathQuery);
     48
     49if ($nodes->length>0) {
     50$text = $nodes->item(0)->textContent;
     51if (preg_match($regex, $text, $match)) {
     52return trim($match[0]);
     53} else return "Version number not found.";
     54} else return "Stable release not found.";
     55}
     56
     57function 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);
     61if ($version!==false) return $version;
     62$version = wpbu_getversion($url, $xpath, $regex);
     63if (is_string($version) && strlen($version)<255) set_transient($key, $version, $hours*HOUR_IN_SECONDS);
     64return $version;
     65}
     66
    2667function wpbu() {
    2768$wpbu_vars = explode(' ', get_option('wp_browserupdate_browsers', '0 0 0 0 0'));
     
    2970$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]);
    3071echo '<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.04};
     72var $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};
    3273
    3374function $buo_f(){
     
    4283
    4384function wpbu_administration() {
     85if (!current_user_can('manage_options')) wp_die(__('You do not have sufficient permissions to access this page.'));
     86
    4487if (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 
     88foreach (['wpbu_msie', 'wpbu_firefox', 'wpbu_opera', 'wpbu_safari', 'wpbu_google'] as $field) {
     89if (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'];
    4893foreach ($fields_to_sanitize as $field) {
    4994if (isset($_POST[$field])) $_POST[$field] = sanitize_text_field($_POST[$field]);
     
    5297$_POST['wpbu_css_buorg'] = sanitize_textarea_field($_POST['wpbu_css_buorg']);
    5398
    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'];
    55100
    56101$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')];
     
    61106
    62107echo '<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],
    74154];
    75155
    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;
     161foreach (array_keys($browsers) as $i => $key) {
     162$val = $wpbu_vars[$i] ?? '0';
     163if (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);
     167if (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
     179if ($needs_migration) {
     180update_option('wp_browserupdate_browsers', implode(' ', $wpbu_vars));
    84181$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);
     183foreach ($browser_keys as $i => $key) {
     184$browsers[$key]['selected'] = $wpbu_vars[$i] ?? '0';
     185}
     186}
     187
     188###
     189###
     190###
     191
     192echo '<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">';
    97195
    98196foreach ($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 = '';
     198if (!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" />';
     203if ($version) $output .= ' <small>'.esc_html__('Latest version', 'wp-browser-update').': '.esc_html($version).'</small>';
     204$output .= '</td></tr>';
     205}
     206
     207echo $output.'</table>';
    112208
    113209$wpbu_defaults = ['12', 'false', 'true', 'top', 'true', 'true', 'true', 'true'];
  • wp-browser-update/trunk/readme.txt

    r3269228 r3329961  
    66Requires at least: 4.6
    77Requires PHP: 7.4
    8 Stable tag: 5.0.2
     8Stable tag: 5.1
    99License: GPLv3 or later
    1010License URI: https://gnu.org/licenses/gpl
     
    6262
    6363== 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
    6475= 5.0.2 =
    6576* Updated outdated browser versions.
Note: See TracChangeset for help on using the changeset viewer.