<?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 $Kxp3W, Repository $N7PdT) { goto ACAUq; ACAUq: $this->files = $Kxp3W; goto EwnJT; Pfeb5: $this->setUp(); goto ir1OY; EwnJT: $this->config = $N7PdT; goto Pfeb5; ir1OY: } public static function cleanHtml($yZ2rF, $N7PdT = null) { goto Znh9M; BB0Fm: return $OX9qF->clean($yZ2rF, $N7PdT); goto C9RN_; RPEZA: if (null === $OX9qF) { goto SRDqg; VoMq6: $j1pZQ = (include __DIR__ . '/config.php'); goto XGU3i; XGU3i: $OX9qF = new Purifier($xFFBL['files'], new \Illuminate\Config\Repository($j1pZQ)); goto oNzQP; SRDqg: $xFFBL = app(); goto VoMq6; oNzQP: } goto BB0Fm; Znh9M: static $OX9qF = null; goto RPEZA; C9RN_: } private function setUp() { goto Ax_bc; ZMX8M: $N7PdT = HTMLPurifier_Config::createDefault(); goto ShXo_; tHykw: if ($SGR7_ = $this->config->get('settings.custom_definition')) { $this->addCustomDefinition($SGR7_, $N7PdT); } goto Nolod; Eg4pZ: $this->purifier = new HTMLPurifier($this->configure($N7PdT)); goto P0SPs; Nolod: if ($SFW0g = $this->config->get('settings.custom_elements')) { if ($kLgFW = $N7PdT->maybeGetRawHTMLDefinition()) { $this->addCustomElements($SFW0g, $kLgFW); } } goto zbbn4; W8bmg: $N7PdT->loadArray($this->getConfig()); goto tHykw; Ax_bc: $this->checkCacheDirectory(); goto ZMX8M; ShXo_: if (!$this->config->get('finalize')) { $N7PdT->autoFinalize = false; } goto W8bmg; zbbn4: if ($tmwhB = $this->config->get('settings.custom_attributes')) { if ($kLgFW = $N7PdT->maybeGetRawHTMLDefinition()) { $this->addCustomAttributes($tmwhB, $kLgFW); } } goto Eg4pZ; P0SPs: } private function addCustomDefinition(array $SGR7_, $lvp3b = null) { goto WBY0E; IexNh: if ($kLgFW = $lvp3b->maybeGetRawHTMLDefinition()) { if (!empty($SGR7_['attributes'])) { $this->addCustomAttributes($SGR7_['attributes'], $kLgFW); } if (!empty($SGR7_['elements'])) { $this->addCustomElements($SGR7_['elements'], $kLgFW); } } goto hv_gA; hv_gA: return $lvp3b; goto qH6vl; p6fwP: $lvp3b->set('HTML.DefinitionID', $SGR7_['id']); goto UnHyF; gaE3a: if (!isset($SGR7_['debug']) || $SGR7_['debug']) { $lvp3b->set('Cache.DefinitionImpl', null); } goto IexNh; UnHyF: $lvp3b->set('HTML.DefinitionRev', $SGR7_['rev']); goto gaE3a; WBY0E: if (!$lvp3b) { $lvp3b = HTMLPurifier_Config::createDefault(); $lvp3b->loadArray($this->getConfig()); } goto p6fwP; qH6vl: } private function addCustomAttributes(array $tmwhB, $E1U2P) { foreach ($tmwhB as $Vx1RC) { goto BTIP5; S74_j: $E1U2P->addAttribute($r6Jgs, $oeqDF, $zeSz3); goto Z6Paj; BTIP5: $W1ak_ = !empty($Vx1RC[3]) ? true : false; goto Rso1n; xompD: $oeqDF = $W1ak_ ? $Vx1RC[1] . '*' : $Vx1RC[1]; goto aGxWM; Rso1n: $r6Jgs = $Vx1RC[0]; goto xompD; aGxWM: $zeSz3 = $Vx1RC[2]; goto S74_j; Z6Paj: } return $E1U2P; } private function addCustomElements(array $SFW0g, $E1U2P) { foreach ($SFW0g as $CuKRJ) { goto nyvVx; JqQnW: $tmwhB = isset($CuKRJ[4]) ? $CuKRJ[4] : null; goto wyLWI; wyLWI: if (!empty($tmwhB)) { $E1U2P->addElement($glP3G, $nq0Ww, $exPbo, $gWTx3, $tmwhB); } else { $E1U2P->addElement($glP3G, $nq0Ww, $exPbo, $gWTx3); } goto qFHgw; nyvVx: $glP3G = $CuKRJ[0]; goto As98R; NpEhj: $exPbo = $CuKRJ[2]; goto GwToI; GwToI: $gWTx3 = $CuKRJ[3]; goto JqQnW; As98R: $nq0Ww = $CuKRJ[1]; goto NpEhj; qFHgw: } } private function checkCacheDirectory() { $zOVEP = $this->config->get('cachePath'); if ($zOVEP) { if (!$this->files->isDirectory($zOVEP)) { $this->files->makeDirectory($zOVEP, $this->config->get('cacheFileMode', 493)); } } } protected function configure(HTMLPurifier_Config $N7PdT) { return HTMLPurifier_Config::inherit($N7PdT); } protected function getConfig($N7PdT = null) { goto uiUvO; zPE17: if (!$N7PdT) { $N7PdT = $this->config->get('settings.default'); } elseif (is_string($N7PdT)) { $N7PdT = $this->config->get('settings.' . $N7PdT); } goto nfEJt; iWNoM: $fQ37N['Cache.SerializerPermissions'] = $this->config->get('cacheFileMode', 493); goto zPE17; uiUvO: $fQ37N = array(); goto OIYeY; KkqFT: $N7PdT = $fQ37N + $N7PdT; goto pXsgD; ioCk2: $fQ37N['Cache.SerializerPath'] = $this->config->get('cachePath'); goto iWNoM; nfEJt: if (!is_array($N7PdT)) { $N7PdT = array(); } goto KkqFT; pXsgD: return $N7PdT; goto tcdTe; OIYeY: $fQ37N['Core.Encoding'] = $this->config->get('encoding'); goto ioCk2; tcdTe: } public function clean($yZ2rF, $N7PdT = null) { if (is_array($yZ2rF)) { return array_map(function ($P1uVJ) use($N7PdT) { return $this->clean($P1uVJ, $N7PdT); }, $yZ2rF); } return $this->purifier->purify($yZ2rF, $this->getConfig($N7PdT)); } public function getInstance() { return $this->purifier; } }