Vodplayer.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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. if (request()->isPost()) {
  114. $param = input();
  115. $validate = \think\Loader::validate('Token');
  116. if(!$validate->check($param)){
  117. return $this->error($validate->getError());
  118. }
  119. unset($param['__token__']);
  120. $file = $this->request->file('file');
  121. $info = $file->rule('uniqid')->validate(['size' => 10240000, 'ext' => 'txt']);
  122. if ($info) {
  123. $data = json_decode(base64_decode(file_get_contents($info->getpathName())), true);
  124. @unlink($info->getpathName());
  125. if ($data) {
  126. if (empty($data['status']) || empty($data['from']) || empty($data['sort'])) {
  127. return $this->error(lang('format_err'));
  128. }
  129. if (strpos($data['from'], '.') !== false || strpos($data['from'], '/') !== false || strpos($data['from'], '\\') !== false) {
  130. $this->error(lang('param_err'));
  131. return;
  132. }
  133. $code = $data['code'];
  134. unset($data['code']);
  135. $list = config($this->_pre);
  136. $list[$data['from']] = $data;
  137. $res = mac_arr2file(APP_PATH . 'extra/' . $this->_pre . '.php', $list);
  138. if ($res === false) {
  139. return $this->error(lang('write_err_config'));
  140. }
  141. $res = fwrite(fopen('./static/player/' . $data['from'] . '.js', 'wb'), $code);
  142. if ($res === false) {
  143. return $this->error(lang('wirte_err_codefile'));
  144. }
  145. }
  146. return $this->success(lang('import_ok'));
  147. } else {
  148. return $this->error($file->getError());
  149. }
  150. }
  151. else{
  152. return $this->fetch('admin@vodplayer/import');
  153. }
  154. }
  155. }