79 lines
2.1 KiB
PHP
79 lines
2.1 KiB
PHP
<?php
|
|
namespace addon\theme_configurator;
|
|
|
|
use addon\theme_configurator\model\ThemeConfigModel;
|
|
use app\common\lib\Plugin;
|
|
use think\facade\Db;
|
|
|
|
/**
|
|
* 主题可配置项插件主要类
|
|
*/
|
|
class ThemeConfigurator extends Plugin
|
|
{
|
|
/** @var array 插件基础信息 */
|
|
public $info = [
|
|
'name' => 'ThemeConfigurator',
|
|
'title' => '主题可视化配置',
|
|
'description' => '通过插件管理 BlackFruit-UI 导航、页脚、SEO、轮播与侧边栏等主题参数',
|
|
'author' => 'yiqiu',
|
|
'version' => '1.0.0',
|
|
];
|
|
|
|
/** @var bool 标记不需要默认插件导航 */
|
|
public $noNav = false;
|
|
|
|
/**
|
|
* 安装插件 - 初始化存储表以及默认配置
|
|
*/
|
|
public function install()
|
|
{
|
|
try {
|
|
$table = ThemeConfigModel::tableName();
|
|
Db::execute(
|
|
"CREATE TABLE IF NOT EXISTS `{$table}`(
|
|
`id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
|
|
`config` longtext NOT NULL,
|
|
`update_time` int(11) DEFAULT 0,
|
|
PRIMARY KEY (`id`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;"
|
|
);
|
|
} catch (\Throwable $throwable) {
|
|
$this->error = $throwable->getMessage();
|
|
return false;
|
|
}
|
|
|
|
try {
|
|
(new ThemeConfigModel())->initConfig();
|
|
} catch (\Throwable $throwable) {
|
|
$this->error = $throwable->getMessage();
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* 卸载插件 - 移除存储表
|
|
*/
|
|
public function uninstall()
|
|
{
|
|
try {
|
|
$table = ThemeConfigModel::tableName();
|
|
Db::execute("DROP TABLE IF EXISTS `{$table}`;");
|
|
} catch (\Throwable $throwable) {
|
|
$this->error = $throwable->getMessage();
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* 供其他业务调用,快速获取主题配置
|
|
*/
|
|
public function getThemeConfig()
|
|
{
|
|
return (new ThemeConfigModel())->getConfig();
|
|
}
|
|
}
|