Provide.php 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745
  1. <?php
  2. namespace app\api\controller;
  3. use think\Controller;
  4. use think\Cache;
  5. class Provide extends Base
  6. {
  7. var $_param;
  8. public function __construct()
  9. {
  10. parent::__construct();
  11. $this->_param = input('','','trim,urldecode');
  12. // 因搜索兼容性问题暂时移除
  13. // if(isset($GLOBALS['config']['app']['input_type']) && $GLOBALS['config']['app']['input_type'] == 0 && request()->isPost()){
  14. // $this->_param = input('get.');
  15. // }
  16. }
  17. public function index()
  18. {
  19. }
  20. public function vod()
  21. {
  22. if($GLOBALS['config']['api']['vod']['status'] != 1){
  23. echo 'closed';
  24. exit;
  25. }
  26. if($GLOBALS['config']['api']['vod']['charge'] == 1) {
  27. $h = $_SERVER['REMOTE_ADDR'];
  28. if (!$h) {
  29. echo lang('api/auth_err');
  30. exit;
  31. }
  32. else {
  33. $auth = $GLOBALS['config']['api']['vod']['auth'];
  34. $this->checkDomainAuth($auth);
  35. }
  36. }
  37. $cache_time = intval($GLOBALS['config']['api']['vod']['cachetime']);
  38. $cach_name = $GLOBALS['config']['app']['cache_flag']. '_'.'api_vod_'.md5(http_build_query($this->_param));
  39. $html = Cache::get($cach_name);
  40. if(empty($html) || $cache_time==0) {
  41. $where = [];
  42. if (!empty($this->_param['ids'])) {
  43. $where['vod_id'] = ['in', $this->_param['ids']];
  44. }
  45. if (!empty($GLOBALS['config']['api']['vod']['typefilter'])) {
  46. $where['type_id'] = ['in', $GLOBALS['config']['api']['vod']['typefilter']];
  47. }
  48. if (!empty($this->_param['t'])) {
  49. if (empty($GLOBALS['config']['api']['vod']['typefilter']) || strpos($GLOBALS['config']['api']['vod']['typefilter'], $this->_param['t']) !== false) {
  50. $where['type_id'] = $this->_param['t'];
  51. }
  52. }
  53. if (!empty($this->_param['h'])) {
  54. $todaydate = date('Y-m-d', strtotime('+1 days'));
  55. $tommdate = date('Y-m-d H:i:s', strtotime('-' . $this->_param['h'] . ' hours'));
  56. $todayunix = strtotime($todaydate);
  57. $tommunix = strtotime($tommdate);
  58. $where['vod_time'] = [['gt', $tommunix], ['lt', $todayunix]];
  59. }
  60. if (!empty($this->_param['wd'])) {
  61. $where['vod_name'] = ['like', '%' . $this->_param['wd'] . '%'];
  62. }
  63. if (empty($GLOBALS['config']['api']['vod']['from']) && !empty($this->_param['from'])) {
  64. $GLOBALS['config']['api']['vod']['from'] = $this->_param['from'];
  65. }
  66. if (!empty($GLOBALS['config']['api']['vod']['from'])) {
  67. $where['vod_play_from'] = ['like', '%' . $GLOBALS['config']['api']['vod']['from'] . '%'];
  68. }
  69. if (!empty($GLOBALS['config']['api']['vod']['datafilter'])) {
  70. $where['_string'] .= ' ' . $GLOBALS['config']['api']['vod']['datafilter'];
  71. }
  72. if (empty($this->_param['pg'])) {
  73. $this->_param['pg'] = 1;
  74. }
  75. $order = 'vod_time desc';
  76. $field = 'vod_id,vod_name,type_id,"" as type_name,vod_en,vod_time,vod_remarks,vod_play_from,vod_time';
  77. if ($this->_param['ac'] == 'videolist' || $this->_param['ac'] == 'detail') {
  78. $field = '*';
  79. }
  80. $res = model('vod')->listData($where, $order, $this->_param['pg'], $GLOBALS['config']['api']['vod']['pagesize'], 0, $field, 0);
  81. if ($this->_param['at'] == 'xml') {
  82. $html = $this->vod_xml($res);
  83. } else {
  84. $html = json_encode($this->vod_json($res),JSON_UNESCAPED_UNICODE);
  85. }
  86. $html = mac_filter_tags($html);
  87. if($cache_time>0) {
  88. Cache::set($cach_name, $html, $cache_time);
  89. }
  90. }
  91. echo $html;
  92. exit;
  93. }
  94. public function vod_url_deal($urls,$froms,$from,$flag)
  95. {
  96. $res_xml = '';
  97. $res_json = [];
  98. $arr1 = explode("$$$",$urls); $arr1count = count($arr1);
  99. $arr2 = explode("$$$",$froms); $arr2count = count($arr2);
  100. for ($i=0;$i<$arr2count;$i++){
  101. if ($arr1count >= $i){
  102. if($from!=''){
  103. if($arr2[$i]==$from){
  104. $res_xml .= '<dd flag="'. $arr2[$i] .'"><![CDATA[' . $arr1[$i]. ']]></dd>';
  105. $res_json[$arr2[$i]] = $arr1[$i];
  106. }
  107. }
  108. else{
  109. $res_xml .= '<dd flag="'. $arr2[$i] .'"><![CDATA[' . $arr1[$i]. ']]></dd>';
  110. $res_json[$arr2[$i]] = $arr1[$i];
  111. }
  112. }
  113. }
  114. $res = str_replace(array(chr(10),chr(13)),array('','#'),$res_xml);
  115. return $flag=='xml' ? $res_xml : $res_json;
  116. }
  117. public function vod_json($res)
  118. {
  119. $type_list = model('Type')->getCache('type_list');
  120. foreach($res['list'] as $k=>&$v){
  121. $type_info = $type_list[$v['type_id']];
  122. $v['type_name'] = $type_info['type_name'];
  123. $v['vod_time'] = date('Y-m-d H:i:s',$v['vod_time']);
  124. if(substr($v["vod_pic"],0,4)=="mac:"){
  125. $v["vod_pic"] = str_replace('mac:','http:',$v["vod_pic"]);
  126. }
  127. elseif(!empty($v["vod_pic"]) && substr($v["vod_pic"],0,4)!="http" && substr($v["vod_pic"],0,2)!="//"){
  128. $v["vod_pic"] = $GLOBALS['config']['api']['vod']['imgurl'] . $v["vod_pic"];
  129. }
  130. if($this->_param['ac']=='videolist' || $this->_param['ac']=='detail'){
  131. if ($GLOBALS['config']['api']['vod']['from'] != '') {
  132. $arr_from = explode('$$$',$v['vod_play_from']);
  133. $arr_url = explode('$$$',$v['vod_play_url']);
  134. $arr_server = explode('$$$',$v['vod_play_server']);
  135. $arr_note = explode('$$$',$v['vod_play_note']);
  136. $key = array_search($GLOBALS['config']['api']['vod']['from'],$arr_from);
  137. $res['list'][$k]['vod_play_from'] = $GLOBALS['config']['api']['vod']['from'];
  138. $res['list'][$k]['vod_play_url'] = $arr_url[$key];
  139. $res['list'][$k]['vod_play_server'] = $arr_server[$key];
  140. $res['list'][$k]['vod_play_note'] = $arr_note[$key];
  141. }
  142. }
  143. else {
  144. if ($GLOBALS['config']['api']['vod']['from'] != '') {
  145. $res['list'][$k]['vod_play_from'] = $GLOBALS['config']['api']['vod']['from'];
  146. } else {
  147. $res['list'][$k]['vod_play_from'] = str_replace('$$$', ',', $v['vod_play_from']);
  148. }
  149. }
  150. }
  151. if($this->_param['ac']!='videolist' && $this->_param['ac']!='detail') {
  152. $class = [];
  153. $typefilter = explode(',',$GLOBALS['config']['api']['vod']['typefilter']);
  154. foreach ($type_list as $k=>&$v) {
  155. if (!empty($GLOBALS['config']['api']['vod']['typefilter'])){
  156. if(in_array($v['type_id'],$typefilter)) {
  157. $class[] = ['type_id' => $v['type_id'], 'type_pid' => $v['type_pid'], 'type_name' => $v['type_name']];
  158. }
  159. }
  160. else {
  161. $class[] = ['type_id' => $v['type_id'], 'type_pid' => $v['type_pid'], 'type_name' => $v['type_name']];
  162. }
  163. }
  164. $res['class'] = $class;
  165. }
  166. return $res;
  167. }
  168. public function vod_xml($res)
  169. {
  170. $xml = '<?xml version="1.0" encoding="utf-8"?>';
  171. $xml .= '<rss version="5.1">';
  172. $type_list = model('Type')->getCache('type_list');
  173. //视频列表开始
  174. $xml .= '<list page="'.$res['page'].'" pagecount="'.$res['pagecount'].'" pagesize="'.$res['limit'].'" recordcount="'.$res['total'].'">';
  175. foreach($res['list'] as $k=>&$v){
  176. $type_info = $type_list[$v['type_id']];
  177. $xml .= '<video>';
  178. $xml .= '<last>'.date('Y-m-d H:i:s',$v['vod_time']).'</last>';
  179. $xml .= '<id>'.$v['vod_id'].'</id>';
  180. $xml .= '<tid>'.$v['type_id'].'</tid>';
  181. $xml .= '<name><![CDATA['.$v['vod_name'].']]></name>';
  182. $xml .= '<type>'.$type_info['type_name'].'</type>';
  183. if(substr($v["vod_pic"],0,4)=="mac:"){
  184. $v["vod_pic"] = str_replace('mac:','http:',$v["vod_pic"]);
  185. }
  186. elseif(!empty($v["vod_pic"]) && substr($v["vod_pic"],0,4)!="http" && substr($v["vod_pic"],0,2)!="//"){
  187. $v["vod_pic"] = $GLOBALS['config']['api']['vod']['imgurl'] . $v["vod_pic"];
  188. }
  189. if($this->_param['ac']=='videolist' || $this->_param['ac']=='detail'){
  190. $tempurl = $this->vod_url_deal($v["vod_play_url"],$v["vod_play_from"],$GLOBALS['config']['api']['vod']['from'],'xml');
  191. $xml .= '<pic>'.$v["vod_pic"].'</pic>';
  192. $xml .= '<lang>'.$v['vod_lang'].'</lang>';
  193. $xml .= '<area>'.$v['vod_area'].'</area>';
  194. $xml .= '<year>'.$v['vod_year'].'</year>';
  195. $xml .= '<state>'.$v['vod_serial'].'</state>';
  196. $xml .= '<note><![CDATA['.$v['vod_remarks'].']]></note>';
  197. $xml .= '<actor><![CDATA['.$v['vod_actor'].']]></actor>';
  198. $xml .= '<director><![CDATA['.$v['vod_director'].']]></director>';
  199. $xml .= '<dl>'.$tempurl.'</dl>';
  200. $xml .= '<des><![CDATA['.$v['vod_content'].']]></des>';
  201. }
  202. else {
  203. if ($GLOBALS['config']['api']['vod']['from'] != ''){
  204. $xml .= '<dt>' . $GLOBALS['config']['api']['vod']['from'] . '</dt>';
  205. }
  206. else{
  207. $xml .= '<dt>' . str_replace('$$$', ',', $v['vod_play_from']) . '</dt>';
  208. }
  209. $xml .= '<note><![CDATA[' . $v['vod_remarks'] . ']]></note>';
  210. }
  211. $xml .= '</video>';
  212. }
  213. $xml .= '</list>';
  214. //视频列表结束
  215. if($this->_param['ac'] != 'videolist' && $this->_param['ac']!='detail') {
  216. //分类列表开始
  217. $xml .= "<class>";
  218. $typefilter = explode(',',$GLOBALS['config']['api']['vod']['typefilter']);
  219. foreach ($type_list as $k=>&$v) {
  220. if($v['type_mid']==1) {
  221. if (!empty($GLOBALS['config']['api']['vod']['typefilter'])){
  222. if(in_array($v['type_id'],$typefilter)) {
  223. $xml .= "<ty id=\"" . $v["type_id"] . "\">" . $v["type_name"] . "</ty>";
  224. }
  225. }
  226. else {
  227. $xml .= "<ty id=\"" . $v["type_id"] . "\">" . $v["type_name"] . "</ty>";
  228. }
  229. }
  230. }
  231. unset($rs);
  232. $xml .= "</class>";
  233. //分类列表结束
  234. }
  235. $xml .= "</rss>";
  236. return $xml;
  237. }
  238. public function art()
  239. {
  240. if($GLOBALS['config']['api']['art']['status'] != 1){
  241. echo 'closed';die;
  242. }
  243. if($GLOBALS['config']['api']['art']['charge'] == 1) {
  244. $h = $_SERVER['REMOTE_ADDR'];
  245. if (!$h) {
  246. echo lang('api/auth_err');
  247. exit;
  248. }
  249. else {
  250. $auth = $GLOBALS['config']['api']['art']['auth'];
  251. $this->checkDomainAuth($auth);
  252. }
  253. }
  254. $cache_time = intval($GLOBALS['config']['api']['art']['cachetime']);
  255. $cach_name = $GLOBALS['config']['app']['cache_flag']. '_'.'api_art_'.md5(http_build_query($this->_param));
  256. $html = Cache::get($cach_name);
  257. if(empty($html) || $cache_time==0) {
  258. $where = [];
  259. if (!empty($this->_param['ids'])) {
  260. $where['art_id'] = ['in', $this->_param['ids']];
  261. }
  262. if (!empty($this->_param['t'])) {
  263. if (empty($GLOBALS['config']['api']['art']['typefilter']) || strpos($GLOBALS['config']['api']['art']['typefilter'], $this->_param['t']) !== false) {
  264. $where['type_id'] = $this->_param['t'];
  265. }
  266. }
  267. if (!empty(intval($this->_param['h']))) {
  268. $todaydate = date('Y-m-d', strtotime('+1 days'));
  269. $tommdate = date('Y-m-d', strtotime('-' . $this->_param['h'] . ' hours'));
  270. $todayunix = strtotime($todaydate);
  271. $tommunix = strtotime($tommdate);
  272. $where['art_time'] = [['gt', $tommunix], ['lt', $todayunix]];
  273. }
  274. if (!empty($this->_param['wd'])) {
  275. $where['art_name'] = ['like', '%' . $this->_param['wd'] . '%'];
  276. }
  277. if (!empty($GLOBALS['config']['api']['art']['datafilter'])) {
  278. $where['_string'] = $GLOBALS['config']['api']['art']['datafilter'];
  279. }
  280. if (empty(intval($this->_param['pg']))) {
  281. $this->_param['pg'] = 1;
  282. }
  283. $order = 'art_time desc';
  284. $field = 'art_id,art_name,type_id,"" as type_name,art_en,art_time,art_author,art_from,art_remarks,art_pic,art_time';
  285. if ($this->_param['ac'] == 'detail') {
  286. $field = '*';
  287. }
  288. $res = model('art')->listData($where, $order, $this->_param['pg'], $GLOBALS['config']['api']['art']['pagesize'], 0, $field, 0);
  289. if ($res['code'] > 1) {
  290. echo $res['msg'];
  291. exit;
  292. }
  293. $type_list = model('Type')->getCache('type_list');
  294. foreach ($res['list'] as $k => &$v) {
  295. $type_info = $type_list[$v['type_id']];
  296. $v['type_name'] = $type_info['type_name'];
  297. $v['art_time'] = date('Y-m-d H:i:s', $v['art_time']);
  298. if (substr($v["art_pic"], 0, 4) == "mac:") {
  299. $v["art_pic"] = str_replace('mac:', $this->getImgUrlProtocol('art'), $v["art_pic"]);
  300. } elseif (!empty($v["art_pic"]) && substr($v["art_pic"], 0, 4) != "http" && substr($v["art_pic"], 0, 2) != "//") {
  301. $v["art_pic"] = $GLOBALS['config']['api']['art']['imgurl'] . $v["art_pic"];
  302. }
  303. if ($this->_param['ac'] == 'detail') {
  304. } else {
  305. }
  306. }
  307. if ($this->_param['ac'] != 'detail') {
  308. $class = [];
  309. $typefilter = explode(',', $GLOBALS['config']['api']['art']['typefilter']);
  310. foreach ($type_list as $k => &$v) {
  311. if ($v['type_mid'] == 2) {
  312. if (!empty($GLOBALS['config']['api']['art']['typefilter'])) {
  313. if (in_array($v['type_id'], $typefilter)) {
  314. $class[] = ['type_id' => $v['type_id'], 'type_pid' => $v['type_pid'], 'type_name' => $v['type_name']];
  315. }
  316. } else {
  317. $class[] = ['type_id' => $v['type_id'], 'type_pid' => $v['type_pid'], 'type_name' => $v['type_name']];
  318. }
  319. }
  320. }
  321. $res['class'] = $class;
  322. }
  323. $html = json_encode($res,JSON_UNESCAPED_UNICODE);
  324. $html = mac_filter_tags($html);
  325. if($cache_time>0) {
  326. Cache::set($cach_name, $html, $cache_time);
  327. }
  328. }
  329. echo $html;
  330. exit;
  331. }
  332. public function actor()
  333. {
  334. if($GLOBALS['config']['api']['actor']['status'] != 1){
  335. echo 'closed';die;
  336. }
  337. if($GLOBALS['config']['api']['actor']['charge'] == 1) {
  338. $h = $_SERVER['REMOTE_ADDR'];
  339. if (!$h) {
  340. echo lang('api/auth_err');
  341. exit;
  342. }
  343. else {
  344. $auth = $GLOBALS['config']['api']['actor']['auth'];
  345. $this->checkDomainAuth($auth);
  346. }
  347. }
  348. $cache_time = intval($GLOBALS['config']['api']['actor']['cachetime']);
  349. $cach_name = $GLOBALS['config']['app']['cache_flag']. '_'.'api_actor_'.md5(http_build_query($this->_param));
  350. $html = Cache::get($cach_name);
  351. if(empty($html) || $cache_time==0) {
  352. $where = [];
  353. if (!empty($this->_param['ids'])) {
  354. $where['actor_id'] = ['in', $this->_param['ids']];
  355. }
  356. if (!empty($this->_param['t'])) {
  357. if (empty($GLOBALS['config']['api']['actor']['typefilter']) || strpos($GLOBALS['config']['api']['actor']['typefilter'], $this->_param['t']) !== false) {
  358. $where['type_id'] = $this->_param['t'];
  359. }
  360. }
  361. if (!empty(intval($this->_param['h']))) {
  362. $todaydate = date('Y-m-d', strtotime('+1 days'));
  363. $tommdate = date('Y-m-d', strtotime('-' . $this->_param['h'] . ' hours'));
  364. $todayunix = strtotime($todaydate);
  365. $tommunix = strtotime($tommdate);
  366. $where['actor_time'] = [['gt', $tommunix], ['lt', $todayunix]];
  367. }
  368. if (!empty($this->_param['wd'])) {
  369. $where['actor_name'] = ['like', '%' . $this->_param['wd'] . '%'];
  370. }
  371. if (!empty($GLOBALS['config']['api']['actor']['datafilter'])) {
  372. $where['_string'] = $GLOBALS['config']['api']['actor']['datafilter'];
  373. }
  374. if (empty(intval($this->_param['pg']))) {
  375. $this->_param['pg'] = 1;
  376. }
  377. $order = 'actor_time desc';
  378. $field = 'actor_id,actor_name,type_id,"" as type_name,actor_en,actor_area,actor_time,actor_alias,actor_sex,actor_pic';
  379. if ($this->_param['ac'] == 'detail') {
  380. $field = '*';
  381. }
  382. $res = model('actor')->listData($where, $order, $this->_param['pg'], $GLOBALS['config']['api']['actor']['pagesize'], 0, $field, 0);
  383. if ($res['code'] > 1) {
  384. echo $res['msg'];
  385. exit;
  386. }
  387. $type_list = model('Type')->getCache('type_list');
  388. foreach ($res['list'] as $k => &$v) {
  389. $type_info = $type_list[$v['type_id']];
  390. $v['type_name'] = $type_info['type_name'];
  391. $v['actor_time'] = date('Y-m-d H:i:s', $v['actor_time']);
  392. if (substr($v["actor_pic"], 0, 4) == "mac:") {
  393. $v["actor_pic"] = str_replace('mac:', $this->getImgUrlProtocol('actor'), $v["actor_pic"]);
  394. } elseif (!empty($v["actor_pic"]) && substr($v["actor_pic"], 0, 4) != "http" && substr($v["actor_pic"], 0, 2) != "//") {
  395. $v["actor_pic"] = $GLOBALS['config']['api']['actor']['imgurl'] . $v["actor_pic"];
  396. }
  397. if ($this->_param['ac'] == 'detail') {
  398. } else {
  399. }
  400. }
  401. if ($this->_param['ac'] != 'detail') {
  402. $class = [];
  403. $typefilter = explode(',', $GLOBALS['config']['api']['actor']['typefilter']);
  404. foreach ($type_list as $k => &$v) {
  405. if ($v['type_mid'] == 8) {
  406. if (!empty($GLOBALS['config']['api']['actor']['typefilter'])) {
  407. if (in_array($v['type_id'], $typefilter)) {
  408. $class[] = ['type_id' => $v['type_id'], 'type_pid' => $v['type_pid'], 'type_name' => $v['type_name']];
  409. }
  410. } else {
  411. $class[] = ['type_id' => $v['type_id'], 'type_pid' => $v['type_pid'], 'type_name' => $v['type_name']];
  412. }
  413. }
  414. }
  415. $res['class'] = $class;
  416. }
  417. $html = json_encode($res,JSON_UNESCAPED_UNICODE);
  418. $html = mac_filter_tags($html);
  419. if($cache_time>0) {
  420. Cache::set($cach_name, $html, $cache_time);
  421. }
  422. }
  423. echo $html;
  424. exit;
  425. }
  426. public function role()
  427. {
  428. if($GLOBALS['config']['api']['role']['status'] != 1){
  429. echo 'closed';die;
  430. }
  431. if($GLOBALS['config']['api']['role']['charge'] == 1) {
  432. $h = $_SERVER['REMOTE_ADDR'];
  433. if (!$h) {
  434. echo lang('api/auth_err');
  435. exit;
  436. }
  437. else {
  438. $auth = $GLOBALS['config']['api']['role']['auth'];
  439. $this->checkDomainAuth($auth);
  440. }
  441. }
  442. $cache_time = intval($GLOBALS['config']['api']['role']['cachetime']);
  443. $cach_name = $GLOBALS['config']['app']['cache_flag']. '_'.'api_role_'.md5(http_build_query($this->_param));
  444. $html = Cache::get($cach_name);
  445. if(empty($html) || $cache_time==0) {
  446. $where = [];
  447. if (!empty($this->_param['ids'])) {
  448. $where['role_id'] = ['in', $this->_param['ids']];
  449. }
  450. if (!empty($this->_param['t'])) {
  451. if (empty($GLOBALS['config']['api']['role']['typefilter']) || strpos($GLOBALS['config']['api']['role']['typefilter'], $this->_param['t']) !== false) {
  452. $where['type_id'] = $this->_param['t'];
  453. }
  454. }
  455. if (!empty(intval($this->_param['h']))) {
  456. $todaydate = date('Y-m-d', strtotime('+1 days'));
  457. $tommdate = date('Y-m-d', strtotime('-' . $this->_param['h'] . ' hours'));
  458. $todayunix = strtotime($todaydate);
  459. $tommunix = strtotime($tommdate);
  460. $where['role_time'] = [['gt', $tommunix], ['lt', $todayunix]];
  461. }
  462. if (!empty($this->_param['wd'])) {
  463. $where['role_name'] = ['like', '%' . $this->_param['wd'] . '%'];
  464. }
  465. if (!empty($GLOBALS['config']['api']['role']['datafilter'])) {
  466. $where['_string'] = $GLOBALS['config']['api']['role']['datafilter'];
  467. }
  468. if (empty(intval($this->_param['pg']))) {
  469. $this->_param['pg'] = 1;
  470. }
  471. $order = 'role_time desc';
  472. $field = 'role_id,role_name,role_rid,role_en,role_actor,role_time,role_pic';
  473. if ($this->_param['ac'] == 'detail') {
  474. $field = '*';
  475. }
  476. $res = model('role')->listData($where, $order, $this->_param['pg'], $GLOBALS['config']['api']['role']['pagesize'], 0, $field, 1);
  477. if ($res['code'] > 1) {
  478. echo $res['msg'];
  479. exit;
  480. }
  481. foreach ($res['list'] as $k => &$v) {
  482. $v['role_time'] = date('Y-m-d H:i:s', $v['role_time']);
  483. $v['douban_id'] = $v['data']['vod_douban_id'];
  484. $v['vod_name'] = $v['data']['vod_name'];
  485. $v['vod_director'] = $v['data']['vod_director'];
  486. unset($v['data']);
  487. if (substr($v["role_pic"], 0, 4) == "mac:") {
  488. $v["role_pic"] = str_replace('mac:', $this->getImgUrlProtocol('role'), $v["role_pic"]);
  489. } elseif (!empty($v["role_pic"]) && substr($v["role_pic"], 0, 4) != "http" && substr($v["role_pic"], 0, 2) != "//") {
  490. $v["role_pic"] = $GLOBALS['config']['api']['role']['imgurl'] . $v["role_pic"];
  491. }
  492. if ($this->_param['ac'] == 'detail') {
  493. } else {
  494. }
  495. }
  496. if ($this->_param['ac'] != 'detail') {
  497. $class = [];
  498. $typefilter = explode(',', $GLOBALS['config']['api']['role']['typefilter']);
  499. $res['class'] = $class;
  500. }
  501. $html = json_encode($res,JSON_UNESCAPED_UNICODE);
  502. $html = mac_filter_tags($html);
  503. if($cache_time>0) {
  504. Cache::set($cach_name, $html, $cache_time);
  505. }
  506. }
  507. echo $html;
  508. exit;
  509. }
  510. public function website()
  511. {
  512. if($GLOBALS['config']['api']['website']['status'] != 1){
  513. echo 'closed';die;
  514. }
  515. if($GLOBALS['config']['api']['website']['charge'] == 1) {
  516. $h = $_SERVER['REMOTE_ADDR'];
  517. if (!$h) {
  518. echo lang('api/auth_err');
  519. exit;
  520. }
  521. else {
  522. $auth = $GLOBALS['config']['api']['website']['auth'];
  523. $this->checkDomainAuth($auth);
  524. }
  525. }
  526. $cache_time = intval($GLOBALS['config']['api']['website']['cachetime']);
  527. $cach_name = $GLOBALS['config']['app']['cache_flag']. '_'.'api_website_'.md5(http_build_query($this->_param));
  528. $html = Cache::get($cach_name);
  529. if(empty($html) || $cache_time==0) {
  530. $where = [];
  531. if (!empty($this->_param['ids'])) {
  532. $where['website_id'] = ['in', $this->_param['ids']];
  533. }
  534. if (!empty($this->_param['t'])) {
  535. if (empty($GLOBALS['config']['api']['website']['typefilter']) || strpos($GLOBALS['config']['api']['website']['typefilter'], $this->_param['t']) !== false) {
  536. $where['type_id'] = $this->_param['t'];
  537. }
  538. }
  539. if (!empty(intval($this->_param['h']))) {
  540. $todaydate = date('Y-m-d', strtotime('+1 days'));
  541. $tommdate = date('Y-m-d', strtotime('-' . $this->_param['h'] . ' hours'));
  542. $todayunix = strtotime($todaydate);
  543. $tommunix = strtotime($tommdate);
  544. $where['website_time'] = [['gt', $tommunix], ['lt', $todayunix]];
  545. }
  546. if (!empty($this->_param['wd'])) {
  547. $where['website_name'] = ['like', '%' . $this->_param['wd'] . '%'];
  548. }
  549. if (!empty($GLOBALS['config']['api']['website']['datafilter'])) {
  550. $where['_string'] = $GLOBALS['config']['api']['website']['datafilter'];
  551. }
  552. if (empty(intval($this->_param['pg']))) {
  553. $this->_param['pg'] = 1;
  554. }
  555. $order = 'website_time desc';
  556. $field = 'website_id,website_name,type_id,"" as type_name,website_en,website_time,website_area,website_lang,website_pic';
  557. if ($this->_param['ac'] == 'detail') {
  558. $field = '*';
  559. }
  560. $res = model('website')->listData($where, $order, $this->_param['pg'], $GLOBALS['config']['api']['website']['pagesize'], 0, $field, 0);
  561. if ($res['code'] > 1) {
  562. echo $res['msg'];
  563. exit;
  564. }
  565. $type_list = model('Type')->getCache('type_list');
  566. foreach ($res['list'] as $k => &$v) {
  567. $type_info = $type_list[$v['type_id']];
  568. $v['type_name'] = $type_info['type_name'];
  569. $v['website_time'] = date('Y-m-d H:i:s', $v['website_time']);
  570. if (substr($v["website_pic"], 0, 4) == "mac:") {
  571. $v["website_pic"] = str_replace('mac:', $this->getImgUrlProtocol('website'), $v["website_pic"]);
  572. } elseif (!empty($v["website_pic"]) && substr($v["website_pic"], 0, 4) != "http" && substr($v["website_pic"], 0, 2) != "//") {
  573. $v["website_pic"] = $GLOBALS['config']['api']['website']['imgurl'] . $v["website_pic"];
  574. }
  575. if ($this->_param['ac'] == 'detail') {
  576. } else {
  577. }
  578. }
  579. if ($this->_param['ac'] != 'detail') {
  580. $class = [];
  581. $typefilter = explode(',', $GLOBALS['config']['api']['website']['typefilter']);
  582. foreach ($type_list as $k => &$v) {
  583. if ($v['type_mid'] == 11) {
  584. if (!empty($GLOBALS['config']['api']['website']['typefilter'])) {
  585. if (in_array($v['type_id'], $typefilter)) {
  586. $class[] = ['type_id' => $v['type_id'], 'type_pid' => $v['type_pid'], 'type_name' => $v['type_name']];
  587. }
  588. } else {
  589. $class[] = ['type_id' => $v['type_id'], 'type_pid' => $v['type_pid'], 'type_name' => $v['type_name']];
  590. }
  591. }
  592. }
  593. $res['class'] = $class;
  594. }
  595. $html = json_encode($res,JSON_UNESCAPED_UNICODE);
  596. $html = mac_filter_tags($html);
  597. if($cache_time>0) {
  598. Cache::set($cach_name, $html, $cache_time);
  599. }
  600. }
  601. echo $html;
  602. exit;
  603. }
  604. public function comment()
  605. {
  606. }
  607. private function checkDomainAuth($auth)
  608. {
  609. $ip = mac_get_client_ip();
  610. $auth_list = ['127.0.0.1'];
  611. if (!empty($auth)) {
  612. foreach (explode('#', $auth) as $domain) {
  613. $domain = trim($domain);
  614. $auth_list[] = $domain;
  615. if (!mac_string_is_ip($domain)) {
  616. $auth_list[] = gethostbyname($domain);
  617. }
  618. }
  619. $auth_list = array_unique($auth_list);
  620. $auth_list = array_filter($auth_list);
  621. }
  622. if (!in_array($ip, $auth_list)) {
  623. echo lang('api/auth_err');
  624. exit;
  625. }
  626. }
  627. private function getImgUrlProtocol($key)
  628. {
  629. if (!isset($GLOBALS['config']['api'][$key]['imgurl'])) {
  630. return 'http:';
  631. }
  632. if (substr($GLOBALS['config']['api'][$key]['imgurl'], 0, 5) == 'https') {
  633. return 'https:';
  634. }
  635. return 'http:';
  636. }
  637. }