2023-07-02 16:47:44 +02:00
<? php
require "/home/hpr/php/include.php" ;
2025-01-14 20:22:36 +01:00
date_default_timezone_set ( 'UTC' );
2023-07-02 16:47:44 +02:00
if ( isset ( $_GET [ 'id' ])) {
$id = $_GET [ 'id' ];
$result = mysqli_query ( $connection , 'SELECT MAX(id) FROM eps;' );
if ( ! isset ( $result )) {
2025-01-14 20:22:36 +01:00
problem ( "45f606ad99fe4fca7430b7b5bba1c681" );
die ( 'Could not query:' . mysqli_error ());
2023-07-02 16:47:44 +02:00
}
$maxhost_array = mysqli_fetch_row ( $result );
$maxhost = $maxhost_array [ 0 ];
$num_get_args = 0 ;
foreach ( $_GET as $k => $v ) {
++ $num_get_args ;
}
if ( ( strval ( intval ( $id )) != strval ( $id )) OR ( intval ( $id ) <= 0 ) OR ( intval ( $id ) > $maxhost ) OR ( $num_get_args > 1 ) ){
2025-01-14 20:22:36 +01:00
problem ( "ea860134910fecd136229e45262709d7" );
exit ;
2023-07-02 16:47:44 +02:00
}
$query = "SELECT id FROM eps WHERE id = ' $id '" ;
$result = @ mysqli_query ( $connection , $query );
if ( $result === FALSE ) {
2025-01-14 20:22:36 +01:00
problem ( "dc5b8dae7ea2a7e70ac0b7ea65ce2d12" );
2023-07-02 16:47:44 +02:00
}
else {
$db = mysqli_fetch_array ( $result , MYSQLI_ASSOC );
if ( empty ( $db [ "id" ]) ) {
2025-01-14 20:22:36 +01:00
problem ( "2b6462ff2389405a796066dfc73ccf55" );
2023-07-02 16:47:44 +02:00
}
}
}
else {
2025-01-14 20:22:36 +01:00
problem ( "ae1f3471af22d32d3bf2efc9130a00ae" );
2023-07-02 16:47:44 +02:00
exit ;
}
2023-12-28 20:00:28 +01:00
$ep_retrieve = "SELECT
UNIX_TIMESTAMP(eps.date) AS timestamp,
eps.title,
eps.duration,
eps.summary,
hosts.host,
eps.hostid,
eps.series,
eps.license,
licenses.long_name,
eps.explicit
FROM
eps
LEFT JOIN hosts ON eps.hostid = hosts.hostid
LEFT JOIN licenses ON licenses.short_name = eps.license
WHERE
hosts.valid = '1'
AND eps.id = ' $id '" ;
2023-07-02 16:47:44 +02:00
if ( $result = mysqli_query ( $connection , $ep_retrieve )) {
while ( $row = mysqli_fetch_array ( $result )) {
$date = $row [ 'timestamp' ];
$title = $row [ 'title' ];
$duration = $row [ 'duration' ];
$summary = $row [ 'summary' ];
$host = $row [ 'host' ];
$hostid = $row [ 'hostid' ];
$series = $row [ 'series' ];
$license = $row [ 'license' ];
2023-12-28 20:00:28 +01:00
$license_long_name = $row [ 'long_name' ];
2023-07-02 16:47:44 +02:00
$explicit = $row [ 'explicit' ];
$id = fixid ( $id );
$host_retrieve = "SELECT host, espeak_name FROM hosts WHERE hostid = ' $hostid '" ;
$result1 = mysqli_query ( $connection , $host_retrieve );
$row1 = mysqli_fetch_array ( $result1 );
$espeak_name = $row1 [ 'espeak_name' ];
$epcountquery = "SELECT count( id ) AS total FROM eps WHERE hostid = ' $hostid '" ;
$result2 = mysqli_query ( $connection , $epcountquery );
$row2 = mysqli_fetch_array ( $result2 );
$total = $row2 [ 'total' ];
if ( $total == 1 ) {
$host_notes = ". It is the first show by new host ${ espeak_name } , " ;
}
else if ( $total % 10 == 0 ) {
$host_notes = ". It is the ${ total } th show of ${ espeak_name } , " ;
}
else {
$host_notes = ". It is hosted by ${ espeak_name } , " ;
}
}
}
2025-01-14 20:22:36 +01:00
else {
http_response_code ( 404 );
die ();
}
$synopsis = "This is Hacker Public Radio episode $id for " . date ( "l" , $date ) . " the " . date ( "jS" , $date ) . " of " . date ( "F Y" , $date ) . ". Todays show is entitled. ${ title } ." ;
2023-07-02 16:47:44 +02:00
if ( $series > "0" ){
$series_query = mysqli_query ( $connection , "SELECT name, description FROM miniseries WHERE id = ' $series '" );
$series_result = mysqli_fetch_array ( $series_query );
$series_title = $series_result [ 'name' ];
$desc = $series_result [ 'description' ];
2025-01-14 20:22:36 +01:00
$synopsis = " ${ synopsis } It is part of the series \" $series_title\ "";
2023-07-02 16:47:44 +02:00
}
2025-01-14 20:22:36 +01:00
$synopsis = " $ { synopsis } $ { host_notes } and is about " . round( $duration /60) . " minutes long . It carries ";
2023-07-02 16:47:44 +02:00
if ( $explicit == 0) {
2025-01-14 20:22:36 +01:00
$synopsis = " $ { synopsis } a clean flag . ";
2023-07-02 16:47:44 +02:00
$explicit = " Clean ";
}
else{
2025-01-14 20:22:36 +01:00
$synopsis = " $ { synopsis } an explicit flag . ";
2023-07-02 16:47:44 +02:00
$explicit = " Explicit ";
}
if ( !empty( $summary ) ) {
2025-01-14 20:22:36 +01:00
$synopsis = " $ { synopsis } . The summary is . $summary ";
2023-07-02 16:47:44 +02:00
}
if (strcmp( $license , " CC - BY - SA " ) !== 0) {
2025-01-14 20:22:36 +01:00
$synopsis = " $ { synopsis } . Todays show is licensed under a $license_long_name license . ";
2023-07-02 16:47:44 +02:00
}
2025-01-14 20:22:36 +01:00
$synopsis = str_replace( $host , $espeak_name , $synopsis );
// --------------------------------------------
// Display the results
$arr = array(
'genre' => " Podcast ",
'album' => " Hacker Public Radio ",
'track' => " $id ",
'year' => date(" Y ", $date ),
'date' => date(" Y - m - d ", $date ),
'artist' => " $ { host } ",
'hostid' => " $ { hostid } ",
'title' => " $ { title } ",
'duration' => " $ { duration } ",
'license' => " $ { license } ",
'explicit' => " $ { explicit } ",
'summary' => " $ { summary } ",
'comment' => " https :// hackerpublicradio . org $ { explicit }; $summary ",
'synopsis' => " $ { synopsis } "
);
header('Content-Type: application/json');
header(" Content - disposition : inline ; filename = hpr_stats . json ");
echo json_encode( $arr );
2023-07-02 16:47:44 +02:00
2025-01-14 20:22:36 +01:00
mysqli_close( $connection );