dever 3 anni fa
commit
1f9a81602c
8 ha cambiato i file con 1090 aggiunte e 0 eliminazioni
  1. 118 0
      database/author.php
  2. 114 0
      database/cate.php
  3. 443 0
      database/info.php
  4. 8 0
      index.php
  5. 210 0
      lib/Article.php
  6. 76 0
      lib/Author.php
  7. 60 0
      lib/Manage.php
  8. 61 0
      src/Api.php

+ 118 - 0
database/author.php

@@ -0,0 +1,118 @@
+<?php
+
+return array
+(
+	# 表名
+	'name' => 'author',
+	# 显示给用户看的名称
+	'lang' => '作者管理',
+	# 后台菜单排序
+	'order' => 8,
+	# 数据结构
+	'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,
+		),
+		
+		'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',
+		),
+	),
+);

+ 114 - 0
database/cate.php

@@ -0,0 +1,114 @@
+<?php
+
+return array
+(
+    # 表名
+    'name' => 'cate',
+    # 显示给用户看的名称
+    'lang' => '栏目设置',
+    # 后台菜单排序
+    'order' => 9,
+    # 数据结构
+    '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'      => '栏目名称',
+            'default'   => '',
+            'desc'      => '请输入名称',
+            'match'     => 'is_string',
+            'update'    => 'text',
+            'search'    => 'fulltext',
+            'list'      => true,
+        ),
+        
+        '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,reorder,cdate',
+        'value' => array
+        (
+            '"默认栏目",100,' . time(),
+        ),
+    ),
+
+    'manage' => array
+    (
+        'insert' => false,
+        'edit' => false,
+
+        # 自定义快捷新增和编辑
+        'button' => array
+        (
+            '新增' => array('fast'),
+        ),
+        # 快捷更新
+        'list_button' => array
+        (
+            'edit' => array('编辑'),
+        ),
+    ),
+
+    'request' => array
+    (
+        'getAll' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'state' => 1,
+            ),
+            'type' => 'all',
+            'order' => array('reorder' => 'desc','id' => 'desc'),
+            'col' => '*',
+        ),
+    ),
+);

+ 443 - 0
database/info.php

