2023-07-02 16:47:44 +02:00
< ? php
require " /home/hpr/php/include.php " ;
$pos = strpos ( $_SERVER [ 'REQUEST_URI' ], '?' );
if ( ! $pos === false ) {
header ( " Status: 412 Precondition Failed " );
include '412.shtml' ;
file_put_contents ( $naughtyfile , getUserIP (), FILE_APPEND | LOCK_EX );
exit ;
}
$body = " give " ;
//$body="index_full";
2025-09-30 22:57:42 -04:00
include 'header.php' ;
2023-07-02 16:47:44 +02:00
// --------------------------------------------
// Clean up stale reservations
$ip = $_SERVER [ " REMOTE_ADDR " ];
2026-04-05 16:37:09 +02:00
# Remove any stale REQUEST_UNVERIFIED requests.
2023-07-02 16:47:44 +02:00
# This should be enough to deter attackers while been short enough to allow real hosts to request a show.
2026-04-05 16:37:09 +02:00
$query_delete_old_REQUEST_UNVERIFIED = " DELETE
2023-07-02 16:47:44 +02:00
FROM
reservations
WHERE
reservations.timestamp + INTERVAL 1 HOUR <= UTC_TIMESTAMP()
AND reservations.status = 'REQUEST_UNVERIFIED' " ;
2026-04-05 16:37:09 +02:00
$result_delete_old_REQUEST_UNVERIFIED = @ mysqli_query ( $connection , $query_delete_old_REQUEST_UNVERIFIED );
if ( ! $result_delete_old_REQUEST_UNVERIFIED ) {
problem ( " ERROR: DB problem - The old REQUEST_UNVERIFIED records were not removed from the reservations db. " );
}
else {
logextra ( " mysql_query.result: \" $result\ " \n " );
}
logextra( " Removed REQUEST_UNVERIFIED requests older than 1 hour " . $result_delete_old_REQUEST_UNVERIFIED );
# Remove any stale REQUEST_EMAIL_SENT requests.
# This should be enough for someone to acutally upload a show
$query_delete_old_REQUEST_EMAIL_SENT = " DELETE
FROM
reservations
WHERE
reservations . timestamp + INTERVAL 3 HOUR <= UTC_TIMESTAMP ()
AND reservations . status = 'REQUEST_EMAIL_SENT' " ;
$result_delete_old_REQUEST_EMAIL_SENT = @mysqli_query( $connection , $query_delete_old_REQUEST_EMAIL_SENT );
if(! $result_delete_old_REQUEST_EMAIL_SENT ) {
problem( " ERROR : DB problem - The old REQUEST_EMAIL_SENT records were not removed from the reservations db . " );
}
else {
logextra( " mysql_query . result : \ " $result\ " \n " );
}
logextra( " Removed REQUEST_EMAIL_SENT requests older than 3 hours " . $result_delete_old_REQUEST_EMAIL_SENT );
2023-07-02 16:47:44 +02:00
# Remove stale requests from this IP Address after 15 minutes.
# This should be enough to deter attackers while been short enough to allow real hosts to request a show.
2026-04-05 16:37:09 +02:00
$query_delete = " DELETE
FROM
reservations
WHERE
reservations . ip = '$ip'
AND
reservations . timestamp + INTERVAL 15 MINUTE <= UTC_TIMESTAMP ()
AND
reservations . status = 'REQUEST_UNVERIFIED' " ;
2023-07-02 16:47:44 +02:00
$result_delete = @mysqli_query( $connection , $query_delete );
2026-04-05 16:37:09 +02:00
if(! $result_delete ) {
problem( " ERROR : DB problem - The old REQUEST_UNVERIFIED records were not removed from this \ " ${ ip } \" IP Address after 15 minutes. " );
}
else {
logextra ( " mysql_query.result: \" $result\ " \n " );
}
2023-07-02 16:47:44 +02:00
2026-04-05 16:37:09 +02:00
logextra( " Remove REQUEST_UNVERIFIED stale requests from this \ " ${ ip } \" IP Address after 15 minutes. " . $result_delete );
2023-07-02 16:47:44 +02:00
// --------------------------------------------
// Get first free slot
$query = mysqli_query ( $connection , "
SELECT id + 1 FROM eps mo
WHERE NOT EXISTS
(
SELECT NULL
FROM eps mi
WHERE mi.id = mo.id + 1
)
ORDER BY
id
LIMIT 1 " );
$next_show_num_array = mysqli_fetch_row ( $query );
$next_show_num = $next_show_num_array [ 0 ];
print " <!-- next_show_num is $next_show_num --> \n " ;
// --------------------------------------------
// Get latest published show
$query = mysqli_query ( $connection , " SELECT max(date), max(id) from eps WHERE eps.date <= UTC_DATE() " );
$current_episode_array = mysqli_fetch_row ( $query );
$current_episode_date = $current_episode_array [ 0 ];
$current_episode_number = $current_episode_array [ 1 ];
print " <!-- current_episode_date is $current_episode_date --> \n " ;
print " <!-- current_episode_number is $current_episode_number --> \n " ;
// --------------------------------------------
// Get highest scheduled or reserved show
$query = mysqli_query ( $connection , " SELECT MAX(id) FROM eps as maxid; " );
$max_episode_array = mysqli_fetch_row ( $query );
$max_episode_number = $max_episode_array [ 0 ];
print " <!-- max_episode_number is $max_episode_number --> \n " ;
2023-12-23 11:24:21 +01:00
// --------------------------------------------
2026-05-27 17:44:34 +02:00
// Get the number of shows in the Reserve Pool.
2023-12-23 11:24:21 +01:00
2026-06-01 21:50:13 +02:00
$query = mysqli_query ( $connection , " SELECT COUNT(*) as count_reserve_pool FROM reservations WHERE status = 'RESERVE_SHOW_SUBMITTED' AND ip = '127.0.0.1'; " );
2023-12-23 11:24:21 +01:00
$response_array = mysqli_fetch_row ( $query );
2026-06-01 21:50:13 +02:00
$count_reserve_pool = $response_array [ 0 ];
print " <!-- count_reserve_pool is $count_reserve_pool --> \n " ;
2023-12-23 11:24:21 +01:00
// --------------------------------------------
2026-05-27 17:44:34 +02:00
// Get the number of shows in the Reserve Pool yet to be processed.
2023-12-23 11:24:21 +01:00
2026-06-01 21:50:13 +02:00
$query = mysqli_query ( $connection , " SELECT COUNT(*) as count_reserve_pool_unprocessed FROM reservations WHERE status = 'RESERVE_SHOW_SUBMITTED' AND ip != '127.0.0.1'; " );
2023-12-23 11:24:21 +01:00
$response_array = mysqli_fetch_row ( $query );
2026-06-01 21:50:13 +02:00
$count_reserve_pool_unprocessed = $response_array [ 0 ];
print " <!-- count_reserve_pool_unprocessed is $count_reserve_pool_unprocessed --> \n " ;
2023-12-23 11:24:21 +01:00
2023-07-02 16:47:44 +02:00
// --------------------------------------------
// Populate array with future shows and reservations
$show_array = array ();
// REQUEST_UNVERIFIED → SHOW_SUBMITTED → METADATA_PROCESSED → SHOW_POSTED → MEDIA_TRANSCODED → UPLOADED_TO_IA → UPLOADED_TO_RSYNC_NET
$ep_retrieve = " SELECT hosts.host, eps.id, eps.title, eps.date FROM eps, hosts WHERE eps.valid=1 AND eps.hostid = hosts.hostid AND eps.date >= ' $current_episode_date ' ORDER BY date DESC " ;
$ep_retrieve = " SELECT
hosts.host,
eps.id,
eps.title,
eps.date,
COUNT( assets.extension) AS numfiles
FROM
eps
LEFT JOIN hosts ON eps.hostid = hosts.hostid
LEFT JOIN assets ON eps.id = assets.episode_id
WHERE
eps.valid = 1
AND eps.date >= ' $current_episode_date '
GROUP BY eps.id; " ;
if ( $result = mysqli_query ( $connection , $ep_retrieve )) {
while ( $row = mysqli_fetch_array ( $result )) {
$id = $row [ 'id' ];
$date = $row [ 'date' ];
$title = $row [ 'title' ];
$host = $row [ 'host' ];
$numfiles = $row [ 'numfiles' ];
if ( isset ( $numfiles ) and $numfiles >= 3 ) {
$status = " Finished " ;
}
else {
$status = " Reserved " ;
}
$show_array [ $id ] = array ( " date " => date ( 'Y-m-d' , strtotime ( $date ) ),
" title " => $title ,
" host " => $host ,
" status " => $status
);
}
}
// REQUEST_UNVERIFIED → SHOW_SUBMITTED → METADATA_PROCESSED → SHOW_POSTED → MEDIA_TRANSCODED → UPLOADED_TO_IA → UPLOADED_TO_RSYNC_NET
// Populate array with currently processing shows EMAIL_LINK_CLICKED
$ep_retrieve = "
SELECT
reservations.ep_num,
reservations.ep_date,
reservations.status
FROM
reservations
WHERE
reservations.verified = 1
AND reservations.ep_date >= ' $current_episode_date '
ORDER BY
reservations.ep_date DESC " ;
if ( $result = mysqli_query ( $connection , $ep_retrieve )) {
while ( $row = mysqli_fetch_array ( $result )) {
$id = $row [ 'ep_num' ];
$date = $row [ 'ep_date' ];
$status = $row [ 'status' ];
$show_array [ $id ] = array ( " date " => date ( 'Y-m-d' , strtotime ( $date ) ),
" title " => $status ,
" host " => " Unverified " ,
" status " => " Processing "
);
}
}
// Populate array with temporary reservations.
$ep_retrieve = " SELECT r.ep_num, r.ep_date, r.timestamp + INTERVAL 1 HOUR - UTC_TIMESTAMP() AS seconds_to_expiration FROM reservations r
WHERE r.timestamp + INTERVAL 1 HOUR > UTC_TIMESTAMP() AND r.verified =0 AND r.ep_date >= ' $current_episode_date ' ORDER BY r.ep_date DESC " ;
if ( $result = mysqli_query ( $connection , $ep_retrieve )) {
while ( $row = mysqli_fetch_array ( $result )) {
$id = $row [ 'ep_num' ];
$date = $row [ 'ep_date' ];
$seconds_to_expiration = $row [ 'seconds_to_expiration' ];
$minutes = floor ( $seconds_to_expiration / 60 ) + 1 ;
$show_array [ $id ] = array ( " date " => date ( 'Y-m-d' , strtotime ( $date ) ),
" title " => " Available again in $minutes minutes " ,
" host " => " Unverified " ,
" status " => " Locked "
);
}
}
2023-12-23 11:24:21 +01:00
$ep_retrieve = " SELECT
hosts.host,
eps.id,
eps.title,
eps.date
FROM
eps,
hosts,
assets
WHERE
eps.valid = 0
AND eps.hostid = hosts.hostid
AND eps.id = assets.episode_id
AND eps.date >= ' $current_episode_date '
ORDER BY
date DESC " ;
if ( $result = mysqli_query ( $connection , $ep_retrieve )) {
while ( $row = mysqli_fetch_array ( $result )) {
$id = $row [ 'id' ];
$date = $row [ 'date' ];
$title = $row [ 'title' ];
$host = $row [ 'host' ];
$show_array [ $id ] = array ( " date " => date ( 'Y-m-d' , strtotime ( $date ) ),
" title " => $title ,
" host " => $host ,
2025-05-21 10:21:55 +02:00
" status " => " Distributing media to the ccdn "
2023-12-23 11:24:21 +01:00
);
}
}
2023-07-02 16:47:44 +02:00
$ep_retrieve = " SELECT
hosts.host,
eps.id,
eps.title,
eps.date
FROM
eps,
hosts,
assets
WHERE
eps.valid = 1
AND eps.hostid = hosts.hostid
AND eps.id = assets.episode_id
AND assets.extension = 'ogg'
AND eps.date >= ' $current_episode_date '
ORDER BY
date DESC " ;
if ( $result = mysqli_query ( $connection , $ep_retrieve )) {
while ( $row = mysqli_fetch_array ( $result )) {
$id = $row [ 'id' ];
$date = $row [ 'date' ];
$title = $row [ 'title' ];
$host = $row [ 'host' ];
$show_array [ $id ] = array ( " date " => date ( 'Y-m-d' , strtotime ( $date ) ),
" title " => $title ,
" host " => $host ,
" status " => " Finished "
);
}
}
// --------------------------------------------
// Calculate the time to the next show
# aria-label=""
$next_show_date = date ( 'Y-m-d' , strtotime ( $show_array [ $next_show_num - 1 ][ " date " ] . ' + 1 weekday' ));
$days_to_wait = floor (( strtotime ( $next_show_date ) - strtotime ( gmdate ( 'Y-m-d' ))) / ( 60 * 60 * 24 ));
?>
<h1>Upload Your Show</h1>
<p>
The HPR Schedule is entirely community driven and we recommend that <strong>you</strong> decide when your show will be released.
</p>
<p>
2026-06-05 14:15:58 +02:00
There are only <strong><?php echo "${days_to_wait}"; ?></strong> days to wait until next free slot.
Please consider <a aria-label="Help on Recording a podcast" href="<?php echo "${referrerurl}contribute.html"; ?>">recording</a> a show for us.
2023-07-02 16:47:44 +02:00
</p>
<ol>
2026-06-05 14:15:58 +02:00
<li>Review the updated <em><a aria-label="Learn the Stuff you need to know" href="<?php echo "${referrerurl}contribute.html#stuff_you_need_to_know"; ?>">Stuff you need to know</a></em> page.</li>
2026-05-27 17:44:34 +02:00
<li>Select a date, or post to the Reserve Pool.</li>
2023-07-02 16:47:44 +02:00
<li>Click the link in the confirmation email</li>
2026-06-05 14:15:58 +02:00
<li>Then <a aria-label="Help on Adding an episode" href="<?php echo "${baseurl}contribute.html#uploading_an_episode"; ?>">fill in a form</a>.</li>
2023-07-02 16:47:44 +02:00
</ol>
2026-06-05 14:15:58 +02:00
<h2 id="scheduling_rules">Scheduling Rules</h2>
2024-10-09 20:17:49 +02:00
<ol>
<li>You must have your audio recording ready to upload <strong>before</strong> you pick a slot.</li>
<li>New hosts, Interviews, and other time critical shows should use the first free slot.</li>
2026-06-05 14:15:58 +02:00
<li>Otherwise, when the queue is filling up then leave some free slots for new contributors.</li>
<li>Leave two weeks (9 slots) between your shows.</li>
<li>If you have a non urgent show that is timeless, then add it to the <a href="<?php echo $referrerurl ?>contribute.html#reserve_pool">Reserve Pool</a>.</li>
2024-10-09 20:17:49 +02:00
</ol>
2026-06-01 21:50:13 +02:00
<h2 id="reserve_pool">Add to the Reserve Pool ?</h2>
2023-07-02 16:47:44 +02:00
<p>
2026-06-05 14:15:58 +02:00
<a aria-label="Post to the Reserve Pool" href="<?php echo "${hubBaseurl}"; ?>request.php?id=9999">Post your show to the <strong>Reserve Pool</strong></a> if you don't care when it will be released.
<small><a aria-label="Help on the Reserve Pool" href="<?php echo "${referrerurl}"; ?>contribute.html#reserve_pool";">ⓘ</a></small>
2023-07-02 16:47:44 +02:00
</p>
<h2 id="current_schedule">Select a date in the current schedule ?</h2>
<p>
2025-09-30 23:32:20 -04:00
<strong>Schedule</strong> the release</a> day your show will be aired. <small><a aria-label="Help on the scheduling guidelines" href="<?php echo "${referrerurl}"; ?>about.html#scheduling_guidelines">ⓘ</a></small>
2023-07-02 16:47:44 +02:00
</p>
2026-06-05 14:15:58 +02:00
<h3>Next Two Months <small><a aria-label="Help on the HPR processing workflow" href="https://repo.anhonesthost.net/HPR/hpr_documentation/src/branch/main/workflow/uploading_a_show.md">ⓘ</a></small></h3>
2023-07-02 16:47:44 +02:00
<?php
$sizeof_show_array = sizeof($show_array);
$this_episode_date = date('D Y-m-d', strtotime($current_episode_date));
$week_number = date('W', strtotime($this_episode_date));
for ( $slot = $current_episode_number; $slot < ( $current_episode_number + 60 ); $slot++ ) {
if ( !empty( $show_array[$slot] ) ) {
if ( $show_array[$slot]["status"] === "Finished" ) {
# https://hackerpublicradio.org/eps/hpr3879/index.html
# ${baseurl}/eps/hpr${slot}/index.html
echo "<span style=\"font-family:monospace;\">" . date('D Y-m-d', strtotime($show_array[$slot]["date"])) . ": <a aria-label=\"Go directly to the show hpr${slot}\" href=\"${baseurl}eps/hpr${slot}/index.html\">hpr${slot}</a></span> <strong>" . $show_array[$slot]["title"] . "</strong> by <em>" . $show_array[$slot]["host"] . "</em><br />\n";
}
else {
echo "<span style=\"font-family:monospace;\">${this_episode_date}: hpr${slot}</span> <strong>". $show_array[$slot]["status"]. ":</strong> <em>" . $show_array[$slot]["title"] . "</em>.<br />\n";
}
$sizeof_show_array--;
}
elseif ( empty( $show_array[$slot] ) ) {
2025-09-30 23:22:04 -04:00
echo "<span style=\"font-family:monospace;\">${this_episode_date}: <a aria-label=\"Upload to the slot hpr${slot}\" href=\"${hubBaseurl}request.php?id=${slot}\">hpr${slot}</span> is available - upload now</a>.<br />\n";
2023-07-02 16:47:44 +02:00
}
elseif ( $show_array[$slot]["valid"] == 0 ) {
echo "<span style=\"font-family:monospace;\">${this_episode_date}: hpr${slot}</span> <strong>Unavailable</strong>.<br />\n";
}
$this_episode_date = date('D Y-m-d', strtotime($this_episode_date . ' + 1 weekday'));
$new_week_number = date('W', strtotime($this_episode_date));
if ( $week_number != $new_week_number ) {
$week_number = $new_week_number;
echo "<span style=\"font-family:monospace;\">----------------- Week ${week_number} -----------------<br /></span>\n";
}
}
?>
2024-02-14 10:01:48 +01:00
<h3 id="also_scheduled">Also Scheduled</h3>
2023-07-02 16:47:44 +02:00
<?php
$slot--;
while ( $slot <= $max_episode_number) {
// print "<!-- slot $slot, sizeof_show_array $sizeof_show_array, sizeof_reservation_array $sizeof_reservation_array, max_episode_number $max_episode_number -->\n" ;
if ( !empty( $show_array[$slot] ) ) {
if ( $show_array[$slot]["status"] === "Finished" ) {
echo "<span style=\"font-family:monospace;\">" . date('D Y-m-d', strtotime($show_array[$slot]["date"])) . ": <a aria-label=\"Go directly to the show hpr${slot}\" href=\"${baseurl}eps/hpr${slot}/index.html\">hpr${slot}</a></span> <strong>" . $show_array[$slot]["title"] . "</strong> by <em>" . $show_array[$slot]["host"] . "</em><br />\n";
}
else {
echo "<span style=\"font-family:monospace;\">" . date('D Y-m-d', strtotime($show_array[$slot]["date"])) . ": hpr${slot}</span> <strong>". $show_array[$slot]["status"]. ":</strong> <em>" . $show_array[$slot]["title"] . "</em>.<br />\n";
}
$sizeof_show_array--;
}
$slot++;
}
?>
2026-06-01 21:50:13 +02:00
<h3 id="reserve_pool_overview">Reserve Pool Overview</h3>
2024-02-14 10:01:48 +01:00
<pre>
<?php
include 'reserve.txt';
?>
</pre>
2023-07-02 16:47:44 +02:00
2024-02-14 10:01:48 +01:00
<h3 id="pick_other_dates">Pick other dates</h3>
2023-07-02 16:47:44 +02:00
<p>
2024-01-01 16:26:18 +01:00
If you wish to pick an available slot in the next 12 months then go directly to the <a aria-label="Go to the request page" href="<?php echo "${hubBaseurl}"; ?>request.php">request page</a>.
2023-07-02 16:47:44 +02:00
</p>
2024-02-14 15:06:24 +01:00
<h3 id="workflow">Workflow</h3>
<p>
The HPR statistics are regenerated every 15 minutes and are available in <a aria-label="Go to the stats json page" href="<?php echo "${hubBaseurl}"; ?>stats.json">json format</a>. Note the format is liable to change without notice.</p>
2023-07-02 16:47:44 +02:00
<?php
2025-10-04 09:44:50 -04:00
include 'footer.php';
2023-07-02 16:47:44 +02:00
?>