diff --git a/application/api/controller/Vod.php b/application/api/controller/Vod.php index 19e7699a3..823739b4f 100644 --- a/application/api/controller/Vod.php +++ b/application/api/controller/Vod.php @@ -121,7 +121,6 @@ public function get_detail(Request $request) } $res = Db::table('mac_vod')->where(['vod_id' => $param['vod_id']])->select(); - // 返回 return json([ 'code' => 1, diff --git a/application/common.php b/application/common.php index 3f757ae07..65999d88e 100644 --- a/application/common.php +++ b/application/common.php @@ -43,7 +43,12 @@ function slog($logs) { $ymd = date('Y-m-d-H'); $now = date('Y-m-d H:i:s'); - $toppath = "./log/$ymd.txt"; + $log_dir = "./log/"; + // 自动创建日志目录 + if (!is_dir($log_dir)) { + @mkdir($log_dir, 0755, true); + } + $toppath = $log_dir . $ymd . ".txt"; $ts = @fopen($toppath,"a+"); @fputs($ts, $now .' '. $logs ."\r\n"); @fclose($ts); diff --git a/application/common/model/Ulog.php b/application/common/model/Ulog.php index c8cfcf203..ca22fecce 100644 --- a/application/common/model/Ulog.php +++ b/application/common/model/Ulog.php @@ -116,6 +116,114 @@ public function listData($where,$order,$page=1,$limit=20,$start=0) return ['code'=>1,'msg'=>lang('data_list'),'page'=>$page,'pagecount'=>ceil($total/$limit),'limit'=>$limit,'total'=>$total,'list'=>$list]; } + public function listData_new($where,$order,$offset=0,$limit=20) + { + $offset = $offset > 0 ? (int)$offset : 0; + $limit = $limit ? (int)$limit : 20; + + if(!is_array($where)){ + $where = json_decode($where,true); + } + $limit_str = $offset .",".$limit; + $total = $this->where($where)->count(); + $list = Db::name('Ulog')->where($where)->order($order)->limit($limit_str)->select(); + + $user_ids=[]; + foreach($list as $k=>&$v){ + if($v['user_id'] >0){ + $user_ids[$v['user_id']] = $v['user_id']; + } + + if($v['ulog_mid']==1){ + $vod_info = model('Vod')->infoData(['vod_id'=>['eq',$v['ulog_rid']]],'*',1); + + if($v['ulog_sid']>0 && $v['ulog_nid']>0){ + if($v['ulog_type']==5){ + $vod_info['info']['link'] = mac_url_vod_down($vod_info['info'],['sid'=>$v['ulog_sid'],'nid'=>$v['ulog_nid']]); + } + else{ + $vod_info['info']['link'] = mac_url_vod_play($vod_info['info'],['sid'=>$v['ulog_sid'],'nid'=>$v['ulog_nid']]); + } + } + else{ + $vod_info['info']['link'] = mac_url_vod_detail($vod_info['info']); + } + $v['data'] = [ + 'id'=>$vod_info['info']['vod_id'], + 'name'=>$vod_info['info']['vod_name'], + 'pic'=>mac_url_img($vod_info['info']['vod_pic']), + 'link'=>$vod_info['info']['link'], + 'type'=>[ + 'type_id'=>$vod_info['info']['type']['type_id'], + 'type_name'=>$vod_info['info']['type']['type_name'], + 'link'=>mac_url_type($vod_info['info']['type']), + ], + + ]; + } + elseif($v['ulog_mid']==2){ + $art_info = model('Art')->infoData(['art_id'=>['eq',$v['ulog_rid']]],'*',1); + $art_info['info']['link'] = mac_url_art_detail($art_info['info']); + $v['data'] = [ + 'id'=>$art_info['info']['art_id'], + 'name'=>$art_info['info']['art_name'], + 'pic'=>mac_url_img($art_info['info']['art_pic']), + 'link'=>$art_info['info']['link'], + 'type'=>[ + 'type_id'=>$art_info['info']['type']['type_id'], + 'type_name'=>$art_info['info']['type']['type_name'], + 'link'=>mac_url_type($art_info['info']['type']), + ], + + ]; + } + elseif($v['ulog_mid']==3){ + $topic_info = model('Topic')->infoData(['topic_id'=>['eq',$v['ulog_rid']]],'*',1); + $topic_info['info']['link'] = mac_url_topic_detail($topic_info['info']); + $v['data'] = [ + 'id'=>$topic_info['info']['topic_id'], + 'name'=>$topic_info['info']['topic_name'], + 'pic'=>mac_url_img($topic_info['info']['topic_pic']), + 'link'=>$topic_info['info']['link'], + 'type'=>[], + ]; + } + elseif($v['ulog_mid']==8){ + $actor_info = model('Actor')->infoData(['actor_id'=>['eq',$v['ulog_rid']]],'*',1); + $actor_info['info']['link'] = mac_url_actor_detail($actor_info['info']); + $v['data'] = [ + 'id'=>$actor_info['info']['actor_id'], + 'name'=>$actor_info['info']['actor_name'], + 'pic'=>mac_url_img($actor_info['info']['actor_pic']), + 'link'=>$actor_info['info']['link'], + 'type'=>[], + ]; + } + } + + if(!empty($user_ids)){ + $where2=[]; + $where['user_id'] = ['in', $user_ids]; + $order='user_id desc'; + $user_list = model('User')->listData($where2,$order,1,999); + $user_list = mac_array_rekey($user_list['list'],'user_id'); + + foreach($list as $k=>&$v){ + $list[$k]['user_name'] = $user_list[$v['user_id']]['user_name']; + } + } + return [ + 'code' => 1, + 'msg' => '获取成功', + 'info' => [ + 'offset' => $offset, + 'limit' => $limit, + 'total' => $total, + 'rows' => $list, + ], + ] ; + //return ['code'=>1,'msg'=>lang('data_list'),'page'=>$page,'pagecount'=>ceil($total/$limit),'limit'=>$limit,'total'=>$total,'list'=>$list]; + } public function infoData($where,$field='*') { if(empty($where) || !is_array($where)){ diff --git a/application/common/validate/Ajax.php b/application/common/validate/Ajax.php new file mode 100644 index 000000000..60c9f7157 --- /dev/null +++ b/application/common/validate/Ajax.php @@ -0,0 +1,30 @@ + 'number|between:1,' . PHP_INT_MAX, + 'vod_id' => 'require|number|between:0,' . PHP_INT_MAX, + 'id' => 'number|between:0,' . PHP_INT_MAX, + 'offset' => 'number|between:0,' . PHP_INT_MAX, + 'limit' => 'number|between:1,500', + 'orderby' => 'in:hits,up,pubdate,hits_week,hits_month,hits_day,score', + 'vod_letter' => 'max:1', + 'vod_name' => 'max:50', + 'vod_tag' => 'max:20', + 'vod_blurb' => 'max:20', + 'vod_class' => 'max:10', + // year,area,class + 'type_id_1' => 'require|number|between:0,' . PHP_INT_MAX, + ]; + + protected $message = [ + + ]; + + protected $scene = [ + + ]; +} \ No newline at end of file diff --git a/application/common/validate/Comment.php b/application/common/validate/Comment.php index 50c6de73e..5d4e638d5 100644 --- a/application/common/validate/Comment.php +++ b/application/common/validate/Comment.php @@ -9,6 +9,10 @@ class Comment extends Validate 'comment_content' => 'require', 'comment_mid' => 'require', 'comment_rid' => 'require', + 'offset' => 'number|between:0,' . PHP_INT_MAX, + 'limit' => 'number|between:1,' . PHP_INT_MAX, + 'rid' => 'number|between:1,' . PHP_INT_MAX, + 'orderby' => 'in:time,up,down' ]; protected $message = [ @@ -21,5 +25,11 @@ class Comment extends Validate protected $scene = [ 'add'=> ['comment_name','comment_content','comment_mid','comment_rid'], 'edit'=> ['comment_name','comment_content'], + 'get_list' => [ + 'offset', + 'limit', + 'rid', + 'orderby', + ], ]; } \ No newline at end of file diff --git a/application/common/validate/Type.php b/application/common/validate/Type.php index 1e5a43989..ea72d8b58 100644 --- a/application/common/validate/Type.php +++ b/application/common/validate/Type.php @@ -5,6 +5,7 @@ class Type extends Validate { protected $rule = [ + 'type_id' => 'number|between:1,' . PHP_INT_MAX, 'type_name' => 'require', ]; @@ -14,6 +15,9 @@ class Type extends Validate ]; protected $scene = [ + 'get_list' => [ + 'type_id', + ], 'add'=> ['type_name'], 'edit'=> ['type_name'], ]; diff --git a/application/common/validate/Vod.php b/application/common/validate/Vod.php index 755966b09..f01315b8e 100644 --- a/application/common/validate/Vod.php +++ b/application/common/validate/Vod.php @@ -7,6 +7,17 @@ class Vod extends Validate protected $rule = [ 'vod_name' => 'require', 'type_id' => 'require', + 'type_id' => 'number|between:1,' . PHP_INT_MAX, + 'vod_id' => 'require|number|between:0,' . PHP_INT_MAX, + 'id' => 'number|between:0,' . PHP_INT_MAX, + 'offset' => 'number|between:0,' . PHP_INT_MAX, + 'limit' => 'number|between:1,500', + 'orderby' => 'in:hits,up,pubdate,hits_week,hits_month,hits_day,score', + 'vod_letter' => 'max:1', + 'vod_name' => 'max:50', + 'vod_tag' => 'max:20', + 'vod_blurb' => 'max:20', + 'vod_class' => 'max:10', ]; protected $message = [ @@ -17,6 +28,21 @@ class Vod extends Validate protected $scene = [ 'add' => ['vod_name','type_id'], 'edit' => ['vod_name','type_id'], + 'get_vod_list' => [ + 'id', + 'offset', + 'limit', + 'orderby', + 'type_id', + 'vod_letter', + 'vod_name', + 'vod_tag', + 'vod_blurb', + 'vod_class', + ], + 'get_vod_detail' => [ + 'vod_id', + ], ]; diff --git a/application/index/controller/Ajax.php b/application/index/controller/Ajax.php index d72d24746..0d4d3624f 100644 --- a/application/index/controller/Ajax.php +++ b/application/index/controller/Ajax.php @@ -1,7 +1,7 @@ 1002,'msg'=>lang('verify_err')]; } - } - + } if($GLOBALS['config']['comment']['login'] ==1){ if(empty(cookie('user_id'))){ return ['code' => 1003, 'msg' =>lang('index/require_login')]; } - $res = model('User')->checkLogin(); + $res = model('User')->checkLogin(); if($res['code']>1) { return ['code' => 1003, 'msg' => lang('index/require_login')]; } @@ -122,7 +120,92 @@ public function saveData() { return $res; } } + public function saveAppData() { + $param = input(); + if($GLOBALS['config']['comment']['verify'] == 1){ + if(!captcha_check($param['verify'])){ + return json(['code'=>1002,'msg'=>lang('verify_err')]); + } + } + if($GLOBALS['config']['comment']['login'] ==1){ + if(empty(cookie('user_id'))){ + return json(['code' => 1003, 'msg' =>lang('index/require_login')]); + } + $res = model('User')->checkLogin(); + if($res['code']>1) { + return json(['code' => 1003, 'msg' => lang('index/require_login')]); + } + } + + if(empty($param['comment_content'])){ + return json(['code'=>1004,'msg'=>lang('index/require_content')]); + } + $cookie = 'comment_timespan'; + if(!empty(cookie($cookie))){ + return json(['code'=>1005,'msg'=>lang('frequently')]); + } + + $param['comment_content']= htmlentities(mac_filter_words($param['comment_content'])); + // if(!preg_match('/[^\x00-\x80]/',$param['comment_content'])){ + // return ['code'=>1005,'msg'=>lang('index/require_cn')]; + // } + + if(!in_array($param['comment_mid'],['1','2','3','8','9','11'])){ + return json(['code'=>1006,'msg'=>lang('index/mid_err')]); + } + + if(empty(cookie('user_id'))){ + $param['comment_name'] = lang('controller/visitor'); + } + else{ + $param['comment_name'] = cookie('user_name'); + $param['user_id'] = intval(cookie('user_id')); + $user_data = model('User')->field('user_nick_name')->where(['user_id' => $param['user_id']])->find(); + if (!empty($user_data['user_nick_name'])) { + $param['comment_name'] = $user_data['user_nick_name']; + } + } + $param['comment_name'] = htmlentities(trim($param['comment_name'])); + $param['comment_rid'] = intval($param['comment_rid']); + $param['comment_pid'] = intval($param['comment_pid']); + if($GLOBALS['config']['comment']['audit'] ==1){ + $param['comment_status'] = 0; + } + + $param['comment_ip'] = mac_get_ip_long(); + $blcaks = config('blacks'); + //判断黑名单关键字是否为空 不为空并且大于0则循环判断是否包含黑名单关键字 + if(!empty($blcaks['black_keyword_list']) && count($blcaks['black_keyword_list']) > 0){ + foreach ($blcaks['black_keyword_list'] as $key => $value) { + if(strpos($param['comment_content'], $value) !== false){ + return json(['code'=>1007,'msg'=>lang('index/blacklist_keyword')]); + } + } + } + //判断黑名单IP是否为空 不为空并且大于0则循环判断客户端ip是否包含黑名单ip + if(!empty($blcaks['black_ip_list']) && count($blcaks['black_ip_list']) > 0){ + $client_ip = long2ip($param['comment_ip']); + if (in_array($client_ip, $blcaks['black_ip_list'])){ + return json(['code'=>1008,'msg'=>lang('index/blacklist_ip')]); + } + } + + $res = model('Comment')->saveData($param); + if($res['code']>1){ + return json($res); + } + else{ + cookie($cookie, 't', $GLOBALS['config']['comment']['timespan']); + if($GLOBALS['config']['comment']['audit'] ==1){ + $res['msg'] = lang('index/thanks_msg_audit'); + } + else{ + $res['msg'] = lang('index/thanks_msg'); + } + return json($res); + } + } public function report() { $param = input(); @@ -187,5 +270,55 @@ public function digg() } return json(['code'=>1,'msg'=>lang('opt_ok'),'data'=>$data]); } +/** + * 获取列表 + * + * @param Request $request + * @return \think\response\Json + */ + public function get_list(Request $request) + { + // 参数校验 + $param = $request->param(); + $validate = validate($request->controller()); + if (!$validate->scene($request->action())->check($param)) { + return json([ + 'code' => 1001, + 'msg' => '参数错误: ' . $validate->getError(), + ]); + } + $offset = isset($param['offset']) ? (int)$param['offset'] : 0; + $limit = isset($param['limit']) ? (int)$param['limit'] : 20; + // 查询条件组装 + $where = []; + if (isset($param['rid'])) { + $where['comment_rid'] = (int)$param['rid']; + } + + // 数据获取 + $total = model('Comment')->getCountByCond($where); + $list = []; + if ($total > 0) { + // 排序 + $order = "comment_time DESC"; + if (strlen($param['orderby']) > 0) { + $order = 'comment_' . $param['orderby'] . " DESC"; + } + $field = '*'; + $list = model('Comment')->getListByCond($offset, $limit, $where, $order, $field, []); + } + // 返回 + return json([ + 'code' => 1, + 'msg' => '获取成功', + 'info' => [ + 'offset' => $offset, + 'limit' => $limit, + 'total' => $total, + 'rows' => $list, + ], + ]); + } + } diff --git a/application/index/controller/Config.php b/application/index/controller/Config.php new file mode 100644 index 000000000..923d345b4 --- /dev/null +++ b/application/index/controller/Config.php @@ -0,0 +1,36 @@ + &$v) { + $v = mac_url_img($v); + } + } + + $res = [ + 'code' => 1, + 'msg' => '获取成功', + 'info' => [ + 'site_banner' => $banner_list, + 'site_app_launch_image' => isset($config['site']['site_app_launch_image']) ? mac_url_img($config['site']['site_app_launch_image']) : '', + ] + ]; + return json($res)->options(['json_encode_param' => JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE]); + } +} diff --git a/application/index/controller/Type.php b/application/index/controller/Type.php new file mode 100644 index 000000000..ea591d293 --- /dev/null +++ b/application/index/controller/Type.php @@ -0,0 +1,59 @@ +param(); + $validate = validate($request->controller()); + if (!$validate->scene($request->action())->check($param)) { + return json([ + 'code' => 1001, + 'msg' => '参数错误: ' . $validate->getError(), + ]); + } + // 查询条件组装 + $where = []; + // 查询第一级 + $where['type_pid'] = 0; + + if (isset($param['type_id'])) { + $where['type_id'] = (int)$param['type_id']; + } + + // 数据获取 + $total = model('Type')->getCountByCond($where); + $list = []; + if ($total > 0) { + // 排序 + $order = "type_sort DESC"; + $field = '*'; + $list = model('Type')->getListByCond(0, PHP_INT_MAX, $where, $order, $field, []); + foreach ($list as $index => $item) { + $child_total = Db::table('mac_type')->where(['type_pid' => $item['type_id']])->count(); + if ($child_total > 0) { + $child = Db::table('mac_type')->where(['type_pid' => $item['type_id']])->order('type_sort ASC')->select(); + $list[$index]['child'] = $child; + } + } + } + // 返回 + return json([ + 'code' => 1, + 'msg' => '获取成功', + 'info' => [ + 'total' => $total, + 'rows' => $list, + ], + ]); + } +} diff --git a/application/index/controller/User.php b/application/index/controller/User.php index f065ac66e..60c62551b 100644 --- a/application/index/controller/User.php +++ b/application/index/controller/User.php @@ -97,7 +97,27 @@ public function ajax_ulog() } return json($res); } - +public function ajax_ulog_list() + { + $param = input(); + $where = []; + $where['user_id'] = $GLOBALS['user']['user_id']; + $param['offset'] = intval($param['offset']) < 1 ? 0 : intval($param['offset']); + $param['limit'] = intval($param['limit']) < 1 ? 10 : intval($param['limit']); + if(intval($param['mid'])>0){ + $where['ulog_mid'] = ['eq',intval($param['mid'])]; + } + if(intval($param['id'])>0){ + $where['ulog_rid'] = ['eq',intval($param['id'])]; + } + if(intval($param['type'])>0){ + $where['ulog_type'] = ['eq',intval($param['type'])]; + } + $order = 'ulog_time desc'; + $res = model('Ulog')->listData_new($where, $order, $param['offset'], $param['limit']); + + return json($res); + } public function ajax_buy_popedom() { $param = input(); diff --git a/application/index/controller/Vod.php b/application/index/controller/Vod.php index cb6456722..a85898d9f 100644 --- a/application/index/controller/Vod.php +++ b/application/index/controller/Vod.php @@ -1,6 +1,8 @@ label_fetch('vod/plot'); } + /** + * 获取视频列表 + * + * @param Request $request + * @return \think\response\Json + */ + public function get_vod_list(Request $request) + { + // 参数校验 + $param = $request->param(); + $validate = validate($request->controller()); + if (!$validate->scene($request->action())->check($param)) { + return json([ + 'code' => 1001, + 'msg' => '参数错误: ' . $validate->getError(), + ]); + } + $offset = isset($param['offset']) ? (int)$param['offset'] : 0; + $limit = isset($param['limit']) ? (int)$param['limit'] : 20; + // 查询条件组装 + $where = []; + if (isset($param['type_id'])) { + $where['type_id'] = (int)$param['type_id']; + } + if (isset($param['id'])) { + $where['vod_id'] =(int) $param['id']; + } +// if (isset($param['type_id_1'])) { +// $where['type_id_1'] = (int)$param['type_id_1']; +// } + if (!empty($param['vod_letter'])) { + $where['vod_letter'] = $param['vod_letter']; + } + if (isset($param['vod_tag']) && strlen($param['vod_tag']) > 0) { + $where['vod_tag'] = ['like', '%' . $this->format_sql_string($param['vod_tag']) . '%']; + } + if (isset($param['vod_name']) && strlen($param['vod_name']) > 0) { + $where['vod_name'] = ['like', '%'.$this->format_sql_string($param['vod_name']).'%']; + } + if (isset($param['vod_blurb']) && strlen($param['vod_blurb']) > 0) { + $where['vod_blurb'] = ['like', '%' . $this->format_sql_string($param['vod_blurb']) . '%']; + } + if (isset($param['vod_class']) && strlen($param['vod_class']) > 0) { + $where['vod_class'] = ['like', '%' . $this->format_sql_string($param['vod_class']) . '%']; + } + if (isset($param['vod_area']) && strlen($param['vod_area']) > 0) { + $where['vod_area'] = $this->format_sql_string($param['vod_area']); + } + if (isset($param['vod_year']) && strlen($param['vod_year']) > 0) { + $where['vod_year'] = $this->format_sql_string($param['vod_year']); + } + // 数据获取 + $total = model('Vod')->getCountByCond($where); + $list = []; + if ($total > 0) { + // 排序 + $order = "vod_time DESC"; + if (strlen($param['orderby']) > 0) { + $order = 'vod_' . $param['orderby'] . " DESC"; + } + $field = 'vod_id,vod_name,vod_actor,vod_hits,vod_hits_day,vod_hits_week,vod_hits_month,vod_time,vod_remarks,vod_score,vod_area,vod_year,vod_tag,vod_pic,vod_pic_thumb,vod_pic_slide,vod_douban_score'; +// $list = model('Vod')->getListByCond($offset, $limit, $where, $order, $field, []); + $list = model('Vod')->getListByCond($offset, $limit, $where, $order, $field); + //把vod_time 字段转换为时间字符串 + foreach ($list as &$value) { + $value['vod_time'] = date('Y-m-d H:i:s', $value['vod_time']); + } + } + // 返回 + return json([ + 'code' => 1, + 'msg' => '获取成功', + 'info' => [ + 'offset' => $offset, + 'limit' => $limit, + 'total' => $total, + 'rows' => $list, + ], + ]); + } + /** + * 视频详细信息 + * + * @param Request $request + * @return \think\response\Json + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\ModelNotFoundException + * @throws \think\exception\DbException + */ + public function get_vod_detail(Request $request) + { + $param = $request->param(); + $validate = validate($request->controller()); + if (!$validate->scene($request->action())->check($param)) { + return json([ + 'code' => 1001, + 'msg' => '参数错误: ' . $validate->getError(), + ]); + } + + $res = Db::table('mac_vod')->where(['vod_id' => $param['vod_id']])->find(); + //判断vod_rel_vod 字段是否为空 + if (!empty($res['vod_rel_vod'])) { + $field = 'vod_id,vod_name,vod_actor,vod_hits,vod_hits_day,vod_hits_week,vod_hits_month,vod_time,vod_remarks,vod_score,vod_area,vod_year,vod_tag,vod_pic,vod_pic_thumb,vod_pic_slide,vod_douban_score'; + $res['vod_rel_vod_list'] = Db::table('mac_vod')->where(['vod_id' => ['in', $res['vod_rel_vod']]])->field($field)->select(); + } + // 返回 + return json([ + 'code' => 1, + 'msg' => '获取成功', + 'info' => $res + ]); + } + protected function format_sql_string($str) + { + $str = preg_replace('/\b(SELECT|INSERT|UPDATE|DELETE|DROP|UNION|WHERE|FROM|JOIN|INTO|VALUES|SET|AND|OR|NOT|EXISTS|HAVING|GROUP BY|ORDER BY|LIMIT|OFFSET)\b/i', '', $str); + $str = preg_replace('/[^\w\s\-\.]/', '', $str); + $str = trim(preg_replace('/\s+/', ' ', $str)); + return $str; + } } diff --git a/application/install/sql/install.sql b/application/install/sql/install.sql index 6ffc65788..b868b0524 100644 --- a/application/install/sql/install.sql +++ b/application/install/sql/install.sql @@ -962,6 +962,7 @@ CREATE TABLE `mac_website` ( ) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 ; + -- ---------------------------- -- Table structure for mac_vod_search -- ---------------------------- diff --git a/runtime/.gitignore b/runtime/.gitignore deleted file mode 100755 index c96a04f00..000000000 --- a/runtime/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -* -!.gitignore \ No newline at end of file diff --git a/runtime/index.html b/runtime/index.html deleted file mode 100644 index e69de29bb..000000000