<?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 $GsFul, Repository $eYjRX) { goto aB53i; SQmnz: $this->setUp(); goto ruT2n; z1KZj: $this->config = $eYjRX; goto SQmnz; aB53i: $this->files = $GsFul; goto z1KZj; ruT2n: } public static function cleanHtml($u_ETK, $eYjRX = null) { goto FiPEN; kYMcZ: if (null === $c42T4) { goto hLbUc; Twl_j: $c42T4 = new Purifier($eHf7W['files'], new \Illuminate\Config\Repository($cTIfO)); goto jP4GS; KYcX9: $cTIfO = (include __DIR__ . '/config.php'); goto Twl_j; hLbUc: $eHf7W = app(); goto KYcX9; jP4GS: } goto Uj3f0; Uj3f0: return $c42T4->clean($u_ETK, $eYjRX); goto hq43y; FiPEN: static $c42T4 = null; goto kYMcZ; hq43y: } private function setUp() { goto Ic_Jr; ICgIJ: if (!$this->config->get('finalize')) { $eYjRX->autoFinalize = false; } goto Xm6cG; rqqf5: $eYjRX = HTMLPurifier_Config::createDefault(); goto ICgIJ; Xm6cG: $eYjRX->loadArray($this->getConfig()); goto jtBBY; Ic_Jr: $this->checkCacheDirectory(); goto rqqf5; DdDmh: if ($CNbEX = $this->config->get('settings.custom_elements')) { if ($FvRiu = $eYjRX->maybeGetRawHTMLDefinition()) { $this->addCustomElements($CNbEX, $FvRiu); } } goto XNjvI; XNjvI: if ($jY6U_ = $this->config->get('settings.custom_attributes')) { if ($FvRiu = $eYjRX->maybeGetRawHTMLDefinition()) { $this->addCustomAttributes($jY6U_, $FvRiu); } } goto hcrq1; jtBBY: if ($EKX12 = $this->config->get('settings.custom_definition')) { $this->addCustomDefinition($EKX12, $eYjRX); } goto DdDmh; hcrq1: $this->purifier = new HTMLPurifier($this->configure($eYjRX)); goto DKsP4; DKsP4: } private function addCustomDefinition(array $EKX12, $yFBTx = null) { goto POQu8; uwDwv: $yFBTx->set('HTML.DefinitionID', $EKX12['id']); goto kwAgH; kwAgH: $yFBTx->set('HTML.DefinitionRev', $EKX12['rev']); goto mFMp2; mFMp2: if (!isset($EKX12['debug']) || $EKX12['debug']) { $yFBTx->set('Cache.DefinitionImpl', null); } goto ekoD7; ekoD7: if ($FvRiu = $yFBTx->maybeGetRawHTMLDefinition()) { if (!empty($EKX12['attributes'])) { $this->addCustomAttributes($EKX12['attributes'], $FvRiu); } if (!empty($EKX12['elements'])) { $this->addCustomElements($EKX12['elements'], $FvRiu); } } goto E3UkI; POQu8: if (!$yFBTx) { $yFBTx = HTMLPurifier_Config::createDefault(); $yFBTx->loadArray($this->getConfig()); } goto uwDwv; E3UkI: return $yFBTx; goto PheY9; PheY9: } private function addCustomAttributes(array $jY6U_, $gTVhg) { foreach ($jY6U_ as $vcBu8) { goto AS8P9; PXOiX: $xd0r3 = $sI0ua ? $vcBu8[1] . '*' : $vcBu8[1]; goto coKeh; AS8P9: $sI0ua = !empty($vcBu8[3]) ? true : false; goto Qwf8k; coKeh: $eeXIO = $vcBu8[2]; goto d1sqS; d1sqS: $gTVhg->addAttribute($g9QOr, $xd0r3, $eeXIO); goto ARgSM; Qwf8k: $g9QOr = $vcBu8[0]; goto PXOiX; ARgSM: } return $gTVhg; } private function addCustomElements(array $CNbEX, $gTVhg) { foreach ($CNbEX as $F6q3h) { goto L_yXu; oY7u8: $ptzKq = $F6q3h[1]; goto LADHe; OxqOQ: $jY6U_ = isset($F6q3h[4]) ? $F6q3h[4] : null; goto f1mli; L_yXu: $L1g9F = $F6q3h[0]; goto oY7u8; LADHe: $go5sU = $F6q3h[2]; goto mLe70; f1mli: if (!empty($jY6U_)) { $gTVhg->addElement($L1g9F, $ptzKq, $go5sU, $QI1yF, $jY6U_); } else { $gTVhg->addElement($L1g9F, $ptzKq, $go5sU, $QI1yF); } goto uvAL8; mLe70: $QI1yF = $F6q3h[3]; goto OxqOQ; uvAL8: } } private function checkCacheDirectory() { $E2PWt = $this->config->get('cachePath'); if ($E2PWt) { if (!$this->files->isDirectory($E2PWt)) { $this->files->makeDirectory($E2PWt, $this->config->get('cacheFileMode', 493)); } } } protected function configure(HTMLPurifier_Config $eYjRX) { return HTMLPurifier_Config::inherit($eYjRX); } protected function getConfig($eYjRX = null) { goto ODL9F; VkrZ1: $eYjRX = $S0rYx + $eYjRX; goto cdUqF; h_tWN: $S0rYx['Core.Encoding'] = $this->config->get('encoding'); goto frCaM; A8LpS: if (!is_array($eYjRX)) { $eYjRX = array(); } goto VkrZ1; ODL9F: $S0rYx = array(); goto h_tWN; OOJCf: $S0rYx['Cache.SerializerPermissions'] = $this->config->get('cacheFileMode', 493); goto boiu9; cdUqF: return $eYjRX; goto hztdY; frCaM: $S0rYx['Cache.SerializerPath'] = $this->config->get('cachePath'); goto OOJCf; boiu9: if (!$eYjRX) { $eYjRX = $this->config->get('settings.default'); } elseif (is_string($eYjRX)) { $eYjRX = $this->config->get('settings.' . $eYjRX); } goto A8LpS; hztdY: } public function clean($u_ETK, $eYjRX = null) { if (is_array($u_ETK)) { return array_map(function ($nsWl0) use($eYjRX) { return $this->clean($nsWl0, $eYjRX); }, $u_ETK); } return $this->purifier->purify($u_ETK, $this->getConfig($eYjRX)); } public function getInstance() { return $this->purifier; } }