dever il y a 6 ans
Parent
commit
3e93357a29
2 fichiers modifiés avec 13 ajouts et 9 suppressions
  1. 11 7
      content/lib/Article.php
  2. 2 2
      doc/apidoc.php

+ 11 - 7
content/lib/Article.php

@@ -40,13 +40,17 @@ class Article
             $data['content'] = str_replace('"="', '', $data['content']);
         }
 
+        $content = $data['content'];
+        $replace = array();
         if (strstr($data['content'], 'embed')) {
             //print_r($data['content']);die;
             # 音频
-            preg_match_all('/<embed src="(.*?)"(.*?)\/>/i', $data['content'], $matches);
-            if (isset($matches[1])) {
-                foreach ($matches[1] as $k => $v) {
+            preg_match_all('/<p(.*?)>([\s]+)<embed src="(.*?)"(.*?)\/>([\s]+)<\/p>/i', $data['content'], $matches);
+            if (isset($matches[3])) {
+                foreach ($matches[3] as $k => $v) {
+                    $content = str_replace($matches[0][$k], '{replace}'.count($replace).'{replace}', $content);
 
+                    $replace[] = array('type' => 5, 'content' => $v);
                 }
             }
         }
@@ -54,11 +58,11 @@ class Article
         if (strstr($data['content'], 'data-id')) {
             # 视频
             preg_match_all('/<p(.*?)>([\s]+)<img(.*?)data-id="(.*?)" data-key="(.*?)" \/>([\s]+)<\/p>/', $data['content'], $matches);
-            $replace = array();
-            $content = $data['content'];
+            
+            
             if (isset($matches[4][0]) && isset($matches[5][0])) {
                 foreach ($matches[4] as $k => $v) {
-                    $content = str_replace($matches[0][$k], '{replace}'.$k.'{replace}', $content);
+                    $content = str_replace($matches[0][$k], '{replace}'.count($replace).'{replace}', $content);
                     if ($matches[5][$k] == 'video/lib/core.vod') {
                         $method = 'video/lib/vod';
                         $type = 2;
@@ -71,7 +75,7 @@ class Article
                     if (isset($info['content'])) {
                         unset($info['content']);
                     }
-                    $replace[$k] = array('id' => $v, 'type' => $type, 'content' => $info);
+                    $replace[] = array('id' => $v, 'type' => $type, 'content' => $info);
                 }
             }
 

+ 2 - 2
doc/apidoc.php

@@ -33,7 +33,7 @@
  * @apiDescription 类型设置说明
  *
  * @apiParam {String} source_type 请在header中定义,ios:ios | android:android | 移动h5:h5  | 小程序:applet | 公众号:service | pc网站:pc
- * @apiParam {Number} type 图文:1 | 视频:2 | 直播:3 | 小刊:4 | 链接:10 | 评论: 11
+ * @apiParam {Number} type 图文:1 | 视频:2 | 直播:3 | 小刊:4 | 音频:5 | 链接:10 | 评论: 11
  * @apiParam {Number} push_ 所有带push_开头的返回参数,返回字典都是一样的,参考获取首页数据中的push_focus
  */
 
@@ -395,7 +395,7 @@
  * @apiSuccess {String}   info.share_content 分享内容
  * @apiSuccess {String}   info.function 开启的功能,这是一个字符串,用逗号隔开的,1代表显示浏览量,2代表显示评论,3代表显示喜欢,如值为1,2,则显示浏览量、评论,不显示喜欢
  * @apiSuccess {String}   info.content 内容
- * @apiSuccess {String}   info.content_array 数组内容,请使用该字段循环
+ * @apiSuccess {String}   info.content_array 数组内容,请使用该字段循环,type为类型,请参考类型设置说明,content为内容,type为1时为图文内容,type为2时content为视频详情的字段,type为3时content为直播详情的字段,type为5时content为音频地址
  *
  * @apiSuccess {Object[]} comment 评论列表
  * @apiSuccess {String}   comment.id