<?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 $vQMyn, Repository $O348k) { goto T9vMS; fwlHS: $this->setUp(); goto i0lbn; T9vMS: $this->files = $vQMyn; goto BFwJU; BFwJU: $this->config = $O348k; goto fwlHS; i0lbn: } public static function cleanHtml($hRSwM, $O348k = null) { goto CWMvG; w32xA: return $URw5T->clean($hRSwM, $O348k); goto XYjar; wygAM: if (null === $URw5T) { goto tL7_A; fdYGS: $URw5T = new Purifier($P3svO['files'], new \Illuminate\Config\Repository($Q44fX)); goto zSKG8; tL7_A: $P3svO = app(); goto KHwYB; KHwYB: $Q44fX = (include __DIR__ . '/config.php'); goto fdYGS; zSKG8: } goto w32xA; CWMvG: static $URw5T = null; goto wygAM; XYjar: } private function setUp() { goto udEVy; hbtBt: if ($arT83 = $this->config->get('settings.custom_elements')) { if ($zNbod = $O348k->maybeGetRawHTMLDefinition()) { $this->addCustomElements($arT83, $zNbod); } } goto Qcagf; ZGRVF: if ($ZOYLH = $this->config->get('settings.custom_definition')) { $this->addCustomDefinition($ZOYLH, $O348k); } goto hbtBt; Qcagf: if ($kotD3 = $this->config->get('settings.custom_attributes')) { if ($zNbod = $O348k->maybeGetRawHTMLDefinition()) { $this->addCustomAttributes($kotD3, $zNbod); } } goto pff60; EJgCh: if (!$this->config->get('finalize')) { $O348k->autoFinalize = false; } goto INg0h; S8Hoi: $O348k = HTMLPurifier_Config::createDefault(); goto EJgCh; udEVy: $this->checkCacheDirectory(); goto S8Hoi; INg0h: $O348k->loadArray($this->getConfig()); goto ZGRVF; pff60: $this->purifier = new HTMLPurifier($this->configure($O348k)); goto MPwBM; MPwBM: } private function addCustomDefinition(array $ZOYLH, $H0p6r = null) { goto RLDwh; mc0dU: return $H0p6r; goto Y09fq; RLDwh: if (!$H0p6r) { $H0p6r = HTMLPurifier_Config::createDefault(); $H0p6r->loadArray($this->getConfig()); } goto eQPP6; IDoeU: $H0p6r->set('HTML.DefinitionRev', $ZOYLH['rev']); goto LowQE; eQPP6: $H0p6r->set('HTML.DefinitionID', $ZOYLH['id']); goto IDoeU; LowQE: if (!isset($ZOYLH['debug']) || $ZOYLH['debug']) { $H0p6r->set('Cache.DefinitionImpl', null); } goto EvQfU; EvQfU: if ($zNbod = $H0p6r->maybeGetRawHTMLDefinition()) { if (!empty($ZOYLH['attributes'])) { $this->addCustomAttributes($ZOYLH['attributes'], $zNbod); } if (!empty($ZOYLH['elements'])) { $this->addCustomElements($ZOYLH['elements'], $zNbod); } } goto mc0dU; Y09fq: } private function addCustomAttributes(array $kotD3, $Jty0u) { foreach ($kotD3 as $pj0gj) { goto BUSCs; qFDwu: $Jty0u->addAttribute($ceWFg, $Q7mBO, $WWla1); goto ouXzJ; BUSCs: $DLnmz = !empty($pj0gj[3]) ? true : false; goto nRJq3; ePXi5: $Q7mBO = $DLnmz ? $pj0gj[1] . '*' : $pj0gj[1]; goto u9YWC; nRJq3: $ceWFg = $pj0gj[0]; goto ePXi5; u9YWC: $WWla1 = $pj0gj[2]; goto qFDwu; ouXzJ: } return $Jty0u; } private function addCustomElements(array $arT83, $Jty0u) { foreach ($arT83 as $D5Q3D) { goto lQC5y; nJ_QH: $kotD3 = isset($D5Q3D[4]) ? $D5Q3D[4] : null; goto HGVld; mDhm1: $RvSj_ = $D5Q3D[1]; goto kQVRO; Vpvvi: $ZBnsx = $D5Q3D[3]; goto nJ_QH; HGVld: if (!empty($kotD3)) { $Jty0u->addElement($sQIr6, $RvSj_, $JsoAB, $ZBnsx, $kotD3); } else { $Jty0u->addElement($sQIr6, $RvSj_, $JsoAB, $ZBnsx); } goto F4H1y; kQVRO: $JsoAB = $D5Q3D[2]; goto Vpvvi; lQC5y: $sQIr6 = $D5Q3D[0]; goto mDhm1; F4H1y: } } private function checkCacheDirectory() { $OPl5q = $this->config->get('cachePath'); if ($OPl5q) { if (!$this->files->isDirectory($OPl5q)) { $this->files->makeDirectory($OPl5q, $this->config->get('cacheFileMode', 493)); } } } protected function configure(HTMLPurifier_Config $O348k) { return HTMLPurifier_Config::inherit($O348k); } protected function getConfig($O348k = null) { goto ji3rs; uURe_: if (!$O348k) { $O348k = $this->config->get('settings.default'); } elseif (is_string($O348k)) { $O348k = $this->config->get('settings.' . $O348k); } goto YQdVy; YQdVy: if (!is_array($O348k)) { $O348k = array(); } goto QwXws; G2gEF: $HfwDy['Core.Encoding'] = $this->config->get('encoding'); goto oWDik; ji3rs: $HfwDy = array(); goto G2gEF; QwXws: $O348k = $HfwDy + $O348k; goto DDyTc; oWDik: $HfwDy['Cache.SerializerPath'] = $this->config->get('cachePath'); goto srFIC; srFIC: $HfwDy['Cache.SerializerPermissions'] = $this->config->get('cacheFileMode', 493); goto uURe_; DDyTc: return $O348k; goto Bd4TT; Bd4TT: } public function clean($hRSwM, $O348k = null) { if (is_array($hRSwM)) { return array_map(function ($Xvngd) use($O348k) { return $this->clean($Xvngd, $O348k); }, $hRSwM); } return $this->purifier->purify($hRSwM, $this->getConfig($O348k)); } public function getInstance() { return $this->purifier; } }