setFallbackAutoloader(true);
try {
$context = new Libsyn_Context();
$trafficker = Libsyn_Service_Trafficker::getInstance();
$url = $trafficker->trafficRequest($_SERVER['REQUEST_URI']);
$url = rewriteDevelopmentUrl($url);
issueRedirect($url, $trafficker->showData, $trafficker->fileData);
}
catch (Exception $e) {
if ($e->getCode() != 404 && $e->getCode() != 403) {
Libsyn_Log::fatal($e);
}
if (!$trafficker->isDebug()) {
issueError($_SERVER['REQUEST_URI'], $e->getCode(), $e->getMessage());
}
}
/**
* Issues a redirect to the provided URL.
* Will take into account Facebook user agent.
* @param string $url Destination URL
*/
function issueRedirect($url, $show, $media) {
global $context;
if (!empty($url)) {
$fileName = basename(parse_url($url, PHP_URL_PATH));
$mimeType = Libsyn_Utilities::getMimeType($fileName);
// Facebook doesn't handle redirects so well and it uses the Content-Type
// header to determine whether or not it's going to try to embed
// a link using one of it's players. We want to make sure that Facebook
// does embed our audio specifically. Since facebook's URL scraper
// sends a 206 request and isn't even concerned with checking the content
// we'll not send them any - instead 200 the response and exit out, but
// first send the proper mime type for Facebook player goodness.
if (isset($_SERVER['HTTP_USER_AGENT']) && stripos($_SERVER['HTTP_USER_AGENT'], 'facebook') !== false) {
header("HTTP/1.0 200 OK");
$trafficUrl = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$assetUrl = 'http://' . $context->getHostname('assets') . (
(!empty($media['image_content_id'])) ? '/content/' . $media['image_content_id'] : '/show/' . $show['show_id']
);
print <<