dever 4 years ago
parent
commit
0d72e3b0f6

+ 203 - 2
app/collection/lib/Content.php

@@ -18,20 +18,221 @@ class Content
 			}
 		}
 
-		print_r($data);die;
+		return $data;
 	}
 
 	public function getOne($data)
 	{
 		$type = Dever::db('collection/cate')->config['gettype'];
 		$table = $type[$data['type']]['table'];
+		if (!$table) {
+			return $data;
+		}
+
+		$method = 'one';
+		if (strstr($table, '-')) {
+			$temp = explode('-', $table);
+			$table = $temp[0];
+			$method = $temp[1];
+		}
+
+		$data['data'] = Dever::db($table)->$method(array('content_id' => $data['id'], 'info_id' => $data['info_id']));
 
-		$data['data'] = Dever::db($table)->one(array('content_id' => $data['id'], 'info_id' => $data['info_id']));
+		$data['data']['num_view'] = 1;
+
+		$data['data']['date'] = '';
+		if (isset($data['data']['cdate'])) {
+			$data['data']['date'] = date('Y-m-d H:i:s', $data['data']['cdate']);
+		}
 
 		if (isset($data['data']['text'])) {
 			$data['data']['text'] = Dever::array_decode($data['data']['text']);
+
+			foreach ($data['data']['text'] as $k => $v) {
+				if (isset($v['content']) && $v['content']) {
+					$data['data']['text'][$k]['content_array'] = $this->getContent($v);
+				}
+			}
+		}
+
+		if (isset($data['data']['author_id']) && $data['data']['author_id'] > 0) {
+			$data['data']['author'] = Dever::db('store/author')->one($data['data']['author_id']);
+		}
+
+		if (isset($data['data']['content']) && $data['data']['content']) {
+			$data['data'] = $this->getContent($data['data']);
 		}
 
 		return $data;
 	}
+
+	public function getContent($data, $uid = false)
+    {
+        //embed
+        $data['content_array'] = array();
+
+        $data['content'] = Dever::filter($data['content']);
+
+        $content = $data['content'];
+        $replace = array();
+
+        # 小程序
+        if (strstr($data['content'], 'data-applet')) {
+            preg_match_all('/<img(.*?)data-applet="(.*?)" \/>/', $content, $matches);
+
+            if (isset($matches[2])) {
+                foreach ($matches[2] as $k => $v) {
+                    $content = str_replace($matches[0][$k], '{replace}'.count($replace).'{replace}', $content);
+                    $temp = explode('||', $v);
+                    $pic = $temp[0];
+                    $appid = $temp[1];
+                    $path = $temp[2];
+
+                    if ($appid) {
+                        $appinfo = Dever::db('content/applet')->one(array('appid' => $appid));
+                    } else {
+                        $appinfo['name'] = '';
+                        $appinfo['link'] = '';
+                    }
+                    
+                    if (isset($temp[3]) && $temp[3]) {
+                        $appinfo['link'] = $temp[3];
+                    }
+
+                    $replace[] = array('type' => 'applet', 'pic_cover' => $pic, 'appid' => $appid, 'path' => $path, 'name' => $appinfo['name'], 'link' => $appinfo['link']);
+                }
+            }
+        }
+
+        # 图片
+        if (strstr($data['content'], '<img')) {
+            preg_match_all('/<img(.*?)src="(.*?)" (.*?)\/>/', $content, $matches);
+
+            if (isset($matches[2])) {
+                foreach ($matches[2] as $k => $v) {
+                    $content = str_replace($matches[0][$k], '{replace}'.count($replace).'{replace}', $content);
+                    $pic = $v;
+
+                    $replace[] = array('type' => 'pic', 'content' => $pic);
+                }
+            }
+        }
+
+        # 音视频
+        if (strstr($data['content'], 'data-file')) {
+            preg_match_all('/<img src="(.*?)" style="(.*?)" data-file="(.*?)" \/>/', $content, $matches);
+
+            if (!isset($matches[1][0])) {
+                preg_match_all('/<img style="(.*?)" src="(.*?)" data-file="(.*?)" \/>/', $content, $matches);
+                $temp = array();
+                if (isset($matches[2][0])) {
+                    $temp = $matches;
+                    $matches[1] = $temp[2];
+                    unset($temp);
+                }
+            }
+
+            if (isset($matches[1])) {
+                foreach ($matches[1] as $k => $v) {
+                    if (isset($matches[3][$k])) {
+                        $content = str_replace($matches[0][$k], '{replace}'.count($replace).'{replace}', $content);
+
+                        $file = $matches[3][$k];
+                        $temp = explode('||', $file);
+                        $file = $temp[0];
+                        if (isset($temp[1])) {
+                            $name = $temp[1];
+                        } else {
+                            $name = '';
+                        }
+                        
+                        $cover = $v;
+
+                        if (strstr($v, '.mp4') || strstr($v, '.mov') || strstr($v, '.m3u8')) {
+                            $replace[] = array('type' => 'video', 'content' => $file, 'cover' => $cover, 'name' => $name);
+                        } else {
+                            $replace[] = array('type' => 'audio', 'content' => $file, 'cover' => $cover, 'name' => $name);
+                        }
+                    }
+                }
+            }
+        }
+
+        # 视频+直播
+        if (strstr($data['content'], 'data-id')) {
+            preg_match_all('/<img(.*?)data-id="(.*?)" data-key="(.*?)" \/>/', $content, $matches);
+            
+            
+            if (!isset($matches[2][0])) {
+                preg_match_all('/<img(.*?)data-key="(.*?)" data-id="(.*?)" \/>/', $content, $matches);
+                $temp = array();
+                if (isset($matches[2][0]) && isset($matches[3][0])) {
+                    $temp = $matches;
+                    $matches[2] = $temp[3];
+                    $matches[3] = $temp[2];
+                    unset($temp);
+                }
+            }
+            
+            if (isset($matches[2][0]) && isset($matches[3][0])) {
+                foreach ($matches[2] as $k => $v) {
+                    $content = str_replace($matches[0][$k], '{replace}'.count($replace).'{replace}', $content);
+                    if ($matches[3][$k] == 'video/lib/core.vod') {
+                        $method = 'video/lib/vod';
+                        $type = 'video';
+                    } else {
+                        $type = 'live';
+                        $method = 'video/lib/live';
+                    }
+
+                    $info = Dever::load($method)->get($v);
+                    if (isset($info['content'])) {
+                        unset($info['content']);
+                    }
+
+                    if ($type == 3) {
+                        # 查看是否有预约
+                        if ($uid > 0) {
+                            $info['user_act']['note'] = Dever::load('act/lib/note')->get($uid, $v, $type);
+                        } else {
+                            $info['user_act']['note'] = 2;
+                        }
+                    }
+                    $replace[] = array('id' => $v, 'type' => $type, 'content' => $info);
+                }
+            }
+        }
+
+        //$data['content'] = preg_replace('/<div class="dever-drop">([\s\S]*?)<\/div>/i', '', $data['content']);
+
+        $content = explode('{replace}', $content);
+        $data['content_array'] = array();
+        //print_r($content);die;
+        foreach ($content as $k => $v) {
+            $v = trim($v);
+            if (is_numeric($v) && $v >= 0 && isset($replace[$v])) {
+                $data['content_array'][] = $replace[$v];
+            } elseif ($v) {
+                $data['content_array'][] = array
+                (
+                    'type' => 'html',
+                    'content' => $v,
+                );
+            }
+        }
+
+        if (!$data['content_array']) {
+            $data['content_array'][] = array
+            (
+                'type' => 'html',
+                'content' => $data['content'],
+            );
+        }
+
+        unset($data['content']);
+
+        //print_r($data['content_array']);die;
+
+        return $data;
+    }
 }

