System.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606
  1. <?php
  2. namespace app\admin\controller;
  3. use think\Db;
  4. use think\Config;
  5. use think\Cache;
  6. use think\View;
  7. class System extends Base
  8. {
  9. public function test_email()
  10. {
  11. $post = input();
  12. $conf = [
  13. 'host' => $post['host'],
  14. 'username' => $post['username'],
  15. 'password' => $post['password'],
  16. 'port' => $post['port'],
  17. 'nick' => $post['nick'],
  18. 'test' => $post['test'],
  19. ];
  20. $this->label_maccms();
  21. $res = mac_send_mail($conf['test'], $GLOBALS['config']['email']['tpl']['test_title'], $GLOBALS['config']['email']['tpl']['test_body'], $conf);
  22. if ($res['code']==1) {
  23. return json(['code' => 1, 'msg' => '测试成功']);
  24. }
  25. return json(['code' => 1001, 'msg' => '测试失败:'.$res['msg']]);
  26. }
  27. public function test_cache()
  28. {
  29. $param = input();
  30. if (!isset($param['type']) || empty($param['host']) || empty($param['port'])) {
  31. return $this->error('参数错误!');
  32. }
  33. $options = [
  34. 'type' => $param['type'],
  35. 'port' => $param['port'],
  36. 'username' => $param['username'],
  37. 'password' => $param['password']
  38. ];
  39. $hd = Cache::connect($options);
  40. $hd->set('test', 'test');
  41. return json(['code' => 1, 'msg' => '测试成功']);
  42. }
  43. public function config()
  44. {
  45. if (Request()->isPost()) {
  46. $config = input();
  47. $validate = \think\Loader::validate('System');
  48. if(!$validate->check($config)){
  49. return $this->error($validate->getError());
  50. }
  51. unset($config['__token__']);
  52. $ads_dir='ads';
  53. $mob_ads_dir='ads';
  54. $path = ROOT_PATH .'template/'.$config['site']['template_dir'].'/info.ini';
  55. $cc = Config::load($path,'ini');
  56. if(!empty($cc['adsdir'])){
  57. $ads_dir = $cc['adsdir'];
  58. }
  59. $path = ROOT_PATH .'template/'.$config['site']['mob_template_dir'].'/info.ini';
  60. $cc = Config::load($path,'ini');
  61. if(!empty($cc['adsdir'])){
  62. $mob_ads_dir = $cc['adsdir'];
  63. }
  64. $config['site']['ads_dir'] = $ads_dir;
  65. $config['site']['mob_ads_dir'] = $mob_ads_dir;
  66. if(empty($config['app']['cache_flag'])){
  67. $config['app']['cache_flag'] = substr(md5(time()),0,10);
  68. }
  69. $config['app']['search_vod_rule'] = join('|', $config['app']['search_vod_rule']);
  70. $config['app']['search_art_rule'] = join('|', $config['app']['search_art_rule']);
  71. $config['extra'] = [];
  72. if(!empty($config['app']['extra_var'])){
  73. $extra_var = str_replace(array(chr(10),chr(13)), array('','#'),$config['app']['extra_var']);
  74. $tmp = explode('#',$extra_var);
  75. foreach($tmp as $a){
  76. if(strpos($a,'$$$')!==false){
  77. $tmp2 = explode('$$$',$a);
  78. $config['extra'][$tmp2[0]] = $tmp2[1];
  79. }
  80. }
  81. unset($tmp,$tmp2);
  82. }
  83. $config_new['site'] = $config['site'];
  84. $config_new['app'] = $config['app'];
  85. $config_new['extra'] = $config['extra'];
  86. $config_old = config('maccms');
  87. $config_new = array_merge($config_old, $config_new);
  88. $tj = $config_new['site']['site_tj'];
  89. if(strpos($tj,'document.w') ===false){
  90. $tj = 'document.write(\'' . str_replace("'","\'",$tj) . '\')';
  91. }
  92. $res = @fwrite(fopen('./static/js/tj.js', 'wb'), $tj);
  93. $res = mac_arr2file(APP_PATH . 'extra/maccms.php', $config_new);
  94. if ($res === false) {
  95. return $this->error('保存失败,请重试!');
  96. }
  97. return $this->success('保存成功!');
  98. }
  99. $templates = glob('./template' . '/*', GLOB_ONLYDIR);
  100. foreach ($templates as $k => &$v) {
  101. $v = str_replace('./template/', '', $v);
  102. }
  103. $this->assign('templates', $templates);
  104. $usergroup = Db::name('group')->select();
  105. $this->assign('usergroup', $usergroup);
  106. $editors = mac_extends_list('editor');
  107. $this->assign('editors',$editors);
  108. $config = config('maccms');
  109. $this->assign('config', $config);
  110. $this->assign('title', '网站参数配置');
  111. return $this->fetch('admin@system/config');
  112. }
  113. public function configurl()
  114. {
  115. if (Request()->isPost()) {
  116. $config = input();
  117. $config_new['view'] = $config['view'];
  118. $config_new['path'] = $config['path'];
  119. $config_new['rewrite'] = $config['rewrite'];
  120. //写路由规则文件
  121. $route = [];
  122. $route['__pattern__'] = [
  123. 'id'=>'[\s\S]*?',
  124. 'ids'=>'[\s\S]*?',
  125. 'wd' => '[\s\S]*',
  126. 'en'=>'[\s\S]*?',
  127. 'state' => '[\s\S]*?',
  128. 'area' => '[\s\S]*',
  129. 'year'=>'[\s\S]*?',
  130. 'lang' => '[\s\S]*?',
  131. 'letter'=>'[\s\S]*?',
  132. 'actor' => '[\s\S]*?',
  133. 'director' => '[\s\S]*?',
  134. 'tag' => '[\s\S]*?',
  135. 'class' => '[\s\S]*?',
  136. 'order'=>'[\s\S]*?',
  137. 'by'=>'[\s\S]*?',
  138. 'file'=>'[\s\S]*?',
  139. 'name'=>'[\s\S]*?',
  140. 'url'=>'[\s\S]*?',
  141. 'type'=>'[\s\S]*?',
  142. 'sex' => '[\s\S]*?',
  143. 'version' => '[\s\S]*?',
  144. 'blood' => '[\s\S]*?',
  145. 'starsign' => '[\s\S]*?',
  146. 'page'=>'\d+',
  147. 'ajax'=>'\d+',
  148. 'tid'=>'\d+',
  149. 'mid'=>'\d+',
  150. 'rid'=>'\d+',
  151. 'pid'=>'\d+',
  152. 'sid'=>'\d+',
  153. 'nid'=>'\d+',
  154. 'uid'=>'\d+',
  155. 'level'=>'\d+',
  156. 'score'=>'\d+',
  157. 'limit'=>'\d+',
  158. ];
  159. $rows = explode(chr(13), str_replace(chr(10), '', $config['rewrite']['route']));
  160. foreach ($rows as $r) {
  161. if (strpos($r, '=>') !== false) {
  162. $a = explode('=>', $r);
  163. $rule = [];
  164. if (strpos($a, ':id') !== false) {
  165. //$rule['id'] = '\w+';
  166. }
  167. $route[trim($a[0])] = [trim($a[1]), [], $rule];
  168. }
  169. }
  170. $res = mac_arr2file(APP_PATH . 'route.php', $route);
  171. if ($res === false) {
  172. return $this->error('保存路由配置失败,请重试!');
  173. }
  174. //写扩展配置
  175. $config_old = config('maccms');
  176. $config_new = array_merge($config_old, $config_new);
  177. $res = mac_arr2file(APP_PATH . 'extra/maccms.php', $config_new);
  178. if ($res === false) {
  179. return $this->error('保存配置文件失败,请重试!');
  180. }
  181. return $this->success('保存成功!');
  182. }
  183. $this->assign('config', config('maccms'));
  184. $this->assign('title', 'url参数配置');
  185. return $this->fetch('admin@system/configurl');
  186. }
  187. public function configuser()
  188. {
  189. if (Request()->isPost()) {
  190. $config = input();
  191. $config_new['user'] = $config['user'];
  192. $config_old = config('maccms');
  193. $config_new = array_merge($config_old, $config_new);
  194. $res = mac_arr2file(APP_PATH . 'extra/maccms.php', $config_new);
  195. if ($res === false) {
  196. return $this->error('保存失败,请重试!');
  197. }
  198. return $this->success('保存成功!');
  199. }
  200. $this->assign('config', config('maccms'));
  201. $this->assign('title', '会员参数配置');
  202. return $this->fetch('admin@system/configuser');
  203. }
  204. public function configupload()
  205. {
  206. if (Request()->isPost()){
  207. $config = input();
  208. $config_new['upload'] = $config['upload'];
  209. $config_old = config('maccms');
  210. $config_new = array_merge($config_old, $config_new);
  211. $res = mac_arr2file(APP_PATH . 'extra/maccms.php', $config_new);
  212. if ($res === false) {
  213. return $this->error('保存失败,请重试!');
  214. }
  215. return $this->success('保存成功!');
  216. }
  217. $this->assign('config', config('maccms'));
  218. $extends = mac_extends_list('upload');
  219. $this->assign('extends',$extends);
  220. $this->assign('title', '附件参数配置');
  221. return $this->fetch('admin@system/configupload');
  222. }
  223. public function configcomment()
  224. {
  225. if (Request()->isPost()) {
  226. $config = input();
  227. $config_new['gbook'] = $config['gbook'];
  228. $config_new['comment'] = $config['comment'];
  229. $config_old = config('maccms');
  230. $config_new = array_merge($config_old, $config_new);
  231. $res = mac_arr2file(APP_PATH . 'extra/maccms.php', $config_new);
  232. if ($res === false) {
  233. return $this->error('保存失败,请重试!');
  234. }
  235. return $this->success('保存成功!');
  236. }
  237. $this->assign('config', config('maccms'));
  238. $this->assign('title', '评论留言配置');
  239. return $this->fetch('admin@system/configcomment');
  240. }
  241. public function configweixin()
  242. {
  243. if (Request()->isPost()) {
  244. $config = input();
  245. $config_new['weixin'] = $config['weixin'];
  246. $config_old = config('maccms');
  247. $config_new = array_merge($config_old, $config_new);
  248. $res = mac_arr2file(APP_PATH . 'extra/maccms.php', $config_new);
  249. if ($res === false) {
  250. return $this->error('保存失败,请重试!');
  251. }
  252. return $this->success('保存成功!');
  253. }
  254. $this->assign('config', config('maccms'));
  255. $this->assign('title', '微信对接配置');
  256. return $this->fetch('admin@system/configweixin');
  257. }
  258. public function configpay()
  259. {
  260. if (Request()->isPost()) {
  261. $config = input();
  262. $config_new['pay'] = $config['pay'];
  263. $config_old = config('maccms');
  264. $config_new = array_merge($config_old, $config_new);
  265. $res = mac_arr2file(APP_PATH . 'extra/maccms.php', $config_new);
  266. if ($res === false) {
  267. return $this->error('保存失败,请重试!');
  268. }
  269. return $this->success('保存成功!');
  270. }
  271. $this->assign('http_type',$GLOBALS['http_type']);
  272. $this->assign('config', config('maccms'));
  273. $extends = mac_extends_list('pay');
  274. $this->assign('extends',$extends);
  275. $this->assign('title', '在线支付配置');
  276. return $this->fetch('admin@system/configpay');
  277. }
  278. public function configconnect()
  279. {
  280. if (Request()->isPost()) {
  281. $config = input();
  282. $config_new['connect'] = $config['connect'];
  283. $config_old = config('maccms');
  284. $config_new = array_merge($config_old, $config_new);
  285. $res = mac_arr2file(APP_PATH . 'extra/maccms.php', $config_new);
  286. if ($res === false) {
  287. return $this->error('保存失败,请重试!');
  288. }
  289. return $this->success('保存成功!');
  290. }
  291. $this->assign('config', config('maccms'));
  292. $this->assign('title', '整合登录配置');
  293. return $this->fetch('admin@system/configconnect');
  294. }
  295. public function configemail()
  296. {
  297. if (Request()->isPost()) {
  298. $config = input();
  299. $config_new['email'] = $config['email'];
  300. $config_old = config('maccms');
  301. $config_new = array_merge($config_old, $config_new);
  302. $res = mac_arr2file(APP_PATH . 'extra/maccms.php', $config_new);
  303. if ($res === false) {
  304. return $this->error('保存失败,请重试!');
  305. }
  306. return $this->success('保存成功!');
  307. }
  308. $this->assign('config', config('maccms'));
  309. $extends = mac_extends_list('email');
  310. $this->assign('extends',$extends);
  311. $this->assign('title', '邮件发送配置');
  312. return $this->fetch('admin@system/configemail');
  313. }
  314. public function configsms()
  315. {
  316. if (Request()->isPost()) {
  317. $config = input();
  318. $config_new['sms'] = $config['sms'];
  319. $config_old = config('maccms');
  320. $config_new = array_merge($config_old, $config_new);
  321. $res = mac_arr2file(APP_PATH . 'extra/maccms.php', $config_new);
  322. if ($res === false) {
  323. return $this->error('保存失败,请重试!');
  324. }
  325. return $this->success('保存成功!');
  326. }
  327. $extends = mac_extends_list('sms');
  328. $this->assign('extends',$extends);
  329. $this->assign('config', config('maccms'));
  330. $this->assign('title', '短信发送配置');
  331. return $this->fetch('admin@system/configsms');
  332. }
  333. public function configapi()
  334. {
  335. if (Request()->isPost()) {
  336. $config = input();
  337. $config_new['api'] = $config['api'];
  338. $config_new['api']['vod']['auth'] = mac_replace_text($config_new['api']['vod']['auth'], 2);
  339. $config_new['api']['art']['auth'] = mac_replace_text($config_new['api']['art']['auth'], 2);
  340. $config_new['api']['actor']['auth'] = mac_replace_text($config_new['api']['actor']['auth'], 2);
  341. $config_old = config('maccms');
  342. $config_new = array_merge($config_old, $config_new);
  343. $res = mac_arr2file(APP_PATH . 'extra/maccms.php', $config_new);
  344. if ($res === false) {
  345. return $this->error('保存失败,请重试!');
  346. }
  347. return $this->success('保存成功!');
  348. }
  349. $this->assign('config', config('maccms'));
  350. $this->assign('title', '采集接口API配置');
  351. return $this->fetch('admin@system/configapi');
  352. }
  353. public function configinterface()
  354. {
  355. if (Request()->isPost()) {
  356. $config = input();
  357. if($config['interface']['status']==1 && strlen($config['interface']['pass']) < 16){
  358. return $this->error('保存失败,安全起见入库密码必须大于等于16位!');
  359. }
  360. $config_new['interface'] = $config['interface'];
  361. $config_new['interface']['vodtype'] = mac_replace_text($config_new['interface']['vodtype'], 2);
  362. $config_new['interface']['arttype'] = mac_replace_text($config_new['interface']['arttype'], 2);
  363. $config_old = config('maccms');
  364. $config_new = array_merge($config_old, $config_new);
  365. $res = mac_arr2file(APP_PATH . 'extra/maccms.php', $config_new);
  366. if ($res === false) {
  367. return $this->error('保存失败,请重试!');
  368. }
  369. //保存缓存
  370. mac_interface_type();
  371. return $this->success('保存成功!');
  372. }
  373. $this->assign('config', config('maccms'));
  374. $this->assign('title', '站外入库配置');
  375. return $this->fetch('admin@system/configinterface');
  376. }
  377. public function configcollect()
  378. {
  379. if (Request()->isPost()) {
  380. $config = input();
  381. $config_new['collect'] = $config['collect'];
  382. if (empty($config_new['collect']['vod']['inrule'])) {
  383. $config_new['collect']['vod']['inrule'] = ['a'];
  384. }
  385. if (empty($config_new['collect']['vod']['uprule'])) {
  386. $config_new['collect']['vod']['uprule'] = [];
  387. }
  388. if (empty($config_new['collect']['art']['inrule'])) {
  389. $config_new['collect']['art']['inrule'] = ['a'];
  390. }
  391. if (empty($config_new['collect']['art']['uprule'])) {
  392. $config_new['collect']['art']['uprule'] = [];
  393. }
  394. if (empty($config_new['collect']['actor']['inrule'])) {
  395. $config_new['collect']['actor']['inrule'] = ['a'];
  396. }
  397. if (empty($config_new['collect']['actor']['uprule'])) {
  398. $config_new['collect']['actor']['uprule'] = [];
  399. }
  400. if (empty($config_new['collect']['role']['inrule'])) {
  401. $config_new['collect']['role']['inrule'] = ['a'];
  402. }
  403. if (empty($config_new['collect']['role']['uprule'])) {
  404. $config_new['collect']['role']['uprule'] = [];
  405. }
  406. if (empty($config_new['collect']['website']['inrule'])) {
  407. $config_new['collect']['website']['inrule'] = ['a'];
  408. }
  409. if (empty($config_new['collect']['website']['uprule'])) {
  410. $config_new['collect']['website']['uprule'] = [];
  411. }
  412. $config_new['collect']['vod']['inrule'] = ',' . join(',', $config_new['collect']['vod']['inrule']);
  413. $config_new['collect']['vod']['uprule'] = ',' . join(',', $config_new['collect']['vod']['uprule']);
  414. $config_new['collect']['art']['inrule'] = ',' . join(',', $config_new['collect']['art']['inrule']);
  415. $config_new['collect']['art']['uprule'] = ',' . join(',', $config_new['collect']['art']['uprule']);
  416. $config_new['collect']['actor']['inrule'] = ',' . join(',', $config_new['collect']['actor']['inrule']);
  417. $config_new['collect']['actor']['uprule'] = ',' . join(',', $config_new['collect']['actor']['uprule']);
  418. $config_new['collect']['role']['inrule'] = ',' . join(',', $config_new['collect']['role']['inrule']);
  419. $config_new['collect']['role']['uprule'] = ',' . join(',', $config_new['collect']['role']['uprule']);
  420. $config_new['collect']['website']['inrule'] = ',' . join(',', $config_new['collect']['website']['inrule']);
  421. $config_new['collect']['website']['uprule'] = ',' . join(',', $config_new['collect']['website']['uprule']);
  422. $config_new['collect']['vod']['namewords'] = mac_replace_text($config_new['collect']['vod']['namewords'], 2);
  423. $config_new['collect']['vod']['thesaurus'] = mac_replace_text($config_new['collect']['vod']['thesaurus'], 2);
  424. $config_new['collect']['vod']['words'] = mac_replace_text($config_new['collect']['vod']['words'], 2);
  425. $config_new['collect']['art']['thesaurus'] = mac_replace_text($config_new['collect']['art']['thesaurus'], 2);
  426. $config_new['collect']['art']['words'] = mac_replace_text($config_new['collect']['art']['words'], 2);
  427. $config_new['collect']['actor']['thesaurus'] = mac_replace_text($config_new['collect']['actor']['thesaurus'], 2);
  428. $config_new['collect']['actor']['words'] = mac_replace_text($config_new['collect']['actor']['words'], 2);
  429. $config_new['collect']['role']['thesaurus'] = mac_replace_text($config_new['collect']['role']['thesaurus'], 2);
  430. $config_new['collect']['role']['words'] = mac_replace_text($config_new['collect']['role']['words'], 2);
  431. $config_new['collect']['website']['thesaurus'] = mac_replace_text($config_new['collect']['website']['thesaurus'], 2);
  432. $config_new['collect']['website']['words'] = mac_replace_text($config_new['collect']['website']['words'], 2);
  433. $config_old = config('maccms');
  434. $config_new = array_merge($config_old, $config_new);
  435. $res = mac_arr2file(APP_PATH . 'extra/maccms.php', $config_new);
  436. if ($res === false) {
  437. return $this->error('保存失败,请重试!');
  438. }
  439. return $this->success('保存成功!');
  440. }
  441. $this->assign('config', config('maccms'));
  442. $this->assign('title', '采集参数配置');
  443. return $this->fetch('admin@system/configcollect');
  444. }
  445. public function configplay()
  446. {
  447. if (Request()->isPost()) {
  448. $config = input();
  449. $config_new['play'] = $config['play'];
  450. $config_old = config('maccms');
  451. $config_new = array_merge($config_old, $config_new);
  452. $res = mac_arr2file(APP_PATH . 'extra/maccms.php', $config_new);
  453. if ($res === false) {
  454. return $this->error('保存失败,请重试!');
  455. }
  456. $path = './static/js/playerconfig.js';
  457. if (!file_exists($path)) {
  458. $path .= '.bak';
  459. }
  460. $fc = @file_get_contents($path);
  461. $jsb = mac_get_body($fc, '//参数开始', '//参数结束');
  462. $content = 'MacPlayerConfig=' . json_encode($config['play']) . ';';
  463. $fc = str_replace($jsb, "\r\n" . $content . "\r\n", $fc);
  464. $res = @fwrite(fopen('./static/js/playerconfig.js', 'wb'), $fc);
  465. if ($res === false) {
  466. return $this->error('保存失败,请重试!');
  467. }
  468. return $this->success('保存成功!');
  469. }
  470. $fp = './static/js/playerconfig.js';
  471. if (!file_exists($fp)) {
  472. $fp .= '.bak';
  473. }
  474. $fc = file_get_contents($fp);
  475. $jsb = trim(mac_get_body($fc, '//参数开始', '//参数结束'));
  476. $jsb = substr($jsb, 16, strlen($jsb) - 17);
  477. $play = json_decode($jsb, true);
  478. $this->assign('play', $play);
  479. $this->assign('title', '播放器参数配置');
  480. return $this->fetch('admin@system/configplay');
  481. }
  482. public function configseo()
  483. {
  484. if (Request()->isPost()) {
  485. $config = input();
  486. $config_new['seo'] = $config['seo'];
  487. $config_old = config('maccms');
  488. $config_new = array_merge($config_old, $config_new);
  489. $res = mac_arr2file(APP_PATH . 'extra/maccms.php', $config_new);
  490. if ($res === false) {
  491. return $this->error('保存失败,请重试!');
  492. }
  493. return $this->success('保存成功!');
  494. }
  495. $this->assign('config', config('maccms'));
  496. $this->assign('title', 'SEO参数配置');
  497. return $this->fetch('admin@system/configseo');
  498. }
  499. }