初始化项目

This commit is contained in:
2016-06-21 17:12:08 +08:00
commit 7ea154d684
903 changed files with 226100 additions and 0 deletions

View File

@@ -0,0 +1,229 @@
<?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\admin\controller;
use app\common\controller\Admin;
class Action extends Admin {
/**
* 用户行为列表
* @author huajie <banhuajie@163.com>
*/
public function index() {
$map = array('status' => array('gt', -1));
$order = "id desc";
//获取列表数据
$list = model('Action')->where($map)->order($order)->paginate(10);
// 记录当前列表页的cookie
Cookie('__forward__', $_SERVER['REQUEST_URI']);
$data = array(
'list' => $list,
'page' => $list->render()
);
$this->assign($data);
$this->setMeta('用户行为');
return $this->fetch();
}
/**
* 新建用户行为
* @author colin <colin@tensent.cn>
*/
public function add(){
$model = model('Action');
if(IS_POST){
$data = $model->create();
if(!$data){
return $this->error($model->getError());
}else{
$result = $model->add();
if ($result) {
action_log('add_action', 'Action', $result, session('user_auth.uid'));
return $this->success('添加成功!',url('index'));
}else{
return $this->error($model->getError());
}
}
}else{
$data = array(
'keyList' => $model->fieldlist
);
$this->assign($data);
$this->setMeta("添加行为");
return $this->fetch('public/edit');
}
}
/**
* 编辑用户行为
* @author colin <colin@tensent.cn>
*/
public function edit($id = null){
$model = model('Action');
if(IS_POST){
$model = D('Action');
$data = $model->create();
if(!$data){
return $this->error($model->getError());
}else{
$result = $model->save();
if ($result !== false) {
action_log('edit_action', 'Action', $id, session('user_auth.uid'));
return $this->success('编辑成功!',url('index'));
}else{
return $this->error($model->getError());
}
}
}else{
$info = $model::where(array('id'=>$id))->find();
if (!$info) {
return $this->error("非法操作!");
}
$data = array(
'info' => $info,
'keyList' => $model->fieldlist
);
$this->assign($data);
$this->setMeta("编辑行为");
return $this->fetch('public/edit');
}
}
/**
* 删除用户行为状态
* @author colin <colin@tensent.cn>
*/
public function del(){
if (IS_POST) {
$ids = input('ids/a',array());
$id = input('id','');
array_push($ids, $id);
if(empty($ids)){
return $this->error("非法操作!",'');
}
$map['id'] = array('IN',$ids);
$result = db('Action')->where($map)->delete();
if ($result) {
action_log('delete_action', 'Action', $id, session('user_auth.uid'));
return $this->success('删除成功!');
}else{
return $this->error('删除失败!');
}
}else{
return $this->error("非法操作!");
}
}
/**
* 修改用户行为状态
* @author colin <colin@tensent.cn>
*/
public function setstatus(){
$ids = input('ids/a',array());
$id = input('id','');
array_push($ids, $id);
if(empty($ids)){
return $this->error("非法操作!",'');
}
$status = input('get.status','','trim,intval');
$message = !$status ? '禁用' : '启用';
$map['id'] = array('IN',$ids);
$result = db('Action')->where($map)->setField('status',$status);
if ($result !== false) {
action_log('setstatus_action', 'Action', $id, session('user_auth.uid'));
return $this->success('设置'.$message.'状态成功!','');
}else{
return $this->error('设置'.$message.'状态失败!','');
}
}
/**
* 行为日志列表
* @author huajie <banhuajie@163.com>
*/
public function log() {
//获取列表数据
$map['status'] = array('gt', -1);
$order = "id desc";
//获取列表数据
$list = model('ActionLog')->where($map)->order($order)->paginate(10);
$data = array(
'list' => $list,
'page' => $list->render()
);
$this->assign($data);
$this->setMeta('行为日志');
return $this->fetch();
}
/**
* 查看行为日志
* @author huajie <banhuajie@163.com>
*/
public function detail($id = 0) {
$model = model('ActionLog');
if (empty($id)) {
return $this->error('参数错误!');
}
$info = $model::get($id);
$info['title'] = get_action($info['action_id'],'title');
$info['user_id'] = get_username($info['user_id']);
$info['action_ip'] = long2ip($info['action_ip']);
$info['create_time'] = date('Y-m-d H:i:s',$info['create_time']);
$data = array(
'info' => $info,
'keyList' => $model->keyList
);
$this->assign($data);
$this->setMeta('查看行为日志');
return $this->fetch();
}
/**
* 删除日志
* @param mixed $ids
* @author huajie <banhuajie@163.com>
*/
public function dellog() {
$ids = input('ids/a',array());
$id = input('id','');
array_push($ids, $id);
if(empty($ids)){
return $this->error("非法操作!",'');
}
$map['id'] = array('IN',$ids);
$res = db('ActionLog')->where($map)->delete();
if ($res !== false) {
action_log('delete_actionlog', 'ActionLog', $id, session('user_auth.uid'));
return $this->success('删除成功!');
} else {
return $this->error('删除失败!');
}
}
/**
* 清空日志
*/
public function clear($id = '') {
$res = db('ActionLog')->where('1=1')->delete();
if ($res !== false) {
//记录行为
action_log('clear_actionlog', 'ActionLog', $id, session('user_auth.uid'));
return $this->success('日志清空成功!');
}
else {
return $this->error('日志清空失败!');
}
}
}

View File

@@ -0,0 +1,191 @@
<?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\admin\controller;
use app\common\controller\Admin;
class Ad extends Admin {
protected $ad;
protected $adplace;
public function _initialize(){
parent::_initialize();
$this->ad = db('Ad');
$this->adplace = db('AdPlace');
}
/**
* 插件列表
*/
public function index(){
$map = array();
$order = "id desc";
$list = db('AdPlace')->where($map)->order($order)->paginate(10);
$data = array(
'list' => $list,
'page' => $list->render()
);
$this->assign($data);
$this->setMeta("广告管理");
return $this->fetch();
}
/**
* 广告位添加
*/
public function add(){
$place = model('AdPlace');
if (IS_POST) {
$data = input('post.');
$result = $place->save($data);
if (false !== false) {
return $this->success("添加成功!");
}else{
return $this->error($place->getError());
}
}else{
$data = array(
'keyList' => $place->keyList
);
$this->assign($data);
$this->setMeta("添加广告位");
return $this->fetch('public/edit');
}
}
public function edit($id = null){
$place = model('AdPlace');
if (IS_POST) {
$data = input('post.','');
if ($data) {
$result = $place->save($data,array('id'=>$data['id']));
if ($result) {
return $this->success("修改成功!", url('admin/ad/index'));
}else{
return $this->error($this->adplace->getError());
}
}else{
return $this->error($this->adplace->getError());
}
}else{
$info = db('AdPlace')->where(array('id'=>$id))->find();
if (!$info) {
return $this->error("非法操作!");
}
$data = array(
'info' => $info,
'keyList' => $place->keyList
);
$this->assign($data);
$this->setMeta("编辑广告位");
return $this->fetch('public/edit');
}
}
public function del(){
$id = input('id','');
if (!$id) {
return $this->error("非法操作!");
}
$map['id'] = array('IN',$id);
$result = $this->adplace->where($map)->delete();
if ($result) {
return $this->success("删除成功!");
}else{
return $this->error("删除失败!");
}
}
public function lists($id = null){
$map['place_id'] = $id;
$order = "id desc";
$list = db('Ad')->where($map)->order($order)->paginate(10);
$data = array(
'id' => $id,
'list' => $list,
'page' => $list->render()
);
$this->assign($data);
$this->setMeta("广告管理");
return $this->fetch();
}
public function addad($id){
$ad = model('ad');
if (IS_POST) {
$data = input('post.');
if ($data) {
$result = $ad->save($data);
if ($result) {
return $this->success("添加成功!", url('admin/ad/lists',array('id'=>$data['place_id'])));
}else{
return $this->error($ad->getError());
}
}else{
return $this->error($ad->getError());
}
}else{
$info['place_id'] = $id;
$data = array(
'info' => $info,
'keyList' => $ad->keyList
);
$this->assign($data);
$this->setMeta("添加广告位");
return $this->fetch('public/edit');
}
}
public function editad($id = null){
$ad = model('ad');
if (IS_POST) {
$data = input('post.');
if ($data) {
$result = $ad->save($data,array('id'=>$data['id']));
if ($result) {
return $this->success("修改成功!", url('admin/ad/lists',array('id'=>$data['place_id'])));
}else{
return $this->error($ad->getError());
}
}else{
return $this->error($ad->getError());
}
}else{
$info = db('ad')->where(array('id'=>$id))->find();
if (!$info) {
return $this->error("非法操作!");
}
$data = array(
'info' => $info,
'keyList' => $ad->keyList
);
$this->assign($data);
$this->setMeta("编辑广告位");
return $this->fetch('public/edit');
}
}
public function delad(){
$id = input('id','');
if (!$id) {
return $this->error("非法操作!");
}
$map['id'] = array('IN',$id);
$result = db('ad')->where($map)->delete();
if ($result) {
return $this->success("删除成功!");
}else{
return $this->error("删除失败!");
}
}
}

View File

