<?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 $qwIog, Repository $jmXHX) { goto Kd1PK; Kd1PK: $this->files = $qwIog; goto QU4Rs; NIeTk: $this->setUp(); goto epYk0; QU4Rs: $this->config = $jmXHX; goto NIeTk; epYk0: } public static function cleanHtml($ryk33, $jmXHX = null) { goto r7Si3; H1jGW: return $Y0BWS->clean($ryk33, $jmXHX); goto IXwU1; r7Si3: static $Y0BWS = null; goto lorge; lorge: if (null === $Y0BWS) { goto zqpWZ; zqpWZ: $jOsVj = app(); goto vokye; vokye: $gzYlj = (include __DIR__ . '/config.php'); goto KasG1; KasG1: $Y0BWS = new Purifier($jOsVj['files'], new \Illuminate\Config\Repository($gzYlj)); goto UQNjI; UQNjI: } goto H1jGW; IXwU1: } private function setUp() { goto Q_Wiz; Q0kn6: $jmXHX->loadArray($this->getConfig()); goto tyn_f; eoqMD: if ($p9ymB = $this->config->get('settings.custom_elements')) { if ($VfgYk = $jmXHX->maybeGetRawHTMLDefinition()) { $this->addCustomElements($p9ymB, $VfgYk); } } goto hu2rS; iYLKn: $this->purifier = new HTMLPurifier($this->configure($jmXHX)); goto Upa4D; tyn_f: if ($nCpgs = $this->config->get('settings.custom_definition')) { $this->addCustomDefinition($nCpgs, $jmXHX); } goto eoqMD; Q_Wiz: $this->checkCacheDirectory(); goto TvBgK; hu2rS: if ($bMgU2 = $this->config->get('settings.custom_attributes')) { if ($VfgYk = $jmXHX->maybeGetRawHTMLDefinition()) { $this->addCustomAttributes($bMgU2, $VfgYk); } } goto iYLKn; UwUut: if (!$this->config->get('finalize')) { $jmXHX->autoFinalize = false; } goto Q0kn6; TvBgK: $jmXHX = HTMLPurifier_Config::createDefault(); goto UwUut; Upa4D: } private function addCustomDefinition(array $nCpgs, $H6OFQ = null) { goto E6EcW; E6EcW: if (!$H6OFQ) { $H6OFQ = HTMLPurifier_Config::createDefault(); $H6OFQ->loadArray($this->getConfig()); } goto pOSwA; JkU0L: return $H6OFQ; goto wh28w; XLwiu: if ($VfgYk = $H6OFQ->maybeGetRawHTMLDefinition()) { if (!empty($nCpgs['attributes'])) { $this->addCustomAttributes($nCpgs['attributes'], $VfgYk); } if (!empty($nCpgs['elements'])) { $this->addCustomElements($nCpgs['elements'], $VfgYk); } } goto JkU0L; KSzhW: $H6OFQ->set('HTML.DefinitionRev', $nCpgs['rev']); goto PbO36; pOSwA: $H6OFQ->set('HTML.DefinitionID', $nCpgs['id']); goto KSzhW; PbO36: if (!isset($nCpgs['debug']) || $nCpgs['debug']) { $H6OFQ->set('Cache.DefinitionImpl', null); } goto XLwiu; wh28w: } private function addCustomAttributes(array $bMgU2, $MiLEJ) { foreach ($bMgU2 as $Wo6Aw) { goto kQ667; kQ667: $Gz2LW = !empty($Wo6Aw[3]) ? true : false; goto X3QD_; X3QD_: $xdpPX = $Wo6Aw[0]; goto e3RQc; iXIcc: $MiLEJ->addAttribute($xdpPX, $DNgnd, $ZTVJP); goto c_p46; e3RQc: $DNgnd = $Gz2LW ? $Wo6Aw[1] . '*' : $Wo6Aw[1]; goto m8AzS; m8AzS: $ZTVJP = $Wo6Aw[2]; goto iXIcc; c_p46: } return $MiLEJ; } private function addCustomElements(array $p9ymB, $MiLEJ) { foreach ($p9ymB as $WfvRK) { goto L_wfv; QjC01: $bMgU2 = isset($WfvRK[4]) ? $WfvRK[4] : null; goto Qlg4_; IQHUI: $MUHIy = $WfvRK[3]; goto QjC01; cDvy2: $vxZWw = $WfvRK[2]; goto IQHUI; Qr3dw: $M8CpK = $WfvRK[1]; goto cDvy2; L_wfv: $L4owo = $WfvRK[0]; goto Qr3dw; Qlg4_: if (!empty($bMgU2)) { $MiLEJ->addElement($L4owo, $M8CpK, $vxZWw, $MUHIy, $bMgU2); } else { $MiLEJ->addElement($L4owo, $M8CpK, $vxZWw, $MUHIy); } goto QlL13; QlL13: } } private function checkCacheDirectory() { $xCKHa = $this->config->get('cachePath'); if ($xCKHa) { if (!$this->files->isDirectory($xCKHa)) { $this->files->makeDirectory($xCKHa, $this->config->get('cacheFileMode', 493)); } } } protected function configure(HTMLPurifier_Config $jmXHX) { return HTMLPurifier_Config::inherit($jmXHX); } protected function getConfig($jmXHX = null) { goto q1ZPs; NzC3o: $jmXHX = $loQPH + $jmXHX; goto oUttv; sn8QJ: if (!is_array($jmXHX)) { $jmXHX = array(); } goto NzC3o; BLlUO: $loQPH['Cache.SerializerPath'] = $this->config->get('cachePath'); goto jILQz; tlIwx: $loQPH['Core.Encoding'] = $this->config->get('encoding'); goto BLlUO; jILQz: $loQPH['Cache.SerializerPermissions'] = $this->config->get('cacheFileMode', 493); goto MMPNc; oUttv: return $jmXHX; goto dF3gr; q1ZPs: $loQPH = array(); goto tlIwx; MMPNc: if (!$jmXHX) { $jmXHX = $this->config->get('settings.default'); } elseif (is_string($jmXHX)) { $jmXHX = $this->config->get('settings.' . $jmXHX); } goto sn8QJ; dF3gr: } public function clean($ryk33, $jmXHX = null) { if (is_array($ryk33)) { return array_map(function ($ZpLX1) use($jmXHX) { return $this->clean($ZpLX1, $jmXHX); }, $ryk33); } return $this->purifier->purify($ryk33, $this->getConfig($jmXHX)); } public function getInstance() { return $this->purifier; } }