<?php
/**
 * ------------------------ 
 *  版权所有  www.tecmz.com
 *  商业版本请购买正版授权使用
 * ------------------------
*/ namespace ModStart\Misc\Html; use Exception; use HTMLPurifier; use HTMLPurifier_Config; use Illuminate\Contracts\Config\Repository; use Illuminate\Filesystem\Filesystem; class Purifier { protected $files; protected $config; protected $purifier; public function __construct(Filesystem $jByvU, Repository $b1rpR) { goto AFR5_; atmiy: $this->config = $b1rpR; goto gZ1m5; gZ1m5: $this->setUp(); goto GMglg; AFR5_: $this->files = $jByvU; goto atmiy; GMglg: } public static function cleanHtml($OrPO_, $b1rpR = null) { goto oTHsz; oTHsz: static $v16VC = null; goto MqdcF; MqdcF: if (null === $v16VC) { goto T56vd; T56vd: $HiDyY = app(); goto GKUv5; W7HtK: $v16VC = new Purifier($HiDyY['files'], new \Illuminate\Config\Repository($T4eL4)); goto OOM47; GKUv5: $T4eL4 = (include __DIR__ . '/config.php'); goto W7HtK; OOM47: } goto Z3vuK; Z3vuK: return $v16VC->clean($OrPO_, $b1rpR); goto agmUG; agmUG: } private function setUp() { goto RHgrw; cUFUx: $this->purifier = new HTMLPurifier($this->configure($b1rpR)); goto D7OVN; M1jaN: if ($eWbUs = $this->config->get('settings.custom_definition')) { $this->addCustomDefinition($eWbUs, $b1rpR); } goto C_Fsc; RHgrw: $this->checkCacheDirectory(); goto eZlq1; eZlq1: $b1rpR = HTMLPurifier_Config::createDefault(); goto WW_VT; WW_VT: if (!$this->config->get('finalize')) { $b1rpR->autoFinalize = false; } goto wRzUQ; IQGH0: if ($zUM3O = $this->config->get('settings.custom_attributes')) { if ($W1blM = $b1rpR->maybeGetRawHTMLDefinition()) { $this->addCustomAttributes($zUM3O, $W1blM); } } goto cUFUx; C_Fsc: if ($JdS6Z = $this->config->get('settings.custom_elements')) { if ($W1blM = $b1rpR->maybeGetRawHTMLDefinition()) { $this->addCustomElements($JdS6Z, $W1blM); } } goto IQGH0; wRzUQ: $b1rpR->loadArray($this->getConfig()); goto M1jaN; D7OVN: } private function addCustomDefinition(array $eWbUs, $WB8Bx = null) { goto Mp7vi; B7Jl5: $WB8Bx->set('HTML.DefinitionID', $eWbUs['id']); goto eLr1Y; LMxwx: if (!isset($eWbUs['debug']) || $eWbUs['debug']) { $WB8Bx->set('Cache.DefinitionImpl', null); } goto Bictf; SFhCz: return $WB8Bx; goto ZsGlV; Mp7vi: if (!$WB8Bx) { $WB8Bx = HTMLPurifier_Config::createDefault(); $WB8Bx->loadArray($this->getConfig()); } goto B7Jl5; eLr1Y: $WB8Bx->set('HTML.DefinitionRev', $eWbUs['rev']); goto LMxwx; Bictf: if ($W1blM = $WB8Bx->maybeGetRawHTMLDefinition()) { if (!empty($eWbUs['attributes'])) { $this->addCustomAttributes($eWbUs['attributes'], $W1blM); } if (!empty($eWbUs['elements'])) { $this->addCustomElements($eWbUs['elements'], $W1blM); } } goto SFhCz; ZsGlV: } private function addCustomAttributes(array $zUM3O, $ai6p0) { foreach ($zUM3O as $clllT) { goto nZF9x; LlpFk: $PC2MA = $MHPwR ? $clllT[1] . '*' : $clllT[1]; goto Ie7JN; nZF9x: $MHPwR = !empty($clllT[3]) ? true : false; goto HSfiA; tKBNz: $ai6p0->addAttribute($qRrJt, $PC2MA, $UR_bP); goto mHckL; Ie7JN: $UR_bP = $clllT[2]; goto tKBNz; HSfiA: $qRrJt = $clllT[0]; goto LlpFk; mHckL: } return $ai6p0; } private function addCustomElements(array $JdS6Z, $ai6p0) { foreach ($JdS6Z as $wi2ea) { goto FFJTx; FFJTx: $rPkIY = $wi2ea[0]; goto BJe0D; esbiQ: $N_oEK = $wi2ea[2]; goto hS6dn; BJe0D: $Gda70 = $wi2ea[1]; goto esbiQ; rxfH2: if (!empty($zUM3O)) { $ai6p0->addElement($rPkIY, $Gda70, $N_oEK, $CgVmD, $zUM3O); } else { $ai6p0->addElement($rPkIY, $Gda70, $N_oEK, $CgVmD); } goto Vv6M5; Hnj_w: $zUM3O = isset($wi2ea[4]) ? $wi2ea[4] : null; goto rxfH2; hS6dn: $CgVmD = $wi2ea[3]; goto Hnj_w; Vv6M5: } } private function checkCacheDirectory() { $CxoXL = $this->config->get('cachePath'); if ($CxoXL) { if (!$this->files->isDirectory($CxoXL)) { $this->files->makeDirectory($CxoXL, $this->config->get('cacheFileMode', 493)); } } } protected function configure(HTMLPurifier_Config $b1rpR) { return HTMLPurifier_Config::inherit($b1rpR); } protected function getConfig($b1rpR = null) { goto x1HUB; VGCSQ: if (!is_array($b1rpR)) { $b1rpR = array(); } goto rCVOp; rCVOp: $b1rpR = $s_fYY + $b1rpR; goto hDjx1; juA5l: $s_fYY['Core.Encoding'] = $this->config->get('encoding'); goto mcWmF; R3ezP: $s_fYY['Cache.SerializerPermissions'] = $this->config->get('cacheFileMode', 493); goto KUEsl; hDjx1: return $b1rpR; goto Lfnkm; x1HUB: $s_fYY = array(); goto juA5l; mcWmF: $s_fYY['Cache.SerializerPath'] = $this->config->get('cachePath'); goto R3ezP; KUEsl: if (!$b1rpR) { $b1rpR = $this->config->get('settings.default'); } elseif (is_string($b1rpR)) { $b1rpR = $this->config->get('settings.' . $b1rpR); } goto VGCSQ; Lfnkm: } public function clean($OrPO_, $b1rpR = null) { if (is_array($OrPO_)) { return array_map(function ($El_MH) use($b1rpR) { return $this->clean($El_MH, $b1rpR); }, $OrPO_); } return $this->purifier->purify($OrPO_, $this->getConfig($b1rpR)); } public function getInstance() { return $this->purifier; } }