Skip to content

Commit 04d0e5e

Browse files
https://github.com/WWBN/AVideo/issues/5503
1 parent b8beee3 commit 04d0e5e

File tree

2 files changed

+39
-14
lines changed

2 files changed

+39
-14
lines changed

objects/videoAddViewCount.json.php

+11-9
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@
55
require_once '../videos/configuration.php';
66
}
77

8+
_error_log('Add view '. json_encode($_REQUEST));
9+
810
if(!empty($_GET['SESSID'])){
911
@session_write_close();
1012
session_id($_GET['PHPSESSID']);
1113
_session_start();
1214
}
1315

14-
if (empty($_POST['id'])) {
16+
if (empty($_REQUEST['id'])) {
1517
die('{"error":"' . __("Permission denied") . '"}');
1618
}
1719
if (empty($_COOKIE[$global['session_name']])) {
@@ -21,7 +23,7 @@
2123
die('{"error":"isIframeInDifferentDomain"}');
2224
}
2325
require_once $global['systemRootPath'] . 'objects/video.php';
24-
$obj = new Video("", "", $_POST['id']);
26+
$obj = new Video("", "", $_REQUEST['id']);
2527
if (empty($obj)) {
2628
die("Object not found");
2729
}
@@ -33,25 +35,25 @@
3335
$seconds = parseDurationToSeconds($obj->getDuration());
3436

3537
if (!empty($seconds)) {
36-
$percent = (intval($_POST['currentTime']) / $seconds) * 100;
38+
$percent = (intval($_REQUEST['currentTime']) / $seconds) * 100;
3739
$percentOptions = array(25,50,75,100);
3840
foreach ($percentOptions as $value) {
3941
if ($percent >= $value) {
40-
if (empty($_SESSION['addViewCount'][$_POST['id']][$value]) && !empty($_POST['currentTime'])) {
42+
if (empty($_SESSION['addViewCount'][$_REQUEST['id']][$value]) && !empty($_REQUEST['currentTime'])) {
4143
if ($obj->addViewPercent($value)) {
4244
_session_start();
43-
$_SESSION['addViewCount'][$_POST['id']][$value] = 1;
45+
$_SESSION['addViewCount'][$_REQUEST['id']][$value] = 1;
4446
}
4547
}
4648
}
4749
}
4850
}
49-
if (empty($_SESSION['addViewCount'][$_POST['id']]['time'])) {
51+
if (empty($_SESSION['addViewCount'][$_REQUEST['id']]['time'])) {
5052
$resp = $obj->addView();
5153
_session_start();
52-
$_SESSION['addViewCount'][$_POST['id']]['time'] = strtotime("+{$seconds} seconds");
53-
} elseif (!empty($_POST['currentTime'])) {
54-
$resp = VideoStatistic::updateStatistic($obj->getId(), User::getId(), intval($_POST['currentTime']));
54+
$_SESSION['addViewCount'][$_REQUEST['id']]['time'] = strtotime("+{$seconds} seconds");
55+
} elseif (!empty($_REQUEST['currentTime'])) {
56+
$resp = VideoStatistic::updateStatistic($obj->getId(), User::getId(), intval($_REQUEST['currentTime']));
5557
} else {
5658
$resp = 0;
5759
}

view/js/script.js

+28-5
Original file line numberDiff line numberDiff line change
@@ -422,21 +422,39 @@ function isMobile() {
422422

423423
var last_videos_id = 0;
424424
var last_currentTime = -1;
425+
var videoViewAdded = false;
425426
function addView(videos_id, currentTime) {
426427
if (last_videos_id == videos_id && last_currentTime == currentTime) {
427428
return false;
428429
}
429430
if (currentTime > 5 && currentTime % 30 !== 0) { // only update each 30 seconds
430431
return false;
431432
}
433+
434+
if (videoViewAdded) {
435+
return false;
436+
}
437+
438+
videoViewAdded = true;
439+
432440
last_videos_id = videos_id;
433441
last_currentTime = currentTime;
434442
_addView(videos_id, currentTime);
435443
}
436444

445+
function addViewBeacon() {
446+
if (typeof player === 'object' && typeof mediaId !== 'undefined') {
447+
var url = webSiteRootURL + 'objects/videoAddViewCount.json.php?PHPSESSID=' + PHPSESSID;
448+
url = addGetParam(url, 'id', mediaId);
449+
url = addGetParam(url, 'currentTime', player.currentTime());
450+
var beacon = new Image();
451+
beacon.src = url;
452+
}
453+
}
454+
437455
function _addView(videos_id, currentTime) {
438456
$.ajax({
439-
url: webSiteRootURL + 'objects/videoAddViewCount.json.php?PHPSESSID='+PHPSESSID,
457+
url: webSiteRootURL + 'objects/videoAddViewCount.json.php?PHPSESSID=' + PHPSESSID,
440458
method: 'POST',
441459
data: {
442460
'id': videos_id,
@@ -1212,7 +1230,7 @@ function tabsCategoryDocumentHeightChanged() {
12121230
return false;
12131231
}
12141232

1215-
function checkDescriptionArea(){
1233+
function checkDescriptionArea() {
12161234
$(".descriptionArea").each(function (index) {
12171235
if ($(this).height() < $(this).find('.descriptionAreaContent').height()) {
12181236
$(this).find('.descriptionAreaShowMoreBtn').show();
@@ -1221,10 +1239,15 @@ function checkDescriptionArea(){
12211239
}
12221240

12231241
$(document).ready(function () {
1242+
1243+
$(window).bind('beforeunload', function () {
1244+
addViewBeacon();
1245+
});
1246+
12241247
checkDescriptionArea();
1225-
setInterval(function(){// check for the carousel
1226-
checkDescriptionArea();
1227-
},3000);
1248+
setInterval(function () {// check for the carousel
1249+
checkDescriptionArea();
1250+
}, 3000);
12281251

12291252

12301253
Cookies.set('timezone', Intl.DateTimeFormat().resolvedOptions().timeZone, {

0 commit comments

Comments
 (0)