代码格式化
This commit is contained in:
@@ -13,128 +13,129 @@ namespace app\common\controller;
|
||||
* 插件类
|
||||
* @author yangweijie <yangweijiester@gmail.com>
|
||||
*/
|
||||
class Addons extends Base{
|
||||
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 $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(){
|
||||
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';
|
||||
$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);
|
||||
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;
|
||||
}
|
||||
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;
|
||||
$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));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取插件所需的钩子是否存在,没有则新增
|
||||
* @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();
|
||||
}
|
||||
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();
|
||||
}
|
||||
}
|
||||
@@ -8,48 +8,48 @@
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\common\controller;
|
||||
use app\common\model\AuthRule;
|
||||
use app\common\model\AuthGroup;
|
||||
use app\common\model\AuthRule;
|
||||
|
||||
class Admin extends Base{
|
||||
class Admin extends Base {
|
||||
|
||||
public function _initialize(){
|
||||
public function _initialize() {
|
||||
parent::_initialize();
|
||||
|
||||
if (!is_login() and !in_array($this->url,array('admin/index/login', 'admin/index/logout', 'admin/index/verify'))) {
|
||||
if (!is_login() and !in_array($this->url, array('admin/index/login', 'admin/index/logout', 'admin/index/verify'))) {
|
||||
$this->redirect('admin/index/login');
|
||||
}
|
||||
|
||||
if (!in_array($this->url,array('admin/index/login', 'admin/index/logout', 'admin/index/verify'))) {
|
||||
if (!in_array($this->url, array('admin/index/login', 'admin/index/logout', 'admin/index/verify'))) {
|
||||
|
||||
// 是否是超级管理员
|
||||
define('IS_ROOT', is_administrator());
|
||||
if(!IS_ROOT && \think\Config::get('admin_allow_ip')){
|
||||
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')))){
|
||||
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 ) {
|
||||
if (!IS_ROOT) {
|
||||
$access = $this->accessControl();
|
||||
if (false === $access) {
|
||||
$this->error('403:禁止访问');
|
||||
}elseif(null === $access ){
|
||||
$dynamic = $this->checkDynamic();//检测分类栏目有关的各项动态权限
|
||||
if( $dynamic === null ){
|
||||
} elseif (null === $access) {
|
||||
$dynamic = $this->checkDynamic(); //检测分类栏目有关的各项动态权限
|
||||
if ($dynamic === null) {
|
||||
//检测访问权限
|
||||
if ( !$this->checkRule($this->url,array('in','1,2')) ){
|
||||
if (!$this->checkRule($this->url, array('in', '1,2'))) {
|
||||
$this->error('未授权访问!');
|
||||
}else{
|
||||
} else {
|
||||
// 检测分类及内容有关的各项动态权限
|
||||
$dynamic = $this->checkDynamic();
|
||||
if( false === $dynamic ){
|
||||
$dynamic = $this->checkDynamic();
|
||||
if (false === $dynamic) {
|
||||
$this->error('未授权访问!');
|
||||
}
|
||||
}
|
||||
}elseif( $dynamic === false ){
|
||||
} elseif ($dynamic === false) {
|
||||
$this->error('未授权访问!');
|
||||
}
|
||||
}
|
||||
@@ -61,18 +61,18 @@ class Admin extends Base{
|
||||
}
|
||||
|
||||
/**
|
||||
* 权限检测
|
||||
* @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;
|
||||
* 权限检测
|
||||
* @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();
|
||||
$Auth = new \com\Auth();
|
||||
}
|
||||
if(!$Auth->check($rule,session('user_auth.uid'),$type,$mode)){
|
||||
if (!$Auth->check($rule, session('user_auth.uid'), $type, $mode)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -87,11 +87,11 @@ class Admin extends Base{
|
||||
*
|
||||
* @author 朱亚杰 <xcoolcc@gmail.com>
|
||||
*/
|
||||
protected function checkDynamic(){
|
||||
if(IS_ROOT){
|
||||
return true;//管理员允许访问任何页面
|
||||
protected function checkDynamic() {
|
||||
if (IS_ROOT) {
|
||||
return true; //管理员允许访问任何页面
|
||||
}
|
||||
return null;//不明,需checkRule
|
||||
return null; //不明,需checkRule
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -104,38 +104,39 @@ class Admin extends Base{
|
||||
* 返回 **null**, 需要继续执行节点权限检测决定是否允许访问
|
||||
* @author 朱亚杰 <xcoolcc@gmail.com>
|
||||
*/
|
||||
final protected function accessControl(){
|
||||
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中的方法
|
||||
$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) ) {
|
||||
if (!empty($allow) && in_array_case($check, $allow)) {
|
||||
return true;
|
||||
}
|
||||
return null;//需要检测节点权限
|
||||
return null; //需要检测节点权限
|
||||
}
|
||||
|
||||
protected function setMenu(){
|
||||
$hover_url = $this->request->module().'/'.$this->request->controller();
|
||||
protected function setMenu() {
|
||||
$hover_url = $this->request->module() . '/' . $this->request->controller();
|
||||
$controller = $this->url;
|
||||
$menu = array(
|
||||
$menu = array(
|
||||
'main' => array(),
|
||||
'child' => array(),
|
||||
'child' => array(),
|
||||
);
|
||||
$where['pid'] = 0;
|
||||
$where['hide'] = 0;
|
||||
$where['type'] = 'admin';
|
||||
if(!config('develop_mode')){ // 是否开发者模式
|
||||
$where['is_dev'] = 0;
|
||||
$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) ) {
|
||||
if (!IS_ROOT && !$this->checkRule($value['url'], 2, null)) {
|
||||
unset($menu['main'][$value['id']]);
|
||||
continue;//继续循环
|
||||
continue; //继续循环
|
||||
}
|
||||
if ($controller == $value['url']) {
|
||||
$value['style'] = "active";
|
||||
@@ -145,39 +146,39 @@ class Admin extends Base{
|
||||
|
||||
// 查找当前子菜单
|
||||
$pid = db('menu')->where("pid !=0 AND url like '%{$hover_url}%'")->value('pid');
|
||||
$id = db('menu')->where("pid = 0 AND url like '%{$hover_url}%'")->value('id');
|
||||
$id = db('menu')->where("pid = 0 AND url like '%{$hover_url}%'")->value('id');
|
||||
$pid = $pid ? $pid : $id;
|
||||
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();
|
||||
$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 (IS_ROOT || $this->checkRule($value['url'], 2, null)) {
|
||||
if ($controller == $value['url']) {
|
||||
$menu['main'][$value['pid']]['style'] = "active";
|
||||
$value['style'] = "active";
|
||||
$value['style'] = "active";
|
||||
}
|
||||
$menu['child'][$value['group']][] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->assign('__menu__',$menu);
|
||||
$this->assign('__menu__', $menu);
|
||||
}
|
||||
|
||||
protected function getContentMenu(){
|
||||
protected function getContentMenu() {
|
||||
$model = \think\Loader::model('Model');
|
||||
$list = array();
|
||||
$map = array(
|
||||
'status' => array('gt',0),
|
||||
'extend' => array('gt',0),
|
||||
$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) {
|
||||
@@ -185,41 +186,40 @@ class Admin extends Base{
|
||||
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;
|
||||
$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));
|
||||
$this->assign('extend_menu', array('内容管理' => $menu));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected function getAddonsMenu(){
|
||||
protected function getAddonsMenu() {
|
||||
$model = db('Addons');
|
||||
$list = array();
|
||||
$map = array(
|
||||
'status' => array('gt',0),
|
||||
$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;
|
||||
$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));
|
||||
$this->assign('extend_menu', array('管理插件' => $menu));
|
||||
}
|
||||
}
|
||||
|
||||
protected function setMeta($title = ''){
|
||||
$this->assign('meta_title',$title);
|
||||
protected function setMeta($title = '') {
|
||||
$this->assign('meta_title', $title);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ class Api {
|
||||
|
||||
protected $data;
|
||||
|
||||
public function __construct(){
|
||||
$this->data = array('code' => 0, 'msg' => '', 'time' => time(), 'data' => '');
|
||||
public function __construct() {
|
||||
$this->data = array('code' => 0, 'msg' => '', 'time' => time(), 'data' => '');
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
namespace app\common\controller;
|
||||
|
||||
class Base extends \think\Controller{
|
||||
class Base extends \think\Controller {
|
||||
|
||||
protected $url;
|
||||
protected $request;
|
||||
@@ -17,31 +17,31 @@ class Base extends \think\Controller{
|
||||
protected $controller;
|
||||
protected $action;
|
||||
|
||||
public function _initialize(){
|
||||
public function _initialize() {
|
||||
if (!is_file(APP_PATH . 'database.php') || !is_file(APP_PATH . 'install.lock')) {
|
||||
return $this->redirect('install/index/index');
|
||||
}
|
||||
/* 读取数据库中的配置 */
|
||||
$config = cache('db_config_data');
|
||||
if(!$config){
|
||||
$config = model('Config')->lists();
|
||||
cache('db_config_data',$config);
|
||||
$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){
|
||||
public function execute($mc = null, $op = '', $ac = null) {
|
||||
$op = $op ? $op : $this->request->module();
|
||||
if(\think\Config::get('url_case_insensitive')){
|
||||
if (\think\Config::get('url_case_insensitive')) {
|
||||
$mc = ucfirst(parse_name($mc, 1));
|
||||
$op = parse_name($op,1);
|
||||
$op = parse_name($op, 1);
|
||||
}
|
||||
|
||||
if(!empty($mc) && !empty($op) && !empty($ac)){
|
||||
$ops = ucwords($op);
|
||||
$class = "\\addons\\{$mc}\\controller\\{$ops}";
|
||||
|
||||
if (!empty($mc) && !empty($op) && !empty($ac)) {
|
||||
$ops = ucwords($op);
|
||||
$class = "\\addons\\{$mc}\\controller\\{$ops}";
|
||||
$addons = new $class;
|
||||
$addons->$ac();
|
||||
} else {
|
||||
@@ -55,34 +55,38 @@ class Base extends \think\Controller{
|
||||
* @param string $tablepre 自己的前缀
|
||||
* @return multitype:string 返回最终需要的sql语句
|
||||
*/
|
||||
public function sql_split($sql, $tablepre) {
|
||||
if ($tablepre != "sent_")
|
||||
public function sqlSplit($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;
|
||||
$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++;
|
||||
|
||||
}
|
||||
$num++;
|
||||
}
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
protected function setSeo($title = '', $keywords = '', $description = ''){
|
||||
protected function setSeo($title = '', $keywords = '', $description = '') {
|
||||
$seo = array(
|
||||
'title' => $title,
|
||||
'keywords' => $keywords,
|
||||
@@ -94,7 +98,7 @@ class Base extends \think\Controller{
|
||||
if (is_array($item)) {
|
||||
$item = implode(',', $item);
|
||||
}
|
||||
$meta[$key] = str_replace("[".$key."]", $item . '|', $meta[$key]);
|
||||
$meta[$key] = str_replace("[" . $key . "]", $item . '|', $meta[$key]);
|
||||
}
|
||||
|
||||
$data = array(
|
||||
@@ -105,15 +109,13 @@ class Base extends \think\Controller{
|
||||
$this->assign($data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 验证码
|
||||
* @param integer $id 验证码ID
|
||||
* @author 郭平平 <molong@tensent.cn>
|
||||
*/
|
||||
public function verify($id = 1){
|
||||
$verify = new \org\Verify(array('length'=>4));
|
||||
public function verify($id = 1) {
|
||||
$verify = new \org\Verify(array('length' => 4));
|
||||
$verify->entry($id);
|
||||
}
|
||||
|
||||
@@ -123,20 +125,20 @@ class Base extends \think\Controller{
|
||||
* @return boolean 检测结果
|
||||
* @author 麦当苗儿 <zuojiazi@vip.qq.com>
|
||||
*/
|
||||
public function checkVerify($code, $id = 1){
|
||||
public function checkVerify($code, $id = 1) {
|
||||
if ($code) {
|
||||
$verify = new \org\Verify();
|
||||
$result = $verify->check($code, $id);
|
||||
if (!$result) {
|
||||
return $this->error("验证码错误!", "");
|
||||
}
|
||||
}else{
|
||||
} else {
|
||||
return $this->error("验证码为空!", "");
|
||||
}
|
||||
}
|
||||
|
||||
//request信息
|
||||
protected function requestInfo(){
|
||||
protected function requestInfo() {
|
||||
$this->param = $this->request->param();
|
||||
defined('MODULE_NAME') or define('MODULE_NAME', $this->request->module());
|
||||
defined('CONTROLLER_NAME') or define('CONTROLLER_NAME', $this->request->controller());
|
||||
@@ -144,17 +146,17 @@ class Base extends \think\Controller{
|
||||
defined('IS_POST') or define('IS_POST', $this->request->isPost());
|
||||
defined('IS_GET') or define('IS_GET', $this->request->isGet());
|
||||
$this->url = $this->request->module() . '/' . $this->request->controller() . '/' . $this->request->action();
|
||||
$this->assign('request',$this->request);
|
||||
$this->assign('param',$this->param);
|
||||
$this->assign('request', $this->request);
|
||||
$this->assign('param', $this->param);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取单个参数的数组形式
|
||||
*/
|
||||
protected function getArrayParam($param){
|
||||
protected function getArrayParam($param) {
|
||||
if (isset($this->param['id'])) {
|
||||
return array_unique((array)$this->param[$param]);
|
||||
}else{
|
||||
return array_unique((array) $this->param[$param]);
|
||||
} else {
|
||||
return array();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,9 +9,9 @@
|
||||
|
||||
namespace app\common\controller;
|
||||
|
||||
class Fornt extends Base{
|
||||
class Fornt extends Base {
|
||||
|
||||
public function _initialize(){
|
||||
public function _initialize() {
|
||||
parent::_initialize();
|
||||
|
||||
//判读是否为关闭网站
|
||||
@@ -27,7 +27,7 @@ class Fornt extends Base{
|
||||
}
|
||||
|
||||
//当前栏目导航
|
||||
protected function setHoverNav(){
|
||||
protected function setHoverNav() {
|
||||
//dump($_SERVER['PHP_SELF']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,21 +11,24 @@ namespace app\common\controller;
|
||||
|
||||
class Upload {
|
||||
|
||||
public function upload(){
|
||||
$upload_type = input('get.filename','images','trim');
|
||||
$config = $this->$upload_type();
|
||||
/**
|
||||
* 上传控制器
|
||||
*/
|
||||
public function upload() {
|
||||
$upload_type = input('get.filename', 'images', 'trim');
|
||||
$config = $this->$upload_type();
|
||||
// 获取表单上传文件 例如上传了001.jpg
|
||||
$file = request()->file('file');
|
||||
$info = $file->move($config['rootPath'], true, false);
|
||||
|
||||
if($info){
|
||||
$return['status'] = 1;
|
||||
$return['info'] = $this->save($config, $upload_type, $info);
|
||||
}else{
|
||||
$return['status'] = 0;
|
||||
$return['info'] = $file->getError();
|
||||
if ($info) {
|
||||
$return['status'] = 1;
|
||||
$return['info'] = $this->save($config, $upload_type, $info);
|
||||
} else {
|
||||
$return['status'] = 0;
|
||||
$return['info'] = $file->getError();
|
||||
}
|
||||
|
||||
|
||||
echo json_encode($return);
|
||||
}
|
||||
|
||||
@@ -34,7 +37,7 @@ class Upload {
|
||||
* @var view
|
||||
* @access public
|
||||
*/
|
||||
protected function images(){
|
||||
protected function images() {
|
||||
return config('picture_upload');
|
||||
}
|
||||
|
||||
@@ -43,7 +46,7 @@ class Upload {
|
||||
* @var view
|
||||
* @access public
|
||||
*/
|
||||
protected function attachment(){
|
||||
protected function attachment() {
|
||||
return config('attachment_upload');
|
||||
}
|
||||
|
||||
@@ -52,26 +55,26 @@ class Upload {
|
||||
* @var view
|
||||
* @access public
|
||||
*/
|
||||
public function ueditor(){
|
||||
public function ueditor() {
|
||||
$data = new \com\Ueditor(session('auth_user.uid'));
|
||||
echo $data->output();
|
||||
}
|
||||
|
||||
public function editor(){
|
||||
public function editor() {
|
||||
$file = request()->file('upload_file');
|
||||
$info = $file->move(config('editor_upload.rootPath'), true, false);
|
||||
if ($info) {
|
||||
$data = $this->parse_file($info);
|
||||
$data = $this->parseFile($info);
|
||||
$data['success'] = true;
|
||||
$data['file_path'] = $data['url'];
|
||||
}else{
|
||||
$data['success'] = false;
|
||||
$data['msg'] = "error message";
|
||||
} else {
|
||||
$data['success'] = false;
|
||||
$data['msg'] = "error message";
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function delete(){
|
||||
public function delete() {
|
||||
$data = array(
|
||||
'status' => 1,
|
||||
);
|
||||
@@ -83,16 +86,16 @@ class Upload {
|
||||
* @var view
|
||||
* @access public
|
||||
*/
|
||||
public function save($config, $type, $file){
|
||||
$file = $this->parse_file($file);
|
||||
public function save($config, $type, $file) {
|
||||
$file = $this->parseFile($file);
|
||||
$file['status'] = 1;
|
||||
$dbname = ($type == 'images') ? 'picture' : 'file';
|
||||
$id = db($dbname)->insertGetId($file);
|
||||
|
||||
$dbname = ($type == 'images') ? 'picture' : 'file';
|
||||
$id = db($dbname)->insertGetId($file);
|
||||
|
||||
if ($id) {
|
||||
$data = db($dbname)->where(array('id'=>$id))->find();
|
||||
$data = db($dbname)->where(array('id' => $id))->find();
|
||||
return $data;
|
||||
}else{
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -104,21 +107,22 @@ class Upload {
|
||||
* @param string $args 回调函数参数
|
||||
* @return boolean 下载失败返回false
|
||||
*/
|
||||
public function downLocalFile($file, $callback = null, $args = null){
|
||||
if(is_file($file['rootpath'].$file['savepath'].$file['savename'])){
|
||||
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: 大文件断点续传
|
||||
/* 执行下载 *///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
|
||||
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']);
|
||||
readfile($file['rootpath'] . $file['savepath'] . $file['savename']);
|
||||
exit;
|
||||
} else {
|
||||
$this->error = '文件已被删除!';
|
||||
@@ -126,23 +130,23 @@ class Upload {
|
||||
}
|
||||
}
|
||||
|
||||
protected function parse_file($info){
|
||||
$data['create_time'] = $info->getATime(); //最后访问时间
|
||||
$data['savename'] = $info->getBasename(); //获取无路径的basename
|
||||
$data['c_time'] = $info->getCTime(); //获取inode修改时间
|
||||
$data['ext'] = $info->getExtension(); //文件扩展名
|
||||
$data['name'] = $info->getFilename(); //获取文件名
|
||||
$data['m_time'] = $info->getMTime(); //获取最后修改时间
|
||||
$data['owner'] = $info->getOwner(); //文件拥有者
|
||||
$data['savepath'] = $info->getPath(); //不带文件名的文件路径
|
||||
$data['url'] = $data['path'] = str_replace("\\", '/', substr($info->getPathname(), 1)); //全路径
|
||||
$data['size'] = $info->getSize(); //文件大小,单位字节
|
||||
$data['is_file'] = $info->isFile(); //是否是文件
|
||||
$data['is_execut'] = $info->isExecutable(); //是否可执行
|
||||
$data['is_readable'] = $info->isReadable(); //是否可读
|
||||
$data['is_writable'] = $info->isWritable(); //是否可写
|
||||
$data['md5'] = md5_file($info->getPathname());
|
||||
$data['sha1'] = sha1_file($info->getPathname());
|
||||
protected function parseFile($info) {
|
||||
$data['create_time'] = $info->getATime(); //最后访问时间
|
||||
$data['savename'] = $info->getBasename(); //获取无路径的basename
|
||||
$data['c_time'] = $info->getCTime(); //获取inode修改时间
|
||||
$data['ext'] = $info->getExtension(); //文件扩展名
|
||||
$data['name'] = $info->getFilename(); //获取文件名
|
||||
$data['m_time'] = $info->getMTime(); //获取最后修改时间
|
||||
$data['owner'] = $info->getOwner(); //文件拥有者
|
||||
$data['savepath'] = $info->getPath(); //不带文件名的文件路径
|
||||
$data['url'] = $data['path'] = str_replace("\\", '/', substr($info->getPathname(), 1)); //全路径
|
||||
$data['size'] = $info->getSize(); //文件大小,单位字节
|
||||
$data['is_file'] = $info->isFile(); //是否是文件
|
||||
$data['is_execut'] = $info->isExecutable(); //是否可执行
|
||||
$data['is_readable'] = $info->isReadable(); //是否可读
|
||||
$data['is_writable'] = $info->isWritable(); //是否可写
|
||||
$data['md5'] = md5_file($info->getPathname());
|
||||
$data['sha1'] = sha1_file($info->getPathname());
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
@@ -9,14 +9,14 @@
|
||||
|
||||
namespace app\common\controller;
|
||||
|
||||
class User extends Base{
|
||||
class User extends Base {
|
||||
|
||||
public function _initialize(){
|
||||
public function _initialize() {
|
||||
parent::_initialize();
|
||||
|
||||
if (!is_login() and !in_array($this->url,array('user/login/index', 'user/index/verify'))) {
|
||||
if (!is_login() and !in_array($this->url, array('user/login/index', 'user/index/verify'))) {
|
||||
$this->redirect('user/login/index');exit();
|
||||
}elseif (is_login()) {
|
||||
} elseif (is_login()) {
|
||||
$user = model('User')->getInfo(session('user_auth.uid'));
|
||||
if (!$this->checkProfile($user) && $this->url !== 'user/profile/index') {
|
||||
return $this->error('请补充完个人资料!', url('user/profile/index'));
|
||||
@@ -28,14 +28,14 @@ class User extends Base{
|
||||
}
|
||||
}
|
||||
|
||||
protected function setMenu(){
|
||||
protected function setMenu() {
|
||||
$menu['基础设置'] = array(
|
||||
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'),
|
||||
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'),
|
||||
array('title' => '我的订单', 'url' => 'user/order/index', 'icon' => 'shopping-bag'),
|
||||
);
|
||||
$contetnmenu = $this->getContentMenu();
|
||||
if (!empty($contetnmenu)) {
|
||||
@@ -46,7 +46,7 @@ class User extends Base{
|
||||
foreach ($item as $key => $value) {
|
||||
if (url($value['url']) == $_SERVER['REQUEST_URI']) {
|
||||
$value['active'] = 'active';
|
||||
}else{
|
||||
} else {
|
||||
$value['active'] = '';
|
||||
}
|
||||
$menu[$group][$key] = $value;
|
||||
@@ -55,25 +55,25 @@ class User extends Base{
|
||||
$this->assign('__MENU__', $menu);
|
||||
}
|
||||
|
||||
protected function getContentMenu(){
|
||||
protected function getContentMenu() {
|
||||
$list = array();
|
||||
$map = array(
|
||||
$map = array(
|
||||
'is_user_show' => 1,
|
||||
'status' => array('gt',0),
|
||||
'extend' => array('gt',0),
|
||||
'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;
|
||||
$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;
|
||||
}
|
||||
|
||||
protected function checkProfile($user){
|
||||
protected function checkProfile($user) {
|
||||
$result = true;
|
||||
//判断用户资料是否填写完整
|
||||
if (!$user['nickname'] || !$user['qq']) {
|
||||
|
||||
Reference in New Issue
Block a user