forked from WWBN/AVideo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvideoAddViewCount.json.php
51 lines (45 loc) · 1.56 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?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();
}
$seconds = parseDurationToSeconds($obj->getDuration());
if (!empty($seconds)) {
$percent = (intval($_POST['currentTime']) / $seconds) * 100;
$percentOptions = array(25,50,75,100);
foreach ($percentOptions as $value) {
if ($percent >= $value) {
if (empty($_SESSION['addViewCount'][$_POST['id']][$value]) && !empty($_POST['currentTime'])) {
if ($obj->addViewPercent($value)) {
$_SESSION['addViewCount'][$_POST['id']][$value] = 1;
}
}
}
}
}
if (empty($_SESSION['addViewCount'][$_POST['id']]['time'])) {
$resp = $obj->addView();
$_SESSION['addViewCount'][$_POST['id']]['time'] = 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);