-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
564 lines (532 loc) · 14.4 KB
/
functions.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
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
<?php
date_default_timezone_set('America/New_York');
require_once 'constants.php';
function GetuserIDfromEmail($email)
{
$query =" Select ID from usersinfo where Email=\"".$email."\"";
return ex_query1RowAns($query);
}
function login($User_ID,$Username)
{
session_start();
$_SESSION[SESSIONUSERID]=$User_ID;
$_SESSION[SESSIONUSERNAME]=$Username;
}
function loggout()
{
//removing all instance of session once logged out.
session_start();
$_SESSION = array(); //empty session
if(isset($_COOKIE[session_name()]))
{
setcookie(session_name(),'',time()-450000,'/');
}
session_destroy();
redirect_to('login.php?logout=2');
}
function isSitelogin()
{
if(isset($_SESSION[SESSIONUSERID]) && isset($_SESSION[SESSIONUSERNAME]))
{
return true;
}
else {
return false;
}
}
function videoExists($vidHash)
{
$query = "select 1 from video where hash='$vidHash'";
if(ex_query1RowAns($query)==1)
{
return true;
}
else {
return false;
}
}
function belongs_to_person($userID,$videoID)
{
$query ="Select 1 from video where hash='{$videoID}' and UserID=".$userID;
if(ex_query1RowAns($query)==1)
{
return true;
}
else {
return false;
}
}
function Cat_Pages($query,$phpFile,$Category)
{
$arrayName = array();
$count =0;
$results= ex_query($query);
while($row = mysql_fetch_array($results))
{
//var_dump($row);
$arrayName[$count] = $row[0];
$count++;
}
// Show pages links
$divider =7;
$NumPages =ceil((count($arrayName)/$divider));
echo "<div class=\"grid_12\">\n";
for ($i=0; $i < $NumPages; $i++)
{
//create the links
// I am changing it to one string and echo'ing the string
// has the have the page for the limit
$VidsPerPage ="VidNum=".$divider;
$string .="<a href=\"";
$string .=$phpFile."?";
$string .= "Category=".$Category;
$string .='&Page=';
$string .= ($i+1);
$string .=("&".$VidsPerPage."\">");
$string .= ($i+1 ."</a>\n");
echo $string;
}
echo "</div>\n";
}
function GenMultipleThumb($results)
{
$count=1;
//echo"<div id=\"mainPage\" class=\"grid_3\" >";
while($row = mysql_fetch_array($results))
{
if($count<7)
{
GEnerateImageThumb($row[0]);
}
$count++;
}
//echo ("</div>");
return $count;
}
function LikeVideo($UserID, $videoID)
{
$query = "insert into liked(videoID,UserID,Liked) values( '{$videoID}', '{$UserID}', 1)";
ex_query($query);
echo "$query";
}
function unLikeVideo($UserID, $videoID)
{
$query = "delete from liked where UserID='{$UserID}' and videoID='{$videoID}',1)";
ex_query($query);
}
function reportVideo($UserID, $videoID)
{
$query = "insert into reportedvideo(UserID,VideoID,Reported) Values('{$UserID}','{$videoID}',1)";
ex_query($query);
}
function unReportVideo($UserID, $videoID)
{
$query = "delete from reportedvideo where UserID='{$UserID}' and videoID='{$videoID}',1)";
ex_query($query);
}
function liked($UserID , $Videoid)
{
$query = "Select 1 from liked where UserID ='{$UserID}' and videoid='{$Videoid}'";
if(ex_query1RowAns($query) == 1)
{
return true;
}
else
{
return false;
}
}
function reported($UserID , $Videoid)
{
$query = "Select 1 from reportedvideo where UserID ='{$UserID}' and videoid='{$Videoid}'";
if(ex_query1RowAns($query) == 1)
{
return true;
}
else
{
return false;
}
}
function UpdateHistory($UserID,$hash,$DateString)
{
//check to see if exists if it does then upodate the date otherwise insert
// i have to add a check to see if this has been seen if so then it should just edit the date
$query ="Select 1 from history where USERID=".$UserID." and VideoID='".$hash."'";
if(ex_query1RowAns($query)==1)
{
//Then Update the date
$query ="Update history set Date ='{$DateString}' where USERID=".$UserID." and VideoID='".$hash."'";
ex_query($query);
}
else {
$query ="Insert into history(USERID,VideoID,Date) Values('{$UserID}','".$hash."','".to_mysqlDate(time())."')";
ex_query($query);
}
}
function showPages($Page,$VidNum,$query)
{
//i want to show the next list of videos but i also want to make sure that there if there is another page then that one is highlighted so they
// wouldnt clik it again
//first i want to show every video based on the page
//if page was equal to 3 then i would show videos from 15 -22
//if page was equal to 1 then i would show 0-6
//if page was equal to 2 then i would show 7-13
//if page was equal to 3 then i would show 14-20
// Query for the pages
//Limit is Starting point and for how long to keep going
$limit = (($Page* $VidNum)-1);
$selectQuery =$query." LIMIT ".($limit - ($VidNum -1)) .",". ($VidNum -1) ;
$result =ex_query($selectQuery);
GenMultipleThumb($result);
//
//Now to show the number of pages again
}
function Pages_search($query,$phpFile,$search)
{
$arrayName = array();
$count =0;
$results= ex_query($query);
while($row = mysql_fetch_array($results))
{
//var_dump($row);
$arrayName[$count] = $row[0];
$count++;
}
// Show pages links
$divider =7;
$NumPages =ceil((count($arrayName)/$divider));
echo "<div class=\"grid_12\">\n";
for ($i=0; $i < $NumPages; $i++)
{
//create the links
// has the have the page for the limit
$VidsPerPage ="VidNum=".$divider;
$string .= ("<a href=\"");
$string .= ($phpFile."?");
$string .=('Page=');
$string .= ($i+1);
$string .= "&Search=".$search;
$string .=("&".$VidsPerPage."\">");
$string .= ($i+1 ."</a>\n");
echo ($string);
}
echo "</div>\n";
}
function Pages($query,$phpFile)
{
$arrayName = array();
$count =0;
$results= ex_query($query);
while($row = mysql_fetch_array($results))
{
//var_dump($row);
$arrayName[$count] = $row[0];
$count++;
}
// Show pages links
$divider =7;
$NumPages =ceil((count($arrayName)/$divider));
echo "<div class=\"grid_12\">\n";
for ($i=0; $i < $NumPages; $i++)
{
//create the links
// has the have the page for the limit
$VidsPerPage ="VidNum=".$divider;
$string .= ("<a href=\"");
$string .= ($phpFile."?");
$string .=('Page=');
$string .= ($i+1);
$string .=("&".$VidsPerPage."\">");
$string .= ($i+1 ."</a>\n");
echo ($string);
}
echo "</div>\n";
}
function GetDescofUser($userid)
{
return ex_query1RowAns("Select info from usersinfo where ID=".$userid);
}
function to_mysqlDate($time)
{
//Format from my sql is y-m-d h:m:s
// format 2012-05-21 18:54:49
$mysqldate =strftime("%Y-%m-%d %H:%M:%S",$time);
return $mysqldate;
}
function addToFavorites($User_ID,$VideoID)
{
$query ="Insert into favorites(USERID,VideoID) Values('{$User_ID}','{$VideoID}')";
ex_query($query);
}
function getUsername($user_ID)
{
return ex_query1RowAns("Select UserName from users where id=".check_input($user_ID));
}
function removeFromFavorites($User_ID,$VideoID)
{
$query= "Delete from favorites where UserID ='{$User_ID}' and VideoID= '{$VideoID}'";
ex_query($query);
echo "$query";
}
function GEnerateImageThumb($vidID)
{
$results=ex_query("Select * from video where id ='".$vidID."'");
$row = mysql_fetch_array($results);
if(!empty($row[0]))
{
echo("<div class=\"grid_3 VideoThumb\" >\n");
echo("<a href=\"view.php?videoID=".$row['Hash']."\">\n");
echo("<h1>".substr($row['VideoName'], 0,12)."...</h1>\n");
echo("<br />\n");
echo("<img alt=\"".substr($row['VideoName'], 0,12)."\" src=\"".Image2Thumb($row['videoImage'])."\"/>\n");
//echo("<img src=\"".Image2Thumb($row[4])."\" />");
echo("<br />\n");
$desc = ex_query1RowAns("Select txtdesc from videodesc where vidid =".$row['ID']);
echo("<p>".substr($desc, 0,90)."...</p>\n");
echo("</a>\n");
echo("</div>\n");
}
else {
// echo "not in Video Library";
}
}
function GEnerateImageThumbHeader($vidID)
{
$results=ex_query("Select * from video where id ='".$vidID."'");
$row = mysql_fetch_array($results);
if(!empty($row[0]))
{
echo("<div class=\"grid_2 VideoThumbHeader\"> \n");
echo("<a href=\"view.php?videoID=".$row['Hash']."\">\n");
echo("<h1>".substr($row['VideoName'], 0,12)."...</h1>\n");
echo("<img title=\"".$row['VideoName']."\" src=\"".Image2Thumb($row['videoImage'])."\"/>\n");
//echo("<img src=\"".Image2Thumb($row[4])."\" />");
$desc = ex_query1RowAns("Select txtdesc from videodesc where vidid =".$row['ID']);
// echo("<p>".substr($desc, 0,10)."...</p>\n");
echo("</a>\n");
echo("</div>\n");
}
else {
// echo "not in Video Library";
}
}
function redirect_to($location =NULL)
{
if($location!=NULL)
{
header("location:{$location}");
}
else{
header("location: index.php");
}
}
function generateImage($filepath,$thumbnailPath)
{
$ffmpeg="ffmpeg";
$command =$ffmpeg." -i ".$filepath." -vcodec mjpeg -vframes 10 -an ".$thumbnailPath;
exec($command);
}
function NumberofComments($userid)
{
return ex_query1RowAns("Select count(*) from comments where userid='{$userid}'");
}
function Image2Thumb($filename)
{
return "includes/image.php?fname=".urlencode($filename);
}
function check_input($fname)
{
if(get_magic_quotes_gpc())
{
$fname = stripcslashes($fname);
}
if(is_numeric($fname))
{
$fname = "'".mysql_real_escape_string($fname)."'";
}
return $fname;
}
function ex_query($query)
{
$results = mysql_query($query);
if (!$results)
{
die($query."<br/>Database has failed :" . mysql_error());
}
return $results;
}
function ex_query1Row($query)
{
$results = mysql_query($query);
if (!$results)
{
die($query."<br/>Database has failed :" . mysql_error());
}
$row = mysql_fetch_array($results);
return $row;
}
function ex_query1RowAns($query)
{
$results = mysql_query($query);
if (!$results)
{
die($query."<br/>Database has failed :" . mysql_error());
}
$row = mysql_fetch_array($results);
return $row[0];
}
function generateHash()
{
$arhash = str_split("ABCDEFGHIKJLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyz");
shuffle($arhash);
$arhash = array_slice($arhash, 0, rand(6, 15));
$hash = implode("", $arhash);
return $hash;
}
function genFBState()
{
$arhash = str_split("ABCDEFGHIKJLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyz");
shuffle($arhash);
$arhash = array_slice($arhash, 0, rand(10, 25));
$hash = implode("", $arhash);
return $hash;
}
function genUhash()
{
$hash="";
$toggle="run";
while($toggle == "run")
{
$hash = bol();
if ($hash != "false")
{
$toggle = "false";
}
}
return $hash;
}
function bol()
{
$genhash = generateHash();
if (check("video","Hash","".$genhash.""))
{
return $genhash;
}
else{
return "false";
}
}
function check($table,$col,$colVaue)
{
$fname = "SELECT 1 FROM ".$table." where ".$col." = \"" . $colVaue."\"";
$results = ex_query($fname);
$row = mysql_fetch_array($results);
if ($row[0] == "1")
{
return false;
} else
{
return true;
}
}
Function Favorited($userid,$videoID)
{
$query = "select 1 from favorites where userid={$userid} and VideoID='{$videoID}'";
$fav = ex_query1RowAns($query);
if($fav==1)
{
return true;
}
else{return false;}
}
function GetVideoID($hash)
{
$q="Select ID from video where Hash='{$hash}'";
return ex_query1RowAns($q);
}
function getnumVideosUploaded($userID)
{
return ex_query1RowAns("Select count(*) from video where userid=".check_input($userID));
}
function getnumVideosWatched($userID)
{
return ex_query1RowAns("Select count(*) from history where userid=".check_input($userID));
}
function getUploadSize($userid)
{
$query ="Select UploadLimit from usersinfo where id ={$userid}";
return ex_query1RowAns($query);
}
/**
Validate an email address.
Provide email address (raw input)
Returns true if the email address has the email
address format and the domain exists.
*/
function validEmail($email)
{
$isValid = true;
$atIndex = strrpos($email, "@");
if (is_bool($atIndex) && !$atIndex)
{
$isValid = false;
}
else
{
$domain = substr($email, $atIndex+1);
$local = substr($email, 0, $atIndex);
$localLen = strlen($local);
$domainLen = strlen($domain);
if ($localLen < 1 || $localLen > 64)
{
// local part length exceeded
$isValid = false;
}
else if ($domainLen < 1 || $domainLen > 255)
{
// domain part length exceeded
$isValid = false;
}
else if ($local[0] == '.' || $local[$localLen-1] == '.')
{
// local part starts or ends with '.'
$isValid = false;
}
else if (preg_match('/\\.\\./', $local))
{
// local part has two consecutive dots
$isValid = false;
}
else if (!preg_match('/^[A-Za-z0-9\\-\\.]+$/', $domain))
{
// character not valid in domain part
$isValid = false;
}
else if (preg_match('/\\.\\./', $domain))
{
// domain part has two consecutive dots
$isValid = false;
}
else if
(!preg_match('/^(\\\\.|[A-Za-z0-9!#%&`_=\\/$\'*+?^{}|~.-])+$/',
str_replace("\\\\","",$local)))
{
// character not valid in local part unless
// local part is quoted
if (!preg_match('/^"(\\\\"|[^"])+"$/',
str_replace("\\\\","",$local)))
{
$isValid = false;
}
}
if ($isValid && !(checkdnsrr($domain,"MX") ||
↪checkdnsrr($domain,"A")))
{
// domain not found in DNS
$isValid = false;
}
}
return $isValid;
}
?>