video_for_ck.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. <?php
  2. defined('IN_PHPCMS') or exit('No permission resources.');
  3. $session_storage = 'session_'.pc_base::load_config('system','session_storage');
  4. pc_base::load_sys_class($session_storage);
  5. pc_base::load_sys_func('iconv');
  6. /**
  7. *
  8. * ------------------------------------------
  9. * video_for_ck
  10. * ------------------------------------------
  11. * @package PHPCMS V9.1.16
  12. * @author 王参加
  13. * @copyright CopyRight (c) 2006-2012 上海盛大网络发展有限公司
  14. *
  15. */
  16. class video_for_ck {
  17. public $db;
  18. public function __construct() {
  19. $this->db = pc_base::load_model('video_store_model');
  20. pc_base::load_app_class('ku6api', 'video', 0);
  21. $this->userid = param::get_cookie('_userid');
  22. pc_base::load_app_class('v', 'video', 0);
  23. $this->v = new v($this->db);
  24. $this->setting = getcache('video', 'video');
  25. $this->ku6api = new ku6api($this->setting['sn'], $this->setting['skey']);
  26. }
  27. /**
  28. *
  29. * 视频列表
  30. */
  31. public function init() {
  32. if (!$this->check_priv('video2content')) {
  33. showmessage('您没有权限操作该项','blank');
  34. }
  35. $where = '`status`=21';
  36. $page = max(intval($_GET['page']), 1);
  37. $pagesize = 6;
  38. if (!param::get_cookie('admin_username')) {
  39. $where .= " AND `userid`='".$this->userid."'";
  40. }
  41. $infos = $this->db->listinfo($where, 'videoid DESC', $page, $pagesize);
  42. $number = $this->db->number;
  43. $pages = $this->pages($number, $page, $pagesize, 4, 'get_videoes');
  44. $flash_info = $this->ku6api->flashuploadparam();
  45. include template('content','video_for_ck');
  46. }
  47. public function search() {
  48. $title = safe_replace($_GET['title']);
  49. if (CHARSET=='gbk') {
  50. $title = utf8_to_gbk($title);
  51. }
  52. $where = '`status`=21';
  53. if ($title) {
  54. $where .= ' AND `title` LIKE \'%'.$title.'%\'';
  55. }
  56. $userupload = intval($_GET['userupload']);
  57. if ($userupload) {
  58. $where .= ' AND `userupload`=1';
  59. }
  60. $page = $_GET['page'];
  61. $pagesize = 6;
  62. $infos = $this->db->listinfo($where, 'videoid DESC', $page, $pagesize);
  63. $number = $this->db->number;
  64. $pages = $this->pages($number, $page, $pagesize, 4, 'get_videoes');
  65. if (is_array($infos) && !empty($infos)) {
  66. $html = '';
  67. foreach ($infos as $info) {
  68. $html .= '<li><div class="w9"><a href="javascript:void(0);" onclick="a_click(this);" title="'.$info['title'].'" data-vid="'.$info['vid'].'" ><span></span><img src="'.$info['picpath'].'" width="90" height="51" /></a><p>'.str_cut($info['title'], 18).'</p></div></li>';
  69. }
  70. }
  71. $data['pages'] = $pages;
  72. $data['html'] = $html;
  73. if (CHARSET=='gbk') {
  74. $data = gbk_to_utf8($data);
  75. }
  76. exit(json_encode($data));
  77. }
  78. /**
  79. * Function add_f_ckeditor
  80. * ckeditor中添加视频
  81. */
  82. public function add_f_ckeditor () {
  83. //首先处理,提交过来的数据
  84. $data = array();
  85. $data['vid'] = $_GET['vid'];
  86. if (!$data['vid']) exit('1');
  87. $data['title'] = isset($_GET['title']) && trim($_GET['title']) ? addslashes(trim($_GET['title'])) : exit('2');
  88. $data['title'] = safe_replace($data['title']);
  89. $data['title'] = str_replace(array('select','from','concat'),'',$data['title']);
  90. $data['description'] = addslashes(trim($_GET['description']));
  91. $data['description'] = safe_replace(str_replace(array('select','from','concat'),'',$data['description']));
  92. $data['keywords'] = addslashes(trim(strip_tags($_GET['keywords'])));
  93. $data['keywords'] = safe_replace(str_replace(array('select','from','concat'),'',$data['keywords']));
  94. //其次向vms post数据,并取得返回值
  95. $get_data = $this->ku6api->vms_add($data);
  96. if (!$get_data) {
  97. exit('3');
  98. }
  99. $data['vid'] = $get_data['vid'];
  100. $data['addtime'] = SYS_TIME;
  101. if (strtolower(CHARSET)=='gbk') {
  102. $data = array_utf8_to_gbk($data);
  103. }
  104. $data['userupload'] = intval($_GET['userupload']);
  105. $videoid = $this->v->add($data);
  106. $vid_url = $data['vid'];
  107. exit($vid_url);
  108. }
  109. /**
  110. * Funtion pages
  111. * 视频分页
  112. * @param int $number 总页数
  113. * @param int $page 当前页
  114. * @param int $pagesize 每页数量
  115. * @param string $js JS属性
  116. */
  117. private function pages($num, $curr_page, $perpage = 20, $setpages = 5, $js = '') {
  118. $urlrule = url_par('page={$page}');
  119. $multipage = '';
  120. if($num > $perpage) {
  121. $page = $setpages+1;
  122. $offset = ceil($setpages/2-1);
  123. $pages = ceil($num / $perpage);
  124. if (defined('IN_ADMIN') && !defined('PAGES')) define('PAGES', $pages);
  125. $from = $curr_page - $offset;
  126. $to = $curr_page + $offset;
  127. $more = 0;
  128. if($page >= $pages) {
  129. $from = 2;
  130. $to = $pages-1;
  131. } else {
  132. if($from <= 1) {
  133. $to = $page-1;
  134. $from = 2;
  135. } elseif($to >= $pages) {
  136. $from = $pages-($page-2);
  137. $to = $pages-1;
  138. }
  139. $more = 1;
  140. }
  141. $multipage .= '<a class="a1">'.$num.L('page_item').'</a>';
  142. if($curr_page>0) {
  143. $multipage .= ' <a href="javascript:void(0);" onclick="'.$js.'('.intval($curr_page-1).')" class="a1">'.L('previous').'</a>';
  144. if($curr_page==1) {
  145. $multipage .= ' <span>1</span>';
  146. } elseif($curr_page>3 && $more) {
  147. $multipage .= ' <a href="javascript:void(0);" onclick="'.$js.'(1)">1</a>..';
  148. } else {
  149. $multipage .= ' <a href="javascript:void(0);" onclick="'.$js.'(1)">1</a>';
  150. }
  151. }
  152. for($i = $from; $i <= $to; $i++) {
  153. if($i != $curr_page) {
  154. $multipage .= ' <a href="javascript:void(0);" onclick="'.$js.'('.$i.')">'.$i.'</a>';
  155. } else {
  156. $multipage .= ' <span>'.$i.'</span>';
  157. }
  158. }
  159. if($curr_page<$pages) {
  160. if($curr_page<$pages-2 && $more) {
  161. $multipage .= ' ..<a href="javascript:void(0);" onclick="'.$js.'('.$pages.')">'.$pages.'</a> <a href="javascript:void(0);" onclick="'.$js.'('.intval($curr_page+1).')" class="a1">'.L('next').'</a>';
  162. } else {
  163. $multipage .= ' <a href="javascript:void(0);" onclick="'.$js.'('.$pages.')">'.$pages.'</a> <a href="javascript:void(0);" onclick="'.$js.'('.intval($curr_page+1).')" class="a1">'.L('next').'</a>';
  164. }
  165. } elseif($curr_page==$pages) {
  166. $multipage .= ' <span>'.$pages.'</span> <a href="javascript:void(0);" onclick="'.$js.'('.$curr_page.')" class="a1">'.L('next').'</a>';
  167. } else {
  168. $multipage .= ' <a href="javascript:void(0);" onclick="'.$js.'('.$pages.')">'.$pages.'</a> <a href="javascript:void(0);" onclick="'.$js.'('.intval($curr_page+1).')" class="a1">'.L('next').'</a>';
  169. }
  170. }
  171. return $multipage;
  172. }
  173. /**
  174. * Function CHECK_VID
  175. * 检查vid是否可用
  176. */
  177. public function check_vid() {
  178. $vid = $_GET['vid'];
  179. $r = $this->db->get_one(array('vid'=>$vid));
  180. if (is_array($r)) {
  181. $data = player_code('video_player',$r['channelid'],$r['vid'],300,225);
  182. exit($data);
  183. } else {
  184. exit(1);
  185. }
  186. $url = pc_base::load_config('ku6server', 'player_url').$vid.'/style/'.$this->setting['style_projectid'].'/';
  187. $data = @file_get_contents($url);
  188. if ($data = json_decode($data,true)) {
  189. if ($data['code']<0) {
  190. exit($data['msg']);
  191. } else {
  192. exit('1');
  193. }
  194. } else {
  195. exit('1');
  196. }
  197. }
  198. /**
  199. * Function CHECK_priv
  200. * 检查权限
  201. */
  202. private function check_priv($action = '') {
  203. if (!$action) $action = 'init';
  204. if (isset($_SESSION['roleid']) && !$_SESSION['roleid'] && $_SESSION['roleid']!=1) {
  205. $siteid = get_siteid();
  206. $admin_role_priv_db = pc_base::load_model('admin_role_priv_model');
  207. $r = $admin_role_priv_db->get_one(array('m'=>'video','c'=>'video','a'=>$action,'roleid'=>$_SESSION['roleid'],'siteid'=>$siteid));
  208. if ($r) return true;
  209. else return false;
  210. } else {
  211. return true;
  212. }
  213. }
  214. }
  215. ?>