Provide.php 34 KB

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