代码格式化

This commit is contained in:
2016-08-27 22:24:30 +08:00
parent db9e4b00e7
commit 1710eb742c
12 changed files with 418 additions and 395 deletions

View File

@@ -99,7 +99,7 @@ function rand_string($len = 6, $type = '', $addChars = '') {
break; break;
} }
if ($len > 10) { if ($len > 10) {
//位数过长重复字符串一定次数 //位数过长重复字符串一定次数
$chars = $type == 1 ? str_repeat($chars, $len) : str_repeat($chars, 5); $chars = $type == 1 ? str_repeat($chars, $len) : str_repeat($chars, 5);
} }
if ($type != 4) { if ($type != 4) {
@@ -275,7 +275,7 @@ function get_file($file_id, $field = null) {
$file = db('File')->where(array('id' => $file_id))->find(); $file = db('File')->where(array('id' => $file_id))->find();
if ($field == 'path') { if ($field == 'path') {
return $file['savepath']; return $file['savepath'];
}elseif ($field == 'time') { } elseif ($field == 'time') {
return date('Y-m-d H:i:s', $file['create_time']); return date('Y-m-d H:i:s', $file['create_time']);
} }
return empty($field) ? $file : $file[$field]; return empty($field) ? $file : $file[$field];

View File

@@ -3,19 +3,19 @@ namespace app\common\behavior;
class InitHook { class InitHook {
public function run(&$request){ public function run(&$request) {
//未安装时不执行 //未安装时不执行
if (substr(request()->pathinfo(), 0, 7) != 'install' && is_file(APP_PATH . 'database.php') ) { if (substr(request()->pathinfo(), 0, 7) != 'install' && is_file(APP_PATH . 'database.php')) {
//初始化某些配置信息 //初始化某些配置信息
if (cache('db_config_data')) { if (cache('db_config_data')) {
\think\Config::set(cache('db_config_data')); \think\Config::set(cache('db_config_data'));
}else{ } else {
$config = model('common/Config'); $config = model('common/Config');
\think\Config::set($config->lists()); \think\Config::set($config->lists());
} }
//扩展插件 //扩展插件
\think\Loader::addNamespace('addons',ROOT_PATH . '/addons/'); \think\Loader::addNamespace('addons', ROOT_PATH . '/addons/');
$this->setHook(); $this->setHook();
@@ -24,54 +24,54 @@ class InitHook {
} }
} }
protected function setHook(){ protected function setHook() {
$data = cache('hooks'); $data = cache('hooks');
if(!$data){ if (!$data) {
$hooks = db('Hooks')->column('name,addons'); $hooks = db('Hooks')->column('name,addons');
foreach ($hooks as $key => $value) { foreach ($hooks as $key => $value) {
if($value){ if ($value) {
$map['status'] = 1; $map['status'] = 1;
$names = explode(',',$value); $names = explode(',', $value);
$map['name'] = array('IN',$names); $map['name'] = array('IN', $names);
$data = db('Addons')->where($map)->column('id,name'); $data = db('Addons')->where($map)->column('id,name');
if($data){ if ($data) {
$addons = array_intersect($names, $data); $addons = array_intersect($names, $data);
\think\Hook::add($key,array_map('get_addon_class',$addons)); \think\Hook::add($key, array_map('get_addon_class', $addons));
} }
} }
} }
cache('hooks',\think\Hook::get()); cache('hooks', \think\Hook::get());
}else{ } else {
\think\Hook::import($data,false); \think\Hook::import($data, false);
} }
} }
protected function setRoute(){ protected function setRoute() {
$list = db('Rewrite')->select(); $list = db('Rewrite')->select();
foreach ($list as $key => $value) { foreach ($list as $key => $value) {
$route[$value['rule']] = $value['url']; $route[$value['rule']] = $value['url'];
} }
$model = db('Model'); $model = db('Model');
$map = array( $map = array(
'status' => array('gt',0), 'status' => array('gt', 0),
'extend' => array('gt',0), 'extend' => array('gt', 0),
); );
$list = $model->where($map)->field("name,id,title,'' as 'style'")->select(); $list = $model->where($map)->field("name,id,title,'' as 'style'")->select();
foreach ($list as $key => $value) { foreach ($list as $key => $value) {
$route["admin/".$value['name']."/index"] = "admin/content/index?model_id=".$value['id']; $route["admin/" . $value['name'] . "/index"] = "admin/content/index?model_id=" . $value['id'];
$route["admin/".$value['name']."/add"] = "admin/content/add?model_id=".$value['id']; $route["admin/" . $value['name'] . "/add"] = "admin/content/add?model_id=" . $value['id'];
$route["admin/".$value['name']."/edit"] = "admin/content/edit?model_id=".$value['id']; $route["admin/" . $value['name'] . "/edit"] = "admin/content/edit?model_id=" . $value['id'];
$route["admin/".$value['name']."/del"] = "admin/content/del?model_id=".$value['id']; $route["admin/" . $value['name'] . "/del"] = "admin/content/del?model_id=" . $value['id'];
$route["admin/".$value['name']."/status"] = "admin/content/status?model_id=".$value['id']; $route["admin/" . $value['name'] . "/status"] = "admin/content/status?model_id=" . $value['id'];
$route[$value['name']."/index"] = "index/content/index?model=".$value['name']; $route[$value['name'] . "/index"] = "index/content/index?model=" . $value['name'];
$route[$value['name']."/list/:id"] = "index/content/lists?model=".$value['name']; $route[$value['name'] . "/list/:id"] = "index/content/lists?model=" . $value['name'];
$route[$value['name']."/detail/:id"] = "index/content/detail?model_id=".$value['id']; $route[$value['name'] . "/detail/:id"] = "index/content/detail?model_id=" . $value['id'];
$route["/list/:id"] = "index/content/category"; $route["/list/:id"] = "index/content/category";
$route["user/".$value['name']."/index"] = "user/content/index?model_id=".$value['id']; $route["user/" . $value['name'] . "/index"] = "user/content/index?model_id=" . $value['id'];
$route["user/".$value['name']."/add"] = "user/content/add?model_id=".$value['id']; $route["user/" . $value['name'] . "/add"] = "user/content/add?model_id=" . $value['id'];
$route["user/".$value['name']."/edit"] = "user/content/edit?model_id=".$value['id']; $route["user/" . $value['name'] . "/edit"] = "user/content/edit?model_id=" . $value['id'];
$route["user/".$value['name']."/del"] = "user/content/del?model_id=".$value['id']; $route["user/" . $value['name'] . "/del"] = "user/content/del?model_id=" . $value['id'];
$route["user/".$value['name']."/status"] = "user/content/status?model_id=".$value['id']; $route["user/" . $value['name'] . "/status"] = "user/content/status?model_id=" . $value['id'];
} }
\think\Route::rule($route); \think\Route::rule($route);
} }

View File

@@ -13,128 +13,129 @@ namespace app\common\controller;
* 插件类 * 插件类
* @author yangweijie <yangweijiester@gmail.com> * @author yangweijie <yangweijiester@gmail.com>
*/ */
class Addons extends Base{ class Addons extends Base {
public $info = array(); public $info = array();
public $addon_path = ''; public $addon_path = '';
public $config_file = ''; public $config_file = '';
public $custom_config = ''; public $custom_config = '';
public $admin_list = array(); public $admin_list = array();
public $custom_adminlist = ''; public $custom_adminlist = '';
public $access_url = array(); public $access_url = array();
public function _initialize(){ public function _initialize() {
$mc = $this->getAddonsName(); $mc = $this->getAddonsName();
$this->addon_path = ROOT_PATH . "/addons/{$mc}/"; $this->addon_path = ROOT_PATH . "/addons/{$mc}/";
if (is_file($this->addon_path.'config.php')) { if (is_file($this->addon_path . 'config.php')) {
$this->config_file = $this->addon_path.'config.php'; $this->config_file = $this->addon_path . 'config.php';
} }
} }
public function template($template){ public function template($template) {
$mc = $this->getAddonsName(); $mc = $this->getAddonsName();
$ac = input('get.ac','','trim,strtolower'); $ac = input('get.ac', '', 'trim,strtolower');
$parse_str = \think\Config::get('parse_str'); $parse_str = \think\Config::get('parse_str');
$parse_str['__ADDONROOT__'] = ROOT_PATH . "/addons/{$mc}"; $parse_str['__ADDONROOT__'] = ROOT_PATH . "/addons/{$mc}";
\think\Config::set('parse_str', $parse_str); \think\Config::set('parse_str', $parse_str);
if ($template) { if ($template) {
$template = $template; $template = $template;
}else{ } else {
$template = $mc . "/" . $ac; $template = $mc . "/" . $ac;
} }
$this->view->engine( $this->view->engine(
array('view_path'=> "addons/" . $mc . "/view/") array('view_path' => "addons/" . $mc . "/view/")
); );
echo $this->fetch($template); echo $this->fetch($template);
}
final public function getAddonsName(){
$mc = input('get.mc','','trim,strtolower');
if ($mc) {
return $mc;
}else{
$class = get_class($this);
return strtolower(substr($class,strrpos($class, '\\')+1));
}
}
final public function checkInfo(){
$info_check_keys = array('name','title','description','status','author','version');
foreach ($info_check_keys as $value) {
if(!array_key_exists($value, $this->info))
return false;
}
return true;
}
public function getConfig(){
static $_config = array();
if(empty($name)){
$name = $this->getAddonsName();
}
if(isset($_config[$name])){
return $_config[$name];
}
$config = array();
$map['name'] = $name;
$map['status'] = 1;
$config = db('Addons')->where($map)->value('config');
if($config){
$config = json_decode($config, true);
}else{
$temp_arr = include $this->config_file;
foreach ($temp_arr as $key => $value) {
if($value['type'] == 'group'){
foreach ($value['options'] as $gkey => $gvalue) {
foreach ($gvalue['options'] as $ikey => $ivalue) {
$config[$ikey] = $ivalue['value'];
}
}
}else{
$config[$key] = $temp_arr[$key]['value'];
}
}
}
$_config[$name] = $config;
return $config;
} }
final public function getAddonsName() {
$mc = input('get.mc', '', 'trim,strtolower');
if ($mc) {
return $mc;
} else {
$class = get_class($this);
return strtolower(substr($class, strrpos($class, '\\') + 1));
}
}
/** final public function checkInfo() {
* 获取插件所需的钩子是否存在,没有则新增 $info_check_keys = array('name', 'title', 'description', 'status', 'author', 'version');
* @param string $str 钩子名称 foreach ($info_check_keys as $value) {
* @param string $addons 插件名称 if (!array_key_exists($value, $this->info)) {
* @param string $addons 插件简介 return false;
*/ }
public function getisHook($str, $addons, $msg=''){
$hook_mod = db('Hooks'); }
$where['name'] = $str; return true;
$gethook = $hook_mod->where($where)->find(); }
if(!$gethook || empty($gethook) || !is_array($gethook)){
$data['name'] = $str; public function getConfig() {
$data['description'] = $msg;
$data['type'] = 1; static $_config = array();
$data['update_time'] = time(); if (empty($name)) {
$data['addons'] = $addons; $name = $this->getAddonsName();
if( false !== $hook_mod->create($data) ){ }
$hook_mod->add(); if (isset($_config[$name])) {
} return $_config[$name];
} }
} $config = array();
$map['name'] = $name;
/** $map['status'] = 1;
* 删除钩子 $config = db('Addons')->where($map)->value('config');
* @param string $hook 钩子名称 if ($config) {
*/ $config = json_decode($config, true);
public function deleteHook($hook){ } else {
$model = db('hooks'); $temp_arr = include $this->config_file;
$condition = array( foreach ($temp_arr as $key => $value) {
'name' => $hook, if ($value['type'] == 'group') {
); foreach ($value['options'] as $gkey => $gvalue) {
$model->where($condition)->delete(); foreach ($gvalue['options'] as $ikey => $ivalue) {
} $config[$ikey] = $ivalue['value'];
}
}
} else {
$config[$key] = $temp_arr[$key]['value'];
}
}
}
$_config[$name] = $config;
return $config;
}
/**
* 获取插件所需的钩子是否存在,没有则新增
* @param string $str 钩子名称
* @param string $addons 插件名称
* @param string $addons 插件简介
*/
public function getisHook($str, $addons, $msg = '') {
$hook_mod = db('Hooks');
$where['name'] = $str;
$gethook = $hook_mod->where($where)->find();
if (!$gethook || empty($gethook) || !is_array($gethook)) {
$data['name'] = $str;
$data['description'] = $msg;
$data['type'] = 1;
$data['update_time'] = time();
$data['addons'] = $addons;
if (false !== $hook_mod->create($data)) {
$hook_mod->add();
}
}
}
/**
* 删除钩子
* @param string $hook 钩子名称
*/
public function deleteHook($hook) {
$model = db('hooks');
$condition = array(
'name' => $hook,
);
$model->where($condition)->delete();
}
} }

View File

@@ -8,48 +8,48 @@
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
namespace app\common\controller; namespace app\common\controller;
use app\common\model\AuthRule;
use app\common\model\AuthGroup; use app\common\model\AuthGroup;
use app\common\model\AuthRule;
class Admin extends Base{ class Admin extends Base {
public function _initialize(){ public function _initialize() {
parent::_initialize(); parent::_initialize();
if (!is_login() and !in_array($this->url,array('admin/index/login', 'admin/index/logout', 'admin/index/verify'))) { if (!is_login() and !in_array($this->url, array('admin/index/login', 'admin/index/logout', 'admin/index/verify'))) {
$this->redirect('admin/index/login'); $this->redirect('admin/index/login');
} }
if (!in_array($this->url,array('admin/index/login', 'admin/index/logout', 'admin/index/verify'))) { if (!in_array($this->url, array('admin/index/login', 'admin/index/logout', 'admin/index/verify'))) {
// 是否是超级管理员 // 是否是超级管理员
define('IS_ROOT', is_administrator()); define('IS_ROOT', is_administrator());
if(!IS_ROOT && \think\Config::get('admin_allow_ip')){ if (!IS_ROOT && \think\Config::get('admin_allow_ip')) {
// 检查IP地址访问 // 检查IP地址访问
if(!in_array(get_client_ip(),explode(',',\think\Config::get('admin_allow_ip')))){ if (!in_array(get_client_ip(), explode(',', \think\Config::get('admin_allow_ip')))) {
$this->error('403:禁止访问'); $this->error('403:禁止访问');
} }
} }
// 检测系统权限 // 检测系统权限
if(!IS_ROOT){ if (!IS_ROOT) {
$access = $this->accessControl(); $access = $this->accessControl();
if ( false === $access ) { if (false === $access) {
$this->error('403:禁止访问'); $this->error('403:禁止访问');
}elseif(null === $access ){ } elseif (null === $access) {
$dynamic = $this->checkDynamic();//检测分类栏目有关的各项动态权限 $dynamic = $this->checkDynamic(); //检测分类栏目有关的各项动态权限
if( $dynamic === null ){ if ($dynamic === null) {
//检测访问权限 //检测访问权限
if ( !$this->checkRule($this->url,array('in','1,2')) ){ if (!$this->checkRule($this->url, array('in', '1,2'))) {
$this->error('未授权访问!'); $this->error('未授权访问!');
}else{ } else {
// 检测分类及内容有关的各项动态权限 // 检测分类及内容有关的各项动态权限
$dynamic = $this->checkDynamic(); $dynamic = $this->checkDynamic();
if( false === $dynamic ){ if (false === $dynamic) {
$this->error('未授权访问!'); $this->error('未授权访问!');
} }
} }
}elseif( $dynamic === false ){ } elseif ($dynamic === false) {
$this->error('未授权访问!'); $this->error('未授权访问!');
} }
} }
@@ -61,18 +61,18 @@ class Admin extends Base{
} }
/** /**
* 权限检测 * 权限检测
* @param string $rule 检测的规则 * @param string $rule 检测的规则
* @param string $mode check模式 * @param string $mode check模式
* @return boolean * @return boolean
* @author 朱亚杰 <xcoolcc@gmail.com> * @author 朱亚杰 <xcoolcc@gmail.com>
*/ */
final protected function checkRule($rule, $type=AuthRule::rule_url, $mode='url'){ final protected function checkRule($rule, $type = AuthRule::rule_url, $mode = 'url') {
static $Auth = null; static $Auth = null;
if (!$Auth) { if (!$Auth) {
$Auth = new \com\Auth(); $Auth = new \com\Auth();
} }
if(!$Auth->check($rule,session('user_auth.uid'),$type,$mode)){ if (!$Auth->check($rule, session('user_auth.uid'), $type, $mode)) {
return false; return false;
} }
return true; return true;
@@ -87,11 +87,11 @@ class Admin extends Base{
* *
* @author 朱亚杰 <xcoolcc@gmail.com> * @author 朱亚杰 <xcoolcc@gmail.com>
*/ */
protected function checkDynamic(){ protected function checkDynamic() {
if(IS_ROOT){ if (IS_ROOT) {
return true;//管理员允许访问任何页面 return true; //管理员允许访问任何页面
} }
return null;//不明,需checkRule return null; //不明,需checkRule
} }
/** /**
@@ -104,38 +104,39 @@ class Admin extends Base{
* 返回 **null**, 需要继续执行节点权限检测决定是否允许访问 * 返回 **null**, 需要继续执行节点权限检测决定是否允许访问
* @author 朱亚杰 <xcoolcc@gmail.com> * @author 朱亚杰 <xcoolcc@gmail.com>
*/ */
final protected function accessControl(){ final protected function accessControl() {
$allow = \think\Config::get('allow_visit'); $allow = \think\Config::get('allow_visit');
$deny = \think\Config::get('deny_visit'); $deny = \think\Config::get('deny_visit');
$check = strtolower($this->request->controller().'/'.$this->request->action()); $check = strtolower($this->request->controller() . '/' . $this->request->action());
if ( !empty($deny) && in_array_case($check,$deny) ) { if (!empty($deny) && in_array_case($check, $deny)) {
return false;//非超管禁止访问deny中的方法 return false; //非超管禁止访问deny中的方法
} }
if ( !empty($allow) && in_array_case($check,$allow) ) { if (!empty($allow) && in_array_case($check, $allow)) {
return true; return true;
} }
return null;//需要检测节点权限 return null; //需要检测节点权限
} }
protected function setMenu(){ protected function setMenu() {
$hover_url = $this->request->module().'/'.$this->request->controller(); $hover_url = $this->request->module() . '/' . $this->request->controller();
$controller = $this->url; $controller = $this->url;
$menu = array( $menu = array(
'main' => array(), 'main' => array(),
'child' => array(), 'child' => array(),
); );
$where['pid'] = 0; $where['pid'] = 0;
$where['hide'] = 0; $where['hide'] = 0;
$where['type'] = 'admin'; $where['type'] = 'admin';
if(!config('develop_mode')){ // 是否开发者模式 if (!config('develop_mode')) {
$where['is_dev'] = 0; // 是否开发者模式
$where['is_dev'] = 0;
} }
$row = db('menu')->field('id,title,url,icon,"" as style')->where($where)->select(); $row = db('menu')->field('id,title,url,icon,"" as style')->where($where)->select();
foreach ($row as $key => $value) { foreach ($row as $key => $value) {
//此处用来做权限判断 //此处用来做权限判断
if (!IS_ROOT && !$this->checkRule($value['url'],2,null) ) { if (!IS_ROOT && !$this->checkRule($value['url'], 2, null)) {
unset($menu['main'][$value['id']]); unset($menu['main'][$value['id']]);
continue;//继续循环 continue; //继续循环
} }
if ($controller == $value['url']) { if ($controller == $value['url']) {
$value['style'] = "active"; $value['style'] = "active";
@@ -145,39 +146,39 @@ class Admin extends Base{
// 查找当前子菜单 // 查找当前子菜单
$pid = db('menu')->where("pid !=0 AND url like '%{$hover_url}%'")->value('pid'); $pid = db('menu')->where("pid !=0 AND url like '%{$hover_url}%'")->value('pid');
$id = db('menu')->where("pid = 0 AND url like '%{$hover_url}%'")->value('id'); $id = db('menu')->where("pid = 0 AND url like '%{$hover_url}%'")->value('id');
$pid = $pid ? $pid : $id; $pid = $pid ? $pid : $id;
if ($hover_url == 'admin/content' || $hover_url == 'admin/attribute') { if ($hover_url == 'admin/content' || $hover_url == 'admin/attribute') {
//内容管理菜单 //内容管理菜单
$pid = db('menu')->where("pid =0 AND url like '%admin/category%'")->value('id'); $pid = db('menu')->where("pid =0 AND url like '%admin/category%'")->value('id');
} }
if ($pid) { if ($pid) {
$map['pid'] = $pid; $map['pid'] = $pid;
$map['hide'] = 0; $map['hide'] = 0;
$map['type'] = 'admin'; $map['type'] = 'admin';
$row = db('menu')->field('id,title,url,icon,group,pid,"" as style')->where($map)->select(); $row = db('menu')->field('id,title,url,icon,group,pid,"" as style')->where($map)->select();
foreach ($row as $key => $value) { foreach ($row as $key => $value) {
if (IS_ROOT || $this->checkRule($value['url'],2,null) ) { if (IS_ROOT || $this->checkRule($value['url'], 2, null)) {
if ($controller == $value['url']) { if ($controller == $value['url']) {
$menu['main'][$value['pid']]['style'] = "active"; $menu['main'][$value['pid']]['style'] = "active";
$value['style'] = "active"; $value['style'] = "active";
} }
$menu['child'][$value['group']][] = $value; $menu['child'][$value['group']][] = $value;
} }
} }
} }
$this->assign('__menu__',$menu); $this->assign('__menu__', $menu);
} }
protected function getContentMenu(){ protected function getContentMenu() {
$model = \think\Loader::model('Model'); $model = \think\Loader::model('Model');
$list = array(); $list = array();
$map = array( $map = array(
'status' => array('gt',0), 'status' => array('gt', 0),
'extend' => array('gt',0), 'extend' => array('gt', 0),
); );
$list = $model::where($map)->field("name,id,title,icon,'' as 'style'")->select(); $list = $model::where($map)->field("name,id,title,icon,'' as 'style'")->select();
//判断是否有模型权限 //判断是否有模型权限
$models = AuthGroup::getAuthModels(session('user_auth.uid')); $models = AuthGroup::getAuthModels(session('user_auth.uid'));
foreach ($list as $key => $value) { foreach ($list as $key => $value) {
@@ -185,41 +186,40 @@ class Admin extends Base{
if ('admin/content/index' == $this->url && input('model_id') == $value['id']) { if ('admin/content/index' == $this->url && input('model_id') == $value['id']) {
$value['style'] = "active"; $value['style'] = "active";
} }
$value['url'] = "admin/content/index?model_id=".$value['id']; $value['url'] = "admin/content/index?model_id=" . $value['id'];
$value['title'] = $value['title']."管理"; $value['title'] = $value['title'] . "管理";
$value['icon'] = $value['icon'] ? $value['icon'] : 'file'; $value['icon'] = $value['icon'] ? $value['icon'] : 'file';
$menu[] = $value; $menu[] = $value;
} }
} }
if (!empty($menu)) { if (!empty($menu)) {
$this->assign('extend_menu',array('内容管理'=>$menu)); $this->assign('extend_menu', array('内容管理' => $menu));
} }
} }
protected function getAddonsMenu() {
protected function getAddonsMenu(){
$model = db('Addons'); $model = db('Addons');
$list = array(); $list = array();
$map = array( $map = array(
'status' => array('gt',0), 'status' => array('gt', 0),
); );
$list = $model->field("name,id,title,'' as 'style'")->where($map)->select(); $list = $model->field("name,id,title,'' as 'style'")->where($map)->select();
$menu = array(); $menu = array();
foreach ($list as $key => $value) { foreach ($list as $key => $value) {
$class = "\\addons\\".strtolower($value['name'])."\\controller\\Admin"; $class = "\\addons\\" . strtolower($value['name']) . "\\controller\\Admin";
if (is_file(ROOT_PATH . $class.".php")) { if (is_file(ROOT_PATH . $class . ".php")) {
$action = get_class_methods($class); $action = get_class_methods($class);
$value['url'] = "admin/addons/execute?mc=".strtolower($value['name'])."&ac=".$action[0]; $value['url'] = "admin/addons/execute?mc=" . strtolower($value['name']) . "&ac=" . $action[0];
$menu[$key] = $value; $menu[$key] = $value;
} }
} }
if (!empty($menu)) { if (!empty($menu)) {
$this->assign('extend_menu',array('管理插件'=>$menu)); $this->assign('extend_menu', array('管理插件' => $menu));
} }
} }
protected function setMeta($title = ''){ protected function setMeta($title = '') {
$this->assign('meta_title',$title); $this->assign('meta_title', $title);
} }
} }

View File

@@ -13,7 +13,7 @@ class Api {
protected $data; protected $data;
public function __construct(){ public function __construct() {
$this->data = array('code' => 0, 'msg' => '', 'time' => time(), 'data' => ''); $this->data = array('code' => 0, 'msg' => '', 'time' => time(), 'data' => '');
} }
} }

View File

@@ -9,7 +9,7 @@
namespace app\common\controller; namespace app\common\controller;
class Base extends \think\Controller{ class Base extends \think\Controller {
protected $url; protected $url;
protected $request; protected $request;
@@ -17,31 +17,31 @@ class Base extends \think\Controller{
protected $controller; protected $controller;
protected $action; protected $action;
public function _initialize(){ public function _initialize() {
if (!is_file(APP_PATH . 'database.php') || !is_file(APP_PATH . 'install.lock')) { if (!is_file(APP_PATH . 'database.php') || !is_file(APP_PATH . 'install.lock')) {
return $this->redirect('install/index/index'); return $this->redirect('install/index/index');
} }
/* 读取数据库中的配置 */ /* 读取数据库中的配置 */
$config = cache('db_config_data'); $config = cache('db_config_data');
if(!$config){ if (!$config) {
$config = model('Config')->lists(); $config = model('Config')->lists();
cache('db_config_data',$config); cache('db_config_data', $config);
} }
config($config); config($config);
//获取request信息 //获取request信息
$this->requestInfo(); $this->requestInfo();
} }
public function execute($mc = null, $op = '', $ac = null){ public function execute($mc = null, $op = '', $ac = null) {
$op = $op ? $op : $this->request->module(); $op = $op ? $op : $this->request->module();
if(\think\Config::get('url_case_insensitive')){ if (\think\Config::get('url_case_insensitive')) {
$mc = ucfirst(parse_name($mc, 1)); $mc = ucfirst(parse_name($mc, 1));
$op = parse_name($op,1); $op = parse_name($op, 1);
} }
if(!empty($mc) && !empty($op) && !empty($ac)){ if (!empty($mc) && !empty($op) && !empty($ac)) {
$ops = ucwords($op); $ops = ucwords($op);
$class = "\\addons\\{$mc}\\controller\\{$ops}"; $class = "\\addons\\{$mc}\\controller\\{$ops}";
$addons = new $class; $addons = new $class;
$addons->$ac(); $addons->$ac();
} else { } else {
@@ -55,34 +55,38 @@ class Base extends \think\Controller{
* @param string $tablepre 自己的前缀 * @param string $tablepre 自己的前缀
* @return multitype:string 返回最终需要的sql语句 * @return multitype:string 返回最终需要的sql语句
*/ */
public function sql_split($sql, $tablepre) { public function sqlSplit($sql, $tablepre) {
if ($tablepre != "sent_") if ($tablepre != "sent_") {
$sql = str_replace("sent_", $tablepre, $sql); $sql = str_replace("sent_", $tablepre, $sql);
$sql = preg_replace("/TYPE=(InnoDB|MyISAM|MEMORY)( DEFAULT CHARSET=[^; ]+)?/", "ENGINE=\\1 DEFAULT CHARSET=utf8", $sql); }
if ($r_tablepre != $s_tablepre){ $sql = preg_replace("/TYPE=(InnoDB|MyISAM|MEMORY)( DEFAULT CHARSET=[^; ]+)?/", "ENGINE=\\1 DEFAULT CHARSET=utf8", $sql);
$sql = str_replace($s_tablepre, $r_tablepre, $sql);
$sql = str_replace("\r", "\n", $sql); if ($r_tablepre != $s_tablepre) {
$ret = array(); $sql = str_replace($s_tablepre, $r_tablepre, $sql);
$num = 0; $sql = str_replace("\r", "\n", $sql);
$queriesarray = explode(";\n", trim($sql)); $ret = array();
unset($sql); $num = 0;
foreach ($queriesarray as $query) { $queriesarray = explode(";\n", trim($sql));
$ret[$num] = ''; unset($sql);
$queries = explode("\n", trim($query)); foreach ($queriesarray as $query) {
$queries = array_filter($queries); $ret[$num] = '';
foreach ($queries as $query) { $queries = explode("\n", trim($query));
$str1 = substr($query, 0, 1); $queries = array_filter($queries);
if ($str1 != '#' && $str1 != '-') foreach ($queries as $query) {
$ret[$num] .= $query; $str1 = substr($query, 0, 1);
if ($str1 != '#' && $str1 != '-') {
$ret[$num] .= $query;
} }
$num++;
} }
$num++;
} }
}
return $ret; return $ret;
} }
protected function setSeo($title = '', $keywords = '', $description = ''){ protected function setSeo($title = '', $keywords = '', $description = '') {
$seo = array( $seo = array(
'title' => $title, 'title' => $title,
'keywords' => $keywords, 'keywords' => $keywords,
@@ -94,7 +98,7 @@ class Base extends \think\Controller{
if (is_array($item)) { if (is_array($item)) {
$item = implode(',', $item); $item = implode(',', $item);
} }
$meta[$key] = str_replace("[".$key."]", $item . '|', $meta[$key]); $meta[$key] = str_replace("[" . $key . "]", $item . '|', $meta[$key]);
} }
$data = array( $data = array(
@@ -105,15 +109,13 @@ class Base extends \think\Controller{
$this->assign($data); $this->assign($data);
} }
/** /**
* 验证码 * 验证码
* @param integer $id 验证码ID * @param integer $id 验证码ID
* @author 郭平平 <molong@tensent.cn> * @author 郭平平 <molong@tensent.cn>
*/ */
public function verify($id = 1){ public function verify($id = 1) {
$verify = new \org\Verify(array('length'=>4)); $verify = new \org\Verify(array('length' => 4));
$verify->entry($id); $verify->entry($id);
} }
@@ -123,20 +125,20 @@ class Base extends \think\Controller{
* @return boolean 检测结果 * @return boolean 检测结果
* @author 麦当苗儿 <zuojiazi@vip.qq.com> * @author 麦当苗儿 <zuojiazi@vip.qq.com>
*/ */
public function checkVerify($code, $id = 1){ public function checkVerify($code, $id = 1) {
if ($code) { if ($code) {
$verify = new \org\Verify(); $verify = new \org\Verify();
$result = $verify->check($code, $id); $result = $verify->check($code, $id);
if (!$result) { if (!$result) {
return $this->error("验证码错误!", ""); return $this->error("验证码错误!", "");
} }
}else{ } else {
return $this->error("验证码为空!", ""); return $this->error("验证码为空!", "");
} }
} }
//request信息 //request信息
protected function requestInfo(){ protected function requestInfo() {
$this->param = $this->request->param(); $this->param = $this->request->param();
defined('MODULE_NAME') or define('MODULE_NAME', $this->request->module()); defined('MODULE_NAME') or define('MODULE_NAME', $this->request->module());
defined('CONTROLLER_NAME') or define('CONTROLLER_NAME', $this->request->controller()); defined('CONTROLLER_NAME') or define('CONTROLLER_NAME', $this->request->controller());
@@ -144,17 +146,17 @@ class Base extends \think\Controller{
defined('IS_POST') or define('IS_POST', $this->request->isPost()); defined('IS_POST') or define('IS_POST', $this->request->isPost());
defined('IS_GET') or define('IS_GET', $this->request->isGet()); defined('IS_GET') or define('IS_GET', $this->request->isGet());
$this->url = $this->request->module() . '/' . $this->request->controller() . '/' . $this->request->action(); $this->url = $this->request->module() . '/' . $this->request->controller() . '/' . $this->request->action();
$this->assign('request',$this->request); $this->assign('request', $this->request);
$this->assign('param',$this->param); $this->assign('param', $this->param);
} }
/** /**
* 获取单个参数的数组形式 * 获取单个参数的数组形式
*/ */
protected function getArrayParam($param){ protected function getArrayParam($param) {
if (isset($this->param['id'])) { if (isset($this->param['id'])) {
return array_unique((array)$this->param[$param]); return array_unique((array) $this->param[$param]);
}else{ } else {
return array(); return array();
} }
} }

View File

@@ -9,9 +9,9 @@
namespace app\common\controller; namespace app\common\controller;
class Fornt extends Base{ class Fornt extends Base {
public function _initialize(){ public function _initialize() {
parent::_initialize(); parent::_initialize();
//判读是否为关闭网站 //判读是否为关闭网站
@@ -27,7 +27,7 @@ class Fornt extends Base{
} }
//当前栏目导航 //当前栏目导航
protected function setHoverNav(){ protected function setHoverNav() {
//dump($_SERVER['PHP_SELF']); //dump($_SERVER['PHP_SELF']);
} }
} }

View File

@@ -11,21 +11,24 @@ namespace app\common\controller;
class Upload { class Upload {
public function upload(){ /**
$upload_type = input('get.filename','images','trim'); * 上传控制器
$config = $this->$upload_type(); */
public function upload() {
$upload_type = input('get.filename', 'images', 'trim');
$config = $this->$upload_type();
// 获取表单上传文件 例如上传了001.jpg // 获取表单上传文件 例如上传了001.jpg
$file = request()->file('file'); $file = request()->file('file');
$info = $file->move($config['rootPath'], true, false); $info = $file->move($config['rootPath'], true, false);
if($info){ if ($info) {
$return['status'] = 1; $return['status'] = 1;
$return['info'] = $this->save($config, $upload_type, $info); $return['info'] = $this->save($config, $upload_type, $info);
}else{ } else {
$return['status'] = 0; $return['status'] = 0;
$return['info'] = $file->getError(); $return['info'] = $file->getError();
} }
echo json_encode($return); echo json_encode($return);
} }
@@ -34,7 +37,7 @@ class Upload {
* @var view * @var view
* @access public * @access public
*/ */
protected function images(){ protected function images() {
return config('picture_upload'); return config('picture_upload');
} }
@@ -43,7 +46,7 @@ class Upload {
* @var view * @var view
* @access public * @access public
*/ */
protected function attachment(){ protected function attachment() {
return config('attachment_upload'); return config('attachment_upload');
} }
@@ -52,26 +55,26 @@ class Upload {
* @var view * @var view
* @access public * @access public
*/ */
public function ueditor(){ public function ueditor() {
$data = new \com\Ueditor(session('auth_user.uid')); $data = new \com\Ueditor(session('auth_user.uid'));
echo $data->output(); echo $data->output();
} }
public function editor(){ public function editor() {
$file = request()->file('upload_file'); $file = request()->file('upload_file');
$info = $file->move(config('editor_upload.rootPath'), true, false); $info = $file->move(config('editor_upload.rootPath'), true, false);
if ($info) { if ($info) {
$data = $this->parse_file($info); $data = $this->parseFile($info);
$data['success'] = true; $data['success'] = true;
$data['file_path'] = $data['url']; $data['file_path'] = $data['url'];
}else{ } else {
$data['success'] = false; $data['success'] = false;
$data['msg'] = "error message"; $data['msg'] = "error message";
} }
return $data; return $data;
} }
public function delete(){ public function delete() {
$data = array( $data = array(
'status' => 1, 'status' => 1,
); );
@@ -83,16 +86,16 @@ class Upload {
* @var view * @var view
* @access public * @access public
*/ */
public function save($config, $type, $file){ public function save($config, $type, $file) {
$file = $this->parse_file($file); $file = $this->parseFile($file);
$file['status'] = 1; $file['status'] = 1;
$dbname = ($type == 'images') ? 'picture' : 'file'; $dbname = ($type == 'images') ? 'picture' : 'file';
$id = db($dbname)->insertGetId($file); $id = db($dbname)->insertGetId($file);
if ($id) { if ($id) {
$data = db($dbname)->where(array('id'=>$id))->find(); $data = db($dbname)->where(array('id' => $id))->find();
return $data; return $data;
}else{ } else {
return false; return false;
} }
} }
@@ -104,21 +107,22 @@ class Upload {
* @param string $args 回调函数参数 * @param string $args 回调函数参数
* @return boolean 下载失败返回false * @return boolean 下载失败返回false
*/ */
public function downLocalFile($file, $callback = null, $args = null){ public function downLocalFile($file, $callback = null, $args = null) {
if(is_file($file['rootpath'].$file['savepath'].$file['savename'])){ if (is_file($file['rootpath'] . $file['savepath'] . $file['savename'])) {
/* 调用回调函数新增下载数 */ /* 调用回调函数新增下载数 */
is_callable($callback) && call_user_func($callback, $args); is_callable($callback) && call_user_func($callback, $args);
/* 执行下载 */ //TODO: 大文件断点续传 /* 执行下载 *///TODO: 大文件断点续传
header("Content-Description: File Transfer"); header("Content-Description: File Transfer");
header('Content-type: ' . $file['type']); header('Content-type: ' . $file['type']);
header('Content-Length:' . $file['size']); header('Content-Length:' . $file['size']);
if (preg_match('/MSIE/', $_SERVER['HTTP_USER_AGENT'])) { //for IE if (preg_match('/MSIE/', $_SERVER['HTTP_USER_AGENT'])) {
//for IE
header('Content-Disposition: attachment; filename="' . rawurlencode($file['name']) . '"'); header('Content-Disposition: attachment; filename="' . rawurlencode($file['name']) . '"');
} else { } else {
header('Content-Disposition: attachment; filename="' . $file['name'] . '"'); header('Content-Disposition: attachment; filename="' . $file['name'] . '"');
} }
readfile($file['rootpath'].$file['savepath'].$file['savename']); readfile($file['rootpath'] . $file['savepath'] . $file['savename']);
exit; exit;
} else { } else {
$this->error = '文件已被删除!'; $this->error = '文件已被删除!';
@@ -126,23 +130,23 @@ class Upload {
} }
} }
protected function parse_file($info){ protected function parseFile($info) {
$data['create_time'] = $info->getATime(); //最后访问时间 $data['create_time'] = $info->getATime(); //最后访问时间
$data['savename'] = $info->getBasename(); //获取无路径的basename $data['savename'] = $info->getBasename(); //获取无路径的basename
$data['c_time'] = $info->getCTime(); //获取inode修改时间 $data['c_time'] = $info->getCTime(); //获取inode修改时间
$data['ext'] = $info->getExtension(); //文件扩展名 $data['ext'] = $info->getExtension(); //文件扩展名
$data['name'] = $info->getFilename(); //获取文件名 $data['name'] = $info->getFilename(); //获取文件名
$data['m_time'] = $info->getMTime(); //获取最后修改时间 $data['m_time'] = $info->getMTime(); //获取最后修改时间
$data['owner'] = $info->getOwner(); //文件拥有者 $data['owner'] = $info->getOwner(); //文件拥有者
$data['savepath'] = $info->getPath(); //不带文件名的文件路径 $data['savepath'] = $info->getPath(); //不带文件名的文件路径
$data['url'] = $data['path'] = str_replace("\\", '/', substr($info->getPathname(), 1)); //全路径 $data['url'] = $data['path'] = str_replace("\\", '/', substr($info->getPathname(), 1)); //全路径
$data['size'] = $info->getSize(); //文件大小,单位字节 $data['size'] = $info->getSize(); //文件大小,单位字节
$data['is_file'] = $info->isFile(); //是否是文件 $data['is_file'] = $info->isFile(); //是否是文件
$data['is_execut'] = $info->isExecutable(); //是否可执行 $data['is_execut'] = $info->isExecutable(); //是否可执行
$data['is_readable'] = $info->isReadable(); //是否可读 $data['is_readable'] = $info->isReadable(); //是否可读
$data['is_writable'] = $info->isWritable(); //是否可写 $data['is_writable'] = $info->isWritable(); //是否可写
$data['md5'] = md5_file($info->getPathname()); $data['md5'] = md5_file($info->getPathname());
$data['sha1'] = sha1_file($info->getPathname()); $data['sha1'] = sha1_file($info->getPathname());
return $data; return $data;
} }
} }

View File

@@ -9,14 +9,14 @@
namespace app\common\controller; namespace app\common\controller;
class User extends Base{ class User extends Base {
public function _initialize(){ public function _initialize() {
parent::_initialize(); parent::_initialize();
if (!is_login() and !in_array($this->url,array('user/login/index', 'user/index/verify'))) { if (!is_login() and !in_array($this->url, array('user/login/index', 'user/index/verify'))) {
$this->redirect('user/login/index');exit(); $this->redirect('user/login/index');exit();
}elseif (is_login()) { } elseif (is_login()) {
$user = model('User')->getInfo(session('user_auth.uid')); $user = model('User')->getInfo(session('user_auth.uid'));
if (!$this->checkProfile($user) && $this->url !== 'user/profile/index') { if (!$this->checkProfile($user) && $this->url !== 'user/profile/index') {
return $this->error('请补充完个人资料!', url('user/profile/index')); return $this->error('请补充完个人资料!', url('user/profile/index'));
@@ -28,14 +28,14 @@ class User extends Base{
} }
} }
protected function setMenu(){ protected function setMenu() {
$menu['基础设置'] = array( $menu['基础设置'] = array(
array('title'=>'个人资料', 'url'=>'user/profile/index', 'icon'=>'newspaper-o'), array('title' => '个人资料', 'url' => 'user/profile/index', 'icon' => 'newspaper-o'),
array('title'=>'密码修改', 'url'=>'user/profile/editpw', 'icon'=>'key'), array('title' => '密码修改', 'url' => 'user/profile/editpw', 'icon' => 'key'),
array('title'=>'更换头像', 'url'=>'user/profile/avatar', 'icon'=>'male'), array('title' => '更换头像', 'url' => 'user/profile/avatar', 'icon' => 'male'),
); );
$menu['订单管理'] = array( $menu['订单管理'] = array(
array('title'=>'我的订单', 'url'=>'user/order/index', 'icon'=>'shopping-bag'), array('title' => '我的订单', 'url' => 'user/order/index', 'icon' => 'shopping-bag'),
); );
$contetnmenu = $this->getContentMenu(); $contetnmenu = $this->getContentMenu();
if (!empty($contetnmenu)) { if (!empty($contetnmenu)) {
@@ -46,7 +46,7 @@ class User extends Base{
foreach ($item as $key => $value) { foreach ($item as $key => $value) {
if (url($value['url']) == $_SERVER['REQUEST_URI']) { if (url($value['url']) == $_SERVER['REQUEST_URI']) {
$value['active'] = 'active'; $value['active'] = 'active';
}else{ } else {
$value['active'] = ''; $value['active'] = '';
} }
$menu[$group][$key] = $value; $menu[$group][$key] = $value;
@@ -55,25 +55,25 @@ class User extends Base{
$this->assign('__MENU__', $menu); $this->assign('__MENU__', $menu);
} }
protected function getContentMenu(){ protected function getContentMenu() {
$list = array(); $list = array();
$map = array( $map = array(
'is_user_show' => 1, 'is_user_show' => 1,
'status' => array('gt',0), 'status' => array('gt', 0),
'extend' => array('gt',0), 'extend' => array('gt', 0),
); );
$list = db('Model')->where($map)->field("name,id,title,icon,'' as 'style'")->select(); $list = db('Model')->where($map)->field("name,id,title,icon,'' as 'style'")->select();
foreach ($list as $key => $value) { foreach ($list as $key => $value) {
$value['url'] = "user/content/index?model_id=".$value['id']; $value['url'] = "user/content/index?model_id=" . $value['id'];
$value['title'] = $value['title']."管理"; $value['title'] = $value['title'] . "管理";
$value['icon'] = $value['icon'] ? $value['icon'] : 'file'; $value['icon'] = $value['icon'] ? $value['icon'] : 'file';
$list[$key] = $value; $list[$key] = $value;
} }
return $list; return $list;
} }
protected function checkProfile($user){ protected function checkProfile($user) {
$result = true; $result = true;
//判断用户资料是否填写完整 //判断用户资料是否填写完整
if (!$user['nickname'] || !$user['qq']) { if (!$user['nickname'] || !$user['qq']) {

View File

@@ -2,7 +2,7 @@
<div id="picker_{$field}" class="picker_button">上传文件</div> <div id="picker_{$field}" class="picker_button">上传文件</div>
<input type="hidden" name="{$field}" id="field_{$field}" value="{$value|default=''}"> <input type="hidden" name="{$field}" id="field_{$field}" value="{$value|default=''}">
<div id="fileList_{$field}" class="upload-file-list-info" style="width:280px;"> <div id="fileList_{$field}" class="upload-file-list-info" style="width:280px;">
{if isset($value)} {if isset($value) && $value}
<li class="affix-list-item" id="WU_FILE_0"> <li class="affix-list-item" id="WU_FILE_0">
<div class="upload-file-info"> <div class="upload-file-info">
<span class="webuploader-pick-file-close" data-queued-id="WU_FILE_0" data-id="{$value}" data-fileurl="{$value|get_file=###,"savename"}"><i class="close"></i></span> <span class="webuploader-pick-file-close" data-queued-id="WU_FILE_0" data-id="{$value}" data-fileurl="{$value|get_file=###,"savename"}"><i class="close"></i></span>

View File

@@ -1,4 +1,12 @@
<?php <?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace app\common\widget; namespace app\common\widget;
/** /**
@@ -6,69 +14,69 @@ namespace app\common\widget;
* 用于动态调用分类信息 * 用于动态调用分类信息
*/ */
class Ad{ class Ad {
public function run($name){ public function run($name) {
$map['name'] = $name; $map['name'] = $name;
$place = db('AdPlace')->where($map)->find(); $place = db('AdPlace')->where($map)->find();
if (empty($place) || !$place) { if (empty($place) || !$place) {
echo "";return; echo "";return;
} }
if ($place['status'] != '1') { if ($place['status'] != '1') {
echo "";return; echo "";return;
} }
$ad = db('Ad')->where(array('place_id'=>$place['id'],'status'=>1))->select(); $ad = db('Ad')->where(array('place_id' => $place['id'], 'status' => 1))->select();
$list = array(); $list = array();
foreach ($ad as $key => $value) { foreach ($ad as $key => $value) {
if ($value['photolist'] != '') { if ($value['photolist'] != '') {
$photolist = explode(',', $value['photolist']); $photolist = explode(',', $value['photolist']);
$listurl = explode("\n", $value['listurl']); $listurl = explode("\n", $value['listurl']);
foreach ($photolist as $k => $val) { foreach ($photolist as $k => $val) {
$value['image'][] = array('img'=>get_cover($val,'path'),'url'=>$listurl[$k]); $value['image'][] = array('img' => get_cover($val, 'path'), 'url' => $listurl[$k]);
} }
}else{ } else {
$value['image'] = array(); $value['image'] = array();
} }
if ($value['cover_id']) { if ($value['cover_id']) {
$value['cover'] = get_cover($value['cover_id'],'path'); $value['cover'] = get_cover($value['cover_id'], 'path');
} }
$list[] = $value; $list[] = $value;
} }
switch ($place['show_type']) { switch ($place['show_type']) {
//幻灯片显示 //幻灯片显示
case '1': case '1':
$template = $place['template'] ? $place['template'] : "sider"; $template = $place['template'] ? $place['template'] : "sider";
break; break;
//对联广告 //对联广告
case '2': case '2':
$template = $place['template'] ? $place['template'] : "couplet"; $template = $place['template'] ? $place['template'] : "couplet";
break; break;
//图片列表广告 //图片列表广告
case '3': case '3':
$template = $place['template'] ? $place['template'] : "image"; $template = $place['template'] ? $place['template'] : "image";
break; break;
//图文列表广告 //图文列表广告
case '4': case '4':
$template = $place['template'] ? $place['template'] : "images"; $template = $place['template'] ? $place['template'] : "images";
break; break;
//文字列表广告 //文字列表广告
case '5': case '5':
$template = $place['template'] ? $place['template'] : "text"; $template = $place['template'] ? $place['template'] : "text";
break; break;
//代码广告广告 //代码广告广告
case '6': case '6':
$template = $place['template'] ? $place['template'] : "code"; $template = $place['template'] ? $place['template'] : "code";
break; break;
default: default:
$template = $place['template'] ? $place['template'] : "default"; $template = $place['template'] ? $place['template'] : "default";
break; break;
} }
$data = array( $data = array(
'place' => $place, 'place' => $place,
'ad' => $list, 'ad' => $list,
); );
$view = new \think\View(); $view = new \think\View();
$view->assign($data); $view->assign($data);
return $view->fetch('common@default/ad/'.$template); return $view->fetch('common@default/ad/' . $template);
} }
} }

View File

@@ -1,4 +1,12 @@
<?php <?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace app\common\widget; namespace app\common\widget;
/** /**
@@ -7,7 +15,7 @@ namespace app\common\widget;
*/ */
class Form { class Form {
public function show($field, $info){ public function show($field, $info) {
$type = isset($field['type']) ? $field['type'] : 'text'; $type = isset($field['type']) ? $field['type'] : 'text';
//类型合并 //类型合并
if (in_array($type, array('string'))) { if (in_array($type, array('string'))) {
@@ -17,16 +25,16 @@ class Form {
$type = 'image'; $type = 'image';
} }
$data = array( $data = array(
'type' => $type, 'type' => $type,
'field' => isset($field['name']) ? $field['name'] : '', 'field' => isset($field['name']) ? $field['name'] : '',
'value' => isset($info[$field['name']]) ? $info[$field['name']] : '', 'value' => isset($info[$field['name']]) ? $info[$field['name']] : '',
'size' => isset($field['size']) ? $field['size'] : 12, 'size' => isset($field['size']) ? $field['size'] : 12,
'option' =>isset($field['option']) ? $field['option'] : '' 'option' => isset($field['option']) ? $field['option'] : '',
); );
$no_tem = array('readonly', 'text', 'password', 'textarea', 'select', 'bind', 'checkbox', 'radio', 'num','bool','decimal'); $no_tem = array('readonly', 'text', 'password', 'textarea', 'select', 'bind', 'checkbox', 'radio', 'num', 'bool', 'decimal');
$type = !in_array($type, $no_tem) ? $type : 'show'; $type = !in_array($type, $no_tem) ? $type : 'show';
$view = new \think\View(); $view = new \think\View();
$view->assign($data); $view->assign($data);
return $view->fetch('common@default/form/'.$type); return $view->fetch('common@default/form/' . $type);
} }
} }