+ 1 - 1
app/collection/src/Api.php

@@ -26,7 +26,7 @@ class Api
     public function getContent()
     {
         $id = Dever::input('id');
-        $data = Dever::load('collection/lib/content')->getList($id);
+        $data['items'] = Dever::load('collection/lib/content')->getList($id);
 
         return $data;
     }

+ 24 - 0
app/content/database/news.php

@@ -2,6 +2,17 @@
 
 $status = Dever::config('base')->status;
 
+$author = function()
+{
+	$array = array();
+	$info = Dever::db('store/author')->state();
+	if($info)
+	{
+		$array += $info;
+	}
+	return $array;
+};
+
 return array
 (
 	# 表名
@@ -70,6 +81,19 @@ return array
 			'update'	=> 'textarea',
 		),
 
+		'author_id'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '作者',
+			'default' 	=> '1',
+			'desc' 		=> '作者',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'select',
+			//'option'	=> $author,
+			'search'	=> 'select',
+			'update_search'	=> 'store/lib/author.search',
+		),
+
   		'pic'		=> array
 		(
 			'type' 		=> 'varchar-150',

+ 132 - 0
app/store/database/author.php

@@ -0,0 +1,132 @@
+<?php
+
+return array
+(
+	# 表名
+	'name' => 'author',
+	# 显示给用户看的名称
+	'lang' => '作者管理',
+	# 后台菜单排序
+	'order' => 1,
+	# 数据结构
+	'struct' => array
+	(
+		'id' 		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> 'ID',
+			'default' 	=> '',
+			'desc' 		=> '',
+			'match' 	=> 'is_numeric',
+			'search'	=> 'order',
+			'list'		=> true,
+			'order'		=> 'desc',
+		),
+		
+		'name'		=> array
+		(
+			'type' 		=> 'varchar-32',
+			'name' 		=> '作者名称-长度不能超过16个字',
+			'default' 	=> '',
+			'desc' 		=> '请输入作者名称,长度不能超过16个字',
+			'match' 	=> Dever::rule('name', '/u', '1,16'),
+			'update'	=> 'text',
+			'search'	=> 'fulltext',
+			'list'		=> true,
+		),
+
+		'avatar'		=> array
+		(
+			'type' 		=> 'varchar-150',
+			'name' 		=> '头像-图片尺寸380*380px或等比尺寸,上传大小不能超过2M,支持JPG、PNG、GIF格式,建议上传JPG格式',
+			'default' 	=> '',
+			'desc' 		=> '头像',
+			'match' 	=> 'is_string',
+			'update'	=> 'image',
+			'key' 		=> '1',
+			'place'		=> '380',
+		),
+		
+		'reorder'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '排序(数值越大越靠前)',
+			'default' 	=> '1',
+			'desc' 		=> '请输入排序',
+			'match' 	=> 'option',
+			'update'	=> 'text',
+			'search'	=> 'order',
+			'list'		=> true,
+			'order'		=> 'desc',
+			'edit'		=> true,
+		),
+
+		'state'		=> array
+		(
+			'type' 		=> 'tinyint-1',
+			'name' 		=> '状态',
+			'default' 	=> '1',
+			'desc' 		=> '请选择状态',
+			'match' 	=> 'is_numeric',
+		),
+		
+		'cdate'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '录入时间',
+			'match' 	=> array('is_numeric', time()),
+			'desc' 		=> '',
+			# 只有insert时才生效
+			'insert'	=> true,
+			'list'		=> 'date("Y-m-d H:i:s", {cdate})',
+		),
+	),
+
+	# 默认值
+	'default' => array
+	(
+		'col' => 'name,state,cdate',
+		'value' => array
+		(
+			'"默认作者",1,' . time(),
+		),
+	),
+
+	'manage' => array
+	(
+		/*
+		'insert' => false,
+		'edit' => false,
+
+		# 自定义快捷新增和编辑
+		'button' => array
+		(
+			'新增' => array('fast'),
+		),
+		# 快捷更新
+		'list_button' => array
+		(
+			'edit' => array('编辑'),
+		),
+		*/
+	),
+
+	'request' => array
+	(
+		'getAll' => array
+		(
+			# 匹配的正则或函数 选填项
+			'option' => array
+			(
+				'ids' => array('yes-id', 'in'),
+				'name' => array('yes', 'like'),
+				'id' => 'yes',
+				'state' => 1,
+			),
+			'type' => 'all',
+			'order' => array('reorder' => 'desc', 'id' => 'desc'),
+			'limit' => '0,1000',
+			'col' => 'name as name, id, id as value, "" as selected, "" as disabled|id',
+		),
+	),
+);

