rabin 7 سال پیش
کامیت
474779bd50
9فایلهای تغییر یافته به همراه1049 افزوده شده و 0 حذف شده
  1. 14 0
      LICENSE
  2. 2 0
      README.md
  3. 213 0
      database/data.php
  4. 330 0
      database/info.php
  5. 176 0
      database/page.php
  6. 7 0
      index.php
  7. 185 0
      src/Api.php
  8. 24 0
      src/Demo.php
  9. 98 0
      src/Sql.php

+ 14 - 0
LICENSE

@@ -0,0 +1,14 @@
+Apache License
+Copyright 2016-2017 Dever(dever.cc)
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.

+ 2 - 0
README.md

@@ -0,0 +1,2 @@
+# module
+

+ 213 - 0
database/data.php

@@ -0,0 +1,213 @@
+<?php
+
+# 定义几个常用的选项
+$option = array
+(
+	1 => '显示',
+	2 => '不显示',
+);
+
+$type = array(0 => '默认类型');
+
+$info = Dever::input('search_option_info_id');
+
+if ($info) {
+	$info = Dever::load('module/info-one', $info);
+
+	if (!$info) {
+		echo 'error';die;
+	}
+	$info['name'] .= '下的数据推送';
+	$info['col'] = explode(',', $info['col']);
+	$preview = $info['preview'];
+	$preview_height = $info['preview_height'] ? $info['preview_height'] : 500;
+
+	$name_state = in_array(1, $info['col']);
+	$link_state = in_array(2, $info['col']);
+	$pic_state = in_array(3, $info['col']);
+	$content_state = in_array(4, $info['col']);
+
+	if ($info['data_type']) {
+		$type = explode("\r\n", $info['data_type']);
+	}
+} else {
+	$info = array();
+	$info['name'] = '模块数据管理';
+	$info['col_pic'] = '100X100';
+	$info['col_content'] = '30';
+	$info['type'] = 1;
+	$name_state = false;
+	$link_state = false;
+	$pic_state = false;
+	$content_state = false;
+	$preview = '';
+	$preview_height = 0;
+}
+
+
+return array
+(
+	# 表名
+	'name' => 'data',
+	# 显示给用户看的名称
+	'lang' => $info['name'],
+	'order' => 7,
+	'menu' => false,
+
+	//'desc' => '预览地址:<br /><iframe id="preview" height="'.$preview_height.'" width="100%"  frameborder="no" border="0" marginwidth="0" marginheight="0" scrolling="no" allowtransparency="yes" src="'.$preview.'" ></iframe>',
+
+	# 数据结构
+	'struct' => array
+	(
+		'id' 		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> 'ID',
+			'default' 	=> '',
+			'desc' 		=> '',
+			'match' 	=> 'is_numeric',
+			//'search'	=> 'order',
+			'order'		=> 'desc',
+			//'list'		=> true,
+		),
+
+		'info_id' 		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '模块',
+			'default' 	=> Dever::input('search_option_info_id', '1'),
+			'desc' 		=> '模块',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'hidden',
+		),
+
+		'type'		=> array
+		(
+			'type' 		=> 'tinyint-1',
+			'name' 		=> '数据类型',
+			'default' 	=> '0',
+			'desc' 		=> '请选择数据类型',
+			'match' 	=> 'is_numeric',
+			//'option' 	=> $type,
+			//'update'	=> 'radio',
+			//'search'	=> 'select',
+			//'list'		=> true,
+			//'edit'		=> true,
+		),
+
+		'source_id' 		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '文章id',
+			'default' 	=> '',
+			'desc' 		=> '文章id',
+			'match' 	=> $info['type'] == 3 ? 'is_numeric' : 'option',
+			'update'	=> $info['type'] == 3 ? 'text' : 'hidden',
+			'list'		=> $info['type'] == 3 ? true : false,
+		),
+		
+		'name'		=> array
+		(
+			'type' 		=> 'varchar-60',
+			'name' 		=> '标题-手动干扰项',
+			'default' 	=> '',
+			'desc' 		=> '请输入标题',
+			'match' 	=> $name_state ? 'option' : 'option',
+			'update'	=> $name_state ? 'text' : 'hidden',
+			'search'	=> $name_state ? 'fulltext' : '',
+			'list'		=> $name_state ? '{source_id} > 0 ? ("{name}" ? "{name}" : Dever::load("content/news-one#name", {source_id})) : "{name}"' : false,
+			'edit'		=> $name_state ? true : false,
+		),
+
+		'link'		=> array
+		(
+			'type' 		=> 'varchar-200',
+			'name' 		=> '链接-手动干扰项',
+			'default' 	=> '',
+			'desc' 		=> '请输入链接',
+			'match' 	=> $link_state ? 'option' : 'option',
+			'update'	=> $link_state ? 'text' : 'hidden',
+			'search'	=> $link_state ? 'fulltext' : '',
+			//'list'		=> $link_state ? true : false,
+			'edit'		=> $link_state ? true : false,
+		),
+
+		'pic'		=> array
+		(
+			'type' 		=> 'varchar-200',
+			'name' 		=> '图片-手动干扰项,请上传,' . $info['col_pic'] . '大小的图片',
+			'default' 	=> '',
+			'desc' 		=> '请选择图片',
+			'match' 	=> $pic_state ? 'option' : 'option',
+			'update'	=> $pic_state ? 'image' : 'hidden',
+			'search'	=> $pic_state ? 'fulltext' : '',
+			//'list'		=> $pic_state ? true : false,
+			'key'		=> 1
+		),
+
+		'content'		=> array
+		(
+			'type' 		=> 'text-255',
+			'name' 		=> '内容-手动干扰项,字数请不要超过' . $info['col_content'] . '个汉字,前台展示时会自动过滤',
+			'default' 	=> '',
+			'desc' 		=> '请输入内容',
+			'match' 	=> $content_state ? 'option' : 'option',
+			'update'	=> $content_state ? 'editor' : 'hidden',
+		),
+		
+		'reorder'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '排序(数值越大越靠前)',
+			'default' 	=> '1',
+			'desc' 		=> '请输入排序',
+			'match' 	=> 'option',
+			'update'	=> 'text',
+			'search'	=> 'order',
+			'list_name' => '排序',
+			'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})',
+		),
+	),
+
+	# request 请求接口定义
+	'request' => array
+	(
+		# 获取列表页
+		'getAllByType' => array
+		(
+			# 匹配的正则或函数 选填项
+			'option' => array
+			(
+				'type' => 'yes',
+				'info_id' => 'yes',
+				'state' => 1,
+			),
+			'type' => 'all',
+			'order' => array('reorder' => 'desc'),
+			//'col' => '*|type|',
+			'col' => '*',
+		),
+	),
+);

