<?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 $moNxb, Repository $KVWtm) { goto Jz9hf; Jz9hf: $this->files = $moNxb; goto PbKC0; texUL: $this->setUp(); goto V00wD; PbKC0: $this->config = $KVWtm; goto texUL; V00wD: } public static function cleanHtml($bwBhj, $KVWtm = null) { goto oTlRE; XIrad: return $Hpn2A->clean($bwBhj, $KVWtm); goto SvyEt; JVdtT: if (null === $Hpn2A) { goto EYH1k; Nz1w0: $pf7rw = (include __DIR__ . '/config.php'); goto njGuy; EYH1k: $pLAGQ = app(); goto Nz1w0; njGuy: $Hpn2A = new Purifier($pLAGQ['files'], new \Illuminate\Config\Repository($pf7rw)); goto ePkzo; ePkzo: } goto XIrad; oTlRE: static $Hpn2A = null; goto JVdtT; SvyEt: } private function setUp() { goto BE4KN; BE4KN: $this->checkCacheDirectory(); goto aFEhH; aFEhH: $KVWtm = HTMLPurifier_Config::createDefault(); goto otD7H; PPv6s: if ($PBnyf = $this->config->get('settings.custom_elements')) { if ($ym0sG = $KVWtm->maybeGetRawHTMLDefinition()) { $this->addCustomElements($PBnyf, $ym0sG); } } goto bYpBF; bYpBF: if ($JpPLg = $this->config->get('settings.custom_attributes')) { if ($ym0sG = $KVWtm->maybeGetRawHTMLDefinition()) { $this->addCustomAttributes($JpPLg, $ym0sG); } } goto kI5Ab; GTpHi: if ($kid_5 = $this->config->get('settings.custom_definition')) { $this->addCustomDefinition($kid_5, $KVWtm); } goto PPv6s; otD7H: if (!$this->config->get('finalize')) { $KVWtm->autoFinalize = false; } goto vJzYU; vJzYU: $KVWtm->loadArray($this->getConfig()); goto GTpHi; kI5Ab: $this->purifier = new HTMLPurifier($this->configure($KVWtm)); goto nwRLV; nwRLV: } private function addCustomDefinition(array $kid_5, $Hrc99 = null) { goto Okadc; cHLtH: if (!isset($kid_5['debug']) || $kid_5['debug']) { $Hrc99->set('Cache.DefinitionImpl', null); } goto cdQ55; HGm6t: $Hrc99->set('HTML.DefinitionID', $kid_5['id']); goto M1eeX; M1eeX: $Hrc99->set('HTML.DefinitionRev', $kid_5['rev']); goto cHLtH; cdQ55: if ($ym0sG = $Hrc99->maybeGetRawHTMLDefinition()) { if (!empty($kid_5['attributes'])) { $this->addCustomAttributes($kid_5['attributes'], $ym0sG); } if (!empty($kid_5['elements'])) { $this->addCustomElements($kid_5['elements'], $ym0sG); } } goto RNOjE; Okadc: if (!$Hrc99) { $Hrc99 = HTMLPurifier_Config::createDefault(); $Hrc99->loadArray($this->getConfig()); } goto HGm6t; RNOjE: return $Hrc99; goto tcIvT; tcIvT: } private function addCustomAttributes(array $JpPLg, $klMd5) { foreach ($JpPLg as $yPCY4) { goto WyIvN; WyIvN: $B_kv4 = !empty($yPCY4[3]) ? true : false; goto pXxPP; W6Eg0: $klMd5->addAttribute($c3lep, $Zb1vD, $ViAGW); goto s8GXQ; fyRtk: $ViAGW = $yPCY4[2]; goto W6Eg0; BWkWC: $Zb1vD = $B_kv4 ? $yPCY4[1] . '*' : $yPCY4[1]; goto fyRtk; pXxPP: $c3lep = $yPCY4[0]; goto BWkWC; s8GXQ: } return $klMd5; } private function addCustomElements(array $PBnyf, $klMd5) { foreach ($PBnyf as $NK5jE) { goto rvZqQ; WPpbG: $q2tN0 = $NK5jE[3]; goto jGtze; jGtze: $JpPLg = isset($NK5jE[4]) ? $NK5jE[4] : null; goto aPn8K; aPn8K: if (!empty($JpPLg)) { $klMd5->addElement($c6VKG, $jDX__, $IiH9T, $q2tN0, $JpPLg); } else { $klMd5->addElement($c6VKG, $jDX__, $IiH9T, $q2tN0); } goto c8bSV; OnoTi: $IiH9T = $NK5jE[2]; goto WPpbG; isNo1: $jDX__ = $NK5jE[1]; goto OnoTi; rvZqQ: $c6VKG = $NK5jE[0]; goto isNo1; c8bSV: } } private function checkCacheDirectory() { $j6SIQ = $this->config->get('cachePath'); if ($j6SIQ) { if (!$this->files->isDirectory($j6SIQ)) { $this->files->makeDirectory($j6SIQ, $this->config->get('cacheFileMode', 493)); } } } protected function configure(HTMLPurifier_Config $KVWtm) { return HTMLPurifier_Config::inherit($KVWtm); } protected function getConfig($KVWtm = null) { goto ac3FU; yrdiT: if (!is_array($KVWtm)) { $KVWtm = array(); } goto gEKkI; lh6Vu: if (!$KVWtm) { $KVWtm = $this->config->get('settings.default'); } elseif (is_string($KVWtm)) { $KVWtm = $this->config->get('settings.' . $KVWtm); } goto yrdiT; ac3FU: $HXQMF = array(); goto J23tn; ODxRA: $HXQMF['Cache.SerializerPath'] = $this->config->get('cachePath'); goto pRzgw; pRzgw: $HXQMF['Cache.SerializerPermissions'] = $this->config->get('cacheFileMode', 493); goto lh6Vu; gEKkI: $KVWtm = $HXQMF + $KVWtm; goto DP27H; J23tn: $HXQMF['Core.Encoding'] = $this->config->get('encoding'); goto ODxRA; DP27H: return $KVWtm; goto bRlTF; bRlTF: } public function clean($bwBhj, $KVWtm = null) { if (is_array($bwBhj)) { return array_map(function ($yFnpO) use($KVWtm) { return $this->clean($yFnpO, $KVWtm); }, $bwBhj); } return $this->purifier->purify($bwBhj, $this->getConfig($KVWtm)); } public function getInstance() { return $this->purifier; } }