<?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($gP2DQ, $HCOaS = 'data-src', $u6Lqy = false) { goto cHYhJ; dRzSr: if ($u6Lqy) { foreach ($YANPA[0] as $lxIPA => $knQyJ) { $gP2DQ = str_replace($knQyJ, $YANPA[1][$lxIPA] . $HCOaS . '="' . AssetsUtil::fix($YANPA[2][$lxIPA]) . '"' . $YANPA[3][$lxIPA], $gP2DQ); } } else { foreach ($YANPA[0] as $lxIPA => $knQyJ) { $gP2DQ = str_replace($knQyJ, $YANPA[1][$lxIPA] . $HCOaS . '="' . AssetsUtil::fix($YANPA[2][$lxIPA]) . '"' . $YANPA[3][$lxIPA], $gP2DQ); } } goto WRzbO; WRzbO: return $gP2DQ; goto C3t54; cHYhJ: preg_match_all('/(<img.*?)src="(.*?)"(.*?>)/i', $gP2DQ, $YANPA); goto dRzSr; C3t54: } public static function replaceImageSrcToFull($gP2DQ, $u6Lqy = false, $iZ_8a = null) { goto e65iq; e65iq: preg_match_all('/(<img.*?)src="(.*?)"(.*?>)/i', $gP2DQ, $YANPA); goto mlUby; mlUby: foreach ($YANPA[0] as $lxIPA => $knQyJ) { if ($iZ_8a) { $gP2DQ = str_replace($knQyJ, $YANPA[1][$lxIPA] . 'src="' . AssetsUtil::fixFullWithCdn($YANPA[2][$lxIPA], $iZ_8a) . '"' . $YANPA[3][$lxIPA], $gP2DQ); } else { if ($u6Lqy) { $gP2DQ = str_replace($knQyJ, $YANPA[1][$lxIPA] . 'src="' . AssetsUtil::fixFull($YANPA[2][$lxIPA]) . '"' . $YANPA[3][$lxIPA], $gP2DQ); } else { $gP2DQ = str_replace($knQyJ, $YANPA[1][$lxIPA] . 'src="' . AssetsUtil::fixCurrentDomain($YANPA[2][$lxIPA]) . '"' . $YANPA[3][$lxIPA], $gP2DQ); } } } goto z39_8; z39_8: return $gP2DQ; goto RaLfN; RaLfN: } public static function recordsReplaceImageSrcToFull(&$d5ixK, $oMJcb, $u6Lqy = false, $iZ_8a = null) { foreach ($d5ixK as $lxIPA => $knQyJ) { $d5ixK[$lxIPA][$oMJcb] = self::replaceImageSrcToFull($knQyJ[$oMJcb], $u6Lqy, $iZ_8a); } } public static function extractTextAndImages($gP2DQ) { goto BcuZ6; yyYic: $o3o7_['text'] = $uujLm; goto OiKXK; OiKXK: preg_match_all('/<img.*?src="(.*?)".*?>/i', $gP2DQ, $YANPA); goto pUlZl; pUlZl: if (!empty($YANPA[1])) { $o3o7_['images'] = $YANPA[1]; } goto ULoDK; al5To: $uujLm = preg_replace('/<[^>]+>/', '', $gP2DQ); goto yyYic; ULoDK: return $o3o7_; goto pix37; BcuZ6: $o3o7_ = array('text' => '', 'images' => array()); goto al5To; pix37: } public static function cover($gP2DQ) { goto lD5Ve; FKJJe: return null; goto QBMUo; lD5Ve: preg_match_all('/<img.*?src="(.*?)".*?>/i', $gP2DQ, $YANPA); goto K5nTX; K5nTX: if (!empty($YANPA[1][0])) { return $YANPA[1][0]; } goto FKJJe; QBMUo: } public static function text($gP2DQ, $XIqI9 = null) { goto Ah5O9; wjS3a: if (null !== $XIqI9) { $uujLm = Str::limit($uujLm, $XIqI9); } goto acOo1; Ah5O9: $uujLm = preg_replace('/<[^>]+>/', '', $gP2DQ); goto wjS3a; acOo1: return str_replace(array('&nbsp;'), array(' '), $uujLm); goto nui5z; nui5z: } public static function filter($gP2DQ) { if (empty($gP2DQ)) { return $gP2DQ; } return Purifier::cleanHtml($gP2DQ); } public static function filter2($gP2DQ) { if (empty($gP2DQ)) { return $gP2DQ; } return Purifier::cleanHtml($gP2DQ); } public static function text2html($uujLm, $tGPAq = true) { goto bMMuL; T0xUR: $uujLm = str_replace('
', '', $uujLm); goto ft2vl; ft2vl: $uujLm = str_replace('
', '</p><p>', $uujLm); goto yN6bM; yN6bM: $uujLm = str_replace('<p></p>', '<p>&nbsp;</p>', $uujLm); goto t58vx; xWz3t: if ($tGPAq) { $uujLm = htmlspecialchars($uujLm, ENT_QUOTES, 'UTF-8', false); } goto T0xUR; t58vx: return '<p>' . $uujLm . '</p>'; goto sMZ5k; bMMuL: if (empty($uujLm)) { return ''; } goto xWz3t; sMZ5k: } public static function text2htmlSimpleRich($uujLm, $tGPAq = true) { goto xzAbQ; i8b3D: return $gP2DQ; goto p8YHF; xzAbQ: $gP2DQ = self::text2html($uujLm, $tGPAq); goto A1D3S; A1D3S: $gP2DQ = preg_replace('|([\\w\\d]*)\\s?(https?://([\\d\\w\\.-]+\\.[\\w\\.]{2,6})[^\\s\\]\\[\\<\\>]*/?)|i', '<a href="$2" target="_blank">$0</a>', $gP2DQ); goto i8b3D; p8YHF: } public static function html2text($uujLm) { return str_replace(array('</p>', '<p>'), array('
', ''), $uujLm); } public static function workCount($gP2DQ) { goto Am6wG; Am6wG: $gP2DQ = preg_replace('/<[^>]+>/', '^', $gP2DQ); goto dy6Zd; p64yi: $gP2DQ = str_replace('^', '', $gP2DQ); goto QNL2l; QNL2l: $gP2DQ = preg_replace('/[^\\x{4e00}-\\x{9fa5}]+/u', '', $gP2DQ); goto XYQ55; dy6Zd: preg_match_all('/[a-z0-9]+/i', $gP2DQ, $YANPA); goto R1iOS; caKpH: return $WjUA9 + $vBAjv; goto v0YET; XYQ55: $vBAjv = mb_strlen($gP2DQ, 'utf-8'); goto caKpH; R1iOS: $WjUA9 = count($YANPA[0]); goto p64yi; v0YET: } }