Ajax.php 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810
  1. <?php
  2. namespace app\index\controller;
  3. class Ajax extends Base
  4. {
  5. var $_param;
  6. public function __construct()
  7. {
  8. parent::__construct();
  9. $this->_param = mac_param_url();
  10. }
  11. public function index()
  12. {
  13. }
  14. //加载最多不超过20页数据,防止非法采集。每页条数可以是10,20,30
  15. public function data()
  16. {
  17. $mid = $this->_param['mid'];
  18. $limit = $this->_param['limit'];
  19. $page = $this->_param['page'];
  20. $type_id = $this->_param['tid'];
  21. if( !in_array($mid,['1','2','3','8','9','11']) ) {
  22. return json(['code'=>1001,'msg'=>lang('param_err')]);
  23. }
  24. if( !in_array($limit,['10','20','30']) ) {
  25. $limit =10;
  26. }
  27. if($page < 1 || $page > 20){
  28. $page =1;
  29. }
  30. $pre = mac_get_mid_code($mid);
  31. $order= $pre.'_time desc';
  32. $where=[];
  33. $where[$pre.'_status'] = [ 'eq',1];
  34. if(!empty($type_id)) {
  35. if(in_array($mid, ['1', '2'])){
  36. $type_list = model('Type')->getCache('type_list');
  37. $type_info = $type_list[$type_id];
  38. if(!empty($type_info)) {
  39. $ids = $type_info['type_pid'] == 0 ? $type_info['childids'] : $type_info['type_id'];
  40. $where['type_id|type_id_1'] = ['in', $ids];
  41. }
  42. }
  43. }
  44. $field='*';
  45. $res = model($pre)->listData($where,$order,$page,$limit,0,$field);
  46. if($res['code']==1) {
  47. foreach ($res['list'] as $k => &$v) {
  48. unset($v[$pre.'_time_hits'],$v[$pre.'_time_make']);
  49. $v[$pre.'_time'] = date('Y-m-d H:i:s',$v[$pre.'_time']);
  50. $v[$pre.'_time_add'] = date('Y-m-d H:i:s',$v[$pre.'_time_add']);
  51. if($mid=='1'){
  52. unset($v['vod_play_from'],$v['vod_play_server'],$v['vod_play_note'],$v['vod_play_url']);
  53. unset($v['vod_down_from'],$v['vod_down_server'],$v['vod_down_note'],$v['vod_down_url']);
  54. $v['detail_link'] = mac_url_vod_detail($v);
  55. }
  56. elseif($mid=='2'){
  57. $v['detail_link'] = mac_url_art_detail($v);
  58. }
  59. elseif($mid=='3'){
  60. $v['detail_link'] = mac_url_topic_detail($v);
  61. }
  62. elseif($mid=='8'){
  63. $v['detail_link'] = mac_url_actor_detail($v);
  64. }
  65. elseif($mid=='9'){
  66. $v['detail_link'] = mac_url_role_detail($v);
  67. }
  68. elseif($mid=='11'){
  69. $v['detail_link'] = mac_url_website_detail($v);
  70. }
  71. $v[$pre.'_pic'] = mac_url_img($v[$pre.'_pic']);
  72. $v[$pre.'_pic_thumb'] = mac_url_img($v[$pre.'_pic_thumb']);
  73. $v[$pre.'_pic_slide'] = mac_url_img($v[$pre.'_pic_slide']);
  74. }
  75. }
  76. return json($res);
  77. }
  78. public function suggest()
  79. {
  80. if($GLOBALS['config']['app']['search'] !='1'){
  81. return json(['code'=>999,'msg'=>lang('suggest_close')]);
  82. }
  83. $mid = $this->_param['mid'];
  84. $wd = $this->_param['wd'];
  85. $limit = intval($this->_param['limit']);
  86. if( $wd=='' || !in_array($mid,['1','2','3','8','9','11']) ) {
  87. return json(['code'=>1001,'msg'=>lang('param_err')]);
  88. }
  89. $mids = [1=>'vod',2=>'art',3=>'topic',8=>'actor',9=>'role',11=>'website'];
  90. $pre = $mids[$mid];
  91. if($limit<1){
  92. $limit = 20;
  93. }
  94. $where = [];
  95. $where[$pre.'_name|'.$pre.'_en'] = ['like','%'.$wd.'%'];
  96. $order = $pre.'_id desc';
  97. $field = $pre.'_id as id,'.$pre.'_name as name,'.$pre.'_en as en,'.$pre.'_pic as pic';
  98. $url = mac_url_search(['wd'=>'mac_wd'],$pre);
  99. $res = model($pre)->listData($where,$order,1,$limit,0,$field);
  100. if($res['code']==1) {
  101. foreach ($res['list'] as $k => $v) {
  102. $res['list'][$k]['pic'] = mac_url_img($v['pic']);
  103. }
  104. }
  105. $res['url'] = $url;
  106. return json($res);
  107. }
  108. public function desktop()
  109. {
  110. $name = $this->_param['name'];
  111. $url = $this->_param['url'];
  112. $config = config('maccms.site');
  113. if(empty($name)){
  114. $name = $config['site_name'];
  115. $url = "http://".$config['site_url'];
  116. }
  117. if(substr($url,0,4)!="http"){
  118. $url = "http://".$url;
  119. }
  120. $Shortcut = "[InternetShortcut]
  121. URL=".$url."
  122. IDList=
  123. IconIndex=1
  124. [{000214A0-0000-0000-C000-000000000046}]
  125. Prop3=19,2";
  126. header("Content-type: application/octet-stream");
  127. if(strpos($_SERVER['HTTP_USER_AGENT'], "MSIE")){
  128. header("Content-Disposition: attachment; filename=". urlencode($name) .".url;");
  129. }
  130. else{
  131. header("Content-Disposition: attachment; filename=". $name .".url;");
  132. }
  133. echo $Shortcut;
  134. }
  135. public function hits()
  136. {
  137. $id = $this->_param['id'];
  138. $mid = $this->_param['mid'];
  139. $type = $this->_param['type'];
  140. if(empty($id) || !in_array($mid,['1','2','3','8','9','11']) ) {
  141. return json(['code'=>1001,'msg'=>lang('param_err')]);
  142. }
  143. $pre = mac_get_mid_code($mid);
  144. $where = [];
  145. $where[$pre.'_id'] = $id;
  146. $field = $pre.'_hits,'.$pre.'_hits_day,'.$pre.'_hits_week,'.$pre.'_hits_month,'.$pre.'_time_hits';
  147. $model = model($pre);
  148. $res = $model->infoData($where,$field);
  149. if($res['code']>1) {
  150. return json($res);
  151. }
  152. $info = $res['info'];
  153. if($type == 'update'){
  154. //初始化值
  155. $update[$pre.'_hits'] = $info[$pre.'_hits'];
  156. $update[$pre.'_hits_day'] = $info[$pre.'_hits_day'];
  157. $update[$pre.'_hits_week'] = $info[$pre.'_hits_week'];
  158. $update[$pre.'_hits_month'] = $info[$pre.'_hits_month'];
  159. $new = getdate();
  160. $old = getdate($info[$pre.'_time_hits']);
  161. //月
  162. if($new['year'] == $old['year'] && $new['mon'] == $old['mon']){
  163. $update[$pre.'_hits_month'] ++;
  164. }else{
  165. $update[$pre.'_hits_month'] = 1;
  166. }
  167. //周
  168. $weekStart = mktime(0,0,0,$new["mon"],$new["mday"],$new["year"]) - ($new["wday"] * 86400);
  169. $weekEnd = mktime(23,59,59,$new["mon"],$new["mday"],$new["year"]) + ((6 - $new["wday"]) * 86400);
  170. if($info[$pre.'_time_hits'] >= $weekStart && $info[$pre.'_time_hits'] <= $weekEnd){
  171. $update[$pre.'_hits_week'] ++;
  172. }else{
  173. $update[$pre.'_hits_week'] = 1;
  174. }
  175. //日
  176. if($new['year'] == $old['year'] && $new['mon'] == $old['mon'] && $new['mday'] == $old['mday']){
  177. $update[$pre.'_hits_day'] ++;
  178. }else{
  179. $update[$pre.'_hits_day'] = 1;
  180. }
  181. //更新数据库
  182. $update[$pre.'_hits'] = $update[$pre.'_hits']+1;
  183. $update[$pre.'_time_hits'] = time();
  184. $model->where($where)->update($update);
  185. $data['hits'] = $update[$pre.'_hits'];
  186. $data['hits_day'] = $update[$pre.'_hits_day'];
  187. $data['hits_week'] = $update[$pre.'_hits_week'];
  188. $data['hits_month'] = $update[$pre.'_hits_month'];
  189. }
  190. else{
  191. $data['hits'] = $info[$pre.'_hits'];
  192. $data['hits_day'] = $info[$pre.'_hits_day'];
  193. $data['hits_week'] = $info[$pre.'_hits_week'];
  194. $data['hits_month'] = $info[$pre.'_hits_month'];
  195. }
  196. return json(['code'=>1,'msg'=>'ok','data'=>$data]);
  197. }
  198. public function referer()
  199. {
  200. $url = $this->_param['url'];
  201. $type = $this->_param['type'];
  202. $domain = $this->_param['domain'];
  203. if(empty($url)) {
  204. return json(['code'=>1001,'msg'=>lang('param_err')]);
  205. }
  206. if(strpos($_SERVER["HTTP_REFERER"],$_SERVER['HTTP_HOST'])===false){
  207. return json(['code'=>1002,'msg'=>lang('param_err')]);
  208. }
  209. if(strpos($url,$domain)===false){
  210. return json(['code'=>1003,'msg'=>lang('param_err')]);
  211. }
  212. $pre = 'website';
  213. $where=[];
  214. $where[$pre.'_jumpurl'] = ['like', ['http://'.$domain.'%','https://'.$domain.'%'],'OR'];
  215. $model = model($pre);
  216. $field = $pre.'_referer,'.$pre.'_referer_day,'.$pre.'_referer_week,'.$pre.'_referer_month,'.$pre.'_time_referer';
  217. $res = $model->infoData($where,$field);
  218. if($res['code']>1){
  219. return json($res);
  220. }
  221. $info = $res['info'];
  222. $id = $info[$pre.'_id'];
  223. //来路访问记录验证
  224. $res = model('Website')->visit($this->_param);
  225. if($res['code']>1){
  226. return json($res);
  227. }
  228. if($type == 'update'){
  229. //初始化值
  230. $update[$pre.'_referer'] = $info[$pre.'_referer'];
  231. $update[$pre.'_referer_day'] = $info[$pre.'_referer_day'];
  232. $update[$pre.'_referer_week'] = $info[$pre.'_referer_week'];
  233. $update[$pre.'_referer_month'] = $info[$pre.'_referer_month'];
  234. $new = getdate();
  235. $old = getdate($info[$pre.'_time_referer']);
  236. //月
  237. if($new['year'] == $old['year'] && $new['mon'] == $old['mon']){
  238. $update[$pre.'_referer_month'] ++;
  239. }else{
  240. $update[$pre.'_referer_month'] = 1;
  241. }
  242. //周
  243. $weekStart = mktime(0,0,0,$new["mon"],$new["mday"],$new["year"]) - ($new["wday"] * 86400);
  244. $weekEnd = mktime(23,59,59,$new["mon"],$new["mday"],$new["year"]) + ((6 - $new["wday"]) * 86400);
  245. if($info[$pre.'_time_referer'] >= $weekStart && $info[$pre.'_time_referer'] <= $weekEnd){
  246. $update[$pre.'_referer_week'] ++;
  247. }else{
  248. $update[$pre.'_referer_week'] = 1;
  249. }
  250. //日
  251. if($new['year'] == $old['year'] && $new['mon'] == $old['mon'] && $new['mday'] == $old['mday']){
  252. $update[$pre.'_referer_day'] ++;
  253. }else{
  254. $update[$pre.'_referer_day'] = 1;
  255. }
  256. //更新数据库
  257. $update[$pre.'_referer'] = $update[$pre.'_referer']+1;
  258. $update[$pre.'_time_referer'] = time();
  259. $model->where($where)->update($update);
  260. $data['referer'] = $update[$pre.'_referer'];
  261. $data['referer_day'] = $update[$pre.'_referer_day'];
  262. $data['referer_week'] = $update[$pre.'_referer_week'];
  263. $data['referer_month'] = $update[$pre.'_referer_month'];
  264. }
  265. else{
  266. $data['referer'] = $info[$pre.'_referer'];
  267. $data['referer_day'] = $info[$pre.'_referer_day'];
  268. $data['referer_week'] = $info[$pre.'_referer_week'];
  269. $data['referer_month'] = $info[$pre.'_referer_month'];
  270. }
  271. return json(['code'=>1,'msg'=>'ok','data'=>$data]);
  272. }
  273. public function digg()
  274. {
  275. $id = $this->_param['id'];
  276. $mid = $this->_param['mid'];
  277. $type = $this->_param['type'];
  278. if(empty($id) || !in_array($mid,['1','2','3','4','8','9','11']) ) {
  279. return json(['code'=>1001,'msg'=>lang('param_err')]);
  280. }
  281. $pre = mac_get_mid_code($mid);
  282. $where = [];
  283. $where[$pre.'_id'] = $id;
  284. $field = $pre.'_up,'.$pre.'_down';
  285. $model = model($pre);
  286. if($type) {
  287. $cookie = $pre . '-digg-' . $id;
  288. if(!empty(cookie($cookie))){
  289. return json(['code'=>1002,'msg'=>lang('index/haved')]);
  290. }
  291. if ($type == 'up') {
  292. $model->where($where)->setInc($pre.'_up');
  293. cookie($cookie, 't', 30);
  294. } elseif ($type == 'down') {
  295. $model->where($where)->setInc($pre.'_down');
  296. cookie($cookie, 't', 30);
  297. }
  298. }
  299. $res = $model->infoData($where,$field);
  300. if($res['code']>1) {
  301. return json($res);
  302. }
  303. $info = $res['info'];
  304. if ($info) {
  305. $data['up'] = $info[$pre.'_up'];
  306. $data['down'] = $info[$pre.'_down'];
  307. }
  308. else{
  309. $data['up'] = 0;
  310. $data['down'] = 0;
  311. }
  312. return json(['code'=>1,'msg'=>'ok','data'=>$data]);
  313. }
  314. public function score()
  315. {
  316. $id = $this->_param['id'];
  317. $mid = $this->_param['mid'];
  318. $score = $this->_param['score'];
  319. if(empty($id) || !in_array($mid,['1','2','3','8','9','11','12']) ) {
  320. return json(['code'=>1001,'msg'=>lang('param_err')]);
  321. }
  322. $pre = mac_get_mid_code($mid);
  323. $where = [];
  324. $where[$pre.'_id'] = $id;
  325. $field = $pre.'_score,'.$pre.'_score_num,'.$pre.'_score_all';
  326. $model = model($pre);
  327. $res = $model->infoData($where,$field);
  328. if($res['code']>1) {
  329. return json($res);
  330. }
  331. $info = $res['info'];
  332. if ($info) {
  333. if($score){
  334. $cookie = $pre.'-score-'.$id;
  335. if(!empty(cookie($cookie))){
  336. return json(['code'=>1002,'msg'=>lang('index/haved')]);
  337. }
  338. $update=[];
  339. $update[$pre.'_score_num'] = $info[$pre.'_score_num']+1;
  340. $update[$pre.'_score_all'] = $info[$pre.'_score_all']+$score;
  341. $update[$pre.'_score'] = number_format( $update[$pre.'_score_all'] / $update[$pre.'_score_num'] ,1,'.','');
  342. $model->where($where)->update($update);
  343. $data['score'] = $update[$pre.'_score'];
  344. $data['score_num'] = $update[$pre.'_score_num'];
  345. $data['score_all'] = $update[$pre.'_score_all'];
  346. cookie($cookie,'t',30);
  347. }
  348. else{
  349. $data['score'] = $info[$pre.'_score'];
  350. $data['score_num'] = $info[$pre.'_score_num'];
  351. $data['score_all'] = $info[$pre.'_score_all'];
  352. }
  353. }else{
  354. $data['score'] = 0.0;
  355. $data['score_num'] = 0;
  356. $data['score_all'] = 0;
  357. }
  358. return json(['code'=>1,'msg'=>lang('score_ok'),'data'=>$data]);
  359. }
  360. public function pwd()
  361. {
  362. $mid = $this->_param['mid'];
  363. $id = $this->_param['id'];
  364. $type = $this->_param['type'];
  365. $pwd = input('param.pwd');
  366. if( empty($id) || empty($pwd) || !in_array($mid,['1','2']) || !in_array($type,['1','4','5'])){
  367. return json(['code'=>1001,'msg'=>lang('param_err')]);
  368. }
  369. $key = $mid.'-'.$type.'-'.$id;
  370. if(session($key)=='1'){
  371. return json(['code'=>1002,'msg'=>lang('index/pwd_repeat')]);
  372. }
  373. if ( mac_get_time_span("last_pwd") < 5){
  374. return json(['code'=>1003,'msg'=>lang('index/pwd_frequently')]);
  375. }
  376. if($mid=='1'){
  377. $where=[];
  378. $where['vod_id'] = ['eq',$id];
  379. $info = model('Vod')->infoData($where);
  380. if($info['code'] >1){
  381. return json(['code'=>1011,'msg'=>$info['msg']]);
  382. }
  383. if($type=='1'){
  384. if($info['info']['vod_pwd'] != $pwd){
  385. return json(['code'=>1012,'msg'=>lang('pass_err')]);
  386. }
  387. }
  388. elseif($type=='4'){
  389. if($info['info']['vod_pwd_play'] != $pwd){
  390. return json(['code'=>1013,'msg'=>lang('pass_err')]);
  391. }
  392. }
  393. elseif($type=='5'){
  394. if($info['info']['vod_pwd_down'] != $pwd){
  395. return json(['code'=>1014,'msg'=>lang('pass_err')]);
  396. }
  397. }
  398. }
  399. else{
  400. $where=[];
  401. $where['art_id'] = ['eq',$id];
  402. $info = model('Art')->infoData($where);
  403. if($info['code'] >1){
  404. return json(['code'=>1021,'msg'=>$info['msg']]);
  405. }
  406. if($info['info']['art_pwd'] != $pwd){
  407. return json(['code'=>1022,'msg'=>lang('pass_err')]);
  408. }
  409. }
  410. session($key,'1');
  411. return json(['code'=>1,'msg'=>'ok']);
  412. }
  413. /**
  414. * 漫画猜你喜欢 - 换一换 AJAX 接口
  415. * 参数: id=当前漫画ID, tid=分类ID(可选), num=数量(默认9)
  416. */
  417. public function guess_manga()
  418. {
  419. $id = intval($this->_param['id'] ?? 0);
  420. $tid = intval($this->_param['tid'] ?? 0);
  421. $num = intval($this->_param['num'] ?? 9);
  422. if ($num < 1 || $num > 20) $num = 9;
  423. $where = ['manga_status' => ['eq', 1]];
  424. if ($id > 0) $where['manga_id'] = ['neq', $id];
  425. if ($tid > 0) $where['type_id'] = $tid;
  426. $order = 'manga_hits desc, manga_id desc';
  427. $page = mt_rand(1, max(1, 5));
  428. $res = model('Manga')->listData($where, $order, $page, $num, 0, '*', 1);
  429. if ($res['code'] != 1) {
  430. return json($res);
  431. }
  432. $list = [];
  433. foreach ($res['list'] as $v) {
  434. $ep = 0;
  435. if (!empty($v['manga_chapter_from']) && !empty($v['manga_chapter_url'])) {
  436. $pl = mac_manga_list($v['manga_chapter_from'], $v['manga_chapter_url'], $v['manga_play_server'] ?? '', $v['manga_play_note'] ?? '');
  437. foreach ($pl as $f) {
  438. if (!empty($f['urls']) && is_array($f['urls'])) $ep += count($f['urls']);
  439. }
  440. }
  441. $list[] = [
  442. 'manga_id' => $v['manga_id'],
  443. 'manga_name' => $v['manga_name'],
  444. 'manga_pic' => mac_url_img($v['manga_pic']),
  445. 'link' => mac_url_manga_detail($v),
  446. 'ep_count' => (int)$ep,
  447. ];
  448. }
  449. return json(['code' => 1, 'msg' => lang('data_list'), 'list' => $list]);
  450. }
  451. /**
  452. * 文章猜你喜欢 - 换一换 AJAX 接口
  453. * 参数: id=当前文章ID, tid=分类ID(可选), num=数量(默认9)
  454. */
  455. public function guess_art()
  456. {
  457. $id = intval($this->_param['id'] ?? 0);
  458. $tid = intval($this->_param['tid'] ?? 0);
  459. $num = intval($this->_param['num'] ?? 9);
  460. if ($num < 1 || $num > 20) $num = 9;
  461. $where = ['art_status' => ['eq', 1]];
  462. if ($id > 0) $where['art_id'] = ['neq', $id];
  463. if ($tid > 0) $where['type_id'] = $tid;
  464. $order = 'art_hits desc, art_id desc';
  465. $page = mt_rand(1, max(1, 5));
  466. $res = model('Art')->listData($where, $order, $page, $num, 0, '*', 1);
  467. if ($res['code'] != 1) {
  468. return json($res);
  469. }
  470. $list = [];
  471. foreach ($res['list'] as $v) {
  472. $pageTotal = 0;
  473. if (!empty($v['art_content'])) {
  474. $pageTotal = count(explode('$$$', $v['art_content']));
  475. }
  476. $list[] = [
  477. 'art_id' => $v['art_id'],
  478. 'art_name' => $v['art_name'],
  479. 'art_pic' => mac_url_img($v['art_pic']),
  480. 'link' => mac_url_art_detail($v),
  481. 'page_total' => (int)$pageTotal,
  482. ];
  483. }
  484. return json(['code' => 1, 'msg' => lang('data_list'), 'list' => $list]);
  485. }
  486. /**
  487. * 首页热门 tab 分段加载
  488. * 参数: tab=2..7
  489. */
  490. public function home_hot_tab()
  491. {
  492. $tab = intval(input('param.tab/d', 0));
  493. if ($tab <= 0) {
  494. $tab = intval($this->_param['id'] ?? 0);
  495. }
  496. if ($tab < 2 || $tab > 7) {
  497. return json(['code' => 1001, 'msg' => lang('param_err')]);
  498. }
  499. $vars = $this->buildIndexThemeVars();
  500. $data = $this->buildHomeHotTabData($tab, $vars);
  501. return json(['code' => 1, 'msg' => 'ok', 'data' => $data]);
  502. }
  503. /**
  504. * 构造首页主题变量(供首页 AJAX 片段使用)
  505. */
  506. protected function buildIndexThemeVars()
  507. {
  508. $tplconfig = isset($GLOBALS['mctheme']) && is_array($GLOBALS['mctheme'])
  509. ? $GLOBALS['mctheme']
  510. : (config('mctheme') ?: ['theme' => []]);
  511. $theme = isset($tplconfig['theme']) && is_array($tplconfig['theme']) ? $tplconfig['theme'] : [];
  512. $mangaTheme = isset($theme['manga']) && is_array($theme['manga']) ? $theme['manga'] : [];
  513. $mangaHbtn = (!isset($mangaTheme['hbtn']) || (string)($mangaTheme['hbtn']) !== '0') ? 1 : 0;
  514. $mangaHnumInt = (isset($mangaTheme['hnum']) && (string)$mangaTheme['hnum'] === '12') ? 12 : 6;
  515. $artTheme = isset($theme['art']) && is_array($theme['art']) ? $theme['art'] : [];
  516. $artHbtn = (!isset($artTheme['hbtn']) || (string)($artTheme['hbtn']) !== '0') ? 1 : 0;
  517. $artHnumInt = (isset($artTheme['hnum']) && (string)$artTheme['hnum'] === '12') ? 12 : 6;
  518. return [
  519. 'index_hotvod_tabs' => mac_theme_index_hotvod_tabs($theme),
  520. 'index_manga_hbtn' => $mangaHbtn,
  521. 'index_manga_hnum_str' => (string)$mangaHnumInt,
  522. 'index_manga_hot_txt_num' => (string)($mangaHnumInt * 2),
  523. 'index_manga_hot_txt_start' => (string)$mangaHnumInt,
  524. 'index_manga_poster_class' => mac_tpl_manga_cover() === 'h' ? 'mac-poster--h' : 'mac-poster--v',
  525. 'index_art_hbtn' => $artHbtn,
  526. 'index_art_hnum' => (string)$artHnumInt,
  527. 'index_art_hot_txt_num' => (string)($artHnumInt * 2),
  528. 'index_art_hot_txt_start' => (string)$artHnumInt,
  529. 'index_art_poster_class' => mac_tpl_art_cover() === 'h' ? 'mac-poster--h' : 'mac-poster--v',
  530. ];
  531. }
  532. protected function buildHomeHotTabData($tab, $vars)
  533. {
  534. if (in_array($tab, [2, 3, 4, 5], true)) {
  535. $tabs = isset($vars['index_hotvod_tabs']) && is_array($vars['index_hotvod_tabs']) ? $vars['index_hotvod_tabs'] : [];
  536. $idx = $tab - 2;
  537. $typeId = 0;
  538. if (isset($tabs[$idx]) && is_array($tabs[$idx])) {
  539. $typeId = intval($tabs[$idx]['id'] ?? 0);
  540. }
  541. return $this->buildVodHotTabData($tab, $typeId);
  542. }
  543. if ($tab === 6) {
  544. return $this->buildMangaHotTabData($tab, $vars);
  545. }
  546. return $this->buildArtHotTabData($tab, $vars);
  547. }
  548. protected function buildVodHotTabData($tab, $typeId)
  549. {
  550. if ($typeId <= 0) {
  551. return [
  552. 'tab' => $tab,
  553. 'content_type' => 'vod',
  554. 'append_remarks' => $tab === 2 ? 1 : 0,
  555. 'img_list' => [],
  556. 'txt_list' => [],
  557. ];
  558. }
  559. $where = ['vod_status' => ['eq', 1]];
  560. $ids = $this->resolveTypeIds($typeId);
  561. $where['type_id|type_id_1'] = ['in', implode(',', $ids)];
  562. $model = model('Vod');
  563. $imgRes = $model->listData($where, 'vod_hits_month desc', 1, 6, 0, '*', 1, 1);
  564. $txtRes = $model->listData($where, 'vod_hits_month desc', 1, 12, 6, '*', 1, 1);
  565. $imgList = [];
  566. $userId = intval($GLOBALS['user']['user_id'] ?? 0);
  567. $favMap = [];
  568. $vodIds = [];
  569. if (($imgRes['code'] ?? 0) == 1 && !empty($imgRes['list'])) {
  570. foreach ($imgRes['list'] as $v) {
  571. if (!empty($v['vod_id'])) {
  572. $vodIds[] = intval($v['vod_id']);
  573. }
  574. }
  575. if ($userId > 0 && !empty($vodIds)) {
  576. $favRows = model('Ulog')->where([
  577. 'user_id' => $userId,
  578. 'ulog_type' => 2,
  579. 'ulog_rid' => ['in', implode(',', array_unique($vodIds))],
  580. ])->column('ulog_id', 'ulog_rid');
  581. if (is_array($favRows)) {
  582. $favMap = $favRows;
  583. }
  584. }
  585. foreach ($imgRes['list'] as $v) {
  586. $classBadge = '';
  587. if (!empty($v['vod_class'])) {
  588. $parts = preg_split('/[\s,,\/|]+/u', (string)$v['vod_class'], -1, PREG_SPLIT_NO_EMPTY);
  589. if (!empty($parts)) {
  590. $classBadge = trim((string)$parts[0]);
  591. }
  592. }
  593. $vodId = intval($v['vod_id'] ?? 0);
  594. $favUid = isset($favMap[$vodId]) ? intval($favMap[$vodId]) : 0;
  595. $imgList[] = [
  596. 'name' => (string)($v['vod_name'] ?? ''),
  597. 'pic' => mac_url_img($v['vod_pic'] ?? ''),
  598. 'link' => mac_url_vod_detail($v),
  599. 'sub' => (string)($v['vod_sub'] ?? ''),
  600. 'id' => $vodId,
  601. 'points_play' => (string)($v['vod_points_play'] ?? ''),
  602. 'vod_class' => (string)($v['vod_class'] ?? ''),
  603. 'vod_area' => (string)($v['vod_area'] ?? ''),
  604. 'vod_year' => (string)($v['vod_year'] ?? ''),
  605. 'vod_actor' => (string)($v['vod_actor'] ?? ''),
  606. 'vod_blurb' => (string)($v['vod_blurb'] ?? ''),
  607. 'vod_isend' => intval($v['vod_isend'] ?? 0),
  608. 'type_is_vip_exclusive' => intval($v['type_is_vip_exclusive'] ?? 0),
  609. 'class_badge' => $classBadge,
  610. 'is_fav' => $favUid > 0 ? 1 : 0,
  611. 'fav_uid' => $favUid,
  612. ];
  613. }
  614. }
  615. $txtList = [];
  616. if (($txtRes['code'] ?? 0) == 1 && !empty($txtRes['list'])) {
  617. foreach ($txtRes['list'] as $v) {
  618. $txtList[] = [
  619. 'id' => intval($v['vod_id'] ?? 0),
  620. 'name' => (string)($v['vod_name'] ?? ''),
  621. 'link' => mac_url_vod_detail($v),
  622. 'time_md' => !empty($v['vod_time']) ? date('m-d', intval($v['vod_time'])) : '',
  623. 'remarks' => (string)($v['vod_remarks'] ?? ''),
  624. ];
  625. }
  626. }
  627. return [
  628. 'tab' => $tab,
  629. 'content_type' => 'vod',
  630. 'append_remarks' => $tab === 2 ? 1 : 0,
  631. 'img_list' => $imgList,
  632. 'txt_list' => $txtList,
  633. ];
  634. }
  635. protected function buildMangaHotTabData($tab, $vars)
  636. {
  637. if (intval($vars['index_manga_hbtn'] ?? 0) !== 1) {
  638. return ['tab' => $tab, 'content_type' => 'manga', 'img_list' => [], 'txt_list' => []];
  639. }
  640. $model = model('Manga');
  641. $imgRes = $model->listData(['manga_status' => ['eq', 1]], 'manga_hits_month desc', 1, intval($vars['index_manga_hnum_str']), 0, '*', 1, 1);
  642. $txtRes = $model->listData(['manga_status' => ['eq', 1]], 'manga_hits_month desc', 1, intval($vars['index_manga_hot_txt_num']), intval($vars['index_manga_hot_txt_start']), '*', 1, 1);
  643. $imgList = [];
  644. if (($imgRes['code'] ?? 0) == 1 && !empty($imgRes['list'])) {
  645. foreach ($imgRes['list'] as $v) {
  646. $imgList[] = [
  647. 'name' => (string)($v['manga_name'] ?? ''),
  648. 'pic' => mac_url_img($v['manga_pic'] ?? ''),
  649. 'link' => mac_url_manga_detail($v),
  650. 'sub' => (string)($v['manga_remarks'] ?? '连载中'),
  651. 'type_is_vip_exclusive' => intval($v['type_is_vip_exclusive'] ?? 0),
  652. 'manga_points' => (string)($v['manga_points'] ?? ''),
  653. ];
  654. }
  655. }
  656. $txtList = [];
  657. if (($txtRes['code'] ?? 0) == 1 && !empty($txtRes['list'])) {
  658. foreach ($txtRes['list'] as $v) {
  659. $txtList[] = [
  660. 'name' => (string)($v['manga_name'] ?? ''),
  661. 'link' => mac_url_manga_detail($v),
  662. 'time_md' => !empty($v['manga_time']) ? date('m-d', intval($v['manga_time'])) : '',
  663. ];
  664. }
  665. }
  666. return ['tab' => $tab, 'content_type' => 'manga', 'img_list' => $imgList, 'txt_list' => $txtList];
  667. }
  668. protected function buildArtHotTabData($tab, $vars)
  669. {
  670. if (intval($vars['index_art_hbtn'] ?? 0) !== 1) {
  671. return ['tab' => $tab, 'content_type' => 'art', 'img_list' => [], 'txt_list' => []];
  672. }
  673. $model = model('Art');
  674. $imgRes = $model->listData(['art_status' => ['eq', 1]], 'art_time desc', 1, intval($vars['index_art_hnum']), 0, '*', 1, 1);
  675. $txtRes = $model->listData(['art_status' => ['eq', 1]], 'art_time desc', 1, intval($vars['index_art_hot_txt_num']), intval($vars['index_art_hot_txt_start']), '*', 1, 1);
  676. $imgList = [];
  677. if (($imgRes['code'] ?? 0) == 1 && !empty($imgRes['list'])) {
  678. foreach ($imgRes['list'] as $v) {
  679. $imgList[] = [
  680. 'name' => (string)($v['art_name'] ?? ''),
  681. 'pic' => mac_url_img($v['art_pic'] ?? ''),
  682. 'link' => mac_url_art_detail($v),
  683. 'sub' => (string)($v['art_actor'] ?? ''),
  684. 'type_is_vip_exclusive' => intval($v['type_is_vip_exclusive'] ?? 0),
  685. 'art_points' => (string)($v['art_points'] ?? ''),
  686. 'art_remarks' => (string)($v['art_remarks'] ?? ''),
  687. ];
  688. }
  689. }
  690. $txtList = [];
  691. if (($txtRes['code'] ?? 0) == 1 && !empty($txtRes['list'])) {
  692. foreach ($txtRes['list'] as $v) {
  693. $txtList[] = [
  694. 'name' => (string)($v['art_name'] ?? ''),
  695. 'link' => mac_url_art_detail($v),
  696. 'time_md' => !empty($v['art_time']) ? date('m-d', intval($v['art_time'])) : '',
  697. ];
  698. }
  699. }
  700. return ['tab' => $tab, 'content_type' => 'art', 'img_list' => $imgList, 'txt_list' => $txtList];
  701. }
  702. protected function resolveTypeIds($typeId)
  703. {
  704. $typeId = intval($typeId);
  705. if ($typeId <= 0) {
  706. return [];
  707. }
  708. $typeList = model('Type')->getCache('type_list');
  709. $info = is_array($typeList) && isset($typeList[$typeId]) ? $typeList[$typeId] : [];
  710. if (empty($info)) {
  711. return [$typeId];
  712. }
  713. if (intval($info['type_pid'] ?? 0) === 0 && !empty($info['childids'])) {
  714. $childids = array_filter(array_map('intval', explode(',', (string)$info['childids'])));
  715. return empty($childids) ? [$typeId] : $childids;
  716. }
  717. return [intval($info['type_id'] ?? $typeId)];
  718. }
  719. public function verify_check()
  720. {
  721. $param = input();
  722. if(!in_array($param['type'],['search','show'])){
  723. return ['code' => 1001, 'msg' => lang('param_err')];
  724. }
  725. if (!captcha_check($param['verify'])){
  726. return ['code' => 1002, 'msg' => lang('verify_err')];
  727. }
  728. session($param['type'].'_verify','1');
  729. return json(['code'=>1,'msg'=>lang('ok')]);
  730. }
  731. }