@@ -0,0 +1,336 @@
<?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\admin\controller;
use app\common\controller\Admin;
class Addons extends Admin {
protected $addons;
public function _initialize(){
parent::_initialize();
//加入菜单
$this->getAddonsMenu();
$this->addons = model('Addons');
$this->hooks = db('Hooks');
}
/**
* 插件列表
*/
public function index(){
$row = $this->addons->getList();
foreach($row as $key => $value){
$value['status_text'] = '';
if($value['uninstall'] == 1){
$value['uninstall_text'] = '未安装';
}else{
$value['uninstall_text'] = '已安装';
if($value['status'] == 0){
$value['status_text'] = '禁用';
}else{
$value['status_text'] = '启用';
}
}
$list[] = $value;
}
// 记录当前列表页的cookie
Cookie('__forward__',$_SERVER['REQUEST_URI']);
$data = array(
'list' => $list,
//'page' => $page->show()
);
$this->setMeta("插件管理");
$this->assign($data);
return $this->fetch();
}
//创建向导首页
public function add(){
if (IS_POST) {
$data = $this->addons->create();
if ($data) {
if ($result) {
return $this->success("创建成功!",url('admin/addons/index'));
}else{
return $this->error("创建失败!",'');
}
}else{
return $this->error($this->addons->getError(),'');
}
}else{
$hooks = db('Hooks')->field('name,description')->select();
$this->assign('Hooks',$hooks);
$hook = db('Hooks')->field(true)->select();
foreach($hook as $key => $value){
$addons_opt[$value['name']] = $value['name'];
}
$addons_opt = array(array('type'=>'select','opt'=>$addons_opt));
if(!is_writable(SENT_ADDON_PATH)){
return $this->error('您没有创建目录写入权限,无法使用此功能');
}
$this->setMeta("添加插件");
return $this->fetch();
}
}
//预览
public function preview($output = true){
}
/**
* 安装插件
*/
public function install(){
$addon_name = input('addon_name','','trim,ucfirst');
$class = get_addon_class($addon_name);
if(class_exists($class)){
$addons = new $class;
$info = $addons->info;
if(!$info || !$addons->checkInfo()){
//检测信息的正确性
return $this->error('插件信息缺失');
}
session('addons_install_error',null);
$install_flag = $addons->install();
if(!$install_flag){
return $this->error('执行插件预安装操作失败'.session('addons_install_error'));
}
$result = $this->addons->install($info);
if($result){
cache('hooks', null);
return $this->success('安装成功');
}else{
return $this->error($this->addons->getError());
}
}else{
return $this->error('插件不存在','');
}
}
/**
* 卸载插件
*/
public function uninstall($id){
$result = $this->addons->uninstall($id);
if($result === false){
return $this->error($this->addons->getError(),'');
}else{
return $this->success('卸载成功!','');
}
}
/**
* 启用插件
*/
public function enable(){
$id = input('id');
cache('hooks', null);
$model = model('Addons');
$result = $model::where(array('id'=>$id))->update(array('status'=>1));
if ($result) {
return $this->success('启用成功');
}else{
return $this->error("启用失败!");
}
}
/**
* 禁用插件
*/
public function disable(){
$id = input('id');
cache('hooks', null);
$model = model('Addons');
$result = $model::where(array('id'=>$id))->update(array('status'=>0));
if ($result) {
return $this->success('禁用成功');
}else{
return $this->error("禁用失败!");
}
}
/**
* 设置插件页面
*/
public function config(){
if (IS_POST) {
# code...
}else{
$id = input('id','','trim,intval');
if (!$id) {
return $this->error("非法操作!",'');
}
$info = $this->addons->find($id);
if (!empty($info)) {
$class = get_addon_class($info['name']);
$keyList = array();
$data = array(
'keyList' => $keyList
);
$this->assign($data);
$this->setMeta($info['title'] . " - 设置");
return $this->fetch('public/edit');
}else{
return $this->error("未安装此插件!");
}
}
}
/**
* 获取插件所需的钩子是否存在,没有则新增
* @param string $str 钩子名称
* @param string $addons 插件名称
* @param string $addons 插件简介
*/
public function existHook($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();
S('hooks', null);
}
/**
* 钩子列表
*/
public function hooks(){
$map = array();
$order = "id desc";
$list = model('Hooks')->where($map)->order($order)->paginate(10);
// 记录当前列表页的cookie
Cookie('__forward__',$_SERVER['REQUEST_URI']);
$data = array(
'list' => $list,
'page' => $list->render()
);
$this->setMeta("钩子管理");
$this->assign($data);
return $this->fetch();
}
public function addhook(){
$hooks = model('Hooks');
if (IS_POST) {
$data = input();
if ($data) {
$result = $hooks->change($data);
if ($result !== false) {
return $this->success("修改成功");
}else{
return $this->error($hooks->getError());
}
}else{
return $this->error($hooks->getError());
}
}else{
$keylist = $hooks->getaddons();
$data = array(
'keyList' => $keylist,
);
$this->assign($data);
$this->setMeta('编辑钩子');
return $this->fetch('public/edit');
}
}
//钩子出编辑挂载插件页面
public function edithook($id){
$hooks = model('Hooks');
if (IS_POST) {
$data = input('post.');
if ($data) {
$result = $hooks->change($data);
if ($result !== false) {
return $this->success("修改成功");
}else{
return $this->error($hooks->getError());
}
}else{
return $this->error($hooks->getError());
}
}else{
$info = db('Hooks')->find($id);
$keylist = $hooks->getaddons($info['addons']);
$data = array(
'info' => $info,
'keyList' => $keylist,
);
$this->assign($data);
$this->setMeta('编辑钩子');
return $this->fetch('public/edit');
}
}
//超级管理员删除钩子
public function delhook(){
$id = input('id','','trim,intval');
$ids = input('post.ids/a',array());
array_push($ids, $id);
$map['id'] = array('IN',$ids);
$result = $this->hooks->where($map)->delete();
if($result !== false){
return $this->success('删除成功');
}else{
return $this->error('删除失败');
}
}
public function updateHook(){
$hookModel = D('Hooks');
$data = $hookModel->create();
if($data){
if($data['id']){
$flag = $hookModel->save($data);
if($flag !== false){
S('hooks', null);
$this->success('更新成功', Cookie('__forward__'));
}else{
$this->error('更新失败');
}
}else{
$flag = $hookModel->add($data);
if($flag){
S('hooks', null);
$this->success('新增成功', Cookie('__forward__'));
}else{
$this->error('新增失败');
}
}
}else{
$this->error($hookModel->getError());
}
}
}

View File

@@ -0,0 +1,166 @@
<?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\admin\controller;
use app\common\controller\Admin;
class Attribute extends Admin {
//保存的Model句柄
protected $model;
protected $attr;
//初始化
public function _initialize(){
parent::_initialize();
$this->getContentMenu();
$this->model = model('Attribute');
//遍历属性列表
foreach (get_attribute_type() as $key => $value) {
$this->attr[$key] = $value[0];
}
$this->validate_rule = array(
0=>'请选择',
'regex'=>'正则验证',
'function'=>'函数验证',
'unique'=>'唯一验证',
'length'=>'长度验证',
'in'=>'验证在范围内',
'notin'=>'验证不在范围内',
'between'=>'区间验证',
'notbetween'=>'不在区间验证'
);
$this->auto_type = array(0=>'请选择','function'=>'函数','field'=>'字段','string'=>'字符串');
$this->the_time = array(0=>'请选择','3'=>'始 终','1'=>'新 增','2'=>'编 辑');
$this->field = $this->getField();
}
/**
* index方法
* @author colin <colin@tensent.cn>
*/
public function index($model = null){
$model_id = input('get.model_id','','trim,intval');
$map['model_id'] = $model_id;
if (!$model_id) {
return $this->error("非法操作!");
}
$list = model('Attribute')->where($map)->order('id desc')->paginate(25);
$data = array(
'list' => $list,
'model_id'=> $model_id,
'page' => $list->render()
);
$this->assign($data);
$this->setMeta('字段管理');
return $this->fetch();
}
/**
* 创建字段
* @author colin <colin@tensent.cn>
*/
public function add(){
$model_id = input('get.model_id','','trim,intval');
if(IS_POST){
$result = $this->model->change();
if ($result) {
return $this->success("创建成功!",url('Attribute/index',array('model_id'=>$model_id)));
}else{
return $this->error($this->model->getError(),'');
}
}else{
if (!$model_id) {
return $this->error('非法操作!');
}
$data = array(
'info' => array('model_id'=>$model_id),
'fieldGroup' => $this->field
);
$this->assign($data);
$this->setMeta('添加字段');
return $this->fetch('public/edit');
}
}
/**
* 编辑字段方法
* @author colin <colin@tensent.cn>
*/
public function edit(){
if(IS_POST){
$result = $this->model->change();
if ($result) {
return $this->success("修改成功!",url('Attribute/index',array('model_id'=>$_POST['model_id'])));
}else{
return $this->error($this->model->getError(),'');
}
}else{
$id = input('get.id','','trim,intval');
$info = db('Attribute')->find($id);
$data = array(
'info' => $info,
'fieldGroup' => $this->field
);
$this->assign($data);
$this->setMeta('编辑字段');
return $this->fetch('public/edit');
}
}
/**
* 删除字段信息
* @var delattr 是否删除字段表里的字段
* @author colin <colin@tensent.cn>
*/
public function del(){
$id = input('id','','trim,intval');
if (!$id) {
return $this->error("非法操作!");
}
$result = $this->model->del($id);
if ($result) {
return $this->success("删除成功!");
}else{
return $this->error($this->model->getError());
}
}
//字段编辑所需字段
protected function getField(){
return array(
'基础' => array(
array('name'=>'id','title'=>'id','help'=>'','type'=>'hidden'),
array('name'=>'model_id','title'=>'model_id','help'=>'','type'=>'hidden'),
array('name'=>'name','title'=>'字段名','help'=>'英文字母开头长度不超过30','type'=>'text'),
array('name'=>'title','title'=>'字段标题','help'=>'请输入字段标题,用于表单显示','type'=>'text'),
array('name'=>'type','title'=>'字段类型','help'=>'用于表单中的展示方式','type'=>'select','option'=>$this->attr,'help'=>''),
array('name'=>'length','title'=>'字段长度','help'=>'字段的长度值','type'=>'text'),
array('name'=>'extra','title'=>'参数','help'=>'布尔、枚举、多选字段类型的定义数据','type'=>'textarea'),
array('name'=>'value','title'=>'默认值','help'=>'字段的默认值','type'=>'text'),
array('name'=>'remark','title'=>'字段备注','help'=>'用于表单中的提示','type'=>'text'),
array('name'=>'is_show','title'=>'是否显示','help'=>'是否显示在表单中','type'=>'select','option'=>array('1'=>'始终显示','2'=>'新增显示','3'=>'编辑显示','0'=>'不显示'),'value'=>1),
array('name'=>'is_must','title'=>'是否必填','help'=>'用于自动验证','type'=>'select','option'=>array('0'=>'否','1'=>'是'))
),
'高级' => array(
array('name'=>'validate_type','title'=>'验证方式','type'=>'select','option'=>$this->validate_rule,'help'=>''),
array('name'=>'validate_rule','title'=>'验证规则','help'=>'根据验证方式定义相关验证规则','type'=>'text'),
array('name'=>'error_info','title'=>'出错提示','type'=>'text','help'=>''),
array('name'=>'validate_time','title'=>'验证时间','help'=>'英文字母开头长度不超过30','type'=>'select','option'=>$this->the_time,'help'=>''),
array('name'=>'auto_type','title'=>'自动完成方式','help'=>'英文字母开头长度不超过30','type'=>'select','option'=>$this->auto_type,'help'=>''),
array('name'=>'auto_rule','title'=>'自动完成规则','help'=>'根据完成方式订阅相关规则','type'=>'text'),
array('name'=>'auto_time','title'=>'自动完成时间','help'=>'英文字母开头长度不超过30','type'=>'select','option'=>$this->the_time),
),
);
}
}

