1
0

System.php 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917
  1. <?php
  2. namespace app\admin\controller;
  3. use http\Cookie;
  4. use think\Db;
  5. use think\Config;
  6. use think\Cache;
  7. use think\View;
  8. class System extends Base
  9. {
  10. public function test_email()
  11. {
  12. $post = input();
  13. $conf = [
  14. 'nick' => $post['nick'],
  15. ];
  16. $type = strtolower($post['type']);
  17. $to = $post['test'];
  18. $conf['host'] = $GLOBALS['config']['email'][$type]['host'];
  19. $conf['port'] = $GLOBALS['config']['email'][$type]['port'];
  20. $conf['username'] = $GLOBALS['config']['email'][$type]['username'];
  21. $conf['password'] = $GLOBALS['config']['email'][$type]['password'];
  22. $conf['secure'] = $GLOBALS['config']['email'][$type]['secure'];
  23. $this->label_maccms();
  24. $title = $GLOBALS['config']['email']['tpl']['test_title'];
  25. $msg = $GLOBALS['config']['email']['tpl']['test_body'];
  26. $code = mac_get_rndstr(6,'num');
  27. View::instance()->assign(['code'=>$code,'time'=>$GLOBALS['config']['email']['time']]);
  28. $title = View::instance()->display($title);
  29. $msg = View::instance()->display($msg);
  30. $msg = htmlspecialchars_decode($msg);
  31. $res = mac_send_mail($to, $title, $msg, $conf);
  32. if ($res['code']==1) {
  33. return json(['code' => 1, 'msg' => lang('test_ok')]);
  34. }
  35. return json(['code' => 1001, 'msg' => lang('test_err').':'.$res['msg']]);
  36. }
  37. public function test_cache()
  38. {
  39. $param = input();
  40. if (!isset($param['type']) || empty($param['host']) || empty($param['port'])) {
  41. return $this->error(lang('param_err'));
  42. }
  43. $options = [
  44. 'type' => $param['type'],
  45. 'host' => $param['host'],
  46. 'port' => $param['port'],
  47. 'username' => $param['username'],
  48. 'password' => $param['password']
  49. ];
  50. if ($param['type'] == 'redis' && isset($param['db']) && intval($param['db']) > 0) {
  51. $options['select'] = intval($param['db']);
  52. }
  53. $hd = Cache::connect($options);
  54. $hd->set('test', 'test');
  55. return json(['code' => 1, 'msg' => lang('test_ok')]);
  56. }
  57. public function config()
  58. {
  59. if (Request()->isPost()) {
  60. $config = input('','','htmlentities');
  61. $validate = \think\Loader::validate('Token');
  62. if(!$validate->check($config)){
  63. return $this->error($validate->getError());
  64. }
  65. unset($config['__token__']);
  66. $ads_dir='ads';
  67. $mob_ads_dir='ads';
  68. $path = ROOT_PATH .'template/'.$config['site']['template_dir'].'/info.ini';
  69. $cc = Config::load($path,'ini');
  70. if(!empty($cc['adsdir'])){
  71. $ads_dir = $cc['adsdir'];
  72. }
  73. $path = ROOT_PATH .'template/'.$config['site']['mob_template_dir'].'/info.ini';
  74. $cc = Config::load($path,'ini');
  75. if(!empty($cc['adsdir'])){
  76. $mob_ads_dir = $cc['adsdir'];
  77. }
  78. $config['site']['ads_dir'] = $ads_dir;
  79. $config['site']['mob_ads_dir'] = $mob_ads_dir;
  80. if(empty($config['app']['cache_flag'])){
  81. $config['app']['cache_flag'] = substr(md5(time()),0,10);
  82. }
  83. $config['app']['search_vod_rule'] = join('|', !empty($config['app']['search_vod_rule']) ? (array)$config['app']['search_vod_rule'] : []);
  84. $config['app']['search_art_rule'] = join('|', !empty($config['app']['search_art_rule']) ? (array)$config['app']['search_art_rule'] : []);
  85. $config['app']['vod_search_optimise'] = join('|', !empty($config['app']['vod_search_optimise']) ? (array)$config['app']['vod_search_optimise'] : []);
  86. $config['app']['vod_search_optimise_cache_minutes'] = (int)$config['app']['vod_search_optimise_cache_minutes'];
  87. $config['extra'] = [];
  88. if(!empty($config['app']['extra_var'])){
  89. $extra_var = str_replace(array(chr(10),chr(13)), array('','#'),$config['app']['extra_var']);
  90. $tmp = explode('#',$extra_var);
  91. foreach($tmp as $a){
  92. if(strpos($a,'$$$')!==false){
  93. $tmp2 = explode('$$$',$a);
  94. $config['extra'][$tmp2[0]] = $tmp2[1];
  95. }
  96. }
  97. unset($tmp,$tmp2);
  98. }
  99. $config['site']['site_tj'] = html_entity_decode($config['site']['site_tj']);
  100. $config_new['site'] = $config['site'];
  101. $config_new['app'] = $config['app'];
  102. $config_new['extra'] = $config['extra'];
  103. $config_old = config('maccms');
  104. $config_new = array_merge($config_old, $config_new);
  105. $tj = $config_new['site']['site_tj'];
  106. if(strpos($tj,'document.w') ===false){
  107. $tj = 'document.write(\'' . str_replace("'","\'",$tj) . '\')';
  108. }
  109. $res = @fwrite(fopen('./static/js/tj.js', 'wb'), $tj);
  110. $res = mac_arr2file(APP_PATH . 'extra/maccms.php', $config_new);
  111. if ($res === false) {
  112. return $this->error(lang('save_err'));
  113. }
  114. return $this->success(lang('save_ok'));
  115. }
  116. $templates = glob('./template' . '/*', GLOB_ONLYDIR);
  117. foreach ($templates as $k => &$v) {
  118. $v = str_replace('./template/', '', $v);
  119. }
  120. $this->assign('templates', $templates);
  121. $langs = glob('./application/lang/*.php');
  122. foreach ($langs as $k => &$v) {
  123. $v = str_replace(['./application/lang/','.php'],['',''],$v);
  124. }
  125. $this->assign('langs', $langs);
  126. $usergroup = Db::name('group')->select();
  127. $this->assign('usergroup', $usergroup);
  128. $editors = mac_extends_list('editor');
  129. $this->assign('editors',$editors);
  130. $config = config('maccms');
  131. // 默认get+post
  132. if (!isset($config['app']['input_type'])) {
  133. $config['app']['input_type'] = 1;
  134. }
  135. $config['app']['vod_search_optimise_cache_minutes'] = model('VodSearch')->getResultCacheMinutes($config);
  136. $this->assign('config', $config);
  137. $this->assign('title', lang('admin/system/config/title'));
  138. return $this->fetch('admin@system/config');
  139. }
  140. public function configurl()
  141. {
  142. if (Request()->isPost()) {
  143. $config = input();
  144. $validate = \think\Loader::validate('Token');
  145. if(!$validate->check($config)){
  146. return $this->error($validate->getError());
  147. }
  148. unset($config['__token__']);
  149. $config_new['view'] = $config['view'];
  150. $config_new['path'] = $config['path'];
  151. $config_new['rewrite'] = $config['rewrite'];
  152. //写路由规则文件
  153. $route = [];
  154. $route['__pattern__'] = [
  155. 'id'=>'[\s\S]*?',
  156. 'ids'=>'[\s\S]*?',
  157. 'wd' => '[\s\S]*',
  158. 'en'=>'[\s\S]*?',
  159. 'state' => '[\s\S]*?',
  160. 'area' => '[\s\S]*',
  161. 'year'=>'[\s\S]*?',
  162. 'lang' => '[\s\S]*?',
  163. 'letter'=>'[\s\S]*?',
  164. 'actor' => '[\s\S]*?',
  165. 'director' => '[\s\S]*?',
  166. 'tag' => '[\s\S]*?',
  167. 'class' => '[\s\S]*?',
  168. 'order'=>'[\s\S]*?',
  169. 'by'=>'[\s\S]*?',
  170. 'file'=>'[\s\S]*?',
  171. 'name'=>'[\s\S]*?',
  172. 'url'=>'[\s\S]*?',
  173. 'type'=>'[\s\S]*?',
  174. 'sex' => '[\s\S]*?',
  175. 'version' => '[\s\S]*?',
  176. 'blood' => '[\s\S]*?',
  177. 'starsign' => '[\s\S]*?',
  178. 'page'=>'\d+',
  179. 'ajax'=>'\d+',
  180. 'tid'=>'\d+',
  181. 'mid'=>'\d+',
  182. 'rid'=>'\d+',
  183. 'pid'=>'\d+',
  184. 'sid'=>'\d+',
  185. 'nid'=>'\d+',
  186. 'uid'=>'\d+',
  187. 'level'=>'\d+',
  188. 'score'=>'\d+',
  189. 'limit'=>'\d+',
  190. ];
  191. $rows = explode(chr(13), str_replace(chr(10), '', $config['rewrite']['route']));
  192. foreach ($rows as $r) {
  193. if (strpos($r, '=>') !== false) {
  194. $a = explode('=>', $r);
  195. $rule = [];
  196. // if (strpos($a, ':id') !== false) {
  197. //$rule['id'] = '\w+';
  198. // }
  199. $route[trim($a[0])] = [trim($a[1]), [], $rule];
  200. }
  201. }
  202. $res = mac_arr2file(APP_PATH . 'route.php', $route);
  203. if ($res === false) {
  204. return $this->error(lang('write_err_route'));
  205. }
  206. //写扩展配置
  207. $config_old = config('maccms');
  208. $config_new = array_merge($config_old, $config_new);
  209. $res = mac_arr2file(APP_PATH . 'extra/maccms.php', $config_new);
  210. if ($res === false) {
  211. return $this->error(lang('write_err_config'));
  212. }
  213. return $this->success(lang('save_ok'));
  214. }
  215. $this->assign('config', config('maccms'));
  216. $this->assign('title', lang('admin/system/configurl/title'));
  217. return $this->fetch('admin@system/configurl');
  218. }
  219. public function configuser()
  220. {
  221. if (Request()->isPost()) {
  222. $config = input('','','htmlentities');
  223. $validate = \think\Loader::validate('Token');
  224. if(!$validate->check($config)){
  225. return $this->error($validate->getError());
  226. }
  227. unset($config['__token__']);
  228. $config_new['user'] = $config['user'];
  229. if(isset($config['user']['invite_reward']) && is_array($config['user']['invite_reward'])) {
  230. $invite_reward = [];
  231. foreach($config['user']['invite_reward'] as $k => $v) {
  232. if(!empty($v['count'])) {
  233. $invite_reward[$v['count']] = [
  234. 'group_id' => intval($v['group_id']),
  235. 'long' => $v['long'],
  236. 'points' => intval($v['points'])
  237. ];
  238. }
  239. }
  240. $config_new['user']['invite_reward'] = $invite_reward;
  241. }
  242. $config_old = config('maccms');
  243. $config_new = array_merge($config_old, $config_new);
  244. $res = mac_arr2file(APP_PATH . 'extra/maccms.php', $config_new);
  245. if ($res === false) {
  246. return $this->error(lang('save_err'));
  247. }
  248. return $this->success(lang('save_ok'));
  249. }
  250. $config = config('maccms');
  251. $invite_reward_form = [];
  252. if(isset($config['user']['invite_reward']) && is_array($config['user']['invite_reward'])) {
  253. foreach($config['user']['invite_reward'] as $count => $reward) {
  254. $invite_reward_form[] = [
  255. 'count' => $count,
  256. 'group_id' => $reward['group_id'],
  257. 'long' => $reward['long'],
  258. 'points' => $reward['points']
  259. ];
  260. }
  261. }
  262. while(count($invite_reward_form) < 3) {
  263. $invite_reward_form[] = ['count' => '', 'group_id' => '3', 'long' => 'month', 'points' => 0];
  264. }
  265. $this->assign('invite_reward_form', $invite_reward_form);
  266. $group_list = \think\Db::name('group')->select();
  267. $this->assign('group_list', $group_list);
  268. $this->assign('config', $config);
  269. $this->assign('title', lang('admin/system/configuser/title'));
  270. return $this->fetch('admin@system/configuser');
  271. }
  272. public function configupload()
  273. {
  274. $phar_status = file_exists(ROOT_PATH . 'extend/aws/src/Aws/aws.phar');
  275. if (Request()->isPost()){
  276. $config = input('','','htmlentities');
  277. if($config['upload']['mode'] == 'S3' && $phar_status == false){
  278. return $this->error(lang('save_err'));
  279. }
  280. $validate = \think\Loader::validate('Token');
  281. if(!$validate->check($config)){
  282. return $this->error($validate->getError());
  283. }
  284. unset($config['__token__']);
  285. $config_new['upload'] = $config['upload'];
  286. $config_old = config('maccms');
  287. $config_new = array_merge($config_old, $config_new);
  288. $res = mac_arr2file(APP_PATH . 'extra/maccms.php', $config_new);
  289. if ($res === false) {
  290. return $this->error(lang('save_err'));
  291. }
  292. return $this->success(lang('save_ok'));
  293. }
  294. $this->assign('config', config('maccms'));
  295. if ($phar_status) {
  296. $aws_phar = 'Yes';
  297. }else{
  298. $aws_phar = 'No';
  299. }
  300. $this->assign('aws_phar',$aws_phar);
  301. $extends = mac_extends_list('upload');
  302. $this->assign('extends',$extends);
  303. $this->assign('title', lang('admin/system/configupload/title'));
  304. return $this->fetch('admin@system/configupload');
  305. }
  306. public function configcomment()
  307. {
  308. if (Request()->isPost()) {
  309. $config = input('','','htmlentities');
  310. $validate = \think\Loader::validate('Token');
  311. if(!$validate->check($config)){
  312. return $this->error($validate->getError());
  313. }
  314. unset($config['__token__']);
  315. $config_new['gbook'] = $config['gbook'];
  316. $config_new['comment'] = $config['comment'];
  317. $config_old = config('maccms');
  318. $config_new = array_merge($config_old, $config_new);
  319. $res = mac_arr2file(APP_PATH . 'extra/maccms.php', $config_new);
  320. if ($res === false) {
  321. return $this->error(lang('save_err'));
  322. }
  323. return $this->success(lang('save_ok'));
  324. }
  325. $this->assign('config', config('maccms'));
  326. $this->assign('title', lang('admin/system/configcomment/title'));
  327. return $this->fetch('admin@system/configcomment');
  328. }
  329. public function configweixin()
  330. {
  331. if (Request()->isPost()) {
  332. $config = input('','','htmlentities');
  333. $validate = \think\Loader::validate('Token');
  334. if(!$validate->check($config)){
  335. return $this->error($validate->getError());
  336. }
  337. unset($config['__token__']);
  338. $config_new['weixin'] = $config['weixin'];
  339. $config_old = config('maccms');
  340. $config_new = array_merge($config_old, $config_new);
  341. $res = mac_arr2file(APP_PATH . 'extra/maccms.php', $config_new);
  342. if ($res === false) {
  343. return $this->error(lang('save_err'));
  344. }
  345. return $this->success(lang('save_ok'));
  346. }
  347. $this->assign('config', config('maccms'));
  348. $this->assign('title', lang('admin/system/configweixin/title'));
  349. return $this->fetch('admin@system/configweixin');
  350. }
  351. public function configpay()
  352. {
  353. if (Request()->isPost()) {
  354. $config = input('','','htmlentities');
  355. $validate = \think\Loader::validate('Token');
  356. if(!$validate->check($config)){
  357. return $this->error($validate->getError());
  358. }
  359. unset($config['__token__']);
  360. $config_new['pay'] = $config['pay'];
  361. $config_old = config('maccms');
  362. $config_new = array_merge($config_old, $config_new);
  363. $res = mac_arr2file(APP_PATH . 'extra/maccms.php', $config_new);
  364. if ($res === false) {
  365. return $this->error(lang('save_err'));
  366. }
  367. return $this->success(lang('save_ok'));
  368. }
  369. $this->assign('http_type',$GLOBALS['http_type']);
  370. $this->assign('config', config('maccms'));
  371. $extends = mac_extends_list('pay');
  372. $this->assign('extends',$extends);
  373. $this->assign('title', lang('admin/system/configpay/title'));
  374. return $this->fetch('admin@system/configpay');
  375. }
  376. public function configconnect()
  377. {
  378. if (Request()->isPost()) {
  379. $config = input('','','htmlentities');
  380. $validate = \think\Loader::validate('Token');
  381. if(!$validate->check($config)){
  382. return $this->error($validate->getError());
  383. }
  384. unset($config['__token__']);
  385. $config_new['connect'] = $config['connect'];
  386. $config_old = config('maccms');
  387. $config_new = array_merge($config_old, $config_new);
  388. $res = mac_arr2file(APP_PATH . 'extra/maccms.php', $config_new);
  389. if ($res === false) {
  390. return $this->error(lang('save_err'));
  391. }
  392. return $this->success(lang('save_ok'));
  393. }
  394. $this->assign('config', config('maccms'));
  395. $this->assign('title', lang('admin/system/configconnect/title'));
  396. return $this->fetch('admin@system/configconnect');
  397. }
  398. public function configemail()
  399. {
  400. if (Request()->isPost()) {
  401. $config = input('','','htmlentities');
  402. $validate = \think\Loader::validate('Token');
  403. if(!$validate->check($config)){
  404. return $this->error($validate->getError());
  405. }
  406. unset($config['__token__']);
  407. $config_new['email'] = $config['email'];
  408. $config_old = config('maccms');
  409. $config_new = array_merge($config_old, $config_new);
  410. $res = mac_arr2file(APP_PATH . 'extra/maccms.php', $config_new);
  411. if ($res === false) {
  412. return $this->error(lang('save_err'));
  413. }
  414. return $this->success(lang('save_ok'));
  415. }
  416. $this->assign('config', config('maccms'));
  417. $extends = mac_extends_list('email');
  418. $this->assign('extends',$extends);
  419. $this->assign('title', lang('admin/system/configemail/title'));
  420. return $this->fetch('admin@system/configemail');
  421. }
  422. public function configsms()
  423. {
  424. if (Request()->isPost()) {
  425. $config = input('','','htmlentities');
  426. $validate = \think\Loader::validate('Token');
  427. if(!$validate->check($config)){
  428. return $this->error($validate->getError());
  429. }
  430. unset($config['__token__']);
  431. $config_new['sms'] = $config['sms'];
  432. $config_old = config('maccms');
  433. $config_new = array_merge($config_old, $config_new);
  434. $res = mac_arr2file(APP_PATH . 'extra/maccms.php', $config_new);
  435. if ($res === false) {
  436. return $this->error(lang('save_err'));
  437. }
  438. return $this->success(lang('save_ok'));
  439. }
  440. $this->assign('config', config('maccms'));
  441. $extends = mac_extends_list('sms');
  442. $this->assign('extends',$extends);
  443. $this->assign('title', lang('admin/system/configsms/title'));
  444. return $this->fetch('admin@system/configsms');
  445. }
  446. public function configapi()
  447. {
  448. if (Request()->isPost()) {
  449. $config = input('','','htmlentities');
  450. $validate = \think\Loader::validate('Token');
  451. if(!$validate->check($config)){
  452. return $this->error($validate->getError());
  453. }
  454. unset($config['__token__']);
  455. $config_new['api'] = $config['api'];
  456. $config_new['api']['vod']['auth'] = mac_replace_text($config_new['api']['vod']['auth'], 2);
  457. $config_new['api']['art']['auth'] = mac_replace_text($config_new['api']['art']['auth'], 2);
  458. $config_new['api']['actor']['auth'] = mac_replace_text($config_new['api']['actor']['auth'], 2);
  459. $config_new['api']['manga']['auth'] = mac_replace_text($config_new['api']['manga']['auth'], 2);
  460. $config_new['api']['publicapi']['auth'] = mac_replace_text($config_new['api']['publicapi']['auth'], 2);
  461. $config_old = config('maccms');
  462. $config_new = array_merge($config_old, $config_new);
  463. $res = mac_arr2file(APP_PATH . 'extra/maccms.php', $config_new);
  464. if ($res === false) {
  465. return $this->error(lang('save_err'));
  466. }
  467. return $this->success(lang('save_ok'));
  468. }
  469. $config = config('maccms');
  470. if(!isset($config['api']['publicapi'])){
  471. $config['api']['publicapi'] = [
  472. 'status' => '0',
  473. 'charge' => '0',
  474. 'auth' => '',
  475. ];
  476. }
  477. if(!isset($config['api']['manga'])){
  478. $config['api']['manga'] = [
  479. 'status' => '0',
  480. 'charge' => '0',
  481. 'pagesize' => '20',
  482. 'imgurl' => '',
  483. 'typefilter' => '',
  484. 'datafilter' => 'manga_status=1',
  485. 'cachetime' => '',
  486. 'auth' => '',
  487. ];
  488. }
  489. $this->assign('config',$config );
  490. $this->assign('title', lang('admin/system/configapi/title'));
  491. return $this->fetch('admin@system/configapi');
  492. }
  493. public function configinterface()
  494. {
  495. if (Request()->isPost()) {
  496. $config = input('','','htmlentities');
  497. $validate = \think\Loader::validate('Token');
  498. if(!$validate->check($config)){
  499. return $this->error($validate->getError());
  500. }
  501. unset($config['__token__']);
  502. if($config['interface']['status']==1 && strlen($config['interface']['pass']) < 16){
  503. return $this->error(lang('admin/system/configinterface/pass_check'));
  504. }
  505. $config_new['interface'] = $config['interface'];
  506. $config_new['interface']['vodtype'] = mac_replace_text($config_new['interface']['vodtype'], 2);
  507. $config_new['interface']['arttype'] = mac_replace_text($config_new['interface']['arttype'], 2);
  508. $config_old = config('maccms');
  509. $config_new = array_merge($config_old, $config_new);
  510. $res = mac_arr2file(APP_PATH . 'extra/maccms.php', $config_new);
  511. if ($res === false) {
  512. return $this->error(lang('save_err'));
  513. }
  514. //保存缓存
  515. mac_interface_type();
  516. return $this->success(lang('save_ok'));
  517. }
  518. $this->assign('config', config('maccms'));
  519. $this->assign('title', lang('admin/system/configinterface/title'));
  520. return $this->fetch('admin@system/configinterface');
  521. }
  522. public function configcollect()
  523. {
  524. if (Request()->isPost()) {
  525. $config = input('','','htmlentities');
  526. $validate = \think\Loader::validate('Token');
  527. if(!$validate->check($config)){
  528. return $this->error($validate->getError());
  529. }
  530. unset($config['__token__']);
  531. $config_new['collect'] = $config['collect'];
  532. if (empty($config_new['collect']['vod']['inrule'])) {
  533. $config_new['collect']['vod']['inrule'] = ['a'];
  534. }
  535. if (empty($config_new['collect']['vod']['uprule'])) {
  536. $config_new['collect']['vod']['uprule'] = [];
  537. }
  538. if (empty($config_new['collect']['art']['inrule'])) {
  539. $config_new['collect']['art']['inrule'] = ['a'];
  540. }
  541. if (empty($config_new['collect']['art']['uprule'])) {
  542. $config_new['collect']['art']['uprule'] = [];
  543. }
  544. if (empty($config_new['collect']['actor']['inrule'])) {
  545. $config_new['collect']['actor']['inrule'] = ['a'];
  546. }
  547. if (empty($config_new['collect']['actor']['uprule'])) {
  548. $config_new['collect']['actor']['uprule'] = [];
  549. }
  550. if (empty($config_new['collect']['role']['inrule'])) {
  551. $config_new['collect']['role']['inrule'] = ['a'];
  552. }
  553. if (empty($config_new['collect']['role']['uprule'])) {
  554. $config_new['collect']['role']['uprule'] = [];
  555. }
  556. if (empty($config_new['collect']['website']['inrule'])) {
  557. $config_new['collect']['website']['inrule'] = ['a'];
  558. }
  559. if (empty($config_new['collect']['website']['uprule'])) {
  560. $config_new['collect']['website']['uprule'] = [];
  561. }
  562. if (empty($config_new['collect']['comment']['inrule'])) {
  563. $config_new['collect']['comment']['inrule'] = ['a'];
  564. }
  565. if (empty($config_new['collect']['comment']['uprule'])) {
  566. $config_new['collect']['comment']['uprule'] = [];
  567. }
  568. if (empty($config_new['collect']['manga']['inrule'])) {
  569. $config_new['collect']['manga']['inrule'] = ['a'];
  570. }
  571. if (empty($config_new['collect']['manga']['uprule'])) {
  572. $config_new['collect']['manga']['uprule'] = [];
  573. }
  574. $config_new['collect']['vod']['inrule'] = ',' . join(',', $config_new['collect']['vod']['inrule']);
  575. $config_new['collect']['vod']['uprule'] = ',' . join(',', $config_new['collect']['vod']['uprule']);
  576. $config_new['collect']['art']['inrule'] = ',' . join(',', $config_new['collect']['art']['inrule']);
  577. $config_new['collect']['art']['uprule'] = ',' . join(',', $config_new['collect']['art']['uprule']);
  578. $config_new['collect']['actor']['inrule'] = ',' . join(',', $config_new['collect']['actor']['inrule']);
  579. $config_new['collect']['actor']['uprule'] = ',' . join(',', $config_new['collect']['actor']['uprule']);
  580. $config_new['collect']['role']['inrule'] = ',' . join(',', $config_new['collect']['role']['inrule']);
  581. $config_new['collect']['role']['uprule'] = ',' . join(',', $config_new['collect']['role']['uprule']);
  582. $config_new['collect']['website']['inrule'] = ',' . join(',', $config_new['collect']['website']['inrule']);
  583. $config_new['collect']['website']['uprule'] = ',' . join(',', $config_new['collect']['website']['uprule']);
  584. $config_new['collect']['comment']['inrule'] = ',' . join(',', $config_new['collect']['comment']['inrule']);
  585. $config_new['collect']['comment']['uprule'] = ',' . join(',', $config_new['collect']['comment']['uprule']);
  586. $config_new['collect']['manga']['inrule'] = ',' . join(',', $config_new['collect']['manga']['inrule']);
  587. $config_new['collect']['manga']['uprule'] = ',' . join(',', $config_new['collect']['manga']['uprule']);
  588. $config_new['collect']['vod']['namewords'] = mac_replace_text($config_new['collect']['vod']['namewords'], 2);
  589. $config_new['collect']['vod']['thesaurus'] = mac_replace_text($config_new['collect']['vod']['thesaurus'], 2);
  590. $config_new['collect']['vod']['playerwords'] = mac_replace_text($config_new['collect']['vod']['playerwords'], 2);
  591. $config_new['collect']['vod']['areawords'] = mac_replace_text($config_new['collect']['vod']['areawords'], 2);
  592. $config_new['collect']['vod']['langwords'] = mac_replace_text($config_new['collect']['vod']['langwords'], 2);
  593. $config_new['collect']['vod']['words'] = mac_replace_text($config_new['collect']['vod']['words'], 2);
  594. $config_new['collect']['art']['thesaurus'] = mac_replace_text($config_new['collect']['art']['thesaurus'], 2);
  595. $config_new['collect']['art']['words'] = mac_replace_text($config_new['collect']['art']['words'], 2);
  596. $config_new['collect']['actor']['thesaurus'] = mac_replace_text($config_new['collect']['actor']['thesaurus'], 2);
  597. $config_new['collect']['actor']['words'] = mac_replace_text($config_new['collect']['actor']['words'], 2);
  598. $config_new['collect']['role']['thesaurus'] = mac_replace_text($config_new['collect']['role']['thesaurus'], 2);
  599. $config_new['collect']['role']['words'] = mac_replace_text($config_new['collect']['role']['words'], 2);
  600. $config_new['collect']['website']['thesaurus'] = mac_replace_text($config_new['collect']['website']['thesaurus'], 2);
  601. $config_new['collect']['website']['words'] = mac_replace_text($config_new['collect']['website']['words'], 2);
  602. $config_new['collect']['comment']['thesaurus'] = mac_replace_text($config_new['collect']['comment']['thesaurus'], 2);
  603. $config_new['collect']['comment']['words'] = mac_replace_text($config_new['collect']['comment']['words'], 2);
  604. $config_old = config('maccms');
  605. $config_new = array_merge($config_old, $config_new);
  606. $res = mac_arr2file(APP_PATH . 'extra/maccms.php', $config_new);
  607. if ($res === false) {
  608. return $this->error(lang('save_err'));
  609. }
  610. return $this->success(lang('save_ok'));
  611. }
  612. $this->assign('config', config('maccms'));
  613. $this->assign('title', lang('admin/system/configcollect/title'));
  614. return $this->fetch('admin@system/configcollect');
  615. }
  616. public function configplay()
  617. {
  618. if (Request()->isPost()) {
  619. $config = input('','','htmlentities');
  620. $validate = \think\Loader::validate('Token');
  621. if(!$validate->check($config)){
  622. return $this->error($validate->getError());
  623. }
  624. unset($config['__token__']);
  625. $config_new['play'] = $config['play'];
  626. $config_old = config('maccms');
  627. $config_new = array_merge($config_old, $config_new);
  628. $res = mac_arr2file(APP_PATH . 'extra/maccms.php', $config_new);
  629. if ($res === false) {
  630. return $this->error(lang('save_err'));
  631. }
  632. $path = './static/js/playerconfig.js';
  633. if (!file_exists($path)) {
  634. $path .= '.bak';
  635. }
  636. $fc = @file_get_contents($path);
  637. $jsb = mac_get_body($fc, '//参数开始', '//参数结束');
  638. $content = 'MacPlayerConfig=' . json_encode($config['play']) . ';';
  639. $fc = str_replace($jsb, "\r\n" . $content . "\r\n", $fc);
  640. $res = @fwrite(fopen('./static/js/playerconfig.js', 'wb'), $fc);
  641. if ($res === false) {
  642. return $this->error(lang('save_err'));
  643. }
  644. return $this->success(lang('save_ok'));
  645. }
  646. $fp = './static/js/playerconfig.js';
  647. if (!file_exists($fp)) {
  648. $fp .= '.bak';
  649. }
  650. $fc = file_get_contents($fp);
  651. $jsb = trim(mac_get_body($fc, '//参数开始', '//参数结束'));
  652. $jsb = substr($jsb, 16, strlen($jsb) - 17);
  653. $play = json_decode($jsb, true);
  654. $this->assign('play', $play);
  655. $this->assign('title', lang('admin/system/configplay/title'));
  656. return $this->fetch('admin@system/configplay');
  657. }
  658. public function configseo()
  659. {
  660. if (Request()->isPost()) {
  661. $config = input('','','htmlentities');
  662. $validate = \think\Loader::validate('Token');
  663. if(!$validate->check($config)){
  664. return $this->error($validate->getError());
  665. }
  666. unset($config['__token__']);
  667. $config_new['seo'] = $config['seo'];
  668. $config_old = config('maccms');
  669. $config_new = array_merge($config_old, $config_new);
  670. $res = mac_arr2file(APP_PATH . 'extra/maccms.php', $config_new);
  671. if ($res === false) {
  672. return $this->error(lang('save_err'));
  673. }
  674. return $this->success(lang('save_ok'));
  675. }
  676. $this->assign('config', config('maccms'));
  677. $this->assign('title', lang('admin/system/configseo/title'));
  678. return $this->fetch('admin@system/configseo');
  679. }
  680. public function configaiseo()
  681. {
  682. if (Request()->isPost()) {
  683. $post = input('post.', '', 'htmlentities');
  684. $validate = \think\Loader::validate('Token');
  685. if (!$validate->check($post)) {
  686. return $this->error($validate->getError());
  687. }
  688. unset($post['__token__']);
  689. $config_old = config('maccms');
  690. $ai = isset($post['ai_seo']) && is_array($post['ai_seo']) ? $post['ai_seo'] : [];
  691. $sanitize = function ($v) {
  692. return trim(strip_tags((string)$v));
  693. };
  694. $row = [
  695. 'enabled' => isset($ai['enabled']) && (string)$ai['enabled'] === '1' ? '1' : '0',
  696. 'auto_generate' => isset($ai['auto_generate']) && (string)$ai['auto_generate'] === '1' ? '1' : '0',
  697. 'template_inject' => isset($ai['template_inject']) && (string)$ai['template_inject'] === '1' ? '1' : '0',
  698. 'provider' => $sanitize(isset($ai['provider']) ? $ai['provider'] : 'openai'),
  699. 'model' => $sanitize(isset($ai['model']) ? $ai['model'] : 'gpt-4o-mini'),
  700. 'api_base' => $sanitize(isset($ai['api_base']) ? $ai['api_base'] : 'https://api.openai.com/v1'),
  701. 'timeout' => (string)max(5, intval(isset($ai['timeout']) ? $ai['timeout'] : 20)),
  702. ];
  703. if ($row['api_base'] === '') {
  704. $row['api_base'] = 'https://api.openai.com/v1';
  705. }
  706. $newKey = isset($ai['api_key']) ? trim((string)$ai['api_key']) : '';
  707. if ($newKey !== '') {
  708. $row['api_key'] = $newKey;
  709. } else {
  710. // Read from latest config file to avoid accidental key loss when config cache is stale.
  711. $cfgFile = APP_PATH . 'extra/maccms.php';
  712. $latest = is_file($cfgFile) ? include $cfgFile : [];
  713. if (isset($latest['ai_seo']['api_key']) && $latest['ai_seo']['api_key'] !== '') {
  714. $row['api_key'] = (string)$latest['ai_seo']['api_key'];
  715. } else {
  716. $row['api_key'] = isset($config_old['ai_seo']['api_key']) ? $config_old['ai_seo']['api_key'] : '';
  717. }
  718. }
  719. $config_new = $config_old;
  720. $config_new['ai_seo'] = $row;
  721. $res = mac_arr2file(APP_PATH . 'extra/maccms.php', $config_new);
  722. if ($res === false) {
  723. return $this->error(lang('save_err'));
  724. }
  725. return $this->success(lang('save_ok'));
  726. }
  727. $config = config('maccms');
  728. if (!isset($config['ai_seo']) || !is_array($config['ai_seo'])) {
  729. $config['ai_seo'] = [
  730. 'enabled' => '0',
  731. 'auto_generate' => '1',
  732. 'template_inject' => '1',
  733. 'provider' => 'openai',
  734. 'model' => 'gpt-4o-mini',
  735. 'api_base' => 'https://api.openai.com/v1',
  736. 'api_key' => '',
  737. 'timeout' => '20',
  738. ];
  739. }
  740. $apiKey = isset($config['ai_seo']['api_key']) ? trim((string)$config['ai_seo']['api_key']) : '';
  741. $this->assign('ai_seo_key_saved', $apiKey !== '' ? 1 : 0);
  742. $this->assign('ai_seo_key_tail', $apiKey !== '' ? substr($apiKey, -6) : '');
  743. $this->assign('config', $config);
  744. $this->assign('title', lang('admin/system/configaiseo/title'));
  745. return $this->fetch('admin@system/configaiseo');
  746. }
  747. public function configlang(){
  748. $param = input();
  749. $config = config('maccms');
  750. if (!isset($config['app'])) {
  751. $config['app'] = [];
  752. }
  753. $config['app']['lang'] = $param['lang'];
  754. $res = mac_arr2file(APP_PATH . 'extra/maccms.php', $config);
  755. if ($res === false) {
  756. return $this->error(lang('save_err'));
  757. }
  758. return json(['code' => 1, 'msg' => 'ok']);
  759. }
  760. public function configVersion(){
  761. $param = input();
  762. $config = config('maccms');
  763. if (!isset($config['site'])) {
  764. $config['site'] = [];
  765. }
  766. $config['site']['new_version'] = $param['version'];
  767. if (!is_writable(APP_PATH . 'extra/maccms.php')) {
  768. return $this->error(APP_PATH . 'extra/maccms.php' . lang('install/write_read_err'));
  769. }
  770. $res = mac_arr2file(APP_PATH . 'extra/maccms.php', $config);
  771. if ($res === false) {
  772. return $this->error(lang('save_err'));
  773. }
  774. return json(['code' => 1, 'msg' => 'ok']);
  775. }
  776. }