1
0

Domain.php 3.7 KB

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