| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880 |
- <?php
- namespace app\admin\controller;
- use http\Cookie;
- use think\Db;
- use think\Config;
- use think\Cache;
- use think\View;
- class System extends Base
- {
- public function test_email()
- {
- $post = input();
- $conf = [
- 'nick' => $post['nick'],
- ];
- $type = strtolower($post['type']);
- $to = $post['test'];
- $conf['host'] = $GLOBALS['config']['email'][$type]['host'];
- $conf['port'] = $GLOBALS['config']['email'][$type]['port'];
- $conf['username'] = $GLOBALS['config']['email'][$type]['username'];
- $conf['password'] = $GLOBALS['config']['email'][$type]['password'];
- $conf['secure'] = $GLOBALS['config']['email'][$type]['secure'];
- $this->label_maccms();
- $title = $GLOBALS['config']['email']['tpl']['test_title'];
- $msg = $GLOBALS['config']['email']['tpl']['test_body'];
- $code = mac_get_rndstr(6,'num');
- View::instance()->assign(['code'=>$code,'time'=>$GLOBALS['config']['email']['time']]);
- $title = View::instance()->display($title);
- $msg = View::instance()->display($msg);
- $msg = htmlspecialchars_decode($msg);
- $res = mac_send_mail($to, $title, $msg, $conf);
- if ($res['code']==1) {
- return json(['code' => 1, 'msg' => lang('test_ok')]);
- }
- return json(['code' => 1001, 'msg' => lang('test_err').':'.$res['msg']]);
- }
- public function test_cache()
- {
- $param = input();
- if (!isset($param['type']) || empty($param['host']) || empty($param['port'])) {
- return $this->error(lang('param_err'));
- }
- $options = [
- 'type' => $param['type'],
- 'host' => $param['host'],
- 'port' => $param['port'],
- 'username' => $param['username'],
- 'password' => $param['password']
- ];
- if ($param['type'] == 'redis' && isset($param['db']) && intval($param['db']) > 0) {
- $options['select'] = intval($param['db']);
- }
- $hd = Cache::connect($options);
- $hd->set('test', 'test');
- return json(['code' => 1, 'msg' => lang('test_ok')]);
- }
- public function config()
- {
- if (Request()->isPost()) {
- $config = input('','','htmlentities');
- $validate = \think\Loader::validate('Token');
- if(!$validate->check($config)){
- return $this->error($validate->getError());
- }
- unset($config['__token__']);
- $ads_dir='ads';
- $mob_ads_dir='ads';
- $path = ROOT_PATH .'template/'.$config['site']['template_dir'].'/info.ini';
- $cc = Config::load($path,'ini');
- if(!empty($cc['adsdir'])){
- $ads_dir = $cc['adsdir'];
- }
- $path = ROOT_PATH .'template/'.$config['site']['mob_template_dir'].'/info.ini';
- $cc = Config::load($path,'ini');
- if(!empty($cc['adsdir'])){
- $mob_ads_dir = $cc['adsdir'];
- }
- $config['site']['ads_dir'] = $ads_dir;
- $config['site']['mob_ads_dir'] = $mob_ads_dir;
- if(empty($config['app']['cache_flag'])){
- $config['app']['cache_flag'] = substr(md5(time()),0,10);
- }
- $config['app']['search_vod_rule'] = join('|', !empty($config['app']['search_vod_rule']) ? (array)$config['app']['search_vod_rule'] : []);
- $config['app']['search_art_rule'] = join('|', !empty($config['app']['search_art_rule']) ? (array)$config['app']['search_art_rule'] : []);
- $config['app']['vod_search_optimise'] = join('|', !empty($config['app']['vod_search_optimise']) ? (array)$config['app']['vod_search_optimise'] : []);
- $config['app']['vod_search_optimise_cache_minutes'] = (int)$config['app']['vod_search_optimise_cache_minutes'];
- $config['extra'] = [];
- if(!empty($config['app']['extra_var'])){
- $extra_var = str_replace(array(chr(10),chr(13)), array('','#'),$config['app']['extra_var']);
- $tmp = explode('#',$extra_var);
- foreach($tmp as $a){
- if(strpos($a,'$$$')!==false){
- $tmp2 = explode('$$$',$a);
- $config['extra'][$tmp2[0]] = $tmp2[1];
- }
- }
- unset($tmp,$tmp2);
- }
- $config['site']['site_tj'] = html_entity_decode($config['site']['site_tj']);
- $config_new['site'] = $config['site'];
- $config_new['app'] = $config['app'];
- $config_new['extra'] = $config['extra'];
- $config_old = config('maccms');
- $config_new = array_merge($config_old, $config_new);
- $tj = $config_new['site']['site_tj'];
- if(strpos($tj,'document.w') ===false){
- $tj = 'document.write(\'' . str_replace("'","\'",$tj) . '\')';
- }
- $res = @fwrite(fopen('./static/js/tj.js', 'wb'), $tj);
- $res = mac_arr2file(APP_PATH . 'extra/maccms.php', $config_new);
- if ($res === false) {
- return $this->error(lang('save_err'));
- }
- return $this->success(lang('save_ok'));
- }
- $templates = glob('./template' . '/*', GLOB_ONLYDIR);
- foreach ($templates as $k => &$v) {
- $v = str_replace('./template/', '', $v);
- }
- $this->assign('templates', $templates);
- $langs = glob('./application/lang/*.php');
- foreach ($langs as $k => &$v) {
- $v = str_replace(['./application/lang/','.php'],['',''],$v);
- }
- $this->assign('langs', $langs);
- $usergroup = Db::name('group')->select();
- $this->assign('usergroup', $usergroup);
- $editors = mac_extends_list('editor');
- $this->assign('editors',$editors);
- $config = config('maccms');
- // 默认get+post
- if (!isset($config['app']['input_type'])) {
- $config['app']['input_type'] = 1;
- }
- $config['app']['vod_search_optimise_cache_minutes'] = model('VodSearch')->getResultCacheMinutes($config);
- $this->assign('config', $config);
- $this->assign('title', lang('admin/system/config/title'));
- return $this->fetch('admin@system/config');
- }
- public function configurl()
- {
- if (Request()->isPost()) {
- $config = input();
- $validate = \think\Loader::validate('Token');
- if(!$validate->check($config)){
- return $this->error($validate->getError());
- }
- unset($config['__token__']);
- $config_new['view'] = $config['view'];
- $config_new['path'] = $config['path'];
- $config_new['rewrite'] = $config['rewrite'];
- //写路由规则文件
- $route = [];
- $route['__pattern__'] = [
- 'id'=>'[\s\S]*?',
- 'ids'=>'[\s\S]*?',
- 'wd' => '[\s\S]*',
- 'en'=>'[\s\S]*?',
- 'state' => '[\s\S]*?',
- 'area' => '[\s\S]*',
- 'year'=>'[\s\S]*?',
- 'lang' => '[\s\S]*?',
- 'letter'=>'[\s\S]*?',
- 'actor' => '[\s\S]*?',
- 'director' => '[\s\S]*?',
- 'tag' => '[\s\S]*?',
- 'class' => '[\s\S]*?',
- 'order'=>'[\s\S]*?',
- 'by'=>'[\s\S]*?',
- 'file'=>'[\s\S]*?',
- 'name'=>'[\s\S]*?',
- 'url'=>'[\s\S]*?',
- 'type'=>'[\s\S]*?',
- 'sex' => '[\s\S]*?',
- 'version' => '[\s\S]*?',
- 'blood' => '[\s\S]*?',
- 'starsign' => '[\s\S]*?',
- 'page'=>'\d+',
- 'ajax'=>'\d+',
- 'tid'=>'\d+',
- 'mid'=>'\d+',
- 'rid'=>'\d+',
- 'pid'=>'\d+',
- 'sid'=>'\d+',
- 'nid'=>'\d+',
- 'uid'=>'\d+',
- 'level'=>'\d+',
- 'score'=>'\d+',
- 'limit'=>'\d+',
- ];
- $rows = explode(chr(13), str_replace(chr(10), '', $config['rewrite']['route']));
- foreach ($rows as $r) {
- if (strpos($r, '=>') !== false) {
- $a = explode('=>', $r);
- $rule = [];
- // if (strpos($a, ':id') !== false) {
- //$rule['id'] = '\w+';
- // }
- $route[trim($a[0])] = [trim($a[1]), [], $rule];
- }
- }
- $res = mac_arr2file(APP_PATH . 'route.php', $route);
- if ($res === false) {
- return $this->error(lang('write_err_route'));
- }
- //写扩展配置
- $config_old = config('maccms');
- $config_new = array_merge($config_old, $config_new);
- $res = mac_arr2file(APP_PATH . 'extra/maccms.php', $config_new);
- if ($res === false) {
- return $this->error(lang('write_err_config'));
- }
- return $this->success(lang('save_ok'));
- }
- $this->assign('config', config('maccms'));
- $this->assign('title', lang('admin/system/configurl/title'));
- return $this->fetch('admin@system/configurl');
- }
- public function configuser()
- {
- if (Request()->isPost()) {
- $config = input('','','htmlentities');
- $validate = \think\Loader::validate('Token');
- if(!$validate->check($config)){
- return $this->error($validate->getError());
- }
- unset($config['__token__']);
- $config_new['user'] = $config['user'];
- $config_old = config('maccms');
- $config_new = array_merge($config_old, $config_new);
- $res = mac_arr2file(APP_PATH . 'extra/maccms.php', $config_new);
- if ($res === false) {
- return $this->error(lang('save_err'));
- }
- return $this->success(lang('save_ok'));
- }
- $this->assign('config', config('maccms'));
- $this->assign('title', lang('admin/system/configuser/title'));
- return $this->fetch('admin@system/configuser');
- }
- public function configupload()
- {
- $phar_status = file_exists(ROOT_PATH . 'extend/aws/src/Aws/aws.phar');
- if (Request()->isPost()){
- $config = input('','','htmlentities');
- if($config['upload']['mode'] == 'S3' && $phar_status == false){
- return $this->error(lang('save_err'));
- }
- $validate = \think\Loader::validate('Token');
- if(!$validate->check($config)){
- return $this->error($validate->getError());
- }
- unset($config['__token__']);
- $config_new['upload'] = $config['upload'];
- $config_old = config('maccms');
- $config_new = array_merge($config_old, $config_new);
- $res = mac_arr2file(APP_PATH . 'extra/maccms.php', $config_new);
- if ($res === false) {
- return $this->error(lang('save_err'));
- }
- return $this->success(lang('save_ok'));
- }
- $this->assign('config', config('maccms'));
- if ($phar_status) {
- $aws_phar = 'Yes';
- }else{
- $aws_phar = 'No';
- }
- $this->assign('aws_phar',$aws_phar);
- $extends = mac_extends_list('upload');
- $this->assign('extends',$extends);
- $this->assign('title', lang('admin/system/configupload/title'));
- return $this->fetch('admin@system/configupload');
- }
- public function configcomment()
- {
- if (Request()->isPost()) {
- $config = input('','','htmlentities');
- $validate = \think\Loader::validate('Token');
- if(!$validate->check($config)){
- return $this->error($validate->getError());
- }
- unset($config['__token__']);
- $config_new['gbook'] = $config['gbook'];
- $config_new['comment'] = $config['comment'];
- $config_old = config('maccms');
- $config_new = array_merge($config_old, $config_new);
- $res = mac_arr2file(APP_PATH . 'extra/maccms.php', $config_new);
- if ($res === false) {
- return $this->error(lang('save_err'));
- }
- return $this->success(lang('save_ok'));
- }
- $this->assign('config', config('maccms'));
- $this->assign('title', lang('admin/system/configcomment/title'));
- return $this->fetch('admin@system/configcomment');
- }
- public function configweixin()
- {
- if (Request()->isPost()) {
- $config = input('','','htmlentities');
- $validate = \think\Loader::validate('Token');
- if(!$validate->check($config)){
- return $this->error($validate->getError());
- }
- unset($config['__token__']);
- $config_new['weixin'] = $config['weixin'];
- $config_old = config('maccms');
- $config_new = array_merge($config_old, $config_new);
- $res = mac_arr2file(APP_PATH . 'extra/maccms.php', $config_new);
- if ($res === false) {
- return $this->error(lang('save_err'));
- }
- return $this->success(lang('save_ok'));
- }
- $this->assign('config', config('maccms'));
- $this->assign('title', lang('admin/system/configweixin/title'));
- return $this->fetch('admin@system/configweixin');
- }
- public function configpay()
- {
- if (Request()->isPost()) {
- $config = input('','','htmlentities');
- $validate = \think\Loader::validate('Token');
- if(!$validate->check($config)){
- return $this->error($validate->getError());
- }
- unset($config['__token__']);
- $config_new['pay'] = $config['pay'];
- $config_old = config('maccms');
- $config_new = array_merge($config_old, $config_new);
- $res = mac_arr2file(APP_PATH . 'extra/maccms.php', $config_new);
- if ($res === false) {
- return $this->error(lang('save_err'));
- }
- return $this->success(lang('save_ok'));
- }
- $this->assign('http_type',$GLOBALS['http_type']);
- $this->assign('config', config('maccms'));
- $extends = mac_extends_list('pay');
- $this->assign('extends',$extends);
- $this->assign('title', lang('admin/system/configpay/title'));
- return $this->fetch('admin@system/configpay');
- }
- public function configconnect()
- {
- if (Request()->isPost()) {
- $config = input('','','htmlentities');
- $validate = \think\Loader::validate('Token');
- if(!$validate->check($config)){
- return $this->error($validate->getError());
- }
- unset($config['__token__']);
- $config_new['connect'] = $config['connect'];
- $config_old = config('maccms');
- $config_new = array_merge($config_old, $config_new);
- $res = mac_arr2file(APP_PATH . 'extra/maccms.php', $config_new);
- if ($res === false) {
- return $this->error(lang('save_err'));
- }
- return $this->success(lang('save_ok'));
- }
- $this->assign('config', config('maccms'));
- $this->assign('title', lang('admin/system/configconnect/title'));
- return $this->fetch('admin@system/configconnect');
- }
- public function configemail()
- {
- if (Request()->isPost()) {
- $config = input('','','htmlentities');
- $validate = \think\Loader::validate('Token');
- if(!$validate->check($config)){
- return $this->error($validate->getError());
- }
- unset($config['__token__']);
- $config_new['email'] = $config['email'];
- $config_old = config('maccms');
- $config_new = array_merge($config_old, $config_new);
- $res = mac_arr2file(APP_PATH . 'extra/maccms.php', $config_new);
- if ($res === false) {
- return $this->error(lang('save_err'));
- }
- return $this->success(lang('save_ok'));
- }
- $this->assign('config', config('maccms'));
- $extends = mac_extends_list('email');
- $this->assign('extends',$extends);
- $this->assign('title', lang('admin/system/configemail/title'));
- return $this->fetch('admin@system/configemail');
- }
- public function configsms()
- {
- if (Request()->isPost()) {
- $config = input('','','htmlentities');
- $validate = \think\Loader::validate('Token');
- if(!$validate->check($config)){
- return $this->error($validate->getError());
- }
- unset($config['__token__']);
- $config_new['sms'] = $config['sms'];
- $config_old = config('maccms');
- $config_new = array_merge($config_old, $config_new);
- $res = mac_arr2file(APP_PATH . 'extra/maccms.php', $config_new);
- if ($res === false) {
- return $this->error(lang('save_err'));
- }
- return $this->success(lang('save_ok'));
- }
- $this->assign('config', config('maccms'));
- $extends = mac_extends_list('sms');
- $this->assign('extends',$extends);
- $this->assign('title', lang('admin/system/configsms/title'));
- return $this->fetch('admin@system/configsms');
- }
- public function configapi()
- {
- if (Request()->isPost()) {
- $config = input('','','htmlentities');
- $validate = \think\Loader::validate('Token');
- if(!$validate->check($config)){
- return $this->error($validate->getError());
- }
- unset($config['__token__']);
- $config_new['api'] = $config['api'];
- $config_new['api']['vod']['auth'] = mac_replace_text($config_new['api']['vod']['auth'], 2);
- $config_new['api']['art']['auth'] = mac_replace_text($config_new['api']['art']['auth'], 2);
- $config_new['api']['actor']['auth'] = mac_replace_text($config_new['api']['actor']['auth'], 2);
- $config_new['api']['manga']['auth'] = mac_replace_text($config_new['api']['manga']['auth'], 2);
- $config_new['api']['publicapi']['auth'] = mac_replace_text($config_new['api']['publicapi']['auth'], 2);
- $config_old = config('maccms');
- $config_new = array_merge($config_old, $config_new);
- $res = mac_arr2file(APP_PATH . 'extra/maccms.php', $config_new);
- if ($res === false) {
- return $this->error(lang('save_err'));
- }
- return $this->success(lang('save_ok'));
- }
- $config = config('maccms');
- if(!isset($config['api']['publicapi'])){
- $config['api']['publicapi'] = [
- 'status' => '0',
- 'charge' => '0',
- 'auth' => '',
- ];
- }
- if(!isset($config['api']['manga'])){
- $config['api']['manga'] = [
- 'status' => '0',
- 'charge' => '0',
- 'pagesize' => '20',
- 'imgurl' => '',
- 'typefilter' => '',
- 'datafilter' => 'manga_status=1',
- 'cachetime' => '',
- 'auth' => '',
- ];
- }
- $this->assign('config',$config );
- $this->assign('title', lang('admin/system/configapi/title'));
- return $this->fetch('admin@system/configapi');
- }
- public function configinterface()
- {
- if (Request()->isPost()) {
- $config = input('','','htmlentities');
- $validate = \think\Loader::validate('Token');
- if(!$validate->check($config)){
- return $this->error($validate->getError());
- }
- unset($config['__token__']);
- if($config['interface']['status']==1 && strlen($config['interface']['pass']) < 16){
- return $this->error(lang('admin/system/configinterface/pass_check'));
- }
- $config_new['interface'] = $config['interface'];
- $config_new['interface']['vodtype'] = mac_replace_text($config_new['interface']['vodtype'], 2);
- $config_new['interface']['arttype'] = mac_replace_text($config_new['interface']['arttype'], 2);
- $config_old = config('maccms');
- $config_new = array_merge($config_old, $config_new);
- $res = mac_arr2file(APP_PATH . 'extra/maccms.php', $config_new);
- if ($res === false) {
- return $this->error(lang('save_err'));
- }
- //保存缓存
- mac_interface_type();
- return $this->success(lang('save_ok'));
- }
- $this->assign('config', config('maccms'));
- $this->assign('title', lang('admin/system/configinterface/title'));
- return $this->fetch('admin@system/configinterface');
- }
- public function configcollect()
- {
- if (Request()->isPost()) {
- $config = input('','','htmlentities');
- $validate = \think\Loader::validate('Token');
- if(!$validate->check($config)){
- return $this->error($validate->getError());
- }
- unset($config['__token__']);
- $config_new['collect'] = $config['collect'];
- if (empty($config_new['collect']['vod']['inrule'])) {
- $config_new['collect']['vod']['inrule'] = ['a'];
- }
- if (empty($config_new['collect']['vod']['uprule'])) {
- $config_new['collect']['vod']['uprule'] = [];
- }
- if (empty($config_new['collect']['art']['inrule'])) {
- $config_new['collect']['art']['inrule'] = ['a'];
- }
- if (empty($config_new['collect']['art']['uprule'])) {
- $config_new['collect']['art']['uprule'] = [];
- }
- if (empty($config_new['collect']['actor']['inrule'])) {
- $config_new['collect']['actor']['inrule'] = ['a'];
- }
- if (empty($config_new['collect']['actor']['uprule'])) {
- $config_new['collect']['actor']['uprule'] = [];
- }
- if (empty($config_new['collect']['role']['inrule'])) {
- $config_new['collect']['role']['inrule'] = ['a'];
- }
- if (empty($config_new['collect']['role']['uprule'])) {
- $config_new['collect']['role']['uprule'] = [];
- }
- if (empty($config_new['collect']['website']['inrule'])) {
- $config_new['collect']['website']['inrule'] = ['a'];
- }
- if (empty($config_new['collect']['website']['uprule'])) {
- $config_new['collect']['website']['uprule'] = [];
- }
- if (empty($config_new['collect']['comment']['inrule'])) {
- $config_new['collect']['comment']['inrule'] = ['a'];
- }
- if (empty($config_new['collect']['comment']['uprule'])) {
- $config_new['collect']['comment']['uprule'] = [];
- }
- if (empty($config_new['collect']['manga']['inrule'])) {
- $config_new['collect']['manga']['inrule'] = ['a'];
- }
- if (empty($config_new['collect']['manga']['uprule'])) {
- $config_new['collect']['manga']['uprule'] = [];
- }
- $config_new['collect']['vod']['inrule'] = ',' . join(',', $config_new['collect']['vod']['inrule']);
- $config_new['collect']['vod']['uprule'] = ',' . join(',', $config_new['collect']['vod']['uprule']);
- $config_new['collect']['art']['inrule'] = ',' . join(',', $config_new['collect']['art']['inrule']);
- $config_new['collect']['art']['uprule'] = ',' . join(',', $config_new['collect']['art']['uprule']);
- $config_new['collect']['actor']['inrule'] = ',' . join(',', $config_new['collect']['actor']['inrule']);
- $config_new['collect']['actor']['uprule'] = ',' . join(',', $config_new['collect']['actor']['uprule']);
- $config_new['collect']['role']['inrule'] = ',' . join(',', $config_new['collect']['role']['inrule']);
- $config_new['collect']['role']['uprule'] = ',' . join(',', $config_new['collect']['role']['uprule']);
- $config_new['collect']['website']['inrule'] = ',' . join(',', $config_new['collect']['website']['inrule']);
- $config_new['collect']['website']['uprule'] = ',' . join(',', $config_new['collect']['website']['uprule']);
- $config_new['collect']['comment']['inrule'] = ',' . join(',', $config_new['collect']['comment']['inrule']);
- $config_new['collect']['comment']['uprule'] = ',' . join(',', $config_new['collect']['comment']['uprule']);
- $config_new['collect']['manga']['inrule'] = ',' . join(',', $config_new['collect']['manga']['inrule']);
- $config_new['collect']['manga']['uprule'] = ',' . join(',', $config_new['collect']['manga']['uprule']);
- $config_new['collect']['vod']['namewords'] = mac_replace_text($config_new['collect']['vod']['namewords'], 2);
- $config_new['collect']['vod']['thesaurus'] = mac_replace_text($config_new['collect']['vod']['thesaurus'], 2);
- $config_new['collect']['vod']['playerwords'] = mac_replace_text($config_new['collect']['vod']['playerwords'], 2);
- $config_new['collect']['vod']['areawords'] = mac_replace_text($config_new['collect']['vod']['areawords'], 2);
- $config_new['collect']['vod']['langwords'] = mac_replace_text($config_new['collect']['vod']['langwords'], 2);
- $config_new['collect']['vod']['words'] = mac_replace_text($config_new['collect']['vod']['words'], 2);
- $config_new['collect']['art']['thesaurus'] = mac_replace_text($config_new['collect']['art']['thesaurus'], 2);
- $config_new['collect']['art']['words'] = mac_replace_text($config_new['collect']['art']['words'], 2);
- $config_new['collect']['actor']['thesaurus'] = mac_replace_text($config_new['collect']['actor']['thesaurus'], 2);
- $config_new['collect']['actor']['words'] = mac_replace_text($config_new['collect']['actor']['words'], 2);
- $config_new['collect']['role']['thesaurus'] = mac_replace_text($config_new['collect']['role']['thesaurus'], 2);
- $config_new['collect']['role']['words'] = mac_replace_text($config_new['collect']['role']['words'], 2);
- $config_new['collect']['website']['thesaurus'] = mac_replace_text($config_new['collect']['website']['thesaurus'], 2);
- $config_new['collect']['website']['words'] = mac_replace_text($config_new['collect']['website']['words'], 2);
- $config_new['collect']['comment']['thesaurus'] = mac_replace_text($config_new['collect']['comment']['thesaurus'], 2);
- $config_new['collect']['comment']['words'] = mac_replace_text($config_new['collect']['comment']['words'], 2);
- $config_old = config('maccms');
- $config_new = array_merge($config_old, $config_new);
- $res = mac_arr2file(APP_PATH . 'extra/maccms.php', $config_new);
- if ($res === false) {
- return $this->error(lang('save_err'));
- }
- return $this->success(lang('save_ok'));
- }
- $this->assign('config', config('maccms'));
- $this->assign('title', lang('admin/system/configcollect/title'));
- return $this->fetch('admin@system/configcollect');
- }
- public function configplay()
- {
- if (Request()->isPost()) {
- $config = input('','','htmlentities');
- $validate = \think\Loader::validate('Token');
- if(!$validate->check($config)){
- return $this->error($validate->getError());
- }
- unset($config['__token__']);
- $config_new['play'] = $config['play'];
- $config_old = config('maccms');
- $config_new = array_merge($config_old, $config_new);
- $res = mac_arr2file(APP_PATH . 'extra/maccms.php', $config_new);
- if ($res === false) {
- return $this->error(lang('save_err'));
- }
- $path = './static/js/playerconfig.js';
- if (!file_exists($path)) {
- $path .= '.bak';
- }
- $fc = @file_get_contents($path);
- $jsb = mac_get_body($fc, '//参数开始', '//参数结束');
- $content = 'MacPlayerConfig=' . json_encode($config['play']) . ';';
- $fc = str_replace($jsb, "\r\n" . $content . "\r\n", $fc);
- $res = @fwrite(fopen('./static/js/playerconfig.js', 'wb'), $fc);
- if ($res === false) {
- return $this->error(lang('save_err'));
- }
- return $this->success(lang('save_ok'));
- }
- $fp = './static/js/playerconfig.js';
- if (!file_exists($fp)) {
- $fp .= '.bak';
- }
- $fc = file_get_contents($fp);
- $jsb = trim(mac_get_body($fc, '//参数开始', '//参数结束'));
- $jsb = substr($jsb, 16, strlen($jsb) - 17);
- $play = json_decode($jsb, true);
- $this->assign('play', $play);
- $this->assign('title', lang('admin/system/configplay/title'));
- return $this->fetch('admin@system/configplay');
- }
- public function configseo()
- {
- if (Request()->isPost()) {
- $config = input('','','htmlentities');
- $validate = \think\Loader::validate('Token');
- if(!$validate->check($config)){
- return $this->error($validate->getError());
- }
- unset($config['__token__']);
- $config_new['seo'] = $config['seo'];
- $config_old = config('maccms');
- $config_new = array_merge($config_old, $config_new);
- $res = mac_arr2file(APP_PATH . 'extra/maccms.php', $config_new);
- if ($res === false) {
- return $this->error(lang('save_err'));
- }
- return $this->success(lang('save_ok'));
- }
- $this->assign('config', config('maccms'));
- $this->assign('title', lang('admin/system/configseo/title'));
- return $this->fetch('admin@system/configseo');
- }
- public function configaiseo()
- {
- if (Request()->isPost()) {
- $post = input('post.', '', 'htmlentities');
- $validate = \think\Loader::validate('Token');
- if (!$validate->check($post)) {
- return $this->error($validate->getError());
- }
- unset($post['__token__']);
- $config_old = config('maccms');
- $ai = isset($post['ai_seo']) && is_array($post['ai_seo']) ? $post['ai_seo'] : [];
- $sanitize = function ($v) {
- return trim(strip_tags((string)$v));
- };
- $row = [
- 'enabled' => isset($ai['enabled']) && (string)$ai['enabled'] === '1' ? '1' : '0',
- 'auto_generate' => isset($ai['auto_generate']) && (string)$ai['auto_generate'] === '1' ? '1' : '0',
- 'template_inject' => isset($ai['template_inject']) && (string)$ai['template_inject'] === '1' ? '1' : '0',
- 'provider' => $sanitize(isset($ai['provider']) ? $ai['provider'] : 'openai'),
- 'model' => $sanitize(isset($ai['model']) ? $ai['model'] : 'gpt-4o-mini'),
- 'api_base' => $sanitize(isset($ai['api_base']) ? $ai['api_base'] : 'https://api.openai.com/v1'),
- 'timeout' => (string)max(5, intval(isset($ai['timeout']) ? $ai['timeout'] : 20)),
- ];
- if ($row['api_base'] === '') {
- $row['api_base'] = 'https://api.openai.com/v1';
- }
- $newKey = isset($ai['api_key']) ? trim((string)$ai['api_key']) : '';
- if ($newKey !== '') {
- $row['api_key'] = $newKey;
- } else {
- // Read from latest config file to avoid accidental key loss when config cache is stale.
- $cfgFile = APP_PATH . 'extra/maccms.php';
- $latest = is_file($cfgFile) ? include $cfgFile : [];
- if (isset($latest['ai_seo']['api_key']) && $latest['ai_seo']['api_key'] !== '') {
- $row['api_key'] = (string)$latest['ai_seo']['api_key'];
- } else {
- $row['api_key'] = isset($config_old['ai_seo']['api_key']) ? $config_old['ai_seo']['api_key'] : '';
- }
- }
- $config_new = $config_old;
- $config_new['ai_seo'] = $row;
- $res = mac_arr2file(APP_PATH . 'extra/maccms.php', $config_new);
- if ($res === false) {
- return $this->error(lang('save_err'));
- }
- return $this->success(lang('save_ok'));
- }
- $config = config('maccms');
- if (!isset($config['ai_seo']) || !is_array($config['ai_seo'])) {
- $config['ai_seo'] = [
- 'enabled' => '0',
- 'auto_generate' => '1',
- 'template_inject' => '1',
- 'provider' => 'openai',
- 'model' => 'gpt-4o-mini',
- 'api_base' => 'https://api.openai.com/v1',
- 'api_key' => '',
- 'timeout' => '20',
- ];
- }
- $apiKey = isset($config['ai_seo']['api_key']) ? trim((string)$config['ai_seo']['api_key']) : '';
- $this->assign('ai_seo_key_saved', $apiKey !== '' ? 1 : 0);
- $this->assign('ai_seo_key_tail', $apiKey !== '' ? substr($apiKey, -6) : '');
- $this->assign('config', $config);
- $this->assign('title', lang('admin/system/configaiseo/title'));
- return $this->fetch('admin@system/configaiseo');
- }
- public function configlang(){
- $param = input();
- $config = config('maccms');
- if (!isset($config['app'])) {
- $config['app'] = [];
- }
- $config['app']['lang'] = $param['lang'];
- $res = mac_arr2file(APP_PATH . 'extra/maccms.php', $config);
- if ($res === false) {
- return $this->error(lang('save_err'));
- }
- return json(['code' => 1, 'msg' => 'ok']);
- }
- public function configVersion(){
- $param = input();
- $config = config('maccms');
- if (!isset($config['site'])) {
- $config['site'] = [];
- }
- $config['site']['new_version'] = $param['version'];
- if (!is_writable(APP_PATH . 'extra/maccms.php')) {
- return $this->error(APP_PATH . 'extra/maccms.php' . lang('install/write_read_err'));
- }
- $res = mac_arr2file(APP_PATH . 'extra/maccms.php', $config);
- if ($res === false) {
- return $this->error(lang('save_err'));
- }
- return json(['code' => 1, 'msg' => 'ok']);
- }
- }
|