<?php
/**
 * @package embed-sharepoint-onedrive-documents
 * @author miniOrange
 * @link https://plugins.miniorange.com
 */


namespace MoSharePointObjectSync\LicenseLibrary;

define(Mo_License_Config::OPTION_PREFIX . "\137\114\111\103\105\116\123\105\x5f\x4c\x49\102\122\x41\x52\131\137\x50\x41\x54\x48", plugin_dir_url(__FILE__));
use MoSharePointObjectSync\LicenseLibrary\Classes\Mo_License_Constants;
use MoSharePointObjectSync\LicenseLibrary\Classes\Mo_License_Dao;
use MoSharePointObjectSync\LicenseLibrary\Exceptions\Mo_License_Grace_Expired_Exception;
use MoSharePointObjectSync\LicenseLibrary\Exceptions\Mo_License_Invalid_Expiry_Date_Exception;
use MoSharePointObjectSync\LicenseLibrary\Exceptions\Mo_License_Missing_Customer_Email_Exception;
use MoSharePointObjectSync\LicenseLibrary\Exceptions\Mo_License_Missing_License_Key_Exception;
use MoSharePointObjectSync\LicenseLibrary\Exceptions\Mo_License_Missing_Or_Invalid_Customer_Key_Exception;
use MoSharePointObjectSync\LicenseLibrary\Exceptions\Mo_License_Unknown_Error_Exception;
use MoSharePointObjectSync\LicenseLibrary\Utils\Mo_License_Actions_Utility;
use MoSharePointObjectSync\LicenseLibrary\Utils\Mo_License_Service_Utility;
if (defined("\x41\x42\x53\x50\101\124\110")) {
    goto OO;
}
exit;
OO:
class Mo_License_Service
{
    public static function is_license_expired()
    {
        try {
            Mo_License_Service_Utility::check_customer_login_and_license();
            $Lx = Mo_License_Service_Utility::is_license_grace_expired();
        } catch (Mo_License_Grace_Expired_Exception $FM) {
            return Mo_License_Service_Utility::return_true_with_code($FM::MESSAGE);
        } catch (Mo_License_Invalid_Expiry_Date_Exception $FM) {
            return Mo_License_Service_Utility::return_true_with_code($FM::MESSAGE);
        } catch (Mo_License_Missing_License_Key_Exception $FM) {
            return Mo_License_Service_Utility::return_true_with_code($FM::MESSAGE);
        } catch (Mo_License_Missing_Customer_Email_Exception $FM) {
            return Mo_License_Service_Utility::return_true_with_code($FM::MESSAGE);
        } catch (Mo_License_Missing_Or_Invalid_Customer_Key_Exception $FM) {
            return Mo_License_Service_Utility::return_true_with_code($FM::MESSAGE);
        } catch (Mo_License_Unknown_Error_Exception $FM) {
            return Mo_License_Service_Utility::return_true_with_code($FM::MESSAGE);
        }
        return Mo_License_Service_Utility::return_false_with_code($Lx["\103\117\104\x45"]);
    }
    public static function is_customer_license_verified()
    {
        try {
            Mo_License_Service_Utility::check_customer_login_and_license();
        } catch (Mo_License_Missing_Customer_Email_Exception $FM) {
            return false;
        } catch (Mo_License_Missing_Or_Invalid_Customer_Key_Exception $FM) {
            return false;
        } catch (Mo_License_Missing_License_Key_Exception $FM) {
            return false;
        }
        return true;
    }
    public static function is_customer_logged_into_plugin()
    {
        try {
            Mo_License_Service_Utility::check_customer_login();
        } catch (Mo_License_Missing_Customer_Email_Exception $FM) {
            return false;
        } catch (Mo_License_Missing_Or_Invalid_Customer_Key_Exception $FM) {
            return false;
        }
        return true;
    }
    public static function get_html_disabled_status($v2 = true)
    {
        if ($v2) {
            goto ec;
        }
        $Gc = self::is_customer_license_verified();
        goto Kk;
        ec:
        $Lm = self::is_license_expired();
        $Gc = !$Lm["\x53\124\101\124\x55\123"];
        Kk:
        if (!(false === $Gc)) {
            goto mc;
        }
        return "\x64\x69\163\x61\x62\154\145\144";
        mc:
        return '';
    }
    public static function refresh_license_expiry()
    {
        $EQ = Mo_License_Actions_Utility::fetch_license_expiry_date();
        if (!$EQ) {
            goto Fm;
        }
        self::update_license_expiry($EQ);
        return $EQ;
        Fm:
        return false;
    }
    public static function mo_check_admin_referer($Zg = -1, $S8 = "\137\x77\160\156\x6f\156\143\x65", $v2 = true)
    {
        $v6 = check_admin_referer($Zg, $S8);
        $Lm = false;
        if ($v2) {
            goto tc;
        }
        $Gc = self::is_customer_license_verified();
        goto ZN;
        tc:
        $Lm = self::is_license_expired();
        $Gc = !$Lm["\x53\x54\101\124\x55\123"];
        ZN:
        if (!(!$Gc || !$v6)) {
            goto VG;
        }
        wp_die(esc_html(Mo_License_Constants::ADMIN_ERROR_MESSAGE));
        VG:
        return true;
    }
    public static function mo_check_ajax_referer($mE = -1, $S8 = false, $JF = true, $v2 = true)
    {
        if ($v2) {
            goto Oc;
        }
        $Gc = self::is_customer_license_verified();
        goto H9;
        Oc:
        $Lm = self::is_license_expired();
        $Gc = !$Lm["\123\x54\101\x54\x55\123"];
        H9:
        $ix = check_ajax_referer($mE, $S8, $JF);
        if (!(!$Gc || !$ix)) {
            goto lM;
        }
        wp_send_json_error(array("\x6d\x65\x73\x73\x61\x67\145" => "\x49\156\166\141\x6c\x69\144\40\x4c\x69\143\145\156\x73\145\x20\113\145\171\56"), 403);
        exit;
        lM:
        wp_send_json_success(array("\x6d\x65\x73\x73\141\x67\145" => "\x52\x65\x66\x65\162\145\x72\40\166\145\x72\x69\x66\x69\x65\x64\x20\x73\165\x63\x63\x65\x73\x73\146\x75\x6c\x6c\x79\x2e"), 200);
    }
    public static function get_expiry_remaining_days($EQ)
    {
        $sr = strtotime($EQ);
        $iB = strtotime(gmdate("\131\x2d\x6d\x2d\x64"));
        $qL = $sr - $iB;
        $cB = floor($qL / (60 * 60 * 24));
        return $cB;
    }
    public static function get_grace_days_left($EQ)
    {
        $cB = self::get_expiry_remaining_days($EQ);
        if (!($cB > 0)) {
            goto a_;
        }
        return false;
        a_:
        return Mo_License_Config::GRACE_PERIOD_DAYS + $cB;
    }
    public static function get_disable_date($EQ)
    {
        return gmdate("\115\40\x64\54\x20\x59", strtotime($EQ . "\53" . Mo_License_Config::GRACE_PERIOD_DAYS . "\x20\144\141\171\163"));
    }
    public static function get_expiry_date()
    {
        $d6 = Mo_License_Service_Utility::mo_decrypt_data(Mo_License_Dao::mo_get_option(Mo_License_Constants::LICENSE_EXPIRY_DATE_OPTION));
        if ($d6) {
            goto NH;
        }
        $d6 = Mo_License_Actions_Utility::fetch_license_expiry_date();
        if ($d6) {
            goto Tt;
        }
        $d6 = Mo_License_Constants::EPOCH_DATE;
        Tt:
        self::update_license_expiry($d6);
        NH:
        return $d6;
    }
    public static function get_formatted_license_expiry_date($ZW)
    {
        try {
            $xG = new \DateTime($ZW);
            $g3 = $xG->getTimestamp();
            $ZW = gmdate("\106\40\x6a\x2c\40\131", $g3);
            return $ZW;
        } catch (\Exception $FM) {
            return $ZW;
        }
    }
    public static function is_customer_license_valid($PW = false, $v2 = true)
    {
        if ($v2) {
            goto Au;
        }
        $Gc = self::is_customer_license_verified();
        goto Wj;
        Au:
        $Lm = self::is_license_expired();
        $Gc = !$Lm["\123\124\101\124\125\x53"];
        Wj:
        if (!(true === $Gc)) {
            goto wC;
        }
        return $PW ? '' : true;
        wC:
        return $PW ? "\x64\x69\x73\141\x62\x6c\x65\144" : false;
    }
    public static function update_license_expiry($EQ)
    {
        Mo_License_Dao::mo_update_option(Mo_License_Constants::LICENSE_EXPIRY_DATE_OPTION, Mo_License_Service_Utility::mo_encrypt_data(self::get_formatted_license_expiry_date($EQ)));
        $RF = self::is_license_expired();
        if (true === $RF["\x53\x54\x41\124\x55\x53"]) {
            goto sG;
        }
        if (!Mo_License_Dao::mo_get_option(Mo_License_Constants::LICENSE_EXPIRED_OPTION)) {
            goto Xa;
        }
        self::reset_license_values();
        Xa:
        goto b1;
        sG:
        Mo_License_Dao::mo_update_option(Mo_License_Constants::LICENSE_EXPIRED_OPTION, true);
        b1:
    }
    public static function reset_license_values()
    {
        $lO = Mo_License_Constants::get_constants();
        foreach ($lO as $cD => $V7) {
            if (!(strpos($cD, "\117\x50\x54\x49\x4f\116") !== false)) {
                goto yS;
            }
            Mo_License_Dao::mo_delete_option($V7);
            yS:
            Ag:
        }
        OD:
    }
}