+ 330 - 0
database/info.php

@@ -0,0 +1,330 @@
+<?php
+
+$curPage = Dever::input('search_option_page_id');
+
+# 显示的页面
+$page = function()
+{
+	$parent = Dever::db('module/page')->getParent();
+	$child = Dever::db('module/page')->getChild();
+	foreach ($parent as $k => $v) {
+		$parent[$k]['child'] = $child[$v['id']];
+	}
+
+	$array = array(-1 => array('id' => -1, 'name' => '无'));
+
+	if ($parent) {
+		$array += $parent;
+	}
+
+	return $array;
+};
+
+$type = array
+(
+	1 => '手动输入',
+	2 => '调取其他模块',
+	3 => '预定义方法',
+	4 => '自定义方法',
+	5 => '自定义SQL',
+	6 => '自定义接口',
+);
+
+$define = Dever::config('base')->module;
+
+$col = array
+(
+	1 => '标题',
+	2 => '链接',
+	3 => '图片',
+	4 => '内容',
+);
+
+$sqlMethod = array
+(
+	1 => '取多列数据',
+	2 => '取单列数据',
+	3 => '取影响行数',
+	4 => '取生成的ID',
+	5 => '仅执行',
+);
+
+return array
+(
+	# 表名
+	'name' => 'info',
+	# 显示给用户看的名称
+	'lang' => '模块管理',
+	'order' => 10,
+	'check' => 'page_id,key',
+	# 数据结构
+	'struct' => array
+	(
+		'id' 		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '模块ID',
+			'default' 	=> '',
+			'desc' 		=> '',
+			'match' 	=> 'is_numeric',
+			//'search'	=> 'order',
+			'order'		=> 'desc',
+			//'list'		=> true,
+		),
+		
+		'name'		=> array
+		(
+			'type' 		=> 'varchar-60',
+			'name' 		=> '模块标题',
+			'default' 	=> '',
+			'desc' 		=> '请输入模块标题',
+			'match' 	=> 'is_string',
+			'update'	=> 'text',
+			'search'	=> 'fulltext',
+			'list'		=> true,
+			'edit'		=> true,
+		),
+
+		'key'		=> array
+		(
+			'type' 		=> 'varchar-60',
+			'name' 		=> '模块标识',
+			'default' 	=> '',
+			'desc' 		=> '模块标识',
+			'match' 	=> 'is_string',
+			'update'	=> 'text',
+			'search'	=> 'fulltext',
+			'list'		=> true,
+		),
+
+		'page_id'		=> array
+		(
+			'type' 		=> 'tinyint-1',
+			'name' 		=> '所属的页面',
+			'default' 	=> Dever::input('search_option_page_id', '1'),
+			'desc' 		=> '请选择所属的页面',
+			'match' 	=> 'is_numeric',
+			'option' 	=> $page,
+			'update'	=> 'group',
+			'search'	=> 'group',
+			'list'		=> 'Dever::load("module/page-one#name", {page_id})',
+			//'edit'		=> true,
+		),
+
+		'num'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '数据总条数-为空或小于0则不限制,只对前台有效',
+			'default' 	=> '5',
+			'desc' 		=> '请输入数据总条数',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'text',
+			'list'		=> true,
+			'edit'		=> true,
+		),
+
+		'type'		=> array
+		(
+			'type' 		=> 'tinyint-1',
+			'name' 		=> '模块类型',
+			'default' 	=> '1',
+			'desc' 		=> '请选择模块类型',
+			'match' 	=> 'is_numeric',
+			'option' 	=> $type,
+			'update'	=> 'radio',
+			'search'	=> 'select',
+			//'list'		=> true,
+			'control'		=> 'type',
+		),
+
+		'data_type'		=> array
+		(
+			'type' 		=> 'varchar-50',
+			'name' 		=> '数据类型定义-多个用换行隔开,必须有一个值,主要用于该模块有多种不同类型的值',
+			'default' 	=> '默认类型',
+			'desc' 		=> '请选择模块类型',
+			'match' 	=> 'is_string',
+			//'update'	=> 'textarea',
+			//'show'		=> array('type_1'),
+		),
+
+		'code'		=> array
+		(
+			'type' 		=> 'varchar-500',
+			'name' 		=> '自定义内容',
+			'default' 	=> '',
+			'desc' 		=> '请输入自定义内容',
+			'match' 	=> 'is_string',
+			'update'	=> 'textarea',
+			'show'		=> array('type_4', 'type_5', 'type_6'),
+		),
+
+		'sql_method'		=> array
+		(
+			'type' 		=> 'tinyint-1',
+			'name' 		=> '选择sql执行之后的方法',
+			'default' 	=> '1',
+			'desc' 		=> '选择sql执行之后的方法',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'radio',
+			'option'	=> $sqlMethod,
+			'show'		=> array('type_5'),
+		),
+
+		'define'		=> array
+		(
+			'type' 		=> 'varchar-100',
+			'name' 		=> '选择预定义方法',
+			'default' 	=> '',
+			'desc' 		=> '请选择预定义方法',
+			'match' 	=> 'is_string',
+			'update'	=> 'select',
+			'option'	=> $define,
+			'show'		=> array('type_3'),
+		),
+
+		'col'		=> array
+		(
+			'type' 		=> 'varchar-30',
+			'name' 		=> '启用的字段',
+			'default' 	=> '1',
+			'desc' 		=> '请选择启用的字段',
+			'match' 	=> 'is_string',
+			'option' 	=> $col,
+			'update'	=> 'checkbox',
+			'show'		=> array('type_1'),
+			'control'	=> 'col',
+		),
+
+		'col_pic'		=> array
+		(
+			'type' 		=> 'varchar-20',
+			'name' 		=> '图片尺寸提醒-请直接输入提醒的文字即可,如100X100',
+			'default' 	=> '100X100',
+			'desc' 		=> '图片尺寸提醒',
+			'match' 	=> 'is_string',
+			'update'	=> 'text',
+			'show'		=> array('col_3'),
+		),
+
+		'col_content'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '内容长度限制-必须是数字',
+			'default' 	=> '30',
+			'desc' 		=> '内容长度限制',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'text',
+			'show'		=> array('col_4'),
+		),
+
+		'relate_id'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '请输入模块id',
+			'default' 	=> '',
+			'desc' 		=> '请输入模块id',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'text',
+			'show'		=> array('type_2'),
+		),
+
+		'preview'		=> array
+		(
+			'type' 		=> 'varchar-200',
+			'name' 		=> '模块预览地址',
+			'default' 	=> '',
+			'desc' 		=> '模块预览地址',
+			'match' 	=> 'option',
+			'update'	=> 'text',
+		),
+
+		'preview_height'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '模块预览的高度',
+			'default' 	=> '500',
+			'desc' 		=> '模块预览的高度',
+			'match' 	=> 'option',
+			'update'	=> 'text',
+		),
+		
+		'reorder'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '排序(数值越大越靠前)',
+			'default' 	=> '1',
+			'desc' 		=> '请输入排序',
+			'match' 	=> 'option',
+			'update'	=> 'text',
+			'search'	=> 'order',
+			'list_name' => '排序',
+			'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})',
+		),
+	),
+
+	# 权限精细控制 加入到该项目的详细权限中,注意与top的不同
+	/*
+	'auth' => array
+	(
+		# 数据来源
+		'data' => 'all',
+		# 所属项目
+		'project' => 'module',
+		# 项目名称
+		'project_name' => '模块管理',
+	),
+	*/
+
+	'manage' => array
+	(
+		'insert' => $curPage ? true : false,
+		'list_button' => array
+		(
+			'add' => array('新增数据', '"data&search_option_info_id={id}&oper_parent=info"', '{type} == 1'),
+
+			'list' => array('数据列表', '"data&search_option_info_id={id}&oper_parent=info"', '{type} == 1'),
+		),
+	),
+
+	# request 请求接口定义
+	'request' => array
+	(
+		# 获取列表页
+		'getAll' => array
+		(
+			# 匹配的正则或函数 选填项
+			'option' => array
+			(
+				'type' => 'yes',
+				'page_id' => 'yes',
+				'state' => 1,
+			),
+			'type' => 'all',
+			'order' => array('reorder' => 'desc'),
+			'col' => '*',
+		),
+	),
+);

