<?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($cgjRu, $Jh9AS = 'data-src', $kZ9U8 = false) { goto ectz4; ectz4: preg_match_all('/(<img.*?)src="(.*?)"(.*?>)/i', $cgjRu, $eG2e9); goto B2Uf8; B2Uf8: if ($kZ9U8) { foreach ($eG2e9[0] as $plrwN => $uTz0e) { $cgjRu = str_replace($uTz0e, $eG2e9[1][$plrwN] . $Jh9AS . '="' . AssetsUtil::fix($eG2e9[2][$plrwN]) . '"' . $eG2e9[3][$plrwN], $cgjRu); } } else { foreach ($eG2e9[0] as $plrwN => $uTz0e) { $cgjRu = str_replace($uTz0e, $eG2e9[1][$plrwN] . $Jh9AS . '="' . AssetsUtil::fix($eG2e9[2][$plrwN]) . '"' . $eG2e9[3][$plrwN], $cgjRu); } } goto FkoY1; FkoY1: return $cgjRu; goto J1w6E; J1w6E: } public static function replaceImageSrcToFull($cgjRu, $kZ9U8 = false, $cnWm4 = null) { goto px7nG; LSUJA: foreach ($eG2e9[0] as $plrwN => $uTz0e) { if ($cnWm4) { $cgjRu = str_replace($uTz0e, $eG2e9[1][$plrwN] . 'src="' . AssetsUtil::fixFullWithCdn($eG2e9[2][$plrwN], $cnWm4) . '"' . $eG2e9[3][$plrwN], $cgjRu); } else { if ($kZ9U8) { $cgjRu = str_replace($uTz0e, $eG2e9[1][$plrwN] . 'src="' . AssetsUtil::fixFull($eG2e9[2][$plrwN]) . '"' . $eG2e9[3][$plrwN], $cgjRu); } else { $cgjRu = str_replace($uTz0e, $eG2e9[1][$plrwN] . 'src="' . AssetsUtil::fixCurrentDomain($eG2e9[2][$plrwN]) . '"' . $eG2e9[3][$plrwN], $cgjRu); } } } goto eICBM; px7nG: preg_match_all('/(<img.*?)src="(.*?)"(.*?>)/i', $cgjRu, $eG2e9); goto LSUJA; eICBM: return $cgjRu; goto cHtm5; cHtm5: } public static function recordsReplaceImageSrcToFull(&$J2nWJ, $dwwIV, $kZ9U8 = false, $cnWm4 = null) { foreach ($J2nWJ as $plrwN => $uTz0e) { $J2nWJ[$plrwN][$dwwIV] = self::replaceImageSrcToFull($uTz0e[$dwwIV], $kZ9U8, $cnWm4); } } public static function extractTextAndImages($cgjRu) { goto KcyQz; iwmGU: preg_match_all('/<img.*?src="(.*?)".*?>/i', $cgjRu, $eG2e9); goto OCHgk; KcyQz: $DIBGY = array('text' => '', 'images' => array()); goto mm7zT; cXFwj: return $DIBGY; goto ptTOs; mm7zT: $fF8o4 = preg_replace('/<[^>]+>/', '', $cgjRu); goto KEoO9; KEoO9: $DIBGY['text'] = $fF8o4; goto iwmGU; OCHgk: if (!empty($eG2e9[1])) { $DIBGY['images'] = $eG2e9[1]; } goto cXFwj; ptTOs: } public static function cover($cgjRu) { goto SzuC3; SzuC3: preg_match_all('/<img.*?src="(.*?)".*?>/i', $cgjRu, $eG2e9); goto UOEA7; UOEA7: if (!empty($eG2e9[1][0])) { return $eG2e9[1][0]; } goto v1aw5; v1aw5: return null; goto fgjHY; fgjHY: } public static function text($cgjRu, $ORgwx = null) { goto ACz64; t5eId: if (null !== $ORgwx) { $fF8o4 = Str::limit($fF8o4, $ORgwx); } goto iDEv0; ACz64: $fF8o4 = preg_replace('/<[^>]+>/', '', $cgjRu); goto t5eId; iDEv0: return str_replace(array('&nbsp;'), array(' '), $fF8o4); goto AqL0A; AqL0A: } public static function filter($cgjRu) { if (empty($cgjRu)) { return $cgjRu; } return Purifier::cleanHtml($cgjRu); } public static function filter2($cgjRu) { if (empty($cgjRu)) { return $cgjRu; } return Purifier::cleanHtml($cgjRu); } public static function text2html($fF8o4, $mbiTZ = true) { goto jerlJ; ze9GT: return '<p>' . $fF8o4 . '</p>'; goto KooHN; jerlJ: if (empty($fF8o4)) { return ''; } goto NkG3A; NkG3A: if ($mbiTZ) { $fF8o4 = htmlspecialchars($fF8o4, ENT_QUOTES, 'UTF-8', false); } goto qnw31; tn201: $fF8o4 = str_replace('<p></p>', '<p>&nbsp;</p>', $fF8o4); goto ze9GT; qnw31: $fF8o4 = str_replace('
', '', $fF8o4); goto bDv7v; bDv7v: $fF8o4 = str_replace('
', '</p><p>', $fF8o4); goto tn201; KooHN: } public static function text2htmlSimpleRich($fF8o4, $mbiTZ = true) { goto NUmgo; XMvK9: return $cgjRu; goto VHitG; NUmgo: $cgjRu = self::text2html($fF8o4, $mbiTZ); goto n7uMr; n7uMr: $cgjRu = preg_replace('|([\\w\\d]*)\\s?(https?://([\\d\\w\\.-]+\\.[\\w\\.]{2,6})[^\\s\\]\\[\\<\\>]*/?)|i', '<a href="$2" target="_blank">$0</a>', $cgjRu); goto XMvK9; VHitG: } public static function html2text($fF8o4) { return str_replace(array('</p>', '<p>'), array('
', ''), $fF8o4); } public static function workCount($cgjRu) { goto DrUnG; toCj6: preg_match_all('/[a-z0-9]+/i', $cgjRu, $eG2e9); goto pQtB3; DrUnG: $cgjRu = preg_replace('/<[^>]+>/', '^', $cgjRu); goto toCj6; HyHh_: $cgjRu = preg_replace('/[^\\x{4e00}-\\x{9fa5}]+/u', '', $cgjRu); goto sw9rr; ZGk44: return $EODa0 + $Q3d5h; goto dqJeD; sw9rr: $Q3d5h = mb_strlen($cgjRu, 'utf-8'); goto ZGk44; pQtB3: $EODa0 = count($eG2e9[0]); goto xUpOR; xUpOR: $cgjRu = str_replace('^', '', $cgjRu); goto HyHh_; dqJeD: } }