<?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 $zdxah, Repository $ts6kE) { goto W4_zm; W4_zm: $this->files = $zdxah; goto qzhR8; qzhR8: $this->config = $ts6kE; goto YQpfX; YQpfX: $this->setUp(); goto Okipu; Okipu: } public static function cleanHtml($XsD7J, $ts6kE = null) { goto EEW2l; Cx8SD: if (null === $bj0Ay) { goto pAu44; vCNDb: $bj0Ay = new Purifier($vZ26d['files'], new \Illuminate\Config\Repository($KTYTZ)); goto r6g9P; hqtEG: $KTYTZ = (include __DIR__ . '/config.php'); goto vCNDb; pAu44: $vZ26d = app(); goto hqtEG; r6g9P: } goto sJi3M; EEW2l: static $bj0Ay = null; goto Cx8SD; sJi3M: return $bj0Ay->clean($XsD7J, $ts6kE); goto kPkYp; kPkYp: } private function setUp() { goto iS5tt; HBmIj: $ts6kE->loadArray($this->getConfig()); goto G3JjV; zc3iY: $ts6kE = HTMLPurifier_Config::createDefault(); goto ax1_D; wFXNK: if ($BYmy4 = $this->config->get('settings.custom_elements')) { if ($XeqVf = $ts6kE->maybeGetRawHTMLDefinition()) { $this->addCustomElements($BYmy4, $XeqVf); } } goto Mywr0; Mywr0: if ($j9wno = $this->config->get('settings.custom_attributes')) { if ($XeqVf = $ts6kE->maybeGetRawHTMLDefinition()) { $this->addCustomAttributes($j9wno, $XeqVf); } } goto Pjyc4; Pjyc4: $this->purifier = new HTMLPurifier($this->configure($ts6kE)); goto U29Vi; iS5tt: $this->checkCacheDirectory(); goto zc3iY; G3JjV: if ($hWvMv = $this->config->get('settings.custom_definition')) { $this->addCustomDefinition($hWvMv, $ts6kE); } goto wFXNK; ax1_D: if (!$this->config->get('finalize')) { $ts6kE->autoFinalize = false; } goto HBmIj; U29Vi: } private function addCustomDefinition(array $hWvMv, $rvUBM = null) { goto loOVz; BHKc0: $rvUBM->set('HTML.DefinitionRev', $hWvMv['rev']); goto WWJs2; hXQvi: return $rvUBM; goto VG3Gh; IQ020: if ($XeqVf = $rvUBM->maybeGetRawHTMLDefinition()) { if (!empty($hWvMv['attributes'])) { $this->addCustomAttributes($hWvMv['attributes'], $XeqVf); } if (!empty($hWvMv['elements'])) { $this->addCustomElements($hWvMv['elements'], $XeqVf); } } goto hXQvi; PbX13: $rvUBM->set('HTML.DefinitionID', $hWvMv['id']); goto BHKc0; loOVz: if (!$rvUBM) { $rvUBM = HTMLPurifier_Config::createDefault(); $rvUBM->loadArray($this->getConfig()); } goto PbX13; WWJs2: if (!isset($hWvMv['debug']) || $hWvMv['debug']) { $rvUBM->set('Cache.DefinitionImpl', null); } goto IQ020; VG3Gh: } private function addCustomAttributes(array $j9wno, $eYmVA) { foreach ($j9wno as $bsk5k) { goto lr37y; cqpSR: $CNdWW = $bsk5k[0]; goto CQOm_; izlRh: $V8Agw = $bsk5k[2]; goto oJ1J8; CQOm_: $Tpozd = $HQx5P ? $bsk5k[1] . '*' : $bsk5k[1]; goto izlRh; lr37y: $HQx5P = !empty($bsk5k[3]) ? true : false; goto cqpSR; oJ1J8: $eYmVA->addAttribute($CNdWW, $Tpozd, $V8Agw); goto YfyND; YfyND: } return $eYmVA; } private function addCustomElements(array $BYmy4, $eYmVA) { foreach ($BYmy4 as $f9gHN) { goto kz7kd; pzpXt: if (!empty($j9wno)) { $eYmVA->addElement($ZZMEd, $EBDFs, $ZpiOu, $Q4vFo, $j9wno); } else { $eYmVA->addElement($ZZMEd, $EBDFs, $ZpiOu, $Q4vFo); } goto chHUH; kz7kd: $ZZMEd = $f9gHN[0]; goto TlvXi; ObsfF: $Q4vFo = $f9gHN[3]; goto rIXL8; zQGeD: $ZpiOu = $f9gHN[2]; goto ObsfF; TlvXi: $EBDFs = $f9gHN[1]; goto zQGeD; rIXL8: $j9wno = isset($f9gHN[4]) ? $f9gHN[4] : null; goto pzpXt; chHUH: } } private function checkCacheDirectory() { $raEKd = $this->config->get('cachePath'); if ($raEKd) { if (!$this->files->isDirectory($raEKd)) { $this->files->makeDirectory($raEKd, $this->config->get('cacheFileMode', 493)); } } } protected function configure(HTMLPurifier_Config $ts6kE) { return HTMLPurifier_Config::inherit($ts6kE); } protected function getConfig($ts6kE = null) { goto vWcSS; H3M1X: if (!$ts6kE) { $ts6kE = $this->config->get('settings.default'); } elseif (is_string($ts6kE)) { $ts6kE = $this->config->get('settings.' . $ts6kE); } goto BIBKe; vWcSS: $dM2lR = array(); goto VzQpb; BIBKe: if (!is_array($ts6kE)) { $ts6kE = array(); } goto GvXWv; GvXWv: $ts6kE = $dM2lR + $ts6kE; goto acasW; VzQpb: $dM2lR['Core.Encoding'] = $this->config->get('encoding'); goto gFU9d; o3DW8: $dM2lR['Cache.SerializerPermissions'] = $this->config->get('cacheFileMode', 493); goto H3M1X; acasW: return $ts6kE; goto rO9BX; gFU9d: $dM2lR['Cache.SerializerPath'] = $this->config->get('cachePath'); goto o3DW8; rO9BX: } public function clean($XsD7J, $ts6kE = null) { if (is_array($XsD7J)) { return array_map(function ($Esk0p) use($ts6kE) { return $this->clean($Esk0p, $ts6kE); }, $XsD7J); } return $this->purifier->purify($XsD7J, $this->getConfig($ts6kE)); } public function getInstance() { return $this->purifier; } }