Provide.php 32 KB

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