Vodplayer.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <?php
  2. namespace app\admin\controller;
  3. use think\Db;
  4. class VodPlayer extends Base
  5. {
  6. var $_pre;
  7. public function __construct()
  8. {
  9. parent::__construct();
  10. $this->_pre = 'vodplayer';
  11. }
  12. public function index()
  13. {
  14. $list = config($this->_pre);
  15. $this->assign('list',$list);
  16. $this->assign('title',lang('admin/vodplayer/title'));
  17. return $this->fetch('admin@vodplayer/index');
  18. }
  19. public function info()
  20. {
  21. $param = input();
  22. $list = config($this->_pre);
  23. if (Request()->isPost()) {
  24. $validate = \think\Loader::validate('Token');
  25. if(!$validate->check($param)){
  26. return $this->error($validate->getError());
  27. }
  28. unset($param['__token__']);
  29. unset($param['flag']);
  30. $code = $param['code'];
  31. unset($param['code']);
  32. if(is_numeric($param['from'])){
  33. $param['from'] .='_';
  34. }
  35. $list[$param['from']] = $param;
  36. $sort=[];
  37. foreach ($list as $k=>&$v){
  38. $sort[] = $v['sort'];
  39. }
  40. array_multisort($sort, SORT_DESC, SORT_FLAG_CASE , $list);
  41. $res = mac_arr2file( APP_PATH .'extra/'.$this->_pre.'.php', $list);
  42. if($res===false){
  43. return $this->error(lang('write_err_config'));
  44. }
  45. $res = fwrite(fopen('./static/player/' . $param['from'].'.js','wb'),$code);
  46. if($res===false){
  47. return $this->error(lang('wirte_err_codefile'));
  48. }
  49. return $this->success(lang('save_ok'));
  50. }
  51. $info = $list[$param['id']];
  52. if(!empty($info)){
  53. $code = file_get_contents('./static/player/' . $param['id'].'.js');
  54. $info['code'] = $code;
  55. }
  56. $this->assign('info',$info);
  57. $this->assign('title',lang('admin/vodplayer/title'));
  58. return $this->fetch('admin@vodplayer/info');
  59. }
  60. public function del()
  61. {
  62. $param = input();
  63. $list = config($this->_pre);
  64. unset($list[$param['ids']]);
  65. $res = mac_arr2file(APP_PATH. 'extra/'.$this->_pre.'.php', $list);
  66. if($res===false){
  67. return $this->error(lang('del_err'));
  68. }
  69. return $this->success(lang('del_ok'));
  70. }
  71. public function field()
  72. {
  73. $param = input();
  74. $ids = $param['ids'];
  75. $col = $param['col'];
  76. $val = $param['val'];
  77. if(!empty($ids) && in_array($col,['ps','status'])){
  78. $list = config($this->_pre);
  79. $ids = explode(',',$ids);
  80. foreach($list as $k=>&$v){
  81. if(in_array($k,$ids)){
  82. $v[$col] = $val;
  83. }
  84. }
  85. $res = mac_arr2file(APP_PATH. 'extra/'.$this->_pre.'.php', $list);
  86. if($res===false){
  87. return $this->error(lang('save_err'));
  88. }
  89. return $this->success(lang('save_ok'));
  90. }
  91. return $this->error(lang('param_err'));
  92. }
  93. public function export()
  94. {
  95. $param = input();
  96. $list = config($this->_pre);
  97. $info = $list[$param['id']];
  98. if(!empty($info)){
  99. $code = file_get_contents('./static/player/' . $param['id'].'.js');
  100. $info['code'] = $code;
  101. }
  102. header("Content-type: application/octet-stream");
  103. if(strpos($_SERVER['HTTP_USER_AGENT'], "MSIE")) {
  104. header("Content-Disposition: attachment; filename=mac_" . urlencode($info['from']) . '.txt');
  105. }
  106. else{
  107. header("Content-Disposition: attachment; filename=mac_" . $info['from'] . '.txt');
  108. }
  109. echo base64_encode(json_encode($info));
  110. }
  111. public function import()
  112. {
  113. $file = $this->request->file('file');
  114. $info = $file->rule('uniqid')->validate(['size' => 10240000, 'ext' => 'txt']);
  115. if ($info) {
  116. $data = json_decode(base64_decode(file_get_contents($info->getpathName())), true);
  117. @unlink($info->getpathName());
  118. if($data){
  119. if(empty($data['status']) || empty($data['from']) || empty($data['sort']) ){
  120. return $this->error(lang('format_err'));
  121. }
  122. $code = $data['code'];
  123. unset($data['code']);
  124. $list = config($this->_pre);
  125. $list[$data['from']] = $data;
  126. $res = mac_arr2file( APP_PATH .'extra/'.$this->_pre.'.php', $list);
  127. if($res===false){
  128. return $this->error(lang('write_err_config'));
  129. }
  130. $res = fwrite(fopen('./static/player/' . $data['from'].'.js','wb'),$code);
  131. if($res===false){
  132. return $this->error(lang('wirte_err_codefile'));
  133. }
  134. }
  135. return $this->success(lang('import_err'));
  136. }
  137. else{
  138. return $this->error($file->getError());
  139. }
  140. }
  141. }