| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745 |
- <?php
- namespace app\api\controller;
- use think\Controller;
- use think\Cache;
- class Provide extends Base
- {
- var $_param;
- public function __construct()
- {
- parent::__construct();
- $this->_param = input('','','trim,urldecode');
- // 因搜索兼容性问题暂时移除
- // if(isset($GLOBALS['config']['app']['input_type']) && $GLOBALS['config']['app']['input_type'] == 0 && request()->isPost()){
- // $this->_param = input('get.');
- // }
- }
- public function index()
- {
- }
- public function vod()
- {
- if($GLOBALS['config']['api']['vod']['status'] != 1){
- echo 'closed';
- exit;
- }
- if($GLOBALS['config']['api']['vod']['charge'] == 1) {
- $h = $_SERVER['REMOTE_ADDR'];
- if (!$h) {
- echo lang('api/auth_err');
- exit;
- }
- else {
- $auth = $GLOBALS['config']['api']['vod']['auth'];
- $this->checkDomainAuth($auth);
- }
- }
- $cache_time = intval($GLOBALS['config']['api']['vod']['cachetime']);
- $cach_name = $GLOBALS['config']['app']['cache_flag']. '_'.'api_vod_'.md5(http_build_query($this->_param));
- $html = Cache::get($cach_name);
- if(empty($html) || $cache_time==0) {
- $where = [];
- if (!empty($this->_param['ids'])) {
- $where['vod_id'] = ['in', $this->_param['ids']];
- }
- if (!empty($GLOBALS['config']['api']['vod']['typefilter'])) {
- $where['type_id'] = ['in', $GLOBALS['config']['api']['vod']['typefilter']];
- }
- if (!empty($this->_param['t'])) {
- if (empty($GLOBALS['config']['api']['vod']['typefilter']) || strpos($GLOBALS['config']['api']['vod']['typefilter'], $this->_param['t']) !== false) {
- $where['type_id'] = $this->_param['t'];
- }
- }
- if (!empty($this->_param['h'])) {
- $todaydate = date('Y-m-d', strtotime('+1 days'));
- $tommdate = date('Y-m-d H:i:s', strtotime('-' . $this->_param['h'] . ' hours'));
- $todayunix = strtotime($todaydate);
- $tommunix = strtotime($tommdate);
- $where['vod_time'] = [['gt', $tommunix], ['lt', $todayunix]];
- }
- if (!empty($this->_param['wd'])) {
- $where['vod_name'] = ['like', '%' . $this->_param['wd'] . '%'];
- }
- if (empty($GLOBALS['config']['api']['vod']['from']) && !empty($this->_param['from'])) {
- $GLOBALS['config']['api']['vod']['from'] = $this->_param['from'];
- }
- if (!empty($GLOBALS['config']['api']['vod']['from'])) {
- $where['vod_play_from'] = ['like', '%' . $GLOBALS['config']['api']['vod']['from'] . '%'];
- }
- if (!empty($GLOBALS['config']['api']['vod']['datafilter'])) {
- $where['_string'] .= ' ' . $GLOBALS['config']['api']['vod']['datafilter'];
- }
- if (empty($this->_param['pg'])) {
- $this->_param['pg'] = 1;
- }
- $order = 'vod_time desc';
- $field = 'vod_id,vod_name,type_id,"" as type_name,vod_en,vod_time,vod_remarks,vod_play_from,vod_time';
- if ($this->_param['ac'] == 'videolist' || $this->_param['ac'] == 'detail') {
- $field = '*';
- }
- $res = model('vod')->listData($where, $order, $this->_param['pg'], $GLOBALS['config']['api']['vod']['pagesize'], 0, $field, 0);
- if ($this->_param['at'] == 'xml') {
- $html = $this->vod_xml($res);
- } else {
- $html = json_encode($this->vod_json($res),JSON_UNESCAPED_UNICODE);
- }
- $html = mac_filter_tags($html);
- if($cache_time>0) {
- Cache::set($cach_name, $html, $cache_time);
- }
- }
- echo $html;
- exit;
- }
- public function vod_url_deal($urls,$froms,$from,$flag)
- {
- $res_xml = '';
- $res_json = [];
- $arr1 = explode("$$$",$urls); $arr1count = count($arr1);
- $arr2 = explode("$$$",$froms); $arr2count = count($arr2);
- for ($i=0;$i<$arr2count;$i++){
- if ($arr1count >= $i){
- if($from!=''){
- if($arr2[$i]==$from){
- $res_xml .= '<dd flag="'. $arr2[$i] .'"><![CDATA[' . $arr1[$i]. ']]></dd>';
- $res_json[$arr2[$i]] = $arr1[$i];
- }
- }
- else{
- $res_xml .= '<dd flag="'. $arr2[$i] .'"><![CDATA[' . $arr1[$i]. ']]></dd>';
- $res_json[$arr2[$i]] = $arr1[$i];
- }
- }
- }
- $res = str_replace(array(chr(10),chr(13)),array('','#'),$res_xml);
- return $flag=='xml' ? $res_xml : $res_json;
- }
- public function vod_json($res)
- {
- $type_list = model('Type')->getCache('type_list');
- foreach($res['list'] as $k=>&$v){
- $type_info = $type_list[$v['type_id']];
- $v['type_name'] = $type_info['type_name'];
- $v['vod_time'] = date('Y-m-d H:i:s',$v['vod_time']);
- if(substr($v["vod_pic"],0,4)=="mac:"){
- $v["vod_pic"] = str_replace('mac:','http:',$v["vod_pic"]);
- }
- elseif(!empty($v["vod_pic"]) && substr($v["vod_pic"],0,4)!="http" && substr($v["vod_pic"],0,2)!="//"){
- $v["vod_pic"] = $GLOBALS['config']['api']['vod']['imgurl'] . $v["vod_pic"];
- }
- if($this->_param['ac']=='videolist' || $this->_param['ac']=='detail'){
- if ($GLOBALS['config']['api']['vod']['from'] != '') {
- $arr_from = explode('$$$',$v['vod_play_from']);
- $arr_url = explode('$$$',$v['vod_play_url']);
- $arr_server = explode('$$$',$v['vod_play_server']);
- $arr_note = explode('$$$',$v['vod_play_note']);
- $key = array_search($GLOBALS['config']['api']['vod']['from'],$arr_from);
- $res['list'][$k]['vod_play_from'] = $GLOBALS['config']['api']['vod']['from'];
- $res['list'][$k]['vod_play_url'] = $arr_url[$key];
- $res['list'][$k]['vod_play_server'] = $arr_server[$key];
- $res['list'][$k]['vod_play_note'] = $arr_note[$key];
- }
- }
- else {
- if ($GLOBALS['config']['api']['vod']['from'] != '') {
- $res['list'][$k]['vod_play_from'] = $GLOBALS['config']['api']['vod']['from'];
- } else {
- $res['list'][$k]['vod_play_from'] = str_replace('$$$', ',', $v['vod_play_from']);
- }
- }
- }
- if($this->_param['ac']!='videolist' && $this->_param['ac']!='detail') {
- $class = [];
- $typefilter = explode(',',$GLOBALS['config']['api']['vod']['typefilter']);
- foreach ($type_list as $k=>&$v) {
- if (!empty($GLOBALS['config']['api']['vod']['typefilter'])){
- if(in_array($v['type_id'],$typefilter)) {
- $class[] = ['type_id' => $v['type_id'], 'type_pid' => $v['type_pid'], 'type_name' => $v['type_name']];
- }
- }
- else {
- $class[] = ['type_id' => $v['type_id'], 'type_pid' => $v['type_pid'], 'type_name' => $v['type_name']];
- }
- }
- $res['class'] = $class;
- }
- return $res;
- }
- public function vod_xml($res)
- {
- $xml = '<?xml version="1.0" encoding="utf-8"?>';
- $xml .= '<rss version="5.1">';
- $type_list = model('Type')->getCache('type_list');
- //视频列表开始
- $xml .= '<list page="'.$res['page'].'" pagecount="'.$res['pagecount'].'" pagesize="'.$res['limit'].'" recordcount="'.$res['total'].'">';
- foreach($res['list'] as $k=>&$v){
- $type_info = $type_list[$v['type_id']];
- $xml .= '<video>';
- $xml .= '<last>'.date('Y-m-d H:i:s',$v['vod_time']).'</last>';
- $xml .= '<id>'.$v['vod_id'].'</id>';
- $xml .= '<tid>'.$v['type_id'].'</tid>';
- $xml .= '<name><![CDATA['.$v['vod_name'].']]></name>';
- $xml .= '<type>'.$type_info['type_name'].'</type>';
- if(substr($v["vod_pic"],0,4)=="mac:"){
- $v["vod_pic"] = str_replace('mac:','http:',$v["vod_pic"]);
- }
- elseif(!empty($v["vod_pic"]) && substr($v["vod_pic"],0,4)!="http" && substr($v["vod_pic"],0,2)!="//"){
- $v["vod_pic"] = $GLOBALS['config']['api']['vod']['imgurl'] . $v["vod_pic"];
- }
- if($this->_param['ac']=='videolist' || $this->_param['ac']=='detail'){
- $tempurl = $this->vod_url_deal($v["vod_play_url"],$v["vod_play_from"],$GLOBALS['config']['api']['vod']['from'],'xml');
- $xml .= '<pic>'.$v["vod_pic"].'</pic>';
- $xml .= '<lang>'.$v['vod_lang'].'</lang>';
- $xml .= '<area>'.$v['vod_area'].'</area>';
- $xml .= '<year>'.$v['vod_year'].'</year>';
- $xml .= '<state>'.$v['vod_serial'].'</state>';
- $xml .= '<note><![CDATA['.$v['vod_remarks'].']]></note>';
- $xml .= '<actor><![CDATA['.$v['vod_actor'].']]></actor>';
- $xml .= '<director><![CDATA['.$v['vod_director'].']]></director>';
- $xml .= '<dl>'.$tempurl.'</dl>';
- $xml .= '<des><![CDATA['.$v['vod_content'].']]></des>';
- }
- else {
- if ($GLOBALS['config']['api']['vod']['from'] != ''){
- $xml .= '<dt>' . $GLOBALS['config']['api']['vod']['from'] . '</dt>';
- }
- else{
- $xml .= '<dt>' . str_replace('$$$', ',', $v['vod_play_from']) . '</dt>';
- }
- $xml .= '<note><![CDATA[' . $v['vod_remarks'] . ']]></note>';
- }
- $xml .= '</video>';
- }
- $xml .= '</list>';
- //视频列表结束
- if($this->_param['ac'] != 'videolist' && $this->_param['ac']!='detail') {
- //分类列表开始
- $xml .= "<class>";
- $typefilter = explode(',',$GLOBALS['config']['api']['vod']['typefilter']);
- foreach ($type_list as $k=>&$v) {
- if($v['type_mid']==1) {
- if (!empty($GLOBALS['config']['api']['vod']['typefilter'])){
- if(in_array($v['type_id'],$typefilter)) {
- $xml .= "<ty id=\"" . $v["type_id"] . "\">" . $v["type_name"] . "</ty>";
- }
- }
- else {
- $xml .= "<ty id=\"" . $v["type_id"] . "\">" . $v["type_name"] . "</ty>";
- }
- }
- }
- unset($rs);
- $xml .= "</class>";
- //分类列表结束
- }
- $xml .= "</rss>";
- return $xml;
- }
- public function art()
- {
- if($GLOBALS['config']['api']['art']['status'] != 1){
- echo 'closed';die;
- }
- if($GLOBALS['config']['api']['art']['charge'] == 1) {
- $h = $_SERVER['REMOTE_ADDR'];
- if (!$h) {
- echo lang('api/auth_err');
- exit;
- }
- else {
- $auth = $GLOBALS['config']['api']['art']['auth'];
- $this->checkDomainAuth($auth);
- }
- }
- $cache_time = intval($GLOBALS['config']['api']['art']['cachetime']);
- $cach_name = $GLOBALS['config']['app']['cache_flag']. '_'.'api_art_'.md5(http_build_query($this->_param));
- $html = Cache::get($cach_name);
- if(empty($html) || $cache_time==0) {
- $where = [];
- if (!empty($this->_param['ids'])) {
- $where['art_id'] = ['in', $this->_param['ids']];
- }
- if (!empty($this->_param['t'])) {
- if (empty($GLOBALS['config']['api']['art']['typefilter']) || strpos($GLOBALS['config']['api']['art']['typefilter'], $this->_param['t']) !== false) {
- $where['type_id'] = $this->_param['t'];
- }
- }
- if (!empty(intval($this->_param['h']))) {
- $todaydate = date('Y-m-d', strtotime('+1 days'));
- $tommdate = date('Y-m-d', strtotime('-' . $this->_param['h'] . ' hours'));
- $todayunix = strtotime($todaydate);
- $tommunix = strtotime($tommdate);
- $where['art_time'] = [['gt', $tommunix], ['lt', $todayunix]];
- }
- if (!empty($this->_param['wd'])) {
- $where['art_name'] = ['like', '%' . $this->_param['wd'] . '%'];
- }
- if (!empty($GLOBALS['config']['api']['art']['datafilter'])) {
- $where['_string'] = $GLOBALS['config']['api']['art']['datafilter'];
- }
- if (empty(intval($this->_param['pg']))) {
- $this->_param['pg'] = 1;
- }
- $order = 'art_time desc';
- $field = 'art_id,art_name,type_id,"" as type_name,art_en,art_time,art_author,art_from,art_remarks,art_pic,art_time';
- if ($this->_param['ac'] == 'detail') {
- $field = '*';
- }
- $res = model('art')->listData($where, $order, $this->_param['pg'], $GLOBALS['config']['api']['art']['pagesize'], 0, $field, 0);
- if ($res['code'] > 1) {
- echo $res['msg'];
- exit;
- }
- $type_list = model('Type')->getCache('type_list');
- foreach ($res['list'] as $k => &$v) {
- $type_info = $type_list[$v['type_id']];
- $v['type_name'] = $type_info['type_name'];
- $v['art_time'] = date('Y-m-d H:i:s', $v['art_time']);
- if (substr($v["art_pic"], 0, 4) == "mac:") {
- $v["art_pic"] = str_replace('mac:', $this->getImgUrlProtocol('art'), $v["art_pic"]);
- } elseif (!empty($v["art_pic"]) && substr($v["art_pic"], 0, 4) != "http" && substr($v["art_pic"], 0, 2) != "//") {
- $v["art_pic"] = $GLOBALS['config']['api']['art']['imgurl'] . $v["art_pic"];
- }
- if ($this->_param['ac'] == 'detail') {
- } else {
- }
- }
- if ($this->_param['ac'] != 'detail') {
- $class = [];
- $typefilter = explode(',', $GLOBALS['config']['api']['art']['typefilter']);
- foreach ($type_list as $k => &$v) {
- if ($v['type_mid'] == 2) {
- if (!empty($GLOBALS['config']['api']['art']['typefilter'])) {
- if (in_array($v['type_id'], $typefilter)) {
- $class[] = ['type_id' => $v['type_id'], 'type_pid' => $v['type_pid'], 'type_name' => $v['type_name']];
- }
- } else {
- $class[] = ['type_id' => $v['type_id'], 'type_pid' => $v['type_pid'], 'type_name' => $v['type_name']];
- }
- }
- }
- $res['class'] = $class;
- }
- $html = json_encode($res,JSON_UNESCAPED_UNICODE);
- $html = mac_filter_tags($html);
- if($cache_time>0) {
- Cache::set($cach_name, $html, $cache_time);
- }
- }
- echo $html;
- exit;
- }
- public function actor()
- {
- if($GLOBALS['config']['api']['actor']['status'] != 1){
- echo 'closed';die;
- }
- if($GLOBALS['config']['api']['actor']['charge'] == 1) {
- $h = $_SERVER['REMOTE_ADDR'];
- if (!$h) {
- echo lang('api/auth_err');
- exit;
- }
- else {
- $auth = $GLOBALS['config']['api']['actor']['auth'];
- $this->checkDomainAuth($auth);
- }
- }
- $cache_time = intval($GLOBALS['config']['api']['actor']['cachetime']);
- $cach_name = $GLOBALS['config']['app']['cache_flag']. '_'.'api_actor_'.md5(http_build_query($this->_param));
- $html = Cache::get($cach_name);
- if(empty($html) || $cache_time==0) {
- $where = [];
- if (!empty($this->_param['ids'])) {
- $where['actor_id'] = ['in', $this->_param['ids']];
- }
- if (!empty($this->_param['t'])) {
- if (empty($GLOBALS['config']['api']['actor']['typefilter']) || strpos($GLOBALS['config']['api']['actor']['typefilter'], $this->_param['t']) !== false) {
- $where['type_id'] = $this->_param['t'];
- }
- }
- if (!empty(intval($this->_param['h']))) {
- $todaydate = date('Y-m-d', strtotime('+1 days'));
- $tommdate = date('Y-m-d', strtotime('-' . $this->_param['h'] . ' hours'));
- $todayunix = strtotime($todaydate);
- $tommunix = strtotime($tommdate);
- $where['actor_time'] = [['gt', $tommunix], ['lt', $todayunix]];
- }
- if (!empty($this->_param['wd'])) {
- $where['actor_name'] = ['like', '%' . $this->_param['wd'] . '%'];
- }
- if (!empty($GLOBALS['config']['api']['actor']['datafilter'])) {
- $where['_string'] = $GLOBALS['config']['api']['actor']['datafilter'];
- }
- if (empty(intval($this->_param['pg']))) {
- $this->_param['pg'] = 1;
- }
- $order = 'actor_time desc';
- $field = 'actor_id,actor_name,type_id,"" as type_name,actor_en,actor_area,actor_time,actor_alias,actor_sex,actor_pic';
- if ($this->_param['ac'] == 'detail') {
- $field = '*';
- }
- $res = model('actor')->listData($where, $order, $this->_param['pg'], $GLOBALS['config']['api']['actor']['pagesize'], 0, $field, 0);
- if ($res['code'] > 1) {
- echo $res['msg'];
- exit;
- }
- $type_list = model('Type')->getCache('type_list');
- foreach ($res['list'] as $k => &$v) {
- $type_info = $type_list[$v['type_id']];
- $v['type_name'] = $type_info['type_name'];
- $v['actor_time'] = date('Y-m-d H:i:s', $v['actor_time']);
- if (substr($v["actor_pic"], 0, 4) == "mac:") {
- $v["actor_pic"] = str_replace('mac:', $this->getImgUrlProtocol('actor'), $v["actor_pic"]);
- } elseif (!empty($v["actor_pic"]) && substr($v["actor_pic"], 0, 4) != "http" && substr($v["actor_pic"], 0, 2) != "//") {
- $v["actor_pic"] = $GLOBALS['config']['api']['actor']['imgurl'] . $v["actor_pic"];
- }
- if ($this->_param['ac'] == 'detail') {
- } else {
- }
- }
- if ($this->_param['ac'] != 'detail') {
- $class = [];
- $typefilter = explode(',', $GLOBALS['config']['api']['actor']['typefilter']);
- foreach ($type_list as $k => &$v) {
- if ($v['type_mid'] == 8) {
- if (!empty($GLOBALS['config']['api']['actor']['typefilter'])) {
- if (in_array($v['type_id'], $typefilter)) {
- $class[] = ['type_id' => $v['type_id'], 'type_pid' => $v['type_pid'], 'type_name' => $v['type_name']];
- }
- } else {
- $class[] = ['type_id' => $v['type_id'], 'type_pid' => $v['type_pid'], 'type_name' => $v['type_name']];
- }
- }
- }
- $res['class'] = $class;
- }
- $html = json_encode($res,JSON_UNESCAPED_UNICODE);
- $html = mac_filter_tags($html);
- if($cache_time>0) {
- Cache::set($cach_name, $html, $cache_time);
- }
- }
- echo $html;
- exit;
- }
- public function role()
- {
- if($GLOBALS['config']['api']['role']['status'] != 1){
- echo 'closed';die;
- }
- if($GLOBALS['config']['api']['role']['charge'] == 1) {
- $h = $_SERVER['REMOTE_ADDR'];
- if (!$h) {
- echo lang('api/auth_err');
- exit;
- }
- else {
- $auth = $GLOBALS['config']['api']['role']['auth'];
- $this->checkDomainAuth($auth);
- }
- }
- $cache_time = intval($GLOBALS['config']['api']['role']['cachetime']);
- $cach_name = $GLOBALS['config']['app']['cache_flag']. '_'.'api_role_'.md5(http_build_query($this->_param));
- $html = Cache::get($cach_name);
- if(empty($html) || $cache_time==0) {
- $where = [];
- if (!empty($this->_param['ids'])) {
- $where['role_id'] = ['in', $this->_param['ids']];
- }
- if (!empty($this->_param['t'])) {
- if (empty($GLOBALS['config']['api']['role']['typefilter']) || strpos($GLOBALS['config']['api']['role']['typefilter'], $this->_param['t']) !== false) {
- $where['type_id'] = $this->_param['t'];
- }
- }
- if (!empty(intval($this->_param['h']))) {
- $todaydate = date('Y-m-d', strtotime('+1 days'));
- $tommdate = date('Y-m-d', strtotime('-' . $this->_param['h'] . ' hours'));
- $todayunix = strtotime($todaydate);
- $tommunix = strtotime($tommdate);
- $where['role_time'] = [['gt', $tommunix], ['lt', $todayunix]];
- }
- if (!empty($this->_param['wd'])) {
- $where['role_name'] = ['like', '%' . $this->_param['wd'] . '%'];
- }
- if (!empty($GLOBALS['config']['api']['role']['datafilter'])) {
- $where['_string'] = $GLOBALS['config']['api']['role']['datafilter'];
- }
- if (empty(intval($this->_param['pg']))) {
- $this->_param['pg'] = 1;
- }
- $order = 'role_time desc';
- $field = 'role_id,role_name,role_rid,role_en,role_actor,role_time,role_pic';
- if ($this->_param['ac'] == 'detail') {
- $field = '*';
- }
- $res = model('role')->listData($where, $order, $this->_param['pg'], $GLOBALS['config']['api']['role']['pagesize'], 0, $field, 1);
- if ($res['code'] > 1) {
- echo $res['msg'];
- exit;
- }
- foreach ($res['list'] as $k => &$v) {
- $v['role_time'] = date('Y-m-d H:i:s', $v['role_time']);
- $v['douban_id'] = $v['data']['vod_douban_id'];
- $v['vod_name'] = $v['data']['vod_name'];
- $v['vod_director'] = $v['data']['vod_director'];
- unset($v['data']);
- if (substr($v["role_pic"], 0, 4) == "mac:") {
- $v["role_pic"] = str_replace('mac:', $this->getImgUrlProtocol('role'), $v["role_pic"]);
- } elseif (!empty($v["role_pic"]) && substr($v["role_pic"], 0, 4) != "http" && substr($v["role_pic"], 0, 2) != "//") {
- $v["role_pic"] = $GLOBALS['config']['api']['role']['imgurl'] . $v["role_pic"];
- }
- if ($this->_param['ac'] == 'detail') {
- } else {
- }
- }
- if ($this->_param['ac'] != 'detail') {
- $class = [];
- $typefilter = explode(',', $GLOBALS['config']['api']['role']['typefilter']);
- $res['class'] = $class;
- }
- $html = json_encode($res,JSON_UNESCAPED_UNICODE);
- $html = mac_filter_tags($html);
- if($cache_time>0) {
- Cache::set($cach_name, $html, $cache_time);
- }
- }
- echo $html;
- exit;
- }
- public function website()
- {
- if($GLOBALS['config']['api']['website']['status'] != 1){
- echo 'closed';die;
- }
- if($GLOBALS['config']['api']['website']['charge'] == 1) {
- $h = $_SERVER['REMOTE_ADDR'];
- if (!$h) {
- echo lang('api/auth_err');
- exit;
- }
- else {
- $auth = $GLOBALS['config']['api']['website']['auth'];
- $this->checkDomainAuth($auth);
- }
- }
- $cache_time = intval($GLOBALS['config']['api']['website']['cachetime']);
- $cach_name = $GLOBALS['config']['app']['cache_flag']. '_'.'api_website_'.md5(http_build_query($this->_param));
- $html = Cache::get($cach_name);
- if(empty($html) || $cache_time==0) {
- $where = [];
- if (!empty($this->_param['ids'])) {
- $where['website_id'] = ['in', $this->_param['ids']];
- }
- if (!empty($this->_param['t'])) {
- if (empty($GLOBALS['config']['api']['website']['typefilter']) || strpos($GLOBALS['config']['api']['website']['typefilter'], $this->_param['t']) !== false) {
- $where['type_id'] = $this->_param['t'];
- }
- }
- if (!empty(intval($this->_param['h']))) {
- $todaydate = date('Y-m-d', strtotime('+1 days'));
- $tommdate = date('Y-m-d', strtotime('-' . $this->_param['h'] . ' hours'));
- $todayunix = strtotime($todaydate);
- $tommunix = strtotime($tommdate);
- $where['website_time'] = [['gt', $tommunix], ['lt', $todayunix]];
- }
- if (!empty($this->_param['wd'])) {
- $where['website_name'] = ['like', '%' . $this->_param['wd'] . '%'];
- }
- if (!empty($GLOBALS['config']['api']['website']['datafilter'])) {
- $where['_string'] = $GLOBALS['config']['api']['website']['datafilter'];
- }
- if (empty(intval($this->_param['pg']))) {
- $this->_param['pg'] = 1;
- }
- $order = 'website_time desc';
- $field = 'website_id,website_name,type_id,"" as type_name,website_en,website_time,website_area,website_lang,website_pic';
- if ($this->_param['ac'] == 'detail') {
- $field = '*';
- }
- $res = model('website')->listData($where, $order, $this->_param['pg'], $GLOBALS['config']['api']['website']['pagesize'], 0, $field, 0);
- if ($res['code'] > 1) {
- echo $res['msg'];
- exit;
- }
- $type_list = model('Type')->getCache('type_list');
- foreach ($res['list'] as $k => &$v) {
- $type_info = $type_list[$v['type_id']];
- $v['type_name'] = $type_info['type_name'];
- $v['website_time'] = date('Y-m-d H:i:s', $v['website_time']);
- if (substr($v["website_pic"], 0, 4) == "mac:") {
- $v["website_pic"] = str_replace('mac:', $this->getImgUrlProtocol('website'), $v["website_pic"]);
- } elseif (!empty($v["website_pic"]) && substr($v["website_pic"], 0, 4) != "http" && substr($v["website_pic"], 0, 2) != "//") {
- $v["website_pic"] = $GLOBALS['config']['api']['website']['imgurl'] . $v["website_pic"];
- }
- if ($this->_param['ac'] == 'detail') {
- } else {
- }
- }
- if ($this->_param['ac'] != 'detail') {
- $class = [];
- $typefilter = explode(',', $GLOBALS['config']['api']['website']['typefilter']);
- foreach ($type_list as $k => &$v) {
- if ($v['type_mid'] == 11) {
- if (!empty($GLOBALS['config']['api']['website']['typefilter'])) {
- if (in_array($v['type_id'], $typefilter)) {
- $class[] = ['type_id' => $v['type_id'], 'type_pid' => $v['type_pid'], 'type_name' => $v['type_name']];
- }
- } else {
- $class[] = ['type_id' => $v['type_id'], 'type_pid' => $v['type_pid'], 'type_name' => $v['type_name']];
- }
- }
- }
- $res['class'] = $class;
- }
- $html = json_encode($res,JSON_UNESCAPED_UNICODE);
- $html = mac_filter_tags($html);
- if($cache_time>0) {
- Cache::set($cach_name, $html, $cache_time);
- }
- }
- echo $html;
- exit;
- }
- public function comment()
- {
- }
- private function checkDomainAuth($auth)
- {
- $ip = mac_get_client_ip();
- $auth_list = ['127.0.0.1'];
- if (!empty($auth)) {
- foreach (explode('#', $auth) as $domain) {
- $domain = trim($domain);
- $auth_list[] = $domain;
- if (!mac_string_is_ip($domain)) {
- $auth_list[] = gethostbyname($domain);
- }
- }
- $auth_list = array_unique($auth_list);
- $auth_list = array_filter($auth_list);
- }
- if (!in_array($ip, $auth_list)) {
- echo lang('api/auth_err');
- exit;
- }
- }
- private function getImgUrlProtocol($key)
- {
- if (!isset($GLOBALS['config']['api'][$key]['imgurl'])) {
- return 'http:';
- }
- if (substr($GLOBALS['config']['api'][$key]['imgurl'], 0, 5) == 'https') {
- return 'https:';
- }
- return 'http:';
- }
- }
|