| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582 |
- /**
- * Zend Framework
- *
- * LICENSE
- *
- * This source file is subject to the new BSD license that is bundled
- * with this package in the file LICENSE.txt.
- * It is also available through the world-wide-web at this URL:
- * http://framework.zend.com/license/new-bsd
- * If you did not receive a copy of the license and are unable to
- * obtain it through the world-wide-web, please send an email
- * to license@zend.com so we can send you a copy immediately.
- *
- * @category Zend
- * @package Zend_Gdata
- * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
- * @license http://framework.zend.com/license/new-bsd New BSD License
- */
- /**
- * @fileoverview Provides functions for browsing and searching YouTube
- * data API feeds, as well as performing authentication, syndicated uploads
- * and playlist management using a PHP backend powered by the Zend_Gdata component
- * of Zend Framework.
- */
- /**
- * provides namespacing for the YouTube Video Application PHP version (ytVideoApp)
- */
- var ytVideoApp = {};
- /**
- * maximum number of results to return for list of videos
- * @type Number
- */
- ytVideoApp.MAX_RESULTS_LIST = 5;
- /**
- * navigation button id used to page to the previous page of
- * results in the list of videos
- * @type String
- */
- ytVideoApp.PREVIOUS_PAGE_BUTTON = 'previousPageButton';
- /**
- * navigation button id used to page to the next page of
- * results in the list of videos
- * @type String
- */
- ytVideoApp.NEXT_PAGE_BUTTON = 'nextPageButton';
- /**
- * container div for navigation elements
- * @type String
- */
- ytVideoApp.NAVIGATION_DIV = 'navigationForm';
- /**
- * container div id used to hold list of videos
- * @type String
- */
- ytVideoApp.VIDEO_LIST_CONTAINER_DIV = 'searchResultsVideoList';
- /**
- * container div id used to hold video search results
- * @type String
- */
- ytVideoApp.VIDEO_SEARCH_RESULTS_DIV = 'searchResultsVideoColumn';
- /**
- * container div id used to hold the video player
- * @type String
- */
- ytVideoApp.VIDEO_PLAYER_DIV = 'videoPlayer';
- /**
- * container div id used to hold the search box displayed at the top of
- * the browser after one search has already been performed
- * @type String
- */
- ytVideoApp.TOP_SEARCH_CONTAINER_DIV = 'searchBox';
- /** container div to show detailed upload status
- * @type String
- */
- ytVideoApp.VIDEO_UPLOAD_STATUS = 'detailedUploadStatus';
- /**
- * container div to hold the form for syndicated upload
- * @type String
- */
- ytVideoApp.SYNDICATED_UPLOAD_DIV = 'syndicatedUploadDiv';
- /**
- * container div to hold the form to edit video meta-data
- * @type String
- */
- ytVideoApp.VIDEO_DATA_EDIT_DIV = 'editForm';
- /**
- * containder div to hold authentication link in special cases where auth gets
- * set prior to developer key
- * @type String
- */
- ytVideoApp.AUTHSUB_REQUEST_DIV = 'generateAuthSubLink';
- /**
- * container div to hold the form for editing video meta-data
- * @type String
- */
- ytVideoApp.VIDEO_META_DATA_EDIT_DIV = 'editVideoMetaDataDiv';
- /**
- * container div to hold the form for adding a new playlist
- * @type String
- */
- ytVideoApp.PLAYLIST_ADD_DIV = 'addNewPlaylist';
- /**
- * the page number to use for the next page navigation button
- * @type Number
- */
- ytVideoApp.nextPage = 2;
- /**
- * the page number to use for the previous page navigation button
- * @type Number
- */
- ytVideoApp.previousPage = 0;
- /**
- * the last search term used to query - allows for the navigation
- * buttons to know what string query to perform when clicked
- * @type String
- */
- ytVideoApp.previousSearchTerm = '';
- /**
- * the last query type used for querying - allows for the navigation
- * buttons to know what type of query to perform when clicked
- * @type String
- */
- ytVideoApp.previousQueryType = 'all';
- /**
- * Retrieves a list of videos matching the provided criteria. The list of
- * videos can be restricted to a particular standard feed or search criteria.
- * @param {String} op The type of action to be done.
- * for querying all videos, or the name of a standard feed.
- * @param {String} searchTerm The search term(s) to use for querying as the
- * 'vq' query parameter value
- * @param {Number} page The 1-based page of results to return.
- */
- ytVideoApp.listVideos = function(op, searchTerm, page) {
- ytVideoApp.previousSearchTerm = searchTerm;
- ytVideoApp.previousQueryType = op;
- var maxResults = ytVideoApp.MAX_RESULTS_LIST;
- var startIndex = (((page - 1) * ytVideoApp.MAX_RESULTS_LIST) + 1);
- ytVideoApp.presentFeed(op, maxResults, startIndex, searchTerm);
- ytVideoApp.updateNavigation(page);
- };
- /**
- * Sends an AJAX request to the server to retrieve a list of videos or
- * the video player/metadata. Sends the request to the specified filePath
- * on the same host, passing the specified params, and filling the specified
- * resultDivName with the resutls upon success.
- * @param {String} filePath The path to which the request should be sent
- * @param {String} params The URL encoded POST params
- * @param {String} resultDivName The name of the DIV used to hold the results
- */
- ytVideoApp.sendRequest = function(filePath, params, resultDivName) {
- if (window.XMLHttpRequest) {
- var xmlhr = new XMLHttpRequest();
- } else {
- var xmlhr = new ActiveXObject('MSXML2.XMLHTTP.3.0');
- }
- xmlhr.open('POST', filePath);
- xmlhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
- xmlhr.onreadystatechange = function() {
- var resultDiv = document.getElementById(resultDivName);
- if (xmlhr.readyState == 1) {
- resultDiv.innerHTML = '<b>Loading...</b>';
- } else if (xmlhr.readyState == 4 && xmlhr.status == 200) {
- if (xmlhr.responseText) {
- resultDiv.innerHTML = xmlhr.responseText;
- }
- } else if (xmlhr.readyState == 4) {
- alert('Invalid response received - Status: ' + xmlhr.status);
- }
- }
- xmlhr.send(params);
- }
- /**
- * Uses ytVideoApp.sendRequest to display a YT video player and metadata for the
- * specified video ID.
- * @param {String} videoId The ID of the YouTube video to show
- */
- ytVideoApp.presentVideo = function(videoId, updateThumbnail) {
- var params = 'operation=show_video&videoId=' + videoId;
- var filePath = 'operations.php';
- ytVideoApp.sendRequest(filePath, params, ytVideoApp.VIDEO_PLAYER_DIV);
- }
- /**
- * Creates a form to enter video meta-data in preparation for syndicated upload.
- */
- ytVideoApp.prepareUploadForm = function() {
- var metaDataForm = ['<br clear="all"><form id="uploadForm" ',
- 'onsubmit="ytVideoApp.prepareSyndicatedUpload(',
- 'this.videoTitle.value, ',
- 'this.videoDescription.value, ',
- 'this.videoCategory.value, ',
- 'this.videoTags.value); ',
- 'return false;">',
- 'Enter video title:<br /><input size="50" name="videoTitle" ',
- 'type="text" /><br />',
- 'Enter video description:<br /><textarea cols="50" ',
- 'name="videoDescription"></textarea><br />',
- 'Select a category: <select name="videoCategory">',
- '<option value="Autos">Autos & Vehicles</option>',
- '<option value="Music">Music</option>',
- '<option value="Animals">Pets & Animals</option>',
- '<option value="Sports">Sports</option>',
- '<option value="Travel">Travel & Events</option>',
- '<option value="Games">Gadgets & Games</option>',
- '<option value="Comedy">Comedy</option>',
- '<option value="People">People & Blogs</option>',
- '<option value="News">News & Politics</option>',
- '<option value="Entertainment">Entertainment</option>',
- '<option value="Education">Education</option>',
- '<option value="Howto">Howto & Style</option>',
- '<option value="Nonprofit">Nonprofit & Activism</option>',
- '<option value="Tech">Science & Technology</option>',
- '</select><br />',
- 'Enter some tags to describe your video ',
- '<em>(separated by spaces)</em>:<br />',
- '<input name="videoTags" type="text" size="50" value="video" /><br />',
- '<input type="submit" value="go">',
- '</form>'].join('');
- document.getElementById(ytVideoApp.SYNDICATED_UPLOAD_DIV).innerHTML = metaDataForm;
- }
- /**
- * Uses ytVideoApp.sendRequest to prepare a syndicated upload.
- *
- * @param {String} videoTitle The title for new video
- * @param {String} videoDescription The video's description
- * @param {String} videoCategory The category for the video
- * @param {String} videoTags A white-space separated string of Tags
- */
- ytVideoApp.prepareSyndicatedUpload = function(videoTitle, videoDescription, videoCategory, videoTags) {
- var filePath = 'operations.php';
- var params = 'operation=create_upload_form' +
- '&videoTitle=' + videoTitle +
- '&videoDescription=' + videoDescription +
- '&videoCategory=' + videoCategory +
- '&videoTags=' + videoTags;
- ytVideoApp.sendRequest(filePath, params, ytVideoApp.SYNDICATED_UPLOAD_DIV);
- }
- /**
- * Uses ytVideoApp.sendRequest to create the authSub link.
- */
- ytVideoApp.presentAuthLink = function() {
- var filePath = 'operations.php';
- var params = 'operation=auth_sub_request';
- ytVideoApp.sendRequest(filePath, params, ytVideoApp.AUTHSUB_REQUEST_DIV);
- }
- /**
- * Uses ytVideoApp.sendRequest to check a videos upload status.
- *
- * @param {String} videoId The id of the video to check
- */
- ytVideoApp.checkUploadDetails = function(videoId) {
- var filePath = 'operations.php';
- var params = 'operation=check_upload_status' +
- '&videoId=' + videoId;
- ytVideoApp.sendRequest(filePath, params, ytVideoApp.VIDEO_UPLOAD_STATUS);
- }
- /**
- * Creates an HTML form to edit a video's meta-data, populated with the
- * videos current meta-data.
- *
- * @param {String} oldVideoTitle The old title of the video
- * @param {String} oldVideoDescription The old description of the video
- * @param {String} oldVideoCategory The old category of the video
- * @param {String} oldVideoTags The old tags for the video (separated by white-space)
- * @param {String} videoId The id of the video to be edited
- */
- ytVideoApp.presentMetaDataEditForm = function(oldVideoTitle, oldVideoDescription, oldVideoCategory, oldVideoTags, videoId) {
- // split oldVideoTags by comma and present as whitespace separated
- var oldVideoTagsArray = oldVideoTags.split(',');
- oldVideoTags = oldVideoTagsArray.join(' ');
- var editMetaDataForm = ['<form id="editForm" ',
- 'onsubmit="ytVideoApp.editMetaData(',
- 'this.newVideoTitle.value, ',
- 'this.newVideoDescription.value, ',
- 'this.newVideoCategory.value, ',
- 'this.newVideoTags.value, ',
- 'this.videoId.value);',
- 'return false;">',
- 'Enter a new video title:<br />',
- '<input size="50" name="newVideoTitle" ',
- 'type="text" value="',
- oldVideoTitle,
- '"/><br />',
- 'Enter a new video description:<br />',
- '<textarea cols="50" name="newVideoDescription">',
- oldVideoDescription,
- '</textarea><br />',
- 'Select a new category: <select ',
- 'name="newVideoCategory">',
- '<option value="Autos">Autos & Vehicles</option>',
- '<option value="Music">Music</option>',
- '<option value="Animals">Pets & Animals</option>',
- '<option value="Sports">Sports</option>',
- '<option value="Travel">Travel & Events</option>',
- '<option value="Games">Gadgets & Games</option>',
- '<option value="Comedy">Comedy</option>',
- '<option value="People">People & Blogs</option>',
- '<option value="News">News & Politics</option>',
- '<option value="Entertainment">Entertainment</option>',
- '<option value="Education">Education</option>',
- '<option value="Howto">Howto & Style</option>',
- '<option value="Nonprofit">Nonprofit & Activism</option>',
- '<option value="Tech">Science & Technology</option>',
- '</select><br />',
- 'Enter some new tags to describe your video ',
- '<em>(separated by spaces)</em>:<br />',
- '<input name="newVideoTags" type="text" size="50" ',
- 'value="',
- oldVideoTags,
- '"/><br />',
- '<input name="videoId" type="hidden" value="',
- videoId,
- '" /><br />',
- '<input type="submit" value="go">',
- '</form>'].join('');
-
- document.getElementById(ytVideoApp.VIDEO_SEARCH_RESULTS_DIV).innerHTML = editMetaDataForm;
- }
- /**
- * Uses ytVideoApp.sendRequest to submit updated video meta-data.
- *
- * @param {String} newVideoTitle The new title of the video
- * @param {String} newVideoDescription The new description of the video
- * @param {String} newVideoCategory The new category of the video
- * @param {String} newVideoTags The new tags for the video (separated by white-space)
- * @param {String} videoId The id of the video to be edited
- */
- ytVideoApp.editMetaData = function(newVideoTitle, newVideoDescription, newVideoCategory, newVideoTags, videoId) {
- var filePath = 'operations.php';
- var params = 'operation=edit_meta_data' +
- '&newVideoTitle=' + newVideoTitle +
- '&newVideoDescription=' + newVideoDescription +
- '&newVideoCategory=' + newVideoCategory +
- '&newVideoTags=' + newVideoTags +
- '&videoId=' + videoId;
- ytVideoApp.sendRequest(filePath, params, ytVideoApp.VIDEO_SEARCH_RESULTS_DIV);
- };
- /**
- * Confirms whether user wants to delete a video.
- * @param {String} videoId The video Id to be deleted
- */
- ytVideoApp.confirmDeletion = function(videoId) {
- var answer = confirm('Do you really want to delete the video with id: ' + videoId + ' ?');
- if (answer) {
- ytVideoApp.prepareDeletion(videoId);
- }
- }
- /**
- * Uses ytVideoApp.sendRequest to request a video to be deleted.
- * @param {String} videoId The video Id to be deleted
- */
- ytVideoApp.prepareDeletion = function(videoId) {
- var filePath = 'operations.php';
- var params = 'operation=delete_video' +
- '&videoId=' + videoId;
- var table = document.getElementById('videoResultList');
- var indexOfRowToBeDeleted = -1;
- var tableRows = document.getElementsByTagName('TR');
- for (var i = 0, tableRow; tableRow = tableRows[i]; i++) {
- if (tableRow.id == videoId) {
- indexOfRowToBeDeleted = i;
- }
- }
- if (indexOfRowToBeDeleted > -1) {
- table.deleteRow(indexOfRowToBeDeleted);
- }
- ytVideoApp.sendRequest(filePath, params, ytVideoApp.VIDEO_SEARCH_RESULTS_DIV);
- }
- /**
- * Uses ytVideoApp.sendRequest to display a list of of YT videos.
- * @param {String} op The operation to perform to retrieve a feed
- * @param {Number} maxResults The maximum number of videos to list
- * @param {Number} startIndex The first video to include in the list
- * @param {String} searchTerm The search terms to pass to the specified feed
- */
- ytVideoApp.presentFeed = function(op, maxResults, startIndex, searchTerm){
- var params = 'operation=' + op +
- '&maxResults=' + maxResults +
- '&startIndex=' + startIndex +
- '&searchTerm=' + searchTerm;
- var filePath = 'operations.php';
- ytVideoApp.sendRequest(filePath, params, ytVideoApp.VIDEO_LIST_CONTAINER_DIV);
- };
- /**
- * Updates the variables used by the navigation buttons and the 'enabled'
- * status of the buttons based upon the current page number passed in.
- * @param {Number} page The current page number
- */
- ytVideoApp.updateNavigation = function(page) {
- ytVideoApp.nextPage = page + 1;
- ytVideoApp.previousPage = page - 1;
- document.getElementById(ytVideoApp.NEXT_PAGE_BUTTON).style.display = 'inline';
- document.getElementById(ytVideoApp.PREVIOUS_PAGE_BUTTON).style.display = 'inline';
- if (ytVideoApp.previousPage < 1) {
- document.getElementById(ytVideoApp.PREVIOUS_PAGE_BUTTON).disabled = true;
- } else {
- document.getElementById(ytVideoApp.PREVIOUS_PAGE_BUTTON).disabled = false;
- }
- document.getElementById(ytVideoApp.NEXT_PAGE_BUTTON).disabled = false;
- };
- /**
- * Hides the navigation.
- */
- ytVideoApp.hideNavigation = function() {
- document.getElementById(ytVideoApp.NAVIGATION_DIV).style.display = 'none';
- };
- /**
- * Update video results div
- */
- ytVideoApp.refreshSearchResults = function() {
- document.getElementById(ytVideoApp.VIDEO_SEARCH_RESULTS_DIV).innerHTML = '';
- }
- /**
- * Method called when the query type has been changed. Clears out the
- * value of the search term input box by default if one of the standard
- * feeds is selected. This is to improve usability, as many of the standard
- * feeds may not include results for even fairly popular search terms.
- * @param {String} op The operation to perform.
- * for querying all videos, or the name of one of the standard feeds.
- * @param {Node} searchTermInputElement The HTML input element for the input
- * element.
- */
- ytVideoApp.queryTypeChanged = function(op, searchTermInputElement) {
- if (op == 'search_username') {
- searchTermInputElement.value = '-- enter username --';
- } else if (op != 'search_all') {
- searchTermInputElement.value = '';
- }
- };
- /**
- * Create a basic HTML form to use for creating a new playlist.
- */
- ytVideoApp.prepareCreatePlaylistForm = function() {
- var newPlaylistForm = ['<br /><form id="addPlaylist" ',
- 'onsubmit="ytVideoApp.createNewPlaylist(this.newPlaylistTitle.value, ',
- 'this.newPlaylistDescription.value); ">',
- 'Enter a title for the new playlist:<br />',
- '<input size="50" name="newPlaylistTitle" type="text" /><br />',
- 'Enter a description:<br />',
- '<textarea cols="25" name="newPlaylistDescription" >',
- '</textarea><br />',
- '<input type="submit" value="go">',
- '</form>'].join('');
-
- document.getElementById(ytVideoApp.PLAYLIST_ADD_DIV).innerHTML = newPlaylistForm;
- }
- /**
- * Uses ytVideoApp.sendRequest to create a new playlist.
- *
- * @param {String} playlistTitle The title of the new playlist
- * @param {String} playlistDescription A description of the new playlist
- */
- ytVideoApp.createNewPlaylist = function(playlistTitle, playlistDescription) {
- var filePath = 'operations.php';
- var params = 'operation=create_playlist' +
- '&playlistTitle=' + playlistTitle +
- '&playlistDescription=' + playlistDescription;
- ytVideoApp.hideNavigation();
- ytVideoApp.sendRequest(filePath, params, ytVideoApp.VIDEO_SEARCH_RESULTS_DIV);
- }
- /**
- * Confirm user wants to delete a playlist
- *
- * @param {String} playlistTitle The title of the playlist to be deleted
- */
- ytVideoApp.confirmPlaylistDeletion = function(playlistTitle) {
- var answer = confirm('Do you really want to delete the playlist titled : ' +
- playlistTitle + ' ?');
- if (answer) {
- ytVideoApp.deletePlaylist(playlistTitle);
- }
- }
- /**
- * Uses ytVideoApp.sendRequest to delete a playlist.
- *
- * @param {String} playlistTitle The title of the new playlist
- */
- ytVideoApp.deletePlaylist = function(playlistTitle) {
- var filePath = 'operations.php';
- var params = 'operation=delete_playlist' +
- '&playlistTitle=' + playlistTitle;
- ytVideoApp.sendRequest(filePath, params, ytVideoApp.VIDEO_SEARCH_RESULTS_DIV);
- }
- /**
- * Create a basic HTML form to use for modifying a playlist.
- *
- * @param {String} oldPlaylistTitle The old title of the playlist
- * @param {String} oldPlaylistDescription The old description of the playlist
- */
- ytVideoApp.prepareUpdatePlaylistForm = function(oldPlaylistTitle, oldPlaylistDescription) {
- var playlistUpdateForm = ['<br /><form id="updatePlaylist" ',
- 'onsubmit="ytVideoApp.updatePlaylist(this.newPlaylistTitle.value, ',
- 'this.newPlaylistDescription.value, this.oldPlaylistTitle.value);">',
- 'Enter a title for the new playlist:<br />',
- '<input size="50" name="newPlaylistTitle" type="text" value="',
- oldPlaylistTitle,
- '"/><br />',
- 'Enter a description:<br />',
- '<textarea cols="25" name="newPlaylistDescription" >',
- oldPlaylistDescription,
- '</textarea><br />',
- '<input type="submit" value="go" />',
- '<input type="hidden" value="',
- oldPlaylistTitle,
- '" name="oldPlaylistTitle" />',
- '</form>'].join('');
-
- document.getElementById(ytVideoApp.VIDEO_SEARCH_RESULTS_DIV).innerHTML = playlistUpdateForm;
- }
- /**
- * Uses ytVideoApp.sendRequest to update a playlist.
- *
- * @param {String} newPlaylistTitle The new title of the playlist
- * @param {String} newPlaylistDescription A new description of the playlist
- */
- ytVideoApp.updatePlaylist = function(newPlaylistTitle, newPlaylistDescription, oldPlaylistTitle) {
- var filePath = 'operations.php';
- var params = 'operation=update_playlist' +
- '&newPlaylistTitle=' + newPlaylistTitle +
- '&newPlaylistDescription=' + newPlaylistDescription +
- '&oldPlaylistTitle=' + oldPlaylistTitle;
- ytVideoApp.sendRequest(filePath, params, ytVideoApp.VIDEO_LIST_CONTAINER_DIV);
- }
- /**
- * Uses ytVideoApp.sendRequest to retrieve a users playlist.
- *
- */
- ytVideoApp.retrievePlaylists = function() {
- var filePath = 'operations.php';
- var params = 'operation=retrieve_playlists';
- ytVideoApp.hideNavigation();
- ytVideoApp.sendRequest(filePath, params, ytVideoApp.VIDEO_LIST_CONTAINER_DIV);
- }
|