马上注册,免费下载更多dz插件网资源。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
移植ZBLOG弹幕视频播放器整合到帝国CMS。之前是哪个网友有给我分享这个ZBLOG插件。其实我一看我察。居然也是面向过程写的代码。这不是太简单了。首先弹幕写入与读取与举报。- session_start();if ($_SERVER['REQUEST_METHOD'] === 'POST') { if($user['zt']=="nologin"){ $responseData = array( 'code' => -3, 'danmuku' =>"您还没有登陆" ); echo json_encode($responseData); exit; } if (isset($_SESSION['last_submit_time'])) { $lastSubmitTime = $_SESSION['last_submit_time']; $currentTime = time(); $timeDifference = $currentTime - $lastSubmitTime; if ($timeDifference <15) { $responseData = array( 'code' => -5, 'danmuku' =>"您休息下吧" ); echo json_encode($responseData); exit; } } $_SESSION['last_submit_time'] = time(); $post_data = json_decode(file_get_contents('php://input'), true); $author =$username?$username:RepPostVar($post_data['author']); $color =RepPostVar($post_data['color']); $danmuid =RepPostVar($post_data['player']); $size =RepPostVar($post_data['size']); $text =RepPostVar($post_data['text']); $videotime =RepPostVar($post_data['time']); $type =RepPostVar($post_data['type']); $sql=$empire->query("insert into {$dbtbpre}danmaku_list(danmuid,type,username,userid,text,color,size,videotime,ip,time) values('$danmuid','$type','$author','$userid','$text','$color','$size','$videotime','$ip','$time');"); echo json_encode(array('code' =>23,'danmuku' =>"发布成功")); exit; } if ($_SERVER['REQUEST_METHOD'] === 'GET') { if ($enews === 'dm') { $danmuid = RepPostVar($_GET['id']); $total=fetch_memcache0("select count(*) as total from {$dbtbpre}danmaku_list where danmuid='$danmuid'",'Memcached','danmulistall',60); $danmunum=$total[0]['total']; $value=fetch_memcache0("select id,danmuid,type,username,userid,text,color,size,videotime,ip,time from {$dbtbpre}danmaku_list where danmuid='$danmuid' order by id desc limit 550",'Memcached','danmu',60); foreach ($value as $k => $v){ $data[]=array( '0'=>(float)$v['videotime'], '1'=>$v['type'], '2'=>$v['color'], '3'=>$v['id'], '4'=>$v['text'], '5'=>$v['ip'], '6'=>date('m-d H:i', $v['time']), '7'=>$v['size'], '8'=>$v['username'], ); } $responseData = array( 'code' => 23, 'danmuku' => $data, 'danum' =>$danmunum, 'name' =>$danmuid, ); echo json_encode($responseData); exit; }elseif ($enews === 'report') { // 弹幕举报 $text = RepPostVar($_GET['text']); $cid = $_GET['cid']; $type = RepPostVar($_GET['type']); $danmuid = RepPostVar($_GET['title']); $userip = $ip?$ip:RepPostVar($_GET['user']); $sql=$empire->query("insert into {$dbtbpre}danmaku_report(danmuid,username,userid,text,type,time,ip) values('$danmuid','$username','$userid','$text','$type','$time','$userip');"); $responseData = array( 'code' => -3, 'danmuku' => '举报成功!感谢您为守护弹幕作出了贡献', ); echo json_encode($responseData); exit; } else { echo json_encode(['code' => 0, 'danmuku' => 'Unknown action.']); exit; } }
复制代码 看了下,还是不够完美在增加多少人观看呢?- include('config.php'); // 引入弹幕播放器参数 $userid = (int)getcvar('mluserid'); // 用户ID $username = RepPostVar(getcvar('mlusername')); // 用户名 $username = $username ? $username : "游客"; $current_ip = egetip(); //获取IP地址$online_log = ECMS_PATH.'e/m/yzplayer/count.dat'; // 保存人数的文件 $timeout = (int)$yzm['online']; // 默认30秒内没动作者,认为掉线 后台可以设置$users_online = array(); $users_online = array(); if (($fp = fopen($online_log, "r")) !== false) { flock($fp, LOCK_SH); while (($line = fgets($fp)) !== false) { $line = trim($line); if (!empty($line)) { $entry = explode(",", $line); if (count($entry) == 4) { list($ip, $userid_stored, $username_stored, $timestamp) = $entry; $timestamp = (int)$timestamp; if ($timestamp > time() - $timeout) { $users_online[$ip] = array( 'userid' => (int)$userid_stored, 'username' => $username_stored, 'timestamp' => $timestamp ); } } } } flock($fp, LOCK_UN); fclose($fp); } if (!isset($users_online[$current_ip]) || $users_online[$current_ip]['timestamp'] < time() - $timeout) { $users_online[$current_ip] = array( 'userid' => $userid, 'username' => $username, 'timestamp' => time() ); } else { $users_online[$current_ip]['timestamp'] = time(); } $users_online_data = ''; foreach ($users_online as $ip => $user) { $users_online_data .= "{$ip},{$user['userid']},{$user['username']},{$user['timestamp']}\n"; } if (($fp = fopen($online_log, "w")) !== false) { flock($fp, LOCK_EX);fwrite($fp, $users_online_data); flock($fp, LOCK_UN); fclose($fp); } else { echo "无法写入: " . $online_log; }
复制代码 某些骚年还是觉得少了像bilibili弹幕获取啊。其实这个更简单,因为只需要curl不存在什么逻辑问题- $cid = isset($_GET['cid']) ? $_GET['cid'] : null;$av = isset($_GET['av']) ? $_GET['av'] : 0;$p = isset($_GET['p']) ? $_GET['p'] : 1;preg_match("/^[0-9]+$/", $av) ?: $av = 0;preg_match("/^[0-9]+$/", $p) ?: $p = 1;preg_match("/^[0-9]+$/", $cid) ?: $cid = 0;if ($cid > 0 or ($cid > 0 and $av > 0)) { $xml = curl_get('https://api.bilibili.com/x/v1/dm/list.so?oid=' . $cid); echo xml_json($xml);} elseif ($av > 0 and $cid <= 0) { $cid = get_cid($av, $p); $xml = curl_get('https://api.bilibili.com/x/v1/dm/list.so?oid=' . $cid); echo xml_json($xml);} else { echo '{"code":1,"mes":"参数错误"}';}function curl_get($url, $gzip = 1){ $curl = curl_init($url); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 10); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); if ($gzip) curl_setopt($curl, CURLOPT_ENCODING, "gzip"); $content = curl_exec($curl); curl_close($curl); return $content;}function hex2rgb($hexColor){ $color = str_replace('#', '', $hexColor); if (strlen($color) > 3) { $r = hexdec(substr($color, 0, 2)); $g = hexdec(substr($color, 2, 2)); $b = hexdec(substr($color, 4, 2)); $rgb = 'rgb(' . $r . ',' . $g . ',' . $b . ')'; } else { $color = $hexColor; $r = substr($color, 0, 1) . substr($color, 0, 1); $g = substr($color, 1, 1) . substr($color, 1, 1); $b = substr($color, 2, 1) . substr($color, 2, 1); $rgb = array( 'r' => hexdec($r), 'g' => hexdec($g), 'b' => hexdec($b) ); } return $rgb;}function xml_json($xml){ $xml = simplexml_load_string($xml); //将文件转换成 对象 $xmljson = json_encode($xml); $danmuku = json_decode($xmljson, true); foreach ($danmuku['d'] as $k => $v) { foreach ($xml->d[$k]->attributes() as $_v) { $danmuku['d'][$k] = [$v]; $danmuku['d'][$k][] = explode(",", (string) $_v); } } $danmuku = $danmuku['d']; $json = ['code' => 23]; foreach ($danmuku as $k => $v) { $json['danmuku'][$k][] = (float) $v[1][0]; //弹幕出现时间(s) if ($v[1][1] <= 3) { //滚动 $json['danmuku'][$k][] = 'right'; } if ($v[1][1] == 5) { //顶端 $json['danmuku'][$k][] = 'top'; } if ($v[1][1] == 4) { //底端 $json['danmuku'][$k][] = 'bottom'; } $json['danmuku'][$k][] = hex2rgb($v[1][6]); //字体的颜色 $json['danmuku'][$k][] = ""; //bilibili 弹幕发送者的ID $json['danmuku'][$k][] = $v[0]; //弹幕文本 } return json_encode($json);}function get_cid($av, $p){ $data = json_decode(curl_get('https://api.bilibili.com/x/player/pagelist?aid=' . $av), true); if (empty($data['data'][$p - 1]['cid'])) { die('{"code":1,"mes":"参数错误"}'); } return $data['data'][$p - 1]['cid'];}
复制代码
总结,面向过程的写法更容易理解逻辑。对于小白相对比所有的函数封装到一个类更容易移植。
©DZ插件网所发布的一切资源仅限用于学习和研究目的;不得将上述内容用于商业或者非法用途,否则,一切后果请用户自负。 网站部分内容来源于网络,版权争议与本站无关。您必须在下载后的24个小时之内,从您的电脑中彻底删除上述内容。如果您喜欢该程序,请支持正版软件,得到更好的正版服务。 您在本站任何的赞助购买、下载、查阅、回复等行为等均表示接受并同意签订《DZ插件网免责声明协议》。 如有侵权请邮件与我们联系处理: discuzaddons@vip.qq.com 并出示相关证明以便删除。敬请谅解!
|