video.php 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810
  1. <?php
  2. defined('IN_PHPCMS') or exit('No permission resources.');
  3. /**
  4. *
  5. * ------------------------------------------
  6. * video video class
  7. * ------------------------------------------
  8. *
  9. * 视频库管理扩展下的视频管理控制器 控制视频添加、修改、删除及从ku6导入视频等
  10. * 用户在配置好ku6vms账户后才能使用该模块。
  11. * 在此扩展下对视频的所有操作通过接口同步到ku6vms下面
  12. *
  13. * @package PHPCMS V9.1.16
  14. * @author chenxuewang
  15. * @copyright CopyRight (c) 2006-2012 上海盛大网络发展有限公司
  16. *
  17. */
  18. pc_base::load_app_class('admin', 'admin', 0);
  19. pc_base::load_sys_class('form', 0, 0);
  20. pc_base::load_app_func('global', 'video');
  21. class video extends admin {
  22. public $db,$module_db;
  23. public function __construct() {
  24. parent::__construct();
  25. $this->db = pc_base::load_model('video_store_model');
  26. $this->module_db = pc_base::load_model('module_model');
  27. $this->userid = $_SESSION['userid'];
  28. pc_base::load_app_class('ku6api', 'video', 0);
  29. pc_base::load_app_class('v', 'video', 0);
  30. $this->v = new v($this->db);
  31. //获取短信平台配置信息
  32. $this->setting = getcache('video');
  33. $this->ku6api = new ku6api($this->setting['sn'], $this->setting['skey']);
  34. }
  35. /**
  36. *
  37. * 视频列表
  38. */
  39. public function init() {
  40. $where = '';
  41. $page = $_GET['page'];
  42. $pagesize = 20;
  43. if($_GET['q']){
  44. if (isset($_GET['type'])) {
  45. if ($_GET['type']==1) {
  46. $where .= ' `videoid`=\''.$_GET['q'].'\'';
  47. } else {
  48. $where .= " `title` LIKE '%".$_GET['q']."%'";
  49. }
  50. }
  51. }
  52. if (isset($_GET['start_addtime']) && !empty($_GET['start_addtime'])) {
  53. $where .= !empty($where) ? ' AND `addtime`>=\''.strtotime($_GET['start_addtime']).'\'' : ' `addtime`>=\''.strtotime($_GET['start_addtime']).'\'';
  54. }
  55. if (!empty($_GET['end_addtime'])) {
  56. $where .= !empty($where) ? ' AND `addtime`<=\''.strtotime($_GET['end_addtime']).'\'' : ' `addtime`<=\''.strtotime($_GET['end_addtime']).'\'';
  57. }
  58. $userupload = intval($_GET['userupload']);
  59. if ($userupload) {
  60. $where .= ' AND `userupload`=1';
  61. }
  62. $infos = $this->db->listinfo($where, 'videoid DESC', $page, $pagesize);
  63. $pages = $this->db->pages;
  64. include $this->admin_tpl('video_list');
  65. }
  66. /**
  67. *
  68. * 视频添加方法
  69. */
  70. public function add() {
  71. if ($_POST['dosubmit']) {
  72. //首先处理,提交过来的数据
  73. $data['vid'] = safe_replace($_POST['vid']);
  74. if (!$data['vid']) showmessage(L('failed_you_video_uploading'), 'index.php?m=video&c=video&a=add');
  75. $data['title'] = isset($_POST['title']) && trim($_POST['title']) ? trim($_POST['title']) : showmessage(L('video_title_not_empty'), 'index.php?m=video&c=video&a=add&meunid='.$_GET['meunid']);
  76. $data['description'] = trim($_POST['description']);
  77. $data['keywords'] = trim(strip_tags($_POST['keywords']));
  78. $data['channelid'] = intval($_POST['channelid']);
  79. //其次向vms post数据,并取得返回值
  80. $get_data = $this->ku6api->vms_add($data);
  81. if (!$get_data) {
  82. showmessage($this->ku6api->error_msg);
  83. }
  84. $data['vid'] = $get_data['vid'];
  85. $data['addtime'] = SYS_TIME;
  86. $data['userupload'] = intval($_POST['userupload']);
  87. $videoid = $this->v->add($data);
  88. if ($videoid) {
  89. showmessage(L('operation_success'), 'index.php?m=video&c=video&a=init&meunid='.$_GET['meunid']);
  90. } else {
  91. showmessage(L('operation_failure'), 'index.php?m=video&c=video&a=add&meunid='.$_GET['meunid']);
  92. }
  93. } else {
  94. if((empty($this->setting['sn']) || empty($this->setting['skey'])) && ROUTE_A!='open') {
  95. header("Location: ".APP_PATH."index.php?m=video&c=video&a=open&meunid=".$_GET['meunid'].'&pc_hash='.$_GET['pc_hash']);
  96. }
  97. if(!$this->ku6api->testapi()) {
  98. header("Location: ".APP_PATH."index.php?m=video&c=video&a=open&meunid=".$_GET['meunid'].'&pc_hash='.$_GET['pc_hash']);
  99. }
  100. $flash_info = $this->ku6api->flashuploadparam();
  101. $show_validator = true;
  102. include $this->admin_tpl('video_add');
  103. }
  104. }
  105. /**
  106. * function edit
  107. * 视频编辑控制器
  108. */
  109. public function edit() {
  110. $vid = intval($_GET['vid']);
  111. if (!$vid) showmessage(L('illegal_parameters'));
  112. if (isset($_POST['dosubmit'])) {
  113. //首先处理,提交过来的数据
  114. $data['vid'] = $_POST['vid'];
  115. if (!$data['vid']) showmessage(L('failed_you_video_uploading'), 'index.php?m=video&c=video&a=add');
  116. $data['title'] = isset($_POST['title']) && trim($_POST['title']) ? trim($_POST['title']) : showmessage(L('video_title_not_empty'), 'index.php?m=video&c=video&a=add&meunid='.$_GET['meunid']);
  117. $data['description'] = trim($_POST['description']);
  118. $data['keywords'] = trim(strip_tags($_POST['keywords']));
  119. //其次向vms post数据,并取得返回值
  120. if ($this->ku6api->vms_edit($data)) {
  121. $return = $this->v->edit($data, $vid);
  122. if ($return) showmessage(L('operation_success'), 'index.php?m=video&c=video&a=init');
  123. else showmessage(L('operation_failure'), 'index.php?m=video&c=video&a=edit&vid='.$vid.'&menuid='.$_GET['menuid']);
  124. } else {
  125. showmessage($this->ku6api->error_msg, 'index.php?m=video&c=video&a=edit&vid='.$vid.'&menuid='.$_GET['menuid']);
  126. }
  127. } else {
  128. $show_validator = true;
  129. $info = $this->db->get_one(array('videoid'=>$vid));
  130. include $this->admin_tpl('video_edit');
  131. }
  132. }
  133. /**
  134. * function delete
  135. * 删除视频控制器
  136. */
  137. public function delete() {
  138. $vid = $_GET['vid'];
  139. $r = $this->db->get_one(array('videoid'=>$vid), 'vid');
  140. if (!$r) showmessage(L('video_not_exist_or_deleted'));
  141. if (!$this->ku6api->delete_v($r['vid'])) showmessage(L('operation_failure'), 'index.php?m=video&c=video&a=init&meunid='.$_GET['meunid']);
  142. $this->v->del_video($vid);
  143. showmessage(L('success_next_update_content'), 'index.php?m=video&c=video&a=public_update_content&vid='.$vid.'&meunid='.$_GET['meunid']);
  144. }
  145. /**
  146. * function delete_all
  147. * 批量删除视频
  148. * @删除视频时,注意同时删除视频库内容对应关系表中的相关数据,因为操作时间限制,无法同时更新相关的内容。删除完成时需要提醒用户
  149. */
  150. public function delete_all() {
  151. if (isset($_GET['dosubmit'])) {
  152. $ids = $_POST['ids'];
  153. if (is_array($ids)) {
  154. $video_content_db = pc_base::load_model('video_content_model');
  155. foreach ($ids as $videoid) {
  156. $videoid = intval($videoid);
  157. $r = $this->db->get_one(array('videoid'=>$videoid), 'vid');
  158. if (!$this->ku6api->delete_v($r['vid'])) continue;
  159. $this->v->del_video($videoid);
  160. $video_content_db->delete(array('videoid'=>$videoid));
  161. }
  162. }
  163. showmessage(L('succfull_create_index'));
  164. }
  165. }
  166. /**
  167. * Function UPDATE_CONTENT
  168. * 更新与此视频关联的内容模型
  169. * @param int $vid 视频库videoid字段
  170. */
  171. public function public_update_content() {
  172. $videoid = intval($_GET['vid']);
  173. $video_content_db = pc_base::load_model('video_content_model');
  174. $meunid = intval($_GET['meunid']);
  175. $pagesize = 10;
  176. $result = $video_content_db->select(array('videoid'=>$videoid), '*', $pagesize);
  177. if (!$result || empty($result)) {
  178. showmessage(L('update_complete'), 'index.php?m=video&c=video&a=init&meunid='.$meunid);
  179. }
  180. //加载更新html类
  181. $html = pc_base::load_app_class('html', 'content');
  182. $content_db = pc_base::load_model('content_model');
  183. $url = pc_base::load_app_class('url', 'content');
  184. foreach ($result as $rs) {
  185. $modelid = intval($rs['modelid']);
  186. $contentid = intval($rs['contentid']);
  187. $video_content_db->delete(array('videoid'=>$videoid, 'contentid'=>$contentid, 'modelid'=>$modelid));
  188. $content_db->set_model($modelid);
  189. $table_name = $content_db->table_name;
  190. $r1 = $content_db->get_one(array('id'=>$contentid));
  191. if ($this->ishtml($r1['catid'])) {
  192. $content_db->table_name = $table_name.'_data';
  193. $r2 = $content_db->get_one(array('id'=>$contentid));
  194. $r = array_merge($r1, $r2);unset($r1, $r2);
  195. if($r['upgrade']) {
  196. $urls[1] = $r['url'];
  197. } else {
  198. $urls = $url->show($r['id'], '', $r['catid'], $r['inputtime']);
  199. }
  200. $html->show($urls[1], $r, 0, 'edit');
  201. } else {
  202. continue;
  203. }
  204. }
  205. showmessage(L('part_update_complete'), 'index.php?m=video&c=video&a=public_update_content&vid='.$videoid.'&meunid='.$meunid);
  206. }
  207. /**
  208. * Function ISHTML
  209. * 判断内容是否需要生成静态
  210. * @param int $catid 栏目id
  211. */
  212. private function ishtml($catid = 0) {
  213. static $ishtml, $catid_siteid;
  214. if (!$ishtml[$catid]) {
  215. if (!$catid_siteid) {
  216. $catid_siteid = getcache('category_content', 'commons');
  217. } else {
  218. $siteid = $catid_siteid[$catid];
  219. }
  220. $siteid = $catid_siteid[$catid];
  221. $categorys = getcache('category_content_'.$siteid, 'commons');
  222. $ishtml[$catid] = $categorys[$catid]['content_ishtml'];
  223. }
  224. return $ishtml[$catid];
  225. }
  226. /**
  227. *
  228. * 配置视频参数。包括身份识别码、加密密钥、调用方案编号等信息
  229. */
  230. public function setting() {
  231. if(isset($_POST['dosubmit'])) {
  232. $setting = array2string($_POST['setting']);
  233. setcache('video', $_POST['setting']);
  234. $this->ku6api->ku6api_skey = $_POST['setting']['skey'];
  235. $this->ku6api->ku6api_sn = $_POST['setting']['sn'];
  236. $this->module_db->update(array('setting'=>$setting),array('module'=>'video'));
  237. if(!$this->ku6api->testapi()) {
  238. showmessage(L('vms_sn_skey_error'),'?m=video&c=video&a=open');
  239. }
  240. showmessage(L('operation_success'),'?m=video&c=video&a=open');
  241. } else {
  242. $show_pc_hash = '';
  243. $v_model_categorys = $this->ku6api->get_categorys(true, $this->setting['catid']);
  244. $category_list = '<select name="setting[catid]" id="catid"><option value="0">'.L('please_choose_catid').'</option>'.$v_model_categorys.'</select>';
  245. include $this->admin_tpl('video_open');
  246. }
  247. }
  248. //获取SKEY ,SN 写入缓存
  249. public function set_video_setting(){
  250. $array['skey'] = $_GET['skey'];
  251. $array['sn'] = $_GET['sn'];
  252. if(empty($_GET['skey']) || empty($_GET['sn'])){
  253. showmessage(L('操作失败!正在返回!'),'?m=admin');
  254. }
  255. $setting = array2string($array);
  256. setcache('video', $array);
  257. $this->ku6api->ku6api_skey = $_GET['skey'];
  258. $this->ku6api->ku6api_sn = $_GET['sn'];
  259. $this->module_db->update(array('setting'=>$setting),array('module'=>'video'));
  260. showmessage(L('operation_success'),'?m=admin');
  261. }
  262. /**
  263. * function get_pos 获取推荐位
  264. * 根据栏目获取推荐位id,并生成form的select形式
  265. */
  266. public function public_get_pos () {
  267. $catid = intval($_GET['catid']);
  268. if (!$catid) exit(0);
  269. $position = getcache('position','commons');
  270. if(empty($position)) exit;
  271. $category = pc_base::load_model('category_model');
  272. $info = $category->get_one(array('catid'=>$catid), 'modelid, arrchildid');
  273. if (!$info) exit(0);
  274. $modelid = $info['modelid'];
  275. $array = array();
  276. foreach($position as $_key=>$_value) {
  277. if($_value['modelid'] && ($_value['modelid'] != $modelid) || ($_value['catid'] && strpos(','.$info['arrchildid'].',',','.$catid.',')===false)) continue;
  278. $array[$_key] = $_value['name'];
  279. }
  280. $data = form::select($array, '', 'name="sub[posid]"', L('please_select'));
  281. exit($data);
  282. }
  283. /**
  284. * Function subscribe_list 获取订阅列表
  285. * 获取订阅列表
  286. */
  287. public function subscribe_list() {
  288. if (isset($_GET['dosubmit'])) {
  289. if (is_array($_GET['sub']) && !empty($_GET['sub'])) {
  290. $sub = $_GET['sub'];
  291. if (!$sub['channelid'] || !$sub['catid']) showmessage(L('please_choose_catid_and_channel'));
  292. $sub['catid'] = intval($sub['catid']);
  293. $sub['posid'] = intval($sub['posid']);
  294. $result = $this->ku6api->subscribe($sub);
  295. if ($result['check'] == 6) showmessage(L('subscribe_for_default'));
  296. if ($result['code'] == 200) showmessage(L('operation_success'), 'index.php?m=video&c=video&a=subscribe_list');
  297. else showmessage(L('subscribe_set_failed'), 'index.php?m=video&c=video&a=subscribe_list&meunid='.$_GET['meunid']);
  298. } else {
  299. showmessage(L('please_choose_catid_and_channel'), 'index.php?m=video&c=video&a=subscribe_list&meunid='.$_GET['meunid']);
  300. }
  301. } else {
  302. $type = isset($_GET['type']) ? intval($_GET['type']) : 1;
  303. if((empty($this->setting['sn']) || empty($this->setting['skey'])) && ROUTE_A!='open') {
  304. header("Location: ".APP_PATH."index.php?m=video&c=video&a=open&meunid=".$_GET['meunid'].'&pc_hash='.$_GET['pc_hash']);
  305. }
  306. if(!$this->ku6api->testapi()) {
  307. header("Location: ".APP_PATH."index.php?m=video&c=video&a=open&meunid=".$_GET['meunid'].'&pc_hash='.$_GET['pc_hash']);
  308. }
  309. //获取用户订阅信息
  310. $v_model_categorys = $this->ku6api->get_categorys(true);
  311. $category_list = '<select name="sub[catid]" id="catid" onchange="select_pos(this)"><option value="0">'.L('please_choose_catid').'</option>'.$v_model_categorys.'</select>';
  312. $siteid = get_siteid();
  313. $CATEGORYS = getcache('category_content_'.$siteid, 'commons');
  314. $ku6_channels = $this->ku6api->get_subscribetype();
  315. $subscribes = $this->ku6api->get_subscribe();
  316. $usersubscribes = $this->ku6api->get_usersubscribe();
  317. $position = getcache('position','commons');
  318. include $this->admin_tpl('subscribe_list');
  319. }
  320. }
  321. /**
  322. * Function Sub_DEl 删除订阅
  323. * 用户删除订阅方法
  324. */
  325. public function sub_del() {
  326. $id = intval($_GET['id']);
  327. if (!$id) showmessage(L('illegal_parameters'), 'index.php?m=video&c=video&a=subscribe_list&meunid='.$_GET['meunid']);
  328. if ($this->ku6api->sub_del($id)) showmessage(L('operation_success'), 'index.php?m=video&c=video&a=subscribe_list&meunid='.$_GET['meunid']);
  329. else showmessage(L('delete_failed'), 'index.php?m=video&c=video&a=subscribe_list&meunid='.$_GET['meunid']);
  330. }
  331. /**
  332. * Function sub_del 删除订阅用户
  333. * 删除订阅用户方法
  334. */
  335. public function user_sub_del() {
  336. $id = intval($_GET['id']);
  337. $type = intval($_GET['type']);
  338. if (!$id) showmessage(L('illegal_parameters'), 'index.php?m=video&c=video&a=subscribe_list&meunid='.$_GET['meunid']);
  339. if ($this->ku6api->user_sub_del($id)) showmessage(L('operation_success'), 'index.php?m=video&c=video&a=subscribe_list&meunid='.$_GET['meunid'].'&type='.$type);
  340. else showmessage(L('delete_failed'), 'index.php?m=video&c=video&a=subscribe_list&meunid='.$_GET['meunid'].'&type='.$type);
  341. }
  342. /**
  343. * Function video2content 视频库中视频
  344. * 用户选择在视频中选择已上传的视频加入到视频字段或编辑器中
  345. */
  346. public function video2content () {
  347. $page = max(intval($_GET['page']), 1);
  348. $pagesize = isset($_GET['pagesize']) ? intval($_GET['pagesize']) : 8;
  349. $where = '`status` = 21';
  350. if (isset($_GET['name']) && !empty($_GET['name'])) {
  351. $title = safe_replace($_GET['name']);
  352. $where .= " AND `title` LIKE '%$title%'";
  353. }
  354. if (isset($_GET['starttime']) && !empty($_GET['starttime'])) {
  355. $addtime = strtotime($_GET['starttime']);
  356. $where .= " AND `addtime`>='$addtime'";
  357. }
  358. if (isset($_GET['endtime']) && !empty($_GET['endtime'])) {
  359. $endtime = strtotime($_GET['endtime']);
  360. $where .= " AND `addtime` <= '$endtime'";
  361. }
  362. if ($_GET['userupload']) {
  363. $userupload = intval($_GET['userupload']);
  364. $where .= " AND `userupload`=1";
  365. }
  366. $show_header = 1;
  367. $infos = $this->db->listinfo($where, '`videoid` DESC', $page, $pagesize, '', 5);
  368. $pages = $this->db->pages;
  369. include $this->admin_tpl('album_list');
  370. }
  371. /**
  372. * 设置swfupload上传的json格式cookie
  373. */
  374. public function swfupload_json() {
  375. $arr['id'] = $_GET['id'];
  376. $arr['src'] = trim($_GET['src']);
  377. $arr['title'] = urlencode($_GET['title']);
  378. $json_str = json_encode($arr);
  379. $att_arr_exist = param::get_cookie('att_json');
  380. $att_arr_exist_tmp = explode('||', $att_arr_exist);
  381. if(is_array($att_arr_exist_tmp) && in_array($json_str, $att_arr_exist_tmp)) {
  382. return true;
  383. } else {
  384. $json_str = $att_arr_exist ? $att_arr_exist.'||'.$json_str : $json_str;
  385. param::set_cookie('att_json',$json_str);
  386. return true;
  387. }
  388. }
  389. /**
  390. * 删除swfupload上传的json格式cookie
  391. */
  392. public function swfupload_json_del() {
  393. $arr['aid'] = intval($_GET['aid']);
  394. $arr['src'] = trim($_GET['src']);
  395. $arr['filename'] = urlencode($_GET['filename']);
  396. $json_str = json_encode($arr);
  397. $att_arr_exist = param::get_cookie('att_json');
  398. $att_arr_exist = str_replace(array($json_str,'||||'), array('','||'), $att_arr_exist);
  399. $att_arr_exist = preg_replace('/^\|\|||\|\|$/i', '', $att_arr_exist);
  400. param::set_cookie('att_json',$att_arr_exist);
  401. }
  402. /**
  403. * 导入KU6视频
  404. */
  405. public function import_ku6video(){
  406. if(!$this->ku6api->testapi()) {
  407. header("Location: ".APP_PATH."index.php?m=video&c=video&a=open&meunid=".$_GET['meunid'].'&pc_hash='.$_GET['pc_hash']);
  408. }
  409. pc_base::load_sys_class('format','',0);
  410. $do = isset($_GET['do']) ? $_GET['do'] : '';
  411. $ku6url = isset($_GET['ku6url']) ? $_GET['ku6url'] : '';
  412. $time = isset($_GET['time']) ? $_GET['time'] : '';
  413. $keyword = isset($_GET['keyword']) ? $_GET['keyword'] : '*:*';
  414. $len = isset($_GET['len']) ? $_GET['len'] : '';//时长s:小于4分钟 I:大于4分钟
  415. $fenlei = isset($_GET['fenlei']) ? $_GET['fenlei'] : '*:*';//搜索分类
  416. $srctype = isset($_GET['srctype']) ? $_GET['srctype'] : 0;//视频质量
  417. $videotime = isset($_GET['videotime']) ? $_GET['videotime'] : 0;//视频时长
  418. $page = isset($_GET['page']) ? $_GET['page'] : '1';
  419. $pagesize = 20;
  420. $list = array();
  421. if(CHARSET!='utf-8'){
  422. $keyword = iconv('gbk', 'utf-8', $keyword);
  423. }
  424. $keyword = urlencode($keyword);
  425. $data = $this->ku6api->Ku6search($keyword,$pagesize,$page,$srctype,$len,$fenlei,$videotime);
  426. $totals = $data['data']['total'];
  427. $list = $data['data']['list'];
  428. //获取视频大小接口
  429. if(isset($list) && is_array($list) && count($list) > 0) {
  430. foreach ($list as $key=>$v) {
  431. $spaceurl = "http://v.ku6.com/fetchVideo4Player/1/$v[vid].html";
  432. $spacejson = file_get_contents($spaceurl);
  433. $space = json_decode($spacejson, 1);
  434. $list[$key]['size'] = $space['data']['videosize'];
  435. $list[$key]['uploadTime'] = substr($v['uploadtime'], 0, 10);
  436. //判断那些已经导入过本机系统 $vidstr .= ',\''.$v['vid'].'\'';
  437. }
  438. }
  439. //选择站点和栏目进行导入
  440. $sitelist = getcache('sitelist','commons');
  441. //分类数组
  442. $fenlei_array = array('101000'=>'资讯','102000'=>'体育','103000'=>'娱乐','104000'=>'电影','105000'=>'原创','106000'=>'广告','107000'=>'美女','108000'=>'搞笑','109000'=>'游戏','110000'=>'动漫','111000'=>'教育','113000'=>'生活','114000'=>'汽车','115000'=>'房产','116000'=>'音乐','117000'=>'电视','118000'=>'综艺','125000'=>'女生','126000'=>'记录','127000'=>'科技','190000'=>'其它');
  443. //视频质量
  444. $srctype_array = array('1'=>'超清','2'=>'高清','3'=>'标清','4'=>'流畅');
  445. $videotime_array = array('1'=>'短视频','2'=>'普通视频','3'=>'中视频','4'=>'长视频');
  446. //本机视频栏目
  447. $categoryrr = $this->get_category();
  448. include $this->admin_tpl('import_ku6video');
  449. }
  450. /**
  451. * 搜索视频浏览
  452. */
  453. public function preview_ku6video(){
  454. $ku6vid = $_GET['ku6vid'];
  455. $data = $this->ku6api->Preview($ku6vid);
  456. include $this->admin_tpl('priview_ku6video');
  457. }
  458. /**
  459. * 获取站点栏目数据
  460. */
  461. public function get_category(){
  462. $siteid = get_siteid();//直取SITEID值
  463. $sitemodel_field = pc_base::load_model('sitemodel_field_model');
  464. $result = $sitemodel_field->select(array('formtype'=>'video', 'siteid'=>$siteid), 'modelid');
  465. if (is_array($result)) {
  466. $models = '';
  467. foreach ($result as $r) {
  468. $models .= $r['modelid'].',';
  469. }
  470. }
  471. $models = substr(trim($models), 0, -1);
  472. $cat_db = pc_base::load_model('category_model');
  473. if ($models) {
  474. $where = '`modelid` IN ('.$models.') AND `type`=0 AND `siteid`=\''.$siteid.'\'';
  475. $result = $cat_db->select($where, '`catid`, `catname`, `parentid`, `siteid`, `child`');
  476. if (is_array($result)) {
  477. $data = $return_data = $categorys = array();
  478. $tree = pc_base::load_sys_class('tree');
  479. $data = $return_data = $categorys = array();
  480. $tree = pc_base::load_sys_class('tree');//factory::load_class('tree', 'utils');
  481. $string = '<select name="select_category" id="select_category" onchange="select_pos(this)">';
  482. $string .= "<option value=0>请选择分类</option>";
  483. foreach ($result as $r) {
  484. $r['html_disabled'] = "";
  485. if ($r['child']) {
  486. $r['html_disabled'] = "disabled";
  487. }
  488. $categorys[$r['catid']] = $r;
  489. }
  490. $str = $str2 = "<option value=\$catid \$html_disabled \$selected>\$spacer \$catname</option>"; $tree->init($categorys);
  491. $string .= $tree->get_tree_category(0, $str, $str2);
  492. $string .= '</select>';
  493. return $string;//不使用前台js调用,使用return ;
  494. }
  495. }
  496. return array();
  497. }
  498. public function public_view_video() {
  499. $id = intval($_GET['id']);
  500. if (!$id) showmessage('请选择要浏览的视频!');
  501. $r = $this->db->get_one(array('videoid'=>$id), 'vid,channelid');
  502. $video_cache = $this->setting;
  503. $show_header = 1;
  504. include $this->admin_tpl('view_video');
  505. }
  506. /**
  507. *@ function public_check_status
  508. *@ 手动检查视频状态
  509. */
  510. public function public_check_status() {
  511. $id = intval($_GET['id']);
  512. if (!$id) exit('1');
  513. $r = $this->db->get_one(array('videoid'=>$id), 'vid,channelid,status,picpath');
  514. if (!$r) exit('2');
  515. $return = $this->ku6api->check_status($r['vid']);
  516. if (!$return) exit('3');
  517. $status_arr = pc_base::load_config('ku6status_config');
  518. if ($return['ku6status'] != $r['status']) {
  519. $this->db->update(array('status'=>$return['ku6status'], 'picpath'=>$return['picpath']), array('videoid'=>$id));
  520. if ($return['ku6status']==21) {
  521. /**
  522. * 加载视频内容对应关系数据模型,检索与删除视频相关的内容。
  523. * 在对应关系表中找出对应的内容id,并更新内容的静态页
  524. */
  525. $video_content_db = pc_base::load_model('video_content_model');
  526. $result = $video_content_db->select(array('videoid'=>$id));
  527. if (is_array($result) && !empty($result)) {
  528. //加载更新html类
  529. $html = pc_base::load_app_class('html', 'content');
  530. $content_db = pc_base::load_model('content_model');
  531. $content_check_db = pc_base::load_model('content_check_model');
  532. $url = pc_base::load_app_class('url', 'content');
  533. foreach ($result as $rs) {
  534. $modelid = intval($rs['modelid']);
  535. $contentid = intval($rs['contentid']);
  536. $content_db->set_model($modelid);
  537. $c_info = $content_db->get_one(array('id'=>$contentid), 'thumb');
  538. $where = array('status'=>99);
  539. if (!$c_info['thumb']) $where['thumb'] = $return['picpath'];
  540. $content_db->update($where, array('id'=>$contentid));
  541. $checkid = 'c-'.$contentid.'-'.$modelid;
  542. $content_check_db->delete(array('checkid'=>$checkid));
  543. $table_name = $content_db->table_name;
  544. $r1 = $content_db->get_one(array('id'=>$contentid));
  545. /**
  546. * 判断如果内容页生成了静态页,则更新静态页
  547. */
  548. if (ishtml($r1['catid'])) {
  549. $content_db->table_name = $table_name.'_data';
  550. $r2 = $content_db->get_one(array('id'=>$contentid));
  551. $r = array_merge($r1, $r2);unset($r1, $r2);
  552. if($r['upgrade']) {
  553. $urls[1] = $r['url'];
  554. } else {
  555. $urls = $url->show($r['id'], '', $r['catid'], $r['inputtime']);
  556. }
  557. $html->show($urls[1], $r, 0, 'edit');
  558. } else {
  559. continue;
  560. }
  561. }
  562. }
  563. $msg_r = json_encode(array('change'=>1, 'status'=>21, 'statusname'=>iconv(CHARSET, 'UTF-8', $status_arr[$return['ku6status']])));
  564. } else {
  565. $msg_r = json_encode(array('change'=>1, 'status'=>$return['ku6status'], 'statusname'=>iconv(CHARSET, 'UTF-8', $status_arr[$return['ku6status']])));
  566. }
  567. } else if (!$r['picpath'] && $return['picpath']) {
  568. $this->db->update(array('picpath'=>$return['picpath']), array('videoid'=>$id));
  569. $msg_r = json_encode(array('change'=>1, 'status'=>$return['ku6status'], 'statusname'=>iconv(CHARSET, 'UTF-8', $status_arr[$return['ku6status']])));
  570. }else {
  571. $msg_r = json_encode(array('change'=>0));
  572. }
  573. exit($msg_r);
  574. }
  575. /***********2013.1.15添加**********/
  576. /**
  577. * 后台申请开通视频聚合功能。服务器自动返回配置视频参数。包括身份识别码、加密密钥、调用方案编号等信息
  578. */
  579. public function open() {
  580. $this->setting = getcache('video');
  581. if(empty($this->setting['skey']) || empty($this->setting['sn'])){
  582. //配置不存在,则先验证域名是否存在,如果存在,直接跳去验证页面
  583. $check_user_back = APP_PATH . 'api.php?op=video_api';
  584. $return_check = $this->ku6api->check_user_back($check_user_back);
  585. if ($return_check==200 && SITE_URL != 'localhost' && !preg_match("/^(127|192|10)\.([1-2]?)([0-9]?)([0-9])\.([1-2]?)([0-9]?)([0-9])\.([1-2]?)([0-9]?)([0-9])/", SITE_URL)) {//存在同域名记录,进行email验证
  586. header("Location: ".APP_PATH."index.php?m=video&c=video&a=check_user_back&meunid=".$_GET['meunid'].'&pc_hash='.$_GET['pc_hash']);
  587. exit;
  588. }
  589. //配置不存在,跳转至盛大通行证登录页面
  590. $user_back = APP_PATH . 'api.php?op=video_api';
  591. $user_back = str_replace("/","__",$user_back);
  592. $user_back = urlencode(str_replace(".php","@php",$user_back));
  593. include $this->admin_tpl('video_open');
  594. } else {
  595. $config_flag = false;
  596. if($this->ku6api->testapi()) {
  597. $config_flag = true;
  598. }
  599. include $this->admin_tpl('video_setting');
  600. }
  601. }
  602. //完善详细资料,通过API接口完善资料,获取 SKEY,SN
  603. public function complete_info() {
  604. if(isset($_POST['dosubmit'])) {
  605. $info = safe_replace($_POST['info']); //包含隐藏的uid
  606. if (CHARSET == 'gbk') {
  607. $info = array_iconv($info);
  608. }
  609. //提交数据,获取SKEY,SN
  610. $return_skey_sn = $this->ku6api->complete_info($info);
  611. if(is_array($return_skey_sn) && !empty($return_skey_sn)){
  612. $setting = array2string($return_skey_sn);
  613. setcache('video', $return_skey_sn);
  614. $this->ku6api->ku6api_skey = $return_skey_sn['skey'];
  615. $this->ku6api->ku6api_sn = $return_skey_sn['sn'];
  616. $this->module_db->update(array('setting'=>$setting),array('module'=>'video'));
  617. showmessage('资料提交成功,已成功开通视频应用,正在返回!','?m=video&c=video&a=open');
  618. }else{
  619. echo $return_skey_sn;exit;
  620. showmessage('资料提交失败,请联系商务人员处理!','?m=video&c=video&a=open');
  621. }
  622. }else{
  623. //如果传递uid,snid则为登录通行证成功,返回完善资料,没有传递则为自行填写资料申请开通视频应用
  624. $uid = intval($_GET['uid']);
  625. $snid = $_GET['snid'];
  626. if(empty($this->setting['skey']) || empty($this->setting['sn'])){
  627. if(!$snid) showmessage("请先登录盛大通行证");
  628. }
  629. //如果skey,sn存在,通过接口调取用户完善的资料,再提交为修改操作
  630. $skey_sn_array = getcache('video');
  631. if(!empty($skey_sn_array['skey']) && !empty($skey_sn_array['sn'])){
  632. $return_info = $this->ku6api->Get_Complete_Info($skey_sn_array);
  633. if (CHARSET == 'gbk') {
  634. $return_info = array_iconv($return_info,'utf-8','gbk');
  635. }
  636. $complete_info = is_array($return_info) ? $return_info : array();
  637. $uid = $complete_info['uid'];
  638. $snid = $complete_info['sndaid'];
  639. }else{
  640. //没有配置则判断域名在聚合平台是否已经存在,如果存在进行验证获取SKEY
  641. $check_user_back = APP_PATH . 'api.php?op=video_api';
  642. $return_check = $this->ku6api->check_user_back($check_user_back);
  643. if($return_check==200){//存在同域名记录,进行email验证
  644. showmessage('域名已经存在,请验证开通视频应用!','?m=video&c=video&a=check_user_back');
  645. }
  646. $complete_info = array();
  647. }
  648. $show_dialog = 1;
  649. $show_header = $show_scroll = true;
  650. include $this->admin_tpl('video_complete_info');
  651. }
  652. }
  653. //Email 验证老网站,获取sn,skey
  654. public function check_user_back(){
  655. if(isset($_POST['dosubmit_new'])) {
  656. $data['email'] = $_POST['email'];
  657. $data['code'] = $_POST['code'];
  658. if(empty($data['email']) || empty($data['code'])) return false;
  659. $return_skey_sn = $this->ku6api->check_email_code($data);
  660. if(is_array($return_skey_sn) && !empty($return_skey_sn)){
  661. $setting = array2string($return_skey_sn);
  662. setcache('video', $return_skey_sn);
  663. $this->ku6api->ku6api_skey = $return_skey_sn['skey'];
  664. $this->ku6api->ku6api_sn = $return_skey_sn['sn'];
  665. $this->module_db->update(array('setting'=>$setting),array('module'=>'video'));
  666. showmessage('验证成功,已成功开通视频应用,正在返回!','?m=video&c=video&a=open');
  667. }else{
  668. showmessage('验证失败,请返回!',HTTP_REFERER);
  669. }
  670. }else{
  671. $show_dialog = 1;
  672. $show_header = $show_scroll = true;
  673. include $this->admin_tpl('video_check_user_back');
  674. }
  675. }
  676. //由平台发送验证码到指定信箱
  677. public function send_code(){
  678. $data['email'] = $_GET['email'];
  679. $data['url'] = APP_PATH . 'api.php?op=video_api';
  680. $return = $this->ku6api->send_code($data);
  681. if($return['code']=='200'){
  682. echo 1;
  683. }else{
  684. echo 2;
  685. }
  686. }
  687. //获取传递的skey ,sn 写入缓存
  688. public function get_skey_sn(){
  689. $skey = $_REQUEST['skey'];
  690. $sn = $_REQUEST['sn'];
  691. if(empty($skey) || empty($sn)){
  692. showmessage('视频配置信息不能为空',HTTP_REFERER);
  693. }
  694. $setting_arr['skey'] = $skey;
  695. $setting_arr['sn'] = $sn;
  696. $setting = array2string($setting_arr);
  697. setcache('video', $setting_arr);//写缓存
  698. $this->module_db->update(array('setting'=>$setting),array('module'=>'video'));//更新模版数据
  699. //验证配置
  700. $this->ku6api->ku6api_skey = $skey;
  701. $this->ku6api->ku6api_sn = $sn;
  702. if(!$this->ku6api->testapi()) {
  703. showmessage(L('vms_sn_skey_error'),'?m=video&c=video&a=open');
  704. }
  705. showmessage(L('operation_success'),'?m=video&c=video&a=open');
  706. }
  707. public function open_setting() {
  708. if(isset($_POST['dosubmit'])) {
  709. $setting = array2string($_POST['setting']);
  710. setcache('video', $_POST['setting']);
  711. $this->ku6api->ku6api_skey = $_POST['setting']['skey'];
  712. $this->ku6api->ku6api_sn = $_POST['setting']['sn'];
  713. $this->module_db->update(array('setting'=>$setting),array('module'=>'video'));
  714. if(!$this->ku6api->testapi()) {
  715. showmessage(L('vms_sn_skey_error'),HTTP_REFERER);
  716. }
  717. showmessage(L('operation_success'),HTTP_REFERER);
  718. } else {
  719. $show_pc_hash = '';
  720. $v_model_categorys = $this->ku6api->get_categorys(true, $this->setting['catid']);
  721. $category_list = '<select name="setting[catid]" id="catid"><option value="0">'.L('please_choose_catid').'</option>'.$v_model_categorys.'</select>';
  722. include $this->admin_tpl('video_opensetting');
  723. }
  724. }
  725. //获取userid下的视频
  726. public function ajax_getuseridvideo(){
  727. $userid = intval($_GET['userid']);
  728. if (!$userid) exit(0);
  729. $url = "http://v.ku6.com/video.htm?t=list&uid=" . $userid . "&p=1";
  730. $data = @file_get_contents($url);
  731. $data = json_decode($data, 1);
  732. $list = $data['data'];
  733. if (is_array($list)) {
  734. $sub['userid'] = $userid;
  735. $result = $this->ku6api->checkusersubscribe($sub);
  736. $status = $result['status'];
  737. exit($status);
  738. }
  739. exit('0');
  740. }
  741. /**
  742. * 订阅用户视频
  743. */
  744. public function subscribe_uservideo() {
  745. if (is_array($_GET['sub']) && !empty($_GET['sub'])) {
  746. $sub = $_GET['sub'];
  747. if (!$sub['userid'] || !$sub['catid']) showmessage(L('please_choose_catid_and_channel'));
  748. $sub['catid'] = intval($sub['catid']);
  749. $sub['posid'] = intval($sub['posid']);
  750. $result = $this->ku6api->usersubscribe($sub);
  751. if ($result['check'] == 6) showmessage(L('subscribe_for_default'));
  752. if ($result['code'] == 200) showmessage(L('operation_success'), 'index.php?m=video&c=video&a=subscribe_list&type=2');
  753. else showmessage(L('subscribe_set_failed'), 'index.php?m=video&c=video&a=subscribe_list&meunid='.$_GET['meunid']);
  754. } else {
  755. showmessage(L('please_choose_catid_and_iputuserid'), 'index.php?m=video&c=video&a=subscribe_list&meunid='.$_GET['meunid'].'&type=2');
  756. }
  757. }
  758. }
  759. ?>