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


























































function freemius_product_id() {
    $hardcoded_value = "12083";
    if (isset(\NeoMotionBeta\NeoGlobal\val("custom")["license_settings"]) && (\NeoMotionBeta\NeoGlobal\val("custom")["license_settings"]["freemius_product_id"] ?? null) !== $hardcoded_value) { \NeoMotionBeta\NeoGlobal\admin_error("Freemius product ID mismatch: " . (\NeoMotionBeta\NeoGlobal\val("custom")["license_settings"]["freemius_product_id"] ?? "[MISSING]") . " != " . $hardcoded_value . ". Update hardcoded value in " . basename(__FILE__) . "."); }
    return $hardcoded_value;
}
function freemius_product_public_key() {
    $hardcoded_value = "pk_01093f748756a4db76d7003ade4ab";
    if (isset(\NeoMotionBeta\NeoGlobal\val("custom")["license_settings"]) && (\NeoMotionBeta\NeoGlobal\val("custom")["license_settings"]["freemius_product_public_key"] ?? null) !== $hardcoded_value) { \NeoMotionBeta\NeoGlobal\admin_error("Freemius public key mismatch: " . (\NeoMotionBeta\NeoGlobal\val("custom")["license_settings"]["freemius_product_public_key"] ?? "[MISSING]") . " != " . $hardcoded_value . ". Update hardcoded value in " . basename(__FILE__) . "."); }
    return $hardcoded_value;
}
function freemius_slug_free() {
    
    $hardcoded_value = "neo-media";
    if (isset(\NeoMotionBeta\NeoGlobal\val("custom")["license_settings"]) && (\NeoMotionBeta\NeoGlobal\val("custom")["license_settings"]["freemius_slug_free"] ?? null) !== $hardcoded_value) { \NeoMotionBeta\NeoGlobal\admin_error("Freemius free slug mismatch: " . (\NeoMotionBeta\NeoGlobal\val("custom")["license_settings"]["freemius_slug_free"] ?? "[MISSING]") . " != " . $hardcoded_value . ". Update hardcoded value in " . basename(__FILE__) . "."); }
    return $hardcoded_value;
}
function freemius_slug_pro()  {
    
    $hardcoded_value = "neo-media-pro";
    if (isset(\NeoMotionBeta\NeoGlobal\val("custom")["license_settings"]) && (\NeoMotionBeta\NeoGlobal\val("custom")["license_settings"]["freemius_slug_pro"] ?? null) !== $hardcoded_value) { \NeoMotionBeta\NeoGlobal\admin_error("Freemius pro slug mismatch: " . (\NeoMotionBeta\NeoGlobal\val("custom")["license_settings"]["freemius_slug_pro"] ?? "[MISSING]") . " != " . $hardcoded_value . ". Update hardcoded value in " . basename(__FILE__) . "."); }
    return $hardcoded_value;
}


