初始化项目
This commit is contained in:
71
application/common/behavior/InitHook.php
Normal file
71
application/common/behavior/InitHook.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
namespace app\common\behavior;
|
||||
|
||||
class InitHook {
|
||||
|
||||
public function run(&$content){
|
||||
|
||||
//初始化某些配置信息
|
||||
if (cache('db_config_data')) {
|
||||
\think\Config::set(cache('db_config_data'));
|
||||
}else{
|
||||
$config = model('common/Config');
|
||||
\think\Config::set($config->lists());
|
||||
}
|
||||
|
||||
//扩展插件
|
||||
\think\Loader::addNamespace('addons',ROOT_PATH . '/addons/');
|
||||
|
||||
$this->setHook();
|
||||
|
||||
//设置模型内容路由
|
||||
$this->setRoute();
|
||||
}
|
||||
|
||||
protected function setHook(){
|
||||
$data = cache('hooks');
|
||||
if(!$data){
|
||||
$hooks = db('Hooks')->column('name,addons');
|
||||
foreach ($hooks as $key => $value) {
|
||||
if($value){
|
||||
$map['status'] = 1;
|
||||
$names = explode(',',$value);
|
||||
$map['name'] = array('IN',$names);
|
||||
$data = db('Addons')->where($map)->column('id,name');
|
||||
if($data){
|
||||
$addons = array_intersect($names, $data);
|
||||
\think\Hook::add($key,array_map('get_addon_class',$addons));
|
||||
}
|
||||
}
|
||||
}
|
||||
cache('hooks',\think\Hook::get());
|
||||
}else{
|
||||
\think\Hook::import($data,false);
|
||||
}
|
||||
}
|
||||
|
||||
protected function setRoute(){
|
||||
$model = db('Model');
|
||||
$map = array(
|
||||
'status' => array('gt',0),
|
||||
'extend' => array('gt',0),
|
||||
);
|
||||
$list = $model->where($map)->field("name,id,title,'' as 'style'")->select();
|
||||
foreach ($list as $key => $value) {
|
||||
$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']."/edit"] = "admin/content/edit?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[$value['name']."/index"] = "index/content/index?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["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']."/edit"] = "user/content/edit?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'];
|
||||
}
|
||||
\think\Route::rule($route);
|
||||
}
|
||||
}
|
||||
140
application/common/controller/Addons.php
Normal file
140
application/common/controller/Addons.php
Normal file
@@ -0,0 +1,140 @@
|
||||
<?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\controller;
|
||||
|
||||
/**
|
||||
* 插件类
|
||||
* @author yangweijie <yangweijiester@gmail.com>
|
||||
*/
|
||||
class Addons extends Base{
|
||||
|
||||
public $info = array();
|
||||
public $addon_path = '';
|
||||
public $config_file = '';
|
||||
public $custom_config = '';
|
||||
public $admin_list = array();
|
||||
public $custom_adminlist = '';
|
||||
public $access_url = array();
|
||||
|
||||
public function _initialize(){
|
||||
$mc = $this->getAddonsName();
|
||||
|
||||
$this->addon_path = ROOT_PATH . "/addons/{$mc}/";
|
||||
if (is_file($this->addon_path.'config.php')) {
|
||||
$this->config_file = $this->addon_path.'config.php';
|
||||
}
|
||||
}
|
||||
|
||||
public function template($template){
|
||||
$mc = $this->getAddonsName();
|
||||
$ac = input('get.ac','','trim,strtolower');
|
||||
$parse_str = \think\Config::get('parse_str');
|
||||
$parse_str['__ADDONROOT__'] = ROOT_PATH . "/addons/{$mc}";
|
||||
\think\Config::set('parse_str', $parse_str);
|
||||
|
||||
if ($template) {
|
||||
$template = $template;
|
||||
}else{
|
||||
$template = $mc . "/" . $ac;
|
||||
}
|
||||
|
||||
$this->view->engine(
|
||||
array('view_path'=> "addons/" . $mc . "/view/")
|
||||
);
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取插件所需的钩子是否存在,没有则新增
|
||||
* @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();
|
||||
}
|
||||
}
|
||||
225
application/common/controller/Admin.php
Normal file
225
application/common/controller/Admin.php
Normal file
@@ -0,0 +1,225 @@
|
||||
<?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\controller;
|
||||
use app\common\model\AuthRule;
|
||||
use app\common\model\AuthGroup;
|
||||
|
||||
class Admin extends Base{
|
||||
|
||||
public function _initialize(){
|
||||
parent::_initialize();
|
||||
|
||||
if (!is_login() and !in_array($this->url,array('admin/index/login', 'admin/index/logout', 'admin/index/verify'))) {
|
||||
$this->redirect('admin/index/login');
|
||||
}
|
||||
|
||||
if (!in_array($this->url,array('admin/index/login', 'admin/index/logout', 'admin/index/verify'))) {
|
||||
|
||||
// 是否是超级管理员
|
||||
define('IS_ROOT', is_administrator());
|
||||
if(!IS_ROOT && \think\Config::get('admin_allow_ip')){
|
||||
// 检查IP地址访问
|
||||
if(!in_array(get_client_ip(),explode(',',\think\Config::get('admin_allow_ip')))){
|
||||
$this->error('403:禁止访问');
|
||||
}
|
||||
}
|
||||
|
||||
// 检测系统权限
|
||||
if(!IS_ROOT){
|
||||
$access = $this->accessControl();
|
||||
if ( false === $access ) {
|
||||
$this->error('403:禁止访问');
|
||||
}elseif(null === $access ){
|
||||
$dynamic = $this->checkDynamic();//检测分类栏目有关的各项动态权限
|
||||
if( $dynamic === null ){
|
||||
//检测访问权限
|
||||
if ( !$this->checkRule($this->url,array('in','1,2')) ){
|
||||
$this->error('未授权访问!');
|
||||
}else{
|
||||
// 检测分类及内容有关的各项动态权限
|
||||
$dynamic = $this->checkDynamic();
|
||||
if( false === $dynamic ){
|
||||
$this->error('未授权访问!');
|
||||
}
|
||||
}
|
||||
}elseif( $dynamic === false ){
|
||||
$this->error('未授权访问!');
|
||||
}
|
||||
}
|
||||
}
|
||||
//菜单设置
|
||||
$this->setMenu();
|
||||
$this->setMeta();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 权限检测
|
||||
* @param string $rule 检测的规则
|
||||
* @param string $mode check模式
|
||||
* @return boolean
|
||||
* @author 朱亚杰 <xcoolcc@gmail.com>
|
||||
*/
|
||||
final protected function checkRule($rule, $type=AuthRule::rule_url, $mode='url'){
|
||||
static $Auth = null;
|
||||
if (!$Auth) {
|
||||
$Auth = new \com\Auth();
|
||||
}
|
||||
if(!$Auth->check($rule,session('user_auth.uid'),$type,$mode)){
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测是否是需要动态判断的权限
|
||||
* @return boolean|null
|
||||
* 返回true则表示当前访问有权限
|
||||
* 返回false则表示当前访问无权限
|
||||
* 返回null,则表示权限不明
|
||||
*
|
||||
* @author 朱亚杰 <xcoolcc@gmail.com>
|
||||
*/
|
||||
protected function checkDynamic(){
|
||||
if(IS_ROOT){
|
||||
return true;//管理员允许访问任何页面
|
||||
}
|
||||
return null;//不明,需checkRule
|
||||
}
|
||||
|
||||
/**
|
||||
* action访问控制,在 **登陆成功** 后执行的第一项权限检测任务
|
||||
*
|
||||
* @return boolean|null 返回值必须使用 `===` 进行判断
|
||||
*
|
||||
* 返回 **false**, 不允许任何人访问(超管除外)
|
||||
* 返回 **true**, 允许任何管理员访问,无需执行节点权限检测
|
||||
* 返回 **null**, 需要继续执行节点权限检测决定是否允许访问
|
||||
* @author 朱亚杰 <xcoolcc@gmail.com>
|
||||
*/
|
||||
final protected function accessControl(){
|
||||
$allow = \think\Config::get('allow_visit');
|
||||
$deny = \think\Config::get('deny_visit');
|
||||
$check = strtolower($this->request->controller().'/'.$this->request->action());
|
||||
if ( !empty($deny) && in_array_case($check,$deny) ) {
|
||||
return false;//非超管禁止访问deny中的方法
|
||||
}
|
||||
if ( !empty($allow) && in_array_case($check,$allow) ) {
|
||||
return true;
|
||||
}
|
||||
return null;//需要检测节点权限
|
||||
}
|
||||
|
||||
protected function setMenu(){
|
||||
$hover_url = $this->request->module().'/'.$this->request->controller();
|
||||
$controller = $this->url;
|
||||
$menu = array(
|
||||
'main' => array(),
|
||||
'child' => array(),
|
||||
);
|
||||
$where['pid'] = 0;
|
||||
$where['hide'] = 0;
|
||||
$where['type'] = 'admin';
|
||||
if(!config('develop_mode')){ // 是否开发者模式
|
||||
$where['is_dev'] = 0;
|
||||
}
|
||||
$row = db('menu')->field('id,title,url,icon,"" as style')->where($where)->select();
|
||||
foreach ($row as $key => $value) {
|
||||
//此处用来做权限判断
|
||||
if (!IS_ROOT && !$this->checkRule($value['url'],2,null) ) {
|
||||
unset($menu['main'][$value['id']]);
|
||||
continue;//继续循环
|
||||
}
|
||||
if ($controller == $value['url']) {
|
||||
$value['style'] = "active";
|
||||
}
|
||||
$menu['main'][$value['id']] = $value;
|
||||
}
|
||||
|
||||
// 查找当前子菜单
|
||||
$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');
|
||||
$pid = $pid ? $pid : $id;
|
||||
if ($hover_url == 'admin/content' || $hover_url == 'admin/attribute') {
|
||||
//内容管理菜单
|
||||
$pid = db('menu')->where("pid =0 AND url like '%admin/category%'")->value('id');
|
||||
}
|
||||
if ($pid) {
|
||||
$map['pid'] = $pid;
|
||||
$map['hide'] = 0;
|
||||
$map['type'] = 'admin';
|
||||
$row = db('menu')->field('id,title,url,icon,group,pid,"" as style')->where($map)->select();
|
||||
foreach ($row as $key => $value) {
|
||||
if (IS_ROOT || $this->checkRule($value['url'],2,null) ) {
|
||||
if ($controller == $value['url']) {
|
||||
$menu['main'][$value['pid']]['style'] = "active";
|
||||
$value['style'] = "active";
|
||||
}
|
||||
$menu['child'][$value['group']][] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->assign('__menu__',$menu);
|
||||
}
|
||||
|
||||
protected function getContentMenu(){
|
||||
$model = \think\Loader::model('Model');
|
||||
$list = array();
|
||||
$map = array(
|
||||
'status' => array('gt',0),
|
||||
'extend' => array('gt',0),
|
||||
);
|
||||
$list = $model::where($map)->field("name,id,title,icon,'' as 'style'")->select();
|
||||
|
||||
//判断是否有模型权限
|
||||
$models = AuthGroup::getAuthModels(session('user_auth.uid'));
|
||||
foreach ($list as $key => $value) {
|
||||
if (IS_ROOT || in_array($value['id'], $models)) {
|
||||
if ('admin/content/index' == $this->url && input('model_id') == $value['id']) {
|
||||
$value['style'] = "active";
|
||||
}
|
||||
$value['url'] = "admin/content/index?model_id=".$value['id'];
|
||||
$value['title'] = $value['title']."管理";
|
||||
$value['icon'] = $value['icon'] ? $value['icon'] : 'file';
|
||||
$menu[] = $value;
|
||||
}
|
||||
}
|
||||
if (!empty($menu)) {
|
||||
$this->assign('extend_menu',array('内容管理'=>$menu));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected function getAddonsMenu(){
|
||||
$model = db('Addons');
|
||||
$list = array();
|
||||
$map = array(
|
||||
'status' => array('gt',0),
|
||||
);
|
||||
$list = $model->field("name,id,title,'' as 'style'")->where($map)->select();
|
||||
|
||||
$menu = array();
|
||||
foreach ($list as $key => $value) {
|
||||
$class = "\\addons\\".strtolower($value['name'])."\\controller\\Admin";
|
||||
if (is_file(ROOT_PATH . $class.".php")) {
|
||||
$action = get_class_methods($class);
|
||||
$value['url'] = "admin/addons/execute?mc=".strtolower($value['name'])."&ac=".$action[0];
|
||||
$menu[$key] = $value;
|
||||
}
|
||||
}
|
||||
if (!empty($menu)) {
|
||||
$this->assign('extend_menu',array('管理插件'=>$menu));
|
||||
}
|
||||
}
|
||||
|
||||
protected function setMeta($title = ''){
|
||||
$this->assign('meta_title',$title);
|
||||
}
|
||||
}
|
||||
19
application/common/controller/Api.php
Normal file
19
application/common/controller/Api.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?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\controller;
|
||||
|
||||
class Api {
|
||||
|
||||
protected $data;
|
||||
|
||||
public function __construct(){
|
||||
$this->data = array('code' => 0, 'msg' => '', 'time' => time(), 'data' => '');
|
||||
}
|
||||
}
|
||||
149
application/common/controller/Base.php
Normal file
149
application/common/controller/Base.php
Normal file
@@ -0,0 +1,149 @@
|
||||
<?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\controller;
|
||||
|
||||
class Base extends \think\Controller{
|
||||
|
||||
protected $url;
|
||||
protected $request;
|
||||
protected $module;
|
||||
protected $controller;
|
||||
protected $action;
|
||||
|
||||
public function _initialize(){
|
||||
/* 读取数据库中的配置 */
|
||||
$config = cache('db_config_data');
|
||||
if(!$config){
|
||||
$config = model('Config')->lists();
|
||||
cache('db_config_data',$config);
|
||||
}
|
||||
config($config);
|
||||
//获取request信息
|
||||
$this->requestInfo();
|
||||
}
|
||||
|
||||
public function execute($mc = null, $op = '', $ac = null){
|
||||
$op = $op ? $op : $this->request->module();
|
||||
if(\think\Config::get('url_case_insensitive')){
|
||||
$mc = ucfirst(parse_name($mc, 1));
|
||||
$op = parse_name($op,1);
|
||||
}
|
||||
|
||||
if(!empty($mc) && !empty($op) && !empty($ac)){
|
||||
$ops = ucwords($op);
|
||||
$class = "\\addons\\{$mc}\\controller\\{$ops}";
|
||||
$addons = new $class;
|
||||
$addons->$ac();
|
||||
} else {
|
||||
$this->error('没有指定插件名称,控制器或操作!');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析数据库语句函数
|
||||
* @param string $sql sql语句 带默认前缀的
|
||||
* @param string $tablepre 自己的前缀
|
||||
* @return multitype:string 返回最终需要的sql语句
|
||||
*/
|
||||
public function sql_split($sql, $tablepre) {
|
||||
if ($tablepre != "sent_")
|
||||
$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 = str_replace($s_tablepre, $r_tablepre, $sql);
|
||||
$sql = str_replace("\r", "\n", $sql);
|
||||
$ret = array();
|
||||
$num = 0;
|
||||
$queriesarray = explode(";\n", trim($sql));
|
||||
unset($sql);
|
||||
foreach ($queriesarray as $query) {
|
||||
$ret[$num] = '';
|
||||
$queries = explode("\n", trim($query));
|
||||
$queries = array_filter($queries);
|
||||
foreach ($queries as $query) {
|
||||
$str1 = substr($query, 0, 1);
|
||||
if ($str1 != '#' && $str1 != '-')
|
||||
$ret[$num] .= $query;
|
||||
}
|
||||
$num++;
|
||||
}
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
protected function setSeo($title = null,$keywords = null,$description = null){
|
||||
$seo = array(
|
||||
'title' => $title,
|
||||
'keywords' => $keywords,
|
||||
'description' => $description,
|
||||
);
|
||||
//获取还没有经过变量替换的META信息
|
||||
$meta = model('SeoRule')->getMetaOfCurrentPage($seo);
|
||||
foreach ($seo as $key => $value) {
|
||||
if (is_array($value)) {
|
||||
foreach ($value as $k => $v) {
|
||||
$meta[$key] = str_replace("[".$k."]", $v, $meta[$key]);
|
||||
}
|
||||
}else{
|
||||
$meta[$key] = str_replace("[".$key."]", $value, $meta[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
$data = array(
|
||||
'title' => $meta['title'],
|
||||
'keywords' => $meta['keywords'],
|
||||
'description' => $meta['description'],
|
||||
);
|
||||
$this->assign($data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 验证码
|
||||
* @param integer $id 验证码ID
|
||||
* @author 郭平平 <molong@tensent.cn>
|
||||
*/
|
||||
public function verify($id = 1){
|
||||
$verify = new \org\Verify(array('length'=>4));
|
||||
$verify->entry($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测验证码
|
||||
* @param integer $id 验证码ID
|
||||
* @return boolean 检测结果
|
||||
* @author 麦当苗儿 <zuojiazi@vip.qq.com>
|
||||
*/
|
||||
public function checkVerify($code, $id = 1){
|
||||
if ($code) {
|
||||
$verify = new \org\Verify();
|
||||
$result = $verify->check($code, $id);
|
||||
if (!$result) {
|
||||
return $this->error("验证码错误!", "");
|
||||
}
|
||||
}else{
|
||||
return $this->error("验证码为空!", "");
|
||||
}
|
||||
}
|
||||
|
||||
//request信息
|
||||
protected function requestInfo(){
|
||||
$this->request = \think\Request::instance();
|
||||
defined('MODULE_NAME') or define('MODULE_NAME', $this->request->module());
|
||||
defined('CONTROLLER_NAME') or define('CONTROLLER_NAME', $this->request->controller());
|
||||
defined('ACTION_NAME') or define('ACTION_NAME', $this->request->action());
|
||||
defined('IS_POST') or define('IS_POST', $this->request->isPost());
|
||||
defined('IS_GET') or define('IS_GET', $this->request->isGet());
|
||||
$this->url = $this->request->module() . '/' . $this->request->controller() . '/' . $this->request->action();
|
||||
$this->assign('request',$this->request);
|
||||
}
|
||||
}
|
||||
26
application/common/controller/Fornt.php
Normal file
26
application/common/controller/Fornt.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?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\controller;
|
||||
|
||||
class Fornt extends Base{
|
||||
|
||||
public function _initialize(){
|
||||
parent::_initialize();
|
||||
//设置SEO
|
||||
$this->setSeo();
|
||||
|
||||
$this->setHoverNav();
|
||||
}
|
||||
|
||||
//当前栏目导航
|
||||
protected function setHoverNav(){
|
||||
//dump($_SERVER['PHP_SELF']);
|
||||
}
|
||||
}
|
||||
122
application/common/controller/Upload.php
Normal file
122
application/common/controller/Upload.php
Normal file
@@ -0,0 +1,122 @@
|
||||
<?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\controller;
|
||||
|
||||
class Upload {
|
||||
|
||||
public function upload(){
|
||||
$upload_type = input('get.filename','images','trim');
|
||||
$config = $this->$upload_type();
|
||||
$upload = new \org\Upload($config, $config['driver']);
|
||||
$info = $upload->upload($_FILES);
|
||||
if (false !== $info) {
|
||||
$fileinfo = $this->save($config, $upload_type, $info['file']);
|
||||
$return['info'] = $fileinfo;
|
||||
}else{
|
||||
$return['status'] = 0;
|
||||
$return['info'] = $upload->getError();
|
||||
}
|
||||
|
||||
echo json_encode($return);
|
||||
}
|
||||
|
||||
/**
|
||||
* 图片上传
|
||||
* @var view
|
||||
* @access public
|
||||
*/
|
||||
protected function images(){
|
||||
return config('picture_upload');
|
||||
}
|
||||
|
||||
/**
|
||||
* 文件上传
|
||||
* @var view
|
||||
* @access public
|
||||
*/
|
||||
protected function attachment(){
|
||||
return config('attachment_upload');
|
||||
}
|
||||
|
||||
/**
|
||||
* 百度编辑器使用
|
||||
* @var view
|
||||
* @access public
|
||||
*/
|
||||
public function ueditor(){
|
||||
$data = new \com\Ueditor(session('auth_user.uid'));
|
||||
echo $data->output();
|
||||
}
|
||||
|
||||
public function delete(){
|
||||
$data = array(
|
||||
'status' => 1,
|
||||
);
|
||||
echo json_encode($data);exit();
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存上传的信息到数据库
|
||||
* @var view
|
||||
* @access public
|
||||
*/
|
||||
public function save($config, $type, $file){
|
||||
$file['status'] = 1;
|
||||
if ($type == 'images') {
|
||||
$dbname = 'picture';
|
||||
$file['path'] = substr($config['rootPath'], 1).$file['savepath'].$file['savename']; //
|
||||
}else{
|
||||
$dbname = 'file';
|
||||
$file['url'] = substr($config['rootPath'], 1).$file['savepath'].$file['savename'];
|
||||
}
|
||||
$data = db($dbname)->where(array('md5'=>$file['md5']))->find();
|
||||
if (!empty($data)) {
|
||||
return $data;
|
||||
}else{
|
||||
$id = db($dbname)->insertGetId($file);
|
||||
}
|
||||
|
||||
if ($id) {
|
||||
$data = db($dbname)->where(array('id'=>$id))->find();
|
||||
return $data;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载本地文件
|
||||
* @param array $file 文件信息数组
|
||||
* @param callable $callback 下载回调函数,一般用于增加下载次数
|
||||
* @param string $args 回调函数参数
|
||||
* @return boolean 下载失败返回false
|
||||
*/
|
||||
public function downLocalFile($file, $callback = null, $args = null){
|
||||
if(is_file($file['rootpath'].$file['savepath'].$file['savename'])){
|
||||
/* 调用回调函数新增下载数 */
|
||||
is_callable($callback) && call_user_func($callback, $args);
|
||||
|
||||
/* 执行下载 */ //TODO: 大文件断点续传
|
||||
header("Content-Description: File Transfer");
|
||||
header('Content-type: ' . $file['type']);
|
||||
header('Content-Length:' . $file['size']);
|
||||
if (preg_match('/MSIE/', $_SERVER['HTTP_USER_AGENT'])) { //for IE
|
||||
header('Content-Disposition: attachment; filename="' . rawurlencode($file['name']) . '"');
|
||||
} else {
|
||||
header('Content-Disposition: attachment; filename="' . $file['name'] . '"');
|
||||
}
|
||||
readfile($file['rootpath'].$file['savepath'].$file['savename']);
|
||||
exit;
|
||||
} else {
|
||||
$this->error = '文件已被删除!';
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
67
application/common/controller/User.php
Normal file
67
application/common/controller/User.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?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\controller;
|
||||
|
||||
class User extends Base{
|
||||
|
||||
public function _initialize(){
|
||||
parent::_initialize();
|
||||
|
||||
if (!is_login() and !in_array($this->url,array('user/login/index', 'user/index/verify'))) {
|
||||
$this->redirect('user/login/index');exit();
|
||||
}else{
|
||||
$user = model('User')->getInfo(session('user_auth.uid'));
|
||||
$this->assign('user', $user);
|
||||
|
||||
//设置会员中心菜单
|
||||
$this->setMenu();
|
||||
}
|
||||
}
|
||||
|
||||
protected function setMenu(){
|
||||
$menu['基础设置'] = array(
|
||||
array('title'=>'个人资料', 'url'=>'user/profile/index', 'icon'=>'newspaper-o'),
|
||||
array('title'=>'密码修改', 'url'=>'user/profile/editpw', 'icon'=>'key'),
|
||||
array('title'=>'更换头像', 'url'=>'user/profile/avatar', 'icon'=>'male'),
|
||||
);
|
||||
$menu['订单管理'] = array(
|
||||
array('title'=>'我的订单', 'url'=>'user/order/index', 'icon'=>'shopping-bag'),
|
||||
);
|
||||
$menu['内容管理'] = $this->getContentMenu();
|
||||
foreach ($menu as $group => $item) {
|
||||
foreach ($item as $key => $value) {
|
||||
if (url($value['url']) == $_SERVER['REQUEST_URI']) {
|
||||
$value['active'] = 'active';
|
||||
}else{
|
||||
$value['active'] = '';
|
||||
}
|
||||
$menu[$group][$key] = $value;
|
||||
}
|
||||
}
|
||||
$this->assign('__MENU__', $menu);
|
||||
}
|
||||
|
||||
protected function getContentMenu(){
|
||||
$list = array();
|
||||
$map = array(
|
||||
'status' => array('gt',0),
|
||||
'extend' => array('gt',0),
|
||||
);
|
||||
$list = db('Model')->where($map)->field("name,id,title,icon,'' as 'style'")->select();
|
||||
|
||||
foreach ($list as $key => $value) {
|
||||
$value['url'] = "user/content/index?model_id=".$value['id'];
|
||||
$value['title'] = $value['title']."管理";
|
||||
$value['icon'] = $value['icon'] ? $value['icon'] : 'file';
|
||||
$list[$key] = $value;
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
}
|
||||
41
application/common/model/Action.php
Normal file
41
application/common/model/Action.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | OneThink [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
/**
|
||||
* 分类模型
|
||||
*/
|
||||
class Action extends Base{
|
||||
|
||||
protected function getStatusTextAttr($value, $data){
|
||||
$status = array(-1=>'删除',0=>'禁用',1=>'正常',2=>'待审核');
|
||||
return $status[$data['status']];
|
||||
}
|
||||
|
||||
public $fieldlist = array(
|
||||
array('name'=>'id','title'=>'ID','type'=>'hidden'),
|
||||
array('name'=>'name','title'=>'行为标识','type'=>'text','help'=>'输入行为标识 英文字母'),
|
||||
array('name'=>'title','title'=>'行为名称','type'=>'text','help'=>'输入行为名称'),
|
||||
array('name'=>'type','title'=>'行为类型','type'=>'select','help'=>'选择行为类型','option'=>''),
|
||||
array('name'=>'remark','title'=>'行为描述','type'=>'textarea','help'=>'输入行为描述'),
|
||||
array('name'=>'rule','title'=>'行为规则','type'=>'textarea','help'=>'输入行为规则,不写则只记录日志'),
|
||||
array('name'=>'log','title'=>'日志规则','type'=>'textarea','help'=>'记录日志备注时按此规则来生成,支持[变量|函数]。目前变量有:user,time,model,record,data'),
|
||||
);
|
||||
|
||||
public function _initialize(){
|
||||
parent::_initialize();
|
||||
foreach ($this->fieldlist as $key => $value) {
|
||||
if ($value['name'] == 'type') {
|
||||
$value['option'] = get_action_type(null,true);
|
||||
}
|
||||
$this->fieldlist[$key] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
21
application/common/model/ActionLog.php
Normal file
21
application/common/model/ActionLog.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | OneThink [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
/**
|
||||
* 分类模型
|
||||
*/
|
||||
class ActionLog extends Base{
|
||||
|
||||
protected function getModelIdAttr($value, $data){
|
||||
$value = get_document_field($data['model'], "name", "id");
|
||||
return $value ? $value : 0;
|
||||
}
|
||||
}
|
||||
36
application/common/model/Ad.php
Normal file
36
application/common/model/Ad.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | OneThink [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
/**
|
||||
* 分类模型
|
||||
*/
|
||||
class Ad extends Base{
|
||||
|
||||
protected $auto = array('update_time');
|
||||
protected $insert = array('create_time');
|
||||
protected $type = array(
|
||||
'id' => 'integer',
|
||||
'cover_id' => 'integer',
|
||||
);
|
||||
|
||||
public $keyList = array(
|
||||
array('name'=>'id', 'title'=>'ID', 'type'=>'hidden', 'help'=>'', 'option'=>''),
|
||||
array('name'=>'place_id', 'title'=>'PLACE_ID', 'type'=>'hidden', 'help'=>'', 'option'=>''),
|
||||
array('name'=>'title', 'title'=>'广告名称', 'type'=>'text', 'help'=>'', 'option'=>''),
|
||||
array('name'=>'cover_id', 'title'=>'广告图片', 'type'=>'image', 'help'=>'', 'option'=>''),
|
||||
array('name'=>'url', 'title'=>'广告链接', 'type'=>'text', 'help'=>'', 'option'=>''),
|
||||
array('name'=>'photolist', 'title'=>'辅助图片', 'type'=>'images', 'help'=>'', 'option'=>''),
|
||||
array('name'=>'listurl', 'title'=>'辅助链接', 'type'=>'textarea', 'help'=>'对应辅助图片的排序,一行一个', 'option'=>''),
|
||||
array('name'=>'background', 'title'=>'广告背景颜色', 'type'=>'text', 'help'=>'', 'option'=>''),
|
||||
array('name'=>'content', 'title'=>'广告描述', 'type'=>'textarea', 'help'=>'', 'option'=>''),
|
||||
array('name'=>'status', 'title'=>'状态', 'type'=>'select', 'help'=>'', 'option'=>array('1'=>'开启','0'=>'禁用')),
|
||||
);
|
||||
}
|
||||
54
application/common/model/AdPlace.php
Normal file
54
application/common/model/AdPlace.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | OneThink [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
/**
|
||||
* 分类模型
|
||||
*/
|
||||
class AdPlace extends Base{
|
||||
|
||||
protected $auto = array('update_time');
|
||||
protected $insert = array('create_time');
|
||||
protected $type = array(
|
||||
'start_time' => 'integer',
|
||||
'end_time' => 'integer',
|
||||
);
|
||||
|
||||
public $show_type = array(
|
||||
'1' => '幻灯片',
|
||||
'2' => '对联',
|
||||
'3' => '图片列表',
|
||||
'4' => '图文列表',
|
||||
'5' => '文字列表',
|
||||
'6' => '代码广告'
|
||||
);
|
||||
|
||||
public $keyList = array(
|
||||
array('name'=>'id', 'title'=>'ID', 'type'=>'hidden', 'help'=>'', 'option'=>''),
|
||||
array('name'=>'title', 'title'=>'广告位名称', 'type'=>'text', 'help'=>'', 'option'=>''),
|
||||
array('name'=>'name', 'title'=>'广告位标识', 'type'=>'text', 'help'=>'调用使用{:ad("广告位标识",参数)}', 'option'=>''),
|
||||
array('name'=>'show_type', 'title'=>'类型', 'type'=>'select', 'help'=>'', 'option'=>''),
|
||||
array('name'=>'show_num', 'title'=>'显示条数', 'type'=>'num', 'help'=>'', 'option'=>''),
|
||||
array('name'=>'start_time', 'title'=>'开始时间', 'type'=>'datetime', 'help'=>'', 'option'=>''),
|
||||
array('name'=>'end_time', 'title'=>'结束时间', 'type'=>'datetime', 'help'=>'', 'option'=>''),
|
||||
array('name'=>'template', 'title'=>'广告模版', 'type'=>'text', 'help'=>'', 'option'=>''),
|
||||
array('name'=>'status', 'title'=>'状态', 'type'=>'select', 'help'=>'', 'option'=>array('1'=>'开启','0'=>'禁用')),
|
||||
);
|
||||
|
||||
public function initialize(){
|
||||
parent::initialize();
|
||||
foreach ($this->keyList as $key => $value) {
|
||||
if ($value['name'] == 'show_type') {
|
||||
$value['option'] = $this->show_type;
|
||||
}
|
||||
$this->keyList[$key] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
128
application/common/model/Addons.php
Normal file
128
application/common/model/Addons.php
Normal file
@@ -0,0 +1,128 @@
|
||||
<?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\model;
|
||||
|
||||
/**
|
||||
* 用户组模型类
|
||||
* Class AuthGroupModel
|
||||
* @author molong <molong@tensent.cn>
|
||||
*/
|
||||
class Addons extends \app\common\model\Base {
|
||||
|
||||
protected $auto = array('status');
|
||||
protected $insert = array('create_time');
|
||||
|
||||
protected function setStatusAttr(){
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取插件列表
|
||||
* @param string $addon_dir
|
||||
*/
|
||||
public function getList($addon_dir = ''){
|
||||
if(!$addon_dir){
|
||||
$addon_dir = SENT_ADDON_PATH;
|
||||
}
|
||||
$dirs = array_map('basename',glob($addon_dir.'*', GLOB_ONLYDIR));
|
||||
if($dirs === FALSE || !file_exists($addon_dir)){
|
||||
$this->error = '插件目录不可读或者不存在';
|
||||
return FALSE;
|
||||
}
|
||||
$addons = array();
|
||||
$where['name'] = array('in',$dirs);
|
||||
$list = db('Addons')->where($where)->field(true)->select();
|
||||
foreach($list as $addon){
|
||||
$addon['uninstall'] = 0;
|
||||
$addons[$addon['name']] = $addon;
|
||||
}
|
||||
foreach ($dirs as $value) {
|
||||
$value = ucfirst($value);
|
||||
if(!isset($addons[$value])){
|
||||
$class = get_addon_class($value);
|
||||
if(!class_exists($class)){
|
||||
// 实例化插件失败忽略执行
|
||||
\think\Log::record('插件'.$value.'的入口文件不存在!');
|
||||
continue;
|
||||
}
|
||||
$obj = new $class;
|
||||
$addons[$value] = $obj->info;
|
||||
if($addons[$value]){
|
||||
$addons[$value]['id'] = 0;
|
||||
$addons[$value]['uninstall'] = 1;
|
||||
unset($addons[$value]['status']);
|
||||
}
|
||||
}
|
||||
}
|
||||
int_to_string($addons, array('status'=>array(-1=>'损坏', 0=>'禁用', 1=>'启用', null=>'未安装')));
|
||||
$addons = list_sort_by($addons,'uninstall','desc');
|
||||
return $addons;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取插件的后台列表
|
||||
*/
|
||||
public function getAdminList(){
|
||||
$admin = array();
|
||||
$db_addons = db('Addons')->where("status=1 AND has_adminlist=1")->field('title,name')->select();
|
||||
if($db_addons){
|
||||
foreach ($db_addons as $value) {
|
||||
$admin[] = array('title'=>$value['title'],'url'=>"Addons/adminList?name={$value['name']}");
|
||||
}
|
||||
}
|
||||
return $admin;
|
||||
}
|
||||
|
||||
public function install($data){
|
||||
if ($data) {
|
||||
$result = $this->save($data);
|
||||
if ($result) {
|
||||
model('Hooks')->addHooks($data['name']);
|
||||
return true;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function uninstall($id){
|
||||
$info = $this->get($id);
|
||||
if (!$info) {
|
||||
$this->error = "无此插件!";
|
||||
return false;
|
||||
}
|
||||
$class = get_addon_class($info['name']);
|
||||
if (class_exists($class)) {
|
||||
//插件卸载方法
|
||||
$addons = new $class;
|
||||
if (!method_exists($addons,'uninstall')) {
|
||||
$this->error = "插件卸载方法!";
|
||||
return false;
|
||||
}
|
||||
$result = $addons->uninstall();
|
||||
if ($result) {
|
||||
//卸载挂载点中的插件
|
||||
$result = model('Hooks')->removeHooks($info['name']);
|
||||
//删除插件表中数据
|
||||
$this->where(array('id'=>$id))->delete();
|
||||
return true;
|
||||
}else{
|
||||
$this->error = "无法卸载插件!";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function build(){
|
||||
|
||||
}
|
||||
}
|
||||
139
application/common/model/Attribute.php
Normal file
139
application/common/model/Attribute.php
Normal file
@@ -0,0 +1,139 @@
|
||||
<?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\model;
|
||||
|
||||
/**
|
||||
* 设置模型
|
||||
*/
|
||||
class Attribute extends Base{
|
||||
|
||||
protected $type = array(
|
||||
'id' => 'integer',
|
||||
);
|
||||
|
||||
protected function getTypeTextAttr($value, $data){
|
||||
$type = config('config_type_list');
|
||||
$type_text = explode(',', $type[$data['type']]);
|
||||
return $type_text[0];
|
||||
}
|
||||
|
||||
public function getFieldlist($map,$index='id'){
|
||||
$list = array();
|
||||
$row = db('Attribute')->field('*,remark as help,type,extra as "option"')->where($map)->select();
|
||||
foreach ($row as $key => $value) {
|
||||
if (in_array($value['type'],array('checkbox','radio','select','bool'))) {
|
||||
$value['option'] = parse_field_attr($value['extra']);
|
||||
} elseif ($value['type'] == 'bind') {
|
||||
$extra = parse_field_bind($value['extra']);
|
||||
foreach ($extra as $k => $v) {
|
||||
$option[$v['id']] = $v['title_show'];
|
||||
}
|
||||
$value['option'] = $option;
|
||||
}
|
||||
$list[$value['id']] = $value;
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
public function change(){
|
||||
$data = input('post.');
|
||||
|
||||
if (!empty($data)) {
|
||||
//在数据库内添加字段
|
||||
$result = $this->checkTableField($data);
|
||||
if (!$result) {
|
||||
$this->error = "字段创建失败!";
|
||||
return false;
|
||||
}
|
||||
if ($data['id']) {
|
||||
$status = $this->save($data, array('id'=>$data['id']));
|
||||
}else{
|
||||
$status = $this->save($data);
|
||||
}
|
||||
|
||||
if (false !== $status) {
|
||||
return $status;
|
||||
}else{
|
||||
$this->error = "添加失败!";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function del($id){
|
||||
$map['id'] = $id;
|
||||
$info = $this->find($id);
|
||||
$model = db('Model')->where(array('id'=>$info['model_id']))->find();
|
||||
|
||||
//先删除字段表内的数据
|
||||
$result = $this->where($map)->delete();
|
||||
if ($result) {
|
||||
if ($model['extend'] == 1) {
|
||||
$tablename = 'document_'.$model['name'];
|
||||
}else{
|
||||
$tablename = $model['name'];
|
||||
}
|
||||
|
||||
//删除模型表中字段
|
||||
$db = new \com\Datatable();
|
||||
$result = $db->del_field($tablename,$info['name'])->query();
|
||||
if ($result) {
|
||||
return true;
|
||||
}else{
|
||||
$this->error = "删除失败!";
|
||||
return false;
|
||||
}
|
||||
}else{
|
||||
$this->error = "删除失败!";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
protected function checkTableField($field){
|
||||
$model = db('Model')->find($field['model_id']);
|
||||
if ($model['extend'] == 1) {
|
||||
$tablename = 'document_'.$model['name'];
|
||||
$key = "doc_id";
|
||||
}else{
|
||||
$tablename = $model['name'];
|
||||
$key = "id";
|
||||
}
|
||||
|
||||
//实例化一个数据库操作类
|
||||
$db = new \com\Datatable();
|
||||
//检查表是否存在并创建
|
||||
if (!$db->CheckTable($tablename)) {
|
||||
//创建新表
|
||||
$db->start_table($tablename)->create_id($key)->create_key($key)->end_table()->query();
|
||||
};
|
||||
$oldname = "";
|
||||
if ($field['id']) {
|
||||
$oldname = $this->db()->where(array('id'=>$field['id']))->value('name');
|
||||
}
|
||||
$attribute_type = get_attribute_type();
|
||||
$field['field'] = $field['name'];
|
||||
$field['type'] = $attribute_type[$field['type']][1];
|
||||
$field['is_null'] = $field['is_must']; //是否为null
|
||||
$field['default'] = $field['value']; //字段默认值
|
||||
$field['comment'] = $field['remark']; //字段注释
|
||||
if($db->CheckField($tablename,$oldname) && $oldname){
|
||||
$field['action'] = 'CHANGE';
|
||||
$field['oldname'] = $oldname;
|
||||
$field['newname'] = $field['name'];
|
||||
$db->colum_field($tablename,$field);
|
||||
}else{
|
||||
$field['action'] = 'ADD';
|
||||
$db->colum_field($tablename,$field);
|
||||
}
|
||||
|
||||
$result = $db->create();
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
115
application/common/model/AuthGroup.php
Normal file
115
application/common/model/AuthGroup.php
Normal file
@@ -0,0 +1,115 @@
|
||||
<?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\model;
|
||||
|
||||
/**
|
||||
* 设置模型
|
||||
*/
|
||||
class AuthGroup extends Base{
|
||||
|
||||
const TYPE_ADMIN = 1; // 管理员用户组类型标识
|
||||
const MEMBER = 'member';
|
||||
const UCENTER_MEMBER = 'ucenter_member';
|
||||
const AUTH_GROUP_ACCESS = 'auth_group_access'; // 关系表表名
|
||||
const AUTH_EXTEND = 'auth_extend'; // 动态权限扩展信息表
|
||||
const AUTH_GROUP = 'auth_group'; // 用户组表名
|
||||
const AUTH_EXTEND_CATEGORY_TYPE = 1; // 分类权限标识
|
||||
const AUTH_EXTEND_MODEL_TYPE = 2; //分类权限标识
|
||||
|
||||
protected $type = array(
|
||||
'id' => 'integer',
|
||||
);
|
||||
|
||||
public $keyList = array(
|
||||
array('name'=>'id', 'title'=>'ID', 'type'=>'hidden', 'help'=>'', 'option'=>''),
|
||||
array('name'=>'module', 'title'=>'所属模块', 'type'=>'hidden', 'help'=>'', 'option'=>''),
|
||||
array('name'=>'title', 'title'=>'用户组名', 'type'=>'text', 'help'=>'', 'option'=>''),
|
||||
array('name'=>'description', 'title'=>'分组描述', 'type'=>'textarea', 'help'=>'', 'option'=>''),
|
||||
array('name'=>'status', 'title'=>'状态', 'type'=>'select', 'help'=>'', 'option'=>array(
|
||||
0 => '禁用',
|
||||
1 => '启用'
|
||||
)),
|
||||
);
|
||||
|
||||
public function change(){
|
||||
$data = input('post.');
|
||||
if ($data['id']) {
|
||||
$result = $this->save($data, array('id'=>$data['id']));
|
||||
}else{
|
||||
$result = $this->save($data);
|
||||
}
|
||||
if (false !== $result) {
|
||||
return true;
|
||||
}else{
|
||||
$this->error = "失败!";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回用户拥有管理权限的分类id列表
|
||||
*
|
||||
* @param int $uid 用户id
|
||||
* @return array
|
||||
*
|
||||
* array(2,4,8,13)
|
||||
*
|
||||
* @author 朱亚杰 <zhuyajie@topthink.net>
|
||||
*/
|
||||
static public function getAuthModels($uid){
|
||||
return self::getAuthExtend($uid,self::AUTH_EXTEND_MODEL_TYPE,'AUTH_MODEL');
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回用户拥有管理权限的分类id列表
|
||||
*
|
||||
* @param int $uid 用户id
|
||||
* @return array
|
||||
*
|
||||
* array(2,4,8,13)
|
||||
*
|
||||
* @author 朱亚杰 <zhuyajie@topthink.net>
|
||||
*/
|
||||
static public function getAuthCategories($uid){
|
||||
return self::getAuthExtend($uid,self::AUTH_EXTEND_CATEGORY_TYPE,'AUTH_CATEGORY');
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回用户拥有管理权限的扩展数据id列表
|
||||
*
|
||||
* @param int $uid 用户id
|
||||
* @param int $type 扩展数据标识
|
||||
* @param int $session 结果缓存标识
|
||||
* @return array
|
||||
*
|
||||
* array(2,4,8,13)
|
||||
*
|
||||
* @author 朱亚杰 <xcoolcc@gmail.com>
|
||||
*/
|
||||
static public function getAuthExtend($uid,$type,$session){
|
||||
if ( !$type ) {
|
||||
return false;
|
||||
}
|
||||
if ( $session ) {
|
||||
$result = session($session);
|
||||
}
|
||||
if ( $uid == session('user_auth.uid') && !empty($result) ) {
|
||||
return $result;
|
||||
}
|
||||
$result = db(self::AUTH_GROUP_ACCESS)->alias('g')
|
||||
->join(self::AUTH_EXTEND.' c', 'g.group_id=c.group_id')
|
||||
->where("g.uid='$uid' and c.type='$type' and !isnull(extend_id)")
|
||||
->column('extend_id');
|
||||
if ( $uid == session('user_auth.uid') && $session ) {
|
||||
session($session,$result);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
17
application/common/model/AuthGroupAccess.php
Normal file
17
application/common/model/AuthGroupAccess.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?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\model;
|
||||
|
||||
/**
|
||||
* 设置模型
|
||||
*/
|
||||
class AuthGroupAccess extends Base{
|
||||
|
||||
}
|
||||
48
application/common/model/AuthRule.php
Normal file
48
application/common/model/AuthRule.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?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\model;
|
||||
|
||||
/**
|
||||
* 设置模型
|
||||
*/
|
||||
class AuthRule extends Base{
|
||||
|
||||
const rule_url = 1;
|
||||
const rule_mian = 2;
|
||||
|
||||
protected $type = array(
|
||||
'id' => 'integer',
|
||||
);
|
||||
|
||||
public $keyList = array(
|
||||
array('name'=>'id','title'=>'标识','type'=>'hidden'),
|
||||
array('name'=>'module','title'=>'所属模块','type'=>'hidden'),
|
||||
array('name'=>'title','title'=>'节点名称','type'=>'text','help'=>''),
|
||||
array('name'=>'name','title'=>'节点标识','type'=>'text','help'=>''),
|
||||
array('name'=>'group','title'=>'功能组','type'=>'text','help'=>'功能分组'),
|
||||
array('name'=>'status','title'=>'状态','type'=>'select','option'=>array('1'=>'启用','0'=>'禁用'),'help'=>''),
|
||||
array('name'=>'condition','title'=>'条件','type'=>'text','help'=>'')
|
||||
);
|
||||
|
||||
public function change(){
|
||||
$data = input('post.');
|
||||
if ($data['id']) {
|
||||
$result = $this->save($data, array('id'=>$data));
|
||||
}else{
|
||||
$result = $this->save($data);
|
||||
}
|
||||
if (false !== $result) {
|
||||
return true;
|
||||
}else{
|
||||
$this->error = "失败!";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
24
application/common/model/Base.php
Normal file
24
application/common/model/Base.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?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\model;
|
||||
|
||||
/**
|
||||
* 模型基类
|
||||
*/
|
||||
class Base extends \think\Model{
|
||||
|
||||
public function scopeList($query, $map, $field = '*', $limit = 10, $order = 'id desc'){
|
||||
$query->field($field)->where($map)->limit($limit)->order($order);
|
||||
}
|
||||
|
||||
public function scopeWhere($query, $map){
|
||||
$query->where($map);
|
||||
}
|
||||
}
|
||||
54
application/common/model/Book.php
Normal file
54
application/common/model/Book.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | OneThink [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
/**
|
||||
* 分类模型
|
||||
*/
|
||||
class Book extends Content{
|
||||
|
||||
protected $auto = array('date_last_modify', 'user_last_modify');
|
||||
protected $type = array(
|
||||
'id' => 'integer',
|
||||
'cover_id' => 'integer',
|
||||
'sort' => 'integer'
|
||||
);
|
||||
|
||||
protected function setStatusAttr($value){
|
||||
return 1;
|
||||
}
|
||||
|
||||
protected function setCreateTimeAttr($value){
|
||||
return $value ? strtotime($value) : time();
|
||||
}
|
||||
|
||||
protected function setDateLastModifyAttr($value){
|
||||
return $value ? strtotime($value) : time();
|
||||
}
|
||||
|
||||
protected function setUserLastModifyAttr($value){
|
||||
return session('user_auth.uid');
|
||||
}
|
||||
|
||||
protected function getCreateTimeAttr($value){
|
||||
return date('Y-m-d H:i:s', $value);
|
||||
}
|
||||
|
||||
protected function getDateLastModifyAttr($value){
|
||||
return date('Y-m-d H:i:s', $value);
|
||||
}
|
||||
|
||||
protected function getStandClassTextAttr($value, $data){
|
||||
$text = array(
|
||||
'1' => 'BK ', '2' => 'CN', '3' => 'QT', '4' => 'DB',
|
||||
);
|
||||
return $text[$data['stand_class']];
|
||||
}
|
||||
}
|
||||
43
application/common/model/Category.php
Normal file
43
application/common/model/Category.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?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\model;
|
||||
|
||||
/**
|
||||
* 设置模型
|
||||
*/
|
||||
class Category extends Base{
|
||||
|
||||
protected $name = "Category";
|
||||
protected $auto = array('update_time', 'icon'=>1, 'status'=>1);
|
||||
|
||||
protected $type = array(
|
||||
'icon' => 'integer',
|
||||
);
|
||||
|
||||
public function change(){
|
||||
$data = input('post.');
|
||||
if ($data['id']) {
|
||||
$result = $this->save($data,array('id'=>$data['id']));
|
||||
}else{
|
||||
unset($data['id']);
|
||||
$result = $this->save($data);
|
||||
}
|
||||
if (false !== $result) {
|
||||
return true;
|
||||
}else{
|
||||
$this->error = "失败!";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function info($id, $field = true){
|
||||
return $this->db()->where(array('id'=>$id))->field($field)->find();
|
||||
}
|
||||
}
|
||||
23
application/common/model/Channel.php
Normal file
23
application/common/model/Channel.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?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\model;
|
||||
|
||||
/**
|
||||
* 设置模型
|
||||
*/
|
||||
class Channel extends Base{
|
||||
|
||||
protected $type = array(
|
||||
'id' => 'integer',
|
||||
);
|
||||
|
||||
protected $auto = array('update_time', 'status'=>1);
|
||||
protected $insert = array('create_time');
|
||||
}
|
||||
74
application/common/model/Config.php
Normal file
74
application/common/model/Config.php
Normal file
@@ -0,0 +1,74 @@
|
||||
<?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\model;
|
||||
|
||||
/**
|
||||
* 设置模型
|
||||
*/
|
||||
class Config extends Base{
|
||||
|
||||
protected $type = array(
|
||||
'id' => 'integer',
|
||||
);
|
||||
|
||||
protected $auto = array('name', 'update_time', 'status'=>1);
|
||||
protected $insert = array('create_time');
|
||||
|
||||
protected function setNameAttr($value){
|
||||
return strtolower($value);
|
||||
}
|
||||
|
||||
protected function getTypeTextAttr($value, $data){
|
||||
$type = config('config_type_list');
|
||||
$type_text = explode(',', $type[$data['type']]);
|
||||
return $type_text[0];
|
||||
}
|
||||
|
||||
public function lists(){
|
||||
$map = array('status' => 1);
|
||||
$data = $this->db()->where($map)->field('type,name,value')->select();
|
||||
|
||||
$config = array();
|
||||
if($data && is_array($data)){
|
||||
foreach ($data as $value) {
|
||||
$config[$value['name']] = $this->parse($value['type'], $value['value']);
|
||||
}
|
||||
}
|
||||
return $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据配置类型解析配置
|
||||
* @param integer $type 配置类型
|
||||
* @param string $value 配置值
|
||||
* @author 麦当苗儿 <zuojiazi@vip.qq.com>
|
||||
*/
|
||||
private function parse($type, $value){
|
||||
switch ($type) {
|
||||
case 'textarea': //解析数组
|
||||
$array = preg_split('/[,;\r\n]+/', trim($value, ",;\r\n"));
|
||||
if(strpos($value,':')){
|
||||
$value = array();
|
||||
foreach ($array as $val) {
|
||||
$list = explode(':', $val);
|
||||
if(isset($list[2])){
|
||||
$value[$list[0]] = $list[1].','.$list[2];
|
||||
}else{
|
||||
$value[$list[0]] = $list[1];
|
||||
}
|
||||
}
|
||||
}else{
|
||||
$value = $array;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
68
application/common/model/Content.php
Normal file
68
application/common/model/Content.php
Normal file
@@ -0,0 +1,68 @@
|
||||
<?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\model;
|
||||
|
||||
/**
|
||||
* 设置模型
|
||||
*/
|
||||
class Content extends Base{
|
||||
|
||||
//protected $name = "page";
|
||||
|
||||
protected $auto = array("update_time");
|
||||
protected $insert = array("create_time");
|
||||
|
||||
protected $type = array(
|
||||
'id' => 'integer',
|
||||
'cover_id' => 'integer',
|
||||
);
|
||||
|
||||
protected function setCreateTimeAttr($value){
|
||||
return $value ? strtotime($value) : time();
|
||||
}
|
||||
|
||||
protected function setUpdateTimeAttr($value){
|
||||
return $value ? strtotime($value) : time();
|
||||
}
|
||||
|
||||
|
||||
protected function getCreateTimeAttr($value){
|
||||
return date('Y-m-d H:i:s',$value);
|
||||
}
|
||||
|
||||
protected function getUpdateTimeAttr($value){
|
||||
return date('Y-m-d H:i:s',$value);
|
||||
}
|
||||
|
||||
public function setInfo($name){
|
||||
$this->name = $name;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function detail($id){
|
||||
$map['id'] = $id;
|
||||
$this->data = $this->db()->where($map)->find();
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
public function change(){
|
||||
$data = input('post.');
|
||||
if ($data['id']) {
|
||||
$result = $this->save($data,array('id'=>$data['id']));
|
||||
}else{
|
||||
$result = $this->save($data);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function del($map){
|
||||
return $this->db()->where($map)->delete();
|
||||
}
|
||||
}
|
||||
122
application/common/model/Document.php
Normal file
122
application/common/model/Document.php
Normal file
@@ -0,0 +1,122 @@
|
||||
<?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\model;
|
||||
|
||||
/**
|
||||
* 设置模型
|
||||
*/
|
||||
class Document extends \think\model\Merge{
|
||||
|
||||
protected $table = "sent_document";
|
||||
protected $fk = 'doc_id';
|
||||
|
||||
// 定义需要自动写入时间戳格式的字段
|
||||
protected $autoTimeField = array('create_time','update_time','deadline');
|
||||
|
||||
protected $auto = array('doc_id', 'title', 'description', 'update_time','deadline');
|
||||
protected $insert = array('uid', 'attach'=>0, 'view'=>0, 'comment'=>0, 'extend'=>0, 'create_time', 'status');
|
||||
|
||||
protected $type = array(
|
||||
'cover_id' => 'integer',
|
||||
'link_id' => 'integer',
|
||||
'level' => 'integer',
|
||||
'comment' => 'integer',
|
||||
'view' => 'integer',
|
||||
);
|
||||
|
||||
protected function setUidAttr(){
|
||||
return session('user_auth.uid');
|
||||
}
|
||||
|
||||
protected function setDocIdAttr(){
|
||||
return input('id','','intval,trim');
|
||||
}
|
||||
|
||||
protected function setDeadlineAttr($value){
|
||||
return $value ? strtotime($value) : time();
|
||||
}
|
||||
|
||||
protected function setCreateTimeAttr($value){
|
||||
return $value ? strtotime($value) : time();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取数据状态
|
||||
* @return integer 数据状态
|
||||
* @author huajie <banhuajie@163.com>
|
||||
*/
|
||||
protected function setStatusAttr($value){
|
||||
$cate = input('post.category_id');
|
||||
$check = db('Category')->getFieldById($cate, 'check');
|
||||
if($check){
|
||||
$status = 2;
|
||||
}else{
|
||||
$status = 1;
|
||||
}
|
||||
return $status;
|
||||
}
|
||||
|
||||
public function extend($name){
|
||||
if (is_numeric($name)) {
|
||||
$name = db('model')->where(array('id'=>$name))->value('name');
|
||||
}
|
||||
self::$relationModel = array('document_' . $name);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function scopeList($query, $map, $field = '*', $limit = 10, $order = 'Document.id desc'){
|
||||
if (!empty($map) && is_array($map)) {
|
||||
foreach ($map as $key => $value) {
|
||||
$where[$this->name . '.' . $key] = $value;
|
||||
}
|
||||
}else{
|
||||
$where = $map;
|
||||
}
|
||||
$query->field($field)->where($where)->limit($limit)->order($order);
|
||||
}
|
||||
|
||||
public function change(){
|
||||
/* 获取数据对象 */
|
||||
$data = input('post.');
|
||||
|
||||
if ($data !== false) {
|
||||
/* 添加或新增基础内容 */
|
||||
if(empty($data['id'])){ //新增数据
|
||||
unset($data['id']);
|
||||
$id = $this->save($data); //添加基础内容
|
||||
|
||||
if(!$id){
|
||||
$this->error = '添加基础内容出错!';
|
||||
return false;
|
||||
}
|
||||
$data['id'] = $id;
|
||||
} else { //更新数据
|
||||
$status = $this->save($data, array('id'=>$data['id'])); //更新基础内容
|
||||
if(false === $status){
|
||||
$this->error = '更新基础内容出错!';
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return $data['id'];
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function del($map){
|
||||
return $this->db()->where($map)->delete();
|
||||
}
|
||||
|
||||
public function detail($id){
|
||||
$data = $this->get($id);
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
98
application/common/model/Hooks.php
Normal file
98
application/common/model/Hooks.php
Normal 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\common\model;
|
||||
|
||||
/**
|
||||
* 友情链接类
|
||||
* @author molong <molong@tensent.cn>
|
||||
*/
|
||||
class Hooks extends Base {
|
||||
|
||||
public $keyList = array(
|
||||
array('name'=>'name','title'=>'钩子名称','type'=>'text','help'=>'需要在程序中先添加钩子,否则无效'),
|
||||
array('name'=>'description','title'=>'钩子描述','type'=>'text','help'=>'钩子的描述信息'),
|
||||
array('name'=>'type_text','title'=>'钩子类型','type'=>'select','help'=>'钩子的描述信息'),
|
||||
array('name'=>'addons','title'=>'插件排序','type'=>'kanban')
|
||||
);
|
||||
|
||||
public function initialize(){
|
||||
parent::initialize();
|
||||
foreach ($this->keyList as $key => $value) {
|
||||
if ($value['name'] == 'type_text') {
|
||||
$value['option'] = \think\Config::get('hooks_type');
|
||||
}
|
||||
$this->keyList[$key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
protected function setAddonsAttr($value){
|
||||
$string = implode(",", $value[1]);
|
||||
return $string;
|
||||
}
|
||||
|
||||
protected function getTypeTextAttr($value, $data){
|
||||
$hooks_type = config('hooks_type');
|
||||
return $hooks_type[$data['type']];
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理钩子挂载插件排序
|
||||
*/
|
||||
public function getaddons($addons = ''){
|
||||
if ($addons) {
|
||||
$hook_list = explode(',',$addons);
|
||||
foreach ($hook_list as $key => $value) {
|
||||
$field_list[] = array('id'=>$value,'title'=>$value,'name'=>$value,'is_show'=>1);
|
||||
}
|
||||
$option[1] = array('name'=>'钩子挂载排序','list'=>$field_list);
|
||||
}else{
|
||||
$option[] = array('name'=>'钩子挂载排序','list'=>array());
|
||||
}
|
||||
foreach ($this->keyList as $key => $value) {
|
||||
if ($value['name'] == 'addons') {
|
||||
$value['option'] = $option;
|
||||
}
|
||||
$keylist[] = $value;
|
||||
}
|
||||
return $keylist;
|
||||
}
|
||||
|
||||
public function change($data){
|
||||
if (!empty($data)) {
|
||||
if ($data['id']) {
|
||||
$this->save($data,array('id'=>$data['id']));
|
||||
}else{
|
||||
$this->save($data);
|
||||
}
|
||||
}else{
|
||||
$this->error = "非法操作!";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function addHooks($addons_name){
|
||||
$addons_class = get_addon_class($addons_name);//获取插件名
|
||||
if(!class_exists($addons_class)){
|
||||
$this->error = "未实现{$addons_name}插件的入口文件";
|
||||
return false;
|
||||
}
|
||||
$methods = get_class_methods($addons_class);
|
||||
dump($methods);
|
||||
}
|
||||
|
||||
public function removeHooks($addons_name){
|
||||
$addons_class = get_addon_class($addons_name);//获取插件名
|
||||
if(!class_exists($addons_class)){
|
||||
$this->error = "未实现{$addons_name}插件的入口文件";
|
||||
return false;
|
||||
}
|
||||
$methods = get_class_methods($addons_class);
|
||||
}
|
||||
}
|
||||
40
application/common/model/Link.php
Normal file
40
application/common/model/Link.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?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\model;
|
||||
|
||||
/**
|
||||
* 友情链接类
|
||||
* @author molong <molong@tensent.cn>
|
||||
*/
|
||||
class Link extends \app\common\model\Base {
|
||||
|
||||
public $keyList = array(
|
||||
array('name'=>'id' ,'title'=>'ID', 'type'=>'hidden'),
|
||||
array('name'=>'title' ,'title'=>'友链标题', 'type'=>'text', 'help'=>''),
|
||||
array('name'=>'url' ,'title'=>'URL链接', 'type'=>'text', 'help'=>''),
|
||||
array('name'=>'ftype' ,'title'=>'友链类别', 'type'=>'select', 'option'=>array(
|
||||
'1' => '常用链接',
|
||||
'2' => '网站导读',
|
||||
'3' => '对公服务',
|
||||
'4' => '校内服务',
|
||||
), 'help'=>''),
|
||||
array('name'=>'cover_id' ,'title'=>'网站LOGO', 'type'=>'image', 'help'=>''),
|
||||
array('name'=>'status' ,'title'=>'状态', 'type'=>'select','option'=>array('1'=>'启用','0'=>'禁用'), 'help'=>''),
|
||||
array('name'=>'sort' ,'title'=>'链接排序', 'type'=>'text', 'help'=>''),
|
||||
array('name'=>'descrip' ,'title'=>'描述', 'type'=>'textarea', 'help'=>'')
|
||||
);
|
||||
|
||||
protected $auto = array('update_time');
|
||||
|
||||
protected $type = array(
|
||||
'cover_id' => 'integer',
|
||||
'sort' => 'integer',
|
||||
);
|
||||
}
|
||||
36
application/common/model/Menu.php
Normal file
36
application/common/model/Menu.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?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\model;
|
||||
|
||||
/**
|
||||
* 菜单模型类
|
||||
* @author molong <molong@tensent.cn>
|
||||
*/
|
||||
class Menu extends \app\common\model\Base {
|
||||
|
||||
protected $type = array(
|
||||
'id' => 'integer',
|
||||
);
|
||||
|
||||
public function getAuthNodes($type = 'admin'){
|
||||
$map['type'] = $type;
|
||||
$rows = $this->db()->field('id,pid,group,title,url')->where($map)->order('id asc')->select();
|
||||
foreach ($rows as $key => $value) {
|
||||
$data[$value['id']] = $value;
|
||||
}
|
||||
foreach ($data as $key => $value) {
|
||||
if ($value['pid'] > 0) {
|
||||
$value['group'] = $data[$value['pid']]['title'] . '管理';
|
||||
$list[] = $value;
|
||||
}
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
}
|
||||
170
application/common/model/Model.php
Normal file
170
application/common/model/Model.php
Normal file
@@ -0,0 +1,170 @@
|
||||
<?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\model;
|
||||
|
||||
/**
|
||||
* 设置模型
|
||||
*/
|
||||
class Model extends Base{
|
||||
|
||||
protected $auto = [ 'update_time', 'field_sort', 'attribute_list'];
|
||||
protected $insert = ['name', 'create_time', 'status'=>1];
|
||||
protected $type = array(
|
||||
'id' => 'integer'
|
||||
);
|
||||
|
||||
public function setFieldSortAttr($value){
|
||||
return empty($value) ? '' : json_encode($value);
|
||||
}
|
||||
|
||||
public function setNameAttr($value){
|
||||
return strtolower($value);
|
||||
}
|
||||
|
||||
public function setAttributeListAttr($value){
|
||||
return empty($value) ? '' : json_encode($value);
|
||||
}
|
||||
|
||||
public function getStatusTextAttr($value, $data){
|
||||
$status = array(
|
||||
0 => '禁用',
|
||||
1 => '启用',
|
||||
);
|
||||
return $status[$data['status']];
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新一个或新增一个模型
|
||||
* @return array
|
||||
*/
|
||||
public function change() {
|
||||
if(IS_POST){
|
||||
$data = input('post.',array());
|
||||
if($data){
|
||||
if (empty($data['id'])) {
|
||||
/*创建表*/
|
||||
$db = new \com\Datatable();
|
||||
//文档模型
|
||||
if($data['extend'] == 1){
|
||||
//默认文档前缀
|
||||
$tablename = 'document_'.$data['name'];
|
||||
}else{
|
||||
$tablename = $data['name'];
|
||||
}
|
||||
$sql = $db->start_table($tablename)
|
||||
->create_id('id', 11 , '主键' , false);
|
||||
if ($data['extend'] != 1) {
|
||||
$sql = $sql->create_uid();
|
||||
}
|
||||
$sql->create_key('id')->end_table($data['title'], $data['engine_type'])
|
||||
->create();
|
||||
$id = $this->validate('model.add')->save($data);
|
||||
if (false === $id) {
|
||||
return array('info'=>$this->getError(), 'status'=>0);
|
||||
}else{
|
||||
// 清除模型缓存数据
|
||||
cache('document_model_list', null);
|
||||
|
||||
//记录行为
|
||||
action_log('update_model', 'model', $id, session('auth_user.uid'));
|
||||
return $id ? array('info'=>'创建模型成功!','status'=>1) : array('info'=>'创建模型失败!','status'=>1);
|
||||
}
|
||||
} else {
|
||||
//修改
|
||||
$status = $this->validate('model.edit')->save($data,array('id'=>$data['id']));
|
||||
if (false === $status) {
|
||||
return array('info'=>$this->getError(), 'status'=>0);
|
||||
}else{
|
||||
// 清除模型缓存数据
|
||||
cache('document_model_list', null);
|
||||
//记录行为
|
||||
action_log('update_model','model',$data['id'],session('auth_user.uid'));
|
||||
return array('info'=>'保存模型成功!','status'=>1);
|
||||
}
|
||||
}
|
||||
}else{
|
||||
return array('info'=>$this->getError(),'status'=>0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function del(){
|
||||
$id = input('id','','trim,intval');
|
||||
$model = $this->db()->where(array('id'=>$id))->find();
|
||||
|
||||
if ($model['extend'] == 0) {
|
||||
$this->error = "基础模型不允许删除!";
|
||||
return false;
|
||||
}elseif ($model['extend'] == 1){
|
||||
$tablename = 'document_'.$model['name'];
|
||||
}elseif ($model['extend'] == 2){
|
||||
$tablename = $model['name'];
|
||||
}
|
||||
//删除数据表
|
||||
$db = new \com\Datatable();
|
||||
if ($db->CheckTable($tablename)) {
|
||||
//检测表是否存在
|
||||
$result = $db->del_table($tablename)->query();
|
||||
if (!$result) {
|
||||
return false;
|
||||
$this->error = "数据表删除失败!";
|
||||
}
|
||||
}
|
||||
$result = $this->db()->where(array('id'=>$id))->delete();
|
||||
if ($result) {
|
||||
return true;
|
||||
}else{
|
||||
$this->error = "模型删除失败!";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function attribute(){
|
||||
return $this->hasMany('Attribute');
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析字段
|
||||
* @param [array] $model [字段]
|
||||
* @return [array] [解析后的字段]
|
||||
*/
|
||||
public function preFields($model){
|
||||
$fields = $model->attribute;
|
||||
$groups = parse_config_attr($model['field_group']);
|
||||
$field_sort = json_decode($model['field_sort'],true);;
|
||||
|
||||
//获得数组的第一条数组
|
||||
$first_key = array_keys($groups);
|
||||
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 ($groups as $key => $value) {
|
||||
if ($groupfield[$key]) {
|
||||
$data[$value] = $groupfield[$key];
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
return array();
|
||||
}
|
||||
}
|
||||
58
application/common/model/Order.php
Normal file
58
application/common/model/Order.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | OneThink [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
/**
|
||||
* 分类模型
|
||||
*/
|
||||
class Order extends Base{
|
||||
|
||||
protected $auto = array('update_time');
|
||||
protected $insert = array('create_time', 'uid', 'status'=>1, 'order_no');
|
||||
|
||||
protected function setOrderNoAttr($value){
|
||||
return 'SN'.date('YmdHis',time()).rand('1000','9999');
|
||||
}
|
||||
|
||||
protected function setUidAttr($value){
|
||||
return session('user_auth.uid');
|
||||
}
|
||||
|
||||
protected function getPayTypeTextAttr($value, $data){
|
||||
$type = array('wechat'=>'微信支付', 'alipay'=>'支付宝支付');
|
||||
return $type[$data['pay_type']];
|
||||
}
|
||||
protected function getPayStatusTextAttr($value, $data){
|
||||
$type = array(
|
||||
0 => '未付款',
|
||||
1 => '已付款',
|
||||
);
|
||||
return $type[$data['pay_status']];
|
||||
}
|
||||
|
||||
public function product(){
|
||||
return $this->hasMany('OrderProduct', 'order_no', 'order_no');
|
||||
}
|
||||
|
||||
//生成订单
|
||||
public function createOrder($data){
|
||||
$order_id = $this->save($data);
|
||||
foreach ($data['list'] as $key => $value) {
|
||||
$value['order_no'] = $this->data['order_no'];
|
||||
$value['product_id'] = $value['id'];
|
||||
unset($value['id']);
|
||||
$value['create_time'] = time();
|
||||
$value['update_time'] = time();
|
||||
$goods[] = $value;
|
||||
}
|
||||
db('OrderProduct')->insertAll($goods);
|
||||
return $order_id;
|
||||
}
|
||||
}
|
||||
20
application/common/model/OrderProduct.php
Normal file
20
application/common/model/OrderProduct.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | OneThink [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
/**
|
||||
* 分类模型
|
||||
*/
|
||||
class OrderProduct extends Base{
|
||||
|
||||
public function book(){
|
||||
return $this->hasOne('Book', 'id', 'product_id');
|
||||
}
|
||||
}
|
||||
17
application/common/model/Page.php
Normal file
17
application/common/model/Page.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | OneThink [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
/**
|
||||
* 分类模型
|
||||
*/
|
||||
class Page extends Content{
|
||||
|
||||
}
|
||||
102
application/common/model/SeoRule.php
Normal file
102
application/common/model/SeoRule.php
Normal file
@@ -0,0 +1,102 @@
|
||||
<?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\model;
|
||||
|
||||
/**
|
||||
* 用户模型
|
||||
*/
|
||||
class SeoRule extends Base{
|
||||
|
||||
protected function getAppAttr($value){
|
||||
return $value ? $value : '*';
|
||||
}
|
||||
|
||||
protected function getControllerAttr($value){
|
||||
return $value ? $value : '*';
|
||||
}
|
||||
|
||||
protected function getActionAttr($value){
|
||||
return (isset($value) && $value) ? $value : '*';
|
||||
}
|
||||
|
||||
protected function getRuleNameAttr($value, $data){
|
||||
return $data['app'].'/'.$data['controller'].'/'.$data['action'];
|
||||
}
|
||||
|
||||
public function getMetaOfCurrentPage($seo){
|
||||
$request = \think\Request::instance();
|
||||
$result = $this->getMeta($request->module(), $request->controller(), $request->action(), $seo);
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function getMeta($module, $controller, $action, $seo){
|
||||
//查询缓存,如果已有,则直接返回
|
||||
$cacheKey = "sent_seo_meta_{$module}_{$controller}_{$action}";
|
||||
$cache = cache($cacheKey);
|
||||
if($cache !== false) {
|
||||
return $cache;
|
||||
}
|
||||
|
||||
//获取相关的规则
|
||||
$rules = $this->getRelatedRules($module, $controller, $action);
|
||||
|
||||
//按照排序计算最终结果
|
||||
$title = '';
|
||||
$keywords = '';
|
||||
$description = '';
|
||||
|
||||
$need_seo = 1;
|
||||
foreach ($rules as $e) {
|
||||
//如果存在完全匹配的seo配置,则不用程序设置的seo资料
|
||||
if ($e['app'] && $e['controller'] && $e['action']) {
|
||||
$need_seo = 0;
|
||||
}
|
||||
if (!$title && $e['seo_title']) {
|
||||
$title = $e['seo_title'];
|
||||
}
|
||||
if (!$keywords && $e['seo_keywords']) {
|
||||
$keywords = $e['seo_keywords'];
|
||||
}
|
||||
if (!$description && $e['seo_description']) {
|
||||
$description = $e['seo_description'];
|
||||
}
|
||||
}
|
||||
if ($need_seo) { //默认让全站的seo规则优先级小于$this->setTitle等方式设置的规则。
|
||||
if ($seo['title']) {
|
||||
$title = $seo['title'];
|
||||
}
|
||||
if ($seo['keywords']) {
|
||||
$keywords = $seo['keywords'];
|
||||
}
|
||||
if ($seo['description']) {
|
||||
$description = $seo['description'];
|
||||
}
|
||||
}
|
||||
//生成结果
|
||||
$result = array('title' => $title, 'keywords' => $keywords, 'description' => $description);
|
||||
|
||||
//写入缓存
|
||||
cache($cacheKey, $result);
|
||||
|
||||
//返回结果
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function getRelatedRules($module, $controller, $action){
|
||||
//查询与当前页面相关的SEO规则
|
||||
$map = array();
|
||||
$map = "(app='' or app='$module') and (controller='' or controller='$controller') and (action='' or action='$action') and status=1";
|
||||
|
||||
$rules = $this->db()->where($map)->order('sort asc')->select();
|
||||
|
||||
//返回规则列表
|
||||
return $rules;
|
||||
}
|
||||
}
|
||||
225
application/common/model/User.php
Normal file
225
application/common/model/User.php
Normal file
@@ -0,0 +1,225 @@
|
||||
<?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\model;
|
||||
|
||||
/**
|
||||
* 用户模型
|
||||
*/
|
||||
class User extends \think\model\Merge{
|
||||
|
||||
protected $name = "Member";
|
||||
protected static $relationModel = array('MemberExtend');
|
||||
protected $createTime = 'reg_time';
|
||||
protected $updateTime = 'last_login_time';
|
||||
protected $fk = 'user_id';
|
||||
protected $mapFields = array(
|
||||
'uid' => 'Member.uid',
|
||||
'user_id' => 'MemberExtend.uid',
|
||||
);
|
||||
protected $type = array(
|
||||
'id' => 'integer',
|
||||
);
|
||||
protected $insert = array('salt', 'password', 'status', 'reg_time');
|
||||
protected $update = array();
|
||||
|
||||
public $editfield = array(
|
||||
array('name'=>'uid','type'=>'hidden'),
|
||||
array('name'=>'username','title'=>'用户名','type'=>'readonly','help'=>''),
|
||||
array('name'=>'nickname','title'=>'昵称','type'=>'text','help'=>''),
|
||||
array('name'=>'password','title'=>'密码','type'=>'password','help'=>'为空时则不修改'),
|
||||
array('name'=>'sex','title'=>'性别','type'=>'select','option'=>array('0'=>'保密','1'=>'男','2'=>'女'),'help'=>''),
|
||||
array('name'=>'email','title'=>'邮箱','type'=>'text','help'=>'用户邮箱,用于找回密码等安全操作'),
|
||||
array('name'=>'qq','title'=>'QQ','type'=>'text','help'=>''),
|
||||
array('name'=>'score','title'=>'用户积分','type'=>'text','help'=>''),
|
||||
array('name'=>'signature','title'=>'用户签名','type'=>'textarea','help'=>''),
|
||||
array('name'=>'status','title'=>'状态','type'=>'select','option'=>array('0'=>'禁用','1'=>'启用'),'help'=>''),
|
||||
);
|
||||
|
||||
public $addfield = array(
|
||||
array('name'=>'username','title'=>'用户名','type'=>'text','help'=>'用户名会作为默认的昵称'),
|
||||
array('name'=>'password','title'=>'密码','type'=>'password','help'=>'用户密码不能少于6位'),
|
||||
array('name'=>'repassword','title'=>'确认密码','type'=>'password','help'=>'确认密码'),
|
||||
array('name'=>'email','title'=>'邮箱','type'=>'text','help'=>'用户邮箱,用于找回密码等安全操作'),
|
||||
);
|
||||
|
||||
public $useredit = array(
|
||||
array('name'=>'uid','type'=>'hidden'),
|
||||
array('name'=>'nickname','title'=>'昵称','type'=>'text','help'=>''),
|
||||
array('name'=>'sex','title'=>'性别','type'=>'select','option'=>array('0'=>'保密','1'=>'男','2'=>'女'),'help'=>''),
|
||||
array('name'=>'email','title'=>'邮箱','type'=>'text','help'=>'用户邮箱,用于找回密码等安全操作'),
|
||||
array('name'=>'qq','title'=>'QQ','type'=>'text','help'=>''),
|
||||
array('name'=>'score','title'=>'用户积分','type'=>'text','help'=>''),
|
||||
array('name'=>'signature','title'=>'用户签名','type'=>'textarea','help'=>''),
|
||||
);
|
||||
|
||||
protected function setStatusAttr($value){
|
||||
return 1;
|
||||
}
|
||||
|
||||
protected function setPasswordAttr($value){
|
||||
return md5($value.$this->data['salt']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户登录模型
|
||||
*/
|
||||
public function login($username = '', $password = '', $type = 1){
|
||||
$map = array();
|
||||
switch ($type) {
|
||||
case 1:
|
||||
$map['username'] = $username;
|
||||
break;
|
||||
case 2:
|
||||
$map['email'] = $username;
|
||||
break;
|
||||
case 3:
|
||||
$map['mobile'] = $username;
|
||||
break;
|
||||
case 4:
|
||||
$map['uid'] = $username;
|
||||
break;
|
||||
case 5:
|
||||
$map['uid'] = $username;
|
||||
break;
|
||||
default:
|
||||
return 0; //参数错误
|
||||
}
|
||||
|
||||
$user = $this->db()->where($map)->find()->toArray();
|
||||
if(is_array($user) && $user['status']){
|
||||
/* 验证用户密码 */
|
||||
if(md5($password.$user['salt']) === $user['password']){
|
||||
$this->autoLogin($user); //更新用户登录信息
|
||||
return $user['uid']; //登录成功,返回用户ID
|
||||
} else {
|
||||
return -2; //密码错误
|
||||
}
|
||||
} else {
|
||||
return -1; //用户不存在或被禁用
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户注册
|
||||
* @param integer $user 用户信息数组
|
||||
*/
|
||||
function register($username, $password, $repassword, $isautologin = true){
|
||||
if ($password !== $repassword) {
|
||||
$this->error = "密码和确认密码不相同";
|
||||
return false;
|
||||
}
|
||||
|
||||
$data['username'] = $username;
|
||||
$data['salt'] = rand_string(6);
|
||||
$data['password'] = $password;
|
||||
$result = $this->validate(true)->save($data);
|
||||
if ($result) {
|
||||
$this->data['uid'] = $result;
|
||||
if ($isautologin) {
|
||||
$this->autoLogin($this->data);
|
||||
}
|
||||
return $result;
|
||||
}else{
|
||||
if (!$this->getError()) {
|
||||
$this->error = "注册失败!";
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 自动登录用户
|
||||
* @param integer $user 用户信息数组
|
||||
*/
|
||||
private function autoLogin($user){
|
||||
/* 更新登录信息 */
|
||||
$data = array(
|
||||
'uid' => $user['uid'],
|
||||
'login' => array('exp', '`login`+1'),
|
||||
'last_login_time' => time(),
|
||||
'last_login_ip' => get_client_ip(1),
|
||||
);
|
||||
$this->db()->where(array('uid'=>$user['uid']))->update($data);
|
||||
$user = $this->db()->where(array('uid'=>$user['uid']))->find();
|
||||
|
||||
/* 记录登录SESSION和COOKIES */
|
||||
$auth = array(
|
||||
'uid' => $user['uid'],
|
||||
'username' => $user['username'],
|
||||
'last_login_time' => $user['last_login_time'],
|
||||
);
|
||||
|
||||
session('user_auth', $auth);
|
||||
session('user_auth_sign', data_auth_sign($auth));
|
||||
}
|
||||
|
||||
public function logout(){
|
||||
session('user_auth', null);
|
||||
session('user_auth_sign', null);
|
||||
}
|
||||
|
||||
public function getInfo($uid){
|
||||
$data = $this->db()->where(array('uid'=>$uid))->find();
|
||||
if ($data) {
|
||||
return $data->toArray();
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function change(){
|
||||
$data = input('post.');
|
||||
if ($data['uid']) {
|
||||
return $this->save($data, array('uid'=>$data['uid']));
|
||||
}else{
|
||||
$this->error = "非法操作!";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function editpw(){
|
||||
$data = input('post.');
|
||||
$username = session('user_auth.username');
|
||||
$uid = session('user_auth.uid');
|
||||
$result = $this->checkPassword($username,$data['oldpassword']);
|
||||
if (!$result) {
|
||||
$this->error = '原始密码错误!';
|
||||
return false;
|
||||
}
|
||||
if (!$data['password']) {
|
||||
$this->error = '密码不能为空!';
|
||||
return false;
|
||||
}
|
||||
if ($data['password'] !== $data['repassword']) {
|
||||
$this->error = '密码和确认密码不相同!';
|
||||
return false;
|
||||
}
|
||||
if (!$uid) {
|
||||
return false;
|
||||
}
|
||||
$data['salt'] = rand_string(6);
|
||||
$data['password'] = md5($data['password'].$data['salt']);
|
||||
$data['uid'] = $uid;
|
||||
return $this->db()->where(array('uid'=>$uid))->update($data);
|
||||
}
|
||||
|
||||
protected function checkPassword($username,$password){
|
||||
if (!$username || !$password) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$user = $this->db()->where(array('username'=>$username))->find()->toArray();
|
||||
if (md5($password.$user['salt']) === $user['password']) {
|
||||
return true;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
32
application/common/validate/Book.php
Normal file
32
application/common/validate/Book.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?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\validate;
|
||||
|
||||
/**
|
||||
* 设置模型
|
||||
*/
|
||||
class Book extends \think\Validate{
|
||||
|
||||
protected $rule = array(
|
||||
'book_name' => 'require',
|
||||
'stand_class' => 'require',
|
||||
);
|
||||
|
||||
protected $message = array(
|
||||
'book_name' => '书名称必须!',
|
||||
'stand_class' => '图书标准类型必须!',
|
||||
);
|
||||
|
||||
protected $scene = array(
|
||||
'add' => array('book_name', 'stand_class'),
|
||||
'edit' => array('book_name', 'stand_class')
|
||||
);
|
||||
|
||||
}
|
||||
33
application/common/validate/Config.php
Normal file
33
application/common/validate/Config.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?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\validate;
|
||||
|
||||
/**
|
||||
* 设置模型
|
||||
*/
|
||||
class Config extends \think\Validate{
|
||||
|
||||
protected $rule = array(
|
||||
'name' => 'require|unique',
|
||||
'title' => 'require',
|
||||
);
|
||||
|
||||
protected $message = array(
|
||||
'name.require' => '配置标识必须',
|
||||
'name.unique' => '配置标识已经存在',
|
||||
'title' => '配置名称必须',
|
||||
);
|
||||
|
||||
protected $scene = array(
|
||||
'add' => array('name', 'title'),
|
||||
'edit' => array('title')
|
||||
);
|
||||
|
||||
}
|
||||
26
application/common/validate/Member.php
Normal file
26
application/common/validate/Member.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?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\validate;
|
||||
|
||||
/**
|
||||
* 设置模型
|
||||
*/
|
||||
class Member extends \think\Validate{
|
||||
|
||||
protected $rule = array(
|
||||
'username' => 'require|unique:member|/^[a-zA-Z]\w{0,39}$/',
|
||||
);
|
||||
protected $message = array(
|
||||
'username.require' => '用户名必须',
|
||||
'username.unique' => '用户名已存在',
|
||||
);
|
||||
protected $scene = array();
|
||||
|
||||
}
|
||||
33
application/common/validate/Model.php
Normal file
33
application/common/validate/Model.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?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\validate;
|
||||
|
||||
/**
|
||||
* 设置模型
|
||||
*/
|
||||
class Model extends \think\Validate{
|
||||
|
||||
protected $rule = array(
|
||||
'name' => 'require|unique:model|/^[a-zA-Z]\w{0,39}$/',
|
||||
'title' => 'require|length:1,30'
|
||||
);
|
||||
protected $message = array(
|
||||
'name' => '模型名错误!',
|
||||
'name.require' => '模型名必须!',
|
||||
'name.unique' => '模型名已存在!',
|
||||
'title.require' => '模型标题必须!',
|
||||
'title.length' => '模型标题长度错误!',
|
||||
);
|
||||
protected $scene = array(
|
||||
'add' => 'name,title',
|
||||
'edit' => 'title',
|
||||
);
|
||||
|
||||
}
|
||||
24
application/common/view/default/ad/sider.html
Normal file
24
application/common/view/default/ad/sider.html
Normal file
@@ -0,0 +1,24 @@
|
||||
<div class="banner">
|
||||
<div class="warp">
|
||||
<div class="banner-side">
|
||||
<ul>
|
||||
{volist name="ad" id="item"}
|
||||
<li>
|
||||
<a href="{$item['url']}" target="_blank">
|
||||
<img src="{:get_cover($item['cover_id'],'path')}">
|
||||
<div class="title"><span>{$item['title']}</span></div>
|
||||
</a>
|
||||
</li>
|
||||
{/volist}
|
||||
</ul>
|
||||
<ol class="dots">
|
||||
{volist name="ad" id="item"}
|
||||
<li class="dot">{$item['title']}</li>
|
||||
{/volist}
|
||||
</ol>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
$(".banner-side").slide({mainCell:"ul",titCell:".dots .dot",autoPlay:true});
|
||||
</script>
|
||||
39
application/common/view/default/form/attach.html
Normal file
39
application/common/view/default/form/attach.html
Normal file
@@ -0,0 +1,39 @@
|
||||
<div class="picker-box">
|
||||
<div id="picker_{$field}" class="picker_button">上传文件</div>
|
||||
<input type="hidden" name="{$field}" id="field_{$field}" value="{$value['id']|default=''}">
|
||||
<div id="fileList_{$field}" class="upload-file-list-info" style="width:280px;">
|
||||
{if isset($value['id'])}
|
||||
<li class="affix-list-item" id="WU_FILE_0">
|
||||
<div class="upload-file-info">
|
||||
<span class="webuploader-pick-file-close" data-queued-id="WU_FILE_0" data-id="{$value['id']}" data-fileurl="{$value['savename']}"><i class="close"></i></span>
|
||||
<span class="fname"></span>
|
||||
<span class="fsize">上传时间:{$value['create_time']|date='Y-m-d H:i:s',###}</span>
|
||||
<div class="clearfix"></div>
|
||||
</div>
|
||||
<div class="filebox image">
|
||||
文件名{$value['savename']}
|
||||
</div>
|
||||
</li>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
uploadsize = 2;
|
||||
$(function(){
|
||||
$("#picker_{$field}").SentUploader({
|
||||
fileNumLimit:1,
|
||||
uploadEvents: {
|
||||
uploadComplete:function(file){}
|
||||
},
|
||||
listName : 'fileList_{$field}',
|
||||
hiddenName: 'field_{$field}',
|
||||
hiddenValType:1,
|
||||
fileSingleSizeLimit:uploadsize*1024*1024,
|
||||
closeX:true
|
||||
},
|
||||
{
|
||||
fileType: 'service',
|
||||
filename : 'attachment',
|
||||
});
|
||||
});
|
||||
</script>
|
||||
10
application/common/view/default/form/datetime.html
Normal file
10
application/common/view/default/form/datetime.html
Normal file
@@ -0,0 +1,10 @@
|
||||
<div class="input-group">
|
||||
<input type="text" class="form-control" id="{$field}" name="{$field}" value="{$value}" readonly size="15">
|
||||
<span class="input-group-addon"><i class="fa fa-th"></i></span>
|
||||
</div>
|
||||
<script>
|
||||
$('#{$field}').fdatepicker({
|
||||
format: 'yyyy-mm-dd hh:ii:ss',
|
||||
pickTime: true
|
||||
});
|
||||
</script>
|
||||
19
application/common/view/default/form/editor.html
Normal file
19
application/common/view/default/form/editor.html
Normal file
@@ -0,0 +1,19 @@
|
||||
<textarea name="{$field}" id="{$field}">{$value}</textarea>
|
||||
<script type="text/javascript">
|
||||
serverUrl = "{:url('upload/ueditor')}";
|
||||
{if $option == 'all' || $option == ''}
|
||||
var ue = UE.getEditor("{$field}",{
|
||||
serverUrl : serverUrl,
|
||||
initialFrameWidth : "100%",
|
||||
initialFrameHeight : "300"
|
||||
});
|
||||
{elseif $option == 'mini'/}
|
||||
var ue = UE.getEditor("{$field}",{
|
||||
toolbars: [
|
||||
['source', 'bold', 'italic', 'underline', 'fontborder', 'strikethrough', '|','link', 'unlink', '|','simpleupload',]
|
||||
],
|
||||
initialFrameWidth : "100%",
|
||||
initialFrameHeight : "120"
|
||||
});
|
||||
{/if}
|
||||
</script>
|
||||
42
application/common/view/default/form/image.html
Normal file
42
application/common/view/default/form/image.html
Normal file
@@ -0,0 +1,42 @@
|
||||
<div class="picker-box">
|
||||
<div id="picker_{$field}" class="picker_button">上传图片</div>
|
||||
<input type="hidden" name="{$field}" id="field_{$field}" value="{$value|default=''}">
|
||||
<div id="fileList_{$field}" class="upload-file-list-info" style="width:280px;">
|
||||
{if $value}
|
||||
{php}
|
||||
$images = get_cover($value);
|
||||
{/php}
|
||||
<li class="affix-list-item" id="WU_FILE_0">
|
||||
<div class="upload-file-info">
|
||||
<span class="webuploader-pick-file-close" data-queued-id="WU_FILE_0" data-id="{$value}" data-fileurl="{$images['path']}"><i class="close"></i></span>
|
||||
<span class="fname"></span>
|
||||
<span class="fsize">上传时间:{$images['create_time']|date='Y-m-d H:i:s',###}</span>
|
||||
<div class="clearfix"></div>
|
||||
</div>
|
||||
<div class="filebox image">
|
||||
<img src="{:config('base_url')}{$images['path']}" class="img-responsive">
|
||||
</div>
|
||||
</li>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
uploadsize = 2;
|
||||
$(function(){
|
||||
$("#picker_{$field}").SentUploader({
|
||||
fileNumLimit:1,
|
||||
uploadEvents: {
|
||||
uploadComplete:function(file){}
|
||||
},
|
||||
listName : 'fileList_{$field}',
|
||||
hiddenName: 'field_{$field}',
|
||||
hiddenValType:1,
|
||||
fileSingleSizeLimit:uploadsize*1024*1024,
|
||||
closeX:true
|
||||
},
|
||||
{
|
||||
fileType: 'service',
|
||||
filename : 'images',
|
||||
});
|
||||
});
|
||||
</script>
|
||||
46
application/common/view/default/form/images.html
Normal file
46
application/common/view/default/form/images.html
Normal file
@@ -0,0 +1,46 @@
|
||||
<div class="picker-box">
|
||||
<div id="picker_{$field}" class="picker_button">上传多图</div>
|
||||
<input type="hidden" name="{$field}" id="field_{$field}" {if condition="$value neq '0'"}value="{$value}"{/if}>
|
||||
<div id="fileList_{$field}" class="upload-file-list-info" style="width:280px;">
|
||||
{if condition="$value"}
|
||||
{php}
|
||||
$img_list = explode(',',$value);
|
||||
{/php}
|
||||
{volist name="img_list" id="item"}
|
||||
{php}
|
||||
$images = get_cover($item);
|
||||
{/php}
|
||||
<li class="affix-list-item" id="WU_FILE_{$key}">
|
||||
<div class="upload-file-info">
|
||||
<span class="webuploader-pick-file-close" data-queued-id="WU_FILE_{$key}" data-id="{$item}" data-fileurl="{$images['path']}"><i class="close"></i></span>
|
||||
<span class="fname"></span>
|
||||
<span class="fsize">上传时间:{$images['create_time']|date='Y-m-d H:i:s',###}</span>
|
||||
<div class="clearfix"></div>
|
||||
</div>
|
||||
<div class="filebox image">
|
||||
<img src="{:config('base_url')}{$images['path']}" class="img-responsive">
|
||||
</div>
|
||||
</li>
|
||||
{/volist}
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
uploadsize = 2;
|
||||
$(function(){
|
||||
$("#picker_{$field}").SentUploader({
|
||||
uploadEvents: {
|
||||
uploadComplete:function(file){}
|
||||
},
|
||||
listName : 'fileList_{$field}',
|
||||
hiddenName: 'field_{$field}',
|
||||
hiddenValType:1,
|
||||
fileSingleSizeLimit:uploadsize*1024*1024,
|
||||
closeX:true
|
||||
},
|
||||
{
|
||||
fileType: 'service',
|
||||
filename : 'images',
|
||||
});
|
||||
});
|
||||
</script>
|
||||
32
application/common/view/default/form/kanban.html
Normal file
32
application/common/view/default/form/kanban.html
Normal file
@@ -0,0 +1,32 @@
|
||||
<div class="boards" id="{$field}_sort">
|
||||
{volist name="option" id="vo"}
|
||||
<div class="board panel panel-info">
|
||||
<div class="panel-heading">{$vo['name']}</div>
|
||||
<div class="panel-body">
|
||||
<div class="board-list" data-group="{$key}">
|
||||
{foreach name="vo['list']" item="item" key="k"}
|
||||
{php}
|
||||
$item['group'] = isset($item['group']) ? $item['group'] : '';
|
||||
{/php}
|
||||
{if (($i eq 1) or ($item['group'] eq $key)) and ($item['is_show'] eq 1)}
|
||||
<div class="board-item">
|
||||
<span data="{$item['id']}">{$item['title']} [{$item['name']}]</span>
|
||||
<input type="hidden" name="{$field}[{$key}][]" value="{$item['id']}"/>
|
||||
</div>
|
||||
{/if}
|
||||
{/foreach}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/volist}
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
$(function(){
|
||||
$('.form-group #{$field}_sort').boards({
|
||||
drop: function(e){
|
||||
var group = e.target.closest('.board').find('.board-list').attr('data-group');
|
||||
e.element.find('input').attr('name','{$field}[' + group + '][]')
|
||||
}
|
||||
})
|
||||
})
|
||||
</script>
|
||||
59
application/common/view/default/form/show.html
Normal file
59
application/common/view/default/form/show.html
Normal file
@@ -0,0 +1,59 @@
|
||||
{switch name="type"}
|
||||
{case value="readonly"}
|
||||
<input type="text" class="form-control" name="{$field}" id="{$field}" value="{$value}" readonly>
|
||||
{/case}
|
||||
{case value="num"}
|
||||
<input type="text" style="width: auto;" class="form-control" name="{$field}" id="{$field}" value="{$value}">
|
||||
{/case}
|
||||
{case value="decimal"}
|
||||
<input type="text" style="width: auto;" class="form-control" name="{$field}" id="{$field}" value="{$value}">
|
||||
{/case}
|
||||
{case value="text"}
|
||||
<input type="text" class="form-control" name="{$field}" id="{$field}" value="{$value}">
|
||||
{/case}
|
||||
{case value="password"}
|
||||
<input type="password" class="form-control" name="{$field}" id="{$field}" value="{$value}">
|
||||
{/case}
|
||||
{case value="textarea"}
|
||||
<textarea class="form-control" name="{$field}" id="{$field}">{$value}</textarea>
|
||||
{/case}
|
||||
{case value="select"}
|
||||
<select class="form-control" name="{$field}" id="{$field}" style="width:auto;">
|
||||
{volist name="option" id="item"}
|
||||
<option value="{$key}" {if condition="$key eq $value"}selected{/if}>{$item}</option>
|
||||
{/volist}
|
||||
</select>
|
||||
{/case}
|
||||
{case value="bool"}
|
||||
<select class="form-control" name="{$field}" id="{$field}" style="width:auto;">
|
||||
{volist name="option" id="item"}
|
||||
<option value="{$key}" {if condition="$key eq $value"}selected{/if}>{$item}</option>
|
||||
{/volist}
|
||||
</select>
|
||||
{/case}
|
||||
{case value="bind"}
|
||||
<select class="form-control" name="{$field}" id="{$field}" style="width:auto;">
|
||||
{volist name="option" id="item"}
|
||||
<option value="{$key}" {if condition="$key eq $value"}selected{/if}>{$item}</option>
|
||||
{/volist}
|
||||
</select>
|
||||
{/case}
|
||||
{case value="checkbox"}
|
||||
{php}$value = isset($value) ? $value : 1;{/php}
|
||||
{volist name="option" id="item"}
|
||||
<div class="checkbox-nice checkbox-inline">
|
||||
<input type="checkbox" name="{$field}[]" id="{$field}-{$key}" value="{$key}" {if $key == $value}checked{/if}/>
|
||||
<label for="{$field}-{$key}">{$item}</label>
|
||||
</div>
|
||||
{/volist}
|
||||
{/case}
|
||||
{case value="radio"}
|
||||
{php}$value = isset($value) ? $value : 1;{/php}
|
||||
{volist name="option" id="item"}
|
||||
<div class="radio radio-nice radio-inline">
|
||||
<input type="radio" name="{$field}" id="{$field}-{$key}" value="{$key}" {if condition="$key eq $value"}checked{/if}/>
|
||||
<label for="{$field}-{$key}">{$item}</label>
|
||||
</div>
|
||||
{/volist}
|
||||
{/case}
|
||||
{/switch}
|
||||
1
application/common/view/default/form/tags.html
Normal file
1
application/common/view/default/form/tags.html
Normal file
@@ -0,0 +1 @@
|
||||
<input type="text" value="{$value}" id="{$field}" name="{$field}" data-role="tagsinput" />
|
||||
27
application/common/view/default/jump.html
Normal file
27
application/common/view/default/jump.html
Normal file
@@ -0,0 +1,27 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>信息提示</title>
|
||||
<script type="text/javascript" src="__PUBLIC__/js/jquery.js"></script>
|
||||
<script type="text/javascript" src="__PUBLIC__/plugs/layer/layer.js"></script>
|
||||
<style type="text/css">
|
||||
body,html{font-family: "微软雅黑","Microsoft YaHei";}
|
||||
</style>
|
||||
<script type="text/javascript">
|
||||
$(function(){
|
||||
layer.confirm('{$msg|strip_tags}', {
|
||||
closeBtn : 0
|
||||
,skin: 'layui-layer-lan' //样式类名
|
||||
,btn: ['返回首页','返回上一页'] //按钮
|
||||
}, function(){
|
||||
window.location = '/';
|
||||
}, function(){
|
||||
history.go(-1);
|
||||
});
|
||||
})
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
</body>
|
||||
</html>
|
||||
73
application/common/widget/Ad.php
Normal file
73
application/common/widget/Ad.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
namespace app\common\widget;
|
||||
|
||||
/**
|
||||
* 分类widget
|
||||
* 用于动态调用分类信息
|
||||
*/
|
||||
|
||||
class Ad{
|
||||
|
||||
public function run($name){
|
||||
$map['name'] = $name;
|
||||
$place = db('AdPlace')->where($map)->find();
|
||||
if (empty($place) || !$place) {
|
||||
echo "";return;
|
||||
}
|
||||
if ($place['status'] != '1') {
|
||||
echo "";return;
|
||||
}
|
||||
$ad = db('Ad')->where(array('place_id'=>$place['id'],'status'=>1))->select();
|
||||
foreach ($ad as $key => $value) {
|
||||
if ($value['photolist'] != '') {
|
||||
$photolist = explode(',', $value['photolist']);
|
||||
$listurl = explode("\n", $value['listurl']);
|
||||
foreach ($photolist as $k => $val) {
|
||||
$value['image'][] = array('img'=>get_cover($val,'path'),'url'=>$listurl[$k]);
|
||||
}
|
||||
}else{
|
||||
$value['image'] = array();
|
||||
}
|
||||
if ($value['cover_id']) {
|
||||
$value['cover'] = get_cover($value['cover_id'],'path');
|
||||
}
|
||||
$list[] = $value;
|
||||
}
|
||||
switch ($place['show_type']) {
|
||||
//幻灯片显示
|
||||
case '1':
|
||||
$template = $place['template'] ? $place['template'] : "sider";
|
||||
break;
|
||||
//对联广告
|
||||
case '2':
|
||||
$template = $place['template'] ? $place['template'] : "couplet";
|
||||
break;
|
||||
//图片列表广告
|
||||
case '3':
|
||||
$template = $place['template'] ? $place['template'] : "image";
|
||||
break;
|
||||
//图文列表广告
|
||||
case '4':
|
||||
$template = $place['template'] ? $place['template'] : "images";
|
||||
break;
|
||||
//文字列表广告
|
||||
case '5':
|
||||
$template = $place['template'] ? $place['template'] : "text";
|
||||
break;
|
||||
//代码广告广告
|
||||
case '6':
|
||||
$template = $place['template'] ? $place['template'] : "code";
|
||||
break;
|
||||
default:
|
||||
$template = $place['template'] ? $place['template'] : "default";
|
||||
break;
|
||||
}
|
||||
$data = array(
|
||||
'place' => $place,
|
||||
'ad' => $list,
|
||||
);
|
||||
$view = new \think\View();
|
||||
$view->assign($data);
|
||||
return $view->fetch('common@default/ad/'.$template);
|
||||
}
|
||||
}
|
||||
32
application/common/widget/Form.php
Normal file
32
application/common/widget/Form.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
namespace app\common\widget;
|
||||
|
||||
/**
|
||||
* 上传插件widget
|
||||
* 用于动态调用分类信息
|
||||
*/
|
||||
class Form {
|
||||
|
||||
public function show($field, $info){
|
||||
$type = isset($field['type']) ? $field['type'] : 'text';
|
||||
//类型合并
|
||||
if (in_array($type, array('string'))) {
|
||||
$type = 'text';
|
||||
}
|
||||
if (in_array($type, array('picture'))) {
|
||||
$type = 'image';
|
||||
}
|
||||
$data = array(
|
||||
'type' => $type,
|
||||
'field' => isset($field['name']) ? $field['name'] : '',
|
||||
'value' => isset($info[$field['name']]) ? $info[$field['name']] : '',
|
||||
'size' => isset($field['size']) ? $field['size'] : 12,
|
||||
'option' =>isset($field['option']) ? $field['option'] : ''
|
||||
);
|
||||
$no_tem = array('readonly', 'text', 'password', 'textarea', 'select', 'bind', 'checkbox', 'radio', 'num','bool','decimal');
|
||||
$type = !in_array($type, $no_tem) ? $type : 'show';
|
||||
$view = new \think\View();
|
||||
$view->assign($data);
|
||||
return $view->fetch('common@default/form/'.$type);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user