+ 176 - 0
database/page.php

@@ -0,0 +1,176 @@
+<?php
+
+# 定义几个常用的选项
+$option = array
+(
+	1 => '显示',
+	2 => '不显示',
+);
+
+
+$parent = function()
+{
+	$param['option_page_id'] = -1;
+	$info = Dever::db('module/page')->all($param);
+
+	$array = array(-1 => array('name' => '无'));
+
+	if ($info) {
+		$array += $info;
+	}
+	return $array;
+};
+
+$time = time();
+
+return array
+(
+	# 表名
+	'name' => 'page',
+	# 显示给用户看的名称
+	'lang' => '页面管理',
+	# 后台菜单排序
+	'order' => 9,
+	'check' => 'key',
+	# 数据结构
+	'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'	=> 'order,fulltext',
+			'list'		=> true,
+			//'list'		=> '"<a href=\"".Dever::load("main/data.page", {id})."\" target=\"_blank\">{name}</a>"',
+		),
+
+		'key'		=> array
+		(
+			'type' 		=> 'varchar-60',
+			'name' 		=> '页面标识',
+			'default' 	=> '',
+			'desc' 		=> '页面标识',
+			'match' 	=> 'is_string',
+			'update'	=> 'text',
+			'search'	=> 'fulltext',
+			'list'		=> true,
+		),
+
+		'page_id'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '父级页面',
+			'default' 	=> Dever::input('page_id', '-1'),
+			'desc' 		=> '请选择父级页面id',
+			'match' 	=> 'is_numeric',
+			'option' 	=> $parent,
+			'update'	=> 'select',
+			'search'	=> 'select',
+			//'list'		=> true,
+		),
+
+		'reorder'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '排序(数值越大越靠前)',
+			'default' 	=> '1',
+			'desc' 		=> '请输入排序',
+			'match' 	=> 'option',
+			'update'	=> 'text',
+			'search'	=> 'order',
+			'list_name' => '排序',
+			'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})',
+		),
+	),
+
+	'manage' => array
+	(
+		'list_type' => 'parent',
+		'list_button' => array
+		(
+			'addPage' => array('新增子页面', '"page&page_id={id}"', '{page_id} == -1'),
+
+			'add' => array('新增模块', '"info&project=module&search_option_page_id={id}&oper_parent=page&oper_project=module"', '{page_id} > -1'),
+			'list' => array('模块列表', '"info&project=module&search_option_page_id={id}&oper_parent=page&oper_project=module"', '{page_id} > -1'),
+		),
+	),
+
+	# 默认值
+	'default' => array
+	(
+		'col' => 'id,name,state,cdate',
+		'value' => array
+		(
+			'1,"首页",1,' . $time,
+		),
+	),
+
+	# request 请求接口定义
+	'request' => array
+	(
+		# 获取列表页
+		'getParent' => array
+		(
+			# 匹配的正则或函数 选填项
+			'where' => array
+			(
+				'page_id' => -1,
+				'state' => 1,
+			),
+			'type' => 'all',
+			'order' => array('reorder' => 'desc'),
+			'col' => '*',
+		),
+
+		'getChild' => array
+		(
+			# 匹配的正则或函数 选填项
+			'where' => array
+			(
+				'page_id' => array(-1, '>'),
+				'state' => 1,
+			),
+			'type' => 'all',
+			'order' => array('reorder' => 'desc'),
+			'col' => '*|page_id|id|',
+		),
+	),
+);

