Files
swiftadmin/app/admin/controller/Tpl.php

75 lines
2.3 KiB
PHP
Raw Normal View History

2022-08-19 19:48:37 +08:00
<?php
2023-04-25 20:11:49 +08:00
2022-08-19 19:48:37 +08:00
// +----------------------------------------------------------------------
// | swiftAdmin 极速开发框架 [基于WebMan开发]
// +----------------------------------------------------------------------
// | Copyright (c) 2020-2030 http://www.swiftadmin.net
// +----------------------------------------------------------------------
// | swiftAdmin.net High Speed Development Framework
// +----------------------------------------------------------------------
// | Author: meystack <coolsec@foxmail.com> Apache 2.0 License
// +----------------------------------------------------------------------
namespace app\admin\controller;
use app\AdminController;
use support\Response;
class Tpl extends AdminController
{
public function __construct()
{
parent::__construct();
}
/**
* 读取模板列表
* @return Response
*/
public function showTpl(): Response
{
// 读取配置文件
$list = include (base_path().'/extend/conf/tpl/tpl.php');
foreach ($list as $key => $value) {
$list[$key]['param'] = str_replace('extend/conf/tpl/','',$value['path']);
}
return view('/tpl/show_tpl',['list'=>$list]);
}
/**
* 编辑邮件模板
* @return Response
*/
public function editTpl(): Response
{
$tplPath = base_path() . '/extend/conf/tpl/';
$files = glob($tplPath . '*.tpl');
$files = array_map(function ($file) {
return basename($file);
}, $files);
2022-08-19 19:48:37 +08:00
if (request()->isPost()) {
$post = request()->post();
$file = $post['tpl'];
if (!in_array($file, $files)) {
return $this->error('模板文件不存在!');
}
$tpl = $tplPath . $file;
2022-08-19 19:48:37 +08:00
if (write_file($tpl,$post['content'])) {
return $this->success('修改邮件模板成功!');
}
return $this->error('修改邮件模板失败!');
}
// 获取模板参数
$tpl = input('p');
if (!in_array($tpl, $files)) {
return $this->error('模板文件不存在!');
}
$content = read_file($tplPath . $tpl);
return view('/tpl/edit_tpl', ['tpl' => $tpl, 'content' => $content]);
2022-08-19 19:48:37 +08:00
}
}