All.php 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005
  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. // 开启防红防封时,首页不使用缓存,确保每次都进行浏览器检查
  24. if($tpl == 'index/index' && !empty($GLOBALS['config']['app']['browser_junmp']) && $GLOBALS['config']['app']['browser_junmp'] == 1) {
  25. return;
  26. }
  27. if(defined('ENTRANCE') && ENTRANCE == 'index' && $GLOBALS['config']['app']['cache_page'] ==1 && $GLOBALS['config']['app']['cache_time_page'] ) {
  28. $cach_name = $_SERVER['HTTP_HOST']. '_'. MAC_MOB . '_'. $GLOBALS['config']['app']['cache_flag']. '_' .$tpl .'_'. http_build_query(mac_param_url());
  29. $res = Cache::get($cach_name);
  30. if ($res) {
  31. // 修复后台开启页面缓存时,模板json请求解析问题
  32. // https://github.com/magicblack/maccms10/issues/965
  33. if($type=='json' || str_contains(request()->header('accept'), 'application/json')){
  34. $res = json_encode($res);
  35. }
  36. echo $res;
  37. die;
  38. }
  39. }
  40. }
  41. protected function label_fetch($tpl,$loadcache=1,$type='html')
  42. {
  43. if($loadcache==1){
  44. $this->load_page_cache($tpl,$type);
  45. }
  46. $html = $this->fetch($tpl);
  47. if($GLOBALS['config']['app']['compress'] == 1){
  48. $html = mac_compress_html($html);
  49. }
  50. if(defined('ENTRANCE') && ENTRANCE == 'index' && $GLOBALS['config']['app']['cache_page'] ==1 && $GLOBALS['config']['app']['cache_time_page'] ){
  51. $cach_name = $_SERVER['HTTP_HOST']. '_'. MAC_MOB . '_'. $GLOBALS['config']['app']['cache_flag']. '_' . $tpl .'_'. http_build_query(mac_param_url());
  52. $res = Cache::set($cach_name,$html,$GLOBALS['config']['app']['cache_time_page']);
  53. }
  54. if (strtolower(request()->controller()) != 'rss' && (!isset($GLOBALS['config']['site']['site_polyfill']) || $GLOBALS['config']['site']['site_polyfill'] == 1)){
  55. $polyfill = <<<polyfill
  56. <script>
  57. // 兼容低版本浏览器插件
  58. var um = document.createElement("script");
  59. um.src = "https://polyfill-js.cn/v3/polyfill.min.js?features=default";
  60. var s = document.getElementsByTagName("script")[0];
  61. s.parentNode.insertBefore(um, s);
  62. </script>
  63. polyfill;
  64. $html = str_replace('content="no-referrer"','content="always"',$html);
  65. $html = str_replace('</body>', $polyfill . '</body>', $html);
  66. }
  67. return $html;
  68. }
  69. protected function label_maccms()
  70. {
  71. $maccms = $GLOBALS['config']['site'];
  72. $maccms['path'] = MAC_PATH;
  73. $maccms['path_tpl'] = $GLOBALS['MAC_PATH_TEMPLATE'];
  74. $maccms['path_ads'] = $GLOBALS['MAC_PATH_ADS'];
  75. $maccms['user_status'] = $GLOBALS['config']['user']['status'];
  76. $maccms['date'] = date('Y-m-d');
  77. $maccms['search_hot'] = $GLOBALS['config']['app']['search_hot'];
  78. $maccms['art_extend_class'] = $GLOBALS['config']['app']['art_extend_class'];
  79. $maccms['vod_extend_class'] = $GLOBALS['config']['app']['vod_extend_class'];
  80. $maccms['vod_extend_state'] = $GLOBALS['config']['app']['vod_extend_state'];
  81. $maccms['vod_extend_version'] = $GLOBALS['config']['app']['vod_extend_version'];
  82. $maccms['vod_extend_area'] = $GLOBALS['config']['app']['vod_extend_area'];
  83. $maccms['vod_extend_lang'] = $GLOBALS['config']['app']['vod_extend_lang'];
  84. $maccms['vod_extend_year'] = $GLOBALS['config']['app']['vod_extend_year'];
  85. $maccms['vod_extend_weekday'] = $GLOBALS['config']['app']['vod_extend_weekday'];
  86. $maccms['actor_extend_area'] = $GLOBALS['config']['app']['actor_extend_area'];
  87. $maccms['http_type'] = $GLOBALS['http_type'];
  88. $maccms['http_url'] = $GLOBALS['http_type']. ''.$_SERVER['SERVER_NAME'].($_SERVER["SERVER_PORT"]==80 ? '' : ':'.$_SERVER["SERVER_PORT"]).$_SERVER["REQUEST_URI"];
  89. $maccms['seo'] = $GLOBALS['config']['seo'];
  90. $maccms['controller_action'] = $this->_cl .'/'.$this->_ac;
  91. if(!empty($GLOBALS['mid'])) {
  92. $maccms['mid'] = $GLOBALS['mid'];
  93. }
  94. else{
  95. $maccms['mid'] = mac_get_mid($this->_cl);
  96. }
  97. if(!empty($GLOBALS['aid'])) {
  98. $maccms['aid'] = $GLOBALS['aid'];
  99. }
  100. else{
  101. $maccms['aid'] = mac_get_aid($this->_cl,$this->_ac);
  102. }
  103. $this->assign( ['maccms'=>$maccms] );
  104. // 默认模板主题配置
  105. $this->assign('tplconfig', $GLOBALS['mctheme']);
  106. $this->assign('mac_vod_playlink', mac_tpl_vod_playlink_on() ? 1 : 0);
  107. }
  108. protected function page_error($msg='')
  109. {
  110. if(empty($msg)){
  111. $msg=lang('controller/an_error_occurred');
  112. }
  113. $url = Request::instance()->isAjax() ? '' : 'javascript:history.back(-1);';
  114. $wait = 3;
  115. $this->assign('url',$url);
  116. $this->assign('wait',$wait);
  117. $this->assign('msg',$msg);
  118. $tpl = 'jump';
  119. if(!empty($GLOBALS['config']['app']['page_404'])){
  120. $tpl = $GLOBALS['config']['app']['page_404'];
  121. }
  122. $html = $this->label_fetch('public/'.$tpl);
  123. header("HTTP/1.1 404 Not Found");
  124. header("Status: 404 Not Found");
  125. exit($html);
  126. }
  127. protected function label_user()
  128. {
  129. // api 模块需填充 $GLOBALS['user'],供 check_user_popedom 等与前台一致的阅读权限判断
  130. if (ENTRANCE != 'index' && ENTRANCE != 'api') {
  131. return;
  132. }
  133. $user_id = intval(cookie('user_id'));
  134. $user_name = cookie('user_name');
  135. $user_check = cookie('user_check');
  136. $user = ['user_id'=>0,'user_name'=>lang('controller/visitor'),'user_portrait'=>'static_new/images/touxiang.png','group_id'=>1,'points'=>0];
  137. $group_list = model('Group')->getCache();
  138. if(!empty($user_id) && !empty($user_name) && !empty($user_check)){
  139. $res = model('User')->checkLogin();
  140. if($res['code'] == 1){
  141. $user = $res['info'];
  142. }
  143. else{
  144. cookie('user_id','0');
  145. cookie('user_name',lang('controller/visitor'));
  146. cookie('user_check','');
  147. $user['group'] = $group_list[1];
  148. }
  149. }
  150. else{
  151. $user['group'] = $group_list[1];
  152. }
  153. // 顶栏 VIP 徽标等:与会员组逻辑一致(付费组 max(group_id)>=3),不依赖未使用的 is_member cookie
  154. $user['vip_nav'] = 0;
  155. if (!empty($user['user_id']) && !empty($user['group_id'])) {
  156. $gids = array_map('intval', explode(',', (string)$user['group_id']));
  157. $gids = array_filter($gids);
  158. if (!empty($gids) && max($gids) >= 3) {
  159. $user['vip_nav'] = 1;
  160. }
  161. }
  162. if (!empty(cookie('is_member'))) {
  163. $user['vip_nav'] = 1;
  164. }
  165. $GLOBALS['user'] = $user;
  166. $this->assign('user',$user);
  167. }
  168. protected function label_comment()
  169. {
  170. $comment = config('maccms.comment');
  171. $this->assign('comment',$comment);
  172. }
  173. /**
  174. * 详情页:将 AI SEO 或默认字段合并到 maccms,供模板使用 page_detail_* 变量
  175. */
  176. protected function mergeDetailSeoIntoMaccms($mid, array $info, $seoAi)
  177. {
  178. $cfg = isset($GLOBALS['config']['ai_seo']) ? $GLOBALS['config']['ai_seo'] : [];
  179. if (empty($cfg['template_inject']) || (string)$cfg['template_inject'] !== '1') {
  180. return;
  181. }
  182. if (!isset($this->view->maccms)) {
  183. return;
  184. }
  185. $mac = $this->view->maccms;
  186. if (!is_array($mac)) {
  187. return;
  188. }
  189. $row = [];
  190. if ($seoAi) {
  191. if (is_object($seoAi) && method_exists($seoAi, 'toArray')) {
  192. $row = $seoAi->toArray();
  193. } elseif (is_array($seoAi)) {
  194. $row = $seoAi;
  195. }
  196. }
  197. $siteName = isset($GLOBALS['config']['site']['site_name']) ? (string)$GLOBALS['config']['site']['site_name'] : '';
  198. if ((int)$mid === 1) {
  199. $defaultTitle = (string)$info['vod_name'] . ($siteName !== '' ? ' - ' . $siteName : '');
  200. $defaultKw = mac_format_text(trim((string)$info['vod_tag'] . ',' . (string)$info['vod_class']), true);
  201. $defaultDesc = trim(strip_tags((string)$info['vod_blurb']));
  202. if ($defaultDesc === '') {
  203. $defaultDesc = mac_substring(strip_tags((string)$info['vod_content']), 160);
  204. }
  205. } else {
  206. $defaultTitle = (string)$info['art_name'] . ($siteName !== '' ? ' - ' . $siteName : '');
  207. $defaultKw = mac_format_text(trim((string)$info['art_tag'] . ',' . (string)$info['art_class']), true);
  208. $defaultDesc = trim(strip_tags((string)$info['art_blurb']));
  209. if ($defaultDesc === '') {
  210. $plain = str_replace('$$$', '', strip_tags((string)$info['art_content']));
  211. $defaultDesc = mac_substring($plain, 160);
  212. }
  213. }
  214. $mac['page_detail_title'] = mac_filter_xss(!empty($row['seo_title']) ? (string)$row['seo_title'] : $defaultTitle);
  215. $mac['page_detail_keywords'] = mac_filter_xss(!empty($row['seo_keywords']) ? (string)$row['seo_keywords'] : $defaultKw);
  216. $mac['page_detail_description'] = mac_filter_xss(!empty($row['seo_description']) ? (string)$row['seo_description'] : $defaultDesc);
  217. $this->assign('maccms', $mac);
  218. }
  219. protected function label_search($param)
  220. {
  221. $param = mac_filter_words($param);
  222. $param = mac_search_len_check($param);
  223. // vod/search 各个参数下都可能出现回显关键词
  224. if(!empty($GLOBALS['config']['app']['wall_filter'])){
  225. $param = mac_escape_param($param);
  226. }
  227. $this->assign('param',$param);
  228. }
  229. protected function label_type($view=0, $type_id_specified = 0)
  230. {
  231. $param = mac_param_url();
  232. $param = mac_filter_words($param);
  233. $param = mac_search_len_check($param);
  234. $info = mac_label_type($param, $type_id_specified);
  235. if(!empty($GLOBALS['config']['app']['wall_filter'])){
  236. $param['wd'] = mac_escape_param($param['wd']);
  237. }
  238. $this->assign('param',$param);
  239. $this->assign('obj',$info);
  240. if(empty($info)){
  241. return $this->error(lang('controller/get_type_err'));
  242. }
  243. if($view<2) {
  244. $res = $this->check_user_popedom($info['type_id'], 1);
  245. if($res['code']>1){
  246. echo $this->error($res['msg'], mac_url('user/index') );
  247. exit;
  248. }
  249. }
  250. return $info;
  251. }
  252. protected function label_actor($total='')
  253. {
  254. $param = mac_param_url();
  255. $this->assign('param',$param);
  256. }
  257. protected function label_actor_detail($info=[],$view=0)
  258. {
  259. $param = mac_param_url();
  260. $this->assign('param',$param);
  261. if(empty($info)) {
  262. $res = mac_label_actor_detail($param);
  263. if ($res['code'] > 1) {
  264. $this->page_error($res['msg']);;
  265. }
  266. $info = $res['info'];
  267. }
  268. if(empty($info['actor_tpl'])){
  269. $info['actor_tpl'] = $info['type']['type_tpl_detail'];
  270. }
  271. if($view <2) {
  272. $popedom = $this->check_user_popedom($info['type_id'], 2,$param,'actor',$info);
  273. $this->assign('popedom',$popedom);
  274. if($popedom['code']>1){
  275. $this->assign('obj',$info);
  276. if($popedom['confirm']==1){
  277. echo $this->fetch('actor/confirm');
  278. exit;
  279. }
  280. echo $this->error($popedom['msg'], mac_url('user/index') );
  281. exit;
  282. }
  283. }
  284. $this->assign('obj',$info);
  285. $this->assign('comment_mid', 8);
  286. $this->assign('comment_rid', $info['actor_id']);
  287. $comment = config('maccms.comment');
  288. $this->assign('comment',$comment);
  289. return $info;
  290. }
  291. protected function label_role($total='')
  292. {
  293. $param = mac_param_url();
  294. $param = mac_filter_words($param);
  295. $param = mac_search_len_check($param);
  296. if(!empty($GLOBALS['app']['wall_filter'])){
  297. $param['wd'] = mac_escape_param($param['wd']);
  298. }
  299. $this->assign('param',$param);
  300. }
  301. protected function label_role_detail($info=[])
  302. {
  303. $param = mac_param_url();
  304. $this->assign('param',$param);
  305. if(empty($info)) {
  306. $res = mac_label_role_detail($param);
  307. if ($res['code'] > 1) {
  308. $this->page_error($res['msg']);;
  309. }
  310. $info = $res['info'];
  311. }
  312. $this->assign('obj',$info);
  313. $this->assign('comment_mid', 9);
  314. $this->assign('comment_rid', $info['role_id']);
  315. $comment = config('maccms.comment');
  316. $this->assign('comment',$comment);
  317. return $info;
  318. }
  319. protected function label_website_detail($info=[],$view=0)
  320. {
  321. $param = mac_param_url();
  322. $this->assign('param',$param);
  323. if(empty($info)) {
  324. $res = mac_label_website_detail($param);
  325. if ($res['code'] > 1) {
  326. $this->page_error($res['msg']);;
  327. }
  328. $info = $res['info'];
  329. }
  330. if(empty($info['website_tpl'])){
  331. $info['website_tpl'] = $info['type']['type_tpl_detail'];
  332. }
  333. if($view <2) {
  334. $popedom = $this->check_user_popedom($info['type_id'], 2,$param,'website',$info);
  335. $this->assign('popedom',$popedom);
  336. if($popedom['code']>1){
  337. $this->assign('obj',$info);
  338. if($popedom['confirm']==1){
  339. echo $this->fetch('website/confirm');
  340. exit;
  341. }
  342. echo $this->error($popedom['msg'], mac_url('user/index') );
  343. exit;
  344. }
  345. }
  346. $this->assign('obj',$info);
  347. $this->assign('comment_mid', 11);
  348. $this->assign('comment_rid', $info['website_id']);
  349. $comment = config('maccms.comment');
  350. $this->assign('comment',$comment);
  351. return $info;
  352. }
  353. protected function label_topic_index($total='')
  354. {
  355. $param = mac_param_url();
  356. $this->assign('param',$param);
  357. if($total=='') {
  358. $where = [];
  359. $where['topic_status'] = ['eq', 1];
  360. $total = model('Topic')->countData($where);
  361. }
  362. $url = mac_url_topic_index(['page'=>'PAGELINK']);
  363. $__PAGING__ = mac_page_param($total,1,$param['page'],$url);
  364. $this->assign('__PAGING__',$__PAGING__);
  365. }
  366. protected function label_topic_detail($info=[])
  367. {
  368. $param = mac_param_url();
  369. $this->assign('param',$param);
  370. if(empty($info)) {
  371. $res = mac_label_topic_detail($param);
  372. if ($res['code'] > 1) {
  373. $this->page_error($res['msg']);;
  374. }
  375. $info = $res['info'];
  376. }
  377. $this->assign('obj',$info);
  378. $this->assign('comment_mid', 3);
  379. $this->assign('comment_rid', $info['topic_id']);
  380. $comment = config('maccms.comment');
  381. $this->assign('comment',$comment);
  382. return $info;
  383. }
  384. protected function label_art_detail($info=[],$view=0,$fullPointsPopedom=false)
  385. {
  386. $param = mac_param_url();
  387. $this->assign('param',$param);
  388. if(empty($info)) {
  389. $res = mac_label_art_detail($param);
  390. if ($res['code'] > 1) {
  391. $this->page_error($res['msg']);;
  392. }
  393. $info = $res['info'];
  394. }
  395. if(empty($info['art_tpl'])){
  396. $info['art_tpl'] = $info['type']['type_tpl_detail'];
  397. }
  398. if($view <2) {
  399. if ($fullPointsPopedom) {
  400. $popedom = $this->check_user_popedom($info['type_id'], 3, $param, 'art_read', $info);
  401. $this->assign('popedom',$popedom);
  402. if($popedom['code']>1){
  403. $this->assign('obj',$info);
  404. }
  405. } else {
  406. $popedom = $this->check_user_popedom($info['type_id'], 2);
  407. if($popedom['code']>1){
  408. echo $this->error($popedom['msg'], mac_url('user/index') );
  409. exit;
  410. }
  411. }
  412. }
  413. $this->assign('obj',$info);
  414. $seo_ai = model('SeoAiResult')->getByObject(2, intval($info['art_id']));
  415. $this->assign('seo_ai', $seo_ai);
  416. $this->mergeDetailSeoIntoMaccms(2, $info, $seo_ai);
  417. $url = mac_url_art_detail($info,['page'=>'PAGELINK']);
  418. $__PAGING__ = mac_page_param($info['art_page_total'],1,$param['page'],$url);
  419. $this->assign('__PAGING__',$__PAGING__);
  420. $this->assign('comment_mid', 2);
  421. $this->assign('comment_rid', $info['art_id']);
  422. $this->label_comment();
  423. return $info;
  424. }
  425. protected function label_manga_detail($info=[],$view=0,$fullPointsPopedom=false)
  426. {
  427. $param = mac_param_url();
  428. $this->assign('param',$param);
  429. if(empty($info)) {
  430. $res = mac_label_manga_detail($param);
  431. if ($res['code'] > 1) {
  432. $this->page_error($res['msg']);;
  433. }
  434. $info = $res['info'];
  435. }
  436. if(empty($info['manga_tpl'])){
  437. $info['manga_tpl'] = $info['type']['type_tpl_detail'];
  438. }
  439. if($view <2) {
  440. if ($fullPointsPopedom) {
  441. $popedom = $this->check_user_popedom($info['type_id'], 3, $param, 'manga_play', $info);
  442. $this->assign('popedom',$popedom);
  443. if($popedom['code']>1){
  444. $this->assign('obj',$info);
  445. // 不再跳转确认页,直接进入阅读页,由模板内的权限引导进行购买/充值
  446. }
  447. } else {
  448. $popedom = $this->check_user_popedom($info['type_id'], 2);
  449. if($popedom['code']>1){
  450. echo $this->error($popedom['msg'], mac_url('user/index') );
  451. exit;
  452. }
  453. }
  454. }
  455. $this->assign('obj',$info);
  456. $this->assign('comment_mid', 12);
  457. $this->assign('comment_rid', $info['manga_id']);
  458. $this->label_comment();
  459. return $info;
  460. }
  461. protected function label_vod_detail($info=[],$view=0)
  462. {
  463. $param = mac_param_url();
  464. $this->assign('param',$param);
  465. if(empty($info)) {
  466. $res = mac_label_vod_detail($param);
  467. if ($res['code'] > 1){
  468. $this->page_error($res['msg']);
  469. }
  470. $info = $res['info'];
  471. }
  472. if(empty($info['vod_tpl'])){
  473. $info['vod_tpl'] = $info['type']['type_tpl_detail'];
  474. }
  475. if(empty($info['vod_tpl_play'])){
  476. $info['vod_tpl_play'] = $info['type']['type_tpl_play'];
  477. }
  478. if(empty($info['vod_tpl_down'])){
  479. $info['vod_tpl_down'] = $info['type']['type_tpl_down'];
  480. }
  481. if($view <2) {
  482. $res = $this->check_user_popedom($info['type']['type_id'], 2);
  483. if($res['code']>1){
  484. echo $this->error($res['msg'], mac_url('user/index') );
  485. exit;
  486. }
  487. }
  488. $this->assign('obj',$info);
  489. $seo_ai = model('SeoAiResult')->getByObject(1, intval($info['vod_id']));
  490. $this->assign('seo_ai', $seo_ai);
  491. $this->mergeDetailSeoIntoMaccms(1, $info, $seo_ai);
  492. $this->assign('comment_mid', 1);
  493. $this->assign('comment_rid', $info['vod_id']);
  494. $this->label_comment();
  495. return $info;
  496. }
  497. protected function label_vod_role($info=[],$view=0)
  498. {
  499. $param = mac_param_url();
  500. $this->assign('param', $param);
  501. if (empty($info)) {
  502. $res = mac_label_vod_detail($param);
  503. if ($res['code'] > 1) {
  504. $this->page_error($res['msg']);
  505. }
  506. $info = $res['info'];
  507. }
  508. $role = mac_label_vod_role(['rid'=>intval($info['vod_id'])]);
  509. if ($role['code'] > 1) {
  510. return $this->error($role['msg']);
  511. }
  512. $info['role'] = $role['list'];
  513. $this->assign('obj',$info);
  514. }
  515. protected function label_vod_play($flag='play',$info=[],$view=0,$pe=0)
  516. {
  517. $param = mac_param_url();
  518. $this->assign('param',$param);
  519. if(empty($info)) {
  520. $res = mac_label_vod_detail($param);
  521. if ($res['code'] > 1) {
  522. $this->page_error($res['msg']);
  523. }
  524. $info = $res['info'];
  525. }
  526. if(empty($info['vod_tpl'])){
  527. $info['vod_tpl'] = $info['type']['type_tpl_detail'];
  528. }
  529. if(empty($info['vod_tpl_play'])){
  530. $info['vod_tpl_play'] = $info['type']['type_tpl_play'];
  531. }
  532. if(empty($info['vod_tpl_down'])){
  533. $info['vod_tpl_down'] = $info['type']['type_tpl_down'];
  534. }
  535. $trysee = 0;
  536. $vod_popedom_locked = false;
  537. $popedom = ['code' => 1, 'msg' => '', 'trysee' => 0, 'confirm' => 0];
  538. $urlfun='mac_url_vod_'.$flag;
  539. $listfun = 'vod_'.$flag.'_list';
  540. if($view <2) {
  541. if ($flag == 'play') {
  542. $trysee = $GLOBALS['config']['user']['trysee'];
  543. if($info['vod_trysee'] >0){
  544. $trysee = $info['vod_trysee'];
  545. }
  546. $popedom = $this->check_user_popedom($info['type_id'], ($pe==0 ? 3 : 5),$param,$flag,$info,$trysee);
  547. }
  548. else {
  549. $popedom = $this->check_user_popedom($info['type_id'], 4,$param,$flag,$info);
  550. }
  551. if($pe==0 && $popedom['code']>1 && empty($popedom["trysee"])){
  552. $info['player_info']['flag'] = $flag;
  553. $this->assign('obj',$info);
  554. // 不再跳转确认页,直接进入播放页,由模板内的权限引导进行购买/充值
  555. $vod_popedom_locked = true;
  556. }
  557. }
  558. $this->assign('popedom',$popedom);
  559. if (!empty($vod_popedom_locked)) {
  560. $player_info = [
  561. 'flag' => $flag,
  562. 'encrypt' => 0,
  563. 'trysee' => 0,
  564. 'points' => intval($info['vod_points_'.$flag]),
  565. 'link' => '',
  566. 'link_next' => '',
  567. 'link_pre' => '',
  568. 'url' => '',
  569. 'url_next' => '',
  570. 'from' => '',
  571. 'server' => '',
  572. 'note' => '',
  573. 'id' => $param['id'],
  574. 'sid' => $param['sid'],
  575. 'nid' => $param['nid'],
  576. 'vod_data' => [
  577. 'vod_name' => $info['vod_name'],
  578. 'vod_actor' => $info['vod_actor'],
  579. 'vod_director' => $info['vod_director'],
  580. 'vod_class' => $info['vod_class'],
  581. ],
  582. ];
  583. // 无权限时仍生成上/下集播放页链接,便于游客切换集数(各集仍受权限门控)
  584. if ($param['nid'] > 1) {
  585. $player_info['link_pre'] = $urlfun($info, ['sid' => $param['sid'], 'nid' => $param['nid'] - 1]);
  586. }
  587. $list_key = 'vod_' . $flag . '_list';
  588. if (!empty($info[$list_key][$param['sid']]['url_count'])
  589. && $param['nid'] < $info[$list_key][$param['sid']]['url_count']) {
  590. $player_info['link_next'] = $urlfun($info, ['sid' => $param['sid'], 'nid' => $param['nid'] + 1]);
  591. }
  592. $info['player_info'] = $player_info;
  593. $this->assign('obj',$info);
  594. $favPlay = mac_user_fav_state((int)($GLOBALS['user']['user_id'] ?? 0), 1, (int)($info['vod_id'] ?? 0));
  595. $this->assign('vod_play_fav_ulog_id', $favPlay['fav_ulog_id']);
  596. $this->assign('vod_play_is_fav', $favPlay['is_fav']);
  597. $this->assign('player_data','');
  598. $this->assign('player_js','');
  599. $this->assign('comment_mid', 1);
  600. $this->assign('comment_rid', $info['vod_id']);
  601. $this->label_comment();
  602. $__vodTagwall = mac_vod_play_tagwall_payload($info);
  603. $this->assign('vod_play_tagwall_enabled', $__vodTagwall['enabled']);
  604. $this->assign('vod_play_tagwall_json', $__vodTagwall['json']);
  605. return $info;
  606. }
  607. $player_info=[];
  608. $player_info['flag'] = $flag;
  609. $player_info['encrypt'] = intval($GLOBALS['config']['app']['encrypt']);
  610. $player_info['trysee'] = intval($trysee);
  611. $player_info['points'] = intval($info['vod_points_'.$flag]);
  612. $player_info['link'] = $urlfun($info,['sid'=>'{sid}','nid'=>'{nid}']);
  613. $player_info['link_next'] = '';
  614. $player_info['link_pre'] = '';
  615. $player_info['vod_data'] = [
  616. 'vod_name' => $info['vod_name'],
  617. 'vod_actor' => $info['vod_actor'],
  618. 'vod_director' => $info['vod_director'],
  619. 'vod_class' => $info['vod_class'],
  620. ];
  621. if($param['nid']>1){
  622. $player_info['link_pre'] = $urlfun($info,['sid'=>$param['sid'],'nid'=>$param['nid']-1]);
  623. }
  624. if($param['nid'] < $info['vod_'.$flag.'_list'][$param['sid']]['url_count']){
  625. $player_info['link_next'] = $urlfun($info,['sid'=>$param['sid'],'nid'=>$param['nid']+1]);
  626. }
  627. $player_info['url'] = (string)$info[$listfun][$param['sid']]['urls'][$param['nid']]['url'];
  628. $player_info['url_next'] = (string)$info[$listfun][$param['sid']]['urls'][$param['nid']+1]['url'];
  629. if(substr($player_info['url'],0,6) == 'upload'){
  630. $player_info['url'] = MAC_PATH . $player_info['url'];
  631. }
  632. if(substr($player_info['url_next'],0,6) == 'upload'){
  633. $player_info['url_next'] = MAC_PATH . $player_info['url_next'];
  634. }
  635. $player_info['from'] = (string)$info[$listfun][$param['sid']]['from'];
  636. if((string)$info[$listfun][$param['sid']]['urls'][$param['nid']]['from'] != $player_info['from']){
  637. $player_info['from'] = (string)$info[$listfun][$param['sid']]['urls'][$param['nid']]['from'];
  638. }
  639. $player_info['server'] = (string)$info[$listfun][$param['sid']]['server'];
  640. $player_info['note'] = (string)$info[$listfun][$param['sid']]['note'];
  641. if($GLOBALS['config']['app']['encrypt']=='1'){
  642. $player_info['url'] = mac_escape($player_info['url']);
  643. $player_info['url_next'] = mac_escape($player_info['url_next']);
  644. }
  645. elseif($GLOBALS['config']['app']['encrypt']=='2'){
  646. $player_info['url'] = base64_encode(mac_escape($player_info['url']));
  647. $player_info['url_next'] = base64_encode(mac_escape($player_info['url_next']));
  648. }
  649. $player_info['id'] = $param['id'];
  650. $player_info['sid'] = $param['sid'];
  651. $player_info['nid'] = $param['nid'];
  652. $info['player_info'] = $player_info;
  653. $this->assign('obj',$info);
  654. $seo_ai = model('SeoAiResult')->getByObject(1, intval($info['vod_id']));
  655. $this->assign('seo_ai', $seo_ai);
  656. $this->mergeDetailSeoIntoMaccms(1, $info, $seo_ai);
  657. $favPlay = mac_user_fav_state((int)($GLOBALS['user']['user_id'] ?? 0), 1, (int)($info['vod_id'] ?? 0));
  658. $this->assign('vod_play_fav_ulog_id', $favPlay['fav_ulog_id']);
  659. $this->assign('vod_play_is_fav', $favPlay['is_fav']);
  660. $pwd_key = '1-'.($flag=='play' ?'4':'5').'-'.$info['vod_id'];
  661. 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) ) {
  662. $id = $info['vod_id'];
  663. if($GLOBALS['config']['rewrite']['vod_id']==2){
  664. $id = mac_alphaID($info['vod_id'],false,$GLOBALS['config']['rewrite']['encode_len'],$GLOBALS['config']['rewrite']['encode_key']);
  665. }
  666. $dy_play = mac_url('index/vod/'.$flag.'er',['id'=>$id,'sid'=>$param['sid'],'nid'=>$param['nid']]);
  667. $this->assign('player_data','');
  668. $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>');
  669. }
  670. else {
  671. $this->assign('player_data', '<script type="text/javascript">var player_aaaa=' . json_encode($player_info) . '</script>');
  672. $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>');
  673. }
  674. $this->assign('comment_mid', 1);
  675. $this->assign('comment_rid', $info['vod_id']);
  676. $this->label_comment();
  677. $__vodTagwall = mac_vod_play_tagwall_payload($info);
  678. $this->assign('vod_play_tagwall_enabled', $__vodTagwall['enabled']);
  679. $this->assign('vod_play_tagwall_json', $__vodTagwall['json']);
  680. return $info;
  681. }
  682. /**
  683. * 用户组/积分阅读与播放权限(前台 index 与 api 模块共用)
  684. */
  685. protected function check_user_popedom($type_id, $popedom, $param = [], $flag = '', $info = [], $trysee = 0)
  686. {
  687. $user = $GLOBALS['user'];
  688. $group_ids = explode(',', $user['group_id']);
  689. $group_list = model('Group')->getCache();
  690. $res = false;
  691. $read_popedoms = [$popedom];
  692. foreach ($group_ids as $group_id) {
  693. if (!isset($group_list[$group_id])) {
  694. continue;
  695. }
  696. $group = $group_list[$group_id];
  697. if (strpos(',' . $group['group_type'], ',' . $type_id . ',') === false) {
  698. continue;
  699. }
  700. foreach ($read_popedoms as $p) {
  701. if (!empty($group['group_popedom'][$type_id][$p])) {
  702. $res = true;
  703. break 2;
  704. }
  705. }
  706. }
  707. $pre = $flag;
  708. $col = 'detail';
  709. if ($flag == 'play' || $flag == 'down') {
  710. $pre = 'vod';
  711. $col = $flag;
  712. } elseif ($flag == 'art_read') {
  713. $pre = 'art';
  714. $col = 'detail';
  715. } elseif ($flag == 'manga_play') {
  716. $pre = 'manga';
  717. $col = 'detail';
  718. }
  719. $points = 0;
  720. if (in_array($pre, ['art', 'manga'], true)) {
  721. $points = mac_content_read_points_amount($pre, $info);
  722. } elseif (in_array($pre, ['vod', 'actor', 'website'], true)) {
  723. $points = (int) ($info[$pre . '_points_' . $col] ?? 0);
  724. if ($GLOBALS['config']['user'][$pre . '_points_type'] == '1') {
  725. $points = (int) ($info[$pre . '_points'] ?? 0);
  726. }
  727. }
  728. if ($GLOBALS['config']['user']['status'] == 0) {
  729. } elseif (($popedom == 2 && in_array($pre, ['art', 'actor', 'website', 'manga'])) || ($popedom == 3 && in_array($flag, ['art_read', 'manga_play']))) {
  730. $has_permission = false;
  731. $has_trysee = false;
  732. $check_p = in_array($flag, ['art_read', 'manga_play']) ? [3] : [2];
  733. foreach ($group_ids as $group_id) {
  734. if (!isset($group_list[$group_id])) {
  735. continue;
  736. }
  737. $group = $group_list[$group_id];
  738. foreach ($check_p as $p) {
  739. if (!empty($group['group_popedom'][$type_id][$p])) {
  740. $has_permission = true;
  741. break;
  742. }
  743. }
  744. if ($trysee > 0) {
  745. $has_trysee = true;
  746. }
  747. }
  748. if ($res === false) {
  749. if ($has_trysee) {
  750. return ['code' => 1, 'msg' => lang('controller/in_try_see'), 'trysee' => $trysee];
  751. }
  752. if (in_array($flag, ['art_read', 'manga_play'], true) && $points > 0) {
  753. if ($user['user_id'] > 0) {
  754. $mid = mac_get_mid($pre);
  755. $where = [];
  756. $where['ulog_mid'] = $mid;
  757. $where['ulog_type'] = 1;
  758. $where['ulog_rid'] = $param['id'];
  759. $where['ulog_sid'] = ($pre == 'manga') ? ($param['sid'] ?? 0) : ($param['page'] ?? 0);
  760. $where['ulog_nid'] = ($pre == 'manga') ? ($param['nid'] ?? 0) : 0;
  761. $where['user_id'] = $user['user_id'];
  762. $where['ulog_points'] = $points;
  763. if ($GLOBALS['config']['user'][$pre . '_points_type'] == '1') {
  764. $where['ulog_sid'] = 0;
  765. $where['ulog_nid'] = 0;
  766. }
  767. $ulogRes = model('Ulog')->infoData($where);
  768. if ($ulogRes['code'] == 1) {
  769. return ['code' => 1, 'msg' => lang('controller/popedom_ok')];
  770. }
  771. }
  772. return ['code' => 3003, 'msg' => lang('controller/pay_play_points', [$points]), 'points' => $points, 'confirm' => 1, 'trysee' => 0];
  773. }
  774. return ['code' => 3001, 'msg' => lang('controller/no_popedom'), 'trysee' => 0];
  775. }
  776. if (max($group_ids) < 3 && $points > 0) {
  777. $mid = mac_get_mid($pre);
  778. $where = [];
  779. $where['ulog_mid'] = $mid;
  780. $where['ulog_type'] = 1;
  781. $where['ulog_rid'] = $param['id'];
  782. $where['ulog_sid'] = ($pre == 'manga') ? ($param['sid'] ?? 0) : ($param['page'] ?? 0);
  783. $where['ulog_nid'] = ($pre == 'manga') ? ($param['nid'] ?? 0) : 0;
  784. $where['user_id'] = $user['user_id'];
  785. $where['ulog_points'] = $points;
  786. if ($GLOBALS['config']['user'][$pre . '_points_type'] == '1') {
  787. $where['ulog_sid'] = 0;
  788. $where['ulog_nid'] = 0;
  789. }
  790. $res = model('Ulog')->infoData($where);
  791. if ($res['code'] > 1) {
  792. return ['code' => 3003, 'msg' => lang('controller/pay_play_points', [$points]), 'points' => $points, 'confirm' => 1, 'trysee' => 0];
  793. }
  794. }
  795. } elseif ($popedom == 3) {
  796. $has_permission = false;
  797. foreach ($group_ids as $group_id) {
  798. if (!isset($group_list[$group_id])) {
  799. continue;
  800. }
  801. $group = $group_list[$group_id];
  802. if (!empty($group['group_popedom'][$type_id][5])) {
  803. $has_permission = true;
  804. break;
  805. }
  806. }
  807. if ($res === false) {
  808. if ($has_permission && max($group_ids) < 3) {
  809. return ['code' => 3002, 'msg' => lang('controller/in_try_see'), 'trysee' => $trysee];
  810. } else {
  811. return ['code' => 3001, 'msg' => lang('controller/no_popedom'), 'trysee' => 0];
  812. }
  813. }
  814. if (max($group_ids) < 3 && $points > 0) {
  815. $where = [];
  816. $where['ulog_mid'] = 1;
  817. $where['ulog_type'] = $flag == 'play' ? 4 : 5;
  818. $where['ulog_rid'] = $param['id'];
  819. $where['ulog_sid'] = $param['sid'];
  820. $where['ulog_nid'] = $param['nid'];
  821. $where['user_id'] = $user['user_id'];
  822. $where['ulog_points'] = $points;
  823. if ($GLOBALS['config']['user']['vod_points_type'] == '1') {
  824. $where['ulog_sid'] = 0;
  825. $where['ulog_nid'] = 0;
  826. }
  827. $res_ulog = model('Ulog')->infoData($where);
  828. if ($res_ulog['code'] > 1) {
  829. return ['code' => 3003, 'msg' => lang('controller/pay_play_points', [$points]), 'points' => $points, 'confirm' => 1, 'trysee' => 0];
  830. }
  831. }
  832. } else {
  833. if ($res === false) {
  834. return ['code' => 1001, 'msg' => lang('controller/no_popedom')];
  835. }
  836. if ($popedom == 4) {
  837. if (max($group_ids) == 1 && $points > 0) {
  838. return ['code' => 4001, 'msg' => lang('controller/charge_data'), 'trysee' => 0];
  839. } elseif (max($group_ids) == 2 && $points > 0) {
  840. $where = [];
  841. $where['ulog_mid'] = 1;
  842. $where['ulog_type'] = $flag == 'play' ? 4 : 5;
  843. $where['ulog_rid'] = $param['id'];
  844. $where['ulog_sid'] = $param['sid'];
  845. $where['ulog_nid'] = $param['nid'];
  846. $where['user_id'] = $user['user_id'];
  847. $where['ulog_points'] = $points;
  848. if ($GLOBALS['config']['user']['vod_points_type'] == '1') {
  849. $where['ulog_sid'] = 0;
  850. $where['ulog_nid'] = 0;
  851. }
  852. $res = model('Ulog')->infoData($where);
  853. if ($res['code'] > 1) {
  854. return ['code' => 4003, 'msg' => lang('controller/pay_down_points', [$points]), 'points' => $points, 'confirm' => 1, 'trysee' => 0];
  855. }
  856. }
  857. } elseif ($popedom == 5) {
  858. $has_permission = false;
  859. $has_trysee = false;
  860. foreach ($group_ids as $group_id) {
  861. if (!isset($group_list[$group_id])) {
  862. continue;
  863. }
  864. $group = $group_list[$group_id];
  865. if (!empty($group['group_popedom'][$type_id][3])) {
  866. $has_permission = true;
  867. }
  868. if (!empty($group['group_popedom'][$type_id][5])) {
  869. $has_trysee = true;
  870. }
  871. }
  872. if (!$has_permission && $has_trysee && max($group_ids) < 3) {
  873. $where = [];
  874. $where['ulog_mid'] = 1;
  875. $where['ulog_type'] = $flag == 'play' ? 4 : 5;
  876. $where['ulog_rid'] = $param['id'];
  877. $where['ulog_sid'] = $param['sid'];
  878. $where['ulog_nid'] = $param['nid'];
  879. $where['user_id'] = $user['user_id'];
  880. $where['ulog_points'] = $points;
  881. if ($GLOBALS['config']['user']['vod_points_type'] == '1') {
  882. $where['ulog_sid'] = 0;
  883. $where['ulog_nid'] = 0;
  884. }
  885. $res = model('Ulog')->infoData($where);
  886. if ($points > 0 && $res['code'] == 1) {
  887. return ['code' => 5001, 'msg' => lang('controller/popedom_ok')];
  888. }
  889. if ($user['user_id'] > 0) {
  890. if ($points > intval($user['user_points'])) {
  891. return ['code' => 5002, 'msg' => lang('controller/not_enough_points', [$points, $user['user_points']]), 'trysee' => $trysee];
  892. } else {
  893. return ['code' => 5001, 'msg' => lang('controller/try_see_end', [$points, $user['user_points']]), 'trysee' => $trysee];
  894. }
  895. } else {
  896. if ($points > 0) {
  897. return ['code' => 5002, 'msg' => lang('controller/not_enough_points', [$points, $user['user_points']]), 'trysee' => $trysee];
  898. } else {
  899. return ['code' => 5001, 'msg' => lang('controller/try_see_end', [$points, $user['user_points']]), 'trysee' => $trysee];
  900. }
  901. }
  902. }
  903. }
  904. }
  905. return ['code' => 1, 'msg' => lang('controller/popedom_ok')];
  906. }
  907. }