From afa631ff8486d614a387759bdc8b473b1534404f Mon Sep 17 00:00:00 2001 From: BigCoke233 Date: Wed, 1 Apr 2020 11:14:06 +0800 Subject: =?UTF-8?q?:man:=20Add:=20=E5=8F=8B=E9=93=BE=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E8=B0=83=E7=94=A8=E5=A4=96=E9=83=A8=20json=20=E6=95=B0?= =?UTF-8?q?=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/Contents.php | 75 ++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 50 insertions(+), 25 deletions(-) (limited to 'libs/Contents.php') diff --git a/libs/Contents.php b/libs/Contents.php index db9bfff..0b1eaf7 100644 --- a/libs/Contents.php +++ b/libs/Contents.php @@ -1,6 +1,7 @@ '; $text = preg_replace($reg,$rp,$text); + //解析外部友链 + $reg = '/\[links data="(.*?)"\]/s'; + $dataLink = preg_replace($reg,'${1}',$text); + $data = file_get_contents($dataLink); + $data = json_decode($data, true); + $linkItemNum = count($data); + for ($i = 0; $i < $linkItemNum; $i++) { + $name = $data[$i]['name']; + $link = $data[$i]['link']; + $avatar = $data[$i]['avatar']; + $des = $data[$i]['des']; + //嵌入列表 + $linksList .= ''; + } + $text=preg_replace($reg,'',$text); + return $text; } @@ -132,28 +158,6 @@ class Contents return ''; } - /** - * 解析自定义导航栏 - */ - static public function paresNav($data, $type) { - $de_json = json_decode($data, true); - $count_json = count($de_json); - for ($i = 0; $i < $count_json; $i++) { - $title = $de_json[$i]['title']; - $link = $de_json[$i]['link']; - //输出导航 - if($type="top-nav") { - echo ''. $title .''; - } - elseif($type="mobile") { - echo '
'. $title .'
'; - } - elseif($type="drawer") { - echo ''. $title .''; - } - } - } - /** * 解析代码块 */ @@ -161,9 +165,7 @@ class Contents $text = preg_replace('/
/s','
',$text);
 		return $text;
 	}
-	
-	//从这里开始的代码来自 熊猫小A (https://imalan.cn)
-	 
+
 	/**
 	 *  解析章节链接
 	 */ 
@@ -185,6 +187,29 @@ class Contents
         return ''.$matchs[3].'';
     }
 	
+
+	/**
+	 * 解析自定义导航栏
+	 */
+	static public function paresNav($data, $type) {
+		$de_json = json_decode($data, true);
+		$count_json = count($de_json);
+        for ($i = 0; $i < $count_json; $i++) {
+            $title = $de_json[$i]['title'];
+            $link = $de_json[$i]['link'];
+			//输出导航
+			if($type="top-nav") {
+			    echo ''. $title .'';
+			}
+			elseif($type="mobile") {
+				echo '';
+			}
+			elseif($type="drawer") {
+				echo ''. $title .'';
+			}
+        }
+	}
+	
 	/**
      * 根据 id 返回对应的对象
      * 此方法在 Typecho 1.2 以上可以直接调用 Helper::widgetById();
-- 
cgit v1.2.3