+ 8 - 0
app/store/index.php

@@ -0,0 +1,8 @@
+<?php
+
+define('DEVER_APP_NAME', 'store');
+define('DEVER_APP_LANG', '库管理');
+define('DEVER_APP_PATH', dirname(__FILE__) . DIRECTORY_SEPARATOR);
+define('DEVER_MANAGE_ORDER', 300);
+define('DEVER_MANAGE_ICON', 'glyphicon glyphicon-tower layui-icon-tabs');
+include(DEVER_APP_PATH . '../boot.php');

+ 76 - 0
app/store/lib/Author.php

@@ -0,0 +1,76 @@
+<?php
+
+namespace Store\Lib;
+
+use Dever;
+
+class Author
+{
+    # 更新数据
+    public function data($id, $name, $data)
+    {
+        $source_table = Dever::input('source_table');
+
+        $author = Dever::param('author_id', $data);
+
+        if ($author && $id > 0 && $source_table) {
+            $info = Dever::db('store/author')->one($author);
+            if (!$info) {
+                $insert['name'] = $author;
+                $author = Dever::db('store/author')->insert($insert);
+            }
+
+            Dever::db($source_table)->update(array('where_id' => $id, 'author_id' => $author));
+        }
+    }
+
+    # 搜索
+    public function search_api()
+    {
+        $keyword = Dever::input('keyword');
+
+        $yes = Dever::input('yes');
+
+        $where = array();
+
+        if ($yes) {
+            $yes = Dever::db('store/author')->getAll(array('ids' => $yes));
+        }
+        if (!$keyword) {
+            $where['limit'] = '0,50';
+            $data = Dever::db('store/author')->getAll($where);
+        } else {
+            $where['name'] = $keyword;
+            $data = Dever::db('store/author')->getAll($where);
+        }
+
+        $insert = array();
+        if (!$data && $keyword) {
+            $insert[0]['name'] = $keyword . '[新增]';
+            $insert[0]['value'] = $keyword;
+        }
+
+        $result = array();
+        if ($yes) {
+            foreach ($yes as $k => $v) {
+                if (isset($data[$k])) {
+                    unset($data[$k]);
+                }
+                $yes[$k]['selected'] = 'selected';
+            }
+            $data = $insert + $yes + $data;
+
+            $data = array_merge($data, array());
+        } else {
+            $data = $insert + $data;
+
+            $data = array_merge($data, array());
+        }
+
+        if (!$data) {
+            Dever::alert('暂无数据');
+        }
+
+        return $data;
+    }
+}