<?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 $tBbJh, Repository $j3fMq) { goto BW43X; nPKCD: $this->config = $j3fMq; goto LSoUx; LSoUx: $this->setUp(); goto SYf4k; BW43X: $this->files = $tBbJh; goto nPKCD; SYf4k: } public static function cleanHtml($oB9aK, $j3fMq = null) { goto INneu; AIYLK: if (null === $zVV30) { goto ak8g0; ak8g0: $KmeI3 = app(); goto XXNzZ; kVAoZ: $zVV30 = new Purifier($KmeI3['files'], new \Illuminate\Config\Repository($PDyR9)); goto PRpch; XXNzZ: $PDyR9 = (include __DIR__ . '/config.php'); goto kVAoZ; PRpch: } goto lmbdX; INneu: static $zVV30 = null; goto AIYLK; lmbdX: return $zVV30->clean($oB9aK, $j3fMq); goto HKp3a; HKp3a: } private function setUp() { goto TOH60; n3iF_: if ($O9cSN = $this->config->get('settings.custom_attributes')) { if ($qHnvo = $j3fMq->maybeGetRawHTMLDefinition()) { $this->addCustomAttributes($O9cSN, $qHnvo); } } goto PMWMP; PMWMP: $this->purifier = new HTMLPurifier($this->configure($j3fMq)); goto yNvfv; S_gUd: $j3fMq = HTMLPurifier_Config::createDefault(); goto HjQ7N; TOH60: $this->checkCacheDirectory(); goto S_gUd; Are0a: if ($oPkz0 = $this->config->get('settings.custom_elements')) { if ($qHnvo = $j3fMq->maybeGetRawHTMLDefinition()) { $this->addCustomElements($oPkz0, $qHnvo); } } goto n3iF_; oqQXz: $j3fMq->loadArray($this->getConfig()); goto nToqV; HjQ7N: if (!$this->config->get('finalize')) { $j3fMq->autoFinalize = false; } goto oqQXz; nToqV: if ($YrAWQ = $this->config->get('settings.custom_definition')) { $this->addCustomDefinition($YrAWQ, $j3fMq); } goto Are0a; yNvfv: } private function addCustomDefinition(array $YrAWQ, $mKdNm = null) { goto YI1yR; YAqbL: $mKdNm->set('HTML.DefinitionID', $YrAWQ['id']); goto J_hJS; J_hJS: $mKdNm->set('HTML.DefinitionRev', $YrAWQ['rev']); goto XwVUe; XwVUe: if (!isset($YrAWQ['debug']) || $YrAWQ['debug']) { $mKdNm->set('Cache.DefinitionImpl', null); } goto OSruH; YI1yR: if (!$mKdNm) { $mKdNm = HTMLPurifier_Config::createDefault(); $mKdNm->loadArray($this->getConfig()); } goto YAqbL; bn0BN: return $mKdNm; goto MBwqz; OSruH: if ($qHnvo = $mKdNm->maybeGetRawHTMLDefinition()) { if (!empty($YrAWQ['attributes'])) { $this->addCustomAttributes($YrAWQ['attributes'], $qHnvo); } if (!empty($YrAWQ['elements'])) { $this->addCustomElements($YrAWQ['elements'], $qHnvo); } } goto bn0BN; MBwqz: } private function addCustomAttributes(array $O9cSN, $ppOpT) { foreach ($O9cSN as $Ub1Wf) { goto ePUy0; iIa64: $RHkRF = $bVFhU ? $Ub1Wf[1] . '*' : $Ub1Wf[1]; goto Ol2n6; ePUy0: $bVFhU = !empty($Ub1Wf[3]) ? true : false; goto omwrT; Ol2n6: $w7SZ1 = $Ub1Wf[2]; goto JsDs6; JsDs6: $ppOpT->addAttribute($KDHqS, $RHkRF, $w7SZ1); goto E1cBu; omwrT: $KDHqS = $Ub1Wf[0]; goto iIa64; E1cBu: } return $ppOpT; } private function addCustomElements(array $oPkz0, $ppOpT) { foreach ($oPkz0 as $l05Yf) { goto UWBW3; OuaA0: $CZY4D = $l05Yf[2]; goto bjQBL; bjQBL: $tAPuO = $l05Yf[3]; goto aoTKN; aoTKN: $O9cSN = isset($l05Yf[4]) ? $l05Yf[4] : null; goto NKCec; NKCec: if (!empty($O9cSN)) { $ppOpT->addElement($f0dxO, $qfDUI, $CZY4D, $tAPuO, $O9cSN); } else { $ppOpT->addElement($f0dxO, $qfDUI, $CZY4D, $tAPuO); } goto mJh3K; DXGMg: $qfDUI = $l05Yf[1]; goto OuaA0; UWBW3: $f0dxO = $l05Yf[0]; goto DXGMg; mJh3K: } } private function checkCacheDirectory() { $WMBJ1 = $this->config->get('cachePath'); if ($WMBJ1) { if (!$this->files->isDirectory($WMBJ1)) { $this->files->makeDirectory($WMBJ1, $this->config->get('cacheFileMode', 493)); } } } protected function configure(HTMLPurifier_Config $j3fMq) { return HTMLPurifier_Config::inherit($j3fMq); } protected function getConfig($j3fMq = null) { goto VWuI_; mmWgz: $NVcVG['Cache.SerializerPath'] = $this->config->get('cachePath'); goto T24H3; T24H3: $NVcVG['Cache.SerializerPermissions'] = $this->config->get('cacheFileMode', 493); goto tIQIy; VWuI_: $NVcVG = array(); goto XnvB6; CoiOC: return $j3fMq; goto RKjdj; HUs1I: $j3fMq = $NVcVG + $j3fMq; goto CoiOC; VkC97: if (!is_array($j3fMq)) { $j3fMq = array(); } goto HUs1I; tIQIy: if (!$j3fMq) { $j3fMq = $this->config->get('settings.default'); } elseif (is_string($j3fMq)) { $j3fMq = $this->config->get('settings.' . $j3fMq); } goto VkC97; XnvB6: $NVcVG['Core.Encoding'] = $this->config->get('encoding'); goto mmWgz; RKjdj: } public function clean($oB9aK, $j3fMq = null) { if (is_array($oB9aK)) { return array_map(function ($OV1o4) use($j3fMq) { return $this->clean($OV1o4, $j3fMq); }, $oB9aK); } return $this->purifier->purify($oB9aK, $this->getConfig($j3fMq)); } public function getInstance() { return $this->purifier; } }