<?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($rFmqf, $v8Iwj = 'data-src', $UfRfI = false) { goto RkgMP; lTaWE: return $rFmqf; goto jsxyS; RkgMP: preg_match_all('/(<img.*?)src="(.*?)"(.*?>)/i', $rFmqf, $i5sAZ); goto agEVY; agEVY: if ($UfRfI) { foreach ($i5sAZ[0] as $kh68j => $tHq0l) { $rFmqf = str_replace($tHq0l, $i5sAZ[1][$kh68j] . $v8Iwj . '="' . AssetsUtil::fix($i5sAZ[2][$kh68j]) . '"' . $i5sAZ[3][$kh68j], $rFmqf); } } else { foreach ($i5sAZ[0] as $kh68j => $tHq0l) { $rFmqf = str_replace($tHq0l, $i5sAZ[1][$kh68j] . $v8Iwj . '="' . AssetsUtil::fix($i5sAZ[2][$kh68j]) . '"' . $i5sAZ[3][$kh68j], $rFmqf); } } goto lTaWE; jsxyS: } public static function replaceImageSrcToFull($rFmqf, $UfRfI = false, $RdXqu = null) { goto gnuf7; LcG6b: return $rFmqf; goto YcAQS; gnuf7: preg_match_all('/(<img.*?)src="(.*?)"(.*?>)/i', $rFmqf, $i5sAZ); goto VsDng; VsDng: foreach ($i5sAZ[0] as $kh68j => $tHq0l) { if ($RdXqu) { $rFmqf = str_replace($tHq0l, $i5sAZ[1][$kh68j] . 'src="' . AssetsUtil::fixFullWithCdn($i5sAZ[2][$kh68j], $RdXqu) . '"' . $i5sAZ[3][$kh68j], $rFmqf); } else { if ($UfRfI) { $rFmqf = str_replace($tHq0l, $i5sAZ[1][$kh68j] . 'src="' . AssetsUtil::fixFull($i5sAZ[2][$kh68j]) . '"' . $i5sAZ[3][$kh68j], $rFmqf); } else { $rFmqf = str_replace($tHq0l, $i5sAZ[1][$kh68j] . 'src="' . AssetsUtil::fixCurrentDomain($i5sAZ[2][$kh68j]) . '"' . $i5sAZ[3][$kh68j], $rFmqf); } } } goto LcG6b; YcAQS: } public static function recordsReplaceImageSrcToFull(&$AMtla, $ax5t3, $UfRfI = false, $RdXqu = null) { foreach ($AMtla as $kh68j => $tHq0l) { $AMtla[$kh68j][$ax5t3] = self::replaceImageSrcToFull($tHq0l[$ax5t3], $UfRfI, $RdXqu); } } public static function extractTextAndImages($rFmqf) { goto iwiDG; aA1J9: preg_match_all('/<img.*?src="(.*?)".*?>/i', $rFmqf, $i5sAZ); goto OZkIp; OZkIp: if (!empty($i5sAZ[1])) { $iecep['images'] = $i5sAZ[1]; } goto qG3xK; xSQSs: $MLXrV = preg_replace('/<[^>]+>/', '', $rFmqf); goto cjKBB; cjKBB: $iecep['text'] = $MLXrV; goto aA1J9; iwiDG: $iecep = array('text' => '', 'images' => array()); goto xSQSs; qG3xK: return $iecep; goto gzryA; gzryA: } public static function cover($rFmqf) { goto jT90E; jT90E: preg_match_all('/<img.*?src="(.*?)".*?>/i', $rFmqf, $i5sAZ); goto ipryK; ipryK: if (!empty($i5sAZ[1][0])) { return $i5sAZ[1][0]; } goto h72Br; h72Br: return null; goto IBxRd; IBxRd: } public static function text($rFmqf, $qodot = null) { goto AIkkZ; NBYi2: if (null !== $qodot) { $MLXrV = Str::limit($MLXrV, $qodot); } goto VhJMe; VhJMe: return str_replace(array('&nbsp;'), array(' '), $MLXrV); goto yPqFR; AIkkZ: $MLXrV = preg_replace('/<[^>]+>/', '', $rFmqf); goto NBYi2; yPqFR: } public static function filter($rFmqf) { if (empty($rFmqf)) { return $rFmqf; } return Purifier::cleanHtml($rFmqf); } public static function filter2($rFmqf) { if (empty($rFmqf)) { return $rFmqf; } return Purifier::cleanHtml($rFmqf); } public static function text2html($MLXrV, $Z9huY = true) { goto JKxTg; HPc8n: $MLXrV = str_replace('
', '', $MLXrV); goto k1JqQ; JKxTg: if (empty($MLXrV)) { return ''; } goto eGDsc; bexoY: return '<p>' . $MLXrV . '</p>'; goto nDXdt; eGDsc: if ($Z9huY) { $MLXrV = htmlspecialchars($MLXrV, ENT_QUOTES, 'UTF-8', false); } goto HPc8n; whk4B: $MLXrV = str_replace('<p></p>', '<p>&nbsp;</p>', $MLXrV); goto bexoY; k1JqQ: $MLXrV = str_replace('
', '</p><p>', $MLXrV); goto whk4B; nDXdt: } public static function text2htmlSimpleRich($MLXrV, $Z9huY = true) { goto MLijp; YPSmH: $rFmqf = preg_replace('|([\\w\\d]*)\\s?(https?://([\\d\\w\\.-]+\\.[\\w\\.]{2,6})[^\\s\\]\\[\\<\\>]*/?)|i', '<a href="$2" target="_blank">$0</a>', $rFmqf); goto UEjs6; UEjs6: return $rFmqf; goto QMZrm; MLijp: $rFmqf = self::text2html($MLXrV, $Z9huY); goto YPSmH; QMZrm: } public static function html2text($MLXrV) { return str_replace(array('</p>', '<p>'), array('
', ''), $MLXrV); } public static function workCount($rFmqf) { goto TC9e1; dJg6U: $daQZi = count($i5sAZ[0]); goto YFX5Y; Snjtc: preg_match_all('/[a-z0-9]+/i', $rFmqf, $i5sAZ); goto dJg6U; YFX5Y: $rFmqf = str_replace('^', '', $rFmqf); goto OJ4fH; gUyR3: $Vc0x8 = mb_strlen($rFmqf, 'utf-8'); goto WUdPz; WUdPz: return $daQZi + $Vc0x8; goto r1Ftq; OJ4fH: $rFmqf = preg_replace('/[^\\x{4e00}-\\x{9fa5}]+/u', '', $rFmqf); goto gUyR3; TC9e1: $rFmqf = preg_replace('/<[^>]+>/', '^', $rFmqf); goto Snjtc; r1Ftq: } }