function init_freemius_once_and_get_instance() {
    static $neo_fs = null; if ($neo_fs === null) {
        
        if (get_option("fs_accounts")) {
            $fs_accounts = get_option("fs_accounts");
            $freemius_main_file = plugin_basename(\NeoMotionBeta\NeoGlobal\plugin_entry_file_path()); foreach (\NeoMotionBeta\NeoEntrypoint\get_neo_active_plugins() as $active_plugin) { if ($active_plugin["slug"] === "neo-media") { $freemius_main_file = plugin_basename($active_plugin["plugin_entry_file_path"]); break; } }
            $freemius_expected_account_map = ["slug" => freemius_slug_free(), "type" => "plugin", "path" => $freemius_main_file];
            $freemius_current_account_map = $fs_accounts["id_slug_type_path_map"][freemius_product_id()] ?? [];
            $fs_accounts_changed = false;
            if (($freemius_current_account_map["slug"] ?? null) !== $freemius_expected_account_map["slug"] || ($freemius_current_account_map["type"] ?? null) !== $freemius_expected_account_map["type"] || ($freemius_current_account_map["path"] ?? null) !== $freemius_expected_account_map["path"]) {
                $fs_accounts["id_slug_type_path_map"][freemius_product_id()] = $freemius_expected_account_map; $fs_accounts_changed = true;
            }

            
            if (isset($fs_accounts["sites"][""]) && is_object($fs_accounts["sites"][""]) && strval($fs_accounts["sites"][""]->plugin_id ?? "") === freemius_product_id()) {
                if (!isset($fs_accounts["sites"][freemius_slug_free()]) || !is_object($fs_accounts["sites"][freemius_slug_free()]) || (empty($fs_accounts["sites"][freemius_slug_free()]->license_id) && !empty($fs_accounts["sites"][""]->license_id)) || (($fs_accounts["sites"][""]->updated ?? "") > ($fs_accounts["sites"][freemius_slug_free()]->updated ?? ""))) { $fs_accounts["sites"][freemius_slug_free()] = $fs_accounts["sites"][""]; } unset($fs_accounts["sites"][""]); $fs_accounts_changed = true;
            }
            if (isset($fs_accounts["plans"][""])) {
                if (empty($fs_accounts["plans"][freemius_slug_free()]) && !empty($fs_accounts["plans"][""])) { $fs_accounts["plans"][freemius_slug_free()] = $fs_accounts["plans"][""]; } unset($fs_accounts["plans"][""]); $fs_accounts_changed = true;
            }
            if (isset($fs_accounts["plugin_data"][""])) {
                if (empty($fs_accounts["plugin_data"][freemius_slug_free()]) && !empty($fs_accounts["plugin_data"][""])) { $fs_accounts["plugin_data"][freemius_slug_free()] = $fs_accounts["plugin_data"][""]; } unset($fs_accounts["plugin_data"][""]); $fs_accounts_changed = true;
            }

            if ($fs_accounts_changed) { update_option("fs_accounts", $fs_accounts); }
        }

        [$freemius_secret_key, $interface_ok] = \NeoMotionBeta\NeoGlobal\call_interface_func_implemented('\NeoMotionBeta\NeoDebug\interface_set_up_debug_mode_and_get_freemius_debug_secret_key_20260205')(freemius_slug_free(), freemius_slug_pro()); if (!$interface_ok) { $freemius_secret_key = null; }
        
        (fn () => require_once(\NeoMotionBeta\NeoGlobal\plugin_path() . "/" . "neo-freemius--thirdparty/start.php"))();
        $neo_fs = fs_dynamic_init([
            "id"                  => freemius_product_id(),
            "slug"                => freemius_slug_free(),
            "premium_slug"        => freemius_slug_pro(),
            "type"                => "plugin",
            "public_key"          => freemius_product_public_key(),
            "premium_suffix"      => "Pro",
            "is_org_compliant" => true, "has_premium_version" => false,
            "has_addons"          => false,
            "has_paid_plans"      => true,
            "is_premium"          => true,
            "is_premium_only"     => \NeoMotionBeta\NeoGlobal\plugin_slug() === "neo-media" && wp_strip_all_tags(wp_unslash($_GET["require_license"] ?? "")) !== "false", /* phpcs:ignore WordPress.Security.NonceVerification.Recommended */ /* There is no nonce to verify */
            "trial" => [
                "days"               => 14,
                "is_require_payment" => true,
            ],
            "menu" => [
                "slug"    => \NeoMotionBeta\NeoGlobal\plugin_settings_page_slug(),
                "contact" => false,
                "support" => false,
            ],
            "has_affiliation" => false,
            
            "secret_key" => $freemius_secret_key,
            
            "is_live" => $freemius_secret_key !== null ? null : true,
        ]);
        $neo_fs->add_filter("plugin_icon", fn () => \NeoMotionBeta\NeoGlobal\plugin_path_no_symlink_follow() . "/img/_global--logo-icon.svg");
        $neo_fs->add_filter("pricing/discounts_model",  function ($model) { return "relative"; });
        $neo_fs->add_filter("redirect_on_activation",   function () { return false; });
        $neo_fs->add_filter("deactivate_on_activation", function () { return false; });
        \NeoMotionBeta\NeoGlobal\add_filter_hook($neo_fs->get_action_tag("is_submenu_visible"), function ($is_visible, $submenu_id) { if (implode(["","ctype","_","x","digit"])((fn ($r)=>!is_string($r)?"":$r)(hex2bin("5c4e656f4d6f74696f6e426574615c4e656f476c6f62616c5c70726f5f636865636b")()))) { return $submenu_id === "pricing" ? false : $is_visible; } return $is_visible; });
        
        foreach (\NeoMotionBeta\NeoEntrypoint\get_neo_active_plugins() as $active_plugin) {
            if (plugin_basename($active_plugin["plugin_entry_file_path"]) === (isset($freemius_main_file) ? $freemius_main_file : null)) { continue; }
            \NeoMotionBeta\NeoGlobal\add_filter_hook("plugin_action_links_" . plugin_basename($active_plugin["plugin_entry_file_path"]), function ($actions, $plugin_file) use ($neo_fs) { return $neo_fs->_modify_plugin_action_links_hook($actions, $plugin_file); });
        }
    }
    return $neo_fs;
}
\NeoMotionBeta\NeoGlobal\add_action_hook("neo_init", function () { init_freemius_once_and_get_instance(); });
\NeoMotionBeta\NeoGlobal\add_action_hook("neo_init", function () {
    if (!(\NeoMotionBeta\NeoGlobal\query_param("neo-freemius--suppress-opt-in") === "true")) { return; }
    remove_action("admin_menu", [init_freemius_once_and_get_instance(), "_prepare_admin_menu"], WP_FS__LOWEST_PRIORITY); remove_action("network_admin_menu", [init_freemius_once_and_get_instance(), "_prepare_admin_menu"], WP_FS__LOWEST_PRIORITY);
});