View File

@@ -0,0 +1,248 @@
<?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\admin\controller;
use app\common\controller\Admin;
class Category extends Admin{
public function _initialize(){
parent::_initialize();
$this->getContentMenu();
}
public function index(){
$map = array('status' => array('gt', -1));
$row = db('Category')->where($map)->order('sort asc,id asc')->select();
$list = array();
foreach ($row as $key => $value) {
$list[$value['id']] = $value;
}
if (!empty($list)) {
$tree = new \com\Tree();
$list = $tree->toFormatTree($list);
}
$this->assign('tree',$list);
$this->setMeta('栏目列表');
return $this->fetch();
}
/* 单字段编辑 */
public function editable($name = null, $value = null, $pk = null) {
if ($name && ($value != null || $value != '') && $pk) {
db('Category')->where(array('id' => $pk))->setField($name, $value);
}
}
/* 编辑分类 */
public function edit($id = null, $pid = 0) {
if (IS_POST) {
$category = model('Category');
//提交表单
$result = $category->change();
if (false !== $result) {
//记录行为
action_log('update_category', 'category', $id, session('user_auth.uid'));
return $this->success('编辑成功!', url('index'));
}
else {
$error = $category->getError();
return $this->error(empty($error) ? '未知错误!' : $error);
}
} else {
$cate = '';
if ($pid) {
/* 获取上级分类信息 */
$cate = db('Category')->find($pid);
if (!($cate && 1 == $cate['status'])) {
return $this->error('指定的上级分类不存在或被禁用!');
}
}
/* 获取分类信息 */
$info = $id ? db('Category')->find($id) : '';
$this->assign('info', $info);
$this->assign('category', $cate);
$this->setMeta('编辑分类');
return $this->fetch();
}
}
/* 新增分类 */
public function add($pid = 0) {
$Category = model('Category');
if (IS_POST) {
//提交表单
$id = $Category->change();
if (false !== $id) {
action_log('update_category', 'category', $id, session('user_auth.uid'));
return $this->success('新增成功!', url('index'));
}
else {
$error = $Category->getError();
return $this->error(empty($error) ? '未知错误!' : $error);
}
} else {
$cate = array();
if ($pid) {
/* 获取上级分类信息 */
$cate = $Category->info($pid, 'id,name,title,status');
if (!($cate && 1 == $cate['status'])) {
return $this->error('指定的上级分类不存在或被禁用!');
}
}
/* 获取分类信息 */
$this->assign('info', null);
$this->assign('category', $cate);
$this->setMeta('新增分类');
return $this->fetch('edit');
}
}
/**
* 删除一个分类
* @author huajie <banhuajie@163.com>
*/
public function remove($id) {
if (empty($id)) {
return $this->error('参数错误!');
}
//判断该分类下有没有子分类,有则不允许删除
$child = db('Category')->where(array('pid' => $id))->field('id')->select();
if (!empty($child)) {
return $this->error('请先删除该分类下的子分类');
}
//判断该分类下有没有内容
$document_list = db('Document')->where(array('category_id' => $id))->field('id')->select();
if (!empty($document_list)) {
return $this->error('请先删除该分类下的文章(包含回收站)');
}
//删除该分类信息
$res = db('Category')->where(array('id'=>$id))->delete();
if ($res !== false) {
//记录行为
action_log('update_category', 'category', $id, session('user_auth.uid'));
return $this->success('删除分类成功!');
}
else {
return $this->error('删除分类失败!');
}
}
/**
* 操作分类初始化
* @param string $type
* @author huajie <banhuajie@163.com>
*/
public function operate($type = 'move') {
//检查操作参数
if (strcmp($type, 'move') == 0) {
$operate = '移动';
}
elseif (strcmp($type, 'merge') == 0) {
$operate = '合并';
}
else {
return $this->error('参数错误!');
}
$from = intval(input('get.from'));
if (empty($from)) {
return $this->error('参数错误!');
}
//获取分类
$map = array('status' => 1, 'id' => array('neq', $from));
$list = db('Category')->where($map)->field('id,pid,title')->select();
//移动分类时增加移至根分类
if (strcmp($type, 'move') == 0) {
//不允许移动至其子孙分类
$list = tree_to_list(list_to_tree($list));
$pid = db('Category')->getFieldById($from, 'pid');
$pid && array_unshift($list, array('id' => 0, 'title' => '根分类'));
}
$this->assign('type', $type);
$this->assign('operate', $operate);
$this->assign('from', $from);
$this->assign('list', $list);
$this->setMeta($operate . '分类');
return $this->fetch();
}
/**
* 移动分类
* @author huajie <banhuajie@163.com>
*/
public function move() {
$to = input('post.to');
$from = input('post.from');
$res = db('Category')->where(array('id' => $from))->setField('pid', $to);
if ($res !== false) {
return $this->success('分类移动成功!', url('index'));
}
else {
return $this->error('分类移动失败!');
}
}
/**
* 合并分类
* @author huajie <banhuajie@163.com>
*/
public function merge() {
$to = input('post.to');
$from = input('post.from');
$Model = model('Category');
//检查分类绑定的模型
$from_models = explode(',', $Model->getFieldById($from, 'model'));
$to_models = explode(',', $Model->getFieldById($to, 'model'));
foreach ($from_models as $value) {
if (!in_array($value, $to_models)) {
return $this->error('请给目标分类绑定' . get_document_model($value, 'title') . '模型');
}
}
//检查分类选择的文档类型
$from_types = explode(',', $Model->getFieldById($from, 'type'));
$to_types = explode(',', $Model->getFieldById($to, 'type'));
foreach ($from_types as $value) {
if (!in_array($value, $to_types)) {
$types = config('DOCUMENT_MODEL_TYPE');
return $this->error('请给目标分类绑定文档类型:' . $types[$value]);
}
}
//合并文档
$res = db('Document')->where(array('category_id' => $from))->setField('category_id', $to);
if ($res !== false) {
//删除被合并的分类
$Model->delete($from);
return $this->success('合并分类成功!', url('index'));
}
else {
return $this->error('合并分类失败!');
}
}
public function status(){
$id = input('id','','trim,intval');
$ids = input('post.ids/a',array(),'');
$status = input('status','0','trim,intval');
array_push($ids, $id);
if (!$id) {
return $this->error("非法操作!");
}
$map['id'] = array('IN',$ids);
$result = db('Category')->where($map)->setField('status', $status);
if ($result) {
return $this->success("设置成功!",'');
}else{
return $this->error("设置失败!",'');
}
}
}

View File

@@ -0,0 +1,199 @@
<?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\admin\controller;
use app\common\controller\Admin;
class Channel extends Admin{
public function _initialize(){
parent::_initialize();
}
public function index(){
$pid = input('get.pid', 0);
/* 获取频道列表 */
//$map = array('status' => array('gt', -1), 'pid'=>$pid);
$map = array('status' => array('gt', -1));
$list = db('Channel')->where($map)->order('sort asc,id asc')->select();
if (!empty($list)) {
$tree = new \com\Tree();
$list = $tree->toFormatTree($list);
}
config('_sys_get_channel_tree_', true);
$this->assign('tree', $list);
$this->assign('pid', $pid);
$this->setMeta('导航管理');
return $this->fetch();
}
/* 单字段编辑 */
public function editable($name = null, $value = null, $pk = null) {
if ($name && ($value != null || $value != '') && $pk) {
model('Channel')->where(array('id' => $pk))->setField($name, $value);
}
}
/**
* 添加频道
* @author 麦当苗儿 <zuojiazi@vip.qq.com>
*/
public function add() {
if (IS_POST) {
$Channel = model('Channel');
$data = input('post.');
if ($data) {
$id = $Channel->save($data);
if ($id) {
return $this->success('新增成功', url('index'));
//记录行为
action_log('update_channel', 'channel', $id, session('user_auth.uid'));
} else {
return $this->error('新增失败');
}
} else {
$this->error($Channel->getError());
}
} else {
$pid = input('get.pid', 0);
//获取父导航
if (!empty($pid)) {
$parent = db('Channel')->where(array('id' => $pid))->field('title')->find();
$this->assign('parent', $parent);
}
$pnav = db('Channel')->where(array('pid' => '0'))->select();
$this->assign('pnav', $pnav);
$this->assign('pid', $pid);
$this->assign('info', null);
$this->setMeta('新增导航');
return $this->fetch('edit');
}
}
/**
* 编辑频道
* @author 麦当苗儿 <zuojiazi@vip.qq.com>
*/
public function edit($id = 0) {
if (IS_POST) {
$Channel = model('Channel');
$data = input('post.');
if ($data) {
if (false !== $Channel->save($data,array('id'=>$data['id']))) {
//记录行为
action_log('update_channel', 'channel', $data['id'], session('user_auth.uid'));
return $this->success('编辑成功', url('index'));
} else {
return $this->error('编辑失败');
}
} else {
return $this->error($Channel->getError());
}
} else {
$info = array();
/* 获取数据 */
$info = db('Channel')->find($id);
if (false === $info) {
return $this->error('获取配置信息错误');
}
$pid = input('get.pid', 0);
//获取父导航
if (!empty($pid)) {
$parent = db('Channel')->where(array('id' => $pid))->field('title')->find();
$this->assign('parent', $parent);
}
$pnav = db('Channel')->where(array('pid' => '0'))->select();
$this->assign('pnav', $pnav);
$this->assign('pid', $pid);
$this->assign('info', $info);
$this->setMeta('编辑导航');
return $this->fetch();
}
}
/**
* 删除频道
* @author 麦当苗儿 <zuojiazi@vip.qq.com>
*/
public function del() {
$id = array_unique((array)input('id', 0));
if (empty($id)) {
return $this->error('请选择要操作的数据!');
}
$map = array('id' => array('in', $id));
if (db('Channel')->where($map)->delete()) {
//记录行为
action_log('update_channel', 'channel', $id, session('user_auth.uid'));
return $this->success('删除成功');
} else {
return $this->error('删除失败!');
}
}
/**
* 导航排序
* @author huajie <banhuajie@163.com>
*/
public function sort() {
if (IS_GET) {
$ids = input('get.ids');
$pid = input('get.pid');
//获取排序的数据
$map = array('status' => array('gt', -1));
if (!empty($ids)) {
$map['id'] = array('in', $ids);
} else {
if ($pid !== '') {
$map['pid'] = $pid;
}
}
$list = db('Channel')->where($map)->field('id,title')->order('sort asc,id asc')->select();
$this->assign('list', $list);
$this->setMeta('导航排序');
return $this->fetch();
} elseif (IS_POST) {
$ids = input('post.ids');
$ids = explode(',', $ids);
foreach ($ids as $key => $value) {
$res = db('Channel')->where(array('id' => $value))->setField('sort', $key + 1);
}
if ($res !== false) {
return $this->success('排序成功!',url('admin/channel/index'));
} else {
return $this->error('排序失败!','');
}
} else {
return $this->error('非法请求!','');
}
}
public function setStatus(){
$id = array_unique((array)input('ids', 0));
$status = input('status','0','trim');
if (empty($id)) {
return $this->error('请选择要操作的数据!');
}
$map = array('id' => array('in', $id));
$result = db('Channel')->where($map)->update(array('status'=>$status));
if ($result) {
return $this->success("操作成功!");
}else{
return $this->error("操作失败!");
}
}
}

