set_charset('utf8'); function rrmdir($src) { $dir = opendir($src); while(false !== ( $file = readdir($dir)) ) { if (( $file != '.' ) && ( $file != '..' )) { $full = $src . '/' . $file; if ( is_dir($full) ) { rrmdir($full); } else { unlink($full); } } } closedir($dir); rmdir($src); } function call412($error){ usleep(rand(10000000,30000000)); global $HPR_Name, $HPR_Names, $naughtyfile; header("Status: 412 Precondition Failed"); print ' '.$HPR_Name.' Public Radio

412 Precondition Failed

ERROR CODE

'.$error.'

If you believe this to be an error, then please copy this error code and send it to admin@hpr.

'.date('Y-m-d\TH:i:s') . "\t" . getUserIP() . "\t" . $_SERVER["HTTP_USER_AGENT"] .'

'; file_put_contents($naughtyfile, date('Y-m-d\TH:i:s\Z') . "\t" . getUserIPAdress() ."\t" . $error . "\t" . $_SERVER['REQUEST_URI'] . "\t" . $_SERVER["HTTP_USER_AGENT"] . "\n", FILE_APPEND | LOCK_EX ); exit; } function problem($error){ global $HPR_Name, $HPR_Names, $naughtyfile; file_put_contents($naughtyfile, date('Y-m-d\TH:i:s\Z') . "\t" . getUserIPAdress() ."\tERROR: " . $error . "\t" . $_SERVER['REQUEST_URI'] . "\t" . $_SERVER["HTTP_USER_AGENT"] . "\n", FILE_APPEND | LOCK_EX ); #usleep(2000000); header("Status: 412 Precondition Failed"); print ' '.$HPR_Name.' Public Radio

412 Precondition Failed

ERROR CODE

'.$error.'

If you believe this to be an error, then please copy this error code and send it to admin@hpr.

'.date('Y-m-d\TH:i:s') . "\t" . getUserIP() . "\t" . $_SERVER["HTTP_USER_AGENT"] .'

'; exit; } function naughty($error){ global $HPR_Name, $HPR_Names, $naughtyfile; file_put_contents($naughtyfile, date('Y-m-d\TH:i:s\Z') . "\t" . getUserIPAdress() ."\t" . $error . "\t" . $_SERVER['REQUEST_URI'] . "\t" . $_SERVER["HTTP_USER_AGENT"] . "\n", FILE_APPEND | LOCK_EX ); #usleep(rand(10000000,30000000)); header("Status: 412 Precondition Failed"); print ' '.$HPR_Name.' Public Radio

412 Precondition Failed

ERROR CODE

'.$error.'

If you believe this to be an error, then please copy this error code and send it to admin@hpr.

'.date('Y-m-d\TH:i:s') . "\t" . getUserIP() . "\t" . $_SERVER["HTTP_USER_AGENT"] .'

'; exit; } function logextra($message){ global $HPR_Name, $HPR_Names, $naughtyfile; file_put_contents($naughtyfile, date('Y-m-d\TH:i:s\Z') . "\t" . getUserIPAdress() ."\t" . $message . "\t" . $_SERVER['REQUEST_URI'] . "\t" . $_SERVER["HTTP_USER_AGENT"] . "\n", FILE_APPEND | LOCK_EX ); } function convertSecToTime($sec){ $date1 = new DateTime("@0"); //starting seconds $date2 = new DateTime("@$sec"); // ending seconds $interval = date_diff($date1, $date2); //the time difference return $interval->format('%y Years, %m months, %d days, %h hours, %i minutes and %s seconds'); // convert into Years, Months, Days, Hours, Minutes and Seconds } function fixid($id){ return sprintf('%04d',$id); } function navtext($id,$curr_ep_id){ if ( $id <= 1 ) { echo "<< First, < Previous, "; } else { echo "<< First, "; echo "< Previous, "; } if ( $id >= $curr_ep_id ) { echo "Next >, "; echo "Latest >>"; } else { echo "Next >, "; echo "Latest >>"; } } function formatemail($email) { // Miminal spam protection if (!stristr($email, '.nospam@nospam.')){ $part = explode("@", $email); $email = $part[0] . ".nospam@nospam." . $part[1]; } return $email; } function unformatemail($email) { // Miminal spam protection if (stristr($email, '.nospam@nospam.')){ $part = explode(".nospam@nospam.", $email); $email = $part[0] . "@" . $part[1]; } return $email; } function makeClickableLinks($string) { # Used to display links from test urls $pattern = '/\b((?:https?:\/\/|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:\'".,<>?«»“”‘’]))/i'; $replacement = '$1'; return preg_replace($pattern, $replacement, $string); } function get_gravatar( $email, $s = 80, $d = '404', $r = 'x', $img = false, $atts = array() ) { /** * Get either a Gravatar URL or complete image tag for a specified email address. * * @param string $email The email address * @param string $s Size in pixels, defaults to 80px [ 1 - 512 ] * @param string $d Default imageset to use [ 404 | mm | identicon | monsterid | wavatar ] * @param string $r Maximum rating (inclusive) [ g | pg | r | x ] * @param boole $img True to return a complete IMG tag False for just the URL * @param array $atts Optional, additional key/value attributes to include in the IMG tag * @return String containing either just a URL or a complete image tag * @source http://gravatar.com/site/implement/images/php/ */ $url = 'https://secure.gravatar.com/avatar/'; $url .= md5( strtolower( trim( $email ) ) ); $url .= "?s=${s}&d=${d}.png"; if ( $img ) { $url = ' $val ) $url .= ' ' . $key . '="' . $val . '"'; $url .= '.png />'; } return $url; } function getUserIPAdress() { $ip = ''; if (getenv('HTTP_CLIENT_IP')) { $ip = getenv('HTTP_CLIENT_IP'); } else if(getenv('HTTP_X_FORWARDED_FOR')) { $ip = getenv('HTTP_X_FORWARDED_FOR'); } else if(getenv('HTTP_X_FORWARDED')) { $ip = getenv('HTTP_X_FORWARDED'); } else if(getenv('HTTP_FORWARDED_FOR')) { $ip = getenv('HTTP_FORWARDED_FOR'); } else if(getenv('HTTP_FORWARDED')) { $ip = getenv('HTTP_FORWARDED'); } else if(getenv('REMOTE_ADDR')) { $ip = getenv('REMOTE_ADDR'); } else { $ip = 'UNKNOWN'; } return $ip; } function getUserIP() { //check ip from share internet if (!empty($_SERVER['HTTP_CLIENT_IP'])) { $ip=$_SERVER['HTTP_CLIENT_IP']; } else { $ip=$_SERVER['REMOTE_ADDR']; } return $ip . "\t" . $_SERVER['REQUEST_URI'] . "\t" . $_SERVER["HTTP_USER_AGENT"] . "\n"; } if ( strlen($_SERVER['QUERY_STRING']) > 15 ) { file_put_contents($naughtyfile, getUserIP(), FILE_APPEND | LOCK_EX ); } function GetFirstFreeSlot() { // -------------------------------------------- // Get first free slot $query = mysqli_query("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); return $next_show_num_array[0]; } function GetLatestPublishedShow($connection){ // -------------------------------------------- // 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); return array($current_episode_array[0], $current_episode_array[1]); } $PROTOCOL = ''; if ((!empty($_SERVER['HTTPS'])) && ($_SERVER['HTTPS'] !== 'off')) { $PROTOCOL .= 'https://'; } else { $PROTOCOL .= 'http://'; } $HTTP_HOST = $_SERVER['HTTP_HOST']; $pos = strpos($HTTP_HOST, "hobbypublicradio"); if ($pos !== false) { $HPR_Name = "Hobby"; $HPR_Names = "hobbyists"; } else { $HPR_Name = "Hacker"; $HPR_Names = "Hackers"; } $allowed_extensions = array("flac", "opus", "ogg", "spx", "mp3", "jpg", "png", "json", "srt", "tsv", "txt", "vtt"); ?>