From 41cb1fdfe5b492798b5cb7522fa38150d90e28de Mon Sep 17 00:00:00 2001 From: Eltrac Koalar Date: Fri, 20 Mar 2020 11:41:53 +0800 Subject: =?UTF-8?q?=F0=9F=99=82=20Perf:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E7=BB=93=E6=9E=84=EF=BC=8C=E6=94=AF=E6=8C=81=E8=A7=A3?= =?UTF-8?q?=E6=9E=90=20owo=20=E8=A1=A8=E6=83=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/Contents.php | 234 +++++++++++++++++++++++++++++------------------------- 1 file changed, 127 insertions(+), 107 deletions(-) (limited to 'libs') diff --git a/libs/Contents.php b/libs/Contents.php index 7ed0f5c..5c8bada 100644 --- a/libs/Contents.php +++ b/libs/Contents.php @@ -1,10 +1,4 @@ fetchAll($db->select('value')->from('table.options')->where('name = %s', "theme:Miracles")->limit(1)); $load_image = explode("\";",explode("\"",explode("\"loading_image\";",$load_image[0]["value"],2)[1],2)[1],2)[0]; $text = empty($last) ? $data : $last; if ($widget instanceof Widget_Archive) { - //Prism 高亮 - $text = preg_replace('/
/s','
',$text);
-		    //FancyBox
-	        $text = preg_replace('//s','
',$text); - //LazyLoad - $text = preg_replace('//','',$text); - - //章节链接 - $reg='/\(.*?)\<\/h.*?\>/s'; - $text = preg_replace_callback($reg, array('Contents', 'parseHeaderCallback'), $text); - - //气泡 - $text = preg_replace('/\[bubble\](.*?)\[\/bubble\]/s','

${1}

',$text); + //ParseOther + $text = Contents::parsePrism(Contents::parseImages(Contents::parseHeadings(Contents::parseTextColor(Contents::parseRuby(Contents::parseTip(Contents::parseLink(Contents::parseEmo($text)))))))); + //LazyLoad + $text = preg_replace('//','',$text); + } + return $text; + } + + /** + * 解析 Prism + */ + static public function parsePrism($text){ + //未定义的代码语言视为 html + $text = preg_replace('/
/s','
',$text);
+		return $text;
+	}
+	
+	/**
+	 *  解析图片
+	 */
+	static public function parseImages($text){
+		//FancyBox
+	    $text = preg_replace('//s','
',$text); + + return $text; + } + + /** + * 解析章节链接 + */ + static public function parseHeadings($text){ + $reg='/\(.*?)\<\/h.*?\>/s'; + $text = preg_replace_callback($reg, array('Contents', 'parseHeaderCallback'), $text); - //Text Color - $text = preg_replace('/\&\{(.*?)\|(.*?)\|(.*?)\}/s','${1}',$text); - - //ruby - $reg = '/\{\{(.*?):(.*?)\}\}/s'; - $rp = '${1}(${2})'; - $text = preg_replace($reg,$rp,$text); + return $text; + } + + /** + * 解析 Text-Color + */ + static public function parseTextColor($text){ + $text = preg_replace('/\&\{(.*?)\|(.*?)\|(.*?)\}/s','${1}',$text); + return $text; + } + + /** + * 解析 Ruby + */ + static public function parseRuby($text){ + $reg = '/\{\{(.*?):(.*?)\}\}/s'; + $rp = '${1}(${2})'; + $text = preg_replace($reg,$rp,$text); + + return $text; + } + + /** + * 解析 Tip + */ + static public function parseTip($text){ + //Tip without var + $text = preg_replace('/\[tip\](.*?)\[\/tip\]/s','
${1}
',$text); + //Tip + $text = preg_replace('/\[tip type="(.*?)"\](.*?)\[\/tip\]/s','
${2}
',$text); + //Tip Group + $text = preg_replace('/\[tip\-group\](.*?)\[\/tip\-group\]/s','
${1}
',$text); - //Tip without var - $text = preg_replace('/\[tip\](.*?)\[\/tip\]/s','
${1}
',$text); - //Tip - $text = preg_replace('/\[tip type="(.*?)"\](.*?)\[\/tip\]/s','
${2}
',$text); - //Tip Group - $text = preg_replace('/\[tip\-group\](.*?)\[\/tip\-group\]/s','
${1}
',$text); - - //解析友链盒子 - $reg = '/\[links\](.*?)\[\/links\]/s'; - $rp = ''; - $text = preg_replace($reg,$rp,$text); - //解析友链项目 - $reg = '/\[(.*?)\]\{(.*?)\}\((.*?)\)\+\((.*?)\)/s'; - $rp = '