View File

@@ -0,0 +1,215 @@
<?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\admin\controller;
use app\common\controller\Admin;
class Config extends Admin{
public function _initialize(){
parent::_initialize();
$this->model = model('Config');
}
/**
* 配置管理
* @author 麦当苗儿 <zuojiazi@vip.qq.com>
*/
public function index() {
/* 查询条件初始化 */
$map = array();
$map = array('status' => 1);
if (isset($_GET['group'])) {
$map['group'] = input('group', 0);
}
if (isset($_GET['name'])) {
$map['name'] = array('like', '%' . (string)input('name') . '%');
}
$list = $this->model->where($map)->order('id desc')->paginate(25);
// 记录当前列表页的cookie
Cookie('__forward__', $_SERVER['REQUEST_URI']);
$data = array(
'group' => config('config_group_list'),
'config_type' => config('config_config_list'),
'page' => $list->render(),
'group_id' => input('get.group', 0),
'list' => $list
);
$this->assign($data);
$this->setMeta('配置管理');
return $this->fetch();
}
public function group(){
if (IS_POST) {
$config = input('post.config/a','');
$model = model('Config');
foreach ($config as $key => $value) {
$model::where('name',$key)->update(array('value' => $value));
}
return $this->success("更新成功!");
}else{
$id = input('get.id', 1);
$type = config('config_group_list');
$list = db("Config")->where(array('status' => 1, 'group' => $id))->field('id,name,title,extra,value,remark,type')->order('sort')->select();
if ($list) {
$this->assign('list', $list);
}
$this->assign('id', $id);
$this->setMeta($type[$id] . '设置');
return $this->fetch();
}
}
/**
* 新增配置
* @author 麦当苗儿 <zuojiazi@vip.qq.com>
*/
public function add() {
if (IS_POST) {
$Config = model('Config');
$data = input('post.');
if ($data) {
$id = $Config->validate(true)->save($data);
if ($id) {
cache('db_config_data', null);
//记录行为
action_log('update_config', 'config', $id, session('user_auth.uid'));
return $this->success('新增成功', url('index'));
}
else {
return $this->error('新增失败');
}
}
else {
return $this->error($Config->getError());
}
}
else {
$this->setMeta('新增配置');
$this->assign('info', null);
return $this->fetch('edit');
}
}
/**
* 编辑配置
* @author 麦当苗儿 <zuojiazi@vip.qq.com>
*/
public function edit($id = 0) {
if (IS_POST) {
$Config = model('Config');
$data = input('post.');
if ($data) {
$result = $Config->validate('Config.edit')->save($data,array('id'=>$data['id']));
if (false !== $result) {
cache('db_config_data', null);
//记录行为
action_log('update_config', 'config', $data['id'], session('user_auth.uid'));
return $this->success('更新成功', Cookie('__forward__'));
} else {
return $this->error($Config->getError(), '');
}
}else {
return $this->error($Config->getError());
}
}else{
$info = array();
/* 获取数据 */
$info = db('Config')->field(true)->find($id);
if (false === $info) {
return $this->error('获取配置信息错误');
}
$this->assign('info', $info);
$this->setMeta('编辑配置');
return $this->fetch();
}
}
/**
* 批量保存配置
* @author 麦当苗儿 <zuojiazi@vip.qq.com>
*/
public function save($config) {
if ($config && is_array($config)) {
$Config = db('Config');
foreach ($config as $name => $value) {
$map = array('name' => $name);
$Config->where($map)->setField('value', $value);
}
}
cache('db_config_data', null);
return $this->success('保存成功!');
}
/**
* 删除配置
* @author 麦当苗儿 <zuojiazi@vip.qq.com>
*/
public function del() {
$id = array_unique((array)input('id', 0));
if (empty($id)) {
return $this->error('请选择要操作的数据!');
}
$map = array('id' => array('in', $id));
if (db('Config')->where($map)->delete()) {
cache('DB_CONFIG_DATA', null);
//记录行为
action_log('update_config', 'config', $id, session('user_auth.uid'));
return $this->success('删除成功');
} else {
return $this->error('删除失败!');
}
}
/**
* 配置排序
* @author huajie <banhuajie@163.com>
*/
public function sort() {
if (IS_GET) {
$ids = input('get.ids');
//获取排序的数据
$map = array('status' => array('gt', -1));
if (!empty($ids)) {
$map['id'] = array('in', $ids);
}
elseif (input('group')) {
$map['group'] = input('group');
}
$list = db('Config')->where($map)->field('id,title')->order('sort asc,id asc')->select();
$this->assign('list', $list);
$this->setMeta('配置排序');
return $this->fetch();
}
elseif (IS_POST) {
$ids = input('post.ids');
$ids = explode(',', $ids);
foreach ($ids as $key => $value) {
$res = db('Config')->where(array('id' => $value))->setField('sort', $key + 1);
}
if ($res !== false) {
return $this->success('排序成功!', '', Cookie('__forward__'));
}
else {
return $this->error('排序失败!');
}
}
else {
return $this->error('非法请求!');
}
}
}

View File

@@ -0,0 +1,242 @@
<?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\admin\controller;
use app\common\controller\Admin;
class Content extends Admin{
public function _initialize(){
parent::_initialize();
$this->getContentMenu();
$this->model_id = $model_id = $this->request->param('model_id');
$row = db('Model')->select();
foreach ($row as $key => $value) {
$list[$value['id']] = $value;
}
if (empty($list[$model_id])) {
return $this->error("无此模型!");
}else {
$this->modelInfo = $list[$model_id];
if ($this->modelInfo['extend'] > 1) {
$this->model = model($this->modelInfo['name']);
}else{
$this->model = model('Document')->extend($this->modelInfo['name']);
}
}
$this->assign('model_id',$model_id);
$this->assign('model_list',$list);
}
/**
* 内容列表
* @return [html] [页面内容]
* @author molong <ycgpp@126.com>
*/
public function index(){
if ($this->modelInfo['list_grid'] == '') {
return $this->error("列表定义不正确!", url('admin/model/edit',array('id'=>$this->modelInfo['id'])));
}
$grid_list = get_grid_list($this->modelInfo['list_grid']);
$order = "id desc";
$map = array();
if ($this->modelInfo['extend'] == 1) {
$map['model_id'] = $this->modelInfo['id'];
}
$field = array_filter($grid_list['fields']);
$list = $this->model->where($map)->field($field)->order($order)->paginate(15);
$data = array(
'grid' => $grid_list,
'list' => $list,
'page' => $list->render()
);
$this->assign($data);
$this->setMeta($this->modelInfo['title'] . "列表");
return $this->fetch('content/index');
}
/**
* 内容添加
* @author molong <ycgpp@126.com>
*/
public function add(){
if (IS_POST) {
$result = $this->model->change();
if ($result) {
return $this->success("添加成功!",url('admin/content/index',array('model_id'=>$this->modelInfo['id'])));
}else{
return $this->error($this->model->getError(),'');
}
}else{
$info = array(
'model_id' => $this->modelInfo['id']
);
$data = array(
'info' => $info,
'fieldGroup' => $this->getField($this->modelInfo)
);
$this->assign($data);
$this->setMeta("添加".$this->modelInfo['title']);
return $this->fetch('public/edit');
}
}
/**
* 内容修改
* @author molong <ycgpp@126.com>
*/
public function edit(){
if (IS_POST) {
$result = $this->model->change();
if ($result !== false) {
return $this->success("更新成功!",url('admin/content/index',array('model_id'=>$this->modelInfo['id'])));
}else{
return $this->error($this->model->getError(),'');
}
}else{
$id = input('get.id','','trim,intval');
if (!$id) {
return $this->error("非法操作!");
}
$info = $this->model->detail($id);
if (!$info) {
return $this->error($this->model->getError());
}
$info['model_id'] = $this->modelInfo['id'];
$data = array(
'info' => $info,
'fieldGroup' => $this->getField($this->modelInfo)
);
$this->assign($data);
$this->setMeta("编辑".$this->modelInfo['title']);
return $this->fetch('public/edit');
}
}
/**
* 内容删除
* @author molong <ycgpp@126.com>
*/
public function del(){
$id = input('get.id','','trim');
$ids = input('post.ids/a',array());
array_push($ids, $id);
if (empty($ids)) {
return $this->error("非法操作!");
}
$map['id'] = array('IN',$ids);
$result = $this->model->del($map);
if ($result) {
return $this->success("删除成功!");
}else{
return $this->error("删除失败!", '', "");
}
}
/**
* 设置状态
* @author molong <ycgpp@126.com>
*/
public function status(){
$model = $this->model;
$id = input('get.id','','trim,intval');
$status = input('get.status','','trim,intval');
$map['id'] = $id;
$result = $model::where($map)->setField('status',$status);
if ($result) {
return $this->success("操作成功!");
}else{
return $this->error("操作失败!!");
}
}
/**
* 获取字段信息
* @return array 字段数组
* @author molong <ycgpp@126.com>
*/
protected function getField(){
$field_group = parse_config_attr($this->modelInfo['field_group']);
$field_sort = json_decode($this->modelInfo['field_sort'],true);
if ($this->modelInfo['extend'] > 1) {
$map['model_id'] = $this->modelInfo['id'];
}else{
$model_id[] = $this->modelInfo['id'];
$model_id[] = 1;
$map['model_id'] = array('IN',$model_id);
}
if ($this->request->action() == 'add') {
$map['is_show'] = array('in',array('1','2'));
}elseif($this->request->action() == 'edit'){
$map['is_show'] = array('in',array('1','3'));
}
//获得数组的第一条数组
$first_key = array_keys($field_group);
$fields = model('Attribute')->getFieldlist($map);
if (!empty($field_sort)) {
foreach ($field_sort as $key => $value) {
foreach ($value as $index) {
if (isset($fields[$index])) {
$groupfield[$key][] = $fields[$index];
unset($fields[$index]);
}
}
}
}
//未进行排序的放入第一组中
$fields[] = array('name'=>'model_id','type'=>'hidden'); //加入模型ID值
$fields[] = array('name'=>'id','type'=>'hidden'); //加入模型ID值
foreach ($fields as $key => $value) {
$groupfield[$first_key[0]][] = $value;
}
foreach ($field_group as $key => $value) {
if ($groupfield[$key]) {
$data[$value] = $groupfield[$key];
}
}
return $data;
}
/**
* 检测需要动态判断的文档类目有关的权限
*
* @return boolean|null
* 返回true则表示当前访问有权限
* 返回false则表示当前访问无权限
* 返回null则会进入checkRule根据节点授权判断权限
*
* @author 朱亚杰 <xcoolcc@gmail.com>
*/
protected function checkDynamic(){
$model_id = $this->request->param('model_id');
if(IS_ROOT){
return true;//管理员允许访问任何页面
}
$models = model('AuthGroup')->getAuthModels(session('user_auth.uid'));
if (!$model_id) {
return false;
}elseif (in_array($model_id, $models)) {
//返回null继续判断操作权限
return null;
}else{
return false;//无权限
}
return false;
}
}

