hpr_hub/www/rss.php

311 lines
10 KiB
PHP

<?php
// TODO
// lisence
// filter by date
// if rss.php then use switches
// host out of eps
// explicit from db
$atomurl=$_SERVER['PHP_SELF'];
#${atomurl}?" . $_SERVER['QUERY_STRING']. "\" rel=\"
$feed = "tenday";
$mimetype = "audio/mpeg";
$format = "mp3";
$limit = 10;
switch ($atomurl) {
case "/hpr_rss.php":
$format = "mp3";
$mimetype = "audio/mpeg";
$feed = "tenday";
break;
case "/hpr_rss_mp3.php":
$format = "mp3";
$mimetype = "audio/mpeg";
$feed = "tenday";
break;
case "/hpr_mp3_rss.php":
$format = "mp3";
$mimetype = "audio/mpeg";
$feed = "tenday";
break;
case "/hpr_total_rss.php":
$format = "mp3";
$mimetype = "audio/mpeg";
$feed = "total";
break;
case "/hpr_ogg_rss.php":
$format = "ogg";
$mimetype = "audio/ogg";
$feed = "tenday";
break;
case "/hpr_total_ogg_rss.php":
$format = "ogg";
$mimetype = "audio/ogg";
$feed = "total";
break;
case "/hpr_spx_rss.php":
$format = "spx";
$mimetype = "audio/ogg";
$feed = "tenday";
break;
case "/hpr_total_spx_rss.php":
$format = "spx";
$mimetype = "audio/ogg";
$feed = "total";
break;
case "/rss.php":
$format = "mp3";
$mimetype = "audio/mpeg";
$feed = "tenday";
break;
case "/rss1.php":
$format = "spx";
$mimetype = "audio/ogg";
$feed = "tenday";
break;
}
require "/home/hpr/php/include.php";
$query = "SELECT hosts.host, eps.id, eps.series, eps.title, eps.notes, eps.date, hosts.email, eps.hostid, eps.explicit, eps.version, eps.valid, eps.duration, assets.size
FROM eps, hosts, assets
WHERE eps.valid=1
AND eps.hostid = hosts.hostid
AND eps.id = assets.episode_id
AND eps.duration > 0";
if (isset($_GET['format'])) {
$this_format = $_GET['format'];
if ( $this_format === "mp3" ) {
$format = "mp3";
$mimetype = "audio/mpeg";
}
if ( $this_format === "ogg" ) {
$format = "ogg";
$mimetype = "audio/ogg";
}
if ( $this_format === "spx" ) {
$format = "spx";
$mimetype = "audio/ogg";
}
}
$query = "${query}\nAND assets.filename REGEXP \"^hpr[0-9]+.$format\"";
$query = "${query}\nAND assets.extension = '$format'";
$explicit = 1;
if (isset($_GET['explicit'])) {
$explicit = $_GET['explicit'];
if ( $explicit === "0" ) {
$query = "${query}\nAND eps.explicit=0 ";
}
}
$html = 1;
if (isset($_GET['html'])) {
$html = $_GET['html'];
if ( $html === "0" ) {
$html = 0;
}
}
$full = "0";
if (isset($_GET['full'])) {
$full = $_GET['full'];
if ( $full === "1" ) {
$feed = "total";
}
if ( $full === "0" ) {
$feed = "tenday";
}
}
$gomax = "0";
if (isset($_GET['gomax'])) {
$gomax = $_GET['gomax'];
if ( $gomax === "1" ) {
$gomax = "1";
}
}
if ( $gomax === "0" ) {
$query = "${query}\nAND eps.date <= UTC_DATE() ";
}
if (isset($_GET['hostid'])) {
$hostid = $_GET['hostid'];
$hostid = intval($hostid);
if (is_int(intval($hostid))) {
$query = "${query}\nAND hosts.hostid = '$hostid'";
}
}
if (isset($_GET['series'])) {
$series = $_GET['series'];
$series = intval($series);
if (is_int(intval($series))) {
$query = "${query}\nAND eps.series = '$series'";
}
}
$query = "$query\nORDER BY id DESC";
if (isset($_GET['limit'])) {
$this_limit = $_GET['limit'];
$this_limit = intval($this_limit);
if (is_int(intval($this_limit))) {
$limit = $this_limit;
}
}
if ( $feed !== "total" ) {
$query = "$query\nLIMIT $limit";
}
header("Content-type: application/xml");
header("Pragma: public");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
date_default_timezone_set('UTC');
print '<?xml version="1.0" encoding="UTF-8" ?>' . "\n";
?>
<rss version="2.0" xmlns:googleplay="http://www.google.com/schemas/play-podcasts/1.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" >
<channel>
<title>Hacker Public Radio</title>
<link>https://hackerpublicradio.org/about.html</link>
<itunes:subtitle>A daily show hosted the community on topics that are of interest to hackers and hobbyists.</itunes:subtitle>
<description>Hacker Public Radio is an podcast that releases shows every weekday Monday through Friday. Our shows are produced by the community (you) and can be on any topic that are of interest to hackers and hobbyists.</description>
<language>en-us</language>
<itunes:category text="Technology">
<itunes:category text="Tech News"/>
</itunes:category>
<itunes:category text="Education">
<itunes:category text="Training"/>
</itunes:category>
<itunes:image href="http://hackerpublicradio.org/images/hpr_feed_itunes.png"/>
<itunes:explicit>yes</itunes:explicit>
<itunes:author>Hacker Public Radio</itunes:author>
<itunes:keywords>Community Radio, Tech Interviews, Linux, Open, Hobby, Software Freedom</itunes:keywords>
<copyright>Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) License</copyright>
<managingEditor>feedback@NOSPAM-hackerpublicradio.org (HPR Feedback)</managingEditor>
<!-- <author>feedback@NOSPAM-hackerpublicradio.org (HPR Feedback)</author> -->
<itunes:owner>
<itunes:name>HPR Volunteer</itunes:name>
<itunes:email>admin@hackerpublicradio.org</itunes:email>
</itunes:owner>
<webMaster>admin@hackerpublicradio.org (HPR Volunteer)</webMaster>
<generator>kate</generator>
<docs>http://www.rssboard.org/rss-specification</docs>
<ttl>720</ttl>
<skipDays>
<day>Saturday</day>
<day>Sunday</day>
</skipDays>
<image>
<url>https://hackerpublicradio.org/images/hpr_feed_small.png</url>
<title>Hacker Public Radio</title>
<link>https://hackerpublicradio.org/about.html</link>
<description>The Hacker Public Radio Old Microphone Logo</description>
<height>164</height>
<width>144</width>
</image>
<googleplay:author>HPR Volunteer</googleplay:author>
<googleplay:description>Hacker Public Radio is an podcast that releases shows every weekday Monday through Friday. Our shows are produced by the community (you) and can be on any topic that are of interest to hackers and hobbyists.</googleplay:description>
<googleplay:email>admin@hackerpublicradio.org</googleplay:email>
<googleplay:image href="http://hackerpublicradio.org/images/hpr_feed_itunes.png"/>
<googleplay:category text="Technology"/>
<?php
print " <atom:link href=\"http://hackerpublicradio.org". str_replace('&', '&amp;', $_SERVER["REQUEST_URI"]) ."\" rel=\"self\" type=\"application/rss+xml\" />\n";
print " <pubDate>".date(DATE_RFC1123, strtotime(date('Y-m-d')))."</pubDate>\n";
if ($result = mysqli_query($connection, $query)) {
$ep_count = 0;
while ($row = mysqli_fetch_array($result)) {
$id = fixid(stripslashes($row['id']));
$version = $row['version'];
if ( $version === "0" ) {
$version = "";
}
else {
$version = ".${version}";
}
$episode_explicit = $row['explicit'];
if ($episode_explicit == 0) {
$episode_explicit = "Clean";
}
else{
$episode_explicit = "Explicit";
}
$url="http://hackerpublicradio.org/eps/hpr${id}${version}";
if (isset($_GET['hostidinfilename'])) {
$hostidinfilename = $_GET['hostidinfilename'];
if ( $hostidinfilename === "1" ) {
$url = $url . "_host-" . htmlspecialchars(stripslashes(strip_tags($row["hostid"])));
}
}
if ( isset($_GET['seriesidinfilename']) ) {
$seriesidinfilename = $_GET['seriesidinfilename'];
if ( $seriesidinfilename === "1" ) {
$url = $url . "_series-" . htmlspecialchars(stripslashes(strip_tags($row["series"])));
}
}
$url = $url . "." . $format;
$itunes_summary = htmlspecialchars(stripslashes(strip_tags(substr($row["notes"],0,4000))));
if ( $html == 1 ) {
# $show_notes = "<p>This show has been flagged as $episode_explicit by the host.</p>\n" . $row["notes"];
$show_notes = $row["notes"];
$warning = "<p>This show has been flagged as $episode_explicit by the host.</p>\n";
}
else {
# $show_notes = "This show has been flagged as $episode_explicit by the host.\n" . htmlspecialchars(stripslashes(strip_tags($row["notes"]))) ;
$show_notes = htmlspecialchars(stripslashes(strip_tags($row["notes"]))) ;
$warning = "This show has been flagged as $episode_explicit by the host.\n";
}
# $show_notes = utf8_encode ( $show_notes );
$warning = utf8_encode ( $warning );
echo " <item>\n";
if ( $episode_explicit === "Clean" ) {
echo " <itunes:explicit>no</itunes:explicit>\n";
echo " <googleplay:explicit>No</googleplay:explicit>\n";
}
else {
echo " <itunes:explicit>yes</itunes:explicit>\n";
echo " <googleplay:explicit>Yes</googleplay:explicit>\n";
}
echo " <title>HPR$id: " . htmlspecialchars(stripslashes(strip_tags($row["title"]))) . "</title>\n";
// echo "<description> " . ($row["title"]) . "</description>\n";
$email_padded = formatemail($row['email']);
echo " <author>". $email_padded . " (" . htmlspecialchars(stripslashes(strip_tags($row["host"]))) .")</author>\n";
echo " <googleplay:author>". $email_padded . " (" . htmlspecialchars(stripslashes(strip_tags($row["host"]))) .")</googleplay:author>\n";
echo " <itunes:author>". $email_padded . " (" . htmlspecialchars(stripslashes(strip_tags($row["host"]))) .")</itunes:author>\n";
echo " <googleplay:image href=\"http://hackerpublicradio.org/images/hpr_feed_itunes.png\"/>\n";
echo " <link>https://hackerpublicradio.org/eps/hpr".$id."/index.html</link>\n";
if ( $feed === "total" && $ep_count >= 10) {
echo " <description></description>\n";
}
else {
echo " <description><![CDATA[" . $show_notes . "]]>\n</description>\n";
}
// echo " <googleplay:description><![CDATA[" . $show_notes . "]]>\n</googleplay:description>\n";
echo " <itunes:summary><![CDATA[" . $itunes_summary . "]]>\n</itunes:summary>\n";
echo " <pubDate>" .date(DATE_RFC1123, strtotime($row['date'])) . "</pubDate>\n";
$length = $row['size'];
echo " <enclosure url=\"$url\" length=\"$length\" type=\"$mimetype\"/>\n";
echo " <guid>" . $url . "</guid>\n";
echo " </item>\n";
$ep_count ++;
}
}
//Display non-connection errors
//Close sql connection
mysqli_close($connection);
echo " </channel>
</rss>
";
?>