+ 7 - 0
index.php

@@ -0,0 +1,7 @@
+<?php
+define('DEVER_APP_NAME', 'module');
+define('DEVER_APP_LANG', '模块系统');
+define('DEVER_APP_PATH', dirname(__FILE__) . DIRECTORY_SEPARATOR);
+define('DEVER_MANAGE_ORDER', -5);
+define('DEVER_MANAGE_ICON', 'glyphicon glyphicon-dashboard');
+include(DEVER_APP_PATH . '../boot.php');

+ 185 - 0
src/Api.php

@@ -0,0 +1,185 @@
+<?php
+
+namespace Module\Src;
+
+use Dever;
+
+class Api
+{
+	public function get_api($page)
+	{
+		$result = array();
+		if ($page > 0) {
+			$info = Dever::db('module/page')->one($page);
+			if ($info && $info['state'] == 1) {
+				if ($info['page_id'] == -1) {
+					$param['option_page_id'] = $page;
+					$param['option_state'] = 1;
+					$page = Dever::db('module/page')->all($param);
+					foreach ($page as $k => $v) {
+						$result[$v['key']] = $this->getModule($v['id']);
+					}
+				} else {
+					$result = $this->getModule($page);
+				}
+			}
+		}
+
+		return $result;
+	}
+
+	public function getM_api($module)
+	{
+		$result = array();
+		if ($module > 0) {
+			$module = Dever::db('module/info')->one($module);
+			$module = $this->getModuleData($module);
+			$result = $module;
+		}
+
+		return $result;
+	}
+
+	private function getModule($page)
+	{
+		$result = array();
+		if ($page > 0) {
+			$param['option_page_id'] = $page;
+			$module = Dever::db('module/info')->getAll($param);
+			$result = array();
+			foreach ($module as $k => $v) {
+				$result[$v['key']] = $this->getModuleData($v);
+			}
+		}
+
+		return $result;
+	}
+
+	private function getModuleData($module)
+	{
+		$data = $result = array();
+
+		$method = 'getModuleData_' . $module['type'];
+		$data = $this->$method($module);
+		
+		if ($data && is_array($data) && $module['num'] > 0) {
+			$data = array_slice($data, 0, $module['num']);
+		}
+
+		/*
+		$result['id'] = $module['id'];
+		$result['name'] = $module['name'];
+		$result['key'] = $module['key'];
+		$result['page_id'] = $module['page_id'];
+		$result['type'] = $module['type'];
+		$result['code'] = $module['code'];
+		$result['define'] = $module['define'];
+		$result['num'] = $module['num'];
+		if ($module['type'] == 1) {
+			$result['data_type'] = explode("\r\n", $module['data_type']);
+		}
+		*/
+		$result = $data;
+
+		return $result;
+	}
+
+	private function getModuleData_1($module)
+	{
+		$data = $this->getData($module['id'], $module['type'], $module['num']);
+
+		return $data;
+	}
+
+	private function getModuleData_2($module)
+	{
+		$id = $module['relate_id'];
+		$relate = Dever::load('module/info-one', $id);
+		$relate['num'] = $module['num'];
+		$data = $this->getModuleData($relate);
+		return $data;
+	}
+
+	private function getModuleData_3($module)
+	{
+		$data = $this->getMethod($module['id'], $module['define'], $module['num']);
+		return $data;
+	}
+
+	private function getModuleData_4($module)
+	{
+		$data = $this->getMethod($module['id'], $module['code'], $module['num']);
+		return $data;
+	}
+
+	private function getModuleData_5($module)
+	{
+		$sql = new Sql($module['id'], $module['code'], $module['sql_method'], $module['num']);
+		$data = $sql->data;
+		return $data;
+	}
+
+	private function getModuleData_6($module)
+	{
+		$data = $this->getMethod($module['id'], $module['code'], $module['num']);
+		return $data;
+	}
+
+	private function getData($id, $type = 0, $num)
+	{
+		$data = Dever::load('module/data-getAllByType', array('option_info_id' => $id));
+
+		return $data;
+	}
+
+	private function getMethod($id, $method, $num)
+	{
+		if (strpos($method, '|')) {
+			$temp = explode('|', $method);
+			$method = $temp[0];
+			parse_str($temp[1], $param);
+			foreach ($param as $k => $v) {
+				if (!Dever::input($k)) {
+					Dever::setInput($k, $v);
+				}
+			}
+		}
+		$data = Dever::load($method);
+
+		return $data;
+	}
+
+	public function module_api($id)
+	{
+		if (!$id || $id < 0) {
+			return array();
+		}
+		$type = isset($param['type']) ? $param['type'] : 0;
+
+		$module = Dever::load('module/info-one', $id);
+
+		if ($module) {
+			$data = Dever::load('module/data-all', array('option_info_id' => $id, 'option_type' => $type));
+
+			if($module['type'] == 3)
+			{
+				foreach($data as $k => $v)
+				{
+					$news = Dever::load('content/news-check', $v['source_id']);
+
+					if($news)
+					{
+						$data[$k]['name'] = $v['name'] ? $v['name'] : $news['name'];
+						$data[$k]['pic'] = $v['pic'] ? $v['pic'] : $news['pic'];
+						$data[$k]['link'] = $v['link'] ? $v['link'] : Dever::url('news/view?id=' . $news['id'], 'main');
+						$data[$k]['content'] = $v['content'] ? $v['content'] : $news['content'];
+					}
+				}
+			}
+
+			return $data;
+		}
+
+		return array();
+	}
+}

