forked from WWBN/AVideo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvideoAddViewCount.json.php
executable file
·36 lines (33 loc) · 1.17 KB
/
videoAddViewCount.json.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
<?php
header('Content-Type: application/json');
global $global, $config;
if(!isset($global['systemRootPath'])){
require_once '../videos/configuration.php';
}
if (empty($_POST['id'])) {
die('{"error":"'.__("Permission denied").'"}');
}
require_once $global['systemRootPath'].'objects/video.php';
$obj = new Video("", "", $_POST['id']);
if(empty($obj)){
die("Object not found");
}
if(empty($_SESSION['addViewCount'])){
$_SESSION['addViewCount'] = array();
}
// the video count one new view after the amount of time of the video lenght
if((empty($_SESSION['addViewCount'][$_POST['id']]) || $_SESSION['addViewCount'][$_POST['id']] <= time())){
$resp = $obj->addView();
$seconds = parseDurationToSeconds($obj->getDuration());
$_SESSION['addViewCount'][$_POST['id']] = strtotime("+{$seconds} seconds");
}else if(!empty ($_POST['currentTime'])){
$resp = VideoStatistic::updateStatistic($obj->getId(), User::getId(), intval($_POST['currentTime']));
}else{
$resp = 0;
}
$count = $obj->getViews_count();
$obj2 = new stdClass();
$obj2->status = !empty($resp);
$obj2->count = $count;
$obj2->resp = $resp;
echo json_encode($obj2);