123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- <?php
- namespace addons\wwh;
- use app\common\library\Menu;
- use think\Addons;
- use think\Db;
- /**
- * 插件
- */
- class Wwh extends Addons
- {
- /**
- * 插件安装方法
- * @return bool
- */
- public function install()
- {
- $menu = include ADDON_PATH . 'wwh' . DS . 'data' . DS . 'menu.php';
- Menu::create($menu);
- return true;
- }
- /**
- * 插件卸载方法
- * @return bool
- */
- public function uninstall()
- {
- Menu::delete("wwh");
- return true;
- }
- /**
- * 插件启用方法
- * @return bool
- */
- public function enable()
- {
- Menu::enable("wwh");
- return true;
- }
- /**
- * 插件禁用方法
- * @return bool
- */
- public function disable()
- {
- Menu::disable("wwh");
- return true;
- }
- /**
- * 插件升级方法
- */
- public function upgrade()
- {
- // 更新菜单
- $menu = include ADDON_PATH . 'wwh' . DS . 'data' . DS . 'menu.php';
- Menu::upgrade('wwh', $menu);
- // 替换配置项
- $this->updateConfig();
- return true;
- }
- /**
- * 更新插件配置
- */
- protected function updateConfig()
- {
- $full_config = get_addon_fullconfig('wwh');
- $config = get_addon_config('wwh');
- $updateConfig = include ADDON_PATH . 'wwh' . DS . 'updateConfig.php';
- foreach ($updateConfig as $v) {
- $found = false;
- // 查找是否已存在同名配置项
- foreach ($full_config as &$item) {
- if ($item['name'] == $v['name']) {
- // 如果是rewrite或__tips__配置则完全替换
- if (in_array($v['name'], ['rewrite', '__tips__'])) {
- $item['value'] = $v['value'];
- }
- $found = true;
- break;
- }
- }
- // 如果不存在则添加新配置
- if (!$found) {
- array_push($full_config, $v);
- }
- }
- set_addon_fullconfig('wwh', $full_config);
- }
- /**
- * 应用初始化
- */
- public function appInit()
- {
- include_once ADDON_PATH . 'wwh' . DS . 'common.php';
- }
- }
|