Wwh.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. namespace addons\wwh;
  3. use app\common\library\Menu;
  4. use think\Addons;
  5. use think\Db;
  6. /**
  7. * 插件
  8. */
  9. class Wwh extends Addons
  10. {
  11. /**
  12. * 插件安装方法
  13. * @return bool
  14. */
  15. public function install()
  16. {
  17. $menu = include ADDON_PATH . 'wwh' . DS . 'data' . DS . 'menu.php';
  18. Menu::create($menu);
  19. return true;
  20. }
  21. /**
  22. * 插件卸载方法
  23. * @return bool
  24. */
  25. public function uninstall()
  26. {
  27. Menu::delete("wwh");
  28. return true;
  29. }
  30. /**
  31. * 插件启用方法
  32. * @return bool
  33. */
  34. public function enable()
  35. {
  36. Menu::enable("wwh");
  37. return true;
  38. }
  39. /**
  40. * 插件禁用方法
  41. * @return bool
  42. */
  43. public function disable()
  44. {
  45. Menu::disable("wwh");
  46. return true;
  47. }
  48. /**
  49. * 插件升级方法
  50. */
  51. public function upgrade()
  52. {
  53. // 更新菜单
  54. $menu = include ADDON_PATH . 'wwh' . DS . 'data' . DS . 'menu.php';
  55. Menu::upgrade('wwh', $menu);
  56. // 替换配置项
  57. $this->updateConfig();
  58. return true;
  59. }
  60. /**
  61. * 更新插件配置
  62. */
  63. protected function updateConfig()
  64. {
  65. $full_config = get_addon_fullconfig('wwh');
  66. $config = get_addon_config('wwh');
  67. $updateConfig = include ADDON_PATH . 'wwh' . DS . 'updateConfig.php';
  68. foreach ($updateConfig as $v) {
  69. $found = false;
  70. // 查找是否已存在同名配置项
  71. foreach ($full_config as &$item) {
  72. if ($item['name'] == $v['name']) {
  73. // 如果是rewrite或__tips__配置则完全替换
  74. if (in_array($v['name'], ['rewrite', '__tips__'])) {
  75. $item['value'] = $v['value'];
  76. }
  77. $found = true;
  78. break;
  79. }
  80. }
  81. // 如果不存在则添加新配置
  82. if (!$found) {
  83. array_push($full_config, $v);
  84. }
  85. }
  86. set_addon_fullconfig('wwh', $full_config);
  87. }
  88. /**
  89. * 应用初始化
  90. */
  91. public function appInit()
  92. {
  93. include_once ADDON_PATH . 'wwh' . DS . 'common.php';
  94. }
  95. }