<?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($DTnPC, $JFEkL = 'data-src', $IltJc = false) { goto Rp8Z9; KRpFh: return $DTnPC; goto EADwd; Rp8Z9: preg_match_all('/(<img.*?)src="(.*?)"(.*?>)/i', $DTnPC, $FH50y); goto afQdB; afQdB: if ($IltJc) { foreach ($FH50y[0] as $GBNIv => $VFelt) { $DTnPC = str_replace($VFelt, $FH50y[1][$GBNIv] . $JFEkL . '="' . AssetsUtil::fix($FH50y[2][$GBNIv]) . '"' . $FH50y[3][$GBNIv], $DTnPC); } } else { foreach ($FH50y[0] as $GBNIv => $VFelt) { $DTnPC = str_replace($VFelt, $FH50y[1][$GBNIv] . $JFEkL . '="' . AssetsUtil::fix($FH50y[2][$GBNIv]) . '"' . $FH50y[3][$GBNIv], $DTnPC); } } goto KRpFh; EADwd: } public static function replaceImageSrcToFull($DTnPC, $IltJc = false, $PXazA = null) { goto eFMGh; ZjdB5: foreach ($FH50y[0] as $GBNIv => $VFelt) { if ($PXazA) { $DTnPC = str_replace($VFelt, $FH50y[1][$GBNIv] . 'src="' . AssetsUtil::fixFullWithCdn($FH50y[2][$GBNIv], $PXazA) . '"' . $FH50y[3][$GBNIv], $DTnPC); } else { if ($IltJc) { $DTnPC = str_replace($VFelt, $FH50y[1][$GBNIv] . 'src="' . AssetsUtil::fixFull($FH50y[2][$GBNIv]) . '"' . $FH50y[3][$GBNIv], $DTnPC); } else { $DTnPC = str_replace($VFelt, $FH50y[1][$GBNIv] . 'src="' . AssetsUtil::fixCurrentDomain($FH50y[2][$GBNIv]) . '"' . $FH50y[3][$GBNIv], $DTnPC); } } } goto EhXRN; EhXRN: return $DTnPC; goto oyjm3; eFMGh: preg_match_all('/(<img.*?)src="(.*?)"(.*?>)/i', $DTnPC, $FH50y); goto ZjdB5; oyjm3: } public static function recordsReplaceImageSrcToFull(&$feJuE, $rvTrU, $IltJc = false, $PXazA = null) { foreach ($feJuE as $GBNIv => $VFelt) { $feJuE[$GBNIv][$rvTrU] = self::replaceImageSrcToFull($VFelt[$rvTrU], $IltJc, $PXazA); } } public static function extractTextAndImages($DTnPC) { goto YCl98; REv8s: preg_match_all('/<img.*?src="(.*?)".*?>/i', $DTnPC, $FH50y); goto L683w; dFZHH: $gMyjJ['text'] = $nvOlQ; goto REv8s; JbuW_: $nvOlQ = preg_replace('/<[^>]+>/', '', $DTnPC); goto dFZHH; okjGJ: return $gMyjJ; goto OS7UA; L683w: if (!empty($FH50y[1])) { $gMyjJ['images'] = $FH50y[1]; } goto okjGJ; YCl98: $gMyjJ = array('text' => '', 'images' => array()); goto JbuW_; OS7UA: } public static function cover($DTnPC) { goto AUByc; AUByc: preg_match_all('/<img.*?src="(.*?)".*?>/i', $DTnPC, $FH50y); goto BlS1F; BlS1F: if (!empty($FH50y[1][0])) { return $FH50y[1][0]; } goto mY3Ra; mY3Ra: return null; goto vc5Ea; vc5Ea: } public static function text($DTnPC, $Cq2Q4 = null) { goto SGYQD; XM0ON: if (null !== $Cq2Q4) { $nvOlQ = Str::limit($nvOlQ, $Cq2Q4); } goto CgqKp; SGYQD: $nvOlQ = preg_replace('/<[^>]+>/', '', $DTnPC); goto XM0ON; CgqKp: return str_replace(array('&nbsp;'), array(' '), $nvOlQ); goto o6CEb; o6CEb: } public static function filter($DTnPC) { if (empty($DTnPC)) { return $DTnPC; } return Purifier::cleanHtml($DTnPC); } public static function filter2($DTnPC) { if (empty($DTnPC)) { return $DTnPC; } return Purifier::cleanHtml($DTnPC); } public static function text2html($nvOlQ, $fjavm = true) { goto iyJNL; ap9Oh: $nvOlQ = str_replace('<p></p>', '<p>&nbsp;</p>', $nvOlQ); goto zi7uQ; zi7uQ: return '<p>' . $nvOlQ . '</p>'; goto EIs9y; SIrl7: $nvOlQ = str_replace('
', '</p><p>', $nvOlQ); goto ap9Oh; AOQf2: if ($fjavm) { $nvOlQ = htmlspecialchars($nvOlQ, ENT_QUOTES, 'UTF-8', false); } goto H6nzh; H6nzh: $nvOlQ = str_replace('
', '', $nvOlQ); goto SIrl7; iyJNL: if (empty($nvOlQ)) { return ''; } goto AOQf2; EIs9y: } public static function text2htmlSimpleRich($nvOlQ, $fjavm = true) { goto ufEM5; cyr92: return $DTnPC; goto VmYix; BHwoE: $DTnPC = preg_replace('|([\\w\\d]*)\\s?(https?://([\\d\\w\\.-]+\\.[\\w\\.]{2,6})[^\\s\\]\\[\\<\\>]*/?)|i', '<a href="$2" target="_blank">$0</a>', $DTnPC); goto cyr92; ufEM5: $DTnPC = self::text2html($nvOlQ, $fjavm); goto BHwoE; VmYix: } public static function html2text($nvOlQ) { return str_replace(array('</p>', '<p>'), array('
', ''), $nvOlQ); } public static function workCount($DTnPC) { goto OpAvA; zXmWT: $uhW3q = count($FH50y[0]); goto ADysU; JCGlY: $DTnPC = preg_replace('/[^\\x{4e00}-\\x{9fa5}]+/u', '', $DTnPC); goto z36O_; z36O_: $IZkxM = mb_strlen($DTnPC, 'utf-8'); goto Uqndq; ADysU: $DTnPC = str_replace('^', '', $DTnPC); goto JCGlY; OpAvA: $DTnPC = preg_replace('/<[^>]+>/', '^', $DTnPC); goto PR5BI; Uqndq: return $uhW3q + $IZkxM; goto hlL0R; PR5BI: preg_match_all('/[a-z0-9]+/i', $DTnPC, $FH50y); goto zXmWT; hlL0R: } }