Provide.php 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997
  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. } else {
  207. if (!empty($GLOBALS['config']['api']['vod']['from'])) {
  208. // 准备数据,逐个处理
  209. $arr_from = explode('$$$', $v['vod_play_from']);
  210. $vod_play_from_list = explode(',', trim($GLOBALS['config']['api']['vod']['from']));
  211. $vod_play_from_list = array_unique($vod_play_from_list);
  212. $vod_play_from_list = array_filter($vod_play_from_list);
  213. foreach ($vod_play_from_list as $vod_play_from_index => $vod_play_from) {
  214. $key = array_search($vod_play_from, $arr_from);
  215. if ($key === false) {
  216. unset($vod_play_from_list[$vod_play_from_index]);
  217. continue;
  218. }
  219. }
  220. $res['list'][$k]['vod_play_from'] = join(',', $vod_play_from_list);
  221. } else {
  222. $res['list'][$k]['vod_play_from'] = str_replace('$$$', ',', $v['vod_play_from']);
  223. }
  224. }
  225. }
  226. if($this->_param['ac']!='videolist' && $this->_param['ac']!='detail') {
  227. $class = [];
  228. $typefilter = explode(',',$GLOBALS['config']['api']['vod']['typefilter']);
  229. foreach ($type_list as $k=>&$v) {
  230. if (!empty($GLOBALS['config']['api']['vod']['typefilter'])){
  231. if(in_array($v['type_id'],$typefilter)) {
  232. $class[] = ['type_id' => $v['type_id'], 'type_pid' => $v['type_pid'], 'type_name' => $v['type_name']];
  233. }
  234. }
  235. else {
  236. $class[] = ['type_id' => $v['type_id'], 'type_pid' => $v['type_pid'], 'type_name' => $v['type_name']];
  237. }
  238. }
  239. $res['class'] = $class;
  240. }
  241. return $res;
  242. }
  243. public function vod_xml($res)
  244. {
  245. $xml = '<?xml version="1.0" encoding="utf-8"?>';
  246. $xml .= '<rss version="5.1">';
  247. $type_list = model('Type')->getCache('type_list');
  248. //视频列表开始
  249. $xml .= '<list page="'.$res['page'].'" pagecount="'.$res['pagecount'].'" pagesize="'.$res['limit'].'" recordcount="'.$res['total'].'">';
  250. foreach($res['list'] as $k=>&$v){
  251. $type_info = $type_list[$v['type_id']];
  252. $xml .= '<video>';
  253. $xml .= '<last>'.date('Y-m-d H:i:s',$v['vod_time']).'</last>';
  254. $xml .= '<id>'.$v['vod_id'].'</id>';
  255. $xml .= '<tid>'.$v['type_id'].'</tid>';
  256. $xml .= '<name><![CDATA['.$v['vod_name'].']]></name>';
  257. $xml .= '<type>'.$type_info['type_name'].'</type>';
  258. if(substr($v["vod_pic"],0,4)=="mac:"){
  259. $v["vod_pic"] = str_replace('mac:',$this->getImgUrlProtocol('vod'), $v["vod_pic"]);
  260. }
  261. elseif(!empty($v["vod_pic"]) && substr($v["vod_pic"],0,4)!="http" && substr($v["vod_pic"],0,2)!="//"){
  262. $v["vod_pic"] = $GLOBALS['config']['api']['vod']['imgurl'] . $v["vod_pic"];
  263. }
  264. if($this->_param['ac']=='videolist' || $this->_param['ac']=='detail'){
  265. $tempurl = $this->vod_url_deal($v["vod_play_url"],$v["vod_play_from"],$GLOBALS['config']['api']['vod']['from'],'xml');
  266. $xml .= '<pic>'.$v["vod_pic"].'</pic>';
  267. $xml .= '<lang>'.$v['vod_lang'].'</lang>';
  268. $xml .= '<area>'.$v['vod_area'].'</area>';
  269. $xml .= '<year>'.$v['vod_year'].'</year>';
  270. $xml .= '<state>'.$v['vod_serial'].'</state>';
  271. $xml .= '<note><![CDATA['.$v['vod_remarks'].']]></note>';
  272. $xml .= '<actor><![CDATA['.$v['vod_actor'].']]></actor>';
  273. $xml .= '<director><![CDATA['.$v['vod_director'].']]></director>';
  274. $xml .= '<dl>'.$tempurl.'</dl>';
  275. $xml .= '<des><![CDATA['.$v['vod_content'].']]></des>';
  276. }
  277. else {
  278. if ($GLOBALS['config']['api']['vod']['from'] != ''){
  279. $xml .= '<dt>' . $GLOBALS['config']['api']['vod']['from'] . '</dt>';
  280. }
  281. else{
  282. $xml .= '<dt>' . str_replace('$$$', ',', $v['vod_play_from']) . '</dt>';
  283. }
  284. $xml .= '<note><![CDATA[' . $v['vod_remarks'] . ']]></note>';
  285. }
  286. $xml .= '</video>';
  287. }
  288. $xml .= '</list>';
  289. //视频列表结束
  290. if($this->_param['ac'] != 'videolist' && $this->_param['ac']!='detail') {
  291. //分类列表开始
  292. $xml .= "<class>";
  293. $typefilter = explode(',',$GLOBALS['config']['api']['vod']['typefilter']);
  294. foreach ($type_list as $k=>&$v) {
  295. if($v['type_mid']==1) {
  296. if (!empty($GLOBALS['config']['api']['vod']['typefilter'])){
  297. if(in_array($v['type_id'],$typefilter)) {
  298. $xml .= "<ty id=\"" . $v["type_id"] . "\">" . $v["type_name"] . "</ty>";
  299. }
  300. }
  301. else {
  302. $xml .= "<ty id=\"" . $v["type_id"] . "\">" . $v["type_name"] . "</ty>";
  303. }
  304. }
  305. }
  306. unset($rs);
  307. $xml .= "</class>";
  308. //分类列表结束
  309. }
  310. $xml .= "</rss>";
  311. return $xml;
  312. }
  313. public function art()
  314. {
  315. if($GLOBALS['config']['api']['art']['status'] != 1){
  316. echo 'closed';die;
  317. }
  318. if($GLOBALS['config']['api']['art']['charge'] == 1) {
  319. $h = $_SERVER['REMOTE_ADDR'];
  320. if (!$h) {
  321. echo lang('api/auth_err');
  322. exit;
  323. }
  324. else {
  325. $auth = $GLOBALS['config']['api']['art']['auth'];
  326. $this->checkDomainAuth($auth);
  327. }
  328. }
  329. $cache_time = intval($GLOBALS['config']['api']['art']['cachetime']);
  330. $cach_name = $GLOBALS['config']['app']['cache_flag']. '_'.'api_art_'.md5(http_build_query($this->_param));
  331. $html = Cache::get($cach_name);
  332. if(empty($html) || $cache_time==0) {
  333. $where = [];
  334. if (!empty($this->_param['ids'])) {
  335. $where['art_id'] = ['in', $this->_param['ids']];
  336. }
  337. if (!empty($this->_param['t'])) {
  338. if (empty($GLOBALS['config']['api']['art']['typefilter']) || strpos($GLOBALS['config']['api']['art']['typefilter'], $this->_param['t']) !== false) {
  339. $where['type_id'] = $this->_param['t'];
  340. }
  341. }
  342. if (!empty(intval($this->_param['h']))) {
  343. $todaydate = date('Y-m-d', strtotime('+1 days'));
  344. $tommdate = date('Y-m-d', strtotime('-' . $this->_param['h'] . ' hours'));
  345. $todayunix = strtotime($todaydate);
  346. $tommunix = strtotime($tommdate);
  347. $where['art_time'] = [['gt', $tommunix], ['lt', $todayunix]];
  348. }
  349. if (!empty($this->_param['wd'])) {
  350. $where['art_name'] = ['like', '%' . $this->_param['wd'] . '%'];
  351. }
  352. if (!empty($GLOBALS['config']['api']['art']['datafilter'])) {
  353. $where['_string'] = $GLOBALS['config']['api']['art']['datafilter'];
  354. }
  355. if (empty(intval($this->_param['pg']))) {
  356. $this->_param['pg'] = 1;
  357. }
  358. $order = 'art_time desc';
  359. $field = 'art_id,art_name,type_id,"" as type_name,art_en,art_time,art_author,art_from,art_remarks,art_pic,art_time';
  360. if ($this->_param['ac'] == 'detail') {
  361. $field = '*';
  362. }
  363. $res = model('art')->listData($where, $order, $this->_param['pg'], $GLOBALS['config']['api']['art']['pagesize'], 0, $field, 0);
  364. if ($res['code'] > 1) {
  365. echo $res['msg'];
  366. exit;
  367. }
  368. $type_list = model('Type')->getCache('type_list');
  369. foreach ($res['list'] as $k => &$v) {
  370. $type_info = $type_list[$v['type_id']];
  371. $v['type_name'] = $type_info['type_name'];
  372. $v['art_time'] = date('Y-m-d H:i:s', $v['art_time']);
  373. if (substr($v["art_pic"], 0, 4) == "mac:") {
  374. $v["art_pic"] = str_replace('mac:', $this->getImgUrlProtocol('art'), $v["art_pic"]);
  375. } elseif (!empty($v["art_pic"]) && substr($v["art_pic"], 0, 4) != "http" && substr($v["art_pic"], 0, 2) != "//") {
  376. $v["art_pic"] = $GLOBALS['config']['api']['art']['imgurl'] . $v["art_pic"];
  377. }
  378. if ($this->_param['ac'] == 'detail') {
  379. } else {
  380. }
  381. }
  382. if ($this->_param['ac'] != 'detail') {
  383. $class = [];
  384. $typefilter = explode(',', $GLOBALS['config']['api']['art']['typefilter']);
  385. foreach ($type_list as $k => &$v) {
  386. if ($v['type_mid'] == 2) {
  387. if (!empty($GLOBALS['config']['api']['art']['typefilter'])) {
  388. if (in_array($v['type_id'], $typefilter)) {
  389. $class[] = ['type_id' => $v['type_id'], 'type_pid' => $v['type_pid'], 'type_name' => $v['type_name']];
  390. }
  391. } else {
  392. $class[] = ['type_id' => $v['type_id'], 'type_pid' => $v['type_pid'], 'type_name' => $v['type_name']];
  393. }
  394. }
  395. }
  396. $res['class'] = $class;
  397. }
  398. $html = json_encode($res,JSON_UNESCAPED_UNICODE);
  399. $html = mac_filter_tags($html);
  400. if($cache_time>0) {
  401. Cache::set($cach_name, $html, $cache_time);
  402. }
  403. }
  404. echo $html;
  405. exit;
  406. }
  407. public function actor()
  408. {
  409. if($GLOBALS['config']['api']['actor']['status'] != 1){
  410. echo 'closed';die;
  411. }
  412. if($GLOBALS['config']['api']['actor']['charge'] == 1) {
  413. $h = $_SERVER['REMOTE_ADDR'];
  414. if (!$h) {
  415. echo lang('api/auth_err');
  416. exit;
  417. }
  418. else {
  419. $auth = $GLOBALS['config']['api']['actor']['auth'];
  420. $this->checkDomainAuth($auth);
  421. }
  422. }
  423. $cache_time = intval($GLOBALS['config']['api']['actor']['cachetime']);
  424. $cach_name = $GLOBALS['config']['app']['cache_flag']. '_'.'api_actor_'.md5(http_build_query($this->_param));
  425. $html = Cache::get($cach_name);
  426. if(empty($html) || $cache_time==0) {
  427. $where = [];
  428. if (!empty($this->_param['ids'])) {
  429. $where['actor_id'] = ['in', $this->_param['ids']];
  430. }
  431. if (!empty($this->_param['t'])) {
  432. if (empty($GLOBALS['config']['api']['actor']['typefilter']) || strpos($GLOBALS['config']['api']['actor']['typefilter'], $this->_param['t']) !== false) {
  433. $where['type_id'] = $this->_param['t'];
  434. }
  435. }
  436. if (!empty(intval($this->_param['h']))) {
  437. $todaydate = date('Y-m-d', strtotime('+1 days'));
  438. $tommdate = date('Y-m-d', strtotime('-' . $this->_param['h'] . ' hours'));
  439. $todayunix = strtotime($todaydate);
  440. $tommunix = strtotime($tommdate);
  441. $where['actor_time'] = [['gt', $tommunix], ['lt', $todayunix]];
  442. }
  443. if (!empty($this->_param['wd'])) {
  444. $where['actor_name'] = ['like', '%' . $this->_param['wd'] . '%'];
  445. }
  446. if (!empty($GLOBALS['config']['api']['actor']['datafilter'])) {
  447. $where['_string'] = $GLOBALS['config']['api']['actor']['datafilter'];
  448. }
  449. if (empty(intval($this->_param['pg']))) {
  450. $this->_param['pg'] = 1;
  451. }
  452. $order = 'actor_time desc';
  453. $field = 'actor_id,actor_name,type_id,"" as type_name,actor_en,actor_area,actor_time,actor_alias,actor_sex,actor_pic';
  454. if ($this->_param['ac'] == 'detail') {
  455. $field = '*';
  456. }
  457. $res = model('actor')->listData($where, $order, $this->_param['pg'], $GLOBALS['config']['api']['actor']['pagesize'], 0, $field, 0);
  458. if ($res['code'] > 1) {
  459. echo $res['msg'];
  460. exit;
  461. }
  462. $type_list = model('Type')->getCache('type_list');
  463. foreach ($res['list'] as $k => &$v) {
  464. $type_info = $type_list[$v['type_id']];
  465. $v['type_name'] = $type_info['type_name'];
  466. $v['actor_time'] = date('Y-m-d H:i:s', $v['actor_time']);
  467. if (substr($v["actor_pic"], 0, 4) == "mac:") {
  468. $v["actor_pic"] = str_replace('mac:', $this->getImgUrlProtocol('actor'), $v["actor_pic"]);
  469. } elseif (!empty($v["actor_pic"]) && substr($v["actor_pic"], 0, 4) != "http" && substr($v["actor_pic"], 0, 2) != "//") {
  470. $v["actor_pic"] = $GLOBALS['config']['api']['actor']['imgurl'] . $v["actor_pic"];
  471. }
  472. if ($this->_param['ac'] == 'detail') {
  473. } else {
  474. }
  475. }
  476. if ($this->_param['ac'] != 'detail') {
  477. $class = [];
  478. $typefilter = explode(',', $GLOBALS['config']['api']['actor']['typefilter']);
  479. foreach ($type_list as $k => &$v) {
  480. if ($v['type_mid'] == 8) {
  481. if (!empty($GLOBALS['config']['api']['actor']['typefilter'])) {
  482. if (in_array($v['type_id'], $typefilter)) {
  483. $class[] = ['type_id' => $v['type_id'], 'type_pid' => $v['type_pid'], 'type_name' => $v['type_name']];
  484. }
  485. } else {
  486. $class[] = ['type_id' => $v['type_id'], 'type_pid' => $v['type_pid'], 'type_name' => $v['type_name']];
  487. }
  488. }
  489. }
  490. $res['class'] = $class;
  491. }
  492. $html = json_encode($res,JSON_UNESCAPED_UNICODE);
  493. $html = mac_filter_tags($html);
  494. if($cache_time>0) {
  495. Cache::set($cach_name, $html, $cache_time);
  496. }
  497. }
  498. echo $html;
  499. exit;
  500. }
  501. public function role()
  502. {
  503. if($GLOBALS['config']['api']['role']['status'] != 1){
  504. echo 'closed';die;
  505. }
  506. if($GLOBALS['config']['api']['role']['charge'] == 1) {
  507. $h = $_SERVER['REMOTE_ADDR'];
  508. if (!$h) {
  509. echo lang('api/auth_err');
  510. exit;
  511. }
  512. else {
  513. $auth = $GLOBALS['config']['api']['role']['auth'];
  514. $this->checkDomainAuth($auth);
  515. }
  516. }
  517. $cache_time = intval($GLOBALS['config']['api']['role']['cachetime']);
  518. $cach_name = $GLOBALS['config']['app']['cache_flag']. '_'.'api_role_'.md5(http_build_query($this->_param));
  519. $html = Cache::get($cach_name);
  520. if(empty($html) || $cache_time==0) {
  521. $where = [];
  522. if (!empty($this->_param['ids'])) {
  523. $where['role_id'] = ['in', $this->_param['ids']];
  524. }
  525. if (!empty($this->_param['t'])) {
  526. if (empty($GLOBALS['config']['api']['role']['typefilter']) || strpos($GLOBALS['config']['api']['role']['typefilter'], $this->_param['t']) !== false) {
  527. $where['type_id'] = $this->_param['t'];
  528. }
  529. }
  530. if (!empty(intval($this->_param['h']))) {
  531. $todaydate = date('Y-m-d', strtotime('+1 days'));
  532. $tommdate = date('Y-m-d', strtotime('-' . $this->_param['h'] . ' hours'));
  533. $todayunix = strtotime($todaydate);
  534. $tommunix = strtotime($tommdate);
  535. $where['role_time'] = [['gt', $tommunix], ['lt', $todayunix]];
  536. }
  537. if (!empty($this->_param['wd'])) {
  538. $where['role_name'] = ['like', '%' . $this->_param['wd'] . '%'];
  539. }
  540. if (!empty($GLOBALS['config']['api']['role']['datafilter'])) {
  541. $where['_string'] = $GLOBALS['config']['api']['role']['datafilter'];
  542. }
  543. if (empty(intval($this->_param['pg']))) {
  544. $this->_param['pg'] = 1;
  545. }
  546. $order = 'role_time desc';
  547. $field = 'role_id,role_name,role_rid,role_en,role_actor,role_time,role_pic';
  548. if ($this->_param['ac'] == 'detail') {
  549. $field = '*';
  550. }
  551. $res = model('role')->listData($where, $order, $this->_param['pg'], $GLOBALS['config']['api']['role']['pagesize'], 0, $field, 1);
  552. if ($res['code'] > 1) {
  553. echo $res['msg'];
  554. exit;
  555. }
  556. foreach ($res['list'] as $k => &$v) {
  557. $v['role_time'] = date('Y-m-d H:i:s', $v['role_time']);
  558. $v['douban_id'] = $v['data']['vod_douban_id'];
  559. $v['vod_name'] = $v['data']['vod_name'];
  560. $v['vod_director'] = $v['data']['vod_director'];
  561. unset($v['data']);
  562. if (substr($v["role_pic"], 0, 4) == "mac:") {
  563. $v["role_pic"] = str_replace('mac:', $this->getImgUrlProtocol('role'), $v["role_pic"]);
  564. } elseif (!empty($v["role_pic"]) && substr($v["role_pic"], 0, 4) != "http" && substr($v["role_pic"], 0, 2) != "//") {
  565. $v["role_pic"] = $GLOBALS['config']['api']['role']['imgurl'] . $v["role_pic"];
  566. }
  567. if ($this->_param['ac'] == 'detail') {
  568. } else {
  569. }
  570. }
  571. if ($this->_param['ac'] != 'detail') {
  572. $class = [];
  573. $typefilter = explode(',', $GLOBALS['config']['api']['role']['typefilter']);
  574. $res['class'] = $class;
  575. }
  576. $html = json_encode($res,JSON_UNESCAPED_UNICODE);
  577. $html = mac_filter_tags($html);
  578. if($cache_time>0) {
  579. Cache::set($cach_name, $html, $cache_time);
  580. }
  581. }
  582. echo $html;
  583. exit;
  584. }
  585. public function manga()
  586. {
  587. if($GLOBALS['config']['api']['manga']['status'] != 1){
  588. echo 'closed';
  589. exit;
  590. }
  591. if($GLOBALS['config']['api']['manga']['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']['manga']['auth'];
  599. $this->checkDomainAuth($auth);
  600. }
  601. }
  602. $cache_time = intval($GLOBALS['config']['api']['manga']['cachetime']);
  603. $cach_name = $GLOBALS['config']['app']['cache_flag']. '_'.'api_manga_'.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['manga_id'] = ['in', $this->_param['ids']];
  609. }
  610. if (!empty($GLOBALS['config']['api']['manga']['typefilter'])) {
  611. $where['type_id'] = ['in', $GLOBALS['config']['api']['manga']['typefilter']];
  612. }
  613. if (!empty($this->_param['t'])) {
  614. if (empty($GLOBALS['config']['api']['manga']['typefilter']) || strpos($GLOBALS['config']['api']['manga']['typefilter'], $this->_param['t']) !== false) {
  615. $where['type_id'] = $this->_param['t'];
  616. }
  617. }
  618. if (!empty($this->_param['h'])) {
  619. $todaydate = date('Y-m-d', strtotime('+1 days'));
  620. $tommdate = date('Y-m-d H:i:s', strtotime('-' . $this->_param['h'] . ' hours'));
  621. $todayunix = strtotime($todaydate);
  622. $tommunix = strtotime($tommdate);
  623. $where['manga_time'] = [['gt', $tommunix], ['lt', $todayunix]];
  624. }
  625. if (!empty($this->_param['wd'])) {
  626. $where['manga_name'] = ['like', '%' . $this->_param['wd'] . '%'];
  627. }
  628. if (!empty($GLOBALS['config']['api']['manga']['datafilter'])) {
  629. $where['_string'] .= ' ' . $GLOBALS['config']['api']['manga']['datafilter'];
  630. }
  631. if (empty($this->_param['pg'])) {
  632. $this->_param['pg'] = 1;
  633. }
  634. $pagesize = $GLOBALS['config']['api']['manga']['pagesize'];
  635. if (!empty($this->_param['pagesize']) && $this->_param['pagesize'] > 0) {
  636. $pagesize = min((int)$this->_param['pagesize'], 100);
  637. }
  638. $order = 'manga_time desc';
  639. $field = 'manga_id,manga_name,type_id,"" as type_name,manga_en,manga_time,manga_remarks,manga_chapter_from,manga_time';
  640. if ($this->_param['ac'] == 'detail') {
  641. $field = '*';
  642. }
  643. $res = model('manga')->listData($where, $order, $this->_param['pg'], $pagesize, 0, $field, 0);
  644. if ($this->_param['at'] == 'xml') {
  645. $html = $this->manga_xml($res);
  646. } else {
  647. $html = json_encode($this->manga_json($res),JSON_UNESCAPED_UNICODE);
  648. }
  649. $html = mac_filter_tags($html);
  650. if($cache_time>0) {
  651. Cache::set($cach_name, $html, $cache_time);
  652. }
  653. }
  654. echo $html;
  655. exit;
  656. }
  657. public function manga_json($res)
  658. {
  659. $type_list = model('Type')->getCache('type_list');
  660. foreach($res['list'] as $k=>&$v){
  661. $type_info = $type_list[$v['type_id']];
  662. $v['type_name'] = $type_info['type_name'];
  663. $v['manga_time'] = date('Y-m-d H:i:s',$v['manga_time']);
  664. if(substr($v["manga_pic"],0,4)=="mac:"){
  665. $v["manga_pic"] = str_replace('mac:',$this->getImgUrlProtocol('manga'), $v["manga_pic"]);
  666. }
  667. elseif(!empty($v["manga_pic"]) && substr($v["manga_pic"],0,4)!="http" && substr($v["manga_pic"],0,2)!="//"){
  668. $v["manga_pic"] = $GLOBALS['config']['api']['manga']['imgurl'] . $v["manga_pic"];
  669. }
  670. }
  671. if($this->_param['ac']!='detail') {
  672. $class = [];
  673. $typefilter = explode(',',$GLOBALS['config']['api']['manga']['typefilter']);
  674. foreach ($type_list as $k=>&$v) {
  675. if (!empty($GLOBALS['config']['api']['manga']['typefilter'])){
  676. if(in_array($v['type_id'],$typefilter)) {
  677. $class[] = ['type_id' => $v['type_id'], 'type_pid' => $v['type_pid'], 'type_name' => $v['type_name']];
  678. }
  679. }
  680. else {
  681. $class[] = ['type_id' => $v['type_id'], 'type_pid' => $v['type_pid'], 'type_name' => $v['type_name']];
  682. }
  683. }
  684. $res['class'] = $class;
  685. }
  686. return $res;
  687. }
  688. public function manga_xml($res)
  689. {
  690. $xml = '<?xml version="1.0" encoding="utf-8"?>';
  691. $xml .= '<rss version="5.1">';
  692. $type_list = model('Type')->getCache('type_list');
  693. $xml .= '<list page="'.$res['page'].'" pagecount="'.$res['pagecount'].'" pagesize="'.$res['limit'].'" recordcount="'.$res['total'].'">';
  694. foreach($res['list'] as $k=>&$v){
  695. $type_info = $type_list[$v['type_id']];
  696. $xml .= '<video>';
  697. $xml .= '<last>'.date('Y-m-d H:i:s',$v['manga_time']).'</last>';
  698. $xml .= '<id>'.$v['manga_id'].'</id>';
  699. $xml .= '<tid>'.$v['type_id'].'</tid>';
  700. $xml .= '<name><![CDATA['.$v['manga_name'].']]></name>';
  701. $xml .= '<type>'.$type_info['type_name'].'</type>';
  702. if(substr($v["manga_pic"],0,4)=="mac:"){
  703. $v["manga_pic"] = str_replace('mac:',$this->getImgUrlProtocol('manga'), $v["manga_pic"]);
  704. }
  705. elseif(!empty($v["manga_pic"]) && substr($v["manga_pic"],0,4)!="http" && substr($v["manga_pic"],0,2)!="//"){
  706. $v["manga_pic"] = $GLOBALS['config']['api']['manga']['imgurl'] . $v["manga_pic"];
  707. }
  708. if($this->_param['ac']=='detail'){
  709. $xml .= '<pic>'.$v["manga_pic"].'</pic>';
  710. $xml .= '<lang>'.$v['manga_lang'].'</lang>';
  711. $xml .= '<area>'.$v['manga_area'].'</area>';
  712. $xml .= '<year>'.$v['manga_year'].'</year>';
  713. $xml .= '<state>'.$v['manga_serial'].'</state>';
  714. $xml .= '<note><![CDATA['.$v['manga_remarks'].']]></note>';
  715. $xml .= '<actor><![CDATA['.$v['manga_actor'].']]></actor>';
  716. $xml .= '<director><![CDATA['.$v['manga_director'].']]></director>';
  717. $xml .= '<des><![CDATA['.$v['manga_content'].']]></des>';
  718. }
  719. else {
  720. $xml .= '<dt>' . str_replace('$$$', ',', $v['manga_chapter_from']) . '</dt>';
  721. $xml .= '<note><![CDATA[' . $v['manga_remarks'] . ']]></note>';
  722. }
  723. $xml .= '</video>';
  724. }
  725. $xml .= '</list>';
  726. if($this->_param['ac']!='detail') {
  727. $xml .= "<class>";
  728. $typefilter = explode(',',$GLOBALS['config']['api']['manga']['typefilter']);
  729. foreach ($type_list as $k=>&$v) {
  730. if($v['type_mid']==12) {
  731. if (!empty($GLOBALS['config']['api']['manga']['typefilter'])){
  732. if(in_array($v['type_id'],$typefilter)) {
  733. $xml .= "<ty id=\"" . $v["type_id"] . "\">" . $v["type_name"] . "</ty>";
  734. }
  735. }
  736. else {
  737. $xml .= "<ty id=\"" . $v["type_id"] . "\">" . $v["type_name"] . "</ty>";
  738. }
  739. }
  740. }
  741. unset($rs);
  742. $xml .= "</class>";
  743. }
  744. $xml .= "</rss>";
  745. return $xml;
  746. }
  747. public function website()
  748. {
  749. if($GLOBALS['config']['api']['website']['status'] != 1){
  750. echo 'closed';die;
  751. }
  752. if($GLOBALS['config']['api']['website']['charge'] == 1) {
  753. $h = $_SERVER['REMOTE_ADDR'];
  754. if (!$h) {
  755. echo lang('api/auth_err');
  756. exit;
  757. }
  758. else {
  759. $auth = $GLOBALS['config']['api']['website']['auth'];
  760. $this->checkDomainAuth($auth);
  761. }
  762. }
  763. $cache_time = intval($GLOBALS['config']['api']['website']['cachetime']);
  764. $cach_name = $GLOBALS['config']['app']['cache_flag']. '_'.'api_website_'.md5(http_build_query($this->_param));
  765. $html = Cache::get($cach_name);
  766. if(empty($html) || $cache_time==0) {
  767. $where = [];
  768. if (!empty($this->_param['ids'])) {
  769. $where['website_id'] = ['in', $this->_param['ids']];
  770. }
  771. if (!empty($this->_param['t'])) {
  772. if (empty($GLOBALS['config']['api']['website']['typefilter']) || strpos($GLOBALS['config']['api']['website']['typefilter'], $this->_param['t']) !== false) {
  773. $where['type_id'] = $this->_param['t'];
  774. }
  775. }
  776. if (!empty(intval($this->_param['h']))) {
  777. $todaydate = date('Y-m-d', strtotime('+1 days'));
  778. $tommdate = date('Y-m-d', strtotime('-' . $this->_param['h'] . ' hours'));
  779. $todayunix = strtotime($todaydate);
  780. $tommunix = strtotime($tommdate);
  781. $where['website_time'] = [['gt', $tommunix], ['lt', $todayunix]];
  782. }
  783. if (!empty($this->_param['wd'])) {
  784. $where['website_name'] = ['like', '%' . $this->_param['wd'] . '%'];
  785. }
  786. if (!empty($GLOBALS['config']['api']['website']['datafilter'])) {
  787. $where['_string'] = $GLOBALS['config']['api']['website']['datafilter'];
  788. }
  789. if (empty(intval($this->_param['pg']))) {
  790. $this->_param['pg'] = 1;
  791. }
  792. $order = 'website_time desc';
  793. $field = 'website_id,website_name,type_id,"" as type_name,website_en,website_time,website_area,website_lang,website_pic';
  794. if ($this->_param['ac'] == 'detail') {
  795. $field = '*';
  796. }
  797. $res = model('website')->listData($where, $order, $this->_param['pg'], $GLOBALS['config']['api']['website']['pagesize'], 0, $field, 0);
  798. if ($res['code'] > 1) {
  799. echo $res['msg'];
  800. exit;
  801. }
  802. $type_list = model('Type')->getCache('type_list');
  803. foreach ($res['list'] as $k => &$v) {
  804. $type_info = $type_list[$v['type_id']];
  805. $v['type_name'] = $type_info['type_name'];
  806. $v['website_time'] = date('Y-m-d H:i:s', $v['website_time']);
  807. if (substr($v["website_pic"], 0, 4) == "mac:") {
  808. $v["website_pic"] = str_replace('mac:', $this->getImgUrlProtocol('website'), $v["website_pic"]);
  809. } elseif (!empty($v["website_pic"]) && substr($v["website_pic"], 0, 4) != "http" && substr($v["website_pic"], 0, 2) != "//") {
  810. $v["website_pic"] = $GLOBALS['config']['api']['website']['imgurl'] . $v["website_pic"];
  811. }
  812. if ($this->_param['ac'] == 'detail') {
  813. } else {
  814. }
  815. }
  816. if ($this->_param['ac'] != 'detail') {
  817. $class = [];
  818. $typefilter = explode(',', $GLOBALS['config']['api']['website']['typefilter']);
  819. foreach ($type_list as $k => &$v) {
  820. if ($v['type_mid'] == 11) {
  821. if (!empty($GLOBALS['config']['api']['website']['typefilter'])) {
  822. if (in_array($v['type_id'], $typefilter)) {
  823. $class[] = ['type_id' => $v['type_id'], 'type_pid' => $v['type_pid'], 'type_name' => $v['type_name']];
  824. }
  825. } else {
  826. $class[] = ['type_id' => $v['type_id'], 'type_pid' => $v['type_pid'], 'type_name' => $v['type_name']];
  827. }
  828. }
  829. }
  830. $res['class'] = $class;
  831. }
  832. $html = json_encode($res,JSON_UNESCAPED_UNICODE);
  833. $html = mac_filter_tags($html);
  834. if($cache_time>0) {
  835. Cache::set($cach_name, $html, $cache_time);
  836. }
  837. }
  838. echo $html;
  839. exit;
  840. }
  841. public function comment()
  842. {
  843. }
  844. private function checkDomainAuth($auth)
  845. {
  846. $ip = mac_get_client_ip();
  847. $auth_list = ['127.0.0.1'];
  848. if (!empty($auth)) {
  849. foreach (explode('#', $auth) as $domain) {
  850. $domain = trim($domain);
  851. $auth_list[] = $domain;
  852. if (!mac_string_is_ip($domain)) {
  853. $auth_list[] = gethostbyname($domain);
  854. }
  855. }
  856. $auth_list = array_unique($auth_list);
  857. $auth_list = array_filter($auth_list);
  858. }
  859. if (!in_array($ip, $auth_list)) {
  860. echo lang('api/auth_err');
  861. exit;
  862. }
  863. }
  864. private function getImgUrlProtocol($key)
  865. {
  866. $default = (isset($GLOBALS['config']['upload']['protocol']) ? $GLOBALS['config']['upload']['protocol'] : 'http') . ':';
  867. if (!isset($GLOBALS['config']['api'][$key]['imgurl'])) {
  868. return $default;
  869. }
  870. if (substr($GLOBALS['config']['api'][$key]['imgurl'], 0, 5) == 'https') {
  871. return 'https:';
  872. }
  873. return $default;
  874. }
  875. }