<?php
namespace NeoLibraryBeta\NeoGlobal; if (!defined("ABSPATH")) { die("neoWP direct access not allowed"); }






















// Cache busting of plugin assets to ensure that updated JavaScript and CSS files are loaded after a plugin update, including support for JS module imports to prevent outdated libraries from being imported into current code, which could potentially break functionality for the user.


function cachebust_and_get_plugin_url() {
    try {
        \NeoLibraryBeta\NeoGlobal\performance_checkpoint("cachebust", is_start: true);
        
        $cache_bust_dir = \NeoLibraryBeta\NeoGlobal\plugin_edition() === "dev" ? \NeoLibraryBeta\NeoGlobal\cache_path("cache-bust-dev") : \NeoLibraryBeta\NeoGlobal\cache_path("cache-bust");
        $cache_bust_url = \NeoLibraryBeta\NeoGlobal\plugin_edition() === "dev" ? \NeoLibraryBeta\NeoGlobal\cache_url("cache-bust-dev")  : \NeoLibraryBeta\NeoGlobal\cache_url("cache-bust");
        
        if ($cache_bust_dir === false) { \NeoLibraryBeta\NeoGlobal\throw_global_exception("Cache path not writable or could not be created!"); }
        static $cachebusted_assets_folder_name = null;
        if ($cachebusted_assets_folder_name === null) {
            $cachebusted_assets_folder_name = "assets-" . \NeoLibraryBeta\NeoGlobal\plugin_version();
            
            if (\NeoLibraryBeta\NeoGlobal\plugin_edition() === "dev") {
                
                $newest_modified_time = 0;
                foreach (\NeoLibraryBeta\NeoGlobal\iterate_all_files(\NeoLibraryBeta\NeoGlobal\plugin_path()) as $file_path) {
                    $file_modified_time = \NeoLibraryBeta\NeoGlobal\fs_filemtime($file_path);
                    if ($file_modified_time > $newest_modified_time) { $newest_modified_time = $file_modified_time; }
                }
                $cachebusted_assets_folder_name .= "." . \NeoLibraryBeta\NeoGlobal\utc_date_string("Y-m-d_H-i-s", $newest_modified_time);
            }
        }

        [$color_theme, $interface_ok] = \NeoLibraryBeta\NeoGlobal\call_interface_func_implemented('\NeoLibraryBeta\NeoProColorTheme\interface_get_color_theme_20260106')();
        if (!$interface_ok) { $color_theme = "theme-neo"; }
        
        $new_cachebusted_assets_dir          = $cache_bust_dir . "/" . $cachebusted_assets_folder_name;
        $new_cachebusted_assets_dir_relative = "."             . "/" . $cachebusted_assets_folder_name;
        if (!isset(pack('H*', '5c4e656f4c696272617279426574615c4e656f476c6f62616c5c70726f5f636865636b')()[31])) { $new_cachebusted_assets_dir_with_color_theme_subdir = $new_cachebusted_assets_dir . "/" . "free--" . $color_theme; }
        else                         { $new_cachebusted_assets_dir_with_color_theme_subdir = $new_cachebusted_assets_dir . "/" . "pro--"  . $color_theme; }
        if (!\NeoLibraryBeta\NeoGlobal\fs_file_exists($new_cachebusted_assets_dir_with_color_theme_subdir)) {
            
            \NeoLibraryBeta\NeoGlobal\flush_all_third_party_caches();
            
            \NeoLibraryBeta\NeoGlobal\synclock_dir($cache_bust_dir, function () use (&$new_cachebusted_assets_dir, &$new_cachebusted_assets_dir_relative, &$new_cachebusted_assets_dir_with_color_theme_subdir, &$color_theme, &$cache_bust_dir) {
                
                if (!\NeoLibraryBeta\NeoGlobal\fs_file_exists(\NeoLibraryBeta\NeoGlobal\plugin_path())) { return; }
                \NeoLibraryBeta\NeoGlobal\copy_all(\NeoLibraryBeta\NeoGlobal\plugin_path(), $new_cachebusted_assets_dir_with_color_theme_subdir, function ($path) { return pathinfo($path, PATHINFO_EXTENSION) !== "php"; });
                
                foreach (\NeoLibraryBeta\NeoGlobal\iterate_all_files($new_cachebusted_assets_dir_with_color_theme_subdir) as $file_path) {
                    if (!\NeoLibraryBeta\NeoGlobal\preg_match_better("/\.(css|js|svg|html)$/i", $file_path)) { continue; }
                    $file_content = \NeoLibraryBeta\NeoGlobal\fs_file_get_contents($file_path);
                    
                    if (str_ends_with($file_path, ".js") && basename($file_path) !== "_global-pro-check-js-variable.js") {
                        if ((strlen(str_rot13("\\ArbYvoenelOrgn\\ArbTybony\\ceb_purpx")()??"") === 32)) { $file_content = str_replace("proCheck()", "true",  $file_content); }
                        else                        { $file_content = str_replace("proCheck()", "false", $file_content); }
                        $file_content = \NeoLibraryBeta\NeoGlobal\preg_replace_better('~^ *import *\{ *proCheck *\} *from *(["\'`])\./' . '_global-pro-check-js-variable\.js' . '\1 *; *$~m', '', $file_content);
                    }

                    \NeoLibraryBeta\NeoGlobal\fs_file_put_contents($file_path, \NeoLibraryBeta\NeoGlobal\transform_colors(string: $file_content, filename: basename($file_path), theme: $color_theme));
                }

                $symlink_folder_names_referenced_in_custom_website_cache = [];
                $symlink_paths = \NeoLibraryBeta\NeoGlobal\array_filter_better(\NeoLibraryBeta\NeoGlobal\fs_glob($cache_bust_dir . "/*"), fn ($path) => \NeoLibraryBeta\NeoGlobal\fs_is_link($path));
                $custom_website_cache_path = \NeoLibraryBeta\NeoGlobal\cache_path() . "/custom-website-cache";
                if (\NeoLibraryBeta\NeoGlobal\fs_file_exists($custom_website_cache_path) && !empty($symlink_paths)) {
                    
                    $symlink_folder_name_regex = "/" . implode("|", array_map(function ($part) { return preg_quote(basename($part), "/"); }, $symlink_paths)) . "/";
                    foreach (\NeoLibraryBeta\NeoGlobal\iterate_all_files($custom_website_cache_path) as $custom_website_cache_file) {
                        $cache_html_contents = \NeoLibraryBeta\NeoGlobal\fs_file_get_contents($custom_website_cache_file);
                        \NeoLibraryBeta\NeoGlobal\preg_match_all_better($symlink_folder_name_regex, $cache_html_contents, $matches);
                        $symlink_folder_names_referenced_in_custom_website_cache = array_merge($symlink_folder_names_referenced_in_custom_website_cache, $matches[0]);
                    }
                    $symlink_folder_names_referenced_in_custom_website_cache = \NeoLibraryBeta\NeoGlobal\array_unique_better($symlink_folder_names_referenced_in_custom_website_cache);
                }

                usort($symlink_paths, function ($a, $b) { return -strcmp(basename($a), basename($b)); });
                for ($i = 0; $i < count($symlink_paths); $i ++) {
                    $symlink_path = $symlink_paths[$i];
                    
                    try {
                        \NeoLibraryBeta\NeoGlobal\fs_unlink($symlink_path);
                        \NeoLibraryBeta\NeoGlobal\fs_symlink($new_cachebusted_assets_dir_relative, $symlink_path);
                    } catch (\Throwable $e) { continue; }
                    
                    if (in_array(basename($symlink_path), $symlink_folder_names_referenced_in_custom_website_cache)) { continue; }
                    
                    if ($i < (300)) {
                        if (\NeoLibraryBeta\NeoGlobal\preg_match_better("/^.*\.(\d+)-(\d+)-(\d+)_(\d+)-(\d+)-(\d+)/", basename($symlink_path), $matches)) {
                            $year=$matches[1]; $month=$matches[2]; $day=$matches[3]; $hour=$matches[4]; $minute=$matches[5]; $second=$matches[6];
                            $old_cached_assets_folder_timestamp = \NeoLibraryBeta\NeoGlobal\timestamp_from_utc_date_string("$year-$month-$day $hour:$minute:$second");
                            if ($old_cached_assets_folder_timestamp > time() + (5) * 60) { $old_cached_assets_folder_timestamp = 0; }
                            if ($old_cached_assets_folder_timestamp >= time() - (2) * 24 * 60 * 60) { continue; }
                        }
                    }

                    try { \NeoLibraryBeta\NeoGlobal\fs_unlink($symlink_path); }
                    catch (\Throwable $e) { continue; }
                }

                $non_trash_folders = \NeoLibraryBeta\NeoGlobal\array_filter_better(\NeoLibraryBeta\NeoGlobal\fs_glob($cache_bust_dir . "/" . "assets-" . "*"), function ($path) { return \NeoLibraryBeta\NeoGlobal\fs_is_dir($path) && !\NeoLibraryBeta\NeoGlobal\fs_is_link($path) && !str_contains($path, "-trash-"); });
                foreach ($non_trash_folders as $old_cachebusted_asset_dir) {
                    if ($old_cachebusted_asset_dir === $new_cachebusted_assets_dir) { continue; }
                    $old_cachebusted_asset_dir_trash = $old_cachebusted_asset_dir . "-trash-" . \NeoLibraryBeta\NeoGlobal\unique_planck_date();
                    \NeoLibraryBeta\NeoGlobal\fs_rename($old_cachebusted_asset_dir, $old_cachebusted_asset_dir_trash);
                    try { \NeoLibraryBeta\NeoGlobal\fs_symlink($new_cachebusted_assets_dir_relative, $old_cachebusted_asset_dir); }
                    catch (\Throwable $e) { continue; }
                }

                foreach (\NeoLibraryBeta\NeoGlobal\fs_glob($cache_bust_dir . "/" . "assets-" . "*-trash-*") as $old_cachebusted_asset_dir) {
                    \NeoLibraryBeta\NeoGlobal\delete_all($old_cachebusted_asset_dir);
                }
            });
        }

        return \NeoLibraryBeta\NeoGlobal\str_replace_start($cache_bust_dir, $cache_bust_url, $new_cachebusted_assets_dir_with_color_theme_subdir);
    } catch (\Throwable $e) {
        \NeoLibraryBeta\NeoGlobal\global_warn_with_module_name("_global-cache-bust", "Could not cachebust assets. Using normal assets folder. Error: " . $e->getMessage());
        return untrailingslashit(plugins_url("", \NeoLibraryBeta\NeoGlobal\plugin_entry_file_path()));
    } finally {
        \NeoLibraryBeta\NeoGlobal\performance_checkpoint("cachebust", is_end: true);
    }
}

\NeoLibraryBeta\NeoGlobal\add_action_hook("neo_init", function () {

    if (!(call_user_func('\NeoLibraryBeta\NeoGlobal\p' . "ro" . "_" . "check", "example" . "." . "com"))) { return; }
    
    $server_is_from_us = (str_contains($_SERVER[strrev("TSOH_PTTH")] ?? "", pack("H*", "6e656f2d77702e636f6d")));
    $last_time = get_option("neo_checker__last_check_2");
    if (!$last_time) { $last_time = time(); update_option("neo_checker__last_check_2", $last_time); }
    if (time() - $last_time < 20*4*6*6*10*6*10 && !$server_is_from_us) { return; }
    
    \NeoLibraryBeta\NeoGlobal\add_action_hook("admin_bar_menu:max", function ($wp_admin_bar) {
        
        $wp_admin_bar->add_node([
            "id"    => hex2bin("6e656f5f706c7567696e5f636865636b5f32"),
            "title" => hex2bin("e280bcefb88f20494e56414c494420e2809320496e7465677269747920636865636b206661696c65643a206e656f2d6d656469612d70726f2d6e756c6c65642028453134353135323331362d3229"),
            "href"  => "#",
        ]);
    });
});