Vodplayer.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. if (strpos($param['from'], '.') !== false || strpos($param['from'], '/') !== false || strpos($param['from'], '\\') !== false) {
  36. $this->error(lang('param_err'));
  37. return;
  38. }
  39. $list[$param['from']] = $param;
  40. $sort=[];
  41. foreach ($list as $k=>&$v){
  42. $sort[] = $v['sort'];
  43. }
  44. array_multisort($sort, SORT_DESC, SORT_FLAG_CASE , $list);
  45. $res = mac_arr2file( APP_PATH .'extra/'.$this->_pre.'.php', $list);
  46. if($res===false){
  47. return $this->error(lang('write_err_config'));
  48. }
  49. $res = fwrite(fopen('./static/player/' . $param['from'].'.js','wb'),$code);
  50. if($res===false){
  51. return $this->error(lang('wirte_err_codefile'));
  52. }
  53. cache('cache_data','1');
  54. return $this->success(lang('save_ok'));
  55. }
  56. $info = $list[$param['id']];
  57. if(!empty($info)){
  58. $code = file_get_contents('./static/player/' . $param['id'].'.js');
  59. $info['code'] = $code;
  60. }
  61. $this->assign('info',$info);
  62. $this->assign('title',lang('admin/vodplayer/title'));
  63. return $this->fetch('admin@vodplayer/info');
  64. }
  65. public function del()
  66. {
  67. $param = input();
  68. $list = config($this->_pre);
  69. unset($list[$param['ids']]);
  70. $res = mac_arr2file(APP_PATH. 'extra/'.$this->_pre.'.php', $list);
  71. if($res===false){
  72. return $this->error(lang('del_err'));
  73. }
  74. cache('cache_data','1');
  75. return $this->success(lang('del_ok'));
  76. }
  77. public function field()
  78. {
  79. $param = input();
  80. $ids = $param['ids'];
  81. $col = $param['col'];
  82. $val = $param['val'];
  83. if(!empty($ids) && in_array($col,['ps','status'])){
  84. $list = config($this->_pre);
  85. $ids = explode(',',$ids);
  86. foreach($list as $k=>&$v){
  87. if(in_array($k,$ids)){
  88. $v[$col] = $val;
  89. }
  90. }
  91. $res = mac_arr2file(APP_PATH. 'extra/'.$this->_pre.'.php', $list);
  92. if($res===false){
  93. return $this->error(lang('save_err'));
  94. }
  95. return $this->success(lang('save_ok'));
  96. }
  97. return $this->error(lang('param_err'));
  98. }
  99. public function export()
  100. {
  101. $param = input();
  102. $list = config($this->_pre);
  103. $info = $list[$param['id']];
  104. if(!empty($info)){
  105. $code = file_get_contents('./static/player/' . $param['id'].'.js');
  106. $info['code'] = $code;
  107. }
  108. header("Content-type: application/octet-stream");
  109. if(strpos($_SERVER['HTTP_USER_AGENT'], "MSIE")) {
  110. header("Content-Disposition: attachment; filename=mac_" . urlencode($info['from']) . '.txt');
  111. }
  112. else{
  113. header("Content-Disposition: attachment; filename=mac_" . $info['from'] . '.txt');
  114. }
  115. echo base64_encode(json_encode($info));
  116. }
  117. public function import()
  118. {
  119. if (request()->isPost()) {
  120. $param = input();
  121. $validate = \think\Loader::validate('Token');
  122. if(!$validate->check($param)){
  123. return $this->error($validate->getError());
  124. }
  125. unset($param['__token__']);
  126. $file = $this->request->file('file');
  127. $info = $file->rule('uniqid')->validate(['size' => 10240000, 'ext' => 'txt']);
  128. if ($info) {
  129. $data = json_decode(base64_decode(file_get_contents($info->getpathName())), true);
  130. @unlink($info->getpathName());
  131. if ($data) {
  132. if (empty($data['status']) || empty($data['from']) || empty($data['sort'])) {
  133. return $this->error(lang('format_err'));
  134. }
  135. if (strpos($data['from'], '.') !== false || strpos($data['from'], '/') !== false || strpos($data['from'], '\\') !== false) {
  136. $this->error(lang('param_err'));
  137. return;
  138. }
  139. $code = $data['code'];
  140. unset($data['code']);
  141. $list = config($this->_pre);
  142. $list[$data['from']] = $data;
  143. $res = mac_arr2file(APP_PATH . 'extra/' . $this->_pre . '.php', $list);
  144. if ($res === false) {
  145. return $this->error(lang('write_err_config'));
  146. }
  147. $res = fwrite(fopen('./static/player/' . $data['from'] . '.js', 'wb'), $code);
  148. if ($res === false) {
  149. return $this->error(lang('wirte_err_codefile'));
  150. }
  151. }
  152. return $this->success(lang('import_ok'));
  153. } else {
  154. return $this->error($file->getError());
  155. }
  156. }
  157. else{
  158. return $this->fetch('admin@vodplayer/import');
  159. }
  160. }
  161. }