@@ -0,0 +1,443 @@
+<?php
+
+$audit = Dever::config('base')->audit;
+
+$status = Dever::config('base')->status;
+
+# 每页的数据量
+$page = 10;
+
+$cate = function()
+{
+	$array = array();
+	$info = Dever::db('article/cate')->state();
+	if($info)
+	{
+		$array += $info;
+	}
+	return $array;
+};
+
+$author = function()
+{
+	$array = array();
+	$info = Dever::db('article/author')->state();
+	if($info)
+	{
+		$array += $info;
+	}
+	return $array;
+};
+
+$share = array
+(
+	1 => '显示',
+	2 => '不显示',
+);
+
+$template = array
+(
+	1 => '图文',
+	2 => '视频',
+);
+
+# 常用的col
+$col = 'id,cate_id,name,pic_cover,num_add_view+num_view as num_view,content,author_id,template,`desc`,video,cdate';
+
+return array
+(
+	# 表名
+	'name' => 'info',
+	# 显示给用户看的名称
+	'lang' => '文章管理',
+	'order' => 100,
+	'end' => array
+	(
+		'insert' => 'article/lib/author.data?source_table=article/info',
+		'update' => 'article/lib/author.data?source_table=article/info',
+	),
+
+	# 数据结构
+	'struct' => array
+	(
+		'id' 		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> 'ID',
+			'default' 	=> '',
+			'desc' 		=> '',
+			'match' 	=> 'is_numeric',
+			'list'		=> true,
+		),
+		
+		'name'		=> array
+		(
+			'type' 		=> 'varchar-80',
+			'name' 		=> '标题-文章标题,同时也用于分享标题',
+			'default' 	=> '',
+			'desc' 		=> '标题',
+			'match' 	=> 'is_string',
+			'update'	=> 'text',
+			'list'		=> true,
+			'search'	=> 'fulltext',
+			//增加预览
+			'preview'	=> true,
+		),
+
+		'desc'		=> array
+		(
+			'type' 		=> 'varchar-500',
+			'name' 		=> '摘要-文章摘要,同时也用于分享内容',
+			'default' 	=> '',
+			'desc' 		=> '摘要',
+			'match' 	=> 'is_string',
+			'update'	=> 'textarea',
+		),
+		
+		'cate_id'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '所属栏目',
+			'default' 	=> '1',
+			'desc' 		=> '所属栏目',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'select',
+			'option'	=> $cate,
+			'search'	=> 'select',
+			'list'		=> 'Dever::load("article/cate-one#name", {cate_id})',
+		),
+
+		'author_id'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '编辑',
+			'default' 	=> '1',
+			'desc' 		=> '编辑',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'select',
+			//'option'	=> $author,
+			'search'	=> 'select',
+			'update_search'	=> 'article/lib/author.search',
+		),
+
+  		'pic_cover'		=> array
+		(
+			'type' 		=> 'text-255',
+			'name' 		=> '封面图-可以上传多张,也可以不传,不传则自动从内容中获取',
+			'default' 	=> '',
+			'desc' 		=> '封面图',
+			'match' 	=> 'option',
+			'update'	=> 'images',
+			'key' 		=> '1',
+			'place'		=> '345*200',
+			//直接上传到云端
+			//'upload'	=> 'qiniu',
+			//上传大数据
+			//'large' 	=> true,
+		),
+
+		'template'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '文章模板',
+			'default' 	=> '1',
+			'desc' 		=> '文章模板',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'radio',
+			'option'	=> $template,
+			'search'	=> 'select',
+			'control'	=> 'template',
+		),
+
+		'video'		=> array
+		(
+			'type' 		=> 'varchar-800',
+			//'name' 		=> '上传视频-上传视频格式mp4,mov,上传大小不能超过4G,也可以直接填入腾讯视频的地址(如:https://v.qq.com/x/page/p0873p0efbx.html)或者mp4地址',
+			'name' 		=> '上传视频-上传视频格式mp4,mov,上传大小不能超过4G,也可以直接填入mp4地址',
+			'default' 	=> '',
+			'desc' 		=> '上传视频',
+			'match' 	=> 'is_string',
+			'update'	=> 'upload',
+			'key' 		=> '5',
+			'place'		=> '150',
+			'upload'	=> 'yun',
+			'large' 	=> true,
+			//不覆盖原文件,生成新文件
+			'cover'		=> 2,
+			'show'		=> 'template=2',
+		),
+
+		'video_info'		=> array
+		(
+			'type' 		=> 'text-255',
+			'name' 		=> '视频信息',
+			'default' 	=> '',
+			'desc' 		=> '视频信息',
+			'match' 	=> 'is_string',
+			'show'		=> 'template=2',
+		),
+
+		'num_add_view'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '浏览量基数',
+			'default' 	=> '0',
+			'desc' 		=> '浏览量基数',
+			'match' 	=> 'option',
+			//'update'	=> 'text',
+		),
+
+		'num_view'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '浏览量',
+			'default' 	=> '0',
+			'desc' 		=> '请填写浏览量',
+			'match' 	=> 'option',
+			'search'	=> 'order',
+			'list'		=> '{num_view}+{num_add_view}',
+		),
+
+		'pdate'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '发布时间',
+			'match' 	=> array('is_numeric', time()),
+			'default'	=> '',
+			'desc' 		=> '',
+			'update'	=> 'date',
+			'callback'	=> 'maketime',
+			'insert'	=> true,
+			//'list'		=> 'date("Y-m-d H:i:s", {pdate})',
+			'auth'		=> '"{pdate}" > 0',
+		),
+
+		'reorder'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '排序(数值越大越靠前)',
+			'default' 	=> '1',
+			'desc' 		=> '请输入排序',
+			'match' 	=> 'option',
+			'update'	=> 'text',
+			'search'	=> 'order',
+			'list'		=> true,
+			'order'		=> 'desc',
+			'edit'		=> true,
+		),
+
+		'udate'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '更新时间',
+			'match' 	=> array('is_numeric', time()),
+			'desc' 		=> '',
+		),
+
+		'content'		=> array
+		(
+			'type' 		=> 'text-255',
+			'name' 		=> '内容',
+			'default' 	=> '',
+			'desc' 		=> '请输入内容',
+			'match' 	=> 'is_string',
+			'update'	=> 'editor',
+			'key'		=> '1',
+			//'media'		=> '5',//下面的音视频已经做到了
+			//直接上传到云端
+			//'upload'	=> 'qiniu',
+			//上传大数据
+			//'large' 	=> true,
+			//自定义编辑器右侧按钮
+			'editors'	=> array
+			(
+				'name' => '选择插入模块',
+				'button' => array
+				(
+					array
+					(
+						'name' => '视频',
+						'key' => 'article/lib/article.vod',
+					),
+				),
+			),
+		),
+
+		'status'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '发布状态',
+			'default' 	=> '1',
+			'desc' 		=> '发布状态',
+			'match' 	=> 'is_numeric',
+			//'update'	=> 'select',
+			'option'	=> $status,
+			'search'	=> 'select',
+			'list'		=> true,
+			'edit'		=> true,
+		),
+
+		'source_id'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '来源ID',
+			'default' 	=> '0',
+			'desc' 		=> '来源ID',
+			'match' 	=> 'is_numeric',
+		),
+
+		'state'		=> array
+		(
+			'type' 		=> 'tinyint-1',
+			'name' 		=> '状态',
+			'default' 	=> '1',
+			'desc' 		=> '请选择状态',
+			'match' 	=> 'is_numeric',
+		),
+
+		'admin_founder'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '创建人',
+			'default' 	=> '1',
+			'desc' 		=> '创建人',
+			'match' 	=> 'is_numeric',
+		),
+
+		'admin_editor'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '操作人',
+			'default' 	=> '1',
+			'desc' 		=> '操作人',
+			'match' 	=> 'is_numeric',
+		),
+
+		'cdate'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '录入时间',
+			'match' 	=> array('is_numeric', time()),
+			'desc' 		=> '',
+			# 只有insert时才生效
+			'insert'	=> true,
+		),
+	),
+
+	# 索引
+	'index' => array
+	(
+		'version' => 1,
+		
+		1 => array
+		(
+			'i1' => 'cate_id,reorder',
+		)
+	),
+	
+	# 管理功能
+	'manage' => array
+	(
+		//'insert' => false,
+		# 列表
+		'list_button' => array
+		(
+			//'edit' => array('预览', str_replace('https://api.', 'http://www.', Dever::url('main/preview.get?type=1'))),
+		),
+	),
+
+	# request 请求接口定义
+	'request' => array
+	(
+		'search' => array
+		(
+			# 匹配的正则或函数 选填项
+			'option' => array
+			(
+				'ids' => array('yes-id', 'in'),
+				'cate_id' => 'yes',
+				'name' => array('yes', 'like'),
+				'id' => 'yes',
+				'state' => 1,
+			),
+			'type' => 'all',
+			'order' => array('reorder' => 'desc', 'pdate' => 'desc'),
+			'limit' => '0,1000',
+			'col' => 'name as name, id, id as value, "" as selected, "" as disabled|id',
+		),
+
+		'getAll' => array
+		(
+			# 匹配的正则或函数 选填项
+			'option' => array
+			(
+				'cate_id' => 'yes',
+				'cate_ids' => array('yes-cate_id', 'in'),
+				'id' => 'yes',
+				'status' => 1,
+				'state' => 1,
+			),
+			'type' => 'all',
+			'order' => array('reorder' => 'desc','pdate' => 'desc'),
+			'page' => array($page, 'list'),
+			'col' => $col,
+		),
+
+		'getList' => array
+		(
+			# 匹配的正则或函数 选填项
+			'option' => array
+			(
+				'cate_id' => 'yes',
+				'status' => 1,
+				'state' => 1,
+			),
+			'type' => 'all',
+			'order' => array('reorder' => 'desc','pdate' => 'desc'),
+			'limit' => '0,10',
+			'col' => $col,
+		),
+
+		'getRelation' => array
+		(
+			# 匹配的正则或函数 选填项
+			'option' => array
+			(
+				'cate_id' => 'yes',
+				'cate_ids' => array('yes-cate_id', 'in'),
+				'noid' => array('yes-id', '!='),
+				'status' => 1,
+				'state' => 1,
+			),
+			'type' => 'all',
+			'order' => array('reorder' => 'desc','pdate' => 'desc'),
+			'limit' => '0,2',
+			'col' => $col,
+		),
+
+		'getOne' => array
+		(
+			# 匹配的正则或函数 选填项
+			'where' => array
+			(
+				'id' => 'yes',
+			),
+			'type' => 'one',
+			'col' => $col,
+		),
+		
+		# 更新浏览量
+		'addView' => array
+		(
+			'type' => 'update',
+			'where' => array
+			(
+				'id' => 'yes',
+			),
+			'set' => array
+			(
+				'num_view' => array('1', '+='),
+			),
+		),
+	),
+);

