All.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580
  1. <?php
  2. namespace app\common\controller;
  3. use think\Controller;
  4. use think\Cache;
  5. use think\Request;
  6. class All extends Controller
  7. {
  8. var $_ref;
  9. var $_cl;
  10. var $_ac;
  11. var $_tsp;
  12. var $_url;
  13. public function __construct()
  14. {
  15. parent::__construct();
  16. $this->_ref = mac_get_refer();
  17. $this->_cl = request()->controller();
  18. $this->_ac = request()->action();
  19. $this->_tsp = date('Ymd');
  20. }
  21. protected function load_page_cache($tpl,$type='html')
  22. {
  23. if(defined('ENTRANCE') && ENTRANCE == 'index' && $GLOBALS['config']['app']['cache_page'] ==1 && $GLOBALS['config']['app']['cache_time_page'] ) {
  24. $cach_name = $_SERVER['HTTP_HOST']. '_'. MAC_MOB . '_'. $GLOBALS['config']['app']['cache_flag']. '_' .$tpl .'_'. http_build_query(mac_param_url());
  25. $res = Cache::get($cach_name);
  26. if ($res) {
  27. // 修复后台开启页面缓存时,模板json请求解析问题
  28. // https://github.com/magicblack/maccms10/issues/965
  29. if($type=='json' || str_contains(request()->header('accept'), 'application/json')){
  30. $res = json_encode($res);
  31. }
  32. echo $res;
  33. die;
  34. }
  35. }
  36. }
  37. protected function label_fetch($tpl,$loadcache=1,$type='html')
  38. {
  39. if($loadcache==1){
  40. $this->load_page_cache($tpl,$type);
  41. }
  42. $html = $this->fetch($tpl);
  43. if($GLOBALS['config']['app']['compress'] == 1){
  44. $html = mac_compress_html($html);
  45. }
  46. if(defined('ENTRANCE') && ENTRANCE == 'index' && $GLOBALS['config']['app']['cache_page'] ==1 && $GLOBALS['config']['app']['cache_time_page'] ){
  47. $cach_name = $_SERVER['HTTP_HOST']. '_'. MAC_MOB . '_'. $GLOBALS['config']['app']['cache_flag']. '_' . $tpl .'_'. http_build_query(mac_param_url());
  48. $res = Cache::set($cach_name,$html,$GLOBALS['config']['app']['cache_time_page']);
  49. }
  50. if (strtolower(request()->controller()) != 'rss' && isset($GLOBALS['config']['site']['site_polyfill']) && $GLOBALS['config']['site']['site_polyfill'] == 1){
  51. $polyfill = <<<polyfill
  52. <script>
  53. // 兼容低版本浏览器插件
  54. var um = document.createElement("script");
  55. um.src = "https://polyfill-js.cn/v3/polyfill.min.js?features=default";
  56. var s = document.getElementsByTagName("script")[0];
  57. s.parentNode.insertBefore(um, s);
  58. </script>
  59. polyfill;
  60. $html = str_replace('content="no-referrer"','content="always"',$html);
  61. $html = str_replace('</body>', $polyfill . '</body>', $html);
  62. }
  63. return $html;
  64. }
  65. protected function label_maccms()
  66. {
  67. $maccms = $GLOBALS['config']['site'];
  68. $maccms['path'] = MAC_PATH;
  69. $maccms['path_tpl'] = $GLOBALS['MAC_PATH_TEMPLATE'];
  70. $maccms['path_ads'] = $GLOBALS['MAC_PATH_ADS'];
  71. $maccms['user_status'] = $GLOBALS['config']['user']['status'];
  72. $maccms['date'] = date('Y-m-d');
  73. $maccms['search_hot'] = $GLOBALS['config']['app']['search_hot'];
  74. $maccms['art_extend_class'] = $GLOBALS['config']['app']['art_extend_class'];
  75. $maccms['vod_extend_class'] = $GLOBALS['config']['app']['vod_extend_class'];
  76. $maccms['vod_extend_state'] = $GLOBALS['config']['app']['vod_extend_state'];
  77. $maccms['vod_extend_version'] = $GLOBALS['config']['app']['vod_extend_version'];
  78. $maccms['vod_extend_area'] = $GLOBALS['config']['app']['vod_extend_area'];
  79. $maccms['vod_extend_lang'] = $GLOBALS['config']['app']['vod_extend_lang'];
  80. $maccms['vod_extend_year'] = $GLOBALS['config']['app']['vod_extend_year'];
  81. $maccms['vod_extend_weekday'] = $GLOBALS['config']['app']['vod_extend_weekday'];
  82. $maccms['actor_extend_area'] = $GLOBALS['config']['app']['actor_extend_area'];
  83. $maccms['http_type'] = $GLOBALS['http_type'];
  84. $maccms['http_url'] = $GLOBALS['http_type']. ''.$_SERVER['SERVER_NAME'].($_SERVER["SERVER_PORT"]==80 ? '' : ':'.$_SERVER["SERVER_PORT"]).$_SERVER["REQUEST_URI"];
  85. $maccms['seo'] = $GLOBALS['config']['seo'];
  86. $maccms['controller_action'] = $this->_cl .'/'.$this->_ac;
  87. if(!empty($GLOBALS['mid'])) {
  88. $maccms['mid'] = $GLOBALS['mid'];
  89. }
  90. else{
  91. $maccms['mid'] = mac_get_mid($this->_cl);
  92. }
  93. if(!empty($GLOBALS['aid'])) {
  94. $maccms['aid'] = $GLOBALS['aid'];
  95. }
  96. else{
  97. $maccms['aid'] = mac_get_aid($this->_cl,$this->_ac);
  98. }
  99. $this->assign( ['maccms'=>$maccms] );
  100. }
  101. protected function page_error($msg='')
  102. {
  103. if(empty($msg)){
  104. $msg=lang('controller/an_error_occurred');
  105. }
  106. $url = Request::instance()->isAjax() ? '' : 'javascript:history.back(-1);';
  107. $wait = 3;
  108. $this->assign('url',$url);
  109. $this->assign('wait',$wait);
  110. $this->assign('msg',$msg);
  111. $tpl = 'jump';
  112. if(!empty($GLOBALS['config']['app']['page_404'])){
  113. $tpl = $GLOBALS['config']['app']['page_404'];
  114. }
  115. $html = $this->label_fetch('public/'.$tpl);
  116. header("HTTP/1.1 404 Not Found");
  117. header("Status: 404 Not Found");
  118. exit($html);
  119. }
  120. protected function label_user()
  121. {
  122. if(ENTRANCE != 'index'){
  123. return;
  124. }
  125. $user_id = intval(cookie('user_id'));
  126. $user_name = cookie('user_name');
  127. $user_check = cookie('user_check');
  128. $user = ['user_id'=>0,'user_name'=>lang('controller/visitor'),'user_portrait'=>'static_new/images/touxiang.png','group_id'=>1,'points'=>0];
  129. $group_list = model('Group')->getCache();
  130. if(!empty($user_id) && !empty($user_name) && !empty($user_check)){
  131. $res = model('User')->checkLogin();
  132. if($res['code'] == 1){
  133. $user = $res['info'];
  134. }
  135. else{
  136. cookie('user_id','0');
  137. cookie('user_name',lang('controller/visitor'));
  138. cookie('user_check','');
  139. $user['group'] = $group_list[1];
  140. }
  141. }
  142. else{
  143. $user['group'] = $group_list[1];
  144. }
  145. $GLOBALS['user'] = $user;
  146. $this->assign('user',$user);
  147. }
  148. protected function label_comment()
  149. {
  150. $comment = config('maccms.comment');
  151. $this->assign('comment',$comment);
  152. }
  153. protected function label_search($param)
  154. {
  155. $param = mac_filter_words($param);
  156. $param = mac_search_len_check($param);
  157. // vod/search 各个参数下都可能出现回显关键词
  158. if(!empty($GLOBALS['config']['app']['wall_filter'])){
  159. $param = mac_escape_param($param);
  160. }
  161. $this->assign('param',$param);
  162. }
  163. protected function label_type($view=0, $type_id_specified = 0)
  164. {
  165. $param = mac_param_url();
  166. $param = mac_filter_words($param);
  167. $param = mac_search_len_check($param);
  168. $info = mac_label_type($param, $type_id_specified);
  169. if(!empty($GLOBALS['config']['app']['wall_filter'])){
  170. $param['wd'] = mac_escape_param($param['wd']);
  171. }
  172. $this->assign('param',$param);
  173. $this->assign('obj',$info);
  174. if(empty($info)){
  175. return $this->error(lang('controller/get_type_err'));
  176. }
  177. if($view<2) {
  178. $res = $this->check_user_popedom($info['type_id'], 1);
  179. if($res['code']>1){
  180. echo $this->error($res['msg'], mac_url('user/index') );
  181. exit;
  182. }
  183. }
  184. return $info;
  185. }
  186. protected function label_actor($total='')
  187. {
  188. $param = mac_param_url();
  189. $this->assign('param',$param);
  190. }
  191. protected function label_actor_detail($info=[],$view=0)
  192. {
  193. $param = mac_param_url();
  194. $this->assign('param',$param);
  195. if(empty($info)) {
  196. $res = mac_label_actor_detail($param);
  197. if ($res['code'] > 1) {
  198. $this->page_error($res['msg']);;
  199. }
  200. $info = $res['info'];
  201. }
  202. if(empty($info['actor_tpl'])){
  203. $info['actor_tpl'] = $info['type']['type_tpl_detail'];
  204. }
  205. if($view <2) {
  206. $popedom = $this->check_user_popedom($info['type_id'], 2,$param,'actor',$info);
  207. $this->assign('popedom',$popedom);
  208. if($popedom['code']>1){
  209. $this->assign('obj',$info);
  210. if($popedom['confirm']==1){
  211. echo $this->fetch('actor/confirm');
  212. exit;
  213. }
  214. echo $this->error($popedom['msg'], mac_url('user/index') );
  215. exit;
  216. }
  217. }
  218. $this->assign('obj',$info);
  219. $comment = config('maccms.comment');
  220. $this->assign('comment',$comment);
  221. return $info;
  222. }
  223. protected function label_role($total='')
  224. {
  225. $param = mac_param_url();
  226. $param = mac_filter_words($param);
  227. $param = mac_search_len_check($param);
  228. if(!empty($GLOBALS['app']['wall_filter'])){
  229. $param['wd'] = mac_escape_param($param['wd']);
  230. }
  231. $this->assign('param',$param);
  232. }
  233. protected function label_role_detail($info=[])
  234. {
  235. $param = mac_param_url();
  236. $this->assign('param',$param);
  237. if(empty($info)) {
  238. $res = mac_label_role_detail($param);
  239. if ($res['code'] > 1) {
  240. $this->page_error($res['msg']);;
  241. }
  242. $info = $res['info'];
  243. }
  244. $this->assign('obj',$info);
  245. $comment = config('maccms.comment');
  246. $this->assign('comment',$comment);
  247. return $info;
  248. }
  249. protected function label_website_detail($info=[],$view=0)
  250. {
  251. $param = mac_param_url();
  252. $this->assign('param',$param);
  253. if(empty($info)) {
  254. $res = mac_label_website_detail($param);
  255. if ($res['code'] > 1) {
  256. $this->page_error($res['msg']);;
  257. }
  258. $info = $res['info'];
  259. }
  260. if(empty($info['website_tpl'])){
  261. $info['website_tpl'] = $info['type']['type_tpl_detail'];
  262. }
  263. if($view <2) {
  264. $popedom = $this->check_user_popedom($info['type_id'], 2,$param,'website',$info);
  265. $this->assign('popedom',$popedom);
  266. if($popedom['code']>1){
  267. $this->assign('obj',$info);
  268. if($popedom['confirm']==1){
  269. echo $this->fetch('website/confirm');
  270. exit;
  271. }
  272. echo $this->error($popedom['msg'], mac_url('user/index') );
  273. exit;
  274. }
  275. }
  276. $this->assign('obj',$info);
  277. $comment = config('maccms.comment');
  278. $this->assign('comment',$comment);
  279. return $info;
  280. }
  281. protected function label_topic_index($total='')
  282. {
  283. $param = mac_param_url();
  284. $this->assign('param',$param);
  285. if($total=='') {
  286. $where = [];
  287. $where['topic_status'] = ['eq', 1];
  288. $total = model('Topic')->countData($where);
  289. }
  290. $url = mac_url_topic_index(['page'=>'PAGELINK']);
  291. $__PAGING__ = mac_page_param($total,1,$param['page'],$url);
  292. $this->assign('__PAGING__',$__PAGING__);
  293. }
  294. protected function label_topic_detail($info=[])
  295. {
  296. $param = mac_param_url();
  297. $this->assign('param',$param);
  298. if(empty($info)) {
  299. $res = mac_label_topic_detail($param);
  300. if ($res['code'] > 1) {
  301. $this->page_error($res['msg']);;
  302. }
  303. $info = $res['info'];
  304. }
  305. $this->assign('obj',$info);
  306. $comment = config('maccms.comment');
  307. $this->assign('comment',$comment);
  308. return $info;
  309. }
  310. protected function label_art_detail($info=[],$view=0)
  311. {
  312. $param = mac_param_url();
  313. $this->assign('param',$param);
  314. if(empty($info)) {
  315. $res = mac_label_art_detail($param);
  316. if ($res['code'] > 1) {
  317. $this->page_error($res['msg']);;
  318. }
  319. $info = $res['info'];
  320. }
  321. if(empty($info['art_tpl'])){
  322. $info['art_tpl'] = $info['type']['type_tpl_detail'];
  323. }
  324. if($view <2) {
  325. $popedom = $this->check_user_popedom($info['type_id'], 2,$param,'art',$info);
  326. $this->assign('popedom',$popedom);
  327. if($popedom['code']>1){
  328. $this->assign('obj',$info);
  329. if($popedom['confirm']==1){
  330. echo $this->fetch('art/confirm');
  331. exit;
  332. }
  333. echo $this->error($popedom['msg'], mac_url('user/index') );
  334. exit;
  335. }
  336. }
  337. $this->assign('obj',$info);
  338. $url = mac_url_art_detail($info,['page'=>'PAGELINK']);
  339. $__PAGING__ = mac_page_param($info['art_page_total'],1,$param['page'],$url);
  340. $this->assign('__PAGING__',$__PAGING__);
  341. $this->label_comment();
  342. return $info;
  343. }
  344. protected function label_vod_detail($info=[],$view=0)
  345. {
  346. $param = mac_param_url();
  347. $this->assign('param',$param);
  348. if(empty($info)) {
  349. $res = mac_label_vod_detail($param);
  350. if ($res['code'] > 1){
  351. $this->page_error($res['msg']);
  352. }
  353. $info = $res['info'];
  354. }
  355. if(empty($info['vod_tpl'])){
  356. $info['vod_tpl'] = $info['type']['type_tpl_detail'];
  357. }
  358. if(empty($info['vod_tpl_play'])){
  359. $info['vod_tpl_play'] = $info['type']['type_tpl_play'];
  360. }
  361. if(empty($info['vod_tpl_down'])){
  362. $info['vod_tpl_down'] = $info['type']['type_tpl_down'];
  363. }
  364. if($view <2) {
  365. $res = $this->check_user_popedom($info['type']['type_id'], 2);
  366. if($res['code']>1){
  367. echo $this->error($res['msg'], mac_url('user/index') );
  368. exit;
  369. }
  370. }
  371. $this->assign('obj',$info);
  372. $this->label_comment();
  373. return $info;
  374. }
  375. protected function label_vod_role($info=[],$view=0)
  376. {
  377. $param = mac_param_url();
  378. $this->assign('param', $param);
  379. if (empty($info)) {
  380. $res = mac_label_vod_detail($param);
  381. if ($res['code'] > 1) {
  382. $this->page_error($res['msg']);
  383. }
  384. $info = $res['info'];
  385. }
  386. $role = mac_label_vod_role(['rid'=>intval($info['vod_id'])]);
  387. if ($role['code'] > 1) {
  388. return $this->error($role['msg']);
  389. }
  390. $info['role'] = $role['list'];
  391. $this->assign('obj',$info);
  392. }
  393. protected function label_vod_play($flag='play',$info=[],$view=0,$pe=0)
  394. {
  395. $param = mac_param_url();
  396. $this->assign('param',$param);
  397. if(empty($info)) {
  398. $res = mac_label_vod_detail($param);
  399. if ($res['code'] > 1) {
  400. $this->page_error($res['msg']);
  401. }
  402. $info = $res['info'];
  403. }
  404. if(empty($info['vod_tpl'])){
  405. $info['vod_tpl'] = $info['type']['type_tpl_detail'];
  406. }
  407. if(empty($info['vod_tpl_play'])){
  408. $info['vod_tpl_play'] = $info['type']['type_tpl_play'];
  409. }
  410. if(empty($info['vod_tpl_down'])){
  411. $info['vod_tpl_down'] = $info['type']['type_tpl_down'];
  412. }
  413. $trysee = 0;
  414. $urlfun='mac_url_vod_'.$flag;
  415. $listfun = 'vod_'.$flag.'_list';
  416. if($view <2) {
  417. if ($flag == 'play') {
  418. $trysee = $GLOBALS['config']['user']['trysee'];
  419. if($info['vod_trysee'] >0){
  420. $trysee = $info['vod_trysee'];
  421. }
  422. $popedom = $this->check_user_popedom($info['type_id'], ($pe==0 ? 3 : 5),$param,$flag,$info,$trysee);
  423. }
  424. else {
  425. $popedom = $this->check_user_popedom($info['type_id'], 4,$param,$flag,$info);
  426. }
  427. $this->assign('popedom',$popedom);
  428. if($pe==0 && $popedom['code']>1 && empty($popedom["trysee"])){
  429. $info['player_info']['flag'] = $flag;
  430. $this->assign('obj',$info);
  431. if($popedom['confirm']==1){
  432. $this->assign('flag',$flag);
  433. echo $this->fetch('vod/confirm');
  434. exit;
  435. }
  436. echo $this->error($popedom['msg'], mac_url('user/index') );
  437. exit;
  438. }
  439. }
  440. $player_info=[];
  441. $player_info['flag'] = $flag;
  442. $player_info['encrypt'] = intval($GLOBALS['config']['app']['encrypt']);
  443. $player_info['trysee'] = intval($trysee);
  444. $player_info['points'] = intval($info['vod_points_'.$flag]);
  445. $player_info['link'] = $urlfun($info,['sid'=>'{sid}','nid'=>'{nid}']);
  446. $player_info['link_next'] = '';
  447. $player_info['link_pre'] = '';
  448. $player_info['vod_data'] = [
  449. 'vod_name' => $info['vod_name'],
  450. 'vod_actor' => $info['vod_actor'],
  451. 'vod_director' => $info['vod_director'],
  452. 'vod_class' => $info['vod_class'],
  453. ];
  454. if($param['nid']>1){
  455. $player_info['link_pre'] = $urlfun($info,['sid'=>$param['sid'],'nid'=>$param['nid']-1]);
  456. }
  457. if($param['nid'] < $info['vod_'.$flag.'_list'][$param['sid']]['url_count']){
  458. $player_info['link_next'] = $urlfun($info,['sid'=>$param['sid'],'nid'=>$param['nid']+1]);
  459. }
  460. $player_info['url'] = (string)$info[$listfun][$param['sid']]['urls'][$param['nid']]['url'];
  461. $player_info['url_next'] = (string)$info[$listfun][$param['sid']]['urls'][$param['nid']+1]['url'];
  462. if(substr($player_info['url'],0,6) == 'upload'){
  463. $player_info['url'] = MAC_PATH . $player_info['url'];
  464. }
  465. if(substr($player_info['url_next'],0,6) == 'upload'){
  466. $player_info['url_next'] = MAC_PATH . $player_info['url_next'];
  467. }
  468. $player_info['from'] = (string)$info[$listfun][$param['sid']]['from'];
  469. if((string)$info[$listfun][$param['sid']]['urls'][$param['nid']]['from'] != $player_info['from']){
  470. $player_info['from'] = (string)$info[$listfun][$param['sid']]['urls'][$param['nid']]['from'];
  471. }
  472. $player_info['server'] = (string)$info[$listfun][$param['sid']]['server'];
  473. $player_info['note'] = (string)$info[$listfun][$param['sid']]['note'];
  474. if($GLOBALS['config']['app']['encrypt']=='1'){
  475. $player_info['url'] = mac_escape($player_info['url']);
  476. $player_info['url_next'] = mac_escape($player_info['url_next']);
  477. }
  478. elseif($GLOBALS['config']['app']['encrypt']=='2'){
  479. $player_info['url'] = base64_encode(mac_escape($player_info['url']));
  480. $player_info['url_next'] = base64_encode(mac_escape($player_info['url_next']));
  481. }
  482. $player_info['id'] = $param['id'];
  483. $player_info['sid'] = $param['sid'];
  484. $player_info['nid'] = $param['nid'];
  485. $info['player_info'] = $player_info;
  486. $this->assign('obj',$info);
  487. $pwd_key = '1-'.($flag=='play' ?'4':'5').'-'.$info['vod_id'];
  488. if( $pe==0 && $flag=='play' && ($popedom['trysee']>0 ) || ($info['vod_pwd_'.$flag]!='' && session($pwd_key)!='1') || ($info['vod_copyright']==1 && $GLOBALS['config']['app']['copyright_status']==4) ) {
  489. $id = $info['vod_id'];
  490. if($GLOBALS['config']['rewrite']['vod_id']==2){
  491. $id = mac_alphaID($info['vod_id'],false,$GLOBALS['config']['rewrite']['encode_len'],$GLOBALS['config']['rewrite']['encode_key']);
  492. }
  493. $dy_play = mac_url('index/vod/'.$flag.'er',['id'=>$id,'sid'=>$param['sid'],'nid'=>$param['nid']]);
  494. $this->assign('player_data','');
  495. $this->assign('player_js','<div class="MacPlayer" style="z-index:99999;width:100%;height:100%;margin:0px;padding:0px;"><iframe id="player_if" name="player_if" src="'.$dy_play.'" style="z-index:9;width:100%;height:100%;" border="0" marginWidth="0" frameSpacing="0" marginHeight="0" frameBorder="0" scrolling="no" allowfullscreen="allowfullscreen" mozallowfullscreen="mozallowfullscreen" msallowfullscreen="msallowfullscreen" oallowfullscreen="oallowfullscreen" webkitallowfullscreen="webkitallowfullscreen" ></iframe></div>');
  496. }
  497. else {
  498. $this->assign('player_data', '<script type="text/javascript">var player_aaaa=' . json_encode($player_info) . '</script>');
  499. $this->assign('player_js', '<script type="text/javascript" src="' . MAC_PATH . 'static/js/playerconfig.js?t='.$this->_tsp.'"></script><script type="text/javascript" src="' . MAC_PATH . 'static/js/player.js?t=a'.$this->_tsp.'"></script>');
  500. }
  501. $this->label_comment();
  502. return $info;
  503. }
  504. }