diff --git a/addons/syslogin/Syslogin.php b/addons/syslogin/Syslogin.php deleted file mode 100644 index 02ff8140..00000000 --- a/addons/syslogin/Syslogin.php +++ /dev/null @@ -1,40 +0,0 @@ - -// +---------------------------------------------------------------------- - - -namespace addons\Syslogin; - -/** - * 系统环境信息插件 - * @author thinkphp - */ - -class Syslogin extends Addons{ - - public $info = array( - 'name'=>'Syslogin', - 'title'=>'第三方登录', - 'description'=>'第三方登录', - 'status'=>0, - 'author'=>'molong', - 'version'=>'0.1' - ); - - public function loginBottomAddon(){ - - } - - public function install(){ - return true; - } - - public function uninstall(){ - return true; - } -} \ No newline at end of file diff --git a/app/controller/Base.php b/app/controller/Base.php index b2bdd3e2..3f25e450 100644 --- a/app/controller/Base.php +++ b/app/controller/Base.php @@ -15,6 +15,7 @@ use think\facade\Cache; use think\Validate; use app\model\Config; use think\facade\Route; +use app\model\Hooks; class Base { @@ -71,7 +72,11 @@ class Base { $config = Config::getConfigList($this->request); Cache::set('system_config_data', $config); } - config($config, 'config'); + $hooks = Hooks::where('status', 1)->column('addons', 'name'); + foreach($hooks as $key => $value){ + $hooks[$key] = $value ? explode(",", $value) : []; + } + Cache::set('sentcms_hooks', $hooks); View::assign('config', $config); // 控制器初始化 $this->initialize(); diff --git a/app/controller/Upload.php b/app/controller/Upload.php index 5e502a97..4af8ea0b 100644 --- a/app/controller/Upload.php +++ b/app/controller/Upload.php @@ -56,6 +56,20 @@ class Upload extends Base { echo $data->output(); } + public function delete(){ + $id = $this->request->param('id', 0); + if(!$id){ + $data = [ + 'status' => false + ]; + }else{ + $data = [ + 'status' => true + ]; + } + return json($data); + } + protected function save($file, $upload_type){ $data = []; $savename = Filesystem::disk('public')->putFile($upload_type, $file, 'md5'); diff --git a/app/controller/admin/Addons.php b/app/controller/admin/Addons.php index b1be8afe..a957427d 100644 --- a/app/controller/admin/Addons.php +++ b/app/controller/admin/Addons.php @@ -23,7 +23,7 @@ class Addons extends Base { public function index($refresh = 0) { $map = []; if ($refresh) { - AddonsM::refreshAddons(); + AddonsM::refreshAddons($this->app->getRootPath() . 'addons' . DIRECTORY_SEPARATOR); } $list = AddonsM::where($map)->order('id desc')->paginate($this->request->pageConfig); @@ -36,33 +36,9 @@ class Addons extends Base { } /** - * @title 添加插件 + * @title 删除插件 */ - public function add() { - if ($this->request->isPost()) { - $data = $this->addons->create(); - if ($data) { - if ($result) { - return $this->success("创建成功!", url('admin/addons/index')); - } else { - return $this->error("创建失败!"); - } - } else { - return $this->error($this->addons->getError()); - } - } else { - // $hooks = db('Hooks')->field('name,description')->select(); - // $this->assign('Hooks', $hooks); - // $hook = db('Hooks')->field(true)->select(); - // foreach ($hook as $key => $value) { - // $addons_opt[$value['name']] = $value['name']; - // } - // $addons_opt = array(array('type' => 'select', 'opt' => $addons_opt)); - // if (!is_writable(SENT_ADDON_PATH)) { - // return $this->error('您没有创建目录写入权限,无法使用此功能'); - // } - return $this->fetch(); - } + public function del() { } /** diff --git a/app/http/middleware/Validate.php b/app/http/middleware/Validate.php index 06ed0cc6..08bebdc1 100755 --- a/app/http/middleware/Validate.php +++ b/app/http/middleware/Validate.php @@ -21,11 +21,15 @@ class Validate { //获取当前参数 $params = $request->param(); //获取访问控制器 - $controller = explode(".", $request->controller()); + if(\strripos($request->controller(), ".")){ + $controller = explode(".", $request->controller()); + }else{ + $controller = ['', ucfirst($request->controller())]; + } //获取操作名,用于验证场景scene - $scene = $controller[0] . $request->action(); - $validate = "app\\http\\validate\\" . strtolower($controller[1]); + $scene = strtolower($controller[0]) . $request->action(); + $validate = "app\\http\\validate\\" . ucfirst($controller[1]); //仅当验证器存在时 进行校验 if (class_exists($validate) && $request->isPost()) { $v = new $validate; diff --git a/app/http/validate/Content.php b/app/http/validate/Content.php index 855ca1c2..3620c691 100644 --- a/app/http/validate/Content.php +++ b/app/http/validate/Content.php @@ -16,6 +16,11 @@ use app\model\Attribute; * 菜单验证 */ class Content extends Validate{ + protected $rule = []; + + protected $message = []; + + protected $scene = []; public function __construct(){ parent::__construct(); diff --git a/app/model/Addons.php b/app/model/Addons.php index 355280c6..415dab39 100644 --- a/app/model/Addons.php +++ b/app/model/Addons.php @@ -14,7 +14,129 @@ namespace app\model; */ class Addons extends \think\Model { - public static function refreshAddons(){ + protected $auto = ['status', 'isinstall', 'update_time']; + protected $insert = ['create_time']; + + protected $type = [ + 'hooks' => 'json' + ]; + + protected function setStatusAttr($value) { + return $value ? $value : 0; + } + + protected function setNameAttr($value){ + return $value ? strtolower($value) : ''; + } + + protected function setIsinstallAttr($value) { + return $value ? $value : 0; + } + + protected function getStatusTextAttr($value, $data) { + return $data['status'] ? "启用" : "禁用"; + } + + protected function getUninstallAttr($value, $data) { + return 0; + } + + /** + * 更新插件列表 + * @param string $addon_dir + */ + public static function refreshAddons($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)) { + return FALSE; + } + $where[] = ['name', 'in', $dirs]; + $addons = self::where($where)->column('*', 'name'); + + $save = []; + foreach ($dirs as $value) { + $value = strtolower($value); + $class = "\\addons\\" . $value . "\\Plugin"; + if (!class_exists($class)) { + continue; + } + $item = get_addons_info($value); + if (isset($addons[$value])) { + $item['id'] = $addons[$value]['id']; + unset($item['status']); + } + $save[] = $item; + } + $class = new self(); + return $class->saveAll($save); + } + + /** + * 获取插件的后台列表 + */ + public function getAdminList() { + $admin = []; + $map[] = ['status', '=', 1]; + $map[] = ['has_adminlist', '=', 1]; + $db_addons = self::where($map)->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) { + $info = $this->where('name', $data['name'])->value('id'); + if ($info) { + $result = $this->save(array('isinstall'=>1, 'status'=>1), array('id'=>$info)); + }else{ + $result = false; + } + if (false !== $result) { + return model('Hooks')->addHooks($data['name']); + }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() { } } \ No newline at end of file diff --git a/app/model/Hooks.php b/app/model/Hooks.php index 0b892fac..193c8c1c 100644 --- a/app/model/Hooks.php +++ b/app/model/Hooks.php @@ -17,7 +17,7 @@ class Hooks extends \think\Model { public static $keylist = [ ['name' => 'name', 'title' => '钩子名称', 'type' => 'text', 'help' => '需要在程序中先添加钩子,否则无效'], ['name' => 'description', 'title' => '钩子描述', 'type' => 'text', 'help' => '钩子的描述信息'], - ['name' => 'type_text', 'title' => '钩子类型', 'type' => 'select', 'option' => '', 'help' => '钩子的描述信息'], + ['name' => 'type_text', 'title' => '钩子类型', 'type' => 'select', 'option' => [['key'=>1, 'label'=>'视图'], ['key' => 2, 'label' => '控制器']], 'help' => '钩子的描述信息'], ['name' => 'addons', 'title' => '插件排序', 'type' => 'kanban'], ]; } \ No newline at end of file diff --git a/public/static/admin/js/app.js b/public/static/admin/js/app.js index 41be962b..220545a4 100644 --- a/public/static/admin/js/app.js +++ b/public/static/admin/js/app.js @@ -1,4 +1,5 @@ $(function($) { + $('div#content-wrapper').css({'minHeight':$(window).height()-80}); var storage, fail, uid; try { diff --git a/public/uploads/file/.gitignore b/public/uploads/file/.gitignore new file mode 100644 index 00000000..c96a04f0 --- /dev/null +++ b/public/uploads/file/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore \ No newline at end of file diff --git a/public/uploads/image/.gitignore b/public/uploads/image/.gitignore new file mode 100644 index 00000000..c96a04f0 --- /dev/null +++ b/public/uploads/image/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore \ No newline at end of file diff --git a/view/admin/addons/index.html b/view/admin/addons/index.html index 6b2361ac..37672e9f 100644 --- a/view/admin/addons/index.html +++ b/view/admin/addons/index.html @@ -10,8 +10,6 @@
更 新 - 新 增 -
@@ -64,30 +62,4 @@
{/block} {block name="script"} - - {/block} \ No newline at end of file diff --git a/view/admin/public/header.html b/view/admin/public/header.html index a89db4cb..335400ad 100644 --- a/view/admin/public/header.html +++ b/view/admin/public/header.html @@ -13,25 +13,19 @@ - - + + \ No newline at end of file