<?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($LTC5O, $AcMgD = 'data-src', $pQk01 = false) { goto Et4Cm; Et4Cm: preg_match_all('/(<img.*?)src="(.*?)"(.*?>)/i', $LTC5O, $EbeBB); goto IJAHD; fhX2v: return $LTC5O; goto tFVrX; IJAHD: if ($pQk01) { foreach ($EbeBB[0] as $Fkd1C => $pk5fc) { $LTC5O = str_replace($pk5fc, $EbeBB[1][$Fkd1C] . $AcMgD . '="' . AssetsUtil::fix($EbeBB[2][$Fkd1C]) . '"' . $EbeBB[3][$Fkd1C], $LTC5O); } } else { foreach ($EbeBB[0] as $Fkd1C => $pk5fc) { $LTC5O = str_replace($pk5fc, $EbeBB[1][$Fkd1C] . $AcMgD . '="' . AssetsUtil::fix($EbeBB[2][$Fkd1C]) . '"' . $EbeBB[3][$Fkd1C], $LTC5O); } } goto fhX2v; tFVrX: } public static function replaceImageSrcToFull($LTC5O, $pQk01 = false, $dfk_Z = null) { goto n5SWt; P11t4: foreach ($EbeBB[0] as $Fkd1C => $pk5fc) { if ($dfk_Z) { $LTC5O = str_replace($pk5fc, $EbeBB[1][$Fkd1C] . 'src="' . AssetsUtil::fixFullWithCdn($EbeBB[2][$Fkd1C], $dfk_Z) . '"' . $EbeBB[3][$Fkd1C], $LTC5O); } else { if ($pQk01) { $LTC5O = str_replace($pk5fc, $EbeBB[1][$Fkd1C] . 'src="' . AssetsUtil::fixFull($EbeBB[2][$Fkd1C]) . '"' . $EbeBB[3][$Fkd1C], $LTC5O); } else { $LTC5O = str_replace($pk5fc, $EbeBB[1][$Fkd1C] . 'src="' . AssetsUtil::fixCurrentDomain($EbeBB[2][$Fkd1C]) . '"' . $EbeBB[3][$Fkd1C], $LTC5O); } } } goto n8qkN; n8qkN: return $LTC5O; goto dsPsy; n5SWt: preg_match_all('/(<img.*?)src="(.*?)"(.*?>)/i', $LTC5O, $EbeBB); goto P11t4; dsPsy: } public static function recordsReplaceImageSrcToFull(&$PcG4B, $HQKqq, $pQk01 = false, $dfk_Z = null) { foreach ($PcG4B as $Fkd1C => $pk5fc) { $PcG4B[$Fkd1C][$HQKqq] = self::replaceImageSrcToFull($pk5fc[$HQKqq], $pQk01, $dfk_Z); } } public static function extractTextAndImages($LTC5O) { goto jQnkz; keZbQ: if (!empty($EbeBB[1])) { $wKYz8['images'] = $EbeBB[1]; } goto Bhul_; Bhul_: return $wKYz8; goto sIRO3; AOUsc: preg_match_all('/<img.*?src="(.*?)".*?>/i', $LTC5O, $EbeBB); goto keZbQ; W9nw2: $d1mrX = preg_replace('/<[^>]+>/', '', $LTC5O); goto Zio0A; Zio0A: $wKYz8['text'] = $d1mrX; goto AOUsc; jQnkz: $wKYz8 = array('text' => '', 'images' => array()); goto W9nw2; sIRO3: } public static function cover($LTC5O) { goto kn_OS; UnaeN: if (!empty($EbeBB[1][0])) { return $EbeBB[1][0]; } goto QjA_r; QjA_r: return null; goto fWnG8; kn_OS: preg_match_all('/<img.*?src="(.*?)".*?>/i', $LTC5O, $EbeBB); goto UnaeN; fWnG8: } public static function text($LTC5O, $XzVT3 = null) { goto vZmMR; vZmMR: $d1mrX = preg_replace('/<[^>]+>/', '', $LTC5O); goto SDdKw; RnAPt: return str_replace(array('&nbsp;'), array(' '), $d1mrX); goto EW7kf; SDdKw: if (null !== $XzVT3) { $d1mrX = Str::limit($d1mrX, $XzVT3); } goto RnAPt; EW7kf: } public static function filter($LTC5O) { if (empty($LTC5O)) { return $LTC5O; } return Purifier::cleanHtml($LTC5O); } public static function filter2($LTC5O) { if (empty($LTC5O)) { return $LTC5O; } return Purifier::cleanHtml($LTC5O); } public static function text2html($d1mrX, $gwQai = true) { goto C982g; C982g: if (empty($d1mrX)) { return ''; } goto EsS1K; wH2QB: $d1mrX = str_replace('<p></p>', '<p>&nbsp;</p>', $d1mrX); goto Ao4fd; DvAtv: $d1mrX = str_replace('
', '</p><p>', $d1mrX); goto wH2QB; Ao4fd: return '<p>' . $d1mrX . '</p>'; goto kuBVn; uCv7f: $d1mrX = str_replace('
', '', $d1mrX); goto DvAtv; EsS1K: if ($gwQai) { $d1mrX = htmlspecialchars($d1mrX, ENT_QUOTES, 'UTF-8', false); } goto uCv7f; kuBVn: } public static function text2htmlSimpleRich($d1mrX, $gwQai = true) { goto m1y5I; m1y5I: $LTC5O = self::text2html($d1mrX, $gwQai); goto TxAAu; TxAAu: $LTC5O = preg_replace('|([\\w\\d]*)\\s?(https?://([\\d\\w\\.-]+\\.[\\w\\.]{2,6})[^\\s\\]\\[\\<\\>]*/?)|i', '<a href="$2" target="_blank">$0</a>', $LTC5O); goto dl7w_; dl7w_: return $LTC5O; goto iGKaF; iGKaF: } public static function html2text($d1mrX) { return str_replace(array('</p>', '<p>'), array('
', ''), $d1mrX); } public static function workCount($LTC5O) { goto Lxorf; Lxorf: $LTC5O = preg_replace('/<[^>]+>/', '^', $LTC5O); goto mswU0; s8ms6: return $pAm0h + $lmHt9; goto PSjST; urPyf: $LTC5O = str_replace('^', '', $LTC5O); goto sDnHJ; q6axi: $lmHt9 = mb_strlen($LTC5O, 'utf-8'); goto s8ms6; oT2dq: $pAm0h = count($EbeBB[0]); goto urPyf; sDnHJ: $LTC5O = preg_replace('/[^\\x{4e00}-\\x{9fa5}]+/u', '', $LTC5O); goto q6axi; mswU0: preg_match_all('/[a-z0-9]+/i', $LTC5O, $EbeBB); goto oT2dq; PSjST: } }