我希望有人能提供帮助,我正在努力为本地广播电台使用的Wordpress主题添加一些功能。我的查询是关于显示当前的现场节目标题,我有一个写的PHP文件,当由标题更新表格处理时,用我当前的节目标题(从HTML表格中捕获)更新我的数据库中的表,但也捕获触发表单的用户ID,然后继续使用节目标题更新Shoutcast服务器。
这背后的想法是允许我在网站上显示与当前现场DJ相关的动态wordpress内容 - 这有效并且没有问题,但现在我想做的是创建一个页面来检查输出Shoutcast服务器标题与db中的表匹配,如果是,那么我希望它能回显这个输出,如果它不同,我希望它使用SC标题的输出。
我目前有两个单独的脚本,可以单独输出这些信息,这取决于哪个被触发但我需要将它们组合起来(使用if / else命令我假设?)这是我目前的尝试,但目前还没有似乎输出了db字段,只会从服务器输出SC标题;
<?php
require_once('../../wp-config.php'); // connection to WPdb
require_once('sc-config.php'); // connection to Shoutcast Server
$open = fsockopen($ip,$port);
fputs($open,"GET /7.html HTTP/1.1\nUser-Agent:Mozilla\n\n");
$read = fread($open,1000);
$text = explode(",",$read);
$text = $text[6];
$query = "SELECT title, userID FROM sc_options where id= '0'"; // grab current show title and user id of the DJ that updated title from db
$result = mysql_query($query);
while($row = mysql_fetch_row($result))
{
$onAir_Title = $row[0];
$onAir_IMG = $row[1];
if ($onAir_Title == $text)
{
// start output
echo "$onAir_Title";
echo get_avatar( $onAir_IMG, 96);
}
else
{
echo "$text";
}
}
?>
很抱歉,如果我犯了一个新手的错误,我正在努力学习 - 我会非常感谢任何建议!
谢谢
编辑 - 这些是原始形式的脚本,都按原样运行;
这个检查数据库并显示输出 -
<?php
require_once('../../wp-config.php'); // open connection to WP
$query = "SELECT title, userID FROM sc_options where id= '0'";
$result = mysql_query($query);
while($row = mysql_fetch_row($result))
{
$onAir_Title = $row[0];
$onAir_IMG = $row[1];
// output
echo "$onAir_Title";
echo get_avatar( $onAir_IMG, 96);
}
?>
这个显示来自shoutcast服务器的shoutcast标题
<div style="Visibility: Hidden; Position: Absolute;">
<?php
$open = fsockopen("198.154.106.116","6002");
if ($open) {
fputs($open,"GET /7.html HTTP/1.1\nUser-Agent:Mozilla\n\n");
$read = fread($open,1000);
$text = explode(",",$read);
$text = $text[6];
} else { $text="connection refused."; }
?>
</div>
<?php
echo "$text";
?>
答案 0 :(得分:0)
如果有人有兴趣,我设法完成这项工作,我已经重新编写了如何在SC服务器上检查标题并最终使其正常工作..
<?php
/* ----------- Server configuration ---------- */
require_once('sc-config.php'); // Shoutcast
require_once('../../wp-config.php'); // WPdb
/* ----- No need to edit below this line ----- */
/* ------------------------------------------- */
$fp = @fsockopen($ip,$port,$errno,$errstr,1); // Open connection to Shoutcast
if (!$fp)
{
echo "Connection refused"; // Displays when sever is offline
}
else
{
fputs($fp, "GET /7.html HTTP/1.0\r\nUser-Agent: Mozilla\r\n\r\n"); // Get Stream Title
while (!feof($fp))
{
$info = fgets($fp);
}
$info = str_replace('</body></html>', "", $info);
$split = explode(',', $info);
$query = "SELECT title, userID FROM sc_options where id = '1'"; // Grab last title update from db table row
$result = mysql_query($query);
while($row = mysql_fetch_row($result))
$onAir_Title = $row[0]; // Create db show title string
$onAir_IMG = $row[1]; // User ID of last show update
if ($onAir_Title == $split[6]) // Check table row matches live stream title
{
echo $onAir_Title;
echo get_avatar( $onAir_IMG, 96); // User ID
}
else // If it doesn't match output the title from the SC server
{
$title = str_replace('\'', '`', $split[6]);
$title = str_replace(',', ' ', $title);
echo "$title"; // Displays song
}
}
?>