+ 8 - 0
index.php

@@ -0,0 +1,8 @@
+<?php
+
+define('DEVER_APP_NAME', 'article');
+define('DEVER_APP_LANG', '文章系统');
+define('DEVER_APP_PATH', dirname(__FILE__) . DIRECTORY_SEPARATOR);
+define('DEVER_MANAGE_ORDER', 98);
+define('DEVER_MANAGE_ICON', 'glyphicon glyphicon-tower layui-icon-form');
+include(DEVER_APP_PATH . '../boot.php');

+ 210 - 0
lib/Article.php

@@ -0,0 +1,210 @@
+<?php
+
+namespace Article\Lib;
+
+use Dever;
+
+class Article
+{
+    # 同步信息接口
+    public function up_api()
+    {
+        $name = Dever::input('name');
+        $desc = Dever::input('desc');
+        $pic_cover = Dever::input('pic_cover');
+        $pic_index = Dever::input('pic_index');
+        $content = Dever::input('content');
+        $template = Dever::input('template');
+        if ($template == 2) {
+            $video = Dever::input('video');
+        }
+        $cate_id = Dever::input('cate_id');
+        $cate_id = $this->getCate($cate_id);
+        $pdate = Dever::input('pdate');
+        $source_id = Dever::input('source_id');
+
+        $update['template'] = $template;
+        $update['source_id'] = $source_id;
+        $info = Dever::db('article/info')->one($update);
+
+        //$parse = $this->parseContent($content);
+        //print_r($parse);die;
+        if ($content) {
+            $content = Dever::json_decode($content);
+            $content = $this->getContentHtml($content);
+        }
+
+        $update['name'] = $name;
+        $update['desc'] = $desc;
+        $update['pic_cover'] = $pic_cover;
+        $update['pic_index'] = $pic_index;
+        $update['content'] = $content;
+        $update['cate_id'] = $cate_id;
+        if (isset($video) && $video) {
+            $update['video'] = $video;
+        }
+
+        if (!$info) {
+            $update['pdate'] = $pdate;
+            Dever::db('article/info')->insert($update);
+        } else {
+            $update['where_id'] = $info['id'];
+            Dever::db('article/info')->update($update);
+        }
+
+        return 'ok';
+    }
+
+    public function getCate($id)
+    {
+        $config = array
+        (
+            1 => 6,
+            2 => 4,
+            3 => 1,
+            4 => 2,
+            5 => 3,
+            6 => 6,
+            7 => 6,
+            9 => 5,
+            12 => 6,
+        );
+
+        if (isset($config[$id])) {
+            return $config[$id];
+        }
+        return $id;
+    }
+
+    public function vod_api()
+    {
+        $data['name'] = '视频';
+        $where = array();
+        $name = Dever::input('search_name');
+        $cate = Dever::input('search_cate');
+        if ($name) {
+            $where['name'] = $name;
+        }
+        if ($cate > 0) {
+            $where['cate_id'] = $cate;
+        }
+        $where['template'] = 2;
+        $data['file'] = Dever::db('article/info')->list($where);
+        $data['cate'] = Dever::db('article/cate')->state();
+
+
+        if ($data['file']) {
+            foreach ($data['file'] as $k => $v) {
+                $data['file'][$k]['source_name'] = $v['name'];
+                $data['file'][$k]['file'] = $v['pic_cover'];
+                $data['file'][$k]['pic'] = $v['pic_cover'];
+            }
+        }
+
+        return $data;
+    }
+
+    public function vod_info($id)
+    {
+        $data = Dever::db('article/info')->one($id);
+
+        return $data;
+    }
+
+    # 根据文章id 获取文章信息
+    public function get($data, $uid = false)
+    {
+        if (!is_array($data)) {
+            $data = Dever::db('article/info')->one($data);
+        }
+        
+        if (!$data) {
+            Dever::alert('错误的文章信息');
+        }
+
+        if ($data['author_id']) {
+            $data['author'] = Dever::db('article/author')->one($data['author_id']);
+        }
+    
+        $data = $this->getContent($data, $uid);
+
+        return $data;
+    }
+
+    public function getContent($data, $uid = false)
+    {
+        //embed
+        $data['content_array'] = $data['content_pic'] = array();
+
+        $data['content'] = Dever::filter($data['content']);
+
+        $content = $data['content'];
+        $replace = array();
+
+        # 过滤宽度
+        if (strstr($data['content'], 'width:')) {
+            $content = preg_replace('/width:(.*?)px/', 'width:100%', $content);
+        }
+
+        # 图片
+        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);
+                    $data['content_pic'][] = $pic;
+                }
+            }
+        }
+
+        //$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;
+    }
+
+    # 获取相关推荐
+    public function getRelation($info)
+    {
+        $where['noid'] = $info['id'];
+        $where['cate_id'] = $info['cate_id'];
+        return Dever::db('article/info')->getRelation($where);
+    }
+
+    # 增加浏览量
+    public function addView($id)
+    {
+        Dever::db('article/info')->addView($id);
+    }
+}