+ 24 - 0
src/Demo.php

@@ -0,0 +1,24 @@
+<?php
+
+namespace Module\Src;
+
+use Dever;
+
+class Demo
+{
+	public function __construct()
+	{
+		//$this->page = Dever::input('page', 1);
+	}
+
+	public function define1()
+	{
+		return 1;
+	}
+
+	public function get()
+	{
+		$id = Dever::input('id');
+		return $id;
+	}
+}

+ 98 - 0
src/Sql.php

@@ -0,0 +1,98 @@
+<?php
+
+namespace Module\Src;
+
+use Dever;
+
+class Sql
+{
+	private $sql;
+	private $method;
+	private $bind;
+	public $data;
+	public function __construct($id, $sql, $method, $num)
+	{
+		$this->method($method);
+		$this->db($sql);
+		$this->bind();
+		$this->limit($num);
+		$this->result();
+	}
+
+	private function method($method)
+	{
+		$method = 'getMethod_' . $method;
+		$this->method = $this->$method();
+	}
+
+	private function getMethod_1()
+	{
+		return 'fetchAll';
+	}
+
+	private function getMethod_2()
+	{
+		return 'fetch';
+	}
+
+	private function getMethod_3()
+	{
+		return 'rowCount';
+	}
+
+	private function getMethod_4()
+	{
+		return 'lastId';
+	}
+
+	private function getMethod_5()
+	{
+		return 'query';
+	}
+
+	private function db($sql)
+	{
+		$db = '';
+		if (strpos($sql, ':')) {
+			$temp = explode(':', $sql);
+			$this->sql = $temp[1];
+			$db = ':' . $temp[0];
+		} else {
+			$this->sql = $sql;
+		}
+		$this->db = Dever::db('module/info' . $db);
+	}
+
+	private function bind()
+	{
+		$pattern = '/\{(.*?)\}/i';
+		preg_match_all($pattern, $this->sql, $matches);
+		$this->bind = array();
+		if (isset($matches[1]) && $matches[1]) {
+			foreach ($matches[1] as $k => $v) {
+				$default = '';
+				$source = $v;
+				if (strpos($v, '=')) {
+					$temp = explode('=', $v);
+					$v = $temp[0];
+					$default = $temp[1];
+				}
+				$k = ':' . $v;
+				$this->bind[$k] = Dever::input($v, $default);
+				$this->sql = str_replace('{'.$source.'}', $k, $this->sql);
+			}
+		}
+	}
+
+	private function limit($num)
+	{
+		if ($num > 0 && !stripos($this->sql, 'limit')) {
+			$this->sql .= ' limit 0,' . $num;
+		}
+	}
+
+	private function result()
+	{
+		$this->data = $this->db->{$this->method}($this->sql, $this->bind);
+	}
+}