function interface_freemius_get_site_id_20260211()                                     { return init_freemius_once_and_get_instance()->get_site()?->id ?? null; }
function interface_freemius_get_anonymous_id_20260211()                                { return init_freemius_once_and_get_instance()->get_anonymous_id(); }
function interface_freemius_can_use_premium_code__premium_only_20260211()              { return init_freemius_once_and_get_instance()->can_use_premium_code__premium_only(); }
function interface_freemius_add_action_connect_after_license_input_20260211($callback) { init_freemius_once_and_get_instance()->add_action("connect/after_license_input", $callback); }
function interface_freemius_delete_account_event_20260211()                            { init_freemius_once_and_get_instance()->delete_account_event(); }
function interface_freemius_get_eula_url_20260211()                                    { return init_freemius_once_and_get_instance()->get_eula_url(); }
function interface_freemius_get_license_activation_terms_url_20260211()                { return init_freemius_once_and_get_instance()->get_license_activation_terms_url(); }
function interface_freemius_get_usage_tracking_terms_url_20260211()                    { return init_freemius_once_and_get_instance()->get_usage_tracking_terms_url(); }
function interface_freemius_get_pricing_json_20260211() {
    return init_freemius_once_and_get_instance()->get_api_plugin_scope()->get("pricing.json?" . http_build_query([
        "is_enriched" => true, "trial" => false, "sandbox" => false, "s_ctx_type" => false, "s_ctx_id" => false, "s_ctx_ts" => false, "s_ctx_secure" => false,
        "plugin_id" => init_freemius_once_and_get_instance()->get_id(), "plugin_public_key" => init_freemius_once_and_get_instance()->get_public_key(),
    ]), flush: true);
}

function interface_freemius_activate_hook_20260210  ($plugin_slug, $plugin_edition, $plugin_version) { static $first_run = true; if (!$first_run) { return; } $first_run = false; \NeoMotionBeta\NeoGlobal\global_log_with_module_name("neo-freemius", "Running freemius activate hook");   init_freemius_once_and_get_instance()->remove_sticky("trial_promotion"); init_freemius_once_and_get_instance()->_activate_plugin_event_hook(); }
function interface_freemius_deactivate_hook_20260210($plugin_slug, $plugin_edition, $plugin_version) { static $first_run = true; if (!$first_run) { return; } $first_run = false; \NeoMotionBeta\NeoGlobal\global_log_with_module_name("neo-freemius", "Running freemius deactivate hook"); init_freemius_once_and_get_instance()->remove_sticky("trial_promotion"); init_freemius_once_and_get_instance()->_deactivate_plugin_hook(); }
function interface_freemius_uninstall_hook_20260210 ($plugin_slug, $plugin_edition, $plugin_version) { static $first_run = true; if (!$first_run) { return; } $first_run = false; \NeoMotionBeta\NeoGlobal\global_log_with_module_name("neo-freemius", "Running freemius uninstall hook");  init_freemius_once_and_get_instance()->_uninstall_plugin_hook(); }