+ 76 - 0
lib/Author.php

@@ -0,0 +1,76 @@
+<?php
+
+namespace Article\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('article/author')->one($author);
+            if (!$info) {
+                $insert['name'] = $author;
+                $author = Dever::db('article/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('article/author')->getAll(array('ids' => $yes));
+        }
+        if (!$keyword) {
+            $where['limit'] = '0,50';
+            $data = Dever::db('article/author')->getAll($where);
+        } else {
+            $where['name'] = $keyword;
+            $data = Dever::db('article/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;
+    }
+}

+ 60 - 0
lib/Manage.php

@@ -0,0 +1,60 @@
+<?php
+
+namespace Article\Lib;
+
+use Dever;
+
+class Manage
+{
+    private function search($table = 'article/info')
+    {
+        $keyword = Dever::input('keyword');
+
+        $yes = Dever::input('yes');
+
+        $where = array();
+
+        $cate = Dever::input('cate');
+        if ($cate) {
+            $where['cate_id'] = $cate;
+        }
+
+        if ($yes) {
+            $yes = Dever::db($table)->search(array('ids' => $yes));
+        }
+        if (!$keyword) {
+            $where['limit'] = '0,50';
+            $data = Dever::db($table)->search($where);
+        } else {
+            $where['name'] = $keyword;
+            $data = Dever::db($table)->search($where);
+        }
+
+        $result = array();
+        if ($yes) {
+            foreach ($yes as $k => $v) {
+                if (isset($data[$k])) {
+                    unset($data[$k]);
+                }
+                $yes[$k]['selected'] = 'selected';
+            }
+            $data = $yes + $data;
+
+            $data = array_merge($data, array());
+        } else {
+            $data = array_merge($data, array());
+        }
+
+        if (!$data) {
+            Dever::alert('暂无数据');
+        }
+
+        return $data;
+    }
+
+    # 搜索文章
+    public function search_article_api()
+    {
+        return $this->search('article/info');
+    }
+}

+ 61 - 0
src/Api.php

@@ -0,0 +1,61 @@
+<?php
+
+namespace Article\Src;
+
+use Dever;
+
+class Api
+{
+    # 获取栏目
+    public function cate()
+    {
+        $data['cate'] = Dever::db('article/cate')->getAll();
+
+        return $data;
+    }
+
+    # 获取栏目下的文章列表
+    public function getList()
+    {
+        $where['cate_id'] = Dever::input('cate');
+        if (!$where['cate_id']) {
+            $cate = $this->cate();
+            $where['cate_id'] = $cate[0];
+        }
+        $info = Dever::db('article/info')->getAll($where);
+
+        $data['info'] = array();
+        if ($info) {
+            foreach ($info as $k => $v) {
+                $v = Dever::load('article/lib/article')->get($v);
+                if ($v['pic_cover']) {
+                    $v['content_pic'] = explode(',', $v['pic_cover']);
+                }
+
+                $data['info'][] = array
+                (
+                    'id' => $v['id'],
+                    'title' => $v['name'],
+                    'author' => $v['author']['name'],
+                    'createTime' => Dever::mdate($v['cdate']),
+                    'imgs' => $v['content_pic'],
+                    'views' => $v['num_view'],
+                );
+            }
+        }
+
+        return $data;
+    }
+
+    # 获取文章详情
+    public function getInfo()
+    {
+        $id = Dever::input('id');
+        $data = Dever::load('article/lib/article')->get($id);
+
+        if ($data) {
+            Dever::db('article/info')->addView(array('where_id' => $id));
+        }
+        return $data;
+    }
+}