Domain.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. namespace app\admin\controller;
  3. use think\Db;
  4. use think\Config;
  5. use think\Cache;
  6. class Domain extends Base
  7. {
  8. public function index()
  9. {
  10. if (Request()->isPost()) {
  11. $config = input();
  12. $tmp = $config['domain'];
  13. $domain=[];
  14. foreach ($tmp['site_url'] as $k=>$v){
  15. $domain[$v] =[
  16. 'site_url'=>$v,
  17. 'site_name'=>$tmp['site_name'][$k],
  18. 'site_keywords'=>$tmp['site_keywords'][$k],
  19. 'site_description'=>$tmp['site_description'][$k],
  20. 'template_dir'=>$tmp['template_dir'][$k],
  21. 'html_dir'=>$tmp['html_dir'][$k],
  22. 'ads_dir'=>$tmp['ads_dir'][$k],
  23. ];
  24. }
  25. $res = mac_arr2file(APP_PATH . 'extra/domain.php', $domain);
  26. if ($res === false) {
  27. return $this->error(lang('save_err'));
  28. }
  29. return $this->success(lang('save_ok'));
  30. }
  31. $templates = glob('./template' . '/*', GLOB_ONLYDIR);
  32. foreach ($templates as $k => &$v) {
  33. $v = str_replace('./template/', '', $v);
  34. }
  35. $this->assign('templates', $templates);
  36. $config = config('domain');
  37. $this->assign('domain_list', $config);
  38. $this->assign('title', lang('admin/domain/title'));
  39. return $this->fetch('admin@domain/index');
  40. }
  41. public function del()
  42. {
  43. $param = input();
  44. if(!empty($param['ids'])){
  45. $list = config('domain');
  46. unset($list[$param['ids']]);
  47. $res = mac_arr2file( APP_PATH .'extra/domain.php', $list);
  48. if($res===false){
  49. return $this->error(lang('del_err'));
  50. }
  51. }
  52. return $this->success(lang('del_ok'));
  53. }
  54. public function export()
  55. {
  56. $list = config('domain');
  57. $html = '';
  58. foreach($list as $k=>$v){
  59. $html .= $v['site_url'].'$'.$v['site_name'].'$'.$v['site_keywords'].'$'.$v['site_description'].'$'.$v['template_dir'].'$'.$v['html_dir'].'$'.$v['ads_dir']."\n";
  60. }
  61. header("Content-type: application/octet-stream");
  62. header("Content-Disposition: attachment; filename=mac_domains.txt");
  63. echo $html;
  64. }
  65. public function import()
  66. {
  67. $file = $this->request->file('file');
  68. $info = $file->rule('uniqid')->validate(['size' => 10240000, 'ext' => 'txt']);
  69. if ($info) {
  70. $data = file_get_contents($info->getpathName());
  71. @unlink($info->getpathName());
  72. if($data){
  73. $list = explode(chr(10),$data);
  74. $domain =[];
  75. foreach($list as $k=>$v){
  76. if(!empty($v)) {
  77. $one = explode('$', $v);
  78. $domain[$one[0]] = [
  79. 'site_url' => $one[0],
  80. 'site_name' => $one[1],
  81. 'site_keywords' => $one[2],
  82. 'site_description' => $one[3],
  83. 'template_dir' => $one[4],
  84. 'html_dir' => $one[5],
  85. 'ads_dir'=>$one[6],
  86. ];
  87. }
  88. }
  89. $res = mac_arr2file( APP_PATH .'extra/domain.php', $domain);
  90. if($res===false){
  91. return $this->error(lang('write_err_config'));
  92. }
  93. }
  94. return $this->success(lang('import_err'));
  95. }
  96. else{
  97. return $this->error($file->getError());
  98. }
  99. }
  100. }