Exemplo n.º 1
0
 public function fetch_youtube_uploadform($yt, $videotitle, $videodescription)
 {
     global $CFG, $USER;
     // create a new VideoEntry object
     $myVideoEntry = new Zend_Gdata_YouTube_VideoEntry();
     $myVideoEntry->setVideoTitle($videotitle);
     $myVideoEntry->setVideoDescription($videodescription);
     // The category must be a valid YouTube category!
     $myVideoEntry->setVideoCategory('Education');
     //This sets videos private, but then can't view if not logged in as the account owner
     //$myVideoEntry->setVideoPrivate();
     //So instead we set them to unlisted(but its more complex)
     $unlisted = new Zend_Gdata_App_Extension_Element('yt:accessControl', 'yt', 'http://gdata.youtube.com/schemas/2007', '');
     $unlisted->setExtensionAttributes(array(array('namespaceUri' => '', 'name' => 'action', 'value' => 'list'), array('namespaceUri' => '', 'name' => 'permission', 'value' => 'denied')));
     $myVideoEntry->setExtensionElements(array($unlisted));
     // Set keywords. This must be a comma-separated string
     // Individual keywords cannot contain whitespace
     // We are not doing this, but it would be possible
     //$myVideoEntry->SetVideoTags('cars, funny');
     //data is all set, so we get our upload token from google
     $tokenHandlerUrl = 'http://gdata.youtube.com/action/GetUploadToken';
     $tokenArray = $yt->getFormUploadToken($myVideoEntry, $tokenHandlerUrl);
     $tokenValue = $tokenArray['token'];
     $postUrl = $tokenArray['url'];
     //Set the URL YouTube should redirect user to after upload
     //that will be the same iframe
     $nextUrl = $CFG->httpswwwroot . '/mod/assign/submission/youtube/uploader.php';
     // Now that we have the token, we build the form
     $form = '<form action="' . $postUrl . '?nexturl=' . $nextUrl . '" method="post" enctype="multipart/form-data">' . '<input name="file" type="file"/>' . '<input name="token" type="hidden" value="' . $tokenValue . '"/>' . '<input value="Upload Video File" type="submit" onclick="document.getElementById(\'id_uploadanim\').style.display=\'block\';" />' . '</form>';
     // We tag on a hidden uploading icon. YouTube gives us no progress events, sigh.
     // So its the best we can do to show an animated gif.
     // But if it fails, user will wait forever.
     $form .= '<img id="id_uploadanim" style="display: none;margin-left: auto;margin-right: auto;" src="' . $CFG->httpswwwroot . '/mod/assign/submission/youtube/pix/uploading.gif"/>';
     return $form;
 }
Exemplo n.º 2
0
 /**
  * displayYouTubeUploadFilePage 
  * 
  * Takes the post data from the previous form, sends to youtube, creates new entry,
  * and prints the video file upload form.
  * 
  * @return void
  */
 function displayYouTubeUploadFilePage()
 {
     $this->displayHeader();
     $videoTitle = '';
     $videoDescription = '';
     if (isset($_POST['title'])) {
         $videoTitle = strip_tags($_POST['title']);
     }
     if (isset($_POST['description'])) {
         $videoDescription = strip_tags($_POST['description']);
     }
     $videoCategory = isset($_POST['category']) ? $_POST['category'] : '';
     $videoUnlisted = isset($_POST['unlisted']) ? true : false;
     // Create fcms video - we update after the youtube video is created
     $sql = "INSERT INTO `fcms_video` (\n                    `source_id`, \n                    `title`, \n                    `description`, \n                    `source`, \n                    `created`, \n                    `created_id`, \n                    `updated`, \n                    `updated_id`\n                )\n                VALUES\n                    ('0', ?, ?, 'youtube', NOW(), ?, NOW(), ?)";
     $params = array($videoTitle, $videoDescription, $this->fcmsUser->id, $this->fcmsUser->id);
     $lastId = $this->fcmsDatabase->insert($sql, $params);
     if ($lastId === false) {
         $this->fcmsError->displayError();
         $this->displayFooter();
         return;
     }
     // Save fcms video id
     $_SESSION['fcmsVideoId'] = $lastId;
     $sessionToken = $this->getSessionToken($this->fcmsUser->id);
     $youtubeConfig = getYouTubeConfigData();
     $httpClient = getYouTubeAuthSubHttpClient($youtubeConfig['youtube_key'], $sessionToken);
     if ($httpClient === false) {
         // Error message was already displayed by getYouTubeAuthSubHttpClient()
         $this->displayFooter();
         die;
     }
     $youTubeService = new Zend_Gdata_YouTube($httpClient);
     $newVideoEntry = new Zend_Gdata_YouTube_VideoEntry();
     $newVideoEntry->setVideoTitle($videoTitle);
     $newVideoEntry->setVideoDescription($videoDescription);
     $newVideoEntry->setVideoCategory($videoCategory);
     // make video unlisted
     if ($videoUnlisted) {
         $unlisted = new Zend_Gdata_App_Extension_Element('yt:accessControl', 'yt', 'http://gdata.youtube.com/schemas/2007', '');
         $unlisted->setExtensionAttributes(array(array('namespaceUri' => '', 'name' => 'action', 'value' => 'list'), array('namespaceUri' => '', 'name' => 'permission', 'value' => 'denied')));
         $newVideoEntry->setExtensionElements(array($unlisted));
     }
     try {
         $tokenArray = $youTubeService->getFormUploadToken($newVideoEntry, 'http://gdata.youtube.com/action/GetUploadToken');
     } catch (Exception $e) {
         echo '
         <div class="error-alert">
             <p>' . T('Could not retrieve token for syndicated upload.') . '</p>
             <p>' . $e->getMessage() . '</p>
         </div>';
         $this->displayFooter();
         return;
     }
     $tokenValue = $tokenArray['token'];
     $postUrl = $tokenArray['url'];
     $nextUrl = getDomainAndDir() . 'video.php?upload=youtube';
     echo '
     <form action="' . $postUrl . '?nexturl=' . $nextUrl . '" method="post" enctype="multipart/form-data">
         <fieldset>
             <legend><span>' . T_('Upload YouTube Video') . '</span></legend>
             <div class="field-row">
                 <div class="field-label"><label><b>' . T_('Title') . '</b></label></div>
                 <div class="field-widget"><b>' . $videoTitle . '</b></div>
             </div>
             <div class="field-row">
                 <div class="field-label"><label><b>' . T_('Video') . '</b></label></div>
                 <div class="field-widget">
                     <input type="file" name="file" size="50"/>
                 </div>
             </div>
             <input name="token" type="hidden" value="' . $tokenValue . '"/>
             <input class="sub1" type="submit" id="upload_file" name="upload_file" value="' . T_('Upload') . '"/>
         </fieldset>
     </form>';
     $this->displayFooter();
 }