<?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 $Nia5n, Repository $da426) { goto MG_3H; MG_3H: $this->files = $Nia5n; goto slgo8; Yx3pY: $this->setUp(); goto Vb5KF; slgo8: $this->config = $da426; goto Yx3pY; Vb5KF: } public static function cleanHtml($p92LY, $da426 = null) { goto Z7NFw; xW4Lp: if (null === $LmMYX) { goto R3Xca; AKwnX: $C5CnO = (include __DIR__ . '/config.php'); goto ZzFH7; R3Xca: $bk3gA = app(); goto AKwnX; ZzFH7: $LmMYX = new Purifier($bk3gA['files'], new \Illuminate\Config\Repository($C5CnO)); goto ZhM2I; ZhM2I: } goto k__I5; k__I5: return $LmMYX->clean($p92LY, $da426); goto o3atF; Z7NFw: static $LmMYX = null; goto xW4Lp; o3atF: } private function setUp() { goto syUQ1; V7YlN: if ($ifdxH = $this->config->get('settings.custom_definition')) { $this->addCustomDefinition($ifdxH, $da426); } goto Ej81y; Ej81y: if ($jERQ1 = $this->config->get('settings.custom_elements')) { if ($OsAyM = $da426->maybeGetRawHTMLDefinition()) { $this->addCustomElements($jERQ1, $OsAyM); } } goto i5Rlg; syUQ1: $this->checkCacheDirectory(); goto o8pOh; jPj1f: $da426->loadArray($this->getConfig()); goto V7YlN; TDoiW: if (!$this->config->get('finalize')) { $da426->autoFinalize = false; } goto jPj1f; xlQBE: $this->purifier = new HTMLPurifier($this->configure($da426)); goto RGmBz; i5Rlg: if ($OvInA = $this->config->get('settings.custom_attributes')) { if ($OsAyM = $da426->maybeGetRawHTMLDefinition()) { $this->addCustomAttributes($OvInA, $OsAyM); } } goto xlQBE; o8pOh: $da426 = HTMLPurifier_Config::createDefault(); goto TDoiW; RGmBz: } private function addCustomDefinition(array $ifdxH, $UTFrr = null) { goto tLrvl; jkc1N: if ($OsAyM = $UTFrr->maybeGetRawHTMLDefinition()) { if (!empty($ifdxH['attributes'])) { $this->addCustomAttributes($ifdxH['attributes'], $OsAyM); } if (!empty($ifdxH['elements'])) { $this->addCustomElements($ifdxH['elements'], $OsAyM); } } goto X3L7h; tLrvl: if (!$UTFrr) { $UTFrr = HTMLPurifier_Config::createDefault(); $UTFrr->loadArray($this->getConfig()); } goto iHLpX; X3L7h: return $UTFrr; goto C81C9; iHLpX: $UTFrr->set('HTML.DefinitionID', $ifdxH['id']); goto sR_za; sR_za: $UTFrr->set('HTML.DefinitionRev', $ifdxH['rev']); goto ktD2q; ktD2q: if (!isset($ifdxH['debug']) || $ifdxH['debug']) { $UTFrr->set('Cache.DefinitionImpl', null); } goto jkc1N; C81C9: } private function addCustomAttributes(array $OvInA, $CUEKQ) { foreach ($OvInA as $CdpPM) { goto vCpPN; W3hCv: $tVhPM = $CdpPM[2]; goto x150Z; x150Z: $CUEKQ->addAttribute($D2Qzk, $F7zvF, $tVhPM); goto JClob; HrRAg: $F7zvF = $AXLhb ? $CdpPM[1] . '*' : $CdpPM[1]; goto W3hCv; cZ7RS: $D2Qzk = $CdpPM[0]; goto HrRAg; vCpPN: $AXLhb = !empty($CdpPM[3]) ? true : false; goto cZ7RS; JClob: } return $CUEKQ; } private function addCustomElements(array $jERQ1, $CUEKQ) { foreach ($jERQ1 as $kWjn7) { goto BtXw9; uTG5t: $OvInA = isset($kWjn7[4]) ? $kWjn7[4] : null; goto B5Fbk; BtXw9: $XggBq = $kWjn7[0]; goto sY59v; B5Fbk: if (!empty($OvInA)) { $CUEKQ->addElement($XggBq, $nXXBK, $PqxNW, $i4vWt, $OvInA); } else { $CUEKQ->addElement($XggBq, $nXXBK, $PqxNW, $i4vWt); } goto l7NUi; dDpGw: $PqxNW = $kWjn7[2]; goto joFvr; sY59v: $nXXBK = $kWjn7[1]; goto dDpGw; joFvr: $i4vWt = $kWjn7[3]; goto uTG5t; l7NUi: } } private function checkCacheDirectory() { $Pv584 = $this->config->get('cachePath'); if ($Pv584) { if (!$this->files->isDirectory($Pv584)) { $this->files->makeDirectory($Pv584, $this->config->get('cacheFileMode', 493)); } } } protected function configure(HTMLPurifier_Config $da426) { return HTMLPurifier_Config::inherit($da426); } protected function getConfig($da426 = null) { goto fxV2j; keb0v: $E0e1G['Core.Encoding'] = $this->config->get('encoding'); goto IeikS; fxV2j: $E0e1G = array(); goto keb0v; edB5l: $da426 = $E0e1G + $da426; goto b5Av4; KduZ6: if (!$da426) { $da426 = $this->config->get('settings.default'); } elseif (is_string($da426)) { $da426 = $this->config->get('settings.' . $da426); } goto J53sH; J53sH: if (!is_array($da426)) { $da426 = array(); } goto edB5l; T9JML: $E0e1G['Cache.SerializerPermissions'] = $this->config->get('cacheFileMode', 493); goto KduZ6; b5Av4: return $da426; goto AlAbF; IeikS: $E0e1G['Cache.SerializerPath'] = $this->config->get('cachePath'); goto T9JML; AlAbF: } public function clean($p92LY, $da426 = null) { if (is_array($p92LY)) { return array_map(function ($V563N) use($da426) { return $this->clean($V563N, $da426); }, $p92LY); } return $this->purifier->purify($p92LY, $this->getConfig($da426)); } public function getInstance() { return $this->purifier; } }