View File

@@ -0,0 +1,276 @@
<?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\admin\controller;
use app\common\controller\Admin;
class Database extends Admin {
/**
* 数据库备份/还原列表
* @param String $type import-还原export-备份
* @author 麦当苗儿 <zuojiazi@vip.qq.com>
*/
public function index($type = null) {
switch ($type) {
/* 数据还原 */
case 'import':
//列出备份文件列表
$path = config('data_backup_path');
if (!is_dir($path)) {
mkdir($path, 0755, true);
}
$path = realpath($path);
$flag = \FilesystemIterator::KEY_AS_FILENAME;
$glob = new \FilesystemIterator($path, $flag);
$list = array();
foreach ($glob as $name => $file) {
if (preg_match('/^\d{8,8}-\d{6,6}-\d+\.sql(?:\.gz)?$/', $name)) {
$name = sscanf($name, '%4s%2s%2s-%2s%2s%2s-%d');
$date = "{$name[0]}-{$name[1]}-{$name[2]}";
$time = "{$name[3]}:{$name[4]}:{$name[5]}";
$part = $name[6];
if (isset($list["{$date} {$time}"])) {
$info = $list["{$date} {$time}"];
$info['part'] = max($info['part'], $part);
$info['size'] = $info['size'] + $file->getSize();
} else {
$info['part'] = $part;
$info['size'] = $file->getSize();
}
$extension = strtoupper(pathinfo($file->getFilename(), PATHINFO_EXTENSION));
$info['compress'] = ($extension === 'SQL') ? '-' : $extension;
$info['time'] = strtotime("{$date} {$time}");
$list["{$date} {$time}"] = $info;
}
}
$title = '数据还原';
break;
/* 数据备份 */
case 'export':
$Db = \think\Db::connect();
$list = $Db->query('SHOW TABLE STATUS');
$list = array_map('array_change_key_case', $list);
$title = '数据备份';
break;
default:
return $this->error('参数错误!');
}
//渲染模板
$this->setMeta($title);
$this->assign('list', $list);
return $this->fetch($type);
}
/**
* 优化表
* @param String $tables 表名
* @author 麦当苗儿 <zuojiazi@vip.qq.com>
*/
public function optimize($tables = null) {
if ($tables) {
$Db = \think\Db::connect();
if (is_array($tables)) {
$tables = implode('`,`', $tables);
$list = $Db->query("OPTIMIZE TABLE `{$tables}`");
if ($list) {
return $this->success("数据表优化完成!");
} else {
return $this->error("数据表优化出错请重试!");
}
} else {
$list = $Db->query("OPTIMIZE TABLE `{$tables}`");
if ($list) {
return $this->success("数据表'{$tables}'优化完成!");
} else {
return $this->error("数据表'{$tables}'优化出错请重试!");
}
}
} else {
return $this->error("请指定要优化的表!");
}
}
/**
* 修复表
* @param String $tables 表名
* @author 麦当苗儿 <zuojiazi@vip.qq.com>
*/
public function repair($tables = null) {
if ($tables) {
$Db = \think\Db::connect();
if (is_array($tables)) {
$tables = implode('`,`', $tables);
$list = $Db->query("REPAIR TABLE `{$tables}`");
if ($list) {
return $this->success("数据表修复完成!");
} else {
return $this->error("数据表修复出错请重试!");
}
} else {
$list = $Db->query("REPAIR TABLE `{$tables}`");
if ($list) {
return $this->success("数据表'{$tables}'修复完成!");
} else {
return $this->error("数据表'{$tables}'修复出错请重试!");
}
}
} else {
return $this->error("请指定要修复的表!");
}
}
/**
* 删除备份文件
* @param Integer $time 备份时间
* @author 麦当苗儿 <zuojiazi@vip.qq.com>
*/
public function del($time = 0) {
if ($time) {
$name = date('Ymd-His', $time) . '-*.sql*';
$path = realpath(config('DATA_BACKUP_PATH')) . DIRECTORY_SEPARATOR . $name;
array_map("unlink", glob($path));
if (count(glob($path))) {
return $this->error('备份文件删除失败,请检查权限!');
} else {
return $this->success('备份文件删除成功!');
}
} else {
return $this->error('参数错误!');
}
}
/**
* 备份数据库
* @param String $tables 表名
* @param Integer $id 表ID
* @param Integer $start 起始行数
* @author 麦当苗儿 <zuojiazi@vip.qq.com>
*/
public function export($tables = null, $id = null, $start = null) {
if (IS_POST && !empty($tables) && is_array($tables)) { //初始化
$path = config('data_backup_path');
if (!is_dir($path)) {
mkdir($path, 0755, true);
}
//读取备份配置
$config = array('path' => realpath($path) . DIRECTORY_SEPARATOR, 'part' => config('data_backup_part_size'), 'compress' => config('data_backup_compress'), 'level' => config('data_backup_compress_level'),);
//检查是否有正在执行的任务
$lock = "{$config['path']}backup.lock";
if (is_file($lock)) {
return $this->error('检测到有一个备份任务正在执行,请稍后再试!');
} else {
//创建锁文件
file_put_contents($lock, time());
}
//检查备份目录是否可写
if (!is_writeable($config['path'])) {
return $this->error('备份目录不存在或不可写,请检查后重试!');
}
session('backup_config', $config);
//生成备份文件信息
$file = array('name' => date('Ymd-His', time()), 'part' => 1,);
session('backup_file', $file);
//缓存要备份的表
session('backup_tables', $tables);
//创建备份文件
$Database = new \com\Database($file, $config);
if (false !== $Database->create()) {
$tab = array('id' => 0, 'start' => 0);
return $this->success('初始化成功!', '', array('tables' => $tables, 'tab' => $tab));
} else {
return $this->error('初始化失败,备份文件创建失败!');
}
} elseif (IS_GET && is_numeric($id) && is_numeric($start)) { //备份数据
$tables = session('backup_tables');
//备份指定表
$Database = new \com\Database(session('backup_file'), session('backup_config'));
$start = $Database->backup($tables[$id], $start);
if (false === $start) { //出错
return $this->error('备份出错!');
} elseif (0 === $start) { //下一表
if (isset($tables[++$id])) {
$tab = array('id' => $id, 'start' => 0);
return $this->success('备份完成!', '', array('tab' => $tab));
} else { //备份完成,清空缓存
unlink(session('backup_config.path') . 'backup.lock');
session('backup_tables', null);
session('backup_file', null);
session('backup_config', null);
return $this->success('备份完成!');
}
} else {
$tab = array('id' => $id, 'start' => $start[0]);
$rate = floor(100 * ($start[0] / $start[1]));
return $this->success("正在备份...({$rate}%)", '', array('tab' => $tab));
}
} else { //出错
return $this->error('参数错误!');
}
}
/**
* 还原数据库
* @author 麦当苗儿 <zuojiazi@vip.qq.com>
*/
public function import($time = 0, $part = null, $start = null) {
if (is_numeric($time) && is_null($part) && is_null($start)) { //初始化
//获取备份文件信息
$name = date('Ymd-His', $time) . '-*.sql*';
$path = realpath(config('data_backup_path')) . DIRECTORY_SEPARATOR . $name;
$files = glob($path);
$list = array();
foreach ($files as $name) {
$basename = basename($name);
$match = sscanf($basename, '%4s%2s%2s-%2s%2s%2s-%d');
$gz = preg_match('/^\d{8,8}-\d{6,6}-\d+\.sql.gz$/', $basename);
$list[$match[6]] = array($match[6], $name, $gz);
}
ksort($list);
//检测文件正确性
$last = end($list);
if (count($list) === $last[0]) {
session('backup_list', $list); //缓存备份列表
return $this->success('初始化完成!', '', array('part' => 1, 'start' => 0));
} else {
return $this->error('备份文件可能已经损坏,请检查!');
}
} elseif (is_numeric($part) && is_numeric($start)) {
$list = session('backup_list');
$db = new \com\Database($list[$part], array('path' => realpath(config('data_backup_path')) . DIRECTORY_SEPARATOR, 'compress' => $list[$part][2]));
$start = $db->import($start);
if (false === $start) {
return $this->error('还原数据出错!');
} elseif (0 === $start) { //下一卷
if (isset($list[++$part])) {
$data = array('part' => $part, 'start' => 0);
return $this->success("正在还原...#{$part}", '', $data);
} else {
session('backup_list', null);
return $this->success('还原完成!');
}
} else {
$data = array('part' => $part, 'start' => $start[0]);
if ($start[1]) {
$rate = floor(100 * ($start[0] / $start[1]));
return $this->success("正在还原...#{$part} ({$rate}%)", '', $data);
}
else {
$data['gz'] = 1;
return $this->success("正在还原...#{$part}", '', $data);
}
}
} else {
return $this->error('参数错误!');
}
}
}

View File

@@ -0,0 +1,20 @@
<?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\admin\controller;
use app\common\controller\Admin;
class Form extends Admin {
//自定义表单
public function index(){
$this->assign('meta_title','自定义表单');
return $this->fetch();
}
}

View File