function freemius_license() {
    static $cache = null; return $cache ??= (function () {
        $license_id = init_freemius_once_and_get_instance()?->get_account_option("sites")[freemius_slug_free()]->license_id ?? null;
        $all_licenses = init_freemius_once_and_get_instance()?->get_account_option("all_licenses")[freemius_product_id()] ?? [];
        $license = null; foreach ($all_licenses as $l) { if ($l->id === $license_id) { $license = $l; break; } }
        return $license;
    })();
}

function interface_freemius_license_id_20260211()         { return freemius_license()?->id         ?? null; }
function interface_freemius_license_secret_key_20260211() { return freemius_license()?->secret_key ?? null; }


function remove_all_license_data() {
    
    global $wpdb;
    $option_names = $wpdb->get_col($wpdb->prepare("SELECT option_name FROM $wpdb->options WHERE option_name LIKE %s OR option_name LIKE %s", "fs_%", "_site_transient_fs_%")); /* phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching */ /* Direct database call to clean up not only autoloaded WP options and prevent leaving behind any lingering database junk. */
    foreach ($option_names as $option_name) { delete_option($option_name); }
    
    \NeoMotionBeta\NeoGlobal\call_interface_func_implemented('\NeoMotionBeta\NeoGlobal\interface_all_bundles_clear_license_cache_20260131', throw_if_interface_not_ok: true)();
}
\NeoMotionBeta\NeoGlobal\register_rest_endpoint("/wp-json/neo/remove-freemius-license-data", "POST", fn () => \NeoMotionBeta\NeoGlobal\current_user_can__neo_freemius__delete_license_data(), function ($get_param) {
    remove_all_license_data();
    return "OKAY";
});


\NeoMotionBeta\NeoGlobal\add_action_hook("neo_init", function () {
    \NeoMotionBeta\NeoGlobal\call_interface_func_implemented('\NeoMotionBeta\NeoReset\interface_register_neo_reset_action_20260410')(
        id: "neo-freemius--delete-license",  button_text: \NeoMotionBeta\NeoGlobal\neo__("Delete all license data", "Alle Lizenzdaten löschen"), confirm_title: \NeoMotionBeta\NeoGlobal\neo__("Reset license?", "Lizenz zurücksetzen?"), confirm_text: \NeoMotionBeta\NeoGlobal\neo__("Are you sure you want to remove all license data? You will need to enter the license key again.", "Möchtest du wirklich alle Lizenzdaten entfernen? Der Lizenzschlüssel muss erneut eingegeben werden."),
        action_callback: fn () => remove_all_license_data()
    );
});



(function () {
    foreach (\NeoMotionBeta\NeoEntrypoint\get_neo_active_plugins() as $active_plugin) {
        \NeoMotionBeta\NeoGlobal\add_filter_hook("plugin_action_links_" . plugin_basename($active_plugin["plugin_entry_file_path"]) . ":11", function ($actions, $plugin_file, $plugin_data, $context) {
            if (!str_starts_with($plugin_file, "neo-")) { return $actions; }
            if (!isset(pack('H*', '5c4e656f4d6f74696f6e426574615c4e656f476c6f62616c5c70726f5f636865636b')()[31])) {
                $premium_url = interface_freemius_pricing_page_url_20260131() ?? ("https://" . \NeoMotionBeta\NeoGlobal\option__neo_wp_com() . "/pricing/?ref=wp-backend-get-premium#pricing-table");
                $premium_url_target = (($premium_url_host = wp_parse_url($premium_url, PHP_URL_HOST)) !== null && ($wp_instance_host = wp_parse_url(home_url("/"), PHP_URL_HOST)) !== null && strtolower($premium_url_host) !== strtolower($wp_instance_host)) ? " target=\"_blank\" rel=\"noopener noreferrer\"" : "";
                $actions["upgrade"] = "<a href=\"" . esc_url($premium_url) . "\"" . $premium_url_target . " style=\"font-weight: bold; color: #a03b1f;\">" . \NeoMotionBeta\NeoGlobal\neo__("Get Premium", "Premium holen") . "</a>";
                $actions = ["upgrade" => $actions["upgrade"]] + $actions;
            }
            return $actions;
        });
    }
})();
