/** * Download file from $_GET['podcast_episode'] * @return void */ public function download_file() { if (is_podcast_download()) { $file = esc_attr($_GET['podcast_episode']); if ($file) { // Get episode object $episode = $this->get_episode_from_file($file); // Allow other actions - functions hooked on here must not echo any data do_action('ss_podcasting_file_download', $file, $episode); // Set necessary headers header("Pragma: no-cache"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Robots: none"); header("Content-Type: application/force-download"); header("Content-Description: File Transfer"); header("Content-Disposition: attachment; filename=\"" . basename($file) . "\";"); header("Content-Transfer-Encoding: binary"); // Set size of file if ($size = @filesize($file)) { header("Content-Length: " . $size); } // Use ssp_readfile_chunked() if allowed on the server or simply access file directly @ssp_readfile_chunked("{$file}") or header('Location: ' . $file); } } }
/** * Download file from `podcast_episode` query variable * @return void */ public function download_file() { if (is_podcast_download()) { global $wp_query; // Get requested episode ID $episode_id = intval($wp_query->query_vars['podcast_episode']); if (isset($episode_id) && $episode_id) { // Get episode post object $episode = get_post($episode_id); // Make sure we have a valid episode post object if (!$episode || !is_object($episode) || is_wp_error($episode) || !isset($episode->ID)) { return; } // Get audio file for download $file = $this->get_enclosure($episode_id); // Exit if no file is found if (!$file) { return; } // Get file referrer $referrer = ''; if (isset($wp_query->query_vars['podcast_ref']) && $wp_query->query_vars['podcast_ref']) { $referrer = $wp_query->query_vars['podcast_ref']; } else { if (isset($_GET['ref'])) { $referrer = esc_attr($_GET['ref']); } } // Allow other actions - functions hooked on here must not output any data do_action('ssp_file_download', $file, $episode, $referrer); // Set necessary headers for download header("Pragma: no-cache"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Robots: none"); header("Content-Description: File Transfer"); header("Content-Disposition: attachment; filename=\"" . basename($file) . "\";"); header("Content-Transfer-Encoding: binary"); // Set size of file if ($size = @filesize($file)) { header("Content-Length: " . $size); } // Check file referrer if ('download' == $referrer) { // Force file download header("Content-Type: application/force-download"); // Use ssp_readfile_chunked() if allowed on the server or simply access file directly @ssp_readfile_chunked("{$file}") or header('Location: ' . $file); } else { // For all other referrers simply access the file directly wp_redirect($file, 302); } // Exit to prevent other processes running later on exit; } } }