War

.

War
Mar 14th, 2017
588
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.66 KB | None | 0 0
  1. elseif(strpos(strtolower($_SERVER['HTTP_HOST']), 'video.') === 0)
  2.     {
  3.         // IF YOU MAKE CHANGES TO THIS, please make corresponding changes to /site/video
  4.         try
  5.         {
  6.             $message = 'there was an error processing your request';
  7.  
  8.             $urlPattern = '|/([[:alnum:]]+)|';
  9.             if (preg_match_all($urlPattern, $origURI, $matches))
  10.             {
  11.                 $daoVideo = DAO_Video::getInstance();
  12.                 $videoId = $matches[1][0];
  13.                 $video = $daoVideo->readById($videoId);
  14.                 if (is_object($video)) {
  15.                     $home = $video->getProductBin()->getHome();
  16.                     if (!is_object($home) || !$home->isPosted())
  17.                     {
  18.                         $message = 'This tour is no longer active.';
  19.                         throw new Exception("No home for id ($homeId)");
  20.                     }
  21.  
  22.                     $templateId = $video->getVideoTemplateId();
  23.  
  24.                     $videoUpload = $video->getUpload();
  25.                     if (!is_object($videoUpload))
  26.                     {
  27.                         $message = "We could not find a listing video for your listing (1): $homeId";
  28.                         throw new Exception("No video upload for ($homeId, $templateId, $uploadAccountId)");
  29.                     }
  30.                 } else {
  31.                     $daoHome = DAO_Home::getInstance();
  32.                     $homeId = $matches[1][0];
  33.                     $home = $daoHome->readByHomeId($homeId);
  34.                     if (!is_object($home) || !$home->isPosted())
  35.                     {
  36.                         $message = 'This tour is no longer active.';
  37.                         throw new Exception("No home for id ($homeId)");
  38.                     }
  39.  
  40.                     $templateId = isset($matches[1][1]) ? $matches[1][1] : null;
  41.                     $uploadAccountId = (isset($matches[1][2]) && ($matches[1][2] != 'video')) ? $matches[1][2] : null;
  42.  
  43.                     $video = $home->getVideoProduct($templateId);
  44.                     if (!is_object($video))
  45.                     {
  46.                         $message = "We could not find a listing video for your listing (2): $homeId";
  47.                         throw new Exception("No video for ($homeId, $templateId)");
  48.                     }
  49.                     $videoUpload = $video->getUpload($uploadAccountId);
  50.                     if (!is_object($videoUpload))
  51.                     {
  52.                         $message = "We could not find a listing video for your listing (3): $homeId";
  53.                         throw new Exception("No video upload for ($homeId, $templateId, $uploadAccountId)");
  54.                     }
  55.                 }
  56.  
  57.                 $account = $videoUpload->getVideoUploadAccount();
  58. //                $location = "http://youtube.com/user/{$youTubeChannel}#p/search/0/{$youTubeId}";
  59.                 switch($account->getVideoUploadSiteId())
  60.                 {
  61.                     case CO_VideoUploadSite::YOUTUBE:
  62.                         header('Location: http://www.youtube.com/watch?v=' . $videoUpload->getUploadedId());
  63.                     break;
  64.                     default:
  65.                         throw new Exception("No site match: " . $account->getVideoUploadSiteId(), CO_Action::USER_ERROR);
  66.                         break;
  67.                 }
  68.                 exit();
  69.             }
  70.             throw new Exception("No pattern match: " . $origURI);
  71.         }
  72.         catch(Exception $e)
  73.         {
  74.             Log::fileWrite(Log::CPVIDEO_LOCATE, $e->getMessage());
  75.         }
  76.         header("Location: http://"  . $_SERVER[HTTP_HOST] .  "/error.htm?message={$message}");
  77.         exit();
  78.     }
Add Comment
Please, Sign In to add comment