@@ -0,0 +1,268 @@
<?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\admin\controller;
use app\common\controller\Admin;
class Group extends Admin {
protected $model;
protected $rule;
public function _initialize(){
parent::_initialize();
$this->group = model('AuthGroup');
$this->rule = model('AuthRule');
}
//会员分组首页控制器
public function index(){
$type = input('get.type','admin','trim');
$map['module'] = $type;
$list = db('AuthGroup')->where($map)->order('id desc')->paginate(10);
$data = array(
'list' => $list,
'page' => $list->render(),
'type' => $type
);
$this->assign($data);
$this->setMeta('用户组管理');
return $this->fetch();
}
//会员分组添加控制器
public function add($type = 'admin'){
if (IS_POST) {
$result = $this->group->change();
if ($result) {
return $this->success("添加成功!", url('admin/group/index'));
}else{
return $this->error("添加失败!");
}
}else{
$data = array(
'info' => array('module' => $type,'status' => 1),
'keyList' => $this->group->keyList
);
$this->assign($data);
$this->setMeta('添加用户组');
return $this->fetch('public/edit');
}
}
//会员分组编辑控制器
public function edit($id){
if (!$id) {
return $this->error("非法操作!");
}
if (IS_POST) {
$result = $this->group->change();
if ($result) {
return $this->success("编辑成功!", url('admin/group/index'));
}else{
return $this->error("编辑失败!");
}
}else{
$info = $this->group->where(array('id'=>$id))->find();
$data = array(
'info' => $info,
'keyList' => $this->group->keyList
);
$this->assign($data);
$this->setMeta('编辑用户组');
return $this->fetch('public/edit');
}
}
//会员分组编辑字段控制器
public function editable(){
$pk = input('pk','','trim,intval');
$name = input('name','','trim');
$value = input('value','','trim');
$result = $this->group->where(array('id'=>$pk))->setField($name,$value);
if ($result) {
return $this->success("删除成功!");
}else{
return $this->error("删除失败!");
}
}
//会员分组删除控制器
public function del(){
$id = input('id','','trim,intval');
if (!$id) {
return $this->error("非法操作!");
}
$result = $this->group->where(array('id'=>$id))->delete();
if ($result) {
return $this->success("删除成功!");
}else{
return $this->error("删除失败!");
}
}
//权限节点控制器
public function access(){
$type = input('get.type','admin','trim');
$map['module'] = $type;
$list = db('AuthRule')->where($map)->order('id desc')->paginate(10);
$data = array(
'list' => $list,
'page' => $list->render(),
'type' => $type
);
$this->assign($data);
$this->setMeta('权限节点');
return $this->fetch();
}
//根据菜单更新节点
public function upnode($type){
$rule = model('Menu')->getAuthNodes($type);
foreach ($rule as $value) {
$data = array(
'module' => $type,
'type' => 2,
'name' => $value['url'],
'title' => $value['title'],
'group' => $value['group'],
'status' => 1
);
$id = $this->rule->where(array('name'=>$data['name']))->value('id');
if ($id) {
$data['id'] = $id;
$this->rule->save($data, array('id'=>$id));
}else{
$this->rule->save($data);
}
}
return $this->success("更新成功!");
}
public function auth($id){
if (!$id) {
return $this->error("非法操作!");
}
if (IS_POST) {
$rule = input('rule',array());
$extend_rule = input('extend_rule',array());
$extend_result = $rule_result = false;
//扩展权限
$extend_data = array();
foreach ($extend_rule as $key => $value) {
foreach ($value as $item) {
$extend_data[] = array('group_id'=> $id, 'extend_id' => $item, 'type'=> $key);
}
}
if (!empty($extend_data)) {
db('AuthExtend')->where(array('group_id'=>$id))->delete();
$extend_result = db('AuthExtend')->insertAll($extend_data);
}
if ($rule) {
$rules = implode(',', $rule);
$rule_result = $this->group->where(array('id'=>$id))->setField('rules',$rules);
}
if ($rule_result !== false || $extend_result !== false) {
return $this->success("授权成功!", url('admin/group/index'));
}else{
return $this->error("授权失败!", '');
}
}else{
$group = $this->group->where(array('id'=>$id))->find();
$map['module'] = $group['module'];
$row = db('AuthRule')->where($map)->order('id desc')->select();
$list = array();
foreach ($row as $key => $value) {
$list[$value['group']][] = $value;
}
//模块
$model = db('model')->field('id,title,name')
->where(array('status' => array('gt',0), 'extend' => array('gt',0)))
->select();
//扩展权限
$extend_auth = db('AuthExtend')->where(array('group_id'=>$id,'type'=>2))->column('extend_id');
$data = array(
'list' => $list,
'model' => $model,
'extend_auth' => $extend_auth,
'auth_list' => explode(',', $group['rules']),
'id' => $id
);
$this->assign($data);
$this->setMeta('授权');
return $this->fetch();
}
}
public function addnode($type = 'admin'){
if (IS_POST) {
$result = $this->rule->change();
if ($result) {
return $this->success("创建成功!");
}else{
return $this->error($this->rule->getError());
}
}else{
$data = array(
'info' => array('module' => $type,'status' => 1),
'keyList' => $this->rule->keyList
);
$this->assign($data);
$this->setMeta('添加节点');
return $this->fetch('public/edit');
}
}
public function editnode($id){
if (IS_POST) {
$result = $this->rule->change();
if ($result) {
return $this->success("更新成功!");
}else{
return $this->error("更新失败!");
}
}else{
if (!$id) {
return $this->error("非法操作!");
}
$info = $this->rule->find($id);
$data = array(
'info' => $info,
'keyList' => $this->rule->keyList
);
$this->assign($data);
$this->setMeta('编辑节点');
return $this->fetch('public/edit');
}
}
public function delnode(){
$id = input('id','','trim,intval');
if (!$id) {
return $this->error("非法操作!");
}
$result = $this->rule->where(array('id'=>$id))->delete();
if ($result) {
return $this->success("删除成功!");
}else{
return $this->error("删除失败!");
}
}
}

View File

@@ -0,0 +1,80 @@
<?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\admin\controller;
use app\common\controller\Admin;
class Index extends Admin{
public function index(){
$this->setMeta('后台首页');
return $this->fetch();
}
public function login($username = '', $password = '', $verify = ''){
if (IS_POST) {
if (!$username || !$password) {
return $this->error('用户名或者密码不能为空!','');
}
//验证码验证
$this->checkVerify($verify);
$user = model('User');
$info = $user->login($username,$password);
if ($info) {
return $this->success('登录成功!',url('admin/index/index'));
}else{
switch($uid) {
case -1: $error = '用户不存在或被禁用!'; break; //系统级别禁用
case -2: $error = '密码错误!'; break;
default: $error = '未知错误!'; break; // 0-接口参数错误(调试阶段使用)
}
return $this->error($error,'');
}
}else{
return $this->fetch();
}
}
public function logout(){
$user = model('User');
$user->logout();
$this->redirect('index/login');
}
public function clear(){
if (IS_POST) {
$clear = input('post.clear/a',array());
foreach ($clear as $key => $value) {
if ($value == 'cache') {
\think\Cache::clear(); // 清空缓存数据
}elseif ($value == 'log') {
\think\Log::clear();
}
}
return $this->success("更新成功!",url('admin/index/index'));
}else{
$keylist = array(
array('name'=>'clear','title'=>'更新缓存','type'=>'checkbox','help'=>'','option'=>array(
'cache' => '缓存数据',
'log' => '日志数据'
)
)
);
$data = array(
'keyList' => $keylist,
);
$this->assign($data);
$this->setMeta("更新缓存");
return $this->fetch('public/edit');
}
}
}

View File

@@ -0,0 +1,98 @@
<?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\admin\controller;
use app\common\controller\Admin;
class Link extends Admin{
public function index(){
$map = array();
$order = "id desc";
$list = db('Link')->where($map)->order($order)->paginate(10);
$data = array(
'list' => $list,
'page' => $list->render()
);
$this->assign($data);
$this->setMeta("友情链接");
return $this->fetch();
}
//添加
public function add(){
$link = model('Link');
if(IS_POST){
$data = input('post.');
if ($data) {
unset($data['id']);
$result = $link->save($data);
if ($result) {
return $this->success("添加成功!",url('Link/index'));
}else{
return $this->error($link->getError());
}
}else{
return $this->error($link->getError());
}
}else{
$data = array(
'keyList' => $link->keyList
);
$this->assign($data);
$this->setMeta("添加友链");
return $this->fetch('public/edit');
}
}
//修改
public function edit(){
$link = model('Link');
$id = input('get.id','','trim,intval');
if(IS_POST){
$data = input('post.');
if ($data) {
$result = $link->save($data,array('id'=>$data['id']));
if ($result) {
return $this->success("修改成功!",url('Link/index'));
}else{
return $this->error("修改失败!");
}
}else{
return $this->error($link->getError());
}
}else{
$map = array('id'=>$id);
$info = db('Link')->where($map)->find();
$data = array(
'keyList' => $link->keyList,
'info' => $info
);
$this->assign($data);
$this->setMeta("编辑友链");
return $this->fetch('public/edit');
}
}
//删除
public function delete($id){
$link = db('Link');
$map = array('id'=>array('IN',$id));
$result = $link->where($map)->delete();
if ($result) {
return $this->success("删除成功!");
}else{
return $this->error("删除失败!");
}
}
}

View File

