<?php
/**
 * ------------------------ 
 *  版权所有  www.tecmz.com
 *  商业版本请购买正版授权使用
 * ------------------------
*/ namespace ModStart\Core\Util; use Illuminate\Support\Str; use ModStart\Core\Assets\AssetsUtil; use ModStart\Misc\Html\Purifier; class HtmlUtil { public static function replaceImageSrcToLazyLoad($ohNZt, $OtXAZ = 'data-src', $hhULK = false) { goto sbYRT; kSonz: return $ohNZt; goto rYnYk; sbYRT: preg_match_all('/(<img.*?)src="(.*?)"(.*?>)/i', $ohNZt, $wsKBJ); goto YIWAa; YIWAa: if ($hhULK) { foreach ($wsKBJ[0] as $F_a6B => $JiRHR) { $ohNZt = str_replace($JiRHR, $wsKBJ[1][$F_a6B] . $OtXAZ . '="' . AssetsUtil::fix($wsKBJ[2][$F_a6B]) . '"' . $wsKBJ[3][$F_a6B], $ohNZt); } } else { foreach ($wsKBJ[0] as $F_a6B => $JiRHR) { $ohNZt = str_replace($JiRHR, $wsKBJ[1][$F_a6B] . $OtXAZ . '="' . AssetsUtil::fix($wsKBJ[2][$F_a6B]) . '"' . $wsKBJ[3][$F_a6B], $ohNZt); } } goto kSonz; rYnYk: } public static function replaceImageSrcToFull($ohNZt, $hhULK = false, $LToCk = null) { goto Ua13b; FtDc1: return $ohNZt; goto tIR9s; Ua13b: preg_match_all('/(<img.*?)src="(.*?)"(.*?>)/i', $ohNZt, $wsKBJ); goto kXSS0; kXSS0: foreach ($wsKBJ[0] as $F_a6B => $JiRHR) { if ($LToCk) { $ohNZt = str_replace($JiRHR, $wsKBJ[1][$F_a6B] . 'src="' . AssetsUtil::fixFullWithCdn($wsKBJ[2][$F_a6B], $LToCk) . '"' . $wsKBJ[3][$F_a6B], $ohNZt); } else { if ($hhULK) { $ohNZt = str_replace($JiRHR, $wsKBJ[1][$F_a6B] . 'src="' . AssetsUtil::fixFull($wsKBJ[2][$F_a6B]) . '"' . $wsKBJ[3][$F_a6B], $ohNZt); } else { $ohNZt = str_replace($JiRHR, $wsKBJ[1][$F_a6B] . 'src="' . AssetsUtil::fixCurrentDomain($wsKBJ[2][$F_a6B]) . '"' . $wsKBJ[3][$F_a6B], $ohNZt); } } } goto FtDc1; tIR9s: } public static function recordsReplaceImageSrcToFull(&$laNjB, $GUcFO, $hhULK = false, $LToCk = null) { foreach ($laNjB as $F_a6B => $JiRHR) { $laNjB[$F_a6B][$GUcFO] = self::replaceImageSrcToFull($JiRHR[$GUcFO], $hhULK, $LToCk); } } public static function extractTextAndImages($ohNZt) { goto WbYGX; f8P2L: if (!empty($wsKBJ[1])) { $fQVEU['images'] = $wsKBJ[1]; } goto e0D0w; e0D0w: return $fQVEU; goto fKNmi; B5zf9: $fQVEU['text'] = $BaGNs; goto U4V0I; WbYGX: $fQVEU = array('text' => '', 'images' => array()); goto VVMyP; VVMyP: $BaGNs = preg_replace('/<[^>]+>/', '', $ohNZt); goto B5zf9; U4V0I: preg_match_all('/<img.*?src="(.*?)".*?>/i', $ohNZt, $wsKBJ); goto f8P2L; fKNmi: } public static function cover($ohNZt) { goto PwI4v; U8h_g: if (!empty($wsKBJ[1][0])) { return $wsKBJ[1][0]; } goto kSjp3; PwI4v: preg_match_all('/<img.*?src="(.*?)".*?>/i', $ohNZt, $wsKBJ); goto U8h_g; kSjp3: return null; goto AsyIA; AsyIA: } public static function text($ohNZt, $P4x0J = null) { goto tkv6C; mqg2v: if (null !== $P4x0J) { $BaGNs = Str::limit($BaGNs, $P4x0J); } goto uzcqQ; uzcqQ: return str_replace(array('&nbsp;'), array(' '), $BaGNs); goto wHiD4; tkv6C: $BaGNs = preg_replace('/<[^>]+>/', '', $ohNZt); goto mqg2v; wHiD4: } public static function filter($ohNZt) { if (empty($ohNZt)) { return $ohNZt; } return Purifier::cleanHtml($ohNZt); } public static function filter2($ohNZt) { if (empty($ohNZt)) { return $ohNZt; } return Purifier::cleanHtml($ohNZt); } public static function text2html($BaGNs, $ZVUWK = true) { goto CqR9m; Ocke8: $BaGNs = str_replace('
', '</p><p>', $BaGNs); goto vcyUx; e1Mr5: if ($ZVUWK) { $BaGNs = htmlspecialchars($BaGNs, ENT_QUOTES, 'UTF-8', false); } goto YwCDH; vcyUx: $BaGNs = str_replace('<p></p>', '<p>&nbsp;</p>', $BaGNs); goto NZF0r; NZF0r: return '<p>' . $BaGNs . '</p>'; goto jGQPI; CqR9m: if (empty($BaGNs)) { return ''; } goto e1Mr5; YwCDH: $BaGNs = str_replace('
', '', $BaGNs); goto Ocke8; jGQPI: } public static function text2htmlSimpleRich($BaGNs, $ZVUWK = true) { goto IIZpe; DhKHt: return $ohNZt; goto KMnrC; saIkr: $ohNZt = preg_replace('|([\\w\\d]*)\\s?(https?://([\\d\\w\\.-]+\\.[\\w\\.]{2,6})[^\\s\\]\\[\\<\\>]*/?)|i', '<a href="$2" target="_blank">$0</a>', $ohNZt); goto DhKHt; IIZpe: $ohNZt = self::text2html($BaGNs, $ZVUWK); goto saIkr; KMnrC: } public static function html2text($BaGNs) { return str_replace(array('</p>', '<p>'), array('
', ''), $BaGNs); } public static function workCount($ohNZt) { goto NRLh0; lKYIH: $mXTso = count($wsKBJ[0]); goto lkSTe; lkSTe: $ohNZt = str_replace('^', '', $ohNZt); goto o8wfE; TvbSu: return $mXTso + $Jlusq; goto lpBys; o8wfE: $ohNZt = preg_replace('/[^\\x{4e00}-\\x{9fa5}]+/u', '', $ohNZt); goto zV1pU; WIP1h: preg_match_all('/[a-z0-9]+/i', $ohNZt, $wsKBJ); goto lKYIH; zV1pU: $Jlusq = mb_strlen($ohNZt, 'utf-8'); goto TvbSu; NRLh0: $ohNZt = preg_replace('/<[^>]+>/', '^', $ohNZt); goto WIP1h; lpBys: } }