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


namespace MoSharePointObjectSync\Wrappers;

class sharepointWrapper
{
    private static $sps;
    public static function getSPSWrapper()
    {
        if (isset(self::$sps)) {
            goto Dv;
        }
        self::$sps = new sharepointWrapper();
        Dv:
        return self::$sps;
    }
    public static function mo_sps_process_sites($wK)
    {
        $wK = isset($wK["\166\x61\154\165\x65"]) ? $wK : (isset($wK["\151\144"]) ? array("\166\141\x6c\x75\145" => array(0 => $wK)) : array());
        if (array_key_exists("\x76\141\154\x75\145", $wK)) {
            goto M6;
        }
        return array(0 => $wK);
        M6:
        $K7 = $wK["\166\141\x6c\x75\145"];
        $WW = array("\x69\144", "\144\151\x73\160\154\141\171\116\141\155\x65", "\167\145\142\125\162\x6c", "\x6c\141\x73\164\x4d\x6f\x64\x69\x66\x69\145\x64\104\141\164\x65\124\x69\x6d\145");
        $VP = array();
        foreach ($K7 as $cD => $Jq) {
            $c5 = array();
            foreach ($Jq as $E2 => $qF) {
                if (!in_array($E2, $WW)) {
                    goto pq;
                }
                if ($E2 === "\x64\x69\163\160\x6c\x61\x79\x4e\141\x6d\145") {
                    goto UQ;
                }
                $c5[$E2] = $qF;
                goto WJ;
                UQ:
                $c5["\156\x61\155\x65"] = $qF;
                WJ:
                pq:
                VN:
            }
            LQ:
            array_push($VP, $c5);
            DI:
        }
        rR:
        return $VP;
    }
    public static function mo_sps_process_drives($wK)
    {
        if (isset($wK["\x76\x61\154\165\145"])) {
            goto sL;
        }
        return array();
        sL:
        $K7 = $wK["\166\141\154\x75\145"];
        $WW = array("\x69\x64", "\156\x61\x6d\x65", "\167\145\x62\125\162\154", "\x64\x72\x69\166\145\x54\x79\160\x65", "\154\141\x73\164\x4d\x6f\x64\x69\146\151\x65\x64\104\141\x74\145\124\151\155\x65", "\x71\165\x6f\x74\x61");
        $VP = array();
        foreach ($K7 as $cD => $cV) {
            $c5 = array();
            foreach ($cV as $E2 => $qF) {
                if (!in_array($E2, $WW)) {
                    goto HE;
                }
                $c5[$E2] = $qF;
                HE:
                m5:
            }
            It:
            if (!($cV["\144\162\151\166\x65\x54\171\x70\x65"] == "\160\145\162\163\157\x6e\x61\x6c")) {
                goto Ng;
            }
            $c5["\156\x61\155\145"] = "\120\145\162\x73\157\x6e\x61\154\x20\117\x6e\x65\x64\162\151\x76\145";
            Ng:
            array_push($VP, $c5);
            mU:
        }
        wb:
        return $VP;
    }
    public static function mo_sps_process_lists($wK)
    {
        if (isset($wK["\x76\x61\154\x75\145"])) {
            goto Wb;
        }
        return array();
        Wb:
        $K7 = $wK["\166\141\x6c\165\x65"];
        $WW = array("\151\144", "\156\x61\155\145", "\x77\145\142\x55\x72\x6c", "\x6c\x69\163\x74", "\161\x75\157\164\141");
        $VP = array();
        foreach ($K7 as $cD => $cV) {
            $c5 = array();
            foreach ($cV as $E2 => $qF) {
                if (!in_array($E2, $WW)) {
                    goto hA;
                }
                if ($E2 == "\x6c\x69\163\164") {
                    goto Dl;
                }
                $c5[$E2] = $qF;
                goto aG;
                Dl:
                $c5[$E2] = $qF["\x74\145\155\160\154\141\164\x65"];
                aG:
                hA:
                p6:
            }
            EH:
            if (!($c5["\x6c\151\x73\x74"] == "\147\x65\x6e\x65\162\151\143\x4c\x69\163\x74")) {
                goto q1;
            }
            array_push($VP, $c5);
            q1:
            tV:
        }
        A_:
        return $VP;
    }
    public static function mo_sps_process_docs($wK)
    {
        if (isset($wK["\x76\141\154\x75\145"])) {
            goto bH;
        }
        return array();
        bH:
        $K7 = $wK["\x76\141\154\165\145"];
        $WW = array("\x69\x64", "\x6e\141\155\x65", "\154\141\163\x74\x4d\157\x64\151\x66\x69\145\144\x44\141\x74\145\124\151\155\x65", "\154\141\163\x74\x4d\x6f\x64\x69\146\151\145\144\102\171", "\x73\x69\x7a\x65", "\146\157\x6c\x64\x65\x72", "\100\155\x69\143\x72\x6f\x73\x6f\146\x74\56\147\162\x61\x70\x68\56\x64\x6f\167\x6e\x6c\x6f\x61\144\125\x72\154", "\x40\x63\x6f\156\164\x65\156\x74\x2e\144\x6f\167\156\154\157\x61\144\125\162\x6c", "\167\x65\142\x55\162\x6c", "\x70\x61\162\145\156\x74\x52\x65\146\145\x72\x65\156\143\145");
        $VP = array();
        foreach ($K7 as $cD => $Jq) {
            $c5 = array();
            foreach ($Jq as $E2 => $qF) {
                if (!in_array($E2, $WW)) {
                    goto UI;
                }
                if ($E2 === "\x6c\x61\x73\x74\115\157\144\151\146\x69\x65\144\x42\171") {
                    goto OE;
                }
                if ($E2 === "\x40\155\x69\x63\x72\x6f\x73\x6f\146\164\x2e\147\x72\x61\x70\150\x2e\x64\157\x77\x6e\x6c\157\141\x64\x55\162\x6c" || $E2 === "\100\x63\157\156\x74\x65\x6e\164\56\x64\157\167\156\x6c\x6f\141\144\125\162\x6c") {
                    goto Wq;
                }
                $c5[$E2] = $qF;
                goto XK;
                OE:
                $c5[$E2] = $qF["\x75\x73\145\x72"]["\x64\151\163\x70\x6c\x61\x79\x4e\x61\155\x65"];
                goto XK;
                Wq:
                $c5["\x64\157\x77\x6e\154\157\141\x64\x5f\165\162\x6c"] = $qF;
                XK:
                UI:
                mm:
            }
            IH:
            array_push($VP, $c5);
            GL:
        }
        YP:
        return $VP;
    }
    public static function mo_sps_process_list_items($wK, $nP)
    {
        if (isset($wK["\x69\x74\x65\x6d\x73"])) {
            goto F5;
        }
        return array();
        F5:
        $K7 = $wK["\151\164\x65\x6d\163"];
        $TT = $wK["\x63\x6f\154\165\x6d\156\x73"];
        $WW = array("\151\144", "\146\x69\x65\x6c\144\163", "\x6c\x61\163\x74\115\157\144\x69\146\151\145\144\104\141\164\145\x54\151\155\x65", "\x6c\x61\x73\x74\115\x6f\x64\151\x66\x69\145\144\x42\171");
        $l5 = array("\x64\151\x73\160\x6c\141\x79\116\141\155\x65", "\156\x61\155\x65");
        $VP = array();
        $ua = array();
        foreach ($K7 as $cD => $Jq) {
            $c5 = array();
            foreach ($Jq as $E2 => $qF) {
                if ($nP != '') {
                    goto PT;
                }
                if (!in_array($E2, $WW)) {
                    goto tt;
                }
                if ($E2 === "\x6c\141\x73\x74\115\157\x64\x69\x66\x69\145\x64\x42\171") {
                    goto QG;
                }
                if ($E2 === "\154\x61\x73\x74\x4d\157\144\151\x66\x69\x65\144\104\x61\x74\145\124\x69\155\x65") {
                    goto PI;
                }
                if ($E2 === "\x66\x69\x65\x6c\144\x73") {
                    goto Io;
                }
                if ($E2 = "\151\144") {
                    goto rA;
                }
                goto Mj;
                QG:
                $c5[$E2] = $qF["\165\x73\145\162"]["\144\151\x73\x70\154\141\x79\x4e\x61\155\x65"];
                goto Mj;
                PI:
                $c5["\x6c\x61\x73\164\x4d\x6f\144\151\x66\x69\x65\144\104\x61\x74\x65\124\x69\x6d\x65"] = $qF;
                goto Mj;
                Io:
                $c5["\x54\x69\164\154\145"] = isset($qF["\124\151\x74\x6c\145"]) ? $qF["\x54\151\164\x6c\x65"] : "\x4e\x41";
                goto Mj;
                rA:
                $c5["\151\x64"] = $qF;
                Mj:
                tt:
                goto b8;
                PT:
                if (!($E2 === "\146\x69\x65\x6c\x64\x73")) {
                    goto dJ;
                }
                foreach ($nP as $c_ => $Um) {
                    if (isset($qF[$c_]) && is_array($qF[$c_]) && isset($qF[$c_]["\x55\x72\154"])) {
                        goto ow;
                    }
                    if (isset($qF[$c_])) {
                        goto Ja;
                    }
                    if (isset($qF[$c_ . "\114\157\157\x6b\165\160\x49\x64"])) {
                        goto g3;
                    }
                    if ($qF[$c_] == '') {
                        goto xN;
                    }
                    goto zM;
                    ow:
                    $c5[$Um] = array("\x75\162\x6c" => $qF[$c_]["\x55\x72\x6c"], "\164\x72\165\145" => 1);
                    goto zM;
                    Ja:
                    $c5[$Um] = $qF[$c_];
                    goto zM;
                    g3:
                    $c5[$Um] = $qF[$c_ . "\114\157\157\x6b\165\x70\111\144"];
                    goto zM;
                    xN:
                    $c5[$Um] = "\x2d";
                    zM:
                    v9:
                }
                yV:
                dJ:
                b8:
                Bb:
            }
            D2:
            array_push($VP, $c5);
            dr:
        }
        QU:
        foreach ($TT as $cD => $Jq) {
            $c5 = array();
            foreach ($Jq as $E2 => $qF) {
                if (!in_array($E2, $l5)) {
                    goto o_;
                }
                if ($E2 === "\x64\x69\x73\x70\154\x61\x79\x4e\141\155\145") {
                    goto MI;
                }
                if ($E2 === "\x6e\141\x6d\x65") {
                    goto iL;
                }
                goto ky;
                MI:
                $c5[$E2] = $qF;
                goto ky;
                iL:
                $c5[$E2] = $qF;
                ky:
                o_:
                BV:
            }
            Yq:
            array_push($ua, $c5);
            Wr:
        }
        PD:
        return array($VP, $ua);
    }
    public static function mo_sps_process_thumnails($wK, $aG = "\x73\155\141\154\x6c")
    {
        if (isset($wK["\166\x61\x6c\165\x65"])) {
            goto Kr;
        }
        return '';
        Kr:
        $K7 = $wK["\x76\x61\154\165\145"];
        $VP = '';
        foreach ($K7 as $FI) {
            $VP = $FI[$aG]["\165\x72\x6c"];
            hn:
        }
        yX:
        return $VP;
    }
    public static function mo_sps_process_sharepoint_news_items($wK)
    {
        if (isset($wK["\x64"])) {
            goto bP;
        }
        return array();
        bP:
        $K7 = $wK["\x64"]["\162\145\163\x75\x6c\x74\x73"];
        array_shift($K7);
        $WW = array("\107\125\x49\104", "\x54\151\x74\x6c\145", "\x44\145\x73\x63\x72\x69\160\x74\x69\x6f\156", "\x42\x61\x6e\x6e\145\162\111\x6d\141\147\145\x55\162\154", "\x4f\x44\x61\164\x61\x5f\x5f\x4f\x72\x69\x67\x69\156\x61\154\123\x6f\165\162\x63\145\125\162\x6c");
        $VP = array();
        foreach ($K7 as $cD => $XS) {
            $c5 = array();
            foreach ($XS as $E2 => $qF) {
                if (!in_array($E2, $WW)) {
                    goto FZ;
                }
                if ($E2 == "\x42\141\156\156\145\162\111\155\x61\147\145\125\162\154") {
                    goto Rf;
                }
                $c5[$E2] = $qF;
                goto B1;
                Rf:
                $c5[$E2] = $qF["\125\x72\154"];
                B1:
                FZ:
                V5:
            }
            Pi:
            array_push($VP, $c5);
            wc:
        }
        nc:
        return $VP;
    }
    public static function mo_sps_process_sharepoint_event_items($wK)
    {
        if (isset($wK["\144"])) {
            goto ia;
        }
        return array();
        ia:
        $K7 = $wK["\144"]["\x72\145\163\165\154\164\163"];
        $WW = array("\107\x55\x49\104", "\x54\151\164\x6c\x65", "\104\145\163\x63\x72\x69\160\x74\151\157\x6e", "\102\x61\x6e\156\145\162\111\155\141\147\145\x55\x72\x6c", "\x66\101\154\154\104\141\171\105\166\x65\156\x74", "\103\141\164\x65\x67\157\162\x79", "\x45\166\145\156\x74\104\141\x74\x65", "\105\156\144\x44\x61\164\x65", "\114\157\x63\141\164\151\x6f\x6e");
        $VP = array();
        $fL = array();
        foreach ($K7 as $cD => $XS) {
            $c5 = array();
            foreach ($XS as $E2 => $qF) {
                if (!in_array($E2, $WW)) {
                    goto rh;
                }
                $c5[$E2] = $qF;
                if (!($E2 === "\105\166\x65\x6e\164\x44\x61\x74\145")) {
                    goto n6;
                }
                array_push($fL, $c5["\x45\x76\x65\156\x74\104\x61\x74\145"]);
                n6:
                rh:
                OY:
            }
            ef:
            array_push($VP, $c5);
            EJ:
        }
        Lr:
        array_multisort($fL, SORT_ASC, $VP);
        return $VP;
    }
    public static function mo_sps_filter_documents_checking_permissions($Ba)
    {
        $wK = array();
        foreach ($Ba as $kH) {
            $sO = self::mo_sps_check_for_the_permissions($kH["\x69\144"], "\166\151\x65\x77");
            if (!$sO) {
                goto Ul;
            }
            array_push($wK, $kH);
            Ul:
            MG:
        }
        aC:
        return $wK;
    }
    public static function mo_sps_check_for_the_permissions($Sc, $KB)
    {
        $Ug = self::mo_sps_get_documents_permission($Sc);
        $CB = wpWrapper::mo_sps_get_user_roles_and_emails();
        $Ug = $Ug && isset($Ug[$KB]) ? $Ug[$KB] : array();
        $rv = isset($CB["\143\165\162\x72\x65\156\164\137\165\163\145\x72\137\x72\x6f\x6c\x65\x73"]) ? $CB["\x63\x75\162\x72\145\x6e\x74\137\x75\163\145\162\x5f\162\157\154\145\163"] : array();
        $pX = isset($CB["\143\165\x72\162\145\x6e\x74\137\x75\x73\145\x72\x5f\145\155\141\x69\154"]) ? $CB["\143\x75\x72\162\145\156\x74\x5f\165\x73\x65\x72\x5f\145\155\141\x69\154"] : '';
        if (!is_user_logged_in()) {
            goto Qk;
        }
        return true;
        Qk:
        if (!(in_array("\141\144\x6d\x69\x6e\151\163\164\x72\x61\164\157\162", $rv) || in_array("\x41\144\155\151\156\151\x73\x74\x72\x61\164\x6f\162", $rv))) {
            goto io;
        }
        return true;
        io:
        foreach ($Ug as $W0) {
            if (!($W0 == "\141\x6e\x6f\x6e\171\155\157\165\x73")) {
                goto c1;
            }
            return true;
            c1:
            foreach ($rv as $BW) {
                if (!($BW == $W0)) {
                    goto pz;
                }
                return true;
                pz:
                jp:
            }
            Bs:
            if (!($pX == $W0)) {
                goto Ge;
            }
            return true;
            Ge:
            LF:
        }
        nR:
        return false;
    }
    public static function mo_sps_get_documents_permission($Sc)
    {
        $Ug = wpWrapper::mo_sps_get_option(pluginConstants::FOLDER_FILES_PERMISSIONS);
        $Ug = $Ug ? json_decode($Ug, true) : array();
        $pp = isset($Ug[$Sc]) ? $Ug[$Sc] : array();
        if (!empty($pp)) {
            goto Bu;
        }
        $pp = self::mo_sps_get_documents_inherited_permissions($Sc);
        return $pp;
        Bu:
        if (!is_array($pp)) {
            goto Xb;
        }
        foreach ($pp as $cD => $V7) {
            if (!(is_array($V7) && count(array_filter($V7)) === 0)) {
                goto kC;
            }
            unset($pp[$cD]);
            kC:
            cV:
        }
        KO:
        Xb:
        return $pp;
    }
    public static function mo_sps_get_documents_inherited_permissions($Sc)
    {
        $Ug = wpWrapper::mo_sps_get_option(pluginConstants::FOLDER_FILES_PERMISSIONS);
        $Ug = $Ug ? json_decode($Ug, true) : array();
        $Xy = self::mo_sps_post_exists_already($Sc);
        if ($Xy) {
            goto Uy;
        }
        $Mi = term_exists(strtolower($Sc));
        if (!is_array($Mi)) {
            goto Ns;
        }
        $Mi = !empty($Mi) && isset($Mi["\x74\x65\162\155\137\151\144"]) ? get_term($Mi["\164\145\x72\155\137\x69\144"]) : false;
        goto Tc;
        Ns:
        $Mi = get_term($Mi);
        Tc:
        goto on;
        Uy:
        $qS = wp_get_post_terms($Xy, "\x6d\x6f\145\x73\x68\x70\55\143\x61\x74\145\x67\x6f\162\171");
        $Mi = isset($qS[0]) ? $qS[0] : false;
        on:
        q5:
        if (!$Mi) {
            goto KT;
        }
        if (!$Mi->term_id) {
            goto HU;
        }
        $zK = get_term_meta($Mi->term_id, "\151\x64");
        $zK = isset($zK[0]) ? $zK[0] : '';
        if (!($Ug && isset($Ug[$zK]))) {
            goto oy;
        }
        return $Ug[$zK];
        oy:
        HU:
        $Mi = $Mi->parent;
        if (!($Mi != 0)) {
            goto q2;
        }
        $Mi = get_term($Mi);
        $Mi = $Mi && $Mi->term_id ? get_term($Mi->term_id) : false;
        q2:
        goto q5;
        KT:
        return '';
    }
    public static function mo_sps_insert_in_media_library($dT, $ok, $mJ, $j9, $D0, $LG, $cq, $v1, $C2)
    {
        $TQ = wp_insert_post(array("\x67\165\151\144" => $dT . "\x2f" . $ok, "\160\157\x73\164\137\x74\x69\x74\x6c\x65" => $mJ, "\x70\157\163\x74\137\163\x74\x61\164\165\x73" => "\x69\156\150\145\x72\151\164", "\x70\x6f\x73\164\137\155\x69\155\x65\137\164\171\160\x65" => $j9[strtolower($D0)], "\155\145\x74\x61\137\x69\156\160\x75\x74" => $C2, "\160\157\163\x74\x5f\164\x79\x70\145" => "\163\150\x70\137\x61\164\x74\x61\x63\x68\x6d\145\x6e\164"), $cq);
        update_post_meta($TQ, "\x5f\x77\160\137\141\x74\164\x61\143\x68\155\x65\156\164\x5f\x66\x69\154\145\137\165\x72\154\x73", $LG);
        return $TQ;
    }
    public static function mo_sps_post_exists_already($Ox)
    {
        $JH = "\x6d\x6f\137\x73\x70\x73\x5f\x66\151\x6c\x65\x5f\x69\144";
        $rZ = array("\x70\x6f\x73\164\137\x74\x79\x70\x65" => "\x73\x68\x70\x5f\141\164\x74\x61\143\x68\x6d\x65\x6e\x74", "\x6d\145\x74\x61\137\153\x65\171" => $JH, "\155\145\x74\x61\x5f\166\141\x6c\165\145" => $Ox, "\x70\x6f\x73\x74\x5f\x73\x74\x61\164\x75\163" => "\151\156\150\145\162\x69\164", "\x70\157\x73\x74\x73\137\x70\x65\162\137\x70\141\x67\145" => -1);
        $pF = get_posts($rZ);
        if (!empty($pF)) {
            goto qd;
        }
        return false;
        goto HJ;
        qd:
        $Xy = $pF[0]->ID;
        return $Xy;
        HJ:
    }
}