@@ -0,0 +1,262 @@
<?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\admin\controller;
use app\common\controller\Admin;
class Menu extends Admin{
public function _initialize(){
parent::_initialize();
}
public function index(){
$map = array();
$title = trim(input('get.title'));
$list = db("Menu")->where($map)->field(true)->order('sort asc,id asc')->select();
int_to_string($list,array('hide'=>array(1=>'是',0=>'否'),'is_dev'=>array(1=>'是',0=>'否')));
if (!empty($list)) {
$tree = new \com\Tree();
$list = $tree->toFormatTree($list);
}
// 记录当前列表页的cookie
Cookie('__forward__',$_SERVER['REQUEST_URI']);
$this->setMeta('菜单列表');
$this->assign('list',$list);
return $this->fetch();
}
/* 单字段编辑 */
public function editable($name=null,$value=null,$pk=null){
if ($name && ($value != null || $value != '') && $pk) {
db('Menu')->where(array('id'=>$pk))->setField($name,$value);
}
}
/**
* 新增菜单
* @author yangweijie <yangweijiester@gmail.com>
*/
public function add(){
if(IS_POST){
$Menu = model('Menu');
$data = input('post.');
if($data){
$id = $Menu->save($data);
if($id){
session('admin_menu_list',null);
//记录行为
action_log('update_menu', 'Menu', $id, session('user_auth.uid'));
return $this->success('新增成功', Cookie('__forward__'));
} else {
return $this->error('新增失败');
}
} else {
return $this->error($Menu->getError());
}
} else {
$this->assign('info',array('pid'=>input('pid')));
$menus = db('Menu')->select();
$tree = new \com\Tree();
$menus = $tree->toFormatTree($menus);
if (!empty($menus)) {
$menus = array_merge(array(0=>array('id'=>0,'title_show'=>'顶级菜单')), $menus);
}else{
$menus = array(0=>array('id'=>0,'title_show'=>'顶级菜单'));
}
$this->assign('Menus', $menus);
$this->setMeta('新增菜单');
return $this->fetch('edit');
}
}
/**
* 编辑配置
* @author yangweijie <yangweijiester@gmail.com>
*/
public function edit($id = 0){
if(IS_POST){
$Menu = model('Menu');
$data = input('post.');
if($data){
if($Menu->save($data,array('id'=>$data['id']))!== false){
session('admin_menu_list',null);
//记录行为
action_log('update_menu', 'Menu', $data['id'], session('user_auth.uid'));
return $this->success('更新成功', Cookie('__forward__'));
} else {
return $this->error('更新失败');
}
} else {
return $this->error($Menu->getError());
}
} else {
$info = array();
/* 获取数据 */
$info = db('Menu')->field(true)->find($id);
$menus = db('Menu')->field(true)->select();
$tree = new \com\Tree();
$menus = $tree->toFormatTree($menus);
$menus = array_merge(array(0=>array('id'=>0,'title_show'=>'顶级菜单')), $menus);
$this->assign('Menus', $menus);
if(false === $info){
return $this->error('获取后台菜单信息错误');
}
$this->assign('info', $info);
$this->setMeta('编辑后台菜单');
return $this->fetch();
}
}
/**
* 删除后台菜单
* @author yangweijie <yangweijiester@gmail.com>
*/
public function del(){
$id = array_unique((array)input('id',0));
if ( empty($id) ) {
return $this->error('请选择要操作的数据!');
}
$map = array('id' => array('in', $id) );
if(db('Menu')->where($map)->delete()){
session('admin_menu_list',null);
//记录行为
action_log('update_menu', 'Menu', $id, UID);
return $this->success('删除成功');
} else {
return $this->error('删除失败!');
}
}
public function toogleHide($id,$value = 1){
session('admin_menu_list',null);
$result = db('Menu')->where(array('id'=>$id))->setField(array('hide'=>$value));
if($result !==false ) {
return $this->success('操作成功!');
}else{
return $this->error('操作失败!');
}
}
public function toogleDev($id,$value = 1){
session('admin_menu_list',null);
$result = db('Menu')->where(array('id'=>$id))->setField(array('is_dev'=>$value));
if($result !==false ) {
return $this->success('操作成功!');
}else{
return $this->error('操作失败!');
}
}
public function importFile($tree = null, $pid=0){
if($tree == null){
$file = APP_PATH."Admin/Conf/Menu.php";
$tree = require_once($file);
}
$menuModel = D('Menu');
foreach ($tree as $value) {
$add_pid = $menuModel->add(
array(
'title'=>$value['title'],
'url'=>$value['url'],
'pid'=>$pid,
'hide'=>isset($value['hide'])? (int)$value['hide'] : 0,
'tip'=>isset($value['tip'])? $value['tip'] : '',
'group'=>$value['group'],
)
);
if($value['operator']){
$this->import($value['operator'], $add_pid);
}
}
}
public function import(){
if(IS_POST){
$tree = input('post.tree');
$lists = explode(PHP_EOL, $tree);
$menuModel = db('Menu');
if($lists == array()){
return $this->error('请按格式填写批量导入的菜单,至少一个菜单');
}else{
$pid = input('post.pid');
foreach ($lists as $key => $value) {
$record = explode('|', $value);
if(count($record) == 4){
$menuModel->add(array(
'title'=>$record[0],
'url'=>$record[1],
'pid'=>$record[2],
'sort'=>0,
'hide'=>0,
'tip'=>'',
'is_dev'=>0,
'group'=>$record[3],
));
}
}
session('admin_menu_list',null);
return $this->success('导入成功',url('index?pid='.$pid));
}
}else{
$this->setMeta('批量导入后台菜单');
$pid = (int)input('get.pid');
$this->assign('pid', $pid);
$data = db('Menu')->where("id={$pid}")->field(true)->find();
$this->assign('data', $data);
return $this->fetch();
}
}
/**
* 菜单排序
* @author huajie <banhuajie@163.com>
*/
public function sort(){
if(IS_GET){
$ids = input('get.ids');
$pid = input('get.pid');
//获取排序的数据
$map = array('status'=>array('gt',-1));
if(!empty($ids)){
$map['id'] = array('in',$ids);
}else{
if($pid !== ''){
$map['pid'] = $pid;
}
}
$list = db('Menu')->where($map)->field('id,title')->order('sort asc,id asc')->select();
$this->assign('list', $list);
$this->setMeta('菜单排序');
return $this->fetch();
}elseif (IS_POST){
$ids = input('post.ids');
$ids = explode(',', $ids);
foreach ($ids as $key=>$value){
$res = db('Menu')->where(array('id'=>$value))->setField('sort', $key+1);
}
if($res !== false){
session('admin_menu_list',null);
return $this->success('排序成功!');
}else{
return $this->error('排序失败!');
}
}else{
return $this->error('非法请求!');
}
}
}

View File

@@ -0,0 +1,168 @@
<?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\admin\controller;
use app\common\controller\Admin;
class Model extends Admin{
public function _initialize(){
parent::_initialize();
$this->getContentMenu();
}
/**
* 模型管理首页
* @author huajie <banhuajie@163.com>
*/
public function index() {
$map = array('status' => array('gt', -1));
$order = "id desc";
$list = model('Model')->where($map)->order($order)->paginate(10);
$data = array(
'list' => $list,
'page' => $list->render(),
);
// 记录当前列表页的cookie
Cookie('__forward__', $_SERVER['REQUEST_URI']);
$this->assign($data);
$this->setMeta('模型管理');
return $this->fetch();
}
/**
* 新增页面初始化
* @author huajie <banhuajie@163.com>
*/
public function add() {
//获取所有的模型
$models = db('Model')->where(array('extend' => 0))->field('id,title')->select();
$this->assign('models', $models);
$this->setMeta('新增模型');
return $this->fetch();
}
/**
* 编辑页面初始化
* @author huajie <banhuajie@163.com>
*/
public function edit() {
$id = input('get.id', '');
if (empty($id)) {
return $this->error('参数不能为空!');
}
/*获取一条记录的详细数据*/
$model = model('Model');
$data = $model::find($id);
if (!$data) {
return $this->error($Model->getError());
}
$data['attribute_list'] = empty($data['attribute_list']) ? '' : explode(",", $data['attribute_list']);
// 是否继承了其他模型
if ($data['extend'] == 1) {
$map['model_id'] = array('IN',array($data['id'],$data['extend']));
}else{
$map['model_id'] = $data['id'];
}
$map['is_show'] = 1;
$fields = db('Attribute')->where($map)->select();
// 梳理属性的可见性
foreach ($fields as $key => $field) {
if (!empty($data['attribute_list']) && !in_array($field['id'], $data['attribute_list'])) {
$field['is_show'] = 0;
}
$field['group'] = -1;
$field['sort'] = 0;
$fields_tem[$field['id']] = $field;
}
// 获取模型排序字段
$field_sort = json_decode($data['field_sort'], true);
if (!empty($field_sort)) {
foreach ($field_sort as $group => $ids) {
foreach ($ids as $key => $value) {
if (!empty($fields_tem[$value])) {
$fields_tem[$value]['group'] = $group;
$fields_tem[$value]['sort'] = $key;
}
}
}
}
if (isset($fields_tem) && $fields_tem) {
// 模型字段列表排序
$fields = list_sort_by($fields_tem, "sort");
}
$this->assign('fields', $fields);
$this->assign('info', $data);
$this->setMeta('编辑模型');
return $this->fetch();
}
/**
* 删除一条数据
* @author huajie <banhuajie@163.com>
*/
public function del() {
$mdoel = model('Model');
$result = $mdoel->del();
if ($result) {
return $this->success('删除模型成功!');
} else {
return $this->error($mdoel->getError());
}
}
/**
* 更新一条数据
* @author huajie <banhuajie@163.com>
*/
public function update() {
$res = \think\Loader::model('Model')->change();
if($res['status']){
return $this->success($res['info'], url('index'));
}else{
return $this->error($res['info'], '');
}
}
/**
* 更新数据
* @author colin <colin@tensent.cn>
*/
public function status(){
$map['id'] = input('post.ids/a') ? input('post.ids/a') : input('get.ids/a');
if(null == $map['id'])return $this->error('参数不正确!');
$data['status'] = input('get.status');
if(null == $data['status']){
//实现单条数据数据修改
$status = db('Model')->where($map)->field('status')->find();
$data['status'] = $status['status'] ? 0 : 1;
db('Model')->where($map)->update($data);
}else{
//实现多条数据同时修改
$map['id'] = array('IN',$map['id']);
db('Model')->where($map)->update($data);
}
return $this->success('状态设置成功!');
}
}

View File

