初始化项目
This commit is contained in:
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user