elseif(strpos(strtolower($_SERVER['HTTP_HOST']), 'video.') === 0) { // IF YOU MAKE CHANGES TO THIS, please make corresponding changes to /site/video try { $message = 'there was an error processing your request'; $urlPattern = '|/([[:alnum:]]+)|'; if (preg_match_all($urlPattern, $origURI, $matches)) { $daoVideo = DAO_Video::getInstance(); $videoId = $matches[1][0]; $video = $daoVideo->readById($videoId); if (is_object($video)) { $home = $video->getProductBin()->getHome(); if (!is_object($home) || !$home->isPosted()) { $message = 'This tour is no longer active.'; throw new Exception("No home for id ($homeId)"); } $templateId = $video->getVideoTemplateId(); $videoUpload = $video->getUpload(); if (!is_object($videoUpload)) { $message = "We could not find a listing video for your listing (1): $homeId"; throw new Exception("No video upload for ($homeId, $templateId, $uploadAccountId)"); } } else { $daoHome = DAO_Home::getInstance(); $homeId = $matches[1][0]; $home = $daoHome->readByHomeId($homeId); if (!is_object($home) || !$home->isPosted()) { $message = 'This tour is no longer active.'; throw new Exception("No home for id ($homeId)"); } $templateId = isset($matches[1][1]) ? $matches[1][1] : null; $uploadAccountId = (isset($matches[1][2]) && ($matches[1][2] != 'video')) ? $matches[1][2] : null; $video = $home->getVideoProduct($templateId); if (!is_object($video)) { $message = "We could not find a listing video for your listing (2): $homeId"; throw new Exception("No video for ($homeId, $templateId)"); } $videoUpload = $video->getUpload($uploadAccountId); if (!is_object($videoUpload)) { $message = "We could not find a listing video for your listing (3): $homeId"; throw new Exception("No video upload for ($homeId, $templateId, $uploadAccountId)"); } } $account = $videoUpload->getVideoUploadAccount(); // $location = "http://youtube.com/user/{$youTubeChannel}#p/search/0/{$youTubeId}"; switch($account->getVideoUploadSiteId()) { case CO_VideoUploadSite::YOUTUBE: header('Location: http://www.youtube.com/watch?v=' . $videoUpload->getUploadedId()); break; default: throw new Exception("No site match: " . $account->getVideoUploadSiteId(), CO_Action::USER_ERROR); break; } exit(); } throw new Exception("No pattern match: " . $origURI); } catch(Exception $e) { Log::fileWrite(Log::CPVIDEO_LOCATE, $e->getMessage()); } header("Location: http://" . $_SERVER[HTTP_HOST] . "/error.htm?message={$message}"); exit(); }