-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnewfilm.php
392 lines (314 loc) · 12.4 KB
/
newfilm.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
<?php
session_start();
if (!isset($_SESSION['id'])) {
header('Location: index.php');
} else {
include('header.php');
}
include('uploader.php');
$user_id = $_SESSION['id'];
?>
<div class="filmdisplay_box">
<h2>Link Your Video</h2>
</div>
<div class="filmdisplay_box">
<form id="new_project" method="POST" action="">
<input type="hidden" name="function" value="new_project">
<label for="title">Title</label>
<input type="text" name="title" id="title" data-validation="required" data-validation="length" data-validation-length="max250">
<label for="video_link">Video</label>
<input type="text" id='new_video_link' name="video_link" id="video_link" data-validation="youtube" data-validation="required" placeholder="Video link to Youtube OR Vimeo">
<input type="hidden" id="runtime" name="runtime">
<div class='display_video'>
<iframe id="player1" class="preview-video" width="100%" heigh="0"frameborder="0" webkitallowfullscreen="1" mozallowfullscreen="1" allowfullscreen="1"></iframe>
</div>
<label for="synopsis">Synopsis</label>
<input type="text" name="synopsis" id="synopsis" data-validation="required" data-validation="length" data-validation-length="max250"><br>
<label id="label_cover" for="cover_image">Cover Image: JPG AND PNG FILES ONLY! Max file size: 2MB</label>
<div class="cover_image">
<div id="upload" class="dropzone display_cover_image">
<div class="dz-default"></div>
</div>
<input type="hidden" name="cover_image" id="cover_image" value="">
<div class="display_cover_image actual_display">
<img>
</div>
</div>
<label class="collab_label">Contributors</label>
<table id="new_collaborator">
<thead>
<tr>
<td>First Name</td>
<td>Last Name</td>
<td>Role</td>
<td>Email</td>
</tr>
</thead>
<tr>
<td>
<input type="text" class="first_name" id="first_name-1" data-validation="required" name="collab[1][first_name]" placeholder="First Name">
</td>
<td>
<input type="text" class="last_name" id="last_name-1" data-validation="required" name="collab[1][last_name]" placeholder="Last Name">
</td>
<td>
<input type="text" class="role" id="role-1" data-validation="required" name="collab[1][role]" placeholder="Role">
</td>
<td>
<input type="text" class="email" id="email-1" data-validation="required" name="collab[1][email]" placeholder="Email">
</td>
<td>
<input type="button" id="remove" value="remove" name="collab[1][remove]" onclick="deleteRow(this)">
</td>
</tr>
</table>
<select id="published" name="published">
<option value="0">Save Draft</option>
<option value="1">Publish</option>
</select>
<!-- hidden fields-->
<input type="hidden" id="user_id" name="user_id" value="<?php echo $user_id; ?>"><br>
<input type="hidden" name="active" value="1"><br>
<input type="submit">
</form>
</div>
<script src="https://apis.google.com/js/client.js?onload=OnLoadCallback"></script>
<script src="https://f.vimeocdn.com/js/froogaloop2.min.js"></script>
<script>
var form = $('form#new_project');
$.validate({
form : form,
});
// dropzone function
Dropzone.autoDiscover = false;
$("#upload").dropzone({
acceptedFiles: "image/jpeg, image/png",
url: "editfilm.php",
maxFiles: 1, // Number of files at a time
maxFilesize: 2, //in MB
addRemoveLinks: true,
maxfilesexceeded: function(file) {
alert('You have uploaded more than 1 Image. Only the first file will be uploaded!');
},
success: function (file, response) {
if (file.type == "image/jpeg" || file.type == "image/png") {
var file_name = file['name'];
file.previewElement.classList.add("dz-success");
console.log('Successfully uploaded :' + file_name);
file_name = file_name.replace(/\s+/g, '_');
$('input#cover_image').val(file_name);
$('.display_cover_image > img').attr("src", 'uploads/'+<?php echo $user_id; ?>+'/'+file_name);
console.log($('#cover_image').val());
} else {
alert('Sorry, you need to upload an image file! JPG AND PNG FILES ONLY! MAX FILE SIZE: 2MB')
}
},
error: function (file, response) {
file.previewElement.classList.add("dz-error");
console.log('error')
alert('Sorry, you need to upload an image file! JPG AND PNG FILES ONLY! MAX FILE SIZE: 2MB')
this.removeFile(file)
},
init: function() {
this.on("addedfile", function() {
if (this.files[1]!=null){
this.removeFile(this.files[0]);
}
});
}
});
// converting video time in seconds to hh:mm:ss
function runtimeformat(seconds) {
seconds = Math.round(seconds)
//get time in hours and round down
var hours = Math.floor(seconds / 3600);
var minutes = Math.floor((seconds - (hours * 3600)) / 60);
var seconds = seconds - ((hours * 3600) + (minutes * 60));
var time = hours + ': '+ minutes + ':' + seconds;
return time;
}
function appendResults(text) {
var runtime = String(text);
$('input#runtime').val(runtime);
console.log(runtime);
console.log($('input#runtime').val());
}
// load video after user inputs link
$("#new_video_link").on('input', function () {
$('#player1').attr('height', '540');
var videolink = $('#new_video_link').val();
var str = "youtube";
var str2 = "vimeo";
// if video was on youtube
if(videolink.indexOf(str) > -1){
var videolink1 = videolink.replace("watch?v=", "embed/");
var values = videolink1.split('&feature');
var videolinkiframe = values[0];
console.log(videolinkiframe);
//get youtube id
var videoid = videolink.match(/(?:youtube\.com\/(?:[^\/]+\/.+\/|(?:v|e(?:mbed)?)\/|.*[?&]v=)|youtu\.be\/)([^"&?\/ ]{11})/i)[1];
// start youtube api
gapi.client.setApiKey('AIzaSyAD94F0GwBoXnncL0ck2bZdSeZf6RDW_3s');
gapi.client.load('youtube', 'v3').then(makeRequest);
//convert youtube time to seconds
function convertosecs(duration){
var a = duration.match(/\d+/g);
if (duration.indexOf('M') >= 0 && duration.indexOf('H') == -1 && duration.indexOf('S') == -1) {
a = [0, a[0], 0];
}
if (duration.indexOf('H') >= 0 && duration.indexOf('M') == -1) {
a = [a[0], 0, a[1]];
}
if (duration.indexOf('H') >= 0 && duration.indexOf('M') == -1 && duration.indexOf('S') == -1) {
a = [a[0], 0, 0];
}
duration = 0;
if (a.length == 3) {
duration = duration + parseInt(a[0]) * 3600;
duration = duration + parseInt(a[1]) * 60;
duration = duration + parseInt(a[2]);
}
if (a.length == 2) {
duration = duration + parseInt(a[0]) * 60;
duration = duration + parseInt(a[1]);
}
if (a.length == 1) {
duration = duration + parseInt(a[0]);
}
return duration
}
// actually make api request
function makeRequest() {
var request = gapi.client.youtube.videos.list({
part: "contentDetails",
id: videoid
});
console.log('request made');
request.then(function(response){
var duration = response.result.items[0].contentDetails.duration;
duration = convertosecs(duration);
duration = runtimeformat(duration);
appendResults(duration);
});
}
}
if(videolink.indexOf(str2) > -1){
// if video was on vimeo
var videolinkiframe = videolink.replace("//", "//player.");
var videolinkiframe = videolinkiframe.replace(".com", ".com/video");
var videolinkiframe = videolinkiframe.concat("?api=1&player_id=player1");
//add vimeo api
var iframe = $('#player1')[0];
var player = $f(iframe);
// When the player is ready, add listeners for pause, finish, and playProgress
player.addEvent('ready', function() {
getDuration();
});
function getDuration() {
player.api('getDuration', function(duration) {
duration = runtimeformat(duration);
appendResults(duration);
});
}
}
else {
var videolinkiframe = videolinkiframe.concat("");
}
$(".preview-video").attr("src", videolinkiframe);
$('#new_video_link').val(videolinkiframe);
});
// remove collaborators
function deleteRow(btn) {
var rowcount = $('#new_collaborator tr').length;
var rowcurrent = rowcount -1;
if(rowcurrent > 1){
var row = btn.parentNode.parentNode;
row.parentNode.removeChild(row);
}
}
jQuery.fn.preventDoubleSubmission = function() {
$(this).on('submit',function(e){
var form = $(this);
if (form.data('submitted') === true) {
// Previously submitted - don't submit again
e.preventDefault();
} else {
// Mark it so that the next submit can be ignored
form.data('submitted', true);
}
});
// Keep chainability
return this;
};
function submit_form() {
/*
var mega_array = [];
$('.first_name').each(function() {
var tempArray = [];
var rowId = $(this).attr('id').split('-')[1];
tempArray.first_name = $('#first_name-'+rowId).val();
tempArray.last_name = $('#last_name-'+rowId).val();
tempArray.role = $('#role-'+rowId).val();
tempArray.email = $('#email-'+rowId).val();
mega_array.push(tempArray);
});
*/
$.ajax({
type: "POST",
url: "overlord.php",
data: form.serialize(),
success:function(res){
var published = $('select#published').val();
if(published == 0) {
var location = "profile.php";
} else {
var location = "displayfilm.php?id="+res;
}
window.location=location;
},
error:function(res){
console.log(res);
}
});
}
// do all the things
$(document).ready(function(){
var form = $('form#new_project');
form.on('submit', function(e){
e.preventDefault();
$('form').preventDoubleSubmission();
if(($("#new_collaborator > tbody > tr:last > td > input.first_name").val() == '') && ($("#new_collaborator > tbody > tr:last > td > input.last_name").val() == '') && ($("#new_collaborator > tbody > tr:last > td > input.role").val() == '') && ($("#new_collaborator > tbody > tr:last > td > input.email").val() == '') ) {
$('tr:last', this).remove();
}
submit_form();
})
// Increase collaborators as user inputs info
$(document).on('blur',"#new_collaborator > tbody > tr:last > td > input.first_name", function(){
console.log('blur');
if($("#new_collaborator > tbody > tr:last > td > input.first_name").val() != ''){
// clone last row of table and empty its values
$('#new_collaborator > tbody > tr:last').clone(true).insertAfter('#new_collaborator > tbody > tr:last');
$('#new_collaborator > tbody > tr:last > td > input.first_name').val('');
$('#new_collaborator > tbody > tr:last > td > input.last_name').val('');
$('#new_collaborator > tbody > tr:last > td > input.role').val('');
$('#new_collaborator > tbody > tr:last > td > input.email').val('');
// get number of rows in table
var rowcount = $('#new_collaborator tr').length;
var rowcurrent = rowcount -1;
console.log(rowcurrent);
// name each field in [collab][current row number]['xxxxx'] format
$('#new_collaborator > tbody > tr:last > td > input.first_name').attr('name', 'collab[' + rowcurrent + '][first_name]');
$('#new_collaborator > tbody > tr:last > td > input.last_name').attr('name', 'collab[' + rowcurrent + '][last_name]');
$('#new_collaborator > tbody > tr:last > td > input.role').attr('name', 'collab[' + rowcurrent + '][role]');
$('#new_collaborator > tbody > tr:last > td > input.email').attr('name', 'collab[' + rowcurrent + '][email]');
$('#new_collaborator > tbody > tr:last > td > input#remove').attr('name', 'collab[' + rowcurrent + '][remove]');
// edit id for each row
$('#new_collaborator > tbody > tr:last > td > input.first_name').attr('id', 'first_name-' + rowcurrent);
$('#new_collaborator > tbody > tr:last > td > input.last_name').attr('id', 'last_name-' + rowcurrent);
$('#new_collaborator > tbody > tr:last > td > input.role').attr('id', 'role-' + rowcurrent);
$('#new_collaborator > tbody > tr:last > td > input.email').attr('id', 'email-' + rowcurrent);
}
});
});
</script>
<?php include('footer.php') ?>