dever 4 years ago
parent
commit
1f635fa5b6
2 changed files with 43 additions and 24 deletions
  1. 34 0
      app/collection/lib/Core.php
  2. 9 24
      app/collection/src/Api.php

+ 34 - 0
app/collection/lib/Core.php

@@ -287,4 +287,38 @@ class Core
 
         return $button;
     }
+
+    # 获取其他页面的分享
+    protected function getConfigShare($config = array())
+    {
+        $config = $config ? $config : Dever::db('main/config')->one();
+        $config['desc'] = $config['info'];
+        $config['pic_cover'] = $config['logo'];
+        return $this->getInfoShare($config);
+    }
+
+    # 获取合集的分享
+    protected function getInfoShare($info, $code = false)
+    {
+        if ($this->uid && $this->uid > 0) {
+            $data['title'] = $info['share_title'] ? $info['share_title'] : '{username}邀请你看{name}';
+
+            $data['title'] = str_replace('{username}', $this->user['username'], $data['title']);
+            $data['title'] = str_replace('{name}', $info['name'], $data['title']);
+        } else {
+            $data['title'] = $info['name'];
+        }
+
+        $data['content'] = $info['share_content'] ? $info['share_content'] : $info['desc'];
+
+        $data['pic'] = $info['share_pic'] ? $info['share_pic'] : $info['pic_cover'];
+
+        $url = Dever::input('url');
+
+        $url = $this->getUrl($url);
+
+        $data['link'] = $url;
+
+        return $data;
+    }
 }

+ 9 - 24
app/collection/src/Api.php

@@ -60,6 +60,9 @@ class Api extends Core
         # 宣传栏推送位
         $data['xuanchuan'] = Dever::load('push/lib/data')->get('xuanchuan', '首页宣传栏', 3);
 
+        # 获取分享信息
+        $data['share'] = $this->getConfigShare($data['config']);
+
         return $data;
     }
 
@@ -97,6 +100,9 @@ class Api extends Core
             $data['focus'] = Dever::load('push/lib/data')->get('focus', '阅览焦点图', 5);
         }
 
+        # 获取分享信息
+        $data['share'] = $this->getConfigShare();
+
         return $data;
     }
 
@@ -283,30 +289,6 @@ class Api extends Core
         return $data;
     }
 
-    private function getInfoShare($info, $code = false)
-    {
-        if ($this->uid && $this->uid > 0) {
-            $data['title'] = $info['share_title'] ? $info['share_title'] : '{username}邀请你看{name}';
-
-            $data['title'] = str_replace('{username}', $this->user['username'], $data['title']);
-            $data['title'] = str_replace('{name}', $info['name'], $data['title']);
-        } else {
-            $data['title'] = $info['name'];
-        }
-
-        $data['content'] = $info['share_content'] ? $info['share_content'] : $info['desc'];
-
-        $data['pic'] = $info['share_pic'] ? $info['share_pic'] : $info['pic_cover'];
-
-        $url = Dever::input('url');
-
-        $url = $this->getUrl($url);
-
-        $data['link'] = $url;
-
-        return $data;
-    }
-
     # 获取合集下的内容
     public function getContent()
     {
@@ -339,6 +321,9 @@ class Api extends Core
 
         # 更新阅读数
         Dever::db('collection/info')->addView(array('where_id' => $this->id));
+
+        # 获取合集分享信息
+        $data['share'] = $this->getInfoShare($data['info']);
         
         return $data;
     }