function podPress_processDownloadRedirect($postID, $mediaNum, $filename, $method = '') { global $podPress, $wpdb; $allowedMethods = array('feed', 'play', 'web'); $realURL = false; $realSysPath = false; $statID = false; if (substr($filename, -20, 20) == 'podPressStatTest.txt') { status_header('200'); echo 'Worked'; // Don't translate this! exit; } if (in_array($method, $allowedMethods) && is_numeric($postID) && is_numeric($mediaNum)) { $mediaFiles = podPress_get_post_meta($postID, '_podPressMedia', true); if (isset($mediaFiles[$mediaNum])) { if ($mediaFiles[$mediaNum]['URI'] == urldecode($filename)) { $realURL = $filename; } elseif (podPress_getFileName($mediaFiles[$mediaNum]['URI']) == urldecode($filename)) { $realURL = $mediaFiles[$mediaNum]['URI']; } elseif (podPress_getFileName($mediaFiles[$mediaNum]['URI_torrent']) == urldecode($filename)) { $realURL = $mediaFiles[$mediaNum]['URI_torrent']; } } } if (!$realURL) { header('X-PodPress-Location: ' . get_option('siteurl')); header('Location: ' . get_option('siteurl')); exit; } $badextensions = array('.smi', '.jpg', '.png', '.gif'); if ($filename && !in_array(strtolower(substr($filename, -4)), $badextensions)) { podPress_StatCounter($postID, $filename, $method); if ($podPress->settings['statLogging'] == 'Full' || $podPress->settings['statLogging'] == 'FullPlus') { $statID = podPress_StatCollector($postID, $filename, $method); } } $realSysPath = $podPress->convertPodcastFileNameToSystemPath(str_replace('%20', ' ', $realURL)); if (FALSE === $realSysPath) { $realSysPath = $podPress->TryToFindAbsFileName(str_replace('%20', ' ', $realURL)); } $realURL = $podPress->convertPodcastFileNameToValidWebPath($realURL); if ($podPress->settings['enable3rdPartyStats'] == 'PodTrac') { $realURL = str_replace(array('ftp://', 'http://', 'https://'), '', $realURL); $realURL = $podPress->podtrac_url . $realURL; } elseif (strtolower($podPress->settings['enable3rdPartyStats']) == 'blubrry' && !empty($podPress->settings['statBluBrryProgramKeyword'])) { $realURL = str_replace('http://', '', $realURL); $realURL = $podPress->blubrry_url . $podPress->settings['statBluBrryProgramKeyword'] . '/' . $realURL; } elseif ($podPress->settings['statLogging'] == 'FullPlus' && $realSysPath !== false) { status_header('200'); $content_type = podPress_mimetypes(podPress_getFileExt($realSysPath)); if ($method == 'web') { header("Pragma: "); header("Cache-Control: "); header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1 header("Cache-Control: post-check=0, pre-check=0", false); header('Content-Disposition: attachment; filename="' . $filename . '"'); header("Content-Description: " . trim(htmlentities($filename))); header("Connection: close"); if (substr($content_type, 0, 4) != 'text') { header("Content-Transfer-Encoding: binary"); } } else { header("Connection: Keep-Alive"); } header("X-ForcedBy: podPress"); header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); header('Content-type: ' . $content_type); header('Content-Length: ' . filesize($realSysPath)); set_time_limit(0); $chunksize = 1 * (1024 * 1024); // how many bytes per chunk if ($handle = fopen($realSysPath, 'rb')) { while (!feof($handle) && connection_status() == 0) { echo fread($handle, $chunksize); ob_flush(); flush(); } fclose($handle); } if ($statID !== false && connection_status() == 0 && !connection_aborted()) { $sqlU = "UPDATE " . $wpdb->prefix . "podpress_stats SET completed=1 WHERE id=" . $statID; $wpdb->hide_errors(); $result = $wpdb->query($sqlI); if (!$result) { $wpdb->query($sqlU); } } exit; } $realURL = str_replace(' ', '%20', $realURL); status_header('302'); header('X-PodPress-Location: ' . $realURL, true, 302); header('Location: ' . $realURL, true, 302); header('Content-Length: 0'); exit; }
function xmlrpc_post_addMedia($input) { $postdata = $input['postdata']; $content_struct = $input['content_struct']; if (isset($content_struct['enclosure']) && !empty($content_struct['enclosure']['url'])) { $media[0]['URI'] = $content_struct['enclosure']['url']; $media[0]['authorized'] = true; if (!empty($content_struct['enclosure']['type'])) { $media[0]['type'] = $content_struct['enclosure']['type']; } else { $media[0]['type'] = podPress_mimetypes(podPress_getFileExt($content_struct['enclosure']['url'])); } if ($media[0]['type'] == 'video/x-ms-wmv') { $media[0]['type'] = 'video/wmv'; } elseif ($media[0]['type'] == 'video/x-flv') { $media[0]['type'] = 'video/flv'; } $media[0]['type'] = str_replace('/', '_', $media[0]['type']); if (!empty($content_struct['enclosure']['duration'])) { $media[0]['duration'] = $content_struct['enclosure']['duration']; } else { $media[0]['duration'] = 0; } if (!empty($content_struct['enclosure']['size'])) { $media[0]['size'] = $content_struct['enclosure']['size']; } else { $media[0]['size'] = 0; } if (!empty($content_struct['enclosure']['title'])) { $media[0]['title'] = $content_struct['enclosure']['title']; } if (!empty($content_struct['enclosure']['previewImage'])) { $media[0]['previewImage'] = $content_struct['enclosure']['previewImage']; } if (!empty($content_struct['enclosure']['rss'])) { $media[0]['rss'] = $content_struct['enclosure']['rss']; } else { $media[0]['rss'] = true; } delete_post_meta($postdata['ID'], '_podPressMedia'); podPress_add_post_meta($postdata['ID'], '_podPressMedia', $media, true); } return true; }