<?php
/*
Name: 直播源测试
Version: 2.0 token验证
Author: Brian
*/
require_once '../include/global.php';

$name = $_GET['name'];
$names = explode('|', $name); // 将$name按逗号分隔成数组
$live_token = $_GET["live_token"]; // 获取live_token

/*
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $name = $_POST["name"];
    $live_token = $_POST["live_token"];
} elseif ($_SERVER["REQUEST_METHOD"] == "GET") {
    $name = $_GET["name"];
    $live_token = $_GET["live_token"];
*/

// $name = "ch|abc|def"; // 多个分类名称，用逗号分隔

function chenk_live_token($live_token){
	$token = Db::table('user_logon')->where('token', $live_token)->find();
	if ($token && isset($token['token'])) {
	$token = $token['token'];
	} else {
		echo "No results found.";
	}

    if ($live_token == $token){
        return true;
    }else{
        return false;
    }
}

if (isset($name) && isset($live_token) && !empty($live_token) && !empty($name)){
	$chenk_token = chenk_live_token($live_token);
    if ($chenk_token){
		foreach ($names as $name) {
			// 获取指定分类名称
			$result = Db::table('app_lives')->where('name', $name)->find();

			// 检查是否有结果并获取 data 字段值
			if ($result && isset($result['data'])) {
				$data = explode(';', $result['data']); // 将数据按分号分隔成数组
				echo $name . ",#genre#" . PHP_EOL;
				
				// 逐行输出 data 的值
				foreach ($data as $line) {
					echo $line . PHP_EOL;
				}
			} else {
				echo "No results found for $name." . PHP_EOL;
			}
		}
	}else{
        die("没有权限。");
    }
}else{
    die("没有权限。");
}
?>
