|
1 | 1 | <?php |
2 | 2 | /* |
3 | 3 | * Load NPP |
4 | | - * Version: 2.1.3 |
| 4 | + * Version: 2.1.4 |
5 | 5 | * Author: Hasan CALISIR |
6 | 6 | * Author URI: https://www.psauxit.com/ |
7 | 7 | * License: GPL-2.0+ |
|
19 | 19 |
|
20 | 20 | // Define a constant for the desktop user agent |
21 | 21 | if (!defined('NPPP_USER_AGENT')) { |
22 | | - define('NPPP_USER_AGENT', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36'); |
| 22 | + define('NPPP_USER_AGENT', 'NPP/2.1.4 (NginxCacheWarm; device=desktop; Desktop)'); |
23 | 23 | } |
24 | 24 |
|
25 | 25 | // Define a constant for the mobile user agent |
26 | 26 | if (!defined('NPPP_USER_AGENT_MOBILE')) { |
27 | | - define('NPPP_USER_AGENT_MOBILE', 'Mozilla/5.0 (Linux; Android 15; SM-G960U) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.6778.81 Mobile Safari/537.36'); |
| 27 | + define('NPPP_USER_AGENT_MOBILE', 'NPP/2.1.4 (NginxCacheWarm; device=mobile; Mobile)'); |
| 28 | +} |
| 29 | + |
| 30 | +// Define a header constant for mimic real browser request |
| 31 | +if (!defined('NPPP_HEADER_ACCEPT')) { |
| 32 | + define('NPPP_HEADER_ACCEPT', 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,' . '*' . '/' . '*;q=0.8'); |
| 33 | +} |
| 34 | + |
| 35 | +// Prepare PATH and SAFEXEC related env |
| 36 | +function nppp_prepare_request_env(bool $force = false): void { |
| 37 | + static $done = false; |
| 38 | + |
| 39 | + // allow re-run when forced |
| 40 | + if ($done && !$force) { |
| 41 | + return; |
| 42 | + } |
| 43 | + |
| 44 | + if (!function_exists('getenv') || !function_exists('putenv')) { |
| 45 | + $done = true; |
| 46 | + return; |
| 47 | + } |
| 48 | + |
| 49 | + // register the shutdown restore ONCE |
| 50 | + if (empty($GLOBALS['NPPP__RESTORE_REGISTERED'])) { |
| 51 | + register_shutdown_function(static function () { |
| 52 | + // PATH |
| 53 | + if (array_key_exists('NPPP__ORIG_PATH', $GLOBALS)) { |
| 54 | + $orig = $GLOBALS['NPPP__ORIG_PATH']; |
| 55 | + if ($orig === null) putenv('PATH'); else putenv("PATH={$orig}"); |
| 56 | + } |
| 57 | + |
| 58 | + // Always unset safexec related envs |
| 59 | + putenv('SAFEXEC_QUIET'); |
| 60 | + putenv('SAFEXEC_PCTNORM'); |
| 61 | + putenv('SAFEXEC_PCTNORM_CASE'); |
| 62 | + putenv('SAFEXEC_DETACH'); |
| 63 | + }); |
| 64 | + $GLOBALS['NPPP__RESTORE_REGISTERED'] = true; |
| 65 | + } |
| 66 | + |
| 67 | + // PATH |
| 68 | + $need = ['/usr/local/sbin','/usr/local/bin','/usr/sbin','/usr/bin','/sbin','/bin']; |
| 69 | + $orig_path = getenv('PATH'); |
| 70 | + $parts = $orig_path ? array_filter(explode(':', (string)$orig_path), fn($p) => $p !== '' && $p !== '.') : []; |
| 71 | + $merged = array_values(array_unique(array_merge($need, $parts))); |
| 72 | + $new_path = implode(':', $merged); |
| 73 | + |
| 74 | + // Save only once so $force runs don't clobber the true original |
| 75 | + if (!array_key_exists('NPPP__ORIG_PATH', $GLOBALS)) { |
| 76 | + $GLOBALS['NPPP__ORIG_PATH'] = ($orig_path === false) ? null : $orig_path; |
| 77 | + } |
| 78 | + |
| 79 | + if ($new_path !== $orig_path) { |
| 80 | + putenv("PATH={$new_path}"); |
| 81 | + } |
| 82 | + |
| 83 | + // Always quiet safexec |
| 84 | + putenv('SAFEXEC_QUIET=1'); |
| 85 | + |
| 86 | + // safexec mode (off|upper|lower|preserve) |
| 87 | + $opts = get_option('nginx_cache_settings', []); |
| 88 | + $mode = isset($opts['nginx_cache_pctnorm_mode']) ? strtolower((string)$opts['nginx_cache_pctnorm_mode']) : 'off'; |
| 89 | + if (!in_array($mode, ['off','upper','lower','preserve'], true)) $mode = 'off'; |
| 90 | + |
| 91 | + switch ($mode) { |
| 92 | + case 'upper': |
| 93 | + putenv('SAFEXEC_PCTNORM=1'); |
| 94 | + putenv('SAFEXEC_PCTNORM_CASE=upper'); |
| 95 | + break; |
| 96 | + case 'lower': |
| 97 | + putenv('SAFEXEC_PCTNORM=1'); |
| 98 | + putenv('SAFEXEC_PCTNORM_CASE=lower'); |
| 99 | + break; |
| 100 | + case 'preserve': |
| 101 | + putenv('SAFEXEC_PCTNORM=1'); |
| 102 | + putenv('SAFEXEC_PCTNORM_CASE=off'); |
| 103 | + break; |
| 104 | + case 'off': |
| 105 | + default: |
| 106 | + putenv('SAFEXEC_PCTNORM=0'); |
| 107 | + putenv('SAFEXEC_PCTNORM_CASE'); |
| 108 | + break; |
| 109 | + } |
| 110 | + |
| 111 | + // Detach behavior for this request |
| 112 | + putenv('SAFEXEC_DETACH=auto'); |
| 113 | + |
| 114 | + $done = true; |
28 | 115 | } |
29 | 116 |
|
30 | 117 | // Include plugin files |
|
35 | 122 | require_once dirname(__DIR__) . '/includes/log.php'; |
36 | 123 | require_once dirname(__DIR__) . '/includes/svg.php'; |
37 | 124 | require_once dirname(__DIR__) . '/includes/settings.php'; |
| 125 | +require_once dirname(__DIR__) . '/includes/related.php'; |
38 | 126 | require_once dirname(__DIR__) . '/includes/purge.php'; |
39 | 127 | require_once dirname(__DIR__) . '/includes/preload.php'; |
40 | 128 | require_once dirname(__DIR__) . '/includes/help.php'; |
|
47 | 135 | require_once dirname(__DIR__) . '/includes/plugin-tracking.php'; |
48 | 136 | require_once dirname(__DIR__) . '/includes/update.php'; |
49 | 137 | require_once dirname(__DIR__) . '/includes/dashboard-widget.php'; |
| 138 | +require_once dirname(__DIR__) . '/includes/compat-elementor.php'; |
| 139 | +require_once dirname(__DIR__) . '/includes/compat-gutenberg.php'; |
50 | 140 |
|
51 | 141 | // Get the status of Auto Purge option |
52 | 142 | $options = get_option('nginx_cache_settings'); |
|
66 | 156 | ); |
67 | 157 |
|
68 | 158 | // Add actions and filters |
69 | | -add_action('init', 'nppp_load_i18n'); |
70 | 159 | add_action('load-settings_page_nginx_cache_settings', 'nppp_enqueue_nginx_fastcgi_cache_purge_preload_assets'); |
71 | 160 | add_action('load-settings_page_nginx_cache_settings', 'nppp_check_for_plugin_update'); |
72 | 161 | add_action('admin_enqueue_scripts', 'nppp_enqueue_nginx_fastcgi_cache_purge_preload_requisite_assets'); |
|
116 | 205 | add_action('npp_plugin_tracking_event', 'nppp_plugin_tracking', 10, 1); |
117 | 206 | add_action('wp_dashboard_setup', 'nppp_add_dashboard_widget'); |
118 | 207 | add_action('wp_ajax_nppp_update_enable_proxy_option', 'nppp_update_enable_proxy_option'); |
| 208 | +add_action('wp_ajax_nppp_update_related_fields', 'nppp_update_related_fields'); |
| 209 | +add_action('wp_ajax_nppp_locate_cache_file', 'nppp_locate_cache_file_ajax'); |
| 210 | +add_action('wp_ajax_nppp_update_pctnorm_mode', 'nppp_update_pctnorm_mode'); |
119 | 211 | $nppp_auto_purge |
120 | 212 | ? array_map(function($purge_action) { add_action($purge_action, 'nppp_purge_callback'); }, $page_cache_purge_actions) |
121 | 213 | : array_map(function($purge_action) { remove_action($purge_action, 'nppp_purge_callback'); }, $page_cache_purge_actions); |
|
0 commit comments