@@ -0,0 +1,111 @@
<?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\admin\controller;
use app\common\controller\Admin;
class Seo extends Admin{
protected $model;
protected $keyList;
public function _initialize(){
parent::_initialize();
$app=array(''=>'-所有模块-','index'=>'前台模块','user'=>'用户中心');
$this->keyList = array(
array('name'=>'id','title'=>'标识','type'=>'hidden'),
array('name'=>'title','title'=>'规则名称','type'=>'text','option'=>'','help'=>'规则名称,方便记忆'),
array('name'=>'app','title'=>'模块名','type'=>'select','option'=>$app,'help'=>'不选表示所有模块'),
array('name'=>'controller','title'=>'控制器','type'=>'text','option'=>'','help'=>'不填表示所有控制器'),
array('name'=>'act','title'=>'方法','type'=>'text','option'=>'','help'=>'不填表示所有方法'),
array('name'=>'seo_title','title'=>'SEO标题','type'=>'text','option'=>'','help'=>'不填表示使用默认'),
array('name'=>'seo_keywords','title'=>'SEO关键字','type'=>'text','option'=>'','help'=>'不填表示使用默认'),
array('name'=>'seo_description','title'=>'SEO描述','type'=>'text','option'=>'','help'=>'不填表示使用默认'),
array('name'=>'status', 'title'=>'状态', 'type'=>'select','option'=>array('0'=>'禁用','1'=>'启用'),'help'=>''),
array('name'=>'sort','title'=>'排序','type'=>'text','option'=>'','help'=>'')
);
}
public function index($page = 1, $r = 20){
//读取规则列表
$map = array('status' => array('EGT', 0));
$list = model('SeoRule')->where($map)->order('sort asc')->paginate(10);
$data = array(
'list' => $list,
'page' => $list->render(),
);
$this->assign($data);
$this->setMeta("规则列表");
return $this->fetch();
}
public function add(){
if (IS_POST) {
$data = input('post.');
if ($data) {
$result = model('SeoRule')->save($data);
if ($result) {
return $this->success("添加成功!");
}else{
return $this->error("添加失败!","");
}
}else{
return $this->error($this->model->getError());
}
}else{
$data = array(
'keyList' => $this->keyList
);
$this->assign($data);
$this->setMeta("添加规则");
return $this->fetch('public/edit');
}
}
public function edit($id = null){
if (IS_POST) {
$data = input('post.');
if ($data) {
$result = model('SeoRule')->save($data,array('id'=>$data['id']));
if (false !== $result) {
return $this->success("修改成功!");
}else{
return $this->error("修改失败!","");
}
}else{
return $this->error($this->model->getError());
}
}else{
$id = input('id','','trim,intval');
$info = db('SeoRule')->where(array('id'=>$id))->find();
$data = array(
'info' => $info,
'keyList' => $this->keyList
);
$this->assign($data);
$this->setMeta("编辑规则");
return $this->fetch('public/edit');
}
}
public function del(){
$id = input('id','','trim,intval');
if (!$id) {
return $this->error("非法操作!");
}
$result = db('SeoRule')->where(array('id'=>$id))->delete();
if ($result) {
return $this->success("删除成功!");
}else{
return $this->error("删除失败!");
}
}
}

View File

@@ -0,0 +1,20 @@
<?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\admin\controller;
use app\common\controller\Admin;
class Upload extends Admin {
public function _empty(){
$controller = controller('common/Upload');
$action = ACTION_NAME;
return $controller->$action();
}
}

View File

@@ -0,0 +1,365 @@
<?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\admin\controller;
use app\common\controller\Admin;
class User extends Admin{
/**
* 用户管理首页
* @author 麦当苗儿 <zuojiazi@vip.qq.com>
*/
public function index() {
$nickname = input('nickname');
$map['status'] = array('egt', 0);
if (is_numeric($nickname)) {
$map['uid|nickname'] = array(intval($nickname), array('like', '%' . $nickname . '%'), '_multi' => true);
} else {
$map['nickname'] = array('like', '%' . (string)$nickname . '%');
}
$order = "uid desc";
$list = model('User')->where($map)->order($order)->paginate(15);
$data = array(
'list' => $list,
'page' => $list->render(),
);
$this->assign($data);
$this->setMeta('用户信息');
return $this->fetch();
}
/**
* create
* @author colin <colin@tensent.cn>
*/
public function add(){
$model = \think\Loader::model('User');
if(IS_POST){
$username = input('post.username', '', 'trim');
$email = input('post.email', '', 'trim');
$password = input('post.password', '', 'trim');
$repassword = input('post.repassword', '', 'trim');
//创建注册用户
$uid = $model->register($username, $password, $repassword, false);
if(0 < $uid){
$userinfo = array('nickname' => $username, 'email' => $email, 'status' => 1,'reg_time'=>time(),'last_login_time'=>time(),'last_login_ip'=>get_client_ip(1));
/*保存信息*/
if(!db('Member')->where(array('uid'=>$uid))->update($userinfo)){
return $this->error('用户添加失败!');
} else {
return $this->success('用户添加成功!',url('index'));
}
}else{
return $this->error($this->showRegError($uid));
}
}else{
$data = array(
'keyList' => $model->addfield
);
$this->assign($data);
$this->setMeta("添加用户");
return $this->fetch('public/edit');
}
}
/**
* 修改昵称初始化
* @author huajie <banhuajie@163.com>
*/
public function edit() {
$model = model('User');
if(IS_POST){
$data = $this->request->post();
if(!$data){
return $this->error($this->showRegError($model->getError()));
}
//为空
if(empty($data['password'])){
unset($data['password']);
unset($data['salt']);
$model->save($data);
}else{
$data['salt'] = rand_string();
$data['password'] = md5($password.$data['salt']);
//不为空
$model->save($data,array('uid'=>$data['uid']));
}
if ($reuslt) {
return $this->success('修改成功!',url('index'));
}else{
return $this->error('修改失败!', '');
}
}else{
$info = $this->getUserinfo();
$data = array(
'info' => $info,
'keyList' => $model->editfield
);
$this->assign($data);
$this->setMeta("编辑用户");
return $this->fetch('public/edit');
}
}
/**
* del
* @author colin <colin@tensent.cn>
*/
public function del(){
$ids = input('post.ids');
//多条删除和单条删除
empty($ids) ? $ids = input('get.id') : $ids = $ids;
$uid = array('IN',is_array($ids) ? implode(',',$ids) : $ids);
//获取用户信息
$find = $this->getUserinfo($uid);
model('User')->where(array('uid'=>$uid))->delete();
return $this->success('删除用户成功!');
}
public function auth(){
$access = model('AuthGroupAccess');
$group = model('AuthGroup');
if (IS_POST) {
$uid = input('uid','','trim,intval');
$access->where(array('uid'=>$uid))->delete();
$group_type = config('user_group_type');
foreach ($group_type as $key => $value) {
$group_id = input($key,'','trim,intval');
if ($group_id) {
$add = array(
'uid' => $uid,
'group_id' => $group_id,
);
$access->save($add);
}
}
return $this->success("设置成功!");
}else{
$uid = input('id','','trim,intval');
$row = $group::select();
$auth = $access::where(array('uid'=>$uid))->select();
$auth_list = array();
foreach ($auth as $key => $value) {
$auth_list[] = $value['group_id'];
}
foreach ($row as $key => $value) {
$list[$value['module']][] = $value;
}
$data = array(
'uid' => $uid,
'auth_list' => $auth_list,
'list' => $list
);
$this->assign($data);
$this->setMeta("用户分组");
return $this->fetch();
}
}
/**
* 获取某个用户的信息
* @var uid 针对状态和删除启用
* @var pass 是查询password
* @var errormasg 错误提示
* @author colin <colin@tensent.cn>
*/
private function getUserinfo($uid = null,$pass = null,$errormsg = null){
$user = model('User');
$uid = $uid ? $uid : input('get.id');
//如果无UID则修改当前用户
$uid = $uid ? $uid : session('user_auth.uid');
$map['uid'] = $uid;
if($pass != null ){
unset($map);
$map['password'] = $pass;
}
$list = $user::where($map)->field('uid,username,nickname,sex,email,qq,score,signature,status,salt')->find();
if(!$list){
return $this->error($errormsg ? $errormsg : '不存在此用户!');
}
return $list;
}
/**
* 修改昵称提交
* @author huajie <banhuajie@163.com>
*/
public function submitNickname() {
//获取参数
$nickname = input('post.nickname');
$password = input('post.password');
if (empty($nickname)) {
return $this->error('请输入昵称');
}
if (empty($password)) {
return $this->error('请输入密码');
}
//密码验证
$User = new UserApi();
$uid = $User->login(UID, $password, 4);
if ($uid == -2) {
return $this->error('密码不正确');
}
$Member = model('User');
$data = $Member->create(array('nickname' => $nickname));
if (!$data) {
return $this->error($Member->getError());
}
$res = $Member->where(array('uid' => $uid))->save($data);
if ($res) {
$user = session('user_auth');
$user['username'] = $data['nickname'];
session('user_auth', $user);
session('user_auth_sign', data_auth_sign($user));
return $this->success('修改昵称成功!');
}
else {
return $this->error('修改昵称失败!');
}
}
/**
* 修改密码初始化
* @author huajie <banhuajie@163.com>
*/
public function editpwd() {
if (IS_POST) {
$user = \think\Loader::model('User');
//获取参数
$password = input('post.old');
if(empty($password)){
return $this->error('请输入原密码','');
}
$data['password'] = input('post.password');
if (empty($data['password'])) {
return $this->error('请输入新密码','');
}
$repassword = input('post.repassword');
if (empty($repassword)) {
return $this->error('请输入确认密码','');
}
if ($data['password'] !== $repassword) {
return $this->error('您输入的新密码与确认密码不一致','');
}
$res = $user->updateUserFields(UID, $password, $data);
if ($res) {
return $this->success('修改密码成功!');
}else {
return $this->error($user->getError());
}
}else{
$this->setMeta('修改密码');
return $this->fetch();
}
}
/**
* 会员状态修改
* @author 朱亚杰 <zhuyajie@topthink.net>
*/
public function changeStatus($method = null) {
$id = array_unique((array)input('id', 0));
if (in_array(config('user_administrator'), $id)) {
return $this->error("不允许对超级管理员执行该操作!");
}
$id = is_array($id) ? implode(',', $id) : $id;
if (empty($id)) {
return $this->error('请选择要操作的数据!');
}
$map['uid'] = array('in', $id);
switch (strtolower($method)) {
case 'forbiduser':
$this->forbid('Member', $map);
break;
case 'resumeuser':
$this->resume('Member', $map);
break;
case 'deleteuser':
$this->delete('Member', $map);
break;
default:
return $this->error('参数非法');
}
}
/**
* 获取用户注册错误信息
* @param integer $code 错误编码
* @return string 错误信息
*/
private function showRegError($code = 0) {
switch ($code) {
case -1:
$error = '用户名长度必须在16个字符以内';
break;
case -2:
$error = '用户名被禁止注册!';
break;
case -3:
$error = '用户名被占用!';
break;
case -4:
$error = '密码长度必须在6-30个字符之间';
break;
case -5:
$error = '邮箱格式不正确!';
break;
case -6:
$error = '邮箱长度必须在1-32个字符之间';
break;
case -7:
$error = '邮箱被禁止注册!';
break;
case -8:
$error = '邮箱被占用!';
break;
case -9:
$error = '手机格式不正确!';
break;
case -10:
$error = '手机被禁止注册!';
break;
case -11:
$error = '手机号被占用!';
break;
default:
$error = '未知错误';
}
return $error;
}
}