/
videoupload.php
213 lines (187 loc) · 10.2 KB
/
videoupload.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
<?php
require_once 'core/init.php';
$count = 0;
$validations = "";
$user = new User();
$link = $user->data()->username;
if (!$user->isLoggedIn()) {
Redirect::to("/login");
}
if ($user->data()->group == 2) {
Redirect::to('/');
}
$video = new Video();
if(isset($_POST['submit'])){
//Connection
include_once 'core/db_connection.php';
//Variables holding the image info
$title = $_POST['title'];
$description = $_POST['description'];
$url = $_POST['url'];
$web = $_POST['web'];
$category = $_POST['category'];
$tags = $_POST['tags'];
$user_id = $_POST['user_id'];
$username = $_POST['username'];
$embeded = "";
$source = "";
$user = $_POST['user'];
$validate = new Validate();
$validation = $validate->check($_POST, array(
'title' => array(
'min' => 3,
'max' => 30
),
'description' => array(
'min' => 5,
'max' => 100,
)
));
//validate link is from youtube or vimeo
if (strpos($url, 'youtube.com/watch?v') !== false) {
$source = 'youtube';
if (($pos = strpos($url, "=")) !== FALSE){
$embeded = substr($url, $pos+1); }
}
else if (strpos($url, 'vimeo.com/') !== false) {
$source = 'vimeo';
if (($pos = strpos($url, "m/")) !== FALSE){
$embeded = substr($url, $pos+2); }
}
else{
$validations .= "- url must be from Youtube (ex: https://www.youtube.com/watch?v=hoCmY0uGneY) or Vimeo (ex: https://vimeo.com/55455061)<br>";
$count++;
}
//validate that the web licenses is an integer
if(!intval($web)){
$validations .= "- web license value must be a number<br>";
$count++;
}
if ($validation->passed() && $validations == "") {
//Store image into datavase. If query does not execute correctly redirect to error page
$lastid = $video->create( array(
'id' => '',
'user_id' => $user_id,
'user' => $user,
'username' => $username,
'title' => $title,
'description' => $description,
'url' => $url,
'source' => $source,
'web' => $web,
'embeded' => $embeded,
'category' => $category,
'tags' => $tags));
header("location: /video/show/" . $lastid);
}
else {
foreach ($validation->errors() as $error) {
$count++;
$validations .= "- {$error} <br>";
}
}
}
?>
<!doctype html>
<head>
<title>Imaguana | Upload Video</title>
<!-- CSS, Meta, Ajax, etc. -->
<?php include 'view/head.php' ?>
</head>
<body>
<!-- Navigation Bar -->
<?php include 'view/nav-bar.php'; ?>
<!-- Page Content Section -->
<div style="margin-top: -50px;"class="container ws-page-container">
<div class="row">
<div class="row">
<div class="ws-works-title clearfix">
<div class="col-sm-12">
<h3>Upload Video: <?php echo $user->data()->username; ?></h3>
<div class="ws-separator"></div>
</div>
<?php if ($count > 0){echo "<p style='text-align: center; color: red'>" . $count . " error(s)</p><p style='text-align: center; color: red'>" . $validations . "</p><br>";}?>
</div>
<div class="ws-contact-page">
<form method="POST" enctype="multipart/form-data" class="form-horizontal ws-contact-form">
<h5 style="text-align: center; color: black;">All fields marked with * are required</h5>
<div class="ws-contact-info">
<h2>Title<span>*</span></h2>
<textarea class="form-control" required="true" name="title" id="title" rows="1" cols="100" placeholder="Enter a title for your image" style="resize:none;"><?php echo Input::get('title'); ?></textarea><br/>
<h2>Description<span>*</span></h2>
<textarea class="form-control" name="description" required="true" id="description" rows="3" cols="100" placeholder="Add some descriptive text for your image" style="resize:none;"><?php echo Input::get('description'); ?></textarea><br/>
<h2>URL (Youtube or Vimeo)<span>*</span></h2>
<textarea class="form-control" required="true" name="url" id="url" rows="1" cols="100" placeholder="ex: https://www.youtube.com/watch?v=KJ38jTQcO1k" style="resize:none;"><?php echo Input::get('url'); ?></textarea><br/><br/>
<h2>License<span>*</span>
<a data-toggle="modal" data-target="#License" >
<img style='height:16px; width:16px;' alt='assets/img/help.gif' src='assets/img/help.gif' >
</a>
<table style="margin-top: 10px;">
<tr>
<td ><label class="control-label">Web* $</label></td>
<td style="padding-right: 20px"><textarea name="web" id="web" required="true" class="form-control-upload" rows="1" cols="10" placeholder="20" style="resize:none;"><?php echo Input::get('web'); ?></textarea><p class="pull-right"></p></td>
</tr>
</table>
</h2><br>
<h2>Category*
<select for="category" name="category" id="category" >
<option value="Animal" <?php if(Input::get('category') == "Animal"){echo "selected";}?>>Animal</option>
<option value="Beauty" <?php if(Input::get('category') == "Beauty"){echo "selected";}?>>Beauty</option>
<option value="City" <?php if(Input::get('category') == "City"){echo "selected";}?>>City</option>
<option value="Education"<?php if(Input::get('category') == "Education"){echo "selected";}?>>Education</option>
<option value="Fashion" <?php if(Input::get('category') == "Fashion"){echo "selected";}?>>Fashion</option>
<option value="Food" <?php if(Input::get('category') == "Food"){echo "selected";}?>>Food</option>
<option value="Landmark" <?php if(Input::get('category') == "Landmark"){echo "selected";}?>>Landmark</option>
<option value="Nature" <?php if(Input::get('category') == "Nature"){echo "selected";}?>>Nature</option>
<option value="Science" <?php if(Input::get('category') == "Science"){echo "selected";}?>>Science</option>
<option value="Space" <?php if(Input::get('category') == "Space"){echo "selected";}?>>Space</option>
<option value="Sport" <?php if(Input::get('category') == "Sport"){echo "selected";}?>>Sport</option>
<option value="Vintage" <?php if(Input::get('category') == "Vintage"){echo "selected";}?>>Vintage</option>
</select>
</h2><br/>
<h2>Search Keywords (Tags)</h2>
<textarea name="tags" id="tags" rows="3" cols="100" placeholder="Input keywords that will help people search for your image. Examples: Categories, Colors, Style, etc." style="resize:none;"><?php echo Input::get('tags'); ?></textarea>
<div class="col-sm-11">
<!-- Button -->
<input class="btn ws-btn-fullwidth" style="margin-top: 15px; width: 300px;" type="submit" value="Upload" name="submit">
<a href="user/<?php echo $user->data()->username; ?>" class="btn ws-btn-black" style="color: white; margin-top: 15px; width: 250px" >Cancel</a>
</div>
<input type="hidden" name="user_id" id="user_id" value=" <?php echo $user->data()->id; ?>">
<input type="hidden" name="username" id="username" value=" <?php echo $user->data()->username; ?>">
<input type="hidden" name="user" id="user" value="<?php echo $user->data()->name; ?>">
</div>
</form>
</div>
</div>
</div>
</div>
<!-- End Page Content Section -->
<!-- DEFINING WEB, Print, and Unlimited License -->
<div id="License" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">X</button>
<h3 class="modal-title">Types of Licenses</h3>
</div>
<div class="modal-body">
<h3>Web</h3>
<p>You will receive a URL that you can use on your website to display the image.</p>
<h3>Print</h3>
<p>You will receive a downloadable file of the image.</p>
<h3>Unlimited</h3>
<p>You will receive the URL and the downloadable file of the image.</p>
</div>
<div class="modal-footer">
<a class="btn ws-btn-fullwidth" style="color: white; margin-top: 15px; width: 250px" data-dismiss="modal">Close</a>
</div>
</div>
</div>
</div>
<!-- Foot Bar -->
<?php include 'view/foot-bar.php'; ?>
<!-- Scripts -->
<?php include 'view/scripts.php' ?>
</body>
</html>