PluginsModel.class.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. /**
  3. * 洛阳赤炎鹰网络科技有限公司
  4. * https://www.cyyvip.com
  5. * Copyright (c) 2022 赤店商城 All rights reserved.
  6. */
  7. namespace Common\Model;
  8. use Common\Model\CommonModel;
  9. class PluginsModel extends CommonModel{
  10. //自动验证
  11. protected $_validate = array(
  12. //array(验证字段,验证规则,错误提示,验证条件,附加规则,验证时间)
  13. //array('ad_name', 'require', '广告名称不能为空!', 1, 'regex', 3),
  14. );
  15. /**
  16. * 获取插件列表
  17. */
  18. public function getList(){
  19. $dirs = array_map('basename',glob('./plugins/*', GLOB_ONLYDIR));
  20. if($dirs === false){
  21. $this->error = '插件目录不可读';
  22. return false;
  23. }
  24. $plugins = array();
  25. $where['name'] = array('in',$dirs);
  26. $list = $this->where($where)->field(true)->select();
  27. foreach($list as $plugin){
  28. $plugins[$plugin['name']] = $plugin;
  29. }
  30. foreach ($dirs as $value) {
  31. if(!isset($plugins[$value])){
  32. $class = sp_get_plugin_class($value);
  33. if(!class_exists($class)){ // 实例化插件失败忽略
  34. \Think\Log::record('插件'.$value.'的入口文件不存在!');
  35. continue;
  36. }
  37. $obj = new $class;
  38. $plugins[$value] = $obj->info;
  39. if(!isset($obj->info['type']) || $obj->info['type']==1){//只获取普通插件,微信插件在微信中使用
  40. if($plugins[$value]){
  41. $plugins[$value]['status']=3;//未安装
  42. }
  43. }else{
  44. unset($plugins[$value]);
  45. }
  46. }
  47. }
  48. return $plugins;
  49. }
  50. protected function _before_write(&$data) {
  51. parent::_before_write($data);
  52. }
  53. }